blob: 9c69030dab34eb66f2e8951b38dfd7917b3f94f6 [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
Tao Bao0b1118d2017-01-14 07:46:10 -080017#include <fcntl.h>
18#include <linux/fb.h>
19#include <linux/kd.h>
20#include <stdio.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080021#include <stdlib.h>
Elliott Hughescd3c55a2015-01-29 20:50:08 -080022#include <string.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080023#include <sys/ioctl.h>
24#include <sys/mman.h>
25#include <sys/types.h>
Tao Bao0b1118d2017-01-14 07:46:10 -080026#include <unistd.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080027
Yabin Cui4425c1d2016-02-10 13:47:32 -080028#include <vector>
Tao Bao0b1118d2017-01-14 07:46:10 -080029
Doug Zongker19faefa2009-03-27 17:06:24 -070030#include <png.h>
31
Tao Bao0ecbd762017-01-16 21:16:58 -080032#include "minui/minui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080033
Doug Zongker16f97c32014-03-06 16:16:05 -080034#define SURFACE_DATA_ALIGNMENT 8
35
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070036static GRSurface* malloc_surface(size_t data_size) {
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070037 size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -080038 unsigned char* temp = static_cast<unsigned char*>(malloc(size));
Doug Zongker16f97c32014-03-06 16:16:05 -080039 if (temp == NULL) return NULL;
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070040 GRSurface* surface = reinterpret_cast<GRSurface*>(temp);
Doug Zongker16f97c32014-03-06 16:16:05 -080041 surface->data = temp + sizeof(GRSurface) +
42 (SURFACE_DATA_ALIGNMENT - (sizeof(GRSurface) % SURFACE_DATA_ALIGNMENT));
43 return surface;
Doug Zongker19faefa2009-03-27 17:06:24 -070044}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080045
Doug Zongkera418aa72014-03-17 12:10:02 -070046static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
47 png_uint_32* width, png_uint_32* height, png_byte* channels) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080048 char resPath[256];
Doug Zongker19faefa2009-03-27 17:06:24 -070049 unsigned char header[8];
Doug Zongkera418aa72014-03-17 12:10:02 -070050 int result = 0;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070051 int color_type, bit_depth;
52 size_t bytesRead;
Doug Zongker6809c512011-03-01 14:04:34 -080053
Doug Zongker19faefa2009-03-27 17:06:24 -070054 snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080055 resPath[sizeof(resPath)-1] = '\0';
Doug Zongker19faefa2009-03-27 17:06:24 -070056 FILE* fp = fopen(resPath, "rb");
57 if (fp == NULL) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080058 result = -1;
59 goto exit;
60 }
Doug Zongker19faefa2009-03-27 17:06:24 -070061
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070062 bytesRead = fread(header, 1, sizeof(header), fp);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080063 if (bytesRead != sizeof(header)) {
64 result = -2;
65 goto exit;
66 }
Doug Zongker19faefa2009-03-27 17:06:24 -070067
68 if (png_sig_cmp(header, 0, sizeof(header))) {
69 result = -3;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080070 goto exit;
71 }
Doug Zongker19faefa2009-03-27 17:06:24 -070072
Doug Zongkera418aa72014-03-17 12:10:02 -070073 *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
74 if (!*png_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080075 result = -4;
76 goto exit;
77 }
Doug Zongker19faefa2009-03-27 17:06:24 -070078
Doug Zongkera418aa72014-03-17 12:10:02 -070079 *info_ptr = png_create_info_struct(*png_ptr);
80 if (!*info_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080081 result = -5;
82 goto exit;
83 }
Doug Zongker19faefa2009-03-27 17:06:24 -070084
Doug Zongkera418aa72014-03-17 12:10:02 -070085 if (setjmp(png_jmpbuf(*png_ptr))) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080086 result = -6;
87 goto exit;
88 }
Doug Zongker19faefa2009-03-27 17:06:24 -070089
Doug Zongkera418aa72014-03-17 12:10:02 -070090 png_init_io(*png_ptr, fp);
91 png_set_sig_bytes(*png_ptr, sizeof(header));
92 png_read_info(*png_ptr, *info_ptr);
Doug Zongker19faefa2009-03-27 17:06:24 -070093
Doug Zongkera418aa72014-03-17 12:10:02 -070094 png_get_IHDR(*png_ptr, *info_ptr, width, height, &bit_depth,
John Reck94fd07b2013-08-26 16:45:33 -070095 &color_type, NULL, NULL, NULL);
96
Doug Zongkera418aa72014-03-17 12:10:02 -070097 *channels = png_get_channels(*png_ptr, *info_ptr);
John Reck94fd07b2013-08-26 16:45:33 -070098
Doug Zongkera418aa72014-03-17 12:10:02 -070099 if (bit_depth == 8 && *channels == 3 && color_type == PNG_COLOR_TYPE_RGB) {
100 // 8-bit RGB images: great, nothing to do.
101 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_GRAY) {
102 // 1-, 2-, 4-, or 8-bit gray images: expand to 8-bit gray.
103 png_set_expand_gray_1_2_4_to_8(*png_ptr);
Doug Zongker577a1302014-03-20 08:27:01 -0700104 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_PALETTE) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700105 // paletted images: expand to 8-bit RGB. Note that we DON'T
106 // currently expand the tRNS chunk (if any) to an alpha
107 // channel, because minui doesn't support alpha channels in
108 // general.
109 png_set_palette_to_rgb(*png_ptr);
110 *channels = 3;
111 } else {
112 fprintf(stderr, "minui doesn't support PNG depth %d channels %d color_type %d\n",
Doug Zongkera388a762014-03-17 16:51:47 -0700113 bit_depth, *channels, color_type);
Doug Zongkera418aa72014-03-17 12:10:02 -0700114 result = -7;
Doug Zongker19faefa2009-03-27 17:06:24 -0700115 goto exit;
116 }
117
Doug Zongkera418aa72014-03-17 12:10:02 -0700118 return result;
Doug Zongker55a36ac2013-03-04 15:49:02 -0800119
Doug Zongkera418aa72014-03-17 12:10:02 -0700120 exit:
121 if (result < 0) {
122 png_destroy_read_struct(png_ptr, info_ptr, NULL);
123 }
124 if (fp != NULL) {
125 fclose(fp);
126 }
127
128 return result;
129}
130
131// "display" surfaces are transformed into the framebuffer's required
132// pixel format (currently only RGBX is supported) at load time, so
133// gr_blit() can be nothing more than a memcpy() for each row. The
134// next two functions are the only ones that know anything about the
135// framebuffer pixel format; they need to be modified if the
136// framebuffer format changes (but nothing else should).
137
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700138// Allocate and return a GRSurface* sufficient for storing an image of
Doug Zongkera418aa72014-03-17 12:10:02 -0700139// the indicated size in the framebuffer pixel format.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700140static GRSurface* init_display_surface(png_uint_32 width, png_uint_32 height) {
141 GRSurface* surface = malloc_surface(width * height * 4);
Doug Zongkera418aa72014-03-17 12:10:02 -0700142 if (surface == NULL) return NULL;
143
144 surface->width = width;
145 surface->height = height;
146 surface->row_bytes = width * 4;
147 surface->pixel_bytes = 4;
148
149 return surface;
150}
151
152// Copy 'input_row' to 'output_row', transforming it to the
153// framebuffer pixel format. The input format depends on the value of
154// 'channels':
155//
156// 1 - input is 8-bit grayscale
157// 3 - input is 24-bit RGB
158// 4 - input is 32-bit RGBA/RGBX
159//
160// 'width' is the number of pixels in the row.
161static void transform_rgb_to_draw(unsigned char* input_row,
162 unsigned char* output_row,
163 int channels, int width) {
164 int x;
165 unsigned char* ip = input_row;
166 unsigned char* op = output_row;
167
168 switch (channels) {
169 case 1:
170 // expand gray level to RGBX
171 for (x = 0; x < width; ++x) {
172 *op++ = *ip;
173 *op++ = *ip;
174 *op++ = *ip;
175 *op++ = 0xff;
176 ip++;
177 }
178 break;
179
180 case 3:
181 // expand RGBA to RGBX
182 for (x = 0; x < width; ++x) {
183 *op++ = *ip++;
184 *op++ = *ip++;
185 *op++ = *ip++;
186 *op++ = 0xff;
187 }
188 break;
189
190 case 4:
191 // copy RGBA to RGBX
192 memcpy(output_row, input_row, width*4);
193 break;
194 }
195}
196
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700197int res_create_display_surface(const char* name, GRSurface** pSurface) {
198 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700199 int result = 0;
200 png_structp png_ptr = NULL;
201 png_infop info_ptr = NULL;
202 png_uint_32 width, height;
203 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700204 unsigned char* p_row;
205 unsigned int y;
Doug Zongkera418aa72014-03-17 12:10:02 -0700206
207 *pSurface = NULL;
208
209 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
210 if (result < 0) return result;
211
212 surface = init_display_surface(width, height);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800213 if (surface == NULL) {
Doug Zongker19faefa2009-03-27 17:06:24 -0700214 result = -8;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800215 goto exit;
216 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800217
Tony Kuofd778e32015-02-05 21:25:56 +0800218#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
219 png_set_bgr(png_ptr);
220#endif
221
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -0800222 p_row = static_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700223 for (y = 0; y < height; ++y) {
224 png_read_row(png_ptr, p_row, NULL);
225 transform_rgb_to_draw(p_row, surface->data + y * surface->row_bytes, channels, width);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800226 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700227 free(p_row);
Doug Zongker19faefa2009-03-27 17:06:24 -0700228
Doug Zongkera418aa72014-03-17 12:10:02 -0700229 *pSurface = surface;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800230
Doug Zongkera418aa72014-03-17 12:10:02 -0700231 exit:
Doug Zongker19faefa2009-03-27 17:06:24 -0700232 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700233 if (result < 0 && surface != NULL) free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800234 return result;
235}
236
Tao Baob723f4f2015-12-11 15:18:51 -0800237int res_create_multi_display_surface(const char* name, int* frames, int* fps,
238 GRSurface*** pSurface) {
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700239 GRSurface** surface = NULL;
Doug Zongker469954f2014-03-07 09:21:25 -0800240 int result = 0;
Doug Zongker469954f2014-03-07 09:21:25 -0800241 png_structp png_ptr = NULL;
242 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700243 png_uint_32 width, height;
244 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700245 png_textp text;
246 int num_text;
247 unsigned char* p_row;
248 unsigned int y;
Doug Zongker469954f2014-03-07 09:21:25 -0800249
250 *pSurface = NULL;
251 *frames = -1;
252
Doug Zongkera418aa72014-03-17 12:10:02 -0700253 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
254 if (result < 0) return result;
Doug Zongker469954f2014-03-07 09:21:25 -0800255
256 *frames = 1;
Tao Baob723f4f2015-12-11 15:18:51 -0800257 *fps = 20;
Doug Zongker469954f2014-03-07 09:21:25 -0800258 if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
Tao Baob723f4f2015-12-11 15:18:51 -0800259 for (int i = 0; i < num_text; ++i) {
Doug Zongker469954f2014-03-07 09:21:25 -0800260 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
261 *frames = atoi(text[i].text);
Tao Baob723f4f2015-12-11 15:18:51 -0800262 } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
263 *fps = atoi(text[i].text);
Doug Zongker469954f2014-03-07 09:21:25 -0800264 }
265 }
266 printf(" found frames = %d\n", *frames);
Tao Baob723f4f2015-12-11 15:18:51 -0800267 printf(" found fps = %d\n", *fps);
268 }
269
MinSeong Kim126cf8c2016-11-11 05:26:06 +0000270 if (*frames <= 0 || *fps <= 0) {
Tao Baob723f4f2015-12-11 15:18:51 -0800271 printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
272 result = -10;
273 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800274 }
275
276 if (height % *frames != 0) {
277 printf("bad height (%d) for frame count (%d)\n", height, *frames);
278 result = -9;
279 goto exit;
280 }
281
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -0800282 surface = static_cast<GRSurface**>(calloc(*frames, sizeof(GRSurface*)));
Doug Zongker469954f2014-03-07 09:21:25 -0800283 if (surface == NULL) {
284 result = -8;
285 goto exit;
286 }
Tao Baob723f4f2015-12-11 15:18:51 -0800287 for (int i = 0; i < *frames; ++i) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700288 surface[i] = init_display_surface(width, height / *frames);
289 if (surface[i] == NULL) {
290 result = -8;
291 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800292 }
293 }
294
Tony Kuofd778e32015-02-05 21:25:56 +0800295#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
296 png_set_bgr(png_ptr);
297#endif
298
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -0800299 p_row = static_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700300 for (y = 0; y < height; ++y) {
301 png_read_row(png_ptr, p_row, NULL);
302 int frame = y % *frames;
303 unsigned char* out_row = surface[frame]->data +
304 (y / *frames) * surface[frame]->row_bytes;
305 transform_rgb_to_draw(p_row, out_row, channels, width);
306 }
307 free(p_row);
308
Rahul Chaudhry1cf93f52016-11-08 16:35:22 -0800309 *pSurface = surface;
Doug Zongker469954f2014-03-07 09:21:25 -0800310
311exit:
312 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
313
Doug Zongker469954f2014-03-07 09:21:25 -0800314 if (result < 0) {
315 if (surface) {
Tao Baob723f4f2015-12-11 15:18:51 -0800316 for (int i = 0; i < *frames; ++i) {
Elliott Hughes7d626df2016-02-19 10:33:01 -0800317 free(surface[i]);
Doug Zongker469954f2014-03-07 09:21:25 -0800318 }
319 free(surface);
320 }
321 }
322 return result;
323}
324
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700325int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
326 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700327 int result = 0;
328 png_structp png_ptr = NULL;
329 png_infop info_ptr = NULL;
330 png_uint_32 width, height;
331 png_byte channels;
332
333 *pSurface = NULL;
334
335 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
336 if (result < 0) return result;
337
338 if (channels != 1) {
339 result = -7;
340 goto exit;
341 }
342
343 surface = malloc_surface(width * height);
344 if (surface == NULL) {
345 result = -8;
346 goto exit;
347 }
348 surface->width = width;
349 surface->height = height;
350 surface->row_bytes = width;
351 surface->pixel_bytes = 1;
352
Tony Kuofd778e32015-02-05 21:25:56 +0800353#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
354 png_set_bgr(png_ptr);
355#endif
356
Doug Zongkera418aa72014-03-17 12:10:02 -0700357 unsigned char* p_row;
358 unsigned int y;
359 for (y = 0; y < height; ++y) {
360 p_row = surface->data + y * surface->row_bytes;
361 png_read_row(png_ptr, p_row, NULL);
362 }
363
364 *pSurface = surface;
365
366 exit:
367 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
368 if (result < 0 && surface != NULL) free(surface);
369 return result;
370}
371
Tianjie Xu2430e292016-04-19 15:02:41 -0700372// This function tests if a locale string stored in PNG (prefix) matches
373// the locale string provided by the system (locale).
374bool matches_locale(const char* prefix, const char* locale) {
375 if (locale == NULL) return false;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700376
Tianjie Xu2430e292016-04-19 15:02:41 -0700377 // Return true if the whole string of prefix matches the top part of
378 // locale. For instance, prefix == "en" matches locale == "en_US";
379 // and prefix == "zh_CN" matches locale == "zh_CN_#Hans".
Doug Zongker02ec6b82012-08-22 17:26:40 -0700380
Tianjie Xu2430e292016-04-19 15:02:41 -0700381 return (strncmp(prefix, locale, strlen(prefix)) == 0);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700382}
383
Doug Zongkera418aa72014-03-17 12:10:02 -0700384int res_create_localized_alpha_surface(const char* name,
385 const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700386 GRSurface** pSurface) {
387 GRSurface* surface = NULL;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700388 int result = 0;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700389 png_structp png_ptr = NULL;
390 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700391 png_uint_32 width, height;
392 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700393 png_uint_32 y;
Yabin Cui4425c1d2016-02-10 13:47:32 -0800394 std::vector<unsigned char> row;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700395
396 *pSurface = NULL;
397
Doug Zongkera418aa72014-03-17 12:10:02 -0700398 if (locale == NULL) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800399 return result;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700400 }
401
Doug Zongkera418aa72014-03-17 12:10:02 -0700402 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
403 if (result < 0) return result;
404
405 if (channels != 1) {
406 result = -7;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700407 goto exit;
408 }
409
Yabin Cui4425c1d2016-02-10 13:47:32 -0800410 row.resize(width);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700411 for (y = 0; y < height; ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800412 png_read_row(png_ptr, row.data(), NULL);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700413 int w = (row[1] << 8) | row[0];
414 int h = (row[3] << 8) | row[2];
Elliott Hughes7d626df2016-02-19 10:33:01 -0800415 __unused int len = row[4];
Yabin Cui4425c1d2016-02-10 13:47:32 -0800416 char* loc = reinterpret_cast<char*>(&row[5]);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700417
Doug Zongkera418aa72014-03-17 12:10:02 -0700418 if (y+1+h >= height || matches_locale(loc, locale)) {
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700419 printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
420
Doug Zongker16f97c32014-03-06 16:16:05 -0800421 surface = malloc_surface(w*h);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700422 if (surface == NULL) {
423 result = -8;
424 goto exit;
425 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700426 surface->width = w;
427 surface->height = h;
Doug Zongker16f97c32014-03-06 16:16:05 -0800428 surface->row_bytes = w;
429 surface->pixel_bytes = 1;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700430
431 int i;
432 for (i = 0; i < h; ++i, ++y) {
Yabin Cui4425c1d2016-02-10 13:47:32 -0800433 png_read_row(png_ptr, row.data(), NULL);
434 memcpy(surface->data + i*w, row.data(), w);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700435 }
436
Rahul Chaudhry1cf93f52016-11-08 16:35:22 -0800437 *pSurface = surface;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700438 break;
439 } else {
Doug Zongker02ec6b82012-08-22 17:26:40 -0700440 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);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700443 }
444 }
445 }
446
447exit:
448 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700449 if (result < 0 && surface != NULL) free(surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700450 return result;
451}
452
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700453void res_free_surface(GRSurface* surface) {
Doug Zongker16f97c32014-03-06 16:16:05 -0800454 free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800455}