#include <stdio.h>
#include <stdlib.h>
#define LOG_TAG "JpegDecTest"
#include <utils/Log.h>
// jpeg_hw_dec_api_include
#include "hw_jpegdecapi.h"
#include "SkHwJpegUtility.h"
#define MAX_HARDWARE_SUPPORT_INPUT_SIZE ((1 << 24) - 1)
// current support jpeg-decode output format
enum SupportOutFormatType {
OUT_FORMAT_RGB565 = 0,
OUT_FORMAT_ARGB = 1,
OUT_FORMAT_YUV422INTERLAVE = 3,
OUT_FORMAT_YUV420INTERLAVE = 5,
};
/****** Update test parameters before the test starts *****/
const char* INPUT_JPEG_PATH = "/data/test.jpg";
const char* OUTPUT_BGRA_PATH = "/data/output";
// input jpeg resolution
int INPUT_WIDTH = 4000;
int INPUT_HEIGHT = 3091;
/**********************************************************/
static bool hwjpeg_decode(char *src_data, size_t src_size, int jepgWidth,
int jpegHeight, FILE* output_file)
{
int ret;
HwJpegInputInfo input_info;
HwJpegOutputInfo output_info;
SkMemoryStream stream(src_data, src_size, /* copyData */ false);
sk_hw_jpeg_source_mgr sk_hw_stream(&stream, &input_info, /* vpuMem */ false);
input_info.justcaloutwh = 0;
input_info.streamCtl.inStream = &sk_hw_stream;
input_info.streamCtl.wholeStreamLength = stream.getLength(); // > 64M ? break;
input_info.streamCtl.thumbOffset = -1;
input_info.streamCtl.thumbLength = -1;
input_info.streamCtl.useThumb = 0;
ReusePmem thumbPmem;
thumbPmem.reuse = 0;
output_info.thumbPmem = &thumbPmem;
output_info.inputPool = NULL;
output_info.outAddr = NULL;
PostProcessInfo *ppInfo = &input_info.ppInfo;
ppInfo->outFomart = OUT_FORMAT_ARGB;
ppInfo->shouldDither = 0;
ppInfo->scale_denom = 1;
ppInfo->cropX = 0;
ppInfo->cropY = 0;
ppInfo->cropW = -1;
ppInfo->cropH = -1;
// Per pixel occupancy, depend on output format type
// ARGB: 4, RGB565: 2
int pixelBytes = 4;
char reuseBitmap = 0;
// main hw-jpeg-decode api
ret = hw_jpeg_decode(&input_info, &output_info, &reuseBitmap, jepgWidth, jpegHeight);
if (ret >= 0) {
ALOGD("hw_jpeg_decode execute successfully and outInfo.width = %d, outInfo.height = %d",
output_info.outWidth, output_info.outHeight);
// save decode-result to output file
fwrite(output_info.outAddr, 1,
output_info.outWidth * output_info.outHeight * pixelBytes, output_file);
}
// hw_jpeg handler release
hw_jpeg_release(output_info.decoderHandle);
output_info.decoderHandle = NULL;
return ret >= 0 ? true : false;
}
static size_t getFileSize(const char* fileName)
{
size_t size;
FILE* file;
file = fopen(fileName, "rb");
if (!file) {
ALOGE("%s(%d): null file in", __FUNCTION__, __LINE__);
return -1;
}
fseek(file, 0, SEEK_END);
size = ftell(file);
fseek(file, 0, SEEK_SET);
return size;
}
int main(int /* argc */, char** /* argv */)
{
// input jpeg image file
FILE *input_fp;
// output file
FILE *output_fp;
size_t input_size;
char *src_data = NULL;
input_size = getFileSize(INPUT_JPEG_PATH);
if (input_size <= 0 || input_size >= MAX_HARDWARE_SUPPORT_INPUT_SIZE) {
ALOGE("%s(line: %d): input size invalid", __FUNCTION__, __LINE__);
return -1;
}
// malloc input data memory
src_data = new char[input_size];
memset(src_data, 0, input_size);
input_fp = fopen(INPUT_JPEG_PATH, "rb");
output_fp = fopen(OUTPUT_BGRA_PATH, "wb");
if (!input_fp || !output_fp) {
ALOGE("%s(line: %d): fopen faied, please check file input path(%s) "
"or output path(%s)", __FUNCTION__, __LINE__,
INPUT_JPEG_PATH, OUTPUT_BGRA_PATH);
return -1;
}
fread(src_data, 1, input_size, input_fp);
if (!hwjpeg_decode(src_data, input_size, INPUT_WIDTH, INPUT_HEIGHT, output_fp)) {
ALOGE("hw_jpeg_decode failed");
}
fclose(input_fp);
fclose(output_fp);
free(src_data);
return 0;
}
android_rockchip_jpeg_hw 硬解码 demo 实现
最新推荐文章于 2021-06-04 10:14:00 发布