Skip to content

Commit

Permalink
General cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Jan 8, 2025
1 parent bef1e6b commit 3960baa
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 113 deletions.
8 changes: 3 additions & 5 deletions lib/history.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '/image.dart';

class HistoryManager {
final Function getImage;
final Function? updateCallback;
final SlyImage Function() getImage;
final void Function()? updateCallback;

final List<List<Map<String, SlyRangeAttribute>>> _undoList = [];
final List<List<Map<String, SlyRangeAttribute>>> _redoList = [];
Expand Down Expand Up @@ -35,7 +35,6 @@ class HistoryManager {
}

void undo() => _undoOrRedo(redo: false);

void redo() => _undoOrRedo(redo: true);

void _undoOrRedo({required bool redo}) {
Expand All @@ -57,7 +56,6 @@ class HistoryManager {
}
}

if (updateCallback == null) return;
updateCallback!();
updateCallback?.call();
}
}
87 changes: 38 additions & 49 deletions lib/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class SlyImage {

Map<String, SlyRangeAttribute> colorAttributes = {
'saturation': SlyRangeAttribute('Saturation', 1, 1, 0, 2),
'temp': SlyRangeAttribute('Temperature', 0, 0, -1, 1),
'temperature': SlyRangeAttribute('Temperature', 0, 0, -1, 1),
'tint': SlyRangeAttribute('Tint', 0, 0, -1, 1),
};

Expand All @@ -142,17 +142,33 @@ class SlyImage {
'rotation': SlyOverflowAttribute('Rotation', 0, 0, 4),
};

int get width {
return _image.width;
}

int get height {
return _image.height;
}

bool get loading {
return _loading > 0;
}
SlyRangeAttribute get exposure => lightAttributes['exposure']!;
SlyRangeAttribute get brightness => lightAttributes['brightness']!;
SlyRangeAttribute get contrast => lightAttributes['contrast']!;
SlyRangeAttribute get blacks => lightAttributes['blacks']!;
SlyRangeAttribute get whites => lightAttributes['whites']!;
SlyRangeAttribute get mids => lightAttributes['mids']!;

SlyRangeAttribute get saturation => colorAttributes['stauration']!;
SlyRangeAttribute get temperature => colorAttributes['temperature']!;
SlyRangeAttribute get tint => colorAttributes['tint']!;

SlyRangeAttribute get denoise => effectAttributes['denoise']!;
SlyRangeAttribute get sharpness => effectAttributes['sharpness']!;
SlyRangeAttribute get sepia => effectAttributes['sepia']!;
SlyRangeAttribute get vignette => effectAttributes['vignette']!;
SlyRangeAttribute get border => effectAttributes['border']!;

SlyBoolAttribute get hflip =>
geometryAttributes['hflip']! as SlyBoolAttribute;
SlyBoolAttribute get vflip =>
geometryAttributes['vflip']! as SlyBoolAttribute;
SlyOverflowAttribute get rotation =>
geometryAttributes['rotation']! as SlyOverflowAttribute;

int get width => _image.width;
int get height => _image.height;
bool get loading => _loading > 0;

/// True if the image is small enough and the device is powerful enough to load it.
bool get canLoadFullRes {
Expand Down Expand Up @@ -211,11 +227,9 @@ class SlyImage {

_loading -= 1;

if (editedImage == null) return;

if (_editsApplied > applied) return;

if (controller.isClosed) return;
if (editedImage == null || _editsApplied > applied || controller.isClosed) {
return;
}

_image = editedImage;
controller.add('updated');
Expand Down Expand Up @@ -308,15 +322,9 @@ class SlyImage {

if (skipGeometry) return;

geometryAttributes['hflip'] = SlyBoolAttribute.copy(
src.geometryAttributes['hflip'] as SlyBoolAttribute,
);
geometryAttributes['vflip'] = SlyBoolAttribute.copy(
src.geometryAttributes['vflip'] as SlyBoolAttribute,
);
geometryAttributes['rotation'] = SlyOverflowAttribute.copy(
src.geometryAttributes['rotation'] as SlyOverflowAttribute,
);
geometryAttributes['hflip'] = SlyBoolAttribute.copy(src.hflip);
geometryAttributes['vflip'] = SlyBoolAttribute.copy(src.vflip);
geometryAttributes['rotation'] = SlyOverflowAttribute.copy(src.rotation);
}

/// Removes Exif metadata from the image.
Expand Down Expand Up @@ -375,10 +383,7 @@ class SlyImage {
height: (rect.height * height).round(),
);

final croppedImage = (await cmd.executeThread()).outputImage;
if (croppedImage == null) return;

_originalImage = croppedImage;
_originalImage = (await cmd.executeThread()).outputImage ?? _originalImage;
}

/// Returns the image encoded as `format`.
Expand Down Expand Up @@ -462,28 +467,17 @@ class SlyImage {
..image(editableImage)
..copy();

final temp = colorAttributes['temp']!;
final tint = colorAttributes['tint']!;

for (SlyRangeAttribute attribute in [temp, tint]) {
for (SlyRangeAttribute attribute in [temperature, tint]) {
if (attribute.value != attribute.anchor) {
cmd.colorOffset(
red: 50 * temp.value,
red: 50 * temperature.value,
green: 50 * tint.value * -1,
blue: 50 * temp.value * -1,
blue: 50 * temperature.value * -1,
);
break;
}
}

final exposure = lightAttributes['exposure']!;
final brightness = lightAttributes['brightness']!;
final contrast = lightAttributes['contrast']!;
final saturation = colorAttributes['saturation']!;
final blacks = lightAttributes['blacks']!;
final whites = lightAttributes['whites']!;
final mids = lightAttributes['mids']!;

for (SlyRangeAttribute attribute in [
exposure,
brightness,
Expand Down Expand Up @@ -513,12 +507,10 @@ class SlyImage {
}
}

final sepia = effectAttributes['sepia']!;
if (sepia.value != sepia.anchor) {
cmd.sepia(amount: sepia.value);
}

final denoise = effectAttributes['denoise']!;
if (denoise.value != denoise.anchor) {
cmd.convolution(
filter: [
Expand All @@ -536,20 +528,17 @@ class SlyImage {
);
}

final sharpness = effectAttributes['sharpness']!;
if (sharpness.value != sharpness.anchor) {
cmd.convolution(
filter: [0, -1, 0, -1, 5, -1, 0, -1, 0],
amount: sharpness.value,
);
}

final vignette = effectAttributes['vignette']!;
if (vignette.value != vignette.anchor) {
cmd.vignette(amount: vignette.value);
}

final border = effectAttributes['border']!;
if (border.value != border.anchor) {
cmd.copyExpandCanvas(
backgroundColor: border.value > 0
Expand Down
2 changes: 1 addition & 1 deletion lib/juggler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SlyJuggler {
///
/// Does not include geometry attributes.
void pasteEdits() {
if (copiedEdits == null || copiedEdits == editedImage) return;
if ({editedImage, null}.contains(copiedEdits)) return;
editedImage?.copyEditsFrom(copiedEdits!, skipGeometry: true);
editedImage?.applyEditsProgressive();
}
Expand Down
4 changes: 1 addition & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ void main() async {

if (isDesktop) {
await windowManager.ensureInitialized();
}
if (isWindows) {
windowManager.setMinimumSize(const Size(360, 294));
if (isWindows) windowManager.setMinimumSize(const Size(360, 294));
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/controls_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '/widgets/slider_row.dart';

LinearGradient? getGradientForAttributeName(String name) {
switch (name) {
case 'temp':
case 'temperature':
return LinearGradient(colors: [
Colors.blue,
Colors.lightBlue.shade100,
Expand All @@ -30,7 +30,7 @@ LinearGradient? getGradientForAttributeName(String name) {
class SlyControlsListView extends StatelessWidget {
final Map<String, SlyRangeAttribute> attributes;
final HistoryManager history;
final Function updateImage;
final VoidCallback updateImage;

const SlyControlsListView({
super.key,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/slider_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _SlySliderRowState extends State<SlySliderRow> {
String label =
'${value < initial ? '-' : '+'}${(100 * ((v - i) / ((v < i ? min : max) - i))).round().toString()}';

return (label == '+0' || label == '-0') ? null : label;
return ({'+0', '-0'}.contains(label)) ? null : label;
}

late final slider = SlySlider(
Expand Down
Loading

0 comments on commit 3960baa

Please sign in to comment.