]> rtime.felk.cvut.cz Git - sojka/tekpic.git/commitdiff
Added support for PCX images. TDS224 doesn't have TIFF.
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 10 Nov 2006 10:01:08 +0000 (11:01 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 10 Nov 2006 10:01:08 +0000 (11:01 +0100)
darcs-hash:20061110100108-f2ef6-790afecd4e3223c333769678b75bb900760d16fe.gz

qtpcxio/pcx.cpp [new file with mode: 0644]
qtpcxio/pcx.h [new file with mode: 0644]
qtpcxio/pcxio.pri [new file with mode: 0644]
qtpcxio/pcxio.pro [new file with mode: 0644]
qtpcxio/pcxio_dbg.pro [new file with mode: 0644]
qtpcxio/rules.pri [new file with mode: 0644]
src/main.ui
src/mainwindow.cpp
src/mainwindow.h
src/osccommthread.cpp
src/osccommthread.h

diff --git a/qtpcxio/pcx.cpp b/qtpcxio/pcx.cpp
new file mode 100644 (file)
index 0000000..b500196
--- /dev/null
@@ -0,0 +1,616 @@
+/* This file is part of the KDE project
+   Copyright (C) 2002-2005 Nadeem Hasan <nhasan@kde.org>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License (LGPL) as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+*/
+
+#include "pcx.h"
+
+#include <qimage.h>
+
+static QDataStream &operator>>( QDataStream &s, RGB &rgb )
+{
+  s >> rgb.r >> rgb.g >> rgb.b;
+
+  return s;
+}
+
+static QDataStream &operator>>( QDataStream &s, Palette &pal )
+{
+  for ( int i=0; i<16; ++i )
+    s >> pal.rgb[ i ];
+
+  return s;
+}
+
+static QDataStream &operator>>( QDataStream &s, PCXHEADER &ph )
+{
+  s >> ph.Manufacturer;
+  s >> ph.Version;
+  s >> ph.Encoding;
+  s >> ph.Bpp;
+  s >> ph.XMin >> ph.YMin >> ph.XMax >> ph.YMax;
+  s >> ph.HDpi >> ph.YDpi;
+  s >> ph.ColorMap;
+  s >> ph.Reserved;
+  s >> ph.NPlanes;
+  s >> ph.BytesPerLine;
+  s >> ph.PaletteInfo;
+  s >> ph.HScreenSize;
+  s >> ph.VScreenSize;
+
+  // Skip the rest of the header
+  quint8 byte;
+  while ( s.device()->pos() < 128 )
+    s >> byte;
+
+  return s;
+}
+
+static QDataStream &operator<<( QDataStream &s, const RGB &rgb )
+{
+  s << rgb.r << rgb.g << rgb.b;
+
+  return s;
+}
+
+static QDataStream &operator<<( QDataStream &s, const Palette &pal )
+{
+  for ( int i=0; i<16; ++i )
+    s << pal.rgb[ i ];
+
+  return s;
+}
+
+static QDataStream &operator<<( QDataStream &s, const PCXHEADER &ph )
+{
+  s << ph.Manufacturer;
+  s << ph.Version;
+  s << ph.Encoding;
+  s << ph.Bpp;
+  s << ph.XMin << ph.YMin << ph.XMax << ph.YMax;
+  s << ph.HDpi << ph.YDpi;
+  s << ph.ColorMap;
+  s << ph.Reserved;
+  s << ph.NPlanes;
+  s << ph.BytesPerLine;
+  s << ph.PaletteInfo;
+  s << ph.HScreenSize;
+  s << ph.VScreenSize;
+
+  quint8 byte = 0;
+  for ( int i=0; i<54; ++i )
+    s << byte;
+
+  return s;
+}
+
+PCXHEADER::PCXHEADER()
+{
+  // Initialize all data to zero
+  QByteArray dummy( 128, 0 );
+  dummy.fill( 0 );
+  QDataStream s( &dummy, QIODevice::ReadOnly );
+  s >> *this;
+}
+
+static void readLine( QDataStream &s, QByteArray &buf, const PCXHEADER &header )
+{
+  quint32 i=0;
+  quint32 size = buf.size();
+  quint8 byte, count;
+
+  if ( header.isCompressed() )
+  {
+    // Uncompress the image data
+    while ( i < size )
+    {
+      count = 1;
+      s >> byte;
+      if ( byte > 0xc0 )
+      {
+        count = byte - 0xc0;
+        s >> byte;
+      }
+      while ( count-- && i < size )
+        buf[ i++ ] = byte;
+    }
+  }
+  else
+  {
+    // Image is not compressed (possible?)
+    while ( i < size )
+    {
+      s >> byte;
+      buf[ i++ ] = byte;
+    }
+  }
+}
+
+static void readImage1( QImage &img, QDataStream &s, const PCXHEADER &header )
+{
+  QByteArray buf( header.BytesPerLine, 0 );
+
+  img = QImage( header.width(), header.height(), QImage::Format_Mono );
+  img.setNumColors( 2 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    if ( s.atEnd() )
+    {
+      img = QImage();
+      return;
+    }
+
+    readLine( s, buf, header );
+    uchar *p = img.scanLine( y );
+    unsigned int bpl = qMin((quint16)((header.width()+7)/8), header.BytesPerLine);
+    for ( unsigned int x=0; x< bpl; ++x )
+      p[ x ] = buf[x];
+  }
+
+  // Set the color palette
+  img.setColor( 0, qRgb( 0, 0, 0 ) );
+  img.setColor( 1, qRgb( 255, 255, 255 ) );
+}
+
+static void readImage4( QImage &img, QDataStream &s, const PCXHEADER &header )
+{
+  QByteArray buf( header.BytesPerLine*4, 0 );
+  QByteArray pixbuf( header.width(), 0 );
+
+  img = QImage( header.width(), header.height(), QImage::Format_Indexed8 );
+  img.setNumColors( 16 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    if ( s.atEnd() )
+    {
+      img = QImage();
+      return;
+    }
+
+    pixbuf.fill( 0 );
+    readLine( s, buf, header );
+
+    for ( int i=0; i<4; i++ )
+    {
+      quint32 offset = i*header.BytesPerLine;
+      for ( int x=0; x<header.width(); ++x )
+        if ( buf[ offset + ( x/8 ) ] & ( 128 >> ( x%8 ) ) )
+          pixbuf[ x ] = (int)(pixbuf[ x ]) + ( 1 << i );
+    }
+
+    uchar *p = img.scanLine( y );
+    for ( int x=0; x<header.width(); ++x )
+      p[ x ] = pixbuf[ x ];
+  }
+
+  // Read the palette
+  for ( int i=0; i<16; ++i )
+    img.setColor( i, header.ColorMap.color( i ) );
+}
+
+static void readImage8( QImage &img, QDataStream &s, const PCXHEADER &header )
+{
+  QByteArray buf( header.BytesPerLine, 0 );
+
+  img = QImage( header.width(), header.height(), QImage::Format_Indexed8 );
+  img.setNumColors( 256 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    if ( s.atEnd() )
+    {
+      img = QImage();
+      return;
+    }
+
+    readLine( s, buf, header );
+
+    uchar *p = img.scanLine( y );
+    unsigned int bpl = qMin(header.BytesPerLine, (quint16)header.width());
+    for ( unsigned int x=0; x<bpl; ++x )
+      p[ x ] = buf[ x ];
+  }
+
+  quint8 flag;
+  s >> flag;
+//  kDebug( 399 ) << "Palette Flag: " << flag << endl;
+
+  if ( flag == 12 && ( header.Version == 5 || header.Version == 2 ) )
+  {
+    // Read the palette
+    quint8 r, g, b;
+    for ( int i=0; i<256; ++i )
+    {
+      s >> r >> g >> b;
+      img.setColor( i, qRgb( r, g, b ) );
+    }
+  }
+}
+
+static void readImage24( QImage &img, QDataStream &s, const PCXHEADER &header )
+{
+  QByteArray r_buf( header.BytesPerLine, 0 );
+  QByteArray g_buf( header.BytesPerLine, 0 );
+  QByteArray b_buf( header.BytesPerLine, 0 );
+
+  img = QImage( header.width(), header.height(), QImage::Format_RGB32 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    if ( s.atEnd() )
+    {
+      img = QImage();
+      return;
+    }
+
+    readLine( s, r_buf, header );
+    readLine( s, g_buf, header );
+    readLine( s, b_buf, header );
+
+    uint *p = ( uint * )img.scanLine( y );
+    for ( int x=0; x<header.width(); ++x )
+      p[ x ] = qRgb( r_buf[ x ], g_buf[ x ], b_buf[ x ] );
+  }
+}
+
+static void writeLine( QDataStream &s, QByteArray &buf )
+{
+  quint32 i = 0;
+  quint32 size = buf.size();
+  quint8 count, data;
+  char byte;
+
+  while ( i < size )
+  {
+    count = 1;
+    byte = buf[ i++ ];
+
+    while ( ( i < size ) && ( byte == buf[ i ] ) && ( count < 63 ) )
+    {
+      ++i;
+      ++count;
+    }
+
+    data = byte;
+
+    if ( count > 1 || data >= 0xc0 )
+    {
+      count |= 0xc0;
+      s << count;
+    }
+
+    s << data;
+  }
+}
+
+static void writeImage1( QImage &img, QDataStream &s, PCXHEADER &header )
+{
+  img.convertToFormat( QImage::Format_Mono );
+
+  header.Bpp = 1;
+  header.NPlanes = 1;
+  header.BytesPerLine = img.bytesPerLine();
+
+  s << header;
+
+  QByteArray buf( header.BytesPerLine, 0 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    quint8 *p = img.scanLine( y );
+
+    // Invert as QImage uses reverse palette for monochrome images?
+    for ( int i=0; i<header.BytesPerLine; ++i )
+      buf[ i ] = ~p[ i ];
+
+    writeLine( s, buf );
+  }
+}
+
+static void writeImage4( QImage &img, QDataStream &s, PCXHEADER &header )
+{
+  header.Bpp = 1;
+  header.NPlanes = 4;
+  header.BytesPerLine = header.width()/8;
+
+  for ( int i=0; i<16; ++i )
+    header.ColorMap.setColor( i, img.color( i ) );
+
+  s << header;
+
+  QByteArray buf[ 4 ];
+
+  for ( int i=0; i<4; ++i )
+      buf[ i ].resize( header.BytesPerLine );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    quint8 *p = img.scanLine( y );
+
+    for ( int i=0; i<4; ++i )
+      buf[ i ].fill( 0 );
+
+    for ( int x=0; x<header.width(); ++x )
+    {
+      for ( int i=0; i<4; ++i )
+        if ( *( p+x ) & ( 1 << i ) )
+          buf[ i ][ x/8 ] = (int)(buf[ i ][ x/8 ])| 1 << ( 7-x%8 );
+    }
+
+    for ( int i=0; i<4; ++i )
+      writeLine( s, buf[ i ] );
+  }
+}
+
+static void writeImage8( QImage &img, QDataStream &s, PCXHEADER &header )
+{
+  header.Bpp = 8;
+  header.NPlanes = 1;
+  header.BytesPerLine = img.bytesPerLine();
+
+  s << header;
+
+  QByteArray buf( header.BytesPerLine, 0 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    quint8 *p = img.scanLine( y );
+
+    for ( int i=0; i<header.BytesPerLine; ++i )
+      buf[ i ] = p[ i ];
+
+    writeLine( s, buf );
+  }
+
+  // Write palette flag
+  quint8 byte = 12;
+  s << byte;
+
+  // Write palette
+  for ( int i=0; i<256; ++i )
+    s << RGB( img.color( i ) );
+}
+
+static void writeImage24( QImage &img, QDataStream &s, PCXHEADER &header )
+{
+  header.Bpp = 8;
+  header.NPlanes = 3;
+  header.BytesPerLine = header.width();
+
+  s << header;
+
+  QByteArray r_buf( header.width(), 0 );
+  QByteArray g_buf( header.width(), 0 );
+  QByteArray b_buf( header.width(), 0 );
+
+  for ( int y=0; y<header.height(); ++y )
+  {
+    uint *p = ( uint * )img.scanLine( y );
+
+    for ( int x=0; x<header.width(); ++x )
+    {
+      QRgb rgb = *p++;
+      r_buf[ x ] = qRed( rgb );
+      g_buf[ x ] = qGreen( rgb );
+      b_buf[ x ] = qBlue( rgb );
+    }
+
+    writeLine( s, r_buf );
+    writeLine( s, g_buf );
+    writeLine( s, b_buf );
+  }
+}
+
+
+PCXHandler::PCXHandler()
+{
+}
+
+bool PCXHandler::canRead() const
+{
+    return canRead(device());
+}
+
+bool PCXHandler::read(QImage *outImage)
+{
+  QDataStream s( device() );
+  s.setByteOrder( QDataStream::LittleEndian );
+
+  if ( s.device()->size() < 128 )
+  {
+    return false;
+  }
+
+  PCXHEADER header;
+
+  s >> header;
+
+  if ( header.Manufacturer != 10 || s.atEnd())
+  {
+    return false;
+  }
+
+  int w = header.width();
+  int h = header.height();
+
+//  kDebug( 399 ) << "Manufacturer: " << header.Manufacturer << endl;
+//   kDebug( 399 ) << "Version: " << header.Version << endl;
+//   kDebug( 399 ) << "Encoding: " << header.Encoding << endl;
+//   kDebug( 399 ) << "Bpp: " << header.Bpp << endl;
+//   kDebug( 399 ) << "Width: " << w << endl;
+//   kDebug( 399 ) << "Height: " << h << endl;
+//   kDebug( 399 ) << "Window: " << header.XMin << "," << header.XMax << ","
+//                  << header.YMin << "," << header.YMax << endl;
+//   kDebug( 399 ) << "BytesPerLine: " << header.BytesPerLine << endl;
+//   kDebug( 399 ) << "NPlanes: " << header.NPlanes << endl;
+
+  QImage img;
+
+  if ( header.Bpp == 1 && header.NPlanes == 1 )
+  {
+    readImage1( img, s, header );
+  }
+  else if ( header.Bpp == 1 && header.NPlanes == 4 )
+  {
+    readImage4( img, s, header );
+  }
+  else if ( header.Bpp == 8 && header.NPlanes == 1 )
+  {
+    readImage8( img, s, header );
+  }
+  else if ( header.Bpp == 8 && header.NPlanes == 3 )
+  {
+    readImage24( img, s, header );
+  }
+
+//   kDebug( 399 ) << "Image Bytes: " << img.numBytes() << endl;
+//   kDebug( 399 ) << "Image Bytes Per Line: " << img.bytesPerLine() << endl;
+//   kDebug( 399 ) << "Image Depth: " << img.depth() << endl;
+
+  if ( !img.isNull() )
+  {
+    *outImage = img;
+    return true;
+  }
+  else
+  {
+    return false;
+  }
+}
+
+bool PCXHandler::write(const QImage &image)
+{
+  QDataStream s( device() );
+  s.setByteOrder( QDataStream::LittleEndian );
+
+  QImage img = image;
+
+  int w = img.width();
+  int h = img.height();
+
+//   kDebug( 399 ) << "Width: " << w << endl;
+//   kDebug( 399 ) << "Height: " << h << endl;
+//   kDebug( 399 ) << "Depth: " << img.depth() << endl;
+//   kDebug( 399 ) << "BytesPerLine: " << img.bytesPerLine() << endl;
+//   kDebug( 399 ) << "Num Colors: " << img.numColors() << endl;
+
+  PCXHEADER header;
+
+  header.Manufacturer = 10;
+  header.Version = 5;
+  header.Encoding = 1;
+  header.XMin = 0;
+  header.YMin = 0;
+  header.XMax = w-1;
+  header.YMax = h-1;
+  header.HDpi = 300;
+  header.YDpi = 300;
+  header.Reserved = 0;
+  header.PaletteInfo =1;
+
+  if ( img.depth() == 1 )
+  {
+    writeImage1( img, s, header );
+  }
+  else if ( img.depth() == 8 && img.numColors() <= 16 )
+  {
+    writeImage4( img, s, header );
+  }
+  else if ( img.depth() == 8 )
+  {
+    writeImage8( img, s, header );
+  }
+  else if ( img.depth() == 32 )
+  {
+    writeImage24( img, s, header );
+  }
+
+  return true;
+}
+
+QByteArray PCXHandler::name() const
+{
+    return "pcx";
+}
+
+bool PCXHandler::canRead(QIODevice *device)
+{
+    if (!device) {
+        qWarning("PCXHandler::canRead() called with no device");
+        return false;
+    }
+
+    qint64 oldPos = device->pos();
+
+    char head[1];
+    qint64 readBytes = device->read(head, sizeof(head));
+    if (readBytes != sizeof(head)) {
+        if (device->isSequential()) {
+            while (readBytes > 0)
+                device->ungetChar(head[readBytes-- - 1]);
+        } else {
+            device->seek(oldPos);
+        }
+        return false;
+    }
+
+    if (device->isSequential()) {
+        while (readBytes > 0)
+            device->ungetChar(head[readBytes-- - 1]);
+    } else {
+        device->seek(oldPos);
+    }
+
+    return qstrncmp(head, "\012", 1) == 0;
+}
+
+class PCXPlugin : public QImageIOPlugin
+{
+public:
+    QStringList keys() const;
+    Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
+    QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
+};
+
+QStringList PCXPlugin::keys() const
+{
+    return QStringList() << "pcx" << "PCX";
+}
+
+QImageIOPlugin::Capabilities PCXPlugin::capabilities(QIODevice *device, const QByteArray &format) const
+{
+    if (format == "pcx" || format == "PCX")
+        return Capabilities(CanRead | CanWrite);
+    if (!format.isEmpty())
+        return 0;
+    if (!device->isOpen())
+        return 0;
+
+    Capabilities cap;
+    if (device->isReadable() && PCXHandler::canRead(device))
+        cap |= CanRead;
+    if (device->isWritable())
+        cap |= CanWrite;
+    return cap;
+}
+
+QImageIOHandler *PCXPlugin::create(QIODevice *device, const QByteArray &format) const
+{
+    QImageIOHandler *handler = new PCXHandler;
+    handler->setDevice(device);
+    handler->setFormat(format);
+    return handler;
+}
+
+Q_EXPORT_STATIC_PLUGIN(PCXPlugin)
+Q_EXPORT_PLUGIN2(pcx, PCXPlugin)
+
+/* vim: et sw=2 ts=2
+*/
+
diff --git a/qtpcxio/pcx.h b/qtpcxio/pcx.h
new file mode 100644 (file)
index 0000000..1cb74c3
--- /dev/null
@@ -0,0 +1,113 @@
+/* This file is part of the KDE project
+   Copyright (C) 2002-2003 Nadeem Hasan <nhasan@kde.org>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the Lesser GNU General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+*/
+
+#ifndef PCX_H
+#define PCX_H
+
+
+#include <QImageIOHandler>
+#include <QDataStream>
+#include <QColor>
+
+class PCXHandler : public QImageIOHandler
+{
+public:
+    PCXHandler();
+
+    bool canRead() const;
+    bool read(QImage *image);
+    bool write(const QImage &image);
+
+    QByteArray name() const;
+
+    static bool canRead(QIODevice *device);
+};
+
+class RGB
+{
+  public:
+    RGB() { }
+
+    RGB( const QRgb color )
+    {
+      r = qRed( color );
+      g = qGreen( color );
+      b = qBlue( color );
+    }
+
+    quint8 r;
+    quint8 g;
+    quint8 b;
+};
+
+class Palette
+{
+  public:
+    Palette() { }
+
+    void setColor( int i, const QRgb color )
+    {
+      rgb[ i ] = RGB( color );
+    }
+
+    QRgb color( int i ) const
+    {
+      return qRgb( rgb[ i ].r, rgb[ i ].g, rgb[ i ].b );
+    }
+
+    class RGB rgb[ 16 ];
+};
+
+class PCXHEADER
+{
+  public:
+    PCXHEADER();
+
+    inline int width() const { return ( XMax-XMin ) + 1; }
+    inline int height() const { return ( YMax-YMin ) + 1; }
+    inline bool isCompressed() const { return ( Encoding==1 ); }
+
+    quint8  Manufacturer;    // Constant Flag, 10 = ZSoft .pcx
+    quint8  Version;         // Version information·
+                              // 0 = Version 2.5 of PC Paintbrush·
+                              // 2 = Version 2.8 w/palette information·
+                              // 3 = Version 2.8 w/o palette information·
+                              // 4 = PC Paintbrush for Windows(Plus for
+                              //     Windows uses Ver 5)·
+                              // 5 = Version 3.0 and > of PC Paintbrush
+                              //     and PC Paintbrush +, includes
+                              //     Publisher's Paintbrush . Includes
+                              //     24-bit .PCX files·
+    quint8  Encoding;        // 1 = .PCX run length encoding
+    quint8  Bpp;             // Number of bits to represent a pixel
+                              // (per Plane) - 1, 2, 4, or 8·
+    quint16 XMin;
+    quint16 YMin;
+    quint16 XMax;
+    quint16 YMax;
+    quint16 HDpi;
+    quint16 YDpi;
+    Palette  ColorMap;
+    quint8  Reserved;        // Should be set to 0.
+    quint8  NPlanes;         // Number of color planes
+    quint16 BytesPerLine;    // Number of bytes to allocate for a scanline
+                              // plane.  MUST be an EVEN number.  Do NOT
+                              // calculate from Xmax-Xmin.·
+    quint16 PaletteInfo;     // How to interpret palette- 1 = Color/BW,
+                              // 2 = Grayscale ( ignored in PB IV/ IV + )·
+    quint16 HScreenSize;     // Horizontal screen size in pixels. New field
+                              // found only in PB IV/IV Plus
+    quint16 VScreenSize;     // Vertical screen size in pixels. New field
+                              // found only in PB IV/IV Plus
+} KDE_PACKED;
+
+#endif // PCX_H
+
+/* vim: et sw=2 ts=2
+*/
diff --git a/qtpcxio/pcxio.pri b/qtpcxio/pcxio.pri
new file mode 100644 (file)
index 0000000..e32eff8
--- /dev/null
@@ -0,0 +1,64 @@
+# TiffIO.pri : define evrything common to TiffIO and TiffIO-debug
+#
+# $Id: TiffIO.pri,v 1.29 2006/08/30 09:40:47 gascuel Exp $
+#
+#-----------------------------------------------------------------------------
+# qmake runtime options:
+#
+#   DEFINES+=Q_STATIC_PLUGIN=1 (Qt3) or QT_STATICPLUGIN=1 (Qt4)
+#                   : if defined at compile time, and TiffIO.pri is included
+#                     in your project, then the codec is linked within your
+#                     project, and initialised automatically at run time.
+#                     (See test.pro for an example).
+#
+#   CONFIG+=no-zlib : Do not support zlib (even if found)
+#   CONFIG+=no-jpeg : Do not support lib jpeg (even if found)
+#   CONFIG+=no-lzw  : Do not support lzw compression from libtiff sources.
+#   CONFIG+=no-lzw-encode  : Do support lzw decode, but not encode.
+#
+#-----------------------------------------------------------------------------
+#
+# I *strongly* urge you not to compile with a different version of LibTiff...
+# Nevertheless, some of your folks have to live dangerously for whatever 
+# reason, so the config file enable you to do that :
+#
+#  qmake TIFF=/home/me/libtiff-3.7.4/src TiffIO.pro
+#       compiles using a different directory to look for tiff's sources.
+#
+#  qmake CONFIG+=libtiff TiffIO.pro
+#       compiles using a precompiled tiff library, located in the TIFF_ROOT
+#       (command line argument, or env var) directory.
+#
+#       TIFF_ROOT defaults to "/usr", hence using the unix standard
+#       "/usr/include/tiffio.h" and "/usr/lib/libtiff.so" (or .a) files.
+#
+#-----------------------------------------------------------------------------
+#
+# Using your own version of the jpeg lib (eg. from $QTDIR/src/3rdparty/libjpeg)
+# for win32 :
+#
+#   - Compile the lib, in order to have a directory with both the jpeglib.h
+#     and libjpeg.lib
+#
+#   - run qmake with the 'JPEG=$QTDIR/src/3rdparty/libjpeg' option (or your
+#     own directory).
+#
+# This is helpfull, because even you you install Qt3 or Qt4 with jpeg support,
+# they are inside a dll (Qt of plugin), where jpeg symbols are not exported,
+# hence you can't link against them.
+# 
+#-----------------------------------------------------------------------------
+
+CONFIG -= debug_and_release debug_and_release_target
+CONFIG *= qt
+
+# Note: we have our own error handler, no needs to compile TIFF's own
+#       (that generates link error on Qt4/nmake compiles).
+DEFINES += TIF_PLATFORM_CONSOLE=1
+
+SOURCES += \
+    pcx.cpp
+
+# qt3: SOURCES += TiffIO_Qt3.cpp
+# qt4: SOURCES += pcx.cpp
+
diff --git a/qtpcxio/pcxio.pro b/qtpcxio/pcxio.pro
new file mode 100644 (file)
index 0000000..dd3ca45
--- /dev/null
@@ -0,0 +1,28 @@
+# TiffIO.pro : Compile the release plugin version of TiffIO.
+#
+# $Id: TiffIO.pro,v 1.7 2006/01/12 01:57:40 gascuel Exp $
+#
+
+CONFIG  += plugin dynlib release dll
+CONFIG  -= debug
+
+TEMPLATE= lib
+TARGET  = pcxio
+
+!include( rules.pri )  : error( Unable to find rules.pri )
+!include( pcxio.pri )  : error( Unable to find pcxio.pri )
+
+# NOTE: Install features have been removed from Qt 4.0 (and 4.1) doc,
+#       *but* they are still working...
+#
+linux {
+    target.path = $$(RPM_BUILD_ROOT)$$(QTDIR)/plugins/imageformats/
+    INSTALLS += target
+}
+
+macx {
+    target.path = $$(QTDIR)/plugins/imageformats/
+    INSTALLS += target
+}
+
+win32: DESTDIR = $$(QTDIR)/plugins/imageformats/
diff --git a/qtpcxio/pcxio_dbg.pro b/qtpcxio/pcxio_dbg.pro
new file mode 100644 (file)
index 0000000..6d1783f
--- /dev/null
@@ -0,0 +1,30 @@
+# TiffIO.pro : Compile the debug plugin version of TiffIO.
+#
+# $Id: TiffIO_DBG.pro,v 1.5 2006/03/21 09:56:49 gascuel Exp $
+#
+
+CONFIG  += plugin dynlib debug
+CONFIG  -= release
+
+TEMPLATE= lib
+TARGET  = TiffIO
+
+!include( rules.pri )  : error( Unable to find rules.pri )
+!include( TiffIO.pri ) : error( Unable to find TiffIO.pri )
+
+# NOTE: Install features have been removed from Qt 4.0 (and 4.1) doc,
+#       *but* they are still working...
+#
+linux {
+    target.path = $$(RPM_BUILD_ROOT)$$(QTDIR)/plugins/imageformats/
+    INSTALLS += target
+}
+
+macx {
+    target.path = $$(QTDIR)/plugins/imageformats/
+    INSTALLS += target
+}
+
+# No install: directly compile at destination. Meaning all Qt app
+# should be exited before linking can write the dll.
+win32: DESTDIR = $$(QTDIR)/plugins/imageformats/
diff --git a/qtpcxio/rules.pri b/qtpcxio/rules.pri
new file mode 100644 (file)
index 0000000..b2c7cfb
--- /dev/null
@@ -0,0 +1,313 @@
+#######################################################################
+#
+# Basic compilation rules. Should not need to be changed 8-).
+#
+#######################################################################
+# Make sure debug/release flags are set correctly.
+debug: release: error( Can't be both in debug and release mode )
+
+debug {
+    message(----------- DEBUG compilation ----------------)
+    DEFINES *= DEBUG 
+    # Add all the Qt's check flags. This the default, but add them in any case.
+    DEFINES *= QT_DEBUG QT_FATAL_ASSERT
+    TARGET = $$TARGET-debug
+    
+    win32 {
+        OBJECTS_DIR = Debug/Obj/
+    } else {
+        OBJECTS_DIR = .debug.obj/
+    }
+}
+
+release {
+    message(+++++++++++ RELEASE compilation ++++++++++++++)
+    # Remove all Qt's checking code, and all Q_ASSERT().
+    # *BUT* still do Q_CHECK_PTR !
+    DEFINES *= QT_NO_DEBUG QT_NO_CHECK QT_CHECK_NULL
+
+    win32 {
+        OBJECTS_DIR = Release/Obj/
+    } else {
+        OBJECTS_DIR = .release.obj/
+    }
+}
+
+win32 {
+    MOC_DIR = Generated/
+} else {
+    MOC_DIR = .generated/
+}
+UI_DIR  = $${MOC_DIR}
+
+#######################################################################
+#
+# Specific compiler rules. Might need to be twicked to achieve what
+# you really need...
+#
+#######################################################################
+
+win32 {
+    DEFINES *= WIN32=1
+    DEFINES -= UNICODE
+    DEFINES *= HAVE_STRING_H=1
+}
+
+win32-msvc {
+    message( Compile using MSVC6 )
+    # Make sure to have C++/C files, PentiumPro code, few warnings
+    # add support to RTTI and Exceptions,
+    # and generate debug info "program database" :
+    QMAKE_CXXFLAGS = -TP -G6 -W1 -GR -GX -EHsc -Zi -Fo$$OBJECTS_DIR -FR$$OBJECTS_DIR -Fd$$OBJECTS_DIR
+    QMAKE_CFLAGS =   -TC -G6 -W1 -GR -GX -EHsc -Zi -Fo$$OBJECTS_DIR -FR$$OBJECTS_DIR -Fd$$OBJECTS_DIR
+    # Optimise for speed, and expand any suitable inlines :
+    QMAKE_CXXFLAGS_RELEASE = -Ot -Ox
+    QMAKE_CFLAGS_RELEASE   = -Ot -Ox
+    # Optimise for debug :
+    QMAKE_CXXFLAGS_DEBUG = -Od
+    QMAKE_CFLAGS_DEBUG   = -Od
+}
+
+win32-msvc.net* {
+    message( Compile using .NET )
+    # Make sure to have C++ files, PentiumPro code, few warnings
+    # add support to RTTI, use exceptions, use ANSI C++ for scope,
+    # and generate debug info "program database", and compile using intrisic functions
+    QMAKE_CFLAGS = -G6 -G7 -GR -EHsc -Zc:forScope -Zi -Oi
+    QMAKE_CFLAGS += -MT -Fd$$OBJECTS_DIR
+    QMAKE_CXXFLAGS = -TP $$QMAKE_CFLAGS
+    
+    # Full Optimise, Global optimize, Optimise for speed, 
+    # omit frame pointer, and expand any suitable inlines :
+    QMAKE_CXXFLAGS_RELEASE= -Ox -Og -Ot -Oy -Ob2
+    QMAKE_CFLAGS_RELEASE  = $$QMAKE_CXXFLAGS_RELEASE
+    
+    # Optimise for debug, and generate navigation file
+    QMAKE_CXXFLAGS_DEBUG  = -Od -Fr
+    QMAKE_CFLAGS_DEBUG    = $$QMAKE_CXXFLAGS_DEBUG
+    
+    # Bugs in Qt's .h and mkspecs/qmake.conf :
+    # warning 4251 : nécessite une interface DLL pour être utilisé(e)
+    #                (issues in QGLViewer)
+    # warning 4305 : troncation de 'double' à 'float'
+    # warning 4189 : variable locale initialisée mais non référencée
+    QMAKE_CXXFLAGS_WARN_ON = -W3 -wd4100 -wd4251 -wd4305 -wd4189
+    
+    # Links flags :
+    # Add checksum, and machine code X86.
+    QMAKE_LFLAGS += -machine:x86
+    release {
+        QMAKE_LFLAGS *= /RELEASE
+        QMAKE_LFLAGS -= /DEBUG
+    }
+}
+
+# Copyed from win32-msvc.net
+# See http://blogs.msdn.com/branbray/archive/2005/07/08/437078.aspx for a nice description
+# for the new switch rationals.
+win32-msvc2005 {
+    message( Compile using Visual Studio 2005 (8.0))
+
+    # Make sure to have C++/C files (TP),
+    # Share string literals (in a RO page) (GF),
+    # add use exceptions (EHsc),
+    # and compile using intrisic functions (Oi),
+    # and enlarge compiler memory allocation (by 800%).
+    # Now by default : ZR (RTTI) and  Zc:forScope
+    QMAKE_CXXFLAGS = -TP -EHsc -Oi -Zm800
+    QMAKE_CFLAGS   = -TC -EHsc -Oi -Zm800
+
+    # Full Optimise, Global optimize, Optimise for speed, 
+    # omit frame pointer, and expand any suitable inlines :
+    #  /Os = also throw Oy Ob2 GF
+    # Note : -Os == -O2 == -Ox
+    QMAKE_CXXFLAGS_RELEASE = -Os
+    QMAKE_CFLAGS_RELEASE   = -Os
+
+    # Optimise for debug, and generate navigation file
+    # Output debug info (Zi),
+    # Don't optimize (Od)
+    # /Od = also throw Oi- Oy-  Ob0 GF-
+    QMAKE_CXXFLAGS_DEBUG = -Od -Zi
+    QMAKE_CFLAGS_DEBUG   = -Od -Zi
+
+    # Qt Bug #114573 in vcproj generator. Waitting for 3.3.7 ...
+    # QMAKE_CXXFLAGS += -arch:SSE2
+
+    # .PDB and .SBR hidden in Obj dir.
+    QMAKE_CXXFLAGS += -Fd$$OBJECTS_DIR
+    QMAKE_CFLAGS   += -Fd$$OBJECTS_DIR
+
+    # avoid Microsoft crazyness about deprecating *NORMALIZED* functions...
+    DEFINES += _CRT_SECURE_NO_DEPRECATE=1
+    DEFINES += _CRT_NONSTDC_NO_DEPRECATE=1
+    DEFINES += __STDC_WANT_SECURE_LIB__=0
+    DEFINES += _SECURE_ATL=0
+
+    # Bugs in Qt's .h and mkspecs/qmake.conf :
+    QMAKE_CXXFLAGS_WARN_ON = -W3
+
+    # Links flags :
+    # Add checksum, and machine code X86.
+    QMAKE_LFLAGS += /machine:x86
+    release {
+        QMAKE_LFLAGS *= /RELEASE
+        QMAKE_LFLAGS -= /DEBUG /NOLOGO
+    }
+    QMAKE_LFLAGS -= /NOLOGO
+}
+
+win32-borland {
+    message( Compile using Borland C++ compiler )
+    DEFINES *= BORLAND=1
+    # Force C++, Pentium Pro code, with RTTI
+    QMAKE_CXXFLAGS -= -RT
+    QMAKE_CXXFLAGS *= -P -6
+    QMAKE_CXXFLAGS_DEBUG *= -v
+    # Shutup warnings:
+    CONFIG *= warn_off
+}
+
+win32-icc {
+       message( Compile using Intel C++ Compiler ICC )
+       DEFINES *= WIN32_ICC=1
+       QMAKE_CFLAGS = -nologo -Zm200 -W3 -MD -Od -Ob1 -arch:SSE2 -Qms2 -GA -EHsc -Zc:forScope -Qunroll500 -fast -Qprec -Qip -Qipo -Qparallel -Qopenmp -Ot -Oy -QaxKNBP -G7 -GX -GX -GR
+       QMAKE_CXXFLAGS *= $$QMAKE_CFLAGS
+
+       QMAKE_LFLAGS = /libpath:"C:/Intel/CPP/Compiler80/Ia32/Lib" \
+       /libpath:"C:/Program Files/Fichiers communs/Intel/Shared Files/Ia32/Lib" \
+       /libpath:"C:\Program Files\Microsoft Visual Studio .NET\Vc7\lib" \
+       /libpath:"C:\Program Files\Microsoft Visual Studio .NET\Vc7\ATLMFC\LIB" \
+       /libpath:"C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\lib\prerelease" \
+       /libpath:"C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\lib" \
+       /libpath:"C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\lib" \
+       -nologo /DELAYLOAD:zlib.dll -nologo -Od -Ob1 -arch:SSE2 -Qms2 -GA -EHsc -Zc:forScope -Qunroll500 -fast -Qprec -Qip -Qipo -Qparallel -Qopenmp -Ot -Oy -QaxKNBP -G7
+}
+
+# Common part for all G++ compilers :
+*-g++* {
+    # Get more warnings on all G++ compilers.
+    QMAKE_CXXFLAGS_WARN_ON *= -Wall -W -Woverloaded-virtual -Wimplicit
+
+    # Keep some optimisations while in debug mode.
+    QMAKE_CXXFLAGS_DEBUG = -O1 -fno-omit-frame-pointer -g
+    QMAKE_LFLAGS_DEBUG += -g
+
+    # Use most agressive AND standard 'optimizing for speed' option.
+    QMAKE_CXXFLAGS_RELEASE = -O3
+}
+
+linux-g++* {
+    message( Compile using Linux platform specifics )
+    DEFINES *= LINUX=1
+    CONFIG *= linux
+
+    # On usual linux Qt distribution, only the thread-safe version of the 
+    # lib is compiled and installed...
+    CONFIG *= thread
+}
+
+irix-cc {
+    message( Compile using Irix platform specifics )
+    DEFINES *= SGI=1
+    CONFIG *= sgi
+    QMAKE_CXXFLAGS += -LANG:std -woff 1460,3284,1061
+    QMAKE_CXXFLAGS_RELEASE = -Ofast=IP35 -IPA:alias=ON -IPA:addressing=ON \
+                -IPA:aggr_cp
+                rop=ON -OPT:Olimit=0 -OPT:reorg_common=ON \
+                -OPT:rsqrt=ON -OPT:swp=ON -OPT:unroll_size=40000 \
+                -OPT:unroll_times_max=720 -LNO:auto_dist=ON -pca -apo
+    QMAKE_LFLAGS += -LANG:std
+    release: QMAKE_LFLAGS += $$QMAKE_CXXFLAGS_RELEASE
+
+    # MIPS is BigEndian
+    DEFINES += WORDS_BIGENDIAN=1
+}
+
+macx {
+    # ALSO the g++ compiler !
+    DEFINES *= MACX=1
+
+    # On universal binaries machine, let defaults work by themselfs...
+    # Adapt to PowerPC architectures :
+    # ppc {
+    #     !G5: !G4: !G3: CONFIG+=G4
+    #     G5: ARCH_PPC = -mtune=G5 -mpowerpc64 -mpowerpc-gpopt
+    #     G4: ARCH_PPC = -mtune=G4 -mpowerpc   -mpowerpc-gpopt -force_cpusubtype_ALL
+    #     G3: ARCH_PPC = -mtune=G3 -mpowerpc   -mpowerpc-gpopt -force_cpusubtype_ALL
+    #     QMAKE_CXXFLAGS += -arch ppc $$ARCH_PPC
+    #     QMAKE_CFLAGS   += -arch ppc $$ARCH_PPC
+    # }
+    # 
+    # And to x86 arch too !
+    # x86 {
+    #     ARCH_X86 = -mtune=pentiumpro -msse2 -mfpmath=sse
+    #     QMAKE_CXXFLAGS += -arch i386 $$ARCH_X86
+    #     QMAKE_CFLAGS   += -arch i386 $$ARCH_X86
+    # }
+
+    QMAKE_CXXFLAGS_RELEASE = -g -O3 -ffast-math -funroll-loops -finline -fobey-inline
+    QMAKE_CFLAGS_RELEASE   = -g -O3 -ffast-math -funroll-loops -finline -fobey-inline
+    QMAKE_CXXFLAGS_DEBUG   = -g -O1 -fno-inline
+    QMAKE_CFLAGS_DEBUG     = -g -O1 -fno-inline
+    QMAKE_LFLAGS += -g
+    
+    # PowerPC is BigEndian, x86 is not, and universal binaries means
+    # that every sources is compiled twice...
+    DEFINES *= WORDS_BIGENDIAN=__BIG_ENDIAN__
+}
+
+# Added HAVE_INT_TYPES and HAVE_UINT_TYPES in tiff.h, to avoid double-typedef 
+# of int32/uint32 etc. errors on some systems.
+#
+aix-xlc* {
+    DEFINES *= HAVE_INT_TYPES=1 HAVE_AIX=1
+}
+
+# Common to all unix platforms
+unix {
+       DEFINES *= UNIX=1
+       exists( /usr/include/string.h ): DEFINES *= HAVE_STRING_H=1
+       exists( /usr/include/unistd.h ): DEFINES *= HAVE_UNISTD_H=1
+}
+
+##############################################################################
+# Auto-detect Qt3 or Qt4 support mode...
+
+isEmpty(QTDIR) : QTDIR=$$(QTDIR)
+isEmpty(QTDIR) : error( QTDIR not set. Qt environement not installed correctly )
+
+# Auto-detect only if nothing said on the command line :
+!qt3: !qt4 {
+    macx {
+        exists( $$QTDIR/lib/QtCore.framework ) : CONFIG *= qt4
+        exists( /Library/Frameworks/QtCore.framework ) : CONFIG *= qt4
+    } else {
+        exists( $(QTDIR)/include/QtCore ) : CONFIG *= qt4
+    }
+
+    # Nothing detected: should be using Qt3...
+    !qt4: CONFIG *= qt3
+}
+
+qt3: qt4: error( Cannot be both Qt3 and Qt4 ! )
+
+qt4 {
+    message( Compiling for Qt4 )
+    !exists( $$QTDIR/include/Qt/qconfig.h ) : error( **** QTDIR for Qt4 does not leads to includes )
+    # Strange link error encontered on some windows variants:
+    # win32: QMAKE_LFLAGS += /NODEFAULTLIB:LIBCMT
+    # win32: QMAKE_LFLAGS += /NODEFAULTLIB:MSVCRTD
+}
+
+qt3 {
+    message( Compiling for Qt3 )
+    !exists( $$QTDIR/include/qconfig.h ) : error( **** QTDIR for Qt3 does not leads to includes )
+}
+
+# If you have several versions of Qt installed, make sure the QTDIR's one
+# is the one used by the Makefile !
+unix {
+    QMAKE_UIC=$$QTDIR/bin/uic
+    QMAKE_MOC=$$QTDIR/bin/moc
+}
index 8944c4e0be8c6b4acca1dcfc3929396b17c6d333..601eff68b33624f3a90c57738cdacc4c85b87e46 100644 (file)
@@ -5,7 +5,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>430</width>
+    <width>516</width>
     <height>352</height>
    </rect>
   </property>
@@ -79,7 +79,7 @@
       <widget class="QLineEdit" name="prefixLine" >
        <property name="sizePolicy" >
         <sizepolicy>
-         <hsizetype>1</hsizetype>
+         <hsizetype>0</hsizetype>
          <vsizetype>0</vsizetype>
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
       </widget>
      </item>
      <item>
-      <widget class="QLineEdit" name="fileLine" />
+      <widget class="QLineEdit" name="fileLine" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+      </widget>
      </item>
      <item>
       <spacer>
        </property>
        <property name="sizeHint" >
         <size>
-         <width>201</width>
+         <width>100</width>
          <height>71</height>
         </size>
        </property>
      </item>
      <item>
       <widget class="QPushButton" name="saveButton" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <property name="text" >
         <string>&amp;Save</string>
        </property>
      </item>
      <item>
       <widget class="QPushButton" name="quitButton" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <property name="text" >
         <string>&amp;Quit</string>
        </property>
index 6895675dfdf67618eba13d7db79b588fd866c33c..fcde8f83b24c22438dbefa3d11d107748ff385d4 100644 (file)
 #include <QClipboard>
 
 MainWindow::MainWindow(const string &tty)
- : QDialog(), m_commThread(tty), m_fileNum(0), m_image()
+ : QDialog(), m_commThread(tty), m_fileNum(0), m_lastSize(0), m_image()
 {
      ui.setupUi(this);
      
      imageLabel = new QLabel;
      ui.scrollArea->setWidget(imageLabel);
+     ui.scrollArea->setMinimumWidth(320);
      ui.progressBar->setValue(0);
-     ui.progressBar->setMaximum(15000);
+     ui.progressBar->hide();
      ui.saveButton->setDisabled(true);
      
      connect(ui.quitButton, SIGNAL(clicked()), this, SLOT(close()));
      connect(&m_commThread, SIGNAL(bytesReceived(int)), ui.progressBar, SLOT(setValue(int)));
+     connect(&m_commThread, SIGNAL(newImage()), this, SLOT(newImage()));
      connect(&m_commThread, SIGNAL(imageAvailable(OscImage*)), this, SLOT(processImage(OscImage*)));
      connect(ui.prefixLine, SIGNAL(textChanged(const QString&)), this, SLOT(generateFileName(const QString&)));
      connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(saveImage()));
@@ -52,9 +54,10 @@ void MainWindow::processImage( OscImage * img )
 {
         bool ret;
         ui.saveButton->setEnabled(true);
-        ui.progressBar->setMaximum(img->size());
-        ui.progressBar->setValue(img->size());
-        ui.progressBar->update();
+        m_lastSize = img->size();
+        ui.progressBar->setMaximum(m_lastSize);
+        ui.progressBar->setValue(m_lastSize);
+        ui.progressBar->hide();
         
         m_fileNum++;
         generateFileName( ui.prefixLine->text());
@@ -97,3 +100,10 @@ void MainWindow::saveImage()
         ds.writeRawData(m_image->data(), m_image->size());
         file.close();
 }
+
+void MainWindow::newImage()
+{
+     ui.progressBar->show();
+        if (m_lastSize == 0)
+                ui.progressBar->setMaximum(0);
+}
index 0d42c6f9df2d6df5ca7110df00a41f5aaaa8dffc..77a358bdbf76b48107f1211047448095c68f2c15 100644 (file)
@@ -41,6 +41,7 @@ private:
         Ui::MainWin ui;
         OscCommThread m_commThread;
         int m_fileNum;
+        int m_lastSize;
         OscImage *m_image;
         QLabel *imageLabel;
 private slots:
@@ -48,6 +49,7 @@ private slots:
         void saveImage();
         void resetFileCounter();
         void generateFileName(const QString& prefix);
+        void newImage();
 
 };
 
index e1056d24043d806fded83d8dbf588619aecdcacb..c1722de120a64036dec25e4285579bd5cb8e0b5f 100644 (file)
@@ -104,6 +104,7 @@ void OscCommThread::run()
         while (1) {
                 ret = poll(&pfd, 1, 1000/*ms*/);
                 if (ret>0) {
+                        if (m_img->size() == 0) newImage();
                         n = read(m_fd, buf, sizeof(buf)-1);
                         QByteArray ba = QByteArray::fromRawData(buf, n);
                         m_img->append(ba);
index 4ab2a1abac850726bfa5f90fd8469b038155aa14..3404d0a85cdf4b97d3301179016ac22bf7f6d30a 100644 (file)
@@ -61,8 +61,9 @@ private:
         void run();
         void processImage();
 signals:
-        void imageAvailable(OscImage *img);
+        void newImage();
         void bytesReceived(int bytes);
+        void imageAvailable(OscImage *img);
 };
 
 #endif