/src/LibRaw/src/decoders/generic.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/dcraw_defs.h" |
20 | | |
21 | | void LibRaw::unpacked_load_raw() |
22 | 0 | { |
23 | 0 | int row, col, bits = 0; |
24 | 0 | while (1 << ++bits < (int)maximum) |
25 | 0 | ; |
26 | 0 | read_shorts(raw_image, raw_width * raw_height); |
27 | 0 | fseek(ifp, -2, SEEK_CUR); // avoid EOF error |
28 | 0 | if (maximum < 0xffff || load_flags) |
29 | 0 | for (row = 0; row < raw_height; row++) |
30 | 0 | { |
31 | 0 | checkCancel(); |
32 | 0 | for (col = 0; col < raw_width; col++) |
33 | 0 | if ((RAW(row, col) >>= load_flags) >> bits && |
34 | 0 | (unsigned)(row - top_margin) < height && |
35 | 0 | (unsigned)(col - left_margin) < width) |
36 | 0 | derror(); |
37 | 0 | } |
38 | 0 | } |
39 | | |
40 | | void LibRaw::packed_load_raw() |
41 | 0 | { |
42 | 0 | int vbits = 0, bwide, rbits, bite, half, irow, row, col, val, i; |
43 | 0 | UINT64 bitbuf = 0; |
44 | |
|
45 | 0 | bwide = raw_width * tiff_bps / 8; |
46 | 0 | bwide += bwide & load_flags >> 7; |
47 | 0 | rbits = bwide * 8 - raw_width * tiff_bps; |
48 | 0 | if (load_flags & 1) |
49 | 0 | bwide = bwide * 16 / 15; |
50 | 0 | bite = 8 + (load_flags & 24); |
51 | 0 | half = (raw_height + 1) >> 1; |
52 | 0 | for (irow = 0; irow < raw_height; irow++) |
53 | 0 | { |
54 | 0 | checkCancel(); |
55 | 0 | row = irow; |
56 | 0 | if (load_flags & 2 && (row = irow % half * 2 + irow / half) == 1 && |
57 | 0 | load_flags & 4) |
58 | 0 | { |
59 | 0 | if (vbits = 0, tiff_compress) |
60 | 0 | fseek(ifp, data_offset - (-half * bwide & -2048), SEEK_SET); |
61 | 0 | else |
62 | 0 | { |
63 | 0 | fseek(ifp, 0, SEEK_END); |
64 | 0 | fseek(ifp, ftell(ifp) >> 3 << 2, SEEK_SET); |
65 | 0 | } |
66 | 0 | } |
67 | 0 | if (feof(ifp)) |
68 | 0 | throw LIBRAW_EXCEPTION_IO_EOF; |
69 | 0 | for (col = 0; col < raw_width; col++) |
70 | 0 | { |
71 | 0 | for (vbits -= tiff_bps; vbits < 0; vbits += bite) |
72 | 0 | { |
73 | 0 | bitbuf <<= bite; |
74 | 0 | for (i = 0; i < bite; i += 8) |
75 | 0 | bitbuf |= (unsigned(fgetc(ifp)) << i); |
76 | 0 | } |
77 | 0 | val = int((bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps)) & 0x7fffffff); |
78 | 0 | RAW(row, col ^ (load_flags >> 6 & 1)) = val; |
79 | 0 | if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) && |
80 | 0 | row < height + top_margin && col < width + left_margin) |
81 | 0 | derror(); |
82 | 0 | } |
83 | 0 | vbits -= rbits; |
84 | 0 | } |
85 | 0 | } |
86 | | |
87 | | void LibRaw::eight_bit_load_raw() |
88 | 0 | { |
89 | 0 | unsigned row, col; |
90 | |
|
91 | 0 | std::vector<uchar> pixel(raw_width); |
92 | 0 | for (row = 0; row < raw_height; row++) |
93 | 0 | { |
94 | 0 | checkCancel(); |
95 | 0 | if (fread(pixel.data(), 1, raw_width, ifp) < raw_width) |
96 | 0 | derror(); |
97 | 0 | for (col = 0; col < raw_width; col++) |
98 | 0 | RAW(row, col) = curve[pixel[col]]; |
99 | 0 | } |
100 | 0 | maximum = curve[0xff]; |
101 | 0 | } |