[x265] [PATCH 3 of 5] Main12: fix up sample fault on 10b -> 12b input convert
Min Chen
chenm003 at 163.com
Sat Jul 11 04:35:31 CEST 2015
# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1436581256 25200
# Node ID bd94f83f4138310c9d002ac095a964abe0f5e34d
# Parent 3dfb4e6240cd5cf22b4be17a37a4fdd4efb82246
Main12: fix up sample fault on 10b -> 12b input convert
---
source/common/picyuv.cpp | 103 +++++++++++++++++++++++++-------------------
source/common/pixel.cpp | 13 ++++++
source/common/primitives.h | 1 +
3 files changed, 73 insertions(+), 44 deletions(-)
diff -r 3dfb4e6240cd -r bd94f83f4138 source/common/picyuv.cpp
--- a/source/common/picyuv.cpp Fri Jul 10 16:25:51 2015 -0700
+++ b/source/common/picyuv.cpp Fri Jul 10 19:20:56 2015 -0700
@@ -148,52 +148,62 @@
padx++;
pady++;
- if (pic.bitDepth < X265_DEPTH)
+ X265_CHECK(pic.bitDepth >= 8, "pic.bitDepth check failure");
+
+ if (pic.bitDepth == 8)
{
- pixel *yPixel = m_picOrg[0];
- pixel *uPixel = m_picOrg[1];
- pixel *vPixel = m_picOrg[2];
+#if (X265_DEPTH > 8)
+ {
+ pixel *yPixel = m_picOrg[0];
+ pixel *uPixel = m_picOrg[1];
+ pixel *vPixel = m_picOrg[2];
- uint8_t *yChar = (uint8_t*)pic.planes[0];
- uint8_t *uChar = (uint8_t*)pic.planes[1];
- uint8_t *vChar = (uint8_t*)pic.planes[2];
- int shift = X265_MAX(0, X265_DEPTH - pic.bitDepth);
+ uint8_t *yChar = (uint8_t*)pic.planes[0];
+ uint8_t *uChar = (uint8_t*)pic.planes[1];
+ uint8_t *vChar = (uint8_t*)pic.planes[2];
+ int shift = (X265_DEPTH - 8);
- primitives.planecopy_cp(yChar, pic.stride[0] / sizeof(*yChar), yPixel, m_stride, width, height, shift);
- primitives.planecopy_cp(uChar, pic.stride[1] / sizeof(*uChar), uPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift);
- primitives.planecopy_cp(vChar, pic.stride[2] / sizeof(*vChar), vPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift);
- }
- else if (pic.bitDepth == 8)
- {
- pixel *yPixel = m_picOrg[0];
- pixel *uPixel = m_picOrg[1];
- pixel *vPixel = m_picOrg[2];
+ primitives.planecopy_cp(yChar, pic.stride[0] / sizeof(*yChar), yPixel, m_stride, width, height, shift);
+ primitives.planecopy_cp(uChar, pic.stride[1] / sizeof(*uChar), uPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift);
+ primitives.planecopy_cp(vChar, pic.stride[2] / sizeof(*vChar), vPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift);
+ }
+#else /* Case for (X265_DEPTH == 8) */
+ // TODO: Does we need this path? may merge into above in future
+ {
+ pixel *yPixel = m_picOrg[0];
+ pixel *uPixel = m_picOrg[1];
+ pixel *vPixel = m_picOrg[2];
- uint8_t *yChar = (uint8_t*)pic.planes[0];
- uint8_t *uChar = (uint8_t*)pic.planes[1];
- uint8_t *vChar = (uint8_t*)pic.planes[2];
+ uint8_t *yChar = (uint8_t*)pic.planes[0];
+ uint8_t *uChar = (uint8_t*)pic.planes[1];
+ uint8_t *vChar = (uint8_t*)pic.planes[2];
- for (int r = 0; r < height; r++)
- {
- memcpy(yPixel, yChar, width * sizeof(pixel));
+ for (int r = 0; r < height; r++)
+ {
+ memcpy(yPixel, yChar, width * sizeof(pixel));
- yPixel += m_stride;
- yChar += pic.stride[0] / sizeof(*yChar);
+ yPixel += m_stride;
+ yChar += pic.stride[0] / sizeof(*yChar);
+ }
+
+ for (int r = 0; r < height >> m_vChromaShift; r++)
+ {
+ memcpy(uPixel, uChar, (width >> m_hChromaShift) * sizeof(pixel));
+ memcpy(vPixel, vChar, (width >> m_hChromaShift) * sizeof(pixel));
+
+ uPixel += m_strideC;
+ vPixel += m_strideC;
+ uChar += pic.stride[1] / sizeof(*uChar);
+ vChar += pic.stride[2] / sizeof(*vChar);
+ }
}
-
- for (int r = 0; r < height >> m_vChromaShift; r++)
- {
- memcpy(uPixel, uChar, (width >> m_hChromaShift) * sizeof(pixel));
- memcpy(vPixel, vChar, (width >> m_hChromaShift) * sizeof(pixel));
-
- uPixel += m_strideC;
- vPixel += m_strideC;
- uChar += pic.stride[1] / sizeof(*uChar);
- vChar += pic.stride[2] / sizeof(*vChar);
- }
+#endif /* (X265_DEPTH > 8) */
}
else /* pic.bitDepth > 8 */
{
+ /* defensive programming, mask off bits that are supposed to be zero */
+ uint16_t mask = (1 << X265_DEPTH) - 1;
+ int shift = abs(pic.bitDepth - X265_DEPTH);
pixel *yPixel = m_picOrg[0];
pixel *uPixel = m_picOrg[1];
pixel *vPixel = m_picOrg[2];
@@ -202,15 +212,20 @@
uint16_t *uShort = (uint16_t*)pic.planes[1];
uint16_t *vShort = (uint16_t*)pic.planes[2];
- /* defensive programming, mask off bits that are supposed to be zero */
- uint16_t mask = (1 << X265_DEPTH) - 1;
- int shift = X265_MAX(0, pic.bitDepth - X265_DEPTH);
-
- /* shift and mask pixels to final size */
-
- primitives.planecopy_sp(yShort, pic.stride[0] / sizeof(*yShort), yPixel, m_stride, width, height, shift, mask);
- primitives.planecopy_sp(uShort, pic.stride[1] / sizeof(*uShort), uPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
- primitives.planecopy_sp(vShort, pic.stride[2] / sizeof(*vShort), vPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
+ if (pic.bitDepth > X265_DEPTH)
+ {
+ /* shift right and mask pixels to final size */
+ primitives.planecopy_sp(yShort, pic.stride[0] / sizeof(*yShort), yPixel, m_stride, width, height, shift, mask);
+ primitives.planecopy_sp(uShort, pic.stride[1] / sizeof(*uShort), uPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
+ primitives.planecopy_sp(vShort, pic.stride[2] / sizeof(*vShort), vPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
+ }
+ else /* Case for (pic.bitDepth <= X265_DEPTH) */
+ {
+ /* shift left and mask pixels to final size */
+ primitives.planecopy_sp_shl(yShort, pic.stride[0] / sizeof(*yShort), yPixel, m_stride, width, height, shift, mask);
+ primitives.planecopy_sp_shl(uShort, pic.stride[1] / sizeof(*uShort), uPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
+ primitives.planecopy_sp_shl(vShort, pic.stride[2] / sizeof(*vShort), vPixel, m_strideC, width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
+ }
}
/* extend the right edge if width was not multiple of the minimum CU size */
diff -r 3dfb4e6240cd -r bd94f83f4138 source/common/pixel.cpp
--- a/source/common/pixel.cpp Fri Jul 10 16:25:51 2015 -0700
+++ b/source/common/pixel.cpp Fri Jul 10 19:20:56 2015 -0700
@@ -945,6 +945,18 @@
}
}
+static void planecopy_sp_shl_c(const uint16_t* src, intptr_t srcStride, pixel* dst, intptr_t dstStride, int width, int height, int shift, uint16_t mask)
+{
+ for (int r = 0; r < height; r++)
+ {
+ for (int c = 0; c < width; c++)
+ dst[c] = (pixel)((src[c] << shift) & mask);
+
+ dst += dstStride;
+ src += srcStride;
+ }
+}
+
/* Estimate the total amount of influence on future quality that could be had if we
* were to improve the reference samples used to inter predict any given CU. */
static void estimateCUPropagateCost(int* dst, const uint16_t* propagateIn, const int32_t* intraCosts, const uint16_t* interCosts,
@@ -1245,6 +1257,7 @@
p.planecopy_cp = planecopy_cp_c;
p.planecopy_sp = planecopy_sp_c;
+ p.planecopy_sp_shl = planecopy_sp_shl_c;
p.propagateCost = estimateCUPropagateCost;
}
}
diff -r 3dfb4e6240cd -r bd94f83f4138 source/common/primitives.h
--- a/source/common/primitives.h Fri Jul 10 16:25:51 2015 -0700
+++ b/source/common/primitives.h Fri Jul 10 19:20:56 2015 -0700
@@ -312,6 +312,7 @@
extendCURowBorder_t extendRowBorder;
planecopy_cp_t planecopy_cp;
planecopy_sp_t planecopy_sp;
+ planecopy_sp_t planecopy_sp_shl;
weightp_sp_t weight_sp;
weightp_pp_t weight_pp;
More information about the x265-devel
mailing list