summaryrefslogtreecommitdiff
path: root/cli.c
diff options
context:
space:
mode:
authorNicolas Schodet2019-11-15 23:52:13 +0100
committerNicolas Schodet2019-11-15 23:52:13 +0100
commit7ce1b8358a8c41d2f00e93cfd614dd445c2d1a5c (patch)
tree85b1f7b760f2ecd4e5a04d040a1edef15702976a /cli.c
parentde86953c464ef457bfd9fefb38f6492035c34698 (diff)
New image API
This allows to remove conversion responsibility from devices so that image treatments can be made on raw data. Now clients must unref images when they are not used, the driver can check this.
Diffstat (limited to 'cli.c')
-rw-r--r--cli.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/cli.c b/cli.c
index 33edcee..b0d3a1b 100644
--- a/cli.c
+++ b/cli.c
@@ -34,23 +34,31 @@ cli_read_images(libusb_context *usb, struct device *device, int count,
{
device_start(device);
for (int i = 0; i < count;) {
- const struct device_image *device_image = device_read(device);
- if (device_image) {
+ struct image *image = device_read(device);
+ if (image) {
+ if (image->format != IMAGE_FORMAT_XBGR32) {
+ struct image *cimage = image_new(image->width, image->height,
+ image->width * 4, IMAGE_FORMAT_XBGR32);
+ image_convert(cimage, image);
+ image_unref(image);
+ image = cimage;
+ }
char *name = NULL;
if (asprintf(&name, out, i) < 0)
utils_fatal("can not prepare file name");
utils_info("write %s", name);
- png_image image;
- memset(&image, 0, sizeof(image));
- image.version = PNG_IMAGE_VERSION;
- image.width = device_image->width;
- image.height = device_image->height;
- image.format = PNG_FORMAT_BGRA;
- int r = png_image_write_to_file(&image, name, 0,
- device_image->pixels, device_image->stride, NULL);
+ png_image pimage;
+ memset(&pimage, 0, sizeof(pimage));
+ pimage.version = PNG_IMAGE_VERSION;
+ pimage.width = image->width;
+ pimage.height = image->height;
+ pimage.format = PNG_FORMAT_BGRA;
+ int r = png_image_write_to_file(&pimage, name, 0,
+ image->pixels, image->stride, NULL);
if (r == 0)
- utils_fatal("can not write image: %s", image.message);
+ utils_fatal("can not write image: %s", pimage.message);
free(name);
+ image_unref(image);
i++;
} else {
libusb_handle_events(usb);