Fix compression from/decompression to TYPE_INT_{RGB|BGR} BufferedImages on big endian platforms
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
package org.libjpegturbo.turbojpeg;
|
package org.libjpegturbo.turbojpeg;
|
||||||
|
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TurboJPEG compressor
|
* TurboJPEG compressor
|
||||||
@@ -184,15 +185,25 @@ public class TJCompressor {
|
|||||||
int width = srcImage.getWidth();
|
int width = srcImage.getWidth();
|
||||||
int height = srcImage.getHeight();
|
int height = srcImage.getHeight();
|
||||||
int pixelFormat; boolean intPixels = false;
|
int pixelFormat; boolean intPixels = false;
|
||||||
|
if(byteOrder == null)
|
||||||
|
byteOrder = ByteOrder.nativeOrder();
|
||||||
switch(srcImage.getType()) {
|
switch(srcImage.getType()) {
|
||||||
case BufferedImage.TYPE_3BYTE_BGR:
|
case BufferedImage.TYPE_3BYTE_BGR:
|
||||||
pixelFormat = TJ.PF_BGR; break;
|
pixelFormat = TJ.PF_BGR; break;
|
||||||
case BufferedImage.TYPE_BYTE_GRAY:
|
case BufferedImage.TYPE_BYTE_GRAY:
|
||||||
pixelFormat = TJ.PF_GRAY; break;
|
pixelFormat = TJ.PF_GRAY; break;
|
||||||
case BufferedImage.TYPE_INT_BGR:
|
case BufferedImage.TYPE_INT_BGR:
|
||||||
pixelFormat = TJ.PF_RGBX; intPixels = true; break;
|
if(byteOrder == ByteOrder.BIG_ENDIAN)
|
||||||
|
pixelFormat = TJ.PF_XBGR;
|
||||||
|
else
|
||||||
|
pixelFormat = TJ.PF_RGBX;
|
||||||
|
intPixels = true; break;
|
||||||
case BufferedImage.TYPE_INT_RGB:
|
case BufferedImage.TYPE_INT_RGB:
|
||||||
pixelFormat = TJ.PF_BGRX; intPixels = true; break;
|
if(byteOrder == ByteOrder.BIG_ENDIAN)
|
||||||
|
pixelFormat = TJ.PF_XRGB;
|
||||||
|
else
|
||||||
|
pixelFormat = TJ.PF_BGRX;
|
||||||
|
intPixels = true; break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Unsupported BufferedImage format");
|
throw new Exception("Unsupported BufferedImage format");
|
||||||
}
|
}
|
||||||
@@ -313,15 +324,25 @@ public class TJCompressor {
|
|||||||
int width = srcImage.getWidth();
|
int width = srcImage.getWidth();
|
||||||
int height = srcImage.getHeight();
|
int height = srcImage.getHeight();
|
||||||
int pixelFormat; boolean intPixels = false;
|
int pixelFormat; boolean intPixels = false;
|
||||||
|
if(byteOrder == null)
|
||||||
|
byteOrder = ByteOrder.nativeOrder();
|
||||||
switch(srcImage.getType()) {
|
switch(srcImage.getType()) {
|
||||||
case BufferedImage.TYPE_3BYTE_BGR:
|
case BufferedImage.TYPE_3BYTE_BGR:
|
||||||
pixelFormat = TJ.PF_BGR; break;
|
pixelFormat = TJ.PF_BGR; break;
|
||||||
case BufferedImage.TYPE_BYTE_GRAY:
|
case BufferedImage.TYPE_BYTE_GRAY:
|
||||||
pixelFormat = TJ.PF_GRAY; break;
|
pixelFormat = TJ.PF_GRAY; break;
|
||||||
case BufferedImage.TYPE_INT_BGR:
|
case BufferedImage.TYPE_INT_BGR:
|
||||||
pixelFormat = TJ.PF_RGBX; intPixels = true; break;
|
if(byteOrder == ByteOrder.BIG_ENDIAN)
|
||||||
|
pixelFormat = TJ.PF_XBGR;
|
||||||
|
else
|
||||||
|
pixelFormat = TJ.PF_RGBX;
|
||||||
|
intPixels = true; break;
|
||||||
case BufferedImage.TYPE_INT_RGB:
|
case BufferedImage.TYPE_INT_RGB:
|
||||||
pixelFormat = TJ.PF_BGRX; intPixels = true; break;
|
if(byteOrder == ByteOrder.BIG_ENDIAN)
|
||||||
|
pixelFormat = TJ.PF_XRGB;
|
||||||
|
else
|
||||||
|
pixelFormat = TJ.PF_BGRX;
|
||||||
|
intPixels = true; break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Unsupported BufferedImage format");
|
throw new Exception("Unsupported BufferedImage format");
|
||||||
}
|
}
|
||||||
@@ -435,4 +456,5 @@ public class TJCompressor {
|
|||||||
private int subsamp = -1;
|
private int subsamp = -1;
|
||||||
private int jpegQuality = -1;
|
private int jpegQuality = -1;
|
||||||
private int compressedSize = 0;
|
private int compressedSize = 0;
|
||||||
|
private ByteOrder byteOrder = null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
package org.libjpegturbo.turbojpeg;
|
package org.libjpegturbo.turbojpeg;
|
||||||
|
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TurboJPEG decompressor
|
* TurboJPEG decompressor
|
||||||
@@ -378,15 +379,25 @@ public class TJDecompressor {
|
|||||||
if(scaledWidth != desiredWidth || scaledHeight != desiredHeight)
|
if(scaledWidth != desiredWidth || scaledHeight != desiredHeight)
|
||||||
throw new Exception("BufferedImage dimensions do not match a scaled image size that TurboJPEG is capable of generating.");
|
throw new Exception("BufferedImage dimensions do not match a scaled image size that TurboJPEG is capable of generating.");
|
||||||
int pixelFormat; boolean intPixels = false;
|
int pixelFormat; boolean intPixels = false;
|
||||||
|
if(byteOrder == null)
|
||||||
|
byteOrder = ByteOrder.nativeOrder();
|
||||||
switch(dstImage.getType()) {
|
switch(dstImage.getType()) {
|
||||||
case BufferedImage.TYPE_3BYTE_BGR:
|
case BufferedImage.TYPE_3BYTE_BGR:
|
||||||
pixelFormat = TJ.PF_BGR; break;
|
pixelFormat = TJ.PF_BGR; break;
|
||||||
case BufferedImage.TYPE_BYTE_GRAY:
|
case BufferedImage.TYPE_BYTE_GRAY:
|
||||||
pixelFormat = TJ.PF_GRAY; break;
|
pixelFormat = TJ.PF_GRAY; break;
|
||||||
case BufferedImage.TYPE_INT_BGR:
|
case BufferedImage.TYPE_INT_BGR:
|
||||||
pixelFormat = TJ.PF_RGBX; intPixels = true; break;
|
if(byteOrder == ByteOrder.BIG_ENDIAN)
|
||||||
|
pixelFormat = TJ.PF_XBGR;
|
||||||
|
else
|
||||||
|
pixelFormat = TJ.PF_RGBX;
|
||||||
|
intPixels = true; break;
|
||||||
case BufferedImage.TYPE_INT_RGB:
|
case BufferedImage.TYPE_INT_RGB:
|
||||||
pixelFormat = TJ.PF_BGRX; intPixels = true; break;
|
if(byteOrder == ByteOrder.BIG_ENDIAN)
|
||||||
|
pixelFormat = TJ.PF_XRGB;
|
||||||
|
else
|
||||||
|
pixelFormat = TJ.PF_BGRX;
|
||||||
|
intPixels = true; break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Unsupported BufferedImage format");
|
throw new Exception("Unsupported BufferedImage format");
|
||||||
}
|
}
|
||||||
@@ -492,4 +503,5 @@ public class TJDecompressor {
|
|||||||
protected int jpegWidth = 0;
|
protected int jpegWidth = 0;
|
||||||
protected int jpegHeight = 0;
|
protected int jpegHeight = 0;
|
||||||
protected int jpegSubsamp = -1;
|
protected int jpegSubsamp = -1;
|
||||||
|
private ByteOrder byteOrder = null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user