// Reads Tiff Images RGBAImage* RGBAImage::ReadTiff(char *filename) { RGBAImage *fimg = 0; TIFF* tif = TIFFOpen(filename, "r"); char emsg[1024]; if (tif) { TIFFRGBAImage img; if (TIFFRGBAImageBegin(&img, tif, 0, emsg)) { size_t npixels; uint32* raster; npixels = img.width * img.height; raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); if (raster != NULL) { if (TIFFRGBAImageGet(&img, raster, img.width, img.height)) { // result is in ABGR fimg = new RGBAImage(img.width, img.height); for (int y = 0; y < img.height; y++) { for (int x = 0; x < img.width; x++) { fimg->Set(x,y, raster[x + y * img.width]); } } } _TIFFfree(raster); } } TIFFRGBAImageEnd(&img); } else { TIFFError(filename, emsg); } return fimg; }
static RGBAImage *ReadFromFile(const string &filename) { cout << "reading from file:" << filename << "\n"; vector<uint8_t> lodepng_image; //the raw pixels unsigned width, height; unsigned error = lodepng::decode(lodepng_image, width, height, filename.c_str()); if (error) { cout << "decoder error " << error << ": " << lodepng_error_text(error) << endl; return NULL; } //the pixels are now in the vector "image", 4 bytes per pixel, //ordered RGBARGBA..., use it as texture, draw it, ... cout << "width " << width << ", height " << height << "\n"; RGBAImage *rgbaimg = new RGBAImage(width,height,filename); for(unsigned y = 0; y < height; y += 1) { for(unsigned x = 0; x < width; x += 1) { uint32_t red = lodepng_image[4 * y * width + 4 * x + 0]; //red uint32_t green = lodepng_image[4 * y * width + 4 * x + 1]; //green uint32_t blue = lodepng_image[4 * y * width + 4 * x + 2]; //blue uint32_t alpha = lodepng_image[4 * y * width + 4 * x + 3]; //alpha rgbaimg->Set( red, green, blue, alpha, y*width+x ); } } return rgbaimg; }