File indexing completed on 2025-01-05 03:56:53
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/dcraw_defs.h" 0020 0021 void LibRaw::unpacked_load_raw() 0022 { 0023 int row, col, bits = 0; 0024 while (1 << ++bits < (int)maximum) 0025 ; 0026 read_shorts(raw_image, raw_width * raw_height); 0027 fseek(ifp, -2, SEEK_CUR); // avoid EOF error 0028 if (maximum < 0xffff || load_flags) 0029 for (row = 0; row < raw_height; row++) 0030 { 0031 checkCancel(); 0032 for (col = 0; col < raw_width; col++) 0033 if ((RAW(row, col) >>= load_flags) >> bits && 0034 (unsigned)(row - top_margin) < height && 0035 (unsigned)(col - left_margin) < width) 0036 derror(); 0037 } 0038 } 0039 0040 void LibRaw::packed_load_raw() 0041 { 0042 int vbits = 0, bwide, rbits, bite, half, irow, row, col, val, i; 0043 UINT64 bitbuf = 0; 0044 0045 bwide = raw_width * tiff_bps / 8; 0046 bwide += bwide & load_flags >> 7; 0047 rbits = bwide * 8 - raw_width * tiff_bps; 0048 if (load_flags & 1) 0049 bwide = bwide * 16 / 15; 0050 bite = 8 + (load_flags & 24); 0051 half = (raw_height + 1) >> 1; 0052 for (irow = 0; irow < raw_height; irow++) 0053 { 0054 checkCancel(); 0055 row = irow; 0056 if (load_flags & 2 && (row = irow % half * 2 + irow / half) == 1 && 0057 load_flags & 4) 0058 { 0059 if (vbits = 0, tiff_compress) 0060 fseek(ifp, data_offset - (-half * bwide & -2048), SEEK_SET); 0061 else 0062 { 0063 fseek(ifp, 0, SEEK_END); 0064 fseek(ifp, ftell(ifp) >> 3 << 2, SEEK_SET); 0065 } 0066 } 0067 if (feof(ifp)) 0068 throw LIBRAW_EXCEPTION_IO_EOF; 0069 for (col = 0; col < raw_width; col++) 0070 { 0071 for (vbits -= tiff_bps; vbits < 0; vbits += bite) 0072 { 0073 bitbuf <<= bite; 0074 for (i = 0; i < bite; i += 8) 0075 bitbuf |= (unsigned(fgetc(ifp)) << i); 0076 } 0077 val = bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps); 0078 RAW(row, col ^ (load_flags >> 6 & 1)) = val; 0079 if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) && 0080 row < height + top_margin && col < width + left_margin) 0081 derror(); 0082 } 0083 vbits -= rbits; 0084 } 0085 } 0086 0087 void LibRaw::eight_bit_load_raw() 0088 { 0089 unsigned row, col; 0090 0091 std::vector<uchar> pixel(raw_width); 0092 for (row = 0; row < raw_height; row++) 0093 { 0094 checkCancel(); 0095 if (fread(pixel.data(), 1, raw_width, ifp) < raw_width) 0096 derror(); 0097 for (col = 0; col < raw_width; col++) 0098 RAW(row, col) = curve[pixel[col]]; 0099 } 0100 maximum = curve[0xff]; 0101 }