1 /*
2  * videolib.h
3  *
4  * API for routines to convert images from one format to another.
5  *
6  * (C) 1999 Randall Hopper
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met: 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer. 2.
12  * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef __VIDEOLIB_H
31 #define __VIDEOLIB_H
32 
33 typedef unsigned long  VL_UINT32;
34 typedef          long  VL_INT32;
35 typedef unsigned short VL_UINT16;
36 typedef unsigned char  VL_UINT8;
37 typedef          char  VL_INT8;
38 typedef int            VL_BOOL;
39 
40 #define VL_FALSE 0
41 #define VL_TRUE  ( !VL_FALSE )
42 
43 
44 typedef struct {
45   VL_INT32  x,y,w,h;
46   VL_UINT32 bytes_per_line;
47 } VL_GEOM;
48 
49 typedef enum {
50   VL_PIXELTYPE_RGB,
51   VL_PIXELTYPE_YUV
52 } VL_PIXELTYPE;
53 
54 typedef enum {
55  VL_FRAME_PLANAR,                            /*  E.g. YYYYY..UUUUU...VVVVV */
56  VL_FRAME_PACKED                             /*  E.g. YVUVYVUV...          */
57 } VL_YUV_FRAME_PACKING;
58 
59 /*  FIXME  */
60 typedef enum { COLORMAP_BEST,
61                COLORMAP_PREDEF_CUBE,
62                COLORMAP_PREDEF_ARBITRARY } VL_COLORMAP_TYPE;
63 
64 typedef struct {
65   VL_UINT32 pixel;
66   VL_UINT8  r;
67   VL_UINT8  g;
68   VL_UINT8  b;
69 } VL_COLOR;
70 
71 typedef struct {
72   VL_UINT32         id;                      /*  Unique ID <internal use>   */
73   VL_COLORMAP_TYPE  type;                    /*  How the map is set up      */
74   VL_COLOR         *color;                   /*  Color lookup table         */
75   VL_UINT32         len;                     /*  How many colors            */
76   VL_UINT32         dim[3];                  /*  CUBE: colors in R,G,B      */
77   VL_UINT32         corners[2][3];           /*  CUBE: small,largest corner */
78 } VL_COLORMAP;
79 
80 typedef struct {
81   VL_PIXELTYPE           type;               /* RGB, YUV                   */
82 
83   struct {                                   /* RGB-only attributes        */
84     VL_BOOL              direct_color;       /*  T = packed RGB, F = cmap  */
85     VL_UINT32            Bpp;                /*  Bytes per pixel           */
86     VL_UINT32            mask[3];            /*  DC:  Pixel masks          */
87     VL_COLORMAP         *colormap;           /*  NDC: Colormap             */
88     unsigned             swap_bytes  :1;     /*  Bytes in shorts swapped   */
89     unsigned             swap_shorts :1;     /*  Shorts in longs swapped   */
90   } rgb;
91 
92   /* YUV-only attributes  */
93   struct {                                   /* YUV-only attributes        */
94     VL_UINT32            samp_size[3];       /*  [YUV] Bits per sample     */
95     VL_UINT32            samp_int_h[3];      /*  [YUV] Horiz samp interval */
96     VL_UINT32            samp_int_v[3];      /*  [YUV] Vert  samp interval */
97     VL_YUV_FRAME_PACKING frame_packing;      /*  Order YUV data is stored  */
98     char                 comp_order[30];     /*  "YUYV", "YVU", etc.       */
99     unsigned             order_t_to_b :1;    /*  Scanline order TtoB;BtoT  */
100     unsigned             order_l_to_r :1;    /*  Column   order RtoL;LtoR  */
101     unsigned             y_trans      :1;    /*  LSb Y = transparency?     */
102   } yuv;
103 
104 } VL_PIXEL_GEOM;
105 
106 typedef struct {
107   /*  FIXME:  Need a palette.  What about palette modes?              */
108   /*  FIXME:  Support optimimum palette per frame or passed colormap  */
109   VL_INT8       *buf;                        /*  Pixel data                */
110   VL_GEOM        geom;                       /*  Dimensional geometry      */
111   VL_PIXEL_GEOM  pix_geom;                   /*  Pixel geometry            */
112 } VL_IMAGE;
113 
114 
115 
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 
120 
121 void VIDEOLIBConvertImage( VL_IMAGE *src, VL_IMAGE *dst );
122 
123 VL_COLORMAP *VIDEOLIBNewColormap( VL_UINT32 num_colors );
124 
125 #ifdef __cplusplus
126 }  /* Close 'extern "C"' */
127 #endif
128 
129 #endif
130