Last active
April 26, 2024 23:00
-
-
Save juliandescottes/b2a027d3daf9827e538c235e85c0fdac to your computer and use it in GitHub Desktop.
Piskel Feature request: Add unit8_t version to "Export as C file" for single color images #606
This file contains hidden or 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
var export_to_unit8_t_rot = function () { | |
var HTML_NEW_LINE = '
'; | |
var width = pskl.app.piskelController.getWidth(); | |
var height = pskl.app.piskelController.getHeight(); | |
var frameCount = pskl.app.piskelController.getFrameCount(); | |
if (frameCount > 1) { | |
console.error('This export only supports one frame'); | |
} | |
var frame = pskl.utils.LayerUtils.mergeFrameAt(pskl.app.piskelController.getLayers(), 0); | |
var str = 'uint8_t frames[' + width + '] = {' + HTML_NEW_LINE; | |
var lines = []; | |
frame.forEachPixel(function (color, col, row) { | |
if (!lines[col]) { | |
lines[col] = []; | |
} | |
var line = lines[col]; | |
var isTransparent = color === pskl.utils.colorToInt(Constants.TRANSPARENT_COLOR); | |
line[row] = isTransparent ? '0' : '1'; | |
}); | |
str += lines.map(function (line) { | |
return ' B' + line.join(''); | |
}).join(',' + HTML_NEW_LINE); | |
str += HTML_NEW_LINE + '};' + HTML_NEW_LINE; | |
window.open('data:text/html,<textarea style="width:100%;height:100%;">' + str + '</textarea>'); | |
}; | |
export_to_unit8_t_rot(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a bookmarklet: