63 lines
2.1 KiB
HTML
63 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Conversion d'image</title>
|
|
</head>
|
|
<body>
|
|
<input type="file" id="imageInput" accept="image/*">
|
|
<canvas id="canvas" style="display: none;"></canvas>
|
|
<button onclick="afficherResultat()">Convertir et Afficher</button>
|
|
|
|
<script>
|
|
function convertImage() {
|
|
const inputImage = document.getElementById('imageInput').files[0];
|
|
if (!inputImage) {
|
|
alert('Veuillez sélectionner une image.');
|
|
return null;
|
|
}
|
|
|
|
const canvas = document.getElementById('canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
const targetWidth = 480;
|
|
const targetHeight = 480;
|
|
|
|
const img = new Image();
|
|
img.onload = function() {
|
|
canvas.width = targetWidth;
|
|
canvas.height = targetHeight;
|
|
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
|
|
|
|
const imageData = ctx.getImageData(0, 0, targetWidth, targetHeight).data;
|
|
const output_h_path = 'image_data.h';
|
|
|
|
let outputData = `const uint16_t image_data[] = {\n`;
|
|
|
|
for (let i = 0; i < imageData.length; i += 4) {
|
|
const r = imageData[i];
|
|
const g = imageData[i + 1];
|
|
const b = imageData[i + 2];
|
|
const rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
|
outputData += `0x${rgb565.toString(16).toUpperCase()}, `;
|
|
}
|
|
|
|
outputData += '\n};';
|
|
|
|
return(outputData);
|
|
};
|
|
}
|
|
|
|
function afficherResultat() {
|
|
const resultat = convertImage();
|
|
if (resultat) {
|
|
console.log("Résultat de la conversion :");
|
|
console.log(resultat);
|
|
} else {
|
|
console.log("Aucune image sélectionnée.");
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|