diff --git a/src/pixie/images.nim b/src/pixie/images.nim index d8737ee..529d066 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -95,7 +95,7 @@ proc setColor*(image: Image, x, y: int, color: Color) {.inline, raises: [].} = proc fillUnsafe*( data: var seq[ColorRGBX], color: SomeColor, start, len: int ) {.raises: [].} = - ## Fills the image data with the parameter color starting at index start and + ## Fills the image data with the color starting at index start and ## continuing for len indices. let rgbx = color.asRgbx() @@ -126,7 +126,7 @@ proc fillUnsafe*( data[j] = rgbx proc fill*(image: Image, color: SomeColor) {.inline, raises: [].} = - ## Fills the image with the parameter color. + ## Fills the image with the color. fillUnsafe(image.data, color, 0, image.data.len) proc isOneColor*(image: Image): bool {.raises: [].} = @@ -565,7 +565,7 @@ proc blur*( image.setRgbaUnsafe(x, y, rgbx(values)) proc newMask*(image: Image): Mask {.raises: [PixieError].} = - ## Returns a new mask using the alpha values of the parameter image. + ## Returns a new mask using the alpha values of the image. result = newMask(image.width, image.height) var i: int diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index ac8a7a6..c09607e 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -172,12 +172,12 @@ proc magnifyBy2*(mask: Mask, power = 1): Mask {.raises: [PixieError].} = proc fillUnsafe*( data: var seq[uint8], value: uint8, start, len: int ) {.raises: [].} = - ## Fills the mask data with the parameter value starting at index start and + ## Fills the mask data with the value starting at index start and ## continuing for len indices. nimSetMem(data[start].addr, value.cint, len) proc fill*(mask: Mask, value: uint8) {.inline, raises: [].} = - ## Fills the mask with the parameter value. + ## Fills the mask with the value. fillUnsafe(mask.data, value, 0, mask.data.len) proc getValueSmooth*(mask: Mask, x, y: float32): uint8 {.raises: [].} = diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 8f5c554..4aa032a 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -2555,10 +2555,13 @@ proc fillImage( let channels = [rgbx.r.uint32, rgbx.g.uint32, rgbx.b.uint32, rgbx.a.uint32] for i in i ..< result.data.len: let coverage = mask.data[i] - result.data[i].r = ((channels[0] * coverage) div 255).uint8 - result.data[i].g = ((channels[1] * coverage) div 255).uint8 - result.data[i].b = ((channels[2] * coverage) div 255).uint8 - result.data[i].a = ((channels[3] * coverage) div 255).uint8 + if coverage == 255: + result.data[i] = rgbx + elif coverage != 0: + result.data[i].r = ((channels[0] * coverage) div 255).uint8 + result.data[i].g = ((channels[1] * coverage) div 255).uint8 + result.data[i].b = ((channels[2] * coverage) div 255).uint8 + result.data[i].a = ((channels[3] * coverage) div 255).uint8 proc fillImage*( path: SomePath, width, height: int, color: SomeColor, windingRule = wrNonZero diff --git a/tests/paths/pathHeart2.png b/tests/paths/pathHeart2.png new file mode 100644 index 0000000..560cd66 Binary files /dev/null and b/tests/paths/pathHeart2.png differ diff --git a/tests/test_paths.nim b/tests/test_paths.nim index 8c81a5a..8d973a7 100644 --- a/tests/test_paths.nim +++ b/tests/test_paths.nim @@ -131,6 +131,16 @@ block: ) image.writeFile("tests/paths/pathHeart.png") +block: + let image = """ + M 10,30 + A 20,20 0,0,1 50,30 + A 20,20 0,0,1 90,30 + Q 90,60 50,90 + Q 10,60 10,30 z + """.fillImage(100, 100, parseHtmlColor("#FC427B").rgba) + image.writeFile("tests/paths/pathHeart2.png") + block: let image = newImage(100, 100) image.fillPath(