FACT++  1.0
void Writer::Png ( const char *  fname,
const byte buf,
struct timeval *  date,
const TVector2  xy 
)
static

Definition at line 17 of file Writer.cc.

References video_init::name, and t.

Referenced by ~Writer().

19 {
20  MTime t(*date);
21  TString mjd;
22  mjd += t.GetMjd()-52000;
23  mjd = mjd.Strip(TString::kBoth);
24  if (mjd.Length()<10)
25  mjd.Append('0', 10-mjd.Length());
26 
27  TString pos;
28  pos += xy.X();
29  pos = pos.Strip(TString::kBoth);
30  pos +="_";
31  TString posy;
32  posy += xy.Y();
33  posy = posy.Strip(TString::kBoth);
34  pos +=posy;
35 
36  TString name = fname;
37  name += "_";
38  name += mjd;
39  name += "_";
40  name += pos;
41  name += ".png";
42 
43  cout << "Writing PNG '" << name << "'" << endl;
44 
45  //
46  // open file
47  //
48  FILE *fd = fopen(name, "w");
49  if (!fd)
50  {
51  cout << "Warning: Cannot open file for writing." << endl;
52  return;
53  }
54 
55  //
56  // allocate memory
57  //
58  png_structp fPng = png_create_write_struct(PNG_LIBPNG_VER_STRING,
59  NULL, NULL, NULL);
60 
61  if (!fPng)
62  {
63  cout << "Warning: Unable to create PNG structure" << endl;
64  fclose(fd);
65  return;
66  }
67 
68 
69  png_infop fInfo = png_create_info_struct(fPng);
70 
71  if (!fInfo)
72  {
73  cout << "Warning: Unable to create PNG info structure" << endl;
74  png_destroy_write_struct (&fPng, NULL);
75  fclose(fd);
76  return;
77  }
78 
79  fInfo->width = 768;
80  fInfo->height = 576;
81  fInfo->bit_depth = 8;
82  fInfo->color_type = PNG_COLOR_TYPE_GRAY;
83 
84  //
85  // set jump-back point in case of errors
86  //
87  if (setjmp(fPng->jmpbuf))
88  {
89  cout << "longjmp Warning: PNG encounterd an error!" << endl;
90  png_destroy_write_struct (&fPng, &fInfo);
91  fclose(fd);
92  return;
93  }
94 
95  //
96  // connect file to PNG-Structure
97  //
98  png_init_io(fPng, fd);
99 
100  // png_set_compression_level (fPng, Z_BEST_COMPRESSION);
101 
102  //
103  // Write header
104  //
105  png_write_info (fPng, fInfo);
106 
107  //
108  // Write Time Chunks
109  //
110  /*
111  if (date)
112  {
113  char text[36];
114 
115  Timer timet(date);
116  sprintf(text, "*** %s ***", timet.GetTimeStr());
117  png_write_chunk(fPng, (png_byte*)"UTC", (png_byte*)text, strlen(text));
118  sprintf(text,"*** %s %s %.1f %i ***", tzname[0], tzname[1], 1.0/3600*timezone, daylight);
119  png_write_chunk(fPng, (png_byte*)"ZONE", (png_byte*)text, strlen(text));
120  }
121  */
122 
123  //
124  // Write bitmap data
125  //
126  for (unsigned int y=0; y<768*576; y+=768)
127  png_write_row (fPng, (png_byte*)buf+y);
128 
129  //
130  // Write footer
131  //
132  png_write_end (fPng, fInfo);
133 
134  //
135  // free memory
136  //
137  png_destroy_write_struct (&fPng, &fInfo);
138 
139  fclose(fd);
140 }
TT t
Definition: test_client.c:26

+ Here is the caller graph for this function: