Ok, figured it out. There are two considerations to be made.
The first is that the direct rendering path does not shave off the alpha band in the resulting image even if the output has
not been asked as transparent. Now, this is a bug, if I ask for format=png and transparency=false I must get as output
a RGB image, not an RGBA one.
So I added code to shave off the alpha band.
However, that alone does not solve the issue. This is quite evident as the ImageWorker.writeJPEG was already shaving
off the extra band.
What is still tripping the JPEG writer (and also the PNG one too, once we remove the alpha band, it also starts to write out
inverted colors) is that the image is tiled: in order to get the right colors we still need to ensure the image getting
into the encode step is untiled.
The following patch does the trick for me:
diff --git a/src/wms/src/main/java/org/geoserver/wms/map/RenderedImageMapOutputFormat.java b/src/wms/src/main/java/org/g
index 6814481..b9bfcc5 100644
--- a/src/wms/src/main/java/org/geoserver/wms/map/RenderedImageMapOutputFormat.java
+++ b/src/wms/src/main/java/org/geoserver/wms/map/RenderedImageMapOutputFormat.java
@@ -1054,6 +1049,19 @@ public class RenderedImageMapOutputFormat extends AbstractMapOutputFormat {
(float)mapHeight,
null);
}
+
+ + + ColorModel finalColorModel = image.getColorModel();
+ if(!transparent && finalColorModel.hasAlpha()) {
+ ImageWorker iwAlpha = new ImageWorker(image);
+ iwAlpha.setRenderingHint(JAI.KEY_IMAGE_LAYOUT, layout);
+ iwAlpha.retainBands(iwAlpha.getNumBands() - 1);
+ image = iwAlpha.getRenderedImage();
+ }
+
+
+
return image;
}
The trick is setting the image layout as the band is removed, otherwise while removing the band
the image worker will also make it tiled (I guess it's using the default tile size from JAI or something).
To recap, to avoid color inversion on linux 64 bit with native JPEG writer enabled two things are required,
and the above patch does both of them:
- avoid having the alpha band around
- make sure the image is untiled
Given the nature of the issue I think we should also patch the ImageWorker so that
a tiled image getting into the writeJPEG and writePNG methods is flattened if the
native encoders are in use.
This is the result I get cascading topp:states from another server on linux 64bit with all jai/jai imageio native extensions active (and of course native jpeg encoding on)