Alessio Agneessens
2016-03-23 11:26:36 UTC
Hello,
may I ask a question about the tjCompressFromYUV() function?
I'd like to compress a planar 4:2:0 YUV buffer to a jpeg image, but
tjCompressFromYUV() fails, and the error string returned by tjGetErrorStr()
is "Bogus input colorspace".
What am I doing wrong?
Below is my code if it can help.
Thanks in advance,
Alessio
#define PADDING 2
tjhandle tjh;unsigned long buf_size;unsigned char *jpegBuf =
NULL;unsigned long jpegSize;int width = 352;int height = 288;int
quality = 70;unsigned char *ucp_frame;int j;FILE *fp = NULL;
ucp_frame = malloc(width * height * 3 / 2);if ( NULL == ucp_frame ) {
printf("malloc error ucp_frame\n");
return 0;}
fp = fopen("planar_352x288.raw", "rb");if( NULL == fp ) {
printf("fopen error\n");
return 0;}
j = fread( ucp_frame, 1, width * height * 3 / 2, fp);if( j != width *
height * 3 / 2 ) {
printf("fread error\n");
return 0;}
fclose(fp);
tjh = tjInitCompress();if( NULL == tjh ) {
printf("tjInitCompress error '%s'\n", tjGetErrorStr() );
return 0;}
buf_size = tjBufSizeYUV2( width, PADDING, height, TJSAMP_420);
jpegBuf = tjAlloc(buf_size);
if( tjCompressFromYUV( tjh, ucp_frame, width, PADDING, height,
TJSAMP_420, &jpegBuf, &jpegSize, quality,
TJFLAG_NOREALLOC ) ) {
printf("tjCompressFromYUV error '%s'\n", tjGetErrorStr() );}
may I ask a question about the tjCompressFromYUV() function?
I'd like to compress a planar 4:2:0 YUV buffer to a jpeg image, but
tjCompressFromYUV() fails, and the error string returned by tjGetErrorStr()
is "Bogus input colorspace".
What am I doing wrong?
Below is my code if it can help.
Thanks in advance,
Alessio
#define PADDING 2
tjhandle tjh;unsigned long buf_size;unsigned char *jpegBuf =
NULL;unsigned long jpegSize;int width = 352;int height = 288;int
quality = 70;unsigned char *ucp_frame;int j;FILE *fp = NULL;
ucp_frame = malloc(width * height * 3 / 2);if ( NULL == ucp_frame ) {
printf("malloc error ucp_frame\n");
return 0;}
fp = fopen("planar_352x288.raw", "rb");if( NULL == fp ) {
printf("fopen error\n");
return 0;}
j = fread( ucp_frame, 1, width * height * 3 / 2, fp);if( j != width *
height * 3 / 2 ) {
printf("fread error\n");
return 0;}
fclose(fp);
tjh = tjInitCompress();if( NULL == tjh ) {
printf("tjInitCompress error '%s'\n", tjGetErrorStr() );
return 0;}
buf_size = tjBufSizeYUV2( width, PADDING, height, TJSAMP_420);
jpegBuf = tjAlloc(buf_size);
if( tjCompressFromYUV( tjh, ucp_frame, width, PADDING, height,
TJSAMP_420, &jpegBuf, &jpegSize, quality,
TJFLAG_NOREALLOC ) ) {
printf("tjCompressFromYUV error '%s'\n", tjGetErrorStr() );}