Merge "Switch minui over to C++."

This commit is contained in:
Elliott Hughes 2015-04-10 20:57:37 +00:00 committed by Gerrit Code Review
commit 23017c5d5c
8 changed files with 82 additions and 102 deletions

View file

@ -3,10 +3,10 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
events.cpp \ events.cpp \
graphics.c \ graphics.cpp \
graphics_adf.c \ graphics_adf.cpp \
graphics_fbdev.c \ graphics_fbdev.cpp \
resources.c \ resources.cpp \
LOCAL_WHOLE_STATIC_LIBRARIES += libadf LOCAL_WHOLE_STATIC_LIBRARIES += libadf
LOCAL_STATIC_LIBRARIES += libpng LOCAL_STATIC_LIBRARIES += libpng

View file

@ -39,10 +39,10 @@ struct fd_info {
}; };
static int g_epoll_fd; static int g_epoll_fd;
static struct epoll_event polledevents[MAX_DEVICES + MAX_MISC_FDS]; static epoll_event polledevents[MAX_DEVICES + MAX_MISC_FDS];
static int npolledevents; static int npolledevents;
static struct fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS]; static fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS];
static unsigned ev_count = 0; static unsigned ev_count = 0;
static unsigned ev_dev_count = 0; static unsigned ev_dev_count = 0;
@ -62,7 +62,7 @@ int ev_init(ev_callback input_cb, void* data) {
DIR* dir = opendir("/dev/input"); DIR* dir = opendir("/dev/input");
if (dir != NULL) { if (dir != NULL) {
struct dirent* de; dirent* de;
while ((de = readdir(dir))) { while ((de = readdir(dir))) {
unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)];
@ -83,7 +83,7 @@ int ev_init(ev_callback input_cb, void* data) {
continue; continue;
} }
struct epoll_event ev; epoll_event ev;
ev.events = EPOLLIN | EPOLLWAKEUP; ev.events = EPOLLIN | EPOLLWAKEUP;
ev.data.ptr = &ev_fdinfo[ev_count]; ev.data.ptr = &ev_fdinfo[ev_count];
if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) { if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
@ -121,7 +121,7 @@ int ev_add_fd(int fd, ev_callback cb, void* data) {
return -1; return -1;
} }
struct epoll_event ev; epoll_event ev;
ev.events = EPOLLIN | EPOLLWAKEUP; ev.events = EPOLLIN | EPOLLWAKEUP;
ev.data.ptr = (void *)&ev_fdinfo[ev_count]; ev.data.ptr = (void *)&ev_fdinfo[ev_count];
int ret = epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev); int ret = epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev);
@ -163,7 +163,7 @@ void ev_dispatch(void) {
} }
} }
int ev_get_input(int fd, uint32_t epevents, struct input_event* ev) { int ev_get_input(int fd, uint32_t epevents, input_event* ev) {
if (epevents & EPOLLIN) { if (epevents & EPOLLIN) {
ssize_t r = read(fd, ev, sizeof(*ev)); ssize_t r = read(fd, ev, sizeof(*ev));
if (r == sizeof(*ev)) { if (r == sizeof(*ev)) {

View file

@ -35,11 +35,11 @@
#include "minui.h" #include "minui.h"
#include "graphics.h" #include "graphics.h"
typedef struct { struct GRFont {
GRSurface* texture; GRSurface* texture;
int cwidth; int cwidth;
int cheight; int cheight;
} GRFont; };
static GRFont* gr_font = NULL; static GRFont* gr_font = NULL;
static minui_backend* gr_backend = NULL; static minui_backend* gr_backend = NULL;
@ -269,7 +269,7 @@ unsigned int gr_get_height(GRSurface* surface) {
static void gr_init_font(void) static void gr_init_font(void)
{ {
gr_font = calloc(sizeof(*gr_font), 1); gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1));
int res = res_create_alpha_surface("font", &(gr_font->texture)); int res = res_create_alpha_surface("font", &(gr_font->texture));
if (res == 0) { if (res == 0) {
@ -282,14 +282,14 @@ static void gr_init_font(void)
printf("failed to read font: res=%d\n", res); printf("failed to read font: res=%d\n", res);
// fall back to the compiled-in font. // fall back to the compiled-in font.
gr_font->texture = malloc(sizeof(*gr_font->texture)); gr_font->texture = reinterpret_cast<GRSurface*>(malloc(sizeof(*gr_font->texture)));
gr_font->texture->width = font.width; gr_font->texture->width = font.width;
gr_font->texture->height = font.height; gr_font->texture->height = font.height;
gr_font->texture->row_bytes = font.width; gr_font->texture->row_bytes = font.width;
gr_font->texture->pixel_bytes = 1; gr_font->texture->pixel_bytes = 1;
unsigned char* bits = malloc(font.width * font.height); unsigned char* bits = reinterpret_cast<unsigned char*>(malloc(font.width * font.height));
gr_font->texture->data = (void*) bits; gr_font->texture->data = reinterpret_cast<unsigned char*>(bits);
unsigned char data; unsigned char data;
unsigned char* in = font.rundata; unsigned char* in = font.rundata;

View file

@ -17,34 +17,26 @@
#ifndef _GRAPHICS_H_ #ifndef _GRAPHICS_H_
#define _GRAPHICS_H_ #define _GRAPHICS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include "minui.h" #include "minui.h"
typedef struct minui_backend { // TODO: lose the function pointers.
struct minui_backend {
// Initializes the backend and returns a gr_surface to draw into. // Initializes the backend and returns a gr_surface to draw into.
gr_surface (*init)(struct minui_backend*); gr_surface (*init)(minui_backend*);
// Causes the current drawing surface (returned by the most recent // Causes the current drawing surface (returned by the most recent
// call to flip() or init()) to be displayed, and returns a new // call to flip() or init()) to be displayed, and returns a new
// drawing surface. // drawing surface.
gr_surface (*flip)(struct minui_backend*); gr_surface (*flip)(minui_backend*);
// Blank (or unblank) the screen. // Blank (or unblank) the screen.
void (*blank)(struct minui_backend*, bool); void (*blank)(minui_backend*, bool);
// Device cleanup when drawing is done. // Device cleanup when drawing is done.
void (*exit)(struct minui_backend*); void (*exit)(minui_backend*);
} minui_backend; };
minui_backend* open_fbdev(); minui_backend* open_fbdev();
minui_backend* open_adf(); minui_backend* open_adf();
#ifdef __cplusplus
}
#endif
#endif #endif

View file

@ -44,15 +44,13 @@ struct adf_pdata {
unsigned int current_surface; unsigned int current_surface;
unsigned int n_surfaces; unsigned int n_surfaces;
struct adf_surface_pdata surfaces[2]; adf_surface_pdata surfaces[2];
}; };
static gr_surface adf_flip(struct minui_backend *backend); static gr_surface adf_flip(minui_backend *backend);
static void adf_blank(struct minui_backend *backend, bool blank); static void adf_blank(minui_backend *backend, bool blank);
static int adf_surface_init(struct adf_pdata *pdata, static int adf_surface_init(adf_pdata *pdata, drm_mode_modeinfo *mode, adf_surface_pdata *surf) {
struct drm_mode_modeinfo *mode, struct adf_surface_pdata *surf)
{
memset(surf, 0, sizeof(*surf)); memset(surf, 0, sizeof(*surf));
surf->fd = adf_interface_simple_buffer_alloc(pdata->intf_fd, mode->hdisplay, surf->fd = adf_interface_simple_buffer_alloc(pdata->intf_fd, mode->hdisplay,
@ -65,8 +63,9 @@ static int adf_surface_init(struct adf_pdata *pdata,
surf->base.row_bytes = surf->pitch; surf->base.row_bytes = surf->pitch;
surf->base.pixel_bytes = (pdata->format == DRM_FORMAT_RGB565) ? 2 : 4; surf->base.pixel_bytes = (pdata->format == DRM_FORMAT_RGB565) ? 2 : 4;
surf->base.data = mmap(NULL, surf->pitch * surf->base.height, PROT_WRITE, surf->base.data = reinterpret_cast<uint8_t*>(mmap(NULL,
MAP_SHARED, surf->fd, surf->offset); surf->pitch * surf->base.height, PROT_WRITE,
MAP_SHARED, surf->fd, surf->offset));
if (surf->base.data == MAP_FAILED) { if (surf->base.data == MAP_FAILED) {
close(surf->fd); close(surf->fd);
return -errno; return -errno;
@ -75,9 +74,9 @@ static int adf_surface_init(struct adf_pdata *pdata,
return 0; return 0;
} }
static int adf_interface_init(struct adf_pdata *pdata) static int adf_interface_init(adf_pdata *pdata)
{ {
struct adf_interface_data intf_data; adf_interface_data intf_data;
int ret = 0; int ret = 0;
int err; int err;
@ -107,7 +106,7 @@ done:
return ret; return ret;
} }
static int adf_device_init(struct adf_pdata *pdata, struct adf_device *dev) static int adf_device_init(adf_pdata *pdata, adf_device *dev)
{ {
adf_id_t intf_id; adf_id_t intf_id;
int intf_fd; int intf_fd;
@ -137,7 +136,7 @@ static int adf_device_init(struct adf_pdata *pdata, struct adf_device *dev)
static gr_surface adf_init(minui_backend *backend) static gr_surface adf_init(minui_backend *backend)
{ {
struct adf_pdata *pdata = (struct adf_pdata *)backend; adf_pdata *pdata = (adf_pdata *)backend;
adf_id_t *dev_ids = NULL; adf_id_t *dev_ids = NULL;
ssize_t n_dev_ids, i; ssize_t n_dev_ids, i;
gr_surface ret; gr_surface ret;
@ -164,7 +163,7 @@ static gr_surface adf_init(minui_backend *backend)
pdata->intf_fd = -1; pdata->intf_fd = -1;
for (i = 0; i < n_dev_ids && pdata->intf_fd < 0; i++) { for (i = 0; i < n_dev_ids && pdata->intf_fd < 0; i++) {
struct adf_device dev; adf_device dev;
int err = adf_device_open(dev_ids[i], O_RDWR, &dev); int err = adf_device_open(dev_ids[i], O_RDWR, &dev);
if (err < 0) { if (err < 0) {
@ -194,10 +193,10 @@ static gr_surface adf_init(minui_backend *backend)
return ret; return ret;
} }
static gr_surface adf_flip(struct minui_backend *backend) static gr_surface adf_flip(minui_backend *backend)
{ {
struct adf_pdata *pdata = (struct adf_pdata *)backend; adf_pdata *pdata = (adf_pdata *)backend;
struct adf_surface_pdata *surf = &pdata->surfaces[pdata->current_surface]; adf_surface_pdata *surf = &pdata->surfaces[pdata->current_surface];
int fence_fd = adf_interface_simple_post(pdata->intf_fd, pdata->eng_id, int fence_fd = adf_interface_simple_post(pdata->intf_fd, pdata->eng_id,
surf->base.width, surf->base.height, pdata->format, surf->fd, surf->base.width, surf->base.height, pdata->format, surf->fd,
@ -209,22 +208,22 @@ static gr_surface adf_flip(struct minui_backend *backend)
return &pdata->surfaces[pdata->current_surface].base; return &pdata->surfaces[pdata->current_surface].base;
} }
static void adf_blank(struct minui_backend *backend, bool blank) static void adf_blank(minui_backend *backend, bool blank)
{ {
struct adf_pdata *pdata = (struct adf_pdata *)backend; adf_pdata *pdata = (adf_pdata *)backend;
adf_interface_blank(pdata->intf_fd, adf_interface_blank(pdata->intf_fd,
blank ? DRM_MODE_DPMS_OFF : DRM_MODE_DPMS_ON); blank ? DRM_MODE_DPMS_OFF : DRM_MODE_DPMS_ON);
} }
static void adf_surface_destroy(struct adf_surface_pdata *surf) static void adf_surface_destroy(adf_surface_pdata *surf)
{ {
munmap(surf->base.data, surf->pitch * surf->base.height); munmap(surf->base.data, surf->pitch * surf->base.height);
close(surf->fd); close(surf->fd);
} }
static void adf_exit(struct minui_backend *backend) static void adf_exit(minui_backend *backend)
{ {
struct adf_pdata *pdata = (struct adf_pdata *)backend; adf_pdata *pdata = (adf_pdata *)backend;
unsigned int i; unsigned int i;
for (i = 0; i < pdata->n_surfaces; i++) for (i = 0; i < pdata->n_surfaces; i++)
@ -236,7 +235,7 @@ static void adf_exit(struct minui_backend *backend)
minui_backend *open_adf() minui_backend *open_adf()
{ {
struct adf_pdata *pdata = calloc(1, sizeof(*pdata)); adf_pdata* pdata = reinterpret_cast<adf_pdata*>(calloc(1, sizeof(*pdata)));
if (!pdata) { if (!pdata) {
perror("allocating adf backend failed"); perror("allocating adf backend failed");
return NULL; return NULL;

View file

@ -43,7 +43,7 @@ static bool double_buffered;
static GRSurface* gr_draw = NULL; static GRSurface* gr_draw = NULL;
static int displayed_buffer; static int displayed_buffer;
static struct fb_var_screeninfo vi; static fb_var_screeninfo vi;
static int fb_fd = -1; static int fb_fd = -1;
static minui_backend my_backend = { static minui_backend my_backend = {
@ -80,17 +80,13 @@ static void set_displayed_framebuffer(unsigned n)
} }
static gr_surface fbdev_init(minui_backend* backend) { static gr_surface fbdev_init(minui_backend* backend) {
int fd; int fd = open("/dev/graphics/fb0", O_RDWR);
void *bits; if (fd == -1) {
struct fb_fix_screeninfo fi;
fd = open("/dev/graphics/fb0", O_RDWR);
if (fd < 0) {
perror("cannot open fb0"); perror("cannot open fb0");
return NULL; return NULL;
} }
fb_fix_screeninfo fi;
if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) { if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
perror("failed to get fb0 info"); perror("failed to get fb0 info");
close(fd); close(fd);
@ -124,7 +120,7 @@ static gr_surface fbdev_init(minui_backend* backend) {
vi.green.offset, vi.green.length, vi.green.offset, vi.green.length,
vi.blue.offset, vi.blue.length); vi.blue.offset, vi.blue.length);
bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); void* bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (bits == MAP_FAILED) { if (bits == MAP_FAILED) {
perror("failed to mmap framebuffer"); perror("failed to mmap framebuffer");
close(fd); close(fd);
@ -137,7 +133,7 @@ static gr_surface fbdev_init(minui_backend* backend) {
gr_framebuffer[0].height = vi.yres; gr_framebuffer[0].height = vi.yres;
gr_framebuffer[0].row_bytes = fi.line_length; gr_framebuffer[0].row_bytes = fi.line_length;
gr_framebuffer[0].pixel_bytes = vi.bits_per_pixel / 8; gr_framebuffer[0].pixel_bytes = vi.bits_per_pixel / 8;
gr_framebuffer[0].data = bits; gr_framebuffer[0].data = reinterpret_cast<uint8_t*>(bits);
memset(gr_framebuffer[0].data, 0, gr_framebuffer[0].height * gr_framebuffer[0].row_bytes); memset(gr_framebuffer[0].data, 0, gr_framebuffer[0].height * gr_framebuffer[0].row_bytes);
/* check if we can use double buffering */ /* check if we can use double buffering */

View file

@ -19,33 +19,30 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdbool.h> #include <functional>
#ifdef __cplusplus
extern "C" {
#endif
// //
// Graphics. // Graphics.
// //
typedef struct { struct GRSurface {
int width; int width;
int height; int height;
int row_bytes; int row_bytes;
int pixel_bytes; int pixel_bytes;
unsigned char* data; unsigned char* data;
} GRSurface; };
// TODO: remove this.
typedef GRSurface* gr_surface; typedef GRSurface* gr_surface;
int gr_init(void); int gr_init();
void gr_exit(void); void gr_exit();
int gr_fb_width(void); int gr_fb_width();
int gr_fb_height(void); int gr_fb_height();
void gr_flip(void); void gr_flip();
void gr_fb_blank(bool blank); void gr_fb_blank(bool blank);
void gr_clear(); // clear entire surface to current color void gr_clear(); // clear entire surface to current color
@ -66,12 +63,14 @@ unsigned int gr_get_height(gr_surface surface);
struct input_event; struct input_event;
// TODO: move these over to std::function.
typedef int (*ev_callback)(int fd, uint32_t epevents, void* data); typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
typedef int (*ev_set_key_callback)(int code, int value, void* data); typedef int (*ev_set_key_callback)(int code, int value, void* data);
int ev_init(ev_callback input_cb, void* data); int ev_init(ev_callback input_cb, void* data);
void ev_exit(void); void ev_exit();
int ev_add_fd(int fd, ev_callback cb, void* data); int ev_add_fd(int fd, ev_callback cb, void* data);
void ev_iterate_available_keys(std::function<void(int)> f);
int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data); int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
// 'timeout' has the same semantics as poll(2). // 'timeout' has the same semantics as poll(2).
@ -80,9 +79,9 @@ int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
// > 0 : block for 'timeout' milliseconds // > 0 : block for 'timeout' milliseconds
int ev_wait(int timeout); int ev_wait(int timeout);
int ev_get_input(int fd, uint32_t epevents, struct input_event *ev); int ev_get_input(int fd, uint32_t epevents, input_event* ev);
void ev_dispatch(void); void ev_dispatch();
int ev_get_epollfd(void); int ev_get_epollfd();
// //
// Resources // Resources
@ -124,15 +123,4 @@ int res_create_localized_alpha_surface(const char* name, const char* locale,
// functions. // functions.
void res_free_surface(gr_surface surface); void res_free_surface(gr_surface surface);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <functional>
void ev_iterate_available_keys(std::function<void(int)> f);
#endif
#endif #endif

View file

@ -37,7 +37,8 @@ extern char* locale;
#define SURFACE_DATA_ALIGNMENT 8 #define SURFACE_DATA_ALIGNMENT 8
static gr_surface malloc_surface(size_t data_size) { static gr_surface malloc_surface(size_t data_size) {
unsigned char* temp = malloc(sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT); size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
unsigned char* temp = reinterpret_cast<unsigned char*>(malloc(size));
if (temp == NULL) return NULL; if (temp == NULL) return NULL;
gr_surface surface = (gr_surface) temp; gr_surface surface = (gr_surface) temp;
surface->data = temp + sizeof(GRSurface) + surface->data = temp + sizeof(GRSurface) +
@ -50,6 +51,8 @@ static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
char resPath[256]; char resPath[256];
unsigned char header[8]; unsigned char header[8];
int result = 0; int result = 0;
int color_type, bit_depth;
size_t bytesRead;
snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name); snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
resPath[sizeof(resPath)-1] = '\0'; resPath[sizeof(resPath)-1] = '\0';
@ -59,7 +62,7 @@ static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
goto exit; goto exit;
} }
size_t bytesRead = fread(header, 1, sizeof(header), fp); bytesRead = fread(header, 1, sizeof(header), fp);
if (bytesRead != sizeof(header)) { if (bytesRead != sizeof(header)) {
result = -2; result = -2;
goto exit; goto exit;
@ -91,7 +94,6 @@ static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
png_set_sig_bytes(*png_ptr, sizeof(header)); png_set_sig_bytes(*png_ptr, sizeof(header));
png_read_info(*png_ptr, *info_ptr); png_read_info(*png_ptr, *info_ptr);
int color_type, bit_depth;
png_get_IHDR(*png_ptr, *info_ptr, width, height, &bit_depth, png_get_IHDR(*png_ptr, *info_ptr, width, height, &bit_depth,
&color_type, NULL, NULL, NULL); &color_type, NULL, NULL, NULL);
@ -204,6 +206,8 @@ int res_create_display_surface(const char* name, gr_surface* pSurface) {
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
png_uint_32 width, height; png_uint_32 width, height;
png_byte channels; png_byte channels;
unsigned char* p_row;
unsigned int y;
*pSurface = NULL; *pSurface = NULL;
@ -220,8 +224,7 @@ int res_create_display_surface(const char* name, gr_surface* pSurface) {
png_set_bgr(png_ptr); png_set_bgr(png_ptr);
#endif #endif
unsigned char* p_row = malloc(width * 4); p_row = reinterpret_cast<unsigned char*>(malloc(width * 4));
unsigned int y;
for (y = 0; y < height; ++y) { for (y = 0; y < height; ++y) {
png_read_row(png_ptr, p_row, NULL); png_read_row(png_ptr, p_row, NULL);
transform_rgb_to_draw(p_row, surface->data + y * surface->row_bytes, channels, width); transform_rgb_to_draw(p_row, surface->data + y * surface->row_bytes, channels, width);
@ -244,6 +247,10 @@ int res_create_multi_display_surface(const char* name, int* frames, gr_surface**
png_uint_32 width, height; png_uint_32 width, height;
png_byte channels; png_byte channels;
int i; int i;
png_textp text;
int num_text;
unsigned char* p_row;
unsigned int y;
*pSurface = NULL; *pSurface = NULL;
*frames = -1; *frames = -1;
@ -252,8 +259,6 @@ int res_create_multi_display_surface(const char* name, int* frames, gr_surface**
if (result < 0) return result; if (result < 0) return result;
*frames = 1; *frames = 1;
png_textp text;
int num_text;
if (png_get_text(png_ptr, info_ptr, &text, &num_text)) { if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
for (i = 0; i < num_text; ++i) { for (i = 0; i < num_text; ++i) {
if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) { if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
@ -270,7 +275,7 @@ int res_create_multi_display_surface(const char* name, int* frames, gr_surface**
goto exit; goto exit;
} }
surface = malloc(*frames * sizeof(gr_surface)); surface = reinterpret_cast<gr_surface*>(malloc(*frames * sizeof(gr_surface)));
if (surface == NULL) { if (surface == NULL) {
result = -8; result = -8;
goto exit; goto exit;
@ -287,8 +292,7 @@ int res_create_multi_display_surface(const char* name, int* frames, gr_surface**
png_set_bgr(png_ptr); png_set_bgr(png_ptr);
#endif #endif
unsigned char* p_row = malloc(width * 4); p_row = reinterpret_cast<unsigned char*>(malloc(width * 4));
unsigned int y;
for (y = 0; y < height; ++y) { for (y = 0; y < height; ++y) {
png_read_row(png_ptr, p_row, NULL); png_read_row(png_ptr, p_row, NULL);
int frame = y % *frames; int frame = y % *frames;
@ -387,6 +391,8 @@ int res_create_localized_alpha_surface(const char* name,
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
png_uint_32 width, height; png_uint_32 width, height;
png_byte channels; png_byte channels;
unsigned char* row;
png_uint_32 y;
*pSurface = NULL; *pSurface = NULL;
@ -407,8 +413,7 @@ int res_create_localized_alpha_surface(const char* name,
goto exit; goto exit;
} }
unsigned char* row = malloc(width); row = reinterpret_cast<unsigned char*>(malloc(width));
png_uint_32 y;
for (y = 0; y < height; ++y) { for (y = 0; y < height; ++y) {
png_read_row(png_ptr, row, NULL); png_read_row(png_ptr, row, NULL);
int w = (row[1] << 8) | row[0]; int w = (row[1] << 8) | row[0];