MCPcopy Create free account
hub / github.com/OSSystems/EasySplash / load_png

Function load_png

src/load_png.cpp:78–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78image load_png(datablock const &p_png_data)
79{
80 if (p_png_data.empty())
81 {
82 LOG_MSG(error, "no input PNG data");
83 return image();
84 }
85
86 if (!png_check_sig((png_bytep)(&(p_png_data[0])), png_signature_length))
87 {
88 LOG_MSG(error, "invalid PNG signature");
89 return image();
90 }
91
92 png_structp png_ptr = NULL;
93 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
94
95 if(png_ptr == NULL)
96 {
97 LOG_MSG(error, "could not initialize png struct");
98 return image();
99 }
100
101 png_infop info_ptr = NULL;
102 info_ptr = png_create_info_struct(png_ptr);
103
104 if(info_ptr == NULL)
105 {
106 LOG_MSG(error, "could not initialize info struct");
107 png_destroy_read_struct(&png_ptr, NULL, NULL);
108 return image();
109 }
110
111 data_read_state read_state(p_png_data, png_signature_length);
112
113 png_set_error_fn(png_ptr, NULL, png_error_msg_proc, png_warning_msg_proc);
114 png_set_read_fn(png_ptr, &read_state, png_read_proc);
115
116 // Inform libpng that we already checked for the signature
117 png_set_sig_bytes(png_ptr, png_signature_length);
118
119 png_read_info(png_ptr, info_ptr);
120
121 png_uint_32 width = 0;
122 png_uint_32 height = 0;
123 int bit_depth = 0;
124 int color_type = -1;
125 png_uint_32 retval = png_get_IHDR(
126 png_ptr, info_ptr,
127 &width,
128 &height,
129 &bit_depth,
130 &color_type,
131 NULL, NULL, NULL
132 );
133
134 if (retval != 1)
135 {

Callers 1

get_image_handle_atMethod · 0.85

Calls 1

imageClass · 0.85

Tested by

no test coverage detected