Logo Search packages:      
Sourcecode: zapping version File versions  Download package

image_format.h

/*
 *  libzvbi - Image definitions
 *
 *  Copyright (C) 2003, 2004 Michael H. Schimek
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $Id: image_format.h,v 1.4 2005/06/28 01:00:12 mschimek Exp $ */

#ifndef __ZVBI3_IMAGE_FORMAT_H__
#define __ZVBI3_IMAGE_FORMAT_H__

#include <inttypes.h>         /* uint64_t */
#include "macros.h"

VBI3_BEGIN_DECLS

/**
 * @addtogroup Types
 * @{
 */

/** Pixel format identifier. */
00036 typedef enum {
00037       VBI3_PIXFMT_NONE,             /**< */
00038       VBI3_PIXFMT_UNKNOWN = VBI3_PIXFMT_NONE,   /**< */

      VBI3_PIXFMT_RESERVED0,

      /**
       * Planar YUV formats. Letters XYZ describe the contents of the
       * first to last plane in memory. Numbers follow standard naming
       * conventions, e. g. YUV422 means YUV 4:2:2.
       *
       * Relative plane sizes of VBI3_PIXFMT_YUV444: 4x4 4x4 4x4
       */
00049       VBI3_PIXFMT_YUV444,
00050       VBI3_PIXFMT_YVU444,     /**< 4x4 4x4 4x4 */
00051       VBI3_PIXFMT_YUV422,     /**< 4x4 2x4 2x4 */
00052       VBI3_PIXFMT_YVU422,     /**< 4x4 2x4 2x4 */
00053       VBI3_PIXFMT_YUV411,     /**< 4x4 1x4 1x4 */
00054       VBI3_PIXFMT_YVU411,     /**< 4x4 1x4 1x4 */
00055       VBI3_PIXFMT_YUV420,     /**< 4x4 2x2 2x2 */
00056       VBI3_PIXFMT_YVU420,     /**< 4x4 2x2 2x2 */
00057       VBI3_PIXFMT_YUV410,     /**< 4x4 1x1 1x1 */
00058       VBI3_PIXFMT_YVU410,     /**< 4x4 1x1 1x1 */

      /**
       * Packed YUV formats. Letters WXYZ describe register contents
       * from last to most significant bit. Numbers are the significant
       * bits without alpha bits. Appendix _LE means LSB is stored
       * first in memory, _BE means MSB.
       *
       * VBI3_PIXFMT_YUVA24_LE in register: 0xAAVVUUYY, memory: Y U V A
       */
00068       VBI3_PIXFMT_YUVA24_LE,
00069       VBI3_PIXFMT_YUVA24_BE,  /**< 0xAAVVUUYY, A V U Y */
00070       VBI3_PIXFMT_YVUA24_LE,  /**< 0xAAUUVVYY, Y V U A */
00071       VBI3_PIXFMT_YVUA24_BE,  /**< 0xAAUUVVYY, A U V Y */

00073       VBI3_PIXFMT_AVUY24_BE = VBI3_PIXFMT_YUVA24_LE,  /**< */
00074       VBI3_PIXFMT_AVUY24_LE,  /**< */
00075       VBI3_PIXFMT_AUVY24_BE,  /**< */
00076       VBI3_PIXFMT_AUVY24_LE,  /**< */

00078       VBI3_PIXFMT_YUV24_LE,   /**< 0xVVUUYY, Y U V */
00079       VBI3_PIXFMT_YUV24_BE,   /**< 0xVVUUYY, V U Y */
00080       VBI3_PIXFMT_YVU24_LE,   /**< 0xUUVVYY, Y V U */
00081       VBI3_PIXFMT_YVU24_BE,   /**< 0xUUVVYY, U V Y */

00083       VBI3_PIXFMT_VUY24_BE = VBI3_PIXFMT_YUV24_LE,    /**< */
00084       VBI3_PIXFMT_VUY24_LE,   /**< */
00085       VBI3_PIXFMT_UVY24_BE,   /**< */
00086       VBI3_PIXFMT_UVY24_LE,   /**< */

      /**
       * Packed YUV 4:2:2 formats. Letters WXYZ describe color components
       * stored at ascending memory addresses, 8 bits each.
       *
       * VBI3_PIXFMT_YUYV: Y0, (U0 + U1) / 2, Y1, (V0 + V1) / 2 in memory
       */
00094       VBI3_PIXFMT_YUYV,
00095       VBI3_PIXFMT_YVYU, /**< Y0  V Y1  U */
00096       VBI3_PIXFMT_UYVY, /**<  U Y0  V Y1 */
00097       VBI3_PIXFMT_VYUY, /**<  V Y0  U Y1 */

      VBI3_PIXFMT_RESERVED1,

      /** Y only, 8 bit per pixel. */
00102       VBI3_PIXFMT_Y8,

      VBI3_PIXFMT_RESERVED2,
      VBI3_PIXFMT_RESERVED3,

      /**
       * Packed RGB formats. Letters WXYZ describe register contents
       * from last to most significant bit. Numbers are the significant
       * bits without alpha bits. Appendix _LE means LSB is stored
       * first in memory, _BE means MSB.
       *
       * VBI3_PIXFMT_RGBA24_LE in register: 0xAABBGGRR, memory: R G B A
       */
00115       VBI3_PIXFMT_RGBA24_LE,
00116       VBI3_PIXFMT_RGBA24_BE,  /**< 0xAABBGGRR, A B G R */
00117       VBI3_PIXFMT_BGRA24_LE,  /**< 0xAARRGGBB, B G R A */
00118       VBI3_PIXFMT_BGRA24_BE,  /**< 0xAARRGGBB, A R G B */

00120       VBI3_PIXFMT_ABGR24_BE = VBI3_PIXFMT_RGBA24_LE,  /**< */
00121       VBI3_PIXFMT_ABGR24_LE,  /**< */
00122       VBI3_PIXFMT_ARGB24_BE,  /**< */
00123       VBI3_PIXFMT_ARGB24_LE,  /**< */

      VBI3_PIXFMT_RGB24_LE,   /* 0xBBGGRR, R G B */
      VBI3_PIXFMT_RGB24_BE,   /* 0xRRGGBB, B G R */

00128       VBI3_PIXFMT_BGR24_BE = VBI3_PIXFMT_RGB24_LE,    /**< */
00129       VBI3_PIXFMT_BGR24_LE,   /**< */

      /** In register: bbbbbggg gggrrrrr (msb to lsb) */
00132       VBI3_PIXFMT_RGB16_LE,
00133       VBI3_PIXFMT_RGB16_BE,   /**< */
00134       VBI3_PIXFMT_BGR16_LE,   /**< rrrrrggg gggbbbbb */
00135       VBI3_PIXFMT_BGR16_BE,   /**< */

00137       VBI3_PIXFMT_RGBA15_LE,  /**< abbbbbgg gggrrrrr */
00138       VBI3_PIXFMT_RGBA15_BE,  /**< */
00139       VBI3_PIXFMT_BGRA15_LE,  /**< arrrrrgg gggbbbbb */
00140       VBI3_PIXFMT_BGRA15_BE,  /**< */

00142       VBI3_PIXFMT_ARGB15_LE,  /**< bbbbbggg ggrrrrra */
00143       VBI3_PIXFMT_ARGB15_BE,  /**< */
00144       VBI3_PIXFMT_ABGR15_LE,  /**< rrrrrggg ggbbbbba */
00145       VBI3_PIXFMT_ABGR15_BE,  /**< */

00147       VBI3_PIXFMT_RGBA12_LE,  /**< aaaabbbb ggggrrrr */
00148       VBI3_PIXFMT_RGBA12_BE,  /**< */
00149       VBI3_PIXFMT_BGRA12_LE,  /**< aaaarrrr ggggbbbb */
00150       VBI3_PIXFMT_BGRA12_BE,  /**< */
00151       VBI3_PIXFMT_ARGB12_LE,  /**< bbbbgggg rrrraaaa */
00152       VBI3_PIXFMT_ARGB12_BE,  /**< */
00153       VBI3_PIXFMT_ABGR12_LE,  /**< rrrrgggg bbbbaaaa */
00154       VBI3_PIXFMT_ABGR12_BE,  /**< */

00156       VBI3_PIXFMT_RGB8, /**< bbgggrrr */
00157       VBI3_PIXFMT_BGR8, /**< rrrgggbb */

00159       VBI3_PIXFMT_RGBA7,      /**< abbgggrr */
00160       VBI3_PIXFMT_BGRA7,      /**< arrgggbb */
00161       VBI3_PIXFMT_ARGB7,      /**< bbgggrra */
00162       VBI3_PIXFMT_ABGR7 /**< rrgggbba */
} vbi3_pixfmt;

#define VBI3_MAX_PIXFMTS 64

/**
 * A set of pixel formats is used where more than one
 * format may apply. Use VBI3_PIXFMT_SET macros
 * to build a set.
 */
00172 typedef uint64_t vbi3_pixfmt_set;

#define VBI3_PIXFMT_SET(pixfmt) (((vbi3_pixfmt_set) 1) << (pixfmt))

#define VBI3_PIXFMT_SET_UNKNOWN 0
#define VBI3_PIXFMT_SET_EMPTY 0
#define VBI3_PIXFMT_SET_YUV_PLANAR (VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV444) |    \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU444) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV422) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU422) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV411) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU411) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV420) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU420) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV410) | \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU410))
#define VBI3_PIXFMT_SET_YUVA24      (VBI3_PIXFMT_SET (VBI3_PIXFMT_YUVA24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YUVA24_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YVUA24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YVUA24_BE))
#define VBI3_PIXFMT_SET_YUV24 (VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YUV24_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YVU24_BE))
#define VBI3_PIXFMT_SET_YUV16 (VBI3_PIXFMT_SET (VBI3_PIXFMT_YUYV) |     \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_YVYU) |     \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_UYVY) |     \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_VYUY))
#define VBI3_PIXFMT_SET_YUV_PACKED (VBI3_PIXFMT_SET_YUVA24 |            \
                           VBI3_PIXFMT_SET_YUV24 |          \
                           VBI3_PIXFMT_SET_YUV16      |           \
                           VBI3_PIXFMT_SET (VBI3_PIXFMT_Y8))
#define VBI3_PIXFMT_SET_YUV   (VBI3_PIXFMT_SET_YUV_PLANAR |       \
                         VBI3_PIXFMT_SET_YUV_PACKED)
#define VBI3_PIXFMT_SET_RGBA24      (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA24_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA24_BE))
#define VBI3_PIXFMT_SET_RGB24 (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGB24_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGR24_LE))
#define VBI3_PIXFMT_SET_RGB16 (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGB16_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_RGB16_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGR16_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGR16_BE))
#define VBI3_PIXFMT_SET_RGB15 (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA15_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA15_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA15_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA15_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ARGB15_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ARGB15_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ABGR15_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ABGR15_BE))
#define VBI3_PIXFMT_SET_RGB12 (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA12_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA12_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA12_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA12_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ARGB12_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ARGB12_BE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ABGR12_LE) | \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ABGR12_BE))
#define VBI3_PIXFMT_SET_RGB8  (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGB8) |     \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGR8))
#define VBI3_PIXFMT_SET_RGB7  (VBI3_PIXFMT_SET (VBI3_PIXFMT_RGBA7) |    \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_BGRA7) |    \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ARGB7) |    \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_ABGR7))
#define VBI3_PIXFMT_SET_RGB_PACKED (VBI3_PIXFMT_SET_RGBA24 |            \
                           VBI3_PIXFMT_SET_RGB24      |           \
                           VBI3_PIXFMT_SET_RGB16      |           \
                           VBI3_PIXFMT_SET_RGB15      |           \
                           VBI3_PIXFMT_SET_RGB12      |           \
                           VBI3_PIXFMT_SET_RGB8 |           \
                           VBI3_PIXFMT_SET_RGB7)
#define VBI3_PIXFMT_SET_RGB   (VBI3_PIXFMT_SET_RGB_PACKED)
#define VBI3_PIXFMT_SET_PLANAR      (VBI3_PIXFMT_SET_YUV_PLANAR)
#define VBI3_PIXFMT_SET_PACKED      (VBI3_PIXFMT_SET_YUV_PACKED |       \
                         VBI3_PIXFMT_SET_RGB_PACKED)
#define VBI3_PIXFMT_SET_ALL   (VBI3_PIXFMT_SET_YUV |              \
                         VBI3_PIXFMT_SET_RGB)

#define VBI3_PIXFMT_IS_YUV(pixfmt)                          \
      (0 != (VBI3_PIXFMT_SET (pixfmt) & VBI3_PIXFMT_SET_YUV))
#define VBI3_PIXFMT_IS_RGB(pixfmt)                          \
      (0 != (VBI3_PIXFMT_SET (pixfmt) & VBI3_PIXFMT_SET_RGB))
#define VBI3_PIXFMT_IS_PLANAR(pixfmt)                             \
      (0 != (VBI3_PIXFMT_SET (pixfmt) & VBI3_PIXFMT_SET_PLANAR))
#define VBI3_PIXFMT_IS_PACKED(pixfmt)                             \
      (0 != (VBI3_PIXFMT_SET (pixfmt) & VBI3_PIXFMT_SET_PACKED))

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#define _VBI3_PIXFMT_SET_4    (VBI3_PIXFMT_SET_YUVA24 |           \
                         VBI3_PIXFMT_SET_RGBA24)
#define _VBI3_PIXFMT_SET_3    (VBI3_PIXFMT_SET_YUV24 |                  \
                         VBI3_PIXFMT_SET_RGB24)
#define _VBI3_PIXFMT_SET_2    (VBI3_PIXFMT_SET_YUV16 |                  \
                         VBI3_PIXFMT_SET_RGB16 |                  \
                         VBI3_PIXFMT_SET_RGB15 |                  \
                         VBI3_PIXFMT_SET_RGB12)
#define _VBI3_PIXFMT_SET_1    (VBI3_PIXFMT_SET_YUV_PLANAR |       \
                         VBI3_PIXFMT_SET (VBI3_PIXFMT_Y8) | \
                         VBI3_PIXFMT_SET_RGB8 |             \
                         VBI3_PIXFMT_SET_RGB7)
#endif

#ifdef __GNUC__
#define vbi3_pixfmt_bytes_per_pixel(pixfmt)                       \
      (!__builtin_constant_p (pixfmt) ?                     \
       _vbi3_pixfmt_bytes_per_pixel (pixfmt) :                    \
        ((VBI3_PIXFMT_SET (pixfmt) & _VBI3_PIXFMT_SET_4) ? 4U :         \
         ((VBI3_PIXFMT_SET (pixfmt) & _VBI3_PIXFMT_SET_3) ? 3U :  \
          ((VBI3_PIXFMT_SET (pixfmt) & _VBI3_PIXFMT_SET_2) ? 2U : \
           ((VBI3_PIXFMT_SET (pixfmt) & _VBI3_PIXFMT_SET_1) ? 1U :      \
            0U)))))
#else
/**
 * @param pixfmt Pixel format.
 *
 * Returns the number of bytes per pixel used by a pixel format.
 * For planar YUV formats (which may take a fraction of bytes
 * on average) the result is 1.
 * 
 * @return
 * Number of bytes per pixel, 0 if @a pixfmt is invalid.
 */
00297 #define vbi3_pixfmt_bytes_per_pixel(pixfmt)                       \
      (_vbi3_pixfmt_bytes_per_pixel (pixfmt))
#endif

extern const char *
vbi3_pixfmt_name              (vbi3_pixfmt            pixfmt)
  __attribute__ ((const));

#ifndef DOXYGEN_SHOULD_SKIP_THIS

extern unsigned int
_vbi3_pixfmt_bytes_per_pixel  (vbi3_pixfmt            pixfmt)
  __attribute__ ((const));

#endif

/** Color space identifier. No values defined yet. */
00314 typedef enum {
00315       VBI3_COLOR_SPACE_NONE,                    /**< */
00316       VBI3_COLOR_SPACE_UNKNOWN = VBI3_COLOR_SPACE_NONE,     /**< */
} vbi3_color_space;

/** This structure describes an image buffer. */
00320 typedef struct {
      /**
       * Image width in pixels, for planar formats this refers to
       * the Y plane and must be a multiple of vbi3_pixel_format.uv_hscale.
       */
00325       unsigned int            width;

      /**
       * Image height in pixels, for planar formats this refers to
       * the Y plane and must be a multiple of tv_pixel_format.uv_vscale.
       */
00331       unsigned int            height;

      /**
       * For packed formats bytes_per_line >= (width *
       * vbi3_pixel_format.bits_per_pixel + 7) / 8. For planar formats
       * this refers to the Y plane only, with implied y_size =
       * bytes_per_line * height.
       */
00339       unsigned long           bytes_per_line;

      /** For planar formats only, refers to the U and V plane. */
00342       unsigned long           uv_bytes_per_line;

      /**
       * For packed formats the image offset in bytes from the buffer
       * start. For planar formats this refers to the Y plane.
       */
00348       unsigned long           offset;

      /**
       * For planar formats only, the byte offset of the U and V
       * plane from the start of the buffer.
       */
00354       unsigned long           u_offset;
      unsigned long           v_offset;

      /**
       * Buffer size. For packed formats size >= offset + height *
       * bytes_per_line. For planar formats size >=
       * MAX (offset + y_size, u_offset + uv_size, v_offset + uv_size).
       */
00362       unsigned long           size;

      /** Pixel format used by the buffer. */
00365       vbi3_pixfmt       pixfmt;

      /** Color space used by the buffer. */
00368       vbi3_color_space        color_space;
} vbi3_image_format;

/** @} */

VBI3_END_DECLS

#endif /* __ZVBI3_IMAGE_FORMAT_H__ */

Generated by  Doxygen 1.6.0   Back to index