-/*\r
- * File: ximawbmp.cpp\r
- * Purpose: Platform Independent WBMP Image Class Loader and Writer\r
- * 12/Jul/2002 Davide Pizzolato - www.xdp.it\r
- * CxImage version 6.0.0 02/Feb/2008\r
- */\r
-\r
-#include "ximawbmp.h"\r
-\r
-#if CXIMAGE_SUPPORT_WBMP\r
-\r
-#include "ximaiter.h"\r
-\r
-////////////////////////////////////////////////////////////////////////////////\r
-#if CXIMAGE_SUPPORT_DECODE\r
-////////////////////////////////////////////////////////////////////////////////\r
-bool CxImageWBMP::Decode(CxFile *hFile)\r
-{\r
- if (hFile == NULL) return false;\r
-\r
- WBMPHEADER wbmpHead;\r
-\r
- cx_try\r
- {\r
- ReadOctet(hFile, &wbmpHead.Type);\r
-\r
- DWORD dat;\r
- ReadOctet(hFile, &dat);\r
- wbmpHead.FixHeader = (BYTE)dat;\r
-\r
- ReadOctet(hFile, &wbmpHead.ImageWidth);\r
- ReadOctet(hFile, &wbmpHead.ImageHeight);\r
-\r
- if (hFile->Eof())\r
- cx_throw("Not a WBMP");\r
-\r
- if (wbmpHead.Type != 0)\r
- cx_throw("Unsupported WBMP type"); \r
-\r
- head.biWidth = wbmpHead.ImageWidth;\r
- head.biHeight= wbmpHead.ImageHeight;\r
-\r
- if (head.biWidth<=0 || head.biHeight<=0)\r
- cx_throw("Corrupted WBMP");\r
-\r
- if (info.nEscape == -1){\r
- info.dwType = CXIMAGE_FORMAT_WBMP;\r
- return true;\r
- }\r
-\r
- Create(head.biWidth, head.biHeight, 1, CXIMAGE_FORMAT_WBMP);\r
- if (!IsValid()) cx_throw("WBMP Create failed");\r
- SetGrayPalette();\r
-\r
- int linewidth=(head.biWidth+7)/8;\r
- CImageIterator iter(this);\r
- iter.Upset();\r
- for (long y=0; y < head.biHeight; y++){\r
- hFile->Read(iter.GetRow(),linewidth,1);\r
- iter.PrevRow();\r
- }\r
-\r
- } cx_catch {\r
- if (strcmp(message,"")) strncpy(info.szLastError,message,255);\r
- return FALSE;\r
- }\r
- return true;\r
-}\r
-////////////////////////////////////////////////////////////////////////////////\r
-bool CxImageWBMP::ReadOctet(CxFile * hFile, DWORD *data)\r
-{\r
- BYTE c;\r
- *data = 0;\r
- do {\r
- if (hFile->Eof()) return false;\r
- c = (BYTE)hFile->GetC();\r
- *data <<= 7;\r
- *data |= (c & 0x7F);\r
- } while ((c&0x80)!=0);\r
- return true;\r
-}\r
-////////////////////////////////////////////////////////////////////////////////\r
-#endif //CXIMAGE_SUPPORT_DECODE\r
-////////////////////////////////////////////////////////////////////////////////\r
-#if CXIMAGE_SUPPORT_ENCODE\r
-////////////////////////////////////////////////////////////////////////////////\r
-bool CxImageWBMP::Encode(CxFile * hFile)\r
-{\r
- if (EncodeSafeCheck(hFile)) return false;\r
-\r
- //check format limits\r
- if (head.biBitCount!=1){\r
- strcpy(info.szLastError,"Can't save this image as WBMP");\r
- return false;\r
- }\r
-\r
- WBMPHEADER wbmpHead;\r
- wbmpHead.Type=0;\r
- wbmpHead.FixHeader=0;\r
- wbmpHead.ImageWidth=head.biWidth;\r
- wbmpHead.ImageHeight=head.biHeight;\r
-\r
- // Write the file header\r
- hFile->PutC('\0');\r
- hFile->PutC('\0');\r
- WriteOctet(hFile,wbmpHead.ImageWidth);\r
- WriteOctet(hFile,wbmpHead.ImageHeight);\r
- // Write the pixels\r
- int linewidth=(wbmpHead.ImageWidth+7)/8;\r
- CImageIterator iter(this);\r
- iter.Upset();\r
- for (DWORD y=0; y < wbmpHead.ImageHeight; y++){\r
- hFile->Write(iter.GetRow(),linewidth,1);\r
- iter.PrevRow();\r
- }\r
- return true;\r
-}\r
-////////////////////////////////////////////////////////////////////////////////\r
-bool CxImageWBMP::WriteOctet(CxFile * hFile, const DWORD data)\r
-{\r
- int ns = 0;\r
- while (data>>(ns+7)) ns+=7;\r
- while (ns>0){\r
- if (!hFile->PutC(0x80 | (BYTE)(data>>ns))) return false;\r
- ns-=7;\r
- }\r
- if (!(hFile->PutC((BYTE)(0x7F & data)))) return false;\r
- return true;\r
-}\r
-////////////////////////////////////////////////////////////////////////////////\r
-#endif // CXIMAGE_SUPPORT_ENCODE\r
-////////////////////////////////////////////////////////////////////////////////\r
-#endif // CXIMAGE_SUPPORT_WBMP\r
-\r
+/*
+ * File: ximawbmp.cpp
+ * Purpose: Platform Independent WBMP Image Class Loader and Writer
+ * 12/Jul/2002 Davide Pizzolato - www.xdp.it
+ * CxImage version 6.0.0 02/Feb/2008
+ */
+
+#include "ximawbmp.h"
+
+#if CXIMAGE_SUPPORT_WBMP
+
+#include "ximaiter.h"
+
+////////////////////////////////////////////////////////////////////////////////
+#if CXIMAGE_SUPPORT_DECODE
+////////////////////////////////////////////////////////////////////////////////
+bool CxImageWBMP::Decode(CxFile *hFile)
+{
+ if (hFile == NULL) return false;
+
+ WBMPHEADER wbmpHead;
+
+ cx_try
+ {
+ ReadOctet(hFile, &wbmpHead.Type);
+
+ DWORD dat;
+ ReadOctet(hFile, &dat);
+ wbmpHead.FixHeader = (BYTE)dat;
+
+ ReadOctet(hFile, &wbmpHead.ImageWidth);
+ ReadOctet(hFile, &wbmpHead.ImageHeight);
+
+ if (hFile->Eof())
+ cx_throw("Not a WBMP");
+
+ if (wbmpHead.Type != 0)
+ cx_throw("Unsupported WBMP type");
+
+ head.biWidth = wbmpHead.ImageWidth;
+ head.biHeight= wbmpHead.ImageHeight;
+
+ if (head.biWidth<=0 || head.biHeight<=0)
+ cx_throw("Corrupted WBMP");
+
+ if (info.nEscape == -1){
+ info.dwType = CXIMAGE_FORMAT_WBMP;
+ return true;
+ }
+
+ Create(head.biWidth, head.biHeight, 1, CXIMAGE_FORMAT_WBMP);
+ if (!IsValid()) cx_throw("WBMP Create failed");
+ SetGrayPalette();
+
+ int linewidth=(head.biWidth+7)/8;
+ CImageIterator iter(this);
+ iter.Upset();
+ for (long y=0; y < head.biHeight; y++){
+ hFile->Read(iter.GetRow(),linewidth,1);
+ iter.PrevRow();
+ }
+
+ } cx_catch {
+ if (strcmp(message,"")) strncpy(info.szLastError,message,255);
+ return FALSE;
+ }
+ return true;
+}
+////////////////////////////////////////////////////////////////////////////////
+bool CxImageWBMP::ReadOctet(CxFile * hFile, DWORD *data)
+{
+ BYTE c;
+ *data = 0;
+ do {
+ if (hFile->Eof()) return false;
+ c = (BYTE)hFile->GetC();
+ *data <<= 7;
+ *data |= (c & 0x7F);
+ } while ((c&0x80)!=0);
+ return true;
+}
+////////////////////////////////////////////////////////////////////////////////
+#endif //CXIMAGE_SUPPORT_DECODE
+////////////////////////////////////////////////////////////////////////////////
+#if CXIMAGE_SUPPORT_ENCODE
+////////////////////////////////////////////////////////////////////////////////
+bool CxImageWBMP::Encode(CxFile * hFile)
+{
+ if (EncodeSafeCheck(hFile)) return false;
+
+ //check format limits
+ if (head.biBitCount!=1){
+ strcpy(info.szLastError,"Can't save this image as WBMP");
+ return false;
+ }
+
+ WBMPHEADER wbmpHead;
+ wbmpHead.Type=0;
+ wbmpHead.FixHeader=0;
+ wbmpHead.ImageWidth=head.biWidth;
+ wbmpHead.ImageHeight=head.biHeight;
+
+ // Write the file header
+ hFile->PutC('\0');
+ hFile->PutC('\0');
+ WriteOctet(hFile,wbmpHead.ImageWidth);
+ WriteOctet(hFile,wbmpHead.ImageHeight);
+ // Write the pixels
+ int linewidth=(wbmpHead.ImageWidth+7)/8;
+ CImageIterator iter(this);
+ iter.Upset();
+ for (DWORD y=0; y < wbmpHead.ImageHeight; y++){
+ hFile->Write(iter.GetRow(),linewidth,1);
+ iter.PrevRow();
+ }
+ return true;
+}
+////////////////////////////////////////////////////////////////////////////////
+bool CxImageWBMP::WriteOctet(CxFile * hFile, const DWORD data)
+{
+ int ns = 0;
+ while (data>>(ns+7)) ns+=7;
+ while (ns>0){
+ if (!hFile->PutC(0x80 | (BYTE)(data>>ns))) return false;
+ ns-=7;
+ }
+ if (!(hFile->PutC((BYTE)(0x7F & data)))) return false;
+ return true;
+}
+////////////////////////////////////////////////////////////////////////////////
+#endif // CXIMAGE_SUPPORT_ENCODE
+////////////////////////////////////////////////////////////////////////////////
+#endif // CXIMAGE_SUPPORT_WBMP
+