/** @file uwmf_endian.c @brief Functions for converting WMF records between Big Endian and Little Endian byte orders. */ /* File: uwmf_endian.c Version: 0.1.5 Date: 28-MAY-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus extern "C" { #endif #include #include #include /* for offsetof() */ #include #include "uwmf.h" #include "uwmf_endian.h" // hide almost everything in this file from Doxygen //! \cond /* Prototypes for functions used here and defined in uemf_endian.c, but which are not supposed to be used in end user code. */ void U_swap2(void *ul, unsigned int count); void U_swap4(void *ul, unsigned int count); void bitmapinfo_swap(char *Bmi); /* ********************************************************************************************** These functions Swap standard objects used in the WMR records. The low level ones do not append EOL. *********************************************************************************************** */ /** \brief Swap U_BITMAP16 object \param b U_BITMAP16 object */ void bitmap16_swap( char *b ){ U_swap2(b,4); /* Type, Width, Height, WidthBytes */ /* Planes and BitsPixel are bytes, so no swap needed */ /* Bits[] pixel data should already be in order */ } /** \brief Swap a U_BRUSH object. \param b U_BRUSH object. style bColor bHatch U_BS_SOLID ColorRef Object Not used (bytes present???) U_BS_NULL ignored ignored (bytes present???). U_BS_PATTERN ignored Bitmap16 object holding patern U_BS_DIBPATTERNPT ColorUsage Enum DIB object U_BS_HATCHED ColorRef Object HatchStyle Enumeration */ void brush_swap( char *b, int torev ){ int Style; if(torev){ Style = *(uint16_t *)(b + offsetof(U_BRUSH,Style)); } U_swap2(b + offsetof(U_BRUSH,Style),1); if(!torev){ Style = *(uint16_t *)(b + offsetof(U_BRUSH,Style)); } /* Color is already in the right order */ switch(Style){ case U_BS_SOLID: /* no/ignored data field */ break; case U_BS_NULL: /* no/ignored data field */ break; case U_BS_PATTERN: bitmap16_swap(b + offsetof(U_BRUSH,Data)); break; case U_BS_DIBPATTERNPT: bitmapinfo_swap(b + offsetof(U_BRUSH,Data)); break; case U_BS_HATCHED: /* no/ignored data field */ break; } } /** \brief Swap a U_FONT object from pointer. \param lf U_FONT object */ void font_swap( char *f ){ U_swap2(f + offsetof(U_FONT,Height),5); /*Height, Width, Escapement, Orientation, Weight */ /* Other fields are single bytes */ } /** \brief Swap a pointer to a U_PALETTE object. \param lp Pointer to a U_PALETTE object. */ void palette_swap( char *p ){ U_swap2(p + offsetof(U_PALETTE,Start),2); /* Start, NumEntries*/ /* PalEntries[1] is byte ordered, so no need to swap */ } /** \brief Swap a U_PEN object. \param p U_PEN object */ void pen_swap( char *p ){ U_swap2(p + offsetof(U_PEN,Style),3); /* Style,Widthw[0],Widthw[1] */ /* Color already in order */ } /* there are no void rect16_ltrb_swap() void rect16_brtl_swap() because rectangles are swapped using U_swap2 as an array of 4 int16 values. */ /** \brief Swap U_REGION object \param rect U_REGION object \param torev PARTIAL IMPLEMENTATION */ void region_swap( char *reg, int torev ){ int Size; if(torev){ Size = *(int16_t *)(reg + offsetof(U_REGION,Size)); } U_swap2(reg,10); /* ignore1 through sRrect*/ if(!torev){ Size = *(int16_t *)(reg + offsetof(U_REGION,Size)); } U_swap2(reg + U_SIZE_REGION, (Size - U_SIZE_REGION)/2); /* aScans */ } /** \brief Swap U_BITMAPCOREHEADER object \param ch U_BITMAPCOREHEADER object */ void bitmapcoreheader_swap( char *ch ){ U_swap4(ch + offsetof(U_BITMAPCOREHEADER,Size_4), 1); /* Size_4, may not be aligned */ U_swap2(ch + offsetof(U_BITMAPCOREHEADER,Width),4); /* Width, Height, Planes, BitCount, */ } /** LogBrushW Object WMF PDF 2.2.2.10 \brief Swap a U_WLOGBRUSH object. \param lb U_WLOGBRUSH object. style Color Hatch U_BS_SOLID ColorRef Object Not used (bytes present???) U_BS_NULL ignored ignored (bytes present???). U_BS_PATTERN ignored not used (Action is not strictly defined) U_BS_DIBPATTERN ignored not used (Action is not strictly defined) U_BS_DIBPATTERNPT ignored not used (Action is not strictly defined) U_BS_HATCHED ColorRef Object HatchStyle Enumeration */ void wlogbrush_swap( char *lb ){ U_swap2(lb + offsetof(U_WLOGBRUSH,Style),1); /* Color is already in order */ U_swap2(lb + offsetof(U_WLOGBRUSH,Hatch),1); } /** \brief Swap U_POLYPOLY object from pointer \param pp PU_POLYPOLY object */ void polypolygon_swap( char *pp, int torev ){ int i,totPoints; uint16_t nPolys; uint16_t *aPolyCounts; if(torev){ nPolys = *(uint16_t *)(pp + offsetof(U_POLYPOLYGON, nPolys)); } U_swap2(pp + offsetof(U_POLYPOLYGON, nPolys),1); if(!torev){ nPolys = *(uint16_t *)(pp + offsetof(U_POLYPOLYGON, nPolys)); } aPolyCounts = (uint16_t *)(pp + offsetof(U_POLYPOLYGON, aPolyCounts)); if(torev){ for(totPoints=0,i=0;i