morepretty

This commit is contained in:
Ryan Oldenburg 2021-02-14 12:27:32 -06:00
parent 68e2522074
commit f2b3c67d4b
40 changed files with 82 additions and 72 deletions

View file

@ -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)

View file

@ -1,4 +1,4 @@
import pixie, chroma, vmath
import chroma, pixie, vmath
let
image = newImage(200, 200)

View file

@ -1,4 +1,4 @@
import pixie, chroma, vmath
import chroma, pixie, vmath
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))

View file

@ -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)

View file

@ -1,4 +1,4 @@
import pixie, chroma
import chroma, pixie
var image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))

View file

@ -1,4 +1,4 @@
import pixie, chroma, vmath
import chroma, pixie, vmath
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))

View file

@ -1,4 +1,4 @@
import cairo, math, benchy, pixie, chroma
import benchy, cairo, chroma, math, pixie
var
surface = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000)

View file

@ -1,4 +1,4 @@
import svg_cairo, benchy
import benchy, svg_cairo
let data = readFile("tests/images/svg/Ghostscript_Tiger.svg")

View file

@ -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

View file

@ -1,4 +1,4 @@
import svg_cairo, pixie, strformat
import pixie, strformat, svg_cairo
const files = [
"line01",

View file

@ -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) =

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -1,4 +1,4 @@
import pixie/images, pixie/common
import pixie/common, pixie/images
when defined(pixieUseStb):
import pixie/fileformats/stb_image/stb_image

View file

@ -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

View file

@ -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* = "<?xml"

View file

@ -1,4 +1,4 @@
import chroma, blends, bumpy, vmath, common, system/memory, masks
import blends, bumpy, chroma, common, masks, system/memory, vmath
when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2
@ -571,7 +571,7 @@ proc drawCorrect(a, b: Image | Mask, mat = mat3(), blendMode = bmNormal) =
else: # b is a Mask
let
sample = b.getValueSmooth(xFloat, yFloat)
blended = blender(backdrop, rgba(0, 0, 0, sample))
blended = blender(backdrop, rgba(0, 0, 0, sample))
a.setRgbaUnsafe(x, y, blended)
else: # a is a Mask
let backdrop = a.getValueUnsafe(x, y)
@ -678,7 +678,7 @@ proc drawUber(a, b: Image | Mask, mat = mat3(), blendMode = bmNormal) =
else: # b is a Mask
let
sample = b.getValueSmooth(xFloat, yFloat)
blended = blender(backdrop, rgba(0, 0, 0, sample))
blended = blender(backdrop, rgba(0, 0, 0, sample))
a.setRgbaUnsafe(x, y, blended)
else: # a is a Mask
let backdrop = a.getValueUnsafe(x, y)
@ -765,7 +765,7 @@ proc drawUber(a, b: Image | Mask, mat = mat3(), blendMode = bmNormal) =
else: # b is a Mask
let
sample = b.getValueUnsafe(xFloat.int, yFloat.int)
blended = blender(backdrop, rgba(0, 0, 0, sample))
blended = blender(backdrop, rgba(0, 0, 0, sample))
a.setRgbaUnsafe(x, y, blended)
else: # a is a Mask
let backdrop = a.getValueUnsafe(x, y)
@ -827,11 +827,13 @@ proc shift*(target: Image | Mask, offset: Vec2) =
## Shifts the target by offset.
if offset != vec2(0, 0):
let copy = target.copy() # Copy to read from
# Reset target for being drawn to
when type(target) is Image:
target.fill(rgba(0, 0, 0, 0))
else:
target.fill(0)
target.draw(copy, offset, bmOverwrite) # Draw copy at offset
proc shadow*(

View file

@ -1,4 +1,4 @@
import common, vmath, system/memory
import common, system/memory, vmath
when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2

View file

@ -1,4 +1,4 @@
import common, strutils, vmath, images, masks, chroma, bumpy, blends
import blends, bumpy, chroma, common, images, masks, strutils, vmath
when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2
@ -571,15 +571,15 @@ proc commandsToShapes*(path: Path): seq[seq[Vec2]] =
var q = sqrt(max(0, pq))
if large == sweep:
q = -q
q = -q
proc svgAngle(u, v: Vec2): float32 =
let
dot = dot(u,v)
dot = dot(u, v)
len = length(u) * length(v)
result = arccos(clamp(dot / len, -1, 1))
if (u.x * v.y - u.y * v.x) < 0:
result = -result
result = -result
let
cp = vec2(q * radii.x * p.y / radii.y, -q * radii.y * p.x / radii.x)
@ -929,7 +929,7 @@ proc computeCoverages(
for (segment, winding) in partitions[partition]:
if segment.at.y <= scanline.a.y and segment.to.y >= 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

View file

@ -1,4 +1,4 @@
import benchy, chroma, vmath, pixie/images
import benchy, chroma, pixie/images, vmath
include pixie/blends

View file

@ -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)

View file

@ -1,4 +1,4 @@
import chroma, pixie, benchy
import benchy, chroma, pixie
let image = newImage(2560, 1440)

View file

@ -1,4 +1,4 @@
import pixie, chroma, vmath, benchy
import benchy, chroma, pixie, vmath
block:
let

View file

@ -1,4 +1,4 @@
import pixie/fileformats/jpg, benchy
import benchy, pixie/fileformats/jpg
let data = readFile("tests/images/jpg/jpeg420exif.jpg")

View file

@ -1,4 +1,4 @@
import chroma, pixie, benchy
import benchy, chroma, pixie
let mask = newMask(2560, 1440)

View file

@ -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"

View file

@ -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")

View file

@ -1,4 +1,4 @@
import pixie/fileformats/svg, benchy
import benchy, pixie/fileformats/svg
let data = readFile("tests/images/svg/Ghostscript_Tiger.svg")

View file

@ -1,4 +1,4 @@
import random, strformat, pixie/fileformats/jpg, pixie/common
import pixie/common, pixie/fileformats/jpg, random, strformat
randomize()

View file

@ -1,4 +1,4 @@
import random, strformat, pixie/paths, pixie/common, strformat
import pixie/common, pixie/paths, random, strformat
randomize()

View file

@ -1,4 +1,4 @@
import random, strformat, pixie/fileformats/png, pixie/common, pngsuite
import pixie/common, pixie/fileformats/png, pngsuite, random, strformat
randomize()

View file

@ -1,4 +1,4 @@
import random, strformat, pixie/fileformats/svg, pixie/common
import pixie/common, pixie/fileformats/svg, random, strformat
randomize()

View file

@ -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))

View file

@ -1,4 +1,4 @@
import pixie, chroma, vmath
import chroma, pixie, vmath
block:
let image = newImage(10, 10)

View file

@ -1,4 +1,4 @@
import pixie, chroma, pixie/fileformats/png
import chroma, pixie, pixie/fileformats/png
block:
let pathStr = """

View file

@ -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

View file

@ -1,4 +1,4 @@
import pixie/fileformats/svg, pixie, strformat
import pixie, pixie/fileformats/svg, strformat
const files = [
"line01",

View file

@ -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

View file

@ -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")