summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-04-12 15:41:29 +0000
committerTavian Barnes <tavianator@gmail.com>2009-04-12 15:41:29 +0000
commit510c9a95fb5f3f4a40a19ce66c95344c2013085f (patch)
tree4f69c12e773da63b2f5d7c116bd241043de24003
parentbef2ee297d3492c8a54e61fe498e6eda518da250 (diff)
downloaddimension-510c9a95fb5f3f4a40a19ce66c95344c2013085f.tar.xz
Change argument order of dmnsn_set_pixel; write C++ canvas wrapper.
-rw-r--r--libdimension-png/png.c8
-rw-r--r--libdimension/canvas.c4
-rw-r--r--libdimension/dimension/canvas.h4
-rw-r--r--libdimensionxx/canvas.cpp8
-rw-r--r--libdimensionxx/dimensionxx/canvas.hpp22
-rw-r--r--tests/png.c6
6 files changed, 41 insertions, 11 deletions
diff --git a/libdimension-png/png.c b/libdimension-png/png.c
index 2eb6a7d..9bd22be 100644
--- a/libdimension-png/png.c
+++ b/libdimension-png/png.c
@@ -231,7 +231,7 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
color = dmnsn_color_from_sRGB(sRGB);
color.trans = ((double)((png_pixel[6] << UINT16_C(8))
+ png_pixel[7]))/UINT16_MAX;
- dmnsn_set_pixel(*canvas, color, x, height - y - 1);
+ dmnsn_set_pixel(*canvas, x, height - y - 1, color);
}
}
} else {
@@ -247,7 +247,7 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
/UINT16_MAX;
color = dmnsn_color_from_sRGB(sRGB);
- dmnsn_set_pixel(*canvas, color, x, height - y - 1);
+ dmnsn_set_pixel(*canvas, x, height - y - 1, color);
}
}
}
@@ -264,7 +264,7 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
color = dmnsn_color_from_sRGB(sRGB);
color.trans = ((double)png_pixel[3])/UINT8_MAX;
- dmnsn_set_pixel(*canvas, color, x, height - y - 1);
+ dmnsn_set_pixel(*canvas, x, height - y - 1, color);
}
}
} else {
@@ -277,7 +277,7 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
sRGB.B = ((double)png_pixel[2])/UINT8_MAX;
color = dmnsn_color_from_sRGB(sRGB);
- dmnsn_set_pixel(*canvas, color, x, height - y - 1);
+ dmnsn_set_pixel(*canvas, x, height - y - 1, color);
}
}
}
diff --git a/libdimension/canvas.c b/libdimension/canvas.c
index 257f1a9..49096fc 100644
--- a/libdimension/canvas.c
+++ b/libdimension/canvas.c
@@ -111,8 +111,8 @@ dmnsn_get_pixel(const dmnsn_canvas *canvas, unsigned int x, unsigned int y)
}
void
-dmnsn_set_pixel(dmnsn_canvas *canvas, dmnsn_color color,
- unsigned int x, unsigned int y)
+dmnsn_set_pixel(dmnsn_canvas *canvas,
+ unsigned int x, unsigned int y, dmnsn_color color)
{
dmnsn_wrlock_pixel(canvas, x, y);
canvas->pixels[y*canvas->x + x] = color;
diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h
index 9a70327..4449403 100644
--- a/libdimension/dimension/canvas.h
+++ b/libdimension/dimension/canvas.h
@@ -46,8 +46,8 @@ void dmnsn_delete_canvas(dmnsn_canvas *canvas);
/* These handle the rwlocks correctly */
dmnsn_color dmnsn_get_pixel(const dmnsn_canvas *canvas,
unsigned int x, unsigned int y);
-void dmnsn_set_pixel(dmnsn_canvas *canvas, dmnsn_color color,
- unsigned int x, unsigned int y);
+void dmnsn_set_pixel(dmnsn_canvas *canvas,
+ unsigned int x, unsigned int y, dmnsn_color color);
/* Manual locking */
void dmnsn_rdlock_pixel(const dmnsn_canvas *canvas,
diff --git a/libdimensionxx/canvas.cpp b/libdimensionxx/canvas.cpp
index 8b90fe9..2340066 100644
--- a/libdimensionxx/canvas.cpp
+++ b/libdimensionxx/canvas.cpp
@@ -19,3 +19,11 @@
*************************************************************************/
#include "dimensionxx.hpp"
+
+namespace Dimension
+{
+ Canvas::~Canvas()
+ {
+ dmnsn_delete_canvas(m_canvas);
+ }
+}
diff --git a/libdimensionxx/dimensionxx/canvas.hpp b/libdimensionxx/dimensionxx/canvas.hpp
index e2e493a..f51aa75 100644
--- a/libdimensionxx/dimensionxx/canvas.hpp
+++ b/libdimensionxx/dimensionxx/canvas.hpp
@@ -23,6 +23,28 @@
namespace Dimension
{
+ class Canvas
+ {
+ public:
+ Canvas(unsigned int x, unsigned int y)
+ : m_canvas(dmnsn_new_canvas(x, y)) { }
+ virtual ~Canvas();
+
+ Color pixel(unsigned int x, unsigned int y) const
+ { return Color(dmnsn_get_pixel(m_canvas, x, y)); }
+ void pixel(unsigned int x, unsigned int y, const Color& c)
+ { dmnsn_set_pixel(m_canvas, x, y, c.dmnsn()); }
+
+ dmnsn_canvas* dmnsn() { return m_canvas; }
+ const dmnsn_canvas* dmnsn() const { return m_canvas; }
+
+ private:
+ dmnsn_canvas* m_canvas;
+
+ // Copying prohibited
+ Canvas(const Canvas&);
+ Canvas& operator=(const Canvas&);
+ };
}
#endif /* DIMENSIONXX_CANVAS_HPP */
diff --git a/tests/png.c b/tests/png.c
index 2b3bf5b..b7edd95 100644
--- a/tests/png.c
+++ b/tests/png.c
@@ -67,7 +67,7 @@ int main() {
color.trans = 0.5;
}
- dmnsn_set_pixel(canvas, color, i, j);
+ dmnsn_set_pixel(canvas, i, j, color);
/*
* CIE Lab colorspace
@@ -85,7 +85,7 @@ int main() {
color.trans = 0.5;
}
- dmnsn_set_pixel(canvas, color, i + x, j);
+ dmnsn_set_pixel(canvas, i + x, j, color);
/*
* CIE Luv colorspace
@@ -103,7 +103,7 @@ int main() {
color.trans = 0.5;
}
- dmnsn_set_pixel(canvas, color, i + 2*x, j);
+ dmnsn_set_pixel(canvas, i + 2*x, j, color);
}
}