~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_libraries/ADM_utilities/ADM_image.h

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: %{MODULE}
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: %{AUTHOR} <%{EMAIL}>, (C) %{YEAR}
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
//      This is the base time for image exchanged between codec/filters/...
 
13
//
 
14
//      We (optionnally) can carry extra informations
 
15
//              - aspect ratio
 
16
//              - frame type
 
17
//              - quantizer for each macroblock (16x16 pixels)
 
18
//      For the latter 3 infos are used
 
19
//              quant which leads to the int8 quant array
 
20
//              qstride = stride of array. Usually width+15)/16. 0 MEANS NOT USABLE
 
21
//              qsize = size of the array (needed to be able to copy it)
 
22
//
 
23
#ifndef ADM_IMAGE
 
24
#define ADM_IMAGE
 
25
#include "../ADM_assert.h"
 
26
#include "../ADM_colorspace/ADM_rgb.h"
 
27
 
 
28
typedef enum 
 
29
{
 
30
        ADM_ASPECT_4_3=1,
 
31
        ADM_ASPECT_16_9,
 
32
        ADM_ASPECT_1_1
 
33
} ADM_ASPECT;
 
34
// Avisynth compatibility layer
 
35
 
 
36
//#define vi.num_frames _info.nb_frames
 
37
//#define vi.IsYV12()   1
 
38
#define GetReadPtr GetWritePtr
 
39
#define GetRowSize GetPitch
 
40
 
 
41
typedef enum 
 
42
{
 
43
        PLANAR_Y=1,
 
44
        PLANAR_U=2,
 
45
        PLANAR_V=3
 
46
        
 
47
} ADM_PLANE;
 
48
typedef enum 
 
49
{
 
50
                ADM_IMAGE_UNKNOWN=0,
 
51
        ADM_IMAGE_JPG=1,
 
52
        ADM_IMAGE_PNG=2,
 
53
        ADM_IMAGE_BMP=3,
 
54
        ADM_IMAGE_BMP2=4
 
55
        
 
56
} ADM_IMAGE_TYPE;
 
57
class ADMImage
 
58
{
 
59
public:
 
60
        uint32_t        demuxerFrameno;
 
61
  
 
62
        //*****************
 
63
        uint8_t         *data;          /// Pointer to actual image data
 
64
        uint32_t        _width;         /// Width of image
 
65
        uint32_t        _height;        /// Height of image
 
66
        uint32_t        _qStride;       /// Stride of Q infos, usually about width/8 <- ***if 0 means no quant usable***
 
67
        uint8_t         *quant;         /// Byte representing quantize used for this block
 
68
        uint32_t        _Qp;            /// Average quantizer for this image, Default=2
 
69
        uint32_t        _qSize;         /// Size of the *quant field
 
70
        ADM_ASPECT      _aspect;        /// Aspect ratio
 
71
        uint32_t        flags;          /// Flags for this image (AVI_KEY_FRAME/AVI_B_FRAME)
 
72
 
 
73
// This 3 fields are only used to convery container (reference to other datas)
 
74
// Between codec & editor
 
75
        uint8_t         _isRef;         /// If True means the datas are just a link to data we don't own!
 
76
        ADM_colorspace  _colorspace;    /// Colorspace we are moving, default is YV12
 
77
        uint8_t         _noPicture;     /// No picture to display
 
78
 
 
79
// End of section dedicated to codec/editor transfer
 
80
 
 
81
        void            commonInit(uint32_t w,uint32_t h); /// sub constructor
 
82
        
 
83
        uint32_t        GetPitch(ADM_PLANE plane)
 
84
                                {
 
85
                                        switch(plane)
 
86
                                        {
 
87
                                                case PLANAR_Y:return _width;break;
 
88
                                                case PLANAR_U:
 
89
                                                case PLANAR_V:return _width>>1;break;
 
90
                                                default: ADM_assert(0);
 
91
                                        }
 
92
                                };
 
93
        uint8_t         *GetWritePtr(ADM_PLANE plane)
 
94
                        {       
 
95
                                uint32_t plan=_width*_height;
 
96
                                switch(plane)
 
97
                                        {
 
98
                                                case PLANAR_Y:return data;break;
 
99
                                                case PLANAR_U:return data+plan;break;
 
100
                                                case PLANAR_V:return data+((plan*5)>>2);break;
 
101
                                                default: ADM_assert(0);
 
102
                                        }
 
103
                        };
 
104
   
 
105
        uint32_t GetHeight(ADM_PLANE plane)
 
106
                                {
 
107
                                        switch(plane)
 
108
                                        {
 
109
                                                case PLANAR_Y:return _height;break;
 
110
                                                case PLANAR_U:
 
111
                                                case PLANAR_V:return _height>>1;break;
 
112
                                                default: ADM_assert(0);
 
113
                                        }
 
114
                                };
 
115
        uint8_t duplicateMacro(ADMImage *src,uint32_t swap);       /// copy an image to ourself, including info
 
116
public:
 
117
 
 
118
        uint8_t         *_planes[3];     /// In case of linked data store y/u/v pointers
 
119
        uint32_t        _planeStride[3]; /// Same story
 
120
 
 
121
                ADMImage(uint32_t width, uint32_t height);
 
122
                ADMImage(uint32_t width, uint32_t height,uint32_t dummy); /// To create linked datas image        
 
123
 
 
124
                uint8_t   LumaReduceBy2(void);
 
125
                ~ADMImage();
 
126
        uint8_t getWidthHeight(uint32_t *w,uint32_t *h)
 
127
                    {
 
128
                          *w=_width;
 
129
                          *h=_height;
 
130
                          return 1;
 
131
                    }
 
132
        uint8_t duplicate(ADMImage *src);       /// copy an image to ourself, including info
 
133
        uint8_t duplicateSwapUV(ADMImage *src); /// copy an image to ourself, including info
 
134
        uint8_t duplicateFull(ADMImage *src);   /// copy an image to ourself, including info
 
135
        uint8_t copyInfo(ADMImage *src);        /// copy all the flags, not the data themselves
 
136
        uint8_t copyQuantInfo(ADMImage *src);   /// copy quant table if any
 
137
        uint8_t isRef(void) { return _isRef;};
 
138
        uint8_t setLinkInfos(uint8_t *y,        /// To fill in infos for linked image
 
139
                        uint8_t *u,uint8_t *v,uint32_t stridey,
 
140
                        uint32_t strideu, uint32_t stridev);
 
141
        uint8_t merge(ADMImage *src1,ADMImage *src2);
 
142
        uint8_t substract(ADMImage *src1,ADMImage *src2);
 
143
        uint8_t blacken(void);
 
144
        uint8_t copyTo(ADMImage *target, uint32_t x, uint32_t y);
 
145
        uint8_t copyToAlpha(ADMImage *target, uint32_t x, uint32_t y,uint32_t alpha);
 
146
        uint8_t pack(uint8_t invertChroma);     /// Transfer data from planes to regular packed space
 
147
        uint8_t copyLeftSideTo(ADMImage *dest);
 
148
        /* Some utilitarian functions */
 
149
        uint8_t  saveAsBmp(const char *filename);
 
150
        uint8_t  saveAsJpg(const char *filename);
 
151
        
 
152
static uint32_t lumaDiff(ADMImage *src1,ADMImage *src2,uint32_t noise);
 
153
};
 
154
void drawString(ADMImage *dst, int x, int y, const char *s) ;
 
155
#define YPLANE(x) ((x)->data)
 
156
#define UPLANE(x) ((x)->data+((x)->_width*(x)->_height))
 
157
#define VPLANE(x) ((x)->data+(5*((x)->_width*(x)->_height)>>2))
 
158
 
 
159
//
 
160
//  Simple image resizer
 
161
//
 
162
class ADMImageResizer
 
163
{
 
164
        private:
 
165
                void    *_context;
 
166
                uint32_t orgFormat, destFormat;
 
167
                uint32_t orgWidth, orgHeight;
 
168
                uint32_t destWidth, destHeight;
 
169
 
 
170
                void init(uint32_t ow, uint32_t oh, uint32_t dw, uint32_t dh, int srcFormat, int dstFormat);
 
171
                void getYuvPlanes(uint8_t *source, uint32_t width, uint32_t height, uint8_t*& yPlane, uint8_t*& uPlane, uint8_t*& vPlane);
 
172
        public:
 
173
                ADMImageResizer(uint32_t ow,uint32_t oh, uint32_t dw, uint32_t dh);
 
174
                ADMImageResizer(uint32_t ow, uint32_t oh, uint32_t dw, uint32_t dh, int srcFormat, int dstFormat);
 
175
                ~ADMImageResizer();
 
176
                
 
177
                uint8_t resize(ADMImage *src, ADMImage *dest);
 
178
                uint8_t resize(uint8_t *src, ADMImage *dest);
 
179
                uint8_t resize(ADMImage *src, uint8_t *dest);
 
180
                uint8_t resize(uint8_t *src, uint8_t *dest);
 
181
};
 
182
 
 
183
// Misc utilities
 
184
uint8_t BitBlit(uint8_t *dst, uint32_t pitchDest,uint8_t *src,uint32_t pitchSrc,uint32_t width, uint32_t height);
 
185
uint8_t BitBlitAlpha(uint8_t *dst, uint32_t pitchDst,uint8_t *src,uint32_t pitchSrc,uint32_t width, uint32_t height,uint32_t alpha);
 
186
 
 
187
ADMImage *createImageFromFile(const char *filename);
 
188
ADM_IMAGE_TYPE ADM_identidyImageFile(const char *filename,uint32_t *w,uint32_t *h);
 
189
#endif