[opengtl-commits] [475] implement the call to the CTL interpreter

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 475
Author:   cyrille
Date:     2008-11-10 13:06:37 +0100 (Mon, 10 Nov 2008)

Log Message:
-----------
implement the call to the CTL interpreter

Modified Paths:
--------------
    trunk/GTLDesigner/src/gtldesigner.cpp
    trunk/GTLDesigner/src/gtldesignerui.rc


Modified: trunk/GTLDesigner/src/gtldesigner.cpp
===================================================================
--- trunk/GTLDesigner/src/gtldesigner.cpp	2008-11-10 12:05:53 UTC (rev 474)
+++ trunk/GTLDesigner/src/gtldesigner.cpp	2008-11-10 12:06:37 UTC (rev 475)
@@ -44,6 +44,8 @@
 #include <ktexteditor/cursor.h>
 
 #include <OpenShiva/Kernel.h>
+#include <OpenCTL/Module.h>
+#include <OpenCTL/Program.h>
 #include <GTLCore/Region.h>
 #include <GTLImageIO/ImageDCRegistry.h>
 #include <GTLImageIO/ImageDC.h>
@@ -137,7 +139,7 @@
     connect( actionExecuteRun, SIGNAL(triggered()), SLOT(executeRun()));
     actionCollection()->addAction( QLatin1String("execute_run"), actionExecuteRun );
     KAction* actionExecuteRunCTL = new KAction(i18n("Run as CTL"), this );
-    connect( actionExecuteRunCTL, SIGNAL(triggered()), SLOT(executeCtl()));
+    connect( actionExecuteRunCTL, SIGNAL(triggered()), SLOT(executeCTL()));
     actionCollection()->addAction( QLatin1String("execute_run_as_ctl"), actionExecuteRunCTL );
     KAction* actionExecuteRunShiva = new KAction(i18n("Run as Shiva"), this );
     connect( actionExecuteRunShiva, SIGNAL(triggered()), SLOT(executeShiva()));
@@ -189,7 +191,71 @@
 }
 void GTLDesigner::executeCTL()
 {
-  abort();
+  if( ui_imagesDocker->listImages->count() < 1 )
+  {
+    KMessageBox::error( this, "You need at least one image");
+    return;
+  }
+  OpenCTL::Module m("");
+  m.setSource( m_document->text().toAscii ().data() );
+  m.compile();
+  if(m.isCompiled())
+  {
+    GTLCore::String fileName =  ui_imagesDocker->listImages->item( 0 )->data( Qt::UserRole ).toString().toLatin1().data();
+    const GTLImageIO::ImageDC* decoder = GTLImageIO::ImageDCRegistry::instance()->decoder( fileName );
+    if( not decoder )
+    {
+      QMessageBox::warning(this, tr("GTLDesigner"),
+                            tr("Cannot read image %1..")
+                            .arg(fileName.c_str()));
+      return;
+    }
+    GTLCore::Region region;
+    GTLCore::AbstractImage* image = decoder->decode( fileName, &region, 0 );
+    if( not image )
+    {
+      QMessageBox::warning(this, tr("GTLDesigner"),
+                            tr("Cannot read image %1..")
+                            .arg(fileName.c_str()));
+      return;
+    }
+    OpenCTL::Program program( "apply", &m, image->pixelDescription() );
+    if( program.initialised() )
+    {
+      program.apply( *image, *image );
+      QImage res( region.width(), region.height(), QImage::Format_ARGB32);
+      for( int i = 0; i < region.width(); ++i)
+      {
+        for( int j = 0; j < region.height(); ++j)
+        {
+          quint8* px = reinterpret_cast<quint8*>(image->data(i, j ));
+          QRgb rgb;
+          switch( image->pixelDescription().channels() )
+          {
+            case 4:
+              rgb = qRgba( px[0], px[1], px[2], px[3]);
+              break;
+            case 3:
+              rgb = qRgb( px[0], px[1], px[2]);
+              break;
+            case 2:
+              rgb = qRgba( px[0], px[0], px[0], px[1]);
+              break;
+            case 1:
+              rgb = qRgb( px[0], px[0], px[0]);
+              break;
+          }
+          res.setPixel( i, j, rgb );
+        }
+      }
+      showImage( res);
+    } else {
+      KMessageBox::error( this, "Can't initialised the program, check that you have an 'apply' function");
+    }
+    delete image;
+  } else {
+    m_listView->setModel( new ErrorMessagesModel( m.compilationErrors() ) );
+  }
 }
 void GTLDesigner::executeShiva()
 {
@@ -211,7 +277,7 @@
       const GTLImageIO::ImageDC* decoder = GTLImageIO::ImageDCRegistry::instance()->decoder( fileName );
       if( not decoder )
       {
-        QMessageBox::warning(this, tr("QtShiva"),
+        QMessageBox::warning(this, tr("GTLDesigner"),
                               tr("Cannot read image %1..")
                               .arg(fileName.c_str()));
       }
@@ -219,7 +285,7 @@
       GTLCore::AbstractImage* image = decoder->decode( fileName, &region, 0 );
       if( not image )
       {
-        QMessageBox::warning(this, tr("QtShiva"),
+        QMessageBox::warning(this, tr("GTLDesigner"),
                               tr("Cannot read image %1..")
                               .arg(fileName.c_str()));
       }

Modified: trunk/GTLDesigner/src/gtldesignerui.rc
===================================================================
--- trunk/GTLDesigner/src/gtldesignerui.rc	2008-11-10 12:05:53 UTC (rev 474)
+++ trunk/GTLDesigner/src/gtldesignerui.rc	2008-11-10 12:06:37 UTC (rev 475)
@@ -1,7 +1,7 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
 <kpartgui name="gtldesigner" version="2">
 <MenuBar>
-  <Menu name="execute"><text>&amp;Exectute</text>
+  <Menu name="execute"><text>&amp;Execute</text>
     <Action name="execute_run" />
     <Action name="execute_run_as_shiva" />
     <Action name="execute_run_as_ctl" />


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/