Beispiel #1
0
        public virtual void SetupGraphic(ImageDataType type)
        {
            var itemIconName = m_ItemIcon != null ? m_ItemIcon.name : "Icon";
            //if (gameObject.GetChildByName<Image>(itemIconName) == null || gameObject.GetChildByName<IVectorImage>(itemIconName) == null) return;

            Graphic otherIcon = null;

            if (type == ImageDataType.Sprite)
            {
                m_ItemIcon = gameObject.GetChildByName <Image>(itemIconName);
                otherIcon  = gameObject.GetChildByName <IVectorImage>(itemIconName) as Graphic;
            }
            else
            {
                m_ItemIcon = gameObject.GetChildByName <IVectorImage>(itemIconName) as Graphic;
                otherIcon  = gameObject.GetChildByName <Image>(itemIconName);
            }

            if (m_ItemIcon != null)
            {
                m_ItemIcon.gameObject.SetActive(true);
            }
            if (otherIcon != null)
            {
                otherIcon.gameObject.SetActive(false);
            }
        }
Beispiel #2
0
Datei: Pi2.cs Projekt: habi/pi2
        /// <summary>
        /// Read a block of image file to a new image.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="start">Coordinates of the first pixel to read.</param>
        /// <param name="size">Size of the block to read.</param>
        /// <param name="dataType">Data type of the image. Used only if reading .raw images. Leave empty to guess data type based on file size.</param>
        /// <returns></returns>
        public Pi2Image ReadBlock(string filename, Vec3 start, Vec3 size, ImageDataType dataType = ImageDataType.Unknown)
        {
            string imageName = "image_" + RandomString();

            PiLib.RunAndCheck(Handle, $"readblock({imageName}, {filename}, {(int)start.X}, {(int)start.Y}, {(int)start.Z}, {(int)size.X}, {(int)size.Y}, {(int)size.Z}, {dataType})");
            return(new Pi2Image(this, imageName, true));
        }
Beispiel #3
0
Datei: Pi2.cs Projekt: habi/pi2
        /// <summary>
        /// Creates a new Pi2 image object.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="depth"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public Pi2Image NewImage(ImageDataType dt, int width = 1, int height = 1, int depth = 1)
        {
            string imageName = "image_" + RandomString();

            PiLib.RunAndCheck(Handle, $"newimage({imageName}, {dt}, {width}, {height}, {depth})");
            return(new Pi2Image(this, imageName, true));
        }
        public Texture2D Generate(GraphicsDevice device, int width, int height, ImageDataType dataType, byte[] buffer)
        {
            Texture2D texture;

            int w = width + (4 - width % 4) % 4;
            int h = height + (4 - height % 4) % 4;

            switch (dataType)
            {
            case ImageDataType.Dxt1:
                texture = new Texture2D(device, w, h, false, SurfaceFormat.Dxt1);
                texture.SetData(buffer);
                break;

            case ImageDataType.Dxt3:
                texture = new Texture2D(device, w, h, false, SurfaceFormat.Dxt3);
                texture.SetData(buffer);
                break;

            case ImageDataType.Dxt5:
                texture = new Texture2D(device, w, h, false, SurfaceFormat.Dxt5);
                texture.SetData(buffer);
                break;

            default:
                throw new NotImplementedException();
            }

            return(texture);
        }
Beispiel #5
0
        /// <summary>
        /// Find data depth (number of bits) and if the data is float-point.
        /// </summary>
        /// <param name="dataType">Image data type.</param>
        /// <param name="numberOfBits">Number of bits.</param>
        /// <param name="isFloat">True is data is float-point numbers.</param>
        public static void getDataTypeInfo(ImageDataType dataType, out uint numberOfBits, out bool isFloat)
        {
            switch (dataType)
            {
            case ImageDataType.Byte:
                numberOfBits = 8;
                isFloat      = false;
                break;

            case ImageDataType.Float:
                numberOfBits = 32;
                isFloat      = true;
                break;

            case ImageDataType.UInt32:
                numberOfBits = 32;
                isFloat      = false;
                break;

            case ImageDataType.RGB:
                numberOfBits = 8;
                isFloat      = false;
                break;

            case ImageDataType.Short:
                numberOfBits = 16;
                isFloat      = false;
                break;

            default:
                throw new Exception("Unsupported image data type");
            }
        }
        /// <summary>
        /// Loads texture image from stream</summary>
        /// <param name="imageStream">Stream holding texture image</param>
        /// <returns>Texture image</returns>
        public Image LoadImage(Stream imageStream)
        {
            TgaHeader header;

            byte[] pixels;

            using (BinaryReader reader = new BinaryReader(imageStream))
            {
                header = ReadHeader(reader);
                ImageDataType dataType = (ImageDataType)header.dataType;

                switch ((ImageDataType)header.dataType)
                {
                case ImageDataType.UncompressedUnmappedColor:
                case ImageDataType.RleCompressedUnmappedColor:
                case ImageDataType.UncompressedMappedColor:
                    break;

                default:
                    throw new NotImplementedException("Unsupported Targa image type '" + dataType.ToString() + "'");
                }

                ReadIdString(reader, header);

                byte[] colorMap = ReadColorMap(reader, header);
                pixels = ReadPixels(reader, header, colorMap);
            }

            int pixelFormat      = CalculateOpenGlPixelFormat(header);
            int elementsPerPixel = GetPixelDepth(header) / 8;

            return(new Image(header.imageWidth, header.imageHeight, pixels, 1, pixelFormat, elementsPerPixel));
        }
Beispiel #7
0
Datei: Pi2.cs Projekt: habi/pi2
        /// <summary>
        /// Create a disk-mapped image from existing .raw file or create a new .raw file if corresponding file does not exist.
        /// If data type and dimensions are not specified, the image file name must contain dimensions of the image, i.e. it must be in format corresponding to image_name_123x456x789.raw.
        /// </summary>
        /// <param name="filename">Name of image file to map.</param>
        /// <param name="dataType">Data type of the image. Specify empty value to infer data type from image dimensions</param>
        /// <param name="width">Width of the image. Omit width, height and depth to infer dimensions from file name.</param>
        /// <param name="height">Height of the image. Omit width, height and depth to infer dimensions from file name.</param>
        /// <param name="depth">Depth of the image. Omit width, height and depth to infer dimensions from file name.</param>
        /// <returns>The mapped image. NOTE: Changes made to the image are IMMEDIATELY reflected on disk.</returns>
        public Pi2Image MapRaw(string filename, ImageDataType dataType = ImageDataType.Unknown, int width = 0, int height = 0, int depth = 0)
        {
            string   imageName = "image_" + RandomString();
            Pi2Image img       = new Pi2Image(this, imageName, true);

            MapRaw(img, filename, dataType, width, height, depth);
            return(img);
        }
Beispiel #8
0
 public BufferProperty(long attriute, ImageBandType bandType, ImageDataType dataType, int depth, long height, long width)
 {
     Attriute = attriute;
     BandType = bandType;
     DataType = dataType;
     Depth    = depth;
     Height   = height;
     Width    = width;
 }
Beispiel #9
0
Datei: Pi2.cs Projekt: habi/pi2
        /// <summary>
        /// Get pointer to data of this image.
        /// The pointer is valid until this image object is modified in Pi2.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="depth"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public IntPtr GetData(out Int64 width, out Int64 height, out Int64 depth, out ImageDataType dataType)
        {
            IntPtr data = PiLib.GetImage(Pi.Handle, Name, out width, out height, out depth, out dataType);

            if (data == IntPtr.Zero || dataType == ImageDataType.Unknown)
            {
                throw new InvalidOperationException("Image " + Name + " is inaccessible because it has been deleted from the Pi system.");
            }
            return(data);
        }
Beispiel #10
0
Datei: Pi2.cs Projekt: habi/pi2
        /// <summary>
        /// Reads dimensions and data type of given image file.
        /// </summary>
        /// <param name="filename">Name of file to examine.</param>
        /// <param name="dimensions">Dimension of the image. Returns zero dimensions if the image file could not be read.</param>
        /// <param name="dataType">Data type of the image. Returns Unknown if the image could not be read.</param>
        public void GetImageInfo(string filename, out Vec3 dimensions, out ImageDataType dataType)
        {
            dimensions = new Vec3();
            dataType   = ImageDataType.Unknown;

            using (Pi2Image result = NewImage(ImageDataType.UInt32, 4))
            {
                PiLib.RunAndCheck(Handle, $"fileinfo({filename}, {result.Name})");
                dimensions.X = result.GetValue(0);
                dimensions.Y = result.GetValue(1);
                dimensions.Z = result.GetValue(2);
                dataType     = (ImageDataType)result.GetValue(3);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Evaluates the provided pixel buffer for recognizable objects.
        /// </summary>
        /// <param name="buffer">Native pointer to the image data to evaluate.</param>
        /// <param name="dataType">The nature of the data buffer.</param>
        public void EvaluateBuffer(IntPtr buffer, ImageDataType dataType)
        {
            if (_requestsToPerform == VisionRequest.None)
            {
                Debug.LogError("[Vision] Unspecified vision request.");
                return;
            }

            if (_requestsInProgress != VisionRequest.None)
            {
                Debug.LogError("[Vision] One or more vision requests are still in progress.");
                return;
            }

            if (buffer == IntPtr.Zero)
            {
                Debug.LogError("[Vision] Pointer to buffer is null.");
                return;
            }

            bool success;

            switch (dataType)
            {
            case ImageDataType.MetalTexture:
                success = _vision_evaluateWithTexture(buffer) > 0;
                break;

            case ImageDataType.CoreVideoPixelBuffer:
                success = _vision_evaluateWithBuffer(buffer) > 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("dataType", dataType, null);
            }

            if (success)
            {
                // Store requests in progress
                _requestsInProgress = _requestsToPerform;
            }
            else
            {
                Debug.LogError("[Vision] Unable to perform vision request. Pointer to buffer is not in expected type or is no longer accessible.");
            }
        }
Beispiel #12
0
        public void SetupGraphic(ImageDataType type)
        {
            if (gameObject.GetChildByName <Image>("Icon") == null || gameObject.GetChildByName <VectorImage>("Icon") == null)
            {
                return;
            }

            if (type == ImageDataType.Sprite)
            {
                m_ItemIcon = gameObject.GetChildByName <Image>("Icon");
                Destroy(gameObject.GetChildByName <VectorImage>("Icon").gameObject);
            }
            else
            {
                m_ItemIcon = gameObject.GetChildByName <VectorImage>("Icon");
                Destroy(gameObject.GetChildByName <Image>("Icon").gameObject);
            }
        }
Beispiel #13
0
        public static EmfPlusImageData GetImageData(MetafileReader reader, ImageDataType type, uint size)
        {
            EmfPlusImageData data;

            switch (type)
            {
            case ImageDataType.Bitmap:
                data = new EmfPlusBitmap(reader, size);
                break;

            case ImageDataType.Metafile:
                data = new EmfPlusMetafile(reader, size);
                break;

            default:
                throw new InvalidOperationException($"Unknown image type {type}.");
            }

            return(data);
        }
Beispiel #14
0
        public void Issue393Test([IncludeDataSources(ProviderName.SqlCe)] string context)
        {
            using (var db = new DataConnection(context))
                using (db.BeginTransaction())
                {
                    Random rnd   = new Random();
                    var    image = new byte[9000];
                    rnd.NextBytes(image);

                    var testItem = new ImageDataType {
                        imageDataType = image
                    };

                    var id = db.InsertWithInt32Identity(testItem);

                    var item = db.GetTable <ImageDataType>().FirstOrDefault(_ => _.ID == id);

                    Assert.That(testItem.imageDataType, Is.EqualTo(item.imageDataType));
                }
        }
Beispiel #15
0
        protected void prepareWriteStack(StkInfoCollection allInfo, int width, int height, ImageDataType dataType, int planeNum, ushort photometricInterpretation)
        {
            if (allInfo == null)
            {
                return;
            }
            stkInfo = allInfo;
            TiffWriter.getDataTypeInfo(dataType, out numberOfBits, out isFloatPoint);

            isPrepared   = false;
            planeCounter = 0;
            if (width <= 0 || height <= 0 || planeNum <= 0)
            {
                throw new WriteFileException("Invalid image parameters");
            }
            this.width    = width;
            this.height   = height;
            this.planeNum = planeNum;

            System.IO.Stream stream = writer.BaseStream;
            prepareWriteFile();

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.PhotometricInterpretation, "", photometricInterpretation));
            allInfo.add(new TiffInfo(TiffInfoCollection.XResolution, "", (uint)1, (uint)1));
            allInfo.add(new TiffInfo(TiffInfoCollection.YResolution, "", (uint)1, (uint)1));
            allInfo.add(new TiffInfo(TiffInfoCollection.ResolutionUnit, "", (ushort)1));

            if (isFloatPoint)
            {
                allInfo.setSampleFormat(TiffInfoCollection.SampleFormatType.FloatPoint);
            }
            else
            {
                allInfo.setSampleFormat(TiffInfoCollection.SampleFormatType.UnsignedInteger);
            }

            if (photometricInterpretation <= 1 || photometricInterpretation == 3)
            {
                allInfo.forceAdd(new TiffInfo(TiffInfoCollection.BitsPerSample, "Bits per Sample", (ushort)numberOfBits));
                byteCountsPerPlane = (uint)(width * height * numberOfBits / 8);
            }
            else if (photometricInterpretation == 2)
            {
                allInfo.forceAdd(new TiffInfo(TiffInfoCollection.BitsPerSample, "Bits per Sample", new ushort[] { (ushort)8, (ushort)8, (ushort)8 }));
                allInfo.forceAdd(new TiffInfo(TiffInfoCollection.SamplesPerPixel, "Sample per Pixel", (ushort)3));
                allInfo.forceAdd(new TiffInfo(TiffInfoCollection.PlanarConfiguration, "", (ushort)1));
                byteCountsPerPlane = (uint)(width * height * 3);
            }
            else
            {
                throw new Exception("Only support grayscale, palette-color, or RGB images.");
            }

            stripOffset = (uint)stream.Position;

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.ImageWidth, "width", (uint)width));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.ImageLength, "height", (uint)height));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.StripOffsets, "strip Offsets", stripOffset));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.StripByteCounts, "strip Byte Counts", byteCountsPerPlane));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.RowsPerStrip, "Rows per strip", (uint)height));
            MyTiffCompression.setCompressionTag(allInfo, CompressMethod, CompressLevel);
            MyTiffCompression.setHorizontalDifferencing(allInfo, HorizontalDifferencing);

            int[] missing;
            if (photometricInterpretation <= 1)
            {
                missing = allInfo.missingInfoGrayscale();
            }
            else if (photometricInterpretation == 2)
            {
                missing = allInfo.missingInfoRGB();
            }
            else
            {
                missing = allInfo.missingInfoPaletteColor();
            }

            if (missing.Length > 0)
            {
                String msg = "Missing tags: ";
                for (int i = 0; i < missing.Length; i++)
                {
                    msg += missing[i] + " ";
                }
                throw new WriteFileException(msg);
            }

            if (!allInfo.validUIC2tag())
            {
                throw new WriteFileException("Invalid UIC2 data");
            }

            isPrepared = true;
        }
Beispiel #16
0
 public void prepareWritePaletteColorStack(StkInfoCollection allInfo, int width, int height, ImageDataType dataType, byte[][] colormap)
 {
     addColormapToTiffInfo(allInfo, colormap);
     prepareWriteStack(allInfo, width, height, dataType, (ushort)3);
 }
Beispiel #17
0
 public void prepareWriteGrayscaleStack(StkInfoCollection allInfo, int width, int height, ImageDataType dataType)
 {
     prepareWriteStack(allInfo, width, height, dataType, (ushort)1);
 }
Beispiel #18
0
 public static extern bool TexImage(int width, int height, int depth, byte bpp, ImageDataFormat format, ImageDataType type, byte[] data);
Beispiel #19
0
Datei: Pi2.cs Projekt: habi/pi2
 /// <summary>
 /// Create a disk-mapped image from existing .raw file or create a new .raw file if corresponding file does not exist.
 /// If data type and dimensions are not specified, the image file name must contain dimensions of the image, i.e. it must be in format corresponding to image_name_123x456x789.raw.
 /// </summary>
 /// <param name="image">The mapped image is placed into this image object. NOTE: Changes made to the image are IMMEDIATELY reflected on disk.</param>
 /// <param name="filename">Name of image file to map.</param>
 /// <param name="dataType">Data type of the image. Specify empty value to infer data type from image dimensions</param>
 /// <param name="width">Width of the image. Omit width, height and depth to infer dimensions from file name.</param>
 /// <param name="height">Height of the image. Omit width, height and depth to infer dimensions from file name.</param>
 /// <param name="depth">Depth of the image. Omit width, height and depth to infer dimensions from file name.</param>
 public void MapRaw(Pi2Image image, string filename, ImageDataType dataType = ImageDataType.Unknown, int width = 0, int height = 0, int depth = 0)
 {
     PiLib.RunAndCheck(Handle, $"mapraw({image.Name}, {filename}, {dataType}, {width}, {height}, {depth})");
 }
Beispiel #20
0
 /// <summary>Creates a new instance of <see cref="ImageData" />.</summary>
 /// <param name="value">The value.</param>
 public ImageData(ImageDataType value) : base(value, typeof(ImageDataType))
 {
     valueImageDataType = value;
 }
Beispiel #21
0
Datei: Pi2.cs Projekt: habi/pi2
 /// <summary>
 /// Converts img to specified data type in-place.
 /// Does not scale pixel values.
 /// </summary>
 /// <param name="img"></param>
 /// <param name="dt"></param>
 public void Convert(Pi2Image img, ImageDataType dt)
 {
     PiLib.RunAndCheck(Handle, $"convert({img.Name}, {dt})");
 }
Beispiel #22
0
        public void SetupGraphic(ImageDataType type)
        {
            if (gameObject.GetChildByName<Image>("Icon") == null || gameObject.GetChildByName<VectorImage>("Icon") == null) return;

            if (type == ImageDataType.Sprite)
            {
                m_ItemIcon = gameObject.GetChildByName<Image>("Icon");
                Destroy(gameObject.GetChildByName<VectorImage>("Icon").gameObject);
            }
            else
            {
                m_ItemIcon = gameObject.GetChildByName<VectorImage>("Icon");
                Destroy(gameObject.GetChildByName<Image>("Icon").gameObject);
            }
        }
Beispiel #23
0
 public static extern bool ConvertImage(ImageDataFormat destFormat, ImageDataType destType);
Beispiel #24
0
 public ImageData(VectorImageData vectorImageData)
 {
     m_VectorImageData = vectorImageData;
     m_ImageDataType   = ImageDataType.VectorImage;
 }
Beispiel #25
0
 public ImageData(Sprite sprite)
 {
     m_Sprite = sprite;
     m_ImageDataType = ImageDataType.Sprite;
 }
Beispiel #26
0
 public ImageData(VectorImageData vectorImageData)
 {
     m_VectorImageData = vectorImageData;
     m_ImageDataType = ImageDataType.VectorImage;
 }
Beispiel #27
0
        /// <summary>
        /// Copies image data from given pi2 pointer to array in this picture box.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="depth"></param>
        /// <param name="dt"></param>
        private void CopyFromPointerToTemp(IntPtr data, int width, int height, int depth, ImageDataType dt)
        {
            OriginalBitmap.Clear();
            OriginalBitmap.Capacity = width * height;
            for (int n = 0; n < width * height; n++)
            {
                OriginalBitmap.Add(0);
            }
            OriginalWidth  = width;
            OriginalHeight = height;
            OriginalDepth  = depth;

            OriginalDataType = dt;

            if (Slice < 0)
            {
                Slice = 0;
            }
            else if (Slice >= depth)
            {
                Slice = depth - 1;
            }

            if (data != IntPtr.Zero)
            {
                unsafe
                {
                    // Construct pixel getter function that converts all pixel data types to float.
                    byte *  pi8  = (byte *)data.ToPointer();
                    UInt16 *pi16 = (UInt16 *)pi8;
                    UInt32 *pi32 = (UInt32 *)pi8;
                    UInt64 *pi64 = (UInt64 *)pi8;
                    float * pif  = (float *)pi8;

                    Func <int, int, float> getPixel;

                    switch (dt)
                    {
                    case ImageDataType.UInt8:
                        getPixel   = (int x, int y) => pi8[x + y * width + Slice * width * height];
                        DynamicMin = uint.MinValue;
                        DynamicMax = uint.MaxValue;
                        break;

                    case ImageDataType.UInt16:
                        getPixel   = (int x, int y) => pi16[x + y * width + Slice * width * height];
                        DynamicMin = UInt16.MinValue;
                        DynamicMax = UInt16.MaxValue;
                        break;

                    case ImageDataType.UInt32:
                        getPixel   = (int x, int y) => pi32[x + y * width + Slice * width * height];
                        DynamicMin = UInt32.MinValue;
                        DynamicMax = UInt32.MaxValue;
                        break;

                    case ImageDataType.UInt64:
                        getPixel   = (int x, int y) => pi64[x + y * width + Slice * width * height];
                        DynamicMin = UInt64.MinValue;
                        DynamicMax = UInt64.MaxValue;
                        break;

                    case ImageDataType.Float32:
                        getPixel = (int x, int y) => pif[x + y * width + Slice * width * height];
                        // These are updated later as MinValue and MaxValue are not practically very usable choices.
                        //DynamicMin = float.MinValue;
                        //DynamicMax = float.MaxValue;
                        break;

                    default:
                        getPixel   = (int x, int y) => 0;
                        DynamicMin = 0;
                        DynamicMax = 0;
                        break;
                    }

                    // Copy pixel values to the array.
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            float val = getPixel(x, y);
                            OriginalBitmap[x + y * width] = val;
                        }
                    }
                }
            }

            UpdateHistogram();

            if (dt == ImageDataType.Float32)
            {
                float headroom = 0.1f * (GlobalMax - GlobalMin);
                DynamicMin = GlobalMin - headroom;
                DynamicMax = GlobalMax + headroom;
            }
        }
Beispiel #28
0
 public ImageData(Sprite sprite)
 {
     m_Sprite        = sprite;
     m_ImageDataType = ImageDataType.Sprite;
 }
 public ImageData(string imgUrl, Sprite defaultSprite)
 {
     m_ImgUrl        = imgUrl;
     m_Sprite        = defaultSprite;
     m_ImageDataType = ImageDataType.Sprite;
 }
Beispiel #30
0
            /// <summary>
            /// Copies one slice of image data from given pi2 pointer to array in this picture storage object.
            /// </summary>
            /// <param name="data"></param>
            /// <param name="width"></param>
            /// <param name="height"></param>
            /// <param name="depth"></param>
            /// <param name="dt"></param>
            public void CopyFromPointerToTemp(IntPtr data, long width, long height, long depth, ImageDataType dt, int slice, CancellationToken cancellationToken)
            {
                if (width > int.MaxValue)
                {
                    throw new InvalidOperationException("Image width is too large to be shown. Maximum supported width is " + int.MaxValue);
                }
                if (height > int.MaxValue)
                {
                    throw new InvalidOperationException("Image height is too large to be shown. Maximum supported height is " + int.MaxValue);
                }
                if (depth > int.MaxValue)
                {
                    throw new InvalidOperationException("Image depth is too large to be shown. Maximum supported depth is " + int.MaxValue);
                }

                long capacity = width * height;

                if (capacity > int.MaxValue)
                {
                    throw new InvalidOperationException("Size of single slice is too large to be shown. Maximum supported count of pixels is " + int.MaxValue);
                }

                OriginalBitmap.Clear();
                OriginalBitmap.Capacity = (int)capacity;
                for (int n = 0; n < width * height; n++)
                {
                    OriginalBitmap.Add(0);
                }
                OriginalWidth  = (int)width;
                OriginalHeight = (int)height;
                OriginalDepth  = (int)depth;

                OriginalDataType = dt;

                cancellationToken.ThrowIfCancellationRequested();

                if (slice < 0)
                {
                    slice = 0;
                }
                else if (slice >= depth)
                {
                    slice = (int)(depth - 1);
                }

                if (data != IntPtr.Zero)
                {
                    unsafe
                    {
                        // Construct pixel getter function that converts all pixel data types to float.
                        byte *  pi8  = (byte *)data.ToPointer();
                        UInt16 *pi16 = (UInt16 *)pi8;
                        UInt32 *pi32 = (UInt32 *)pi8;
                        UInt64 *pi64 = (UInt64 *)pi8;
                        float * pif  = (float *)pi8;

                        Func <int, int, float> getPixel;

                        switch (dt)
                        {
                        case ImageDataType.UInt8:
                            getPixel   = (int x, int y) => pi8[x + y * width + slice * width * height];
                            DynamicMin = uint.MinValue;
                            DynamicMax = uint.MaxValue;
                            break;

                        case ImageDataType.UInt16:
                            getPixel   = (int x, int y) => pi16[x + y * width + slice * width * height];
                            DynamicMin = UInt16.MinValue;
                            DynamicMax = UInt16.MaxValue;
                            break;

                        case ImageDataType.UInt32:
                            getPixel   = (int x, int y) => pi32[x + y * width + slice * width * height];
                            DynamicMin = UInt32.MinValue;
                            DynamicMax = UInt32.MaxValue;
                            break;

                        case ImageDataType.UInt64:
                            getPixel   = (int x, int y) => pi64[x + y * width + slice * width * height];
                            DynamicMin = UInt64.MinValue;
                            DynamicMax = UInt64.MaxValue;
                            break;

                        case ImageDataType.Float32:
                            getPixel = (int x, int y) => pif[x + y * width + slice * width * height];
                            // These are updated later as MinValue and MaxValue are not practically very usable choices.
                            //DynamicMin = float.MinValue;
                            //DynamicMax = float.MaxValue;
                            break;

                        default:
                            getPixel   = (int x, int y) => 0;
                            DynamicMin = 0;
                            DynamicMax = 0;
                            break;
                        }

                        // Copy pixel values to the array.
                        int iw = (int)width;
                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++)
                            {
                                float val = getPixel(x, y);
                                OriginalBitmap[x + y * iw] = val;
                            }

                            cancellationToken.ThrowIfCancellationRequested();
                        }
                    }
                }

                UpdateHistogram();
            }
Beispiel #31
0
Datei: PiLib.cs Projekt: habi/pi2
 public static extern IntPtr GetImage(IntPtr pi, string imgName, out Int64 width, out Int64 height, out Int64 depth, out ImageDataType dataType);