diff --git a/frameworks/innerkitsimpl/test/BUILD.gn b/frameworks/innerkitsimpl/test/BUILD.gn index e0b8f8be23bee7aa106c204d9affb77827c74909..c713de5b36d70da5d2d0f80da7e8de03012bb780 100644 --- a/frameworks/innerkitsimpl/test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/BUILD.gn @@ -247,6 +247,7 @@ ohos_unittest("imagepixelmaptest") { "googletest:gtest_main", "graphic_2d:color_manager", "hilog:libhilog", + "skia:skia_canvaskit", ] if (use_clang_android || use_clang_ios) { external_deps -= [ "graphic_2d:color_manager" ] diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index c5fb1ff9ae8fde27d1b5830d8407adb03f673f58..d2072fae07a4a67944315d7214e56a8593758084 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -262,12 +262,12 @@ if (use_clang_android) { "ipc:ipc_core", "libjpeg-turbo:turbojpeg", "napi:ace_napi", - "skia:skia_canvaskit", "zlib:libz", ] public_external_deps = [ "graphic_2d:color_manager", "graphic_surface:surface", + "skia:skia_canvaskit", ] if (enable_libexif) { external_deps += [ "libexif:libexif" ] diff --git a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp index df93e731956d2a8b929fc4743c2e94f5236a5900..980e16880eb6a1bd88dc37613e9dd2ab3734b544 100644 --- a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp +++ b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp @@ -67,6 +67,8 @@ #include "include/codec/SkCodecAnimation.h" #include "modules/skcms/src/skcms_public.h" #endif +#include "src/binary_parse/range_checked_byte_ptr.h" +#include "src/image_type_recognition/image_type_recognition_lite.h" #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) #define DMA_BUF_SET_TYPE _IOW(DMA_BUF_BASE, 2, const char *) @@ -133,6 +135,8 @@ using namespace OHOS::HDI::Base; using namespace OHOS::HDI::Display::Composer; #endif using namespace std; +using piex::binary_parse::RangeCheckedBytePtr; +using piex::image_type_recognition::RecognizeRawImageTypeLite; const static string DEFAULT_EXIF_VALUE = "default_exif_value"; const static string CODEC_INITED_KEY = "CodecInited"; @@ -215,6 +219,19 @@ static const map FORMAT_NAME = { { SkEncodedImageFormat::kHEIF, "image/heif" }, }; +static const map RAW_FORMAT_NAME = { + { piex::image_type_recognition::kArwImage, "image/x-sony-arw" }, + { piex::image_type_recognition::kCr2Image, "image/x-canon-cr2" }, + { piex::image_type_recognition::kDngImage, "image/x-adobe-dng" }, + { piex::image_type_recognition::kNefImage, "image/x-nikon-nef" }, + { piex::image_type_recognition::kNrwImage, "image/x-nikon-nrw" }, + { piex::image_type_recognition::kOrfImage, "image/x-olympus-orf" }, + { piex::image_type_recognition::kPefImage, "image/x-pentax-pef" }, + { piex::image_type_recognition::kRafImage, "image/x-fuji-raf" }, + { piex::image_type_recognition::kRw2Image, "image/x-panasonic-rw2" }, + { piex::image_type_recognition::kSrwImage, "image/x-samsung-srw" }, +}; + #if !defined(CROSS_PLATFORM) static const map PIXELFORMAT_TOGRAPHIC_MAP = { {PixelFormat::RGBA_1010102, GRAPHIC_PIXEL_FMT_RGBA_1010102}, @@ -2313,6 +2330,29 @@ uint32_t ExtDecoder::GetImagePropertyInt(uint32_t index, const std::string &key, return Media::ERR_MEDIA_VALUE_INVALID; } +bool ExtDecoder::IsRawFormat(std::string &name) +{ + CHECK_ERROR_RETURN_RET(stream_ == nullptr, false); + ImagePlugin::DataStreamBuffer outData; + uint32_t savedPosition = stream_->Tell(); + stream_->Seek(0); + if (!stream_->Peek(RAW_MIN_BYTEREAD, outData)) { + IMAGE_LOGE("IsRawFormat peek data fail."); + stream_->Seek(savedPosition); + return false; + } else { + stream_->Seek(savedPosition); + piex::binary_parse::RangeCheckedBytePtr header_buffer(outData.inputStreamBuffer, outData.dataSize); + piex::image_type_recognition::RawImageTypes type = RecognizeRawImageTypeLite(header_buffer); + auto rawFormatNameIter = RAW_FORMAT_NAME.find(type); + if (rawFormatNameIter != RAW_FORMAT_NAME.end() && !rawFormatNameIter->second.empty()) { + name = rawFormatNameIter->second; + return true; + } + } + return false; +} + OHOS::Media::Size ExtDecoder::GetHeifGridTileSize() { #ifdef HEIF_HW_DECODE_ENABLE @@ -2341,7 +2381,7 @@ uint32_t ExtDecoder::GetImagePropertyString(uint32_t index, const std::string &k if (ENCODED_FORMAT_KEY.compare(key) == ZERO) { SkEncodedImageFormat format = codec_->getEncodedFormat(); if ((format == SkEncodedImageFormat::kJPEG || format == SkEncodedImageFormat::kDNG) && - ImageUtils::GetAPIVersion() >= APIVERSION_20) { + ImageUtils::GetAPIVersion() >= APIVERSION_20 && IsRawFormat(value)) { return SUCCESS; } else { return GetFormatName(format, value);