char* esDecompressGRAY16_PNG ( char *pngbuf, size_t size, int *width, int *height ) { char *buffer; float offset; float scale; if(png_load((unsigned char*)pngbuf, size, (unsigned char**)&buffer, &offset, &scale, width, height, IT_PNG_GRAY16) == -1) { AMIGO_LOG_W(TAG, "esDecompressGRAY16_PNG() FAILED.\n"); return NULL; } return buffer; }
int paintIcon(const char *const fname, int xstart, int ystart, int xsize, int ysize, int *iw, int *ih) { FILE *tfh; int x1, y1, rv=-1, alpha=0, bpp=0; int imx,imy,dxo,dyo,dxp,dyp; unsigned char *buffer=NULL; if((tfh=fopen(fname,"r"))!=NULL) { if(png_getsize(fname, &x1, &y1)) { perror(__plugin__ " <invalid PNG-Format>\n"); fclose(tfh); return -1; } // no resize if (xsize == 0 || ysize ==0) { xsize = x1; ysize = y1; } if((buffer=(unsigned char *) malloc(x1*y1*4))==NULL) { printf(NOMEM); fclose(tfh); return -1; } if(!(rv=png_load(fname, &buffer, &x1, &y1, &bpp))) { alpha=(bpp==4)?1:0; scale_pic(&buffer,x1,y1,xstart,ystart,xsize,ysize,&imx,&imy,&dxp,&dyp,&dxo,&dyo,alpha); fb_display(buffer, imx, imy, dxp, dyp, dxo, dyo, 0, alpha); } free(buffer); fclose(tfh); } *iw = imx; *ih = imy; return (rv)?-1:0; }
Texture_t *texture_loadFromPng(const char *aPath, bool aRepeatHorizontal, bool aRepeatVertical) { Texture_t *out = obj_create_autoreleased(&Class_Texture); out->displayCallback = (RenderableDisplayCallback_t)&_texture_draw; Png_t *png = png_load(aPath); if(!png) { dynamo_log("Unable to load png file from %s", aPath); return NULL; } glGenTextures(1, &out->id); glBindTexture(GL_TEXTURE_2D, out->id); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, png->hasAlpha ? GL_RGBA : GL_RGB, png->width, png->height, 0, png->hasAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, png->data); glError() glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aRepeatHorizontal ? GL_REPEAT : GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aRepeatVertical ? GL_REPEAT : GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Mipmaps can only be generated if the texture size is a power of 2 if(_isPowerOfTwo(png->width) && _isPowerOfTwo(png->height) && !aRepeatHorizontal && !aRepeatVertical) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glGenerateMipmap(GL_TEXTURE_2D); } else { dynamo_assert(!( (!_isPowerOfTwo(png->width) || !_isPowerOfTwo(png->height)) && (aRepeatHorizontal || aRepeatVertical) ), "Repeating textures must have power of 2 dimensions"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } glError() out->size = vec2_create(png->width, png->height); out->pxAlignInset = vec2_create( (1.0f/out->size.w) * 0.5, (1.0f/out->size.h) * 0.5 ); return out; }
int main(int argc, char *argv[]) { if (argc != 3) { std::cout << "Usage: alpha-bleeding <input> <output>" << std::endl; return 0; } const char *input = argv[1]; const char *output = argv[2]; if (std::ifstream(output).good()) { std::cout << "Output file already exists!" << std::endl; return 0; } int w, h, c; unsigned char *data = png_load(input, &w, &h, &c); if (data == 0) { std::cout << "Error loading image. Must be PNG format." << std::endl; return 1; } if (c != 4) { std::cout << "The image must be 32 bits (RGB with alpha channel)." << std::endl; delete[] data; return 0; } alpha_bleeding(data, w, h); png_save(output, w, h, data); delete[] data; return 0; }
int main(int argc, char *argv[]) { int i,j,k; char c; int res=0; int x,y; char buttons; struct termios t_new,t_old; FILE *fsc; char buf[100]; progname=argv[0]; screen_gamma=1.5; #ifdef DEBUG log=fopen("/png/view.log","w"); #endif while((c=getopt(argc,argv,"r:g:"))!=-1) { switch(c) { case 'r': res=atoi(optarg); if(res>0) max_screen_colors=256; break; case 'g': screen_gamma=atof(optarg); break; case '?': default: usage(); exit(0); } } switch(res) { case 0: VGLInit(SW_CG640x480); break; case 1: VGLInit(SW_VGA_CG320); break; case 2: VGLInit(SW_VGA_MODEX); break; default: fprintf(stderr,"No such resolution!\n"); usage(); exit(-1); } #ifdef DEBUG fprintf(log,"VGL initialised\n"); #endif VGLSavePalette(); if(argc>optind) { res=png_load(argv[optind]); } else { VGLEnd(); usage(); exit(0); } if(res) { /* Hmm... Script? */ fsc=fopen(argv[optind],"r"); #ifdef DEBUG fprintf(log,"Trying script %s\n",argv[optind]); #endif fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; if(strncmp("VIEW SCRIPT",buf,11)!=NULL) { VGLEnd(); usage(); } if(strlen(buf)>12) { auto_chg=atoi(buf+12); } fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; nimg=atoi(buf); if(nimg==0) { VGLEnd(); usage(); } pres=(char **)calloc(nimg,sizeof(char *)); for(i=0;i<nimg;i++) { fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; pres[i]=strdup(buf); } fclose(fsc); cur_img=0; #ifdef DEBUG fprintf(log,"Script with %d entries\n",nimg); #endif png_load(pres[cur_img]); } VGLMouseInit(VGL_MOUSEHIDE); /* Prepare the keyboard */ tcgetattr(0,&t_old); memcpy(&t_new,&t_old,sizeof(struct termios)); cfmakeraw(&t_new); tcsetattr(0,TCSAFLUSH,&t_new); fcntl(0,F_SETFL,O_ASYNC); /* XXX VGLClear doesn't work.. :-(( Prepare a blank background */ bkg.Bitmap=(byte *)calloc(VGLDisplay->Xsize*VGLDisplay->Ysize,1); bkg.Xsize=VGLDisplay->Xsize; bkg.Ysize=VGLDisplay->Ysize; bkg.Type=VGLDisplay->Type; signal(SIGIO,kbd_handler); a.zoom=1; a.Xshift=(VGLDisplay->Xsize-pic.Xsize)/2; a.Yshift=(VGLDisplay->Ysize-pic.Ysize)/2; a.rotate=0; quit=0; changed=0; display(&pic,pal_red,pal_green,pal_blue,&a); while(!quit) { if(act) { #ifdef DEBUG fprintf(log,"kbd_action(%c)\n",act); #endif kbd_action(x,y,act); } if(quit) break; if(changed) { #ifdef DEBUG fprintf(log,"changed, redisplaying\n"); #endif display(&pic,pal_red,pal_green,pal_blue,&a); changed=0; } if(auto_chg) { sleep(auto_chg); kbd_action(x,y,'n'); } else { pause(); } VGLMouseStatus(&x,&y,&buttons); if(buttons & MOUSE_BUTTON3DOWN) { #ifdef DEBUG fprintf(log,"pop_up called\n"); #endif pop_up("View",x,y); } } VGLEnd(); #ifdef DEBUG fclose(log); #endif exit(0); }
int kbd_action(int x, int y, char key) { changed=0; if(key!='n') auto_chg=0; switch(key) { case 'q': quit=1; break; case 'Z': a.zoom++; changed++; break; case 'z': a.zoom--; if(a.zoom<1) a.zoom=1; changed++; break; case 'l': a.Xshift+=VGLDisplay->Xsize/5; changed++; break; case 'h': a.Xshift-=VGLDisplay->Xsize/5; changed++; break; case 'k': a.Yshift+=VGLDisplay->Ysize/5; changed++; break; case 'j': a.Yshift-=VGLDisplay->Ysize/5; changed++; break; case 'R': changed++; break; case 'r': if(a.rotate) a.rotate=0; else a.rotate=1; changed++; break; case '\n': case 'n': if(nimg>0) { if(cur_img<nimg-1) { cur_img++; } else { cur_img=0; } png_load(pres[cur_img]); changed++; } break; case 'p': if(nimg>0) { if(cur_img>0) { cur_img--; } else { cur_img=nimg-1; } png_load(pres[cur_img]); changed++; } break; } act=0; }
void generator_context::load_png_image(const std::string& name, const std::string& png_file) { images_[name] = png_load(png_file); }