From 77832ca0f6d497f6774c97a45650fb3394bfb163 Mon Sep 17 00:00:00 2001 From: zewu-feng Date: Thu, 19 May 2022 17:29:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=A2=9C=E8=89=B2=E7=BC=93=E5=86=B2?= =?UTF-8?q?=E5=8C=BA=E6=A0=BC=E5=BC=8F=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zewu-feng --- .../common/include/pixel_map_utils.h | 1 + .../innerkitsimpl/common/src/pixel_map.cpp | 3 + .../converter/include/pixel_convert.h | 62 ++++++ .../converter/src/pixel_convert.cpp | 208 +++++++++++++++++- .../src/pixel_convert_adapter.cpp | 99 +++++++-- .../kits/js/common/image_source_napi.cpp | 2 +- .../libjpegplugin/include/jpeg_encoder.h | 1 + .../image/libjpegplugin/src/jpeg_encoder.cpp | 34 ++- 8 files changed, 385 insertions(+), 25 deletions(-) diff --git a/frameworks/innerkitsimpl/common/include/pixel_map_utils.h b/frameworks/innerkitsimpl/common/include/pixel_map_utils.h index ae0b91b45..e4c48230b 100644 --- a/frameworks/innerkitsimpl/common/include/pixel_map_utils.h +++ b/frameworks/innerkitsimpl/common/include/pixel_map_utils.h @@ -27,6 +27,7 @@ constexpr int8_t ALPHA_8_BYTES = 1; constexpr int8_t RGB_565_BYTES = 2; constexpr int8_t RGB_888_BYTES = 3; constexpr int8_t ARGB_8888_BYTES = 4; +constexpr int8_t BGRA_F16_BYTES = 8; constexpr int8_t YUV420_BYTES = 2; // in fact NV21 one pixel used 1.5 bytes. // Define shift bits of bytes per pixel diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index f633593d1..48efc1353 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -453,6 +453,9 @@ bool PixelMap::GetPixelFormatDetail(const PixelFormat format) case PixelFormat::CMYK: pixelBytes_ = ARGB_8888_BYTES; break; + case PixelFormat::RGBA_F16: + pixelBytes_ = BGRA_F16_BYTES; + break; default: { HiLog::Error(LABEL, "pixel format:[%{public}d] not supported.", format); return false; diff --git a/frameworks/innerkitsimpl/converter/include/pixel_convert.h b/frameworks/innerkitsimpl/converter/include/pixel_convert.h index 71eab7280..310291886 100644 --- a/frameworks/innerkitsimpl/converter/include/pixel_convert.h +++ b/frameworks/innerkitsimpl/converter/include/pixel_convert.h @@ -17,6 +17,7 @@ #define PIXEL_CONVERT_H #include +#include #include #include "hilog/log.h" #include "image_type.h" @@ -46,6 +47,7 @@ constexpr uint32_t RGBA_8888 = 0x00000003; constexpr uint32_t BGRA_8888 = 0x00000004; constexpr uint32_t RGB_888 = 0x00000005; constexpr uint32_t ALPHA_8 = 0x00000006; /* Gray image, 8 bit = 255 color. */ +constexpr uint32_t RGBA_F16 = 0x00000007; constexpr uint32_t ABGR_8888 = 0x00000008; constexpr uint32_t BGR_888 = 0x40000002; constexpr uint32_t RGB_161616 = 0x40000007; @@ -73,6 +75,8 @@ constexpr uint8_t ALPHA_TRANSPARENT = 0x00; constexpr uint32_t GET_8_BIT = 0x80; constexpr uint32_t GET_1_BIT = 0x01; +constexpr uint32_t SHIFT_48_BIT = 0x30; +constexpr uint32_t SHIFT_32_BIT = 0x20; constexpr uint32_t SHIFT_24_BIT = 0x18; constexpr uint32_t SHIFT_16_BIT = 0x10; constexpr uint32_t SHIFT_8_BIT = 0x08; @@ -81,11 +85,27 @@ constexpr uint32_t SHIFT_5_BIT = 0x05; constexpr uint32_t SHIFT_3_BIT = 0x03; constexpr uint32_t SHIFT_2_BIT = 0x02; +constexpr uint32_t SHIFT_32_MASK = 0x80000000; +constexpr uint32_t SHIFT_16_MASK = 0x8000; +constexpr uint32_t SHIFT_7_MASK = 0x1C000; constexpr uint8_t SHIFT_5_MASK = 0x1F; constexpr uint8_t SHIFT_3_MASK = 0x07; +constexpr uint8_t SHIFT_HALF_BIT = 0x0D; +constexpr uint32_t SHIFT_HALF_MASK = 0x38000000; + constexpr uint16_t MAX_15_BIT_VALUE = 0x7FFF; +constexpr uint16_t MAX_16_BIT_VALUE = 0xFFFF; +constexpr uint32_t MAX_31_BIT_VALUE = 0x7FFFFFFF; constexpr float HALF_ONE = 0.5F; +constexpr float MAX_HALF = 65504; +constexpr float MIN_EPSILON = 1e-6; + +static inline bool FloatCompareTo(float val, float compare) +{ + return fabs(val - compare) < MIN_EPSILON; +} + static inline uint32_t Premul255(uint32_t colorComponent, uint32_t alpha) { if (colorComponent > MAX_15_BIT_VALUE || alpha > MAX_15_BIT_VALUE) { @@ -110,6 +130,48 @@ static inline uint32_t Unpremul255(uint32_t colorComponent, uint32_t alpha) return (result > ALPHA_OPAQUE) ? ALPHA_OPAQUE : result; } +static inline uint32_t FloatToUint(float f) +{ + uint32_t *p = reinterpret_cast(&f); + return *p; +} + +static inline float UintToFloat(uint32_t ui) +{ + float *pf = reinterpret_cast(&ui); + return *pf; +} + +static inline uint16_t FloatToHalf(float f) +{ + uint32_t u32 = FloatToUint(f); + uint16_t u16 = static_cast( + (((u32 & MAX_31_BIT_VALUE) >> SHIFT_HALF_BIT) - SHIFT_7_MASK) & MAX_16_BIT_VALUE); + u16 |= static_cast( + ((u32 & SHIFT_32_MASK) >> SHIFT_16_BIT) & MAX_16_BIT_VALUE); + return u16; +} + +static inline float HalfToFloat(uint16_t ui) +{ + uint32_t u32 = ((ui & MAX_15_BIT_VALUE) << SHIFT_HALF_BIT) + SHIFT_HALF_MASK; + u32 |= ((ui & SHIFT_16_MASK) << SHIFT_16_BIT); + return UintToFloat(u32); +} + +static inline uint16_t U8ToU16(uint8_t val1, uint8_t val2) +{ + uint16_t ret = val1; + return ((ret << SHIFT_8_BIT) | val2); +} + +static inline uint32_t HalfToUint32(const uint8_t* ui, bool isLittleEndian) +{ + uint16_t val = isLittleEndian?U8ToU16(*ui, *(ui + 1)):U8ToU16(*(ui + 1), *ui); + float fRet = HalfToFloat(val); + return static_cast (fRet); +} + using ProcFuncType = void (*)(void *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, const ProcFuncExtension &extension); class PixelConvert { diff --git a/frameworks/innerkitsimpl/converter/src/pixel_convert.cpp b/frameworks/innerkitsimpl/converter/src/pixel_convert.cpp index 08ee0cbca..144c6a79c 100644 --- a/frameworks/innerkitsimpl/converter/src/pixel_convert.cpp +++ b/frameworks/innerkitsimpl/converter/src/pixel_convert.cpp @@ -96,6 +96,18 @@ static uint16_t FillRGB565(uint32_t R, uint32_t G, uint32_t B) return ((R << SHIFT_11_BIT) | (G << SHIFT_5_BIT) | B); } +static uint64_t FillRGBAF16(float R, float G, float B, float A) +{ + uint64_t R16 = FloatToHalf(R); + uint64_t G16 = FloatToHalf(G); + uint64_t B16 = FloatToHalf(B); + uint64_t A16 = FloatToHalf(A); + if (IS_LITTLE_ENDIAN) { + return ((A16 << SHIFT_48_BIT) | (R16 << SHIFT_32_BIT) | (G16 << SHIFT_16_BIT) | B16); + } + return ((B16 << SHIFT_48_BIT) | (G16 << SHIFT_32_BIT) | (R16 << SHIFT_16_BIT) | A16); +} + constexpr uint8_t BYTE_BITS = 8; constexpr uint8_t BYTE_BITS_MAX_INDEX = 7; template @@ -215,6 +227,7 @@ constexpr uint32_t BRANCH_BGR888_TO_ARGB8888 = 0x20000001; constexpr uint32_t BRANCH_BGR888_TO_RGBA8888 = 0x20000002; constexpr uint32_t BRANCH_BGR888_TO_BGRA8888 = 0x20000003; constexpr uint32_t BRANCH_BGR888_TO_RGB565 = 0x20000004; +constexpr uint32_t BRANCH_BGR888_TO_RGBAF16 = 0x20000005; template static void BGR888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch) { @@ -234,6 +247,8 @@ static void BGR888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t G = G >> SHIFT_2_BIT; B = B >> SHIFT_3_BIT; destinationRow[i] = ((B << SHIFT_11_BIT) | (G << SHIFT_5_BIT) | R); + } else if (branch == BRANCH_BGR888_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -269,10 +284,19 @@ static void BGR888ConvertRGB565(void *destinationRow, const uint8_t *sourceRow, BGR888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_BGR888_TO_RGB565); } +static void BGR888ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + BGR888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_BGR888_TO_RGBAF16); +} + constexpr uint32_t BRANCH_RGB888_TO_ARGB8888 = 0x30000001; constexpr uint32_t BRANCH_RGB888_TO_RGBA8888 = 0x30000002; constexpr uint32_t BRANCH_RGB888_TO_BGRA8888 = 0x30000003; constexpr uint32_t BRANCH_RGB888_TO_RGB565 = 0x30000004; +constexpr uint32_t BRANCH_RGB888_TO_RGBAF16 = 0x30000005; template static void RGB888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch) { @@ -292,6 +316,8 @@ static void RGB888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t G = G >> SHIFT_2_BIT; B = B >> SHIFT_3_BIT; destinationRow[i] = FillRGB565(R, G, B); + } else if (branch == BRANCH_RGB888_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -325,10 +351,19 @@ static void RGB888ConvertRGB565(void *destinationRow, const uint8_t *sourceRow, uint16_t *newDestinationRow = static_cast(destinationRow); RGB888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGB888_TO_RGB565); } + +static void RGB888ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + RGB888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGB888_TO_RGBAF16); +} constexpr uint32_t BRANCH_RGBA8888_TO_RGBA8888_ALPHA = 0x40000001; constexpr uint32_t BRANCH_RGBA8888_TO_ARGB8888 = 0x40000002; constexpr uint32_t BRANCH_RGBA8888_TO_BGRA8888 = 0x40000003; constexpr uint32_t BRANCH_RGBA8888_TO_RGB565 = 0x40000004; +constexpr uint32_t BRANCH_RGBA8888_TO_RGBAF16 = 0x40000005; template static void RGBA8888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch, const ProcFuncExtension &extension) @@ -350,6 +385,8 @@ static void RGBA8888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_ G = G >> SHIFT_2_BIT; B = B >> SHIFT_3_BIT; destinationRow[i] = FillRGB565(R, G, B); + } else if (branch == BRANCH_RGBA8888_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -384,10 +421,18 @@ static void RGBA8888ConvertRGB565(void *destinationRow, const uint8_t *sourceRow RGBA8888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBA8888_TO_RGB565, extension); } +static void RGBA8888ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + RGBA8888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBA8888_TO_RGBAF16, extension); +} constexpr uint32_t BRANCH_BGRA8888_TO_BGRA8888_ALPHA = 0x80000001; constexpr uint32_t BRANCH_BGRA8888_TO_ARGB8888 = 0x80000002; constexpr uint32_t BRANCH_BGRA8888_TO_RGBA8888 = 0x80000003; constexpr uint32_t BRANCH_BGRA8888_TO_RGB565 = 0x80000004; +constexpr uint32_t BRANCH_BGRA8888_TO_RGBAF16 = 0x80000005; template static void BGRA8888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch, const ProcFuncExtension &extension) @@ -409,6 +454,8 @@ static void BGRA8888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_ G = G >> SHIFT_2_BIT; B = B >> SHIFT_3_BIT; destinationRow[i] = FillRGB565(R, G, B); + } else if (branch == BRANCH_BGRA8888_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -444,10 +491,19 @@ static void BGRA8888ConvertRGB565(void *destinationRow, const uint8_t *sourceRow BGRA8888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_BGRA8888_TO_RGB565, extension); } +static void BGRA8888ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + BGRA8888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_BGRA8888_TO_RGBAF16, extension); +} + constexpr uint32_t BRANCH_ARGB8888_TO_ARGB8888_ALPHA = 0x90000001; constexpr uint32_t BRANCH_ARGB8888_TO_RGBA8888 = 0x90000002; constexpr uint32_t BRANCH_ARGB8888_TO_BGRA8888 = 0x90000003; constexpr uint32_t BRANCH_ARGB8888_TO_RGB565 = 0x90000004; +constexpr uint32_t BRANCH_ARGB8888_TO_RGBAF16 = 0x90000005; template static void ARGB8888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch, const ProcFuncExtension &extension) @@ -469,6 +525,8 @@ static void ARGB8888Convert(T *destinationRow, const uint8_t *sourceRow, uint32_ G = G >> SHIFT_2_BIT; B = B >> SHIFT_3_BIT; destinationRow[i] = FillRGB565(R, G, B); + } else if (branch == BRANCH_ARGB8888_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -504,11 +562,20 @@ static void ARGB8888ConvertRGB565(void *destinationRow, const uint8_t *sourceRow ARGB8888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_ARGB8888_TO_RGB565, extension); } +static void ARGB8888ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + ARGB8888Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_ARGB8888_TO_RGBAF16, extension); +} + constexpr uint32_t BRANCH_RGB161616_TO_ARGB8888 = 0x50000001; constexpr uint32_t BRANCH_RGB161616_TO_ABGR8888 = 0x50000002; constexpr uint32_t BRANCH_RGB161616_TO_RGBA8888 = 0x50000003; constexpr uint32_t BRANCH_RGB161616_TO_BGRA8888 = 0x50000004; constexpr uint32_t BRANCH_RGB161616_TO_RGB565 = 0x50000005; +constexpr uint32_t BRANCH_RGB161616_TO_RGBAF16 = 0x50000006; template static void RGB161616Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch) { @@ -530,6 +597,8 @@ static void RGB161616Convert(T *destinationRow, const uint8_t *sourceRow, uint32 G = G >> SHIFT_2_BIT; B = B >> SHIFT_3_BIT; destinationRow[i] = FillRGB565(R, G, B); + } else if (branch == BRANCH_RGB161616_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -572,10 +641,19 @@ static void RGB161616ConvertRGB565(void *destinationRow, const uint8_t *sourceRo RGB161616Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGB161616_TO_RGB565); } +static void RGB161616ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + RGB161616Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGB161616_TO_RGBAF16); +} + constexpr uint32_t BRANCH_RGBA16161616_TO_ARGB8888 = 0x60000001; constexpr uint32_t BRANCH_RGBA16161616_TO_ABGR8888 = 0x60000002; constexpr uint32_t BRANCH_RGBA16161616_TO_RGBA8888 = 0x60000003; constexpr uint32_t BRANCH_RGBA16161616_TO_BGRA8888 = 0x60000004; +constexpr uint32_t BRANCH_RGBA16161616_TO_RGBAF16 = 0x60000005; template static void RGBA16161616Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch, const ProcFuncExtension &extension) @@ -594,6 +672,8 @@ static void RGBA16161616Convert(T *destinationRow, const uint8_t *sourceRow, uin destinationRow[i] = FillRGBA8888(A, B, G, R); } else if (branch == BRANCH_RGBA16161616_TO_BGRA8888) { destinationRow[i] = FillBGRA8888(A, B, G, R); + } else if (branch == BRANCH_RGBA16161616_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -629,6 +709,14 @@ static void RGBA16161616ConvertBGRA8888(void *destinationRow, const uint8_t *sou RGBA16161616Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBA16161616_TO_BGRA8888, extension); } +static void RGBA16161616ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + RGBA16161616Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBA16161616_TO_RGBAF16, extension); +} + constexpr uint32_t BRANCH_CMYK_TO_ARGB8888 = 0x70000001; constexpr uint32_t BRANCH_CMYK_TO_ABGR8888 = 0x70000002; constexpr uint32_t BRANCH_CMYK_TO_RGBA8888 = 0x70000003; @@ -704,6 +792,7 @@ static void CMYKConvertRGB565(void *destinationRow, const uint8_t *sourceRow, ui constexpr uint32_t BRANCH_RGB565_TO_ARGB8888 = 0x11000001; constexpr uint32_t BRANCH_RGB565_TO_RGBA8888 = 0x11000002; constexpr uint32_t BRANCH_RGB565_TO_BGRA8888 = 0x11000003; +constexpr uint32_t BRANCH_RGB565_TO_RGBAF16 = 0x11000004; template static void RGB565Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch) { @@ -718,6 +807,8 @@ static void RGB565Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t destinationRow[i] = FillRGBA8888(R, G, B, A); } else if (branch == BRANCH_RGB565_TO_BGRA8888) { destinationRow[i] = FillBGRA8888(B, G, R, A); + } else if (branch == BRANCH_RGB565_TO_RGBAF16) { + destinationRow[i] = FillRGBAF16(R, G, B, A); } else { break; } @@ -746,6 +837,89 @@ static void RGB565ConvertBGRA8888(void *destinationRow, const uint8_t *sourceRow RGB565Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGB565_TO_BGRA8888); } +static void RGB565ConvertRGBAF16(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint64_t *newDestinationRow = static_cast(tmp); + RGB565Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGB565_TO_RGBAF16); +} + +constexpr uint32_t BRANCH_RGBAF16_TO_ARGB8888 = 0x13000001; +constexpr uint32_t BRANCH_RGBAF16_TO_RGBA8888 = 0x13000002; +constexpr uint32_t BRANCH_RGBAF16_TO_BGRA8888 = 0x13000003; +constexpr uint32_t BRANCH_RGBAF16_TO_ABGR8888 = 0x13000004; +constexpr uint32_t BRANCH_RGBAF16_TO_RGB565 = 0x13000005; +template +static void RGBAF16Convert(T *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, uint32_t branch, + const ProcFuncExtension &extension) +{ + for (uint32_t i = 0; i < sourceWidth; i++) { + uint32_t R = HalfToUint32(sourceRow, IS_LITTLE_ENDIAN); + uint32_t G = HalfToUint32(sourceRow + 2, IS_LITTLE_ENDIAN); + uint32_t B = HalfToUint32(sourceRow + 4, IS_LITTLE_ENDIAN); + uint32_t A = HalfToUint32(sourceRow + 6, IS_LITTLE_ENDIAN); + AlphaTypeConvertOnRGB(A, R, G, B, extension); + if (branch == BRANCH_RGBAF16_TO_ARGB8888) { + destinationRow[i] = FillARGB8888(A, R, G, B); + } else if (branch == BRANCH_RGBAF16_TO_RGBA8888) { + destinationRow[i] = FillRGBA8888(R, G, B, A); + } else if (branch == BRANCH_RGBAF16_TO_BGRA8888) { + destinationRow[i] = FillBGRA8888(B, G, R, A); + } else if (branch == BRANCH_RGBAF16_TO_ABGR8888) { + destinationRow[i] = FillABGR8888(A, B, G, R); + } else if (branch == BRANCH_RGBAF16_TO_RGB565) { + R = R >> SHIFT_3_BIT; + G = G >> SHIFT_2_BIT; + B = B >> SHIFT_3_BIT; + destinationRow[i] = FillRGB565(R, G, B); + } else { + break; + } + sourceRow += SIZE_8_BYTE; + } +} + +static void RGBAF16ConvertARGB8888(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint32_t *newDestinationRow = static_cast(tmp); + RGBAF16Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBAF16_TO_ARGB8888, extension); +} + +static void RGBAF16ConvertRGBA8888(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint32_t *newDestinationRow = static_cast(tmp); + RGBAF16Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBAF16_TO_RGBA8888, extension); +} + +static void RGBAF16ConvertBGRA8888(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint32_t *newDestinationRow = static_cast(tmp); + RGBAF16Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBAF16_TO_BGRA8888, extension); +} + +static void RGBAF16ConvertABGR8888(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint32_t *newDestinationRow = static_cast(tmp); + RGBAF16Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBAF16_TO_ABGR8888, extension); +} + +static void RGBAF16ConvertRGB565(uint8_t *destinationRow, const uint8_t *sourceRow, uint32_t sourceWidth, + const ProcFuncExtension &extension) +{ + void* tmp = static_cast(destinationRow); + uint16_t *newDestinationRow = static_cast(tmp); + RGBAF16Convert(newDestinationRow, sourceRow, sourceWidth, BRANCH_RGBAF16_TO_RGB565, extension); +} + static map g_procMapping; static mutex g_procMutex; @@ -822,6 +996,37 @@ static void InitCMYKProc() g_procMapping.emplace(MakeKey(CMKY, RGB_565), &CMYKConvertRGB565); } +static void InitF16Proc() +{ + g_procMapping.emplace(MakeKey(RGBA_F16, ARGB_8888), + reinterpret_cast(&RGBAF16ConvertARGB8888)); + g_procMapping.emplace(MakeKey(RGBA_F16, RGBA_8888), + reinterpret_cast(&RGBAF16ConvertRGBA8888)); + g_procMapping.emplace(MakeKey(RGBA_F16, BGRA_8888), + reinterpret_cast(&RGBAF16ConvertBGRA8888)); + g_procMapping.emplace(MakeKey(RGBA_F16, ABGR_8888), + reinterpret_cast(&RGBAF16ConvertABGR8888)); + g_procMapping.emplace(MakeKey(RGBA_F16, RGB_565), + reinterpret_cast(&RGBAF16ConvertRGB565)); + + g_procMapping.emplace(MakeKey(BGR_888, RGBA_F16), + reinterpret_cast(&BGR888ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(RGB_888, RGBA_F16), + reinterpret_cast(&RGB888ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(RGB_161616, RGBA_F16), + reinterpret_cast(&RGB161616ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(ARGB_8888, RGBA_F16), + reinterpret_cast(&ARGB8888ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(RGBA_8888, RGBA_F16), + reinterpret_cast(&RGBA8888ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(BGRA_8888, RGBA_F16), + reinterpret_cast(&BGRA8888ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(RGB_565, RGBA_F16), + reinterpret_cast(&RGB565ConvertRGBAF16)); + g_procMapping.emplace(MakeKey(RGBA_16161616, RGBA_F16), + reinterpret_cast(&RGBA16161616ConvertRGBAF16)); +} + static ProcFuncType GetProcFuncType(uint32_t srcPixelFormat, uint32_t dstPixelFormat) { unique_lock guard(g_procMutex); @@ -830,6 +1035,7 @@ static ProcFuncType GetProcFuncType(uint32_t srcPixelFormat, uint32_t dstPixelFo InitRGBProc(); InitRGBAProc(); InitCMYKProc(); + InitF16Proc(); } guard.unlock(); string procKey = MakeKey(srcPixelFormat, dstPixelFormat); @@ -901,4 +1107,4 @@ void PixelConvert::Convert(void *destinationPixels, const uint8_t *sourcePixels, procFunc_(destinationPixels, sourcePixels, sourcePixelsNum, procFuncExtension_); } } // namespace Media -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkitsimpl/pixelconverter/src/pixel_convert_adapter.cpp b/frameworks/innerkitsimpl/pixelconverter/src/pixel_convert_adapter.cpp index 8395dda72..5d0273339 100644 --- a/frameworks/innerkitsimpl/pixelconverter/src/pixel_convert_adapter.cpp +++ b/frameworks/innerkitsimpl/pixelconverter/src/pixel_convert_adapter.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "pixel_convert_adapter.h" +#include #include "include/core/SkBitmap.h" #include "include/core/SkCanvas.h" #include "include/core/SkColor.h" @@ -21,6 +21,7 @@ #include "include/core/SkImageInfo.h" #include "include/core/SkPaint.h" #include "include/core/SkPixmap.h" +#include "pixel_convert_adapter.h" #ifdef _WIN32 #include #endif @@ -28,30 +29,75 @@ namespace OHOS { namespace Media { using namespace OHOS::HiviewDFX; +using namespace std; static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelConvertAdapter" }; +static const uint8_t NUM_0 = 0; +static const uint8_t NUM_1 = 1; +static const uint8_t NUM_2 = 2; +static const uint8_t NUM_3 = 3; +static const uint8_t NUM_4 = 4; + +static const map PIXEL_FORMAT_MAP = { + { PixelFormat::UNKNOWN, SkColorType::kUnknown_SkColorType}, + { PixelFormat::ARGB_8888, SkColorType::kRGBA_8888_SkColorType}, + { PixelFormat::ALPHA_8, SkColorType::kAlpha_8_SkColorType}, + { PixelFormat::RGB_565, SkColorType::kRGB_565_SkColorType}, + { PixelFormat::RGBA_F16, SkColorType::kRGBA_F16_SkColorType}, + { PixelFormat::RGBA_8888, SkColorType::kRGBA_8888_SkColorType}, + { PixelFormat::BGRA_8888, SkColorType::kBGRA_8888_SkColorType} +}; static SkColorType PixelFormatConvert(const PixelFormat &pixelFormat) { - SkColorType colorType; - switch (pixelFormat) { - case PixelFormat::BGRA_8888: - colorType = SkColorType::kBGRA_8888_SkColorType; - break; - case PixelFormat::RGBA_8888: - colorType = SkColorType::kRGBA_8888_SkColorType; - break; - case PixelFormat::RGB_565: - colorType = SkColorType::kRGB_565_SkColorType; - break; - case PixelFormat::ALPHA_8: - colorType = SkColorType::kAlpha_8_SkColorType; - break; - default: - colorType = SkColorType::kUnknown_SkColorType; - break; + auto formatSearch = PIXEL_FORMAT_MAP.find(pixelFormat); + return (formatSearch != PIXEL_FORMAT_MAP.end()) ? formatSearch->second : SkColorType::kUnknown_SkColorType; +} + +static void ARGBToRGBA(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount) +{ + if (byteCount % NUM_4 != NUM_0) { + HiLog::Error(LABEL, "Pixel count must multiple of 4."); + return; + } + uint8_t *src = srcPixels; + uint8_t *dst = dstPixels; + uint8_t A, R, G, B; + for (uint32_t i = NUM_0 ; i < byteCount; i += NUM_4) { + A = src[NUM_0]; + R = src[NUM_1]; + G = src[NUM_2]; + B = src[NUM_3]; + dst[NUM_0] = R; + dst[NUM_1] = G; + dst[NUM_2] = B; + dst[NUM_3] = A; + src += NUM_4; + dst += NUM_4; + } +} + +static void RGBAToARGB(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount) +{ + if (byteCount % NUM_4 != NUM_0) { + HiLog::Error(LABEL, "Pixel count must multiple of 4."); + return; + } + uint8_t *src = srcPixels; + uint8_t *dst = dstPixels; + uint8_t A, R, G, B; + for (uint32_t i = NUM_0 ; i < byteCount; i += NUM_4) { + R = src[NUM_0]; + G = src[NUM_1]; + B = src[NUM_2]; + A = src[NUM_3]; + dst[NUM_0] = A; + dst[NUM_1] = R; + dst[NUM_2] = G; + dst[NUM_3] = B; + src += NUM_4; + dst += NUM_4; } - return colorType; } bool PixelConvertAdapter::WritePixelsConvert(const void *srcPixels, uint32_t srcRowBytes, const ImageInfo &srcInfo, @@ -63,15 +109,21 @@ bool PixelConvertAdapter::WritePixelsConvert(const void *srcPixels, uint32_t src HiLog::Error(LABEL, "src or dst pixels invalid."); return false; } + SkAlphaType srcAlphaType = static_cast(srcInfo.alphaType); SkAlphaType dstAlphaType = static_cast(dstInfo.alphaType); SkColorType srcColorType = PixelFormatConvert(srcInfo.pixelFormat); SkColorType dstColorType = PixelFormatConvert(dstInfo.pixelFormat); SkImageInfo srcImageInfo = SkImageInfo::Make(srcInfo.size.width, srcInfo.size.height, srcColorType, srcAlphaType); SkImageInfo dstImageInfo = SkImageInfo::Make(dstInfo.size.width, dstInfo.size.height, dstColorType, dstAlphaType); - SkBitmap dstBitmap; SkPixmap srcPixmap(srcImageInfo, srcPixels, srcRowBytes); + + if (srcInfo.pixelFormat == PixelFormat::ARGB_8888) { + uint8_t* src = static_cast(srcPixmap.writable_addr()); + ARGBToRGBA(src, src, srcRowBytes * srcInfo.size.height); + } + if (!dstBitmap.installPixels(dstImageInfo, dstPixels, dstRowBytes)) { HiLog::Error(LABEL, "WritePixelsConvert dst bitmap install pixels failed."); return false; @@ -81,6 +133,11 @@ bool PixelConvertAdapter::WritePixelsConvert(const void *srcPixels, uint32_t src return false; } + if (dstInfo.pixelFormat == PixelFormat::ARGB_8888) { + uint32_t dstSize = dstRowBytes * dstInfo.size.height; + RGBAToARGB(static_cast(dstPixels), static_cast(dstPixels), dstSize); + } + return true; } @@ -136,4 +193,4 @@ bool PixelConvertAdapter::EraseBitmap(const void *srcPixels, uint32_t srcRowByte return true; } } // namespace Media -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/js/common/image_source_napi.cpp b/frameworks/kits/js/common/image_source_napi.cpp index e990f931e..c97003651 100644 --- a/frameworks/kits/js/common/image_source_napi.cpp +++ b/frameworks/kits/js/common/image_source_napi.cpp @@ -381,7 +381,7 @@ static bool ParseRegion(napi_env env, napi_value root, Rect* region) static bool IsSupportPixelFormat(int32_t val) { if (val >= static_cast(PixelFormat::UNKNOWN) && - val <= static_cast(PixelFormat::BGRA_8888)) { + val <= static_cast(PixelFormat::RGBA_F16)) { return true; } diff --git a/plugins/common/libs/image/libjpegplugin/include/jpeg_encoder.h b/plugins/common/libs/image/libjpegplugin/include/jpeg_encoder.h index 63d1da005..46a15db65 100644 --- a/plugins/common/libs/image/libjpegplugin/include/jpeg_encoder.h +++ b/plugins/common/libs/image/libjpegplugin/include/jpeg_encoder.h @@ -43,6 +43,7 @@ private: void SetYuv420spExtraConfig(); uint32_t SequenceEncoder(const uint8_t *data); uint32_t Yuv420spEncoder(const uint8_t *data); + uint32_t RGBAF16Encoder(const uint8_t *data); static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "JpegEncoder" }; jpeg_compress_struct encodeInfo_; JpegDstMgr dstMgr_; diff --git a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp index 88ae731c9..81c234db4 100644 --- a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp @@ -14,8 +14,9 @@ */ #include "jerror.h" -#include "jpeg_encoder.h" #include "media_errors.h" +#include "pixel_convert.h" +#include "jpeg_encoder.h" namespace OHOS { namespace ImagePlugin { @@ -28,6 +29,7 @@ constexpr uint32_t COMPONENT_NUM_RGBA = 4; constexpr uint32_t COMPONENT_NUM_BGRA = 4; constexpr uint32_t COMPONENT_NUM_RGB = 3; constexpr uint32_t COMPONENT_NUM_GRAY = 1; +constexpr uint32_t PIXEL_SIZE_RGBA_F16 = 8; // yuv format constexpr uint8_t COMPONENT_NUM_YUV420SP = 3; constexpr uint8_t Y_SAMPLE_ROW = 16; @@ -75,6 +77,7 @@ J_COLOR_SPACE JpegEncoder::GetEncodeFormat(PixelFormat format, int32_t &componen J_COLOR_SPACE colorSpace = JCS_UNKNOWN; int32_t components = 0; switch (format) { + case PixelFormat::RGBA_F16: case PixelFormat::RGBA_8888: { colorSpace = JCS_EXT_RGBA; components = COMPONENT_NUM_RGBA; @@ -145,6 +148,8 @@ uint32_t JpegEncoder::FinalizeEncode() PixelFormat pixelFormat = pixelMaps_[0]->GetPixelFormat(); if (pixelFormat == PixelFormat::NV21 || pixelFormat == PixelFormat::NV12) { errorCode = Yuv420spEncoder(data); + } else if (pixelFormat == PixelFormat::RGBA_F16) { + errorCode = RGBAF16Encoder(data); } else { errorCode = SequenceEncoder(data); } @@ -277,10 +282,35 @@ void JpegEncoder::Deinterweave(uint8_t *uvPlane, uint8_t *uPlane, uint8_t *vPlan } } +uint32_t JpegEncoder::RGBAF16Encoder(const uint8_t *data) +{ + if (setjmp(jerr_.setjmp_buffer)) { + HiLog::Error(LABEL, "encode image error."); + return ERR_IMAGE_ENCODE_FAILED; + } + jpeg_start_compress(&encodeInfo_, TRUE); + uint8_t *base = const_cast(data); + uint32_t rowStride = encodeInfo_.image_width * encodeInfo_.input_components; + uint32_t orgRowStride = encodeInfo_.image_width * PIXEL_SIZE_RGBA_F16; + uint8_t *buffer = nullptr; + auto rowBuffer = std::make_unique(rowStride); + while (encodeInfo_.next_scanline < encodeInfo_.image_height) { + buffer = base + encodeInfo_.next_scanline * orgRowStride; + for (uint32_t i = 0; i < rowStride;i++) { + float orgPlane = HalfToFloat(U8ToU16(buffer[i*2], buffer[i*2+1])); + rowBuffer[i] = static_cast(orgPlane/MAX_HALF*ALPHA_OPAQUE); + } + uint8_t *rowBufferPtr = rowBuffer.get(); + jpeg_write_scanlines(&encodeInfo_, &rowBufferPtr, RW_LINE_NUM); + } + jpeg_finish_compress(&encodeInfo_); + return SUCCESS; +} + JpegEncoder::~JpegEncoder() { jpeg_destroy_compress(&encodeInfo_); pixelMaps_.clear(); } } // namespace ImagePlugin -} // namespace OHOS +} // namespace OHOS \ No newline at end of file -- Gitee From d2b005b1e1a91241861ae9276aa7d643d55d0593 Mon Sep 17 00:00:00 2001 From: zewu-feng Date: Fri, 20 May 2022 16:31:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Exif=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zewu-feng --- .../image/libjpegplugin/include/exif_info.h | 8 ++- .../image/libjpegplugin/src/exif_info.cpp | 61 ++++++------------- .../image/libjpegplugin/src/jpeg_decoder.cpp | 22 ++++++- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/plugins/common/libs/image/libjpegplugin/include/exif_info.h b/plugins/common/libs/image/libjpegplugin/include/exif_info.h index fb1e9a1a2..504b0c123 100644 --- a/plugins/common/libs/image/libjpegplugin/include/exif_info.h +++ b/plugins/common/libs/image/libjpegplugin/include/exif_info.h @@ -50,12 +50,16 @@ public: std::string gpsLatitudeRef_; std::string gpsLongitudeRef_; std::string dateTimeOriginal_; // Original date and time. + std::string exposureTime_; + std::string fNumber_; + std::string isoSpeedRatings_; + std::string sceneType_; private: void SetExifTagValues(const ExifTag &tag, const std::string &value); ExifEntry* InitExifTag(ExifData *exif, ExifIfd ifd, ExifTag tag); ExifEntry* CreateExifTag(ExifData *exif, ExifIfd ifd, ExifTag tag, size_t len, ExifFormat format); - unsigned long GetFileSize(FILE *fp); + long GetFileSize(FILE *fp); void ReleaseSource(unsigned char **ptrBuf, FILE **ptrFile); bool CreateExifData(unsigned char *buf, unsigned long length, ExifData **data, bool &isNewExifData); unsigned int GetOrginExifDataLength(const bool &isNewExifData, unsigned char *buf); @@ -72,4 +76,4 @@ private: }; } // namespace ImagePlugin } // namespace OHOS -#endif // EXIF_INFO_H +#endif // EXIF_INFO_H \ No newline at end of file diff --git a/plugins/common/libs/image/libjpegplugin/src/exif_info.cpp b/plugins/common/libs/image/libjpegplugin/src/exif_info.cpp index 780174b55..22b1de904 100644 --- a/plugins/common/libs/image/libjpegplugin/src/exif_info.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/exif_info.cpp @@ -38,6 +38,7 @@ namespace { static const int BUFFER_POSITION_13 = 13; static const int LENGTH_OFFSET_2 = 2; static const int MOVE_OFFSET_8 = 8; + static const int LENGTH_ARRAY_SIZE = 2; static const int CONSTANT_2 = 2; static const unsigned long MAX_FILE_SIZE = 1000 * 1000 * 1000; @@ -114,6 +115,14 @@ void EXIFInfo::SetExifTagValues(const ExifTag &tag, const std::string &value) gpsLongitudeRef_ = value; } else if (tag == EXIF_TAG_DATE_TIME_ORIGINAL) { dateTimeOriginal_ = value; + } else if (tag == EXIF_TAG_EXPOSURE_TIME) { + exposureTime_ = value; + } else if (tag == EXIF_TAG_FNUMBER) { + fNumber_ = value; + } else if (tag == EXIF_TAG_ISO_SPEED_RATINGS) { + isoSpeedRatings_ = value; + } else if (tag == EXIF_TAG_SCENE_TYPE) { + sceneType_ = value; } else { HiLog::Error(LABEL, "No match tag name!"); } @@ -476,7 +485,7 @@ ExifEntry* EXIFInfo::CreateExifTag(ExifData *exif, ExifIfd ifd, ExifTag tag, return entry; } -unsigned long EXIFInfo::GetFileSize(FILE *fp) +long EXIFInfo::GetFileSize(FILE *fp) { long int position; long size; @@ -493,7 +502,7 @@ unsigned long EXIFInfo::GetFileSize(FILE *fp) /* Jump back to the original position. */ (void)fseek(fp, position, SEEK_SET); - return static_cast(size); + return size; } bool EXIFInfo::CreateExifData(unsigned char *buf, unsigned long length, ExifData **ptrData, bool &isNewExifData) @@ -530,8 +539,10 @@ unsigned int EXIFInfo::GetOrginExifDataLength(const bool &isNewExifData, unsigne { unsigned int orginExifDataLength = 0; if (!isNewExifData) { - orginExifDataLength = static_cast(buf[BUFFER_POSITION_5]) | - static_cast(buf[BUFFER_POSITION_4] << MOVE_OFFSET_8); + unsigned char lenthArray[LENGTH_ARRAY_SIZE] = { + buf[BUFFER_POSITION_5], buf[BUFFER_POSITION_4] + }; + orginExifDataLength = *(unsigned int*)lenthArray; } return orginExifDataLength; } @@ -555,10 +566,6 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st switch (tag) { case EXIF_TAG_BITS_PER_SAMPLE: { *ptrEntry = InitExifTag(data, EXIF_IFD_1, EXIF_TAG_BITS_PER_SAMPLE); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } std::vector bitsVec; SplitStr(value, ",", bitsVec); if (bitsVec.size() > CONSTANT_2) { @@ -574,28 +581,16 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st } case EXIF_TAG_ORIENTATION: { *ptrEntry = InitExifTag(data, EXIF_IFD_0, EXIF_TAG_ORIENTATION); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } exif_set_short((*ptrEntry)->data, order, (ExifShort)atoi(value.c_str())); break; } case EXIF_TAG_IMAGE_LENGTH: { *ptrEntry = InitExifTag(data, EXIF_IFD_1, EXIF_TAG_IMAGE_LENGTH); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } exif_set_long((*ptrEntry)->data, order, (ExifLong)atoi(value.c_str())); break; } case EXIF_TAG_IMAGE_WIDTH: { *ptrEntry = InitExifTag(data, EXIF_IFD_1, EXIF_TAG_IMAGE_WIDTH); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } exif_set_long((*ptrEntry)->data, order, (ExifLong)atoi(value.c_str())); break; } @@ -608,14 +603,10 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st } ExifRational latRational; - latRational.numerator = static_cast(atoi(latVec[0].c_str())); - latRational.denominator = static_cast(atoi(latVec[1].c_str())); + latRational.numerator = atoi(latVec[0].c_str()); + latRational.denominator = atoi(latVec[1].c_str()); *ptrEntry = CreateExifTag(data, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE, sizeof(latRational), EXIF_FORMAT_RATIONAL); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } exif_set_rational((*ptrEntry)->data, order, latRational); break; } @@ -628,24 +619,16 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st } ExifRational longRational; - longRational.numerator = static_cast(atoi(longVec[0].c_str())); - longRational.denominator = static_cast(atoi(longVec[1].c_str())); + longRational.numerator = atoi(longVec[0].c_str()); + longRational.denominator = atoi(longVec[1].c_str()); *ptrEntry = CreateExifTag(data, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE, sizeof(longRational), EXIF_FORMAT_RATIONAL); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } exif_set_rational((*ptrEntry)->data, order, longRational); break; } case EXIF_TAG_GPS_LATITUDE_REF: { *ptrEntry = CreateExifTag(data, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE_REF, value.length(), EXIF_FORMAT_ASCII); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } if (memcpy_s((*ptrEntry)->data, value.length(), value.c_str(), value.length()) != 0) { HiLog::Error(LABEL, "LATITUDE ref memcpy error"); } @@ -654,10 +637,6 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st case EXIF_TAG_GPS_LONGITUDE_REF: { *ptrEntry = CreateExifTag(data, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE_REF, value.length(), EXIF_FORMAT_ASCII); - if ((*ptrEntry) == nullptr) { - HiLog::Error(LABEL, "Get exif entry failed."); - return false; - } if (memcpy_s((*ptrEntry)->data, value.length(), value.c_str(), value.length()) != 0) { HiLog::Error(LABEL, "LONGITUDE ref memcpy error"); } @@ -756,4 +735,4 @@ void EXIFInfo::UpdateCacheExifData(FILE *fp) fileBuf = nullptr; } } // namespace ImagePlugin -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp b/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp index 155728a5a..4b901cde6 100644 --- a/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp @@ -58,6 +58,10 @@ const std::string GPS_LONGITUDE = "GPSLongitude"; const std::string GPS_LATITUDE_REF = "GPSLatitudeRef"; const std::string GPS_LONGITUDE_REF = "GPSLongitudeRef"; const std::string DATE_TIME_ORIGINAL = "DateTimeOriginal"; +const std::string EXPOSURE_TIME = "ExposureTime"; +const std::string F_NUMBER = "FNumber"; +const std::string ISO_SPEED_RATINGS = "ISOSpeedRatings"; +const std::string SCENE_TYPE = "SceneType"; } // namespace PluginServer &JpegDecoder::pluginServer_ = DelayedRefSingleton::GetInstance(); @@ -593,6 +597,14 @@ uint32_t JpegDecoder::GetImagePropertyString(uint32_t index, const std::string & value = exifInfo_.gpsLongitudeRef_; } else if (IsSameTextStr(key, DATE_TIME_ORIGINAL)) { value = exifInfo_.dateTimeOriginal_; + } else if (IsSameTextStr(key, EXPOSURE_TIME)) { + value = exifInfo_.exposureTime_; + } else if (IsSameTextStr(key, F_NUMBER)) { + value = exifInfo_.fNumber_; + } else if (IsSameTextStr(key, ISO_SPEED_RATINGS)) { + value = exifInfo_.isoSpeedRatings_; + } else if (IsSameTextStr(key, SCENE_TYPE)) { + value = exifInfo_.sceneType_; } else { return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT; } @@ -620,6 +632,14 @@ ExifTag JpegDecoder::getExifTagFromKey(const std::string &key) return EXIF_TAG_GPS_LONGITUDE_REF; } else if (IsSameTextStr(key, DATE_TIME_ORIGINAL)) { return EXIF_TAG_DATE_TIME_ORIGINAL; + } else if (IsSameTextStr(key, EXPOSURE_TIME)) { + return EXIF_TAG_EXPOSURE_TIME; + } else if (IsSameTextStr(key, F_NUMBER)) { + return EXIF_TAG_FNUMBER; + } else if (IsSameTextStr(key, ISO_SPEED_RATINGS)) { + return EXIF_TAG_ISO_SPEED_RATINGS; + } else if (IsSameTextStr(key, SCENE_TYPE)) { + return EXIF_TAG_SCENE_TYPE; } else { return EXIF_TAG_PRINT_IMAGE_MATCHING; } @@ -676,4 +696,4 @@ uint32_t JpegDecoder::ModifyImageProperty(uint32_t index, const std::string &key return Media::SUCCESS; } } // namespace ImagePlugin -} // namespace OHOS +} // namespace OHOS \ No newline at end of file -- Gitee