Parcourir la source

Depot initial

Rémi Synave il y a 1 an
Parent
commit
fb6aeb72d7
13 fichiers modifiés avec 883 ajouts et 0 suppressions
  1. 16 0
      colorspace.pro
  2. 5 0
      compilation
  3. 53 0
      extract_colorspace
  4. BIN
      images/lena.bmp
  5. 50 0
      include/GLWidget.hpp
  6. 32 0
      include/Image.hpp
  7. 6 0
      include/Pixel.hpp
  8. 37 0
      include/Window.hpp
  9. 354 0
      src/GLWidget.cpp
  10. 129 0
      src/Image.cpp
  11. 100 0
      src/Window.cpp
  12. 88 0
      src/main.cpp
  13. 13 0
      usage

+ 16 - 0
colorspace.pro

@@ -0,0 +1,16 @@
+######################################################################
+# Automatically generated by qmake (2.01a) mar. fvr. 9 13:12:19 2010
+######################################################################
+
+DEPENDPATH += . src include
+INCLUDEPATH += . include
+LIBS += -lm
+
+QT += opengl
+
+# Input
+HEADERS += include/GLWidget.hpp include/Image.hpp include/Pixel.hpp include/Window.hpp
+SOURCES += src/main.cpp \
+           src/GLWidget.cpp \
+           src/Window.cpp \
+           src/Image.cpp

+ 5 - 0
compilation

@@ -0,0 +1,5 @@
+#!/bin/bash
+qmake colorspace.pro
+qmake
+make
+make clean

+ 53 - 0
extract_colorspace

@@ -0,0 +1,53 @@
+#!/bin/bash
+
+PROFONDEUR=8
+FICHIER_SORTIE=$1.$2
+
+taillex=`identify -format "%w" $1`
+tailley=`identify -format "%h" $1`
+
+for ((i=2 ; i<=$# ;i++ ));
+do
+	FICHIER_SORTIE=$1.${!i}
+	COLORSPACE=${!i}
+
+	echo "Extraction de l'espace "$COLORSPACE
+
+	echo "P3" > $FICHIER_SORTIE
+	echo $taillex" "$tailley >> $FICHIER_SORTIE
+	if [[ $PROFONDEUR == 8 ]]
+	then
+	    echo "255" >> $FICHIER_SORTIE
+	fi
+	if [[ $PROFONDEUR == 16 ]]
+	then
+	    echo "65535" >> $FICHIER_SORTIE
+	fi
+
+
+	# convert $1 -depth $PROFONDEUR -colorspace $COLORSPACE +matte txt:- | cut -d " " -f 1,6 | tr -cs '0-9\n'  ' '| while read x y r g b; 
+	# do
+	#     #echo "$x $y $r $g $b" >> $FICHIER_SORTIE
+	#     echo "$r $g $b" >> $FICHIER_SORTIE
+	# done
+
+
+	indice=0
+	convert $1 -depth $PROFONDEUR -colorspace $COLORSPACE txt:- | cut -d " " -f 4 | while read hexa; 
+	do
+	    if (( "$indice" != "0" ))
+	    then
+		#echo "$x $y $r $g $b" >> $FICHIER_SORTIE
+		v1=${hexa:1:2}
+		v2=${hexa:3:2}
+		v3=${hexa:5:2}
+		let v1Dec="16#$v1+0"
+		let v2Dec="16#$v2+0"
+		let v3Dec="16#$v3+0"
+		
+		#echo $hexa" - ("$v1","$v2","$v3") - ("$v1Dec","$v2Dec","$v3Dec")"
+		echo $v1Dec" "$v2Dec" "$v3Dec >> $FICHIER_SORTIE
+	    fi
+	    indice=1
+	done
+done

BIN
images/lena.bmp


+ 50 - 0
include/GLWidget.hpp

@@ -0,0 +1,50 @@
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+#include <QListWidget>
+#include "Image.hpp"
+
+class GLWidget : public QGLWidget
+{
+  Q_OBJECT
+
+public:
+  GLWidget(Image *tabim[]=NULL, QWidget *parent = 0);
+  ~GLWidget();
+  
+  QSize minimumSizeHint() const;
+  QSize sizeHint() const;
+			
+public slots:
+  void modif_canal1(int row);
+  void modif_canal2(int row);
+  void modif_canal3(int row);
+  void sauver_image(const QString& str, int resolution);
+  void passage_2D_3D();
+  
+protected:
+  void initializeGL();
+  void paintGL();
+  void resizeGL(int width, int height);
+  void mousePressEvent(QMouseEvent *event);
+  void mouseReleaseEvent(QMouseEvent *event);
+  void mouseMoveEvent(QMouseEvent *event);
+  void wheelEvent(QWheelEvent * event);
+  void recompose();
+  
+private :
+  void maj_pt_vue();
+  Image **im;
+  Image *composition;
+  int canal1_row;
+  int canal2_row;
+  int canal3_row;
+  double zoom;
+  int transX,transY,rotX,rotY;
+  int lastposx,lastposy;
+  bool translation,rotation;
+  bool mode2D;
+};
+
+#endif

+ 32 - 0
include/Image.hpp

@@ -0,0 +1,32 @@
+#ifndef IMAGE_H
+#define IMAGE_H
+
+#include <assert.h>
+#include <iostream>
+#include <fstream>
+#include <cstring>
+#include <stdlib.h>
+#include "Pixel.hpp"
+
+using namespace std;
+
+class Image{
+
+public :
+  int taillex,tailley;
+  Pixel *pix;
+  
+public :
+  Image();
+  Image(string chemin);
+  Image(int tx, int ty, int *canal1, int *canal2, int *canal3);
+  Image(Image im1, int num_canal1, Image im2, int num_canal2, Image im3, int num_canal3);
+  //Image(const Image &im);
+  ~Image();
+
+  int* extraire_canal(int num_canal);
+  void sauver_image_fichier_ppm(const char *chemin);
+  void affiche();
+};
+  
+#endif

+ 6 - 0
include/Pixel.hpp

@@ -0,0 +1,6 @@
+#ifndef PIXEL_H
+#define PIXEL_H
+
+typedef int Pixel[3];
+
+#endif

+ 37 - 0
include/Window.hpp

@@ -0,0 +1,37 @@
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include <QListWidget>
+#include <QPushButton>
+#include <QtWidgets/QVBoxLayout>
+#include <QtWidgets/QFileDialog>
+#include "Image.hpp"
+
+class QListWidget;
+class GLWidget;
+
+class Window : public QWidget
+{
+  Q_OBJECT
+  
+  public:
+  Window(char* nom_image, char* colorspace[], Image *tabim[], int nb_colorspace);
+
+public slots:
+  void clic_sauver();
+
+signals:
+  void sauver_image(const QString& str, int resolution);
+  void passage_2D_3D();
+
+private:
+  GLWidget *glWidget;
+  QListWidget *canal1;
+  QListWidget *canal2;
+  QListWidget *canal3;
+  QPushButton *sauver;
+  QPushButton *passage_2D_3Db;
+};
+
+#endif

+ 354 - 0
src/GLWidget.cpp

@@ -0,0 +1,354 @@
+#include <QtGui>
+#include <QtOpenGL>
+#include <cstring>
+
+#include <math.h>
+#include <iostream>
+
+#include "GLWidget.hpp"
+
+GLWidget::GLWidget(Image *tabim[], QWidget *parent)
+  : QGLWidget(parent)
+{
+  im=tabim;
+  canal1_row=0;
+  canal2_row=0;
+  canal3_row=0;
+  zoom=1;
+  transX=0;
+  transY=0;
+  rotX=0;
+  rotY=0;
+  translation=false;
+  rotation=false;
+  mode2D=true;
+  recompose();
+}
+
+GLWidget::~GLWidget()
+{
+} 
+
+void GLWidget::maj_pt_vue()
+{
+  if(mode2D)
+    glViewport (transX, transY, composition->taillex*zoom, composition->tailley*zoom); 
+  else
+    glViewport (0, 0, composition->taillex, composition->tailley);
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  if(mode2D)
+    glOrtho(0,composition->taillex,0,composition->tailley,-10,10);
+  else
+    {
+      if(composition->taillex==composition->tailley)
+	glOrtho(-125,375,-125,375,-40000,40000);
+      else
+	{
+	  int min,max;
+	  if(composition->taillex>composition->tailley)
+	    {
+	      min=-125-(500-500*((composition->taillex*1.0)/(composition->tailley*1.0))/2);
+	      max=375+(500-500*((composition->taillex*1.0)/(composition->tailley*1.0))/2);
+	      glOrtho(min,max,-125,375,-40000,40000);
+	    }
+	  else
+	    {
+	      min=-125-(500-500*((composition->tailley*1.0)/(composition->taillex*1.0))/2);
+	      max=375+(500-500*((composition->tailley*1.0)/(composition->taillex*1.0))/2);
+	      glOrtho(-125,375,min,max,-40000,40000);
+	    }
+	}
+    }
+  glMatrixMode(GL_MODELVIEW);
+}
+
+QSize GLWidget::minimumSizeHint() const
+{
+  return QSize(im[0]->taillex, im[0]->tailley);
+}
+
+QSize GLWidget::sizeHint() const
+{
+  return QSize(im[0]->taillex, im[0]->tailley);
+}
+
+void GLWidget::modif_canal1(int row)
+{
+  canal1_row=row;
+  recompose();
+  updateGL();
+}
+
+void GLWidget::modif_canal2(int row)
+{
+  canal2_row=row;
+  recompose();
+  updateGL();
+}
+
+void GLWidget::modif_canal3(int row)
+{
+  canal3_row=row;
+  recompose();
+  updateGL();
+}
+
+void GLWidget::sauver_image(const QString& str, int resolution)
+{
+  string nom_fichier(QString(str).toStdString().data());
+  if(nom_fichier.size()<4)
+    nom_fichier.append(".png");
+  if(nom_fichier[nom_fichier.size()-4]!='.')
+    nom_fichier.append(".png");
+  string extension=nom_fichier.substr(nom_fichier.size()-3,3);
+  for(int i=0;i<3;i++)
+    if(extension[i]<='z' && extension[i]>='a')
+      extension[i]=extension[i]-32;
+  if(string(extension).compare("PNG"))
+    nom_fichier.append(".png");
+
+  if(mode2D)
+    resolution=1;
+
+  QImage qim[resolution][resolution];
+  for(int i=0;i<resolution;i++)
+    for(int j=0;j<resolution;j++)
+      {
+	glViewport(-im[0]->taillex*i, -im[0]->tailley*j, im[0]->taillex*resolution, im[0]->tailley*resolution);
+	updateGL();
+	qim[i][j] = grabFrameBuffer();
+      }
+  
+  QImage tosave(im[0]->taillex*resolution,im[0]->tailley*resolution,qim[0][0].format());
+  
+  for(int i=0;i<im[0]->taillex*resolution;i++)
+    for(int j=0;j<im[0]->tailley*resolution;j++)
+      tosave.setPixel(i, j, qim[i/im[0]->taillex][resolution-j/im[0]->tailley-1].pixel(i-((i/im[0]->taillex)*im[0]->taillex),j-((j/im[0]->tailley)*im[0]->tailley)));
+  
+  
+  tosave.save(QString(nom_fichier.c_str()),"PNG");
+  
+  glViewport(0, 0, im[0]->taillex, im[0]->tailley);
+  updateGL();
+}
+
+void GLWidget::passage_2D_3D()
+{
+  mode2D=!mode2D;
+  transX=0;
+  transY=0;
+  zoom=1;
+  maj_pt_vue();
+  
+  updateGL();
+}
+
+void GLWidget::initializeGL()
+{
+  qglClearColor(QColor::fromRgb(255,255,255));
+  glClearDepth(1.0f);
+  glEnable(GL_DEPTH_TEST);
+  glDepthFunc(GL_LEQUAL);
+  glDisable(GL_CULL_FACE);
+}
+
+void GLWidget::paintGL()
+{ 
+  glClearColor(255.0,255.0,255.0,0.0);
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+  glLoadIdentity();
+  if(!mode2D)
+    {
+      glScalef(zoom,zoom,zoom);
+
+      glTranslatef(transX,transY,0);
+
+      glTranslatef(128,128,128);
+
+      glRotatef(rotY/2.0,1.0,0.0,0.0);
+      glRotatef(rotX/2.0,0.0,1.0,0.0);
+
+      glTranslatef(-128,-128,-128);
+    }
+  else
+    glPointSize(zoom);
+
+  if(mode2D)
+    {
+      for(int j=0;j<composition->tailley;j++)
+	for(int i=0;i<composition->taillex;i++)
+	  {
+	    glColor4f(((composition->pix[j*composition->taillex+i][0])*1.0)/255.0,
+		      ((composition->pix[j*composition->taillex+i][1])*1.0)/255.0,
+		      ((composition->pix[j*composition->taillex+i][2])*1.0)/255.0,1.0);
+	    glBegin(GL_POINTS);
+	    glVertex2i(i,composition->tailley-j);
+	    glEnd();
+	  }
+    }
+  else
+    {
+      /*Affichage du repère*/
+	  glLineWidth(2.0);
+	  glColor4f(1.0,0.0,0.0,1.0);
+	  glBegin(GL_LINES);
+	  glVertex3f(0,0,0);
+	  glVertex3f(255,0,0);
+	  glEnd();
+	  glColor4f(0.0,1.0,0.0,1.0);
+	  glBegin(GL_LINES);
+	  glVertex3f(0,0,0);
+	  glVertex3f(0,255,0);
+	  glEnd();	
+	  glColor4f(0.0,0.0,1.0,1.0);
+	  glBegin(GL_LINES);
+	  glVertex3f(0,0,0);
+	  glVertex3f(0,0,255);
+	  glEnd();
+	  glPointSize (2.0);
+
+	  for(int j=0;j<composition->tailley;j++)
+	    for(int i=0;i<composition->taillex;i++)
+	      {
+		glColor4f(((composition->pix[j*composition->taillex+i][0])*1.0)/255.0,
+			  ((composition->pix[j*composition->taillex+i][1])*1.0)/255.0,
+			  ((composition->pix[j*composition->taillex+i][2])*1.0)/255.0,1.0);
+		glBegin(GL_POINTS);
+		glVertex3f(((composition->pix[j*composition->taillex+i][0])*1.0),
+			   ((composition->pix[j*composition->taillex+i][1])*1.0),
+			   ((composition->pix[j*composition->taillex+i][2])*1.0));
+		glEnd();
+	      }
+    }
+  
+}
+
+void GLWidget::resizeGL(int width, int height)
+{
+  width=height;
+  height=width;
+  maj_pt_vue();
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+  if (event->button() & Qt::RightButton)
+    {
+	  lastposx = event->x();
+	  lastposy = event->y();
+	  translation=true;
+    }
+  if (event->button() & Qt::MidButton)
+    {
+      transX=0;
+      transY=0;
+      rotX=0;
+      rotY=0;
+      zoom=1;
+      maj_pt_vue();
+
+      updateGL();
+    }
+  if(event->button() && Qt::LeftButton && !mode2D)
+    {
+       lastposx = event->x();
+       lastposy = event->y();
+       rotation=true;
+    }
+}
+
+void GLWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+  translation=false;
+  rotation=false;
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+  if(translation)
+    {
+      double dx = 0, dy = 0;
+      
+      dx = event->x() - lastposx;
+      dy = event->y() - lastposy;
+      
+      lastposx = event->x(); 
+      lastposy = event->y(); 
+      
+      transX += dx;
+      transY -= dy;
+      
+      maj_pt_vue();
+
+      updateGL();
+    }
+  if(rotation)
+    {
+      double dx = 0, dy = 0;
+      
+      dx = event->x() - lastposx;
+      dy = event->y() - lastposy;
+      
+      lastposx = event->x(); 
+      lastposy = event->y(); 
+      
+      rotX += dx;
+      rotY += dy;
+      
+      maj_pt_vue();
+
+      updateGL();
+    }
+}
+
+void GLWidget::wheelEvent(QWheelEvent * event)
+{
+  if(event->delta()>0)
+    {
+      if(zoom<15)
+	{
+	  if(mode2D)
+	    zoom=zoom*2;
+	  else
+	    zoom*=1.1;
+	}
+    }
+  else
+    {
+      if(zoom>1.0001)
+	{
+	  if(mode2D)
+	    zoom=zoom/2;
+	  else
+	    zoom/=1.1;
+	  if(transX>composition->taillex)
+	    transX=0;
+	  if(transY>composition->tailley)
+	    transY=0;
+	  if(-transX>composition->taillex*zoom)
+	    transX=(-composition->taillex*zoom+composition->taillex);
+	  if(-transY>composition->tailley*zoom)
+	    transY=(-composition->tailley*zoom+composition->tailley);
+	}
+    }
+
+  maj_pt_vue();
+  
+  updateGL();
+}
+
+void GLWidget::recompose()
+{
+  int mod1=canal1_row%3;
+  int mod2=canal2_row%3;
+  int mod3=canal3_row%3;
+  int *can1=im[(canal1_row-mod1)/3]->extraire_canal(mod1);
+  int *can2=im[(canal2_row-mod2)/3]->extraire_canal(mod2);
+  int *can3=im[(canal3_row-mod3)/3]->extraire_canal(mod3);
+  composition = new Image(im[0]->taillex,im[0]->tailley,can1,can2,can3);
+
+  delete[] can1;
+  delete[] can2;
+  delete[] can3;
+}

+ 129 - 0
src/Image.cpp

@@ -0,0 +1,129 @@
+#include "Image.hpp"
+
+Image::Image()
+{
+  taillex=tailley=0;
+  pix=NULL;
+}
+
+Image::Image(string chemin)
+{
+  ifstream is(chemin.c_str());
+  int ret;
+  string mn;
+
+  assert(is.is_open());
+
+  is >> mn;
+  assert(!mn.compare("P3"));
+
+  is >> taillex;
+  is >> tailley;
+
+  pix=new Pixel[taillex*tailley];
+  assert(pix != NULL);
+
+  is >> ret;
+
+  for(int i=0;i<taillex*tailley;i++)
+    {
+      is >> pix[i][0];
+      is >> pix[i][1];
+      is >> pix[i][2];
+    }
+
+  is.close();
+}
+
+Image::Image(int tx, int ty, int *canal1, int *canal2, int *canal3)
+{  
+  taillex=tx;
+  tailley=ty;
+
+  pix=new Pixel[tx*ty];
+  assert(pix != NULL);
+
+  for(int i=0;i<tx*ty;i++)
+    {
+      pix[i][0]=canal1[i];
+      pix[i][1]=canal2[i];
+      pix[i][2]=canal3[i];
+    }
+}
+
+
+Image::Image(Image im1, int num_canal1, Image im2, int num_canal2, Image im3, int num_canal3)
+{
+  assert(im1.taillex==im2.taillex && im1.taillex==im3.taillex &&
+	 im1.tailley==im2.tailley && im1.tailley==im3.tailley &&
+	 im2.taillex==im3.taillex && im2.tailley==im3.tailley);
+  
+  int *can1=im1.extraire_canal(num_canal1);
+  int *can2=im2.extraire_canal(num_canal2);
+  int *can3=im3.extraire_canal(num_canal3);
+  
+  taillex=im1.taillex;
+  tailley=im1.tailley;
+  
+  pix=new Pixel[taillex*tailley];
+  assert(pix != NULL);
+  
+  for(int i=0;i<taillex*tailley;i++)
+    {
+      pix[i][0]=can1[i];
+      pix[i][1]=can2[i];
+      pix[i][2]=can3[i];
+    }
+
+  delete[] can1;
+  delete[] can2;
+  delete[] can3;
+}
+
+int* Image::extraire_canal(int num_canal)
+{
+  assert(0<=num_canal && num_canal<=2);
+  int *canal=new int[taillex*tailley];
+  assert(canal != NULL);
+  
+  for(int i=0;i<taillex*tailley;i++)
+    canal[i]=pix[i][num_canal];
+  
+  return canal;
+}
+
+
+void Image::sauver_image_fichier_ppm(const char *chemin)
+{
+  ofstream os(chemin);
+  
+  assert(os.is_open());
+  
+  os << "P3" << endl << taillex << " " << tailley << endl<< "255" << endl;
+  for(int j=0;j<tailley;j++)
+    {
+      for(int i=0;i<taillex;i++){
+	os << pix[j*taillex+i][0] << " " << pix[j*taillex+i][1] << " " << pix[j*taillex+i][2] << " ";
+	os << endl;}
+    }
+  
+  os.close();
+}
+
+
+Image::~Image()
+{
+  delete[] pix;
+}
+
+void Image::affiche()
+{
+  cout << "Taille : " << taillex << "x" << tailley << " pixels" << endl;
+  for(int j=0;j<tailley;j++)
+    {
+      for (int i=0; i<taillex; i++)
+	cout << "(" << pix[j*taillex+i][0] << "," << pix[j*taillex+i][1] << "," << pix[j*taillex+i][2] << ") ";
+      cout << endl;
+    }
+}
+

+ 100 - 0
src/Window.cpp

@@ -0,0 +1,100 @@
+#include <QtGui>
+#include <iostream>
+#include <cstring>
+
+#include "GLWidget.hpp"
+#include "Window.hpp"
+
+Window::Window(char* nom_image, char* colorspace[], Image *tabim[], int nb_colorspace)
+{
+  glWidget = new GLWidget(tabim);
+  glWidget->setFixedSize(tabim[0]->taillex,tabim[0]->tailley);
+
+  canal1 = new QListWidget;
+  canal2 = new QListWidget;
+  canal3 = new QListWidget;
+
+  connect(canal1, 
+	  SIGNAL(currentRowChanged(int)), 
+          glWidget, 
+	  SLOT(modif_canal1(int)));
+  connect(canal2, 
+	  SIGNAL(currentRowChanged(int)), 
+          glWidget, 
+	  SLOT(modif_canal2(int)));
+  connect(canal3, 
+	  SIGNAL(currentRowChanged(int)), 
+          glWidget, 
+	  SLOT(modif_canal3(int)));
+  
+  for(int i=0;i<nb_colorspace;i++)
+    {
+      QString str(colorspace[i]);
+      str.append("_c1");
+      canal1->addItem(str);
+      canal2->addItem(str);
+      canal3->addItem(str);
+      str = colorspace[i];
+      str.append("_c2");
+      canal1->addItem(str);
+      canal2->addItem(str);
+      canal3->addItem(str);
+      str = colorspace[i];
+      str.append("_c3");
+      canal1->addItem(str);
+      canal2->addItem(str);
+      canal3->addItem(str);
+    }
+  canal1->setCurrentRow(0);
+  canal2->setCurrentRow(1);
+  canal3->setCurrentRow(2);
+  canal1->adjustSize();
+  canal2->adjustSize();
+  canal3->adjustSize();
+
+  sauver=new QPushButton("Sauver l'image");
+
+  connect(sauver, 
+	  SIGNAL(released()), 
+          this, 
+	  SLOT(clic_sauver()));
+  
+  passage_2D_3Db=new QPushButton("2D/3D");
+
+  connect(passage_2D_3Db, 
+	  SIGNAL(released()), 
+	  glWidget, 
+	  SLOT(passage_2D_3D()));
+
+  QVBoxLayout *sousLayout = new QVBoxLayout;
+  sousLayout->addWidget(sauver);
+  sousLayout->addWidget(passage_2D_3Db);
+
+  QHBoxLayout *mainLayout = new QHBoxLayout;
+  mainLayout->addWidget(glWidget);
+  mainLayout->addWidget(canal1);
+  mainLayout->addWidget(canal2);
+  mainLayout->addWidget(canal3);
+  mainLayout->addLayout(sousLayout);
+  setLayout(mainLayout);
+
+  setWindowTitle(QString("Melange image : ").append(nom_image));
+
+  connect(this, 
+	  SIGNAL(sauver_image(const QString&, int)), 
+          glWidget, 
+	  SLOT(sauver_image(const QString&, int)));
+}
+
+void Window::clic_sauver()
+{
+  QString str = QFileDialog::getSaveFileName(this,
+					     "Sauver l'image sous...",
+					     "",
+					     tr("Images (*.ppm)"));
+  int max=glWidget->width();
+  if(glWidget->height()>max)
+    max = glWidget->height();
+  if(!str.isEmpty())
+    emit sauver_image(str,(1023/max)+1);
+}

+ 88 - 0
src/main.cpp

@@ -0,0 +1,88 @@
+#include <QApplication>
+#include <iostream>
+#include <stdlib.h>
+#include <cstring>
+#include "Window.hpp"
+#include "Image.hpp"
+
+const char* colorspace[20]={"CMY","CMYK","GRAY","HSB","HSL","HWB","LAB","LOG","OHTA","REC601YCBCR","REC709YCBCR","RGB","SRGB","TRANSPARENT","XYZ","YCBCR","YCC","YIQ","YPBPR","YUV"};
+
+void usage(char* nom_prog)
+{
+  cout << "usage : " << nom_prog <<" <fichier image> <colorspace1> <colorspace2> ..." << endl;
+  cout << "Les valeurs possibles des parametres <colorspace> sont les suivantes :"<< endl;
+  for(int i=0;i<20;i++)
+    cout << colorspace[i] << endl;
+}
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  if(argc<3)
+    {
+      usage(argv[0]);
+      return EXIT_FAILURE;
+    }
+  /*On verifie que le fichier passé en parametre existe bien*/
+  ifstream is_image(argv[1]);
+  if(is_image.fail())
+    {
+      cout << "fichier " << argv[1] << " introuvable" << endl;
+      return EXIT_FAILURE;
+    }
+  else
+    is_image.close();
+
+  /*TODO VERIFIER LES EPSACES DE COULEURS*/
+  for(int i=0;i<argc-2;i++)
+    {
+      for(unsigned int j=0;j<strlen(argv[i+2]);j++)
+	if(argv[i+2][j]<='z' && argv[i+2][j]>='a')
+	  argv[i+2][j]=argv[i+2][j]-32;
+      string c(argv[i+2]);
+      bool trouve=false;
+      for(int j=0;j<20;j++)
+	if(!c.compare(colorspace[j]))
+	  trouve=true;
+      if(!trouve)
+	{
+	  cout << "l'espace de couleur " << argv[i+2] << " n'est pas autorise" << endl;
+	  usage(argv[0]);
+	  return EXIT_FAILURE;
+	}
+    }
+
+  /*extraction de l'espace de couleur si nécessaire*/
+  for(int i=0;i<argc-2;i++)
+    {
+      /*test ouverture pour savoir si le fichier existe deja*/
+      //char* nom_fichier=my_strcat(my_strcat(argv[1],"."),argv[i+2]);
+      string nom_fichier(string(argv[1]).append(".").append(argv[i+2]));
+      ifstream is_colorspace(nom_fichier.c_str());
+      if(is_colorspace.fail())
+	{
+	  string command(string("./extract_colorspace ").append(argv[1]).append(" ").append(argv[i+2]));
+	  system(command.c_str());
+	  
+	}
+      else
+	is_colorspace.close();
+    }
+
+  Image *tabim[argc-2];
+  string chemin(argv[1]);
+  chemin.append(".");
+  for(int i=2;i<argc;i++)
+    {
+      string chemincomplet(chemin);
+      chemincomplet.append(argv[i]);
+      cout << "Ouverture du fichier " << chemincomplet << endl;
+      tabim[i-2]=new Image(chemincomplet);
+    }
+
+  QApplication app(argc, argv);
+  Window window(argv[1],argv+2,tabim,argc-2);
+  window.show();
+  return app.exec();
+}

+ 13 - 0
usage

@@ -0,0 +1,13 @@
+Compilation :
+- Vérifier tout d'abord que la bibliothèque QT est bien installé ainsi que le paquet de développement.
+- Vérifier que image-magick est bien installé et que la commande convert est accessible.
+- Pour compiler, lancer simplement ./compilation
+
+Description :
+Le script extract_colorspace permet de faire l'extraction des espaces de couleurs souhaités d'une image grâce à image magick. Le code source compilé fournit l'exécutable ./colorspace. Pour l'utiliser, la commande est la suivante :
+./colorspace <image> <espace1> <espace2>
+espace_n prenant comme valeur : CMY, CMYK, GRAY, HSB, HSL, HWB, LAB, LOG, OHTA, REC601YCBCR, REC709YCBCR, RGB, SRGB, TRANSPARENT, XYZ, YCBCR, YCC, YIQ, YPBPR ou YUV.
+Le programme va d'abord vérifier si les espaces de couleurs sont déjà extraits. Si ce n'est pas le cas, il va lancer cette extraction avec le script extract_colorspace. Une fois tous les espaces de couleurs extraits, le programme va les lire et vous permettre de composer une nouvelle image à partir de tous les espaces de couleurs disponibles. Un bouton enregistrer permet d'enregistrer l'image résultante à tout moment.
+
+Exemple d'exécution :
+./colorspace lena.bmp RGB CMY YUV OHTA LAB YCC HSL