int main(int argc, char* argv[]) { if(argc != 2) { fprintf(stderr, "Usage: %s depthimage\n", argv[0]); exit(EXIT_FAILURE); } const char* depthfile = argv[1]; uint8_t* img; uint32_t width, height; if(!readpng(depthfile, &img, &width, &height)) { fprintf(stderr, "could not open '%s'!\n", depthfile); return EXIT_FAILURE; } double mm[2] = {FLT_MAX, -FLT_MAX}; for(uint32_t j=0; j < height; ++j) { for(uint32_t i=0; i < width; ++i) { const size_t idx = j*width + i; const float val = (float)(img[idx]); if(val < mm[0]) { mm[0] = val; } if(val > mm[1]) { mm[1] = val; } } } printf("minmax depth: %lf %lf\n", mm[0], mm[1]); free(img); return EXIT_SUCCESS; }
/** * grx_context_load_from_png: * @context: (nullable): Context to be loaded or %NULL to use the global context * @filename: (type filename): Name of jpeg file * @use_alpha: if %TRUE, use alpha channel if available * @error: pointer to hold an error or %NULL to ignore * * Load a context from a PNG file * * If context dimensions are less than png dimensions, * the routine loads as much as it can * * If color mode is not in RGB mode, the routine allocates as * many colors as it can * * Returns: %TRUE on success, otherwise %FALSE */ gboolean grx_context_load_from_png(GrxContext *grc, const char *pngfn, int use_alpha, GError **error) { GrxContext grcaux; FILE *f; gboolean r; f = fopen( pngfn,"rb" ); if (f == NULL) { g_set_error(error, G_IO_ERROR, g_io_error_from_errno(errno), "Failed to open '%s'", pngfn); return FALSE; } grx_save_current_context( &grcaux ); if( grc != NULL ) grx_set_current_context( grc ); r = readpng( f,grc,use_alpha ); grx_set_current_context( &grcaux ); fclose( f ); if (!r) { g_set_error(error, GRX_ERROR, GRX_ERROR_PNG_ERROR, "Error while reading '%s'", pngfn); } return r; }
int main() { { const char* depthfile = "/home/tfogal/data/scenedemo/D01293.png"; uint8_t* img; uint32_t width, height; readpng(depthfile, &img, &width, &height); std::shared_ptr<void> id(img, free); bstream_t info = { UNSIGNED_INTEGER, sizeof(uint8_t), 1, { width, height, 1, 1 } }; //std::array<uint64_t,4> dims = {{ width, height, 1, 1 }}; #if 0 gv::Crop c; c.set_axis(0); c.set_index(320); c.set_input(id, info); c.execute(); #endif gv::Cast cast; cast.set_input(id, info); bstream_t convert = info; convert.width = 2; cast.set_otype(convert); cast.execute(); gv::stream upcasted = cast.output(0); assert(((const uint16_t*)upcasted.data.get())[0] == 27); writepng("test.png", (const uint16_t*)upcasted.data.get(), width, height); } { gv::MinMax mm; std::array<double, 12> arr = {{ 9,11,16,42, 19,8,-2,4, -19,86,14,8 }}; bstream_t arri = { FLOAT, sizeof(double), 1, { 12, 1, 1, 1 } }; mm.set_input(std::shared_ptr<void>(arr.data(), nonstd::null_deleter()), arri); mm.execute(); gv::stream mmax = mm.output(0); const double* dat = static_cast<const double*>(mmax.data.get()); std::cout << "minmax: (" << dat[0] << ")--(" << dat[1] << ")\n"; } return EXIT_SUCCESS; }
ImageResolution::ImageResolution(char const *fn) { ok_ = false; readpng(fn); if (!ok_) readexif(fn); if (!ok_) readexiv(fn); if (!ok_) readjfif(fn); }
int main(int argc, char *argv[]) { int w, h, y; if(argc != 2) { fprintf(stderr, "wrong number of args\n"); return 1; } png_bytepp p = readpng(argv[1], &w, &h); printf("P6\n%i %i\n255\n", w, h); for(y=0; y<h; y++) fwrite(p[y], 3, w, stdout); return 0; }
int main(int argc, char* argv[]) { if(argc != 4) { fprintf(stderr, "Usage: %s depthimage colorimage obj-file\n", argv[0]); exit(EXIT_FAILURE); } const char* depthfile = argv[1]; const char* colorfile = argv[2]; const char* objfile = argv[3]; uint8_t* img; uint32_t width, height; readpng(depthfile, &img, &width, &height); printf("expanding...\n"); float* imgf = expand8(img, width, height); free(img); printf("lerping...\n"); lerpf(imgf, width,height, 0.0f,241.0f, 1.0f,1.5f); #if 0 { printf("writing OBJ...\n"); /* generate the basename for the OBJ file by trying to find a "." and hacking off everything there and later. */ char* base_obj = calloc(strlen(objfile)+1, sizeof(char)); strcpy(base_obj, objfile); char* dot = strrchr(base_obj, '.'); if(dot) { *dot = '\0'; } write_objf(base_obj, colorfile, imgf, width, height); free(base_obj); } #endif { printf("writing TJF...\n"); /* generate the basename for the filename by trying to find a "." and hacking off everything there and later. */ char* base_tjf = calloc(strlen(objfile)+1, sizeof(char)); strcpy(base_tjf, objfile); char* dot = strrchr(base_tjf, '.'); if(dot) { *dot = '\0'; } write_tjff(16, base_tjf, colorfile, imgf, width, height); free(base_tjf); } return EXIT_SUCCESS; }
int GrLoadContextFromPng( GrContext *grc, char *pngfn, int use_alpha ) { GrContext grcaux; FILE *f; int r; f = fopen( pngfn,"rb" ); if( f == NULL ) return -1; GrSaveContext( &grcaux ); if( grc != NULL ) GrSetContext( grc ); r = readpng( f,grc,use_alpha ); GrSetContext( &grcaux ); fclose( f ); return r; }
unsigned char *readpicture(char *filename, int *width, int *height, int printflag){ char *ext; unsigned char *returncode; char *filebuffer=NULL; int allocated; STRUCTSTAT statbuffer; if(filename==NULL)return NULL; if(STAT(filename,&statbuffer)==0){ filebuffer=filename; allocated=0; } else{ size_t lenbuffer; if(texturedir==NULL){ if(printflag==1){ fprintf(stderr,"*** Error: texture file: %s unavailable\n",filename); } return NULL; } else{ FILE *stream; lenbuffer=strlen(filename)+strlen(texturedir)+1; NewMemory((void **)&filebuffer,(unsigned int)(lenbuffer+1)); allocated=1; strcpy(filebuffer,texturedir); strcat(filebuffer,dirseparator); strcat(filebuffer,filename); stream=fopen(filebuffer,"rb"); if(stream==NULL){ if(printflag==1){ fprintf(stderr,"*** Error: texture file: %s unavailable\n",filebuffer); } FREEMEMORY(filebuffer); return NULL; } else{ fclose(stream); } } } if(printflag==1)PRINTF("Loading texture:%s ",filebuffer); ext = filebuffer + strlen(filebuffer) - 4; if(strncmp(ext,".jpg",4)==0||strncmp(ext,".JPG",4)==0){ returncode = readjpeg(filebuffer,width,height,pixel_skip); } else if(strncmp(ext,".png",4)==0||strncmp(ext,".PNG",4)==0){ returncode = readpng(filebuffer,width,height); } else{ if(allocated==1){ FREEMEMORY(filebuffer); } return NULL; } if(allocated==1){ FREEMEMORY(filebuffer); } if(printflag==1){ if(returncode!=NULL){ PRINTF(" - completed\n"); } else{ PRINTF(" - failed\n"); fprintf(stderr,"*** Error: attempt to input %s failed\n",filename); } } return returncode; }
void readTex(const std::string &fileName) { std::string filePath = fileName; int w, h; png_bytepp p = readpng(filePath.c_str(), &w, &h); /* gData = new unsigned char [w * h * 3]; for(int y=0; y<h; y++) { png_bytep r = p[h-1-y]; // get the row for (int x = 0; x < 3*w; x += 3) { int index = x + (3 * w * y); gData[index] = r[x]; gData[index + 1] = r[x+1]; gData[index + 2] = r[x+2]; //std::cout << index << " " << int(r[x]) << std::endl; //std::cout << index + 1 << " " << int(r[x+1]) << std::endl; //std::cout << index + 2 << " " << int(r[x+2]) << std::endl; } } */ std::cout << "READ" << std::endl; //gWidth = w; //gHeight = h; GLubyte *textureImage; int width, height; bool hasAlpha; //char filename[] = "yoshihq2x.png"; //char filename[] = "yoshi_side.png"; char *filename = new char[filePath.size()+1]; filename[filePath.size()]=0; memcpy(filename,filePath.c_str(),filePath.size()); bool success = loadPngImage(filename, width, height, hasAlpha, &textureImage); if (!success) { std::cout << "Unable to load png file" << std::endl; return; } gWidth = width; gHeight = height; gData = new unsigned char [width * height * 4]; std::cout << "Image loaded " << width << " " << height << " alpha " << hasAlpha << std::endl; int count = 0; for (int i = 0; i < width * height; i++) { if (hasAlpha) { gData[4*i] = textureImage[4*i]; gData[4*i + 1] = textureImage[4*i + 1]; gData[4*i + 2] = textureImage[4*i + 2]; gData[4*i + 3] = textureImage[4*i + 3]; } else { gData[4*i] = textureImage[3*i]; // since textureImage now is just RGB gData[4*i + 1] = textureImage[3*i + 1]; gData[4*i + 2] = textureImage[3*i + 2]; gData[4*i + 3] = 0; } //std::cout << i << " "<< int(textureImage[i]) << std::endl; /* if (i % 4 == 0) { continue; } else { gData[count] = textureImage[i]; count++; } */ } }
int readimage(rawimage * img) { int rc; int xres, yres; unsigned char * imgdata; char * name = img->name; char msgtxt[2048]; if (strstr(name, ".ppm")) { rc = readppm(name, &xres, &yres, &imgdata); } else if (strstr(name, ".tga")) { rc = readtga(name, &xres, &yres, &imgdata); } else if (strstr(name, ".jpg")) { rc = readjpeg(name, &xres, &yres, &imgdata); } else if (strstr(name, ".png")) { rc = readpng(name, &xres, &yres, &imgdata); } else if (strstr(name, ".gif")) { rc = IMAGEUNSUP; } else if (strstr(name, ".tiff")) { rc = IMAGEUNSUP; } else if (strstr(name, ".rgb")) { rc = IMAGEUNSUP; } else if (strstr(name, ".xpm")) { rc = IMAGEUNSUP; } else { rc = readppm(name, &xres, &yres, &imgdata); } switch (rc) { case IMAGEREADERR: sprintf(msgtxt, "Short read encountered while loading image %s", name); rt_ui_message(MSG_0, msgtxt); rc = IMAGENOERR; /* remap to non-fatal error */ break; case IMAGEUNSUP: sprintf(msgtxt, "Cannot read unsupported format for image %s", name); rt_ui_message(MSG_0, msgtxt); break; } /* If the image load failed, create a tiny white colored image to fake it */ /* this allows a scene to render even when a file can't be loaded */ if (rc != IMAGENOERR) { rc = fakeimage(name, &xres, &yres, &imgdata); } /* If we succeeded in loading the image, return it. */ if (rc == IMAGENOERR) { img->xres = xres; img->yres = yres; img->bpp = 3; img->data = imgdata; } return rc; }