Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-08-06 Thread Nicolas George
Le duodi 12 thermidor, an CCXXV, Paras Chadha a écrit :
> > > +if (strncmp(keyword, "BITPIX", 6)) {
> > > +av_log(avcl, AV_LOG_ERROR, "expected BITPIX keyword,
> > found %s = %s\n", keyword, value);
> > > +return AVERROR_INVALIDDATA;
> > > +}
> > > +
> >
> > > +if (sscanf(value, "%d", &header->bitpix) != 1) {
> > > +av_log(avcl, AV_LOG_ERROR, "invalid value of BITPIX
> > keyword, %s = %s\n", keyword, value);
> > > +return AVERROR_INVALIDDATA;
> > > +}

> Do you mean i should add checking of keyword and value in single if using
> && ?

No, I meant that you could have a function or a macro that parses the
value as an integer, prints the error and returns, all in one step.
Possibly the keyword in the same step, depending on how many you have.

> Yes, i know about this. This version is the correct one to use. Actually,
> for the image, ascii table extensions these keywords should be present
> after NAXISN only and in that order only. But in binary table and groups
> structure there may be other keywords after NAXISN and before PCOUNT,
> GCOUNT. Here it will enter PCOUNT state only when image extension is there.
> Otherwise these keywords will be parsed in the REST state.

You do not need to validate the order of the fields in the demuxer: you
can just parse everything in REST. If it comes in the correct order, it
works, if it comes in the incorrect order, it works too and that is not
a problem.

> Since a common function is made, i have to include them here too for ascii,
> binary table extensions etc. That is why they are checked only when image
> extension is not there.

There is no need to parse them twice: just store the value in an
integer, and once it is finished check that integer only if needed.

> ok, so should i use SIZE_MAX = INT_MAX - 2879 ?

See my other mail: it depends on the type in the computation.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-30 Thread Paras Chadha
On Fri, Jul 28, 2017 at 3:26 PM, Nicolas George  wrote:

> Le decadi 10 thermidor, an CCXXV, Paras Chadha a écrit :
> > Signed-off-by: Paras Chadha 
> > ---
> >  Changelog   |   1 +
> >  doc/general.texi|   2 +
> >  libavcodec/Makefile |   1 +
> >  libavcodec/allcodecs.c  |   1 +
> >  libavcodec/avcodec.h|   1 +
> >  libavcodec/codec_desc.c |   7 +
> >  libavcodec/fits.h   |  79 +++
> >  libavcodec/fitsdec.c| 550 ++
> ++
> >  libavcodec/version.h|   2 +-
> >  9 files changed, 643 insertions(+), 1 deletion(-)
> >  create mode 100644 libavcodec/fits.h
> >  create mode 100644 libavcodec/fitsdec.c
> >
> > diff --git a/Changelog b/Changelog
> > index 187ae79..d9af2b9 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -29,6 +29,7 @@ version :
> >  - limiter video filter
> >  - libvmaf video filter
> >  - Dolby E decoder and SMPTE 337M demuxer
> > +- FITS demuxer and decoder
> >
> >  version 3.3:
> >  - CrystalHD decoder moved to new decode API
> > diff --git a/doc/general.texi b/doc/general.texi
> > index 036c8c2..01402cb 100644
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -592,6 +592,8 @@ following image formats are supported:
> >  @tab Digital Picture Exchange
> >  @item EXR  @tab   @tab X
> >  @tab OpenEXR
> > +@item FITS @tab   @tab X
> > +@tab Flexible Image Transport System
> >  @item JPEG @tab X @tab X
> >  @tab Progressive JPEG is not supported.
> >  @item JPEG 2000@tab X @tab X
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index 357fa1a..5348ed9 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o
> ffv1.o
> >  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
> >  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
> >  OBJS-$(CONFIG_FIC_DECODER) += fic.o
>
> > +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
>
> The avpriv part is required unconditionally. You need to either split it
> into a separate file, or compile this file always and add "#if
> FITS_DECODER" around the optional parts.
>

okay


>
> >  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
> >  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o
> vorbis_data.o
> >  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > index 4712592..8678ac2 100644
> > --- a/libavcodec/allcodecs.c
> > +++ b/libavcodec/allcodecs.c
> > @@ -192,6 +192,7 @@ static void register_all(void)
> >  REGISTER_ENCDEC (FFV1,  ffv1);
> >  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
> >  REGISTER_DECODER(FIC,   fic);
> > +REGISTER_DECODER(FITS,  fits);
> >  REGISTER_ENCDEC (FLASHSV,   flashsv);
> >  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
> >  REGISTER_DECODER(FLIC,  flic);
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index c594993..b28002f 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -447,6 +447,7 @@ enum AVCodecID {
> >  AV_CODEC_ID_SRGC,
> >  AV_CODEC_ID_SVG,
> >  AV_CODEC_ID_GDV,
> > +AV_CODEC_ID_FITS,
> >
> >  /* various PCM "codecs" */
> >  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at
> the start of audio codecs
> > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> > index 6f43b68..2fea680 100644
> > --- a/libavcodec/codec_desc.c
> > +++ b/libavcodec/codec_desc.c
> > @@ -1464,6 +1464,13 @@ static const AVCodecDescriptor
> codec_descriptors[] = {
> >   AV_CODEC_PROP_LOSSLESS,
> >  },
> >  {
> > +.id= AV_CODEC_ID_FITS,
> > +.type  = AVMEDIA_TYPE_VIDEO,
> > +.name  = "fits",
> > +.long_name = NULL_IF_CONFIG_SMALL("FITS image"),
> > +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
> > +},
> > +{
> >  .id= AV_CODEC_ID_GIF,
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .name  = "gif",
> > diff --git a/libavcodec/fits.h b/libavcodec/fits.h
> > new file mode 100644
> > index 000..45d1ae2
> > --- /dev/null
> > +++ b/libavcodec/fits.h
> > @@ -0,0 +1,79 @@
> > +/*
> > + * FITS image format
> > + * Copyright (c) 2017 Paras Chadha
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR P

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-28 Thread Nicolas George
Le decadi 10 thermidor, an CCXXV, Paras Chadha a écrit :
> Signed-off-by: Paras Chadha 
> ---
>  Changelog   |   1 +
>  doc/general.texi|   2 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   7 +
>  libavcodec/fits.h   |  79 +++
>  libavcodec/fitsdec.c| 550 
> 
>  libavcodec/version.h|   2 +-
>  9 files changed, 643 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/fits.h
>  create mode 100644 libavcodec/fitsdec.c
> 
> diff --git a/Changelog b/Changelog
> index 187ae79..d9af2b9 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -29,6 +29,7 @@ version :
>  - limiter video filter
>  - libvmaf video filter
>  - Dolby E decoder and SMPTE 337M demuxer
> +- FITS demuxer and decoder
>  
>  version 3.3:
>  - CrystalHD decoder moved to new decode API
> diff --git a/doc/general.texi b/doc/general.texi
> index 036c8c2..01402cb 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -592,6 +592,8 @@ following image formats are supported:
>  @tab Digital Picture Exchange
>  @item EXR  @tab   @tab X
>  @tab OpenEXR
> +@item FITS @tab   @tab X
> +@tab Flexible Image Transport System
>  @item JPEG @tab X @tab X
>  @tab Progressive JPEG is not supported.
>  @item JPEG 2000@tab X @tab X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 357fa1a..5348ed9 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o ffv1.o
>  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
>  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
>  OBJS-$(CONFIG_FIC_DECODER) += fic.o

> +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o

The avpriv part is required unconditionally. You need to either split it
into a separate file, or compile this file always and add "#if
FITS_DECODER" around the optional parts.

>  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
>  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o 
> vorbis_data.o
>  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 4712592..8678ac2 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -192,6 +192,7 @@ static void register_all(void)
>  REGISTER_ENCDEC (FFV1,  ffv1);
>  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
>  REGISTER_DECODER(FIC,   fic);
> +REGISTER_DECODER(FITS,  fits);
>  REGISTER_ENCDEC (FLASHSV,   flashsv);
>  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
>  REGISTER_DECODER(FLIC,  flic);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index c594993..b28002f 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -447,6 +447,7 @@ enum AVCodecID {
>  AV_CODEC_ID_SRGC,
>  AV_CODEC_ID_SVG,
>  AV_CODEC_ID_GDV,
> +AV_CODEC_ID_FITS,
>  
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 6f43b68..2fea680 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1464,6 +1464,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
>   AV_CODEC_PROP_LOSSLESS,
>  },
>  {
> +.id= AV_CODEC_ID_FITS,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "fits",
> +.long_name = NULL_IF_CONFIG_SMALL("FITS image"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
> +},
> +{
>  .id= AV_CODEC_ID_GIF,
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .name  = "gif",
> diff --git a/libavcodec/fits.h b/libavcodec/fits.h
> new file mode 100644
> index 000..45d1ae2
> --- /dev/null
> +++ b/libavcodec/fits.h
> @@ -0,0 +1,79 @@
> +/*
> + * FITS image format
> + * Copyright (c) 2017 Paras Chadha
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> U

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-21 Thread Nicolas George
Le duodi 2 thermidor, an CCXXV, Paras Chadha a écrit :
> +int64_t t, size = 1;

> +if (!strncmp(keyword, "BLANK", 5) && sscanf(value, "%ld", &t) == 1) {

This %ld is not the correct format specifier for int64_t. It would be
something like %"SCNd64".

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-20 Thread Paras Chadha
On Thu, Jul 20, 2017 at 11:19 PM, Nicolas George  wrote:

> Hi.
>
> Le duodi 2 thermidor, an CCXXV, Paras Chadha a écrit :
> > +size = abs(header->bitpix) >> 3;
>
> > +size *= header->naxisn[i];
>
> Can you explain why PCOUNT and GCOUNT are not taken into account here
> while they are taken into account in the demuxer?
>

It is because for image extensions, PCOUNT = 0 and GCOUNT = 1 are mandatory
in the header according to the standard. These keywords are not even
mandatory in the header of first image.
Anyways as i have told before, it is not necessary FITS file will contain
an image always. It is a general data storage and transport format too. It
supports various extensions - ASCII table extension and binary table
extension that are used to store and transport data. After that there is
something called Random Groups structure which is also used for the same
purpose. PCOUNT and GCOUNT can affect the size of data in those extensions.
In demuxer, i am skipping over these extensions and only sending the images
to the decoder. So, these keywords are taken into account in demuxer but
not in decoder.


>
> Regards,
>
> --
>   Nicolas George
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-20 Thread Nicolas George
Hi.

Le duodi 2 thermidor, an CCXXV, Paras Chadha a écrit :
> +size = abs(header->bitpix) >> 3;

> +size *= header->naxisn[i];

Can you explain why PCOUNT and GCOUNT are not taken into account here
while they are taken into account in the demuxer?

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-04 Thread Paras Chadha
On Tue, Jul 4, 2017 at 2:57 PM, Nicolas George  wrote:

> Le quartidi 14 messidor, an CCXXV, Paras Chadha a écrit :
> > Made all the changes suggested
> > Added a new function which reads a header FITS line safely. It also
> makes it more modular
> > Added an option for the user to enter the value to be used in place of
> BLANK pixels
> > Refactored code using macros to make it short
>
> Note: this is the commit message, it is there to stay, so it must
> contain information about the whole commit, not its differences with a
> previous draft of it. These, and any other kind of comment, belong
> between the first triple-dash line and the beginning of the actual diff,
> where Git places the shortstats of the diff.
>
> Also, lines should be split way below 80 characters.
>

Okay, will remember this the next time


>
> >
> > Signed-off-by: Paras Chadha 
> > ---
> >  Changelog   |   1 +
> >  doc/general.texi|   2 +
> >  libavcodec/Makefile |   1 +
> >  libavcodec/allcodecs.c  |   1 +
> >  libavcodec/avcodec.h|   1 +
> >  libavcodec/codec_desc.c |   8 +
> >  libavcodec/fitsdec.c| 505 ++
> ++
> >  libavcodec/version.h|   4 +-
> >  libavformat/img2.c  |   1 +
> >  9 files changed, 522 insertions(+), 2 deletions(-)
> >  create mode 100644 libavcodec/fitsdec.c
>
> Note: before reviewing the code, I think the boundary between the
> demuxer and the decoder needs to be properly defined. See my comments in
> this mail, near the end:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2017-July/213157.html


okay


>
>
> Regards,
>
> --
>   Nicolas George
>



-- 
Have a Nice Day !
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-04 Thread Nicolas George
Le quartidi 14 messidor, an CCXXV, Paras Chadha a écrit :
> Made all the changes suggested
> Added a new function which reads a header FITS line safely. It also makes it 
> more modular
> Added an option for the user to enter the value to be used in place of BLANK 
> pixels
> Refactored code using macros to make it short

Note: this is the commit message, it is there to stay, so it must
contain information about the whole commit, not its differences with a
previous draft of it. These, and any other kind of comment, belong
between the first triple-dash line and the beginning of the actual diff,
where Git places the shortstats of the diff.

Also, lines should be split way below 80 characters.

> 
> Signed-off-by: Paras Chadha 
> ---
>  Changelog   |   1 +
>  doc/general.texi|   2 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   8 +
>  libavcodec/fitsdec.c| 505 
> 
>  libavcodec/version.h|   4 +-
>  libavformat/img2.c  |   1 +
>  9 files changed, 522 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/fitsdec.c

Note: before reviewing the code, I think the boundary between the
demuxer and the decoder needs to be properly defined. See my comments in
this mail, near the end:
https://ffmpeg.org/pipermail/ffmpeg-devel/2017-July/213157.html

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-02 Thread Paras Chadha
On Fri, Jun 30, 2017 at 6:38 PM, Nicolas George  wrote:

> Hi. A few technical / cosmetic remarks below. I do not know the FITS
> format itself more than in passing.
>
> Le duodi 12 messidor, an CCXXV, Paras Chadha a écrit :
> > Made the changes suggested above
> >
> > Signed-off-by: Paras Chadha 
> > ---
> >  Changelog   |   1 +
> >  doc/general.texi|   2 +
> >  libavcodec/Makefile |   1 +
> >  libavcodec/allcodecs.c  |   1 +
> >  libavcodec/avcodec.h|   1 +
> >  libavcodec/codec_desc.c |   8 +
> >  libavcodec/fitsdec.c| 580 ++
> ++
> >  libavcodec/version.h|   4 +-
> >  libavformat/img2.c  |   1 +
> >  9 files changed, 597 insertions(+), 2 deletions(-)
> >  create mode 100644 libavcodec/fitsdec.c
> >
> > diff --git a/Changelog b/Changelog
> > index a8726c6..2c2bdec 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -26,6 +26,7 @@ version :
> >--x86asmexe=yasm to configure to restore the old behavior.
> >  - additional frame format support for Interplay MVE movies
> >  - support for decoding through D3D11VA in ffmpeg
> > +- FITS demuxer and decoder
> >
> >  version 3.3:
> >  - CrystalHD decoder moved to new decode API
> > diff --git a/doc/general.texi b/doc/general.texi
> > index 8f582d5..c00ce32 100644
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -591,6 +591,8 @@ following image formats are supported:
> >  @tab Digital Picture Exchange
> >  @item EXR  @tab   @tab X
> >  @tab OpenEXR
> > +@item FITS @tab   @tab X
> > +@tab Flexible Image Transport System
> >  @item JPEG @tab X @tab X
> >  @tab Progressive JPEG is not supported.
> >  @item JPEG 2000@tab X @tab X
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index b440a00..729e95e 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o
> ffv1.o
> >  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
> >  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
> >  OBJS-$(CONFIG_FIC_DECODER) += fic.o
> > +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
> >  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
> >  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o
> vorbis_data.o
> >  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > index 0243f47..a4cfd80 100644
> > --- a/libavcodec/allcodecs.c
> > +++ b/libavcodec/allcodecs.c
> > @@ -192,6 +192,7 @@ static void register_all(void)
> >  REGISTER_ENCDEC (FFV1,  ffv1);
> >  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
> >  REGISTER_DECODER(FIC,   fic);
> > +REGISTER_DECODER(FITS,  fits);
> >  REGISTER_ENCDEC (FLASHSV,   flashsv);
> >  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
> >  REGISTER_DECODER(FLIC,  flic);
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index b697afa..8eba460 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -447,6 +447,7 @@ enum AVCodecID {
> >  AV_CODEC_ID_SRGC,
> >  AV_CODEC_ID_SVG,
> >  AV_CODEC_ID_GDV,
> > +AV_CODEC_ID_FITS,
> >
> >  /* various PCM "codecs" */
> >  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at
> the start of audio codecs
> > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> > index cf1246e..0112517 100644
> > --- a/libavcodec/codec_desc.c
> > +++ b/libavcodec/codec_desc.c
> > @@ -1464,6 +1464,14 @@ static const AVCodecDescriptor
> codec_descriptors[] = {
> >   AV_CODEC_PROP_LOSSLESS,
> >  },
> >  {
> > +.id= AV_CODEC_ID_FITS,
> > +.type  = AVMEDIA_TYPE_VIDEO,
> > +.name  = "fits",
> > +.long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport
> System"),
> > +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> > + AV_CODEC_PROP_LOSSLESS,
> > +},
> > +{
> >  .id= AV_CODEC_ID_GIF,
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .name  = "gif",
> > diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> > new file mode 100644
> > index 000..4eaf3c8
> > --- /dev/null
> > +++ b/libavcodec/fitsdec.c
> > @@ -0,0 +1,580 @@
> > +/*
> > + * FITS image decoder
> > + * Copyright (c) 2017 Paras Chadha
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the impli

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-30 Thread Moritz Barsnick
On Fri, Jun 30, 2017 at 15:08:17 +0200, Nicolas George wrote:
> > + * function calculates the data_min and data_max values from the data.
> 
> The style for doxygen comments is impersonal verbs: "Calculate the ...".

I don't want to nitpick, and I *may* be wrong, but the grammar freak in
me thinks the suggested form is actually imperative.

Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-30 Thread Nicolas George
Hi. A few technical / cosmetic remarks below. I do not know the FITS
format itself more than in passing.

Le duodi 12 messidor, an CCXXV, Paras Chadha a écrit :
> Made the changes suggested above
> 
> Signed-off-by: Paras Chadha 
> ---
>  Changelog   |   1 +
>  doc/general.texi|   2 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   8 +
>  libavcodec/fitsdec.c| 580 
> 
>  libavcodec/version.h|   4 +-
>  libavformat/img2.c  |   1 +
>  9 files changed, 597 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/fitsdec.c
> 
> diff --git a/Changelog b/Changelog
> index a8726c6..2c2bdec 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -26,6 +26,7 @@ version :
>--x86asmexe=yasm to configure to restore the old behavior.
>  - additional frame format support for Interplay MVE movies
>  - support for decoding through D3D11VA in ffmpeg
> +- FITS demuxer and decoder
> 
>  version 3.3:
>  - CrystalHD decoder moved to new decode API
> diff --git a/doc/general.texi b/doc/general.texi
> index 8f582d5..c00ce32 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -591,6 +591,8 @@ following image formats are supported:
>  @tab Digital Picture Exchange
>  @item EXR  @tab   @tab X
>  @tab OpenEXR
> +@item FITS @tab   @tab X
> +@tab Flexible Image Transport System
>  @item JPEG @tab X @tab X
>  @tab Progressive JPEG is not supported.
>  @item JPEG 2000@tab X @tab X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index b440a00..729e95e 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o ffv1.o
>  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
>  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
>  OBJS-$(CONFIG_FIC_DECODER) += fic.o
> +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
>  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
>  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o 
> vorbis_data.o
>  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 0243f47..a4cfd80 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -192,6 +192,7 @@ static void register_all(void)
>  REGISTER_ENCDEC (FFV1,  ffv1);
>  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
>  REGISTER_DECODER(FIC,   fic);
> +REGISTER_DECODER(FITS,  fits);
>  REGISTER_ENCDEC (FLASHSV,   flashsv);
>  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
>  REGISTER_DECODER(FLIC,  flic);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index b697afa..8eba460 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -447,6 +447,7 @@ enum AVCodecID {
>  AV_CODEC_ID_SRGC,
>  AV_CODEC_ID_SVG,
>  AV_CODEC_ID_GDV,
> +AV_CODEC_ID_FITS,
> 
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index cf1246e..0112517 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1464,6 +1464,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
>   AV_CODEC_PROP_LOSSLESS,
>  },
>  {
> +.id= AV_CODEC_ID_FITS,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "fits",
> +.long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport System"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> + AV_CODEC_PROP_LOSSLESS,
> +},
> +{
>  .id= AV_CODEC_ID_GIF,
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .name  = "gif",
> diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> new file mode 100644
> index 000..4eaf3c8
> --- /dev/null
> +++ b/libavcodec/fitsdec.c
> @@ -0,0 +1,580 @@
> +/*
> + * FITS image decoder
> + * Copyright (c) 2017 Paras Chadha
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Fo

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-29 Thread Michael Niedermayer
On Wed, Jun 28, 2017 at 07:22:01PM +0530, Paras Chadha wrote:
> Added code to export metadata as frame metadata
> 
> Signed-off-by: Paras Chadha 
> -
[...]
> +/**
> + * function reads the fits header and stores the values in FITSDecContext 
> pointed by header
> + * @param avctx - AVCodec context
> + * @param ptr - pointer to pointer to the data
> + * @param header - pointer to the FITSDecContext
> + * @param end - pointer to end of packet
> + * @return 1, if calculated successfully, otherwise AVERROR_INVALIDDATA
> + */
> +static int fits_read_header(AVCodecContext *avctx, const uint8_t **ptr, 
> FITSDecContext * header,
> +const uint8_t * end, AVDictionary **meta)
> +{
> +const uint8_t *ptr8 = *ptr;
> +int lines_read = 0, i, dim_no, t, data_min_found = 0, data_max_found = 
> 0, ret;
> +uint64_t size=1;
> +double d;
> +AVDictionary *metadata = NULL;
> +char keyword[10], value[72];
> +
> +header->blank = LLONG_MIN;
> +header->bscale = 1.0;
> +header->bzero = 0;
> +header->rgb = 0;
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "SIMPLE = %c", &header->simple) == 1) {
> +if (header->simple == 'F') {
> +av_log(avctx, AV_LOG_WARNING, "not a standard FITS file\n");
> +av_dict_set(&metadata, "SIMPLE", "F", 0);
> +} else if (header->simple != 'T') {
> +av_log(avctx, AV_LOG_ERROR, "invalid SIMPLE value, SIMPLE = 
> %c\n", header->simple);
> +return AVERROR_INVALIDDATA;
> +} else {
> +av_dict_set(&metadata, "SIMPLE", "T", 0);
> +}
> +header->xtension = 0;
> +} else if (!strncmp(ptr8, "XTENSION= 'IMAGE", 16)) {
> +header->xtension = 1;
> +av_dict_set(&metadata, "XTENSION", "'IMAGE   '", 0);
> +} else {
> +av_log(avctx, AV_LOG_ERROR, "missing SIMPLE keyword or invalid 
> XTENSION\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +ptr8 += 80;
> +lines_read++;
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "BITPIX = %d", &header->bitpix) != 1) {
> +av_log(avctx, AV_LOG_ERROR, "missing BITPIX keyword\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +av_dict_set_int(&metadata, "BITPIX", header->bitpix, 0);
> +size = abs(header->bitpix) >> 3;
> +ptr8 += 80;
> +lines_read++;
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "NAXIS = %d", &header->naxis) != 1) {
> +av_log(avctx, AV_LOG_ERROR, "missing NAXIS keyword\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (!header->naxis) {
> +av_log(avctx, AV_LOG_ERROR, "No image data found, NAXIS = %d\n", 
> header->naxis);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (header->naxis != 2 && header->naxis != 3) {
> +av_log(avctx, AV_LOG_ERROR, "unsupported number of dimensions, NAXIS 
> = %d\n", header->naxis);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +av_dict_set_int(&metadata, "NAXIS", header->naxis, 0);
> +ptr8 += 80;
> +lines_read++;
> +
> +for (i = 0; i < header->naxis; i++) {
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "NAXIS%d = %d", &dim_no, &header->naxisn[i]) != 2 
> || dim_no != i+1) {
> +av_log(avctx, AV_LOG_ERROR, "missing NAXIS%d keyword\n", i+1);
> +return AVERROR_INVALIDDATA;
> +}
> +

> +sprintf(keyword, "NAXIS%d", dim_no);

snprintf()


[...]
> +static int fits_decode_frame(AVCodecContext *avctx, void *data, int 
> *got_frame, AVPacket *avpkt)
> +{
> +AVFrame *p=data;
> +const uint8_t *ptr8 = avpkt->data, *end;
> +int16_t t16;
> +int32_t t32;
> +int64_t t64;
> +float   tflt;
> +double  tdbl;
> +int ret, i, j;
> +uint8_t *dst8;
> +uint16_t *dst16;
> +uint32_t *dst32;
> +uint64_t *dst64, size, r, g, b, a, t;
> +FITSDecContext * header = avctx->priv_data;
> +
> +end = ptr8 + avpkt->size;

> +if (ret = fits_read_header(avctx, &ptr8, header, end, &p->metadata) < 0)

missing ()

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-27 Thread Paul B Mahol
On 6/20/17, Paras Chadha  wrote:
> Above changes done. Also fixed an issue with BLANK keyword.
>
> Signed-off-by: Paras Chadha 
> ---
>  Changelog   |   1 +
>  doc/general.texi|   2 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   8 +
>  libavcodec/fitsdec.c| 517
> 
>  libavcodec/version.h|   2 +-
>  libavformat/img2.c  |   1 +
>  9 files changed, 533 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/fitsdec.c
>

Whats about all those metadata available in FITS files?

Please export them as frame metadata too.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-20 Thread Paras Chadha
On Tue, Jun 20, 2017 at 2:44 PM, Paul B Mahol  wrote:

> On 6/19/17, Paras Chadha  wrote:
> > Added support for XTENSION keyword
> >
> > Signed-off-by: Paras Chadha 
> > ---
> >  Changelog   |   1 +
> >  doc/general.texi|   2 +
> >  libavcodec/Makefile |   1 +
> >  libavcodec/allcodecs.c  |   1 +
> >  libavcodec/avcodec.h|   1 +
> >  libavcodec/codec_desc.c |   8 +
> >  libavcodec/fitsdec.c| 518
> > 
> >  libavcodec/version.h|   2 +-
> >  libavformat/img2.c  |   1 +
> >  9 files changed, 534 insertions(+), 1 deletion(-)
> >  create mode 100644 libavcodec/fitsdec.c
> >
> > diff --git a/Changelog b/Changelog
> > index a893efa..a07644c 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -22,6 +22,7 @@ version :
> >  - headphone audio filter
> >  - superequalizer audio filter
> >  - roberts video filter
> > +- FITS decoder
> >
> >  version 3.3:
> >  - CrystalHD decoder moved to new decode API
> > diff --git a/doc/general.texi b/doc/general.texi
> > index 8f582d5..c00ce32 100644
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -591,6 +591,8 @@ following image formats are supported:
> >  @tab Digital Picture Exchange
> >  @item EXR  @tab   @tab X
> >  @tab OpenEXR
> > +@item FITS @tab   @tab X
> > +@tab Flexible Image Transport System
> >  @item JPEG @tab X @tab X
> >  @tab Progressive JPEG is not supported.
> >  @item JPEG 2000@tab X @tab X
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index 2e7f19d..2cfd1fe 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o
> > ffv1.o
> >  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
> >  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
> >  OBJS-$(CONFIG_FIC_DECODER) += fic.o
> > +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
> >  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
> >  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o
> > vorbis_data.o
> >  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > index 27110e1..8a89264 100644
> > --- a/libavcodec/allcodecs.c
> > +++ b/libavcodec/allcodecs.c
> > @@ -186,6 +186,7 @@ static void register_all(void)
> >  REGISTER_ENCDEC (FFV1,  ffv1);
> >  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
> >  REGISTER_DECODER(FIC,   fic);
> > +REGISTER_DECODER(FITS,  fits);
> >  REGISTER_ENCDEC (FLASHSV,   flashsv);
> >  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
> >  REGISTER_DECODER(FLIC,  flic);
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index 39be8cf..1310426 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -447,6 +447,7 @@ enum AVCodecID {
> >  AV_CODEC_ID_SRGC,
> >  AV_CODEC_ID_SVG,
> >  AV_CODEC_ID_GDV,
> > +AV_CODEC_ID_FITS,
> >
> >  /* various PCM "codecs" */
> >  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at
> the
> > start of audio codecs
> > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> > index cf1246e..0112517 100644
> > --- a/libavcodec/codec_desc.c
> > +++ b/libavcodec/codec_desc.c
> > @@ -1464,6 +1464,14 @@ static const AVCodecDescriptor
> codec_descriptors[] =
> > {
> >   AV_CODEC_PROP_LOSSLESS,
> >  },
> >  {
> > +.id= AV_CODEC_ID_FITS,
> > +.type  = AVMEDIA_TYPE_VIDEO,
> > +.name  = "fits",
> > +.long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport
> > System"),
> > +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> > + AV_CODEC_PROP_LOSSLESS,
> > +},
> > +{
> >  .id= AV_CODEC_ID_GIF,
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .name  = "gif",
> > diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> > new file mode 100644
> > index 000..4e80936
> > --- /dev/null
> > +++ b/libavcodec/fitsdec.c
> > @@ -0,0 +1,518 @@
> > +/*
> > + * FITS image decoder
> > + * Copyright (c) 2017 Paras Chadha
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Pub

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-20 Thread Paul B Mahol
On 6/19/17, Paras Chadha  wrote:
> Added support for XTENSION keyword
>
> Signed-off-by: Paras Chadha 
> ---
>  Changelog   |   1 +
>  doc/general.texi|   2 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   8 +
>  libavcodec/fitsdec.c| 518
> 
>  libavcodec/version.h|   2 +-
>  libavformat/img2.c  |   1 +
>  9 files changed, 534 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/fitsdec.c
>
> diff --git a/Changelog b/Changelog
> index a893efa..a07644c 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -22,6 +22,7 @@ version :
>  - headphone audio filter
>  - superequalizer audio filter
>  - roberts video filter
> +- FITS decoder
>
>  version 3.3:
>  - CrystalHD decoder moved to new decode API
> diff --git a/doc/general.texi b/doc/general.texi
> index 8f582d5..c00ce32 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -591,6 +591,8 @@ following image formats are supported:
>  @tab Digital Picture Exchange
>  @item EXR  @tab   @tab X
>  @tab OpenEXR
> +@item FITS @tab   @tab X
> +@tab Flexible Image Transport System
>  @item JPEG @tab X @tab X
>  @tab Progressive JPEG is not supported.
>  @item JPEG 2000@tab X @tab X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 2e7f19d..2cfd1fe 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o
> ffv1.o
>  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
>  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
>  OBJS-$(CONFIG_FIC_DECODER) += fic.o
> +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
>  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
>  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o
> vorbis_data.o
>  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 27110e1..8a89264 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -186,6 +186,7 @@ static void register_all(void)
>  REGISTER_ENCDEC (FFV1,  ffv1);
>  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
>  REGISTER_DECODER(FIC,   fic);
> +REGISTER_DECODER(FITS,  fits);
>  REGISTER_ENCDEC (FLASHSV,   flashsv);
>  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
>  REGISTER_DECODER(FLIC,  flic);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 39be8cf..1310426 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -447,6 +447,7 @@ enum AVCodecID {
>  AV_CODEC_ID_SRGC,
>  AV_CODEC_ID_SVG,
>  AV_CODEC_ID_GDV,
> +AV_CODEC_ID_FITS,
>
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index cf1246e..0112517 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1464,6 +1464,14 @@ static const AVCodecDescriptor codec_descriptors[] =
> {
>   AV_CODEC_PROP_LOSSLESS,
>  },
>  {
> +.id= AV_CODEC_ID_FITS,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "fits",
> +.long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport
> System"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> + AV_CODEC_PROP_LOSSLESS,
> +},
> +{
>  .id= AV_CODEC_ID_GIF,
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .name  = "gif",
> diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> new file mode 100644
> index 000..4e80936
> --- /dev/null
> +++ b/libavcodec/fitsdec.c
> @@ -0,0 +1,518 @@
> +/*
> + * FITS image decoder
> + * Copyright (c) 2017 Paras Chadha
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +/**
> + * @file
> + * FITS image decoder
> + * It supports all 2-d images alongwith, bzero, bscale and blank keywords.
> + * RGBA images are

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-14 Thread Paras Chadha
On Tue, Jun 13, 2017 at 7:45 PM, Paul B Mahol  wrote:

> On 6/13/17, Paras Chadha  wrote:
> > Above mentioned changes have been done.
> >
> > Signed-off-by: Paras Chadha 
> > ---
> >  Changelog   |   1 +
> >  doc/general.texi|   2 +
> >  libavcodec/Makefile |   1 +
> >  libavcodec/allcodecs.c  |   1 +
> >  libavcodec/avcodec.h|   1 +
> >  libavcodec/codec_desc.c |   8 +
> >  libavcodec/fitsdec.c| 515
> > 
> >  libavcodec/version.h|   2 +-
> >  libavformat/img2.c  |   1 +
> >  9 files changed, 531 insertions(+), 1 deletion(-)
> >  create mode 100644 libavcodec/fitsdec.c
> >
> > diff --git a/Changelog b/Changelog
> > index cd91f63..db495d9 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -20,6 +20,7 @@ version :
> >  - sofalizer filter switched to libmysofa
> >  - Gremlin Digital Video demuxer and decoder
> >  - headphone audio filter
> > +- FITS decoder
> >
> >  version 3.3:
> >  - CrystalHD decoder moved to new decode API
> > diff --git a/doc/general.texi b/doc/general.texi
> > index 8f582d5..213e50e 100644
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -591,6 +591,8 @@ following image formats are supported:
> >  @tab Digital Picture Exchange
> >  @item EXR  @tab   @tab X
> >  @tab OpenEXR
> > +@item FITS @tab   @tab X
> > +@tab FITS image format
> >  @item JPEG @tab X @tab X
> >  @tab Progressive JPEG is not supported.
> >  @item JPEG 2000@tab X @tab X
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index 2e7f19d..2cfd1fe 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o
> > ffv1.o
> >  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
> >  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
> >  OBJS-$(CONFIG_FIC_DECODER) += fic.o
> > +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
> >  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
> >  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o
> > vorbis_data.o
> >  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > index 27110e1..8a89264 100644
> > --- a/libavcodec/allcodecs.c
> > +++ b/libavcodec/allcodecs.c
> > @@ -186,6 +186,7 @@ static void register_all(void)
> >  REGISTER_ENCDEC (FFV1,  ffv1);
> >  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
> >  REGISTER_DECODER(FIC,   fic);
> > +REGISTER_DECODER(FITS,  fits);
> >  REGISTER_ENCDEC (FLASHSV,   flashsv);
> >  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
> >  REGISTER_DECODER(FLIC,  flic);
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index dcdcfe0..e0c1089 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -447,6 +447,7 @@ enum AVCodecID {
> >  AV_CODEC_ID_SRGC,
> >  AV_CODEC_ID_SVG,
> >  AV_CODEC_ID_GDV,
> > +AV_CODEC_ID_FITS,
> >
> >  /* various PCM "codecs" */
> >  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at
> the
> > start of audio codecs
> > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> > index cf1246e..0112517 100644
> > --- a/libavcodec/codec_desc.c
> > +++ b/libavcodec/codec_desc.c
> > @@ -1464,6 +1464,14 @@ static const AVCodecDescriptor
> codec_descriptors[] =
> > {
> >   AV_CODEC_PROP_LOSSLESS,
> >  },
> >  {
> > +.id= AV_CODEC_ID_FITS,
> > +.type  = AVMEDIA_TYPE_VIDEO,
> > +.name  = "fits",
> > +.long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport
> > System"),
> > +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> > + AV_CODEC_PROP_LOSSLESS,
> > +},
> > +{
> >  .id= AV_CODEC_ID_GIF,
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .name  = "gif",
> > diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> > new file mode 100644
> > index 000..dfc4995
> > --- /dev/null
> > +++ b/libavcodec/fitsdec.c
> > @@ -0,0 +1,515 @@
> > +/*
> > + * FITS image decoder
> > + * Copyright (c) 2017 Paras Chadha
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-13 Thread Paul B Mahol
On 6/13/17, Paras Chadha  wrote:
> Above mentioned changes have been done.
>
> Signed-off-by: Paras Chadha 
> ---
>  Changelog   |   1 +
>  doc/general.texi|   2 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   8 +
>  libavcodec/fitsdec.c| 515
> 
>  libavcodec/version.h|   2 +-
>  libavformat/img2.c  |   1 +
>  9 files changed, 531 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/fitsdec.c
>
> diff --git a/Changelog b/Changelog
> index cd91f63..db495d9 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -20,6 +20,7 @@ version :
>  - sofalizer filter switched to libmysofa
>  - Gremlin Digital Video demuxer and decoder
>  - headphone audio filter
> +- FITS decoder
>
>  version 3.3:
>  - CrystalHD decoder moved to new decode API
> diff --git a/doc/general.texi b/doc/general.texi
> index 8f582d5..213e50e 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -591,6 +591,8 @@ following image formats are supported:
>  @tab Digital Picture Exchange
>  @item EXR  @tab   @tab X
>  @tab OpenEXR
> +@item FITS @tab   @tab X
> +@tab FITS image format
>  @item JPEG @tab X @tab X
>  @tab Progressive JPEG is not supported.
>  @item JPEG 2000@tab X @tab X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 2e7f19d..2cfd1fe 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o
> ffv1.o
>  OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
>  OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
>  OBJS-$(CONFIG_FIC_DECODER) += fic.o
> +OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
>  OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
>  OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o
> vorbis_data.o
>  OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 27110e1..8a89264 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -186,6 +186,7 @@ static void register_all(void)
>  REGISTER_ENCDEC (FFV1,  ffv1);
>  REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
>  REGISTER_DECODER(FIC,   fic);
> +REGISTER_DECODER(FITS,  fits);
>  REGISTER_ENCDEC (FLASHSV,   flashsv);
>  REGISTER_ENCDEC (FLASHSV2,  flashsv2);
>  REGISTER_DECODER(FLIC,  flic);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index dcdcfe0..e0c1089 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -447,6 +447,7 @@ enum AVCodecID {
>  AV_CODEC_ID_SRGC,
>  AV_CODEC_ID_SVG,
>  AV_CODEC_ID_GDV,
> +AV_CODEC_ID_FITS,
>
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index cf1246e..0112517 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1464,6 +1464,14 @@ static const AVCodecDescriptor codec_descriptors[] =
> {
>   AV_CODEC_PROP_LOSSLESS,
>  },
>  {
> +.id= AV_CODEC_ID_FITS,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "fits",
> +.long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport
> System"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> + AV_CODEC_PROP_LOSSLESS,
> +},
> +{
>  .id= AV_CODEC_ID_GIF,
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .name  = "gif",
> diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> new file mode 100644
> index 000..dfc4995
> --- /dev/null
> +++ b/libavcodec/fitsdec.c
> @@ -0,0 +1,515 @@
> +/*
> + * FITS image decoder
> + * Copyright (c) 2017 Paras Chadha
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +/**
> + * @file
> + * FITS image decoder
> + * It supports all 2-d images alongwith, bzero, bscale and blank keywords

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-13 Thread Paul B Mahol
On 6/13/17, Paras Chadha  wrote:
> Hi,
>
> Any other changes to be made to get this patch applied?
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Use this style instead:

switch (X) {
case 0:
then..
break;

Also for long description, use "Flexible Image Transport System"
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-13 Thread Paras Chadha
Hi,

Any other changes to be made to get this patch applied?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-09 Thread Paras Chadha
On Fri, Jun 9, 2017 at 1:26 AM, Moritz Barsnick  wrote:

> On Thu, Jun 08, 2017 at 22:34:15 +0530, Paras Chadha wrote:
> > +t64 = (((uint64_t) ptr8[0]) << 56) | (((uint64_t) ptr8[1])
> << 48) | (((uint64_t) ptr8[2]) << 40) | (((uint64_t) ptr8[3]) << 32) |
> (ptr8[4] << 24) | (ptr8[5] << 16) | (ptr8[6] << 8) | ptr8[7];
>
> I think you can (or should?) use macros such as av_be2ne64() for this,
> and all the other shift-byte-placements throughout the code. (Yes, I
> know that operation is doing "ne2be", but there's no macro for that,
> probably because it's identical.) In addition to being shorter, they
> will evaluate to pure assignments on big-endian platforms.


yes, Done
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-09 Thread Paras Chadha
On Fri, Jun 9, 2017 at 4:19 PM, Michael Niedermayer 
wrote:

> On Thu, Jun 08, 2017 at 10:34:15PM +0530, Paras Chadha wrote:
> > It supports all 2-d images alongwith bzero, bscale and blank keywords.
> > RGBA images are supported as NAXIS3 = 3 or 4 i.e. Planes in RGBA order.
> Also CTYPE = 'RGB ' should be present.
> > It currently does not support XTENSION keyword.
> >
> > Signed-off-by: Paras Chadha 
> > ---
> >  Changelog|   1 +
> >  doc/general.texi |   2 +
> >  libavcodec/Makefile  |   1 +
> >  libavcodec/allcodecs.c   |   1 +
> >  libavcodec/avcodec.h |   1 +
> >  libavcodec/codec_desc.c  |   8 +
> >  libavcodec/fitsdec.c | 527 ++
> +
> >  libavcodec/version.h |   4 +-
> >  libavformat/Makefile |   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/img2.c   |   1 +
> >  libavformat/img2dec.c|  10 +
> >  12 files changed, 556 insertions(+), 2 deletions(-)
> >  create mode 100644 libavcodec/fitsdec.c
> [...]
> > +/**
> > + * function reads the fits header and stores the values in fits_header
> pointed by header
> > + * @param avctx - AVCodec context
> > + * @param ptr - pointer to pointer to the data
> > + * @param header - pointer to the fits_header
> > + * @param end - pointer to end of packet
> > + * @return 1, if calculated successfully, otherwise AVERROR_INVALIDDATA
> > + */
> > +static int fits_read_header(AVCodecContext *avctx, const uint8_t
> **ptr, fits_header * header, const uint8_t * end)
> > +{
> > +const uint8_t *ptr8 = *ptr;
> > +int lines_read = 0, i, dim_no, t, data_min_found = 0,
> data_max_found = 0, ret;
> > +uint64_t size=1;
> > +char str_val[80];
> > +double d;
> > +
> > +header->blank = 0;
> > +header->bscale = 1.0;
> > +header->bzero = 0;
> > +header->rgb = 0;
> > +
> > +if (end - ptr8 < 80)
> > +return AVERROR_INVALIDDATA;
> > +
> > +if (sscanf(ptr8, "SIMPLE = %c", &header->simple) != 1) {
> > +av_log(avctx, AV_LOG_ERROR, "missing SIMPLE keyword\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +if (header->simple == 'F')
> > +av_log(avctx, AV_LOG_WARNING, "not a standard FITS file\n");
> > +else if (header->simple != 'T') {
> > +av_log(avctx, AV_LOG_ERROR, "invalid SIMPLE value, SIMPLE =
> %c\n", header->simple);
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +ptr8 += 80;
> > +lines_read++;
> > +
> > +if (end - ptr8 < 80)
> > +return AVERROR_INVALIDDATA;
> > +
> > +if (sscanf(ptr8, "BITPIX = %d", &header->bitpix) != 1) {
> > +av_log(avctx, AV_LOG_ERROR, "missing BITPIX keyword\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +size = abs(header->bitpix) / 8;
> > +ptr8 += 80;
> > +lines_read++;
> > +
> > +if (end - ptr8 < 80)
> > +return AVERROR_INVALIDDATA;
> > +
> > +if (sscanf(ptr8, "NAXIS = %d", &header->naxis) != 1) {
> > +av_log(avctx, AV_LOG_ERROR, "missing NAXIS keyword\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +if (header->naxis == 0) {
> > +av_log(avctx, AV_LOG_ERROR, "No image data found, NAXIS =
> %d\n", header->naxis);
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +if (header->naxis != 2 && header->naxis != 3) {
> > +av_log(avctx, AV_LOG_ERROR, "unsupported number of dimensions,
> NAXIS = %d\n", header->naxis);
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +ptr8 += 80;
> > +lines_read++;
> > +
> > +for (i = 0; i < header->naxis; i++) {
> > +if (end - ptr8 < 80)
> > +return AVERROR_INVALIDDATA;
> > +
> > +if (sscanf(ptr8, "NAXIS%d = %d", &dim_no, &header->naxisn[i])
> != 2 || dim_no != i+1) {
> > +av_log(avctx, AV_LOG_ERROR, "missing NAXIS%d keyword\n",
> i+1);
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +size *= header->naxisn[i];
> > +ptr8 += 80;
> > +lines_read++;
> > +}
> > +
> > +if (end - ptr8 < 80)
> > +return AVERROR_INVALIDDATA;
> > +
> > +while (strncmp(ptr8, "END", 3)) {
> > +if (sscanf(ptr8, "BLANK = %d", &t) == 1)
> > +header->blank = t;
> > +else if (sscanf(ptr8, "BSCALE = %lf", &d) == 1)
> > +header->bscale = d;
> > +else if (sscanf(ptr8, "BZERO = %lf", &d) == 1)
> > +header->bzero = d;
> > +else if (sscanf(ptr8, "DATAMAX = %lf", &d) == 1) {
> > +data_max_found = 1;
> > +header->data_max = d;
> > +}
> > +else if (sscanf(ptr8, "DATAMIN = %lf", &d) == 1) {
> > +data_min_found = 1;
> > +header->data_min = d;
> > +}
>
> > +else if (sscanf(ptr8, "CTYPE3 = '%s '", str_val) == 1) {
>
> what prevents a buffer overflow here ?
>

Yes you are right. I have provided an alternative code in latest patch
which prevents 

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-09 Thread Paras Chadha
On Fri, Jun 9, 2017 at 3:08 AM, Martin Vignali 
wrote:

> Hello,
>
> You can create a FipsContext struct to store decoding data
> instead of using Fips Header struct
> (you can take a look to other image decoder)
>
> Also you should need to split the patch for libavcodec part and libavformat
> part
>
> Nit : The coding style for if/else is
>
> if {
>
> } else {
>
> }
>
>
> Not
> if {
> }
> else {
> }
>
>
Done. Any other changes ?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-09 Thread Michael Niedermayer
On Thu, Jun 08, 2017 at 10:34:15PM +0530, Paras Chadha wrote:
> It supports all 2-d images alongwith bzero, bscale and blank keywords.
> RGBA images are supported as NAXIS3 = 3 or 4 i.e. Planes in RGBA order. Also 
> CTYPE = 'RGB ' should be present.
> It currently does not support XTENSION keyword.
> 
> Signed-off-by: Paras Chadha 
> ---
>  Changelog|   1 +
>  doc/general.texi |   2 +
>  libavcodec/Makefile  |   1 +
>  libavcodec/allcodecs.c   |   1 +
>  libavcodec/avcodec.h |   1 +
>  libavcodec/codec_desc.c  |   8 +
>  libavcodec/fitsdec.c | 527 
> +++
>  libavcodec/version.h |   4 +-
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/img2.c   |   1 +
>  libavformat/img2dec.c|  10 +
>  12 files changed, 556 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/fitsdec.c
[...]
> +/**
> + * function reads the fits header and stores the values in fits_header 
> pointed by header
> + * @param avctx - AVCodec context
> + * @param ptr - pointer to pointer to the data
> + * @param header - pointer to the fits_header
> + * @param end - pointer to end of packet
> + * @return 1, if calculated successfully, otherwise AVERROR_INVALIDDATA
> + */
> +static int fits_read_header(AVCodecContext *avctx, const uint8_t **ptr, 
> fits_header * header, const uint8_t * end)
> +{
> +const uint8_t *ptr8 = *ptr;
> +int lines_read = 0, i, dim_no, t, data_min_found = 0, data_max_found = 
> 0, ret;
> +uint64_t size=1;
> +char str_val[80];
> +double d;
> +
> +header->blank = 0;
> +header->bscale = 1.0;
> +header->bzero = 0;
> +header->rgb = 0;
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "SIMPLE = %c", &header->simple) != 1) {
> +av_log(avctx, AV_LOG_ERROR, "missing SIMPLE keyword\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (header->simple == 'F')
> +av_log(avctx, AV_LOG_WARNING, "not a standard FITS file\n");
> +else if (header->simple != 'T') {
> +av_log(avctx, AV_LOG_ERROR, "invalid SIMPLE value, SIMPLE = %c\n", 
> header->simple);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +ptr8 += 80;
> +lines_read++;
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "BITPIX = %d", &header->bitpix) != 1) {
> +av_log(avctx, AV_LOG_ERROR, "missing BITPIX keyword\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +size = abs(header->bitpix) / 8;
> +ptr8 += 80;
> +lines_read++;
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "NAXIS = %d", &header->naxis) != 1) {
> +av_log(avctx, AV_LOG_ERROR, "missing NAXIS keyword\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (header->naxis == 0) {
> +av_log(avctx, AV_LOG_ERROR, "No image data found, NAXIS = %d\n", 
> header->naxis);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (header->naxis != 2 && header->naxis != 3) {
> +av_log(avctx, AV_LOG_ERROR, "unsupported number of dimensions, NAXIS 
> = %d\n", header->naxis);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +ptr8 += 80;
> +lines_read++;
> +
> +for (i = 0; i < header->naxis; i++) {
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +if (sscanf(ptr8, "NAXIS%d = %d", &dim_no, &header->naxisn[i]) != 2 
> || dim_no != i+1) {
> +av_log(avctx, AV_LOG_ERROR, "missing NAXIS%d keyword\n", i+1);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +size *= header->naxisn[i];
> +ptr8 += 80;
> +lines_read++;
> +}
> +
> +if (end - ptr8 < 80)
> +return AVERROR_INVALIDDATA;
> +
> +while (strncmp(ptr8, "END", 3)) {
> +if (sscanf(ptr8, "BLANK = %d", &t) == 1)
> +header->blank = t;
> +else if (sscanf(ptr8, "BSCALE = %lf", &d) == 1)
> +header->bscale = d;
> +else if (sscanf(ptr8, "BZERO = %lf", &d) == 1)
> +header->bzero = d;
> +else if (sscanf(ptr8, "DATAMAX = %lf", &d) == 1) {
> +data_max_found = 1;
> +header->data_max = d;
> +}
> +else if (sscanf(ptr8, "DATAMIN = %lf", &d) == 1) {
> +data_min_found = 1;
> +header->data_min = d;
> +}

> +else if (sscanf(ptr8, "CTYPE3 = '%s '", str_val) == 1) {

what prevents a buffer overflow here ?

[...]
> +
> +static int fits_decode_frame(AVCodecContext *avctx, void *data, int 
> *got_frame, AVPacket *avpkt)
> +{
> +AVFrame *p=data;
> +const uint8_t *ptr8 = avpkt->data, *end;
> +int16_t t16;
> +int32_t t32;
> +int64_t t64;
> +float   tflt;
> +double  tdbl;
> +int ret, i, j;
> +uint8_t *dst8;
> +uint16_t *dst16;
> +uint32_t *dst32;
> +uint64_t 

Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-08 Thread Martin Vignali
Hello,

You can create a FipsContext struct to store decoding data
instead of using Fips Header struct
(you can take a look to other image decoder)

Also you should need to split the patch for libavcodec part and libavformat
part

Nit : The coding style for if/else is

if {

} else {

}


Not
if {
}
else {
}

Martin
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-08 Thread James Almer
On 6/8/2017 4:56 PM, Moritz Barsnick wrote:
> On Thu, Jun 08, 2017 at 22:34:15 +0530, Paras Chadha wrote:
>> +t64 = (((uint64_t) ptr8[0]) << 56) | (((uint64_t) ptr8[1]) << 
>> 48) | (((uint64_t) ptr8[2]) << 40) | (((uint64_t) ptr8[3]) << 32) | (ptr8[4] 
>> << 24) | (ptr8[5] << 16) | (ptr8[6] << 8) | ptr8[7];
> 
> I think you can (or should?) use macros such as av_be2ne64() for this,
> and all the other shift-byte-placements throughout the code. (Yes, I
> know that operation is doing "ne2be", but there's no macro for that,
> probably because it's identical.) In addition to being shorter, they
> will evaluate to pure assignments on big-endian platforms.

In this case, i think AV_RB64() is the correct macro to use.

> 
> Moritz
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Decoder

2017-06-08 Thread Moritz Barsnick
On Thu, Jun 08, 2017 at 22:34:15 +0530, Paras Chadha wrote:
> +t64 = (((uint64_t) ptr8[0]) << 56) | (((uint64_t) ptr8[1]) << 
> 48) | (((uint64_t) ptr8[2]) << 40) | (((uint64_t) ptr8[3]) << 32) | (ptr8[4] 
> << 24) | (ptr8[5] << 16) | (ptr8[6] << 8) | ptr8[7];

I think you can (or should?) use macros such as av_be2ne64() for this,
and all the other shift-byte-placements throughout the code. (Yes, I
know that operation is doing "ne2be", but there's no macro for that,
probably because it's identical.) In addition to being shorter, they
will evaluate to pure assignments on big-endian platforms.

Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel