Skip to main content

pscore 0.2.2 copy "pscore: ^0.2.2" to clipboard
pscore: ^0.2.2 copied to clipboard

Shared binary, descriptor, text-engine, PackBits, and pattern codecs for Adobe file formats.

PsCore package illustration

PsCore #

PsCore contains the pure Dart binary primitives shared by Focale's Adobe format packages. It prevents AbrKit, AcvKit, AiKit, AslKit, CshKit, PatKit and PsdKit from maintaining subtly different implementations of the same codecs.

The package currently provides:

  • bounds-checked big-endian binary readers and writers;
  • a complete Photoshop Action Descriptor model, reader, and writer;
  • every standard descriptor OSType and object-reference form;
  • bounded descriptor depth and value counts for untrusted input;
  • immutable Adobe EngineData/ATE values, bounded parsing and source-preserving edits;
  • PackBits row encoding and decoding;
  • a shared Photoshop pattern-record model, bounded decoder, and encoder;
  • raw and PackBits pattern planes at 1, 8, 16, and 32 bits;
  • profile-independent RGBA previews for standard Photoshop color modes;
  • tone curves, vector paths, and preset hierarchies;
  • layer-style colors, gradients, contours, effects, and blending options, with typed views over existing descriptors and builders for new ones;
  • format, write, and warning base types that every format package extends, so one on PsFormatException clause catches errors from any of them.

Platform support #

The package is pure Dart and runs on native platforms, WebAssembly, and JavaScript.

comp Action Descriptor values retain every signed 64-bit integer on all three targets. Read PsLargeIntegerValue.exactValue as a BigInt, or construct one with PsLargeIntegerValue.fromBigInt(value: value). The existing const integer constructor remains available. intValue is nullable when the target cannot represent a value exactly; the compatibility value getter throws StateError in that case instead of rounding it. Integer descriptor projections also return null for an unrepresentable value.

PsBinaryReader.readBigInt64 and PsBinaryWriter.writeBigInt64 provide the same exact signed range for other binary structures. Ordinary readInt64/writeInt64 and 64-bit length fields continue to use int; JavaScript rejects values beyond psMaxExactInteger for those APIs. Native and WebAssembly integer APIs retain the platform's signed 64-bit range.

Usage #

import 'dart:typed_data';

import 'package:pscore/pscore.dart';

final PsBinaryReader reader = PsBinaryReader(bytes: bytes);
final int version = reader.readUint16();

final PsDescriptor descriptor = PsDescriptorCodec.decode(descriptorBytes);
final PsDescriptorValue? name = descriptor.value('Nm  ');

final Uint8List encoded = PsDescriptorCodec.encode(descriptor);

Adobe text-engine payloads use binary literal strings: raw CR/LF bytes must not be normalized as ordinary PostScript whitespace. The shared codec preserves those bytes, supports BOM-marked UTF-16, and retains unknown atoms and original number spellings. It accepts wrapped dictionaries and ATE/Txt2 bare dictionaries.

final PsEngineDocument engine = PsEngineDocument.decode(bytes: engineBytes);
final PsEngineDictionary root = engine.root as PsEngineDictionary;
final PsEngineDocument changed = engine.replaceValues(
  replacements: {
    root['Name']!: PsEngineString.fromText(text: 'Body text'),
  },
);

Source edits require handles from the same snapshot and reject overlaps. PsEngineLimits bounds bytes, strings, nodes and nesting for reading and writing. Duplicate keys are rejected by default; legacy adapters may explicitly select PsEngineReader(allowDuplicateKeys: true). PsEngineReader.view borrows a typed buffer for short-lived scans; its caller must not mutate the input while reading. Parsed values and PsEngineDocument snapshots own their data. Integers outside the exact JavaScript range are preserved as PsEngineToken, without rounding. This grammar codec does not shape text or synchronize format-specific runs, frames, glyph caches or rendered artwork; container packages own those rules.

Container packages can reuse the pattern-record decoder while controlling source preservation and decoded-memory limits:

final PsPatternDecodeResult decoded = PsPatternRecordDecoder.decode(
  reader: reader,
  kind: PsPatternRecordKind.standalone,
  options: const PsPatternDecodeOptions(
    preserveChannelData: false,
    preserveRecordData: false,
  ),
);
final PsPatternImage preview = decoded.pattern.renderRgba8();
final Uint8List patternBytes = PsPatternRecordEncoder.encode(
  pattern: decoded.pattern,
  kind: PsPatternRecordKind.standalone,
);

Built for Focale, an advanced local image editor. Discover what these packages make possible in a real creative workflow.

0
likes
150
points
1.18k
downloads
screenshot

Documentation

API reference

Publisher

verified publisherfocale-editor.app

Weekly Downloads

Shared binary, descriptor, text-engine, PackBits, and pattern codecs for Adobe file formats.

Repository (GitHub)
View/report issues
Contributing

Topics

#photoshop #binary #codec #image-processing #file-format

License

MIT (license)

More

Packages that depend on pscore