-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f970bc3
commit 6e98a9c
Showing
7 changed files
with
144 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
import test from 'ava' | ||
|
||
import { sum } from '../index.js' | ||
import { sum, encodeImage } from '../index.js' | ||
import * as fs from "node:fs"; | ||
|
||
test('sum from native', (t) => { | ||
t.is(sum(1, 2), 3) | ||
t.is(sum(1, 2), 3) | ||
}) | ||
|
||
test('encode random 1', t => { | ||
let buffer = fs.readFileSync('images/6a12c0010c6e708422f5ba5121ba4a8adc9c7374c2b96fd0754c84f25e181598.png'); | ||
let arr = new Uint8Array(buffer); | ||
let encoded = encodeImage(arr); | ||
|
||
let hash = Buffer.from(encoded.hash).toString('hex'); | ||
console.log(hash); | ||
|
||
let mchash = Buffer.from(encoded.minecraftHash).toString('hex'); | ||
console.log(mchash); | ||
|
||
console.log(encoded.hex) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require('fs'); | ||
const {createCanvas, loadImage} = require("canvas"); | ||
|
||
function makeRandomImage(width = 64, height = 64) { | ||
const canvas = createCanvas(width, height); | ||
const context = canvas.getContext("2d"); | ||
const imageData = context.getImageData(0, 0, width, height); | ||
|
||
// https://gist.github.com/biovisualize/5400576#file-index-html-L26 | ||
const buffer = new ArrayBuffer(imageData.data.length); | ||
const clampedBuffer = new Uint8ClampedArray(buffer); | ||
const data = new Uint32Array(buffer); | ||
|
||
for (let x = 0; x < width; x++) { | ||
for (let y = 0; y < height; y++) { | ||
data[y * width + x] = | ||
(255 << 24) | | ||
(((Math.random() * 300) % 255) << 16) | | ||
(((Math.random() * 300) % 255) << 8) | | ||
(((Math.random() * 300) % 255)) | ||
} | ||
} | ||
|
||
imageData.data.set(clampedBuffer); | ||
context.putImageData(imageData, 0, 0); | ||
|
||
// Make Buffer | ||
const dataUrl = canvas.toDataURL("image/png").substr("data:image/png;base64,".length); | ||
const imageBuffer = new Buffer(dataUrl, 'base64'); | ||
const blob = new Blob([imageBuffer], { type: "image/png" }); | ||
return { imageBuffer, imageData, data, blob } | ||
} | ||
|
||
(() => { | ||
const { imageBuffer, imageData, data, blob } = makeRandomImage(64, 64); | ||
fs.writeFileSync('images/randomImage.png', imageBuffer); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters