-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageio.hpp
55 lines (43 loc) · 1.21 KB
/
imageio.hpp
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
#pragma once
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#pragma region
#include "vector.hpp"
#pragma endregion
//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#pragma region
#define __STDC_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#pragma endregion
//-----------------------------------------------------------------------------
// Declarations and Definitions
//-----------------------------------------------------------------------------
namespace pathtracing
{
inline void WritePPM(uint32_t w, uint32_t h,
const Vector3 *Ls, const char *fname = "./cpp-image.ppm") noexcept
{
FILE *fp;
#ifdef __WIN32__
fopen_s(&fp, fname, "w");
#else
fp = fopen(fname, "w");
if (!fp)
{
perror("File opening failed");
}
#endif
fprintf(fp, "P3\n%u %u\n%u\n", w, h, 255u);
for (size_t i = 0; i < w * h; ++i)
{
fprintf(fp, "%u %u %u ", ToByte(Ls[i].m_x),
ToByte(Ls[i].m_y),
ToByte(Ls[i].m_z));
}
fclose(fp);
}
} // namespace pathtracing