1 /*
2 * FITS image encoder
3 * Copyright (c) 2017 Paras Chadha
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * FITS image encoder
25 *
26 * Specification: https://fits.gsfc.nasa.gov/fits_standard.html Version 3.0
27 *
28 * RGBA images are encoded as planes in RGBA order. So, NAXIS3 is 3 or 4 for them.
29 * Also CTYPE3 = 'RGB ' is added to the header to distinguish them from 3d images.
30 */
31
37
39 const AVFrame *pict,
int *got_packet)
40 {
42 uint8_t *bytestream, *ptr;
43 const uint16_t
flip = (1 << 15);
44 uint64_t data_size = 0, padded_data_size = 0;
45 int ret, bitpix, naxis3 = 1,
i, j, k, bytes_left;
46 int map[] = {2, 0, 1, 3};
// mapping from GBRA -> RGBA as RGBA is to be stored in FITS file..
47
51 map[0] = 0;
// grayscale images should be directly mapped
53 bitpix = 8;
54 } else {
55 bitpix = 16;
56 }
57 break;
60 bitpix = 8;
62 naxis3 = 3;
63 } else {
64 naxis3 = 4;
65 }
66 break;
69 bitpix = 16;
71 naxis3 = 3;
72 } else {
73 naxis3 = 4;
74 }
75 break;
76 default:
79 }
80
81 data_size = (bitpix >> 3) * avctx->
height * avctx->
width * naxis3;
82 padded_data_size = ((data_size + 2879) / 2880 ) * 2880;
83
86
88
89 for (k = 0; k < naxis3; k++) {
93 for (j = 0; j < avctx->
width; j++) {
94 // subtracting bzero is equivalent to first bit flip
95 bytestream_put_be16(&bytestream,
AV_RB16(ptr) ^
flip);
96 ptr += 2;
97 }
98 } else {
99 memcpy(bytestream, ptr, avctx->
width);
100 bytestream += avctx->
width;
101 }
102 }
103 }
104
105 bytes_left = padded_data_size - data_size;
106 memset(bytestream, 0, bytes_left);
107
108 *got_packet = 1;
109
110 return 0;
111 }
112
127 };