Exemplo n.º 1
0
            public void ShouldChangeAreaAndMemory()
            {
                var area   = ResourceLimits.Area;
                var memory = ResourceLimits.Memory;

                ResourceLimits.LimitMemory((Percentage)80);

                Assert.NotEqual(area, ResourceLimits.Area);
                Assert.NotEqual(memory, ResourceLimits.Memory);

                ResourceLimits.Area   = area;
                ResourceLimits.Memory = memory;
            }
Exemplo n.º 2
0
            public void ShouldSetMemoryAndAreaToTheCorrectValues()
            {
                var area   = ResourceLimits.Area;
                var memory = ResourceLimits.Memory;

                ResourceLimits.LimitMemory((Percentage)100);

                Assert.InRange(ResourceLimits.Area, (area * 2) - 8192, (area * 2) + 8192);
                Assert.InRange(ResourceLimits.Memory, (memory * 2) - 8192, (memory * 2) + 8192);

                ResourceLimits.Area   = area;
                ResourceLimits.Memory = memory;
            }
Exemplo n.º 3
0
        private void InitializeProject()
        {
            OpenCL.IsEnabled = true;
            ResourceLimits.LimitMemory(new Percentage(100));

            selectedLayer                = new EmptyLayer(this);
            layers                       = new ObservableCollection <Layer>();
            checkerBoardLarge            = size.GetCheckerBoard(90);
            checkerBoardSmall            = size.GetCheckerBoard(10);
            EventBus.LayerActionChanged += OnLayerActionChanged;
            EventBus.LayerActionChanged += OnAutoSave;
            EventBus.LayerActionAdded   += OnAutoSave;
            EventBus.LayerActionRemoved += OnAutoSave;
            EventBus.LayerBlendChanged  += OnAutoSave;
        }
Exemplo n.º 4
0
            public void ShouldChangeAreaAndMemory()
            {
                TestHelper.ExecuteInsideLock(() =>
                {
                    var area   = ResourceLimits.Area;
                    var memory = ResourceLimits.Memory;

                    ResourceLimits.LimitMemory((Percentage)80);

                    Assert.NotEqual(area, ResourceLimits.Area);
                    Assert.NotEqual(memory, ResourceLimits.Memory);

                    ResourceLimits.Area   = area;
                    ResourceLimits.Memory = memory;
                });
            }
Exemplo n.º 5
0
            public void ShouldSetMemoryAndAreaToTheCorrectValues()
            {
                ExecuteInsideLock(() =>
                {
                    var area   = ResourceLimits.Area;
                    var memory = ResourceLimits.Memory;

                    ResourceLimits.LimitMemory((Percentage)100);

                    Assert.AreEqual(area * 2, ResourceLimits.Area, 8192);
                    Assert.AreEqual(memory * 2, ResourceLimits.Memory, 8192);

                    ResourceLimits.Area   = area;
                    ResourceLimits.Memory = memory;
                });
            }
Exemplo n.º 6
0
 public void ShouldThrowExceptionWhenValueIsTooHigh()
 {
     Assert.Throws <ArgumentOutOfRangeException>("percentage", () => ResourceLimits.LimitMemory(new Percentage(100.1)));
 }
Exemplo n.º 7
0
 public void ShouldThrowExceptionWhenValueIsNegative()
 {
     Assert.Throws <ArgumentOutOfRangeException>("percentage", () => ResourceLimits.LimitMemory(new Percentage(-0.99)));
 }
Exemplo n.º 8
0
        private void ProcessRAW(string[] srcRGBTriplet, ShotSetting[] shotSettings, string targetFilename, TARGETFORMAT targetFormat, FORMAT inputFormat, int maxThreads, float HDRClippingPoint, float HDRFeatherMultiplier, bool EXRIntegrityVerification)
        {
            int groupLength = shotSettings.Length;

            byte[][] buffers = new byte[groupLength][];
            for (int i = 0; i < groupLength; i++)
            {
                buffers[i] = File.ReadAllBytes(srcRGBTriplet[i]);
                if (inputFormat == FORMAT.MONO12p)
                {
                    buffers[i] = convert12pto16bit(buffers[i]);
                }
            }


            int width  = 4096;
            int height = 3000;

            this.Dispatcher.Invoke(() =>
            {
                width = 1;
                int.TryParse(rawWidth.Text, out width);
                height = 1;
                int.TryParse(rawHeight.Text, out height);
            });


            byte[][] RGBBuffers = HDRMerge(buffers, shotSettings, HDRClippingPoint, HDRFeatherMultiplier);

            byte[] buffR = RGBBuffers[0];
            byte[] buffG = RGBBuffers[1];
            byte[] buffB = RGBBuffers[2];

            // Interleave
            int pixelCount  = width * height;
            int totalLength = width * height * 3;

            byte[] buff = new byte[totalLength * 2];


            if (buffR.Count() < pixelCount * 2)
            {
                this.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("Red file too short: " + srcRGBTriplet[0]);
                });
                return;
            }
            if (buffG.Count() < pixelCount * 2)
            {
                this.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("Green file too short: " + srcRGBTriplet[1]);
                });
                return;
            }
            if (buffB.Count() < pixelCount * 2)
            {
                this.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("Blue file too short: " + srcRGBTriplet[2]);
                });
                return;
            }

            for (int pixelIndex = 0; pixelIndex < pixelCount; pixelIndex++)
            {
                /*
                 * // BGR
                 * buff[pixelIndex * 3 * 2] = buffB[pixelIndex * 2];
                 * buff[pixelIndex * 3 * 2 + 1] = buffB[pixelIndex * 2 + 1];
                 * buff[pixelIndex * 3 * 2 +4] = buffR[pixelIndex*2];
                 * buff[pixelIndex * 3 * 2 +5] = buffR[pixelIndex * 2 + 1];
                 * buff[pixelIndex * 3 * 2 +2] = buffG[pixelIndex * 2];
                 * buff[pixelIndex * 3 * 2 +3] = buffG[pixelIndex * 2 + 1];
                 */
                // RGB
                buff[pixelIndex * 3 * 2]     = buffR[pixelIndex * 2];
                buff[pixelIndex * 3 * 2 + 1] = buffR[pixelIndex * 2 + 1];
                buff[pixelIndex * 3 * 2 + 2] = buffG[pixelIndex * 2];
                buff[pixelIndex * 3 * 2 + 3] = buffG[pixelIndex * 2 + 1];
                buff[pixelIndex * 3 * 2 + 4] = buffB[pixelIndex * 2];
                buff[pixelIndex * 3 * 2 + 5] = buffB[pixelIndex * 2 + 1];
            }



            string fileName = targetFilename;

            if (targetFormat == TARGETFORMAT.EXR)
            {
                ResourceLimits.Thread = (ulong)maxThreads;
                ResourceLimits.LimitMemory(new Percentage(90));

                MagickReadSettings settings = new MagickReadSettings();
                settings.Width  = width;
                settings.Height = height;
                settings.Format = MagickFormat.Rgb; // Correction, this is actually right, I had flipped RGB to BGR elsewhere in the code before. Fixed now.

                /*ColorManager.ICC.ICCProfileWriter iccWriter = new ColorManager.ICC.ICCProfileWriter();
                 * iccWriter.WriteProfile(new ColorManager.ICC.ICCProfile());
                 */

                if (EXRIntegrityVerification)
                {
                    /*
                     * Info on half float format: https://www.openexr.com/about.html
                     */
                    // What does this mean for precision of converting 16 bit integers to 16 bit floating point?
                    // We need to know the maximum precision achievable to be able to tell rounding errors from actual integrity fails.
                    // More info here: https://en.wikipedia.org/wiki/Half-precision_floating-point_format
                    // Basically, precision at any given value is 11 bits or 2048 values.


                    int  integrityCheckFailCountLocal = 0;
                    bool integrityCheckPassed         = false;
                    bool retriesExhausted             = false;
                    while (!integrityCheckPassed && !retriesExhausted)
                    {
                        using (var image = new MagickImage(buff, settings))
                        {
                            //ExifProfile profile = new ExifProfile();
                            //profile.SetValue(ExifTag.UserComment, Encoding.ASCII.GetBytes(srcRGBTriplet[0] + "," + srcRGBTriplet[1] + "," + srcRGBTriplet[2]));
                            //image.SetProfile(profile);
                            image.Format = MagickFormat.Exr;
                            image.Settings.Compression = CompressionMethod.Piz;

                            //image.Write(fileName);

                            byte[] exrFile = image.ToByteArray();

                            bool integrityCheckFailed = false;
                            using (var reloadedImage = new MagickImage(exrFile))
                            {
                                reloadedImage.Depth      = 16;
                                reloadedImage.ColorSpace = ColorSpace.Undefined;
                                byte[] reloadedImageBytes = reloadedImage.ToByteArray(MagickFormat.Rgb);

                                integrityCheckFailed = integrityCheckFailed | !IntegrityChecker.VerifyIntegrityUInt16InHalfPrecisionFloat(buff, reloadedImageBytes);
                            }
                            if (integrityCheckFailed)
                            {
                                integrityCheckFailCount++;
                                integrityCheckFailCountLocal++;
                                continue;
                            }
                            else
                            {
                                integrityCheckPassed = true;
                                File.WriteAllBytes(fileName, exrFile);
                            }
                            if (integrityCheckFailCountLocal > integrityCheckRetries)
                            {
                                retriesExhausted = true;
                                // At this point just write it into a subfolder and be done with it.
                                string failedFolder = Path.GetDirectoryName(fileName) + Path.DirectorySeparatorChar + "FAILED" + Path.DirectorySeparatorChar;
                                Directory.CreateDirectory(failedFolder);
                                string failedFile = failedFolder + Path.GetFileName(fileName);

                                File.WriteAllBytes(failedFile, exrFile);
                            }
                        }
                    }
                }
                else
                {
                    using (var image = new MagickImage(buff, settings))
                    {
                        //ExifProfile profile = new ExifProfile();
                        //profile.SetValue(ExifTag.UserComment, Encoding.ASCII.GetBytes(srcRGBTriplet[0] + "," + srcRGBTriplet[1] + "," + srcRGBTriplet[2]));
                        //image.SetProfile(profile);
                        image.Format = MagickFormat.Exr;
                        image.Settings.Compression = CompressionMethod.Piz;

                        //image.Write(fileName);
                        byte[] exrFile = image.ToByteArray();
                        File.WriteAllBytes(fileName, exrFile);
                    }
                }
            }
            else if (targetFormat == TARGETFORMAT.TIF)
            {
                using (Tiff output = Tiff.Open(fileName, "w"))
                {
                    output.SetField(TiffTag.SUBFILETYPE, 0);
                    //output.SetField(TiffTag.ORIGINALRAWFILENAME, srcRGBTriplet[0]+","+srcRGBTriplet[1]+","+srcRGBTriplet[2]);
                    output.SetField(TiffTag.IMAGEWIDTH, width);
                    output.SetField(TiffTag.IMAGELENGTH, height);
                    output.SetField(TiffTag.SAMPLESPERPIXEL, 3);
                    output.SetField(TiffTag.BITSPERSAMPLE, 16);
                    output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                    output.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);
                    output.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
                    output.SetField(TiffTag.COMPRESSION, Compression.DEFLATE);

                    output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);


                    output.WriteEncodedStrip(0, buff, width * height * 2 * 3);
                }
            }
        }