blob: 9ccbf4b1be5e8678536fdff977389a8137d42ace [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 Zongker16f97c32014-03-06 16:16:05 -080036#define SURFACE_DATA_ALIGNMENT 8
37
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070038static GRSurface* malloc_surface(size_t data_size) {
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070039 size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -080040 unsigned char* temp = static_cast<unsigned char*>(malloc(size));
Doug Zongker16f97c32014-03-06 16:16:05 -080041 if (temp == NULL) return NULL;
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070042 GRSurface* surface = reinterpret_cast<GRSurface*>(temp);
Doug Zongker16f97c32014-03-06 16:16:05 -080043 surface->data = temp + sizeof(GRSurface) +
44 (SURFACE_DATA_ALIGNMENT - (sizeof(GRSurface) % SURFACE_DATA_ALIGNMENT));
45 return surface;
Doug Zongker19faefa2009-03-27 17:06:24 -070046}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080047
Doug Zongkera418aa72014-03-17 12:10:02 -070048static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
49 png_uint_32* width, png_uint_32* height, png_byte* channels) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080050 char resPath[256];
Doug Zongker19faefa2009-03-27 17:06:24 -070051 unsigned char header[8];
Doug Zongkera418aa72014-03-17 12:10:02 -070052 int result = 0;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070053 int color_type, bit_depth;
54 size_t bytesRead;
Doug Zongker6809c512011-03-01 14:04:34 -080055
Doug Zongker19faefa2009-03-27 17:06:24 -070056 snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080057 resPath[sizeof(resPath)-1] = '\0';
Doug Zongker19faefa2009-03-27 17:06:24 -070058 FILE* fp = fopen(resPath, "rb");
59 if (fp == NULL) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080060 result = -1;
61 goto exit;
62 }
Doug Zongker19faefa2009-03-27 17:06:24 -070063
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070064 bytesRead = fread(header, 1, sizeof(header), fp);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080065 if (bytesRead != sizeof(header)) {
66 result = -2;
67 goto exit;
68 }
Doug Zongker19faefa2009-03-27 17:06:24 -070069
70 if (png_sig_cmp(header, 0, sizeof(header))) {
71 result = -3;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080072 goto exit;
73 }
Doug Zongker19faefa2009-03-27 17:06:24 -070074
Doug Zongkera418aa72014-03-17 12:10:02 -070075 *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
76 if (!*png_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080077 result = -4;
78 goto exit;
79 }
Doug Zongker19faefa2009-03-27 17:06:24 -070080
Doug Zongkera418aa72014-03-17 12:10:02 -070081 *info_ptr = png_create_info_struct(*png_ptr);
82 if (!*info_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080083 result = -5;
84 goto exit;
85 }
Doug Zongker19faefa2009-03-27 17:06:24 -070086
Doug Zongkera418aa72014-03-17 12:10:02 -070087 if (setjmp(png_jmpbuf(*png_ptr))) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080088 result = -6;
89 goto exit;
90 }
Doug Zongker19faefa2009-03-27 17:06:24 -070091
Doug Zongkera418aa72014-03-17 12:10:02 -070092 png_init_io(*png_ptr, fp);
93 png_set_sig_bytes(*png_ptr, sizeof(header));
94 png_read_info(*png_ptr, *info_ptr);
Doug Zongker19faefa2009-03-27 17:06:24 -070095
Doug Zongkera418aa72014-03-17 12:10:02 -070096 png_get_IHDR(*png_ptr, *info_ptr, width, height, &bit_depth,
John Reck94fd07b2013-08-26 16:45:33 -070097 &color_type, NULL, NULL, NULL);
98
Doug Zongkera418aa72014-03-17 12:10:02 -070099 *channels = png_get_channels(*png_ptr, *info_ptr);
John Reck94fd07b2013-08-26 16:45:33 -0700100
Doug Zongkera418aa72014-03-17 12:10:02 -0700101 if (bit_depth == 8 && *channels == 3 && color_type == PNG_COLOR_TYPE_RGB) {
102 // 8-bit RGB images: great, nothing to do.
103 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_GRAY) {
104 // 1-, 2-, 4-, or 8-bit gray images: expand to 8-bit gray.
105 png_set_expand_gray_1_2_4_to_8(*png_ptr);
Doug Zongker577a1302014-03-20 08:27:01 -0700106 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_PALETTE) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700107 // paletted images: expand to 8-bit RGB. Note that we DON'T
108 // currently expand the tRNS chunk (if any) to an alpha
109 // channel, because minui doesn't support alpha channels in
110 // general.
111 png_set_palette_to_rgb(*png_ptr);
112 *channels = 3;
113 } else {
114 fprintf(stderr, "minui doesn't support PNG depth %d channels %d color_type %d\n",
Doug Zongkera388a762014-03-17 16:51:47 -0700115 bit_depth, *channels, color_type);
Doug Zongkera418aa72014-03-17 12:10:02 -0700116 result = -7;
Doug Zongker19faefa2009-03-27 17:06:24 -0700117 goto exit;
118 }
119
Doug Zongkera418aa72014-03-17 12:10:02 -0700120 return result;
Doug Zongker55a36ac2013-03-04 15:49:02 -0800121
Doug Zongkera418aa72014-03-17 12:10:02 -0700122 exit:
123 if (result < 0) {
124 png_destroy_read_struct(png_ptr, info_ptr, NULL);
125 }
126 if (fp != NULL) {
127 fclose(fp);
128 }
129
130 return result;
131}
132
133// "display" surfaces are transformed into the framebuffer's required
134// pixel format (currently only RGBX is supported) at load time, so
135// gr_blit() can be nothing more than a memcpy() for each row. The
136// next two functions are the only ones that know anything about the
137// framebuffer pixel format; they need to be modified if the
138// framebuffer format changes (but nothing else should).
139
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700140// Allocate and return a GRSurface* sufficient for storing an image of
Doug Zongkera418aa72014-03-17 12:10:02 -0700141// the indicated size in the framebuffer pixel format.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700142static GRSurface* init_display_surface(png_uint_32 width, png_uint_32 height) {
143 GRSurface* surface = malloc_surface(width * height * 4);
Doug Zongkera418aa72014-03-17 12:10:02 -0700144 if (surface == NULL) return NULL;
145
146 surface->width = width;
147 surface->height = height;
148 surface->row_bytes = width * 4;
149 surface->pixel_bytes = 4;
150
151 return surface;
152}
153
154// Copy 'input_row' to 'output_row', transforming it to the
155// framebuffer pixel format. The input format depends on the value of
156// 'channels':
157//
158// 1 - input is 8-bit grayscale
159// 3 - input is 24-bit RGB
160// 4 - input is 32-bit RGBA/RGBX
161//
162// 'width' is the number of pixels in the row.
163static void transform_rgb_to_draw(unsigned char* input_row,
164 unsigned char* output_row,
165 int channels, int width) {
166 int x;
167 unsigned char* ip = input_row;
168 unsigned char* op = output_row;
169
170 switch (channels) {
171 case 1:
172 // expand gray level to RGBX
173 for (x = 0; x < width; ++x) {
174 *op++ = *ip;
175 *op++ = *ip;
176 *op++ = *ip;
177 *op++ = 0xff;
178 ip++;
179 }
180 break;
181
182 case 3:
183 // expand RGBA to RGBX
184 for (x = 0; x < width; ++x) {
185 *op++ = *ip++;
186 *op++ = *ip++;
187 *op++ = *ip++;
188 *op++ = 0xff;
189 }
190 break;
191
192 case 4:
193 // copy RGBA to RGBX
194 memcpy(output_row, input_row, width*4);
195 break;
196 }
197}
198
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700199int res_create_display_surface(const char* name, GRSurface** pSurface) {
200 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700201 int result = 0;
202 png_structp png_ptr = NULL;
203 png_infop info_ptr = NULL;
204 png_uint_32 width, height;
205 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700206 unsigned char* p_row;
207 unsigned int y;
Doug Zongkera418aa72014-03-17 12:10:02 -0700208
209 *pSurface = NULL;
210
211 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
212 if (result < 0) return result;
213
214 surface = init_display_surface(width, height);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800215 if (surface == NULL) {
Doug Zongker19faefa2009-03-27 17:06:24 -0700216 result = -8;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800217 goto exit;
218 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800219
Tony Kuofd778e32015-02-05 21:25:56 +0800220#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
221 png_set_bgr(png_ptr);
222#endif
223
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -0800224 p_row = static_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700225 for (y = 0; y < height; ++y) {
226 png_read_row(png_ptr, p_row, NULL);
227 transform_rgb_to_draw(p_row, surface->data + y * surface->row_bytes, channels, width);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800228 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700229 free(p_row);
Doug Zongker19faefa2009-03-27 17:06:24 -0700230
Doug Zongkera418aa72014-03-17 12:10:02 -0700231 *pSurface = surface;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800232
Doug Zongkera418aa72014-03-17 12:10:02 -0700233 exit:
Doug Zongker19faefa2009-03-27 17:06:24 -0700234 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700235 if (result < 0 && surface != NULL) free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800236 return result;
237}
238
Tao Baob723f4f2015-12-11 15:18:51 -0800239int res_create_multi_display_surface(const char* name, int* frames, int* fps,
240 GRSurface*** pSurface) {
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700241 GRSurface** surface = NULL;
Doug Zongker469954f2014-03-07 09:21:25 -0800242 int result = 0;
Doug Zongker469954f2014-03-07 09:21:25 -0800243 png_structp png_ptr = NULL;
244 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700245 png_uint_32 width, height;
246 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700247 png_textp text;
248 int num_text;
249 unsigned char* p_row;
250 unsigned int y;
Doug Zongker469954f2014-03-07 09:21:25 -0800251
252 *pSurface = NULL;
253 *frames = -1;
254
Doug Zongkera418aa72014-03-17 12:10:02 -0700255 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
256 if (result < 0) return result;
Doug Zongker469954f2014-03-07 09:21:25 -0800257
258 *frames = 1;
Tao Baob723f4f2015-12-11 15:18:51 -0800259 *fps = 20;
Doug Zongker469954f2014-03-07 09:21:25 -0800260 if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
Tao Baob723f4f2015-12-11 15:18:51 -0800261 for (int i = 0; i < num_text; ++i) {
Doug Zongker469954f2014-03-07 09:21:25 -0800262 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
263 *frames = atoi(text[i].text);
Tao Baob723f4f2015-12-11 15:18:51 -0800264 } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
265 *fps = atoi(text[i].text);
Doug Zongker469954f2014-03-07 09:21:25 -0800266 }
267 }
268 printf(" found frames = %d\n", *frames);
Tao Baob723f4f2015-12-11 15:18:51 -0800269 printf(" found fps = %d\n", *fps);
270 }
271
MinSeong Kim126cf8c2016-11-11 05:26:06 +0000272 if (*frames <= 0 || *fps <= 0) {
Tao Baob723f4f2015-12-11 15:18:51 -0800273 printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
274 result = -10;
275 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800276 }
277
278 if (height % *frames != 0) {
279 printf("bad height (%d) for frame count (%d)\n", height, *frames);
280 result = -9;
281 goto exit;
282 }
283
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -0800284 surface = static_cast<GRSurface**>(calloc(*frames, sizeof(GRSurface*)));
Doug Zongker469954f2014-03-07 09:21:25 -0800285 if (surface == NULL) {
286 result = -8;
287 goto exit;
288 }
Tao Baob723f4f2015-12-11 15:18:51 -0800289 for (int i = 0; i < *frames; ++i) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700290 surface[i] = init_display_surface(width, height / *frames);
291 if (surface[i] == NULL) {
292 result = -8;
293 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800294 }
295 }
296
Tony Kuofd778e32015-02-05 21:25:56 +0800297#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
298 png_set_bgr(png_ptr);
299#endif
300
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -0800301 p_row = static_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700302 for (y = 0; y < height; ++y) {
303 png_read_row(png_ptr, p_row, NULL);
304 int frame = y % *frames;
305 unsigned char* out_row = surface[frame]->data +
306 (y / *frames) * surface[frame]->row_bytes;
307 transform_rgb_to_draw(p_row, out_row, channels, width);
308 }
309 free(p_row);
310
Rahul Chaudhry1cf93f52016-11-08 16:35:22 -0800311 *pSurface = surface;
Doug Zongker469954f2014-03-07 09:21:25 -0800312
313exit:
314 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
315
Doug Zongker469954f2014-03-07 09:21:25 -0800316 if (result < 0) {
317 if (surface) {
Tao Baob723f4f2015-12-11 15:18:51 -0800318 for (int i = 0; i < *frames; ++i) {
Elliott Hughes7d626df2016-02-19 10:33:01 -0800319 free(surface[i]);
Doug Zongker469954f2014-03-07 09:21:25 -0800320 }
321 free(surface);
322 }
323 }
324 return result;
325}
326
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700327int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
328 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700329 int result = 0;
330 png_structp png_ptr = NULL;
331 png_infop info_ptr = NULL;
332 png_uint_32 width, height;
333 png_byte channels;
334
335 *pSurface = NULL;
336
337 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
338 if (result < 0) return result;
339
340 if (channels != 1) {
341 result = -7;
342 goto exit;
343 }
344
345 surface = malloc_surface(width * height);
346 if (surface == NULL) {
347 result = -8;
348 goto exit;
349 }
350 surface->width = width;
351 surface->height = height;
352 surface->row_bytes = width;
353 surface->pixel_bytes = 1;
354
Tony Kuofd778e32015-02-05 21:25:56 +0800355#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
356 png_set_bgr(png_ptr);
357#endif
358
Doug Zongkera418aa72014-03-17 12:10:02 -0700359 unsigned char* p_row;
360 unsigned int y;
361 for (y = 0; y < height; ++y) {
362 p_row = surface->data + y * surface->row_bytes;
363 png_read_row(png_ptr, p_row, NULL);
364 }
365
366 *pSurface = surface;
367
368 exit:
369 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
370 if (result < 0 && surface != NULL) free(surface);
371 return result;
372}
373
Tianjie Xu2430e292016-04-19 15:02:41 -0700374// This function tests if a locale string stored in PNG (prefix) matches
375// the locale string provided by the system (locale).
376bool matches_locale(const char* prefix, const char* locale) {
377 if (locale == NULL) return false;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700378
Tianjie Xu2430e292016-04-19 15:02:41 -0700379 // Return true if the whole string of prefix matches the top part of
380 // locale. For instance, prefix == "en" matches locale == "en_US";
381 // and prefix == "zh_CN" matches locale == "zh_CN_#Hans".
Doug Zongker02ec6b82012-08-22 17:26:40 -0700382
Tianjie Xu2430e292016-04-19 15:02:41 -0700383 return (strncmp(prefix, locale, strlen(prefix)) == 0);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700384}
385
Doug Zongkera418aa72014-03-17 12:10:02 -0700386int res_create_localized_alpha_surface(const char* name,
387 const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700388 GRSurface** pSurface) {
389 GRSurface* surface = NULL;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700390 int result = 0;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700391 png_structp png_ptr = NULL;
392 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700393 png_uint_32 width, height;
394 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700395 png_uint_32 y;
Yabin Cui4425c1d2016-02-10 13:47:32 -0800396 std::vector<unsigned char> row;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700397
398 *pSurface = NULL;
399
Doug Zongkera418aa72014-03-17 12:10:02 -0700400 if (locale == NULL) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800401 return result;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700402 }
403
Doug Zongkera418aa72014-03-17 12:10:02 -0700404 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
405 if (result < 0) return result;
406
407 if (channels != 1) {
408 result = -7;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700409 goto exit;
410 }
411
Yabin Cui4425c1d2016-02-10 13:47:32 -0800412 row.resize(width);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700413 for (y = 0; y < height; ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800414 png_read_row(png_ptr, row.data(), NULL);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700415 int w = (row[1] << 8) | row[0];
416 int h = (row[3] << 8) | row[2];
Elliott Hughes7d626df2016-02-19 10:33:01 -0800417 __unused int len = row[4];
Yabin Cui4425c1d2016-02-10 13:47:32 -0800418 char* loc = reinterpret_cast<char*>(&row[5]);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700419
Doug Zongkera418aa72014-03-17 12:10:02 -0700420 if (y+1+h >= height || matches_locale(loc, locale)) {
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700421 printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
422
Doug Zongker16f97c32014-03-06 16:16:05 -0800423 surface = malloc_surface(w*h);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700424 if (surface == NULL) {
425 result = -8;
426 goto exit;
427 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700428 surface->width = w;
429 surface->height = h;
Doug Zongker16f97c32014-03-06 16:16:05 -0800430 surface->row_bytes = w;
431 surface->pixel_bytes = 1;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700432
433 int i;
434 for (i = 0; i < h; ++i, ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800435 png_read_row(png_ptr, row.data(), NULL);
436 memcpy(surface->data + i*w, row.data(), w);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700437 }
438
Rahul Chaudhry1cf93f52016-11-08 16:35:22 -0800439 *pSurface = surface;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700440 break;
441 } else {
Doug Zongker02ec6b82012-08-22 17:26:40 -0700442 int i;
443 for (i = 0; i < h; ++i, ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800444 png_read_row(png_ptr, row.data(), NULL);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700445 }
446 }
447 }
448
449exit:
450 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700451 if (result < 0 && surface != NULL) free(surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700452 return result;
453}
454
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700455void res_free_surface(GRSurface* surface) {
Doug Zongker16f97c32014-03-06 16:16:05 -0800456 free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800457}