GithubHelp home page GithubHelp logo

Comments (20)

sutaburosu avatar sutaburosu commented on July 2, 2024

The tool you should use is in this repo, gif2h.py. It has built-in help, but let me know if you have trouble.

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

To run gif2h.py you'll need to add PIL to Python with something like pip3 install PIL.

You'll have to compile heatshrink itself, so the compressor binary is available for use by the Python script.

If you're on Win10, it's probably easiest to do all this from within WSL, especially the "compile heatshrink" part.

If all this sounds too difficult, I can convert some GIFs for you. I have the same username at gmail dot com

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

I have a matrix of ws2812b 60wide x 34 and it is this that I wish to run animated gifs on (the 16x16 is just a test setup I have which is 4 16x16 ws2812b panels for testing)
I,m trying to find something easy to create the arrays with, I thought this would work...
https://www.youtube.com/watch?v=-h9Vm0Ow_Is&t=329s
but maybe its only good for tft but not ws2812b ? dunno
here is my basic test code, I can get still arrays to show on my matrix but not animated gif arrays, the color depth i,m flexible about, i,m using esp32

`#include <pgmspace.h> // Needed to store stuff in Flash
//#include <Adafruit_GFX.h>
//#include <FastLED_NeoMatrix.h>
#include <FastLED.h>

// How many leds in your strip?
#define LED_WIDTH 16
#define LED_HEIGHT 16
#define NUM_LEDS LED_WIDTH*LED_HEIGHT
#define NUM_LEDS 256
//#define RGB 565
#define DATA_PIN 12

// Define the array of leds
CRGB leds[NUM_LEDS];

//uint8_t one[227] PROGMEM= {
// 0x00, 0x05, 0xa3, 0x6a, 0xe2, 0xd5, 0x1e, 0x6c, 0x6a, 0x07, 0x07, 0x80, 0xd5, 0x3e, 0x91, 0x88,
// 0x54, 0x62, 0x09, 0x19, 0x9e, 0xc2, 0x22, 0x32, 0x68, 0x2d, 0x9b, 0xf9, 0x21, 0x92, 0xd6, 0xa1,
// 0x93, 0x6c, 0x54, 0x42, 0x02, 0x00, 0x0b, 0x02, 0x81, 0x82, 0x03, 0x40, 0x60, 0x80, 0x50, 0x90,
// 0x38, 0x28, 0x1c, 0x1c, 0x12, 0x0d, 0x01, 0x80, 0xc1, 0xe1, 0x00, 0x80, 0x70, 0x58, 0x4c, 0x1c,
// 0x0c, 0x0a, 0x14, 0x04, 0x05, 0x07, 0x84, 0xc2, 0xa0, 0x30, 0x18, 0x34, 0x16, 0x12, 0x0e, 0x05,
// 0x0b, 0x84, 0x87, 0xc1, 0x40, 0x60, 0x61, 0x00, 0x50, 0x88, 0x28, 0x10, 0x14, 0x2a, 0x13, 0x02,
// 0x1d, 0x03, 0x85, 0x42, 0x60, 0xb0, 0x68, 0x44, 0x16, 0x0b, 0x0a, 0x11, 0x82, 0x14, 0x82, 0x1d,
// 0x82, 0x81, 0xc2, 0x61, 0x70, 0x68, 0x2c, 0x16, 0x0f, 0x0b, 0x0f, 0x05, 0x20, 0x82, 0x06, 0x02,
// 0x81, 0xc1, 0x61, 0x45, 0x20, 0xa3, 0x10, 0x90, 0x58, 0x5c, 0x0a, 0x07, 0x0b, 0x82, 0x8b, 0x42,
// 0x42, 0xe0, 0x50, 0xb8, 0x5c, 0x1e, 0x17, 0x03, 0x85, 0xc0, 0xe0, 0x70, 0xa8, 0x38, 0x54, 0x1c,
// 0x1e, 0x05, 0x09, 0x84, 0xc2, 0x60, 0x61, 0x40, 0x50, 0xb0, 0x40, 0x38, 0x10, 0xc8, 0x14, 0x1a,
// 0x0f, 0x0a, 0x81, 0x00, 0x02, 0x42, 0xa1, 0x47, 0xe0, 0x61, 0x00, 0x50, 0xb0, 0xf8, 0x28, 0x10,
// 0x10, 0x12, 0xa4, 0x19, 0x34, 0x10, 0xe8, 0x14, 0x2a, 0x14, 0x45, 0x05, 0x02, 0x81, 0x94, 0x41,
// 0xc1, 0x21, 0x10, 0x68, 0x24, 0x06, 0x0d, 0x08, 0x85, 0x42, 0x00, 0xa0, 0x85, 0xe1, 0x46, 0x61,
// 0x1d, 0xe1, 0xc0,
// };

//const unsigned long one[] PROGMEM =
//{
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xf80305, 0x83365c, 0x355998, 0xa52744, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xfe0000, 0xc6182a, 0x2062a8, 0x026fbe, 0x644474, 0xf70406, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xf70406, 0x644474, 0x026fbe, 0x046ebd, 0x46518b, 0xbd1d31, 0xf70306, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xa92640, 0x265fa3, 0x0070c0, 0x0070c0, 0x026fbe, 0x644474, 0xf70406, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xf70406, 0x644474, 0x026fbe, 0x2f5c9d, 0xa02a47, 0x365898, 0x7e3961, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xeb080e, 0x3a5694, 0x026fbe, 0x644474, 0xf70406, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xf70406, 0x644474, 0x026fbe, 0x3a5694, 0xeb080e, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xeb080e, 0x3a5694, 0x026fbe, 0x644474, 0xf70406, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xf70406, 0x644474, 0x026fbe, 0x3a5694, 0xeb080e, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xeb080e, 0x3a5694, 0x026fbe, 0x644474, 0xf70406, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xfa0204, 0xa22846, 0x674272, 0x893358, 0xf30508, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000,
//0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000
//};

void setup() {
//FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(12);

}

void loop() {

//FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = pgm_read_dword(&(one[i]));
}

FastLED.show();
delay(400);
}

`

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

Your code works for me, after fixing <pgmspace.h> to be <avr/pgmspace.h> and uncommenting the 2nd one[] definition.

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

could you insert into the above your own 16x16 animated gif array for me to try, anything will do thanks

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

I mean, that's what the main scintillating_heatstrink.ino sketch in this repo is. Sure, it's got some fluff like an animated background, and commands sent over Serial, but in essence it's what you're asking me to do.

I took a lot of shortcuts to fit all these GIFs into the 32KiB flash on a Nano. Those shortcuts often traded flexibility for less RAM usage. For GIFs larger than 16x16, you're really better off starting from one of the AnimatedGIF libraries, which were intended to be flexible, not tiny.

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

I need the c array over the animated gifs because it needs to run very fast which I believe can only be achieved if the image is run direct from the progmem.
walk

As a way of me understanding how to get my own images into the sketch could you convert the above 16x16 gif into an array and I will drop it into the GIF folder and hopefully see it on my leds thanks.

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

The command ./gif2h.py GIF/walk.gif generated walk.h.txt. I added the .txt extension to be able to upload it here. You should rename it back to walk.h and place it in the GIF folder.

Then edit hsprites.h, add #include "GIF/walk.h" at the top, and add (HSprite*) &HSpr_walk, to the hsprite_list[] array.

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

Yes I think thats working, i commented out all the other .h's apart from walk.h and now see something resembling walk (the reason for my hesitancy is I chose such a rubbish gif to test with that I can barely see the walk haha)

My next question is can the gif2h.py convert 60x34 gif below ? thanks
test6034

...and would the sketch run it ?

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

I,m trying to get the gif2h.py onto my rpi, to this end I have this output...

pi@raspberrypi:~/Downloads/scintillating_heatshrink-master $ python gif2h.py GIF/walk.gif File "gif2h.py", line 127
print(''.join(gif.compression_log), file=h)
^
SyntaxError: invalid syntax

I,m guessing its because I need the heatshrink installed is it ?
thanks

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

You're using Python 2 to run it. It needs Python 3. Try python3 gif2h.py.

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

Thanks, i,m now getting this ...

pi@raspberrypi:/Arduino/libraries/scintillating_heatshrink $ python3 gif2h.py GIF/walk.gif
Traceback (most recent call last):
File "gif2h.py", line 100, in
with subprocess.Popen(this_hs_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
File "/usr/lib/python3.5/subprocess.py", line 676, in init
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
pi@raspberrypi:
/Arduino/libraries/scintillating_heatshrink $

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

pi@raspberrypi:~/Arduino/libraries/scintillating_heatshrink $ python3 gif2h.py GIF/walk.gif Traceback (most recent call last): File "gif2h.py", line 100, in <module> with subprocess.Popen(this_hs_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: File "/usr/lib/python3.5/subprocess.py", line 676, in __init__ restore_signals, start_new_session) File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child raise child_exception_type(errno_num, err_msg) OSError: [Errno 8] Exec format error pi@raspberrypi:~/Arduino/libraries/scintillating_heatshrink $

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

Yes, that's now due to your original suspicion: you need to compile heatshrink. I had forgotten that I included a pre-built x86-64 binary. That's what your Pi is trying to run.

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

Ive downloaded and placed heatshrink into arduino libraries, now what should i do ? thanks

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

....and the scintillating heatshrink sketch compiles

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

Neither heatshrink nor scintillating_heatshrink are Arduino libraries. Putting them in the libraries folder may work, but I think it's more likely to break things. Move them to anywhere other than that folder.

I don't have a Pi to test on, but it runs a Debian-derivative so it's going to be something like:
sudo apt install build-essential
cd /whereever/you/put/heatshrink
make
cp heatshrink /whereever/you/put/scintillating_heatshrink

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

pi@raspberrypi:~ $ sudo apt install build-essential Reading package lists... Done Building dependency tree Reading state information... Done build-essential is already the newest version (12.3). 0 upgraded, 0 newly installed, 0 to remove and 275 not upgraded.

from scintillating_heatshrink.

sutaburosu avatar sutaburosu commented on July 2, 2024

Sorry. I've got to go and wipe my father's ass. This level of hand-holding is more than I am capable of right now. I am 100% serious.

from scintillating_heatshrink.

dallen98 avatar dallen98 commented on July 2, 2024

pi@raspberrypi:~/Desktop/heatshrink $ make cc -c -o heatshrink.od heatshrink.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 cc -c -o heatshrink_encoder.od heatshrink_encoder.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 cc -c -o heatshrink_decoder.od heatshrink_decoder.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 ar -rcs libheatshrink_dynamic.a heatshrink_encoder.od heatshrink_decoder.od cc -o heatshrink heatshrink.od libheatshrink_dynamic.a -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 -L. -lheatshrink_dynamic cc -c -o test_heatshrink_static.os test_heatshrink_static.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=0 cc -c -o heatshrink_encoder.os heatshrink_encoder.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=0 cc -c -o heatshrink_decoder.os heatshrink_decoder.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=0 ar -rcs libheatshrink_static.a heatshrink_encoder.os heatshrink_decoder.os cc -o test_heatshrink_static test_heatshrink_static.os -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=0 -L. -lheatshrink_static cc -c -o test_heatshrink_dynamic.od test_heatshrink_dynamic.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 cc -c -o test_heatshrink_dynamic_theft.od test_heatshrink_dynamic_theft.c -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 cc -o test_heatshrink_dynamic test_heatshrink_dynamic.od -std=c99 -g -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -O3 -DHEATSHRINK_DYNAMIC_ALLOC=1 test_heatshrink_dynamic_theft.od -L. -lheatshrink_dynamic

from scintillating_heatshrink.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.