Commit 18adb421 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

PdfWriter with JBig2 linux build

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62538 954022d7-b5bf-4e40-9824-e11837661b57
parent c790d7af
...@@ -808,7 +808,7 @@ CString RtfCharProperty::RenderToOOX(RenderParameter oRenderParameter) ...@@ -808,7 +808,7 @@ CString RtfCharProperty::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( m_poShading.RenderToOOX( oRenderParameter )); sResult.Append( m_poShading.RenderToOOX( oRenderParameter ));
return sResult; return sResult;
} }
#include <langinfo.h>
CString RtfListLevelProperty::RenderToRtf(RenderParameter oRenderParameter) CString RtfListLevelProperty::RenderToRtf(RenderParameter oRenderParameter)
{ {
RtfDocument* poRtfDocument = static_cast<RtfDocument*>( oRenderParameter.poDocument); RtfDocument* poRtfDocument = static_cast<RtfDocument*>( oRenderParameter.poDocument);
......
...@@ -432,8 +432,7 @@ SOURCES += \ ...@@ -432,8 +432,7 @@ SOURCES += \
../../../cximage/CxImage/ximawmf.cpp \ ../../../cximage/CxImage/ximawmf.cpp \
../../../cximage/CxImage/ximawnd.cpp \ ../../../cximage/CxImage/ximawnd.cpp \
../../../cximage/CxImage/xmemfile.cpp \ ../../../cximage/CxImage/xmemfile.cpp \
../../../raster/BgraFrame.cpp \ ../../../raster/BgraFrame.cpp
../../../raster/ImageFileFormatChecker.cpp
HEADERS += \ HEADERS += \
../../../graphics/AggPlusEnums.h \ ../../../graphics/AggPlusEnums.h \
......
...@@ -114,7 +114,7 @@ jbig2enc_init(struct jbig2enc_ctx *ctx) { ...@@ -114,7 +114,7 @@ jbig2enc_init(struct jbig2enc_ctx *ctx) {
ctx->bp = -1; ctx->bp = -1;
ctx->b = 0; ctx->b = 0;
ctx->outbuf_used = 0; ctx->outbuf_used = 0;
ctx->outbuf = (u8 *) malloc(JBIG2_OUTPUTBUFFER_SIZE); ctx->outbuf = (u8 *) new u8 [JBIG2_OUTPUTBUFFER_SIZE];
ctx->output_chunks = new std::vector<uint8_t *>; ctx->output_chunks = new std::vector<uint8_t *>;
ctx->iaidctx = NULL; ctx->iaidctx = NULL;
} }
...@@ -127,7 +127,7 @@ jbig2enc_reset(struct jbig2enc_ctx *ctx) { ...@@ -127,7 +127,7 @@ jbig2enc_reset(struct jbig2enc_ctx *ctx) {
ctx->ct = 12; ctx->ct = 12;
ctx->bp = -1; ctx->bp = -1;
ctx->b = 0; ctx->b = 0;
free(ctx->iaidctx); delete []ctx->iaidctx;
ctx->iaidctx = NULL; ctx->iaidctx = NULL;
memset(ctx->context, 0, JBIG2_MAX_CTX); memset(ctx->context, 0, JBIG2_MAX_CTX);
memset(ctx->intctx, 0, 13 * 512); memset(ctx->intctx, 0, 13 * 512);
...@@ -139,8 +139,9 @@ jbig2enc_flush(struct jbig2enc_ctx *ctx) { ...@@ -139,8 +139,9 @@ jbig2enc_flush(struct jbig2enc_ctx *ctx) {
ctx->outbuf_used = 0; ctx->outbuf_used = 0;
for (std::vector<uint8_t *>::iterator i = ctx->output_chunks->begin(); for (std::vector<uint8_t *>::iterator i = ctx->output_chunks->begin();
i != ctx->output_chunks->end(); ++i) { i != ctx->output_chunks->end(); ++i)
free(*i); {
delete [](*i);
} }
ctx->output_chunks->clear(); ctx->output_chunks->clear();
ctx->bp = -1; ctx->bp = -1;
...@@ -150,12 +151,14 @@ jbig2enc_flush(struct jbig2enc_ctx *ctx) { ...@@ -150,12 +151,14 @@ jbig2enc_flush(struct jbig2enc_ctx *ctx) {
void void
jbig2enc_dealloc(struct jbig2enc_ctx *ctx) { jbig2enc_dealloc(struct jbig2enc_ctx *ctx) {
for (std::vector<uint8_t *>::iterator i = ctx->output_chunks->begin(); for (std::vector<uint8_t *>::iterator i = ctx->output_chunks->begin();
i != ctx->output_chunks->end(); ++i) { i != ctx->output_chunks->end(); ++i)
free(*i); {
delete [](*i);
} }
delete ctx->output_chunks; delete ctx->output_chunks;
free(ctx->outbuf);
free(ctx->iaidctx); delete []ctx->outbuf;
delete []ctx->iaidctx;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -166,7 +169,7 @@ static void inline ...@@ -166,7 +169,7 @@ static void inline
emit(struct jbig2enc_ctx *restrict ctx) { emit(struct jbig2enc_ctx *restrict ctx) {
if (unlikely(ctx->outbuf_used == JBIG2_OUTPUTBUFFER_SIZE)) { if (unlikely(ctx->outbuf_used == JBIG2_OUTPUTBUFFER_SIZE)) {
ctx->output_chunks->push_back(ctx->outbuf); ctx->output_chunks->push_back(ctx->outbuf);
ctx->outbuf = (u8 *) malloc(JBIG2_OUTPUTBUFFER_SIZE); ctx->outbuf = new u8[JBIG2_OUTPUTBUFFER_SIZE];
ctx->outbuf_used = 0; ctx->outbuf_used = 0;
} }
...@@ -359,11 +362,12 @@ jbig2enc_oob(struct jbig2enc_ctx *restrict ctx, int proc) { ...@@ -359,11 +362,12 @@ jbig2enc_oob(struct jbig2enc_ctx *restrict ctx, int proc) {
// see comments in .h file // see comments in .h file
void void
jbig2enc_int(struct jbig2enc_ctx *restrict ctx, int proc, int value) { jbig2enc_int(struct jbig2enc_ctx *restrict ctx, int proc, int value)
{
u8 *const context = ctx->intctx[proc]; u8 *const context = ctx->intctx[proc];
int i; int i;
if (value > 2000000000 || value < -2000000000) abort(); // if (value > 2000000000 || value < -2000000000) assert();
u32 prev = 1; u32 prev = 1;
...@@ -404,10 +408,12 @@ jbig2enc_int(struct jbig2enc_ctx *restrict ctx, int proc, int value) { ...@@ -404,10 +408,12 @@ jbig2enc_int(struct jbig2enc_ctx *restrict ctx, int proc, int value) {
// see comments in .h file // see comments in .h file
void void
jbig2enc_iaid(struct jbig2enc_ctx *restrict ctx, int symcodelen, int value) { jbig2enc_iaid(struct jbig2enc_ctx *restrict ctx, int symcodelen, int value)
if (!ctx->iaidctx) { {
if (!ctx->iaidctx)
{
// we've not yet allocated the context index buffer for this // we've not yet allocated the context index buffer for this
ctx->iaidctx = (u8 *) malloc(1 << symcodelen); ctx->iaidctx = (u8 *) new u8[1 << symcodelen];
memset(ctx->iaidctx, 0, 1 << symcodelen); memset(ctx->iaidctx, 0, 1 << symcodelen);
} }
const u32 mask = (1 << (symcodelen + 1)) - 1; const u32 mask = (1 << (symcodelen + 1)) - 1;
......
...@@ -286,7 +286,8 @@ jbig2_pages_complete(struct jbig2ctx *ctx, int *const length) { ...@@ -286,7 +286,8 @@ jbig2_pages_complete(struct jbig2ctx *ctx, int *const length) {
jbig2enc_init(&ectx); jbig2enc_init(&ectx);
struct jbig2_file_header header; struct jbig2_file_header header;
if (ctx->full_headers) { if (ctx->full_headers)
{
memset(&header, 0, sizeof(header)); memset(&header, 0, sizeof(header));
header.n_pages = htonl(ctx->classer->npages); header.n_pages = htonl(ctx->classer->npages);
header.organisation_type = 1; header.organisation_type = 1;
......
#ifndef _JBIG2_ENCODER_H #ifndef _JBIG2_ENCODER_H
#define _JBIG2_ENCODER_H #define _JBIG2_ENCODER_H
#include <vector> #include <vector>
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#include "../LeptonLib/allheaders.h" #include "../LeptonLib/allheaders.h"
#include "../LeptonLib/pix.h" #include "../LeptonLib/pix.h"
#include "jbig2enc.h" #include "jbig2enc.h"
#include "io.h"
#include "../../../Common/DocxFormat/Source/SystemUtility/File.h"
#if defined(_WIN32) || defined (_WIN64)
// ----------------------------------------------------------------------------- #if defined(_WIN32) || defined (_WIN64)
// Windows, sadly, lacks asprintf // -----------------------------------------------------------------------------
// ----------------------------------------------------------------------------- // Windows, sadly, lacks asprintf
#include <stdarg.h> // -----------------------------------------------------------------------------
int asprintf(char **strp, const char *fmt, ...) #include <stdarg.h>
{ int asprintf(char **strp, const char *fmt, ...)
va_list va; {
va_start(va, fmt); va_list va;
va_start(va, fmt);
const int required = vsnprintf(NULL, 0, fmt, va);
char *const buffer = (char *) malloc(required + 1); const int required = vsnprintf(NULL, 0, fmt, va);
const int ret = vsnprintf(buffer, required + 1, fmt, va); char *const buffer = (char *) malloc(required + 1);
*strp = buffer; const int ret = vsnprintf(buffer, required + 1, fmt, va);
*strp = buffer;
va_end(va);
va_end(va);
return ret;
} return ret;
#endif }
#endif
// -----------------------------------------------------------------------------
// Morphological operations for segmenting an image into text regions // -----------------------------------------------------------------------------
// ----------------------------------------------------------------------------- // Morphological operations for segmenting an image into text regions
static const char *segment_mask_sequence = "r11"; // -----------------------------------------------------------------------------
static const char *segment_seed_sequence = "r1143 + o4.4 + x4"; /* maybe o6.6 */ static const char *segment_mask_sequence = "r11";
static const char *segment_dilation_sequence = "d3.3"; static const char *segment_seed_sequence = "r1143 + o4.4 + x4"; /* maybe o6.6 */
static const char *segment_dilation_sequence = "d3.3";
// -----------------------------------------------------------------------------
// Takes two pix as input, generated from the same original image: // -----------------------------------------------------------------------------
// 1. pixb - a binary thresholded image // Takes two pix as input, generated from the same original image:
// 2. piximg - a full color or grayscale image // 1. pixb - a binary thresholded image
// and segments them by finding the areas that contain color or grayscale // 2. piximg - a full color or grayscale image
// graphics, removing those areas from the binary image, and doing the // and segments them by finding the areas that contain color or grayscale
// opposite for the full color/grayscale image. The upshot is that after // graphics, removing those areas from the binary image, and doing the
// this routine has been run, the binary image contains only text and the // opposite for the full color/grayscale image. The upshot is that after
// full color image contains only the graphics. // this routine has been run, the binary image contains only text and the
// // full color image contains only the graphics.
// Both input images are modified by this procedure. If no text is found, //
// pixb is set to NULL. If no graphics is found, piximg is set to NULL. // Both input images are modified by this procedure. If no text is found,
// // pixb is set to NULL. If no graphics is found, piximg is set to NULL.
// Thanks to Dan Bloomberg for this //
// ----------------------------------------------------------------------------- // Thanks to Dan Bloomberg for this
// -----------------------------------------------------------------------------
static PIX*
segment_image(PIX *pixb, PIX *piximg) { static PIX*
// Make seed and mask, and fill seed into mask segment_image(PIX *pixb, PIX *piximg) {
PIX *pixmask4 = pixMorphSequence(pixb, (char *) segment_mask_sequence, 0); // Make seed and mask, and fill seed into mask
PIX *pixseed4 = pixMorphSequence(pixb, (char *) segment_seed_sequence, 0); PIX *pixmask4 = pixMorphSequence(pixb, (char *) segment_mask_sequence, 0);
PIX *pixsf4 = pixSeedfillBinary(NULL, pixseed4, pixmask4, 8); PIX *pixseed4 = pixMorphSequence(pixb, (char *) segment_seed_sequence, 0);
PIX *pixd4 = pixMorphSequence(pixsf4, (char *) segment_dilation_sequence, 0); PIX *pixsf4 = pixSeedfillBinary(NULL, pixseed4, pixmask4, 8);
PIX *pixd4 = pixMorphSequence(pixsf4, (char *) segment_dilation_sequence, 0);
// we want to force the binary mask to be the same size as the
// input color image, so we have to do it this way... // we want to force the binary mask to be the same size as the
// is there a better way? // input color image, so we have to do it this way...
// PIX *pixd = pixExpandBinary(pixd4, 4); // is there a better way?
PIX *pixd = pixCreate(piximg->w, piximg->h, 1); // PIX *pixd = pixExpandBinary(pixd4, 4);
pixCopyResolution(pixd, piximg); PIX *pixd = pixCreate(piximg->w, piximg->h, 1);
expandBinaryPower2Low(pixd->data, pixd->w, pixd->h, pixd->wpl, pixCopyResolution(pixd, piximg);
pixd4->data, pixd4->w, pixd4->h, pixd4->wpl, 4); expandBinaryPower2Low(pixd->data, pixd->w, pixd->h, pixd->wpl,
pixd4->data, pixd4->w, pixd4->h, pixd4->wpl, 4);
pixDestroy(&pixd4);
pixDestroy(&pixsf4); pixDestroy(&pixd4);
pixDestroy(&pixseed4); pixDestroy(&pixsf4);
pixDestroy(&pixmask4); pixDestroy(&pixseed4);
pixDestroy(&pixmask4);
pixSubtract(pixb, pixb, pixd);
pixSubtract(pixb, pixb, pixd);
// now see what we got from the segmentation
static l_int32 *tab = NULL; // now see what we got from the segmentation
if (tab == NULL) tab = makePixelSumTab8(); static l_int32 *tab = NULL;
if (tab == NULL) tab = makePixelSumTab8();
// if no image portion was found, set the image pointer to NULL and return
l_int32 pcount; // if no image portion was found, set the image pointer to NULL and return
pixCountPixels(pixd, &pcount, tab); l_int32 pcount;
if (pcount < 100) { pixCountPixels(pixd, &pcount, tab);
pixDestroy(&pixd); if (pcount < 100) {
return NULL; pixDestroy(&pixd);
} return NULL;
}
// if no text portion found, set the binary pointer to NULL
pixCountPixels(pixb, &pcount, tab); // if no text portion found, set the binary pointer to NULL
if (pcount < 100) { pixCountPixels(pixb, &pcount, tab);
pixDestroy(&pixb); if (pcount < 100) {
} pixDestroy(&pixb);
}
PIX *piximg1;
if (piximg->d == 1 || piximg->d == 8 || piximg->d == 32) { PIX *piximg1;
piximg1 = pixClone(piximg); if (piximg->d == 1 || piximg->d == 8 || piximg->d == 32) {
} else if (piximg->d > 8) { piximg1 = pixClone(piximg);
piximg1 = pixConvertTo32(piximg); } else if (piximg->d > 8) {
} else { piximg1 = pixConvertTo32(piximg);
piximg1 = pixConvertTo8(piximg, FALSE); } else {
} piximg1 = pixConvertTo8(piximg, FALSE);
}
PIX *pixd1;
if (piximg1->d == 32) { PIX *pixd1;
pixd1 = pixConvertTo32(pixd); if (piximg1->d == 32) {
} else if (piximg1->d == 8) { pixd1 = pixConvertTo32(pixd);
pixd1 = pixConvertTo8(pixd, FALSE); } else if (piximg1->d == 8) {
} else { pixd1 = pixConvertTo8(pixd, FALSE);
pixd1 = pixClone(pixd); } else {
} pixd1 = pixClone(pixd);
pixDestroy(&pixd); }
pixDestroy(&pixd);
pixRasteropFullImage(pixd1, piximg1, PIX_SRC | PIX_DST);
pixRasteropFullImage(pixd1, piximg1, PIX_SRC | PIX_DST);
pixDestroy(&piximg1);
pixDestroy(&piximg1);
return pixd1;
return pixd1;
} }
#endif /* _JBIG2_ENCODER_H */ #endif /* _JBIG2_ENCODER_H */
\ No newline at end of file
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <netinet/in.h> #include <netinet/in.h>
#endif #endif
#include <string.h>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// See comments in jbig2structs.h about the bit packing in this structure. // See comments in jbig2structs.h about the bit packing in this structure.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -32,9 +32,9 @@ bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int n ...@@ -32,9 +32,9 @@ bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int n
int lBufferSize = BufferSize; int lBufferSize = BufferSize;
unsigned char *pSourceBuffer = pBufferBGRA; unsigned char *pSourceBuffer = pBufferBGRA;
PIX *pSource = pixCreate( nWidth, nHeight, 32 ); PIX *pSource = pixCreate( nWidth, nHeight, 32 );
if ( !pSource ) return false; if ( !pSource ) return false;
for ( int nY = 0; nY < nHeight; nY++ ) for ( int nY = 0; nY < nHeight; nY++ )
{ {
...@@ -44,158 +44,158 @@ bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int n ...@@ -44,158 +44,158 @@ bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int n
} }
} }
jbig2ctx *pContext = jbig2_init( m_dTreshold, 0.5, 0, 0, ! m_bPDFMode, m_bRefine ? 10 : -1 ); jbig2ctx *pContext = jbig2_init( m_dTreshold, 0.5, 0, 0, ! m_bPDFMode, m_bRefine ? 10 : -1 );
// JBig2 // JBig2
// TO DO: 1 JBig2 // TO DO: 1 JBig2
// ColorMap // ColorMap
PIX *pPixL = NULL; PIX *pPixL = NULL;
if ( NULL == ( pPixL = pixRemoveColormap( pSource, REMOVE_CMAP_BASED_ON_SRC ) ) ) if ( NULL == ( pPixL = pixRemoveColormap( pSource, REMOVE_CMAP_BASED_ON_SRC ) ) )
{ {
pixDestroy( &pSource ); pixDestroy( &pSource );
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return false; return false;
} }
pixDestroy( &pSource ); pixDestroy( &pSource );
PIX *pPixT = NULL; PIX *pPixT = NULL;
if ( pPixL->d > 1 ) if ( pPixL->d > 1 )
{ {
PIX *pGray = NULL; PIX *pGray = NULL;
if ( pPixL->d > 8 ) if ( pPixL->d > 8 )
{ {
pGray = pixConvertRGBToGrayFast( pPixL ); pGray = pixConvertRGBToGrayFast( pPixL );
if ( !pGray ) if ( !pGray )
{ {
pixDestroy( &pSource ); pixDestroy( &pSource );
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return false; return false;
} }
} }
else else
{ {
pGray = pixClone( pPixL ); pGray = pixClone( pPixL );
} }
if ( m_bUpscale2x ) if ( m_bUpscale2x )
{ {
pPixT = pixScaleGray2xLIThresh( pGray, m_nBwTreshold ); pPixT = pixScaleGray2xLIThresh( pGray, m_nBwTreshold );
} }
else if ( m_bUpscale4x ) else if ( m_bUpscale4x )
{ {
pPixT = pixScaleGray4xLIThresh( pGray, m_nBwTreshold ); pPixT = pixScaleGray4xLIThresh( pGray, m_nBwTreshold );
} }
else else
{ {
pPixT = pixThresholdToBinary( pGray, m_nBwTreshold ); pPixT = pixThresholdToBinary( pGray, m_nBwTreshold );
} }
pixDestroy( &pGray ); pixDestroy( &pGray );
} }
else else
{ {
pPixT = pixClone( pPixL ); pPixT = pixClone( pPixL );
} }
if ( m_sOutputTreshold.length() > 0 ) if ( m_sOutputTreshold.length() > 0 )
{ {
pixWrite( m_sOutputTreshold.c_str(), pPixT, IFF_BMP ); pixWrite( m_sOutputTreshold.c_str(), pPixT, IFF_BMP );
} }
if ( m_bSegment && pPixL->d > 1 ) if ( m_bSegment && pPixL->d > 1 )
{ {
PIX *pGraphics = segment_image( pPixT, pPixL ); PIX *pGraphics = segment_image( pPixT, pPixL );
if ( pGraphics ) if ( pGraphics )
{ {
char *sFilename; char *sFilename;
asprintf( &sFilename, "%s.%04d.%s", m_sBaseName.c_str(), 0, ".bmp" ); asprintf( &sFilename, "%s.%04d.%s", m_sBaseName.c_str(), 0, ".bmp" );
pixWrite( sFilename, pGraphics, IFF_BMP ); pixWrite( sFilename, pGraphics, IFF_BMP );
free( sFilename ); free( sFilename );
} }
if ( !pPixT ) if ( !pPixT )
{ {
// //
return true; return true;
} }
} }
pixDestroy( &pPixL ); pixDestroy( &pPixL );
if ( !m_bSymbolMode ) if ( !m_bSymbolMode )
{ {
int nLength = 0; int nLength = 0;
uint8_t *pBuffer = jbig2_encode_generic( pPixT, !m_bPDFMode, 0, 0, m_bDuplicateLineRemoval, &nLength ); uint8_t *pBuffer = jbig2_encode_generic( pPixT, !m_bPDFMode, 0, 0, m_bDuplicateLineRemoval, &nLength );
bool bRes = true; bool bRes = true;
FILE *pFile = _wfopen( sDstFileName.c_str(), _T("wb") ); CFile file;
if ( pFile && pBuffer ) if (file.CreateFile(sDstFileName.c_str() ) == S_OK )
{ {
::fwrite( pBuffer, nLength, 1, pFile ); file.WriteFile(pBuffer, nLength);
::fclose( pFile ); file.CloseFile();
bRes = true; bRes = true;
} }
else else
bRes = false; bRes = false;
pixDestroy( &pPixT ); pixDestroy( &pPixT );
if ( pBuffer ) free( pBuffer ); if ( pBuffer ) free( pBuffer );
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return bRes; return bRes;
} }
int nNumPages = 1; int nNumPages = 1;
jbig2_add_page( pContext, pPixT ); jbig2_add_page( pContext, pPixT );
pixDestroy( &pPixT ); pixDestroy( &pPixT );
int nLength = 0; int nLength = 0;
uint8_t *pBuffer = jbig2_pages_complete( pContext, &nLength ); uint8_t *pBuffer = jbig2_pages_complete( pContext, &nLength );
if ( !pBuffer ) if ( !pBuffer )
{ {
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return false; return false;
} }
if ( m_bPDFMode ) if ( m_bPDFMode )
{ {
std::wstring sFileName = sDstFileName;//m_sBaseName + _T(".sym"); std::wstring sFileName = sDstFileName;//m_sBaseName + _T(".sym");
const int nFileD = _wopen( sFileName.c_str(), O_WRONLY | O_TRUNC | O_CREAT /*| WINBINARY*/, 0600 );
CFile file;
if ( nFileD < 0 ) if ( file.CreateFile(sFileName.c_str()) != S_OK)
{ {
free( pBuffer ); free( pBuffer );
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return false; return false;
} }
write( nFileD, pBuffer, nLength ); file.WriteFile( pBuffer, nLength );
close( nFileD ); file.CloseFile();
} }
free( pBuffer ); free( pBuffer );
for ( int nIndex = 0; nIndex < nNumPages; ++nIndex ) for ( int nIndex = 0; nIndex < nNumPages; ++nIndex )
{ {
pBuffer = jbig2_produce_page( pContext, nIndex, -1, -1, &nLength ); pBuffer = jbig2_produce_page( pContext, nIndex, -1, -1, &nLength );
if ( m_bPDFMode ) if ( m_bPDFMode )
{ {
std::wstring sFileName = m_sBaseName + _T(".0000"); std::wstring sFileName = m_sBaseName + _T(".0000");
const int nFileD = _wopen( sFileName.c_str(), O_WRONLY | O_TRUNC | O_CREAT /*| WINBINARY*/, 0600 ); CFile file;
if ( nFileD < 0 ) if ( file.CreateFile(sFileName.c_str()) != S_OK)
{ {
free( pBuffer ); free( pBuffer );
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return false; return false;
} }
write( nFileD, pBuffer, nLength ); file.WriteFile( pBuffer, nLength );
close( nFileD ); file.CloseFile();
} }
free( pBuffer ); free( pBuffer );
} }
jbig2_destroy( pContext ); jbig2_destroy( pContext );
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment