X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fgdcmmpeg2%2Fsrc%2Fmpeg2dec%2Fstore.c;h=ae42ffb2e6fd0ad0a0b29d91a82ee034d7e679ea;hb=98cf38e32be18dc2b7d3d1a13e45f60717b008bc;hp=852b843593b4cd6ea0e67317f89a6b8e45c33a05;hpb=b5e9b8dee5030829b7e694277a86dc54e14e8f8e;p=gdcm.git diff --git a/src/gdcmmpeg2/src/mpeg2dec/store.c b/src/gdcmmpeg2/src/mpeg2dec/store.c index 852b8435..ae42ffb2 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/store.c +++ b/src/gdcmmpeg2/src/mpeg2dec/store.c @@ -42,10 +42,14 @@ static void store_sif _ANSI_ARGS_((char *outname, unsigned char *src[], int offset, int incr, int height)); static void store_ppm_tga _ANSI_ARGS_((char *outname, unsigned char *src[], int offset, int incr, int height, int tgaflag)); +static void store_in_mem _ANSI_ARGS_((char *outmem, unsigned char *src[], + int offset, int incr, int height)); static void store_yuv1 _ANSI_ARGS_((char *name, unsigned char *src, int offset, int incr, int width, int height)); static void putbyte _ANSI_ARGS_((int c)); static void putword _ANSI_ARGS_((int w)); +static void mem_putbyte _ANSI_ARGS_((int c)); +/*static void mem_putword _ANSI_ARGS_((int w));*/ static void conv422to444 _ANSI_ARGS_((unsigned char *src, unsigned char *dst)); static void conv420to422 _ANSI_ARGS_((unsigned char *src, unsigned char *dst)); @@ -111,6 +115,9 @@ int offset, incr, height; case T_PPM: store_ppm_tga(outname,src,offset,incr,height,0); break; + case T_MEM: + store_in_mem(OUTMEM,src,offset,incr,height); + break; #ifdef DISPLAY case T_X11: dither(src); @@ -395,6 +402,149 @@ int tgaflag; my_fclose(outfile); } +/* + * store as PPM (PBMPLUS) or uncompressed Truevision TGA ('Targa') file + */ +static void store_in_mem(outmem,src,offset,incr,height) +char *outmem; +unsigned char *src[]; +int offset, incr, height; +{ + int i, j; + int y, u, v, r, g, b; + int crv, cbu, cgu, cgv; + unsigned char *py, *pu, *pv; + /*static unsigned char tga24[14] = {0,0,2,0,0,0,0, 0,0,0,0,0,24,32};*/ + /*char header[FILENAME_LENGTH];*/ + static unsigned char *u422, *v422, *u444, *v444; + (void)outmem; + + if (chroma_format==CHROMA444) + { + u444 = src[1]; + v444 = src[2]; + } + else + { + if (!u444) + { + if (chroma_format==CHROMA420) + { + if (!(u422 = (unsigned char *)malloc((Coded_Picture_Width>>1) + *Coded_Picture_Height))) + Error("malloc failed"); + static_malloc[2] = u422; + if (!(v422 = (unsigned char *)malloc((Coded_Picture_Width>>1) + *Coded_Picture_Height))) + Error("malloc failed"); + static_malloc[3] = v422; + } + + if (!(u444 = (unsigned char *)malloc(Coded_Picture_Width + *Coded_Picture_Height))) + Error("malloc failed"); + static_malloc[4] = u444; + + if (!(v444 = (unsigned char *)malloc(Coded_Picture_Width + *Coded_Picture_Height))) + Error("malloc failed"); + static_malloc[5] = v444; + } + + if (chroma_format==CHROMA420) + { + conv420to422(src[1],u422); + conv420to422(src[2],v422); + conv422to444(u422,u444); + conv422to444(v422,v444); + } + else + { + conv422to444(src[1],u444); + conv422to444(src[2],v444); + } + } + + /*strcat(outname,tgaflag ? ".tga" : ".ppm");*/ + + /*if (!Quiet_Flag) + my_fprintf("saving %s\n",outname);*/ + + /* outfile = &file; + if(! my_fopen(outname, "wb", outfile)) + { + my_sprintf(Error_Text,"Couldn't create %s\n",outname); + Error(Error_Text); + }*/ + + optr = obfr; + +#if 0 + if (tgaflag) + { + /* TGA header */ + for (i=0; i<12; i++) + putbyte(tga24[i]); + + putword(horizontal_size); putword(height); + putbyte(tga24[12]); putbyte(tga24[13]); + } + else + { + /* PPM header */ + my_sprintf(header,"P6\n%d %d\n255\n",horizontal_size,height); + + for (i=0; header[i]!=0; i++) + putbyte(header[i]); + } +#endif + + /* matrix coefficients */ + crv = Inverse_Table_6_9[matrix_coefficients][0]; + cbu = Inverse_Table_6_9[matrix_coefficients][1]; + cgu = Inverse_Table_6_9[matrix_coefficients][2]; + cgv = Inverse_Table_6_9[matrix_coefficients][3]; + + for (i=0; i>16]; + g = Clip[(y - cgu*u - cgv*v + 32768)>>16]; + b = Clip[(y + cbu*u + 32786)>>16]; + + +#if 0 + if (tgaflag) + { + putbyte(b); putbyte(g); putbyte(r); + } + else + { + putbyte(r); putbyte(g); putbyte(b); + } +#else + mem_putbyte(r); mem_putbyte(g); mem_putbyte(b); +#endif + } + } + + if (optr!=obfr) + { + /*my_fwrite(obfr,optr-obfr,1,outfile);*/ + memcpy(OUTMEM,obfr,optr-obfr); OUTMEM+=(optr-obfr); + } + + /*my_fclose(outfile);*/ +} + static void putbyte(c) int c; { @@ -413,6 +563,25 @@ int w; putbyte(w); putbyte(w>>8); } +static void mem_putbyte(c) +int c; +{ + *optr++ = c; + + if (optr == obfr+OBFRSIZE) + { + /*my_fwrite(obfr,OBFRSIZE,1,outfile);*/ + memcpy(OUTMEM,obfr,OBFRSIZE);OUTMEM+=OBFRSIZE; + optr = obfr; + } +} + +/*static void mem_putword(w) +int w; +{ + mem_putbyte(w); mem_putbyte(w>>8); +}*/ + /* horizontal 1:2 interpolation filter */ static void conv422to444(src,dst) unsigned char *src,*dst;