2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "libavutil/avassert.h"
25 #include "libavutil/attributes.h"
26 #include "libavutil/imgutils.h"
28 #include "imgconvert.h"
30 #include "mpegvideoencdsp.h"
32 static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
33 int16_t basis[64], int scale)
38 for (i = 0; i < 8 * 8; i++) {
39 int b = rem[i] + ((basis[i] * scale +
40 (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
41 (BASIS_SHIFT - RECON_SHIFT));
44 av_assert2(-512 < b && b < 512);
46 sum += (w * b) * (w * b) >> 4;
51 static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
55 for (i = 0; i < 8 * 8; i++)
56 rem[i] += (basis[i] * scale +
57 (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
58 (BASIS_SHIFT - RECON_SHIFT);
61 static int pix_sum_c(uint8_t *pix, int line_size)
65 for (i = 0; i < 16; i++) {
66 for (j = 0; j < 16; j += 8) {
77 pix += line_size - 16;
82 static int pix_norm1_c(uint8_t *pix, int line_size)
85 uint32_t *sq = ff_square_tab + 256;
87 for (i = 0; i < 16; i++) {
88 for (j = 0; j < 16; j += 8) {
100 register uint64_t x = *(uint64_t *) pix;
102 s += sq[(x >> 8) & 0xff];
103 s += sq[(x >> 16) & 0xff];
104 s += sq[(x >> 24) & 0xff];
105 s += sq[(x >> 32) & 0xff];
106 s += sq[(x >> 40) & 0xff];
107 s += sq[(x >> 48) & 0xff];
108 s += sq[(x >> 56) & 0xff];
110 register uint32_t x = *(uint32_t *) pix;
112 s += sq[(x >> 8) & 0xff];
113 s += sq[(x >> 16) & 0xff];
114 s += sq[(x >> 24) & 0xff];
115 x = *(uint32_t *) (pix + 4);
117 s += sq[(x >> 8) & 0xff];
118 s += sq[(x >> 16) & 0xff];
119 s += sq[(x >> 24) & 0xff];
124 pix += line_size - 16;
129 /* draw the edges of width 'w' of an image of size width, height */
130 // FIXME: Check that this is OK for MPEG-4 interlaced.
131 static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
132 int w, int h, int sides)
134 uint8_t *ptr = buf, *last_line;
138 for (i = 0; i < height; i++) {
139 memset(ptr - w, ptr[0], w);
140 memset(ptr + width, ptr[width - 1], w);
144 /* top and bottom + corners */
146 last_line = buf + (height - 1) * wrap;
147 if (sides & EDGE_TOP)
148 for (i = 0; i < h; i++)
150 memcpy(buf - (i + 1) * wrap, buf, width + w + w);
151 if (sides & EDGE_BOTTOM)
152 for (i = 0; i < h; i++)
154 memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
157 av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
158 AVCodecContext *avctx)
160 c->try_8x8basis = try_8x8basis_c;
161 c->add_8x8basis = add_8x8basis_c;
163 c->shrink[0] = av_image_copy_plane;
164 c->shrink[1] = ff_shrink22;
165 c->shrink[2] = ff_shrink44;
166 c->shrink[3] = ff_shrink88;
168 c->pix_sum = pix_sum_c;
169 c->pix_norm1 = pix_norm1_c;
171 c->draw_edges = draw_edges_8_c;
174 ff_mpegvideoencdsp_init_arm(c, avctx);
176 ff_mpegvideoencdsp_init_ppc(c, avctx);
178 ff_mpegvideoencdsp_init_x86(c, avctx);