36 #define CHARSET_CHARS 256
38 #define CROP_SCREENS 1
72 int blockx, blocky, x, y;
78 for (blocky = 0; blocky <
C64YRES; blocky += 8) {
79 for (blockx = 0; blockx <
C64XRES; blockx += 8) {
80 for (y = blocky; y < blocky + 8 && y <
C64YRES; y++) {
81 for (x = blockx; x < blockx + 8 && x <
C64XRES; x += 2) {
108 int lowdiff, highdiff;
109 int *best_cb =
c->mc_best_cb;
121 for (
a=0;
a < 256;
a++) {
122 if(i < c->mc_pal_size -1 &&
a ==
c->mc_luma_vals[
i + 1]) {
129 if(
i >=
c->mc_pal_size - 1)
dither[
a] = 0;
131 index2[
a] =
FFMIN(
i + 1,
c->mc_pal_size - 1);
138 for (y = 0; y < 8; y++) {
140 for (x = 0; x < 4; x++) {
141 pix = best_cb[y * 4 + x];
144 if (index1[pix] >= 3)
145 highdiff += pix -
c->mc_luma_vals[3];
147 lowdiff +=
c->mc_luma_vals[1] - pix;
154 row1 |= 3-(index2[pix] & 3);
156 row1 |= 3-(index1[pix] & 3);
159 row2 |= 3-(index2[pix] & 3);
161 row2 |= 3-(index1[pix] & 3);
165 row1 |= 3-(index2[pix] & 3);
167 row1 |= 3-(index1[pix] & 3);
170 charset[y+0x000] = row1;
174 if (highdiff > 0 && lowdiff > 0 &&
c->mc_use_5col) {
175 if (lowdiff > highdiff) {
176 for (x = 0; x < 32; x++)
177 best_cb[x] =
FFMIN(
c->mc_luma_vals[3], best_cb[x]);
179 for (x = 0; x < 32; x++)
180 best_cb[x] =
FFMAX(
c->mc_luma_vals[1], best_cb[x]);
190 colrammap[charpos] = (highdiff > 0);
220 c->mc_frame_counter = 0;
222 c->mc_pal_size = 4 +
c->mc_use_5col;
225 for (
a = 0;
a <
c->mc_pal_size;
a++) {
263 for (
a = 0;
a < 256;
a++) {
264 temp = colram[charmap[
a + 0x000]] << 0;
265 temp |= colram[charmap[
a + 0x100]] << 1;
266 temp |= colram[charmap[
a + 0x200]] << 2;
267 if (
a < 0xe8)
temp |= colram[charmap[
a + 0x300]] << 3;
273 const AVFrame *p,
int *got_packet)
285 int *charmap =
c->mc_charmap;
288 int *meta =
c->mc_meta_charset;
289 int *best_cb =
c->mc_best_cb;
292 int colram_size = 0x100 *
c->mc_use_5col;
298 screen_size = b_width * b_height;
308 if (!
c->mc_lifetime)
return 0;
310 if (!
c->mc_frame_counter) {
314 else c->mc_lifetime =
c->mc_frame_counter;
318 if (
c->mc_frame_counter <
c->mc_lifetime) {
320 c->mc_frame_counter++;
322 c->next_pts = p->
pts;
329 if (
c->mc_frame_counter ==
c->mc_lifetime) {
332 if (
c->mc_lifetime) {
333 int alloc_size = charset_size +
c->mc_lifetime*(screen_size + colram_size);
352 memcpy(buf, charset, charset_size);
356 req_size += charset_size;
362 for (y = 0; y < b_height; y++) {
363 for (x = 0; x < b_width; x++) {
364 buf[y * b_width + x] = charmap[y * b_width + x];
369 req_size += screen_size;
372 if (
c->mc_use_5col) {
376 req_size += colram_size;
388 c->mc_frame_counter = 0;
396 *got_packet = !!req_size;
401 #if CONFIG_A64MULTI_ENCODER
416 #if CONFIG_A64MULTI5_ENCODER
419 .long_name =
NULL_IF_CONFIG_SMALL(
"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]
AVCodec ff_a64multi5_encoder
AVCodec 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.
static av_cold int init(AVCodecContext *avctx)
common internal and external API header
int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook, int numCB, int max_steps, int *closest_cb, AVLFG *rand_state)
Initialize the **codebook vector for the elbg algorithm.
int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook, int numCB, int max_steps, int *closest_cb, AVLFG *rand_state)
Implementation of the Enhanced LBG Algorithm Based on the paper "Neural Networks 14:1219-1237" that c...
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#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_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
#define AV_NOPTS_VALUE
Undefined timestamp value.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static float distance(float x, float y, int band)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
unsigned mc_frame_counter
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
some codecs need / can use extradata like Huffman tables.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Context structure for the Lagged Fibonacci PRNG.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
static const uint8_t dither[8][8]