summaryrefslogtreecommitdiff
path: root/lib/Image.cc
diff options
context:
space:
mode:
authorPixel <Pixel>2001-12-08 13:57:52 +0000
committerPixel <Pixel>2001-12-08 13:57:52 +0000
commita83a43e57be59ed407d98f465d02953af5ae0160 (patch)
tree91aa1ea4a24e5b85ef26686828054e858cec21aa /lib/Image.cc
parentc54dfe9b844f6c5d8969669f5144e721e2af82b0 (diff)
*hum* some changes...
Diffstat (limited to 'lib/Image.cc')
-rw-r--r--lib/Image.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/Image.cc b/lib/Image.cc
new file mode 100644
index 0000000..9b41b4e
--- /dev/null
+++ b/lib/Image.cc
@@ -0,0 +1,78 @@
+#include "Image.h"
+#include "config.h"
+
+Image::Image(unsigned int ax, unsigned int ay) : x(ax), y(ay), img((Color *) malloc(x * y * sizeof(Color))) {
+ Fill();
+}
+
+Image::~Image() {
+ free((void *)img);
+}
+
+bool Image::CanWrite() {
+ return false;
+}
+
+String Image::GetName() {
+ return String(_("Image ")) + x + "x" + y;
+}
+
+void Image::Fill(Color c) {
+ for (unsigned int i = 0; i < x * y; i++) {
+ img[i] = c;
+ }
+}
+
+Color Image::GetPixel(unsigned int px, unsigned int py) {
+ if ((px >= x) || (py >= y)) {
+ return Color(0, 0, 0, 0);
+ }
+
+ return img[x * py + px];
+}
+
+void Image::SetPixel(unsigned int px, unsigned int py, Color c) {
+ if ((px >= x) || (py >= y)) {
+ return;
+ }
+
+ img[x * py + px] = c;
+}
+
+bool Image::Prepare(unsigned int f) {
+ if (GetSize()) return false;
+
+ switch (f) {
+ case FORMAT_TGA_BASIC:
+ TGAHeader Header;
+ TGAFooter Footer;
+
+ Header.IDLength = 0;
+ Header.ColorMapType = 0;
+ Header.ImageType = 2;
+ Header.CM_FirstEntry = 0;
+ Header.CM_Length = 0;
+ Header.CM_EntrySize = 0;
+ Header.IS_XOrigin = 0;
+ Header.IS_YOrigin = 0;
+ Header.IS_Width = x;
+ Header.IS_Height = y;
+ Header.IS_Depth = 32;
+ Header.IS_Descriptor = 0x20;
+
+ Footer.ExtOffset = 0;
+ Footer.DevOffset = 0;
+ strcpy(Footer.Sig, "TRUEVISION-XFILE.");
+
+ write(&Header, sizeof(Header));
+ write(img, x * y * sizeof(Color));
+ write(&Footer, sizeof(Footer));
+
+ return true;
+
+ break;
+ default:
+ return false;
+ }
+}
+