-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#--------------------------------------------------------------------------------- | ||
# Clear the implicit built in rules | ||
#--------------------------------------------------------------------------------- | ||
.SUFFIXES: | ||
#--------------------------------------------------------------------------------- | ||
# Make sure that the FXCGSDK environment variable is set! | ||
#--------------------------------------------------------------------------------- | ||
include ${FXCGSDK}/toolchain/prizm_rules | ||
|
||
|
||
#--------------------------------------------------------------------------------- | ||
# TARGET is the name of the output | ||
# BUILD is the directory where object files & intermediate files will be placed | ||
# SOURCES is a list of directories containing source code | ||
# INCLUDES is a list of directories containing extra header files | ||
#--------------------------------------------------------------------------------- | ||
TARGET := $(notdir $(CURDIR)) | ||
BUILD := build | ||
SOURCES := src extern | ||
DATA := data | ||
INCLUDES := extern | ||
|
||
#--------------------------------------------------------------------------------- | ||
# options for code and add-in generation | ||
#--------------------------------------------------------------------------------- | ||
|
||
MKG3AFLAGS := -n basic:"Bad Apple!!" -i uns:../unselected.bmp -i sel:../selected.bmp | ||
|
||
# Optional: add -flto to CFLAGS and LDFLAGS to enable link-time optimization | ||
# (LTO). Doing so will usually allow the compiler to generate much better code | ||
# (smaller and/or faster), but may expose bugs in your code that don't cause | ||
# any trouble without LTO enabled. | ||
CFLAGS = -Os -Wall $(MACHDEP) $(INCLUDE) -ffunction-sections -fdata-sections | ||
CXXFLAGS = $(CFLAGS) -fno-exceptions | ||
|
||
LDFLAGS = $(MACHDEP) -T$(FXCGSDK)/toolchain/prizm.x -Wl,-static -Wl,-gc-sections | ||
|
||
#--------------------------------------------------------------------------------- | ||
# any extra libraries we wish to link with the project | ||
#--------------------------------------------------------------------------------- | ||
LIBS := -lc -lfxcg -lgcc | ||
|
||
#--------------------------------------------------------------------------------- | ||
# list of directories containing libraries, this must be the top level containing | ||
# include and lib | ||
#--------------------------------------------------------------------------------- | ||
LIBDIRS := | ||
|
||
#--------------------------------------------------------------------------------- | ||
# no real need to edit anything past this point unless you need to add additional | ||
# rules for different file extensions | ||
#--------------------------------------------------------------------------------- | ||
ifneq ($(BUILD),$(notdir $(CURDIR))) | ||
#--------------------------------------------------------------------------------- | ||
|
||
export OUTPUT := $(CURDIR)/$(TARGET) | ||
|
||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ | ||
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) | ||
|
||
export DEPSDIR := $(CURDIR)/$(BUILD) | ||
|
||
#--------------------------------------------------------------------------------- | ||
# automatically build a list of object files for our project | ||
#--------------------------------------------------------------------------------- | ||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) | ||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) | ||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) | ||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) | ||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) | ||
|
||
#--------------------------------------------------------------------------------- | ||
# use CXX for linking C++ projects, CC for standard C | ||
#--------------------------------------------------------------------------------- | ||
ifeq ($(strip $(CPPFILES)),) | ||
export LD := $(CC) | ||
else | ||
export LD := $(CXX) | ||
endif | ||
|
||
export OFILES := $(addsuffix .o,$(BINFILES)) \ | ||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ | ||
$(sFILES:.s=.o) $(SFILES:.S=.o) | ||
|
||
#--------------------------------------------------------------------------------- | ||
# build a list of include paths | ||
#--------------------------------------------------------------------------------- | ||
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ | ||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | ||
-I$(CURDIR)/$(BUILD) -I$(LIBFXCG_INC) | ||
|
||
#--------------------------------------------------------------------------------- | ||
# build a list of library paths | ||
#--------------------------------------------------------------------------------- | ||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ | ||
-L$(LIBFXCG_LIB) | ||
|
||
export OUTPUT := $(CURDIR)/$(TARGET) | ||
.PHONY: all clean | ||
|
||
#--------------------------------------------------------------------------------- | ||
all: $(BUILD) | ||
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile | ||
|
||
$(BUILD): | ||
@mkdir $@ | ||
|
||
#--------------------------------------------------------------------------------- | ||
export CYGWIN := nodosfilewarning | ||
clean: | ||
$(call rmdir,$(BUILD)) | ||
$(call rm,$(OUTPUT).bin) | ||
$(call rm,$(OUTPUT).g3a) | ||
|
||
#--------------------------------------------------------------------------------- | ||
else | ||
|
||
DEPENDS := $(OFILES:.o=.d) | ||
|
||
#--------------------------------------------------------------------------------- | ||
# main targets | ||
#--------------------------------------------------------------------------------- | ||
$(OUTPUT).g3a: $(OUTPUT).bin | ||
$(OUTPUT).bin: $(OFILES) | ||
|
||
|
||
-include $(DEPENDS) | ||
|
||
#--------------------------------------------------------------------------------- | ||
endif | ||
#--------------------------------------------------------------------------------- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"arguments": [ | ||
"/usr/bin/sh3eb-elf-gcc", | ||
"-Os", | ||
"-Wall", | ||
"-iquote", | ||
"/home/adame/Documents/BACG50/include", | ||
"-I/home/adame/Documents/BACG50/build", | ||
"-I/home/adame/Documents/libfxcg//include", | ||
"-ffunction-sections", | ||
"-fdata-sections", | ||
"-c", | ||
"-o", | ||
"fastlz.o", | ||
"/home/adame/Documents/BACG50/src/fastlz.c" | ||
], | ||
"directory": "/home/adame/Documents/BACG50", | ||
"file": "/home/adame/Documents/BACG50/src/fastlz.c", | ||
"output": "/home/adame/Documents/BACG50/fastlz.o" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# tool macros | ||
CC ?= gcc | ||
CFLAGS := -O2 -s | ||
|
||
compress2: | ||
$(CC) $(CFLAGS) compress2.c ../extern/fastlz.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from PIL import Image | ||
import numpy as np | ||
import os | ||
from natsort import natsorted | ||
|
||
def apply_runlength(arr, filename): | ||
current_clr = True # true is white, false is black | ||
runlength = 0 | ||
newarr = np.array([], dtype='i') | ||
|
||
pixel_num = 1 | ||
|
||
for pixel in np.nditer(arr): | ||
if pixel_num % 2 == 0: | ||
pixel_num += 1 | ||
continue | ||
|
||
if pixel == current_clr: | ||
runlength += 1 | ||
pixel_num += 1 | ||
else: | ||
newarr = np.append(newarr, runlength) | ||
|
||
# set runlength to 1 and not 0, because we should count this pixel | ||
# for the next run | ||
runlength = 1 | ||
current_clr = not current_clr | ||
pixel_num += 1 | ||
|
||
# account for the last run | ||
newarr = np.append(newarr, runlength) | ||
|
||
return newarr | ||
|
||
|
||
|
||
def reverse_runlength(arr, dimensions): | ||
newarr = np.array([], dtype='b') | ||
|
||
current = True | ||
|
||
# convert runs back into binary 1s and 0s | ||
for run in arr: | ||
newarr = np.append(newarr, [current, 0] * run) | ||
current = not current | ||
|
||
# reshape to original dimensions | ||
newarr = np.reshape(newarr, dimensions) | ||
|
||
return newarr.astype(bool) | ||
|
||
|
||
|
||
def compress(directory, filename, save_filename): | ||
# open a file | ||
img = Image.open(directory + filename, 'r') | ||
data = np.array(img) | ||
|
||
# runlength compress the file | ||
compressed = apply_runlength(data, filename) | ||
|
||
# save compressed information to new file | ||
with open(save_filename, mode='a') as file: | ||
np.savetxt(file, compressed, fmt='%s', newline=' ') | ||
|
||
|
||
|
||
def decompress(filename): | ||
# load compressed data | ||
compressed = np.loadtxt(filename).astype(int) | ||
|
||
# reverse runlength encoding | ||
decompressed = reverse_runlength(compressed, (90, 119)) | ||
|
||
# save new array to image | ||
img = Image.fromarray(decompressed) | ||
img.save("decompressed.png") | ||
|
||
|
||
|
||
def main(): | ||
choice = input("Do you want to compress or decompress? ") | ||
|
||
if choice == "compress": | ||
directory = input("Please enter directory where frames are: ") + "/" | ||
save_filename = input("Please enter filename for compressed data: ").strip() | ||
|
||
framelist = os.listdir(directory) | ||
framelist = natsorted(framelist) | ||
|
||
num = 0 | ||
for frame_filename in framelist: | ||
compress(directory, frame_filename, save_filename) | ||
num += 1 | ||
print(f"Compressed {num} out of {len(framelist)}") | ||
|
||
elif choice == "decompress": | ||
filename = input("Filename: ") | ||
decompress(filename) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "../extern/fastlz.h" | ||
|
||
#define BLOCK_SIZE 4096 | ||
|
||
void compress(const char *input_filename, const char *out_filename) | ||
{ | ||
FILE *src = fopen(input_filename, "r"); | ||
|
||
// overwrite destination file if it already exists | ||
FILE *dst = fopen(out_filename, "w"); | ||
FILE *length_list = fopen("length_list.txt", "w"); | ||
|
||
// buffers | ||
char *comp_buffer = (char *)malloc(BLOCK_SIZE * 2); | ||
char decomp_buffer[BLOCK_SIZE + 1]; // leaving room for NULL terminator | ||
size_t decomp_buffer_size; | ||
size_t comp_buffer_size; | ||
|
||
// compress | ||
do { | ||
decomp_buffer_size = fread(decomp_buffer, 1, BLOCK_SIZE, src); | ||
comp_buffer_size = fastlz_compress_level(1, decomp_buffer, strlen(decomp_buffer), comp_buffer); | ||
|
||
fprintf(length_list, "%du\n", comp_buffer_size); | ||
fwrite(comp_buffer, 1, comp_buffer_size, dst); | ||
printf("Compressed: %lu bytes\n", ftell(src)); | ||
} while (decomp_buffer_size >= BLOCK_SIZE); | ||
|
||
// clean up | ||
free(comp_buffer); | ||
fclose(src); | ||
fclose(dst); | ||
fclose(length_list); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
/* COMPRESS DATA */ | ||
char input_filename[128]; | ||
char out_filename[128]; | ||
|
||
printf("Please enter the input filename: "); | ||
scanf("%s", input_filename); | ||
|
||
printf("Please enter the output filename: "); | ||
scanf("%s", out_filename); | ||
|
||
compress(input_filename, out_filename); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.