Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginG3.cpp view on Meta::CPAN
rowbuf = (BYTE*) _TIFFmalloc(linesize);
refbuf = (BYTE*) _TIFFmalloc(linesize);
if (rowbuf == NULL || refbuf == NULL) {
throw FI_MSG_ERROR_MEMORY;
}
tifin->tif_rawdatasize = G3GetFileSize(io, handle);
tifin->tif_rawdata = (tidata_t) _TIFFmalloc(tifin->tif_rawdatasize);
if (tifin->tif_rawdata == NULL) {
throw FI_MSG_ERROR_MEMORY;
}
if(!G3ReadFile(io, handle, tifin->tif_rawdata, tifin->tif_rawdatasize)) {
throw "Read error at scanline 0";
}
tifin->tif_rawcp = tifin->tif_rawdata;
tifin->tif_rawcc = tifin->tif_rawdatasize;
(*tifin->tif_setupdecode)(tifin);
(*tifin->tif_predecode)(tifin, (uint16) 0);
tifin->tif_row = 0;
badfaxlines = 0;
badfaxrun = 0;
_TIFFmemset(refbuf, 0, linesize);
row = 0;
badrun = 0; // current run of bad lines
while (tifin->tif_rawcc > 0) {
ok = (*tifin->tif_decoderow)(tifin, rowbuf, linesize, 0);
if (!ok) {
badfaxlines++;
badrun++;
// regenerate line from previous good line
_TIFFmemcpy(rowbuf, refbuf, linesize);
} else {
if (badrun > badfaxrun)
badfaxrun = badrun;
badrun = 0;
_TIFFmemcpy(refbuf, rowbuf, linesize);
}
tifin->tif_row++;
FreeImage_WriteMemory(rowbuf, linesize, 1, memory);
row++;
if (stretch) {
FreeImage_WriteMemory(rowbuf, linesize, 1, memory);
row++;
}
}
if (badrun > badfaxrun)
badfaxrun = badrun;
_TIFFfree(tifin->tif_rawdata);
tifin->tif_rawdata = NULL;
_TIFFfree(rowbuf);
_TIFFfree(refbuf);
/*
if (verbose) {
fprintf(stderr, "%d rows in input\n", rows);
fprintf(stderr, "%ld total bad rows\n", (long) badfaxlines);
fprintf(stderr, "%d max consecutive bad rows\n", badfaxrun);
}
*/
} catch(const char *message) {
if(rowbuf) _TIFFfree(rowbuf);
if(refbuf) _TIFFfree(refbuf);
if(tifin->tif_rawdata) {
_TIFFfree(tifin->tif_rawdata);
tifin->tif_rawdata = NULL;
}
FreeImage_OutputMessageProc(s_format_id, message);
return -1;
}
return (row);
}
// ==========================================================
// Plugin Implementation
// ==========================================================
static const char * DLL_CALLCONV
Format() {
return "G3";
}
static const char * DLL_CALLCONV
Description() {
return "Raw fax format CCITT G.3";
}
static const char * DLL_CALLCONV
Extension() {
return "g3";
}
static const char * DLL_CALLCONV
RegExpr() {
return NULL; // there is now reasonable regexp for raw G3
}
static const char * DLL_CALLCONV
MimeType() {
return "image/fax-g3";
}
static BOOL DLL_CALLCONV
SupportsExportDepth(int depth) {
return FALSE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
TIFF *faxTIFF = NULL;
FIBITMAP *dib = NULL;
FIMEMORY *memory = NULL;
( run in 0.442 second using v1.01-cache-2.11-cpan-63c85eba8c4 )