Skip to content

Commit

Permalink
Run dartfmt to clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed Sep 14, 2020
1 parent 80bdf1c commit 7bdf302
Show file tree
Hide file tree
Showing 32 changed files with 205 additions and 113 deletions.
2 changes: 1 addition & 1 deletion lib/src/bitmap_font.dart
Expand Up @@ -280,7 +280,7 @@ class BitmapFont {

var lines = <String>[];
lines = content.split('\r\n');
if(lines.length <= 1) {
if (lines.length <= 1) {
lines = content.split('\n');
}

Expand Down
8 changes: 6 additions & 2 deletions lib/src/color.dart
Expand Up @@ -100,7 +100,9 @@ int getChannel(int color, Channel channel) => channel == Channel.red
? getGreen(color)
: channel == Channel.blue
? getBlue(color)
: channel == Channel.alpha ? getAlpha(color) : getLuminance(color);
: channel == Channel.alpha
? getAlpha(color)
: getLuminance(color);

/// Returns a new color, where the given [color]'s [channel] has been
/// replaced with the given [value].
Expand All @@ -110,7 +112,9 @@ int setChannel(int color, Channel channel, int value) => channel == Channel.red
? setGreen(color, value)
: channel == Channel.blue
? setBlue(color, value)
: channel == Channel.alpha ? setAlpha(color, value) : color;
: channel == Channel.alpha
? setAlpha(color, value)
: color;

/// Get the red channel from the [color].
int getRed(int color) => (color) & 0xff;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/draw/draw_string.dart
Expand Up @@ -63,7 +63,7 @@ Image drawString(Image image, BitmapFont font, int x, int y, String string,
}

/// Draw a string horizontally into [image] at position
/// [x],[y] with the given [color].
/// [x],[y] with the given [color].
/// If x is omitted text is automatically centered into [image]
/// If y is omitted text is automatically centered into [image].
/// If both x and y are provided it has the same behaviour of drawString method.
Expand All @@ -83,19 +83,19 @@ Image drawStringCentered(Image image, BitmapFont font, String string,
}
var ch = font.characters[c];
stringWidth += ch.xadvance;
if(ch.height + ch.yoffset > stringHeight) {
if (ch.height + ch.yoffset > stringHeight) {
stringHeight = ch.height + ch.yoffset;
}
}
}

int xPos, yPos;
if(x == null) {
if (x == null) {
xPos = (image.width / 2).round() - (stringWidth / 2).round();
} else {
xPos = x;
}
if(y == null) {
if (y == null) {
yPos = (image.height / 2).round() - (stringHeight / 2).round();
} else {
yPos = y;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/draw/fill_flood.dart
Expand Up @@ -63,8 +63,7 @@ Uint8List maskFlood(Image src, int x, int y,

_TestPixel array;
if (threshold > 0) {
var lab =
rgbToLab(getRed(srcColor), getGreen(srcColor), getBlue(srcColor));
var lab = rgbToLab(getRed(srcColor), getGreen(srcColor), getBlue(srcColor));

if (compareAlpha) {
lab.add(getAlpha(srcColor).toDouble());
Expand Down
19 changes: 7 additions & 12 deletions lib/src/formats/exr/exr_compressor.dart
Expand Up @@ -29,23 +29,18 @@ abstract class ExrCompressor {
case RLE_COMPRESSION:
return ExrRleCompressor(hdr, maxScanLineSize);
case ZIPS_COMPRESSION:
return ExrZipCompressor(
hdr, maxScanLineSize, numScanLines ?? 1);
return ExrZipCompressor(hdr, maxScanLineSize, numScanLines ?? 1);
case ZIP_COMPRESSION:
return ExrZipCompressor(
hdr, maxScanLineSize, numScanLines ?? 16);
return ExrZipCompressor(hdr, maxScanLineSize, numScanLines ?? 16);
case PIZ_COMPRESSION:
return ExrPizCompressor(
hdr, maxScanLineSize, numScanLines ?? 32);
return ExrPizCompressor(hdr, maxScanLineSize, numScanLines ?? 32);
case PXR24_COMPRESSION:
return ExrPxr24Compressor(
hdr, maxScanLineSize, numScanLines ?? 16);
return ExrPxr24Compressor(hdr, maxScanLineSize, numScanLines ?? 16);
case B44_COMPRESSION:
return ExrB44Compressor(hdr, maxScanLineSize,
numScanLines ?? 32, false);
return ExrB44Compressor(
hdr, maxScanLineSize, numScanLines ?? 32, false);
case B44A_COMPRESSION:
return ExrB44Compressor(hdr, maxScanLineSize,
numScanLines ?? 32, true);
return ExrB44Compressor(hdr, maxScanLineSize, numScanLines ?? 32, true);
default:
throw ImageException('Invalid compression type: $type');
}
Expand Down
6 changes: 2 additions & 4 deletions lib/src/formats/exr/exr_huffman.dart
Expand Up @@ -59,8 +59,7 @@ class ExrHuffman {

// Access decoding table
while (c_lc[1] >= HUF_DECBITS) {
var pl =
hdecod[(c_lc[0] >> (c_lc[1] - HUF_DECBITS)) & HUF_DECMASK];
var pl = hdecod[(c_lc[0] >> (c_lc[1] - HUF_DECBITS)) & HUF_DECMASK];

if (pl.len != 0) {
// Get short code
Expand Down Expand Up @@ -334,8 +333,7 @@ class ExrHuffman {

static const SHORT_ZEROCODE_RUN = 59;
static const LONG_ZEROCODE_RUN = 63;
static const SHORTEST_LONG_RUN =
2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN;
static const SHORTEST_LONG_RUN = 2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN;
static const LONGEST_LONG_RUN = 255 + SHORTEST_LONG_RUN;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/formats/exr/exr_piz_compressor.dart
Expand Up @@ -19,8 +19,8 @@ abstract class ExrPizCompressor extends ExrCompressor {
@internal
class InternalExrPizCompressor extends InternalExrCompressor
implements ExrPizCompressor {
InternalExrPizCompressor(ExrPart header, this._maxScanLineSize,
this._numScanLines)
InternalExrPizCompressor(
ExrPart header, this._maxScanLineSize, this._numScanLines)
: super(header as InternalExrPart) {
_channelData = List<_PizChannelData>(header.channels.length);
for (var i = 0; i < _channelData.length; ++i) {
Expand Down Expand Up @@ -114,8 +114,8 @@ class InternalExrPizCompressor extends InternalExrCompressor
// Expand the pixel data to their original range
_applyLut(lut, _tmpBuffer, tmpBufferEnd);

_output ??= OutputBuffer(
size: (_maxScanLineSize * _numScanLines) + (65536 + 8192));
_output ??=
OutputBuffer(size: (_maxScanLineSize * _numScanLines) + (65536 + 8192));

_output.rewind();

Expand Down
18 changes: 9 additions & 9 deletions lib/src/formats/ico_decoder.dart
Expand Up @@ -182,15 +182,15 @@ class IcoInfo extends DecodeInfo {
}

class IcoInfoImage {
IcoInfoImage({
@required this.width,
@required this.height,
@required this.colorPalette,
@required this.bytesSize,
@required this.bytesOffset,
@required this.colorPlanes,
@required this.bitsPerPixel
}) : assert(width != null),
IcoInfoImage(
{@required this.width,
@required this.height,
@required this.colorPalette,
@required this.bytesSize,
@required this.bytesOffset,
@required this.colorPlanes,
@required this.bitsPerPixel})
: assert(width != null),
assert(height != null),
assert(colorPalette != null),
assert(bytesSize != null),
Expand Down
11 changes: 8 additions & 3 deletions lib/src/formats/jpeg/_jpeg_quantize_html.dart
Expand Up @@ -8,7 +8,11 @@ import '_component_data.dart';
import 'jpeg_data.dart';

Uint8List _dctClip;
int _clamp8(int i) => i < 0 ? 0 : i > 255 ? 255 : i;
int _clamp8(int i) => i < 0
? 0
: i > 255
? 255
: i;

// These functions contain bit-shift operations that fail with HTML builds.
// A conditional import is used to use a modified version for HTML builds
Expand Down Expand Up @@ -376,8 +380,9 @@ Image getImageFromJpeg(JpegData jpeg) {
K = component4Line[x4];

C = 255 - _clamp8((Y + 1.402 * (Cr - 128)).toInt());
M = 255 - _clamp8((Y - 0.3441363 * (Cb - 128) -
0.71413636 * (Cr - 128)).toInt());
M = 255 -
_clamp8((Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128))
.toInt());
Ye = 255 - _clamp8((Y + 1.772 * (Cb - 128)).toInt());
}
R = shiftR((C * K), 8);
Expand Down
11 changes: 8 additions & 3 deletions lib/src/formats/jpeg/_jpeg_quantize_io.dart
Expand Up @@ -7,7 +7,11 @@ import '_component_data.dart';
import 'jpeg_data.dart';

Uint8List _dctClip;
int _clamp8(int i) => i < 0 ? 0 : i > 255 ? 255 : i;
int _clamp8(int i) => i < 0
? 0
: i > 255
? 255
: i;

// Quantize the coefficients and apply IDCT.
//
Expand Down Expand Up @@ -370,8 +374,9 @@ Image getImageFromJpeg(JpegData jpeg) {
K = component4Line[x4];

C = 255 - _clamp8((Y + 1.402 * (Cr - 128)).toInt());
M = 255 - _clamp8((Y - 0.3441363 * (Cb - 128) -
0.71413636 * (Cr - 128)).toInt());
M = 255 -
_clamp8((Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128))
.toInt());
Ye = 255 - _clamp8((Y + 1.772 * (Cb - 128)).toInt());
}
R = (C * K) >> 8;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/formats/jpeg/jpeg.dart
Expand Up @@ -16,8 +16,7 @@ class Jpeg {
static const DCTSIZE2 = 64; // DCTSIZE squared; # of elements in a block
static const NUM_QUANT_TBLS = 4; // Quantization tables are numbered 0..3
static const NUM_HUFF_TBLS = 4; // Huffman tables are numbered 0..3
static const NUM_ARITH_TBLS =
16; // Arith-coding tables are numbered 0..15
static const NUM_ARITH_TBLS = 16; // Arith-coding tables are numbered 0..15
static const MAX_COMPS_IN_SCAN =
4; // JPEG limit on # of components in one scan
static const MAX_SAMP_FACTOR = 4; // JPEG limit on sampling factors
Expand Down
4 changes: 2 additions & 2 deletions lib/src/formats/jpeg/jpeg_data.dart
Expand Up @@ -50,7 +50,7 @@ class JpegData {
break;
}
input.offset += sectionByteSize - 2;

switch (marker) {
case Jpeg.M_SOF0: // SOF0 (Start of Frame, Baseline DCT)
case Jpeg.M_SOF1: // SOF1 (Start of Frame, Extended DCT)
Expand Down Expand Up @@ -319,7 +319,7 @@ class JpegData {
return block.readInt16();
case FMT_SLONG:
return block.readInt32();
// Not sure if this is correct (never seen float used in Exif format)
// Not sure if this is correct (never seen float used in Exif format)
case FMT_SINGLE:
return block.readFloat32();
case FMT_DOUBLE:
Expand Down
12 changes: 9 additions & 3 deletions lib/src/formats/jpeg_encoder.dart
Expand Up @@ -92,15 +92,21 @@ class JpegEncoder extends Encoder {
// calculate YUV values
YDU[pos] = ((RGB_YUV_TABLE[r] +
RGB_YUV_TABLE[(g + 256)] +
RGB_YUV_TABLE[(b + 512)]) >> 16) - 128.0;
RGB_YUV_TABLE[(b + 512)]) >>
16) -
128.0;

UDU[pos] = ((RGB_YUV_TABLE[(r + 768)] +
RGB_YUV_TABLE[(g + 1024)] +
RGB_YUV_TABLE[(b + 1280)]) >> 16) - 128.0;
RGB_YUV_TABLE[(b + 1280)]) >>
16) -
128.0;

VDU[pos] = ((RGB_YUV_TABLE[(r + 1280)] +
RGB_YUV_TABLE[(g + 1536)] +
RGB_YUV_TABLE[(b + 1792)]) >> 16) - 128.0;
RGB_YUV_TABLE[(b + 1792)]) >>
16) -
128.0;
}

DCY = _processDU(fp, YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
Expand Down
18 changes: 15 additions & 3 deletions lib/src/formats/png_decoder.dart
Expand Up @@ -402,7 +402,11 @@ class PngDecoder extends Decoder {
int xStep, int yStep, int passWidth, int passHeight) {
final channels = (_info.colorType == GRAYSCALE_ALPHA)
? 2
: (_info.colorType == RGB) ? 3 : (_info.colorType == RGBA) ? 4 : 1;
: (_info.colorType == RGB)
? 3
: (_info.colorType == RGBA)
? 4
: 1;

final pixelDepth = channels * _info.bits;
final bpp = (pixelDepth + 7) >> 3;
Expand Down Expand Up @@ -461,7 +465,11 @@ class PngDecoder extends Decoder {
void _process(InputBuffer input, Image image) {
final channels = (_info.colorType == GRAYSCALE_ALPHA)
? 2
: (_info.colorType == RGB) ? 3 : (_info.colorType == RGBA) ? 4 : 1;
: (_info.colorType == RGB)
? 3
: (_info.colorType == RGBA)
? 4
: 1;

final pixelDepth = channels * _info.bits;

Expand Down Expand Up @@ -617,7 +625,11 @@ class PngDecoder extends Decoder {
? 3
: (numBits == 4)
? 0xf
: (numBits == 8) ? 0xff : (numBits == 16) ? 0xffff : 0;
: (numBits == 8)
? 0xff
: (numBits == 16)
? 0xffff
: 0;

var octet = (_bitBuffer >> (_bitBufferLen - numBits)) & mask;

Expand Down
6 changes: 5 additions & 1 deletion lib/src/formats/psd/psd_image.dart
Expand Up @@ -523,7 +523,11 @@ class PsdImage extends DecodeInfo {
}

var numChannels = channelList.length;
var ns = (bitDepth == 8) ? 1 : (bitDepth == 16) ? 2 : -1;
var ns = (bitDepth == 8)
? 1
: (bitDepth == 16)
? 2
: -1;
if (ns == -1) {
throw ImageException('PSD: unsupported bit depth: $bitDepth');
}
Expand Down

0 comments on commit 7bdf302

Please sign in to comment.