summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-10-14 20:51:43 +0100
committerCarl Hetherington <cth@carlh.net>2012-10-14 20:51:43 +0100
commitade28a703b15af710161faa017cddf95d66c4118 (patch)
treec581d457104195a0219a0197c523981756bf9ecd /src/lib
parent129afab72bfc026b5704c41a6bfc0f4b3a2c4033 (diff)
Try to clarify the difference between line size and stride.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ab_transcoder.cc5
-rw-r--r--src/lib/dcp_video_frame.cc4
-rw-r--r--src/lib/image.cc66
-rw-r--r--src/lib/image.h12
-rw-r--r--src/lib/server.cc2
5 files changed, 61 insertions, 28 deletions
diff --git a/src/lib/ab_transcoder.cc b/src/lib/ab_transcoder.cc
index a32d82c54..54153ec76 100644
--- a/src/lib/ab_transcoder.cc
+++ b/src/lib/ab_transcoder.cc
@@ -80,14 +80,15 @@ ABTranscoder::process_video (shared_ptr<Image> yuv, int frame, shared_ptr<Subtit
for (int i = 0; i < yuv->components(); ++i) {
int const line_size = yuv->line_size()[i];
int const half_line_size = line_size / 2;
+ int const stride = yuv->stride()[i];
uint8_t* p = _image->data()[i];
uint8_t* q = yuv->data()[i];
for (int j = 0; j < yuv->lines (i); ++j) {
memcpy (p + half_line_size, q + half_line_size, half_line_size);
- p += line_size;
- q += line_size;
+ p += stride;
+ q += stride;
}
}
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc
index 3e5c4b3aa..04735269c 100644
--- a/src/lib/dcp_video_frame.cc
+++ b/src/lib/dcp_video_frame.cc
@@ -188,7 +188,7 @@ DCPVideoFrame::encode_locally ()
int jn = 0;
for (int y = 0; y < _out_size.height; ++y) {
- uint8_t* p = prepared->data()[0] + y * prepared->line_size()[0];
+ uint8_t* p = prepared->data()[0] + y * prepared->stride()[0];
for (int x = 0; x < _out_size.width; ++x) {
/* In gamma LUT (converting 8-bit input to 12-bit) */
@@ -332,7 +332,7 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
socket.write ((uint8_t *) s.str().c_str(), s.str().length() + 1, 30);
for (int i = 0; i < _input->components(); ++i) {
- socket.write (_input->data()[i], _input->line_size()[i] * _input->lines(i), 30);
+ socket.write (_input->data()[i], _input->stride()[i] * _input->lines(i), 30);
}
char buffer[32];
diff --git a/src/lib/image.cc b/src/lib/image.cc
index c8849303c..2c0338b53 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -98,9 +98,9 @@ Image::scale (Size out_size, Scaler const * scaler) const
sws_scale (
scale_context,
- data(), line_size(),
+ data(), stride(),
0, size().height,
- scaled->data (), scaled->line_size ()
+ scaled->data(), scaled->stride()
);
sws_freeContext (scale_context);
@@ -131,9 +131,9 @@ Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scal
/* Scale and convert to RGB from whatever its currently in (which may be RGB) */
sws_scale (
scale_context,
- data(), line_size(),
+ data(), stride(),
0, size().height,
- rgb->data (), rgb->line_size ()
+ rgb->data(), rgb->stride()
);
/* Put the image in the right place in a black frame if are padding; this is
@@ -151,8 +151,8 @@ Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scal
uint8_t* q = rgb->data()[0];
for (int j = 0; j < rgb->lines(0); ++j) {
memcpy (p, q, rgb->line_size()[0]);
- p += padded_rgb->line_size()[0];
- q += rgb->line_size()[0];
+ p += padded_rgb->stride()[0];
+ q += rgb->stride()[0];
}
rgb = padded_rgb;
@@ -176,8 +176,8 @@ Image::post_process (string pp) const
pp_context* context = pp_get_context (size().width, size().height, PP_FORMAT_420 | PP_CPU_CAPS_MMX2);
pp_postprocess (
- (const uint8_t **) data(), line_size(),
- out->data(), out->line_size(),
+ (const uint8_t **) data(), stride(),
+ out->data(), out->stride(),
size().width, size().height,
0, 0, mode, context, 0
);
@@ -193,13 +193,13 @@ Image::make_black ()
{
switch (_pixel_format) {
case PIX_FMT_YUV420P:
- memset (data()[0], 0, lines(0) * line_size()[0]);
- memset (data()[1], 0x80, lines(1) * line_size()[1]);
- memset (data()[2], 0x80, lines(2) * line_size()[2]);
+ memset (data()[0], 0, lines(0) * stride()[0]);
+ memset (data()[1], 0x80, lines(1) * stride()[1]);
+ memset (data()[2], 0x80, lines(2) * stride()[2]);
break;
case PIX_FMT_RGB24:
- memset (data()[0], 0, lines(0) * line_size()[0]);
+ memset (data()[0], 0, lines(0) * stride()[0]);
break;
default:
@@ -230,8 +230,8 @@ Image::alpha_blend (shared_ptr<Image> other, Position position)
}
for (int ty = start_ty, oy = start_oy; ty < size().height && oy < other->size().height; ++ty, ++oy) {
- uint8_t* tp = data()[0] + ty * line_size()[0] + position.x * 3;
- uint8_t* op = other->data()[0] + oy * other->line_size()[0];
+ uint8_t* tp = data()[0] + ty * stride()[0] + position.x * 3;
+ uint8_t* op = other->data()[0] + oy * other->stride()[0];
for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
float const alpha = float (op[3]) / 255;
tp[0] = (tp[0] * (1 - alpha)) + op[0] * alpha;
@@ -257,25 +257,28 @@ SimpleImage::SimpleImage (PixelFormat p, Size s)
_data[0] = _data[1] = _data[2] = _data[3] = 0;
_line_size = (int *) av_malloc (4);
_line_size[0] = _line_size[1] = _line_size[2] = _line_size[3] = 0;
+ _stride = (int *) av_malloc (4);
+ _stride[0] = _stride[1] = _stride[2] = _stride[3] = 0;
switch (p) {
case PIX_FMT_RGB24:
- _line_size[0] = round_up (s.width * 3, 32);
+ _line_size[0] = s.width * 3;
break;
case PIX_FMT_RGBA:
- _line_size[0] = round_up (s.width * 4, 32);
+ _line_size[0] = s.width * 4;
break;
case PIX_FMT_YUV420P:
- _line_size[0] = round_up (s.width, 32);
- _line_size[1] = round_up (s.width / 2, 32);
- _line_size[2] = round_up (s.width / 2, 32);
+ _line_size[0] = s.width;
+ _line_size[1] = s.width / 2;
+ _line_size[2] = s.width / 2;
break;
default:
assert (false);
}
-
+
for (int i = 0; i < components(); ++i) {
- _data[i] = (uint8_t *) av_malloc (_line_size[i] * lines (i));
+ _stride[i] = round_up (_line_size[i], 32);
+ _data[i] = (uint8_t *) av_malloc (_stride[i] * lines (i));
}
}
@@ -288,6 +291,7 @@ SimpleImage::~SimpleImage ()
av_free (_data);
av_free (_line_size);
+ av_free (_stride);
}
uint8_t **
@@ -302,6 +306,12 @@ SimpleImage::line_size () const
return _line_size;
}
+int *
+SimpleImage::stride () const
+{
+ return _stride;
+}
+
Size
SimpleImage::size () const
{
@@ -333,6 +343,13 @@ FilterBufferImage::line_size () const
return _buffer->linesize;
}
+int *
+FilterBufferImage::stride () const
+{
+ /* XXX? */
+ return _buffer->linesize;
+}
+
Size
FilterBufferImage::size () const
{
@@ -377,6 +394,13 @@ RGBFrameImage::line_size () const
return _frame->linesize;
}
+int *
+RGBFrameImage::stride () const
+{
+ /* XXX? */
+ return line_size ();
+}
+
Size
RGBFrameImage::size () const
{
diff --git a/src/lib/image.h b/src/lib/image.h
index ea35fa0b9..3e16d43bf 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -57,9 +57,12 @@ public:
/** @return Array of pointers to arrays of the component data */
virtual uint8_t ** data () const = 0;
- /** @return Array of sizes of each line, in pixels */
+ /** @return Array of sizes of the data in each line, in bytes (without any alignment padding bytes) */
virtual int * line_size () const = 0;
+ /** @return Array of strides for each line (including any alignment padding bytes) */
+ virtual int * stride () const = 0;
+
/** @return Size of the image, in pixels */
virtual Size size () const = 0;
@@ -91,6 +94,7 @@ public:
uint8_t ** data () const;
int * line_size () const;
+ int * stride () const;
Size size () const;
private:
@@ -108,12 +112,15 @@ public:
uint8_t ** data () const;
int * line_size () const;
+ int * stride () const;
Size size () const;
private:
Size _size; ///< size in pixels
uint8_t** _data; ///< array of pointers to components
- int* _line_size; ///< array of widths of each line, in bytes
+ int* _line_size; ///< array of sizes of the data in each line, in pixels (without any alignment padding bytes)
+ int* _stride; ///< array of strides for each line (including any alignment padding bytes)
+
};
/** @class RGBFrameImage
@@ -127,6 +134,7 @@ public:
uint8_t ** data () const;
int * line_size () const;
+ int * stride () const;
Size size () const;
AVFrame * frame () const {
return _frame;
diff --git a/src/lib/server.cc b/src/lib/server.cc
index 26b2be7c7..659418b8f 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -119,7 +119,7 @@ Server::process (shared_ptr<Socket> socket)
shared_ptr<Image> image (new SimpleImage (pixel_format, in_size));
for (int i = 0; i < image->components(); ++i) {
- socket->read_definite_and_consume (image->data()[i], image->line_size()[i] * image->lines(i), 30);
+ socket->read_definite_and_consume (image->data()[i], image->stride()[i] * image->lines(i), 30);
}
/* XXX: subtitle */