diff options
author | Pino Toscano <pino@kde.org> | 2011-01-06 01:09:09 +0100 |
---|---|---|
committer | Pino Toscano <pino@kde.org> | 2011-01-06 01:09:09 +0100 |
commit | b192363960c26111167b1b08db9910e5f39dcf8b (patch) | |
tree | 82986f44461c353c3c6291ceaa35cf640eb6bc5f /cpp/poppler-image.cpp | |
parent | bebc530cbde7898759e1bd3629d2836ce0fb1d08 (diff) |
[cpp] Add PNM (PBM/PGM/PPM) exporting to 'image'.
Introduce a custom ImgWriter (PNMWriter) for exporting in the PNM variants,
and use it choosing the output format matching as close as possible the format of the image.
Diffstat (limited to 'cpp/poppler-image.cpp')
-rw-r--r-- | cpp/poppler-image.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cpp/poppler-image.cpp b/cpp/poppler-image.cpp index ef213a5c..61f4c1e2 100644 --- a/cpp/poppler-image.cpp +++ b/cpp/poppler-image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, Pino Toscano <pino@kde.org> + * Copyright (C) 2010-2011, Pino Toscano <pino@kde.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ #if defined(ENABLE_LIBTIFF) #include "TiffWriter.h" #endif +#include "PNMWriter.h" #include <cstdlib> #include <cstring> @@ -38,6 +39,8 @@ #include <memory> #include <vector> +using poppler::PNMWriter; + namespace { struct FileCloser { @@ -66,6 +69,19 @@ int calc_bytes_per_row(int width, poppler::image::format_enum format) return 0; } +PNMWriter::OutFormat pnm_format(poppler::image::format_enum format) +{ + switch (format) { + case poppler::image::format_invalid: // unused, anyway + case poppler::image::format_mono: + return PNMWriter::PBM; + case poppler::image::format_rgb24: + case poppler::image::format_argb32: + return PNMWriter::PPM; + } + return PNMWriter::PPM; +} + } using namespace poppler; @@ -348,6 +364,9 @@ bool image::save(const std::string &file_name, const std::string &out_format, in w.reset(new TiffWriter()); } #endif + else if (fmt == "pnm") { + w.reset(new PNMWriter(pnm_format(d->format))); + } if (!w.get()) { return false; } @@ -418,6 +437,7 @@ std::vector<std::string> image::supported_image_formats() #if defined(ENABLE_LIBTIFF) formats.push_back("tiff"); #endif + formats.push_back("pnm"); return formats; } |