-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppm-reader.h
36 lines (32 loc) · 1.3 KB
/
ppm-reader.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
// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// (c) 2015 Henner Zeller <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://gnu.org/licenses/gpl-2.0.txt>
#include <stdlib.h>
#include <stdint.h>
struct rgb_t {
uint8_t r, g, b;
} __attribute__((packed));
struct ImageMetaInfo {
int width;
int height;
int range; // Range of gray-levels. We only handle 255 correctly(=1byte)
};
// Given an input buffer + size with a raw PPM file, extract the image
// meta information and return it in "info_out".
// Return pointer to raw image data with uint8 [r,g,b] tuples (memory is
// still owned by "in_buffer".
// Returns nullptr if reading failed.
const rgb_t *ReadImageData(const char *in_buffer, size_t buf_len,
struct ImageMetaInfo *info_out);