Skip to content

Commit

Permalink
Update. (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Dec 10, 2024
1 parent df6c2e1 commit 04d4ec1
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 86 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
- "*/*"

env:
TOIT_VERSION: v2.0.0-alpha.119
TOIT_VERSION: v2.0.0-alpha.174
APP_NAME: pngdiff

jobs:
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
make test
- name: Upload binary artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: binaries-${{ runner.os }}
path: build/png*
Expand All @@ -96,7 +96,7 @@ jobs:
run: |
rm -Recurse -Force ${{ github.workspace }}\*
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: binaries-Windows
path: in
Expand All @@ -123,7 +123,7 @@ jobs:
7z a ${{env.APP_NAME}}-windows.zip ${{env.APP_NAME}}.exe
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: binaries-Windows-signed
path: ./out
Expand All @@ -144,7 +144,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: binaries-macOS
path: in
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
zip -j out/${{env.APP_NAME}}-macos.zip build/${{env.APP_NAME}}
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: binaries-macOS-signed
path: ./out
Expand Down
20 changes: 15 additions & 5 deletions bin/package.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sdk: ^2.0.0-alpha.64
sdk: ^2.0.0-alpha.144
prefixes:
cli: pkg-cli
host: pkg-host
Expand All @@ -9,10 +9,20 @@ packages:
pkg-cli:
url: github.com/toitlang/pkg-cli
name: cli
version: 1.2.0
hash: 0e2adab3ab434c597be60438ccf64008f703ad9c
version: 1.8.0
hash: 73c8aabb60a6f5f304566a1e781d7b025aa17e9b
prefixes:
fs: pkg-fs
host: pkg-host
pkg-fs:
url: github.com/toitlang/pkg-fs
name: fs
version: 2.3.1
hash: 60836d4500317af2093d59d50c117d612c33f1fa
prefixes:
host: pkg-host
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.11.0
hash: 7e7df6ac70d98a02f232185add81a06cec0d77e8
version: 1.15.3
hash: 62393e8522b77eafbafe60b9817935266117daf6
4 changes: 2 additions & 2 deletions bin/package.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies:
cli:
url: github.com/toitlang/pkg-cli
version: ^1.2.0
version: ^1.8.0
host:
url: github.com/toitlang/pkg-host
version: ^1.11.0
version: ^1.15.3
png-tools:
path: ..
36 changes: 17 additions & 19 deletions bin/pngdiff.toit
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// Use of this source code is governed by an MIT-style license that can be
// found in the LICENSE file.
import binary show BIG-ENDIAN
import io show BIG-ENDIAN CloseableReader
import bitmap
import cli
import host.file
import host.pipe
import reader show BufferedReader
import png-tools.png-reader show PngRgba
import png-tools.png-writer show PngWriter
import .version

main args/List:
root-cmd := cli.Command "pngdiff"
--long-help="""
--help="""
Compare two PNG files at the pixel level.
This can be used to compare PNGs that have been compressed with
Expand Down Expand Up @@ -45,33 +44,33 @@ main args/List:
cli.Flag "quiet"
--short-name="q"
--default=false
--short-help="Do not write messages to stderr, just return the exit code.",
--help="Do not write messages to stderr, just return the exit code.",
cli.Option "out"
--short-name="o"
--default=null
--short-help="Output (default: no output file)."
--help="Output (default: no output file)."
--type="file",
cli.Flag "three-way"
--short-name="t"
--default=false
--short-help="Creates a three-way diff image, with the difference on top left, the first image in center, and the second image on the right.",
--help="Creates a three-way diff image, with the difference on top left, the first image in center, and the second image on the right.",
cli.Flag "version"
--short-name="v"
--default=false
--short-help="Print version and exit",
--help="Print version and exit",
cli.Flag "debug-stack-traces"
--short-name="d"
--default=false
--short-help="Dump developer-friendly stack traces on error.",
--help="Dump developer-friendly stack traces on error.",
]
--rest=[
cli.Option "file1"
--required
--short-help="PNG file input 1."
--help="PNG file input 1."
--type="file",
cli.Option "file2"
--default="-"
--short-help="PNG file input 2."
--help="PNG file input 2."
--type="file",
]
--run= :: diff it
Expand Down Expand Up @@ -215,18 +214,17 @@ MAX-OUT := ByteArray 0x100: it == 0 ? 0 : 0xff

slurp-file file-name/string --debug/bool -> PngRgba:
error := catch --unwind=debug:
reader := BufferedReader
file-name == "-" ?
pipe.stdin :
file.Stream.for-read file-name
reader.buffer-all
content := reader.read-bytes reader.buffered
png := PngRgba content
reader/CloseableReader := file-name == "-"
? pipe.stdin.in
: (file.Stream.for-read file-name).in
contents := reader.read-all
reader.close
png := PngRgba contents
return png
if error:
if error == "OUT_OF_BOUNDS":
pipe.stderr.write "$file-name: Broken PNG file.\n"
pipe.stderr.out.write "$file-name: Broken PNG file.\n"
else:
pipe.stderr.write "$file-name: $error.\n"
pipe.stderr.out.write "$file-name: $error.\n"
exit 1
unreachable
45 changes: 22 additions & 23 deletions bin/pnginfo.toit
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import cli
import host.file
import host.pipe
import io show CloseableReader
import encoding.json
import reader show BufferedReader
import png-tools.png-reader show *
import png-tools.png-writer show PngWriter
import .version

main args/List:
root-cmd := cli.Command "pnginfo"
--long-help="""
--help="""
Print information about a PNG file.
The exit code can be used to check if the PNG file is readable.
Expand All @@ -28,51 +28,51 @@ main args/List:
cli.Option "out"
--short-name="o"
--default="-"
--short-help="Output (default: stdout)."
--help="Output (default: stdout)."
--type="file",
cli.Flag "version"
--short-name="v"
--default=false
--short-help="Print version and exit.",
--help="Print version and exit.",
cli.Flag "json"
--short-name="j"
--default=false
--short-help="Print information in JSON format.",
--help="Print information in JSON format.",
cli.Flag "width"
--short-name="w"
--default=false
--short-help="Print the width of the image in pixels, and nothing else.",
--help="Print the width of the image in pixels, and nothing else.",
cli.Flag "height"
--short-name="h"
--default=false
--short-help="Print the width of the image in pixels, and nothing else.",
--help="Print the width of the image in pixels, and nothing else.",
cli.Option "chunk"
--short-name="c"
--default=null
--short-help="Dump the contents of the named chunk and nothing else."
--help="Dump the contents of the named chunk and nothing else."
--type="string",
cli.Flag "all-chunks"
--short-name="a"
--default=false
--short-help="Dump the contents of all non-required chunks.",
--help="Dump the contents of all non-required chunks.",
cli.Flag "random-access"
--short-name="r"
--default=false
--short-help="Print whether the PNG file has uncompressed random access pixel data.",
--help="Print whether the PNG file has uncompressed random access pixel data.",
cli.Flag "show-image-data"
--short-name="s"
--default=false
--short-help="Use terminal graphics to show the image data.",
--help="Use terminal graphics to show the image data.",
cli.Flag "debug-stack-traces"
--short-name="d"
--default=false
--short-help="Dump developer-friendly stack traces on error.",
--help="Dump developer-friendly stack traces on error.",
]
--rest=[
cli.Option "file"
--required
--multi
--short-help="PNG file input."
--help="PNG file input."
--type="file",
]
--run= :: dump it
Expand Down Expand Up @@ -288,19 +288,18 @@ show-image-data png/PngRgba out-stream -> none:

slurp-file file-name/string --debug/bool --include-image-data/bool=false -> List:
error := catch --unwind=debug:
reader := BufferedReader
file-name == "-" ?
pipe.stdin :
file.Stream.for-read file-name
reader.buffer-all
content := reader.read-bytes reader.buffered
info := PngInfo content
reader/CloseableReader := file-name == "-"
? pipe.stdin.in
: (file.Stream.for-read file-name).in
contents := reader.read-all
reader.close
info := PngInfo contents
if not include-image-data: return [info]
return [info, PngRgba content]
return [info, PngRgba contents]
if error:
if error == "OUT_OF_BOUNDS":
pipe.stderr.write "$file-name: Broken PNG file.\n"
pipe.stderr.out.write "$file-name: Broken PNG file.\n"
else:
pipe.stderr.write "$file-name: $error.\n"
pipe.stderr.out.write "$file-name: $error.\n"
exit 1
unreachable
39 changes: 19 additions & 20 deletions bin/pngunzip.toit
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import bitmap
import cli
import host.file
import host.pipe
import io show CloseableReader
import png-tools.png-reader show Png COLOR-TYPE-INDEXED COLOR-TYPE-GRAYSCALE
import png-tools.png-writer show PngWriter
import reader show BufferedReader
import .version

main args/List:
root-cmd := cli.Command "pngunzip"
--long-help="""
--help="""
Uncompress a PNG file.
This can be used to create PNG files that don't use any
Expand All @@ -29,40 +29,40 @@ main args/List:
cli.Flag "quiet"
--short-name="q"
--default=false
--short-help="Do not write messages to stderr, just return the exit code.",
--help="Do not write messages to stderr, just return the exit code.",
cli.Option "out"
--short-name="o"
--default="-"
--short-help="Output (default: stdout)."
--help="Output (default: stdout)."
--type="file",
cli.Flag "version"
--short-name="v"
--default=false
--short-help="Print version and exit",
--help="Print version and exit",
cli.Flag "debug-stack-traces"
--short-name="d"
--default=false
--short-help="Dump developer-friendly stack traces on error.",
--help="Dump developer-friendly stack traces on error.",
cli.Flag "preserve"
--short-name="p"
--default=false
--short-help="Preserve all chunks",
--help="Preserve all chunks",
cli.Option "preserve-chunk"
--multi
--short-help="Preserve a named chunk."
--help="Preserve a named chunk."
--type="string",
cli.OptionInt "max-literal-section"
--default=64000
--short-help="Maximum size of a zlib section.",
--help="Maximum size of a zlib section.",
cli.Option "override-chunk"
--multi
--short-help="Override a named chunk."
--help="Override a named chunk."
--type="string",
]
--rest=[
cli.Option "file"
--required
--short-help="PNG file input."
--help="PNG file input."
--type="file",
]
--run= :: unzip it
Expand Down Expand Up @@ -156,19 +156,18 @@ MAX-OUT := ByteArray 0x100: it == 0 ? 0 : 0xff

slurp-file file-name/string --debug/bool -> Png:
error := catch --unwind=debug:
reader := BufferedReader
file-name == "-" ?
pipe.stdin :
file.Stream.for-read file-name
reader.buffer-all
content := reader.read-bytes reader.buffered
png := Png content
reader/CloseableReader := file-name == "-"
? pipe.stdin.in
: (file.Stream.for-read file-name).in
contents := reader.read-all
reader.close
png := Png contents
return png
if error:
if error == "OUT_OF_BOUNDS":
pipe.stderr.write "$file-name: Broken PNG file.\n"
pipe.stderr.out.write "$file-name: Broken PNG file.\n"
else:
pipe.stderr.write "$file-name: $error.\n"
pipe.stderr.out.write "$file-name: $error.\n"
exit 1
unreachable

Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: png-tools
description: Tools for manipulating PNGs, written in Toit.
environment:
sdk: ^2.0.0-alpha.119
sdk: ^2.0.0-alpha.174
Loading

0 comments on commit 04d4ec1

Please sign in to comment.