-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbm_decoder.h
47 lines (41 loc) · 1.14 KB
/
pbm_decoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <stddef.h>
#include <stdint.h>
struct PbmPalette {
uint8_t low_r;
uint8_t low_g;
uint8_t low_b;
uint8_t high_r;
uint8_t high_g;
uint8_t high_b;
};
struct PbmImage {
unsigned int width;
unsigned int height;
void* raster_pos;
unsigned int current_row_pixel;
struct PbmPalette* palette;
};
struct Pixel {
uint8_t r;
uint8_t g;
uint8_t b;
};
/*
* Decodes a raw Portable Bit Map image, as defined by Netpbm, filling
* the provided pbm_struct with appropriate values. It is assumed that
* the palette is initialized by the caller. If the image couldn't be
* decoded, pbm_struct is unchanged.
*
* This decoder doesn't support comments embedded in the PBM.
* This simplifies the decoder and forces users to delete useless
* comments from the PBM, reducing payload size further.
*/
void decode_pbm(void* pbm_data, size_t size, struct PbmImage* pbm_struct);
/*
* Returns the next pixel of a previously decoded PBM image and
* advances pointers.
* If there are no more pixels, the behavior of this function is
* undefined.
*/
struct Pixel* next_pixel(struct PbmImage* pbm_image);