1 /*
2 * BMP image format encoder
3 * Copyright (c) 2006, 2007 Michel Bardiaux
4 * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24
32
36
41 break;
44 break;
49 break;
57 break;
60 break;
61 }
62
63 return 0;
64 }
65
67 const AVFrame *pict,
int *got_packet)
68 {
70 int n_bytes_image, n_bytes_per_row, n_bytes,
i, n, hsize,
ret;
71 const uint32_t *pal =
NULL;
72 uint32_t palette256[256];
73 int pad_bytes_per_row, pal_entries = 0, compression =
BMP_RGB;
75 const uint8_t *ptr;
76 uint8_t *buf;
77
82 pal_entries = 3;
83 break;
87 pal_entries = 3;
88 break;
96 pal = palette256;
97 break;
99 pal = (uint32_t *)
p->data[1];
100 break;
103 break;
104 }
105 if (pal && !pal_entries) pal_entries = 1 << bit_count;
107 pad_bytes_per_row = (4 - n_bytes_per_row) & 3;
108 n_bytes_image = avctx->
height * (n_bytes_per_row + pad_bytes_per_row);
109
110 // STRUCTURE.field refer to the MSVC documentation for BITMAPFILEHEADER
111 // and related pages.
112 #define SIZE_BITMAPFILEHEADER 14
113 #define SIZE_BITMAPINFOHEADER 40
115 n_bytes = n_bytes_image + hsize;
119 bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType
120 bytestream_put_byte(&buf, 'M'); // do.
121 bytestream_put_le32(&buf, n_bytes); // BITMAPFILEHEADER.bfSize
122 bytestream_put_le16(&buf, 0); // BITMAPFILEHEADER.bfReserved1
123 bytestream_put_le16(&buf, 0); // BITMAPFILEHEADER.bfReserved2
124 bytestream_put_le32(&buf, hsize); // BITMAPFILEHEADER.bfOffBits
126 bytestream_put_le32(&buf, avctx->
width);
// BITMAPINFOHEADER.biWidth
127 bytestream_put_le32(&buf, avctx->
height);
// BITMAPINFOHEADER.biHeight
128 bytestream_put_le16(&buf, 1); // BITMAPINFOHEADER.biPlanes
129 bytestream_put_le16(&buf, bit_count); // BITMAPINFOHEADER.biBitCount
130 bytestream_put_le32(&buf, compression); // BITMAPINFOHEADER.biCompression
131 bytestream_put_le32(&buf, n_bytes_image); // BITMAPINFOHEADER.biSizeImage
132 bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biXPelsPerMeter
133 bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biYPelsPerMeter
134 bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biClrUsed
135 bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biClrImportant
136 for (
i = 0;
i < pal_entries;
i++)
137 bytestream_put_le32(&buf, pal[
i] & 0xFFFFFF);
138 // BMP files are bottom-to-top so we start from the end...
139 ptr =
p->data[0] + (avctx->
height - 1) *
p->linesize[0];
141 for(
i = 0; i < avctx->
height;
i++) {
142 if (HAVE_BIGENDIAN && bit_count == 16) {
143 const uint16_t *
src = (
const uint16_t *) ptr;
144 for(n = 0; n < avctx->
width; n++)
146 } else {
147 memcpy(buf, ptr, n_bytes_per_row);
148 }
149 buf += n_bytes_per_row;
150 memset(buf, 0, pad_bytes_per_row);
151 buf += pad_bytes_per_row;
152 ptr -=
p->linesize[0];
// ... and go back
153 }
154
155 *got_packet = 1;
156 return 0;
157 }
158
172 };