View | Details | Raw Unified | Return to bug 42028
Collapse All | Expand All

(-)src/java-1.4/org/apache/fop/image/ImageIOImage.java.orig (-11 / +41 lines)
Lines 94-101 Link Here
94
            ImageReadParam param = reader.getDefaultReadParam();
94
            ImageReadParam param = reader.getDefaultReadParam();
95
            reader.setInput(imgStream, true, false);
95
            reader.setInput(imgStream, true, false);
96
            BufferedImage imageData = reader.read(0, param);
96
            BufferedImage imageData = reader.read(0, param);
97
            
97
98
            //Read image size
99
            IIOMetadata streammeta = reader.getStreamMetadata();
100
            if (streammeta != null && streammeta.isStandardMetadataFormatSupported()) {
101
                Element metanode = (Element)streammeta.getAsTree("javax_imageio_1.0");
102
                Element dim = getChild(metanode, "Dimension");
103
                if (dim != null) {
104
                    Element child;
105
                    child = getChild(dim, "HorizontalScreenSize");
106
                    if (child != null) {
107
                        this.width = Integer.parseInt(child.getAttribute("value"));
108
                    }
109
                    child = getChild(dim, "VerticalScreenSize");
110
                    if (child != null) {
111
                        this.height = Integer.parseInt(child.getAttribute("value"));
112
                    }
113
                }
114
            }
115
98
            //Read image resolution
116
            //Read image resolution
117
            int horizontalOffset = 0;
118
            int verticalOffset = 0;
99
            IIOMetadata iiometa = reader.getImageMetadata(0);
119
            IIOMetadata iiometa = reader.getImageMetadata(0);
100
            if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {
120
            if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {
101
                Element metanode = (Element)iiometa.getAsTree("javax_imageio_1.0");
121
                Element metanode = (Element)iiometa.getAsTree("javax_imageio_1.0");
Lines 112-124 Link Here
112
                        this.dpiVertical = UnitConv.IN2MM
132
                        this.dpiVertical = UnitConv.IN2MM
113
                                / Float.parseFloat(child.getAttribute("value"));
133
                                / Float.parseFloat(child.getAttribute("value"));
114
                    }
134
                    }
135
                    child = getChild(dim, "HorizontalPixelOffset");
136
                    if (child != null) {
137
                        horizontalOffset = Integer.parseInt(child.getAttribute("value"));
138
                    }
139
                    child = getChild(dim, "VerticalPixelOffset");
140
                    if (child != null) {
141
                        verticalOffset = Integer.parseInt(child.getAttribute("value"));
142
                    }
115
                }
143
                }
116
            }
144
            }
117
            imgStream.close();
145
            imgStream.close();
118
            reader.dispose();
146
            reader.dispose();
119
            
147
            
120
            this.height = imageData.getHeight();
148
            int dataHeight = imageData.getHeight();
121
            this.width = imageData.getWidth();
149
            int dataWidth = imageData.getWidth();
122
150
123
            ColorModel cm = imageData.getColorModel();
151
            ColorModel cm = imageData.getColorModel();
124
            this.bitsPerPixel = cm.getComponentSize(0); //only use first, we assume all are equal
152
            this.bitsPerPixel = cm.getComponentSize(0); //only use first, we assume all are equal
Lines 126-133 Link Here
126
            //We currently force the image to sRGB
154
            //We currently force the image to sRGB
127
            this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
155
            this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
128
156
129
            int[] tmpMap = imageData.getRGB(0, 0, this.width,
157
            int[] tmpMap = imageData.getRGB(0, 0, dataWidth,
130
                                            this.height, null, 0, this.width);
158
                                            dataHeight, null, 0, dataWidth);
131
159
132
            if (cm.hasAlpha()) {
160
            if (cm.hasAlpha()) {
133
                // java.awt.Transparency. BITMASK or OPAQUE or TRANSLUCENT
161
                // java.awt.Transparency. BITMASK or OPAQUE or TRANSLUCENT
Lines 187-203 Link Here
187
215
188
            // Should take care of the ColorSpace and bitsPerPixel
216
            // Should take care of the ColorSpace and bitsPerPixel
189
            this.bitmaps = new byte[this.width * this.height * 3];
217
            this.bitmaps = new byte[this.width * this.height * 3];
190
            for (int i = 0; i < this.height; i++) {
218
            for (int i = 0; i < dataHeight; i++) {
191
                for (int j = 0; j < this.width; j++) {
219
                int realI = i + verticalOffset;
192
                    int p = tmpMap[i * this.width + j];
220
                for (int j = 0; j < dataWidth; j++) {
221
                    int realJ = j + horizontalOffset;
222
                    int p = tmpMap[i * dataWidth + j];
193
                    int r = (p >> 16) & 0xFF;
223
                    int r = (p >> 16) & 0xFF;
194
                    int g = (p >> 8) & 0xFF;
224
                    int g = (p >> 8) & 0xFF;
195
                    int b = (p) & 0xFF;
225
                    int b = (p) & 0xFF;
196
                    this.bitmaps[3 * (i * this.width + j)] 
226
                    this.bitmaps[3 * (realI * this.width + realJ)]
197
                        = (byte)(r & 0xFF);
227
                        = (byte)(r & 0xFF);
198
                    this.bitmaps[3 * (i * this.width + j) + 1] 
228
                    this.bitmaps[3 * (realI * this.width + realJ) + 1]
199
                        = (byte)(g & 0xFF);
229
                        = (byte)(g & 0xFF);
200
                    this.bitmaps[3 * (i * this.width + j) + 2] 
230
                    this.bitmaps[3 * (realI * this.width + realJ) + 2]
201
                        = (byte)(b & 0xFF);
231
                        = (byte)(b & 0xFF);
202
                }
232
                }
203
            }
233
            }

Return to bug 42028