-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageBW.h
164 lines (129 loc) · 5.2 KB
/
imageBW.h
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/// imageBW - A simple image processing module for BW images
/// represented using run-length encoding (RLE)
///
/// This module is part of a programming project
/// for the course AED, DETI / UA.PT
///
/// You may freely use and modify this code, at your own risk,
/// as long as you give proper credit to the original and subsequent authors.
///
/// The AED Team <[email protected], [email protected], ...>
/// 2024
#ifndef IMAGEBW_H
#define IMAGEBW_H
#include <inttypes.h>
// Types for non-negative integer values
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
// Type Image is a pointer to image objects
typedef struct image* Image;
// The values for the B and W pixels
#define BLACK 1 // Black pixel value
#define WHITE 0 // White pixel value
/// Init Image library. (Call once!)
/// Currently, simply calibrate instrumentation and set names of counters.
void ImageInit(void);
/// Image management functions
/// Create a new BW image, either BLACK or WHITE.
/// width, height : the dimensions of the new image.
/// val: the pixel color (BLACK or WHITE).
/// Requires: width and height must be non-negative, val is either BLACK or
/// WHITE.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageCreate(uint32 width, uint32 height, uint8 val);
/// Create a new BW image, with a perfect CHESSBOARD pattern.
/// width, height : the dimensions of the new image.
/// square_edge : the lenght of the edges of the sqares making up the
/// chessboard pattern.
/// first_value: the pixel color (BLACK or WHITE) of the
/// first image pixel.
/// Requires: width and height must be non-negative, val is either BLACK or
/// WHITE.
/// Requires: for the squares, width and height must be multiples of the
/// edge lenght of the squares
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageCreateChessboard(uint32 width, uint32 height, uint32 square_edge,
uint8 first_value);
/// Destroy the image pointed to by (*imgp).
/// imgp : address of an Image variable.
/// If (*imgp)==NULL, no operation is performed.
/// Ensures: (*imgp)==NULL.
/// Should never fail.
void ImageDestroy(Image* imgp);
/// Printing on the console
/// Output the raw BW image
void ImageRAWPrint(const Image img);
/// Output the compressed RLE image
void ImageRLEPrint(const Image img);
/// PBM BW image file operations
/// Load a PBM BW image file.
/// Only binary PBM files are accepted.
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageLoad(const char* filename);
/// Save image to PBM file.
/// On success, returns unspecified integer. (No need to check!)
/// On failure, does not return, EXITS program!
int ImageSave(const Image img, const char* filename);
/// Information queries
/// Get image width
int ImageWidth(const Image img);
/// Get image height
int ImageHeight(const Image img);
/// Image comparison
int ImageIsEqual(const Image img1, const Image img2);
int ImageIsDifferent(const Image img1, const Image img2);
/// Boolean Operations on image pixels
/// These functions apply boolean operations to images,
/// returning a new image as a result.
///
/// Operand images are left untouched and must be of the same size.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageNEG(const Image img);
Image ImageAND(const Image img1, const Image img2);
Image ImageOR(const Image img1, const Image img2);
Image ImageXOR(const Image img1, const Image img2);
/// Geometric transformations
/// These functions apply geometric transformations to an image,
/// returning a new image as a result.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
/// Mirror an image = flip top-bottom.
/// Returns a mirrored version of the image.
/// Ensures: The original img is not modified.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageHorizontalMirror(const Image img);
/// Mirror an image = flip left-right.
/// Returns a mirrored version of the image.
/// Ensures: The original img is not modified.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageVerticalMirror(const Image img);
/// Replicate img2 at the bottom of imag1, creating a larger image
/// Requires: the width of the two images must be the same.
/// Returns the new larger image.
/// Ensures: The original images are not modified.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageReplicateAtBottom(const Image img1, const Image img2);
/// Replicate img2 to the right of imag1, creating a larger image
/// Requires: the height of the two images must be the same.
/// Returns the new larger image.
/// Ensures: The original images are not modified.
///
/// On success, a new image is returned.
/// (The caller is responsible for destroying the returned image!)
Image ImageReplicateAtRight(const Image img1, const Image img2);
#endif