int run_emu(const char *path) { SceCtrlData pad; unsigned int joypad1, joypad2; setup_audio(); emu->set_sample_rate(44100); emu->set_equalizer(Nes_Emu::nes_eq); emu->set_palette_range(0); vita2d_texture *tex = vita2d_create_empty_texture(Nes_Emu::image_width, Nes_Emu::image_height); void *tex_data = vita2d_texture_get_datap(tex); static uint32_t video_buffer[Nes_Emu::image_width * Nes_Emu::image_height]; emu->set_pixels(video_buffer, Nes_Emu::image_width); Auto_File_Reader freader(path); emu->load_ines(freader); int scale = 2; int pos_x = SCREEN_W/2 - (Nes_Emu::image_width/2)*scale; int pos_y = SCREEN_H/2 - (Nes_Emu::image_height/2)*scale; while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if ((pad.buttons & CHANGE_GAME_MASK) == CHANGE_GAME_MASK) break; joypad1 = joypad2 = update_input(&pad); emu->emulate_frame(joypad1, joypad2); const Nes_Emu::frame_t &frame = emu->frame(); const uint8_t *in_pixels = frame.pixels; uint32_t *out_pixels = (uint32_t *)tex_data; for (unsigned h = 0; h < Nes_Emu::image_height; h++, in_pixels += frame.pitch, out_pixels += Nes_Emu::image_width) { for (unsigned w = 0; w < Nes_Emu::image_width; w++) { unsigned col = frame.palette[in_pixels[w]]; const Nes_Emu::rgb_t& rgb = emu->nes_colors[col]; unsigned r = rgb.red; unsigned g = rgb.green; unsigned b = rgb.blue; out_pixels[w] = 0xFF000000 | (r << 0) | (g << 8) | (b << 16); } } vita2d_start_drawing(); vita2d_clear_screen(); vita2d_draw_texture_scale(tex, pos_x, pos_y, scale, scale); show_fps(); vita2d_end_drawing(); vita2d_swap_buffers(); } return 0; }
static void vita_set_texture_frame(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { int i, j; void *tex_p; unsigned int stride; vita_video_t *vita = (vita_video_t*)data; (void)alpha; if (width != vita->menu.width && height != vita->menu.height && vita->menu.texture) { vita2d_free_texture(vita->menu.texture); vita->menu.texture = NULL; } if (!vita->menu.texture) { if (rgb32) { vita->menu.texture = vita2d_create_empty_texture(width, height); RARCH_LOG("Creating Frame RGBA8 texture: w: %i h: %i\n", width, height); } else { vita->menu.texture = vita2d_create_empty_texture_format(width, height, SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_RGBA); RARCH_LOG("Creating Frame R5G6B5 texture: w: %i h: %i\n", width, height); } vita->menu.width = width; vita->menu.height = height; } vita2d_texture_set_filters(vita->menu.texture,SCE_GXM_TEXTURE_FILTER_LINEAR,SCE_GXM_TEXTURE_FILTER_LINEAR); tex_p = vita2d_texture_get_datap(vita->menu.texture); stride = vita2d_texture_get_stride(vita->menu.texture); if (rgb32) { uint32_t *tex32 = tex_p; const uint32_t *frame32 = frame; stride /= 4; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex32[j + i*stride] = frame32[j + i*width]; } else { uint16_t *tex16 = tex_p; const uint16_t *frame16 = frame; stride /= 2; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex16[j + i*stride] = frame16[j + i*width]; } }
int main() { vita2d_init(); vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); vita2d_pgf *pgf = vita2d_load_default_pgf(); vita2d_texture *tex = vita2d_create_empty_texture(128, 128); unsigned int *tex_data = vita2d_texture_get_datap(tex); SceCtrlData pad; memset(&pad, 0, sizeof(pad)); float rad = 0.0f; while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_START) break; vita2d_start_drawing(); vita2d_clear_screen(); vita2d_draw_rectangle(20, 20, 400, 250, RGBA8(255, 0, 0, 255)); vita2d_draw_rectangle(680, 350, 100, 150, RGBA8(0, 0, 255, 255)); vita2d_draw_fill_circle(200, 420, 100, RGBA8(0, 255,0 ,255)); /* Fill the texture with random data */ int i, j; for (i = 0; i < 128; i++) { for (j = 0; j < 128; j++) { tex_data[j + i*128] = rand(); } } vita2d_draw_texture_rotate(tex, 940/2, 544/2, rad); vita2d_draw_line(500, 30, 800, 300, RGBA8(255, 0, 255, 255)); vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0,255,0,255), 1.0f, "PGF Font sample!"); vita2d_end_drawing(); vita2d_swap_buffers(); rad += 0.1f; } vita2d_fini(); vita2d_free_texture(tex); vita2d_free_pgf(pgf); sceKernelExitProcess(0); return 0; }
void show_splash() { vita2d_start_drawing(); vita2d_clear_screen(); vita2d_texture *splash = vita2d_create_empty_texture(960, 544); splash = vita2d_load_PNG_buffer(revitalize); vita2d_draw_texture(splash, 0, 0); vita2d_end_drawing(); vita2d_swap_buffers(); sceKernelDelayThread(5000000); // Delay 5 seconds vita2d_free_texture(splash); }
static void init(void) { vita2d_init(); vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); fullscreen_scale_x = SCREEN_W / (float)GAMEBOY_WIDTH; fullscreen_scale_y = SCREEN_H / (float)GAMEBOY_HEIGHT; gb_texture = vita2d_create_empty_texture(GAMEBOY_WIDTH, GAMEBOY_HEIGHT); gb_texture_pixels = vita2d_texture_get_datap(gb_texture); set_scale(3); theGearboyCore = new GearboyCore(); theGearboyCore->Init(); }
/* Programme "Flocon de Koch" */ int main(int argc, char *argv[]) { struct parameters parameters; struct list *koch = NULL; uint32_t *picture = NULL; char *outfile = NULL; bool screenshots = false; srand(time(NULL)); #ifdef PSP2 vita2d_init(); vita2d_set_clear_color(RGBA8(0, 0, 0, 0xFF)); vita2d_texture *tex = vita2d_create_empty_texture(960, 544); uint32_t *tex_data = vita2d_texture_get_datap(tex); SceCtrlData pad, lastbuttons; memset(&pad, 0, sizeof(pad)); #endif /* Initialisations */ init_parameters(¶meters, argc, argv); show_parameters(parameters); init_koch(&koch, parameters.image_size, parameters.segment_length); outfile = malloc(3 + strlen(parameters.outfile) + 1); int32_t i = 0, step = 1; bool done = false; /* Génération de chaque flocon */ while (!done) { #ifdef PSP2 lastbuttons = pad; sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & PSP2_CTRL_TRIANGLE) break; if (PRESSED(lastbuttons.buttons, pad.buttons, PSP2_CTRL_LTRIGGER)) parameters.fg_color = RGBA8(rand()%255, rand()%255, rand()%255, 255); //if (PRESSED(lastbuttons.buttons, pad.buttons, PSP2_CTRL_RTRIGGER)) // screenshots ^= 1; vita2d_start_drawing(); vita2d_clear_screen(); #endif sprintf(outfile, "%02d_%s", i, parameters.outfile); if (step > 0) generer_koch(koch, i); else { for (uint32_t j = 0; j < i; j++) generer_koch(koch, j); } //show_koch_list(koch); /* Ne générer l'image que si c'est la dernière ou qu'on les génère toutes */ if (parameters.all_images || i == parameters.nb_iterations) { init_picture(&picture, parameters.image_size, parameters.bg_color); render_image_bresenham(picture, koch, parameters.image_size, parameters.fg_color); #ifndef PSP2 const uint32_t LEN = 960 * 544; uint32_t *data = calloc(LEN, sizeof(uint32_t)); for (uint32_t i = 0; i < LEN; i++) data[i] = 0; uint32_t k = 0; for (uint32_t i = 0; i < 544; i++) for (uint32_t j = 0; j < 960; j++) { if (208 <= j && j < 752 && k < 544*544) data[i * 960 + j] = picture[k++]; else data[i * 960 + j] = 0; } create_image(data, 960, 544, outfile); //create_image(picture, parameters.image_size, parameters.image_size, outfile); #else uint32_t k = 0; for (uint32_t i = 0; i < 544; i++) for (uint32_t j = 0; j < 960; j++) { if (208 <= j && j < 752 && k < 544*544) tex_data[i * 960 + j] = picture[k++]; else tex_data[i * 960 + j] = 0; } if (screenshots) create_image(tex_data, 960, 544, outfile); #endif } #ifdef PSP2 vita2d_draw_texture(tex, 0, 0); vita2d_end_drawing(); vita2d_swap_buffers(); sceKernelDelayThread(100000); #endif i = i + step; if (i == parameters.nb_iterations) #ifdef PSP2 i--, step = -1; #else done = true; #endif else if (i == 0) { step = 1; free_koch(koch); init_koch(&koch, parameters.image_size, parameters.segment_length); } if (step < 0) { free_koch(koch); init_koch(&koch, parameters.image_size, parameters.segment_length); } if (parameters.nb_iterations == 1) done = true; }
void loadTheme() { #define COLOR_ENTRY(name) { #name, CONFIG_TYPE_HEXDECIMAL, (void *)&name } ConfigEntry colors_entries[] = { // Shell colors COLOR_ENTRY(BACKGROUND_COLOR), COLOR_ENTRY(TITLE_COLOR), COLOR_ENTRY(PATH_COLOR), COLOR_ENTRY(DATE_TIME_COLOR), // Settings colors COLOR_ENTRY(SETTINGS_MENU_COLOR), COLOR_ENTRY(SETTINGS_MENU_FOCUS_COLOR), COLOR_ENTRY(SETTINGS_MENU_TITLE_COLOR), COLOR_ENTRY(SETTINGS_MENU_ITEM_COLOR), COLOR_ENTRY(SETTINGS_MENU_OPTION_COLOR), // File browser colors COLOR_ENTRY(FOCUS_COLOR), COLOR_ENTRY(FILE_COLOR), COLOR_ENTRY(SFO_COLOR), COLOR_ENTRY(TXT_COLOR), COLOR_ENTRY(FOLDER_COLOR), COLOR_ENTRY(IMAGE_COLOR), COLOR_ENTRY(ARCHIVE_COLOR), COLOR_ENTRY(SCROLL_BAR_COLOR), COLOR_ENTRY(SCROLL_BAR_BG_COLOR), COLOR_ENTRY(MARKED_COLOR), // Context menu colors COLOR_ENTRY(CONTEXT_MENU_TEXT_COLOR), COLOR_ENTRY(CONTEXT_MENU_FOCUS_COLOR), COLOR_ENTRY(CONTEXT_MENU_COLOR), COLOR_ENTRY(CONTEXT_MENU_MORE_COLOR), COLOR_ENTRY(INVISIBLE_COLOR), // Dialog colors COLOR_ENTRY(DIALOG_COLOR), COLOR_ENTRY(DIALOG_BG_COLOR), COLOR_ENTRY(PROGRESS_BAR_COLOR), COLOR_ENTRY(PROGRESS_BAR_BG_COLOR), // Hex editor colors COLOR_ENTRY(HEX_COLOR), COLOR_ENTRY(HEX_OFFSET_COLOR), COLOR_ENTRY(HEX_NIBBLE_COLOR), // Text editor colors COLOR_ENTRY(TEXT_COLOR), COLOR_ENTRY(TEXT_FOCUS_COLOR), COLOR_ENTRY(TEXT_LINE_NUMBER_COLOR), COLOR_ENTRY(TEXT_LINE_NUMBER_COLOR_FOCUS), COLOR_ENTRY(TEXT_HIGHLIGHT_COLOR), // Photo viewer colors COLOR_ENTRY(PHOTO_ZOOM_COLOR), // Audio player colors COLOR_ENTRY(AUDIO_INFO_ASSIGN), COLOR_ENTRY(AUDIO_INFO), COLOR_ENTRY(AUDIO_SPEED), COLOR_ENTRY(AUDIO_TIME_CURRENT), COLOR_ENTRY(AUDIO_TIME_SLASH), COLOR_ENTRY(AUDIO_TIME_TOTAL), COLOR_ENTRY(AUDIO_TIME_BAR), COLOR_ENTRY(AUDIO_TIME_BAR_BG), }; int i; // Load default config file readConfigBuffer(&_binary_resources_colors_txt_start, (int)&_binary_resources_colors_txt_size, colors_entries, sizeof(colors_entries) / sizeof(ConfigEntry)); // Load custom config file if (use_custom_config) { char path[MAX_PATH_LENGTH]; char *theme_name = NULL; ConfigEntry theme_entries[] = { { "THEME_NAME", CONFIG_TYPE_STRING, (void *)&theme_name }, }; // Load theme config readConfig("ux0:VitaShell/theme/theme.txt", theme_entries, sizeof(theme_entries) / sizeof(ConfigEntry)); if (theme_name) { // Load colors config snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/colors.txt", theme_name); readConfig(path, colors_entries, sizeof(colors_entries) / sizeof(ConfigEntry)); // Font snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/font.pgf", theme_name); font = vita2d_load_custom_pgf(path); // Load theme for (i = 0; i < N_THEME_IMAGES; i++) { snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/%s", theme_name, theme_images[i].name); if (theme_images[i].texture && *(theme_images[i].texture) == NULL) *(theme_images[i].texture) = vita2d_load_PNG_file(path); } } } // Load default theme for (i = 0; i < N_THEME_IMAGES; i++) { if (theme_images[i].texture && *(theme_images[i].texture) == NULL && theme_images[i].default_buf) *(theme_images[i].texture) = vita2d_load_PNG_buffer(theme_images[i].default_buf); } // Load default pngs if (!dialog_image) { dialog_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT); void *data = vita2d_texture_get_datap(dialog_image); int y; for (y = 0; y < SCREEN_HEIGHT; y++) { int x; for (x = 0; x < SCREEN_WIDTH; x++) { ((uint32_t *)data)[x + SCREEN_WIDTH * y] = DIALOG_BG_COLOR; } } } if (!context_image) { context_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT); void *data = vita2d_texture_get_datap(context_image); int y; for (y = 0; y < SCREEN_HEIGHT; y++) { int x; for (x = 0; x < SCREEN_WIDTH; x++) { ((uint32_t *)data)[x + SCREEN_WIDTH * y] = CONTEXT_MENU_COLOR; } } } if (!context_more_image) { context_more_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT); void *data = vita2d_texture_get_datap(context_more_image); int y; for (y = 0; y < SCREEN_HEIGHT; y++) { int x; for (x = 0; x < SCREEN_WIDTH; x++) { ((uint32_t *)data)[x + SCREEN_WIDTH * y] = CONTEXT_MENU_MORE_COLOR; } } } if (!settings_image) { settings_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT); void *data = vita2d_texture_get_datap(settings_image); int y; for (y = 0; y < SCREEN_HEIGHT; y++) { int x; for (x = 0; x < SCREEN_WIDTH; x++) { ((uint32_t *)data)[x + SCREEN_WIDTH * y] = SETTINGS_MENU_COLOR; } } } // Load system fonts if (!font) font = loadSystemFonts(); // Font size cache for (i = 0; i < 256; i++) { char character[2]; character[0] = i; character[1] = '\0'; font_size_cache[i] = vita2d_pgf_text_width(font, FONT_SIZE, character); } }
static vita2d_texture *_vita2d_load_PNG_generic(const void *io_ptr, png_rw_ptr read_data_fn) { png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { goto error_create_read; } png_infop info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { goto error_create_info; } png_bytep *row_ptrs = NULL; if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0); if (row_ptrs != NULL) free(row_ptrs); return NULL; } png_set_read_fn(png_ptr, (png_voidp)io_ptr, read_data_fn); png_set_sig_bytes(png_ptr, PNG_SIGSIZE); png_read_info(png_ptr, info_ptr); unsigned int width, height; int bit_depth, color_type; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL); if ((color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8) || (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) || png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) || (bit_depth == 16)) { png_set_expand(png_ptr); } if (bit_depth == 16) png_set_scale_16(png_ptr); if (bit_depth == 8 && color_type == PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER); if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); if (color_type == PNG_COLOR_TYPE_PALETTE) { png_set_palette_to_rgb(png_ptr); png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER); } if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); if (bit_depth < 8) png_set_packing(png_ptr); png_read_update_info(png_ptr, info_ptr); row_ptrs = (png_bytep *)malloc(sizeof(png_bytep) * height); if (!row_ptrs) goto error_alloc_rows; vita2d_texture *texture = vita2d_create_empty_texture(width, height); if (!texture) goto error_create_tex; void *texture_data = vita2d_texture_get_datap(texture); unsigned int stride = vita2d_texture_get_stride(texture); int i; for (i = 0; i < height; i++) { row_ptrs[i] = (png_bytep)(texture_data + i*stride); } png_read_image(png_ptr, row_ptrs); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0); free(row_ptrs); return texture; error_create_tex: free(row_ptrs); error_alloc_rows: png_destroy_info_struct(png_ptr, &info_ptr); error_create_info: png_destroy_read_struct(&png_ptr, (png_infopp)0, (png_infopp)0); error_create_read: return NULL; }