Exemple #1
0
 public BitWriter(Stream baseStream, BitOrder bitOrder, int blockSize, ByteOrder byteOrder)
 {
     _baseStream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
     _bitOrder   = bitOrder;
     _blockSize  = blockSize;
     _byteOrder  = byteOrder;
 }
 public ShiftInResponse(byte digitalPin, byte clockPin, BitOrder bitOrder, byte incoming)
 {
     DigitalPin = digitalPin;
     ClockPin   = clockPin;
     BitOrder   = bitOrder;
     Incoming   = incoming;
 }
Exemple #3
0
        public static void ShiftOut(
            IDigitalWriteRead dwr,
            int dataPin,
            int clockPin,
            int val,
            BitOrder bitOrder = BitOrder.MSBFIRST)
        {
            int i;

            System.Diagnostics.Debug.WriteLine("Shift {0}", val);

            for (i = 0; i < 8; i++)
            {
                if (bitOrder == BitOrder.LSBFIRST)
                {
                    var a = (val & (1 << i));
                    dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(a));
                }
                else
                {
                    var b = (val & (1 << (7 - i)));
                    dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(b));
                }
                ClockIt(dwr, clockPin);
            }
        }
 public ShiftOutResponse(byte digitalPin, byte clockPin, BitOrder bitOrder, byte value)
 {
     DigitalPin = digitalPin;
     ClockPin   = clockPin;
     BitOrder   = bitOrder;
     Value      = value;
 }
        private OutputPort stcpPort; // Storage Register Clock pin

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ds">Pin Serial Data</param>
        /// <param name="shcp">Pin Shift Register Clock</param>
        /// <param name="stcp">Pin Storage Register Clock</param>
        /// <param name="mr">Pin Master Reset</param>
        /// <param name="oe">Pin Output Enable</param>
        /// <param name="bitOrder">Bit order during transferring</param>
        public ShiftRegister74HC595(Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder)
        {
            // Serial Data (DS) pin is necessary
            if (ds == Cpu.Pin.GPIO_NONE)
                throw new ArgumentException("Serial Data (DS) pin is necessary");
            this.dsPort = new OutputPort(ds, false);

            // Shift Register Clock (SHCP) pin is necessary
            if (shcp == Cpu.Pin.GPIO_NONE)
                throw new ArgumentException("Shift Register Clock (SHCP) pin is necessary");
            this.shcpPort = new OutputPort(shcp, false);

            // you can save 1 pin connecting STCP and SHCP together
            if (stcp != Cpu.Pin.GPIO_NONE)
                this.stcpPort = new OutputPort(stcp, false);

            // you can save 1 pin connecting MR pin to Vcc (no reset)
            if (mr != Cpu.Pin.GPIO_NONE)
                this.mrPort = new OutputPort(mr, true);

            // you can save 1 pin connecting OE pin to GND (shift register output pins are always enabled)
            if (oe != Cpu.Pin.GPIO_NONE)
                this.oePort = new OutputPort(oe, false);

            this.bitOrder = bitOrder;
        }
Exemple #6
0
        public GFDv1(StreamInfo input)
        {
            _sourceFile = input.FileName;

            if (_texAdapters == null || _texAdapters.Count == 0)
            {
                _texAdapters = PluginLoader.Instance.GetAdapters <IMtFrameworkTextureAdapter>();
            }

            using (var br = new BinaryReaderX(input.FileData, true))
            {
                // Set endianess
                if (br.PeekString(4, Encoding.ASCII) == "\0DFG")
                {
                    br.ByteOrder = ByteOrder = ByteOrder.BigEndian;
                    br.BitOrder  = BitOrder = BitOrder.LSBFirst;
                }

                // Header
                Header  = br.ReadType <FileHeader>();
                HeaderF = br.ReadMultiple <float>(Header.FCount);

                // Name
                br.ReadInt32();
                Name = br.ReadCStringASCII();

                // Characters
                Characters = br.ReadMultiple <CharacterInfo>(Header.CharacterCount).Select(ci => new GFDv1Character
                {
                    Character = ci.Character,

                    GlyphX    = (int)ci.Block1.GlyphX,
                    GlyphY    = (int)ci.Block1.GlyphY,
                    TextureID = (int)ci.Block1.TextureIndex,

                    GlyphHeight = (int)ci.Block2.GlyphHeight,
                    GlyphWidth  = (int)ci.Block2.GlyphWidth,
                    XAdjust     = (int)ci.Block2.XAdjust,

                    IsSpace        = ci.Block3.IsSpace > 0 ? true : false,
                    Superscript    = ci.Block3.Superscript > 0 ? true : false,
                    CharacterWidth = (int)ci.Block3.CharacterWidth
                }).ToList();

                // Textures
                Textures = new List <Bitmap>();
                for (var i = 0; i < Header.FontTexCount; i++)
                {
                    IMtFrameworkTextureAdapter texAdapter = _texAdapters.Where(adapter => adapter is IIdentifyFiles).
                                                            FirstOrDefault(adapter => ((IIdentifyFiles)adapter).
                                                                           Identify(new StreamInfo(File.OpenRead(GetTexName(_sourceFile, i)), GetTexName(_sourceFile, i)), null));
                    if (texAdapter == null)
                    {
                        continue;
                    }
                    ((ILoadFiles)texAdapter).Load(new StreamInfo(File.OpenRead(GetTexName(_sourceFile, i)), GetTexName(_sourceFile, i)), null);
                    Textures.Add(((IImageAdapter)texAdapter).BitmapInfos[0].Image);
                }
            }
        }
 public ShiftInRequest(byte dataPin, byte clockPin, BitOrder bitOrder)
     : base(CommandConstants.ShiftIn)
 {
     Bytes.Add(dataPin);
     Bytes.Add(clockPin);
     Bytes.Add((byte)bitOrder);
 }
        private static void ShiftOut(IOutputPort dataPort, IOutputPort clockPort, BitOrder bitOrder,  byte value)
        {
            // Lower Clock
            clockPort.Write(false);

            for (int i = 0; i < 8; i++)
            {
                byte mask;
                if (bitOrder == BitOrder.LSBFirst)
                    mask = (byte)(1 << i);
                else
                    mask = (byte)(1 << (7 - i));

                dataPort.Write((value & mask) != 0);

                // Raise Clock
                clockPort.Write(true);

                // Raise Data to prevent IO conflict
                dataPort.Write(true);

                // Lower Clock
                clockPort.Write(false);
            }
        }
Exemple #9
0
 public ShiftOutRequest(byte dataPin, byte clockPin, BitOrder bitOrder, byte value)
     : base(CommandConstants.ShiftOut)
 {
     Bytes.Add(dataPin);
     Bytes.Add(clockPin);
     Bytes.Add((byte)bitOrder);
     Bytes.Add(value);
 }
Exemple #10
0
        /// <summary>
        /// Code for using a 74HC595 Shift Register
        /// </summary>
        /// <param name="numRegisters">Number of shift register connected in series</param>
        /// <param name="latchPin">Pin connected to ST_CP of 74HC595</param>
        /// <param name="clockPin">Pin connected to SH_CP of 74HC595</param>
        /// <param name="dataPin">Pin connected to DS of 74HC595</param>
        /// <param name="bitOrder"></param>
        public ShiftRegister(short numRegisters, Cpu.Pin latchPin, Cpu.Pin clockPin, Cpu.Pin dataPin, BitOrder bitOrder)
        {
            _numRegisters = numRegisters;
            _bitOrder = bitOrder;

            _latchPort = new OutputPort(latchPin, false);
            _clockPort = new OutputPort(clockPin, false);
            _dataPort = new OutputPort(dataPin, false);
        }
Exemple #11
0
 public BitStream(Stream stream, BitOrder order)
 {
     bit_order        = order;
     baseStream       = stream;
     bitstream_length = baseStream.Length > (long.MaxValue >> 3)
                        ? long.MaxValue
                        : (baseStream.Length << 3) - 1;
     Position = 0;
 }
Exemple #12
0
        public override Int32 GetHashCode()
        {
            int value = 31415;

            value = value * 7 + ByteOrder.GetHashCode();
            value = value * 7 + BitOrder.GetHashCode();
            value = value * 7 + BitWidth.GetHashCode();
            value = value * 7 + Signed.GetHashCode();
            return(value);
        }
Exemple #13
0
        /* Check if the decoder can decode the image from this camera */
        /* A RawDecoderException will be thrown if the camera isn't supported */
        /* Unknown cameras does NOT generate any specific feedback */
        /* This function must be overridden by actual decoders */
        void decodeUncompressed(ref TiffIFD rawIFD, BitOrder order)
        {
            UInt32 nslices = rawIFD.getEntry(STRIPOFFSETS).count;
            TiffEntry* offsets = rawIFD.getEntry(STRIPOFFSETS);
            TiffEntry* counts = rawIFD.getEntry(STRIPBYTECOUNTS);
            UInt32 yPerSlice = rawIFD.getEntry(ROWSPERSTRIP).getInt();
            UInt32 width = rawIFD.getEntry(IMAGEWIDTH).getInt();
            UInt32 height = rawIFD.getEntry(IMAGELENGTH).getInt();
            UInt32 bitPerPixel = rawIFD.getEntry(BITSPERSAMPLE).getInt();

            vector<RawSlice> slices;
            UInt32 offY = 0;

            for (UInt32 s = 0; s < nslices; s++)
            {
                RawSlice slice;
                slice.offset = offsets.getInt(s);
                slice.count = counts.getInt(s);
                if (offY + yPerSlice > height)
                    slice.h = height - offY;
                else
                    slice.h = yPerSlice;

                offY += yPerSlice;

                if (mFile.isValid(slice.offset, slice.count)) // Only decode if size is valid
                    slices.push_back(slice);
            }

            if (0 == slices.size())
                ThrowRDE("RAW Decoder: No valid slices found. File probably truncated.");

            mRaw.dim = iPoint2D(width, offY);
            mRaw.createData();
            mRaw.whitePoint = (1 << bitPerPixel) - 1;

            offY = 0;
            for (UInt32 i = 0; i < slices.size(); i++)
            {
                RawSlice slice = slices[i];
                ByteStream in(mFile, slice.offset, slice.count);
                iPoint2D size(width, slice.h);
                iPoint2D pos(0, offY);
            bitPerPixel = (int)((UInt64)((UInt64)slice.count * 8u) / (slice.h * width));
            try
            {
                readUncompressedRaw(in, size, pos, width * bitPerPixel / 8, bitPerPixel, order);
            }
            catch (RawDecoderException &e) {
                if (i > 0)
                    mRaw.setError(e.what());
                else
                    throw;
            } catch (IOException &e) {
        protected PixelIndexEncoding(IPixelIndexDescriptor pixelDescriptor, ByteOrder byteOrder, BitOrder bitOrder)
        {
            _descriptor = pixelDescriptor;
            _byteOrder  = byteOrder;
            _bitOrder   = bitOrder;

            BitDepth       = pixelDescriptor.GetBitDepth();
            FormatName     = pixelDescriptor.GetPixelName();
            ColorsPerValue = 1;

            SetValueDelegates(BitDepth);
        }
Exemple #15
0
        protected PixelEncoding(IPixelDescriptor pixelDescriptor, ByteOrder byteOrder, BitOrder bitOrder)
        {
            ContractAssertions.IsNotNull(pixelDescriptor, nameof(pixelDescriptor));

            _descriptor = pixelDescriptor;
            _byteOrder  = byteOrder;
            _bitOrder   = bitOrder;

            BitDepth       = pixelDescriptor.GetBitDepth();
            FormatName     = pixelDescriptor.GetPixelName();
            ColorsPerValue = 1;

            SetValueDelegates(BitDepth);
        }
        public Shifter74Hc595LcdTransferProvider(SPI.SPI_module spiBus, Cpu.Pin latchPin, BitOrder bitOrder)
        {
            _bitOrder = bitOrder;

            var spiConfig = new SPI.Configuration(
                latchPin,
                false, // active state
                0,     // setup time
                0,     // hold time
                false, // clock idle state
                true,  // clock edge
                1000,   // clock rate
                spiBus);

            _spi = new SPI(spiConfig);
        }
 /// <summary>
 ///     Create a new shift register (say 74595) on the specified SPI bus.
 /// </summary>
 /// <param name="spiBus">SPI module connected to the shift register.</param>
 /// <param name="latchPin">Microcontroller pin connected to the latch pin on the shift register.</param>
 /// <param name="bitOrder">Bit order of the data to be transmitted to the shift register.</param>
 /// <param name="setup">ShifterSetup object defining the order of the pins on the shift register and the pins on the LCD.</param>
 public Shifter74Hc595LcdTransferProvider(SPI.SPI_module spiBus, Cpu.Pin latchPin, BitOrder bitOrder,
                                          ShifterSetup setup)
     : base(setup)
 {
     _bitOrder = bitOrder;
     SPI.Configuration spiConfig = new SPI.Configuration(
         ChipSelect_Port: Cpu.Pin.GPIO_NONE,     // No chip select.
         ChipSelect_ActiveState: false,          // Chip select is active low.
         ChipSelect_SetupTime: 0,                // Amount of time between selection and the clock starting
         ChipSelect_HoldTime: 0,                 // Amount of time the device must be active after the data has been read.
         Clock_Edge: false,                      // Sample on the falling edge.
         Clock_IdleState: true,                  // Clock is idle when low.
         Clock_RateKHz: 1000,                    // 1MHz clock speed.
         SPI_mod: spiBus);
     _spi       = new SPI(spiConfig);
     _latchPort = new OutputPort(latchPin, false);
 }
        public Shifter74Hc595LcdTransferProvider(SPI.SPI_module spiBus, Cpu.Pin latchPin, BitOrder bitOrder, ShifterSetup setup)
            : base(setup)
        {
            _bitOrder = bitOrder;

            var spiConfig = new SPI.Configuration(
                Cpu.Pin.GPIO_NONE, //latchPin,
                false, // active state
                0,     // setup time
                0,     // hold time
                false, // clock idle state
                true,  // clock edge
                1000,   // clock rate
                spiBus);

            _spi = new SPI(spiConfig);
            _latchPort = new OutputPort(latchPin, true);
        }
        public Shifter74Hc595LcdTransferProvider(SPI.SPI_module spiBus, Cpu.Pin latchPin, BitOrder bitOrder, ShifterSetup setup)
            : base(setup)
        {
            _bitOrder = bitOrder;

            var spiConfig = new SPI.Configuration(
                Cpu.Pin.GPIO_NONE, //latchPin,
                false,             // active state
                0,                 // setup time
                0,                 // hold time
                false,             // clock idle state
                true,              // clock edge
                1000,              // clock rate
                spiBus);

            _spi       = new SPI(spiConfig);
            _latchPort = new OutputPort(latchPin, true);
        }
        /// <summary>
        /// Constructor using bit banging
        /// </summary>
        /// <param name="interfaceDataMode">Interface data mode</param>
        /// <param name="rs">Pin Register Select</param>
        /// <param name="rw">Pin Select Read/Write</param>
        /// <param name="enable">Pin Enable</param>
        /// <param name="ds">Pin Serial Data</param>
        /// <param name="shcp">Pin Shift Register Clock</param>
        /// <param name="stcp">Pin Storage Register Clock</param>
        /// <param name="mr">Pin Master Reset</param>
        /// <param name="oe">Pin Output Enable</param>
        /// <param name="bitOrder">Bit order during transferring</param>
        public Shift74HC595LcdTransferProvider(InterfaceDataMode interfaceDataMode, Cpu.Pin rs, Cpu.Pin rw, Cpu.Pin enable,
            Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder)
        {
            // set interface data mode (4 or 8 bits)
            this.interfaceDataMode = interfaceDataMode;

            // Register Select (rs) pin is necessary
            if (rs == Cpu.Pin.GPIO_NONE)
                throw new ArgumentException("Register Select (RS) pin is necessary");
            this.rsPort = new OutputPort(rs, false);

            // you can save 1 pin setting from your board, wiring RW pin to GND for write only operation
            if (rw != Cpu.Pin.GPIO_NONE)
                this.rwPort = new OutputPort(rw, false);

            // Enable (enable) pin is necessary
            if (enable == Cpu.Pin.GPIO_NONE)
                throw new ArgumentException("Enable (EN) signal pin is necessary");
            this.enablePort = new OutputPort(enable, false);

            this.shift = new ShiftRegister74HC595(ds, shcp, stcp, mr, oe, bitOrder);
        }
Exemple #21
0
        public static int ShiftIn(IDigitalWriteRead dwr, int dataPin, int clockPin, BitOrder bitOrder)
        {
            int value = 0;
            int i;

            for (i = 0; i < 8; ++i)
            {
                dwr.DigitalWrite(clockPin, PinState.High);

                if (bitOrder == BitOrder.LSBFIRST)
                {
                    value |= Nusbio.ConvertTo1Or0(dwr.DigitalRead(dataPin)) << i;
                }
                else
                {
                    value |= Nusbio.ConvertTo1Or0(dwr.DigitalRead(dataPin)) << (7 - i);
                }

                dwr.DigitalWrite(dataPin, PinState.Low);
            }
            return(value);
        }
Exemple #22
0
        /// <summary>
        /// Constructor using SPI mode
        /// </summary>
        /// <param name="spiModule">SPI device module</param>
        /// <param name="stcp">Pin Storage Register Clock</param>
        /// <param name="mr">Pin Master Reset</param>
        /// <param name="oe">Pin Output Enable</param>
        /// <param name="bitOrder">Bit order during transferring</param>
        public ShiftRegister74HC595(SPI.SPI_module spiModule, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder)
        {
            // SPI mode :
            // MOSI connected to DS (shift register)
            // SCKL connected to SHCP (shift register)
            SPI.Configuration spiConf = new SPI.Configuration(Cpu.Pin.GPIO_NONE, // chip select not necessary, we use stcp pin (latch)
                                                              false,             // active state
                                                              0,                 // setup time
                                                              0,                 // hold time
                                                              false,             // clock idle state (our clock is shcp and its idle state is low)
                                                              true,              // clock edge (rising)
                                                              1000,              // clock rate
                                                              spiModule);        // spi bus

            this.spi       = new SPI(spiConf);
            this.spiBuffer = new byte[1];

            // you can save 1 pin connecting MR pin to Vcc (no reset)
            if (mr != Cpu.Pin.GPIO_NONE)
            {
                this.mrPort = new OutputPort(mr, true);
            }

            // you can save 1 pin connecting OE pin to GND (shift register output pins are always enabled)
            if (oe != Cpu.Pin.GPIO_NONE)
            {
                this.oePort = new OutputPort(oe, false);
            }

            // you can save 1 pin connecting STCP and SHCP together
            if (stcp != Cpu.Pin.GPIO_NONE)
            {
                this.stcpPort = new OutputPort(stcp, false);
            }

            this.bitOrder = bitOrder;
        }
Exemple #23
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ds">Pin Serial Data</param>
        /// <param name="shcp">Pin Shift Register Clock</param>
        /// <param name="stcp">Pin Storage Register Clock</param>
        /// <param name="mr">Pin Master Reset</param>
        /// <param name="oe">Pin Output Enable</param>
        /// <param name="bitOrder">Bit order during transferring</param>
        public ShiftRegister74HC595(Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder)
        {
            // Serial Data (DS) pin is necessary
            if (ds == Cpu.Pin.GPIO_NONE)
            {
                throw new ArgumentException("Serial Data (DS) pin is necessary");
            }
            this.dsPort = new OutputPort(ds, false);

            // Shift Register Clock (SHCP) pin is necessary
            if (shcp == Cpu.Pin.GPIO_NONE)
            {
                throw new ArgumentException("Shift Register Clock (SHCP) pin is necessary");
            }
            this.shcpPort = new OutputPort(shcp, false);

            // you can save 1 pin connecting STCP and SHCP together
            if (stcp != Cpu.Pin.GPIO_NONE)
            {
                this.stcpPort = new OutputPort(stcp, false);
            }

            // you can save 1 pin connecting MR pin to Vcc (no reset)
            if (mr != Cpu.Pin.GPIO_NONE)
            {
                this.mrPort = new OutputPort(mr, true);
            }

            // you can save 1 pin connecting OE pin to GND (shift register output pins are always enabled)
            if (oe != Cpu.Pin.GPIO_NONE)
            {
                this.oePort = new OutputPort(oe, false);
            }

            this.bitOrder = bitOrder;
        }
Exemple #24
0
        /** Attempt to decode the image
         * A RawDecoderException will be thrown if the image cannot be decoded
         */
        public static void ReadUncompressedRaw(ImageBinaryReader input, Point2D size, Point2D offset, long inputPitch, int bitPerPixel, BitOrder order, Image <ushort> rawImage)
        {
            //uint outPitch = rawImage.pitch;
            var pos = new Point2D(size);//to avoid rewriting the image pos

            if (input.RemainingSize < (inputPitch * pos.height))
            {
                if (input.RemainingSize > inputPitch)
                {
                    pos.height = (uint)(input.RemainingSize / inputPitch - 1);
                    rawImage.errors.Add("Image truncated (file is too short)");
                }
                else
                {
                    throw new IOException("Not enough data to decode a single line. Image file truncated.");
                }
            }
            if (bitPerPixel > 16)
            {
                throw new RawDecoderException("Unsupported bit depth");
            }

            int skipBits = (int)(inputPitch - pos.width * rawImage.fullSize.cpp * bitPerPixel / 8);  // Skip per line

            if (offset.height > rawImage.fullSize.dim.height)
            {
                throw new RawDecoderException("Invalid y offset");
            }
            if (offset.width + size.width > rawImage.fullSize.dim.width)
            {
                throw new RawDecoderException("Invalid x offset");
            }

            uint y = offset.height;

            if (bitPerPixel == 8)
            {
                Decode8BitRaw(input, pos, offset, rawImage);
                return;
            }
            else if (bitPerPixel == 10 && order == BitOrder.Jpeg && skipBits == 0)
            {
                //Optimisation for windows phone DNG
                Decode10BitRaw(input, pos, offset, rawImage);
                return;
            } /*
               * else if (bitPerPixel == 16 && Common.GetHostEndianness() == Endianness.Little)
               * {
               * Decode16BitRawUnpacked(input, pos, offset, rawImage);
               * return;
               * }
               * else if (bitPerPixel == 12 && pos.width == inputPitch * 8 / 12 && Common.GetHostEndianness() == Endianness.Little)
               * {
               * Decode12BitRaw(input, pos, offset, rawImage);
               * return;
               * }*/

            pos.width *= rawImage.fullSize.cpp;
            var off   = ((pos.width * bitPerPixel) / 8) + skipBits;
            var pumps = new BitPump[pos.height];

            //read the data
            switch (order)
            {
            case BitOrder.Jpeg:
                for (int i = 0; i < pos.height; i++)
                {
                    pumps[i] = new BitPumpMSB(input, input.BaseStream.Position, off);
                }
                break;

            case BitOrder.Jpeg16:
                for (int i = 0; i < pos.height; i++)
                {
                    pumps[i] = new BitPumpMSB16(input, input.BaseStream.Position, off);
                }
                break;

            case BitOrder.Jpeg32:
                for (int i = 0; i < pos.height; i++)
                {
                    pumps[i] = new BitPumpMSB32(input, input.BaseStream.Position, off);
                }
                break;

            default:
                for (int i = 0; i < pos.height; i++)
                {
                    pumps[i] = new BitPumpPlain(input, input.BaseStream.Position, off);
                }
                break;
            }
            Parallel.For(0, pos.height, i =>
            {
                long p = ((offset.height + i) * rawImage.fullSize.dim.width + offset.width) * rawImage.fullSize.cpp;
                for (uint x = 0; x < pos.width; x++)
                {
                    rawImage.fullSize.rawView[x + p] = (ushort)pumps[i].GetBits(bitPerPixel);
                }
            });
        }
Exemple #25
0
 /// <summary>
 ///     Reads next unsigned 32-bit integer from stream.
 /// </summary>
 /// <returns>32-bit unsigned integer.</returns>
 public UInt32 ReadUInt32(BitOrder seq = BitOrder.LittleEndian)
 {
     return ReadBytes(4).ToUInt32(0, seq);
 }
Exemple #26
0
 public static IIndexEncoding I4(BitOrder bitOrder = BitOrder.MostSignificantBitFirst) => new Index(4, ByteOrder.LittleEndian, bitOrder);
 /// <summary>
 ///     Create a new shift register (say 74595) on the specified SPI bus.
 /// </summary>
 /// <param name="spiBus">SPI module connected to the shift register.</param>
 /// <param name="latchPin">Microcontroller pin connected to the latch pin on the shift register.</param>
 /// <param name="bitOrder">Bit order of the data to be transmitted to the shift register.</param>
 public Shifter74Hc595LcdTransferProvider(SPI.SPI_module spiBus, Cpu.Pin latchPin, BitOrder bitOrder)
     : this(spiBus, latchPin, bitOrder, DefaultSetup)
 {
 }
        /// <summary>
        /// Constructor using SPI mode
        /// </summary>
        /// <param name="spiModule">SPI device module</param>
        /// <param name="stcp">Pin Storage Register Clock</param>
        /// <param name="mr">Pin Master Reset</param>
        /// <param name="oe">Pin Output Enable</param>
        /// <param name="bitOrder">Bit order during transferring</param>
        public ShiftRegister74HC595(SPI.SPI_module spiModule, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder)
        {
            // SPI mode :
            // MOSI connected to DS (shift register)
            // SCKL connected to SHCP (shift register)
            SPI.Configuration spiConf = new SPI.Configuration(Cpu.Pin.GPIO_NONE, // chip select not necessary, we use stcp pin (latch)
                                                              false, // active state
                                                              0, // setup time
                                                              0, // hold time
                                                              false, // clock idle state (our clock is shcp and its idle state is low)
                                                              true, // clock edge (rising)
                                                              1000, // clock rate
                                                              spiModule); // spi bus

            this.spi = new SPI(spiConf);
            this.spiBuffer = new byte[1];

            // you can save 1 pin connecting MR pin to Vcc (no reset)
            if (mr != Cpu.Pin.GPIO_NONE)
                this.mrPort = new OutputPort(mr, true);

            // you can save 1 pin connecting OE pin to GND (shift register output pins are always enabled)
            if (oe != Cpu.Pin.GPIO_NONE)
                this.oePort = new OutputPort(oe, false);

            // you can save 1 pin connecting STCP and SHCP together
            if (stcp != Cpu.Pin.GPIO_NONE)
                this.stcpPort = new OutputPort(stcp, false);

            this.bitOrder = bitOrder;
        }
Exemple #29
0
        protected override void decodeRawInternal()
        {
            UInt32 width = 0, height = 0, filesize = 0, bits = 0, offset = 0;

            if (cam.hints.TryGetValue("full_width", out string tmp))
            {
                width = UInt32.Parse(tmp);
            }
            else
            {
                throw new RawDecoderException("Naked: couldn't ContainsKey width");
            }

            if (cam.hints.TryGetValue("full_height", out tmp))
            {
                height = UInt32.Parse(tmp);
            }
            else
            {
                throw new RawDecoderException("Naked: couldn't ContainsKey height");
            }

            if (cam.hints.TryGetValue("filesize", out tmp))
            {
                filesize = UInt32.Parse(tmp);
            }
            else
            {
                throw new RawDecoderException("Naked: couldn't ContainsKey filesize");
            }

            if (cam.hints.TryGetValue("offset", out tmp))
            {
                offset = UInt32.Parse(tmp);
            }

            if (cam.hints.TryGetValue("bits", out tmp))
            {
                bits = UInt32.Parse(tmp);
            }
            else
            {
                bits = (filesize - offset) * 8 / width / height;
            }

            BitOrder bo = BitOrder.Jpeg16;  // Default

            if (cam.hints.TryGetValue("order", out tmp))
            {
                if (tmp == "plain")
                {
                    bo = BitOrder.Plain;
                }
                else if (tmp == "jpeg")
                {
                    bo = BitOrder.Jpeg;
                }
                else if (tmp == "jpeg16")
                {
                    bo = BitOrder.Jpeg16;
                }
                else if (tmp == "jpeg32")
                {
                    bo = BitOrder.Jpeg32;
                }
            }

            rawImage.dim = new Point2D((int)width, (int)height);
            rawImage.Init();
            reader = new TIFFBinaryReader(reader.BaseStream, offset, (uint)reader.BaseStream.Length);
            Point2D pos = new Point2D(0, 0);

            readUncompressedRaw(ref reader, rawImage.dim, pos, (int)(width * bits / 8), (int)bits, bo);
        }
Exemple #30
0
 /// <summary>
 /// Creates a new instance of <see cref="Index"/>.
 /// </summary>
 /// <param name="i">Value of the index component.</param>
 /// <param name="componentOrder">The order of the components.</param>
 /// <param name="byteOrder">The byte order in which atomic values are read.</param>
 /// <param name="bitOrder">The bit order in which bit values are read.</param>
 public Index(int i, string componentOrder, ByteOrder byteOrder = ByteOrder.LittleEndian, BitOrder bitOrder = BitOrder.MostSignificantBitFirst) :
     this(i, 0, componentOrder, byteOrder, bitOrder)
 {
 }
Exemple #31
0
 internal static extern ErrorCode SetBitOrder(IntPtr handle, BitOrder order);
        /// <summary>
        ///     Overloaded.
        ///     Assembles a byte array into an integer.
        /// </summary>
        /// <param name="src">Byte array representing the integer</param>
        /// <param name="offset">Byte offset of the integer</param>
        /// <param name="seq">Byte order of the array</param>
        /// <returns>Integer assembled from the byte array</returns>
        public static UInt64 ToUInt64(this Byte[] src, Int32 offset, BitOrder seq = BitOrder.LittleEndian)
        {
            if (offset < 0 || offset > src.Length - 8)
                throw new ArgumentOutOfRangeException("offset", "Byte[].ToUInt64(): Offset out of source array bounds");

            UInt64 result;
            if (seq == BitOrder.LittleEndian)
            {
                result = src[0];
                for (int i = 1; i < 8; i++)
                {
                    result |= Convert.ToUInt64(Convert.ToUInt64(src[i]) << (i * 8));
                }
            }
            else
            {
                result = src[7];
                for (int i = 1; i < 8; i++)
                {
                    result |= Convert.ToUInt64(Convert.ToUInt64(src[7 - i]) << (i * 8));
                }
            }

            return result;
        }
        /// <summary>
        ///     Overloaded.
        ///     Assembles a byte array into an integer.
        /// </summary>
        /// <param name="src">Byte array representing the integer</param>
        /// <param name="offset">Byte offset of the integer</param>
        /// <param name="seq">Byte order of the array</param>
        /// <returns>Integer assembled from the byte array</returns>
        public static UInt16 ToUInt16(this Byte[] src, Int32 offset, BitOrder seq = BitOrder.LittleEndian)
        {
            if (offset < 0 || offset > src.Length - 2)
                throw new ArgumentOutOfRangeException("offset", "Byte[].ToUInt16(): Offset out of source array bounds");

            UInt16 result;
            if (seq == BitOrder.LittleEndian)
            {
                result = src[0];
                result |= Convert.ToUInt16(Convert.ToUInt16(src[1]) << 8);
            }
            else
            {
                result = src[1];
                result |= Convert.ToUInt16(Convert.ToUInt16(src[0]) << 8);
            }

            return result;
        }
Exemple #34
0
        public GFDv2(FileStream input)
        {
            _sourceFile = input.Name;

            if (_texAdapters == null || _texAdapters.Count == 0)
            {
                PluginLoader.ComposePlugins(this);
            }

            using (var br = new BinaryReaderX(input))
            {
                // Set endianess
                if (br.PeekString(4, Encoding.ASCII) == "\0DFG")
                {
                    br.ByteOrder = ByteOrder = ByteOrder.BigEndian;
                    br.BitOrder  = BitOrder = BitOrder.LSBFirst;
                }

                // Header
                Header  = br.ReadType <FileHeader>();
                HeaderF = br.ReadMultiple <float>(Header.FCount);

                // Name
                br.ReadInt32();
                Name = br.ReadCStringASCII();

                // Characters
                Characters = br.ReadMultiple <CharacterInfo>(Header.CharacterCount).Select(ci => new GFDv2Character
                {
                    Character = ci.Character,

                    TextureID = (int)ci.Block1.TextureIndex,
                    GlyphX    = (int)ci.Block1.GlyphX,
                    GlyphY    = (int)ci.Block1.GlyphY,

                    Block2Trailer = (int)ci.Block2.Block2Trailer,
                    GlyphWidth    = (int)ci.Block2.GlyphWidth,
                    GlyphHeight   = (int)ci.Block2.GlyphHeight,

                    CharacterWidth  = (int)ci.Block3.CharacterWidth,
                    CharacterHeight = (int)ci.Block3.CharacterHeight,

                    XAdjust = ci.XAdjust,
                    YAdjust = ci.YAdjust
                }).ToList();

                // Textures
                Textures = new List <Bitmap>();
                for (var i = 0; i < Header.FontTexCount; i++)
                {
                    //TODO
                    IMtFrameworkTextureAdapter texAdapter = null;//_texAdapters.Where(adapter => adapter is IIdentifyFiles).FirstOrDefault(adapter => ((IIdentifyFiles)adapter).Identify(GetTexName(_sourceFile, i)));
                    if (texAdapter == null)
                    {
                        continue;
                    }
                    //TODO
                    //((ILoadFiles)texAdapter).Load(GetTexName(_sourceFile, i));
                    Textures.Add(((IImageAdapter)texAdapter).BitmapInfos[0].Image);
                }
            }
        }
Exemple #35
0
        public TiffDirectory()
        {
            td_subfiletype = 0;
            td_compression = 0;
            td_photometric = 0;
            td_planarconfig = 0;

            td_fillorder = BitOrder.BigEndian;
            td_bitspersample = 1;
            td_threshholding = Threshold.BILevel;
            td_orientation = Orientation.TopLeft;
            td_samplesperpixel = 1;
            td_rowsperstrip = -1;
            td_tiledepth = 1;
            td_stripbytecountsorted = true; // Our own arrays always sorted.
            td_resolutionunit = ResolutionUnit.Inch;
            td_sampleformat = SampleFormat.UInt;
            td_imagedepth = 1;
            td_ycbcrsubsampling[0] = 2;
            td_ycbcrsubsampling[1] = 2;
            td_ycbcrpositioning = YCbCrPosition.Centered;
        }
Exemple #36
0
 /// <summary>
 ///     Writes a unsigned 16-bit integer to the StreamEx.
 /// </summary>
 /// <param name="b">16-bit unsigned integer.</param>
 /// <param name="seq">Byte sequence a.k.a endianness.</param>
 public void WriteUInt16(UInt16 b, BitOrder seq = BitOrder.LittleEndian)
 {
     Write(b.ToBinary(seq), 0, 2);
 }
Exemple #37
0
 /// <summary>
 ///     Reads next unsigned 64-bit integer from stream.
 /// </summary>
 /// <returns>64-bit unsigned integer.</returns>
 public UInt64 ReadUInt64(BitOrder seq = BitOrder.LittleEndian)
 {
     return ReadBytes(8).ToUInt64(0, seq);
 }
        /// <summary>
        ///     Overloaded.
        ///     Assembles a byte array into an integer.
        /// </summary>
        /// <param name="src">Byte array representing the integer</param>
        /// <param name="offset">Byte offset of the integer</param>
        /// <param name="seq">Byte order of the array</param>
        /// <returns>Integer assembled from the byte array</returns>
        public static Int64 ToInt64(this Byte[] src, Int32 offset, BitOrder seq = BitOrder.LittleEndian)
        {
            if (offset < 0 || offset > src.Length - 8)
                throw new ArgumentOutOfRangeException("offset", "Byte[].ToInt64(): Offset out of source array bounds");

            return Sign(src.ToUInt64(offset, seq));
        }
Exemple #39
0
 /// <summary>
 /// Constructor without using MR and OE.
 /// SHCP and STCP are connected together
 /// </summary>
 public ShiftRegister74HC595(SPI.SPI_module spiModule, BitOrder bitOrder)
     : this(spiModule, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, bitOrder)
 {
 }
 /// <summary>
 ///     Overloaded.
 ///     Breaks an integer into an array of bytes.
 /// </summary>
 /// <param name="src">Integer to break</param>
 /// <param name="seq">Byte order of the resulting array</param>
 /// <returns>An array of bytes representing the integer</returns>
 public static Byte[] ToBinary(this Double src, BitOrder seq = BitOrder.LittleEndian)
 {
     MidDouble m = MidDouble.Init();
     m.doubleValue = src;
     return m.intValue.ToBinary(seq);
 }
        /// <summary>
        ///     Overloaded.
        ///     Breaks an integer into an array of bytes.
        /// </summary>
        /// <param name="src">Integer to break</param>
        /// <param name="seq">Byte order of the resulting array</param>
        /// <returns>An array of bytes representing the integer</returns>
        public static Byte[] ToBinary(this UInt64 src, BitOrder seq = BitOrder.LittleEndian)
        {
            Byte[] result = new Byte[8];
            for (int i = 0; i < 8; i++)
            {
                result[7 - i] = Convert.ToByte(src & 0xFF);
                src >>= 8;
            }

            if (seq == BitOrder.LittleEndian)
            {
                Array.Reverse(result);
            }
            return result;
        }
Exemple #42
0
 /// <summary>
 /// Creates a new instance of <see cref="Index"/>.
 /// </summary>
 /// <param name="i">Value of the index component.</param>
 /// <param name="a">Value of the alpha component.</param>
 /// <param name="byteOrder">The byte order in which atomic values are read.</param>
 /// <param name="bitOrder">The bit order in which bit values are read.</param>
 public Index(int i, int a, ByteOrder byteOrder = ByteOrder.LittleEndian, BitOrder bitOrder = BitOrder.MostSignificantBitFirst) :
     this(i, a, "IA", byteOrder, bitOrder)
 {
 }
Exemple #43
0
        public GFDv1(StreamInfo input)
        {
            _sourceFile = input.FileName;

            if (_texAdapters == null || _texAdapters.Count == 0)
            {
                _texAdapters = PluginLoader.Instance.GetAdapters <IMtFrameworkTextureAdapter>();
            }

            using (var br = new BinaryReaderX(input.FileData))
            {
                // Set endianess
                if (br.PeekString() == "\0DFG")
                {
                    br.ByteOrder = ByteOrder = ByteOrder.BigEndian;
                    br.BitOrder  = BitOrder = BitOrder.LSBFirst;
                }

                // Header
                Header  = br.ReadType <FileHeader>();
                HeaderF = br.ReadMultiple <float>(Header.FCount);

                // Name
                br.ReadInt32();
                Name = br.ReadCStringASCII();

                // Characters
                Characters = br.ReadMultiple <CharacterInfo>(Header.CharacterCount).Select(ci => new GFDv1Character
                {
                    Character = ci.Character,

                    WidthInfo = new CharWidthInfo
                    {
                        CharWidth  = (int)ci.Block2.GlyphWidth,
                        GlyphWidth = (int)ci.Block2.GlyphWidth,
                        Left       = (int)ci.Block2.XAdjust
                    },

                    GlyphX    = (int)ci.Block1.GlyphX,
                    GlyphY    = (int)ci.Block1.GlyphY,
                    TextureID = (int)ci.Block1.TextureIndex,

                    GlyphWidth  = (int)ci.Block2.GlyphWidth,
                    GlyphHeight = (int)ci.Block2.GlyphHeight,
                    XAdjust     = (int)ci.Block2.XAdjust,

                    IsSpace        = ci.Block3.IsSpace > 0,
                    Superscript    = ci.Block3.Superscript > 0,
                    CharacterWidth = (int)ci.Block3.CharacterWidth
                }).ToList();

                // Textures
                Textures = new List <Bitmap>();
                for (var i = 0; i < Header.FontTexCount; i++)
                {
                    var streamInfo = new StreamInfo {
                        FileData = File.OpenRead(GetTexName(_sourceFile, i)), FileName = GetTexName(_sourceFile, i)
                    };
                    var texAdapter = _texAdapters.Where(adapter => adapter is IIdentifyFiles).FirstOrDefault(adapter => ((IIdentifyFiles)adapter).Identify(streamInfo, null));
                    streamInfo.FileData.Position = 0;
                    if (texAdapter == null)
                    {
                        continue;
                    }
                    ((ILoadFiles)texAdapter).Load(streamInfo, null);
                    Textures.Add(((IImageAdapter)texAdapter).BitmapInfos[0].Image);
                }

                // Glyphs
                foreach (var c in Characters)
                {
                    var width  = c.WidthInfo.GlyphWidth;
                    var height = c.GlyphHeight;

                    var glyph = new Bitmap(Math.Max(width, 1), Math.Max(height, 1), PixelFormat.Format32bppArgb);
                    var gfx   = Graphics.FromImage(glyph);
                    gfx.DrawImage(Textures[c.TextureID],
                                  new[] {
                        new PointF(0, 0),
                        new PointF(width, 0),
                        new PointF(0, height)
                    },
                                  new RectangleF(c.GlyphX, c.GlyphY, width, height),
                                  GraphicsUnit.Pixel);
                    c.Glyph = glyph;
                }
            }
        }
Exemple #44
0
 /// <summary>
 /// Creates a new instance of <see cref="Index"/>.
 /// </summary>
 /// <param name="i">Value of the index component.</param>
 /// <param name="a">Value of the alpha component.</param>
 /// <param name="componentOrder">The order of the components.</param>
 /// <param name="byteOrder">The byte order in which atomic values are read.</param>
 /// <param name="bitOrder">The bit order in which bit values are read.</param>
 public Index(int i, int a, string componentOrder, ByteOrder byteOrder = ByteOrder.LittleEndian, BitOrder bitOrder = BitOrder.MostSignificantBitFirst) :
     base(new IndexPixelDescriptor(componentOrder, i, a), byteOrder, bitOrder)
 {
     MaxColors = (int)Math.Pow(2, i);
 }
 public Shifter74Hc595LcdTransferProvider(SPI.SPI_module spiBus, Cpu.Pin latchPin, BitOrder bitOrder)
     : this(spiBus, latchPin, bitOrder, DefaultSetup)
 {
 }
 /// <summary>
 ///     Overloaded.
 ///     Breaks an integer into an array of bytes.
 /// </summary>
 /// <param name="src">Integer to break</param>
 /// <param name="seq">Byte order of the resulting array</param>
 /// <returns>An array of bytes representing the integer</returns>
 public static Byte[] ToBinary(this Int64 src, BitOrder seq = BitOrder.LittleEndian)
 {
     return Unsign(src).ToBinary(seq);
 }
 /// <summary>
 /// Constructor without using MR and OE
 /// </summary>
 public Shift74HC595LcdTransferProvider(InterfaceDataMode interfaceDataMode, Cpu.Pin rs, Cpu.Pin rw, Cpu.Pin enable, Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, BitOrder bitOrder)
     : this(interfaceDataMode, rs, rw, enable, ds, shcp, stcp, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, bitOrder)
 {
 }
 /// <summary>
 /// Constructor without using MR and OE.
 /// SHCP and STCP are connected together
 /// </summary>
 public ShiftRegister74HC595(SPI.SPI_module spiModule, BitOrder bitOrder)
     : this(spiModule, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, bitOrder)
 {
 }
Exemple #49
0
 /// <summary>
 ///     Reads next unsigned 16-bit integer from stream.
 /// </summary>
 /// <returns>16-bit unsigned integer.</returns>
 public UInt16 ReadUInt16(BitOrder seq = BitOrder.LittleEndian)
 {
     return ReadBytes(2).ToUInt16(0, seq);
 }
 /// <summary>
 /// Constructor without using MR and OE
 /// </summary>
 public ShiftRegister74HC595(Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, BitOrder bitOrder)
     : this(ds, shcp, stcp, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, bitOrder)
 {
 }
Exemple #51
0
 /// <summary>
 /// Constructor without using MR and OE.
 /// SHCP and STCP are connected together
 /// </summary>
 public ShiftRegister74HC595(Cpu.Pin ds, Cpu.Pin shcp, BitOrder bitOrder)
     : this(ds, shcp, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, Cpu.Pin.GPIO_NONE, bitOrder)
 {
 }
        /// <summary>
        ///     Overloaded.
        ///     Breaks an integer into an array of bytes.
        /// </summary>
        /// <param name="src">Integer to break</param>
        /// <param name="seq">Byte order of the resulting array</param>
        /// <returns>An array of bytes representing the integer</returns>
        public static Byte[] ToBinary(this UInt16 src, BitOrder seq = BitOrder.LittleEndian)
        {
            Byte[] result = new Byte[2];
            result[1] = Convert.ToByte(src & 0xFF);
            result[0] = Convert.ToByte((src >> 8) & 0xFF);

            if (seq == BitOrder.LittleEndian)
            {
                Array.Reverse(result);
            }
            return result;
        }
        /// <summary>
        ///     Overloaded.
        ///     Assembles a byte array into an integer.
        /// </summary>
        /// <param name="src">Byte array representing the integer</param>
        /// <param name="offset">Byte offset of the integer</param>
        /// <param name="seq">Byte order of the array</param>
        /// <returns>Integer assembled from the byte array</returns>
        public static Single ToSingle(this Byte[] src, Int32 offset, BitOrder seq = BitOrder.LittleEndian)
        {
            if (offset < 0 || offset > src.Length - 4)
                throw new ArgumentOutOfRangeException("offset", "Byte[].ToSingle(): Offset out of source array bounds");

            MidSingle m = MidSingle.Init();
            m.intValue = src.ToUInt32(offset, seq);
            return m.singleValue;
        }
Exemple #54
0
 /// <summary>
 ///     Writes a unsigned 32-bit integer to the StreamEx.
 /// </summary>
 /// <param name="b">32-bit unsigned integer.</param>
 /// <param name="seq">Byte sequence a.k.a endianness.</param>
 public void WriteUInt32(UInt32 b, BitOrder seq = BitOrder.LittleEndian)
 {
     Write(b.ToBinary(seq), 0, 4);
 }
Exemple #55
0
 public static IColorEncoding A4(BitOrder bitOrder     = BitOrder.MostSignificantBitFirst) => new La(0, 4, ByteOrder.LittleEndian, bitOrder);
Exemple #56
0
 private bool isFillOrder(BitOrder o)
 {
     TiffFlags order = (TiffFlags)o;
     return ((m_flags & order) == order);
 }
Exemple #57
0
 /// <summary>
 ///     Writes a unsigned 64-bit integer to the StreamEx.
 /// </summary>
 /// <param name="b">64-bit unsigned integer.</param>
 /// <param name="seq">Byte sequence a.k.a endianness.</param>
 public void WriteUInt64(UInt64 b, BitOrder seq = BitOrder.LittleEndian)
 {
     Write(b.ToBinary(seq), 0, 8);
 }