computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 40607d5802637bb2b8e7cc76304927d634fcedd5
parent 7dfa730f22f543985f7505ed65ab5f45b830fca4
Author: Adam M <[email protected]>
Date:   Sun, 27 Sep 2020 13:41:15 -0500

Custom Blank reverted to saving only one path in the serialization, trying to debug why only 1 gif can be shown

Diffstat:
Msrc/ComputerscareBlank.cpp | 38+++++++-------------------------------
Msrc/animatedGif.hpp | 33+++++++++++++++++++++------------
2 files changed, 28 insertions(+), 43 deletions(-)

diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp @@ -110,13 +110,6 @@ struct ComputerscareBlank : Module { if (paths.size() > 0) { json_object_set_new(rootJ, "path", json_string(paths[0].c_str())); } - json_t *pathsJ = json_array(); - for (int i = 0; i < numFrames; i++) { - json_t *pathJ = json_string(paths[i].c_str()); - json_array_append_new(pathsJ, pathJ); - } - json_object_set_new(rootJ, "paths", pathsJ); - json_object_set_new(rootJ, "width", json_real(width)); json_object_set_new(rootJ, "imageFitEnum", json_integer(imageFitEnum)); @@ -132,31 +125,14 @@ struct ComputerscareBlank : Module { void dataFromJson(json_t *rootJ) override { - json_t *pathsJ = json_object_get(rootJ, "paths"); - if (pathsJ) { - std::string val; - for (int i = 0; i < 4; i++) { - - json_t *pathJ = json_array_get(pathsJ, i); - if (pathJ) { - val = json_string_value(pathJ); - - // currentFormula[i] = val; - //currentTextFieldValue[i] = val; - //paths.push_back(val); - setPath(val, 0); - } - } - } - else { - json_t *pathJ = json_object_get(rootJ, "path"); - if (pathJ) { - //paths.push_back(path) - path = json_string_value(pathJ); - setPath(path); - } + + json_t *pathJ = json_object_get(rootJ, "path"); + if (pathJ) { + //paths.push_back(path) + path = json_string_value(pathJ); + setPath(path); } - + json_t *widthJ = json_object_get(rootJ, "width"); if (widthJ) width = json_number_value(widthJ); diff --git a/src/animatedGif.hpp b/src/animatedGif.hpp @@ -10,6 +10,10 @@ #include "dtpulse.hpp" //#include "stb_image_write.h" +/*+ +credit goes to urraka for this code: +https://gist.github.com/urraka/685d9a6340b26b830d49 +*/ typedef struct gif_result_t { @@ -40,6 +44,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra memset(&g, 0, sizeof(g)); memset(&head, 0, sizeof(head)); + printf("%i\n",g); *frames = 0; @@ -57,8 +62,8 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra prev = gr; gr = (gif_result*) stbi__malloc(sizeof(gif_result)); memset(gr, 0, sizeof(gif_result)); - printf("loading gif frame %i, delay:%i/100s\n", *frames, g.delay); - printf("gr:%i, size:%i\n", gr, sizeof(gif_result)); + //printf("loading gif frame %i, delay:%i/100s\n", *frames, g.delay); + //printf("gr:%i, size:%i\n", gr, sizeof(gif_result)); ++(*frames); } @@ -89,7 +94,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra while (gr) { prev = gr; - printf("p:%i, &p:%i, *p:%i\n", p, &p, *p); + //printf("p:%i, &p:%i, *p:%i\n", p, &p, *p); framePointers.push_back(p); memcpy(p, gr->data, size); p += size; @@ -101,6 +106,8 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra if (prev != &head) STBI_FREE(prev); } } + printf("first frame address p:%i",framePointers[0]); + printf("second frame address p:%i",framePointers[1]); } else { @@ -120,7 +127,8 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra struct AnimatedGifBuddy { std::vector<unsigned char*> framePointers; int imageHandle; - bool initialized=false; + bool initialized = false; + int numFrames = -1; AnimatedGifBuddy() { } @@ -128,6 +136,7 @@ struct AnimatedGifBuddy { imageHandle = animatedGifCreateImage(ctx, filename, 0); } int getHandle() { + printf("imageHandle:%i\n",imageHandle); return imageHandle; } int animatedGifCreateImage(NVGcontext* ctx, const char* filename, int imageFlags) { @@ -139,28 +148,28 @@ struct AnimatedGifBuddy { //img = stbi_load(filename, &w, &h, &n, 4); framePointers = {}; img = stbi_xload(filename, &w, &h, &frame, framePointers); + printf(filename); printf("loaded %i frames\n", framePointers.size()); + numFrames = (int) framePointers.size(); //printVector(framePointers); if (img == NULL) { // printf("Failed to load %s - %s\n", filename, stbi_failure_reason()); return 0; } - printf("width:%i, height:%i\n", w, h); image = nvgCreateImageRGBA(ctx, w, h, imageFlags, img); stbi_image_free(img); - initialized=true; + initialized = true; return image; } void displayGifFrame(NVGcontext* ctx, int frameNumber) { - if(initialized) { - - - const unsigned char* dataAtFrame = framePointers[frameNumber]; - nvgUpdateImage(ctx, imageHandle, dataAtFrame); + if (initialized && frameNumber < numFrames) { + const unsigned char* dataAtFrame = framePointers[frameNumber]; + //printf("displaying frame %i\n",frameNumber); + nvgUpdateImage(ctx, imageHandle, dataAtFrame); } } int getFrameCount() { - return (int)framePointers.size(); + return numFrames; } int getFrameDelay() { return 1764;