aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/loader.c (renamed from src/image.c)166
-rw-r--r--src/loader.h (renamed from src/image.h)16
-rw-r--r--src/main.c40
-rw-r--r--src/viewport.c45
-rw-r--r--src/viewport.h14
5 files changed, 140 insertions, 141 deletions
diff --git a/src/image.c b/src/loader.c
index 64fa3b8..c9c5976 100644
--- a/src/image.c
+++ b/src/loader.c
@@ -15,30 +15,30 @@ 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"
+#include "loader.h"
-void imv_init_image(struct imv_image *img)
+void imv_init_loader(struct imv_loader *ldr)
{
- 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;
+ 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_image(struct imv_image *img)
+void imv_destroy_loader(struct imv_loader *ldr)
{
- if(img->cur_bmp) {
- FreeImage_Unload(img->cur_bmp);
- img->cur_bmp = NULL;
+ if(ldr->cur_bmp) {
+ FreeImage_Unload(ldr->cur_bmp);
+ ldr->cur_bmp = NULL;
}
- if(img->mbmp) {
- FreeImage_CloseMultiBitmap(img->mbmp, 0);
- img->mbmp = NULL;
+ if(ldr->mbmp) {
+ FreeImage_CloseMultiBitmap(ldr->mbmp, 0);
+ ldr->mbmp = NULL;
}
}
@@ -51,16 +51,16 @@ int imv_can_load_image(const char* path)
}
}
-int imv_image_load(struct imv_image *img, const char* path)
+int imv_loader_load(struct imv_loader *ldr, const char* path)
{
- if(img->mbmp) {
- FreeImage_CloseMultiBitmap(img->mbmp, 0);
- img->mbmp = NULL;
+ if(ldr->mbmp) {
+ FreeImage_CloseMultiBitmap(ldr->mbmp, 0);
+ ldr->mbmp = NULL;
}
- if(img->cur_bmp) {
- FreeImage_Unload(img->cur_bmp);
- img->cur_bmp = NULL;
+ if(ldr->cur_bmp) {
+ FreeImage_Unload(ldr->cur_bmp);
+ ldr->cur_bmp = NULL;
}
@@ -70,53 +70,53 @@ int imv_image_load(struct imv_image *img, const char* path)
return 1;
}
- img->num_frames = 0;
- img->cur_frame = 0;
- img->next_frame = 0;
- img->frame_time = 0;
+ ldr->num_frames = 0;
+ ldr->cur_frame = 0;
+ ldr->next_frame = 0;
+ ldr->frame_time = 0;
if(fmt == FIF_GIF) {
- img->mbmp = FreeImage_OpenMultiBitmap(FIF_GIF, path,
+ ldr->mbmp = FreeImage_OpenMultiBitmap(FIF_GIF, path,
/* don't create file */ 0,
/* read only */ 1,
/* keep in memory */ 1,
/* flags */ GIF_LOAD256);
- if(!img->mbmp) {
+ if(!ldr->mbmp) {
return 1;
}
- img->num_frames = FreeImage_GetPageCount(img->mbmp);
+ ldr->num_frames = FreeImage_GetPageCount(ldr->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);
+ 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(img->mbmp, frame, 0);
+ FreeImage_UnlockPage(ldr->mbmp, frame, 0);
- if(imv_image_is_animated(img)) {
+ if(imv_loader_is_animated(ldr)) {
/* load a frame */
- imv_image_load_next_frame(img);
+ imv_loader_load_next_frame(ldr);
}
} 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);
+ ldr->cur_bmp = FreeImage_ConvertTo32Bits(image);
+ ldr->width = FreeImage_GetWidth(ldr->cur_bmp);
+ ldr->height = FreeImage_GetHeight(ldr->cur_bmp);
FreeImage_Unload(image);
}
- img->changed = 1;
+ ldr->changed = 1;
return 0;
}
-void imv_image_load_next_frame(struct imv_image *img)
+void imv_loader_load_next_frame(struct imv_loader *ldr)
{
- if(!imv_image_is_animated(img)) {
+ if(!imv_loader_is_animated(ldr)) {
return;
}
@@ -126,13 +126,13 @@ void imv_image_load_next_frame(struct imv_image *img)
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);
+ 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(img->cur_frame > 0) {
+ if(ldr->cur_frame > 0) {
FreeImage_GetMetadata(FIMD_ANIMATION, frame, "DisposalMethod", &tag);
if(FreeImage_GetTagValue(tag)) {
disposal_method = *(char*)FreeImage_GetTagValue(tag);
@@ -158,14 +158,14 @@ void imv_image_load_next_frame(struct imv_image *img)
if(frame_time == 0) {
frame_time = 100;
}
- img->frame_time += frame_time * 0.001;
+ ldr->frame_time += frame_time * 0.001;
- FreeImage_UnlockPage(img->mbmp, frame, 0);
+ FreeImage_UnlockPage(ldr->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);
+ 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;
@@ -173,65 +173,65 @@ void imv_image_load_next_frame(struct imv_image *img)
switch(disposal_method) {
case 0: /* nothing specified, just use the raw frame */
- if(img->cur_bmp) {
- FreeImage_Unload(img->cur_bmp);
+ if(ldr->cur_bmp) {
+ FreeImage_Unload(ldr->cur_bmp);
}
- img->cur_bmp = frame32;
+ ldr->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);
+ 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);
- img->cur_bmp = comp;
+ ldr->cur_bmp = comp;
} else {
/* No previous frame, just render directly */
- if(img->cur_bmp) {
- FreeImage_Unload(img->cur_bmp);
+ if(ldr->cur_bmp) {
+ FreeImage_Unload(ldr->cur_bmp);
}
- img->cur_bmp = frame32;
+ ldr->cur_bmp = frame32;
}
break;
case 2: /* TODO - set to background, composite over that */
- if(img->cur_bmp) {
- FreeImage_Unload(img->cur_bmp);
+ if(ldr->cur_bmp) {
+ FreeImage_Unload(ldr->cur_bmp);
}
- img->cur_bmp = frame32;
+ ldr->cur_bmp = frame32;
break;
case 3: /* TODO - restore to previous content */
- if(img->cur_bmp) {
- FreeImage_Unload(img->cur_bmp);
+ if(ldr->cur_bmp) {
+ FreeImage_Unload(ldr->cur_bmp);
}
- img->cur_bmp = frame32;
+ ldr->cur_bmp = frame32;
break;
}
- img->changed = 1;
+ ldr->changed = 1;
}
-int imv_image_is_animated(struct imv_image *img)
+int imv_loader_is_animated(struct imv_loader *ldr)
{
- return img->num_frames > 1;
+ return ldr->num_frames > 1;
}
-void imv_image_play(struct imv_image *img, double time)
+void imv_loader_play(struct imv_loader *ldr, double time)
{
- if(!imv_image_is_animated(img)) {
+ if(!imv_loader_is_animated(ldr)) {
return;
}
- img->frame_time -= time;
- if(img->frame_time < 0) {
- img->frame_time = 0;
- imv_image_load_next_frame(img);
+ ldr->frame_time -= time;
+ if(ldr->frame_time < 0) {
+ ldr->frame_time = 0;
+ imv_loader_load_next_frame(ldr);
}
}
-int imv_image_has_changed(struct imv_image *img)
+int imv_loader_has_changed(struct imv_loader *ldr)
{
- if(img->changed) {
- img->changed = 0;
+ if(ldr->changed) {
+ ldr->changed = 0;
return 1;
} else {
return 0;
diff --git a/src/image.h b/src/loader.h
index 96f0d51..02d53ad 100644
--- a/src/image.h
+++ b/src/loader.h
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <FreeImage.h>
-struct imv_image {
+struct imv_loader {
FIMULTIBITMAP *mbmp;
FIBITMAP *cur_bmp;
int width;
@@ -32,16 +32,16 @@ struct imv_image {
double frame_time;
};
-void imv_init_image(struct imv_image *img);
-void imv_destroy_image(struct imv_image *img);
+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_image_load(struct imv_image *img, const char* path);
-void imv_image_load_next_frame(struct imv_image *img);
+int imv_loader_load(struct imv_loader *img, const char* path);
+void imv_loader_load_next_frame(struct imv_loader *img);
-int imv_image_is_animated(struct imv_image *img);
-void imv_image_play(struct imv_image *img, double time);
+int imv_loader_is_animated(struct imv_loader *img);
+void imv_loader_play(struct imv_loader *img, double time);
-int imv_image_has_changed(struct imv_image *img);
+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 <getopt.h>
#include <ctype.h>
-#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 <SDL2/SDL.h>
-#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