blob: 9f67cf8445352669893e9dcd56dd3abe79e74be6 [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 Bao3d0cd1d2018-04-13 13:41:58 -070017#include "private/resources.h"
18
Tao Bao0b1118d2017-01-14 07:46:10 -080019#include <fcntl.h>
20#include <linux/fb.h>
21#include <linux/kd.h>
22#include <stdio.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080023#include <stdlib.h>
Elliott Hughescd3c55a2015-01-29 20:50:08 -080024#include <string.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080025#include <sys/ioctl.h>
26#include <sys/mman.h>
27#include <sys/types.h>
Tao Bao0b1118d2017-01-14 07:46:10 -080028#include <unistd.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080029
Tianjie Xuacba38c2017-09-27 17:53:34 -070030#include <memory>
Tianjie Xu2078b222017-03-22 12:27:26 -070031#include <regex>
32#include <string>
Yabin Cui4425c1d2016-02-10 13:47:32 -080033#include <vector>
Tao Bao0b1118d2017-01-14 07:46:10 -080034
Tianjie Xuacba38c2017-09-27 17:53:34 -070035#include <android-base/stringprintf.h>
Tianjie Xu2078b222017-03-22 12:27:26 -070036#include <android-base/strings.h>
Doug Zongker19faefa2009-03-27 17:06:24 -070037#include <png.h>
38
Tao Bao0ecbd762017-01-16 21:16:58 -080039#include "minui/minui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080040
Doug Zongker16f97c32014-03-06 16:16:05 -080041#define SURFACE_DATA_ALIGNMENT 8
42
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070043static GRSurface* malloc_surface(size_t data_size) {
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070044 size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
Rahul Chaudhryb29f23f2016-11-09 13:17:01 -080045 unsigned char* temp = static_cast<unsigned char*>(malloc(size));
Doug Zongker16f97c32014-03-06 16:16:05 -080046 if (temp == NULL) return NULL;
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070047 GRSurface* surface = reinterpret_cast<GRSurface*>(temp);
Doug Zongker16f97c32014-03-06 16:16:05 -080048 surface->data = temp + sizeof(GRSurface) +
49 (SURFACE_DATA_ALIGNMENT - (sizeof(GRSurface) % SURFACE_DATA_ALIGNMENT));
50 return surface;
Doug Zongker19faefa2009-03-27 17:06:24 -070051}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052
Tao Bao3d0cd1d2018-04-13 13:41:58 -070053PngHandler::PngHandler(const std::string& name) {
Tianjie Xuacba38c2017-09-27 17:53:34 -070054 std::string res_path = android::base::StringPrintf("/res/images/%s.png", name.c_str());
55 png_fp_.reset(fopen(res_path.c_str(), "rbe"));
Tao Bao3d0cd1d2018-04-13 13:41:58 -070056 // Try to read from |name| if the resource path does not work.
57 if (!png_fp_) {
58 png_fp_.reset(fopen(name.c_str(), "rbe"));
59 }
Tianjie Xuacba38c2017-09-27 17:53:34 -070060 if (!png_fp_) {
61 error_code_ = -1;
62 return;
63 }
Doug Zongker55a36ac2013-03-04 15:49:02 -080064
Tianjie Xuacba38c2017-09-27 17:53:34 -070065 unsigned char header[8];
66 size_t bytesRead = fread(header, 1, sizeof(header), png_fp_.get());
67 if (bytesRead != sizeof(header)) {
68 error_code_ = -2;
69 return;
70 }
Doug Zongkera418aa72014-03-17 12:10:02 -070071
Tianjie Xuacba38c2017-09-27 17:53:34 -070072 if (png_sig_cmp(header, 0, sizeof(header))) {
73 error_code_ = -3;
74 return;
75 }
76
77 png_ptr_ = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
78 if (!png_ptr_) {
79 error_code_ = -4;
80 return;
81 }
82
83 info_ptr_ = png_create_info_struct(png_ptr_);
84 if (!info_ptr_) {
85 error_code_ = -5;
86 return;
87 }
88
89 if (setjmp(png_jmpbuf(png_ptr_))) {
90 error_code_ = -6;
91 return;
92 }
93
94 png_init_io(png_ptr_, png_fp_.get());
95 png_set_sig_bytes(png_ptr_, sizeof(header));
96 png_read_info(png_ptr_, info_ptr_);
97
Tao Bao3d0cd1d2018-04-13 13:41:58 -070098 png_get_IHDR(png_ptr_, info_ptr_, &width_, &height_, &bit_depth_, &color_type_, nullptr, nullptr,
Tianjie Xuacba38c2017-09-27 17:53:34 -070099 nullptr);
100
101 channels_ = png_get_channels(png_ptr_, info_ptr_);
102
Tao Bao3d0cd1d2018-04-13 13:41:58 -0700103 if (bit_depth_ == 8 && channels_ == 3 && color_type_ == PNG_COLOR_TYPE_RGB) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700104 // 8-bit RGB images: great, nothing to do.
Tao Bao3d0cd1d2018-04-13 13:41:58 -0700105 } else if (bit_depth_ <= 8 && channels_ == 1 && color_type_ == PNG_COLOR_TYPE_GRAY) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700106 // 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_);
Tao Bao3d0cd1d2018-04-13 13:41:58 -0700108 } else if (bit_depth_ <= 8 && channels_ == 1 && color_type_ == PNG_COLOR_TYPE_PALETTE) {
Tianjie Xuacba38c2017-09-27 17:53:34 -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 {
Tao Bao3d0cd1d2018-04-13 13:41:58 -0700116 fprintf(stderr, "minui doesn't support PNG depth %d channels %d color_type %d\n", bit_depth_,
117 channels_, color_type_);
Tianjie Xuacba38c2017-09-27 17:53:34 -0700118 error_code_ = -7;
119 }
120}
121
122PngHandler::~PngHandler() {
123 if (png_ptr_) {
124 png_destroy_read_struct(&png_ptr_, &info_ptr_, nullptr);
125 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700126}
127
128// "display" surfaces are transformed into the framebuffer's required
129// pixel format (currently only RGBX is supported) at load time, so
130// gr_blit() can be nothing more than a memcpy() for each row. The
131// next two functions are the only ones that know anything about the
132// framebuffer pixel format; they need to be modified if the
133// framebuffer format changes (but nothing else should).
134
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700135// Allocate and return a GRSurface* sufficient for storing an image of
Doug Zongkera418aa72014-03-17 12:10:02 -0700136// the indicated size in the framebuffer pixel format.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700137static GRSurface* init_display_surface(png_uint_32 width, png_uint_32 height) {
138 GRSurface* surface = malloc_surface(width * height * 4);
Doug Zongkera418aa72014-03-17 12:10:02 -0700139 if (surface == NULL) return NULL;
140
141 surface->width = width;
142 surface->height = height;
143 surface->row_bytes = width * 4;
144 surface->pixel_bytes = 4;
145
146 return surface;
147}
148
149// Copy 'input_row' to 'output_row', transforming it to the
150// framebuffer pixel format. The input format depends on the value of
151// 'channels':
152//
153// 1 - input is 8-bit grayscale
154// 3 - input is 24-bit RGB
155// 4 - input is 32-bit RGBA/RGBX
156//
157// 'width' is the number of pixels in the row.
158static void transform_rgb_to_draw(unsigned char* input_row,
159 unsigned char* output_row,
160 int channels, int width) {
161 int x;
162 unsigned char* ip = input_row;
163 unsigned char* op = output_row;
164
165 switch (channels) {
166 case 1:
167 // expand gray level to RGBX
168 for (x = 0; x < width; ++x) {
169 *op++ = *ip;
170 *op++ = *ip;
171 *op++ = *ip;
172 *op++ = 0xff;
173 ip++;
174 }
175 break;
176
177 case 3:
178 // expand RGBA to RGBX
179 for (x = 0; x < width; ++x) {
180 *op++ = *ip++;
181 *op++ = *ip++;
182 *op++ = *ip++;
183 *op++ = 0xff;
184 }
185 break;
186
187 case 4:
188 // copy RGBA to RGBX
189 memcpy(output_row, input_row, width*4);
190 break;
191 }
192}
193
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700194int res_create_display_surface(const char* name, GRSurface** pSurface) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700195 *pSurface = nullptr;
Doug Zongkera418aa72014-03-17 12:10:02 -0700196
Tianjie Xuacba38c2017-09-27 17:53:34 -0700197 PngHandler png_handler(name);
198 if (!png_handler) return png_handler.error_code();
Doug Zongkera418aa72014-03-17 12:10:02 -0700199
Tianjie Xuacba38c2017-09-27 17:53:34 -0700200 png_structp png_ptr = png_handler.png_ptr();
201 png_uint_32 width = png_handler.width();
202 png_uint_32 height = png_handler.height();
Doug Zongkera418aa72014-03-17 12:10:02 -0700203
Tianjie Xuacba38c2017-09-27 17:53:34 -0700204 GRSurface* surface = init_display_surface(width, height);
205 if (!surface) {
206 return -8;
207 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800208
Tony Kuofd778e32015-02-05 21:25:56 +0800209#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
Tianjie Xuacba38c2017-09-27 17:53:34 -0700210 png_set_bgr(png_ptr);
Tony Kuofd778e32015-02-05 21:25:56 +0800211#endif
212
Tianjie Xuacba38c2017-09-27 17:53:34 -0700213 for (png_uint_32 y = 0; y < height; ++y) {
214 std::vector<unsigned char> p_row(width * 4);
215 png_read_row(png_ptr, p_row.data(), nullptr);
216 transform_rgb_to_draw(p_row.data(), surface->data + y * surface->row_bytes,
217 png_handler.channels(), width);
218 }
Doug Zongker19faefa2009-03-27 17:06:24 -0700219
Tianjie Xuacba38c2017-09-27 17:53:34 -0700220 *pSurface = surface;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800221
Tianjie Xuacba38c2017-09-27 17:53:34 -0700222 return 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800223}
224
Tao Baob723f4f2015-12-11 15:18:51 -0800225int res_create_multi_display_surface(const char* name, int* frames, int* fps,
Tianjie Xuacba38c2017-09-27 17:53:34 -0700226 GRSurface*** pSurface) {
227 *pSurface = nullptr;
228 *frames = -1;
Doug Zongker469954f2014-03-07 09:21:25 -0800229
Tianjie Xuacba38c2017-09-27 17:53:34 -0700230 PngHandler png_handler(name);
231 if (!png_handler) return png_handler.error_code();
Doug Zongker469954f2014-03-07 09:21:25 -0800232
Tianjie Xuacba38c2017-09-27 17:53:34 -0700233 png_structp png_ptr = png_handler.png_ptr();
234 png_uint_32 width = png_handler.width();
235 png_uint_32 height = png_handler.height();
Doug Zongker469954f2014-03-07 09:21:25 -0800236
Tianjie Xuacba38c2017-09-27 17:53:34 -0700237 *frames = 1;
238 *fps = 20;
239 png_textp text;
240 int num_text;
241 if (png_get_text(png_ptr, png_handler.info_ptr(), &text, &num_text)) {
242 for (int i = 0; i < num_text; ++i) {
243 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
244 *frames = atoi(text[i].text);
245 } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
246 *fps = atoi(text[i].text);
247 }
Tao Baob723f4f2015-12-11 15:18:51 -0800248 }
Tianjie Xuacba38c2017-09-27 17:53:34 -0700249 printf(" found frames = %d\n", *frames);
250 printf(" found fps = %d\n", *fps);
251 }
Tao Baob723f4f2015-12-11 15:18:51 -0800252
Tianjie Xuacba38c2017-09-27 17:53:34 -0700253 int result = 0;
254 GRSurface** surface = nullptr;
255 if (*frames <= 0 || *fps <= 0) {
256 printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
257 result = -10;
258 goto exit;
259 }
Doug Zongker469954f2014-03-07 09:21:25 -0800260
Tianjie Xuacba38c2017-09-27 17:53:34 -0700261 if (height % *frames != 0) {
262 printf("bad height (%d) for frame count (%d)\n", height, *frames);
263 result = -9;
264 goto exit;
265 }
Doug Zongker469954f2014-03-07 09:21:25 -0800266
Tianjie Xuacba38c2017-09-27 17:53:34 -0700267 surface = static_cast<GRSurface**>(calloc(*frames, sizeof(GRSurface*)));
268 if (!surface) {
269 result = -8;
270 goto exit;
271 }
272 for (int i = 0; i < *frames; ++i) {
273 surface[i] = init_display_surface(width, height / *frames);
274 if (!surface[i]) {
275 result = -8;
276 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800277 }
Tianjie Xuacba38c2017-09-27 17:53:34 -0700278 }
Doug Zongker469954f2014-03-07 09:21:25 -0800279
Tony Kuofd778e32015-02-05 21:25:56 +0800280#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
Tianjie Xuacba38c2017-09-27 17:53:34 -0700281 png_set_bgr(png_ptr);
Tony Kuofd778e32015-02-05 21:25:56 +0800282#endif
283
Tianjie Xuacba38c2017-09-27 17:53:34 -0700284 for (png_uint_32 y = 0; y < height; ++y) {
285 std::vector<unsigned char> p_row(width * 4);
286 png_read_row(png_ptr, p_row.data(), nullptr);
287 int frame = y % *frames;
288 unsigned char* out_row = surface[frame]->data + (y / *frames) * surface[frame]->row_bytes;
289 transform_rgb_to_draw(p_row.data(), out_row, png_handler.channels(), width);
290 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700291
Tianjie Xuacba38c2017-09-27 17:53:34 -0700292 *pSurface = surface;
Doug Zongker469954f2014-03-07 09:21:25 -0800293
294exit:
Tianjie Xuacba38c2017-09-27 17:53:34 -0700295 if (result < 0) {
296 if (surface) {
297 for (int i = 0; i < *frames; ++i) {
298 free(surface[i]);
299 }
300 free(surface);
Doug Zongker469954f2014-03-07 09:21:25 -0800301 }
Tianjie Xuacba38c2017-09-27 17:53:34 -0700302 }
303 return result;
Doug Zongker469954f2014-03-07 09:21:25 -0800304}
305
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700306int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700307 *pSurface = nullptr;
Doug Zongkera418aa72014-03-17 12:10:02 -0700308
Tianjie Xuacba38c2017-09-27 17:53:34 -0700309 PngHandler png_handler(name);
310 if (!png_handler) return png_handler.error_code();
Doug Zongkera418aa72014-03-17 12:10:02 -0700311
Tianjie Xuacba38c2017-09-27 17:53:34 -0700312 if (png_handler.channels() != 1) {
313 return -7;
314 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700315
Tianjie Xuacba38c2017-09-27 17:53:34 -0700316 png_structp png_ptr = png_handler.png_ptr();
317 png_uint_32 width = png_handler.width();
318 png_uint_32 height = png_handler.height();
Doug Zongkera418aa72014-03-17 12:10:02 -0700319
Tianjie Xuacba38c2017-09-27 17:53:34 -0700320 GRSurface* surface = malloc_surface(width * height);
321 if (!surface) {
322 return -8;
323 }
324 surface->width = width;
325 surface->height = height;
326 surface->row_bytes = width;
327 surface->pixel_bytes = 1;
Doug Zongkera418aa72014-03-17 12:10:02 -0700328
Tony Kuofd778e32015-02-05 21:25:56 +0800329#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
Tianjie Xuacba38c2017-09-27 17:53:34 -0700330 png_set_bgr(png_ptr);
Tony Kuofd778e32015-02-05 21:25:56 +0800331#endif
332
Tianjie Xuacba38c2017-09-27 17:53:34 -0700333 for (png_uint_32 y = 0; y < height; ++y) {
334 unsigned char* p_row = surface->data + y * surface->row_bytes;
335 png_read_row(png_ptr, p_row, nullptr);
336 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700337
Tianjie Xuacba38c2017-09-27 17:53:34 -0700338 *pSurface = surface;
Doug Zongkera418aa72014-03-17 12:10:02 -0700339
Tianjie Xuacba38c2017-09-27 17:53:34 -0700340 return 0;
Doug Zongkera418aa72014-03-17 12:10:02 -0700341}
342
Tianjie Xu2430e292016-04-19 15:02:41 -0700343// This function tests if a locale string stored in PNG (prefix) matches
344// the locale string provided by the system (locale).
Tianjie Xu2078b222017-03-22 12:27:26 -0700345bool matches_locale(const std::string& prefix, const std::string& locale) {
346 // According to the BCP 47 format, A locale string may consists of:
347 // language-{extlang}-{script}-{region}-{variant}
348 // The locale headers in PNG mostly consist of language-{region} except for sr-Latn, and some
349 // android's system locale can have the format language-{script}-{region}.
Doug Zongker02ec6b82012-08-22 17:26:40 -0700350
Tianjie Xu2078b222017-03-22 12:27:26 -0700351 // Return true if the whole string of prefix matches the top part of locale. Otherwise try to
352 // match the locale string without the {script} section.
353 // For instance, prefix == "en" matches locale == "en-US", prefix == "sr-Latn" matches locale
354 // == "sr-Latn-BA", and prefix == "zh-CN" matches locale == "zh-Hans-CN".
Elliott Hughes1d65c952017-12-20 12:36:31 -0800355 if (android::base::StartsWith(locale, prefix)) {
Tianjie Xu2078b222017-03-22 12:27:26 -0700356 return true;
357 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700358
Tianjie Xu2078b222017-03-22 12:27:26 -0700359 size_t separator = prefix.find('-');
360 if (separator == std::string::npos) {
361 return false;
362 }
363 std::regex loc_regex(prefix.substr(0, separator) + "-[A-Za-z]*" + prefix.substr(separator));
364 return std::regex_match(locale, loc_regex);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700365}
366
Tianjie Xu29d55752017-09-20 17:53:46 -0700367std::vector<std::string> get_locales_in_png(const std::string& png_name) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700368 PngHandler png_handler(png_name);
369 if (!png_handler) {
370 printf("Failed to open %s, error: %d\n", png_name.c_str(), png_handler.error_code());
Tianjie Xu29d55752017-09-20 17:53:46 -0700371 return {};
372 }
Tianjie Xuacba38c2017-09-27 17:53:34 -0700373 if (png_handler.channels() != 1) {
374 printf("Expect input png to have 1 data channel, this file has %d\n", png_handler.channels());
Tianjie Xu29d55752017-09-20 17:53:46 -0700375 return {};
376 }
377
378 std::vector<std::string> result;
Tianjie Xuacba38c2017-09-27 17:53:34 -0700379 std::vector<unsigned char> row(png_handler.width());
380 for (png_uint_32 y = 0; y < png_handler.height(); ++y) {
381 png_read_row(png_handler.png_ptr(), row.data(), nullptr);
Tianjie Xu29d55752017-09-20 17:53:46 -0700382 int h = (row[3] << 8) | row[2];
383 std::string loc(reinterpret_cast<char*>(&row[5]));
384 if (!loc.empty()) {
385 result.push_back(loc);
386 }
387 for (int i = 0; i < h; ++i, ++y) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700388 png_read_row(png_handler.png_ptr(), row.data(), nullptr);
Tianjie Xu29d55752017-09-20 17:53:46 -0700389 }
390 }
391
Tianjie Xu29d55752017-09-20 17:53:46 -0700392 return result;
393}
394
Doug Zongkera418aa72014-03-17 12:10:02 -0700395int res_create_localized_alpha_surface(const char* name,
396 const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700397 GRSurface** pSurface) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700398 *pSurface = nullptr;
399 if (locale == nullptr) {
400 return 0;
401 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700402
Tianjie Xuacba38c2017-09-27 17:53:34 -0700403 PngHandler png_handler(name);
404 if (!png_handler) return png_handler.error_code();
Doug Zongker02ec6b82012-08-22 17:26:40 -0700405
Tianjie Xuacba38c2017-09-27 17:53:34 -0700406 if (png_handler.channels() != 1) {
407 return -7;
408 }
409
410 png_structp png_ptr = png_handler.png_ptr();
411 png_uint_32 width = png_handler.width();
412 png_uint_32 height = png_handler.height();
413
414 for (png_uint_32 y = 0; y < height; ++y) {
415 std::vector<unsigned char> row(width);
416 png_read_row(png_ptr, row.data(), nullptr);
417 int w = (row[1] << 8) | row[0];
418 int h = (row[3] << 8) | row[2];
419 __unused int len = row[4];
420 char* loc = reinterpret_cast<char*>(&row[5]);
421
422 if (y + 1 + h >= height || matches_locale(loc, locale)) {
423 printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
424
425 GRSurface* surface = malloc_surface(w * h);
426 if (!surface) {
427 return -8;
428 }
429 surface->width = w;
430 surface->height = h;
431 surface->row_bytes = w;
432 surface->pixel_bytes = 1;
433
434 for (int i = 0; i < h; ++i, ++y) {
435 png_read_row(png_ptr, row.data(), nullptr);
436 memcpy(surface->data + i * w, row.data(), w);
437 }
438
439 *pSurface = surface;
440 break;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700441 }
442
Tianjie Xuacba38c2017-09-27 17:53:34 -0700443 for (int i = 0; i < h; ++i, ++y) {
444 png_read_row(png_ptr, row.data(), nullptr);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700445 }
Tianjie Xuacba38c2017-09-27 17:53:34 -0700446 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700447
Tianjie Xuacba38c2017-09-27 17:53:34 -0700448 return 0;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700449}
450
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700451void res_free_surface(GRSurface* surface) {
Tianjie Xuacba38c2017-09-27 17:53:34 -0700452 free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800453}