1*c3bb05abSAndrew Rist /************************************************************** 2*c3bb05abSAndrew Rist * 3*c3bb05abSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c3bb05abSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c3bb05abSAndrew Rist * distributed with this work for additional information 6*c3bb05abSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c3bb05abSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c3bb05abSAndrew Rist * "License"); you may not use this file except in compliance 9*c3bb05abSAndrew Rist * with the License. You may obtain a copy of the License at 10*c3bb05abSAndrew Rist * 11*c3bb05abSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*c3bb05abSAndrew Rist * 13*c3bb05abSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c3bb05abSAndrew Rist * software distributed under the License is distributed on an 15*c3bb05abSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c3bb05abSAndrew Rist * KIND, either express or implied. See the License for the 17*c3bb05abSAndrew Rist * specific language governing permissions and limitations 18*c3bb05abSAndrew Rist * under the License. 19*c3bb05abSAndrew Rist * 20*c3bb05abSAndrew Rist *************************************************************/ 21cdf0e10cSrcweir #ifndef _IPDF_PNGHELPER_HXX 22cdf0e10cSrcweir #define _IPDF_PNGHELPER_HXX 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "sal/types.h" 25cdf0e10cSrcweir #include "pdfioutdev_gpl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir namespace pdfi 29cdf0e10cSrcweir { 30cdf0e10cSrcweir class PngHelper 31cdf0e10cSrcweir { 32cdf0e10cSrcweir static sal_uInt32 crc_table[ 256 ]; 33cdf0e10cSrcweir static bool bCRCTableInit; 34cdf0e10cSrcweir 35cdf0e10cSrcweir static void initCRCTable(); 36cdf0e10cSrcweir static void appendFileHeader( OutputBuffer& o_rOutputBuf ); 37cdf0e10cSrcweir static size_t startChunk( const char* pChunkName, OutputBuffer& o_rOut ); 38cdf0e10cSrcweir static void endChunk( size_t nStart, OutputBuffer& o_rOut ); 39cdf0e10cSrcweir 40cdf0e10cSrcweir static void set( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf, size_t i_nIndex ); append(sal_uInt32 i_nValue,OutputBuffer & o_rOutputBuf)41cdf0e10cSrcweir static void append( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf ) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir size_t nCur = o_rOutputBuf.size(); 44cdf0e10cSrcweir o_rOutputBuf.insert( o_rOutputBuf.end(), 4, (Output_t)0 ); 45cdf0e10cSrcweir set( i_nValue, o_rOutputBuf, nCur ); 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir static void appendIHDR( OutputBuffer& o_rOutputBuf, int width, int height, int depth, int colortype ); 49cdf0e10cSrcweir static void appendIEND( OutputBuffer& o_rOutputBuf ); 50cdf0e10cSrcweir 51cdf0e10cSrcweir public: 52cdf0e10cSrcweir static void updateCRC( sal_uInt32& io_rCRC, const sal_uInt8* i_pBuf, size_t i_nLen ); 53cdf0e10cSrcweir static sal_uInt32 getCRC( const sal_uInt8* i_pBuf, size_t i_nLen ); 54cdf0e10cSrcweir 55cdf0e10cSrcweir // deflates the passed buff i_pBuf and appends it to the output vector 56cdf0e10cSrcweir // returns the number of bytes added to the output 57cdf0e10cSrcweir static sal_uInt32 deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, OutputBuffer& o_rOut ); 58cdf0e10cSrcweir 59cdf0e10cSrcweir static void createPng( OutputBuffer& o_rOutputBuf, 60cdf0e10cSrcweir Stream* str, 61cdf0e10cSrcweir int width, 62cdf0e10cSrcweir int height, 63cdf0e10cSrcweir GfxRGB& zeroColor, 64cdf0e10cSrcweir GfxRGB& oneColor, 65cdf0e10cSrcweir bool bIsMask 66cdf0e10cSrcweir ); 67cdf0e10cSrcweir static void createPng( OutputBuffer& o_rOutputBuf, 68cdf0e10cSrcweir Stream* str, 69cdf0e10cSrcweir int width, int height, GfxImageColorMap* colorMap, 70cdf0e10cSrcweir Stream* maskStr, 71cdf0e10cSrcweir int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // for one bit masks 74cdf0e10cSrcweir static void createPng( OutputBuffer& o_rOutputBuf, 75cdf0e10cSrcweir Stream* str, 76cdf0e10cSrcweir int width, int height, GfxImageColorMap* colorMap, 77cdf0e10cSrcweir Stream* maskStr, 78cdf0e10cSrcweir int maskWidth, int maskHeight, bool maskInvert ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir }; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir #endif 84