2007-05-14 01:16:56 +02:00
|
|
|
/*
|
|
|
|
* JPEG-LS common code
|
|
|
|
* Copyright (c) 2003 Michael Niedermayer
|
|
|
|
* Copyright (c) 2006 Konstantin Shishkov
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2007-05-14 01:16:56 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-05-14 01:16:56 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-05-14 01:16:56 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-05-14 01:16:56 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2007-05-14 01:16:56 +02:00
|
|
|
* JPEG-LS common code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jpegls.h"
|
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
void ff_jpegls_init_state(JLSState *state)
|
|
|
|
{
|
2007-05-14 01:16:56 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
state->twonear = state->near * 2 + 1;
|
2013-05-15 19:55:09 +02:00
|
|
|
state->range = (state->maxval + state->twonear - 1) / state->twonear + 1;
|
2007-05-14 01:16:56 +02:00
|
|
|
|
|
|
|
// QBPP = ceil(log2(RANGE))
|
2013-05-15 19:03:53 +02:00
|
|
|
for (state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++)
|
|
|
|
;
|
2007-05-14 01:16:56 +02:00
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
if (state->bpp < 8)
|
|
|
|
state->limit = 2 * state->bpp - state->qbpp + 16;
|
2007-05-14 01:16:56 +02:00
|
|
|
else
|
2013-05-15 19:55:09 +02:00
|
|
|
state->limit = 4 * state->bpp - state->qbpp;
|
2007-05-14 01:16:56 +02:00
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
for (i = 0; i < 367; i++) {
|
2013-05-15 19:55:09 +02:00
|
|
|
state->A[i] = FFMAX(state->range + 32 >> 6, 2);
|
2007-05-14 01:16:56 +02:00
|
|
|
state->N[i] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom value clipping function used in T1, T2, T3 calculation
|
|
|
|
*/
|
2013-05-15 19:03:53 +02:00
|
|
|
static inline int iso_clip(int v, int vmin, int vmax)
|
|
|
|
{
|
|
|
|
if (v > vmax || v < vmin)
|
|
|
|
return vmin;
|
|
|
|
else
|
|
|
|
return v;
|
2007-05-14 01:16:56 +02:00
|
|
|
}
|
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
|
|
|
|
{
|
|
|
|
const int basic_t1 = 3;
|
|
|
|
const int basic_t2 = 7;
|
|
|
|
const int basic_t3 = 21;
|
2007-05-14 01:16:56 +02:00
|
|
|
int factor;
|
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
if (s->maxval == 0 || reset_all)
|
|
|
|
s->maxval = (1 << s->bpp) - 1;
|
2007-05-14 01:16:56 +02:00
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
if (s->maxval >= 128) {
|
2013-05-15 19:55:09 +02:00
|
|
|
factor = FFMIN(s->maxval, 4095) + 128 >> 8;
|
2007-05-14 01:16:56 +02:00
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
if (s->T1 == 0 || reset_all)
|
|
|
|
s->T1 = iso_clip(factor * (basic_t1 - 2) + 2 + 3 * s->near,
|
|
|
|
s->near + 1, s->maxval);
|
|
|
|
if (s->T2 == 0 || reset_all)
|
|
|
|
s->T2 = iso_clip(factor * (basic_t2 - 3) + 3 + 5 * s->near,
|
|
|
|
s->T1, s->maxval);
|
|
|
|
if (s->T3 == 0 || reset_all)
|
|
|
|
s->T3 = iso_clip(factor * (basic_t3 - 4) + 4 + 7 * s->near,
|
|
|
|
s->T2, s->maxval);
|
|
|
|
} else {
|
|
|
|
factor = 256 / (s->maxval + 1);
|
2007-05-14 01:16:56 +02:00
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
if (s->T1 == 0 || reset_all)
|
|
|
|
s->T1 = iso_clip(FFMAX(2, basic_t1 / factor + 3 * s->near),
|
|
|
|
s->near + 1, s->maxval);
|
|
|
|
if (s->T2 == 0 || reset_all)
|
|
|
|
s->T2 = iso_clip(FFMAX(3, basic_t2 / factor + 5 * s->near),
|
|
|
|
s->T1, s->maxval);
|
|
|
|
if (s->T3 == 0 || reset_all)
|
|
|
|
s->T3 = iso_clip(FFMAX(4, basic_t3 / factor + 7 * s->near),
|
|
|
|
s->T2, s->maxval);
|
2007-05-14 01:16:56 +02:00
|
|
|
}
|
|
|
|
|
2013-05-15 19:03:53 +02:00
|
|
|
if (s->reset == 0 || reset_all)
|
|
|
|
s->reset = 64;
|
2012-08-21 12:41:40 +02:00
|
|
|
av_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
|
2007-05-14 01:16:56 +02:00
|
|
|
}
|