File indexing completed on 2025-01-05 03:56:48
0001 /* -*- C++ -*- 0002 * File: multirender_test.cpp 0003 * Copyright 2008-2021 LibRaw LLC (info@libraw.org) 0004 * Created: Jul 10, 2011 0005 * 0006 * LibRaw simple C++ API: creates 8 different renderings from 1 source file. 0007 The 1st and 4th one should be identical 0008 0009 LibRaw is free software; you can redistribute it and/or modify 0010 it under the terms of the one of two licenses as you choose: 0011 0012 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 0013 (See file LICENSE.LGPL provided in LibRaw distribution archive for details). 0014 0015 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 0016 (See file LICENSE.CDDL provided in LibRaw distribution archive for details). 0017 0018 0019 */ 0020 #include <stdio.h> 0021 #include <string.h> 0022 #include <math.h> 0023 #include "libraw/libraw.h" 0024 0025 #ifndef LIBRAW_WIN32_CALLS 0026 #include <unistd.h> 0027 #include <fcntl.h> 0028 #include <sys/stat.h> 0029 #include <sys/mman.h> 0030 #endif 0031 0032 #ifdef LIBRAW_WIN32_CALLS 0033 #define snprintf _snprintf 0034 #endif 0035 0036 int process_once(LibRaw &RawProcessor, int half_mode, int camera_wb, 0037 int auto_wb, int suffix, int user_flip, char *fname) 0038 { 0039 char outfn[1024]; 0040 RawProcessor.imgdata.params.half_size = half_mode; 0041 RawProcessor.imgdata.params.use_camera_wb = camera_wb; 0042 RawProcessor.imgdata.params.use_auto_wb = auto_wb; 0043 RawProcessor.imgdata.params.user_flip = user_flip; 0044 0045 int ret = RawProcessor.dcraw_process(); 0046 0047 if (LIBRAW_SUCCESS != ret) 0048 { 0049 fprintf(stderr, "Cannot do postprocessing on %s: %s\n", fname, 0050 libraw_strerror(ret)); 0051 return ret; 0052 } 0053 snprintf(outfn, sizeof(outfn), "%s.%d.%s", fname, suffix, 0054 (RawProcessor.imgdata.idata.colors > 1 ? "ppm" : "pgm")); 0055 0056 printf("Writing file %s\n", outfn); 0057 0058 if (LIBRAW_SUCCESS != (ret = RawProcessor.dcraw_ppm_tiff_writer(outfn))) 0059 fprintf(stderr, "Cannot write %s: %s\n", outfn, libraw_strerror(ret)); 0060 return ret; 0061 } 0062 0063 int main(int ac, char *av[]) 0064 { 0065 int i, ret; 0066 0067 LibRaw RawProcessor; 0068 if (ac < 2) 0069 { 0070 printf("multirender_test - LibRaw %s sample. Performs 4 different " 0071 "renderings of one file\n" 0072 " %d cameras supported\n" 0073 "Usage: %s raw-files....\n", 0074 LibRaw::version(), LibRaw::cameraCount(), av[0]); 0075 return 0; 0076 } 0077 0078 for (i = 1; i < ac; i++) 0079 { 0080 0081 printf("Processing file %s\n", av[i]); 0082 0083 if ((ret = RawProcessor.open_file(av[i])) != LIBRAW_SUCCESS) 0084 { 0085 fprintf(stderr, "Cannot open_file %s: %s\n", av[i], libraw_strerror(ret)); 0086 continue; // no recycle b/c open file will recycle itself 0087 } 0088 0089 if ((ret = RawProcessor.unpack()) != LIBRAW_SUCCESS) 0090 { 0091 fprintf(stderr, "Cannot unpack %s: %s\n", av[i], libraw_strerror(ret)); 0092 continue; 0093 } 0094 process_once(RawProcessor, 0, 0, 0, 1, -1, av[i]); // default flip 0095 process_once(RawProcessor, 1, 0, 1, 2, -1, av[i]); 0096 process_once(RawProcessor, 1, 1, 0, 3, -1, av[i]); // default flip 0097 process_once(RawProcessor, 1, 1, 0, 4, 1, av[i]); // flip 1 0098 process_once(RawProcessor, 1, 1, 0, 5, 3, av[i]); // flip 3 0099 process_once(RawProcessor, 1, 1, 0, 6, 1, av[i]); // 1 again same as 4 0100 process_once(RawProcessor, 1, 1, 0, 7, -1, 0101 av[i]); // default again, same as 3 0102 process_once(RawProcessor, 0, 0, 0, 8, -1, av[i]); // same as 1 0103 0104 RawProcessor.recycle(); // just for show this call 0105 } 0106 return 0; 0107 }