57 lines
2.2 KiB
HTML
57 lines
2.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Conversion d'image en C</title>
|
|
</head>
|
|
<body>
|
|
<h1>Conversion d'image en C</h1>
|
|
|
|
<input type="file" id="imageInput" accept="image/*" onchange="convertImage()">
|
|
|
|
<div id="result">
|
|
<!-- L'image convertie sera affichée ici -->
|
|
</div>
|
|
|
|
<script>
|
|
function convertImage() {
|
|
const inputElement = document.getElementById("imageInput");
|
|
const file = inputElement.files[0];
|
|
|
|
if (file) {
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function(event) {
|
|
const image = new Image();
|
|
image.src = event.target.result;
|
|
|
|
image.onload = function() {
|
|
const canvas = document.createElement("canvas");
|
|
canvas.width = 480;
|
|
canvas.height = 480;
|
|
const context = canvas.getContext("2d");
|
|
|
|
context.drawImage(image, 0, 0, 480, 480);
|
|
|
|
const imageData = context.getImageData(0, 0, 480, 480).data;
|
|
const outputArray = [];
|
|
|
|
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);
|
|
outputArray.push(`0x${rgb565.toString(16).toUpperCase()}, `);
|
|
}
|
|
|
|
const resultDiv = document.getElementById("result");
|
|
resultDiv.innerHTML = `<h2>Image convertie en tableau C :</h2><pre>const uint16_t image_data[] = {\n${outputArray.join("")}\n};</pre>`;
|
|
};
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|