mirror of
https://gitee.com/openharmony/multimedia_image_framework
synced 2024-11-27 09:10:54 +00:00
add astc software encode
Signed-off-by: zhangqiang <zhangqiang183@huawei.com>
This commit is contained in:
parent
6bd6419652
commit
87ae96c5a1
@ -1109,6 +1109,49 @@ ohos_unittest("pixelastctest") {
|
||||
resource_config_file = "$image_subsystem/test/resource/image/ohos_test.xml"
|
||||
}
|
||||
|
||||
ohos_unittest("textureencodetest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"${image_subsystem}/plugins/common/libs/image/libextplugin/include",
|
||||
"${image_subsystem}/plugins/common/libs/image/libextplugin/include/texture_encode",
|
||||
"${image_subsystem}/interfaces/innerkits/include",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils/include",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/stream/include",
|
||||
"${graphic_subsystem}/interfaces/inner_api/surface",
|
||||
"${image_subsystem}/../../../drivers/peripheral/base/",
|
||||
"${image_subsystem}/../../../drivers/peripheral/display/interfaces/include/",
|
||||
"${image_subsystem}/../../../third_party/skia/",
|
||||
"${image_subsystem}/../../../third_party/skia/include/codec/",
|
||||
"${image_subsystem}/../../../third_party/skia/include/core/",
|
||||
"${image_subsystem}/../../../third_party/libjpeg-turbo/",
|
||||
"${image_subsystem}/../../../third_party/astc-encoder/Source",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/test/unittest",
|
||||
]
|
||||
sources = [
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/test/unittest/image_source_util.cpp",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/test/unittest/plugin_texture_encode_test.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${image_subsystem}/../../../third_party/astc-encoder:astc_encoder_shared",
|
||||
"${image_subsystem}/../../../third_party/opencl-headers:libcl",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"${image_subsystem}/interfaces/innerkits:image_native",
|
||||
"${image_subsystem}/plugins/common/libs/image/libextplugin:exifhelper",
|
||||
"${image_subsystem}/plugins/common/libs/image/libextplugin:extplugin",
|
||||
"${image_subsystem}/plugins/common/libs/image/libextplugin:textureEncoderCL",
|
||||
"${image_subsystem}/plugins/manager:pluginmanager",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"graphic_2d:color_manager",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
]
|
||||
}
|
||||
|
||||
################################################
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
@ -1140,6 +1183,7 @@ group("unittest") {
|
||||
":rawdecodertest",
|
||||
":receivertest",
|
||||
":streamtest",
|
||||
":textureencodetest",
|
||||
":transformtest",
|
||||
":webpplugintest",
|
||||
]
|
||||
|
@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 <cstdlib>
|
||||
#include <gtest/gtest.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "astc_codec.h"
|
||||
#include "buffer_packer_stream.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_compressor.h"
|
||||
#include "image_source_util.h"
|
||||
#include "image_system_properties.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::ImagePlugin;
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test.jpg";
|
||||
static constexpr int32_t OUTPUT_SIZE_MAX = 200000;
|
||||
class PluginTextureEncodeTest : public testing::Test {
|
||||
public:
|
||||
PluginTextureEncodeTest() {}
|
||||
~PluginTextureEncodeTest() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: ASTCEncode001
|
||||
* @tc.desc: Test the AstcSoftwareEncode function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(PluginTextureEncodeTest, ASTCEncode001, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode001 start";
|
||||
size_t bufferSize = 0;
|
||||
bool ret = ImageUtils::GetFileSize(IMAGE_INPUT_JPEG_PATH, bufferSize);
|
||||
ASSERT_EQ(ret, true);
|
||||
uint8_t *inputBuffer = static_cast<uint8_t *>(malloc(bufferSize));
|
||||
ASSERT_NE(inputBuffer, nullptr);
|
||||
ret = OHOS::ImageSourceUtil::ReadFileToBuffer("/data/local/tmp/image/test.jpg", inputBuffer, bufferSize);
|
||||
ASSERT_EQ(ret, true);
|
||||
uint32_t errCode = 0;
|
||||
SourceOptions sourceOpts;
|
||||
std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(inputBuffer,
|
||||
bufferSize, sourceOpts, errCode);
|
||||
ASSERT_EQ(errCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
uint32_t index = 0;
|
||||
DecodeOptions decodeOpts;
|
||||
errCode = 0;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(index, decodeOpts, errCode);
|
||||
ASSERT_EQ(errCode, SUCCESS);
|
||||
Media::PixelMap *pixelMapPtr = pixelMap.get();
|
||||
ASSERT_NE(pixelMapPtr, nullptr);
|
||||
uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
|
||||
ASSERT_NE(output, nullptr);
|
||||
BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
|
||||
ASSERT_NE(stream, nullptr);
|
||||
struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
|
||||
AstcCodec astcEncoder;
|
||||
uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
|
||||
ASSERT_EQ(setRet, SUCCESS);
|
||||
uint32_t astcRet = astcEncoder.ASTCEncode();
|
||||
ASSERT_EQ(astcRet, SUCCESS);
|
||||
if (inputBuffer != nullptr) {
|
||||
free(inputBuffer);
|
||||
inputBuffer = nullptr;
|
||||
}
|
||||
if (output != nullptr) {
|
||||
free(output);
|
||||
output = nullptr;
|
||||
}
|
||||
if (stream != nullptr) {
|
||||
delete stream;
|
||||
stream = nullptr;
|
||||
}
|
||||
if (pixelMapPtr != nullptr) {
|
||||
pixelMapPtr = nullptr;
|
||||
}
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ASTCEncode002
|
||||
* @tc.desc: Test the SetAstcEncode function
|
||||
* @tc.desc: Set outputStream to nullptr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(PluginTextureEncodeTest, ASTCEncode002, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode002 start";
|
||||
size_t bufferSize = 0;
|
||||
bool ret = ImageUtils::GetFileSize(IMAGE_INPUT_JPEG_PATH, bufferSize);
|
||||
ASSERT_EQ(ret, true);
|
||||
uint8_t *buffer = static_cast<uint8_t *>(malloc(bufferSize));
|
||||
ASSERT_NE(buffer, nullptr);
|
||||
ret = OHOS::ImageSourceUtil::ReadFileToBuffer(IMAGE_INPUT_JPEG_PATH, buffer, bufferSize);
|
||||
ASSERT_EQ(ret, true);
|
||||
uint32_t errCode = 0;
|
||||
SourceOptions sourceOpts;
|
||||
std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(buffer,
|
||||
bufferSize, sourceOpts, errCode);
|
||||
ASSERT_EQ(errCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
uint32_t index = 0;
|
||||
DecodeOptions decodeOpts;
|
||||
errCode = 0;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(index, decodeOpts, errCode);
|
||||
ASSERT_EQ(errCode, SUCCESS);
|
||||
Media::PixelMap *pixelMapPtr = pixelMap.get();
|
||||
ASSERT_NE(pixelMapPtr, nullptr);
|
||||
|
||||
BufferPackerStream *stream = nullptr;
|
||||
|
||||
struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
|
||||
AstcCodec astcEncoder;
|
||||
uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
|
||||
ASSERT_EQ(setRet, ERROR);
|
||||
|
||||
if (buffer != nullptr) {
|
||||
free(buffer);
|
||||
buffer = nullptr;
|
||||
}
|
||||
if (pixelMapPtr != nullptr) {
|
||||
pixelMapPtr = nullptr;
|
||||
}
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode002 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ASTCEncode003
|
||||
* @tc.desc: Test the SetAstcEncode function
|
||||
* @tc.desc: Set pixelMap to nullptr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(PluginTextureEncodeTest, ASTCEncode003, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode003 start";
|
||||
Media::PixelMap *pixelMapPtr = nullptr;
|
||||
|
||||
uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
|
||||
ASSERT_NE(output, nullptr);
|
||||
BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
|
||||
ASSERT_NE(stream, nullptr);
|
||||
|
||||
struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
|
||||
AstcCodec astcEncoder;
|
||||
uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
|
||||
ASSERT_EQ(setRet, ERROR);
|
||||
|
||||
if (output != nullptr) {
|
||||
free(output);
|
||||
output = nullptr;
|
||||
}
|
||||
if (stream != nullptr) {
|
||||
delete stream;
|
||||
stream = nullptr;
|
||||
}
|
||||
if (pixelMapPtr != nullptr) {
|
||||
pixelMapPtr = nullptr;
|
||||
}
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode003 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ASTCEncode004
|
||||
* @tc.desc: AstcSoftwareEncode return error test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(PluginTextureEncodeTest, ASTCEncode004, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode004 start";
|
||||
size_t bufferSize = 0;
|
||||
bool ret = ImageUtils::GetFileSize(IMAGE_INPUT_JPEG_PATH, bufferSize);
|
||||
ASSERT_EQ(ret, true);
|
||||
uint8_t *buffer = static_cast<uint8_t *>(malloc(bufferSize));
|
||||
ASSERT_NE(buffer, nullptr);
|
||||
ret = OHOS::ImageSourceUtil::ReadFileToBuffer(IMAGE_INPUT_JPEG_PATH, buffer, bufferSize);
|
||||
ASSERT_EQ(ret, true);
|
||||
uint32_t errCode = 0;
|
||||
SourceOptions sourceOpts;
|
||||
std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(buffer,
|
||||
bufferSize, sourceOpts, errCode);
|
||||
ASSERT_EQ(errCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
uint32_t index = 0;
|
||||
DecodeOptions decodeOpts;
|
||||
errCode = 0;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(index, decodeOpts, errCode);
|
||||
ASSERT_EQ(errCode, SUCCESS);
|
||||
Media::PixelMap *pixelMapPtr = pixelMap.get();
|
||||
ASSERT_NE(pixelMapPtr, nullptr);
|
||||
uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
|
||||
ASSERT_NE(output, nullptr);
|
||||
BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
|
||||
ASSERT_NE(stream, nullptr);
|
||||
struct PlEncodeOptions option = { "image/astc/7*7", 100, 1 }; // quality set to 100
|
||||
AstcCodec astcEncoder;
|
||||
uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
|
||||
ASSERT_EQ(setRet, SUCCESS);
|
||||
uint32_t astcRet = astcEncoder.ASTCEncode();
|
||||
ASSERT_EQ(astcRet, ERROR);
|
||||
if (buffer != nullptr) {
|
||||
free(buffer);
|
||||
buffer = nullptr;
|
||||
}
|
||||
if (output != nullptr) {
|
||||
free(output);
|
||||
output = nullptr;
|
||||
}
|
||||
if (stream != nullptr) {
|
||||
delete stream;
|
||||
stream = nullptr;
|
||||
}
|
||||
if (pixelMapPtr != nullptr) {
|
||||
pixelMapPtr = nullptr;
|
||||
}
|
||||
GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode004 end";
|
||||
}
|
||||
} // namespace Multimedia
|
||||
} // namespace OHOS
|
@ -149,4 +149,9 @@
|
||||
<option name="push" value="images/test.jpg -> /data/local/tmp/image" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="textureencodetest">
|
||||
<preparer>
|
||||
<option name="push" value="images/test.jpg -> /data/local/tmp/image" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user