FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
j2kenc.c File Reference

JPEG2000 image encoder. More...

#include <float.h>
#include "avcodec.h"
#include "internal.h"
#include "bytestream.h"
#include "jpeg2000.h"
#include "libavutil/common.h"
#include "libavutil/opt.h"

Go to the source code of this file.

Data Structures

struct  Jpeg2000Tile
 
struct  Jpeg2000EncoderContext
 

Macros

#define NMSEDEC_BITS   7
 
#define NMSEDEC_FRACBITS   (NMSEDEC_BITS-1)
 
#define WMSEDEC_SHIFT   13
 must be >= 13 More...
 
#define LAMBDA_SCALE   (100000000LL << (WMSEDEC_SHIFT - 13))
 
#define CODEC_JP2   1
 
#define CODEC_J2K   0
 
#define OFFSET(x)   offsetof(Jpeg2000EncoderContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void put_bits (Jpeg2000EncoderContext *s, int val, int n)
 put n times val bit More...
 
static void put_num (Jpeg2000EncoderContext *s, int num, int n)
 put n least significant bits of a number num More...
 
static void j2k_flush (Jpeg2000EncoderContext *s)
 flush the bitstream More...
 
static void tag_tree_code (Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
 code the value stored in node More...
 
static void tag_tree_update (Jpeg2000TgtNode *node)
 update the value in node More...
 
static int put_siz (Jpeg2000EncoderContext *s)
 
static int put_cod (Jpeg2000EncoderContext *s)
 
static int put_qcd (Jpeg2000EncoderContext *s, int compno)
 
static int put_com (Jpeg2000EncoderContext *s, int compno)
 
static uint8_tput_sot (Jpeg2000EncoderContext *s, int tileno)
 
static int init_tiles (Jpeg2000EncoderContext *s)
 compute the sizes of tiles, resolution levels, bands, etc. More...
 
static void copy_frame (Jpeg2000EncoderContext *s)
 
static void init_quantization (Jpeg2000EncoderContext *s)
 
static void init_luts (void)
 
static int getnmsedec_sig (int x, int bpno)
 
static int getnmsedec_ref (int x, int bpno)
 
static void encode_sigpass (Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
 
static void encode_refpass (Jpeg2000T1Context *t1, int width, int height, int *nmsedec, int bpno)
 
static void encode_clnpass (Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
 
static void encode_cblk (Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile, int width, int height, int bandpos, int lev)
 
static void putnumpasses (Jpeg2000EncoderContext *s, int n)
 
static int encode_packet (Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, int precno, uint8_t *expn, int numgbits)
 
static int encode_packets (Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
 
static int getcut (Jpeg2000Cblk *cblk, int64_t lambda, int dwt_norm)
 
static void truncpasses (Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
 
static int encode_tile (Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
 
static void cleanup (Jpeg2000EncoderContext *s)
 
static void reinit (Jpeg2000EncoderContext *s)
 
static void update_size (uint8_t *size, const uint8_t *end)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int j2kenc_init (AVCodecContext *avctx)
 
static int j2kenc_destroy (AVCodecContext *avctx)
 

Variables

static int lut_nmsedec_ref [1<< NMSEDEC_BITS]
 
static int lut_nmsedec_ref0 [1<< NMSEDEC_BITS]
 
static int lut_nmsedec_sig [1<< NMSEDEC_BITS]
 
static int lut_nmsedec_sig0 [1<< NMSEDEC_BITS]
 
static const int dwt_norms [2][4][10]
 
static const AVOption options []
 
static const AVClass j2k_class
 
AVCodec ff_jpeg2000_encoder
 

Detailed Description

JPEG2000 image encoder.

Author
Kamil Nowosad

Definition in file j2kenc.c.

Macro Definition Documentation

#define NMSEDEC_BITS   7

Definition at line 36 of file j2kenc.c.

Referenced by getnmsedec_ref(), getnmsedec_sig(), and init_luts().

#define NMSEDEC_FRACBITS   (NMSEDEC_BITS-1)
#define WMSEDEC_SHIFT   13

must be >= 13

Definition at line 38 of file j2kenc.c.

Referenced by getcut().

#define LAMBDA_SCALE   (100000000LL << (WMSEDEC_SHIFT - 13))

Definition at line 39 of file j2kenc.c.

Referenced by encode_frame().

#define CODEC_JP2   1

Definition at line 41 of file j2kenc.c.

Referenced by encode_frame(), and libopenjpeg_decode_frame().

#define CODEC_J2K   0

Definition at line 42 of file j2kenc.c.

Referenced by libopenjpeg_decode_frame().

#define OFFSET (   x)    offsetof(Jpeg2000EncoderContext, x)

Definition at line 1134 of file j2kenc.c.

Definition at line 1135 of file j2kenc.c.

Function Documentation

static void put_bits ( Jpeg2000EncoderContext s,
int  val,
int  n 
)
static

put n times val bit

Definition at line 167 of file j2kenc.c.

Referenced by aac_adtstoasc_filter(), aac_encode_frame(), ac3_output_frame_header(), adpcm_encode_frame(), adts_decode_extradata(), adts_write_frame_header(), asv1_encode_block(), asv1_put_level(), asv2_encode_block(), asv2_put_bits(), asv2_put_level(), avpriv_align_put_bits(), avpriv_copy_bits(), avpriv_dca_convert_bitstream(), avpriv_put_string(), bit_copy(), codebook_trellis_rate(), copy_bits(), dnxhd_encode_block(), dnxhd_encode_dc(), dnxhd_encode_thread(), dv_encode_ac(), dv_encode_video_segment(), encode_422_bitstream(), encode_ac_coeffs(), encode_bitstream(), encode_block(), encode_codeword(), encode_dc(), encode_exp_vlc(), encode_ext_header(), encode_flush(), encode_frame(), encode_individual_channel(), encode_line(), encode_mb_skip_run(), encode_ms_info(), encode_packet(), encode_picture_ls(), encode_pulses(), encode_scalar(), encode_scale_factors(), encode_superframe(), encode_vlc_codeword(), encode_window_bands_info(), ff_aac_encode_main_pred(), ff_aac_encode_tns_info(), ff_eac3_output_frame_header(), ff_flv2_encode_ac_esc(), ff_flv_encode_picture_header(), ff_h261_encode_mb(), ff_h261_encode_picture_header(), ff_h263_encode_gob_header(), ff_h263_encode_mb(), ff_h263_encode_mba(), ff_h263_encode_motion(), ff_h263_encode_picture_header(), ff_hevc_encode_nal_vps(), ff_mjpeg_encode_dc(), ff_mjpeg_encode_picture_header(), ff_mjpeg_escape_FF(), ff_mjpeg_find_marker(), ff_mpeg1_encode_picture_header(), ff_mpeg1_encode_slice_header(), ff_mpeg4_encode_mb(), ff_mpeg4_encode_picture_header(), ff_mpeg4_encode_video_packet_header(), ff_mpeg4_merge_partitions(), ff_mpeg4_stuffing(), ff_mpv_encode_picture(), ff_msmpeg4_code012(), ff_msmpeg4_encode_block(), ff_msmpeg4_encode_ext_header(), ff_msmpeg4_encode_mb(), ff_msmpeg4_encode_motion(), ff_msmpeg4_encode_picture_header(), ff_rv10_encode_picture_header(), ff_rv20_encode_picture_header(), ff_wmv2_encode_mb(), ff_wmv2_encode_picture_header(), ff_write_quant_matrix(), floor_encode(), gif_image_write_image(), h261_encode_block(), h261_encode_gob_header(), h261_encode_motion(), h263_encode_block(), h263p_encode_umotion(), jpeg_put_comments(), jpeg_table_header(), latm_write_frame_header(), latm_write_packet(), ls_encode_run(), ls_store_lse(), main(), mov_write_ac3_tag(), mov_write_dvc1_structs(), mov_write_eac3_tag(), mpeg1_encode_block(), mpeg1_encode_mb_internal(), mpeg1_encode_motion(), mpeg1_encode_sequence_header(), mpeg4_encode_block(), mpeg4_encode_dc(), mpeg4_encode_gop_header(), mpeg4_encode_visual_object_header(), mpeg4_encode_vol_header(), msmpeg4_encode_dc(), msmpeg4v2_encode_motion(), output_audio_block(), pack_float_sample(), pnm_decode_frame(), put_alpha_diff(), put_alpha_run(), put_audio_specific_config(), put_bitstream_info(), put_codebook_header(), put_codeword(), put_floor_header(), put_frame_header(), put_header(), put_huffman_table(), put_ics_info(), put_main_header(), put_marker(), put_mb_modes(), put_num(), put_pack_header(), put_primary_audio_header(), put_qscale(), put_residue_header(), put_subframe(), put_subframe_samples(), put_swf_line_edge(), put_swf_matrix(), put_swf_rect(), put_system_header(), put_xsub_rle(), quantize_and_encode_band_cost_template(), ra144_encode_frame(), ra144_encode_subblock(), read_packet(), s302m_encode2_frame(), save_bits(), send_mode_a(), send_mode_b(), set_te_golomb(), set_ue_golomb(), set_ur_golomb(), set_ur_golomb_jpegls(), svq1_encode_frame(), svq1_encode_plane(), svq1_write_header(), swf_write_header(), tag_tree_code(), tta_encode_frame(), vorbis_encode_frame(), wavpack_encode_sample(), write_element(), write_element_header(), write_frame(), write_frame_footer(), write_frame_header(), write_header(), write_huff_codes(), write_ptl(), write_ptl_layer(), write_streaminfo(), write_subframes(), and write_utf8().

static void put_num ( Jpeg2000EncoderContext s,
int  num,
int  n 
)
static

put n least significant bits of a number num

Definition at line 180 of file j2kenc.c.

Referenced by encode_packet(), and putnumpasses().

static void j2k_flush ( Jpeg2000EncoderContext s)
static

flush the bitstream

Definition at line 187 of file j2kenc.c.

Referenced by encode_packet().

static void tag_tree_code ( Jpeg2000EncoderContext s,
Jpeg2000TgtNode node,
int  threshold 
)
static

code the value stored in node

Definition at line 198 of file j2kenc.c.

Referenced by encode_packet().

static void tag_tree_update ( Jpeg2000TgtNode node)
static

update the value in node

Definition at line 226 of file j2kenc.c.

Referenced by encode_packet().

static int put_siz ( Jpeg2000EncoderContext s)
static

Definition at line 238 of file j2kenc.c.

Referenced by encode_frame().

static int put_cod ( Jpeg2000EncoderContext s)
static

Definition at line 267 of file j2kenc.c.

Referenced by encode_frame().

static int put_qcd ( Jpeg2000EncoderContext s,
int  compno 
)
static

Definition at line 294 of file j2kenc.c.

Referenced by encode_frame().

static int put_com ( Jpeg2000EncoderContext s,
int  compno 
)
static

Definition at line 320 of file j2kenc.c.

Referenced by encode_frame().

static uint8_t* put_sot ( Jpeg2000EncoderContext s,
int  tileno 
)
static

Definition at line 339 of file j2kenc.c.

Referenced by encode_frame().

static int init_tiles ( Jpeg2000EncoderContext s)
static

compute the sizes of tiles, resolution levels, bands, etc.

allocate memory for them divide the input image into tile-components

Definition at line 363 of file j2kenc.c.

Referenced by j2kenc_init().

static void copy_frame ( Jpeg2000EncoderContext s)
static

Definition at line 409 of file j2kenc.c.

Referenced by encode_frame().

static void init_quantization ( Jpeg2000EncoderContext s)
static

Definition at line 447 of file j2kenc.c.

Referenced by j2kenc_init().

static void init_luts ( void  )
static

Definition at line 477 of file j2kenc.c.

Referenced by j2kenc_init().

static int getnmsedec_sig ( int  x,
int  bpno 
)
static

Definition at line 495 of file j2kenc.c.

Referenced by encode_clnpass(), and encode_sigpass().

static int getnmsedec_ref ( int  x,
int  bpno 
)
static

Definition at line 502 of file j2kenc.c.

Referenced by encode_refpass().

static void encode_sigpass ( Jpeg2000T1Context t1,
int  width,
int  height,
int  bandno,
int *  nmsedec,
int  bpno 
)
static

Definition at line 509 of file j2kenc.c.

Referenced by encode_cblk().

static void encode_refpass ( Jpeg2000T1Context t1,
int  width,
int  height,
int *  nmsedec,
int  bpno 
)
static

Definition at line 531 of file j2kenc.c.

Referenced by encode_cblk().

static void encode_clnpass ( Jpeg2000T1Context t1,
int  width,
int  height,
int  bandno,
int *  nmsedec,
int  bpno 
)
static

Definition at line 545 of file j2kenc.c.

Referenced by encode_cblk().

static void encode_cblk ( Jpeg2000EncoderContext s,
Jpeg2000T1Context t1,
Jpeg2000Cblk cblk,
Jpeg2000Tile tile,
int  width,
int  height,
int  bandpos,
int  lev 
)
static

Definition at line 600 of file j2kenc.c.

Referenced by encode_tile().

static void putnumpasses ( Jpeg2000EncoderContext s,
int  n 
)
static

Definition at line 657 of file j2kenc.c.

Referenced by encode_packet().

static int encode_packet ( Jpeg2000EncoderContext s,
Jpeg2000ResLevel rlevel,
int  precno,
uint8_t expn,
int  numgbits 
)
static

Definition at line 672 of file j2kenc.c.

Referenced by encode_packets().

static int encode_packets ( Jpeg2000EncoderContext s,
Jpeg2000Tile tile,
int  tileno 
)
static

Definition at line 770 of file j2kenc.c.

Referenced by encode_tile().

static int getcut ( Jpeg2000Cblk cblk,
int64_t  lambda,
int  dwt_norm 
)
static

Definition at line 793 of file j2kenc.c.

Referenced by truncpasses().

static void truncpasses ( Jpeg2000EncoderContext s,
Jpeg2000Tile tile 
)
static

Definition at line 811 of file j2kenc.c.

Referenced by encode_tile().

static int encode_tile ( Jpeg2000EncoderContext s,
Jpeg2000Tile tile,
int  tileno 
)
static

Definition at line 840 of file j2kenc.c.

Referenced by encode_frame().

static void cleanup ( Jpeg2000EncoderContext s)
static

Definition at line 921 of file j2kenc.c.

Referenced by j2kenc_destroy().

static void reinit ( Jpeg2000EncoderContext s)
static

Definition at line 936 of file j2kenc.c.

Referenced by encode_frame().

static void update_size ( uint8_t size,
const uint8_t end 
)
static

Definition at line 946 of file j2kenc.c.

Referenced by encode_frame().

static int encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame pict,
int *  got_packet 
)
static

Definition at line 951 of file j2kenc.c.

static av_cold int j2kenc_init ( AVCodecContext avctx)
static

Definition at line 1062 of file j2kenc.c.

static int j2kenc_destroy ( AVCodecContext avctx)
static

Definition at line 1124 of file j2kenc.c.

Variable Documentation

int lut_nmsedec_ref[1<< NMSEDEC_BITS]
static

Definition at line 44 of file j2kenc.c.

Referenced by getnmsedec_ref(), and init_luts().

int lut_nmsedec_ref0[1<< NMSEDEC_BITS]
static

Definition at line 44 of file j2kenc.c.

Referenced by getnmsedec_ref(), and init_luts().

int lut_nmsedec_sig[1<< NMSEDEC_BITS]
static

Definition at line 44 of file j2kenc.c.

Referenced by getnmsedec_sig(), and init_luts().

int lut_nmsedec_sig0[1<< NMSEDEC_BITS]
static

Definition at line 44 of file j2kenc.c.

Referenced by getnmsedec_sig(), and init_luts().

const int dwt_norms[2][4][10]
static
Initial value:
= {
{{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
{20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
{20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
{20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
{{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
{10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
{10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
{ 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
}

Definition at line 49 of file j2kenc.c.

Referenced by init_quantization(), and truncpasses().

const AVOption options[]
static
Initial value:
= {
{ "format", "Codec Format", OFFSET(format), AV_OPT_TYPE_INT, { .i64 = CODEC_JP2 }, CODEC_J2K, CODEC_JP2, VE, "format" },
{ "j2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K }, 0, 0, VE, "format" },
{ "jp2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2 }, 0, 0, VE, "format" },
{ "tile_width", "Tile Width", OFFSET(tile_width), AV_OPT_TYPE_INT, { .i64 = 256 }, 1, 1<<30, VE, },
{ "tile_height", "Tile Height", OFFSET(tile_height), AV_OPT_TYPE_INT, { .i64 = 256 }, 1, 1<<30, VE, },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: j2kenc.c:1134
#define CODEC_J2K
Definition: j2kenc.c:42
#define CODEC_JP2
Definition: j2kenc.c:41
#define VE
Definition: j2kenc.c:1135

Definition at line 1136 of file j2kenc.c.

const AVClass j2k_class
static
Initial value:
= {
.class_name = "jpeg 2000 encoder",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
av_default_item_name
static const AVOption options[]
Definition: j2kenc.c:1136

Definition at line 1146 of file j2kenc.c.

AVCodec ff_jpeg2000_encoder
Initial value:
= {
.name = "jpeg2000",
.long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"),
.priv_data_size = sizeof(Jpeg2000EncoderContext),
.encode2 = encode_frame,
.close = j2kenc_destroy,
.pix_fmts = (const enum AVPixelFormat[]) {
},
.priv_class = &j2k_class,
}
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int j2kenc_init(AVCodecContext *avctx)
Definition: j2kenc.c:1062
static const AVClass j2k_class
Definition: j2kenc.c:1146
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: j2kenc.c:951
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
static int j2kenc_destroy(AVCodecContext *avctx)
Definition: j2kenc.c:1124
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61

Definition at line 1153 of file j2kenc.c.