[FFmpeg-devel] libavcodec : add psd image file decoder

Michael Niedermayer michael at niedermayer.cc
Tue Aug 2 14:28:26 EEST 2016


On Tue, Jul 26, 2016 at 03:07:37PM +0200, Martin Vignali wrote:
> Sorry, forgot one out of array issue in the previous patch
> 
> Correct patch in attach
> 
> Martin

>  Makefile     |    1 +
>  allformats.c |    1 +
>  img2dec.c    |   33 +++++++++++++++++++++++++++++++++
>  3 files changed, 35 insertions(+)
> 2fe2603c097f52ade37e93ab20e7d7c7c9cf3920  0001-libavformat-add-Photoshop-PSD-file.patch
> From 99c60ace42f29b681fc8e5729f4b0081a204cfe5 Mon Sep 17 00:00:00 2001
> From: Martin Vignali <martin.vignali at gmail.com>
> Date: Tue, 26 Jul 2016 15:05:57 +0200
> Subject: [PATCH 1/2] libavformat : add Photoshop PSD file.
> 
> ---
>  libavformat/Makefile     |  1 +
>  libavformat/allformats.c |  1 +
>  libavformat/img2dec.c    | 33 +++++++++++++++++++++++++++++++++
>  3 files changed, 35 insertions(+)
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index c49f9de..a79ca8f 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -234,6 +234,7 @@ OBJS-$(CONFIG_IMAGE_PGM_PIPE_DEMUXER)     += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_PICTOR_PIPE_DEMUXER)  += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_PNG_PIPE_DEMUXER)     += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_PPM_PIPE_DEMUXER)     += img2dec.o img2.o
> +OBJS-$(CONFIG_IMAGE_PSD_PIPE_DEMUXER)     += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_QDRAW_PIPE_DEMUXER)   += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_SGI_PIPE_DEMUXER)     += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_SUNRAST_PIPE_DEMUXER) += img2dec.o img2.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index d490cc4..3d631e1 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -364,6 +364,7 @@ void av_register_all(void)
>      REGISTER_DEMUXER (IMAGE_PICTOR_PIPE,     image_pictor_pipe);
>      REGISTER_DEMUXER (IMAGE_PNG_PIPE,        image_png_pipe);
>      REGISTER_DEMUXER (IMAGE_PPM_PIPE,        image_ppm_pipe);
> +    REGISTER_DEMUXER (IMAGE_PSD_PIPE,        image_psd_pipe);
>      REGISTER_DEMUXER (IMAGE_QDRAW_PIPE,      image_qdraw_pipe);
>      REGISTER_DEMUXER (IMAGE_SGI_PIPE,        image_sgi_pipe);
>      REGISTER_DEMUXER (IMAGE_SUNRAST_PIPE,    image_sunrast_pipe);
> diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> index 9d6796f..c23f379 100644
> --- a/libavformat/img2dec.c
> +++ b/libavformat/img2dec.c
> @@ -821,6 +821,38 @@ static int png_probe(AVProbeData *p)
>      return 0;
>  }
>  
> +static int psd_probe(AVProbeData *p)
> +{
> +    const uint8_t *b = p->buf;
> +    int ret = 0;
> +    uint16_t color_mode;
> +
> +    if (AV_RL32(b) == MKTAG('8','B','P','S')) {
> +        ret += 1;
> +    } else {
> +        return 0;
> +    }
> +
> +    if ((b[4] == 0) && (b[5] == 1)) {/* version 1 is PSD, version 2 is PSB */
> +        ret += 1;
> +    } else {
> +        return 0;
> +    }
> +
> +    if ((AV_RL32(b+6) == 0) && (AV_RL16(b+10) == 0))/* reserved must be 0 */
> +        ret += 1;

> +    if (p->buf_size >= 26) {

I think you should fail probe with less than 26 bytes
or are there smaller files that can be valid ?


[...]

>  Changelog              |    1 
>  doc/general.texi       |    2 
>  libavcodec/Makefile    |    1 
>  libavcodec/allcodecs.c |    1 
>  libavcodec/avcodec.h   |    1 
>  libavcodec/psd.c       |  402 +++++++++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 408 insertions(+)
> a29c64726b8c030e370c552fc6535d8a48fca550  0002-libavcodec-add-decoder-for-Photoshop-PSD-image-file.patch
> From df3cfa66fa71e512125526c226c1629f00949409 Mon Sep 17 00:00:00 2001
> From: Martin Vignali <martin.vignali at gmail.com>
> Date: Tue, 26 Jul 2016 15:06:10 +0200
> Subject: [PATCH 2/2] libavcodec : add decoder for Photoshop PSD image file.
> 
> Decode the Image Data Section (who contain merge picture).
> Support RGB/A and Grayscale/A in 8bits and 16 bits by channel.
> Support uncompress and rle compression in Image Data Section.
> ---
>  Changelog              |   1 +
>  doc/general.texi       |   2 +
>  libavcodec/Makefile    |   1 +
>  libavcodec/allcodecs.c |   1 +
>  libavcodec/avcodec.h   |   1 +
>  libavcodec/psd.c       | 402 +++++++++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 408 insertions(+)
>  create mode 100644 libavcodec/psd.c
> 

> diff --git a/Changelog b/Changelog
> index 99cdb80..f41d2b6 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -3,6 +3,7 @@ releases are sorted from youngest to oldest.
>  
>  version <next>:
>  
> +- PSD Decoder

this is not based on git master


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160802/cdd78e98/attachment.sig>


More information about the ffmpeg-devel mailing list