From 5bc5b3afa5644bfc20a6c8468c79404e6e3d0eaa Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Mon, 15 Dec 2014 23:06:48 +0900 Subject: [PATCH] display: added maru_display_processing Change-Id: Iaa0266d60932f7ce56be5e0eab97f0c6204a94e9 Signed-off-by: GiWoong Kim --- tizen/src/display/Makefile.objs | 2 +- tizen/src/display/maru_display.c | 2 + tizen/src/display/maru_display_processing.c | 199 ++++++++++++++++++++ tizen/src/display/maru_display_processing.h | 41 ++++ tizen/src/display/maru_sdl.c | 5 +- tizen/src/display/maru_sdl_processing.c | 164 ---------------- tizen/src/display/maru_sdl_processing.h | 4 - tizen/src/display/maru_shm.c | 19 +- 8 files changed, 250 insertions(+), 186 deletions(-) create mode 100644 tizen/src/display/maru_display_processing.c create mode 100644 tizen/src/display/maru_display_processing.h diff --git a/tizen/src/display/Makefile.objs b/tizen/src/display/Makefile.objs index b546ca2ef3..796f50862d 100644 --- a/tizen/src/display/Makefile.objs +++ b/tizen/src/display/Makefile.objs @@ -1,4 +1,4 @@ -obj-y += maru_display.o +obj-y += maru_display.o maru_display_processing.o obj-$(CONFIG_USE_SHM) += maru_shm.o diff --git a/tizen/src/display/maru_display.c b/tizen/src/display/maru_display.c index fcf229e213..ddc34cdc11 100644 --- a/tizen/src/display/maru_display.c +++ b/tizen/src/display/maru_display.c @@ -28,8 +28,10 @@ */ +#include #include "emulator.h" #include "maru_display.h" +#include "maru_display_processing.h" #include "debug_ch.h" MULTI_DEBUG_CHANNEL(tizen, display); diff --git a/tizen/src/display/maru_display_processing.c b/tizen/src/display/maru_display_processing.c new file mode 100644 index 0000000000..ac37ca41cd --- /dev/null +++ b/tizen/src/display/maru_display_processing.c @@ -0,0 +1,199 @@ +/* + * Image Processing + * + * Copyright (C) 2011 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * SangHo Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "emulator_common.h" +#include "maru_display_processing.h" +#include "hw/pci/maru_brightness.h" +#include "debug_ch.h" + +MULTI_DEBUG_CHANNEL(tizen, dpy_op); + + +/* Image processing functions using the pixman library */ +void composite_brightness_image(pixman_image_t *dst_image) +{ + /* apply the brightness level */ + if (brightness_level < BRIGHTNESS_MAX) { + pixman_image_composite(PIXMAN_OP_OVER, + brightness_image, NULL, dst_image, + 0, 0, 0, 0, 0, 0, + pixman_image_get_width(dst_image), + pixman_image_get_height(dst_image)); + } +} + +/* libpng library */ +png_bytep read_png_file(const char *file_name, + unsigned int *width_out, unsigned int *height_out) +{ +#define PNG_HEADER_SIZE 8 + + FILE *fp = NULL; + png_byte header[PNG_HEADER_SIZE] = { 0, }; + png_structp png_ptr = NULL; + + png_infop info_ptr = NULL; + png_uint_32 width = 0; + png_uint_32 height = 0; + png_byte channels = 0; + unsigned int stride = 0; + int bit_depth = 0; + int color_type = 0; + int i = 0; + + png_bytep pixel_data = NULL; + png_bytepp row_ptr_data = NULL; + + if (file_name == NULL) { + ERR("file name is empty\n"); + return NULL; + } + + fp = fopen(file_name, "rb"); + if (fp == NULL) { + ERR("file %s could not be opened\n", file_name); + return NULL; + } + + if (fread(header, sizeof(png_byte), PNG_HEADER_SIZE, fp) != PNG_HEADER_SIZE) { + ERR("failed to read header from png file\n"); + fclose(fp); + return NULL; + } + + if (png_sig_cmp(header, 0, PNG_HEADER_SIZE) != 0) { + ERR("file %s is not recognized as a PNG image\n", file_name); + fclose(fp); + return NULL; + } + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (png_ptr == NULL) { + ERR("failed to allocate png read struct\n"); + fclose(fp); + return NULL; + } + + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) { + ERR("failed to allocate png info struct\n"); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + fclose(fp); + return NULL; + } + + if (setjmp(png_jmpbuf(png_ptr)) != 0) { + ERR("error during init_io\n"); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + png_destroy_info_struct(png_ptr, &info_ptr); + fclose(fp); + return NULL; + } + + png_init_io(png_ptr, fp); + png_set_sig_bytes(png_ptr, PNG_HEADER_SIZE); + + /* read the PNG image information */ + png_read_info(png_ptr, info_ptr); + png_get_IHDR(png_ptr, info_ptr, + &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); + + channels = png_get_channels(png_ptr, info_ptr); + stride = width * bit_depth * channels / 8; + + pixel_data = (png_bytep) g_malloc0(stride * height); + if (pixel_data == NULL) { + ERR("could not allocate data buffer for pixels\n"); + + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + png_destroy_info_struct(png_ptr, &info_ptr); + fclose(fp); + return NULL; + } + + row_ptr_data = (png_bytepp) g_malloc0(sizeof(png_bytep) * height); + if (row_ptr_data == NULL) { + ERR("could not allocate data buffer for row_ptr\n"); + + g_free(pixel_data); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + png_destroy_info_struct(png_ptr, &info_ptr); + fclose(fp); + return NULL; + } + + switch(color_type) { + case PNG_COLOR_TYPE_PALETTE : + png_set_palette_to_rgb(png_ptr); + break; + case PNG_COLOR_TYPE_RGB : + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { + /* transparency data for image */ + png_set_tRNS_to_alpha(png_ptr); + } else { + png_set_filter(png_ptr, 0xff, PNG_FILLER_AFTER); + } + break; + case PNG_COLOR_TYPE_RGB_ALPHA : + break; + default : + INFO("png file has an unsupported color type\n"); + break; + } + + for (i = 0; i < height; i++) { + row_ptr_data[i] = pixel_data + (stride * i); + } + + /* read the entire image into memory */ + png_read_image(png_ptr, row_ptr_data); + + /* image information */ + INFO("=== png image file was loaded ===============\n"); + INFO("file path : %s\n", file_name); + INFO("width : %d, height : %d, stride : %d\n", + width, height, stride); + INFO("color type : %d, channels : %d, bit depth : %d\n", + color_type, channels, bit_depth); + INFO("================================================\n"); + + if (width_out != NULL) { + *width_out = (unsigned int) width; + } + if (height_out != NULL) { + *height_out = (unsigned int) height; + } + + g_free(row_ptr_data); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + png_destroy_info_struct(png_ptr, &info_ptr); + fclose(fp); + + return pixel_data; +} diff --git a/tizen/src/display/maru_display_processing.h b/tizen/src/display/maru_display_processing.h new file mode 100644 index 0000000000..f66b859a9b --- /dev/null +++ b/tizen/src/display/maru_display_processing.h @@ -0,0 +1,41 @@ +/* + * Image Processing + * + * Copyright (C) 2011 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * SangHo Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + + +#ifndef MARU_DISPLAY_PROCESSING_H_ +#define MARU_DISPLAY_PROCESSING_H_ + +#include +#include "ui/qemu-pixman.h" + +void composite_brightness_image(pixman_image_t *dst); + +png_bytep read_png_file(const char *file_name, + unsigned int *width_out, unsigned int *height_out); + +#endif /* MARU_DISPLAY_PROCESSING_H_ */ diff --git a/tizen/src/display/maru_sdl.c b/tizen/src/display/maru_sdl.c index eb13dc726e..831b311ef2 100644 --- a/tizen/src/display/maru_sdl.c +++ b/tizen/src/display/maru_sdl.c @@ -34,6 +34,7 @@ #include "emulator.h" #include "emul_state.h" #include "maru_display.h" +#include "maru_display_processing.h" #include "maru_sdl_processing.h" #include "hw/pci/maru_brightness.h" #include "debug_ch.h" @@ -304,7 +305,7 @@ static void qemu_update(void) } if (surface_qemu != NULL) { - maru_do_pixman_dpy_surface(dpy_surface->image); + composite_brightness_image(dpy_surface->image); save_screenshot(dpy_surface); @@ -654,7 +655,7 @@ bool maru_extract_framebuffer(void *buffer) return false; } - maru_do_pixman_dpy_surface(dpy_surface->image); + composite_brightness_image(dpy_surface->image); buffer_size = surface_stride(dpy_surface) * surface_height(dpy_surface); TRACE("extract framebuffer %d\n", buffer_size); diff --git a/tizen/src/display/maru_sdl_processing.c b/tizen/src/display/maru_sdl_processing.c index dbe2a15efe..9ca0ba3f3f 100644 --- a/tizen/src/display/maru_sdl_processing.c +++ b/tizen/src/display/maru_sdl_processing.c @@ -30,25 +30,11 @@ #include "maru_sdl_processing.h" -#include "hw/pci/maru_brightness.h" #include "debug_ch.h" MULTI_DEBUG_CHANNEL(tizen, sdl_op); -/* Image processing functions using the pixman library */ -void maru_do_pixman_dpy_surface(pixman_image_t *dst_image) -{ - /* apply the brightness level */ - if (brightness_level < BRIGHTNESS_MAX) { - pixman_image_composite(PIXMAN_OP_OVER, - brightness_image, NULL, dst_image, - 0, 0, 0, 0, 0, 0, - pixman_image_get_width(dst_image), - pixman_image_get_height(dst_image)); - } -} - SDL_Surface *maru_do_pixman_scale(SDL_Surface *rz_src, SDL_Surface *rz_dst, pixman_filter_t filter) @@ -145,156 +131,6 @@ SDL_Surface *maru_do_pixman_rotate(SDL_Surface *rz_src, return rz_dst; } -png_bytep read_png_file(const char *file_name, - unsigned int *width_out, unsigned int *height_out) -{ -#define PNG_HEADER_SIZE 8 - - FILE *fp = NULL; - png_byte header[PNG_HEADER_SIZE] = { 0, }; - png_structp png_ptr = NULL; - - png_infop info_ptr = NULL; - png_uint_32 width = 0; - png_uint_32 height = 0; - png_byte channels = 0; - unsigned int stride = 0; - int bit_depth = 0; - int color_type = 0; - int i = 0; - - png_bytep pixel_data = NULL; - png_bytepp row_ptr_data = NULL; - - if (file_name == NULL) { - ERR("file name is empty\n"); - return NULL; - } - - fp = fopen(file_name, "rb"); - if (fp == NULL) { - ERR("file %s could not be opened\n", file_name); - return NULL; - } - - if (fread(header, sizeof(png_byte), PNG_HEADER_SIZE, fp) != PNG_HEADER_SIZE) { - ERR("failed to read header from png file\n"); - fclose(fp); - return NULL; - } - - if (png_sig_cmp(header, 0, PNG_HEADER_SIZE) != 0) { - ERR("file %s is not recognized as a PNG image\n", file_name); - fclose(fp); - return NULL; - } - - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (png_ptr == NULL) { - ERR("failed to allocate png read struct\n"); - fclose(fp); - return NULL; - } - - info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) { - ERR("failed to allocate png info struct\n"); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - fclose(fp); - return NULL; - } - - if (setjmp(png_jmpbuf(png_ptr)) != 0) { - ERR("error during init_io\n"); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - png_destroy_info_struct(png_ptr, &info_ptr); - fclose(fp); - return NULL; - } - - png_init_io(png_ptr, fp); - png_set_sig_bytes(png_ptr, PNG_HEADER_SIZE); - - /* read the PNG image information */ - png_read_info(png_ptr, info_ptr); - png_get_IHDR(png_ptr, info_ptr, - &width, &height, &bit_depth, &color_type, - NULL, NULL, NULL); - - channels = png_get_channels(png_ptr, info_ptr); - stride = width * bit_depth * channels / 8; - - pixel_data = (png_bytep) g_malloc0(stride * height); - if (pixel_data == NULL) { - ERR("could not allocate data buffer for pixels\n"); - - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - png_destroy_info_struct(png_ptr, &info_ptr); - fclose(fp); - return NULL; - } - - row_ptr_data = (png_bytepp) g_malloc0(sizeof(png_bytep) * height); - if (row_ptr_data == NULL) { - ERR("could not allocate data buffer for row_ptr\n"); - - g_free(pixel_data); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - png_destroy_info_struct(png_ptr, &info_ptr); - fclose(fp); - return NULL; - } - - switch(color_type) { - case PNG_COLOR_TYPE_PALETTE : - png_set_palette_to_rgb(png_ptr); - break; - case PNG_COLOR_TYPE_RGB : - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { - /* transparency data for image */ - png_set_tRNS_to_alpha(png_ptr); - } else { - png_set_filter(png_ptr, 0xff, PNG_FILLER_AFTER); - } - break; - case PNG_COLOR_TYPE_RGB_ALPHA : - break; - default : - INFO("png file has an unsupported color type\n"); - break; - } - - for (i = 0; i < height; i++) { - row_ptr_data[i] = pixel_data + (stride * i); - } - - /* read the entire image into memory */ - png_read_image(png_ptr, row_ptr_data); - - /* image information */ - INFO("=== blank guide image was loaded ===============\n"); - INFO("file path : %s\n", file_name); - INFO("width : %d, height : %d, stride : %d\n", - width, height, stride); - INFO("color type : %d, channels : %d, bit depth : %d\n", - color_type, channels, bit_depth); - INFO("================================================\n"); - - if (width_out != NULL) { - *width_out = (unsigned int) width; - } - if (height_out != NULL) { - *height_out = (unsigned int) height; - } - - g_free(row_ptr_data); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - png_destroy_info_struct(png_ptr, &info_ptr); - fclose(fp); - - return pixel_data; -} - void draw_image(SDL_Surface *screen, SDL_Surface *image) { if (screen == NULL || image == NULL) { diff --git a/tizen/src/display/maru_sdl_processing.h b/tizen/src/display/maru_sdl_processing.h index ad7d32095a..51fbbddc74 100644 --- a/tizen/src/display/maru_sdl_processing.h +++ b/tizen/src/display/maru_sdl_processing.h @@ -33,15 +33,11 @@ #define MARU_SDL_PROCESSING_H_ #include -#include #include "ui/console.h" -void maru_do_pixman_dpy_surface(pixman_image_t *dst); SDL_Surface *maru_do_pixman_scale(SDL_Surface *src, SDL_Surface *dst, pixman_filter_t filter); SDL_Surface *maru_do_pixman_rotate(SDL_Surface *src, SDL_Surface *dst, int angle); -png_bytep read_png_file(const char *file_name, - unsigned int *width_out, unsigned int *height_out); void draw_image(SDL_Surface *screen, SDL_Surface *image); #endif /* MARU_SDL_PROCESSING_H_ */ diff --git a/tizen/src/display/maru_shm.c b/tizen/src/display/maru_shm.c index 226e8888e6..2b0079481e 100644 --- a/tizen/src/display/maru_shm.c +++ b/tizen/src/display/maru_shm.c @@ -32,9 +32,11 @@ #include #include +#include #include "qemu/main-loop.h" #include "maru_display.h" #include "emul_state.h" +#include "maru_display_processing.h" #include "hw/pci/maru_brightness.h" #include "skin/maruskin_server.h" #include "util/maru_err_table.h" @@ -67,19 +69,6 @@ static unsigned int draw_frame; static unsigned int drop_frame; #endif -/* Image processing functions using the pixman library */ -static void maru_do_pixman_dpy_surface(pixman_image_t *dst_image) -{ - /* apply the brightness level */ - if (brightness_level < BRIGHTNESS_MAX) { - pixman_image_composite(PIXMAN_OP_OVER, - brightness_image, NULL, dst_image, - 0, 0, 0, 0, 0, 0, - pixman_image_get_width(dst_image), - pixman_image_get_height(dst_image)); - } -} - static void qemu_ds_shm_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { @@ -92,7 +81,7 @@ static void qemu_ds_shm_update(DisplayChangeListener *dcl, qemu_mutex_unlock(&mutex_draw_display); if (is_fit_console_size == true) { - maru_do_pixman_dpy_surface(dpy_surface->image); + composite_brightness_image(dpy_surface->image); save_screenshot(dpy_surface); @@ -323,7 +312,7 @@ bool maru_extract_framebuffer(void *buffer) return false; } - maru_do_pixman_dpy_surface(dpy_surface->image); + composite_brightness_image(dpy_surface->image); buffer_size = surface_stride(dpy_surface) * surface_height(dpy_surface); TRACE("extract framebuffer %d\n", buffer_size); -- 2.34.1