annotate jpeglsdec.c @ 10436:a050e8857f00 libavcodec

cosmetics: Remove pointless parentheses from return statement.
author diego
date Mon, 19 Oct 2009 12:47:52 +0000
parents 0dce4fe6e6f3
children 8a4984c5cacc
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 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8627
diff changeset
24 * @file libavcodec/jpeglsdec.c
5003
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"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 8718
diff changeset
29 #include "get_bits.h"
5003
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
30 #include "golomb.h"
8627
d6bab465b82c moves mid_pred() into mathops.h (with arch specific code split by directory)
aurel
parents: 7040
diff changeset
31 #include "mathops.h"
5003
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
32 #include "mjpeg.h"
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
33 #include "mjpegdec.h"
5003
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
34 #include "jpegls.h"
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
35 #include "jpeglsdec.h"
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 /*
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
39 * Uncomment this to significantly speed up decoding of broken JPEG-LS
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
40 * (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
41 *
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
42 * 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
43 * avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
44 * on this errors.
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
45 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
46 //#define JLS_BROKEN
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 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
50 * Decode LSE block with initialization parameters
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
51 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
52 int ff_jpegls_decode_lse(MJpegDecodeContext *s)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
53 {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
54 int len, id;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
55
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
56 /* XXX: verify len field validity */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
57 len = get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
58 id = get_bits(&s->gb, 8);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
59
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
60 switch(id){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
61 case 1:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
62 s->maxval= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
63 s->t1= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
64 s->t2= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
65 s->t3= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
66 s->reset= get_bits(&s->gb, 16);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
67
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
68 // ff_jpegls_reset_coding_parameters(s, 0);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
69 //FIXME quant table?
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
70 break;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
71 case 2:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
72 case 3:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
73 av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n");
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
74 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
75 case 4:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
76 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
77 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
78 default:
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
79 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
80 return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
81 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
82 // 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
83
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
84 return 0;
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 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
88 * Get context-dependent Golomb code, decode it and update context
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
89 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
90 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
91 int k, ret;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
92
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
93 for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
94
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
95 #ifdef JLS_BROKEN
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
96 if(!show_bits_long(gb, 32))return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
97 #endif
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
98 ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
99
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
100 /* decode mapped error */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
101 if(ret & 1)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
102 ret = -((ret + 1) >> 1);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
103 else
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
104 ret >>= 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
105
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
106 /* 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
107 if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q]))
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
108 ret = -(ret + 1);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
109
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
110 ret= ff_jpegls_update_state_regular(state, Q, ret);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
111
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
112 return ret;
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 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
116 * Get Golomb code, decode it and update state for run termination
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
117 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
118 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
119 int k, ret, temp, map;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
120 int Q = 365 + RItype;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
121
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
122 temp= state->A[Q];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
123 if(RItype)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
124 temp += state->N[Q] >> 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
125
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
126 for(k = 0; (state->N[Q] << k) < temp; k++);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
127
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
128 #ifdef JLS_BROKEN
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
129 if(!show_bits_long(gb, 32))return -1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
130 #endif
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
131 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
132
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
133 /* decode mapped error */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
134 map = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
135 if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q]))
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
136 map = 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
137 ret += RItype + map;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
138
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
139 if(ret & 1){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
140 ret = map - ((ret + 1) >> 1);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
141 state->B[Q]++;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
142 } else {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
143 ret = ret >> 1;
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
146 /* update state */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
147 state->A[Q] += FFABS(ret) - RItype;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
148 ret *= state->twonear;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
149 ff_jpegls_downscale_state(state, Q);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
150
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
151 return ret;
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 /**
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
155 * Decode one line of image
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
156 */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
157 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
158 int i, x = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
159 int Ra, Rb, Rc, Rd;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
160 int D0, D1, D2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
161
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
162 while(x < w) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
163 int err, pred;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
164
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
165 /* compute gradients */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
166 Ra = x ? R(dst, x - stride) : R(last, x);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
167 Rb = R(last, x);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
168 Rc = x ? R(last, x - stride) : last2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
169 Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
170 D0 = Rd - Rb;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
171 D1 = Rb - Rc;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
172 D2 = Rc - Ra;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
173 /* run mode */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
174 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
175 int r;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
176 int RItype;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
177
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
178 /* decode full runs while available */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
179 while(get_bits1(&s->gb)) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
180 int r;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
181 r = 1 << ff_log2_run[state->run_index[comp]];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
182 if(x + r * stride > w) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
183 r = (w - x) / stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
184 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
185 for(i = 0; i < r; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
186 W(dst, x, Ra);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
187 x += stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
188 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
189 /* if EOL reached, we stop decoding */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
190 if(r != (1 << ff_log2_run[state->run_index[comp]]))
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
191 return;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
192 if(state->run_index[comp] < 31)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
193 state->run_index[comp]++;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
194 if(x + stride > w)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
195 return;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
196 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
197 /* decode aborted run */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
198 r = ff_log2_run[state->run_index[comp]];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
199 if(r)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
200 r = get_bits_long(&s->gb, r);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
201 for(i = 0; i < r; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
202 W(dst, x, Ra);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
203 x += stride;
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
206 /* decode run termination value */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
207 Rb = R(last, x);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
208 RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
209 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
210 if(state->run_index[comp])
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
211 state->run_index[comp]--;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
212
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
213 if(state->near && RItype){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
214 pred = Ra + err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
215 } else {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
216 if(Rb < Ra)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
217 pred = Rb - err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
218 else
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
219 pred = Rb + err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
220 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
221 } else { /* regular mode */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
222 int context, sign;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
223
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
224 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
225 pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
226
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
227 if(context < 0){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
228 context = -context;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
229 sign = 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
230 }else{
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
231 sign = 0;
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
234 if(sign){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
235 pred = av_clip(pred - state->C[context], 0, state->maxval);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
236 err = -ls_get_code_regular(&s->gb, state, context);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
237 } else {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
238 pred = av_clip(pred + state->C[context], 0, state->maxval);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
239 err = ls_get_code_regular(&s->gb, state, context);
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
242 /* we have to do something more for near-lossless coding */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
243 pred += err;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
244 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
245 if(state->near){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
246 if(pred < -state->near)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
247 pred += state->range * state->twonear;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
248 else if(pred > state->maxval + state->near)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
249 pred -= state->range * state->twonear;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
250 pred = av_clip(pred, 0, state->maxval);
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
253 pred &= state->maxval;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
254 W(dst, x, pred);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
255 x += stride;
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
259 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
260 int i, t = 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
261 uint8_t *zero, *last, *cur;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
262 JLSState *state;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
263 int off = 0, stride = 1, width, shift;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
264
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
265 zero = av_mallocz(s->picture.linesize[0]);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
266 last = zero;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
267 cur = s->picture.data[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
268
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
269 state = av_mallocz(sizeof(JLSState));
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
270 /* initialize JPEG-LS state from JPEG parameters */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
271 state->near = near;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
272 state->bpp = (s->bits < 2) ? 2 : s->bits;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
273 state->maxval = s->maxval;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
274 state->T1 = s->t1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
275 state->T2 = s->t2;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
276 state->T3 = s->t3;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
277 state->reset = s->reset;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
278 ff_jpegls_reset_coding_parameters(state, 0);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
279 ff_jpegls_init_state(state);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
280
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
281 if(s->bits <= 8)
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
282 shift = point_transform + (8 - s->bits);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
283 else
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
284 shift = point_transform + (16 - s->bits);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
285
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
286 // 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
287 // 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
288 if(ilv == 0) { /* separate planes */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
289 off = s->cur_scan - 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
290 stride = (s->nb_components > 1) ? 3 : 1;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
291 width = s->width * stride;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
292 cur += off;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
293 for(i = 0; i < s->height; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
294 if(s->bits <= 8){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
295 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
296 t = last[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
297 }else{
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
298 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
299 t = *((uint16_t*)last);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
300 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
301 last = cur;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
302 cur += s->picture.linesize[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
303
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
304 if (s->restart_interval && !--s->restart_count) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
305 align_get_bits(&s->gb);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
306 skip_bits(&s->gb, 16); /* skip RSTn */
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 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
309 } else if(ilv == 1) { /* line interleaving */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
310 int j;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
311 int Rc[3] = {0, 0, 0};
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
312 memset(cur, 0, s->picture.linesize[0]);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
313 width = s->width * 3;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
314 for(i = 0; i < s->height; i++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
315 for(j = 0; j < 3; j++) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
316 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
317 Rc[j] = last[j];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
318
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
319 if (s->restart_interval && !--s->restart_count) {
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
320 align_get_bits(&s->gb);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
321 skip_bits(&s->gb, 16); /* skip RSTn */
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 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
324 last = cur;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
325 cur += s->picture.linesize[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
326 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
327 } else if(ilv == 2) { /* sample interleaving */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
328 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
329 av_free(state);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
330 av_free(zero);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
331 return -1;
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
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
334 if(shift){ /* we need to do point transform or normalize samples */
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
335 int x, w;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
336
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
337 w = s->width * s->nb_components;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
338
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
339 if(s->bits <= 8){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
340 uint8_t *src = s->picture.data[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
341
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
342 for(i = 0; i < s->height; i++){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
343 for(x = off; x < w; x+= stride){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
344 src[x] <<= shift;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
345 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
346 src += s->picture.linesize[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
347 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
348 }else{
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
349 uint16_t *src = (uint16_t*) s->picture.data[0];
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
350
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
351 for(i = 0; i < s->height; i++){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
352 for(x = 0; x < w; x++){
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
353 src[x] <<= shift;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
354 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
355 src += s->picture.linesize[0]/2;
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 }
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
359 av_free(state);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
360 av_free(zero);
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
361
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
362 return 0;
ddb28de352bb split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
aurel
parents:
diff changeset
363 }
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
364
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
365
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
366 AVCodec jpegls_decoder = {
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
367 "jpegls",
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
368 CODEC_TYPE_VIDEO,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
369 CODEC_ID_JPEGLS,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
370 sizeof(MJpegDecodeContext),
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
371 ff_mjpeg_decode_init,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
372 NULL,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
373 ff_mjpeg_decode_end,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
374 ff_mjpeg_decode_frame,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
375 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6712
diff changeset
376 .long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5003
diff changeset
377 };