Matrix<Color> read_img(std::string filename) { std::size_t n = filename.size(); std::string extension3 = filename.substr(n-3, n); std::string extension4 = filename.substr(n-4, n); if(!extension3.compare("bmp")) { return read_bmp(filename); } else if(!extension3.compare("gif")) { return read_gif(filename); } else if(!extension3.compare("ico")) { return read_ico(filename); } /*else if(!extension3.compare("jpg")) { return read_jpeg(filename); }*/ else if(!extension3.compare("pcx")) { return read_pcx(filename); } else if(!extension3.compare("png")) { return read_png(filename); } else if(!extension3.compare("pbm")) { return bw2colorimage(read_pbm(filename)); } else if(!extension3.compare("pgm")) { return gray2colorimage(read_pgm(filename)); } else if(!extension3.compare("ppm")) { return read_ppm(filename); } else if(!extension3.compare("tga")) { return read_tga(filename); } else if(!extension4.compare("tiff")) { return read_tiff(filename); } else { return Matrix<Color>(); } }
Projection const Image_processor:: read_image(const std::string & name,unsigned long threshold) throw(Exception) { int index_extension = name.rfind('.'); if(index_extension == -1) throw(Exception ("\nimage processing error : no file extension -> "+name)); std::string extension(name.substr((index_extension + 1),(name.size() - 1))); if(extension == "tiff" || extension == "tif") return read_tiff(name,threshold); else throw(Exception ("\nimage processing error : unknown file extension -> "+extension)); }
// Function for reading an image file and storing as a CGAL::Image_3 object (image_) void Vol2mesh :: read_image(){ // Create File_parts object for file names FileParts infile(input_file_); // Loads a *.inr or *.inf.gz image if (infile.ext.compare(".inr") == 0 || infile.ext.compare(".inr.gz") == 0){ image_.read(infile.full.c_str()); // Load a *.tiff or *.tif image } else if (infile.ext.compare(".tif") == 0 || infile.ext.compare(".tiff") == 0){ read_tiff(); // printf("TIFF files are not yet support, future suport is planned.\n"); // exit(100); // Returns an error if the file type is not understood } else { printf("ERROR: The input file type (*%s) is not supported (see vol2mesh.cpp)\n", infile.ext.c_str()); exit(101); } }
int main(int argc, char **argv) { uint16 * img = read_tiff((char*)"GMARBLES.tif"); uint16 * normalizedTiff = normalizeData(img); //uint16 * unnormalizedTiff = unNormalizeData(normalizedTiff); write_tiff((char*)"GMARBLESNORM.tif", normalizedTiff); //write_tiff_strip_file((char*)"Tritsmfin-s1051OUT.tif", unnormalizedTiff); //8 bit image //uint16 * img = read_tiff_strip_file((char*)"GMARBLES.TIF"); //uint16* normalizedImg = normalizeData(img); //unsigned short* unnormalizedImg = unNormalizeData(normalizedImg); //write_tiff_strip_file((char*)"Tritsmfin-s1051OUT.tif", img); return 0; }
void handle_tiff(uint8_t opmode, char* in_file, char* out_file, char* data_file) { FILE* fp = fopen(in_file, "rb"); tiff_info_t* ti = read_tiff(fp); uint8_t grayscale_ok = ((ti->photometric_interpretation == 0 || ti->photometric_interpretation == 1) && ti->samples_per_pixel == 1); uint8_t color_ok = (ti->photometric_interpretation == 2 && (ti->samples_per_pixel == 3 || ti->samples_per_pixel == 4)); //printf("grayscale_ok=%d, color_ok=%d\n", grayscale_ok, color_ok ); if(!ti || ti->compressed != 1 || (!grayscale_ok && !color_ok) ) { printf("Only non-compressed " "Grayscale, RGB and RGBA TIFF files are supported\n"); printf("photometric_interpretation=%d, samples_per_pixel=%d\n", ti->photometric_interpretation, ti->samples_per_pixel); exit(1); } uint8_t* pixel_data = copy_pixel_data_tiff(fp, ti); switch(opmode) { case OP_HIDE: { if(!strcmp(in_file, out_file)) { fprintf(stderr, "input and output files must not be the same file\n"); exit(1); } FILE* data_f = fopen(data_file, "rb"); /* ensure data fits into image */ long data_size = file_size_fp(data_f); if(data_size > (get_data_size_tiff(ti)/8)) { fprintf(stderr, "data is too large to fit in image\n"); exit(1); } char* msg = malloc(data_size); memset(msg, 0, data_size); fseek(data_f, 0L, SEEK_SET); fread(msg, 1, data_size, data_f); fclose(data_f); hide_message_tiff(fp, ti, out_file, pixel_data, msg, REVERSE_BITS); break; } case OP_ADDFRAME: { add_red_frame_tiff(ti, pixel_data); put_pixel_data_tiff(fp, out_file, ti, pixel_data); break; } case OP_UNHIDE: { char* msg = get_hidden_msg_tiff(ti, pixel_data, REVERSE_BITS); if(out_file) { FILE* fout = fopen(out_file, "wb"); fwrite(msg, 1, strlen(msg), fout); fclose(fout); } else { puts(msg); } free(msg); break; } } free(pixel_data); tiff_info_free(ti); fclose(fp); }
int read_image(const char *filename, int *width, int *height, unsigned char *rgb) { char buf[4]; unsigned char *ubuf = (unsigned char *) buf; int success = 0; FILE *file; file = fopen(filename, "rb"); if (file == NULL) return(0); /* see what kind of file we have */ fread(buf, 1, 4, file); fclose(file); if (!strncmp("BM", buf, 2)) { success = read_bmp(filename, width, height, rgb); } else if (!strncmp("GIF8", buf, 4)) { #ifdef HAVE_LIBGIF success = read_gif(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with GIF support\n"); success = 0; #endif /* HAVE_LIBGIF */ } else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8)) { #ifdef HAVE_LIBJPEG success = read_jpeg(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with JPEG support\n"); success = 0; #endif /* HAVE_LIBJPEG */ } else if ((ubuf[0] == 0x89) && !strncmp("PNG", buf+1, 3)) { #ifdef HAVE_LIBPNG success = read_png(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with PNG support\n"); success = 0; #endif /* HAVE_LIBPNG */ } else if (( !strncmp("P6\n", buf, 3)) || (!strncmp("P5\n", buf, 3)) || (!strncmp("P4\n", buf, 3)) || (!strncmp("P3\n", buf, 3)) || (!strncmp("P2\n", buf, 3)) || (!strncmp("P1\n", buf, 3))) { #ifdef HAVE_LIBPNM success = read_pnm(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with PNM support\n"); success = 0; #endif /* HAVE_LIBPNM */ } else if (((!strncmp ("MM", buf, 2)) && (ubuf[2] == 0x00) && (ubuf[3] == 0x2a)) || ((!strncmp ("II", buf, 2)) && (ubuf[2] == 0x2a) && (ubuf[3] == 0x00))) { #ifdef HAVE_LIBTIFF success = read_tiff(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with TIFF support\n"); success = 0; #endif } else { fprintf(stderr, "Unknown image format\n"); success = 0; } return(success); }
void cjb2(const GURL &urlin, const GURL &urlout, cjb2opts &opts) { GP<ByteStream> ibs=ByteStream::create(urlin, "rb"); CCImage rimg; #if HAVE_TIFF if (is_tiff(ibs)) read_tiff(rimg, ibs, opts); else #endif { GP<GBitmap> input=GBitmap::create(*ibs); rimg.init(input->columns(), input->rows(), opts.dpi); rimg.add_bitmap_runs(*input); } if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cjb2.runs"), rimg.runs.size() ); // Component analysis rimg.make_ccids_by_analysis(); // obtain ccids rimg.make_ccs_from_ccids(); // compute cc descriptors if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cjb2.ccs_before"), rimg.ccs.size()); if (opts.losslevel > 0) rimg.erase_tiny_ccs(); // clean rimg.merge_and_split_ccs(); // reorganize weird ccs rimg.sort_in_reading_order(); // sort cc descriptors if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cjb2.ccs_after"), rimg.ccs.size()); // Pattern matching GP<JB2Image> jimg = rimg.get_jb2image(); // get ``raw'' jb2image rimg.runs.empty(); // save memory rimg.ccs.empty(); // save memory if (opts.losslevel>1) tune_jb2image_lossy(jimg, opts.dpi, opts.losslevel); else tune_jb2image_lossless(jimg); if (opts.verbose) { int nshape=0, nrefine=0; for (int i=0; i<jimg->get_shape_count(); i++) { if (!jimg->get_shape(i).bits) continue; if (jimg->get_shape(i).parent >= 0) nrefine++; nshape++; } DjVuFormatErrorUTF8( "%s\t%d\t%d", ERR_MSG("cjb2.shapes"), nshape, nrefine); } // Code GP<ByteStream> obs=ByteStream::create(urlout, "wb"); GP<IFFByteStream> giff=IFFByteStream::create(obs); IFFByteStream &iff=*giff; // -- main composite chunk iff.put_chunk("FORM:DJVU", 1); // -- ``INFO'' chunk GP<DjVuInfo> ginfo=DjVuInfo::create(); DjVuInfo &info=*ginfo; info.height = rimg.height; info.width = rimg.width; info.dpi = opts.dpi; iff.put_chunk("INFO"); info.encode(*iff.get_bytestream()); iff.close_chunk(); // -- ``Sjbz'' chunk iff.put_chunk("Sjbz"); jimg->encode(iff.get_bytestream()); iff.close_chunk(); // -- terminate main composite chunk iff.close_chunk(); // Finished! }