summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/image/image.hh
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/image/image.hh')
-rw-r--r--2005/i/robert/src/image/image.hh114
1 files changed, 114 insertions, 0 deletions
diff --git a/2005/i/robert/src/image/image.hh b/2005/i/robert/src/image/image.hh
new file mode 100644
index 0000000..2496ef7
--- /dev/null
+++ b/2005/i/robert/src/image/image.hh
@@ -0,0 +1,114 @@
+#ifndef image_hh
+#define image_hh
+// image.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include <stdint.h>
+
+class ImageReader;
+class ImageWriter;
+
+/// Classe contenant une image. Le but est de faciliter l'échange des images
+/// entre différentes classes, et de minimiser les copies. Il y a un comptage
+/// de référence et un copy-on-write, ce qui veut dire que si l'on copie cet
+/// objet, il n'y a pas de copie des pixels tant que l'on essaye pas de la
+/// modifier.
+///
+/// La classe n'est pas thread-safe à cause du comptage de référence
+/// implémenté sans lock.
+class Image
+{
+ public:
+ enum PixelFormat { rgb, bgr, yuv422, yuv, hsi };
+ typedef uint32_t pixel_t;
+ public:
+ /// Construit une image vide.
+ Image (void);
+ /// Construit une image aux pixels non initialisée.
+ Image (int width, int length, PixelFormat pixelFormat);
+ /// Constructeur de copie, copy-on-write.
+ Image (const Image &image);
+ /// Construit une image directement à partir d'un ImageReader.
+ Image (ImageReader &reader);
+ /// Destructeur.
+ ~Image (void);
+ /// Opérateur d'affectation.
+ Image &operator= (const Image &rhs);
+ /// Récupère la taille de l'image.
+ void getSize (int &width, int &height) const;
+ /// Retourne le format des pixels.
+ PixelFormat getPixelFormat (void) const;
+ /// Retourne le nombre d'octets par pixels.
+ unsigned getBytePerPixel (void) const;
+ /// Retourne le nombre d'octets par pixels pour un format donnée.
+ static unsigned getBytePerPixel (PixelFormat pixelFormat);
+ /// Retourne la taille du tampon mémoire.
+ unsigned getBufSize (void) const;
+ /// Retourne la taille du tampon mémoire pour une image donnée.
+ static unsigned getBufSize (int width, int height, PixelFormat pixelFormat);
+ /// Récupère un pointeur vers l'image.
+ const uint8_t *getBuf (void) const;
+ /// Récupère un pointeur mutable vers l'image. Déclenche éventuellement
+ /// une copie.
+ uint8_t *getMutableBuf (void);
+ /// Lit une image.
+ void read (ImageReader &reader);
+ /// Écrit une image.
+ void write (ImageWriter &writer) const;
+ private:
+ struct Rep
+ {
+ int width_;
+ int height_;
+ PixelFormat pixelFormat_;
+ unsigned bpp_;
+ unsigned bufSize_;
+ int references_;
+ public:
+ /// Crée un Rep, avec de la place pour l'image.
+ static Rep *create (int width, int height, PixelFormat pixelFormat);
+ /// Copie un Rep, par référence (ne fait qu'incrémenter le nombre de
+ /// références).
+ Rep *copyRef (void);
+ /// Copie un Rep, vrai copie.
+ Rep *copy (void);
+ /// Libère le Rep, detruit si necessaire.
+ void release (void);
+ /// Détruit le Rep.
+ void destroy (void);
+ /// Récupère le buffer.
+ uint8_t *getBuf (void);
+ private:
+ /// Constructeur, interdit.
+ Rep (void);
+ /// Constructeur de copie, interdit.
+ Rep (const Rep &rep);
+ };
+ mutable Rep *rep_;
+};
+
+#include "image.tcc"
+
+#endif // image_hh