@socketsecurity/cli-with-sentry 0.15.11 → 0.15.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +6 -6
- package/dist/.config/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/cli.js +5731 -6607
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +274 -305
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +28 -34
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/shadow-bin.js +96 -123
- package/dist/shadow-bin.js.map +1 -1
- package/dist/shadow-inject.js +470 -580
- package/dist/shadow-inject.js.map +1 -1
- package/dist/socket-completion.bash +221 -0
- package/dist/types/cli.d.mts +2 -2
- package/dist/types/commands/analytics/cmd-analytics.d.mts +9 -15
- package/dist/types/commands/analytics/fetch-org-analytics.d.mts +4 -6
- package/dist/types/commands/analytics/fetch-repo-analytics.d.mts +4 -7
- package/dist/types/commands/analytics/handle-analytics.d.mts +9 -15
- package/dist/types/commands/analytics/handle-analytics.d.mts.map +1 -1
- package/dist/types/commands/analytics/output-analytics.d.mts +26 -46
- package/dist/types/commands/analytics/output-analytics.d.mts.map +1 -1
- package/dist/types/commands/audit-log/cmd-audit-log.d.mts +9 -15
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts +10 -16
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts.map +1 -1
- package/dist/types/commands/audit-log/handle-audit-log.d.mts +9 -15
- package/dist/types/commands/audit-log/handle-audit-log.d.mts.map +1 -1
- package/dist/types/commands/audit-log/output-audit-log.d.mts +22 -47
- package/dist/types/commands/audit-log/output-audit-log.d.mts.map +1 -1
- package/dist/types/commands/cdxgen/cmd-cdxgen.d.mts +9 -15
- package/dist/types/commands/cdxgen/cmd-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/cdxgen/handle-cdxgen.d.mts +4 -0
- package/dist/types/commands/cdxgen/handle-cdxgen.d.mts.map +1 -0
- package/dist/types/commands/ci/cmd-ci.d.mts +9 -15
- package/dist/types/commands/ci/fetch-default-org-slug.d.mts +3 -3
- package/dist/types/commands/ci/handle-ci.d.mts +2 -2
- package/dist/types/commands/config/cmd-config-auto.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-get.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-list.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-set.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-unset.d.mts +9 -15
- package/dist/types/commands/config/cmd-config.d.mts +3 -3
- package/dist/types/commands/config/discover-config-value.d.mts +3 -5
- package/dist/types/commands/config/discover-config-value.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-auto.d.mts +7 -10
- package/dist/types/commands/config/handle-config-auto.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-get.d.mts +7 -10
- package/dist/types/commands/config/handle-config-get.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-set.d.mts +8 -12
- package/dist/types/commands/config/handle-config-set.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-unset.d.mts +7 -10
- package/dist/types/commands/config/handle-config-unset.d.mts.map +1 -1
- package/dist/types/commands/config/output-config-auto.d.mts +4 -8
- package/dist/types/commands/config/output-config-get.d.mts +4 -8
- package/dist/types/commands/config/output-config-list.d.mts +6 -9
- package/dist/types/commands/config/output-config-list.d.mts.map +1 -1
- package/dist/types/commands/config/output-config-set.d.mts +3 -6
- package/dist/types/commands/config/output-config-unset.d.mts +3 -6
- package/dist/types/commands/dependencies/cmd-dependencies.d.mts +9 -15
- package/dist/types/commands/dependencies/fetch-dependencies.d.mts +7 -10
- package/dist/types/commands/dependencies/fetch-dependencies.d.mts.map +1 -1
- package/dist/types/commands/dependencies/handle-dependencies.d.mts +7 -11
- package/dist/types/commands/dependencies/handle-dependencies.d.mts.map +1 -1
- package/dist/types/commands/dependencies/output-dependencies.d.mts +8 -15
- package/dist/types/commands/dependencies/output-dependencies.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/cmd-diff-scan-get.d.mts +9 -15
- package/dist/types/commands/diff-scan/cmd-diff-scan.d.mts +3 -3
- package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts +8 -12
- package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/handle-diff-scan.d.mts +10 -17
- package/dist/types/commands/diff-scan/handle-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/output-diff-scan.d.mts +8 -15
- package/dist/types/commands/diff-scan/output-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts +9 -15
- package/dist/types/commands/fix/git.d.mts +14 -49
- package/dist/types/commands/fix/npm-fix.d.mts +4 -16
- package/dist/types/commands/fix/npm-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/open-pr.d.mts +20 -46
- package/dist/types/commands/fix/open-pr.d.mts.map +1 -1
- package/dist/types/commands/fix/pnpm-fix.d.mts +4 -16
- package/dist/types/commands/fix/pnpm-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/run-fix.d.mts +3 -3
- package/dist/types/commands/fix/shared.d.mts +9 -15
- package/dist/types/commands/fix/types.d.mts +16 -16
- package/dist/types/commands/info/cmd-info.d.mts +9 -15
- package/dist/types/commands/info/fetch-package-info.d.mts +3 -7
- package/dist/types/commands/info/handle-package-info.d.mts +15 -22
- package/dist/types/commands/info/handle-package-info.d.mts.map +1 -1
- package/dist/types/commands/info/output-package-info.d.mts +10 -18
- package/dist/types/commands/info/output-package-info.d.mts.map +1 -1
- package/dist/types/commands/install/cmd-install-completion.d.mts +10 -0
- package/dist/types/commands/install/cmd-install-completion.d.mts.map +1 -0
- package/dist/types/commands/install/cmd-install.d.mts +3 -0
- package/dist/types/commands/install/cmd-install.d.mts.map +1 -0
- package/dist/types/commands/install/handle-install-completion.d.mts +2 -0
- package/dist/types/commands/install/handle-install-completion.d.mts.map +1 -0
- package/dist/types/commands/install/output-install-completion.d.mts +12 -0
- package/dist/types/commands/install/output-install-completion.d.mts.map +1 -0
- package/dist/types/commands/install/setup-tab-completion.d.mts +13 -0
- package/dist/types/commands/install/setup-tab-completion.d.mts.map +1 -0
- package/dist/types/commands/login/apply-login.d.mts +2 -7
- package/dist/types/commands/login/attempt-login.d.mts +2 -5
- package/dist/types/commands/login/attempt-login.d.mts.map +1 -1
- package/dist/types/commands/login/cmd-login.d.mts +9 -15
- package/dist/types/commands/logout/apply-logout.d.mts +2 -2
- package/dist/types/commands/logout/attempt-logout.d.mts +2 -2
- package/dist/types/commands/logout/cmd-logout.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-auto.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts +10 -0
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts.map +1 -0
- package/dist/types/commands/manifest/cmd-manifest-conda.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-scala.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest.d.mts.map +1 -1
- package/dist/types/commands/manifest/convert-conda-to-requirements.d.mts +7 -15
- package/dist/types/commands/manifest/convert_gradle_to_maven.d.mts +2 -8
- package/dist/types/commands/manifest/convert_sbt_to_maven.d.mts +2 -8
- package/dist/types/commands/manifest/handle-manifest-conda.d.mts +3 -9
- package/dist/types/commands/manifest/output-requirements.d.mts +6 -10
- package/dist/types/commands/{cdxgen → manifest}/run-cdxgen.d.mts +2 -2
- package/dist/types/commands/manifest/run-cdxgen.d.mts.map +1 -0
- package/dist/types/commands/npm/cmd-npm.d.mts +9 -15
- package/dist/types/commands/npx/cmd-npx.d.mts +9 -15
- package/dist/types/commands/oops/cmd-oops.d.mts +9 -15
- package/dist/types/commands/optimize/add-overrides.d.mts +18 -22
- package/dist/types/commands/optimize/apply-optimization.d.mts +2 -6
- package/dist/types/commands/optimize/cmd-optimize.d.mts +9 -15
- package/dist/types/commands/optimize/deps-includes-by-agent.d.mts +4 -7
- package/dist/types/commands/optimize/get-dependency-entries.d.mts +3 -5
- package/dist/types/commands/optimize/get-overrides-by-agent.d.mts +8 -11
- package/dist/types/commands/optimize/lockfile-includes-by-agent.d.mts +3 -10
- package/dist/types/commands/optimize/ls-by-agent.d.mts +6 -13
- package/dist/types/commands/optimize/shared.d.mts +2 -2
- package/dist/types/commands/optimize/types.d.mts +7 -7
- package/dist/types/commands/optimize/update-lockfile.d.mts +9 -12
- package/dist/types/commands/optimize/update-manifest-by-agent.d.mts +5 -11
- package/dist/types/commands/organization/cmd-organization-list.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization-policy-license.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization-policy-security.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization-policy.d.mts +3 -3
- package/dist/types/commands/organization/cmd-organization-quota.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization.d.mts +3 -3
- package/dist/types/commands/organization/fetch-license-policy.d.mts +4 -6
- package/dist/types/commands/organization/fetch-organization-list.d.mts +4 -6
- package/dist/types/commands/organization/fetch-quota.d.mts +4 -6
- package/dist/types/commands/organization/fetch-security-policy.d.mts +4 -6
- package/dist/types/commands/organization/handle-license-policy.d.mts +3 -6
- package/dist/types/commands/organization/handle-organization-list.d.mts +3 -5
- package/dist/types/commands/organization/handle-quota.d.mts +3 -3
- package/dist/types/commands/organization/handle-security-policy.d.mts +3 -6
- package/dist/types/commands/organization/output-license-policy.d.mts +4 -7
- package/dist/types/commands/organization/output-organization-list.d.mts +4 -7
- package/dist/types/commands/organization/output-quota.d.mts +4 -7
- package/dist/types/commands/organization/output-security-policy.d.mts +4 -7
- package/dist/types/commands/package/cmd-package-score.d.mts +9 -15
- package/dist/types/commands/package/cmd-package-shallow.d.mts +16 -22
- package/dist/types/commands/package/cmd-package.d.mts +3 -3
- package/dist/types/commands/package/fetch-purl-deep-score.d.mts +49 -51
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts +4 -6
- package/dist/types/commands/package/handle-purl-deep-score.d.mts +3 -6
- package/dist/types/commands/package/handle-purls-shallow-score.d.mts +6 -9
- package/dist/types/commands/package/handle-purls-shallow-score.d.mts.map +1 -1
- package/dist/types/commands/package/output-purl-score.d.mts +4 -8
- package/dist/types/commands/package/output-purls-shallow-score.d.mts +4 -8
- package/dist/types/commands/package/parse-package-specifiers.d.mts +5 -8
- package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts +9 -15
- package/dist/types/commands/raw-npm/run-raw-npm.d.mts +2 -4
- package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts +9 -15
- package/dist/types/commands/raw-npx/run-raw-npx.d.mts +2 -4
- package/dist/types/commands/report/cmd-report-create.d.mts +9 -15
- package/dist/types/commands/report/cmd-report-view.d.mts +9 -15
- package/dist/types/commands/report/cmd-report.d.mts +3 -3
- package/dist/types/commands/repos/cmd-repos-create.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-del.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-list.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-update.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-view.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos.d.mts +3 -3
- package/dist/types/commands/repos/fetch-create-repo.d.mts +11 -18
- package/dist/types/commands/repos/fetch-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-delete-repo.d.mts +4 -7
- package/dist/types/commands/repos/fetch-list-repos.d.mts +10 -16
- package/dist/types/commands/repos/fetch-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-update-repo.d.mts +11 -18
- package/dist/types/commands/repos/fetch-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-view-repo.d.mts +4 -7
- package/dist/types/commands/repos/handle-create-repo.d.mts +10 -20
- package/dist/types/commands/repos/handle-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/handle-delete-repo.d.mts +3 -7
- package/dist/types/commands/repos/handle-list-repos.d.mts +10 -17
- package/dist/types/commands/repos/handle-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repos/handle-update-repo.d.mts +10 -20
- package/dist/types/commands/repos/handle-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/handle-view-repo.d.mts +3 -7
- package/dist/types/commands/repos/output-create-repo.d.mts +4 -8
- package/dist/types/commands/repos/output-delete-repo.d.mts +4 -8
- package/dist/types/commands/repos/output-list-repos.d.mts +4 -7
- package/dist/types/commands/repos/output-update-repo.d.mts +4 -8
- package/dist/types/commands/repos/output-view-repo.d.mts +4 -7
- package/dist/types/commands/scan/cmd-scan-create.d.mts +9 -15
- package/dist/types/commands/scan/cmd-scan-del.d.mts +9 -15
- package/dist/types/commands/scan/cmd-scan-diff.d.mts +9 -15
- package/dist/types/commands/scan/cmd-scan-list.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan-metadata.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan-report.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan-view.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan.d.mts +3 -3
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts +11 -26
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-delete-org-full-scan.d.mts +4 -7
- package/dist/types/commands/scan/fetch-diff-scan.d.mts +8 -12
- package/dist/types/commands/scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-list-scans.d.mts +13 -22
- package/dist/types/commands/scan/fetch-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-report-data.d.mts +8 -14
- package/dist/types/commands/scan/fetch-scan-metadata.d.mts +4 -7
- package/dist/types/commands/scan/fetch-scan.d.mts +4 -7
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts +4 -6
- package/dist/types/commands/scan/generate-report.d.mts +36 -50
- package/dist/types/commands/scan/generate-report.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-create-new-scan.d.mts +20 -37
- package/dist/types/commands/scan/handle-create-new-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-delete-scan.d.mts +3 -7
- package/dist/types/commands/scan/handle-diff-scan.d.mts +10 -17
- package/dist/types/commands/scan/handle-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-list-scans.d.mts +13 -23
- package/dist/types/commands/scan/handle-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-scan-metadata.d.mts +3 -7
- package/dist/types/commands/scan/handle-scan-report.d.mts +12 -21
- package/dist/types/commands/scan/handle-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-scan-view.d.mts +3 -8
- package/dist/types/commands/scan/output-create-new-scan.d.mts +4 -8
- package/dist/types/commands/scan/output-delete-scan.d.mts +4 -7
- package/dist/types/commands/scan/output-diff-scan.d.mts +8 -15
- package/dist/types/commands/scan/output-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/output-list-scans.d.mts +4 -7
- package/dist/types/commands/scan/output-scan-metadata.d.mts +4 -8
- package/dist/types/commands/scan/output-scan-report.d.mts +20 -38
- package/dist/types/commands/scan/output-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/output-scan-view.d.mts +4 -10
- package/dist/types/commands/scan/stream-scan.d.mts +2 -6
- package/dist/types/commands/scan/suggest-org-slug.d.mts +2 -2
- package/dist/types/commands/scan/suggest-repo-slug.d.mts +4 -4
- package/dist/types/commands/scan/suggest_branch_slug.d.mts +2 -4
- package/dist/types/commands/scan/suggest_target.d.mts +2 -2
- package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts +9 -15
- package/dist/types/commands/threat-feed/fetch-threat-feed.d.mts +10 -16
- package/dist/types/commands/threat-feed/fetch-threat-feed.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/handle-threat-feed.d.mts +10 -17
- package/dist/types/commands/threat-feed/handle-threat-feed.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/output-threat-feed.d.mts +4 -7
- package/dist/types/commands/threat-feed/types.d.mts +12 -12
- package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts +9 -0
- package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts.map +1 -0
- package/dist/types/commands/uninstall/cmd-uninstall.d.mts +3 -0
- package/dist/types/commands/uninstall/cmd-uninstall.d.mts.map +1 -0
- package/dist/types/commands/uninstall/handle-uninstall-completion.d.mts +2 -0
- package/dist/types/commands/uninstall/handle-uninstall-completion.d.mts.map +1 -0
- package/dist/types/commands/uninstall/output-uninstall-completion.d.mts +6 -0
- package/dist/types/commands/uninstall/output-uninstall-completion.d.mts.map +1 -0
- package/dist/types/commands/uninstall/teardown-tab-completion.d.mts +6 -0
- package/dist/types/commands/uninstall/teardown-tab-completion.d.mts.map +1 -0
- package/dist/types/commands/wrapper/add-socket-wrapper.d.mts +2 -2
- package/dist/types/commands/wrapper/check-socket-wrapper-setup.d.mts +2 -2
- package/dist/types/commands/wrapper/cmd-wrapper.d.mts +9 -15
- package/dist/types/commands/wrapper/postinstall-wrapper.d.mts +2 -2
- package/dist/types/commands/wrapper/postinstall-wrapper.d.mts.map +1 -1
- package/dist/types/commands/wrapper/remove-socket-wrapper.d.mts +2 -2
- package/dist/types/constants.d.mts +125 -135
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/flags.d.mts +14 -17
- package/dist/types/flags.d.mts.map +1 -1
- package/dist/types/instrument-with-sentry.d.mts +2 -2
- package/dist/types/shadow/npm/arborist/index.d.mts +2 -2
- package/dist/types/shadow/npm/arborist/lib/arborist/index.d.mts +19 -24
- package/dist/types/shadow/npm/arborist/lib/arborist/types.d.mts +43 -71
- package/dist/types/shadow/npm/arborist/lib/dep-valid.d.mts +3 -8
- package/dist/types/shadow/npm/arborist/lib/edge.d.mts +58 -71
- package/dist/types/shadow/npm/arborist/lib/node.d.mts +55 -91
- package/dist/types/shadow/npm/arborist/lib/override-set.d.mts +26 -32
- package/dist/types/shadow/npm/arborist-helpers.d.mts +33 -66
- package/dist/types/shadow/npm/arborist-helpers.d.mts.map +1 -1
- package/dist/types/shadow/npm/bin.d.mts +2 -5
- package/dist/types/shadow/npm/inject.d.mts +2 -2
- package/dist/types/shadow/npm/install.d.mts +11 -16
- package/dist/types/shadow/npm/link.d.mts +2 -5
- package/dist/types/shadow/npm/paths.d.mts +7 -7
- package/dist/types/shadow/npm/proc-log/index.d.mts +3 -6
- package/dist/types/types.d.mts +15 -17
- package/dist/types/utils/agent.d.mts +11 -14
- package/dist/types/utils/alert/artifact.d.mts +32 -50
- package/dist/types/utils/alert/fix.d.mts +5 -5
- package/dist/types/utils/alert/severity.d.mts +12 -24
- package/dist/types/utils/alerts-map.d.mts +23 -36
- package/dist/types/utils/api.d.mts +11 -34
- package/dist/types/utils/check-input.d.mts +9 -12
- package/dist/types/utils/cmd.d.mts +4 -4
- package/dist/types/utils/color-or-markdown.d.mts +14 -23
- package/dist/types/utils/color-or-markdown.d.mts.map +1 -1
- package/dist/types/utils/completion.d.mts +11 -0
- package/dist/types/utils/completion.d.mts.map +1 -0
- package/dist/types/utils/config.d.mts +22 -31
- package/dist/types/utils/config.d.mts.map +1 -1
- package/dist/types/utils/determine-org-slug.d.mts +2 -7
- package/dist/types/utils/errors.d.mts +12 -21
- package/dist/types/utils/fail-msg-with-badge.d.mts +2 -5
- package/dist/types/utils/fs.d.mts +21 -52
- package/dist/types/utils/get-output-kind.d.mts +3 -6
- package/dist/types/utils/glob.d.mts +13 -24
- package/dist/types/utils/map-to-object.d.mts +4 -6
- package/dist/types/utils/markdown.d.mts +4 -15
- package/dist/types/utils/meow-with-subcommands.d.mts +34 -46
- package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
- package/dist/types/utils/npm-paths.d.mts +7 -7
- package/dist/types/utils/npm-paths.d.mts.map +1 -1
- package/dist/types/utils/objects.d.mts +3 -8
- package/dist/types/utils/output-formatting.d.mts +14 -24
- package/dist/types/utils/package-environment.d.mts +51 -72
- package/dist/types/utils/package-environment.d.mts.map +1 -1
- package/dist/types/utils/path-resolve.d.mts +9 -14
- package/dist/types/utils/pnpm.d.mts +9 -7
- package/dist/types/utils/pnpm.d.mts.map +1 -1
- package/dist/types/utils/sdk.d.mts +8 -12
- package/dist/types/utils/semver.d.mts +5 -17
- package/dist/types/utils/serialize-result-json.d.mts +3 -3
- package/dist/types/utils/socket-package-alert.d.mts +62 -81
- package/dist/types/utils/socket-url.d.mts +9 -15
- package/dist/types/utils/spec.d.mts +4 -7
- package/dist/types/utils/spec.d.mts.map +1 -1
- package/dist/types/utils/strings.d.mts +2 -5
- package/dist/types/utils/translations.d.mts +592 -592
- package/dist/types/utils/walk-nested-map.d.mts +7 -10
- package/dist/utils.js +1531 -1833
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +38333 -51605
- package/dist/vendor.js.map +1 -1
- package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +5 -8
- package/external/@socketsecurity/registry/external/@npmcli/promise-spawn.js +2 -4
- package/external/@socketsecurity/registry/external/cacache.js +1 -2
- package/external/@socketsecurity/registry/external/libnpmpack.js +36 -76
- package/external/@socketsecurity/registry/external/make-fetch-happen.js +31 -67
- package/external/@socketsecurity/registry/external/pacote.js +36 -76
- package/external/@socketsecurity/registry/external/tinyglobby.js +3 -6
- package/external/@socketsecurity/registry/external/which.js +2 -4
- package/external/@socketsecurity/registry/lib/logger.d.ts +3 -1
- package/external/@socketsecurity/registry/lib/logger.js +149 -69
- package/external/@socketsecurity/registry/package.json +2 -2
- package/external/blessed/lib/alias.js +475 -468
- package/external/blessed/lib/blessed.js +12 -12
- package/external/blessed/lib/colors.js +234 -194
- package/external/blessed/lib/events.js +64 -70
- package/external/blessed/lib/gpmclient.js +117 -141
- package/external/blessed/lib/helpers.js +89 -94
- package/external/blessed/lib/keys.js +169 -342
- package/external/blessed/lib/program.js +2130 -2365
- package/external/blessed/lib/tput.js +1183 -1276
- package/external/blessed/lib/unicode.js +400 -522
- package/external/blessed/lib/widget.js +14 -14
- package/external/blessed/lib/widgets/ansiimage.js +90 -96
- package/external/blessed/lib/widgets/bigtext.js +91 -102
- package/external/blessed/lib/widgets/box.js +8 -8
- package/external/blessed/lib/widgets/button.js +23 -23
- package/external/blessed/lib/widgets/checkbox.js +50 -54
- package/external/blessed/lib/widgets/element.js +1415 -1716
- package/external/blessed/lib/widgets/filemanager.js +107 -118
- package/external/blessed/lib/widgets/form.js +144 -178
- package/external/blessed/lib/widgets/image.js +26 -36
- package/external/blessed/lib/widgets/input.js +8 -8
- package/external/blessed/lib/widgets/layout.js +103 -119
- package/external/blessed/lib/widgets/line.js +17 -20
- package/external/blessed/lib/widgets/list.js +349 -402
- package/external/blessed/lib/widgets/listbar.js +265 -306
- package/external/blessed/lib/widgets/listtable.js +133 -146
- package/external/blessed/lib/widgets/loading.js +31 -31
- package/external/blessed/lib/widgets/log.js +41 -40
- package/external/blessed/lib/widgets/message.js +64 -86
- package/external/blessed/lib/widgets/node.js +175 -207
- package/external/blessed/lib/widgets/overlayimage.js +360 -437
- package/external/blessed/lib/widgets/progressbar.js +79 -88
- package/external/blessed/lib/widgets/prompt.js +54 -61
- package/external/blessed/lib/widgets/question.js +48 -61
- package/external/blessed/lib/widgets/radiobutton.js +26 -27
- package/external/blessed/lib/widgets/radioset.js +8 -8
- package/external/blessed/lib/widgets/screen.js +1186 -1375
- package/external/blessed/lib/widgets/scrollablebox.js +202 -228
- package/external/blessed/lib/widgets/scrollabletext.js +9 -9
- package/external/blessed/lib/widgets/table.js +187 -216
- package/external/blessed/lib/widgets/terminal.js +258 -298
- package/external/blessed/lib/widgets/text.js +9 -9
- package/external/blessed/lib/widgets/textarea.js +188 -222
- package/external/blessed/lib/widgets/textbox.js +34 -36
- package/external/blessed/lib/widgets/video.js +55 -59
- package/external/blessed/usr/fonts/ter-u14b.json +1 -1
- package/external/blessed/usr/fonts/ter-u14n.json +1 -1
- package/external/blessed/vendor/tng.js +1016 -1144
- package/external/blessed-contrib/lib/layout/grid.js +345 -377
- package/external/blessed-contrib/lib/widget/charts/bar.js +6612 -7139
- package/external/blessed-contrib/lib/widget/charts/line.js +16224 -23941
- package/external/blessed-contrib/lib/widget/table.js +78 -96
- package/package.json +8 -8
- package/dist/types/commands/cdxgen/run-cdxgen.d.mts.map +0 -1
|
@@ -6,117 +6,110 @@
|
|
|
6
6
|
* https://github.com/chjj/tng
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
util = require('util')
|
|
11
|
-
path = require('path')
|
|
12
|
-
zlib = require('zlib')
|
|
13
|
-
assert = require('assert')
|
|
14
|
-
cp = require('child_process')
|
|
15
|
-
exec = cp.execFileSync
|
|
9
|
+
var fs = require('fs')
|
|
10
|
+
, util = require('util')
|
|
11
|
+
, path = require('path')
|
|
12
|
+
, zlib = require('zlib')
|
|
13
|
+
, assert = require('assert')
|
|
14
|
+
, cp = require('child_process')
|
|
15
|
+
, exec = cp.execFileSync;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* PNG
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
function PNG(file, options) {
|
|
22
|
-
|
|
22
|
+
var buf
|
|
23
|
+
, chunks
|
|
24
|
+
, idat
|
|
25
|
+
, pixels;
|
|
23
26
|
|
|
24
27
|
if (!(this instanceof PNG)) {
|
|
25
|
-
return new PNG(file, options)
|
|
28
|
+
return new PNG(file, options);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
if (!file)
|
|
29
|
-
throw new Error('no file')
|
|
30
|
-
}
|
|
31
|
+
if (!file) throw new Error('no file');
|
|
31
32
|
|
|
32
|
-
this.options = options || {}
|
|
33
|
-
this.colors = options.colors || require('blessed/lib/colors')
|
|
34
|
-
this.optimization = this.options.optimization || 'mem'
|
|
35
|
-
this.speed = this.options.speed || 1
|
|
33
|
+
this.options = options || {};
|
|
34
|
+
this.colors = options.colors || require('blessed/lib/colors');
|
|
35
|
+
this.optimization = this.options.optimization || 'mem';
|
|
36
|
+
this.speed = this.options.speed || 1;
|
|
36
37
|
|
|
37
38
|
if (Buffer.isBuffer(file)) {
|
|
38
|
-
this.file = this.options.filename || null
|
|
39
|
-
buf = file
|
|
39
|
+
this.file = this.options.filename || null;
|
|
40
|
+
buf = file;
|
|
40
41
|
} else {
|
|
41
|
-
this.options.filename = file
|
|
42
|
-
this.file = path.resolve(process.cwd(), file)
|
|
43
|
-
buf = fs.readFileSync(this.file)
|
|
42
|
+
this.options.filename = file;
|
|
43
|
+
this.file = path.resolve(process.cwd(), file);
|
|
44
|
+
buf = fs.readFileSync(this.file);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
this.format =
|
|
47
|
-
buf.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
? 'gif'
|
|
51
|
-
: buf.readUInt16BE(0) === 0xffd8
|
|
52
|
-
? 'jpg'
|
|
53
|
-
: path.extname(this.file).slice(1).toLowerCase() || 'png'
|
|
47
|
+
this.format = buf.readUInt32BE(0) === 0x89504e47 ? 'png'
|
|
48
|
+
: buf.slice(0, 3).toString('ascii') === 'GIF' ? 'gif'
|
|
49
|
+
: buf.readUInt16BE(0) === 0xffd8 ? 'jpg'
|
|
50
|
+
: path.extname(this.file).slice(1).toLowerCase() || 'png';
|
|
54
51
|
|
|
55
52
|
if (this.format !== 'png') {
|
|
56
|
-
return this.toPNG(buf)
|
|
53
|
+
return this.toPNG(buf);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
chunks = this.parseRaw(buf)
|
|
60
|
-
idat = this.parseChunks(chunks)
|
|
61
|
-
pixels = this.parseLines(idat)
|
|
56
|
+
chunks = this.parseRaw(buf);
|
|
57
|
+
idat = this.parseChunks(chunks);
|
|
58
|
+
pixels = this.parseLines(idat);
|
|
62
59
|
|
|
63
|
-
this.bmp = this.createBitmap(pixels)
|
|
64
|
-
this.cellmap = this.createCellmap(this.bmp)
|
|
65
|
-
this.frames = this.compileFrames(this.frames)
|
|
60
|
+
this.bmp = this.createBitmap(pixels);
|
|
61
|
+
this.cellmap = this.createCellmap(this.bmp);
|
|
62
|
+
this.frames = this.compileFrames(this.frames);
|
|
66
63
|
}
|
|
67
64
|
|
|
68
|
-
PNG.prototype.parseRaw = function
|
|
69
|
-
|
|
70
|
-
index = 0
|
|
71
|
-
i = 0
|
|
72
|
-
len
|
|
73
|
-
type
|
|
74
|
-
name
|
|
75
|
-
data
|
|
76
|
-
crc
|
|
77
|
-
check
|
|
78
|
-
critical
|
|
79
|
-
public_
|
|
80
|
-
conforming
|
|
81
|
-
copysafe
|
|
82
|
-
pos
|
|
83
|
-
|
|
84
|
-
this._debug(this.file)
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
) {
|
|
90
|
-
throw new Error('bad header')
|
|
65
|
+
PNG.prototype.parseRaw = function(buf) {
|
|
66
|
+
var chunks = []
|
|
67
|
+
, index = 0
|
|
68
|
+
, i = 0
|
|
69
|
+
, len
|
|
70
|
+
, type
|
|
71
|
+
, name
|
|
72
|
+
, data
|
|
73
|
+
, crc
|
|
74
|
+
, check
|
|
75
|
+
, critical
|
|
76
|
+
, public_
|
|
77
|
+
, conforming
|
|
78
|
+
, copysafe
|
|
79
|
+
, pos;
|
|
80
|
+
|
|
81
|
+
this._debug(this.file);
|
|
82
|
+
|
|
83
|
+
if (buf.readUInt32BE(0) !== 0x89504e47
|
|
84
|
+
|| buf.readUInt32BE(4) !== 0x0d0a1a0a) {
|
|
85
|
+
throw new Error('bad header');
|
|
91
86
|
}
|
|
92
87
|
|
|
93
|
-
i += 8
|
|
88
|
+
i += 8;
|
|
94
89
|
|
|
95
90
|
while (i < buf.length) {
|
|
96
91
|
try {
|
|
97
|
-
len = buf.readUInt32BE(i)
|
|
98
|
-
i += 4
|
|
99
|
-
pos = i
|
|
100
|
-
type = buf.slice(i, i + 4)
|
|
101
|
-
name = type.toString('ascii')
|
|
102
|
-
i += 4
|
|
103
|
-
data = buf.slice(i, i + len)
|
|
104
|
-
i += len
|
|
105
|
-
check = this.crc32(buf.slice(pos, i))
|
|
106
|
-
crc = buf.readInt32BE(i)
|
|
107
|
-
i += 4
|
|
108
|
-
critical = !!(~type[0] & 32)
|
|
109
|
-
public_ = !!(~type[1] & 32)
|
|
110
|
-
conforming = !!(~type[2] & 32)
|
|
111
|
-
copysafe = !!(~type[3] & 32)
|
|
92
|
+
len = buf.readUInt32BE(i);
|
|
93
|
+
i += 4;
|
|
94
|
+
pos = i;
|
|
95
|
+
type = buf.slice(i, i + 4);
|
|
96
|
+
name = type.toString('ascii');
|
|
97
|
+
i += 4;
|
|
98
|
+
data = buf.slice(i, i + len);
|
|
99
|
+
i += len;
|
|
100
|
+
check = this.crc32(buf.slice(pos, i));
|
|
101
|
+
crc = buf.readInt32BE(i);
|
|
102
|
+
i += 4;
|
|
103
|
+
critical = !!(~type[0] & 32);
|
|
104
|
+
public_ = !!(~type[1] & 32);
|
|
105
|
+
conforming = !!(~type[2] & 32);
|
|
106
|
+
copysafe = !!(~type[3] & 32);
|
|
112
107
|
if (crc !== check) {
|
|
113
|
-
throw new Error(name + ': bad crc')
|
|
108
|
+
throw new Error(name + ': bad crc');
|
|
114
109
|
}
|
|
115
110
|
} catch (e) {
|
|
116
|
-
if (this.options.debug)
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
break
|
|
111
|
+
if (this.options.debug) throw e;
|
|
112
|
+
break;
|
|
120
113
|
}
|
|
121
114
|
chunks.push({
|
|
122
115
|
index: index++,
|
|
@@ -136,355 +129,308 @@ PNG.prototype.parseRaw = function (buf) {
|
|
|
136
129
|
conforming: conforming,
|
|
137
130
|
copysafe: copysafe
|
|
138
131
|
}
|
|
139
|
-
})
|
|
132
|
+
});
|
|
140
133
|
}
|
|
141
134
|
|
|
142
|
-
return chunks
|
|
143
|
-
}
|
|
135
|
+
return chunks;
|
|
136
|
+
};
|
|
144
137
|
|
|
145
|
-
PNG.prototype.parseChunks = function
|
|
146
|
-
|
|
138
|
+
PNG.prototype.parseChunks = function(chunks) {
|
|
139
|
+
var i
|
|
140
|
+
, chunk
|
|
141
|
+
, name
|
|
142
|
+
, data
|
|
143
|
+
, p
|
|
144
|
+
, idat
|
|
145
|
+
, info;
|
|
147
146
|
|
|
148
147
|
for (i = 0; i < chunks.length; i++) {
|
|
149
|
-
chunk = chunks[i]
|
|
150
|
-
name = chunk.id
|
|
151
|
-
data = chunk.data
|
|
152
|
-
info = {}
|
|
148
|
+
chunk = chunks[i];
|
|
149
|
+
name = chunk.id;
|
|
150
|
+
data = chunk.data;
|
|
151
|
+
info = {};
|
|
153
152
|
switch (name) {
|
|
154
153
|
case 'ihdr': {
|
|
155
|
-
this.width = info.width = data.readUInt32BE(0)
|
|
156
|
-
this.height = info.height = data.readUInt32BE(4)
|
|
157
|
-
this.bitDepth = info.bitDepth = data.readUInt8(8)
|
|
158
|
-
this.colorType = info.colorType = data.readUInt8(9)
|
|
159
|
-
this.compression = info.compression = data.readUInt8(10)
|
|
160
|
-
this.filter = info.filter = data.readUInt8(11)
|
|
161
|
-
this.interlace = info.interlace = data.readUInt8(12)
|
|
154
|
+
this.width = info.width = data.readUInt32BE(0);
|
|
155
|
+
this.height = info.height = data.readUInt32BE(4);
|
|
156
|
+
this.bitDepth = info.bitDepth = data.readUInt8(8);
|
|
157
|
+
this.colorType = info.colorType = data.readUInt8(9);
|
|
158
|
+
this.compression = info.compression = data.readUInt8(10);
|
|
159
|
+
this.filter = info.filter = data.readUInt8(11);
|
|
160
|
+
this.interlace = info.interlace = data.readUInt8(12);
|
|
162
161
|
switch (this.bitDepth) {
|
|
163
|
-
case 1:
|
|
164
|
-
|
|
165
|
-
case 4:
|
|
166
|
-
case 8:
|
|
167
|
-
case 16:
|
|
168
|
-
case 24:
|
|
169
|
-
case 32:
|
|
170
|
-
break
|
|
171
|
-
default:
|
|
172
|
-
throw new Error('bad bit depth: ' + this.bitDepth)
|
|
162
|
+
case 1: case 2: case 4: case 8: case 16: case 24: case 32: break;
|
|
163
|
+
default: throw new Error('bad bit depth: ' + this.bitDepth);
|
|
173
164
|
}
|
|
174
165
|
switch (this.colorType) {
|
|
175
|
-
case 0:
|
|
176
|
-
|
|
177
|
-
case 3:
|
|
178
|
-
case 4:
|
|
179
|
-
case 6:
|
|
180
|
-
break
|
|
181
|
-
default:
|
|
182
|
-
throw new Error('bad color: ' + this.colorType)
|
|
166
|
+
case 0: case 2: case 3: case 4: case 6: break;
|
|
167
|
+
default: throw new Error('bad color: ' + this.colorType);
|
|
183
168
|
}
|
|
184
169
|
switch (this.compression) {
|
|
185
|
-
case 0:
|
|
186
|
-
|
|
187
|
-
default:
|
|
188
|
-
throw new Error('bad compression: ' + this.compression)
|
|
170
|
+
case 0: break;
|
|
171
|
+
default: throw new Error('bad compression: ' + this.compression);
|
|
189
172
|
}
|
|
190
173
|
switch (this.filter) {
|
|
191
|
-
case 0:
|
|
192
|
-
|
|
193
|
-
case 2:
|
|
194
|
-
case 3:
|
|
195
|
-
case 4:
|
|
196
|
-
break
|
|
197
|
-
default:
|
|
198
|
-
throw new Error('bad filter: ' + this.filter)
|
|
174
|
+
case 0: case 1: case 2: case 3: case 4: break;
|
|
175
|
+
default: throw new Error('bad filter: ' + this.filter);
|
|
199
176
|
}
|
|
200
177
|
switch (this.interlace) {
|
|
201
|
-
case 0:
|
|
202
|
-
|
|
203
|
-
break
|
|
204
|
-
default:
|
|
205
|
-
throw new Error('bad interlace: ' + this.interlace)
|
|
178
|
+
case 0: case 1: break;
|
|
179
|
+
default: throw new Error('bad interlace: ' + this.interlace);
|
|
206
180
|
}
|
|
207
|
-
break
|
|
181
|
+
break;
|
|
208
182
|
}
|
|
209
183
|
case 'plte': {
|
|
210
|
-
this.palette = info.palette = []
|
|
184
|
+
this.palette = info.palette = [];
|
|
211
185
|
for (p = 0; p < data.length; p += 3) {
|
|
212
186
|
this.palette.push({
|
|
213
187
|
r: data[p + 0],
|
|
214
188
|
g: data[p + 1],
|
|
215
189
|
b: data[p + 2],
|
|
216
190
|
a: 255
|
|
217
|
-
})
|
|
191
|
+
});
|
|
218
192
|
}
|
|
219
|
-
break
|
|
193
|
+
break;
|
|
220
194
|
}
|
|
221
195
|
case 'idat': {
|
|
222
|
-
this.size = this.size || 0
|
|
223
|
-
this.size += data.length
|
|
224
|
-
this.idat = this.idat || []
|
|
225
|
-
this.idat.push(data)
|
|
226
|
-
info.size = data.length
|
|
227
|
-
break
|
|
196
|
+
this.size = this.size || 0;
|
|
197
|
+
this.size += data.length;
|
|
198
|
+
this.idat = this.idat || [];
|
|
199
|
+
this.idat.push(data);
|
|
200
|
+
info.size = data.length;
|
|
201
|
+
break;
|
|
228
202
|
}
|
|
229
203
|
case 'iend': {
|
|
230
|
-
this.end = true
|
|
231
|
-
break
|
|
204
|
+
this.end = true;
|
|
205
|
+
break;
|
|
232
206
|
}
|
|
233
207
|
case 'trns': {
|
|
234
|
-
this.alpha = info.alpha = Array.prototype.slice.call(data)
|
|
208
|
+
this.alpha = info.alpha = Array.prototype.slice.call(data);
|
|
235
209
|
if (this.palette) {
|
|
236
210
|
for (p = 0; p < data.length; p++) {
|
|
237
|
-
if (!this.palette[p])
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
this.palette[p].a = data[p]
|
|
211
|
+
if (!this.palette[p]) break;
|
|
212
|
+
this.palette[p].a = data[p];
|
|
241
213
|
}
|
|
242
214
|
}
|
|
243
|
-
break
|
|
215
|
+
break;
|
|
244
216
|
}
|
|
245
217
|
// https://wiki.mozilla.org/APNG_Specification
|
|
246
218
|
case 'actl': {
|
|
247
|
-
this.actl = info = {}
|
|
248
|
-
this.frames = []
|
|
249
|
-
this.actl.numFrames = data.readUInt32BE(0)
|
|
250
|
-
this.actl.numPlays = data.readUInt32BE(4)
|
|
251
|
-
break
|
|
219
|
+
this.actl = info = {};
|
|
220
|
+
this.frames = [];
|
|
221
|
+
this.actl.numFrames = data.readUInt32BE(0);
|
|
222
|
+
this.actl.numPlays = data.readUInt32BE(4);
|
|
223
|
+
break;
|
|
252
224
|
}
|
|
253
225
|
case 'fctl': {
|
|
254
226
|
// IDAT is the first frame depending on the order:
|
|
255
227
|
// IDAT is a frame: acTL->fcTL->IDAT->[fcTL]->fdAT
|
|
256
228
|
// IDAT is not a frame: acTL->IDAT->[fcTL]->fdAT
|
|
257
229
|
if (!this.idat) {
|
|
258
|
-
this.idat = []
|
|
230
|
+
this.idat = [];
|
|
259
231
|
this.frames.push({
|
|
260
232
|
idat: true,
|
|
261
233
|
fctl: info,
|
|
262
234
|
fdat: this.idat
|
|
263
|
-
})
|
|
235
|
+
});
|
|
264
236
|
} else {
|
|
265
237
|
this.frames.push({
|
|
266
238
|
fctl: info,
|
|
267
239
|
fdat: []
|
|
268
|
-
})
|
|
240
|
+
});
|
|
269
241
|
}
|
|
270
|
-
info.sequenceNumber = data.readUInt32BE(0)
|
|
271
|
-
info.width = data.readUInt32BE(4)
|
|
272
|
-
info.height = data.readUInt32BE(8)
|
|
273
|
-
info.xOffset = data.readUInt32BE(12)
|
|
274
|
-
info.yOffset = data.readUInt32BE(16)
|
|
275
|
-
info.delayNum = data.readUInt16BE(20)
|
|
276
|
-
info.delayDen = data.readUInt16BE(22)
|
|
277
|
-
info.disposeOp = data.readUInt8(24)
|
|
278
|
-
info.blendOp = data.readUInt8(25)
|
|
279
|
-
break
|
|
242
|
+
info.sequenceNumber = data.readUInt32BE(0);
|
|
243
|
+
info.width = data.readUInt32BE(4);
|
|
244
|
+
info.height = data.readUInt32BE(8);
|
|
245
|
+
info.xOffset = data.readUInt32BE(12);
|
|
246
|
+
info.yOffset = data.readUInt32BE(16);
|
|
247
|
+
info.delayNum = data.readUInt16BE(20);
|
|
248
|
+
info.delayDen = data.readUInt16BE(22);
|
|
249
|
+
info.disposeOp = data.readUInt8(24);
|
|
250
|
+
info.blendOp = data.readUInt8(25);
|
|
251
|
+
break;
|
|
280
252
|
}
|
|
281
253
|
case 'fdat': {
|
|
282
|
-
info.sequenceNumber = data.readUInt32BE(0)
|
|
283
|
-
info.data = data.slice(4)
|
|
284
|
-
this.frames[this.frames.length - 1].fdat.push(info.data)
|
|
285
|
-
break
|
|
254
|
+
info.sequenceNumber = data.readUInt32BE(0);
|
|
255
|
+
info.data = data.slice(4);
|
|
256
|
+
this.frames[this.frames.length - 1].fdat.push(info.data);
|
|
257
|
+
break;
|
|
286
258
|
}
|
|
287
259
|
}
|
|
288
|
-
chunk.info = info
|
|
260
|
+
chunk.info = info;
|
|
289
261
|
}
|
|
290
262
|
|
|
291
|
-
this._debug(chunks)
|
|
263
|
+
this._debug(chunks);
|
|
292
264
|
|
|
293
265
|
if (this.frames) {
|
|
294
|
-
this.frames = this.frames.map(function
|
|
295
|
-
frame.fdat = this.decompress(frame.fdat)
|
|
296
|
-
if (!frame.fdat.length)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return frame
|
|
300
|
-
}, this)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
idat = this.decompress(this.idat)
|
|
304
|
-
if (!idat.length) {
|
|
305
|
-
throw new Error('no data')
|
|
266
|
+
this.frames = this.frames.map(function(frame, i) {
|
|
267
|
+
frame.fdat = this.decompress(frame.fdat);
|
|
268
|
+
if (!frame.fdat.length) throw new Error('no data');
|
|
269
|
+
return frame;
|
|
270
|
+
}, this);
|
|
306
271
|
}
|
|
307
272
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
273
|
+
idat = this.decompress(this.idat);
|
|
274
|
+
if (!idat.length) throw new Error('no data');
|
|
275
|
+
|
|
276
|
+
return idat;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
PNG.prototype.parseLines = function(data) {
|
|
280
|
+
var pixels = []
|
|
281
|
+
, x
|
|
282
|
+
, p
|
|
283
|
+
, prior
|
|
284
|
+
, line
|
|
285
|
+
, filter
|
|
286
|
+
, samples
|
|
287
|
+
, pendingSamples
|
|
288
|
+
, ch
|
|
289
|
+
, shiftStart
|
|
290
|
+
, i
|
|
291
|
+
, toShift
|
|
292
|
+
, sample;
|
|
325
293
|
|
|
326
294
|
this.sampleDepth =
|
|
327
|
-
this.colorType === 0
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
340
|
-
this.
|
|
341
|
-
(this.width * this.bitsPerPixel) / 8 -
|
|
342
|
-
(((this.width * this.bitsPerPixel) / 8) | 0)
|
|
343
|
-
this.byteWidth = Math.ceil(this.width * (this.bitsPerPixel / 8))
|
|
344
|
-
|
|
345
|
-
this.shiftStart =
|
|
346
|
-
(this.bitDepth + (8 / this.bitDepth - this.bitDepth) - 1) | 0
|
|
347
|
-
this.shiftMult = this.bitDepth >= 8 ? 0 : this.bitDepth
|
|
348
|
-
this.mask = this.bitDepth === 32 ? 0xffffffff : (1 << this.bitDepth) - 1
|
|
295
|
+
this.colorType === 0 ? 1
|
|
296
|
+
: this.colorType === 2 ? 3
|
|
297
|
+
: this.colorType === 3 ? 1
|
|
298
|
+
: this.colorType === 4 ? 2
|
|
299
|
+
: this.colorType === 6 ? 4
|
|
300
|
+
: 1;
|
|
301
|
+
this.bitsPerPixel = this.bitDepth * this.sampleDepth;
|
|
302
|
+
this.bytesPerPixel = Math.ceil(this.bitsPerPixel / 8);
|
|
303
|
+
this.wastedBits = ((this.width * this.bitsPerPixel) / 8) - ((this.width * this.bitsPerPixel / 8) | 0);
|
|
304
|
+
this.byteWidth = Math.ceil(this.width * (this.bitsPerPixel / 8));
|
|
305
|
+
|
|
306
|
+
this.shiftStart = ((this.bitDepth + (8 / this.bitDepth - this.bitDepth)) - 1) | 0;
|
|
307
|
+
this.shiftMult = this.bitDepth >= 8 ? 0 : this.bitDepth;
|
|
308
|
+
this.mask = this.bitDepth === 32 ? 0xffffffff : (1 << this.bitDepth) - 1;
|
|
349
309
|
|
|
350
310
|
if (this.interlace === 1) {
|
|
351
|
-
samples = this.sampleInterlacedLines(data)
|
|
311
|
+
samples = this.sampleInterlacedLines(data);
|
|
352
312
|
for (i = 0; i < samples.length; i += this.sampleDepth) {
|
|
353
|
-
pixels.push(samples.slice(i, i + this.sampleDepth))
|
|
313
|
+
pixels.push(samples.slice(i, i + this.sampleDepth));
|
|
354
314
|
}
|
|
355
|
-
return pixels
|
|
315
|
+
return pixels;
|
|
356
316
|
}
|
|
357
317
|
|
|
358
318
|
for (p = 0; p < data.length; p += this.byteWidth) {
|
|
359
|
-
prior = line || []
|
|
360
|
-
filter = data[p++]
|
|
361
|
-
line = data.slice(p, p + this.byteWidth)
|
|
362
|
-
line = this.unfilterLine(filter, line, prior)
|
|
363
|
-
samples = this.sampleLine(line)
|
|
319
|
+
prior = line || [];
|
|
320
|
+
filter = data[p++];
|
|
321
|
+
line = data.slice(p, p + this.byteWidth);
|
|
322
|
+
line = this.unfilterLine(filter, line, prior);
|
|
323
|
+
samples = this.sampleLine(line);
|
|
364
324
|
for (i = 0; i < samples.length; i += this.sampleDepth) {
|
|
365
|
-
pixels.push(samples.slice(i, i + this.sampleDepth))
|
|
325
|
+
pixels.push(samples.slice(i, i + this.sampleDepth));
|
|
366
326
|
}
|
|
367
327
|
}
|
|
368
328
|
|
|
369
|
-
return pixels
|
|
370
|
-
}
|
|
329
|
+
return pixels;
|
|
330
|
+
};
|
|
371
331
|
|
|
372
|
-
PNG.prototype.unfilterLine = function
|
|
373
|
-
for (
|
|
332
|
+
PNG.prototype.unfilterLine = function(filter, line, prior) {
|
|
333
|
+
for (var x = 0; x < line.length; x++) {
|
|
374
334
|
if (filter === 0) {
|
|
375
|
-
break
|
|
335
|
+
break;
|
|
376
336
|
} else if (filter === 1) {
|
|
377
|
-
line[x] = this.filters.sub(x, line, prior, this.bytesPerPixel)
|
|
337
|
+
line[x] = this.filters.sub(x, line, prior, this.bytesPerPixel);
|
|
378
338
|
} else if (filter === 2) {
|
|
379
|
-
line[x] = this.filters.up(x, line, prior, this.bytesPerPixel)
|
|
339
|
+
line[x] = this.filters.up(x, line, prior, this.bytesPerPixel);
|
|
380
340
|
} else if (filter === 3) {
|
|
381
|
-
line[x] = this.filters.average(x, line, prior, this.bytesPerPixel)
|
|
341
|
+
line[x] = this.filters.average(x, line, prior, this.bytesPerPixel);
|
|
382
342
|
} else if (filter === 4) {
|
|
383
|
-
line[x] = this.filters.paeth(x, line, prior, this.bytesPerPixel)
|
|
343
|
+
line[x] = this.filters.paeth(x, line, prior, this.bytesPerPixel);
|
|
384
344
|
}
|
|
385
345
|
}
|
|
386
|
-
return line
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
PNG.prototype.sampleLine = function
|
|
390
|
-
|
|
391
|
-
x = 0
|
|
392
|
-
pendingSamples
|
|
393
|
-
ch
|
|
394
|
-
i
|
|
395
|
-
sample
|
|
396
|
-
shiftStart
|
|
397
|
-
toShift
|
|
346
|
+
return line;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
PNG.prototype.sampleLine = function(line, width) {
|
|
350
|
+
var samples = []
|
|
351
|
+
, x = 0
|
|
352
|
+
, pendingSamples
|
|
353
|
+
, ch
|
|
354
|
+
, i
|
|
355
|
+
, sample
|
|
356
|
+
, shiftStart
|
|
357
|
+
, toShift;
|
|
398
358
|
|
|
399
359
|
while (x < line.length) {
|
|
400
|
-
pendingSamples = this.sampleDepth
|
|
360
|
+
pendingSamples = this.sampleDepth;
|
|
401
361
|
while (pendingSamples--) {
|
|
402
|
-
ch = line[x]
|
|
362
|
+
ch = line[x];
|
|
403
363
|
if (this.bitDepth === 16) {
|
|
404
|
-
ch = (ch << 8) | line[++x]
|
|
364
|
+
ch = (ch << 8) | line[++x];
|
|
405
365
|
} else if (this.bitDepth === 24) {
|
|
406
|
-
ch = (ch << 16) | (line[++x] << 8) | line[++x]
|
|
366
|
+
ch = (ch << 16) | (line[++x] << 8) | line[++x];
|
|
407
367
|
} else if (this.bitDepth === 32) {
|
|
408
|
-
ch = (ch << 24) | (line[++x] << 16) | (line[++x] << 8) | line[++x]
|
|
368
|
+
ch = (ch << 24) | (line[++x] << 16) | (line[++x] << 8) | line[++x];
|
|
409
369
|
} else if (this.bitDepth > 32) {
|
|
410
|
-
throw new Error('bitDepth ' + this.bitDepth + ' unsupported.')
|
|
370
|
+
throw new Error('bitDepth ' + this.bitDepth + ' unsupported.');
|
|
411
371
|
}
|
|
412
|
-
shiftStart = this.shiftStart
|
|
413
|
-
toShift = shiftStart - (x === line.length - 1 ? this.wastedBits : 0)
|
|
372
|
+
shiftStart = this.shiftStart;
|
|
373
|
+
toShift = shiftStart - (x === line.length - 1 ? this.wastedBits : 0);
|
|
414
374
|
for (i = 0; i <= toShift; i++) {
|
|
415
|
-
sample = (ch >> (this.shiftMult * shiftStart)) & this.mask
|
|
375
|
+
sample = (ch >> (this.shiftMult * shiftStart)) & this.mask;
|
|
416
376
|
if (this.colorType !== 3) {
|
|
417
|
-
if (this.bitDepth < 8) {
|
|
418
|
-
// <= 8 would work too, doesn't matter
|
|
377
|
+
if (this.bitDepth < 8) { // <= 8 would work too, doesn't matter
|
|
419
378
|
// sample = sample * (0xff / this.mask) | 0; // would work too
|
|
420
|
-
sample *= 0xff / this.mask
|
|
421
|
-
sample |= 0
|
|
379
|
+
sample *= 0xff / this.mask;
|
|
380
|
+
sample |= 0;
|
|
422
381
|
} else if (this.bitDepth > 8) {
|
|
423
|
-
sample = (
|
|
382
|
+
sample = (sample / this.mask) * 255 | 0;
|
|
424
383
|
}
|
|
425
384
|
}
|
|
426
|
-
samples.push(sample)
|
|
427
|
-
shiftStart
|
|
385
|
+
samples.push(sample);
|
|
386
|
+
shiftStart--;
|
|
428
387
|
}
|
|
429
|
-
x
|
|
388
|
+
x++;
|
|
430
389
|
}
|
|
431
390
|
}
|
|
432
391
|
|
|
433
392
|
// Needed for deinterlacing?
|
|
434
393
|
if (width != null) {
|
|
435
|
-
samples = samples.slice(0, width * this.sampleDepth)
|
|
394
|
+
samples = samples.slice(0, width * this.sampleDepth);
|
|
436
395
|
}
|
|
437
396
|
|
|
438
|
-
return samples
|
|
439
|
-
}
|
|
397
|
+
return samples;
|
|
398
|
+
};
|
|
440
399
|
|
|
441
400
|
// http://www.w3.org/TR/PNG-Filters.html
|
|
442
401
|
PNG.prototype.filters = {
|
|
443
402
|
sub: function Sub(x, line, prior, bpp) {
|
|
444
|
-
if (x < bpp)
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
return (line[x] + line[x - bpp]) % 256
|
|
403
|
+
if (x < bpp) return line[x];
|
|
404
|
+
return (line[x] + line[x - bpp]) % 256;
|
|
448
405
|
},
|
|
449
406
|
up: function Up(x, line, prior, bpp) {
|
|
450
|
-
return (line[x] + (prior[x] || 0)) % 256
|
|
407
|
+
return (line[x] + (prior[x] || 0)) % 256;
|
|
451
408
|
},
|
|
452
409
|
average: function Average(x, line, prior, bpp) {
|
|
453
|
-
if (x < bpp)
|
|
454
|
-
return Math.floor((prior[x] || 0) / 2)
|
|
455
|
-
}
|
|
410
|
+
if (x < bpp) return Math.floor((prior[x] || 0) / 2);
|
|
456
411
|
// if (x < bpp) return (prior[x] || 0) >> 1;
|
|
457
|
-
return (
|
|
458
|
-
|
|
412
|
+
return (line[x]
|
|
413
|
+
+ Math.floor((line[x - bpp] + prior[x]) / 2)
|
|
459
414
|
// + ((line[x - bpp] + prior[x]) >> 1)
|
|
460
|
-
|
|
461
|
-
)
|
|
415
|
+
) % 256;
|
|
462
416
|
},
|
|
463
417
|
paeth: function Paeth(x, line, prior, bpp) {
|
|
464
|
-
if (x < bpp)
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
(line[x] +
|
|
469
|
-
this._predictor(line[x - bpp], prior[x] || 0, prior[x - bpp] || 0)) %
|
|
470
|
-
256
|
|
471
|
-
)
|
|
418
|
+
if (x < bpp) return prior[x] || 0;
|
|
419
|
+
return (line[x] + this._predictor(
|
|
420
|
+
line[x - bpp], prior[x] || 0, prior[x - bpp] || 0
|
|
421
|
+
)) % 256;
|
|
472
422
|
},
|
|
473
423
|
_predictor: function PaethPredictor(a, b, c) {
|
|
474
424
|
// a = left, b = above, c = upper left
|
|
475
|
-
|
|
476
|
-
pa = Math.abs(p - a)
|
|
477
|
-
pb = Math.abs(p - b)
|
|
478
|
-
pc = Math.abs(p - c)
|
|
479
|
-
if (pa <= pb && pa <= pc)
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (pb <= pc) {
|
|
483
|
-
return b
|
|
484
|
-
}
|
|
485
|
-
return c
|
|
425
|
+
var p = a + b - c
|
|
426
|
+
, pa = Math.abs(p - a)
|
|
427
|
+
, pb = Math.abs(p - b)
|
|
428
|
+
, pc = Math.abs(p - c);
|
|
429
|
+
if (pa <= pb && pa <= pc) return a;
|
|
430
|
+
if (pb <= pc) return b;
|
|
431
|
+
return c;
|
|
486
432
|
}
|
|
487
|
-
}
|
|
433
|
+
};
|
|
488
434
|
|
|
489
435
|
/**
|
|
490
436
|
* Adam7 deinterlacing ported to javascript from PyPNG:
|
|
@@ -513,32 +459,32 @@ PNG.prototype.filters = {
|
|
|
513
459
|
* SOFTWARE.
|
|
514
460
|
*/
|
|
515
461
|
|
|
516
|
-
PNG.prototype.sampleInterlacedLines = function
|
|
517
|
-
|
|
518
|
-
vpr
|
|
519
|
-
samples
|
|
520
|
-
source_offset
|
|
521
|
-
i
|
|
522
|
-
pass
|
|
523
|
-
xstart
|
|
524
|
-
ystart
|
|
525
|
-
xstep
|
|
526
|
-
ystep
|
|
527
|
-
recon
|
|
528
|
-
ppr
|
|
529
|
-
row_size
|
|
530
|
-
y
|
|
531
|
-
filter_type
|
|
532
|
-
scanline
|
|
533
|
-
flat
|
|
534
|
-
offset
|
|
535
|
-
end_offset
|
|
536
|
-
skip
|
|
537
|
-
j
|
|
538
|
-
k
|
|
539
|
-
f
|
|
540
|
-
|
|
541
|
-
|
|
462
|
+
PNG.prototype.sampleInterlacedLines = function(raw) {
|
|
463
|
+
var psize
|
|
464
|
+
, vpr
|
|
465
|
+
, samples
|
|
466
|
+
, source_offset
|
|
467
|
+
, i
|
|
468
|
+
, pass
|
|
469
|
+
, xstart
|
|
470
|
+
, ystart
|
|
471
|
+
, xstep
|
|
472
|
+
, ystep
|
|
473
|
+
, recon
|
|
474
|
+
, ppr
|
|
475
|
+
, row_size
|
|
476
|
+
, y
|
|
477
|
+
, filter_type
|
|
478
|
+
, scanline
|
|
479
|
+
, flat
|
|
480
|
+
, offset
|
|
481
|
+
, end_offset
|
|
482
|
+
, skip
|
|
483
|
+
, j
|
|
484
|
+
, k
|
|
485
|
+
, f;
|
|
486
|
+
|
|
487
|
+
var adam7 = [
|
|
542
488
|
[0, 0, 8, 8],
|
|
543
489
|
[4, 0, 8, 8],
|
|
544
490
|
[0, 4, 4, 8],
|
|
@@ -546,637 +492,591 @@ PNG.prototype.sampleInterlacedLines = function (raw) {
|
|
|
546
492
|
[0, 2, 2, 4],
|
|
547
493
|
[1, 0, 2, 2],
|
|
548
494
|
[0, 1, 1, 2]
|
|
549
|
-
]
|
|
495
|
+
];
|
|
550
496
|
|
|
551
497
|
// Fractional bytes per pixel
|
|
552
|
-
psize = (this.bitDepth / 8) * this.sampleDepth
|
|
498
|
+
psize = (this.bitDepth / 8) * this.sampleDepth;
|
|
553
499
|
|
|
554
500
|
// Values per row (of the target image)
|
|
555
|
-
vpr = this.width * this.sampleDepth
|
|
501
|
+
vpr = this.width * this.sampleDepth;
|
|
556
502
|
|
|
557
503
|
// Make a result array, and make it big enough. Interleaving
|
|
558
504
|
// writes to the output array randomly (well, not quite), so the
|
|
559
505
|
// entire output array must be in memory.
|
|
560
|
-
samples = new Buffer(vpr * this.height)
|
|
561
|
-
samples.fill(0)
|
|
506
|
+
samples = new Buffer(vpr * this.height);
|
|
507
|
+
samples.fill(0);
|
|
562
508
|
|
|
563
|
-
source_offset = 0
|
|
509
|
+
source_offset = 0;
|
|
564
510
|
|
|
565
511
|
for (i = 0; i < adam7.length; i++) {
|
|
566
|
-
pass = adam7[i]
|
|
567
|
-
xstart = pass[0]
|
|
568
|
-
ystart = pass[1]
|
|
569
|
-
xstep = pass[2]
|
|
570
|
-
ystep = pass[3]
|
|
571
|
-
if (xstart >= this.width)
|
|
572
|
-
continue
|
|
573
|
-
}
|
|
512
|
+
pass = adam7[i];
|
|
513
|
+
xstart = pass[0];
|
|
514
|
+
ystart = pass[1];
|
|
515
|
+
xstep = pass[2];
|
|
516
|
+
ystep = pass[3];
|
|
517
|
+
if (xstart >= this.width) continue;
|
|
574
518
|
// The previous (reconstructed) scanline. Empty array at the
|
|
575
519
|
// beginning of a pass to indicate that there is no previous
|
|
576
520
|
// line.
|
|
577
|
-
recon = []
|
|
521
|
+
recon = [];
|
|
578
522
|
// Pixels per row (reduced pass image)
|
|
579
|
-
ppr = Math.ceil((this.width - xstart) / xstep)
|
|
523
|
+
ppr = Math.ceil((this.width - xstart) / xstep);
|
|
580
524
|
// Row size in bytes for this pass.
|
|
581
|
-
row_size = Math.ceil(psize * ppr)
|
|
525
|
+
row_size = Math.ceil(psize * ppr);
|
|
582
526
|
for (y = ystart; y < this.height; y += ystep) {
|
|
583
|
-
filter_type = raw[source_offset]
|
|
584
|
-
source_offset += 1
|
|
585
|
-
scanline = raw.slice(source_offset, source_offset + row_size)
|
|
586
|
-
source_offset += row_size
|
|
587
|
-
recon = this.unfilterLine(filter_type, scanline, recon)
|
|
527
|
+
filter_type = raw[source_offset];
|
|
528
|
+
source_offset += 1;
|
|
529
|
+
scanline = raw.slice(source_offset, source_offset + row_size);
|
|
530
|
+
source_offset += row_size;
|
|
531
|
+
recon = this.unfilterLine(filter_type, scanline, recon);
|
|
588
532
|
// Convert so that there is one element per pixel value
|
|
589
|
-
flat = this.sampleLine(recon, ppr)
|
|
533
|
+
flat = this.sampleLine(recon, ppr);
|
|
590
534
|
if (xstep === 1) {
|
|
591
|
-
assert.equal(xstart, 0)
|
|
592
|
-
offset = y * vpr
|
|
535
|
+
assert.equal(xstart, 0);
|
|
536
|
+
offset = y * vpr;
|
|
593
537
|
for (k = offset, f = 0; k < offset + vpr; k++, f++) {
|
|
594
|
-
samples[k] = flat[f]
|
|
538
|
+
samples[k] = flat[f];
|
|
595
539
|
}
|
|
596
540
|
} else {
|
|
597
|
-
offset = y * vpr + xstart * this.sampleDepth
|
|
598
|
-
end_offset = (y + 1) * vpr
|
|
599
|
-
skip = this.sampleDepth * xstep
|
|
541
|
+
offset = y * vpr + xstart * this.sampleDepth;
|
|
542
|
+
end_offset = (y + 1) * vpr;
|
|
543
|
+
skip = this.sampleDepth * xstep;
|
|
600
544
|
for (j = 0; j < this.sampleDepth; j++) {
|
|
601
|
-
for (
|
|
602
|
-
k =
|
|
603
|
-
k < end_offset;
|
|
604
|
-
k += skip, f += this.sampleDepth
|
|
605
|
-
) {
|
|
606
|
-
samples[k] = flat[f]
|
|
545
|
+
for (k = offset + j, f = j; k < end_offset; k += skip, f += this.sampleDepth) {
|
|
546
|
+
samples[k] = flat[f];
|
|
607
547
|
}
|
|
608
548
|
}
|
|
609
549
|
}
|
|
610
550
|
}
|
|
611
551
|
}
|
|
612
552
|
|
|
613
|
-
return samples
|
|
614
|
-
}
|
|
553
|
+
return samples;
|
|
554
|
+
};
|
|
615
555
|
|
|
616
|
-
PNG.prototype.createBitmap = function
|
|
617
|
-
|
|
618
|
-
i
|
|
556
|
+
PNG.prototype.createBitmap = function(pixels) {
|
|
557
|
+
var bmp = []
|
|
558
|
+
, i;
|
|
619
559
|
|
|
620
560
|
if (this.colorType === 0) {
|
|
621
|
-
pixels = pixels.map(function
|
|
622
|
-
return { r: sample[0], g: sample[0], b: sample[0], a: 255 }
|
|
623
|
-
})
|
|
561
|
+
pixels = pixels.map(function(sample) {
|
|
562
|
+
return { r: sample[0], g: sample[0], b: sample[0], a: 255 };
|
|
563
|
+
});
|
|
624
564
|
} else if (this.colorType === 2) {
|
|
625
|
-
pixels = pixels.map(function
|
|
626
|
-
return { r: sample[0], g: sample[1], b: sample[2], a: 255 }
|
|
627
|
-
})
|
|
565
|
+
pixels = pixels.map(function(sample) {
|
|
566
|
+
return { r: sample[0], g: sample[1], b: sample[2], a: 255 };
|
|
567
|
+
});
|
|
628
568
|
} else if (this.colorType === 3) {
|
|
629
|
-
pixels = pixels.map(function
|
|
630
|
-
if (!this.palette[sample[0]])
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
return this.palette[sample[0]]
|
|
634
|
-
}, this)
|
|
569
|
+
pixels = pixels.map(function(sample) {
|
|
570
|
+
if (!this.palette[sample[0]]) throw new Error('bad palette index');
|
|
571
|
+
return this.palette[sample[0]];
|
|
572
|
+
}, this);
|
|
635
573
|
} else if (this.colorType === 4) {
|
|
636
|
-
pixels = pixels.map(function
|
|
637
|
-
return { r: sample[0], g: sample[0], b: sample[0], a: sample[1] }
|
|
638
|
-
})
|
|
574
|
+
pixels = pixels.map(function(sample) {
|
|
575
|
+
return { r: sample[0], g: sample[0], b: sample[0], a: sample[1] };
|
|
576
|
+
});
|
|
639
577
|
} else if (this.colorType === 6) {
|
|
640
|
-
pixels = pixels.map(function
|
|
641
|
-
return { r: sample[0], g: sample[1], b: sample[2], a: sample[3] }
|
|
642
|
-
})
|
|
578
|
+
pixels = pixels.map(function(sample) {
|
|
579
|
+
return { r: sample[0], g: sample[1], b: sample[2], a: sample[3] };
|
|
580
|
+
});
|
|
643
581
|
}
|
|
644
582
|
|
|
645
583
|
for (i = 0; i < pixels.length; i += this.width) {
|
|
646
|
-
bmp.push(pixels.slice(i, i + this.width))
|
|
584
|
+
bmp.push(pixels.slice(i, i + this.width));
|
|
647
585
|
}
|
|
648
586
|
|
|
649
|
-
return bmp
|
|
650
|
-
}
|
|
587
|
+
return bmp;
|
|
588
|
+
};
|
|
651
589
|
|
|
652
|
-
PNG.prototype.createCellmap = function
|
|
590
|
+
PNG.prototype.createCellmap = function(bmp, options) {
|
|
653
591
|
bmp = bmp || this.bmp
|
|
654
592
|
options = options || this.options
|
|
655
|
-
|
|
656
|
-
scale = options.scale || 0.
|
|
657
|
-
height = bmp.length
|
|
658
|
-
width = bmp[0].length
|
|
659
|
-
cmwidth = options.width
|
|
660
|
-
cmheight = options.height
|
|
661
|
-
line
|
|
662
|
-
x
|
|
663
|
-
y
|
|
664
|
-
xx
|
|
665
|
-
yy
|
|
666
|
-
xs
|
|
667
|
-
ys
|
|
593
|
+
var cellmap = []
|
|
594
|
+
, scale = options.scale || 0.20
|
|
595
|
+
, height = bmp.length
|
|
596
|
+
, width = bmp[0].length
|
|
597
|
+
, cmwidth = options.width
|
|
598
|
+
, cmheight = options.height
|
|
599
|
+
, line
|
|
600
|
+
, x
|
|
601
|
+
, y
|
|
602
|
+
, xx
|
|
603
|
+
, yy
|
|
604
|
+
, xs
|
|
605
|
+
, ys;
|
|
668
606
|
|
|
669
607
|
if (cmwidth) {
|
|
670
|
-
scale = cmwidth / width
|
|
608
|
+
scale = cmwidth / width;
|
|
671
609
|
} else if (cmheight) {
|
|
672
|
-
scale = cmheight / height
|
|
610
|
+
scale = cmheight / height;
|
|
673
611
|
}
|
|
674
612
|
|
|
675
613
|
if (!cmheight) {
|
|
676
|
-
cmheight = Math.round(height * scale)
|
|
614
|
+
cmheight = Math.round(height * scale);
|
|
677
615
|
}
|
|
678
616
|
|
|
679
617
|
if (!cmwidth) {
|
|
680
|
-
cmwidth = Math.round(width * scale)
|
|
618
|
+
cmwidth = Math.round(width * scale);
|
|
681
619
|
}
|
|
682
620
|
|
|
683
|
-
ys = height / cmheight
|
|
684
|
-
xs = width / cmwidth
|
|
621
|
+
ys = height / cmheight;
|
|
622
|
+
xs = width / cmwidth;
|
|
685
623
|
|
|
686
624
|
for (y = 0; y < bmp.length; y += ys) {
|
|
687
|
-
line = []
|
|
688
|
-
yy = Math.round(y)
|
|
689
|
-
if (!bmp[yy])
|
|
690
|
-
break
|
|
691
|
-
}
|
|
625
|
+
line = [];
|
|
626
|
+
yy = Math.round(y);
|
|
627
|
+
if (!bmp[yy]) break;
|
|
692
628
|
for (x = 0; x < bmp[yy].length; x += xs) {
|
|
693
|
-
xx = Math.round(x)
|
|
694
|
-
if (!bmp[yy][xx])
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
line.push(bmp[yy][xx])
|
|
629
|
+
xx = Math.round(x);
|
|
630
|
+
if (!bmp[yy][xx]) break;
|
|
631
|
+
line.push(bmp[yy][xx]);
|
|
698
632
|
}
|
|
699
|
-
cellmap.push(line)
|
|
633
|
+
cellmap.push(line);
|
|
700
634
|
}
|
|
701
635
|
|
|
702
|
-
return cellmap
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
PNG.prototype.renderANSI = function
|
|
706
|
-
|
|
707
|
-
out = ''
|
|
708
|
-
|
|
709
|
-
bmp.forEach(function
|
|
710
|
-
line.forEach(function
|
|
711
|
-
|
|
712
|
-
out += self.pixelToSGR(pixel, outch)
|
|
713
|
-
})
|
|
714
|
-
out += '\n'
|
|
715
|
-
})
|
|
716
|
-
|
|
717
|
-
return out
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
PNG.prototype.renderContent = function
|
|
721
|
-
|
|
722
|
-
out = ''
|
|
723
|
-
|
|
724
|
-
bmp.forEach(function
|
|
725
|
-
line.forEach(function
|
|
726
|
-
|
|
727
|
-
out += self.pixelToTags(pixel, outch)
|
|
728
|
-
})
|
|
729
|
-
out += '\n'
|
|
730
|
-
})
|
|
731
|
-
|
|
732
|
-
el.setContent(out)
|
|
733
|
-
|
|
734
|
-
return out
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
PNG.prototype.renderScreen = function
|
|
738
|
-
|
|
739
|
-
lines = screen.lines
|
|
740
|
-
cellLines
|
|
741
|
-
y
|
|
742
|
-
yy
|
|
743
|
-
x
|
|
744
|
-
xx
|
|
745
|
-
alpha
|
|
746
|
-
attr
|
|
747
|
-
ch
|
|
748
|
-
|
|
749
|
-
cellLines = bmp.reduce(function
|
|
750
|
-
|
|
751
|
-
line.forEach(function
|
|
752
|
-
|
|
753
|
-
cell = self.pixelToCell(pixel, outch)
|
|
754
|
-
cellLine.push(cell)
|
|
755
|
-
})
|
|
756
|
-
cellLines.push(cellLine)
|
|
757
|
-
return cellLines
|
|
758
|
-
}, [])
|
|
636
|
+
return cellmap;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
PNG.prototype.renderANSI = function(bmp) {
|
|
640
|
+
var self = this
|
|
641
|
+
, out = '';
|
|
642
|
+
|
|
643
|
+
bmp.forEach(function(line, y) {
|
|
644
|
+
line.forEach(function(pixel, x) {
|
|
645
|
+
var outch = self.getOutch(x, y, line, pixel);
|
|
646
|
+
out += self.pixelToSGR(pixel, outch);
|
|
647
|
+
});
|
|
648
|
+
out += '\n';
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
return out;
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
PNG.prototype.renderContent = function(bmp, el) {
|
|
655
|
+
var self = this
|
|
656
|
+
, out = '';
|
|
657
|
+
|
|
658
|
+
bmp.forEach(function(line, y) {
|
|
659
|
+
line.forEach(function(pixel, x) {
|
|
660
|
+
var outch = self.getOutch(x, y, line, pixel);
|
|
661
|
+
out += self.pixelToTags(pixel, outch);
|
|
662
|
+
});
|
|
663
|
+
out += '\n';
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
el.setContent(out);
|
|
667
|
+
|
|
668
|
+
return out;
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
PNG.prototype.renderScreen = function(bmp, screen, xi, xl, yi, yl) {
|
|
672
|
+
var self = this
|
|
673
|
+
, lines = screen.lines
|
|
674
|
+
, cellLines
|
|
675
|
+
, y
|
|
676
|
+
, yy
|
|
677
|
+
, x
|
|
678
|
+
, xx
|
|
679
|
+
, alpha
|
|
680
|
+
, attr
|
|
681
|
+
, ch;
|
|
682
|
+
|
|
683
|
+
cellLines = bmp.reduce(function(cellLines, line, y) {
|
|
684
|
+
var cellLine = [];
|
|
685
|
+
line.forEach(function(pixel, x) {
|
|
686
|
+
var outch = self.getOutch(x, y, line, pixel)
|
|
687
|
+
, cell = self.pixelToCell(pixel, outch);
|
|
688
|
+
cellLine.push(cell);
|
|
689
|
+
});
|
|
690
|
+
cellLines.push(cellLine);
|
|
691
|
+
return cellLines;
|
|
692
|
+
}, []);
|
|
759
693
|
|
|
760
694
|
for (y = yi; y < yl; y++) {
|
|
761
|
-
yy = y - yi
|
|
695
|
+
yy = y - yi;
|
|
762
696
|
for (x = xi; x < xl; x++) {
|
|
763
|
-
xx = x - xi
|
|
697
|
+
xx = x - xi;
|
|
764
698
|
if (lines[y] && lines[y][x] && cellLines[yy] && cellLines[yy][xx]) {
|
|
765
|
-
alpha = cellLines[yy][xx].pop()
|
|
699
|
+
alpha = cellLines[yy][xx].pop();
|
|
766
700
|
// completely transparent
|
|
767
701
|
if (alpha === 0.0) {
|
|
768
|
-
continue
|
|
702
|
+
continue;
|
|
769
703
|
}
|
|
770
704
|
// translucency / blending
|
|
771
705
|
if (alpha < 1.0) {
|
|
772
|
-
attr = cellLines[yy][xx][0]
|
|
773
|
-
ch = cellLines[yy][xx][1]
|
|
774
|
-
lines[y][x][0] = this.colors.blend(lines[y][x][0], attr, alpha)
|
|
775
|
-
if (ch !== ' ')
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
lines[y].dirty = true
|
|
779
|
-
continue
|
|
706
|
+
attr = cellLines[yy][xx][0];
|
|
707
|
+
ch = cellLines[yy][xx][1];
|
|
708
|
+
lines[y][x][0] = this.colors.blend(lines[y][x][0], attr, alpha);
|
|
709
|
+
if (ch !== ' ') lines[y][x][1] = ch;
|
|
710
|
+
lines[y].dirty = true;
|
|
711
|
+
continue;
|
|
780
712
|
}
|
|
781
713
|
// completely opaque
|
|
782
|
-
lines[y][x] = cellLines[yy][xx]
|
|
783
|
-
lines[y].dirty = true
|
|
714
|
+
lines[y][x] = cellLines[yy][xx];
|
|
715
|
+
lines[y].dirty = true;
|
|
784
716
|
}
|
|
785
717
|
}
|
|
786
718
|
}
|
|
787
|
-
}
|
|
719
|
+
};
|
|
788
720
|
|
|
789
|
-
PNG.prototype.renderElement = function
|
|
790
|
-
|
|
791
|
-
xl = el.aleft + el.width - el.iright
|
|
792
|
-
yi = el.atop + el.itop
|
|
793
|
-
yl = el.atop + el.height - el.ibottom
|
|
721
|
+
PNG.prototype.renderElement = function(bmp, el) {
|
|
722
|
+
var xi = el.aleft + el.ileft
|
|
723
|
+
, xl = el.aleft + el.width - el.iright
|
|
724
|
+
, yi = el.atop + el.itop
|
|
725
|
+
, yl = el.atop + el.height - el.ibottom;
|
|
794
726
|
|
|
795
|
-
return this.renderScreen(bmp, el.screen, xi, xl, yi, yl)
|
|
796
|
-
}
|
|
727
|
+
return this.renderScreen(bmp, el.screen, xi, xl, yi, yl);
|
|
728
|
+
};
|
|
797
729
|
|
|
798
|
-
PNG.prototype.pixelToSGR = function
|
|
799
|
-
|
|
800
|
-
fga = 0.5
|
|
801
|
-
a = pixel.a / 255
|
|
802
|
-
bg
|
|
803
|
-
fg
|
|
730
|
+
PNG.prototype.pixelToSGR = function(pixel, ch) {
|
|
731
|
+
var bga = 1.0
|
|
732
|
+
, fga = 0.5
|
|
733
|
+
, a = pixel.a / 255
|
|
734
|
+
, bg
|
|
735
|
+
, fg;
|
|
804
736
|
|
|
805
737
|
bg = this.colors.match(
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
)
|
|
738
|
+
pixel.r * a * bga | 0,
|
|
739
|
+
pixel.g * a * bga | 0,
|
|
740
|
+
pixel.b * a * bga | 0);
|
|
810
741
|
|
|
811
742
|
if (ch && this.options.ascii) {
|
|
812
743
|
fg = this.colors.match(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
)
|
|
744
|
+
pixel.r * a * fga | 0,
|
|
745
|
+
pixel.g * a * fga | 0,
|
|
746
|
+
pixel.b * a * fga | 0);
|
|
817
747
|
if (a === 0) {
|
|
818
|
-
return '\x1b[38;5;' + fg + 'm' + ch + '\x1b[m'
|
|
748
|
+
return '\x1b[38;5;' + fg + 'm' + ch + '\x1b[m';
|
|
819
749
|
}
|
|
820
|
-
return '\x1b[38;5;' + fg + 'm\x1b[48;5;' + bg + 'm' + ch + '\x1b[m'
|
|
750
|
+
return '\x1b[38;5;' + fg + 'm\x1b[48;5;' + bg + 'm' + ch + '\x1b[m';
|
|
821
751
|
}
|
|
822
752
|
|
|
823
|
-
if (a === 0)
|
|
824
|
-
return ' '
|
|
825
|
-
}
|
|
753
|
+
if (a === 0) return ' ';
|
|
826
754
|
|
|
827
|
-
return '\x1b[48;5;' + bg + 'm \x1b[m'
|
|
828
|
-
}
|
|
755
|
+
return '\x1b[48;5;' + bg + 'm \x1b[m';
|
|
756
|
+
};
|
|
829
757
|
|
|
830
|
-
PNG.prototype.pixelToTags = function
|
|
831
|
-
|
|
832
|
-
fga = 0.5
|
|
833
|
-
a = pixel.a / 255
|
|
834
|
-
bg
|
|
835
|
-
fg
|
|
758
|
+
PNG.prototype.pixelToTags = function(pixel, ch) {
|
|
759
|
+
var bga = 1.0
|
|
760
|
+
, fga = 0.5
|
|
761
|
+
, a = pixel.a / 255
|
|
762
|
+
, bg
|
|
763
|
+
, fg;
|
|
836
764
|
|
|
837
765
|
bg = this.colors.RGBtoHex(
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
)
|
|
766
|
+
pixel.r * a * bga | 0,
|
|
767
|
+
pixel.g * a * bga | 0,
|
|
768
|
+
pixel.b * a * bga | 0);
|
|
842
769
|
|
|
843
770
|
if (ch && this.options.ascii) {
|
|
844
771
|
fg = this.colors.RGBtoHex(
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
)
|
|
772
|
+
pixel.r * a * fga | 0,
|
|
773
|
+
pixel.g * a * fga | 0,
|
|
774
|
+
pixel.b * a * fga | 0);
|
|
849
775
|
if (a === 0) {
|
|
850
|
-
return '{' + fg + '-fg}' + ch + '{/}'
|
|
776
|
+
return '{' + fg + '-fg}' + ch + '{/}';
|
|
851
777
|
}
|
|
852
|
-
return '{' + fg + '-fg}{' + bg + '-bg}' + ch + '{/}'
|
|
778
|
+
return '{' + fg + '-fg}{' + bg + '-bg}' + ch + '{/}';
|
|
853
779
|
}
|
|
854
780
|
|
|
855
|
-
if (a === 0)
|
|
856
|
-
return ' '
|
|
857
|
-
}
|
|
781
|
+
if (a === 0) return ' ';
|
|
858
782
|
|
|
859
|
-
return '{' + bg + '-bg} {/' + bg + '-bg}'
|
|
860
|
-
}
|
|
783
|
+
return '{' + bg + '-bg} {/' + bg + '-bg}';
|
|
784
|
+
};
|
|
861
785
|
|
|
862
|
-
PNG.prototype.pixelToCell = function
|
|
863
|
-
|
|
864
|
-
fga = 0.5
|
|
865
|
-
a = pixel.a / 255
|
|
866
|
-
bg
|
|
867
|
-
fg
|
|
786
|
+
PNG.prototype.pixelToCell = function(pixel, ch) {
|
|
787
|
+
var bga = 1.0
|
|
788
|
+
, fga = 0.5
|
|
789
|
+
, a = pixel.a / 255
|
|
790
|
+
, bg
|
|
791
|
+
, fg;
|
|
868
792
|
|
|
869
793
|
bg = this.colors.match(
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
)
|
|
794
|
+
pixel.r * bga | 0,
|
|
795
|
+
pixel.g * bga | 0,
|
|
796
|
+
pixel.b * bga | 0);
|
|
874
797
|
|
|
875
798
|
if (ch && this.options.ascii) {
|
|
876
799
|
fg = this.colors.match(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
)
|
|
800
|
+
pixel.r * fga | 0,
|
|
801
|
+
pixel.g * fga | 0,
|
|
802
|
+
pixel.b * fga | 0);
|
|
881
803
|
} else {
|
|
882
|
-
fg = 0x1ff
|
|
883
|
-
ch = null
|
|
804
|
+
fg = 0x1ff;
|
|
805
|
+
ch = null;
|
|
884
806
|
}
|
|
885
807
|
|
|
886
808
|
// if (a === 0) bg = 0x1ff;
|
|
887
809
|
|
|
888
|
-
return [(0 << 18) | (fg << 9) | (bg << 0), ch || ' ', a]
|
|
889
|
-
}
|
|
810
|
+
return [(0 << 18) | (fg << 9) | (bg << 0), ch || ' ', a];
|
|
811
|
+
};
|
|
890
812
|
|
|
891
813
|
// Taken from libcaca:
|
|
892
|
-
PNG.prototype.getOutch = (function
|
|
893
|
-
|
|
814
|
+
PNG.prototype.getOutch = (function() {
|
|
815
|
+
var dchars = '????8@8@#8@8##8#MKXWwz$&%x><\\/xo;+=|^-:i\'.`, `. ';
|
|
894
816
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
r = pixel.r * a
|
|
898
|
-
g = pixel.g * a
|
|
899
|
-
b = pixel.b * a
|
|
900
|
-
l = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
817
|
+
var luminance = function(pixel) {
|
|
818
|
+
var a = pixel.a / 255
|
|
819
|
+
, r = pixel.r * a
|
|
820
|
+
, g = pixel.g * a
|
|
821
|
+
, b = pixel.b * a
|
|
822
|
+
, l = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
901
823
|
|
|
902
|
-
return l / 255
|
|
903
|
-
}
|
|
824
|
+
return l / 255;
|
|
825
|
+
};
|
|
904
826
|
|
|
905
|
-
return function
|
|
906
|
-
|
|
907
|
-
outch = dchars[
|
|
827
|
+
return function(x, y, line, pixel) {
|
|
828
|
+
var lumi = luminance(pixel)
|
|
829
|
+
, outch = dchars[lumi * (dchars.length - 1) | 0];
|
|
908
830
|
|
|
909
|
-
return outch
|
|
910
|
-
}
|
|
911
|
-
})()
|
|
831
|
+
return outch;
|
|
832
|
+
};
|
|
833
|
+
})();
|
|
912
834
|
|
|
913
|
-
PNG.prototype.compileFrames = function
|
|
835
|
+
PNG.prototype.compileFrames = function(frames) {
|
|
914
836
|
return this.optimization === 'mem'
|
|
915
837
|
? this.compileFrames_lomem(frames)
|
|
916
|
-
: this.compileFrames_locpu(frames)
|
|
917
|
-
}
|
|
838
|
+
: this.compileFrames_locpu(frames);
|
|
839
|
+
};
|
|
918
840
|
|
|
919
|
-
PNG.prototype.compileFrames_lomem = function
|
|
920
|
-
if (!this.actl)
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
this.width = frame.fctl.width
|
|
925
|
-
this.height = frame.fctl.height
|
|
841
|
+
PNG.prototype.compileFrames_lomem = function(frames) {
|
|
842
|
+
if (!this.actl) return;
|
|
843
|
+
return frames.map(function(frame, i) {
|
|
844
|
+
this.width = frame.fctl.width;
|
|
845
|
+
this.height = frame.fctl.height;
|
|
926
846
|
|
|
927
|
-
|
|
928
|
-
bmp = frame._bmp || this.createBitmap(pixels)
|
|
929
|
-
fc = frame.fctl
|
|
847
|
+
var pixels = frame._pixels || this.parseLines(frame.fdat)
|
|
848
|
+
, bmp = frame._bmp || this.createBitmap(pixels)
|
|
849
|
+
, fc = frame.fctl;
|
|
930
850
|
|
|
931
851
|
return {
|
|
932
852
|
actl: this.actl,
|
|
933
853
|
fctl: frame.fctl,
|
|
934
|
-
delay: (
|
|
854
|
+
delay: (fc.delayNum / (fc.delayDen || 100)) * 1000 | 0,
|
|
935
855
|
bmp: bmp
|
|
936
|
-
}
|
|
937
|
-
}, this)
|
|
938
|
-
}
|
|
856
|
+
};
|
|
857
|
+
}, this);
|
|
858
|
+
};
|
|
939
859
|
|
|
940
|
-
PNG.prototype.compileFrames_locpu = function
|
|
941
|
-
if (!this.actl)
|
|
942
|
-
return
|
|
943
|
-
}
|
|
860
|
+
PNG.prototype.compileFrames_locpu = function(frames) {
|
|
861
|
+
if (!this.actl) return;
|
|
944
862
|
|
|
945
|
-
this._curBmp = null
|
|
946
|
-
this._lastBmp = null
|
|
863
|
+
this._curBmp = null;
|
|
864
|
+
this._lastBmp = null;
|
|
947
865
|
|
|
948
|
-
return frames.map(function
|
|
949
|
-
this.width = frame.fctl.width
|
|
950
|
-
this.height = frame.fctl.height
|
|
866
|
+
return frames.map(function(frame, i) {
|
|
867
|
+
this.width = frame.fctl.width;
|
|
868
|
+
this.height = frame.fctl.height;
|
|
951
869
|
|
|
952
|
-
|
|
953
|
-
bmp = frame._bmp || this.createBitmap(pixels)
|
|
954
|
-
renderBmp = this.renderFrame(bmp, frame, i)
|
|
955
|
-
cellmap = this.createCellmap(renderBmp)
|
|
956
|
-
fc = frame.fctl
|
|
870
|
+
var pixels = frame._pixels || this.parseLines(frame.fdat)
|
|
871
|
+
, bmp = frame._bmp || this.createBitmap(pixels)
|
|
872
|
+
, renderBmp = this.renderFrame(bmp, frame, i)
|
|
873
|
+
, cellmap = this.createCellmap(renderBmp)
|
|
874
|
+
, fc = frame.fctl;
|
|
957
875
|
|
|
958
876
|
return {
|
|
959
877
|
actl: this.actl,
|
|
960
878
|
fctl: frame.fctl,
|
|
961
|
-
delay: (
|
|
879
|
+
delay: (fc.delayNum / (fc.delayDen || 100)) * 1000 | 0,
|
|
962
880
|
bmp: renderBmp,
|
|
963
881
|
cellmap: cellmap
|
|
964
|
-
}
|
|
965
|
-
}, this)
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
PNG.prototype.renderFrame = function
|
|
969
|
-
|
|
970
|
-
last = this.frames[i - 1]
|
|
971
|
-
fc = frame.fctl
|
|
972
|
-
xo = fc.xOffset
|
|
973
|
-
yo = fc.yOffset
|
|
974
|
-
lxo
|
|
975
|
-
lyo
|
|
976
|
-
x
|
|
977
|
-
y
|
|
978
|
-
line
|
|
979
|
-
p
|
|
882
|
+
};
|
|
883
|
+
}, this);
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
PNG.prototype.renderFrame = function(bmp, frame, i) {
|
|
887
|
+
var first = this.frames[0]
|
|
888
|
+
, last = this.frames[i - 1]
|
|
889
|
+
, fc = frame.fctl
|
|
890
|
+
, xo = fc.xOffset
|
|
891
|
+
, yo = fc.yOffset
|
|
892
|
+
, lxo
|
|
893
|
+
, lyo
|
|
894
|
+
, x
|
|
895
|
+
, y
|
|
896
|
+
, line
|
|
897
|
+
, p;
|
|
980
898
|
|
|
981
899
|
if (!this._curBmp) {
|
|
982
|
-
this._curBmp = []
|
|
900
|
+
this._curBmp = [];
|
|
983
901
|
for (y = 0; y < first.fctl.height; y++) {
|
|
984
|
-
line = []
|
|
902
|
+
line = [];
|
|
985
903
|
for (x = 0; x < first.fctl.width; x++) {
|
|
986
|
-
p = bmp[y][x]
|
|
987
|
-
line.push({ r: p.r, g: p.g, b: p.b, a: p.a })
|
|
904
|
+
p = bmp[y][x];
|
|
905
|
+
line.push({ r: p.r, g: p.g, b: p.b, a: p.a });
|
|
988
906
|
}
|
|
989
|
-
this._curBmp.push(line)
|
|
907
|
+
this._curBmp.push(line);
|
|
990
908
|
}
|
|
991
909
|
}
|
|
992
910
|
|
|
993
911
|
if (last && last.fctl.disposeOp !== 0) {
|
|
994
|
-
lxo = last.fctl.xOffset
|
|
995
|
-
lyo = last.fctl.yOffset
|
|
912
|
+
lxo = last.fctl.xOffset;
|
|
913
|
+
lyo = last.fctl.yOffset;
|
|
996
914
|
for (y = 0; y < last.fctl.height; y++) {
|
|
997
915
|
for (x = 0; x < last.fctl.width; x++) {
|
|
998
916
|
if (last.fctl.disposeOp === 0) {
|
|
999
917
|
// none / keep
|
|
1000
918
|
} else if (last.fctl.disposeOp === 1) {
|
|
1001
919
|
// background / clear
|
|
1002
|
-
this._curBmp[lyo + y][lxo + x] = { r: 0, g: 0, b: 0, a: 0 }
|
|
920
|
+
this._curBmp[lyo + y][lxo + x] = { r: 0, g: 0, b: 0, a: 0 };
|
|
1003
921
|
} else if (last.fctl.disposeOp === 2) {
|
|
1004
922
|
// previous / restore
|
|
1005
|
-
p = this._lastBmp[y][x]
|
|
1006
|
-
this._curBmp[lyo + y][lxo + x] = { r: p.r, g: p.g, b: p.b, a: p.a }
|
|
923
|
+
p = this._lastBmp[y][x];
|
|
924
|
+
this._curBmp[lyo + y][lxo + x] = { r: p.r, g: p.g, b: p.b, a: p.a };
|
|
1007
925
|
}
|
|
1008
926
|
}
|
|
1009
927
|
}
|
|
1010
928
|
}
|
|
1011
929
|
|
|
1012
930
|
if (frame.fctl.disposeOp === 2) {
|
|
1013
|
-
this._lastBmp = []
|
|
931
|
+
this._lastBmp = [];
|
|
1014
932
|
for (y = 0; y < frame.fctl.height; y++) {
|
|
1015
|
-
line = []
|
|
933
|
+
line = [];
|
|
1016
934
|
for (x = 0; x < frame.fctl.width; x++) {
|
|
1017
|
-
p = this._curBmp[yo + y][xo + x]
|
|
1018
|
-
line.push({ r: p.r, g: p.g, b: p.b, a: p.a })
|
|
935
|
+
p = this._curBmp[yo + y][xo + x];
|
|
936
|
+
line.push({ r: p.r, g: p.g, b: p.b, a: p.a });
|
|
1019
937
|
}
|
|
1020
|
-
this._lastBmp.push(line)
|
|
938
|
+
this._lastBmp.push(line);
|
|
1021
939
|
}
|
|
1022
940
|
} else {
|
|
1023
|
-
this._lastBmp = null
|
|
941
|
+
this._lastBmp = null;
|
|
1024
942
|
}
|
|
1025
943
|
|
|
1026
944
|
for (y = 0; y < frame.fctl.height; y++) {
|
|
1027
945
|
for (x = 0; x < frame.fctl.width; x++) {
|
|
1028
|
-
p = bmp[y][x]
|
|
946
|
+
p = bmp[y][x];
|
|
1029
947
|
if (fc.blendOp === 0) {
|
|
1030
948
|
// source
|
|
1031
|
-
this._curBmp[yo + y][xo + x] = { r: p.r, g: p.g, b: p.b, a: p.a }
|
|
949
|
+
this._curBmp[yo + y][xo + x] = { r: p.r, g: p.g, b: p.b, a: p.a };
|
|
1032
950
|
} else if (fc.blendOp === 1) {
|
|
1033
951
|
// over
|
|
1034
952
|
if (p.a !== 0) {
|
|
1035
|
-
this._curBmp[yo + y][xo + x] = { r: p.r, g: p.g, b: p.b, a: p.a }
|
|
953
|
+
this._curBmp[yo + y][xo + x] = { r: p.r, g: p.g, b: p.b, a: p.a };
|
|
1036
954
|
}
|
|
1037
955
|
}
|
|
1038
956
|
}
|
|
1039
957
|
}
|
|
1040
958
|
|
|
1041
|
-
return this._curBmp
|
|
1042
|
-
}
|
|
959
|
+
return this._curBmp;
|
|
960
|
+
};
|
|
1043
961
|
|
|
1044
|
-
PNG.prototype._animate = function
|
|
962
|
+
PNG.prototype._animate = function(callback) {
|
|
1045
963
|
if (!this.frames) {
|
|
1046
|
-
return callback(this.bmp, this.cellmap)
|
|
964
|
+
return callback(this.bmp, this.cellmap);
|
|
1047
965
|
}
|
|
1048
966
|
|
|
1049
|
-
|
|
1050
|
-
numPlays = this.actl.numPlays || Infinity
|
|
1051
|
-
running = 0
|
|
1052
|
-
i = -1
|
|
967
|
+
var self = this
|
|
968
|
+
, numPlays = this.actl.numPlays || Infinity
|
|
969
|
+
, running = 0
|
|
970
|
+
, i = -1;
|
|
1053
971
|
|
|
1054
|
-
this._curBmp = null
|
|
1055
|
-
this._lastBmp = null
|
|
972
|
+
this._curBmp = null;
|
|
973
|
+
this._lastBmp = null;
|
|
1056
974
|
|
|
1057
|
-
|
|
1058
|
-
if (!running)
|
|
1059
|
-
return
|
|
1060
|
-
}
|
|
975
|
+
var next_lomem = function() {
|
|
976
|
+
if (!running) return;
|
|
1061
977
|
|
|
1062
|
-
|
|
978
|
+
var frame = self.frames[++i];
|
|
1063
979
|
if (!frame) {
|
|
1064
|
-
if (!--numPlays)
|
|
1065
|
-
|
|
1066
|
-
}
|
|
1067
|
-
i = -1
|
|
980
|
+
if (!--numPlays) return callback();
|
|
981
|
+
i = -1;
|
|
1068
982
|
// XXX may be able to optimize by only setting the self._curBmp once???
|
|
1069
|
-
self._curBmp = null
|
|
1070
|
-
self._lastBmp = null
|
|
1071
|
-
return setImmediate(next)
|
|
983
|
+
self._curBmp = null;
|
|
984
|
+
self._lastBmp = null;
|
|
985
|
+
return setImmediate(next);
|
|
1072
986
|
}
|
|
1073
987
|
|
|
1074
|
-
|
|
1075
|
-
renderBmp = self.renderFrame(bmp, frame, i)
|
|
1076
|
-
cellmap = self.createCellmap(renderBmp)
|
|
988
|
+
var bmp = frame.bmp
|
|
989
|
+
, renderBmp = self.renderFrame(bmp, frame, i)
|
|
990
|
+
, cellmap = self.createCellmap(renderBmp);
|
|
1077
991
|
|
|
1078
|
-
callback(renderBmp, cellmap)
|
|
1079
|
-
return setTimeout(next,
|
|
1080
|
-
}
|
|
992
|
+
callback(renderBmp, cellmap);
|
|
993
|
+
return setTimeout(next, frame.delay / self.speed | 0);
|
|
994
|
+
};
|
|
1081
995
|
|
|
1082
|
-
|
|
1083
|
-
if (!running)
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1086
|
-
const frame = self.frames[++i]
|
|
996
|
+
var next_locpu = function() {
|
|
997
|
+
if (!running) return;
|
|
998
|
+
var frame = self.frames[++i];
|
|
1087
999
|
if (!frame) {
|
|
1088
|
-
if (!--numPlays)
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
i = -1
|
|
1092
|
-
return setImmediate(next)
|
|
1000
|
+
if (!--numPlays) return callback();
|
|
1001
|
+
i = -1;
|
|
1002
|
+
return setImmediate(next);
|
|
1093
1003
|
}
|
|
1094
|
-
callback(frame.bmp, frame.cellmap)
|
|
1095
|
-
return setTimeout(next,
|
|
1096
|
-
}
|
|
1004
|
+
callback(frame.bmp, frame.cellmap);
|
|
1005
|
+
return setTimeout(next, frame.delay / self.speed | 0);
|
|
1006
|
+
};
|
|
1097
1007
|
|
|
1098
|
-
|
|
1008
|
+
var next = this.optimization === 'mem'
|
|
1009
|
+
? next_lomem
|
|
1010
|
+
: next_locpu;
|
|
1099
1011
|
|
|
1100
|
-
this._control = function
|
|
1012
|
+
this._control = function(state) {
|
|
1101
1013
|
if (state === -1) {
|
|
1102
|
-
i = -1
|
|
1103
|
-
self._curBmp = null
|
|
1104
|
-
self._lastBmp = null
|
|
1105
|
-
running = 0
|
|
1106
|
-
callback(
|
|
1107
|
-
self.frames[0].bmp
|
|
1108
|
-
|
|
1109
|
-
)
|
|
1110
|
-
return
|
|
1014
|
+
i = -1;
|
|
1015
|
+
self._curBmp = null;
|
|
1016
|
+
self._lastBmp = null;
|
|
1017
|
+
running = 0;
|
|
1018
|
+
callback(self.frames[0].bmp,
|
|
1019
|
+
self.frames[0].cellmap || self.createCellmap(self.frames[0].bmp));
|
|
1020
|
+
return;
|
|
1111
1021
|
}
|
|
1112
|
-
if (state === running)
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
return next()
|
|
1117
|
-
}
|
|
1022
|
+
if (state === running) return;
|
|
1023
|
+
running = state;
|
|
1024
|
+
return next();
|
|
1025
|
+
};
|
|
1118
1026
|
|
|
1119
|
-
this._control(1)
|
|
1120
|
-
}
|
|
1027
|
+
this._control(1);
|
|
1028
|
+
};
|
|
1121
1029
|
|
|
1122
|
-
PNG.prototype.play = function
|
|
1030
|
+
PNG.prototype.play = function(callback) {
|
|
1123
1031
|
if (!this._control || callback) {
|
|
1124
|
-
this.stop()
|
|
1125
|
-
return this._animate(callback)
|
|
1032
|
+
this.stop();
|
|
1033
|
+
return this._animate(callback);
|
|
1126
1034
|
}
|
|
1127
|
-
this._control(1)
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
PNG.prototype.pause = function
|
|
1131
|
-
if (!this._control)
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
this.
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
gif,
|
|
1151
|
-
i,
|
|
1152
|
-
control,
|
|
1153
|
-
disposeOp
|
|
1035
|
+
this._control(1);
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
PNG.prototype.pause = function() {
|
|
1039
|
+
if (!this._control) return;
|
|
1040
|
+
this._control(0);
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
PNG.prototype.stop = function() {
|
|
1044
|
+
if (!this._control) return;
|
|
1045
|
+
this._control(-1);
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
PNG.prototype.toPNG = function(input) {
|
|
1049
|
+
var options = this.options
|
|
1050
|
+
, file = this.file
|
|
1051
|
+
, format = this.format
|
|
1052
|
+
, buf
|
|
1053
|
+
, img
|
|
1054
|
+
, gif
|
|
1055
|
+
, i
|
|
1056
|
+
, control
|
|
1057
|
+
, disposeOp;
|
|
1154
1058
|
|
|
1155
1059
|
if (format !== 'gif') {
|
|
1156
|
-
buf = exec('convert', [format + ':-', 'png:-'],
|
|
1157
|
-
stdio: ['pipe', 'pipe', 'ignore'],
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
img
|
|
1161
|
-
img.file = file
|
|
1162
|
-
return img
|
|
1060
|
+
buf = exec('convert', [format + ':-', 'png:-'],
|
|
1061
|
+
{ stdio: ['pipe', 'pipe', 'ignore'], input: input });
|
|
1062
|
+
img = PNG(buf, options);
|
|
1063
|
+
img.file = file;
|
|
1064
|
+
return img;
|
|
1163
1065
|
}
|
|
1164
1066
|
|
|
1165
|
-
gif = GIF(input, options)
|
|
1067
|
+
gif = GIF(input, options);
|
|
1166
1068
|
|
|
1167
|
-
this.width = gif.width
|
|
1168
|
-
this.height = gif.height
|
|
1169
|
-
this.frames = []
|
|
1069
|
+
this.width = gif.width;
|
|
1070
|
+
this.height = gif.height;
|
|
1071
|
+
this.frames = [];
|
|
1170
1072
|
|
|
1171
1073
|
for (i = 0; i < gif.images.length; i++) {
|
|
1172
|
-
img = gif.images[i]
|
|
1074
|
+
img = gif.images[i];
|
|
1173
1075
|
// Convert from gif disposal to png disposal. See:
|
|
1174
1076
|
// http://www.w3.org/Graphics/GIF/spec-gif89a.txt
|
|
1175
|
-
control = img.control || gif
|
|
1176
|
-
disposeOp = Math.max(0, (control.disposeMethod || 0) - 1)
|
|
1177
|
-
if (disposeOp > 2)
|
|
1178
|
-
disposeOp = 0
|
|
1179
|
-
}
|
|
1077
|
+
control = img.control || gif;
|
|
1078
|
+
disposeOp = Math.max(0, (control.disposeMethod || 0) - 1);
|
|
1079
|
+
if (disposeOp > 2) disposeOp = 0;
|
|
1180
1080
|
this.frames.push({
|
|
1181
1081
|
fctl: {
|
|
1182
1082
|
sequenceNumber: i,
|
|
@@ -1192,88 +1092,84 @@ PNG.prototype.toPNG = function (input) {
|
|
|
1192
1092
|
fdat: [],
|
|
1193
1093
|
_pixels: [],
|
|
1194
1094
|
_bmp: img.bmp
|
|
1195
|
-
})
|
|
1095
|
+
});
|
|
1196
1096
|
}
|
|
1197
1097
|
|
|
1198
|
-
this.bmp = this.frames[0]._bmp
|
|
1199
|
-
this.cellmap = this.createCellmap(this.bmp)
|
|
1098
|
+
this.bmp = this.frames[0]._bmp;
|
|
1099
|
+
this.cellmap = this.createCellmap(this.bmp);
|
|
1200
1100
|
|
|
1201
1101
|
if (this.frames.length > 1) {
|
|
1202
|
-
this.actl = { numFrames: gif.images.length, numPlays: gif.numPlays || 0 }
|
|
1203
|
-
this.frames = this.compileFrames(this.frames)
|
|
1102
|
+
this.actl = { numFrames: gif.images.length, numPlays: gif.numPlays || 0 };
|
|
1103
|
+
this.frames = this.compileFrames(this.frames);
|
|
1204
1104
|
} else {
|
|
1205
|
-
this.frames = undefined
|
|
1105
|
+
this.frames = undefined;
|
|
1206
1106
|
}
|
|
1207
1107
|
|
|
1208
|
-
return this
|
|
1209
|
-
}
|
|
1108
|
+
return this;
|
|
1109
|
+
};
|
|
1210
1110
|
|
|
1211
1111
|
// Convert a gif to an apng using imagemagick. Unfortunately imagemagick
|
|
1212
1112
|
// doesn't support apngs, so we coalesce the gif frames into one image and then
|
|
1213
1113
|
// slice them into frames.
|
|
1214
|
-
PNG.prototype.gifMagick = function
|
|
1215
|
-
|
|
1216
|
-
file = this.file
|
|
1217
|
-
format = this.format
|
|
1218
|
-
buf
|
|
1219
|
-
fmt
|
|
1220
|
-
img
|
|
1221
|
-
frames
|
|
1222
|
-
frame
|
|
1223
|
-
width
|
|
1224
|
-
height
|
|
1225
|
-
iwidth
|
|
1226
|
-
twidth
|
|
1227
|
-
i
|
|
1228
|
-
lines
|
|
1229
|
-
line
|
|
1230
|
-
x
|
|
1231
|
-
y
|
|
1232
|
-
|
|
1233
|
-
buf = exec('convert',
|
|
1234
|
-
|
|
1235
|
-
input: input
|
|
1236
|
-
})
|
|
1114
|
+
PNG.prototype.gifMagick = function(input) {
|
|
1115
|
+
var options = this.options
|
|
1116
|
+
, file = this.file
|
|
1117
|
+
, format = this.format
|
|
1118
|
+
, buf
|
|
1119
|
+
, fmt
|
|
1120
|
+
, img
|
|
1121
|
+
, frames
|
|
1122
|
+
, frame
|
|
1123
|
+
, width
|
|
1124
|
+
, height
|
|
1125
|
+
, iwidth
|
|
1126
|
+
, twidth
|
|
1127
|
+
, i
|
|
1128
|
+
, lines
|
|
1129
|
+
, line
|
|
1130
|
+
, x
|
|
1131
|
+
, y;
|
|
1132
|
+
|
|
1133
|
+
buf = exec('convert',
|
|
1134
|
+
[format + ':-', '-coalesce', '+append', 'png:-'],
|
|
1135
|
+
{ stdio: ['pipe', 'pipe', 'ignore'], input: input });
|
|
1237
1136
|
|
|
1238
1137
|
fmt = '{"W":%W,"H":%H,"w":%w,"h":%h,"d":%T,"x":"%X","y":"%Y"},'
|
|
1239
|
-
frames = exec('identify', ['-format', fmt, format + ':-'],
|
|
1240
|
-
encoding: 'utf8',
|
|
1241
|
-
|
|
1242
|
-
input: input
|
|
1243
|
-
})
|
|
1244
|
-
frames = JSON.parse('[' + frames.trim().slice(0, -1) + ']')
|
|
1138
|
+
frames = exec('identify', ['-format', fmt, format + ':-'],
|
|
1139
|
+
{ encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'], input: input });
|
|
1140
|
+
frames = JSON.parse('[' + frames.trim().slice(0, -1) + ']');
|
|
1245
1141
|
|
|
1246
|
-
img = PNG(buf, options)
|
|
1247
|
-
img.file = file
|
|
1248
|
-
Object.keys(img).forEach(function
|
|
1249
|
-
this[key] = img[key]
|
|
1250
|
-
}, this)
|
|
1142
|
+
img = PNG(buf, options);
|
|
1143
|
+
img.file = file;
|
|
1144
|
+
Object.keys(img).forEach(function(key) {
|
|
1145
|
+
this[key] = img[key];
|
|
1146
|
+
}, this);
|
|
1251
1147
|
|
|
1252
|
-
width = frames[0].W
|
|
1253
|
-
height = frames[0].H
|
|
1254
|
-
iwidth = 0
|
|
1255
|
-
twidth = 0
|
|
1148
|
+
width = frames[0].W;
|
|
1149
|
+
height = frames[0].H;
|
|
1150
|
+
iwidth = 0;
|
|
1151
|
+
twidth = 0;
|
|
1256
1152
|
|
|
1257
|
-
this.width = width
|
|
1258
|
-
this.height = height
|
|
1153
|
+
this.width = width;
|
|
1154
|
+
this.height = height;
|
|
1259
1155
|
|
|
1260
|
-
this.frames = []
|
|
1156
|
+
this.frames = [];
|
|
1261
1157
|
|
|
1262
1158
|
for (i = 0; i < frames.length; i++) {
|
|
1263
|
-
frame = frames[i]
|
|
1264
|
-
frame.x = +frame.x
|
|
1265
|
-
frame.y = +frame.y
|
|
1159
|
+
frame = frames[i];
|
|
1160
|
+
frame.x = +frame.x;
|
|
1161
|
+
frame.y = +frame.y;
|
|
1266
1162
|
|
|
1267
|
-
iwidth = twidth
|
|
1268
|
-
twidth += width
|
|
1163
|
+
iwidth = twidth;
|
|
1164
|
+
twidth += width;
|
|
1269
1165
|
|
|
1270
|
-
lines = []
|
|
1166
|
+
lines = [];
|
|
1271
1167
|
for (y = frame.y; y < height; y++) {
|
|
1272
|
-
line = []
|
|
1168
|
+
line = [];
|
|
1273
1169
|
for (x = iwidth + frame.x; x < twidth; x++) {
|
|
1274
|
-
line.push(img.bmp[y][x])
|
|
1170
|
+
line.push(img.bmp[y][x]);
|
|
1275
1171
|
}
|
|
1276
|
-
lines.push(line)
|
|
1172
|
+
lines.push(line);
|
|
1277
1173
|
}
|
|
1278
1174
|
|
|
1279
1175
|
this.frames.push({
|
|
@@ -1291,31 +1187,27 @@ PNG.prototype.gifMagick = function (input) {
|
|
|
1291
1187
|
fdat: [],
|
|
1292
1188
|
_pixels: [],
|
|
1293
1189
|
_bmp: lines
|
|
1294
|
-
})
|
|
1190
|
+
});
|
|
1295
1191
|
}
|
|
1296
1192
|
|
|
1297
|
-
this.bmp = this.frames[0]._bmp
|
|
1298
|
-
this.cellmap = this.createCellmap(this.bmp)
|
|
1193
|
+
this.bmp = this.frames[0]._bmp;
|
|
1194
|
+
this.cellmap = this.createCellmap(this.bmp);
|
|
1299
1195
|
|
|
1300
1196
|
if (this.frames.length > 1) {
|
|
1301
|
-
this.actl = { numFrames: frames.length, numPlays: 0 }
|
|
1302
|
-
this.frames = this.compileFrames(this.frames)
|
|
1197
|
+
this.actl = { numFrames: frames.length, numPlays: 0 };
|
|
1198
|
+
this.frames = this.compileFrames(this.frames);
|
|
1303
1199
|
} else {
|
|
1304
|
-
this.frames = undefined
|
|
1200
|
+
this.frames = undefined;
|
|
1305
1201
|
}
|
|
1306
1202
|
|
|
1307
|
-
return this
|
|
1308
|
-
}
|
|
1203
|
+
return this;
|
|
1204
|
+
};
|
|
1309
1205
|
|
|
1310
|
-
PNG.prototype.decompress = function
|
|
1311
|
-
return zlib.inflateSync(
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
}, [])
|
|
1316
|
-
)
|
|
1317
|
-
)
|
|
1318
|
-
}
|
|
1206
|
+
PNG.prototype.decompress = function(buffers) {
|
|
1207
|
+
return zlib.inflateSync(new Buffer(buffers.reduce(function(out, data) {
|
|
1208
|
+
return out.concat(Array.prototype.slice.call(data));
|
|
1209
|
+
}, [])));
|
|
1210
|
+
};
|
|
1319
1211
|
|
|
1320
1212
|
/**
|
|
1321
1213
|
* node-crc
|
|
@@ -1344,10 +1236,10 @@ PNG.prototype.decompress = function (buffers) {
|
|
|
1344
1236
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
1345
1237
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
1346
1238
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1347
|
-
|
|
1239
|
+
*/
|
|
1348
1240
|
|
|
1349
|
-
PNG.prototype.crc32 = (function
|
|
1350
|
-
|
|
1241
|
+
PNG.prototype.crc32 = (function() {
|
|
1242
|
+
var crcTable = [
|
|
1351
1243
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
|
1352
1244
|
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
|
1353
1245
|
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
|
@@ -1391,488 +1283,468 @@ PNG.prototype.crc32 = (function () {
|
|
|
1391
1283
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
|
1392
1284
|
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
|
1393
1285
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
|
1394
|
-
]
|
|
1286
|
+
];
|
|
1395
1287
|
|
|
1396
1288
|
return function crc32(buf) {
|
|
1397
1289
|
//var crc = previous === 0 ? 0 : ~~previous ^ -1;
|
|
1398
|
-
|
|
1399
|
-
for (
|
|
1400
|
-
crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8)
|
|
1290
|
+
var crc = -1;
|
|
1291
|
+
for (var i = 0, len = buf.length; i < len; i++) {
|
|
1292
|
+
crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
|
|
1401
1293
|
}
|
|
1402
|
-
return crc ^ -1
|
|
1403
|
-
}
|
|
1404
|
-
})()
|
|
1294
|
+
return crc ^ -1;
|
|
1295
|
+
};
|
|
1296
|
+
})();
|
|
1405
1297
|
|
|
1406
|
-
PNG.prototype._debug = function
|
|
1407
|
-
if (!this.options.log)
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
return this.options.log.apply(null, arguments)
|
|
1411
|
-
}
|
|
1298
|
+
PNG.prototype._debug = function() {
|
|
1299
|
+
if (!this.options.log) return;
|
|
1300
|
+
return this.options.log.apply(null, arguments);
|
|
1301
|
+
};
|
|
1412
1302
|
|
|
1413
1303
|
/**
|
|
1414
1304
|
* GIF
|
|
1415
1305
|
*/
|
|
1416
1306
|
|
|
1417
1307
|
function GIF(file, options) {
|
|
1418
|
-
|
|
1308
|
+
var self = this;
|
|
1419
1309
|
|
|
1420
1310
|
if (!(this instanceof GIF)) {
|
|
1421
|
-
return new GIF(file, options)
|
|
1311
|
+
return new GIF(file, options);
|
|
1422
1312
|
}
|
|
1423
1313
|
|
|
1424
|
-
|
|
1425
|
-
p = 0
|
|
1426
|
-
buf
|
|
1427
|
-
i
|
|
1428
|
-
total
|
|
1429
|
-
sig
|
|
1430
|
-
desc
|
|
1431
|
-
img
|
|
1432
|
-
ext
|
|
1433
|
-
label
|
|
1434
|
-
size
|
|
1435
|
-
|
|
1436
|
-
if (!file) {
|
|
1437
|
-
throw new Error('no file')
|
|
1438
|
-
}
|
|
1314
|
+
var info = {}
|
|
1315
|
+
, p = 0
|
|
1316
|
+
, buf
|
|
1317
|
+
, i
|
|
1318
|
+
, total
|
|
1319
|
+
, sig
|
|
1320
|
+
, desc
|
|
1321
|
+
, img
|
|
1322
|
+
, ext
|
|
1323
|
+
, label
|
|
1324
|
+
, size;
|
|
1439
1325
|
|
|
1440
|
-
|
|
1326
|
+
if (!file) throw new Error('no file');
|
|
1441
1327
|
|
|
1442
|
-
|
|
1328
|
+
options = options || {};
|
|
1329
|
+
|
|
1330
|
+
this.options = options;
|
|
1443
1331
|
|
|
1444
1332
|
// XXX If the gif is not optimized enough
|
|
1445
1333
|
// it may OOM the process with too many frames.
|
|
1446
1334
|
// TODO: Implement in PNG reader.
|
|
1447
|
-
this.pixelLimit = this.options.pixelLimit || 7622550
|
|
1448
|
-
this.totalPixels = 0
|
|
1335
|
+
this.pixelLimit = this.options.pixelLimit || 7622550;
|
|
1336
|
+
this.totalPixels = 0;
|
|
1449
1337
|
|
|
1450
1338
|
if (Buffer.isBuffer(file)) {
|
|
1451
|
-
buf = file
|
|
1452
|
-
file = null
|
|
1339
|
+
buf = file;
|
|
1340
|
+
file = null;
|
|
1453
1341
|
} else {
|
|
1454
|
-
file = path.resolve(process.cwd(), file)
|
|
1455
|
-
buf = fs.readFileSync(file)
|
|
1342
|
+
file = path.resolve(process.cwd(), file);
|
|
1343
|
+
buf = fs.readFileSync(file);
|
|
1456
1344
|
}
|
|
1457
1345
|
|
|
1458
|
-
sig = buf.slice(0, 6).toString('ascii')
|
|
1346
|
+
sig = buf.slice(0, 6).toString('ascii');
|
|
1459
1347
|
if (sig !== 'GIF87a' && sig !== 'GIF89a') {
|
|
1460
|
-
throw new Error('bad header: ' + sig)
|
|
1348
|
+
throw new Error('bad header: ' + sig);
|
|
1461
1349
|
}
|
|
1462
1350
|
|
|
1463
|
-
this.width = buf.readUInt16LE(6)
|
|
1464
|
-
this.height = buf.readUInt16LE(8)
|
|
1351
|
+
this.width = buf.readUInt16LE(6);
|
|
1352
|
+
this.height = buf.readUInt16LE(8);
|
|
1465
1353
|
|
|
1466
|
-
this.flags = buf.readUInt8(10)
|
|
1467
|
-
this.gct = !!(this.flags & 0x80)
|
|
1468
|
-
this.gctsize = (this.flags & 0x07) + 1
|
|
1354
|
+
this.flags = buf.readUInt8(10);
|
|
1355
|
+
this.gct = !!(this.flags & 0x80);
|
|
1356
|
+
this.gctsize = (this.flags & 0x07) + 1;
|
|
1469
1357
|
|
|
1470
|
-
this.bgIndex = buf.readUInt8(11)
|
|
1471
|
-
this.aspect = buf.readUInt8(12)
|
|
1472
|
-
p += 13
|
|
1358
|
+
this.bgIndex = buf.readUInt8(11);
|
|
1359
|
+
this.aspect = buf.readUInt8(12);
|
|
1360
|
+
p += 13;
|
|
1473
1361
|
|
|
1474
1362
|
if (this.gct) {
|
|
1475
|
-
this.colors = []
|
|
1476
|
-
total = 1 << this.gctsize
|
|
1363
|
+
this.colors = [];
|
|
1364
|
+
total = 1 << this.gctsize;
|
|
1477
1365
|
for (i = 0; i < total; i++, p += 3) {
|
|
1478
|
-
this.colors.push([buf[p], buf[p + 1], buf[p + 2], 255])
|
|
1366
|
+
this.colors.push([buf[p], buf[p + 1], buf[p + 2], 255]);
|
|
1479
1367
|
}
|
|
1480
1368
|
}
|
|
1481
1369
|
|
|
1482
|
-
this.images = []
|
|
1483
|
-
this.extensions = []
|
|
1370
|
+
this.images = [];
|
|
1371
|
+
this.extensions = [];
|
|
1484
1372
|
|
|
1485
1373
|
try {
|
|
1486
1374
|
while (p < buf.length) {
|
|
1487
|
-
desc = buf.readUInt8(p)
|
|
1488
|
-
p += 1
|
|
1375
|
+
desc = buf.readUInt8(p);
|
|
1376
|
+
p += 1;
|
|
1489
1377
|
if (desc === 0x2c) {
|
|
1490
|
-
img = {}
|
|
1378
|
+
img = {};
|
|
1491
1379
|
|
|
1492
|
-
img.left = buf.readUInt16LE(p)
|
|
1493
|
-
p += 2
|
|
1494
|
-
img.top = buf.readUInt16LE(p)
|
|
1495
|
-
p += 2
|
|
1380
|
+
img.left = buf.readUInt16LE(p);
|
|
1381
|
+
p += 2;
|
|
1382
|
+
img.top = buf.readUInt16LE(p);
|
|
1383
|
+
p += 2;
|
|
1496
1384
|
|
|
1497
|
-
img.width = buf.readUInt16LE(p)
|
|
1498
|
-
p += 2
|
|
1499
|
-
img.height = buf.readUInt16LE(p)
|
|
1500
|
-
p += 2
|
|
1385
|
+
img.width = buf.readUInt16LE(p);
|
|
1386
|
+
p += 2;
|
|
1387
|
+
img.height = buf.readUInt16LE(p);
|
|
1388
|
+
p += 2;
|
|
1501
1389
|
|
|
1502
|
-
img.flags = buf.readUInt8(p)
|
|
1503
|
-
p += 1
|
|
1390
|
+
img.flags = buf.readUInt8(p);
|
|
1391
|
+
p += 1;
|
|
1504
1392
|
|
|
1505
|
-
img.lct = !!(img.flags & 0x80)
|
|
1506
|
-
img.ilace = !!(img.flags & 0x40)
|
|
1507
|
-
img.lctsize = (img.flags & 0x07) + 1
|
|
1393
|
+
img.lct = !!(img.flags & 0x80);
|
|
1394
|
+
img.ilace = !!(img.flags & 0x40);
|
|
1395
|
+
img.lctsize = (img.flags & 0x07) + 1;
|
|
1508
1396
|
|
|
1509
1397
|
if (img.lct) {
|
|
1510
|
-
img.lcolors = []
|
|
1511
|
-
total = 1 << img.lctsize
|
|
1398
|
+
img.lcolors = [];
|
|
1399
|
+
total = 1 << img.lctsize;
|
|
1512
1400
|
for (i = 0; i < total; i++, p += 3) {
|
|
1513
|
-
img.lcolors.push([buf[p], buf[p + 1], buf[p + 2], 255])
|
|
1401
|
+
img.lcolors.push([buf[p], buf[p + 1], buf[p + 2], 255]);
|
|
1514
1402
|
}
|
|
1515
1403
|
}
|
|
1516
1404
|
|
|
1517
|
-
img.codeSize = buf.readUInt8(p)
|
|
1518
|
-
p += 1
|
|
1405
|
+
img.codeSize = buf.readUInt8(p);
|
|
1406
|
+
p += 1;
|
|
1519
1407
|
|
|
1520
|
-
img.size = buf.readUInt8(p)
|
|
1521
|
-
p += 1
|
|
1408
|
+
img.size = buf.readUInt8(p);
|
|
1409
|
+
p += 1;
|
|
1522
1410
|
|
|
1523
|
-
img.lzw = [buf.slice(p, p + img.size)]
|
|
1524
|
-
p += img.size
|
|
1411
|
+
img.lzw = [buf.slice(p, p + img.size)];
|
|
1412
|
+
p += img.size;
|
|
1525
1413
|
|
|
1526
1414
|
while (buf[p] !== 0x00) {
|
|
1527
1415
|
// Some gifs screw up their size.
|
|
1528
1416
|
// XXX Same for all subblocks?
|
|
1529
1417
|
if (buf[p] === 0x3b && p === buf.length - 1) {
|
|
1530
|
-
p
|
|
1531
|
-
break
|
|
1418
|
+
p--;
|
|
1419
|
+
break;
|
|
1532
1420
|
}
|
|
1533
|
-
size = buf.readUInt8(p)
|
|
1534
|
-
p += 1
|
|
1535
|
-
img.lzw.push(buf.slice(p, p + size))
|
|
1536
|
-
p += size
|
|
1421
|
+
size = buf.readUInt8(p);
|
|
1422
|
+
p += 1;
|
|
1423
|
+
img.lzw.push(buf.slice(p, p + size));
|
|
1424
|
+
p += size;
|
|
1537
1425
|
}
|
|
1538
1426
|
|
|
1539
|
-
assert.equal(buf.readUInt8(p), 0x00)
|
|
1540
|
-
p += 1
|
|
1427
|
+
assert.equal(buf.readUInt8(p), 0x00);
|
|
1428
|
+
p += 1;
|
|
1541
1429
|
|
|
1542
1430
|
if (ext && ext.label === 0xf9) {
|
|
1543
|
-
img.control = ext
|
|
1431
|
+
img.control = ext;
|
|
1544
1432
|
}
|
|
1545
1433
|
|
|
1546
|
-
this.totalPixels += img.width * img.height
|
|
1434
|
+
this.totalPixels += img.width * img.height;
|
|
1547
1435
|
|
|
1548
|
-
this.images.push(img)
|
|
1436
|
+
this.images.push(img);
|
|
1549
1437
|
|
|
1550
1438
|
if (this.totalPixels >= this.pixelLimit) {
|
|
1551
|
-
break
|
|
1439
|
+
break;
|
|
1552
1440
|
}
|
|
1553
1441
|
} else if (desc === 0x21) {
|
|
1554
1442
|
// Extensions:
|
|
1555
1443
|
// http://www.w3.org/Graphics/GIF/spec-gif89a.txt
|
|
1556
|
-
ext = {}
|
|
1557
|
-
label = buf.readUInt8(p)
|
|
1558
|
-
p += 1
|
|
1559
|
-
ext.label = label
|
|
1444
|
+
ext = {};
|
|
1445
|
+
label = buf.readUInt8(p);
|
|
1446
|
+
p += 1;
|
|
1447
|
+
ext.label = label;
|
|
1560
1448
|
if (label === 0xf9) {
|
|
1561
|
-
size = buf.readUInt8(p)
|
|
1562
|
-
assert.equal(size, 0x04)
|
|
1563
|
-
p += 1
|
|
1564
|
-
ext.fields = buf.readUInt8(p)
|
|
1565
|
-
ext.disposeMethod = (ext.fields >> 2) & 0x07
|
|
1566
|
-
ext.useTransparent = !!(ext.fields & 0x01)
|
|
1567
|
-
p += 1
|
|
1568
|
-
ext.delay = buf.readUInt16LE(p)
|
|
1569
|
-
p += 2
|
|
1570
|
-
ext.transparentColor = buf.readUInt8(p)
|
|
1571
|
-
p += 1
|
|
1449
|
+
size = buf.readUInt8(p);
|
|
1450
|
+
assert.equal(size, 0x04);
|
|
1451
|
+
p += 1;
|
|
1452
|
+
ext.fields = buf.readUInt8(p);
|
|
1453
|
+
ext.disposeMethod = (ext.fields >> 2) & 0x07;
|
|
1454
|
+
ext.useTransparent = !!(ext.fields & 0x01);
|
|
1455
|
+
p += 1;
|
|
1456
|
+
ext.delay = buf.readUInt16LE(p);
|
|
1457
|
+
p += 2;
|
|
1458
|
+
ext.transparentColor = buf.readUInt8(p);
|
|
1459
|
+
p += 1;
|
|
1572
1460
|
while (buf[p] !== 0x00) {
|
|
1573
|
-
size = buf.readUInt8(p)
|
|
1574
|
-
p += 1
|
|
1575
|
-
p += size
|
|
1461
|
+
size = buf.readUInt8(p);
|
|
1462
|
+
p += 1;
|
|
1463
|
+
p += size;
|
|
1576
1464
|
}
|
|
1577
|
-
assert.equal(buf.readUInt8(p), 0x00)
|
|
1578
|
-
p += 1
|
|
1579
|
-
this.delay = ext.delay
|
|
1580
|
-
this.transparentColor = ext.transparentColor
|
|
1581
|
-
this.disposeMethod = ext.disposeMethod
|
|
1582
|
-
this.useTransparent = ext.useTransparent
|
|
1465
|
+
assert.equal(buf.readUInt8(p), 0x00);
|
|
1466
|
+
p += 1;
|
|
1467
|
+
this.delay = ext.delay;
|
|
1468
|
+
this.transparentColor = ext.transparentColor;
|
|
1469
|
+
this.disposeMethod = ext.disposeMethod;
|
|
1470
|
+
this.useTransparent = ext.useTransparent;
|
|
1583
1471
|
} else if (label === 0xff) {
|
|
1584
1472
|
// https://wiki.whatwg.org/wiki/GIF#Specifications
|
|
1585
|
-
size = buf.readUInt8(p)
|
|
1586
|
-
p += 1
|
|
1587
|
-
ext.id = buf.slice(p, p + 8).toString('ascii')
|
|
1588
|
-
p += 8
|
|
1589
|
-
ext.auth = buf.slice(p, p + 3).toString('ascii')
|
|
1590
|
-
p += 3
|
|
1591
|
-
ext.data = []
|
|
1473
|
+
size = buf.readUInt8(p);
|
|
1474
|
+
p += 1;
|
|
1475
|
+
ext.id = buf.slice(p, p + 8).toString('ascii');
|
|
1476
|
+
p += 8;
|
|
1477
|
+
ext.auth = buf.slice(p, p + 3).toString('ascii');
|
|
1478
|
+
p += 3;
|
|
1479
|
+
ext.data = [];
|
|
1592
1480
|
while (buf[p] !== 0x00) {
|
|
1593
|
-
size = buf.readUInt8(p)
|
|
1594
|
-
p += 1
|
|
1595
|
-
ext.data.push(buf.slice(p, p + size))
|
|
1596
|
-
p += size
|
|
1481
|
+
size = buf.readUInt8(p);
|
|
1482
|
+
p += 1;
|
|
1483
|
+
ext.data.push(buf.slice(p, p + size));
|
|
1484
|
+
p += size;
|
|
1597
1485
|
}
|
|
1598
|
-
ext.data = new Buffer(
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
}, [])
|
|
1602
|
-
)
|
|
1486
|
+
ext.data = new Buffer(ext.data.reduce(function(out, data) {
|
|
1487
|
+
return out.concat(Array.prototype.slice.call(data));
|
|
1488
|
+
}, []));
|
|
1603
1489
|
// AnimExts looping extension (identical to netscape)
|
|
1604
1490
|
if (ext.id === 'ANIMEXTS' && ext.auth === '1.0') {
|
|
1605
|
-
ext.id = 'NETSCAPE'
|
|
1606
|
-
ext.auth = '2.0'
|
|
1607
|
-
ext.animexts = true
|
|
1491
|
+
ext.id = 'NETSCAPE';
|
|
1492
|
+
ext.auth = '2.0';
|
|
1493
|
+
ext.animexts = true;
|
|
1608
1494
|
}
|
|
1609
1495
|
// Netscape extensions
|
|
1610
1496
|
if (ext.id === 'NETSCAPE' && ext.auth === '2.0') {
|
|
1611
1497
|
if (ext.data.readUInt8(0) === 0x01) {
|
|
1612
1498
|
// Netscape looping extension
|
|
1613
1499
|
// http://graphcomp.com/info/specs/ani_gif.html
|
|
1614
|
-
ext.numPlays = ext.data.readUInt16LE(1)
|
|
1615
|
-
this.numPlays = ext.numPlays
|
|
1500
|
+
ext.numPlays = ext.data.readUInt16LE(1);
|
|
1501
|
+
this.numPlays = ext.numPlays;
|
|
1616
1502
|
} else if (ext.data.readUInt8(0) === 0x02) {
|
|
1617
1503
|
// Netscape buffering extension
|
|
1618
|
-
this.minBuffer = ext.data
|
|
1504
|
+
this.minBuffer = ext.data;
|
|
1619
1505
|
}
|
|
1620
1506
|
}
|
|
1621
1507
|
// Adobe XMP extension
|
|
1622
1508
|
if (ext.id === 'XMP Data' && ext.auth === 'XMP') {
|
|
1623
|
-
ext.xmp = ext.data.toString('utf8')
|
|
1624
|
-
this.xmp = ext.xmp
|
|
1509
|
+
ext.xmp = ext.data.toString('utf8');
|
|
1510
|
+
this.xmp = ext.xmp;
|
|
1625
1511
|
}
|
|
1626
1512
|
// ICC extension
|
|
1627
1513
|
if (ext.id === 'ICCRGBG1' && ext.auth === '012') {
|
|
1628
1514
|
// NOTE: Says size is 4 bytes, not 1? Maybe just buffer size?
|
|
1629
|
-
this.icc = ext.data
|
|
1515
|
+
this.icc = ext.data;
|
|
1630
1516
|
}
|
|
1631
1517
|
// fractint extension
|
|
1632
1518
|
if (ext.id === 'fractint' && /^00[1-7]$/.test(ext.auth)) {
|
|
1633
1519
|
// NOTE: Says size is 4 bytes, not 1? Maybe just buffer size?
|
|
1634
1520
|
// Size: '!\377\013' == [0x00, 0x15, 0xff, 0x0b]
|
|
1635
|
-
this.fractint = ext.data
|
|
1521
|
+
this.fractint = ext.data;
|
|
1636
1522
|
}
|
|
1637
|
-
assert.equal(buf.readUInt8(p), 0x00)
|
|
1638
|
-
p += 1
|
|
1523
|
+
assert.equal(buf.readUInt8(p), 0x00);
|
|
1524
|
+
p += 1;
|
|
1639
1525
|
} else {
|
|
1640
|
-
ext.data = []
|
|
1526
|
+
ext.data = [];
|
|
1641
1527
|
while (buf[p] !== 0x00) {
|
|
1642
|
-
size = buf.readUInt8(p)
|
|
1643
|
-
p += 1
|
|
1644
|
-
ext.data.push(buf.slice(p, p + size))
|
|
1645
|
-
p += size
|
|
1528
|
+
size = buf.readUInt8(p);
|
|
1529
|
+
p += 1;
|
|
1530
|
+
ext.data.push(buf.slice(p, p + size));
|
|
1531
|
+
p += size;
|
|
1646
1532
|
}
|
|
1647
|
-
assert.equal(buf.readUInt8(p), 0x00)
|
|
1648
|
-
p += 1
|
|
1533
|
+
assert.equal(buf.readUInt8(p), 0x00);
|
|
1534
|
+
p += 1;
|
|
1649
1535
|
}
|
|
1650
|
-
this.extensions.push(ext)
|
|
1536
|
+
this.extensions.push(ext);
|
|
1651
1537
|
} else if (desc === 0x3b) {
|
|
1652
|
-
break
|
|
1538
|
+
break;
|
|
1653
1539
|
} else if (p === buf.length - 1) {
|
|
1654
1540
|
// } else if (desc === 0x00 && p === buf.length - 1) {
|
|
1655
|
-
break
|
|
1541
|
+
break;
|
|
1656
1542
|
} else {
|
|
1657
|
-
throw new Error('unknown block')
|
|
1543
|
+
throw new Error('unknown block');
|
|
1658
1544
|
}
|
|
1659
1545
|
}
|
|
1660
1546
|
} catch (e) {
|
|
1661
1547
|
if (options.debug) {
|
|
1662
|
-
throw e
|
|
1548
|
+
throw e;
|
|
1663
1549
|
}
|
|
1664
1550
|
}
|
|
1665
1551
|
|
|
1666
|
-
this.images = this.images
|
|
1667
|
-
|
|
1668
|
-
const control = img.control || this
|
|
1669
|
-
|
|
1670
|
-
img.lzw = new Buffer(
|
|
1671
|
-
img.lzw.reduce(function (out, data) {
|
|
1672
|
-
return out.concat(Array.prototype.slice.call(data))
|
|
1673
|
-
}, [])
|
|
1674
|
-
)
|
|
1675
|
-
|
|
1676
|
-
try {
|
|
1677
|
-
img.data = this.decompress(img.lzw, img.codeSize)
|
|
1678
|
-
} catch (e) {
|
|
1679
|
-
if (options.debug) {
|
|
1680
|
-
throw e
|
|
1681
|
-
}
|
|
1682
|
-
return
|
|
1683
|
-
}
|
|
1552
|
+
this.images = this.images.map(function(img, imageIndex) {
|
|
1553
|
+
var control = img.control || this;
|
|
1684
1554
|
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
if (
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1555
|
+
img.lzw = new Buffer(img.lzw.reduce(function(out, data) {
|
|
1556
|
+
return out.concat(Array.prototype.slice.call(data));
|
|
1557
|
+
}, []));
|
|
1558
|
+
|
|
1559
|
+
try {
|
|
1560
|
+
img.data = this.decompress(img.lzw, img.codeSize);
|
|
1561
|
+
} catch (e) {
|
|
1562
|
+
if (options.debug) throw e;
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
var interlacing = [
|
|
1567
|
+
[ 0, 8 ],
|
|
1568
|
+
[ 4, 8 ],
|
|
1569
|
+
[ 2, 4 ],
|
|
1570
|
+
[ 1, 2 ],
|
|
1571
|
+
[ 0, 0 ]
|
|
1572
|
+
];
|
|
1573
|
+
|
|
1574
|
+
var table = img.lcolors || this.colors
|
|
1575
|
+
, row = 0
|
|
1576
|
+
, col = 0
|
|
1577
|
+
, ilp = 0
|
|
1578
|
+
, p = 0
|
|
1579
|
+
, b
|
|
1580
|
+
, idx
|
|
1581
|
+
, i
|
|
1582
|
+
, y
|
|
1583
|
+
, x
|
|
1584
|
+
, line
|
|
1585
|
+
, pixel;
|
|
1586
|
+
|
|
1587
|
+
img.samples = [];
|
|
1588
|
+
// Rewritten version of:
|
|
1589
|
+
// https://github.com/lbv/ka-cs-programs/blob/master/lib/gif-reader.js
|
|
1590
|
+
for (;;) {
|
|
1591
|
+
b = img.data[p++];
|
|
1592
|
+
if (b == null) break;
|
|
1593
|
+
idx = (row * img.width + col) * 4;
|
|
1594
|
+
if (!table[b]) {
|
|
1595
|
+
if (options.debug) throw new Error('bad samples');
|
|
1596
|
+
table[b] = [0, 0, 0, 0];
|
|
1597
|
+
}
|
|
1598
|
+
img.samples[idx] = table[b][0];
|
|
1599
|
+
img.samples[idx + 1] = table[b][1];
|
|
1600
|
+
img.samples[idx + 2] = table[b][2];
|
|
1601
|
+
img.samples[idx + 3] = table[b][3];
|
|
1602
|
+
if (control.useTransparent && b === control.transparentColor) {
|
|
1603
|
+
img.samples[idx + 3] = 0;
|
|
1604
|
+
}
|
|
1605
|
+
if (++col >= img.width) {
|
|
1606
|
+
col = 0;
|
|
1607
|
+
if (img.ilace) {
|
|
1608
|
+
row += interlacing[ilp][1];
|
|
1609
|
+
if (row >= img.height) {
|
|
1610
|
+
row = interlacing[++ilp][0];
|
|
1737
1611
|
}
|
|
1612
|
+
} else {
|
|
1613
|
+
row++;
|
|
1738
1614
|
}
|
|
1739
1615
|
}
|
|
1616
|
+
}
|
|
1740
1617
|
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1618
|
+
img.pixels = [];
|
|
1619
|
+
for (i = 0; i < img.samples.length; i += 4) {
|
|
1620
|
+
img.pixels.push(img.samples.slice(i, i + 4));
|
|
1621
|
+
}
|
|
1745
1622
|
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
line.push({ r: 0, g: 0, b: 0, a: 0 })
|
|
1756
|
-
continue
|
|
1757
|
-
}
|
|
1758
|
-
line.push({ r: pixel[0], g: pixel[1], b: pixel[2], a: pixel[3] })
|
|
1623
|
+
img.bmp = [];
|
|
1624
|
+
for (y = 0, p = 0; y < img.height; y++) {
|
|
1625
|
+
line = [];
|
|
1626
|
+
for (x = 0; x < img.width; x++) {
|
|
1627
|
+
pixel = img.pixels[p++];
|
|
1628
|
+
if (!pixel) {
|
|
1629
|
+
if (options.debug) throw new Error('no pixel');
|
|
1630
|
+
line.push({ r: 0, g: 0, b: 0, a: 0 });
|
|
1631
|
+
continue;
|
|
1759
1632
|
}
|
|
1760
|
-
|
|
1633
|
+
line.push({ r: pixel[0], g: pixel[1], b: pixel[2], a: pixel[3] });
|
|
1761
1634
|
}
|
|
1635
|
+
img.bmp.push(line);
|
|
1636
|
+
}
|
|
1762
1637
|
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
.filter(Boolean)
|
|
1638
|
+
return img;
|
|
1639
|
+
}, this).filter(Boolean);
|
|
1766
1640
|
|
|
1767
1641
|
if (!this.images.length) {
|
|
1768
|
-
throw new Error('no image data or bad decompress')
|
|
1642
|
+
throw new Error('no image data or bad decompress');
|
|
1769
1643
|
}
|
|
1770
1644
|
}
|
|
1771
1645
|
|
|
1772
1646
|
// Rewritten version of:
|
|
1773
1647
|
// https://github.com/lbv/ka-cs-programs/blob/master/lib/gif-reader.js
|
|
1774
|
-
GIF.prototype.decompress = function
|
|
1775
|
-
|
|
1776
|
-
CC = 1 << codeSize
|
|
1777
|
-
EOI = CC + 1
|
|
1778
|
-
stack = []
|
|
1779
|
-
table = []
|
|
1780
|
-
ntable = 0
|
|
1781
|
-
oldCode = null
|
|
1782
|
-
buffer = 0
|
|
1783
|
-
nbuffer = 0
|
|
1784
|
-
p = 0
|
|
1785
|
-
buf = []
|
|
1786
|
-
bits
|
|
1787
|
-
read
|
|
1788
|
-
ans
|
|
1789
|
-
n
|
|
1790
|
-
code
|
|
1791
|
-
i
|
|
1792
|
-
K
|
|
1793
|
-
b
|
|
1794
|
-
maxElem
|
|
1648
|
+
GIF.prototype.decompress = function(input, codeSize) {
|
|
1649
|
+
var bitDepth = codeSize + 1
|
|
1650
|
+
, CC = 1 << codeSize
|
|
1651
|
+
, EOI = CC + 1
|
|
1652
|
+
, stack = []
|
|
1653
|
+
, table = []
|
|
1654
|
+
, ntable = 0
|
|
1655
|
+
, oldCode = null
|
|
1656
|
+
, buffer = 0
|
|
1657
|
+
, nbuffer = 0
|
|
1658
|
+
, p = 0
|
|
1659
|
+
, buf = []
|
|
1660
|
+
, bits
|
|
1661
|
+
, read
|
|
1662
|
+
, ans
|
|
1663
|
+
, n
|
|
1664
|
+
, code
|
|
1665
|
+
, i
|
|
1666
|
+
, K
|
|
1667
|
+
, b
|
|
1668
|
+
, maxElem;
|
|
1795
1669
|
|
|
1796
1670
|
for (;;) {
|
|
1797
1671
|
if (stack.length === 0) {
|
|
1798
|
-
bits = bitDepth
|
|
1799
|
-
read = 0
|
|
1800
|
-
ans = 0
|
|
1672
|
+
bits = bitDepth;
|
|
1673
|
+
read = 0;
|
|
1674
|
+
ans = 0;
|
|
1801
1675
|
while (read < bits) {
|
|
1802
1676
|
if (nbuffer === 0) {
|
|
1803
|
-
if (p >= input.length)
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
buffer = input[p++]
|
|
1807
|
-
nbuffer = 8
|
|
1677
|
+
if (p >= input.length) return buf;
|
|
1678
|
+
buffer = input[p++];
|
|
1679
|
+
nbuffer = 8;
|
|
1808
1680
|
}
|
|
1809
|
-
n = Math.min(bits - read, nbuffer)
|
|
1810
|
-
ans |= (buffer & ((1 << n) - 1)) << read
|
|
1811
|
-
read += n
|
|
1812
|
-
nbuffer -= n
|
|
1813
|
-
buffer >>= n
|
|
1681
|
+
n = Math.min(bits - read, nbuffer);
|
|
1682
|
+
ans |= (buffer & ((1 << n) - 1)) << read;
|
|
1683
|
+
read += n;
|
|
1684
|
+
nbuffer -= n;
|
|
1685
|
+
buffer >>= n;
|
|
1814
1686
|
}
|
|
1815
|
-
code = ans
|
|
1687
|
+
code = ans;
|
|
1816
1688
|
|
|
1817
1689
|
if (code === EOI) {
|
|
1818
|
-
break
|
|
1690
|
+
break;
|
|
1819
1691
|
}
|
|
1820
1692
|
|
|
1821
1693
|
if (code === CC) {
|
|
1822
|
-
table = []
|
|
1694
|
+
table = [];
|
|
1823
1695
|
for (i = 0; i < CC; ++i) {
|
|
1824
|
-
table[i] = [i, -1, i]
|
|
1696
|
+
table[i] = [i, -1, i];
|
|
1825
1697
|
}
|
|
1826
|
-
bitDepth = codeSize + 1
|
|
1827
|
-
maxElem = 1 << bitDepth
|
|
1828
|
-
ntable = CC + 2
|
|
1829
|
-
oldCode = null
|
|
1830
|
-
continue
|
|
1698
|
+
bitDepth = codeSize + 1;
|
|
1699
|
+
maxElem = 1 << bitDepth;
|
|
1700
|
+
ntable = CC + 2;
|
|
1701
|
+
oldCode = null;
|
|
1702
|
+
continue;
|
|
1831
1703
|
}
|
|
1832
1704
|
|
|
1833
1705
|
if (oldCode === null) {
|
|
1834
|
-
oldCode = code
|
|
1835
|
-
buf.push(table[code][0])
|
|
1836
|
-
continue
|
|
1706
|
+
oldCode = code;
|
|
1707
|
+
buf.push(table[code][0]);
|
|
1708
|
+
continue;
|
|
1837
1709
|
}
|
|
1838
1710
|
|
|
1839
1711
|
if (code < ntable) {
|
|
1840
1712
|
for (i = code; i >= 0; i = table[i][1]) {
|
|
1841
|
-
stack.push(table[i][0])
|
|
1713
|
+
stack.push(table[i][0]);
|
|
1842
1714
|
}
|
|
1843
|
-
table[ntable++] = [
|
|
1715
|
+
table[ntable++] = [
|
|
1716
|
+
table[code][2],
|
|
1717
|
+
oldCode,
|
|
1718
|
+
table[oldCode][2]
|
|
1719
|
+
];
|
|
1844
1720
|
} else {
|
|
1845
|
-
K = table[oldCode][2]
|
|
1846
|
-
table[ntable++] = [K, oldCode, K]
|
|
1721
|
+
K = table[oldCode][2];
|
|
1722
|
+
table[ntable++] = [K, oldCode, K];
|
|
1847
1723
|
for (i = code; i >= 0; i = table[i][1]) {
|
|
1848
|
-
stack.push(table[i][0])
|
|
1724
|
+
stack.push(table[i][0]);
|
|
1849
1725
|
}
|
|
1850
1726
|
}
|
|
1851
1727
|
|
|
1852
|
-
oldCode = code
|
|
1728
|
+
oldCode = code;
|
|
1853
1729
|
if (ntable === maxElem) {
|
|
1854
|
-
maxElem = 1 << ++bitDepth
|
|
1855
|
-
if (bitDepth > 12)
|
|
1856
|
-
bitDepth = 12
|
|
1857
|
-
}
|
|
1730
|
+
maxElem = 1 << (++bitDepth);
|
|
1731
|
+
if (bitDepth > 12) bitDepth = 12;
|
|
1858
1732
|
}
|
|
1859
1733
|
}
|
|
1860
|
-
b = stack.pop()
|
|
1861
|
-
if (b == null)
|
|
1862
|
-
|
|
1863
|
-
}
|
|
1864
|
-
buf.push(b)
|
|
1734
|
+
b = stack.pop();
|
|
1735
|
+
if (b == null) break;
|
|
1736
|
+
buf.push(b);
|
|
1865
1737
|
}
|
|
1866
1738
|
|
|
1867
|
-
return buf
|
|
1868
|
-
}
|
|
1739
|
+
return buf;
|
|
1740
|
+
};
|
|
1869
1741
|
|
|
1870
1742
|
/**
|
|
1871
1743
|
* Expose
|
|
1872
1744
|
*/
|
|
1873
1745
|
|
|
1874
|
-
exports = PNG
|
|
1875
|
-
exports.png = PNG
|
|
1876
|
-
exports.gif = GIF
|
|
1746
|
+
exports = PNG;
|
|
1747
|
+
exports.png = PNG;
|
|
1748
|
+
exports.gif = GIF;
|
|
1877
1749
|
|
|
1878
|
-
module.exports = exports
|
|
1750
|
+
module.exports = exports;
|