PutByteContext pb;
PutBitContext pb2;
GetBitContext gb;
- uint8_t *buf2 = NULL;
const uint8_t *in;
uint8_t *last = NULL;
- JLSState *state = NULL;
+ JLSState state = { 0 };
int i, size, ret;
int comps;
-#if FF_API_PRIVATE_OPT
-FF_DISABLE_DEPRECATION_WARNINGS
- if (avctx->prediction_method)
- ctx->pred = avctx->prediction_method;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||
avctx->pix_fmt == AV_PIX_FMT_GRAY16)
comps = 1;
AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
return ret;
- buf2 = av_malloc(pkt->size);
- if (!buf2)
- goto memfail;
+ last = av_malloc((unsigned)pkt->size + FFABS(p->linesize[0]));
+ if (!last)
+ return AVERROR(ENOMEM);
+ memset(last, 0, FFABS(p->linesize[0]));
bytestream2_init_writer(&pb, pkt->data, pkt->size);
- init_put_bits(&pb2, buf2, pkt->size);
+ init_put_bits(&pb2, last + FFABS(p->linesize[0]), pkt->size);
/* write our own JPEG header, can't use mjpeg_picture_header */
put_marker_byteu(&pb, SOI);
bytestream2_put_byteu(&pb, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line
bytestream2_put_byteu(&pb, 0); // point transform: none
- state = av_mallocz(sizeof(JLSState));
- if (!state)
- goto memfail;
-
/* initialize JPEG-LS state from JPEG parameters */
- state->near = ctx->pred;
- state->bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8;
- ff_jpegls_reset_coding_parameters(state, 0);
- ff_jpegls_init_state(state);
-
- ls_store_lse(state, &pb);
+ state.near = ctx->pred;
+ state.bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8;
+ ff_jpegls_reset_coding_parameters(&state, 0);
+ ff_jpegls_init_state(&state);
- last = av_mallocz(FFABS(p->linesize[0]));
- if (!last)
- goto memfail;
+ ls_store_lse(&state, &pb);
in = p->data[0];
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
for (i = 0; i < avctx->height; i++) {
int last0 = last[0];
- ls_encode_line(state, &pb2, last, in, t, avctx->width, 1, 0, 8);
+ ls_encode_line(&state, &pb2, last, in, t, avctx->width, 1, 0, 8);
t = last0;
in += p->linesize[0];
}
for (i = 0; i < avctx->height; i++) {
int last0 = *((uint16_t *)last);
- ls_encode_line(state, &pb2, last, in, t, avctx->width, 1, 0, 16);
+ ls_encode_line(&state, &pb2, last, in, t, avctx->width, 1, 0, 16);
t = last0;
in += p->linesize[0];
}
for (i = 0; i < avctx->height; i++) {
for (j = 0; j < 3; j++) {
int last0 = last[j];
- ls_encode_line(state, &pb2, last + j, in + j, Rc[j],
+ ls_encode_line(&state, &pb2, last + j, in + j, Rc[j],
width, 3, j, 8);
Rc[j] = last0;
}
for (i = 0; i < avctx->height; i++) {
for (j = 2; j >= 0; j--) {
int last0 = last[j];
- ls_encode_line(state, &pb2, last + j, in + j, Rc[j],
+ ls_encode_line(&state, &pb2, last + j, in + j, Rc[j],
width, 3, j, 8);
Rc[j] = last0;
}
}
}
- av_freep(&last);
- av_freep(&state);
-
/* the specification says that after doing 0xff escaping unused bits in
* the last byte must be set to 0, so just append 7 "optional" zero bits
* to avoid special-casing. */
size = put_bits_count(&pb2);
flush_put_bits(&pb2);
/* do escape coding */
- init_get_bits(&gb, buf2, size);
+ init_get_bits(&gb, pb2.buf, size);
size -= 7;
while (get_bits_count(&gb) < size) {
int v;
bytestream2_put_byte(&pb, v);
}
}
- av_freep(&buf2);
+ av_freep(&last);
/* End of image */
put_marker_byte(&pb, EOI);
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
-
-memfail:
- av_freep(&buf2);
- av_freep(&state);
- av_freep(&last);
- return AVERROR(ENOMEM);
-}
-
-static av_cold int encode_init_ls(AVCodecContext *ctx)
-{
-#if FF_API_CODED_FRAME
-FF_DISABLE_DEPRECATION_WARNINGS
- ctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
- ctx->coded_frame->key_frame = 1;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
- if (ctx->pix_fmt != AV_PIX_FMT_GRAY8 &&
- ctx->pix_fmt != AV_PIX_FMT_GRAY16 &&
- ctx->pix_fmt != AV_PIX_FMT_RGB24 &&
- ctx->pix_fmt != AV_PIX_FMT_BGR24) {
- av_log(ctx, AV_LOG_ERROR,
- "Only grayscale and RGB24/BGR24 images are supported\n");
- return -1;
- }
- return 0;
}
#define OFFSET(x) offsetof(JPEGLSContext, x)
.version = LIBAVUTIL_VERSION_INT,
};
-AVCodec ff_jpegls_encoder = {
+const AVCodec ff_jpegls_encoder = {
.name = "jpegls",
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_JPEGLS,
.priv_data_size = sizeof(JPEGLSContext),
.priv_class = &jpegls_class,
- .init = encode_init_ls,
.capabilities = AV_CODEC_CAP_FRAME_THREADS,
.encode2 = encode_picture_ls,
.pix_fmts = (const enum AVPixelFormat[]) {