2 * GraphLCD driver library
4 * image.c - Image output device
5 * Output goes to a image file instead of LCD.
7 * This file is released under the GNU General Public License. Refer
8 * to the COPYING file distributed with this package.
10 * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
24 cDriverImage::cDriverImage(cDriverConfig * config)
27 oldConfig = new cDriverConfig(*config);
30 cDriverImage::~cDriverImage()
35 int cDriverImage::Init()
37 width = config->width;
40 height = config->height;
43 lineSize = (width + 7) / 8;
45 for (unsigned int i = 0; i < config->options.size(); i++)
47 if (config->options[i].name == "")
52 newLCD = new unsigned char[lineSize * height];
54 memset(newLCD, 0, lineSize * height);
55 oldLCD = new unsigned char[lineSize * height];
57 memset(oldLCD, 0, lineSize * height);
66 syslog(LOG_INFO, "%s: image driver initialized.\n", config->name.c_str());
70 int cDriverImage::DeInit()
79 int cDriverImage::CheckSetup()
81 if (config->width != oldConfig->width ||
82 config->height != oldConfig->height)
89 if (config->upsideDown != oldConfig->upsideDown ||
90 config->invert != oldConfig->invert)
92 oldConfig->upsideDown = config->upsideDown;
93 oldConfig->invert = config->invert;
99 void cDriverImage::Clear()
101 memset(newLCD, 0, lineSize * height);
104 void cDriverImage::Set8Pixels(int x, int y, unsigned char data)
106 if (x >= width || y >= height)
109 if (!config->upsideDown)
111 // normal orientation
112 newLCD[lineSize * y + x / 8] |= data;
116 // upside down orientation
119 newLCD[lineSize * y + x / 8] |= ReverseBits(data);
123 void cDriverImage::Refresh(bool refreshAll)
133 if (CheckSetup() > 0)
136 for (i = 0; i < lineSize * height; i++)
138 if (newLCD[i] != oldLCD[i])
147 sprintf(fileName, "%s/%s%05d.%s", "/tmp", "lcd", counter, "pbm");
148 fp = fopen(fileName, "wb");
151 sprintf(str, "P4\n%d %d\n", width, height);
152 fwrite(str, strlen(str), 1, fp);
153 for (i = 0; i < lineSize * height; i++)
155 c = newLCD[i] ^ (config->invert ? 0xff : 0x00);
156 fwrite(&c, 1, 1, fp);
157 oldLCD[i] = newLCD[i];
167 } // end of namespace