comparison os2/dw.c @ 1836:692c3a18a112

Imported code to convert to 24bpp from GBM on OS/2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 08 Nov 2012 20:10:54 +0000
parents 0123e8aec5b4
children d7e13f446c41
comparison
equal deleted inserted replaced
1835:0123e8aec5b4 1836:692c3a18a112
7061 { 7061 {
7062 HPOINTER hptr = icon < 65536 ? WinLoadPointer(HWND_DESKTOP,NULLHANDLE,icon) : (HPOINTER)icon; 7062 HPOINTER hptr = icon < 65536 ? WinLoadPointer(HWND_DESKTOP,NULLHANDLE,icon) : (HPOINTER)icon;
7063 WinSendMsg(handle, WM_SETICON, (MPARAM)hptr, 0); 7063 WinSendMsg(handle, WM_SETICON, (MPARAM)hptr, 0);
7064 } 7064 }
7065 7065
7066 /* Code from GBM to convert to 24bpp if it isn't currently */
7067 static int _To24Bit(GBM *gbm, GBMRGB *gbmrgb, BYTE **ppbData)
7068 {
7069 unsigned long stride = (((unsigned long)gbm -> w * gbm -> bpp + 31)/32) * 4;
7070 unsigned long new_stride = (((unsigned long)gbm -> w * 3 + 3) & ~3);
7071 unsigned long bytes;
7072 int y;
7073 unsigned char *pbDataNew;
7074
7075 if ( gbm -> bpp == 24 )
7076 {
7077 return ( TRUE );
7078 }
7079
7080 bytes = new_stride * gbm -> h;
7081 /* Allocate a buffer to store the image */
7082 if(DosAllocMem((PPVOID)&pbDataNew, (ULONG)bytes, PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
7083 {
7084 return ( FALSE );
7085 }
7086
7087 for ( y = 0; y < gbm -> h; y++ )
7088 {
7089 unsigned char *src = *ppbData + y * stride;
7090 unsigned char *dest = pbDataNew + y * new_stride;
7091 int x;
7092
7093 switch ( gbm -> bpp )
7094 {
7095 case 1:
7096 {
7097 unsigned char c = 0;
7098 for ( x = 0; x < gbm -> w; x++ )
7099 {
7100 if ( (x & 7) == 0 )
7101 c = *src++;
7102 else
7103 c <<= 1;
7104
7105 *dest++ = gbmrgb [(c & 0x80) != 0].b;
7106 *dest++ = gbmrgb [(c & 0x80) != 0].g;
7107 *dest++ = gbmrgb [(c & 0x80) != 0].r;
7108 }
7109 }
7110 break;
7111
7112 case 4:
7113 for ( x = 0; x + 1 < gbm -> w; x += 2 )
7114 {
7115 unsigned char c = *src++;
7116
7117 *dest++ = gbmrgb [c >> 4].b;
7118 *dest++ = gbmrgb [c >> 4].g;
7119 *dest++ = gbmrgb [c >> 4].r;
7120 *dest++ = gbmrgb [c & 15].b;
7121 *dest++ = gbmrgb [c & 15].g;
7122 *dest++ = gbmrgb [c & 15].r;
7123 }
7124
7125 if ( x < gbm -> w )
7126 {
7127 unsigned char c = *src;
7128
7129 *dest++ = gbmrgb [c >> 4].b;
7130 *dest++ = gbmrgb [c >> 4].g;
7131 *dest++ = gbmrgb [c >> 4].r;
7132 }
7133 break;
7134
7135 case 8:
7136 for ( x = 0; x < gbm -> w; x++ )
7137 {
7138 unsigned char c = *src++;
7139
7140 *dest++ = gbmrgb [c].b;
7141 *dest++ = gbmrgb [c].g;
7142 *dest++ = gbmrgb [c].r;
7143 }
7144 break;
7145 }
7146 }
7147 DosFreeMem(*ppbData);
7148 *ppbData = pbDataNew;
7149 gbm->bpp = 24;
7150
7151 return ( TRUE );
7152 }
7153
7066 /* GBM seems to be compiled with VisualAge which defines O_BINARY and O_RDONLY 7154 /* GBM seems to be compiled with VisualAge which defines O_BINARY and O_RDONLY
7067 * as follows... but other compilers (GCC and Watcom at least) define them 7155 * as follows... but other compilers (GCC and Watcom at least) define them
7068 * differently... so we add defines that are compatible with VAC here. 7156 * differently... so we add defines that are compatible with VAC here.
7069 */ 7157 */
7070 #define GBM_O_BINARY 0x00008000 7158 #define GBM_O_BINARY 0x00008000
7086 /* If we have GBM support open the file using GBM */ 7174 /* If we have GBM support open the file using GBM */
7087 if(_gbm_init) 7175 if(_gbm_init)
7088 { 7176 {
7089 int fd, z, err = -1, ft = 0; 7177 int fd, z, err = -1, ft = 0;
7090 GBM gbm; 7178 GBM gbm;
7091 GBMRGB *gbmrgb; 7179 GBMRGB *gbmrgb = NULL;
7092 ULONG byteswidth; 7180 ULONG byteswidth;
7093 7181
7094 /* Try to open the file */ 7182 /* Try to open the file */
7095 if((fd = _gbm_io_open(file, GBM_O_RDONLY|GBM_O_BINARY)) == -1) 7183 if((fd = _gbm_io_open(file, GBM_O_RDONLY|GBM_O_BINARY)) == -1)
7096 { 7184 {
7151 #endif 7239 #endif
7152 _gbm_io_close(fd); 7240 _gbm_io_close(fd);
7153 return 0; 7241 return 0;
7154 } 7242 }
7155 } 7243 }
7156 else
7157 gbmrgb = NULL;
7158 7244
7159 /* Save the dimension for return */ 7245 /* Save the dimension for return */
7160 *width = gbm.w; 7246 *width = gbm.w;
7161 *height = gbm.h; 7247 *height = gbm.h;
7162 *depth = gbm.bpp; 7248 *depth = gbm.bpp;
7177 return 0; 7263 return 0;
7178 } 7264 }
7179 7265
7180 /* Close the file */ 7266 /* Close the file */
7181 _gbm_io_close(fd); 7267 _gbm_io_close(fd);
7268
7269 /* Convert to 24bpp for use in the application */
7270 if(_To24Bit(&gbm, gbmrgb, &BitmapFileBegin))
7271 *depth = 24;
7272 else
7273 {
7274 #ifdef DEBUG
7275 dw_debug("GBM: Failed 24bpp conversion\n", z, file, err, _gbm_err(err));
7276 #endif
7277 DosFreeMem(BitmapFileBegin);
7278 return 0;
7279 }
7182 7280
7183 pBitmapInfoHeader = alloca(sizeof(BITMAPINFOHEADER2)); 7281 pBitmapInfoHeader = alloca(sizeof(BITMAPINFOHEADER2));
7184 memset(pBitmapInfoHeader, 0, sizeof(BITMAPINFOHEADER2)); 7282 memset(pBitmapInfoHeader, 0, sizeof(BITMAPINFOHEADER2));
7185 pBitmapInfoHeader->cbFix = sizeof(BITMAPINFOHEADER2); 7283 pBitmapInfoHeader->cbFix = sizeof(BITMAPINFOHEADER2);
7186 pBitmapInfoHeader->cx = (SHORT)gbm.w; 7284 pBitmapInfoHeader->cx = (SHORT)gbm.w;