Esempio n. 1
0
        public unsafe IntPtr CreateReadImageDocumentPointer(FilterCase filterCase, bool hasSelection)
        {
            IntPtr readDocumentPtr = Memory.Allocate(Marshal.SizeOf(typeof(ReadImageDocumentDesc)), true);

            try
            {
                ReadImageDocumentDesc *doc = (ReadImageDocumentDesc *)readDocumentPtr.ToPointer();
                doc->minVersion = PSConstants.kCurrentMinVersReadImageDocDesc;
                doc->maxVersion = PSConstants.kCurrentMaxVersReadImageDocDesc;
                doc->imageMode  = (int)imageMode;

                switch (imageMode)
                {
                case ImageModes.GrayScale:
                case ImageModes.RGB:
                    doc->depth = 8;
                    break;

                case ImageModes.Gray16:
                case ImageModes.RGB48:
                    doc->depth = 16;
                    break;
                }

                doc->bounds.top    = 0;
                doc->bounds.left   = 0;
                doc->bounds.right  = documentWidth;
                doc->bounds.bottom = documentHeight;
                doc->hResolution   = new Fixed16((int)(dpiX + 0.5));
                doc->vResolution   = new Fixed16((int)(dpiY + 0.5));

                if (imageMode == ImageModes.RGB || imageMode == ImageModes.RGB48)
                {
                    IntPtr channel = CreateReadChannelDesc(PSConstants.ChannelPorts.Red, Resources.RedChannelName, doc->depth, doc->bounds);

                    ReadChannelDesc *ch = (ReadChannelDesc *)channel.ToPointer();

                    for (int i = PSConstants.ChannelPorts.Green; i <= PSConstants.ChannelPorts.Blue; i++)
                    {
                        string name = null;
                        switch (i)
                        {
                        case PSConstants.ChannelPorts.Green:
                            name = Resources.GreenChannelName;
                            break;

                        case PSConstants.ChannelPorts.Blue:
                            name = Resources.BlueChannelName;
                            break;
                        }

                        IntPtr ptr = CreateReadChannelDesc(i, name, doc->depth, doc->bounds);

                        ch->next = ptr;

                        ch = (ReadChannelDesc *)ptr.ToPointer();
                    }

                    doc->targetCompositeChannels = doc->mergedCompositeChannels = channel;

                    if (filterCase == FilterCase.EditableTransparencyNoSelection || filterCase == FilterCase.EditableTransparencyWithSelection)
                    {
                        IntPtr alphaPtr = CreateReadChannelDesc(PSConstants.ChannelPorts.Alpha, Resources.AlphaChannelName, doc->depth, doc->bounds);
                        doc->targetTransparency = doc->mergedTransparency = alphaPtr;
                    }
                }
                else if (imageMode == ImageModes.GrayScale || imageMode == ImageModes.Gray16)
                {
                    IntPtr channel = CreateReadChannelDesc(PSConstants.ChannelPorts.Gray, Resources.GrayChannelName, doc->depth, doc->bounds);
                    doc->targetCompositeChannels = doc->mergedCompositeChannels = channel;
                }
                else if (imageMode == ImageModes.CMYK)
                {
                    IntPtr channel = CreateReadChannelDesc(PSConstants.ChannelPorts.Cyan, Resources.CyanChannelName, doc->depth, doc->bounds);

                    ReadChannelDesc *ch = (ReadChannelDesc *)channel.ToPointer();

                    for (int i = PSConstants.ChannelPorts.Magenta; i <= PSConstants.ChannelPorts.Black; i++)
                    {
                        string name = null;
                        switch (i)
                        {
                        case PSConstants.ChannelPorts.Magenta:
                            name = Resources.MagentaChannelName;
                            break;

                        case PSConstants.ChannelPorts.Yellow:
                            name = Resources.YellowChannelName;
                            break;

                        case PSConstants.ChannelPorts.Black:
                            name = Resources.BlackChannelName;
                            break;
                        }

                        IntPtr ptr = CreateReadChannelDesc(i, name, doc->depth, doc->bounds);

                        ch->next = ptr;

                        ch = (ReadChannelDesc *)ptr.ToPointer();
                    }

                    doc->targetCompositeChannels = doc->mergedCompositeChannels = channel;
                }
                else
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unsupported image mode: {0}", imageMode));
                }

                if (hasSelection)
                {
                    IntPtr selectionPtr = CreateReadChannelDesc(PSConstants.ChannelPorts.SelectionMask, Resources.MaskChannelName, doc->depth, doc->bounds);
                    doc->selection = selectionPtr;
                }
            }
            catch (Exception)
            {
                if (readDocumentPtr != IntPtr.Zero)
                {
                    Memory.Free(readDocumentPtr);
                }

                throw;
            }

            return(readDocumentPtr);
        }
        public unsafe IntPtr CreateReadImageDocumentPointer(FilterCase filterCase, bool hasSelection)
        {
            IntPtr readDocumentPtr = Memory.Allocate(Marshal.SizeOf(typeof(ReadImageDocumentDesc)), true);

            try
            {
                ReadImageDocumentDesc *doc = (ReadImageDocumentDesc *)readDocumentPtr.ToPointer();
                doc->minVersion = PSConstants.kCurrentMinVersReadImageDocDesc;
                doc->maxVersion = PSConstants.kCurrentMaxVersReadImageDocDesc;
                doc->imageMode  = PSConstants.plugInModeRGBColor;
                doc->depth      = 8;

                doc->bounds.top    = 0;
                doc->bounds.left   = 0;
                doc->bounds.right  = documentWidth;
                doc->bounds.bottom = documentHeight;
                doc->hResolution   = new Fixed16((int)(dpiX + 0.5));
                doc->vResolution   = new Fixed16((int)(dpiY + 0.5));

                IntPtr channel = CreateReadChannelDesc(PSConstants.ChannelPorts.Red, Resources.RedChannelName, doc->depth, doc->bounds);

                ReadChannelDesc *ch = (ReadChannelDesc *)channel.ToPointer();

                for (int i = PSConstants.ChannelPorts.Green; i <= PSConstants.ChannelPorts.Blue; i++)
                {
                    string name = null;
                    switch (i)
                    {
                    case PSConstants.ChannelPorts.Green:
                        name = Resources.GreenChannelName;
                        break;

                    case PSConstants.ChannelPorts.Blue:
                        name = Resources.BlueChannelName;
                        break;
                    }

                    IntPtr ptr = CreateReadChannelDesc(i, name, doc->depth, doc->bounds);

                    ch->next = ptr;

                    ch = (ReadChannelDesc *)ptr.ToPointer();
                }

                doc->targetCompositeChannels = doc->mergedCompositeChannels = channel;

                if (filterCase == FilterCase.EditableTransparencyNoSelection || filterCase == FilterCase.EditableTransparencyWithSelection)
                {
                    IntPtr alphaPtr = CreateReadChannelDesc(PSConstants.ChannelPorts.Alpha, Resources.AlphaChannelName, doc->depth, doc->bounds);
                    doc->targetTransparency = doc->mergedTransparency = alphaPtr;
                }

                if (hasSelection)
                {
                    IntPtr selectionPtr = CreateReadChannelDesc(PSConstants.ChannelPorts.SelectionMask, Resources.MaskChannelName, doc->depth, doc->bounds);
                    doc->selection = selectionPtr;
                }
            }
            catch (Exception)
            {
                if (readDocumentPtr != IntPtr.Zero)
                {
                    Memory.Free(readDocumentPtr);
                }

                throw;
            }

            return(readDocumentPtr);
        }
Esempio n. 3
0
 public FilterCaseInfo this[FilterCase filterCase] => this[(int)filterCase - 1];