Example #1
0
        public static GDIPen UnpackGPen(BufferChunk chunk)
        {
            uint     penColor;
            PenStyle penStyle;
            Guid     uniqueID;
            int      penSize;

            penStyle = (PenStyle)chunk.NextInt32();
            penSize  = chunk.NextInt32();
            penColor = chunk.NextUInt32();
            uniqueID = UnpackGuid(chunk);

            GDIPen aPen = new GDIPen(PenType.Cosmetic, PenStyle.Solid, PenJoinStyle.Round, PenEndCap.Round, penColor, penSize, uniqueID);

            return(aPen);
        }
Example #2
0
File: TMPlan.cs Project: x2v0/TM
        /// <summary>
        ///    Nexts the plan spot result.
        /// </summary>
        /// <param name="buf">The buf.</param>
        /// <returns>System.Nullable&lt;SpotResult&gt;.</returns>
        public static SpotResult?NextSpotResult(this BufferChunk buf)
        {
            var plan = new SpotResult();

            try {
                plan.id            = buf.NextInt32();
                plan.result_xangle = buf.NextFloat();
                plan.result_zangle = buf.NextFloat();
                plan.result_pcount = buf.NextFloat();
                plan.done          = buf.NextInt32();
            } catch {
                //plan.id = -1; //
                return(null);
            }

            return(plan);
        }
        //public static void Pack(BufferChunk chunk, XFORM aTrans)
        //{
        //    chunk += aTrans.eDx;
        //    chunk += aTrans.eDy;
        //    chunk += aTrans.eM11;
        //    chunk += aTrans.eM12;
        //    chunk += aTrans.eM21;
        //    chunk += aTrans.eM22;
        //}

        //public static void Pack(BufferChunk chunk, TRIVERTEX[] vertices)
        //{
        //    int nVertices = vertices.Length;

        //    // Pack the vertices, starting with the length
        //    chunk += nVertices;
        //    for (int i = 0; i < nVertices; i++)
        //    {
        //        chunk += vertices[i].x;
        //        chunk += vertices[i].y;
        //        chunk += vertices[i].Alpha;
        //        chunk += vertices[i].Blue;
        //        chunk += vertices[i].Green;
        //        chunk += vertices[i].Red;
        //    }
        //}

        //public static void Pack(BufferChunk chunk, GRADIENT_RECT[] gRect)
        //{
        //    int nRects = gRect.Length;

        //    chunk += nRects;
        //    for (int i = 0; i < nRects; i++)
        //    {
        //        chunk += gRect[i].UpperLeft;
        //        chunk += gRect[i].LowerRight;
        //    }
        //}

        //public static void Pack(BufferChunk chunk, GBrush aBrush)
        //{
        //    chunk += GDI32.EMR_CREATEBRUSHINDIRECT;
        //    chunk += (int)aBrush.Style;
        //    chunk += (int)aBrush.Hatching;
        //    chunk += aBrush.Color;
        //    Pack(chunk, aBrush.UniqueID);
        //}

        //public static void Pack(BufferChunk chunk, GPen aPen)
        //{
        //    chunk += GDI32.EMR_CREATEPEN;
        //    chunk += (int)aPen.Style;
        //    chunk += 1;
        //    chunk += aPen.Color;
        //    Pack(chunk, aPen.UniqueID);
        //}

        //public static void Pack(BufferChunk chunk, GFont aFont)
        //{
        //    chunk += GDI32.EMR_EXTCREATEFONTINDIRECTW;

        //    chunk += aFont.FaceName.Length;
        //    chunk += aFont.FaceName;
        //    chunk += (int)aFont.Height;
        //    chunk += (byte)1; // newFont.fLogFont.lfCharSet;
        //    chunk += (byte)0; // newFont.fLogFont.lfClipPrecision;
        //    chunk += (int)0; // newFont.fLogFont.lfEscapement;
        //    chunk += (byte)0; // newFont.fLogFont.lfItalic;
        //    chunk += (int)0; // newFont.fLogFont.lfOrientation;
        //    chunk += (byte)0; // newFont.fLogFont.lfOutPrecision;
        //    chunk += (byte)0; // newFont.fLogFont.lfPitchAndFamily;
        //    chunk += (byte)0; // newFont.fLogFont.lfQuality;
        //    chunk += (byte)0; // newFont.fLogFont.lfStrikeOut;
        //    chunk += (byte)0; // newFont.fLogFont.lfUnderline;
        //    chunk += (int)0; // newFont.fLogFont.lfWeight;
        //    chunk += (int)0; // newFont.fLogFont.lfWidth;

        //    // Write the GUID
        //    Pack(chunk, aFont.UniqueID);
        //}
        #endregion

        #region Unpacking routines
        //public static GPen UnpackGPen(BufferChunk chunk)
        //{
        //    uint penColor;
        //    PenStyle penStyle;
        //    Guid uniqueID;
        //    int penSize;

        //    penStyle = (PenStyle)chunk.NextInt32();
        //    penSize = chunk.NextInt32();
        //    penColor = chunk.NextUInt32();
        //    uniqueID = UnpackGuid(chunk);

        //    GPen aPen = new GPen(penColor, PenType.Cosmetic, PenStyle.Solid, PenJoinStyle.Round, PenEndCap.Round, penSize, uniqueID);

        //    return aPen;
        //}

        public static Guid UnpackGuid(BufferChunk chunk)
        {
            int bufferLength = chunk.NextInt32(); // How many bytes did we pack

            byte[] bytes = (byte[])chunk.NextBufferChunk(bufferLength);
            Guid   aGuid = new Guid(bytes);

            return(aGuid);
        }
Example #4
0
File: TMPlan.cs Project: x2v0/TM
        /// <summary>
        ///    Nexts the full spot.
        /// </summary>
        /// <param name="buf">The buf.</param>
        /// <returns>System.Nullable&lt;SpotFull&gt;.</returns>
        public static SpotFull?NextSpotFull(this BufferChunk buf)
        {
            var plan = new SpotFull();

            try {
                plan.changed       = buf.NextInt32();
                plan.done          = buf.NextInt32();
                plan.energy        = buf.NextFloat();
                plan.id            = buf.NextInt32();
                plan.need_to_sent  = buf.NextInt32();
                plan.pcount        = buf.NextFloat();
                plan.result_pcount = buf.NextFloat();
                plan.result_xangle = buf.NextFloat();
                plan.result_zangle = buf.NextFloat();
                plan.xangle        = buf.NextFloat();
                plan.zangle        = buf.NextFloat();
            } catch {
                //plan.id = -1; //
                return(null);
            }

            return(plan);
        }
Example #5
0
File: TMPlan.cs Project: x2v0/TM
        /// <summary>
        ///    Nexts the Spot.
        /// </summary>
        /// <param name="buf">The buffer chunk.</param>
        /// <returns>Spot.</returns>
        public static Spot?NextSpot(this BufferChunk buf)
        {
            var plan = new Spot();

            try {
                plan.id     = buf.NextInt32();
                plan.xangle = buf.NextFloat();
                plan.zangle = buf.NextFloat();
                plan.energy = buf.NextFloat();
                plan.pcount = buf.NextFloat();
            } catch {
                //plan.id = -1; //
                return(null);
            }

            return(plan);
        }
Example #6
0
        override public void Run()
        {
            BufferChunk bc = new BufferChunk(7);
            short s = 25000;
            int i = 545434;
            byte b = 56;

            bc += s;
            bc += i;
            bc += b;

            if (bc.NextInt16() != s)
                throw new TestCaseException("Short failed for " + s);
            if (bc.NextInt32() != i)
                throw new TestCaseException("Int failed for " + i);
            if (bc.NextByte() != b)
                throw new TestCaseException("Byte failed for " + b);

            bc.Reset();

            s = short.MaxValue;
            i = int.MaxValue;
            b = byte.MaxValue;

            bc += s;
            bc += i;
            bc += b;

            if (bc.NextInt16() != s)
                throw new TestCaseException("Short failed for " + s);
            if (bc.NextInt32() != i)
                throw new TestCaseException("Int failed for " + i);
            if (bc.NextByte() != b)
                throw new TestCaseException("Byte failed for " + b);

            bc.Reset();

            s = short.MinValue;
            i = int.MinValue;
            b = byte.MinValue;

            bc += s;
            bc += i;
            bc += b;

            if (bc.NextInt16() != s)
                throw new TestCaseException("Short failed for " + s);
            if (bc.NextInt32() != i)
                throw new TestCaseException("Int failed for " + i);
            if (bc.NextByte() != b)
                throw new TestCaseException("Byte failed for " + b);

        }
Example #7
0
            /// <summary>
            /// Read the next sample at the given timestamp (or within the FUDGE_FACTOR range.)
            /// Return zero if there is no sample available for this timestamp.
            /// </summary>
            /// <param name="bitsPerSample"></param>
            /// <returns></returns>
            public long ReadSample(int bytesPerSample, long timestamp)
            {
                if ((buffer == null) || (buffer.Length < bytesPerSample))
                {
                    if ((buffer != null) && (buffer.Length > 0))
                    {
                        //Debug.WriteLine(".");
                        Debug.WriteLine("Warning: An audio chunk appeared to contain a fractional part of a sample which will be discarded.");
                    }
                    FillBuffer();
                }

                if (exhausted)
                {
                    return(0);
                }

                bool convertToStereo = false;
                bool convertToMono   = false;

                if (currentChannels != targetChannels)
                {
                    if (targetChannels == 2)
                    {
                        convertToStereo = true;
                    }
                    else
                    {
                        convertToMono = true;
                    }
                }

                long sampleAsLong = 0;

                if (Math.Abs(nextTimestamp - timestamp) < FUDGE_FACTOR)
                {
                    nextTimestamp += this.ticksPerSample;
                    if ((convertToStereo) && (sampleCounter % 2 == 1))
                    {
                        sampleAsLong = previousSample;
                    }
                    else
                    {
                        switch (bytesPerSample)
                        {
                        case 1:
                            sampleAsLong = buffer.NextByte();
                            if (convertToMono)
                            {
                                sampleAsLong += buffer.NextByte();
                                sampleAsLong  = sampleAsLong / 2;
                            }
                            break;

                        case 2:
                            sampleAsLong = BitConverter.ToInt16(buffer.Buffer, buffer.Index);
                            //Note that NextInt16, NextInt32 assume the wrong byte order.  We just use them to
                            //update the BufferChunk.Index and Length.
                            buffer.NextInt16();
                            if (convertToMono)
                            {
                                sampleAsLong += BitConverter.ToInt16(buffer.Buffer, buffer.Index);
                                buffer.NextInt16();
                                sampleAsLong = sampleAsLong / 2;
                            }
                            break;

                        case 4:
                            sampleAsLong = BitConverter.ToInt32(buffer.Buffer, buffer.Index);
                            buffer.NextInt32();
                            if (convertToMono)
                            {
                                sampleAsLong += BitConverter.ToInt32(buffer.Buffer, buffer.Index);
                                buffer.NextInt32();
                                sampleAsLong = sampleAsLong / 2;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }

                this.previousSample = sampleAsLong;
                this.sampleCounter++;
                return(sampleAsLong);
            }
Example #8
0
        override public void Run()
        {
            BufferChunk bc = new BufferChunk(7);
            short       s  = 25000;
            int         i  = 545434;
            byte        b  = 56;

            bc += s;
            bc += i;
            bc += b;

            if (bc.NextInt16() != s)
            {
                throw new TestCaseException("Short failed for " + s);
            }
            if (bc.NextInt32() != i)
            {
                throw new TestCaseException("Int failed for " + i);
            }
            if (bc.NextByte() != b)
            {
                throw new TestCaseException("Byte failed for " + b);
            }

            bc.Reset();

            s = short.MaxValue;
            i = int.MaxValue;
            b = byte.MaxValue;

            bc += s;
            bc += i;
            bc += b;

            if (bc.NextInt16() != s)
            {
                throw new TestCaseException("Short failed for " + s);
            }
            if (bc.NextInt32() != i)
            {
                throw new TestCaseException("Int failed for " + i);
            }
            if (bc.NextByte() != b)
            {
                throw new TestCaseException("Byte failed for " + b);
            }

            bc.Reset();

            s = short.MinValue;
            i = int.MinValue;
            b = byte.MinValue;

            bc += s;
            bc += i;
            bc += b;

            if (bc.NextInt16() != s)
            {
                throw new TestCaseException("Short failed for " + s);
            }
            if (bc.NextInt32() != i)
            {
                throw new TestCaseException("Int failed for " + i);
            }
            if (bc.NextByte() != b)
            {
                throw new TestCaseException("Byte failed for " + b);
            }
        }