xref: /haiku/src/add-ons/translators/bmp/BMPTranslator.h (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*****************************************************************************/
2 // BMPTranslator
3 // BMPTranslator.h
4 //
5 // This BTranslator based object is for opening and writing BMP files.
6 //
7 //
8 // Copyright (c) 2002 Haiku Project
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 // DEALINGS IN THE SOFTWARE.
27 /*****************************************************************************/
28 
29 #ifndef BMP_TRANSLATOR_H
30 #define BMP_TRANSLATOR_H
31 
32 #include <ByteOrder.h>
33 #include <Catalog.h>
34 #include <DataIO.h>
35 #include <GraphicsDefs.h>
36 #include <InterfaceDefs.h>
37 #include <Locale.h>
38 #include <Translator.h>
39 #include <TranslatorFormats.h>
40 #include <TranslationDefs.h>
41 
42 #include "BaseTranslator.h"
43 
44 #define BMP_NO_COMPRESS 0
45 #define BMP_RLE8_COMPRESS 1
46 #define BMP_RLE4_COMPRESS 2
47 
48 #define BMP_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1,0,0)
49 #define BMP_IN_QUALITY 0.4
50 #define BMP_IN_CAPABILITY 0.8
51 #define BMP_OUT_QUALITY 0.4
52 #define BMP_OUT_CAPABILITY 0.8
53 
54 #define BBT_IN_QUALITY 0.4
55 #define BBT_IN_CAPABILITY 0.6
56 #define BBT_OUT_QUALITY 0.4
57 #define BBT_OUT_CAPABILITY 0.6
58 
59 
60 struct BMPFileHeader {
61 	// for both MS and OS/2 BMP formats
62 	uint16 magic;			// = 'BM'
63 	uint32 fileSize;		// file size in bytes
64 	uint32 reserved;		// equals 0
65 	uint32 dataOffset;		// file offset to actual image
66 };
67 
68 struct MSInfoHeader {
69 	uint32 size;			// size of this struct (40)
70 	int32 width;			// bitmap width
71 	int32 height;			// bitmap height
72 	uint16 planes;			// number of planes, always 1?
73 	uint16 bitsperpixel;	// bits per pixel, (1,4,8,16, 24 or 32)
74 	uint32 compression;		// type of compression
75 	uint32 imagesize;		// size of image data if compressed
76 	uint32 xpixperm;		// horizontal pixels per meter
77 	uint32 ypixperm;		// vertical pixels per meter
78 	uint32 colorsused;		// number of actually used colors
79 	uint32 colorsimportant;	// number of important colors, zero = all
80 };
81 
82 struct OS2InfoHeader {
83 	uint32 size;			// size of this struct (12)
84 	uint16 width;			// bitmap width
85 	uint16 height;			// bitmap height
86 	uint16 planes;			// number of planes, always 1?
87 	uint16 bitsperpixel;	// bits per pixel, (1,4,8,16, 24 or 32)
88 };
89 
90 class BMPTranslator : public BaseTranslator {
91 public:
92 	BMPTranslator();
93 
94 	virtual status_t DerivedIdentify(BPositionIO *inSource,
95 		const translation_format *inFormat, BMessage *ioExtension,
96 		translator_info *outInfo, uint32 outType);
97 
98 	virtual status_t DerivedTranslate(BPositionIO *inSource,
99 		const translator_info *inInfo, BMessage *ioExtension,
100 		uint32 outType, BPositionIO *outDestination, int32 baseType);
101 
102 	virtual BView *NewConfigView(TranslatorSettings *settings);
103 
104 protected:
105 	virtual ~BMPTranslator();
106 		// this is protected because the object is deleted by the
107 		// Release() function instead of being deleted directly by
108 		// the user
109 
110 private:
111 
112 	status_t translate_from_bits(BPositionIO *inSource, uint32 outType,
113 		BPositionIO *outDestination);
114 
115 	status_t translate_from_bmp(BPositionIO *inSource, uint32 outType,
116 		BPositionIO *outDestination);
117 };
118 
119 #endif // #ifndef BMP_TRANSLATOR_H
120