private void parseMaskAndAdjustmentData(PsdInputStream stream) throws IOException {
        int size = stream.readInt();
        assert size == 0 || size == 20 || size == 36;
        if (size > 0) {
            Mask mask = new Mask();
            mask.top = stream.readInt();
            mask.left = stream.readInt();
            mask.bottom = stream.readInt();
            mask.right = stream.readInt();
            mask.defaultColor = stream.readByte() & 0xff;
            assert mask.defaultColor == 0 || mask.defaultColor == 255;

            byte flags = stream.readByte();
            mask.relative = (flags & 0x01) != 0;
            mask.disabled = ((flags >> 1) & 0x01) != 0;
            mask.invert = ((flags >> 2) & 0x01) != 0;
            if (size == 20) {
                stream.skipBytes(2);
            } else {
                byte realFlags = stream.readByte();
                mask.relative = (realFlags & 0x01) != 0;
                mask.disabled = ((realFlags >> 1) & 0x01) != 0;
                mask.invert = ((realFlags >> 2) & 0x01) != 0;

                mask.defaultColor = stream.readByte() & 0xff;
                assert mask.defaultColor == 0 || mask.defaultColor == 255;

                mask.top = stream.readInt();
                mask.left = stream.readInt();
                mask.bottom = stream.readInt();
                mask.right = stream.readInt();
            }
            if (handler != null) {
                handler.maskLoaded(mask);
            }
        }
    }