[poppler] cpp/CMakeLists.txt cpp/Makefile.am cpp/PNMWriter.cc cpp/PNMWriter.h cpp/poppler-image.cpp
Adrian Johnson
ajohnson at kemper.freedesktop.org
Fri Aug 30 05:09:57 PDT 2013
cpp/CMakeLists.txt | 1
cpp/Makefile.am | 2
cpp/PNMWriter.cc | 119 --------------------------------------------------
cpp/PNMWriter.h | 43 ------------------
cpp/poppler-image.cpp | 14 ++---
5 files changed, 6 insertions(+), 173 deletions(-)
New commits:
commit e116ef32504b589001814f0f579309ecf7ec89d9
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Wed Aug 28 08:05:23 2013 +0930
Make cpp/poppler-image.cc use goo/NetPBMWriter
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index af61606..e606988 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -8,7 +8,6 @@ configure_file(poppler-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/poppler-version.
add_subdirectory(tests)
set(poppler_cpp_SRCS
- PNMWriter.cc
poppler-document.cpp
poppler-embedded-file.cpp
poppler-font.cpp
diff --git a/cpp/Makefile.am b/cpp/Makefile.am
index f381e58..50856e2 100644
--- a/cpp/Makefile.am
+++ b/cpp/Makefile.am
@@ -41,8 +41,6 @@ poppler_include_HEADERS = \
lib_LTLIBRARIES = libpoppler-cpp.la
libpoppler_cpp_la_SOURCES = \
- PNMWriter.cc \
- PNMWriter.h \
poppler-document.cpp \
poppler-document-private.h \
poppler-embedded-file.cpp \
diff --git a/cpp/PNMWriter.cc b/cpp/PNMWriter.cc
deleted file mode 100644
index a2b9a77..0000000
--- a/cpp/PNMWriter.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-//========================================================================
-//
-// PNMWriter.cc
-//
-// This file is licensed under the GPLv2 or later
-//
-// Copyright (C) 2011 Pino Toscano <pino at kde.org>
-//
-//========================================================================
-
-#include "PNMWriter.h"
-
-#include <vector>
-
-using namespace poppler;
-
-PNMWriter::PNMWriter(OutFormat formatArg)
- : format(formatArg)
- , file(0)
- , imgWidth(0)
- , rowSize(0)
-{
-}
-
-PNMWriter::~PNMWriter()
-{
-}
-
-bool PNMWriter::init(FILE *f, int width, int height, int /*hDPI*/, int /*vDPI*/)
-{
- file = f;
- imgWidth = width;
-
- switch (format)
- {
- case PNMWriter::PBM:
- fprintf(file, "P4\n%d %d\n", width, height);
- rowSize = (width + 7) >> 3;
- break;
- case PNMWriter::PGM:
- fprintf(file, "P5\n%d %d\n255\n", width, height);
- rowSize = width;
- break;
- case PNMWriter::PPM:
- fprintf(file, "P6\n%d %d\n255\n", width, height);
- rowSize = width * 3;
- break;
- }
-
- return true;
-}
-
-bool PNMWriter::writePointers(unsigned char **rowPointers, int rowCount)
-{
- bool ret = true;
- for (int i = 0; ret && (i < rowCount); ++i) {
- ret = writeRow(&(rowPointers[i]));
- }
-
- return ret;
-}
-
-bool PNMWriter::writeRow(unsigned char **row)
-{
- std::vector<unsigned char> newRow;
- unsigned char *rowPtr = *row;
- unsigned char *p = *row;
-
- switch (format)
- {
- case PNMWriter::PBM:
- newRow.resize(rowSize, 0);
- rowPtr = &newRow[0];
- for (int i = 0; i < imgWidth; ++i) {
- unsigned char pixel = p[0];
- if (p[0] == p[1] && p[1] == p[2]) {
- // gray, stored already
- } else {
- pixel = static_cast<unsigned char>((p[0] * 11 + p[1] * 16 + p[2] * 5) / 32);
- }
- if (pixel < 0x7F) {
- *(rowPtr + (i >> 3)) |= (1 << (i & 7));
- }
- p += 3;
- }
- break;
- case PNMWriter::PGM:
- newRow.resize(rowSize, 0);
- rowPtr = &newRow[0];
- for (int i = 0; i < imgWidth; ++i) {
- if (p[0] == p[1] && p[1] == p[2]) {
- // gray, store directly
- newRow[i] = p[0];
- } else {
- // calculate the gray value
- newRow[i] = static_cast<unsigned char>((p[0] * 11 + p[1] * 16 + p[2] * 5) / 32);
- }
- p += 3;
- }
- break;
- case PNMWriter::PPM:
- break;
- }
-
- if (int(fwrite(rowPtr, 1, rowSize, file)) < rowSize) {
- return false;
- }
-
- return true;
-}
-
-bool PNMWriter::close()
-{
- file = 0;
- imgWidth = 0;
- rowSize = 0;
-
- return true;
-}
diff --git a/cpp/PNMWriter.h b/cpp/PNMWriter.h
deleted file mode 100644
index 8d8da2d..0000000
--- a/cpp/PNMWriter.h
+++ /dev/null
@@ -1,43 +0,0 @@
-//========================================================================
-//
-// PNMWriter.h
-//
-// This file is licensed under the GPLv2 or later
-//
-// Copyright (C) 2011 Pino Toscano <pino at kde.org>
-//
-//========================================================================
-
-#ifndef PNMWRITER_H
-#define PNMWRITER_H
-
-#include "ImgWriter.h"
-
-namespace poppler
-{
-
-class PNMWriter : public ImgWriter
-{
- public:
- enum OutFormat { PBM, PGM, PPM };
-
- PNMWriter(OutFormat formatArg);
- ~PNMWriter();
-
- bool init(FILE *f, int width, int height, int hDPI, int vDPI);
-
- bool writePointers(unsigned char **rowPointers, int rowCount);
- bool writeRow(unsigned char **row);
-
- bool close();
-
- private:
- const OutFormat format;
- FILE *file;
- int imgWidth;
- int rowSize;
-};
-
-}
-
-#endif
diff --git a/cpp/poppler-image.cpp b/cpp/poppler-image.cpp
index 8e9ac63..18f9c79 100644
--- a/cpp/poppler-image.cpp
+++ b/cpp/poppler-image.cpp
@@ -31,7 +31,7 @@
#if defined(ENABLE_LIBTIFF)
#include "TiffWriter.h"
#endif
-#include "PNMWriter.h"
+#include "NetPBMWriter.h"
#include <cstdlib>
#include <cstring>
@@ -39,8 +39,6 @@
#include <memory>
#include <vector>
-using poppler::PNMWriter;
-
namespace {
struct FileCloser {
@@ -69,17 +67,17 @@ int calc_bytes_per_row(int width, poppler::image::format_enum format)
return 0;
}
-PNMWriter::OutFormat pnm_format(poppler::image::format_enum format)
+NetPBMWriter::Format pnm_format(poppler::image::format_enum format)
{
switch (format) {
case poppler::image::format_invalid: // unused, anyway
case poppler::image::format_mono:
- return PNMWriter::PBM;
+ return NetPBMWriter::MONOCHROME;
case poppler::image::format_rgb24:
case poppler::image::format_argb32:
- return PNMWriter::PPM;
+ return NetPBMWriter::RGB;
}
- return PNMWriter::PPM;
+ return NetPBMWriter::RGB;
}
}
@@ -366,7 +364,7 @@ bool image::save(const std::string &file_name, const std::string &out_format, in
}
#endif
else if (fmt == "pnm") {
- w.reset(new PNMWriter(pnm_format(d->format)));
+ w.reset(new NetPBMWriter(pnm_format(d->format)));
}
if (!w.get()) {
return false;
More information about the poppler
mailing list