mirror of
https://github.com/whowechina/aic_pico.git
synced 2024-11-27 23:10:48 +01:00
88 lines
2.4 KiB
C
88 lines
2.4 KiB
C
/*
|
|
* Anima compression tool for AIC Pico
|
|
* WHowe <github.com/whowechina>
|
|
* From 8bit grayscale to 4bit grayscale and zero-run-length encoding
|
|
* Input: ani_data[], ani_width, ani_height
|
|
* Frame count is calculated from ani_data size and frame size (ani_width * ani_height)
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "../src/rle.c"
|
|
#include "../src/gfx.h"
|
|
#include "../src/light_frames.h"
|
|
|
|
//#include "../src/glow.h"
|
|
|
|
const char *name = "light";
|
|
|
|
static inline uint8_t gs8bto4b(const uint8_t bytes[2])
|
|
{
|
|
return (bytes[0] & 0xf0) | (bytes[1] >> 4);
|
|
}
|
|
|
|
static uint8_t output[1*1024*1024];
|
|
static uint8_t frame_buffer[1*1024*1024];
|
|
|
|
static void print_frame(int frame, int size)
|
|
{
|
|
printf("\n // Frame %d: %d bytes", frame + 1, size);
|
|
for (int i = 0; i < size; i++) {
|
|
if ((i & 15) == 0) {
|
|
printf("\n ");
|
|
}
|
|
printf(" 0x%02x,", output[i]);
|
|
}
|
|
}
|
|
|
|
static int encode_frame(int frame, int frame_size)
|
|
{
|
|
const uint8_t *frame_data = ani_data + frame * ani_width * ani_height;
|
|
for (int i = 0; i < frame_size / 2; i++) {
|
|
frame_buffer[i] = gs8bto4b(frame_data + i * 2);
|
|
}
|
|
int size = rle_x_encode_uint8(output, frame_buffer, frame_size / 2, 0);
|
|
print_frame(frame, size);
|
|
return size;
|
|
}
|
|
|
|
const char *headlines =
|
|
"/* Generated by anima_conv.c, 4 bit per pixel, RLE X=0 compressed. */\n\n"
|
|
"#include \"gfx.h\"\n\n";
|
|
|
|
|
|
int main()
|
|
{
|
|
int frame_size = ani_width * ani_height;
|
|
int frame_count = sizeof(ani_data) / frame_size;
|
|
int frame_index[frame_count];
|
|
|
|
printf("%s", headlines);
|
|
printf("const uint8_t %s_data[] = {", name);
|
|
int sum = 0;
|
|
for (int frame = 0; frame < frame_count; frame++) {
|
|
frame_index[frame] = sum;
|
|
sum += encode_frame(frame, frame_size);
|
|
}
|
|
printf("\n};\n\n");
|
|
|
|
printf("const uint32_t %s_index[] = {\n ", name);
|
|
for (int frame = 0; frame < frame_count; frame++) {
|
|
printf(" %d,", frame_index[frame]);
|
|
}
|
|
printf("\n};\n\n");
|
|
|
|
printf("const anima_t %s_ani = {\n", name);
|
|
printf(" .width = %d,\n", ani_width);
|
|
printf(" .height = %d,\n", ani_height);
|
|
printf(" .frames = %d,\n", frame_count);
|
|
printf(" .index = %s_index,\n", name);
|
|
printf(" .data = %s_data,\n", name);
|
|
printf(" .size = sizeof(%s_data),\n", name);
|
|
printf("};\n");
|
|
|
|
fprintf(stderr, "Frame count: %d\n", frame_count);
|
|
fprintf(stderr, "Total: %d\n", sum);
|
|
} |