*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h> // for strcat
+#include <stdlib.h> /* for malloc */
+#include <string.h> /* for strcat */
#include "config.h"
#include "global.h"
#define OBFRSIZE 4096
static unsigned char obfr[OBFRSIZE];
static unsigned char *optr;
-static int outfile;
+static ostream *outfile;
+unsigned char *static_malloc[6] = {0,0,0,0,0,0}; /*worse case there is 6 buffer in this impl unit.*/
+
+void FreeStaticBuffer()
+{
+ int i;
+ for(i=0;i<6;++i)
+ free(static_malloc[i]);
+}
/*
* store a picture as either one frame or two fields
if (progressive_sequence || progressive_frame || Frame_Store_Flag)
{
/* progressive */
- sprintf(outname,Output_Picture_Filename,frame,'f');
+ my_sprintf(outname,Output_Picture_Filename,frame,'f');
store_one(outname,src,0,Coded_Picture_Width,vertical_size);
}
else
{
/* interlaced */
- sprintf(outname,Output_Picture_Filename,frame,'a');
+ my_sprintf(outname,Output_Picture_Filename,frame,'a');
store_one(outname,src,0,Coded_Picture_Width<<1,vertical_size>>1);
- sprintf(outname,Output_Picture_Filename,frame,'b');
+ my_sprintf(outname,Output_Picture_Filename,frame,'b');
store_one(outname,src,
Coded_Picture_Width,Coded_Picture_Width<<1,vertical_size>>1);
}
hsize = horizontal_size;
- sprintf(tmpname,"%s.Y",outname);
+ my_sprintf(tmpname,"%s.Y",outname);
store_yuv1(tmpname,src[0],offset,incr,hsize,height);
if (chroma_format!=CHROMA444)
height>>=1;
}
- sprintf(tmpname,"%s.U",outname);
+ my_sprintf(tmpname,"%s.U",outname);
store_yuv1(tmpname,src[1],offset,incr,hsize,height);
- sprintf(tmpname,"%s.V",outname);
+ my_sprintf(tmpname,"%s.V",outname);
store_yuv1(tmpname,src[2],offset,incr,hsize,height);
}
{
int i, j;
unsigned char *p;
+ ostream file;
if (!Quiet_Flag)
- fprintf(stderr,"saving %s\n",name);
+ my_fprintf("saving %s\n",name);
- if ((outfile = open(name,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
+ outfile = &file;
+ if(!my_fopen(name, "wb", outfile))
{
- sprintf(Error_Text,"Couldn't create %s\n",name);
+ my_sprintf(Error_Text,"Couldn't create %s\n",name);
Error(Error_Text);
}
}
if (optr!=obfr)
- write(outfile,obfr,optr-obfr);
+ my_fwrite(obfr,optr-obfr,1,outfile);
- close(outfile);
+ my_fclose(outfile);
}
/*
int i,j;
unsigned char *py, *pu, *pv;
static unsigned char *u422, *v422;
+ ostream file;
if (chroma_format==CHROMA444)
Error("4:4:4 not supported for SIF format");
if (!(u422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
*Coded_Picture_Height)))
Error("malloc failed");
+ static_malloc[0] = u422;
if (!(v422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
*Coded_Picture_Height)))
Error("malloc failed");
+ static_malloc[1] = v422;
}
conv420to422(src[1],u422);
strcat(outname,".SIF");
if (!Quiet_Flag)
- fprintf(stderr,"saving %s\n",outname);
+ my_fprintf("saving %s\n",outname);
- if ((outfile = open(outname,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
+ outfile = &file;
+ if(!my_fopen(outname, "wb", outfile))
{
- sprintf(Error_Text,"Couldn't create %s\n",outname);
+ my_sprintf(Error_Text,"Couldn't create %s\n",outname);
Error(Error_Text);
}
}
if (optr!=obfr)
- write(outfile,obfr,optr-obfr);
+ my_fwrite(obfr,optr-obfr,1,outfile);
- close(outfile);
+ my_fclose(outfile);
}
/*
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;
+ ostream file;
if (chroma_format==CHROMA444)
{
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)
strcat(outname,tgaflag ? ".tga" : ".ppm");
if (!Quiet_Flag)
- fprintf(stderr,"saving %s\n",outname);
+ my_fprintf("saving %s\n",outname);
- if ((outfile = open(outname,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
+ outfile = &file;
+ if(! my_fopen(outname, "wb", outfile))
{
- sprintf(Error_Text,"Couldn't create %s\n",outname);
+ my_sprintf(Error_Text,"Couldn't create %s\n",outname);
Error(Error_Text);
}
else
{
/* PPM header */
- sprintf(header,"P6\n%d %d\n255\n",horizontal_size,height);
+ my_sprintf(header,"P6\n%d %d\n255\n",horizontal_size,height);
for (i=0; header[i]!=0; i++)
putbyte(header[i]);
}
if (optr!=obfr)
- write(outfile,obfr,optr-obfr);
+ my_fwrite(obfr,optr-obfr,1,outfile);
- close(outfile);
+ my_fclose(outfile);
}
static void putbyte(c)
if (optr == obfr+OBFRSIZE)
{
- write(outfile,obfr,OBFRSIZE);
+ my_fwrite(obfr,OBFRSIZE,1,outfile);
optr = obfr;
}
}