#define _IMAGE_HPP_
-#include <fstream>
+#include <iostream>
namespace image {
return flipped ? -(signed)(width*channels) : width*channels;
}
- bool writeBMP(const char *filename) const;
+ bool
+ writeBMP(const char *filename) const;
- void writePNM(std::ostream &os, const char *comment = NULL) const;
+ void
+ writePNM(std::ostream &os, const char *comment = NULL) const;
- inline bool writePNM(const char *filename, const char *comment = NULL) const {
- std::ofstream os(filename, std::ofstream::binary);
- if (!os) {
- return false;
- }
- writePNM(os, comment);
- return true;
- }
+ bool
+ writePNM(const char *filename, const char *comment = NULL) const;
bool
writePNG(std::ostream &os) const;
- inline bool
- writePNG(const char *filename) const {
- std::ofstream os(filename, std::ofstream::binary);
- if (!os) {
- return false;
- }
- return writePNG(os);
- }
+ bool
+ writePNG(const char *filename) const;
void
writeRAW(std::ostream &os) const;
- inline bool
- writeRAW(const char *filename) const {
- std::ofstream os(filename, std::ofstream::binary);
- if (!os) {
- return false;
- }
- writeRAW(os);
- return true;
- }
+ bool
+ writeRAW(const char *filename) const;
};
#include <assert.h>
#include <stdint.h>
+#include <fstream>
+
#include "image.hpp"
}
+bool
+Image::writePNG(const char *filename) const
+{
+ std::ofstream os(filename, std::ofstream::binary);
+ if (!os) {
+ return false;
+ }
+ return writePNG(os);
+}
+
+
Image *
readPNG(const char *filename)
{
#include <stdint.h>
#include <stdio.h>
+#include <fstream>
+
#include "image.hpp"
* http://netpbm.sourceforge.net/doc/ppm.html
*/
void
-Image::writePNM(std::ostream &os, const char *comment) const {
- assert(channels == 1 || channels >= 3);
+Image::writePNM(std::ostream &os, const char *comment) const
+{
os << (channels == 1 ? "P5" : "P6") << "\n";
if (comment) {
}
}
+
+bool
+Image::writePNM(const char *filename, const char *comment) const
+{
+ std::ofstream os(filename, std::ofstream::binary);
+ if (!os) {
+ return false;
+ }
+ writePNM(os, comment);
+ return true;
+}
+
+
const char *
readPNMHeader(const char *buffer, size_t bufferSize, unsigned *channels, unsigned *width, unsigned *height)
{
#include <stdint.h>
#include <stdio.h>
+#include <fstream>
+
#include "image.hpp"
namespace image {
+
void
-Image::writeRAW(std::ostream &os) const {
+Image::writeRAW(std::ostream &os) const
+{
const unsigned char *row;
for (row = start(); row != end(); row += stride()) {
}
}
+
+bool
+Image::writeRAW(const char *filename) const
+{
+ std::ofstream os(filename, std::ofstream::binary);
+ if (!os) {
+ return false;
+ }
+ writeRAW(os);
+ return true;
+}
+
+
} /* namespace image */