예제 #1
0
        public static unsafe void Save(Document input, Stream output, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback)
        {
            bool           rle         = token.GetProperty <PaintDotNet.PropertySystem.BooleanProperty>(PropertyNames.RLE).Value;
            AbrFileVersion fileVersion = (AbrFileVersion)token.GetProperty(PropertyNames.FileVersion).Value;

            double progressPercentage = 0.0;
            double progressDelta      = (1.0 / input.Layers.Count) * 100.0;

            using (BinaryReverseWriter writer = new BinaryReverseWriter(output, true))
            {
                writer.Write((short)fileVersion);
                writer.Write((short)input.Layers.Count);

                foreach (Layer item in input.Layers)
                {
                    BitmapLayer layer = (BitmapLayer)item;

                    SaveLayer(writer, layer, fileVersion, rle);

                    progressPercentage += progressDelta;

                    progressCallback(null, new ProgressEventArgs(progressPercentage));
                }
            }
        }
예제 #2
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int        quality = token.GetProperty <Int32Property>(PropertyNames.Quality).Value;
            WebPPreset preset  = (WebPPreset)token.GetProperty(PropertyNames.Preset).Value;

            WebPFile.Save(input, output, quality, preset, scratchSurface, progressCallback);
        }
예제 #3
0
        protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
        {
            PngBitDepthUIChoices bitDepth = (PngBitDepthUIChoices)token.GetProperty<StaticListChoiceProperty>(PropertyNames.BitDepth).Value;

            // Only 32-bit is reflexive
            return (bitDepth == PngBitDepthUIChoices.Bpp32);
        }
예제 #4
0
        internal override Set <SavableBitDepths> CreateAllowedBitDepthListFromToken(PropertyBasedSaveConfigToken token)
        {
            TgaBitDepthUIChoices bitDepth = (TgaBitDepthUIChoices)token.GetProperty <StaticListChoiceProperty>(PropertyNames.BitDepth).Value;

            Set <SavableBitDepths> bitDepths = new Set <SavableBitDepths>();

            switch (bitDepth)
            {
            case TgaBitDepthUIChoices.AutoDetect:
                bitDepths.Add(SavableBitDepths.Rgb24);
                bitDepths.Add(SavableBitDepths.Rgba32);
                break;

            case TgaBitDepthUIChoices.Bpp24:
                bitDepths.Add(SavableBitDepths.Rgb24);
                break;

            case TgaBitDepthUIChoices.Bpp32:
                bitDepths.Add(SavableBitDepths.Rgba32);
                break;

            default:
                throw new InvalidEnumArgumentException("bitDepth", (int)bitDepth, typeof(TgaBitDepthUIChoices));
            }

            return(bitDepths);
        }
예제 #5
0
 protected sealed override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
 {
     try
     {
         int  num3;
         bool flag;
         bool flag2;
         int  num4;
         int  thresholdFromToken   = this.GetThresholdFromToken(token);
         int  ditherLevelFromToken = this.GetDitherLevelFromToken(token);
         HashSet <SavableBitDepths> allowedBitDepths = this.CreateAllowedBitDepthListFromToken(token);
         if (allowedBitDepths.Count == 0)
         {
             throw new ArgumentException("there must be at least 1 element returned from CreateAllowedBitDepthListFromToken()");
         }
         SavableBitDepths[] items = new SavableBitDepths[] { SavableBitDepths.Rgb8, SavableBitDepths.Rgba8 };
         if (allowedBitDepths.IsSubsetOf(HashSetUtil.Create <SavableBitDepths>(items)))
         {
             num3 = thresholdFromToken;
         }
         else
         {
             num3 = 1;
         }
         this.RenderFlattenedDocument(input, scratchSurface);
         this.Analyze(scratchSurface, out flag, out flag2, out num4);
         HashSet <SavableBitDepths> losslessBitDepths = new HashSet <SavableBitDepths> {
             SavableBitDepths.Rgba32
         };
         if (flag)
         {
             losslessBitDepths.Add(SavableBitDepths.Rgb24);
             if (num4 <= 0x100)
             {
                 losslessBitDepths.Add(SavableBitDepths.Rgb8);
             }
         }
         else if (flag2 && (num4 < 0x100))
         {
             losslessBitDepths.Add(SavableBitDepths.Rgba8);
         }
         double chooseBitDepthProgressLast = 0.0;
         ProgressEventHandler handler      = delegate(object sender, ProgressEventArgs e) {
             chooseBitDepthProgressLast = e.Percent;
             progressCallback(sender, e);
         };
         SavableBitDepths bitDepth = this.ChooseBitDepth(input, scratchSurface, ditherLevelFromToken, num3, token, handler, 0.0, 66.666666666666671, allowedBitDepths, losslessBitDepths, flag, flag2, num4);
         if (((bitDepth == SavableBitDepths.Rgba8) && (num3 == 0)) && (allowedBitDepths.Contains(SavableBitDepths.Rgba8) && allowedBitDepths.Contains(SavableBitDepths.Rgb8)))
         {
             bitDepth = SavableBitDepths.Rgb8;
         }
         this.FinalSave(input, output, scratchSurface, ditherLevelFromToken, num3, bitDepth, token, progressCallback, chooseBitDepthProgressLast, 100.0);
     }
     finally
     {
     }
 }
예제 #6
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            PSPFile file = new PSPFile();

            CompressionFormats format  = (CompressionFormats)token.GetProperty(PropertyNames.CompressionType).Value;
            FileVersion        version = (FileVersion)token.GetProperty(PropertyNames.FileVersion).Value;

            file.Save(input, output, format, scratchSurface, (ushort)version, progressCallback);
        }
예제 #7
0
        internal override Set<SavableBitDepths> CreateAllowedBitDepthListFromToken(PropertyBasedSaveConfigToken token)
        {
            var bitDepths = new Set<SavableBitDepths>();

            bitDepths.Add(SavableBitDepths.Rgb8);
            bitDepths.Add(SavableBitDepths.Rgba8);

            return bitDepths;
        }
예제 #8
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            DdsFileFormat      fileFormat      = (DdsFileFormat)token.GetProperty(PropertyNames.FileFormat).Value;
            BC7CompressionMode compressionMode = (BC7CompressionMode)token.GetProperty(PropertyNames.BC7CompressionMode).Value;
            DdsErrorMetric     errorMetric     = (DdsErrorMetric)token.GetProperty(PropertyNames.ErrorMetric).Value;
            bool           generateMipmaps     = token.GetProperty <BooleanProperty>(PropertyNames.GenerateMipMaps).Value;
            MipMapSampling mipSampling         = (MipMapSampling)token.GetProperty(PropertyNames.MipMapResamplingAlgorithm).Value;

            DdsFile.Save(input, output, fileFormat, errorMetric, compressionMode, generateMipmaps, mipSampling, scratchSurface, progressCallback);
        }
예제 #9
0
 protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
 {
     if ((TgaBitDepthUIChoices)token.GetProperty<StaticListChoiceProperty>(PropertyNames.BitDepth).Value == TgaBitDepthUIChoices.Bpp32)
     {
         return true;
     }
     else
     {
         return base.IsReflexive(token);
     }
 }
        protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
        {
            if (token.GetProperty <BooleanProperty>(PropertyNames.CubeMap).Value)
            {
                return(false);
            }

            DdsFileFormat format = (DdsFileFormat)token.GetProperty(PropertyNames.FileFormat).Value;

            return(format == DdsFileFormat.B8G8R8A8 || format == DdsFileFormat.R8G8B8A8);
        }
예제 #11
0
 protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
 {
     if ((TgaBitDepthUIChoices)token.GetProperty <StaticListChoiceProperty>(PropertyNames.BitDepth).Value == TgaBitDepthUIChoices.Bpp32)
     {
         return(true);
     }
     else
     {
         return(base.IsReflexive(token));
     }
 }
예제 #12
0
        internal override void FinalSave(
            Document input,
            Stream output,
            Surface scratchSurface,
            int ditherLevel,
            SavableBitDepths bitDepth,
            PropertyBasedSaveConfigToken token,
            ProgressEventHandler progressCallback)
        {
            bool rleCompress = token.GetProperty <BooleanProperty>(PropertyNames.RleCompress).Value;

            SaveTga(scratchSurface, output, bitDepth, rleCompress, progressCallback);
        }
예제 #13
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            scratchSurface.Clear(ColorBgra.Zero);
            using (RenderArgs args = new RenderArgs(scratchSurface))
            {
                input.Render(args, true);
            }
            DdsFileFormat     fileFormat     = (DdsFileFormat)token.GetProperty <StaticListChoiceProperty>(PropertyNames.FileFormat).Value;
            DdsCompressorType compressorType = (DdsCompressorType)token.GetProperty <StaticListChoiceProperty>(PropertyNames.CompressorType).Value;
            DdsErrorMetric    errorMetric    = (DdsErrorMetric)token.GetProperty <StaticListChoiceProperty>(PropertyNames.ErrorMetric).Value;
            bool weightColorByAlpha          = token.GetProperty <BooleanProperty>(PropertyNames.WeightColorByAlpha).Value;
            bool generateMipMaps             = token.GetProperty <BooleanProperty>(PropertyNames.GenerateMipMaps).Value;
            ResamplingAlgorithm mipMapResamplingAlgorithm = (ResamplingAlgorithm)token.GetProperty <StaticListChoiceProperty>(PropertyNames.MipMapResamplingAlgorithm).Value;

            new DdsFile().Save(output, scratchSurface, fileFormat, compressorType, errorMetric, generateMipMaps, mipMapResamplingAlgorithm, weightColorByAlpha, callback);
        }
예제 #14
0
        /// <summary>
        /// Saves a document to a stream respecting the properties
        /// </summary>
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int quality = token.GetProperty <Int32Property>(PropertyNames.Quality).Value;
            CompressionSpeed     compressionSpeed  = (CompressionSpeed)token.GetProperty(PropertyNames.CompressionSpeed).Value;
            YUVChromaSubsampling chromaSubsampling = (YUVChromaSubsampling)token.GetProperty(PropertyNames.YUVChromaSubsampling).Value;
            bool preserveExistingTileSize          = token.GetProperty <BooleanProperty>(PropertyNames.PreserveExistingTileSize).Value;

            AvifFile.Save(input,
                          output,
                          quality,
                          compressionSpeed,
                          chromaSubsampling,
                          preserveExistingTileSize,
                          this.maxEncoderThreadsOverride,
                          scratchSurface,
                          progressCallback,
                          this.byteArrayPool.Value);
        }
예제 #15
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int               num            = token.GetProperty <Int32Property>(PropertyNames.Quality).Value;
            ImageCodecInfo    imageCodecInfo = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters encoderParams  = new EncoderParameters(1);
            EncoderParameter  parameter      = new EncoderParameter(Encoder.Quality, (long)num);

            encoderParams.Param[0] = parameter;
            scratchSurface.Clear(ColorBgra.White);
            using (RenderArgs args = new RenderArgs(scratchSurface))
            {
                input.Render(args, false);
            }
            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, imageCodecInfo, encoderParams);
            }
        }
예제 #16
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int quality = token.GetProperty<Int32Property>(PropertyNames.Quality).Value;

            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, false);
            }

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
예제 #17
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int quality = (int)token.GetProperty(PropertyNames.Quality).Value;

            FileIO.EncodeParams parameters = new FileIO.EncodeParams();
            parameters.quality = quality;

            switch (input.DpuUnit)
            {
            case MeasurementUnit.Centimeter:
                parameters.dpcmX = input.DpuX;
                parameters.dpcmY = input.DpuY;
                break;

            case MeasurementUnit.Inch:
                parameters.dpcmX = Document.DotsPerInchToDotsPerCm(input.DpuX);
                parameters.dpcmY = Document.DotsPerInchToDotsPerCm(input.DpuY);
                break;

            case MeasurementUnit.Pixel:
                parameters.dpcmX = Document.DefaultDpcm;
                parameters.dpcmY = Document.DefaultDpcm;
                break;
            }

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            FileIO.EncodeFile(
                scratchSurface.Scan0.Pointer,
                scratchSurface.Width,
                scratchSurface.Height,
                scratchSurface.Stride,
                CountChannels(scratchSurface),
                parameters,
                output);
        }
예제 #18
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            var quality = (int)token.GetProperty(PropertyNames.Quality).Value;
            var comment = (string)token.GetProperty(PropertyNames.Comment).Value;

            using (var args = new RenderArgs(scratchSurface))
                input.Render(args, false);

            var enc = new WsqEncoder();

            byte[] bytes = null;
            using (var bitmap = scratchSurface.CreateAliasedBitmap())
            {
                SetResolution(bitmap, input);
                enc.Comment = comment;
                bytes       = enc.EncodeQualityGdi(bitmap, quality);
            }

            if (bytes != null)
            {
                output.Write(bytes, 0, (int)bytes.Length);
            }
        }
예제 #19
0
 internal override int GetDitherLevelFromToken(PropertyBasedSaveConfigToken token) =>
 token.GetProperty <Int32Property>(PropertyNames.DitherLevel).Value;
예제 #20
0
 internal SavableBitDepths ChooseBitDepth(Document input, Surface scratchSurface, int ditherLevel, int threshold, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback, double progressStart, double progressEnd, HashSet <SavableBitDepths> allowedBitDepths, HashSet <SavableBitDepths> losslessBitDepths, bool allOpaque, bool all0Or255Alpha, int uniqueColorCount)
 {
     if (allowedBitDepths.Count == 0)
     {
         throw new ArgumentException("Count must be 1 or more", "allowedBitDepths");
     }
     try
     {
         HashSet <SavableBitDepths> set2;
         if (allowedBitDepths.Count == 1)
         {
             return(allowedBitDepths.First <SavableBitDepths>());
         }
         HashSet <SavableBitDepths> source = HashSetUtil.Intersect <SavableBitDepths>(allowedBitDepths, losslessBitDepths);
         if (source.Count == 1)
         {
             return(source.First <SavableBitDepths>());
         }
         if (source.Count == 0)
         {
             set2 = allowedBitDepths;
         }
         else
         {
             set2 = source;
         }
         long num = input.Width * input.Height;
         if (((all0Or255Alpha && (uniqueColorCount <= 0xff)) && ((num <= 0x10000L) && set2.Contains(SavableBitDepths.Rgb8))) && set2.Contains(SavableBitDepths.Rgb24))
         {
             long num2 = 0L;
             long num3 = 0L;
             try
             {
                 num2 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgb8, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 0.0, 50.0);
                 num3 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgb24, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 50.0, 100.0);
             }
             catch (OutOfMemoryException)
             {
                 return(SavableBitDepths.Rgb8);
             }
             if (num2 < num3)
             {
                 return(SavableBitDepths.Rgb8);
             }
             return(SavableBitDepths.Rgb24);
         }
         if (((all0Or255Alpha && (uniqueColorCount <= 0xff)) && ((num < 0x10000L) && set2.Contains(SavableBitDepths.Rgba8))) && set2.Contains(SavableBitDepths.Rgba32))
         {
             long num4 = 0L;
             long num5 = 0L;
             try
             {
                 num4 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgba8, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 0.0, 50.0);
                 num5 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgba32, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 50.0, 100.0);
             }
             catch (OutOfMemoryException)
             {
                 return(SavableBitDepths.Rgba8);
             }
             if (num4 < num5)
             {
                 return(SavableBitDepths.Rgba8);
             }
             return(SavableBitDepths.Rgba32);
         }
         if ((set2.Contains(SavableBitDepths.Rgb8) & allOpaque) && (uniqueColorCount <= 0x100))
         {
             return(SavableBitDepths.Rgb8);
         }
         if ((set2.Contains(SavableBitDepths.Rgba8) & all0Or255Alpha) && (uniqueColorCount <= 0xff))
         {
             return(SavableBitDepths.Rgba8);
         }
         if (!(set2.Contains(SavableBitDepths.Rgb24) & allOpaque))
         {
             if (set2.Contains(SavableBitDepths.Rgba32))
             {
                 return(SavableBitDepths.Rgba32);
             }
             SavableBitDepths[] items = new SavableBitDepths[] { SavableBitDepths.Rgb8, SavableBitDepths.Rgb24 };
             if (set2.SetEquals(HashSetUtil.Create <SavableBitDepths>(items)))
             {
                 return(SavableBitDepths.Rgb24);
             }
             SavableBitDepths[] depthsArray2 = new SavableBitDepths[] { SavableBitDepths.Rgb8, SavableBitDepths.Rgba8 };
             if (set2.SetEquals(HashSetUtil.Create <SavableBitDepths>(depthsArray2)))
             {
                 return(SavableBitDepths.Rgba8);
             }
             SavableBitDepths[] depthsArray3 = new SavableBitDepths[] { SavableBitDepths.Rgba8, SavableBitDepths.Rgb24 };
             if (!set2.SetEquals(HashSetUtil.Create <SavableBitDepths>(depthsArray3)))
             {
                 throw new ArgumentException("Could not accomodate input values -- internal error?");
             }
         }
         return(SavableBitDepths.Rgb24);
     }
     finally
     {
     }
 }
예제 #21
0
 internal abstract void OnFinalSave(Document input, Stream output, Surface flattenedImage, int ditherLevel, SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback);
예제 #22
0
 private long GetSavableBitDepthFileLength(SavableBitDepths bitDepth, Document input, Surface scratchSurface, int ditherLevel, int threshold, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback, double progressStart, double progressEnd)
 {
     scratchSurface.Clear(ColorBgra.Zero);
     using (SegmentedMemoryStream stream = new SegmentedMemoryStream())
     {
         this.FinalSave(input, stream, scratchSurface, ditherLevel, threshold, bitDepth, token, progressCallback, progressStart, progressEnd);
         stream.Flush();
         return(stream.Length);
     }
 }
예제 #23
0
        private unsafe void FinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, int threshold, SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback, double progressStart, double progressEnd)
        {
            this.RenderFlattenedDocument(input, scratchSurface);
            if (((bitDepth == SavableBitDepths.Rgb8) || (bitDepth == SavableBitDepths.Rgba8)) || (bitDepth == SavableBitDepths.Rgb24))
            {
                ColorBgra white = ColorBgra.White;
                Work.ParallelFor(WaitType.Blocking, 0, scratchSurface.Height, delegate(int y) {
                    int width             = scratchSurface.Width;
                    ColorBgra *rowAddress = scratchSurface.GetRowAddress(y);
                    for (int j = 0; j < width; j++)
                    {
                        ColorBgra rhs = rowAddress[0];
                        if ((bitDepth == SavableBitDepths.Rgba8) && (rhs.A < threshold))
                        {
                            rowAddress->Bgra = 0;
                        }
                        else
                        {
                            rowAddress->Bgra = CompositionOps.Normal.ApplyStatic(white, rhs).Bgra;
                        }
                        rowAddress++;
                    }
                }, WorkItemQueuePriority.Normal, null);
            }
            ProgressEventHandler handler = (sender, e) => progressCallback(sender, new ProgressEventArgs(progressStart + ((progressEnd - progressStart) * (e.Percent / 100.0))));

            this.OnFinalSave(input, output, scratchSurface, ditherLevel, bitDepth, token, handler);
        }
예제 #24
0
        internal override void OnFinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, InternalFileType.SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback)
        {
            int    num;
            Bitmap bitmap;
            Func <PropertyItem, bool> func;
            ImageCodecInfo            imageCodecInfo = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Png);
            EncoderParameters         encoderParams  = new EncoderParameters(1);

            if (bitDepth == InternalFileType.SavableBitDepths.Rgba32)
            {
                num    = 0x20;
                bitmap = scratchSurface.CreateAliasedBitmap();
            }
            else if (bitDepth == InternalFileType.SavableBitDepths.Rgb24)
            {
                base.SquishSurfaceTo24Bpp(scratchSurface);
                num    = 0x18;
                bitmap = base.CreateAliased24BppBitmap(scratchSurface);
            }
            else if (bitDepth == InternalFileType.SavableBitDepths.Rgb8)
            {
                num    = 8;
                bitmap = base.Quantize(scratchSurface, ditherLevel, 0x100, false, progressCallback);
            }
            else
            {
                if (bitDepth != InternalFileType.SavableBitDepths.Rgba8)
                {
                    throw ExceptionUtil.InvalidEnumArgumentException <InternalFileType.SavableBitDepths>(bitDepth, "bitDepth");
                }
                num    = 8;
                bitmap = base.Quantize(scratchSurface, ditherLevel, 0x100, true, progressCallback);
            }
            EncoderParameter parameter = new EncoderParameter(Encoder.ColorDepth, (long)num);

            encoderParams.Param[0] = parameter;
            if (num == 0x20)
            {
                func = pi => true;
            }
            else
            {
                int iccProfileDataID = 0x8773;
                func = pi => pi.Id != iccProfileDataID;
            }
            GdiPlusFileType.LoadProperties(bitmap, input, func);
            bitmap.Save(output, imageCodecInfo, encoderParams);
            bitmap.Dispose();
            bitmap = null;
        }
예제 #25
0
 internal override int GetDitherLevelFromToken(PropertyBasedSaveConfigToken token)
 {
     int ditherLevel = token.GetProperty<Int32Property>(PropertyNames.DitherLevel).Value;
     return ditherLevel;
 }
예제 #26
0
 protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
 {
     return false;
 }
예제 #27
0
        internal override void FinalSave(
            Document input, 
            Stream output, 
            Surface scratchSurface, 
            int ditherLevel, 
            SavableBitDepths bitDepth,
            PropertyBasedSaveConfigToken token,
            ProgressEventHandler progressCallback)
        {
            bool enableAlpha;

            switch (bitDepth)
            {
                case SavableBitDepths.Rgb8:
                    enableAlpha = false;
                    break;

                case SavableBitDepths.Rgba8:
                    enableAlpha = true;
                    break;

                default:
                    throw new InvalidEnumArgumentException("bitDepth", (int)bitDepth, typeof(SavableBitDepths));
            }

            using (Bitmap quantized = Quantize(scratchSurface, ditherLevel, 256, enableAlpha, progressCallback))
            {
                quantized.Save(output, ImageFormat.Gif);
            }
        }
예제 #28
0
 internal override int GetThresholdFromToken(PropertyBasedSaveConfigToken token)
 {
     return(0);
 }
예제 #29
0
 internal override int GetDitherLevelFromToken(PropertyBasedSaveConfigToken token)
 {
     return(0);
 }
예제 #30
0
 protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
 {
     AbrSave.Save(input, output, token, progressCallback);
 }
예제 #31
0
 internal override int GetThresholdFromToken(PropertyBasedSaveConfigToken token) =>
 token.GetProperty <Int32Property>(PropertyNames.Threshold).Value;
예제 #32
0
 internal override int GetThresholdFromToken(PropertyBasedSaveConfigToken token)
 {
     return 0;
 }
예제 #33
0
        protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
        {
            PngBitDepthUIChoices choices = (PngBitDepthUIChoices)token.GetProperty <StaticListChoiceProperty>(PropertyNames.BitDepth).Value;

            return(choices == PngBitDepthUIChoices.Bpp32);
        }
예제 #34
0
        internal override Set<SavableBitDepths> CreateAllowedBitDepthListFromToken(PropertyBasedSaveConfigToken token)
        {
            BmpBitDepthUIChoices bitDepth = (BmpBitDepthUIChoices)token.GetProperty<StaticListChoiceProperty>(PropertyNames.BitDepth).Value;

            Set<SavableBitDepths> bitDepths = new Set<SavableBitDepths>();

            switch (bitDepth)
            {
                case BmpBitDepthUIChoices.AutoDetect:
                    bitDepths.Add(SavableBitDepths.Rgb24);
                    bitDepths.Add(SavableBitDepths.Rgb8);
                    break;

                case BmpBitDepthUIChoices.Bpp24:
                    bitDepths.Add(SavableBitDepths.Rgb24);
                    break;

                case BmpBitDepthUIChoices.Bpp8:
                    bitDepths.Add(SavableBitDepths.Rgb8);
                    break;

                default:
                    throw new InvalidEnumArgumentException("bitDepth", (int)bitDepth, typeof(BmpBitDepthUIChoices));
            }

            return bitDepths;
        }
예제 #35
0
 internal abstract HashSet <SavableBitDepths> CreateAllowedBitDepthListFromToken(PropertyBasedSaveConfigToken token);
예제 #36
0
        internal override void FinalSave(
            Document input, 
            Stream output, 
            Surface scratchSurface, 
            int ditherLevel, 
            SavableBitDepths bitDepth,
            PropertyBasedSaveConfigToken token,
            ProgressEventHandler progressCallback)
        {
            // finally, do the save.
            if (bitDepth == SavableBitDepths.Rgb24)
            {
                // In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place
                // instead of allocating a new bitmap and copying it over.
                SquishSurfaceTo24Bpp(scratchSurface);

                ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp);
                EncoderParameters parms = new EncoderParameters(1);
                EncoderParameter parm = new EncoderParameter(Encoder.ColorDepth, 24);
                parms.Param[0] = parm;

                using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface))
                {
                    GdiPlusFileType.LoadProperties(bitmap, input);
                    bitmap.Save(output, icf, parms);
                }
            }
            else if (bitDepth == SavableBitDepths.Rgb8)
            {
                using (Bitmap quantized = Quantize(scratchSurface, ditherLevel, 256, false, progressCallback))
                {
                    ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp);
                    EncoderParameters parms = new EncoderParameters(1);
                    EncoderParameter parm = new EncoderParameter(Encoder.ColorDepth, 8);
                    parms.Param[0] = parm;

                    GdiPlusFileType.LoadProperties(quantized, input);
                    quantized.Save(output, icf, parms);
                }
            }
            else
            {
                throw new InvalidEnumArgumentException("bitDepth", (int)bitDepth, typeof(SavableBitDepths));
            }
        }
예제 #37
0
 internal abstract int GetDitherLevelFromToken(PropertyBasedSaveConfigToken token);
예제 #38
0
 internal override int GetDitherLevelFromToken(PropertyBasedSaveConfigToken token)
 {
     return 0;
 }
예제 #39
0
 internal abstract int GetThresholdFromToken(PropertyBasedSaveConfigToken token);
예제 #40
0
 internal override void FinalSave(
     Document input, 
     Stream output, 
     Surface scratchSurface, 
     int ditherLevel, 
     SavableBitDepths bitDepth, 
     PropertyBasedSaveConfigToken token, 
     ProgressEventHandler progressCallback)
 {
     bool rleCompress = token.GetProperty<BooleanProperty>(PropertyNames.RleCompress).Value;
     SaveTga(scratchSurface, output, bitDepth, rleCompress, progressCallback);
 }
예제 #41
0
        protected unsafe override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            using (RenderArgs ra = new RenderArgs(scratchSurface)) {
                input.Render(ra, true);
            }

            int w = token.GetProperty<Int32Property>(PropertyNames.HorizCellSize).Value;
            int h = token.GetProperty<Int32Property>(PropertyNames.VerticalCellSize).Value;
            int W = scratchSurface.Width, H = scratchSurface.Height;

            string chars;
            PresetCharacters preset = (PresetCharacters)token.GetProperty<StaticListChoiceProperty>(PropertyNames.PresetCharacters).Value;
            switch (preset) {
                case PresetCharacters.Custom:
                    chars = token.GetProperty<StringProperty>(PropertyNames.Characters).Value;
                    break;
                case PresetCharacters.AsciiChars:
                    chars = asciiChars;
                    break;
                case PresetCharacters.Blocks:
                    chars = blocks;
                    break;
                default:
                    chars = "";
                    break;
            }
            if (chars.Length == 0) {
                chars = asciiChars;
            }

            // Special case where 1 cell corresponds directly to 1 pixel
            // Written separately for performance
            if (h == 1 && w == 1) {
                StreamWriter writer = new StreamWriter(output);
                for (int y = 0; y < H; y++) {
                    ColorBgra* current = scratchSurface.GetRowAddressUnchecked(y);
                    for (int x = 0; x < W; x++) {
                        int pos = (int)((1 - current->GetIntensity()) * chars.Length);
                        char c = chars[pos == chars.Length ? pos - 1 : pos];
                        writer.Write(c);
                        current++;
                    }
                    if (y != H - 1) {
                        writer.WriteLine();
                    }
                }
                writer.Flush();
            } else {
                double[,] totals = new double[W / w, H / h];
                for (int y = 0; y < H / h * h; y++) {
                    ColorBgra* current = scratchSurface.GetRowAddressUnchecked(y);
                    for (int x = 0; x < W / w * w; x++) {
                        totals[x / w, y / h] += 1 - current->GetIntensity();
                        current++;
                    }
                }

                int ppc = w * h;
                StreamWriter writer = new StreamWriter(output);
                for (int y = 0; y < H / h; y++) {
                    for (int x = 0; x < W / w; x++) {
                        int pos = (int)(totals[x, y] / ppc * chars.Length);
                        char c = chars[pos == chars.Length ? pos - 1 : pos];
                        writer.Write(c);
                    }
                    if (y != H / h - 1) {
                        writer.WriteLine();
                    }
                }
                writer.Flush();
            }
        }
예제 #42
0
        internal override HashSet <InternalFileType.SavableBitDepths> CreateAllowedBitDepthListFromToken(PropertyBasedSaveConfigToken token)
        {
            PngBitDepthUIChoices choices = (PngBitDepthUIChoices)token.GetProperty <StaticListChoiceProperty>(PropertyNames.BitDepth).Value;
            HashSet <InternalFileType.SavableBitDepths> collection = new HashSet <InternalFileType.SavableBitDepths>();

            switch (choices)
            {
            case PngBitDepthUIChoices.AutoDetect:
                collection.AddRange <InternalFileType.SavableBitDepths>(new InternalFileType.SavableBitDepths[] { InternalFileType.SavableBitDepths.Rgb24 });
                return(collection);

            case PngBitDepthUIChoices.Bpp32:
                collection.AddRange <InternalFileType.SavableBitDepths>(new InternalFileType.SavableBitDepths[1]);
                return(collection);

            case PngBitDepthUIChoices.Bpp24:
            {
                InternalFileType.SavableBitDepths[] items = new InternalFileType.SavableBitDepths[] { InternalFileType.SavableBitDepths.Rgb24 };
                collection.AddRange <InternalFileType.SavableBitDepths>(items);
                return(collection);
            }

            case PngBitDepthUIChoices.Bpp8:
            {
                InternalFileType.SavableBitDepths[] depthsArray2 = new InternalFileType.SavableBitDepths[] { InternalFileType.SavableBitDepths.Rgb8, InternalFileType.SavableBitDepths.Rgba8 };
                collection.AddRange <InternalFileType.SavableBitDepths>(depthsArray2);
                return(collection);
            }
            }
            throw ExceptionUtil.InvalidEnumArgumentException <PngBitDepthUIChoices>(choices, "bitDepthFromToken");
        }
예제 #43
0
        protected override bool IsReflexive(PropertyBasedSaveConfigToken token)
        {
            DdsFileFormat format = (DdsFileFormat)token.GetProperty(PropertyNames.FileFormat).Value;

            return(format == DdsFileFormat.B8G8R8A8 || format == DdsFileFormat.R8G8B8A8);
        }
예제 #44
0
 internal override int GetThresholdFromToken(PropertyBasedSaveConfigToken token)
 {
     int threshold = token.GetProperty<Int32Property>(PropertyNames.Threshold).Value;
     return threshold;
 }