-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.h
executable file
·162 lines (127 loc) · 4.04 KB
/
image.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
//Image.h
//
//Class representing an image
// original by Wagner Correa, 1999
// turned to C++ by Robert Osada, 2000
// updated by Stephen J. Guy, 2017
#ifndef IMAGE_INCLUDED
#define IMAGE_INCLUDED
#include <assert.h>
#include <stdio.h>
#include "pixel.h"
#include "stb_image.h"
#include "stb_image_write.h"
/**
* constants
**/
enum {
IMAGE_SAMPLING_POINT,
IMAGE_SAMPLING_BILINEAR,
IMAGE_SAMPLING_GAUSSIAN,
IMAGE_N_SAMPLING_METHODS
};
enum {
IMAGE_CHANNEL_RED,
IMAGE_CHANNEL_GREEN,
IMAGE_CHANNEL_BLUE,
IMAGE_CHANNEL_ALPHA,
IMAGE_N_CHANNELS
};
/**
* Image
**/
class Image
{
public:
union PixelData{
Pixel *pixels;
uint8_t *raw;
};
PixelData data;
//PixelInfo *pixels; //pixel array
//uint8_t *pixelData;
int width, height, num_pixels;
int sampling_method;
//BMP* bmpImg;
public:
// Creates a blank image with the given dimensions
Image (int width, int height);
// Copy iamage
Image (const Image& src);
// Make image from file
Image(char *fname);
// Destructor
~Image ();
// Pixel access
int ValidCoord (int x, int y) const { return x>=0 && x<width && y>=0 && y<height; }
Pixel& GetPixel (int x, int y) const { assert(ValidCoord(x,y)); return data.pixels[y*width + x]; }
void SetPixel (int x, int y, Pixel p) const { assert(ValidCoord(x,y)); data.pixels[y*width + x] = p; }
// Dimension access
int Width () const { return width; }
int Height () const { return height; }
int NumPixels () const { return num_pixels; }
// Make file from image
void Write( char *fname );
// Adds noise to an image. The amount of noise is given by the factor
// in the range [0.0..1.0]. 0.0 adds no noise. 1.0 adds a lot of noise.
void AddNoise (double factor);
// Brightens the image by multiplying each pixel component by the factor.
void Brighten (double factor);
/**
* Changes the contrast of an image by interpolating between the image
* and a constant gray image with the average luminance.
* Interpolation reduces constrast, extrapolation boosts constrast,
* and negative factors generate inverted images.
**/
void ChangeContrast (double factor);
/**
* Changes the saturation of an image by interpolating between the
* image and a gray level version of the image. Interpolation
* decreases saturation, extrapolation increases it, negative factors
* presrve luminance but invert the hue of the input image.
**/
void ChangeSaturation (double factor);
/**
* Extracts a sub image from the image, at position (x, y), width w,
* and height h.
**/
Image* Crop(int x, int y, int w, int h);
/**
* Extracts a channel of an image. Leaves the specified channel
* intact. Sets all other ones to zero.
**/
void ExtractChannel(int channel);
/**
* Quantizes an image with "nbits" bits per channel.
**/
void Quantize (int nbits);
// Converts and image to nbits per channel using random dither.
void RandomDither(int nbits);
// Blurs an image with an n x n Gaussian filter.
void Blur(int n);
// Sharpens an image by blurring with an n x n Gaussian filter and then extrapolating
void Sharpen(int n);
// Detects edges in an image.
void EdgeDetect();
/**
* Converts an image to nbits per channel using ordered dither, with a
* 4x4 Bayer's pattern matrix.
**/
void OrderedDither(int nbits);
/**
* Converts an image to nbits per channel using Floyd-Steinberg dither
* with error diffusion.
**/
void FloydSteinbergDither(int nbits);
// Scales an image in x by sx, and y by sy.
Image* Scale(double sx, double sy);
// Rotates an image by the given angle.
Image* Rotate(double angle);
// Warps an image using a creative filter of your choice.
void Fun();
// Sets the sampling method.
void SetSamplingMethod(int method);
// Sample image using current sampling method.
Pixel Sample(double u, double v);
};
#endif