Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/util/epd/gdey037z03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class Gdey037z03 extends Epd {
get controller => Uc8253() as Driver;

Gdey037z03() {
processingMethods.add(ImageProcessing.rwbTriColorDither);
processingMethods.add(ImageProcessing.colorHalftone);
processingMethods.add(ImageProcessing.bwrFloydSteinbergDither);
processingMethods.add(ImageProcessing.bwrFalseFloydSteinbergDither);
processingMethods.add(ImageProcessing.bwrStuckiDither);
processingMethods.add(ImageProcessing.bwrTriColorAtkinsonDither);
processingMethods.add(ImageProcessing.bwrHalftone);
processingMethods.add(ImageProcessing.bwrThreshold);
}
}
8 changes: 6 additions & 2 deletions lib/util/epd/gdey037z03bw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class Gdey037z03BW extends Epd {
get controller => Uc8253() as Driver;

Gdey037z03BW() {
processingMethods.add(ImageProcessing.binaryDither);
processingMethods.add(ImageProcessing.halftone);
processingMethods.add(ImageProcessing.bwFloydSteinbergDither);
processingMethods.add(ImageProcessing.bwFalseFloydSteinbergDither);
processingMethods.add(ImageProcessing.bwStuckiDither);
processingMethods.add(ImageProcessing.bwAtkinsonDither);
processingMethods.add(ImageProcessing.bwHalftoneDither);
processingMethods.add(ImageProcessing.bwThreshold);
}
}
93 changes: 66 additions & 27 deletions lib/util/image_processing/image_processing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,82 @@ import 'extract_quantizer.dart';
import 'remap_quantizer.dart';

class ImageProcessing {
static img.Image binaryDither(img.Image orgImg) {
static img.Image bwFloydSteinbergDither(img.Image orgImg) {
var image = img.Image.from(orgImg);
return img.ditherImage(image, quantizer: img.BinaryQuantizer());
}

static img.Image halftone(img.Image orgImg) {
static img.Image bwFalseFloydSteinbergDither(img.Image orgImg) {
var image = img.Image.from(orgImg);
return img.ditherImage(image,
quantizer: img.BinaryQuantizer(),
kernel: img.DitherKernel.falseFloydSteinberg);
}

static img.Image bwStuckiDither(img.Image orgImg) {
var image = img.Image.from(orgImg);
return img.ditherImage(image,
quantizer: img.BinaryQuantizer(), kernel: img.DitherKernel.stucki);
}

static img.Image bwAtkinsonDither(img.Image orgImg) {
var image = img.Image.from(orgImg);
return img.ditherImage(image,
quantizer: img.BinaryQuantizer(), kernel: img.DitherKernel.atkinson);
}

static img.Image bwThreshold(img.Image orgImg) {
var image = img.Image.from(orgImg);
return img.ditherImage(image,
quantizer: img.BinaryQuantizer(), kernel: img.DitherKernel.none);
}

static img.Image bwHalftoneDither(img.Image orgImg) {
final image = img.Image.from(orgImg);
img.grayscale(image);
img.colorHalftone(image);
img.colorHalftone(image, size: 3);
return img.ditherImage(image, quantizer: img.BinaryQuantizer());
}

static img.Image colorHalftone(img.Image orgImg) {
static img.Image bwrHalftone(img.Image orgImg) {
var image = img.Image.from(orgImg);

// Tri-color palette
final palette = img.PaletteUint8(3, 3);
palette.setRgb(0, 255, 0, 0); // red
palette.setRgb(1, 0, 0, 0); // black
palette.setRgb(2, 255, 255, 255); // white
img.colorHalftone(image, size: 3);
return img.ditherImage(image,
quantizer: RemapQuantizer(palette: _createTriColorPalette()),
kernel: img.DitherKernel.floydSteinberg);
}

static img.Image bwrFloydSteinbergDither(img.Image orgImg) {
var image = img.Image.from(orgImg);

img.colorHalftone(image);
return img.ditherImage(image,
quantizer: RemapQuantizer(palette: palette),
quantizer: RemapQuantizer(palette: _createTriColorPalette()),
kernel: img.DitherKernel.floydSteinberg);
}

static img.Image rwbTriColorDither(img.Image orgImg) {
static img.Image bwrFalseFloydSteinbergDither(img.Image orgImg) {
var image = img.Image.from(orgImg);

// Tri-color palette
final palette = img.PaletteUint8(3, 3);
palette.setRgb(0, 255, 0, 0); // red
palette.setRgb(1, 0, 0, 0); // black
palette.setRgb(2, 255, 255, 255); // white
return img.ditherImage(image,
quantizer: RemapQuantizer(palette: _createTriColorPalette()),
kernel: img.DitherKernel.falseFloydSteinberg);
}

static img.Image bwrStuckiDither(img.Image orgImg) {
var image = img.Image.from(orgImg);

return img.ditherImage(image,
quantizer: RemapQuantizer(palette: palette),
kernel: img.DitherKernel.floydSteinberg);
quantizer: RemapQuantizer(palette: _createTriColorPalette()),
kernel: img.DitherKernel.stucki);
}

static img.Image bwrTriColorAtkinsonDither(img.Image orgImg) {
var image = img.Image.from(orgImg);

return img.ditherImage(image,
quantizer: RemapQuantizer(palette: _createTriColorPalette()),
kernel: img.DitherKernel.atkinson);
}

static img.Image extract(Color toBeExtract, img.Image orgImg) {
Expand All @@ -54,17 +91,19 @@ class ImageProcessing {
kernel: img.DitherKernel.none);
}

static img.Image experiment(img.Image orgImg) {
static img.Image bwrThreshold(img.Image orgImg) {
var image = img.Image.from(orgImg);

// Tri-color palette
final palette = img.PaletteUint8(3, 3);
palette.setRgb(0, 255, 0, 0); // red
palette.setRgb(1, 0, 0, 0); // black
palette.setRgb(2, 255, 255, 255); // white

return img.ditherImage(image,
quantizer: RemapQuantizer(palette: palette),
quantizer: RemapQuantizer(palette: _createTriColorPalette()),
kernel: img.DitherKernel.none);
}
}

img.PaletteUint8 _createTriColorPalette() {
final palette = img.PaletteUint8(3, 3);
palette.setRgb(0, 255, 0, 0); // red
palette.setRgb(1, 0, 0, 0); // black
palette.setRgb(2, 255, 255, 255); // white
return palette;
}
55 changes: 48 additions & 7 deletions lib/view/image_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:image/image.dart' as img;

import 'package:magic_epaper_app/provider/image_loader.dart';
import 'package:magic_epaper_app/util/epd/epd.dart';
import 'package:magic_epaper_app/constants.dart';

class ImageEditor extends StatelessWidget {
final Epd epd;
Expand All @@ -31,15 +32,50 @@ class ImageEditor extends StatelessWidget {
imgList: processedImgs,
epd: epd,
);

return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('Edit Image'),
iconTheme: const IconThemeData(
color: Colors.white,
),
backgroundColor: colorAccent,
elevation: 0,
title: const Center(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Text(
'Select Your Filter',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
toolbarHeight: 85,
actions: <Widget>[
TextButton(
onPressed: () {
imgLoader.pickImage(width: epd.width, height: epd.height);
},
child: const Text("Import Image"),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.white.withValues(alpha: 0.2),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
onPressed: () {
imgLoader.pickImage(width: epd.width, height: epd.height);
},
child: const Text(
"Import Image",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
TextButton(
onPressed: () async {
Expand All @@ -58,7 +94,12 @@ class ImageEditor extends StatelessWidget {
),
],
),
body: Center(child: imgList),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: imgList,
),
),
);
}
}
Loading