Skip to content

Commit

Permalink
v3.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
zesinger authored May 25, 2024
1 parent ee404ed commit 3e18210
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 309 deletions.
416 changes: 116 additions & 300 deletions ColorizingDMD.cpp

Large diffs are not rendered by default.

Binary file modified ColorizingDMD.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions ColorizingDMD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_aruco451d.lib;opencv_bgsegm451d.lib;opencv_bioinspired451d.lib;opencv_calib3d451d.lib;opencv_ccalib451d.lib;opencv_core451d.lib;opencv_datasets451d.lib;opencv_dnn451d.lib;opencv_dnn_objdetect451d.lib;opencv_dnn_superres451d.lib;opencv_dpm451d.lib;opencv_face451d.lib;opencv_features2d451d.lib;opencv_flann451d.lib;opencv_fuzzy451d.lib;opencv_gapi451d.lib;opencv_hdf451d.lib;opencv_hfs451d.lib;opencv_highgui451d.lib;opencv_imgcodecs451d.lib;opencv_imgproc451d.lib;opencv_img_hash451d.lib;opencv_intensity_transform451d.lib;opencv_line_descriptor451d.lib;opencv_mcc451d.lib;opencv_ml451d.lib;opencv_objdetect451d.lib;opencv_optflow451d.lib;opencv_phase_unwrapping451d.lib;opencv_photo451d.lib;opencv_plot451d.lib;opencv_quality451d.lib;opencv_rapid451d.lib;opencv_reg451d.lib;opencv_rgbd451d.lib;opencv_shape451d.lib;opencv_stereo451d.lib;opencv_stitching451d.lib;opencv_structured_light451d.lib;opencv_superres451d.lib;opencv_surface_matching451d.lib;opencv_text451d.lib;opencv_tracking451d.lib;opencv_video451d.lib;opencv_videoio451d.lib;opencv_videostab451d.lib;opencv_xfeatures2d451d.lib;opencv_ximgproc451d.lib;opencv_xobjdetect451d.lib;opencv_xphoto451d.lib; libserialport64.lib;libserialport64.lib; zedmd64.lib;</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_aruco451d.lib;opencv_bgsegm451d.lib;opencv_bioinspired451d.lib;opencv_calib3d451d.lib;opencv_ccalib451d.lib;opencv_core451d.lib;opencv_datasets451d.lib;opencv_dnn451d.lib;opencv_dnn_objdetect451d.lib;opencv_dnn_superres451d.lib;opencv_dpm451d.lib;opencv_face451d.lib;opencv_features2d451d.lib;opencv_flann451d.lib;opencv_fuzzy451d.lib;opencv_gapi451d.lib;opencv_hdf451d.lib;opencv_hfs451d.lib;opencv_highgui451d.lib;opencv_imgcodecs451d.lib;opencv_imgproc451d.lib;opencv_img_hash451d.lib;opencv_intensity_transform451d.lib;opencv_line_descriptor451d.lib;opencv_mcc451d.lib;opencv_ml451d.lib;opencv_objdetect451d.lib;opencv_optflow451d.lib;opencv_phase_unwrapping451d.lib;opencv_photo451d.lib;opencv_plot451d.lib;opencv_quality451d.lib;opencv_rapid451d.lib;opencv_reg451d.lib;opencv_rgbd451d.lib;opencv_shape451d.lib;opencv_stereo451d.lib;opencv_stitching451d.lib;opencv_structured_light451d.lib;opencv_superres451d.lib;opencv_surface_matching451d.lib;opencv_text451d.lib;opencv_tracking451d.lib;opencv_video451d.lib;opencv_videoio451d.lib;opencv_videostab451d.lib;opencv_xfeatures2d451d.lib;opencv_ximgproc451d.lib;opencv_xobjdetect451d.lib;opencv_xphoto451d.lib;libserialport64.lib;zedmd64.lib;Dwmapi.lib</AdditionalDependencies>
<StackReserveSize>3000000</StackReserveSize>
</Link>
<PostBuildEvent>
Expand All @@ -148,7 +148,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_bgsegm451.lib;opencv_bioinspired451.lib;opencv_calib3d451.lib;opencv_ccalib451.lib;opencv_core451.lib;opencv_datasets451.lib;opencv_dnn451.lib;opencv_dnn_objdetect451.lib;opencv_dnn_superres451.lib;opencv_dpm451.lib;opencv_face451.lib;opencv_features2d451.lib;opencv_flann451.lib;opencv_fuzzy451.lib;opencv_gapi451.lib;opencv_hdf451.lib;opencv_hfs451.lib;opencv_highgui451.lib;opencv_imgcodecs451.lib;opencv_imgproc451.lib;opencv_img_hash451.lib;opencv_intensity_transform451.lib;opencv_line_descriptor451.lib;opencv_mcc451.lib;opencv_ml451.lib;opencv_objdetect451.lib;opencv_optflow451.lib;opencv_phase_unwrapping451.lib;opencv_photo451.lib;opencv_plot451.lib;opencv_quality451.lib;opencv_rapid451.lib;opencv_reg451.lib;opencv_rgbd451.lib;opencv_shape451.lib;opencv_stereo451.lib;opencv_stitching451.lib;opencv_structured_light451.lib;opencv_superres451.lib;opencv_surface_matching451.lib;opencv_text451.lib;opencv_tracking451.lib;opencv_video451.lib;opencv_videoio451.lib;opencv_videostab451.lib;opencv_xfeatures2d451.lib;opencv_ximgproc451.lib;opencv_xobjdetect451.lib;opencv_xphoto451.lib;libserialport64.lib; ws2_32.lib; zedmd64.lib; </AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_bgsegm451.lib;opencv_bioinspired451.lib;opencv_calib3d451.lib;opencv_ccalib451.lib;opencv_core451.lib;opencv_datasets451.lib;opencv_dnn451.lib;opencv_dnn_objdetect451.lib;opencv_dnn_superres451.lib;opencv_dpm451.lib;opencv_face451.lib;opencv_features2d451.lib;opencv_flann451.lib;opencv_fuzzy451.lib;opencv_gapi451.lib;opencv_hdf451.lib;opencv_hfs451.lib;opencv_highgui451.lib;opencv_imgcodecs451.lib;opencv_imgproc451.lib;opencv_img_hash451.lib;opencv_intensity_transform451.lib;opencv_line_descriptor451.lib;opencv_mcc451.lib;opencv_ml451.lib;opencv_objdetect451.lib;opencv_optflow451.lib;opencv_phase_unwrapping451.lib;opencv_photo451.lib;opencv_plot451.lib;opencv_quality451.lib;opencv_rapid451.lib;opencv_reg451.lib;opencv_rgbd451.lib;opencv_shape451.lib;opencv_stereo451.lib;opencv_stitching451.lib;opencv_structured_light451.lib;opencv_superres451.lib;opencv_surface_matching451.lib;opencv_text451.lib;opencv_tracking451.lib;opencv_video451.lib;opencv_videoio451.lib;opencv_videostab451.lib;opencv_xfeatures2d451.lib;opencv_ximgproc451.lib;opencv_xobjdetect451.lib;opencv_xphoto451.lib;libserialport64.lib;ws2_32.lib;zedmd64.lib;Dwmapi.lib</AdditionalDependencies>
<StackReserveSize>3000000</StackReserveSize>
</Link>
<PostBuildEvent>
Expand Down
6 changes: 2 additions & 4 deletions OGL_Immediate_2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ int text_CreateTextureCircle(GLFWwindow* glfww)
{
glfwMakeContextCurrent(glfww);

/* Generate texture
*/
/* Generate texture */
GLuint texid;
UINT8 texel[64] = { 0,255,255,255,255,255,255,0,
255,255,255,255,255,255,255,255,
Expand All @@ -26,8 +25,7 @@ int text_CreateTextureCircle(GLFWwindow* glfww)
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);

/* Setup texture filters
*/
/* Setup texture filters */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Expand Down
9 changes: 9 additions & 0 deletions cRom.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,12 @@ typedef struct {
UINT32 hashcode;
} sFrames;

/*typedef struct {
DWORD lastTime[MAX_COLOR_ROTATION];
UINT8 ncol[MAX_COLOR_ROTATION];
UINT16 colors[MAX_LENGTH_COLOR_ROTATION];
UINT8 acfirst[MAX_COLOR_ROTATION];
DWORD timespan[MAX_COLOR_ROTATION];
} sColRot;*/

241 changes: 241 additions & 0 deletions gifenc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
#include "gifenc.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

#pragma warning(disable : 4996)

/* helper to write a little-endian 16-bit number portably */
#define write_num(fd, n) write((fd), (uint8_t []) {(n) & 0xFF, (n) >> 8}, 2)

static uint8_t vga[0x30] = {
0x00, 0x00, 0x00,
0xAA, 0x00, 0x00,
0x00, 0xAA, 0x00,
0xAA, 0x55, 0x00,
0x00, 0x00, 0xAA,
0xAA, 0x00, 0xAA,
0x00, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA,
0x55, 0x55, 0x55,
0xFF, 0x55, 0x55,
0x55, 0xFF, 0x55,
0xFF, 0xFF, 0x55,
0x55, 0x55, 0xFF,
0xFF, 0x55, 0xFF,
0x55, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF,
};

struct Node {
uint16_t key;
struct Node *children[];
};
typedef struct Node Node;

static Node *
new_node(uint16_t key, int degree)
{
Node *node = calloc(1, sizeof(*node) + degree * sizeof(Node *));
if (node)
node->key = key;
return node;
}

static Node *
new_trie(int degree, int *nkeys)
{
Node *root = new_node(0, degree);
/* Create nodes for single pixels. */
for (*nkeys = 0; *nkeys < degree; (*nkeys)++)
root->children[*nkeys] = new_node(*nkeys, degree);
*nkeys += 2; /* skip clear code and stop code */
return root;
}

static void
del_trie(Node *root, int degree)
{
if (!root)
return;
for (int i = 0; i < degree; i++)
del_trie(root->children[i], degree);
free(root);
}

#define write_and_store(s, dst, fd, src, n) \
do { \
write(fd, src, n); \
if (s) { \
memcpy(dst, src, n); \
dst += n; \
} \
} while (0);

static void put_loop(ge_GIF *gif, uint16_t loop);

ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height, int depth, int bgindex, int loop)
{
ge_GIF* gif = calloc(1, sizeof(*gif) + width * height);
if (!gif)
goto no_gif;
gif->w = width; gif->h = height;
gif->bgindex = bgindex;
gif->frame = (uint8_t*)&gif[1];
gif->back = &gif->frame[width*height];
gif->depth = depth;
#ifdef _WIN32
gif->fd = creat(fname, S_IWRITE);
#else
gif->fd = creat(fname, 0666);
#endif
if (gif->fd == -1)
goto no_fd;
#ifdef _WIN32
setmode(gif->fd, O_BINARY);
#endif
write(gif->fd, "GIF89a", 6);
write_num(gif->fd, width);
write_num(gif->fd, height);
unsigned char flags = 0x70; // no GCT, 2^8 color in the original image (don't care), no sort, size of GCT 2^(7+1) (don't care)
write(gif->fd, (uint8_t []) {flags, (uint8_t) bgindex, 0x00}, 3); // background color = bgindex, ratio = 0 (no default ratio)
put_loop(gif, (uint16_t) loop); // add the NETSCAPE 2.0 option for loop (loop = 0 infinite loop)
return gif;
no_fd:
free(gif);
no_gif:
return NULL;
}

static void put_loop(ge_GIF *gif, uint16_t loop)
{
write(gif->fd, (uint8_t []) {'!', 0xFF, 0x0B}, 3);
write(gif->fd, "NETSCAPE2.0", 11);
write(gif->fd, (uint8_t []) {0x03, 0x01}, 2);
write_num(gif->fd, loop);
write(gif->fd, "\0", 1);
}

/* Add packed key to buffer, updating offset and partial.
* gif->offset holds position to put next *bit*
* gif->partial holds bits to include in next byte */
static void put_key(ge_GIF *gif, uint16_t key, int key_size)
{
int byte_offset, bit_offset, bits_to_write;
byte_offset = gif->offset / 8;
bit_offset = gif->offset % 8;
gif->partial |= ((uint32_t) key) << bit_offset;
bits_to_write = bit_offset + key_size;
while (bits_to_write >= 8) {
gif->buffer[byte_offset++] = gif->partial & 0xFF;
if (byte_offset == 0xFF) {
write(gif->fd, "\xFF", 1);
write(gif->fd, gif->buffer, 0xFF);
byte_offset = 0;
}
gif->partial >>= 8;
bits_to_write -= 8;
}
gif->offset = (gif->offset + key_size) % (0xFF * 8);
}

static void end_key(ge_GIF *gif)
{
int byte_offset;
byte_offset = gif->offset / 8;
if (gif->offset % 8)
gif->buffer[byte_offset++] = gif->partial & 0xFF;
if (byte_offset) {
write(gif->fd, (uint8_t []) {byte_offset}, 1);
write(gif->fd, gif->buffer, byte_offset);
}
write(gif->fd, "\0", 1);
gif->offset = gif->partial = 0;
}

static void put_image(ge_GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y, uint8_t* palette)
{
int nkeys, key_size, i, j;
Node *node, *child, *root;
int degree = 1 << gif->depth;

write(gif->fd, ",", 1);
write_num(gif->fd, x);
write_num(gif->fd, y);
write_num(gif->fd, w);
write_num(gif->fd, h);
unsigned char lcd = 0x80 + gif->depth - 1;
write(gif->fd, (uint8_t[]) { lcd }, 1); // gif->depth }, 2);// 0x80 because there is a local color table and there are 2^gif->depth colors in the table, we must write depth-1
// we write the local color table
int ncol = 3 * degree;
write(gif->fd, palette, ncol);
write(gif->fd, (uint8_t[]) { gif->depth }, 1); // gif->depth }, 2);// 0x80 because there is a local color table and there are 2^gif->depth colors in the table, we must write depth-1
root = node = new_trie(degree, &nkeys);
key_size = gif->depth + 1;
put_key(gif, degree, key_size); /* clear code */
for (i = y; i < y+h; i++) {
for (j = x; j < x+w; j++) {
uint8_t pixel = gif->frame[i*gif->w+j] & (degree - 1);
child = node->children[pixel];
if (child) {
node = child;
} else {
put_key(gif, node->key, key_size);
if (nkeys < 0x1000) {
if (nkeys == (1 << key_size))
key_size++;
node->children[pixel] = new_node(nkeys++, degree);
} else {
put_key(gif, degree, key_size); /* clear code */
del_trie(root, degree);
root = node = new_trie(degree, &nkeys);
key_size = gif->depth + 1;
}
node = root->children[pixel];
}
}
}
put_key(gif, node->key, key_size);
put_key(gif, degree + 1, key_size); /* stop code */
end_key(gif);
del_trie(root, degree);
}

static void add_graphics_control_extension(ge_GIF *gif, uint16_t d)
{
uint8_t flags = 0;// 1;// 2 << 2 + 1;
write(gif->fd, (uint8_t []) {'!', 0xF9, 0x04, flags}, 4);
write_num(gif->fd, d);
write(gif->fd, (uint8_t []) {0xFF, 0x00}, 2);
}

void ge_add_frame(ge_GIF *gif, uint8_t* palette, uint16_t delay)
{
uint8_t *tmp;
if (delay || (gif->bgindex >= 0))
add_graphics_control_extension(gif, delay);
put_image(gif, gif->w, gif->h, 0, 0, palette);
gif->nframes++;
if (gif->bgindex < 0) {
tmp = gif->back;
gif->back = gif->frame;
gif->frame = tmp;
}
}

void
ge_close_gif(ge_GIF* gif)
{
write(gif->fd, ";", 1);
close(gif->fd);
free(gif);
}
29 changes: 29 additions & 0 deletions gifenc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef GIFENC_H
#define GIFENC_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ge_GIF {
uint16_t w, h;
int depth;
int bgindex;
int fd;
int offset;
int nframes;
uint8_t *frame, *back;
uint32_t partial;
uint8_t buffer[0xFF];
} ge_GIF;

ge_GIF* ge_new_gif(const char* fname, uint16_t width, uint16_t height, int depth, int bgindex, int loop);
void ge_add_frame(ge_GIF *gif, uint8_t* palette, uint16_t delay);
void ge_close_gif(ge_GIF* gif);

#ifdef __cplusplus
}
#endif
#endif /* GIFENC_H */
7 changes: 4 additions & 3 deletions serumdll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void DownscaleRGB565Frame(UINT16* frame64, UINT16* frame32, UINT width64)
bool ColorizeAFrame(UINT8* vpframe, UINT16** newframe32, UINT16** newframe64, UINT* frameID, bool* is32fr, bool* is64fr)
{
Serum_Colorize(vpframe);
*frameID = pSerum->frameID;
*newframe32 = pSerum->frame32;
*newframe64 = pSerum->frame64;
if (pSerum->width32 > 0) *is32fr = true; else *is32fr = false;
Expand All @@ -92,13 +93,13 @@ bool ColorizeAFrame(UINT8* vpframe, UINT16** newframe32, UINT16** newframe64, UI

bool ColorRotateAFrame(UINT16** newframe32, UINT8** modelt32, UINT16** newframe64, UINT8** modelt64)
{
bool isrot;
isrot = Serum_Rotate();
UINT isrot = Serum_Rotate();
*newframe32 = pSerum->frame32;
*newframe64 = pSerum->frame64;
if (modelt32) *modelt32 = ModifiedElements32;
if (modelt64) *modelt64 = ModifiedElements64;
return isrot;
if (isrot > 0) return true;
return false;
}

void StopLibSerum(void)
Expand Down

0 comments on commit 3e18210

Please sign in to comment.