Exemplo n.º 1
0
        public async static Task <Action <byte[], PixelAccessor <Rgb888>, Rectangle> > GetImageDecoderAsync(TiffIfd ifd, Stream stream, ByteOrder byteOrder)
        {
            var photometricInterpretation = ifd.GetPhotometricInterpretation(byteOrder);

            switch (photometricInterpretation)
            {
            case TiffPhotometricInterpretation.WhiteIsZero:
            {
                var bitsPerSample = await ifd.ReadBitsPerSampleAsync(stream, byteOrder);

                if (bitsPerSample.Length >= 1 && bitsPerSample[0] == 8)
                {
                    return((imageData, pixels, destination) => DecodeImageData_Grayscale_8(imageData, pixels, destination, true));
                }
            }
            break;

            case TiffPhotometricInterpretation.BlackIsZero:
            {
                var bitsPerSample = await ifd.ReadBitsPerSampleAsync(stream, byteOrder);

                if (bitsPerSample.Length >= 1 && bitsPerSample[0] == 8)
                {
                    return((imageData, pixels, destination) => DecodeImageData_Grayscale_8(imageData, pixels, destination, false));
                }
            }
            break;

            case TiffPhotometricInterpretation.Rgb:
            {
                var samplesPerPixel = (int)ifd.GetSamplesPerPixel(byteOrder);
                var bitsPerSample   = await ifd.ReadBitsPerSampleAsync(stream, byteOrder);

                if (bitsPerSample.Length >= 3 && bitsPerSample[0] == 8 && bitsPerSample[1] == 8 && bitsPerSample[2] == 8)
                {
                    if (samplesPerPixel == 3)
                    {
                        return((imageData, pixels, destination) => DecodeImageData_Rgb_888(imageData, pixels, destination));
                    }
                    else
                    {
                        return((imageData, pixels, destination) => DecodeImageData_Rgb_888_ExtraSamples(imageData, pixels, destination, samplesPerPixel));
                    }
                }
            }
            break;

            default:
                throw new System.NotImplementedException();
            }

            throw new System.NotImplementedException();
        }