GPS4Palm

Source Code Documentation


dobitmap.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * $RCSfile: dobitmap_8c-source.html,v $
00004  *
00005  * Display image stored in memory area pointed to by **lines
00006  *   using WinDrawBitmap
00007  *
00008  * created: 2002-12-15
00009  *
00010  * History:
00011  * 2007-07-11:  16 bit support for the Palm TX (fs)
00012  *              uses little endian coding (intel specific: lowByte / highByte)
00013  * 2002-12-15:  first version, taken from the program PiNGer which is
00014  *                part of the ZBoxZ application suite (Rev. 0.30)
00015  *                by Tom Zerucha
00016  *
00017  * This program is Copyright (C) 12/2002 Matthias Prinke
00018  * <matthias.prinke@surfeu.de> and covered by GNU's GPL.
00019  * In particular, this program is free software and comes WITHOUT
00020  * ANY WARRANTY.
00021  *
00022  * Changes for Palm TX are Copyright (C) 07/2007 Frank Saurbier
00023  * <frank.saurbier@surfeu.de> and covered by GNU's GPL.
00024  * In particular, this program is free software and comes WITHOUT
00025  * ANY WARRANTY.
00026  *
00027  * $Author: mp $
00028  *
00029  * $Date: 2007-10-08 20:40:32 $
00030  *
00031  * $Revision: 1.7.2.1 $
00032  *
00033  * $Log: dobitmap_8c-source.html,v $
00033  * Revision 1.7.2.1  2007-10-08 20:40:32  mp
00033  * updated for gps4palm V0.9.5 beta
00033  *
00034  * Revision 1.4.2.2  2007-10-05 22:51:06  mp
00035  * fixed doxygen comment
00036  *
00037  * Revision 1.4.2.1  2007-10-05 22:37:21  mp
00038  * added Frank's changes (fixes reset bug on TX)
00039  *
00040  * Revision 1.5  2007/07/11 16:00:00  fs
00041  * added 16bit display support, color map from extern gifread
00042  *
00043  * Revision 1.4  2005/04/08 14:46:20  mp
00044  * added High-Density Display support
00045  *
00046  * Revision 1.3  2005/03/24 09:16:04  mp
00047  * updated from SDK-4 to SDK-5r3
00048  * Note: BitmapType is now called BitmapTypeV2!!! (thanks, PalmSoft ...)
00049  *
00050  * Revision 1.2  2003/10/18 16:11:51  mp
00051  * renamed ImgInfo to gPrefs
00052  *
00053  * Revision 1.1.1.1  2003/07/14 18:59:29  mp
00054  * Imported GPS4Palm to CVS revision control.
00055  *
00056  *
00057  ****************************************************************************/
00058 //#define VERBOSE_DOBIT
00059 #define ALLOW_ACCESS_TO_INTERNALS_OF_BITMAPS
00060 #include <PalmOS.h>
00061 #include <PalmCompatibility.h>
00062 #include <Bitmap.h>
00063 #include "BitmapRsrc.h"
00064 #include "stringil.h"
00065 #include "dobitmap.h"
00066 #include "common.h"
00067 
00068 extern PrefsType gPrefs;
00069 extern char **lines;
00070 extern unsigned short int w, h, bandh;
00071 extern Boolean                  gHdFtrSet;
00072 
00073 /**********************************************************
00074  get palette for 16bit TX from gifread.c
00075  fs 07/2007
00076  need the palette to build the RGB656 pixel in 16 bit mode
00077 ***********************************************************/
00078 extern RGBColorType map[256];
00079 
00080 
00081 /**********************************************************************/
00082 /**
00083  * \brief       Display image stored in memory area pointed to by **lines
00084  *              using WinDrawBitmap
00085  *
00086  * \param       xofs            x-offset within image
00087  * \param       yofs            y-offset within image
00088  * \param       mag             magnification (1..8)
00089  * \param       dx              x-coordinate of bitmap (display coords)
00090  * \param       dy              y-coordinate of bitmap (display coords)
00091  * \param       dw              width of bitmap (display coords)
00092  * \param       dh              height of bitmap (display coords)
00093  * \param       deep            display depth
00094  *
00095  * \note        Depends on w, h, bandh globals
00096  *
00097  * \note        The function relies on the internals of the Palm OS
00098  *              bitmap structures defined in Bitmap.h. Since internals
00099  *              of Palm OS structures are subject to change,
00100  *              this may not work with future OS versions.
00101  *
00102  * \note        From SDK-4 to SDK-5r3, BitmapType changed to
00103  *              BitmapTypeV2 (same members, different name...)
00104  *
00105  ***********************************************************************/
00106 void dobitmap(  short unsigned int xofs, short unsigned int yofs,
00107                 short unsigned int mag,
00108                 short unsigned int dx, short unsigned int dy,
00109                 short unsigned int dw, short unsigned int dh,
00110                 short unsigned int deep)
00111 {
00112   BmpRsrcType   *bmprsrc = NULL;
00113 
00114   #define bp bmprsrc
00115   
00116   unsigned char *loc, *loc2;
00117   unsigned short int imask, bw, i, j, j0, k, bit;
00118 // (fs) 20070710 pointer and helper for 16bit pixel generation
00119   unsigned short int *locTX, locTmp, locCalc;
00120   unsigned char loc8;
00121   PixelFormatType locPF;
00122 
00123   gPrefs.xofs = xofs;
00124   gPrefs.yofs = yofs;
00125   gPrefs.dx = dx;
00126   gPrefs.dy = dy;
00127   gPrefs.dw = dw;
00128   gPrefs.dh = dh;
00129   gPrefs.mag = mag;
00130   gPrefs.depth = deep;
00131   
00132 #ifdef VERBOSE_DOBIT
00133 {
00134   Char          tmp[60];        /* temporary string buffer for debugging */
00135   
00136   StrPrintF(tmp, "dobitmap");
00137   WinDrawChars(tmp, StrLen(tmp), 0, 0);
00138   SysTaskDelay(50);
00139 
00140   StrPrintF(tmp, "xofs = %d", xofs);
00141   WinDrawChars(tmp, StrLen(tmp), 0, 0);
00142   SysTaskDelay(50);
00143   StrPrintF(tmp, "yofs = %d", yofs);
00144   WinDrawChars(tmp, StrLen(tmp), 0, 10);
00145   SysTaskDelay(50);
00146   StrPrintF(tmp, "mag = %d", mag);
00147   WinDrawChars(tmp, StrLen(tmp), 0, 20);
00148   SysTaskDelay(50);
00149   StrPrintF(tmp, "deep = %d", deep);
00150   WinDrawChars(tmp, StrLen(tmp), 0, 30);
00151   SysTaskDelay(50);
00152   StrPrintF(tmp, "dx = %d", dx);
00153   WinDrawChars(tmp, StrLen(tmp), 0, 40);
00154   SysTaskDelay(50);
00155   StrPrintF(tmp, "dy = %d", dy);
00156   WinDrawChars(tmp, StrLen(tmp), 0, 50);
00157   SysTaskDelay(50);
00158   StrPrintF(tmp, "dw = %d", dw);
00159   WinDrawChars(tmp, StrLen(tmp), 0, 60);
00160   SysTaskDelay(50);
00161   StrPrintF(tmp, "dh = %d", dh);
00162   WinDrawChars(tmp, StrLen(tmp), 0, 70);
00163   SysTaskDelay(50);
00164 
00165 }
00166 #endif
00167 
00168 
00169 #ifdef OLDSTUFF_PLEASE
00170 /***************
00171  * old stuff: could be deleted 20070713
00172  */
00173   if (gHdFtrSet) {
00174 
00175 /* *************************************************************************************************
00176  * Palm TX:  for 16bit set "pixelFormat565" with "BitmapTypeV3"
00177  * fs 07/2007
00178  * nothing changed from the old code, should still work
00179 */
00180     if (deep > 8)                 /* Palm TX */
00181     bmprsrc = BmpRsrcV3Create(dw, 1, 
00182                               deep, /* deep, works with 8 too, but very bad colors */
00183                               NULL, /* NULL, no colortable */
00184                               NULL, kDensityDouble,
00185                               pixelFormat565 /* 16bit:pixelFormat565, 8bit:pixelFormatIndexed */
00186                               );
00187 /* Palm TX end ***********************************************************************************/
00188 
00189 // old coding
00190     else
00191    bmprsrc = BmpRsrcCreate(
00192        dw, /* width */
00193       1, /* height */
00194       deep, /* pixelSize - 1, 2, 4, 8, 16 - (fs: on TX use 16bit) */
00195       NULL, /* * ct -  null for no color table (preferred) */
00196       kDensityDouble, /* density - only kDensityLow, kDensityDouble supported */
00197       -1 /* pixelFormat  pixelFormat565LE , default = -1*/
00198       );
00199 #ifdef VERBOSE_DOBIT
00200 {
00201   Char          tmp[60];        /* temporary string buffer for debugging */
00202   
00203   StrPrintF(tmp, "BmpCreate deep = %d", deep);
00204   WinDrawChars(tmp, StrLen(tmp), 0, 0);
00205   SysTaskDelay(50);
00206 }
00207 #endif // VERBOSE_DOBIT
00208   } 
00209   else 
00210   {
00211     /* Note: BmpRsrcV2Create() requires OS Version > 3.5 */
00212     bmprsrc = (BmpRsrcType *)MemPtrNew(sizeof(BitmapTypeV2) + 320 + 1024);
00213     bmprsrc->v2.width = dw;
00214     bmprsrc->v2.height = 1;              // dh
00215     bmprsrc->v2.pixelSize = deep;
00216     bmprsrc->v2.rowBytes = deep * 20;    // (deep * (dw+15) / 8) & ~1, i.e. word boundary
00217     bmprsrc->v2.version = 2;
00218   }
00219 
00220 #endif // OLDSTUFF_PLEASE
00221 
00222 #ifndef OLDSTUFF_PLEASE
00223 
00224 /**********************************************************************************
00225  * (fs): thats all, we have to do. The coding above is handles in "BitmapRsrc"
00226  *       this is a chunk for one line of the bitmap.
00227  **********************************************************************************/
00228    bmprsrc = BmpRsrcCreate(
00229       dw, /* width */
00230       1, /* height */
00231       deep, /* pixelSize - 1, 2, 4, 8, 16 - (fs: on TX 16bits are used) */
00232       NULL, /* * ct -  null for no color table (preferred) */
00233       kDensityDouble, /* density - only kDensityLow, kDensityDouble supported */
00234       -1 /* pixelFormat  pixelFormat565LE , default = -1, 16bit:pixelFormat565, 8bit:pixelFormatIndexed */
00235       );
00236 
00237 #endif
00238 
00239   loc = BmpRsrcGetBits(bp);
00240   /* (fs 2007) Pixelformat Type: defines the endian */
00241   locPF = BmpRsrcGetPixelFormat(bp);
00242   
00243 #ifdef VERBOSE_DOBIT
00244 {
00245   Char          tmp[60];        /* temporary string buffer for debugging */
00246   
00247   StrPrintF(tmp, "dobit GetBits ok");
00248   WinDrawChars(tmp, StrLen(tmp), 0, 0);
00249   SysTaskDelay(50);
00250 }
00251 #endif
00252     
00253   /* really should be bkgd, not 0 */// * dh
00254   memset(loc, 0, BmpRsrcGetRowBytes(bmprsrc));
00255 
00256 //  bw = 8 / deep;
00257 //  (fs) thinks bw meens black white
00258 //  for deep > 8 I set this value to 1
00259   if (deep > 8)  bw = 1;               /* for 16bit and more bw=1 */
00260   else                                 /* old coding, for all non Palm TX users*/
00261   {
00262     bw = 8 / deep;
00263     imask = 0xff << (8 - deep);
00264     imask &= 0xff;
00265   }
00266 
00267   if (dw * mag + xofs >= w)
00268     j0 = (w / mag - xofs + bw - 1) / bw;
00269   else
00270     j0 = (dw + bw - 1) / bw;
00271 
00272   /* iterate over all lines, sub-sampling if mag > 1 */
00273 //  for (i = 0; yofs < h && i < dh; i++, yofs += mag) {
00274   for (i = 0; yofs < h && i < dh; i++, yofs += 1) {
00275 
00276     /* destination BMP for drawing */
00277     loc = BmpRsrcGetBits(bp);
00278 
00279     /* fs needs this cast for Palm TX */
00280     locTX = (unsigned short int *) loc;
00281 
00282     /* source BMP from GIF/PNG/... decoding */
00283     loc2 = lines[yofs / bandh] + w * (yofs % bandh) + xofs;
00284 
00285     j = j0;
00286     switch (deep) {
00287 
00288 // (fs) deep = 16, Palm TX support
00289     case 16:
00290         while (j--) 
00291         {
00292             loc8 = *loc2;
00293 
00294             // normal display RGB 565
00295             //locTmp = (unsigned short int) (map[loc8].r & 0x1f);    /* R */
00296             locCalc = (unsigned short int) map[loc8].r;    /* R */
00297             locTmp = (locCalc + 4) * 31 / 255;
00298             locTmp = locTmp << 6;       
00299             //locTmp |= (unsigned short int) (map[loc8].g & 0x3f);   /* G */
00300             locCalc = (unsigned short int) map[loc8].g;    /* G */
00301             locTmp |= (locCalc + 2) * 63 / 255;
00302             locTmp = locTmp << 5;       
00303             //locTmp |= (unsigned short int) (map[loc8].b & 0x1f);   /* B */
00304             locCalc = (unsigned short int) map[loc8].b;    /* B */
00305             locTmp |= (locCalc + 4) * 31 / 255;
00306             /* check for little endian */
00307             //if (locPF==pixelFormatIndexedLE || locPF==pixelFormat565LE) then
00308             if (locPF==pixelFormat565LE) {
00309               /* for ARM use little endian - checked in RsrcBitmap */
00310               // *locTX++ = ((locTmp >> 8) & 0x00ff) | ((locTmp << 8) & 0xff00);
00311               // can do it without &0x00ff!
00312               *locTX++ = (locTmp >> 8) | (locTmp << 8);
00313             } else {
00314               /** this is big endian for 68K Processors */
00315               *locTX++ = locTmp;
00316             }
00317             loc2 += mag;
00318             
00319         } // while j--
00320     
00321     break; /* case deep = 16 */
00322 // end of 16bpp Palm TX support
00323 
00324     case 8:
00325       if (mag == 1)
00326         while (j--)
00327           *loc++ = *loc2++;
00328       else
00329         while (j--) {
00330           *loc++ = *loc2;
00331           loc2 += mag;
00332         }
00333       break;
00334 
00335     case 4:
00336       if (mag == 1)
00337         while (j--) {
00338           k = 0xf0 & *loc2++;
00339           k |= *loc2++ >> 4;
00340           *loc++ = ~k;
00341       } else
00342         while (j--) {
00343           k = 0xf0 & *loc2;
00344           loc2 += mag;
00345           k |= *loc2 >> 4;
00346           loc2 += mag;
00347           *loc++ = ~k;
00348         }
00349       break;
00350 
00351     default:                   /* 2 or 1 */
00352       while (j--) {
00353         *loc = 0;
00354         bit = 0;
00355         do {
00356           k = ~*loc2 & imask;
00357           loc2 += mag;
00358           k >>= deep * bit;
00359           *loc |= k;
00360         } while (++bit < bw);
00361         loc++;
00362       }
00363       break;
00364     }
00365 
00366     /* draw one line of the bitmap */
00367     WinDrawBitmap((void *)bp, dx, dy + i);
00368 
00369   }
00370   if (i < dh) {
00371     /* clear lines below image */
00372     RectangleType r = { {0, i}, {dh, dh - i}};
00373     WinEraseRectangle(&r, 0);   /* SHOULD BE BKGD! */
00374   }
00375 
00376   BmpRsrcDelete(bmprsrc);
00377 
00378 }

Created: Mon, 08 Oct 2007 22:33:16 +0200
Copyright ©2004 M. Prinke