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 OpenBeOS 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 <Translator.h> 33 #include <TranslatorFormats.h> 34 #include <TranslationDefs.h> 35 #include <GraphicsDefs.h> 36 #include <InterfaceDefs.h> 37 #include <DataIO.h> 38 #include <ByteOrder.h> 39 #include "BaseTranslator.h" 40 41 #define BMP_NO_COMPRESS 0 42 #define BMP_RLE8_COMPRESS 1 43 #define BMP_RLE4_COMPRESS 2 44 45 #define BMP_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1,0,0) 46 #define BMP_IN_QUALITY 0.4 47 #define BMP_IN_CAPABILITY 0.8 48 #define BMP_OUT_QUALITY 0.4 49 #define BMP_OUT_CAPABILITY 0.8 50 51 #define BBT_IN_QUALITY 0.4 52 #define BBT_IN_CAPABILITY 0.6 53 #define BBT_OUT_QUALITY 0.4 54 #define BBT_OUT_CAPABILITY 0.6 55 56 57 struct BMPFileHeader { 58 // for both MS and OS/2 BMP formats 59 uint16 magic; // = 'BM' 60 uint32 fileSize; // file size in bytes 61 uint32 reserved; // equals 0 62 uint32 dataOffset; // file offset to actual image 63 }; 64 65 struct MSInfoHeader { 66 uint32 size; // size of this struct (40) 67 uint32 width; // bitmap width 68 uint32 height; // bitmap height 69 uint16 planes; // number of planes, always 1? 70 uint16 bitsperpixel; // bits per pixel, (1,4,8,16, 24 or 32) 71 uint32 compression; // type of compression 72 uint32 imagesize; // size of image data if compressed 73 uint32 xpixperm; // horizontal pixels per meter 74 uint32 ypixperm; // vertical pixels per meter 75 uint32 colorsused; // number of actually used colors 76 uint32 colorsimportant; // number of important colors, zero = all 77 }; 78 79 struct OS2InfoHeader { 80 uint32 size; // size of this struct (12) 81 uint16 width; // bitmap width 82 uint16 height; // bitmap height 83 uint16 planes; // number of planes, always 1? 84 uint16 bitsperpixel; // bits per pixel, (1,4,8,16, 24 or 32) 85 }; 86 87 class BMPTranslator : public BaseTranslator { 88 public: 89 BMPTranslator(); 90 91 virtual status_t DerivedIdentify(BPositionIO *inSource, 92 const translation_format *inFormat, BMessage *ioExtension, 93 translator_info *outInfo, uint32 outType); 94 95 virtual status_t DerivedTranslate(BPositionIO *inSource, 96 const translator_info *inInfo, BMessage *ioExtension, 97 uint32 outType, BPositionIO *outDestination, int32 baseType); 98 99 virtual BView *NewConfigView(TranslatorSettings *settings); 100 101 protected: 102 virtual ~BMPTranslator(); 103 // this is protected because the object is deleted by the 104 // Release() function instead of being deleted directly by 105 // the user 106 107 private: 108 109 status_t translate_from_bits(BPositionIO *inSource, uint32 outType, 110 BPositionIO *outDestination); 111 112 status_t translate_from_bmp(BPositionIO *inSource, uint32 outType, 113 BPositionIO *outDestination); 114 }; 115 116 #endif // #ifndef BMP_TRANSLATOR_H 117