From 834089eec2b11aadb9bffc99846df329f85d6a0b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 8 Sep 2014 19:28:10 +0200 Subject: [PATCH] Style nits --- gfx/d3d9/d3d.cpp | 201 ++++++++++++++++++++++++++-------------- gfx/psp/psp1_gfx.c | 195 ++++++++++++++++++++++++-------------- gfx/psp/psp1_gfx.h | 14 +-- gfx/rpng/rpng.c | 145 ++++++++++++++++++----------- gfx/rpng/rpng.h | 3 +- gfx/rpng/rpng_test.c | 12 ++- gfx/scaler/pixconv.c | 174 +++++++++++++++++++++------------- gfx/scaler/scaler.c | 63 ++++++++----- gfx/scaler/scaler_int.h | 7 +- 9 files changed, 522 insertions(+), 292 deletions(-) diff --git a/gfx/d3d9/d3d.cpp b/gfx/d3d9/d3d.cpp index 9f14ae1427..48b94d3118 100644 --- a/gfx/d3d9/d3d.cpp +++ b/gfx/d3d9/d3d.cpp @@ -31,9 +31,10 @@ #define HAVE_SHADERS #endif -//forward decls +/* forward decls */ static bool d3d_init_luts(d3d_video_t *d3d); -static void d3d_set_font_rect(d3d_video_t *d3d, const struct font_params *params); +static void d3d_set_font_rect(d3d_video_t *d3d, + const struct font_params *params); static bool d3d_process_shader(d3d_video_t *d3d); static bool d3d_init_multipass(d3d_video_t *d3d); static void d3d_deinit_chain(d3d_video_t *d3d); @@ -49,7 +50,8 @@ namespace Monitor static unsigned num_mons; } -static BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) +static BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, + HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { Monitor::all_hms[Monitor::num_mons++] = hMonitor; return TRUE; @@ -62,11 +64,13 @@ static RECT d3d_monitor_rect(d3d_video_t *d3d) EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0); if (!Monitor::last_hm) - Monitor::last_hm = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST); + Monitor::last_hm = MonitorFromWindow( + GetDesktopWindow(), MONITOR_DEFAULTTONEAREST); HMONITOR hm_to_use = Monitor::last_hm; unsigned fs_monitor = g_settings.video.monitor_index; - if (fs_monitor && fs_monitor <= Monitor::num_mons && Monitor::all_hms[fs_monitor - 1]) + if (fs_monitor && fs_monitor <= Monitor::num_mons + && Monitor::all_hms[fs_monitor - 1]) { hm_to_use = Monitor::all_hms[fs_monitor - 1]; d3d->cur_mon_id = fs_monitor - 1; @@ -96,14 +100,16 @@ static void d3d_recompute_pass_sizes(d3d_video_t *d3d) { LinkInfo link_info = {0}; link_info.pass = &d3d->shader.pass[0]; - link_info.tex_w = link_info.tex_h = d3d->video_info.input_scale * RARCH_SCALE_BASE; + link_info.tex_w = link_info.tex_h = + d3d->video_info.input_scale * RARCH_SCALE_BASE; unsigned current_width = link_info.tex_w; unsigned current_height = link_info.tex_h; unsigned out_width = 0; unsigned out_height = 0; - if (!renderchain_set_pass_size(d3d->chain, 0, current_width, current_height)) + if (!renderchain_set_pass_size(d3d->chain, 0, + current_width, current_height)) { RARCH_ERR("[D3D]: Failed to set pass size.\n"); return; @@ -118,7 +124,8 @@ static void d3d_recompute_pass_sizes(d3d_video_t *d3d) link_info.tex_w = next_pow2(out_width); link_info.tex_h = next_pow2(out_height); - if (!renderchain_set_pass_size(d3d->chain, i, link_info.tex_w, link_info.tex_h)) + if (!renderchain_set_pass_size(d3d->chain, i, + link_info.tex_w, link_info.tex_h)) { RARCH_ERR("[D3D]: Failed to set pass size.\n"); return; @@ -139,7 +146,8 @@ static bool d3d_init_imports(d3d_video_t *d3d) state_tracker_info tracker_info = {0}; - tracker_info.wram = (uint8_t*)pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM); + tracker_info.wram = (uint8_t*) + pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM); tracker_info.info = d3d->shader.variable; tracker_info.info_elem = d3d->shader.variables; @@ -150,7 +158,8 @@ static bool d3d_init_imports(d3d_video_t *d3d) tracker_info.script_is_file = true; } - tracker_info.script_class = *d3d->shader.script_class ? d3d->shader.script_class : NULL; + tracker_info.script_class = + *d3d->shader.script_class ? d3d->shader.script_class : NULL; #endif state_tracker_t *state_tracker = state_tracker_init(&tracker_info); @@ -168,18 +177,20 @@ static bool d3d_init_imports(d3d_video_t *d3d) static bool d3d_init_chain(d3d_video_t *d3d, const video_info_t *video_info) { LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; - // Setup information for first pass. + /* Setup information for first pass. */ LinkInfo link_info = {0}; link_info.pass = &d3d->shader.pass[0]; - link_info.tex_w = link_info.tex_h = video_info->input_scale * RARCH_SCALE_BASE; + link_info.tex_w = link_info.tex_h = + video_info->input_scale * RARCH_SCALE_BASE; d3d_deinit_chain(d3d); d3d->chain = new renderchain_t(); if (!d3d->chain) return false; - if (!renderchain_init(d3d->chain, &d3d->video_info, d3dr, d3d->cgCtx, &d3d->final_viewport, &link_info, + if (!renderchain_init(d3d->chain, &d3d->video_info, d3dr, + d3d->cgCtx, &d3d->final_viewport, &link_info, d3d->video_info.rgb32 ? ARGB : RGB565)) { RARCH_ERR("[D3D9]: Failed to init render chain.\n"); @@ -257,12 +268,16 @@ static bool d3d_init_multipass(d3d_video_t *d3d) { if (!d3d->shader.pass[i].fbo.valid) { - d3d->shader.pass[i].fbo.scale_x = d3d->shader.pass[i].fbo.scale_y = 1.0f; - d3d->shader.pass[i].fbo.type_x = d3d->shader.pass[i].fbo.type_y = RARCH_SCALE_INPUT; + d3d->shader.pass[i].fbo.scale_x = + d3d->shader.pass[i].fbo.scale_y = 1.0f; + d3d->shader.pass[i].fbo.type_x = + d3d->shader.pass[i].fbo.type_y = RARCH_SCALE_INPUT; } } - bool use_extra_pass = d3d->shader.passes < GFX_MAX_SHADERS && d3d->shader.pass[d3d->shader.passes - 1].fbo.valid; + bool use_extra_pass = d3d->shader.passes < GFX_MAX_SHADERS && + d3d->shader.pass[d3d->shader.passes - 1].fbo.valid; + if (use_extra_pass) { d3d->shader.passes++; @@ -282,7 +297,8 @@ static bool d3d_init_multipass(d3d_video_t *d3d) } #endif -static void d3d_set_font_rect(d3d_video_t *d3d, const struct font_params *params) +static void d3d_set_font_rect(d3d_video_t *d3d, + const struct font_params *params) { #ifndef _XBOX float pos_x = g_settings.video.msg_pos_x; @@ -296,9 +312,12 @@ static void d3d_set_font_rect(d3d_video_t *d3d, const struct font_params *params font_size *= params->scale; } - d3d->font_rect.left = d3d->final_viewport.X + d3d->final_viewport.Width * pos_x; - d3d->font_rect.right = d3d->final_viewport.X + d3d->final_viewport.Width; - d3d->font_rect.top = d3d->final_viewport.Y + (1.0f - pos_y) * d3d->final_viewport.Height - font_size; + d3d->font_rect.left = d3d->final_viewport.X + + d3d->final_viewport.Width * pos_x; + d3d->font_rect.right = d3d->final_viewport.X + + d3d->final_viewport.Width; + d3d->font_rect.top = d3d->final_viewport.Y + + (1.0f - pos_y) * d3d->final_viewport.Height - font_size; d3d->font_rect.bottom = d3d->final_viewport.Height; d3d->font_rect_shifted = d3d->font_rect; @@ -317,7 +336,8 @@ static bool d3d_init_singlepass(d3d_video_t *d3d) pass.fbo.valid = true; pass.fbo.scale_x = pass.fbo.scale_y = 1.0; pass.fbo.type_x = pass.fbo.type_y = RARCH_SCALE_VIEWPORT; - strlcpy(pass.source.path, d3d->cg_shader.c_str(), sizeof(pass.source.path)); + strlcpy(pass.source.path, d3d->cg_shader.c_str(), + sizeof(pass.source.path)); return true; } @@ -325,7 +345,8 @@ static bool d3d_init_singlepass(d3d_video_t *d3d) static bool d3d_process_shader(d3d_video_t *d3d) { #ifdef HAVE_FBO - if (strcmp(path_get_extension(d3d->cg_shader.c_str()), "cgp") == 0) + if (strcmp(path_get_extension( + d3d->cg_shader.c_str()), "cgp") == 0) return d3d_init_multipass(d3d); #endif @@ -336,7 +357,8 @@ static bool d3d_init_luts(d3d_video_t *d3d) { for (unsigned i = 0; i < d3d->shader.luts; i++) { - bool ret = renderchain_add_lut(d3d->chain, d3d->shader.lut[i].id, d3d->shader.lut[i].path, + bool ret = renderchain_add_lut( + d3d->chain, d3d->shader.lut[i].id, d3d->shader.lut[i].path, d3d->shader.lut[i].filter == RARCH_FILTER_UNSPEC ? g_settings.video.smooth : (d3d->shader.lut[i].filter == RARCH_FILTER_LINEAR)); @@ -415,8 +437,8 @@ static bool d3d_init_base(void *data, const video_info_t *info) return true; } -static void d3d_calculate_rect(d3d_video_t *d3d, unsigned width, unsigned height, - bool keep, float desired_aspect); +static void d3d_calculate_rect(d3d_video_t *d3d, unsigned width, + unsigned height, bool keep, float desired_aspect); static bool d3d_initialize(void *data, const video_info_t *info) { @@ -465,7 +487,8 @@ static bool d3d_initialize(void *data, const video_info_t *info) if (!ret) return ret; - d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height, info->force_aspect, g_extern.system.aspect_ratio); + d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height, + info->force_aspect, g_extern.system.aspect_ratio); #ifdef HAVE_SHADERS if (!d3d_init_shader(d3d)) @@ -482,9 +505,11 @@ static bool d3d_initialize(void *data, const video_info_t *info) } #if defined(_XBOX360) - strlcpy(g_settings.video.font_path, "game:\\media\\Arial_12.xpr", sizeof(g_settings.video.font_path)); + strlcpy(g_settings.video.font_path, "game:\\media\\Arial_12.xpr", + sizeof(g_settings.video.font_path)); #endif - d3d->font_ctx = d3d_font_init_first(d3d, g_settings.video.font_path, g_settings.video.font_size); + d3d->font_ctx = d3d_font_init_first(d3d, g_settings.video.font_path, + g_settings.video.font_size); if (!d3d->font_ctx) { RARCH_ERR("Failed to initialize font.\n"); @@ -513,11 +538,12 @@ bool d3d_restore(d3d_video_t *d3d) #include "d3d_overlays.cpp" #endif -static void d3d_set_viewport(d3d_video_t *d3d, int x, int y, unsigned width, unsigned height) +static void d3d_set_viewport(d3d_video_t *d3d, int x, int y, + unsigned width, unsigned height) { D3DVIEWPORT viewport; - // D3D doesn't support negative X/Y viewports ... + /* D3D doesn't support negative X/Y viewports ... */ if (x < 0) x = 0; if (y < 0) @@ -535,7 +561,8 @@ static void d3d_set_viewport(d3d_video_t *d3d, int x, int y, unsigned width, uns d3d_set_font_rect(d3d, NULL); } -static void d3d_calculate_rect(d3d_video_t *d3d, unsigned width, unsigned height, +static void d3d_calculate_rect(d3d_video_t *d3d, + unsigned width, unsigned height, bool keep, float desired_aspect) { if (g_settings.video.scale_integer) @@ -550,23 +577,29 @@ static void d3d_calculate_rect(d3d_video_t *d3d, unsigned width, unsigned height { if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { - const rarch_viewport_t &custom = g_extern.console.screen.viewports.custom_vp; - d3d_set_viewport(d3d, custom.x, custom.y, custom.width, custom.height); + const rarch_viewport_t &custom = + g_extern.console.screen.viewports.custom_vp; + d3d_set_viewport(d3d, custom.x, custom.y, + custom.width, custom.height); } else { - float device_aspect = static_cast(width) / static_cast(height); + float device_aspect = static_cast(width) / + static_cast(height); + if (fabsf(device_aspect - desired_aspect) < 0.0001f) d3d_set_viewport(d3d, 0, 0, width, height); else if (device_aspect > desired_aspect) { float delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f; - d3d_set_viewport(d3d, int(roundf(width * (0.5f - delta))), 0, unsigned(roundf(2.0f * width * delta)), height); + d3d_set_viewport(d3d, int(roundf(width * (0.5f - delta))), + 0, unsigned(roundf(2.0f * width * delta)), height); } else { float delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f; - d3d_set_viewport(d3d, 0, int(roundf(height * (0.5f - delta))), width, unsigned(roundf(2.0f * height * delta))); + d3d_set_viewport(d3d, 0, int(roundf(height * (0.5f - delta))), + width, unsigned(roundf(2.0f * height * delta))); } } } @@ -587,7 +620,7 @@ static bool d3d_frame(void *data, const void *frame, RARCH_PERFORMANCE_START(d3d_frame); #ifndef _XBOX - // We cannot recover in fullscreen. + /* We cannot recover in fullscreen. */ if (d3d->needs_restore && IsIconic(d3d->hWnd)) return true; #endif @@ -599,14 +632,17 @@ static bool d3d_frame(void *data, const void *frame, if (d3d->should_resize) { - d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height, d3d->video_info.force_aspect, g_extern.system.aspect_ratio); + d3d_calculate_rect(d3d, d3d->screen_width, + d3d->screen_height, d3d->video_info.force_aspect, + g_extern.system.aspect_ratio); + renderchain_set_final_viewport(d3d->chain, &d3d->final_viewport); d3d_recompute_pass_sizes(d3d); d3d->should_resize = false; } - // render_chain() only clears out viewport, clear out everything. + /* render_chain() only clears out viewport, clear out everything. */ screen_vp.X = 0; screen_vp.Y = 0; screen_vp.MinZ = 0; @@ -625,7 +661,8 @@ static bool d3d_frame(void *data, const void *frame, d3dr->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0); } - if (!renderchain_render(d3d->chain, frame, width, height, pitch, d3d->dev_rotation)) + if (!renderchain_render(d3d->chain, frame, width, + height, pitch, d3d->dev_rotation)) { RARCH_ERR("[D3D]: Failed to render scene.\n"); return false; @@ -663,7 +700,8 @@ static bool d3d_frame(void *data, const void *frame, #endif #ifdef HAVE_MENU - if (g_extern.lifecycle_state & (1ULL << MODE_MENU) && driver.menu_ctx && driver.menu_ctx->frame) + if (g_extern.lifecycle_state & (1ULL << MODE_MENU) + && driver.menu_ctx && driver.menu_ctx->frame) driver.menu_ctx->frame(); #endif @@ -737,7 +775,8 @@ static void d3d_free(void *data) d3d->g_pD3D->Release(); #ifdef HAVE_MONITOR - Monitor::last_hm = MonitorFromWindow(d3d->hWnd, MONITOR_DEFAULTTONEAREST); + Monitor::last_hm = MonitorFromWindow(d3d->hWnd, + MONITOR_DEFAULTTONEAREST); DestroyWindow(d3d->hWnd); #endif @@ -779,10 +818,11 @@ static bool d3d_read_viewport(void *data, uint8_t *buffer) goto end; } - if (FAILED(d3d->d3d_err = d3dr->CreateOffscreenPlainSurface(d3d->screen_width, - d3d->screen_height, - D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, - &dest, NULL))) + if (FAILED(d3d->d3d_err = d3dr->CreateOffscreenPlainSurface( + d3d->screen_width, + d3d->screen_height, + D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, + &dest, NULL))) { ret = false; goto end; @@ -803,7 +843,8 @@ static bool d3d_read_viewport(void *data, uint8_t *buffer) pixels += (d3d->final_viewport.Height - 1) * pitchpix; pixels -= d3d->final_viewport.Y * pitchpix; - for (unsigned y = 0; y < d3d->final_viewport.Height; y++, pixels -= pitchpix) + for (unsigned y = 0; y < d3d->final_viewport.Height; + y++, pixels -= pitchpix) { for (unsigned x = 0; x < d3d->final_viewport.Width; x++) { @@ -827,7 +868,8 @@ end: return ret; } -static bool d3d_set_shader(void *data, enum rarch_shader_type type, const char *path) +static bool d3d_set_shader(void *data, + enum rarch_shader_type type, const char *path) { d3d_video_t *d3d = (d3d_video_t*)data; std::string shader = ""; @@ -855,7 +897,8 @@ static bool d3d_set_shader(void *data, enum rarch_shader_type type, const char * } #ifdef HAVE_MENU -static void d3d_get_poke_interface(void *data, const video_poke_interface_t **iface); +static void d3d_get_poke_interface(void *data, + const video_poke_interface_t **iface); #endif static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) @@ -865,7 +908,9 @@ static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width, g_extern.system.av_info.geometry.base_height); + gfx_set_square_pixel_viewport( + g_extern.system.av_info.geometry.base_width, + g_extern.system.av_info.geometry.base_height); break; case ASPECT_RATIO_CORE: @@ -891,7 +936,8 @@ static void d3d_apply_state_changes(void *data) d3d->should_resize = true; } -static void d3d_set_osd_msg(void *data, const char *msg, const struct font_params *params) +static void d3d_set_osd_msg(void *data, const char *msg, + const struct font_params *params) { d3d_video_t *d3d = (d3d_video_t*)data; @@ -917,7 +963,8 @@ static void d3d_set_menu_texture_frame(void *data, { d3d_video_t *d3d = (d3d_video_t*)data; - if (!d3d->menu->tex || d3d->menu->tex_w != width || d3d->menu->tex_h != height) + if (!d3d->menu->tex || d3d->menu->tex_w != width + || d3d->menu->tex_h != height) { if (d3d->menu && d3d->menu->tex) d3d->menu->tex->Release(); @@ -943,17 +990,20 @@ static void d3d_set_menu_texture_frame(void *data, { uint8_t *dst = (uint8_t*)d3dlr.pBits; const uint32_t *src = (const uint32_t*)frame; - for (unsigned h = 0; h < height; h++, dst += d3dlr.Pitch, src += width) + for (unsigned h = 0; h < height; + h++, dst += d3dlr.Pitch, src += width) { memcpy(dst, src, width * sizeof(uint32_t)); - memset(dst + width * sizeof(uint32_t), 0, d3dlr.Pitch - width * sizeof(uint32_t)); + memset(dst + width * sizeof(uint32_t), 0, + d3dlr.Pitch - width * sizeof(uint32_t)); } } else { uint32_t *dst = (uint32_t*)d3dlr.pBits; const uint16_t *src = (const uint16_t*)frame; - for (unsigned h = 0; h < height; h++, dst += d3dlr.Pitch >> 2, src += width) + for (unsigned h = 0; h < height; + h++, dst += d3dlr.Pitch >> 2, src += width) { for (unsigned w = 0; w < width; w++) { @@ -976,7 +1026,8 @@ static void d3d_set_menu_texture_frame(void *data, } } -static void d3d_set_menu_texture_enable(void *data, bool state, bool full_screen) +static void d3d_set_menu_texture_enable(void *data, + bool state, bool full_screen) { d3d_video_t *d3d = (d3d_video_t*)data; @@ -1005,14 +1056,17 @@ static const video_poke_interface_t d3d_poke_interface = { d3d_show_mouse, }; -static void d3d_get_poke_interface(void *data, const video_poke_interface_t **iface) +static void d3d_get_poke_interface(void *data, + const video_poke_interface_t **iface) { (void)data; *iface = &d3d_poke_interface; } -// Delay constructor due to lack of exceptions. -static bool d3d_construct(d3d_video_t *d3d, const video_info_t *info, const input_driver_t **input, +/* Delay constructor due to lack of exceptions. */ + +static bool d3d_construct(d3d_video_t *d3d, + const video_info_t *info, const input_driver_t **input, void **input_data) { d3d->should_resize = false; @@ -1043,8 +1097,10 @@ static bool d3d_construct(d3d_video_t *d3d, const video_info_t *info, const inpu d3d->windowClass.hInstance = NULL; d3d->windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); d3d->windowClass.lpszClassName = "RetroArch"; - d3d->windowClass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON)); - d3d->windowClass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0); + d3d->windowClass.hIcon = LoadIcon(GetModuleHandle(NULL), + MAKEINTRESOURCE(IDI_ICON)); + d3d->windowClass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), + MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0); if (!info->fullscreen) d3d->windowClass.hbrBackground = (HBRUSH)COLOR_WINDOW; @@ -1057,9 +1113,13 @@ static bool d3d_construct(d3d_video_t *d3d, const video_info_t *info, const inpu bool windowed_full = g_settings.video.windowed_fullscreen; - full_x = (windowed_full || info->width == 0) ? (mon_rect.right - mon_rect.left) : info->width; - full_y = (windowed_full || info->height == 0) ? (mon_rect.bottom - mon_rect.top) : info->height; - RARCH_LOG("[D3D]: Monitor size: %dx%d.\n", (int)(mon_rect.right - mon_rect.left), (int)(mon_rect.bottom - mon_rect.top)); + full_x = (windowed_full || info->width == 0) ? + (mon_rect.right - mon_rect.left) : info->width; + full_y = (windowed_full || info->height == 0) ? + (mon_rect.bottom - mon_rect.top) : info->height; + RARCH_LOG("[D3D]: Monitor size: %dx%d.\n", + (int)(mon_rect.right - mon_rect.left), + (int)(mon_rect.bottom - mon_rect.top)); #else if (d3d->ctx_driver && d3d->ctx_driver->get_video_size) d3d->ctx_driver->get_video_size(&full_x, &full_y); @@ -1114,10 +1174,11 @@ static bool d3d_construct(d3d_video_t *d3d, const video_info_t *info, const inpu #endif #ifdef HAVE_SHADERS - // This should only be done once here - // to avoid set_shader() to be overridden - // later. - enum rarch_shader_type type = gfx_shader_parse_type(g_settings.video.shader_path, RARCH_SHADER_NONE); + /* This should only be done once here + * to avoid set_shader() to be overridden + * later. */ + enum rarch_shader_type type = + gfx_shader_parse_type(g_settings.video.shader_path, RARCH_SHADER_NONE); if (g_settings.video.shader_enable && type == RARCH_SHADER_CG) d3d->cg_shader = g_settings.video.shader_path; @@ -1139,7 +1200,7 @@ static bool d3d_construct(d3d_video_t *d3d, const video_info_t *info, const inpu static const gfx_ctx_driver_t *d3d_get_context(void) { - // TODO: GL core contexts through ANGLE? + /* TODO: GL core contexts through ANGLE? */ enum gfx_ctx_api api; unsigned major, minor; #if defined(_XBOX1) @@ -1167,7 +1228,7 @@ static void *d3d_init(const video_info_t *info, const input_driver_t **input, return NULL; } - //default values + /* default values */ vid->g_pD3D = NULL; vid->dev = NULL; #ifndef _XBOX diff --git a/gfx/psp/psp1_gfx.c b/gfx/psp/psp1_gfx.c index 352277263f..9e22be96d5 100644 --- a/gfx/psp/psp1_gfx.c +++ b/gfx/psp/psp1_gfx.c @@ -117,7 +117,8 @@ typedef struct psp1_video #define PSP_FRAME_SLICE_COUNT (PSP_FRAME_ROWS_COUNT * PSP_FRAME_COLUMNS_COUNT) #define PSP_FRAME_VERTEX_COUNT (PSP_FRAME_SLICE_COUNT * 2) -static inline void psp_set_screen_coords (psp1_sprite_t* framecoords, int x, int y, int width, int height) +static inline void psp_set_screen_coords (psp1_sprite_t* framecoords, + int x, int y, int width, int height) { int i; int current_column = 0; @@ -146,7 +147,8 @@ static inline void psp_set_screen_coords (psp1_sprite_t* framecoords, int x, int } } -static inline void psp_set_tex_coords (psp1_sprite_t* framecoords, int width, int height) +static inline void psp_set_tex_coords (psp1_sprite_t* framecoords, + int width, int height) { int i; int current_column = 0; @@ -183,7 +185,8 @@ static void psp_on_vblank(u32 sub, psp1_video_t *psp) static void *psp_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - // to-do : add ASSERT() checks or use main RAM if VRAM is too low for desired video->input_scale + /* to-do : add ASSERT() checks or use main RAM if + * VRAM is too low for desired video->input_scale. */ void *pspinput; int pixel_format, lut_pixel_format, lut_block_count; unsigned int red_shift, color_mask; @@ -202,22 +205,32 @@ static void *psp_init(const video_info_t *video, psp->vp.full_width = SCEGU_SCR_WIDTH; psp->vp.full_height = SCEGU_SCR_HEIGHT; - // make sure anything using uncached pointers reserves whole cachelines (memory address and size need to be a multiple of 64) - // so it isn't overwritten by an unlucky cache writeback. - // this includes display lists since the Gu library uses unchached pointers to write to them. + /* Make sure anything using uncached pointers reserves + * whole cachelines (memory address and size need to be a multiple of 64) + * so it isn't overwritten by an unlucky cache writeback. + * + * This includes display lists since the Gu library uses + * uncached pointers to write to them. */ + + /* Allocate more space if bigger display lists are needed. */ + psp->main_dList = memalign(64, 256); - psp->main_dList = memalign(64, 256); // allocate more space if bigger display lists are needed. psp->frame_dList = memalign(64, 256); psp->menu.dList = memalign(64, 256); psp->menu.frame = memalign(16, 2 * 480 * 272); - psp->frame_coords = memalign(64, (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63)); - psp->menu.frame_coords = memalign(64, (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63)); + psp->frame_coords = memalign(64, + (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63)); + psp->menu.frame_coords = memalign(64, + (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63)); + + memset(psp->frame_coords, 0, + PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)); + memset(psp->menu.frame_coords, 0, + PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)); - memset(psp->frame_coords , 0, PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)); - memset(psp->menu.frame_coords , 0, PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)); sceKernelDcacheWritebackInvalidateAll(); psp->frame_coords = TO_UNCACHED_PTR(psp->frame_coords); - psp->menu.frame_coords = TO_UNCACHED_PTR(psp->menu.frame_coords);; + psp->menu.frame_coords = TO_UNCACHED_PTR(psp->menu.frame_coords); psp->frame_coords->v0.x = 60; psp->frame_coords->v0.y = 0; @@ -272,12 +285,16 @@ static void *psp_init(const video_info_t *video, psp->draw_buffer = SCEGU_VRAM_BP_0; psp->bpp_log2 = 1; - pixel_format = (g_extern.system.pix_fmt == RETRO_PIXEL_FORMAT_0RGB1555)? GU_PSM_5551 : GU_PSM_5650 ; + pixel_format = + (g_extern.system.pix_fmt == RETRO_PIXEL_FORMAT_0RGB1555) + ? GU_PSM_5551 : GU_PSM_5650 ; + lut_pixel_format = GU_PSM_T16; displayBuffer = SCEGU_VRAM_BP_1; - for (u16 i = 0; i < (1 << 5); i++){ + for (u16 i = 0; i < (1 << 5); i++) + { LUT_r_local[i]= i; LUT_b_local[i]= i << (5 + 6); } @@ -289,13 +306,17 @@ static void *psp_init(const video_info_t *video, psp->tex_filter = video->smooth? GU_LINEAR : GU_NEAREST; - sceDisplayWaitVblankStart(); // TODO : check if necessary + /* TODO: check if necessary. */ + sceDisplayWaitVblankStart(); + sceGuDisplay(GU_FALSE); sceGuStart(GU_DIRECT, psp->main_dList); - sceGuDrawBuffer(pixel_format, TO_GU_POINTER(psp->draw_buffer), SCEGU_VRAM_WIDTH); - sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH); + sceGuDrawBuffer(pixel_format, TO_GU_POINTER(psp->draw_buffer), + SCEGU_VRAM_WIDTH); + sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, + TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH); sceGuClearColor(0); sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); @@ -307,35 +328,45 @@ static void *psp_init(const video_info_t *video, sceGuFinish(); sceGuSync(0, 0); - - sceDisplayWaitVblankStart(); // TODO : check if necessary + + /* TODO : check if necessary */ + sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); pspDebugScreenSetColorMode(pixel_format); pspDebugScreenSetBase(psp->draw_buffer); - // fill frame_dList : - + /* fill frame_dList : */ sceGuStart(GU_CALL, psp->frame_dList); sceGuTexMode(pixel_format, 0, 0, GU_FALSE); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuEnable(GU_BLEND); - sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF); // green only - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); - sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF); // restore + /* green only */ + sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF); + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(psp->frame_coords)); + + /* restore */ + sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF); sceGuTexMode(lut_pixel_format, 0, 0, GU_FALSE); sceGuClutMode(pixel_format, red_shift, color_mask, 0); sceGuClutLoad(lut_block_count, LUT_r); - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(psp->frame_coords)); sceGuClutMode(pixel_format, 0, color_mask, 0); sceGuClutLoad(lut_block_count, LUT_b); - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(psp->frame_coords)); sceGuFinish(); @@ -383,7 +414,7 @@ static bool psp_frame(void *data, const void *frame, psp->hw_render = false; if (!psp->hw_render) - sceGuSync(0, 0); // let the core decide when to sync when HW_RENDER + sceGuSync(0, 0); /* let the core decide when to sync when HW_RENDER */ pspDebugScreenSetBase(psp->draw_buffer); @@ -439,14 +470,20 @@ static bool psp_frame(void *data, const void *frame, sceGuTexFilter(psp->tex_filter, psp->tex_filter); sceGuClear(GU_COLOR_BUFFER_BIT); - if (psp->hw_render) // frame in VRAM ? texture/palette was set in core so draw directly - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); + /* frame in VRAM ? texture/palette was + * set in core so draw directly */ + if (psp->hw_render) + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(psp->frame_coords)); else { - if (frame!=NULL) + if (frame) { sceKernelDcacheWritebackRange(frame,pitch * height); - sceGuCopyImage(GU_PSM_5650, ((u32)frame & 0xF) >> psp->bpp_log2, 0, width, height, pitch >> psp->bpp_log2, (void*)((u32)frame & ~0xF), 0, 0, width, psp->texture); + sceGuCopyImage(GU_PSM_5650, ((u32)frame & 0xF) >> psp->bpp_log2, + 0, width, height, pitch >> psp->bpp_log2, + (void*)((u32)frame & ~0xF), 0, 0, width, psp->texture); } sceGuTexImage(0, next_pow2(width), next_pow2(height), width, psp->texture); sceGuCallList(psp->frame_dList); @@ -522,16 +559,19 @@ static void psp_set_texture_frame(void *data, const void *frame, bool rgb32, psp1_video_t *psp = (psp1_video_t*)data; #ifdef DEBUG - rarch_assert((width*height) < (480 * 272)); // psp->menu.frame buffer size is (480 * 272)*2 Bytes + /* psp->menu.frame buffer size is (480 * 272)*2 Bytes */ + rarch_assert((width*height) < (480 * 272)); #endif - psp_set_screen_coords(psp->menu.frame_coords, 0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT); + psp_set_screen_coords(psp->menu.frame_coords, 0, 0, + SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT); psp_set_tex_coords(psp->menu.frame_coords, width, height); sceKernelDcacheWritebackRange(frame, width * height * 2); sceGuStart(GU_DIRECT, psp->main_dList); - sceGuCopyImage(GU_PSM_4444, 0, 0, width, height, width, (void*)frame, 0, 0, width, psp->menu.frame); + sceGuCopyImage(GU_PSM_4444, 0, 0, width, height, width, + (void*)frame, 0, 0, width, psp->menu.frame); sceGuFinish(); sceGuStart(GU_SEND, psp->menu.dList); @@ -541,10 +581,15 @@ static void psp_set_texture_frame(void *data, const void *frame, bool rgb32, sceGuTexImage(0, next_pow2(width), next_pow2(height), width, psp->menu.frame); sceGuEnable(GU_BLEND); -// sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); // default blending +#if 0 + /* default blending */ + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); +#endif sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xF0F0F0F0, 0x0F0F0F0F); ; - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, psp->menu.frame_coords); + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + psp->menu.frame_coords); sceGuFinish(); } @@ -560,35 +605,38 @@ static void psp_set_texture_enable(void *data, bool state, bool full_screen) static inline void psp_update_frame_coords(psp1_video_t* psp) { -// psp1_vertex_t *v0, *v1; + /* TODO: no rotation for now */ +#if 0 + psp1_vertex_t *v0, *v1; -// if (psp->rotation & 0x2) -// { -// v0 = &psp->frame_coords->v1; -// v1 = &psp->frame_coords->v0; -// } -// else -// { -// v0 = &psp->frame_coords->v0; -// v1 = &psp->frame_coords->v1; -// } + if (psp->rotation & 0x2) + { + v0 = &psp->frame_coords->v1; + v1 = &psp->frame_coords->v0; + } + else + { + v0 = &psp->frame_coords->v0; + v1 = &psp->frame_coords->v1; + } -// if (psp->rotation & 0x1) -// { -// v0->x = psp->vp.x + psp->vp.width; -// v1->x = psp->vp.x; -// } -// else -// { -// v0->x = psp->vp.x; -// v1->x = psp->vp.x + psp->vp.width; -// } + if (psp->rotation & 0x1) + { + v0->x = psp->vp.x + psp->vp.width; + v1->x = psp->vp.x; + } + else + { + v0->x = psp->vp.x; + v1->x = psp->vp.x + psp->vp.width; + } -// v0->y = psp->vp.y; -// v1->y = psp->vp.y + psp->vp.height; + v0->y = psp->vp.y; + v1->y = psp->vp.y + psp->vp.height; +#endif - // no rotation for now - psp_set_screen_coords(psp->frame_coords, psp->vp.x, psp->vp.y, psp->vp.width, psp->vp.height); + psp_set_screen_coords(psp->frame_coords, psp->vp.x, + psp->vp.y, psp->vp.width, psp->vp.height); } static void psp_update_viewport(psp1_video_t* psp) @@ -602,7 +650,8 @@ static void psp_update_viewport(psp1_video_t* psp) if (g_settings.video.scale_integer) { - gfx_scale_integer(&psp->vp, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, g_extern.system.aspect_ratio, psp->keep_aspect); + gfx_scale_integer(&psp->vp, SCEGU_SCR_WIDTH, + SCEGU_SCR_HEIGHT, g_extern.system.aspect_ratio, psp->keep_aspect); width = psp->vp.width; height = psp->vp.height; } @@ -625,20 +674,25 @@ static void psp_update_viewport(psp1_video_t* psp) else #endif { - if ((fabsf(device_aspect - desired_aspect) < 0.0001f)||(fabsf((16.0/9.0) - desired_aspect) < 0.0001f)) + if ((fabsf(device_aspect - desired_aspect) < 0.0001f) + || (fabsf((16.0/9.0) - desired_aspect) < 0.0001f)) { - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - // assume they are actually equal. + /* If the aspect ratios of screen and desired aspect + * ratio are sufficiently equal (floating point stuff), + * assume they are actually equal. + */ } else if (device_aspect > desired_aspect) { - delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f; + delta = (desired_aspect / device_aspect - 1.0f) + / 2.0f + 0.5f; x = (int)roundf(width * (0.5f - delta)); width = (unsigned)roundf(2.0f * width * delta); } else { - delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f; + delta = (device_aspect / desired_aspect - 1.0f) + / 2.0f + 0.5f; y = (int)roundf(height * (0.5f - delta)); height = (unsigned)roundf(2.0f * height * delta); } @@ -682,7 +736,9 @@ static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index) switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width, g_extern.system.av_info.geometry.base_height); + gfx_set_square_pixel_viewport( + g_extern.system.av_info.geometry.base_width, + g_extern.system.av_info.geometry.base_height); break; case ASPECT_RATIO_CORE: @@ -733,7 +789,8 @@ static const video_poke_interface_t psp_poke_interface = { NULL }; -static void psp_get_poke_interface(void *data, const video_poke_interface_t **iface) +static void psp_get_poke_interface(void *data, + const video_poke_interface_t **iface) { (void)data; *iface = &psp_poke_interface; diff --git a/gfx/psp/psp1_gfx.h b/gfx/psp/psp1_gfx.h index 79d8923da6..ba473d2890 100644 --- a/gfx/psp/psp1_gfx.h +++ b/gfx/psp/psp1_gfx.h @@ -62,10 +62,10 @@ typedef struct { /* row 0 */ - unsigned char enable; // Light enable - unsigned char type; // Light type - unsigned char xpos; // X position - unsigned char ypos; // Y position + unsigned char enable; /* Light enable */ + unsigned char type; /* Light type */ + unsigned char xpos; /* X position */ + unsigned char ypos; /* Y position */ /* row 1 */ @@ -107,9 +107,9 @@ extern int gu_object_stack_depth; extern GuLightSettings light_settings[4]; -static int tbpcmd_tbl[8] = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7 }; // 0x30A18 -static int tbwcmd_tbl[8] = { 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; // 0x30A38 -static int tsizecmd_tbl[8] = { 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf }; // 0x30A58 +static int tbpcmd_tbl[8] = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7 }; /* 0x30A18 */ +static int tbwcmd_tbl[8] = { 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; /* 0x30A38 */ +static int tsizecmd_tbl[8] = { 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf }; /* 0x30A58 */ #define sendCommandi(cmd, argument) *(gu_list->current++) = (cmd << 24) | (argument & 0xffffff) diff --git a/gfx/rpng/rpng.c b/gfx/rpng/rpng.c index 2c1b7afe74..cd1f87b354 100644 --- a/gfx/rpng/rpng.c +++ b/gfx/rpng/rpng.c @@ -128,17 +128,18 @@ static enum png_chunk_type png_chunk_type(const struct png_chunk *chunk) static bool png_read_chunk(FILE *file, struct png_chunk *chunk) { free(chunk->data); - chunk->data = (uint8_t*)calloc(1, chunk->size + sizeof(uint32_t)); // CRC32 + chunk->data = (uint8_t*)calloc(1, chunk->size + sizeof(uint32_t)); /* CRC32 */ if (!chunk->data) return false; - if (fread(chunk->data, 1, chunk->size + sizeof(uint32_t), file) != (chunk->size + sizeof(uint32_t))) + if (fread(chunk->data, 1, chunk->size + + sizeof(uint32_t), file) != (chunk->size + sizeof(uint32_t))) { free(chunk->data); return false; } - // Ignore CRC. + /* Ignore CRC. */ return true; } @@ -148,7 +149,8 @@ static void png_free_chunk(struct png_chunk *chunk) chunk->data = NULL; } -static bool png_parse_ihdr(FILE *file, struct png_chunk *chunk, struct png_ihdr *ihdr) +static bool png_parse_ihdr(FILE *file, + struct png_chunk *chunk, struct png_ihdr *ihdr) { unsigned i; bool ret = true; @@ -169,7 +171,8 @@ static bool png_parse_ihdr(FILE *file, struct png_chunk *chunk, struct png_ihdr if (ihdr->width == 0 || ihdr->height == 0) GOTO_END_ERROR(); - if (ihdr->color_type == 2 || ihdr->color_type == 4 || ihdr->color_type == 6) + if (ihdr->color_type == 2 || + ihdr->color_type == 4 || ihdr->color_type == 6) { if (ihdr->depth != 8 && ihdr->depth != 16) GOTO_END_ERROR(); @@ -245,7 +248,8 @@ static inline int paeth(int a, int b, int c) return c; } -static inline void copy_line_rgb(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned bpp) +static inline void copy_line_rgb(uint32_t *data, + const uint8_t *decoded, unsigned width, unsigned bpp) { unsigned i; bpp /= 8; @@ -261,7 +265,8 @@ static inline void copy_line_rgb(uint32_t *data, const uint8_t *decoded, unsigne } } -static inline void copy_line_rgba(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned bpp) +static inline void copy_line_rgba(uint32_t *data, + const uint8_t *decoded, unsigned width, unsigned bpp) { unsigned i; bpp /= 8; @@ -279,7 +284,8 @@ static inline void copy_line_rgba(uint32_t *data, const uint8_t *decoded, unsign } } -static inline void copy_line_bw(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned depth) +static inline void copy_line_bw(uint32_t *data, + const uint8_t *decoded, unsigned width, unsigned depth) { unsigned i, bit; if (depth == 16) @@ -308,7 +314,8 @@ static inline void copy_line_bw(uint32_t *data, const uint8_t *decoded, unsigned } } -static inline void copy_line_gray_alpha(uint32_t *data, const uint8_t *decoded, unsigned width, +static inline void copy_line_gray_alpha(uint32_t *data, + const uint8_t *decoded, unsigned width, unsigned bpp) { unsigned i; @@ -324,7 +331,9 @@ static inline void copy_line_gray_alpha(uint32_t *data, const uint8_t *decoded, } } -static inline void copy_line_plt(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned depth, const uint32_t *palette) +static inline void copy_line_plt(uint32_t *data, + const uint8_t *decoded, unsigned width, + unsigned depth, const uint32_t *palette) { unsigned i, bit; unsigned mask = (1 << depth) - 1; @@ -387,7 +396,8 @@ static void png_pass_geom(const struct png_ihdr *ihdr, static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, - const uint8_t *inflate_buf, size_t inflate_buf_size, const uint32_t *palette) + const uint8_t *inflate_buf, size_t inflate_buf_size, + const uint32_t *palette) { unsigned i, h; bool ret = true; @@ -412,23 +422,23 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, unsigned filter = *inflate_buf++; switch (filter) { - case 0: // None + case 0: /* None */ memcpy(decoded_scanline, inflate_buf, pitch); break; - case 1: // Sub + case 1: /* Sub */ for (i = 0; i < bpp; i++) decoded_scanline[i] = inflate_buf[i]; for (i = bpp; i < pitch; i++) decoded_scanline[i] = decoded_scanline[i - bpp] + inflate_buf[i]; break; - case 2: // Up + case 2: /* Up */ for (i = 0; i < pitch; i++) decoded_scanline[i] = prev_scanline[i] + inflate_buf[i]; break; - case 3: // Average + case 3: /* Average */ for (i = 0; i < bpp; i++) { uint8_t avg = prev_scanline[i] >> 1; @@ -441,11 +451,12 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, } break; - case 4: // Paeth + case 4: /* Paeth */ for (i = 0; i < bpp; i++) decoded_scanline[i] = paeth(0, prev_scanline[i], 0) + inflate_buf[i]; for (i = bpp; i < pitch; i++) - decoded_scanline[i] = paeth(decoded_scanline[i - bpp], prev_scanline[i], prev_scanline[i - bpp]) + inflate_buf[i]; + decoded_scanline[i] = paeth(decoded_scanline[i - bpp], + prev_scanline[i], prev_scanline[i - bpp]) + inflate_buf[i]; break; default: @@ -457,9 +468,11 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, else if (ihdr->color_type == 2) copy_line_rgb(data, decoded_scanline, ihdr->width, ihdr->depth); else if (ihdr->color_type == 3) - copy_line_plt(data, decoded_scanline, ihdr->width, ihdr->depth, palette); + copy_line_plt(data, decoded_scanline, ihdr->width, + ihdr->depth, palette); else if (ihdr->color_type == 4) - copy_line_gray_alpha(data, decoded_scanline, ihdr->width, ihdr->depth); + copy_line_gray_alpha(data, decoded_scanline, ihdr->width, + ihdr->depth); else if (ihdr->color_type == 6) copy_line_rgba(data, decoded_scanline, ihdr->width, ihdr->depth); @@ -481,11 +494,13 @@ struct adam7_pass }; static void deinterlace_pass(uint32_t *data, const struct png_ihdr *ihdr, - const uint32_t *input, unsigned pass_width, unsigned pass_height, const struct adam7_pass *pass) + const uint32_t *input, unsigned pass_width, unsigned pass_height, + const struct adam7_pass *pass) { unsigned x, y; data += pass->y * ihdr->width + pass->x; - for (y = 0; y < pass_height; y++, data += ihdr->width * pass->stride_y, input += pass_width) + for (y = 0; y < pass_height; + y++, data += ihdr->width * pass->stride_y, input += pass_width) { uint32_t *out = data; for (x = 0; x < pass_width; x++, out += pass->stride_x) @@ -493,8 +508,10 @@ static void deinterlace_pass(uint32_t *data, const struct png_ihdr *ihdr, } } -static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr, - const uint8_t *inflate_buf, size_t inflate_buf_size, const uint32_t *palette) +static bool png_reverse_filter_adam7(uint32_t *data, + const struct png_ihdr *ihdr, + const uint8_t *inflate_buf, size_t inflate_buf_size, + const uint32_t *palette) { unsigned pass; static const struct adam7_pass passes[] = { @@ -509,13 +526,18 @@ static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr for (pass = 0; pass < ARRAY_SIZE(passes); pass++) { - if (ihdr->width <= passes[pass].x || ihdr->height <= passes[pass].y) // Empty pass + if (ihdr->width <= passes[pass].x || + ihdr->height <= passes[pass].y) /* Empty pass */ continue; - unsigned pass_width = (ihdr->width - passes[pass].x + passes[pass].stride_x - 1) / passes[pass].stride_x; - unsigned pass_height = (ihdr->height - passes[pass].y + passes[pass].stride_y - 1) / passes[pass].stride_y; + unsigned pass_width = (ihdr->width - + passes[pass].x + passes[pass].stride_x - 1) / passes[pass].stride_x; + unsigned pass_height = (ihdr->height - passes[pass].y + + passes[pass].stride_y - 1) / passes[pass].stride_y; + + uint32_t *tmp_data = (uint32_t*) + malloc(pass_width * pass_height * sizeof(uint32_t)); - uint32_t *tmp_data = (uint32_t*)malloc(pass_width * pass_height * sizeof(uint32_t)); if (!tmp_data) return false; @@ -524,7 +546,8 @@ static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr tmp_ihdr.height = pass_height; size_t pass_size; - png_pass_geom(&tmp_ihdr, pass_width, pass_height, NULL, NULL, &pass_size); + png_pass_geom(&tmp_ihdr, pass_width, + pass_height, NULL, NULL, &pass_size); if (pass_size > inflate_buf_size) { @@ -532,7 +555,8 @@ static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr return false; } - if (!png_reverse_filter(tmp_data, &tmp_ihdr, inflate_buf, pass_size, palette)) + if (!png_reverse_filter(tmp_data, + &tmp_ihdr, inflate_buf, pass_size, palette)) { free(tmp_data); return false; @@ -541,14 +565,16 @@ static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr inflate_buf += pass_size; inflate_buf_size -= pass_size; - deinterlace_pass(data, ihdr, tmp_data, pass_width, pass_height, &passes[pass]); + deinterlace_pass(data, + ihdr, tmp_data, pass_width, pass_height, &passes[pass]); free(tmp_data); } return true; } -static bool png_append_idat(FILE *file, const struct png_chunk *chunk, struct idat_buffer *buf) +static bool png_append_idat(FILE *file, + const struct png_chunk *chunk, struct idat_buffer *buf) { uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size); if (!new_buffer) @@ -587,7 +613,8 @@ static bool png_read_plte(FILE *file, uint32_t *buffer, unsigned entries) return true; } -bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, unsigned *height) +bool rpng_load_image_argb(const char *path, uint32_t **data, + unsigned *width, unsigned *height) { long pos; *data = NULL; @@ -622,8 +649,9 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, un if (memcmp(header, png_magic, sizeof(png_magic)) != 0) GOTO_END_ERROR(); - // feof() apparently isn't triggered after a seek (IEND). - for (pos = ftell(file); pos < file_len && pos >= 0; pos = ftell(file)) + /* feof() apparently isn't triggered after a seek (IEND). */ + for (pos = ftell(file); + pos < file_len && pos >= 0; pos = ftell(file)) { struct png_chunk chunk = {0}; if (!read_chunk_header(file, &chunk)) @@ -692,7 +720,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, un GOTO_END_ERROR(); png_pass_geom(&ihdr, ihdr.width, ihdr.height, NULL, NULL, &inflate_buf_size); - if (ihdr.interlace == 1) // To be sure. + if (ihdr.interlace == 1) /* To be sure. */ inflate_buf_size *= 2; inflate_buf = (uint8_t*)malloc(inflate_buf_size); @@ -714,7 +742,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, un *width = ihdr.width; *height = ihdr.height; #ifdef GEKKO - // we often use these in textures, make sure they're 32-byte aligned + /* we often use these in textures, make sure they're 32-byte aligned */ *data = (uint32_t*)memalign(32, ihdr.width * ihdr.height * sizeof(uint32_t)); #else *data = (uint32_t*)malloc(ihdr.width * ihdr.height * sizeof(uint32_t)); @@ -724,10 +752,12 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, un if (ihdr.interlace == 1) { - if (!png_reverse_filter_adam7(*data, &ihdr, inflate_buf, stream.total_out, palette)) + if (!png_reverse_filter_adam7(*data, + &ihdr, inflate_buf, stream.total_out, palette)) GOTO_END_ERROR(); } - else if (!png_reverse_filter(*data, &ihdr, inflate_buf, stream.total_out, palette)) + else if (!png_reverse_filter(*data, + &ihdr, inflate_buf, stream.total_out, palette)) GOTO_END_ERROR(); end: @@ -779,7 +809,8 @@ static bool png_write_ihdr(FILE *file, const struct png_ihdr *ihdr) if (fwrite(ihdr_raw, 1, sizeof(ihdr_raw), file) != sizeof(ihdr_raw)) return false; - if (!png_write_crc(file, ihdr_raw + sizeof(uint32_t), sizeof(ihdr_raw) - sizeof(uint32_t))) + if (!png_write_crc(file, ihdr_raw + sizeof(uint32_t), + sizeof(ihdr_raw) - sizeof(uint32_t))) return false; return true; @@ -806,7 +837,8 @@ static bool png_write_iend(FILE *file) if (fwrite(data, 1, sizeof(data), file) != sizeof(data)) return false; - if (!png_write_crc(file, data + sizeof(uint32_t), sizeof(data) - sizeof(uint32_t))) + if (!png_write_crc(file, data + sizeof(uint32_t), + sizeof(data) - sizeof(uint32_t))) return false; return true; @@ -845,8 +877,8 @@ static unsigned count_sad(const uint8_t *data, size_t size) return cnt; } -static unsigned filter_up(uint8_t *target, const uint8_t *line, const uint8_t *prev, - unsigned width, unsigned bpp) +static unsigned filter_up(uint8_t *target, const uint8_t *line, + const uint8_t *prev, unsigned width, unsigned bpp) { unsigned i; width *= bpp; @@ -869,8 +901,8 @@ static unsigned filter_sub(uint8_t *target, const uint8_t *line, return count_sad(target, width); } -static unsigned filter_avg(uint8_t *target, const uint8_t *line, const uint8_t *prev, - unsigned width, unsigned bpp) +static unsigned filter_avg(uint8_t *target, const uint8_t *line, + const uint8_t *prev, unsigned width, unsigned bpp) { unsigned i; width *= bpp; @@ -882,7 +914,8 @@ static unsigned filter_avg(uint8_t *target, const uint8_t *line, const uint8_t * return count_sad(target, width); } -static unsigned filter_paeth(uint8_t *target, const uint8_t *line, const uint8_t *prev, +static unsigned filter_paeth(uint8_t *target, + const uint8_t *line, const uint8_t *prev, unsigned width, unsigned bpp) { unsigned i; @@ -895,7 +928,8 @@ static unsigned filter_paeth(uint8_t *target, const uint8_t *line, const uint8_t return count_sad(target, width); } -static bool rpng_save_image(const char *path, const uint8_t *data, +static bool rpng_save_image(const char *path, + const uint8_t *data, unsigned width, unsigned height, unsigned pitch, unsigned bpp) { unsigned h; @@ -925,7 +959,7 @@ static bool rpng_save_image(const char *path, const uint8_t *data, ihdr.width = width; ihdr.height = height; ihdr.depth = 8; - ihdr.color_type = bpp == sizeof(uint32_t) ? 6 : 2; // RGBA or RGB + ihdr.color_type = bpp == sizeof(uint32_t) ? 6 : 2; /* RGBA or RGB */ if (!png_write_ihdr(file, &ihdr)) GOTO_END_ERROR(); @@ -955,9 +989,12 @@ static bool rpng_save_image(const char *path, const uint8_t *data, else copy_bgr24_line(rgba_line, data, width); - // Try every filtering method, and choose the method - // which has most entries as zero. - // This is probably not very optimal, but it's very simple to implement. + /* Try every filtering method, and choose the method + * which has most entries as zero. + * + * This is probably not very optimal, but it's very + * simple to implement. + */ unsigned none_score = count_sad(rgba_line, width * bpp); unsigned up_score = filter_up(up_filtered, rgba_line, prev_encoded, width, bpp); unsigned sub_score = filter_sub(sub_filtered, rgba_line, width, bpp); @@ -1002,7 +1039,7 @@ static bool rpng_save_image(const char *path, const uint8_t *data, memcpy(prev_encoded, rgba_line, width * bpp); } - deflate_buf = (uint8_t*)malloc(encode_buf_size * 2); // Just to be sure. + deflate_buf = (uint8_t*)malloc(encode_buf_size * 2); /* Just to be sure. */ if (!deflate_buf) GOTO_END_ERROR(); @@ -1044,13 +1081,15 @@ end: bool rpng_save_image_argb(const char *path, const uint32_t *data, unsigned width, unsigned height, unsigned pitch) { - return rpng_save_image(path, (const uint8_t*)data, width, height, pitch, sizeof(uint32_t)); + return rpng_save_image(path, (const uint8_t*)data, + width, height, pitch, sizeof(uint32_t)); } bool rpng_save_image_bgr24(const char *path, const uint8_t *data, unsigned width, unsigned height, unsigned pitch) { - return rpng_save_image(path, (const uint8_t*)data, width, height, pitch, 3); + return rpng_save_image(path, (const uint8_t*)data, + width, height, pitch, 3); } #endif diff --git a/gfx/rpng/rpng.h b/gfx/rpng/rpng.h index 6f1818e6cc..6401233e56 100644 --- a/gfx/rpng/rpng.h +++ b/gfx/rpng/rpng.h @@ -28,7 +28,8 @@ extern "C" { #endif -bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, unsigned *height); +bool rpng_load_image_argb(const char *path, uint32_t **data, + unsigned *width, unsigned *height); #ifdef HAVE_ZLIB_DEFLATE bool rpng_save_image_argb(const char *path, const uint32_t *data, diff --git a/gfx/rpng/rpng_test.c b/gfx/rpng/rpng_test.c index 79a905b819..711875a646 100644 --- a/gfx/rpng/rpng_test.c +++ b/gfx/rpng/rpng_test.c @@ -31,10 +31,14 @@ int main(int argc, char *argv[]) const char *in_path = argc == 2 ? argv[1] : "/tmp/test.png"; const uint32_t test_data[] = { - 0xff000000 | 0x50, 0xff000000 | 0x80, 0xff000000 | 0x40, 0xff000000 | 0x88, - 0xff000000 | 0x50, 0xff000000 | 0x80, 0xff000000 | 0x40, 0xff000000 | 0x88, - 0xff000000 | 0xc3, 0xff000000 | 0xd3, 0xff000000 | 0xc3, 0xff000000 | 0xd3, - 0xff000000 | 0xc3, 0xff000000 | 0xd3, 0xff000000 | 0xc3, 0xff000000 | 0xd3, + 0xff000000 | 0x50, 0xff000000 | 0x80, + 0xff000000 | 0x40, 0xff000000 | 0x88, + 0xff000000 | 0x50, 0xff000000 | 0x80, + 0xff000000 | 0x40, 0xff000000 | 0x88, + 0xff000000 | 0xc3, 0xff000000 | 0xd3, + 0xff000000 | 0xc3, 0xff000000 | 0xd3, + 0xff000000 | 0xc3, 0xff000000 | 0xd3, + 0xff000000 | 0xc3, 0xff000000 | 0xd3, }; if (!rpng_save_image_argb("/tmp/test.png", test_data, 4, 4, 16)) diff --git a/gfx/scaler/pixconv.c b/gfx/scaler/pixconv.c index 2e8d2912a5..543aa24e3a 100644 --- a/gfx/scaler/pixconv.c +++ b/gfx/scaler/pixconv.c @@ -41,7 +41,8 @@ void conv_rgb565_0rgb1555(void *output_, const void *input_, const __m128i hi_mask = _mm_set1_epi16(0x7fe0); const __m128i lo_mask = _mm_set1_epi16(0x1f); - for (h = 0; h < height; h++, output += out_stride >> 1, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 1, input += in_stride >> 1) { for (w = 0; w < max_width; w += 8) { @@ -69,7 +70,8 @@ void conv_rgb565_0rgb1555(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint16_t *output = (uint16_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 1, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 1, input += in_stride >> 1) { for (w = 0; w < width; w++) { @@ -94,11 +96,13 @@ void conv_0rgb1555_rgb565(void *output_, const void *input_, int max_width = width - 7; - const __m128i hi_mask = _mm_set1_epi16((int16_t)((0x1f << 11) | (0x1f << 6))); + const __m128i hi_mask = _mm_set1_epi16( + (int16_t)((0x1f << 11) | (0x1f << 6))); const __m128i lo_mask = _mm_set1_epi16(0x1f); const __m128i glow_mask = _mm_set1_epi16(1 << 5); - for (h = 0; h < height; h++, output += out_stride >> 1, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 1, input += in_stride >> 1) { for (w = 0; w < max_width; w += 8) { @@ -106,7 +110,8 @@ void conv_0rgb1555_rgb565(void *output_, const void *input_, __m128i rg = _mm_and_si128(_mm_slli_epi16(in, 1), hi_mask); __m128i b = _mm_and_si128(in, lo_mask); __m128i glow = _mm_and_si128(_mm_srli_epi16(in, 4), glow_mask); - _mm_storeu_si128((__m128i*)(output + w), _mm_or_si128(rg, _mm_or_si128(b, glow))); + _mm_storeu_si128((__m128i*)(output + w), + _mm_or_si128(rg, _mm_or_si128(b, glow))); } for (; w < width; w++) @@ -128,7 +133,8 @@ void conv_0rgb1555_rgb565(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint16_t *output = (uint16_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 1, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 1, input += in_stride >> 1) { for (w = 0; w < width; w++) { @@ -159,7 +165,8 @@ void conv_0rgb1555_argb8888(void *output_, const void *input_, int max_width = width - 7; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride >> 1) { for (w = 0; w < max_width; w += 8) { @@ -177,8 +184,10 @@ void conv_0rgb1555_argb8888(void *output_, const void *input_, __m128i res_lo_ra = _mm_unpacklo_epi8(r, a); __m128i res_hi_ra = _mm_unpackhi_epi8(r, a); - __m128i res_lo = _mm_or_si128(res_lo_bg, _mm_slli_si128(res_lo_ra, 2)); - __m128i res_hi = _mm_or_si128(res_hi_bg, _mm_slli_si128(res_hi_ra, 2)); + __m128i res_lo = _mm_or_si128(res_lo_bg, + _mm_slli_si128(res_lo_ra, 2)); + __m128i res_hi = _mm_or_si128(res_hi_bg, + _mm_slli_si128(res_hi_ra, 2)); _mm_storeu_si128((__m128i*)(output + w + 0), res_lo); _mm_storeu_si128((__m128i*)(output + w + 4), res_hi); @@ -207,7 +216,8 @@ void conv_0rgb1555_argb8888(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint32_t *output = (uint32_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride >> 1) { for (w = 0; w < width; w++) { @@ -244,7 +254,8 @@ void conv_rgb565_argb8888(void *output_, const void *input_, int max_width = width - 7; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride >> 1) { for (w = 0; w < max_width; w += 8) { @@ -262,8 +273,10 @@ void conv_rgb565_argb8888(void *output_, const void *input_, __m128i res_lo_ra = _mm_unpacklo_epi8(r, a); __m128i res_hi_ra = _mm_unpackhi_epi8(r, a); - __m128i res_lo = _mm_or_si128(res_lo_bg, _mm_slli_si128(res_lo_ra, 2)); - __m128i res_hi = _mm_or_si128(res_hi_bg, _mm_slli_si128(res_hi_ra, 2)); + __m128i res_lo = _mm_or_si128(res_lo_bg, + _mm_slli_si128(res_lo_ra, 2)); + __m128i res_hi = _mm_or_si128(res_hi_bg, + _mm_slli_si128(res_hi_ra, 2)); _mm_storeu_si128((__m128i*)(output + w + 0), res_lo); _mm_storeu_si128((__m128i*)(output + w + 4), res_hi); @@ -292,7 +305,8 @@ void conv_rgb565_argb8888(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint32_t *output = (uint32_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride >> 1) { for (w = 0; w < width; w++) { @@ -318,7 +332,8 @@ void conv_rgba4444_argb8888(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint32_t *output = (uint32_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride >> 1) { for (w = 0; w < width; w++) { @@ -332,15 +347,15 @@ void conv_rgba4444_argb8888(void *output_, const void *input_, b = (b << 4) | b; a = (a << 4) | a; - //output[w] = (0xffu << 24) | (r << 16) | (g << 8) | (b << 0); output[w] = (a << 24) | (r << 16) | (g << 8) | (b << 0); } } } #if defined(__SSE2__) -// :( TODO: Make this saner. -static inline void store_bgr24_sse2(void *output, __m128i a, __m128i b, __m128i c, __m128i d) +/* :( TODO: Make this saner. */ +static inline void store_bgr24_sse2(void *output, __m128i a, + __m128i b, __m128i c, __m128i d) { const __m128i mask_0 = _mm_set_epi32(0, 0, 0, 0x00ffffff); const __m128i mask_1 = _mm_set_epi32(0, 0, 0x00ffffff, 0); @@ -371,13 +386,16 @@ static inline void store_bgr24_sse2(void *output, __m128i a, __m128i b, __m128i __m128i *out = (__m128i*)output; _mm_storeu_si128(out + 0, - _mm_or_si128(a0, _mm_or_si128(a1, _mm_or_si128(a2, _mm_or_si128(a3, _mm_or_si128(a4, a5)))))); + _mm_or_si128(a0, _mm_or_si128(a1, _mm_or_si128(a2, + _mm_or_si128(a3, _mm_or_si128(a4, a5)))))); _mm_storeu_si128(out + 1, - _mm_or_si128(b0, _mm_or_si128(b1, _mm_or_si128(b2, _mm_or_si128(b3, _mm_or_si128(b4, b5)))))); + _mm_or_si128(b0, _mm_or_si128(b1, _mm_or_si128(b2, + _mm_or_si128(b3, _mm_or_si128(b4, b5)))))); _mm_storeu_si128(out + 2, - _mm_or_si128(c0, _mm_or_si128(c1, _mm_or_si128(c2, _mm_or_si128(c3, _mm_or_si128(c4, c5)))))); + _mm_or_si128(c0, _mm_or_si128(c1, _mm_or_si128(c2, + _mm_or_si128(c3, _mm_or_si128(c4, c5)))))); } void conv_0rgb1555_bgr24(void *output_, const void *input_, @@ -396,7 +414,8 @@ void conv_0rgb1555_bgr24(void *output_, const void *input_, int max_width = width - 15; - for (h = 0; h < height; h++, output += out_stride, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride, input += in_stride >> 1) { uint8_t *out = output; @@ -427,12 +446,16 @@ void conv_0rgb1555_bgr24(void *output_, const void *input_, __m128i res_hi_ra0 = _mm_unpackhi_epi8(r0, a); __m128i res_hi_ra1 = _mm_unpackhi_epi8(r1, a); - __m128i res_lo0 = _mm_or_si128(res_lo_bg0, _mm_slli_si128(res_lo_ra0, 2)); - __m128i res_lo1 = _mm_or_si128(res_lo_bg1, _mm_slli_si128(res_lo_ra1, 2)); - __m128i res_hi0 = _mm_or_si128(res_hi_bg0, _mm_slli_si128(res_hi_ra0, 2)); - __m128i res_hi1 = _mm_or_si128(res_hi_bg1, _mm_slli_si128(res_hi_ra1, 2)); + __m128i res_lo0 = _mm_or_si128(res_lo_bg0, + _mm_slli_si128(res_lo_ra0, 2)); + __m128i res_lo1 = _mm_or_si128(res_lo_bg1, + _mm_slli_si128(res_lo_ra1, 2)); + __m128i res_hi0 = _mm_or_si128(res_hi_bg0, + _mm_slli_si128(res_hi_ra0, 2)); + __m128i res_hi1 = _mm_or_si128(res_hi_bg1, + _mm_slli_si128(res_hi_ra1, 2)); - // Non-POT pixel sizes ftl :( + /* Non-POT pixel sizes ftl :( */ store_bgr24_sse2(out, res_lo0, res_hi0, res_lo1, res_hi1); } @@ -502,10 +525,14 @@ void conv_rgb565_bgr24(void *output_, const void *input_, __m128i res_lo_ra1 = _mm_unpacklo_epi8(r1, a); __m128i res_hi_ra1 = _mm_unpackhi_epi8(r1, a); - __m128i res_lo0 = _mm_or_si128(res_lo_bg0, _mm_slli_si128(res_lo_ra0, 2)); - __m128i res_hi0 = _mm_or_si128(res_hi_bg0, _mm_slli_si128(res_hi_ra0, 2)); - __m128i res_lo1 = _mm_or_si128(res_lo_bg1, _mm_slli_si128(res_lo_ra1, 2)); - __m128i res_hi1 = _mm_or_si128(res_hi_bg1, _mm_slli_si128(res_hi_ra1, 2)); + __m128i res_lo0 = _mm_or_si128(res_lo_bg0, + _mm_slli_si128(res_lo_ra0, 2)); + __m128i res_hi0 = _mm_or_si128(res_hi_bg0, + _mm_slli_si128(res_hi_ra0, 2)); + __m128i res_lo1 = _mm_or_si128(res_lo_bg1, + _mm_slli_si128(res_lo_ra1, 2)); + __m128i res_hi1 = _mm_or_si128(res_hi_bg1, + _mm_slli_si128(res_hi_ra1, 2)); store_bgr24_sse2(out, res_lo0, res_hi0, res_lo1, res_hi1); } @@ -535,7 +562,8 @@ void conv_0rgb1555_bgr24(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint8_t *output = (uint8_t*)output_; - for (h = 0; h < height; h++, output += out_stride, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride, input += in_stride >> 1) { uint8_t *out = output; for (w = 0; w < width; w++) @@ -563,7 +591,8 @@ void conv_rgb565_bgr24(void *output_, const void *input_, const uint16_t *input = (const uint16_t*)input_; uint8_t *output = (uint8_t*)output_; - for (h = 0; h < height; h++, output += out_stride, input += in_stride >> 1) + for (h = 0; h < height; + h++, output += out_stride, input += in_stride >> 1) { uint8_t *out = output; for (w = 0; w < width; w++) @@ -592,7 +621,8 @@ void conv_bgr24_argb8888(void *output_, const void *input_, const uint8_t *input = (const uint8_t*)input_; uint32_t *output = (uint32_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride) { const uint8_t *inp = input; for (w = 0; w < width; w++) @@ -613,7 +643,8 @@ void conv_argb8888_0rgb1555(void *output_, const void *input_, const uint32_t *input = (const uint32_t*)input_; uint16_t *output = (uint16_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 1, input += in_stride >> 2) + for (h = 0; h < height; + h++, output += out_stride >> 1, input += in_stride >> 2) { for (w = 0; w < width; w++) { @@ -637,7 +668,8 @@ void conv_argb8888_bgr24(void *output_, const void *input_, int max_width = width - 15; - for (h = 0; h < height; h++, output += out_stride, input += in_stride >> 2) + for (h = 0; h < height; + h++, output += out_stride, input += in_stride >> 2) { uint8_t *out = output; @@ -668,7 +700,8 @@ void conv_argb8888_bgr24(void *output_, const void *input_, const uint32_t *input = (const uint32_t*)input_; uint8_t *output = (uint8_t*)output_; - for (h = 0; h < height; h++, output += out_stride, input += in_stride >> 2) + for (h = 0; h < height; + h++, output += out_stride, input += in_stride >> 2) { uint8_t *out = output; for (w = 0; w < width; w++) @@ -690,12 +723,14 @@ void conv_argb8888_abgr8888(void *output_, const void *input_, const uint32_t *input = (const uint32_t*)input_; uint32_t *output = (uint32_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 2) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride >> 2) { for (w = 0; w < width; w++) { uint32_t col = input[w]; - output[w] = ((col << 16) & 0xff0000) | ((col >> 16) & 0xff) | (col & 0xff00ff00); + output[w] = ((col << 16) & 0xff0000) | + ((col >> 16) & 0xff) | (col & 0xff00ff00); } } } @@ -727,27 +762,28 @@ void conv_yuyv_argb8888(void *output_, const void *input_, const __m128i u_b_mul = _mm_set1_epi16(YUV_MAT_U_B); const __m128i v_r_mul = _mm_set1_epi16(YUV_MAT_V_R); const __m128i v_g_mul = _mm_set1_epi16(YUV_MAT_V_G); - const __m128i a = _mm_cmpeq_epi16(_mm_setzero_si128(), _mm_setzero_si128()); + const __m128i a = _mm_cmpeq_epi16(_mm_setzero_si128(), + _mm_setzero_si128()); for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride) { const uint8_t *src = input; uint32_t *dst = output; - // Each loop processes 16 pixels. + /* Each loop processes 16 pixels. */ for (w = 0; w + 16 <= width; w += 16, src += 32, dst += 16) { - __m128i yuv0 = _mm_loadu_si128((const __m128i*)(src + 0)); // [Y0, U0, Y1, V0, Y2, U1, Y3, V1, ...] - __m128i yuv1 = _mm_loadu_si128((const __m128i*)(src + 16)); // [Y0, U0, Y1, V0, Y2, U1, Y3, V1, ...] + __m128i yuv0 = _mm_loadu_si128((const __m128i*)(src + 0)); /* [Y0, U0, Y1, V0, Y2, U1, Y3, V1, ...] */ + __m128i yuv1 = _mm_loadu_si128((const __m128i*)(src + 16)); /* [Y0, U0, Y1, V0, Y2, U1, Y3, V1, ...] */ - __m128i y0 = _mm_and_si128(yuv0, mask_y); // [Y0, Y1, Y2, ...] (16-bit) - __m128i u0 = _mm_and_si128(yuv0, mask_u); // [0, U0, 0, 0, 0, U1, 0, 0, ...] - __m128i v0 = _mm_and_si128(yuv0, mask_v); // [0, 0, 0, V1, 0, , 0, V1, ...] - __m128i y1 = _mm_and_si128(yuv1, mask_y); // [Y0, Y1, Y2, ...] (16-bit) - __m128i u1 = _mm_and_si128(yuv1, mask_u); // [0, U0, 0, 0, 0, U1, 0, 0, ...] - __m128i v1 = _mm_and_si128(yuv1, mask_v); // [0, 0, 0, V1, 0, , 0, V1, ...] + __m128i y0 = _mm_and_si128(yuv0, mask_y); /* [Y0, Y1, Y2, ...] (16-bit) */ + __m128i u0 = _mm_and_si128(yuv0, mask_u); /* [0, U0, 0, 0, 0, U1, 0, 0, ...] */ + __m128i v0 = _mm_and_si128(yuv0, mask_v); /* [0, 0, 0, V1, 0, , 0, V1, ...] */ + __m128i y1 = _mm_and_si128(yuv1, mask_y); /* [Y0, Y1, Y2, ...] (16-bit) */ + __m128i u1 = _mm_and_si128(yuv1, mask_u); /* [0, U0, 0, 0, 0, U1, 0, 0, ...] */ + __m128i v1 = _mm_and_si128(yuv1, mask_v); /* [0, 0, 0, V1, 0, , 0, V1, ...] */ - // Juggle around to get U and V in the same 16-bit format as Y. + /* Juggle around to get U and V in the same 16-bit format as Y. */ u0 = _mm_srli_si128(u0, 1); v0 = _mm_srli_si128(v0, 3); u1 = _mm_srli_si128(u1, 1); @@ -755,17 +791,17 @@ void conv_yuyv_argb8888(void *output_, const void *input_, __m128i u = _mm_packs_epi32(u0, u1); __m128i v = _mm_packs_epi32(v0, v1); - // Apply YUV offsets (U, V) -= (-128, -128) + /* Apply YUV offsets (U, V) -= (-128, -128). */ u = _mm_sub_epi16(u, chroma_offset); v = _mm_sub_epi16(v, chroma_offset); - // Upscale chroma horizontally (nearest) + /* Upscale chroma horizontally (nearest). */ u0 = _mm_unpacklo_epi16(u, u); u1 = _mm_unpackhi_epi16(u, u); v0 = _mm_unpacklo_epi16(v, v); v1 = _mm_unpackhi_epi16(v, v); - // Apply transformations + /* Apply transformations. */ y0 = _mm_mullo_epi16(y0, yuv_mul); y1 = _mm_mullo_epi16(y1, yuv_mul); __m128i u0_g = _mm_mullo_epi16(u0, u_g_mul); @@ -777,21 +813,27 @@ void conv_yuyv_argb8888(void *output_, const void *input_, __m128i v0_g = _mm_mullo_epi16(v0, v_g_mul); __m128i v1_g = _mm_mullo_epi16(v1, v_g_mul); - // Add contibutions from the transformed components. - __m128i r0 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(y0, v0_r), round_offset), YUV_SHIFT); - __m128i g0 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(_mm_adds_epi16(y0, v0_g), u0_g), round_offset), YUV_SHIFT); - __m128i b0 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(y0, u0_b), round_offset), YUV_SHIFT); + /* Add contibutions from the transformed components. */ + __m128i r0 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(y0, v0_r), + round_offset), YUV_SHIFT); + __m128i g0 = _mm_srai_epi16(_mm_adds_epi16( + _mm_adds_epi16(_mm_adds_epi16(y0, v0_g), u0_g), round_offset), YUV_SHIFT); + __m128i b0 = _mm_srai_epi16(_mm_adds_epi16( + _mm_adds_epi16(y0, u0_b), round_offset), YUV_SHIFT); - __m128i r1 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(y1, v1_r), round_offset), YUV_SHIFT); - __m128i g1 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(_mm_adds_epi16(y1, v1_g), u1_g), round_offset), YUV_SHIFT); - __m128i b1 = _mm_srai_epi16(_mm_adds_epi16(_mm_adds_epi16(y1, u1_b), round_offset), YUV_SHIFT); + __m128i r1 = _mm_srai_epi16(_mm_adds_epi16( + _mm_adds_epi16(y1, v1_r), round_offset), YUV_SHIFT); + __m128i g1 = _mm_srai_epi16(_mm_adds_epi16( + _mm_adds_epi16(_mm_adds_epi16(y1, v1_g), u1_g), round_offset), YUV_SHIFT); + __m128i b1 = _mm_srai_epi16(_mm_adds_epi16( + _mm_adds_epi16(y1, u1_b), round_offset), YUV_SHIFT); - // Saturate into 8-bit. + /* Saturate into 8-bit. */ r0 = _mm_packus_epi16(r0, r1); g0 = _mm_packus_epi16(g0, g1); b0 = _mm_packus_epi16(b0, b1); - // Interleave into ARGB. + /* Interleave into ARGB. */ __m128i res_lo_bg = _mm_unpacklo_epi8(b0, g0); __m128i res_hi_bg = _mm_unpackhi_epi8(b0, g0); __m128i res_lo_ra = _mm_unpacklo_epi8(r0, a); @@ -807,7 +849,7 @@ void conv_yuyv_argb8888(void *output_, const void *input_, _mm_storeu_si128((__m128i*)(dst + 12), res3); } - // Finish off the rest (if any) in C. + /* Finish off the rest (if any) in C. */ for (; w < width; w += 2, src += 4, dst += 2) { int y0 = src[0]; @@ -837,7 +879,8 @@ void conv_yuyv_argb8888(void *output_, const void *input_, const uint8_t *input = (const uint8_t*)input_; uint32_t *output = (uint32_t*)output_; - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride) + for (h = 0; h < height; + h++, output += out_stride >> 2, input += in_stride) { const uint8_t *src = input; uint32_t *dst = output; @@ -876,7 +919,8 @@ void conv_copy(void *output_, const void *input_, const uint8_t *input = (const uint8_t*)input_; uint8_t *output = (uint8_t*)output_; - for (h = 0; h < height; h++, output += out_stride, input += in_stride) + for (h = 0; h < height; + h++, output += out_stride, input += in_stride) memcpy(output, input, copy_len); } diff --git a/gfx/scaler/scaler.c b/gfx/scaler/scaler.c index abcfc5da13..fe4965b84a 100644 --- a/gfx/scaler/scaler.c +++ b/gfx/scaler/scaler.c @@ -40,14 +40,18 @@ static bool allocate_frames(struct scaler_ctx *ctx) ctx->scaled.stride = ((ctx->out_width + 7) & ~7) * sizeof(uint64_t); ctx->scaled.width = ctx->out_width; ctx->scaled.height = ctx->in_height; - ctx->scaled.frame = (uint64_t*)scaler_alloc(sizeof(uint64_t), (ctx->scaled.stride * ctx->scaled.height) >> 3); + ctx->scaled.frame = (uint64_t*) + scaler_alloc(sizeof(uint64_t), + (ctx->scaled.stride * ctx->scaled.height) >> 3); if (!ctx->scaled.frame) return false; if (ctx->in_fmt != SCALER_FMT_ARGB8888) { ctx->input.stride = ((ctx->in_width + 7) & ~7) * sizeof(uint32_t); - ctx->input.frame = (uint32_t*)scaler_alloc(sizeof(uint32_t), (ctx->input.stride * ctx->in_height) >> 2); + ctx->input.frame = (uint32_t*) + scaler_alloc(sizeof(uint32_t), + (ctx->input.stride * ctx->in_height) >> 2); if (!ctx->input.frame) return false; } @@ -55,7 +59,9 @@ static bool allocate_frames(struct scaler_ctx *ctx) if (ctx->out_fmt != SCALER_FMT_ARGB8888) { ctx->output.stride = ((ctx->out_width + 7) & ~7) * sizeof(uint32_t); - ctx->output.frame = (uint32_t*)scaler_alloc(sizeof(uint32_t), (ctx->output.stride * ctx->out_height) >> 2); + ctx->output.frame = (uint32_t*) + scaler_alloc(sizeof(uint32_t), + (ctx->output.stride * ctx->out_height) >> 2); if (!ctx->output.frame) return false; } @@ -67,29 +73,41 @@ static bool set_direct_pix_conv(struct scaler_ctx *ctx) { if (ctx->in_fmt == ctx->out_fmt) ctx->direct_pixconv = conv_copy; - else if (ctx->in_fmt == SCALER_FMT_0RGB1555 && ctx->out_fmt == SCALER_FMT_ARGB8888) + else if (ctx->in_fmt == SCALER_FMT_0RGB1555 + && ctx->out_fmt == SCALER_FMT_ARGB8888) ctx->direct_pixconv = conv_0rgb1555_argb8888; - else if (ctx->in_fmt == SCALER_FMT_RGB565 && ctx->out_fmt == SCALER_FMT_ARGB8888) + else if (ctx->in_fmt == SCALER_FMT_RGB565 + && ctx->out_fmt == SCALER_FMT_ARGB8888) ctx->direct_pixconv = conv_rgb565_argb8888; - else if (ctx->in_fmt == SCALER_FMT_RGB565 && ctx->out_fmt == SCALER_FMT_BGR24) + else if (ctx->in_fmt == SCALER_FMT_RGB565 + && ctx->out_fmt == SCALER_FMT_BGR24) ctx->direct_pixconv = conv_rgb565_bgr24; - else if (ctx->in_fmt == SCALER_FMT_0RGB1555 && ctx->out_fmt == SCALER_FMT_RGB565) + else if (ctx->in_fmt == SCALER_FMT_0RGB1555 + && ctx->out_fmt == SCALER_FMT_RGB565) ctx->direct_pixconv = conv_0rgb1555_rgb565; - else if (ctx->in_fmt == SCALER_FMT_RGB565 && ctx->out_fmt == SCALER_FMT_0RGB1555) + else if (ctx->in_fmt == SCALER_FMT_RGB565 + && ctx->out_fmt == SCALER_FMT_0RGB1555) ctx->direct_pixconv = conv_rgb565_0rgb1555; - else if (ctx->in_fmt == SCALER_FMT_BGR24 && ctx->out_fmt == SCALER_FMT_ARGB8888) + else if (ctx->in_fmt == SCALER_FMT_BGR24 + && ctx->out_fmt == SCALER_FMT_ARGB8888) ctx->direct_pixconv = conv_bgr24_argb8888; - else if (ctx->in_fmt == SCALER_FMT_ARGB8888 && ctx->out_fmt == SCALER_FMT_0RGB1555) + else if (ctx->in_fmt == SCALER_FMT_ARGB8888 + && ctx->out_fmt == SCALER_FMT_0RGB1555) ctx->direct_pixconv = conv_argb8888_0rgb1555; - else if (ctx->in_fmt == SCALER_FMT_ARGB8888 && ctx->out_fmt == SCALER_FMT_BGR24) + else if (ctx->in_fmt == SCALER_FMT_ARGB8888 + && ctx->out_fmt == SCALER_FMT_BGR24) ctx->direct_pixconv = conv_argb8888_bgr24; - else if (ctx->in_fmt == SCALER_FMT_0RGB1555 && ctx->out_fmt == SCALER_FMT_BGR24) + else if (ctx->in_fmt == SCALER_FMT_0RGB1555 + && ctx->out_fmt == SCALER_FMT_BGR24) ctx->direct_pixconv = conv_0rgb1555_bgr24; - else if (ctx->in_fmt == SCALER_FMT_ARGB8888 && ctx->out_fmt == SCALER_FMT_ABGR8888) + else if (ctx->in_fmt == SCALER_FMT_ARGB8888 + && ctx->out_fmt == SCALER_FMT_ABGR8888) ctx->direct_pixconv = conv_argb8888_abgr8888; - else if (ctx->in_fmt == SCALER_FMT_YUYV && ctx->out_fmt == SCALER_FMT_ARGB8888) + else if (ctx->in_fmt == SCALER_FMT_YUYV + && ctx->out_fmt == SCALER_FMT_ARGB8888) ctx->direct_pixconv = conv_yuyv_argb8888; - else if (ctx->in_fmt == SCALER_FMT_RGBA4444 && ctx->out_fmt == SCALER_FMT_ARGB8888) + else if (ctx->in_fmt == SCALER_FMT_RGBA4444 + && ctx->out_fmt == SCALER_FMT_ARGB8888) ctx->direct_pixconv = conv_rgba4444_argb8888; else return false; @@ -102,7 +120,7 @@ static bool set_pix_conv(struct scaler_ctx *ctx) switch (ctx->in_fmt) { case SCALER_FMT_ARGB8888: - // No need to convert :D + /* No need to convert :D */ break; case SCALER_FMT_0RGB1555: @@ -128,7 +146,7 @@ static bool set_pix_conv(struct scaler_ctx *ctx) switch (ctx->out_fmt) { case SCALER_FMT_ARGB8888: - // No need to convert :D + /* No need to convert :D */ break; case SCALER_FMT_0RGB1555: @@ -151,7 +169,7 @@ bool scaler_ctx_gen_filter(struct scaler_ctx *ctx) scaler_ctx_gen_reset(ctx); if (ctx->in_width == ctx->out_width && ctx->in_height == ctx->out_height) - ctx->unscaled = true; // Only pixel format conversion ... + ctx->unscaled = true; /* Only pixel format conversion ... */ else { ctx->scaler_horiz = scaler_argb8888_horiz; @@ -201,14 +219,16 @@ void scaler_ctx_gen_reset(struct scaler_ctx *ctx) void scaler_ctx_scale(struct scaler_ctx *ctx, void *output, const void *input) { - if (ctx->unscaled) // Just perform straight pixel conversion. + if (ctx->unscaled) { + /* Just perform straight pixel conversion. */ ctx->direct_pixconv(output, input, ctx->out_width, ctx->out_height, ctx->out_stride, ctx->in_stride); } - else if (ctx->scaler_special) // Take some special, and (hopefully) more optimized path. + else if (ctx->scaler_special) { + /* Take some special, and (hopefully) more optimized path. */ const void *inp = input; int in_stride = ctx->in_stride; @@ -244,8 +264,9 @@ void scaler_ctx_scale(struct scaler_ctx *ctx, ctx->out_stride, ctx->output.stride); } } - else // Take generic filter path. + else { + /* Take generic filter path. */ if (ctx->in_fmt != SCALER_FMT_ARGB8888) { ctx->in_pixconv(ctx->input.frame, input, diff --git a/gfx/scaler/scaler_int.h b/gfx/scaler/scaler_int.h index 89d97155fa..fd901bfce4 100644 --- a/gfx/scaler/scaler_int.h +++ b/gfx/scaler/scaler_int.h @@ -18,8 +18,11 @@ #include "scaler.h" -void scaler_argb8888_vert(const struct scaler_ctx *ctx, void *output, int stride); -void scaler_argb8888_horiz(const struct scaler_ctx *ctx, const void *input, int stride); +void scaler_argb8888_vert(const struct scaler_ctx *ctx, + void *output, int stride); + +void scaler_argb8888_horiz(const struct scaler_ctx *ctx, + const void *input, int stride); void scaler_argb8888_point_special(const struct scaler_ctx *ctx, void *output, const void *input,