blob: 8489d60ef5715e0d9fefce20ec537e0f83c97b74 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdlib.h>
Elliott Hughescd3c55a2015-01-29 20:50:08 -080018#include <string.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080019#include <unistd.h>
20
21#include <fcntl.h>
22#include <stdio.h>
23
24#include <sys/ioctl.h>
25#include <sys/mman.h>
26#include <sys/types.h>
27
28#include <linux/fb.h>
29#include <linux/kd.h>
30
Yabin Cui4425c1d2016-02-10 13:47:32 -080031#include <vector>
Doug Zongker19faefa2009-03-27 17:06:24 -070032#include <png.h>
33
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080034#include "minui.h"
35
Doug Zongker02ec6b82012-08-22 17:26:40 -070036extern char* locale;
37
Doug Zongker16f97c32014-03-06 16:16:05 -080038#define SURFACE_DATA_ALIGNMENT 8
39
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070040static GRSurface* malloc_surface(size_t data_size) {
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070041 size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
42 unsigned char* temp = reinterpret_cast<unsigned char*>(malloc(size));
Doug Zongker16f97c32014-03-06 16:16:05 -080043 if (temp == NULL) return NULL;
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070044 GRSurface* surface = reinterpret_cast<GRSurface*>(temp);
Doug Zongker16f97c32014-03-06 16:16:05 -080045 surface->data = temp + sizeof(GRSurface) +
46 (SURFACE_DATA_ALIGNMENT - (sizeof(GRSurface) % SURFACE_DATA_ALIGNMENT));
47 return surface;
Doug Zongker19faefa2009-03-27 17:06:24 -070048}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080049
Doug Zongkera418aa72014-03-17 12:10:02 -070050static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
51 png_uint_32* width, png_uint_32* height, png_byte* channels) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052 char resPath[256];
Doug Zongker19faefa2009-03-27 17:06:24 -070053 unsigned char header[8];
Doug Zongkera418aa72014-03-17 12:10:02 -070054 int result = 0;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070055 int color_type, bit_depth;
56 size_t bytesRead;
Doug Zongker6809c512011-03-01 14:04:34 -080057
Doug Zongker19faefa2009-03-27 17:06:24 -070058 snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080059 resPath[sizeof(resPath)-1] = '\0';
Doug Zongker19faefa2009-03-27 17:06:24 -070060 FILE* fp = fopen(resPath, "rb");
61 if (fp == NULL) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080062 result = -1;
63 goto exit;
64 }
Doug Zongker19faefa2009-03-27 17:06:24 -070065
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070066 bytesRead = fread(header, 1, sizeof(header), fp);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080067 if (bytesRead != sizeof(header)) {
68 result = -2;
69 goto exit;
70 }
Doug Zongker19faefa2009-03-27 17:06:24 -070071
72 if (png_sig_cmp(header, 0, sizeof(header))) {
73 result = -3;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080074 goto exit;
75 }
Doug Zongker19faefa2009-03-27 17:06:24 -070076
Doug Zongkera418aa72014-03-17 12:10:02 -070077 *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
78 if (!*png_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080079 result = -4;
80 goto exit;
81 }
Doug Zongker19faefa2009-03-27 17:06:24 -070082
Doug Zongkera418aa72014-03-17 12:10:02 -070083 *info_ptr = png_create_info_struct(*png_ptr);
84 if (!*info_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080085 result = -5;
86 goto exit;
87 }
Doug Zongker19faefa2009-03-27 17:06:24 -070088
Doug Zongkera418aa72014-03-17 12:10:02 -070089 if (setjmp(png_jmpbuf(*png_ptr))) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080090 result = -6;
91 goto exit;
92 }
Doug Zongker19faefa2009-03-27 17:06:24 -070093
Doug Zongkera418aa72014-03-17 12:10:02 -070094 png_init_io(*png_ptr, fp);
95 png_set_sig_bytes(*png_ptr, sizeof(header));
96 png_read_info(*png_ptr, *info_ptr);
Doug Zongker19faefa2009-03-27 17:06:24 -070097
Doug Zongkera418aa72014-03-17 12:10:02 -070098 png_get_IHDR(*png_ptr, *info_ptr, width, height, &bit_depth,
John Reck94fd07b2013-08-26 16:45:33 -070099 &color_type, NULL, NULL, NULL);
100
Doug Zongkera418aa72014-03-17 12:10:02 -0700101 *channels = png_get_channels(*png_ptr, *info_ptr);
John Reck94fd07b2013-08-26 16:45:33 -0700102
Doug Zongkera418aa72014-03-17 12:10:02 -0700103 if (bit_depth == 8 && *channels == 3 && color_type == PNG_COLOR_TYPE_RGB) {
104 // 8-bit RGB images: great, nothing to do.
105 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_GRAY) {
106 // 1-, 2-, 4-, or 8-bit gray images: expand to 8-bit gray.
107 png_set_expand_gray_1_2_4_to_8(*png_ptr);
Doug Zongker577a1302014-03-20 08:27:01 -0700108 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_PALETTE) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700109 // paletted images: expand to 8-bit RGB. Note that we DON'T
110 // currently expand the tRNS chunk (if any) to an alpha
111 // channel, because minui doesn't support alpha channels in
112 // general.
113 png_set_palette_to_rgb(*png_ptr);
114 *channels = 3;
115 } else {
116 fprintf(stderr, "minui doesn't support PNG depth %d channels %d color_type %d\n",
Doug Zongkera388a762014-03-17 16:51:47 -0700117 bit_depth, *channels, color_type);
Doug Zongkera418aa72014-03-17 12:10:02 -0700118 result = -7;
Doug Zongker19faefa2009-03-27 17:06:24 -0700119 goto exit;
120 }
121
Doug Zongkera418aa72014-03-17 12:10:02 -0700122 return result;
Doug Zongker55a36ac2013-03-04 15:49:02 -0800123
Doug Zongkera418aa72014-03-17 12:10:02 -0700124 exit:
125 if (result < 0) {
126 png_destroy_read_struct(png_ptr, info_ptr, NULL);
127 }
128 if (fp != NULL) {
129 fclose(fp);
130 }
131
132 return result;
133}
134
135// "display" surfaces are transformed into the framebuffer's required
136// pixel format (currently only RGBX is supported) at load time, so
137// gr_blit() can be nothing more than a memcpy() for each row. The
138// next two functions are the only ones that know anything about the
139// framebuffer pixel format; they need to be modified if the
140// framebuffer format changes (but nothing else should).
141
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700142// Allocate and return a GRSurface* sufficient for storing an image of
Doug Zongkera418aa72014-03-17 12:10:02 -0700143// the indicated size in the framebuffer pixel format.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700144static GRSurface* init_display_surface(png_uint_32 width, png_uint_32 height) {
145 GRSurface* surface = malloc_surface(width * height * 4);
Doug Zongkera418aa72014-03-17 12:10:02 -0700146 if (surface == NULL) return NULL;
147
148 surface->width = width;
149 surface->height = height;
150 surface->row_bytes = width * 4;
151 surface->pixel_bytes = 4;
152
153 return surface;
154}
155
156// Copy 'input_row' to 'output_row', transforming it to the
157// framebuffer pixel format. The input format depends on the value of
158// 'channels':
159//
160// 1 - input is 8-bit grayscale
161// 3 - input is 24-bit RGB
162// 4 - input is 32-bit RGBA/RGBX
163//
164// 'width' is the number of pixels in the row.
165static void transform_rgb_to_draw(unsigned char* input_row,
166 unsigned char* output_row,
167 int channels, int width) {
168 int x;
169 unsigned char* ip = input_row;
170 unsigned char* op = output_row;
171
172 switch (channels) {
173 case 1:
174 // expand gray level to RGBX
175 for (x = 0; x < width; ++x) {
176 *op++ = *ip;
177 *op++ = *ip;
178 *op++ = *ip;
179 *op++ = 0xff;
180 ip++;
181 }
182 break;
183
184 case 3:
185 // expand RGBA to RGBX
186 for (x = 0; x < width; ++x) {
187 *op++ = *ip++;
188 *op++ = *ip++;
189 *op++ = *ip++;
190 *op++ = 0xff;
191 }
192 break;
193
194 case 4:
195 // copy RGBA to RGBX
196 memcpy(output_row, input_row, width*4);
197 break;
198 }
199}
200
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700201int res_create_display_surface(const char* name, GRSurface** pSurface) {
202 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700203 int result = 0;
204 png_structp png_ptr = NULL;
205 png_infop info_ptr = NULL;
206 png_uint_32 width, height;
207 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700208 unsigned char* p_row;
209 unsigned int y;
Doug Zongkera418aa72014-03-17 12:10:02 -0700210
211 *pSurface = NULL;
212
213 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
214 if (result < 0) return result;
215
216 surface = init_display_surface(width, height);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800217 if (surface == NULL) {
Doug Zongker19faefa2009-03-27 17:06:24 -0700218 result = -8;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800219 goto exit;
220 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800221
Tony Kuofd778e32015-02-05 21:25:56 +0800222#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
223 png_set_bgr(png_ptr);
224#endif
225
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700226 p_row = reinterpret_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700227 for (y = 0; y < height; ++y) {
228 png_read_row(png_ptr, p_row, NULL);
229 transform_rgb_to_draw(p_row, surface->data + y * surface->row_bytes, channels, width);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800230 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700231 free(p_row);
Doug Zongker19faefa2009-03-27 17:06:24 -0700232
Doug Zongkera418aa72014-03-17 12:10:02 -0700233 *pSurface = surface;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800234
Doug Zongkera418aa72014-03-17 12:10:02 -0700235 exit:
Doug Zongker19faefa2009-03-27 17:06:24 -0700236 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700237 if (result < 0 && surface != NULL) free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800238 return result;
239}
240
Tao Baob723f4f2015-12-11 15:18:51 -0800241int res_create_multi_display_surface(const char* name, int* frames, int* fps,
242 GRSurface*** pSurface) {
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700243 GRSurface** surface = NULL;
Doug Zongker469954f2014-03-07 09:21:25 -0800244 int result = 0;
Doug Zongker469954f2014-03-07 09:21:25 -0800245 png_structp png_ptr = NULL;
246 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700247 png_uint_32 width, height;
248 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700249 png_textp text;
250 int num_text;
251 unsigned char* p_row;
252 unsigned int y;
Doug Zongker469954f2014-03-07 09:21:25 -0800253
254 *pSurface = NULL;
255 *frames = -1;
256
Doug Zongkera418aa72014-03-17 12:10:02 -0700257 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
258 if (result < 0) return result;
Doug Zongker469954f2014-03-07 09:21:25 -0800259
260 *frames = 1;
Tao Baob723f4f2015-12-11 15:18:51 -0800261 *fps = 20;
Doug Zongker469954f2014-03-07 09:21:25 -0800262 if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
Tao Baob723f4f2015-12-11 15:18:51 -0800263 for (int i = 0; i < num_text; ++i) {
Doug Zongker469954f2014-03-07 09:21:25 -0800264 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
265 *frames = atoi(text[i].text);
Tao Baob723f4f2015-12-11 15:18:51 -0800266 } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
267 *fps = atoi(text[i].text);
Doug Zongker469954f2014-03-07 09:21:25 -0800268 }
269 }
270 printf(" found frames = %d\n", *frames);
Tao Baob723f4f2015-12-11 15:18:51 -0800271 printf(" found fps = %d\n", *fps);
272 }
273
274 if (frames <= 0 || fps <= 0) {
275 printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
276 result = -10;
277 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800278 }
279
280 if (height % *frames != 0) {
281 printf("bad height (%d) for frame count (%d)\n", height, *frames);
282 result = -9;
283 goto exit;
284 }
285
Elliott Hughes7d626df2016-02-19 10:33:01 -0800286 surface = reinterpret_cast<GRSurface**>(calloc(*frames, sizeof(GRSurface*)));
Doug Zongker469954f2014-03-07 09:21:25 -0800287 if (surface == NULL) {
288 result = -8;
289 goto exit;
290 }
Tao Baob723f4f2015-12-11 15:18:51 -0800291 for (int i = 0; i < *frames; ++i) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700292 surface[i] = init_display_surface(width, height / *frames);
293 if (surface[i] == NULL) {
294 result = -8;
295 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800296 }
297 }
298
Tony Kuofd778e32015-02-05 21:25:56 +0800299#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
300 png_set_bgr(png_ptr);
301#endif
302
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700303 p_row = reinterpret_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700304 for (y = 0; y < height; ++y) {
305 png_read_row(png_ptr, p_row, NULL);
306 int frame = y % *frames;
307 unsigned char* out_row = surface[frame]->data +
308 (y / *frames) * surface[frame]->row_bytes;
309 transform_rgb_to_draw(p_row, out_row, channels, width);
310 }
311 free(p_row);
312
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700313 *pSurface = reinterpret_cast<GRSurface**>(surface);
Doug Zongker469954f2014-03-07 09:21:25 -0800314
315exit:
316 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
317
Doug Zongker469954f2014-03-07 09:21:25 -0800318 if (result < 0) {
319 if (surface) {
Tao Baob723f4f2015-12-11 15:18:51 -0800320 for (int i = 0; i < *frames; ++i) {
Elliott Hughes7d626df2016-02-19 10:33:01 -0800321 free(surface[i]);
Doug Zongker469954f2014-03-07 09:21:25 -0800322 }
323 free(surface);
324 }
325 }
326 return result;
327}
328
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700329int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
330 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700331 int result = 0;
332 png_structp png_ptr = NULL;
333 png_infop info_ptr = NULL;
334 png_uint_32 width, height;
335 png_byte channels;
336
337 *pSurface = NULL;
338
339 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
340 if (result < 0) return result;
341
342 if (channels != 1) {
343 result = -7;
344 goto exit;
345 }
346
347 surface = malloc_surface(width * height);
348 if (surface == NULL) {
349 result = -8;
350 goto exit;
351 }
352 surface->width = width;
353 surface->height = height;
354 surface->row_bytes = width;
355 surface->pixel_bytes = 1;
356
Tony Kuofd778e32015-02-05 21:25:56 +0800357#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
358 png_set_bgr(png_ptr);
359#endif
360
Doug Zongkera418aa72014-03-17 12:10:02 -0700361 unsigned char* p_row;
362 unsigned int y;
363 for (y = 0; y < height; ++y) {
364 p_row = surface->data + y * surface->row_bytes;
365 png_read_row(png_ptr, p_row, NULL);
366 }
367
368 *pSurface = surface;
369
370 exit:
371 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
372 if (result < 0 && surface != NULL) free(surface);
373 return result;
374}
375
376static int matches_locale(const char* loc, const char* locale) {
Doug Zongker02ec6b82012-08-22 17:26:40 -0700377 if (locale == NULL) return 0;
378
Doug Zongker02ec6b82012-08-22 17:26:40 -0700379 if (strcmp(loc, locale) == 0) return 1;
380
381 // if loc does *not* have an underscore, and it matches the start
382 // of locale, and the next character in locale *is* an underscore,
383 // that's a match. For instance, loc == "en" matches locale ==
384 // "en_US".
385
386 int i;
387 for (i = 0; loc[i] != 0 && loc[i] != '_'; ++i);
388 if (loc[i] == '_') return 0;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700389
390 return (strncmp(locale, loc, i) == 0 && locale[i] == '_');
391}
392
Doug Zongkera418aa72014-03-17 12:10:02 -0700393int res_create_localized_alpha_surface(const char* name,
394 const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700395 GRSurface** pSurface) {
396 GRSurface* surface = NULL;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700397 int result = 0;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700398 png_structp png_ptr = NULL;
399 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700400 png_uint_32 width, height;
401 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700402 png_uint_32 y;
Yabin Cui4425c1d2016-02-10 13:47:32 -0800403 std::vector<unsigned char> row;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700404
405 *pSurface = NULL;
406
Doug Zongkera418aa72014-03-17 12:10:02 -0700407 if (locale == NULL) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800408 return result;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700409 }
410
Doug Zongkera418aa72014-03-17 12:10:02 -0700411 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
412 if (result < 0) return result;
413
414 if (channels != 1) {
415 result = -7;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700416 goto exit;
417 }
418
Yabin Cui4425c1d2016-02-10 13:47:32 -0800419 row.resize(width);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700420 for (y = 0; y < height; ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800421 png_read_row(png_ptr, row.data(), NULL);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700422 int w = (row[1] << 8) | row[0];
423 int h = (row[3] << 8) | row[2];
Elliott Hughes7d626df2016-02-19 10:33:01 -0800424 __unused int len = row[4];
Yabin Cui4425c1d2016-02-10 13:47:32 -0800425 char* loc = reinterpret_cast<char*>(&row[5]);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700426
Doug Zongkera418aa72014-03-17 12:10:02 -0700427 if (y+1+h >= height || matches_locale(loc, locale)) {
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700428 printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
429
Doug Zongker16f97c32014-03-06 16:16:05 -0800430 surface = malloc_surface(w*h);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700431 if (surface == NULL) {
432 result = -8;
433 goto exit;
434 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700435 surface->width = w;
436 surface->height = h;
Doug Zongker16f97c32014-03-06 16:16:05 -0800437 surface->row_bytes = w;
438 surface->pixel_bytes = 1;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700439
440 int i;
441 for (i = 0; i < h; ++i, ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800442 png_read_row(png_ptr, row.data(), NULL);
443 memcpy(surface->data + i*w, row.data(), w);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700444 }
445
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700446 *pSurface = reinterpret_cast<GRSurface*>(surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700447 break;
448 } else {
Doug Zongker02ec6b82012-08-22 17:26:40 -0700449 int i;
450 for (i = 0; i < h; ++i, ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800451 png_read_row(png_ptr, row.data(), NULL);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700452 }
453 }
454 }
455
456exit:
457 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700458 if (result < 0 && surface != NULL) free(surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700459 return result;
460}
461
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700462void res_free_surface(GRSurface* surface) {
Doug Zongker16f97c32014-03-06 16:16:05 -0800463 free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800464}