libopenraw
rawfile.cpp
1 /*
2  * libopenraw - rawfile.cpp
3  *
4  * Copyright (C) 2007 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 /* @brief C api for rawfile
21  */
22 
23 #include <boost/checked_delete.hpp>
24 #include <libopenraw/libopenraw.h>
25 
26 
27 #include <libopenraw++/rawfile.h>
28 #include <libopenraw++/bitmapdata.h>
29 
30 using OpenRaw::RawFile;
31 using OpenRaw::RawData;
33 using OpenRaw::Thumbnail;
34 
35 extern "C" {
36 
38 #define CHECK_PTR(p,r) \
39  if(p == NULL) { return r; }
40 
41 const char **or_get_file_extensions()
42 {
43  return RawFile::fileExtensions();
44 }
45 
46 ORRawFileRef
47 or_rawfile_new(const char* filename, or_rawfile_type type)
48 {
49  CHECK_PTR(filename, NULL);
50  RawFile * rawfile = RawFile::newRawFile(filename, type);
51  return reinterpret_cast<ORRawFileRef>(rawfile);
52 }
53 
54 ORRawFileRef
55 or_rawfile_new_from_memory(const uint8_t *buffer, uint32_t len, or_rawfile_type type)
56 {
57  CHECK_PTR(buffer, NULL);
58  RawFile * rawfile = RawFile::newRawFileFromMemory(buffer, len, type);
59  return reinterpret_cast<ORRawFileRef>(rawfile);
60 }
61 
62 
63 or_error
64 or_rawfile_release(ORRawFileRef rawfile)
65 {
66  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
67  boost::checked_delete(reinterpret_cast<RawFile *>(rawfile));
68  return OR_ERROR_NONE;
69 }
70 
71 or_rawfile_type
72 or_rawfile_get_type(ORRawFileRef rawfile)
73 {
74  CHECK_PTR(rawfile, OR_RAWFILE_TYPE_UNKNOWN);
75  RawFile * prawfile = reinterpret_cast<RawFile *>(rawfile);
76  return prawfile->type();
77 }
78 
79 or_error
80 or_rawfile_get_thumbnail(ORRawFileRef rawfile, uint32_t _preferred_size,
81  ORThumbnailRef thumb)
82 {
83  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
84  RawFile * prawfile = reinterpret_cast<RawFile *>(rawfile);
85  return prawfile->getThumbnail(_preferred_size,
86  *reinterpret_cast<Thumbnail*>(thumb));
87 }
88 
89 or_error
90 or_rawfile_get_rawdata(ORRawFileRef rawfile, ORRawDataRef rawdata,
91  uint32_t options)
92 {
93  RawFile * prawfile = reinterpret_cast<RawFile *>(rawfile);
94  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
95  return prawfile->getRawData(*reinterpret_cast<RawData*>(rawdata), options);
96 }
97 
98 or_error
99 or_rawfile_get_rendered_image(ORRawFileRef rawfile, ORBitmapDataRef bitmapdata,
100  uint32_t options)
101 {
102  RawFile * prawfile = reinterpret_cast<RawFile *>(rawfile);
103  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
104  return prawfile->getRenderedImage(*reinterpret_cast<BitmapData*>(bitmapdata), options);
105 }
106 
107 int32_t
108 or_rawfile_get_orientation(ORRawFileRef rawfile)
109 {
110  RawFile * prawfile = reinterpret_cast<RawFile *>(rawfile);
111  CHECK_PTR(rawfile, 0);
112  return prawfile->getOrientation();
113 }
114 
115 }
::or_error getThumbnail(uint32_t size, Thumbnail &thumbnail)
Definition: rawfile.cpp:322
Type type() const
Definition: rawfile.cpp:291
::or_error getRawData(RawData &rawdata, uint32_t options)
Definition: rawfile.cpp:372
::or_error getRenderedImage(BitmapData &bitmapdata, uint32_t options)
Definition: rawfile.cpp:379
int32_t getOrientation()
Definition: rawfile.cpp:414