Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Data/Format/PNGLoad.h
5651 views
1
#pragma once
2
3
#include <cstdint>
4
5
#include "Common/BitSet.h"
6
#include "Common/File/Path.h"
7
8
// *image_data_ptr should be deleted with free()
9
// return value of 1 == success.
10
int pngLoad(const char *file, int *pwidth,
11
int *pheight, unsigned char **image_data_ptr);
12
13
int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth,
14
int *pheight, unsigned char **image_data_ptr);
15
16
// PNG peeker - just read the start of a PNG straight into this struct, in order to
17
// look at basic parameters like width and height. Note that while PNG is a chunk-based
18
// format, the IHDR chunk is REQUIRED to be the first one, so this will work.
19
// Does not handle Apple's weirdo extension CgBI. http://iphonedevwiki.net/index.php/CgBI_file_format
20
// That should not be an issue.
21
struct PNGHeaderPeek {
22
uint32_t magic;
23
uint32_t ignore0;
24
uint32_t ignore1;
25
uint32_t ihdrTag;
26
uint32_t be_width; // big endian
27
uint32_t be_height;
28
uint8_t bitDepth; // bits per channel, can be 1, 2, 4, 8, 16
29
uint8_t colorType; // really, pixel format. 0 = grayscale, 2 = rgb, 3 = palette index, 4 = gray+alpha, 6 = rgba
30
31
bool IsValidPNGHeader() const;
32
int Width() const { return swap32(be_width); }
33
int Height() const { return swap32(be_height); }
34
};
35
36
bool pngSave(const Path &filename, const void *buffer, int w, int h, int bytesPerPixel);
37
38