if (yuv == YUVDECODE)
tjd.decompressToYUV(dstBuf, scaledw, yuvpad, scaledh, flags);
else
- tjd.decompress(dstBuf, scaledw, pitch, scaledh, pf, flags);
+ tjd.decompress(dstBuf, 0, 0, scaledw, pitch, scaledh, pf, flags);
/* Benchmark */
for (i = 0, start = getTime(); (elapsed = getTime() - start) < benchTime;
int ps = TJ.getPixelSize(pf), i;
int yuvSize = 0;
- yuvSize = TJ.bufSizeYUV(w, h, subsamp);
+ yuvSize = TJ.bufSizeYUV(w, yuvpad, h, subsamp);
dstBuf = new byte[yuvSize];
if (quiet == 0)
(flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD",
subNameLong[subsamp]);
- tjc = new TJCompressor(srcBuf, w, 0, h, pf);
+ tjc = new TJCompressor(srcBuf, 0, 0, w, 0, h, pf);
tjc.setSubsamp(subsamp);
/* Execute once to preload cache */
if (yuv == YUVCOMPRESS)
tjc.setSourceImageYUV(srcBuf, tilew, yuvpad, tileh);
else
- tjc.setSourceImage(srcBuf, tilew, pitch, tileh, pf);
+ tjc.setSourceImage(srcBuf, 0, 0, tilew, pitch, tileh, pf);
tjc.setJPEGQuality(jpegQual);
tjc.setSubsamp(subsamp);
System.out.println("-bottomup = Test bottom-up compression/decompression");
System.out.println("-tile = Test performance of the codec when the image is encoded as separate");
System.out.println(" tiles of varying sizes.");
- System.out.println("-forcemmx, -forcesse, -forcesse2, -forcesse3 =");
- System.out.println(" Force MMX, SSE, SSE2, or SSE3 code paths in the underlying codec");
System.out.println("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =");
System.out.println(" Test the specified color conversion path in the codec (default: BGR)");
System.out.println("-fastupsample = Use the fastest chrominance upsampling algorithm available in");
if (argv[i].equalsIgnoreCase("-tile")) {
doTile = true; xformOpt |= TJTransform.OPT_CROP;
}
- if (argv[i].equalsIgnoreCase("-forcesse3")) {
- System.out.println("Forcing SSE3 code\n");
- flags |= TJ.FLAG_FORCESSE3;
- }
- if (argv[i].equalsIgnoreCase("-forcesse2")) {
- System.out.println("Forcing SSE2 code\n");
- flags |= TJ.FLAG_FORCESSE2;
- }
- if (argv[i].equalsIgnoreCase("-forcesse")) {
- System.out.println("Forcing SSE code\n");
- flags |= TJ.FLAG_FORCESSE;
- }
- if (argv[i].equalsIgnoreCase("-forcemmx")) {
- System.out.println("Forcing MMX code\n");
- flags |= TJ.FLAG_FORCEMMX;
- }
if (argv[i].equalsIgnoreCase("-fastupsample")) {
System.out.println("Using fast upsampling code\n");
flags |= TJ.FLAG_FASTUPSAMPLE;
/*
- * Copyright (C)2011-2012 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2011-2012, 2014 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
tjc.setSubsamp(outSubsamp);
tjc.setJPEGQuality(outQual);
if (img != null)
- jpegBuf = tjc.compress(img, flags);
+ tjc.setSourceImage(img, 0, 0, 0, 0);
else {
- tjc.setSourceImage(bmpBuf, width, 0, height, TJ.PF_BGRX);
- jpegBuf = tjc.compress(flags);
+ tjc.setSourceImage(bmpBuf, 0, 0, width, 0, height, TJ.PF_BGRX);
}
+ jpegBuf = tjc.compress(flags);
jpegSize = tjc.getCompressedSize();
tjc.close();
tjc.setSubsamp(subsamp);
tjc.setJPEGQuality(jpegQual);
tjc.setYUVPad(pad);
- if (bi) {
- if (yuv == YUVENCODE)
- tjc.encodeYUV(img, dstBuf, flags);
- else
- tjc.compress(img, dstBuf, flags);
- } else {
- if (yuv == YUVDECODE)
- tjc.setSourceImageYUV(srcBuf, w, pad, h);
- else
- tjc.setSourceImage(srcBuf, w, 0, h, pf);
- if (yuv == YUVENCODE)
- tjc.encodeYUV(dstBuf, flags);
- else
- tjc.compress(dstBuf, flags);
- }
+ if (yuv == YUVDECODE)
+ tjc.setSourceImageYUV(srcBuf, w, pad, h);
+ else if (bi)
+ tjc.setSourceImage(img, 0, 0, 0, 0);
+ else
+ tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, pf);
+ if (yuv == YUVENCODE)
+ tjc.encodeYUV(dstBuf, flags);
+ else
+ tjc.compress(dstBuf, flags);
size = tjc.getCompressedSize();
if (yuv == YUVENCODE)
for (i = 0; i < w * h * 4; i++) {
srcBuf[i] = (byte)(r.nextInt(2) * 255);
}
- tjc.setSourceImage(srcBuf, w, 0, h, TJ.PF_BGRX);
+ tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, TJ.PF_BGRX);
tjc.setSubsamp(subsamp);
tjc.setJPEGQuality(100);
tjc.setYUVPad(pad);
for (i = 0; i < h * w * 4; i++) {
srcBuf[i] = (byte)(r.nextInt(2) * 255);
}
- tjc.setSourceImage(srcBuf, h, 0, w, TJ.PF_BGRX);
+ tjc.setSourceImage(srcBuf, 0, 0, h, 0, w, TJ.PF_BGRX);
if (yuv == YUVENCODE)
tjc.encodeYUV(dstBuf, 0);
else
<B>Contents</B><UL>
<LI><A HREF="#field">Deprecated Fields</A>
<LI><A HREF="#method">Deprecated Methods</A>
+<LI><A HREF="#constructor">Deprecated Constructors</A>
</UL>
<A NAME="field"><!-- --></A>
<I>Use <A HREF="org/libjpegturbo/turbojpeg/TJ.html#bufSizeYUV(int, int, int, int)"><CODE>TJ.bufSizeYUV(int, int, int, int)</CODE></A> instead.</I> </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#compress(java.awt.image.BufferedImage, byte[], int)">org.libjpegturbo.turbojpeg.TJCompressor.compress(BufferedImage, byte[], int)</A>
+<BR>
+ <I>Use
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#compress(byte[], int)"><CODE>TJCompressor.compress(byte[], int)</CODE></A> instead.</I> </TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#compress(java.awt.image.BufferedImage, int)">org.libjpegturbo.turbojpeg.TJCompressor.compress(BufferedImage, int)</A>
+<BR>
+ <I>Use
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#compress(int)"><CODE>TJCompressor.compress(int)</CODE></A> instead.</I> </TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><A HREF="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(byte[], int, int, int, int, int)">org.libjpegturbo.turbojpeg.TJDecompressor.decompress(byte[], int, int, int, int, int)</A>
<BR>
<I>Use
<I>Use <A HREF="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompressToYUV(int, int, int, int)"><CODE>TJDecompressor.decompressToYUV(int, int, int, int)</CODE></A> instead.</I> </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(java.awt.image.BufferedImage, byte[], int)">org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(BufferedImage, byte[], int)</A>
+<BR>
+ <I>Use
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(byte[], int)"><CODE>TJCompressor.encodeYUV(byte[], int)</CODE></A> instead.</I> </TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(java.awt.image.BufferedImage, int)">org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(BufferedImage, int)</A>
+<BR>
+ <I>Use
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(int)"><CODE>TJCompressor.encodeYUV(int)</CODE></A> instead.</I> </TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int)">org.libjpegturbo.turbojpeg.TJCompressor.setSourceImage(byte[], int, int, int, int)</A>
<BR>
<I>Use
</TABLE>
<P>
+<A NAME="constructor"><!-- --></A>
+<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
+<B>Deprecated Constructors</B></FONT></TH>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int)">org.libjpegturbo.turbojpeg.TJCompressor(byte[], int, int, int, int)</A>
+<BR>
+ <I>Use
+ <A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)"><CODE>TJCompressor.TJCompressor(byte[], int, int, int, int, int, int)</CODE></A> instead.</I> </TD>
+</TR>
+</TABLE>
+
+<P>
<HR>
instance and return a buffer containing a JPEG image.
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#compress(java.awt.image.BufferedImage, byte[], int)"><B>compress(BufferedImage, byte[], int)</B></A> -
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
-<DD>Compress the uncompressed source image stored in <code>srcImage</code>
- and output a JPEG image to the given destination buffer.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#compress(byte[], int)"><CODE>TJCompressor.compress(byte[], int)</CODE></A> instead.</I>
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#compress(java.awt.image.BufferedImage, int)"><B>compress(BufferedImage, int)</B></A> -
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
-<DD>Compress the uncompressed source image stored in <code>srcImage</code>
- and return a buffer containing a JPEG image.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#compress(int)"><CODE>TJCompressor.compress(int)</CODE></A> instead.</I>
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJ.html#CS_CMYK"><B>CS_CMYK</B></A> -
Static variable in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</A>
<DD>CMYK colorspace.
instance and return a buffer containing a YUV planar image.
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(java.awt.image.BufferedImage, byte[], int)"><B>encodeYUV(BufferedImage, byte[], int)</B></A> -
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
-<DD>Encode the uncompressed source image stored in <code>srcImage</code>
- and output a YUV planar image to the given destination buffer.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(byte[], int)"><CODE>TJCompressor.encodeYUV(byte[], int)</CODE></A> instead.</I>
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(java.awt.image.BufferedImage, int)"><B>encodeYUV(BufferedImage, int)</B></A> -
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
-<DD>Encode the uncompressed source image stored in <code>srcImage</code>
- and return a buffer containing a YUV planar image.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>TJCompressor.setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(int)"><CODE>TJCompressor.encodeYUV(int)</CODE></A> instead.</I>
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJScalingFactor.html#equals(org.libjpegturbo.turbojpeg.TJScalingFactor)"><B>equals(TJScalingFactor)</B></A> -
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg">TJScalingFactor</A>
<DD>Returns true or false, depending on whether this instance and
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
<DD><B>Deprecated.</B> <I>Use
<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>TJCompressor.setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> instead.</I>
+<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><B>setSourceImage(BufferedImage, int, int, int, int)</B></A> -
+Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
+<DD>Associate an uncompressed source image with this compressor instance.
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImageYUV(byte[], int, int, int)"><B>setSourceImageYUV(byte[], int, int, int)</B></A> -
Method in class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
<DD>Associate an uncompressed YUV planar source image with this compressor
<DD>Create a TurboJPEG compressor instance.
<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int)"><B>TJCompressor(byte[], int, int, int, int)</B></A> -
Constructor for class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)"><CODE>TJCompressor.TJCompressor(byte[], int, int, int, int, int, int)</CODE></A> instead.</I>
+<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)"><B>TJCompressor(byte[], int, int, int, int, int, int)</B></A> -
+Constructor for class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
<DD>Create a TurboJPEG compressor instance and associate the uncompressed
source image stored in <code>srcImage</code> with the newly-created
instance.
-<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)"><B>TJCompressor(byte[], int, int, int, int, int, int)</B></A> -
+<DT><A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(java.awt.image.BufferedImage, int, int, int, int)"><B>TJCompressor(BufferedImage, int, int, int, int)</B></A> -
Constructor for class org.libjpegturbo.turbojpeg.<A HREF="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
<DD>Create a TurboJPEG compressor instance and associate the uncompressed
source image stored in <code>srcImage</code> with the newly-created
Create a TurboJPEG compressor instance.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(java.awt.image.BufferedImage, int, int, int, int)">TJCompressor</A></B>(java.awt.image.BufferedImage srcImage,
+ int x,
+ int y,
+ int width,
+ int height)</CODE>
+
+<BR>
+ Create a TurboJPEG compressor instance and associate the uncompressed
+ source image stored in <code>srcImage</code> with the newly-created
+ instance.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int)">TJCompressor</A></B>(byte[] srcImage,
int width,
int pitch,
int pixelFormat)</CODE>
<BR>
- Create a TurboJPEG compressor instance and associate the uncompressed
- source image stored in <code>srcImage</code> with the newly-created
- instance.</TD>
+ <B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)"><CODE>TJCompressor(byte[], int, int, int, int, int, int)</CODE></A> instead.</I></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)">TJCompressor</A></B>(byte[] srcImage,
int flags)</CODE>
<BR>
- Compress the uncompressed source image stored in <code>srcImage</code>
- and output a JPEG image to the given destination buffer.</TD>
+ <B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#compress(byte[], int)"><CODE>compress(byte[], int)</CODE></A> instead.</I></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
int flags)</CODE>
<BR>
- Compress the uncompressed source image stored in <code>srcImage</code>
- and return a buffer containing a JPEG image.</TD>
+ <B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#compress(int)"><CODE>compress(int)</CODE></A> instead.</I></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
int flags)</CODE>
<BR>
- Encode the uncompressed source image stored in <code>srcImage</code>
- and output a YUV planar image to the given destination buffer.</TD>
+ <B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(byte[], int)"><CODE>encodeYUV(byte[], int)</CODE></A> instead.</I></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
int flags)</CODE>
<BR>
- Encode the uncompressed source image stored in <code>srcImage</code>
- and return a buffer containing a YUV planar image.</TD>
+ <B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(int)"><CODE>encodeYUV(int)</CODE></A> instead.</I></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)">setSourceImage</A></B>(java.awt.image.BufferedImage srcImage,
+ int x,
+ int y,
+ int width,
+ int height)</CODE>
+
+<BR>
+ Associate an uncompressed source image with this compressor instance.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int)">setSourceImage</A></B>(byte[] srcImage,
int width,
int pitch,
<A NAME="TJCompressor(byte[], int, int, int, int)"><!-- --></A><H3>
TJCompressor</H3>
<PRE>
+<FONT SIZE="-1">@Deprecated
+</FONT>public <B>TJCompressor</B>(byte[] srcImage,
+ int width,
+ int pitch,
+ int height,
+ int pixelFormat)
+ throws java.lang.Exception</PRE>
+<DL>
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#TJCompressor(byte[], int, int, int, int, int, int)"><CODE>TJCompressor(byte[], int, int, int, int, int, int)</CODE></A> instead.</I>
+<P>
+<DL>
+
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DL>
+<HR>
+
+<A NAME="TJCompressor(byte[], int, int, int, int, int, int)"><!-- --></A><H3>
+TJCompressor</H3>
+<PRE>
public <B>TJCompressor</B>(byte[] srcImage,
+ int x,
+ int y,
int width,
int pitch,
int height,
instance.
<P>
<DL>
-<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>width</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>pitch</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>height</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>pixelFormat</CODE> - pixel format of the source image (one of
+<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>x</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>y</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>width</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>pitch</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>height</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>pixelFormat</CODE> - pixel format of the source image (one of
<A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><CODE>TJ.PF_*</CODE></A>)
<DT><B>Throws:</B>
<DD><CODE>java.lang.Exception</CODE></DL>
</DL>
<HR>
-<A NAME="TJCompressor(byte[], int, int, int, int, int, int)"><!-- --></A><H3>
+<A NAME="TJCompressor(java.awt.image.BufferedImage, int, int, int, int)"><!-- --></A><H3>
TJCompressor</H3>
<PRE>
-public <B>TJCompressor</B>(byte[] srcImage,
+public <B>TJCompressor</B>(java.awt.image.BufferedImage srcImage,
int x,
int y,
int width,
- int pitch,
- int height,
- int pixelFormat)
+ int height)
throws java.lang.Exception</PRE>
<DL>
<DD>Create a TurboJPEG compressor instance and associate the uncompressed
instance.
<P>
<DL>
-<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>x</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>y</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>width</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>pitch</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>height</CODE> - see <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte[], int, int, int, int, int, int)"><CODE>setSourceImage(byte[], int, int, int, int, int, int)</CODE></A> for description<DD><CODE>pixelFormat</CODE> - pixel format of the source image (one of
- <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><CODE>TJ.PF_*</CODE></A>)
+<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - see
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> for description<DD><CODE>x</CODE> - see
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> for description<DD><CODE>y</CODE> - see
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> for description<DD><CODE>width</CODE> - see
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> for description<DD><CODE>height</CODE> - see
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> for description
<DT><B>Throws:</B>
<DD><CODE>java.lang.Exception</CODE></DL>
</DL>
</DL>
<HR>
+<A NAME="setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><!-- --></A><H3>
+setSourceImage</H3>
+<PRE>
+public void <B>setSourceImage</B>(java.awt.image.BufferedImage srcImage,
+ int x,
+ int y,
+ int width,
+ int height)
+ throws java.lang.Exception</PRE>
+<DL>
+<DD>Associate an uncompressed source image with this compressor instance.
+<P>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - a <code>BufferedImage</code> instance containing RGB or
+ grayscale pixels to be compressed<DD><CODE>x</CODE> - x offset (in pixels) of the region in the source image from which
+ the JPEG image should be compressed<DD><CODE>y</CODE> - y offset (in pixels) of the region in the source image from which
+ the JPEG image should be compressed<DD><CODE>width</CODE> - width (in pixels) of the region in the source image from
+ which the JPEG image should be compressed (0 = compress the whole image)<DD><CODE>height</CODE> - height (in pixels) of the region in the source image from
+ which the JPEG image should be compressed (0 = compress the whole image)
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
<A NAME="setSourceImageYUV(byte[], int, int, int)"><!-- --></A><H3>
setSourceImageYUV</H3>
<PRE>
<A NAME="compress(java.awt.image.BufferedImage, byte[], int)"><!-- --></A><H3>
compress</H3>
<PRE>
-public void <B>compress</B>(java.awt.image.BufferedImage srcImage,
- byte[] dstBuf,
- int flags)
+<FONT SIZE="-1">@Deprecated
+</FONT>public void <B>compress</B>(java.awt.image.BufferedImage srcImage,
+ byte[] dstBuf,
+ int flags)
throws java.lang.Exception</PRE>
<DL>
-<DD>Compress the uncompressed source image stored in <code>srcImage</code>
- and output a JPEG image to the given destination buffer.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#compress(byte[], int)"><CODE>compress(byte[], int)</CODE></A> instead.</I>
<P>
<DD><DL>
-<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - a <code>BufferedImage</code> instance containing RGB or
- grayscale pixels to be compressed<DD><CODE>dstBuf</CODE> - buffer that will receive the JPEG image. Use
- <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html#bufSize(int, int, int)"><CODE>TJ.bufSize(int, int, int)</CODE></A> to determine the maximum size for this buffer based on
- the image width, height, and level of chrominance subsampling.<DD><CODE>flags</CODE> - the bitwise OR of one or more of <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><CODE>TJ.FLAG_*</CODE></A>
+
<DT><B>Throws:</B>
<DD><CODE>java.lang.Exception</CODE></DL>
</DD>
<A NAME="compress(java.awt.image.BufferedImage, int)"><!-- --></A><H3>
compress</H3>
<PRE>
-public byte[] <B>compress</B>(java.awt.image.BufferedImage srcImage,
- int flags)
+<FONT SIZE="-1">@Deprecated
+</FONT>public byte[] <B>compress</B>(java.awt.image.BufferedImage srcImage,
+ int flags)
throws java.lang.Exception</PRE>
<DL>
-<DD>Compress the uncompressed source image stored in <code>srcImage</code>
- and return a buffer containing a JPEG image.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#compress(int)"><CODE>compress(int)</CODE></A> instead.</I>
<P>
<DD><DL>
-<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - a <code>BufferedImage</code> instance containing RGB or
- grayscale pixels to be compressed<DD><CODE>flags</CODE> - the bitwise OR of one or more of <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><CODE>TJ.FLAG_*</CODE></A>
-<DT><B>Returns:</B><DD>a buffer containing a JPEG image. The length of this buffer will
- not be equal to the size of the JPEG image. Use <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#getCompressedSize()"><CODE>getCompressedSize()</CODE></A> to obtain the size of the JPEG image.
+
<DT><B>Throws:</B>
<DD><CODE>java.lang.Exception</CODE></DL>
</DD>
<A NAME="encodeYUV(java.awt.image.BufferedImage, byte[], int)"><!-- --></A><H3>
encodeYUV</H3>
<PRE>
-public void <B>encodeYUV</B>(java.awt.image.BufferedImage srcImage,
- byte[] dstBuf,
- int flags)
+<FONT SIZE="-1">@Deprecated
+</FONT>public void <B>encodeYUV</B>(java.awt.image.BufferedImage srcImage,
+ byte[] dstBuf,
+ int flags)
throws java.lang.Exception</PRE>
<DL>
-<DD>Encode the uncompressed source image stored in <code>srcImage</code>
- and output a YUV planar image to the given destination buffer. See
- <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(byte[], int)"><CODE>encodeYUV(byte[], int)</CODE></A> for more detail.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(byte[], int)"><CODE>encodeYUV(byte[], int)</CODE></A> instead.</I>
<P>
<DD><DL>
-<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - a <code>BufferedImage</code> instance containing RGB or
- grayscale pixels to be encoded<DD><CODE>dstBuf</CODE> - buffer that will receive the YUV planar image. Use
- <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html#bufSizeYUV(int, int, int, int)"><CODE>TJ.bufSizeYUV(int, int, int, int)</CODE></A> to determine the appropriate size for this buffer
- based on the image width, height, and level of chrominance subsampling.<DD><CODE>flags</CODE> - the bitwise OR of one or more of <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><CODE>TJ.FLAG_*</CODE></A>
+
<DT><B>Throws:</B>
<DD><CODE>java.lang.Exception</CODE></DL>
</DD>
<A NAME="encodeYUV(java.awt.image.BufferedImage, int)"><!-- --></A><H3>
encodeYUV</H3>
<PRE>
-public byte[] <B>encodeYUV</B>(java.awt.image.BufferedImage srcImage,
- int flags)
+<FONT SIZE="-1">@Deprecated
+</FONT>public byte[] <B>encodeYUV</B>(java.awt.image.BufferedImage srcImage,
+ int flags)
throws java.lang.Exception</PRE>
<DL>
-<DD>Encode the uncompressed source image stored in <code>srcImage</code>
- and return a buffer containing a YUV planar image. See
- <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(byte[], int)"><CODE>encodeYUV(byte[], int)</CODE></A> for more detail.
+<DD><B>Deprecated.</B> <I>Use
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage, int, int, int, int)"><CODE>setSourceImage(BufferedImage, int, int, int, int)</CODE></A> and
+ <A HREF="../../../org/libjpegturbo/turbojpeg/TJCompressor.html#encodeYUV(int)"><CODE>encodeYUV(int)</CODE></A> instead.</I>
<P>
<DD><DL>
-<DT><B>Parameters:</B><DD><CODE>srcImage</CODE> - a <code>BufferedImage</code> instance containing RGB or
- grayscale pixels to be encoded<DD><CODE>flags</CODE> - the bitwise OR of one or more of <A HREF="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><CODE>TJ.FLAG_*</CODE></A>
-<DT><B>Returns:</B><DD>a buffer containing a YUV planar image
+
<DT><B>Throws:</B>
<DD><CODE>java.lang.Exception</CODE></DL>
</DD>
/*
- * Copyright (C)2011-2013 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2011-2014 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
}
/**
- * Create a TurboJPEG compressor instance and associate the uncompressed
- * source image stored in <code>srcImage</code> with the newly-created
- * instance.
- *
- * @param srcImage see {@link #setSourceImage} for description
- *
- * @param width see {@link #setSourceImage} for description
- *
- * @param pitch see {@link #setSourceImage} for description
- *
- * @param height see {@link #setSourceImage} for description
- *
- * @param pixelFormat pixel format of the source image (one of
- * {@link TJ TJ.PF_*})
+ * @deprecated Use
+ * {@link #TJCompressor(byte[], int, int, int, int, int, int)} instead.
*/
+ @Deprecated
public TJCompressor(byte[] srcImage, int width, int pitch, int height,
int pixelFormat) throws Exception {
setSourceImage(srcImage, width, pitch, height, pixelFormat);
setSourceImage(srcImage, x, y, width, pitch, height, pixelFormat);
}
+ /**
+ * Create a TurboJPEG compressor instance and associate the uncompressed
+ * source image stored in <code>srcImage</code> with the newly-created
+ * instance.
+ *
+ * @param srcImage see
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description
+ *
+ * @param x see
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description
+ *
+ * @param y see
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description
+ *
+ * @param width see
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description
+ *
+ * @param height see
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description
+ */
+ public TJCompressor(BufferedImage srcImage, int x, int y, int width,
+ int height) throws Exception {
+ setSourceImage(srcImage, x, y, width, height);
+ }
+
/**
* Associate an uncompressed source image with this compressor instance.
*
srcPixelFormat = pixelFormat;
srcX = x;
srcY = y;
+ srcBufInt = null;
srcIsYUV = false;
}
srcX = srcY = -1;
}
+ /**
+ * Associate an uncompressed source image with this compressor instance.
+ *
+ * @param srcImage a <code>BufferedImage</code> instance containing RGB or
+ * grayscale pixels to be compressed
+ *
+ * @param x x offset (in pixels) of the region in the source image from which
+ * the JPEG image should be compressed
+ *
+ * @param y y offset (in pixels) of the region in the source image from which
+ * the JPEG image should be compressed
+ *
+ * @param width width (in pixels) of the region in the source image from
+ * which the JPEG image should be compressed (0 = compress the whole image)
+ *
+ * @param height height (in pixels) of the region in the source image from
+ * which the JPEG image should be compressed (0 = compress the whole image)
+ */
+ public void setSourceImage(BufferedImage srcImage, int x, int y, int width,
+ int height) throws Exception {
+ if (handle == 0) init();
+ if (srcImage == null || x < 0 || y < 0 || width < 0 || height < 0)
+ throw new Exception("Invalid argument in setSourceImage()");
+ srcX = x;
+ srcY = y;
+ srcWidth = (width == 0) ? srcImage.getWidth(): width;
+ srcHeight = (height == 0) ? srcImage.getHeight() : height;
+ if (x + width > srcImage.getWidth() || y + height > srcImage.getHeight())
+ throw new Exception("Compression region exceeds the bounds of the source image");
+
+ int pixelFormat;
+ boolean intPixels = false;
+ if (byteOrder == null)
+ byteOrder = ByteOrder.nativeOrder();
+ switch(srcImage.getType()) {
+ case BufferedImage.TYPE_3BYTE_BGR:
+ pixelFormat = TJ.PF_BGR; break;
+ case BufferedImage.TYPE_4BYTE_ABGR:
+ case BufferedImage.TYPE_4BYTE_ABGR_PRE:
+ pixelFormat = TJ.PF_XBGR; break;
+ case BufferedImage.TYPE_BYTE_GRAY:
+ pixelFormat = TJ.PF_GRAY; break;
+ case BufferedImage.TYPE_INT_BGR:
+ 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_ARGB:
+ case BufferedImage.TYPE_INT_ARGB_PRE:
+ if (byteOrder == ByteOrder.BIG_ENDIAN)
+ pixelFormat = TJ.PF_XRGB;
+ else
+ pixelFormat = TJ.PF_BGRX;
+ intPixels = true; break;
+ default:
+ throw new Exception("Unsupported BufferedImage format");
+ }
+ srcPixelFormat = pixelFormat;
+
+ WritableRaster wr = srcImage.getRaster();
+ if (intPixels) {
+ SinglePixelPackedSampleModel sm =
+ (SinglePixelPackedSampleModel)srcImage.getSampleModel();
+ srcStride = sm.getScanlineStride();
+ DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+ srcBufInt = db.getData();
+ srcBuf = null;
+ } else {
+ ComponentSampleModel sm =
+ (ComponentSampleModel)srcImage.getSampleModel();
+ int pixelSize = sm.getPixelStride();
+ if (pixelSize != TJ.getPixelSize(pixelFormat))
+ throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage");
+ srcPitch = sm.getScanlineStride();
+ DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
+ srcBuf = db.getData();
+ srcBufInt = null;
+ }
+ }
+
/**
* Associate an uncompressed YUV planar source image with this compressor
* instance.
public void compress(byte[] dstBuf, int flags) throws Exception {
if (dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()");
- if (srcBuf == null)
+ if (srcBuf == null && (srcBufInt == null || srcIsYUV))
throw new Exception(NO_ASSOC_ERROR);
if (jpegQuality < 0)
throw new Exception("JPEG Quality not set");
if (subsamp < 0)
throw new Exception("Subsampling level not set");
+
if (srcIsYUV)
compressedSize = compressFromYUV(srcBuf, srcWidth, srcYUVPad, srcHeight,
subsamp, dstBuf, jpegQuality, flags);
- else {
+ else if (srcBuf != null) {
if (srcX >= 0 && srcY >= 0)
compressedSize = compress(srcBuf, srcX, srcY, srcWidth, srcPitch,
srcHeight, srcPixelFormat, dstBuf, subsamp,
compressedSize = compress(srcBuf, srcWidth, srcPitch, srcHeight,
srcPixelFormat, dstBuf, subsamp, jpegQuality,
flags);
+ } else if (srcBufInt != null) {
+ if (srcX >= 0 && srcY >= 0)
+ compressedSize = compress(srcBufInt, srcX, srcY, srcWidth, srcStride,
+ srcHeight, srcPixelFormat, dstBuf, subsamp,
+ jpegQuality, flags);
+ else
+ compressedSize = compress(srcBufInt, srcWidth, srcStride, srcHeight,
+ srcPixelFormat, dstBuf, subsamp, jpegQuality,
+ flags);
}
}
}
/**
- * Compress the uncompressed source image stored in <code>srcImage</code>
- * and output a JPEG image to the given destination buffer.
- *
- * @param srcImage a <code>BufferedImage</code> instance containing RGB or
- * grayscale pixels to be compressed
- *
- * @param dstBuf buffer that will receive the JPEG image. Use
- * {@link TJ#bufSize} to determine the maximum size for this buffer based on
- * the image width, height, and level of chrominance subsampling.
- *
- * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
+ * @deprecated Use
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} and
+ * {@link #compress(byte[], int)} instead.
*/
+ @Deprecated
public void compress(BufferedImage srcImage, byte[] dstBuf, int flags)
throws Exception {
- if (srcImage == null || dstBuf == null || flags < 0)
- throw new Exception("Invalid argument in compress()");
- int width = srcImage.getWidth();
- int height = srcImage.getHeight();
- int pixelFormat;
- boolean intPixels = false;
- if (byteOrder == null)
- byteOrder = ByteOrder.nativeOrder();
- switch(srcImage.getType()) {
- case BufferedImage.TYPE_3BYTE_BGR:
- pixelFormat = TJ.PF_BGR; break;
- case BufferedImage.TYPE_4BYTE_ABGR:
- case BufferedImage.TYPE_4BYTE_ABGR_PRE:
- pixelFormat = TJ.PF_XBGR; break;
- case BufferedImage.TYPE_BYTE_GRAY:
- pixelFormat = TJ.PF_GRAY; break;
- case BufferedImage.TYPE_INT_BGR:
- 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_ARGB:
- case BufferedImage.TYPE_INT_ARGB_PRE:
- if (byteOrder == ByteOrder.BIG_ENDIAN)
- pixelFormat = TJ.PF_XRGB;
- else
- pixelFormat = TJ.PF_BGRX;
- intPixels = true; break;
- default:
- throw new Exception("Unsupported BufferedImage format");
- }
- WritableRaster wr = srcImage.getRaster();
- if (jpegQuality < 0)
- throw new Exception("JPEG Quality not set");
- if (subsamp < 0)
- throw new Exception("Subsampling level not set");
- if (intPixels) {
- SinglePixelPackedSampleModel sm =
- (SinglePixelPackedSampleModel)srcImage.getSampleModel();
- int stride = sm.getScanlineStride();
- DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
- int[] buf = db.getData();
- if (srcX >= 0 && srcY >= 0)
- compressedSize = compress(buf, srcX, srcY, width, stride, height,
- pixelFormat, dstBuf, subsamp, jpegQuality,
- flags);
- else
- compressedSize = compress(buf, width, stride, height, pixelFormat,
- dstBuf, subsamp, jpegQuality, flags);
- } else {
- ComponentSampleModel sm =
- (ComponentSampleModel)srcImage.getSampleModel();
- int pixelSize = sm.getPixelStride();
- if (pixelSize != TJ.getPixelSize(pixelFormat))
- throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage");
- int pitch = sm.getScanlineStride();
- DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
- byte[] buf = db.getData();
- if (srcX >= 0 && srcY >= 0)
- compressedSize = compress(buf, srcX, srcY, width, pitch, height,
- pixelFormat, dstBuf, subsamp, jpegQuality,
- flags);
- else
- compressedSize = compress(buf, width, pitch, height, pixelFormat,
- dstBuf, subsamp, jpegQuality, flags);
- }
+ setSourceImage(srcImage, 0, 0, 0, 0);
+ compress(dstBuf, flags);
}
/**
- * Compress the uncompressed source image stored in <code>srcImage</code>
- * and return a buffer containing a JPEG image.
- *
- * @param srcImage a <code>BufferedImage</code> instance containing RGB or
- * grayscale pixels to be compressed
- *
- * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
- *
- * @return a buffer containing a JPEG image. The length of this buffer will
- * not be equal to the size of the JPEG image. Use {@link
- * #getCompressedSize} to obtain the size of the JPEG image.
+ * @deprecated Use
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} and
+ * {@link #compress(int)} instead.
*/
+ @Deprecated
public byte[] compress(BufferedImage srcImage, int flags) throws Exception {
- int width = srcImage.getWidth();
- int height = srcImage.getHeight();
- byte[] buf = new byte[TJ.bufSize(width, height, subsamp)];
- compress(srcImage, buf, flags);
- return buf;
+ setSourceImage(srcImage, 0, 0, 0, 0);
+ return compress(flags);
}
public void encodeYUV(byte[] dstBuf, int flags) throws Exception {
if (dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()");
- if (srcBuf == null)
+ if (srcBuf == null && srcBufInt == null)
throw new Exception(NO_ASSOC_ERROR);
+ if (srcIsYUV)
+ throw new Exception("Source image is not correct type");
if (subsamp < 0)
throw new Exception("Subsampling level not set");
- encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight, srcPixelFormat, dstBuf,
- yuvPad, subsamp, flags);
+
+ if (srcBufInt != null) {
+ encodeYUV(srcBufInt, srcWidth, srcStride, srcHeight, srcPixelFormat,
+ dstBuf, yuvPad, subsamp, flags);
+ } else {
+ encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight, srcPixelFormat, dstBuf,
+ yuvPad, subsamp, flags);
+ }
compressedSize = TJ.bufSizeYUV(srcWidth, yuvPad, srcHeight, subsamp);
}
}
/**
- * Encode the uncompressed source image stored in <code>srcImage</code>
- * and output a YUV planar image to the given destination buffer. See
- * {@link #encodeYUV(byte[], int)} for more detail.
- *
- * @param srcImage a <code>BufferedImage</code> instance containing RGB or
- * grayscale pixels to be encoded
- *
- * @param dstBuf buffer that will receive the YUV planar image. Use
- * {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer
- * based on the image width, height, and level of chrominance subsampling.
- *
- * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
+ * @deprecated Use
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} and
+ * {@link #encodeYUV(byte[], int)} instead.
*/
+ @Deprecated
public void encodeYUV(BufferedImage srcImage, byte[] dstBuf, int flags)
throws Exception {
- if (srcImage == null || dstBuf == null || flags < 0)
- throw new Exception("Invalid argument in encodeYUV()");
- int width = srcImage.getWidth();
- int height = srcImage.getHeight();
- int pixelFormat; boolean intPixels = false;
- if (byteOrder == null)
- byteOrder = ByteOrder.nativeOrder();
- switch(srcImage.getType()) {
- case BufferedImage.TYPE_3BYTE_BGR:
- pixelFormat = TJ.PF_BGR; break;
- case BufferedImage.TYPE_4BYTE_ABGR:
- case BufferedImage.TYPE_4BYTE_ABGR_PRE:
- pixelFormat = TJ.PF_XBGR; break;
- case BufferedImage.TYPE_BYTE_GRAY:
- pixelFormat = TJ.PF_GRAY; break;
- case BufferedImage.TYPE_INT_BGR:
- 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_ARGB:
- case BufferedImage.TYPE_INT_ARGB_PRE:
- if (byteOrder == ByteOrder.BIG_ENDIAN)
- pixelFormat = TJ.PF_XRGB;
- else
- pixelFormat = TJ.PF_BGRX;
- intPixels = true; break;
- default:
- throw new Exception("Unsupported BufferedImage format");
- }
- WritableRaster wr = srcImage.getRaster();
- if (subsamp < 0) throw new Exception("Subsampling level not set");
- if (intPixels) {
- SinglePixelPackedSampleModel sm =
- (SinglePixelPackedSampleModel)srcImage.getSampleModel();
- int stride = sm.getScanlineStride();
- DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
- int[] buf = db.getData();
- encodeYUV(buf, width, stride, height, pixelFormat, dstBuf, yuvPad,
- subsamp, flags);
- } else {
- ComponentSampleModel sm =
- (ComponentSampleModel)srcImage.getSampleModel();
- int pixelSize = sm.getPixelStride();
- if (pixelSize != TJ.getPixelSize(pixelFormat))
- throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage");
- int pitch = sm.getScanlineStride();
- DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
- byte[] buf = db.getData();
- encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, yuvPad,
- subsamp, flags);
- }
- compressedSize = TJ.bufSizeYUV(width, yuvPad, height, subsamp);
+ setSourceImage(srcImage, 0, 0, 0, 0);
+ encodeYUV(dstBuf, flags);
}
/**
- * Encode the uncompressed source image stored in <code>srcImage</code>
- * and return a buffer containing a YUV planar image. See
- * {@link #encodeYUV(byte[], int)} for more detail.
- *
- * @param srcImage a <code>BufferedImage</code> instance containing RGB or
- * grayscale pixels to be encoded
- *
- * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
- *
- * @return a buffer containing a YUV planar image
+ * @deprecated Use
+ * {@link #setSourceImage(BufferedImage, int, int, int, int)} and
+ * {@link #encodeYUV(int)} instead.
*/
+ @Deprecated
public byte[] encodeYUV(BufferedImage srcImage, int flags) throws Exception {
- if (subsamp < 0)
- throw new Exception("Subsampling level not set");
- int width = srcImage.getWidth();
- int height = srcImage.getHeight();
- byte[] buf = new byte[TJ.bufSizeYUV(width, yuvPad, height, subsamp)];
- encodeYUV(srcImage, buf, flags);
- return buf;
+ setSourceImage(srcImage, 0, 0, 0, 0);
+ return encodeYUV(flags);
}
/**
private long handle = 0;
private byte[] srcBuf = null;
+ private int[] srcBufInt = null;
private int srcWidth = 0;
private int srcHeight = 0;
private int srcX = -1;
private int srcY = -1;
private int srcPitch = 0;
+ private int srcStride = 0;
private int srcPixelFormat = -1;
private int srcYUVPad = -1;
private boolean srcIsYUV;