Hi,
http://code.google.com/p/ocropus/issues/detail?id=146 discusses the
possibility of creating searchable image PDFs. I'm not sure how well that is
going to work out, but basic PDF support seems like it might be useful.
As a first cut (not intended to be applied at this stage), I've added support
for reading PDF files to iulib and ocropus. It relies on the poppler library. I
recognise it isn't complete and that RGB doesn't work yet, but it is enough to
get ocropus book2pages to run on a multiple page PDF file.
I've based the support on the TIFF implementation - much of the patch is
fairly mechanical (well, it was once I understood what was going on, anyway).
>From the comment in issue 146, I'm assuming that this the sort of thing you'd
like to see added to ocropus. However is this the sort of implementation you'd
expected?
Also, the tests for this are fairly messy, because I can't write a PDF file.
Instead, I rely on an existing PDF files, and a set of "known answer" PNG
files.
See test-io_pdf.cc (attached) for the test as it currently exits. I've tried
to choose a fairly small PDF file, which gives:
$ ls -go orientation*
-rw-r--r-- 1 12033 2009-07-12 21:41 orientation-0.png
-rw-r--r-- 1 13078 2009-07-13 08:30 orientation-1.png
-rw-r--r-- 1 14030 2009-07-13 08:26 orientation-2.png
-rw-r--r-- 1 13403 2009-07-13 08:30 orientation-3.png
-rw-r--r-- 1 14675 2009-07-11 22:08 orientation.pdf
That 67K of test files just covers the simple gray case. I'll try to make the
other examples just one page, but the png images will still take a bit of
space. Is that OK for iulib?
As an alternative, we could just check that the results were the right size.
There are reasonable amount of things that could go wrong in such a case
though (for example, that probably won't pick up endianess problems in the
image).
Thoughts? Comments?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ocropus" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ocropus?hl=en
-~----------~----~----~----~------~----~------~--~---
diff -r e9c95bb1ab68 configure.ac
--- a/configure.ac Mon Jul 13 02:43:39 2009 +0200
+++ b/configure.ac Mon Jul 13 16:49:29 2009 +1000
@@ -120,6 +120,27 @@
AC_CHECK_LIB(iulib, exit,,
AC_MSG_ERROR([no iulib; please install iulib first (see INSTALL)]))
+# --- Poppler, for PDF files (optional, though we really need it if iulib used it....) ---
+AC_SUBST(have_poppler, 0)
+AC_ARG_WITH(poppler,[ --without-poppler disable PDF support],
+ [ac_cv_use_poppler=$withval], [ac_cv_use_poppler=yes])
+if test x$ac_cv_use_poppler != xno; then
+CPPFLAGS+=" -I/usr/include/poppler"
+ AC_MSG_CHECKING([whether Poppler PDF support is available])
+ AC_COMPILE_IFELSE([#include <poppler-config.h>
+ #include <PDFDoc.h>
+ PDFDoc doc(new GooString("filename"));],
+ [AC_SUBST(have_poppler, 1)],
+ [AC_SUBST(have_poppler, 0)])
+ if test "$have_poppler" != 0; then
+ AC_MSG_RESULT(yes)
+ LIBS="$LIBS -lpoppler"
+ else
+ AC_MSG_RESULT(no)
+ fi
+fi
+AM_CONDITIONAL([have_poppler], [test "$have_poppler" != 0])
+
# --- libpthread (needed by tesseract) ---
AC_CHECK_LIB(pthread, pthread_create,,)
@@ -174,7 +195,7 @@
fi
# ??? how to set the path correctly ?
LDFLAGS="$LDFLAGS -L$leptheaders/../../lib"
- AC_CHECK_LIB(lept,pixCreate,,AC_MSG_ERROR([leptonica not found! Choose --without-leptonica if you don't want to use it.]))
+ AC_CHECK_LIB(lept,pixCreate,,AC_MSG_ERROR([leptonica not found! Choose --without-leptonica if you don't want to use it.]), "-lz -lgif")
fi
AM_CONDITIONAL([use_leptonica], [test x$use_leptonica == xyes])
@@ -231,14 +252,26 @@
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
+if [[ "$notesseract" != "1" ]]; then
+ use_tesseract="yes"
+else
+ use_tesseract="no"
+fi
+
+echo
+echo "OCRopus configuration:"
+echo " leptonica: $use_leptonica"
+echo " GSL: $use_gsl"
+echo " tesseract: $use_tesseract"
+echo " SDL: $ac_cv_use_sdl"
+echo " OpenFST: $ac_cv_use_fst"
+echo " OpenMP: $ac_cv_use_openmp"
echo
echo "OK! You can build and install OCRopus the usual way:"
echo
echo " make"
echo " sudo make install"
echo
+echo "To recognize something, you may want to build the separate ocroscript package"
+echo "which can be checked out using hg clone http://mercurial.iupr.org/ocroscript"
echo
-echo "To recognize something, you can use"
-echo
-echo " ocroscript recognize data/pages/alice_1.png"
-echo
diff -r e9c95bb1ab68 ocr-utils/pages.h
--- a/ocr-utils/pages.h Mon Jul 13 02:43:39 2009 +0200
+++ b/ocr-utils/pages.h Mon Jul 13 16:49:29 2009 +1000
@@ -119,9 +119,18 @@
static bool isTiff(iucstring& filename) {
return re_search(filename, "\\.tif\\(f\\?\\)$") >= 0;
}
+ static bool isPdf(iucstring& filename) {
+ return re_search(filename, "\\.pdf\\(f\\?\\)$") >= 0;
+ }
void addFile(const char *file) {
files.push() = file;
- numSubpages.push(isTiff(files.last())?Tiff(file, "r").numPages():1);
+ if ( isTiff( files.last() ) ) {
+ numSubpages.push( Tiff(file, "r").numPages() );
+ } if ( isPdf( files.last() ) ) {
+ numSubpages.push( PDF(file, "r").numPages() );
+ } else {
+ numSubpages.push( 1 );
+ }
}
void parseSpec(const char *spec) {
current_index = -1;
@@ -190,10 +199,13 @@
color.clear();
iucstring& current_file = files(current_image);
if(current_subpage > 0) {
- if(!isTiff(current_file)) {
- throw "subpage requested but not a TIFF image";
+ if (isTiff(current_file)) {
+ Tiff(current_file, "r").getPage(gray, current_subpage);
+ } else if (isPdf(current_file)) {
+ PDF(current_file, "r").getPage(gray, current_subpage);
+ } else {
+ throw "subpage requested but not a PDF or TIFF image";
}
- Tiff(current_file, "r").getPage(gray, current_subpage);
} else {
iulib::read_image_gray(gray,current_file);
}
diff -r 124581f1e82e configure.ac
--- a/configure.ac Mon Jul 13 01:47:50 2009 +0200
+++ b/configure.ac Mon Jul 13 17:08:01 2009 +1000
@@ -50,18 +50,39 @@
fi
AM_CONDITIONAL([have_sdl], [test "$nosdl" != 1])
-# vidio needs C++ headers
+# poppler and vidio need C++ headers
AC_LANG(C++)
+# --- Poppler, for PDF files (optional) ---
+AC_SUBST(have_poppler, 0)
+AC_ARG_WITH(poppler,[ --without-poppler disable PDF support],
+ [ac_cv_use_poppler=$withval], [ac_cv_use_poppler=yes])
+if test x$ac_cv_use_poppler != xno; then
+CPPFLAGS+=" -I/usr/include/poppler"
+ AC_MSG_CHECKING([whether Poppler PDF support is available])
+ AC_COMPILE_IFELSE([#include <poppler-config.h>
+ #include <PDFDoc.h>
+ PDFDoc doc(new GooString("filename"));],
+ [AC_SUBST(have_poppler, 1)],
+ [AC_SUBST(have_poppler, 0)])
+ if test "$have_poppler" != 0; then
+ AC_MSG_RESULT(yes)
+ LIBS="$LIBS -lpoppler"
+ else
+ AC_MSG_RESULT(no)
+ fi
+fi
+AM_CONDITIONAL([have_poppler], [test "$have_poppler" != 0])
+
# --- vidio (optional video in-/output) ---
AC_SUBST(novidio, 0)
-CPPFLAGS+=" -I/usr/include/ffmpeg"
AC_ARG_WITH(vidio,[ --without-vidio disable video i/o support (using ffmpeg)],
[ac_cv_use_vidio=$withval], [ac_cv_use_vidio=yes])
if test x$ac_cv_use_vidio != xno; then
+ CPPFLAGS+=" -I/usr/include/ffmpeg"
AC_CHECK_HEADER(libavutil/avutil.h, [], AC_SUBST(novidio, 1))
AC_CHECK_HEADER(libavcodec/avcodec.h, [], AC_SUBST(novidio, 1), [#include <libavutil/avutil.h>])
- AC_CHECK_HEADER(libavformat/avformat.h,,AC_SUBST(novidio, 1))
+ AC_CHECK_HEADER(libavformat/avformat.h, [], AC_SUBST(novidio, 1))
AC_TRY_COMPILE([#include <libavformat/avio.h>
#include <libavformat/avformat.h>],
[AVFormatContext fc; url_fclose(fc.pb);],
@@ -102,11 +123,19 @@
use_v4l2="no"
fi
+if [[ "$have_poppler" == "1" ]]; then
+ use_poppler="yes"
+else
+ use_poppler="no"
+fi
+
echo
echo "IULIB configuration:"
echo " SDL (debugging): $ac_cv_use_sdl"
echo " Video IO: $use_vidio"
-echo " Video for Linux 2: $use_v4l2"
+echo " Video for Linux 2: $use_v4l2"
+echo " PDF (Poppler): $use_poppler"
+
echo
echo "OK! You can build and install iulib the usual way:"
echo
diff -r 124581f1e82e imgio/imgio.cc
--- a/imgio/imgio.cc Mon Jul 13 01:47:50 2009 +0200
+++ b/imgio/imgio.cc Mon Jul 13 17:08:01 2009 +1000
@@ -51,6 +51,15 @@
return magic1 == 0xff && magic2 == 0xd8;
}
+ bool is_pdf(FILE *in) {
+ char magic[] = "%PDF-";
+ char buf[sizeof(magic)];
+ if(fread(buf, 1, sizeof(buf), in)!=sizeof(buf))
+ buf[0] = 0;
+ rewind(in);
+ return !memcmp(magic, buf, sizeof(buf));
+ }
+
const char *ext_fmt(const char *filename) {
int n = strlen(filename);
if(n>=5) {
@@ -65,6 +74,7 @@
if(!strcasecmp(filename+(n-4),".ppm")) return "pnm";
if(!strcasecmp(filename+(n-4),".pnm")) return "pnm";
if(!strcasecmp(filename+(n-4),".tif")) return "tif";
+ if(!strcasecmp(filename+(n-4),".pdf")) return "pdf";
}
static char error[1024];
snprintf(error,1020,"%s: file has an unknown extension",filename);
@@ -76,6 +86,7 @@
if(is_jpeg(f)) return "jpg";
if(is_png(f)) return "png";
if(is_pnm(f)) return "pnm";
+ if(is_pdf(f)) return "pdf";
throw "unknown format (file contents)";
}
@@ -87,6 +98,7 @@
if(!strcasecmp(format,"pgm")) return "pnm";
if(!strcasecmp(format,"ppm")) return "pnm";
if(!strcasecmp(format,"pnm")) return "pnm";
+ if(!strcasecmp(format,"pdf")) return "pdf";
throw "unknown format (required format)";
}
@@ -103,6 +115,7 @@
else if(!strcmp(format,"png")) read_png_packed(image,f,false);
else if(!strcmp(format,"pnm")) read_ppm_packed(f,image);
else if(!strcmp(format,"tif")) read_tiff_packed(image,f,false);
+ else if(!strcmp(format,"pdf")) read_pdf_packed(image,f,false);
else throw "unknown format";
}
@@ -112,6 +125,7 @@
else if(!strcmp(format,"png")) read_png(image,f,false);
else if(!strcmp(format,"pnm")) read_ppm_rgb(f,image);
else if(!strcmp(format,"tif")) read_tiff(image,f,false);
+ else if(!strcmp(format,"pdf")) read_pdf(image,f,false);
else throw "unknown format";
}
@@ -121,6 +135,7 @@
else if(!strcmp(format,"png")) read_png(image,f,true);
else if(!strcmp(format,"pnm")) read_pnm_gray(f,image);
else if(!strcmp(format,"tif")) read_tiff(image,f,true);
+ else if(!strcmp(format,"pdf")) read_pdf(image,f,true);
else throw "unknown format";
}
@@ -139,6 +154,7 @@
else if(!strcmp(format,"png")) read_png_packed(image,stdio(path,"rb"),false);
else if(!strcmp(format,"pnm")) read_ppm_packed(stdio(path,"rb"),image);
else if(!strcmp(format,"tif")) read_tiff_packed(image, path);
+ else if(!strcmp(format,"pdf")) read_pdf_packed(image, path);
else throw "unknown format";
}
@@ -148,6 +164,7 @@
else if(!strcmp(format,"png")) read_png(image,stdio(path,"rb"),false);
else if(!strcmp(format,"pnm")) read_ppm_rgb(stdio(path,"rb"),image);
else if(!strcmp(format,"tif")) read_tiff(image,path,false);
+ else if(!strcmp(format,"pdf")) read_pdf(image,path,false);
else throw "unknown format";
}
@@ -157,6 +174,7 @@
else if(!strcmp(format,"png")) read_png(image,stdio(path,"rb"),true);
else if(!strcmp(format,"pnm")) read_pnm_gray(stdio(path,"rb"),image);
else if(!strcmp(format,"tif")) read_tiff(image,path,true);
+ else if(!strcmp(format,"pdf")) read_pdf(image,path,true);
else throw "unknown format";
}
@@ -176,6 +194,7 @@
if(!strcmp(format,"jpg")) throw "jpeg writing unimplemented"; //FIXME
else if(!strcmp(format,"png")) write_png_packed(f,image);
else if(!strcmp(format,"pnm")) write_ppm_packed(f,image);
+ else if(!strcmp(format,"pdf")) throw "PDF writing unimplemented";
else throw "unknown format";
}
@@ -185,6 +204,7 @@
if(!strcmp(format,"jpg")) throw "jpeg writing unimplemented"; //FIXME
else if(!strcmp(format,"png")) write_png(f,image);
else if(!strcmp(format,"pnm")) write_ppm_rgb(f,image);
+ else if(!strcmp(format,"pdf")) throw "PDF writing unimplemented";
else throw "unknown format";
}
@@ -195,6 +215,7 @@
if(!strcmp(format,"jpg")) throw "jpeg writing unimplemented"; //FIXME
else if(!strcmp(format,"png")) write_png(f,image);
else if(!strcmp(format,"pnm")) write_pgm(f,image);
+ else if(!strcmp(format,"pdf")) throw "PDF writing unimplemented";
else throw "unknown format";
}
@@ -209,6 +230,7 @@
if(!strcmp(format,"jpg")) throw "jpeg writing unimplemented"; //FIXME
else if(!strcmp(format,"png")) write_png(stream,image);
else if(!strcmp(format,"pnm")) write_pbm(stream,image);
+ else if(!strcmp(format,"pdf")) throw "PDF writing unimplemented";
else throw "unknown format";
}
diff -r 124581f1e82e imgio/imgio.h
--- a/imgio/imgio.h Mon Jul 13 01:47:50 2009 +0200
+++ b/imgio/imgio.h Mon Jul 13 17:08:01 2009 +1000
@@ -28,6 +28,7 @@
#include "io_pbm.h"
#include "io_jpeg.h"
#include "io_tiff.h"
+#include "io_pdf.h"
#include "autoinvert.h"
namespace iulib {
diff -r 124581f1e82e imgio/io_pdf.cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/imgio/io_pdf.cc Mon Jul 13 17:08:01 2009 +1000
@@ -0,0 +1,154 @@
+// -*- C++ -*-
+
+// Copyright Brad Hards <[email protected]> 2009
+//
+// You may not use this file except under the terms of the accompanying license.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you
+// may not use this file except in compliance with the License. You may
+// obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Project: iulib -- image understanding library
+// File: io_pdf.cc
+// Purpose: implementation of PDF I/O for iulib
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "io_pdf.h"
+#include <iostream>
+
+// poppler headers
+#include <GlobalParams.h>
+#include <PDFDoc.h>
+#include <splash/Splash.h>
+#include <splash/SplashBitmap.h>
+#include <SplashOutputDev.h>
+
+using namespace colib;
+
+namespace iulib {
+
+ PDF::PDF(const char* filename, const char* mode) {
+ GooString *file = new GooString(filename);
+ // TODO: do we need to find a way to handle passwords here?
+ m_doc = new PDFDoc( file );
+ globalParams = new GlobalParams();
+ }
+
+ PDF::PDF(FILE* file, const char* mode) {
+ if(ftell(file) != 0) {
+ throw "pdf: file offset not zero";
+ }
+ Object obj;
+ obj.initNull();
+ FileStream *str = new FileStream(file, 0, gFalse, 0, &obj);
+ // TODO: do we need to find a way to handle passwords here?
+ m_doc = new PDFDoc(str);
+ globalParams = new GlobalParams();
+ globalParams->setAntialias((char*)"yes");
+ }
+
+ PDF::~PDF() {
+ delete m_doc;
+ }
+
+ int PDF::numPages() {
+ return m_doc->getNumPages();
+ }
+
+
+ void PDF::getPageRaw(bytearray &image, int page, bool gray) {
+ // TODO: implement
+ }
+
+ void PDF::getPage(bytearray &resultImage, int pageNum, bool gray) {
+ if ( ! m_doc->isOk() ) {
+ return;
+ }
+ ++pageNum; /* zero base -> 1 based */
+ if ( pageNum > numPages() ) {
+ return;
+ }
+ SplashColor paperColor = { 255, 255, 255 };
+ SplashColorMode colourMode;
+ if (gray) {
+ colourMode = splashModeMono8;
+ } else {
+ colourMode = splashModeRGB8;
+ }
+ SplashOutputDev *outputDev = new SplashOutputDev(colourMode, 4, gFalse, paperColor);
+ outputDev->startDoc( m_doc->getXRef() );
+
+ double xDPI = 150.0;
+ double yDPI = 150.0;
+
+ m_doc->displayPage(outputDev, pageNum, xDPI, yDPI,
+ 0 /* rotate */, gTrue /* useMediaBox */,
+ gFalse /* crop */, gFalse /* printing */);
+ SplashBitmap *renderedBitmap = outputDev->getBitmap();
+
+ int imageWidth = (int) ceil(renderedBitmap->getWidth());
+ int imageHeight = (int) ceil(renderedBitmap->getHeight());
+
+ SplashColorPtr row = renderedBitmap->getDataPtr();
+
+ if (renderedBitmap->getMode() == splashModeMono8) {
+ resultImage.renew(imageWidth, imageHeight);
+ for (int rowNum = 0; rowNum < imageHeight; ++rowNum) {
+ SplashColorPtr pixel = row;
+ for (int colNum = 0; colNum < imageWidth; ++colNum) {
+ resultImage(colNum, imageHeight - rowNum - 1) = *pixel;
+ ++pixel;
+ }
+ row += renderedBitmap->getRowSize();
+ }
+ } else if (renderedBitmap->getMode() == splashModeRGB8) {
+ resultImage.renew(imageWidth, imageHeight, 3);
+ for (int rowNum = 0; rowNum < imageHeight; ++rowNum) {
+ SplashColorPtr pixel = row;
+ for (int colNum = 0; colNum < imageWidth; ++colNum) {
+ resultImage(colNum, imageHeight - rowNum - 1, 0) = splashBGR8R(pixel);
+ resultImage(colNum, imageHeight - rowNum - 1, 1) = splashBGR8G(pixel);
+ resultImage(colNum, imageHeight - rowNum - 1, 2) = splashBGR8B(pixel);
+ pixel += 3;
+ }
+ row += renderedBitmap->getRowSize();
+ }
+ } else {
+ std::cerr << "unhandled PDF bitmap mode: " << renderedBitmap->getMode() << std::endl;
+ }
+ delete outputDev;
+ }
+
+ void PDF::getPageRaw(intarray &image, int page, bool gray) {
+ // TODO: implement
+ }
+
+ void PDF::getPage(intarray &image, int page, bool gray) {
+ // TODO: implement
+ }
+
+ void read_pdf(bytearray &image, const char *file, bool gray) {
+ PDF(file, "r").getPage(image, 0, gray);
+ }
+
+ void read_pdf_packed(intarray &image, const char *file, bool gray) {
+ PDF(file, "r").getPage(image, 0, gray);
+ }
+
+ void read_pdf(bytearray &image, FILE *file, bool gray) {
+ PDF(file, "r").getPage(image, 0, gray);
+ }
+ void read_pdf_packed(intarray &image, FILE *file, bool gray) {
+ PDF(file, "r").getPage(image, 0, gray);
+ }
+
+}
diff -r 124581f1e82e imgio/io_pdf.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/imgio/io_pdf.h Mon Jul 13 17:08:01 2009 +1000
@@ -0,0 +1,68 @@
+// -*- C++ -*-
+
+// Copyright Brad Hards <[email protected]> 2009
+//
+// You may not use this file except under the terms of the accompanying license.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you
+// may not use this file except in compliance with the License. You may
+// obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Project: iulib -- image understanding library
+// File: io_pdf.h
+// Purpose: interface to PDF I/O for iulib
+
+#ifndef h_io_pdf__
+#define h_io_pdf__
+
+#include "colib/colib.h"
+#include "iulib.h"
+
+class PDFDoc;
+
+namespace iulib {
+ using namespace colib;
+
+ /**
+ * @brief reading pages (as images) from a PDF file
+ */
+ class PDF {
+ public:
+ PDF(const char* filename, const char* mode);
+ PDF(FILE* file, const char* mode);
+ ~PDF();
+
+ ///@return number of pages inside the PDF file
+ int numPages();
+
+ /// reads page in original color format
+ void getPageRaw(colib::bytearray &image, int page, bool gray=true);
+
+ /// reads page in original color format
+ void getPageRaw(colib::intarray &image, int page, bool gray=false);
+
+ /// reads page in RGBA color format
+ void getPage(colib::bytearray &image, int page, bool gray=true);
+
+ /// reads page in RGBA color format
+ void getPage(colib::intarray &image, int page, bool gray=false);
+
+ private:
+ PDFDoc *m_doc;
+ };
+
+ void read_pdf(colib::bytearray &image, const char *file, bool gray=true);
+ void read_pdf_packed(colib::intarray &image, const char *file, bool gray=false);
+
+ void read_pdf(colib::bytearray &image, FILE *file, bool gray=true);
+ void read_pdf_packed(colib::intarray &image, FILE *file, bool gray=false);
+
+}
+
+#endif
// -*- C++ -*-
// Copyright Brad Hards <[email protected]> 2009
//
// You may not use this file except under the terms of the accompanying license.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may
// obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Project: iulib - Image Understanding Library
// File: test_io_pdf.cc
// Purpose: Test cases for pdf I/O classes
#include <stdio.h>
#include "colib/colib.h"
#include "imgio.h"
#include "imglib.h"
using namespace iulib;
using namespace colib;
int main(int argc,char **argv) {
bytearray refimage_ba;
// intarray refimage_ia;
bytearray image_from_pdf_ba;
// intarray image_from_pdf_ia;
try
{
PDF pdf_doc ("imgio/tests/orientation.pdf", "rb");
TEST_ASSERT( pdf_doc.numPages() == 4 );
pdf_doc.getPage(image_from_pdf_ba, 0, true);
read_image_gray( refimage_ba, stdio("imgio/tests/orientation-0.png", "rb"));
TEST_ASSERT( equal( refimage_ba, image_from_pdf_ba ) );
pdf_doc.getPage(image_from_pdf_ba, 1, true);
read_image_gray( refimage_ba, stdio("imgio/tests/orientation-1.png", "rb"));
TEST_ASSERT( equal( refimage_ba, image_from_pdf_ba ) );
pdf_doc.getPage(image_from_pdf_ba, 2, true);
read_image_gray( refimage_ba, stdio("imgio/tests/orientation-2.png", "rb"));
TEST_ASSERT( equal( refimage_ba, image_from_pdf_ba ) );
pdf_doc.getPage(image_from_pdf_ba, 3, true);
read_image_gray( refimage_ba, stdio("imgio/tests/orientation-3.png", "rb"));
TEST_ASSERT( equal( refimage_ba, image_from_pdf_ba ) );
}
catch(...)
{
TEST_OR_DIE( equal( refimage_ba, image_from_pdf_ba ) );
}
try
{
read_pdf( image_from_pdf_ba, stdio("imgio/tests/orientation.pdf", "rb"), true );
read_image_gray( refimage_ba, stdio("imgio/tests/orientation-0.png", "rb"));
TEST_ASSERT( equal( refimage_ba, image_from_pdf_ba ) );
}
catch(...)
{
TEST_OR_DIE( equal( refimage_ba, image_from_pdf_ba ) );
}
#if 0
try
{
read_pdf( image_from_pdf_ba, stdio("imgio/tests/orientation.pdf","rb"), false );
write_image_binary("imgio/tests/orientation_rgb.png", image_from_pdf_ba);
// TEST_ASSERT( equal( refimage_ba, image_from_pdf_ba ) );
}
catch(...)
{
TEST_OR_DIE( equal( refimage_ba, image_from_pdf_ba ) );
}
#endif
return 0;
}