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

(-)test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFaxTestCase.java (+54 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
/* $Id$ */
19
20
package org.apache.xmlgraphics.image.loader.impl;
21
22
import junit.framework.TestCase;
23
24
import org.apache.xmlgraphics.image.loader.ImageContext;
25
import org.apache.xmlgraphics.image.loader.ImageInfo;
26
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
27
import org.apache.xmlgraphics.image.loader.ImageSize;
28
import org.apache.xmlgraphics.image.loader.MockImageContext;
29
import org.apache.xmlgraphics.image.loader.MockImageSessionContext;
30
import org.apache.xmlgraphics.util.MimeConstants;
31
32
/**
33
 * Test case for {@link ImageLoaderRawCCITTFax}. 
34
 */
35
public class ImageLoaderRawCCITTFaxTestCase extends TestCase {
36
    private ImageLoaderRawCCITTFax sut;
37
38
    public void testLoadImage() throws Exception {
39
        ImageContext context = MockImageContext.newSafeInstance();
40
        ImageSessionContext session = new MockImageSessionContext(context);
41
        // This image file is NOT a valid tif! It is the directory table ONLY.
42
        ImageInfo info = new ImageInfo("dirOnly.tif", MimeConstants.MIME_TIFF);
43
        ImageSize size = new ImageSize();
44
        // Size data can be retrieve by parsing the directory table in the TIFF
45
        size.setSizeInPixels(1728, 2266);
46
        size.setResolution(203, 192);
47
        size.calcSizeFromPixels();
48
        info.setSize(size);
49
50
        sut = new ImageLoaderRawCCITTFax();
51
        ImageRawCCITTFax rawImage = (ImageRawCCITTFax) sut.loadImage(info, null, session);
52
        assertEquals(2, rawImage.getCompression());
53
    }
54
}
(-)src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFax.java (-3 / +19 lines)
Lines 51-56 Link Here
51
 */
51
 */
52
public class ImageLoaderRawCCITTFax extends AbstractImageLoader implements JPEGConstants {
52
public class ImageLoaderRawCCITTFax extends AbstractImageLoader implements JPEGConstants {
53
53
54
    private static final int COMPRESSION_CCITT_1D = 2;
55
    private static final int COMPRESSION_FAX_GROUP3 = 3;
56
    private static final int COMPRESSION_FAX_GROUP4 = 4;
57
54
    /** logger */
58
    /** logger */
55
    protected static Log log = LogFactory.getLog(ImageLoaderRawCCITTFax.class);
59
    protected static Log log = LogFactory.getLog(ImageLoaderRawCCITTFax.class);
56
60
Lines 90-99 Link Here
90
            if (fld != null) {
94
            if (fld != null) {
91
                compression = fld.getAsInt(0);
95
                compression = fld.getAsInt(0);
92
                switch (compression) {
96
                switch (compression) {
93
                case TIFFImage.COMP_FAX_G3_1D:
97
                case COMPRESSION_CCITT_1D:
94
                case TIFFImage.COMP_FAX_G3_2D:
98
                case COMPRESSION_FAX_GROUP4:
95
                case TIFFImage.COMP_FAX_G4_2D:
96
                    break;
99
                    break;
100
                case COMPRESSION_FAX_GROUP3:
101
                    //Note: the TIFFImage compression constants seem to be a bit misleading!
102
                    compression = TIFFImage.COMP_FAX_G3_1D; //1D is the default for Group3
103
                    fld = dir.getField(TIFFImageDecoder.TIFF_T4_OPTIONS);
104
                    if (fld != null) {
105
                        long t4Options = fld.getAsLong(0);
106
                        if ((t4Options & 0x01) != 0) {
107
                            compression = TIFFImage.COMP_FAX_G3_2D; //"Abusing" for 2D signalling
108
                        }
109
                    }
110
                    break;
97
                default:
111
                default:
98
                    log.debug("Unsupported compression " + compression);
112
                    log.debug("Unsupported compression " + compression);
99
                    throw new ImageException(
113
                    throw new ImageException(
Lines 143-148 Link Here
143
        }
157
        }
144
158
145
        /** {@inheritDoc} */
159
        /** {@inheritDoc} */
160
        @Override
146
        public int read(byte[] b, int off, int len) throws IOException {
161
        public int read(byte[] b, int off, int len) throws IOException {
147
            int result = super.read(b, off, len);
162
            int result = super.read(b, off, len);
148
            if (result > 0) {
163
            if (result > 0) {
Lines 155-160 Link Here
155
        }
170
        }
156
171
157
        /** {@inheritDoc} */
172
        /** {@inheritDoc} */
173
        @Override
158
        public int read() throws IOException {
174
        public int read() throws IOException {
159
            int b = super.read();
175
            int b = super.read();
160
            if (b < 0) {
176
            if (b < 0) {

Return to bug 51911