From: Andrew R. <ar...@us...> - 2007-01-18 10:34:25
|
Update of /cvsroot/plplot/plplot/drivers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16850/drivers Modified Files: gd.c wingcc.c Log Message: Added improved anti-aliasing routines to freetype. To support this I added to new private callbacks to the freetype driver which are "plD_read_pixel_fp" and "plD_set_pixel_fp". What they do (respectively) is read and write pixels from a device directly, bypassing plplot's internal colour maps. They only work with truecolour devices. The net affect of this are two-fold: there are no palette limitations imposed by plplot for smoothing anymore, which means text is a little smoother, and the warnings with x02c have disappeared; and, because it now directly anti-aliases with the driver's background, the "background silhouette" around text has now gone. Currently only wingcc and gd have the enhancements. Any other drivers which use freetype still using the old callbacks will remain unaffected by these changes. Also added support for varying the compression level of the PNGs. Use the command line compression option (e.g. "-compression 9") to set the compression. Index: gd.c =================================================================== RCS file: /cvsroot/plplot/plplot/drivers/gd.c,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- gd.c 3 Nov 2006 13:22:34 -0000 1.44 +++ gd.c 18 Jan 2007 10:34:20 -0000 1.45 @@ -27,8 +27,8 @@ * Following the expiration of Unisys's worldwide patents on lzw compression * GD 2.0.28+ have reinstated support for GIFs, and so support for this * format has been added to the GD family of drivers. GIF's only support - * 1, 4 and 8 bit, so no truecolour. Why would you want GIFs though ? PNG is - * a far superior format, not only giving you 1,4,8 and 24 bit, but also + * 1, 4 and 8 bit, so no truecolour. Why would you want GIFs though ? PNG is + * a far superior format, not only giving you 1,4,8 and 24 bit, but also * better compression and just about all browsers now support them. */ @@ -178,6 +178,8 @@ #ifdef HAVE_FREETYPE static void plD_pixel_gd (PLStream *pls, short x, short y); +static PLINT plD_read_pixel_gd (PLStream *pls, short x, short y); +static void plD_set_pixel_gd (PLStream *pls, short x, short y, PLINT colour); static void init_freetype_lv1 (PLStream *pls); static void init_freetype_lv2 (PLStream *pls); @@ -242,8 +244,10 @@ int black15; /* Flag used for forcing a black colour */ int red15; /* Flag for swapping red and 15 */ + unsigned char TRY_BLENDED_ANTIALIASING; /* Flag to try and set up BLENDED ANTIALIASING */ + #if GD2_VERS >= 2 - int truecolour; /* Flag to ALWAYS force 24 bit mode */ + int truecolour; /* Flag to ALWAYS force 24 bit mode */ int palette; /* Flag to ALWAYS force 8 bit mode */ #endif @@ -420,9 +424,21 @@ pls->dev_text = 1; /* want to draw text */ pls->dev_unicode = 1; /* want unicode */ + /* As long as we aren't optimising, we'll try to use better antialaising + * We can also only do this if the user wants smoothing, and hasn't + * selected a palette mode. + */ + + init_freetype_lv1(pls); FT=(FT_Data *)pls->FT; FT->want_smooth_text=smooth_text; + if ((dev->optimise==0)&&(dev->palette==0)&&(smooth_text!=0)) + { + FT->BLENDED_ANTIALIASING=1; + dev->truecolour=1; + } + } #endif @@ -577,6 +593,7 @@ init_freetype_lv1(pls); FT=(FT_Data *)pls->FT; + FT->want_smooth_text=smooth_text; } @@ -1237,12 +1254,16 @@ #endif } - + /* image is written to output file by the driver since if the gd.dll is linked to a different c lib a crash occurs - this fix works also in Linux */ /* gdImagePng(dev->im_out, pls->OutFile); */ - im_ptr = gdImagePngPtr(dev->im_out, &im_size); + #if GD2_VERS >= 2 + im_ptr = gdImagePngPtrEx (dev->im_out, &im_size, pls->dev_compression >9 ? (pls->dev_compression/10) : pls->dev_compression); + #else + im_ptr = gdImagePngPtr(dev->im_out, &im_size); + #endif if( im_ptr ) { fwrite(im_ptr, sizeof(char), im_size, pls->OutFile); gdFree(im_ptr); @@ -1273,6 +1294,52 @@ } /*----------------------------------------------------------------------*\ + * void plD_set_pixel_gd (PLStream *pls, short x, short y) + * + * callback function, of type "plD_pixel_fp", which specifies how a single + * pixel is set directly to hardware, using the colour provided +\*----------------------------------------------------------------------*/ + +void plD_set_pixel_gd (PLStream *pls, short x, short y, PLINT colour) +{ +png_Dev *dev=(png_Dev *)pls->dev; +int R,G,B; +int Colour; + + G=GetGValue(colour); + R=GetRValue(colour); + B=GetBValue(colour); + + Colour=gdImageColorResolve(dev->im_out,R,G,B); + gdImageSetPixel(dev->im_out, x, y,Colour); +} + +/*----------------------------------------------------------------------*\ + * PLINT plD_read_pixel_gd (PLStream *pls, short x, short y) + * + * callback function, of type "plD_read_pixel_gd", which specifies how a + * single pixel's RGB is read (in the destination context), then + * returns an RGB encoded int with the info for blending. +\*----------------------------------------------------------------------*/ + +PLINT plD_read_pixel_gd (PLStream *pls, short x, short y) +{ +png_Dev *dev=(png_Dev *)pls->dev; +PLINT colour; +unsigned char R,G,B; + + colour=gdImageGetTrueColorPixel(dev->im_out, x, y); + + R=gdTrueColorGetRed(colour); + G=gdTrueColorGetGreen(colour); + B=gdTrueColorGetBlue(colour); + + colour=RGB(R,G,B); + return(colour); +} + + +/*----------------------------------------------------------------------*\ * void init_freetype_lv1 (PLStream *pls) * * "level 1" initialisation of the freetype library. @@ -1289,8 +1356,8 @@ FT=(FT_Data *)pls->FT; FT->pixel= (plD_pixel_fp)plD_pixel_gd; - - +FT->read_pixel= (plD_read_pixel_fp)plD_read_pixel_gd; +FT->set_pixel= (plD_set_pixel_fp)plD_set_pixel_gd; } /*----------------------------------------------------------------------*\ @@ -1328,7 +1395,7 @@ FT->invert_y=1; FT->smooth_text=0; -if (FT->want_smooth_text==1) /* do we want to at least *try* for smoothing ? */ +if ((FT->want_smooth_text==1)&&(FT->BLENDED_ANTIALIASING==0)) /* do we want to at least *try* for smoothing ? */ { FT->ncol0_org=pls->ncol0; /* save a copy of the original size of ncol0 */ FT->ncol0_xtra=NCOLOURS-(pls->ncol1+pls->ncol0); /* work out how many free slots we have */ @@ -1355,6 +1422,11 @@ else plwarn("Insufficient colour slots available in CMAP0 to do text smoothing."); } +else if ((FT->want_smooth_text==1)&&(FT->BLENDED_ANTIALIASING==1)) /* If we have a truecolour device, we wont even bother trying to change the palette */ + { + FT->smooth_text=1; + } + } #endif Index: wingcc.c =================================================================== RCS file: /cvsroot/plplot/plplot/drivers/wingcc.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- wingcc.c 27 Oct 2006 18:21:50 -0000 1.22 +++ wingcc.c 18 Jan 2007 10:34:20 -0000 1.23 @@ -127,6 +127,9 @@ static void plD_pixel_wingcc (PLStream *pls, short x, short y); static void plD_pixelV_wingcc (PLStream *pls, short x, short y); +static PLINT plD_read_pixel_wingcc (PLStream *pls, short x, short y); +static void plD_set_pixel_wingcc (PLStream *pls, short x, short y, PLINT colour); +static void plD_set_pixelV_wingcc (PLStream *pls, short x, short y,PLINT colour); static void init_freetype_lv1 (PLStream *pls); static void init_freetype_lv2 (PLStream *pls); @@ -564,7 +567,6 @@ AppendMenu(dev->PopupMenu, MF_STRING, PopupNextPage, "Next Page "); AppendMenu(dev->PopupMenu, MF_STRING, PopupQuit, "Quit"); - #ifdef HAVE_FREETYPE if (freetype) @@ -1098,20 +1100,54 @@ * pixel is set in the current colour. \*----------------------------------------------------------------------*/ -void plD_pixel_wingcc (PLStream *pls, short x, short y) +static void plD_pixel_wingcc (PLStream *pls, short x, short y) { wingcc_Dev *dev=(wingcc_Dev *)pls->dev; SetPixel(dev->hdc, x, y,dev->colour); - } -void plD_pixelV_wingcc (PLStream *pls, short x, short y) +static void plD_pixelV_wingcc (PLStream *pls, short x, short y) { wingcc_Dev *dev=(wingcc_Dev *)pls->dev; SetPixelV(dev->hdc, x, y,dev->colour); +} + +/*----------------------------------------------------------------------*\ + * void plD_set_pixelV_wingcc (PLStream *pls, short x, short y,PLINT colour) + * + * callback function, of type "plD_set_pixel_fp", which specifies how a + * single pixel is set in the s[ecified colour. This colour + * by-passes plplot's internal table, and directly 'hits the hardware'. +\*----------------------------------------------------------------------*/ + +static void plD_set_pixel_wingcc (PLStream *pls, short x, short y, PLINT colour) +{ + wingcc_Dev *dev=(wingcc_Dev *)pls->dev; + + SetPixel(dev->hdc, x, y,colour); +} + +static void plD_set_pixelV_wingcc (PLStream *pls, short x, short y, PLINT colour) +{ + wingcc_Dev *dev=(wingcc_Dev *)pls->dev; + + SetPixelV(dev->hdc, x, y,colour); +} + + +/*--------------------------------------------------------------------------*\ + * void plD_read_pixel_wingcc (PLStream *pls, short x, short y) + * + * callback function, of type "plD_pixel_fp", which specifies how a single + * pixel is read. +\*--------------------------------------------------------------------------*/ +static PLINT plD_read_pixel_wingcc (PLStream *pls, short x, short y) +{ + wingcc_Dev *dev=(wingcc_Dev *)pls->dev; + return(GetPixel(dev->hdc, x, y)); } @@ -1135,6 +1171,7 @@ FT=(FT_Data *)pls->FT; + /* * Work out if our device support "fast" pixel setting * and if so, use that instead of "slow" pixel setting @@ -1147,6 +1184,21 @@ else FT->pixel= (plD_pixel_fp)plD_pixel_wingcc; +/* + * See if we have a 24 bit device (or better), in which case + * we can use the better antialaaising. + */ + +if (GetDeviceCaps(dev->hdc,BITSPIXEL)>24) +{ + FT->BLENDED_ANTIALIASING=1; + FT->read_pixel= (plD_read_pixel_fp)plD_read_pixel_wingcc; + + if (x & RC_BITBLT) + FT->set_pixel= (plD_set_pixel_fp)plD_set_pixelV_wingcc; + else + FT->set_pixel= (plD_set_pixel_fp)plD_set_pixel_wingcc; +} } @@ -1155,7 +1207,7 @@ * * "Level 2" initialisation of the freetype library. * "Level 2" fills in a few setting that aren't public until after the - * graphics sub-syetm has been initialised. + * graphics sub-system has been initialised. * The "level 2" initialisation fills in a few things that are defined * later in the initialisation process for the GD driver. * @@ -1184,7 +1236,7 @@ FT->ymax=dev->height; FT->invert_y=1; -if (FT->want_smooth_text==1) /* do we want to at least *try* for smoothing ? */ +if ((FT->want_smooth_text==1)&&(FT->BLENDED_ANTIALIASING==0)) /* do we want to at least *try* for smoothing ? */ { FT->ncol0_org=pls->ncol0; /* save a copy of the original size of ncol0 */ FT->ncol0_xtra=16777216-(pls->ncol1+pls->ncol0); /* work out how many free slots we have */ @@ -1204,7 +1256,11 @@ pls->level = level_save; } FT->smooth_text=1; /* Yippee ! We had success setting up the extended cmap0 */ - } + } +else if ((FT->want_smooth_text==1)&&(FT->BLENDED_ANTIALIASING==1)) /* If we have a truecolour device, we wont even bother trying to change the palette */ + { + FT->smooth_text=1; + } } #endif |