diff mbox

[FFmpeg-devel,3/3] avcodec/webp: add support for ICCP chunks

Message ID 20170726043124.6296-3-jamrial@gmail.com
State Accepted
Commit c220fe008c5a3f7c652dbd03ce2a58e392e59e19
Headers show

Commit Message

James Almer July 26, 2017, 4:31 a.m. UTC
Export the raw data as ICC Profile frame side data.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/webp.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Comments

Rostislav Pehlivanov July 26, 2017, 6:18 a.m. UTC | #1
On 26 July 2017 at 05:31, James Almer <jamrial@gmail.com> wrote:

> Export the raw data as ICC Profile frame side data.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/webp.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/webp.c b/libavcodec/webp.c
> index a0d4d1812d..efa864a6f1 100644
> --- a/libavcodec/webp.c
> +++ b/libavcodec/webp.c
> @@ -33,10 +33,10 @@
>   *
>   * @author James Almer <jamrial@gmail.com>
>   * Exif metadata
> + * ICC profile
>   *
>   * Unimplemented:
>   *   - Animation
> - *   - ICC profile
>   *   - XMP metadata
>   */
>
> @@ -197,6 +197,7 @@ typedef struct WebPContext {
>      uint8_t *alpha_data;                /* alpha chunk data */
>      int alpha_data_size;                /* alpha chunk data size */
>      int has_exif;                       /* set after an EXIF chunk has
> been processed */
> +    int has_iccp;                       /* set after an ICCP chunk has
> been processed */
>      int width;                          /* image width */
>      int height;                         /* image height */
>      int lossless;                       /* indicates lossless or lossy */
> @@ -1381,6 +1382,7 @@ static int webp_decode_frame(AVCodecContext *avctx,
> void *data, int *got_frame,
>      *got_frame   = 0;
>      s->has_alpha = 0;
>      s->has_exif  = 0;
> +    s->has_iccp  = 0;
>      bytestream2_init(&gb, avpkt->data, avpkt->size);
>
>      if (bytestream2_get_bytes_left(&gb) < 12)
> @@ -1514,7 +1516,27 @@ exif_end:
>              bytestream2_skip(&gb, chunk_size);
>              break;
>          }
> -        case MKTAG('I', 'C', 'C', 'P'):
> +        case MKTAG('I', 'C', 'C', 'P'): {
> +            AVFrameSideData *sd;
> +
> +            if (s->has_iccp) {
> +                av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra ICCP
> chunk\n");
> +                bytestream2_skip(&gb, chunk_size);
> +                break;
> +            }
> +            if (!(vp8x_flags & VP8X_FLAG_ICC))
> +                av_log(avctx, AV_LOG_WARNING,
> +                       "ICCP chunk present, but ICC Profile bit not set
> in the "
> +                       "VP8X header\n");
> +
> +            s->has_iccp = 1;
> +            sd = av_frame_new_side_data(p, AV_FRAME_DATA_ICC_PROFILE,
> chunk_size);
> +            if (!sd)
> +                return AVERROR(ENOMEM);
> +
> +            bytestream2_get_buffer(&gb, sd->data, chunk_size);
> +            break;
> +        }
>          case MKTAG('A', 'N', 'I', 'M'):
>          case MKTAG('A', 'N', 'M', 'F'):
>          case MKTAG('X', 'M', 'P', ' '):
> --
> 2.13.3
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Can't find anything that could go wrong here and the specs don't mention
anything special, so LGTM.
Moritz Barsnick July 26, 2017, 12:23 p.m. UTC | #2
On Wed, Jul 26, 2017 at 07:18:35 +0100, Rostislav Pehlivanov wrote:
> >   * Exif metadata
> > + * ICC profile
> 
> Can't find anything that could go wrong here and the specs don't mention
> anything special, so LGTM.

Does this perhaps imply need of a micro version bump?

Moritz
James Almer July 26, 2017, 2:35 p.m. UTC | #3
On 7/26/2017 3:18 AM, Rostislav Pehlivanov wrote:
> On 26 July 2017 at 05:31, James Almer <jamrial@gmail.com> wrote:
> 
>> Export the raw data as ICC Profile frame side data.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavcodec/webp.c | 26 ++++++++++++++++++++++++--
>>  1 file changed, 24 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/webp.c b/libavcodec/webp.c
>> index a0d4d1812d..efa864a6f1 100644
>> --- a/libavcodec/webp.c
>> +++ b/libavcodec/webp.c
>> @@ -33,10 +33,10 @@
>>   *
>>   * @author James Almer <jamrial@gmail.com>
>>   * Exif metadata
>> + * ICC profile
>>   *
>>   * Unimplemented:
>>   *   - Animation
>> - *   - ICC profile
>>   *   - XMP metadata
>>   */
>>
>> @@ -197,6 +197,7 @@ typedef struct WebPContext {
>>      uint8_t *alpha_data;                /* alpha chunk data */
>>      int alpha_data_size;                /* alpha chunk data size */
>>      int has_exif;                       /* set after an EXIF chunk has
>> been processed */
>> +    int has_iccp;                       /* set after an ICCP chunk has
>> been processed */
>>      int width;                          /* image width */
>>      int height;                         /* image height */
>>      int lossless;                       /* indicates lossless or lossy */
>> @@ -1381,6 +1382,7 @@ static int webp_decode_frame(AVCodecContext *avctx,
>> void *data, int *got_frame,
>>      *got_frame   = 0;
>>      s->has_alpha = 0;
>>      s->has_exif  = 0;
>> +    s->has_iccp  = 0;
>>      bytestream2_init(&gb, avpkt->data, avpkt->size);
>>
>>      if (bytestream2_get_bytes_left(&gb) < 12)
>> @@ -1514,7 +1516,27 @@ exif_end:
>>              bytestream2_skip(&gb, chunk_size);
>>              break;
>>          }
>> -        case MKTAG('I', 'C', 'C', 'P'):
>> +        case MKTAG('I', 'C', 'C', 'P'): {
>> +            AVFrameSideData *sd;
>> +
>> +            if (s->has_iccp) {
>> +                av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra ICCP
>> chunk\n");
>> +                bytestream2_skip(&gb, chunk_size);
>> +                break;
>> +            }
>> +            if (!(vp8x_flags & VP8X_FLAG_ICC))
>> +                av_log(avctx, AV_LOG_WARNING,
>> +                       "ICCP chunk present, but ICC Profile bit not set
>> in the "
>> +                       "VP8X header\n");
>> +
>> +            s->has_iccp = 1;
>> +            sd = av_frame_new_side_data(p, AV_FRAME_DATA_ICC_PROFILE,
>> chunk_size);
>> +            if (!sd)
>> +                return AVERROR(ENOMEM);
>> +
>> +            bytestream2_get_buffer(&gb, sd->data, chunk_size);
>> +            break;
>> +        }
>>          case MKTAG('A', 'N', 'I', 'M'):
>>          case MKTAG('A', 'N', 'M', 'F'):
>>          case MKTAG('X', 'M', 'P', ' '):
>> --
>> 2.13.3
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
> 
> Can't find anything that could go wrong here and the specs don't mention
> anything special, so LGTM.

Pushed.
diff mbox

Patch

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index a0d4d1812d..efa864a6f1 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -33,10 +33,10 @@ 
  *
  * @author James Almer <jamrial@gmail.com>
  * Exif metadata
+ * ICC profile
  *
  * Unimplemented:
  *   - Animation
- *   - ICC profile
  *   - XMP metadata
  */
 
@@ -197,6 +197,7 @@  typedef struct WebPContext {
     uint8_t *alpha_data;                /* alpha chunk data */
     int alpha_data_size;                /* alpha chunk data size */
     int has_exif;                       /* set after an EXIF chunk has been processed */
+    int has_iccp;                       /* set after an ICCP chunk has been processed */
     int width;                          /* image width */
     int height;                         /* image height */
     int lossless;                       /* indicates lossless or lossy */
@@ -1381,6 +1382,7 @@  static int webp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     *got_frame   = 0;
     s->has_alpha = 0;
     s->has_exif  = 0;
+    s->has_iccp  = 0;
     bytestream2_init(&gb, avpkt->data, avpkt->size);
 
     if (bytestream2_get_bytes_left(&gb) < 12)
@@ -1514,7 +1516,27 @@  exif_end:
             bytestream2_skip(&gb, chunk_size);
             break;
         }
-        case MKTAG('I', 'C', 'C', 'P'):
+        case MKTAG('I', 'C', 'C', 'P'): {
+            AVFrameSideData *sd;
+
+            if (s->has_iccp) {
+                av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra ICCP chunk\n");
+                bytestream2_skip(&gb, chunk_size);
+                break;
+            }
+            if (!(vp8x_flags & VP8X_FLAG_ICC))
+                av_log(avctx, AV_LOG_WARNING,
+                       "ICCP chunk present, but ICC Profile bit not set in the "
+                       "VP8X header\n");
+
+            s->has_iccp = 1;
+            sd = av_frame_new_side_data(p, AV_FRAME_DATA_ICC_PROFILE, chunk_size);
+            if (!sd)
+                return AVERROR(ENOMEM);
+
+            bytestream2_get_buffer(&gb, sd->data, chunk_size);
+            break;
+        }
         case MKTAG('A', 'N', 'I', 'M'):
         case MKTAG('A', 'N', 'M', 'F'):
         case MKTAG('X', 'M', 'P', ' '):