FFmpeg
Data Structures | Macros | Functions | Variables
fitsdec.c File Reference
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
#include <float.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat.h"
#include "libavutil/dict.h"
#include "libavutil/opt.h"
#include "fits.h"

Go to the source code of this file.

Data Structures

struct  FITSContext
 

Macros

#define CASE_N(a, t, rd)
 
#define CASE_RGB(cas, dst, type, dref)
 
#define CASE_GRAY(cas, dst, type, t, rd)
 

Functions

static int fill_data_min_max (const uint8_t *ptr8, FITSHeader *header, const uint8_t *end)
 Calculate the data_min and data_max values from the data. More...
 
static int fits_read_header (AVCodecContext *avctx, const uint8_t **ptr, FITSHeader *header, const uint8_t *end, AVDictionary **metadata)
 Read the fits header and store the values in FITSHeader pointed by header. More...
 
static int fits_decode_frame (AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
 

Variables

static const AVOption fits_options []
 
static const AVClass fits_decoder_class
 
const FFCodec ff_fits_decoder
 

Detailed Description

FITS image decoder

Specification: https://fits.gsfc.nasa.gov/fits_standard.html Version 3.0

Support all 2d 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. Also to interpret data, values are linearly scaled using min-max scaling but not RGB images.

Definition in file fitsdec.c.

Macro Definition Documentation

◆ CASE_N

#define CASE_N (   a,
  t,
  rd 
)
Value:
case a: \
for (i = 0; i < header->naxisn[1]; i++) { \
for (j = 0; j < header->naxisn[0]; j++) { \
t = rd; \
if (!header->blank_found || t != header->blank) { \
if (t > header->data_max) \
header->data_max = t; \
if (t < header->data_min) \
header->data_min = t; \
} \
ptr8 += abs(a) >> 3; \
} \
} \
break

◆ CASE_RGB

#define CASE_RGB (   cas,
  dst,
  type,
  dref 
)
Value:
case cas: \
for (k = 0; k < header.naxisn[2]; k++) { \
for (i = 0; i < avctx->height; i++) { \
dst = (type *) (p->data[map[k]] + (avctx->height - i - 1) * p->linesize[map[k]]); \
for (j = 0; j < avctx->width; j++) { \
t32 = dref(ptr8); \
if (!header.blank_found || t32 != header.blank) { \
t = t32 * header.bscale + header.bzero; \
} else { \
t = fitsctx->blank_val; \
} \
*dst++ = (type) t; \
ptr8 += cas >> 3; \
} \
} \
} \
break

◆ CASE_GRAY

#define CASE_GRAY (   cas,
  dst,
  type,
  t,
  rd 
)
Value:
case cas: \
for (i = 0; i < avctx->height; i++) { \
dst = (type *) (p->data[0] + (avctx->height-i-1)* p->linesize[0]); \
for (j = 0; j < avctx->width; j++) { \
t = rd; \
if (!header.blank_found || t != header.blank) { \
*dst++ = lrint(((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) * scale); \
} else { \
*dst++ = fitsctx->blank_val; \
} \
ptr8 += abs(cas) >> 3; \
} \
} \
break

Function Documentation

◆ fill_data_min_max()

static int fill_data_min_max ( const uint8_t *  ptr8,
FITSHeader header,
const uint8_t *  end 
)
static

Calculate the data_min and data_max values from the data.

This is called if the values are not present in the header.

Parameters
ptr8pointer to the data
headerpointer to the header
endpointer to end of packet
Returns
0 if calculated successfully otherwise AVERROR_INVALIDDATA

Definition at line 56 of file fitsdec.c.

Referenced by fits_read_header().

◆ fits_read_header()

static int fits_read_header ( AVCodecContext avctx,
const uint8_t **  ptr,
FITSHeader header,
const uint8_t *  end,
AVDictionary **  metadata 
)
static

Read the fits header and store the values in FITSHeader pointed by header.

Parameters
avctxAVCodec context
ptrpointer to pointer to the data
headerpointer to the FITSHeader
endpointer to end of packet
metadatapointer to pointer to AVDictionary to store metadata
Returns
0 if calculated successfully otherwise AVERROR_INVALIDDATA

Definition at line 106 of file fitsdec.c.

Referenced by fits_decode_frame().

◆ fits_decode_frame()

static int fits_decode_frame ( AVCodecContext avctx,
AVFrame p,
int *  got_frame,
AVPacket avpkt 
)
static

Definition at line 184 of file fitsdec.c.

Variable Documentation

◆ fits_options

const AVOption fits_options[]
static
Initial value:
= {
{ "blank_value", "value that is used to replace BLANK pixels in data array", 0x42, AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 65535, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM},
{ NULL },
}

Definition at line 309 of file fitsdec.c.

◆ fits_decoder_class

const AVClass fits_decoder_class
static
Initial value:
= {
.class_name = "FITS decoder",
.item_name = av_default_item_name,
.option = fits_options,
}

Definition at line 314 of file fitsdec.c.

◆ ff_fits_decoder

const FFCodec ff_fits_decoder
Initial value:
= {
.p.name = "fits",
.p.type = AVMEDIA_TYPE_VIDEO,
.p.capabilities = AV_CODEC_CAP_DR1,
CODEC_LONG_NAME("Flexible Image Transport System"),
.p.priv_class = &fits_decoder_class,
.priv_data_size = sizeof(FITSContext),
}

Definition at line 322 of file fitsdec.c.

AV_CLASS_CATEGORY_DECODER
@ AV_CLASS_CATEGORY_DECODER
Definition: log.h:35
FITSContext
Definition: fitsdec.c:43
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
lrint
#define lrint
Definition: tablegen.h:53
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_FITS
@ AV_CODEC_ID_FITS
Definition: codec_id.h:290
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
header
static const uint8_t header[24]
Definition: sdr2.c:68
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:358
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
fits_decoder_class
static const AVClass fits_decoder_class
Definition: fitsdec.c:314
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:356
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
fits_decode_frame
static int fits_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
Definition: fitsdec.c:184
fits_options
static const AVOption fits_options[]
Definition: fitsdec.c:309