From f0448375624d7d81808995ebb3a2f9352c21dfc4 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Thu, 19 Nov 2015 23:38:59 +0000 Subject: Rename imv_image -> imv_loader to prepare for refactoring --- src/image.c | 239 --------------------------------------------------------- src/image.h | 47 ------------ src/loader.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/loader.h | 47 ++++++++++++ src/main.c | 40 +++++----- src/viewport.c | 45 ++++++----- src/viewport.h | 14 ++-- 7 files changed, 335 insertions(+), 336 deletions(-) delete mode 100644 src/image.c delete mode 100644 src/image.h create mode 100644 src/loader.c create mode 100644 src/loader.h diff --git a/src/image.c b/src/image.c deleted file mode 100644 index 64fa3b8..0000000 --- a/src/image.c +++ /dev/null @@ -1,239 +0,0 @@ -/* Copyright (c) 2015 Harry Jeffery - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "image.h" - -void imv_init_image(struct imv_image *img) -{ - img->mbmp = NULL; - img->cur_bmp = NULL; - img->width = 0; - img->height = 0; - img->cur_frame = 0; - img->next_frame = 0; - img->num_frames = 0; - img->frame_time = 0; - img->changed = 0; -} - -void imv_destroy_image(struct imv_image *img) -{ - if(img->cur_bmp) { - FreeImage_Unload(img->cur_bmp); - img->cur_bmp = NULL; - } - if(img->mbmp) { - FreeImage_CloseMultiBitmap(img->mbmp, 0); - img->mbmp = NULL; - } -} - -int imv_can_load_image(const char* path) -{ - if(FreeImage_GetFileType(path, 0) == FIF_UNKNOWN) { - return 0; - } else { - return 1; - } -} - -int imv_image_load(struct imv_image *img, const char* path) -{ - if(img->mbmp) { - FreeImage_CloseMultiBitmap(img->mbmp, 0); - img->mbmp = NULL; - } - - if(img->cur_bmp) { - FreeImage_Unload(img->cur_bmp); - img->cur_bmp = NULL; - } - - - FREE_IMAGE_FORMAT fmt = FreeImage_GetFileType(path,0); - - if(fmt == FIF_UNKNOWN) { - return 1; - } - - img->num_frames = 0; - img->cur_frame = 0; - img->next_frame = 0; - img->frame_time = 0; - - if(fmt == FIF_GIF) { - img->mbmp = FreeImage_OpenMultiBitmap(FIF_GIF, path, - /* don't create file */ 0, - /* read only */ 1, - /* keep in memory */ 1, - /* flags */ GIF_LOAD256); - if(!img->mbmp) { - return 1; - } - img->num_frames = FreeImage_GetPageCount(img->mbmp); - - /* get the dimensions from the first frame */ - FIBITMAP *frame = FreeImage_LockPage(img->mbmp, 0); - img->width = FreeImage_GetWidth(frame); - img->height = FreeImage_GetHeight(frame); - if(!imv_image_is_animated(img)) { - img->cur_bmp = FreeImage_ConvertTo32Bits(frame); - } - FreeImage_UnlockPage(img->mbmp, frame, 0); - - if(imv_image_is_animated(img)) { - /* load a frame */ - imv_image_load_next_frame(img); - } - } else { - FIBITMAP *image = FreeImage_Load(fmt, path, 0); - if(!image) { - return 1; - } - img->cur_bmp = FreeImage_ConvertTo32Bits(image); - img->width = FreeImage_GetWidth(img->cur_bmp); - img->height = FreeImage_GetHeight(img->cur_bmp); - FreeImage_Unload(image); - } - - img->changed = 1; - return 0; -} - -void imv_image_load_next_frame(struct imv_image *img) -{ - if(!imv_image_is_animated(img)) { - return; - } - - FITAG *tag = NULL; - char disposal_method = 0; - int frame_time = 0; - short top = 0; - short left = 0; - - img->cur_frame = img->next_frame; - img->next_frame = (img->cur_frame + 1) % img->num_frames; - FIBITMAP *frame = FreeImage_LockPage(img->mbmp, img->cur_frame); - FIBITMAP *frame32 = FreeImage_ConvertTo32Bits(frame); - - /* First frame is always going to use the raw frame */ - if(img->cur_frame > 0) { - FreeImage_GetMetadata(FIMD_ANIMATION, frame, "DisposalMethod", &tag); - if(FreeImage_GetTagValue(tag)) { - disposal_method = *(char*)FreeImage_GetTagValue(tag); - } - } - - FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameLeft", &tag); - if(FreeImage_GetTagValue(tag)) { - left = *(short*)FreeImage_GetTagValue(tag); - } - - FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameTop", &tag); - if(FreeImage_GetTagValue(tag)) { - top = *(short*)FreeImage_GetTagValue(tag); - } - - FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameTime", &tag); - if(FreeImage_GetTagValue(tag)) { - frame_time = *(int*)FreeImage_GetTagValue(tag); - } - - /* some gifs don't provide a frame time at all */ - if(frame_time == 0) { - frame_time = 100; - } - img->frame_time += frame_time * 0.001; - - FreeImage_UnlockPage(img->mbmp, frame, 0); - - /* If this frame is inset, we need to expand it for compositing */ - if(img->width != (int)FreeImage_GetWidth(frame32) || - img->height != (int)FreeImage_GetHeight(frame32)) { - FIBITMAP *expanded = FreeImage_Allocate(img->width, img->height, 32, 0,0,0); - FreeImage_Paste(expanded, frame32, left, top, 255); - FreeImage_Unload(frame32); - frame32 = expanded; - } - - switch(disposal_method) { - case 0: /* nothing specified, just use the raw frame */ - if(img->cur_bmp) { - FreeImage_Unload(img->cur_bmp); - } - img->cur_bmp = frame32; - break; - case 1: /* composite over previous frame */ - if(img->cur_bmp && img->cur_frame > 0) { - FIBITMAP *bg_frame = FreeImage_ConvertTo24Bits(img->cur_bmp); - FreeImage_Unload(img->cur_bmp); - FIBITMAP *comp = FreeImage_Composite(frame32, 1, NULL, bg_frame); - FreeImage_Unload(bg_frame); - FreeImage_Unload(frame32); - img->cur_bmp = comp; - } else { - /* No previous frame, just render directly */ - if(img->cur_bmp) { - FreeImage_Unload(img->cur_bmp); - } - img->cur_bmp = frame32; - } - break; - case 2: /* TODO - set to background, composite over that */ - if(img->cur_bmp) { - FreeImage_Unload(img->cur_bmp); - } - img->cur_bmp = frame32; - break; - case 3: /* TODO - restore to previous content */ - if(img->cur_bmp) { - FreeImage_Unload(img->cur_bmp); - } - img->cur_bmp = frame32; - break; - } - img->changed = 1; -} - -int imv_image_is_animated(struct imv_image *img) -{ - return img->num_frames > 1; -} - -void imv_image_play(struct imv_image *img, double time) -{ - if(!imv_image_is_animated(img)) { - return; - } - - img->frame_time -= time; - if(img->frame_time < 0) { - img->frame_time = 0; - imv_image_load_next_frame(img); - } -} - -int imv_image_has_changed(struct imv_image *img) -{ - if(img->changed) { - img->changed = 0; - return 1; - } else { - return 0; - } -} diff --git a/src/image.h b/src/image.h deleted file mode 100644 index 96f0d51..0000000 --- a/src/image.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef IMV_IMAGE_H -#define IMV_IMAGE_H - -/* Copyright (c) 2015 Harry Jeffery - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include - -struct imv_image { - FIMULTIBITMAP *mbmp; - FIBITMAP *cur_bmp; - int width; - int height; - int cur_frame; - int next_frame; - int num_frames; - int changed; - double frame_time; -}; - -void imv_init_image(struct imv_image *img); -void imv_destroy_image(struct imv_image *img); - -int imv_can_load_image(const char* path); -int imv_image_load(struct imv_image *img, const char* path); -void imv_image_load_next_frame(struct imv_image *img); - -int imv_image_is_animated(struct imv_image *img); -void imv_image_play(struct imv_image *img, double time); - -int imv_image_has_changed(struct imv_image *img); - -#endif diff --git a/src/loader.c b/src/loader.c new file mode 100644 index 0000000..c9c5976 --- /dev/null +++ b/src/loader.c @@ -0,0 +1,239 @@ +/* Copyright (c) 2015 Harry Jeffery + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "loader.h" + +void imv_init_loader(struct imv_loader *ldr) +{ + ldr->mbmp = NULL; + ldr->cur_bmp = NULL; + ldr->width = 0; + ldr->height = 0; + ldr->cur_frame = 0; + ldr->next_frame = 0; + ldr->num_frames = 0; + ldr->frame_time = 0; + ldr->changed = 0; +} + +void imv_destroy_loader(struct imv_loader *ldr) +{ + if(ldr->cur_bmp) { + FreeImage_Unload(ldr->cur_bmp); + ldr->cur_bmp = NULL; + } + if(ldr->mbmp) { + FreeImage_CloseMultiBitmap(ldr->mbmp, 0); + ldr->mbmp = NULL; + } +} + +int imv_can_load_image(const char* path) +{ + if(FreeImage_GetFileType(path, 0) == FIF_UNKNOWN) { + return 0; + } else { + return 1; + } +} + +int imv_loader_load(struct imv_loader *ldr, const char* path) +{ + if(ldr->mbmp) { + FreeImage_CloseMultiBitmap(ldr->mbmp, 0); + ldr->mbmp = NULL; + } + + if(ldr->cur_bmp) { + FreeImage_Unload(ldr->cur_bmp); + ldr->cur_bmp = NULL; + } + + + FREE_IMAGE_FORMAT fmt = FreeImage_GetFileType(path,0); + + if(fmt == FIF_UNKNOWN) { + return 1; + } + + ldr->num_frames = 0; + ldr->cur_frame = 0; + ldr->next_frame = 0; + ldr->frame_time = 0; + + if(fmt == FIF_GIF) { + ldr->mbmp = FreeImage_OpenMultiBitmap(FIF_GIF, path, + /* don't create file */ 0, + /* read only */ 1, + /* keep in memory */ 1, + /* flags */ GIF_LOAD256); + if(!ldr->mbmp) { + return 1; + } + ldr->num_frames = FreeImage_GetPageCount(ldr->mbmp); + + /* get the dimensions from the first frame */ + FIBITMAP *frame = FreeImage_LockPage(ldr->mbmp, 0); + ldr->width = FreeImage_GetWidth(frame); + ldr->height = FreeImage_GetHeight(frame); + if(!imv_loader_is_animated(ldr)) { + ldr->cur_bmp = FreeImage_ConvertTo32Bits(frame); + } + FreeImage_UnlockPage(ldr->mbmp, frame, 0); + + if(imv_loader_is_animated(ldr)) { + /* load a frame */ + imv_loader_load_next_frame(ldr); + } + } else { + FIBITMAP *image = FreeImage_Load(fmt, path, 0); + if(!image) { + return 1; + } + ldr->cur_bmp = FreeImage_ConvertTo32Bits(image); + ldr->width = FreeImage_GetWidth(ldr->cur_bmp); + ldr->height = FreeImage_GetHeight(ldr->cur_bmp); + FreeImage_Unload(image); + } + + ldr->changed = 1; + return 0; +} + +void imv_loader_load_next_frame(struct imv_loader *ldr) +{ + if(!imv_loader_is_animated(ldr)) { + return; + } + + FITAG *tag = NULL; + char disposal_method = 0; + int frame_time = 0; + short top = 0; + short left = 0; + + ldr->cur_frame = ldr->next_frame; + ldr->next_frame = (ldr->cur_frame + 1) % ldr->num_frames; + FIBITMAP *frame = FreeImage_LockPage(ldr->mbmp, ldr->cur_frame); + FIBITMAP *frame32 = FreeImage_ConvertTo32Bits(frame); + + /* First frame is always going to use the raw frame */ + if(ldr->cur_frame > 0) { + FreeImage_GetMetadata(FIMD_ANIMATION, frame, "DisposalMethod", &tag); + if(FreeImage_GetTagValue(tag)) { + disposal_method = *(char*)FreeImage_GetTagValue(tag); + } + } + + FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameLeft", &tag); + if(FreeImage_GetTagValue(tag)) { + left = *(short*)FreeImage_GetTagValue(tag); + } + + FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameTop", &tag); + if(FreeImage_GetTagValue(tag)) { + top = *(short*)FreeImage_GetTagValue(tag); + } + + FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameTime", &tag); + if(FreeImage_GetTagValue(tag)) { + frame_time = *(int*)FreeImage_GetTagValue(tag); + } + + /* some gifs don't provide a frame time at all */ + if(frame_time == 0) { + frame_time = 100; + } + ldr->frame_time += frame_time * 0.001; + + FreeImage_UnlockPage(ldr->mbmp, frame, 0); + + /* If this frame is inset, we need to expand it for compositing */ + if(ldr->width != (int)FreeImage_GetWidth(frame32) || + ldr->height != (int)FreeImage_GetHeight(frame32)) { + FIBITMAP *expanded = FreeImage_Allocate(ldr->width, ldr->height, 32, 0,0,0); + FreeImage_Paste(expanded, frame32, left, top, 255); + FreeImage_Unload(frame32); + frame32 = expanded; + } + + switch(disposal_method) { + case 0: /* nothing specified, just use the raw frame */ + if(ldr->cur_bmp) { + FreeImage_Unload(ldr->cur_bmp); + } + ldr->cur_bmp = frame32; + break; + case 1: /* composite over previous frame */ + if(ldr->cur_bmp && ldr->cur_frame > 0) { + FIBITMAP *bg_frame = FreeImage_ConvertTo24Bits(ldr->cur_bmp); + FreeImage_Unload(ldr->cur_bmp); + FIBITMAP *comp = FreeImage_Composite(frame32, 1, NULL, bg_frame); + FreeImage_Unload(bg_frame); + FreeImage_Unload(frame32); + ldr->cur_bmp = comp; + } else { + /* No previous frame, just render directly */ + if(ldr->cur_bmp) { + FreeImage_Unload(ldr->cur_bmp); + } + ldr->cur_bmp = frame32; + } + break; + case 2: /* TODO - set to background, composite over that */ + if(ldr->cur_bmp) { + FreeImage_Unload(ldr->cur_bmp); + } + ldr->cur_bmp = frame32; + break; + case 3: /* TODO - restore to previous content */ + if(ldr->cur_bmp) { + FreeImage_Unload(ldr->cur_bmp); + } + ldr->cur_bmp = frame32; + break; + } + ldr->changed = 1; +} + +int imv_loader_is_animated(struct imv_loader *ldr) +{ + return ldr->num_frames > 1; +} + +void imv_loader_play(struct imv_loader *ldr, double time) +{ + if(!imv_loader_is_animated(ldr)) { + return; + } + + ldr->frame_time -= time; + if(ldr->frame_time < 0) { + ldr->frame_time = 0; + imv_loader_load_next_frame(ldr); + } +} + +int imv_loader_has_changed(struct imv_loader *ldr) +{ + if(ldr->changed) { + ldr->changed = 0; + return 1; + } else { + return 0; + } +} diff --git a/src/loader.h b/src/loader.h new file mode 100644 index 0000000..02d53ad --- /dev/null +++ b/src/loader.h @@ -0,0 +1,47 @@ +#ifndef IMV_IMAGE_H +#define IMV_IMAGE_H + +/* Copyright (c) 2015 Harry Jeffery + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include + +struct imv_loader { + FIMULTIBITMAP *mbmp; + FIBITMAP *cur_bmp; + int width; + int height; + int cur_frame; + int next_frame; + int num_frames; + int changed; + double frame_time; +}; + +void imv_init_loader(struct imv_loader *img); +void imv_destroy_loader(struct imv_loader *img); + +int imv_can_load_image(const char* path); +int imv_loader_load(struct imv_loader *img, const char* path); +void imv_loader_load_next_frame(struct imv_loader *img); + +int imv_loader_is_animated(struct imv_loader *img); +void imv_loader_play(struct imv_loader *img, double time); + +int imv_loader_has_changed(struct imv_loader *img); + +#endif diff --git a/src/main.c b/src/main.c index 8e7f6a1..ed17366 100644 --- a/src/main.c +++ b/src/main.c @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include -#include "image.h" +#include "loader.h" #include "texture.h" #include "navigator.h" #include "viewport.h" @@ -273,8 +273,8 @@ int main(int argc, char** argv) SDL_Surface *overlay_surf = NULL; SDL_Texture *overlay_tex = NULL; - struct imv_image img; - imv_init_image(&img); + struct imv_loader ldr; + imv_init_loader(&ldr); struct imv_texture tex; imv_init_texture(&tex, renderer); @@ -309,24 +309,24 @@ int main(int argc, char** argv) case SDLK_EQUALS: case SDLK_i: case SDLK_UP: - imv_viewport_zoom(&view, &img, IMV_ZOOM_KEYBOARD, 1); + imv_viewport_zoom(&view, &ldr, IMV_ZOOM_KEYBOARD, 1); break; case SDLK_MINUS: case SDLK_o: case SDLK_DOWN: - imv_viewport_zoom(&view, &img, IMV_ZOOM_KEYBOARD, -1); + imv_viewport_zoom(&view, &ldr, IMV_ZOOM_KEYBOARD, -1); break; - case SDLK_a: imv_viewport_scale_to_actual(&view, &img);break; - case SDLK_r: imv_viewport_scale_to_window(&view, &img);break; - case SDLK_c: imv_viewport_center(&view, &img); break; + case SDLK_a: imv_viewport_scale_to_actual(&view, &ldr);break; + case SDLK_r: imv_viewport_scale_to_window(&view, &ldr);break; + case SDLK_c: imv_viewport_center(&view, &ldr); break; case SDLK_j: imv_viewport_move(&view, 0, -50); break; case SDLK_k: imv_viewport_move(&view, 0, 50); break; case SDLK_h: imv_viewport_move(&view, 50, 0); break; case SDLK_l: imv_viewport_move(&view, -50, 0); break; case SDLK_x: imv_navigator_remove_current_path(&nav); break; case SDLK_f: imv_viewport_toggle_fullscreen(&view); break; - case SDLK_PERIOD: imv_image_load_next_frame(&img); break; - case SDLK_SPACE: imv_viewport_toggle_playing(&view, &img);break; + case SDLK_PERIOD: imv_loader_load_next_frame(&ldr); break; + case SDLK_SPACE: imv_viewport_toggle_playing(&view, &ldr);break; case SDLK_p: puts(imv_navigator_get_current_path(&nav));break; case SDLK_d: g_options.overlay = !g_options.overlay; @@ -335,7 +335,7 @@ int main(int argc, char** argv) } break; case SDL_MOUSEWHEEL: - imv_viewport_zoom(&view, &img, IMV_ZOOM_MOUSE, e.wheel.y); + imv_viewport_zoom(&view, &ldr, IMV_ZOOM_MOUSE, e.wheel.y); break; case SDL_MOUSEMOTION: if(e.motion.state & SDL_BUTTON_LMASK) { @@ -343,7 +343,7 @@ int main(int argc, char** argv) } break; case SDL_WINDOWEVENT: - imv_viewport_updated(&view, &img); + imv_viewport_updated(&view, &ldr); break; } } @@ -364,14 +364,14 @@ int main(int argc, char** argv) exit(1); } - if(imv_image_load(&img, current_path) != 0) { + if(imv_loader_load(&ldr, current_path) != 0) { imv_navigator_remove_current_path(&nav); } else { snprintf(&title[0], sizeof(title), "imv - [%i/%i] [%ix%i] %s", nav.cur_path + 1, nav.num_paths, - img.width, img.height, current_path); + ldr.width, ldr.height, current_path); imv_viewport_set_title(&view, title); - imv_viewport_scale_to_window(&view, &img); + imv_viewport_scale_to_window(&view, &ldr); if(overlay_surf) { free(overlay_surf); @@ -392,7 +392,7 @@ int main(int argc, char** argv) } if(g_options.actual) { - imv_viewport_scale_to_actual(&view, &img); + imv_viewport_scale_to_actual(&view, &ldr); } } @@ -400,11 +400,11 @@ int main(int argc, char** argv) double cur_time = SDL_GetTicks() / 1000.0; double dt = cur_time - last_time; last_time = SDL_GetTicks() / 1000.0; - imv_image_play(&img, dt); + imv_loader_play(&ldr, dt); } - if(imv_image_has_changed(&img)) { - imv_texture_set_image(&tex, img.cur_bmp); + if(imv_loader_has_changed(&ldr)) { + imv_texture_set_image(&tex, ldr.cur_bmp); imv_viewport_set_redraw(&view); } @@ -442,7 +442,7 @@ int main(int argc, char** argv) SDL_Delay(10); } - imv_destroy_image(&img); + imv_destroy_loader(&ldr); imv_destroy_texture(&tex); imv_destroy_navigator(&nav); imv_destroy_viewport(&view); diff --git a/src/viewport.c b/src/viewport.c index 0cb3c14..f53c0fa 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -16,7 +16,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "viewport.h" -#include "image.h" void imv_init_viewport(struct imv_viewport *view, SDL_Window *window) { @@ -44,21 +43,21 @@ void imv_viewport_toggle_fullscreen(struct imv_viewport *view) } } -void imv_viewport_toggle_playing(struct imv_viewport *view, struct imv_image *img) +void imv_viewport_toggle_playing(struct imv_viewport *view, struct imv_loader *ldr) { if(view->playing) { view->playing = 0; - } else if(imv_image_is_animated(img)) { + } else if(imv_loader_is_animated(ldr)) { view->playing = 1; } } -void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_image *img) +void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_loader *ldr) { view->scale = 1; view->redraw = 1; view->locked = 1; - imv_viewport_center(view, img); + imv_viewport_center(view, ldr); } void imv_viewport_move(struct imv_viewport *view, int x, int y) @@ -69,30 +68,30 @@ void imv_viewport_move(struct imv_viewport *view, int x, int y) view->locked = 1; } -void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *img, enum imv_zoom_source src, int amount) +void imv_viewport_zoom(struct imv_viewport *view, const struct imv_loader *ldr, enum imv_zoom_source src, int amount) { double prev_scale = view->scale; int x, y, ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); - /* x and y cordinates are relative to the image */ + /* x and y cordinates are relative to the loader */ if(src == IMV_ZOOM_MOUSE) { SDL_GetMouseState(&x, &y); x -= view->x; y -= view->y; } else { - x = view->scale * img->width / 2; - y = view->scale * img->height / 2; + x = view->scale * ldr->width / 2; + y = view->scale * ldr->height / 2; } - const int scaled_width = img->width * view->scale; - const int scaled_height = img->height * view->scale; + const int scaled_width = ldr->width * view->scale; + const int scaled_height = ldr->height * view->scale; const int ic_x = view->x + scaled_width/2; const int ic_y = view->y + scaled_height/2; const int wc_x = ww/2; const int wc_y = wh/2; - double delta_scale = 0.04 * ww * amount / img->width; + double delta_scale = 0.04 * ww * amount / ldr->width; view->scale += delta_scale; const double min_scale = 0.1; @@ -129,35 +128,35 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *img, e view->locked = 1; } -void imv_viewport_center(struct imv_viewport *view, const struct imv_image* img) +void imv_viewport_center(struct imv_viewport *view, const struct imv_loader* ldr) { int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); - view->x = (ww - img->width * view->scale) / 2; - view->y = (wh - img->height * view->scale) / 2; + view->x = (ww - ldr->width * view->scale) / 2; + view->y = (wh - ldr->height * view->scale) / 2; view->locked = 1; view->redraw = 1; } -void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_image* img) +void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_loader* ldr) { int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); double window_aspect = (double)ww / (double)wh; - double image_aspect = (double)img->width / (double)img->height; + double image_aspect = (double)ldr->width / (double)ldr->height; if(window_aspect > image_aspect) { /* Image will become too tall before it becomes too wide */ - view->scale = (double)wh / (double)img->height; + view->scale = (double)wh / (double)ldr->height; } else { /* Image will become too wide before it becomes too tall */ - view->scale = (double)ww / (double)img->width; + view->scale = (double)ww / (double)ldr->width; } - imv_viewport_center(view, img); + imv_viewport_center(view, ldr); view->locked = 0; } @@ -171,13 +170,13 @@ void imv_viewport_set_title(struct imv_viewport *view, char* title) SDL_SetWindowTitle(view->window, title); } -void imv_viewport_updated(struct imv_viewport *view, struct imv_image* img) +void imv_viewport_updated(struct imv_viewport *view, struct imv_loader* ldr) { view->redraw = 1; if(view->locked) { return; } - imv_viewport_scale_to_window(view, img); - imv_viewport_center(view, img); + imv_viewport_scale_to_window(view, ldr); + imv_viewport_center(view, ldr); } diff --git a/src/viewport.h b/src/viewport.h index 096f17a..ad3ac23 100644 --- a/src/viewport.h +++ b/src/viewport.h @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include -#include "image.h" +#include "loader.h" struct imv_viewport { SDL_Window *window; @@ -40,15 +40,15 @@ void imv_init_viewport(struct imv_viewport *view, SDL_Window *window); void imv_destroy_viewport(struct imv_viewport *view); void imv_viewport_toggle_fullscreen(struct imv_viewport*); -void imv_viewport_toggle_playing(struct imv_viewport*, struct imv_image*); +void imv_viewport_toggle_playing(struct imv_viewport*, struct imv_loader*); void imv_viewport_reset(struct imv_viewport*); void imv_viewport_move(struct imv_viewport*, int, int); -void imv_viewport_zoom(struct imv_viewport*, const struct imv_image*, enum imv_zoom_source, int); -void imv_viewport_center(struct imv_viewport*, const struct imv_image*); -void imv_viewport_scale_to_actual(struct imv_viewport*, const struct imv_image*); -void imv_viewport_scale_to_window(struct imv_viewport*, const struct imv_image*); +void imv_viewport_zoom(struct imv_viewport*, const struct imv_loader*, enum imv_zoom_source, int); +void imv_viewport_center(struct imv_viewport*, const struct imv_loader*); +void imv_viewport_scale_to_actual(struct imv_viewport*, const struct imv_loader*); +void imv_viewport_scale_to_window(struct imv_viewport*, const struct imv_loader*); void imv_viewport_set_redraw(struct imv_viewport*); void imv_viewport_set_title(struct imv_viewport*, char*); -void imv_viewport_updated(struct imv_viewport*, struct imv_image*); +void imv_viewport_updated(struct imv_viewport*, struct imv_loader*); #endif -- cgit v1.2.3