Sprite2DView::Sprite2DView() : sc(), directory(), shuffle_directory(), mode(), zoom(), pos(), width(), height(), aspect(), index(), sprite(), new_sprite(), fadein(), scale(), offset(), display_time(), show_thumbnail(), ignore_delta(), shuffle(), auto_scroll() { auto_scroll = false; index = 0; for(std::vector<std::string>::iterator i = arg_files.begin(); i != arg_files.end(); ++i) { if (boost::filesystem::is_directory(i->c_str())) { adddir(Pathname(*i, Pathname::kSysPath)); } else { directory.push_back(Pathname(*i, Pathname::kSysPath)); } } shuffle_directory = directory; shuffle = false; //std::sort(shuffle_directory.begin(), shuffle_directory.end()); //std::random_shuffle(shuffle_directory.begin(), shuffle_directory.end()); offset = 0.0f; if (directory.size() > 1) mode = SLIDESHOW; else mode = SLIDESHOW; zoom = 1.0f; pos = Vector2f(0,0); display_time = 0.0f; show_thumbnail = false; ignore_delta = false; next_image(0); sprite = new_sprite; new_sprite = Sprite(); }
int main(int argc, char **argv) { DARNIT_IMAGE_DATA img; DARNIT_TILESHEET *ts; IMG_STRUCT **imgs, **tmp; DARNIT_KEYS keys; int images, image_disp, i; imgs = NULL; images = 0; image_disp = 0; if (argc < 2) { fprintf(stderr, "Usage: %s <image to analyze>\n", argv[0]); return -1; } d_init("algdata", "algdata", NULL); if (!((img = d_img_load_raw(argv[1])).data)) { fprintf(stderr, "Unable to load %s\n", argv[1]); d_quit(); } d_render_clearcolor_set(255, 255, 255); do { i = 0; ts = next_image(img, &i); if (ts) { if (!(tmp = realloc(imgs, sizeof(IMG_STRUCT **) * (images + 1)))) d_quit(); imgs = tmp; imgs[images] = new_image(ts, i); images++; } } while (ts); if (!imgs) d_quit(); sort_image(imgs, images); for (;;) { keys = d_keys_get(); if (keys.start) { image_disp = (image_disp + 1 >= images) ? 0 : image_disp + 1; d_keys_set(keys); } d_render_begin(); d_render_tile_blit(imgs[image_disp]->ts, 0, 0, 0); d_render_end(); d_loop(); } return 0; }
static int scene_slideshow_forward(dword * selidx) { bool should_exit = false; if (config.imgpaging == conf_imgpaging_updown || config.imgpaging == conf_imgpaging_leftright) { xrKernelDelayThread(200000); } if (!image_paging(true, config.imgpaging)) { return -1; } next_image(selidx, &should_exit); if (should_exit) { return *selidx; } return -1; }
void prev_image(int i = 1) { next_image(-i); }
void Sprite2DView::update_slideshow(float delta, const Controller& controller) { if (!new_sprite) { width = sprite.get_width(); height = sprite.get_height(); aspect = width/height; if (aspect > 4.0/3.0) { // expand vertical float s = DISPLAY_H/height; width *= s; height *= s; sprite.set_scale(s); if (offset - (width - DISPLAY_W) > 0) { offset = (width - DISPLAY_W); if (auto_scroll && display_time > 3.0f) next_image(); } else { offset += delta * 50.0f + controller.get_axis_state(X_AXIS) * 200.0f * delta; } offset += controller.get_ball_state(MOUSE_MOTION_Y); } else { // expand horizontal float s = 800.0f/width; width *= s; height *= s; sprite.set_scale(s); if (offset - (height - DISPLAY_H) > 0) { offset = (width - DISPLAY_H); if (auto_scroll && display_time > 3.0f) next_image(); } else { offset += delta * 50.0f + controller.get_axis_state(X_AXIS) * 200.0f * delta; } offset += controller.get_ball_state(MOUSE_MOTION_Y); } } if (controller.button_was_pressed(PRIMARY_BUTTON)) { next_image(); } else if (controller.button_was_pressed(SECONDARY_BUTTON)) { prev_image(); } }
dword scene_readimage(dword selidx) { u64 timer_start, timer_end; u64 slide_start, slide_end; width_rotated = 0, height_rotated = 0, thumb_width = 0, thumb_height = 0, paintleft = 0, painttop = 0; imgdata = NULL, imgshow = NULL; oldangle = 0; curtop = 0, curleft = 0, xpos = 0, ypos = 0; img_needrf = true, img_needrc = true, img_needrp = true, showinfo = false, thumb = false; slideshow = false; now = 0, lasttime = 0; imgreading = true; if (config.imginfobar) imgh = PSP_SCREEN_HEIGHT - DISP_FONTSIZE; else imgh = PSP_SCREEN_HEIGHT; if (config.use_image_queue) { cache_setup(config.max_cache_img, &selidx); cache_set_forward(true); cache_on(true); } xrRtcGetCurrentTick(&timer_start); while (1) { u64 dbgnow, dbglasttick; dword key = 0; int ret; if (img_needrf) { int fid; dword ret; fid = freq_enter_hotzone(); xrRtcGetCurrentTick(&dbglasttick); ret = scene_reloadimage(selidx); if (ret == -1) { freq_leave(fid); break; } img_needrf = false; xrRtcGetCurrentTick(&dbgnow); dbg_printf(d, _("装载图像时间: %.2f秒"), pspDiffTime(&dbgnow, &dbglasttick)); freq_leave(fid); } if (img_needrc) { int fid; fid = freq_enter_hotzone(); xrRtcGetCurrentTick(&dbglasttick); scene_rotateimage(); img_needrc = false; xrRtcGetCurrentTick(&dbgnow); dbg_printf(d, _("旋转图像时间: %.2f秒"), pspDiffTime(&dbgnow, &dbglasttick)); freq_leave(fid); } if (img_needrp) { scene_printimage(selidx); img_needrp = false; } now = time(NULL); if (config.thumb == conf_thumb_scroll && thumb) { thumb = false; img_needrp = true; } key = ctrl_read_cont(); ret = image_handle_input(&selidx, key); if (ret == -1 && slideshow && !slideshow_move) { if (key == PSP_CTRL_CIRCLE) { } else if (key != 0 && (key == config.imgkey[1] || key == config.imgkey2[1] || key == CTRL_FORWARD)) { bool should_exit = false; next_image(&selidx, &should_exit); if (should_exit) { break; } } else if (key != 0 && (key == config.imgkey[0] || key == config.imgkey2[0] || key == CTRL_BACK)) { prev_image(&selidx); } else { xrPowerTick(0); if (config.imgpaging == conf_imgpaging_direct || config.imgpaging == conf_imgpaging_updown || config.imgpaging == conf_imgpaging_leftright) { if (now - lasttime >= config.slideinterval) { lasttime = now; ret = scene_slideshow_forward(&selidx); } } else { xrRtcGetCurrentTick(&slide_end); if (pspDiffTime(&slide_end, &slide_start) >= 0.1) { xrRtcGetCurrentTick(&slide_start); } else { lasttime = now; ret = scene_slideshow_forward(&selidx); } } } } if (showinfo && (key & PSP_CTRL_CIRCLE) == 0) { img_needrp = true; showinfo = false; } xrRtcGetCurrentTick(&timer_end); if (pspDiffTime(&timer_end, &timer_start) >= 1.0) { xrRtcGetCurrentTick(&timer_start); secticks++; } if (config.autosleep != 0 && secticks > 60 * config.autosleep) { power_down(); xrPowerRequestSuspend(); secticks = 0; } if (ret != -1) { selidx = ret; break; } scene_image_delay_action(); } reset_image_show_ptr(); if (config.use_image_queue) { cache_on(false); } imgreading = false; if (config.use_image_queue) { } else { if (imgdata != NULL) { free(imgdata); imgdata = NULL; } } if (config.use_image_queue) { // let cacher delete exif data exif_array = NULL; } else { if (exif_array) { buffer_array_free(exif_array); exif_array = NULL; } } return selidx; }
static int image_handle_input(dword * selidx, dword key) { slideshow_move = false; #ifdef ENABLE_ANALOG if (config.img_enable_analog) { int x, y, orgtop = curtop, orgleft = curleft; if (ctrl_analog(&x, &y)) { slideshow_move = true; x = x / 31 * (int) config.imgmvspd / 2; y = y / 31 * (int) config.imgmvspd / 2; curtop += y; if (curtop + imgh > height_rotated) curtop = (int) height_rotated - imgh; if (curtop < 0) curtop = 0; curleft += x; if (curleft + PSP_SCREEN_WIDTH > width_rotated) curleft = (int) width_rotated - PSP_SCREEN_WIDTH; if (curleft < 0) curleft = 0; thumb = (config.thumb == conf_thumb_scroll); img_needrp = (thumb || orgtop != curtop || orgleft != curleft); } } #endif if (key == 0) goto next; if (!slideshow || (key != CTRL_FORWARD && key != 0)) secticks = 0; if (key == (PSP_CTRL_SELECT | PSP_CTRL_START)) { return exit_confirm(); } else if (key == PSP_CTRL_SELECT) { bool lastbicubic = config.bicubic; img_needrp = true; if (scene_options(selidx)) { imgreading = false; reset_image_ptr(); return *selidx; } if (lastbicubic != config.bicubic) img_needrc = true; if (config.imginfobar) imgh = PSP_SCREEN_HEIGHT - DISP_FONTSIZE; else imgh = PSP_SCREEN_HEIGHT; } else if (key == PSP_CTRL_START) { scene_mp3bar(); img_needrp = true; } else if (key == config.imgkey[1] || key == config.imgkey2[1] || key == CTRL_FORWARD) { bool should_exit = false; if (config.imgpaging == conf_imgpaging_updown || config.imgpaging == conf_imgpaging_leftright) xrKernelDelayThread(200000); if (!image_paging(true, config.imgpaging)) goto next; next_image(selidx, &should_exit); if (should_exit) { return *selidx; } } else if (key == config.imgkey[0] || key == config.imgkey2[0] || key == CTRL_BACK) { if (config.imgpaging == conf_imgpaging_updown || config.imgpaging == conf_imgpaging_leftright) xrKernelDelayThread(200000); if (!image_paging(false, config.imgpaging)) goto next; prev_image(selidx); } else if (key == config.imgkey[2] || key == config.imgkey2[2]) { ctrl_waitrelease(); if (config.fit == conf_fit_custom) config.fit = conf_fit_none; else config.fit++; img_needrc = img_needrp = true; } else if (key == config.imgkey[10] || key == config.imgkey2[10]) { config.bicubic = !config.bicubic; img_needrc = img_needrp = true; } else if (key == config.imgkey[11] || key == config.imgkey2[11]) { if (!slideshow) { slideshow = true; lasttime = time(NULL); ctrl_waitrelease(); } else { slideshow = false; win_msg(_("幻灯片播放已经停止!"), COLOR_WHITE, COLOR_WHITE, config.msgbcolor); ctrl_waitrelease(); } } else if (key == config.imgkey[7] || key == config.imgkey2[7]) { SceCtrlData ctl; int t = 0; config.imginfobar = !config.imginfobar; if (config.imginfobar) imgh = PSP_SCREEN_HEIGHT - DISP_FONTSIZE; else imgh = PSP_SCREEN_HEIGHT; if (height_rotated > imgh && curtop > height_rotated - imgh) curtop = height_rotated - imgh; img_needrc = (config.fit == conf_fit_height); img_needrp = true; do { xrCtrlReadBufferPositive(&ctl, 1); xrKernelDelayThread(10000); t += 10000; } while (ctl.Buttons != 0 && t <= 500000); } else if (key == config.imgkey[9] || key == config.imgkey2[9] || key == CTRL_PLAYPAUSE) { if (slideshow) { slideshow = false; win_msg(_("幻灯片播放已经停止!"), COLOR_WHITE, COLOR_WHITE, config.msgbcolor); ctrl_waitrelease(); } else { imgreading = false; reset_image_ptr(); return *selidx; } } else if (key == config.imgkey[8] || key == config.imgkey2[8]) { if (!slideshow && !showinfo) { img_needrp = true; showinfo = true; } } else if (key == config.imgkey[5] || key == config.imgkey2[5]) { if (config.rotate == conf_rotate_0) config.rotate = conf_rotate_270; else config.rotate--; ctrl_waitreleasekey(key); img_needrc = img_needrp = true; } else if (key == config.imgkey[6] || key == config.imgkey2[6]) { if (config.rotate == conf_rotate_270) config.rotate = conf_rotate_0; else config.rotate++; ctrl_waitreleasekey(key); img_needrc = img_needrp = true; } else if (key == config.imgkey[3] || key == config.imgkey2[3]) { if (config.scale > 200) config.scale -= 50; else if (config.scale > 10) config.scale -= 5; else goto next; config.fit = conf_fit_custom; img_needrc = img_needrp = true; ctrl_waitreleasekey(key); } else if (key == config.imgkey[4] || key == config.imgkey2[4]) { if (config.scale < 200) config.scale += 5; else if (config.scale < 1000) config.scale += 50; else goto next; config.fit = conf_fit_custom; img_needrc = img_needrp = true; ctrl_waitreleasekey(key); } else if (key & (config.imgkey[12] | config.imgkey[13] | config. imgkey[14] | config.imgkey[15] | config.imgkey2[12] | config. imgkey2[13] | config.imgkey2[14] | config.imgkey2[15]) && !(key & ~(config.imgkey[12] | config.imgkey[13] | config. imgkey[14] | config.imgkey[15] | config. imgkey2[12] | config.imgkey2[13] | config. imgkey2[14] | config.imgkey2[15] ))) { slideshow_move = true; image_move(key); } else img_needrf = img_needrc = false; next: return -1; }