xref: /haiku/src/add-ons/translators/tiff/TIFFTranslator.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /*****************************************************************************/
2 // TIFFTranslator
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // TIFFTranslator.h
6 //
7 // This BTranslator based object is for opening and writing
8 // TIFF images.
9 //
10 //
11 // Copyright (c) 2003 OpenBeOS Project
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 /*****************************************************************************/
31 
32 #ifndef TIFF_TRANSLATOR_H
33 #define TIFF_TRANSLATOR_H
34 
35 #include <Translator.h>
36 #include <TranslatorFormats.h>
37 #include <TranslationDefs.h>
38 #include <GraphicsDefs.h>
39 #include <InterfaceDefs.h>
40 #include <DataIO.h>
41 #include <File.h>
42 #include <ByteOrder.h>
43 #include <fs_attr.h>
44 #include "DecodeTree.h"
45 
46 // IO Extension Names:
47 #define DOCUMENT_COUNT "/documentCount"
48 #define DOCUMENT_INDEX "/documentIndex"
49 
50 #define TIFF_TRANSLATOR_VERSION 100
51 
52 #define TIFF_IN_QUALITY 0.1
53 #define TIFF_IN_CAPABILITY 0.1
54 #define TIFF_OUT_QUALITY 0.6
55 #define TIFF_OUT_CAPABILITY 0.2
56 
57 #define BBT_IN_QUALITY 0.4
58 #define BBT_IN_CAPABILITY 0.6
59 #define BBT_OUT_QUALITY 0.4
60 #define BBT_OUT_CAPABILITY 0.6
61 
62 enum TIFF_IMAGE_TYPE {
63 	TIFF_BILEVEL = 1,
64 	TIFF_PALETTE,
65 	TIFF_RGB,
66 	TIFF_CMYK
67 };
68 
69 // class for storing only the TIFF fields
70 // that are of interest to the TIFFTranslator
71 //
72 // The class is very minimal so that it is
73 // convenient to use, but cleans up after itself
74 class TiffDetails {
75 public:
76 	TiffDetails();
77 	~TiffDetails();
78 
79 	uint32 width;
80 	uint32 height;
81 	uint32 compression;
82 	uint32 t4options;
83 	uint32 rowsPerStrip;
84 	uint32 stripsPerImage;
85 	uint32 *pstripOffsets;
86 	uint32 *pstripByteCounts;
87 	uint8 *pcolorMap;
88 	uint16 interpretation;
89 	uint16 bitsPerPixel;
90 	uint16 imageType;
91 	uint16 fillOrder;
92 };
93 
94 class TIFFTranslator : public BTranslator {
95 public:
96 	TIFFTranslator();
97 
98 	virtual const char *TranslatorName() const;
99 		// returns the short name of the translator
100 
101 	virtual const char *TranslatorInfo() const;
102 		// returns a verbose name/description for the translator
103 
104 	virtual int32 TranslatorVersion() const;
105 		// returns the version of the translator
106 
107 	virtual const translation_format *InputFormats(int32 *out_count)
108 		const;
109 		// returns the input formats and the count of input formats
110 		// that this translator supports
111 
112 	virtual const translation_format *OutputFormats(int32 *out_count)
113 		const;
114 		// returns the output formats and the count of output formats
115 		// that this translator supports
116 
117 	virtual status_t Identify(BPositionIO *inSource,
118 		const translation_format *inFormat, BMessage *ioExtension,
119 		translator_info *outInfo, uint32 outType);
120 		// determines whether or not this translator can convert the
121 		// data in inSource to the type outType
122 
123 	virtual status_t Translate(BPositionIO *inSource,
124 		const translator_info *inInfo, BMessage *ioExtension,
125 		uint32 outType, BPositionIO *outDestination);
126 		// this function is the whole point of the Translation Kit,
127 		// it translates the data in inSource to outDestination
128 		// using the format outType
129 
130 	virtual status_t MakeConfigurationView(BMessage *ioExtension,
131 		BView **outView, BRect *outExtent);
132 		// creates and returns the view for displaying information
133 		// about this translator
134 
135 protected:
136 	virtual ~TIFFTranslator();
137 		// this is protected because the object is deleted by the
138 		// Release() function instead of being deleted directly by
139 		// the user
140 
141 private:
142 	status_t LoadHuffmanTrees();
143 
144 	ssize_t decode_huffman(StreamBuffer *pstreambuf, TiffDetails &details,
145 		uint8 *pbits);
146 	ssize_t decode_t4(BitReader &stream, TiffDetails &details,
147 		uint8 *pbits, bool bfirstLine);
148 
149 	status_t translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
150 		ssize_t amtread, uint8 *read, swap_action swp, uint32 outType,
151 		BPositionIO *outDestination);
152 
153 	DecodeTree *fpblackTree;
154 	DecodeTree *fpwhiteTree;
155 
156 	char fName[30];
157 	char fInfo[100];
158 };
159 
160 #endif // #ifndef TIFF_TRANSLATOR_H
161