libopenraw  0.3.7
capi.cpp
1 /* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */
2 /*
3  * libopenraw - capi.cpp
4  *
5  * Copyright (C) 2005-2019 Hubert Figuière
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #include <libopenraw/consts.h>
30 #include <libopenraw/thumbnails.h>
31 
32 #include "capi.h"
33 #include "thumbnail.hpp"
34 
35 using OpenRaw::Thumbnail;
36 
37 extern "C" {
38 
39 API_EXPORT
40 or_error or_get_extract_thumbnail(const char* _filename,
41  uint32_t _preferred_size,
42  ORThumbnailRef *_thumb)
43 {
44  or_error ret = OR_ERROR_NONE;
45 
46  Thumbnail ** pThumbnail = reinterpret_cast<Thumbnail **>(_thumb);
47  *pThumbnail = Thumbnail::getAndExtractThumbnail(_filename,
48  _preferred_size, ret);
49  return ret;
50 }
51 
52 API_EXPORT
54 {
55  Thumbnail *thumb = new Thumbnail();
56  return reinterpret_cast<ORThumbnailRef>(thumb);
57 }
58 
59 API_EXPORT or_error
61 {
62  if (thumb == nullptr) {
63  return OR_ERROR_NOTAREF;
64  }
65  delete reinterpret_cast<Thumbnail *>(thumb);
66  return OR_ERROR_NONE;
67 }
68 
69 API_EXPORT or_data_type
71 {
72  return reinterpret_cast<Thumbnail *>(thumb)->dataType();
73 }
74 
75 API_EXPORT void *
77 {
78  return reinterpret_cast<Thumbnail *>(thumb)->data();
79 }
80 
81 API_EXPORT size_t
83 {
84  return reinterpret_cast<Thumbnail *>(thumb)->size();
85 }
86 
87 API_EXPORT void
88 or_thumbnail_dimensions(ORThumbnailRef thumb, uint32_t *width, uint32_t *height)
89 {
90  Thumbnail* t = reinterpret_cast<Thumbnail *>(thumb);
91  if (width != nullptr) {
92  *width = t->width();
93  }
94  if (height != nullptr) {
95  *height = t->height();
96  }
97 }
98 
99 
100 }
101 
uint32_t width() const
Width of the image data.
Definition: bitmapdata.cpp:137
uint32_t height() const
Height of the image data.
Definition: bitmapdata.cpp:142
Represent a thumbnail.
Definition: thumbnail.hpp:32
or_data_type
Data types.
Definition: consts.h:80
struct _Thumbnail * ORThumbnailRef
Thumbnail reference.
Definition: types.h:33
or_error
Error codes returned by libopenraw.
Definition: consts.h:42
@ OR_ERROR_NONE
Definition: consts.h:43
@ OR_ERROR_NOTAREF
Definition: consts.h:45
API_EXPORT ORThumbnailRef or_thumbnail_new(void)
Allocate a Thumbnail object.
Definition: capi.cpp:53
API_EXPORT size_t or_thumbnail_data_size(ORThumbnailRef thumb)
Get the data size.
Definition: capi.cpp:82
API_EXPORT void or_thumbnail_dimensions(ORThumbnailRef thumb, uint32_t *width, uint32_t *height)
Get the Thumbnail dimensions in pixels.
Definition: capi.cpp:88
API_EXPORT or_data_type or_thumbnail_format(ORThumbnailRef thumb)
Get the thumbnail format.
Definition: capi.cpp:70
API_EXPORT void * or_thumbnail_data(ORThumbnailRef thumb)
Get the pointer to the data.
Definition: capi.cpp:76
API_EXPORT or_error or_thumbnail_release(ORThumbnailRef thumb)
Release a Thumbnail object.
Definition: capi.cpp:60
API_EXPORT or_error or_get_extract_thumbnail(const char *_filename, uint32_t _preferred_size, ORThumbnailRef *_thumb)
Extract thumbnail for raw file.
Definition: capi.cpp:40