From eaf55aec004d24ba009756442dee6c5445e70695 Mon Sep 17 00:00:00 2001 From: vince damiani Date: Fri, 4 Nov 2016 16:37:01 +0100 Subject: [PATCH 1/9] multiple-files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Re-arranged html structure, used html5 features. 2. Added multiple images capability, images can be added one-by-one or selecting them with ctrl/cmd from the file dialog. 4. Output for multiple images can be represented by a single byte array or with a byte array for each images, its identifier will be increased with a trailing counter. 3. Added ‘GFXfontBitmap’ support. 4. Other smaller improvement. NOTE: still under testing. --- index.html | 797 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 606 insertions(+), 191 deletions(-) diff --git a/index.html b/index.html index 60b0dee..ef43c5b 100644 --- a/index.html +++ b/index.html @@ -3,161 +3,341 @@ Original utility by: https://jaspervanloenen.com - This is a modified version by: - https://wiredolphine.net + This is the 2nd revision of the modified version by: + https://wiredolphin.net --> image2cpp +
-

image2cpp

-

- - - - - -
-

1. Select image

-
- no image selected - -
or -

1. Paste byte array

-
+
+

image2cpp

+

Click here to visit the Github repo for this tool.

+
+
+
+
+

1. Select image

+
+
+
+

or

+
+
+

1. Paste byte array

+
-
-

-
- -

+

+ + +

2. Image Settings

- * pixels
- - -
- 0 - 255; pixels with brightness above become white, below become black.
- -
- -
-
- Centering the image only works when using a canvas larger than the selected image.
- -

- -
- -

+

+
+
+
+
+
    +
    Only images file type are allowed
    + +
    +
    +
    +
    +
    + + + + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + +
    0 - 255; pixels with brightness above become white, below become black.
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + + + +
    +
    +
    +
    + NOTE: Centering the image only works when using a canvas larger than the selected image. +
    +
    +
    +

    3. Preview

    - -

    - -
    - -

    +

    +
    +
    +
    +

    4. Output

    -
    - Adds some extra Arduino code around the output for easy copy-paste into this example.
    -

    - - -

    -
    - - -
    - If your image looks all messed up on your display, like the image below, try the other mode.
    -
    -

    -

    - -

    +
    +
    +
    +
    +
    + +
    +
    + Adds some extra Arduino code around the output for easy copy-paste into + this example. + If multiple images are loaded, generates a byte array for each and appends a counter to the identifier. +
    +
    + Adds some extra Arduino code around the output for easy copy-paste. + If multiple images are loaded, generates a single byte array. +
    +
    + Creates a GFXbitmapFont formatted ouput. Used by a modified version of the Adafruit GFX library. + GitHub project and example here. +
    + First ASCII character value is used only if a glyph identifier of length equal to 1 is not provided for each image. The value itself will be incremented by 1 for each glyph. +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + +
    +
    +
    +
    + If your image looks all messed up on your display, like the image below, try the other mode. +
    + +
    +
    + + +
    +
    + + From bfe60c590da39ca77a8121450ad0936f09e8dc6a Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 4 Nov 2016 16:57:15 +0100 Subject: [PATCH 2/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5471ad5..c21f364 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,4 @@ You can find a simple Arduino example sketch [over here](https://github.com/javl I wrote the code with my 128x64 pixel monochrome OLED display in mind, but it should work with most similar displays. You might need to change some export settings; those are explained in the tool. ### Credit ### -Initial code by [javl](https://github.com/javl), with aditional code by [wiredolphine](https://github.com/wiredolphin). The example sketch was made by Adafruit. +Initial code by [javl](https://github.com/javl), with aditional code by [wiredolphin](https://github.com/wiredolphin). The example sketch was made by Adafruit. From 88634133401ef9d11f82603024845d2b8bcf1576 Mon Sep 17 00:00:00 2001 From: vince damiani Date: Sat, 5 Nov 2016 08:33:45 +0100 Subject: [PATCH 3/9] integrated image and minor improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example image encoded within html, no more external file required. Added “no files selected” if no images are added. --- index.html | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index ef43c5b..0c273ef 100644 --- a/index.html +++ b/index.html @@ -117,7 +117,8 @@ } #extra-settings-container { } #arduino-identifier, #adafruit-gfx-settings, #all-same-size { display: none; } - .error-msg { color: #ff0000; font-size: 1.2em; display: none; } + .msg { font-size: 1.2em; } + .error-msg { color: #ff0000; display: none; } @@ -151,7 +152,8 @@
      -
      Only images file type are allowed
      +
      Only images file type are allowed
      +
      No files selected
      @@ -279,7 +281,9 @@
      If your image looks all messed up on your display, like the image below, try the other mode.
      - +
      @@ -334,6 +338,8 @@ var allSameSizeButton = document.getElementById('all-same-size'); // error message var onlyImagesFileError = document.getElementById("only-images-file-error"); + // initial message + var noFileSelected = document.getElementById("no-file-selected"); // The variable to hold our images. Global so we can easily reuse it when the // user updates the settings (change canvas size, scale, invert, etc) @@ -549,6 +555,10 @@ var files = evt.target.files; onlyImagesFileError.style.display = "none"; + files.length > 0 ? + noFileSelected.style.display = "none" : + noFileSelected.style.display = "block"; + for (var i = 0, f; f = files[i]; i++) { // Only process image files. @@ -614,6 +624,7 @@ if(imageSizeSettings.children.length == 1) { allSameSizeButton.style.display = "none"; } + if(images.length() == 0) noFileSelected.style.display = "block"; update(); }; From 561f4d7c2e4b673dda5659cea5db1787032b2b3e Mon Sep 17 00:00:00 2001 From: vincent Date: Sat, 5 Nov 2016 08:37:11 +0100 Subject: [PATCH 4/9] Delete error.jpg --- img/error.jpg | Bin 7330 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 img/error.jpg diff --git a/img/error.jpg b/img/error.jpg deleted file mode 100644 index 9109b259bdd7801b2991c0a7ca827a0ec2d2c266..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7330 zcmd5>bxISfo08t=3M|EPg~5&|L; zG73E0vl91T#edU3EdXe+AOHpv783wK2Li`PH|~kbk{G5rh6w)f0RX(PHB2i5wU9l# zq@oiU3GLUoi~yJ?0KmKXe#W009IdJTGM)>03P8Evh>%Kz`O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wx@y zuwFTERByn?YMjWf;Y1!eDCT0UHLz?He0c^<+4x9Yj2}DmG>EKr{Bx)kOl0m0;Lx~y zVF^tsk+y3akbJO4&8#u6X)=eWsE)bI_vYJ?@%qNt7&g&b Date: Sat, 5 Nov 2016 09:03:08 +0100 Subject: [PATCH 5/9] minor improvements and restyles --- index.html | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 0c273ef..62233c5 100644 --- a/index.html +++ b/index.html @@ -42,8 +42,13 @@ } .column { float: left; - min-width: 100px; - margin: 0 20px 0 0; + } + .column-center { + min-width: 160px; + text-align: center; + } + .column-right { + float: right; } .sub-section-title { margin: 0 0 10px; @@ -70,15 +75,15 @@ color: #505050; } .byte-input { - min-width: 400px; - min-height: 200px; + min-width: 360px; + min-height: 160px; } .code-output { width: 100%; height: 200px; } .note { color: #666666; margin: 3px 0; font-size: .9em; line-height: 1.4em; } - button { + button, input[type="file"]::-webkit-file-upload-button { margin: 10px 0; background: #00CB99; border: none; @@ -88,6 +93,10 @@ font-size: .9em; border-radius: 3px; } + input[type="file"]::-webkit-file-upload-button { + padding: 6px 20px; + font-size: 1.6em; + } .generate-button { margin: 40px 0 20px; } @@ -133,10 +142,10 @@

      1. Select image


      -
      +

      or

      -
      +

      1. Paste byte array


      From 26b8a5c628eb73d973d83691e4ab2e9e206bf75f Mon Sep 17 00:00:00 2001 From: vince damiani Date: Sat, 5 Nov 2016 09:24:46 +0100 Subject: [PATCH 6/9] GFXbitmapFont correction --- index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 62233c5..2e606d2 100644 --- a/index.html +++ b/index.html @@ -822,7 +822,8 @@ output_string = output_string.substring(0, output_string.length - 3); output_string = "const unsigned char " - + getIdentifier() + + getIdentifier() + + "Bitmap" + " [] PROGMEM = {" + "\n" + output_string + "\n};\n\n" + "const GFXbitmapGlyph " @@ -858,7 +859,7 @@ + getIdentifier() + "Font PROGMEM = {\n" + "\t(uint8_t *)" - + getIdentifier() + ",\n" + + getIdentifier() + "Bitmap,\n" + "\t(GFXbitmapGlyph *)" + getIdentifier() + "Glyphs,\n" From 94f4166995caee8bfa7d1ee25f21bc51f6280afc Mon Sep 17 00:00:00 2001 From: vince damiani Date: Sat, 5 Nov 2016 09:40:22 +0100 Subject: [PATCH 7/9] GFXbitmapFont correction --- index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.html b/index.html index 2e606d2..c4ee8b4 100644 --- a/index.html +++ b/index.html @@ -846,9 +846,8 @@ image.glyph : String.fromCharCode(firstAschiiChar++)) + "'" + " }" - + " // '" + image.glyph + "'" if(image != images.last()) code += ","; - code += "\n"; + code += " // '" + image.glyph + "'\n"; offset += image.canvas.width; }); code += "};\n"; From df7ccac4829799efa591af6dd396bf8987c4a407 Mon Sep 17 00:00:00 2001 From: vince damiani Date: Sat, 12 Nov 2016 18:49:31 +0100 Subject: [PATCH 8/9] Text input feature: corrected a critic error --- index.html | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index c4ee8b4..834d5b6 100644 --- a/index.html +++ b/index.html @@ -318,6 +318,7 @@ this.length = function() { return collection.length; }; this.first = function() { return collection[0]; }; this.last = function() { return collection[collection.length - 1]; }; + this.getByIndex = function(index) { return collection[index]; }; this.get = function(img) { if(img) { for(var i = 0; i < collection.length; i++) { @@ -515,6 +516,13 @@ // Handle inserting an image by pasting code function handleTextInput(drawMode){ + images = new Images(); + + var canvas = document.createElement('canvas'); + canvas.width = 128; + canvas.height = 64; + canvasContainer.appendChild(canvas); + var input = document.getElementById('byte-input').value; // Remove Arduino code @@ -531,9 +539,9 @@ var list = input.split(","); if(drawMode == 'horizontal'){ - listToImageHorizontal(list); + listToImageHorizontal(list, canvas); }else{ - listToImageVertical(list); + listToImageVertical(list, canvas); } } @@ -887,8 +895,9 @@ } // Use the horizontally oriented list to draw the image - function listToImageHorizontal(list){ + function listToImageHorizontal(list, canvas){ + var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); var imgData = ctx.createImageData(canvas.width, canvas.height); @@ -925,13 +934,16 @@ // inside the img object. This way we can reuse the img object when // we want to scale / invert, etc. ctx.putImageData(imgData, 0, 0); + var img = new Image(); img.src = canvas.toDataURL('image/png'); + images.push(img); } // Use the vertically oriented list to draw the image - function listToImageVertical(list){ + function listToImageVertical(list, canvas){ + var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); // Create a new imageData object, but 90 degrees rotates (height x width) From b4c553cb5637399f33020b781b6b253c6491a494 Mon Sep 17 00:00:00 2001 From: vince damiani Date: Sat, 12 Nov 2016 18:55:16 +0100 Subject: [PATCH 9/9] text input field corrected critic error --- index.html | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 834d5b6..0b20ba1 100644 --- a/index.html +++ b/index.html @@ -148,6 +148,10 @@

      1. Paste byte array


      +
      + x + px +
      @@ -319,6 +323,7 @@ this.first = function() { return collection[0]; }; this.last = function() { return collection[collection.length - 1]; }; this.getByIndex = function(index) { return collection[index]; }; + this.setByIndex = function(index, img) { collection[index] = img; }; this.get = function(img) { if(img) { for(var i = 0; i < collection.length; i++) { @@ -517,11 +522,18 @@ function handleTextInput(drawMode){ images = new Images(); - + var canvas = document.createElement('canvas'); - canvas.width = 128; - canvas.height = 64; + canvas.width = parseInt(document.getElementById("text-input-width").value); + canvas.height = parseInt(document.getElementById("text-input-height").value); + + if(canvasContainer.children.length) { + canvasContainer.removeChild(canvasContainer.firstChild); + } canvasContainer.appendChild(canvas); + + var image = new Image(); + images.setByIndex(0, {"img": image, "canvas" : canvas}); var input = document.getElementById('byte-input').value; @@ -936,7 +948,7 @@ ctx.putImageData(imgData, 0, 0); var img = new Image(); img.src = canvas.toDataURL('image/png'); - images.push(img); + images.first().img = img; } @@ -973,7 +985,7 @@ color = 255; } // color = 0; - drawPixel(x, (page*8)+y, color); + drawPixel(ctx, x, (page*8)+y, color); y--; if(y < 0){ y = 7; @@ -988,7 +1000,9 @@ } // Save the canvas contents inside the img object. This way we can // reuse the img object when we want to scale / invert, etc. + var img = new Image(); img.src = canvas.toDataURL('image/png'); + images.first().img = img; } @@ -1018,18 +1032,15 @@ // Quick and effective way to draw single pixels onto the canvas // using a global 1x1px large canvas - var ctx = images && images.last() ? images.last().ctx : undefined; - if(ctx) { + function drawPixel(ctx, x, y, color) { var single_pixel = ctx.createImageData(1,1); var d = single_pixel.data; - function drawPixel(x, y, color){ - d[0] = color; - d[1] = color; - d[2] = color; - d[3] = 255; - ctx.putImageData(single_pixel, x, y); - }/**/ + d[0] = color; + d[1] = color; + d[2] = color; + d[3] = 255; + ctx.putImageData(single_pixel, x, y); }