Source Code Cross Referenced for JPEGFrameHeader.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, 2005 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 org.eclipse.swt.*;
013:
014:        final class JPEGFrameHeader extends JPEGVariableSizeSegment {
015:            int maxVFactor;
016:            int maxHFactor;
017:            public int[] componentIdentifiers;
018:            public int[][] componentParameters;
019:
020:            public JPEGFrameHeader(byte[] reference) {
021:                super (reference);
022:            }
023:
024:            public JPEGFrameHeader(LEDataInputStream byteStream) {
025:                super (byteStream);
026:                initializeComponentParameters();
027:            }
028:
029:            public int getSamplePrecision() {
030:                return reference[4] & 0xFF;
031:            }
032:
033:            public int getNumberOfLines() {
034:                return (reference[5] & 0xFF) << 8 | (reference[6] & 0xFF);
035:            }
036:
037:            public int getSamplesPerLine() {
038:                return (reference[7] & 0xFF) << 8 | (reference[8] & 0xFF);
039:            }
040:
041:            public int getNumberOfImageComponents() {
042:                return reference[9] & 0xFF;
043:            }
044:
045:            public void setSamplePrecision(int precision) {
046:                reference[4] = (byte) (precision & 0xFF);
047:            }
048:
049:            public void setNumberOfLines(int anInteger) {
050:                reference[5] = (byte) ((anInteger & 0xFF00) >> 8);
051:                reference[6] = (byte) (anInteger & 0xFF);
052:            }
053:
054:            public void setSamplesPerLine(int samples) {
055:                reference[7] = (byte) ((samples & 0xFF00) >> 8);
056:                reference[8] = (byte) (samples & 0xFF);
057:            }
058:
059:            public void setNumberOfImageComponents(int anInteger) {
060:                reference[9] = (byte) (anInteger & 0xFF);
061:            }
062:
063:            public int getMaxHFactor() {
064:                return maxHFactor;
065:            }
066:
067:            public int getMaxVFactor() {
068:                return maxVFactor;
069:            }
070:
071:            public void setMaxHFactor(int anInteger) {
072:                maxHFactor = anInteger;
073:            }
074:
075:            public void setMaxVFactor(int anInteger) {
076:                maxVFactor = anInteger;
077:            }
078:
079:            /* Used when decoding. */
080:            void initializeComponentParameters() {
081:                int nf = getNumberOfImageComponents();
082:                componentIdentifiers = new int[nf];
083:                int[][] compSpecParams = new int[0][];
084:                int hmax = 1;
085:                int vmax = 1;
086:                for (int i = 0; i < nf; i++) {
087:                    int ofs = i * 3 + 10;
088:                    int ci = reference[ofs] & 0xFF;
089:                    componentIdentifiers[i] = ci;
090:                    int hi = (reference[ofs + 1] & 0xFF) >> 4;
091:                    int vi = reference[ofs + 1] & 0xF;
092:                    int tqi = reference[ofs + 2] & 0xFF;
093:                    if (hi > hmax) {
094:                        hmax = hi;
095:                    }
096:                    if (vi > vmax) {
097:                        vmax = vi;
098:                    }
099:                    int[] compParam = new int[5];
100:                    compParam[0] = tqi;
101:                    compParam[1] = hi;
102:                    compParam[2] = vi;
103:                    if (compSpecParams.length <= ci) {
104:                        int[][] newParams = new int[ci + 1][];
105:                        System.arraycopy(compSpecParams, 0, newParams, 0,
106:                                compSpecParams.length);
107:                        compSpecParams = newParams;
108:                    }
109:                    compSpecParams[ci] = compParam;
110:                }
111:                int x = getSamplesPerLine();
112:                int y = getNumberOfLines();
113:                int[] multiples = new int[] { 8, 16, 24, 32 };
114:                for (int i = 0; i < nf; i++) {
115:                    int[] compParam = compSpecParams[componentIdentifiers[i]];
116:                    int hi = compParam[1];
117:                    int vi = compParam[2];
118:                    int compWidth = (x * hi + hmax - 1) / hmax;
119:                    int compHeight = (y * vi + vmax - 1) / vmax;
120:                    int dsWidth = roundUpToMultiple(compWidth,
121:                            multiples[hi - 1]);
122:                    int dsHeight = roundUpToMultiple(compHeight,
123:                            multiples[vi - 1]);
124:                    compParam[3] = dsWidth;
125:                    compParam[4] = dsHeight;
126:                }
127:                setMaxHFactor(hmax);
128:                setMaxVFactor(vmax);
129:                componentParameters = compSpecParams;
130:            }
131:
132:            /* Used when encoding. */
133:            public void initializeContents() {
134:                int nf = getNumberOfImageComponents();
135:                if (nf == 0 || nf != componentParameters.length) {
136:                    SWT.error(SWT.ERROR_INVALID_IMAGE);
137:                }
138:                int hmax = 0;
139:                int vmax = 0;
140:                int[][] compSpecParams = componentParameters;
141:                for (int i = 0; i < nf; i++) {
142:                    int ofs = i * 3 + 10;
143:                    int[] compParam = compSpecParams[componentIdentifiers[i]];
144:                    int hi = compParam[1];
145:                    int vi = compParam[2];
146:                    if (hi * vi > 4) {
147:                        SWT.error(SWT.ERROR_INVALID_IMAGE);
148:                    }
149:                    reference[ofs] = (byte) (i + 1);
150:                    reference[ofs + 1] = (byte) (hi * 16 + vi);
151:                    reference[ofs + 2] = (byte) (compParam[0]);
152:                    if (hi > hmax)
153:                        hmax = hi;
154:                    if (vi > vmax)
155:                        vmax = vi;
156:                }
157:                int x = getSamplesPerLine();
158:                int y = getNumberOfLines();
159:                int[] multiples = new int[] { 8, 16, 24, 32 };
160:                for (int i = 0; i < nf; i++) {
161:                    int[] compParam = compSpecParams[componentIdentifiers[i]];
162:                    int hi = compParam[1];
163:                    int vi = compParam[2];
164:                    int compWidth = (x * hi + hmax - 1) / hmax;
165:                    int compHeight = (y * vi + vmax - 1) / vmax;
166:                    int dsWidth = roundUpToMultiple(compWidth,
167:                            multiples[hi - 1]);
168:                    int dsHeight = roundUpToMultiple(compHeight,
169:                            multiples[vi - 1]);
170:                    compParam[3] = dsWidth;
171:                    compParam[4] = dsHeight;
172:                }
173:                setMaxHFactor(hmax);
174:                setMaxVFactor(vmax);
175:            }
176:
177:            int roundUpToMultiple(int anInteger, int mInteger) {
178:                int a = anInteger + mInteger - 1;
179:                return a - (a % mInteger);
180:            }
181:
182:            /*
183:             * Verify the information contained in the receiver is correct.
184:             * Answer true if the header contains a valid marker. Otherwise,
185:             * answer false. Valid Start Of Frame markers are:
186:             *	SOF_0  - Baseline DCT, Huffman coding
187:             *	SOF_1  - Extended sequential DCT, Huffman coding
188:             *	SOF_2  - Progressive DCT, Huffman coding
189:             *	SOF_3  - Lossless (sequential), Huffman coding
190:             *	SOF_5  - Differential sequential, Huffman coding
191:             *	SOF_6  - Differential progressive, Huffman coding
192:             *	SOF_7  - Differential lossless, Huffman coding
193:             *	SOF_9  - Extended sequential DCT, arithmetic coding
194:             *	SOF_10 - Progressive DCT, arithmetic coding
195:             *	SOF_11 - Lossless (sequential), arithmetic coding
196:             *	SOF_13 - Differential sequential, arithmetic coding
197:             *	SOF_14 - Differential progressive, arithmetic coding
198:             *	SOF_15 - Differential lossless, arithmetic coding
199:             */
200:            public boolean verify() {
201:                int marker = getSegmentMarker();
202:                return (marker >= JPEGFileFormat.SOF0 && marker <= JPEGFileFormat.SOF3)
203:                        || (marker >= JPEGFileFormat.SOF5 && marker <= JPEGFileFormat.SOF7)
204:                        || (marker >= JPEGFileFormat.SOF9 && marker <= JPEGFileFormat.SOF11)
205:                        || (marker >= JPEGFileFormat.SOF13 && marker <= JPEGFileFormat.SOF15);
206:            }
207:
208:            public boolean isProgressive() {
209:                int marker = getSegmentMarker();
210:                return marker == JPEGFileFormat.SOF2
211:                        || marker == JPEGFileFormat.SOF6
212:                        || marker == JPEGFileFormat.SOF10
213:                        || marker == JPEGFileFormat.SOF14;
214:            }
215:
216:            public boolean isArithmeticCoding() {
217:                return getSegmentMarker() >= JPEGFileFormat.SOF9;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.