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 <paraschadh...@gmail.com> > - [...] > +/** > + * 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