Source Code Cross Referenced for ImageContent.java in  » Graphic-Library » fop » org » apache » fop » render » afp » modca » 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 » fop » org.apache.fop.render.afp.modca 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /* $Id: ImageContent.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020:        package org.apache.fop.render.afp.modca;
021:
022:        import java.io.IOException;
023:        import java.io.OutputStream;
024:        import org.apache.fop.render.afp.tools.BinaryUtils;
025:
026:        /**
027:         */
028:        public class ImageContent extends AbstractAFPObject {
029:
030:            /**
031:             * The image size parameter
032:             */
033:            private ImageSizeParameter _imageSizeParameter = null;
034:
035:            /**
036:             * The image encoding
037:             */
038:            private byte _encoding = 0x03;
039:
040:            /**
041:             * The image ide size
042:             */
043:            private byte _size = 1;
044:
045:            /**
046:             * The image compression
047:             */
048:            private byte _compression = (byte) 0xC0;
049:
050:            /**
051:             * The image color model
052:             */
053:            private byte _colorModel = 0x01;
054:
055:            /**
056:             * The image data
057:             */
058:            private byte _data[] = null;
059:
060:            /**
061:             * Constructor for the image content
062:             */
063:            public ImageContent() {
064:
065:            }
066:
067:            /**
068:             * Sets the image size parameters
069:             * resolution, hsize and vsize.
070:             * @param hresol The horizontal resolution of the image.
071:             * @param vresol The vertical resolution of the image.
072:             * @param hsize The horizontal size of the image.
073:             * @param vsize The vertival size of the image.
074:             */
075:            public void setImageSize(int hresol, int vresol, int hsize,
076:                    int vsize) {
077:                _imageSizeParameter = new ImageSizeParameter(hresol, vresol,
078:                        hsize, vsize);
079:            }
080:
081:            /**
082:             * Sets the image encoding.
083:             * @param encoding The image encoding.
084:             */
085:            public void setImageEncoding(byte encoding) {
086:                _encoding = encoding;
087:            }
088:
089:            /**
090:             * Sets the image compression.
091:             * @param compression The image compression.
092:             */
093:            public void setImageCompression(byte compression) {
094:                _compression = compression;
095:            }
096:
097:            /**
098:             * Sets the image IDE size.
099:             * @param size The IDE size.
100:             */
101:            public void setImageIDESize(byte size) {
102:                _size = size;
103:            }
104:
105:            /**
106:             * Sets the image IDE color model.
107:             * @param size The IDE color model.
108:             */
109:            public void setImageIDEColorModel(byte colorModel) {
110:                _colorModel = colorModel;
111:            }
112:
113:            /**
114:             * Set the data of the image.
115:             */
116:            public void setImageData(byte data[]) {
117:                _data = data;
118:            }
119:
120:            /**
121:             * Accessor method to write the AFP datastream for the Image Content
122:             * @param os The stream to write to
123:             * @throws java.io.IOException
124:             */
125:            public void writeDataStream(OutputStream os) throws IOException {
126:
127:                writeStart(os);
128:
129:                if (_imageSizeParameter != null) {
130:                    _imageSizeParameter.writeDataStream(os);
131:                }
132:
133:                os.write(getImageEncodingParameter());
134:
135:                os.write(getImageIDESizeParameter());
136:
137:                os.write(getIDEStructureParameter());
138:
139:                os.write(getExternalAlgorithmParameter());
140:
141:                if (_data != null) {
142:                    int off = 0;
143:                    while (off < _data.length) {
144:                        int len = Math.min(30000, _data.length - off);
145:                        os.write(getImageDataStart(len));
146:                        os.write(_data, off, len);
147:                        off += len;
148:                    }
149:                }
150:
151:                writeEnd(os);
152:
153:            }
154:
155:            /**
156:             * Helper method to write the start of the Image Content.
157:             * @param os The stream to write to
158:             */
159:            private void writeStart(OutputStream os) throws IOException {
160:
161:                byte[] data = new byte[] { (byte) 0x91, // ID
162:                        0x01, // Length
163:                        (byte) 0xff, // Object Type = IOCA Image Object
164:                };
165:
166:                os.write(data);
167:
168:            }
169:
170:            /**
171:             * Helper method to write the end of the Image Content.
172:             * @param os The stream to write to
173:             */
174:            private void writeEnd(OutputStream os) throws IOException {
175:
176:                byte[] data = new byte[] { (byte) 0x93, // ID
177:                        0x00, // Length
178:                };
179:
180:                os.write(data);
181:
182:            }
183:
184:            /**
185:             * Helper method to return the start of the image segment.
186:             * @return byte[] The data stream.
187:             */
188:            private byte[] getImageDataStart(int len) {
189:
190:                byte[] data = new byte[] { (byte) 0xFE, // ID
191:                        (byte) 0x92, // ID
192:                        0x00, // Length
193:                        0x00, // Length
194:                };
195:
196:                byte[] l = BinaryUtils.convert(len, 2);
197:                data[2] = l[0];
198:                data[3] = l[1];
199:
200:                return data;
201:
202:            }
203:
204:            /**
205:             * Helper method to return the image encoding parameter.
206:             * @return byte[] The data stream.
207:             */
208:            private byte[] getImageEncodingParameter() {
209:
210:                byte[] data = new byte[] { (byte) 0x95, // ID
211:                        0x02, // Length
212:                        _encoding, 0x01, // RECID
213:                };
214:
215:                return data;
216:
217:            }
218:
219:            /**
220:             * Helper method to return the external algorithm parameter.
221:             * @return byte[] The data stream.
222:             */
223:            private byte[] getExternalAlgorithmParameter() {
224:
225:                if (_encoding == (byte) 0x83 && _compression != 0) {
226:                    byte[] data = new byte[] { (byte) 0x95, // ID
227:                            0x00, // Length
228:                            0x10, // ALGTYPE = Compression Algorithm
229:                            0x00, // Reserved
230:                            (byte) 0x83, // COMPRID = JPEG
231:                            0x00, // Reserved
232:                            0x00, // Reserved
233:                            0x00, // Reserved
234:                            _compression, // MARKER
235:                            0x00, // Reserved
236:                            0x00, // Reserved
237:                            0x00, // Reserved
238:                    };
239:                    data[1] = (byte) (data.length - 2);
240:                    return data;
241:                }
242:                return new byte[0];
243:            }
244:
245:            /**
246:             * Helper method to return the image encoding parameter.
247:             * @return byte[] The data stream.
248:             */
249:            private byte[] getImageIDESizeParameter() {
250:
251:                byte[] data = new byte[] { (byte) 0x96, // ID
252:                        0x01, // Length
253:                        _size, };
254:
255:                return data;
256:
257:            }
258:
259:            /**
260:             * Helper method to return the external algorithm parameter.
261:             * @return byte[] The data stream.
262:             */
263:            private byte[] getIDEStructureParameter() {
264:
265:                if (_colorModel != 0 && _size == 24) {
266:                    byte bits = (byte) (_size / 3);
267:                    byte[] data = new byte[] { (byte) 0x9B, // ID
268:                            0x00, // Length
269:                            0x00, // FLAGS
270:                            0x00, // Reserved
271:                            _colorModel, // COLOR MODEL
272:                            0x00, // Reserved
273:                            0x00, // Reserved
274:                            0x00, // Reserved
275:                            bits, bits, bits, };
276:                    data[1] = (byte) (data.length - 2);
277:                    return data;
278:                }
279:                return new byte[0];
280:            }
281:
282:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.