*/
#include <stdlib.h> /* for malloc */
-#include <fcntl.h>
#include <string.h> /* for strcat */
#include "config.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
{
int i, j;
unsigned char *p;
+ ostream file;
if (!Quiet_Flag)
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))
{
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);
if (!Quiet_Flag)
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))
{
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)
if (!Quiet_Flag)
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))
{
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 void putbyte(c)
if (optr == obfr+OBFRSIZE)
{
- write(outfile,obfr,OBFRSIZE);
+ my_fwrite(obfr,OBFRSIZE,1,outfile);
optr = obfr;
}
}