View Javadoc
1   package org.apache.commons.imaging.formats.tga;
2   
3   ///*
4   // * Licensed to the Apache Software Foundation (ASF) under one or more
5   // * contributor license agreements.  See the NOTICE file distributed with
6   // * this work for additional information regarding copyright ownership.
7   // * The ASF licenses this file to You under the Apache License, Version 2.0
8   // * (the "License"); you may not use this file except in compliance with
9   // * the License.  You may obtain a copy of the License at
10  // *
11  // *      http://www.apache.org/licenses/LICENSE-2.0
12  // *
13  // * Unless required by applicable law or agreed to in writing, software
14  // * distributed under the License is distributed on an "AS IS" BASIS,
15  // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  // * See the License for the specific language governing permissions and
17  // * limitations under the License.
18  // */
19  //package org.apache.commons.imaging.formats.tga;
20  //
21  //import java.awt.Dimension;
22  //import java.awt.image.BufferedImage;
23  //import java.io.File;
24  //import java.io.IOException;
25  //import java.io.InputStream;
26  //import java.io.PrintWriter;
27  //import java.util.Map;
28  //import java.util.ArrayList;
29  //
30  //import org.apache.commons.imaging.ImageFormat;
31  //import org.apache.commons.imaging.ImageInfo;
32  //import org.apache.commons.imaging.ImageParser;
33  //import org.apache.commons.imaging.ImageReadException;
34  //import org.apache.commons.imaging.common.IImageMetadata;
35  //import org.apache.commons.imaging.common.bytesource.ByteSource;
36  //import org.apache.commons.imaging.util.Debug;
37  //
38  ///*
39  // * This class is just a placeholder.  TGA format is not yet supported.
40  // */
41  //public class TgaImageParser extends ImageParser implements TgaConstants
42  //{
43  //    public TgaImageParser()
44  //    {
45  //        this.setByteOrder(BYTE_ORDER_INTEL);
46  //        setDebug(true);
47  //    }
48  //
49  //    public String getName()
50  //    {
51  //        return "Tga";
52  //    }
53  //
54  //    public String getDefaultExtension()
55  //    {
56  //        return DEFAULT_EXTENSION;
57  //    }
58  //
59  //    private static final String DEFAULT_EXTENSION = ".tga";
60  //
61  //    private static final String[] ACCEPTED_EXTENSIONS = {
62  //            ".tga", ".tpic",
63  //    };
64  //
65  //    protected String[] getAcceptedExtensions()
66  //    {
67  //        return ACCEPTED_EXTENSIONS;
68  //    }
69  //
70  //    protected ImageFormat[] getAcceptedTypes()
71  //    {
72  //        return new ImageFormat[]{
73  //            ImageFormat.IMAGE_FORMAT_TGA, //
74  //        };
75  //    }
76  //
77  //    public IImageMetadata getMetadata(ByteSource byteSource, Map params)
78  //            throws ImageReadException, IOException
79  //    {
80  //        return null;
81  //    }
82  //
83  //    public byte[] getICCProfileBytes(ByteSource byteSource)
84  //            throws ImageReadException, IOException
85  //    {
86  //        return null;
87  //    }
88  //
89  //    private static final int TGA_FILE_HEADER_LENGTH = 18;
90  //
91  //    public Dimension getImageSize(ByteSource byteSource)
92  //            throws ImageReadException, IOException
93  //    {
94  ////        int length = (int) byteSource.getLength();
95  ////        if (length < TGA_FILE_HEADER_LENGTH)
96  ////            return null;
97  //
98  //        InputStream is = byteSource.getInputStream();
99  //
100 //        is.skip(12);
101 //
102 //        int width = this.read2Bytes("image width", is, "image width");
103 //        int height = this.read2Bytes("image height", is, "image height");
104 //
105 //        return new Dimension(width, height);
106 //    }
107 //
108 //    private static final int TGA_FILE_FOOTER_LENGTH = 26;
109 //    private static final String TGA_FILE_FOOTER_SIGNATURE = "TRUEVISION-XFILE";
110 //
111 //    private final boolean isNewTGAFormat(ByteSource byteSource)
112 //            throws ImageReadException, IOException
113 //    {
114 //        int length = (int) byteSource.getLength();
115 //        if (length < TGA_FILE_FOOTER_LENGTH)
116 //            return true;
117 //
118 //        InputStream is = byteSource.getInputStream(length
119 //                - TGA_FILE_FOOTER_LENGTH);
120 //
121 //        byte bytes[] = this.readByteArray("tga_file_footer",
122 //                TGA_FILE_FOOTER_LENGTH, is, "tga_file_footer");
123 //
124 //        Debug.debug("bytes", bytes);
125 //
126 //        Debug.debug("kTGA_FILE_FOOTER_SIGNATURE", TGA_FILE_FOOTER_SIGNATURE);
127 //        Debug.debug("kTGA_FILE_FOOTER_SIGNATURE", TGA_FILE_FOOTER_SIGNATURE
128 //                .length());
129 //
130 //        return this.compareByteArrays(bytes, 8, TGA_FILE_FOOTER_SIGNATURE
131 //                .getBytes(), 0, TGA_FILE_FOOTER_SIGNATURE.length());
132 //    }
133 //
134 //    private static final int TGA_IMAGE_TYPE_NO_IMAGE = 0;
135 //    private static final int UNCOMPRESSED_COLOR_MAPPED = 1;
136 //    private static final int UNCOMPRESSED_RGB = 2;
137 //    private static final int UNCOMPRESSED_BLACK_AND_WHITE = 3;
138 //    private static final int COMPRESSED_COLOR_MAPPED_RLE = 9;
139 //    private static final int COMPRESSED_RGB_RLE = 10;
140 //    private static final int COMPRESSED_BLACK_AND_WHITE = 11;
141 //    private static final int COMPRESSED_COLOR_MAPPED_DATA_HUFFMAN_DELTA_RLE = 32;
142 //    private static final int COMPRESSED_COLOR_MAPPED_DATA_RLE = 33;
143 //
144 //    public ImageInfo getImageInfo(ByteSource byteSource)
145 //            throws ImageReadException, IOException
146 //    {
147 ////        int length = (int) byteSource.getLength();
148 ////        if (length < TGA_FILE_HEADER_LENGTH)
149 ////            return null;
150 //
151 //        InputStream is = byteSource.getInputStream();
152 //
153 //        int id_string_length = this.readByte("id_string_length", is,
154 //                "id_string_length");
155 //        int color_map_type = this.readByte("color_map_type", is,
156 //                "color_map_type");
157 //        int image_type = this.readByte("image_type", is, "image_type");
158 //
159 //        int color_map_first_entry_index = this.read2Bytes(
160 //                "color_map_first_entry_index", is,
161 //                "color_map_first_entry_index");
162 //        int color_map_length = this.read2Bytes("color_map_length", is,
163 //                "color_map_length");
164 //        int color_map_entry_size = this.readByte("color_map_entry_size", is,
165 //                "color_map_entry_size");
166 //
167 //        int origin_x = this.read2Bytes("origin_x", is, "origin_x");
168 //        int origin_y = this.read2Bytes("origin_y", is, "origin_y");
169 //
170 //        int width = this.read2Bytes("image width", is, "image width");
171 //        int height = this.read2Bytes("image height", is, "image height");
172 //
173 //        int pixel_depth = this.readByte("pixel_depth", is, "pixel_depth");
174 //        int image_descriptor = this.readByte("image_descriptor", is,
175 //                "image_descriptor");
176 //        // charles
177 //
178 //        switch (image_type)
179 //        {
180 //            case UNCOMPRESSED_COLOR_MAPPED :
181 //                break;
182 //            case UNCOMPRESSED_RGB :
183 //                break;
184 //            case UNCOMPRESSED_BLACK_AND_WHITE :
185 //                break;
186 //            case COMPRESSED_COLOR_MAPPED_RLE :
187 //                break;
188 //            case COMPRESSED_RGB_RLE :
189 //                break;
190 //            case COMPRESSED_BLACK_AND_WHITE :
191 //                break;
192 //            case COMPRESSED_COLOR_MAPPED_DATA_HUFFMAN_DELTA_RLE :
193 //                break;
194 //            case COMPRESSED_COLOR_MAPPED_DATA_RLE :
195 //                break;
196 //
197 //            default :
198 //
199 //        }
200 //        String FormatDetails;
201 //        int BitsPerPixel;
202 //        List Comments;
203 //        ImageFormat Format = ImageFormat.IMAGE_FORMAT_TGA;
204 //        String FormatName = Format.name;
205 //        String MimeType = "image/tga";
206 //        int NumberOfImages = 1; // charles could have thumbnail(s).
207 //        int PhysicalHeightDpi;
208 //        float PhysicalHeightInch;
209 //        int PhysicalWidthDpi;
210 //        float PhysicalWidthInch;
211 //        boolean progressive = false;
212 //        boolean transparent = pixel_depth > 24;
213 //        boolean usesPalette;
214 //        int ColorType;
215 //
216 //        return null;
217 //        //        return new ImageInfo(FormatDetails, BitsPerPixel, Comments, Format,
218 //        //                FormatName, height, MimeType, NumberOfImages,
219 //        //                PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
220 //        //                PhysicalWidthInch, width, progressive, transparent,
221 //        //                usesPalette, ColorType);
222 //
223 //        //        boolean is_new_tga_format = isNewTGAFormat(byteSource);
224 //        //
225 //        //        Debug.debug("is_new_tga_format", is_new_tga_format);
226 //    }
227 //
228 //    public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
229 //            throws ImageReadException, IOException
230 //    {
231 //        return false;
232 //    }
233 //
234 //    public BufferedImage getBufferedImage(ByteSource byteSource, Map params)
235 //            throws ImageReadException, IOException
236 //    {
237 //        return null;
238 //    }
239 //
240 //    //    public void writeImage(BufferedImage src, OutputStream os, Map params)
241 //    //            throws ImageWriteException, IOException
242 //    //    {
243 //    //        return false;
244 //    //    }
245 //
246 // }