You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
3.4 KiB
158 lines
3.4 KiB
//#define LOG_NDEBUG 0
|
|
#define LOG_TAG "JpegDecoderTest"
|
|
#include <utils/Log.h>
|
|
|
|
#include <getopt.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
|
|
#include "MpiJpegDecoder.h"
|
|
|
|
/*
|
|
* Dumps usage on stderr.
|
|
*/
|
|
void usage() {
|
|
fprintf(stderr,
|
|
"Usage: jpegd_test [options]\n"
|
|
"\n"
|
|
"used for MpiJpegDecoder test.\n"
|
|
"\n"
|
|
"Options:\n"
|
|
"-i\n"
|
|
" input file.\n"
|
|
"-o\n"
|
|
" output file.\n"
|
|
"-h\n"
|
|
" Show this message.\n"
|
|
""
|
|
" jpegd_test -i test.jpg -o test.yuv"
|
|
"\n"
|
|
);
|
|
}
|
|
|
|
bool storeFileData(const char *fileName, char **data, size_t *size) {
|
|
FILE *file = NULL;
|
|
size_t fileLen = 0;
|
|
|
|
file = fopen(fileName, "rb");
|
|
if (file == NULL) {
|
|
ALOGE("failed to open file %s - %s", fileName, strerror(errno));
|
|
return false;
|
|
}
|
|
|
|
fseek(file, 0L, SEEK_END);
|
|
fileLen = ftell(file);
|
|
rewind(file);
|
|
|
|
*data = (char *)malloc(fileLen);
|
|
if (*data == NULL) {
|
|
ALOGE("failed to malloc buffer");
|
|
fclose(file);
|
|
return false;
|
|
}
|
|
|
|
fread(*data, 1, fileLen, file);
|
|
*size = fileLen;
|
|
|
|
fflush(file);
|
|
fclose(file);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool dumpDataToFile(void *data, size_t size, const char *fileName) {
|
|
FILE *file = NULL;
|
|
|
|
file = fopen(fileName, "w+b");
|
|
if (file == NULL) {
|
|
ALOGE("failed to open file %s - %s", fileName, strerror(errno));
|
|
return false;
|
|
}
|
|
|
|
fwrite(data, 1, size, file);
|
|
fflush(file);
|
|
fclose(file);
|
|
|
|
return true;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
const char *inputFile = NULL;
|
|
const char *outputFile = NULL;
|
|
|
|
int res;
|
|
while ((res = getopt(argc, argv, "i:o:")) >= 0) {
|
|
switch (res) {
|
|
case 'i': {
|
|
inputFile = optarg;
|
|
break;
|
|
}
|
|
case 'o': {
|
|
outputFile = optarg;
|
|
break;
|
|
}
|
|
case 'h':
|
|
default: {
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!inputFile || !outputFile) {
|
|
printf("Must specify input/output file (see -h).\n");
|
|
return 2;
|
|
}
|
|
|
|
bool err = false;
|
|
char *data = NULL;
|
|
size_t size = 0;
|
|
|
|
MpiJpegDecoder decoder;
|
|
MpiJpegDecoder::OutputFrame_t frameOut;
|
|
|
|
memset(&frameOut, 0, sizeof(MpiJpegDecoder::OutputFrame_t));
|
|
|
|
err = decoder.prepareDecoder();
|
|
if (!err) {
|
|
printf("failed to prepare decoder.\n");
|
|
return 2;
|
|
}
|
|
|
|
err = storeFileData(inputFile, &data, &size);
|
|
if (!err) {
|
|
printf("failed to open input file.\n");
|
|
goto cleanUp;
|
|
}
|
|
|
|
err = decoder.decodePacket(data, size, &frameOut);
|
|
if (!err) {
|
|
printf("failed to decode packet.\n");
|
|
goto cleanUp;
|
|
}
|
|
|
|
// write output frame to destination.
|
|
err = dumpDataToFile(frameOut.MemVirAddr, frameOut.OutputSize, outputFile);
|
|
if (!err) {
|
|
printf("failed to open output file.\n");
|
|
} else {
|
|
printf("get output file %s - dimens %dx%d.\n",
|
|
outputFile, frameOut.FrameWidth, frameOut.FrameHeight);
|
|
}
|
|
|
|
/* output buffer count within limits, so release frame buffer if one
|
|
frame has been display successfully. */
|
|
decoder.deinitOutputFrame(&frameOut);
|
|
|
|
decoder.flushBuffer();
|
|
|
|
cleanUp:
|
|
if (data) {
|
|
free(data);
|
|
data = NULL;
|
|
}
|
|
|
|
return 0;
|
|
}
|