00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 00002 00003 /* AbiWord 00004 * Copyright (C) 1998 AbiSource, Inc. 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 * 02110-1301 USA. 00020 */ 00021 00022 00023 #ifndef IE_IMPGRAPHIC_BMP_H 00024 #define IE_IMPGRAPHIC_BMP_H 00025 00026 #include "ut_bytebuf.h" 00027 00028 #include "png.h" 00029 00030 #include "ie_impGraphic.h" 00031 00032 class IE_ImpGraphicBMP_Sniffer : public IE_ImpGraphicSniffer 00033 { 00034 public: 00035 virtual const IE_SuffixConfidence * getSuffixConfidence (); 00036 virtual const IE_MimeConfidence * getMimeConfidence () { return NULL; } 00037 virtual UT_Confidence_t recognizeContents (const char * szBuf, 00038 UT_uint32 iNumbytes); 00039 virtual bool getDlgLabels (const char ** szDesc, 00040 const char ** szSuffixList, 00041 IEGraphicFileType * ft); 00042 virtual UT_Error constructImporter (IE_ImpGraphic ** ppieg); 00043 }; 00044 00045 class IE_ImpGraphic_BMP : public IE_ImpGraphic 00046 { 00047 public: 00048 virtual UT_Error importGraphic(const UT_ConstByteBufPtr &pBB, 00049 FG_ConstGraphicPtr & pfg); 00050 00051 private: 00052 // PNG structures used 00053 png_structp m_pPNG; // libpng structure for the PNG Object 00054 png_infop m_pPNGInfo; // libpng structure for info on the PNG Object 00055 00056 // BMP File Header Data 00057 UT_uint16 m_iFileType; // type - 'BM' for Bitmaps 00058 UT_uint32 m_iFileSize; // file size in bytes 00059 UT_uint16 m_iXHotspot; // 0 or x hotspot 00060 UT_uint16 m_iYHotspot; // 0 or y hotspot 00061 UT_uint32 m_iOffset; // Offset to BMP image 00062 00063 // BMP Header Data 00064 UT_uint32 m_iHeaderSize; // Size of Header Data 00065 UT_sint32 m_iWidth; // Image Width in pixels 00066 UT_sint32 m_iHeight; // Image Height in pixels 00067 UT_uint16 m_iPlanes; // Number of Planes == 1 00068 UT_uint16 m_iBitsPerPlane; // Bit per pixel 00069 UT_uint32 m_iCompression; // compression flag 00070 UT_uint32 m_iImageSize; // Image size in bytes 00071 UT_uint32 m_iXResolution; // Horizontal Resolution (Pels/Meter) 00072 UT_uint32 m_iYResolution; // Vertical Resolution (Pels/Meter) 00073 UT_uint32 m_iClrUsed; // Color Table Size 00074 UT_uint32 m_iClrImportant; // Important Color Count 00075 UT_uint16 m_iResolutionUnits; // Units of Measure 00076 UT_uint16 m_iPadding; // Reserved 00077 UT_uint16 m_iOrigin; // Recording Algorithm 00078 UT_uint16 m_iHalfToning; // Halftoning Algorithm 00079 UT_uint32 m_iHalfToningParam1;// Size Value 1 00080 UT_uint32 m_iHalfToningParam2;// Size Value 2 00081 UT_uint32 m_iClrEncoding; // Color Encoding 00082 UT_uint32 m_iIdentifier; // 00083 00084 // BMP Utility Data 00085 UT_uint32 m_iBytesRead; // Number of Bytes Read 00086 bool m_bOldBMPFormat; // Older smaller file type 00087 bool m_bHeaderDone; // Check to see if finshed Reading Header 00088 00089 void InitializePrivateClassData(); 00090 UT_Error _convertGraphic(const UT_ConstByteBufPtr & pBB); 00091 00092 // Functions for Reading Bitmaps 00093 UT_Error Read_BMP_Header (const UT_ConstByteBufPtr & pBB); 00094 00095 UT_Error Initialize_PNG(); 00096 UT_Error Convert_BMP_Pallet (const UT_ConstByteBufPtr & pBB); 00097 UT_Error Convert_BMP (const UT_ConstByteBufPtr & pBB); 00098 00099 // Function to Read ByteBuffer 00100 UT_Byte ReadByte (const UT_ConstByteBufPtr & pBB, UT_uint32 offset); 00101 UT_uint16 Read2Bytes(const UT_ConstByteBufPtr & pBB, UT_uint32 offset); 00102 UT_uint32 Read4Bytes(const UT_ConstByteBufPtr & pBB, UT_uint32 offset); 00103 UT_uint32 ReadBytes (const UT_ConstByteBufPtr & pBB, UT_uint32 offset, UT_uint32 num_bytes); 00104 00105 UT_ConstByteBufPtr m_pBB; // pBB Converted to PNG File 00106 }; 00107 00108 #endif /* IE_IMPGRAPHIC_BMP_H */