29 #ifndef PT_GFX_YUV12IMAGE_H
30 #define PT_GFX_YUV12IMAGE_H
32 #include <Pt/Gfx/Api.h>
33 #include <Pt/Gfx/Color.h>
34 #include <Pt/Gfx/CompositionMode.h>
35 #include <Pt/Gfx/BasicImage.h>
50 static std::size_t imageSize(
const Size& size, Pt::ssize_t padding)
52 Pt::ssize_t stride = size.
width() + padding;
53 Pt::ssize_t planeSize = stride * size.
height();
55 return planeSize + planeSize / 2;
58 static Pt::ssize_t pixelStride()
66 Pt::uint32_t rv = 298 * (y - 16) + 409 * (v - 128) + 128;
67 Pt::uint32_t gv = 298 * (y - 16) - 100 * (u - 128) - 208 * (v - 128) + 128;
68 Pt::uint32_t bv = 298 * (y - 16) + 516 * (u - 128) + 128;
74 return Color(r, g, b);
84 Pt::int32_t yy = (( 66 * r + 129 * g + 25 * b + 128) >> 16) + 16;
85 Pt::int32_t uu = ((-38 * r - 74 * g + 112 * b + 128) >> 16) + 128;
86 Pt::int32_t vv = ((112 * r - 94 * g - 18 * b + 128) >> 16) + 128;
94 static Pt::ssize_t init(T* data, Pt::ssize_t stride,
const Size& size,
95 Pt::ssize_t xpos, Pt::ssize_t ypos,
98 Pt::ssize_t yOffset = stride * ypos + xpos;
101 return init(data, stride, size, xpos, ypos, u, v);
104 template <
typename T>
105 static Pt::ssize_t init(T* data, Pt::ssize_t stride,
const Size& size,
106 Pt::ssize_t xpos, Pt::ssize_t ypos,
109 Pt::ssize_t planeSize = stride * size.
height();
111 Pt::ssize_t subStride = stride / 2;
112 Pt::ssize_t subPlaneSize = planeSize / 4;
114 Pt::ssize_t subXPos = xpos / 2;
115 Pt::ssize_t subYPos = ypos / 2;
116 Pt::ssize_t subOffset = subStride * subYPos + subXPos;
118 Pt::ssize_t uOffset = planeSize + subOffset;
121 Pt::ssize_t vOffset = uOffset + subPlaneSize;
127 template <
typename T>
128 static void advance(T*& y, T*& u, T*& v,
129 Pt::ssize_t& xpos, Pt::ssize_t& ypos,
130 T* data, Pt::ssize_t stride,
const Size& size,
131 Pt::ssize_t padding, Pt::ssize_t subStride)
135 if( ++xpos >= size.
width() )
151 else if(xpos % 2 == 0)
158 template <
typename T>
159 static void advance(T*& y, T*& u, T*& v, Pt::ssize_t n,
160 Pt::ssize_t& xpos, Pt::ssize_t& ypos,
161 T* data, Pt::ssize_t stride,
const Size& size)
163 Pt::ssize_t off = xpos + n;
164 ypos += off / size.
width();
165 xpos = off % size.
width();
167 init(data, stride, size,xpos, ypos, y, u, v);
176 ConstPixel(
const BasicView<Yuv12Model>& view, Pt::ssize_t xpos, Pt::ssize_t ypos)
185 reset(view, xpos, ypos);
192 , _subStride(p._subStride)
198 void reset(
const BasicView<Yuv12Model>& view, Pt::ssize_t xpos, Pt::ssize_t ypos)
204 _subStride = Yuv12Model::init(view.data(), view.stride(), view.size(), xpos, ypos, _y, _u, _v);
212 _subStride = p._subStride;
221 Yuv12Model::advance(_y, _u, _v, _xpos, _ypos,
222 _view->data(), _view->stride(),
223 _view->size(), _view->padding(), _subStride);
226 void advance( Pt::ssize_t n )
228 Yuv12Model::advance(_y, _u, _v, n, _xpos, _ypos,
229 _view->data(), _view->stride(),_view->size());
232 Color toColor()
const
234 return Yuv12Model::toColor(*_y, *_u, *_v);
247 {
return _y != p._y; }
250 {
return _y == p._y; }
256 const BasicView<Yuv12Model>* _view;
259 Pt::ssize_t _subStride;
270 Pixel(BasicView<Yuv12Model>& view, Pt::ssize_t xpos, Pt::ssize_t ypos)
279 _subStride = Yuv12Model::init(view.data(), view.stride(), view.size(), xpos, ypos, _y, _u, _v);
286 , _subStride(p._subStride)
294 assign(p, CompositionMode::SourceCopy);
300 assign(p, CompositionMode::SourceCopy);
304 Pixel& operator=(
const Color& color)
306 assign(color, CompositionMode::SourceCopy);
310 void reset(BasicView<Yuv12Model>& view, Pt::ssize_t xpos, Pt::ssize_t ypos)
316 _subStride = Yuv12Model::init(view.data(), view.stride(), view.size(), xpos, ypos, _u, _v);
319 void reset(
const Pixel& p)
324 _subStride = p._subStride;
333 Yuv12Model::advance(_y, _u, _v, _xpos, _ypos,
334 _view->data(), _view->stride(),
335 _view->size(), _view->padding(), _subStride);
338 void advance( Pt::ssize_t n )
340 Yuv12Model::advance(_y, _u, _v, n, _xpos, _ypos,
341 _view->data(), _view->stride(),_view->size());
344 void assign(
const Color& color, CompositionMode)
346 Yuv12Model::fromColor(*_y, *_u, *_v, color);
349 void assign(
const Pixel& p, CompositionMode)
356 void assign(
const ConstPixel& p, CompositionMode)
363 Color toColor()
const
365 return Yuv12Model::toColor(*_y, *_u, *_v);
386 bool operator!=(
const Pixel& p)
const
387 {
return _y != p._y; }
389 bool operator==(
const Pixel& p)
const
390 {
return _y == p._y; }
393 BasicView<Yuv12Model>* _view;
396 Pt::ssize_t _subStride;
414 : BasicImage(size, padding)
420 : BasicImage(data, size, padding)
uint_type uint16_t
Unsigned 16-bit integer type.
Definition: Types.h:30
T width() const
Returns the width.
Definition: Size.h:65
YV-12 image.
Definition: Yuv12Image.h:408
int_type int32_t
Signed 32-bit integer type.
Definition: Types.h:36
Yuv12Image(const Size &size, size_t padding=0)
Constructor.
Definition: Yuv12Image.h:413
YV-12 image model.
Definition: Yuv12Image.h:44
Const pixel in a YV-12 Image.
Definition: Yuv12Image.h:173
T height() const
Returns the height.
Definition: Size.h:69
Yuv12Image(Pt::uint8_t *data, const Size &size, size_t padding=0)
Construct from external buffer.
Definition: Yuv12Image.h:419
uint_type uint32_t
Unsigned 32-bit integer type.
Definition: Types.h:42
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
Pixel in a YV-12 Image.
Definition: Yuv12Image.h:267