1 #ifndef DALI_TEXT_ABSTRACTION_GLYPH_BUFFER_DATA_H
2 #define DALI_TEXT_ABSTRACTION_GLYPH_BUFFER_DATA_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/images/pixel.h>
23 #include <cstddef> /// for size_t
26 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
27 #include <dali/public-api/dali-adaptor-common.h>
31 namespace TextAbstraction
34 * @brief Struct used to retrieve the glyph's bitmap.
36 struct DALI_ADAPTOR_API GlyphBufferData
41 * Initializes struct members to their defaults.
51 * @brief Move constructor.
53 * @param[in] rhs moved data.
55 GlyphBufferData(GlyphBufferData&& rhs) noexcept;
58 * @brief Move assign operator.
60 * @param[in] rhs moved data.
61 * @return A reference to this.
63 GlyphBufferData& operator=(GlyphBufferData&& rhs) noexcept;
65 // Compression method of buffer. Each buffer compressed line by line
66 enum class CompressionType
68 NO_COMPRESSION = 0, // No compression
69 BPP_4 = 1, // Compress as 4 bit. Color become value * 17 (0x00, 0x11, 0x22, ... 0xee, 0xff).
70 // Only works for Pixel::L8 format
71 RLE_4 = 2, // Compress as 4 bit, and Run-Length-Encode. For more high compress rate, we store difference between previous scanline.
72 // Only works for Pixel::L8 format
76 * @brief Helper static function to compress raw buffer from inBuffer to outBufferData.buffer.
77 * outBufferData will have it's own buffer.
79 * @pre outBufferData must not have it's own buffer.
80 * @param[in] inBuffer The input raw data.
81 * @param[in, out] outBufferData The output glyph buffer data.
82 * @return Size of compressed out buffer, Or 0 if compress failed.
84 static size_t Compress(const uint8_t* const inBuffer, GlyphBufferData& outBufferData);
87 * @brief Helper static function to decompress raw buffer from inBuffer to outBufferPtr.
88 * If outBuffer is nullptr, Do nothing.
90 * @pre outBuffer memory should be allocated.
91 * @param[in] inBufferData The input glyph buffer data.
92 * @param[in, out] outBuffer The output pointer of raw buffer data.
94 static void Decompress(const GlyphBufferData& inBufferData, uint8_t* outBuffer);
97 * @brief Special Helper static function to decompress raw buffer from inBuffer to outBuffer one scanline.
98 * After decompress one scanline successed, offset will be changed.
100 * @pre outBuffer memory should be allocated.
101 * @pre if inBufferData's compression type is RLE4, outBuffer memory should store the previous scanline data.
102 * @param[in] inBufferData The input glyph buffer data.
103 * @param[in, out] outBuffer The output pointer of raw buffer data.
104 * @param[in, out] offset The offset of input. It will be changed as next scanline's offset.
106 static void DecompressScanline(const GlyphBufferData& inBufferData, uint8_t* outBuffer, uint32_t& offset);
109 // Delete copy operation.
110 GlyphBufferData(const GlyphBufferData& rhs) = delete;
111 GlyphBufferData& operator=(const GlyphBufferData& rhs) = delete;
114 uint8_t* buffer; ///< The glyph's bitmap buffer data.
115 uint32_t width; ///< The width of the bitmap.
116 uint32_t height; ///< The height of the bitmap.
117 int outlineOffsetX; ///< The additional horizontal offset to be added for the glyph's position for outline.
118 int outlineOffsetY; ///< The additional vertical offset to be added for the glyph's position for outline.
119 Pixel::Format format; ///< The pixel's format of the bitmap.
120 CompressionType compressionType; ///< The type of buffer compression.
121 bool isColorEmoji : 1; ///< Whether the glyph is an emoji.
122 bool isColorBitmap : 1; ///< Whether the glyph is a color bitmap.
123 bool isBufferOwned : 1; ///< Whether the glyph's bitmap buffer data owned by this class or not. Becareful when you use non-owned buffer data.
126 } // namespace TextAbstraction
130 #endif //DALI_TEXT_ABSTRACTION_GLYPH_INFO_H