Skip to content

Commit

Permalink
minuitwrp: fix crash when taking a screenshot.
Browse files Browse the repository at this point in the history
when "gr_mem_surface.format = GGL_PIXEL_FORMAT_RGBA_8888", "gl->recti" will be crash.
this is a simple fix.

Change-Id: I39da7298286f34cdf7eae98f6b082c36695b222e
  • Loading branch information
xiaolu authored and Dees-Troy committed Jun 17, 2015
1 parent 9416f4f commit 26ffa86
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions minuitwrp/graphics_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ GGLSurface gr_mem_surface;
int gr_save_screenshot(const char *dest)
{
uint32_t y, stride_bytes;
int res = -1;
volatile int res = -1;
GGLContext *gl = NULL;
GGLSurface surface;
uint8_t * volatile img_data = NULL;
uint8_t *ptr;
FILE *fp = NULL;
FILE * volatile fp = NULL;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;

fp = fopen(dest, "wb");
if(!fp)
goto exit;

img_data = malloc(vi.xres * vi.yres * 3);
img_data = malloc(gr_mem_surface.stride * vi.yres * 4);
surface.version = sizeof(surface);
surface.width = gr_mem_surface.width;
surface.height = gr_mem_surface.height;
surface.stride = gr_mem_surface.width;
surface.stride = gr_mem_surface.stride;
surface.data = img_data;
surface.format = GGL_PIXEL_FORMAT_RGB_888;
surface.format = GGL_PIXEL_FORMAT_RGBA_8888;

gglInit(&gl);
gl->colorBuffer(gl, &surface);
gl->activeTexture(gl, 0);

if(gr_mem_surface.format == GGL_PIXEL_FORMAT_RGBX_8888)
gl->disable(gl, GGL_BLEND);

gl->bindTexture(gl, &gr_mem_surface);
gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
Expand Down Expand Up @@ -81,8 +84,11 @@ int gr_save_screenshot(const char *dest)
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);

// To remove the alpha channel for PNG_COLOR_TYPE_RGB format,
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);

ptr = img_data;
stride_bytes = surface.width*3;
stride_bytes = surface.stride*4;
for(y = 0; y < surface.height; ++y)
{
png_write_row(png_ptr, ptr);
Expand Down

0 comments on commit 26ffa86

Please sign in to comment.