mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-08 11:10:16 +00:00
some fix
This commit is contained in:
parent
d11c377f4c
commit
871bc77bd3
@ -152,7 +152,7 @@ static bool cute_png_Image__clear(int argc, py_Ref argv) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cute_png_Image__to_rgb565(int argc, py_Ref argv) {
|
static bool cute_png_Image__to_rgb565_bytes(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
cp_image_t* image = py_touserdata(argv);
|
cp_image_t* image = py_touserdata(argv);
|
||||||
unsigned char* data = py_newbytes(py_retval(), image->w * image->h * 2);
|
unsigned char* data = py_newbytes(py_retval(), image->w * image->h * 2);
|
||||||
@ -171,6 +171,17 @@ static bool cute_png_Image__to_rgb565(int argc, py_Ref argv) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool cute_png_Image__to_png_bytes(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(1);
|
||||||
|
cp_image_t* image = py_touserdata(argv);
|
||||||
|
cp_saved_png_t saved_image = cp_save_png_to_memory(image);
|
||||||
|
assert(saved_image.data != NULL);
|
||||||
|
unsigned char* data = py_newbytes(py_retval(), saved_image.size);
|
||||||
|
memcpy(data, saved_image.data, saved_image.size);
|
||||||
|
CUTE_PNG_FREE(saved_image.data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void pk__add_module_cute_png() {
|
void pk__add_module_cute_png() {
|
||||||
py_GlobalRef mod = py_newmodule("cute_png");
|
py_GlobalRef mod = py_newmodule("cute_png");
|
||||||
py_Type tp_image = py_newtype("Image", tp_object, mod, cute_png_Image__dtor);
|
py_Type tp_image = py_newtype("Image", tp_object, mod, cute_png_Image__dtor);
|
||||||
@ -188,5 +199,6 @@ void pk__add_module_cute_png() {
|
|||||||
py_bindmethod(tp_image, "getpixel", cute_png_Image__getpixel);
|
py_bindmethod(tp_image, "getpixel", cute_png_Image__getpixel);
|
||||||
py_bindmethod(tp_image, "clear", cute_png_Image__clear);
|
py_bindmethod(tp_image, "clear", cute_png_Image__clear);
|
||||||
|
|
||||||
py_bindmethod(tp_image, "to_rgb565", cute_png_Image__to_rgb565);
|
py_bindmethod(tp_image, "to_rgb565_bytes", cute_png_Image__to_rgb565_bytes);
|
||||||
|
py_bindmethod(tp_image, "to_png_bytes", cute_png_Image__to_png_bytes);
|
||||||
}
|
}
|
||||||
@ -16,7 +16,8 @@ class Image:
|
|||||||
def getpixel(self, x: int, y: int) -> color32: ...
|
def getpixel(self, x: int, y: int) -> color32: ...
|
||||||
def clear(self, color: color32) -> None: ...
|
def clear(self, color: color32) -> None: ...
|
||||||
|
|
||||||
def to_rgb565(self) -> bytes: ...
|
def to_rgb565_bytes(self) -> bytes: ...
|
||||||
|
def to_png_bytes(self) -> bytes: ...
|
||||||
|
|
||||||
def loads(data: bytes) -> array2d[color32]: ...
|
def loads(data: bytes) -> array2d[color32]: ...
|
||||||
def dumps(image: array2d[color32]) -> bytes: ...
|
def dumps(image: array2d[color32]) -> bytes: ...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user