Skip to content

Commit ed10bef

Browse files
committed
.
1 parent 07e5b45 commit ed10bef

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

Diff for: Fractal Images/Bitmap.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace std;
88

99
namespace fractal {
1010

11-
Bitmap::Bitmap(int width, int height) : m_width(width), m_height(height), m_pPixel(new uint8_t[width * height * 3]{}) {
11+
Bitmap::Bitmap(int width, int height) : m_width(width), m_height(height), m_pPixels(new uint8_t[width * height * 3]{}) {
1212

1313
}
1414

@@ -32,7 +32,7 @@ namespace fractal {
3232

3333
file.write((char*)&fileheader, sizeof(fileheader));
3434
file.write((char*)&infoheader, sizeof(infoheader));
35-
file.write((char*)m_pPixel.get(), m_width * m_height * 3);
35+
file.write((char*)m_pPixels.get(), m_width * m_height * 3);
3636

3737
file.close();
3838

@@ -42,8 +42,16 @@ namespace fractal {
4242

4343
return true;
4444
}
45-
void setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue) {
46-
45+
void Bitmap::setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue) {
46+
uint8_t* pPixel = m_pPixels.get();
47+
48+
pPixel += (y*3)*m_width+(x*3);
49+
50+
pPixel[0] = blue;
51+
pPixel[1] = green;
52+
pPixel[2] = red;
53+
54+
4755
}
4856

4957
Bitmap:: ~Bitmap() {

Diff for: Fractal Images/Bitmap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace fractal {
1515
private:
1616
int m_width{0};
1717
int m_height{0};
18-
unique_ptr<uint8_t[]> m_pPixel{nullptr};
18+
unique_ptr<uint8_t[]> m_pPixels{nullptr};
1919
public:
2020
Bitmap(int width, int height);
2121

Diff for: Fractal Images/main.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ using namespace fractal;
99

1010
int main() {
1111

12-
Bitmap bitmap(800, 600);
12+
int const WIDTH = 800;
13+
int const HEIGHT = 600;
1314

15+
Bitmap bitmap(WIDTH, HEIGHT);
16+
17+
for (int y = 0; y < HEIGHT; y++) {
18+
for (int x = 0; x < WIDTH; x++) {
19+
bitmap.setPixel(x, y, 255, 0, 0);
20+
}
21+
}
22+
1423
bitmap.write("test.bmp");
1524

1625
cout << "Finished" << endl;

Diff for: test.bmp

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)