]> Creatis software - clitk.git/blobdiff - utilities/CxImage/ximawmf.h
cosmetic
[clitk.git] / utilities / CxImage / ximawmf.h
index fb59452872687850194f0eccd913852c55d4da4d..75e119a064289363e77c0f4b7689c9d5d605d55c 100644 (file)
-/*\r
-*********************************************************************\r
- * File:       ximawmf.h\r
- * Purpose:    Windows Metafile Class Loader and Writer\r
- * Author:     Volker Horch - vhorch@gmx.de\r
- * created:    13-Jun-2002\r
-*********************************************************************\r
- */\r
-\r
-/*\r
-*********************************************************************\r
-       Notes by Author:\r
-*********************************************************************\r
-\r
-       Limitations:\r
-       ============\r
-\r
-       a) Transparency:\r
-\r
-       A Metafile is vector graphics, which has transparency by design.\r
-       This class always converts into a Bitmap format. Transparency is\r
-       supported, but there is no good way to find out, which parts\r
-       of the Metafile are transparent. There are two ways how we can\r
-       handle this:\r
-\r
-       - Clear the Background of the Bitmap with the background color\r
-         you like (i have used COLOR_WINDOW) and don't support transparency.\r
-\r
-         below #define XMF_SUPPORT_TRANSPARENCY 0\r
-                       #define XMF_COLOR_BACK RGB(Background color you like)\r
-\r
-       - Clear the Background of the Bitmap with a very unusual color\r
-         (which one ?) and use this color as the transparent color\r
-\r
-         below #define XMF_SUPPORT_TRANSPARENCY 1\r
-                       #define XMF_COLOR_TRANSPARENT_R ...\r
-                       #define XMF_COLOR_TRANSPARENT_G ...\r
-                       #define XMF_COLOR_TRANSPARENT_B ...\r
-\r
-       b) Resolution\r
-\r
-       Once we have converted the Metafile into a Bitmap and we zoom in\r
-       or out, the image may not look very good. If we still had the\r
-       original Metafile, zooming would produce good results always.\r
-\r
-       c) Size\r
-\r
-       Although the filesize of a Metafile may be very small, it might\r
-       produce a Bitmap with a bombastic size. Assume you have a Metafile\r
-       with an image size of 6000*4000, which contains just one Metafile\r
-       record ((e.g. a line from (0,0) to (6000, 4000)). The filesize\r
-       of this Metafile would be let's say 100kB. If we convert it to\r
-       a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume\r
-       about 68MB of memory.\r
-\r
-       I have choosen, to limit the size of the Bitmap to max.\r
-       screensize, to avoid memory problems.\r
-\r
-       If you want something else,\r
-       modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below\r
-\r
-*********************************************************************\r
-*/\r
-\r
-#ifndef _XIMAWMF_H\r
-#define _XIMAWMF_H\r
-\r
-#include "ximage.h"\r
-\r
-#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS\r
-\r
-class CxImageWMF: public CxImage\r
-{\r
-\r
-#pragma pack(1)\r
-\r
-typedef struct tagRECT16\r
-{\r
-       short int       left;\r
-       short int       top;\r
-       short int       right;\r
-       short int       bottom;\r
-} RECT16;\r
-\r
-// taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources)\r
-typedef struct tagMETAFILEHEADER\r
-{\r
-       DWORD   key;            // always 0x9ac6cdd7\r
-       WORD    reserved1;      // reserved = 0\r
-       RECT16  bbox;           // bounding rectangle in metafile units as defined in "inch"\r
-       WORD    inch;           // number of metafile units per inch (should be < 1440)\r
-       DWORD   reserved2;      // reserved = 0\r
-       WORD    checksum;       // sum of the first 10 WORDS (using XOR operator)\r
-} METAFILEHEADER;\r
-\r
-#pragma pack()\r
-\r
-public:\r
-       CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { }\r
-\r
-       bool Decode(CxFile * hFile, long nForceWidth=0, long nForceHeight=0);\r
-       bool Decode(FILE *hFile, long nForceWidth=0, long nForceHeight=0)\r
-                       { CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); }\r
-\r
-#if CXIMAGE_SUPPORT_ENCODE\r
-       bool Encode(CxFile * hFile);\r
-       bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }\r
-#endif // CXIMAGE_SUPPORT_ENCODE\r
-\r
-protected:\r
-       void ShrinkMetafile(int &cx, int &cy);\r
-       BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader);\r
-       HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader);\r
-       HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh);\r
-\r
-};\r
-\r
-#define        METAFILEKEY     0x9ac6cdd7L\r
-\r
-// Background color definition (if no transparency). see Notes above\r
-#define        XMF_COLOR_BACK  GetSysColor(COLOR_WINDOW)\r
-// alternatives\r
-//#define      XMF_COLOR_BACK  RGB(192, 192, 192)      // lite gray\r
-//#define      XMF_COLOR_BACK  RGB(  0,   0,   0)      // black\r
-//#define      XMF_COLOR_BACK  RGB(255, 255, 255)      // white\r
-\r
-\r
-// transparency support. see Notes above\r
-#define        XMF_SUPPORT_TRANSPARENCY        0\r
-#define        XMF_COLOR_TRANSPARENT_R         211\r
-#define        XMF_COLOR_TRANSPARENT_G         121\r
-#define        XMF_COLOR_TRANSPARENT_B         112\r
-// don't change\r
-#define        XMF_COLOR_TRANSPARENT           RGB (XMF_COLOR_TRANSPARENT_R, \\r
-                                                                                XMF_COLOR_TRANSPARENT_G, \\r
-                                                                                XMF_COLOR_TRANSPARENT_B)\r
-// don't change\r
-#define        XMF_RGBQUAD_TRANSPARENT         XMF_COLOR_TRANSPARENT_B, \\r
-                                                                       XMF_COLOR_TRANSPARENT_G, \\r
-                                                                       XMF_COLOR_TRANSPARENT_R, \\r
-                                                                       0\r
-// max. size. see Notes above\r
-// alternatives\r
-//#define      XMF_MAXSIZE_CX  (GetSystemMetrics(SM_CXSCREEN)-10)\r
-//#define      XMF_MAXSIZE_CY  (GetSystemMetrics(SM_CYSCREEN)-50)\r
-//#define      XMF_MAXSIZE_CX  (2*GetSystemMetrics(SM_CXSCREEN)/3)\r
-//#define      XMF_MAXSIZE_CY  (2*GetSystemMetrics(SM_CYSCREEN)/3)\r
-#define        XMF_MAXSIZE_CX  4000\r
-#define        XMF_MAXSIZE_CY  4000\r
-\r
-\r
-#endif\r
-\r
-#endif\r
+/*
+*********************************************************************
+ * File:       ximawmf.h
+ * Purpose:    Windows Metafile Class Loader and Writer
+ * Author:     Volker Horch - vhorch@gmx.de
+ * created:    13-Jun-2002
+*********************************************************************
+ */
+
+/*
+*********************************************************************
+       Notes by Author:
+*********************************************************************
+
+       Limitations:
+       ============
+
+       a) Transparency:
+
+       A Metafile is vector graphics, which has transparency by design.
+       This class always converts into a Bitmap format. Transparency is
+       supported, but there is no good way to find out, which parts
+       of the Metafile are transparent. There are two ways how we can
+       handle this:
+
+       - Clear the Background of the Bitmap with the background color
+         you like (i have used COLOR_WINDOW) and don't support transparency.
+
+         below #define XMF_SUPPORT_TRANSPARENCY 0
+                       #define XMF_COLOR_BACK RGB(Background color you like)
+
+       - Clear the Background of the Bitmap with a very unusual color
+         (which one ?) and use this color as the transparent color
+
+         below #define XMF_SUPPORT_TRANSPARENCY 1
+                       #define XMF_COLOR_TRANSPARENT_R ...
+                       #define XMF_COLOR_TRANSPARENT_G ...
+                       #define XMF_COLOR_TRANSPARENT_B ...
+
+       b) Resolution
+
+       Once we have converted the Metafile into a Bitmap and we zoom in
+       or out, the image may not look very good. If we still had the
+       original Metafile, zooming would produce good results always.
+
+       c) Size
+
+       Although the filesize of a Metafile may be very small, it might
+       produce a Bitmap with a bombastic size. Assume you have a Metafile
+       with an image size of 6000*4000, which contains just one Metafile
+       record ((e.g. a line from (0,0) to (6000, 4000)). The filesize
+       of this Metafile would be let's say 100kB. If we convert it to
+       a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume
+       about 68MB of memory.
+
+       I have choosen, to limit the size of the Bitmap to max.
+       screensize, to avoid memory problems.
+
+       If you want something else,
+       modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below
+
+*********************************************************************
+*/
+
+#ifndef _XIMAWMF_H
+#define _XIMAWMF_H
+
+#include "ximage.h"
+
+#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS
+
+class CxImageWMF: public CxImage
+{
+
+#pragma pack(1)
+
+typedef struct tagRECT16
+{
+       short int       left;
+       short int       top;
+       short int       right;
+       short int       bottom;
+} RECT16;
+
+// taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources)
+typedef struct tagMETAFILEHEADER
+{
+       DWORD   key;            // always 0x9ac6cdd7
+       WORD    reserved1;      // reserved = 0
+       RECT16  bbox;           // bounding rectangle in metafile units as defined in "inch"
+       WORD    inch;           // number of metafile units per inch (should be < 1440)
+       DWORD   reserved2;      // reserved = 0
+       WORD    checksum;       // sum of the first 10 WORDS (using XOR operator)
+} METAFILEHEADER;
+
+#pragma pack()
+
+public:
+       CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { }
+
+       bool Decode(CxFile * hFile, long nForceWidth=0, long nForceHeight=0);
+       bool Decode(FILE *hFile, long nForceWidth=0, long nForceHeight=0)
+                       { CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); }
+
+#if CXIMAGE_SUPPORT_ENCODE
+       bool Encode(CxFile * hFile);
+       bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
+#endif // CXIMAGE_SUPPORT_ENCODE
+
+protected:
+       void ShrinkMetafile(int &cx, int &cy);
+       BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader);
+       HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader);
+       HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh);
+
+};
+
+#define        METAFILEKEY     0x9ac6cdd7L
+
+// Background color definition (if no transparency). see Notes above
+#define        XMF_COLOR_BACK  GetSysColor(COLOR_WINDOW)
+// alternatives
+//#define      XMF_COLOR_BACK  RGB(192, 192, 192)      // lite gray
+//#define      XMF_COLOR_BACK  RGB(  0,   0,   0)      // black
+//#define      XMF_COLOR_BACK  RGB(255, 255, 255)      // white
+
+
+// transparency support. see Notes above
+#define        XMF_SUPPORT_TRANSPARENCY        0
+#define        XMF_COLOR_TRANSPARENT_R         211
+#define        XMF_COLOR_TRANSPARENT_G         121
+#define        XMF_COLOR_TRANSPARENT_B         112
+// don't change
+#define        XMF_COLOR_TRANSPARENT           RGB (XMF_COLOR_TRANSPARENT_R, \
+                                                                                XMF_COLOR_TRANSPARENT_G, \
+                                                                                XMF_COLOR_TRANSPARENT_B)
+// don't change
+#define        XMF_RGBQUAD_TRANSPARENT         XMF_COLOR_TRANSPARENT_B, \
+                                                                       XMF_COLOR_TRANSPARENT_G, \
+                                                                       XMF_COLOR_TRANSPARENT_R, \
+                                                                       0
+// max. size. see Notes above
+// alternatives
+//#define      XMF_MAXSIZE_CX  (GetSystemMetrics(SM_CXSCREEN)-10)
+//#define      XMF_MAXSIZE_CY  (GetSystemMetrics(SM_CYSCREEN)-50)
+//#define      XMF_MAXSIZE_CX  (2*GetSystemMetrics(SM_CXSCREEN)/3)
+//#define      XMF_MAXSIZE_CY  (2*GetSystemMetrics(SM_CYSCREEN)/3)
+#define        XMF_MAXSIZE_CX  4000
+#define        XMF_MAXSIZE_CY  4000
+
+
+#endif
+
+#endif