diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | demo/Makefile.am | 12 | ||||
-rw-r--r-- | demo/cfa.cpp | 113 | ||||
-rw-r--r-- | demo/thumb.cpp | 147 | ||||
-rw-r--r-- | include/libopenraw/Makefile.am | 1 | ||||
-rw-r--r-- | include/libopenraw/consts.h | 9 | ||||
-rw-r--r-- | include/libopenraw/ifd.h | 41 | ||||
-rw-r--r-- | include/libopenraw/rawfile.h | 5 | ||||
-rw-r--r-- | include/libopenraw/thumbnails.h | 2 | ||||
-rw-r--r-- | include/libopenraw/types.h | 4 | ||||
-rw-r--r-- | lib/Makefile.am | 3 | ||||
-rw-r--r-- | lib/capi/bitmapdata.cpp | 10 | ||||
-rw-r--r-- | lib/capi/capi.cpp | 126 | ||||
-rw-r--r-- | lib/capi/capi.h | 7 | ||||
-rw-r--r-- | lib/capi/cfapattern.cpp | 16 | ||||
-rw-r--r-- | lib/capi/debug.cpp | 20 | ||||
-rw-r--r-- | lib/capi/ifd.cpp | 52 | ||||
-rw-r--r-- | lib/capi/metadata.cpp | 5 | ||||
-rw-r--r-- | lib/capi/rawdata.cpp | 17 | ||||
-rw-r--r-- | lib/capi/rawfile.cpp | 44 | ||||
-rw-r--r-- | test/Makefile.am | 8 | ||||
-rw-r--r-- | testsuite/testsuite.cpp | 204 | ||||
-rw-r--r-- | testsuite/testsuite.h | 30 |
23 files changed, 408 insertions, 470 deletions
diff --git a/configure.ac b/configure.ac index 76b2ca8..08fb3cd 100644 --- a/configure.ac +++ b/configure.ac @@ -185,6 +185,8 @@ AM_CONDITIONAL(DEBUG, test x$debug = xtrue) AC_LANG_CPLUSPLUS AC_LANG_COMPILER_REQUIRE +AX_APPEND_COMPILE_FLAGS([-fvisibility=hidden]) + AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option], [ ax_compiler_flags_test="-Werror=unknown-warning-option" ], [ diff --git a/demo/Makefile.am b/demo/Makefile.am index dfdfc85..1ac9bd2 100644 --- a/demo/Makefile.am +++ b/demo/Makefile.am @@ -4,14 +4,14 @@ if BUILD_GNOME_SUPPORT GNOME_BINARIES = gdk pixbufload endif -noinst_PROGRAMS = extensions thumb thumbc cfa ccfa ppmload $(GNOME_BINARIES) +noinst_PROGRAMS = extensions thumbc ccfa ppmload $(GNOME_BINARIES) AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib \ -I$(top_srcdir)/gnome/include \ @LIBGDKPIXBUF_CFLAGS@ @BOOST_CPPFLAGS@ -LIBOPENRAW_LIBS = ../lib/libopenraw.la -LIBOPENRAWGNOME_LIBS = ../gnome/libopenrawgnome.la \ +LIBOPENRAW_LIBS = $(top_builddir)/lib/libopenraw.la +LIBOPENRAWGNOME_LIBS = $(top_builddir)/gnome/libopenrawgnome.la \ @LIBGDKPIXBUF_LIBS@ extensions_SOURCES = extensions.cpp @@ -20,12 +20,6 @@ extensions_LDADD = $(LIBOPENRAW_LIBS) thumbc_SOURCES = thumbc.c thumbc_LDADD = $(LIBOPENRAW_LIBS) -thumb_SOURCES = thumb.cpp -thumb_LDADD = $(LIBOPENRAW_LIBS) - -cfa_SOURCES = cfa.cpp -cfa_LDADD = $(LIBOPENRAW_LIBS) - ccfa_SOURCES = ccfa.c ccfa_LDADD = $(LIBOPENRAW_LIBS) diff --git a/demo/cfa.cpp b/demo/cfa.cpp deleted file mode 100644 index fb7348e..0000000 --- a/demo/cfa.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * libopenraw - cfa.cpp - * - * Copyright (C) 2007-2018 Hubert Figuiere - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include <stdio.h> -#include <stdlib.h> - -#include <iostream> -#include <memory> -#include <libopenraw/libopenraw.h> -#include <libopenraw/debug.h> - -#include "thumbnail.hpp" -#include "rawfile.hpp" -#include "rawdata.hpp" - -using OpenRaw::Thumbnail; - -int -main(int argc, char** argv) -{ - bool keepCompressed = false; - if (argc < 2) { - std::cerr << "missing parameter" << std::endl; - return 1; - } - - int c; - do { - c = getopt(argc, argv, "r"); - if(c != -1) { - if(c == 'r') { - keepCompressed = true; - } - } - } while(c != -1); - - OpenRaw::init(); - or_debug_set_level(DEBUG2); - FILE * f; - size_t written_size; - - std::unique_ptr<OpenRaw::RawFile> raw_file(OpenRaw::RawFile::newRawFile(argv[optind])); - - OpenRaw::RawData rdata; - uint32_t options = (keepCompressed ? OR_OPTIONS_DONT_DECOMPRESS : 0); - raw_file->getRawData(rdata, options); - - if(keepCompressed) { - std::cout << "keep compressed" << std::endl; - } - std::cout << "data size = " << rdata.size() << std::endl; - std::cout << "data type = " << rdata.dataType() << std::endl; - - if(!keepCompressed && rdata.dataType() == OR_DATA_TYPE_RAW) { - f = fopen("image.pgm", "wb"); - fprintf(f, "P5\n"); - fprintf(f, "%d %d\n", rdata.width(), rdata.height()); - fprintf(f, "%d\n", (1 << rdata.bpc()) - 1); - } - else { - f = fopen("image.cfa", "wb"); - } - // Convert data byte order to most significant byte first - if(rdata.bpc() == 16) { - uint8_t* buf = (uint8_t*)malloc(rdata.size()); - uint8_t* p = buf; - uint16_t* n = reinterpret_cast<uint16_t*>(rdata.data()); - for(size_t i = 0; i < rdata.size() / 2; i++) { - unsigned char lo = n[i] & 0xFF; - unsigned char hi = n[i] >> 8; - p[i * 2] = hi; - p[i * 2 + 1] = lo; - } - written_size = fwrite(buf, 1, rdata.size(), f); - free(buf); - } - else { - written_size = fwrite(rdata.data(), 1, rdata.size(), f); - } - if (written_size != rdata.size()) { - printf("short write\n"); - } - fclose(f); - - return 0; -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)) - indent-tabs-mode:nil - fill-column:80 - End: -*/ diff --git a/demo/thumb.cpp b/demo/thumb.cpp deleted file mode 100644 index e755c0c..0000000 --- a/demo/thumb.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * libopenraw - thumb.cpp - * - * Copyright (C) 2006-2016 Hubert Figuiere - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - - -#include <stdio.h> - -#include <iostream> -#include <memory> -#include <libopenraw/libopenraw.h> -#include <libopenraw/debug.h> - -#include "thumbnail.hpp" -#include "rawfile.hpp" - -using OpenRaw::Thumbnail; - -void writeThumbnail(const std::unique_ptr<Thumbnail> & thumb, - const char* basename) -{ - FILE * f; - size_t s; - auto thumbnailFormat = thumb->dataType(); - std::cerr << "thumb data size =" << thumb->size() << std::endl; - std::cerr << "thumb data type =" << thumbnailFormat << std::endl; - - std::string filename = basename; - - switch (thumbnailFormat) { - case OR_DATA_TYPE_JPEG: - filename += ".jpg"; - break; - case OR_DATA_TYPE_PIXMAP_8RGB: - filename += ".ppm"; - break; - default: - std::cerr << "invalid format" << std::endl; - return; - } - - f = fopen(filename.c_str(), "wb"); - if(thumbnailFormat == OR_DATA_TYPE_PIXMAP_8RGB) { - fprintf(f, "P6\n"); - fprintf(f, "%u\n%u\n", thumb->width(), thumb->height()); - fprintf(f, "%d\n", 255); - } - - s = fwrite(thumb->data(), 1, thumb->size(), f); - if(s != thumb->size()) { - std::cerr << "short write of " << s << " bytes\n"; - } - fclose(f); -} - - -int -main(int argc, char** argv) -{ - ::or_error err = OR_ERROR_NONE; - - if (argc < 2) { - std::cerr << "missing parameter" << std::endl; - return 1; - } - - OpenRaw::init(); - or_debug_set_level(DEBUG2); - - { - std::unique_ptr<OpenRaw::RawFile> raw_file( - OpenRaw::RawFile::newRawFile(argv[1])); - if(!raw_file) - { - std::cout << "Unable to open raw file.\n"; - return 1; - } - auto list = raw_file->listThumbnailSizes(); - for(auto elem : list) - { - std::cout << "found " << elem << " pixels\n"; - } - } - - { - std::unique_ptr<Thumbnail> thumb( - Thumbnail::getAndExtractThumbnail(argv[1], - 160, err)); - if (thumb != NULL) { - writeThumbnail(thumb, "thumb"); - } - else { - std::cerr << "error = " << err << std::endl; - } - } - - { - std::unique_ptr<Thumbnail> thumb( - Thumbnail::getAndExtractThumbnail(argv[1], - 640, err)); - if (thumb != NULL) { - writeThumbnail(thumb, "thumbl"); - } - else { - std::cerr << "error = " << err << std::endl; - } - } - - { - std::unique_ptr<Thumbnail> thumb( - Thumbnail::getAndExtractThumbnail(argv[1], - 2048, err)); - if (thumb != NULL) { - writeThumbnail(thumb, "preview"); - } - else { - std::cerr << "error = " << err << std::endl; - } - } - - return 0; -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)) - indent-tabs-mode:nil - fill-column:80 - End: -*/ diff --git a/include/libopenraw/Makefile.am b/include/libopenraw/Makefile.am index 1ff128e..cc3e875 100644 --- a/include/libopenraw/Makefile.am +++ b/include/libopenraw/Makefile.am @@ -10,4 +10,5 @@ libopenraw_HEADERS = libopenraw.h \ rawfile.h exif.h metadata.h \ demosaic.h bitmapdata.h \ cfapattern.h \ + ifd.h \ $(NULL) diff --git a/include/libopenraw/consts.h b/include/libopenraw/consts.h index 24daad3..e720711 100644 --- a/include/libopenraw/consts.h +++ b/include/libopenraw/consts.h @@ -128,6 +128,15 @@ typedef uint32_t or_rawfile_typeid; /** get the camera from the %or_rawfile_typeid */ #define OR_GET_FILE_TYPEID_CAMERA(ftypeid) (ftypeid & 0xffff) +/** Index for the Ifd inside a RAW file. + */ +typedef enum { + OR_IFD_MAIN = 0, + OR_IFD_CFA = 1, + OR_IFD_EXIF = 2, + OR_IFD_MAKERNOTE = 3, +} or_ifd_index; + #ifdef __cplusplus } #endif diff --git a/include/libopenraw/ifd.h b/include/libopenraw/ifd.h new file mode 100644 index 0000000..5d3e5d1 --- /dev/null +++ b/include/libopenraw/ifd.h @@ -0,0 +1,41 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ +/* + * libopenraw - ifd.h + * + * Copyright (C) 2019 Hubert Figuière + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <libopenraw/types.h> +#include <libopenraw/consts.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** Count the number of tags in the ifd + */ +int32_t +or_ifd_count_tags(ORIfdDirRef rawfile); + +const char* +or_ifd_get_makernote_id(ORIfdDirRef ifd); + +#ifdef __cplusplus +} +#endif diff --git a/include/libopenraw/rawfile.h b/include/libopenraw/rawfile.h index 5652203..6d55f72 100644 --- a/include/libopenraw/rawfile.h +++ b/include/libopenraw/rawfile.h @@ -1,7 +1,7 @@ /* * libopenraw - rawfile.h * - * Copyright (C) 2007-2016 Hubert Figuiere + * Copyright (C) 2007-2019 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -132,6 +132,9 @@ or_rawfile_get_colour_matrix_origin(ORRawFileRef rawfile); ORConstMetaValueRef or_rawfile_get_metavalue(ORRawFileRef rawfile, int32_t meta_index); +ORIfdDirRef +or_rawfile_get_ifd(ORRawFileRef rawfile, or_ifd_index ifd); + #if 0 /** Get the metadata out of the raw file as XMP * @param rawfile the rawfile object diff --git a/include/libopenraw/thumbnails.h b/include/libopenraw/thumbnails.h index 18153d7..7c7c659 100644 --- a/include/libopenraw/thumbnails.h +++ b/include/libopenraw/thumbnails.h @@ -35,8 +35,6 @@ extern "C" { #endif - typedef struct _Thumbnail *ORThumbnailRef; - /** Extract thumbnail for raw file * @param filename the file name to extract from * @param preferred_size preferred thumnail size diff --git a/include/libopenraw/types.h b/include/libopenraw/types.h index 873de99..b35039a 100644 --- a/include/libopenraw/types.h +++ b/include/libopenraw/types.h @@ -1,7 +1,7 @@ /* * libopenraw - types.h * - * Copyright (C) 2006-2016 Hubert Figuiere + * Copyright (C) 2006-2019 Hubert Figuiere * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -27,5 +27,7 @@ typedef struct _RawFile *ORRawFileRef; typedef struct _RawData *ORRawDataRef; typedef struct _BitmapData *ORBitmapDataRef; +typedef struct _Thumbnail *ORThumbnailRef; +typedef struct _IfdDir *ORIfdDirRef; #endif diff --git a/lib/Makefile.am b/lib/Makefile.am index 283c490..a4cb6e1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -25,6 +25,7 @@ TESTS = teststream check_PROGRAMS = teststream teststream_SOURCES = io/teststream.cpp +teststream_LDFLAGS = -static teststream_LDADD = libopenraw.la noinst_HEADERS = \ @@ -109,6 +110,7 @@ libopenraw_la_SOURCES = \ io/memstream.cpp io/memstream.hpp \ io/file.cpp io/file.hpp \ io/io_private.h \ + capi/capi.h \ capi/capi.cpp \ capi/debug.cpp \ capi/rawdata.cpp \ @@ -116,6 +118,7 @@ libopenraw_la_SOURCES = \ capi/bitmapdata.cpp \ capi/cfapattern.cpp \ capi/metadata.cpp \ + capi/ifd.cpp \ mp4/mp4parse.h \ trace.cpp \ bititerator.hpp \ diff --git a/lib/capi/bitmapdata.cpp b/lib/capi/bitmapdata.cpp index 74abbed..9039ff7 100644 --- a/lib/capi/bitmapdata.cpp +++ b/lib/capi/bitmapdata.cpp @@ -1,7 +1,7 @@ /* * libopenraw - bitmapdata.cpp * - * Copyright (C) 2007-2015 Hubert Figuiere + * Copyright (C) 2007-2019 Hubert Figuiere * Copyright (C) 2008 Novell Inc. * * This library is free software: you can redistribute it and/or @@ -27,18 +27,21 @@ #include <libopenraw/types.h> #include <libopenraw/consts.h> +#include "capi.h" #include "bitmapdata.hpp" using OpenRaw::BitmapData; extern "C" { +API_EXPORT ORBitmapDataRef or_bitmapdata_new(void) { BitmapData *bitmapdata = new BitmapData(); return reinterpret_cast<ORBitmapDataRef>(bitmapdata); } +API_EXPORT or_error or_bitmapdata_release(ORBitmapDataRef bitmapdata) { if (bitmapdata == NULL) { @@ -48,21 +51,25 @@ or_error or_bitmapdata_release(ORBitmapDataRef bitmapdata) return OR_ERROR_NONE; } +API_EXPORT or_data_type or_bitmapdata_format(ORBitmapDataRef bitmapdata) { return reinterpret_cast<BitmapData *>(bitmapdata)->dataType(); } +API_EXPORT void *or_bitmapdata_data(ORBitmapDataRef bitmapdata) { return reinterpret_cast<BitmapData *>(bitmapdata)->data(); } +API_EXPORT size_t or_bitmapdata_data_size(ORBitmapDataRef bitmapdata) { return reinterpret_cast<BitmapData *>(bitmapdata)->size(); } +API_EXPORT void or_bitmapdata_dimensions(ORBitmapDataRef bitmapdata, uint32_t *x, uint32_t *y) { @@ -75,6 +82,7 @@ void or_bitmapdata_dimensions(ORBitmapDataRef bitmapdata, uint32_t *x, } } +API_EXPORT uint32_t or_bitmapdata_bpc(ORBitmapDataRef bitmapdata) { return reinterpret_cast<BitmapData *>(bitmapdata)->bpc(); diff --git a/lib/capi/capi.cpp b/lib/capi/capi.cpp index bee42a1..7f544c1 100644 --- a/lib/capi/capi.cpp +++ b/lib/capi/capi.cpp @@ -1,7 +1,8 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ /* * libopenraw - capi.cpp * - * Copyright (C) 2005-2015 Hubert Figuiere + * Copyright (C) 2005-2019 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -28,75 +29,72 @@ #include <libopenraw/consts.h> #include <libopenraw/thumbnails.h> +#include "capi.h" #include "thumbnail.hpp" using OpenRaw::Thumbnail; extern "C" { -// typedef struct Thumbnail _Thumbnail; - - or_error or_get_extract_thumbnail(const char* _filename, - uint32_t _preferred_size, - ORThumbnailRef *_thumb) - { - or_error ret = OR_ERROR_NONE; - - Thumbnail ** pThumbnail = reinterpret_cast<Thumbnail **>(_thumb); - *pThumbnail = Thumbnail::getAndExtractThumbnail(_filename, - _preferred_size, ret); - return ret; - } - - - ORThumbnailRef or_thumbnail_new(void) - { - Thumbnail *thumb = new Thumbnail(); - return reinterpret_cast<ORThumbnailRef>(thumb); - } - - - or_error - or_thumbnail_release(ORThumbnailRef thumb) - { - if (thumb == NULL) { - return OR_ERROR_NOTAREF; - } - delete reinterpret_cast<Thumbnail *>(thumb); - return OR_ERROR_NONE; - } - - - or_data_type - or_thumbnail_format(ORThumbnailRef thumb) - { - return reinterpret_cast<Thumbnail *>(thumb)->dataType(); - } - - - void * - or_thumbnail_data(ORThumbnailRef thumb) - { - return reinterpret_cast<Thumbnail *>(thumb)->data(); - } - - size_t - or_thumbnail_data_size(ORThumbnailRef thumb) - { - return reinterpret_cast<Thumbnail *>(thumb)->size(); - } - - void - or_thumbnail_dimensions(ORThumbnailRef thumb, uint32_t *width, uint32_t *height) - { - Thumbnail* t = reinterpret_cast<Thumbnail *>(thumb); - if (width != NULL) { - *width = t->width(); - } - if (height != NULL) { - *height = t->height(); - } - } +API_EXPORT +or_error or_get_extract_thumbnail(const char* _filename, + uint32_t _preferred_size, + ORThumbnailRef *_thumb) +{ + or_error ret = OR_ERROR_NONE; + + Thumbnail ** pThumbnail = reinterpret_cast<Thumbnail **>(_thumb); + *pThumbnail = Thumbnail::getAndExtractThumbnail(_filename, + _preferred_size, ret); + return ret; +} + +API_EXPORT +ORThumbnailRef or_thumbnail_new(void) +{ + Thumbnail *thumb = new Thumbnail(); + return reinterpret_cast<ORThumbnailRef>(thumb); +} + +API_EXPORT or_error +or_thumbnail_release(ORThumbnailRef thumb) +{ + if (thumb == nullptr) { + return OR_ERROR_NOTAREF; + } + delete reinterpret_cast<Thumbnail *>(thumb); + return OR_ERROR_NONE; +} + +API_EXPORT or_data_type +or_thumbnail_format(ORThumbnailRef thumb) +{ + return reinterpret_cast<Thumbnail *>(thumb)->dataType(); +} + +API_EXPORT void * +or_thumbnail_data(ORThumbnailRef thumb) +{ + return reinterpret_cast<Thumbnail *>(thumb)->data(); +} + +API_EXPORT size_t +or_thumbnail_data_size(ORThumbnailRef thumb) +{ + return reinterpret_cast<Thumbnail *>(thumb)->size(); +} + +API_EXPORT void +or_thumbnail_dimensions(ORThumbnailRef thumb, uint32_t *width, uint32_t *height) +{ + Thumbnail* t = reinterpret_cast<Thumbnail *>(thumb); + if (width != nullptr) { + *width = t->width(); + } + if (height != nullptr) { + *height = t->height(); + } +} } diff --git a/lib/capi/capi.h b/lib/capi/capi.h new file mode 100644 index 0000000..d4088b8 --- /dev/null +++ b/lib/capi/capi.h @@ -0,0 +1,7 @@ + + +#pragma once +/* + * Use this to mark a symbol to be exported + */ +#define API_EXPORT __attribute__ ((visibility ("default"))) diff --git a/lib/capi/cfapattern.cpp b/lib/capi/cfapattern.cpp index 2e98c63..9864cbc 100644 --- a/lib/capi/cfapattern.cpp +++ b/lib/capi/cfapattern.cpp @@ -1,7 +1,8 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ /* * libopenraw - cfapattern.cpp * - * Copyright (C) 2016 Hubert Figuiere + * Copyright (C) 2016-2019 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -20,22 +21,23 @@ #include <libopenraw/cfapattern.h> +#include "capi.h" #include "cfapattern.hpp" extern "C" { -or_cfa_pattern +API_EXPORT or_cfa_pattern or_cfapattern_get_type(ORCfaPatternRef pattern) { - return reinterpret_cast<const OpenRaw::CfaPattern*>(pattern)->patternType(); + return reinterpret_cast<const OpenRaw::CfaPattern*>(pattern)->patternType(); } -const uint8_t * +API_EXPORT const uint8_t * or_cfapattern_get_pattern(ORCfaPatternRef pattern, uint16_t *count) { - // TODO check parameters. - auto pat = reinterpret_cast<const OpenRaw::CfaPattern*>(pattern); - return pat->patternPattern(*count); + // TODO check parameters. + auto pat = reinterpret_cast<const OpenRaw::CfaPattern*>(pattern); + return pat->patternPattern(*count); } } diff --git a/lib/capi/debug.cpp b/lib/capi/debug.cpp index 654b678..d971799 100644 --- a/lib/capi/debug.cpp +++ b/lib/capi/debug.cpp @@ -1,7 +1,8 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ /* - * libopenraw - debug.h + * libopenraw - debug.cpp * - * Copyright (C) 2006 Hubert Figuiere + * Copyright (C) 2006-2019 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -21,21 +22,20 @@ * @brief C API for Debug */ - - #include <libopenraw/debug.h> + +#include "capi.h" #include "trace.hpp" #ifdef __cplusplus extern "C" { #endif - - - void or_debug_set_level(debug_level lvl) - { - Debug::Trace::setDebugLevel(lvl); - } +API_EXPORT +void or_debug_set_level(debug_level lvl) +{ + Debug::Trace::setDebugLevel(lvl); +} #ifdef __cplusplus diff --git a/lib/capi/ifd.cpp b/lib/capi/ifd.cpp new file mode 100644 index 0000000..d1c8a21 --- /dev/null +++ b/lib/capi/ifd.cpp @@ -0,0 +1,52 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ +/* + * libopenraw - ifd.cpp + * + * Copyright (C) 2019 Hubert Figuière + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#include <libopenraw/types.h> + +#include "capi.h" + +#include "makernotedir.hpp" + +extern "C" { +/** check pointer validity */ +#define CHECK_PTR(p, r) \ + if (p == nullptr) { \ + return r; \ + } + +API_EXPORT int32_t +or_ifd_count_tags(ORIfdDirRef ifd) +{ + auto pifd = reinterpret_cast<OpenRaw::Internals::IfdDir*>(ifd); + CHECK_PTR(ifd, -1); + return pifd->numTags(); +} + +API_EXPORT const char* +or_ifd_get_makernote_id(ORIfdDirRef ifd) +{ + auto pifd = reinterpret_cast<OpenRaw::Internals::IfdDir*>(ifd); + CHECK_PTR(ifd, nullptr); + auto maker_note = dynamic_cast<OpenRaw::Internals::MakerNoteDir*>(pifd); + return maker_note->getId().c_str(); +} + +} diff --git a/lib/capi/metadata.cpp b/lib/capi/metadata.cpp index 067d82f..605c53a 100644 --- a/lib/capi/metadata.cpp +++ b/lib/capi/metadata.cpp @@ -1,7 +1,7 @@ /* * libopenraw - metadata.cpp * - * Copyright (C) 2016 Hubert Figuiere + * Copyright (C) 2016-2019 Hubert Figuiere * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -20,11 +20,12 @@ #include <libopenraw/metadata.h> +#include "capi.h" #include "metavalue.hpp" extern "C" { -const char* +API_EXPORT const char* or_metavalue_get_string(ORConstMetaValueRef value, uint32_t idx) { // TODO validate parameters diff --git a/lib/capi/rawdata.cpp b/lib/capi/rawdata.cpp index da9efb1..f704e43 100644 --- a/lib/capi/rawdata.cpp +++ b/lib/capi/rawdata.cpp @@ -1,3 +1,4 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ /* * libopenraw - rawdata.cpp * @@ -27,6 +28,7 @@ #include <libopenraw/consts.h> #include <libopenraw/types.h> +#include "capi.h" #include "rawdata.hpp" #include "cfapattern.hpp" @@ -45,6 +47,7 @@ extern "C" { return r; \ } +API_EXPORT or_error or_get_extract_rawdata(const char *filename, uint32_t options, ORRawDataRef *rawdata) { @@ -55,12 +58,14 @@ or_error or_get_extract_rawdata(const char *filename, uint32_t options, return ret; } +API_EXPORT ORRawDataRef or_rawdata_new(void) { RawData *rawdata = new RawData(); return reinterpret_cast<ORRawDataRef>(rawdata); } +API_EXPORT or_error or_rawdata_release(ORRawDataRef rawdata) { if (rawdata == NULL) { @@ -70,21 +75,25 @@ or_error or_rawdata_release(ORRawDataRef rawdata) return OR_ERROR_NONE; } +API_EXPORT or_data_type or_rawdata_format(ORRawDataRef rawdata) { return reinterpret_cast<RawData *>(rawdata)->dataType(); } +API_EXPORT void *or_rawdata_data(ORRawDataRef rawdata) { return reinterpret_cast<RawData *>(rawdata)->data(); } +API_EXPORT size_t or_rawdata_data_size(ORRawDataRef rawdata) { return reinterpret_cast<RawData *>(rawdata)->size(); } +API_EXPORT void or_rawdata_dimensions(ORRawDataRef rawdata, uint32_t *width, uint32_t *height) { @@ -97,6 +106,7 @@ void or_rawdata_dimensions(ORRawDataRef rawdata, uint32_t *width, } } +API_EXPORT or_error or_rawdata_get_active_area(ORRawDataRef rawdata, uint32_t *x, uint32_t *y, uint32_t *width, uint32_t *height) { @@ -116,26 +126,31 @@ or_error or_rawdata_get_active_area(ORRawDataRef rawdata, uint32_t *x, uint32_t return OR_ERROR_NONE; } +API_EXPORT uint32_t or_rawdata_bpc(ORRawDataRef rawdata) { return reinterpret_cast<RawData *>(rawdata)->bpc(); } +API_EXPORT or_cfa_pattern or_rawdata_get_cfa_pattern_type(ORRawDataRef rawdata) { return reinterpret_cast<RawData *>(rawdata)->cfaPattern()->patternType(); } +API_EXPORT ORCfaPatternRef or_rawdata_get_cfa_pattern(ORRawDataRef rawdata) { return reinterpret_cast<ORCfaPatternRef>(reinterpret_cast<RawData *>(rawdata)->cfaPattern()); } +API_EXPORT uint32_t or_rawdata_get_compression(ORRawDataRef rawdata) { return reinterpret_cast<RawData *>(rawdata)->compression(); } +API_EXPORT or_error or_rawdata_get_levels(ORRawDataRef rawdata, uint16_t *black, uint16_t *white) { @@ -149,6 +164,7 @@ or_error or_rawdata_get_levels(ORRawDataRef rawdata, uint16_t *black, return OR_ERROR_NONE; } +API_EXPORT const double *or_rawdata_get_colour_matrix(ORRawDataRef rawdata, uint32_t index, uint32_t *size) { @@ -180,6 +196,7 @@ const double *or_rawdata_get_colour_matrix(ORRawDataRef rawdata, uint32_t index, return matrix; } +API_EXPORT or_error or_rawdata_get_rendered_image(ORRawDataRef rawdata, ORBitmapDataRef bitmapdata, uint32_t options) diff --git a/lib/capi/rawfile.cpp b/lib/capi/rawfile.cpp index df6b388..edfbc16 100644 --- a/lib/capi/rawfile.cpp +++ b/lib/capi/rawfile.cpp @@ -1,7 +1,8 @@ +/* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */ /* * libopenraw - rawfile.cpp * - * Copyright (C) 2007-2016 Hubert Figuiere + * Copyright (C) 2007-2019 Hubert Figuiere * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -29,7 +30,9 @@ #include <libopenraw/thumbnails.h> #include <libopenraw/types.h> +#include "capi.h" #include "rawfile.hpp" +#include "ifddir.hpp" namespace OpenRaw { class BitmapData; @@ -41,6 +44,7 @@ using OpenRaw::RawFile; using OpenRaw::RawData; using OpenRaw::BitmapData; using OpenRaw::Thumbnail; +using OpenRaw::Internals::IfdDir; extern "C" { @@ -50,11 +54,13 @@ extern "C" { return r; \ } +API_EXPORT const char **or_get_file_extensions() { return RawFile::fileExtensions(); } +API_EXPORT ORRawFileRef or_rawfile_new(const char *filename, or_rawfile_type type) { CHECK_PTR(filename, NULL); @@ -62,6 +68,7 @@ ORRawFileRef or_rawfile_new(const char *filename, or_rawfile_type type) return reinterpret_cast<ORRawFileRef>(rawfile); } +API_EXPORT ORRawFileRef or_rawfile_new_from_memory(const uint8_t *buffer, uint32_t len, or_rawfile_type type) { @@ -70,6 +77,7 @@ ORRawFileRef or_rawfile_new_from_memory(const uint8_t *buffer, uint32_t len, return reinterpret_cast<ORRawFileRef>(rawfile); } +API_EXPORT or_error or_rawfile_release(ORRawFileRef rawfile) { CHECK_PTR(rawfile, OR_ERROR_NOTAREF); @@ -77,6 +85,7 @@ or_error or_rawfile_release(ORRawFileRef rawfile) return OR_ERROR_NONE; } +API_EXPORT or_rawfile_type or_rawfile_get_type(ORRawFileRef rawfile) { CHECK_PTR(rawfile, OR_RAWFILE_TYPE_UNKNOWN); @@ -84,6 +93,7 @@ or_rawfile_type or_rawfile_get_type(ORRawFileRef rawfile) return prawfile->type(); } +API_EXPORT or_rawfile_typeid or_rawfile_get_typeid(ORRawFileRef rawfile) { CHECK_PTR(rawfile, OR_RAWFILE_TYPE_UNKNOWN); @@ -91,6 +101,7 @@ or_rawfile_typeid or_rawfile_get_typeid(ORRawFileRef rawfile) return prawfile->typeId(); } +API_EXPORT or_rawfile_typeid or_rawfile_get_vendorid(ORRawFileRef rawfile) { CHECK_PTR(rawfile, OR_RAWFILE_TYPE_UNKNOWN); @@ -98,7 +109,7 @@ or_rawfile_typeid or_rawfile_get_vendorid(ORRawFileRef rawfile) return prawfile->vendorId(); } -const uint32_t * +API_EXPORT const uint32_t * or_rawfile_get_thumbnail_sizes(ORRawFileRef rawfile, size_t *size) { @@ -116,6 +127,7 @@ or_rawfile_get_thumbnail_sizes(ORRawFileRef rawfile, return &(*v.begin()); } +API_EXPORT or_error or_rawfile_get_thumbnail(ORRawFileRef rawfile, uint32_t _preferred_size, ORThumbnailRef thumb) @@ -126,6 +138,7 @@ or_error or_rawfile_get_thumbnail(ORRawFileRef rawfile, *reinterpret_cast<Thumbnail *>(thumb)); } +API_EXPORT or_error or_rawfile_get_rawdata(ORRawFileRef rawfile, ORRawDataRef rawdata, uint32_t options) { @@ -134,6 +147,7 @@ or_error or_rawfile_get_rawdata(ORRawFileRef rawfile, ORRawDataRef rawdata, return prawfile->getRawData(*reinterpret_cast<RawData *>(rawdata), options); } +API_EXPORT or_error or_rawfile_get_rendered_image(ORRawFileRef rawfile, ORBitmapDataRef bitmapdata, uint32_t options) @@ -144,6 +158,7 @@ or_error or_rawfile_get_rendered_image(ORRawFileRef rawfile, *reinterpret_cast<BitmapData *>(bitmapdata), options); } +API_EXPORT int32_t or_rawfile_get_orientation(ORRawFileRef rawfile) { RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile); @@ -151,6 +166,7 @@ int32_t or_rawfile_get_orientation(ORRawFileRef rawfile) return prawfile->getOrientation(); } +API_EXPORT or_error or_rawfile_get_colourmatrix1(ORRawFileRef rawfile, double *matrix, uint32_t *size) { @@ -160,6 +176,7 @@ or_error or_rawfile_get_colourmatrix1(ORRawFileRef rawfile, double *matrix, return prawfile->getColourMatrix1(matrix, *size); } +API_EXPORT or_error or_rawfile_get_colourmatrix2(ORRawFileRef rawfile, double *matrix, uint32_t *size) { @@ -169,6 +186,7 @@ or_error or_rawfile_get_colourmatrix2(ORRawFileRef rawfile, double *matrix, return prawfile->getColourMatrix2(matrix, *size); } +API_EXPORT ExifLightsourceValue or_rawfile_get_calibration_illuminant1(ORRawFileRef rawfile) { RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile); @@ -176,6 +194,7 @@ ExifLightsourceValue or_rawfile_get_calibration_illuminant1(ORRawFileRef rawfile return prawfile->getCalibrationIlluminant1(); } +API_EXPORT ExifLightsourceValue or_rawfile_get_calibration_illuminant2(ORRawFileRef rawfile) { RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile); @@ -183,7 +202,7 @@ ExifLightsourceValue or_rawfile_get_calibration_illuminant2(ORRawFileRef rawfile return prawfile->getCalibrationIlluminant2(); } -or_colour_matrix_origin +API_EXPORT or_colour_matrix_origin or_rawfile_get_colour_matrix_origin(ORRawFileRef rawfile) { RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile); @@ -191,7 +210,7 @@ or_rawfile_get_colour_matrix_origin(ORRawFileRef rawfile) return prawfile->getColourMatrixOrigin(); } -ORConstMetaValueRef +API_EXPORT ORConstMetaValueRef or_rawfile_get_metavalue(ORRawFileRef rawfile, int32_t meta_index) { RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile); @@ -199,4 +218,21 @@ or_rawfile_get_metavalue(ORRawFileRef rawfile, int32_t meta_index) return reinterpret_cast<ORConstMetaValueRef>(prawfile->getMetaValue(meta_index)); } +API_EXPORT ORIfdDirRef +or_rawfile_get_ifd(ORRawFileRef rawfile, or_ifd_index ifd) +{ + RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile); + CHECK_PTR(rawfile, nullptr); + IfdDir::Ref dir; + switch (ifd) { + case OR_IFD_MAKERNOTE: + dir = prawfile->getMakerNoteIfd(); + break; + } + if (!dir) { + return nullptr; + } + return reinterpret_cast<ORIfdDirRef>(dir.get()); +} + } diff --git a/test/Makefile.am b/test/Makefile.am index 271861e..6a041e7 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -9,6 +9,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/lib +# -static to get private symbols for the test + check_PROGRAMS = fileio testoption ciffcontainertest ljpegtest testunpack\ extensions missingcoefficients @@ -24,15 +26,17 @@ extensions_SOURCES = extensions.cpp extensions_LDADD = $(OPENRAW_LIB) ciffcontainertest_SOURCES = ciffcontainertest.cpp +ciffcontainertest_LDFLAGS = -static ciffcontainertest_LDADD = $(OPENRAW_LIB) ljpegtest_SOURCES = ljpegtest.cpp -ljpegtest_LDFLAGS = @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@ +ljpegtest_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@ ljpegtest_LDADD = $(OPENRAW_LIB) @BOOST_UNIT_TEST_FRAMEWORK_LIBS@ testunpack_SOURCES = testunpack.cpp -testunpack_LDFLAGS = @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@ +testunpack_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@ testunpack_LDADD = $(OPENRAW_LIB) @BOOST_UNIT_TEST_FRAMEWORK_LIBS@ missingcoefficients_SOURCES = missingcoefficients.cpp +missingcoefficients_LDFLAGS = -static missingcoefficients_LDADD = $(OPENRAW_LIB) diff --git a/testsuite/testsuite.cpp b/testsuite/testsuite.cpp index 5b4f97d..41a44f3 100644 --- a/testsuite/testsuite.cpp +++ b/testsuite/testsuite.cpp @@ -2,7 +2,7 @@ /* * libopenraw - testsuite.cpp * - * Copyright (C) 2008-2018 Hubert Figuiere + * Copyright (C) 2008-2019 Hubert Figuière * Copyright (C) 2008 Novell, Inc. * * This library is free software: you can redistribute it and/or @@ -55,6 +55,7 @@ #define IN_TESTSUITE #include <libopenraw/debug.h> #include <libopenraw/consts.h> +#include <libopenraw/ifd.h> #include <libopenraw/metadata.h> #include "rawfile.hpp" @@ -82,6 +83,10 @@ using OpenRaw::Thumbnail; using std::unique_ptr; +ThumbnailDeleter td; +RawDataDeleter rd; +RawFileDeleter rfd; + #define RETURN_TEST_EQUALS(a,b) \ { \ bool _success = (a == b); \ @@ -224,27 +229,29 @@ Test::~Test() bool Test::testRawType(const std::string & result) { - RawFile::Type t = m_rawfile->type(); + or_rawfile_type t = or_rawfile_get_type(m_rawfile.get()); // test the detection by content.... - RawFile::Type t2; - OpenRaw::IO::File f(m_file.c_str()); - ::or_error err = f.open(); - if(err != OR_ERROR_NONE) { + or_rawfile_type t2; + FILE* f = fopen(m_file.c_str(), "rb"); + if (!f) { std::string message("failed to open "); - message += boost::lexical_cast<std::string>(err); + message += boost::lexical_cast<std::string>(errno); RETURN_FAIL(message.c_str()); } - off_t len = f.filesize(); + fseek(f, 0, SEEK_END); + off_t len = ftell(f); + fseek(f, 0, SEEK_SET); unique_ptr<uint8_t[]> buff(new uint8_t[len]); - int res = f.read(buff.get(), len); - if(res == len) { - unique_ptr<RawFile> r2(RawFile::newRawFileFromMemory(buff.get(), len)); - if(!r2) { + int res = fread(buff.get(), 1, len, f); + fclose(f); + if (res == len) { + unique_ptr<_RawFile, RawFileDeleter> r2(or_rawfile_new_from_memory(buff.get(), len, OR_RAWFILE_TYPE_UNKNOWN), rfd); + if (!r2) { RETURN_FAIL("failed to load from memory"); } - t2 = r2->type(); - if(t2 != t) { + t2 = or_rawfile_get_type(r2.get()); + if (t2 != t) { RETURN_FAIL("type mismatch"); } } @@ -309,8 +316,8 @@ bool Test::testRawType(const std::string & result) bool Test::testRawTypeId(const std::string & result) { - auto type_id = m_rawfile->typeId(); - auto vendor_id = m_rawfile->vendorId(); + auto type_id = or_rawfile_get_typeid(m_rawfile.get()); + auto vendor_id = or_rawfile_get_vendorid(m_rawfile.get()); bool test = false; CHECK_TEST_EQUALS_N(OR_GET_FILE_TYPEID_VENDOR(type_id), vendor_id, test); if (!test) { @@ -324,10 +331,10 @@ bool Test::testRawTypeId(const std::string & result) bool Test::testThumbNum(const std::string & result) { - const std::vector<uint32_t> & thumbs = m_rawfile->listThumbnailSizes(); - int num = thumbs.size(); + size_t num = 0; + /*auto thumbs =*/ or_rawfile_get_thumbnail_sizes(m_rawfile.get(), &num); try { - RETURN_TEST_EQUALS_N(num, boost::lexical_cast<int>(result)); + RETURN_TEST_EQUALS_N(num, boost::lexical_cast<size_t>(result)); } catch(...) { @@ -337,10 +344,11 @@ bool Test::testThumbNum(const std::string & result) bool Test::testThumbSizes(const std::string& result) { - std::vector<uint32_t> thumbs = m_rawfile->listThumbnailSizes(); + size_t num = 0; + auto thumbs = or_rawfile_get_thumbnail_sizes(m_rawfile.get(), &num); std::vector<std::string> v; boost::split(v, result, boost::is_any_of(" ")); - if(v.size() != thumbs.size()) { + if (v.size() != num) { RETURN_FAIL("mismatch number of elements"); } std::vector<uint32_t> v2; @@ -355,7 +363,7 @@ bool Test::testThumbSizes(const std::string& result) } } bool success = true; - for (size_t i = 0; i < thumbs.size(); i++) { + for (size_t i = 0; i < num; i++) { bool test = false; CHECK_TEST_EQUALS_N(thumbs[i], v2[i], test); if (!test) { @@ -368,17 +376,18 @@ bool Test::testThumbSizes(const std::string& result) bool Test::testThumbFormats(const std::string & result) { bool success = true; - auto thumbs = m_rawfile->listThumbnailSizes(); + size_t num = 0; + auto thumbs = or_rawfile_get_thumbnail_sizes(m_rawfile.get(), &num); std::vector< std::string > v; boost::split(v, result, boost::is_any_of(" ")); auto result_iter = v.cbegin(); - if(v.size() != thumbs.size()) { + if (v.size() != num) { RETURN_FAIL("mismatch number of elements"); } - for (const auto& thumb : thumbs) { - Thumbnail t; - m_rawfile->getThumbnail(thumb, t); - success &= equalDataType(*result_iter, t.dataType()); + for (size_t i = 0; i < num; i++) { + unique_ptr<_Thumbnail, ThumbnailDeleter> t(or_thumbnail_new(), td); + or_rawfile_get_thumbnail(m_rawfile.get(), thumbs[i], t.get()); + success &= equalDataType(*result_iter, or_thumbnail_format(t.get())); result_iter++; } RETURN_TEST(success, result); @@ -387,19 +396,20 @@ bool Test::testThumbFormats(const std::string & result) bool Test::testThumbDataSizes(const std::string & result) { bool success = true; - auto thumbs = m_rawfile->listThumbnailSizes(); + size_t num = 0; + auto thumbs = or_rawfile_get_thumbnail_sizes(m_rawfile.get(), &num); std::vector< std::string > v; boost::split(v, result, boost::is_any_of(" ")); auto result_iter = v.cbegin(); - if(v.size() != thumbs.size()) { + if (v.size() != num) { RETURN_FAIL("mismatch number of elements"); } - for (const auto& thumb : thumbs) { - Thumbnail t; - m_rawfile->getThumbnail(thumb, t); + for (size_t i = 0; i < num; i++) { + unique_ptr<_Thumbnail, ThumbnailDeleter> t(or_thumbnail_new(), td); + or_rawfile_get_thumbnail(m_rawfile.get(), thumbs[i], t.get()); try { bool succ = false; - CHECK_TEST_EQUALS_N(t.size(), boost::lexical_cast<uint32_t>(*result_iter), succ); + CHECK_TEST_EQUALS_N(or_thumbnail_data_size(t.get()), boost::lexical_cast<uint32_t>(*result_iter), succ); success &= succ; result_iter++; } @@ -411,13 +421,13 @@ bool Test::testThumbDataSizes(const std::string & result) } namespace { -uint32_t computeCrc(const Thumbnail * thumb) +uint32_t computeCrc(ORThumbnailRef thumb) { boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2; - const uint8_t * data = static_cast<uint8_t *>(thumb->data()); - size_t data_len = thumb->size(); - crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 ); + const uint8_t * data = static_cast<uint8_t *>(or_thumbnail_data(thumb)); + size_t data_len = or_thumbnail_data_size(thumb); + crc_ccitt2 = std::for_each(data, data + data_len, crc_ccitt2); return crc_ccitt2(); } } @@ -425,19 +435,20 @@ uint32_t computeCrc(const Thumbnail * thumb) bool Test::testThumbMd5(const std::string & result) { bool success = true; - auto thumbs = m_rawfile->listThumbnailSizes(); + size_t num = 0; + auto thumbs = or_rawfile_get_thumbnail_sizes(m_rawfile.get(), &num); std::vector< std::string > v; boost::split(v, result, boost::is_any_of(" ")); auto result_iter = v.cbegin(); - if(v.size() != thumbs.size()) { + if (v.size() != num) { RETURN_FAIL("mismatch number of elements"); } - for (const auto& thumb : thumbs) { - Thumbnail t; - m_rawfile->getThumbnail(thumb, t); + for (size_t i = 0; i < num; i++) { + unique_ptr<_Thumbnail, ThumbnailDeleter> t(or_thumbnail_new(), td); + or_rawfile_get_thumbnail(m_rawfile.get(), thumbs[i], t.get()); try { bool succ = false; - uint32_t crc = computeCrc(&t); + uint32_t crc = computeCrc(t.get()); CHECK_TEST_EQUALS(boost::lexical_cast<std::string>(crc), (*result_iter), succ); success &= succ; result_iter++; @@ -450,23 +461,23 @@ bool Test::testThumbMd5(const std::string & result) } namespace { -unique_ptr<RawData> loadRawData(const unique_ptr<RawFile> & file) +unique_ptr<_RawData, RawDataDeleter> loadRawData(const unique_ptr<_RawFile, RawFileDeleter> & file) { - unique_ptr<RawData> rawdata(new RawData()); + unique_ptr<_RawData, RawDataDeleter> rawdata(or_rawdata_new(), rd); ::or_error err; - err = file->getRawData(*rawdata, OR_OPTIONS_NONE); - if(OR_ERROR_NONE != err) { + err = or_rawfile_get_rawdata(file.get(), rawdata.get(), OR_OPTIONS_NONE); + if (OR_ERROR_NONE != err) { rawdata.reset(); } return rawdata; } -uint32_t computeCrc(const unique_ptr<RawData> & rawdata) +uint32_t computeCrc(_RawData* rawdata) { boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2; - auto data = static_cast<const uint8_t *>(rawdata->data()); - size_t data_len = rawdata->size(); + auto data = static_cast<const uint8_t *>(or_rawdata_data(rawdata)); + size_t data_len = or_rawdata_data_size(rawdata); crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 ); return crc_ccitt2(); } @@ -475,26 +486,26 @@ uint32_t computeCrc(const unique_ptr<RawData> & rawdata) bool Test::testRawDataType(const std::string & result) { - if(m_rawdata == NULL) { + if (!m_rawdata) { m_rawdata = loadRawData(m_rawfile); - if(m_rawdata == NULL) { + if (!m_rawdata) { RETURN_FAIL("failed to get rawData"); } } - RETURN_TEST(equalDataType(result, m_rawdata->dataType()), result); + RETURN_TEST(equalDataType(result, or_rawdata_format(m_rawdata.get())), result); } bool Test::testRawDataSize(const std::string & result) { - if(m_rawdata == NULL) { + if (!m_rawdata) { m_rawdata = loadRawData(m_rawfile); - if(m_rawdata == NULL) { + if (!m_rawdata) { RETURN_FAIL("failed to get rawData"); } } try { - RETURN_TEST_EQUALS_N(m_rawdata->size(), boost::lexical_cast<uint32_t>(result)); + RETURN_TEST_EQUALS_N(or_rawdata_data_size(m_rawdata.get()), boost::lexical_cast<uint32_t>(result)); } catch(...) { } @@ -503,9 +514,9 @@ bool Test::testRawDataSize(const std::string & result) bool Test::testRawDataDimensions(const std::string & result) { - if(m_rawdata == NULL) { + if (!m_rawdata) { m_rawdata = loadRawData(m_rawfile); - if(m_rawdata == NULL) { + if (!m_rawdata) { RETURN_FAIL("failed to get rawData"); } } @@ -520,9 +531,12 @@ bool Test::testRawDataDimensions(const std::string & result) x = boost::lexical_cast<uint32_t>(v[0]); y = boost::lexical_cast<uint32_t>(v[1]); bool succ = false; - CHECK_TEST_EQUALS_N(m_rawdata->width(), x, succ); + uint32_t rx, ry; + rx = ry = 0; + or_rawdata_dimensions(m_rawdata.get(), &rx, &ry); + CHECK_TEST_EQUALS_N(rx, x, succ); success &= succ; - CHECK_TEST_EQUALS_N(m_rawdata->height(), y, succ); + CHECK_TEST_EQUALS_N(ry, y, succ); success &= succ; } catch(...) @@ -556,10 +570,10 @@ bool Test::testRawDataActiveArea(const std::string & result) { RETURN_FAIL("conversion failed"); } - RETURN_TEST(x == m_rawdata->activeAreaX() && y == m_rawdata->activeAreaY() - && w == m_rawdata->activeAreaWidth() - && h == m_rawdata->activeAreaHeight(), - result); + uint32_t rx, ry, rw, rh; + rx = ry = rw = rh = 0; + or_rawdata_get_active_area(m_rawdata.get(), &rx, &ry, &rw, &rh); + RETURN_TEST(x == rx && y == ry && w == rw && h == rh, result); } bool Test::testRawCfaPattern(const std::string & result) @@ -571,8 +585,7 @@ bool Test::testRawCfaPattern(const std::string & result) } } bool succ = false; - CHECK_TEST_EQUALS(cfaPatternToString( - m_rawdata->cfaPattern()->patternType()), + CHECK_TEST_EQUALS(cfaPatternToString(or_rawdata_get_cfa_pattern_type(m_rawdata.get())), result, succ); return succ; } @@ -593,7 +606,10 @@ bool Test::testRawMinValue(const std::string & result) { RETURN_FAIL("conversion failed"); } - RETURN_TEST_EQUALS_N(m_rawdata->blackLevel(), expected); + uint16_t black, white; + black = white = 0; + or_rawdata_get_levels(m_rawdata.get(), &black, &white); + RETURN_TEST_EQUALS_N(black, expected); } @@ -613,7 +629,10 @@ bool Test::testRawMaxValue(const std::string & result) { RETURN_FAIL("conversion failed"); } - RETURN_TEST_EQUALS_N(m_rawdata->whiteLevel(), expected); + uint16_t black, white; + black = white = 0; + or_rawdata_get_levels(m_rawdata.get(), &black, &white); + RETURN_TEST_EQUALS_N(white, expected); } bool Test::testRawMd5(const std::string & result) @@ -625,7 +644,7 @@ bool Test::testRawMd5(const std::string & result) } } - uint32_t crc = computeCrc(m_rawdata); + uint32_t crc = computeCrc(m_rawdata.get()); uint32_t expected = 0; try { @@ -653,17 +672,17 @@ bool Test::testRawDecompressedMd5(const std::string &) bool Test::testMetaOrientation(const std::string & result) { - int32_t orientation = m_rawfile->getOrientation(); + int32_t orientation = or_rawfile_get_orientation(m_rawfile.get()); RETURN_TEST_EQUALS_N(orientation, boost::lexical_cast<int32_t>(result)); } bool Test::testExifString(int32_t meta_index, const std::string & result) { - auto val = m_rawfile->getMetaValue(meta_index); + auto val = or_rawfile_get_metavalue(m_rawfile.get(), meta_index); if (val) { // - auto stringVal = val->getString(0); + auto stringVal = std::string(or_metavalue_get_string(val, 0)); RETURN_TEST_EQUALS(stringVal, result); } RETURN_FAIL("meta data not found"); @@ -672,11 +691,9 @@ bool Test::testExifString(int32_t meta_index, const std::string & result) bool Test::testMakerNoteCount(const std::string & result) { try { - auto maker_note = m_rawfile->getMakerNoteIfd(); - if (!maker_note) { - RETURN_FAIL("no MakeNote found"); - } - RETURN_TEST_EQUALS_N(maker_note->numTags(), + auto ifd = or_rawfile_get_ifd(m_rawfile.get(), OR_IFD_MAKERNOTE); + auto numTags = or_ifd_count_tags(ifd); + RETURN_TEST_EQUALS_N(numTags, boost::lexical_cast<int32_t>(result)); } catch(const std::bad_cast & e) { @@ -689,30 +706,15 @@ bool Test::testMakerNoteCount(const std::string & result) bool Test::testMakerNoteId(const std::string & result) { - try { - auto ifd_file = - dynamic_cast<OpenRaw::Internals::IfdFile*>(m_rawfile.get()); - if (ifd_file == nullptr) { - RETURN_FAIL("not an IFD file"); - } - auto exif = ifd_file->exifIfd(); - if (!exif) { - RETURN_FAIL("not an exif"); - } - auto maker_note = - std::dynamic_pointer_cast<OpenRaw::Internals::MakerNoteDir>( - exif->getMakerNoteIfd()); - if (!maker_note) { - RETURN_FAIL("no MakerNote found"); - } - RETURN_TEST_EQUALS(maker_note->getId(), result); + auto ifd = or_rawfile_get_ifd(m_rawfile.get(), OR_IFD_MAKERNOTE); + if (!ifd) { + RETURN_FAIL("no MakerNote found"); } - catch(const std::bad_cast & e) { - RETURN_FAIL("not an IFD file"); - } - catch(...) { - RETURN_FAIL("unknown exception"); + auto makernote_id = or_ifd_get_makernote_id(ifd); + if (!makernote_id) { + RETURN_FAIL("no MakeNote id"); } + RETURN_TEST_EQUALS(std::string(makernote_id), result); } @@ -730,7 +732,7 @@ int Test::run() fprintf(stderr, "File not found, skipping. (%d)\n", errno); return 0; } - m_rawfile.reset(RawFile::newRawFile(m_file.c_str())); + m_rawfile.reset(or_rawfile_new(m_file.c_str(), OR_RAWFILE_TYPE_UNKNOWN)); if(m_rawfile == NULL) { RETURN_FAIL("m_rawfile == NULL"); diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 2d3efe9..2abd4f0 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -37,10 +37,28 @@ #include <map> #include <memory> -namespace OpenRaw { -class RawFile; -class RawData; -} +#include <libopenraw/libopenraw.h> + +struct ThumbnailDeleter +{ + void operator()(ORThumbnailRef p) const { + or_thumbnail_release(p); + } +}; + +struct RawDataDeleter +{ + void operator()(ORRawDataRef p) const { + or_rawdata_release(p); + } +}; + +struct RawFileDeleter +{ + void operator()(ORRawFileRef p) const { + or_rawfile_release(p); + } +}; class Test { public: @@ -96,8 +114,8 @@ private: std::string m_referer; std::map<int, std::string> m_results; // runtime data - std::unique_ptr<OpenRaw::RawFile> m_rawfile; - std::unique_ptr<OpenRaw::RawData> m_rawdata; + std::unique_ptr<_RawFile, RawFileDeleter> m_rawfile; + std::unique_ptr<_RawData, RawDataDeleter> m_rawdata; int m_total, m_success, m_failure; }; |