1 /*
2 * FFV1 encoder template
3 *
4 * Copyright (c) 2003-2016 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
25 int plane_index, int bits)
26 {
29 int x;
31 int run_count = 0;
32 int run_mode = 0;
33
38 }
39 } else {
43 }
44 }
45
46 if (
s->slice_coding_mode == 1) {
47 for (x = 0; x <
w; x++) {
48 int i;
50 for (i = bits-1; i>=0; i--) {
53 }
54 }
55 return 0;
56 }
57
58 for (x = 0; x <
w; x++) {
60
63
64 if (context < 0) {
65 context = -context;
67 }
68
69 diff =
fold(diff, bits);
70
75 } else {
77 }
78 } else {
79 if (context == 0)
80 run_mode = 1;
81
82 if (run_mode) {
83 if (diff) {
86 run_index++;
88 }
89
91 if (run_index)
92 run_index--;
93 run_count = 0;
94 run_mode = 0;
95 if (diff > 0)
96 diff--;
97 } else {
98 run_count++;
99 }
100 }
101
102 ff_dlog(
s->avctx,
"count:%d index:%d, mode:%d, x:%d pos:%d\n",
103 run_count, run_index, run_mode, x,
105
106 if (run_mode == 0)
108 }
109 }
110 if (run_mode) {
113 run_index++;
115 }
116
117 if (run_count)
119 }
121
122 return 0;
123 }
124
127 {
128 int x, y, p, i;
129 const int ring_size =
s->context_model ? 3 : 2;
131 int lbd =
s->bits_per_raw_sample <= 8;
132 int packed = !
src[1];
133 int bits =
s->bits_per_raw_sample > 0 ?
s->bits_per_raw_sample : 8;
137
139
141 (
w + 6) *
sizeof(*
RENAME(
s->sample_buffer)));
142
143 for (y = 0; y <
h; y++) {
146 sample[p][i]=
RENAME(
s->sample_buffer) + p*ring_size*(
w+6) + ((h+i-y)%
ring_size)*(
w+6) + 3;
147
148 for (x = 0; x <
w; x++) {
150 if (lbd) {
151 unsigned v = *((
const uint32_t*)(
src[0] + x*4 +
stride[0]*y));
152 b = v & 0xFF;
153 g = (v >> 8) & 0xFF;
154 r = (v >> 16) & 0xFF;
156 } else if (packed) {
157 const uint16_t *p = ((
const uint16_t*)(
src[0] + x*packed_size +
stride[0]*y));
158 r = p[0];
159 g = p[1];
160 b = p[2];
161 if (transparency)
164 g = *((
const uint16_t *)(
src[0] + x*2 +
stride[0]*y));
165 b = *((
const uint16_t *)(
src[1] + x*2 +
stride[1]*y));
166 r = *((
const uint16_t *)(
src[2] + x*2 +
stride[2]*y));
167 if (transparency)
168 a = *((
const uint16_t *)(
src[3] + x*2 +
stride[3]*y));
169 } else {
170 b = *((
const uint16_t *)(
src[0] + x*2 +
stride[0]*y));
171 g = *((
const uint16_t *)(
src[1] + x*2 +
stride[1]*y));
172 r = *((
const uint16_t *)(
src[2] + x*2 +
stride[2]*y));
173 }
174
175 if (
s->slice_coding_mode != 1) {
178 g += (b *
s->slice_rct_by_coef + r *
s->slice_rct_ry_coef) >> 2;
181 }
182
187 }
189 int ret;
190 sample[p][0][-1] = sample[p][1][0 ];
191 sample[p][1][
w] = sample[p][1][w-1];
192 if (lbd &&
s->slice_coding_mode == 0)
193 ret =
RENAME(encode_line)(
s,
w, sample[p], (p + 1) / 2, 9);
194 else
195 ret =
RENAME(encode_line)(
s,
w, sample[p], (p + 1) / 2, bits + (
s->slice_coding_mode != 1));
196 if (ret < 0)
197 return ret;
198 }
199 }
200 return 0;
201 }
202
static av_always_inline int fold(int diff, int bits)
const uint8_t ff_log2_run[41]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static av_always_inline av_flatten void put_symbol_inline(RangeCoder *c, uint8_t *state, int v, int is_signed, uint64_t rc_stat[256][2], uint64_t rc_stat2[32][2])
static int ring_size(RingBuffer *ring)
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint8_t offset[127][2]
static int put_bits_count(PutBitContext *s)
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static void put_vlc_symbol(PutBitContext *pb, VlcState *const state, int v, int bits)
GLint GLenum GLboolean GLsizei stride
uint8_t(* state)[CONTEXT_SIZE]
static av_always_inline int diff(const uint32_t a, const uint32_t b)