~ruther/CTU-FEE-B0B35APO-Semestral-project

ref: 50a526b4935e2ff0e37aa53f47a71417517ddefa CTU-FEE-B0B35APO-Semestral-project/image-viewer/include/image.h -rw-r--r-- 2.6 KiB
50a526b4 — František Boháček feat: add size and date to browser table 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef __IMAGE_H__
#define __IMAGE_H__

#include <stddef.h>
#include <stdio.h>
#include <jpeglib.h>
#include <magic.h>
#include <png.h>
#include <stdio.h>

#include <stdbool.h>
#include <stdint.h>

#include "direction.h"
#include "display_utils.h"

typedef enum {
  IMG_UNKNOWN,
  IMG_PNG,
  IMG_JPG,
  IMG_PPM,
} image_type_t;

typedef enum {
  IMERR_SUCCESS,
  IMERR_UNKNOWN_FORMAT,
  IMERR_FILE_NOT_FOUND,
  IMERR_FILE_NO_PERMISSIONS,
  IMERR_FILE_CANT_OPEN,
  IMERR_WRONG_FORMAT,
  IMERR_UNKNOWN,
} image_error_t;

typedef struct {
  char *path;
  image_type_t type;

  display_pixel_t *pixels;

  uint16_t width;
  uint16_t height;
} image_t;

typedef struct {
  uint16_t x;
  uint16_t y;
  double scale;
} image_zoom_t;

typedef struct {
  uint16_t x;
  uint16_t y;

  uint16_t width;
  uint16_t height;
} image_region_t;

/**
 * @brief Create image with given path
 *
 * @param path path to image file
 * @return image_t
 */
image_t image_create(char *path);

/**
 * @brief Clean up image data
 *
 * @param image
 */
void image_destroy(image_t *image);

/**
 * @brief Get image pixel on coords
 *
 * @param image
 * @param x x coordinate of pixel
 * @param y y coordinate of pixel
 * @return display_pixel_t
 */
display_pixel_t image_get_pixel(image_t *image, uint16_t x, uint16_t y);

/**
 * @brief Set image pixel on coords
 *
 * @param image
 * @param x x coords of pixel
 * @param y y coords of pixel
 * @param pixel pixel to set
 */
void image_set_pixel(image_t *image, uint16_t x, uint16_t y,
                     display_pixel_t pixel);

/**
 * @brief Create image region
 *
 * @param x begin x coord
 * @param y begin y coord
 * @param width width of the region
 * @param height height of the region
 * @return image_region_t
 */
image_region_t image_region_create(uint16_t x, uint16_t y, uint16_t width,
                                   uint16_t height);
bool image_region_move_within(image_region_t *to_move, direction_t direction,
                              int amount, image_region_t *border);

/**
 * @brief Write image data to display data
 *
 * @param image
 * @param display
 * @param scale
 * @return image_zoom_t
 */
image_zoom_t image_write_to_display(image_t *image, display_t *display,
                                    image_zoom_t scale);

/**
 * @brief Get initial zoom to show whole image on the display
 *
 * @param image
 * @return image_zoom_t
 */
image_zoom_t image_get_initial_zoom(image_t *image);

/**
 * @brief Get shown region from image and zoom
 *
 * @param image
 * @param zoom
 * @return image_region_t
 */
image_region_t image_get_zoom_region(image_t *image, image_zoom_t zoom);

#endif // __IMAGE_H__
Do not follow this link