Files
UVtools/UVtools.Core/FileFormats/ImageFile.cs
T
Tiago Conceição 95020ce2f1 v2.19.0
- **File formats:**
   - Add and remove some image types that can be open
   - (Add) `CanProcess` method to know if a file can be read under a format and to allow diferent formats with same extension
   - (Fix) `LiftHeightTotal` and `RetractHeight` was rounding to no decimals and returning wrong values
   - (Improvement) Round all float setters on `Layer` class
   - (Improvement) Decode/encode RAM usage and performance by processing in batch groups
- **Pixel Dimming:** (#262)
   - (Add) Option "Lightening pixels" to add brightness/lightening instead of dimming/subtract pixels
   - (Fix) "Dim walls only" would reset body brightness by increase pixel brightness two times it value
- **Pixel Arithmetic:**
   - (Change) Transpose "Pixel Dimming" to "Pixel Arithmetic"
   - (Improvement) New options and manipulations
- **(Fix) Exposure time finder:**
  - Generate top staircase based on selected measure (px or mm)
  - Zebra bars when used in mm measures, it was using X density instead Y to calculate the thickness
  - Move 'Unit of measure' to 'Object configuration'
  - Custom text with wrong Y position when using out of portion resolutions/LCDs
- **CTBv4:**
  - (Fix) More Unknown fields discovered and implemented
  - (Fix) Reserved table is 384 bytes instead of 420
  - (Fix) When full encoding it was forcing to change to version 3. This also affected convertions. (#263)
  - (Fix) `BottomRetractHeight2` was being set to `BottomRetractSpeed2`
  - (Fix) `RetractHeight2` was being set to `RetracSpeed2`
  - (Fix) The PrintParametersV4 table address
  - (Fix) Generates invalid files to open with Chitubox and printers (#263)
  - (Fix) Better progress report
- **(Add) PrusaSlicer printer notes variables:**
  - BottomLiftHeight2
  - BottomLiftSpeed2
  - LiftHeight2
  - LiftSpeed2
  - BottomRetractSpeed
  - BottomRetractSpeed2
  - BottomRetractHeight2
  - BottomRetractSpeed2
  - RetractHeight2
  - RetractSpeed2
- **UI:**
  - (Add) File - Open current file folder (Ctrl+Shift+L): Locate and open the folder that contain the current loaded file
  - (Improvement) Hide some virtual extensions from file open dialog filters
  - (Improvement) UI: Refresh active thumbnail when changed
  - (Change) Icon for File - Open and Open in a new file
  - (Change) Rename File - Extract to: Extract file contents
- (Upgrade) AvaloniaUI from 0.10.6 to 0.10.7
- (Fix) PW0, PWM, PWMX, PWMO, PWMS: Unable to decode some files with AntiAliasing (#143)
2021-08-17 20:17:08 +01:00

123 lines
4.1 KiB
C#

using System;
using Emgu.CV;
using Emgu.CV.CvEnum;
using UVtools.Core.Operations;
using Size = System.Drawing.Size;
namespace UVtools.Core.FileFormats
{
public class ImageFile : FileFormat
{
public override FileFormatType FileType => FileFormatType.Binary;
public override FileExtension[] FileExtensions { get; } =
{
new (typeof(ImageFile), "png", "PNG: Portable Network Graphics"),
new (typeof(ImageFile), "jpg", "JPG: Joint Photographic Experts Group"),
new (typeof(ImageFile), "jpeg", "JPEG: Joint Photographic Experts Group"),
new (typeof(ImageFile), "jp2", "JP2: Joint Photographic Experts Group (JPEG 2000)"),
//new (typeof(ImageFile), "tga", "TGA: Truevision"),
new (typeof(ImageFile), "tif", "TIF: Tag Image File Format"),
new (typeof(ImageFile), "tiff", "TIFF: Tag Image File Format"),
new (typeof(ImageFile), "bmp", "BMP: Bitmap"),
new (typeof(ImageFile), "pbm", "PBM: Portable Bitmap"),
new (typeof(ImageFile), "pgm", "PGM: Portable Greymap"),
//new (typeof(ImageFile), "gif", "GIF"),
new (typeof(ImageFile), "sr", "SR: Sun raster"),
new (typeof(ImageFile), "RAS", "RAS: Sun raster"),
};
public override PrintParameterModifier[] PrintParameterModifiers => null;
public override Size[] ThumbnailsOriginalSize { get; } = {
Size.Empty,
Size.Empty,
Size.Empty,
Size.Empty
};
public override uint ResolutionX
{
get => (uint) ImageMat.Width;
set => throw new NotImplementedException();
}
public override uint ResolutionY
{
get => (uint) ImageMat.Height;
set => throw new NotImplementedException();
}
public override float DisplayWidth
{
get => ResolutionX;
set
{
ResolutionX = (uint) value;
RaisePropertyChanged();
}
}
public override float DisplayHeight
{
get => ResolutionY;
set
{
ResolutionY = (uint) value;
RaisePropertyChanged();
}
}
public override bool DisplayMirror
{
get => false;
set { }
}
public override float LayerHeight { get; set; } = 0.01f;
/*public override float PrintTime { get; } = 0;
public override float UsedMaterial { get; } = 0;
public override float MaterialCost { get; } = 0;
public override string MaterialName { get; } = null;
public override string MachineName { get; } = null;*/
public override object[] Configs { get; } = null;
private Mat ImageMat { get; set; }
protected override void EncodeInternally(string fileFullPath, OperationProgress progress)
{
throw new NotSupportedException();
}
protected override void DecodeInternally(string fileFullPath, OperationProgress progress)
{
ImageMat = CvInvoke.Imread(fileFullPath, ImreadModes.Grayscale);
const byte startDivisor = 2;
for (int i = 0; i < ThumbnailsCount; i++)
{
Thumbnails[i] = new Mat();
var divisor = (i + 1) * startDivisor;
CvInvoke.Resize(ImageMat, Thumbnails[i],
new Size(ImageMat.Width / divisor, ImageMat.Height / divisor));
}
/*if (ImageMat.NumberOfChannels > 1)
{
CvInvoke.CvtColor(ImageMat, ImageMat, ColorConversion.Bgr2Gray);
}*/
LayerManager.Init(1);
this[0] = new Layer(0, ImageMat, LayerManager);
}
public override void SaveAs(string filePath = null, OperationProgress progress = null)
{
this[0].LayerMat.Save(filePath ?? FileFullPath);
}
public override FileFormat Convert(Type to, string fileFullPath, OperationProgress progress = null)
{
throw new NotSupportedException();
}
}
}