2
// C++ Interface: %{MODULE}
7
// Author: %{AUTHOR} <%{EMAIL}>, (C) %{YEAR}
9
// Copyright: See COPYING file that comes with this distribution
12
// This is the base time for image exchanged between codec/filters/...
14
// We (optionnally) can carry extra informations
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)
25
#include "../ADM_assert.h"
26
#include "../ADM_colorspace/ADM_rgb.h"
34
// Avisynth compatibility layer
36
//#define vi.num_frames _info.nb_frames
37
//#define vi.IsYV12() 1
38
#define GetReadPtr GetWritePtr
39
#define GetRowSize GetPitch
60
uint32_t demuxerFrameno;
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)
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
79
// End of section dedicated to codec/editor transfer
81
void commonInit(uint32_t w,uint32_t h); /// sub constructor
83
uint32_t GetPitch(ADM_PLANE plane)
87
case PLANAR_Y:return _width;break;
89
case PLANAR_V:return _width>>1;break;
90
default: ADM_assert(0);
93
uint8_t *GetWritePtr(ADM_PLANE plane)
95
uint32_t plan=_width*_height;
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);
105
uint32_t GetHeight(ADM_PLANE plane)
109
case PLANAR_Y:return _height;break;
111
case PLANAR_V:return _height>>1;break;
112
default: ADM_assert(0);
115
uint8_t duplicateMacro(ADMImage *src,uint32_t swap); /// copy an image to ourself, including info
118
uint8_t *_planes[3]; /// In case of linked data store y/u/v pointers
119
uint32_t _planeStride[3]; /// Same story
121
ADMImage(uint32_t width, uint32_t height);
122
ADMImage(uint32_t width, uint32_t height,uint32_t dummy); /// To create linked datas image
124
uint8_t LumaReduceBy2(void);
126
uint8_t getWidthHeight(uint32_t *w,uint32_t *h)
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);
152
static uint32_t lumaDiff(ADMImage *src1,ADMImage *src2,uint32_t noise);
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))
160
// Simple image resizer
162
class ADMImageResizer
166
uint32_t orgFormat, destFormat;
167
uint32_t orgWidth, orgHeight;
168
uint32_t destWidth, destHeight;
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);
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);
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);
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);
187
ADMImage *createImageFromFile(const char *filename);
188
ADM_IMAGE_TYPE ADM_identidyImageFile(const char *filename,uint32_t *w,uint32_t *h);