00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "mss2dsp.h"
00027 #include "libavutil/common.h"
00028
00029 static av_always_inline void mss2_blit_wmv9_template(uint8_t *dst,
00030 int dst_stride,
00031 int gray,
00032 int use_mask,
00033 int maskcolor,
00034 const uint8_t *mask,
00035 int mask_stride,
00036 const uint8_t *srcy,
00037 int srcy_stride,
00038 const uint8_t *srcu,
00039 const uint8_t *srcv,
00040 int srcuv_stride,
00041 int w, int h)
00042 {
00043 int i, j, k, r = -1;
00044 while (++r < h) {
00045 for (i = 0, j = 0, k = 0; i < w; j += (i & 1), i++, k += 3) {
00046 if (!use_mask || mask[i] == maskcolor) {
00047 if (gray) {
00048 dst[k] = dst[k + 1] = dst[k + 2] = 0x80;
00049 } else {
00050 int y = srcy[i];
00051 int u = srcu[j] - 128;
00052 int v = srcv[j] - 128;
00053 dst[k] = av_clip_uint8(y + ( 91881 * v + 32768 >> 16));
00054 dst[k + 1] = av_clip_uint8(y + (-22554 * u - 46802 * v + 32768 >> 16));
00055 dst[k + 2] = av_clip_uint8(y + (116130 * u + 32768 >> 16));
00056 }
00057 }
00058 }
00059 mask += mask_stride;
00060 dst += dst_stride;
00061 srcy += srcy_stride;
00062 srcu += srcuv_stride * (r & 1);
00063 srcv += srcuv_stride * (r & 1);
00064 }
00065 }
00066
00067 static void mss2_blit_wmv9_c(uint8_t *dst, int dst_stride,
00068 const uint8_t *srcy, int srcy_stride,
00069 const uint8_t *srcu, const uint8_t *srcv,
00070 int srcuv_stride, int w, int h)
00071 {
00072 mss2_blit_wmv9_template(dst, dst_stride, 0, 0,
00073 0, NULL, 0,
00074 srcy, srcy_stride,
00075 srcu, srcv, srcuv_stride,
00076 w, h);
00077 }
00078
00079 static void mss2_blit_wmv9_masked_c(uint8_t *dst, int dst_stride,
00080 int maskcolor, const uint8_t *mask,
00081 int mask_stride,
00082 const uint8_t *srcy, int srcy_stride,
00083 const uint8_t *srcu, const uint8_t *srcv,
00084 int srcuv_stride, int w, int h)
00085 {
00086 mss2_blit_wmv9_template(dst, dst_stride, 0, 1,
00087 maskcolor, mask, mask_stride,
00088 srcy, srcy_stride,
00089 srcu, srcv, srcuv_stride,
00090 w, h);
00091 }
00092
00093 static void mss2_gray_fill_masked_c(uint8_t *dst, int dst_stride,
00094 int maskcolor, const uint8_t *mask,
00095 int mask_stride, int w, int h)
00096 {
00097 mss2_blit_wmv9_template(dst, dst_stride, 1, 1,
00098 maskcolor, mask, mask_stride,
00099 NULL, 0,
00100 NULL, NULL, 0,
00101 w, h);
00102 }
00103
00104 static void upsample_plane_c(uint8_t *plane, int plane_stride, int w, int h)
00105 {
00106 uint8_t *src1, *src2, *dst1, *dst2, *p, a, b;
00107 int i, j;
00108
00109 w += (w & 1);
00110 h += (h & 1);
00111
00112 j = h - 1;
00113
00114 memcpy(plane + plane_stride * j,
00115 plane + plane_stride * (j >> 1),
00116 w);
00117
00118 while ((j -= 2) > 0) {
00119 dst1 = plane + plane_stride * (j + 1);
00120 dst2 = plane + plane_stride * j;
00121 src1 = plane + plane_stride * ((j + 1) >> 1);
00122 src2 = plane + plane_stride * ( j >> 1);
00123
00124 for (i = (w - 1) >> 1; i >= 0; i--) {
00125 a = src1[i];
00126 b = src2[i];
00127 dst1[i] = (3 * a + b + 2) >> 2;
00128 dst2[i] = (a + 3 * b + 2) >> 2;
00129 }
00130 }
00131
00132 for (j = h - 1; j >= 0; j--) {
00133 p = plane + plane_stride * j;
00134 i = w - 1;
00135
00136 p[i] = p[i >> 1];
00137
00138 while ((i -= 2) > 0) {
00139 a = p[ i >> 1];
00140 b = p[(i + 1) >> 1];
00141 p[i] = (3 * a + b + 1) >> 2;
00142 p[i + 1] = (a + 3 * b + 1) >> 2;
00143 }
00144 }
00145 }
00146
00147 av_cold void ff_mss2dsp_init(MSS2DSPContext* dsp)
00148 {
00149 dsp->mss2_blit_wmv9 = mss2_blit_wmv9_c;
00150 dsp->mss2_blit_wmv9_masked = mss2_blit_wmv9_masked_c;
00151 dsp->mss2_gray_fill_masked = mss2_gray_fill_masked_c;
00152 dsp->upsample_plane = upsample_plane_c;
00153 }