FFmpeg
Loading...
Searching...
No Matches
fitsdec.c File Reference

FITS image decoder. More...

#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.
 
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.
 
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
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define abs(x)
int a
static const uint8_t header[24]
Definition sdr2.c:68

Referenced by fill_data_min_max().

◆ 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
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
cl_device_type type
const VDPAUPixFmtMap * map

Referenced by fits_decode_frame().

◆ 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
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
#define lrint
Definition tablegen.h:53

Referenced by fits_decode_frame().

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 },
}
#define NULL
Definition coverity.c:32
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258

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,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const AVOption fits_options[]
Definition fitsdec.c:309
@ AV_CLASS_CATEGORY_DECODER
Definition log.h:35

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),
}
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_FITS
Definition codec_id.h:281
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int fits_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
Definition fitsdec.c:184
static const AVClass fits_decoder_class
Definition fitsdec.c:314

Definition at line 322 of file fitsdec.c.