bool write_image(char *file_name, int width, int height, int nbytes, UCHAR *image, double *geotiffInfo, DWORD jpegQuality, DWORD tiffCompression) { const char *p = strrchr(file_name, '.'); if (!p) return false; if (!_stricmp(p, ".jpg")) return write_jpeg(file_name, width, height, nbytes, image, jpegQuality); if (!_stricmp(p, ".tif")) return write_tiff(file_name, width, height, nbytes, image, geotiffInfo, jpegQuality, tiffCompression); if (!_stricmp(p, ".png")) return write_png(file_name, width, height, nbytes, image); return false; }
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; }
int main(int ac, char *av[]) { int i, ret; int verbose=1,autoscale=0,use_gamma=0,out_tiff=0; char outfn[1024]; LibRaw RawProcessor; if(ac<2) { usage: printf( "unprocessed_raw - LibRaw %s sample. %d cameras supported\n" "Usage: %s [-q] [-A] [-g] [-s N] raw-files....\n" "\t-q - be quiet\n" "\t-s N - select Nth image in file (default=0)\n" "\t-g - use gamma correction with gamma 2.2 (not precise,use for visual inspection only)\n" "\t-A - autoscaling (by integer factor)\n" "\t-T - write tiff instead of pgm\n" ,LibRaw::version(), LibRaw::cameraCount(), av[0]); return 0; } #define S RawProcessor.imgdata.sizes #define OUT RawProcessor.imgdata.params for (i=1; i<ac; i++) { if(av[i][0]=='-') { if(av[i][1]=='q' && av[i][2]==0) verbose=0; else if(av[i][1]=='A' && av[i][2]==0) autoscale=1; else if(av[i][1]=='g' && av[i][2]==0) use_gamma = 1; else if(av[i][1]=='T' && av[i][2]==0) out_tiff = 1; else if(av[i][1]=='s' && av[i][2]==0) { i++; OUT.shot_select=av[i]?atoi(av[i]):0; } else goto usage; continue; } if(verbose) printf("Processing file %s\n",av[i]); if( (ret = RawProcessor.open_file(av[i])) != LIBRAW_SUCCESS) { fprintf(stderr,"Cannot open %s: %s\n",av[i],libraw_strerror(ret)); continue; // no recycle b/c open file will recycle itself } if(verbose) { printf("Image size: %dx%d\nRaw size: %dx%d\n",S.width,S.height,S.raw_width,S.raw_height); printf("Margins: top=%d, left=%d\n", S.top_margin,S.left_margin); } if( (ret = RawProcessor.unpack() ) != LIBRAW_SUCCESS) { fprintf(stderr,"Cannot unpack %s: %s\n",av[i],libraw_strerror(ret)); continue; } if(verbose) printf("Unpacked....\n"); if(!(RawProcessor.imgdata.idata.filters || RawProcessor.imgdata.idata.colors == 1)) { printf("Only Bayer-pattern RAW files supported, sorry....\n"); continue; } if(autoscale) { unsigned max=0,scale; for(int j=0; j<S.raw_height*S.raw_width; j++) if(max < RawProcessor.imgdata.rawdata.raw_image[j]) max = RawProcessor.imgdata.rawdata.raw_image[j]; if (max >0 && max< 1<<15) { scale = (1<<16)/max; if(verbose) printf("Scaling with multiplier=%d (max=%d)\n",scale,max); for(int j=0; j<S.raw_height*S.raw_width; j++) RawProcessor.imgdata.rawdata.raw_image[j] *= scale; } } if(use_gamma) { unsigned short curve[0x10000]; gamma_curve(curve); for(int j=0; j<S.raw_height*S.raw_width; j++) RawProcessor.imgdata.rawdata.raw_image[j] = curve[RawProcessor.imgdata.rawdata.raw_image[j]]; if(verbose) printf("Gamma-corrected....\n"); } if(OUT.shot_select) snprintf(outfn,sizeof(outfn),"%s-%d.%s",av[i],OUT.shot_select,out_tiff?"tiff":"pgm"); else snprintf(outfn,sizeof(outfn),"%s.%s",av[i],out_tiff?"tiff":"pgm"); if(out_tiff) write_tiff(S.raw_width,S.raw_height,RawProcessor.imgdata.rawdata.raw_image,outfn); else write_ppm(S.raw_width,S.raw_height,RawProcessor.imgdata.rawdata.raw_image,outfn); if(verbose) printf("Stored to file %s\n",outfn); } return 0; }
int write_image(const char *filename, int width, int height, unsigned char *rgb) { FILE *outfile; char *extension = strrchr(filename, '.'); char *lowercase; char *ptr; int success = 0; lowercase = malloc(strlen(extension) + 1); strcpy(lowercase, extension); ptr = lowercase; while (*ptr != '\0') *ptr++ = tolower(*extension++); outfile = fopen(filename, "wb"); if (outfile == NULL) return(0); if (strcmp(lowercase, ".bmp" ) == 0) { success = write_bmp(filename, width, height, rgb); } else if (strcmp(lowercase, ".gif" ) == 0) { #ifdef HAVE_LIBGIF success = write_gif(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with GIF support\n"); success = 0; #endif /* HAVE_LIBPNG */ } else if (( strcmp(lowercase, ".jpg" ) == 0) || (strcmp(lowercase, ".jpeg") == 0)) { #ifdef HAVE_LIBJPEG success = write_jpeg(outfile, width, height, rgb, Q); #else fprintf(stderr, "Sorry, this program was not compiled with JPEG support\n"); success = 0; #endif /* HAVE_LIBJPEG */ } else if (strcmp(lowercase, ".png" ) == 0) { #ifdef HAVE_LIBPNG success = write_png(outfile, width, height, rgb, alpha); #else fprintf(stderr, "Sorry, this program was not compiled with PNG support\n"); success = 0; #endif /* HAVE_LIBPNG */ } else if (( strcmp(lowercase, ".pbm") == 0) || (strcmp(lowercase, ".pgm") == 0) || (strcmp(lowercase, ".ppm") == 0)) { #ifdef HAVE_LIBPNM if (strcmp(lowercase, ".pbm") == 0) success = write_pnm(outfile, width, height, rgb, 1, PBM_TYPE, 0); else if (strcmp(lowercase, ".pgm") == 0) success = write_pnm(outfile, width, height, rgb, 255, PGM_TYPE, 0); else if (strcmp(lowercase, ".ppm") == 0) success = write_pnm(outfile, width, height, rgb, 255, PPM_TYPE, 0); #else fprintf(stderr, "Sorry, this program was not compiled with PNM support\n"); success = 0; #endif /* HAVE_LIBPNM */ } else if ((strcmp(lowercase, ".tif" ) == 0) || (strcmp(lowercase, ".tiff" ) == 0)) { #ifdef HAVE_LIBTIFF success = write_tiff(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with TIFF support\n"); success = 0; #endif /* HAVE_LIBTIFF */ } else { fprintf(stderr, "Unknown image format\n"); success = 0; } free(lowercase); fclose(outfile); return(success); }
static GError * record_frames (UcaCamera *camera, Options *opts) { guint roi_width; guint roi_height; guint bits; guint pixel_size; gsize size; gint n_frames; guint n_allocated; GTimer *timer; UcaRingBuffer *buffer; GError *error = NULL; gdouble last_printed; g_object_get (G_OBJECT (camera), "roi-width", &roi_width, "roi-height", &roi_height, "sensor-bitdepth", &bits, NULL); pixel_size = get_bytes_per_pixel (bits); size = roi_width * roi_height * pixel_size; n_allocated = opts->n_frames > 0 ? opts->n_frames : 256; buffer = uca_ring_buffer_new (size, n_allocated); timer = g_timer_new(); g_print("Start recording: %ix%i at %i bits/pixel\n", roi_width, roi_height, bits); uca_camera_start_recording(camera, &error); if (error != NULL) return error; n_frames = 0; g_timer_start(timer); last_printed = 0.0; while (1) { gdouble elapsed; uca_camera_grab (camera, uca_ring_buffer_get_write_pointer (buffer), &error); uca_ring_buffer_write_advance (buffer); if (error != NULL) return error; n_frames++; elapsed = g_timer_elapsed (timer, NULL); if (n_frames == opts->n_frames || (opts->duration > 0.0 && elapsed >= opts->duration)) break; if (elapsed - last_printed >= 1.0) { g_print ("Recorded %i frames at %.2f frames/s\n", n_frames, n_frames / elapsed); last_printed = elapsed; } } g_print ("Stop recording: %3.2f frames/s\n", n_frames / g_timer_elapsed (timer, NULL)); uca_camera_stop_recording (camera, &error); #ifdef HAVE_LIBTIFF if (opts->write_tiff) write_tiff (buffer, opts, roi_width, roi_height, bits); else write_raw (buffer, opts); #else write_raw (buffer, opts); #endif g_object_unref (buffer); g_timer_destroy (timer); return error; }