OSDN Git Service

[added] bitmap clear by default
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sat, 5 Feb 2011 11:24:24 +0000 (11:24 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sat, 5 Feb 2011 11:24:24 +0000 (11:24 +0000)
[fixed] pitch in gdx2d pixmap set_pixel/get_pixel was wrong o_O

gdx/jni/gdx2d/gdx2d.c
gdx/src/com/badlogic/gdx/graphics/Pixmap.java
gdx/src/com/badlogic/gdx/graphics/g2d/Gdx2DPixmap.java

index 0392388..8426dd3 100644 (file)
@@ -389,14 +389,14 @@ inline int32_t in_pixmap(const gdx2d_pixmap* pixmap, int32_t x, int32_t y) {
 inline void set_pixel(unsigned char* pixels, uint32_t width, uint32_t height, uint32_t bpp, set_pixel_func pixel_func, int32_t x, int32_t y, uint32_t col) {\r
        if(x < 0 || y < 0) return;\r
        if(x >= (int32_t)width || y >= (int32_t)height) return;\r
-       pixels = pixels + (x + height * y) * bpp;\r
+       pixels = pixels + (x + width * y) * bpp;\r
        pixel_func(pixels, col);\r
 }\r
 \r
 uint32_t gdx2d_get_pixel(const gdx2d_pixmap* pixmap, int32_t x, int32_t y) {\r
        if(!in_pixmap(pixmap, x, y))\r
                return 0;\r
-       unsigned char* ptr = (unsigned char*)pixmap->pixels + (x + pixmap->height * y) * bytes_per_pixel(pixmap->format);\r
+       unsigned char* ptr = (unsigned char*)pixmap->pixels + (x + pixmap->width * y) * bytes_per_pixel(pixmap->format);\r
        return to_RGBA8888(pixmap->format, get_pixel_func_ptr(pixmap->format)(ptr));\r
 }\r
 \r
@@ -422,7 +422,7 @@ void gdx2d_draw_line(const gdx2d_pixmap* pixmap, int32_t x0, int32_t y0, int32_t
        set_pixel_func pset = set_pixel_func_ptr(pixmap->format);\r
        get_pixel_func pget = get_pixel_func_ptr(pixmap->format);\r
        uint32_t col_format = to_format(pixmap->format, col);\r
-       void* addr = ptr + (x0 + y0) * bpp;\r
+       void* addr = ptr + (x0 + y0 * pixmap->width) * bpp;\r
 \r
     if (dy < 0) { dy = -dy;  stepy = -1; } else { stepy = 1; }\r
     if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }\r
index 4e3a6f1..397ed76 100644 (file)
@@ -115,6 +115,9 @@ public class Pixmap {
         */\r
        public Pixmap(int width, int height, Format format) {\r
                pixmap = new Gdx2DPixmap(width, height, Format.toGdx2DPixmapFormat(format));\r
+               setColor(0, 0, 0, 0);\r
+               fill();\r
+               setColor(1, 1, 1, 1);\r
        }\r
        \r
        /**\r
index 43e18c7..364decb 100644 (file)
@@ -57,7 +57,7 @@ public class Gdx2DPixmap {
                int readBytes = 0;\r
                \r
                while((readBytes = in.read(buffer)) != -1) {\r
-                       bytes.write(buffer);\r
+                       bytes.write(buffer, 0, readBytes);\r
                }\r
                \r
                buffer = bytes.toByteArray();\r