Results 1 to 8 of 8

Thread: QImage loadFromData not run... XPDF data

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QImage loadFromData not run... XPDF data

    I try to load a Portable pixmap to QImage
    http://en.wikipedia.org/wiki/Portabl...ap_file_format and QImage not load ..

    I hack the XPDF 3.0.2 to enable build on QT4.3 i build on Win Mingw

    http://ppk.ciz.ch/qt_c++/XPDF_2_QT.tar.bz2 400kb

    the hard work was the pro file to accept minumum to make Portable pixmap


    only lib give no problem. main apps say ...

    main.cpp: In function `int main(int, char**)':
    main.cpp:54: error: conversion from `SplashBitmap*' to non-scalar type `QByteArr
    ay' requested



    Qt Code:
    1. #include <QFile>
    2. #include <QtCore>
    3. #include <QCoreApplication>
    4.  
    5. #include <aconf.h>
    6. #include <stdio.h>
    7. #include "parseargs.h"
    8. #include "GString.h"
    9. #include "Object.h"
    10. #include "PDFDoc.h"
    11. #include "SplashBitmap.h"
    12. #include "Splash.h"
    13. #include "SplashOutputDev.h"
    14. #include "config.h"
    15. #include <iostream>
    16. #include <QImage>
    17. using namespace std;
    18.  
    19. /* xpdf 3.02 PDF 1.4 dir and libs hacked to QT4 get http://ppk.ciz.ch/qt_c++/XPDF_2_QT.tar.bz2 400kb */
    20.  
    21.  
    22. int main(int argc, char *argv[]) {
    23. QCoreApplication a( argc, argv );
    24.  
    25. PDFDoc *doc;
    26. GString *fileName;
    27. GString *ownerPW, *userPW;
    28. SplashColor paperColor;
    29. SplashOutputDev *splashOut;
    30. GBool ok;
    31. int resolution = 300;
    32. ownerPW = NULL;
    33. userPW = NULL;
    34. int sumpage;
    35.  
    36. const QString filepdf = argv[1];
    37. if (filepdf.size() < 1) {
    38. cout << "Usage:\n";
    39. cout << "appsname pdf_file";
    40.  
    41. return 0;
    42. } else {
    43. /* build the class ! */
    44. fileName = new GString(new GString(filepdf)); /* GString is hack to accept QString */
    45. doc = new PDFDoc(fileName, ownerPW, userPW);
    46. paperColor[0] = paperColor[1] = paperColor[2] = 0xff;
    47. splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
    48. sumpage = doc->getNumPages();
    49. splashOut->startDoc(doc->getXRef());
    50.  
    51. for (int i=0;i<sumpage;i++) {
    52. int pagenr = i + 1; /* render page pdf nr. */
    53. doc->displayPage(splashOut, pagenr, resolution, resolution, 0, gFalse, gTrue, gFalse);
    54. QByteArray dat = splashOut->takeBitmap();
    55. QImage pdfpage;
    56. pdfpage.loadFromData(dat);
    57. /* if ok save .... */
    58. if (!pdfpage.isNull()) {
    59. const QString filepage = QString("Page%1.png").arg(pagenr);
    60. pdfpage.save(filepage,"PNG",100);
    61. }
    62.  
    63. }
    64.  
    65. /* remove class */
    66. delete splashOut;
    67. delete doc;
    68.  
    69. }
    70. return 0;
    71. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage loadFromData not run... XPDF data

    Could we see the SplashBitmap type?
    You cannot simply convert from SplashBitmap to QByteArray.

    Also, use QString::toAscii().constData() when you build the GString. So many allocations aren't good .

    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImage loadFromData not run... XPDF data

    If you want PPM support, why not use libppm to implement an imageformat plugin for Qt?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage loadFromData not run... XPDF data

    Qt Code:
    1. fileName = new GString(new GString(filepdf)); /* GString is hack to accept QString */
    To copy to clipboard, switch view to plain text mode 
    Actually, I don't think this is going to work at all. You will get an invalid GString.
    GString also has ha constructor GString( const char *). So you can pass filePdf.toAscii().constData() instead.

    regards

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage loadFromData not run... XPDF data

    Quote Originally Posted by marcel View Post
    Qt Code:
    1. fileName = new GString(new GString(filepdf)); /* GString is hack to accept QString */
    To copy to clipboard, switch view to plain text mode 
    Actually, I don't think this is going to work at all. You will get an invalid GString.
    GString also has ha constructor GString( const char *). So you can pass filePdf.toAscii().constData() instead.

    regards
    no this is not problem .... if
    qDebug() << "### doc->isOk() "<< doc->isOk();

    say true....

    i suppose the GlobalParams.h from xpdf is not enable to run on all OS....
    and a default setting not exist on this class....



    this run... GString support QString now ...

    i cute out 200 line and insert QT proper....

    Qt Code:
    1. GString::GString(const QString in) {
    2. int n = in.size();
    3. s = NULL;
    4. QByteArray der = in.toAscii();
    5. const char *sA = der.data();
    6. resize(length = n);
    7. memcpy(s, sA, n + 1);
    8. }
    9.  
    10.  
    11. other .... ...
    12.  
    13. GString *getHomeDir() {
    14.  
    15. const QString st = QDir::homePath();
    16.  
    17. return new GString(st);
    18. }
    19.  
    20. GString *getCurrentDir() {
    21. const QString st = QDir::currentPath();
    22. return new GString(st);
    23. }
    24.  
    25. GString *appendToPath(GString *path, char *fileName) {
    26.  
    27. QString xpat = path->QValue();
    28. if (!xpat.endsWith("/")) {
    29. xpat.append("/");
    30. }
    31. xpat.append(fileName);
    32. const QString st = xpat;
    33. return new GString(st);
    34. }
    35.  
    36. GString *grabPath(char *fileName) {
    37.  
    38. QString sfile = QString(fileName);
    39. QFileInfo now(sfile);
    40. QString xpat = now.absolutePath();
    41. return new GString(xpat);
    42. }
    43.  
    44. GBool isAbsolutePath(char *path) {
    45.  
    46. QString spat = QString(path);
    47. QDir now(spat);
    48. return now.isAbsolute();
    49. }
    50.  
    51. GString *makePathAbsolute(GString *path) {
    52.  
    53. QString xpati = path->QValue();
    54. QDir now(xpati);
    55. QString xpat = now.absolutePath();
    56. return new GString(xpat);
    57. }
    58.  
    59. time_t getModTime(char *fileName) {
    60.  
    61. QString sfile = QString(fileName);
    62.  
    63. QFileInfo now(sfile);
    64. QDateTime filet = now.lastModified();
    65. return filet.toTime_t();
    66. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage loadFromData not run... XPDF data

    Well, it's OK then. I thought you're using the unmodified GString from xpdf.

    What about the SplashBitmap?

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage loadFromData not run... XPDF data

    Quote Originally Posted by wysota View Post
    If you want PPM support, why not use libppm to implement an imageformat plugin for Qt?

    QT4 already read PPM ...

    i found on

    QList<QByteArray> formats = QImageReader::supportedImageFormats();

    I need pdf and postscript eps to image.....
    Write a plug-in is not a game...

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage loadFromData not run... XPDF data

    Quote Originally Posted by marcel View Post
    Well, it's OK then. I thought you're using the unmodified GString from xpdf.

    What about the SplashBitmap?
    You think to take out data from here ...

    this run and write file....



    grab data from this??

    case splashModeRGB8:

    How?




    Qt Code:
    1. SplashError SplashBitmap::writePNMFile(char *fileName) {
    2. FILE *f;
    3. SplashColorPtr row, p;
    4. int x, y;
    5.  
    6. if (!(f = fopen(fileName, "wb"))) {
    7. return splashErrOpenFile;
    8. }
    9.  
    10. switch (mode) {
    11.  
    12. case splashModeMono1:
    13. fprintf(f, "P4\n%d %d\n", width, height);
    14. row = data;
    15. for (y = 0; y < height; ++y) {
    16. p = row;
    17. for (x = 0; x < width; x += 8) {
    18. fputc(*p ^ 0xff, f);
    19. ++p;
    20. }
    21. row += rowSize;
    22. }
    23. break;
    24.  
    25. case splashModeMono8:
    26. fprintf(f, "P5\n%d %d\n255\n", width, height);
    27. row = data;
    28. for (y = 0; y < height; ++y) {
    29. p = row;
    30. for (x = 0; x < width; ++x) {
    31. fputc(*p, f);
    32. ++p;
    33. }
    34. row += rowSize;
    35. }
    36. break;
    37.  
    38. case splashModeRGB8:
    39. fprintf(f, "P6\n%d %d\n255\n", width, height);
    40. row = data;
    41. for (y = 0; y < height; ++y) {
    42. p = row;
    43. for (x = 0; x < width; ++x) {
    44. fputc(splashRGB8R(p), f);
    45. fputc(splashRGB8G(p), f);
    46. fputc(splashRGB8B(p), f);
    47. p += 3;
    48. }
    49. row += rowSize;
    50. }
    51. break;
    52.  
    53. case splashModeBGR8:
    54. fprintf(f, "P6\n%d %d\n255\n", width, height);
    55. row = data;
    56. for (y = 0; y < height; ++y) {
    57. p = row;
    58. for (x = 0; x < width; ++x) {
    59. fputc(splashBGR8R(p), f);
    60. fputc(splashBGR8G(p), f);
    61. fputc(splashBGR8B(p), f);
    62. p += 3;
    63. }
    64. row += rowSize;
    65. }
    66. break;
    67.  
    68. #if SPLASH_CMYK
    69. case splashModeCMYK8:
    70. // PNM doesn't support CMYK
    71. break;
    72. #endif
    73. }
    74.  
    75. fclose(f);
    76. return splashOk;
    77. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Creating a QImage from uchar* data
    By forrestfsu in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 15:21
  2. how to use loadFromData in painter
    By sar_van81 in forum Qt Programming
    Replies: 18
    Last Post: 31st January 2007, 04:09
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  4. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.