diff --git a/examples/blur.nim b/examples/blur.nim index aa34a4f..ff6d364 100644 --- a/examples/blur.nim +++ b/examples/blur.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath +import chroma, pixie, vmath let trees = readImage("examples/data/trees.png") @@ -8,7 +8,7 @@ let image.fill(rgba(255, 255, 255, 255)) var p: Path -p.polygon(100, 100, 70, sides=6) +p.polygon(100, 100, 70, sides = 6) p.closePath() let mask = newMask(200, 200) diff --git a/examples/heart.nim b/examples/heart.nim index 6397cee..79251c1 100644 --- a/examples/heart.nim +++ b/examples/heart.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath +import chroma, pixie, vmath let image = newImage(200, 200) diff --git a/examples/rounded_rectangle.nim b/examples/rounded_rectangle.nim index 63bb3cb..598ea92 100644 --- a/examples/rounded_rectangle.nim +++ b/examples/rounded_rectangle.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath +import chroma, pixie, vmath let image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) diff --git a/examples/shadow.nim b/examples/shadow.nim index db78970..8922f79 100644 --- a/examples/shadow.nim +++ b/examples/shadow.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath +import chroma, pixie, vmath let trees = readImage("examples/data/trees.png") @@ -7,7 +7,7 @@ let image.fill(rgba(255, 255, 255, 255)) var p: Path -p.polygon(100, 100, 70, sides=8) +p.polygon(100, 100, 70, sides = 8) p.closePath() var polyImage = newImage(200, 200) diff --git a/examples/square.nim b/examples/square.nim index 528d3ab..43f2fe5 100644 --- a/examples/square.nim +++ b/examples/square.nim @@ -1,4 +1,4 @@ -import pixie, chroma +import chroma, pixie var image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) diff --git a/examples/tiger.nim b/examples/tiger.nim index 00f741e..1d0e3a4 100644 --- a/examples/tiger.nim +++ b/examples/tiger.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath +import chroma, pixie, vmath let image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) diff --git a/experiments/benchmark_cairo.nim b/experiments/benchmark_cairo.nim index b9b6cfe..062f2ba 100644 --- a/experiments/benchmark_cairo.nim +++ b/experiments/benchmark_cairo.nim @@ -1,4 +1,4 @@ -import cairo, math, benchy, pixie, chroma +import benchy, cairo, chroma, math, pixie var surface = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000) diff --git a/experiments/benchmark_svg_cairo.nim b/experiments/benchmark_svg_cairo.nim index 51ebf16..f8feb05 100644 --- a/experiments/benchmark_svg_cairo.nim +++ b/experiments/benchmark_svg_cairo.nim @@ -1,4 +1,4 @@ -import svg_cairo, benchy +import benchy, svg_cairo let data = readFile("tests/images/svg/Ghostscript_Tiger.svg") diff --git a/experiments/svg_cairo.nim b/experiments/svg_cairo.nim index db910aa..e0b9900 100644 --- a/experiments/svg_cairo.nim +++ b/experiments/svg_cairo.nim @@ -1,7 +1,7 @@ ## Load and Save SVG files. -import chroma, pixie/images, pixie/common, pixie/paths, vmath, xmlparser, - xmltree, strutils, strutils, cairo +import cairo, chroma, pixie/common, pixie/images, pixie/paths, strutils, vmath, + xmlparser, xmltree type Path = paths.Path diff --git a/experiments/test_svg_cairo.nim b/experiments/test_svg_cairo.nim index 20efe86..5e54f94 100644 --- a/experiments/test_svg_cairo.nim +++ b/experiments/test_svg_cairo.nim @@ -1,4 +1,4 @@ -import svg_cairo, pixie, strformat +import pixie, strformat, svg_cairo const files = [ "line01", diff --git a/experiments/trapezoid.nim b/experiments/trapezoid.nim index e9146de..e99b589 100644 --- a/experiments/trapezoid.nim +++ b/experiments/trapezoid.nim @@ -1,10 +1,9 @@ - -import pixie, pixie/paths, pixie/images, chroma, print, vmath, algorithm, sequtils, bumpy +import algorithm, bumpy, chroma, pixie, pixie/images, pixie/paths, print, + sequtils, vmath printColors = false - proc intersectsInner*(a, b: Segment, at: var Vec2): bool {.inline.} = ## Checks if the a segment intersects b segment. ## If it returns true, at will have point of intersection @@ -73,7 +72,7 @@ proc pathToTrapezoids(p: Path): seq[Trapezoid] = var collision = false for y in yScanLines: var at: Vec2 - if intersects(line(vec2(0,y), vec2(1,y)), s, at): + if intersects(line(vec2(0, y), vec2(1, y)), s, at): at = at.roundBy(q) at.y = y if s.at.y != at.y and s.to.y != at.y: @@ -136,9 +135,9 @@ proc pathToTrapezoids(p: Path): seq[Trapezoid] = Trapezoid( nw: a.at, ne: b.at, - se: b.to,# + vec2(0,0.7), - sw: a.to# + vec2(0,0.7) - ) + se: b.to, # + vec2(0,0.7), + sw: a.to # + vec2(0,0.7) + ) ) proc trapFill(image: Image, t: Trapezoid, color: ColorRGBA) = diff --git a/src/pixie.nim b/src/pixie.nim index 889f583..38ad7d7 100644 --- a/src/pixie.nim +++ b/src/pixie.nim @@ -1,8 +1,8 @@ -import pixie/images, pixie/masks, pixie/paths, pixie/common, pixie/blends, - pixie/fileformats/bmp, pixie/fileformats/png, pixie/fileformats/jpg, - pixie/fileformats/svg, flatty/binny, os, pixie/gradients +import flatty/binny, os, pixie/blends, pixie/common, pixie/fileformats/bmp, + pixie/fileformats/jpg, pixie/fileformats/png, pixie/fileformats/svg, + pixie/images, pixie/masks, pixie/paths -export images, masks, paths, common, blends, gradients +export blends, common, images, masks, paths type FileFormat* = enum diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index b992f6b..7c401fb 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -1,5 +1,6 @@ ## Blending modes. -import chroma, math, common + +import chroma, common, math when defined(amd64) and not defined(pixieNoSimd): import nimsimd/sse2 @@ -28,8 +29,8 @@ type bmColor bmLuminosity - bmMask ## Special blend mode that is used for masking - bmOverwrite ## Special blend mode that just copies pixels + bmMask ## Special blend mode that is used for masking + bmOverwrite ## Special blend mode that just copies pixels bmSubtractMask ## Inverse mask bmIntersectMask bmExcludeMask @@ -141,9 +142,9 @@ proc ClipColor(C: var Color) {.inline.} = n = min([C.r, C.g, C.b]) x = max([C.r, C.g, C.b]) if n < 0: - C = L + (((C - L) * L) / (L - n)) + C = L + (((C - L) * L) / (L - n)) if x > 1: - C = L + (((C - L) * (1 - L)) / (x - L)) + C = L + (((C - L) * (1 - L)) / (x - L)) proc SetLum(C: Color, l: float32): Color {.inline.} = let d = l - Lum(C) @@ -297,7 +298,12 @@ proc blendSoftLight(backdrop, source: ColorRGBA): ColorRGBA = when defined(amd64) and not defined(pixieNoSimd): let - vb = mm_setr_ps(backdrop.r.float32, backdrop.g.float32, backdrop.b.float32, 0) + vb = mm_setr_ps( + backdrop.r.float32, + backdrop.g.float32, + backdrop.b.float32, + 0 + ) vs = mm_setr_ps(source.r.float32, source.g.float32, source.b.float32, 0) v2 = mm_set1_ps(2) v255 = mm_set1_ps(255) @@ -519,8 +525,8 @@ when defined(amd64) and not defined(pixieNoSimd): proc unpackAlphaValues*(v: M128i): M128i {.inline.} = ## Unpack the first 32 bits into 4 rgba(0, 0, 0, value) let - first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits - alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a` + first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits + alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a` result = mm_shuffle_epi32(v, MM_SHUFFLE(0, 0, 0, 0)) diff --git a/src/pixie/fileformats/bmp.nim b/src/pixie/fileformats/bmp.nim index d705bd0..5be8d1f 100644 --- a/src/pixie/fileformats/bmp.nim +++ b/src/pixie/fileformats/bmp.nim @@ -1,4 +1,4 @@ -import flatty/binny, chroma, pixie/common, pixie/images +import chroma, flatty/binny, pixie/common, pixie/images # See: https://en.wikipedia.org/wiki/BMP_file_format diff --git a/src/pixie/fileformats/jpg.nim b/src/pixie/fileformats/jpg.nim index 9070ae5..9cd1b37 100644 --- a/src/pixie/fileformats/jpg.nim +++ b/src/pixie/fileformats/jpg.nim @@ -1,4 +1,4 @@ -import pixie/images, pixie/common +import pixie/common, pixie/images when defined(pixieUseStb): import pixie/fileformats/stb_image/stb_image diff --git a/src/pixie/fileformats/png.nim b/src/pixie/fileformats/png.nim index c98ce41..0f2d9d3 100644 --- a/src/pixie/fileformats/png.nim +++ b/src/pixie/fileformats/png.nim @@ -1,5 +1,5 @@ -import chroma, pixie/common, math, zippy, zippy/crc, flatty/binny, - pixie/images, pixie/masks +import chroma, flatty/binny, math, pixie/common, pixie/images, pixie/masks, + zippy, zippy/crc # See http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 45bdf98..ef66800 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -1,7 +1,7 @@ ## Load and Save SVG files. -import chroma, pixie/images, pixie/common, pixie/paths, vmath, xmlparser, - xmltree, strutils, strutils +import chroma, pixie/common, pixie/images, pixie/paths, strutils, vmath, + xmlparser, xmltree const svgSignature* = "= scanline.a.y: var at: Vec2 - if scanline.intersects(segment, at):# and segment.to != at: + if scanline.intersects(segment, at): # and segment.to != at: if numHits == hits.len: hits.setLen(hits.len * 2) hits[numHits] = (at.x.clamp(0, scanline.b.x), winding) @@ -1153,6 +1153,7 @@ proc fillShapes( if peeked == 0: x += 8 continue + let coverage = coverages[x] if coverage != 0: let diff --git a/tests/benchmark_blends.nim b/tests/benchmark_blends.nim index b82c87a..a1e25fc 100644 --- a/tests/benchmark_blends.nim +++ b/tests/benchmark_blends.nim @@ -1,4 +1,4 @@ -import benchy, chroma, vmath, pixie/images +import benchy, chroma, pixie/images, vmath include pixie/blends diff --git a/tests/benchmark_drawCorrect_vs_drawUber.nim b/tests/benchmark_drawCorrect_vs_drawUber.nim index 5b16cc3..b8108c8 100644 --- a/tests/benchmark_drawCorrect_vs_drawUber.nim +++ b/tests/benchmark_drawCorrect_vs_drawUber.nim @@ -1,4 +1,5 @@ -import chroma, vmath, benchy +import benchy, chroma, vmath + include pixie/images block: @@ -23,7 +24,6 @@ block: a.drawUber(b, translate(vec2(25, 25)), bmNormal) keep(b) - block: let a = newImage(1000, 1000) diff --git a/tests/benchmark_images.nim b/tests/benchmark_images.nim index 7ace876..8112f1b 100644 --- a/tests/benchmark_images.nim +++ b/tests/benchmark_images.nim @@ -1,4 +1,4 @@ -import chroma, pixie, benchy +import benchy, chroma, pixie let image = newImage(2560, 1440) diff --git a/tests/benchmark_images_draw.nim b/tests/benchmark_images_draw.nim index 53ff723..3d34544 100644 --- a/tests/benchmark_images_draw.nim +++ b/tests/benchmark_images_draw.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath, benchy +import benchy, chroma, pixie, vmath block: let diff --git a/tests/benchmark_jpg.nim b/tests/benchmark_jpg.nim index 0b9524e..6420e2a 100644 --- a/tests/benchmark_jpg.nim +++ b/tests/benchmark_jpg.nim @@ -1,4 +1,4 @@ -import pixie/fileformats/jpg, benchy +import benchy, pixie/fileformats/jpg let data = readFile("tests/images/jpg/jpeg420exif.jpg") diff --git a/tests/benchmark_masks.nim b/tests/benchmark_masks.nim index 2c04b3d..f92e8d9 100644 --- a/tests/benchmark_masks.nim +++ b/tests/benchmark_masks.nim @@ -1,4 +1,4 @@ -import chroma, pixie, benchy +import benchy, chroma, pixie let mask = newMask(2560, 1440) diff --git a/tests/benchmark_paths.nim b/tests/benchmark_paths.nim index 18fc471..7f483e3 100644 --- a/tests/benchmark_paths.nim +++ b/tests/benchmark_paths.nim @@ -1,4 +1,4 @@ -import pixie/paths, benchy +import benchy, pixie/paths let pathStr = "m57.611-8.591c-1.487,1.851-4.899,4.42-1.982,6.348,0.194,0.129,0.564,0.133,0.737-0.001,2.021-1.565,4.024-2.468,6.46-3.05,0.124-0.029,0.398,0.438,0.767,0.277,1.613-0.703,3.623-0.645,4.807-1.983,3.767,0.224,7.332-0.892,10.723-2.2,1.161-0.448,2.431-1.007,3.632-1.509,1.376-0.576,2.58-1.504,3.692-2.645,0.133-0.136,0.487-0.046,0.754-0.046-0.04-0.863,0.922-0.99,1.169-1.612,0.092-0.232-0.058-0.628,0.075-0.73,2.138-1.63,3.058-3.648,1.889-6.025-0.285-0.578-0.534-1.196-1.1-1.672-1.085-0.911-2.187-0.057-3.234-0.361-0.159,0.628-0.888,0.456-1.274,0.654-0.859,0.439-2.192-0.146-3.051,0.292-1.362,0.695-2.603,0.864-4.025,1.241-0.312,0.082-1.09-0.014-1.25,0.613-0.134-0.134-0.282-0.368-0.388-0.346-1.908,0.396-3.168,0.61-4.469,2.302-0.103,0.133-0.545-0.046-0.704,0.089-0.957,0.808-1.362,2.042-2.463,2.714-0.201,0.123-0.553-0.045-0.747,0.084-0.646,0.431-1.013,1.072-1.655,1.519-0.329,0.229-0.729-0.096-0.697-0.352,0.245-1.947,0.898-3.734,0.323-5.61,2.077-2.52,4.594-4.469,6.4-7.2,0.015-2.166,0.707-4.312,0.594-6.389-0.01-0.193-0.298-0.926-0.424-1.273-0.312-0.854,0.594-1.92-0.25-2.644-1.404-1.203-2.696-0.327-3.52,1.106-1.838,0.39-3.904,1.083-5.482-0.151-1.007-0.787-1.585-1.693-2.384-2.749-0.985-1.302-0.65-2.738-0.58-4.302,0.006-0.128-0.309-0.264-0.309-0.398,0.001-0.135,0.221-0.266,0.355-0.4-0.706-0.626-0.981-1.684-2-2,0.305-1.092-0.371-1.976-1.242-2.278-1.995-0.691-3.672,1.221-5.564,1.294-0.514,0.019-0.981-1.019-1.63-1.344-0.432-0.216-1.136-0.249-1.498,0.017-0.688,0.504-1.277,0.618-2.035,0.823-1.617,0.436-2.895,1.53-4.375,2.385-1.485,0.857-2.44,2.294-3.52,3.614-0.941,1.152-1.077,3.566,0.343,4.066,1.843,0.65,3.147-2.053,5.113-1.727,0.312,0.051,0.518,0.362,0.408,0.75,0.389,0.109,0.607-0.12,0.8-0.4,0.858,1.019,2.022,1.356,2.96,2.229,0.97,0.904,2.716,0.486,3.731,1.483,1.529,1.502,0.97,4.183,2.909,5.488-0.586,1.313-1.193,2.59-1.528,4.017-0.282,1.206,0.712,2.403,1.923,2.312,1.258-0.094,1.52-0.853,2.005-1.929,0.267,0.267,0.736,0.564,0.695,0.78-0.457,2.387-1.484,4.38-1.942,6.811-0.059,0.317-0.364,0.519-0.753,0.409-0.468,4.149-4.52,6.543-7.065,9.708-0.403,0.502-0.407,1.751,0.002,2.154,1.403,1.387,3.363-0.159,5.063-0.662,0.213-1.206,1.072-2.148,2.404-2.092,0.256,0.01,0.491-0.532,0.815-0.662,0.348-0.138,0.85,0.086,1.136-0.112,1.729-1.195,3.137-2.301,4.875-3.49,0.192-0.131,0.536,0.028,0.752-0.08,0.325-0.162,0.512-0.549,0.835-0.734,0.348-0.2,0.59,0.09,0.783,0.37-0.646,0.349-0.65,1.306-1.232,1.508-0.775,0.268-1.336,0.781-2.01,1.228-0.292,0.193-0.951-0.055-1.055,0.124-0.598,1.028-1.782,1.466-2.492,2.349z" diff --git a/tests/benchmark_png.nim b/tests/benchmark_png.nim index d2e0aa9..eb0b120 100644 --- a/tests/benchmark_png.nim +++ b/tests/benchmark_png.nim @@ -1,5 +1,5 @@ -import pixie/fileformats/png, stb_image/read as stbi, stb_image/write as stbr, - benchy, nimPNG +import benchy, nimPNG, pixie/fileformats/png, stb_image/read as stbi, + stb_image/write as stbr let data = readFile("tests/images/png/lenna.png") diff --git a/tests/benchmark_svg.nim b/tests/benchmark_svg.nim index cf6cf74..e36e3a6 100644 --- a/tests/benchmark_svg.nim +++ b/tests/benchmark_svg.nim @@ -1,4 +1,4 @@ -import pixie/fileformats/svg, benchy +import benchy, pixie/fileformats/svg let data = readFile("tests/images/svg/Ghostscript_Tiger.svg") diff --git a/tests/fuzz_jpg.nim b/tests/fuzz_jpg.nim index 015f97e..ea366e7 100644 --- a/tests/fuzz_jpg.nim +++ b/tests/fuzz_jpg.nim @@ -1,4 +1,4 @@ -import random, strformat, pixie/fileformats/jpg, pixie/common +import pixie/common, pixie/fileformats/jpg, random, strformat randomize() diff --git a/tests/fuzz_paths.nim b/tests/fuzz_paths.nim index a296670..8237878 100644 --- a/tests/fuzz_paths.nim +++ b/tests/fuzz_paths.nim @@ -1,4 +1,4 @@ -import random, strformat, pixie/paths, pixie/common, strformat +import pixie/common, pixie/paths, random, strformat randomize() diff --git a/tests/fuzz_png.nim b/tests/fuzz_png.nim index 89fb4a8..631d376 100644 --- a/tests/fuzz_png.nim +++ b/tests/fuzz_png.nim @@ -1,4 +1,4 @@ -import random, strformat, pixie/fileformats/png, pixie/common, pngsuite +import pixie/common, pixie/fileformats/png, pngsuite, random, strformat randomize() diff --git a/tests/fuzz_svg.nim b/tests/fuzz_svg.nim index faaf4ab..7356a18 100644 --- a/tests/fuzz_svg.nim +++ b/tests/fuzz_svg.nim @@ -1,4 +1,4 @@ -import random, strformat, pixie/fileformats/svg, pixie/common +import pixie/common, pixie/fileformats/svg, random, strformat randomize() diff --git a/tests/test_bmp.nim b/tests/test_bmp.nim index d02b36c..ba3c52c 100644 --- a/tests/test_bmp.nim +++ b/tests/test_bmp.nim @@ -1,4 +1,4 @@ -import pixie, pixie/fileformats/bmp, chroma +import chroma, pixie, pixie/fileformats/bmp block: var image = newImage(4, 2) @@ -32,5 +32,6 @@ block: block: for bits in [32, 24]: - var image = decodeBmp(readFile("tests/images/bmp/knight." & $bits & ".master.bmp")) + var image = decodeBmp(readFile("tests/images/bmp/knight." & $bits & + ".master.bmp")) writeFile("tests/images/bmp/knight." & $bits & ".bmp", encodeBmp(image)) diff --git a/tests/test_images.nim b/tests/test_images.nim index 0a56c7b..024637a 100644 --- a/tests/test_images.nim +++ b/tests/test_images.nim @@ -1,4 +1,4 @@ -import pixie, chroma, vmath +import chroma, pixie, vmath block: let image = newImage(10, 10) diff --git a/tests/test_paths.nim b/tests/test_paths.nim index ef28738..0ed6582 100644 --- a/tests/test_paths.nim +++ b/tests/test_paths.nim @@ -1,4 +1,4 @@ -import pixie, chroma, pixie/fileformats/png +import chroma, pixie, pixie/fileformats/png block: let pathStr = """ diff --git a/tests/test_png.nim b/tests/test_png.nim index 719bb8b..ffe3d37 100644 --- a/tests/test_png.nim +++ b/tests/test_png.nim @@ -1,4 +1,4 @@ -import pixie/fileformats/png, strformat, pngsuite, pixie/common +import pixie/common, pixie/fileformats/png, pngsuite, strformat for file in pngSuiteFiles: let diff --git a/tests/test_svg.nim b/tests/test_svg.nim index 2d09953..f4165f2 100644 --- a/tests/test_svg.nim +++ b/tests/test_svg.nim @@ -1,4 +1,4 @@ -import pixie/fileformats/svg, pixie, strformat +import pixie, pixie/fileformats/svg, strformat const files = [ "line01", diff --git a/tests/validate_png.nim b/tests/validate_png.nim index b7648ad..d5be59f 100644 --- a/tests/validate_png.nim +++ b/tests/validate_png.nim @@ -1,4 +1,4 @@ -import chroma, pixie/fileformats/png, stb_image/read as stbi, strformat, pngsuite +import chroma, pixie/fileformats/png, pngsuite, stb_image/read as stbi, strformat for file in pngSuiteFiles: let diff --git a/tools/gen_readme.nim b/tools/gen_readme.nim index 27cb9dc..c64a060 100644 --- a/tools/gen_readme.nim +++ b/tools/gen_readme.nim @@ -1,4 +1,4 @@ -import os, strutils, osproc, sequtils, algorithm +import algorithm, os, osproc, sequtils, strutils proc cutBetween(str, a, b: string): string = let @@ -30,7 +30,8 @@ for path in exampleFiles: md.add "```nim" md.add innerCode.strip() md.add "```" - md.add "![example output](" & path.replace(".nim", ".png").replace("\\", "/") & ")" + md.add "![example output](" & path.replace(".nim", ".png").replace("\\", + "/") & ")" md.add "" var readme = readFile("README.md")