Instead of talking about yaw, pitch and roll, I'll talk here about Euler angles x, y and z.
To perform a rotation of your equirectangular mapping, you can follow this procedure:
Consider coordinates (i2, j2)
in your result image. We'll try to find which color to put here. These coordinates correspond to a point on the sphere with latitude lat2 = 180 * i2 / image.height
and longitude lon2 = 360 * j2 / image.width
. Compute the corresponding 3D vector v2
.
Compute the rotation matrix R
with angles x, y and z (look at the formulas here). Take the transpose of this matrix to get the inverse rotation from the new image to the old one. We'll name this inverse rotation matrix Rt
.
Compute v1 = Rt * v2
. Then compute the latitude lat1
and longitude lon1
of v1
.
Find the color in the original image at coordinates i1 = image.height * lat1 / 180
and j1 = image.width * lon1 / 360
. This might not be integer coordinates. You might have to interpolate between several pixels to get your value. This is the color of the pixel at position (i2, j2)
in your new image.
You'll need to look at how to convert between 3D vectors on a sphere and their latitude and longitude angles but this shouldn't be too hard to find. The algorithm described here should be rather straightforward to implement.
Let me know if I made any mistake as I haven't tested it myself.