]> Creatis software - gdcm.git/blob - src/gdcmmpeg2/src/mpeg2enc/writepic.c
avoid segfault when unaware user sets SplitOnly to true, and the asks for ImageDataVector
[gdcm.git] / src / gdcmmpeg2 / src / mpeg2enc / writepic.c
1 /* writepic.c, write reconstructed pictures                                 */
2
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
4
5 /*
6  * Disclaimer of Warranty
7  *
8  * These software programs are available to the user without any license fee or
9  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
10  * any and all warranties, whether express, implied, or statuary, including any
11  * implied warranties or merchantability or of fitness for a particular
12  * purpose.  In no event shall the copyright-holder be liable for any
13  * incidental, punitive, or consequential damages of any kind whatsoever
14  * arising from the use of these programs.
15  *
16  * This disclaimer of warranty extends to the user of these programs and user's
17  * customers, employees, agents, transferees, successors, and assigns.
18  *
19  * The MPEG Software Simulation Group does not represent or warrant that the
20  * programs furnished hereunder are free of infringement of any third-party
21  * patents.
22  *
23  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24  * are subject to royalty fees to patent holders.  Many of these patents are
25  * general enough such that they are unavoidable regardless of implementation
26  * design.
27  *
28  */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "config.h"
33 #include "global.h"
34
35 void writeframe(fname,frame)
36 char *fname;
37 unsigned char *frame[];
38 {
39   int chrom_hsize, chrom_vsize;
40   char name[128];
41   FILE *fd;
42
43   chrom_hsize = (chroma_format==CHROMA444) ? horizontal_size
44                                            : horizontal_size>>1;
45
46   chrom_vsize = (chroma_format!=CHROMA420) ? vertical_size
47                                            : vertical_size>>1;
48
49   if (fname[0]=='-')
50     return;
51
52   /* Y */
53   sprintf(name,"%s.Y",fname);
54   if (!(fd = fopen(name,"wb")))
55   {
56     sprintf(errortext,"Couldn't create %s\n",name);
57     error(errortext);
58   }
59   fwrite(frame[0],1,horizontal_size*vertical_size,fd);
60   fclose(fd);
61
62   /* Cb */
63   sprintf(name,"%s.U",fname);
64   if (!(fd = fopen(name,"wb")))
65   {
66     sprintf(errortext,"Couldn't create %s\n",name);
67     error(errortext);
68   }
69   fwrite(frame[1],1,chrom_hsize*chrom_vsize,fd);
70   fclose(fd);
71
72   /* Cr */
73   sprintf(name,"%s.V",fname);
74   if (!(fd = fopen(name,"wb")))
75   {
76     sprintf(errortext,"Couldn't create %s\n",name);
77     error(errortext);
78   }
79   fwrite(frame[2],1,chrom_hsize*chrom_vsize,fd);
80   fclose(fd);
81 }