MCPcopy Create free account
hub / github.com/Siv3D/OpenSiv3D / WriteP6

Function WriteP6

Siv3D/src/Siv3D/ImageFormat/PPM/PPMEncoder.cpp:197–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195 }
196
197 static bool WriteP6(const Image& image, IWriter& writer)
198 {
199 writer.write("P6\n", 3);
200 WriteNumber(writer, image.width());
201 writer.write(' ');
202 WriteNumber(writer, image.height());
203 writer.write('\n');
204 writer.write("255\n", 4);
205
206 for (int y = 0; y < image.height(); ++y)
207 {
208 for (int x = 0; x + 1 < image.width(); ++x)
209 {
210 const Color& c = image[y][x];
211 writer.write(static_cast<uint8>(c.r));
212 writer.write(static_cast<uint8>(c.g));
213 writer.write(static_cast<uint8>(c.b));
214 }
215
216 if (1 <= image.width())
217 {
218 const Color& c = image[y][image.width() - 1];
219 writer.write(static_cast<uint8>(c.r));
220 writer.write(static_cast<uint8>(c.g));
221 writer.write(static_cast<uint8>(c.b));
222 }
223 }
224
225 return true;
226 }
227 }
228
229 StringView PPMEncoder::name() const

Callers 1

encodeMethod · 0.85

Calls 4

WriteNumberFunction · 0.85
writeMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected