Skip to content

Commit 4c98f2e

Browse files
committed
test and fix image
1 parent c7ba8de commit 4c98f2e

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

tcod/_image.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,24 @@ def image_load(filename):
3737
_lib.TCOD_image_delete)
3838

3939
def image_from_console(console):
40-
return _ffi.gc(_lib.TCOD_image_from_console(console),
40+
return _ffi.gc(_lib.TCOD_image_from_console(console or _ffi.NULL),
4141
_lib.TCOD_image_delete)
4242

4343
def image_refresh_console(image, console):
44-
_lib.TCOD_image_refresh_console(image, console)
44+
_lib.TCOD_image_refresh_console(image, console or _ffi.NULL)
4545

4646
def image_get_size(image):
4747
w = _ffi.new('int *')
4848
h = _ffi.new('int *')
4949
_lib.TCOD_image_get_size(image, w, h)
50-
return w.value, h.value
50+
return w[0], h[0]
5151

5252
def image_get_pixel(image, x, y):
5353
return _lib.TCOD_image_get_pixel(image, x, y)
5454

5555
def image_get_mipmap_pixel(image, x0, y0, x1, y1):
5656
return _lib.TCOD_image_get_mipmap_pixel(image, x0, y0, x1, y1)
57+
5758
def image_put_pixel(image, x, y, col):
5859
_lib.TCOD_image_put_pixel(image, x, y, col)
5960
##_lib.TCOD_image_put_pixel_wrapper(image, x, y, col)

tests/test_libtcodpy.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,34 @@ def test_sys_clipboard(self):
237237
tcod.sys_clipboard_set('')
238238
tcod.sys_clipboard_get()
239239

240+
def test_image(self):
241+
img = tcod.image_new(16, 16)
242+
tcod.image_clear(img, (0, 0, 0))
243+
tcod.image_invert(img)
244+
tcod.image_hflip(img)
245+
tcod.image_rotate90(img)
246+
tcod.image_vflip(img)
247+
tcod.image_scale(img, 24, 24)
248+
tcod.image_set_key_color(img, (255, 255, 255))
249+
tcod.image_get_alpha(img, 0, 0)
250+
tcod.image_is_pixel_transparent(img, 0, 0)
251+
tcod.image_get_size(img)
252+
tcod.image_get_pixel(img, 0, 0)
253+
tcod.image_get_mipmap_pixel(img, 0, 0, 1, 1)
254+
tcod.image_put_pixel(img, 0, 0, (255, 255, 255))
255+
tcod.image_blit(img, self.console, 0, 0, tcod.BKGND_SET, 1, 1, 0)
256+
tcod.image_blit_rect(img, self.console, 0, 0, 16, 16, tcod.BKGND_SET)
257+
tcod.image_blit_2x(img, self.console, 0, 0)
258+
tcod.image_save(img, tempfile.mktemp(dir=self.temp_dir))
259+
tcod.image_delete(img)
260+
261+
img = tcod.image_from_console(self.console)
262+
tcod.image_refresh_console(img, self.console)
263+
tcod.image_delete(img)
264+
265+
tcod.image_delete(tcod.image_load('libtcod/data/img/circle.png'))
266+
267+
240268
class TestLibtcodpy(unittest.TestCase):
241269
# arguments to test with and the results expected from these arguments
242270
LINE_ARGS = (-5, 0, 5, 10)

0 commit comments

Comments
 (0)