diff options
Diffstat (limited to 'app/wlib/gtklib/gtkxpm.c')
-rw-r--r-- | app/wlib/gtklib/gtkxpm.c | 90 |
1 files changed, 43 insertions, 47 deletions
diff --git a/app/wlib/gtklib/gtkxpm.c b/app/wlib/gtklib/gtkxpm.c index 022c973..54ce5a6 100644 --- a/app/wlib/gtklib/gtkxpm.c +++ b/app/wlib/gtklib/gtkxpm.c @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + #include <stdio.h> #include <stdlib.h> #ifdef HAVE_MALLOC_H @@ -34,7 +34,7 @@ struct xpmColTable { int color; /* color value (rgb) */ - char name[ 5 ]; /* corresponding character representation */ + char name[ 5 ]; /* corresponding character representation */ UT_hash_handle hh; /* makes this structure hashable */ }; @@ -42,34 +42,30 @@ static struct xpmColTable *colTable = NULL; // must be 64 chars long static char colVal[] = ".*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - - -struct wDraw_t { - WOBJ_COMMON - void * context; - wDrawActionCallBack_p action; - wDrawRedrawCallBack_p redraw; - - GdkPixmap * pixmap; - GdkPixmap * pixmapBackup; - - double dpi; - - GdkGC * gc; - wDrawWidth lineWidth; - wDrawOpts opts; - wPos_t maxW; - wPos_t maxH; - unsigned long lastColor; - wBool_t lastColorInverted; - const char * helpStr; - - wPos_t lastX; - wPos_t lastY; - - wBool_t delayUpdate; - }; - + +//struct wDraw_t { + //WOBJ_COMMON + //void * context; + //wDrawActionCallBack_p action; + //wDrawRedrawCallBack_p redraw; + + //double dpi; + + //GdkGC * gc; + //wDrawWidth lineWidth; + //wDrawOpts opts; + //wPos_t maxW; + //wPos_t maxH; + //unsigned long lastColor; + //wBool_t lastColorInverted; + //const char * helpStr; + + //wPos_t lastX; + //wPos_t lastY; + + //wBool_t delayUpdate; + //}; + /** * Export as XPM bitmap file. During creation of the color table, a 4 byte color * encoding is assumed and a table created accordingly. Once the whole picture has been scanned @@ -78,7 +74,7 @@ struct wDraw_t { * This routine was heavily inspired by on implementation for TK written by Jan Nijtmans. * * \param d IN the drawing area ? - * \param fileName IN fully qualified filename for the bitmap file. + * \param fileName IN fully qualified filename for the bitmap file. * \return TRUE on success, FALSE on error */ @@ -88,7 +84,7 @@ wBool_t wBitMapWriteFile( wDraw_p d, const char * fileName ) gint x, y; guint32 pixel; FILE * f; - int cc = 0; + int cc = 0; struct xpmColTable *ct, *tmp; int numChars; @@ -106,11 +102,11 @@ wBool_t wBitMapWriteFile( wDraw_p d, const char * fileName ) fprintf( f, "/* XPM */\n" ); fprintf( f, "static char * xtrkcad_bitmap[] = {\n" ); fprintf( f, "/* width height num_colors chars_per_pixel */\n" ); - + // count colors used and create the color table in the same pass for( y = 0; y < d->h;y ++ ) { for (x = 0; x < d->w; x++ ) { - + pixel = gdk_image_get_pixel( image, x, y ); //check whether color is new @@ -119,18 +115,18 @@ wBool_t wBitMapWriteFile( wDraw_p d, const char * fileName ) // not found previously, so add a new color table entry int i; int c; - + ct = malloc( sizeof( struct xpmColTable ) ); ct->name[ 4 ] = '\0'; for( i = 3, c = cc; i >= 0; i--, c>>=6 ) { (ct->name)[ i ] = colVal[ c & 0x3F ]; - } + } ct->color = pixel; - + HASH_ADD(hh, colTable, color, sizeof( guint32 ), ct); cc++; - } - } + } + } } // calculate how many characters are needed for the color table @@ -143,15 +139,15 @@ wBool_t wBitMapWriteFile( wDraw_p d, const char * fileName ) } else { if( cc > 0x3f ) { numChars = 2; - } + } } - } - // print color table + } + // print color table fprintf( f, "\"%d %d %d %d\"\n", d->w, d->h, cc, numChars ); fprintf( f, "/* colors */\n" ); for( ct = colTable; ct != NULL; ct = ct->hh.next ) fprintf( f, "\"%s c #%6.6x\",\n", (ct->name) + (4 - numChars ), ct->color ); - + // print the pixels fprintf( f, "/* pixels */\n" ); for ( y=0; y<d->h; y++ ) { @@ -159,17 +155,17 @@ wBool_t wBitMapWriteFile( wDraw_p d, const char * fileName ) for ( x=0; x<d->w; x++ ) { pixel = gdk_image_get_pixel( image, x, y ); HASH_FIND( hh, colTable, &pixel, sizeof(guint32), ct ); - fputs( (ct->name) + (4 - numChars ), f ); + fputs( (ct->name) + (4 - numChars ), f ); } fprintf( f, "\"%s\n", (y<d->h-1)?",":"" ); } // delete the hash and free the content HASH_ITER(hh, colTable, ct, tmp) { - HASH_DEL(colTable,ct); - free(ct); + HASH_DEL(colTable,ct); + free(ct); } - + gdk_image_destroy( image ); fprintf( f, "};\n" ); fclose( f ); |