mirror of
https://gitee.com/openharmony/multimedia_image_framework
synced 2024-11-27 17:22:40 +00:00
STD代码合入
Signed-off-by: zewu-feng <fengzewu@huawei.com>
This commit is contained in:
parent
2827a6dce2
commit
530fb4d2a4
@ -380,6 +380,16 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOpt
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
// add graphic colorspace object to pixelMap.
|
||||
bool isSupportICCProfile = mainDecoder_->IsSupportICCProfile();
|
||||
if (isSupportICCProfile) {
|
||||
OHOS::ColorManager::ColorSpace grColorSpace = mainDecoder_->getGrColorSpace();
|
||||
pixelMap->InnerSetColorSpace(grColorSpace);
|
||||
}
|
||||
#endif
|
||||
|
||||
pixelMap->SetPixelsAddr(context.pixelsBuffer.buffer, context.pixelsBuffer.context, context.pixelsBuffer.bufferSize,
|
||||
context.allocatorType, context.freeFunc);
|
||||
DecodeOptions procOpts;
|
||||
|
@ -1630,5 +1630,17 @@ uint32_t PixelMap::crop(const Rect &rect)
|
||||
};
|
||||
return postProc.ConvertProc(rect, dstImageInfo, *this, imageInfo_);
|
||||
}
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
void PixelMap::InnerSetColorSpace(const OHOS::ColorManager::ColorSpace &grColorSpace)
|
||||
{
|
||||
grColorSpace_ = OHOS::ColorManager::ColorSpace(grColorSpace.ToSkColorSpace());
|
||||
}
|
||||
|
||||
OHOS::ColorManager::ColorSpace PixelMap::InnerGetGrColorSpace()
|
||||
{
|
||||
return grColorSpace_;
|
||||
}
|
||||
#endif
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -161,16 +161,53 @@ ohos_unittest("transformtest") {
|
||||
|
||||
# external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
}
|
||||
ohos_unittest("imagecolorspacetest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/include",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils/include",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits/include",
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include",
|
||||
"//foundation/multimedia/utils/include",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager/export",
|
||||
"//third_party/googletest/googletest/include",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_color_space_test.cpp",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_util.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
resource_config_file =
|
||||
"//foundation/multimedia/image_standard/test/resource/image/ohos_test.xml"
|
||||
}
|
||||
|
||||
################################################
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":colorconvertertest",
|
||||
":imagecolorspacetest",
|
||||
":imagepixelmapparceltest",
|
||||
":imagepixelmaptest",
|
||||
":imagesourcetest",
|
||||
":transformtest",
|
||||
]
|
||||
}
|
||||
################################################
|
||||
################################################
|
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include <fcntl.h>
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
#include "image_source_util.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
|
||||
static const std::string IMAGE_INPUT_JPEG_INCLUDE_ICC_PATH = "/data/local/tmp/image/jpeg_include_icc_profile.jpg";
|
||||
static const std::string IMAGE_OUTPUT_JPEG_INCLUDE_ICC_PATH = "/data/test/test_jpeg_include_icc_profile.jpg";
|
||||
static const std::string IMAGE_INPUT_JPEG_NOT_INCLUDE_ICC_PATH = "/data/local/tmp/image/test.jpg";
|
||||
static const std::string IMAGE_OUTPUT_JPEG_NOT_INCLUDE_ICC_PATH = "/data/test/test_jpeg_no_include_icc_profile.jpg";
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
|
||||
LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageColorSpaceTest"
|
||||
};
|
||||
|
||||
class ImageColorSpaceTest : public testing::Test {
|
||||
public:
|
||||
ImageColorSpaceTest() {};
|
||||
~ImageColorSpaceTest() {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: JpegColorSpaceDecode001
|
||||
* @tc.desc: Decode jpeg icc image from file source stream
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageColorSpaceTest, JpegColorSpaceDecode001, TestSize.Level3)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create image source by correct jpeg file path and jpeg format hit.
|
||||
* @tc.expected: step1. create image source success.
|
||||
*/
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. decode image source to pixel map by default decode options.
|
||||
* @tc.expected: step2. decode image source to pixel map success.
|
||||
* @tc.expected: step2. parsing colorspace success.
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpace = pixelMap->InnerGetGrColorSpace();
|
||||
EXPECT_NE(grColorSpace.ToSkColorSpace(), nullptr);
|
||||
EXPECT_NE(grColorSpace.GetWhitePoint().size(), 0UL);
|
||||
EXPECT_NE(grColorSpace.GetXYZToRGB().size(), 0UL);
|
||||
EXPECT_NE(grColorSpace.GetRGBToXYZ().size(), 0UL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JpegColorSpaceEncode001
|
||||
* @tc.desc: Encode jpeg icc image to file source stream
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageColorSpaceTest, JpegColorSpaceEncode001, TestSize.Level3)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create image source by correct jpeg file path and jpeg format hit.
|
||||
* @tc.expected: step1. create image source success.
|
||||
*/
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code==%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. decode image source to pixel map by default decode options.
|
||||
* @tc.expected: step2. decode image source to first pixel map success.
|
||||
* @tc.expected: step2. parsing colorspace success.
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMapOne = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMapOne.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpaceOne = pixelMapOne->InnerGetGrColorSpace();
|
||||
EXPECT_NE(grColorSpaceOne.ToSkColorSpace(), nullptr);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. encode image source from pixel map.
|
||||
* @tc.expected: step3. encode image source from first pixel map success.
|
||||
* @tc.expected: step3. packing colorspace success.
|
||||
*/
|
||||
ImagePacker imagePacker;
|
||||
int64_t packSize = OHOS::ImageSourceUtil::PackImage(IMAGE_OUTPUT_JPEG_INCLUDE_ICC_PATH, std::move(pixelMapOne));
|
||||
ASSERT_NE(packSize, 0);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. create image source by correct jpeg file path and jpeg format hit.
|
||||
* @tc.expected: step4. create second image source success.
|
||||
*/
|
||||
imageSource = ImageSource::CreateImageSource(IMAGE_OUTPUT_JPEG_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. decode image source to second pixel map by default decode options from packaged image.
|
||||
* @tc.expected: step5. decode image source to second pixel map success.
|
||||
* @tc.expected: step5. acquire second colorspace success.
|
||||
*/
|
||||
std::unique_ptr<PixelMap> pixelMapTwo = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMapTwo.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpaceTwo = pixelMapTwo->InnerGetGrColorSpace();
|
||||
EXPECT_NE(grColorSpaceTwo.ToSkColorSpace(), nullptr);
|
||||
EXPECT_EQ(grColorSpaceOne.GetWhitePoint(), grColorSpaceTwo.GetWhitePoint());
|
||||
EXPECT_EQ(grColorSpaceOne.GetXYZToRGB(), grColorSpaceTwo.GetXYZToRGB());
|
||||
EXPECT_EQ(grColorSpaceOne.GetRGBToXYZ(), grColorSpaceTwo.GetRGBToXYZ());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JpegColorSpaceDecode002
|
||||
* @tc.desc: Decode jpeg image, which don't contain ICC from file source stream
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageColorSpaceTest, JpegColorSpaceDecode002, TestSize.Level3)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create image source by correct jpeg file path and jpeg format hit.
|
||||
* @tc.expected: step1. create image source success.
|
||||
*/
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_NOT_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. decode image source to pixel map by default decode options.
|
||||
* @tc.expected: step2. decode image source to pixel map success.
|
||||
* @tc.expected: step2. parsing colorspace failed.
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpace = pixelMap->InnerGetGrColorSpace();
|
||||
EXPECT_EQ(grColorSpace.ToSkColorSpace(), nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JpegColorSpaceEncode002
|
||||
* @tc.desc: Encode jpeg image, which don't contain ICC to file source stream.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageColorSpaceTest, JpegColorSpaceEncode002, TestSize.Level3)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create image source by correct jpeg file path and jpeg format hit.
|
||||
* @tc.expected: step1. create image source success.
|
||||
*/
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_NOT_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code==%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. decode image source to pixel map by default decode options.
|
||||
* @tc.expected: step2. decode image source to first pixel map success.
|
||||
* @tc.expected: step2. parsing colorspace failed.
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMapOne = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMapOne.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpaceOne = pixelMapOne->InnerGetGrColorSpace();
|
||||
EXPECT_EQ(grColorSpaceOne.ToSkColorSpace(), nullptr);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. encode image source from pixel map.
|
||||
* @tc.expected: step3. encode image source from first pixel map success.
|
||||
* @tc.expected: step3. packing colorspace success.
|
||||
*/
|
||||
ImagePacker imagePacker;
|
||||
int64_t packSize = OHOS::ImageSourceUtil::PackImage(IMAGE_OUTPUT_JPEG_NOT_INCLUDE_ICC_PATH, std::move(pixelMapOne));
|
||||
ASSERT_NE(packSize, 0);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. create image source by correct jpeg file path and jpeg format hit.
|
||||
* @tc.expected: step4. create second image source success.
|
||||
*/
|
||||
imageSource = ImageSource::CreateImageSource(IMAGE_OUTPUT_JPEG_NOT_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. decode image source to second pixel map by default decode options from packaged image.
|
||||
* @tc.expected: step5. decode image source to second pixel map success.
|
||||
* @tc.expected: step5. parsing second colorspace failed.
|
||||
*/
|
||||
std::unique_ptr<PixelMap> pixelMapTwo = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMapTwo.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpaceTwo = pixelMapTwo->InnerGetGrColorSpace();
|
||||
EXPECT_EQ(grColorSpaceTwo.ToSkColorSpace(), nullptr);
|
||||
#endif
|
||||
}
|
@ -38,6 +38,7 @@ config("image_external_config") {
|
||||
"//foundation/graphic/graphic_2d/interfaces/innerkits/common",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/graphic/graphic_2d/utils/buffer_handle/export",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager/export",
|
||||
"//drivers/peripheral/display/interfaces/include",
|
||||
"//drivers/peripheral/base",
|
||||
]
|
||||
@ -85,12 +86,16 @@ ohos_shared_library("image") {
|
||||
"//foundation/multimedia/image_standard/frameworks/kits/js/common/pixel_map_napi.cpp",
|
||||
]
|
||||
|
||||
cflags = [ "-DIMAGE_DEBUG_FLAG" ]
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":image_native",
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager",
|
||||
@ -111,6 +116,11 @@ ohos_shared_library("image") {
|
||||
ohos_shared_library("image_native") {
|
||||
public_configs = [ ":image_external_config" ]
|
||||
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/codec/src/image_packer.cpp",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/codec/src/image_packer_ex.cpp",
|
||||
@ -145,6 +155,7 @@ ohos_shared_library("image_native") {
|
||||
]
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static",
|
||||
"//foundation/multimedia/image_standard/mock/native:log_mock_static",
|
||||
@ -161,6 +172,7 @@ ohos_shared_library("image_native") {
|
||||
]
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static",
|
||||
"//foundation/multimedia/image_standard/mock/native:log_mock_static",
|
||||
@ -174,6 +186,7 @@ ohos_shared_library("image_native") {
|
||||
deps = [
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager",
|
||||
@ -209,12 +222,16 @@ ohos_static_library("image_static_napi") {
|
||||
"//foundation/multimedia/image_standard/frameworks/kits/js/common/pixel_map_napi.cpp",
|
||||
]
|
||||
|
||||
cflags = [ "-DIMAGE_DEBUG_FLAG" ]
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":image_native",
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager",
|
||||
@ -260,6 +277,7 @@ ohos_static_library("image_static") {
|
||||
]
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static",
|
||||
"//foundation/multimedia/image_standard/mock/native:log_mock_static",
|
||||
@ -277,6 +295,7 @@ ohos_static_library("image_static") {
|
||||
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static",
|
||||
"//foundation/multimedia/image_standard/mock/native:log_mock_static",
|
||||
@ -290,6 +309,7 @@ ohos_static_library("image_static") {
|
||||
deps = [
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager",
|
||||
|
@ -107,6 +107,8 @@ const int32_t ERR_MEDIA_RTSP_CAMERA_NUM_REACH_MAX = BASE_MEDIA_ERR_OFFSET + 71;
|
||||
const int32_t ERR_MEDIA_SET_VOLUME = BASE_MEDIA_ERR_OFFSET + 72; // media set volume error
|
||||
const int32_t ERR_MEDIA_NUMBER_OVERFLOW = BASE_MEDIA_ERR_OFFSET + 73; // media number operation overflow
|
||||
const int32_t ERR_MEDIA_DIS_PLAYER_UNSUPPORTED = BASE_MEDIA_ERR_OFFSET + 74; // media distribute player unsupporteded
|
||||
const uint32_t ERR_IMAGE_DENCODE_ICC_FAILED = BASE_MEDIA_ERR_OFFSET + 75; // image dencode ICC fail
|
||||
const uint32_t ERR_IMAGE_ENCODE_ICC_FAILED = BASE_MEDIA_ERR_OFFSET + 76; // image encode ICC fail
|
||||
|
||||
const int32_t ERR_MEDIA_UNKNOWN = BASE_MEDIA_ERR_OFFSET + 200; // media unknown error
|
||||
} // namespace Media
|
||||
|
@ -17,6 +17,9 @@
|
||||
#define PIXEL_MAP_H
|
||||
|
||||
#include <memory>
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "image_type.h"
|
||||
#include "parcel.h"
|
||||
|
||||
@ -126,6 +129,13 @@ public:
|
||||
NATIVEEXPORT bool Marshalling(Parcel &data) const override;
|
||||
NATIVEEXPORT static PixelMap *Unmarshalling(Parcel &data);
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
// -------[inner api for ImageSource/ImagePacker codec] it will get a colorspace object pointer----begin----
|
||||
NATIVEEXPORT void InnerSetColorSpace(const OHOS::ColorManager::ColorSpace &grColorSpace);
|
||||
NATIVEEXPORT OHOS::ColorManager::ColorSpace InnerGetGrColorSpace();
|
||||
// -------[inner api for ImageSource/ImagePacker codec] it will get a colorspace object pointer----end-------
|
||||
#endif
|
||||
|
||||
private:
|
||||
static constexpr size_t MAX_IMAGEDATA_SIZE = 128 * 1024 * 1024; // 128M
|
||||
static constexpr size_t MIN_IMAGEDATA_SIZE = 32 * 1024; // 32k
|
||||
@ -192,6 +202,11 @@ private:
|
||||
uint32_t pixelsSize_ = 0;
|
||||
bool editable_ = false;
|
||||
bool useSourceAsResponse_ = false;
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace grColorSpace_ =
|
||||
OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
|
||||
#endif
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/image_standard/ide/image_decode_config.gni")
|
||||
import("//foundation/arkui/ace_engine/ace_config.gni")
|
||||
import("//third_party/flutter/flutter_config.gni")
|
||||
|
||||
ohos_shared_library("jpegplugin") {
|
||||
sources = [
|
||||
@ -20,21 +22,31 @@ ohos_shared_library("jpegplugin") {
|
||||
"//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp",
|
||||
"//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/src/jpeg_utils.cpp",
|
||||
"//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp",
|
||||
"//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/src/icc_profile_info.cpp",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/multimedia/utils/include",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits/include",
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include",
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include/image",
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include/pluginbase",
|
||||
"//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/include",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits/include",
|
||||
"//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils/include",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager/export",
|
||||
"//third_party/flutter/skia/third_party/externals/libjpeg-turbo",
|
||||
"//third_party/flutter/skia/include/codec",
|
||||
"//third_party/flutter/skia",
|
||||
"//third_party/flutter/skia/include/core",
|
||||
"//third_party/flutter/skia/third_party/libjpeg-turbo",
|
||||
"//third_party/flutter/skia/third_party/externals/libjpeg-turbo",
|
||||
"//third_party/flutter/skia/third_party/skcms",
|
||||
"//third_party/libexif",
|
||||
]
|
||||
|
||||
@ -42,14 +54,17 @@ ohos_shared_library("jpegplugin") {
|
||||
defines = image_decode_windows_defines
|
||||
include_dirs += [
|
||||
"//foundation/multimedia/image_standard/mock/native/include",
|
||||
|
||||
"//third_party/flutter/skia/third_party/libjpeg-turbo",
|
||||
"//third_party/flutter/skia/third_party/externals/libjpeg-turbo",
|
||||
]
|
||||
deps = [
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_static",
|
||||
"//foundation/multimedia/image_standard/mock/native:utils_mock_static",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager_static",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//third_party/flutter/build/skia:ace_skia_ohos",
|
||||
"//third_party/flutter/build/libjpeg:ace_libjpeg",
|
||||
"//third_party/flutter/build/skia:ace_skcms",
|
||||
"//third_party/libexif:libexif",
|
||||
]
|
||||
} else if (use_clang_mac) {
|
||||
@ -57,24 +72,34 @@ ohos_shared_library("jpegplugin") {
|
||||
include_dirs += [
|
||||
"//foundation/multimedia/image_standard/mock/native/include",
|
||||
"//third_party/flutter/skia/third_party/libjpeg-turbo",
|
||||
"//third_party/flutter/skia/third_party/externals/libjpeg-turbo",
|
||||
]
|
||||
deps = [
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_static",
|
||||
"//foundation/multimedia/image_standard/mock/native:utils_mock_static",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager_static",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//third_party/flutter/build/skia:ace_skia_ohos",
|
||||
"//third_party/flutter/build/libjpeg:ace_libjpeg",
|
||||
"//third_party/flutter/build/skia:ace_skcms",
|
||||
"//third_party/libexif:libexif",
|
||||
]
|
||||
} else {
|
||||
defines = [ "DUAL_ADAPTER" ]
|
||||
DUAL_ADAPTER = true
|
||||
include_dirs += [ "//utils/native/base/include" ]
|
||||
sources += [ "//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp" ]
|
||||
sources += [
|
||||
"//foundation/multimedia/image_standard/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp",
|
||||
"$flutter_root/skia/third_party/externals/libjpeg-turbo/jdicc.c"
|
||||
]
|
||||
deps = [
|
||||
#"//third_party/flutter/skia/third_party/libjpeg-turbo:libjpeg",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//foundation/multimedia/image_standard/plugins/manager:pluginmanager",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
"//third_party/flutter/build/skia:ace_skia_ohos",
|
||||
"//third_party/flutter/build/libjpeg:ace_libjpeg",
|
||||
"//third_party/flutter/build/skia:ace_skcms",
|
||||
"//third_party/libexif:libexif",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
@ -85,7 +110,10 @@ ohos_shared_library("jpegplugin") {
|
||||
"//third_party/flutter/build/libjpeg:ace_libjpeg",
|
||||
"//third_party/libexif:libexif",
|
||||
]
|
||||
include_dirs += [ "//third_party/flutter/skia/third_party/libjpeg-turbo" ]
|
||||
include_dirs += [
|
||||
"//third_party/flutter/skia/third_party/libjpeg-turbo",
|
||||
"//third_party/flutter/skia/third_party/externals/libjpeg-turbo",
|
||||
]
|
||||
}
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2021 - 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ICC_PROFILE_INFO_H
|
||||
#define ICC_PROFILE_INFO_H
|
||||
|
||||
#include <string>
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "hilog/log.h"
|
||||
#include "image_plugin_type.h"
|
||||
#include "include/core/SkData.h"
|
||||
#include "include/core/SkColorSpace.h"
|
||||
#include "include/core/SkImageInfo.h"
|
||||
#include "include/third_party/skcms/skcms.h"
|
||||
#include "jpeg_utils.h"
|
||||
#include "jpeglib.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "src/images/SkImageEncoderFns.h"
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
/*
|
||||
* Class responsible for storing and parsing ICC profile information from JPEG
|
||||
*/
|
||||
class ICCProfileInfo {
|
||||
public:
|
||||
ICCProfileInfo();
|
||||
~ICCProfileInfo();
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
/**
|
||||
* @brief get icc data.
|
||||
* @param cinfo jpeg decompress pionter.
|
||||
* @return parse result data.
|
||||
*/
|
||||
sk_sp<SkData> GetICCData(j_decompress_ptr cinfo);
|
||||
|
||||
/**
|
||||
* @brief paser icc profile data form jpeg.
|
||||
* @param cinfo jpeg decompress pionter.
|
||||
* @return parse result data.
|
||||
*/
|
||||
uint32_t ParsingICCProfile(j_decompress_ptr cinfo);
|
||||
|
||||
/**
|
||||
* @brief get graphiccolorspace info.
|
||||
* @return SkColorSpace Object.
|
||||
*/
|
||||
OHOS::ColorManager::ColorSpace getGrColorSpace();
|
||||
|
||||
/**
|
||||
* @brief get whether ICC data exists in the current source
|
||||
* @return is support icc profile or not.
|
||||
*/
|
||||
bool IsSupportICCProfile();
|
||||
|
||||
/**
|
||||
* @brief packing icc profile data
|
||||
* @param cinfo jpeg decompress pionter.
|
||||
* @param SkImageInfo.
|
||||
* @return packing result data.
|
||||
*/
|
||||
uint32_t PackingICCProfile(j_compress_ptr cinfo, const SkImageInfo& info);
|
||||
#endif
|
||||
private:
|
||||
OHOS::ColorManager::ColorSpace grColorSpace_ =
|
||||
OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB);
|
||||
bool isSupportICCProfile_;
|
||||
};
|
||||
} // namespace ImagePlugin
|
||||
} // namespace OHOS
|
||||
#endif // ICC_PROFILE_INFO_H
|
@ -20,7 +20,11 @@
|
||||
#include <string>
|
||||
#include "abs_image_decoder.h"
|
||||
#include "abs_image_decompress_component.h"
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "hilog/log.h"
|
||||
#include "icc_profile_info.h"
|
||||
#include "jpeg_utils.h"
|
||||
#include "jpeglib.h"
|
||||
#include "log_tags.h"
|
||||
@ -59,6 +63,12 @@ public:
|
||||
const int fd) override;
|
||||
uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value,
|
||||
uint8_t *data, uint32_t size) override;
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace getGrColorSpace();
|
||||
bool IsSupportICCProfile();
|
||||
#endif
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(JpegDecoder);
|
||||
int ExifPrintMethod();
|
||||
@ -84,6 +94,7 @@ private:
|
||||
PlPixelFormat outputFormat_ = PlPixelFormat::UNKNOWN;
|
||||
PixelDecodeOptions opts_;
|
||||
EXIFInfo exifInfo_;
|
||||
ICCProfileInfo iccProfileInfo_;
|
||||
};
|
||||
} // namespace ImagePlugin
|
||||
} // namespace OHOS
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
#include "abs_image_encoder.h"
|
||||
#include "hilog/log.h"
|
||||
#include "icc_profile_info.h"
|
||||
#include "jpeg_utils.h"
|
||||
#include "jpeglib.h"
|
||||
#include "log_tags.h"
|
||||
@ -50,8 +51,8 @@ private:
|
||||
ErrorMgr jerr_;
|
||||
std::vector<Media::PixelMap *> pixelMaps_;
|
||||
PlEncodeOptions encodeOpts_;
|
||||
ICCProfileInfo iccProfileInfo_;
|
||||
};
|
||||
} // namespace ImagePlugin
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // JPEG_ENCODER_H
|
129
plugins/common/libs/image/libjpegplugin/src/icc_profile_info.cpp
Normal file
129
plugins/common/libs/image/libjpegplugin/src/icc_profile_info.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "icc_profile_info.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
#include <unistd.h>
|
||||
#include "securec.h"
|
||||
#include "jerror.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
namespace {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "IccProfile" };
|
||||
static constexpr uint32_t ICC_MARKER = JPEG_APP0 + 2;
|
||||
static constexpr uint32_t ICC_MARKER_HEADER_SIZE = 14;
|
||||
static constexpr uint8_t ICC_SIGNATURE[] = {
|
||||
'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0',
|
||||
}; // Corresponding hexadecimal: { 0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x00 }
|
||||
}
|
||||
|
||||
ICCProfileInfo::ICCProfileInfo(): isSupportICCProfile_(false)
|
||||
{
|
||||
}
|
||||
|
||||
ICCProfileInfo::~ICCProfileInfo()
|
||||
{
|
||||
}
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
sk_sp<SkData> ICCProfileInfo::GetICCData(j_decompress_ptr cinfo)
|
||||
{
|
||||
HiLog::Info(LABEL, "%{public}s begin", __func__);
|
||||
unsigned char *icc_profile = NULL;
|
||||
unsigned int icc_data_len = 0;
|
||||
bool isReadIccProfile = false;
|
||||
sk_sp<SkData> data;
|
||||
isReadIccProfile = jpeg_read_icc_profile(cinfo, &icc_profile, &icc_data_len);
|
||||
if (isReadIccProfile) {
|
||||
// copy ICC profile data
|
||||
data = SkData::MakeWithCopy(icc_profile, icc_data_len);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "ERROR: jpeg_read_icc_profile failed!");
|
||||
}
|
||||
|
||||
// clean up
|
||||
free(icc_profile);
|
||||
return data;
|
||||
}
|
||||
|
||||
uint32_t ICCProfileInfo::ParsingICCProfile(j_decompress_ptr cinfo)
|
||||
{
|
||||
HiLog::Info(LABEL, "%{public}s begin", __func__);
|
||||
|
||||
// read icc data to skdata
|
||||
sk_sp<SkData> profile = GetICCData(cinfo);
|
||||
skcms_ICCProfile parsed;
|
||||
uint32_t parseResult = OHOS::Media::ERR_IMAGE_DENCODE_ICC_FAILED;
|
||||
sk_sp<SkColorSpace> skColorSpace = nullptr;
|
||||
if (skcms_Parse(profile->data(), profile->size(), &parsed)) {
|
||||
skColorSpace = SkColorSpace::Make(parsed);
|
||||
if (skColorSpace != nullptr) {
|
||||
isSupportICCProfile_ = true;
|
||||
}
|
||||
} else {
|
||||
skColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, SkNamedGamut::kAdobeRGB);
|
||||
isSupportICCProfile_ = false;
|
||||
}
|
||||
if (skColorSpace != nullptr) {
|
||||
parseResult = OHOS::Media::SUCCESS;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "ERROR: ParsingICCProfile skColorSpace is Null!");
|
||||
}
|
||||
grColorSpace_ = OHOS::ColorManager::ColorSpace(skColorSpace);
|
||||
return parseResult;
|
||||
}
|
||||
|
||||
OHOS::ColorManager::ColorSpace ICCProfileInfo::getGrColorSpace()
|
||||
{
|
||||
return grColorSpace_;
|
||||
}
|
||||
|
||||
bool ICCProfileInfo::IsSupportICCProfile()
|
||||
{
|
||||
return isSupportICCProfile_;
|
||||
}
|
||||
|
||||
uint32_t ICCProfileInfo::PackingICCProfile(j_compress_ptr cinfo, const SkImageInfo& info)
|
||||
{
|
||||
HiLog::Info(LABEL, "%{public}s begin", __func__);
|
||||
uint32_t packingResult = OHOS::Media::ERR_IMAGE_ENCODE_ICC_FAILED;
|
||||
|
||||
// write colorspace to SKData
|
||||
sk_sp<SkData> icc = icc_from_color_space(info);
|
||||
|
||||
if (icc) {
|
||||
// get a contiguous block of profile memory with the icc signature
|
||||
sk_sp<SkData> jpegMarkerData =
|
||||
SkData::MakeUninitialized(ICC_MARKER_HEADER_SIZE + icc->size());
|
||||
uint8_t* ptrMaker = (uint8_t*) jpegMarkerData->writable_data();
|
||||
(void)memcpy_s(ptrMaker, sizeof(*ptrMaker), ICC_SIGNATURE, sizeof(ICC_SIGNATURE));
|
||||
ptrMaker += sizeof(ICC_SIGNATURE);
|
||||
// first marker
|
||||
*ptrMaker++ = 1;
|
||||
// total markers
|
||||
*ptrMaker++ = 1;
|
||||
(void)memcpy_s(ptrMaker, sizeof(*ptrMaker), icc->data(), icc->size());
|
||||
jpeg_write_marker(cinfo, ICC_MARKER, jpegMarkerData->bytes(), jpegMarkerData->size());
|
||||
packingResult = OHOS::Media::SUCCESS;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "ERROR: PackingICCProfile icc profile is Null!");
|
||||
}
|
||||
return packingResult;
|
||||
}
|
||||
#endif
|
||||
} // namespace ImagePlugin
|
||||
} // namespace OHOS
|
@ -30,6 +30,8 @@ using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
using namespace Media;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "JpegDecoder" };
|
||||
static constexpr uint32_t PL_ICC_MARKER = JPEG_APP0 + 2;
|
||||
static constexpr uint32_t PL_MARKER_LENGTH_LIMIT = 0xFFFF;
|
||||
namespace {
|
||||
constexpr uint32_t NUM_100 = 100;
|
||||
constexpr uint32_t PIXEL_BYTES_RGB_565 = 2;
|
||||
@ -323,6 +325,16 @@ uint32_t JpegDecoder::DoSwDecode(DecodeContext &context)
|
||||
}
|
||||
}
|
||||
streamPosition_ = srcMgr_.inputStream->Tell();
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
// paser icc profile info
|
||||
uint32_t iccPaseredResult = iccProfileInfo_.ParsingICCProfile(&decodeInfo_);
|
||||
if (iccPaseredResult == OHOS::Media::ERR_IMAGE_DENCODE_ICC_FAILED) {
|
||||
HiLog::Error(LABEL, "dencode image icc error.");
|
||||
return iccPaseredResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Media::SUCCESS;
|
||||
}
|
||||
|
||||
@ -525,6 +537,8 @@ uint32_t JpegDecoder::DecodeHeader()
|
||||
}
|
||||
}
|
||||
|
||||
// call jpeg_save_markers, use to get ICC profile.
|
||||
jpeg_save_markers(&decodeInfo_, PL_ICC_MARKER, PL_MARKER_LENGTH_LIMIT);
|
||||
int32_t ret = jpeg_read_header(&decodeInfo_, false);
|
||||
streamPosition_ = srcMgr_.inputStream->Tell();
|
||||
if (ret == JPEG_SUSPENDED) {
|
||||
@ -695,5 +709,19 @@ uint32_t JpegDecoder::ModifyImageProperty(uint32_t index, const std::string &key
|
||||
}
|
||||
return Media::SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
OHOS::ColorManager::ColorSpace JpegDecoder::getGrColorSpace()
|
||||
{
|
||||
OHOS::ColorManager::ColorSpace grColorSpace = iccProfileInfo_.getGrColorSpace();
|
||||
return grColorSpace;
|
||||
}
|
||||
|
||||
bool JpegDecoder::IsSupportICCProfile()
|
||||
{
|
||||
bool isSupportICCProfile = iccProfileInfo_.IsSupportICCProfile();
|
||||
return isSupportICCProfile;
|
||||
}
|
||||
#endif
|
||||
} // namespace ImagePlugin
|
||||
} // namespace OHOS
|
||||
|
@ -13,6 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "include/core/SkColorSpace.h"
|
||||
#include "include/core/SkImageInfo.h"
|
||||
#include "jerror.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_convert.h"
|
||||
@ -193,6 +198,28 @@ uint32_t JpegEncoder::SequenceEncoder(const uint8_t *data)
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
}
|
||||
jpeg_start_compress(&encodeInfo_, TRUE);
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
// packing icc profile.
|
||||
SkImageInfo skImageInfo;
|
||||
OHOS::ColorManager::ColorSpace grColorSpace = pixelMaps_[0]->InnerGetGrColorSpace();
|
||||
sk_sp<SkColorSpace> skColorSpace = grColorSpace.ToSkColorSpace();
|
||||
|
||||
// when there is colorspace data, package it.
|
||||
if (skColorSpace != nullptr) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
SkColorType ct = SkColorType::kUnknown_SkColorType;
|
||||
SkAlphaType at = SkAlphaType::kUnknown_SkAlphaType;
|
||||
skImageInfo = SkImageInfo::Make(width, height, ct, at, skColorSpace);
|
||||
uint32_t iccPackedresult = iccProfileInfo_.PackingICCProfile(&encodeInfo_, skImageInfo);
|
||||
if (iccPackedresult == OHOS::Media::ERR_IMAGE_ENCODE_ICC_FAILED) {
|
||||
HiLog::Error(LABEL, "encode image icc error.");
|
||||
return iccPackedresult;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t *base = const_cast<uint8_t *>(data);
|
||||
uint32_t rowStride = encodeInfo_.image_width * encodeInfo_.input_components;
|
||||
uint8_t *buffer = nullptr;
|
||||
|
@ -32,6 +32,11 @@ ohos_shared_library("pluginmanager") {
|
||||
"//foundation/multimedia/image_standard/plugins/manager/src/thirdpartyadp/gstreamer/gst_plugin_fw.cpp",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include",
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include/pluginbase",
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include <sys/mman.h>
|
||||
#include "ashmem.h"
|
||||
#endif
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "image_plugin_type.h"
|
||||
#include "input_data_stream.h"
|
||||
#include "media_errors.h"
|
||||
@ -166,6 +169,20 @@ public:
|
||||
return Media::ERR_MEDIA_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
// get current source is support icc profile or not.
|
||||
bool IsSupportICCProfile()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// if current source support icc. get relevant color gamut information by this method.
|
||||
OHOS::ColorManager::ColorSpace getGrColorSpace()
|
||||
{
|
||||
return OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
// define multiple subservices for this interface
|
||||
static constexpr uint16_t SERVICE_DEFAULT = 0;
|
||||
};
|
||||
|
@ -60,6 +60,12 @@
|
||||
<option name="push" value="images/test.rw2 -> /data/local/tmp/image" src="res"/>
|
||||
<option name="push" value="images/test.wbmp -> /data/local/tmp/image" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="imagecolorspacetest">
|
||||
<preparer>
|
||||
<option name="push" value="images/jpeg_icc_test.jpg -> /data/local/tmp/image" src="res"/>
|
||||
<option name="push" value="images/test.jpg -> /data/local/tmp/image" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="test_imagesystemadapter_java_maple">
|
||||
<preparer>
|
||||
|
Loading…
Reference in New Issue
Block a user