Java Doc for PngEncoder.java in  » Graphic-Library » jcommon-components » com » keypoint » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » jcommon components » com.keypoint 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.keypoint.PngEncoder

PngEncoder
public class PngEncoder (Code)
PngEncoder takes a Java Image object and creates a byte string which can be saved as a PNG file. The Image is presumed to use the DirectColorModel.

Thanks to Jay Denny at KeyPoint Software http://www.keypoint.com/ who let me develop this code on company time.

You may contact me with (probably very-much-needed) improvements, comments, and bug fixes at:

david@catcode.com

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. A copy of the GNU LGPL may be found at http://www.gnu.org/copyleft/lesser.html


author:
   J. David Eisenberg
version:
   1.5, 19 Oct 2003
version:
   CHANGES:
version:
   --------
version:
   19-Nov-2002 : CODING STYLE CHANGES ONLY (by David Gilbert for Object
version:
   Refinery Limited);
version:
   19-Sep-2003 : Fix for platforms using EBCDIC (contributed by Paulo Soares);
version:
   19-Oct-2003 : Change private fields to protected fields so that
version:
   PngEncoderB can inherit them (JDE)
version:
   Fixed bug with calculation of nRows


Field Summary
final public static  booleanENCODE_ALPHA
     Constant specifying that alpha channel should be encoded.
final public static  intFILTER_LAST
     Constants for filter (LAST).
final public static  intFILTER_NONE
     Constants for filter (NONE).
final public static  intFILTER_SUB
     Constants for filter (SUB).
final public static  intFILTER_UP
     Constants for filter (UP).
final protected static  byte[]IDAT
     IDAT tag.
final protected static  byte[]IEND
     IEND tag.
final protected static  byte[]IHDR
     IHDR tag.
final public static  booleanNO_ALPHA
     Constant specifying that alpha channel should not be encoded.
final protected static  byte[]PHYS
    
protected  intbytePos
     The byte position.
protected  intbytesPerPixel
     The bytes-per-pixel.
protected  intcompressionLevel
     The compression level (1 = best speed, 9 = best compression, 0 = no compression).
protected  CRC32crc
     CRC.
protected  longcrcValue
     The CRC value.
protected  booleanencodeAlpha
    
protected  intfilter
     The filter type.
protected  intheight
     The height.
protected  Imageimage
     The image.
protected  byte[]leftBytes
     The left bytes.
protected  intmaxPos
     The maximum position.
protected  byte[]pngBytes
     The png bytes.
protected  byte[]priorRow
     The prior row.
protected  intwidth
     The width.

Constructor Summary
public  PngEncoder()
     Class constructor.
public  PngEncoder(Image image)
     Class constructor specifying Image to encode, with no alpha channel encoding.
public  PngEncoder(Image image, boolean encodeAlpha)
     Class constructor specifying Image to encode, and whether to encode alpha.
public  PngEncoder(Image image, boolean encodeAlpha, int whichFilter)
     Class constructor specifying Image to encode, whether to encode alpha, and filter to use.
public  PngEncoder(Image image, boolean encodeAlpha, int whichFilter, int compLevel)
     Class constructor specifying Image source to encode, whether to encode alpha, filter to use, and compression level.

Method Summary
protected  voidfilterSub(byte[] pixels, int startPos, int width)
     Perform "sub" filtering on the given row. Uses temporary array leftBytes to store the original values of the previous pixels.
protected  voidfilterUp(byte[] pixels, int startPos, int width)
     Perform "up" filtering on the given row.
public  intgetCompressionLevel()
     Retrieve compression level.
public  booleangetEncodeAlpha()
     Retrieve alpha encoding status.
public  intgetFilter()
     Retrieve filtering scheme.
public  ImagegetImage()
     Returns the image to be encoded.
public  intgetXDpi()
     Get the DPI for the X axis.
public  intgetYDpi()
     Get the DPI for the Y axis.
public  byte[]pngEncode(boolean encodeAlpha)
     Creates an array of bytes that is the PNG equivalent of the current image, specifying whether to encode alpha or not.
public  byte[]pngEncode()
     Creates an array of bytes that is the PNG equivalent of the current image.
protected  byte[]resizeByteArray(byte[] array, int newLength)
     Increase or decrease the length of a byte array.
Parameters:
  array - The original array.
Parameters:
  newLength - The length you wish the new array to have.
public  voidsetCompressionLevel(int level)
     Set the compression level to use.
public  voidsetDpi(int xDpi, int yDpi)
     Set the DPI resolution.
public  voidsetEncodeAlpha(boolean encodeAlpha)
     Set the alpha encoding on or off.
public  voidsetFilter(int whichFilter)
     Set the filter to use.
public  voidsetImage(Image image)
     Set the image to be encoded.
public  voidsetXDpi(int xDpi)
     Set the DPI for the X axis.
public  voidsetYDpi(int yDpi)
     Set the DPI for the Y axis.
protected  intwriteByte(int b, int offset)
     Write a single byte into the pngBytes array at a given position.
Parameters:
  b - The integer to be written into pngBytes.
Parameters:
  offset - The starting point to write to.
protected  intwriteBytes(byte[] data, int offset)
     Write an array of bytes into the pngBytes array. Note: This routine has the side effect of updating maxPos, the largest element written in the array. The array is resized by 1000 bytes or the length of the data to be written, whichever is larger.
Parameters:
  data - The data to be written into pngBytes.
Parameters:
  offset - The starting point to write to.
protected  intwriteBytes(byte[] data, int nBytes, int offset)
     Write an array of bytes into the pngBytes array, specifying number of bytes to write.
protected  voidwriteEnd()
     Write a PNG "IEND" chunk into the pngBytes array.
protected  voidwriteHeader()
     Write a PNG "IHDR" chunk into the pngBytes array.
protected  booleanwriteImageData()
     Write the image data into the pngBytes array. This will write one or more PNG "IDAT" chunks.
protected  intwriteInt2(int n, int offset)
     Write a two-byte integer into the pngBytes array at a given position.
Parameters:
  n - The integer to be written into pngBytes.
Parameters:
  offset - The starting point to write to.
protected  intwriteInt4(int n, int offset)
     Write a four-byte integer into the pngBytes array at a given position.
Parameters:
  n - The integer to be written into pngBytes.
Parameters:
  offset - The starting point to write to.
protected  voidwriteResolution()
     Write a PNG "pHYs" chunk into the pngBytes array.

Field Detail
ENCODE_ALPHA
final public static boolean ENCODE_ALPHA(Code)
Constant specifying that alpha channel should be encoded.



FILTER_LAST
final public static int FILTER_LAST(Code)
Constants for filter (LAST).



FILTER_NONE
final public static int FILTER_NONE(Code)
Constants for filter (NONE).



FILTER_SUB
final public static int FILTER_SUB(Code)
Constants for filter (SUB).



FILTER_UP
final public static int FILTER_UP(Code)
Constants for filter (UP).



IDAT
final protected static byte[] IDAT(Code)
IDAT tag.



IEND
final protected static byte[] IEND(Code)
IEND tag.



IHDR
final protected static byte[] IHDR(Code)
IHDR tag.



NO_ALPHA
final public static boolean NO_ALPHA(Code)
Constant specifying that alpha channel should not be encoded.



PHYS
final protected static byte[] PHYS(Code)



bytePos
protected int bytePos(Code)
The byte position.



bytesPerPixel
protected int bytesPerPixel(Code)
The bytes-per-pixel.



compressionLevel
protected int compressionLevel(Code)
The compression level (1 = best speed, 9 = best compression, 0 = no compression).



crc
protected CRC32 crc(Code)
CRC.



crcValue
protected long crcValue(Code)
The CRC value.



encodeAlpha
protected boolean encodeAlpha(Code)
Encode alpha?



filter
protected int filter(Code)
The filter type.



height
protected int height(Code)
The height.



image
protected Image image(Code)
The image.



leftBytes
protected byte[] leftBytes(Code)
The left bytes.



maxPos
protected int maxPos(Code)
The maximum position.



pngBytes
protected byte[] pngBytes(Code)
The png bytes.



priorRow
protected byte[] priorRow(Code)
The prior row.



width
protected int width(Code)
The width.




Constructor Detail
PngEncoder
public PngEncoder()(Code)
Class constructor.



PngEncoder
public PngEncoder(Image image)(Code)
Class constructor specifying Image to encode, with no alpha channel encoding.
Parameters:
  image - A Java Image object which uses the DirectColorModel
See Also:   java.awt.Image



PngEncoder
public PngEncoder(Image image, boolean encodeAlpha)(Code)
Class constructor specifying Image to encode, and whether to encode alpha.
Parameters:
  image - A Java Image object which uses the DirectColorModel
Parameters:
  encodeAlpha - Encode the alpha channel? false=no; true=yes
See Also:   java.awt.Image



PngEncoder
public PngEncoder(Image image, boolean encodeAlpha, int whichFilter)(Code)
Class constructor specifying Image to encode, whether to encode alpha, and filter to use.
Parameters:
  image - A Java Image object which uses the DirectColorModel
Parameters:
  encodeAlpha - Encode the alpha channel? false=no; true=yes
Parameters:
  whichFilter - 0=none, 1=sub, 2=up
See Also:   java.awt.Image



PngEncoder
public PngEncoder(Image image, boolean encodeAlpha, int whichFilter, int compLevel)(Code)
Class constructor specifying Image source to encode, whether to encode alpha, filter to use, and compression level.
Parameters:
  image - A Java Image object
Parameters:
  encodeAlpha - Encode the alpha channel? false=no; true=yes
Parameters:
  whichFilter - 0=none, 1=sub, 2=up
Parameters:
  compLevel - 0..9 (1 = best speed, 9 = best compression, 0 = no compression)
See Also:   java.awt.Image




Method Detail
filterSub
protected void filterSub(byte[] pixels, int startPos, int width)(Code)
Perform "sub" filtering on the given row. Uses temporary array leftBytes to store the original values of the previous pixels. The array is 16 bytes long, which will easily hold two-byte samples plus two-byte alpha.
Parameters:
  pixels - The array holding the scan lines being built
Parameters:
  startPos - Starting position within pixels of bytes to be filtered.
Parameters:
  width - Width of a scanline in pixels.



filterUp
protected void filterUp(byte[] pixels, int startPos, int width)(Code)
Perform "up" filtering on the given row. Side effect: refills the prior row with current row
Parameters:
  pixels - The array holding the scan lines being built
Parameters:
  startPos - Starting position within pixels of bytes to be filtered.
Parameters:
  width - Width of a scanline in pixels.



getCompressionLevel
public int getCompressionLevel()(Code)
Retrieve compression level. int (1 = best speed, 9 = best compression, 0 = no compression)



getEncodeAlpha
public boolean getEncodeAlpha()(Code)
Retrieve alpha encoding status. boolean false=no, true=yes



getFilter
public int getFilter()(Code)
Retrieve filtering scheme. int (see constant list)



getImage
public Image getImage()(Code)
Returns the image to be encoded.



getXDpi
public int getXDpi()(Code)
Get the DPI for the X axis. The number of dots per inch



getYDpi
public int getYDpi()(Code)
Get the DPI for the Y axis. The number of dots per inch



pngEncode
public byte[] pngEncode(boolean encodeAlpha)(Code)
Creates an array of bytes that is the PNG equivalent of the current image, specifying whether to encode alpha or not.
Parameters:
  encodeAlpha - boolean false=no alpha, true=encode alpha an array of bytes, or null if there was a problem



pngEncode
public byte[] pngEncode()(Code)
Creates an array of bytes that is the PNG equivalent of the current image. Alpha encoding is determined by its setting in the constructor. an array of bytes, or null if there was a problem



resizeByteArray
protected byte[] resizeByteArray(byte[] array, int newLength)(Code)
Increase or decrease the length of a byte array.
Parameters:
  array - The original array.
Parameters:
  newLength - The length you wish the new array to have. Array of newly desired length. If shorter than theoriginal, the trailing elements are truncated.



setCompressionLevel
public void setCompressionLevel(int level)(Code)
Set the compression level to use.
Parameters:
  level - the compression level (1 = best speed, 9 = best compression,0 = no compression)



setDpi
public void setDpi(int xDpi, int yDpi)(Code)
Set the DPI resolution.
Parameters:
  xDpi - The number of dots per inch for the X axis.
Parameters:
  yDpi - The number of dots per inch for the Y axis.



setEncodeAlpha
public void setEncodeAlpha(boolean encodeAlpha)(Code)
Set the alpha encoding on or off.
Parameters:
  encodeAlpha - false=no, true=yes



setFilter
public void setFilter(int whichFilter)(Code)
Set the filter to use.
Parameters:
  whichFilter - from constant list



setImage
public void setImage(Image image)(Code)
Set the image to be encoded.
Parameters:
  image - A Java Image object which uses the DirectColorModel
See Also:   java.awt.Image
See Also:   java.awt.image.DirectColorModel



setXDpi
public void setXDpi(int xDpi)(Code)
Set the DPI for the X axis.
Parameters:
  xDpi - The number of dots per inch



setYDpi
public void setYDpi(int yDpi)(Code)
Set the DPI for the Y axis.
Parameters:
  yDpi - The number of dots per inch



writeByte
protected int writeByte(int b, int offset)(Code)
Write a single byte into the pngBytes array at a given position.
Parameters:
  b - The integer to be written into pngBytes.
Parameters:
  offset - The starting point to write to. The next place to be written to in the pngBytes array.



writeBytes
protected int writeBytes(byte[] data, int offset)(Code)
Write an array of bytes into the pngBytes array. Note: This routine has the side effect of updating maxPos, the largest element written in the array. The array is resized by 1000 bytes or the length of the data to be written, whichever is larger.
Parameters:
  data - The data to be written into pngBytes.
Parameters:
  offset - The starting point to write to. The next place to be written to in the pngBytes array.



writeBytes
protected int writeBytes(byte[] data, int nBytes, int offset)(Code)
Write an array of bytes into the pngBytes array, specifying number of bytes to write. Note: This routine has the side effect of updating maxPos, the largest element written in the array. The array is resized by 1000 bytes or the length of the data to be written, whichever is larger.
Parameters:
  data - The data to be written into pngBytes.
Parameters:
  nBytes - The number of bytes to be written.
Parameters:
  offset - The starting point to write to. The next place to be written to in the pngBytes array.



writeEnd
protected void writeEnd()(Code)
Write a PNG "IEND" chunk into the pngBytes array.



writeHeader
protected void writeHeader()(Code)
Write a PNG "IHDR" chunk into the pngBytes array.



writeImageData
protected boolean writeImageData()(Code)
Write the image data into the pngBytes array. This will write one or more PNG "IDAT" chunks. In order to conserve memory, this method grabs as many rows as will fit into 32K bytes, or the whole image; whichever is less. true if no errors; false if error grabbing pixels



writeInt2
protected int writeInt2(int n, int offset)(Code)
Write a two-byte integer into the pngBytes array at a given position.
Parameters:
  n - The integer to be written into pngBytes.
Parameters:
  offset - The starting point to write to. The next place to be written to in the pngBytes array.



writeInt4
protected int writeInt4(int n, int offset)(Code)
Write a four-byte integer into the pngBytes array at a given position.
Parameters:
  n - The integer to be written into pngBytes.
Parameters:
  offset - The starting point to write to. The next place to be written to in the pngBytes array.



writeResolution
protected void writeResolution()(Code)
Write a PNG "pHYs" chunk into the pngBytes array.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.