[<<] [<] Page 1 of 1 [>] [>>] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
[patch] BMP for bigendian systems. Makefile tweaks
From: Jamie Guinan ####@####.#### Date: 1 Sep 2000 07:52:53 -0000 Message-Id: <Pine.LNX.4.21.0009010343180.7668-100000@gemini.home.net> BMP support was broken for big-endian systems (incl. PowerPC). Added some endian macros in new file mwendian.h, fixed devimage.c, added support in Makefile.rules, added sample #define to config.ppc. Changed Makefile.rules to stop build when building in a subdirectory fails. Clarity tweak to fblin16.c Hope this is useful. -Jamie diff -urN microwin.cvs/src/Makefile.rules microwin/src/Makefile.rules --- microwin.cvs/src/Makefile.rules Tue Aug 22 12:42:36 2000 +++ microwin/src/Makefile.rules Fri Sep 1 02:57:07 2000 @@ -28,6 +28,8 @@ # DEFINES += -DMWPIXEL_FORMAT=$(SCREEN_PIXTYPE) +DEFINES += -DMWENDIAN=$(MWENDIAN) + ifeq ($(VTSWITCH), Y) DEFINES += -DVTSWITCH=1 endif @@ -248,7 +250,7 @@ then mkdir $(TOP)/lib; fi;) endif - $(foreach dir, $(dirs), $(MAKE) -C $(dir);) + $(foreach dir, $(dirs), $(MAKE) -C $(dir) || exit 1;) # # If a library name is specified, diff -urN microwin.cvs/src/config.ppc microwin/src/config.ppc --- microwin.cvs/src/config.ppc Tue Aug 22 00:30:47 2000 +++ microwin/src/config.ppc Fri Sep 1 02:30:00 2000 @@ -92,6 +92,13 @@ #################################################################### # +# Target platform CPU endianness. MWBIGENDIAN or MWLITTLEENDIAN. +# +#################################################################### +MWENDIAN = MWBIGENDIAN + +#################################################################### +# # NanoX: Put Y to the following line to link the nano-X application # with the server. This is required for ELKS, if no network is present, # or for speed or debugging. This affects the nano-X server only. diff -urN microwin.cvs/src/drivers/fblin16.c microwin/src/drivers/fblin16.c --- microwin.cvs/src/drivers/fblin16.c Tue Aug 22 00:30:47 2000 +++ microwin/src/drivers/fblin16.c Fri Sep 1 03:16:22 2000 @@ -80,10 +80,11 @@ if(gr_mode == MWMODE_XOR) { while(x1++ <= x2) *addr++ ^= c; - } else + } else { //FIXME: memsetw(dst, c, x2-x1+1)? while(x1++ <= x2) *addr++ = c; + } DRAWOFF; } diff -urN microwin.cvs/src/engine/devimage.c microwin/src/engine/devimage.c --- microwin.cvs/src/engine/devimage.c Tue Aug 22 00:30:50 2000 +++ microwin/src/engine/devimage.c Fri Sep 1 02:18:45 2000 @@ -14,6 +14,7 @@ #include <unistd.h> #include <fcntl.h> #include "device.h" +#include "mwendian.h" /* cached image list*/ typedef struct { @@ -671,16 +672,17 @@ bmpf.bfType[0] = headbuffer[0]; bmpf.bfType[1] = headbuffer[1]; - bmpf.bfSize = *(DWORD*)&headbuffer[2]; - bmpf.bfOffBits = *(DWORD*)&headbuffer[10]; + bmpf.bfSize = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[2]); + bmpf.bfOffBits = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[10]); /* Is it really a bmp file ? */ - if (*(WORD*)&bmpf.bfType[0] != 0x4D42) /* 'BM' */ + if (!((bmpf.bfType[0] == 'B') && (bmpf.bfType[1] == 'M'))) return 0; /* not bmp image*/ /* Read remaining header size */ if (fread(&headsize, 1, sizeof(DWORD), fp) != sizeof(DWORD)) return 0; /* not bmp image*/ + headsize = LE_TO_NATIVE_32(headsize); /* might be windows or os/2 header */ if(headsize == COREHEADSIZE) { @@ -691,10 +693,10 @@ return 0; /* not bmp image*/ /* Get data */ - bmpc.bcWidth = *(WORD*)&headbuffer[0]; - bmpc.bcHeight = *(WORD*)&headbuffer[2]; - bmpc.bcPlanes = *(WORD*)&headbuffer[4]; - bmpc.bcBitCount = *(WORD*)&headbuffer[6]; + bmpc.bcWidth = LE_TO_NATIVE_16(*(WORD*)&headbuffer[0]); + bmpc.bcHeight = LE_TO_NATIVE_16(*(WORD*)&headbuffer[2]); + bmpc.bcPlanes = LE_TO_NATIVE_16(*(WORD*)&headbuffer[4]); + bmpc.bcBitCount = LE_TO_NATIVE_16(*(WORD*)&headbuffer[6]); pimage->width = (int)bmpc.bcWidth; pimage->height = (int)bmpc.bcHeight; @@ -710,16 +712,16 @@ return 0; /* not bmp image*/ /* Get data */ - bmpi.BiWidth = *(DWORD*)&headbuffer[0]; - bmpi.BiHeight = *(DWORD*)&headbuffer[4]; - bmpi.BiPlanes = *(WORD*)&headbuffer[8]; - bmpi.BiBitCount = *(WORD*)&headbuffer[10]; - bmpi.BiCompression = *(DWORD*)&headbuffer[12]; - bmpi.BiSizeImage = *(DWORD*)&headbuffer[16]; - bmpi.BiXpelsPerMeter = *(DWORD*)&headbuffer[20]; - bmpi.BiYpelsPerMeter = *(DWORD*)&headbuffer[24]; - bmpi.BiClrUsed = *(DWORD*)&headbuffer[28]; - bmpi.BiClrImportant = *(DWORD*)&headbuffer[32]; + bmpi.BiWidth = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[0]); + bmpi.BiHeight = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[4]); + bmpi.BiPlanes = LE_TO_NATIVE_16(*(WORD*)&headbuffer[8]); + bmpi.BiBitCount = LE_TO_NATIVE_16(*(WORD*)&headbuffer[10]); + bmpi.BiCompression = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[12]); + bmpi.BiSizeImage = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[16]); + bmpi.BiXpelsPerMeter = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[20]); + bmpi.BiYpelsPerMeter = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[24]); + bmpi.BiClrUsed = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[28]); + bmpi.BiClrImportant = LE_TO_NATIVE_32(*(DWORD*)&headbuffer[32]); pimage->width = (int)bmpi.BiWidth; pimage->height = (int)bmpi.BiHeight; diff -urN microwin.cvs/src/include/mwendian.h microwin/src/include/mwendian.h --- microwin.cvs/src/include/mwendian.h Wed Dec 31 19:00:00 1969 +++ microwin/src/include/mwendian.h Fri Sep 1 02:19:10 2000 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2000 Jamie Guinan ####@####.#### + * + * Endian macros. + */ + +#ifndef _MWENDIAN_H_ +#define _MWENDIAN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define SWAP16(x) ( (((x) << 8) & 0xFF00) | ( ((x) >> 8) & 0xFF)) +#define SWAP32(x) ( (((x) << 24) & 0xFF000000) | (((x) << 8) & 0x00FF0000)\ + | (((x) >> 8) & 0x0000FF00) | (((x) >> 24) & 0x000000FF)) + +#ifndef MWENDIAN +#define MWENDIAN MWBIGENDIAN +#endif + +#if (MWENDIAN == MWBIGENDIAN) +#define LE_TO_NATIVE_16(x) SWAP16(x) +#define LE_TO_NATIVE_32(x) SWAP32(x) +#define BE_TO_NATIVE_16(x) (x) +#define BE_TO_NATIVE_32(x) (x) +#else /* MWLITTLEENDIAN */ +#define LE_TO_NATIVE_16(x) (x) +#define LE_TO_NATIVE_32(x) (x) +#define BE_TO_NATIVE_16(x) SWAP16(x) +#define BE_TO_NATIVE_32(x) SWAP32(x) + +#endif + +#ifdef __cplusplus +} +#endif + +#endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[<<] [<] Page 1 of 1 [>] [>>] |