int main ( int argc, char* argv[] ) { JString fileName; JBoolean printInfo; int transparentColor; LaceOption interlace; JBoolean padColormap; JBoolean blend; JFloat alpha; JRGB alphaColor; JString blendOutput; ParseOptions(argc, argv, &fileName, &printInfo, &transparentColor, &interlace, &padColormap, &blend, &alpha, &alphaColor, &blendOutput); JBoolean changed = kJFalse; gdImagePtr image = ReadGIF(fileName); if (printInfo) { PrintGIFInfo(image); } if (SetTransparentColor(image, transparentColor)) { changed = kJTrue; } if (SetInterlace(image, interlace)) { changed = kJTrue; } if (padColormap && PadColormap(image)) { changed = kJTrue; } if (blend) { Blend(image, alpha, alphaColor, blendOutput); } if (changed) { WriteGIF(image, fileName); } gdImageDestroy(image); return 0; }
void outputimggif(char *outfname,unsigned char *RGB,int ny,int nx,int dim) { int i,j,imagesize; FILE *fp; int ptype,numcols,colorstyle; char comment[200]; byte *pic,*rmap,*gmap,*bmap; imagesize = ny*nx; pic = RGB; if (dim==3) { conv24=CONV24_BEST; numcols=256; colorstyle=0; ptype = PIC24; } else if (dim==1) { rmap=(byte *)calloc(256,sizeof(byte)); gmap=(byte *)calloc(256,sizeof(byte)); bmap=(byte *)calloc(256,sizeof(byte)); numcols=0; for (i=0;i<imagesize;i++) { for (j=0;j<numcols;j++) { if (pic[i]==rmap[j]) break; } if (j==numcols) { rmap[j]=pic[i]; gmap[j]=pic[i]; bmap[j]=pic[i]; numcols++; } pic[i]=j; } colorstyle=1; ptype = PIC8; } fp = fopen(outfname,"wb"); WriteGIF(fp,pic,ptype,nx,ny,rmap,gmap,bmap,numcols,colorstyle,comment); fclose(fp); if (dim==1) { free(rmap); free(gmap); free(bmap); } }
void Blend ( gdImagePtr image, const JFloat alpha, const JRGB& alphaColor, const JCharacter* outputFileName ) { const JSize w = gdImageSX(image); const JSize h = gdImageSY(image); gdImagePtr i2 = gdImageCreate(w,h); for (JIndex x=0; x<w; x++) { for (JIndex y=0; y<h; y++) { const int c = gdImageGetPixel(image, x,y); const int r = BlendComponent(gdImageRed(image, c), alphaColor.red, alpha); const int g = BlendComponent(gdImageGreen(image, c), alphaColor.green, alpha); const int b = BlendComponent(gdImageBlue(image, c), alphaColor.blue, alpha); int c2 = gdImageColorExact(i2, r,g,b); if (c2 == -1) { c2 = gdImageColorAllocate(i2, r,g,b); if (c2 == -1) { c2 = gdImageColorClosest(i2, r,g,b); } } gdImageSetPixel(i2, x,y, c2); } } WriteGIF(i2, outputFileName); gdImageDestroy(i2); }
/** * Routine to write out a GIF image */ void DumpGif( char *FilenameBase, int W, int H, double **Image ){ double Val, Min, Max, dVal; int w, h; unsigned char *uImage, uVal, Filename[1024]; FILE *fp_gif, *fp_info; int LogScale; LogScale = FALSE; LogScale = TRUE; // Determine Min/Max values... Min = 9e99; Max = -9e99; for ( w=0; w<W; w++ ){ for ( h=0; h<H; h++ ) { if ( LogScale ) { Val = Image[h][w] > 0.0 ? log10( Image[h][w] ) : -9e99; } else { Val = Image[h][w]; } if (Val > Max) Max = Val; if ((Val < Min)&&(Val > -1e99)) Min = Val; } } printf("Min, Max = %g %g\n", Min, Max); sprintf( Filename, "%s.info", FilenameBase); fp_info = fopen( Filename, "w" ); fprintf( fp_info, "Min: %g\n", Min ); fprintf( fp_info, "Max: %g\n", Max ); fclose( fp_info ); uImage = (unsigned char *)calloc( W*H, sizeof(unsigned char) ); for ( w=0; w<W; w++ ){ for ( h=0; h<H; h++ ) { if ( LogScale ) { Val = Image[h][w] > 0.0 ? log10( Image[h][w] ) : -9e99; } else { Val = Image[h][w]; } if ( Val < -1e99 ) { uVal = 0; } else { dVal = (Val - Min)/(Max-Min)*255.0; uVal = (dVal > 255.0) ? 255 : (unsigned char)dVal; } *(uImage + W*(H-1-h) + w) = uVal; } } sprintf( Filename, "%s.gif", FilenameBase); fp_gif = fopen(Filename, "w"); WriteGIF(fp_gif, (byte *)uImage, 0, W, H, Rainbow3_Red, Rainbow3_Grn, Rainbow3_Blu, 256, 0, ""); fclose(fp_gif); free( uImage ); // dump a colorbar image W = 10; H = 256; uImage = (unsigned char *)calloc( W*H, sizeof(unsigned char) ); for ( w=0; w<W; w++ ){ for ( h=0; h<H; h++ ) { *(uImage + W*(H-1-h) + w) = h; } } sprintf( Filename, "%s_Bar.gif", FilenameBase); fp_gif = fopen(Filename, "w"); WriteGIF(fp_gif, (byte *)uImage, 0, W, H, Rainbow3_Red, Rainbow3_Grn, Rainbow3_Blu, 256, 0, ""); fclose(fp_gif); free( uImage ); }