48 std::ofstream outputStream(fileName.c_str(), std::ios::out | std::ios::binary);
50 if (
false == outputStream.good()) {
51 std::cerr <<
"Failed to open \"" << fileName <<
"\"" << std::endl;
55 const uint32_t imageSize = height * width * 3;
57 outputStream <<
"P6\n"
58 << width <<
" " << height <<
"\n"
61 outputStream.write(
reinterpret_cast<const char*
>(dataP), imageSize);
70 uint32_t bitsPerPixel,
71 const std::string& comment,
74 std::ofstream outputStream(fileName.c_str(), std::ios::binary | std::ios::out);
76 if (
false == outputStream.good()) {
77 std::cerr <<
"Failed to open \"" << fileName <<
"\"" << std::endl;
81 const uint32_t imageSize = height * width;
83 switch(bitsPerPixel) {
87 outputStream <<
"P5\n"
88 <<
"#" << comment <<
"\n"
89 << width <<
" " << height <<
"\n"
92 outputStream.write(
reinterpret_cast<const char*
>(dataP), imageSize);
98 outputStream <<
"P5\n"
99 <<
"#" << comment <<
"\n"
100 << width <<
" " << height <<
"\n"
103 const uint16_t *imageP =
reinterpret_cast<const uint16_t*
>(dataP);
105 for (uint32_t i=0; i<imageSize; ++i) {
106 uint16_t o = htons(imageP[i]);
107 outputStream.write(
reinterpret_cast<const char*
>(&o),
sizeof(uint16_t));
114 outputStream.close();