std::pair<UncompressedImage, GeoQuadrilateral> LoadGeoTiff(Path path) { TiffLoader tiff(path); GeoQuadrilateral bounds; { auto gtif = GTIFNew(tiff.Get()); if (gtif == nullptr) throw std::runtime_error("Not a GeoTIFF file"); AtScopeExit(gtif) { GTIFFree(gtif); }; GTIFDefn defn; if (!GTIFGetDefn(gtif, &defn)) throw std::runtime_error("Failed to parse GeoTIFF metadata"); int width, height; tiff.GetField(TIFFTAG_IMAGEWIDTH, width); tiff.GetField(TIFFTAG_IMAGELENGTH, height); bounds.top_left = TiffPixelToGeoPoint(*gtif, defn, 0, 0); bounds.top_right = TiffPixelToGeoPoint(*gtif, defn, width, 0); bounds.bottom_left = TiffPixelToGeoPoint(*gtif, defn, 0, height); bounds.bottom_right = TiffPixelToGeoPoint(*gtif, defn, width, height); if (!bounds.Check()) throw std::runtime_error("Invalid GeoTIFF bounds"); } return std::make_pair(LoadTiff(tiff), bounds); }
fz_error * fz_processpredict(fz_filter *filter, fz_buffer *in, fz_buffer *out) { fz_predict *dec = (fz_predict*)filter; int ispng = dec->predictor >= 10; int predictor; while (1) { if (in->rp + dec->stride + (!dec->encode && ispng) > in->wp) { if (in->eof) return fz_iodone; return fz_ioneedin; } if (out->wp + dec->stride + (dec->encode && ispng) > out->ep) return fz_ioneedout; if (dec->predictor == 1) { none(dec, in->rp, out->wp); } else if (dec->predictor == 2) { if (dec->bpc != 8) memset(out->wp, 0, dec->stride); tiff(dec, in->rp, out->wp); } else { if (dec->encode) { predictor = dec->predictor - 10; if (predictor < 0 || predictor > 4) predictor = 1; *out->wp ++ = predictor; } else { predictor = *in->rp++; } png(dec, in->rp, out->wp, predictor); } if (dec->ref) memcpy(dec->ref, out->wp, dec->stride); in->rp += dec->stride; out->wp += dec->stride; } }
void bench_fp() { // const char * ch = "../TMP/f3Reduc1.tif"; const char * ch = "/home/data/mpd/Andalousie/andaReduc1.tif"; Tiff_Im tiff(ch); ELISE_fp fp(ch, ELISE_fp::READ); tiff.show(); INT NbTx = tiff.sz().x/ tiff.SzTile()[0]; INT NbTy = tiff.sz().y/ tiff.SzTile()[1]; REAL ttot =0; INT k=0; INT f = 1; char * c = new char [tiff.SzTile()[0] * tiff.SzTile()[1]*f*3]; for (INT x=0; x< NbTx -1; x++) for (INT y=0; y< NbTy ; y++) { fp.seek_begin(tiff.offset_tile(x,y,0)); ElTimer tim; cout << tiff.offset_tile(x,y,0) << " " << tiff.byte_count_tile(x,y,0) << "\n"; fp.read(c,1,tiff.byte_count_tile(x,y,0)/1); REAL t = tim.sval(); ttot += t; k++; cout << "Read Time moy " << ttot/k << " " << x << " " << y << "\n"; } REAL m1 = ttot/k ; ttot = 0; k=0; { for (INT x=0; x< NbTx ; x++) for (INT y=0; y< NbTy ; y++) { fp.seek_begin(0); ElTimer tim; fp.seek_begin(tiff.offset_tile(x,y,0)); REAL t = tim.sval(); ttot += t; k++; cout << "Time moy " << ttot/k << " " << x << " " << y << "\n"; } } REAL m2 = ttot/k ; cout << "Moy read = " << m1 << " Moy Seek = " << m2 << "\n"; }
int Jeremy_main( int argc, char **argv ) { if ( argc<2 ) return EXIT_FAILURE; Tiff_Im tiff(argv[1]); cout << '[' << argv[1] << "]: sz = " << tiff.sz() << 'x' << tiff.nb_chan() << ' ' << eToString(tiff.type_el()) << endl; Im2DGen image = tiff.ReadIm(); cout << '[' << argv[1] << "]: sz = " << image.sz() << ' ' << eToString(image.TypeEl()) << endl; ELISE_COPY ( image.all_pts(), Virgule( image.in(), image.in(), image.in() ), Tiff_Im( "toto.tif", image.sz(), image.TypeEl(), Tiff_Im::No_Compr, Tiff_Im::RGB, ArgOpTiffMDP(argv[1])/*Tiff_Im::Empty_ARG*/ ).out() ); return EXIT_SUCCESS; }
void convolute() { const string filename = "61.030.tif"; REAL sigma = 3.2; int nbShift = 15; double epsilon = 0.001; int surEch = 10; ConvolutionKernel1D<INT> kernel; integralGaussianKernel<INT>(sigma, nbShift, epsilon, surEch, kernel); const vector<INT> &c = kernel.coefficients(); cout << "kernel.size() = " << kernel.size() << endl; for (size_t i = 0; i < kernel.size(); i++) cout << c[i] << ' '; cout << endl; ConvolutionHandler<U_INT2> convolutionHandler; cConvolSpec<U_INT2> *convolution1d = convolutionHandler.getConvolution(kernel); cout << "convolution is " << ( !convolution1d->IsCompiled() ? "not " : "") << "compiled" << endl; Tiff_Im tiff(filename.c_str()); cout << "[" << filename << "]: " << tiff.sz() << 'x' << tiff.nb_chan() << ' ' << eToString(tiff.type_el()) << endl; Im2DGen src_gen = tiff.ReadIm(); Im2D_U_INT2 image0; if (tiff.type_el() != GenIm::u_int1) ELISE_ERROR_EXIT("bad type"); { U_INT1 *src = ((Im2D_U_INT1 *) &src_gen)->data_lin(); image0.Resize(tiff.sz()); cout << "src_gen.sz() = " << src_gen.sz() << " image0.sz() = " << image0.sz() << endl; U_INT2 *dst = image0.data_lin(); size_t i = size_t(image0.tx()) * size_t(image0.ty()); while (i--) *dst++ = (U_INT2)(*src++) * 257; } Im2D_U_INT2 image1(image0.tx(), image0.ty()); Im2D_U_INT2 *src = &image0, *dst = &image1; int nbConvol = 10; while (nbConvol--) { convolution<U_INT2>((const U_INT2 **)src->data(), src->tx(), src->ty(), *convolution1d, dst->data()); ElSwap<Im2D_U_INT2 *>(src, dst); } Im2D_U_INT1 imageToWrite(src->tx(), src->ty()); { U_INT2 *itSrc = src->data_lin(); U_INT1 *itDst = imageToWrite.data_lin(); size_t i = size_t(src->tx()) * size_t(src->ty()); while (i--) *itDst++ = (U_INT1)((*itSrc++) / 257); } ELISE_COPY ( imageToWrite.all_pts(), imageToWrite.in(), Tiff_Im( "toto.tif", imageToWrite.sz(), GenIm::u_int1, Tiff_Im::No_Compr, Tiff_Im::BlackIsZero, Tiff_Im::Empty_ARG ).out() ); }
UncompressedImage LoadTiff(Path path) { TiffLoader tiff(path); return LoadTiff(tiff); }