-obj-y += maru_display.o
+obj-y += maru_display.o maru_display_processing.o
obj-$(CONFIG_USE_SHM) += maru_shm.o
*/
+#include <png.h>
#include "emulator.h"
#include "maru_display.h"
+#include "maru_display_processing.h"
#include "debug_ch.h"
MULTI_DEBUG_CHANNEL(tizen, display);
--- /dev/null
+/*
+ * Image Processing
+ *
+ * Copyright (C) 2011 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SangHo Park <sangho1206.park@samsung.com>
+ *
+ * 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;
+}
--- /dev/null
+/*
+ * Image Processing
+ *
+ * Copyright (C) 2011 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SangHo Park <sangho1206.park@samsung.com>
+ *
+ * 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 <png.h>
+#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_ */
#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"
}
if (surface_qemu != NULL) {
- maru_do_pixman_dpy_surface(dpy_surface->image);
+ composite_brightness_image(dpy_surface->image);
save_screenshot(dpy_surface);
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);
#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)
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) {
#define MARU_SDL_PROCESSING_H_
#include <SDL.h>
-#include <png.h>
#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_ */
#include <sys/ipc.h>
#include <sys/shm.h>
+#include <png.h>
#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"
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)
{
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);
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);