Commit 5639729b authored by Michael Niedermayer's avatar Michael Niedermayer

unfinished jpeg-ls codec (feel free to finish it ...)

Originally committed as revision 4752 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent a42bed52
...@@ -131,6 +131,9 @@ void avcodec_register_all(void) ...@@ -131,6 +131,9 @@ void avcodec_register_all(void)
#ifdef CONFIG_LJPEG_ENCODER #ifdef CONFIG_LJPEG_ENCODER
register_avcodec(&ljpeg_encoder); register_avcodec(&ljpeg_encoder);
#endif //CONFIG_LJPEG_ENCODER #endif //CONFIG_LJPEG_ENCODER
#ifdef CONFIG_JPEGLS_ENCODER
register_avcodec(&jpegls_encoder);
#endif //CONFIG_JPEGLS_ENCODER
#ifdef CONFIG_ZLIB #ifdef CONFIG_ZLIB
#ifdef CONFIG_PNG_ENCODER #ifdef CONFIG_PNG_ENCODER
register_avcodec(&png_encoder); register_avcodec(&png_encoder);
......
...@@ -44,6 +44,7 @@ enum CodecID { ...@@ -44,6 +44,7 @@ enum CodecID {
CODEC_ID_MJPEGB, CODEC_ID_MJPEGB,
CODEC_ID_LJPEG, CODEC_ID_LJPEG,
CODEC_ID_SP5X, CODEC_ID_SP5X,
CODEC_ID_JPEGLS,
CODEC_ID_MPEG4, CODEC_ID_MPEG4,
CODEC_ID_RAWVIDEO, CODEC_ID_RAWVIDEO,
CODEC_ID_MSMPEG4V1, CODEC_ID_MSMPEG4V1,
...@@ -1532,6 +1533,14 @@ typedef struct AVCodecContext { ...@@ -1532,6 +1533,14 @@ typedef struct AVCodecContext {
* - decoding: unused * - decoding: unused
*/ */
int context_model; int context_model;
#if 0
/**
*
* - encoding: unused
* - decoding: set by user.
*/
uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
#endif
/** /**
* slice flags * slice flags
...@@ -1944,6 +1953,7 @@ extern AVCodec rv20_encoder; ...@@ -1944,6 +1953,7 @@ extern AVCodec rv20_encoder;
extern AVCodec dvvideo_encoder; extern AVCodec dvvideo_encoder;
extern AVCodec mjpeg_encoder; extern AVCodec mjpeg_encoder;
extern AVCodec ljpeg_encoder; extern AVCodec ljpeg_encoder;
extern AVCodec jpegls_encoder;
extern AVCodec png_encoder; extern AVCodec png_encoder;
extern AVCodec ppm_encoder; extern AVCodec ppm_encoder;
extern AVCodec pgm_encoder; extern AVCodec pgm_encoder;
......
This diff is collapsed.
...@@ -118,8 +118,8 @@ typedef enum { ...@@ -118,8 +118,8 @@ typedef enum {
JPG4 = 0xf4, JPG4 = 0xf4,
JPG5 = 0xf5, JPG5 = 0xf5,
JPG6 = 0xf6, JPG6 = 0xf6,
JPG7 = 0xf7, SOF48 = 0xf7, ///< JPEG-LS
JPG8 = 0xf8, LSE = 0xf8, ///< JPEG-LS extension parameters
JPG9 = 0xf9, JPG9 = 0xf9,
JPG10 = 0xfa, JPG10 = 0xfa,
JPG11 = 0xfb, JPG11 = 0xfb,
...@@ -417,7 +417,10 @@ static void jpeg_put_comments(MpegEncContext *s) ...@@ -417,7 +417,10 @@ static void jpeg_put_comments(MpegEncContext *s)
void mjpeg_picture_header(MpegEncContext *s) void mjpeg_picture_header(MpegEncContext *s)
{ {
const int lossless= s->avctx->codec_id == CODEC_ID_LJPEG; const int lossless= s->avctx->codec_id != CODEC_ID_MJPEG;
const int ls = s->avctx->codec_id == CODEC_ID_JPEGLS;
assert(!(ls && s->mjpeg_write_tables));
put_marker(&s->pb, SOI); put_marker(&s->pb, SOI);
...@@ -427,7 +430,12 @@ void mjpeg_picture_header(MpegEncContext *s) ...@@ -427,7 +430,12 @@ void mjpeg_picture_header(MpegEncContext *s)
if (s->mjpeg_write_tables) jpeg_table_header(s); if (s->mjpeg_write_tables) jpeg_table_header(s);
put_marker(&s->pb, lossless ? SOF3 : SOF0); switch(s->avctx->codec_id){
case CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break;
case CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break;
case CODEC_ID_JPEGLS: put_marker(&s->pb, SOF48); break;
default: assert(0);
}
put_bits(&s->pb, 16, 17); put_bits(&s->pb, 16, 17);
if(lossless && s->avctx->pix_fmt == PIX_FMT_RGBA32) if(lossless && s->avctx->pix_fmt == PIX_FMT_RGBA32)
...@@ -485,9 +493,18 @@ void mjpeg_picture_header(MpegEncContext *s) ...@@ -485,9 +493,18 @@ void mjpeg_picture_header(MpegEncContext *s)
put_bits(&s->pb, 4, 1); /* DC huffman table index */ put_bits(&s->pb, 4, 1); /* DC huffman table index */
put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */ put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
put_bits(&s->pb, 8, lossless ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */ put_bits(&s->pb, 8, (lossless && !ls) ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */
put_bits(&s->pb, 8, lossless ? 0 : 63); /* Se (not used) */
switch(s->avctx->codec_id){
case CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */
case CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */
case CODEC_ID_JPEGLS: put_bits(&s->pb, 8, 1); break; /* ILV = line interleaved */
default: assert(0);
}
put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */ put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */
//FIXME DC/AC entropy table selectors stuff in jpegls
} }
static void escape_FF(MpegEncContext *s, int start) static void escape_FF(MpegEncContext *s, int start)
...@@ -827,11 +844,17 @@ typedef struct MJpegDecodeContext { ...@@ -827,11 +844,17 @@ typedef struct MJpegDecodeContext {
int interlaced; /* true if interlaced */ int interlaced; /* true if interlaced */
int bottom_field; /* true if bottom field */ int bottom_field; /* true if bottom field */
int lossless; int lossless;
int ls;
int rgb; int rgb;
int rct; /* standard rct */ int rct; /* standard rct */
int pegasus_rct; /* pegasus reversible colorspace transform */ int pegasus_rct; /* pegasus reversible colorspace transform */
int bits; /* bits per component */ int bits; /* bits per component */
int maxval;
int near; ///< near lossless bound (si 0 for lossless)
int t1,t2,t3;
int reset; ///< context halfing intervall ?rename
int width, height; int width, height;
int mb_width, mb_height; int mb_width, mb_height;
int nb_components; int nb_components;
...@@ -864,6 +887,8 @@ typedef struct MJpegDecodeContext { ...@@ -864,6 +887,8 @@ typedef struct MJpegDecodeContext {
int mjpb_skiptosod; int mjpb_skiptosod;
} MJpegDecodeContext; } MJpegDecodeContext;
#include "jpeg_ls.c" //FIXME make jpeg-ls more independant
static int mjpeg_decode_dht(MJpegDecodeContext *s); static int mjpeg_decode_dht(MJpegDecodeContext *s);
static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
...@@ -1521,8 +1546,8 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s) ...@@ -1521,8 +1546,8 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
#endif #endif
} }
predictor= get_bits(&s->gb, 8); /* lossless predictor or start of spectral (Ss) */ predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
skip_bits(&s->gb, 8); /* Se */ int ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
skip_bits(&s->gb, 4); /* Ah */ skip_bits(&s->gb, 4); /* Ah */
point_transform= get_bits(&s->gb, 4); /* Al */ point_transform= get_bits(&s->gb, 4); /* Al */
...@@ -1544,13 +1569,19 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s) ...@@ -1544,13 +1569,19 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
} }
if(s->avctx->debug & FF_DEBUG_PICT_INFO) if(s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d\n", s->lossless ? "lossless" : "sequencial DCT", s->rgb ? "RGB" : "", predictor, point_transform); av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d %s\n", s->lossless ? "lossless" : "sequencial DCT", s->rgb ? "RGB" : "",
predictor, point_transform, ilv, s->bits,
s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""));
/* mjpeg-b can have padding bytes between sos and image data, skip them */ /* mjpeg-b can have padding bytes between sos and image data, skip them */
for (i = s->mjpb_skiptosod; i > 0; i--) for (i = s->mjpb_skiptosod; i > 0; i--)
skip_bits(&s->gb, 8); skip_bits(&s->gb, 8);
if(s->lossless){ if(s->lossless){
if(s->ls){
// for(){
}else{
if(s->rgb){ if(s->rgb){
if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0) if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
return -1; return -1;
...@@ -1558,6 +1589,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s) ...@@ -1558,6 +1589,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0) if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0)
return -1; return -1;
} }
}
}else{ }else{
if(mjpeg_decode_scan(s) < 0) if(mjpeg_decode_scan(s) < 0)
return -1; return -1;
...@@ -1894,6 +1926,8 @@ static int mjpeg_decode_frame(AVCodecContext *avctx, ...@@ -1894,6 +1926,8 @@ static int mjpeg_decode_frame(AVCodecContext *avctx,
switch(start_code) { switch(start_code) {
case SOI: case SOI:
s->restart_interval = 0; s->restart_interval = 0;
reset_ls_coding_parameters(s, 1);
s->restart_count = 0; s->restart_count = 0;
/* nothing to do on SOI */ /* nothing to do on SOI */
break; break;
...@@ -1916,6 +1950,16 @@ static int mjpeg_decode_frame(AVCodecContext *avctx, ...@@ -1916,6 +1950,16 @@ static int mjpeg_decode_frame(AVCodecContext *avctx,
if (mjpeg_decode_sof(s) < 0) if (mjpeg_decode_sof(s) < 0)
return -1; return -1;
break; break;
case SOF48:
s->lossless=1;
s->ls=1;
if (mjpeg_decode_sof(s) < 0)
return -1;
break;
case LSE:
if (decode_lse(s) < 0)
return -1;
break;
case EOI: case EOI:
if ((s->buggy_avid && !s->interlaced) || s->restart_interval) if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment