Re: [dev] Looking for simple, alpha supporting image format

From: Alex Anderson <alexanderandersonofandover_AT_gmail.com>
Date: Tue, 15 Jul 2014 17:35:59 +0100

Looks nice.

A couple of questions:

* why have fixed-size width and height fields if they're between
"blank" bytes? Is for simpler read code?
* is "blank" ASCII-blank, or '0x00'? (From the write-code, it looks like ASCII)

On 15 July 2014 17:28, FRIGN <dev_AT_frign.de> wrote:
> On Mon, 14 Jul 2014 14:54:42 -0400
> Charlie Murphy <cmsmurp00_AT_gmail.com> wrote:
>
>> [1]: http://pastebin.com/vZEcxte3
>
> As this expires, here's the full text:
>
> ###
>
> This is an easy-to-parse image format that works well in pipelines.
> Inspired by Netpbm and the Plan 9 image format.
>
> Bytes Description
> 9 ASCII string: "imagefile"
> 1 Blank
> 9 Right-justified, blank-padded ASCII string containing width.
> 1 Blank
> 9 Right-justified, blank-padded ASCII string containing height.
> 1 Blank
>
> Then, (width*height) pixels in the form of RGBA, where each channel
> is one byte.
>
> This function reads an image:
>
> int
> readimage(int fd, int *wp, int *hp, char **datap)
> {
> char buf[30];
> int w, h, total;
> char *data;
>
> if (read(fd, buf, 30) != 30)
> return -1;
>
> buf[9] = '\0';
> buf[19] = '\0';
> buf[29] = '\0';
>
> if (strcmp(buf, "imagefile") != 0)
> return -1;
>
> w = atoi(buf+10);
> h = atoi(buf+20);
> total = w*h*4;
>
> data = malloc(total);
> if (!data)
> return -1;
>
> if (read(fd, data, total) != total) {
> free(data);
> return -1;
> }
>
> *wp = w;
> *hp = h;
> *datap = datap;
>
> return 0;
> }
>
> This function writes an image:
>
> int
> writeimage(int fd, int w, int h, char *data)
> {
> if (dprintf(fd, "imagefile %9d %9d ", w, h) < 0)
> return -1;
> if (write(fd, data, w*h*4) != w*h*4)
> return -1;
> return 0;
> }
>
> -Anonymous
>
> ###
>
> --
> FRIGN <dev_AT_frign.de>
>
Received on Tue Jul 15 2014 - 18:35:59 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 15 2014 - 18:48:07 CEST