/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include"pnghelper.hxx" #include <sal/macros.h>
#include <zlib.h>
usingnamespace pdfi;
// checksum helpers, courtesy of libpng.org
/* Table of CRCs of all 8-bit messages. */
sal_uInt32 PngHelper::crc_table[256];
/* Flag: has the table been computed? Initially false. */ bool PngHelper::bCRCTableInit = true;
/* Make the table for a fast CRC. */ void PngHelper::initCRCTable()
{ for (sal_uInt32 n = 0; n < 256; n++)
{
sal_uInt32 c = n; for (int k = 0; k < 8; k++)
{ if (c & 1)
c = 0xedb88320L ^ (c >> 1); else
c = c >> 1;
}
crc_table[n] = c;
}
bCRCTableInit = false;
}
/* Update a running CRC with the bytes buf[0..len-1]--the CRC should be initialized to all 1's, and the transmitted value is the 1's complement of the final running CRC (see the
crc() routine below)). */
// create scan line data buffer
OutputBuffer aScanlines; int nLineSize = (width + 7)/8;
aScanlines.reserve( nLineSize * height + height );
#if POPPLER_CHECK_VERSION(25, 2, 0) if (!str->reset()) return; #else
str->reset(); #endif for( int y = 0; y < height; y++ )
{ // determine filter type (none) for this scanline
aScanlines.push_back( 0 ); for( int x = 0; x < nLineSize; x++ )
aScanlines.push_back( str->getChar() );
}
// begin IDAT chunk for scanline data
nIdx = startChunk( "IDAT", o_rOutputBuf ); // compress scanlines
deflateBuffer( aScanlines.data(), aScanlines.size(), o_rOutputBuf ); // end IDAT chunk
endChunk( nIdx, o_rOutputBuf );
// output IEND
appendIEND( o_rOutputBuf );
}
void PngHelper::createPng( OutputBuffer& o_rOutputBuf,
Stream* str, int width, int height, GfxImageColorMap* colorMap,
Stream* maskStr, int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap )
{
appendFileHeader( o_rOutputBuf );
appendIHDR( o_rOutputBuf, width, height, 8, 6 ); // RGBA image
// create scan line data buffer
OutputBuffer aScanlines;
aScanlines.reserve( width*height*4 + height );
for( int y=0; y<height; ++y)
{
aScanlines.push_back( 0 );
p = imgStr->getLine(); for( int x=0; x<width; ++x)
{
colorMap->getRGB(p, &rgb);
aScanlines.push_back(colToByte(rgb.r));
aScanlines.push_back(colToByte(rgb.g));
aScanlines.push_back(colToByte(rgb.b));
aScanlines.push_back( 0xff );
p +=colorMap->getNumPixelComps();
}
}
// now fill in the mask data
// CAUTION: originally this was done in one single loop // it caused merry chaos; the reason is that maskStr and str are // not independent streams, it happens that reading one advances // the other, too. Hence the two passes are imperative !
// create scan line data buffer
OutputBuffer aScanlines;
aScanlines.reserve( width*height*4 + height );
for( int y=0; y<height; ++y)
{
aScanlines.push_back( 0 );
p = imgStr->getLine(); for( int x=0; x<width; ++x)
{
colorMap->getRGB(p, &rgb);
aScanlines.push_back(colToByte(rgb.r));
aScanlines.push_back(colToByte(rgb.g));
aScanlines.push_back(colToByte(rgb.b));
aScanlines.push_back( 0xff );
p +=colorMap->getNumPixelComps();
}
}
// now fill in the mask data
// CAUTION: originally this was done in one single loop // it caused merry chaos; the reason is that maskStr and str are // not independent streams, it happens that reading one advances // the other, too. Hence the two passes are imperative !
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.