Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ImageFile.cs « FileFormats « UVtools.Core - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 59ce84a0adccf39293a7065650993cabde318e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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();
        }

        
    }
}