diff -urNwb -x CVS -x WIN32_1.1.2s_i386_OBJ -x WIN32_1.1.2s_i386_DBG ./src/wp/ap/xp/ap_EditMethods.cpp ../abi-orig/src/wp/ap/xp/ap_EditMethods.cpp --- ./src/wp/ap/xp/ap_EditMethods.cpp Thu Jun 8 23:33:20 2000 +++ ../abi-orig/src/wp/ap/xp/ap_EditMethods.cpp Thu Jun 8 18:24:46 2000 @@ -1719,19 +1719,16 @@ // I dislike the fact that this function is here, but have yet to find a better location -UT_sint32 isValidImage(const char * szFileName) +UT_sint32 isPNG(const char * szFileName) { FILE * fp = fopen(szFileName, "r"); char str[10] = ""; char str2[10] = "\211PNG\r\n\032\n"; char str3[10] = "<89>PNG"; - char str4[10] = "BM"; /* Bitmap File */ fgets(str, 6, fp); fclose(fp); UT_DEBUGMSG(("header: %s\n", str)); - return ( !(strncmp(str, str2, 4)) || - !(strncmp(str, str3, 6)) || - !(strncmp(str, str4, 2)) ); + return (!(strncmp(str, str2, 4)) || !(strncmp(str, str3, 6))); } Defun1(fileInsertGraphic) @@ -1759,7 +1756,7 @@ // here we see that it is really a png file - this will have to be modified // as we add support for new graphics types - UT_Bool tmpVar = isValidImage(pNewFile); + UT_Bool tmpVar = isPNG(pNewFile); if(!tmpVar) { diff -urNwb -x CVS -x WIN32_1.1.2s_i386_OBJ -x WIN32_1.1.2s_i386_DBG ./src/wp/impexp/xp/Makefile ../abi-orig/src/wp/impexp/xp/Makefile --- ./src/wp/impexp/xp/Makefile Thu Jun 8 23:53:44 2000 +++ ../abi-orig/src/wp/impexp/xp/Makefile Thu Jun 8 19:04:38 2000 @@ -40,17 +40,16 @@ ie_imp_Text.cpp \ ie_imp_UTF8.cpp \ ie_impGraphic.cpp \ - ie_impGraphic_PNG.cpp \ - ie_impGraphic_BMP.cpp + ie_impGraphic_PNG.cpp LIBRARY_NAME= AbiImpExp LIBRARY_VERSION= $(ABI_VERSION) TARGETS= $(LIBRARY) ifeq ($(OS_NAME), WIN32) -INCLUDES= -I$(ABI_XX_ROOT)/../wv -I$(ABI_XX_ROOT)/../zlib -I$(ABI_XX_ROOT)/../wv/libole2 -I$(ABI_XX_ROOT)/../libpng +INCLUDES= -I$(ABI_XX_ROOT)/../wv -I$(ABI_XX_ROOT)/../zlib -I$(ABI_XX_ROOT)/../wv/libole2 else -INCLUDES= -I$(ABI_ROOT)/../wv -I$(ABI_ROOT)/../wv/libole2 -I$(ABI_ROOT)/../libpng +INCLUDES= -I$(ABI_ROOT)/../wv -I$(ABI_ROOT)/../wv/libole2 endif ifdef GLIB_CONFIG diff -urNwb -x CVS -x WIN32_1.1.2s_i386_OBJ -x WIN32_1.1.2s_i386_DBG ./src/wp/impexp/xp/ie_impGraphic.cpp ../abi-orig/src/wp/impexp/xp/ie_impGraphic.cpp --- ./src/wp/impexp/xp/ie_impGraphic.cpp Fri Jun 9 00:24:38 2000 +++ ../abi-orig/src/wp/impexp/xp/ie_impGraphic.cpp Wed Jan 26 15:22:46 2000 @@ -24,7 +24,6 @@ #include "ie_impGraphic.h" #include "ie_impGraphic_PNG.h" -#include "ie_impGraphic_BMP.h" // #include "ie_impGraphic_SVG.h" /*****************************************************************/ @@ -45,7 +44,6 @@ static struct _impGraphic s_impGraphicTable[] = { DeclareImporter(IE_ImpGraphic_PNG), - DeclareImporter(IE_ImpGraphic_BMP), // DeclareImporter(IE_ImpGraphic_SVG), }; diff -urNwb -x CVS -x WIN32_1.1.2s_i386_OBJ -x WIN32_1.1.2s_i386_DBG ./src/wp/impexp/xp/ie_impGraphic_BMP.cpp ../abi-orig/src/wp/impexp/xp/ie_impGraphic_BMP.cpp --- ./src/wp/impexp/xp/ie_impGraphic_BMP.cpp Fri Jun 9 00:06:38 2000 +++ ../abi-orig/src/wp/impexp/xp/ie_impGraphic_BMP.cpp Wed Dec 31 16:00:00 1969 @@ -1,379 +0,0 @@ -/* AbiWord - * Copyright (C) 1998 AbiSource, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ -#include -#include "ut_string.h" - -#include "ie_impGraphic_BMP.h" -#include "fg_GraphicRaster.h" - -static void _write_png( png_structp png_ptr, - png_bytep data, - unsigned int length ) -{ - UT_ByteBuf* bb = (UT_ByteBuf*) png_get_io_ptr(png_ptr); - bb->append(data, length); -} - -static void _write_flush(png_structp png_ptr) { } // Empty Fuction. - - -UT_Bool IE_ImpGraphic_BMP::RecognizeSuffix(const char * szSuffix) -{ - return (UT_stricmp(szSuffix,".bmp") == 0); -} - -UT_Bool IE_ImpGraphic_BMP::GetDlgLabels(const char ** pszDesc, - const char ** pszSuffixList, - IEGraphicFileType * ft) -{ - *pszDesc = "Window's Bitmap (.bmp)"; - *pszSuffixList = "*.bmp"; - *ft = IEGFT_BMP; - return UT_TRUE; -} - -UT_Bool IE_ImpGraphic_BMP::SupportsFileType(IEGraphicFileType ft) -{ - return (IEGFT_BMP == ft); -} - -UT_Error IE_ImpGraphic_BMP::StaticConstructor(IE_ImpGraphic **ppieg) -{ - *ppieg = new IE_ImpGraphic_BMP(); - if (*ppieg == NULL) - return UT_IE_NOMEMORY; - - return UT_OK; -} - - -// This actually creates our FG_Graphic object for a PNG -UT_Error IE_ImpGraphic_BMP::importGraphic(UT_ByteBuf* pBB, - FG_Graphic ** ppfg) -{ - UT_Error err; - InitializePrivateClassData(); - - /* Read Header Data */ - if(err = Read_BMP_Header(pBB)) return err; - if(err = Initialize_PNG()) return err; - - /* Read Palette, if no palette set Header accordingly */ - if(m_iBitsPerPlane < 24) - { - if (err = Convert_BMP_Pallet(pBB)) return err; - } - else - { - png_set_IHDR ( m_pPNG, - m_pPNGInfo, - m_iWidth, - m_iHeight, - m_iBitsPerPlane, - PNG_COLOR_TYPE_RGB, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT ); - - } - if (err = Convert_BMP(pBB)) return err; - - /* Clean Up Memory Used */ - - FREEP(m_pPNGInfo->palette); - DELETEP(pBB); - png_destroy_write_struct(&m_pPNG, &m_pPNGInfo); - - /* Send Data back to AbiWord as PNG */ - FG_GraphicRaster *pFGR; - pFGR = new FG_GraphicRaster(); - - if(pFGR == NULL) - return UT_IE_NOMEMORY; - - if(!pFGR->setRaster_PNG(m_pBB)) { - DELETEP(pFGR); - return UT_IE_BOGUSDOCUMENT; - } - - *ppfg = (FG_Graphic *) pFGR; - - return UT_OK; -} - -UT_Error IE_ImpGraphic_BMP::Read_BMP_Header(UT_ByteBuf* pBB) -{ - /* Stepping Through the Header Data first all the File Info - * Then the Image Info until reached the end of the image Header Size - * Note some simple checks for data out of bounds are included - */ - - /* File Info Starts Here */ - m_iBytesRead = 0; - m_iFileType = Read2Bytes(pBB,m_iBytesRead); - if (m_iFileType != 0x4D42) return UT_IE_BOGUSDOCUMENT; - m_iFileSize = Read4Bytes(pBB,m_iBytesRead); - m_iXHotspot = Read2Bytes(pBB,m_iBytesRead); - m_iYHotspot = Read2Bytes(pBB,m_iBytesRead); - m_iOffset = Read4Bytes(pBB,m_iBytesRead); - - /* Image Info Starts Here */ - m_iHeaderSize = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_IE_BOGUSDOCUMENT; /* More Header Info Needed */ - m_bOldBMPFormat = (m_iHeaderSize <=12) ? UT_TRUE : UT_FALSE; - m_iWidth = (m_bOldBMPFormat) ? - (UT_sint32) Read2Bytes(pBB,m_iBytesRead) : - (UT_sint32) Read4Bytes(pBB,m_iBytesRead) ; - m_iHeight = (m_bOldBMPFormat) ? - (UT_sint32) Read2Bytes(pBB,m_iBytesRead) : - (UT_sint32) Read4Bytes(pBB,m_iBytesRead) ; - if (m_bHeaderDone) return UT_IE_BOGUSDOCUMENT; /* More Header Info Needed */ - m_iPlanes = Read2Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_IE_BOGUSDOCUMENT; /* More Header Info Needed */ - if (m_iPlanes != 1) return UT_IE_BOGUSDOCUMENT; - m_iBitsPerPlane = Read2Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - - /* This rest of the header is read but not normally required */ - m_iCompression = Read4Bytes(pBB,m_iBytesRead); - if (m_iCompression != 0) return UT_IE_BOGUSDOCUMENT; - if (m_bHeaderDone) return UT_OK; - m_iImageSize = Read4Bytes(pBB,m_iBytesRead); - if(m_bHeaderDone) return UT_OK; - m_iXResolution = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iYResolution = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iClrUsed = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iClrImportant = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iResolutionUnits = Read2Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iPadding = Read2Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iOrigin = Read2Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iHalfToning = Read2Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iHalfToningParam1 = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iHalfToningParam2 = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iClrEncoding = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - m_iIdentifier = Read4Bytes(pBB,m_iBytesRead); - if (m_bHeaderDone) return UT_OK; - /* Document Using non-standard HeaderSize Assume OK */ - return UT_OK; -} - -UT_Error IE_ImpGraphic_BMP::Initialize_PNG() -{ - /* Set up png structures for writing */ - m_pPNG = png_create_write_struct( PNG_LIBPNG_VER_STRING, - (void*) NULL, - NULL, - NULL ); - if( m_pPNG == NULL ) - { - return UT_FALSE; - } - - m_pPNGInfo = png_create_info_struct(m_pPNG); - if ( m_pPNGInfo == NULL ) - { - png_destroy_write_struct(&m_pPNG, (png_infopp) NULL); - return UT_FALSE; - } - - /* Set error handling if you are using the setjmp/longjmp method (this is - * the normal method of doing things with libpng). REQUIRED unless you - * set up your own error handlers in the png_create_read_struct() earlier. - */ - if (setjmp(m_pPNG->jmpbuf)) - { - /* Free all of the memory associated with the png_ptr and info_ptr */ - png_destroy_write_struct(&m_pPNG, &m_pPNGInfo); - - /* If we get here, we had a problem reading the file */ - return UT_FALSE; - } - m_pBB = new UT_ByteBuf; /* Byte Buffer for Converted Data */ - - /* Setting up the Data Writing Function */ - png_set_write_fn(m_pPNG, (void *)m_pBB, _write_png, _write_flush); - - return UT_OK; -} - -UT_Error IE_ImpGraphic_BMP::Convert_BMP_Pallet(UT_ByteBuf* pBB) -{ - /* Reset error handling for libpng */ - if (setjmp(m_pPNG->jmpbuf)) - { - png_destroy_write_struct(&m_pPNG, &m_pPNGInfo); - return UT_FALSE; - } - - png_set_IHDR ( m_pPNG, - m_pPNGInfo, - m_iWidth, - m_iHeight, - m_iBitsPerPlane, - PNG_COLOR_TYPE_PALETTE, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT ); - - UT_uint32 iOffset = m_iHeaderSize + 14; - UT_uint32 numClrs = (m_iClrUsed > 0) ? - m_iClrUsed : - (m_iOffset - iOffset)/((m_bOldBMPFormat)?3:4); - - png_colorp palette = (png_colorp)png_malloc(m_pPNG, numClrs * sizeof(png_color)); - - for (UT_uint32 i=0; i < numClrs; i++) - { - palette[i].blue = ReadByte(pBB,iOffset++); - palette[i].green = ReadByte(pBB,iOffset++); - palette[i].red = ReadByte(pBB,iOffset++); - if(!m_bOldBMPFormat) iOffset++; - } - if (iOffset > m_iOffset) return UT_IE_BOGUSDOCUMENT; - - png_set_PLTE( m_pPNG, m_pPNGInfo, palette, numClrs ); - - return UT_OK; -} - -UT_Error IE_ImpGraphic_BMP::Convert_BMP(UT_ByteBuf* pBB) -{ - /* Reset error handling for libpng */ - if (setjmp(m_pPNG->jmpbuf)) - { - png_destroy_write_struct(&m_pPNG, &m_pPNGInfo); - return UT_FALSE; - } - png_write_info(m_pPNG,m_pPNGInfo); - - UT_Byte* row_data; - UT_sint32 row; - UT_uint32 position; - UT_uint32 row_width = m_iWidth; - while ((row_width & 3) != 0) row_width++; - - switch (m_iBitsPerPlane) - { - case 1: - case 4: - case 8: - case 16: - case 24: - for (row=m_iHeight-1; row >= 0; row--) - { - /* Calculatin the start of each row */ - position=m_iOffset + row*row_width*m_iBitsPerPlane/8; - row_data = (unsigned char *) pBB->getPointer(position); - png_write_rows(m_pPNG,&row_data,1); - } - break; - default: - return UT_IE_BOGUSDOCUMENT; - break; - } - - png_write_end(m_pPNG,m_pPNGInfo); - return UT_OK; -} - -UT_Byte IE_ImpGraphic_BMP::ReadByte (UT_ByteBuf* pBB, - UT_uint32 offset) -{ - return ( (UT_Byte) ReadBytes(pBB,offset,1) ); -} - -UT_uint16 IE_ImpGraphic_BMP::Read2Bytes(UT_ByteBuf* pBB, - UT_uint32 offset) -{ - return ( (UT_uint16) ReadBytes(pBB,offset,2) ); -} - - -UT_uint32 IE_ImpGraphic_BMP::Read4Bytes(UT_ByteBuf* pBB, - UT_uint32 offset) -{ - return ( ReadBytes(pBB,offset,4) ); -} - - -UT_uint32 IE_ImpGraphic_BMP::ReadBytes(UT_ByteBuf* pBB, - UT_uint32 offset, - UT_uint32 num_bytes) -{ - UT_ASSERT(num_bytes <= 4); - m_iBytesRead+=num_bytes; - - if (m_iHeaderSize) - { - m_bHeaderDone = (m_iBytesRead >= m_iHeaderSize + 14) ? - UT_TRUE : - UT_FALSE; - } - - UT_uint32 result = 0; - const UT_Byte* pByte; - for (UT_uint32 i=0; igetPointer(offset+i); - result |= *pByte << (i*8); - } - return (result); -} - -void IE_ImpGraphic_BMP::InitializePrivateClassData() -{ - m_iFileType=0; - m_iFileSize=0; - m_iXHotspot=0; - m_iYHotspot=0; - m_iOffset=0; - m_iHeaderSize=0; - m_iWidth=0; - m_iHeight=0; - m_iPlanes=0; - m_iBitsPerPlane=0; - m_iCompression=0; - m_iImageSize=0; - m_iXResolution=0; - m_iYResolution=0; - m_iClrUsed=0; - m_iClrImportant=0; - m_iResolutionUnits=0; - m_iPadding=0; - m_iOrigin=0; - m_iHalfToning=0; - m_iHalfToningParam1=0; - m_iHalfToningParam2=0; - m_iClrEncoding=0; - m_iIdentifier=0; - m_iBytesRead=0; - m_bOldBMPFormat=UT_FALSE; - m_bHeaderDone=UT_FALSE; -} diff -urNwb -x CVS -x WIN32_1.1.2s_i386_OBJ -x WIN32_1.1.2s_i386_DBG ./src/wp/impexp/xp/ie_impGraphic_BMP.h ../abi-orig/src/wp/impexp/xp/ie_impGraphic_BMP.h --- ./src/wp/impexp/xp/ie_impGraphic_BMP.h Thu Jun 8 17:09:22 2000 +++ ../abi-orig/src/wp/impexp/xp/ie_impGraphic_BMP.h Wed Dec 31 16:00:00 1969 @@ -1,99 +0,0 @@ -/* AbiWord - * Copyright (C) 1998 AbiSource, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - - -#ifndef IE_IMPGRAPHIC_BMP_H -#define IE_IMPGRAPHIC_BMP_H - -#include "ut_bytebuf.h" - -#include "png.h" - -#include "ie_impGraphic.h" - -class IE_ImpGraphic_BMP : public IE_ImpGraphic -{ -public: - static UT_Bool RecognizeSuffix(const char * szSuffix); - static UT_Bool GetDlgLabels(const char ** pszDesc, - const char ** pszSuffixList, - IEGraphicFileType * ft); - static UT_Bool SupportsFileType(IEGraphicFileType ft); - static UT_Error StaticConstructor(IE_ImpGraphic **ppieg); - - virtual UT_Error importGraphic(UT_ByteBuf* pBB, - FG_Graphic ** ppfg); - -private: - // PNG structures used - png_structp m_pPNG; // libpng structure for the PNG Object - png_infop m_pPNGInfo; // libpng structure for info on the PNG Object - - // BMP File Header Data - UT_uint16 m_iFileType; // type - 'BM' for Bitmaps - UT_uint32 m_iFileSize; // file size in bytes - UT_uint16 m_iXHotspot; // 0 or x hotspot - UT_uint16 m_iYHotspot; // 0 or y hotspot - UT_uint32 m_iOffset; // Offset to BMP image - - // BMP Header Data - UT_uint32 m_iHeaderSize; // Size of Header Data - UT_sint32 m_iWidth; // Image Width in pixels - UT_sint32 m_iHeight; // Image Height in pixels - UT_uint16 m_iPlanes; // Number of Planes == 1 - UT_uint16 m_iBitsPerPlane; // Bit per pixel - UT_uint32 m_iCompression; // compression flag - UT_uint32 m_iImageSize; // Image size in bytes - UT_uint32 m_iXResolution; // Horizontal Resolution (Pels/Meter) - UT_uint32 m_iYResolution; // Vertical Resolution (Pels/Meter) - UT_uint32 m_iClrUsed; // Color Table Size - UT_uint32 m_iClrImportant; // Important Color Count - UT_uint16 m_iResolutionUnits; // Units of Measure - UT_uint16 m_iPadding; // Reserved - UT_uint16 m_iOrigin; // Recording Algorithm - UT_uint16 m_iHalfToning; // Halftoning Algorithm - UT_uint32 m_iHalfToningParam1;// Size Value 1 - UT_uint32 m_iHalfToningParam2;// Size Value 2 - UT_uint32 m_iClrEncoding; // Color Encoding - UT_uint32 m_iIdentifier; // - - // BMP Utility Data - UT_uint32 m_iBytesRead; // Number of Bytes Read - UT_Bool m_bOldBMPFormat; // Older smaller file type - UT_Bool m_bHeaderDone; // Check to see if finshed Reading Header - - void InitializePrivateClassData(); - - // Functions for Reading Bitmaps - UT_Error Read_BMP_Header (UT_ByteBuf* pBB); - - UT_Error Initialize_PNG(); - UT_Error Convert_BMP_Pallet (UT_ByteBuf* pBB); - UT_Error Convert_BMP (UT_ByteBuf* pBB); - - // Function to Read ByteBuffer - UT_Byte ReadByte (UT_ByteBuf* pBB, UT_uint32 offset); - UT_uint16 Read2Bytes(UT_ByteBuf* pBB, UT_uint32 offset); - UT_uint32 Read4Bytes(UT_ByteBuf* pBB, UT_uint32 offset); - UT_uint32 ReadBytes (UT_ByteBuf* pBB, UT_uint32 offset, UT_uint32 num_bytes); - - UT_ByteBuf* m_pBB; // pBB Converted to PNG File -}; - -#endif /* IE_IMPGRAPHIC_BMP_H */