Skip to content

Commit

Permalink
Added D0142 COHP support by MTK
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Zakharchenko committed Oct 19, 2016
1 parent 8190085 commit 64d4518
Show file tree
Hide file tree
Showing 7 changed files with 2,438 additions and 1,464 deletions.
62 changes: 54 additions & 8 deletions app/360tools_conv/360tools_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ static S360_ARGS_OPT argopt[] = \
"16: ROHP to OHP\n\t"
"21: ERP to RISP\n\t"
"22: RISP to ERP\n\t"
"25: ERP to COHP\n\t"
"26: COHP to ERP\n\t"
"31: CPP to ERP\n\t"
"32: CPP to ISP\n\t"
"33: CPP to CMP\n\t"
Expand Down Expand Up @@ -184,11 +186,12 @@ static void print_usage(void)

int main(int argc, const char * argv[])
{
S360_IMAGE * imgi = NULL;
S360_IMAGE * imgo = NULL;
S360_MAP * map = NULL;
FILE * fpi = NULL;
FILE * fpo = NULL;
S360_IMAGE * imgi = NULL;
S360_IMAGE * imgo = NULL;
S360_IMAGE * imgos = NULL;
S360_MAP * map = NULL;
FILE * fpi = NULL;
FILE * fpo = NULL;
int (* fn_conv)(S360_IMAGE * imgi, S360_IMAGE * imgo, int opt, S360_MAP * map);
int opt = 0;
int ret, pic_cnt = 0;
Expand Down Expand Up @@ -314,6 +317,21 @@ int main(int argc, const char * argv[])
print_usage();
goto END;
}
if((cfmt == CONV_FMT_ERP_TO_COHP) && (((w_out)%8 != 0 ||
h_out != 4*NEAREST_EVEN((((int)((int)((w_out)/4)/4)*4))*SIN_60))))
{
/* some suggested dimensions */
int w_tri, h_tri;
w_tri = ((int)((int)((w_out)/4)/4)*4);
h_tri = NEAREST_EVEN((w_tri)*SIN_60);
w_tri = w_tri*4;
h_tri = h_tri*4;
s360_print("Invalid output resolution %dx%d, COHP recommended aspect "
" ratio: 112:97\n", w_out, h_out);
s360_print("Suggested sample dimension: %dx%d\n", w_tri, h_tri);
print_usage();
goto END;
}

if(!opt_flag[CMD_FLAG_CONV_OWIDTH]) w_out = w_in;
if(!opt_flag[CMD_FLAG_CONV_OHEIGHT]) h_out = h_in;
Expand Down Expand Up @@ -343,8 +361,14 @@ int main(int argc, const char * argv[])
opt |= S360_OPT_PAD;
}

if (cfmt == CONV_FMT_ERP_TO_COHP)
{
imgos = s360_img_create(w_out, h_out, cs_int, opt);
w_out = w_out * 2;
}
imgi = s360_img_create(w_in, h_in, cs_int, opt);
imgo = s360_img_create(w_out, h_out, cs_int, opt);

if(imgi == NULL || imgo == NULL)
{
s360_print("Failed to create image buffer\n");
Expand Down Expand Up @@ -425,6 +449,12 @@ int main(int argc, const char * argv[])
case CONV_FMT_CPP_TO_SSP:
fn_conv = o360_cpp_to_ssp;
break;
case CONV_FMT_ERP_TO_COHP:
fn_conv = s360_erp_to_cohp;
break;
case CONV_FMT_COHP_TO_ERP:
fn_conv = s360_cohp_to_erp;
break;
default:
s360_print("Unsupprted converting format\n");
print_usage();
Expand Down Expand Up @@ -457,18 +487,33 @@ int main(int argc, const char * argv[])

if(S360_SUCCEEDED(ret))
{
s360_print("convert succeeded: resolution= %dx%d\n", imgo->width, imgo->height);
if (cfmt == CONV_FMT_ERP_TO_COHP)
s360_print("convert succeeded: resolution= %dx%d\n", imgo->width / 2, imgo->height);
else
s360_print("convert succeeded: resolution= %dx%d\n", imgo->width, imgo->height);
}
else
{
s360_print("convert failed: ret = %d\n", ret);
goto END;
}

if (cfmt == CONV_FMT_ERP_TO_COHP)
{
s360_img_copy(imgos, imgo);
}

fpo = fopen(fname_out, "ab");
if(fpo)
{
s360_img_write(fpo, imgo, cs_out);
if (cfmt == CONV_FMT_ERP_TO_COHP)
{
s360_img_write(fpo, imgos, cs_out);
}
else
{
s360_img_write(fpo, imgo, cs_out);
}
fclose(fpo);
}

Expand All @@ -479,7 +524,8 @@ int main(int argc, const char * argv[])
if(fpi) fclose(fpi);
if(imgi) s360_img_delete(imgi);
if(imgo) s360_img_delete(imgo);
if (map) s360_map_delete(map);
if(imgos) s360_img_delete(imgos);
if(map) s360_map_delete(map);

s360_deinit();

Expand Down
2 changes: 2 additions & 0 deletions src/360tools_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ typedef enum
CONV_FMT_ROHP_TO_OHP,
CONV_FMT_ERP_TO_RISP1 = 21,
CONV_FMT_RISP1_TO_ERP,
CONV_FMT_ERP_TO_COHP = 25,
CONV_FMT_COHP_TO_ERP,
CONV_FMT_CPP_TO_ERP = 31,
CONV_FMT_CPP_TO_ISP,
CONV_FMT_CPP_TO_CMP,
Expand Down
58 changes: 58 additions & 0 deletions src/360tools_img.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,61 @@ int s360_img_align(S360_IMAGE * img, int align)
}
}

int s360_img_copy(S360_IMAGE *out, S360_IMAGE *in)
{
int w = out->width;
int h = out->height;
int s = out->stride[0];
int w_tri = GET_W_TRI_OHP(w*2);
int h_tri = GET_H_TRI_OHP(w_tri);
int i, j;
int x;
uint8 *p1, *p2;
uint16 *q1, *q2;

for (i=0; i<3; i++)
{
for (j=0; j<h; j++)
{
//if (out->colorspace==S360_COLORSPACE_YUV420) {
if (0)
{
p1 = (uint8*)out->buffer[i];
p2 = (uint8*)in->buffer[i];
memcpy(&p1[j*out->stride[i]], &p2[j*in->stride[i]+w_tri/2], w*2);
}
else if (out->colorspace==S360_COLORSPACE_YUV420_10)
{
q1 = (uint16*)out->buffer[i];
q2 = (uint16*)in->buffer[i];
memcpy(&q1[j*out->stride[i]], &q2[j*in->stride[i]+w_tri/2], w*2);
}
}
for (j=0; j<h/2; j++)
{
x = CEILING((double)w_tri*j/h);
if (!x) x=1;
memcpy(&q1[j*out->stride[i]], &q2[j*in->stride[i]+w_tri*7/2], x*2);
x = CEILING((double)w_tri*(h/2-1-j)/h);
if (!x) x=1;
memcpy(&q1[j*out->stride[i]+w_tri*3/2+x], &q2[j*in->stride[i]+w_tri*3+x], (w_tri/2-x)*2);
}
for (j=h/2; j<h; j++)
{
x = CEILING((double)w_tri*(h-1-j)/h);
if (!x) x=1;
memcpy(&q1[j*out->stride[i]], &q2[j*in->stride[i]+w_tri*7/2], x*2);
x = CEILING((double)w_tri*(h-1-j)/h);
if (!x) x=1;
memcpy(&q1[j*out->stride[i]+w_tri*3/2+(w_tri/2-x)], &q2[j*in->stride[i]+w_tri*3+(w_tri/2-x)], x*2);
}

if (i==0)
{
h/=2;
w/=2;
w_tri/=2;
}
}
return S360_OK;
}
3 changes: 3 additions & 0 deletions src/360tools_img.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ int s360_img_read(FILE * fp, S360_IMAGE * img, int cs);
/* write an image to file */
int s360_img_write(FILE * fp, S360_IMAGE * img, int cs);

/* copy image */
int s360_img_copy(S360_IMAGE *out, S360_IMAGE *in);

/* change width and height of the image */
int s360_img_realloc(S360_IMAGE * img, int w, int h, int opt);

Expand Down
Loading

0 comments on commit 64d4518

Please sign in to comment.