1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
#ifndef __OUTPUT_H__
#define __OUTPUT_H__
//
// Headerfile for output classes
//
// This file is part of sfftobmp, a program to convert
// structured fax files (sff) to windows bitmap files (bmp),
// portable bitmap graphics (pbm), tagged image file format (tiff)
// or JPEG (jpg).
//
// Copyright (C) 1998-2008 Peter Schaefer-Hutter and contributors ("THE AUTHORS")
//
// Permission to use, copy, modify, distribute, and sell this software and
// its documentation for any purpose is hereby granted without fee.
//
// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
// INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
// DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
// WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY
// THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE
// OR PERFORMANCE OF THIS SOFTWARE.
//
// Contributor(s):
// Gernot Hillier <ghillie@suse.de> (StdOut output support)
// Ulf Zibis <ulf.zibis@gmx.de> (Resolution preserving output, Cleanups,
// inheritance from CFile, destructor handling, preserving filetime)
//
// You can contact the original author by email at peter.schaefer@gmx.de.
//
// I'm always pleased to hear that somebody is actually using my software.
// If you can manage it, e-mail me a quick notice. Thanks!
//
/*-RCS-Info----------------------------------------------------
$Id: output.h,v 1.4 2009/08/23 12:58:37 pschaefer Exp $
---RCS-Info--------------------------------------------------*/
#include "decoder.h"
#pragma pack(1)
typedef struct {
sff_byte bBlue;
sff_byte bGreen;
sff_byte bRed;
sff_byte bNOP;
} TBmpRGB;
typedef struct {
sff_word wType;
sff_dword dwFileSize;
sff_word wNOP1;
sff_word wNOP2;
sff_dword dwOffset;
sff_dword dwBitmapSize;
sff_dword dwPixelWidth;
sff_dword dwPixelHeight;
sff_word wPlanes;
sff_word wCountBits;
sff_dword dwCompression;
sff_dword dwSizeImage;
sff_dword dwPixelWidthPerMeter;
sff_dword dwPixelHeightPerMeter;
sff_dword dwUsedColors;
sff_dword dwImportantColors;
TBmpRGB sCol1;
TBmpRGB sCol2;
} TBitMapFileHeader;
#pragma pack()
//-----------------------------------------------------------------
class COutputFilter
{
protected:
CBitSink m_sink;
sff_byte m_abBuffer[5120];
sff_word m_nPageCount;
std::string m_strExtension;
CFile *m_pFile;
public:
COutputFilter(const std::string& strExt, sff_word nPagecount) :
m_strExtension(strExt),
m_nPageCount(nPagecount),
m_sink(m_abBuffer, sizeof(m_abBuffer))
{ /* nth. else */ }
virtual void Init(CFile *pFile);
virtual void BeginPage(sff_dword aPage, sff_dword aWidth,
sff_dword aHeight, sff_word aDpi,
sff_word aLpi) = 0;
virtual void EndPage();
virtual void Finalize();
virtual CBitSink& GetBitSink();
virtual void BlankLine();
virtual void WriteLine() = 0;
const std::string& GetExtension() { return m_strExtension; };
};
//-----------------------------------------------------------------
class CBMPFilter : public COutputFilter
{
protected:
static TBitMapFileHeader m_bmpHeader;
int m_nLineToWrite;
public:
CBMPFilter(sff_word nPagecount) :
COutputFilter(".bmp", nPagecount)
{ /* nth. else */ };
void BeginPage(sff_dword aPage, sff_dword aWidth,
sff_dword aHeight, sff_word aDpi,
sff_word aLpi);
void WriteLine();
};
//-----------------------------------------------------------------
class CPBMFilter : public COutputFilter
{
protected:
sff_dword m_Width;
public:
CPBMFilter(sff_word nPagecount) :
COutputFilter(".pbm", nPagecount)
{ /* nth. else */ };
void BeginPage(sff_dword aPage, sff_dword aWidth,
sff_dword aHeight, sff_word aDpi,
sff_word aLpi);
void WriteLine();
};
//-----------------------------------------------------------------
class CJPEGFilter : public COutputFilter
{
protected:
CByteSink m_bytesink;
jpeg_compress_struct m_cinfo;
jpeg_error_mgr m_jerr;
JSAMPROW m_row_pointer[1];
int m_quality;
public:
CJPEGFilter(sff_word nPagecount, int nQuality = 40) :
COutputFilter(".jpg", nPagecount),
m_quality(nQuality),
m_bytesink(m_abBuffer, sizeof(m_abBuffer))
{ /* nth. else */ };
CBitSink& GetBitSink();
void BlankLine();
void BeginPage(sff_dword aPage, sff_dword aWidth,
sff_dword aHeight, sff_word aDpi,
sff_word aLpi);
void WriteLine();
void EndPage();
};
//-----------------------------------------------------------------
class CTIFFFilter : public COutputFilter
{
protected:
TIFF * m_tiffFile;
TIFFErrorHandler m_terr;
unsigned m_nRow;
sff_dword m_wCompression;
time_t m_nModTime;
public:
CTIFFFilter(sff_word nPagecount, sff_word nCompression, time_t nModTime) :
COutputFilter(".tif", nPagecount),
m_wCompression(nCompression),
m_tiffFile(NULL),
m_nModTime(nModTime)
{ /* nth. else */ };
void Init(CFile *pFile);
void BeginPage(sff_dword aPage, sff_dword aWidth,
sff_dword aHeight, sff_word aDpi,
sff_word aLpi);
void WriteLine();
void EndPage();
void Finalize();
};
#endif // __OUTPUT_H__
|