Source Code Cross Referenced for PngHuffmanTables.java in  » IDE-Eclipse » swt » org » eclipse » swt » internal » image » 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 » IDE Eclipse » swt » org.eclipse.swt.internal.image 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.swt.internal.image;
011:
012:        import java.io.*;
013:
014:        public class PngHuffmanTables {
015:            PngHuffmanTable literalTable;
016:            PngHuffmanTable distanceTable;
017:
018:            static PngHuffmanTable FixedLiteralTable;
019:            static PngHuffmanTable FixedDistanceTable;
020:
021:            static final int LiteralTableSize = 288;
022:            static final int[] FixedLiteralLengths = { 8, 8, 8, 8, 8, 8, 8, 8,
023:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
024:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
025:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
026:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
027:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
028:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
029:                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
030:                    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
031:                    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
032:                    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
033:                    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
034:                    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
035:                    9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
036:                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, };
037:
038:            static final int DistanceTableSize = 32;
039:            static final int[] FixedDistanceLengths = { 5, 5, 5, 5, 5, 5, 5, 5,
040:                    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
041:                    5, 5, 5, 5, };
042:
043:            static final int LengthCodeTableSize = 19;
044:            static final int[] LengthCodeOrder = { 16, 17, 18, 0, 8, 7, 9, 6,
045:                    10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
046:
047:            static PngHuffmanTables getDynamicTables(
048:                    PngDecodingDataStream stream) throws IOException {
049:                return new PngHuffmanTables(stream);
050:            }
051:
052:            static PngHuffmanTables getFixedTables() {
053:                return new PngHuffmanTables();
054:            }
055:
056:            private PngHuffmanTable getFixedLiteralTable() {
057:                if (FixedLiteralTable == null) {
058:                    FixedLiteralTable = new PngHuffmanTable(FixedLiteralLengths);
059:                }
060:                return FixedLiteralTable;
061:            }
062:
063:            private PngHuffmanTable getFixedDistanceTable() {
064:                if (FixedDistanceTable == null) {
065:                    FixedDistanceTable = new PngHuffmanTable(
066:                            FixedDistanceLengths);
067:                }
068:                return FixedDistanceTable;
069:            }
070:
071:            private PngHuffmanTables() {
072:                literalTable = getFixedLiteralTable();
073:                distanceTable = getFixedDistanceTable();
074:            }
075:
076:            private PngHuffmanTables(PngDecodingDataStream stream)
077:                    throws IOException {
078:                int literals = PngLzBlockReader.FIRST_LENGTH_CODE
079:                        + stream.getNextIdatBits(5);
080:                int distances = PngLzBlockReader.FIRST_DISTANCE_CODE
081:                        + stream.getNextIdatBits(5);
082:                int codeLengthCodes = PngLzBlockReader.FIRST_CODE_LENGTH_CODE
083:                        + stream.getNextIdatBits(4);
084:
085:                if (codeLengthCodes > PngLzBlockReader.LAST_CODE_LENGTH_CODE) {
086:                    stream.error();
087:                }
088:
089:                /* Tricky, tricky, tricky. The length codes are stored in
090:                 * a very odd order. (For the order, see the definition of
091:                 * the static field lengthCodeOrder.) Also, the data may 
092:                 * not contain values for all the codes. It may just contain 
093:                 * values for the first X number of codes. The table should
094:                 * be of size <LengthCodeTableSize> regardless of the number
095:                 * of values actually given in the table.
096:                 */
097:                int[] lengthCodes = new int[LengthCodeTableSize];
098:                for (int i = 0; i < codeLengthCodes; i++) {
099:                    lengthCodes[LengthCodeOrder[i]] = stream.getNextIdatBits(3);
100:                }
101:                PngHuffmanTable codeLengthsTable = new PngHuffmanTable(
102:                        lengthCodes);
103:
104:                int[] literalLengths = readLengths(stream, literals,
105:                        codeLengthsTable, LiteralTableSize);
106:                int[] distanceLengths = readLengths(stream, distances,
107:                        codeLengthsTable, DistanceTableSize);
108:
109:                literalTable = new PngHuffmanTable(literalLengths);
110:                distanceTable = new PngHuffmanTable(distanceLengths);
111:            }
112:
113:            private int[] readLengths(PngDecodingDataStream stream,
114:                    int numLengths, PngHuffmanTable lengthsTable, int tableSize)
115:                    throws IOException {
116:                int[] lengths = new int[tableSize];
117:
118:                for (int index = 0; index < numLengths;) {
119:                    int value = lengthsTable.getNextValue(stream);
120:                    if (value < 16) {
121:                        // Literal value
122:                        lengths[index] = value;
123:                        index++;
124:                    } else if (value == 16) {
125:                        // Repeat the previous code 3-6 times.
126:                        int count = stream.getNextIdatBits(2) + 3;
127:                        for (int i = 0; i < count; i++) {
128:                            lengths[index] = lengths[index - 1];
129:                            index++;
130:                        }
131:                    } else if (value == 17) {
132:                        // Repeat 0 3-10 times.
133:                        int count = stream.getNextIdatBits(3) + 3;
134:                        for (int i = 0; i < count; i++) {
135:                            lengths[index] = 0;
136:                            index++;
137:                        }
138:                    } else if (value == 18) {
139:                        // Repeat 0 11-138 times.
140:                        int count = stream.getNextIdatBits(7) + 11;
141:                        for (int i = 0; i < count; i++) {
142:                            lengths[index] = 0;
143:                            index++;
144:                        }
145:                    } else {
146:                        stream.error();
147:                    }
148:                }
149:                return lengths;
150:            }
151:
152:            int getNextLiteralValue(PngDecodingDataStream stream)
153:                    throws IOException {
154:                return literalTable.getNextValue(stream);
155:            }
156:
157:            int getNextDistanceValue(PngDecodingDataStream stream)
158:                    throws IOException {
159:                return distanceTable.getNextValue(stream);
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.