// ImageIO Function Definitions std::unique_ptr<RGBSpectrum[]> ReadImage(const std::string &name, Point2i *resolution) { if (name.size() >= 5) { size_t suffixOffset = name.size() - 4; if (!strcmp(name.c_str() + suffixOffset, ".exr") || !strcmp(name.c_str() + suffixOffset, ".EXR")) return std::unique_ptr<RGBSpectrum[]>( ReadImageEXR(name, &resolution->x, &resolution->y)); if (!strcmp(name.c_str() + suffixOffset, ".tga") || !strcmp(name.c_str() + suffixOffset, ".TGA")) return std::unique_ptr<RGBSpectrum[]>( ReadImageTGA(name, &resolution->x, &resolution->y)); if (!strcmp(name.c_str() + suffixOffset, ".pfm") || !strcmp(name.c_str() + suffixOffset, ".PFM")) return std::unique_ptr<RGBSpectrum[]>( ReadImagePFM(name, &resolution->x, &resolution->y)); } Error( "Unable to load image stored in format \"%s\" for filename \"%s\". " "Returning a constant grey image instead.", strrchr(name.c_str(), '.') ? (strrchr(name.c_str(), '.') + 1) : "(unknown)", name.c_str()); RGBSpectrum *ret = new RGBSpectrum[1]; ret[0] = RGBSpectrum(0.5f); resolution->x = resolution->y = 1; return std::unique_ptr<RGBSpectrum[]>(ret); }
// ImageIO Function Definitions std::unique_ptr<RGBSpectrum[]> ReadImage(const std::string &name, Point2i *resolution) { if (HasExtension(name, ".exr")) return std::unique_ptr<RGBSpectrum[]>( ReadImageEXR(name, &resolution->x, &resolution->y)); else if (HasExtension(name, ".tga")) return std::unique_ptr<RGBSpectrum[]>( ReadImageTGA(name, &resolution->x, &resolution->y)); else if (HasExtension(name, ".pfm")) return std::unique_ptr<RGBSpectrum[]>( ReadImagePFM(name, &resolution->x, &resolution->y)); Error( "Unable to load image stored in format \"%s\" for filename \"%s\". " "Returning a constant gray image instead.", strrchr(name.c_str(), '.') ? (strrchr(name.c_str(), '.') + 1) : "(unknown)", name.c_str()); RGBSpectrum *ret = new RGBSpectrum[1]; ret[0] = RGBSpectrum(0.5f); resolution->x = resolution->y = 1; return std::unique_ptr<RGBSpectrum[]>(ret); }
int main(int argc, char *argv[]) { int nx, ny, ncha, cx, cy; int xmin, xmax, ymin, ymax; int x0,x1,y0,y1; int cxy,nxy; float *data, *d; char flag_mc = 1; if(argc < 6) { printf("not enough arguments...\n"); printf("usage:\n"); printf(" %s x0 y0 x1 y1 img-exr img-crop-exr\n",argv[0]); exit(0); } data = readMultiImageEXR(argv[5], &nx, &ny, &ncha); if (!data) { data = ReadImageEXR(argv[5], &nx, &ny); ncha = 3; flag_mc = 0; if(!data) { printf("error :: %s not a correct exr image \n", argv[5]); exit(-1); } } x0 = atoi(argv[1]); y0 = atoi(argv[2]); x1 = atoi(argv[3]); y1 = atoi(argv[4]); xmin = MAX(0,MIN(x0,x1)); xmax = MIN(nx-1,MAX(x0,x1)); ymin = MAX(0,MIN(y0,y1)); ymax = MIN(ny-1,MAX(y0,y1)); cx = xmax - xmin; cy = ymax - ymin; printf("Cropping: xmin:%d xmax:%d ymin:%d ymax:%d\n",xmin,xmax,ymin,ymax); //if cx or cy is negative parameters wrong if(cx <= 0 || cy <= 0) { printf("error :: incorrect crop values\n"); exit(-1); } nxy = nx * ny; cxy = cx * cy; d = (float*)malloc(sizeof(float) * cxy * ncha); /*Crop Image*/ for(int y=0;y<cy;y++) for(int x=0;x<cx;x++) for(int c=0;c<ncha;c++) d[x + cx*y + cxy*c] = data[x + xmin + nx*(y+ymin) + nxy*c]; if(flag_mc) { writeMultiImageEXR(argv[6], d, cx, cy, ncha); } else { WriteImageEXR(argv[6], d, cx, cy); } free(data); free(d); return 0; }