Skip to content

Commit

Permalink
Merge pull request #2 from Flajt/main
Browse files Browse the repository at this point in the history
Sync main with gps lat long branch
  • Loading branch information
Flajt authored Nov 22, 2024
2 parents db98dee + a648616 commit a214097
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 61 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 4.3.0 - October 15, 2024

- Fix exceptions loading some PSD files.
- Fix trim for palette images.
- Fix ICC decompression.
- Add physical size handling to PNG.
- Fix TIFF out of bounds error.

## 4.2.0 - May 22, 2024

- Fix decoding EXIF data from WebP.
Expand Down
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:lints/recommended.yaml
include: package:lints/core.yaml
analyzer:
language:
strict-casts: true
Expand Down Expand Up @@ -62,7 +62,6 @@ linter:
- non_constant_identifier_names
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_asserts_in_initializer_lists
Expand Down
30 changes: 15 additions & 15 deletions lib/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,22 @@ export 'src/formats/png/png_info.dart' hide InternalPngInfo;
export 'src/formats/png_decoder.dart';
export 'src/formats/png_encoder.dart';
export 'src/formats/pnm_decoder.dart';
//export 'src/formats/psd/effect/psd_bevel_effect.dart';
//export 'src/formats/psd/effect/psd_drop_shadow_effect.dart';
//export 'src/formats/psd/effect/psd_effect.dart';
//export 'src/formats/psd/effect/psd_inner_glow_effect.dart';
//export 'src/formats/psd/effect/psd_inner_shadow_effect.dart';
//export 'src/formats/psd/effect/psd_outer_glow_effect.dart';
//export 'src/formats/psd/effect/psd_solid_fill_effect.dart';
//export 'src/formats/psd/layer_data/psd_layer_additional_data.dart';
//export 'src/formats/psd/layer_data/psd_layer_section_divider.dart';
//export 'src/formats/psd/psd_blending_ranges.dart';
//export 'src/formats/psd/psd_channel.dart';
export 'src/formats/psd/effect/psd_bevel_effect.dart';
export 'src/formats/psd/effect/psd_drop_shadow_effect.dart';
export 'src/formats/psd/effect/psd_effect.dart';
export 'src/formats/psd/effect/psd_inner_glow_effect.dart';
export 'src/formats/psd/effect/psd_inner_shadow_effect.dart';
export 'src/formats/psd/effect/psd_outer_glow_effect.dart';
export 'src/formats/psd/effect/psd_solid_fill_effect.dart';
export 'src/formats/psd/layer_data/psd_layer_additional_data.dart';
export 'src/formats/psd/layer_data/psd_layer_section_divider.dart';
export 'src/formats/psd/psd_blending_ranges.dart';
export 'src/formats/psd/psd_channel.dart';
export 'src/formats/psd/psd_image.dart';
//export 'src/formats/psd/psd_image_resource.dart';
//export 'src/formats/psd/psd_layer.dart';
//export 'src/formats/psd/psd_layer_data.dart';
//export 'src/formats/psd/psd_mask.dart';
export 'src/formats/psd/psd_image_resource.dart';
export 'src/formats/psd/psd_layer.dart';
export 'src/formats/psd/psd_layer_data.dart';
export 'src/formats/psd/psd_mask.dart';
export 'src/formats/psd_decoder.dart';
//export 'src/formats/pvr/pvr_bit_utility.dart';
//export 'src/formats/pvr/pvr_color.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/draw/_calculate_circumference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ List<Point> calculateCircumference(Image image, int x0, int y0, int radius) {
for (var f = 1 - radius, ddFx = 0, ddFy = -(radius << 1), x = 0, y = radius;
x < y;) {
if (f >= 0) {
f += (ddFy += 2);
f += ddFy += 2;
--y;
}
++x;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/exif/exif_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ class ExifData extends IfdContainer {
var index = 0;
while (ifdOffset > 0) {
block.offset = blockOffset + ifdOffset;
if (block.length < 2) {
break;
}

final directory = IfdDirectory();
final numEntries = block.readUint16();
Expand Down
18 changes: 15 additions & 3 deletions lib/src/formats/bmp_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ class BmpEncoder extends Encoder {
final rowPadding =
rowPaddingSize > 0 ? List<int>.filled(rowPaddingSize, 0xff) : null;

final implicitPaletteSize = bpp >= 1 && bpp <= 8 ? 1 << bpp : 0;

final imageFileSize = fileStride * image.height;
final headerInfoSize = bpp > 8 ? 124 : 40;
final headerSize = headerInfoSize + 14;
final paletteSize = (image.palette?.numColors ?? 0) * 4;
final paletteSize = implicitPaletteSize * 4;
final origImageOffset = headerSize + paletteSize;
final imageOffset = origImageOffset;
//final imageOffset = _roundToMultiple(origImageOffset);
Expand Down Expand Up @@ -161,14 +163,24 @@ class BmpEncoder extends Encoder {
if (bpp == 1 || bpp == 2 || bpp == 4 || bpp == 8) {
if (palette != null) {
//final palette = image.palette!;
final l = palette.numColors;
for (var pi = 0; pi < l; ++pi) {
final l = palette.numColors > implicitPaletteSize
? implicitPaletteSize
: palette.numColors;
var pi = 0;
for (pi = 0; pi < l; ++pi) {
out
..writeByte(palette.getBlue(pi).toInt())
..writeByte(palette.getGreen(pi).toInt())
..writeByte(palette.getRed(pi).toInt())
..writeByte(0);
}
for (; pi < implicitPaletteSize; ++pi) {
out
..writeByte(0)
..writeByte(0)
..writeByte(0)
..writeByte(0);
}
} else {
if (bpp == 1) {
out
Expand Down
19 changes: 14 additions & 5 deletions lib/src/formats/psd/psd_channel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:math';
import 'dart:typed_data';

import '../../util/image_exception.dart';
Expand All @@ -19,7 +20,7 @@ class PsdChannel {

int id;
int? dataLength;
late Uint8List data;
Uint8List? data;

PsdChannel(this.id, this.dataLength);

Expand All @@ -38,6 +39,9 @@ class PsdChannel {

void readPlane(InputBuffer input, int width, int height, int? bitDepth,
[int? compression, Uint16List? lineLengths, int planeNum = 0]) {
if (input.length < 2) {
return;
}
compression ??= input.readUint16();

switch (compression) {
Expand Down Expand Up @@ -70,7 +74,7 @@ class PsdChannel {
}
if (len > input.length) {
data = Uint8List(len);
data.fillRange(0, len, 255);
data!.fillRange(0, len, 255);
return;
}

Expand All @@ -88,23 +92,27 @@ class PsdChannel {
var pos = 0;
var lineIndex = planeNum * height;
if (lineIndex >= lineLengths.length) {
data.fillRange(0, data.length, 255);
data!.fillRange(0, data!.length, 255);
return;
}

for (var i = 0; i < height; ++i) {
final len = lineLengths[lineIndex++];
final s = input.readBytes(len);
_decodeRLE(s, data, pos);
_decodeRLE(s, data!, pos);
pos += width;
}
}

void _decodeRLE(InputBuffer src, Uint8List dst, int dstIndex) {
while (!src.isEOS) {
var n = src.readInt8();
var n = 0;
n = src.readInt8();
if (n < 0) {
n = 1 - n;
if (src.isEOS) {
break;
}
final b = src.readByte();
if ((dstIndex + n) > dst.length) {
n = dst.length - dstIndex;
Expand All @@ -117,6 +125,7 @@ class PsdChannel {
if ((dstIndex + n) > dst.length) {
n = dst.length - dstIndex;
}
n = min(n, src.length);
for (var i = 0; i < n; ++i) {
dst[dstIndex++] = src.readByte();
}
Expand Down
50 changes: 26 additions & 24 deletions lib/src/formats/psd/psd_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class PsdImage implements DecodeInfo {
final imageResources = <int, PsdImageResource>{};
bool hasAlpha = false;

static const resourceBlockSignature = 0x3842494d; // '8BIM'

late InputBuffer? _input;

//InputBuffer? _colorData;
InputBuffer? _imageResourceData;
InputBuffer? _layerAndMaskData;
InputBuffer? _imageData;

@override
Color? get backgroundColor => null;

Expand All @@ -53,14 +62,13 @@ class PsdImage implements DecodeInfo {
}

var len = _input!.readUint32();
/*_colorData =*/
_input!.readBytes(len);
/*_colorData =*/ _input!.readBytes(len);

len = _input!.readUint32();
/*_imageResourceData =*/ _input!.readBytes(len);
_imageResourceData = _input!.readBytes(len);

len = _input!.readUint32();
/*_layerAndMaskData =*/ _input!.readBytes(len);
_layerAndMaskData = _input!.readBytes(len);

_imageData = _input!.readBytes(_input!.length);
}
Expand All @@ -85,16 +93,16 @@ class PsdImage implements DecodeInfo {
// Image Resource Block:
// Image resources are used to store non-pixel data associated with images,
// such as pen tool paths.
//_readImageResources();
_readImageResources();

//_readLayerAndMaskData();
_readLayerAndMaskData();

_readMergeImageData();

_input = null;
//_colorData = null;
//_imageResourceData = null;
//_layerAndMaskData = null;
_imageResourceData = null;
_layerAndMaskData = null;
_imageData = null;

return true;
Expand Down Expand Up @@ -135,7 +143,7 @@ class PsdImage implements DecodeInfo {
//var di = (layer.top! + y) * width * 4 + layer.left! * 4;
final dy = layer.top! + y;
for (int? x = 0, sx = layer.left; x! < layer.width; ++x, ++sx) {
final srcP = src.getPixel(x, y);
final srcP = src!.getPixel(x, y);
final br = srcP.r.toInt();
final bg = srcP.g.toInt();
final bb = srcP.b.toInt();
Expand Down Expand Up @@ -408,7 +416,7 @@ class PsdImage implements DecodeInfo {
// TODO support indexed and duotone images.
}

/*void _readImageResources() {
void _readImageResources() {
_imageResourceData!.rewind();
while (!_imageResourceData!.isEOS) {
final blockSignature = _imageResourceData!.readUint32();
Expand All @@ -433,9 +441,9 @@ class PsdImage implements DecodeInfo {
PsdImageResource(blockId, blockName, blockData);
}
}
}*/
}

/*void _readLayerAndMaskData() {
void _readLayerAndMaskData() {
_layerAndMaskData!.rewind();
var len = _layerAndMaskData!.readUint32();
if ((len & 1) != 0) {
Expand Down Expand Up @@ -484,7 +492,7 @@ class PsdImage implements DecodeInfo {
/*int kind =*/
..readByte();
}
}*/
}

void _readMergeImageData() {
_imageData!.rewind();
Expand All @@ -509,8 +517,11 @@ class PsdImage implements DecodeInfo {
colorMode, depth, width, height, mergeImageChannels);
}

static int _ch(List<int> data, int si, int ns) =>
ns == 1 ? data[si] : ((data[si] << 8) | data[si + 1]) >> 8;
static int _ch(List<int>? data, int si, int ns) => data == null
? 0
: ns == 1
? data[si]
: ((data[si] << 8) | data[si + 1]) >> 8;

static Image createImageFromChannels(PsdColorMode? colorMode, int? bitDepth,
int width, int height, List<PsdChannel> channelList) {
Expand Down Expand Up @@ -596,13 +607,4 @@ class PsdImage implements DecodeInfo {

return output;
}

static const resourceBlockSignature = 0x3842494d; // '8BIM'

late InputBuffer? _input;

//InputBuffer _colorData;
//late InputBuffer? _imageResourceData;
//late InputBuffer? _layerAndMaskData;
late InputBuffer? _imageData;
}
2 changes: 1 addition & 1 deletion lib/src/formats/psd/psd_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PsdLayer {
Map<String, PsdLayerData> additionalData = {};
List<PsdLayer> children = [];
PsdLayer? parent;
late Image layerImage;
Image? layerImage;
List<PsdEffect> effects = [];

static const signature = 0x3842494d; // '8BIM'
Expand Down
3 changes: 3 additions & 0 deletions lib/src/formats/tiff/tiff_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ class TiffImage {

for (var y = 0, py = outY; y < tileHeight; ++y, ++py) {
for (var x = 0, px = outX; x < tileWidth; ++x, ++px) {
if (byteData.isEOS) {
break;
}
if (samplesPerPixel == 1) {
if (sampleFormat == TiffFormat.float) {
num sample = 0;
Expand Down
6 changes: 4 additions & 2 deletions lib/src/image/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ class Image extends Iterable<Pixel> {
numChannels ??= this.numChannels;
alpha ??= formatMaxValue[format];

if (withPalette &&
// Commented out because it causes problems converting a uint8 w/ palette
// to a uint1 w/ palette
/*if (withPalette &&
(numChannels >= 4 ||
!(format == Format.uint1 ||
format == Format.uint2 ||
Expand All @@ -841,7 +843,7 @@ class Image extends Iterable<Pixel> {
(format.index < Format.uint8.index &&
this.format.index >= Format.uint8.index)) {
withPalette = false;
}
}*/

if (format == this.format &&
numChannels == this.numChannels &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transform/copy_crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Image copyCrop(Image src,
final c4x = x1 + rad - 1;
final c4y = y2 - rad + 1;

final iter = src.getRange(x1, y1, width, height);
final iter = frame.getRange(x1, y1, width, height);
while (iter.moveNext()) {
final p = iter.current;
final px = p.x;
Expand Down
1 change: 0 additions & 1 deletion lib/src/util/_internal.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// Annotates a function or class that's for internal use within the image
/// library and is not to be exported as part of the main API.
const internal = _Internal();

class _Internal {
Expand Down
1 change: 0 additions & 1 deletion lib/src/util/clip_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/// Results are stored in [line].
/// If [line] falls completely outside of [rect], false is returned, otherwise
/// true is returned.
bool clipLine(List<int> line, List<int> rect) {
var x0 = line[0];
var y0 = line[1];
Expand Down
Loading

0 comments on commit a214097

Please sign in to comment.