Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Side by Side Diff: core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/jp2.c

Issue 589243004: Update openjpeg (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Merge security fixes from openjpeg r2883 Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * The copyright in this software is being made available under the 2-clauses 2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third 3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights 4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license. 5 * are granted under this license.
6 * 6 *
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq 8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens 9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren 10 * Copyright (c) 2002-2003, Yannick Verschueren
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 852
853 channel_size = color->jp2_pclr->channel_size; 853 channel_size = color->jp2_pclr->channel_size;
854 channel_sign = color->jp2_pclr->channel_sign; 854 channel_sign = color->jp2_pclr->channel_sign;
855 entries = color->jp2_pclr->entries; 855 entries = color->jp2_pclr->entries;
856 cmap = color->jp2_pclr->cmap; 856 cmap = color->jp2_pclr->cmap;
857 nr_channels = color->jp2_pclr->nr_channels; 857 nr_channels = color->jp2_pclr->nr_channels;
858 858
859 old_comps = image->comps; 859 old_comps = image->comps;
860 new_comps = (opj_image_comp_t*) 860 new_comps = (opj_image_comp_t*)
861 opj_malloc(nr_channels * sizeof(opj_image_comp_t)); 861 opj_malloc(nr_channels * sizeof(opj_image_comp_t));
862 862 » if (!new_comps) {
863 » » /* FIXME no error code for opj_jp2_apply_pclr */
864 » » /* FIXME event manager error callback */
865 » » return;
866 » }
863 for(i = 0; i < nr_channels; ++i) { 867 for(i = 0; i < nr_channels; ++i) {
864 pcol = cmap[i].pcol; cmp = cmap[i].cmp; 868 pcol = cmap[i].pcol; cmp = cmap[i].cmp;
865 869
866 /* Direct use */ 870 /* Direct use */
867 if(cmap[i].mtyp == 0){ 871 if(cmap[i].mtyp == 0){
868 assert( pcol == 0 ); 872 assert( pcol == 0 );
869 new_comps[i] = old_comps[cmp]; 873 new_comps[i] = old_comps[cmp];
870 } else { 874 } else {
871 assert( i == pcol ); 875 assert( i == pcol );
872 new_comps[pcol] = old_comps[cmp]; 876 new_comps[pcol] = old_comps[cmp];
873 } 877 }
874 878
875 /* Palette mapping: */ 879 /* Palette mapping: */
876 new_comps[i].data = (OPJ_INT32*) 880 new_comps[i].data = (OPJ_INT32*)
877 opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32)); 881 opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
882 if (!new_comps[i].data) {
883 opj_free(new_comps);
884 new_comps = NULL;
885 /* FIXME no error code for opj_jp2_apply_pclr */
886 /* FIXME event manager error callback */
887 return;
888 }
878 new_comps[i].prec = channel_size[i]; 889 new_comps[i].prec = channel_size[i];
879 new_comps[i].sgnd = channel_sign[i]; 890 new_comps[i].sgnd = channel_sign[i];
880 } 891 }
881 892
882 top_k = color->jp2_pclr->nr_entries - 1; 893 top_k = color->jp2_pclr->nr_entries - 1;
883 894
884 for(i = 0; i < nr_channels; ++i) { 895 for(i = 0; i < nr_channels; ++i) {
885 /* Palette mapping: */ 896 /* Palette mapping: */
886 cmp = cmap[i].cmp; pcol = cmap[i].pcol; 897 cmp = cmap[i].cmp; pcol = cmap[i].pcol;
887 src = old_comps[cmp].data; 898 src = old_comps[cmp].data;
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 1610
1600 /* further JP2 initializations go here */ 1611 /* further JP2 initializations go here */
1601 jp2->color.jp2_has_colr = 0; 1612 jp2->color.jp2_has_colr = 0;
1602 jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR _CMAP_CDEF_FLAG; 1613 jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR _CMAP_CDEF_FLAG;
1603 } 1614 }
1604 1615
1605 /* ----------------------------------------------------------------------- */ 1616 /* ----------------------------------------------------------------------- */
1606 /* JP2 encoder interface */ 1617 /* JP2 encoder interface */
1607 /* ----------------------------------------------------------------------- */ 1618 /* ----------------------------------------------------------------------- */
1608 1619
1609 void opj_jp2_setup_encoder(» opj_jp2_t *jp2, 1620 OPJ_BOOL opj_jp2_setup_encoder(»opj_jp2_t *jp2,
1610 opj_cparameters_t *parameters, 1621 opj_cparameters_t *parameters,
1611 opj_image_t *image, 1622 opj_image_t *image,
1612 opj_event_mgr_t * p_manager) 1623 opj_event_mgr_t * p_manager)
1613 { 1624 {
1614 OPJ_UINT32 i; 1625 OPJ_UINT32 i;
1615 OPJ_UINT32 depth_0; 1626 OPJ_UINT32 depth_0;
1616 OPJ_UINT32 sign; 1627 OPJ_UINT32 sign;
1617 1628
1618 if(!jp2 || !parameters || !image) 1629 if(!jp2 || !parameters || !image)
1619 » » return; 1630 » » return OPJ_FALSE;
1620 1631
1621 /* setup the J2K codec */ 1632 /* setup the J2K codec */
1622 /* ------------------- */ 1633 /* ------------------- */
1623 1634
1624 /* Check if number of components respects standard */ 1635 /* Check if number of components respects standard */
1625 if (image->numcomps < 1 || image->numcomps > 16384) { 1636 if (image->numcomps < 1 || image->numcomps > 16384) {
1626 opj_event_msg(p_manager, EVT_ERROR, "Invalid number of component s specified while setting up JP2 encoder\n"); 1637 opj_event_msg(p_manager, EVT_ERROR, "Invalid number of component s specified while setting up JP2 encoder\n");
1627 » » return; 1638 » » return OPJ_FALSE;
1628 } 1639 }
1629 1640
1630 » opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager ); 1641 » if (opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager ) == OP J_FALSE) {
1642 » » return OPJ_FALSE;
1643 » }
1631 1644
1632 /* setup the JP2 codec */ 1645 /* setup the JP2 codec */
1633 /* ------------------- */ 1646 /* ------------------- */
1634 1647
1635 /* Profile box */ 1648 /* Profile box */
1636 1649
1637 jp2->brand = JP2_JP2; /* BR */ 1650 jp2->brand = JP2_JP2; /* BR */
1638 jp2->minversion = 0; /* MinV */ 1651 jp2->minversion = 0; /* MinV */
1639 jp2->numcl = 1; 1652 jp2->numcl = 1;
1640 jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32)); 1653 jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
1641 if (!jp2->cl){ 1654 » if (!jp2->cl){
1642 jp2->cl = NULL; 1655 » » jp2->cl = NULL;
1643 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP 2 encoder\n"); 1656 » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setu p the JP2 encoder\n");
1644 return; 1657 » » return OPJ_FALSE;
1645 } 1658 » }
1646 jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */ 1659 jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
1647 1660
1648 /* Image Header box */ 1661 /* Image Header box */
1649 1662
1650 jp2->numcomps = image->numcomps; /* NC */ 1663 jp2->numcomps = image->numcomps; /* NC */
1651 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp 2_comps_t)); 1664 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp 2_comps_t));
1652 if (!jp2->comps) { 1665 » if (!jp2->comps) {
1653 jp2->comps = NULL; 1666 » » jp2->comps = NULL;
1654 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP 2 encoder\n"); 1667 » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setu p the JP2 encoder\n");
1655 return; 1668 » » /* Memory of jp2->cl will be freed by opj_jp2_destroy */
1656 } 1669 » » return OPJ_FALSE;
1670 » }
1657 1671
1658 jp2->h = image->y1 - image->y0; /* HEIGHT */ 1672 jp2->h = image->y1 - image->y0; /* HEIGHT */
1659 jp2->w = image->x1 - image->x0; /* WIDTH */ 1673 jp2->w = image->x1 - image->x0; /* WIDTH */
1660 /* BPC */ 1674 /* BPC */
1661 depth_0 = image->comps[0].prec - 1; 1675 depth_0 = image->comps[0].prec - 1;
1662 sign = image->comps[0].sgnd; 1676 sign = image->comps[0].sgnd;
1663 jp2->bpc = depth_0 + (sign << 7); 1677 jp2->bpc = depth_0 + (sign << 7);
1664 for (i = 1; i < image->numcomps; i++) { 1678 for (i = 1; i < image->numcomps; i++) {
1665 OPJ_UINT32 depth = image->comps[i].prec - 1; 1679 OPJ_UINT32 depth = image->comps[i].prec - 1;
1666 sign = image->comps[i].sgnd; 1680 sign = image->comps[i].sgnd;
(...skipping 22 matching lines...) Expand all
1689 jp2->enumcs = 17; /* greyscale */ 1703 jp2->enumcs = 17; /* greyscale */
1690 else if (image->color_space == 3) 1704 else if (image->color_space == 3)
1691 jp2->enumcs = 18; /* YUV */ 1705 jp2->enumcs = 18; /* YUV */
1692 } 1706 }
1693 1707
1694 1708
1695 jp2->precedence = 0; /* PRECEDENCE */ 1709 jp2->precedence = 0; /* PRECEDENCE */
1696 jp2->approx = 0; /* APPROX */ 1710 jp2->approx = 0; /* APPROX */
1697 1711
1698 jp2->jpip_on = parameters->jpip_on; 1712 jp2->jpip_on = parameters->jpip_on;
1713
1714 return OPJ_TRUE;
1699 } 1715 }
1700 1716
1701 OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2, 1717 OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
1702 opj_stream_private_t *stream, 1718 opj_stream_private_t *stream,
1703 opj_event_mgr_t * p_manager) 1719 opj_event_mgr_t * p_manager)
1704 { 1720 {
1705 return opj_j2k_encode(jp2->j2k, stream, p_manager); 1721 return opj_j2k_encode(jp2->j2k, stream, p_manager);
1706 } 1722 }
1707 1723
1708 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, 1724 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 len = opj_stream_tell(cio)-lenp; 2832 len = opj_stream_tell(cio)-lenp;
2817 opj_stream_skip(cio, lenp, p_manager); 2833 opj_stream_skip(cio, lenp, p_manager);
2818 opj_write_bytes(l_data_header,len,4);/* L */ 2834 opj_write_bytes(l_data_header,len,4);/* L */
2819 opj_stream_write_data(cio,l_data_header,4,p_manager); 2835 opj_stream_write_data(cio,l_data_header,4,p_manager);
2820 opj_stream_seek(cio, lenp+len,p_manager); 2836 opj_stream_seek(cio, lenp+len,p_manager);
2821 2837
2822 return len; 2838 return len;
2823 } 2839 }
2824 #endif 2840 #endif
2825 #endif /* USE_JPIP */ 2841 #endif /* USE_JPIP */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698