breaking changes: more pythonic api (still allowed because of the very begining state of the project

This commit is contained in:
2021-05-12 13:57:49 +02:00
parent 6fccc1b6cf
commit e57d63f562
4 changed files with 48 additions and 34 deletions

View File

@@ -165,8 +165,12 @@ class FloatImg:
assert c_fimg_clear(self.c_img_p) == 0
#######################################################################################################
def clone(self, flags=0):
def clone(self, copy_data=False):
"""return a clone of the current instance"""
if copy_data:
flags = 1
else:
flags = 0
new_pic = C_FloatImg()
assert c_fimg_clone(self.c_img_p, ct.pointer(new_pic), flags) == 0
return FloatImg(new_pic)
@@ -182,18 +186,18 @@ class FloatImg:
return c_fimg_str_type(self.c_img.type).decode("utf-8")
#######################################################################################################
def rgb_constant(self, r, v, b):
assert c_fimg_rgb_constant(self.c_img_p, r, v, b) == 0
def fill(self, color):
assert c_fimg_rgb_constant(self.c_img_p, *color) == 0
#######################################################################################################
def get_rgb(self, x, y):
def get(self, x, y):
"""get r,g,b triplet from a pixel"""
rgb = (ct.c_float * 3)()
assert c_fimg_get_rgb(self.c_img_p, x, y, ct.pointer(rgb)) == 0
return rgb[:3]
#######################################################################################################
def put_rgb(self, x, y, rgb):
def put(self, x, y, rgb):
"""put r,g,b triplet to a pixel"""
# TODO may be a better way to create the array rather than iterating
c_rgb = (ct.c_float * 3)()
@@ -202,7 +206,7 @@ class FloatImg:
assert c_fimg_put_rgb(self.c_img_p, x, y, ct.pointer(c_rgb)) == 0
#######################################################################################################
def dump_to_file(self, fname):
def dump(self, fname):
"""save data to a dump file"""
# TODO use system encoding instead of utf-8
assert (
@@ -213,7 +217,7 @@ class FloatImg:
)
#######################################################################################################
def load_from_dump(self, fname):
def load(self, fname):
"""load data from a dump. size and type have to be compatible"""
assert (
c_fimg_load_from_dump(
@@ -260,7 +264,7 @@ def create_from_dump(fname):
"""Create a new instance from a dump file"""
witdh, height, img_type = fileinfos(fname)
img = create(witdh, height, img_type)
img.load_from_dump(fname)
img.load(fname)
return img