-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.h
58 lines (41 loc) · 1.15 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
/* File: image.h; Mode: C++; Tab-width: 3; Author: Simon Flannery; */
#ifndef IMAGE_H
#define IMAGE_H
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include "math.h"
#define BITMAP_SUPPORT
#define BITMAP_ID 0x4D42
class Image
{
public:
Image(size_t width, size_t height);
Image(const Image& i);
~Image();
enum class Format {TGA, BMP};
size_t GetWidth() const { return w; }
size_t GetHeight() const { return h; }
void SetPixel(float _x, float _y, const color3f& color);
void SetPixel(size_t _x, size_t _y, const color3f& color);
color3f GetPixel(size_t _x, size_t _y) const;
void Save(const char* szFileName, Format t) const;
protected:
private:
void SaveTGA(const char* szFileName) const;
void SaveBMP(const char* szFileName) const;
static void WriteByte(FILE* file, unsigned char b)
{
fwrite(&b, sizeof(unsigned char), 1, file);
return;
}
static unsigned char ClampColorComponent(float c)
{
int b = (int) (c * 255.0f);
if (b < 0) b = 0;
if (b > 255) b = 255;
return (unsigned char) b;
}
size_t w, h;
color3f* data;
};
#endif