219 #ifndef __PGFROISUPPORT__ 224 ASSERT(0 <= quality && quality <= MaxQuality);
225 bool returnValue =
true;
228 clock_t start = 0, mean = 0, end = 0;
229 UINT32 writtenBytes = 0;
230 CPGFStream *stream =
nullptr;
234 #elif defined(__POSIX__) 242 fd = CreateFile(dest, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
243 if (fd == INVALID_HANDLE_VALUE) {
244 cerr <<
"Error: Could not open destination file." << endl;
251 stream =
new CPGFFileStream(fd);
253 #elif defined(__POSIX__) 254 fd = open(dest, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
256 cout <<
"Error: Could not open destination file." << endl;
263 stream =
new CPGFFileStream(fd);
268 if (!
bQuiet) cout <<
"Encoding PGF image to memory stream (quality: " << quality <<
", levels: " << levels <<
"): " << source << endl;
270 if (!
bQuiet) cout <<
"Encoding PGF image (quality: " << quality <<
", levels: " << levels <<
"): " << source << endl;
272 if (roi || streaming) {
274 cout <<
"PGF image will support ROI." << endl;
276 cout << dest <<
" will support ROI." << endl;
287 if (!image->
Load(source)) {
290 FORMAT_MESSAGE_ALLOCATE_BUFFER |
291 FORMAT_MESSAGE_FROM_SYSTEM |
292 FORMAT_MESSAGE_IGNORE_INSERTS,
295 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
300 cerr <<
"Error: " << lpMsgBuf << endl;
305 #elif defined(__POSIX__) 306 if (!image->
Load(source) ){
307 cerr <<
"Error: Could not load source file." << endl;
315 if ((bpp < 1) || (bpp > 48) || (bpp == 4)) {
316 cerr <<
"Error: Unhandled image format." << endl;
321 ASSERT((bpp >= 1) && (bpp <= 48) && (bpp != 4));
331 pgf.ConfigureEncoder(
true,
false);
335 header.nLevels = (UINT8)levels;
336 header.quality = (UINT8)quality;
338 header.bpp = header.channels = 0;
339 header.usedBitsPerChannel = 0;
343 pgf.SetHeader(header, (roi || streaming) ? PGFROI : 0);
345 char data[] =
"This is a free text annotation.";
346 pgf.SetHeader(header, (roi || streaming) ? PGFROI : 0, (UINT8 *)data,
sizeof(data));
349 #ifdef __PNMEXSUPPORT__ 357 UINT8* buff = (UINT8 *)image->
GetBits();
359 int map[] = { 2, 1, 0 };
362 #ifdef __BIG_ENDIAN__ 363 int map[] = { 2, 1, 0 };
373 RGBQUAD* pColorTable =
new RGBQUAD[colorTableSize];
376 pgf.SetColorTable(0, colorTableSize, pColorTable);
377 delete[] pColorTable;
380 }
catch(IOException& e) {
383 if (err >= AppError) {
384 cerr <<
"Error: Importing input image failed\n(" <<
PGFErrors[err - AppError] <<
")!" << endl;
386 cerr <<
"Error: Importing input image failed (" << err <<
")!" << endl;
393 #ifdef __PGFROISUPPORT__ 396 writtenBytes = pgf.WriteHeader(stream);
397 if (!
bQuiet) cout <<
"Write header [" << writtenBytes <<
" bytes]" << endl;
399 for(
int i = pgf.Levels() - 1; i >= 0; i--) {
400 UINT32 size = pgf.Write(i);
401 if (!
bQuiet) cout <<
"Write level " << i <<
" [" << size <<
" bytes]" << endl;
402 writtenBytes += size;
405 #endif __PGFROISUPPORT__ 408 pgf.Write(stream, &writtenBytes);
411 }
catch(IOException& e) {
413 if (err >= AppError) {
414 cerr <<
"Error: Writing PGF image failed\n(" <<
PGFErrors[err - AppError] <<
")!" << endl;
416 cerr <<
"Error: Writing PGF image failed (" << err <<
")!" << endl;
427 pgf.ResetStreamPos(
false);
431 if (fd) CloseHandle(fd);
432 #elif defined(__POSIX__) 440 double destSize = (memStream) ? writtenBytes :
double(
FileSize(dest));
441 double ratio = double(
FileSize(source))/destSize;
444 cout << double(end - mean)/CLOCKS_PER_SEC <<
';' << double(end - start)/CLOCKS_PER_SEC <<
';' << ratio <<
';';
446 cout <<
"Written bytes: " << writtenBytes << endl;
447 cout <<
"Encoding time (encoding, writing PGF): " << double(end - mean)/CLOCKS_PER_SEC <<
" s" << endl;
448 cout <<
"Total time (reading source, encoding, writing PGF): " << double(end - start)/CLOCKS_PER_SEC <<
" s" << endl;
449 cout <<
"Compression ratio: " << ratio << endl;
bool Load(const char *source)
unsigned char GetBPP() const
#define ImageModeIndexedColor
unsigned char * GetBits() const
unsigned char GetColorType() const
static INT64 FileSize(char *filename)
static string PGFErrors[]
void GetColorTable(int firstColor, int numColors, void *prgbColors)
int GetMaxColorTableEntries()
unsigned int GetHeight() const
int GetChannelDepth() const
unsigned int GetWidth() const