add some cruft

This commit is contained in:
randomuser 2021-11-22 16:13:24 -06:00
parent 79a7624639
commit 009978d819
3 changed files with 265 additions and 0 deletions

137
sane_hello.c Normal file
View File

@ -0,0 +1,137 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sane/sane.h>
#include <png.h>
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
} pixel_t;
typedef struct {
pixel_t *pixels;
size_t width;
size_t height;
} bitmap_t;
pixel_t *pixel_at(bitmap_t * bitmap, int x, int y) {
return bitmap->pixels + bitmap->width * y + x;
}
int pngtofile(bitmap_t *bitmap, FILE *fp) {
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
size_t x, y;
png_byte **row_pointers = NULL;
int status = -1;
int pixel_size = 3;
int depth = 8;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info_ptr = png_create_info_struct(png_ptr);
png_set_IHDR(png_ptr, info_ptr,
bitmap->width, bitmap->height,
depth,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
row_pointers = png_malloc(png_ptr, bitmap->height * sizeof (png_byte *));
for(y = 0; y < bitmap->height; y++) {
png_byte *row = png_malloc(png_ptr, sizeof (uint8_t) * bitmap->width * pixel_size);
row_pointers[y] = row;
for(x = 0; x < bitmap->width; x++) {
pixel_t * pixel = pixel_at(bitmap, x, y);
*row++ = pixel->red;
*row++ = pixel->green;
*row++ = pixel->blue;
}
}
png_init_io(png_ptr, fp);
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
status = 0;
return status;
}
int main(void) {
SANE_Status status;
SANE_Option_Descriptor *desc;
SANE_Int vc = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, 1, 10);
SANE_Device **device_list;
SANE_Handle h;
SANE_Parameters p;
SANE_Int cap;
FILE *file = fopen("lsakjfsalkfd.png", "w");
status = sane_init(&vc, NULL);
sane_get_devices(&device_list, SANE_FALSE);
for(int i = 0; device_list[i]; i++) {
printf("%s %s %s %s\n", device_list[i]->name,
device_list[i]->vendor,
device_list[i]->model,
device_list[i]->type);
}
if(device_list[0]) sane_open(device_list[0]->name, &h);
sane_get_parameters(h, &p);
/*
printf("%i %i %i\n", p.pixels_per_line, p.lines, p.format);
*/
const SANE_Byte *storage = malloc(p.bytes_per_line * p.lines);
if(!storage) abort();
desc = sane_get_option_descriptor(h, (SANE_Int)0);
printf("%i\n", desc->cap);
int f;
sane_control_option(h, 0, SANE_ACTION_GET_VALUE, &f, NULL);
cap = f;
for(int i = 0; i < cap; i++) {
desc = sane_get_option_descriptor(h, (SANE_Int)i);
printf("|%i|%s|%s|%s|\n", i, desc->name, desc->title, desc->desc);
}
for(int i = 8; i < 12; i++) {
int hello;
sane_control_option(h, i, SANE_ACTION_GET_VALUE, &hello, NULL);
printf("%i\n", hello);
}
desc = sane_get_option_descriptor(h, 10);
printf("%i\n", desc->unit);
SANE_Int info = 0;
char valone[100];
char valtwo[100];
sane_control_option(h, 10, SANE_ACTION_GET_VALUE, &valone, NULL);
sane_control_option(h, 11, SANE_ACTION_GET_VALUE, &valtwo, NULL);
printf("%s %s\n", valone, valtwo);
// sane_control_option(h,
sane_start(h);
SANE_Int len;
SANE_Byte *buf = storage;
for(;;) {
status = sane_read(h, buf, (SANE_Int)80, (SANE_Int *)&len);
buf += (int)len;
if(status == SANE_STATUS_EOF) break;
}
bitmap_t *bitmap = malloc(sizeof *bitmap);
bitmap->width = p.pixels_per_line;
bitmap->height = p.lines;
bitmap->pixels = (pixel_t *)storage;
pngtofile(bitmap, file);
sane_close(h);
sane_exit();
return 0;
}

74
test.py Normal file
View File

@ -0,0 +1,74 @@
#!/usr/bin/python
import sys
red = '\033[31m'
blue = '\033[34m'
green = '\033[32m'
reset = '\033[0m'
class name:
def __init__(self, name, objtype):
self.name = name
self.objtype = objtype
self.children = {}
self.parents = {}
self.keys = {}
def add(self, key, value):
self.keys[key] = value
def str(self):
return f"{self.objtype} {self.name}: {self.keys}"
def child(self, ind, child):
self.children[ind] = child
def parent(self, ind, parent):
self.parents[ind] = parent
fd = open(sys.argv[1], "r")
lines = [i.rstrip() for i in fd.readlines()]
objects = {}
cobj = None
for i in lines:
if i == '': continue
indented = i[0:2] == ' '
if indented:
splitted = i[2:].split(': ')
cobj.add(splitted[0], splitted[1])
else:
if cobj != None:
objects[cobj.name] = cobj
cobj = name(
i.split(' ')[1][0:-1],
i.split(' ')[0]
)
for i in objects:
try:
groups = objects[i].keys['inherit'].split(' ')
order = objects[i].keys['inherit_order'].split(' ')
except KeyError:
continue
for j, k in zip(groups, order):
objects[j].child(k, objects[i])
objects[i].parent(k, objects[j])
entrypoint = sys.argv[2]
def print_tree(obj, ind):
try: filename = obj.keys['file']
except KeyError: filename = None
try: index = obj.keys['inherit_order']
except KeyError: index = None
print((" " * (ind - 1)) + f"[{red}{index}{reset}] {green}{obj.name}{reset}, {blue}{filename}{reset}")
for i in obj.children:
print_tree(obj.children[i], ind + 1)
print_tree(objects[entrypoint], 1)
fd.close()

54
test2.py Normal file
View File

@ -0,0 +1,54 @@
import os
import sys
args = sys.argv
minimum = int(sys.argv[1])
maximum = int(sys.argv[2])
outputgroup = sys.argv[4]
filelist = []
for i in os.listdir():
if ".png" in i: filelist.append(i)
filelist.sort()
groups = 0
files = 0
idx = 1
autogen = int(sys.argv[3])
data = [filelist[0], filelist[-1]]
splitted = [data[0].split('-'), data[1].split('-')]
splitted = [int(splitted[0][1]), int(splitted[1][1])]
print(f"cat {outputgroup}:")
print(" null: yes")
print("")
for i in range(max(minimum, splitted[0]), min(maximum, splitted[1]) + 1):
test = [j for j in filelist if "0000-" + str(i).zfill(4) in j]
if len(test) == 1:
print(f"rec g{str(autogen).zfill(2)}-f{str(files).zfill(4)}:")
print(f" file: {test[0]}")
print(f" inherit: {outputgroup}")
print(f" inherit_order: {idx}")
print("")
files += 1
idx += 1
else:
internal_idx = 1
print(f"cat g{str(autogen).zfill(2)}-g{str(groups).zfill(4)}:")
print(f" inherit: {outputgroup}")
print(f" inherit_order: {idx}")
print("")
for j in test:
print(f"rec g{str(autogen).zfill(2)}-f{str(files).zfill(4)}:")
print(f" file: {j}")
print(f" inherit: g{str(autogen).zfill(2)}-g{str(groups).zfill(4)}")
print(f" inherit_order: {internal_idx}")
print("")
internal_idx += 1
files += 1
idx += 1
groups += 1