Ocean
media/android/Image.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_MEDIA_ANDROID_IMAGE_H
9 #define META_OCEAN_MEDIA_ANDROID_IMAGE_H
10 
12 
13 #include "ocean/base/Frame.h"
15 
16 #include <unistd.h>
17 
18 #if defined(__ANDROID_API__) && __ANDROID_API__ >= 30
19  #include <android/imagedecoder.h>
20 
21  #ifndef OCEAN_MEDIA_ANDROID_IMAGE_AVAILABLE
22  #define OCEAN_MEDIA_ANDROID_IMAGE_AVAILABLE
23  #endif
24 #endif
25 
26 
27 namespace Ocean
28 {
29 
30 namespace Media
31 {
32 
33 namespace Android
34 {
35 
36 class Image
37 {
38  protected:
39 
40  /**
41  * Definition of a scoped file based on a file descriptor.
42  */
43  using ScopedFileDescriptor = ScopedObjectCompileTimeT<int, int, int, close, 0, true, -1>;
44 
45 #if defined(__ANDROID_API__) && __ANDROID_API__ >= 30
46 
47  /**
48  * Definition of a scoped object wrapping an AImageDecoder object.
49  */
51 #endif
52 
53  public:
54 
55  /**
56  * Decodes (reads/loads) an image from a given binary buffer.
57  * @param buffer The buffer from which the image will be loaded, must be valid
58  * @param size The size of the given buffer in bytes, with range [1, infinity)
59  * @param imageBufferTypeIn Type of the given image that is stored in the buffer, should be specified if known (e.g. the file extension of a corresponding image file)
60  * @param imageBufferTypeOut Optional type of the given image that is stored in the buffer, as determined by the decoder (if possible)
61  * @return The frame containing the image information, an invalid frame if the image could not be loaded
62  * @see writeImage().
63  */
64  static Frame decodeImage(const void* buffer, const size_t size, const std::string& imageBufferTypeIn = std::string(), std::string* imageBufferTypeOut = nullptr);
65 
66  /**
67  * Reads/loads an image from a specified file.
68  * @param filename The name of the file from which the image will be loaded, must be valid
69  * @return The frame containing the image information, an invalid frame if the image could not be loaded
70  * @see writeImage().
71  */
72  static Frame readImage(const std::string& filename);
73 
74  protected:
75 
76 #if defined(__ANDROID_API__) && __ANDROID_API__ >= 30
77 
78  /**
79  * Decodes an image from a given Android image decoder object.
80  * @param aImageDecoder The Android image decoder from which the image will be decoded, must be valid
81  * @return The resulting frame, invalid in case of an error
82  */
83  static Frame decodeImage(AImageDecoder* aImageDecoder);
84 
85 #endif
86 };
87 
88 }
89 
90 }
91 
92 }
93 
94 #endif // META_OCEAN_MEDIA_ANDROID_IMAGE_H
This class implements Ocean's image class.
Definition: Frame.h:1792
Definition: media/android/Image.h:37
static Frame decodeImage(const void *buffer, const size_t size, const std::string &imageBufferTypeIn=std::string(), std::string *imageBufferTypeOut=nullptr)
Decodes (reads/loads) an image from a given binary buffer.
static Frame readImage(const std::string &filename)
Reads/loads an image from a specified file.
static Frame decodeImage(AImageDecoder *aImageDecoder)
Decodes an image from a given Android image decoder object.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15