1 /*
2 * JPEG2000 image encoder
3 * Copyright (c) 2007 Kamil Nowosad
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * **********************************************************************************************************************
22 *
23 *
24 *
25 * This source code incorporates work covered by the following copyright and
26 * permission notice:
27 *
28 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
29 * Copyright (c) 2002-2007, Professor Benoit Macq
30 * Copyright (c) 2001-2003, David Janssens
31 * Copyright (c) 2002-2003, Yannick Verschueren
32 * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
33 * Copyright (c) 2005, Herve Drolon, FreeImage Team
34 * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
35 * All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
47 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
50 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 * POSSIBILITY OF SUCH DAMAGE.
57 */
58
59
60 /**
61 * JPEG2000 image encoder
62 * @file
63 * @author Kamil Nowosad
64 */
65
74
75 #define NMSEDEC_BITS 7
76 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
77 #define WMSEDEC_SHIFT 13 ///< must be >= 13
78 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
79
82
87
88 static const int dwt_norms[2][4][10] = {
// [dwt_type][band][rlevel] (multiplied by 10000)
89 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
90 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
91 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
92 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
93
94 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
95 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
96 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
97 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
98 };
99
103
108
110 uint8_t cbps[4];
///< bits per sample in particular components
116
121
123
126
128
132
133
134 /* debug */
135 #if 0
136 #undef ifprintf
137 #undef printf
138
139 static void nspaces(FILE *fd,
int n)
140 {
141 while(n--) putc(' ', fd);
142 }
143
145 {
146 int i;
147 for (i = 0; i < comp->y1 - comp->y0; i++)
148 ff_jpeg2000_printv(comp->
i_data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
149 }
150
152 {
153 int tileno, compno, reslevelno, bandno, precno;
154 fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
155 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
156 "tiles:\n",
161 nspaces(fd, 2);
162 fprintf(fd, "tile %d:\n", tileno);
163 for(compno = 0; compno < s->
ncomponents; compno++){
165 nspaces(fd, 4);
166 fprintf(fd, "component %d:\n", compno);
167 nspaces(fd, 4);
168 fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
169 comp->x0, comp->x1, comp->y0, comp->y1);
170 for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
172 nspaces(fd, 6);
173 fprintf(fd, "reslevel %d:\n", reslevelno);
174 nspaces(fd, 6);
175 fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
176 reslevel->x0, reslevel->x1, reslevel->y0,
177 reslevel->y1, reslevel->
nbands);
178 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
180 nspaces(fd, 8);
181 fprintf(fd, "band %d:\n", bandno);
182 nspaces(fd, 8);
183 fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
184 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
185 band->x0, band->x1,
186 band->y0, band->y1,
187 band->codeblock_width, band->codeblock_height,
188 band->cblknx, band->cblkny);
191 nspaces(fd, 10);
192 fprintf(fd, "prec %d:\n", precno);
193 nspaces(fd, 10);
194 fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
195 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
196 }
197 }
198 }
199 }
200 }
201 }
202 #endif
203
204 /* bitstream routines */
205
206 /** put n times val bit */
208 {
209 while (n-- > 0){
211 {
214 }
216 }
217 }
218
219 /** put n least significant bits of a number num */
221 {
222 while(--n >= 0)
224 }
225
226 /** flush the bitstream */
228 {
232 }
233 }
234
235 /* tag tree routines */
236
237 /** code the value stored in node */
239 {
241 int sp = 1, curval = 0;
242 stack[0] = node;
243
245 while(node){
248 break;
249 }
251 stack[sp++] = node;
253 }
254 while(--sp >= 0){
255 if (stack[sp]->
val >= threshold){
257 break;
258 }
261 curval = stack[
sp]->
val;
262 }
263 }
264
265 /** update the value in node */
267 {
268 int lev = 0;
271 break;
274 lev++;
275 }
276 }
277
279 {
280 int i;
281
283 return -1;
284
287 bytestream_put_be16(&s->
buf, 0);
// Rsiz
288 bytestream_put_be32(&s->
buf, s->
width);
// width
289 bytestream_put_be32(&s->
buf, s->
height);
// height
290 bytestream_put_be32(&s->
buf, 0);
// X0Siz
291 bytestream_put_be32(&s->
buf, 0);
// Y0Siz
292
295 bytestream_put_be32(&s->
buf, 0);
// XT0Siz
296 bytestream_put_be32(&s->
buf, 0);
// YT0Siz
298
299 for (i = 0; i < s->
ncomponents; i++){
// Ssiz_i XRsiz_i, YRsiz_i
300 bytestream_put_byte(&s->
buf, 7);
303 }
304 return 0;
305 }
306
308 {
310
312 return -1;
313
315 bytestream_put_be16(&s->
buf, 12);
// Lcod
316 bytestream_put_byte(&s->
buf, 0);
// Scod
317 // SGcod
318 bytestream_put_byte(&s->
buf, 0);
// progression level
319 bytestream_put_be16(&s->
buf, 1);
// num of layers
321 bytestream_put_byte(&s->
buf, 0);
// unspecified
322 }else{
323 bytestream_put_byte(&s->
buf, 0);
// unspecified
324 }
325 // SPcod
326 bytestream_put_byte(&s->
buf, codsty->
nreslevels - 1);
// num of decomp. levels
329 bytestream_put_byte(&s->
buf, 0);
// cblk style
331 return 0;
332 }
333
335 {
339
342 else // QSTY_SE
344
346 return -1;
347
349 bytestream_put_be16(&s->
buf, size);
// LQcd
352 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
353 bytestream_put_byte(&s->
buf, qntsty->
expn[i] << 3);
354 else // QSTY_SE
355 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
356 bytestream_put_be16(&s->
buf, (qntsty->
expn[i] << 11) | qntsty->
mant[i]);
357 return 0;
358 }
359
361 {
363
365 return 0;
366
368 return -1;
369
371 bytestream_put_be16(&s->
buf, size);
372 bytestream_put_be16(&s->
buf, 1);
// General use (ISO/IEC 8859-15 (Latin) values)
373
375
376 return 0;
377 }
378
380 {
382
385
387 bytestream_put_be16(&s->
buf, 10);
// Lsot
388 bytestream_put_be16(&s->
buf, tileno);
// Isot
389
391 bytestream_put_be32(&s->
buf, 0);
// Psot (filled in later)
392
393 bytestream_put_byte(&s->
buf, 0);
// TPsot
394 bytestream_put_byte(&s->
buf, 1);
// TNsot
395 return psotptr;
396 }
397
398 /**
399 * compute the sizes of tiles, resolution levels, bands, etc.
400 * allocate memory for them
401 * divide the input image into tile-components
402 */
404 {
405 int tileno, tilex, tiley, compno;
408
411
415 for (tileno = 0, tiley = 0; tiley < s->
numYtiles; tiley++)
416 for (tilex = 0; tilex < s->
numXtiles; tilex++, tileno++){
418
422 for (compno = 0; compno < s->
ncomponents; compno++){
424 int ret, i, j;
425
430 if (compno > 0)
431 for (i = 0; i < 2; i++)
432 for (j = 0; j < 2; j++)
434
436 codsty,
437 qntsty,
442 )) < 0)
443 return ret;
444 }
445 }
446 return 0;
447 }
448
450 {
451 int tileno, compno, i, y, x;
456 for (compno = 0; compno < s->
ncomponents; compno++){
462 for (y = comp->
coord[1][0]; y < comp->coord[1][1]; y++){
464 for (x = comp->
coord[0][0]; x < comp->coord[0][1]; x++)
465 *dst++ = *ptr++ - (1 << 7);
467 }
468 }
469 } else{
472
473 i = 0;
474 for (y = tile->
comp[0].
coord[1][0]; y < tile->comp[0].
coord[1][1]; y++){
476 for (x = tile->
comp[0].
coord[0][0]; x < tile->comp[0].
coord[0][1]; x++, i++){
477 for (compno = 0; compno < s->
ncomponents; compno++){
478 tile->
comp[compno].
i_data[i] = *ptr++ - (1 << 7);
479 }
480 }
482 }
483 }
484 }
485 }
486
488 {
489 int compno, reslevelno, bandno;
492
493 for (compno = 0; compno < s->
ncomponents; compno++){
494 int gbandno = 0;
495 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
496 int nbands, lev = codsty->
nreslevels - reslevelno - 1;
497 nbands = reslevelno ? 3 : 1;
498 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
499 int expn, mant = 0;
500
502 int bandpos = bandno + (reslevelno>0),
505 mant = (11 - log < 0 ? ss >> log - 11 :
ss << 11 - log) & 0x7ff;
506 expn = s->
cbps[compno] - log + 13;
507 } else
508 expn = ((bandno&2)>>1) + (reslevelno>0) + s->
cbps[compno];
509
510 qntsty->
expn[gbandno] = expn;
511 qntsty->
mant[gbandno] = mant;
512 }
513 }
514 }
515 }
516
518 {
521
525
530 << 1, 0);
531 }
532 }
533
534 /* tier-1 routines */
536 {
540 }
541
543 {
547 }
548
550 {
552 for (y0 = 0; y0 <
height; y0 += 4)
553 for (x = 0; x <
width; x++)
554 for (y = y0; y < height && y < y0+4; y++){
557 bit = t1->
data[(y) * t1->
stride + x] & mask ? 1 : 0;
559 if (bit){
560 int xorbit;
565 }
567 }
568 }
569 }
570
572 {
574 for (y0 = 0; y0 <
height; y0 += 4)
575 for (x = 0; x <
width; x++)
576 for (y = y0; y < height && y < y0+4; y++)
582 }
583 }
584
586 {
588 for (y0 = 0; y0 <
height; y0 += 4)
589 for (x = 0; x <
width; x++){
590 if (y0 + 3 < height && !(
595 {
596 // aggregation mode
597 int rlen;
598 for (rlen = 0; rlen < 4; rlen++)
600 break;
602 if (rlen == 4)
603 continue;
606 for (y = y0 + rlen; y < y0 + 4; y++){
609 if (y > y0 + rlen)
611 if (t1->
data[(y) * t1->
stride + x] & mask){
// newly significant
612 int xorbit;
617 }
618 }
620 }
621 } else{
622 for (y = y0; y < y0 + 4 && y <
height; y++){
626 if (t1->
data[(y) * t1->
stride + x] & mask){
// newly significant
627 int xorbit;
632 }
633 }
635 }
636 }
637 }
638 }
639
642 {
643 int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;
644 int64_t wmsedec = 0;
645
647
648 for (y = 0; y <
height; y++){
649 for (x = 0; x <
width; x++){
653 }
655 }
656 }
657
658 if (max == 0){
660 bpno = 0;
661 } else{
664 }
665
668
669 for (passno = 0; bpno >= 0; passno++){
670 nmsedec=0;
671
672 switch(pass_t){
673 case 0:
encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);
674 break;
676 break;
677 case 2:
encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);
678 break;
679 }
680
682 wmsedec += (int64_t)nmsedec << (2*bpno);
684
685 if (++pass_t == 3){
686 pass_t = 0;
687 bpno--;
688 }
689 }
692
693 if (passno)
695 }
696
697 /* tier-2 routines: */
698
700 {
701 if (n == 1)
703 else if (n == 2)
705 else if (n <= 5)
707 else if (n <= 36)
709 else
710 put_num(s, 0xff80 | (n-37), 16);
711 }
712
713
716 {
717 int bandno, empty = 1;
718
719 // init bitstream
722
723 // header
724
725 // is the packet empty?
726 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
729 empty = 0;
730 break;
731 }
732 }
733
735 if (empty){
737 return 0;
738 }
739
740 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
743 int yi, xi, pos;
745
748 continue;
749
751 for (xi = 0; xi < cblknw; xi++, pos++){
756 }
757 }
758
760 for (xi = 0; xi < cblknw; xi++, pos++){
761 int pad = 0, llen,
length;
763
764 if (s->
buf_end - s->
buf < 20)
// approximately
765 return -1;
766
767 // inclusion information
770 continue;
771 // zerobits information
773 // number of passes
775
778 if (llen < 0){
779 pad = -llen;
780 llen = 0;
781 }
782 // length of code block
786 }
787 }
788 }
790 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
795 int xi;
796 for (xi = 0; xi < cblknw; xi++){
800 return -1;
805 }
806 }
807 }
808 }
809 return 0;
810 }
811
813 {
814 int compno, reslevelno, ret;
817
819 // lay-rlevel-comp-pos progression
820 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
821 for (compno = 0; compno < s->
ncomponents; compno++){
822 int precno;
825 if ((ret =
encode_packet(s, reslevel, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
827 return ret;
828 }
829 }
830 }
832 return 0;
833 }
834
836 {
837 int passno, res = 0;
838 for (passno = 0; passno < cblk->
npasses; passno++){
839 int dr;
840 int64_t dd;
841
846
847 if (((dd * dwt_norm) >>
WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
848 res = passno+1;
849 }
850 return res;
851 }
852
854 {
855 int precno, compno, reslevelno, bandno, cblkno, lev;
857
858 for (compno = 0; compno < s->
ncomponents; compno++){
860
861 for (reslevelno = 0, lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
863
865 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
866 int bandpos = bandno + (reslevelno > 0);
869
872
875 }
876 }
877 }
878 }
879 }
880 }
881
883 {
884 int compno, reslevelno, bandno, ret;
887 for (compno = 0; compno < s->
ncomponents; compno++){
889
891
894 return ret;
896
897 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
899
900 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
902 Jpeg2000Prec *prec = band->
prec;
// we support only 1 precinct per band ATM in the encoder
903 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
905 y0 = yy0;
908
910 continue;
911
912 bandpos = bandno + (reslevelno > 0);
913
915 if (reslevelno == 0 || bandno == 1)
916 xx0 = 0;
917 else
919 x0 = xx0;
922
924 int y, x;
926 for (y = yy0; y < yy1; y++){
928 for (x = xx0; x < xx1; x++){
930 }
931 }
932 } else{
933 for (y = yy0; y < yy1; y++){
935 for (x = xx0; x < xx1; x++){
938 ptr++;
939 }
940 }
941 }
949 bandpos, codsty->
nreslevels - reslevelno - 1);
950 xx0 = xx1;
952 }
953 yy0 = yy1;
955 }
956 }
957 }
959 }
960
964 return ret;
966 return 0;
967 }
968
970 {
971 int tileno, compno;
973
975 for (compno = 0; compno < s->
ncomponents; compno++){
978 }
980 }
982 }
983
985 {
986 int tileno, compno;
989 for (compno = 0; compno < s->
ncomponents; compno++)
991 }
992 }
993
995 {
997 }
998
1000 const AVFrame *pict,
int *got_packet)
1001 {
1002 int tileno, ret;
1004 uint8_t *chunkstart, *jp2cstart, *jp2hstart;
1005
1007 return ret;
1008
1009 // init:
1012
1014
1016
1019
1022
1023 bytestream_put_be32(&s->
buf, 0x0000000C);
1024 bytestream_put_be32(&s->
buf, 0x6A502020);
1025 bytestream_put_be32(&s->
buf, 0x0D0A870A);
1026
1027 chunkstart = s->
buf;
1028 bytestream_put_be32(&s->
buf, 0);
1031 bytestream_put_be32(&s->
buf, 0);
1034
1036 bytestream_put_be32(&s->
buf, 0);
1038
1039 chunkstart = s->
buf;
1040 bytestream_put_be32(&s->
buf, 0);
1042 bytestream_put_be32(&s->
buf, avctx->
height);
1043 bytestream_put_be32(&s->
buf, avctx->
width);
1045 bytestream_put_byte(&s->
buf, s->
cbps[0]);
1046 bytestream_put_byte(&s->
buf, 7);
1047 bytestream_put_byte(&s->
buf, 0);
1048 bytestream_put_byte(&s->
buf, 0);
1050
1051 chunkstart = s->
buf;
1052 bytestream_put_be32(&s->
buf, 0);
1054 bytestream_put_byte(&s->
buf, 1);
1055 bytestream_put_byte(&s->
buf, 0);
1056 bytestream_put_byte(&s->
buf, 0);
1058 bytestream_put_be32(&s->
buf, 17);
1060 bytestream_put_be32(&s->
buf, 16);
1061 } else {
1062 bytestream_put_be32(&s->
buf, 18);
1063 }
1066
1068 bytestream_put_be32(&s->
buf, 0);
1070 }
1071
1073 return -1;
1076 return ret;
1078 return ret;
1079 if ((ret =
put_qcd(s, 0)) < 0)
1080 return ret;
1081 if ((ret =
put_com(s, 0)) < 0)
1082 return ret;
1083
1086 if (!(psotptr =
put_sot(s, tileno)))
1087 return -1;
1089 return -1;
1092 return ret;
1093 bytestream_put_be32(&psotptr, s->
buf - psotptr + 6);
1094 }
1096 return -1;
1098
1101
1105 *got_packet = 1;
1106
1107 return 0;
1108 }
1109
1111 {
1112 int i, ret;
1116
1119
1120 #if FF_API_PRIVATE_OPT
1125 #endif
1126
1127 // defaults:
1128 // TODO: implement setting non-standard precinct size
1136
1138
1142 }
1143
1146 else
1148
1151
1152 for (i = 0; i < 3; i++)
1154
1159 } else{ // planar YUV
1164 if (ret)
1165 return ret;
1166 }
1167
1171
1174 return ret;
1175
1177
1178 return 0;
1179 }
1180
1182 {
1184
1186 return 0;
1187 }
1188
1189 // taken from the libopenjpeg wraper so it matches
1190
1191 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
1192 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1202
1204 };
1205
1211 };
1212
1227 },
1229 };
static int getcut(Jpeg2000Cblk *cblk, int64_t lambda, int dwt_norm)
const char const char void * val
void av_cold ff_jpeg2000_init_tier1_luts(void)
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
static const char * format[]
This structure describes decoded (raw) audio or video data.
Jpeg2000TgtNode * cblkincl
static void cleanup(Jpeg2000EncoderContext *s)
#define JPEG2000_T1_SIG_NB
AVCodec ff_jpeg2000_encoder
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVCodecContext *avctx)
Jpeg2000QuantStyle qntsty
static int lut_nmsedec_ref[1<< NMSEDEC_BITS]
static av_cold int j2kenc_init(AVCodecContext *avctx)
const char * av_default_item_name(void *ptr)
Return the context name.
static int put_com(Jpeg2000EncoderContext *s, int compno)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
initialize the encoder
static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
code the value stored in node
static void tag_tree_update(Jpeg2000TgtNode *node)
update the value in node
static void update_size(uint8_t *size, const uint8_t *end)
static int getnmsedec_ref(int x, int bpno)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static int lut_nmsedec_ref0[1<< NMSEDEC_BITS]
static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, int precno, uint8_t *expn, int numgbits)
static av_cold int end(AVCodecContext *avctx)
static const AVClass j2k_class
Jpeg2000TgtNode * zerobits
static void j2k_flush(Jpeg2000EncoderContext *s)
flush the bitstream
static int init_tiles(Jpeg2000EncoderContext *s)
compute the sizes of tiles, resolution levels, bands, etc.
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
static const uint16_t mask[17]
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
static int put_cod(Jpeg2000EncoderContext *s)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
int flags
AV_CODEC_FLAG_*.
#define JPEG2000_MAX_PASSES
static void put_num(Jpeg2000EncoderContext *s, int num, int n)
put n least significant bits of a number num
const char * name
Name of the codec implementation.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static int put_siz(Jpeg2000EncoderContext *s)
static int lut_nmsedec_sig0[1<< NMSEDEC_BITS]
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static int put_qcd(Jpeg2000EncoderContext *s, int compno)
static int getnmsedec_sig(int x, int bpno)
struct Jpeg2000TgtNode * parent
static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
int width
picture width / height.
JPEG 2000 structures and defines common to encoder and decoder.
static int j2kenc_destroy(AVCodecContext *avctx)
static int ff_jpeg2000_getsigctxno(int flag, int bandno)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
uint8_t cbps[4]
bits per sample in particular components
int ff_dwt_encode(DWTContext *s, void *t)
static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
static int ff_jpeg2000_ceildivpow2(int a, int b)
static const float pred[4]
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Libavcodec external API header.
static void encode_refpass(Jpeg2000T1Context *t1, int width, int height, int *nmsedec, int bpno)
attribute_deprecated int prediction_method
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Jpeg2000CodingStyle codsty
main external API structure.
void av_cold ff_mqc_init_context_tables(void)
MQ-coder Initialize context tables (QE, NLPS, NMPS)
static void init_luts(void)
static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile, int width, int height, int bandpos, int lev)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
static const AVOption options[]
int height
image width and height
Jpeg2000ResLevel * reslevel
static enum AVPixelFormat pix_fmts[]
static int ff_jpeg2000_ceildiv(int a, int b)
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
static void reinit(Jpeg2000EncoderContext *s)
static uint8_t * put_sot(Jpeg2000EncoderContext *s, int tileno)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
common internal and external API header
static void copy_frame(Jpeg2000EncoderContext *s)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
uint16_t log2_cblk_height
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy, AVCodecContext *avctx)
static void putnumpasses(Jpeg2000EncoderContext *s, int n)
int ff_mqc_flush_to(MqcState *mqc, uint8_t *dst, int *dst_len)
#define FF_ENABLE_DEPRECATION_WARNINGS
static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
static int lut_nmsedec_sig[1<< NMSEDEC_BITS]
static int ff_jpeg2000_getrefctxno(int flag)
#define av_malloc_array(a, b)
static void init_quantization(Jpeg2000EncoderContext *s)
static const int dwt_norms[2][4][10]
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define WMSEDEC_SHIFT
must be >= 13
static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
void * av_mallocz_array(size_t nmemb, size_t size)
static int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
code bit d with context cx