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"); }
private void SaveTga(Surface input, Stream output, InternalFileType.SavableBitDepths bitDepth, bool rleCompress, ProgressEventHandler progressCallback) { TgaHeader header = new TgaHeader { idLength = 0, cmapType = 0, imageType = rleCompress ? TgaType.RleRgb : TgaType.Rgb, cmapIndex = 0, cmapLength = 0, cmapEntrySize = 0, xOrigin = 0, yOrigin = 0, imageWidth = (ushort)input.Width, imageHeight = (ushort)input.Height, imageDesc = 0 }; if (bitDepth != InternalFileType.SavableBitDepths.Rgba32) { if (bitDepth != InternalFileType.SavableBitDepths.Rgb24) { throw ExceptionUtil.InvalidEnumArgumentException <InternalFileType.SavableBitDepths>(bitDepth, "bitDepth"); } } else { header.pixelDepth = 0x20; header.imageDesc = (byte)(header.imageDesc | 8); goto Label_00AC; } header.pixelDepth = 0x18; Label_00AC: header.Write(output); for (int i = input.Height - 1; i >= 0; i--) { if (rleCompress) { SaveTgaRowRle(output, input, ref header, i); } else { SaveTgaRowRaw(output, input, ref header, i); } if (progressCallback != null) { progressCallback(this, new ProgressEventArgs(100.0 * (((double)(input.Height - i)) / ((double)input.Height)))); } } }
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; }
internal override void OnFinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, InternalFileType.SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback) { bool rleCompress = token.GetProperty <BooleanProperty>(PropertyNames.RleCompress).Value; this.SaveTga(scratchSurface, output, bitDepth, rleCompress, progressCallback); }
internal override void OnFinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, InternalFileType.SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback) { if (bitDepth == InternalFileType.SavableBitDepths.Rgb24) { base.SquishSurfaceTo24Bpp(scratchSurface); ImageCodecInfo imageCodecInfo = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp); EncoderParameters encoderParams = new EncoderParameters(1); EncoderParameter parameter = new EncoderParameter(Encoder.ColorDepth, 0x18); encoderParams.Param[0] = parameter; using (Bitmap bitmap = base.CreateAliased24BppBitmap(scratchSurface)) { GdiPlusFileType.LoadProperties(bitmap, input); bitmap.Save(output, imageCodecInfo, encoderParams); return; } } if (bitDepth == InternalFileType.SavableBitDepths.Rgb8) { using (Bitmap bitmap2 = base.Quantize(scratchSurface, ditherLevel, 0x100, false, progressCallback)) { ImageCodecInfo encoder = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp); EncoderParameters parameters2 = new EncoderParameters(1); EncoderParameter parameter2 = new EncoderParameter(Encoder.ColorDepth, 8); parameters2.Param[0] = parameter2; GdiPlusFileType.LoadProperties(bitmap2, input); bitmap2.Save(output, encoder, parameters2); return; } } throw ExceptionUtil.InvalidEnumArgumentException <InternalFileType.SavableBitDepths>(bitDepth, "bitDepth"); }
internal override void OnFinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, InternalFileType.SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback) { bool flag; if (bitDepth != InternalFileType.SavableBitDepths.Rgb8) { if (bitDepth != InternalFileType.SavableBitDepths.Rgba8) { throw ExceptionUtil.InvalidEnumArgumentException <InternalFileType.SavableBitDepths>(bitDepth, "bitDepth"); } } else { flag = false; goto Label_0021; } flag = true; Label_0021: using (Bitmap bitmap = base.Quantize(scratchSurface, ditherLevel, 0x100, flag, progressCallback)) { bitmap.Save(output, ImageFormat.Gif); } }