diff --git a/tools/biosCRC32Patcher.htm b/tools/biosCRC32Patcher.htm index d5830c2..94757da 100644 --- a/tools/biosCRC32Patcher.htm +++ b/tools/biosCRC32Patcher.htm @@ -25,7 +25,7 @@
-

CC0: public domain. Version 1.1, 20230626.1

+

CC0: public domain. Version 1.2, 20240514.1

diff --git a/tools/bootLogoChanger.htm b/tools/bootLogoChanger.htm index 1e73a81..576d945 100644 --- a/tools/bootLogoChanger.htm +++ b/tools/bootLogoChanger.htm @@ -24,15 +24,17 @@
-

CC0: public domain. Version 1.5, 20231019.1

+

CC0: public domain. Version 1.6, 20240514.1

diff --git a/tools/buttonMappingChanger.htm b/tools/buttonMappingChanger.htm index 28a09b1..e267bb4 100644 --- a/tools/buttonMappingChanger.htm +++ b/tools/buttonMappingChanger.htm @@ -26,11 +26,11 @@
-

CC0: public domain. Version 1.5, 20231019.1

+

CC0: public domain. Version 1.6, 20240514.1

\ No newline at end of file diff --git a/tools/firmwareVersionChecker.htm b/tools/firmwareVersionChecker.htm index 4c52d2c..e39c854 100644 --- a/tools/firmwareVersionChecker.htm +++ b/tools/firmwareVersionChecker.htm @@ -24,13 +24,13 @@
-

CC0: public domain. Version 1.2, 20231019.1

+

CC0: public domain. Version 1.3, 20240514.1

diff --git a/tools/genericImageTool.htm b/tools/genericImageTool.htm index 15f7973..a9d7f11 100644 --- a/tools/genericImageTool.htm +++ b/tools/genericImageTool.htm @@ -15,8 +15,8 @@

Step 1: Select Operating Mode

This tool can operate in two main modes - you can use it to convert from an SF2000 format to RGB888/RGBA, or you can use it to convert to an SF2000 format from RGB888/RGBA. Choose the mode you want, and follow the next instruction that appears.

-
- +
+
@@ -25,24 +25,28 @@ // Global Variables // ================ - var sf2000ImageData; // Holds binary data for images coming from the SF2000 - var userImageData; // Holds the original data of the PNG/JPEG coming from the user - var previewCanvasData; // Holds the binary data used for drawing to our preview canvases - var outputImageWidth = 320; // The width the user wants to interpret the image from the SF2000 as, default to 320px - var outputImageHeight = 240; // The height the user wants to interpret the image from the SF2000 as, default to 240px - var imageFormat = "RGB565"; // The format the user wants to interpret the image coming from the SF2000 as, default to RGB565 - var fileName; // Holds the name of the user-selected file - var userScaleMode = "scale"; // The type of scaling the user wants for their image, default to preset scales - var userScaleFactor = "1x"; // Holds the currently selected scaling factor, defaults to 1x - var userFitWidth = 320; // Holds the current fit-to width, default to 320px - var userFitHeight = 240; // Holds the current fit-to height, default to 240px - var userFilterType = "Nearest Neighbour"; // Holds the currently selected filter type, defaulting to Nearest Neighbour + let sf2000ImageData; // Holds binary data for images coming from the SF2000 + let userImageData; // Holds the original data of the PNG/JPEG coming from the user + let previewCanvasData; // Holds the binary data used for drawing to our preview canvases + let outputImageWidth = 320; // The width the user wants to interpret the image from the SF2000 as, default to 320px + let outputImageHeight = 240; // The height the user wants to interpret the image from the SF2000 as, default to 240px + let fileName; // Holds the name of the user-selected file + let imageFormat = "RGB565"; // The format the user wants to interpret the image coming from the SF2000 as, default to RGB565 + let ditherEnabled = false; // Holds whether the user wants to enable dithering for RGB565 mode or not + let ditherStrength = 0.2; // Holds the selected dither strength value - 0.2 seems to be a good general balance + let userScaleMode = "scale"; // The type of scaling the user wants for their image, default to preset scales + let userScaleFactor = "1x"; // Holds the currently selected scaling factor, defaults to 1x + let fitToWidthEnabled = true; // Holds whether the "fit to width" checkbox is ticked or not + let userFitWidth = 320; // Holds the current fit-to width, default to 320px + let fitToHeightEnabled = true; // Holds whether the "fit to width" checkbox is ticked or not + let userFitHeight = 240; // Holds the current fit-to height, default to 240px + let userFilterType = "Nearest Neighbour"; // Holds the currently selected filter type, defaulting to Nearest Neighbour // When the tool loads, add some event watchers for when the Step 1 radio // buttons change; and depending on which mode the user selects, begin // rewriting the rest of the page... - var modes = document.getElementsByName("toolMode"); - for (var i = 0; i < modes.length; i++) { + const modes = document.getElementsByName("toolMode"); + for (let i = 0; i < modes.length; i++) { modes[i].addEventListener("change", function() { // Clear out any HTML that might already exist after Step 1, just so @@ -69,10 +73,10 @@ // Create the new section, add our heading and our instruction // paragraph... - var html = "

Step 2: Select SF2000 Image File

Select the SF2000 image file you want to convert from. If you need help choosing the image you want to convert, you can find a reference to all of the used UI images in my overview of the SF2000 here.

"; + let html = "

Step 2: Select SF2000 Image File

Select the SF2000 image file you want to convert from. If you need help choosing the image you want to convert, you can find a reference to all of the used UI images in my overview of the SF2000 here.

"; // Add our file chooser... - html += "
"; + html += "
"; // Close off our section... html += "
"; @@ -83,7 +87,7 @@ document.getElementById("steps").insertAdjacentHTML("beforeend", html); // Attach our event handler to our new file input control... - var sf2000ImageInput = document.getElementById("inputImage"); + const sf2000ImageInput = document.getElementById("inputImage"); sf2000ImageInput.addEventListener("change", function() { // The user has chosen a new file; it should be a binary blob we can @@ -92,22 +96,22 @@ // Now let's check to make sure the data URI indicates // "application/octet-stream"... - var frImage = new FileReader(); + const frImage = new FileReader(); fileName = event.target.files[0].name; frImage.readAsDataURL(event.target.files[0]); frImage.onload = function(event) { - var fileData = event.target.result; - var dataType = fileData.substring(5, fileData.indexOf(";")); + const fileData = event.target.result; + const dataType = fileData.substring(5, fileData.indexOf(";")); if (dataType === "application/octet-stream") { // The user selected a file that appears to contain binary data; // it's a good candidate for image interpretation so! Extract the // binary data, store it in our sf2000ImageData global, and start // setting up Step 3... - var base64Data = fileData.substring(fileData.indexOf(",") + 1); - var binaryData = atob(base64Data); + const base64Data = fileData.substring(fileData.indexOf(",") + 1); + const binaryData = atob(base64Data); sf2000ImageData = new Uint8Array(binaryData.length); - for (var i = 0; i < binaryData.length; i++) { + for (let i = 0; i < binaryData.length; i++) { sf2000ImageData[i] = binaryData.charCodeAt(i); } @@ -137,10 +141,10 @@ function setupStepTwo_To() { // Start our new section, add our header and our instructions... - var html = "

Step 2: Select RGB888/RGBA Image File

Select the image file you want to convert to an SF2000 image format. You can select either a PNG or JPEG format image. Transparency is respected for PNGs, but only if outputting to the BGRA output format.

"; + let html = "

Step 2: Select RGB888/RGBA Image File

Select the image file you want to convert to an SF2000 image format. You can select either a PNG or JPEG format image. Transparency is respected for PNGs, but only if outputting to the BGRA output format.

"; // Add our file chooser... - html += "
"; + html += "
"; // Close our section... html += "
"; @@ -151,17 +155,16 @@ document.getElementById("steps").insertAdjacentHTML("beforeend", html); // Attach our event handler to our new file input control... - var userImageInput = document.getElementById("inputImage"); + const userImageInput = document.getElementById("inputImage"); userImageInput.addEventListener("change", function() { // The user has chosen a new file; it should be either a PNG or JPEG - // image for converting to an SF2000 binary image format... - - // First let's clear any old messages... + // image for converting to an SF2000 binary image format. First let's + // clear any old messages... document.getElementById("step2Messages").innerHTML = ""; // Now let's read in the file... - var frImage = new FileReader(); + const frImage = new FileReader(); fileName = event.target.files[0].name; frImage.readAsDataURL(event.target.files[0]); frImage.onload = function(event) { @@ -173,7 +176,6 @@ // Whoops! Doesn't look like the user provided a PNG or a JPEG! setMessage("error", "step2Messages", "ERROR: The selected file does not appear to be either a PNG or JPEG image; please make sure you're selecting an appropriate image file."); return; - } // Now we're going to load the file's data into an Image object, so @@ -335,15 +337,15 @@ // Create the new section, add our heading and our instruction // paragraph... - var html = "

Step 3: Set Data Interpretation Options

As the image files on the SF2000 are raw binary blobs, there's no information stored in them to say what their width or height is, what format the pixel information is stored in, etc.. Therefore, it is up to you to specify those details yourself, which you can do using the options below.

A preview of the image will appear below the options, reflecting the current options; the preview has a white dash outline so you can better judge where the bounds of transparent images are. Below the preview image is a \"Download\" button you can use to download the image as a PNG.

Depending on the size of the file you selected, this tool may recognise it as a \"known\" file from the SF2000, and if so the options below will have been set automatically for you. If not, or if the options are automatically set incorrectly, here's a brief description of what each option does:

Image Format:
Specifies the data format for each pixel in the image. There are two image formats currently used by the SF2000 - RGB565 (used for most of the \"basic\" UI elements, including main backgrounds, etc.), and BGRA (used for anything that requires transparency, such as the system logos on the main menu, etc.).
Width:
Specifies the width of the image in pixels.
Height:
Specifies the height of the image in pixels.
"; + let html = "

Step 3: Set Data Interpretation Options

As the image files on the SF2000 are raw binary blobs, there's no information stored in them to say what their width or height is, what format the pixel information is stored in, etc.. Therefore, it is up to you to specify those details yourself, which you can do using the options below.

A preview of the image will appear below the options, reflecting the current options; the preview has a white dash outline so you can better judge where the bounds of transparent images are. Below the preview image is a \"Download\" button you can use to download the image as a PNG.

Depending on the size of the file you selected, this tool may recognise it as a \"known\" file from the SF2000, and if so the options below will have been set automatically for you. If not, or if the options are automatically set incorrectly, here's a brief description of what each option does:

Image Format:
Specifies the data format for each pixel in the image. There are two image formats currently used by the SF2000 - RGB565 (used for most of the \"basic\" UI elements, including main backgrounds, etc.), and BGRA (used for anything that requires transparency, such as the system logos on the main menu, etc.).
Width:
Specifies the width of the image in pixels.
Height:
Specifies the height of the image in pixels.
"; // Next, let's add our image controls; a select list for the image // format, and number inputs for the interpreted width and height... - html += "
"; - html += "
"; - html += "
"; - html += "
"; - html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; // Next, we'll add the image preview... html += "
"; @@ -359,18 +361,12 @@ document.getElementById("steps").insertAdjacentHTML("beforeend", "
"); document.getElementById("steps").insertAdjacentHTML("beforeend", html); - // Now, add our interactivity by attaching our event handlers; first up, - // our format selector... - var ifField = document.getElementById("imageFormat"); - ifField.addEventListener("change", function() { - // Set our global imageFormat to the new value, and update our - // preview... - imageFormat = this.value; - convertFromSF2000AndRender(); - }); - - // Next our width and height fields... - var whFields = [document.getElementById("outputImageWidth"), document.getElementById("outputImageHeight")]; + // Now, attach some event handlers to our form controls; these will + // handle some of the logic for how I want the controls to behave. First + // up, our width and height fields - I have some limitations on the + // types of things I want typed in them, and how I want them to be + // changed... + const whFields = [document.getElementById("outputImageWidth"), document.getElementById("outputImageHeight")]; whFields.forEach(field => { // When a key is pressed, only allow the events through under certain @@ -390,25 +386,39 @@ if (this.value === "" || this.value === "0") { this.value = "1"; } - if (this.id == "outputImageWidth") { - outputImageWidth = this.value; - } - else { - outputImageHeight = this.value; - } - convertFromSF2000AndRender(); }); }); - // And attach the event handler for the download button... - var downloadButton = document.getElementById("sf2000Download"); + // Next, attach the event handler for the download button... + const downloadButton = document.getElementById("sf2000Download"); downloadButton.addEventListener("click", function() { - var canvas = document.getElementById("processFilePreview"); + const canvas = document.getElementById("processFilePreview"); canvas.toBlob(function(blob) { downloadToBrowser(blob, "image/png", fileName + ".png"); }); }); + // That's the end of the specific UI event handlers; the final handler + // we'll set up is a general event handler for the entire form itself. + // Any time *any* of the controls in the form change, that event will + // bubble-up and trigger this handler, where we'll get the current state + // of the form's controls, and use it to re-convert and re-render the + // image using the current settings... + const fromSF2000Form = document.getElementById("fromSF2000ImageSettings"); + fromSF2000Form.addEventListener("change", function() { + + // Get the state of all of the form's controls... + const formData = Object.fromEntries(new FormData(fromSF2000Form)); + + // Set our general globals from the current form state... + imageFormat = formData.imageFormat; + outputImageWidth = formData.outputImageWidth; + outputImageHeight = formData.outputImageHeight; + + // And re-convert and re-render based on those globals... + convertFromSF2000AndRender(); + }); + // We're nearly ready to wrap up Step 3; all that's left is to perform // our initial conversion and rendering... convertFromSF2000AndRender(); @@ -423,7 +433,7 @@ // from a known image, we already have our width and height this time, // and so we can just get on to rendering the HTML. Create our new // section, add its heading and instruction paragraphs... - html = "

Step 3: Set Conversion Options

The options below control how your image is converted for use on the SF2000. A preview of the image will appear below the options, reflecting their current settings; the preview has a white dash outline so you can better judge where the bounds of transparent images are. Below the preview image is a \"Download\" button you can use to download the image as binary blob for the SF2000. If you name your input image like name.extension.extension (e.g., c1eac.pal.png), then the download will automatically be named like name.extension (e.g., c1eac.pal); this may help to speed up your workflow.

Here's a brief description of what each option does:

Image Format:
Specifies the data format for the output image. There are two image formats currently used by the SF2000 - RGB565 (used for most of the \"basic\" UI elements, including main backgrounds, etc.), and BGRA (used for anything that requires transparency, such as the system logos on the main menu, etc.). If you're not sure which format to choose, refer to my list of images used by the SF2000.
Scaling:
One of two available scaling modes for your input image; the \"Scaling\" option lets you scale your image maintaining aspect ratio amongst several common sizes (e.g., 1x scaling to maintain the input image size, 2x scaling to double it, etc.)
Fit to:
The other available scaling mode; this will scale your image to the specified width and height, without maintaining aspect ratio. This will allow you to scale an image to any dimension you want, but it'll be up to you to do your own aspect ratio calculations.
Filter Type:
When scaling an image by anything other than 1x, specifies the type of image filtering to use. \"Nearest Neighbour\" will give sharp pixel scaling but only at integer upscales; any other scale will appear aliased. \"Bilinear\" will give a fuzzier scale, but it works better for non-integer scale factors and for downscaling.
"; + let html = "

Step 3: Set Conversion Options

The options below control how your image is converted for use on the SF2000. A preview of the image will appear below the options, reflecting their current settings; the preview has a white dash outline so you can better judge where the bounds of transparent images are. Below the preview image is a \"Download\" button you can use to download the image as binary blob for the SF2000. If you name your input image like name.extension.extension (e.g., c1eac.pal.png), then the download will automatically be named like name.extension (e.g., c1eac.pal); this may help to speed up your workflow.

Here's a brief description of what each option does:

Image Format:
Specifies the data format for the output image. There are two image formats currently used by the SF2000 - RGB565 (used for most of the \"basic\" UI elements, including main backgrounds, etc.), and BGRA (used for anything that requires transparency, such as the system logos on the main menu, etc.). If you're not sure which format to choose, refer to my list of images used by the SF2000.
Scaling:
One of two available scaling modes for your input image; the \"Scaling\" option lets you scale your image maintaining aspect ratio amongst several common sizes (e.g., 1x scaling to maintain the input image size, 2x scaling to double it, etc.)
Fit to:
The other available scaling mode; this will scale your image to the specified width and height, without maintaining aspect ratio. This will allow you to scale an image to any dimension you want, but it'll be up to you to do your own aspect ratio calculations.
Filter Type:
When scaling an image by anything other than 1x, specifies the type of image filtering to use. \"Nearest Neighbour\" will give sharp pixel scaling but only at integer upscales; any other scale will appear aliased. \"Bilinear\" will give a fuzzier scale, but it works better for non-integer scale factors and for downscaling.
"; // Now let's add our image controls; there's a few of them! We have a // select box for choosing the image format, we have two different @@ -431,21 +441,24 @@ // scales, and one for user-defined output size), and we have a select // box for choosing nearest-neighbour or hybrid gaussian/bilinear // image filtering... - html += "
"; - // Image format... - html += "
"; + html += "
"; + // Image format and dithering options... + html += "
"; + html += "
"; + html += "
"; + html += "
"; // Scaling options... html += "
"; - html += "
"; + html += "
"; html += " OR "; - html += "
and
"; + html += "
and
"; html += "
"; // Filter type... - html += "
"; - html += "
"; + html += "
"; + html += ""; // Next we'll add our image preview... - html += "
"; + html += "

"; // ... and our Download button... html += "
"; @@ -458,76 +471,80 @@ document.getElementById("steps").insertAdjacentHTML("beforeend", "
"); document.getElementById("steps").insertAdjacentHTML("beforeend", html); - // Now we'll attach event listeners for all of the interactive elements - // in this step. We'll start with our image format select box... - var ifField = document.getElementById("imageFormat"); - ifField.addEventListener("change", function() { + // Now, attach some event handlers to our form controls; these will + // handle some of the logic for how I want the controls to behave. + // First, let's enable/disable dithering options depending on whether or + // not image format is set to RGB565... + const formatSelect = document.getElementById("imageFormat"); + formatSelect.addEventListener("change", function() { + switch (this.value){ + case "RGB565": + document.getElementById("ditherEnabled").removeAttribute("disabled"); + document.getElementById("ditherStrength").removeAttribute("disabled"); + break; - // Update our global variable with the new value, convert the user's - // image using the new format and render a preview... - imageFormat = this.value; - let newWH = calculateNewSize(userImageData); - convertImageToSF2000(scaleImage(userImageData, newWH.width, newWH.height, userFilterType)); - convertFromSF2000AndRender(); + case "BGRA": + document.getElementById("ditherEnabled").setAttribute("disabled", ""); + document.getElementById("ditherStrength").setAttribute("disabled", ""); + break; + } }); - // The scaling mode radio buttons; these let the user choose between - // fixed-ratio scaling, or fixed width/height scaling... - var modes = document.getElementsByName("scaleMode"); - for (var i = 0; i < modes.length; i++) { + // Now let's do the scaling mode radio buttons; these let the user + // choose between fixed-ratio scaling, or fixed width/height scaling... + const modes = document.getElementsByName("scaleMode"); + for (let i = 0; i < modes.length; i++) { modes[i].addEventListener("change", function() { - // Update our global variable with the new selection... - userScaleMode = this.value; - // Check what they chose... - if (userScaleMode == "scale") { - + if (this.value == "scale") { // They chose fixed-ratio scaling, so enable the ratio selector, - // and disable the fixed-width/height number inputs... + // and disable the fixed-width/height controls... document.getElementById("scaleFactor").removeAttribute("disabled"); + document.getElementById("fitToWidthEnabled").setAttribute("disabled", ""); document.getElementById("userFitWidth").setAttribute("disabled", ""); + document.getElementById("fitToHeightEnabled").setAttribute("disabled", ""); document.getElementById("userFitHeight").setAttribute("disabled", ""); } - else if (userScaleMode == "fit") { - + else if (this.value == "fit") { // They chose fixed width/height scaling, so enable our // width/height number inputs, and disable the ratio-scaling // selection box... + document.getElementById("fitToWidthEnabled").removeAttribute("disabled"); document.getElementById("userFitWidth").removeAttribute("disabled"); + document.getElementById("fitToHeightEnabled").removeAttribute("disabled"); document.getElementById("userFitHeight").removeAttribute("disabled"); document.getElementById("scaleFactor").setAttribute("disabled", ""); } - - // We'll also want to re-convert the user's image data and render - // a new preview... - let newWH = calculateNewSize(userImageData); - convertImageToSF2000(scaleImage(userImageData, newWH.width, newWH.height, userFilterType)); - convertFromSF2000AndRender(); }); } - // The fixed-ratio scaling selector... - var sField = document.getElementById("scaleFactor"); - sField.addEventListener("change", function() { - - // Update our global variable with the newly chosen scaling factor, - // and then re-convert the user's image data and render a new - // preview... - userScaleFactor = this.value; - let newWH = calculateNewSize(userImageData); - convertImageToSF2000(scaleImage(userImageData, newWH.width, newWH.height, userFilterType)); - convertFromSF2000AndRender(); + // Next, the fixed-width/height checkboxes; these have a little twist + // whereby we don't want to allow them both to be unticked at the same + // time - so we catch click events, and ignore them if they would cause + // both checkboxes to be unticked... + const widthCheckbox = document.getElementById("fitToWidthEnabled"); + widthCheckbox.addEventListener("click", function() { + const heightCheckbox = document.getElementById("fitToHeightEnabled"); + if (heightCheckbox.checked == false) { + event.preventDefault(); + } + }); + const heightCheckbox = document.getElementById("fitToHeightEnabled"); + heightCheckbox.addEventListener("click", function() { + const widthCheckbox = document.getElementById("fitToWidthEnabled"); + if (widthCheckbox.checked == false) { + event.preventDefault(); + } }); - // And the fixed-width/height number inputs... - var whFields = [document.getElementById("userFitWidth"), document.getElementById("userFitHeight")]; + // And now the fixed-width/height number inputs... + const whFields = [document.getElementById("userFitWidth"), document.getElementById("userFitHeight")]; whFields.forEach(field => { // These get two event listeners; the first is designed to prevent the // user from entering anything other than positive integers... field.addEventListener("keydown", function(event) { - // Only allow integer entry and things like arrow keys, etc! if (event.key.length > 1 || /\d/.test(event.key)) { return; @@ -535,95 +552,129 @@ event.preventDefault(); }); - // ... and this updates our global variables, re-converts the user's - // image data and renders a new preview image when the numbers are - // changed... + // ... and the second catches when if the value is blank or set to 0, + // and if so sets it to 1 instead... field.addEventListener("change", function() { - if (this.value === "" || this.value === "0") { this.value = "1"; } - if (this.id == "userFitWidth") { - userFitWidth = this.value; - } - else { - userFitHeight = this.value; - } - let newWH = calculateNewSize(userImageData); - convertImageToSF2000(scaleImage(userImageData, newWH.width, newWH.height, userFilterType)); - convertFromSF2000AndRender(); }); }); - // Next, the event listener for our filter type selection... - var ftField = document.getElementById("userFilterType"); - ftField.addEventListener("change", function() { - - // Update our global variable with the new filter type, re-convert - // the user's image data, and update our preview... - userFilterType = this.value; - let newWH = calculateNewSize(userImageData); - convertImageToSF2000(scaleImage(userImageData, newWH.width, newWH.height, userFilterType)); - convertFromSF2000AndRender(); - }); - // And last but not least, our Download button... - var dButton = document.getElementById("userDownload"); + const dButton = document.getElementById("userDownload"); dButton.addEventListener("click", function() { // For the file-name we're going to do something semi-fancy; if the // user's original image file name had *two* extensions (e.g., - // c1eac.pal.png), then we'll strip off the second extension and - // just save the file with the remainder of the name (e.g., - // c1eac.pal) - this will speed up their workflow if their source - // image came from a design tool that exports images named after - // layers/artboards. Otherwise, we'll just use the name of the - // file they provided with ".bin" appended to the end... - var downloadName = fileName + ".bin"; - var match = fileName.match(/(.+)\.([^.]+)\.([^.]+)/); + // c1eac.pal.png), then we'll strip off the second extension and just + // save the file with the remainder of the name (e.g., c1eac.pal) - + // this will speed up their workflow if their source image came from a + // design tool that exports images named after layers/art-boards. + // Otherwise, we'll just use the name of the file they provided with + // ".bin" appended to the end... + let downloadName = fileName + ".bin"; + const match = fileName.match(/(.+)\.([^.]+)\.([^.]+)/); if (match) { - // It's got a double extension - so let's just strip off the - // second one... + // It's got a double extension - so let's just strip off the second + // one... downloadName = match[1] + "." + match[2]; } downloadToBrowser(sf2000ImageData, "application/octet-stream", downloadName); }); + // Great, that's all the UI handling done. The final event we'll set up + // is on the overall control strip itself, to watch for changes to any + // of the controls. When any of them change, this event will trigger, + // and we'll get the new control state and use their current values to + // render an updated image... + const toSF2000Form = document.getElementById("toSF2000ImageSettings"); + toSF2000Form.addEventListener("change", function() { + + // Get the state of all of our form controls... + const formData = Object.fromEntries(new FormData(toSF2000Form)); + + // Set our general globals from the current form state... + imageFormat = formData.imageFormat; + if (formData.ditherEnabled !== undefined) {ditherEnabled = true;} + else if (imageFormat == "RGB565") {ditherEnabled = false;} + ditherEnabled = formData.ditherEnabled ? true : ditherEnabled; + ditherStrength = formData.ditherStrength? parseFloat(formData.ditherStrength) : ditherStrength; + userScaleMode = formData.scaleMode; + userScaleFactor = formData.scaleFactor; + if (formData.fitToWidthEnabled !== undefined) {fitToWidthEnabled = true;} + else if (userScaleMode == "fit") {fitToWidthEnabled = false;} + if (formData.fitToHeightEnabled !== undefined) {fitToHeightEnabled = true;} + else if (userScaleMode == "fit") {fitToHeightEnabled = false;} + userFitWidth = formData.userFitWidth ? formData.userFitWidth : userFitWidth; + userFitHeight = formData.userFitHeight ? formData.userFitHeight : userFitHeight; + userFilterType = formData.userFilterType; + + // Finally render an updated preview... + calculateOutputDimensions(); + convertImageToSF2000(scaleImage(userImageData, outputImageWidth, outputImageHeight, userFilterType), ditherEnabled, ditherStrength); + convertFromSF2000AndRender(); + }); + // The last thing to do here in Step 3 is to perform our initial // image data conversion and preview rendering... so let's do it! - let newWH = calculateNewSize(userImageData); - convertImageToSF2000(scaleImage(userImageData, newWH.width, newWH.height, userFilterType)); + calculateOutputDimensions(); + convertImageToSF2000(scaleImage(userImageData, outputImageWidth, outputImageHeight, userFilterType), ditherEnabled, ditherStrength); convertFromSF2000AndRender(); } - // This function takes in an ImageData object, and given our global - // variables for the image conversion options, returns an object - // containing the new width and height of the image based on those - // options... - function calculateNewSize(imageData) { - var newWidth = userFitWidth; - var newHeight = userFitHeight; - if (userScaleMode == "scale") { - newWidth = Math.round(imageData.width * Number(userScaleFactor.slice(0, -1))); - newHeight = Math.round(imageData.height * Number(userScaleFactor.slice(0, -1))); + // This function takes our userImageData global, and given our other + // global variables for the image conversion options, sets + // outputImageWidth and outputImageHeight based on calculated dimensions + // from the options... + function calculateOutputDimensions() { + + // Default to just being the same size as the original image... + outputImageWidth = userImageData.width; + outputImageHeight = userImageData.height; + + // Check to see which scaling mode the user has selected... + switch (userScaleMode){ + + case "scale": + // They've selected "scale" mode! So take the value from the + // selection box, strip off the "x" character at the end, and use it + // as a multiplier for the original image dimensions, rounding to + // the nearest whole number... + outputImageWidth = Math.round(outputImageWidth * Number(userScaleFactor.slice(0, -1))); + outputImageHeight = Math.round(outputImageHeight * Number(userScaleFactor.slice(0, -1))); + break; + + case "fit": + // They've selected "fit to width/height" mode! This is a little + // more involved than "scale", as the final width/height will depend + // on which combination of the width/height fitting checkboxes are + // currently checked... + if (fitToWidthEnabled){ + outputImageWidth = Number(userFitWidth); + if (fitToHeightEnabled) { + outputImageHeight = Number(userFitHeight); + } + else { + outputImageHeight = Math.round(userImageData.height * (outputImageWidth / userImageData.width)); + } + } + else if (fitToHeightEnabled){ + outputImageHeight = Number(userFitHeight); + outputImageWidth = Math.round(userImageData.width * (outputImageHeight / userImageData.height)); + } + break; } - - // Update the global variables used for rendering SF2000 image data with - // our new output width and height... - outputImageWidth = newWidth; - outputImageHeight = newHeight; - - return {width: newWidth, height: newHeight}; } // This function takes in an ImageData object, and uses our standard // library conversion functions to convert it to either RGB565 or BGRA // format, and sets the sf2000ImageData global to the resulting // Uint8Array object... - function convertImageToSF2000(sourceData) { + function convertImageToSF2000(sourceData, dither, ditherStrength) { if (imageFormat == "RGB565") { - sf2000ImageData = imageDataToRgb565(sourceData); + sf2000ImageData = imageDataToRgb565(sourceData, dither, ditherStrength); } else if (imageFormat == "BGRA") { sf2000ImageData = imageDataToBgra(sourceData); @@ -641,15 +692,20 @@ else if (imageFormat == "BGRA") { previewCanvasData = bgraToImageData(sf2000ImageData, outputImageWidth, outputImageHeight); } - var canvas = document.getElementById("processFilePreview"); - var context = canvas.getContext("2d"); + const canvas = document.getElementById("processFilePreview"); + const context = canvas.getContext("2d"); canvas.width = previewCanvasData.width; canvas.height = previewCanvasData.height; context.clearRect(0, 0, canvas.width, canvas.height); context.putImageData(previewCanvasData, 0, 0); + + // Just as a utility, let's also show the output image's width and + // height; we'll also set this as a title on the canvas... + document.getElementById("previewDimensions").innerText = previewCanvasData.width + " x " + previewCanvasData.height; + canvas.setAttribute("title", previewCanvasData.width + " x " + previewCanvasData.height); }
-

CC0: public domain. Version 1.1, 20230626.1

+

CC0: public domain. Version 1.2, 20240514.1

diff --git a/tools/saveStateTool.htm b/tools/saveStateTool.htm index fe048c8..75e3f71 100644 --- a/tools/saveStateTool.htm +++ b/tools/saveStateTool.htm @@ -29,14 +29,14 @@ // Global Variables // ================ - var previewCanvasData; // Binary data used for drawing to our preview canvas - var saveFileName; // Name of the save state file chosen by the user - var downloadName; // Name we're going to give any download being sent to the user - var saveData; // Binary data of a save state file - var thumbData; // Binary data of a save state thumbnail - var thumbWidth; // Integer width of a save state thumbnail - var thumbHeight; // Integer height of a save state thumbnail - var romFileGood; // Boolean indicating if a chosen save state file appears to be binary or not + let previewCanvasData; // Binary data used for drawing to our preview canvas + let saveFileName; // Name of the save state file chosen by the user + let downloadName; // Name we're going to give any download being sent to the user + let saveData; // Binary data of a save state file + let thumbData; // Binary data of a save state thumbnail + let thumbWidth; // Integer width of a save state thumbnail + let thumbHeight; // Integer height of a save state thumbnail + let romFileGood; // Boolean indicating if a chosen save state file appears to be binary or not // Display a note about platform compatibility for save states... setMessage("warning", "platformNote", "NOTE: The SF2000 is uses a MIPS processor; as a result, save states created on the SF2000 will likely only ever work on other MIPS devices, and will likely never work on any other kind of device (e.g., PCs, Android devices, Rockchip devices, ARM devices, etc.).") @@ -47,8 +47,8 @@ // When the tool loads, add some event watchers for when the Step 1 radio // buttons change; and depending on which mode the user selects, begin // rewriting the rest of the page... - var modes = document.getElementsByName("toolMode"); - for (var i = 0; i < modes.length; i++) { + const modes = document.getElementsByName("toolMode"); + for (let i = 0; i < modes.length; i++) { modes[i].addEventListener("change", function() { // Clear out any HTML that might already exist after Step 1, just so @@ -68,13 +68,14 @@ }); } - // This function sets up the HTML for "Convert from SF2000 > Step 2", selecting - // a save state file from the SF2000's microSD card that the user wants to - // convert to raw save state data and/or a thumbnail... + // This function sets up the HTML for "Convert from SF2000 > Step 2", + // selecting a save state file from the SF2000's microSD card that the + // user wants to convert to raw save state data and/or a thumbnail... function setupStepTwo_From() { - // Create the new section, add our heading and our instruction paragraph... - var html = "

Step 2: Select SF2000 Save State File

Select the SF2000 save state file you want to convert from. The save states are usually stored in the save subfolder where the ROM for the game is located. There can be up to four saves states per game, with the extensions .sa0, .sa1, .sa2 and .sa3 respectively.

"; + // Create the new section, add our heading and our instruction + // paragraph... + let html = "

Step 2: Select SF2000 Save State File

Select the SF2000 save state file you want to convert from. The save states are usually stored in the save subfolder where the ROM for the game is located. There can be up to four saves states per game, with the extensions .sa0, .sa1, .sa2 and .sa3 respectively.

"; // Add our file chooser... html += "
"; @@ -82,16 +83,18 @@ // Close off our section... html += "
"; - // Finally, add a
separator after the last step, and append the new step... + // Finally, add a
separator after the last step, and append the new + // step... document.getElementById("steps").insertAdjacentHTML("beforeend", "
"); document.getElementById("steps").insertAdjacentHTML("beforeend", html); // Attach our event handler to our new file input control... - var sf2000SaveInput = document.getElementById("inputSAFile"); + const sf2000SaveInput = document.getElementById("inputSAFile"); sf2000SaveInput.addEventListener("change", function() { - // The user has chosen a new file; it should be a binary blob we can try - // to interpret as a save state file. First let's clear any old messages... + // The user has chosen a new file; it should be a binary blob we can + // try to interpret as a save state file. First let's clear any old + // messages... document.getElementById("step2Messages").innerHTML = ""; // And also remove any old HTML after the current section... @@ -100,7 +103,7 @@ } // Now let's read in our file data as a binary stream... - var frSave = new FileReader(); + const frSave = new FileReader(); saveFileName = event.target.files[0].name; frSave.readAsArrayBuffer(event.target.files[0]); frSave.onload = function(event) { @@ -118,8 +121,8 @@ } else { - // Whoops, the file doesn't looke like it was an SF2000 save state file. - // Let the user know and return... + // Whoops, the file doesn't look like it was an SF2000 save state + // file. Let the user know and return... setMessage("error", "step2Messages", "ERROR: The selected file does not appear to be a valid SF2000 save state file."); return; } @@ -127,13 +130,13 @@ }); } - // This function sets up the HTML for "Convert to SF2000 > Step 2", selecting - // the non-SF2000 save state file the user wants to convert to an SF2000 save - // state bundle... + // This function sets up the HTML for "Convert to SF2000 > Step 2", + // selecting the non-SF2000 save state file the user wants to convert to + // an SF2000 save state bundle... function setupStepTwo_To() { // Start our new section, add our header and our instructions... - var html = "

Step 2: Save State File

Select the save state file from your non-SF2000 emulator that you want to convert to an SF2000-compatible save state bundle.

"; + let html = "

Step 2: Save State File

Select the save state file from your non-SF2000 emulator that you want to convert to an SF2000-compatible save state bundle.

"; // Add our file chooser... html += "
"; @@ -141,12 +144,13 @@ // Close our section... html += "
"; - // Finally, add a
separator after the last step, and append the new step... + // Finally, add a
separator after the last step, and append the new + // step... document.getElementById("steps").insertAdjacentHTML("beforeend", "
"); document.getElementById("steps").insertAdjacentHTML("beforeend", html); // Attach our event handler to our new file input control... - var userFileInput = document.getElementById("inputStateFile"); + const userFileInput = document.getElementById("inputStateFile"); userFileInput.addEventListener("change", function() { // First let's clear any old messages... @@ -158,31 +162,31 @@ } // Now let's read in the file... - var frImage = new FileReader(); + const frImage = new FileReader(); frImage.readAsDataURL(event.target.files[0]); frImage.onload = function(event) { - // The file is loaded; let's check to make sure we got a binary file (can't - // really do much more validation than that, alas)... + // The file is loaded; let's check to make sure we got a binary file + // (can't really do much more validation than that, alas)... if (!event.target.result.includes("application/octet-stream")) { - // Whoops! Doesn't look like the user provided a binary file, so can't be - // a save state! + // Whoops! Doesn't look like the user provided a binary file, so + // can't be a save state! setMessage("error", "step2Messages", "ERROR: The selected file does not appear to be a binary file, and therefore can't be a save state file; please make sure you're selecting a valid emulator save state file."); return; } - // If we're here then it was a binary file; read the data into our global - // saveData buffer... - var base64Data = event.target.result.substring(event.target.result.indexOf(",") + 1); - var binaryData = atob(base64Data); + // If we're here then it was a binary file; read the data into our + // global saveData buffer... + const base64Data = event.target.result.substring(event.target.result.indexOf(",") + 1); + const binaryData = atob(base64Data); saveData = new Uint8Array(binaryData.length); - for (var i = 0; i < binaryData.length; i++) { + for (let i = 0; i < binaryData.length; i++) { saveData[i] = binaryData.charCodeAt(i); } - // Let's check the provided data for Retroarch's save-state headers, and - // strip them out if we find them... + // Let's check the provided data for Retroarch's save-state headers, + // and strip them out if we find them... saveData = stripRetroarchHeaders(saveData); // On to Step 3! @@ -191,13 +195,14 @@ }); } - // This function sets up the HTML for "Convert from SF2000 > Step 2 > Step 3"... + // This function sets up the HTML for "Convert from SF2000 > Step 2 > Step + // 3"... function setupStepThree_From() { // In this section, we'll be presenting the user with the thumbnail of // their save state, and a download button for downloading the save // state data itself. Let's start building our HTML... - var html = "

Step 3: Download Save State Data

Below you'll find the thumbnail for your chosen save state file, as well as a download button which will let you download the raw save state data for use with other emulators/devices. If you want to save the thumbnail as well, just right-click or tap-and-hold on it like any other image, and save it that way.

"; + let html = "

Step 3: Download Save State Data

Below you'll find the thumbnail for your chosen save state file, as well as a download button which will let you download the raw save state data for use with other emulators/devices. If you want to save the thumbnail as well, just right-click or tap-and-hold on it like any other image, and save it that way.

"; // Next, we'll add the image preview... html += "
"; @@ -208,13 +213,14 @@ // ... and lastly we'll close off our section... html += "
"; - // Add a
separator after the previous step, and append the new step... + // Add a
separator after the previous step, and append the new + // step... document.getElementById("steps").insertAdjacentHTML("beforeend", "
"); document.getElementById("steps").insertAdjacentHTML("beforeend", html); - // Now, add our interactivity by attaching our event handler to the download - // button... - var downloadButton = document.getElementById("saveStateDownload"); + // Now, add our interactivity by attaching our event handler to the + // download button... + const downloadButton = document.getElementById("saveStateDownload"); downloadButton.addEventListener("click", function() { // Before we kick-off our download function, let's determine the file @@ -224,7 +230,7 @@ // strip off both extensions and *then* add .state (Retroarch save // state naming convention)... downloadName = saveFileName + ".state"; - var match = saveFileName.match(/(.+)\.([^.]+)\.([^.]+)/); + const match = saveFileName.match(/(.+)\.([^.]+)\.([^.]+)/); if (match) { downloadName = match[1] + ".state"; } @@ -237,7 +243,8 @@ convertFromSF2000AndRender(); } - // This function sets up the HTML for "Convert to SF2000 > Step 2 > Step 3"... + // This function sets up the HTML for "Convert to SF2000 > Step 2 > Step + // 3"... function setupStepThree_To() { // In this section, we'll be rendering the HTML for some controls - the @@ -246,7 +253,7 @@ // save state should be stored in slot 1, 2, 3 or 4 (again, required for // the file name). Let's start by creating our new section, and add its // heading and instruction paragraph... - html = "

Step 3: Select Game ROM And Slot Number

To name your new SF2000 save state properly, this tool needs to know two things - the name of the game ROM file the save state is for, and which save slot (1, 2, 3 or 4) the save state should take up. Use the controls below to select your game ROM file from your SF2000's microSD card, and to choose which save slot you want.

When you've chosen a ROM file and a slot number, the Download button will become enabled, and can be used to download your new save state file. Put it in the save subfolder along-side wherever your ROM file is stored on the SF2000's microSD card (e.g., if your ROM file is sd:/ROMS/Apotris.gba, and you chose save slot 1, you'd put the resulting save state in sd:/ROMS/save/Apotris.gba.sa0).

The one special case is with arcade games; the ROM you need to select is one of the ones in the sd:/ARCADE/bin/ folder, and the resulting save state bundle goes into sd:/ARCADE/save/. As an example, if you wanted to transfer a save state to the SF2000 for the game \"Metal Slug\" in slot 3, you'd select sd:/ARCADE/bin/mslug.zip and Slot 3, and the final location to put the save state would be sd:/ARCADE/save/mslug.zip.sa2 - I hope that makes sense! You can find a list of all potential arcade zip-file names and the full name of the game they represent here, if it helps - the first column (\"rom\") is the name of the zip-file without the .zip part, and the second column (\"fullname\") is the full name of the game/romset.

"; + let html = "

Step 3: Select Game ROM And Slot Number

To name your new SF2000 save state properly, this tool needs to know two things - the name of the game ROM file the save state is for, and which save slot (1, 2, 3 or 4) the save state should take up. Use the controls below to select your game ROM file from your SF2000's microSD card, and to choose which save slot you want.

When you've chosen a ROM file and a slot number, the Download button will become enabled, and can be used to download your new save state file. Put it in the save subfolder along-side wherever your ROM file is stored on the SF2000's microSD card (e.g., if your ROM file is sd:/ROMS/Apotris.gba, and you chose save slot 1, you'd put the resulting save state in sd:/ROMS/save/Apotris.gba.sa0).

The one special case is with arcade games; the ROM you need to select is one of the ones in the sd:/ARCADE/bin/ folder, and the resulting save state bundle goes into sd:/ARCADE/save/. As an example, if you wanted to transfer a save state to the SF2000 for the game \"Metal Slug\" in slot 3, you'd select sd:/ARCADE/bin/mslug.zip and Slot 3, and the final location to put the save state would be sd:/ARCADE/save/mslug.zip.sa2 - I hope that makes sense! You can find a list of all potential arcade zip-file names and the full name of the game they represent here, if it helps - the first column (\"rom\") is the name of the zip-file without the .zip part, and the second column (\"fullname\") is the full name of the game/romset.

"; // Now let's add our controls (file browser for the game ROM, and four // radio button inputs for the save state slot number); we'll group them @@ -264,17 +271,18 @@ // ... and lastly we'll close off our section... html += "
"; - // Add a
separator after the previous step, and append the new step... + // Add a
separator after the previous step, and append the new + // step... document.getElementById("steps").insertAdjacentHTML("beforeend", "
"); document.getElementById("steps").insertAdjacentHTML("beforeend", html); - // Now we'll attach event listeners for all of the interactive elements in - // this step. Mostly this will just be for storing the provided details; - // we'll also call a little helper function for each one which'll determine - // if the Download button should be enabled or not... + // Now we'll attach event listeners for all of the interactive elements + // in this step. Mostly this will just be for storing the provided + // details; we'll also call a little helper function for each one + // which'll determine if the Download button should be enabled or not... // Let's start with the ROM file select... - var romFileInput = document.getElementById("inputROMFile"); + const romFileInput = document.getElementById("inputROMFile"); romFileInput.addEventListener("change", function() { // First let's clear any old messages... @@ -289,9 +297,9 @@ romFileGood = false; // Now let's read in the file; we don't really care about its contents - // per-se (we only need it for its file name), but we may as well confirm - // it's a binary file while we're here... - var frImage = new FileReader(); + // per-se (we only need it for its file name), but we may as well + // confirm it's a binary file while we're here... + const frImage = new FileReader(); saveFileName = event.target.files[0].name; frImage.readAsDataURL(event.target.files[0]); frImage.onload = function(event) { @@ -322,8 +330,8 @@ }); // Next up, our radio buttons... - var slots = document.getElementsByName("saveSlot"); - for (var i = 0; i < slots.length; i++) { + const slots = document.getElementsByName("saveSlot"); + for (let i = 0; i < slots.length; i++) { slots[i].addEventListener("change", function() { // The only thing we'll do here is run our Download button // state-checking function; we'll pull the actual data from the @@ -333,14 +341,14 @@ } // And last but not least, our Download button... - var dButton = document.getElementById("saveStateDownload"); + const dButton = document.getElementById("saveStateDownload"); dButton.addEventListener("click", function() { // We're actually going to be doing quite a bit here - we'll assemble // the binary blob of the new save state bundle before handing it off - // to our download function. First, let's try zlib-deflating the user's - // save state data... - var compressedSaveState = compressZlib(saveData); + // to our download function. First, let's try zlib-deflating the + // user's save state data... + const compressedSaveState = compressZlib(saveData); if (!(compressedSaveState instanceof Uint8Array)) { // Oh! We failed to compress the save state data using the pako // library for some reason... display a message to the user and @@ -349,7 +357,8 @@ return; } - // We also need to check our compressed data is of an appropriate size... + // We also need to check our compressed data is of an appropriate + // size... if (compressedSaveState.length < 0 || compressedSaveState.length > 4294967295) { setMessage("error", "step3Messages", "ERROR: Compressed save state data is not valid (either it was 0 bytes in length, or was larger than 4 GB)!"); return false; @@ -361,7 +370,7 @@ // We'll also use a little "offset" variable, to help keep track of // where we are in the array as we go... - var offset = 0; + let offset = 0; // The first four bytes are a little-endian Uint32 version of our // compressed save state data's length... @@ -371,34 +380,33 @@ saveData[offset + 3] = (compressedSaveState.length >> 24) & 0xFF; offset += 4; - // The next sequence of bytes are all of our compressed save state data, - // so let's just copy it in... - for (var i = 0; i < compressedSaveState.length; i++) { + // The next sequence of bytes are all of our compressed save state + // data, so let's just copy it in... + for (let i = 0; i < compressedSaveState.length; i++) { saveData[offset] = compressedSaveState[i]; offset += 1; } // For reasons, we'll need our current offset a little later on, so // let's make a note of it now... - var thumbnailStart = offset; + const thumbnailStart = offset; // The next three sets of four bytes are little-endian Uint32 versions // of our thumbnail image's width, height and compressed data length; // I've got all of those numbers pre-calculated, so I'll just add them - // in... - // Width... + // in, starting with width... saveData[offset + 0] = 64; saveData[offset + 1] = 1; saveData[offset + 2] = 0; saveData[offset + 3] = 0; offset += 4; - // Height... + // ... and then height... saveData[offset + 0] = 240; saveData[offset + 1] = 0; saveData[offset + 2] = 0; saveData[offset + 3] = 0; offset += 4; - // Length... + // ... and finally length... saveData[offset + 0] = 107; saveData[offset + 1] = 62; saveData[offset + 2] = 0; @@ -408,7 +416,7 @@ // Next comes the zlib compressed thumbnail data itself; I've already // got that too :) thumbData = atob("eJztnU18E9e5/3sDAfOS+2FJd7CDGzA2ecO3XcS8WjbJDV5d+26KWWGagGXSBpsusHgxliGfD/YqVjdFWdlOAthpm+AuMDbGb6SLsLt012zuLQmkSZtu/ud7NM9wNJoZjWRZcu//8FuMNBrJsuZrfnp+5zlndp3ddXbX+fyqUTq1QnRSKcp7Lkhnw/Wgu7zK937+T8nyZ/lbySr92S6PQn6nByHnfnGFKOw9mqo4HxG0pPdeaY4sf/93+Qs4dzWOKu21YR5cch8ukNPl1nIzsSJk+bP8rSQVee5glW0YLyY3XpWUowhcoQcB573SvluI9z74J+M073u3/FWcvf+v+PMwVHKn7Ffy3u535HdM2L4QHy4JwxH5LJfKxQSqcSS3T3kk++SYksnyZ/mrJH8+HIZpOeuSZfXjiGxFcsdOQ9775v4y+O/yk7k8ynn/lj/LXyX4WwpT/WXUcjMbwqTI5O+qksnZ1c5nMhnK4bYAvpbr3J9U8vprseK1luTJlj/LX4X5i6Ll8NsoXlwuD/Zy5Oeh7L+iNM6/0fHRN068cYL7bPkbeW/xvUWTQxHHXDnhSN0Oev1C/He52Cy7LH+WvwqqICrK6bcRvbhUObYw+NKHL3342vRr00E+Cj88/v3E9xNwJ7o5eHPwJ1/95Kssfh2f5vF3RzPiPcvj+RgrNWcnHeW4qHmOvfdln3lsgBebGY7lz/L3z8Bf0PmQ8bJKqaTjc2czXhvkcyZb8AdHVzKumeWR4rWwhwVvPPZMHf0d/f949I9HwqM8n9s3+m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l+Ataf83lMWIWU1YfLhdPRXqtV1G9N5L/hvQbvGEoEmsrwH8tf5a/SvNXjAfn+HCxnvxPxKYvowVIrtnt/byX03/Fg6P6b44HL3MOY/mz/FWSv/8H7F6WNw=="); - for (var i = 0; i < thumbData.length; i++) { + for (let i = 0; i < thumbData.length; i++) { saveData[offset] = thumbData.charCodeAt(i); offset += 1; } @@ -449,40 +457,39 @@ }); } - // This function takes in a Uint8Array object, and attempts to inflate it using - // the pako library; returns a Uint8Array object containing the inflated data - // on success, or null on failure... + // This function takes in a Uint8Array object, and attempts to inflate it + // using the pako library; returns a Uint8Array object containing the + // inflated data on success, or null on failure... function decompressZlib(data) { if (!(data instanceof Uint8Array)) { return null; } try { - let decompressed = pako.inflate(data); - return decompressed; + return pako.inflate(data); } catch (error) { return null; } } // This function takes in a Uint8Array object, and attempts to deflate it - // using the pako library; returns a Uint8Array object containing the defalated - // data on success, or null on failure... + // using the pako library; returns a Uint8Array object containing the + // deflated data on success, or null on failure... function compressZlib(data) { if (!(data instanceof Uint8Array)) { return null; } try { - let compressed = pako.deflate(data); - return compressed; + return pako.deflate(data); } catch (error) { return null; } } - // This function validates that a provided Uint8Array object matches the format - // of an SF2000 save state file, and assigns the state data, thumbnail data and - // thumbnail dimensions to our global storage variables. The function returns - // true when successfully processing the array, or false otherwise... + // This function validates that a provided Uint8Array object matches the + // format of an SF2000 save state file, and assigns the state data, + // thumbnail data and thumbnail dimensions to our global storage + // variables. The function returns true when successfully processing the + // array, or false otherwise... function validateSave(data) { // First check if data is a Uint8Array object... @@ -495,15 +502,18 @@ return false; } - // Read the first four bytes as a little-endian number and store it in saveLength... - let saveLength = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24); + // Read the first four bytes as a little-endian number and store it in + // saveLength... + const saveLength = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24); - // Check if saveLength is positive and does not exceed the remaining bytes... + // Check if saveLength is positive and does not exceed the remaining + // bytes... if (saveLength <= 0 || saveLength > data.length - 16) { return false; } - // Check if the next two bytes are [120, 156] (zlib header used by SF2000)... + // Check if the next two bytes are [120, 156] (zlib header used by the + // SF2000)... if (data[4] !== 120 || data[5] !== 156) { return false; } @@ -514,7 +524,8 @@ return false; } - // Read the next four bytes as a little-endian number and store it in thumbWidth... + // Read the next four bytes as a little-endian number and store it in + // thumbWidth... thumbWidth = data[4 + saveLength] + (data[5 + saveLength] << 8) + (data[6 + saveLength] << 16) + (data[7 + saveLength] << 24); // Check if thumbWidth is positive... @@ -522,7 +533,8 @@ return false; } - // Read the next four bytes as a little-endian number and store it in thumbHeight... + // Read the next four bytes as a little-endian number and store it in + // thumbHeight... thumbHeight = data[8 + saveLength] + (data[9 + saveLength] << 8) + (data[10 + saveLength] << 16) + (data[11 + saveLength] << 24); // Check if thumbHeight is positive... @@ -530,20 +542,24 @@ return false; } - // Read the next four bytes as a little-endian number and store it in thumbLength... - let thumbLength = data[12 + saveLength] + (data[13 + saveLength] << 8) + (data[14 + saveLength] << 16) + (data[15 + saveLength] << 24); + // Read the next four bytes as a little-endian number and store it in + // thumbLength... + const thumbLength = data[12 + saveLength] + (data[13 + saveLength] << 8) + (data[14 + saveLength] << 16) + (data[15 + saveLength] << 24); - // Check if thumbLength is positive and does not exceed the remaining bytes... + // Check if thumbLength is positive and does not exceed the remaining + // bytes... if (thumbLength <= 0 || thumbLength > data.length - (16 + saveLength)) { return false; } - // Check if the next two bytes are [120, 156] (zlib header used by SF2000)... + // Check if the next two bytes are [120, 156] (zlib header used by the + // SF2000)... if (data[16 + saveLength] !== 120 || data[17 + saveLength] !== 156) { return false; } - // Store the next thumbLength bytes in thumbData, and attempt to inflate it... + // Store the next thumbLength bytes in thumbData, and attempt to inflate + // it... thumbData = decompressZlib(data.slice(16 + saveLength, 16 + saveLength + thumbLength)); if (!(thumbData instanceof Uint8Array)) { return false; @@ -555,10 +571,10 @@ } // Store the last four bytes in lastFour... - let lastFour = data[data.length - 4] + (data[data.length -3 ] <<8 )+ (data[data.length -2 ]<<16 )+ (data[data.length -1 ]<<24 ); + const lastFour = data[data.length - 4] + (data[data.length -3 ] <<8 )+ (data[data.length -2 ]<<16 )+ (data[data.length -1 ]<<24 ); - // Confirm the last four bytes equal the offset within the data of thumbWidth, - // i.e., first zlib stream length + 4... + // Confirm the last four bytes equal the offset within the data of + // thumbWidth, i.e., first zlib stream length + 4... if (lastFour !== saveLength + 4) { return false; } @@ -567,20 +583,22 @@ return true; } - // This function runs through our binary save state data, and checks it for any - // of Retroarch's save state headers. If it finds them, it strips them out... + // This function runs through our binary save state data, and checks it + // for any of Retroarch's save state headers. If it finds them, it strips + // them out... // See https://github.com/libretro/RetroArch/blob/master/tasks/task_save.c function stripRetroarchHeaders(input) { - // Define an array of the possible Retroarch headers that we're looking for... - let headers = ["RASTATE" + String.fromCharCode([1]), "MEM ", "RPLY", "ACHV", "END "]; + // Define an array of the possible Retroarch headers that we're looking + // for... + const headers = ["RASTATE" + String.fromCharCode([1]), "MEM ", "RPLY", "ACHV", "END "]; - // Define a helper function that checks if a header starts at the provided - // index in the data stream... + // Define a helper function that checks if a header starts at the + // provided index in the data stream... function isHeader(array, i) { // Starting at an index of i, convert the next 8 bytes to a string... - let str = String.fromCharCode(...array.slice(i, i + 8)); + const str = String.fromCharCode(...array.slice(i, i + 8)); // Check if the string includes any of our defined headers... for (let i = 0; i < headers.length; i++) { @@ -595,23 +613,25 @@ return false; } - // Create an intermediate storage array with the same length as input; we - // don't know how long our output length will be yet, but it won't be any - // longer than input, and this array will hold our modified data while we - // work... + // Create an intermediate storage array with the same length as input; + // we don't know how long our output length will be yet, but it won't be + // any longer than input, and this array will hold our modified data + // while we work... let intermediate = new Uint8Array(input.length); - // Now, it's on to the meat of this function. We're going to loop through - // all of our current save state data, byte by byte, and check to see if - // we find a Retroarch save state header starting at the current byte. If - // we don't, we just copy the current byte to our intermediate storage - // array. If we *do* find a Retroarch header, we skip forward 8 bytes (all - // the Retroarch save state header blocks are 8 bytes long)... + // Now, it's on to the meat of this function. We're going to loop + // through all of our current save state data, byte by byte, and check + // to see if we find a Retroarch save state header starting at the + // current byte. If we don't, we just copy the current byte to our + // intermediate storage array. If we *do* find a Retroarch header, we + // skip forward 8 bytes (all the Retroarch save state header blocks are + // 8 bytes long)... let index = 0; let intermediateIndex = 0; while (index < input.length && !isNaN(input[index])) { - // Check if we have a header starting at the current index in our data... + // Check if we have a header starting at the current index in our + // data... if (isHeader(input, index)) { // We do! Don't write any data, and just skip forward 8 bytes... @@ -630,7 +650,7 @@ } // If we're here, intermediate should contain our final output data. - // If the output data length is the same as the input data lenth, then + // If the output data length is the same as the input data length, then // we didn't change anything and can just return the input. Otherwise, // we stripped *something* from the input data... so we'll copy our // new, shorter intermediate data to a correctly sized Uint8Array @@ -647,19 +667,22 @@ } } - // This function checks if we're both happy that the user-selected ROM file - // is binary, AND that a save state slot radio button has been selected; if - // both are true, it enables the download button, otherwise it makes sure - // the button is disabled... + // This function checks if we're both happy that the user-selected ROM + // file is binary, AND that a save state slot radio button has been + // selected; if both are true, it enables the download button, otherwise + // it makes sure the button is disabled... function userStateDownloadCheck() { + if (romFileGood === true && document.querySelector('input[name="saveSlot"]:checked')) { + // Looks good - enable Download button! - var dButton = document.getElementById("saveStateDownload"); + const dButton = document.getElementById("saveStateDownload"); dButton.removeAttribute("disabled"); } else { + // No good - disable Download button! - var dButton = document.getElementById("saveStateDownload"); + const dButton = document.getElementById("saveStateDownload"); dButton.setAttribute("disabled", ""); } } @@ -669,8 +692,8 @@ // global; it then renders that ImageData to our preview canvas... function convertFromSF2000AndRender() { previewCanvasData = rgb565ToImageData(thumbData, thumbWidth, thumbHeight); - var canvas = document.getElementById("thumbnailPreview"); - var context = canvas.getContext("2d"); + const canvas = document.getElementById("thumbnailPreview"); + const context = canvas.getContext("2d"); canvas.width = previewCanvasData.width; canvas.height = previewCanvasData.height; context.clearRect(0, 0, canvas.width, canvas.height); @@ -678,6 +701,6 @@ }
-

CC0: public domain. Version 1.3, 20240223.1

+

CC0: public domain. Version 1.4, 20240514.1

diff --git a/tools/tools.css b/tools/tools.css index b46bfaf..a96c1a7 100644 --- a/tools/tools.css +++ b/tools/tools.css @@ -11,6 +11,10 @@ Just like the tools themselves, this file should be considered CC0 Public Domain (https://creativecommons.org/publicdomain/zero/1.0/) + Version 1.1: Added a max-width to the body element, and auto margins to center + things again (just stops the page being too wide on full-screen desktop + browsers). + Version 1.0: Initial version */ @@ -44,6 +48,8 @@ body { background-color: var(--background); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif; + max-width: 80em; + margin: 0 auto; } a, a:visited, a:hover, a:active { color: inherit; } diff --git a/tools/tools.js b/tools/tools.js index a7ef6ea..9e878b9 100644 --- a/tools/tools.js +++ b/tools/tools.js @@ -12,6 +12,17 @@ Just like the tools themselves, this file should be considered CC0 Public Domain (https://creativecommons.org/publicdomain/zero/1.0/) + Version 1.7: Added ordered dithering support to imageDataToRgb565(). Also + swapped out the Gaussian resampling function in scaleImage() for a higher + quality algorithm based on a semi-custom hybrid between a looped 50% + bilinear downsampling scheme and a Hermite interpolation resampler. Added a + "keepAlpha" argument to imageToImageData() (defaults to true) - if false, + the provided image is drawn on a black background, removing any alpha + channel; this was added as a utility for the boot logo changer. Also + generally tidied up the code here and there (changed vars to lets/consts, + replaced the SVG icons with simple emoji, fixed a few small logic edge + cases, etc.) + Version 1.6: Added support for the (hopefully not broken) October 13th BIOS in getFirmwareHash() and knownHash() @@ -44,17 +55,17 @@ // 0x18f with an updated CRC32 calculated on bytes 512 to the end of the // array. Credit to `bnister` for this code! function patchCRC32(data) { - var c; - var tabCRC32 = new Int32Array(256); - for (var i = 0; i < 256; i++) { + let c; + const tabCRC32 = new Int32Array(256); + for (let i = 0; i < 256; i++) { c = i << 24; - for (var j = 0; j < 8; j++) { + for (let j = 0; j < 8; j++) { c = c & (1 << 31) ? c << 1 ^ 0x4c11db7 : c << 1; } tabCRC32[i] = c; } c = ~0; - for (var i = 512; i < data.length; i++) { + for (let i = 512; i < data.length; i++) { c = c << 8 ^ tabCRC32[c >>> 24 ^ data[i]]; } data[0x18c] = c & 255; @@ -71,7 +82,7 @@ function getFirmwareHash(data) { // we're going to be manipulating that data before generating our hash, but we // don't want to modify the original object at all... so we'll create a copy, // and work only on the copy... - var dataCopy = data.slice(); + const dataCopy = data.slice(); // Only really worthwhile doing this for big bisrv.asd files... if (dataCopy.length > 12600000) { @@ -87,9 +98,9 @@ function getFirmwareHash(data) { // level indicator. These unfortunately can't be searched for - they're just // in specific known locations for specific firmware versions... // Location: Approximately 0x35A8F8 (about 25% of the way through the file) - var prePowerCurve = findSequence([0x11, 0x05, 0x00, 0x02, 0x24], dataCopy); + const prePowerCurve = findSequence([0x11, 0x05, 0x00, 0x02, 0x24], dataCopy); if (prePowerCurve > -1) { - var powerCurveFirstByteLocation = prePowerCurve + 5; + const powerCurveFirstByteLocation = prePowerCurve + 5; switch (powerCurveFirstByteLocation) { case 0x35A8F8: // Seems to match mid-March layout... @@ -156,11 +167,11 @@ function getFirmwareHash(data) { // Next identify the emulator button mappings (if they exist), and blank // them out too... // Location: Approximately 0x8D6200 (about 75% of the way through the file) - var preButtonMapOffset = findSequence([0x00, 0x00, 0x00, 0x71, 0xDB, 0x8E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], dataCopy); + const preButtonMapOffset = findSequence([0x00, 0x00, 0x00, 0x71, 0xDB, 0x8E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], dataCopy); if (preButtonMapOffset > -1) { - var postButtonMapOffset = findSequence([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00], dataCopy, preButtonMapOffset); + const postButtonMapOffset = findSequence([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00], dataCopy, preButtonMapOffset); if (postButtonMapOffset > -1) { - for (var i = preButtonMapOffset + 16; i < postButtonMapOffset; i++) { + for (let i = preButtonMapOffset + 16; i < postButtonMapOffset; i++) { dataCopy[i] = 0x00; } } @@ -174,10 +185,10 @@ function getFirmwareHash(data) { // Next identify the boot logo position, and blank it out too... // Location: Approximately 0x9B3520 (about 80% of the way through the file) - var badExceptionOffset = findSequence([0x62, 0x61, 0x64, 0x5F, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x00, 0x00, 0x00], dataCopy); + const badExceptionOffset = findSequence([0x62, 0x61, 0x64, 0x5F, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x00, 0x00, 0x00], dataCopy); if (badExceptionOffset > -1) { - var bootLogoStart = badExceptionOffset + 16; - for (var i = bootLogoStart; i < (bootLogoStart + 204800); i++) { + const bootLogoStart = badExceptionOffset + 16; + for (let i = bootLogoStart; i < (bootLogoStart + 204800); i++) { dataCopy[i] = 0x00; } } @@ -189,10 +200,10 @@ function getFirmwareHash(data) { // CPU cycles, in case folks want to patch those bytes to correct SNES // first-launch issues on newer firmwares... // Location: Approximately 0xC0A170 (about 99% of the way through the file) - var preSNESBytes = findSequence([0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80], dataCopy); + const preSNESBytes = findSequence([0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80], dataCopy); if (preSNESBytes > -1) { - var snesAudioBitrateBytes = preSNESBytes + 8; - var snesCPUCyclesBytes = snesAudioBitrateBytes + 8; + const snesAudioBitrateBytes = preSNESBytes + 8; + const snesCPUCyclesBytes = snesAudioBitrateBytes + 8; dataCopy[snesAudioBitrateBytes] = 0x00; dataCopy[snesAudioBitrateBytes + 1] = 0x00; dataCopy[snesCPUCyclesBytes] = 0x00; @@ -208,9 +219,8 @@ function getFirmwareHash(data) { // against some known values... return crypto.subtle.digest("SHA-256", dataCopy.buffer) .then(function(digest) { - var array = Array.from(new Uint8Array(digest)); - var hash = array.map(byte => ("00" + byte.toString(16)).slice(-2)).join(""); - return hash; + const array = Array.from(new Uint8Array(digest)); + return array.map(byte => ("00" + byte.toString(16)).slice(-2)).join(""); }) .catch(function(error) { return false; @@ -224,26 +234,21 @@ function getFirmwareHash(data) { // This function searches for array needle in array haystack starting at offset // and returns the zero-based index of the first match found, or -1 if not // found... -function findSequence(needle, haystack, offset) { - - // If offset is not provided, default to 0... - offset = offset || 0; +function findSequence(needle, haystack, offset = 0) { // Loop through the haystack array starting from the offset... - for (var i = offset; i < haystack.length - needle.length + 1; i++) { + for (let i = offset; i < haystack.length - needle.length + 1; i++) { // Assume a match until proven otherwise... - var match = true; + let match = true; // Loop through the needle array and compare each byte... - for (var j = 0; j < needle.length; j++) { - + for (let j = 0; j < needle.length; j++) { if (haystack[i + j] !== needle[j]) { // Mismatch found, break the inner loop and continue the outer loop... match = false; break; } - } // If match is still true after the inner loop, we have found a match; @@ -261,7 +266,7 @@ function findSequence(needle, haystack, offset) { // download... function downloadToBrowser(data, type, name) { // Send the data to the user's browser as a file download... - var link = document.createElement("a"); + const link = document.createElement("a"); link.href = window.URL.createObjectURL(new Blob([data], {type: type})); link.download = name; link.style.display = "none"; @@ -304,33 +309,103 @@ function knownHash(hash) { } // Takes in an ImageData object, and returns a Uint8Array object containing the -// data in little-endian RGB565 format... -function imageDataToRgb565(input) { +// data in little-endian RGB565 format. Optionally supports applying ordered +// dithering to the input... +function imageDataToRgb565(input, dither = false, ditherStrength = 0.2) { + + // Pre-define a Bayer 8x8 matrix for ordered dithering (if enabled); also, + // this matrix was shamelessly yoinked from the Wikipedia example! + const bayerMatrix = [ + [ 0, 32, 8, 40, 2, 34, 10, 42], + [48, 16, 56, 24, 50, 18, 58, 26], + [12, 44, 4, 36, 14, 46, 6, 38], + [60, 28, 52, 20, 62, 30, 54, 22], + [ 3, 35, 11, 43, 1, 33, 9, 41], + [51, 19, 59, 27, 49, 17, 57, 25], + [15, 47, 7, 39, 13, 45, 5, 37], + [63, 31, 55, 23, 61, 29, 53, 21] + ]; // Loop through the image data, and convert it to little-endian RGB565. First, // we'll store the raw RGB565-converted integers in an array, one entry per // pixel... - var intArray = []; - var pixelCount = 0; - for (var i = 0; i < input.data.length; i += 4){ + const intArray = []; + for (let i = 0; i < input.data.length; i += 4){ // Read in the raw source RGB colours from the image data stream... - var red = input.data[i]; - var green = input.data[i+1]; - var blue = input.data[i+2]; + let red = input.data[i]; + let green = input.data[i+1]; + let blue = input.data[i+2]; - // Use some shifting and masking to get a big-endian version of the RGB565 - // colour and store it in our array before moving on... - intArray[pixelCount] = ((red & 248)<<8) + ((green & 252)<<3) + (blue>>3); - pixelCount++; + // Check if we're going to dither or not... + if (dither) { + + // We are! The ordered dither algorithm is kinda messy, but essentially we + // just end up slightly brightening/darkening our source colour pixels, + // using the matrix defined above - this essentially adds a kind of + // "noise" to the image, which stops banding being as apparent when + // dropping down to RGB565. The first thing we need to do is calculate our + // X and Y coordinates within the Bayer matrix for the current source + // image pixel... + const bayerX = (i / 4) % input.width % 8; + const bayerY = (Math.floor(i / 4 / input.width)) % 8; + + // The Wikipedia Bayer matrix was designed to work with colour values that + // range from 0 to 63... which is great for our RGB565 green colour + // channel, but not for red or blue - so we scale the matrix values to + // range from 0 to 31 for those two colour channels. Also, we want to both + // lighten *and* darken our source input values, so to do that we subtract + // roughly half the *possible* maximum from each value - 16 for red and + // blue (half of 31, rounded up), and 32 for green (half of 63, rounded + // up); note I'm using actual values of 18 and 36 instead of 16 and 32, as + // I found that the Wikipedia matrix tended towards lightening more than + // darkening, so I'm compensating by offsetting downwards a little more... + const bayerValueRedBlue = (bayerMatrix[bayerY][bayerX] / 63 * 31) - 18; + const bayerValueGreen = bayerMatrix[bayerY][bayerX] - 36; + + // Now we apply the ordered dithering itself; basically this "adds" the + // Bayer matrix values to red, green and blue (which might lighten or + // darken the pixel, depending on the specific value), and then uses that + // value as a percentage of 255 (the highest possible value) to scale our + // *actual* RGB565 output values for the pixel (which is a maximum of 31 + // for red and blue, and 63 for green). We also scale the whole effect by + // ditherStrength, so that we can adjust how strong or weak the overall + // dithering noise is (too strong and its distracting, too weak and it + // mightn't effectively cover up banding in the output image). We scale + // the green colour channel half as much as red and blue, as otherwise at + // high dither strengths the image would take on an increasingly green + // color cast... + red = Math.round(31 * (Math.min(255, Math.max(0, red + (bayerValueRedBlue * ditherStrength))) / 255)); + green = Math.round(63 * (Math.min(255, Math.max(0, green + (bayerValueGreen * ditherStrength * 0.5))) / 255)); + blue = Math.round(31 * (Math.min(255, Math.max(0, blue + (bayerValueRedBlue * ditherStrength))) / 255)); + + // As a result of the multiplying above, it's possible our red, green and + // blue values are now outside of the 0-31/63 ranges that are allowed for + // our RGB565 output - so we need to clamp the values, just in case... + red = Math.min(31, Math.max(0, red)); + green = Math.min(63, Math.max(0, green)); + blue = Math.min(31, Math.max(0, blue)); + + // And finally, we take our values and convert them to an int representing + // the RGB565 value, that will eventually be stuffed into our output + // Uint8Array object... + intArray[i / 4] = (red << 11) + (green << 5) + blue; + } + else { + + // We're not dithering, so all we need to do is use some shifting and + // masking to get a big-endian version of the RGB565 colour and store it + // in our array before moving on... + intArray[i / 4] = ((red & 248)<<8) + ((green & 252)<<3) + (blue>>3); + } } // Create a data buffer and a data view; we'll use the view to convert our int // array data to little-endian format (the "true" below) to be stored in the // buffer... - var buffer = new ArrayBuffer(intArray.length * 2); - var dataView = new DataView(buffer); - for (var i = 0; i < intArray.length; i++) { + const buffer = new ArrayBuffer(intArray.length * 2); + const dataView = new DataView(buffer); + for (let i = 0; i < intArray.length; i++) { dataView.setInt16(i * 2, intArray[i], true); } @@ -344,8 +419,8 @@ function imageDataToBgra(input) { // This is pretty simple - we just loop through the input data (which is in // RGBA format), and swap the Red and Blue channels to output BGRA instead... - output = new Uint8Array(input.data.length); - for (var i = 0; i < input.data.length; i += 4) { + const output = new Uint8Array(input.data.length); + for (let i = 0; i < input.data.length; i += 4) { output[i] = input.data[i + 2]; output[i + 1] = input.data[i + 1]; output[i + 2] = input.data[i]; @@ -360,25 +435,25 @@ function rgb565ToImageData(input, width, height) { // Create an output ImageData object of the specified dimensions; it'll // default to transparent black, but we'll fill it with our input data... - output = new ImageData(width, height); - outputIndex = 0; - for (var i = 0; i < input.length; i += 2) { + const output = new ImageData(width, height); + let outputIndex = 0; + for (let i = 0; i < input.length; i += 2) { // Check to make sure we haven't run out of space in our output buffer... if (outputIndex < output.data.length) { // Read in two bytes, representing one RGB565 pixel in little-endian // format... - var byte1 = input[i]; - var byte2 = input[i + 1]; + const byte1 = input[i]; + const byte2 = input[i + 1]; // Extract the red, green and blue components from them. The first five // bits of byte2 are red, the first three bits of byte1 and the last // three bits of byte 2 are green, and the last five bits of byte1 are // blue... - var red = (byte2 & 0b11111000) >> 3; - var green = ((byte1 & 0b11100000) >> 5) | ((byte2 & 0b00000111) << 3); - var blue = byte1 & 0b00011111; + let red = (byte2 & 0b11111000) >> 3; + let green = ((byte1 & 0b11100000) >> 5) | ((byte2 & 0b00000111) << 3); + let blue = byte1 & 0b00011111; // These values are in 5-bit/6-bit ranges; we need to scale them to 8-bit // ranges for the colours to look right... @@ -422,9 +497,9 @@ function bgraToImageData(input, width, height) { // Create an output ImageData object of the specified dimensions; it'll // default to transparent black, but we'll fill it with our input data... - output = new ImageData(width, height); - outputIndex = 0; - for (var i = 0; i < input.length; i += 4) { + const output = new ImageData(width, height); + let outputIndex = 0; + for (let i = 0; i < input.length; i += 4) { // Check to make sure we haven't run out of space in our output buffer... if (outputIndex < output.data.length) { @@ -461,193 +536,302 @@ function bgraToImageData(input, width, height) { // This function takes in a Javascript Image object, and outputs it as an // ImageData object instead... -function imageToImageData(image) { +function imageToImageData(image, keepAlpha = true) { // Create a virtual canvas, and load it up with our image file... - var canvas = document.createElement("canvas"); - var context = canvas.getContext("2d"); + const canvas = document.createElement("canvas"); + const context = canvas.getContext("2d"); canvas.width = image.width; canvas.height = image.height; // Draw our image to the canvas, which will allow us to get data about the - // image... + // image. If the user doesn't want to keep the alpha channel, draw the image + // on a black background... + if (!keepAlpha) { + context.fillStyle = "black"; + context.fillRect(0, 0, image.width, image.height); + } context.drawImage(image, 0, 0, image.width, image.height); - var imageData = context.getImageData(0, 0, image.width, image.height); + const imageData = context.getImageData(0, 0, image.width, image.height); // Return the ImageData object... return imageData; } -// This function takes in an ImageData object, and returns a new ImageData -// object containing a scaled version of the original image. The new image's -// width, height and scaling method are also specified... -function scaleImage(input, newWidth, newHeight, method) { +// This function takes in an ImageData object "input", and returns a new +// ImageData object containing a scaled version of the original image resized to +// "newWidth" and "newHeight". Two different scaling methods are supported: +// "Nearest Neighbour", and "Bilinear", although specifically when downscaling, +// "Bilinear" is just a friendly name for two different scaling +// filters/techniques that are used in a hybrid approach - halve-to-target, and +// Hermite interpolation... +function scaleImage(input, newWidth, newHeight, method, downscaleFilter = "hermite") { - // Utility function which takes in an ImageData object, and returns - // a (partially) upscaled version using bilinear filtering... + // Utility function which takes in an ImageData object, and returns a scaled + // version using bilinear filtering... function _bilinear(imageData, newWidth, newHeight) { - var canvas = document.createElement("canvas"); - var context = canvas.getContext("2d"); - canvas.width = imageData.width; - canvas.height = imageData.height; - context.putImageData(imageData, 0, 0); - var outCanvas = document.createElement("canvas"); - var outContext = outCanvas.getContext("2d"); - outContext.imageSmoothingEnabled = true; - outContext.imageSmoothingQuality = "high"; - outCanvas.width = newWidth; - outCanvas.height = newHeight; - outContext.drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, newWidth, newHeight); - - return outContext.getImageData(0, 0, newWidth, newHeight); - } - - // Utility function which takes in an ImageData object, and returns - // a (partially) downscaled version using gaussian resampling... - // [Side note: I asked Bing AI for this function; ain't technology grand!] - function _gaussian(imageData, newWidth, newHeight) { - - // Get the original width and height of the image data - let oldWidth = imageData.width; - let oldHeight = imageData.height; - - // Get the pixel data array of the image data - let oldData = imageData.data; - - // Create a new pixel data array for the scaled image data - let newData = new Uint8ClampedArray(newWidth * newHeight * 4); - - // Calculate the scaling factor along each axis - let scaleX = newWidth / oldWidth; - let scaleY = newHeight / oldHeight; - - // Calculate the radius of the Gaussian kernel based on the scaling factor - let radiusX = Math.ceil(1 / scaleX); - let radiusY = Math.ceil(1 / scaleY); - - // Calculate the size of the Gaussian kernel along each axis - let sizeX = radiusX * 2 + 1; - let sizeY = radiusY * 2 + 1; - - // Create a Gaussian kernel array - let kernel = new Float32Array(sizeX * sizeY); - - // Calculate the standard deviation of the Gaussian distribution based on - // the radius - let sigmaX = radiusX / 3; - let sigmaY = radiusY / 3; - - // Calculate the inverse of the variance of the Gaussian distribution along - // each axis - let invVarX = 1 / (2 * sigmaX * sigmaX); - let invVarY = 1 / (2 * sigmaY * sigmaY); - - // Calculate the normalization factor for the Gaussian kernel - let norm = Math.sqrt(2 * Math.PI * sigmaX * sigmaY); - - // Loop through each element in the Gaussian kernel array - for (let ky = -radiusY; ky <= radiusY; ky++) { - for (let kx = -radiusX; kx <= radiusX; kx++) { - // Calculate the index of the element in the Gaussian kernel array - let k = (ky + radiusY) * sizeX + (kx + radiusX); - - // Calculate the value of the element using the Gaussian formula - kernel[k] = Math.exp(-(kx * kx) * invVarX - (ky * ky) * invVarY) / norm; - } + // Just in case, let's check to see if imageData's dimensions are already at + // the target width and height - if they are, there's no need to do anything + // to it, and we can just return it as-is... + if (imageData.width == newWidth && imageData.height == newHeight) { + return imageData; } - // Loop through each pixel in the new image data - for (let y = 0; y < newHeight; y++) { - for (let x = 0; x < newWidth; x++) { - // Calculate the corresponding coordinates in the old image data - let oldX = x / scaleX; - let oldY = y / scaleY; + // If we're here, then nope - we have some scaling to do! Create a canvas + // object and draw our input ImageData object to it... + const inputCanvas = document.createElement("canvas"); + const inputContext = inputCanvas.getContext("2d"); + inputCanvas.width = imageData.width; + inputCanvas.height = imageData.height; + inputContext.putImageData(imageData, 0, 0); - // Initialize the RGBA values of the pixel to zero - let r7 = 0; - let g7 = 0; - let b7 = 0; - let a7 = 0; + // Create another canvas object with the target dimensions, and draw the + // inputCanvas to it at target dimensions; this utilises the browser's + // native bilinear filtering... + const outputCanvas = document.createElement("canvas"); + const outputContext = outputCanvas.getContext("2d"); + outputContext.imageSmoothingEnabled = true; + outputContext.imageSmoothingQuality = "high"; + outputCanvas.width = newWidth; + outputCanvas.height = newHeight; + outputContext.drawImage(inputCanvas, 0, 0, inputCanvas.width, inputCanvas.height, 0, 0, newWidth, newHeight); - // Initialize the sum of the kernel values to zero - let sum = 0; + // Return an ImageData object pulled from the output canvas... + return outputContext.getImageData(0, 0, newWidth, newHeight); + } - // Loop through each element in the Gaussian kernel array - for (let ky = -radiusY; ky <= radiusY; ky++) { - for (let kx = -radiusX; kx <= radiusX; kx++) { - // Calculate the index of the element in the Gaussian kernel array - let k = (ky + radiusY) * sizeX + (kx + radiusX); + // Utility function which takes in an ImageData object, and returns a + // downscaled version using a technique that involves downscaling the input's + // width and height repeatedly by half until doing so again would take the + // image below the target dimensions. The result is then blended with the next + // scale down based on how close the target dimensions are to the current or + // next scale - this essentially gives an effect like mip-mapping in 3D games. + // This method is fast, doesn't introduce image distortion, and works great + // with alpha channels... but can give "soft" images if the target image + // dimensions are just under native scale (or a 50% downscale threshold), and + // can give a "harsh" image if the target dimensions are just above a + // downscale threshold. I try to mitigate the latter by blending in an + // additional downscale when we get close to a downscale threshold. This + // function and sub-functions are based on the following JSFiddle code, but + // with my own modifications: https://jsfiddle.net/1b68eLdr/93089/ + function _halveToTarget(imageData, newWidth, newHeight) { - // Get the value of the element in the Gaussian kernel array - let w = kernel[k]; + // This sub-function takes two ImageData objects (assumed to be of identical + // dimensions) and blends their RGBA data together based on the passed-in + // amount (between 0 and 1 inclusive) of how much of imageDataOne should be + // in the blend. An amount of 1 means the result will be purely + // imageDataOne, while an amount of 0 means the result will be purely + // imageDataTwo. Numbers between 0 and 1 will give an appropriate mix of the + // two. The result of the blend is then returned as an ImageData object... + function blendImageDatas(imageDataOne, imageDataTwo, amountImageDataOne){ + const blendedData = new ImageData(imageDataOne.width, imageDataOne.height); + const amountImageDataTwo = 1 - amountImageDataOne; + for (let i = 0; i < imageDataOne.data.length; i += 4) { + blendedData.data[i ] = (imageDataOne.data[i ] * amountImageDataOne) + (imageDataTwo.data[i ] * amountImageDataTwo); + blendedData.data[i + 1] = (imageDataOne.data[i + 1] * amountImageDataOne) + (imageDataTwo.data[i + 1] * amountImageDataTwo); + blendedData.data[i + 2] = (imageDataOne.data[i + 2] * amountImageDataOne) + (imageDataTwo.data[i + 2] * amountImageDataTwo); + blendedData.data[i + 3] = (imageDataOne.data[i + 3] * amountImageDataOne) + (imageDataTwo.data[i + 3] * amountImageDataTwo); + } + return blendedData; + } - // Calculate the coordinates of the pixel in the old image data that - // corresponds to this element - let x1 = Math.round(oldX + kx); - let y1 = Math.round(oldY + ky); + // First, let's just copy imageData, and work on the copy instead - just in + // case we don't want to modify the input directly (it's passed by reference + // because it's an object - thanks JavaScript!) + let inputData = new ImageData(imageData.width, imageData.height); + inputData.data.set(imageData.data); - // Clamp the coordinates to the valid range - x1 = Math.max(0, Math.min(x1, oldWidth - 1)); - y1 = Math.max(0, Math.min(y1, oldHeight - 1)); + // Now let's reduce the input's width and height (independently) until doing + // so again would take the input's dimensions below the target dimensions; + // we'll use plain-old browser bilinear filtering to do this... + while (newWidth <= Math.round(inputData.width * 0.5)) { + inputData = _bilinear(inputData, Math.round(inputData.width * 0.5), inputData.height); + } + while (newHeight <= Math.round(inputData.height * 0.5)) { + inputData = _bilinear(inputData, inputData.width, Math.round(inputData.height * 0.5)); + } - // Get the index of the pixel in the old pixel data array - let i1 = (y1 * oldWidth + x1) * 4; + // Now, inputData either exactly matches the dimensions of newWidth AND + // newHeight (in which case we're done), OR one or more of inputData's + // dimensions is greater than newWidth/newHeight. In that case, we want to + // generate the next level down for the dimensions that't aren't equal, and + // then blend between inputData (which is too detailed) and the next level + // down (which is too soft) based on how far away from the next level down + // we are - this essentially gives an effect like mip-mapping, and will help + // to ensure that transitions across 50% downscale thresholds aren't too + // jarring... + if (newWidth < inputData.width || newHeight < inputData.height) { - // Get the RGBA values of the pixel in the old pixel data array - let r1 = oldData[i1]; - let g1 = oldData[i1 + 1]; - let b1 = oldData[i1 + 2]; - let a1 = oldData[i1 + 3]; + // OK, one or more of inputData's dimensions is greater than + // newWidth/newHeight, so we're going to be doing some blending. First we + // need to generate the next scale of image downwards - just like before, + // we'll do each dimension separately... + let blendData = new ImageData(inputData.width, inputData.height); + blendData.data.set(inputData.data); + if (newWidth < inputData.width) { + blendData = _bilinear(blendData, Math.round(blendData.width * 0.5), blendData.height); + } + if (newHeight < inputData.height) { + blendData = _bilinear(blendData, blendData.width, Math.round(blendData.height * 0.5)); + } - // Multiply the RGBA values by the kernel value and add them to the - // pixel values - r7 += r1 * w; - g7 += g1 * w; - b7 += b1 * w; - a7 += a1 * w; + // Now we have the next level of downscale, we need to work out where + // our target width and height lie between inputData's width and height, + // and blendData's width and height - that'll tell us what proportion of + // each image should be in the final blend between the two. Once we've + // worked that out, we blend inputData with blendData accordingly + // (blendData gets upscaled to inputData's resolution first, to make the + // blending less complicated)... + let axisBeingBlended = 0; + let widthFactor = 0; + let heightFactor = 0; + if (inputData.width - blendData.width != 0) { + widthFactor = (newWidth - blendData.width) / (inputData.width - blendData.width); + axisBeingBlended += 1; + } + if (inputData.height - blendData.height != 0) { + heightFactor = (newHeight - blendData.height) / (inputData.height - blendData.height); + axisBeingBlended += 1; + } + inputData = blendImageDatas(inputData, _bilinear(blendData, inputData.width, inputData.height), (widthFactor + heightFactor) / axisBeingBlended); + } - // Add the kernel value to the sum - sum += w; + // Finally, return imageData as scaled to the final desired width and height + // (it may not currently exactly those dimensions)... + return _bilinear(inputData, newWidth, newHeight); + } + + // Utility function that takes in an ImageData object, and returns a + // downscaled version using a technique called Hermite interpolation. This + // method is a little slow, produces very high-quality output and works great + // with alpha channels... but it can introduce a little image distortion with + // high-frequency inputs, as well as some light aliasing on very fine details. + // To mitigate this, I've modified it to use a hybrid approach - I scale the + // image image to twice the target width and height using _halveToTarget + // (defined above), even if this means upscaling the input image first, and + // *then* I downscale the result using Hermite interpolation. The result is a + // bit slower again (as the input gets rescaled several times), but produced + // excellent results with zero distortion across all of my test images, even + // those with huge downscale ratios and very fine details (starfields). The + // core of this function is based on the following JSFiddle code, but again + // with some modifications by myself: https://jsfiddle.net/9g9Nv/442/ + function _hermite(imageData, newWidth, newHeight){ + + // So the very first thing we do is rescale the input to twice the desired + // width and height using _halveToTarget and bilinear filtering (which may + // involve upscaling the input), before we use Hermite interpolation to + // downscale to the final target resolution - this hybrid approach appears + // to give excellent results for a slight speed penalty. We just call our + // main scaleImage() function, and force it to use "halveToTarget" instead + // of the default "hermite" method (don't want to be stuck in an infinite + // loop!). We'll do all our work on a copy of the input, just in case + // we don't want to modify that in the calling code... + let inputData = new ImageData(imageData.width, imageData.height); + inputData.data.set(imageData.data); + inputData = scaleImage(inputData, newWidth * 2, newHeight * 2, "Bilinear", "halveToTarget"); + + // OK, now it's on to the main Hermite interpolation; thanks to the original + // author of the JSFiddle! I've just cleaned up their code a little to fit + // within my use-case here. I'm not a "maths" person, and so the + // underpinnings of Hermite interpolation go over my head (I'm talking about + // the Wikipedia article here)... but from reading the code below, what I + // believe is happening is that it loops through the input data, and breaks + // it up into little rectangular chunks, where each chunk will become one + // pixel in the output image. It goes through each pixel of the chunk, and + // accumulates a weighted version of its RGBA data into a buffer (the gr_X + // variables). Once it's finished going through the chunk, it takes the + // accumulation buffer and uses the total weight to calculate a final RGBA + // for the matching pixel in the output buffer and stores it. The bit that's + // over my head is why the weighting is calculated the way it is... I'll + // leave that as an exercise to the more mathematically inclined, and just + // say silent thanks to the JSFiddle author again! I've renamed their + // original variables to match my own understanding as best I can, in case + // it helps to parse it a bit better... + const ratioWidth = inputData.width / newWidth; + const ratioWidthHalf = Math.ceil(ratioWidth / 2); + const ratioHeight = inputData.height / newHeight; + const ratioHeightHalf = Math.ceil(ratioHeight / 2); + const output = new ImageData(newWidth, newHeight); + + // Loop through our desired output (as we're calculating the final value + // of each output pixel directly)... + for (let outputY = 0; outputY < newHeight; outputY++) { + for (let outputX = 0; outputX < newWidth; outputX++) { + + let currentWeight = 0; + let totalWeightRGB = 0; + let totalWeightAlpha = 0; + let accumulatorRed = 0; + let accumulatorGreen = 0; + let accumulatorBlue = 0; + let accumulatorAlpha = 0; + const center_y = (outputY + 0.5) * ratioHeight; + + // Calculate the borders of the "chunk" of input that'll be weighted + // down to a single output pixel... + const inputChunkLeftEdge = Math.floor(outputX * ratioWidth); + const inputChunkRightEdge = Math.min(Math.ceil((outputX + 1) * ratioWidth), inputData.width); + const inputChunkTopEdge = Math.floor(outputY * ratioHeight); + const inputChunkBottomEdge = Math.min(Math.ceil((outputY + 1) * ratioHeight), inputData.height); + + // Now loop through the input rows within that chunk... + for (let inputY = inputChunkTopEdge; inputY < inputChunkBottomEdge; inputY++) { + + // These three lines I'm not sure about, to be honest... + const dy = Math.abs(center_y - (inputY + 0.5)) / ratioHeightHalf; + const center_x = (outputX + 0.5) * ratioWidth; + const w0 = dy * dy; + + // And loop through the input columns within those rows... + for (let inputX = inputChunkLeftEdge; inputX < inputChunkRightEdge; inputX++) { + + // Again, these lines are similar to the three above; I know "w" is + // used in the Hermite weighting calculation... + const dx = Math.abs(center_x - (inputX + 0.5)) / ratioWidthHalf; + const w = Math.sqrt(w0 + dx * dx); + if (w >= 1) { + continue; + } + + // This line is where the Hermite weighting is calculated... + currentWeight = 2 * w * w * w - 3 * w * w + 1; + + // Now we use the weighting to fractions of the source pixel RGBA + // data in our accumulators; we also add the weight of the current + // pixel to a weight accumulator... + const pos_x = 4 * (inputX + inputY * inputData.width); + accumulatorAlpha += currentWeight * inputData.data[pos_x + 3]; + totalWeightAlpha += currentWeight; + if (inputData.data[pos_x + 3] < 255) { + currentWeight = currentWeight * inputData.data[pos_x + 3] / 250; + } + accumulatorRed += currentWeight * inputData.data[pos_x]; + accumulatorGreen += currentWeight * inputData.data[pos_x + 1]; + accumulatorBlue += currentWeight * inputData.data[pos_x + 2]; + totalWeightRGB += currentWeight; } } - // Divide the RGBA values by the sum to get an average value - r7 /= sum; - g7 /= sum; - b7 /= sum; - a7 /= sum; - - // Round the RGBA values to integers - r7 = Math.round(r7); - g7 = Math.round(g7); - b7 = Math.round(b7); - a7 = Math.round(a7); - - // Get the index of the pixel in the new pixel data array - let j = (y * newWidth + x) * 4; - - // Set the RGBA values of the pixel in the new pixel data array - newData[j] = r7; - newData[j + 1] = g7; - newData[j + 2] = b7; - newData[j + 3] = a7; + // Now that we've finished accumulating the weighted RGBA data for that + // entire source "chunk", we divide it by the total weight and store the + // result in our output ImageData object... + const pixelIndex = (outputX + outputY * newWidth) * 4; + output.data[pixelIndex ] = accumulatorRed / totalWeightRGB; + output.data[pixelIndex + 1] = accumulatorGreen / totalWeightRGB; + output.data[pixelIndex + 2] = accumulatorBlue / totalWeightRGB; + output.data[pixelIndex + 3] = accumulatorAlpha / totalWeightAlpha; } } - - // Create and return a new ImageData object with the new pixel data array - // and dimensions - return new ImageData(newData, newWidth, newHeight); + + // And that's it - output now contains the downscaled image, so return it! + return output; } - // Get the original width and height... - var width = input.width; - var height = input.height; - // Before we consider doing *any* scaling, let's check to make sure the new // dimensions are different from the old ones; if they're not, there's no // point in doing any scaling! - if (width == newWidth && height == newHeight) { + if (input.width == newWidth && input.height == newHeight) { return input; } @@ -659,43 +843,33 @@ function scaleImage(input, newWidth, newHeight, method) { // If the method is "Nearest Neighbour"... case "Nearest Neighbour": - // Create a new canvas element to draw the scaled image (we'll use the - // canvas to get our output ImageData object)... - var canvas = document.createElement("canvas"); - var context = canvas.getContext("2d"); - - // Set the canvas size to the new dimensions... - canvas.width = newWidth; - canvas.height = newHeight; - - // Create a new image data object to store the scaled pixel data... - var scaledData = context.createImageData(newWidth, newHeight); + // Create a new ImageData object to store the scaled pixel data... + const outputData = new ImageData(newWidth, newHeight); // Loop through each pixel of the new image... - for (var y = 0; y < newHeight; y++) { - for (var x = 0; x < newWidth; x++) { + for (let outputY = 0; outputY < newHeight; outputY++) { + for (let outputX = 0; outputX < newWidth; outputX++) { - // Calculate the index of the new pixel in the scaled data array... - var index = (y * newWidth + x) * 4; + // Calculate the index of the new pixel in the output data... + const outputIndex = (outputY * newWidth + outputX) * 4; // Calculate the x and y coordinates of the corresponding pixel in - // the original image... - var x2 = Math.floor(x * width / newWidth); - var y2 = Math.floor(y * height / newHeight); + // the original image, and it's index within input's data... + const inputX = Math.floor(outputX * input.width / newWidth); + const inputY = Math.floor(outputY * input.height / newHeight); + const inputIndex = (inputY * input.width + inputX) * 4; - // Calculate the index of the original pixel in the data array... - var index2 = (y2 * width + x2) * 4; - - // Copy the color values from the original pixel to the new pixel... - scaledData.data[index] = input.data[index2]; // Red - scaledData.data[index + 1] = input.data[index2 + 1]; // Green - scaledData.data[index + 2] = input.data[index2 + 2]; // Blue - scaledData.data[index + 3] = input.data[index2 + 3]; // Alpha + // Copy the color values from the input pixel to the output pixel... + outputData.data[outputIndex] = input.data[inputIndex]; // Red + outputData.data[outputIndex + 1] = input.data[inputIndex + 1]; // Green + outputData.data[outputIndex + 2] = input.data[inputIndex + 2]; // Blue + outputData.data[outputIndex + 3] = input.data[inputIndex + 3]; // Alpha } } // Finally, return the scaled ImageData object... - return scaledData; + return outputData; + break; // If the method is "Bilinear"... case "Bilinear": @@ -704,66 +878,73 @@ function scaleImage(input, newWidth, newHeight, method) { // you're *upscaling* an image, but if you're *downscaling* an image // by more than half the original's width/height, then true bilinear // filtering creates just as much of an aliased mess as nearest - // neighbour filtering. Most image editing apps therefore cheat and - // use a resampling algorithm when downscaling, and bilinear filtering - // when upscaling... so that's what we're going to do here too! We'll - // use gaussian resampling for any image axis that's being downscaled, - // and bilinear for any axis that's being upscaled; this should give - // the user a result that's much closer to what they'd expect to see... + // neighbour filtering once you get down to downscaling by more than half + // the dimensions of the original image. Most image editing apps therefore + // cheat and use a resampling algorithm when downscaling, and bilinear + // filtering when upscaling... so that's what we're going to do here too! + // We'll use a hybrid of bilinear and Hermite interpolation for any image + // axis that's being downscaled, and bilinear for any axis that's being + // upscaled; this should give the user a result that's much closer to what + // they'd expect to see from a graphics app like Photoshop or similar... + let upscaling = false, downscaling = false; + if (newWidth > input.width || newHeight > input.height) { upscaling = true; } + if (newWidth < input.width || newHeight < input.height) { downscaling = true; } - // Let's see which kind of scaling scenario we're in... - if (newWidth > width && newHeight > height) { - - // All dimensions being upscaled, so we'll use bilinear filtering for - // everything... + // Now we'll process the image differently depending on whether or not + // we're only upscaling, only downscaling, or doing a mix of upscaling and + // downscaling. In the case of a mix, we do the upscaling part first, and + // the downscaling part second, as it'll give a slightly sharper result... + if (upscaling && !downscaling) { + // Upscale only... return _bilinear(input, newWidth, newHeight); } - else if (newWidth < width && newHeight < height) { - - // All dimensions being downscaled, so we'll use gaussian resampling - // for everything... - return _gaussian(input, newWidth, newHeight); + else if (downscaling && !upscaling) { + // Downscale only - run the input through either our halve-to-target or + // Hermite filter... + switch (downscaleFilter){ + case "hermite": + return _hermite(input, newWidth, newHeight); + break; + case "halveToTarget": + return _halveToTarget(input, newWidth, newHeight); + break; + } } else { - - // It's a mix! - if (newWidth < width) { - - // Gaussian for width, bilinear for height... - let partial = _gaussian(input, newWidth, height); - return _bilinear(partial, newWidth, newHeight); + // Both upscaling and downscaling... do the upscale first, then send the + // result back to this function again for downscaling... + let partiallyScaled; + if (newWidth > input.width) { + // Upscale width + partiallyScaled = _bilinear(input, newWidth, input.height); } - else if (newHeight < height) { - - // Gaussian for height, bilinear for width... - let partial = _gaussian(input, width, newHeight); - return _bilinear(partial, newWidth, newHeight); + else { + // Upscale height + partiallyScaled = _bilinear(input, input.width, newHeight); } + // Downscale the rest... + return scaleImage(partiallyScaled, newWidth, newHeight, method, downscaleFilter); } break; } } // This utility function is used for adding info, warning and error messages to -// the appropriate spots in my tools. It uses custom-modified versions of the -// SVG Famfamfam Silk icon set via https://github.com/frhun/silk-icon-scalable +// the appropriate spots in my tools... function setMessage(type, divID, text) { - var icon; + let icon = ""; switch(type) { case "info": - icon = ''; - break; + icon = "ℹ️"; + break; case "warning": - icon = ''; - break; + icon = "⚠️"; + break; case "error": - icon = ''; - break; + icon = "🛑"; + break; } - document.getElementById(divID).innerHTML = "

" + icon + " " + text + "

"; - - return; } \ No newline at end of file