source: trunk/Cosy/videodev/PngReader.cc@ 9988

Last change on this file since 9988 was 8860, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 2.5 KB
Line 
1#include "png.h"
2
3#include "PngReader.h"
4
5#include <iostream>
6
7#include "PixClient.h"
8
9ClassImp(PngReader);
10
11using namespace std;
12
13char *PngReader::GetImg(unsigned int frame)
14{
15 char txt1[100];
16
17 frame %= 333;
18
19 sprintf(txt1, "file%04d.png", frame);
20
21 // cout << "Reading PNG '" << txt1 << "'" << endl;
22
23 char txt2[200];
24 sprintf(txt2, "/home/caos/Dani/Cosy/smallleds/%s", txt1);
25 //sprintf(txt2, "/home/caos/cosy.lp/pix/stable_1min/%s", txt1);
26
27 //
28 // open file
29 //
30 FILE *fd = fopen(txt2, "r");
31 if (!fd)
32 {
33 cout << "Cannot open file." << endl;
34 return 0;
35 }
36 //
37 // allocate memory
38 //
39 png_structp fPng = png_create_read_struct(PNG_LIBPNG_VER_STRING,
40 NULL, NULL, NULL);
41
42 if (!fPng)
43 {
44 cout << "Warning: Unable to create PNG structure" << endl;
45 fclose(fd);
46 return 0;
47 }
48
49
50 png_infop fInfo = png_create_info_struct(fPng);
51
52 if (!fInfo)
53 {
54 cout << "Warning: Unable to create PNG info structure" << endl;
55 png_destroy_read_struct (&fPng, NULL, NULL);
56 fclose(fd);
57 return 0;
58 }
59
60 //
61 // set jump-back point in case of errors
62 //
63 if (setjmp(fPng->jmpbuf))
64 {
65 cout << "longjmp Warning: PNG encounterd an error!" << endl;
66 png_destroy_read_struct (&fPng, &fInfo, NULL);
67 fclose(fd);
68 return 0;
69 }
70
71 //
72 // connect file to PNG-Structure
73 //
74 png_init_io(fPng, fd);
75
76 // png_set_compression_level (fPng, Z_BEST_COMPRESSION);
77
78 png_read_png(fPng, fInfo, 0, NULL);
79
80 //
81 // Write bitmap data
82 //
83 for (unsigned int y=0; y<576; y++)
84 for (unsigned int x=0; x<768; x++)
85 *(fImg+(y*768)+x) = fInfo->row_pointers[y][x];
86
87 //
88 // free memory
89 //
90 png_destroy_read_struct (&fPng, &fInfo, NULL);
91
92 fclose(fd);
93
94 return fImg;
95}
96
97PngReader::PngReader(PixClient &client) : fClient(client)
98{
99 cout << "Starting thread..." << flush;
100 RunThread();
101 cout << "done." << endl;
102
103}
104
105PngReader::~PngReader()
106{
107 cout << "Stopping thread..." << flush;
108 CancelThread();
109 cout << "done." << endl;
110}
111
112Int_t PngReader::Thread()
113{
114 Sleep(3000000);
115
116 int i=0;
117
118 gettimeofday(&fTime, NULL);
119
120 while (1)
121 {
122 // if (i<536)
123 // {
124 GetImg(i);
125
126 TThread::CancelPoint();
127
128 fClient.ProcessFrame(i++, (byte*)fImg, &fTime);
129 // usleep(10000);
130 // }
131 // else exit();
132 fTime.tv_sec += 1;
133 Sleep(1000);
134 }
135
136 return 0;
137}
138
Note: See TracBrowser for help on using the repository browser.