File indexing completed on 2025-01-05 03:57:09
0001 /* -*- C++ -*- 0002 * Copyright 2019-2021 LibRaw LLC (info@libraw.org) 0003 * 0004 LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder, 0005 dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net. 0006 LibRaw do not use RESTRICTED code from dcraw.c 0007 0008 LibRaw is free software; you can redistribute it and/or modify 0009 it under the terms of the one of two licenses as you choose: 0010 0011 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 0012 (See file LICENSE.LGPL provided in LibRaw distribution archive for details). 0013 0014 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 0015 (See file LICENSE.CDDL provided in LibRaw distribution archive for details). 0016 0017 */ 0018 0019 #include "../../internal/libraw_cxx_defs.h" 0020 0021 int LibRaw::dcraw_ppm_tiff_writer(const char *filename) 0022 { 0023 CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); 0024 0025 if (!imgdata.image) 0026 return LIBRAW_OUT_OF_ORDER_CALL; 0027 0028 if (!filename) 0029 return ENOENT; 0030 FILE *f = NULL; 0031 if (!strcmp(filename, "-")) 0032 { 0033 #ifdef LIBRAW_WIN32_CALLS 0034 _setmode(_fileno(stdout), _O_BINARY); 0035 #endif 0036 f = stdout; 0037 } 0038 else 0039 f = fopen(filename, "wb"); 0040 0041 if (!f) 0042 return errno; 0043 0044 try 0045 { 0046 if (!libraw_internal_data.output_data.histogram) 0047 { 0048 libraw_internal_data.output_data.histogram = 0049 (int(*)[LIBRAW_HISTOGRAM_SIZE])malloc( 0050 sizeof(*libraw_internal_data.output_data.histogram) * 4); 0051 } 0052 libraw_internal_data.internal_data.output = f; 0053 write_ppm_tiff(); 0054 SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); 0055 libraw_internal_data.internal_data.output = NULL; 0056 if (strcmp(filename, "-")) 0057 fclose(f); 0058 return 0; 0059 } 0060 catch (const LibRaw_exceptions& err) 0061 { 0062 if (strcmp(filename, "-")) 0063 fclose(f); 0064 EXCEPTION_HANDLER(err); 0065 } 0066 catch (const std::bad_alloc&) 0067 { 0068 if (strcmp(filename, "-")) 0069 fclose(f); 0070 EXCEPTION_HANDLER(LIBRAW_EXCEPTION_ALLOC); 0071 } 0072 0073 }