1 /* -*- C++ -*- 2 * Copyright 2019-2020 LibRaw LLC (info@libraw.org) 3 * 4 LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder, 5 dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net. 6 LibRaw do not use RESTRICTED code from dcraw.c 7 8 LibRaw is free software; you can redistribute it and/or modify 9 it under the terms of the one of two licenses as you choose: 10 11 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 12 (See file LICENSE.LGPL provided in LibRaw distribution archive for details). 13 14 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 15 (See file LICENSE.CDDL provided in LibRaw distribution archive for details). 16 17 */ 18 19 #include "../../internal/libraw_cxx_defs.h" 20 dcraw_ppm_tiff_writer(const char * filename)21int LibRaw::dcraw_ppm_tiff_writer(const char *filename) 22 { 23 CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); 24 25 if (!imgdata.image) 26 return LIBRAW_OUT_OF_ORDER_CALL; 27 28 if (!filename) 29 return ENOENT; 30 FILE *f = NULL; 31 if (!strcmp(filename, "-")) 32 { 33 #ifdef LIBRAW_WIN32_CALLS 34 _setmode(_fileno(stdout), _O_BINARY); 35 #endif 36 f = stdout; 37 } 38 else 39 f = fopen(filename, "wb"); 40 41 if (!f) 42 return errno; 43 44 try 45 { 46 if (!libraw_internal_data.output_data.histogram) 47 { 48 libraw_internal_data.output_data.histogram = 49 (int(*)[LIBRAW_HISTOGRAM_SIZE])malloc( 50 sizeof(*libraw_internal_data.output_data.histogram) * 4); 51 merror(libraw_internal_data.output_data.histogram, 52 "LibRaw::dcraw_ppm_tiff_writer()"); 53 } 54 libraw_internal_data.internal_data.output = f; 55 write_ppm_tiff(); 56 SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); 57 libraw_internal_data.internal_data.output = NULL; 58 if (strcmp(filename, "-")) 59 fclose(f); 60 return 0; 61 } 62 catch (LibRaw_exceptions err) 63 { 64 if (strcmp(filename, "-")) 65 fclose(f); 66 EXCEPTION_HANDLER(err); 67 } 68 } 69