/src/libraw/src/write/tiff_writer.cpp
Line | Count | Source |
1 | | /* -*- C++ -*- |
2 | | * Copyright 2019-2025 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 | | |
21 | | int LibRaw::dcraw_ppm_tiff_writer(const char *filename) |
22 | 0 | { |
23 | 0 | CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); |
24 | | |
25 | 0 | if (!imgdata.image) |
26 | 0 | return LIBRAW_OUT_OF_ORDER_CALL; |
27 | | |
28 | 0 | if (!filename) |
29 | 0 | return ENOENT; |
30 | 0 | FILE *f = NULL; |
31 | 0 | if (!strcmp(filename, "-")) |
32 | 0 | { |
33 | | #ifdef LIBRAW_WIN32_CALLS |
34 | | _setmode(_fileno(stdout), _O_BINARY); |
35 | | #endif |
36 | 0 | f = stdout; |
37 | 0 | } |
38 | 0 | else |
39 | 0 | f = fopen(filename, "wb"); |
40 | |
|
41 | 0 | if (!f) |
42 | 0 | return errno; |
43 | | |
44 | 0 | try |
45 | 0 | { |
46 | 0 | if (!libraw_internal_data.output_data.histogram) |
47 | 0 | { |
48 | 0 | libraw_internal_data.output_data.histogram = |
49 | 0 | (int(*)[LIBRAW_HISTOGRAM_SIZE])malloc( |
50 | 0 | sizeof(*libraw_internal_data.output_data.histogram) * 4); |
51 | 0 | } |
52 | 0 | libraw_internal_data.internal_data.output = f; |
53 | 0 | write_ppm_tiff(); |
54 | 0 | SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); |
55 | 0 | libraw_internal_data.internal_data.output = NULL; |
56 | 0 | if (strcmp(filename, "-")) |
57 | 0 | fclose(f); |
58 | 0 | return 0; |
59 | 0 | } |
60 | 0 | catch (const LibRaw_exceptions& err) |
61 | 0 | { |
62 | 0 | if (strcmp(filename, "-")) |
63 | 0 | fclose(f); |
64 | 0 | EXCEPTION_HANDLER(err); |
65 | 0 | } |
66 | 0 | catch (const std::bad_alloc&) |
67 | 0 | { |
68 | 0 | if (strcmp(filename, "-")) |
69 | 0 | fclose(f); |
70 | 0 | EXCEPTION_HANDLER(LIBRAW_EXCEPTION_ALLOC); |
71 | 0 | } |
72 | |
|
73 | 0 | } |