@@ -94,7 +94,10 @@ class PipelineWorker : public Napi::AsyncWorker {
9494 // Calculate angle of rotation
9595 VipsAngle rotation = VIPS_ANGLE_D0 ;
9696 VipsAngle autoRotation = VIPS_ANGLE_D0 ;
97+ VipsAngle gainMapRotation = VIPS_ANGLE_D0 ;
9798 bool autoFlop = false ;
99+ bool gainMapFlip = false ;
100+ bool gainMapFlop = false ;
98101
99102 if (baton->input ->autoOrient ) {
100103 // Rotate and flip image according to Exif orientation
@@ -115,11 +118,13 @@ class PipelineWorker : public Napi::AsyncWorker {
115118 MultiPageUnsupported (nPages, " Rotate" );
116119 }
117120 image = image.rot (autoRotation);
121+ gainMapRotation = autoRotation;
118122 autoRotation = VIPS_ANGLE_D0 ;
119123 }
120124 if (autoFlop) {
121125 image = image.flip (VIPS_DIRECTION_HORIZONTAL );
122126 autoFlop = false ;
127+ gainMapFlop = true ;
123128 }
124129 }
125130
@@ -128,20 +133,24 @@ class PipelineWorker : public Napi::AsyncWorker {
128133 if (baton->flip ) {
129134 image = image.flip (VIPS_DIRECTION_VERTICAL );
130135 baton->flip = false ;
136+ gainMapFlip = true ;
131137 }
132138 if (baton->flop ) {
133139 image = image.flip (VIPS_DIRECTION_HORIZONTAL );
134140 baton->flop = false ;
141+ gainMapFlop = true ;
135142 }
136143 if (rotation != VIPS_ANGLE_D0 ) {
137144 if (rotation != VIPS_ANGLE_D180 ) {
138145 MultiPageUnsupported (nPages, " Rotate" );
139146 }
140147 image = image.rot (rotation);
148+ gainMapRotation = rotation;
141149 rotation = VIPS_ANGLE_D0 ;
142150 }
143151 if (baton->rotationAngle != 0.0 ) {
144152 MultiPageUnsupported (nPages, " Rotate" );
153+ KeepGainMapUnsupported (baton->keepGainMap , " Rotate" );
145154 std::vector<double > background;
146155 std::tie (image, background) = sharp::ApplyAlpha (image, baton->rotationBackground , false );
147156 image = image.rotate (baton->rotationAngle , VImage::option ()->set (" background" , background)).copy_memory ();
@@ -307,6 +316,15 @@ class PipelineWorker : public Napi::AsyncWorker {
307316 if (image.get_typeof (" gainmap-scale-factor" ) == G_TYPE_INT ) {
308317 gainMapScaleFactor = image.get_int (" gainmap-scale-factor" );
309318 }
319+ if (gainMapFlip) {
320+ gainMap = gainMap.flip (VIPS_DIRECTION_VERTICAL );
321+ }
322+ if (gainMapFlop) {
323+ gainMap = gainMap.flip (VIPS_DIRECTION_HORIZONTAL );
324+ }
325+ if (gainMapRotation != VIPS_ANGLE_D0 ) {
326+ gainMap = gainMap.rot (gainMapRotation);
327+ }
310328 if (baton->topOffsetPre != -1 ) {
311329 gainMap = gainMap.extract_area (
312330 baton->leftOffsetPre / gainMapScaleFactor, baton->topOffsetPre / gainMapScaleFactor,
@@ -563,6 +581,7 @@ class PipelineWorker : public Napi::AsyncWorker {
563581 // Rotate post-extract non-90 angle
564582 if (!baton->rotateBefore && baton->rotationAngle != 0.0 ) {
565583 MultiPageUnsupported (nPages, " Rotate" );
584+ KeepGainMapUnsupported (baton->keepGainMap , " Rotate" );
566585 image = sharp::StaySequential (image);
567586 std::vector<double > background;
568587 std::tie (image, background) = sharp::ApplyAlpha (image, baton->rotationBackground , shouldPremultiplyAlpha);
0 commit comments