Initial commit
This commit is contained in:
commit
758503d33f
12 changed files with 164 additions and 0 deletions
BIN
web/cat.png
Normal file
BIN
web/cat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 238 KiB |
BIN
web/favicon.ico
Normal file
BIN
web/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
21
web/index.html
Normal file
21
web/index.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="scaffolded-by" content="https://github.com/google/stagehand">
|
||||
<title>dart_floyd_steinberg_dithering</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<link rel="icon" href="favicon.ico">
|
||||
<script defer src="main.dart" type="application/dart"></script>
|
||||
<script defer src="packages/browser/dart.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas id="input" width="712" height="470"></canvas>
|
||||
|
||||
<canvas id="output" width="712" height="470"></canvas>
|
||||
</body>
|
||||
</html>
|
||||
BIN
web/kitten.jpg
Normal file
BIN
web/kitten.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
56
web/main.dart
Normal file
56
web/main.dart
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import 'dart:html';
|
||||
import 'package:image/image.dart';
|
||||
|
||||
CanvasElement input;
|
||||
CanvasElement output;
|
||||
|
||||
ImageElement inputImg;
|
||||
|
||||
void main() {
|
||||
inputImg = new ImageElement(src: 'kitten.jpg', width: 712, height: 470);
|
||||
|
||||
input = document.querySelector('#input');
|
||||
print(input);
|
||||
inputImg.onLoad.listen(imgLoaded);
|
||||
|
||||
output = document.querySelector('#output');
|
||||
|
||||
output.context2D.fillRect(0, 0, output.width, output.height);
|
||||
}
|
||||
|
||||
void imgLoaded(Event e) {
|
||||
print("image loaded");
|
||||
input.context2D.drawImage(inputImg, 0, 0);
|
||||
|
||||
Image outputImg = editImage( getImageFromCanvas(input) );
|
||||
|
||||
drawImageToCanvas(output, outputImg ) ;
|
||||
}
|
||||
|
||||
Image getImageFromCanvas(CanvasElement input) {
|
||||
ImageData data = input.context2D.getImageData(0, 0, input.width, input.height);
|
||||
return new Image.fromBytes(input.width, input.height, data.data);
|
||||
}
|
||||
|
||||
void drawImageToCanvas(CanvasElement canvas, Image image) {
|
||||
var imageData = canvas.context2D.createImageData(image.width, image.height);
|
||||
imageData.data.setRange(0, imageData.data.length, image.getBytes());
|
||||
|
||||
canvas.context2D.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
Image editImage(Image image) {
|
||||
|
||||
|
||||
image = contrast( image, 200);
|
||||
|
||||
for (var y = 0; y < image.height; y++) {
|
||||
for (var x = 0; x < image.width; x++) {
|
||||
// print(image.getPixel(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
16
web/styles.css
Normal file
16
web/styles.css
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
@import url(https://fonts.googleapis.com/css?family=Roboto);
|
||||
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
background: gainsboro;
|
||||
}
|
||||
|
||||
canvas {
|
||||
padding: 00px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue