static void gc_destroy(struct graphics_gc_priv *gc) { if (gc->color != -1) gdImageColorDeallocate(gc->gr->im, gc->color); if (gc->bgcolor != -1) gdImageColorDeallocate(gc->gr->im, gc->bgcolor); g_free(gc->dash_list); g_free(gc); }
result_t Image::colorDeallocate(int32_t colorIndex) { if (!m_image) return CHECK_ERROR(CALL_E_INVALID_CALL); gdImageColorDeallocate(m_image, colorIndex); return 0; }
static int allocate_color(GIFmetafile *meta, int idx, float r, float g, float b){ GIFcolor *color = 0; int index; int ir = r * 255, ig = g * 255, ib = b * 255; assert(idx < meta->numcolors); color = &meta->colors[idx]; if (color->index != -1) gdImageColorDeallocate(meta->image, color->index); color->index = gdImageColorAllocate(meta->image, ir, ig, ib); color->r = r; color->g = g; color->b = b; /* test transparency...*/ /* if (color->index == 22) gdImageColorTransparent (meta->image, color->index); */ return color->index; }
void plD_gd_optimise(PLStream *pls) { png_Dev *dev=(png_Dev *)pls->dev; int i,j; char *bbuf; bbuf=calloc(256,(size_t) 1); /* Allocate a buffer to "check off" colours as they are used */ if (bbuf==NULL) plexit("plD_gd_optimise: Out of memory."); for(i=0;i<(pls->xlength-1);i++) /* Walk through the image pixel by pixel */ { /* checking to see what colour it is */ for(j=0;j<(pls->ylength-1);j++) /* and adding it to the list of used colours */ { bbuf[gdImagePalettePixel(dev->im_out, i, j)]=1; } } for (i=0;i<256;i++) /* next walk over the colours and deallocate */ { /* unused ones */ if (bbuf[i]==0) gdImageColorDeallocate(dev->im_out,i); } free(bbuf); }
int main() { gdImagePtr im; FILE *pngout, *pArchivo; short int dato; int nx,ny,posicion; int resx,resy; int black, white, red, green, blue; float lonPL, latPL; float gris, color; int colorrgb; resx=10800; resy=6000; im = gdImageCreate(resx, resy); black = gdImageColorAllocate(im, 0, 0, 0); white = gdImageColorAllocate(im,255,255,255); red = gdImageColorAllocate(im,255, 0, 0); green = gdImageColorAllocate(im, 0,255, 0); blue = gdImageColorAllocate(im, 0, 0,255); // gdImageLine(im,0,0,resx,resy,white); // gdImageLine(im,resx,0,0,resy,red); // gdImageSetPixel(im, resx/3,resy/2, red); pArchivo=fopen("/home/marcos/WRF_PRD/globe_data/all10/f10g","r"); if (pArchivo == NULL) { printf("*** ERROR: No se ha podido abrir el fichero solicitado.\n"); return; } for (nx = 0; nx < resx ; nx++) { for (ny = 0; ny < resy ; ny++) { posicion= 21600 * ny + 2 * nx ; fseek(pArchivo, posicion, SEEK_SET); fread(&dato, sizeof(short int), 1, pArchivo); // printf("%i, %i, %i\n", i,j,dato ); if (dato < -499) { gdImageSetPixel(im, nx, ny, blue); } else if (dato > -499 & dato < 0) { gdImageSetPixel(im, nx,ny, red); } else { gris=(float)dato/6085.0; // 6085 metros es la altitud máxima de esta losa. color=255.0*gris; colorrgb=gdImageColorAllocate(im,(int)color,(int)color,(int)color); // printf("gris=%f, color=%i, colorrgb=%i\n",gris,(int)color,colorrgb ); gdImageSetPixel(im, nx, ny, colorrgb); gdImageColorDeallocate(im, colorrgb); } } } // Píxel en rojo en Puerto Lumbreras. latPL=37.5663; lonPL=-1.8083; latPL=6000.0-(latPL*120.0); lonPL=10800.0+(lonPL*120.0); printf("%f\n",lonPL ); printf("latPL=%i px, lonPL=%i px\n",(int)latPL,(int)lonPL ); gdImageSetPixel(im, (int)lonPL,(int)latPL, red); pngout=fopen("test.png","wb"); gdImagePng(im, pngout); fclose(pngout); gdImageDestroy(im); fclose(pArchivo); }
static void setcmap(PLStream *pls) { int i, ncol1=pls->ncol1; int ncol0=pls->ncol0, total_colours; PLColor cmap1col; png_Dev *dev=(png_Dev *)pls->dev; PLFLT tmp_colour_pos; /* * Yuckky fix to get rid of the previosuly allocated palette from the * GD image */ if (dev->im_out != NULL) { for (i=0;i<256;i++) { gdImageColorDeallocate(dev->im_out,i); } } if (ncol0>NCOLOURS/2) /* Check for ridiculous number of colours */ { /* in ncol0, and appropriately adjust the */ plwarn("Too many colours in cmap0."); /* number, issuing a */ ncol0=NCOLOURS/2; /* warning if it does */ pls->ncol0=ncol0; } dev->totcol=0; /* Reset the number of colours counter to zero */ total_colours=ncol0+ncol1; /* Work out how many colours are wanted */ if (total_colours>NCOLOURS) /* Do some rather modest error */ { /* checking to make sure that */ total_colours=NCOLOURS; /* we are not defining more colours */ ncol1=total_colours-ncol0; /* than we have room for. */ if (ncol1<=0) { plexit("Problem setting colourmap in PNG or JPEG driver."); } } dev->ncol1=ncol1; /* The actual size of ncol1, regardless of what was asked. * This is dependent on colour slots available. * It might well be the same as ncol1. */ /* Initialize cmap 0 colors */ if ((ncol0>0)&&(dev->im_out != NULL)) /* make sure the program actually asked for cmap0 first */ { for (i = 0; i < ncol0; i++) { gdImageColorAllocate(dev->im_out, pls->cmap0[i].r, pls->cmap0[i].g, pls->cmap0[i].b); ++dev->totcol; /* count the number of colours we use as we use them */ } } /* Initialize any remaining slots for cmap1 */ if ((ncol1>0)&&(dev->im_out != NULL)) /* make sure that we want to define cmap1 first */ { for (i = 0; i < ncol1; i++) { if (ncol1<pls->ncol1) /* Check the dynamic range of colours */ { /* * Ok, now if we have less colour slots available than are being * defined by pls->ncol1, then we still want to use the full * dynamic range of cmap1 as best we can, so what we do is work * out an approximation to the index in the full dynamic range * in cases when pls->ncol1 exceeds the number of free colours. */ tmp_colour_pos= i>0 ? pls->ncol1*((PLFLT)i/ncol1) : 0; plcol_interp(pls, &cmap1col, (int) tmp_colour_pos, pls->ncol1); } else { plcol_interp(pls, &cmap1col, i, ncol1); } gdImageColorAllocate(dev->im_out, cmap1col.r, cmap1col.g, cmap1col.b); ++dev->totcol; /* count the number of colours we use as we go */ } } }