Finxing some bytesperline in QImage data, and prepared to make in MacOSX.
authorviric@llimona
Wed, 14 Nov 2007 14:57:33 +0100
changeset 214 4f8e0b41c1a5
parent 213 cdf16c93b654
child 215 d3973f7ea877
Finxing some bytesperline in QImage data, and prepared to make in MacOSX.
qjpeg/README.MacOSX
qjpeg/gui/CMakeLists.txt
qjpeg/gui/MeasureThread.cpp
qjpeg/gui/QImagePtr.h
qjpeg/gui/main.cpp
qjpeg/libimage/GrayImage.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qjpeg/README.MacOSX	Wed Nov 14 14:57:33 2007 +0100
@@ -0,0 +1,61 @@
+This is how I compiled qjpeg in MacOSX:
+
+1. Get libjpeg from IJG
+  1.1. Unpack it
+  1.2. configure it:
+      ./configure --prefix=~/usr
+  1.3. make it
+      make
+  1.4. install progs and libs
+      make install install-lib
+2. Get qt for Mac
+  2.1. Unpack it
+  2.2. Configure it:
+      (optional "yes yes |" in front of it)
+      ./configure -nomake demos -nomake examples -nomake tools -static \
+        -system-libjpeg -release  -L~/usr/lib/ -I~/usr/include -prefix ~/usr
+  2.3. Make it:
+      make
+  2.4. Install it:
+      make install
+
+3. Get netpbm
+  3.1. Unpack it
+  3.2. Make it (interactive)
+       make --keep-going
+  3.3. Package it
+       make package --keep-going pkgdir=/tmp/netpbm
+  3.3. Install it
+       make install (interactive)
+
+4. Get cmake
+  4.1. Unpack it
+  4.2. Configure it
+       ./configure --prefix ~/usr
+  4.3. Make it
+       make
+  4.4. Install it
+       make install
+  4.5. Go to the modules directory and update the paths for libjpeg
+       cd ~/usr/share/cmake-2.4/Modules
+       vi FindJPEG*
+        (Add the /Users/viric/usr/include and .../lib paths to the
+         concerned lists)
+
+5. Get qjpeg
+  4.1. Update the FindNetpbm module:
+       vi FindNetpbm*
+        (do as in the previous change with FindJPEG)
+  4.2. Create an output directory
+       mkdir out2 ; cd out2;
+  4.3. Set your environment:
+       # The next don't work well unless in PATH
+       export LIB=~/usr/lib
+       export INCLUDE=~/usr/include
+       export PATH=~/usr/bin:"$PATH":$LIB:$INCLUDE
+       export QTDIR=~/usr
+  4.4. Run cmake:
+       cmake -DBUILD_TYPE=Debug ..
+  4.5. Build the gui
+       cd gui
+       make
--- a/qjpeg/gui/CMakeLists.txt	Tue Nov 13 17:38:52 2007 +0100
+++ b/qjpeg/gui/CMakeLists.txt	Wed Nov 14 14:57:33 2007 +0100
@@ -1,5 +1,13 @@
 find_package(Qt4 REQUIRED)
 
+find_library(PLUGIN_JPEG qjpeg 
+   PATHS ${QT_PLUGINS_DIR}/imageformats
+   NO_DEFAULT_PATH)
+
+if (NOT PLUGIN_JPEG)
+   MESSAGE(FATAL_ERROR "Cannot find the QT's libjpeg plugin")
+endif (NOT PLUGIN_JPEG)
+
 include(${QT_USE_FILE})
 
 set(qtproject_SRCS
@@ -59,9 +67,21 @@
 
 #add_executable(qjpeg ${qtproject_SRCS} ${qtproject_UIS_H})
 
-add_executable(qjpeg ${qtproject_SRCS})
-
 #add_executable(testQChain ${testQChain_SRCS})
 
-target_link_libraries(qjpeg ${QT_LIBRARIES} netpbm jpeg plugins image)
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  # By this flag, we include the libqjpeg qt plugin
+  add_definitions(-DSTATIC)
+  add_executable(qjpeg MACOSX_BUNDLE ${qtproject_SRCS})
+
+  set_target_properties(qjpeg PROPERTIES
+    LINK_FLAGS "-L${QT_PLUGINS_DIR}/imageformats -liconv -framework AppKit -framework CoreData")
+  target_link_libraries(qjpeg ${QT_LIBRARIES}
+	netpbm jpeg plugins image ${PLUGIN_JPEG})
+else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  add_executable(qjpeg ${qtproject_SRCS})
+  target_link_libraries(qjpeg ${QT_LIBRARIES}
+	netpbm jpeg plugins image)
+endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+
 #target_link_libraries(testQChain ${QT_LIBRARIES} netpbm jpeg plugins image)
--- a/qjpeg/gui/MeasureThread.cpp	Tue Nov 13 17:38:52 2007 +0100
+++ b/qjpeg/gui/MeasureThread.cpp	Wed Nov 14 14:57:33 2007 +0100
@@ -133,7 +133,7 @@
     if(img->format() != QImage::Format_Indexed8 && img->isGrayscale())
         throw new Error::UnsupportedColorspace;
     const GrayImage *gray = new GrayImage((unsigned char *) img->bits(),
-            img->width(), img->height());
+            img->width(), img->height(), img->bytesPerLine());
     return gray;
 }
 
--- a/qjpeg/gui/QImagePtr.h	Tue Nov 13 17:38:52 2007 +0100
+++ b/qjpeg/gui/QImagePtr.h	Wed Nov 14 14:57:33 2007 +0100
@@ -4,9 +4,9 @@
 {
 public:
     QImagePtr ( uchar * data, int width, int height, Format format )
-        : QImage(data, width, height, format) {};
+        : QImage(data, width, height, width, format) {};
     QImagePtr ( const uchar * data, int width, int height, Format format )
-        : QImage(data, width, height, format) {};
+        : QImage(data, width, height, width, format) {};
     ~QImagePtr() {
         delete[] bits();
     };
--- a/qjpeg/gui/main.cpp	Tue Nov 13 17:38:52 2007 +0100
+++ b/qjpeg/gui/main.cpp	Wed Nov 14 14:57:33 2007 +0100
@@ -2,6 +2,10 @@
 #include <QImage>
 #include "MainWindow.h"
 
+#ifdef STATIC
+    Q_IMPORT_PLUGIN(qjpeg)
+#endif
+
 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
--- a/qjpeg/libimage/GrayImage.h	Tue Nov 13 17:38:52 2007 +0100
+++ b/qjpeg/libimage/GrayImage.h	Wed Nov 14 14:57:33 2007 +0100
@@ -3,20 +3,30 @@
     unsigned char *ptr;
     unsigned int width;
     unsigned int height;
+    unsigned int bytes_per_line;
 
 public:
-    GrayImage(const unsigned int _width, const unsigned int _height)
+    GrayImage(const unsigned int _width, const unsigned int _height,
+            const unsigned int _bytes_per_line = 0)
     {
-        ptr = new unsigned char[_width * _height];
         width = _width;
         height = _height;
+        if (_bytes_per_line)
+            bytes_per_line = _bytes_per_line;
+        else
+            bytes_per_line = _width;
+        ptr = new unsigned char[bytes_per_line * _height];
     }
 
-    GrayImage(unsigned char *p, const unsigned int _width, const unsigned int _height)
+    GrayImage(unsigned char *p, const unsigned int _width, const unsigned int _height, const unsigned int _bytes_per_line = 0)
     {
         ptr = p;
         width = _width;
         height = _height;
+        if (_bytes_per_line)
+            bytes_per_line = _bytes_per_line;
+        else
+            bytes_per_line = _width;
     }
 
     inline unsigned char *data() const
@@ -36,10 +46,10 @@
 
     inline unsigned char getPixel(const unsigned int x, const unsigned int y) const
     {
-        return ptr[y*width + x];
+        return ptr[y*bytes_per_line + x];
     } 
     inline void setPixel(const unsigned int x, const unsigned int y, unsigned char val)
     {
-         ptr[y*width + x] = val;
+         ptr[y*bytes_per_line + x] = val;
     }
 };