aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-11-26 12:13:28 +0000
committerHarry Jeffery <harry@exec64.co.uk>2017-11-26 12:13:28 +0000
commita8eec46b5c8d6d895a0b4e746e934b073cdb129a (patch)
tree51d6de33e29d901fd44fbd311a24adb699a65a25 /src
parent3ceb0eac655e04da262b8148b35ee37a8ae3402a (diff)
downloadimv-a8eec46b5c8d6d895a0b4e746e934b073cdb129a.tar.gz
Make imv_image interface opaque
Diffstat (limited to 'src')
-rw-r--r--src/image.c23
-rw-r--r--src/image.h21
-rw-r--r--src/imv.c3
-rw-r--r--src/viewport.c34
4 files changed, 53 insertions, 28 deletions
diff --git a/src/image.c b/src/image.c
index 5c9d9b5..155a57b 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1,5 +1,19 @@
#include "image.h"
+struct imv_image {
+ int width; /* width of the image overall */
+ int height; /* height of the image overall */
+ int num_chunks; /* number of chunks allocated */
+ SDL_Texture **chunks; /* array of chunks */
+ int num_chunks_wide; /* number of chunks per row of the image */
+ int num_chunks_tall; /* number of chunks per column of the image */
+ int chunk_width; /* chunk width */
+ int chunk_height; /* chunk height */
+ int last_chunk_width; /* width of rightmost chunk */
+ int last_chunk_height; /* height of bottommost chunk */
+ SDL_Renderer *renderer; /* SDL renderer to draw to */
+};
+
struct imv_image *imv_image_create(SDL_Renderer *r)
{
struct imv_image *image = malloc(sizeof(struct imv_image));
@@ -128,5 +142,14 @@ void imv_image_draw(struct imv_image *image, int bx, int by, double scale)
}
}
+int imv_image_width(const struct imv_image *image)
+{
+ return image->width;
+}
+
+int imv_image_height(const struct imv_image *image)
+{
+ return image->height;
+}
/* vim:set ts=2 sts=2 sw=2 et: */
diff --git a/src/image.h b/src/image.h
index 5b17fff..4e6d73d 100644
--- a/src/image.h
+++ b/src/image.h
@@ -4,20 +4,7 @@
#include <SDL2/SDL.h>
#include <FreeImage.h>
-struct imv_image {
- int width; /* width of the image overall */
- int height; /* height of the image overall */
- int num_chunks; /* number of chunks allocated */
- SDL_Texture **chunks; /* array of chunks */
- int num_chunks_wide; /* number of chunks per row of the image */
- int num_chunks_tall; /* number of chunks per column of the image */
- int chunk_width; /* chunk width */
- int chunk_height; /* chunk height */
- int last_chunk_width; /* width of rightmost chunk */
- int last_chunk_height; /* height of bottommost chunk */
- SDL_Renderer *renderer; /* SDL renderer to draw to */
-};
-
+struct imv_image;
/* Creates an instance of imv_image */
struct imv_image *imv_image_create(SDL_Renderer *r);
@@ -31,6 +18,12 @@ int imv_image_set_bitmap(struct imv_image *image, FIBITMAP *bmp);
/* Draw the image at the given position with the given scale */
void imv_image_draw(struct imv_image *image, int x, int y, double scale);
+/* Get the image width */
+int imv_image_width(const struct imv_image *image);
+
+/* Get the image height */
+int imv_image_height(const struct imv_image *image);
+
#endif
diff --git a/src/imv.c b/src/imv.c
index 34a352f..ef03fb8 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -765,7 +765,8 @@ static void render_window(struct imv *imv)
const size_t index_cur = imv_navigator_index(imv->navigator);
const size_t index_len = imv_navigator_length(imv->navigator);
int len = snprintf(title, sizeof(title), "imv - [%zu/%zu] [%ix%i] [%.2f%%] %s [%s]",
- index_cur + 1, index_len, imv->image->width, imv->image->height,
+ index_cur + 1, index_len,
+ imv_image_width(imv->image), imv_image_height(imv->image),
100.0 * imv->view->scale,
current_path, scaling_label[imv->scaling_mode]);
if(imv->slideshow_image_duration >= 1000) {
diff --git a/src/viewport.c b/src/viewport.c
index ffefbcd..a5df9df 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -47,8 +47,8 @@ void imv_viewport_move(struct imv_viewport *view, int x, int y,
view->y += y;
view->redraw = 1;
view->locked = 1;
- int w = (int)((double)image->width * view->scale);
- int h = (int)((double)image->height * view->scale);
+ int w = (int)(imv_image_width(image) * view->scale);
+ int h = (int)(imv_image_height(image) * view->scale);
int ww, wh;
SDL_GetWindowSize(view->window, &ww, &wh);
if (view->x < -w) {
@@ -71,24 +71,27 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *image,
int x, y, ww, wh;
SDL_GetWindowSize(view->window, &ww, &wh);
+ const int image_width = imv_image_width(image);
+ const int image_height = imv_image_height(image);
+
/* x and y cordinates are relative to the image */
if(src == IMV_ZOOM_MOUSE) {
SDL_GetMouseState(&x, &y);
x -= view->x;
y -= view->y;
} else {
- x = view->scale * image->width / 2;
- y = view->scale * image->height / 2;
+ x = view->scale * image_width / 2;
+ y = view->scale * image_height / 2;
}
- const int scaled_width = image->width * view->scale;
- const int scaled_height = image->height * view->scale;
+ const int scaled_width = image_width * view->scale;
+ const int scaled_height = image_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 / image->width;
+ double delta_scale = 0.04 * ww * amount / image_width;
view->scale += delta_scale;
const double min_scale = 0.1;
@@ -130,8 +133,11 @@ void imv_viewport_center(struct imv_viewport *view, const struct imv_image *imag
int ww, wh;
SDL_GetWindowSize(view->window, &ww, &wh);
- view->x = (ww - image->width * view->scale) / 2;
- view->y = (wh - image->height * view->scale) / 2;
+ const int image_width = imv_image_width(image);
+ const int image_height = imv_image_height(image);
+
+ view->x = (ww - image_width * view->scale) / 2;
+ view->y = (wh - image_height * view->scale) / 2;
view->locked = 1;
view->redraw = 1;
@@ -142,15 +148,17 @@ void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_im
int ww, wh;
SDL_GetWindowSize(view->window, &ww, &wh);
- double window_aspect = (double)ww / (double)wh;
- double image_aspect = (double)image->width / (double)image->height;
+ const int image_width = imv_image_width(image);
+ const int image_height = imv_image_height(image);
+ const double window_aspect = (double)ww / (double)wh;
+ const double image_aspect = (double)image_width / (double)image_height;
if(window_aspect > image_aspect) {
/* Image will become too tall before it becomes too wide */
- view->scale = (double)wh / (double)image->height;
+ view->scale = (double)wh / (double)image_height;
} else {
/* Image will become too wide before it becomes too tall */
- view->scale = (double)ww / (double)image->width;
+ view->scale = (double)ww / (double)image_width;
}
imv_viewport_center(view, image);