On 28/08/13 06:47, Albert Astals Cid wrote:
> El Dimecres, 28 d'agost de 2013, a les 06:33:03, Adrian Johnson va escriure:
>> On 28/08/13 03:45, Albert Astals Cid wrote:
>>> El Dilluns, 26 d'agost de 2013, a les 01:12:32, Pino Toscano va escriure:
>>>> Alle lunedì 26 agosto 2013, Adrian Johnson ha scritto:
>>>>> On 26/08/13 07:55, Albert Astals Cid wrote:
>>>>>> I think you copy/pasted the NetPBMWriter.* headears and there's too
>>>>>> many names in them, no?
>>>>>
>>>>> NetPBMWriter.h is based on a modified copy of ImageWriter.h so I
>>>>> would expect the headers stay the same.
>>>>
>>>> Isn't it basically what I did time ago as cpp/PNMWriter.{cpp,h}?
>>>
>>> Adrian?
>>
>> I don't know. I've never paid any attention to what is under cpp/*
>
> Fair enough, can you pay attention now to that existing file, see what code
> is
> better, the same or worse than the one oyu did to write PBM and if needed
> move
> the cpp/ implementation to goo/ and adjust the buildsystem?
goo/NetPBMWriter accepts input in RGB, gray, or monochrome (like the
other goo image writers) while cpp/PNMWriter only takes input in RGB
then uses the selected output format to do the conversion. So
goo/NetPBMWriterversion can not be replaced by the cpp version. Also, as
cpp/poppler-image.cpp only supports writing in PNM format and is not
using the other formats in cpp/PNMWriter we can easily switch it to
using goo/NetPBMWriter. See attached patch.
>
> Cheers,
> Albert
>
>>
>>> Cheers,
>>>
>>> Albert
>>>
>>> _______________________________________________
>>> poppler mailing list
>>> [email protected]
>>> http://lists.freedesktop.org/mailman/listinfo/poppler
>>
>> _______________________________________________
>> poppler mailing list
>> [email protected]
>> http://lists.freedesktop.org/mailman/listinfo/poppler
>
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
>From e47a1df4047052add704aa068f098e33391a0dce Mon Sep 17 00:00:00 2001
From: Adrian Johnson <[email protected]>
Date: Wed, 28 Aug 2013 08:05:23 +0930
Subject: [PATCH] Make cpp/poppler-image.cc use goo/NetPBMWriter
---
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(-)
delete mode 100644 cpp/PNMWriter.cc
delete mode 100644 cpp/PNMWriter.h
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 <[email protected]>
-//
-//========================================================================
-
-#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 <[email protected]>
-//
-//========================================================================
-
-#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;
--
1.8.1.2
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler