70 int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize;
71 const uint32_t *pal =
NULL;
72 int pad_bytes_per_row, pal_entries = 0, compression =
BMP_RGB;
75 unsigned char* buf0 = buf;
97 pal = (uint32_t *)p->
data[1];
103 if (pal && !pal_entries) pal_entries = 1 << bit_count;
104 n_bytes_per_row = ((int64_t)avctx->
width * (int64_t)bit_count + 7LL) >> 3LL;
105 pad_bytes_per_row = (4 - n_bytes_per_row) & 3;
106 n_bytes_image = avctx->
height * (n_bytes_per_row + pad_bytes_per_row);
110 #define SIZE_BITMAPFILEHEADER 14
111 #define SIZE_BITMAPINFOHEADER 40
113 n_bytes = n_bytes_image + hsize;
114 if(n_bytes>buf_size) {
115 av_log(avctx,
AV_LOG_ERROR,
"buf size too small (need %d, got %d)\n", n_bytes, buf_size);
118 bytestream_put_byte(&buf,
'B');
119 bytestream_put_byte(&buf,
'M');
120 bytestream_put_le32(&buf, n_bytes);
121 bytestream_put_le16(&buf, 0);
122 bytestream_put_le16(&buf, 0);
123 bytestream_put_le32(&buf, hsize);
125 bytestream_put_le32(&buf, avctx->
width);
126 bytestream_put_le32(&buf, avctx->
height);
127 bytestream_put_le16(&buf, 1);
128 bytestream_put_le16(&buf, bit_count);
129 bytestream_put_le32(&buf, compression);
130 bytestream_put_le32(&buf, n_bytes_image);
131 bytestream_put_le32(&buf, 0);
132 bytestream_put_le32(&buf, 0);
133 bytestream_put_le32(&buf, 0);
134 bytestream_put_le32(&buf, 0);
135 for (i = 0; i < pal_entries; i++)
136 bytestream_put_le32(&buf, pal[i] & 0xFFFFFF);
140 for(i = 0; i < avctx->
height; i++) {
141 if (bit_count == 16) {
142 const uint16_t *src = (
const uint16_t *) ptr;
143 uint16_t *dst = (uint16_t *) buf;
144 for(n = 0; n < avctx->
width; n++)
147 memcpy(buf, ptr, n_bytes_per_row);
149 buf += n_bytes_per_row;
150 memset(buf, 0, pad_bytes_per_row);
151 buf += pad_bytes_per_row;