X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=utilities%2FCxImage%2Fximajbg.cpp;h=06fb9bfa26bcef3fcd4da6e000d1468c3c5a9e04;hb=f6c9b46ceb3aad0f9b31b67ee6d079fd498f9c73;hp=25331080da2e39094ce9080665676a1d2b845739;hpb=3fd15028ab81e6746d3af96695526d7d973a26c8;p=clitk.git diff --git a/utilities/CxImage/ximajbg.cpp b/utilities/CxImage/ximajbg.cpp index 2533108..06fb9bf 100644 --- a/utilities/CxImage/ximajbg.cpp +++ b/utilities/CxImage/ximajbg.cpp @@ -1,174 +1,174 @@ -/* - * File: ximajbg.cpp - * Purpose: Platform Independent JBG Image Class Loader and Writer - * 18/Aug/2002 Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - */ - -#include "ximajbg.h" - -#if CXIMAGE_SUPPORT_JBG - -#include "ximaiter.h" - -#define JBIG_BUFSIZE 8192 - -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_DECODE -//////////////////////////////////////////////////////////////////////////////// -bool CxImageJBG::Decode(CxFile *hFile) -{ - if (hFile == NULL) return false; - - struct jbg_dec_state jbig_state; - unsigned long xmax = 4294967295UL, ymax = 4294967295UL; - unsigned int len, cnt; - BYTE *buffer,*p; - int result; - - cx_try - { - jbg_dec_init(&jbig_state); - jbg_dec_maxsize(&jbig_state, xmax, ymax); - - buffer = (BYTE*)malloc(JBIG_BUFSIZE); - if (!buffer) cx_throw("Sorry, not enough memory available!"); - - result = JBG_EAGAIN; - do { - len = hFile->Read(buffer, 1, JBIG_BUFSIZE); - if (!len) break; - cnt = 0; - p = buffer; - while (len > 0 && (result == JBG_EAGAIN || result == JBG_EOK)) { - result = jbg_dec_in(&jbig_state, p, len, &cnt); - p += cnt; - len -= cnt; - } - } while (result == JBG_EAGAIN || result == JBG_EOK); - - if (hFile->Error()) - cx_throw("Problem while reading input file"); - if (result != JBG_EOK && result != JBG_EOK_INTR) - cx_throw("Problem with input file"); - - int w, h, bpp, planes, ew; - - w = jbg_dec_getwidth(&jbig_state); - h = jbg_dec_getheight(&jbig_state); - planes = jbg_dec_getplanes(&jbig_state); - bpp = (planes+7)>>3; - ew = (w + 7)>>3; - - if (info.nEscape == -1){ - head.biWidth = w; - head.biHeight= h; - info.dwType = CXIMAGE_FORMAT_JBG; - cx_throw("output dimensions returned"); - } - - switch (planes){ - case 1: - { - BYTE* binary_image = jbg_dec_getimage(&jbig_state, 0); - - if (!Create(w,h,1,CXIMAGE_FORMAT_JBG)) - cx_throw(""); - - SetPaletteColor(0,255,255,255); - SetPaletteColor(1,0,0,0); - - CImageIterator iter(this); - iter.Upset(); - for (int i=0;i>3; - ew = (w + 7)>>3; - - BYTE mask; - RGBQUAD *rgb = GetPalette(); - if (CompareColors(&rgb[0],&rgb[1])<0) mask=255; else mask=0; - - BYTE *buffer = (BYTE*)malloc(ew*h*2); - if (!buffer) { - strcpy(info.szLastError,"Sorry, not enough memory available!"); - return false; - } - - for (y=0; yError()){ - strcpy(info.szLastError,"Problem while writing JBG file"); - return false; - } - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -#endif // CXIMAGE_SUPPORT_JBG - +/* + * File: ximajbg.cpp + * Purpose: Platform Independent JBG Image Class Loader and Writer + * 18/Aug/2002 Davide Pizzolato - www.xdp.it + * CxImage version 6.0.0 02/Feb/2008 + */ + +#include "ximajbg.h" + +#if CXIMAGE_SUPPORT_JBG + +#include "ximaiter.h" + +#define JBIG_BUFSIZE 8192 + +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_DECODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJBG::Decode(CxFile *hFile) +{ + if (hFile == NULL) return false; + + struct jbg_dec_state jbig_state; + unsigned long xmax = 4294967295UL, ymax = 4294967295UL; + unsigned int len, cnt; + BYTE *buffer,*p; + int result; + + cx_try + { + jbg_dec_init(&jbig_state); + jbg_dec_maxsize(&jbig_state, xmax, ymax); + + buffer = (BYTE*)malloc(JBIG_BUFSIZE); + if (!buffer) cx_throw("Sorry, not enough memory available!"); + + result = JBG_EAGAIN; + do { + len = hFile->Read(buffer, 1, JBIG_BUFSIZE); + if (!len) break; + cnt = 0; + p = buffer; + while (len > 0 && (result == JBG_EAGAIN || result == JBG_EOK)) { + result = jbg_dec_in(&jbig_state, p, len, &cnt); + p += cnt; + len -= cnt; + } + } while (result == JBG_EAGAIN || result == JBG_EOK); + + if (hFile->Error()) + cx_throw("Problem while reading input file"); + if (result != JBG_EOK && result != JBG_EOK_INTR) + cx_throw("Problem with input file"); + + int w, h, bpp, planes, ew; + + w = jbg_dec_getwidth(&jbig_state); + h = jbg_dec_getheight(&jbig_state); + planes = jbg_dec_getplanes(&jbig_state); + bpp = (planes+7)>>3; + ew = (w + 7)>>3; + + if (info.nEscape == -1){ + head.biWidth = w; + head.biHeight= h; + info.dwType = CXIMAGE_FORMAT_JBG; + cx_throw("output dimensions returned"); + } + + switch (planes){ + case 1: + { + BYTE* binary_image = jbg_dec_getimage(&jbig_state, 0); + + if (!Create(w,h,1,CXIMAGE_FORMAT_JBG)) + cx_throw(""); + + SetPaletteColor(0,255,255,255); + SetPaletteColor(1,0,0,0); + + CImageIterator iter(this); + iter.Upset(); + for (int i=0;i>3; + ew = (w + 7)>>3; + + BYTE mask; + RGBQUAD *rgb = GetPalette(); + if (CompareColors(&rgb[0],&rgb[1])<0) mask=255; else mask=0; + + BYTE *buffer = (BYTE*)malloc(ew*h*2); + if (!buffer) { + strcpy(info.szLastError,"Sorry, not enough memory available!"); + return false; + } + + for (y=0; yError()){ + strcpy(info.szLastError,"Problem while writing JBG file"); + return false; + } + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_JBG +