That's a fuckload of code written in a fuckload of desperation for a thing
This commit is contained in:
parent
31867af95c
commit
899db9fdaf
4 changed files with 154 additions and 7 deletions
32
bin/main.c
32
bin/main.c
|
@ -41,7 +41,8 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
||||||
" %1$s merge-rgb file.sav rn gn bn output.png\n"
|
" %1$s merge-rgb file.sav rn gn bn output.png\n"
|
||||||
" %1$s import-tile file.sav 1..30 printer.tile\n"
|
" %1$s import-tile file.sav 1..30 printer.tile\n"
|
||||||
" %1$s export-tile file.sav 1..30 output.tile\n"
|
" %1$s export-tile file.sav 1..30 output.tile\n"
|
||||||
" %1$s convert-tile printer.tile output.png\n",
|
" %1$s convert-tile printer.tile output.png\n"
|
||||||
|
" %1$s stripe input.png\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -753,6 +754,34 @@ error_open:
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int stripe(int argc, char **argv) {
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t width, height;
|
||||||
|
int depth;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
usage(argc, argv, "No input PNG image provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((buf = read_png_file(argv[2], &width, &height, &depth)) == NULL) {
|
||||||
|
goto error_read_png_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cammy_image_stripe(buf, width, height, depth) < 0) {
|
||||||
|
goto error_image_stripe;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_image_stripe:
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
error_read_png_file:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
char *name;
|
char *name;
|
||||||
int (*fun)(int, char **);
|
int (*fun)(int, char **);
|
||||||
|
@ -765,6 +794,7 @@ static struct {
|
||||||
{ "import-tile", import_tile },
|
{ "import-tile", import_tile },
|
||||||
{ "export-tile", export_tile },
|
{ "export-tile", export_tile },
|
||||||
{ "convert-tile", convert_tile },
|
{ "convert-tile", convert_tile },
|
||||||
|
{ "stripe", stripe },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,16 @@ void cammy_image_dither(uint8_t *dest,
|
||||||
|
|
||||||
void cammy_image_dither_to_tile(cammy_tile *dest,
|
void cammy_image_dither_to_tile(cammy_tile *dest,
|
||||||
uint8_t *src,
|
uint8_t *src,
|
||||||
|
size_t x_dest,
|
||||||
|
size_t y_dest,
|
||||||
|
size_t x_src,
|
||||||
|
size_t y_src,
|
||||||
size_t width,
|
size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
|
size_t dest_width,
|
||||||
|
size_t dest_height,
|
||||||
|
size_t src_width,
|
||||||
|
size_t src_height,
|
||||||
int depth);
|
int depth);
|
||||||
|
|
||||||
void cammy_image_split_to_tiles(cammy_tile *destr,
|
void cammy_image_split_to_tiles(cammy_tile *destr,
|
||||||
|
@ -92,4 +100,6 @@ void cammy_image_copy(cammy_image *dest,
|
||||||
size_t width,
|
size_t width,
|
||||||
size_t height);
|
size_t height);
|
||||||
|
|
||||||
|
int cammy_image_stripe(uint8_t *buf, size_t width, size_t height, int depth);
|
||||||
|
|
||||||
#endif /* _CAMMY_IMAGE_H */
|
#endif /* _CAMMY_IMAGE_H */
|
||||||
|
|
114
src/image.c
114
src/image.c
|
@ -1,10 +1,13 @@
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <cammy/screen.h>
|
||||||
#include <cammy/image.h>
|
#include <cammy/image.h>
|
||||||
|
|
||||||
static uint32_t bayer_matrix[256] = {
|
static uint32_t bayer_matrix[256] = {
|
||||||
|
@ -350,20 +353,39 @@ void cammy_image_copy_from_tile(uint8_t *dest,
|
||||||
|
|
||||||
void cammy_image_dither_to_tile(cammy_tile *dest,
|
void cammy_image_dither_to_tile(cammy_tile *dest,
|
||||||
uint8_t *src,
|
uint8_t *src,
|
||||||
|
size_t x_dest,
|
||||||
|
size_t y_dest,
|
||||||
|
size_t x_src,
|
||||||
|
size_t y_src,
|
||||||
size_t width,
|
size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
|
size_t dest_width,
|
||||||
|
size_t dest_height,
|
||||||
|
size_t src_width,
|
||||||
|
size_t src_height,
|
||||||
int depth) {
|
int depth) {
|
||||||
size_t x, y;
|
size_t x_offset, y_offset;
|
||||||
|
|
||||||
memset(dest, '\x00', CAMMY_TILE_SIZE * (width >> 3) * (height >> 3));
|
printf("dest dimensions %zux%zu\n", dest_width, dest_height);
|
||||||
|
|
||||||
for (y=0; y<height; y++) {
|
for (y_offset=0; y_offset<height; y_offset++) {
|
||||||
for (x=0; x<width; x++) {
|
if (y_dest + y_offset > dest_height) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x_offset=0; x_offset<width; x_offset++) {
|
||||||
uint8_t r, g, b;
|
uint8_t r, g, b;
|
||||||
|
|
||||||
buf_read(src, x, y, width, &r, &g, &b, depth);
|
if (x_dest + x_offset > dest_width) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
tile_write(dest, x, y, width, rgb_to_tile_2bpp(r, g, b, x, y) ^ 3);
|
buf_read(src, x_src + x_offset, y_src + y_offset, src_width,
|
||||||
|
&r, &g, &b, depth);
|
||||||
|
|
||||||
|
tile_write(dest, x_dest + x_offset, y_dest + y_offset,
|
||||||
|
dest_width, rgb_to_tile_2bpp(r, g, b, x_dest + x_offset,
|
||||||
|
y_dest + y_offset) ^ 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,3 +448,83 @@ void cammy_image_copy(cammy_image *dest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int save_tile_to_file(cammy_tile *tiles, size_t width,
|
||||||
|
size_t height,
|
||||||
|
int file) {
|
||||||
|
static const char *format = "slice%04d.tile";
|
||||||
|
char name[32];
|
||||||
|
int fd;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (snprintf(name, sizeof(name), format, file) < 0) {
|
||||||
|
goto error_snprintf_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stat(name, &st) == 0) {
|
||||||
|
errno = EEXIST;
|
||||||
|
|
||||||
|
goto error_exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fd = open(name, O_CREAT | O_WRONLY, 0644)) < 0) {
|
||||||
|
goto error_open;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write(fd, tiles, (width * height) >> 2) < 0) {
|
||||||
|
goto error_write;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_write:
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
error_open:
|
||||||
|
error_exists:
|
||||||
|
error_snprintf_name:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cammy_image_stripe(uint8_t *buf, size_t width, size_t height, int depth) {
|
||||||
|
cammy_tile *tiles;
|
||||||
|
int file = 0;
|
||||||
|
|
||||||
|
size_t x, y;
|
||||||
|
|
||||||
|
if ((tiles = malloc(CAMMY_SCREEN_SIZE)) == NULL) {
|
||||||
|
goto error_malloc_tiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x=0; x<width; x+=224) {
|
||||||
|
for (y=0; y<height; y+=CAMMY_SCREEN_HEIGHT) {
|
||||||
|
cammy_image_dither_to_tile(tiles, buf,
|
||||||
|
0, 0,
|
||||||
|
x + 32, y,
|
||||||
|
CAMMY_SCREEN_WIDTH,
|
||||||
|
CAMMY_SCREEN_HEIGHT,
|
||||||
|
CAMMY_SCREEN_WIDTH,
|
||||||
|
CAMMY_SCREEN_HEIGHT,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
depth);
|
||||||
|
|
||||||
|
if (save_tile_to_file(tiles, CAMMY_SCREEN_WIDTH,
|
||||||
|
CAMMY_SCREEN_HEIGHT, file++) < 0) {
|
||||||
|
goto error_save_tile_to_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(tiles);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_save_tile_to_file:
|
||||||
|
free(tiles);
|
||||||
|
|
||||||
|
error_malloc_tiles:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ void cammy_photo_import(cammy_photo *dest, uint8_t *src, int depth) {
|
||||||
|
|
||||||
cammy_image_dither_to_tile((cammy_tile *)&dest->tiles,
|
cammy_image_dither_to_tile((cammy_tile *)&dest->tiles,
|
||||||
src,
|
src,
|
||||||
|
0, 0, 0, 0,
|
||||||
|
CAMMY_PHOTO_WIDTH,
|
||||||
|
CAMMY_PHOTO_HEIGHT,
|
||||||
|
CAMMY_PHOTO_WIDTH,
|
||||||
|
CAMMY_PHOTO_HEIGHT,
|
||||||
CAMMY_PHOTO_WIDTH,
|
CAMMY_PHOTO_WIDTH,
|
||||||
CAMMY_PHOTO_HEIGHT,
|
CAMMY_PHOTO_HEIGHT,
|
||||||
depth);
|
depth);
|
||||||
|
|
Loading…
Add table
Reference in a new issue