annotate jpeglsdec.c @ 5398:392483301260 libavcodec

Reindent two lines. Patch by: Ian Caulfield, ian caulfield & gmx at
author takis
date Tue, 24 Jul 2007 13:05:28 +0000
parents 01a165280429
children 5b3acf9fd50a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5003
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
1 /*
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
2 * JPEG-LS decoder
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
4 * Copyright (c) 2006 Konstantin Shishkov
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
5 *
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
6 * This file is part of FFmpeg.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
7 *
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
12 *
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
16 * Lesser General Public License for more details.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
17 *
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
21 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
22
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
23 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
24 * @file jpeglsdec.c
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
25 * JPEG-LS decoder.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
26 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
27
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
28 #include "avcodec.h"
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
29 #include "bitstream.h"
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
30 #include "golomb.h"
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
31 #include "mjpeg.h"
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
32 #include "mjpegdec.h"
5003
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
33 #include "jpegls.h"
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
34 #include "jpeglsdec.h"
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
35
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
36
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
37 /*
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
38 * Uncomment this to significantly speed up decoding of broken JPEG-LS
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
39 * (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
40 *
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
41 * There is no Golomb code with length >= 32 bits possible, so check and
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
42 * avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
43 * on this errors.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
44 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
45 //#define JLS_BROKEN
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
46
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
47
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
48 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
49 * Decode LSE block with initialization parameters
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
50 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
51 int ff_jpegls_decode_lse(MJpegDecodeContext *s)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
52 {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
53 int len, id;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
54
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
55 /* XXX: verify len field validity */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
56 len = get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
57 id = get_bits(&s->gb, 8);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
58
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
59 switch(id){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
60 case 1:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
61 s->maxval= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
62 s->t1= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
63 s->t2= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
64 s->t3= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
65 s->reset= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
66
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
67 // ff_jpegls_reset_coding_parameters(s, 0);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
68 //FIXME quant table?
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
69 break;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
70 case 2:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
71 case 3:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
72 av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n");
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
73 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
74 case 4:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
75 av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n");
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
76 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
77 default:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
78 av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
79 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
80 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
81 // av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
82
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
83 return 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
84 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
85
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
86 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
87 * Get context-dependent Golomb code, decode it and update context
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
88 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
89 static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
90 int k, ret;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
91
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
92 for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
93
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
94 #ifdef JLS_BROKEN
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
95 if(!show_bits_long(gb, 32))return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
96 #endif
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
97 ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
98
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
99 /* decode mapped error */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
100 if(ret & 1)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
101 ret = -((ret + 1) >> 1);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
102 else
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
103 ret >>= 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
104
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
105 /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
106 if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q]))
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
107 ret = -(ret + 1);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
108
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
109 ret= ff_jpegls_update_state_regular(state, Q, ret);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
110
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
111 return ret;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
112 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
113
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
114 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
115 * Get Golomb code, decode it and update state for run termination
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
116 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
117 static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
118 int k, ret, temp, map;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
119 int Q = 365 + RItype;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
120
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
121 temp= state->A[Q];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
122 if(RItype)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
123 temp += state->N[Q] >> 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
124
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
125 for(k = 0; (state->N[Q] << k) < temp; k++);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
126
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
127 #ifdef JLS_BROKEN
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
128 if(!show_bits_long(gb, 32))return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
129 #endif
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
130 ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
131
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
132 /* decode mapped error */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
133 map = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
134 if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q]))
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
135 map = 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
136 ret += RItype + map;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
137
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
138 if(ret & 1){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
139 ret = map - ((ret + 1) >> 1);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
140 state->B[Q]++;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
141 } else {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
142 ret = ret >> 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
143 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
144
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
145 /* update state */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
146 state->A[Q] += FFABS(ret) - RItype;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
147 ret *= state->twonear;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
148 ff_jpegls_downscale_state(state, Q);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
149
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
150 return ret;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
151 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
152
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
153 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
154 * Decode one line of image
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
155 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
156 static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
157 int i, x = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
158 int Ra, Rb, Rc, Rd;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
159 int D0, D1, D2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
160
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
161 while(x < w) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
162 int err, pred;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
163
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
164 /* compute gradients */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
165 Ra = x ? R(dst, x - stride) : R(last, x);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
166 Rb = R(last, x);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
167 Rc = x ? R(last, x - stride) : last2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
168 Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
169 D0 = Rd - Rb;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
170 D1 = Rb - Rc;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
171 D2 = Rc - Ra;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
172 /* run mode */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
173 if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
174 int r;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
175 int RItype;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
176
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
177 /* decode full runs while available */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
178 while(get_bits1(&s->gb)) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
179 int r;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
180 r = 1 << ff_log2_run[state->run_index[comp]];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
181 if(x + r * stride > w) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
182 r = (w - x) / stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
183 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
184 for(i = 0; i < r; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
185 W(dst, x, Ra);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
186 x += stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
187 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
188 /* if EOL reached, we stop decoding */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
189 if(r != (1 << ff_log2_run[state->run_index[comp]]))
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
190 return;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
191 if(state->run_index[comp] < 31)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
192 state->run_index[comp]++;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
193 if(x + stride > w)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
194 return;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
195 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
196 /* decode aborted run */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
197 r = ff_log2_run[state->run_index[comp]];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
198 if(r)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
199 r = get_bits_long(&s->gb, r);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
200 for(i = 0; i < r; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
201 W(dst, x, Ra);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
202 x += stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
203 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
204
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
205 /* decode run termination value */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
206 Rb = R(last, x);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
207 RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
208 err = ls_get_code_runterm(&s->gb, state, RItype, ff_log2_run[state->run_index[comp]]);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
209 if(state->run_index[comp])
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
210 state->run_index[comp]--;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
211
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
212 if(state->near && RItype){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
213 pred = Ra + err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
214 } else {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
215 if(Rb < Ra)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
216 pred = Rb - err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
217 else
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
218 pred = Rb + err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
219 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
220 } else { /* regular mode */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
221 int context, sign;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
222
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
223 context = ff_jpegls_quantize(state, D0) * 81 + ff_jpegls_quantize(state, D1) * 9 + ff_jpegls_quantize(state, D2);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
224 pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
225
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
226 if(context < 0){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
227 context = -context;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
228 sign = 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
229 }else{
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
230 sign = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
231 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
232
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
233 if(sign){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
234 pred = av_clip(pred - state->C[context], 0, state->maxval);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
235 err = -ls_get_code_regular(&s->gb, state, context);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
236 } else {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
237 pred = av_clip(pred + state->C[context], 0, state->maxval);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
238 err = ls_get_code_regular(&s->gb, state, context);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
239 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
240
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
241 /* we have to do something more for near-lossless coding */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
242 pred += err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
243 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
244 if(state->near){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
245 if(pred < -state->near)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
246 pred += state->range * state->twonear;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
247 else if(pred > state->maxval + state->near)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
248 pred -= state->range * state->twonear;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
249 pred = av_clip(pred, 0, state->maxval);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
250 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
251
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
252 pred &= state->maxval;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
253 W(dst, x, pred);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
254 x += stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
255 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
256 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
257
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
258 int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
259 int i, t = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
260 uint8_t *zero, *last, *cur;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
261 JLSState *state;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
262 int off = 0, stride = 1, width, shift;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
263
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
264 zero = av_mallocz(s->picture.linesize[0]);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
265 last = zero;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
266 cur = s->picture.data[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
267
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
268 state = av_mallocz(sizeof(JLSState));
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
269 /* initialize JPEG-LS state from JPEG parameters */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
270 state->near = near;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
271 state->bpp = (s->bits < 2) ? 2 : s->bits;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
272 state->maxval = s->maxval;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
273 state->T1 = s->t1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
274 state->T2 = s->t2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
275 state->T3 = s->t3;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
276 state->reset = s->reset;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
277 ff_jpegls_reset_coding_parameters(state, 0);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
278 ff_jpegls_init_state(state);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
279
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
280 if(s->bits <= 8)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
281 shift = point_transform + (8 - s->bits);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
282 else
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
283 shift = point_transform + (16 - s->bits);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
284
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
285 // av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
286 // av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
287 if(ilv == 0) { /* separate planes */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
288 off = s->cur_scan - 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
289 stride = (s->nb_components > 1) ? 3 : 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
290 width = s->width * stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
291 cur += off;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
292 for(i = 0; i < s->height; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
293 if(s->bits <= 8){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
294 ls_decode_line(state, s, last, cur, t, width, stride, off, 8);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
295 t = last[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
296 }else{
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
297 ls_decode_line(state, s, last, cur, t, width, stride, off, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
298 t = *((uint16_t*)last);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
299 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
300 last = cur;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
301 cur += s->picture.linesize[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
302
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
303 if (s->restart_interval && !--s->restart_count) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
304 align_get_bits(&s->gb);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
305 skip_bits(&s->gb, 16); /* skip RSTn */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
306 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
307 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
308 } else if(ilv == 1) { /* line interleaving */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
309 int j;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
310 int Rc[3] = {0, 0, 0};
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
311 memset(cur, 0, s->picture.linesize[0]);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
312 width = s->width * 3;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
313 for(i = 0; i < s->height; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
314 for(j = 0; j < 3; j++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
315 ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
316 Rc[j] = last[j];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
317
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
318 if (s->restart_interval && !--s->restart_count) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
319 align_get_bits(&s->gb);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
320 skip_bits(&s->gb, 16); /* skip RSTn */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
321 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
322 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
323 last = cur;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
324 cur += s->picture.linesize[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
325 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
326 } else if(ilv == 2) { /* sample interleaving */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
327 av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n");
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
328 av_free(state);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
329 av_free(zero);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
330 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
331 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
332
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
333 if(shift){ /* we need to do point transform or normalize samples */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
334 int x, w;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
335
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
336 w = s->width * s->nb_components;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
337
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
338 if(s->bits <= 8){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
339 uint8_t *src = s->picture.data[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
340
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
341 for(i = 0; i < s->height; i++){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
342 for(x = off; x < w; x+= stride){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
343 src[x] <<= shift;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
344 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
345 src += s->picture.linesize[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
346 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
347 }else{
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
348 uint16_t *src = (uint16_t*) s->picture.data[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
349
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
350 for(i = 0; i < s->height; i++){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
351 for(x = 0; x < w; x++){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
352 src[x] <<= shift;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
353 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
354 src += s->picture.linesize[0]/2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
355 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
356 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
357 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
358 av_free(state);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
359 av_free(zero);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
360
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
361 return 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
362 }
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
363
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
364
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
365 AVCodec jpegls_decoder = {
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
366 "jpegls",
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
367 CODEC_TYPE_VIDEO,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
368 CODEC_ID_JPEGLS,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
369 sizeof(MJpegDecodeContext),
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
370 ff_mjpeg_decode_init,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
371 NULL,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
372 ff_mjpeg_decode_end,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
373 ff_mjpeg_decode_frame,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
374 CODEC_CAP_DR1,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
375 };