| @@ -2031,13 +2031,17 @@ static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 2030 unmodified lines |
| 2031 | static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) | 2031 | static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) |
| 2032 | { | 2032 | { |
| 2033 | AVStream *st; | 2033 | AVStream *st; |
| | 2034 | HEIFItem *item = NULL; |
| 2034 | char color_parameter_type[5] = { 0 }; | 2035 | char color_parameter_type[5] = { 0 }; |
| 2035 | uint16_t color_primaries, color_trc, color_matrix; | 2036 | uint16_t color_primaries, color_trc, color_matrix; |
| 2036 | int ret; | 2037 | int ret; |
| 2037 | | 2038 | |
| 2038 | st = get_curr_st(c); | 2039 | st = get_curr_st(c); |
| 2039 | if (!st) | 2040 | if (!st) { |
| 2040 | return 0; | 2041 | item = heif_cur_item(c); |
| | 2042 | if (!item) |
| | 2043 | return 0; |
| | 2044 | } |
| 2041 | | 2045 | |
| 2042 | ret = ffio_read_size(pb, color_parameter_type, 4); | 2046 | ret = ffio_read_size(pb, color_parameter_type, 4); |
| 2043 | if (ret < 0) | 2047 | if (ret < 0) |
| @@ -2051,16 +2055,29 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 7 unmodified lines |
| 2051 | } | 2055 | } |
| 2052 | | 2056 | |
| 2053 | if (!strncmp(color_parameter_type, "prof", 4)) { | 2057 | if (!strncmp(color_parameter_type, "prof", 4)) { |
| 2054 | AVPacketSideData *sd = av_packet_side_data_new(&st->codecpar->coded_side_data, | 2058 | AVPacketSideData *sd; |
| 2055 | &st->codecpar->nb_coded_side_data, | 2059 | uint8_t *icc_profile; |
| 2056 | AV_PKT_DATA_ICC_PROFILE, | 2060 | if (st) { |
| 2057 | atom.size - 4, 0); | 2061 | sd = av_packet_side_data_new(&st->codecpar->coded_side_data, |
| 2058 | if (!sd) | 2062 | &st->codecpar->nb_coded_side_data, |
| 2059 | return AVERROR(ENOMEM); | 2063 | AV_PKT_DATA_ICC_PROFILE, |
| 2060 | ret = ffio_read_size(pb, sd->data, atom.size - 4); | 2064 | atom.size - 4, 0); |
| | 2065 | if (!sd) |
| | 2066 | return AVERROR(ENOMEM); |
| | 2067 | icc_profile = sd->data; |
| | 2068 | } else { |
| | 2069 | av_freep(&item->icc_profile); |
| | 2070 | icc_profile = item->icc_profile = av_malloc(atom.size - 4); |
| | 2071 | if (!icc_profile) { |
| | 2072 | item->icc_profile_size = 0; |
| | 2073 | return AVERROR(ENOMEM); |
| | 2074 | } |
| | 2075 | item->icc_profile_size = atom.size - 4; |
| | 2076 | } |
| | 2077 | ret = ffio_read_size(pb, icc_profile, atom.size - 4); |
| 2061 | if (ret < 0) | 2078 | if (ret < 0) |
| 2062 | return ret; | 2079 | return ret; |
| 2063 | } else { | 2080 | } else if (st) { |
| 2064 | color_primaries = avio_rb16(pb); | 2081 | color_primaries = avio_rb16(pb); |
| 2065 | color_trc = avio_rb16(pb); | 2082 | color_trc = avio_rb16(pb); |
| 2066 | color_matrix = avio_rb16(pb); | 2083 | color_matrix = avio_rb16(pb); |
| @@ -9714,8 +9731,10 @@ static int mov_read_close(AVFormatContext *s) · 7647 unmodified lines |
| 9714 | | 9731 | |
| 9715 | av_freep(&mov->aes_decrypt); | 9732 | av_freep(&mov->aes_decrypt); |
| 9716 | av_freep(&mov->chapter_tracks); | 9733 | av_freep(&mov->chapter_tracks); |
| 9717 | for (i = 0; i < mov->nb_heif_item; i++) | 9734 | for (i = 0; i < mov->nb_heif_item; i++) { |
| 9718 | av_freep(&mov->heif_item[i].name); | 9735 | av_freep(&mov->heif_item[i].name); |
| | 9736 | av_freep(&mov->heif_item[i].icc_profile); |
| | 9737 | } |
| 9719 | av_freep(&mov->heif_item); | 9738 | av_freep(&mov->heif_item); |
| 9720 | for (i = 0; i < mov->nb_heif_grid; i++) { | 9739 | for (i = 0; i < mov->nb_heif_grid; i++) { |
| 9721 | av_freep(&mov->heif_grid[i].tile_id_list); | 9740 | av_freep(&mov->heif_grid[i].tile_id_list); |
| @@ -9861,6 +9880,20 @@ fail: · 139 unmodified lines |
| 9861 | return ret; | 9880 | return ret; |
| 9862 | } | 9881 | } |
| 9863 | | 9882 | |
| | 9883 | static int set_icc_profile_from_item(AVPacketSideData **coded_side_data, int *nb_coded_side_data, |
| | 9884 | const HEIFItem *item) |
| | 9885 | { |
| | 9886 | AVPacketSideData *sd = av_packet_side_data_new(coded_side_data, nb_coded_side_data, |
| | 9887 | AV_PKT_DATA_ICC_PROFILE, |
| | 9888 | item->icc_profile_size, 0); |
| | 9889 | if (!sd) |
| | 9890 | return AVERROR(ENOMEM); |
| | 9891 | |
| | 9892 | memcpy(sd->data, item->icc_profile, item->icc_profile_size); |
| | 9893 | |
| | 9894 | return 0; |
| | 9895 | } |
| | 9896 | |
| 9864 | static int set_display_matrix_from_item(AVPacketSideData **coded_side_data, int *nb_coded_side_data, | 9897 | static int set_display_matrix_from_item(AVPacketSideData **coded_side_data, int *nb_coded_side_data, |
| 9865 | const HEIFItem *item) | 9898 | const HEIFItem *item) |
| 9866 | { | 9899 | { |
| @@ -9914,6 +9947,13 @@ static int read_image_grid(AVFormatContext *s, const HEIFGrid *grid, · 47 unmodified lines |
| 9914 | tile_grid->width = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb); | 9947 | tile_grid->width = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb); |
| 9915 | tile_grid->height = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb); | 9948 | tile_grid->height = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb); |
| 9916 | | 9949 | |
| | 9950 | /* ICC profile */ |
| | 9951 | if (item->icc_profile_size) { |
| | 9952 | int ret = set_icc_profile_from_item(&tile_grid->coded_side_data, |
| | 9953 | &tile_grid->nb_coded_side_data, item); |
| | 9954 | if (ret < 0) |
| | 9955 | return ret; |
| | 9956 | } |
| 9917 | /* rotation */ | 9957 | /* rotation */ |
| 9918 | if (item->rotation) { | 9958 | if (item->rotation) { |
| 9919 | int ret = set_display_matrix_from_item(&tile_grid->coded_side_data, | 9959 | int ret = set_display_matrix_from_item(&tile_grid->coded_side_data, |
| @@ -10021,6 +10061,14 @@ static int read_image_iovl(AVFormatContext *s, const HEIFGrid *grid, · 101 unmodified lines |
| 10021 | return ret; | 10061 | return ret; |
| 10022 | } | 10062 | } |
| 10023 | | 10063 | |
| | 10064 | /* ICC profile */ |
| | 10065 | if (item->icc_profile_size) { |
| | 10066 | int ret = set_icc_profile_from_item(&tile_grid->coded_side_data, |
| | 10067 | &tile_grid->nb_coded_side_data, item); |
| | 10068 | if (ret < 0) |
| | 10069 | return ret; |
| | 10070 | } |
| | 10071 | |
| 10024 | av_log(c->fc, AV_LOG_TRACE, "iovl: output_width %d, output_height %d\n", | 10072 | av_log(c->fc, AV_LOG_TRACE, "iovl: output_width %d, output_height %d\n", |
| 10025 | tile_grid->width, tile_grid->height); | 10073 | tile_grid->width, tile_grid->height); |
| 10026 | | 10074 | |