diff --git a/rtengine/libraw/Changelog.txt b/rtengine/libraw/Changelog.txt index 50fb003b5..d38ca49cb 100644 --- a/rtengine/libraw/Changelog.txt +++ b/rtengine/libraw/Changelog.txt @@ -1,3 +1,128 @@ +2025-02-11 Alex Tutubalin + +LibRaw-snapshot-202502 + + * Camera format support: + 1) OM System 14-bit high-resolution files. + Note: the new decoder supports old (12-bit) Olympus/OM-System files + too and slightly faster (about 5%), so the old one is removed. + 2) Nikon NEFX (4/8/16/32 shots in PixelShift mode merged via Nikon software) + + * Camera support + Canon EOS R5 C + Hasselblad CFV-50c, CFV-100c + Leica SL3 + Nikon Z f (standard/lossless compression only) + Olympus/OM System OM-1 Mark II, TG-7 + Pentax KF, K III Monochrome + Samsung S23+, S23 Ultra + Sony A9-III, ILX-LR1 + + * API Changes/improvements + - Exif callback is called from CR3 parser before calling parse_makernotes() + parameters are the same as usual, except tag parameter value. + tag values: + (0x70000 | 0x927c) - if called from CMT3 tag + (__type << 20) | 0x80000 | 0x927c - if called from CTMD record with type __type + + - Exif callback is called for Sony SR2 tag with tag parameter set to 0x60000 | tagID + + - Makernotes callback implemented for TIFF-like (IFD structure makernotes) + Callback is very similar to exif_callback. + To set callback use LibRaw::set_makernotes_handler(exif_parser_callback cb, void *data) + Callback is called (if set) with tag value set to (uptag << 16)|makernotes_tag + where uptag is + EXIF tag: if called from EXIF makernotes parser + 0: if called from CR3 metadata parser + tag-ID if parse_makernotes() is called from some specific tag context (see parse_makernotes calls in source code). + + - New metadata field makernotes.pentax.DynamicRangeExpansion[4] + if DynamicRangeExpansion[1] is non-zero, DynamicRangeExpansion[0] should be added + to BaselineExposure + + - New API call (static) int LibRaw::simplify_make_model(unsigned * mkindex, char *mkbuf, unsigned mkbuf_size, char *modelbuf, unsigned modelbuf_size): + This call can be used to simplify/standardize vendor name/model received + from external source (e.g. EXIF block in JPEG file). + mkindex: pointer to received maker index (LibRaw_CAMERAMAKER_...) + mkbuf, mkbuf_size: buffer with make string, buffer size + modelbuf, modelbuf_size: buffer with model string. + simplify_make_model(..) simplifies/re-writes vendor name/model in place, in provided buffers. + return values: + 0 - mkindex is set (if non-null pointer provided), data simplified; + 1 - mkindex is not set, while some data processing is done; + -1 - incorrect parameters; + + - All file offsets are 64-bit now; + Note: data callback signature has changed + + - New LibRaw_abstract_datastream (and derived classes) methods: + bool is_buffered() - returns current buffering mode (if implemented); + void buffering_on() - turns buffering on. + These methods complement the (existing) buffering_off() method + + - New bits in imgdata.process_warnings: + LIBRAW_WARN_DNG_NOT_PROCESSED - RAW file was passed to DNG SDK, but not processed. + LIBRAW_WARN_DNG_NOT_PARSED - DNG parse error or non-valid DNG at valid_for_dngsdk() stage + + - New compile-time define: LIBRAW_MAX_CR3_RAW_FILE_SIZE + Default: value of LIBRAW_MAX_NONDNG_RAW_FILE_SIZE + CR3 file size is limited by 4GB (max MP4 container size), so it may be needed + to set the limit above non-DNG 2GB file size limit. + + * Minor improvements + + - Adobe DNG SDK 1.7.1 compatibility + + - restored compatibility with pre-1.7 Adobe DNG SDK + + - RawSpeed1/3: do not pass files larger then 2GB + + - Jpeg XL preview file writer + + - Jpeg XL preview support in simple_dcraw -E/-e + + - DNG 1.7 JpegXL DNG/GoPro DNG: do not refuse files at open_file() if LibRaw is not built with DNG SDK/GoPro SDK + Note: LibRaw::get_decoder_info() will return decoder flag bit set to LIBRAW_DECODER_UNSUPPORTED_FORMAT if + LibRaw is not built with corresponding SDK. + + - All implicit type conversion *excluding INT64<=>int/uint* conversions are made explicit + to remove C++ compiler type conversion warnings. + + - libraw_dng_stream: underlying LibRaw_abstract_datastream buffering restored in + destructor call. + + * Bug/problem fixes + * Fix for PanasonicV8 decoder compile with OpenMP + * Fix for incorrect 32-bit shift in Pana8 decoder generated by gcc11+ + * DNG SDK Integration: clear imdata.color.linear_max[] if Stage3 opcodes are applied. + * Fixed possible buffer overrun in LibRaw::remove_trailing_spaces call + * CR3 decoder: workaround for possible incorrect generation of 64-bit code + * Improved Sony metadata processing + * fixed possible static table read overrun (if specially crafted image + data passed to LibRaw) + * Fix for monochrome DNG files compressed as 2-color component LJPEG + * Fixed integer overflow in largest DNG frame selection code + * Additional out-of range checks to better handle specially crafted files + * Prevent out-of-buffer access in phase_one_correct() + * Prevent one-off read in Fuji WB table parsing + * Prevent one-off read in phase_one_correct() + * Do not apply Canon metadata crop values to DNG files + * Adjust profile_length to allocated data size. + +2024-11-30 Alex Tutubalin + + * H265 (Canon) and JPEG-XL thumbnail support for dcraw_make_mem_thumb + Note: libraw_processed_image_t.type is set to LIBRAW_IMAGE_H265 or + LIBRAW_IMAGE_JPEGXL respectively + +2024-09-18 Alex Tutubalin + * Fixed possible buffer overrun in old panasonic decoder + * Most small buffer allocations: malloc changed to calloc to prevent + uninitialized heap data leaks + * Large buffer allocation (RAW backing store, thumbnails store): + If LIBRAW_CALLOC_RAWSTORE is defined on build: large buffers will be + allocated via calloc + 2024-03-30 Alex Tutubalin LibRaw-snapshot-202403 @@ -66,6 +191,10 @@ * New possible bit in imgdata.process_warnings: LIBRAW_WARN_VENDOR_CROP_SUGGESTED If set: unknown/untested RAW image frame size passed to LibRaw, cropping may be incorrect. It is suggested to use LibRaw::adjust_to_raw_inset_crop(1) for vendor specified crop. + + * LibRaw::adjust_to_raw_inset_crop exposed via C-API call: + libraw_adjust_to_raw_inset_crop(libraw_data_t *lr, unsigned mask, float maxcrop); + Note: default maxcrop value for C++ API is 0.55f * Better handling of DNG RAW Previews with Stage2 opcodes diff --git a/rtengine/libraw/Makefile.am b/rtengine/libraw/Makefile.am index c5bd647da..922ff4311 100644 --- a/rtengine/libraw/Makefile.am +++ b/rtengine/libraw/Makefile.am @@ -33,6 +33,7 @@ lib_libraw_a_SOURCES = src/libraw_c_api.cpp \ src/decoders/crx.cpp src/decoders/pana8.cpp src/decoders/decoders_dcraw.cpp \ src/decoders/sonycc.cpp src/decompressors/losslessjpeg.cpp \ src/decoders/decoders_libraw_dcrdefs.cpp \ + src/decoders/olympus14.cpp \ src/decoders/decoders_libraw.cpp src/decoders/dng.cpp \ src/decoders/fp_dng.cpp src/decoders/fuji_compressed.cpp \ src/decoders/generic.cpp src/decoders/kodak_decoders.cpp \ diff --git a/rtengine/libraw/Makefile.devel b/rtengine/libraw/Makefile.devel index 73da195e3..ca0f6b620 100644 --- a/rtengine/libraw/Makefile.devel +++ b/rtengine/libraw/Makefile.devel @@ -9,7 +9,7 @@ CXX=clang++ LDADD+=-lz CFLAGS=-DLIBRAW_USE_AUTOPTR -CFLAGS+= -g -I. -pedantic -Wno-long-long -Wno-overflow -O3 +CFLAGS+= -g -I. -pedantic -Wno-long-long -Wno-overflow -O3 -Wall # macOS dual arch # CFLAGS+=-arch x86_64 -arch arm64 @@ -54,7 +54,7 @@ HEADERS=libraw/libraw.h libraw/libraw_alloc.h libraw/libraw_const.h \ LIB_OBJECTS= object/libraw_datastream.o object/libraw_c_api.o \ object/cameralist.o object/fuji_compressed.o \ - object/crx.o object/pana8.o object/fp_dng.o object/decoders_libraw.o \ + object/crx.o object/pana8.o object/olympus14.o object/fp_dng.o object/decoders_libraw.o \ object/sonycc.o object/losslessjpeg.o \ object/unpack.o object/unpack_thumb.o \ object/rawspeed_glue.o object/dngsdk_glue.o \ @@ -88,7 +88,7 @@ LIB_OBJECTS= object/libraw_datastream.o object/libraw_c_api.o \ LIB_MT_OBJECTS= object/libraw_datastream.mt.o object/libraw_c_api.mt.o \ object/cameralist.mt.o object/fuji_compressed.mt.o \ - object/crx.mt.o object/pana8.mt.o object/fp_dng.mt.o \ + object/crx.mt.o object/pana8.mt.o object/olympus14.mt.o object/fp_dng.mt.o \ object/sonycc.mt.o object/losslessjpeg.mt.o \ object/decoders_libraw.mt.o \ object/unpack.mt.o object/unpack_thumb.mt.o \ @@ -209,6 +209,10 @@ object/crx.o: src/decoders/crx.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/crx.o src/decoders/crx.cpp object/crx.mt.o: src/decoders/crx.cpp $(HEADERS) ${CXX} -c ${CFLAGS} -o object/crx.mt.o src/decoders/crx.cpp +object/olympus14.o: src/decoders/olympus14.cpp + ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/olympus14.o src/decoders/olympus14.cpp +object/olympus14.mt.o: src/decoders/olympus14.cpp $(HEADERS) + ${CXX} -c ${CFLAGS} -o object/olympus14.mt.o src/decoders/olympus14.cpp object/pana8.o: src/decoders/pana8.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/pana8.o src/decoders/pana8.cpp object/pana8.mt.o: src/decoders/pana8.cpp $(HEADERS) diff --git a/rtengine/libraw/Makefile.devel.nopp b/rtengine/libraw/Makefile.devel.nopp index e84d1e9d4..7acf0ea7e 100644 --- a/rtengine/libraw/Makefile.devel.nopp +++ b/rtengine/libraw/Makefile.devel.nopp @@ -38,6 +38,7 @@ CSTFLAGS=$(CFLAGS) -DLIBRAW_NOTHREADS LIB_OBJECTS= object/libraw_datastream.o \ object/cameralist.o object/fuji_compressed.o \ object/crx.o object/pana8.o object/fp_dng.o object/decoders_libraw.o \ + object/olympus14.o \ object/sonycc.o object/losslessjpeg.o \ object/unpack.o object/unpack_thumb.o \ object/rawspeed_glue.o object/dngsdk_glue.o \ @@ -108,6 +109,8 @@ object/crx.o: src/decoders/crx.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/crx.o src/decoders/crx.cpp object/pana8.o: src/decoders/pana8.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/pana8.o src/decoders/pana8.cpp +object/olympus14.o: src/decoders/olympus14.cpp + ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/olympus14.o src/decoders/olympus14.cpp object/sonycc.o: src/decoders/sonycc.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/sonycc.o src/decoders/sonycc.cpp object/losslessjpeg.o: src/decompressors/losslessjpeg.cpp diff --git a/rtengine/libraw/Makefile.devel.noppr2i b/rtengine/libraw/Makefile.devel.noppr2i index 7fb9bc71d..40391a4c2 100644 --- a/rtengine/libraw/Makefile.devel.noppr2i +++ b/rtengine/libraw/Makefile.devel.noppr2i @@ -37,6 +37,7 @@ CSTFLAGS=$(CFLAGS) -DLIBRAW_NOTHREADS LIB_OBJECTS= object/libraw_datastream.o \ object/cameralist.o object/fuji_compressed.o \ object/crx.o object/pana8.o object/fp_dng.o object/decoders_libraw.o \ + object/olympus14.o \ object/sonycc.o object/losslessjpeg.o \ object/unpack.o object/unpack_thumb.o \ object/rawspeed_glue.o object/dngsdk_glue.o \ @@ -99,6 +100,8 @@ object/crx.o: src/decoders/crx.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/crx.o src/decoders/crx.cpp object/pana8.o: src/decoders/pana8.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/pana8.o src/decoders/pana8.cpp +object/olympus14.o: src/decoders/olympus14.cpp + ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/olympus14.o src/decoders/olympus14.cpp object/sonycc.o: src/decoders/sonycc.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/sonycc.o src/decoders/sonycc.cpp object/losslessjpeg.o: src/decompressors/losslessjpeg.cpp diff --git a/rtengine/libraw/Makefile.dist b/rtengine/libraw/Makefile.dist index 4fd4ba989..2fd4da6a5 100644 --- a/rtengine/libraw/Makefile.dist +++ b/rtengine/libraw/Makefile.dist @@ -44,6 +44,7 @@ CSTFLAGS=$(CFLAGS) -DLIBRAW_NOTHREADS LIB_OBJECTS= object/libraw_datastream.o object/libraw_c_api.o \ object/cameralist.o object/fuji_compressed.o \ object/crx.o object/pana8.o object/fp_dng.o object/decoders_libraw.o \ + object/olympus14.o \ object/sonycc.o object/losslessjpeg.o \ object/unpack.o object/unpack_thumb.o \ object/rawspeed_glue.o object/dngsdk_glue.o \ @@ -78,6 +79,7 @@ LIB_OBJECTS= object/libraw_datastream.o object/libraw_c_api.o \ LIB_MT_OBJECTS= object/libraw_datastream.mt.o object/libraw_c_api.mt.o \ object/cameralist.mt.o object/fuji_compressed.mt.o \ object/crx.mt.o object/pana8.mt.o object/fp_dng.mt.o object/decoders_libraw.mt.o \ + object/olympus14.mt.o \ object/sonycc.mt.o object/losslessjpeg.mt.o \ object/unpack.mt.o object/unpack_thumb.mt.o \ object/rawspeed_glue.mt.o object/dngsdk_glue.mt.o \ @@ -217,6 +219,10 @@ object/pana8.o: src/decoders/pana8.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/pana8.o src/decoders/pana8.cpp object/pana8.mt.o: src/decoders/pana8.cpp $(HEADERS) ${CXX} -c ${CFLAGS} -o object/pana8.mt.o src/decoders/pana8.cpp +object/olympus14.o: src/decoders/olympus14.cpp + ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/olympus14.o src/decoders/olympus14.cpp +object/olympus14.mt.o: src/decoders/olympus14.cpp $(HEADERS) + ${CXX} -c ${CFLAGS} -o object/olympus14.mt.o src/decoders/olympus14.cpp object/sonycc.o: src/decoders/sonycc.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/sonycc.o src/decoders/sonycc.cpp object/sonycc.mt.o: src/decoders/sonycc.cpp $(HEADERS) diff --git a/rtengine/libraw/Makefile.mingw b/rtengine/libraw/Makefile.mingw index e9172e10f..e9d90bd4b 100644 --- a/rtengine/libraw/Makefile.mingw +++ b/rtengine/libraw/Makefile.mingw @@ -35,6 +35,7 @@ CSTFLAGS=$(CFLAGS) -DLIBRAW_NOTHREADS LIB_OBJECTS= object/libraw_datastream.o object/libraw_c_api.o \ object/cameralist.o object/fuji_compressed.o \ object/crx.o object/pana8.o object/fp_dng.o object/decoders_libraw.o \ + object/olympus14.o \ object/losslessjpeg.o object/sonycc.o \ object/unpack.o object/unpack_thumb.o \ object/rawspeed_glue.o object/dngsdk_glue.o \ @@ -152,6 +153,8 @@ object/crx.o: src/decoders/crx.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/crx.o src/decoders/crx.cpp object/pana8.o: src/decoders/pana8.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/pana8.o src/decoders/pana8.cpp +object/olympus14.o: src/decoders/olympus14.cpp + ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/olympus14.o src/decoders/olympus14.cpp object/sonycc.o: src/decoders/sonycc.cpp ${CXX} -c -DLIBRAW_NOTHREADS ${CFLAGS} -o object/sonycc.o src/decoders/sonycc.cpp object/losslessjpeg.o: src/decompressors/losslessjpeg.cpp diff --git a/rtengine/libraw/Makefile.msvc b/rtengine/libraw/Makefile.msvc index 80bfcad05..d965f58a6 100644 --- a/rtengine/libraw/Makefile.msvc +++ b/rtengine/libraw/Makefile.msvc @@ -42,6 +42,7 @@ $(LIBDLL): $(DLL) LIB_OBJECTS= object\libraw_datastream_st.obj object\libraw_c_api_st.obj \ object\cameralist_st.obj object\fuji_compressed_st.obj \ object\crx_st.obj object\pana8_st.obj object\fp_dng_st.obj object\decoders_libraw_st.obj \ + object\olympus14_st.obj \ object\sonycc_st.obj object\losslessjpeg_st.obj \ object\unpack_st.obj object\unpack_thumb_st.obj \ object\rawspeed_glue_st.obj object\dngsdk_glue_st.obj \ @@ -76,6 +77,7 @@ LIB_OBJECTS= object\libraw_datastream_st.obj object\libraw_c_api_st.obj \ DLL_OBJECTS= object\libraw_datastream.obj object\libraw_c_api.obj \ object\cameralist.obj object\fuji_compressed.obj \ object\crx.obj object\pana8.obj object\fp_dng.obj object\decoders_libraw.obj \ + object\olympus14.obj \ object\sonycc.obj object\losslessjpeg.obj \ object\unpack.obj object\unpack_thumb.obj \ object\rawspeed_glue.obj object\dngsdk_glue.obj \ @@ -167,14 +169,14 @@ $(DLL): $(DLL_OBJECTS) # LIBRARY BUILD $(LIBSTATIC): $(LIB_OBJECTS) - -del /f $(LIBSTATIC) + -del /f $(LIBSTATIC) lib /OUT:$(LIBSTATIC) /LTCG $(LIB_OBJECTS) # clean clean: -del $(LIBSTATIC) $(LIBDLL) lib\*.exp -del $(LIB_OBJECTS) $(DLL_OBJECTS) - -del object\*.o + -del object\*.o -del $(DLL) $(SAMPLES) # OBJ generation rules @@ -196,6 +198,12 @@ object\pana8_st.obj: src\decoders\pana8.cpp object\pana8.obj: src\decoders\pana8.cpp $(CC) $(COPT) /DLIBRAW_BUILDLIB /Fo"object\\pana8.obj" /c src\decoders\pana8.cpp +object\olympus14_st.obj: src\decoders\olympus14.cpp + $(CC) $(COPT) /DLIBRAW_NODLL /DLIBRAW_BUILDLIB /Fo"object\\olympus14_st.obj" /c src\decoders\olympus14.cpp + +object\olympus14.obj: src\decoders\olympus14.cpp + $(CC) $(COPT) /DLIBRAW_BUILDLIB /Fo"object\\olympus14.obj" /c src\decoders\olympus14.cpp + object\sonycc_st.obj: src\decoders\sonycc.cpp $(CC) $(COPT) /DLIBRAW_NODLL /DLIBRAW_BUILDLIB /Fo"object\\sonycc_st.obj" /c src\decoders\sonycc.cpp diff --git a/rtengine/libraw/README.DNGSDK.txt b/rtengine/libraw/README.DNGSDK.txt index 00f6ce497..966545211 100644 --- a/rtengine/libraw/README.DNGSDK.txt +++ b/rtengine/libraw/README.DNGSDK.txt @@ -16,9 +16,9 @@ include/linker path settings to point to DNG SDK's include and library folders. DNG SDK Version compatibility: - - DNG SDK 1.6 and 1.7 are tested with LibRaw newer then 0.21 + - DNG SDK 1.6 and 1.7/1.7.1 are tested with LibRaw newer then 0.21 If you want to use LibRaw with Modern DNG files please use: - -- DNG SDK 1.7 for JpegXL compressed files + -- DNG SDK 1.7/1.7.1 for JpegXL compressed files -- DNG SDK 1.6+ to access Enhanced DNG frames - DNG SDK 1.5 may work too, but have not tested w/ LibRaw. diff --git a/rtengine/libraw/README.md b/rtengine/libraw/README.md index 8f00255f7..39978c875 100644 --- a/rtengine/libraw/README.md +++ b/rtengine/libraw/README.md @@ -16,13 +16,13 @@ The library is intended for use with programs that work with RAW files, such as: Using the LibRaw library allows one to focus on the substantive part of processing the data contained in RAW files, without getting distracted by the wide variety of RAW file and metadata formats, compression algorithms, etc. -The library�s development is focused on: +The library's development is focused on: * Support for new cameras and formats * Improving extraction of metadata necessary for RAW processing * Providing an interface for reading other types of metadata. -Additionally, the LibRaw library offers some basic RAW conversion, intended for cases when such conversion is not the main function of the LibRaw-using application _(for example: a viewer for 500+ graphic file formats, including RAW)._ These methods are inherited from the Dave Coffin�s dcraw.c utility _(see below the �Project history� section);_ their further development is not currently planned, because we do not consider production-quality rendering to be in the scope of LibRaw�s functionality _(the methods are retained for compatibility with prior versions and for rapid-fire testing of RAW support and other aspects)._ +Additionally, the LibRaw library offers some basic RAW conversion, intended for cases when such conversion is not the main function of the LibRaw-using application _(for example: a viewer for 500+ graphic file formats, including RAW)._ These methods are inherited from the Dave Coffin's dcraw.c utility _(see below the "Project history" section);_ their further development is not currently planned, because we do not consider production-quality rendering to be in the scope of LibRaw's functionality _(the methods are retained for compatibility with prior versions and for rapid-fire testing of RAW support and other aspects)._ ## Licensing @@ -35,7 +35,7 @@ The LibRaw library is distributed free of charge and with open-source code subje To use the LibRaw library in an application, you can choose the license that better suits your needs. -If you modify/add/improve the LibRaw source code, then your patches can only be included into the library�s official source code if you agree to it being distributed under both of the above licenses. +If you modify/add/improve the LibRaw source code, then your patches can only be included into the library's official source code if you agree to it being distributed under both of the above licenses. We do not guarantee that the licensing will not change in future versions of LibRaw. @@ -44,18 +44,18 @@ We do not guarantee that the licensing will not change in future versions of Lib ### Major/minor releases -* Major releases _(for example, 0.20)_ are published once every year and a half to two years. +* Major releases _(for example, 0.20)_ are published once every year and a half to three years. * When the first public beta version of a major release is published, the list of supported cameras and formats is frozen; we try (but do not guarantee) to freeze the API/ABI as well. * The public major release contains only that code which has been sufficiently tested on a wide user base (including in our commercial products). Something very new may not be included in it (but it will probably be included in a public snapshot, see below). -* Minor updates _(0.20.1, 0.20.2�)_ do not change the API/ABI and new cameras are not added; generally they are just bugfixes. +* Minor updates _(0.20.1, 0.20.2)_ do not change the API/ABI and new cameras are not added; generally they are just bugfixes. * Bugfixes are published as soon as possible in the [public GitHub repository](https://github.com/LibRaw/LibRaw). * Minor version increments: these are generally published if a serious error has been fixed, one that potentially affects many library users (for example, a possible stack overflow). ### Public snapshots -* Public snapshots are published every 7-9 months in the [public GitHub repository](https://github.com/LibRaw/LibRaw). +* Public snapshots are published every 9-18 months in the [public GitHub repository](https://github.com/LibRaw/LibRaw). * These versions contain support for new cameras that was added after the previous major release. The API/ABI of public snapshots is not frozen, and may change. -* Public snapshots are always tested on a fairly large user base, and may be considered suitable for use in programs that work with files with known origins (that is, recorded directly by users� digital cameras). However, public snapshots should not be considered sufficiently reliable for processing files that are specially constructed for vulnerability testing; that is, they should not be used in public services that allow for anonymous processing of files of unknown provenance +* Public snapshots are always tested on a fairly large user base, and may be considered suitable for use in programs that work with files with known origins (that is, recorded directly by users' digital cameras). However, public snapshots should not be considered sufficiently reliable for processing files that are specially constructed for vulnerability testing; that is, they should not be used in public services that allow for anonymous processing of files of unknown provenance ## Support and feedback @@ -85,7 +85,7 @@ The code that implements rendering of RAW to RGB is inherited from dcraw.c, with In the early-to-mid 2010s, we gladly expanded post-processing implemented in LibRaw, and readily accepted the input of outside developers (new/improved methods for debayerization/demosaicing, systematic noise reduction etc.). -Experience has shown that the LibRaw team cannot support this added code on their own, while contributors do not provide support and development of the code they suggest and it ends up abandoned. As such, the majority of the modifications that are implemented by people outside the LibRaw team was moved to the [LibRaw-demosaic-pack-�.](https://github.com/LibRaw?tab=repositories), where they remain in their original form (but these projects are still present in our GitHub). +Experience has shown that the LibRaw team cannot support this added code on their own, while contributors do not provide support and development of the code they suggest and it ends up abandoned. As such, the majority of the modifications that are implemented by people outside the LibRaw team was moved to the [LibRaw-demosaic-pack-...](https://github.com/LibRaw?tab=repositories), where they remain in their original form (but these projects are still present in our GitHub). Thus, we arrive at our current status, described in the first part of this text. @@ -93,7 +93,7 @@ Thus, we arrive at our current status, described in the first part of this text. Copyright (C) 2008-2024 LibRaw LLC -LibRaw uses code from Dave Coffin�s dcraw.c utility (without RESTRICTED/GPL2 code): +LibRaw uses code from Dave Coffin's dcraw.c utility (without RESTRICTED/GPL2 code): Copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net @@ -101,6 +101,6 @@ LibRaw uses DCB demosaic code by Jaceck Gozdz distributed under BSD license: Copyright (C) 2010, Jacek Gozdz (mailto:cuniek@kft.umcs.lublin.pl) -LibRaw uses Roland Karlsson�s X3F tools source code, licensed under BSD license: +LibRaw uses Roland Karlsson's X3F tools source code, licensed under BSD license: Copyright (c) 2010, Roland Karlsson (roland@proxel.se) \ No newline at end of file diff --git a/rtengine/libraw/buildfiles/libraw.pro b/rtengine/libraw/buildfiles/libraw.pro index 786123f13..d6d10f2e0 100644 --- a/rtengine/libraw/buildfiles/libraw.pro +++ b/rtengine/libraw/buildfiles/libraw.pro @@ -30,6 +30,7 @@ SOURCES+= ../src/libraw_datastream.cpp ../src/decoders/canon_600.cpp \ ../src/decoders/crx.cpp ../src/decoders/decoders_dcraw.cpp \ ../src/decoders/decoders_libraw_dcrdefs.cpp ../src/decoders/pana8.cpp \ ../src/decompressors/losslessjpeg.cpp ../src/decoders/sonycc.cpp \ + ../src/decoders/olympus14.cpp \ ../src/decoders/decoders_libraw.cpp ../src/decoders/dng.cpp \ ../src/decoders/fp_dng.cpp ../src/decoders/fuji_compressed.cpp \ ../src/decoders/generic.cpp ../src/decoders/kodak_decoders.cpp \ diff --git a/rtengine/libraw/buildfiles/libraw.vcxproj b/rtengine/libraw/buildfiles/libraw.vcxproj index 9d3277818..8fa229012 100644 --- a/rtengine/libraw/buildfiles/libraw.vcxproj +++ b/rtengine/libraw/buildfiles/libraw.vcxproj @@ -150,6 +150,7 @@ + @@ -234,4 +235,4 @@ - \ No newline at end of file + diff --git a/rtengine/libraw/doc/API-datastruct.html b/rtengine/libraw/doc/API-datastruct.html index 1907b36b5..14a0f7a74 100644 --- a/rtengine/libraw/doc/API-datastruct.html +++ b/rtengine/libraw/doc/API-datastruct.html @@ -242,7 +242,7 @@ black has been subtracted at the unpacking stage or by the camera itself), calculated at the unpacking stage, read from the RAW file, or hardcoded. -
unsigned cblack[4102];
+
unsigned cblack[4104];
Per-channel black level correction. First 4 values are per-channel correction, next two are black level pattern block size, than cblack[4]*cblack[5] correction values (for indexes diff --git a/rtengine/libraw/internal/libraw_cameraids.h b/rtengine/libraw/internal/libraw_cameraids.h index 419bdeaad..ab25dc544 100644 --- a/rtengine/libraw/internal/libraw_cameraids.h +++ b/rtengine/libraw/internal/libraw_cameraids.h @@ -27,6 +27,9 @@ it under the terms of the one of two licenses as you choose: #define CanonID_EOS_M5 0x03940000ULL #define CanonID_EOS_M100 0x03980000ULL #define CanonID_EOS_M6 0x04070000ULL + +#define CanonID_EOS_R5_C (0x40000000ULL + 0x218ULL) + #define CanonID_EOS_1D (0x80000000ULL + 0x001ULL) #define CanonID_EOS_1Ds (0x80000000ULL + 0x167ULL) #define CanonID_EOS_10D (0x80000000ULL + 0x168ULL) @@ -118,6 +121,7 @@ it under the terms of the one of two licenses as you choose: #define OlyID_TG_4 OlyID_str2hex("D4586") #define OlyID_TG_5 OlyID_str2hex("D4593") #define OlyID_TG_6 OlyID_str2hex("D4603") +#define OlyID_TG_7 OlyID_str2hex("D4605") #define OlyID_E_10 OlyID_str2hex("D4842") #define OlyID_AIR_A01 OlyID_str2hex("K0055") #define OlyID_NORMA OlyID_str2hex("NORMA") @@ -165,6 +169,7 @@ it under the terms of the one of two licenses as you choose: #define OlyID_E_P7 OlyID_str2hex("S0093") #define OlyID_OM_1 OlyID_str2hex("S0095") #define OlyID_OM_5 OlyID_str2hex("S0101") +#define OlyID_OM_1_Mark_II OlyID_str2hex("S0121") #define OlyID_C_3030Z OlyID_str2hex("SX351") #define OlyID_C_5050Z OlyID_str2hex("SX558") #define OlyID_C_350Z OlyID_str2hex("SX751") @@ -229,6 +234,8 @@ it under the terms of the one of two licenses as you choose: #define PentaxID_K_1_Mark_II 0x13240ULL #define PentaxID_K_3_III 0x13254ULL #define PentaxID_GR_IIIx 0x1329aULL +#define PentaxID_KF 0x132b8ULL +#define PentaxID_K_3_III_Mono 0x132d6ULL #define SonyID_DSC_R1 0x002ULL #define SonyID_DSLR_A100 0x100ULL @@ -323,12 +330,13 @@ it under the terms of the one of two licenses as you choose: #define SonyID_ILCE_7RM3A 0x182ULL #define SonyID_ILCE_7RM4A 0x183ULL #define SonyID_ILCE_7M4 0x184ULL -// #define SonyID_ZV_1F 0x185ULL // Sony ZV-1F doesn't save raw #define SonyID_ILCE_7RM5 0x186ULL #define SonyID_ILME_FX30 0x187ULL +#define SonyID_ILCE_9M3 0x188ULL #define SonyID_ZV_E1 0x189ULL #define SonyID_ILCE_6700 0x18aULL #define SonyID_ZV_1M2 0x18bULL #define SonyID_ILCE_7CR 0x18cULL #define SonyID_ILCE_7CM2 0x18dULL +#define SonyID_ILX_LR1 0x18eULL #endif diff --git a/rtengine/libraw/internal/libraw_checked_buffer.h b/rtengine/libraw/internal/libraw_checked_buffer.h index a5de6fd99..032fb7b93 100644 --- a/rtengine/libraw/internal/libraw_checked_buffer.h +++ b/rtengine/libraw/internal/libraw_checked_buffer.h @@ -10,10 +10,13 @@ public: checked_buffer_t(short ord, int size); checked_buffer_t(short ord, unsigned char *dd, int ss); ushort sget2(int offset); + ushort sget2LL(INT64 offset) { return sget2(int(offset)); } void checkoffset(int off); unsigned char operator[](int idx); unsigned sget4(int offset); + unsigned sget4LL(INT64 offset) { return sget4(int(offset)); } double sgetreal(int type, int offset); + float sgetrealf(int type, int offset) { return float(sgetreal(type, offset)); } unsigned char *data() { return _data; } int tiff_sget(unsigned save, INT64 *tag_offset, unsigned *tag_id, unsigned *tag_type, INT64 *tag_dataoffset, diff --git a/rtengine/libraw/internal/libraw_cxx_defs.h b/rtengine/libraw/internal/libraw_cxx_defs.h index d249414c0..0ef9314dc 100644 --- a/rtengine/libraw/internal/libraw_cxx_defs.h +++ b/rtengine/libraw/internal/libraw_cxx_defs.h @@ -44,6 +44,10 @@ void *make_camera_metadata(); void clear_camera_metadata(void*); void clear_rawspeed_decoder(void*); #endif +#ifdef USE_DNGSDK +void clear_dng_negative(void *); +void clear_dng_image(void*); +#endif #define P1 imgdata.idata diff --git a/rtengine/libraw/internal/libraw_internal_funcs.h b/rtengine/libraw/internal/libraw_internal_funcs.h index ebb3efcb1..e3c43fe21 100644 --- a/rtengine/libraw/internal/libraw_internal_funcs.h +++ b/rtengine/libraw/internal/libraw_internal_funcs.h @@ -51,8 +51,8 @@ it under the terms of the one of two licenses as you choose: static libraw_static_table_t Sony_SR2_wb_list; static libraw_static_table_t Sony_SR2_wb_list1; /* */ - int find_ifd_by_offset(int ); - void libraw_swab(void *arr, size_t len); + int find_ifd_by_offset(INT64 ); + void libraw_swab(void *arr, int len); ushort sget2 (uchar *s); ushort sget2Rev(uchar *s); libraw_area_t get_CanonArea(); @@ -70,24 +70,24 @@ it under the terms of the one of two licenses as you choose: void parseCanonMakernotes (unsigned tag, unsigned type, unsigned len, unsigned dng_writer); void processNikonLensData (uchar *LensData, unsigned len); void Nikon_NRW_WBtag (int wb, int skip); - void parseNikonMakernote (int base, int uptag, unsigned dng_writer); - void parseEpsonMakernote (int base, int uptag, unsigned dng_writer); - void parseSigmaMakernote (int base, int uptag, unsigned dng_writer); + void parseNikonMakernote (INT64 base, int uptag, unsigned dng_writer); + void parseEpsonMakernote (INT64 base, int uptag, unsigned dng_writer); + void parseSigmaMakernote (INT64 base, int uptag, unsigned dng_writer); void setOlympusBodyFeatures (unsigned long long id); void getOlympus_CameraType2 (); void getOlympus_SensorTemperature (unsigned len); void parseOlympus_Equipment (unsigned tag, unsigned type, unsigned len, unsigned dng_writer); - void parseOlympus_CameraSettings (int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); + void parseOlympus_CameraSettings (INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); void parseOlympus_ImageProcessing (unsigned tag, unsigned type, unsigned len, unsigned dng_writer); void parseOlympus_RawInfo (unsigned tag, unsigned type, unsigned len, unsigned dng_writer); - void parseOlympusMakernotes (int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); + void parseOlympusMakernotes (INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); void setPhaseOneFeatures (unsigned long long id); void setPentaxBodyFeatures (unsigned long long id); void PentaxISO (ushort c); void PentaxLensInfo (unsigned long long id, unsigned len); - void parsePentaxMakernotes(int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); - void parseRicohMakernotes(int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); - void parseSamsungMakernotes(int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); + void parsePentaxMakernotes(INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); + void parseRicohMakernotes(INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); + void parseSamsungMakernotes(INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer); void setSonyBodyFeatures (unsigned long long id); void parseSonyLensType2 (uchar a, uchar b); void parseSonyLensFeatures (uchar a, uchar b); @@ -100,7 +100,7 @@ it under the terms of the one of two licenses as you choose: void process_Sony_0x9406 (uchar * buf, ushort); void process_Sony_0x940c (uchar * buf, ushort); void process_Sony_0x940e (uchar * buf, ushort, unsigned long long id); - void parseSonyMakernotes (int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer, + void parseSonyMakernotes (INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer, uchar *&table_buf_0x0116, ushort &table_buf_0x0116_len, uchar *&table_buf_0x2010, ushort &table_buf_0x2010_len, uchar *&table_buf_0x9050, ushort &table_buf_0x9050_len, @@ -123,7 +123,7 @@ it under the terms of the one of two licenses as you choose: void parseLeicaLensID(); int parseLeicaLensName(unsigned len); int parseLeicaInternalBodySerial(unsigned len); - void parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType); + void parseLeicaMakernote(INT64 base, int uptag, unsigned MakernoteTagType); void parseAdobePanoMakernote (); void parseAdobeRAFMakernote (); void GetNormalizedModel (); @@ -134,6 +134,7 @@ it under the terms of the one of two licenses as you choose: unsigned getint(int type); float int_to_float (int i); double getreal (int type); + float getrealf(int type) { return float(getreal(type)); } double sgetreal(int type, uchar *s); void read_shorts (ushort *pixel, unsigned count); @@ -145,7 +146,7 @@ it under the terms of the one of two licenses as you choose: void canon_600_load_raw(); void canon_600_correct(); int canon_s2is(); - void parse_ciff (int offset, int length, int); + void parse_ciff (INT64 offset, int length, int); void ciff_block_1030(); @@ -201,8 +202,8 @@ it under the terms of the one of two licenses as you choose: // Fuji // void fuji_load_raw(); int guess_RAFDataGeneration (uchar *RAFData_start); - void parse_fuji (int offset); - void parse_fuji_thumbnail(int offset); + void parse_fuji (INT64 offset); + void parse_fuji_thumbnail(INT64 offset); // Rollei void rollei_load_raw(); @@ -234,7 +235,7 @@ it under the terms of the one of two licenses as you choose: void unpacked_load_raw_reversed(); void unpacked_load_raw_fuji_f700s20(); void parse_sinar_ia(); - void parse_phase_one (int base); + void parse_phase_one (INT64 base); // Misc P&S cameras void parse_broadcom(); @@ -245,7 +246,8 @@ it under the terms of the one of two licenses as you choose: unsigned pana_data (int nb, unsigned *bytes); void panasonic_load_raw(); // void panasonic_16x10_load_raw(); - void olympus_load_raw(); +// void olympus_load_raw(); + void olympus14_load_raw(); // void olympus_cseries_load_raw(); void minolta_rd175_load_raw(); void quicktake_100_load_raw(); @@ -262,8 +264,8 @@ it under the terms of the one of two licenses as you choose: void smal_v9_load_raw(); void parse_riff(int maxdepth); void parse_cine(); - void parse_smal (int offset, int fsize); - int parse_jpeg (int offset); + void parse_smal (INT64 offset, INT64 fsize); + int parse_jpeg (INT64 offset); // Kodak void kodak_262_load_raw(); @@ -289,7 +291,7 @@ it under the terms of the one of two licenses as you choose: void samsung_load_raw(); void samsung2_load_raw(); void samsung3_load_raw(); - void parse_minolta (int base); + void parse_minolta (INT64 base); #ifdef USE_X3FTOOLS // Foveon/Sigma @@ -315,7 +317,7 @@ it under the terms of the one of two licenses as you choose: void dng_ycbcr_thumb_loader(); #ifdef USE_X3FTOOLS void x3f_thumb_loader(); - INT64 x3f_thumb_size(); + int x3f_thumb_size(); #endif @@ -329,37 +331,37 @@ it under the terms of the one of two licenses as you choose: // Tiff/Exif parsers - void tiff_get (unsigned base,unsigned *tag, unsigned *type, unsigned *len, unsigned *save); + void tiff_get (INT64 base,unsigned *tag, unsigned *type, unsigned *len, INT64 *save); short tiff_sget(unsigned save, uchar *buf, unsigned buf_len, INT64 *tag_offset, unsigned *tag_id, unsigned *tag_type, INT64 *tag_dataoffset, unsigned *tag_datalen, int *tag_dataunit_len); - void parse_thumb_note (int base, unsigned toff, unsigned tlen); - void parse_makernote (int base, int uptag); - void parse_makernote_0xc634(int base, int uptag, unsigned dng_writer); - void parse_exif (int base); - void parse_exif_interop(int base); + void parse_thumb_note (INT64 base, unsigned toff, unsigned tlen); + void parse_makernote (INT64 base, int uptag); + void parse_makernote_0xc634(INT64 base, int uptag, unsigned dng_writer); + void parse_exif (INT64 base); + void parse_exif_interop(INT64 base); void linear_table(unsigned len); void Kodak_DCR_WBtags(int wb, unsigned type, int wbi); void Kodak_KDC_WBtags(int wb, int wbi); short KodakIllumMatrix (unsigned type, float *romm_camIllum); - void parse_kodak_ifd (int base); - int parse_tiff_ifd (int base); - int parse_tiff (int base); + void parse_kodak_ifd (INT64 base); + int parse_tiff_ifd (INT64 base); + int parse_tiff (INT64 base); void apply_tiff(void); - void parse_gps (int base); - void parse_gps_libraw(int base); + void parse_gps (INT64 base); + void parse_gps_libraw(INT64 base); void aRGB_coeff(double aRGB_cam[3][3]); void romm_coeff(float romm_cam[3][3]); void parse_mos (INT64 offset); - void parse_qt (int end); + void parse_qt (INT64 end); void get_timestamp (int reversed); // The identify short guess_byte_order (int words); void identify_process_dng_fields(); void identify_finetune_pentax(); - void identify_finetune_by_filesize(int); - void identify_finetune_dcr(char head[64],int,int); + void identify_finetune_by_filesize(INT64); + void identify_finetune_dcr(char head[64],INT64,INT64); // Tiff writer void tiff_set(struct tiff_hdr *th, ushort *ntag,ushort tag, ushort type, int count, int val); void tiff_head (struct tiff_hdr *th, int full); @@ -381,7 +383,7 @@ it under the terms of the one of two licenses as you choose: void fuji_14bit_load_raw(); void parse_fuji_compressed_header(); void crxLoadRaw(); - int crxParseImageHeader(uchar *cmp1TagData, int nTrack, int size); + int crxParseImageHeader(uchar *cmp1TagData, int nTrack, INT64 size); void panasonicC6_load_raw(); void panasonicC7_load_raw(); void panasonicC8_load_raw(); diff --git a/rtengine/libraw/internal/losslessjpeg.h b/rtengine/libraw/internal/losslessjpeg.h index 382746be0..de0a4dce3 100644 --- a/rtengine/libraw/internal/losslessjpeg.h +++ b/rtengine/libraw/internal/losslessjpeg.h @@ -1,6 +1,6 @@ /* -*- C++ -*- * File: huffmandec.h - * Copyright (C) 2023-2024 Alex Tutubalin, LibRaw LLC + * Copyright (C) 2024 Alex Tutubalin, LibRaw LLC * Lossless JPEG decoder @@ -159,15 +159,15 @@ struct HuffTable uint64_t cached = disable_cache ? 0 : decodecache[pump.peek(LIBRAW_DECODE_CACHE_BITS)]; if (cached & LIBRAW_CACHE_PRESENT_FLAG) { - uint32_t bits = (cached >> 16) & 0xff; + uint32_t _bits = (cached >> 16) & 0xff; int16_t val = int16_t(cached & 0xffff); if (val == -32768 && dng_bug) { - if (bits > 16) - pump.consume(bits - 16); + if (_bits > 16) + pump.consume(_bits - 16); } else - pump.consume(bits); + pump.consume(_bits); return val; } else @@ -194,8 +194,8 @@ struct HuffTable { uint32_t code = pump.peek(nbits); uint32_t huffdata = hufftable[code]; - uint32_t bits = (huffdata >> 16) & 0xff; - pump.consume(bits); + uint32_t _bits = (huffdata >> 16) & 0xff; + pump.consume(_bits); return huffdata; } @@ -212,8 +212,8 @@ struct HuffTable } uint32_t shift = hentry & 0xff; uint32_t fulllen = len + shift; - uint32_t bits = pump.get(len); - int32_t diff = ((bits << 1) + 1) << shift >> 1; + uint32_t _bits = pump.get(len); + int32_t diff = ((_bits << 1) + 1) << shift >> 1; if ((diff & (1 << (fulllen - 1))) == 0) { diff -= int32_t((1 << fulllen) - ((shift == 0))); diff --git a/rtengine/libraw/internal/x3f_tools.h b/rtengine/libraw/internal/x3f_tools.h index df2c6f796..3e63aba0c 100644 --- a/rtengine/libraw/internal/x3f_tools.h +++ b/rtengine/libraw/internal/x3f_tools.h @@ -534,6 +534,6 @@ x3f_directory_entry_t *x3f_get_thumb_huffman(x3f_t *x3f); x3f_directory_entry_t *x3f_get_thumb_jpeg(x3f_t *x3f); x3f_directory_entry_t *x3f_get_camf(x3f_t *x3f); x3f_directory_entry_t *x3f_get_prop(x3f_t *x3f); -/* extern */ int64_t x3f_load_data_size(x3f_t *x3f, x3f_directory_entry_t *DE); +/* extern */ int32_t x3f_load_data_size(x3f_t *x3f, x3f_directory_entry_t *DE); #endif diff --git a/rtengine/libraw/libraw/libraw.h b/rtengine/libraw/libraw/libraw.h index 897f63f1a..53dc181ce 100644 --- a/rtengine/libraw/libraw/libraw.h +++ b/rtengine/libraw/libraw/libraw.h @@ -120,16 +120,19 @@ extern "C" DllDef int libraw_raw2image(libraw_data_t *); DllDef void libraw_free_image(libraw_data_t *); /* version helpers */ - DllDef const char *libraw_version(); - DllDef int libraw_versionNumber(); + DllDef const char *libraw_version(void); + DllDef int libraw_versionNumber(void); /* Camera list */ - DllDef const char **libraw_cameraList(); - DllDef int libraw_cameraCount(); + DllDef const char **libraw_cameraList(void); + DllDef int libraw_cameraCount(void); /* helpers */ DllDef void libraw_set_exifparser_handler(libraw_data_t *, exif_parser_callback cb, void *datap); + DllDef void libraw_set_makernotes_handler(libraw_data_t *, + exif_parser_callback cb, + void *datap); DllDef void libraw_set_dataerror_handler(libraw_data_t *, data_callback func, void *datap); DllDef void libraw_set_progress_handler(libraw_data_t *, progress_callback cb, @@ -138,7 +141,8 @@ extern "C" DllDef int libraw_get_decoder_info(libraw_data_t *lr, libraw_decoder_info_t *d); DllDef int libraw_COLOR(libraw_data_t *, int row, int col); - DllDef unsigned libraw_capabilities(); + DllDef unsigned libraw_capabilities(void); + DllDef int libraw_adjust_to_raw_inset_crop(libraw_data_t *lr, unsigned mask, float maxcrop); /* DCRAW compatibility */ DllDef int libraw_adjust_sizes_info_only(libraw_data_t *); @@ -231,6 +235,11 @@ public: callbacks.exifparser_data = data; callbacks.exif_cb = cb; } + void set_makernotes_handler(exif_parser_callback cb, void *data) + { + callbacks.makernotesparser_data = data; + callbacks.makernotes_cb = cb; + } void set_dataerror_handler(data_callback func, void *data) { callbacks.datacb_data = data; @@ -247,6 +256,10 @@ public: void convertFloatToInt(float dmin = 4096.f, float dmax = 32767.f, float dtarget = 16383.f); + + /* Make/Model simplification */ + static int simplify_make_model(unsigned *_maker_index, char *_make, unsigned _make_buf_size, char *_model, unsigned _model_buf_size); + /* helpers */ static unsigned capabilities(); static const char *version(); diff --git a/rtengine/libraw/libraw/libraw_const.h b/rtengine/libraw/libraw/libraw_const.h index 0d84029eb..a9be67b73 100644 --- a/rtengine/libraw/libraw/libraw_const.h +++ b/rtengine/libraw/libraw/libraw_const.h @@ -29,14 +29,18 @@ it under the terms of the one of two licenses as you choose: #endif #ifndef LIBRAW_MAX_NONDNG_RAW_FILE_SIZE -#define LIBRAW_MAX_NONDNG_RAW_FILE_SIZE 2147483647ULL +#define LIBRAW_MAX_NONDNG_RAW_FILE_SIZE 2147483647LL +#endif + +#ifndef LIBRAW_MAX_CR3_RAW_FILE_SIZE +#define LIBRAW_MAX_CR3_RAW_FILE_SIZE LIBRAW_MAX_NONDNG_RAW_FILE_SIZE #endif #ifndef LIBRAW_MAX_DNG_RAW_FILE_SIZE #ifdef USE_DNGSDK -#define LIBRAW_MAX_DNG_RAW_FILE_SIZE 4294967295ULL +#define LIBRAW_MAX_DNG_RAW_FILE_SIZE 4294967295LL #else -#define LIBRAW_MAX_DNG_RAW_FILE_SIZE 2147483647ULL +#define LIBRAW_MAX_DNG_RAW_FILE_SIZE 2147483647LL #endif #endif @@ -474,6 +478,37 @@ enum LibRawImageAspects LIBRAW_IMAGE_ASPECT_7to5 = (1000 * 7) / 5 }; +/* +inch-based ID (diameter) -> diagonal, mm +ID diagonal aspect +1/4" 4.00 4:3 +1/3.6" 5.00 4:3 +1/3.4" 5.29 4:3 +1/3.2" 5.62 4:3 +1/3" 6.00 4:3 +1/2.9" 6.20 4:3 +1/2.7" 6.66 4:3 +1/2.5" 7.19 4:3 +1/2.4" 7.38 4:3 +1/2.35" 7.54 4:3 +1/2.33" 7.60 4:3 +1/2.3" 7.70 4:3 +1/2" 8.00 4:3 +1/1.9" 8.42 4:3 +1/1.8" 8.89 4:3 +1/1.76" 9.09 4:3 +1/1.75" 9.14 4:3 +1/1.72" 9.30 4:3 +1/1.7" 9.41 4:3 +1/1.65" 9.69 4:3 +1/1.63" 9.81 4:3 +1/1.6" 10.00 4:3 +2/3" 11.00 4:3 +1" 15.86 3:2 +4/3" 21.64 4:3 +1.5" 23.36 4:3 +*/ + enum LibRaw_lens_focal_types { LIBRAW_FT_UNDEFINED = 0, @@ -699,7 +734,9 @@ enum LibRaw_warnings LIBRAW_WARN_RAWSPEED3_UNSUPPORTED = 1 << 22, LIBRAW_WARN_RAWSPEED3_PROCESSED = 1 << 23, LIBRAW_WARN_RAWSPEED3_NOTLISTED = 1 << 24, - LIBRAW_WARN_VENDOR_CROP_SUGGESTED = 1 << 25 + LIBRAW_WARN_VENDOR_CROP_SUGGESTED = 1 << 25, + LIBRAW_WARN_DNG_NOT_PROCESSED = 1 << 26, + LIBRAW_WARN_DNG_NOT_PARSED = 1 << 27 }; enum LibRaw_exceptions @@ -813,7 +850,9 @@ enum LibRaw_thumbnail_formats enum LibRaw_image_formats { LIBRAW_IMAGE_JPEG = 1, - LIBRAW_IMAGE_BITMAP = 2 + LIBRAW_IMAGE_BITMAP = 2, + LIBRAW_IMAGE_JPEGXL = 3, + LIBRAW_IMAGE_H265 = 4 }; #endif diff --git a/rtengine/libraw/libraw/libraw_datastream.h b/rtengine/libraw/libraw/libraw_datastream.h index a978ae602..9a6a04223 100644 --- a/rtengine/libraw/libraw/libraw_datastream.h +++ b/rtengine/libraw/libraw/libraw_datastream.h @@ -29,7 +29,18 @@ it under the terms of the one of two licenses as you choose: #else /* __cplusplus */ #if defined _WIN32 #ifndef LIBRAW_NO_WINSOCK2 +#ifdef NOMINMAX +#define LIBRAW_NO_UNDEF_NOMINMAX +#else +#define NOMINMAX +#endif + #include + +#ifndef LIBRAW_NO_UNDEF_NOMINMAX +#undef NOMINMAX /* restore previous mode*/ +#endif +#undef LIBRAW_NO_UNDEF_NOMINMAX #endif #endif /* No unique_ptr on Apple ?? */ @@ -97,6 +108,8 @@ public: virtual int eof() = 0; virtual int jpeg_src(void *); virtual void buffering_off() {} + virtual void buffering_on() {} + virtual bool is_buffered() { return false; } /* reimplement in subclass to use parallel access in xtrans_load_raw() if * OpenMP is not used */ virtual int lock() { return 1; } /* success */ @@ -209,6 +222,8 @@ public: virtual ~LibRaw_bigfile_buffered_datastream(); virtual int valid(); virtual void buffering_off() { buffered = 0; } + virtual void buffering_on() { buffered = 1; } + virtual bool is_buffered() { return buffered; } virtual int read(void *ptr, size_t size, size_t nmemb); virtual int eof(); virtual int seek(INT64 o, int whence); @@ -354,15 +369,20 @@ public: { if (parent_stream) { + parent_buffered = parent_stream->is_buffered(); parent_stream->buffering_off(); - off = parent_stream->tell(); - parent_stream->seek(0UL, SEEK_SET); /* seek to start */ + off = parent_stream->tell(); + parent_stream->seek(0UL, SEEK_SET); /* seek to start */ } } ~libraw_dng_stream() { - if (parent_stream) - parent_stream->seek(off, SEEK_SET); + if (parent_stream) + { + if (parent_buffered) + parent_stream->buffering_on(); + parent_stream->seek(off, SEEK_SET); + } } virtual uint64 DoGetLength() { @@ -384,6 +404,7 @@ private: libraw_dng_stream &operator=(const libraw_dng_stream &stream); LibRaw_abstract_datastream *parent_stream; INT64 off; + bool parent_buffered; }; #endif diff --git a/rtengine/libraw/libraw/libraw_internal.h b/rtengine/libraw/libraw/libraw_internal.h index 5af31d3ab..9ef8c0cb9 100644 --- a/rtengine/libraw/libraw/libraw_internal.h +++ b/rtengine/libraw/libraw/libraw_internal.h @@ -174,7 +174,7 @@ typedef struct INT64 strip_offset, data_offset; INT64 meta_offset; INT64 exif_offset, exif_subdir_offset, ifd0_offset; - unsigned data_size; + INT64 data_size; unsigned meta_length; unsigned cr3_exif_length, cr3_ifd0_length; unsigned thumb_misc; @@ -228,11 +228,14 @@ struct decode struct tiff_ifd_t { - int t_width, t_height, bps, comp, phint, offset, t_flip, samples, bytes, extrasamples; + int t_width, t_height, bps, comp, phint, t_flip, samples, extrasamples; + INT64 offset, bytes; int t_tile_width, t_tile_length, sample_format, predictor; int rows_per_strip; - int *strip_offsets, strip_offsets_count; - int *strip_byte_counts, strip_byte_counts_count; + INT64 *strip_offsets; + int strip_offsets_count; + INT64 *strip_byte_counts; + int strip_byte_counts_count; unsigned t_filters; int t_vwidth, t_vheight, t_lm,t_tm; int t_fuji_width; diff --git a/rtengine/libraw/libraw/libraw_types.h b/rtengine/libraw/libraw/libraw_types.h index 481ee720a..9203d55b4 100644 --- a/rtengine/libraw/libraw/libraw_types.h +++ b/rtengine/libraw/libraw/libraw_types.h @@ -138,10 +138,10 @@ typedef unsigned long long UINT64; int len, unsigned int ord, void *ifp, INT64 base); - typedef void (*data_callback)(void *data, const char *file, const int offset); + typedef void (*data_callback)(void *data, const char *file, const INT64 offset); DllDef void default_data_callback(void *data, const char *file, - const int offset); + const INT64 offset); typedef int (*progress_callback)(void *data, enum LibRaw_progress stage, int iteration, int expected); @@ -157,8 +157,8 @@ typedef unsigned long long UINT64; progress_callback progress_cb; void *progresscb_data; - exif_parser_callback exif_cb; - void *exifparser_data; + exif_parser_callback exif_cb,makernotes_cb; + void *exifparser_data, *makernotesparser_data; pre_identify_callback pre_identify_cb; post_identify_callback post_identify_cb; process_step_callback pre_subtractblack_cb, pre_scalecolors_cb, @@ -519,6 +519,14 @@ typedef unsigned long long UINT64; char PictureControlName [20]; char PictureControlBase [20]; unsigned ShotInfoVersion; + char ShotInfoFirmware [9]; + + unsigned BurstTable_0x0056_len; + uchar *BurstTable_0x0056; + ushort BurstTable_0x0056_ver; + ushort BurstTable_0x0056_gid; + uchar BurstTable_0x0056_fnum; + short MakernotesFlip; double RollAngle; // positive is clockwise, CW double PitchAngle; // positive is upwords @@ -529,6 +537,10 @@ typedef unsigned long long UINT64; { char CameraType2[6]; ushort ValidBits; + // decoder data + unsigned tagX640, tagX641, tagX642, tagX643, tagX644, tagX645, tagX646, tagX647, + tagX648, tagX649, tagX650, tagX651, tagX652, tagX653; + // int SensorCalibration[2]; ushort DriveMode[5]; ushort ColorSpace; @@ -584,6 +596,7 @@ typedef unsigned long long UINT64; int AFPointsInFocus_version; unsigned AFPointsInFocus; ushort FocusPosition; + uchar DynamicRangeExpansion[4]; /* if (DynamicRangeExpansion[1] > 0) BLE+=DynamicRangeExpansion[0] */ short AFAdjustment; uchar AFPointMode; uchar MultiExposure; /* last bit is not "1" if ME is not used */ @@ -744,6 +757,7 @@ typedef unsigned long long UINT64; 3350 ARW 2.3.5 4000 ARW 4.0 4010 ARW 4.0.1 + 5000 ARW 5.0 */ char MetaVersion [16]; float AspectRatio; @@ -771,7 +785,7 @@ typedef unsigned long long UINT64; // Sony // and aliases of the above // DNG - long linear_max[4]; + unsigned linear_max[4]; float fmaximum; float fnorm; @@ -1156,7 +1170,19 @@ private: /* Byte order */ -#if defined(__POWERPC__) +#if defined(__LITTLE_ENDIAN__) +#define LibRawBigEndian 0 + +#elif defined(__BIG_ENDIAN__) +#define LibRawBigEndian 1 + +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define LibRawBigEndian 0 + +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define LibRawBigEndian 1 + +#elif defined(__POWERPC__) #define LibRawBigEndian 1 #elif defined(__INTEL__) @@ -1168,19 +1194,9 @@ private: #elif defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) #define LibRawBigEndian 0 -#elif defined(__LITTLE_ENDIAN__) -#define LibRawBigEndian 0 - -#elif defined(__BIG_ENDIAN__) -#define LibRawBigEndian 1 #elif defined(_ARM_) #define LibRawBigEndian 0 -#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define LibRawBigEndian 0 - -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define LibRawBigEndian 1 #else #ifndef qXCodeRez #error Unable to figure out byte order. diff --git a/rtengine/libraw/libraw/libraw_version.h b/rtengine/libraw/libraw/libraw_version.h index 143a769ad..844f07983 100644 --- a/rtengine/libraw/libraw/libraw_version.h +++ b/rtengine/libraw/libraw/libraw_version.h @@ -21,11 +21,11 @@ it under the terms of the one of two licenses as you choose: #define __VERSION_H #define LIBRAW_MAJOR_VERSION 0 -#define LIBRAW_MINOR_VERSION 21 +#define LIBRAW_MINOR_VERSION 22 #define LIBRAW_PATCH_VERSION 0 -#define LIBRAW_VERSION_TAIL Beta1 +#define LIBRAW_VERSION_TAIL Devel202502 -#define LIBRAW_SHLIB_CURRENT 23 +#define LIBRAW_SHLIB_CURRENT 24 #define LIBRAW_SHLIB_REVISION 0 #define LIBRAW_SHLIB_AGE 0 diff --git a/rtengine/libraw/m4/ax_openmp.m4 b/rtengine/libraw/m4/ax_openmp.m4 index 7ea794be0..59b5c27f0 100644 --- a/rtengine/libraw/m4/ax_openmp.m4 +++ b/rtengine/libraw/m4/ax_openmp.m4 @@ -1,5 +1,5 @@ # =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_openmp.html +# https://www.gnu.org/software/autoconf-archive/ax_openmp.html # =========================================================================== # # SYNOPSIS @@ -38,6 +38,8 @@ # LICENSE # # Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2015 John W. Peterson +# Copyright (c) 2016 Nick R. Papior # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -50,7 +52,7 @@ # Public License for more details. # # You should have received a copy of the GNU General Public License along -# with this program. If not, see . +# with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure @@ -65,16 +67,19 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 8 +#serial 14 AC_DEFUN([AX_OPENMP], [ -AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX +AC_PREREQ([2.69]) dnl for _AC_LANG_PREFIX AC_CACHE_CHECK([for OpenMP flag of _AC_LANG compiler], ax_cv_[]_AC_LANG_ABBREV[]_openmp, [save[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS ax_cv_[]_AC_LANG_ABBREV[]_openmp=unknown -# Flags to try: -fopenmp (gcc), -openmp (icc), -mp (SGI & PGI), -# -xopenmp (Sun), -omp (Tru64), -qsmp=omp (AIX), none -ax_openmp_flags="-fopenmp -openmp -mp -xopenmp -omp -qsmp=omp none" +# Flags to try: -fopenmp (gcc), -mp (SGI & PGI), +# -qopenmp (icc>=15), -openmp (icc), +# -xopenmp (Sun), -omp (Tru64), +# -qsmp=omp (AIX), +# none +ax_openmp_flags="-fopenmp -openmp -qopenmp -mp -xopenmp -omp -qsmp=omp none" if test "x$OPENMP_[]_AC_LANG_PREFIX[]FLAGS" != x; then ax_openmp_flags="$OPENMP_[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flags" fi @@ -83,8 +88,27 @@ for ax_openmp_flag in $ax_openmp_flags; do none) []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[] ;; *) []_AC_LANG_PREFIX[]FLAGS="$save[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flag" ;; esac - AC_TRY_LINK_FUNC(omp_set_num_threads, - [ax_cv_[]_AC_LANG_ABBREV[]_openmp=$ax_openmp_flag; break]) + AC_LINK_IFELSE([AC_LANG_SOURCE([[ +@%:@include + +static void +parallel_fill(int * data, int n) +{ + int i; +@%:@pragma omp parallel for + for (i = 0; i < n; ++i) + data[i] = i; +} + +int +main(void) +{ + int arr[100000]; + omp_set_num_threads(2); + parallel_fill(arr, 100000); + return 0; +} +]])],[ax_cv_[]_AC_LANG_ABBREV[]_openmp=$ax_openmp_flag; break],[]) done []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[]FLAGS ]) diff --git a/rtengine/libraw/samples/raw-identify.cpp b/rtengine/libraw/samples/raw-identify.cpp index 5c5b29a8c..b48a4c661 100644 --- a/rtengine/libraw/samples/raw-identify.cpp +++ b/rtengine/libraw/samples/raw-identify.cpp @@ -566,7 +566,7 @@ void print_verbose(FILE *outfile, LibRaw &MyCoolRawProcessor, std::string &fn) { fprintf(outfile, "\nHighlight linearity limits:"); for (int c = 0; c < 4; c++) - fprintf(outfile, " %ld", C.linear_max[c]); + fprintf(outfile, " %u", C.linear_max[c]); } if (P1.colors > 1) diff --git a/rtengine/libraw/samples/simple_dcraw.cpp b/rtengine/libraw/samples/simple_dcraw.cpp index 710252ecf..a29195b00 100644 --- a/rtengine/libraw/samples/simple_dcraw.cpp +++ b/rtengine/libraw/samples/simple_dcraw.cpp @@ -126,6 +126,8 @@ int main(int ac, char *av[]) if (verbose) printf("Processing file %s\n", av[i]); + RawProcessor->imgdata.rawparams.options |= LIBRAW_RAWOPTIONS_ALLOW_JPEGXL_PREVIEWS; + if ((ret = RawProcessor->open_file(av[i])) != LIBRAW_SUCCESS) { fprintf(stderr, "Cannot open_file %s: %s\n", av[i], libraw_strerror(ret)); @@ -151,8 +153,10 @@ int main(int ac, char *av[]) fprintf(stderr, "Cannot unpack_thumb #%d from %s: %s\n", t, av[i], libraw_strerror(ret)); if (LIBRAW_FATAL_ERROR(ret)) break; // skip to next file - snprintf(thumbfn, sizeof(thumbfn), "%s.thumb.%d.%s", av[i], t, - T.tformat == LIBRAW_THUMBNAIL_JPEG ? "jpg" : "ppm"); + snprintf(thumbfn, sizeof(thumbfn), "%s.thumb.%d.%s", av[i], t, + T.tformat == LIBRAW_THUMBNAIL_JPEG ? "jpg" + : (T.tformat == LIBRAW_THUMBNAIL_JPEGXL ? "jxl" + : (T.tcolors == 1 ? "pgm" : "ppm"))); if (verbose) printf("Writing thumbnail file %s\n", thumbfn); if (LIBRAW_SUCCESS != (ret = RawProcessor->dcraw_thumb_writer(thumbfn))) @@ -177,7 +181,8 @@ int main(int ac, char *av[]) { snprintf(thumbfn, sizeof(thumbfn), "%s.%s", av[i], T.tformat == LIBRAW_THUMBNAIL_JPEG ? "thumb.jpg" - : (T.tcolors == 1? "thumb.pgm" : "thumb.ppm")); + : (T.tformat == LIBRAW_THUMBNAIL_JPEGXL ? "thumb.jxl" + : (T.tcolors == 1? "thumb.pgm" : "thumb.ppm"))); if (verbose) printf("Writing thumbnail file %s\n", thumbfn); if (LIBRAW_SUCCESS != (ret = RawProcessor->dcraw_thumb_writer(thumbfn))) diff --git a/rtengine/libraw/src/decoders/crx.cpp b/rtengine/libraw/src/decoders/crx.cpp index 495c2f4e4..aadb06efc 100644 --- a/rtengine/libraw/src/decoders/crx.cpp +++ b/rtengine/libraw/src/decoders/crx.cpp @@ -54,8 +54,8 @@ libraw_inline void _BitScanReverse(DWORD *Index, unsigned long Mask) struct CrxBitstream { uint8_t mdatBuf[CRX_BUF_SIZE]; - uint64_t mdatSize; - uint64_t curBufOffset; + INT64 mdatSize; + INT64 curBufOffset; uint32_t curPos; uint32_t curBufSize; uint32_t bitData; @@ -98,7 +98,7 @@ struct CrxWaveletTransform struct CrxSubband { CrxBandParam *bandParam; - uint64_t mdatOffset; + INT64 mdatOffset; uint8_t *bandBuf; uint16_t width; uint16_t height; @@ -108,8 +108,8 @@ struct CrxSubband uint32_t qStepMult; bool supportsPartial; int32_t bandSize; - uint64_t dataSize; - int64_t dataOffset; + INT64 dataSize; + INT64 dataOffset; short rowStartAddOn; short rowEndAddOn; short colStartAddOn; @@ -123,7 +123,7 @@ struct CrxPlaneComp CrxSubband *subBands; CrxWaveletTransform *wvltTransform; int8_t compNumber; - int64_t dataOffset; + INT64 dataOffset; int32_t compSize; bool supportsPartial; int32_t roundedBitsMask; @@ -252,7 +252,7 @@ libraw_inline int crxBitstreamGetZeros(CrxBitstream *bitStrm) { _BitScanReverse((DWORD *)&nonZeroBit, (DWORD)nextData); result = bitsLeft + 31 - nonZeroBit; - bitStrm->bitData = nextData << (32 - nonZeroBit); + bitStrm->bitData = uint32_t((nextData << (32 - nonZeroBit))&0xffffffffu); bitStrm->bitsLeft = nonZeroBit; return result; } @@ -268,7 +268,7 @@ libraw_inline int crxBitstreamGetZeros(CrxBitstream *bitStrm) } _BitScanReverse((DWORD *)&nonZeroBit, (DWORD)nextData); result = (uint32_t)(bitsLeft + 7 - nonZeroBit); - bitStrm->bitData = nextData << (32 - nonZeroBit); + bitStrm->bitData = uint32_t((nextData << (32 - nonZeroBit)) & 0xffffffffu); bitStrm->bitsLeft = nonZeroBit; } return result; @@ -1771,7 +1771,7 @@ int crxParamInit(CrxImage *img, CrxBandParam **param, uint64_t subbandMdatOffset return 0; } -int crxSetupSubbandData(CrxImage *img, CrxPlaneComp *planeComp, const CrxTile *tile, uint32_t mdatOffset) +int crxSetupSubbandData(CrxImage *img, CrxPlaneComp *planeComp, const CrxTile *tile, uint64_t mdatOffset) { long compDataSize = 0; long waveletDataOffset = 0; @@ -2003,7 +2003,8 @@ int crxMakeQStep(CrxImage *img, CrxTile *tile, int32_t *qpTable, uint32_t /*tota totalHeight += qpHeight4; if (img->levels > 2) totalHeight += qpHeight8; - tile->qStep = (CrxQStep *) + + tile->qStep = (CrxQStep *) #ifdef LIBRAW_CR3_MEMPOOL img->memmgr. #endif @@ -2032,7 +2033,7 @@ int crxMakeQStep(CrxImage *img, CrxTile *tile, int32_t *qpTable, uint32_t /*tota // not sure about this nonsense - why is it not just avg like with 2 levels? quantVal = ((quantVal < 0) * 3 + quantVal) >> 2; if (quantVal / 6 >= 6) - *qStepTbl = q_step_tbl[quantVal % 6] * (1 << ((quantVal / 6 - 6 ) & 0x1f)); + *qStepTbl = q_step_tbl[quantVal % 6] << ((quantVal / 6 - 6 ) & 0x1f); else *qStepTbl = q_step_tbl[quantVal % 6] >> (6 - quantVal / 6); } @@ -2052,7 +2053,7 @@ int crxMakeQStep(CrxImage *img, CrxTile *tile, int32_t *qpTable, uint32_t /*tota { int32_t quantVal = (qpTable[row0Idx++] + qpTable[row1Idx++]) / 2; if (quantVal / 6 >= 6) - *qStepTbl = q_step_tbl[quantVal % 6] * (1 << ((quantVal / 6 - 6) & 0x1f)); + *qStepTbl = q_step_tbl[quantVal % 6] << ((quantVal / 6 - 6) & 0x1f); else *qStepTbl = q_step_tbl[quantVal % 6] >> (6 - quantVal / 6); } @@ -2066,7 +2067,7 @@ int crxMakeQStep(CrxImage *img, CrxTile *tile, int32_t *qpTable, uint32_t /*tota for (int qpRow = 0; qpRow < qpHeight; ++qpRow) for (int qpCol = 0; qpCol < qpWidth; ++qpCol, ++qStepTbl, ++qpTable) if (*qpTable / 6 >= 6) - *qStepTbl = q_step_tbl[*qpTable % 6] * (1 << ((*qpTable / 6 - 6) & 0x1f)); + *qStepTbl = q_step_tbl[*qpTable % 6] << ((*qpTable / 6 - 6) & 0x1f); else *qStepTbl = q_step_tbl[*qpTable % 6] >> (6 - *qpTable / 6); @@ -2493,7 +2494,7 @@ int crxReadImageHeaders(crx_data_header_t *hdr, CrxImage *img, uint8_t *mdatPtr, return 0; } -int crxSetupImageData(crx_data_header_t *hdr, CrxImage *img, int16_t *outBuf, uint64_t mdatOffset, uint32_t mdatSize, +int crxSetupImageData(crx_data_header_t *hdr, CrxImage *img, int16_t *outBuf, int64_t mdatOffset, int64_t mdatSize, uint8_t *mdatHdrPtr, int32_t mdatHdrSize) { int IncrBitTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0}; @@ -2677,7 +2678,7 @@ void LibRaw::crxLoadRaw() std::vector hdrBuf(hdr.mdatHdrSize); - unsigned bytes = 0; + int bytes = 0; // read image header #ifdef LIBRAW_USE_OPENMP #pragma omp critical @@ -2710,9 +2711,9 @@ void LibRaw::crxLoadRaw() crxFreeImageData(&img); } -int LibRaw::crxParseImageHeader(uchar *cmp1TagData, int nTrack, int size) +int LibRaw::crxParseImageHeader(uchar *cmp1TagData, int nTrack, INT64 size) { - if (nTrack < 0 || nTrack >= LIBRAW_CRXTRACKS_MAXCOUNT) + if (nTrack < 0 || nTrack >= LIBRAW_CRXTRACKS_MAXCOUNT || size < 32) return -1; if (!cmp1TagData) return -1; diff --git a/rtengine/libraw/src/decoders/decoders_dcraw.cpp b/rtengine/libraw/src/decoders/decoders_dcraw.cpp index bd70b2dbd..56727fc35 100644 --- a/rtengine/libraw/src/decoders/decoders_dcraw.cpp +++ b/rtengine/libraw/src/decoders/decoders_dcraw.cpp @@ -779,9 +779,9 @@ void LibRaw::ljpeg_idct(struct jhead *jh) 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63}; if (!cs[0]) - FORC(106) cs[c] = cos((c & 31) * M_PI / 16) / 2; + FORC(106) cs[c] = float(cos((c & 31) * M_PI / 16) / 2); memset(work, 0, sizeof work); - work[0][0][0] = jh->vpred[0] += ljpeg_diff(jh->huff[0]) * jh->quant[0]; + work[0][0][0] = float(jh->vpred[0] += ljpeg_diff(jh->huff[0]) * jh->quant[0]); for (i = 1; i < 64; i++) { len = gethuff(jh->huff[16]); @@ -791,7 +791,7 @@ void LibRaw::ljpeg_idct(struct jhead *jh) coef = getbits(len); if ((coef & (1 << (len - 1))) == 0) coef -= (1 << len) - 1; - ((float *)work)[zigzag[i]] = coef * jh->quant[i]; + ((float *)work)[zigzag[i]] = float(coef * jh->quant[i]); } FORC(8) work[0][0][c] *= float(M_SQRT1_2); FORC(8) work[0][c][0] *= float(M_SQRT1_2); @@ -972,11 +972,12 @@ void LibRaw::nikon_yuv_load_raw() FORC(6) bitbuf |= (UINT64)fgetc(ifp) << c * 8; FORC(4) yuv[c] = (bitbuf >> c * 12 & 0xfff) - (c >> 1 << 11); } - rgb[0] = yuv[b] + 1.370705 * yuv[3]; - rgb[1] = yuv[b] - 0.337633 * yuv[2] - 0.698001 * yuv[3]; - rgb[2] = yuv[b] + 1.732446 * yuv[2]; - FORC3 image[row * width + col][c] = - curve[LIM(rgb[c], 0, 0xfff)] / cmul[c]; + rgb[0] = int(yuv[b] + 1.370705f * yuv[3]); + rgb[1] = int(yuv[b] - 0.337633f * yuv[2] - 0.698001f * yuv[3]); + rgb[2] = int(yuv[b] + 1.732446f * yuv[2]); + FORC3 image[row * width + col][c] = + ushort( + curve[LIM(rgb[c], 0, 0xfff)] / cmul[c]); } } } @@ -1025,7 +1026,7 @@ void LibRaw::nokia_load_raw() if (raw_stride) dwide = raw_stride; #endif - std::vector data(dwide * 2 + 4); + std::vector data(dwide * 2 + 4,0); for (row = 0; row < raw_height; row++) { checkCancel(); @@ -1066,11 +1067,17 @@ unsigned LibRaw::pana_data(int nb, unsigned *bytes) int byte; if (!nb && !bytes) - return vpos = 0; + { + memset(buf, 0, sizeof(buf)); + return vpos = 0; + } + if (load_flags > 0x4000) + throw LIBRAW_EXCEPTION_IO_BADFILE; if (!vpos) { - fread(buf + load_flags, 1, 0x4000 - load_flags, ifp); + if(load_flags < 0x4000) + fread(buf + load_flags, 1, 0x4000 - load_flags, ifp); fread(buf, 1, load_flags, ifp); } @@ -1180,64 +1187,6 @@ void LibRaw::panasonic_load_raw() } } -void LibRaw::olympus_load_raw() -{ - ushort huff[4096]; - int row, col, nbits, sign, low, high, i, c, w, n, nw; - int acarry[2][3], *carry, pred, diff; - - huff[n = 0] = 0xc0c; - for (i = 12; i--;) - FORC(2048 >> i) huff[++n] = (i + 1) << 8 | i; - fseek(ifp, 7, SEEK_CUR); - getbits(-1); - for (row = 0; row < height; row++) - { - checkCancel(); - memset(acarry, 0, sizeof acarry); - for (col = 0; col < raw_width; col++) - { - carry = acarry[col & 1]; - i = 2 * (carry[2] < 3); - for (nbits = 2 + i; (ushort)carry[0] >> (nbits + i); nbits++) - ; - low = (sign = getbits(3)) & 3; - sign = sign << 29 >> 31; - if ((high = getbithuff(12, huff)) == 12) - high = getbits(16 - nbits) >> 1; - carry[0] = (high << nbits) | getbits(nbits); - diff = (carry[0] ^ sign) + carry[1]; - carry[1] = (diff * 3 + carry[1]) >> 5; - carry[2] = carry[0] > 16 ? 0 : carry[2] + 1; - if (col >= width) - continue; - if (row < 2 && col < 2) - pred = 0; - else if (row < 2) - pred = RAW(row, col - 2); - else if (col < 2) - pred = RAW(row - 2, col); - else - { - w = RAW(row, col - 2); - n = RAW(row - 2, col); - nw = RAW(row - 2, col - 2); - if ((w < nw && nw < n) || (n < nw && nw < w)) - { - if (ABS(w - nw) > 32 || ABS(n - nw) > 32) - pred = w + n - nw; - else - pred = (w + n) >> 1; - } - else - pred = ABS(w - nw) > ABS(n - nw) ? w : n; - } - if ((RAW(row, col) = pred + ((diff << 2) | low)) >> 12) - derror(); - } - } -} - void LibRaw::minolta_rd175_load_raw() { uchar pixel[768]; @@ -1409,7 +1358,7 @@ void LibRaw::sony_load_raw() void LibRaw::sony_arw_load_raw() { - std::vector huff_buffer(32770); + std::vector huff_buffer(32770,0); ushort* huff = &huff_buffer[0]; static const ushort tab[18] = {0xf11, 0xf10, 0xe0f, 0xd0e, 0xc0d, 0xb0c, 0xa0b, 0x90a, 0x809, 0x708, 0x607, 0x506, @@ -1441,7 +1390,7 @@ void LibRaw::sony_arw2_load_raw() ushort pix[16]; int row, col, val, max, min, imax, imin, sh, bit, i; - data = (uchar *)malloc(raw_width + 1); + data = (uchar *)calloc(raw_width + 1,1); try { for (row = 0; row < height; row++) diff --git a/rtengine/libraw/src/decoders/decoders_libraw.cpp b/rtengine/libraw/src/decoders/decoders_libraw.cpp index bc62a6c2d..7eafe286e 100644 --- a/rtengine/libraw/src/decoders/decoders_libraw.cpp +++ b/rtengine/libraw/src/decoders/decoders_libraw.cpp @@ -54,11 +54,19 @@ void LibRaw::sony_arq_load_raw() void LibRaw::pentax_4shot_load_raw() { - ushort *plane = (ushort *)malloc(imgdata.sizes.raw_width * - imgdata.sizes.raw_height * sizeof(ushort)); - int alloc_sz = imgdata.sizes.raw_width * (imgdata.sizes.raw_height + 16) * 4 * +#ifdef LIBRAW_CALLOC_RAWSTORE + ushort *plane = (ushort *)calloc(size_t(imgdata.sizes.raw_width) * size_t(imgdata.sizes.raw_height), sizeof(ushort)); +#else + ushort *plane = (ushort *)malloc(size_t(imgdata.sizes.raw_width) * + size_t(imgdata.sizes.raw_height) * sizeof(ushort)); +#endif + size_t alloc_sz = size_t(imgdata.sizes.raw_width) * (size_t(imgdata.sizes.raw_height) + 16) * 4 * sizeof(ushort); +#ifdef LIBRAW_CALLOC_RAWSTORE + ushort(*result)[4] = (ushort(*)[4])calloc(alloc_sz,1); +#else ushort(*result)[4] = (ushort(*)[4])malloc(alloc_sz); +#endif struct movement_t { int row, col; @@ -191,23 +199,62 @@ static inline void unpack7bytesto4x16_nikon(unsigned char *src, dest[0] = ((src[1] & 0x3f) << 8) | src[0]; } +static inline void unpack21bytesto12x16_nikon(unsigned char *src, unsigned short (*dest)[4]) +{ + // bytes 0-6 + dest[0][0] = ((src[1] & 0x3f) << 8) | src[0]; + dest[0][1] = (src[3] & 0xf) << 10 | (src[2] << 2) | (src[1] >> 6); + dest[0][2] = ((src[5] & 0x3) << 12) | (src[4] << 4) | (src[3] >> 4); + dest[1][0] = (src[6] << 6) | (src[5] >> 2); + // bytes 7-13 + dest[1][1] = ((src[8] & 0x3f) << 8) | src[7]; + dest[1][2] = (src[10] & 0xf) << 10 | (src[9] << 2) | (src[8] >> 6); + dest[2][0] = ((src[12] & 0x3) << 12) | (src[11] << 4) | (src[10] >> 4); + dest[2][1] = (src[13] << 6) | (src[12] >> 2); + // bytes 14-20 + dest[2][2] = ((src[15] & 0x3f) << 8) | src[14]; + dest[3][0] = (src[17] & 0xf) << 10 | (src[16] << 2) | (src[15] >> 6); + dest[3][1] = ((src[19] & 0x3) << 12) | (src[18] << 4) | (src[17] >> 4); + dest[3][2] = (src[20] << 6) | (src[19] >> 2); +} + + void LibRaw::nikon_14bit_load_raw() { + int cps = (imgdata.idata.filters == 0 && imgdata.idata.colors == 3) ? 3 : 1; + + if (cps == 1 && !imgdata.rawdata.raw_image) + throw LIBRAW_EXCEPTION_DECODE_RAW; + if(cps == 3 && !imgdata.image) + throw LIBRAW_EXCEPTION_DECODE_RAW; + const unsigned linelen = - (unsigned)(ceilf((float)(S.raw_width * 7 / 4) / 16.0)) * + (unsigned)(ceilf((float)(S.raw_width * cps * 7 / 4) / 16.0f)) * 16; // 14512; // S.raw_width * 7 / 4; - const unsigned pitch = S.raw_pitch ? S.raw_pitch / 2 : S.raw_width; - unsigned char *buf = (unsigned char *)malloc(linelen); + const unsigned pitch = S.raw_pitch ? S.raw_pitch /( (cps>=3)? 8 : 2) : S.raw_width; + unsigned char *buf = (unsigned char *)calloc(linelen,1); for (int row = 0; row < S.raw_height; row++) { unsigned bytesread = libraw_internal_data.internal_data.input->read(buf, 1, linelen); - unsigned short *dest = &imgdata.rawdata.raw_image[pitch * row]; - // swab32arr((unsigned *)buf, bytesread / 4); - for (unsigned int sp = 0, dp = 0; - dp < pitch - 3 && sp < linelen - 6 && sp < bytesread - 6; - sp += 7, dp += 4) - unpack7bytesto4x16_nikon(buf + sp, dest + dp); + if (cps == 1) + { + unsigned short *dest = &imgdata.rawdata.raw_image[pitch * row]; + // swab32arr((unsigned *)buf, bytesread / 4); + for (unsigned int sp = 0, dp = 0; + dp < pitch - 3 && sp < linelen - 6 && sp < bytesread - 6; + sp += 7, dp += 4) + unpack7bytesto4x16_nikon(buf + sp, dest + dp); + } + else if (cps == 3) + { + unsigned short (*dest)[4] = &imgdata.image[pitch * row]; + // swab32arr((unsigned *)buf, bytesread / 4); + for (unsigned int sp = 0, dp = 0; + dp < pitch - 3 && sp < linelen - 20 && sp < bytesread - 20; + sp += 21, dp += 4) + unpack21bytesto12x16_nikon(buf + sp, dest + dp); + } } free(buf); } @@ -216,7 +263,7 @@ void LibRaw::fuji_14bit_load_raw() { const unsigned linelen = S.raw_width * 7 / 4; const unsigned pitch = S.raw_pitch ? S.raw_pitch / 2 : S.raw_width; - unsigned char *buf = (unsigned char *)malloc(linelen); + unsigned char *buf = (unsigned char *)calloc(linelen,1); for (int row = 0; row < S.raw_height; row++) { @@ -247,7 +294,7 @@ void LibRaw::nikon_load_padded_packed_raw() // 12 bit per pixel, padded to 16 libraw_internal_data.unpacker_data.load_flags > 64000) return; unsigned char *buf = - (unsigned char *)malloc(libraw_internal_data.unpacker_data.load_flags); + (unsigned char *)calloc(libraw_internal_data.unpacker_data.load_flags,1); for (int row = 0; row < S.raw_height; row++) { checkCancel(); @@ -311,7 +358,7 @@ void LibRaw::nikon_load_striped_packed_raw() << i); } imgdata.rawdata.raw_image[(row)*S.raw_width + (col)] = - bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps); + ushort((bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps)) & 0xffff); } vbits -= rbits; } @@ -478,7 +525,7 @@ void LibRaw::panasonicC7_load_raw() const int rowstep = 16; int pixperblock = libraw_internal_data.unpacker_data.pana_bpp == 14 ? 9 : 10; int rowbytes = imgdata.sizes.raw_width / pixperblock * 16; - unsigned char *iobuf = (unsigned char *)malloc(rowbytes * rowstep); + unsigned char *iobuf = (unsigned char *)calloc(rowbytes * rowstep,1); for (int row = 0; row < imgdata.sizes.raw_height - rowstep + 1; row += rowstep) { @@ -540,7 +587,7 @@ void LibRaw::unpacked_load_raw_fuji_f700s20() libraw_internal_data.internal_data.input->seek(-row_size, SEEK_CUR); base_offset = row_size; // in bytes } - unsigned char *buffer = (unsigned char *)malloc(row_size * 2); + unsigned char *buffer = (unsigned char *)calloc(row_size,2); for (int row = 0; row < imgdata.sizes.raw_height; row++) { read_shorts((ushort *)buffer, imgdata.sizes.raw_width * 2); @@ -554,7 +601,7 @@ void LibRaw::nikon_load_sraw() { // We're already seeked to data! unsigned char *rd = - (unsigned char *)malloc(3 * (imgdata.sizes.raw_width + 2)); + (unsigned char *)calloc(3 * (imgdata.sizes.raw_width + 2),1); if (!rd) throw LIBRAW_EXCEPTION_ALLOC; try @@ -639,12 +686,12 @@ void LibRaw::nikon_load_sraw() r = 0.f; if (r > 1.f) r = 1.f; - float g = Y - 0.34414f * (Ch2 - 0.5f) - 0.71414 * (Ch3 - 0.5f); + float g = Y - 0.34414f * (Ch2 - 0.5f) - 0.71414f * (Ch3 - 0.5f); if (g > 1.f) g = 1.f; if (g < 0.f) g = 0.f; - float b = Y + 1.77200 * (Ch2 - 0.5f); + float b = Y + 1.77200f * (Ch2 - 0.5f); if (b > 1.f) b = 1.f; if (b < 0.f) @@ -761,7 +808,7 @@ void decode_S_type(int32_t out_width, uint32_t *img_input, ushort *outbuf /*, in for (int blk_id = 0; blk_id < block_count; ++blk_id) { - int8_t idx_even = stream.peek(7); + int8_t idx_even = int8_t(stream.peek(7)); stream.consume(2); if ((unsigned int)idx_even >= 32) @@ -772,7 +819,7 @@ void decode_S_type(int32_t out_width, uint32_t *img_input, ushort *outbuf /*, in stream.consume(skip_bits[idx_even]); } - int8_t idx_odd = stream.peek(7); + int8_t idx_odd = int8_t(stream.peek(7)); stream.consume(2); if ((unsigned int)idx_odd >= 32) @@ -783,7 +830,7 @@ void decode_S_type(int32_t out_width, uint32_t *img_input, ushort *outbuf /*, in stream.consume(skip_bits[idx_odd]); } - uint8_t bidx = stream.peek(3); + uint8_t bidx = uint8_t(stream.peek(3)); stream.consume(used_corr[bidx]); uint8_t take_bits = init_bits + extra_bits[bidx]; // 11 or less @@ -796,7 +843,7 @@ void decode_S_type(int32_t out_width, uint32_t *img_input, ushort *outbuf /*, in { int32_t value = 0; if (bit_check[i & 1] == 9) - value = stream.get(14); + value = int32_t(stream.get(14)); else value = prev_pix_value[i & 1] + ((uint32_t)stream.get(take_bits) << bp_shift[i & 1]) - pix_sub[i & 1]; @@ -814,7 +861,7 @@ void decode_S_type(int32_t out_width, uint32_t *img_input, ushort *outbuf /*, in do { stream.fill(); - uint32_t pix_value = stream.get(14); + uint32_t pix_value = uint32_t(stream.get(14)); ++block_total_bytes; *outbuf++ = pix_value << pix_corr_shift; } while (block_total_bytes < out_width); diff --git a/rtengine/libraw/src/decoders/decoders_libraw_dcrdefs.cpp b/rtengine/libraw/src/decoders/decoders_libraw_dcrdefs.cpp index 9ce9dd467..483e1260b 100644 --- a/rtengine/libraw/src/decoders/decoders_libraw_dcrdefs.cpp +++ b/rtengine/libraw/src/decoders/decoders_libraw_dcrdefs.cpp @@ -14,6 +14,7 @@ #include "../../internal/dcraw_defs.h" + void LibRaw::packed_tiled_dng_load_raw() { ushort *rp; @@ -87,11 +88,11 @@ void LibRaw::sony_ljpeg_load_raw() break; try { - for (row = jrow = 0; jrow < (unsigned)jh.high; jrow++, row += 2) + for (row = jrow = 0; jrow < (unsigned)jh.high && trow+row < raw_height-1; jrow++, row += 2) { checkCancel(); ushort(*rowp)[4] = (ushort(*)[4])ljpeg_row(jrow, &jh); - for (col = jcol = 0; jcol < (unsigned)jh.wide; jcol++, col += 2) + for (col = jcol = 0; jcol < (unsigned)jh.wide && tcol+col < raw_width-1; jcol++, col += 2) { RAW(trow + row, tcol + col) = rowp[jcol][0]; RAW(trow + row, tcol + col + 1) = rowp[jcol][1]; @@ -129,7 +130,7 @@ void LibRaw::nikon_coolscan_load_raw() int bypp = tiff_bps <= 8 ? 1 : 2; int bufsize = width * clrs * bypp; - unsigned char *buf = (unsigned char *)malloc(bufsize); + unsigned char *buf = (unsigned char *)calloc(bufsize,1); unsigned short *ubuf = (unsigned short *)buf; if (tiff_bps <= 8) @@ -153,16 +154,16 @@ void LibRaw::nikon_coolscan_load_raw() { for (int col = 0; col < width; col++) { - ip[col][0] = ((float)curve[buf[col * 3]]) / 255.0f; - ip[col][1] = ((float)curve[buf[col * 3 + 1]]) / 255.0f; - ip[col][2] = ((float)curve[buf[col * 3 + 2]]) / 255.0f; + ip[col][0] = ushort(((float)curve[buf[col * 3]]) / 255.0f); + ip[col][1] = ushort(((float)curve[buf[col * 3 + 1]]) / 255.0f); + ip[col][2] = ushort(((float)curve[buf[col * 3 + 2]]) / 255.0f); ip[col][3] = 0; } } else { for (int col = 0; col < width; col++) - rp[col] = ((float)curve[buf[col]]) / 255.0f; + rp[col] = ushort(((float)curve[buf[col]]) / 255.0f); } } else if (tiff_bps <= 8) @@ -228,7 +229,7 @@ void LibRaw::android_tight_load_raw() int bwide, row, col, c; bwide = -(-5 * raw_width >> 5) << 3; - data = (uchar *)malloc(bwide); + data = (uchar *)calloc(bwide,1); for (row = 0; row < raw_height; row++) { if (fread(data, 1, bwide, ifp) < bwide) @@ -246,7 +247,7 @@ void LibRaw::android_loose_load_raw() UINT64 bitbuf = 0; bwide = (raw_width + 5) / 6 << 3; - data = (uchar *)malloc(bwide); + data = (uchar *)calloc(bwide,1); for (row = 0; row < raw_height; row++) { if (fread(data, 1, bwide, ifp) < bwide) @@ -289,7 +290,7 @@ void LibRaw::rpi_load_raw8() dwide = raw_width; else dwide = raw_stride; - data = (uchar *)malloc(dwide * 2); + data = (uchar *)calloc(dwide, 2); for (row = 0; row < raw_height; row++) { if (fread(data + dwide, 1, dwide, ifp) < dwide) derror(); FORC(dwide) data[c] = data[dwide + (c ^ rev)]; @@ -320,7 +321,7 @@ void LibRaw::rpi_load_raw12() dwide = (raw_width * 3 + 1) / 2; else dwide = raw_stride; - data = (uchar *)malloc(dwide * 2); + data = (uchar *)calloc(dwide, 2); for (row = 0; row < raw_height; row++) { if (fread(data + dwide, 1, dwide, ifp) < dwide) derror(); FORC(dwide) data[c] = data[dwide + (c ^ rev)]; @@ -351,7 +352,7 @@ void LibRaw::rpi_load_raw14() dwide = ((raw_width * 7) + 3) >> 2; else dwide = raw_stride; - data = (uchar *)malloc(dwide * 2); + data = (uchar *)calloc(dwide, 2); for (row = 0; row < raw_height; row++) { if (fread(data + dwide, 1, dwide, ifp) < dwide) derror(); FORC(dwide) data[c] = data[dwide + (c ^ rev)]; @@ -386,7 +387,7 @@ void LibRaw::rpi_load_raw16() dwide = (raw_width * 2); else dwide = raw_stride; - data = (uchar *)malloc(dwide * 2); + data = (uchar *)calloc(dwide, 2); for (row = 0; row < raw_height; row++) { if (fread(data + dwide, 1, dwide, ifp) < dwide) derror(); FORC(dwide) data[c] = data[dwide + (c ^ rev)]; diff --git a/rtengine/libraw/src/decoders/dng.cpp b/rtengine/libraw/src/decoders/dng.cpp index 4245e52f9..bc8183594 100644 --- a/rtengine/libraw/src/decoders/dng.cpp +++ b/rtengine/libraw/src/decoders/dng.cpp @@ -21,12 +21,12 @@ void LibRaw::vc5_dng_load_raw_placeholder() { // placeholder only, real decoding implemented in GPR SDK - throw LIBRAW_EXCEPTION_DECODE_RAW; + throw LIBRAW_EXCEPTION_UNSUPPORTED_FORMAT; } void LibRaw::jxl_dng_load_raw_placeholder() { // placeholder only, real decoding implemented in DNG SDK - throw LIBRAW_EXCEPTION_DECODE_RAW; + throw LIBRAW_EXCEPTION_UNSUPPORTED_FORMAT; } void LibRaw::adobe_copy_pixel(unsigned row, unsigned col, ushort **rp) @@ -70,7 +70,7 @@ void LibRaw::lossless_dng_load_raw() if (!ljpeg_start(&jh, 0)) break; jwide = jh.wide; - if (filters) + if (filters || colors == 1) jwide *= jh.clrs; if(filters && (tiff_samples == 2)) // Fuji Super CCD @@ -188,12 +188,11 @@ void LibRaw::lossy_dng_load_raw() if (!image) throw LIBRAW_EXCEPTION_IO_CORRUPT; struct jpeg_decompress_struct cinfo; - JSAMPARRAY buf; - JSAMPLE(*pixel)[3]; + unsigned sorder = order, ntags, opcode, deg, i, j, c; unsigned trow = 0, tcol = 0, row, col; INT64 save = data_offset - 4; - ushort cur[3][256]; + ushort cur[4][256]; double coeff[9], tot; if (meta_offset) @@ -212,7 +211,7 @@ void LibRaw::lossy_dng_load_raw() continue; } fseek(ifp, 20, SEEK_CUR); - if ((c = get4()) > 2) + if ((c = get4()) > 3) break; fseek(ifp, 12, SEEK_CUR); if ((deg = get4()) > 8) @@ -231,13 +230,15 @@ void LibRaw::lossy_dng_load_raw() else { gamma_curve(1 / 2.4, 12.92, 1, 255); - FORC3 memcpy(cur[c], curve, sizeof cur[0]); + FORC4 memcpy(cur[c], curve, sizeof cur[0]); } struct jpeg_error_mgr pub; cinfo.err = jpeg_std_error(&pub); pub.error_exit = jpegErrorExit_d; + std::vector buf; + jpeg_create_decompress(&cinfo); while (trow < raw_height) @@ -252,19 +253,24 @@ void LibRaw::lossy_dng_load_raw() } jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); - buf = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, - cinfo.output_width * 3, 1); + if (cinfo.output_components != colors) + throw LIBRAW_EXCEPTION_DECODE_JPEG; + + if (buf.size() < cinfo.output_width * cinfo.output_components) + buf = std::vector(cinfo.output_width * cinfo.output_components,0); + try { + JSAMPLE *buffer_array[1]; + buffer_array[0] = buf.data(); while (cinfo.output_scanline < cinfo.output_height && (row = trow + cinfo.output_scanline) < height) { checkCancel(); - jpeg_read_scanlines(&cinfo, buf, 1); - pixel = (JSAMPLE(*)[3])buf[0]; + jpeg_read_scanlines(&cinfo, buffer_array, 1); for (col = 0; col < cinfo.output_width && tcol + col < width; col++) { - FORC3 image[row * width + tcol + col][c] = cur[c][pixel[col][c]]; + FORC(colors) image[row * width + tcol + col][c] = cur[c][buf[col*colors+c]]; } } } diff --git a/rtengine/libraw/src/decoders/fp_dng.cpp b/rtengine/libraw/src/decoders/fp_dng.cpp index f54a79ef3..e3985e793 100644 --- a/rtengine/libraw/src/decoders/fp_dng.cpp +++ b/rtengine/libraw/src/decoders/fp_dng.cpp @@ -257,8 +257,8 @@ struct tile_stripe_data_t bool tiled, striped; int tileCnt; unsigned tileWidth, tileHeight, tilesH, tilesV; - size_t maxBytesInTile; - std::vector tOffsets, tBytes; + INT64 maxBytesInTile; + std::vector tOffsets, tBytes; tile_stripe_data_t() : tiled(false), striped(false),tileCnt(0), tileWidth(0),tileHeight(0),tilesH(0),tilesV(0), maxBytesInTile(0){} @@ -291,8 +291,8 @@ void tile_stripe_data_t::init(tiff_ifd_t *ifd, const libraw_image_sizes_t& sizes if (tileCnt < 1 || tileCnt > 1000000) throw LIBRAW_EXCEPTION_DECODE_RAW; - tOffsets = std::vector(tileCnt); - tBytes = std::vector (tileCnt); + tOffsets = std::vector(tileCnt,0); + tBytes = std::vector (tileCnt,0); if (tiled) for (int t = 0; t < tileCnt; ++t) @@ -377,8 +377,8 @@ void LibRaw::deflate_dng_load_raw() if(INT64(tiles.maxBytesInTile) > INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024) ) throw LIBRAW_EXCEPTION_TOOBIG; - std::vector cBuffer(tiles.maxBytesInTile); - std::vector uBuffer(tileBytes + tileRowBytes); // extra row for decoding + std::vector cBuffer(tiles.maxBytesInTile,0); + std::vector uBuffer(tileBytes + tileRowBytes,0); // extra row for decoding for (size_t y = 0, t = 0; y < imgdata.sizes.raw_height; y += tiles.tileHeight) { @@ -492,7 +492,7 @@ void LibRaw::convertFloatToInt(float dmin /* =4096.f */, ushort *raw_alloc = (ushort *)malloc( imgdata.sizes.raw_height * imgdata.sizes.raw_width * libraw_internal_data.unpacker_data.tiff_samples * sizeof(ushort)); - float tmax = MAX(imgdata.color.maximum, 1); + float tmax = float(MAX(imgdata.color.maximum, 1)); float datamax = imgdata.color.fmaximum; tmax = MAX(tmax, datamax); @@ -502,15 +502,15 @@ void LibRaw::convertFloatToInt(float dmin /* =4096.f */, if (tmax < dmin || tmax > dmax) { imgdata.rawdata.color.fnorm = imgdata.color.fnorm = multip = dtarget / tmax; - imgdata.rawdata.color.maximum = imgdata.color.maximum = dtarget; + imgdata.rawdata.color.maximum = imgdata.color.maximum = unsigned(dtarget); imgdata.rawdata.color.black = imgdata.color.black = - (float)imgdata.color.black * multip; + unsigned((float)imgdata.color.black * multip); for (int i = 0; i < int(sizeof(imgdata.color.cblack)/sizeof(imgdata.color.cblack[0])); i++) if (i != 4 && i != 5) imgdata.rawdata.color.cblack[i] = imgdata.color.cblack[i] = - (float)imgdata.color.cblack[i] * multip; + unsigned((float)imgdata.color.cblack[i] * multip); } else imgdata.rawdata.color.fnorm = imgdata.color.fnorm = 0.f; @@ -623,7 +623,7 @@ void LibRaw::uncompressed_fp_dng_load_raw() bool difford = (libraw_internal_data.unpacker_data.order == 0x4949) == (ntohs(0x1234) == 0x1234); float max = 0.f; - std::vector rowbuf(tiles.tileWidth *sizeof(float) * ifd->samples); // line buffer for last tile in tile row + std::vector rowbuf(tiles.tileWidth *sizeof(float) * ifd->samples,0); // line buffer for last tile in tile row for (size_t y = 0, t = 0; y < imgdata.sizes.raw_height; y += tiles.tileHeight) { @@ -639,7 +639,7 @@ void LibRaw::uncompressed_fp_dng_load_raw() for (size_t row = 0; row < rowsInTile; ++row) // do not process full tile if not needed { - unsigned char *dst = fullrowbytes > inrowbytes ? rowbuf.data(): // last tile in row, use buffer + unsigned char *dst = fullrowbytes > int(inrowbytes) ? rowbuf.data(): // last tile in row, use buffer (unsigned char *)&float_raw_image [((y + row) * imgdata.sizes.raw_width + x) * ifd->samples]; libraw_internal_data.internal_data.input->read(dst, 1, fullrowbytes); @@ -654,7 +654,7 @@ void LibRaw::uncompressed_fp_dng_load_raw() dst, tiles.tileWidth * ifd->samples, bytesps); - if (fullrowbytes > inrowbytes) // last tile in row: copy buffer to destination + if (fullrowbytes > int(inrowbytes)) // last tile in row: copy buffer to destination memmove(&float_raw_image[((y + row) * imgdata.sizes.raw_width + x) * ifd->samples], dst, outrowbytes); max = MAX(max, lmax); } diff --git a/rtengine/libraw/src/decoders/fuji_compressed.cpp b/rtengine/libraw/src/decoders/fuji_compressed.cpp index 9ca82f6e4..00c6885f1 100644 --- a/rtengine/libraw/src/decoders/fuji_compressed.cpp +++ b/rtengine/libraw/src/decoders/fuji_compressed.cpp @@ -229,6 +229,7 @@ static inline void fuji_fill_buffer(fuji_compressed_block *info) { if (info->cur_pos >= info->cur_buf_size) { + bool needthrow = false; info->cur_pos = 0; info->cur_buf_offset += info->cur_buf_size; #ifdef LIBRAW_USE_OPENMP @@ -252,10 +253,12 @@ static inline void fuji_fill_buffer(fuji_compressed_block *info) info->fillbytes -= ls; } else - throw LIBRAW_EXCEPTION_IO_EOF; + needthrow = true; } info->max_read_size -= info->cur_buf_size; } + if (needthrow) + throw LIBRAW_EXCEPTION_IO_EOF; } } @@ -1151,13 +1154,30 @@ void LibRaw::fuji_decode_loop(fuji_compressed_params *common_info, int count, IN int cur_block; const int lineStep = (libraw_internal_data.unpacker_data.fuji_total_lines + 0xF) & ~0xF; #ifdef LIBRAW_USE_OPENMP -#pragma omp parallel for private(cur_block) + unsigned errcnt = 0; +#pragma omp parallel for private(cur_block) shared(errcnt) #endif for (cur_block = 0; cur_block < count; cur_block++) { - fuji_decode_strip(common_info, cur_block, raw_block_offsets[cur_block], block_sizes[cur_block], - q_bases ? q_bases + cur_block * lineStep : 0); + try + { + fuji_decode_strip(common_info, cur_block, raw_block_offsets[cur_block], block_sizes[cur_block], + q_bases ? q_bases + cur_block * lineStep : 0); + } + catch (...) + { +#ifdef LIBRAW_USE_OPENMP +#pragma omp atomic + errcnt++; +#else + throw; +#endif + } } +#ifdef LIBRAW_USE_OPENMP + if (errcnt) + throw LIBRAW_EXCEPTION_IO_EOF; +#endif } void LibRaw::parse_fuji_compressed_header() diff --git a/rtengine/libraw/src/decoders/generic.cpp b/rtengine/libraw/src/decoders/generic.cpp index b286ed790..09dcf17ec 100644 --- a/rtengine/libraw/src/decoders/generic.cpp +++ b/rtengine/libraw/src/decoders/generic.cpp @@ -74,7 +74,7 @@ void LibRaw::packed_load_raw() for (i = 0; i < bite; i += 8) bitbuf |= (unsigned(fgetc(ifp)) << i); } - val = bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps); + val = int((bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps)) & 0x7fffffff); RAW(row, col ^ (load_flags >> 6 & 1)) = val; if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) && row < height + top_margin && col < width + left_margin) diff --git a/rtengine/libraw/src/decoders/kodak_decoders.cpp b/rtengine/libraw/src/decoders/kodak_decoders.cpp index 0706e4911..f8eb01d83 100644 --- a/rtengine/libraw/src/decoders/kodak_decoders.cpp +++ b/rtengine/libraw/src/decoders/kodak_decoders.cpp @@ -55,7 +55,7 @@ void LibRaw::kodak_radc_load_raw() 3, -49, 3, -9, 3, 9, 4, 49, 5, -79, 5, 79, 2, -1, 2, 13, 2, 26, 3, 39, 4, -16, 5, 55, 6, -37, 6, 76, 2, -26, 2, -13, 2, 1, 3, -39, 4, 16, 5, -55, 6, -76, 6, 37}; - std::vector huff_buffer(19 * 256); + std::vector huff_buffer(19 * 256,0); ushort* huff = &huff_buffer[0]; int row, col, tree, nreps, rep, step, i, c, s, r, x, y, val; short last[3] = {16, 16, 16}, mul[3], buf[3][3][386]; @@ -64,9 +64,9 @@ void LibRaw::kodak_radc_load_raw() for (i = 2; i < 12; i += 2) for (c = pt[i - 2]; c <= pt[i]; c++) - curve[c] = (float)(c - pt[i - 2]) / (pt[i] - pt[i - 2]) * + curve[c] = ushort((float)(c - pt[i - 2]) / (pt[i] - pt[i - 2]) * (pt[i + 1] - pt[i - 1]) + - pt[i - 1] + 0.5; + pt[i - 1] + 0.5f); for (s = i = 0; i < int(sizeof src); i += 2) FORC(256 >> src[i]) ((ushort *)huff)[s++] = src[i] << 8 | (uchar)src[i + 1]; @@ -88,7 +88,8 @@ void LibRaw::kodak_radc_load_raw() x = ~((~0u) << (s - 1)); val <<= 12 - s; for (i = 0; i < int(sizeof(buf[0]) / sizeof(short)); i++) - ((short *)buf[c])[i] = MIN(0x7FFFFFFF, (((short *)buf[c])[i] * static_cast(val) + x)) >> s; + ((short *)buf[c])[i] = + short((MIN(0x7FFFFFFF, (((short *)buf[c])[i] * static_cast(val) + x)) >> s) & 0xffff); last[c] = mul[c]; for (r = 0; r <= int(!c); r++) { @@ -181,15 +182,15 @@ void LibRaw::kodak_jpeg_load_raw() INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024)) throw LIBRAW_EXCEPTION_TOOBIG; - unsigned char *jpg_buf = (unsigned char *)malloc(data_size); - std::vector pixel_buf(width * 3); + unsigned char *jpg_buf = (unsigned char *)calloc(data_size,1); + std::vector pixel_buf(width * 3, 0); jpeg_create_decompress(&cinfo); fread(jpg_buf, data_size, 1, ifp); - libraw_swab(jpg_buf, data_size); + libraw_swab(jpg_buf, int(data_size)); try { - jpeg_mem_src(&cinfo, jpg_buf, data_size); + jpeg_mem_src(&cinfo, jpg_buf, (unsigned long)data_size); int rc = jpeg_read_header(&cinfo, TRUE); if (rc != 1) throw LIBRAW_EXCEPTION_DECODE_JPEG; @@ -369,7 +370,8 @@ int LibRaw::kodak_65000_decode(short *out, int bsize) uchar c, blen[768]; ushort raw[6]; INT64 bitbuf = 0; - int save, bits = 0, i, j, len, diff; + int bits = 0, i, j, len, diff; + INT64 save; save = ftell(ifp); bsize = (bsize + 3) & -4; diff --git a/rtengine/libraw/src/decoders/load_mfbacks.cpp b/rtengine/libraw/src/decoders/load_mfbacks.cpp index 35da14da4..7485c52ef 100644 --- a/rtengine/libraw/src/decoders/load_mfbacks.cpp +++ b/rtengine/libraw/src/decoders/load_mfbacks.cpp @@ -152,7 +152,7 @@ void LibRaw::phase_one_flat_field(int is_float, int nc) for (x = 0; x < wide; x++) for (c = 0; c < (unsigned)nc; c += 2) { - num = is_float ? getreal(LIBRAW_EXIFTAG_TYPE_FLOAT) : get2() / 32768.0; + num = is_float ? getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT) : float(get2()) / 32768.f; if (y == 0) mrow[c * wide + x] = num; else @@ -180,7 +180,7 @@ void LibRaw::phase_one_flat_field(int is_float, int nc) c = nc > 2 ? FC(row - top_margin, col - left_margin) : 0; if (!(c & 1)) { - c = RAW(row, col) * mult[c]; + c = unsigned(RAW(row, col) * mult[c]); RAW(row, col) = LIM(c, 0, 65535); } for (c = 0; c < (unsigned)nc; c += 2) @@ -197,12 +197,14 @@ void LibRaw::phase_one_flat_field(int is_float, int nc) int LibRaw::phase_one_correct() { - unsigned entries, tag, data, save, col, row, type; + unsigned entries, tag, data, col, row, type; + INT64 save; int len, i, j, k, cip, sum; #if 0 int val[4], dev[4], max; #endif - int head[9], diff, mindiff = INT_MAX, off_412 = 0; + int head[9], diff, mindiff = INT_MAX; + INT64 off_412 = 0; /* static */ const signed char dir[12][2] = { {-1, -1}, {-1, 1}, {1, -1}, {1, 1}, {-2, 0}, {0, -2}, {0, 2}, {2, 0}, {-2, -2}, {-2, 2}, {2, -2}, {2, 2}}; @@ -298,24 +300,24 @@ int LibRaw::phase_one_correct() else if (tag == 0x0419) { /* Polynomial curve - output calibraion */ for (get4(), i = 0; i < 8; i++) - poly[i] = getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + poly[i] = getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; for (i = 0; i < 0x10000; i++) { num = (poly[5] * i + poly[3]) * i + poly[1]; - curve[i] = LIM(num, 0, 65535); + curve[i] = ushort(LIM(num, 0, 65535)); } goto apply; /* apply to right half */ } else if (tag == 0x041a) { /* Polynomial curve */ for (i = 0; i < 4; i++) - poly[i] = getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + poly[i] = getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); for (i = 0; i < 0x10000; i++) { for (num = 0, j = 4; j--;) num = num * i + poly[j]; - curve[i] = LIM(num + i, 0, 65535); + curve[i] = ushort(LIM(num + i, 0, 65535)); } apply: /* apply to whole image */ for (row = 0; row < raw_height; row++) @@ -348,7 +350,8 @@ int LibRaw::phase_one_correct() off_412 = ftell(ifp) - 38; } } - else if (tag == 0x041f && !qlin_applied) + else if (tag == 0x041f && !qlin_applied && ph1.split_col > 0 && ph1.split_col < raw_width + && ph1.split_row > 0 && ph1.split_row < raw_height) { /* Quadrant linearization */ ushort lc[2][2][16], ref[16]; int qr, qc; @@ -405,34 +408,35 @@ int LibRaw::phase_one_correct() get4(); get4(); get4(); - qmult[0][0] = 1.0 + getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + qmult[0][0] = 1.0f + getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); get4(); get4(); get4(); get4(); get4(); - qmult[0][1] = 1.0 + getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + qmult[0][1] = 1.0f + getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); get4(); get4(); get4(); - qmult[1][0] = 1.0 + getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + qmult[1][0] = 1.0f + getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); get4(); get4(); get4(); - qmult[1][1] = 1.0 + getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + qmult[1][1] = 1.0f + getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); for (row = 0; row < raw_height; row++) { checkCancel(); for (col = 0; col < raw_width; col++) { - i = qmult[row >= (unsigned)ph1.split_row][col >= (unsigned)ph1.split_col] * - RAW(row, col); + i = int(qmult[row >= (unsigned)ph1.split_row][col >= (unsigned)ph1.split_col] * + RAW(row, col)); RAW(row, col) = LIM(i, 0, 65535); } } qmult_applied = 1; } - else if (tag == 0x0431 && !qmult_applied) + else if (tag == 0x0431 && !qmult_applied && ph1.split_col > 0 && ph1.split_col < raw_width + && ph1.split_row > 0 && ph1.split_row < raw_height) { /* Quadrant combined - four tile gain calibration */ ushort lc[2][2][7], ref[7]; int qr, qc; @@ -490,6 +494,9 @@ int LibRaw::phase_one_correct() fseek(ifp, off_412, SEEK_SET); for (i = 0; i < 9; i++) head[i] = get4() & 0x7fff; + unsigned w0 = head[1] * head[3], w1 = head[2] * head[4]; + if (w0 > 10240000 || w1 > 10240000) + throw LIBRAW_EXCEPTION_ALLOC; yval[0] = (float *)calloc(head[1] * head[3] + head[2] * head[4], 6); yval[1] = (float *)(yval[0] + head[1] * head[3]); xval[0] = (ushort *)(yval[1] + head[2] * head[4]); @@ -497,7 +504,7 @@ int LibRaw::phase_one_correct() get2(); for (i = 0; i < 2; i++) for (j = 0; j < head[i + 1] * head[i + 3]; j++) - yval[i][j] = getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + yval[i][j] = getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); for (i = 0; i < 2; i++) for (j = 0; j < head[i + 1] * head[i + 3]; j++) xval[i][j] = get2(); @@ -507,19 +514,27 @@ int LibRaw::phase_one_correct() for (col = 0; col < raw_width; col++) { cfrac = (float)col * head[3] / raw_width; - cfrac -= cip = cfrac; - num = RAW(row, col) * 0.5; + cip = (int)cfrac; + cfrac -= cip; + num = RAW(row, col) * 0.5f; for (i = cip; i < cip + 2; i++) { for (k = j = 0; j < head[1]; j++) if (num < xval[0][k = head[1] * i + j]) break; - frac = (j == 0 || j == head[1]) - ? 0 - : (xval[0][k] - num) / (xval[0][k] - xval[0][k - 1]); - mult[i - cip] = yval[0][k - 1] * frac + yval[0][k] * (1 - frac); + if (j == 0 || j == head[1] || k < 1 || k >= w0+w1) + frac = 0; + else + { + int xdiv = (xval[0][k] - xval[0][k - 1]); + frac = xdiv ? (xval[0][k] - num) / (xval[0][k] - xval[0][k - 1]) : 0; + } + if (k < w0 + w1) + mult[i - cip] = yval[0][k > 0 ? k - 1 : 0] * frac + yval[0][k] * (1 - frac); + else + mult[i - cip] = 0; } - i = ((mult[0] * (1 - cfrac) + mult[1] * cfrac) * row + num) * 2; + i = int(((mult[0] * (1.f - cfrac) + mult[1] * cfrac) * row + num) * 2.f); RAW(row, col) = LIM(i, 0, 65535); } } @@ -585,7 +600,10 @@ unsigned LibRaw::ph1_bithuff(int nbits, ushort *huff) unsigned c; if (nbits == -1) - return bitbuf = vbits = 0; + { + bitbuf = vbits = 0; + return 0; + } if (nbits == 0) return 0; if (vbits < nbits) @@ -593,7 +611,7 @@ unsigned LibRaw::ph1_bithuff(int nbits, ushort *huff) bitbuf = bitbuf << 32 | get4(); vbits += 32; } - c = bitbuf << (64 - vbits) >> (64 - nbits); + c = unsigned ((bitbuf << (64 - vbits) >> (64 - nbits)) & 0xffffffff); if (huff) { vbits -= huff[c] >> 8; @@ -644,7 +662,7 @@ void LibRaw::phase_one_load_raw_c() } for (i = 0; i < 256; i++) - curve[i] = i * i / 3.969 + 0.5; + curve[i] = ushort(float(i * i) / 3.969f + 0.5f); try { for (row = 0; row < raw_height; row++) diff --git a/rtengine/libraw/src/decoders/olympus14.cpp b/rtengine/libraw/src/decoders/olympus14.cpp new file mode 100644 index 000000000..4fa230efc --- /dev/null +++ b/rtengine/libraw/src/decoders/olympus14.cpp @@ -0,0 +1,318 @@ +/* -*- C++ -*- + * File: pana8.cpp + * Copyright (C) 2024 Alex Tutubalin, LibRaw LLC + * + Olympus/OM System 12/14-bit file decoder + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of two licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + + */ + +#include "../../internal/libraw_cxx_defs.h" +#include + + + struct buffered_bitpump_t +{ + uint32_t bitcount; + uint32_t bitstorage; + LibRaw_abstract_datastream *input; + std::vector buffer; + uint8_t *bufp; + int pos, datasz; + bool is_buf; + buffered_bitpump_t(LibRaw_abstract_datastream *in, int bufsz) : bitcount(0), bitstorage(0), input(in), + buffer(bufsz),pos(0),datasz(0) + { + is_buf = input->is_buffered(); + input->buffering_off(); + bufp = buffer.data(); + } + ~buffered_bitpump_t() + { + if (is_buf) + input->buffering_on(); + } +void skip_bit(uint32_t &vbits) + { + if (!vbits) + { + replace_data(); + vbits = --bitcount; + } + else + bitcount = --vbits; + } + void replace_data() + { + bitstorage = get4(); + bitcount = 32; + } + + uint32_t add_data() + { + uint32_t bb = get2(); + bitstorage = bitstorage << 16 | bb; + bitcount += 16; + return bitcount; + } + uint32_t getbits(unsigned wbits) + { + while (bitcount < wbits) + add_data(); + uint32_t ret = bitstorage << (32 - (bitcount & 0x1f)) >> (32 - wbits); + bitcount -= wbits; + return ret; + } + uint32_t get2() + { + if (pos < datasz - 1) + { + uint32_t ret = bufp[pos] << 8 | bufp[pos + 1]; + pos += 2; + return ret; + } + uint8_t b[2]; + int i = 0; + while (pos < datasz) + b[i++] = bufp[pos++]; + refill(2); + for (; i < 2; i++) + b[i] = bufp[pos++]; + return b[0] << 8 | b[1]; + } + + uint32_t get4() + { + if (pos < datasz - 3) + { + uint32_t ret = bufp[pos] << 24 | bufp[pos + 1] << 16 | bufp[pos + 2] << 8 | bufp[pos + 3]; + pos += 4; + return ret; + } + uint8_t b[4]; + int i = 0; + while (pos < datasz) + b[i++] = bufp[pos++]; + refill(4); + for (; i < 4; i++) + b[i] = bufp[pos++]; + return b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3]; + } + void refill(int b) + { + int r = input->read(bufp, 1, buffer.size()); + pos = 0; + datasz = r > b ? r : b; + } +}; + + +static bool checkhdr(LibRaw_abstract_datastream *ifp, int bytes) +{ + if (bytes <= 0) return false; + uint64_t b64 = 0ULL; + for(int i = 0; i < bytes; i++) + { + uint8_t databyte1 = (uint8_t)ifp->get_char(); + uint64_t q = (b64 << 8) | databyte1; + b64 = q; + } + if (b64 != 1ULL) + return false; + if (ifp->get_char() | ifp->get_char()) + return false; + return true; +} + +static +#ifdef _MSC_VER + __forceinline +#else + inline +#endif +int32_t _local_iabs(int32_t x){ return (x ^ (x >> 31)) - (x >> 31);} + +static +#ifdef _MSC_VER +__forceinline +#else +inline +#endif +int32_t oly_code(buffered_bitpump_t *th, unsigned int wbits, unsigned int tag0x640, + unsigned int tag0x643, int tag0x652, + int *glc, int *t640bits, int *t643bits) +{ + int highdatabit; + + if (!th->bitcount) + th->replace_data(); + + int v = --th->bitcount; + highdatabit = (th->bitstorage >> v) & 1; + *t643bits = tag0x643 ? th->getbits(tag0x643) : 0; + *t640bits = tag0x640 ? th->getbits(tag0x640) : 0; + + uint32_t vbits = th->bitcount; + uint32_t high = 0; + uint32_t low = 0; + + while (1) + { + th->skip_bit(vbits); + if ((th->bitstorage >> vbits) & 1) + break; + if ((uint32_t)tag0x652 == ++high) + { + high = 0; + if (wbits != 15) + { + uint32_t i; + for (i = 15 - wbits; vbits < i;) + vbits = th->add_data(); + + high = th->bitstorage << (32 - (vbits & 0x1f)) >> (wbits + 17); + vbits -= i; + th->bitcount = vbits; + } + th->skip_bit(vbits); + break; + } + } + + if (wbits < 1) + low = 0; + else + { + while (vbits < wbits) + vbits = th->add_data(); + low = th->bitstorage << (32 - (vbits & 0x1f)) >> (32 - (wbits & 0x1f)); + th->bitcount = vbits - wbits; + } + *glc = low | (high << wbits); + int32_t result = *glc ^ (unsigned int)(-highdatabit); + return result; +} + + + +void LibRaw::olympus14_load_raw() +{ + if (!checkhdr(libraw_internal_data.internal_data.input, imgdata.makernotes.olympus.tagX653)) + throw LIBRAW_EXCEPTION_IO_CORRUPT; + + const int32_t tag0x640 = imgdata.makernotes.olympus.tagX640; // usually 0 + const uint32_t tag0x643 = imgdata.makernotes.olympus.tagX643; // usually 2 + + uint32_t context[4] = { 0,0,0,0 }; + buffered_bitpump_t pump(libraw_internal_data.internal_data.input, 65536); + + const int32_t one_shl_tag0x641 = 1 << imgdata.makernotes.olympus.tagX641; + const int32_t tag0x642 = imgdata.makernotes.olympus.tagX642; + const int32_t tag0x644 = imgdata.makernotes.olympus.tagX644; + const int32_t one_shl_tag645 = 1 << (imgdata.makernotes.olympus.tagX645 & 0x1f); + const int32_t tag0x646 = imgdata.makernotes.olympus.tagX646; + const int32_t tag0x647 = imgdata.makernotes.olympus.tagX647; + const int32_t tag0x648 = imgdata.makernotes.olympus.tagX648; + const int32_t tag0x649 = imgdata.makernotes.olympus.tagX649; + const int32_t tag0x650 = imgdata.makernotes.olympus.tagX650; + const int32_t tag0x651 = imgdata.makernotes.olympus.tagX651; + const int32_t tag0x652 = MAX(1, imgdata.makernotes.olympus.tagX652); + const uint16_t datamax = 1< bitcounts(65536); + bitcounts[0] = 0; + for (int i = 0, n = 1; i < 16; i++) + for (int j = 0; j < 1 << i; j++) + bitcounts[n++] = i+1; + + int32_t lpred = 0, pred1 = 0, glc = 0, gcode=0; + + for (uint32_t row = 0; row < imgdata.sizes.raw_height; row++) + { + checkCancel(); + for (uint32_t col = 0; col < raw_width; col++) + { + int32_t wbits, vbits, t640bits, t643bits; + int32_t p = gcode; + gcode = glc; + int32_t psel = ((col>1) && one_shl_tag645 >= p) ? context[3] + 1 : 0; + context[3] = context[2]; + context[2] = psel; + if (col>1) + { + int highbitcount = bitcounts[p & 0xffff]; + int32_t T1 = ((col > 1) && (psel >= tag0x646)) ? tag0x648 : tag0x650; + int32_t T2 = ((col > 1) && (psel >= tag0x646)) ? tag0x647 : tag0x649; + int32_t TT = MAX((highbitcount - T1),-1); + wbits = T2 + TT + 1; + } + else + wbits = tag0x649; + + if (wbits > tag0x651) + wbits = tag0x651; + + int32_t gcode = oly_code(&pump, wbits, tag0x640, tag0x643, tag0x652, &glc, &t640bits, &t643bits); + if (tag0x643) + { + if (tag0x643 == 1) + { + int32_t v = col<2 ? 0 : pred1; + gcode = t643bits + 2 * (v + gcode); + vbits = v + (gcode >> 1); + } + else + { + int32_t v = col<2 ? 0 : pred1; + gcode = t643bits + 4 * (v + gcode); + vbits = ((gcode >> 1) & 0xFFFFFFFE) + v + (gcode >> 2); + } + } + else + vbits = 0; + + pred1 = context[0]; + context[0] = (tag0x644 == 15) ? 0 : vbits >> tag0x644; + int32_t W = col < 2 ? tag0x642 : context[1]; + int32_t N = row < 2 ? tag0x642 : raw_image[(row - 2) * raw_width + col] >> tag0x640; + int32_t NW = (row < 2 || col < 2)? tag0x642 : NW = raw_image[(row - 2) * raw_width + col - 2] >> tag0x640; + + context[1] = lpred; + if ((W < N) || (NW < W)) + { + if (NW <= N && W >= N) + N = W; + else if (NW < N || W >= N) + { + if (NW > W || W >= N) + { + if (_local_iabs(N - NW) > one_shl_tag0x641) + N += W - NW; + else if (_local_iabs(W - NW) <= one_shl_tag0x641) + N = (N + W) >> 1; + else + N = N + W - NW; + } + } + else + N = W; + } + lpred = gcode + N; + uint32_t pixel_final_value = t640bits + ((gcode + N) << tag0x640); + if(((raw_image[row * raw_width + col] = (ushort)pixel_final_value) > datamax) + && col >= imgdata.sizes.width) + derror(); + } + } +} diff --git a/rtengine/libraw/src/decoders/pana8.cpp b/rtengine/libraw/src/decoders/pana8.cpp index 909c9bd8b..682960923 100644 --- a/rtengine/libraw/src/decoders/pana8.cpp +++ b/rtengine/libraw/src/decoders/pana8.cpp @@ -1,6 +1,6 @@ /* -*- C++ -*- * File: pana8.cpp - * Copyright (C) 2022-2024 Alex Tutubalin, LibRaw LLC + * Copyright (C) 2022 Alex Tutubalin, LibRaw LLC * Panasonic RawFormat=8 file decoder diff --git a/rtengine/libraw/src/decoders/smal.cpp b/rtengine/libraw/src/decoders/smal.cpp index eeab2f006..22e70e9e6 100644 --- a/rtengine/libraw/src/decoders/smal.cpp +++ b/rtengine/libraw/src/decoders/smal.cpp @@ -166,12 +166,12 @@ void LibRaw::smal_v9_load_raw() nseg = (uchar)fgetc(ifp); fseek(ifp, offset, SEEK_SET); for (i = 0; i < nseg * 2; i++) - ((unsigned *)seg)[i] = get4() + data_offset * (i & 1); + ((unsigned *)seg)[i] = get4() + unsigned(data_offset & 0xffffffff) * (i & 1); fseek(ifp, 78, SEEK_SET); holes = fgetc(ifp); fseek(ifp, 88, SEEK_SET); seg[nseg][0] = raw_height * raw_width; - seg[nseg][1] = get4() + data_offset; + seg[nseg][1] = get4() + unsigned(data_offset & 0xffffffff); for (i = 0; i < nseg; i++) smal_decode_segment(seg + i, holes); if (holes) diff --git a/rtengine/libraw/src/decoders/sonycc.cpp b/rtengine/libraw/src/decoders/sonycc.cpp index 7d3cd4174..95b9eabd4 100644 --- a/rtengine/libraw/src/decoders/sonycc.cpp +++ b/rtengine/libraw/src/decoders/sonycc.cpp @@ -1,6 +1,6 @@ /* -*- C++ -*- * File: sonycc.cpp - * Copyright (C) 2023-2024 Alex Tutubalin, LibRaw LLC + * Copyright (C) 2024 Alex Tutubalin, LibRaw LLC * Sony YCC (small/medium lossy compressed) decoder @@ -66,11 +66,11 @@ void copy_yuv_420(uint16_t *out, uint32_t row, uint32_t col, uint32_t width, bool LibRaw_SonyYCC_Decompressor::decode_sony_ljpeg_420(std::vector &_dest, int width, int height) { - if (sof.width * 3 != width || sof.height != height) + if (sof.width * 3 != unsigned(width) || sof.height != unsigned(height)) return false; if (width % 2 || width % 6 || height % 2) return false; - if (_dest.size() < width*height) + if (_dest.size() < size_t(width*height)) return false; HuffTable &huff1 = dhts[sof.components[0].dc_tbl]; @@ -94,10 +94,10 @@ bool LibRaw_SonyYCC_Decompressor::decode_sony_ljpeg_420(std::vector &_ uint16_t *dest = _dest.data(); copy_yuv_420(dest, 0, 0, width, y1, y2, y3, y4, cb, cr); - for (uint32_t row = 0; row < height; row += 2) + for (int32_t row = 0; row < height; row += 2) { - uint32_t startcol = row == 0 ? 6 : 0; - for (uint32_t col = startcol; col < width; col += 6) + int32_t startcol = row == 0 ? 6 : 0; + for (int32_t col = startcol; col < width; col += 6) { int32_t py1, py3, pcb, pcr; if (col == 0) @@ -271,7 +271,7 @@ void LibRaw::sony_ycbcr_load_raw() { ifp->seek(toffsets[tile],SEEK_SET); int readed = ifp->read(iobuffer.data(), 1, tlengths[tile]); - if(readed != tlengths[tile]) + if(unsigned(readed) != tlengths[tile]) throw LIBRAW_EXCEPTION_IO_EOF; LibRaw_SonyYCC_Decompressor dec(iobuffer.data(), readed); if(dec.sof.cps != 3) // !YUV diff --git a/rtengine/libraw/src/decoders/unpack.cpp b/rtengine/libraw/src/decoders/unpack.cpp index c4f3359e7..1804fd594 100644 --- a/rtengine/libraw/src/decoders/unpack.cpp +++ b/rtengine/libraw/src/decoders/unpack.cpp @@ -54,7 +54,11 @@ int LibRaw::unpack(void) throw LIBRAW_EXCEPTION_TOOBIG; libraw_internal_data.internal_data.meta_data = +#ifdef LIBRAW_CALLOC_RAWSTORE + (char *)calloc(libraw_internal_data.unpacker_data.meta_length,1); +#else (char *)malloc(libraw_internal_data.unpacker_data.meta_length); +#endif } libraw_decoder_info_t decoder_info; @@ -106,6 +110,7 @@ int LibRaw::unpack(void) #endif #ifdef USE_RAWSPEED3 if (!raw_was_read() + && ID.input->size() < 2147483615LL && (!IO.fuji_width) // Do not use for fuji rotated && ((imgdata.idata.raw_count == 1) // Canon dual pixel, 1st frame @@ -167,11 +172,7 @@ int LibRaw::unpack(void) throw "Size mismatch"; // DECODED w/ success - if (rs3ret.filters > 1) // Fuji or bayer - { - imgdata.rawdata.raw_image = (ushort*)rs3ret.pixeldata; - } - else if (rs3ret.cpp == 4) + if (rs3ret.cpp == 4) { imgdata.rawdata.color4_image = (ushort(*)[4])rs3ret.pixeldata; //if (r->whitePoint > 0 && r->whitePoint < 65536) @@ -183,6 +184,10 @@ int LibRaw::unpack(void) //if (r->whitePoint > 0 && r->whitePoint < 65536) // C.maximum = r->whitePoint; } + else if (rs3ret.cpp == 1 && rs3ret.filters > 1) // Fuji or bayer + { + imgdata.rawdata.raw_image = (ushort *)rs3ret.pixeldata; + } if (raw_was_read()) // buffers are assigned above { @@ -196,8 +201,8 @@ int LibRaw::unpack(void) load_raw == &LibRaw::phase_one_load_raw_c && imgdata.color.phase_one_data.format != 8) { // Scale data to match libraw own decoder - for (int row = 0; row < rs3ret.height; row++) - for (int col = 0; col < rs3ret.pitch / 2; col++) + for (unsigned row = 0; row < rs3ret.height; row++) + for (unsigned col = 0; col < rs3ret.pitch / 2; col++) imgdata.rawdata.raw_image[row * rs3ret.pitch / 2 + col] <<= 2; } @@ -217,7 +222,7 @@ int LibRaw::unpack(void) } #endif #ifdef USE_RAWSPEED - if (!raw_was_read()) + if (!raw_was_read() && ID.input->size() < 2147483615LL) { int rawspeed_enabled = 1; @@ -325,8 +330,12 @@ int LibRaw::unpack(void) + +INT64(libraw_internal_data.unpacker_data.meta_length) > INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024)) throw LIBRAW_EXCEPTION_TOOBIG; +#ifdef LIBRAW_CALLOC_RAWSTORE + imgdata.rawdata.raw_alloc = calloc(size_t(rwidth) * (size_t(rheight) + 8), sizeof(imgdata.rawdata.raw_image[0])); +#else imgdata.rawdata.raw_alloc = malloc( - rwidth * (rheight + 8) * sizeof(imgdata.rawdata.raw_image[0])); + size_t(rwidth) * (size_t(rheight) + 8) * sizeof(imgdata.rawdata.raw_image[0])); +#endif imgdata.rawdata.raw_image = (ushort *)imgdata.rawdata.raw_alloc; if (!S.raw_pitch) S.raw_pitch = S.raw_width * 2; // Bayer case, not set before @@ -340,10 +349,15 @@ int LibRaw::unpack(void) throw LIBRAW_EXCEPTION_TOOBIG; S.raw_pitch = S.raw_width * 8; imgdata.rawdata.raw_alloc = 0; +#ifdef LIBRAW_CALLOC_RAWSTORE imgdata.image = (ushort(*)[4])calloc( - unsigned(MAX(S.width, S.raw_width)) * - unsigned(MAX(S.height, S.raw_height) + 8), + size_t(MAX(S.width, S.raw_width)) * + (size_t(MAX(S.height, S.raw_height)) + 8), sizeof(*imgdata.image)); +#else + imgdata.image = (ushort(*)[4])malloc( + size_t(MAX(S.width, S.raw_width)) * (size_t(MAX(S.height, S.raw_height)) + 8) * sizeof(*imgdata.image)); +#endif } } else if (decoder_info.decoder_flags & LIBRAW_DECODER_3CHANNEL) @@ -354,8 +368,13 @@ int LibRaw::unpack(void) INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024)) throw LIBRAW_EXCEPTION_TOOBIG; +#ifdef LIBRAW_CALLOC_RAWSTORE + imgdata.rawdata.raw_alloc = + calloc(size_t(rwidth) * (size_t(rheight) + 8), sizeof(imgdata.rawdata.raw_image[0]) * 3); +#else imgdata.rawdata.raw_alloc = malloc( - rwidth * (rheight + 8) * sizeof(imgdata.rawdata.raw_image[0]) * 3); + size_t(rwidth) * (size_t(rheight) + 8) * sizeof(imgdata.rawdata.raw_image[0]) * 3); +#endif imgdata.rawdata.color3_image = (ushort(*)[3])imgdata.rawdata.raw_alloc; if (!S.raw_pitch) S.raw_pitch = S.raw_width * 6; @@ -369,8 +388,13 @@ int LibRaw::unpack(void) + INT64(libraw_internal_data.unpacker_data.meta_length) > INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024)) throw LIBRAW_EXCEPTION_TOOBIG; +#ifdef LIBRAW_CALLOC_RAWSTORE + imgdata.rawdata.raw_alloc = + calloc(size_t(rwidth) * (size_t(rheight) + 8),sizeof(imgdata.rawdata.raw_image[0])); +#else imgdata.rawdata.raw_alloc = malloc( - rwidth * (rheight + 8) * sizeof(imgdata.rawdata.raw_image[0])); + size_t(rwidth) * (size_t(rheight) + 8) * sizeof(imgdata.rawdata.raw_image[0])); +#endif imgdata.rawdata.raw_image = (ushort *)imgdata.rawdata.raw_alloc; if (!S.raw_pitch) S.raw_pitch = S.raw_width * 2; // Bayer case, not set before diff --git a/rtengine/libraw/src/decoders/unpack_thumb.cpp b/rtengine/libraw/src/decoders/unpack_thumb.cpp index 1082b9326..a8546b66e 100644 --- a/rtengine/libraw/src/decoders/unpack_thumb.cpp +++ b/rtengine/libraw/src/decoders/unpack_thumb.cpp @@ -155,7 +155,11 @@ int LibRaw::unpack_thumb(void) THUMB_SIZE_CHECKTNZ(T.tlength); if (T.thumb) free(T.thumb); +#ifdef LIBRAW_CALLOC_RAWSTORE + T.thumb = (char *)calloc(T.tlength,1); +#else T.thumb = (char *)malloc(T.tlength); +#endif if(!T.thumb) return LIBRAW_NO_THUMBNAIL; ID.input->read(T.thumb, 1, T.tlength); @@ -331,11 +335,15 @@ int LibRaw::unpack_thumb(void) else if (total_size == T.twidth * T.tlength) T.tcolors = 1; } - T.tlength = total_size; + T.tlength = unsigned(total_size); THUMB_SIZE_CHECKTNZ(T.tlength); if (T.thumb) free(T.thumb); +#ifdef LIBRAW_CALLOC_RAWSTORE + T.thumb = (char *)calloc(T.tlength,1); +#else T.thumb = (char *)malloc(T.tlength); +#endif if (!T.thumb) return LIBRAW_NO_THUMBNAIL; @@ -371,7 +379,11 @@ int LibRaw::unpack_thumb(void) THUMB_SIZE_CHECKTNZ(T.tlength); +#ifdef LIBRAW_CALLOC_RAWSTORE + T.thumb = (char *)calloc(T.tlength,1); +#else T.thumb = (char *)malloc(T.tlength); +#endif if (!T.thumb) return LIBRAW_NO_THUMBNAIL; if (!T.tcolors) @@ -413,7 +425,11 @@ int LibRaw::unpack_thumb(void) } else { +#ifdef LIBRAW_CALLOC_RAWSTORE + T.thumb = (char *)calloc(o_length,1); +#else T.thumb = (char *)malloc(o_length); +#endif if (!T.thumb) { free(t_thumb); diff --git a/rtengine/libraw/src/decompressors/losslessjpeg.cpp b/rtengine/libraw/src/decompressors/losslessjpeg.cpp index 538c2cb23..131bf979b 100644 --- a/rtengine/libraw/src/decompressors/losslessjpeg.cpp +++ b/rtengine/libraw/src/decompressors/losslessjpeg.cpp @@ -1,6 +1,6 @@ /* -*- C++ -*- * File: huffmandec.cpp - * Copyright (C) 2023-2024 Alex Tutubalin, LibRaw LLC + * Copyright (C) 2024 Alex Tutubalin, LibRaw LLC * Lossless JPEG decoder @@ -170,8 +170,8 @@ bool LibRaw_LjpegDecompressor::parse_dht(bool init[4], uint32_t bits[4][17], uin return false; if (length < 1 + 16 + acc) - return 0xff; - for (int i = 0; i < acc; i++) + return false; + for (uint32_t i = 0; i < acc; i++) huffval[th][i] = buffer.get_u8(); init[th] = true; @@ -202,12 +202,15 @@ void copy_yuv_422(uint16_t *out, uint32_t row, uint32_t col, uint32_t width, int bool LibRaw_LjpegDecompressor::decode_ljpeg_422(std::vector &_dest, int width, int height) { - if (sof.width * 3 != width || sof.height != height) + if (sof.width * 3u != unsigned(width) || sof.height != unsigned(height)) return false; if (width % 2 || width % 6 || height % 2) return false; - if (_dest.size() < width * height) + if (_dest.size() < size_t(width * height)) + return false; + + if(width < 1 || height < 1) return false; uint16_t *dest = _dest.data(); @@ -228,20 +231,20 @@ bool LibRaw_LjpegDecompressor::decode_ljpeg_422(std::vector &_dest, in int32_t cr = base + h3.decode(pump); copy_yuv_422(dest, 0, 0, width, y1, y2, cb, cr); - for (uint32_t row = 0; row < height; row++) + for (uint32_t row = 0; row < uint32_t(height); row++) { uint32_t startcol = row == 0 ? 6 : 0; - for (uint32_t col = startcol; col < width; col += 6) + for (uint32_t col = startcol; col < uint32_t(width); col += 6) { uint32_t pos = (col == 0) ? (row - 1) * width : row * width + col - 3; int32_t py = dest[pos], pcb = dest[pos + 1], pcr = dest[pos + 2]; - int32_t y1 = py + h1.decode(pump); - int32_t y2 = y1 + h1.decode(pump); - int32_t cb = pcb + h2.decode(pump); - int32_t cr = pcr + h3.decode(pump); - copy_yuv_422(dest, row, col, width, y1, y2, cb, cr); + int32_t _y1 = py + h1.decode(pump); + int32_t _y2 = _y1 + h1.decode(pump); + int32_t _cb = pcb + h2.decode(pump); + int32_t _cr = pcr + h3.decode(pump); + copy_yuv_422(dest, row, col, width, _y1, _y2, _cb, _cr); } } return true; @@ -263,7 +266,7 @@ bool LibRaw_SOFInfo::parse_sof(ByteStreamBE& input) return false; components.clear(); - for (int i = 0; i < cps; i++) + for (unsigned i = 0; i < cps; i++) { unsigned id = input.get_u8(); unsigned subs = input.get_u8(); @@ -288,7 +291,7 @@ uint32_t LibRaw_SOFInfo::parse_sos(ByteStreamBE& input) uint32_t readcs = input.get_u8(); uint32_t cs = csfix ? csi : readcs; // csfix might be used in MOS decoder int cid = -1; - for(int c = 0; c < components.size(); c++) + for(unsigned c = 0; c < components.size(); c++) if (components[c].id == cs) { cid = c; @@ -357,14 +360,14 @@ void HuffTable::initval(uint32_t _bits[17], uint32_t _huffval[256], bool _dng_bu break; nbits--; } - hufftable.resize(1 << nbits); - for (int i = 0; i < hufftable.size(); i++) hufftable[i] = 0; + hufftable.resize( size_t(1ULL << nbits)); + for (unsigned i = 0; i < hufftable.size(); i++) hufftable[i] = 0; int h = 0; int pos = 0; for (uint8_t len = 0; len < nbits; len++) { - for (int i = 0; i < bits[len + 1]; i++) + for (uint32_t i = 0; i < bits[len + 1]; i++) { for (int j = 0; j < (1 << (nbits - len - 1)); j++) { diff --git a/rtengine/libraw/src/demosaic/aahd_demosaic.cpp b/rtengine/libraw/src/demosaic/aahd_demosaic.cpp index 942176566..ce058cd7e 100644 --- a/rtengine/libraw/src/demosaic/aahd_demosaic.cpp +++ b/rtengine/libraw/src/demosaic/aahd_demosaic.cpp @@ -63,18 +63,18 @@ struct AAHD } int inline Y(ushort3 &rgb) throw() { - return yuv_cam[0][0] * rgb[0] + yuv_cam[0][1] * rgb[1] + - yuv_cam[0][2] * rgb[2]; + return int(yuv_cam[0][0] * rgb[0] + yuv_cam[0][1] * rgb[1] + + yuv_cam[0][2] * rgb[2]); } int inline U(ushort3 &rgb) throw() { - return yuv_cam[1][0] * rgb[0] + yuv_cam[1][1] * rgb[1] + - yuv_cam[1][2] * rgb[2]; + return int(yuv_cam[1][0] * rgb[0] + yuv_cam[1][1] * rgb[1] + + yuv_cam[1][2] * rgb[2]); } int inline V(ushort3 &rgb) throw() { - return yuv_cam[2][0] * rgb[0] + yuv_cam[2][1] * rgb[1] + - yuv_cam[2][2] * rgb[2]; + return int(yuv_cam[2][0] * rgb[0] + yuv_cam[2][1] * rgb[1] + + yuv_cam[2][2] * rgb[2]); } inline int nr_offset(int row, int col) throw() { @@ -307,7 +307,7 @@ void AAHD::evaluate_ahd() ushort3 rgb; for (int c = 0; c < 3; ++c) { - rgb[c] = gammaLUT[rgb_ahd[d][i][c]]; + rgb[c] = ushort(gammaLUT[rgb_ahd[d][i][c]]); } yuv[d][i][0] = Y(rgb); yuv[d][i][1] = U(rgb); @@ -363,7 +363,7 @@ void AAHD::evaluate_ahd() ynr = &yuv[d][moff]; for (int k = 0; k < 4; k++) { - ydiff[d][k] = ABS(ynr[0][0] - ynr[hvdir[k]][0]); + ydiff[d][k] = float(ABS(ynr[0][0] - ynr[hvdir[k]][0])); uvdiff[d][k] = SQR(ynr[0][1] - ynr[hvdir[k]][1]) + SQR(ynr[0][2] - ynr[hvdir[k]][2]); } @@ -606,9 +606,9 @@ void AAHD::make_ahd_gline(int i) min -= min / OverFraction; max += max / OverFraction; if (eg < min) - eg = min - sqrt(float(min - eg)); + eg = min - int(sqrtf(float(min - eg))); else if (eg > max) - eg = max + sqrt(float(eg - max)); + eg = max + int(sqrtf(float(eg - max))); if (eg > channel_maximum[1]) eg = channel_maximum[1]; else if (eg < channel_minimum[1]) diff --git a/rtengine/libraw/src/demosaic/ahd_demosaic.cpp b/rtengine/libraw/src/demosaic/ahd_demosaic.cpp index 8d32d6cd1..70f5fc337 100644 --- a/rtengine/libraw/src/demosaic/ahd_demosaic.cpp +++ b/rtengine/libraw/src/demosaic/ahd_demosaic.cpp @@ -41,15 +41,15 @@ void LibRaw::cielab(ushort rgb[3], short lab[3]) #endif for (i = 0; i < 0x10000; i++) { - r = i / 65535.0; + r = i / 65535.0f; cbrt[i] = - r > 0.008856 ? pow(r, 1.f / 3.0f) : 7.787f * r + 16.f / 116.0f; + r > 0.008856f ? pow(r, 1.f / 3.0f) : 7.787f * r + 16.f / 116.0f; } for (i = 0; i < 3; i++) for (j = 0; j < colors; j++) - for (xyz_cam[i][j] = k = 0; k < 3; k++) - xyz_cam[i][j] += LibRaw_constants::xyz_rgb[i][k] * rgb_cam[k][j] / - LibRaw_constants::d65_white[i]; + for (xyz_cam[i][j] = float( k = 0); k < 3; k++) + xyz_cam[i][j] += float(LibRaw_constants::xyz_rgb[i][k] * rgb_cam[k][j] / + LibRaw_constants::d65_white[i]); return; } xyz[0] = xyz[1] = xyz[2] = 0.5; @@ -62,9 +62,9 @@ void LibRaw::cielab(ushort rgb[3], short lab[3]) xyz[0] = cbrt[CLIP((int)xyz[0])]; xyz[1] = cbrt[CLIP((int)xyz[1])]; xyz[2] = cbrt[CLIP((int)xyz[2])]; - lab[0] = 64 * (116 * xyz[1] - 16); - lab[1] = 64 * 500 * (xyz[0] - xyz[1]); - lab[2] = 64 * 200 * (xyz[1] - xyz[2]); + lab[0] = short(64 * (116 * xyz[1] - 16)); + lab[1] = short(64 * 500 * (xyz[0] - xyz[1])); + lab[2] = short(64 * 200 * (xyz[1] - xyz[2])); #ifndef LIBRAW_NOTHREADS #undef cbrt #undef xyz_cam diff --git a/rtengine/libraw/src/demosaic/dcb_demosaic.cpp b/rtengine/libraw/src/demosaic/dcb_demosaic.cpp index f25292b9a..1eadb3592 100644 --- a/rtengine/libraw/src/demosaic/dcb_demosaic.cpp +++ b/rtengine/libraw/src/demosaic/dcb_demosaic.cpp @@ -51,7 +51,7 @@ void LibRaw::dcb_ver(float (*image3)[3]) col += 2, indx += 2) { - image3[indx][1] = CLIP((image[indx + u][1] + image[indx - u][1]) / 2.0); + image3[indx][1] = float(CLIP((image[indx + u][1] + image[indx - u][1]) / 2.0)); } } @@ -65,7 +65,7 @@ void LibRaw::dcb_hor(float (*image2)[3]) col += 2, indx += 2) { - image2[indx][1] = CLIP((image[indx + 1][1] + image[indx - 1][1]) / 2.0); + image2[indx][1] = float(CLIP((image[indx + 1][1] + image[indx - 1][1]) / 2.0)); } } @@ -117,12 +117,14 @@ void LibRaw::dcb_color2(float (*image2)[3]) { image2[indx][c] = + float( CLIP((4 * image2[indx][1] - image2[indx + u + 1][1] - image2[indx + u - 1][1] - image2[indx - u + 1][1] - image2[indx - u - 1][1] + image[indx + u + 1][c] + image[indx + u - 1][c] + image[indx - u + 1][c] + image[indx - u - 1][c]) / - 4.0); + 4.0) + ); } for (row = 1; row < height - 1; row++) @@ -131,11 +133,11 @@ void LibRaw::dcb_color2(float (*image2)[3]) col < width - 1; col += 2, indx += 2) { - image2[indx][c] = CLIP((image[indx + 1][c] + image[indx - 1][c]) / 2.0); + image2[indx][c] = float(CLIP((image[indx + 1][c] + image[indx - 1][c]) / 2.0)); image2[indx][d] = - CLIP((2 * image2[indx][1] - image2[indx + u][1] - + float(CLIP((2 * image2[indx][1] - image2[indx + u][1] - image2[indx - u][1] + image[indx + u][d] + image[indx - u][d]) / - 2.0); + 2.0)); } } @@ -151,12 +153,14 @@ void LibRaw::dcb_color3(float (*image3)[3]) { image3[indx][c] = + float( CLIP((4 * image3[indx][1] - image3[indx + u + 1][1] - image3[indx + u - 1][1] - image3[indx - u + 1][1] - image3[indx - u - 1][1] + image[indx + u + 1][c] + image[indx + u - 1][c] + image[indx - u + 1][c] + image[indx - u - 1][c]) / - 4.0); + 4.0) + ); } for (row = 1; row < height - 1; row++) @@ -166,10 +170,12 @@ void LibRaw::dcb_color3(float (*image3)[3]) { image3[indx][c] = + float( CLIP((2 * image3[indx][1] - image3[indx + 1][1] - image3[indx - 1][1] + image[indx + 1][c] + image[indx - 1][c]) / - 2.0); - image3[indx][d] = CLIP((image[indx + u][d] + image[indx - u][d]) / 2.0); + 2.0) + ); + image3[indx][d] = float(CLIP((image[indx + u][d] + image[indx - u][d]) / 2.0)); } } @@ -186,7 +192,7 @@ void LibRaw::dcb_decide(float (*image2)[3], float (*image3)[3]) d = ABS(c - 2); - current = MAX(image[indx + v][c], + current = float(MAX(image[indx + v][c], MAX(image[indx - v][c], MAX(image[indx - 2][c], image[indx + 2][c]))) - MIN(image[indx + v][c], @@ -197,9 +203,10 @@ void LibRaw::dcb_decide(float (*image2)[3], float (*image3)[3]) MAX(image[indx - 1 + u][d], image[indx - 1 - u][d]))) - MIN(image[indx + 1 + u][d], MIN(image[indx + 1 - u][d], - MIN(image[indx - 1 + u][d], image[indx - 1 - u][d]))); + MIN(image[indx - 1 + u][d], image[indx - 1 - u][d])))); current2 = + float( MAX(image2[indx + v][d], MAX(image2[indx - v][d], MAX(image2[indx - 2][d], image2[indx + 2][d]))) - @@ -211,9 +218,11 @@ void LibRaw::dcb_decide(float (*image2)[3], float (*image3)[3]) MAX(image2[indx - 1 + u][c], image2[indx - 1 - u][c]))) - MIN(image2[indx + 1 + u][c], MIN(image2[indx + 1 - u][c], - MIN(image2[indx - 1 + u][c], image2[indx - 1 - u][c]))); + MIN(image2[indx - 1 + u][c], image2[indx - 1 - u][c]))) + ); current3 = + float( MAX(image3[indx + v][d], MAX(image3[indx - v][d], MAX(image3[indx - 2][d], image3[indx + 2][d]))) - @@ -225,12 +234,13 @@ void LibRaw::dcb_decide(float (*image2)[3], float (*image3)[3]) MAX(image3[indx - 1 + u][c], image3[indx - 1 - u][c]))) - MIN(image3[indx + 1 + u][c], MIN(image3[indx + 1 - u][c], - MIN(image3[indx - 1 + u][c], image3[indx - 1 - u][c]))); + MIN(image3[indx - 1 + u][c], image3[indx - 1 - u][c]))) + ); if (ABS(current - current2) < ABS(current - current3)) - image[indx][1] = image2[indx][1]; + image[indx][1] = ushort(image2[indx][1]); else - image[indx][1] = image3[indx][1]; + image[indx][1] = ushort(image3[indx][1]); } } @@ -253,8 +263,8 @@ void LibRaw::dcb_restore_from_buffer(float (*image2)[3]) for (indx = 0; indx < height * width; indx++) { - image[indx][0] = image2[indx][0]; // R - image[indx][2] = image2[indx][2]; // B + image[indx][0] = ushort(image2[indx][0]); // R + image[indx][2] = ushort(image2[indx][2]); // B } } @@ -267,21 +277,21 @@ void LibRaw::dcb_pp() for (col = 2, indx = row * u + col; col < width - 2; col++, indx++) { - r1 = (image[indx - 1][0] + image[indx + 1][0] + image[indx - u][0] + + r1 = int((image[indx - 1][0] + image[indx + 1][0] + image[indx - u][0] + image[indx + u][0] + image[indx - u - 1][0] + image[indx + u + 1][0] + image[indx - u + 1][0] + image[indx + u - 1][0]) / - 8.0; - g1 = (image[indx - 1][1] + image[indx + 1][1] + image[indx - u][1] + + 8.0f); + g1 = int((image[indx - 1][1] + image[indx + 1][1] + image[indx - u][1] + image[indx + u][1] + image[indx - u - 1][1] + image[indx + u + 1][1] + image[indx - u + 1][1] + image[indx + u - 1][1]) / - 8.0; - b1 = (image[indx - 1][2] + image[indx + 1][2] + image[indx - u][2] + + 8.0f); + b1 = int((image[indx - 1][2] + image[indx + 1][2] + image[indx - u][2] + image[indx + u][2] + image[indx - u - 1][2] + image[indx + u + 1][2] + image[indx - u + 1][2] + image[indx + u - 1][2]) / - 8.0; + 8.0f); image[indx][0] = CLIP(r1 + (image[indx][1] - g1)); image[indx][2] = CLIP(b1 + (image[indx][1] - g1)); @@ -321,41 +331,41 @@ void LibRaw::dcb_color_full() for (col = 1 + (FC(row, 1) & 1), indx = row * width + col, c = FC(row, col), d = c / 2; col < u - 1; col += 2, indx += 2) - chroma[indx][d] = image[indx][c] - image[indx][1]; + chroma[indx][d] = float(image[indx][c] - image[indx][1]); for (row = 3; row < height - 3; row++) for (col = 3 + (FC(row, 1) & 1), indx = row * width + col, c = 1 - FC(row, col) / 2, d = 1 - c; col < u - 3; col += 2, indx += 2) { - f[0] = 1.0 / + f[0] = 1.0f / (float)(1.0 + - fabs(chroma[indx - u - 1][c] - chroma[indx + u + 1][c]) + - fabs(chroma[indx - u - 1][c] - chroma[indx - w - 3][c]) + - fabs(chroma[indx + u + 1][c] - chroma[indx - w - 3][c])); - f[1] = 1.0 / + fabsf(chroma[indx - u - 1][c] - chroma[indx + u + 1][c]) + + fabsf(chroma[indx - u - 1][c] - chroma[indx - w - 3][c]) + + fabsf(chroma[indx + u + 1][c] - chroma[indx - w - 3][c])); + f[1] = 1.0f / (float)(1.0 + - fabs(chroma[indx - u + 1][c] - chroma[indx + u - 1][c]) + - fabs(chroma[indx - u + 1][c] - chroma[indx - w + 3][c]) + - fabs(chroma[indx + u - 1][c] - chroma[indx - w + 3][c])); - f[2] = 1.0 / + fabsf(chroma[indx - u + 1][c] - chroma[indx + u - 1][c]) + + fabsf(chroma[indx - u + 1][c] - chroma[indx - w + 3][c]) + + fabsf(chroma[indx + u - 1][c] - chroma[indx - w + 3][c])); + f[2] = 1.0f / (float)(1.0 + - fabs(chroma[indx + u - 1][c] - chroma[indx - u + 1][c]) + - fabs(chroma[indx + u - 1][c] - chroma[indx + w + 3][c]) + - fabs(chroma[indx - u + 1][c] - chroma[indx + w - 3][c])); - f[3] = 1.0 / + fabsf(chroma[indx + u - 1][c] - chroma[indx - u + 1][c]) + + fabsf(chroma[indx + u - 1][c] - chroma[indx + w + 3][c]) + + fabsf(chroma[indx - u + 1][c] - chroma[indx + w - 3][c])); + f[3] = 1.0f / (float)(1.0 + - fabs(chroma[indx + u + 1][c] - chroma[indx - u - 1][c]) + - fabs(chroma[indx + u + 1][c] - chroma[indx + w - 3][c]) + - fabs(chroma[indx - u - 1][c] - chroma[indx + w + 3][c])); - g[0] = 1.325 * chroma[indx - u - 1][c] - 0.175 * chroma[indx - w - 3][c] - - 0.075 * chroma[indx - w - 1][c] - 0.075 * chroma[indx - u - 3][c]; - g[1] = 1.325 * chroma[indx - u + 1][c] - 0.175 * chroma[indx - w + 3][c] - - 0.075 * chroma[indx - w + 1][c] - 0.075 * chroma[indx - u + 3][c]; - g[2] = 1.325 * chroma[indx + u - 1][c] - 0.175 * chroma[indx + w - 3][c] - - 0.075 * chroma[indx + w - 1][c] - 0.075 * chroma[indx + u - 3][c]; - g[3] = 1.325 * chroma[indx + u + 1][c] - 0.175 * chroma[indx + w + 3][c] - - 0.075 * chroma[indx + w + 1][c] - 0.075 * chroma[indx + u + 3][c]; + fabsf(chroma[indx + u + 1][c] - chroma[indx - u - 1][c]) + + fabsf(chroma[indx + u + 1][c] - chroma[indx + w - 3][c]) + + fabsf(chroma[indx - u - 1][c] - chroma[indx + w + 3][c])); + g[0] = 1.325f * chroma[indx - u - 1][c] - 0.175f * chroma[indx - w - 3][c] - + 0.075f * chroma[indx - w - 1][c] - 0.075f * chroma[indx - u - 3][c]; + g[1] = 1.325f * chroma[indx - u + 1][c] - 0.175f * chroma[indx - w + 3][c] - + 0.075f * chroma[indx - w + 1][c] - 0.075f * chroma[indx - u + 3][c]; + g[2] = 1.325f * chroma[indx + u - 1][c] - 0.175f * chroma[indx + w - 3][c] - + 0.075f * chroma[indx + w - 1][c] - 0.075f * chroma[indx + u - 3][c]; + g[3] = 1.325f * chroma[indx + u + 1][c] - 0.175f * chroma[indx + w + 3][c] - + 0.075f * chroma[indx + w + 1][c] - 0.075f * chroma[indx + u + 3][c]; chroma[indx][c] = (f[0] * g[0] + f[1] * g[1] + f[2] * g[2] + f[3] * g[3]) / (f[0] + f[1] + f[2] + f[3]); @@ -366,27 +376,27 @@ void LibRaw::dcb_color_full() col < u - 3; col += 2, indx += 2) for (d = 0; d <= 1; c = 1 - c, d++) { - f[0] = 1.0 / - (float)(1.0 + fabs(chroma[indx - u][c] - chroma[indx + u][c]) + - fabs(chroma[indx - u][c] - chroma[indx - w][c]) + - fabs(chroma[indx + u][c] - chroma[indx - w][c])); - f[1] = 1.0 / - (float)(1.0 + fabs(chroma[indx + 1][c] - chroma[indx - 1][c]) + - fabs(chroma[indx + 1][c] - chroma[indx + 3][c]) + - fabs(chroma[indx - 1][c] - chroma[indx + 3][c])); - f[2] = 1.0 / + f[0] = 1.0f / + (float)(1.0f + fabsf(chroma[indx - u][c] - chroma[indx + u][c]) + + fabsf(chroma[indx - u][c] - chroma[indx - w][c]) + + fabsf(chroma[indx + u][c] - chroma[indx - w][c])); + f[1] = 1.0f / + (float)(1.0f + fabsf(chroma[indx + 1][c] - chroma[indx - 1][c]) + + fabsf(chroma[indx + 1][c] - chroma[indx + 3][c]) + + fabsf(chroma[indx - 1][c] - chroma[indx + 3][c])); + f[2] = 1.0f / (float)(1.0 + fabs(chroma[indx - 1][c] - chroma[indx + 1][c]) + fabs(chroma[indx - 1][c] - chroma[indx - 3][c]) + fabs(chroma[indx + 1][c] - chroma[indx - 3][c])); - f[3] = 1.0 / + f[3] = 1.0f / (float)(1.0 + fabs(chroma[indx + u][c] - chroma[indx - u][c]) + fabs(chroma[indx + u][c] - chroma[indx + w][c]) + fabs(chroma[indx - u][c] - chroma[indx + w][c])); - g[0] = 0.875 * chroma[indx - u][c] + 0.125 * chroma[indx - w][c]; - g[1] = 0.875 * chroma[indx + 1][c] + 0.125 * chroma[indx + 3][c]; - g[2] = 0.875 * chroma[indx - 1][c] + 0.125 * chroma[indx - 3][c]; - g[3] = 0.875 * chroma[indx + u][c] + 0.125 * chroma[indx + w][c]; + g[0] = 0.875f * chroma[indx - u][c] + 0.125f * chroma[indx - w][c]; + g[1] = 0.875f * chroma[indx + 1][c] + 0.125f * chroma[indx + 3][c]; + g[2] = 0.875f * chroma[indx - 1][c] + 0.125f * chroma[indx - 3][c]; + g[3] = 0.875f * chroma[indx + u][c] + 0.125f * chroma[indx + w][c]; chroma[indx][c] = (f[0] * g[0] + f[1] * g[1] + f[2] * g[2] + f[3] * g[3]) / @@ -488,9 +498,10 @@ void LibRaw::dcb_correction() image[indx - 2][3]; image[indx][1] = + ushort( ((16 - current) * (image[indx - 1][1] + image[indx + 1][1]) / 2.0 + current * (image[indx - u][1] + image[indx + u][1]) / 2.0) / - 16.0; + 16.0f); } } @@ -568,7 +579,7 @@ void LibRaw::dcb_refinement() else f[4] = f[0]; - g1 = (5 * f[0] + 3 * f[1] + f[2] + 3 * f[3] + f[4]) / 13.0; + g1 = (5.f * f[0] + 3.f * f[1] + f[2] + 3.f * f[3] + f[4]) / 13.0f; f[0] = (float)(image[indx - 1][1] + image[indx + 1][1]) / (2 * image[indx][c]); @@ -597,7 +608,7 @@ void LibRaw::dcb_refinement() else f[4] = f[0]; - g2 = (5 * f[0] + 3 * f[1] + f[2] + 3 * f[3] + f[4]) / 13.0; + g2 = (5.f * f[0] + 3.f * f[1] + f[2] + 3.f * f[3] + f[4]) / 13.0f; image[indx][1] = CLIP((image[indx][c]) * (current * g1 + (16 - current) * g2) / 16.0); @@ -625,7 +636,7 @@ void LibRaw::dcb_refinement() MAX(image[indx + 1][1], MAX(image[indx - u][1], image[indx + u][1]))))))); - image[indx][1] = ULIM(image[indx][1], g2, g1); + image[indx][1] = ushort(ULIM(image[indx][1], g2, g1)); } } @@ -743,35 +754,35 @@ void LibRaw::fbdd_green() col < u - 5; col += 2, indx += 2) { - f[0] = 1.0 / (1.0 + abs(image[indx - u][1] - image[indx - w][1]) + + f[0] = 1.0f / (1.0f + abs(image[indx - u][1] - image[indx - w][1]) + abs(image[indx - w][1] - image[indx + y][1])); - f[1] = 1.0 / (1.0 + abs(image[indx + 1][1] - image[indx + 3][1]) + + f[1] = 1.0f / (1.0f + abs(image[indx + 1][1] - image[indx + 3][1]) + abs(image[indx + 3][1] - image[indx - 5][1])); - f[2] = 1.0 / (1.0 + abs(image[indx - 1][1] - image[indx - 3][1]) + + f[2] = 1.0f / (1.0f + abs(image[indx - 1][1] - image[indx - 3][1]) + abs(image[indx - 3][1] - image[indx + 5][1])); - f[3] = 1.0 / (1.0 + abs(image[indx + u][1] - image[indx + w][1]) + + f[3] = 1.0f / (1.0f + abs(image[indx + u][1] - image[indx + w][1]) + abs(image[indx + w][1] - image[indx - y][1])); - g[0] = CLIP((23 * image[indx - u][1] + 23 * image[indx - w][1] + + g[0] = float(CLIP((23 * image[indx - u][1] + 23 * image[indx - w][1] + 2 * image[indx - y][1] + 8 * (image[indx - v][c] - image[indx - x][c]) + 40 * (image[indx][c] - image[indx - v][c])) / - 48.0); - g[1] = CLIP((23 * image[indx + 1][1] + 23 * image[indx + 3][1] + + 48.0f)); + g[1] = float(CLIP((23 * image[indx + 1][1] + 23 * image[indx + 3][1] + 2 * image[indx + 5][1] + 8 * (image[indx + 2][c] - image[indx + 4][c]) + 40 * (image[indx][c] - image[indx + 2][c])) / - 48.0); - g[2] = CLIP((23 * image[indx - 1][1] + 23 * image[indx - 3][1] + + 48.f)); + g[2] = float(CLIP((23 * image[indx - 1][1] + 23 * image[indx - 3][1] + 2 * image[indx - 5][1] + 8 * (image[indx - 2][c] - image[indx - 4][c]) + 40 * (image[indx][c] - image[indx - 2][c])) / - 48.0); - g[3] = CLIP((23 * image[indx + u][1] + 23 * image[indx + w][1] + + 48.0f)); + g[3] = float(CLIP((23 * image[indx + u][1] + 23 * image[indx + w][1] + 2 * image[indx + y][1] + 8 * (image[indx + v][c] - image[indx + x][c]) + 40 * (image[indx][c] - image[indx + v][c])) / - 48.0); + 48.0f)); image[indx][1] = CLIP((f[0] * g[0] + f[1] * g[1] + f[2] * g[2] + f[3] * g[3]) / diff --git a/rtengine/libraw/src/demosaic/dht_demosaic.cpp b/rtengine/libraw/src/demosaic/dht_demosaic.cpp index bff8f77b0..9fa603f88 100644 --- a/rtengine/libraw/src/demosaic/dht_demosaic.cpp +++ b/rtengine/libraw/src/demosaic/dht_demosaic.cpp @@ -167,13 +167,13 @@ struct DHT } static inline float scale_over(float ec, float base) { - float s = base * .4; + float s = base * .4f; float o = ec - base; return base + sqrt(s * (o + s)) - s; } static inline float scale_under(float ec, float base) { - float s = base * .6; + float s = base * .6f; float o = base - ec; return base - sqrt(s * (o + s)) + s; } @@ -787,10 +787,10 @@ void DHT::illustrate_dline(int i) l = 1; if (ndir[nr_offset(y, x)] & HOT) nraw[nr_offset(y, x)][0] = - l * channel_maximum[0] / 4 + channel_maximum[0] / 4; + l * channel_maximum[0] / 4.f + channel_maximum[0] / 4.f; else nraw[nr_offset(y, x)][2] = - l * channel_maximum[2] / 4 + channel_maximum[2] / 4; + l * channel_maximum[2] / 4.f + channel_maximum[2] / 4.f; } } diff --git a/rtengine/libraw/src/demosaic/misc_demosaic.cpp b/rtengine/libraw/src/demosaic/misc_demosaic.cpp index 76b837860..7d3e85361 100644 --- a/rtengine/libraw/src/demosaic/misc_demosaic.cpp +++ b/rtengine/libraw/src/demosaic/misc_demosaic.cpp @@ -47,7 +47,8 @@ void LibRaw::pre_interpolate() } else { - img = (ushort(*)[4])calloc(height, width * sizeof *img); + int extra = filters ? (filters == 9 ? 6 : 2) : 0; + img = (ushort(*)[4])calloc((height+extra), (width+extra) * sizeof *img); for (row = 0; row < height; row++) for (col = 0; col < width; col++) { @@ -153,7 +154,7 @@ void LibRaw::lin_interpolate() *ip++ = color; sum[color] += 1 << shift; } - code[(row * 16 + col) * 32] = (ip - (code + ((row * 16) + col) * 32)) / 3; + code[(row * 16 + col) * 32] = int((ip - (code + ((row * 16) + col) * 32)) / 3); FORCC if (c != f) { diff --git a/rtengine/libraw/src/demosaic/xtrans_demosaic.cpp b/rtengine/libraw/src/demosaic/xtrans_demosaic.cpp index 8bd1842c4..7a91751d8 100644 --- a/rtengine/libraw/src/demosaic/xtrans_demosaic.cpp +++ b/rtengine/libraw/src/demosaic/xtrans_demosaic.cpp @@ -36,7 +36,7 @@ void LibRaw::xtrans_interpolate(int passes) short allhex[3][3][2][8]; ushort sgrow = 0, sgcol = 0; - if (width < LIBRAW_AHD_TILE || height < LIBRAW_AHD_TILE) + if (width < LIBRAW_AHD_TILE || height < LIBRAW_AHD_TILE || filters != 9) throw LIBRAW_EXCEPTION_IO_CORRUPT; // too small image /* Check against right pattern */ for (int row = 0; row < 6; row++) @@ -360,9 +360,11 @@ void LibRaw::xtrans_interpolate(int passes) lix = &lab[row][col]; int g = 2 * lix[0][0] - lix[f][0] - lix[-f][0]; drv[d][row][col] = + float( SQR(g) + SQR((2 * lix[0][1] - lix[f][1] - lix[-f][1] + g * 500 / 232)) + - SQR((2 * lix[0][2] - lix[f][2] - lix[-f][2] - g * 500 / 580)); + SQR((2 * lix[0][2] - lix[f][2] - lix[-f][2] - g * 500 / 580)) + ); } } diff --git a/rtengine/libraw/src/integration/dngsdk_glue.cpp b/rtengine/libraw/src/integration/dngsdk_glue.cpp index 0d0a9e8e3..ceec189d9 100644 --- a/rtengine/libraw/src/integration/dngsdk_glue.cpp +++ b/rtengine/libraw/src/integration/dngsdk_glue.cpp @@ -35,6 +35,22 @@ #endif #ifdef USE_DNGSDK + +void clear_dng_negative(void *p) +{ + if (!p) + return; + dng_negative *dn = (dng_negative *)p; + delete dn; +} + +void clear_dng_image(void *p) +{ + if (!p) return; + dng_image *dimage = (dng_image *)p; + delete dimage; +} + static dng_ifd* search_single_ifd(const std::vector & v, uint64 offset, int& idx, dng_stream& stream) { idx = -1; @@ -93,17 +109,15 @@ int LibRaw::valid_for_dngsdk() if (!imgdata.idata.dng_version) return 0; -#ifdef qDNGSupportJXL if (libraw_internal_data.unpacker_data.tiff_compress == 52546) // regardless of flags or use_dngsdk value! { #ifdef qDNGSupportJXL - if (dngVersion_Current >= dngVersion_1_7_0_0) - return 1; - else + if (dngVersion_Current >= dngVersion_1_7_0_0) + return 1; + else #endif - return 0; // Old DNG SDK + return 0; // Old DNG SDK } -#endif // All DNG larger than 2GB - to DNG SDK @@ -118,30 +132,44 @@ int LibRaw::valid_for_dngsdk() if (libraw_internal_data.unpacker_data.tiff_compress == 34892 && libraw_internal_data.unpacker_data.tiff_bps == 8 - && (libraw_internal_data.unpacker_data.tiff_samples == 3 || libraw_internal_data.unpacker_data.tiff_samples == 1) + && (libraw_internal_data.unpacker_data.tiff_samples == 3 + || libraw_internal_data.unpacker_data.tiff_samples == 1 + || libraw_internal_data.unpacker_data.tiff_samples == 4 ) && load_raw == &LibRaw::lossy_dng_load_raw ) { if (!dnghost) return 0; - dng_host *host = static_cast(dnghost); - libraw_dng_stream stream(libraw_internal_data.internal_data.input); - AutoPtr negative; - negative.Reset(host->Make_dng_negative()); - dng_info info; - info.Parse(*host, stream); - info.PostParse(*host); - if (!info.IsValidDNG()) - return 0; - negative->Parse(*host, stream, info); - negative->PostParse(*host, stream, info); - int ifdindex = -1; - dng_ifd *rawIFD = search_for_ifd(info, libraw_internal_data.unpacker_data.data_offset, imgdata.sizes.raw_width, imgdata.sizes.raw_height, ifdindex,stream); - if (rawIFD && ifdindex >= 0 && ifdindex == info.fMainIndex) + try + { + dng_host *host = static_cast(dnghost); + libraw_dng_stream stream(libraw_internal_data.internal_data.input); + AutoPtr negative; + negative.Reset(host->Make_dng_negative()); + dng_info info; + info.Parse(*host, stream); + info.PostParse(*host); + if (!info.IsValidDNG()) + { + imgdata.process_warnings |= LIBRAW_WARN_DNG_NOT_PARSED; + return 0; + } + negative->Parse(*host, stream, info); + negative->PostParse(*host, stream, info); + int ifdindex = -1; + dng_ifd *rawIFD = search_for_ifd(info, libraw_internal_data.unpacker_data.data_offset, imgdata.sizes.raw_width, + imgdata.sizes.raw_height, ifdindex, stream); + if (rawIFD && ifdindex >= 0 && ifdindex == info.fMainIndex) return 1; - if (rawIFD && ifdindex >= 0 && (imgdata.rawparams.options & LIBRAW_RAWOPTIONS_DNG_ADD_PREVIEWS)) - return 1; - return 0; + if (rawIFD && ifdindex >= 0 && (imgdata.rawparams.options & LIBRAW_RAWOPTIONS_DNG_ADD_PREVIEWS)) + return 1; + return 0; + } + catch (...) + { + imgdata.process_warnings |= LIBRAW_WARN_DNG_NOT_PARSED; + return 0; + } } #ifdef USE_GPRSDK @@ -205,8 +233,11 @@ int LibRaw::try_dngsdk() negative->PostParse(*host, stream, info); int ifdindex; dng_ifd *rawIFD = search_for_ifd(info,libraw_internal_data.unpacker_data.data_offset,imgdata.sizes.raw_width,imgdata.sizes.raw_height,ifdindex,stream); - if(!rawIFD) - return LIBRAW_DATA_ERROR; + if (!rawIFD) + { + imgdata.process_warnings |= LIBRAW_WARN_DNG_NOT_PROCESSED; + return LIBRAW_DATA_ERROR; + } AutoPtr stage2; unsigned stageBits = 0; // 1=> release Stage2, 2=> change Black/Max @@ -303,6 +334,7 @@ int LibRaw::try_dngsdk() else { stage2.Release(); // It holds copy to internal dngnegative + imgdata.process_warnings |= LIBRAW_WARN_DNG_NOT_PROCESSED; return LIBRAW_DATA_ERROR; } } @@ -316,6 +348,7 @@ int LibRaw::try_dngsdk() // reset BL and whitepoint imgdata.color.black = 0; memset(imgdata.color.cblack, 0, sizeof(imgdata.color.cblack)); + memset(imgdata.color.linear_max, 0, sizeof(imgdata.color.linear_max)); imgdata.color.maximum = 0xffff; } @@ -344,8 +377,7 @@ int LibRaw::try_dngsdk() ushort *dst = (ushort *)imgdata.rawdata.raw_alloc; if (is_curve_linear()) { - for (int i = 0; i < pixels; i++) - dst[i] = src[i]; + memmove(dst, src, pixels * TagTypeSize(ptype)); } else { @@ -448,10 +480,14 @@ int LibRaw::try_dngsdk() } catch (...) { + imgdata.process_warnings |= LIBRAW_WARN_DNG_NOT_PROCESSED; return LIBRAW_UNSPECIFIED_ERROR; } - return (dngnegative || imgdata.rawdata.raw_alloc) ? LIBRAW_SUCCESS : LIBRAW_UNSPECIFIED_ERROR; + int ret = (dngnegative || imgdata.rawdata.raw_alloc) ? LIBRAW_SUCCESS : LIBRAW_UNSPECIFIED_ERROR; + if(ret != LIBRAW_SUCCESS) + imgdata.process_warnings |= LIBRAW_WARN_DNG_NOT_PROCESSED; + return ret; #else return LIBRAW_UNSPECIFIED_ERROR; #endif diff --git a/rtengine/libraw/src/integration/rawspeed_glue.cpp b/rtengine/libraw/src/integration/rawspeed_glue.cpp index 90d461190..58ffe9415 100644 --- a/rtengine/libraw/src/integration/rawspeed_glue.cpp +++ b/rtengine/libraw/src/integration/rawspeed_glue.cpp @@ -221,12 +221,15 @@ int LibRaw::try_rawspeed() try { ID.input->seek(0, SEEK_SET); - INT64 _rawspeed_buffer_sz = ID.input->size() + 32; + INT64 _rawspeed_buffer_sz = ID.input->size() + 32LL; + if(_rawspeed_buffer_sz > 2147483647LL) + throw LIBRAW_EXCEPTION_ALLOC; + _rawspeed_buffer = malloc(_rawspeed_buffer_sz); if (!_rawspeed_buffer) throw LIBRAW_EXCEPTION_ALLOC; ID.input->read(_rawspeed_buffer, _rawspeed_buffer_sz, 1); - RawSpeed::FileMap map((RawSpeed::uchar8 *)_rawspeed_buffer, _rawspeed_buffer_sz); + RawSpeed::FileMap map((RawSpeed::uchar8 *)_rawspeed_buffer, uint32_t(_rawspeed_buffer_sz)); RawSpeed::RawParser t(&map); RawSpeed::RawDecoder *d = 0; CameraMetaDataLR *meta = diff --git a/rtengine/libraw/src/libraw_c_api.cpp b/rtengine/libraw/src/libraw_c_api.cpp index 2609fef70..ac168093e 100644 --- a/rtengine/libraw/src/libraw_c_api.cpp +++ b/rtengine/libraw/src/libraw_c_api.cpp @@ -198,6 +198,15 @@ extern "C" ip->set_exifparser_handler(cb, data); } + void libraw_set_makernotes_handler(libraw_data_t *lr, exif_parser_callback cb, + void *data) + { + if (!lr) + return; + LibRaw *ip = (LibRaw *)lr->parent_class; + ip->set_makernotes_handler(cb, data); + } + void libraw_set_dataerror_handler(libraw_data_t *lr, data_callback func, void *data) { @@ -215,6 +224,14 @@ extern "C" ip->set_progress_handler(cb, data); } + int libraw_adjust_to_raw_inset_crop(libraw_data_t *lr, unsigned mask, float maxcrop) + { + if (!lr) + return EINVAL; + LibRaw *ip = (LibRaw *)lr->parent_class; + return ip->adjust_to_raw_inset_crop(mask,maxcrop); + } + // DCRAW int libraw_adjust_sizes_info_only(libraw_data_t *lr) { diff --git a/rtengine/libraw/src/libraw_datastream.cpp b/rtengine/libraw/src/libraw_datastream.cpp index 33182253d..1835005bb 100644 --- a/rtengine/libraw/src/libraw_datastream.cpp +++ b/rtengine/libraw/src/libraw_datastream.cpp @@ -556,6 +556,8 @@ int LibRaw_bigfile_datastream::seek(INT64 o, int whence) #else return fseek(f, (long)o, whence); #endif +#elif (defined(__ANDROID__) && __ANDROID_API__ < 24) + return fseek(f, o, whence); #else return fseeko(f, o, whence); #endif @@ -570,6 +572,8 @@ INT64 LibRaw_bigfile_datastream::tell() #else return ftell(f); #endif +#elif (defined(__ANDROID__) && __ANDROID_API__ < 24) + return ftell(f); #else return ftello(f); #endif @@ -776,9 +780,11 @@ INT64 LibRaw_bigfile_buffered_datastream::readAt(void *ptr, size_t size, INT64 o memset(&olap, 0, sizeof(olap)); olap.Offset = off & 0xffffffff; olap.OffsetHigh = off >> 32; - if (ReadFile(fhandle, ptr, nNumberOfBytesToRead, &NumberOfBytesRead, &olap)) - return NumberOfBytesRead; - else + if (ReadFile(fhandle, ptr, nNumberOfBytesToRead, &NumberOfBytesRead, &olap)) + return NumberOfBytesRead; + else if (NumberOfBytesRead > 0) + return NumberOfBytesRead; + else return 0; } @@ -901,14 +907,14 @@ char *LibRaw_bigfile_buffered_datastream::gets(char *s, int sz) if (contains >= sz) { unsigned char *buf = iobuffers[bufindex].data() + (_fpos - iobuffers[bufindex]._bstart); - int streampos = 0; - int streamsize = contains; + INT64 streampos = 0; + INT64 streamsize = contains; unsigned char *str = (unsigned char *)s; unsigned char *psrc, *pdest; psrc = buf + streampos; pdest = str; - while ((size_t(psrc - buf) < streamsize) && ((pdest - str) < sz-1)) // sz-1: to append \0 + while ((INT64(psrc - buf) < streamsize) && ((pdest - str) < INT64(sz)-1)) // sz-1: to append \0 { *pdest = *psrc; if (*psrc == '\n') @@ -916,7 +922,7 @@ char *LibRaw_bigfile_buffered_datastream::gets(char *s, int sz) psrc++; pdest++; } - if (size_t(psrc - buf) < streamsize) + if (INT64(psrc - buf) < streamsize) psrc++; if ((pdest - str) < sz - 1) *(++pdest) = 0; @@ -952,8 +958,8 @@ int LibRaw_bigfile_buffered_datastream::scanf_one(const char *fmt, void *val) if (contains >= 24) { unsigned char *bstart = iobuffers[bufindex].data() + (_fpos - iobuffers[bufindex]._bstart); - int streampos = 0; - int streamsize = contains; + INT64 streampos = 0; + INT64 streamsize = contains; int #ifndef WIN32SECURECALLS scanf_res = sscanf((char *)(bstart), fmt, val); diff --git a/rtengine/libraw/src/metadata/adobepano.cpp b/rtengine/libraw/src/metadata/adobepano.cpp index ee1d2c8a1..3bca3ebb7 100644 --- a/rtengine/libraw/src/metadata/adobepano.cpp +++ b/rtengine/libraw/src/metadata/adobepano.cpp @@ -37,7 +37,7 @@ void LibRaw::parseAdobePanoMakernote() PrivateMknLength = get4(); if ((PrivateMknLength > 4) && (PrivateMknLength < 10240000) && - (PrivateMknBuf = (uchar *)malloc(PrivateMknLength + 1024))) + (PrivateMknBuf = (uchar *)calloc(PrivateMknLength + 1024,1))) { // 1024b for safety fread(PrivateMknBuf, PrivateMknLength, 1, ifp); PrivateOrder = sget2(PrivateMknBuf); diff --git a/rtengine/libraw/src/metadata/canon.cpp b/rtengine/libraw/src/metadata/canon.cpp index eab35e0e8..a45889d51 100644 --- a/rtengine/libraw/src/metadata/canon.cpp +++ b/rtengine/libraw/src/metadata/canon.cpp @@ -113,6 +113,7 @@ void LibRaw::setCanonBodyFeatures(unsigned long long id) || (id == CanonID_EOS_RP) || (id == CanonID_EOS_R3) || (id == CanonID_EOS_R5) + || (id == CanonID_EOS_R5_C) || (id == CanonID_EOS_R6) || (id == CanonID_EOS_R6m2) || (id == CanonID_EOS_R8) @@ -845,7 +846,7 @@ void LibRaw::parseCanonMakernotes(unsigned tag, unsigned /*type*/, unsigned len, imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); imCommon.afcount = 1; } diff --git a/rtengine/libraw/src/metadata/ciff.cpp b/rtengine/libraw/src/metadata/ciff.cpp index b3c43066d..18e5911f3 100644 --- a/rtengine/libraw/src/metadata/ciff.cpp +++ b/rtengine/libraw/src/metadata/ciff.cpp @@ -57,7 +57,7 @@ void LibRaw::ciff_block_1030() /* Parse a CIFF file, better known as Canon CRW format. */ -void LibRaw::parse_ciff(int offset, int length, int depth) +void LibRaw::parse_ciff(INT64 offset, int length, int depth) { int nrecs, c, type, len, wbi = -1; INT64 save, tboff; diff --git a/rtengine/libraw/src/metadata/cr3_parser.cpp b/rtengine/libraw/src/metadata/cr3_parser.cpp index 4b0d1d195..989aa9622 100644 --- a/rtengine/libraw/src/metadata/cr3_parser.cpp +++ b/rtengine/libraw/src/metadata/cr3_parser.cpp @@ -35,14 +35,14 @@ int LibRaw::selectCRXFrame(short trackNum, unsigned frameIndex) if (frameIndex >= hdr->sample_count) return -1; - for (int i = 0; i < hdr->chunk_count; i++) + for (unsigned i = 0; i < hdr->chunk_count; i++) { int64_t current_offset = hdr->chunk_offsets[i]; while((stsc_index < hdr->stsc_count) && (i+1 == hdr->stsc_data[stsc_index+1].first)) stsc_index++; - for (int j = 0; j < hdr->stsc_data[stsc_index].count; j++) + for (unsigned j = 0; j < hdr->stsc_data[stsc_index].count; j++) { if (current_sample > hdr->sample_count) return -1; @@ -68,13 +68,12 @@ void LibRaw::selectCRXTrack() return; INT64 bitcounts[LIBRAW_CRXTRACKS_MAXCOUNT], maxbitcount = 0; - int framecounts[LIBRAW_CRXTRACKS_MAXCOUNT], maxframecount = 0; + int framecounts[LIBRAW_CRXTRACKS_MAXCOUNT]; uint32_t maxjpegbytes = 0; int framecnt = 0; int media_tracks = 0; int track_select = 0; int frame_select = 0; - int err; memset(bitcounts, 0, sizeof(bitcounts)); memset(framecounts, 0, sizeof(framecounts)); @@ -140,10 +139,10 @@ void LibRaw::selectCRXTrack() int ctmdcount = 0; // Frame selected: parse CTMD metadata - for (int i = 0, trackcnt = 0; i <= maxTrack && i < LIBRAW_CRXTRACKS_MAXCOUNT; i++) + for (int i = 0; i <= maxTrack && i < LIBRAW_CRXTRACKS_MAXCOUNT; i++) { crx_data_header_t *d = &libraw_internal_data.unpacker_data.crx_header[i]; - int fsel = LIM(frame_select, 0, d->sample_count); + int fsel = LIM(frame_select, 0, int(d->sample_count)); if (d->MediaType == 3) // CTMD metadata { /* ignore errors !*/ @@ -297,7 +296,7 @@ int LibRaw::parseCR3_CTMD(short trackNum) err = -11; goto ctmd_fin; } - if ((Tag == 0x927c) && ((tItem == 7) || (tItem == 8))) + if (Tag == 0x927c) { fseek(ifp, track.MediaOffset + relpos_inBox + 8L, SEEK_SET); @@ -308,11 +307,22 @@ int LibRaw::parseCR3_CTMD(short trackNum) err = -13; goto ctmd_fin; } - fseek(ifp, -8L, SEEK_CUR); - libraw_internal_data.unpacker_data.CR3_CTMDtag = 1; - parse_makernote(track.MediaOffset + relpos_inBox + 8, - 0); - libraw_internal_data.unpacker_data.CR3_CTMDtag = 0; + if (callbacks.exif_cb) + { + INT64 savepos = ifp->tell(); + callbacks.exif_cb(callbacks.exifparser_data, (tItem << 20) | 0x80000 | 0x927c, 7, lTag-8, order, ifp, + track.MediaOffset + relpos_inBox + 8); + fseek(ifp, savepos, SEEK_SET); + } + + if ((tItem == 7) || (tItem == 8)) + { + fseek(ifp, -8L, SEEK_CUR); + libraw_internal_data.unpacker_data.CR3_CTMDtag = 1; + parse_makernote(track.MediaOffset + relpos_inBox + 8, + 0); + libraw_internal_data.unpacker_data.CR3_CTMDtag = 0; + } order = q_order; } relpos_inBox += lTag; @@ -452,9 +462,6 @@ int LibRaw::parseCR3(INT64 oAtomList, uchar thdr[4]; uchar CDI1[60]; char HandlerType[5], MediaFormatID[5]; - uint32_t relpos_inDir, relpos_inBox; - unsigned szItem, Tag, lTag; - ushort tItem; nmAtom[0] = MediaFormatID[0] = nmAtom[4] = MediaFormatID[4] = '\0'; strcpy(HandlerType, sHandlerType[0]); @@ -537,9 +544,9 @@ int LibRaw::parseCR3(INT64 oAtomList, fread(UIID, 1, lHdr, ifp); if (!memcmp(UIID, UUID_XMP, 16) && szAtom > 24LL && szAtom < 1024000LL) { - xmpdata = (char *)malloc(xmplen = unsigned(szAtom - 23)); - fread(xmpdata, szAtom - 24, 1, ifp); - xmpdata[szAtom - 24] = 0; + xmpdata = (char *)calloc(xmplen = unsigned(szAtom - 23),1); + unsigned br = fread(xmpdata,1, szAtom - 24, ifp); + xmpdata[br] = 0; } else if (!memcmp(UIID, UIID_CanonPreview, 16) && szAtom > 48LL && szAtom < 100LL * 1024000LL) { @@ -633,7 +640,7 @@ int LibRaw::parseCR3(INT64 oAtomList, int idx = imgdata.thumbs_list.thumbcount; imgdata.thumbs_list.thumblist[idx].tformat = LIBRAW_INTERNAL_THUMBNAIL_JPEG; imgdata.thumbs_list.thumblist[idx].toffset = xoffset; - imgdata.thumbs_list.thumblist[idx].tlength = szAtom-24; + imgdata.thumbs_list.thumblist[idx].tlength = unsigned(szAtom-24LL); imgdata.thumbs_list.thumblist[idx].tflip = 0xffff; imgdata.thumbs_list.thumblist[idx].tmisc = (3 << 5) | 8; // 3 samples/8 bps imgdata.thumbs_list.thumblist[idx].twidth = (xdata[4] << 8) + xdata[5]; @@ -665,6 +672,12 @@ int LibRaw::parseCR3(INT64 oAtomList, err = -6; goto fin; } + if (callbacks.exif_cb) + { + INT64 savepos = ifp->tell(); + callbacks.exif_cb(callbacks.exifparser_data, 0x70000 | 0x927c, 7, szAtomContent, order, ifp, oAtomContent); + fseek(ifp, savepos, SEEK_SET); + } fseek(ifp, -12L, SEEK_CUR); parse_makernote(oAtomContent, 0); order = q_order; @@ -734,9 +747,9 @@ int LibRaw::parseCR3(INT64 oAtomList, } else if (!strcmp(AtomNameStack, "moovtrakmdiaminfstblstsdCRAWCMP1")) { - int read_size = szAtomContent > 85 ? 85 : szAtomContent; + INT64 read_size = szAtomContent > 85LL ? 85 : INT64(szAtomContent); if (szAtomContent >= 40) - fread(CMP1, 1, read_size, ifp); + fread(CMP1, 1, size_t(read_size), ifp); else { err = -7; @@ -775,7 +788,7 @@ int LibRaw::parseCR3(INT64 oAtomList, goto fin; } - current_track.stsc_data = (crx_sample_to_chunk_t*) malloc(entries * sizeof(crx_sample_to_chunk_t)); + current_track.stsc_data = (crx_sample_to_chunk_t*) calloc(entries * sizeof(crx_sample_to_chunk_t),1); if(!current_track.stsc_data) { err = -9; @@ -812,7 +825,7 @@ int LibRaw::parseCR3(INT64 oAtomList, err = -10; goto fin; } - current_track.sample_sizes = (int32_t*)malloc(entries * sizeof(int32_t)); + current_track.sample_sizes = (int32_t*)calloc(entries * sizeof(int32_t),1); if (!current_track.sample_sizes) { err = -10; @@ -830,13 +843,13 @@ int LibRaw::parseCR3(INT64 oAtomList, if (szAtomContent >= 16) { fseek(ifp, 4L, SEEK_CUR); uint32_t entries = get4(); - int i; + uint32_t i; if (entries < 1 || entries > 1000000) { err = -11; goto fin; } - current_track.chunk_offsets = (INT64*)malloc(entries * sizeof(int64_t)); + current_track.chunk_offsets = (INT64*)calloc(entries * sizeof(int64_t),1); if(!current_track.chunk_offsets) { err = -11; diff --git a/rtengine/libraw/src/metadata/epson.cpp b/rtengine/libraw/src/metadata/epson.cpp index 5537c9752..fdaf57a00 100644 --- a/rtengine/libraw/src/metadata/epson.cpp +++ b/rtengine/libraw/src/metadata/epson.cpp @@ -14,12 +14,13 @@ #include "../../internal/dcraw_defs.h" -void LibRaw::parseEpsonMakernote(int base, int uptag, unsigned dng_writer) +void LibRaw::parseEpsonMakernote(INT64 base, int uptag, unsigned dng_writer) { #define isRIC imgdata.sizes.raw_inset_crops[0] - unsigned entries, tag, type, len, save; + unsigned entries, tag, type, len; + INT64 save; short morder, sorder = order; ushort c; INT64 fsize = ifp->size(); @@ -46,6 +47,13 @@ void LibRaw::parseEpsonMakernote(int base, int uptag, unsigned dng_writer) if (len > 100 * 1024 * 1024) goto next; // 100Mb tag? No! + if (callbacks.makernotes_cb) + { + INT64 _savepos = ifp->tell(); + callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } + if (tag == 0x020b) { if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) @@ -83,8 +91,8 @@ void LibRaw::parseEpsonMakernote(int base, int uptag, unsigned dng_writer) else if (tag == 0x0e80) { fseek(ifp, 48, SEEK_CUR); - cam_mul[0] = get2() * 567.0 / 0x10000; - cam_mul[2] = get2() * 431.0 / 0x10000; + cam_mul[0] = get2() * 567.0f / 0x10000; + cam_mul[2] = get2() * 431.0f / 0x10000; } } diff --git a/rtengine/libraw/src/metadata/exif_gps.cpp b/rtengine/libraw/src/metadata/exif_gps.cpp index bc59371e5..5cc352b00 100644 --- a/rtengine/libraw/src/metadata/exif_gps.cpp +++ b/rtengine/libraw/src/metadata/exif_gps.cpp @@ -19,9 +19,10 @@ #include "../../internal/dcraw_defs.h" #include "../../internal/libraw_cameraids.h" -void LibRaw::parse_exif_interop(int base) +void LibRaw::parse_exif_interop(INT64 base) { - unsigned entries, tag, type, len, save; + unsigned entries, tag, type, len; + INT64 save; char value[4] = { 0,0,0,0 }; entries = get2(); INT64 fsize = ifp->size(); @@ -59,10 +60,11 @@ void LibRaw::parse_exif_interop(int base) } } -void LibRaw::parse_exif(int base) +void LibRaw::parse_exif(INT64 base) { - unsigned entries, tag, type, len, save, c; + unsigned entries, tag, type, len, c; double expo, ape; + INT64 save; unsigned kodak = !strncmp(make, "EASTMAN", 7) && tiff_nifds < 3; @@ -81,7 +83,7 @@ void LibRaw::parse_exif(int base) tiff_get(base, &tag, &type, &len, &save); INT64 savepos = ftell(ifp); - if (len > 8 && savepos + len > fsize * 2) + if (len > 8 && savepos + INT64(len) > fsize * 2LL) { fseek(ifp, save, SEEK_SET); // Recover tiff-read position!! continue; @@ -107,7 +109,7 @@ void LibRaw::parse_exif(int base) imgdata.color.ExifColorSpace = LIBRAW_COLORSPACE_AdobeRGB; break; case 0x9400: - imCommon.exifAmbientTemperature = getreal(type); + imCommon.exifAmbientTemperature = getrealf(type); if ((imCommon.CameraTemperature > -273.15f) && ((OlyID == OlyID_TG_5) || (OlyID == OlyID_TG_6)) @@ -115,19 +117,19 @@ void LibRaw::parse_exif(int base) imCommon.CameraTemperature += imCommon.exifAmbientTemperature; break; case 0x9401: - imCommon.exifHumidity = getreal(type); + imCommon.exifHumidity = getrealf(type); break; case 0x9402: - imCommon.exifPressure = getreal(type); + imCommon.exifPressure = getrealf(type); break; case 0x9403: - imCommon.exifWaterDepth = getreal(type); + imCommon.exifWaterDepth = getrealf(type); break; case 0x9404: - imCommon.exifAcceleration = getreal(type); + imCommon.exifAcceleration = getrealf(type); break; case 0x9405: - imCommon.exifCameraElevationAngle = getreal(type); + imCommon.exifCameraElevationAngle = getrealf(type); break; case 0xa405: // FocalLengthIn35mmFormat @@ -137,10 +139,10 @@ void LibRaw::parse_exif(int base) stmread(imgdata.shootinginfo.BodySerial, len, ifp); break; case 0xa432: // LensInfo, 42034dec, Lens Specification per EXIF standard - imgdata.lens.MinFocal = getreal(type); - imgdata.lens.MaxFocal = getreal(type); - imgdata.lens.MaxAp4MinFocal = getreal(type); - imgdata.lens.MaxAp4MaxFocal = getreal(type); + imgdata.lens.MinFocal = getrealf(type); + imgdata.lens.MaxFocal = getrealf(type); + imgdata.lens.MaxAp4MinFocal = getrealf(type); + imgdata.lens.MaxAp4MaxFocal = getrealf(type); break; case 0xa435: // LensSerialNumber stmread(imgdata.lens.LensSerial, len, ifp); @@ -155,10 +157,10 @@ void LibRaw::parse_exif(int base) fread(imgdata.color.RawDataUniqueID, 1, 16, ifp); break; case 0xc630: // DNG LensInfo, Lens Specification per EXIF standard - imgdata.lens.dng.MinFocal = getreal(type); - imgdata.lens.dng.MaxFocal = getreal(type); - imgdata.lens.dng.MaxAp4MinFocal = getreal(type); - imgdata.lens.dng.MaxAp4MaxFocal = getreal(type); + imgdata.lens.dng.MinFocal = getrealf(type); + imgdata.lens.dng.MaxFocal = getrealf(type); + imgdata.lens.dng.MaxAp4MinFocal = getrealf(type); + imgdata.lens.dng.MaxAp4MaxFocal = getrealf(type); break; case 0xc68b: /* 50827, OriginalRawFileName */ stmread(imgdata.color.OriginalRawFileName, len, ifp); @@ -172,27 +174,27 @@ void LibRaw::parse_exif(int base) imgdata.lens.Lens[0] = '\0'; break; case 0x9205: - imgdata.lens.EXIF_MaxAp = libraw_powf64l(2.0f, (getreal(type) / 2.0f)); + imgdata.lens.EXIF_MaxAp = libraw_powf64l(2.0f, getrealf(type) / 2.0f); break; case 0x829a: // 33434 - shutter = getreal(type); + shutter = getrealf(type); if (tiff_nifds > 0 && tiff_nifds <= LIBRAW_IFD_MAXCOUNT) tiff_ifd[tiff_nifds - 1].t_shutter = shutter; break; case 0x829d: // 33437, FNumber - aperture = getreal(type); + aperture = getrealf(type); break; case 0x8827: // 34855 iso_speed = get2(); break; case 0x8831: // 34865 if (iso_speed == 0xffff && !strncasecmp(make, "FUJI", 4)) - iso_speed = getreal(type); + iso_speed = getrealf(type); break; case 0x8832: // 34866 if (iso_speed == 0xffff && (!strncasecmp(make, "SONY", 4) || !strncasecmp(make, "CANON", 5))) - iso_speed = getreal(type); + iso_speed = getrealf(type); break; case 0x9003: // 36867 case 0x9004: // 36868 @@ -201,20 +203,20 @@ void LibRaw::parse_exif(int base) case 0x9201: // 37377 if ((expo = -getreal(type)) < 128 && shutter == 0.) { - shutter = libraw_powf64l(2.0, expo); + shutter = libraw_powf64l(2.0f, float(expo)); if (tiff_nifds > 0 && tiff_nifds <= LIBRAW_IFD_MAXCOUNT) tiff_ifd[tiff_nifds - 1].t_shutter = shutter; } break; case 0x9202: // 37378 ApertureValue if ((fabs(ape = getreal(type)) < 256.0) && (!aperture)) - aperture = libraw_powf64l(2.0, ape / 2); + aperture = libraw_powf64l(2.0f, float(ape / 2.0)); break; case 0x9209: // 37385 - flash_used = getreal(type); + flash_used = getrealf(type); break; case 0x920a: // 37386 - focal_len = getreal(type); + focal_len = getrealf(type); break; case 0x927c: // 37500 #ifndef USE_6BY9RPI @@ -239,14 +241,14 @@ void LibRaw::parse_exif(int base) pos = strstr(mn_text, "ev="); if (pos) - imCommon.ExposureCalibrationShift = atof(pos + 3); + imCommon.ExposureCalibrationShift = float(atof(pos + 3)); pos = strstr(mn_text, "gain_r="); if (pos) - cam_mul[0] = atof(pos + 7); + cam_mul[0] = float(atof(pos + 7)); pos = strstr(mn_text, "gain_b="); if (pos) - cam_mul[2] = atof(pos + 7); + cam_mul[2] = float(atof(pos + 7)); if ((cam_mul[0] > 0.001f) && (cam_mul[2] > 0.001f)) cam_mul[1] = cam_mul[3] = 1.0f; else @@ -259,7 +261,7 @@ void LibRaw::parse_exif(int base) char *pos2 = strstr(pos, " "); if (pos2) { - l = pos2 - pos; + l = LIM(ushort(pos2 - pos), 0, 511); memcpy(ccms, pos, l); ccms[l] = '\0'; #ifdef LIBRAW_WIN32_CALLS @@ -326,9 +328,10 @@ void LibRaw::parse_exif(int base) } } -void LibRaw::parse_gps_libraw(int base) +void LibRaw::parse_gps_libraw(INT64 base) { - unsigned entries, tag, type, len, save, c; + unsigned entries, tag, type, len, c; + INT64 save; entries = get2(); if (entries > 40) @@ -370,18 +373,18 @@ void LibRaw::parse_gps_libraw(int base) break; case 0x0002: if (len == 3) - FORC(3) imgdata.other.parsed_gps.latitude[c] = getreal(type); + FORC(3) imgdata.other.parsed_gps.latitude[c] = getrealf(type); break; case 0x0004: if (len == 3) - FORC(3) imgdata.other.parsed_gps.longitude[c] = getreal(type); + FORC(3) imgdata.other.parsed_gps.longitude[c] = getrealf(type); break; case 0x0007: if (len == 3) - FORC(3) imgdata.other.parsed_gps.gpstimestamp[c] = getreal(type); + FORC(3) imgdata.other.parsed_gps.gpstimestamp[c] = getrealf(type); break; case 0x0006: - imgdata.other.parsed_gps.altitude = getreal(type); + imgdata.other.parsed_gps.altitude = getrealf(type); break; case 0x0009: imgdata.other.parsed_gps.gpsstatus = getc(ifp); @@ -391,9 +394,10 @@ void LibRaw::parse_gps_libraw(int base) } } -void LibRaw::parse_gps(int base) +void LibRaw::parse_gps(INT64 base) { - unsigned entries, tag, type, len, save, c; + unsigned entries, tag, type, len, c; + INT64 save; entries = get2(); if (entries > 40) diff --git a/rtengine/libraw/src/metadata/fuji.cpp b/rtengine/libraw/src/metadata/fuji.cpp index 30e64c2ea..26ff12a15 100644 --- a/rtengine/libraw/src/metadata/fuji.cpp +++ b/rtengine/libraw/src/metadata/fuji.cpp @@ -60,7 +60,7 @@ int LibRaw::guess_RAFDataGeneration (uchar *RAFData_start) // returns offset to X-E2S, X-E3, X-H1, X-S10, X-H2 X-T2, X-T3, X-T4, X-T20, X-T30 X-Pro2, X-Pro3 - X100F, X100V + X100F, X100V, X100VI RAFData gen. set to 4096: - RAFData length is exactly 4096 @@ -99,8 +99,8 @@ int LibRaw::guess_RAFDataGeneration (uchar *RAFData_start) // returns offset to imFuji.RAFDataVersion = b23; } -//printf ("ID: 0x%llx, RAFDataVersion: 0x%04x, RAFDataGeneration: %d\n", -//ilm.CamID, imFuji.RAFDataVersion, imFuji.RAFDataGeneration); +// printf (">> ID: 0x%llx, RAFDataVersion: 0x%04x, RAFDataGeneration: %d\n", +// ilm.CamID, imFuji.RAFDataVersion, imFuji.RAFDataGeneration); return offsetWH_inRAFData; } @@ -168,17 +168,19 @@ void LibRaw::parseAdobeRAFMakernote() #endif #define get_average_WB(wb_index) \ - FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = \ - PrivateMknBuf.sget2(posPrivateMknBuf + (c << 1)); \ - if ((PrivateTagBytes == 16) && average_WBData) { \ - FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = \ - (icWBC[wb_index][GRGB_2_RGBG(c)] + \ - PrivateMknBuf.sget2(posPrivateMknBuf + (c << 1)+8)) /2; \ - } \ - if (use_WBcorr_coeffs) { \ - icWBC[wb_index][0] *= wbR_corr; \ - icWBC[wb_index][2] *= wbB_corr; \ - } + do { \ + FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = \ + PrivateMknBuf.sget2(posPrivateMknBuf + (c << 1)); \ + if ((PrivateTagBytes == 16) && average_WBData) { \ + FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = \ + (icWBC[wb_index][GRGB_2_RGBG(c)] + \ + PrivateMknBuf.sget2(posPrivateMknBuf + (c << 1)+8)) /2; \ + } \ + if (use_WBcorr_coeffs) { \ + icWBC[wb_index][0] = int(icWBC[wb_index][0]*wbR_corr); \ + icWBC[wb_index][2] = int(icWBC[wb_index][2]*wbB_corr); \ + } \ + } while(0) ushort use_WBcorr_coeffs = 0; double wbR_corr = 1.0; @@ -289,8 +291,8 @@ void LibRaw::parseAdobeRAFMakernote() PrivateMknBuf.sget2(posWB + (c << 1))) /2; } if (use_WBcorr_coeffs) { - icWBC[wb_ind][0] *= wbR_corr; - icWBC[wb_ind][2] *= wbB_corr; + icWBC[wb_ind][0] = int(icWBC[wb_ind][0]*wbR_corr); + icWBC[wb_ind][2] = int(icWBC[wb_ind][2]*wbB_corr); } posWB += 8; } @@ -298,7 +300,7 @@ void LibRaw::parseAdobeRAFMakernote() else if (PrivateTagID == 0x2ff0) { get_average_WB(LIBRAW_WBI_AsShot); - FORC4 cam_mul[c] = icWBC[LIBRAW_WBI_AsShot][c]; + FORC4 cam_mul[c] = float(icWBC[LIBRAW_WBI_AsShot][c]); } else if ((PrivateTagID == 0x4000) && ((PrivateTagBytes == 8) || (PrivateTagBytes == 16))) @@ -329,8 +331,8 @@ void LibRaw::parseAdobeRAFMakernote() PrivateMknBuf.checkoffset(posPrivateMknBuf + 8); // will raise exception if no space guess_RAFDataGeneration (PrivateMknBuf.data() + posPrivateMknBuf); -//printf ("ID: 0x%llx, RAFDataVersion: 0x%04x, RAFDataGeneration: %d\n", -//ilm.CamID, imFuji.RAFDataVersion, imFuji.RAFDataGeneration); +// printf (">> ID: 0x%llx, RAFDataVersion: 0x%04x, RAFDataGeneration: %d\n", +// ilm.CamID, imFuji.RAFDataVersion, imFuji.RAFDataGeneration); for (posWB = 0; posWB < (int)PrivateTagBytes - 16; posWB++) { @@ -358,10 +360,12 @@ void LibRaw::parseAdobeRAFMakernote() (imFuji.RAFDataVersion == 0x0265) || // X-E4, X-T5 (imFuji.RAFDataVersion == 0x0266) || // X-T30 II (imFuji.RAFDataVersion == 0x0267) || // GFX 100 II + (imFuji.RAFDataVersion == 0x0369) || // X100VI !strcmp(model, "X-Pro3") || !strcmp(model, "GFX 100 II") || !strcmp(model, "GFX100 II") || !strcmp(model, "GFX 100S") || !strcmp(model, "GFX100S") || !strcmp(model, "GFX 50S II") || !strcmp(model, "GFX50S II") || + !strcmp(model, "X100VI") || !strcmp(model, "X100V") || !strcmp(model, "X-H2") || !strcmp(model, "X-H2S") || @@ -506,6 +510,10 @@ void LibRaw::parseAdobeRAFMakernote() { wb_section_offset = 0x1840; } + else if (imFuji.RAFDataVersion == 0x0369) // X100VI + { + wb_section_offset = 0x0c5a; + } /* try for unknown RAF Data versions */ else if (!strcmp(model, "X-Pro2")) @@ -601,6 +609,11 @@ void LibRaw::parseAdobeRAFMakernote() if (PrivateMknBuf.isWB(posPrivateMknBuf + 0x2014)) wb_section_offset = 0x2014; } + else if (!strcmp(model, "X100VI")) + { + if (PrivateMknBuf.isWB(posPrivateMknBuf + 0x0c5a)) + wb_section_offset = 0x0c5a; + } else if (!strcmp(model, "X100V")) { if (PrivateMknBuf.isWB(posPrivateMknBuf + 0x2078)) @@ -770,7 +783,7 @@ void LibRaw::parseAdobeRAFMakernote() { for (int iCCT = 0; iCCT < 31; iCCT++) { - icWBCCTC[iCCT][0] = FujiCCT_K[iCCT]; + icWBCCTC[iCCT][0] = float(FujiCCT_K[iCCT]); icWBCCTC[iCCT][1] = PrivateMknBuf.sget2(wb_section_offset + iCCT * 6 + 2); icWBCCTC[iCCT][2] = icWBCCTC[iCCT][4] = PrivateMknBuf.sget2(wb_section_offset + iCCT * 6); icWBCCTC[iCCT][3] = PrivateMknBuf.sget2(wb_section_offset + iCCT * 6 + 4); @@ -800,10 +813,10 @@ void LibRaw::parseAdobeRAFMakernote() wb[2] = PrivateMknBuf.sget4(posWB) << 1; posWB += 4; - if (tWB && (iCCT < 255)) + if (tWB && (iCCT < 64)) { - icWBCCTC[iCCT][0] = tWB; - FORC4 icWBCCTC[iCCT][c + 1] = wb[c]; + icWBCCTC[iCCT][0] = float(tWB); + FORC4 icWBCCTC[iCCT][c + 1] = float(wb[c]); iCCT++; } if (nWB != 0x46) @@ -952,7 +965,7 @@ void LibRaw::parseFujiMakernotes(unsigned tag, unsigned type, unsigned len, imFuji.WB_Preset = get2(); break; case 0x1011: - imCommon.FlashEC = getreal(type); + imCommon.FlashEC = getrealf(type); break; case 0x1020: imFuji.Macro = get2(); @@ -999,8 +1012,8 @@ void LibRaw::parseFujiMakernotes(unsigned tag, unsigned type, unsigned len, imFuji.SeriesLength = get2(); break; case 0x1106: - imFuji.PixelShiftOffset[0] = getreal(type); - imFuji.PixelShiftOffset[1] = getreal(type); + imFuji.PixelShiftOffset[0] = getrealf(type); + imFuji.PixelShiftOffset[1] = getrealf(type); break; case 0x1301: imFuji.FocusWarning = get2(); @@ -1018,16 +1031,16 @@ void LibRaw::parseFujiMakernotes(unsigned tag, unsigned type, unsigned len, imFuji.DevelopmentDynamicRange = get2(); break; case 0x1404: - ilm.MinFocal = getreal(type); + ilm.MinFocal = getrealf(type); break; case 0x1405: - ilm.MaxFocal = getreal(type); + ilm.MaxFocal = getrealf(type); break; case 0x1406: - ilm.MaxAp4MinFocal = getreal(type); + ilm.MaxAp4MinFocal = getrealf(type); break; case 0x1407: - ilm.MaxAp4MaxFocal = getreal(type); + ilm.MaxAp4MaxFocal = getrealf(type); break; case 0x140b: imFuji.AutoDynamicRange = get2(); @@ -1064,7 +1077,7 @@ void LibRaw::parseFujiMakernotes(unsigned tag, unsigned type, unsigned len, return; } -void LibRaw::parse_fuji_thumbnail(int offset) +void LibRaw::parse_fuji_thumbnail(INT64 offset) { uchar xmpmarker[] = "http://ns.adobe.com/xap/1.0/"; uchar buf[sizeof(xmpmarker)+1]; @@ -1089,9 +1102,9 @@ void LibRaw::parse_fuji_thumbnail(int offset) if ((fread(buf, 1, xmpsz, ifp) == xmpsz) && !memcmp(buf, xmpmarker, xmpsz)) // got it { xmplen = len - xmpsz - 2; - xmpdata = (char*) malloc(xmplen+1); - fread(xmpdata, 1, xmplen, ifp); - xmpdata[xmplen] = 0; + xmpdata = (char*) calloc(xmplen+1,1); + unsigned br = fread(xmpdata, 1, xmplen, ifp); + xmpdata[br] = 0; break; } } @@ -1103,20 +1116,23 @@ void LibRaw::parse_fuji_thumbnail(int offset) fseek(ifp, pos, SEEK_SET); } -void LibRaw::parse_fuji(int offset) +void LibRaw::parse_fuji(INT64 offset) { - unsigned entries, tag, len, save, c; + unsigned entries, tag, len, c; + INT64 save; #define get_average_WB(wb_index) \ - FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = get2(); \ - if ((len == 16) && average_WBData) { \ - FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = \ - (icWBC[wb_index][GRGB_2_RGBG(c)] + get2())/2; \ - } \ - if (use_WBcorr_coeffs) { \ - icWBC[wb_index][0] *= wbR_corr; \ - icWBC[wb_index][2] *= wbB_corr; \ - } + do { \ + FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = get2(); \ + if ((len == 16) && average_WBData) { \ + FORC4 icWBC[wb_index][GRGB_2_RGBG(c)] = \ + (icWBC[wb_index][GRGB_2_RGBG(c)] + get2())/2; \ + } \ + if (use_WBcorr_coeffs) { \ + icWBC[wb_index][0] = int(icWBC[wb_index][0] * wbR_corr); \ + icWBC[wb_index][2] = int( icWBC[wb_index][2] * wbB_corr); \ + } \ + } while(0) ushort raw_inset_present = 0; ushort use_WBcorr_coeffs = 0; @@ -1204,7 +1220,7 @@ void LibRaw::parse_fuji(int offset) else if (tag == 0x2ff0) // WB_GRGBLevels { get_average_WB(LIBRAW_WBI_AsShot); - FORC4 cam_mul[c] = icWBC[LIBRAW_WBI_AsShot][c]; + FORC4 cam_mul[c] = float(icWBC[LIBRAW_WBI_AsShot][c]); } else if ((tag == 0x4000) && ((len == 8) || (len == 16))) @@ -1229,7 +1245,7 @@ void LibRaw::parse_fuji(int offset) else if ((s1*16) == s2) imFuji.BrightnessCompensation = 4.0f; else - imFuji.BrightnessCompensation = log(double(s2)/double(s1))/log(2.0); + imFuji.BrightnessCompensation = logf(float(s2)/float(s1))/logf(2.f); } else if (tag == 0x9650) // RawExposureBias { @@ -1258,8 +1274,8 @@ void LibRaw::parse_fuji(int offset) (icWBC[wb_ind][GRGB_2_RGBG(c)] +get2()) /2; } if (use_WBcorr_coeffs) { - icWBC[LIBRAW_WBI_Custom1 + wb_ind][0] *= wbR_corr; - icWBC[LIBRAW_WBI_Custom1 + wb_ind][2] *= wbB_corr; + icWBC[LIBRAW_WBI_Custom1 + wb_ind][0] = int(icWBC[LIBRAW_WBI_Custom1 + wb_ind][0] * wbR_corr); + icWBC[LIBRAW_WBI_Custom1 + wb_ind][2] = int(icWBC[LIBRAW_WBI_Custom1 + wb_ind][2] * wbB_corr); } } } @@ -1309,10 +1325,10 @@ void LibRaw::parse_fuji(int offset) wb[1] = get4(); wb[3] = get4(); wb[2] = get4() << 1; - if (tWB && (iCCT < 255)) + if (tWB && (iCCT < 64)) { - icWBCCTC[iCCT][0] = tWB; - FORC4 icWBCCTC[iCCT][c + 1] = wb[c]; + icWBCCTC[iCCT][0] = float(tWB); + FORC4 icWBCCTC[iCCT][c + 1] = float(wb[c]); iCCT++; } if (nWB != 70) diff --git a/rtengine/libraw/src/metadata/hasselblad_model.cpp b/rtengine/libraw/src/metadata/hasselblad_model.cpp index a8c919c70..437c12185 100644 --- a/rtengine/libraw/src/metadata/hasselblad_model.cpp +++ b/rtengine/libraw/src/metadata/hasselblad_model.cpp @@ -148,7 +148,7 @@ static const char *Hasselblad_SensorEnclosures[] = { if (imHassy.format == LIBRAW_HF_AdobeDNG) { // Adobe DNG, use LocalizedCameraModel imgdata.color.LocalizedCameraModel[63] = 0; // make sure it's 0-terminated if ((ps = strrchr(imgdata.color.LocalizedCameraModel, '-'))) - c = ps-imgdata.color.LocalizedCameraModel; + c = int(ps-imgdata.color.LocalizedCameraModel); else c = int(strlen(imgdata.color.LocalizedCameraModel)); int cc = MIN(c, (int)sizeof(tmp_model)-1); memcpy(tmp_model, imgdata.color.LocalizedCameraModel,cc); @@ -162,7 +162,7 @@ static const char *Hasselblad_SensorEnclosures[] = { memmove(normalized_model, normalized_model+11, 64-11); } else { if ((ps = strrchr(imgdata.color.UniqueCameraModel, '/'))) { - c = ps-imgdata.color.UniqueCameraModel; + c = int(ps-imgdata.color.UniqueCameraModel); } else c = int(strlen(imgdata.color.UniqueCameraModel)); int cc = MIN(c, (int)sizeof(tmp_model)-1); @@ -410,7 +410,7 @@ static const char *Hasselblad_SensorEnclosures[] = { } } - } else if (((raw_width == 8374) && (raw_height == 6304)) || // (H5D-50c) + } else if (((raw_width == 8374) && (raw_height == 6304)) || // (H5D-50c, CFV-50c) ((raw_width == 8384) && (raw_height == 6304)) || // (X1D-50c, "X1D II 50C", "CFV II 50C") ((raw_width == 8280) && (raw_height == 6208)) || // Adobe crop ((raw_width == 8272) && (raw_height == 6200))) { // Phocus crop @@ -458,7 +458,7 @@ static const char *Hasselblad_SensorEnclosures[] = { if (!imHassy.SensorCode) imHassy.SensorCode = 17; if (!imHassy.CoatingCode) imHassy.CoatingCode = 5; - } else if (((raw_width == 11904) && (raw_height == 8842)) || // X2D 100C + } else if (((raw_width == 11904) && (raw_height == 8842)) || // X2D 100C, CFV 100C ((raw_width == 11664) && (raw_height == 8750)) || // Adobe crop ((raw_width == 11656) && (raw_height == 8742))) { // Phocus crop strcpy(imHassy.Sensor, "-100c"); @@ -534,7 +534,7 @@ static const char *Hasselblad_SensorEnclosures[] = { } else if (!imgdata.lens.Lens[0] && (aperture > 1.0f) && (focal_len > 10.0f)) { - ilm.LensID = focal_len; + ilm.LensID = uint64_t(focal_len); if (ilm.LensID == 35) { ilm.FocalType = LIBRAW_FT_ZOOM_LENS; ilm.LensID = LIBRAW_MOUNT_Hasselblad_XCD*100000000ULL + @@ -548,8 +548,8 @@ static const char *Hasselblad_SensorEnclosures[] = { } } } - -// printf (">> SensorCode: %d, CoatingCode: %d, Sensor: %s\n", imHassy.SensorCode, imHassy.CoatingCode, imHassy.Sensor); +// printf (">>Host Body: =%s= CaptureSequenceInitiator: =%s=\n", imHassy.HostBody, imHassy.CaptureSequenceInitiator); +// printf (">> SensorCode: %d, CoatingCode: %d, Sensor: =%s=\n", imHassy.SensorCode, imHassy.CoatingCode, imHassy.Sensor); // printf (">> raw_width: %d, raw_height: %d\n", raw_width, raw_height); if (normalized_model[0] && !CM_found) diff --git a/rtengine/libraw/src/metadata/identify.cpp b/rtengine/libraw/src/metadata/identify.cpp index bb43081bc..4e6da0297 100644 --- a/rtengine/libraw/src/metadata/identify.cpp +++ b/rtengine/libraw/src/metadata/identify.cpp @@ -129,6 +129,81 @@ const char *LibRaw::cameramakeridx2maker(unsigned maker) return 0; } +int LibRaw::simplify_make_model(unsigned *_maker_index, + char *_make, unsigned _make_buf_size, char *_model, unsigned _model_buf_size) +{ + if (!_make || _make_buf_size < 2 || !_model || _model_buf_size < 2) + return -1; + + unsigned mkindex = 0; + for (int i = 0; i < int(sizeof CorpTable / sizeof *CorpTable); i++) + { + if (strcasestr(_make, CorpTable[i].CorpName)) + { /* Simplify company names */ + mkindex = CorpTable[i].CorpId; + break; + } + } + + if (mkindex == LIBRAW_CAMERAMAKER_HMD_Global && !strncasecmp(_model, "Nokia", 5)) + { + mkindex = LIBRAW_CAMERAMAKER_Nokia; + } + else if (mkindex == LIBRAW_CAMERAMAKER_JK_Imaging && !strncasecmp(_model, "Kodak", 5)) + { + mkindex = LIBRAW_CAMERAMAKER_Kodak; + } + else if (mkindex == LIBRAW_CAMERAMAKER_Ricoh && !strncasecmp(_model, "PENTAX", 6)) + { + mkindex = LIBRAW_CAMERAMAKER_Pentax; + } + + for (int i = 0; i < int(sizeof CorpTable / sizeof *CorpTable); i++) + { + if (mkindex == (unsigned)CorpTable[i].CorpId) + { + strncpy(_make, CorpTable[i].CorpName, _make_buf_size - 1); + _make[_make_buf_size - 1] = 0; + break; + } + } + + char *cp = 0; + if ((mkindex == LIBRAW_CAMERAMAKER_Kodak || mkindex == LIBRAW_CAMERAMAKER_Leica) && + ((cp = strcasestr(_model, " DIGITAL CAMERA")) || (cp = strstr(_model, "FILE VERSION")))) + { + *cp = 0; + } + + remove_trailing_spaces(_make, _make_buf_size); + remove_trailing_spaces(_model, _model_buf_size); + + int i = int(strnlen(_make, _make_buf_size - 1)); /* Remove make from model */ + if (!strncasecmp(_model, _make, i) && _model[i++] == ' ') + memmove(_model, _model + i, _model_buf_size - i); + + if (mkindex == LIBRAW_CAMERAMAKER_Fujifilm && !strncmp(_model, "FinePix", 7)) + { + memmove(_model, _model + 7, strlen(_model) - 6); + if (_model[0] == ' ') + { + memmove(_model, _model + 1, strlen(_model)); + } + } + else if ((mkindex == LIBRAW_CAMERAMAKER_Kodak || mkindex == LIBRAW_CAMERAMAKER_Konica) && + !strncmp(_model, "Digital Camera ", 15)) + { + memmove(_model, _model + 15, strlen(_model) - 14); + } + + if (mkindex) + { + if (_maker_index) + *_maker_index = mkindex; + return 0; // maker index is set + } + return 1; // maker index is not set +} /* Identify which camera created this file, and set global variables @@ -365,8 +440,8 @@ void LibRaw::identify() // clang-format on char head[64] = {0}, *cp; - int hlen, fsize, flen, zero_fsize = 1, i, c; - INT64 fsize64; + int hlen, zero_fsize = 1, i, c; + INT64 flen, fsize; struct jhead jh; unsigned camera_count = @@ -447,19 +522,19 @@ void LibRaw::identify() if (fread(head, 1, 64, ifp) < 64) throw LIBRAW_EXCEPTION_IO_CORRUPT; - libraw_internal_data.unpacker_data.lenRAFData = - libraw_internal_data.unpacker_data.posRAFData = 0; + libraw_internal_data.unpacker_data.lenRAFData = 0; + libraw_internal_data.unpacker_data.posRAFData = 0; fseek(ifp, 0, SEEK_END); - fsize64 = ftell(ifp); - if(fsize64 > LIBRAW_MAX_NONDNG_RAW_FILE_SIZE && fsize64 > LIBRAW_MAX_DNG_RAW_FILE_SIZE) + flen = fsize = ftell(ifp); + if(fsize > LIBRAW_MAX_NONDNG_RAW_FILE_SIZE && fsize > LIBRAW_MAX_DNG_RAW_FILE_SIZE + && fsize > LIBRAW_MAX_CR3_RAW_FILE_SIZE) throw LIBRAW_EXCEPTION_TOOBIG; - flen = fsize = ftell(ifp); if ((cp = (char *)memmem(head, 32, (char *)"MMMM", 4)) || (cp = (char *)memmem(head, 32, (char *)"IIII", 4))) { - parse_phase_one(cp - head); + parse_phase_one(int(cp - head)); if (cp - head && parse_tiff(0)) apply_tiff(); } @@ -468,7 +543,7 @@ void LibRaw::identify() if (!memcmp(head + 6, "HEAPCCDR", 8)) { data_offset = hlen; - parse_ciff(hlen, flen - hlen, 0); + parse_ciff(INT64(hlen), int(flen - hlen), 0); load_raw = &LibRaw::canon_load_raw; } else if (parse_tiff(0)) @@ -635,18 +710,23 @@ void LibRaw::identify() if (dng_version) { - if (fsize64 > LIBRAW_MAX_DNG_RAW_FILE_SIZE) + if (fsize > LIBRAW_MAX_DNG_RAW_FILE_SIZE) throw LIBRAW_EXCEPTION_TOOBIG; } + else if (load_raw == &LibRaw::crxLoadRaw) + { + if (fsize > LIBRAW_MAX_CR3_RAW_FILE_SIZE) + throw LIBRAW_EXCEPTION_TOOBIG; + } else { - if (fsize64 > LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) + if (fsize > LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) throw LIBRAW_EXCEPTION_TOOBIG; } if (make[0] == 0) for (zero_fsize = i = 0; i < (int)camera_count; i++) - if (fsize == (int)table[i].fsize) + if (fsize == (INT64)table[i].fsize) { strcpy(make, table[i].t_make); strcpy(model, table[i].t_model); @@ -667,7 +747,7 @@ void LibRaw::identify() colors = 1; filters = 0; } - switch (tiff_bps = (fsize - data_offset) * 8 / (raw_width * raw_height)) + switch (tiff_bps = unsigned((fsize - data_offset) * 8LL / (INT64(raw_width) * INT64(raw_height)))) { case 6: load_raw = &LibRaw::minolta_rd175_load_raw; @@ -677,7 +757,7 @@ void LibRaw::identify() load_raw = &LibRaw::eight_bit_load_raw; break; case 10: - if ((fsize - data_offset) / raw_height * 3 >= raw_width * 4) + if ((fsize - data_offset) / INT64(raw_height) * 3LL >= INT64(raw_width) * 4LL) { load_raw = &LibRaw::android_loose_load_raw; break; @@ -704,7 +784,7 @@ void LibRaw::identify() } if (zero_fsize) fsize = 0; - if (make[0] == 0 && fsize64 < 25000000LL) + if (make[0] == 0 && fsize < 25000000LL) parse_smal(0, flen); if (make[0] == 0) { @@ -835,6 +915,14 @@ void LibRaw::identify() // make sure strings are terminated desc[511] = artist[63] = make[63] = model[63] = model2[63] = 0; +#if 1 + unsigned mkindex = 0; + if (simplify_make_model(&mkindex, make, sizeof(make), model, sizeof(model)) == 0) + { + maker_index = mkindex; + } +#else + for (i = 0; i < int(sizeof CorpTable / sizeof *CorpTable); i++) { if (strcasestr(make, CorpTable[i].CorpName)) @@ -881,6 +969,7 @@ void LibRaw::identify() !strncmp(model, "Digital Camera ", 15)) { memmove(model, model + 15, strlen(model) - 14); } +#endif desc[511] = artist[63] = make[63] = model[63] = model2[63] = 0; if (!is_raw) @@ -917,16 +1006,12 @@ void LibRaw::identify() else if((tiff_sampleformat == 0 || tiff_sampleformat == 1) && tiff_bps>=8 && tiff_bps <=16) load_raw = &LibRaw::deflate_dng_load_raw; break; -#ifdef USE_GPRSDK case 9: load_raw = &LibRaw::vc5_dng_load_raw_placeholder; break; -#endif -#ifdef USE_DNGSDK case 52546: load_raw = &LibRaw::jxl_dng_load_raw_placeholder; break; -#endif case 34892: load_raw = &LibRaw::lossy_dng_load_raw; break; @@ -1156,7 +1241,7 @@ dng_skip: (tiff_bps > 16 && (load_raw != &LibRaw::deflate_dng_load_raw && load_raw != &LibRaw::uncompressed_fp_dng_load_raw)) || - tiff_samples > 6 || colors > 4) + tiff_samples > 6 || colors > 4 || colors == 2) is_raw = 0; if (raw_width < 22 || raw_width > 64000 || raw_height < 22 || @@ -1586,11 +1671,13 @@ void LibRaw::identify_process_dng_fields() bl64 /= LIM(cnt, 1, 4096); } int rblack = black + bl4 + bl64; - for (int chan = 0; chan < colors && chan < 4; chan++) - imgdata.color.linear_max[chan] = - (maximum - rblack) * - imgdata.color.dng_levels.LinearResponseLimit + - rblack; + for (int chan = 0; chan < colors && chan < 4; chan++) + imgdata.color.linear_max[chan] = + unsigned( + (maximum - rblack) * + imgdata.color.dng_levels.LinearResponseLimit + + rblack + ); if (imgdata.color.linear_max[1] && !imgdata.color.linear_max[3]) imgdata.color.linear_max[3] = imgdata.color.linear_max[1]; } @@ -1659,6 +1746,13 @@ void LibRaw::identify_finetune_pentax() filters = 0x16161616; top_margin = 2; } + if (width == 6080 && (unique_id == PentaxID_KF)) + { + top_margin = 28; + height = 4024; + left_margin = 56; + width = 6024; + } if ((width == 6080) && (unique_id == PentaxID_K_3_II)) { left_margin = 4; @@ -1671,6 +1765,18 @@ void LibRaw::identify_finetune_pentax() top_margin = 34; height = 4160; } + if (unique_id == PentaxID_K_3_III_Mono) + { + if (width == 6304) + { + left_margin = 26; + width = 6224; + top_margin = 34; + height = 4160; + } + filters = 0; + colors = 1; + } if ((width == 6112) && (unique_id == PentaxID_KP)) { // From DNG, maybe too strict @@ -1698,7 +1804,7 @@ void LibRaw::identify_finetune_pentax() width = 4014; } -void LibRaw::identify_finetune_by_filesize(int fsize) +void LibRaw::identify_finetune_by_filesize(INT64 fsize) { if (fsize == 4771840) @@ -1731,7 +1837,7 @@ void LibRaw::identify_finetune_by_filesize(int fsize) } } -void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) +void LibRaw::identify_finetune_dcr(char head[64], INT64 fsize, INT64 flen) { static const short pana[][6] = { // raw_width, raw_height, left_margin, top_margin, width_increment, @@ -2109,8 +2215,8 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) else if (makeIs(LIBRAW_CAMERAMAKER_Olympus)) { if (OlyID == OlyID_C_740UZ) { // (fsize == 4775936) - i = find_green(12, 32, 1188864, 3576832); - c = find_green(12, 32, 2383920, 2387016); + i = int(find_green(12, 32, 1188864, 3576832)); + c = int(find_green(12, 32, 2383920, 2387016)); if (abs(i) < abs(c)) { SWAP(i, c); load_flags = 24; @@ -2152,9 +2258,17 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) if (load_raw == &LibRaw::unpacked_load_raw) { load_flags = 4; - if (imOly.ValidBits == 10) load_flags += 2; + if (imOly.ValidBits == 10) load_flags += 2; } - tiff_bps = imOly.ValidBits; + tiff_bps = imOly.ValidBits; + if (tiff_bps == 14) + { + black *= 4; + FORC(4) cblack[c] *= 4; + FORC(4) imgdata.color.linear_max[c] *= 4; + FORC(MIN(cblack[4] * cblack[5], LIBRAW_CBLACK_SIZE - 6)) cblack[c] *= 4; + } + if ((OlyID == OlyID_E_300) || (OlyID == OlyID_E_500)) { @@ -2176,17 +2290,19 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) } else if (OlyID == OlyID_SP_550UZ) { - thumb_length = flen - (thumb_offset = 0xa39800); + thumb_length = unsigned(flen - INT64(thumb_offset = 0xa39800)); thumb_height = 480; thumb_width = 640; } else if (OlyID == OlyID_TG_4) { width -= 16; - } - else if ((OlyID == OlyID_TG_5) || - (OlyID == OlyID_TG_6)) { + else if ( + (OlyID == OlyID_TG_5) || + (OlyID == OlyID_TG_6) || + (OlyID == OlyID_TG_7) + ) { width -= 26; } } @@ -2389,15 +2505,18 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) default: /* insert model name-based width/height/margins/etc. assignments */ - /* raw_inset_crops default*/ - if (imgdata.sizes.raw_inset_crops[0].cwidth > 0 && imgdata.sizes.raw_inset_crops[0].cwidth <= raw_width && - imgdata.sizes.raw_inset_crops[0].cheight > 0 && imgdata.sizes.raw_inset_crops[0].cheight <= raw_height) - { - top_margin = imgdata.sizes.raw_inset_crops[0].ctop; - left_margin = imgdata.sizes.raw_inset_crops[0].cleft; - width = imgdata.sizes.raw_inset_crops[0].cwidth; - height = imgdata.sizes.raw_inset_crops[0].cheight; - } + if (strncmp(model, "S6000", 5) && strncmp(model, "S6500", 5)) + { + /* raw_inset_crops default*/ + if (imgdata.sizes.raw_inset_crops[0].cwidth > 0 && imgdata.sizes.raw_inset_crops[0].cwidth <= raw_width && + imgdata.sizes.raw_inset_crops[0].cheight > 0 && imgdata.sizes.raw_inset_crops[0].cheight <= raw_height) + { + top_margin = imgdata.sizes.raw_inset_crops[0].ctop; + left_margin = imgdata.sizes.raw_inset_crops[0].cleft; + width = imgdata.sizes.raw_inset_crops[0].cwidth; + height = imgdata.sizes.raw_inset_crops[0].cheight; + } + } break; } } @@ -2613,7 +2732,7 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) } else if ((imHassy.SensorCode == 15) && - !imHassy.SensorSubCode && // Hasselblad H5D-50c + !imHassy.SensorSubCode && // Hasselblad H5D-50c, CFV-50c imHassy.uncropped) { left_margin = 52; top_margin = 100; @@ -2659,7 +2778,7 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) height = raw_height - top_margin; } else if ((imHassy.SensorCode == 20) && imHassy.uncropped) - { // Hasselblad X2D-100c + { // Hasselblad X2D-100c, CFV-100c left_margin = 124; width = 11664; top_margin = 92; @@ -2830,7 +2949,9 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) load_raw = &LibRaw::sony_load_raw; } - else if ((unique_id == SonyID_ILCE_7RM5) || (unique_id == SonyID_ILCE_7CR)) + else if ((unique_id == SonyID_ILCE_7RM5) || + (unique_id == SonyID_ILCE_7CR) || + (unique_id == SonyID_ILX_LR1)) { if (raw_width == 6304) { @@ -2892,6 +3013,35 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) width -= height > 3664 ? 8 : 32; } + else if (unique_id == SonyID_ILCE_9M3) + { + if (raw_width == 6048) + width -= 36; // + else if (raw_width == 6144) // Lossless/L, FF + { + width = 6012; + height = 4020; + } + else if (raw_width == 4096) // Lossless/M + { + width = 3944; + height = 2644; + } + else if (raw_width == 3072) // Lossless/S + { + width = 3016; + height = 2008; + } + else if (raw_width == 3968) // Uncompressed, APS + { + width = 3948; + } + else // We do not have other samples, offer vendor crop to caller + { + width = raw_width - 32; // fallback + imgdata.process_warnings |= LIBRAW_WARN_VENDOR_CROP_SUGGESTED; + } + } else if (raw_width == 6048) { // Sony SLT-A65, DSC-RX1, SLT-A77, DSC-RX1, ILCA-77M2, // ILCE-7M3, NEX-7, SLT-A99, ILCE-7, DSC-RX1R, ILCE-6000, @@ -2966,6 +3116,11 @@ void LibRaw::identify_finetune_dcr(char head[64], int fsize, int flen) width = 7028; height = 4688; } + else if (raw_width == 4736) // APS-C crop + { + width = 4692; + //height = 3080; + } else if (raw_width == 5120) // Lossy/Medium { width = 4624; diff --git a/rtengine/libraw/src/metadata/identify_tools.cpp b/rtengine/libraw/src/metadata/identify_tools.cpp index caf1cddf0..ec84b26fb 100644 --- a/rtengine/libraw/src/metadata/identify_tools.cpp +++ b/rtengine/libraw/src/metadata/identify_tools.cpp @@ -44,7 +44,7 @@ float LibRaw::find_green(int bps, int bite, int off0, int off1) UINT64 bitbuf = 0; int vbits, col, i, c; ushort img[2][2064]; - double sum[] = {0, 0}; + float sum[] = {0, 0}; if (width > 2064) return 0.f; // too wide @@ -59,7 +59,7 @@ float LibRaw::find_green(int bps, int bite, int off0, int off1) for (i = 0; i < bite; i += 8) bitbuf |= (unsigned)(fgetc(ifp) << i); } - img[c][col] = bitbuf << (64 - bps - vbits) >> (64 - bps); + img[c][col] = ushort((bitbuf << (64 - bps - vbits) >> (64 - bps)) & 0xffff); } } FORC(width - 1) @@ -68,7 +68,7 @@ float LibRaw::find_green(int bps, int bite, int off0, int off1) sum[~c & 1] += ABS(img[1][c] - img[0][c + 1]); } if (sum[0] >= 1.0 && sum[1] >= 1.0) - return 100 * log(sum[0] / sum[1]); + return 100.f * logf(sum[0] / sum[1]); else return 0.f; } @@ -94,7 +94,7 @@ void LibRaw::remove_trailing_spaces(char *string, size_t len) if (len < 3) return; // also not needed len = strnlen(string, len - 1); - for (size_t i = len - 1; i >= 0; i--) + for (int i = int(len) - 1; i >= 0; i--) { if (isspace((unsigned char)string[i])) string[i] = 0; @@ -109,7 +109,7 @@ void LibRaw::remove_caseSubstr(char *string, char *subStr) // replace a substrin while ((found = strcasestr(string,subStr))) { if (!found) return; int fill_len = int(strlen(subStr)); - int p = found - string; + int p = int(found - string); for (int i=p; i c) && (!strncasecmp(pkti, "Lens:", c))) { - ilm.CurFocal = atoi(pkti + c); + ilm.CurFocal = float(atoi(pkti + c)); } c = 9; if (((int)strlen(pkti) > c) && (!strncasecmp(pkti, "Aperture:", c))) @@ -181,17 +182,17 @@ void LibRaw::parse_kodak_ifd(int base) { c++; } - ilm.CurAp = atof(pkti + c); + ilm.CurAp = float(atof(pkti + c)); } c = 10; if (((int)strlen(pkti) > c) && (!strncasecmp(pkti, "ISO Speed:", c))) { - iso_speed = atoi(pkti + c); + iso_speed = float(atoi(pkti + c)); } c = 13; if (((int)strlen(pkti) > c) && (!strncasecmp(pkti, "Focal Length:", c))) { - ilm.CurFocal = atoi(pkti + c); + ilm.CurFocal = float(atoi(pkti + c)); } c = 13; if (((int)strlen(pkti) > c) && (!strncasecmp(pkti, "Max Aperture:", c))) @@ -200,7 +201,7 @@ void LibRaw::parse_kodak_ifd(int base) { c++; } - ilm.MaxAp4CurFocal = atof(pkti + c); + ilm.MaxAp4CurFocal = float(atof(pkti + c)); } c = 13; if (((int)strlen(pkti) > c) && (!strncasecmp(pkti, "Min Aperture:", c))) @@ -209,7 +210,7 @@ void LibRaw::parse_kodak_ifd(int base) { c++; } - ilm.MinAp4CurFocal = atof(pkti + c); + ilm.MinAp4CurFocal = float(atof(pkti + c)); } #ifdef LIBRAW_WIN32_CALLS pkti = strtok(NULL, "\x0a"); @@ -221,7 +222,7 @@ void LibRaw::parse_kodak_ifd(int base) } else if (tag == 0x03f3) // 1011 - imCommon.FlashEC = getreal(type); + imCommon.FlashEC = getrealf(type); else if (tag == 0x03fc) // 1020 { @@ -232,14 +233,14 @@ void LibRaw::parse_kodak_ifd(int base) else if (tag == 0x03fd && len == 72) // 1021 { /* WB set in software */ fseek(ifp, 40, SEEK_CUR); - FORC3 cam_mul[c] = 2048.0 / fMAX(1.0f, get2()); + FORC3 cam_mul[c] = 2048.0f / fMAX(1.0f, get2()); wbi = -2; } else if ((tag == 0x0406) && (len == 1)) // 1030 - imCommon.CameraTemperature = getreal(type); + imCommon.CameraTemperature = getrealf(type); else if ((tag == 0x0413) && (len == 1)) // 1043 - imCommon.SensorTemperature = getreal(type); + imCommon.SensorTemperature = getrealf(type); else if (tag == 0x0848) // 2120 Kodak_DCR_WBtags(LIBRAW_WBI_Daylight, type, wbi); else if (tag == 0x0849) // 2121 @@ -257,9 +258,9 @@ void LibRaw::parse_kodak_ifd(int base) Kodak_DCR_WBtags(LIBRAW_WBI_Auto, type, wbi); } else if (tag == 0x089f) // 2207 - imKodak.ISOCalibrationGain = getreal(type); + imKodak.ISOCalibrationGain = getrealf(type); else if (tag == 0x0903) // 2307 - imKodak.AnalogISO = iso_speed = getreal(type); + imKodak.AnalogISO = iso_speed = getrealf(type); else if (tag == 0x090d) // 2317 linear_table(len); else if (tag == 0x09ce) // 2510 diff --git a/rtengine/libraw/src/metadata/leica.cpp b/rtengine/libraw/src/metadata/leica.cpp index 182537485..40122c524 100644 --- a/rtengine/libraw/src/metadata/leica.cpp +++ b/rtengine/libraw/src/metadata/leica.cpp @@ -68,7 +68,7 @@ void LibRaw::setLeicaBodyFeatures(int LeicaMakernoteSignature) } else if ((LeicaMakernoteSignature == 0x0600) || // "T (Typ 701)", TL (LeicaMakernoteSignature == 0x0900) || // SL2, "SL2-S", "SL (Typ 601)", CL, Q2, "Q2 MONO" - (LeicaMakernoteSignature == 0x0a00) || // Q3 + (LeicaMakernoteSignature == 0x0a00) || // Q3, SL3 (LeicaMakernoteSignature == 0x1a00)) // TL2 { if ((model[0] == 'S') || (model[6] == 'S')) @@ -177,11 +177,12 @@ non_std: return 1; } -void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) +void LibRaw::parseLeicaMakernote(INT64 base, int uptag, unsigned MakernoteTagType) { int c; uchar ci, cj; - unsigned entries, tag, type, len, save; + unsigned entries, tag, type, len; + INT64 save; short morder, sorder = order; char buf[10]; int LeicaMakernoteSignature = -1; @@ -234,6 +235,13 @@ void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) if (len > 100 * 1024 * 1024) goto next; // 100Mb tag? No! + if (callbacks.makernotes_cb) + { + INT64 _savepos = ifp->tell(); + callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } + if (LeicaMakernoteSignature == -3) // M8 { if (tag == 0x0310) @@ -242,7 +250,7 @@ void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) } else if ((tag == 0x0313) && (fabs(ilm.CurAp) < 0.17f)) { - ilm.CurAp = getreal(type); + ilm.CurAp = getrealf(type); if (ilm.CurAp > 126.3) { ilm.CurAp = 0.0f; @@ -251,7 +259,7 @@ void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) } else if (tag == 0x0320) { - imCommon.CameraTemperature = getreal(type); + imCommon.CameraTemperature = getrealf(type); } } else if (LeicaMakernoteSignature == -2) // DMR @@ -336,7 +344,7 @@ void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) else if ((LeicaMakernoteSignature == 0x0800) || // "Q (Typ 116)" (LeicaMakernoteSignature == 0x0900) || // SL2, "SL2-S", "SL (Typ 601)", // CL, Q2, "Q2 MONO" - (LeicaMakernoteSignature == 0x0a00) // Q3 + (LeicaMakernoteSignature == 0x0a00) // Q3, SL3 ) { if ((tag == 0x0304) && (len == 1) && ((c = fgetc(ifp)) != 0) && @@ -356,7 +364,7 @@ void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) { if (tag == 0x34003402) { - imCommon.CameraTemperature = getreal(type); + imCommon.CameraTemperature = getrealf(type); } else if (tag == 0x34003405) { @@ -364,7 +372,7 @@ void LibRaw::parseLeicaMakernote(int base, int uptag, unsigned MakernoteTagType) } else if ((tag == 0x34003406) && (fabs(ilm.CurAp) < 0.17f)) { - ilm.CurAp = getreal(type); + ilm.CurAp = getrealf(type); if (ilm.CurAp > 126.3) { ilm.CurAp = 0.0f; diff --git a/rtengine/libraw/src/metadata/makernotes.cpp b/rtengine/libraw/src/metadata/makernotes.cpp index 20b90397f..7b0180a66 100644 --- a/rtengine/libraw/src/metadata/makernotes.cpp +++ b/rtengine/libraw/src/metadata/makernotes.cpp @@ -18,14 +18,15 @@ #include "../../internal/dcraw_defs.h" -void LibRaw::parseSigmaMakernote (int base, int /*uptag*/, unsigned /*dng_writer*/) { +void LibRaw::parseSigmaMakernote (INT64 base, int uptag, unsigned /*dng_writer*/) { unsigned wb_table1 [] = { LIBRAW_WBI_Auto, LIBRAW_WBI_Daylight, LIBRAW_WBI_Shade, LIBRAW_WBI_Cloudy, LIBRAW_WBI_Tungsten, LIBRAW_WBI_Fluorescent, LIBRAW_WBI_Flash, LIBRAW_WBI_Custom, LIBRAW_WBI_Custom1, LIBRAW_WBI_Custom2 }; - unsigned entries, tag, type, len, save; + unsigned entries, tag, type, len; + INT64 save; unsigned i; entries = get2(); @@ -33,14 +34,22 @@ unsigned wb_table1 [] = { return; while (entries--) { tiff_get(base, &tag, &type, &len, &save); + + if (callbacks.makernotes_cb) + { + INT64 _savepos = ifp->tell(); + callbacks.makernotes_cb(callbacks.makernotesparser_data, tag | (uptag << 16), type, len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } + if (tag == 0x0027) { ilm.LensID = get2(); } else if (tag == 0x002a) { - ilm.MinFocal = getreal(type); - ilm.MaxFocal = getreal(type); + ilm.MinFocal = getrealf(type); + ilm.MaxFocal = getrealf(type); } else if (tag == 0x002b) { - ilm.MaxAp4MinFocal = getreal(type); - ilm.MaxAp4MaxFocal = getreal(type); + ilm.MaxAp4MinFocal = getrealf(type); + ilm.MaxAp4MaxFocal = getrealf(type); } else if (tag == 0x0120) { const unsigned tblsz = (sizeof wb_table1 / sizeof wb_table1[0]); if ((len >= tblsz) && (len%3 == 0) && len/3 <= tblsz) { @@ -57,7 +66,7 @@ unsigned wb_table1 [] = { return; } -void LibRaw::parse_makernote_0xc634(int base, int uptag, unsigned dng_writer) +void LibRaw::parse_makernote_0xc634(INT64 base, int uptag, unsigned dng_writer) { if (metadata_blocks++ > LIBRAW_MAX_METADATA_BLOCKS) @@ -91,7 +100,8 @@ void LibRaw::parse_makernote_0xc634(int base, int uptag, unsigned dng_writer) return; } - unsigned entries, tag, type, len, save, c; + unsigned entries, tag, type, len, c; + INT64 save; uchar *CanonCameraInfo = NULL; unsigned lenCanonCameraInfo = 0; @@ -202,18 +212,25 @@ void LibRaw::parse_makernote_0xc634(int base, int uptag, unsigned dng_writer) if (len > 100 * 1024 * 1024) goto next; // 100Mb tag? No! + if (callbacks.makernotes_cb) + { + INT64 _savepos = ifp->tell(); + callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } + if (!strncmp(make, "Canon", 5)) { if (tag == 0x000d && len < 256000) { // camera info if (!tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) { - CanonCameraInfo = (uchar *)malloc(MAX(16, len)); + CanonCameraInfo = (uchar *)calloc(MAX(16, len),1); fread(CanonCameraInfo, len, 1, ifp); } else { - CanonCameraInfo = (uchar *)malloc(MAX(16, len * 4)); + CanonCameraInfo = (uchar *)calloc(MAX(16, len * 4),1); fread(CanonCameraInfo, len, 4, ifp); } lenCanonCameraInfo = len; @@ -331,7 +348,7 @@ void LibRaw::parse_makernote_0xc634(int base, int uptag, unsigned dng_writer) order = sorder; } -void LibRaw::parse_makernote(int base, int uptag) +void LibRaw::parse_makernote(INT64 base, int uptag) { if (metadata_blocks++ > LIBRAW_MAX_METADATA_BLOCKS) @@ -381,8 +398,9 @@ void LibRaw::parse_makernote(int base, int uptag) } - unsigned entries, tag, type, len, save, c; - unsigned i, wb[4] = {0, 0, 0, 0}; + unsigned entries, tag, type, len, c; + INT64 save; + unsigned wb[4] = {0, 0, 0, 0}; short morder, sorder = order; uchar *CanonCameraInfo = 0;; @@ -420,7 +438,8 @@ void LibRaw::parse_makernote(int base, int uptag) !strncmp(buf, "MLY", 3)) /* Minolta DiMAGE G series */ { order = 0x4d4d; - while ((i = ftell(ifp)) < data_offset && i < 16384) + INT64 ii; + while ((ii = ftell(ifp)) < data_offset && ii < 16384LL) { wb[0] = wb[2]; wb[2] = wb[1]; @@ -430,7 +449,7 @@ void LibRaw::parse_makernote(int base, int uptag) wb[3] = get2(); if (wb[1] == 256 && wb[3] == 256 && wb[0] > 256 && wb[0] < 640 && wb[2] > 256 && wb[2] < 640) - FORC4 cam_mul[c] = wb[c]; + FORC4 cam_mul[c] = float(wb[c]); } goto quit; } @@ -533,6 +552,14 @@ void LibRaw::parse_makernote(int base, int uptag) fseek(ifp, save, SEEK_SET); // Recover tiff-read position!! continue; } + + if (callbacks.makernotes_cb) + { + INT64 _savepos = ifp->tell(); + callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } + if (imKodak.MakerNoteKodak8a) { if ((tag == 0xff00) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG) && (len == 1)) @@ -561,12 +588,12 @@ void LibRaw::parse_makernote(int base, int uptag) { if (!tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) { - CanonCameraInfo = (uchar *)malloc(MAX(16, len)); + CanonCameraInfo = (uchar *)calloc(MAX(16, len),1); fread(CanonCameraInfo, len, 1, ifp); } else { - CanonCameraInfo = (uchar *)malloc(MAX(16, len * 4)); + CanonCameraInfo = (uchar *)calloc(MAX(16, len * 4),1); fread(CanonCameraInfo, len, 4, ifp); } lenCanonCameraInfo = len; @@ -752,7 +779,7 @@ void LibRaw::parse_makernote(int base, int uptag) { order = 0x4949; fseek(ifp, 140, SEEK_CUR); - FORC3 cam_mul[c] = get4(); + FORC3 cam_mul[c] = float(get4()); } if (tag == 0xb001 && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT)) // Sony ModelID @@ -777,8 +804,8 @@ void LibRaw::parse_makernote(int base, int uptag) { get2_256: order = 0x4d4d; - cam_mul[0] = get2() / 256.0; - cam_mul[2] = get2() / 256.0; + cam_mul[0] = float(get2()) / 256.0f; + cam_mul[2] = float(get2()) / 256.0f; } next: diff --git a/rtengine/libraw/src/metadata/mediumformat.cpp b/rtengine/libraw/src/metadata/mediumformat.cpp index c3d3dbeca..b4089bd4e 100644 --- a/rtengine/libraw/src/metadata/mediumformat.cpp +++ b/rtengine/libraw/src/metadata/mediumformat.cpp @@ -18,7 +18,7 @@ #include "../../internal/dcraw_defs.h" -void LibRaw::parse_phase_one(int base) +void LibRaw::parse_phase_one(INT64 base) { unsigned entries, tag, type, len, data, i, c; INT64 save; @@ -135,13 +135,13 @@ void LibRaw::parse_phase_one(int base) ph1.split_col = data; break; case 0x0223: - ph1.black_col = data + base; + ph1.black_col = int(data + base); break; case 0x0224: ph1.split_row = data; break; case 0x0225: - ph1.black_row = data + base; + ph1.black_row = int(data + base); break; case 0x0226: for (i = 0; i < 9; i++) @@ -193,7 +193,7 @@ void LibRaw::parse_phase_one(int base) if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) ilm.CurAp = libraw_powf64l(2.0f, (int_to_float(data) / 2.0f)); else - ilm.CurAp = libraw_powf64l(2.0f, float(getreal(type) / 2.0f)); + ilm.CurAp = libraw_powf64l(2.0f, getrealf(type) / 2.0f); break; case 0x0403: if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) @@ -218,7 +218,7 @@ void LibRaw::parse_phase_one(int base) } else { - ilm.MaxAp4CurFocal = libraw_powf64l(2.0f, float(getreal(type) / 2.0f)); + ilm.MaxAp4CurFocal = libraw_powf64l(2.0f, getrealf(type) / 2.0f); } break; case 0x0415: @@ -228,7 +228,7 @@ void LibRaw::parse_phase_one(int base) } else { - ilm.MinAp4CurFocal = libraw_powf64l(2.0f, float(getreal(type) / 2.0f)); + ilm.MinAp4CurFocal = libraw_powf64l(2.0f, getrealf(type) / 2.0f); } break; case 0x0416: diff --git a/rtengine/libraw/src/metadata/minolta.cpp b/rtengine/libraw/src/metadata/minolta.cpp index aa40a9b03..1e655c4fd 100644 --- a/rtengine/libraw/src/metadata/minolta.cpp +++ b/rtengine/libraw/src/metadata/minolta.cpp @@ -18,11 +18,11 @@ #include "../../internal/dcraw_defs.h" -void LibRaw::parse_minolta(int base) +void LibRaw::parse_minolta(INT64 base) { - int tag, len, offset, high = 0, wide = 0, i, c; + int tag, len, high = 0, wide = 0, i, c; short sorder = order; - INT64 save; + INT64 save,offset; fseek(ifp, base, SEEK_SET); if (fgetc(ifp) || fgetc(ifp) - 'M' || fgetc(ifp) - 'R') @@ -30,8 +30,8 @@ void LibRaw::parse_minolta(int base) order = fgetc(ifp) * 0x101; offset = base + get4() + 8; INT64 fsize = ifp->size(); - if (offset > fsize - 8) // At least 8 bytes for tag/len - offset = fsize - 8; + if (offset > fsize - 8LL) // At least 8 bytes for tag/len + offset = fsize - 8LL; while ((save = ftell(ifp)) < offset) { diff --git a/rtengine/libraw/src/metadata/misc_parsers.cpp b/rtengine/libraw/src/metadata/misc_parsers.cpp index 1aea57e6f..f29274452 100644 --- a/rtengine/libraw/src/metadata/misc_parsers.cpp +++ b/rtengine/libraw/src/metadata/misc_parsers.cpp @@ -148,12 +148,12 @@ void LibRaw::parse_cine() case 0: flip = 2; } - cam_mul[0] = getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); - cam_mul[2] = getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + cam_mul[0] = getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); + cam_mul[2] = getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); temp = get4(); maximum = ~((~0u) << LIM(temp, 1, 31)); fseek(ifp, 668, SEEK_CUR); - shutter = get4() / 1000000000.0; + shutter = float(get4()) / 1000000000.f; fseek(ifp, off_image, SEEK_SET); if (shot_select < is_raw) fseek(ifp, shot_select * 8, SEEK_CUR); @@ -161,9 +161,10 @@ void LibRaw::parse_cine() data_offset += (INT64)get4() << 32; } -void LibRaw::parse_qt(int end) +void LibRaw::parse_qt(INT64 end) { - unsigned save, size; + unsigned size; + INT64 save; char tag[4]; order = 0x4d4d; @@ -182,20 +183,20 @@ void LibRaw::parse_qt(int end) parse_qt(save + size); if (!memcmp(tag, "CNDA", 4)) parse_jpeg(ftell(ifp)); - fseek(ifp, save + size, SEEK_SET); + fseek(ifp, save + INT64(size), SEEK_SET); } } -void LibRaw::parse_smal(int offset, int fsize) +void LibRaw::parse_smal(INT64 offset, INT64 fsize) { int ver; - fseek(ifp, offset + 2, SEEK_SET); + fseek(ifp, offset + 2LL, SEEK_SET); order = 0x4949; ver = fgetc(ifp); if (ver == 6) fseek(ifp, 5, SEEK_CUR); - if (get4() != (unsigned)fsize) + if (INT64(get4()) != fsize) return; if (ver > 6) data_offset = get4(); @@ -211,7 +212,8 @@ void LibRaw::parse_smal(int offset, int fsize) void LibRaw::parse_riff(int maxdepth) { - unsigned i, size, end; + unsigned i, size; + INT64 end; char tag[4], date[64], month[64]; static const char mon[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -297,11 +299,11 @@ void LibRaw::parse_rollei() if (!strcmp(line, "TY ")) thumb_height = atoi(val); if (!strcmp(line, "APT")) - aperture = atof(val); + aperture = float(atof(val)); if (!strcmp(line, "SPE")) - shutter = atof(val); + shutter = float(atof(val)); if (!strcmp(line, "FOCLEN")) - focal_len = atof(val); + focal_len = float(atof(val)); if (!strcmp(line, "BLKOFS")) black = atoi(val) +1; if (!strcmp(line, "ORI")) @@ -389,11 +391,11 @@ void LibRaw::parse_kyocera() if ((c > 6) && (c < 20)) iso_speed = table[c - 7]; shutter = libraw_powf64l(2.0f, (((float)get4()) / 8.0f)) / 16000.0f; - FORC4 cam_mul[RGGB_2_RGBG(c)] = get4(); + FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4()); fseek(ifp, 88, SEEK_SET); aperture = libraw_powf64l(2.0f, ((float)get4()) / 16.0f); fseek(ifp, 112, SEEK_SET); - focal_len = get4(); + focal_len = float(get4()); fseek(ifp, 104, SEEK_SET); ilm.MaxAp4CurFocal = libraw_powf64l(2.0f, ((float)get4()) / 16.0f); @@ -408,9 +410,11 @@ void LibRaw::parse_kyocera() } } -int LibRaw::parse_jpeg(int offset) +int LibRaw::parse_jpeg(INT64 offset) { - int len, save, hlen, mark; + int len, hlen, mark; + INT64 save; + fseek(ifp, offset, SEEK_SET); if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; @@ -428,21 +432,22 @@ int LibRaw::parse_jpeg(int offset) } order = get2(); hlen = get4(); - if (get4() == 0x48454150 && (save + hlen) >= 0 && - (save + hlen) <= ifp->size()) /* "HEAP" */ + if (get4() == 0x48454150 && (save + INT64(hlen)) >= 0 && + (save + INT64(hlen)) <= ifp->size()) /* "HEAP" */ { parse_ciff(save + hlen, len - hlen, 0); } if (parse_tiff(save + 6)) apply_tiff(); - fseek(ifp, save + len, SEEK_SET); + fseek(ifp, save + INT64(len), SEEK_SET); } return 1; } -void LibRaw::parse_thumb_note(int base, unsigned toff, unsigned tlen) +void LibRaw::parse_thumb_note(INT64 base, unsigned toff, unsigned tlen) { - unsigned entries, tag, type, len, save; + unsigned entries, tag, type, len; + INT64 save; entries = get2(); while (entries--) @@ -572,7 +577,7 @@ void LibRaw::parse_raspberrypi() if (ftell(ifp) > 22LL) // 22 bytes is minimum jpeg size { - thumb_length = ftell(ifp); + thumb_length = unsigned(ftell(ifp)); thumb_offset = 0; thumb_width = thumb_height = 0; load_flags |= 0x4000; // flag: we have JPEG from beginning to meta_offset diff --git a/rtengine/libraw/src/metadata/nikon.cpp b/rtengine/libraw/src/metadata/nikon.cpp index f0fb655d9..0bd6ac191 100644 --- a/rtengine/libraw/src/metadata/nikon.cpp +++ b/rtengine/libraw/src/metadata/nikon.cpp @@ -146,6 +146,7 @@ void LibRaw::processNikonLensData(uchar *LensData, unsigned len) || (ilm.LensID == 26) || (ilm.LensID == 41) || (ilm.LensID == 43) + || (ilm.LensID == 0xd003) ) ilm.LensFormat = LIBRAW_FORMAT_APSC; else ilm.LensFormat = LIBRAW_FORMAT_FF; if (ilm.MaxAp4CurFocal < 0.7f) @@ -237,10 +238,11 @@ void LibRaw::Nikon_NRW_WBtag(int wb, int skip) return; } -void LibRaw::parseNikonMakernote(int base, int uptag, unsigned /*dng_writer */) +void LibRaw::parseNikonMakernote(INT64 base, int uptag, unsigned /*dng_writer */) { - unsigned offset = 0, entries, tag, type, len, save; + unsigned offset = 0, entries, tag, type, len; + INT64 save; unsigned c, i; unsigned LensData_len = 0; @@ -300,6 +302,13 @@ uchar *cj_block, *ck_block; if (len > 100 * 1024 * 1024) goto next; // 100Mb tag? No! + if (callbacks.makernotes_cb) + { + INT64 _savepos = ifp->tell(); + callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } + if (tag == 0x0002) { if (!iso_speed) @@ -312,10 +321,10 @@ uchar *cj_block, *ck_block; } else if ((tag == 0x000c) && (len == 4) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_RATIONAL)) { - cam_mul[0] = getreal(type); - cam_mul[2] = getreal(type); - cam_mul[1] = getreal(type); - cam_mul[3] = getreal(type); + cam_mul[0] = getrealf(type); + cam_mul[2] = getrealf(type); + cam_mul[1] = getrealf(type); + cam_mul[3] = getrealf(type); } else if (tag == 0x0011) { @@ -341,8 +350,8 @@ uchar *cj_block, *ck_block; { // E5400, E8400, E8700, E8800 fseek(ifp, 0x4e0L, SEEK_CUR); order = 0x4d4d; - cam_mul[0] = get2() / 256.0; - cam_mul[2] = get2() / 256.0; + cam_mul[0] = float(get2()) / 256.f; + cam_mul[2] = float(get2()) / 256.f; cam_mul[1] = cam_mul[3] = 1.0; icWBC[LIBRAW_WBI_Auto][0] = get2(); icWBC[LIBRAW_WBI_Auto][2] = get2(); @@ -393,10 +402,10 @@ uchar *cj_block, *ck_block; if (!strcmp(buf + 4, "0100")) { // P6000 fseek(ifp, 0x13deL, SEEK_CUR); - cam_mul[0] = get4() << 1; - cam_mul[1] = get4(); - cam_mul[3] = get4(); - cam_mul[2] = get4() << 1; + cam_mul[0] = float(get4() << 1); + cam_mul[1] = float(get4()); + cam_mul[3] = float(get4()); + cam_mul[2] = float(get4() << 1); Nikon_NRW_WBtag(LIBRAW_WBI_Daylight, 0); Nikon_NRW_WBtag(LIBRAW_WBI_Cloudy, 0); fseek(ifp, 0x10L, SEEK_CUR); @@ -414,10 +423,10 @@ uchar *cj_block, *ck_block; if (cam_mul[0] < 0.1f) { fseek(ifp, 0x16L, SEEK_CUR); - cam_mul[0] = get4() << 1; - cam_mul[1] = get4(); - cam_mul[3] = get4(); - cam_mul[2] = get4() << 1; + cam_mul[0] = float(get4() << 1); + cam_mul[1] = float(get4()); + cam_mul[3] = float(get4()); + cam_mul[2] = float(get4() << 1); } else { @@ -530,7 +539,7 @@ uchar *cj_block, *ck_block; } } else if (tag == 0x0025) { - imCommon.real_ISO = int(100.0 * libraw_powf64l(2.0, double((uchar)fgetc(ifp)) / 12.0 - 5.0)); + imCommon.real_ISO = float(100.f * float(libraw_powf64l(2.f, float((uchar)fgetc(ifp)) / 12.f - 5.f))); if (!iso_speed || (iso_speed == 65535)) { iso_speed = imCommon.real_ISO; @@ -583,6 +592,57 @@ uchar *cj_block, *ck_block; fseek(ifp, 10LL, SEEK_CUR); imNikon.NEFCompression = get2(); } + +// BurstTable_0x0056 +/* +photo shooting menu -> [Pixel shift shooting] : + [Pixel shift shooting mode] : On(series) | On(single photo) | Off (default is Off) + [Number of shots] : 4 | 8 | 16 | 32 (default is 16) + [Delay] : (default is 2 s) + [Interval until next shot] : (default is 0) +*/ + else if ((tag == 0x0056) && !strncmp(model+6, "Z ", 2)) + { + imNikon.BurstTable_0x0056_len = len; + if (imNikon.BurstTable_0x0056_len == 16) { + imNikon.BurstTable_0x0056 = (uchar *)malloc(imNikon.BurstTable_0x0056_len); + fread(imNikon.BurstTable_0x0056, imNikon.BurstTable_0x0056_len, 1, ifp); + FORC4 imNikon.BurstTable_0x0056_ver = imNikon.BurstTable_0x0056_ver * 10 + (imNikon.BurstTable_0x0056[c] - '0'); + imNikon.BurstTable_0x0056_gid = (imNikon.BurstTable_0x0056[5]<<8) | imNikon.BurstTable_0x0056[4]; + imNikon.BurstTable_0x0056_fnum = imNikon.BurstTable_0x0056[8]; +/* + printf (">> camera: %s; BurstTable_0x0056: len %d, ver %d, gid 0x%04x, fnum %d\n", + model, imNikon.BurstTable_0x0056_len, imNikon.BurstTable_0x0056_ver, imNikon.BurstTable_0x0056_gid, imNikon.BurstTable_0x0056_fnum); + printf (" 0x6: 0x%02x 0x7: 0x%02x\n 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + imNikon.BurstTable_0x0056[0x6], imNikon.BurstTable_0x0056[0x7], + imNikon.BurstTable_0x0056[0x9], imNikon.BurstTable_0x0056[0xa], + imNikon.BurstTable_0x0056[0xb], imNikon.BurstTable_0x0056[0xc], + imNikon.BurstTable_0x0056[0xd], imNikon.BurstTable_0x0056[0xe], + imNikon.BurstTable_0x0056[0xf]); + + printf ("BurstTable_0x0056[5 .. 4]: "); + for (c = 1 << 7; c > 0; c = c / 2) + (imNikon.BurstTable_0x0056[5] & c) ? printf("1") : printf("0"); + printf (" "); + for (c = 1 << 7; c > 0; c = c / 2) + (imNikon.BurstTable_0x0056[4] & c) ? printf("1") : printf("0"); + printf ("\n"); + printf ("BurstTable_0x0056[7 .. 6]: "); + for (c = 1 << 7; c > 0; c = c / 2) + (imNikon.BurstTable_0x0056[7] & c) ? printf("1") : printf("0"); + printf (" "); + for (c = 1 << 7; c > 0; c = c / 2) + (imNikon.BurstTable_0x0056[6] & c) ? printf("1") : printf("0"); + printf ("\n"); +*/ + } +/* + else { + printf (">> camera: =%s=; table 0x0056 len!=16, len %d\n", model, len); + } +*/ + } + else if (tag == 0x0082) { // lens attachment stmread(ilm.Attachment, len, ifp); @@ -593,10 +653,10 @@ uchar *cj_block, *ck_block; } else if (tag == 0x0084) { // lens - ilm.MinFocal = getreal(type); - ilm.MaxFocal = getreal(type); - ilm.MaxAp4MinFocal = getreal(type); - ilm.MaxAp4MaxFocal = getreal(type); + ilm.MinFocal = getrealf(type); + ilm.MaxFocal = getrealf(type); + ilm.MaxAp4MinFocal = getrealf(type); + ilm.MaxAp4MaxFocal = getrealf(type); } else if (tag == 0x0088) // AFInfo { @@ -605,7 +665,7 @@ uchar *cj_block, *ck_block; imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); imCommon.afcount = 1; } @@ -628,7 +688,7 @@ uchar *cj_block, *ck_block; else if ((tag == 0x0091) && (len > 4)) { ShotInfo_len = len; - ShotInfo_buf = (uchar *)malloc(ShotInfo_len); + ShotInfo_buf = (uchar *)calloc(ShotInfo_len,1); /* for dump: cj_block = (uchar *)malloc(ShotInfo_len); @@ -761,7 +821,7 @@ ck_block = (uchar *)malloc(ShotInfo_len); } if (LensData_len) { - LensData_buf = (uchar *)malloc(LensData_len); + LensData_buf = (uchar *)calloc(LensData_len,1); fread(LensData_buf, LensData_len, 1, ifp); } } @@ -881,8 +941,24 @@ free(ck_block); case 805: // "Z 9", ShotInfoZ9, Roll/Pitch/Yaw OrientationOffset = sget4_order(morder, ShotInfo_buf+0x84); break; + case 806: // "Z 8" + if (ShotInfo_len >= 12) { + memcpy (imNikon.ShotInfoFirmware, ShotInfo_buf+4, 8*sizeof(char)); + imNikon.ShotInfoFirmware[8] = '\0'; + // printf (">> camera: =%s= exifSW: =%s= ShotInfo: Version %d, Firmware =%s=\n", + // model, software, imNikon.ShotInfoVersion, imNikon.ShotInfoFirmware); + } + break; case 807: // "Z 30" break; + case 808: // "Z f" + if (ShotInfo_len >= 12) { + memcpy (imNikon.ShotInfoFirmware, ShotInfo_buf+4, 8*sizeof(char)); + imNikon.ShotInfoFirmware[8] = '\0'; + // printf (">> camera: =%s= exifSW: =%s= ShotInfo: Version %d, Firmware =%s=\n", + // model, software, imNikon.ShotInfoVersion, imNikon.ShotInfoFirmware); + } + break; } if (OrientationOffset && ((OrientationOffset+12) -273.15f) && ((OlyID == OlyID_TG_5) || - (OlyID == OlyID_TG_6)) + (OlyID == OlyID_TG_6) || + (OlyID == OlyID_TG_7)) ) imCommon.CameraTemperature += imCommon.exifAmbientTemperature; } @@ -516,11 +594,11 @@ void LibRaw::parseOlympus_RawInfo(unsigned tag, unsigned /*type */, unsigned len { if (!imOly.ColorSpace) { - FORC3 cmatrix[i][c] = ((short)get2()) / 256.0; + FORC3 cmatrix[i][c] = float((short)get2()) / 256.f; } else { - FORC3 imgdata.color.ccm[i][c] = ((short)get2()) / 256.0; + FORC3 imgdata.color.ccm[i][c] = float((short)get2()) / 256.f; } } } @@ -548,7 +626,7 @@ void LibRaw::parseOlympus_RawInfo(unsigned tag, unsigned /*type */, unsigned len } -void LibRaw::parseOlympusMakernotes (int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer) { +void LibRaw::parseOlympusMakernotes (INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer) { int c; unsigned a; @@ -578,7 +656,7 @@ void LibRaw::parseOlympusMakernotes (int base, unsigned tag, unsigned type, unsi stmread(imgdata.shootinginfo.BodySerial, len, ifp); break; case 0x1002: - ilm.CurAp = libraw_powf64l(2.0f, getreal(type) / 2); + ilm.CurAp = float(libraw_powf64l(2.0f, getrealf(type) / 2.f)); break; case 0x1007: imCommon.SensorTemperature = (float)get2(); @@ -603,9 +681,9 @@ void LibRaw::parseOlympusMakernotes (int base, unsigned tag, unsigned type, unsi if (strcmp(software, "v757-71") && (dng_writer == nonDNG)) { for (int i = 0; i < 3; i++) { if (!imOly.ColorSpace) { - FORC3 cmatrix[i][c] = ((short)get2()) / 256.0; + FORC3 cmatrix[i][c] = float((short)get2()) / 256.f; } else { - FORC3 imgdata.color.ccm[i][c] = ((short)get2()) / 256.0; + FORC3 imgdata.color.ccm[i][c] = float((short)get2()) / 256.f; } } } @@ -616,11 +694,11 @@ void LibRaw::parseOlympusMakernotes (int base, unsigned tag, unsigned type, unsi break; case 0x1017: if (dng_writer == nonDNG) - cam_mul[0] = get2() / 256.0; + cam_mul[0] = float(get2()) / 256.f; break; case 0x1018: if (dng_writer == nonDNG) - cam_mul[2] = get2() / 256.0; + cam_mul[2] = float(get2()) / 256.f; break; case 0x102c: if (dng_writer == nonDNG) diff --git a/rtengine/libraw/src/metadata/pentax.cpp b/rtengine/libraw/src/metadata/pentax.cpp index ae238d0aa..4e339e6fb 100644 --- a/rtengine/libraw/src/metadata/pentax.cpp +++ b/rtengine/libraw/src/metadata/pentax.cpp @@ -39,22 +39,24 @@ void LibRaw::setPentaxBodyFeatures(unsigned long long id) case PentaxID_K200D: case PentaxID_K2000: case PentaxID_K_m: - case PentaxID_K_7: case PentaxID_K_x: case PentaxID_K_r: - case PentaxID_K_5: case PentaxID_K_01: - case PentaxID_K_30: + case PentaxID_K_3: + case PentaxID_K_3_II: + case PentaxID_K_3_III: + case PentaxID_K_3_III_Mono: + case PentaxID_K_5: case PentaxID_K_5_II: case PentaxID_K_5_II_s: + case PentaxID_K_7: + case PentaxID_K_30: case PentaxID_K_50: - case PentaxID_K_3: + case PentaxID_K_70: case PentaxID_K_500: case PentaxID_K_S1: case PentaxID_K_S2: - case PentaxID_K_3_II: - case PentaxID_K_3_III: - case PentaxID_K_70: + case PentaxID_KF: case PentaxID_KP: ilm.CameraMount = LIBRAW_MOUNT_Pentax_K; ilm.CameraFormat = LIBRAW_FORMAT_APSC; @@ -123,7 +125,7 @@ void LibRaw::PentaxISO(ushort c) { if (code[i] == c) { - iso_speed = value[i]; + iso_speed = float(value[i]); return; } } @@ -136,7 +138,7 @@ void LibRaw::PentaxLensInfo(unsigned long long id, unsigned len) // tag 0x0207 { ushort iLensData = 0; uchar *table_buf; - table_buf = (uchar *)malloc(MAX(len, 128)); + table_buf = (uchar *)calloc(MAX(len, 128),1); fread(table_buf, len, 1, ifp); if ((id < PentaxID_K100D) || (((id == PentaxID_K100D) || @@ -185,8 +187,8 @@ void LibRaw::PentaxLensInfo(unsigned long long id, unsigned len) // tag 0x0207 if (iLensData) { if (table_buf[iLensData + 9] && (fabs(ilm.CurFocal) < 0.1f)) - ilm.CurFocal = 10 * (table_buf[iLensData + 9] >> 2) * - libraw_powf64l(4, (table_buf[iLensData + 9] & 0x03) - 2); + ilm.CurFocal = 10.f * (table_buf[iLensData + 9] >> 2) * + libraw_powf64l(4.f, float((table_buf[iLensData + 9] & 0x03) - 2.f)); if (table_buf[iLensData + 10] & 0xf0) ilm.MaxAp4CurFocal = libraw_powf64l( 2.0f, (float)((table_buf[iLensData + 10] & 0xf0) >> 4) / 4.0f); @@ -235,7 +237,7 @@ void LibRaw::PentaxLensInfo(unsigned long long id, unsigned len) // tag 0x0207 return; } -void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, +void LibRaw::parsePentaxMakernotes(INT64 /*base*/, unsigned tag, unsigned type, unsigned len, unsigned dng_writer) { @@ -294,10 +296,10 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, imgdata.shootinginfo.MeteringMode = get2(); } else if (tag == 0x001b) { - cam_mul[2] = get2() / 256.0; + cam_mul[2] = float(get2()) / 256.f; } else if (tag == 0x001c) { - cam_mul[0] = get2() / 256.0; + cam_mul[0] = float(get2()) / 256.f; } else if (tag == 0x001d) { @@ -360,7 +362,7 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, else if (tag == 0x004d) { if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_SLONG)) - imCommon.FlashEC = getreal(type) / 256.0f; + imCommon.FlashEC = getrealf(type) / 256.0f; else imCommon.FlashEC = (float)((signed short)fgetc(ifp)) / 6.0f; } @@ -369,6 +371,15 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, fgetc(ifp); imgdata.shootinginfo.ImageStabilization = (short)fgetc(ifp); } + else if (tag == 0x0069) + { + uchar uc; + FORC4 + { + fread(&uc, 1, 1, ifp); + imPentax.DynamicRangeExpansion[c] = uc; + } + } else if (tag == 0x0072) { imPentax.AFAdjustment = get2(); @@ -410,7 +421,7 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, else if ((tag == 0x0203) && (dng_writer == nonDNG)) { for (int i = 0; i < 3; i++) - FORC3 cmatrix[i][c] = ((short)get2()) / 8192.0; + FORC3 cmatrix[i][c] = float((short)get2()) / 8192.f; } else if (tag == 0x0205) { @@ -419,7 +430,7 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); if ((len < 25) && (len >= 11)) { @@ -445,7 +456,7 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, tagtypeIs(LIBRAW_EXIFTAG_TYPE_UNDEFINED) && (dng_writer == nonDNG)) { for (int i = 0; i < 3; i++) - FORC3 cmatrix[i][c] = ((short)get2()) / 8192.0; + FORC3 cmatrix[i][c] = float((short)get2()) / 8192.f; } else if (tag == 0x021f) { @@ -466,10 +477,10 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, else if (tag == 0x0221) { int nWB = get2(); - if (nWB <= int(sizeof(icWBCCTC) / sizeof(icWBCCTC[0]))) + if (nWB > 0 && nWB <= int(sizeof(icWBCCTC) / sizeof(icWBCCTC[0]))) FORC(nWB) { - icWBCCTC[c][0] = (unsigned)0xcfc6 - get2(); + icWBCCTC[c][0] = float((unsigned)0xcfc6 - get2()); fseek(ifp, 2, SEEK_CUR); icWBCCTC[c][1] = get2(); icWBCCTC[c][2] = icWBCCTC[c][4] = 0x2000; @@ -511,14 +522,14 @@ void LibRaw::parsePentaxMakernotes(int /*base*/, unsigned tag, unsigned type, imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); imCommon.afcount++; } } } -void LibRaw::parseRicohMakernotes(int /*base*/, unsigned tag, unsigned type, +void LibRaw::parseRicohMakernotes(INT64 /*base*/, unsigned tag, unsigned type, unsigned /*len*/, unsigned /*dng_writer */) { char buffer[17]; @@ -591,7 +602,7 @@ void LibRaw::parseRicohMakernotes(int /*base*/, unsigned tag, unsigned type, } else if ((tag == 0x100b) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SRATIONAL)) { - imCommon.FlashEC = getreal(type); + imCommon.FlashEC = getrealf(type); } else if ((tag == 0x1017) && ((imRicoh.WideAdapter = get2()) == 2)) { @@ -631,7 +642,7 @@ void LibRaw::parseRicohMakernotes(int /*base*/, unsigned tag, unsigned type, } else if (tag == 0x1500) { - ilm.CurFocal = getreal(type); + ilm.CurFocal = getrealf(type); } else if (tag == 0x1601) { diff --git a/rtengine/libraw/src/metadata/samsung.cpp b/rtengine/libraw/src/metadata/samsung.cpp index 26fd58f4d..24a967650 100644 --- a/rtengine/libraw/src/metadata/samsung.cpp +++ b/rtengine/libraw/src/metadata/samsung.cpp @@ -15,7 +15,7 @@ #include "../../internal/dcraw_defs.h" -void LibRaw::parseSamsungMakernotes(int /*base*/, unsigned tag, unsigned type, +void LibRaw::parseSamsungMakernotes(INT64 /*base*/, unsigned tag, unsigned type, unsigned len, unsigned dng_writer) { int i, c; @@ -93,12 +93,12 @@ void LibRaw::parseSamsungMakernotes(int /*base*/, unsigned tag, unsigned type, } else if (tag == 0xa019) { - ilm.CurAp = getreal(type); + ilm.CurAp = getrealf(type); } else if ((tag == 0xa01a) && (unique_id != 0x5000000) && (!imgdata.lens.FocalLengthIn35mmFormat)) { - ilm.FocalLengthIn35mmFormat = get4(); + ilm.FocalLengthIn35mmFormat = float(get4()); if (ilm.FocalLengthIn35mmFormat >= 160) ilm.FocalLengthIn35mmFormat /= 10.0f; if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) && @@ -111,7 +111,7 @@ void LibRaw::parseSamsungMakernotes(int /*base*/, unsigned tag, unsigned type, } else if ((tag == 0xa021) && (dng_writer == nonDNG)) { - FORC4 cam_mul[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c]; + FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]); } else if (tag == 0xa022) { @@ -169,7 +169,7 @@ void LibRaw::parseSamsungMakernotes(int /*base*/, unsigned tag, unsigned type, { for (i = 0; i < 3; i++) FORC3 imgdata.color.ccm[i][c] = - (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.0; + (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.f; } else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG)) { diff --git a/rtengine/libraw/src/metadata/sony.cpp b/rtengine/libraw/src/metadata/sony.cpp index b63d0495d..bfc3a0cb5 100644 --- a/rtengine/libraw/src/metadata/sony.cpp +++ b/rtengine/libraw/src/metadata/sony.cpp @@ -123,8 +123,22 @@ void LibRaw::sony_decrypt(unsigned *data, int len, int start, int key) #undef p #endif } -void LibRaw::setSonyBodyFeatures(unsigned long long id) -{ +void LibRaw::setSonyBodyFeatures(unsigned long long id) { + +#define sbfDSLR_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_DSLR,LIBRAW_MOUNT_Unknown +#define sbfDSLR_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_DSLR,LIBRAW_MOUNT_Unknown +#define sbfNEX_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_NEX,LIBRAW_MOUNT_Unknown +#define sbfNEX_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_NEX,LIBRAW_MOUNT_Unknown +#define sbfSLT_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_SLT,LIBRAW_MOUNT_Unknown +#define sbfSLT_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_SLT,LIBRAW_MOUNT_Unknown +#define sbfDSC_1div2p3in LIBRAW_FORMAT_1div2p3INCH,LIBRAW_MOUNT_FixedLens,LIBRAW_SONY_DSC,LIBRAW_MOUNT_FixedLens +#define sbfDSC_1in LIBRAW_FORMAT_1INCH,LIBRAW_MOUNT_FixedLens,LIBRAW_SONY_DSC,LIBRAW_MOUNT_FixedLens +#define sbfDSC_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_FixedLens,LIBRAW_SONY_DSC,LIBRAW_MOUNT_FixedLens +#define sbfILCE_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_ILCE,LIBRAW_MOUNT_Unknown +#define sbfILCE_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_ILCE,LIBRAW_MOUNT_Unknown +#define sbfILCA_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_ILCA,LIBRAW_MOUNT_Unknown +#define sbfILCA_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_ILCA,LIBRAW_MOUNT_Unknown + static const struct { ushort scf[11]; @@ -142,215 +156,223 @@ void LibRaw::setSonyBodyFeatures(unsigned long long id) scf[10] offset of ReleaseMode2 in 0x2010 table, 0xffff if not valid */ } SonyCamFeatures[] = { - {SonyID_DSLR_A100, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A100, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A900, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A900, sbfDSLR_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A700, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A700, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A200, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A200, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A350, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A350, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A300, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A300, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A900, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A900_APSC, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A380, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A380, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A330, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A330, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A230, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A230, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A290, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A290, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A850, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A850, sbfDSLR_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A850, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A850_APSC, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A550, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A550, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A500, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A500, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A450, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A450, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_NEX_5, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_5, sbfNEX_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_NEX_3, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_3, sbfNEX_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_SLT_A33, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A33, sbfSLT_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_SLT_A55, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A55, sbfSLT_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A560, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A560, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_DSLR_A580, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_DSLR, LIBRAW_MOUNT_Unknown, + {SonyID_DSLR_A580, sbfDSLR_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_NEX_C3, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_C3, sbfNEX_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_SLT_A35, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A35, sbfSLT_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_SLT_A65, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A65, sbfSLT_DX, LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c}, - {SonyID_SLT_A77, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A77, sbfSLT_DX, LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c}, - {SonyID_NEX_5N, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_5N, sbfNEX_DX, LIBRAW_SONY_Tag2010a, 0x113e, 0x01bd, 0x1174, 0x1175, 0x112c}, - {SonyID_NEX_7, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_7, sbfNEX_DX, LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c}, - {SonyID_NEX_VG20, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_VG20, sbfNEX_DX, LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c}, - {SonyID_SLT_A37, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A37, sbfSLT_DX, LIBRAW_SONY_Tag2010c, 0x11f4, 0x01bd, 0x1154, 0x1155, 0x1108}, - {SonyID_SLT_A57, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A57, sbfSLT_DX, LIBRAW_SONY_Tag2010c, 0x11f4, 0x01bd, 0x1154, 0x1155, 0x1108}, - {SonyID_NEX_F3, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_F3, sbfNEX_DX, LIBRAW_SONY_Tag2010c, 0x11f4, 0x01bd, 0x1154, 0x1155, 0x1108}, - {SonyID_SLT_A99, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A99, sbfSLT_FF, LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_NEX_6, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_6, sbfNEX_DX, LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_NEX_5R, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_5R, sbfNEX_DX, LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_DSC_RX100, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100, sbfDSC_1in, LIBRAW_SONY_Tag2010e, 0x1254, 0xffff, 0x11ac, 0x11ad, 0x1160}, - {SonyID_DSC_RX1, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX1, sbfDSC_FF, LIBRAW_SONY_Tag2010e, 0x1258, 0xffff, 0x11ac, 0x11ad, 0x1160}, - {SonyID_NEX_VG900, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_VG900, sbfNEX_FF, LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_NEX_VG30, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_VG30, sbfNEX_DX, LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_ILCE_3000, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_3000, sbfILCE_DX, LIBRAW_SONY_Tag2010e, 0x1280, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_SLT_A58, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_SLT, LIBRAW_MOUNT_Unknown, + {SonyID_SLT_A58, sbfSLT_DX, LIBRAW_SONY_Tag2010e, 0x1280, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_NEX_3N, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_3N, sbfNEX_DX, LIBRAW_SONY_Tag2010e, 0x1280, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_ILCE_7, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7, sbfILCE_FF, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_NEX_5T, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_NEX, LIBRAW_MOUNT_Unknown, + {SonyID_NEX_5T, sbfNEX_DX, LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160}, - {SonyID_DSC_RX100M2, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M2, sbfDSC_1in, LIBRAW_SONY_Tag2010f, 0x113c, 0xffff, 0x1064, 0x1065, 0x1018}, - {SonyID_DSC_RX10, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX10, sbfDSC_1in, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX1R, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX1R, sbfDSC_FF, LIBRAW_SONY_Tag2010e, 0x1258, 0xffff, 0x11ac, 0x11ad, 0x1160}, - {SonyID_ILCE_7R, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7R, sbfILCE_FF, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_6000, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6000, sbfILCE_DX, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_5000, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_5000, sbfILCE_DX, LIBRAW_SONY_Tag2010g, 0x0344, 0x01aa, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX100M3, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M3, sbfDSC_1in, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_7S, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7S, sbfILCE_FF, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCA_77M2, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_ILCA, LIBRAW_MOUNT_Unknown, + {SonyID_ILCA_77M2, sbfILCA_DX, LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_5100, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_5100, sbfILCE_DX, LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_7M2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7M2, sbfILCE_FF, LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX100M4, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M4, sbfDSC_1in, LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX10M2, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX10M2, sbfDSC_1in, LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX1RM2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX1RM2, sbfDSC_FF, LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_QX1, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_QX1, sbfILCE_DX, LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_7RM2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7RM2, sbfILCE_FF, LIBRAW_SONY_Tag2010h, 0x0346, 0x01cb, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_7SM2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7SM2, sbfILCE_FF, LIBRAW_SONY_Tag2010h, 0x0346, 0x01cb, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCA_68, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_ILCA, LIBRAW_MOUNT_Unknown, + {SonyID_ILCA_68, sbfILCA_DX, LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCA_99M2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Minolta_A, LIBRAW_SONY_ILCA, LIBRAW_MOUNT_Unknown, + {SonyID_ILCA_99M2, sbfILCA_FF, LIBRAW_SONY_Tag2010h, 0x0346, 0x01cd, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX10M3, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX10M3, sbfDSC_1in, LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX100M5, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M5, sbfDSC_1in, LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_6300, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6300, sbfILCE_DX, LIBRAW_SONY_Tag2010h, 0x0346, 0x01cd, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_9, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_9, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_6500, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6500, sbfILCE_DX, LIBRAW_SONY_Tag2010h, 0x0346, 0x01cd, 0x025c, 0x025d, 0x0210}, - {SonyID_ILCE_7RM3, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7RM3, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_7M3, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7M3, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_RX0, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX0, sbfDSC_1in, LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210}, - {SonyID_DSC_RX10M4, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX10M4, sbfDSC_1in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_RX100M6, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M6, sbfDSC_1in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_HX99, LIBRAW_FORMAT_1div2p3INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_HX99, sbfDSC_1div2p3in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_RX100M5A, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M5A, sbfDSC_1in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_6400, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6400, sbfILCE_DX, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_RX0M2, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX0M2, sbfDSC_1in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_HX95, LIBRAW_FORMAT_1div2p3INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_HX95, sbfDSC_1div2p3in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_DSC_RX100M7, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_DSC_RX100M7, sbfDSC_1in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_7RM4, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7RM4, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_9M2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_9M2, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_6600, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6600, sbfILCE_DX, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_6100, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6100, sbfILCE_DX, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ZV_1, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, + {SonyID_ZV_1, sbfDSC_1in, LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_7C, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7C, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - -// a la SonyID_ILCE_6100 - {SonyID_ZV_E10, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ZV_E10, sbfILCE_DX, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - - {SonyID_ILCE_7SM3, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7SM3, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILCE_1, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_1, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILME_FX3, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILME_FX3, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILCE_7RM3A, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7RM3A, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_7RM4A, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7RM4A, sbfILCE_FF, LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208}, - {SonyID_ILCE_7M4, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7M4, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILCE_7RM5, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_7RM5, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILME_FX30, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILME_FX30, sbfILCE_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ZV_E1, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_9M3, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILCE_6700, LIBRAW_FORMAT_APSC, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ZV_E1, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ZV_1M2, LIBRAW_FORMAT_1INCH, LIBRAW_MOUNT_FixedLens, LIBRAW_SONY_DSC, LIBRAW_MOUNT_FixedLens, - LIBRAW_SONY_Tag2010i, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - - {SonyID_ILCE_7CR, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ILCE_6700, sbfILCE_DX, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, - {SonyID_ILCE_7CM2, LIBRAW_FORMAT_FF, LIBRAW_MOUNT_Sony_E, LIBRAW_SONY_ILCE, LIBRAW_MOUNT_Unknown, + {SonyID_ZV_1M2, sbfDSC_1in, + LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208}, + {SonyID_ILCE_7CR, sbfILCE_FF, + LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, + {SonyID_ILCE_7CM2, sbfILCE_FF, + LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, + {SonyID_ILX_LR1, sbfILCE_FF, LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, }; ilm.CamID = id; int isPreProductionFW = 0; - if (!strcmp(model, "MODEL-NAME")) isPreProductionFW = 1; + if ( + (!strncmp(model, "MODEL-NAME", 10)) + || (!strncmp(model, "DSLR-A000", 9)) + || (!strncmp(model, "SLT-A00", 7)) + || (!strncmp(model, "NEX-00", 6)) + ) { + isPreProductionFW = 1; + } if (id == SonyID_DSC_R1) { + ilm.CameraFormat = LIBRAW_FORMAT_APSC; ilm.CameraMount = ilm.LensMount = LIBRAW_MOUNT_FixedLens; imSony.CameraType = LIBRAW_SONY_DSC; imSony.group2010 = LIBRAW_SONY_Tag2010None; @@ -408,6 +430,7 @@ void LibRaw::setSonyBodyFeatures(unsigned long long id) case SonyID_ILCE_7RM5: case SonyID_ILCE_7SM3: case SonyID_ILME_FX3: + case SonyID_ILX_LR1: if (!isPreProductionFW) { imSony.group9050 = LIBRAW_SONY_Tag9050c; // length: 256 bytes @@ -422,6 +445,7 @@ void LibRaw::setSonyBodyFeatures(unsigned long long id) case SonyID_ILCE_6700: case SonyID_ILCE_7CR: case SonyID_ILCE_7CM2: + case SonyID_ILCE_9M3: imSony.group9050 = LIBRAW_SONY_Tag9050d; break; default: // see also process_Sony_0x9050 @@ -442,7 +466,7 @@ void LibRaw::setSonyBodyFeatures(unsigned long long id) { sbstr += 2; strcpy(imCommon.firmware, sbstr); - imSony.firmware = atof(sbstr); + imSony.firmware = float(atof(sbstr)); if ((id == SonyID_ILCE_7) || (id == SonyID_ILCE_7R)) @@ -468,7 +492,21 @@ void LibRaw::setSonyBodyFeatures(unsigned long long id) imSony.ImageCount3_offset = 0x01b6; } } -} + +#undef sbfILCA_FF +#undef sbfILCA_DX +#undef sbfILCE_FF +#undef sbfILCE_DX +#undef sbfDSC_FF +#undef sbfDSC_1in +#undef sbfDSC_1div2p3in +#undef sbfSLT_FF +#undef sbfSLT_DX +#undef sbfNEX_FF +#undef sbfNEX_DX +#undef sbfDSLR_FF +#undef sbfDSLR_DX +} // closing setSonyBodyFeatures() void LibRaw::parseSonyLensType2(uchar a, uchar b) { @@ -634,7 +672,7 @@ void LibRaw::process_Sony_0x2010(uchar *buf, ushort len) } else if (imSony.group2010 == LIBRAW_SONY_Tag2010i) { ar_offset = 0x188c; } - if (ar_offset != 0) { + if (ar_offset != 0 && ar_offset= (imSony.MeteringMode_offset + 2))) + (len > (imSony.MeteringMode_offset)) && + (len > (imSony.ExposureProgram_offset)) + ) { imgdata.shootinginfo.MeteringMode = SonySubstitution[buf[imSony.MeteringMode_offset]]; @@ -670,7 +710,7 @@ void LibRaw::process_Sony_0x2010(uchar *buf, ushort len) } if ((imSony.ReleaseMode2_offset != 0xffff) && - (len >= (imSony.ReleaseMode2_offset + 2))) + (len > (imSony.ReleaseMode2_offset))) { imgdata.shootinginfo.DriveMode = SonySubstitution[buf[imSony.ReleaseMode2_offset]]; @@ -693,12 +733,16 @@ void LibRaw::process_Sony_0x9050(uchar *buf, ushort len, unsigned long long id) } /* -printf ("==>> Tag9050, len: 0x%04x, type: %s\n", len, +printf ("==>> Tag9050, len: 0x%04x, type: %s, model: =%s=, CamID: %llu, ARW version: %d\n", + len, imSony.group9050==LIBRAW_SONY_Tag9050None?"None": imSony.group9050==LIBRAW_SONY_Tag9050a?"9050a": imSony.group9050==LIBRAW_SONY_Tag9050b?"9050b": imSony.group9050==LIBRAW_SONY_Tag9050c?"9050c": - imSony.group9050==LIBRAW_SONY_Tag9050d?"9050d":"---"); + imSony.group9050==LIBRAW_SONY_Tag9050d?"9050d": + "---", + model, id, + imSony.FileFormat); */ if (imSony.group9050 == LIBRAW_SONY_Tag9050None) return; @@ -711,13 +755,13 @@ printf ("==>> Tag9050, len: 0x%04x, type: %s\n", len, if (buf[0]) ilm.MaxAp4CurFocal = my_roundf( - libraw_powf64l(2.0f, ((float)SonySubstitution[buf[0]] / 8.0 - 1.06f) / 2.0f) * + libraw_powf64l(2.0f, ((float)SonySubstitution[buf[0]] / 8.0f - 1.06f) / 2.0f) * 10.0f) / 10.0f; if (buf[1]) ilm.MinAp4CurFocal = my_roundf( - libraw_powf64l(2.0f, ((float)SonySubstitution[buf[1]] / 8.0 - 1.06f) / 2.0f) * + libraw_powf64l(2.0f, ((float)SonySubstitution[buf[1]] / 8.0f - 1.06f) / 2.0f) * 10.0f) / 10.0f; } @@ -1099,7 +1143,7 @@ void LibRaw::process_Sony_0x940e(uchar *buf, ushort len, unsigned long long id) } void LibRaw::parseSonyMakernotes( - int base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer, + INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer, uchar *&table_buf_0x0116, ushort &table_buf_0x0116_len, uchar *&table_buf_0x2010, ushort &table_buf_0x2010_len, uchar *&table_buf_0x9050, ushort &table_buf_0x9050_len, @@ -1121,7 +1165,11 @@ void LibRaw::parseSonyMakernotes( // printf ("==>> tag 0x%x, len %d, type %d, model =%s=, cam.id 0x%llx, cam.type %d, =%s=\n", // tag, len, type, model, ilm.CamID, imSony.CameraType, imSony.MetaVersion); - if (tag == 0xb001) // Sony ModelID + if (tag == 0xb000) + { + FORC4 imSony.FileFormat = imSony.FileFormat * 10 + fgetc(ifp); + } + else if (tag == 0xb001) // Sony ModelID { unique_id = get2(); setSonyBodyFeatures(unique_id); @@ -1190,10 +1238,6 @@ void LibRaw::parseSonyMakernotes( table_buf_0x940e_len = 0; } } - else if (tag == 0xb000) - { - FORC4 imSony.FileFormat = imSony.FileFormat * 10 + fgetc(ifp); - } else if (tag == 0xb026) { uitemp = get4(); @@ -1204,7 +1248,7 @@ void LibRaw::parseSonyMakernotes( (tag == 0x0003)) && (len >= 196)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); lid = 0x01 << 2; @@ -1237,7 +1281,7 @@ void LibRaw::parseSonyMakernotes( else if ((tag == 0x0004) && // Minolta CameraSettings7D, big endian (len >= 227)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); lid = 0x0; @@ -1287,7 +1331,7 @@ void LibRaw::parseSonyMakernotes( ) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); if (imCommon.afcount < LIBRAW_AFDATA_MAXCOUNT) { @@ -1314,9 +1358,9 @@ void LibRaw::parseSonyMakernotes( if (LensDataValid) { if (table_buf[0] | table_buf[3]) - ilm.MinFocal = bcd2dec(table_buf[0]) * 100 + bcd2dec(table_buf[3]); + ilm.MinFocal = bcd2dec(table_buf[0]) * 100.f + bcd2dec(table_buf[3]); if (table_buf[2] | table_buf[5]) - ilm.MaxFocal = bcd2dec(table_buf[2]) * 100 + bcd2dec(table_buf[5]); + ilm.MaxFocal = bcd2dec(table_buf[2]) * 100.f + bcd2dec(table_buf[5]); if (table_buf[4]) ilm.MaxAp4MinFocal = bcd2dec(table_buf[4]) / 10.0f; if (table_buf[4]) @@ -1344,9 +1388,9 @@ void LibRaw::parseSonyMakernotes( if ((LensDataValid) && strncasecmp(model, "NEX-5C", 6)) { if (table_buf[1] | table_buf[2]) - ilm.MinFocal = bcd2dec(table_buf[1]) * 100 + bcd2dec(table_buf[2]); + ilm.MinFocal = bcd2dec(table_buf[1]) * 100.f + bcd2dec(table_buf[2]); if (table_buf[3] | table_buf[4]) - ilm.MaxFocal = bcd2dec(table_buf[3]) * 100 + bcd2dec(table_buf[4]); + ilm.MaxFocal = bcd2dec(table_buf[3]) * 100.f + bcd2dec(table_buf[4]); if (table_buf[5]) ilm.MaxAp4MinFocal = bcd2dec(table_buf[5]) / 10.0f; if (table_buf[6]) @@ -1395,7 +1439,7 @@ void LibRaw::parseSonyMakernotes( else if ((len == 19154) || // a200 a230 a290 a300 a330 a350 a380 a390 : FocusInfo (len == 19148)) // a700 a850 a900 : FocusInfo { - table_buf = (uchar *)malloc(0x0080); + table_buf = (uchar *)calloc(0x0080,1); fread(table_buf, 0x0080, 1, ifp); imgdata.shootinginfo.DriveMode = table_buf[14]; imgdata.shootinginfo.ExposureProgram = table_buf[63]; @@ -1413,7 +1457,7 @@ void LibRaw::parseSonyMakernotes( if ((a) && (c == 1)) { fseek(ifp, INT64(d) - 8LL, SEEK_CUR); - table_buf = (uchar *)malloc(256); + table_buf = (uchar *)calloc(256,1); fread(table_buf, 256, 1, ifp); imgdata.shootinginfo.DriveMode = table_buf[1]; imgdata.shootinginfo.ExposureProgram = table_buf[2]; @@ -1467,7 +1511,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x0104) { - imCommon.FlashEC = getreal(type); + imCommon.FlashEC = getrealf(type); } else if (tag == 0x0105) // Teleconverter { @@ -1495,7 +1539,7 @@ void LibRaw::parseSonyMakernotes( (tag == 0xb0280114)) && (len < 256000)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); switch (len) { @@ -1707,7 +1751,7 @@ void LibRaw::parseSonyMakernotes( } else if ((tag == 0x3000) && (len < 256000)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); if (len >= 0x19) { @@ -1723,7 +1767,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x0116 && len < 256000) { - table_buf_0x0116 = (uchar *)malloc(len); + table_buf_0x0116 = (uchar *)calloc(len,1); table_buf_0x0116_len = len; fread(table_buf_0x0116, len, 1, ifp); if (ilm.CamID) @@ -1748,7 +1792,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x2010 && len < 256000) { - table_buf_0x2010 = (uchar *)malloc(len); + table_buf_0x2010 = (uchar *)calloc(len,1); table_buf_0x2010_len = len; fread(table_buf_0x2010, len, 1, ifp); if (ilm.CamID) @@ -1803,7 +1847,7 @@ void LibRaw::parseSonyMakernotes( imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); imSony.nAFPointsUsed = short(MIN(imCommon.afdata[imCommon.afcount].AFInfoData_length, sizeof imSony.AFPointsUsed)); @@ -1827,7 +1871,7 @@ void LibRaw::parseSonyMakernotes( imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); imCommon.afcount++; } @@ -1859,7 +1903,7 @@ void LibRaw::parseSonyMakernotes( imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag; imCommon.afdata[imCommon.afcount].AFInfoData_order = order; imCommon.afdata[imCommon.afcount].AFInfoData_length = len; - imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length); + imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length,1); fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp); imCommon.afcount++; } @@ -1884,7 +1928,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x9050 && len < 256000) // little endian { - table_buf_0x9050 = (uchar *)malloc(len); + table_buf_0x9050 = (uchar *)calloc(len,1); table_buf_0x9050_len = len; fread(table_buf_0x9050, len, 1, ifp); @@ -1898,7 +1942,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x9400 && len < 256000) { - table_buf_0x9400 = (uchar *)malloc(len); + table_buf_0x9400 = (uchar *)calloc(len,1); table_buf_0x9400_len = len; fread(table_buf_0x9400, len, 1, ifp); if (ilm.CamID) @@ -1910,7 +1954,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x9402 && len < 256000) { - table_buf_0x9402 = (uchar *)malloc(len); + table_buf_0x9402 = (uchar *)calloc(len,1); table_buf_0x9402_len = len; fread(table_buf_0x9402, len, 1, ifp); if (ilm.CamID) @@ -1922,7 +1966,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x9403 && len < 256000) { - table_buf_0x9403 = (uchar *)malloc(len); + table_buf_0x9403 = (uchar *)calloc(len,1); table_buf_0x9403_len = len; fread(table_buf_0x9403, len, 1, ifp); if (ilm.CamID) @@ -1934,7 +1978,7 @@ void LibRaw::parseSonyMakernotes( } else if ((tag == 0x9405) && (len < 256000) && (len > 0x64)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); uc = table_buf[0x0]; if (imCommon.real_ISO < 0.1f) @@ -1952,7 +1996,7 @@ void LibRaw::parseSonyMakernotes( } else if ((tag == 0x9404) && (len < 256000) && (len > 0x21)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); uc = table_buf[0x00]; if (((uc == 0x70) || @@ -1972,7 +2016,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x9406 && len < 256000) { - table_buf_0x9406 = (uchar *)malloc(len); + table_buf_0x9406 = (uchar *)calloc(len,1); table_buf_0x9406_len = len; fread(table_buf_0x9406, len, 1, ifp); if (ilm.CamID) @@ -1984,7 +2028,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x940c && len < 256000) { - table_buf_0x940c = (uchar *)malloc(len); + table_buf_0x940c = (uchar *)calloc(len,1); table_buf_0x940c_len = len; fread(table_buf_0x940c, len, 1, ifp); if (ilm.CamID) @@ -1996,7 +2040,7 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0x940e && len < 256000) { - table_buf_0x940e = (uchar *)malloc(len); + table_buf_0x940e = (uchar *)calloc(len,1); table_buf_0x940e_len = len; fread(table_buf_0x940e, len, 1, ifp); if (ilm.CamID) @@ -2007,7 +2051,7 @@ void LibRaw::parseSonyMakernotes( } } else if ((tag == 0x9416) && (len < 256000) && (len > 0x0076)) { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); if (imCommon.real_ISO < 0.1f) { s[0] = SonySubstitution[table_buf[0x04]]; @@ -2072,16 +2116,16 @@ void LibRaw::parseSonyMakernotes( } else if (tag == 0xb02a && len < 256000) // Sony LensSpec { - table_buf = (uchar *)malloc(len); + table_buf = (uchar *)calloc(len,1); fread(table_buf, len, 1, ifp); if ((!dng_writer) || (saneSonyCameraInfo(table_buf[1], table_buf[2], table_buf[3], table_buf[4], table_buf[5], table_buf[6]))) { if (table_buf[1] | table_buf[2]) - ilm.MinFocal = bcd2dec(table_buf[1]) * 100 + bcd2dec(table_buf[2]); + ilm.MinFocal = bcd2dec(table_buf[1]) * 100.f + bcd2dec(table_buf[2]); if (table_buf[3] | table_buf[4]) - ilm.MaxFocal = bcd2dec(table_buf[3]) * 100 + bcd2dec(table_buf[4]); + ilm.MaxFocal = bcd2dec(table_buf[3]) * 100.f + bcd2dec(table_buf[4]); if (table_buf[5]) ilm.MaxAp4MinFocal = bcd2dec(table_buf[5]) / 10.0f; if (table_buf[6]) @@ -2136,15 +2180,15 @@ void LibRaw::parseSonySR2(uchar *_cbuf_SR2, unsigned SR2SubIFDOffset, if (dng_writer == nonDNG) { switch (tag_id) { case 0x7300: - FORC4 cblack[c] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC4 cblack[c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); TagProcessed = 1; break; case 0x7303: - FORC4 cam_mul[GRBG_2_RGBG(c)] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC4 cam_mul[GRBG_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); TagProcessed = 1; break; case 0x7310: - FORC4 cblack[RGGB_2_RGBG(c)] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC4 cblack[RGGB_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); i = cblack[3]; FORC3 if (i > (int)cblack[c]) i = cblack[c]; FORC4 cblack[c] -= i; @@ -2152,23 +2196,23 @@ void LibRaw::parseSonySR2(uchar *_cbuf_SR2, unsigned SR2SubIFDOffset, TagProcessed = 1; break; case 0x7313: - FORC4 cam_mul[RGGB_2_RGBG(c)] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC4 cam_mul[RGGB_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); TagProcessed = 1; break; case 0x74a0: - ilm.MaxAp4MaxFocal = cbuf_SR2.sgetreal(tag_type, tag_dataoffset); + ilm.MaxAp4MaxFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset)); TagProcessed = 1; break; case 0x74a1: - ilm.MaxAp4MinFocal = cbuf_SR2.sgetreal(tag_type, tag_dataoffset); + ilm.MaxAp4MinFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset)); TagProcessed = 1; break; case 0x74a2: - ilm.MaxFocal = cbuf_SR2.sgetreal(tag_type, tag_dataoffset); + ilm.MaxFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset)); TagProcessed = 1; break; case 0x74a3: - ilm.MinFocal = cbuf_SR2.sgetreal(tag_type, tag_dataoffset); + ilm.MinFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset)); TagProcessed = 1; break; case 0x7800: @@ -2178,7 +2222,7 @@ void LibRaw::parseSonySR2(uchar *_cbuf_SR2, unsigned SR2SubIFDOffset, for (c = 0; c < 3; c++) { imgdata.color.ccm[i][c] = - (float)((short)cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * (i * 3 + c))); + (float)((short)cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * (i * 3 + c))); num += imgdata.color.ccm[i][c]; } if (num > 0.01) @@ -2189,14 +2233,14 @@ void LibRaw::parseSonySR2(uchar *_cbuf_SR2, unsigned SR2SubIFDOffset, case 0x787f: if (tag_datalen == 3) { - FORC3 imgdata.color.linear_max[c] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC3 imgdata.color.linear_max[c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); imgdata.color.linear_max[3] = imgdata.color.linear_max[1]; } else if (tag_datalen == 1) { imgdata.color.linear_max[0] = imgdata.color.linear_max[1] = imgdata.color.linear_max[2] = imgdata.color.linear_max[3] = - cbuf_SR2.sget2(tag_dataoffset); + cbuf_SR2.sget2LL(tag_dataoffset); } TagProcessed = 1; break; @@ -2207,38 +2251,42 @@ void LibRaw::parseSonySR2(uchar *_cbuf_SR2, unsigned SR2SubIFDOffset, if ((tag_id >= 0x7480) && (tag_id <= 0x7486)) { i = tag_id - 0x7480; if (Sony_SR2_wb_list[i] > 255) { + if (WBCTC_count < 64) { icWBCCTC[WBCTC_count][0] = Sony_SR2_wb_list[i]; FORC3 icWBCCTC[WBCTC_count][c + 1] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); icWBCCTC[WBCTC_count][4] = icWBCCTC[WBCTC_count][2]; - WBCTC_count++; + } + WBCTC_count++; } else { - FORC3 icWBC[Sony_SR2_wb_list[i]][c] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC3 icWBC[Sony_SR2_wb_list[i]][c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); icWBC[Sony_SR2_wb_list[i]][3] = icWBC[Sony_SR2_wb_list[i]][1]; } } else if ((tag_id >= 0x7820) && (tag_id <= 0x782d)) { i = tag_id - 0x7820; if (Sony_SR2_wb_list1[i] > 255) { + if (WBCTC_count < 64) { icWBCCTC[WBCTC_count][0] = Sony_SR2_wb_list1[i]; FORC3 icWBCCTC[WBCTC_count][c + 1] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); icWBCCTC[WBCTC_count][4] = icWBCCTC[WBCTC_count][2]; if (Sony_SR2_wb_list1[i] == 3200) { - FORC3 icWBC[LIBRAW_WBI_StudioTungsten][c] = icWBCCTC[WBCTC_count][c + 1]; + FORC3 icWBC[LIBRAW_WBI_StudioTungsten][c] = int(icWBCCTC[WBCTC_count][c + 1]); icWBC[LIBRAW_WBI_StudioTungsten][3] = icWBC[LIBRAW_WBI_StudioTungsten][1]; } - WBCTC_count++; + } + WBCTC_count++; } else { - FORC3 icWBC[Sony_SR2_wb_list1[i]][c] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC3 icWBC[Sony_SR2_wb_list1[i]][c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); icWBC[Sony_SR2_wb_list1[i]][3] = icWBC[Sony_SR2_wb_list1[i]][1]; } } else if (tag_id == 0x7302) { - FORC4 icWBC[LIBRAW_WBI_Auto][GRBG_2_RGBG(c)] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC4 icWBC[LIBRAW_WBI_Auto][GRBG_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); } else if (tag_id == 0x7312) { - FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = cbuf_SR2.sget2(tag_dataoffset + tag_dataunitlen * c); + FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c); } } } @@ -2277,43 +2325,44 @@ void LibRaw::parseSonySRF(unsigned len) checked_buffer_t srf_buf(order, len); fread(srf_buf.data(), len, 1, ifp); - offset += srf_buf[offset] << 2; + offset += srf_buf[int(offset)] << 2; + int ioffset = int(offset); /* master key is stored in big endian */ - MasterKey = ((unsigned)srf_buf[offset] << 24) | - ((unsigned)srf_buf[offset + 1] << 16) | - ((unsigned)srf_buf[offset + 2] << 8) | - (unsigned)srf_buf[offset + 3]; + MasterKey = ((unsigned)srf_buf[ioffset] << 24) | + ((unsigned)srf_buf[ioffset + 1] << 16) | + ((unsigned)srf_buf[ioffset + 2] << 8) | + (unsigned)srf_buf[ioffset + 3]; /* skip SRF0 */ srf_offset = 0; - entries = srf_buf.sget2(srf_offset); + entries = srf_buf.sget2LL(srf_offset); if (entries > 1000) goto restore_after_parseSonySRF; offset = srf_offset + 2; - srf_offset = srf_buf.sget4(offset + 12 * entries) - save; /* SRF0 ends with SRF1 abs. position */ + srf_offset = srf_buf.sget4LL(offset + 12 * entries) - save; /* SRF0 ends with SRF1 abs. position */ /* get SRF1, it has fixed 40 bytes length and contains keys to decode metadata * and raw data */ if (srf_offset < 0 || decrypt_len < srf_offset / 4) goto restore_after_parseSonySRF; - sony_decrypt((unsigned *)(srf_buf.data() + srf_offset), decrypt_len - srf_offset / 4, + sony_decrypt((unsigned *)(srf_buf.data() + int(srf_offset)), int(decrypt_len - srf_offset / 4), 1, MasterKey); - entries = srf_buf.sget2(srf_offset); + entries = srf_buf.sget2LL(srf_offset); if (entries > 1000) goto restore_after_parseSonySRF; offset = srf_offset + 2; tag_offset = offset; while (entries--) { - if (tiff_sget(save, srf_buf.data(), len, + if (tiff_sget(unsigned(save), srf_buf.data(), len, &tag_offset, &tag_id, &tag_type, &tag_dataoffset, &tag_datalen, &tag_dataunitlen) == 0) { if (tag_id == 0x0000) { - SRF2Key = srf_buf.sget4(tag_dataoffset); + SRF2Key = srf_buf.sget4LL(tag_dataoffset); } else if (tag_id == 0x0001) { - /*RawDataKey =*/ srf_buf.sget4(tag_dataoffset); + /*RawDataKey =*/ srf_buf.sget4LL(tag_dataoffset); } } else goto restore_after_parseSonySRF; @@ -2321,26 +2370,26 @@ void LibRaw::parseSonySRF(unsigned len) offset = tag_offset; /* get SRF2 */ - srf_offset = srf_buf.sget4(offset) - save; /* SRFn ends with SRFn+1 position */ + srf_offset = srf_buf.sget4LL(offset) - save; /* SRFn ends with SRFn+1 position */ if (srf_offset < 0 || decrypt_len < srf_offset / 4) goto restore_after_parseSonySRF; - sony_decrypt((unsigned *)(srf_buf.data() + srf_offset), decrypt_len - srf_offset / 4, + sony_decrypt((unsigned *)(srf_buf.data() + srf_offset), int(decrypt_len - srf_offset / 4), 1, SRF2Key); - entries = srf_buf.sget2(srf_offset); + entries = srf_buf.sget2(int(srf_offset)); if (entries > 1000) goto restore_after_parseSonySRF; offset = srf_offset + 2; tag_offset = offset; while (entries--) { - if (srf_buf.tiff_sget(save, + if (srf_buf.tiff_sget(unsigned(save), &tag_offset, &tag_id, &tag_type, &tag_dataoffset, &tag_datalen, &tag_dataunitlen) == 0) { if ((tag_id >= 0x00c0) && (tag_id <= 0x00ce)) { i = (tag_id - 0x00c0) % 3; nWB = (tag_id - 0x00c0) / 3; - icWBC[Sony_SRF_wb_list[nWB]][i] = srf_buf.sget4(tag_dataoffset); + icWBC[Sony_SRF_wb_list[nWB]][i] = srf_buf.sget4LL(tag_dataoffset); if (i == 1) { icWBC[Sony_SRF_wb_list[nWB]][3] = icWBC[Sony_SRF_wb_list[nWB]][i]; @@ -2348,7 +2397,7 @@ void LibRaw::parseSonySRF(unsigned len) } else if ((tag_id >= 0x00d0) && (tag_id <= 0x00d2)) { i = (tag_id - 0x00d0) % 3; - cam_mul[i] = srf_buf.sget4(tag_dataoffset); + cam_mul[i] = float(srf_buf.sget4LL(tag_dataoffset)); if (i == 1) { cam_mul[3] = cam_mul[i]; } @@ -2361,16 +2410,16 @@ void LibRaw::parseSonySRF(unsigned len) 0x0005 RawDataLength */ case 0x0043: - ilm.MaxAp4MaxFocal = srf_buf.sgetreal(tag_type, tag_dataoffset); + ilm.MaxAp4MaxFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset)); break; case 0x0044: - ilm.MaxAp4MinFocal = srf_buf.sgetreal(tag_type, tag_dataoffset); + ilm.MaxAp4MinFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset)); break; case 0x0045: - ilm.MinFocal = srf_buf.sgetreal(tag_type, tag_dataoffset); + ilm.MinFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset)); break; case 0x0046: - ilm.MaxFocal = srf_buf.sgetreal(tag_type, tag_dataoffset); + ilm.MaxFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset)); break; } } diff --git a/rtengine/libraw/src/metadata/tiff.cpp b/rtengine/libraw/src/metadata/tiff.cpp index 9c1650c1a..b353367a4 100644 --- a/rtengine/libraw/src/metadata/tiff.cpp +++ b/rtengine/libraw/src/metadata/tiff.cpp @@ -19,9 +19,10 @@ #include "../../internal/dcraw_defs.h" #include "../../internal/libraw_cameraids.h" -int LibRaw::parse_tiff_ifd(int base) +int LibRaw::parse_tiff_ifd(INT64 base) { - unsigned entries, tag, type, len, plen = 16, save, utmp; + unsigned entries, tag, type, len, plen = 16, utmp; + INT64 save; int ifd, use_cm = 0, cfa, i, j, c, ima_len = 0; char *cbuf, *cp; uchar cfa_pat[16], cfa_pc[] = {0, 1, 2, 3}, tab[256]; @@ -90,8 +91,8 @@ int LibRaw::parse_tiff_ifd(int base) case 0x0111: /* 273, StripOffset */ if (len > 1 && len < 16384) { - off_t sav = ftell(ifp); - tiff_ifd[ifd].strip_offsets = (int *)calloc(len, sizeof(int)); + INT64 sav = ftell(ifp); + tiff_ifd[ifd].strip_offsets = (INT64 *)calloc(len, sizeof(INT64)); tiff_ifd[ifd].strip_offsets_count = len; for (int ii = 0; ii < (int)len; ii++) tiff_ifd[ifd].strip_offsets[ii] = get4() + base; @@ -175,10 +176,12 @@ int LibRaw::parse_tiff_ifd(int base) { if ((j = get2()) < 0x100) { - icWBC[j][0] = get2(); - icWBC[j][2] = get2(); - icWBC[j][1] = icWBC[j][3] = - 0x100; + if (j >= 0) { + icWBC[j][0] = get2(); + icWBC[j][2] = get2(); + icWBC[j][1] = icWBC[j][3] = + 0x100; + } } else // light source out of EXIF numbers range get4(); @@ -223,7 +226,7 @@ int LibRaw::parse_tiff_ifd(int base) break; case 0x0037: /* 55, ISO if ISO in 0x8827 & ISO in 0x0017 == 65535 */ if (iso_speed == 65535) - iso_speed = get4(); + iso_speed = float(get4()); break; case 0x0039: if (type == LIBRAW_EXIFTAG_TYPE_UNDEFINED && len == 26) @@ -372,7 +375,7 @@ int LibRaw::parse_tiff_ifd(int base) case 0x0120: /* 288, CameraIFD, contains tags 0x1xxx, 0x2xxx, 0x3xxx */ { unsigned sorder = order; - unsigned long sbase = base; + INT64 sbase = base; base = ftell(ifp); order = get2(); fseek(ifp, 2, SEEK_CUR); @@ -441,7 +444,7 @@ int LibRaw::parse_tiff_ifd(int base) break; case 0x3420: /* 13344, WB_RedLevelAuto, contained in 0x0120 CameraIFD */ icWBC[LIBRAW_WBI_Auto][0] = get2(); - icWBC[LIBRAW_WBI_Auto][1] = icWBC[LIBRAW_WBI_Auto][3] = 1024.0f; + icWBC[LIBRAW_WBI_Auto][1] = icWBC[LIBRAW_WBI_Auto][3] = 1024; break; case 0x3421: /* 13345, WB_BlueLevelAuto, contained in 0x0120 CameraIFD */ icWBC[LIBRAW_WBI_Auto][2] = get2(); @@ -474,7 +477,7 @@ int LibRaw::parse_tiff_ifd(int base) case 0x0011: /* 17, RedBalance */ case 0x0012: /* 18, BlueBalance */ if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT) && len == 1) - cam_mul[(tag - 0x0011) * 2] = get2() / 256.0; + cam_mul[(tag - 0x0011) * 2] = get2() / 256.f; break; case 0x0017: /* 23, ISO */ if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT)) @@ -492,12 +495,14 @@ int LibRaw::parse_tiff_ifd(int base) { if ((j = get2()) < 0x100) { + if(j >= 0) { icWBC[j][0] = get2(); icWBC[j][1] = icWBC[j][3] = get2(); icWBC[j][2] = get2(); if (c == 1 && i > 6 && cam_mul[0] <= 0.001f) for (int q = 0; q < 4; q++) - cam_mul[q] = icWBC[j][q]; + cam_mul[q] = float(icWBC[j][q]); + } } else fseek(ifp, 6, SEEK_CUR); @@ -518,8 +523,8 @@ int LibRaw::parse_tiff_ifd(int base) case 0x0111: /* 273, StripOffset */ if (len > 1 && len < 16384) { - off_t sav = ftell(ifp); - tiff_ifd[ifd].strip_offsets = (int *)calloc(len, sizeof(int)); + INT64 sav = ftell(ifp); + tiff_ifd[ifd].strip_offsets = (INT64 *)calloc(len, sizeof(INT64)); tiff_ifd[ifd].strip_offsets_count = len; for (int ii = 0; ii < (int)len; ii++) tiff_ifd[ifd].strip_offsets[ii] = get4() + base; @@ -561,7 +566,7 @@ int LibRaw::parse_tiff_ifd(int base) parse_tiff_ifd(base); break; case 0x00fe: /* NewSubfileType */ - tiff_ifd[ifd].newsubfiletype = getreal(type); + tiff_ifd[ifd].newsubfiletype = int(getreal(type)); break; case 0x0100: /* 256, ImageWidth */ case 0xf001: /* 61441, Fuji RAF RawImageFullWidth */ @@ -630,8 +635,8 @@ int LibRaw::parse_tiff_ifd(int base) case 0x0117: /* 279, StripByteCounts */ if (len > 1 && len < 16384) { - off_t sav = ftell(ifp); - tiff_ifd[ifd].strip_byte_counts = (int *)calloc(len, sizeof(int)); + INT64 sav = ftell(ifp); + tiff_ifd[ifd].strip_byte_counts = (INT64 *)calloc(len, sizeof(INT64)); tiff_ifd[ifd].strip_byte_counts_count = len; for (int ii = 0; ii < (int)len; ii++) tiff_ifd[ifd].strip_byte_counts[ii] = get4(); @@ -643,7 +648,7 @@ int LibRaw::parse_tiff_ifd(int base) tiff_ifd[ifd].bytes = get4(); break; case 0xf00e: // 61454, FujiFilm "As Shot" - FORC3 cam_mul[GRBG_2_RGBG(c)] = getint(type); + FORC3 cam_mul[GRBG_2_RGBG(c)] = float(getint(type)); break; case 0x0131: /* 305, Software */ fgets(software, 64, ifp); @@ -668,7 +673,7 @@ int LibRaw::parse_tiff_ifd(int base) tiff_ifd[ifd].t_tile_length = getint(type); break; case 0x0144: /* 324, TileOffsets */ - tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4(); + tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4(); // FIXME: get8 for BigTIFF if (len == 1) tiff_ifd[ifd].t_tile_width = tiff_ifd[ifd].t_tile_length = 0; if (len == 4) @@ -678,7 +683,7 @@ int LibRaw::parse_tiff_ifd(int base) } break; case 0x0145: // 325 - tiff_ifd[ifd].bytes = len > 1 ? ftell(ifp) : get4(); + tiff_ifd[ifd].bytes = len > 1 ? ftell(ifp) : get4(); // FIXME: get8 for BigTIFF break; case 0x014a: /* 330, SubIFDs */ if (!strcmp(model, "DSLR-A100") && tiff_ifd[ifd].t_width == 3872) @@ -702,11 +707,11 @@ int LibRaw::parse_tiff_ifd(int base) len = 1000; /* 1000 SubIFDs is enough */ while (len--) { - i = ftell(ifp); + INT64 ii = ftell(ifp); fseek(ifp, get4() + base, SEEK_SET); if (parse_tiff_ifd(base)) break; - fseek(ifp, i + 4, SEEK_SET); + fseek(ifp, ii + 4LL, SEEK_SET); } break; case 0x0153: // 339 @@ -723,9 +728,9 @@ int LibRaw::parse_tiff_ifd(int base) tagtypeIs(LIBRAW_EXIFTOOLTAGTYPE_binary)) && (len > 1) && (len < 5100000)) { - xmpdata = (char *)malloc(xmplen = len + 1); - fread(xmpdata, len, 1, ifp); - xmpdata[len] = 0; + xmpdata = (char *)calloc(xmplen = len + 1,1); + unsigned br = fread(xmpdata,1, len, ifp); + xmpdata[br] = 0; } break; case 0x7000: @@ -814,32 +819,34 @@ int LibRaw::parse_tiff_ifd(int base) parse_kodak_ifd(base); break; case 0x829a: /* 33434, ExposureTime */ - tiff_ifd[ifd].t_shutter = shutter = getreal(type); + tiff_ifd[ifd].t_shutter = shutter = getrealf(type); break; case 0x829d: /* 33437, FNumber */ - aperture = getreal(type); + aperture = getrealf(type); break; case 0x9400: - imCommon.exifAmbientTemperature = getreal(type); + imCommon.exifAmbientTemperature = getrealf(type); if ((imCommon.CameraTemperature > -273.15f) && - ((OlyID == OlyID_TG_5) || (OlyID == OlyID_TG_6))) + ((OlyID == OlyID_TG_5) || + (OlyID == OlyID_TG_6) || + (OlyID == OlyID_TG_7))) imCommon.CameraTemperature += imCommon.exifAmbientTemperature; break; case 0x9401: - imCommon.exifHumidity = getreal(type); + imCommon.exifHumidity = getrealf(type); break; case 0x9402: - imCommon.exifPressure = getreal(type); + imCommon.exifPressure = getrealf(type); break; case 0x9403: - imCommon.exifWaterDepth = getreal(type); + imCommon.exifWaterDepth = getrealf(type); break; case 0x9404: - imCommon.exifAcceleration = getreal(type); + imCommon.exifAcceleration = getrealf(type); break; case 0x9405: - imCommon.exifCameraElevationAngle = getreal(type); + imCommon.exifCameraElevationAngle = getrealf(type); break; case 0xa405: // FocalLengthIn35mmFormat imgdata.lens.FocalLengthIn35mmFormat = get2(); @@ -849,19 +856,19 @@ int LibRaw::parse_tiff_ifd(int base) stmread(imgdata.shootinginfo.BodySerial, len, ifp); break; case 0xa432: // LensInfo, 42034dec, Lens Specification per EXIF standard - imgdata.lens.MinFocal = getreal(type); - imgdata.lens.MaxFocal = getreal(type); - imgdata.lens.MaxAp4MinFocal = getreal(type); - imgdata.lens.MaxAp4MaxFocal = getreal(type); + imgdata.lens.MinFocal = getrealf(type); + imgdata.lens.MaxFocal = getrealf(type); + imgdata.lens.MaxAp4MinFocal = getrealf(type); + imgdata.lens.MaxAp4MaxFocal = getrealf(type); break; case 0xa435: // LensSerialNumber stmread(imgdata.lens.LensSerial, len, ifp); break; case 0xc630: // DNG LensInfo, Lens Specification per EXIF standard - imgdata.lens.MinFocal = getreal(type); - imgdata.lens.MaxFocal = getreal(type); - imgdata.lens.MaxAp4MinFocal = getreal(type); - imgdata.lens.MaxAp4MaxFocal = getreal(type); + imgdata.lens.MinFocal = getrealf(type); + imgdata.lens.MaxFocal = getrealf(type); + imgdata.lens.MaxAp4MinFocal = getrealf(type); + imgdata.lens.MaxAp4MaxFocal = getrealf(type); break; case 0xa420: /* 42016, ImageUniqueID */ stmread(imgdata.color.ImageUniqueID, len, ifp); @@ -879,14 +886,14 @@ int LibRaw::parse_tiff_ifd(int base) imgdata.lens.Lens[0] = 0; break; case 0x9205: - imgdata.lens.EXIF_MaxAp = libraw_powf64l(2.0f, (getreal(type) / 2.0f)); + imgdata.lens.EXIF_MaxAp = libraw_powf64l(2.0f, (getrealf(type) / 2.0f)); break; case 0x8602: /* 34306, Leaf white balance */ FORC4 { int q = get2(); if (q) - cam_mul[GRGB_2_RGBG(c)] = 4096.0 / q; + cam_mul[GRGB_2_RGBG(c)] = 4096.f / q; } break; case 0x8603: /* 34307, Leaf CatchLight color matrix */ @@ -901,7 +908,7 @@ int LibRaw::parse_tiff_ifd(int base) continue; num = 0; FORC4 num += rgb_cam[i][c]; - FORC4 rgb_cam[i][c] /= MAX(1, num); + FORC4 rgb_cam[i][c] /= float(MAX(1, num)); } break; case 0x8606: /* 34310, Leaf metadata */ @@ -915,7 +922,7 @@ int LibRaw::parse_tiff_ifd(int base) break; case 0x8825: /* 34853, GPSInfo tag */ { - unsigned pos; + INT64 pos; fseek(ifp, pos = (get4() + base), SEEK_SET); parse_gps(base); fseek(ifp, pos, SEEK_SET); @@ -931,19 +938,19 @@ int LibRaw::parse_tiff_ifd(int base) kodak_cbpp = get4(); break; case 0x920a: /* 37386, FocalLength */ - focal_len = getreal(type); + focal_len = getrealf(type); break; case 0x9211: /* 37393, ImageNumber */ shot_order = getint(type); break; case 0x9215: /* 37397, ExposureIndex */ - imCommon.exifExposureIndex = getreal(type); + imCommon.exifExposureIndex = getrealf(type); break; case 0x9218: /* 37400, old Kodak KDC tag */ for (raw_color = i = 0; i < 3; i++) { getreal(type); - FORC3 rgb_cam[i][c] = getreal(type); + FORC3 rgb_cam[i][c] = getrealf(type); } break; case 0xa010: // 40976 @@ -993,7 +1000,7 @@ int LibRaw::parse_tiff_ifd(int base) left_margin = 7; } fseek(ifp, 52, SEEK_CUR); - FORC3 cam_mul[c] = getreal(LIBRAW_EXIFTAG_TYPE_FLOAT); + FORC3 cam_mul[c] = getrealf(LIBRAW_EXIFTAG_TYPE_FLOAT); fseek(ifp, 114, SEEK_CUR); flip = (get2() >> 7) * 90; if (width * (height * 6l) == ima_len) @@ -1038,11 +1045,12 @@ int LibRaw::parse_tiff_ifd(int base) { libraw_internal_data.unpacker_data.hasselblad_parser_flag = 1; i = order; - j = ftell(ifp); + INT64 jj = ftell(ifp); c = tiff_nifds; order = get2(); - fseek(ifp, j + (get2(), get4()), SEEK_SET); - parse_tiff_ifd(j); + get2(); + fseek(ifp, jj + get4(), SEEK_SET); + parse_tiff_ifd(jj); maximum = 0xffff; tiff_nifds = c; order = i; @@ -1094,18 +1102,23 @@ int LibRaw::parse_tiff_ifd(int base) break; case 0xc619: /* 50713, BlackLevelRepeatDim */ tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_BLACK; - tiff_ifd[ifd].dng_levels.dng_fcblack[4] = - tiff_ifd[ifd].dng_levels.dng_cblack[4] = cblack[4] = get2(); - tiff_ifd[ifd].dng_levels.dng_fcblack[5] = - tiff_ifd[ifd].dng_levels.dng_cblack[5] = cblack[5] = get2(); - if (cblack[4] * cblack[5] > - (LIBRAW_CBLACK_SIZE - - 7)) // Use last cblack item as DNG black level count - tiff_ifd[ifd].dng_levels.dng_fcblack[4] = - tiff_ifd[ifd].dng_levels.dng_fcblack[5] = - tiff_ifd[ifd].dng_levels.dng_cblack[4] = - tiff_ifd[ifd].dng_levels.dng_cblack[5] = cblack[4] = - cblack[5] = 1; + + tiff_ifd[ifd].dng_levels.dng_cblack[4] = cblack[4] = get2(); + tiff_ifd[ifd].dng_levels.dng_fcblack[4] = float(cblack[4]); + + + tiff_ifd[ifd].dng_levels.dng_cblack[5] = cblack[5] = get2(); + tiff_ifd[ifd].dng_levels.dng_fcblack[5] = float(cblack[5]); + + if (cblack[4] * cblack[5] > + (LIBRAW_CBLACK_SIZE - + 7)) // Use last cblack item as DNG black level count + { + tiff_ifd[ifd].dng_levels.dng_fcblack[4] = + tiff_ifd[ifd].dng_levels.dng_fcblack[5] = 1.f; + tiff_ifd[ifd].dng_levels.dng_cblack[4] = tiff_ifd[ifd].dng_levels.dng_cblack[5] = + cblack[4] = cblack[5] = 1; + } break; case 0xf00c: @@ -1122,8 +1135,8 @@ int LibRaw::parse_tiff_ifd(int base) (libraw_internal_data.unpacker_data.lenRAFData < 10240000)) { INT64 f_save = ftell(ifp); - rafdata = (ushort *)malloc( - sizeof(ushort) * libraw_internal_data.unpacker_data.lenRAFData); + rafdata = (ushort *)calloc( + sizeof(ushort) * libraw_internal_data.unpacker_data.lenRAFData,1); fseek(ifp, libraw_internal_data.unpacker_data.posRAFData, SEEK_SET); fread(rafdata, sizeof(ushort), libraw_internal_data.unpacker_data.lenRAFData, ifp); @@ -1150,10 +1163,12 @@ int LibRaw::parse_tiff_ifd(int base) (imFuji.RAFDataVersion == 0x0265) || // X-E4, X-T5 (imFuji.RAFDataVersion == 0x0266) || // X-T30 II, X-S20 (imFuji.RAFDataVersion == 0x0267) || // GFX 100 II + (imFuji.RAFDataVersion == 0x0369) || // X100VI !strcmp(model, "X-Pro3") || !strcmp(model, "GFX100 II") || !strcmp(model, "GFX 100 II") || !strcmp(model, "GFX100S") || !strcmp(model, "GFX 100S") || !strcmp(model, "GFX50S II") || !strcmp(model, "GFX 50S II") || + !strcmp(model, "X100VI") || !strcmp(model, "X100V") || !strcmp(model, "X-T4") || !strcmp(model, "X-H2S") || @@ -1173,34 +1188,40 @@ int LibRaw::parse_tiff_ifd(int base) if ((fwb[0] == rafdata[fi]) && (fwb[1] == rafdata[fi + 1]) && (fwb[2] == rafdata[fi + 2])) // found Tungsten WB { - if (rafdata[fi - 15] != + if (fi > 14 && rafdata[fi - 15] != fwb[0]) // 15 is offset of Tungsten WB from the first // preset, Fine Weather WB continue; - for (int wb_ind = 0, ofst = fi - 15; wb_ind < (int)Fuji_wb_list1.size(); - wb_ind++, ofst += 3) - { - icWBC[Fuji_wb_list1[wb_ind]][1] = - icWBC[Fuji_wb_list1[wb_ind]][3] = rafdata[ofst]; - icWBC[Fuji_wb_list1[wb_ind]][0] = rafdata[ofst + 1]; - icWBC[Fuji_wb_list1[wb_ind]][2] = rafdata[ofst + 2]; - } + if (fi >= 15) + { + for (int wb_ind = 0, ofst = fi - 15; wb_ind < (int)Fuji_wb_list1.size(); + wb_ind++, ofst += 3) + { + icWBC[Fuji_wb_list1[wb_ind]][1] = + icWBC[Fuji_wb_list1[wb_ind]][3] = rafdata[ofst]; + icWBC[Fuji_wb_list1[wb_ind]][0] = rafdata[ofst + 1]; + icWBC[Fuji_wb_list1[wb_ind]][2] = rafdata[ofst + 2]; + } + } if (is34) fi += 24; fi += 96; for (fj = fi; fj < (fi + 15); fj += 3) // looking for the end of the WB table { + if (fj > libraw_internal_data.unpacker_data.lenRAFData - 3) + break; if (rafdata[fj] != rafdata[fi]) { fj -= 93; if (is34) fj -= 9; //printf ("wb start in DNG: 0x%04x\n", fj*2-0x4e); - for (int iCCT = 0, ofst = fj; iCCT < 31; + for (int iCCT = 0, ofst = fj; iCCT < 31 + && ofst < libraw_internal_data.unpacker_data.lenRAFData - 3; iCCT++, ofst += 3) { - icWBCCTC[iCCT][0] = FujiCCT_K[iCCT]; + icWBCCTC[iCCT][0] = float(FujiCCT_K[iCCT]); icWBCCTC[iCCT][1] = rafdata[ofst + 1]; icWBCCTC[iCCT][2] = icWBCCTC[iCCT][4] = rafdata[ofst]; icWBCCTC[iCCT][3] = rafdata[ofst + 2]; @@ -1232,7 +1253,7 @@ int LibRaw::parse_tiff_ifd(int base) stmread(imgdata.color.LocalizedCameraModel, len, ifp); break; case 0xf00a: // 61450 - cblack[4] = cblack[5] = MIN(sqrt((double)len), 64); + cblack[4] = cblack[5] = int(MIN(sqrtf((float)len), 64.f)); case 0xc61a: /* 50714, BlackLevel */ if (tiff_ifd[ifd].samples > 1 && tiff_ifd[ifd].samples == (int)len) // LinearDNG, per-channel black @@ -1240,15 +1261,15 @@ int LibRaw::parse_tiff_ifd(int base) tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_BLACK; for (i = 0; i < 4 && i < (int)len; i++) { - tiff_ifd[ifd].dng_levels.dng_fcblack[i] = getreal(type); + tiff_ifd[ifd].dng_levels.dng_fcblack[i] = getrealf(type); tiff_ifd[ifd].dng_levels.dng_cblack[i] = cblack[i] = - tiff_ifd[ifd].dng_levels.dng_fcblack[i] + 0.5; + unsigned(tiff_ifd[ifd].dng_levels.dng_fcblack[i] + 0.5f); } // Record len in last cblack field tiff_ifd[ifd].dng_levels.dng_cblack[LIBRAW_CBLACK_SIZE - 1] = len; - tiff_ifd[ifd].dng_levels.dng_fblack = - tiff_ifd[ifd].dng_levels.dng_black = black = 0; + tiff_ifd[ifd].dng_levels.dng_fblack = 0.f; + tiff_ifd[ifd].dng_levels.dng_black = black = 0; } else if (tiff_ifd[ifd].samples > 1 // Linear DNG w repeat dim && (tiff_ifd[ifd].samples * cblack[4] * cblack[5] == len)) @@ -1258,24 +1279,24 @@ int LibRaw::parse_tiff_ifd(int base) cblack[LIBRAW_CBLACK_SIZE - 1] = len; for (i = 0; i < (int)len && i < LIBRAW_CBLACK_SIZE - 7; i++) { - tiff_ifd[ifd].dng_levels.dng_fcblack[i + 6] = getreal(type); + tiff_ifd[ifd].dng_levels.dng_fcblack[i + 6] = getrealf(type); tiff_ifd[ifd].dng_levels.dng_cblack[i + 6] = cblack[i + 6] = - tiff_ifd[ifd].dng_levels.dng_fcblack[i + 6] + 0.5; + unsigned(tiff_ifd[ifd].dng_levels.dng_fcblack[i + 6] + 0.5f); } } else if ((cblack[4] * cblack[5] < 2) && len == 1) { tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_BLACK; - tiff_ifd[ifd].dng_levels.dng_fblack = getreal(type); + tiff_ifd[ifd].dng_levels.dng_fblack = getrealf(type); black = tiff_ifd[ifd].dng_levels.dng_black = - tiff_ifd[ifd].dng_levels.dng_fblack; + unsigned(tiff_ifd[ifd].dng_levels.dng_fblack); } else if (cblack[4] * cblack[5] <= len) { FORC(int(cblack[4] * cblack[5])) { - tiff_ifd[ifd].dng_levels.dng_fcblack[6 + c] = getreal(type); - cblack[6 + c] = tiff_ifd[ifd].dng_levels.dng_fcblack[6 + c]; + tiff_ifd[ifd].dng_levels.dng_fcblack[6 + c] = getrealf(type); + cblack[6 + c] = unsigned(tiff_ifd[ifd].dng_levels.dng_fcblack[6 + c]); } black = 0; FORC4 @@ -1288,9 +1309,11 @@ int LibRaw::parse_tiff_ifd(int base) tiff_ifd[ifd].dng_levels.dng_cblack[6 + c] = cblack[6 + c]; tiff_ifd[ifd].dng_levels.dng_fblack = 0; tiff_ifd[ifd].dng_levels.dng_black = 0; - FORC4 - tiff_ifd[ifd].dng_levels.dng_fcblack[c] = - tiff_ifd[ifd].dng_levels.dng_cblack[c] = 0; + FORC4 + { + tiff_ifd[ifd].dng_levels.dng_fcblack[c] = 0.f; + tiff_ifd[ifd].dng_levels.dng_cblack[c] = 0; + } } } break; @@ -1300,9 +1323,9 @@ int LibRaw::parse_tiff_ifd(int base) num += getreal(type); if (len > 0) { - black += num / len + 0.5; - tiff_ifd[ifd].dng_levels.dng_fblack += num / float(len); - tiff_ifd[ifd].dng_levels.dng_black += num / len + 0.5; + black += unsigned(num / len + 0.5); + tiff_ifd[ifd].dng_levels.dng_fblack += float(num / len); + tiff_ifd[ifd].dng_levels.dng_black += unsigned(num / len + 0.5); tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_BLACK; } break; @@ -1315,8 +1338,8 @@ int LibRaw::parse_tiff_ifd(int base) break; case 0xc61e: /* DefaultScale */ { - float q1 = getreal(type); - float q2 = getreal(type); + float q1 = getrealf(type); + float q2 = getrealf(type); if (q1 > 0.00001f && q2 > 0.00001f) { pixel_aspect = q1 / q2; @@ -1329,8 +1352,8 @@ int LibRaw::parse_tiff_ifd(int base) if (len == 2) { tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_CROPORIGIN; - tiff_ifd[ifd].dng_levels.default_crop[0] = getreal(type); - tiff_ifd[ifd].dng_levels.default_crop[1] = getreal(type); + tiff_ifd[ifd].dng_levels.default_crop[0] = ushort(getreal(type)); + tiff_ifd[ifd].dng_levels.default_crop[1] = ushort(getreal(type)); if (!strncasecmp(make, "SONY", 4)) { imgdata.sizes.raw_inset_crops[0].cleft = @@ -1345,8 +1368,8 @@ int LibRaw::parse_tiff_ifd(int base) if (len == 2) { tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_CROPSIZE; - tiff_ifd[ifd].dng_levels.default_crop[2] = getreal(type); - tiff_ifd[ifd].dng_levels.default_crop[3] = getreal(type); + tiff_ifd[ifd].dng_levels.default_crop[2] = ushort(getreal(type)); + tiff_ifd[ifd].dng_levels.default_crop[3] = ushort(getreal(type)); if (!strncasecmp(make, "SONY", 4)) { imgdata.sizes.raw_inset_crops[0].cwidth = @@ -1363,7 +1386,7 @@ int LibRaw::parse_tiff_ifd(int base) int cnt = 0; FORC4 { - float v = getreal(type); + float v = getrealf(type); if (v >= 0.f && v <= 1.f) { tiff_ifd[ifd].dng_levels.user_crop[c] = v; @@ -1414,7 +1437,8 @@ int LibRaw::parse_tiff_ifd(int base) } FORC(chan) for (j = 0; j < 3; j++) { - tiff_ifd[ifd].dng_color[i].colormatrix[c][j] = cm[c][j] = getreal(type); + cm[c][j] = getreal(type); + tiff_ifd[ifd].dng_color[i].colormatrix[c][j] = float(cm[c][j]); } use_cm = 1; } @@ -1430,8 +1454,8 @@ int LibRaw::parse_tiff_ifd(int base) for (j = 0; j < 3; j++) FORC(chan) { - tiff_ifd[ifd].dng_color[i].forwardmatrix[j][c] = fm[j][c] = - getreal(type); + fm[j][c] = getreal(type); + tiff_ifd[ifd].dng_color[i].forwardmatrix[j][c] = float(fm[j][c]); } } break; @@ -1445,9 +1469,9 @@ int LibRaw::parse_tiff_ifd(int base) tiff_ifd[ifd].dng_color[j].parsedfields |= LIBRAW_DNGFM_CALIBRATION; for (i = 0; i < chan; i++) FORC(chan) - { - tiff_ifd[ifd].dng_color[j].calibration[i][c] = cc[i][c] = - getreal(type); + { + cc[i][c] = getreal(type); + tiff_ifd[ifd].dng_color[j].calibration[i][c] = float(cc[i][c]); } } break; @@ -1456,14 +1480,18 @@ int LibRaw::parse_tiff_ifd(int base) tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_ANALOGBALANCE; for (c = 0; c < (int)len && c < 4; c++) { - tiff_ifd[ifd].dng_levels.analogbalance[c] = ab[c] = getreal(type); + ab[c] = getreal(type); + tiff_ifd[ifd].dng_levels.analogbalance[c] = float(ab[c]); } break; case 0xc628: /* 50728, AsShotNeutral */ if (len >= 3) tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_ASSHOTNEUTRAL; - for (c = 0; c < (int)len && c < 4; c++) - tiff_ifd[ifd].dng_levels.asshotneutral[c] = asn[c] = getreal(type); + for (c = 0; c < (int)len && c < 4; c++) + { + asn[c] = getreal(type); + tiff_ifd[ifd].dng_levels.asshotneutral[c] = float(asn[c]); + } break; case 0xc629: /* 50729, AsShotWhiteXY */ xyz[0] = getreal(type); @@ -1473,11 +1501,11 @@ int LibRaw::parse_tiff_ifd(int base) break; case 0xc62a: /* DNG: 50730 BaselineExposure */ tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_BASELINEEXPOSURE; - tiff_ifd[ifd].dng_levels.baseline_exposure = getreal(type); + tiff_ifd[ifd].dng_levels.baseline_exposure = getrealf(type); break; case 0xc62e: /* DNG: 50734 LinearResponseLimit */ tiff_ifd[ifd].dng_levels.parsedfields |= LIBRAW_DNGFM_LINEARRESPONSELIMIT; - tiff_ifd[ifd].dng_levels.LinearResponseLimit = getreal(type); + tiff_ifd[ifd].dng_levels.LinearResponseLimit = getrealf(type); break; case 0xc634: /* 50740 : DNG Adobe, DNG Pentax, Sony SR2, DNG Private */ @@ -1549,12 +1577,20 @@ int LibRaw::parse_tiff_ifd(int base) unsigned SR2SubIFDLength = 0; unsigned SR2SubIFDKey = 0; { - int _base = curr_pos + 6 - pos_in_original_raw; - unsigned _entries, _tag, _type, _len, _save; - _entries = get2(); + INT64 _base = curr_pos + 6 - pos_in_original_raw; + unsigned _entries, _tag, _type, _len; + INT64 _save; + _entries = get2(); while (_entries--) { tiff_get(_base, &_tag, &_type, &_len, &_save); + if (callbacks.exif_cb) + { + INT64 _savepos = ftell(ifp); + callbacks.exif_cb(callbacks.exifparser_data, tag | 0x60000, + _type, _len, order, ifp, base); + fseek(ifp, _savepos, SEEK_SET); + } if (_tag == 0x7200) { @@ -1573,14 +1609,16 @@ int LibRaw::parse_tiff_ifd(int base) } if (SR2SubIFDLength && (SR2SubIFDLength < 10240000) && - (buf_SR2 = (unsigned *)malloc(SR2SubIFDLength + 1024))) + (buf_SR2 = (unsigned *)calloc(SR2SubIFDLength + 1024,1))) { // 1024b for safety fseek(ifp, SR2SubIFDOffset + base, SEEK_SET); - fread(buf_SR2, SR2SubIFDLength, 1, ifp); - sony_decrypt(buf_SR2, SR2SubIFDLength / 4, 1, SR2SubIFDKey); - parseSonySR2((uchar *)buf_SR2, SR2SubIFDOffset, - SR2SubIFDLength, AdobeDNG); - + int items = fread(buf_SR2, 1, SR2SubIFDLength, ifp); + if (items == SR2SubIFDLength) + { + sony_decrypt(buf_SR2, SR2SubIFDLength / 4, 1, SR2SubIFDKey); + parseSonySR2((uchar *)buf_SR2, SR2SubIFDOffset, + SR2SubIFDLength, AdobeDNG); + } free(buf_SR2); } @@ -1611,8 +1649,12 @@ int LibRaw::parse_tiff_ifd(int base) { break; } - parse_minolta(j = get4() + base); - fseek(ifp, j, SEEK_SET); + + { + INT64 jj = get4() + base; + parse_minolta(jj); + fseek(ifp, jj, SEEK_SET); + } parse_tiff_ifd(base); break; case 0xc640: // 50752 @@ -1662,12 +1704,15 @@ int LibRaw::parse_tiff_ifd(int base) fseek(ifp, save, SEEK_SET); } if (sony_length && sony_length < 10240000 && - (buf = (unsigned *)malloc(sony_length))) + (buf = (unsigned *)calloc(sony_length, 1))) { fseek(ifp, sony_offset, SEEK_SET); - fread(buf, sony_length, 1, ifp); - sony_decrypt(buf, sony_length / 4, 1, sony_key); - parseSonySR2((uchar *)buf, sony_offset, sony_length, nonDNG); + int items = fread(buf, 1, sony_length, ifp); + if (items == sony_length) + { + sony_decrypt(buf, sony_length / 4, 1, sony_key); + parseSonySR2((uchar *)buf, sony_offset, sony_length, nonDNG); + } free(buf); } for (i = 0; i < colors && i < 4; i++) @@ -1683,14 +1728,14 @@ int LibRaw::parse_tiff_ifd(int base) cam_mul[3] = 0; FORCC if (fabs(asn[c]) > 0.0001) - cam_mul[c] = 1 / asn[c]; + cam_mul[c] = float(1. / asn[c]); } if (!use_cm) - FORCC if (fabs(cc[c][c]) > 0.0001) pre_mul[c] /= cc[c][c]; + FORCC if (fabs(cc[c][c]) > 0.0001) pre_mul[c] /= float(cc[c][c]); return 0; } -int LibRaw::parse_tiff(int _base) +int LibRaw::parse_tiff(INT64 _base) { INT64 base = _base; int doff; @@ -1817,9 +1862,9 @@ void LibRaw::apply_tiff() (libraw_internal_data.unpacker_data.dng_frames[q] >> 8) & 0xff; arr[q].ifdi = libraw_internal_data.unpacker_data.dng_frames[q]; arr[q].databits = - tiff_ifd[ifdidx].t_width * tiff_ifd[ifdidx].t_height * - tiff_ifd[ifdidx].samples * tiff_ifd[ifdidx].bps + - (0x100 - + INT64(tiff_ifd[ifdidx].t_width) * INT64(tiff_ifd[ifdidx].t_height) * + INT64(tiff_ifd[ifdidx].samples) * INT64(tiff_ifd[ifdidx].bps) + + INT64(0x100 - (arr[q].ifdi & 0xff)); // add inverted frame # to ensure same // sort order for similar sized frames. if (tiff_ifd[ifdidx].phint == 4) @@ -1956,7 +2001,7 @@ void LibRaw::apply_tiff() { if (tiff_compress == 1) { - if ((raw_width * raw_height * 3) == (tiff_ifd[raw].bytes << 1)) + if ((INT64(raw_width) * INT64(raw_height) * 3LL) == (tiff_ifd[raw].bytes << 1)) { tiff_bps = tiff_ifd[raw].bps = 12; } @@ -1994,21 +2039,20 @@ void LibRaw::apply_tiff() { case 32767: if (!dng_version && - INT64(tiff_ifd[raw].bytes) == INT64(raw_width) * INT64(raw_height)) + tiff_ifd[raw].bytes == INT64(raw_width) * INT64(raw_height)) { tiff_bps = 14; load_raw = &LibRaw::sony_arw2_load_raw; break; } if (!dng_version && !strncasecmp(make, "Sony", 4) && - INT64(tiff_ifd[raw].bytes) == - INT64(raw_width) * INT64(raw_height) * 2LL) + tiff_ifd[raw].bytes == INT64(raw_width) * INT64(raw_height) * 2LL) { tiff_bps = 14; load_raw = &LibRaw::unpacked_load_raw; break; } - if (INT64(tiff_ifd[raw].bytes) * 8LL != + if (tiff_ifd[raw].bytes * 8LL != INT64(raw_width) * INT64(raw_height) * INT64(tiff_bps)) { raw_height += 8; @@ -2030,18 +2074,15 @@ void LibRaw::apply_tiff() break; } // Sony 14-bit uncompressed - if (!dng_version && !strncasecmp(make, "Sony", 4) && - INT64(tiff_ifd[raw].bytes) == - INT64(raw_width) * INT64(raw_height) * 2LL) + if (!dng_version && !strncasecmp(make, "Sony", 4) && + tiff_ifd[raw].bytes == INT64(raw_width) * INT64(raw_height) * 2LL) { tiff_bps = 14; load_raw = &LibRaw::unpacked_load_raw; break; } - if (!dng_version && !strncasecmp(make, "Sony", 4) && - tiff_ifd[raw].samples == 4 && - INT64(tiff_ifd[raw].bytes) == - INT64(raw_width) * INT64(raw_height) * 8LL) // Sony ARQ + if (!dng_version && !strncasecmp(make, "Sony", 4) && tiff_ifd[raw].samples == 4 && + tiff_ifd[raw].bytes == INT64(raw_width) * INT64(raw_height) * 8LL) // Sony ARQ { // maybe to detect ARQ with the following: // if (tiff_ifd[raw].phint == 32892) @@ -2063,13 +2104,10 @@ void LibRaw::apply_tiff() break; } if ((!strncmp(make, "OLYMPUS", 7) || !strncmp(make, "OM Digi", 7) || - (!strncasecmp(make, "CLAUSS", 6) && - !strncasecmp(model, "piX 5oo", 7))) && // 0x5330303539 works here - (INT64(tiff_ifd[raw].bytes) * 2ULL == - INT64(raw_width) * INT64(raw_height) * 3ULL)) + (!strncasecmp(make, "CLAUSS", 6) && !strncasecmp(model, "piX 5oo", 7))) && // 0x5330303539 works here + (tiff_ifd[raw].bytes * 2LL == INT64(raw_width) * INT64(raw_height) * 3LL)) load_flags = 24; - if (!dng_version && INT64(tiff_ifd[raw].bytes) * 5ULL == - INT64(raw_width) * INT64(raw_height) * 8ULL) + if (!dng_version && tiff_ifd[raw].bytes * 5LL == INT64(raw_width) * INT64(raw_height) * 8LL) { load_flags = 81; tiff_bps = 12; @@ -2094,12 +2132,12 @@ void LibRaw::apply_tiff() load_flags = 0; case 16: load_raw = &LibRaw::unpacked_load_raw; - if ((!strncmp(make, "OLYMPUS", 7) || !strncmp(make, "OM Digi", 7) || - (!strncasecmp(make, "CLAUSS", 6) && - !strncasecmp(model, "piX 5oo", 7))) && // 0x5330303539 works here - (INT64(tiff_ifd[raw].bytes) * 7LL > - INT64(raw_width) * INT64(raw_height))) - load_raw = &LibRaw::olympus_load_raw; + if ((!strncmp(make, "OLYMPUS", 7) || !strncmp(make, "OM Digi", 7) || + (!strncasecmp(make, "CLAUSS", 6) && !strncasecmp(model, "piX 5oo", 7))) && // 0x5330303539 works here + (tiff_ifd[raw].bytes * 7LL > INT64(raw_width) * INT64(raw_height))) + { + load_raw = &LibRaw::olympus14_load_raw; + } } break; case 6: @@ -2130,29 +2168,25 @@ void LibRaw::apply_tiff() load_raw = &LibRaw::kodak_262_load_raw; break; case 34713: - if ((INT64(raw_width) + 9LL) / 10LL * 16LL * INT64(raw_height) == - INT64(tiff_ifd[raw].bytes)) + if ((INT64(raw_width) + 9LL) / 10LL * 16LL * INT64(raw_height) == tiff_ifd[raw].bytes) { load_raw = &LibRaw::packed_load_raw; load_flags = 1; } - else if (INT64(raw_width) * INT64(raw_height) * 3LL == - INT64(tiff_ifd[raw].bytes) * 2LL) + else if (INT64(raw_width) * INT64(raw_height) * 3LL == tiff_ifd[raw].bytes * 2LL) { load_raw = &LibRaw::packed_load_raw; if (model[0] == 'N') load_flags = 80; } - else if (INT64(raw_width) * INT64(raw_height) * 3LL == - INT64(tiff_ifd[raw].bytes)) + else if (INT64(raw_width) * INT64(raw_height) * 3LL == tiff_ifd[raw].bytes) { load_raw = &LibRaw::nikon_yuv_load_raw; gamma_curve(1 / 2.4, 12.92, 1, 4095); memset(cblack, 0, sizeof cblack); filters = 0; } - else if (INT64(raw_width) * INT64(raw_height) * 2LL == - INT64(tiff_ifd[raw].bytes)) + else if (INT64(raw_width) * INT64(raw_height) * 2LL == tiff_ifd[raw].bytes) { load_raw = &LibRaw::unpacked_load_raw; load_flags = 4; @@ -2185,15 +2219,14 @@ void LibRaw::apply_tiff() else load_raw = &LibRaw::nikon_load_raw; // fallback } - else if ((((INT64(raw_width) * 3LL / 2LL) + 15LL) / 16LL) * 16LL * - INT64(raw_height) == - INT64(tiff_ifd[raw].bytes)) + else if ((((INT64(raw_width) * 3LL / 2LL) + 15LL) / 16LL) * 16LL * INT64(raw_height) == tiff_ifd[raw].bytes) { load_raw = &LibRaw::nikon_load_padded_packed_raw; load_flags = (((INT64(raw_width) * 3ULL / 2ULL) + 15ULL) / 16ULL) * 16ULL; // bytes per row } - else if ((!strncmp(model, "NIKON Z 9", 9) || !strncmp(model, "NIKON Z 8", 9)) && tiff_ifd[raw].offset) + else if ((!strncmp(model, "NIKON Z 9", 9) || !strncmp(model, "NIKON Z 8", 9) || !strcmp(model, "NIKON Z f")) && + tiff_ifd[raw].offset) { INT64 pos = ftell(ifp); unsigned char cmp[] = "CONTACT_INTOPIX"; // 15 @@ -2231,18 +2264,14 @@ void LibRaw::apply_tiff() break; case 8: break; -#ifdef USE_DNGSDK case 52546: - if (dng_version) - break; /* Compression=9 supported for dng if we compiled with GPR SDK */ - /* Else: fallthrough */ -#endif -#ifdef USE_GPRSDK + if (dng_version) /* DNG 1.7 JPEG XL: if not compiled w/ DNG SDK decoder will return NOT SUPPORTED*/ + break; + // else: fallthrough case 9: if (dng_version) - break; /* Compression=9 supported for dng if we compiled with GPR SDK */ - /* Else: fallthrough */ -#endif + break; /* Compression=9 supported for dng if we compiled with GPR SDK; if NO SDK: decoder will return NOT Supported */ + // else: fallthrough default: is_raw = 0; } @@ -2310,7 +2339,7 @@ void LibRaw::apply_tiff() thumb_width = tiff_ifd[i].t_width; thumb_height = tiff_ifd[i].t_height; thumb_offset = tiff_ifd[i].offset; - thumb_length = tiff_ifd[i].bytes; + thumb_length = unsigned(tiff_ifd[i].bytes); // do we expect >4GB thumbnail? thumb_misc = tiff_ifd[i].bps; thm = i; } @@ -2331,7 +2360,7 @@ void LibRaw::apply_tiff() imgdata.thumbs_list.thumblist[idx].twidth = tiff_ifd[i].t_width; imgdata.thumbs_list.thumblist[idx].theight = tiff_ifd[i].t_height; imgdata.thumbs_list.thumblist[idx].tflip = tiff_ifd[i].t_flip; - imgdata.thumbs_list.thumblist[idx].tlength = tiff_ifd[i].bytes; + imgdata.thumbs_list.thumblist[idx].tlength = unsigned(tiff_ifd[i].bytes); imgdata.thumbs_list.thumblist[idx].tmisc = tiff_ifd[i].bps | (tiff_ifd[i].samples << 5); imgdata.thumbs_list.thumblist[idx].toffset = tiff_ifd[i].offset; imgdata.thumbs_list.thumbcount++; diff --git a/rtengine/libraw/src/postprocessing/aspect_ratio.cpp b/rtengine/libraw/src/postprocessing/aspect_ratio.cpp index e5165e9bf..b12d77a17 100644 --- a/rtengine/libraw/src/postprocessing/aspect_ratio.cpp +++ b/rtengine/libraw/src/postprocessing/aspect_ratio.cpp @@ -30,8 +30,8 @@ void LibRaw::fuji_rotate() return; fuji_width = (fuji_width - 1 + shrink) >> shrink; step = sqrt(0.5); - wide = fuji_width / step; - high = (height - fuji_width) / step; + wide = ushort(fuji_width / step); + high = ushort((height - fuji_width) / step); // All real fuji/rotated images are small, so check against max_raw_memory_mb here is safe if (INT64(wide) * INT64(high) * INT64(sizeof(*img)) > @@ -45,8 +45,8 @@ void LibRaw::fuji_rotate() for (row = 0; row < high; row++) for (col = 0; col < wide; col++) { - ur = r = fuji_width + (row - col) * step; - uc = c = (row + col) * step; + ur = unsigned( r = float(fuji_width + (row - col) * step)); + uc = unsigned( c = float( (row + col) * step)); if (ur > (unsigned)height - 2 || uc > (unsigned)width - 2) continue; fr = r - ur; @@ -54,8 +54,9 @@ void LibRaw::fuji_rotate() pix = image + ur * width + uc; for (i = 0; i < colors; i++) img[row * wide + col][i] = + ushort( (pix[0][i] * (1 - fc) + pix[1][i] * fc) * (1 - fr) + - (pix[width][i] * (1 - fc) + pix[width + 1][i] * fc) * fr; + (pix[width][i] * (1 - fc) + pix[width + 1][i] * fc) * fr); } free(image); @@ -77,33 +78,33 @@ void LibRaw::stretch() RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH, 0, 2); if (pixel_aspect < 1) { - newdim = height / pixel_aspect + 0.5; + newdim = ushort(height / pixel_aspect + 0.5); img = (ushort(*)[4])calloc(width, newdim * sizeof *img); for (rc = row = 0; row < newdim; row++, rc += pixel_aspect) { - frac = rc - (c = rc); + frac = int(rc - double(c = int(rc))); pix0 = pix1 = image[c * width]; if (c + 1 < height) pix1 += width * 4; for (col = 0; col < width; col++, pix0 += 4, pix1 += 4) FORCC img[row * width + col][c] = - pix0[c] * (1 - frac) + pix1[c] * frac + 0.5; + ushort(pix0[c] * (1 - frac) + pix1[c] * frac + 0.5); } height = newdim; } else { - newdim = width * pixel_aspect + 0.5; + newdim = ushort(width * pixel_aspect + 0.5); img = (ushort(*)[4])calloc(height, newdim * sizeof *img); for (rc = col = 0; col < newdim; col++, rc += 1 / pixel_aspect) { - frac = rc - (c = rc); + frac = int(rc - double(c = int(rc))); pix0 = pix1 = image[c]; if (c + 1 < width) pix1 += 4; for (row = 0; row < height; row++, pix0 += width * 4, pix1 += width * 4) FORCC img[row * newdim + col][c] = - pix0[c] * (1 - frac) + pix1[c] * frac + 0.5; + ushort(pix0[c] * (1 - frac) + pix1[c] * frac + 0.5); } width = newdim; } diff --git a/rtengine/libraw/src/postprocessing/dcraw_process.cpp b/rtengine/libraw/src/postprocessing/dcraw_process.cpp index 8b3d77cf6..f34abce5c 100644 --- a/rtengine/libraw/src/postprocessing/dcraw_process.cpp +++ b/rtengine/libraw/src/postprocessing/dcraw_process.cpp @@ -33,6 +33,10 @@ int LibRaw::dcraw_process(void) if (~O.cropbox[2] && ~O.cropbox[3]) no_crop = 0; + for(int c = 0; c < 4; c++) + if (O.aber[c]< 0.001 || O.aber[c] > 1000.f) + O.aber[c] = 1.0; + libraw_decoder_info_t di; get_decoder_info(&di); @@ -155,7 +159,7 @@ int LibRaw::dcraw_process(void) (callbacks.interpolate_xtrans_cb)(this); else if (quality == 0) lin_interpolate(); - else if (quality == 1 || P1.colors > 3) + else if (quality == 1 || P1.colors > 3 || (P1.filters != LIBRAW_XTRANS && P1.filters <= 1000)) vng_interpolate(); else if (quality == 2 && P1.filters > 1000) ppg_interpolate(); @@ -218,7 +222,7 @@ int LibRaw::dcraw_process(void) if (!libraw_internal_data.output_data.histogram) { libraw_internal_data.output_data.histogram = - (int(*)[LIBRAW_HISTOGRAM_SIZE])malloc( + (int(*)[LIBRAW_HISTOGRAM_SIZE])calloc(1, sizeof(*libraw_internal_data.output_data.histogram) * 4); } #ifndef NO_LCMS diff --git a/rtengine/libraw/src/postprocessing/mem_image.cpp b/rtengine/libraw/src/postprocessing/mem_image.cpp index 4c17994df..d1bf9a4e3 100644 --- a/rtengine/libraw/src/postprocessing/mem_image.cpp +++ b/rtengine/libraw/src/postprocessing/mem_image.cpp @@ -119,6 +119,24 @@ libraw_processed_image_t *LibRaw::dcraw_make_mem_thumb(int *errcode) *errcode = 0; return ret; } + else if (T.tformat == LIBRAW_THUMBNAIL_H265 || T.tformat == LIBRAW_THUMBNAIL_JPEGXL) + { + int dsize = T.tlength; + libraw_processed_image_t *ret = (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t) + dsize); + if (!ret) + { + if (errcode) + *errcode = ENOMEM; + return NULL; + } + memset(ret, 0, sizeof(libraw_processed_image_t)); + ret->type = T.tformat == LIBRAW_THUMBNAIL_H265 ? LIBRAW_IMAGE_H265 : LIBRAW_IMAGE_JPEGXL; + ret->data_size = dsize; + memmove(ret->data, T.thumb, dsize); + if (errcode) + *errcode = 0; + return ret; + } else { if (errcode) @@ -177,7 +195,7 @@ int LibRaw::copy_mem_image(void *scan0, int stride, int bgr) if (libraw_internal_data.output_data.histogram) { int perc, val, total, t_white = 0x2000, c; - perc = S.width * S.height * O.auto_bright_thr; + perc = int(S.width * S.height * O.auto_bright_thr); if (IO.fuji_width) perc /= 2; if (!((O.highlight & ~2) || O.no_auto_bright)) @@ -190,7 +208,7 @@ int LibRaw::copy_mem_image(void *scan0, int stride, int bgr) if (t_white < val) t_white = val; } - gamma_curve(O.gamm[0], O.gamm[1], 2, (t_white << 3) / O.bright); + gamma_curve(O.gamm[0], O.gamm[1], 2, int((t_white << 3) / O.bright)); } int s_iheight = S.iheight; diff --git a/rtengine/libraw/src/postprocessing/postprocessing_aux.cpp b/rtengine/libraw/src/postprocessing/postprocessing_aux.cpp index e0fd33521..3120ecd7e 100644 --- a/rtengine/libraw/src/postprocessing/postprocessing_aux.cpp +++ b/rtengine/libraw/src/postprocessing/postprocessing_aux.cpp @@ -53,8 +53,8 @@ void LibRaw::wavelet_denoise() nc++; FORC(nc) { /* denoise R,G1,B,G3 individually */ - for (i = 0; i < size; i++) - fimg[i] = 256 * sqrt((double)(image[i][c] << scale)); + for (i = 0; i < size; i++) + fimg[i] = 256.f * sqrtf((float)(image[i][c] << scale)); for (hpass = lev = 0; lev < 5; lev++) { lpass = size * ((lev & 1) + 1); @@ -62,13 +62,13 @@ void LibRaw::wavelet_denoise() { hat_transform(temp, fimg + hpass + row * iwidth, 1, iwidth, 1 << lev); for (col = 0; col < iwidth; col++) - fimg[lpass + row * iwidth + col] = temp[col] * 0.25; + fimg[lpass + row * iwidth + col] = temp[col] * 0.25f; } for (col = 0; col < iwidth; col++) { hat_transform(temp, fimg + lpass + col, iwidth, iheight, 1 << lev); for (row = 0; row < iheight; row++) - fimg[lpass + row * iwidth + col] = temp[row] * 0.25; + fimg[lpass + row * iwidth + col] = temp[row] * 0.25f; } thold = threshold * noise[lev]; for (i = 0; i < size; i++) @@ -92,7 +92,7 @@ void LibRaw::wavelet_denoise() { /* pull G1 and G3 closer together */ for (row = 0; row < 2; row++) { - mul[row] = 0.125 * pre_mul[FC(row + 1, 0) | 1] / pre_mul[FC(row, 0) | 1]; + mul[row] = 0.125f * pre_mul[FC(row + 1, 0) | 1] / pre_mul[FC(row, 0) | 1]; blk[row] = cblack[FC(row, 0) | 1]; } for (i = 0; i < 4; i++) @@ -112,9 +112,9 @@ void LibRaw::wavelet_denoise() avg = (window[0][col - 1] + window[0][col + 1] + window[2][col - 1] + window[2][col + 1] - blk[~row & 1] * 4) * mul[row & 1] + - (window[1][col] + blk[row & 1]) * 0.5; + (window[1][col] + blk[row & 1]) * 0.5f; avg = avg < 0 ? 0 : sqrt(avg); - diff = sqrt((double)BAYER(row, col)) - avg; + diff = sqrtf((float)BAYER(row, col)) - avg; if (diff < -thold) diff += thold; else if (diff > thold) @@ -287,7 +287,7 @@ void LibRaw::blend_highlights() if ((unsigned)(colors - 3) > 1) return; RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS, 0, 2); - FORCC if (clip > (i = 65535 * pre_mul[c])) clip = i; + FORCC if (clip > (i = int(65535.f * pre_mul[c]))) clip = i; for (row = 0; row < height; row++) for (col = 0; col < width; col++) { @@ -301,17 +301,17 @@ void LibRaw::blend_highlights() } for (i = 0; i < 2; i++) { - FORCC for (lab[i][c] = j = 0; j < colors; j++) lab[i][c] += - trans[colors - 3][c][j] * cam[i][j]; + FORCC for (lab[i][c] = 0, j = 0; j < colors; j++) lab[i][c] += + int(trans[colors - 3][c][j] * cam[i][j]); for (sum[i] = 0, c = 1; c < colors; c++) sum[i] += SQR(lab[i][c]); } chratio = sqrt(sum[1] / sum[0]); for (c = 1; c < colors; c++) lab[0][c] *= chratio; - FORCC for (cam[0][c] = j = 0; j < colors; j++) cam[0][c] += + FORCC for (cam[0][c] = 0, j = 0; j < colors; j++) cam[0][c] += itrans[colors - 3][c][j] * lab[0][j]; - FORCC image[row * width + col][c] = cam[0][c] / colors; + FORCC image[row * width + col][c] = ushort(cam[0][c] / colors); } RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS, 1, 2); } @@ -326,8 +326,8 @@ void LibRaw::recover_highlights() static const signed char dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}}; - grow = pow(2.0, 4 - highlight); - FORC(unsigned(colors)) hsat[c] = 32000 * pre_mul[c]; + grow = powf(2.0f, float(4 - highlight)); + FORC(unsigned(colors)) hsat[c] = int(32000.f * pre_mul[c]); FORC(unsigned(colors)) if(hsat[c]<1) return; @@ -344,7 +344,8 @@ void LibRaw::recover_highlights() for (mrow = 0; mrow < high; mrow++) for (mcol = 0; mcol < wide; mcol++) { - sum = wgt = count = 0; + count = 0; + sum = wgt = 0; for (row = mrow * SCALE; row < (mrow + 1) * SCALE; row++) for (col = mcol * SCALE; col < (mcol + 1) * SCALE; col++) { @@ -359,14 +360,15 @@ void LibRaw::recover_highlights() if (count == SCALE * SCALE) map[mrow * wide + mcol] = sum / wgt; } - for (spread = 32 / grow; spread--;) + for (spread = int(32.f / grow); spread--;) { for (mrow = 0; mrow < high; mrow++) for (mcol = 0; mcol < wide; mcol++) { if (map[mrow * wide + mcol]) continue; - sum = count = 0; + sum = 0; + count = 0; for (d = 0; d < 8; d++) { y = mrow + dir[d][0]; @@ -401,7 +403,7 @@ void LibRaw::recover_highlights() pixel = image[row * width + col]; if (pixel[c] / hsat[c] > 1) { - val = pixel[kc] * map[mrow * wide + mcol]; + val = int(pixel[kc] * map[mrow * wide + mcol]); if (pixel[c] < val) pixel[c] = CLIP(val); } diff --git a/rtengine/libraw/src/postprocessing/postprocessing_utils.cpp b/rtengine/libraw/src/postprocessing/postprocessing_utils.cpp index f944adb4c..07d40e984 100644 --- a/rtengine/libraw/src/postprocessing/postprocessing_utils.cpp +++ b/rtengine/libraw/src/postprocessing/postprocessing_utils.cpp @@ -156,7 +156,7 @@ void LibRaw::scale_colors_loop(float scale_mul[4]) val -= C.cblack[6 + i / S.iwidth % C.cblack[4] * C.cblack[5] + i % S.iwidth % C.cblack[5]]; val -= C.cblack[c]; - val *= scale_mul[c]; + val = int(val * scale_mul[c]); imgdata.image[i][c] = CLIP(val); } } @@ -170,7 +170,7 @@ void LibRaw::scale_colors_loop(float scale_mul[4]) int val = imgdata.image[i][c]; if (!val) continue; val -= C.cblack[c]; - val *= scale_mul[c]; + val = int(val * scale_mul[c]); imgdata.image[i][c] = CLIP(val); } } @@ -182,7 +182,7 @@ void LibRaw::scale_colors_loop(float scale_mul[4]) for (unsigned c = 0; c < 4; c++) { int val = imgdata.image[i][c]; - val *= scale_mul[c]; + val = int(val * scale_mul[c]); imgdata.image[i][c] = CLIP(val); } } diff --git a/rtengine/libraw/src/postprocessing/postprocessing_utils_dcrdefs.cpp b/rtengine/libraw/src/postprocessing/postprocessing_utils_dcrdefs.cpp index cddc292ab..4bd41d410 100644 --- a/rtengine/libraw/src/postprocessing/postprocessing_utils_dcrdefs.cpp +++ b/rtengine/libraw/src/postprocessing/postprocessing_utils_dcrdefs.cpp @@ -59,11 +59,11 @@ void LibRaw::convert_to_rgb() std::vector prof_desc; int i, j, k; prof_desc_len = snprintf(NULL, 0, "%s gamma %g toe slope %g", name[output_color - 1], - floorf(1000.f / gamm[0] + .5f) / 1000.f, floorf(gamm[1] * 1000.0f + .5f) / 1000.f) + + floor(1000. / gamm[0] + .5) / 1000., floor(gamm[1] * 1000.0 + .5) / 1000.) + 1; prof_desc.resize(prof_desc_len); - sprintf(prof_desc.data(), "%s gamma %g toe slope %g", name[output_color - 1], floorf(1000.f / gamm[0] + .5f) / 1000.f, - floorf(gamm[1] * 1000.0f + .5f) / 1000.f); + sprintf(prof_desc.data(), "%s gamma %g toe slope %g", name[output_color - 1], floor(1000. / gamm[0] + .5) / 1000., + floor(gamm[1] * 1000.0 + .5) / 1000.); oprof = (unsigned *)calloc(phead[0], 1); memcpy(oprof, phead, sizeof phead); @@ -88,7 +88,7 @@ void LibRaw::convert_to_rgb() { for (num = k = 0; k < 3; k++) num += LibRaw_constants::xyzd50_srgb[i][k] * inverse[j][k]; - oprof[pbody[j * 3 + 23] / 4 + i + 2] = num * 0x10000 + 0.5; + oprof[pbody[j * 3 + 23] / 4 + i + 2] = unsigned(num * 0x10000 + 0.5); } for (i = 0; i < (int)phead[0] / 4; i++) oprof[i] = htonl(oprof[i]); @@ -97,8 +97,8 @@ void LibRaw::convert_to_rgb() strcpy((char *)oprof + pbody[5] + 12, prof_desc.data()); for (i = 0; i < 3; i++) for (j = 0; j < colors; j++) - for (out_cam[i][j] = k = 0; k < 3; k++) - out_cam[i][j] += out_rgb[output_color - 1][i][k] * rgb_cam[k][j]; + for (out_cam[i][j] = 0.f, k = 0; k < 3; k++) + out_cam[i][j] += float(out_rgb[output_color - 1][i][k] * rgb_cam[k][j]); } convert_to_rgb_loop(out_cam); @@ -156,7 +156,7 @@ void LibRaw::scale_colors() FORC(8) dsum[c] += sum[c]; skip_block:; } - FORC4 if (dsum[c]) pre_mul[c] = dsum[c + 4] / dsum[c]; + FORC4 if (dsum[c]) pre_mul[c] = float(dsum[c + 4] / dsum[c]); } if (use_camera_wb && cam_mul[0] > 0.00001f) { @@ -207,7 +207,7 @@ void LibRaw::scale_colors() if (!highlight) dmax = dmin; if (dmax > 0.00001 && maximum > 0) - FORC4 scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum; + FORC4 scale_mul[c] = (pre_mul[c] /= float(dmax)) * 65535.f / maximum; else FORC4 scale_mul[c] = 1.0; @@ -230,20 +230,24 @@ void LibRaw::scale_colors() img[i] = image[i][c]; for (row = 0; row < iheight; row++) { - ur = fr = (row - iheight * 0.5) * aber[c] + iheight * 0.5; + fr = float((row - iheight * 0.5) * aber[c] + iheight * 0.5); + ur = unsigned(fr); if (ur > (unsigned)iheight - 2) continue; fr -= ur; for (col = 0; col < iwidth; col++) { - uc = fc = (col - iwidth * 0.5) * aber[c] + iwidth * 0.5; + fc = float((col - iwidth * 0.5) * aber[c] + iwidth * 0.5); + uc = unsigned(fc); if (uc > (unsigned)iwidth - 2) continue; fc -= uc; pix = img + ur * iwidth + uc; image[row * iwidth + col][c] = + ushort( (pix[0] * (1 - fc) + pix[1] * fc) * (1 - fr) + - (pix[iwidth] * (1 - fc) + pix[iwidth + 1] * fc) * fr; + (pix[iwidth] * (1 - fc) + pix[iwidth + 1] * fc) * fr + ); } } free(img); @@ -300,8 +304,8 @@ void LibRaw::green_matching() if ((img[j * width + i][3] < maximum * 0.95) && (c1 < maximum * thr) && (c2 < maximum * thr)) { - f = image[j * width + i][3] * m1 / m2; - image[j * width + i][3] = f > 0xffff ? 0xffff : f; + f = float(image[j * width + i][3] * m1 / m2); + image[j * width + i][3] = f > 65535.f ? 0xffff : ushort(f); } } free(img); diff --git a/rtengine/libraw/src/preprocessing/raw2image.cpp b/rtengine/libraw/src/preprocessing/raw2image.cpp index df5ad020d..db4056231 100644 --- a/rtengine/libraw/src/preprocessing/raw2image.cpp +++ b/rtengine/libraw/src/preprocessing/raw2image.cpp @@ -41,6 +41,10 @@ void LibRaw::raw2image_start() break; } + for (int c = 0; c < 4; c++) + if (O.aber[c] < 0.001 || O.aber[c] > 1000.f) + O.aber[c] = 1.0; + // adjust for half mode! IO.shrink = !imgdata.rawdata.color4_image && !imgdata.rawdata.color3_image && @@ -82,15 +86,16 @@ int LibRaw::raw2image(void) } // free and re-allocate image bitmap + int extra = P1.filters ? (P1.filters == 9 ? 6 : 2) : 0; if (imgdata.image) { imgdata.image = (ushort(*)[4])realloc( - imgdata.image, S.iheight * S.iwidth * sizeof(*imgdata.image)); - memset(imgdata.image, 0, S.iheight * S.iwidth * sizeof(*imgdata.image)); + imgdata.image, (S.iheight+extra) * (S.iwidth+extra) * sizeof(*imgdata.image)); + memset(imgdata.image, 0, (S.iheight+extra) * (S.iwidth+extra) * sizeof(*imgdata.image)); } else imgdata.image = - (ushort(*)[4])calloc(S.iheight * S.iwidth, sizeof(*imgdata.image)); + (ushort(*)[4])calloc((S.iheight+extra) * (S.iwidth+extra), sizeof(*imgdata.image)); libraw_decoder_info_t decoder_info; @@ -348,8 +353,8 @@ int LibRaw::raw2image_ex(int do_subtract_black) crop[1] = (crop[1] / 4) * 4; if (!libraw_internal_data.unpacker_data.fuji_layout) { - crop[2] *= sqrt(2.0); - crop[3] /= sqrt(2.0); + crop[2] = int(crop[2] * sqrtf(2.f)); + crop[3] = int(crop[3] / sqrtf(2.f)); } crop[2] = (crop[2] / 4 + 1) * 4; crop[3] = (crop[3] / 4 + 1) * 4; @@ -388,8 +393,9 @@ int LibRaw::raw2image_ex(int do_subtract_black) } } - int alloc_width = S.iwidth; - int alloc_height = S.iheight; + int extra = P1.filters ? (P1.filters == 9 ? 6 : 2) : 0; + int alloc_width = S.iwidth + extra; + int alloc_height = S.iheight + extra; if (IO.fuji_width && do_crop) { diff --git a/rtengine/libraw/src/tables/cameralist.cpp b/rtengine/libraw/src/tables/cameralist.cpp index 86c88894a..366b8cb4a 100644 --- a/rtengine/libraw/src/tables/cameralist.cpp +++ b/rtengine/libraw/src/tables/cameralist.cpp @@ -32,6 +32,13 @@ static const char *static_camera_list[] = { "Apple iPhone 12 Pro Max", "Apple iPhone 13", "Apple iPhone 14", + "Apple iPhone 14 Plus", + "Apple iPhone 14 Pro", + "Apple iPhone 14 Pro Max", + "Apple iPhone 15", + "Apple iPhone 15 Plus", + "Apple iPhone 15 Pro", + "Apple iPhone 15 Pro Max", "Apple QuickTake 100", "Apple QuickTake 150", "Apple QuickTake 200", @@ -146,6 +153,7 @@ static const char *static_camera_list[] = { "Canon EOS RP", "Canon EOS R3", "Canon EOS R5", + "Canon EOS R5 C", "Canon EOS R6", "Canon EOS R6 Mark II", "Canon EOS R7", @@ -354,6 +362,7 @@ static const char *static_camera_list[] = { "FujiFilm X100S", "FujiFilm X100T", "FujiFilm X100V", + "FujiFilm X100VI", "FujiFilm X10", "FujiFilm X20", "FujiFilm X30", @@ -401,6 +410,7 @@ static const char *static_camera_list[] = { "Google Pixel 4a (5G)", "Google Pixel 5", "Google Pixel 7a", + "Google Pixel 8 Pro", #ifdef USE_GPRSDK "GoPro Fusion", "GoPro HERO5", @@ -433,7 +443,9 @@ static const char *static_camera_list[] = { "Hasselblad A6D-100c", // Aerial camera "Hasselblad CFV", "Hasselblad CFV-50", + "Hasselblad CFV-50c", "Hasselblad CFV II 50C", + "Hasselblad CFV-100c", "Hasselblad CFH", "Hasselblad CF-22", "Hasselblad CF-31", @@ -499,7 +511,6 @@ static const char *static_camera_list[] = { "Kodak DCS420", "Kodak DCS460", "Kodak DCS460M", - "Kodak DCS460", "Kodak DCS520C", "Kodak DCS560C", "Kodak DCS620C", @@ -614,6 +625,7 @@ static const char *static_camera_list[] = { "Leica SL (Typ 601)", "Leica SL2", "Leica SL2-S", + "Leica SL3", "Leica T (Typ 701)", "Leica TL", "Leica TL2", @@ -722,6 +734,7 @@ static const char *static_camera_list[] = { "Nikon Z 9 (HE/HE* formats are not supported yet)", "Nikon Z 30", "Nikon Z 50", + "Nikon Z f (HE/HE* formats are not supported yet)", "Nikon Z fc", "Nikon 1 AW1", "Nikon 1 J1", @@ -849,10 +862,12 @@ static const char *static_camera_list[] = { "Olympus TG-4", "Olympus TG-5", "Olympus TG-6", + "Olympus TG-7", "Olympus XZ-1", "Olympus XZ-2", "Olympus XZ-10", "OM Digital Solutions OM-1", + "OM Digital Solutions OM-1 Mark II", "OM Digital Solutions OM-5", "OmniVision 4688", "OmniVision OV5647", @@ -961,6 +976,7 @@ static const char *static_camera_list[] = { "Pentax K110D", "Pentax K200D", "Pentax K2000/K-m", + "Pentax KF", "Pentax KP", "Pentax K-x", "Pentax K-r", @@ -970,7 +986,7 @@ static const char *static_camera_list[] = { "Pentax K-3", "Pentax K-3 Mark II", "Pentax K-3 Mark III", -// "Pentax K-3 Mark III Monochrome", + "Pentax K-3 Mark III Monochrome", "Pentax K-30", "Pentax K-5", "Pentax K-5 II", @@ -1072,6 +1088,8 @@ static const char *static_camera_list[] = { "Samsung Galaxy S10 (SM-G973F)", "Samsung Galaxy S10+ (SM-G975U)", "Samsung Galaxy S22 Ultra (SM-S908B)", + "Samsung Galaxy S23+", + "Samsung Galaxy S23 Ultra", "Samsung NX1", "Samsung NX5", "Samsung NX10", @@ -1165,6 +1183,7 @@ static const char *static_camera_list[] = { "Sony ILCE-7SM3 (A7S III)", "Sony ILCE-9 (A9)", "Sony ILCE-9M2 (A9 II)", + "Sony ILCE-9M3 (A9 III)", "Sony ILCA-68 (A68)", "Sony ILCA-77M2 (A77-II)", "Sony ILCA-99M2 (A99-II)", @@ -1179,6 +1198,7 @@ static const char *static_camera_list[] = { "Sony ILCE-6600", "Sony ILCE-6700", "Sony ILCE-QX1", + "Sony ILX-LR1", "Sony DSC-F828", "Sony DSC-HX95", "Sony DSC-HX99", diff --git a/rtengine/libraw/src/tables/colordata.cpp b/rtengine/libraw/src/tables/colordata.cpp index 08bc5314b..7eca7ad76 100644 --- a/rtengine/libraw/src/tables/colordata.cpp +++ b/rtengine/libraw/src/tables/colordata.cpp @@ -152,7 +152,7 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Canon, "EOS R100", 0, 0, { 8230, -1515, -1032, -4179, 12005, 2454, -649, 2076, 4711 } }, { LIBRAW_CAMERAMAKER_Canon, "EOS R5", 0, 0, - { 9766,-2953,-1254,-4276,12116,2433,-437,1336,5131 } }, + { 9766,-2953,-1254,-4276,12116,2433,-437,1336,5131 } }, // same CMs: "EOS R5", "EOS R5 C" { LIBRAW_CAMERAMAKER_Canon, "EOS R6 Mark II", 0, 0, { 9539, -2795, -1224, -4175, 11998, 2458, -465, 1755,6048 } }, { LIBRAW_CAMERAMAKER_Canon, "EOS R6", 0, 0, @@ -467,8 +467,10 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 10592,-4262,-1008,-3514,11355,2465,-870,2025,6386 } }, { LIBRAW_CAMERAMAKER_Fujifilm, "X100T", 0, 0, { 10592,-4262,-1008,-3514,11355,2465,-870,2025,6386 } }, + { LIBRAW_CAMERAMAKER_Fujifilm, "X100VI", 0, 0, + { 11809,-5358,-1141,-4248,12164,2343,-514,1097,5848 } }, { LIBRAW_CAMERAMAKER_Fujifilm, "X100V", 0, 0, - { 13426,-6334,-1177,-4244,12136,2371,580,1303,5980 } }, + { 13717, -6490, -1154, -4348, 12266, 2335, -690, 1286, 6134 } }, // 20240512 { LIBRAW_CAMERAMAKER_Fujifilm, "X100", 0, 0, { 12161,-4457,-1069,-5034,12874,2400,-795,1724,6904 } }, @@ -494,7 +496,7 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Fujifilm, "X-Pro2", 0, 0, { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } }, { LIBRAW_CAMERAMAKER_Fujifilm, "X-Pro3", 0, 0, - { 13426,-6334,-1177,-4244,12136,2371,580,1303,5980 } }, + { 13426,-6334,-1177,-4244,12136,2371, -580,1303,5980 } }, { LIBRAW_CAMERAMAKER_Fujifilm, "X-A10", 0, 0, { 11540,-4999,-991,-2949,10963,2278,-382,1049,5605} }, @@ -544,11 +546,11 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Fujifilm, "X-T2", 0, 0, // same CMs: X-T2, X-T20 { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } }, { LIBRAW_CAMERAMAKER_Fujifilm, "X-T3", 0, 0, // same CMs: X-T3, X-T30, "X-T30 II" - { 13426,-6334,-1177,-4244,12136,2371,580,1303,5980 } }, // v.2 + { 13426,-6334,-1177,-4244,12136,2371, -580,1303,5980 } }, // v.2 { LIBRAW_CAMERAMAKER_Fujifilm, "X-T4", 0, 0, - { 13426,-6334,-1177,-4244,12136,2371,580,1303,5980 } }, - { LIBRAW_CAMERAMAKER_Fujifilm, "X-T5", 0, 0, - { 11809, -5358, -1141, -4248, 12164, 2343, -514, 1097, 5848 } }, + { 13426,-6334,-1177,-4244,12136,2371,-580,1303,5980 } }, + { LIBRAW_CAMERAMAKER_Fujifilm, "X-T5", 0, 0, + { 11809,-5358,-1141,-4248,12164,2343,-514,1097,5848 } }, { LIBRAW_CAMERAMAKER_GITUP, "G3DUO", 130, 62000, { 8489,-2583,-1036,-8051,15583,2643,-1307,1407,7354 } }, @@ -1032,6 +1034,9 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Nikon, "Z fc", 0, 0, { 11640,-4829,-1079,-5107,13006,2325,-972,1711,7380 } }, + { LIBRAW_CAMERAMAKER_Nikon, "Z f", 0, 0, + { 11607, -4491, -977, -4522, 12460, 2304, -458, 1519, 7616 } }, + { LIBRAW_CAMERAMAKER_Olympus, "AIR A01", 0, 0xfe1, { 8992,-3093,-639,-2563,10721,2122,-437,1270,5473 } }, @@ -1169,7 +1174,7 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Olympus, "TG-4", 0, 0, { 11426,-4159,-1126,-2066,10678,1593,-120,1327,4998 } }, - { LIBRAW_CAMERAMAKER_Olympus, "TG-", 0, 0, // same CMs: TG-5, TG-6 + { LIBRAW_CAMERAMAKER_Olympus, "TG-", 0, 0, // same CMs: TG-5, TG-6, TG-7 { 10899,-3833,-1082,-2112,10736,1575,-267,1452,5269 } }, { LIBRAW_CAMERAMAKER_Olympus, "XZ-10", 0, 0, @@ -1180,12 +1185,12 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 9777,-3483,-925,-2886,11297,1800,-602,1663,5134 } }, { LIBRAW_CAMERAMAKER_Olympus, "OM-1", 0, 0, - { 9488, -3984, -714, -2887, 10945, 2229, -137, 960, 5786 } }, + { 9488, -3984, -714, -2887, 10945, 2229, -137, 960, 5786 } }, { LIBRAW_CAMERAMAKER_Olympus, "OM-5", 0, 0, { 11896, -5110, -1076, -3181, 11378, 2048, -519, 1224, 5166 } }, - { LIBRAW_CAMERAMAKER_OmniVison, "", 16, 0x3ff, + { LIBRAW_CAMERAMAKER_OmniVison, "", 16, 0x3ff, { 12782,-4059,-379,-478,9066,1413,1340,1513,5176 } }, /* DJC */ { LIBRAW_CAMERAMAKER_Pentax, "*istDL2", 0, 0, @@ -1211,8 +1216,10 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 9186,-2678,-907,-8693,16517,2260,-1129,1094,8524 } }, { LIBRAW_CAMERAMAKER_Pentax, "K-m", 0, 0, { 9730,-2989,-970,-8527,16258,2381,-1060,970,8362 } }, + { LIBRAW_CAMERAMAKER_Pentax, "KF", 0, 0, + { 8766,-3149,-747,-3976,11943,2292,-517,1259,5552 } }, { LIBRAW_CAMERAMAKER_Pentax, "KP", 0, 0, - { 7825,-2160,-1403,-4841,13555,1349,-1559,2449,5814 } }, + { 8617,-3228,-1034,-4674,12821,2044,-803,1577,5728 } }, { LIBRAW_CAMERAMAKER_Pentax, "K-x", 0, 0, { 8843,-2837,-625,-5025,12644,2668,-411,1234,7410 } }, { LIBRAW_CAMERAMAKER_Pentax, "K-r", 0, 0, @@ -1237,8 +1244,6 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 8766,-3149,-747,-3976,11943,2292,-517,1259,5552 } }, { LIBRAW_CAMERAMAKER_Pentax, "K-7", 0, 0, { 9142,-2947,-678,-8648,16967,1663,-2224,2898,8615 } }, - { LIBRAW_CAMERAMAKER_Pentax, "KP", 0, 0, - { 8617,-3228,-1034,-4674,12821,2044,-803,1577,5728 } }, { LIBRAW_CAMERAMAKER_Pentax, "K-S1", 0, 0, { 8512,-3211,-787,-4167,11966,2487,-638,1288,6054 } }, { LIBRAW_CAMERAMAKER_Pentax, "K-S2", 0, 0, @@ -1367,7 +1372,7 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } }, {LIBRAW_CAMERAMAKER_Panasonic, "DC-G9M2", 0, 0, - {8325,-3456,-623,-4330,12089,2528,-860,2646,5984}}, + {8325,-3456,-623,-4330,12089,2528,-860,2646,5984}}, { LIBRAW_CAMERAMAKER_Panasonic, "DC-G9", -15, 0, { 7685,-2375,-634,-3687,11700,2249,-748,1546,5111 } }, @@ -1668,14 +1673,17 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 6596,-2079,-562,-4782,13016,1933,-970,1581,5181 } }, { LIBRAW_CAMERAMAKER_Sony, "DSC-RX100", 0, 0, { 8651,-2754,-1057,-3464,12207,1373,-568,1398,4434 } }, + { LIBRAW_CAMERAMAKER_Sony, "DSC-RX10M4", -800, 0, { 7699,-2566,-629,-2967,11270,1928,-378,1286,4807 } }, { LIBRAW_CAMERAMAKER_Sony, "DSC-RX10",0, 0, // same CMs: DSC-RX10, DSC-RX10M2, DSC-RX10M3 { 6679,-1825,-745,-5047,13256,1953,-1580,2422,5183 } }, + { LIBRAW_CAMERAMAKER_Sony, "DSC-RX1RM2", 0, 0, { 6629,-1900,-483,-4618,12349,2550,-622,1381,6514 } }, { LIBRAW_CAMERAMAKER_Sony, "DSC-RX1R", 0, 0, { 6344,-1612,-462,-4863,12477,2681,-865,1786,6899 } }, + { LIBRAW_CAMERAMAKER_Sony, "DSC-RX1", 0, 0, { 6344,-1612,-462,-4863,12477,2681,-865,1786,6899 } }, @@ -1708,6 +1716,8 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 5413,-1162,-365,-5665,13098,2866,-608,1179,8440 } }, { LIBRAW_CAMERAMAKER_Sony, "DSLR-A900", 0, 0, { 5209,-1072,-397,-8845,16120,2919,-1618,1803,8654 } }, + { LIBRAW_CAMERAMAKER_Sony, "DSLR-A", 0, 0, + { 5209,-1072,-397,-8845,16120,2919,-1618,1803,8654 } }, { LIBRAW_CAMERAMAKER_Sony, "ILCA-68", 0, 0, { 6435,-1903,-536,-4722,12449,2550,-663,1363,6517 } }, @@ -1736,10 +1746,10 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 5838,-1430,-246,-3497,11477,2297,-748,1885,5778 } }, { LIBRAW_CAMERAMAKER_Sony, "ILCE-7CR", 0, 0, - { 8200,-2976,-719,-4296,12053,2532,-429,1282,5774 } }, // temp + { 8200,-2976,-719,-4296,12053,2532,-429,1282,5774 } }, { LIBRAW_CAMERAMAKER_Sony, "ILCE-7CM2", 0, 0, - { 7460,-2365,-588,-5687,13442,2474,-624,1156,6584 } }, // temp + { 7460,-2365,-588,-5687,13442,2474,-624,1156,6584 } }, { LIBRAW_CAMERAMAKER_Sony, "ILCE-7C", 0, 0, { 7374,-2389,-551,-5435,13162,2519,-1006,1795,6552 } }, @@ -1750,6 +1760,8 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Sony, "ILCE-7", 0, 0, // same CMs: ILCE-7, ILCE-7M2 { 5271,-712,-347,-6153,13653,2763,-1601,2366,7242 } }, + { LIBRAW_CAMERAMAKER_Sony, "ILCE-9M3", 0, 0, + { 9811,-3908,-752,-3704,11577,2417,-73,950,5980 } }, { LIBRAW_CAMERAMAKER_Sony, "ILCE-9", 0, 0, // same CMs: ILCE-9, ILCE-9M2 { 6389,-1703,-378,-4562,12265,2587,-670,1489,6550 } }, @@ -1765,8 +1777,7 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 7657,-2847,-607,-4083,11966,2389,-684,1418,5844 } }, { LIBRAW_CAMERAMAKER_Sony, "ILCE-6700", 0, 0, { 6972,-2408,-600,-4330,12101,2515,-388,1277,5847 } }, - - { LIBRAW_CAMERAMAKER_Sony, "ILCE", 0, 0, // same CMs: ILCE-3000, ILCE-5000, ILCE-5100, ILCE-6000, ILCE-QX1 + { LIBRAW_CAMERAMAKER_Sony, "ILCE-", 0, 0, // same CMs: ILCE-3000, ILCE-5000, ILCE-5100, ILCE-6000, ILCE-QX1 { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, { LIBRAW_CAMERAMAKER_Sony, "ILME-FX30", 0, 0, @@ -1774,6 +1785,9 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { LIBRAW_CAMERAMAKER_Sony, "ILME-FX3", 0, 0, { 6912, -2127, -469, -4470, 12175, 2587, -398, 1478, 6492 } }, + { LIBRAW_CAMERAMAKER_Sony, "ILX-LR1", 0, 0, + { 8200, -2976, -719, -4296, 12053, 2532, -429, 1282, 5774 } }, // temp, same as for ILCE-7RM5 + { LIBRAW_CAMERAMAKER_Sony, "NEX-5N", 0, 0, { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, { LIBRAW_CAMERAMAKER_Sony, "NEX-5R", 0, 0, @@ -1794,8 +1808,9 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 6129,-1545,-418,-4930,12490,2743,-977,1693,6615 } }, { LIBRAW_CAMERAMAKER_Sony, "NEX-VG900", 0, 0, { 6344,-1612,-462,-4863,12477,2681,-865,1786,6899 } }, - { LIBRAW_CAMERAMAKER_Sony, "NEX", 0, 0, // same CMs: NEX-C3, NEX-F3, NEX-VG20 + { LIBRAW_CAMERAMAKER_Sony, "NEX-", 0, 0, // same CMs: NEX-C3, NEX-F3, NEX-VG20 { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { LIBRAW_CAMERAMAKER_Sony, "SLT-A33", 0, 0, { 6069,-1221,-366,-5221,12779,2734,-1024,2066,6834 } }, { LIBRAW_CAMERAMAKER_Sony, "SLT-A35", 0, 0, @@ -1812,6 +1827,9 @@ int LibRaw::adobe_coeff(unsigned make_idx, const char *t_model, { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, { LIBRAW_CAMERAMAKER_Sony, "SLT-A99", 0, 0, { 6344,-1612,-462,-4863,12477,2681,-865,1786,6899 } }, + { LIBRAW_CAMERAMAKER_Sony, "SLT-A", 0, 0, + { 5986,-1618,-415,-4557,11820,3120,-681,1404,6971 } }, + { LIBRAW_CAMERAMAKER_Sony, "MODEL-NAME", 0, 0, { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, diff --git a/rtengine/libraw/src/utils/curves.cpp b/rtengine/libraw/src/utils/curves.cpp index 58a1436f4..b175f2301 100644 --- a/rtengine/libraw/src/utils/curves.cpp +++ b/rtengine/libraw/src/utils/curves.cpp @@ -32,8 +32,8 @@ void LibRaw::cubic_spline(const int *x_, const int *y_, const int len) y = len + (x = i + (d = i + (c = i + (b = A[0] + i * i)))); for (i = 0; i < len; i++) { - x[i] = x_[i] / 65535.0; - y[i] = y_[i] / 65535.0; + x[i] = float(x_[i]) / 65535.0f; + y[i] = float(y_[i]) / 65535.0f; } for (i = len - 1; i > 0; i--) { @@ -68,7 +68,7 @@ void LibRaw::cubic_spline(const int *x_, const int *y_, const int len) } for (i = 0; i < 0x10000; i++) { - float x_out = (float)(i / 65535.0); + float x_out = (float)(i / 65535.0f); float y_out = 0; for (j = 0; j < len - 1; j++) { @@ -79,13 +79,13 @@ void LibRaw::cubic_spline(const int *x_, const int *y_, const int len) ((y[j + 1] - y[j]) / d[j] - (2 * d[j] * c[j] + c[j + 1] * d[j]) / 6) * v + - (c[j] * 0.5) * v * v + - ((c[j + 1] - c[j]) / (6 * d[j])) * v * v * v; + (c[j] * 0.5f) * v * v + + ((c[j + 1] - c[j]) / (6.f * d[j])) * v * v * v; } } curve[i] = y_out < 0.0 ? 0 - : (y_out >= 1.0 ? 65535 : (ushort)(y_out * 65535.0 + 0.5)); + : (y_out >= 1.0 ? 65535 : (ushort)(y_out * 65535.0f + 0.5f)); } free(A); } @@ -130,13 +130,15 @@ void LibRaw::gamma_curve(double pwr, double ts, int mode, int imax) curve[i] = 0xffff; if ((r = (double)i / imax) < 1) curve[i] = + ushort( 0x10000 * (mode ? (r < g[3] ? r * g[1] : (g[0] ? pow(r, g[0]) * (1 + g[4]) - g[4] : log(r) * g[2] + 1)) : (r < g[2] ? r / g[1] : (g[0] ? pow((r + g[4]) / (1 + g[4]), 1 / g[0]) - : exp((r - 1) / g[2])))); + : exp((r - 1) / g[2])))) + ); } } diff --git a/rtengine/libraw/src/utils/decoder_info.cpp b/rtengine/libraw/src/utils/decoder_info.cpp index 3abc35e9b..aafba28bf 100644 --- a/rtengine/libraw/src/utils/decoder_info.cpp +++ b/rtengine/libraw/src/utils/decoder_info.cpp @@ -81,7 +81,7 @@ int LibRaw::get_decoder_info(libraw_decoder_info_t *d_info) else if (load_raw == &LibRaw::canon_sraw_load_raw) { d_info->decoder_name = "canon_sraw_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_TRYRAWSPEED3; + //d_info->decoder_flags = LIBRAW_DECODER_TRYRAWSPEED3; } else if (load_raw == &LibRaw::crxLoadRaw) { @@ -204,7 +204,7 @@ int LibRaw::get_decoder_info(libraw_decoder_info_t *d_info) else if (load_raw == &LibRaw::panasonic_load_raw) { d_info->decoder_name = "panasonic_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_TRYRAWSPEED | LIBRAW_DECODER_TRYRAWSPEED; + d_info->decoder_flags = LIBRAW_DECODER_TRYRAWSPEED | LIBRAW_DECODER_TRYRAWSPEED3; } else if (load_raw == &LibRaw::panasonicC6_load_raw) { @@ -219,10 +219,10 @@ int LibRaw::get_decoder_info(libraw_decoder_info_t *d_info) { d_info->decoder_name = "panasonicC8_load_raw()"; } - else if (load_raw == &LibRaw::olympus_load_raw) + else if (load_raw == &LibRaw::olympus14_load_raw) { - d_info->decoder_name = "olympus_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_TRYRAWSPEED | LIBRAW_DECODER_TRYRAWSPEED3;; + d_info->decoder_flags = 0; + d_info->decoder_name = "olympus14_load_raw()"; } else if (load_raw == &LibRaw::minolta_rd175_load_raw) { diff --git a/rtengine/libraw/src/utils/init_close_utils.cpp b/rtengine/libraw/src/utils/init_close_utils.cpp index fffab4de6..db0fccf64 100644 --- a/rtengine/libraw/src/utils/init_close_utils.cpp +++ b/rtengine/libraw/src/utils/init_close_utils.cpp @@ -52,6 +52,7 @@ LibRaw::LibRaw(unsigned int flags) : memmgr(1024) ? NULL : &default_data_callback; callbacks.exif_cb = NULL; // no default callback + callbacks.makernotes_cb = NULL; callbacks.pre_identify_cb = NULL; callbacks.post_identify_cb = NULL; callbacks.pre_subtractblack_cb = callbacks.pre_scalecolors_cb = @@ -305,15 +306,13 @@ void LibRaw::recycle() #ifdef USE_DNGSDK if (dngnegative) { - dng_negative *ng = (dng_negative *)dngnegative; - delete ng; - dngnegative = 0; + clear_dng_negative(dngnegative); + dngnegative = 0; } if(dngimage) { - dng_image *dimage = (dng_image*)dngimage; - delete dimage; - dngimage = 0; + clear_dng_image(dngimage); + dngimage = 0; } #endif #ifdef USE_X3FTOOLS diff --git a/rtengine/libraw/src/utils/open.cpp b/rtengine/libraw/src/utils/open.cpp index a1c1917cf..eaa311a60 100644 --- a/rtengine/libraw/src/utils/open.cpp +++ b/rtengine/libraw/src/utils/open.cpp @@ -168,7 +168,10 @@ int LibRaw::open_file(const char *fname) recycle(); return LIBRAW_UNSUFFICIENT_MEMORY; } - if ((stream->size() > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) && (stream->size() > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE)) + if ((stream->size() > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) + && (stream->size() > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) + && (stream->size() > (INT64)LIBRAW_MAX_CR3_RAW_FILE_SIZE) + ) { delete stream; return LIBRAW_TOO_BIG; @@ -199,7 +202,10 @@ int LibRaw::open_file(const wchar_t *fname) recycle(); return LIBRAW_UNSUFFICIENT_MEMORY; } - if ((stream->size() > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) && (stream->size() > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE)) + if ((stream->size() > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) + && (stream->size() > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) && + (stream->size() > (INT64)LIBRAW_MAX_CR3_RAW_FILE_SIZE) + ) { delete stream; return LIBRAW_TOO_BIG; @@ -218,7 +224,10 @@ int LibRaw::open_buffer(const void *buffer, size_t size) if (!buffer || buffer == (const void *)-1) return LIBRAW_IO_ERROR; - if ((size > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) && (size > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE)) + if ((size > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) + && (size > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) + && (size > (INT64)LIBRAW_MAX_CR3_RAW_FILE_SIZE) + ) return LIBRAW_TOO_BIG; LibRaw_buffer_datastream *stream; @@ -461,7 +470,10 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) return ENOENT; if (!stream->valid()) return LIBRAW_IO_ERROR; - if ((stream->size() > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) && (stream->size() > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE)) + if ((stream->size() > (INT64)LIBRAW_MAX_DNG_RAW_FILE_SIZE) + && (stream->size() > (INT64)LIBRAW_MAX_NONDNG_RAW_FILE_SIZE) && + (stream->size() > (INT64)LIBRAW_MAX_CR3_RAW_FILE_SIZE) + ) return LIBRAW_TOO_BIG; recycle(); @@ -482,15 +494,15 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) // Fuji layout files: either DNG or unpacked_load_raw should be used if (libraw_internal_data.internal_output_params.fuji_width || libraw_internal_data.unpacker_data.fuji_layout) { - if (!imgdata.idata.dng_version && load_raw != &LibRaw::unpacked_load_raw - && load_raw != &LibRaw::unpacked_load_raw_FujiDBP - && load_raw != &LibRaw::unpacked_load_raw_fuji_f700s20 - ) - return LIBRAW_FILE_UNSUPPORTED; + if (!imgdata.idata.dng_version && load_raw != &LibRaw::unpacked_load_raw + && load_raw != &LibRaw::unpacked_load_raw_FujiDBP + && load_raw != &LibRaw::unpacked_load_raw_fuji_f700s20 + ) + return LIBRAW_FILE_UNSUPPORTED; } // Remove unsupported Nikon thumbnails - if (makeIs(LIBRAW_CAMERAMAKER_Nikon) && !strncasecmp(imgdata.idata.model, "Z 8",3) && - imgdata.thumbs_list.thumbcount > 1) + if (makeIs(LIBRAW_CAMERAMAKER_Nikon) && !strncasecmp(imgdata.idata.model, "Z 8", 3) && + imgdata.thumbs_list.thumbcount > 1) { int tgtidx = 0; for (int idx = 0; idx < imgdata.thumbs_list.thumbcount && idx < LIBRAW_THUMBNAIL_MAXCOUNT; idx++) @@ -519,22 +531,22 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) INT64(imgdata.thumbs_list.thumblist[0].theight) * INT64(imgdata.thumbs_list.thumblist[0].tmisc & 0x1f); for (int i = 1; i < tgtidx; i++) { - INT64 imgbits = INT64(imgdata.thumbs_list.thumblist[i].twidth) * - INT64(imgdata.thumbs_list.thumblist[i].theight) * - INT64(imgdata.thumbs_list.thumblist[i].tmisc & 0x1f); - if (imgbits > maximgbits) - { - selidx = i; - maximgbits = imgbits; - } + INT64 imgbits = INT64(imgdata.thumbs_list.thumblist[i].twidth) * + INT64(imgdata.thumbs_list.thumblist[i].theight) * + INT64(imgdata.thumbs_list.thumblist[i].tmisc & 0x1f); + if (imgbits > maximgbits) + { + selidx = i; + maximgbits = imgbits; + } } - libraw_internal_data.internal_data.toffset = imgdata.thumbs_list.thumblist[selidx].toffset; - imgdata.thumbnail.tlength = imgdata.thumbs_list.thumblist[selidx].tlength; - libraw_internal_data.unpacker_data.thumb_format = imgdata.thumbs_list.thumblist[selidx].tformat; - imgdata.thumbnail.twidth = imgdata.thumbs_list.thumblist[selidx].twidth; - imgdata.thumbnail.theight = imgdata.thumbs_list.thumblist[selidx].theight; - libraw_internal_data.unpacker_data.thumb_misc = imgdata.thumbs_list.thumblist[selidx].tmisc; - // find another largest thumb and copy it to single thumbnail data + libraw_internal_data.internal_data.toffset = imgdata.thumbs_list.thumblist[selidx].toffset; + imgdata.thumbnail.tlength = imgdata.thumbs_list.thumblist[selidx].tlength; + libraw_internal_data.unpacker_data.thumb_format = imgdata.thumbs_list.thumblist[selidx].tformat; + imgdata.thumbnail.twidth = imgdata.thumbs_list.thumblist[selidx].twidth; + imgdata.thumbnail.theight = imgdata.thumbs_list.thumblist[selidx].theight; + libraw_internal_data.unpacker_data.thumb_misc = imgdata.thumbs_list.thumblist[selidx].tmisc; + // find another largest thumb and copy it to single thumbnail data } imgdata.thumbs_list.thumbcount = tgtidx > 0 ? tgtidx : 1; } @@ -543,8 +555,8 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) if (imgdata.thumbs_list.thumbcount < LIBRAW_THUMBNAIL_MAXCOUNT) { bool already = false; - if(imgdata.thumbnail.tlength || libraw_internal_data.internal_data.toffset) - for(int i = 0; i < imgdata.thumbs_list.thumbcount; i++) + if (imgdata.thumbnail.tlength || libraw_internal_data.internal_data.toffset) + for (int i = 0; i < imgdata.thumbs_list.thumbcount; i++) if (imgdata.thumbs_list.thumblist[i].toffset == libraw_internal_data.internal_data.toffset && imgdata.thumbs_list.thumblist[i].tlength == imgdata.thumbnail.tlength) { @@ -558,10 +570,10 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) imgdata.thumbs_list.thumblist[idx].tlength = imgdata.thumbnail.tlength; imgdata.thumbs_list.thumblist[idx].tflip = 0xffff; imgdata.thumbs_list.thumblist[idx].tformat = libraw_internal_data.unpacker_data.thumb_format; - imgdata.thumbs_list.thumblist[idx].tmisc = libraw_internal_data.unpacker_data.thumb_misc; + imgdata.thumbs_list.thumblist[idx].tmisc = libraw_internal_data.unpacker_data.thumb_misc; // promote if set imgdata.thumbs_list.thumblist[idx].twidth = imgdata.thumbnail.twidth; - imgdata.thumbs_list.thumblist[idx].theight = imgdata.thumbnail.theight; + imgdata.thumbs_list.thumblist[idx].theight = imgdata.thumbnail.theight; imgdata.thumbs_list.thumbcount++; } } @@ -582,24 +594,24 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) isRIC.cleft = isRIC.ctop = 0xffff; isRIC.cwidth = isRIC.cheight = 0; } - // Wipe out canon incorrect in-camera crop - if (!imgdata.idata.dng_version && makeIs(LIBRAW_CAMERAMAKER_Canon) - && isRIC.cleft == 0 && isRIC.ctop == 0 // non symmetric! - && isRIC.cwidth < (imgdata.sizes.raw_width * 4 / 5)) // less than 80% of sensor width - { - isRIC.cleft = isRIC.ctop = 0xffff; - isRIC.cwidth = isRIC.cheight = 0; - } + // Wipe out canon incorrect in-camera crop + if (!imgdata.idata.dng_version && makeIs(LIBRAW_CAMERAMAKER_Canon) + && isRIC.cleft == 0 && isRIC.ctop == 0 // non symmetric! + && isRIC.cwidth < (imgdata.sizes.raw_width * 4 / 5)) // less than 80% of sensor width + { + isRIC.cleft = isRIC.ctop = 0xffff; + isRIC.cwidth = isRIC.cheight = 0; + } - // Wipe out non-standard WB - if (!imgdata.idata.dng_version && - (makeIs(LIBRAW_CAMERAMAKER_Sony) && !strcmp(imgdata.idata.normalized_model, "DSC-F828")) - && !(imgdata.rawparams.options & LIBRAW_RAWOPTIONS_PROVIDE_NONSTANDARD_WB)) - { - for (int i = 0; i < 4; i++) imgdata.color.cam_mul[i] = (i == 1); - memset(imgdata.color.WB_Coeffs, 0, sizeof(imgdata.color.WB_Coeffs)); - memset(imgdata.color.WBCT_Coeffs, 0, sizeof(imgdata.color.WBCT_Coeffs)); - } + // Wipe out non-standard WB + if (!imgdata.idata.dng_version && + (makeIs(LIBRAW_CAMERAMAKER_Sony) && !strcmp(imgdata.idata.normalized_model, "DSC-F828")) + && !(imgdata.rawparams.options & LIBRAW_RAWOPTIONS_PROVIDE_NONSTANDARD_WB)) + { + for (int i = 0; i < 4; i++) imgdata.color.cam_mul[i] = (i == 1); + memset(imgdata.color.WB_Coeffs, 0, sizeof(imgdata.color.WB_Coeffs)); + memset(imgdata.color.WBCT_Coeffs, 0, sizeof(imgdata.color.WBCT_Coeffs)); + } if (load_raw == &LibRaw::nikon_load_raw) nikon_read_curve(); @@ -622,7 +634,7 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) { if (libraw_internal_data.unpacker_data.pana_encoding == 6 || libraw_internal_data.unpacker_data.pana_encoding == 7 || - libraw_internal_data.unpacker_data.pana_encoding == 8) + libraw_internal_data.unpacker_data.pana_encoding == 8) { for (int i = 0; i < 3; i++) imgdata.color.cblack[i] = @@ -638,17 +650,17 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) if (libraw_internal_data.unpacker_data.pana_encoding == 6) { int rowbytes11 = imgdata.sizes.raw_width / 11 * 16; - int rowbytes14 = imgdata.sizes.raw_width / 14 * 16; - INT64 ds = INT64(libraw_internal_data.unpacker_data.data_size); - if (!ds) - ds = libraw_internal_data.internal_data.input->size() - libraw_internal_data.unpacker_data.data_offset; - if ((imgdata.sizes.raw_width % 11) == 0 && + int rowbytes14 = imgdata.sizes.raw_width / 14 * 16; + INT64 ds = INT64(libraw_internal_data.unpacker_data.data_size); + if (!ds) + ds = libraw_internal_data.internal_data.input->size() - libraw_internal_data.unpacker_data.data_offset; + if ((imgdata.sizes.raw_width % 11) == 0 && (INT64(imgdata.sizes.raw_height) * rowbytes11 == ds)) load_raw = &LibRaw::panasonicC6_load_raw; - else if ((imgdata.sizes.raw_width % 14) == 0 && - (INT64(imgdata.sizes.raw_height) * rowbytes14 == ds)) - load_raw = &LibRaw::panasonicC6_load_raw; - else + else if ((imgdata.sizes.raw_width % 14) == 0 && + (INT64(imgdata.sizes.raw_height) * rowbytes14 == ds)) + load_raw = &LibRaw::panasonicC6_load_raw; + else imgdata.idata.raw_count = 0; // incorrect size } else if (libraw_internal_data.unpacker_data.pana_encoding == 7) @@ -665,38 +677,50 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) } else if (libraw_internal_data.unpacker_data.pana_encoding == 8) { - if (libraw_internal_data.unpacker_data.pana8.stripe_count > 0) - load_raw = &LibRaw::panasonicC8_load_raw; - else - imgdata.idata.raw_count = 0; // incorrect stripes count + if (libraw_internal_data.unpacker_data.pana8.stripe_count > 0) + load_raw = &LibRaw::panasonicC8_load_raw; + else + imgdata.idata.raw_count = 0; // incorrect stripes count } } #define NIKON_14BIT_SIZE(rw, rh) \ - (((unsigned)(ceilf((float)(rw * 7 / 4) / 16.0)) * 16) * rh) + (((unsigned)(ceilf((float)(rw * 7 / 4) / 16.f)) * 16) * rh) + +#define NIKON_14BIT_SIZE3COLOR(rw, rh) ( ceilf(float(rw * 21 / 4)/16.f) * 16 * rh) // Ugly hack, replace with proper data/line size for different // cameras/format when available if (makeIs(LIBRAW_CAMERAMAKER_Nikon) - && (!strncasecmp(imgdata.idata.model, "Z", 1) || !strcasecmp(imgdata.idata.model,"D6")) - && NIKON_14BIT_SIZE(imgdata.sizes.raw_width, imgdata.sizes.raw_height) == - libraw_internal_data.unpacker_data.data_size) + && (!strncasecmp(imgdata.idata.model, "Z", 1) || !strcasecmp(imgdata.idata.model, "D6")) + ) { - load_raw = &LibRaw::nikon_14bit_load_raw; + if (NIKON_14BIT_SIZE(imgdata.sizes.raw_width, imgdata.sizes.raw_height) == + libraw_internal_data.unpacker_data.data_size) + { + load_raw = &LibRaw::nikon_14bit_load_raw; + } + if (NIKON_14BIT_SIZE3COLOR(imgdata.sizes.raw_width, imgdata.sizes.raw_height) == + libraw_internal_data.unpacker_data.data_size) + { + load_raw = &LibRaw::nikon_14bit_load_raw; + imgdata.idata.filters = 0; // 3-color nefx image + } } #undef NIKON_14BIT_SIZE +#undef NIKON_14BIT_SIZE3COLOR // Linear max from 14-bit camera, but on 12-bit data? if (makeIs(LIBRAW_CAMERAMAKER_Sony) && imgdata.color.maximum > 0 && - imgdata.color.linear_max[0] > (long)imgdata.color.maximum && - imgdata.color.linear_max[0] <= (long)imgdata.color.maximum * 4) + imgdata.color.linear_max[0] > imgdata.color.maximum && + imgdata.color.linear_max[0] <= imgdata.color.maximum * 4) for (int c = 0; c < 4; c++) imgdata.color.linear_max[c] /= 4; if (makeIs(LIBRAW_CAMERAMAKER_Canon)) { - if (MN.canon.DefaultCropAbsolute.l != -1) // tag 0x00e0 SensorInfo was parsed + if (!imgdata.idata.dng_version && (MN.canon.DefaultCropAbsolute.l != -1)) // tag 0x00e0 SensorInfo was parsed { if (imgdata.sizes.raw_aspect != LIBRAW_IMAGE_ASPECT_UNKNOWN) { // tag 0x009a AspectInfo was parsed @@ -946,7 +970,7 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) black[c] = imgdata.color.dng_levels.dng_black + imgdata.color.dng_levels.dng_cblack[c]; for (int c = 0; c < imgdata.idata.colors; c++) - delta[c] = imgdata.color.dng_levels.dng_whitelevel[c] - black[c]; + delta[c] = float(imgdata.color.dng_levels.dng_whitelevel[c] - black[c]); float mindelta = delta[0], maxdelta = delta[0]; for (int c = 1; c < imgdata.idata.colors; c++) { @@ -962,7 +986,7 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) imgdata.color.cam_mul[c] /= (delta[c] / maxdelta); imgdata.color.pre_mul[c] /= (delta[c] / maxdelta); } - imgdata.color.maximum = imgdata.color.cblack[0] + maxdelta; + imgdata.color.maximum = unsigned(imgdata.color.cblack[0] + maxdelta); } } } @@ -972,10 +996,20 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) && !strcasecmp(imgdata.idata.normalized_model, "DMC-LX100")) imgdata.sizes.width = 4288; - if (imgdata.idata.dng_version - && makeIs(LIBRAW_CAMERAMAKER_Leica) - && !strcasecmp(imgdata.idata.normalized_model, "SL2")) - imgdata.sizes.height -= 16; + if (imgdata.idata.dng_version && makeIs(LIBRAW_CAMERAMAKER_Leica)) + { + if (!strcasecmp(imgdata.idata.normalized_model, "SL2")) + imgdata.sizes.height -= 16; + else if (!strcasecmp(imgdata.idata.normalized_model, "SL3")) + { + if (imgdata.sizes.raw_width == 9536) + imgdata.sizes.width -= 12; + else if (imgdata.sizes.raw_width == 7424) + imgdata.sizes.width -= 14; + else if (imgdata.sizes.raw_width == 5312) + imgdata.sizes.width -= 18; + } + } if (makeIs(LIBRAW_CAMERAMAKER_Sony) && imgdata.idata.dng_version) @@ -1106,7 +1140,7 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) beta_4 * x * x * x * x)); if (y < 0.) y = 0.; - imgdata.color.curve[i] = (y * 16383.); + imgdata.color.curve[i] = ushort(y * 16383.f); } for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) @@ -1201,7 +1235,7 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) } for(int cnt = 0; cnt < 4; cnt++) imgdata.color.pre_mul[cnt] = - C.WB_Coeffs[LIBRAW_WBI_Daylight][cnt]; + float(C.WB_Coeffs[LIBRAW_WBI_Daylight][cnt]); } // Adjust BL for Panasonic @@ -1266,7 +1300,8 @@ int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) INT64 profile_sz = MIN(INT64(C.profile_length), ID.input->size() - ID.profile_offset); if (profile_sz > 0LL && profile_sz < LIBRAW_MAX_PROFILE_SIZE_MB * 1024LL * 1024LL) { - C.profile = malloc(size_t(profile_sz)); + C.profile = calloc(size_t(profile_sz),1); + C.profile_length = unsigned(profile_sz); ID.input->seek(ID.profile_offset, SEEK_SET); ID.input->read(C.profile, size_t(profile_sz), 1); } diff --git a/rtengine/libraw/src/utils/thumb_utils.cpp b/rtengine/libraw/src/utils/thumb_utils.cpp index 98184e759..f8e4ce5c4 100644 --- a/rtengine/libraw/src/utils/thumb_utils.cpp +++ b/rtengine/libraw/src/utils/thumb_utils.cpp @@ -113,7 +113,7 @@ void LibRaw::kodak_thumb_loader() dmax = C.pre_mul[c]; for (c = 0; c < 3; c++) - scale_mul[c] = (C.pre_mul[c] / dmax) * 65535.0 / C.maximum; + scale_mul[c] = float((C.pre_mul[c] / dmax) * 65535. / C.maximum); scale_mul[3] = scale_mul[1]; size_t size = S.height * S.width; @@ -122,7 +122,7 @@ void LibRaw::kodak_thumb_loader() val = imgdata.image[0][i]; if (!val) continue; - val *= scale_mul[i & 3]; + val = int(val * scale_mul[i & 3]); imgdata.image[0][i] = CLIP(val); } } @@ -177,7 +177,7 @@ void LibRaw::kodak_thumb_loader() { int perc, val, total, t_white = 0x2000, c; - perc = S.width * S.height * 0.01; /* 99th percentile white level */ + perc = int(S.width * S.height * 0.01f); /* 99th percentile white level */ if (IO.fuji_width) perc /= 2; if (!((O.highlight & ~2) || O.no_auto_bright)) @@ -190,7 +190,7 @@ void LibRaw::kodak_thumb_loader() if (t_white < val) t_white = val; } - gamma_curve(O.gamm[0], O.gamm[1], 2, (t_white << 3) / O.bright); + gamma_curve(O.gamm[0], O.gamm[1], 2, int((t_white << 3) / O.bright)); } libraw_internal_data.output_data.histogram = save_hist; @@ -320,6 +320,9 @@ int LibRaw::dcraw_thumb_writer(const char *fname) { switch (T.tformat) { + case LIBRAW_THUMBNAIL_JPEGXL: + fwrite(T.thumb, 1, T.tlength, tfp); + break; case LIBRAW_THUMBNAIL_JPEG: jpeg_thumb_writer(tfp, T.thumb, T.tlength); break; diff --git a/rtengine/libraw/src/utils/utils_dcraw.cpp b/rtengine/libraw/src/utils/utils_dcraw.cpp index fd3085cc1..5ac64fe28 100644 --- a/rtengine/libraw/src/utils/utils_dcraw.cpp +++ b/rtengine/libraw/src/utils/utils_dcraw.cpp @@ -154,8 +154,8 @@ void LibRaw::romm_coeff(float romm_cam[3][3]) for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) - for (cmatrix[i][j] = k = 0; k < 3; k++) - cmatrix[i][j] += rgb_romm[i][k] * romm_cam[k][j]; + for (cmatrix[i][j] = 0.f, k = 0; k < 3; k++) + cmatrix[i][j] += float(rgb_romm[i][k] * romm_cam[k][j]); } void LibRaw::remove_zeroes() @@ -297,7 +297,7 @@ void LibRaw::cam_xyz_coeff(float _rgb_cam[3][4], double cam_xyz[4][3]) { for (j = 0; j < 3; j++) cam_rgb[i][j] /= num; - pre_mul[i] = 1 / num; + pre_mul[i] = float(1.0 / num); } else { @@ -309,11 +309,11 @@ void LibRaw::cam_xyz_coeff(float _rgb_cam[3][4], double cam_xyz[4][3]) pseudoinverse(cam_rgb, inverse, colors); for (i = 0; i < 3; i++) for (j = 0; j < colors && j < 4; j++) - _rgb_cam[i][j] = inverse[j][i]; + _rgb_cam[i][j] = float(inverse[j][i]); } -void LibRaw::tiff_get(unsigned base, unsigned *tag, unsigned *type, - unsigned *len, unsigned *save) +void LibRaw::tiff_get(INT64 base, unsigned *tag, unsigned *type, + unsigned *len, INT64 *save) { #ifdef LIBRAW_IOSPACE_CHECK INT64 pos = ftell(ifp); @@ -324,7 +324,7 @@ void LibRaw::tiff_get(unsigned base, unsigned *tag, unsigned *type, *tag = get2(); *type = get2(); *len = get4(); - *save = ftell(ifp) + 4; + *save = ftell(ifp) + 4LL; if (*len * tagtype_dataunit_bytes[(*type <= LIBRAW_EXIFTAG_TYPE_IFD8) ? *type : 0] > 4) - fseek(ifp, get4() + base, SEEK_SET); + fseek(ifp, INT64(get4()) + base, SEEK_SET); } diff --git a/rtengine/libraw/src/utils/utils_libraw.cpp b/rtengine/libraw/src/utils/utils_libraw.cpp index dc81d0dd3..33464cb34 100644 --- a/rtengine/libraw/src/utils/utils_libraw.cpp +++ b/rtengine/libraw/src/utils/utils_libraw.cpp @@ -21,13 +21,13 @@ extern "C" { #endif - void default_data_callback(void *, const char *file, const int offset) + void default_data_callback(void *, const char *file, const INT64 offset) { if (offset < 0) fprintf(stderr, "%s: Unexpected end of file\n", file ? file : "unknown file"); else - fprintf(stderr, "%s: data corrupted at %d\n", + fprintf(stderr, "%s: data corrupted at %lld\n", file ? file : "unknown file", offset); } const char *libraw_strerror(int e) @@ -581,7 +581,7 @@ int LibRaw::stread(char *buf, size_t len, LibRaw_abstract_datastream *fp) return 0; } -int LibRaw::find_ifd_by_offset(int o) +int LibRaw::find_ifd_by_offset(INT64 o) { for(unsigned i = 0; i < libraw_internal_data.identify_data.tiff_nifds && i < LIBRAW_IFD_MAXCOUNT; i++) if(tiff_ifd[i].offset == o) @@ -617,8 +617,8 @@ int LibRaw::adjust_to_raw_inset_crop(unsigned mask, float maxcrop) { int adjindex = -1; - int limwidth = S.width * maxcrop; - int limheight = S.height * maxcrop; + int limwidth = int(S.width * maxcrop); + int limheight = int(S.height * maxcrop); for(int i = 1; i >= 0; i--) if (mask & (1<> 8) & 0xff); @@ -685,12 +685,13 @@ checked_buffer_t::checked_buffer_t(short ord, unsigned char *dd, int ss) : _orde ushort checked_buffer_t::sget2(int offset) { + checkoffset(offset); checkoffset(offset + 2); return libraw_sget2_static(_order, _data + offset); } void checked_buffer_t::checkoffset(int off) { - if (off >= _len) + if (off >= _len || off < 0) throw LIBRAW_EXCEPTION_IO_EOF; } unsigned char checked_buffer_t::operator[](int idx) @@ -700,12 +701,14 @@ unsigned char checked_buffer_t::operator[](int idx) } unsigned checked_buffer_t::sget4(int offset) { + checkoffset(offset); checkoffset(offset + 4); return libraw_sget4_static(_order, _data + offset); } double checked_buffer_t::sgetreal(int type, int offset) { + checkoffset(offset); int sz = libraw_tagtype_dataunit_bytes(type); checkoffset(offset + sz); return libraw_sgetreal_static(_order, type, _data + offset); @@ -718,7 +721,7 @@ int checked_buffer_t::tiff_sget(unsigned save, INT64 *tag_offset, unsigned *tag_ { // abnormal, tag buffer overrun return -1; } - int pos = *tag_offset; + int pos = int(*tag_offset); *tag_id = sget2(pos); pos += 2; *tag_type = sget2(pos); diff --git a/rtengine/libraw/src/write/apply_profile.cpp b/rtengine/libraw/src/write/apply_profile.cpp index 9c8a9fd98..d2a0fec13 100644 --- a/rtengine/libraw/src/write/apply_profile.cpp +++ b/rtengine/libraw/src/write/apply_profile.cpp @@ -48,7 +48,7 @@ void LibRaw::apply_profile(const char *input, const char *output) { fread(&size, 4, 1, fp); fseek(fp, 0, SEEK_SET); - oprof = (unsigned *)malloc(size = ntohl(size)); + oprof = (unsigned *)calloc(size = ntohl(size),1); fread(oprof, 1, size, fp); fclose(fp); if (!(hOutProfile = cmsOpenProfileFromMem(oprof, size))) diff --git a/rtengine/libraw/src/write/file_write.cpp b/rtengine/libraw/src/write/file_write.cpp index ce9073d13..40c997382 100644 --- a/rtengine/libraw/src/write/file_write.cpp +++ b/rtengine/libraw/src/write/file_write.cpp @@ -53,7 +53,7 @@ void LibRaw::tiff_set(struct tiff_hdr *th, ushort *ntag, ushort tag, tt->tag = tag; } -#define TOFF(ptr) ((char *)(&(ptr)) - (char *)th) +#define TOFF(ptr) int((char *)(&(ptr)) - (char *)th) void LibRaw::tiff_head(struct tiff_hdr *th, int full) { @@ -67,9 +67,9 @@ void LibRaw::tiff_head(struct tiff_hdr *th, int full) th->rat[0] = th->rat[2] = 300; th->rat[1] = th->rat[3] = 1; FORC(6) th->rat[4 + c] = 1000000; - th->rat[4] *= shutter; - th->rat[6] *= aperture; - th->rat[8] *= focal_len; + th->rat[4] = int(shutter * 1000000.f); + th->rat[6] = int(aperture * 1000000.f); + th->rat[8] = int(focal_len * 1000000.f); strncpy(th->t_desc, desc, 512); strncpy(th->t_make, make, 64); strncpy(th->t_model, model, 64); @@ -117,7 +117,7 @@ void LibRaw::tiff_head(struct tiff_hdr *th, int full) tiff_set(th, &th->ntag, 34675, 7, psize, sizeof *th); tiff_set(th, &th->nexif, 33434, 5, 1, TOFF(th->rat[4])); tiff_set(th, &th->nexif, 33437, 5, 1, TOFF(th->rat[6])); - tiff_set(th, &th->nexif, 34855, 3, 1, iso_speed); + tiff_set(th, &th->nexif, 34855, 3, 1, int(iso_speed)); tiff_set(th, &th->nexif, 37386, 5, 1, TOFF(th->rat[8])); if (gpsdata[1]) { @@ -163,7 +163,7 @@ void LibRaw::write_ppm_tiff() int c, row, col, soff, rstep, cstep; int perc, val, total, t_white = 0x2000; - perc = width * height * auto_bright_thr; + perc = int(width * height * auto_bright_thr); if (fuji_width) perc /= 2; @@ -176,7 +176,7 @@ void LibRaw::write_ppm_tiff() if (t_white < val) t_white = val; } - gamma_curve(gamm[0], gamm[1], 2, (t_white << 3) / bright); + gamma_curve(gamm[0], gamm[1], 2, int((t_white << 3) / bright)); iheight = height; iwidth = width; if (flip & 4) diff --git a/rtengine/libraw/src/x3f/x3f_parse_process.cpp b/rtengine/libraw/src/x3f/x3f_parse_process.cpp index e704d069f..738234c07 100644 --- a/rtengine/libraw/src/x3f/x3f_parse_process.cpp +++ b/rtengine/libraw/src/x3f/x3f_parse_process.cpp @@ -140,17 +140,17 @@ void LibRaw::parse_x3f() for (i = 0; i < (int)PL->num_properties; i++) { char name[100], value[100]; - int noffset = (P[i].name - datap); - int voffset = (P[i].value - datap); + int noffset = int(P[i].name - datap); + int voffset = int(P[i].value - datap); if (noffset < 0 || noffset > (int)maxitems || voffset < 0 || voffset > (int)maxitems) throw LIBRAW_EXCEPTION_IO_CORRUPT; - int maxnsize = maxitems - (P[i].name - datap); - int maxvsize = maxitems - (P[i].value - datap); + int maxnsize = maxitems - int(P[i].name - datap); + int maxvsize = maxitems - int(P[i].value - datap); utf2char(P[i].name, name, MIN(maxnsize, ((int)sizeof(name)))); utf2char(P[i].value, value, MIN(maxvsize, ((int)sizeof(value)))); if (!strcmp(name, "ISO")) - imgdata.other.iso_speed = atoi(value); + imgdata.other.iso_speed = float(atoi(value)); if (!strcmp(name, "CAMMANUF")) strcpy(imgdata.idata.make, value); if (!strcmp(name, "CAMMODEL")) @@ -162,24 +162,24 @@ void LibRaw::parse_x3f() if (!strcmp(name, "TIME")) imgdata.other.timestamp = atoi(value); if (!strcmp(name, "SHUTTER")) - imgdata.other.shutter = atof(value); + imgdata.other.shutter = float(atof(value)); if (!strcmp(name, "APERTURE")) - imgdata.other.aperture = atof(value); + imgdata.other.aperture = float(atof(value)); if (!strcmp(name, "FLENGTH")) - imgdata.other.focal_len = atof(value); + imgdata.other.focal_len = float(atof(value)); if (!strcmp(name, "FLEQ35MM")) - imgdata.lens.makernotes.FocalLengthIn35mmFormat = atof(value); + imgdata.lens.makernotes.FocalLengthIn35mmFormat = float(atof(value)); if (!strcmp(name, "IMAGERTEMP")) - MN.common.SensorTemperature = atof(value); + MN.common.SensorTemperature = float(atof(value)); if (!strcmp(name, "LENSARANGE")) { char *sp; imgdata.lens.makernotes.MaxAp4CurFocal = - imgdata.lens.makernotes.MinAp4CurFocal = atof(value); + imgdata.lens.makernotes.MinAp4CurFocal = float(atof(value)); sp = strrchr(value, ' '); if (sp) { - imgdata.lens.makernotes.MinAp4CurFocal = atof(sp); + imgdata.lens.makernotes.MinAp4CurFocal = float(atof(sp)); if (imgdata.lens.makernotes.MaxAp4CurFocal > imgdata.lens.makernotes.MinAp4CurFocal) my_swap(float, imgdata.lens.makernotes.MaxAp4CurFocal, @@ -189,12 +189,11 @@ void LibRaw::parse_x3f() if (!strcmp(name, "LENSFRANGE")) { char *sp; - imgdata.lens.makernotes.MinFocal = imgdata.lens.makernotes.MaxFocal = - atof(value); + imgdata.lens.makernotes.MinFocal = imgdata.lens.makernotes.MaxFocal = float(atof(value)); sp = strrchr(value, ' '); if (sp) { - imgdata.lens.makernotes.MaxFocal = atof(sp); + imgdata.lens.makernotes.MaxFocal = float(atof(sp)); if ((imgdata.lens.makernotes.MaxFocal + 0.17f) < imgdata.lens.makernotes.MinFocal) my_swap(float, imgdata.lens.makernotes.MaxFocal, @@ -243,7 +242,7 @@ void LibRaw::parse_x3f() strcpy(imgdata.idata.make, "SIGMA"); #if 1 // Try to find model number in first 2048 bytes; - int pos = libraw_internal_data.internal_data.input->tell(); + INT64 pos = libraw_internal_data.internal_data.input->tell(); libraw_internal_data.internal_data.input->seek(0, SEEK_SET); unsigned char buf[2048]; libraw_internal_data.internal_data.input->read(buf, 2048, 1); @@ -309,7 +308,7 @@ void LibRaw::parse_x3f() } } -INT64 LibRaw::x3f_thumb_size() +int LibRaw::x3f_thumb_size() { try { @@ -321,7 +320,7 @@ INT64 LibRaw::x3f_thumb_size() DE = x3f_get_thumb_plain(x3f); if (!DE) return -1; - int64_t p = x3f_load_data_size(x3f, DE); + int32_t p = x3f_load_data_size(x3f, DE); if (p < 0 || p > 0xffffffff) return -1; return p; @@ -473,23 +472,23 @@ void LibRaw::x3f_dpq_interpolate_af(int xstep, int ystep, int scale) pixel0[1] = imgdata.color.black; float pixf0 = pixf[0]; if (pixf0 < imgdata.color.black) - pixf0 = imgdata.color.black; + pixf0 = float(imgdata.color.black); float pixf1 = pixf[1]; if (pixf1 < imgdata.color.black) - pixf1 = imgdata.color.black; + pixf1 = float(imgdata.color.black); - pixel0[0] = CLIP( + pixel0[0] = uint16_t(CLIP( ((float(pixf0 - imgdata.color.black) * multip + imgdata.color.black) + ((pixel0[0] - imgdata.color.black) * 3.75 + imgdata.color.black)) / 2, - 16383); - pixel0[1] = CLIP( + 16383)); + pixel0[1] = uint16_t(CLIP( ((float(pixf1 - imgdata.color.black) * multip + imgdata.color.black) + ((pixel0[1] - imgdata.color.black) * 3.75 + imgdata.color.black)) / 2, - 16383); + 16383)); // pixel0[1] = float(pixf[1]-imgdata.color.black)*multip + // imgdata.color.black; } @@ -536,8 +535,8 @@ void LibRaw::x3f_dpq_interpolate_af_sd(int xstart, int ystart, int xend, sumG += row0[(x + xx) * 3 + 1]; } } - pixel00[0] = sumR / 8.f; - pixel00[1] = sumG / 8.f; + pixel00[0] = uint16_t(sumR / 8.f); + pixel00[1] = uint16_t(sumG / 8.f); if (scale == 2) { @@ -559,8 +558,8 @@ void LibRaw::x3f_dpq_interpolate_af_sd(int xstart, int ystart, int xend, } if (_cnt > 1.0) { - pixel0B[2] = sumG0 / _cnt; - pixel1B[2] = sumG1 / _cnt; + pixel0B[2] = uint16_t(sumG0 / _cnt); + pixel1B[2] = uint16_t(sumG1 / _cnt); } } diff --git a/rtengine/libraw/src/x3f/x3f_utils_patched.cpp b/rtengine/libraw/src/x3f/x3f_utils_patched.cpp index 6b20b9074..7f61da552 100644 --- a/rtengine/libraw/src/x3f/x3f_utils_patched.cpp +++ b/rtengine/libraw/src/x3f/x3f_utils_patched.cpp @@ -391,7 +391,7 @@ static x3f_huffman_t *new_huffman(x3f_huffman_t **HUFP) { x3f_directory_entry_t *DE = &DS->directory_entry[d]; x3f_directory_entry_header_t *DEH = &DE->header; - uint32_t save_dir_pos; + INT64 save_dir_pos; /* Read the directory entry info */ GET4(DE->input.offset); @@ -1174,7 +1174,7 @@ static void simple_decode_row(x3f_info_t * /*I*/, x3f_directory_entry_t *DE, case X3F_IMAGE_THUMB_HUFFMAN: c_fix = (int8_t)c[color] > 0 ? c[color] : 0; - HUF->rgb8.data[3 * (row * ID->columns + col) + color] = c_fix; + HUF->rgb8.data[3 * (row * ID->columns + col) + color] = uint8_t(c_fix); break; default: /* TODO: Shouldn't this be treated as a fatal error? */ @@ -1215,7 +1215,7 @@ static void read_data_set_offset(x3f_info_t *I, x3f_directory_entry_t *DE, static uint32_t read_data_block(void **data, x3f_info_t *I, x3f_directory_entry_t *DE, uint32_t footer) { - INT64 fpos = I->input.file->tell(); + uint32_t fpos = (I->input.file->tell() & 0x7fffffffU) ; uint32_t size = DE->input.size + DE->input.offset - fpos - footer; if (fpos + size > I->input.file->size()) @@ -1231,8 +1231,9 @@ static uint32_t read_data_block(void **data, x3f_info_t *I, static uint32_t data_block_size(void ** /*data*/, x3f_info_t *I, x3f_directory_entry_t *DE, uint32_t footer) { + uint32_t fpos = (I->input.file->tell() & 0x7fffffffU); uint32_t size = - DE->input.size + DE->input.offset - I->input.file->tell() - footer; + DE->input.size + DE->input.offset - fpos - footer; return size; } @@ -1481,7 +1482,7 @@ static void x3f_load_pixmap(x3f_info_t *I, x3f_directory_entry_t *DE) x3f_load_image_verbatim(I, DE); } -static uint32_t x3f_load_pixmap_size(x3f_info_t *I, x3f_directory_entry_t *DE) +static int32_t x3f_load_pixmap_size(x3f_info_t *I, x3f_directory_entry_t *DE) { return x3f_load_image_verbatim_size(I, DE); } @@ -1491,7 +1492,7 @@ static void x3f_load_jpeg(x3f_info_t *I, x3f_directory_entry_t *DE) x3f_load_image_verbatim(I, DE); } -static uint32_t x3f_load_jpeg_size(x3f_info_t *I, x3f_directory_entry_t *DE) +static int32_t x3f_load_jpeg_size(x3f_info_t *I, x3f_directory_entry_t *DE) { return x3f_load_image_verbatim_size(I, DE); } @@ -1536,7 +1537,7 @@ static void x3f_load_image(x3f_info_t *I, x3f_directory_entry_t *DE) } // Used only for thumbnail size estimation -static uint32_t x3f_load_image_size(x3f_info_t *I, x3f_directory_entry_t *DE) +static int32_t x3f_load_image_size(x3f_info_t *I, x3f_directory_entry_t *DE) { x3f_directory_entry_header_t *DEH = &DE->header; x3f_image_data_t *ID = &DEH->data_subsection.image_data; @@ -2074,7 +2075,7 @@ static void x3f_load_camf(x3f_info_t *I, x3f_directory_entry_t *DE) return X3F_OK; } -/* extern */ int64_t x3f_load_data_size(x3f_t *x3f, x3f_directory_entry_t *DE) +/* extern */ int32_t x3f_load_data_size(x3f_t *x3f, x3f_directory_entry_t *DE) { x3f_info_t *I = &x3f->info;