Ejemplo n.º 1
0
from __future__ import absolute_import, unicode_literals
import attr
import logging

from psd_tools2.psd.base import BaseElement, ListElement, ValueElement
from psd_tools2.constants import PathResourceID
from psd_tools2.psd.descriptor import Descriptor
from psd_tools2.utils import (
    read_fmt, write_fmt, read_length_block, write_length_block, is_readable,
    write_bytes, write_padding, new_registry
)
from psd_tools2.validators import in_

logger = logging.getLogger(__name__)

TYPES, register = new_registry(attribute='selector')  # Path item types.


def decode_fixed_point(numbers):
    return tuple(float(x) / 0x01000000 for x in numbers)


def encode_fixed_point(numbers):
    return tuple(int(x * 0x01000000) for x in numbers)


@attr.s(repr=False, slots=True)
class Path(ListElement):
    """
    List-like Path structure. Elements are either PathFillRule,
    InitialFillRule, ClipboardRecord, ClosedPath, or OpenPath.
Ejemplo n.º 2
0
    ShortIntegerElement,
    StringElement,
    ValueElement,
)
from psd_tools2.psd.color import Color
from psd_tools2.psd.descriptor import DescriptorBlock
from psd_tools2.utils import (read_fmt, write_fmt, read_pascal_string,
                              write_pascal_string, read_length_block,
                              write_length_block, write_bytes, new_registry,
                              read_unicode_string, write_unicode_string,
                              is_readable, trimmed_repr)
from psd_tools2.validators import in_

logger = logging.getLogger(__name__)

TYPES, register = new_registry()

TYPES.update({
    ImageResourceID.BACKGROUND_COLOR: Color,
    ImageResourceID.LAYER_COMPS: DescriptorBlock,
    ImageResourceID.MEASUREMENT_SCALE: DescriptorBlock,
    ImageResourceID.SHEET_DISCLOSURE: DescriptorBlock,
    ImageResourceID.TIMELINE_INFO: DescriptorBlock,
    ImageResourceID.ONION_SKINS: DescriptorBlock,
    ImageResourceID.COUNT_INFO: DescriptorBlock,
    ImageResourceID.PRINT_INFO_CS5: DescriptorBlock,
    ImageResourceID.PRINT_STYLE: DescriptorBlock,
    ImageResourceID.PATH_SELECTION_STATE: DescriptorBlock,
    ImageResourceID.ORIGIN_PATH_INFO: DescriptorBlock,
    ImageResourceID.AUTO_SAVE_FILE_PATH: StringElement,
    ImageResourceID.AUTO_SAVE_FORMAT: StringElement,
Ejemplo n.º 3
0
from psd_tools2.validators import in_
from psd_tools2.utils import (
    read_fmt,
    write_fmt,
    read_unicode_string,
    write_unicode_string,
    write_bytes,
    read_length_block,
    write_length_block,
    write_padding,
    new_registry,
)

logger = logging.getLogger(__name__)

TYPES, register = new_registry(attribute='ostype')

_UNKNOWN_CLASS_ID = set()


def read_length_and_key(fp):
    """
    Helper to write descriptor classID and key.
    """
    length = read_fmt('I', fp)[0]
    key = fp.read(length or 4)
    if length == 0:
        try:
            return DescriptorClassID(key)
        except ValueError:
            if key == b'\x00\x00\x00\x00':
Ejemplo n.º 4
0
    EmptyElement,
    ListElement,
    ShortIntegerElement,
)
from psd_tools2.psd.color import Color
from psd_tools2.psd.descriptor import DescriptorBlock, DescriptorBlock2
from psd_tools2.validators import in_
from psd_tools2.utils import (read_fmt, write_fmt, read_length_block,
                              write_length_block, is_readable, write_bytes,
                              read_unicode_string, write_unicode_string,
                              write_padding, read_pascal_string,
                              write_pascal_string, trimmed_repr, new_registry)

logger = logging.getLogger(__name__)

ADJUSTMENT_TYPES, register = new_registry()

ADJUSTMENT_TYPES.update({
    TaggedBlockID.BLACK_AND_WHITE: DescriptorBlock,
    TaggedBlockID.GRADIENT_FILL_SETTING: DescriptorBlock,
    TaggedBlockID.INVERT: EmptyElement,
    TaggedBlockID.PATTERN_FILL_SETTING: DescriptorBlock,
    TaggedBlockID.POSTERIZE: ShortIntegerElement,
    TaggedBlockID.SOLID_COLOR_SHEET_SETTING: DescriptorBlock,
    TaggedBlockID.THRESHOLD: ShortIntegerElement,
    TaggedBlockID.VIBRANCE: DescriptorBlock,
})


@register(TaggedBlockID.BRIGHTNESS_AND_CONTRAST)
@attr.s(slots=True)
Ejemplo n.º 5
0
    if layer.kind == 'brightnesscontrast':
        print(layer.brightness)

    if layer.kind == 'gradient-fill':
        print(layer.gradient_kind)
"""
from __future__ import absolute_import
import logging

from psd_tools2.api.layers import AdjustmentLayer, FillLayer
from psd_tools2.constants import TaggedBlockID
from psd_tools2.utils import new_registry

logger = logging.getLogger(__name__)

TYPES, register = new_registry(attribute='_KEY')


@register(TaggedBlockID.SOLID_COLOR_SHEET_SETTING)
class SolidColorFill(FillLayer):
    """Solid color fill."""
    @property
    def data(self):
        """Color in Descriptor(RGB)."""
        return self._data.get(b'Clr ')


@register(TaggedBlockID.PATTERN_FILL_SETTING)
class PatternFill(FillLayer):
    """Pattern fill."""
    @property
Ejemplo n.º 6
0
"""
from __future__ import absolute_import, unicode_literals
import attr
from collections import OrderedDict
import codecs
import io
import logging
import re
from enum import Enum
from psd_tools2.psd.base import (BooleanElement, DictElement, IntegerElement,
                                 ListElement, NumericElement, ValueElement)
from psd_tools2.utils import new_registry, trimmed_repr, write_bytes

logger = logging.getLogger(__name__)

TOKEN_CLASSES, register = new_registry()


def compile_re(pattern):
    return re.compile(pattern.encode('macroman'), re.S)


class EngineToken(Enum):
    ARRAY_END = compile_re(r'^\]$')
    ARRAY_START = compile_re(r'^\[$')
    BOOLEAN = compile_re(r'^(true|false)$')
    DICT_END = compile_re(r'^>>(\x00)*$')  # Buggy one?
    DICT_START = compile_re(r'^<<$')
    NOOP = compile_re(r'^$')
    NUMBER = compile_re(r'^-?\d+$')
    NUMBER_WITH_DECIMAL = compile_re(r'^-?\d*\.\d+$')