27#include "config_components.h"
39#define CHARSET_CHARS 256
66static const uint8_t
mc_colors[5]={0x0,0xb,0xc,0xf,0x1};
75 int blockx, blocky, x, y;
79 const uint8_t *
src = p->data[0];
81 for (blocky = 0; blocky <
C64YRES; blocky += 8) {
82 for (blockx = 0; blockx <
C64XRES; blockx += 8) {
83 for (y = blocky; y < blocky + 8 && y <
C64YRES; y++) {
84 for (x = blockx; x < blockx + 8 && x <
C64XRES; x += 2) {
88 luma = (
src[(x + 0 + y * p->linesize[0])] +
89 src[(x + 1 + y * p->linesize[0])]) / 2;
91 luma =
src[(x + y * p->linesize[0])];
111 int lowdiff, highdiff;
112 int *best_cb =
c->mc_best_cb;
124 for (
a=0;
a < 256;
a++) {
125 if(
i < c->mc_pal_size -1 &&
a ==
c->mc_luma_vals[
i + 1]) {
132 if(
i >=
c->mc_pal_size - 1)
dither[
a] = 0;
134 index2[
a] =
FFMIN(
i + 1,
c->mc_pal_size - 1);
141 for (y = 0; y < 8; y++) {
143 for (x = 0; x < 4; x++) {
144 pix = best_cb[y * 4 + x];
147 if (index1[
pix] >= 3)
148 highdiff +=
pix -
c->mc_luma_vals[3];
150 lowdiff +=
c->mc_luma_vals[1] -
pix;
157 row1 |= 3-(index2[
pix] & 3);
159 row1 |= 3-(index1[
pix] & 3);
162 row2 |= 3-(index2[
pix] & 3);
164 row2 |= 3-(index1[
pix] & 3);
168 row1 |= 3-(index2[
pix] & 3);
170 row1 |= 3-(index1[
pix] & 3);
173 charset[y+0x000] = row1;
177 if (highdiff > 0 && lowdiff > 0 &&
c->mc_use_5col) {
178 if (lowdiff > highdiff) {
179 for (x = 0; x < 32; x++)
180 best_cb[x] =
FFMIN(
c->mc_luma_vals[3], best_cb[x]);
182 for (x = 0; x < 32; x++)
183 best_cb[x] =
FFMAX(
c->mc_luma_vals[1], best_cb[x]);
193 colrammap[charpos] = (highdiff > 0);
225 c->mc_frame_counter = 0;
227 c->mc_pal_size = 4 +
c->mc_use_5col;
230 for (
a = 0;
a <
c->mc_pal_size;
a++) {
236 if (!(
c->mc_meta_charset =
av_calloc(
c->mc_lifetime, 32000 *
sizeof(
int))) ||
238 !(
c->mc_charmap =
av_calloc(
c->mc_lifetime, 1000 *
sizeof(
int))) ||
267 for (
a = 0;
a < 256;
a++) {
268 temp = colram[charmap[
a + 0x000]] << 0;
269 temp |= colram[charmap[
a + 0x100]] << 1;
270 temp |= colram[charmap[
a + 0x200]] << 2;
271 if (
a < 0xe8)
temp |= colram[charmap[
a + 0x300]] << 3;
277 const AVFrame *p,
int *got_packet)
289 int *charmap =
c->mc_charmap;
290 uint8_t *colram =
c->mc_colram;
291 int *meta =
c->mc_meta_charset;
292 int *best_cb =
c->mc_best_cb;
295 int colram_size = 0x100 *
c->mc_use_5col;
301 screen_size = b_width * b_height;
311 if (!
c->mc_lifetime)
return 0;
313 if (!
c->mc_frame_counter) {
317 else c->mc_lifetime =
c->mc_frame_counter;
321 if (
c->mc_frame_counter <
c->mc_lifetime) {
323 c->mc_frame_counter++;
325 c->next_pts = p->pts;
332 if (
c->mc_frame_counter ==
c->mc_lifetime) {
335 if (
c->mc_lifetime) {
336 int alloc_size = charset_size +
c->mc_lifetime*(screen_size + colram_size);
352 req_size += charset_size;
358 for (y = 0; y < b_height; y++) {
359 for (x = 0; x < b_width; x++) {
360 buf[y * b_width + x] = charmap[y * b_width + x];
365 req_size += screen_size;
368 if (
c->mc_use_5col) {
372 req_size += colram_size;
384 c->mc_frame_counter = 0;
386 pkt->pts =
pkt->dts =
c->next_pts;
390 *got_packet = !!req_size;
395#if CONFIG_A64MULTI_ENCODER
397 .p.name =
"a64multi",
410#if CONFIG_A64MULTI5_ENCODER
412 .p.name =
"a64multi5",
413 CODEC_LONG_NAME(
"Multicolor charset for Commodore 64, extended with 5th color (colram)"),
a64 video encoder - c64 colors in rgb
static const uint8_t a64_palette[16][3]
static const uint8_t mc_colors[5]
static void a64_compress_colram(unsigned char *buf, int *charmap, uint8_t *colram)
static void render_charset(AVCodecContext *avctx, uint8_t *charset, uint8_t *colrammap)
static av_cold int a64multi_close_encoder(AVCodecContext *avctx)
static av_cold int a64multi_encode_init(AVCodecContext *avctx)
static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet)
static void to_meta_with_crop(AVCodecContext *avctx, const AVFrame *p, int *dest)
a64 video encoder - tables used by a64 encoders
static const uint8_t multi_dither_patterns[9][4][4]
dither patterns used vor rendering the multicolor charset
static const uint8_t interlaced_dither_patterns[9][8][4]
const FFCodec ff_a64multi5_encoder
const FFCodec ff_a64multi_encoder
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
int avpriv_elbg_do(ELBGContext **elbgp, int *points, int dim, int numpoints, int *codebook, int num_cb, int max_steps, int *closest_cb, AVLFG *rand_state, uintptr_t flags)
Implementation of the Enhanced LBG Algorithm Based on the paper "Neural Networks 14:1219-1237" that c...
av_cold void avpriv_elbg_free(ELBGContext **elbgp)
Free an ELBGContext and reset the pointer to it.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_NOPTS_VALUE
Undefined timestamp value.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static float distance(float x, float y, int band)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
unsigned mc_frame_counter
struct ELBGContext * elbg
main external API structure.
int width
picture width / height.
int global_quality
Global quality for codecs which cannot change it per frame.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
const struct AVCodec * codec
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
Context structure for the Lagged Fibonacci PRNG.
This structure stores compressed data.
static const uint16_t dither[8][8]