Exemplo n.º 1
0
        //[PlugMethod(Signature = "System_Boolean__System_Delegate_InternalEqualTypes_System_Object__System_Object_")]
        public static unsafe bool InternalEqualTypes(uint **a, uint **b)
        {
            var xTypeA = a[0][0];
            var xTypeB = b[0][0];

            return(xTypeA == xTypeB);
        }
Exemplo n.º 2
0
 private static unsafe void EmitCopyLen(size_t copylen, uint **commands)
 {
     if (copylen < 10)
     {
         **commands = (uint)(copylen + 38);
     }
     else if (copylen < 134)
     {
         size_t tail     = copylen - 6;
         size_t nbits    = Log2FloorNonZero(tail) - 1;
         size_t prefix   = tail >> (int)nbits;
         size_t code     = (nbits << 1) + prefix + 44;
         size_t extra    = tail - (prefix << (int)nbits);
         **     commands = (uint)(code | (extra << 8));
     }
     else if (copylen < 2118)
     {
         size_t tail     = copylen - 70;
         size_t nbits    = Log2FloorNonZero(tail);
         size_t code     = nbits + 52;
         size_t extra    = tail - ((size_t)1 << (int)nbits);
         **     commands = (uint)(code | (extra << 8));
     }
     else
     {
         size_t extra    = copylen - 2118;
         **     commands = (uint)(63 | (extra << 8));
     }
     ++(*commands);
 }
Exemplo n.º 3
0
        public unsafe VideoFrameRenderer()
        {
            uint **pointerTable;
            uint * paletteTable;

            // We will allocate memory for 16 palettes of 4 colors each, and for a palette pointer table of 16 pointers
            _renderPaletteMemoryBlock = new MemoryBlock(2 * 8 * sizeof(uint *) + 2 * 8 * 4 * sizeof(uint));

            pointerTable = (uint **)_renderPaletteMemoryBlock.Pointer; // Take 16 uint* at the beginning for pointer table
            paletteTable = (uint *)(pointerTable + 16);                // Take the rest for palette array

            // Fill the pointer table with palette
            for (int i = 0; i < 16; i++)
            {
                pointerTable[i] = paletteTable + 4 * i;        // Each palette is 4 uint wide
            }
            _backgroundPalettes32 = pointerTable;              // First 8 pointers are for the 8 background palettes
            _spritePalettes32     = _backgroundPalettes32 + 8; // Other 8 pointers are for the 8 sprite palettes

            // We'll use the same memory for 16 and 32 bit palettes, because only one will be used at once
            _backgroundPalettes16 = (ushort **)_backgroundPalettes32;
            _spritePalettes16     = _backgroundPalettes16 + 8;

            _backgroundPalette = new uint[4];
            _objectPalette1    = new uint[4];
            _objectPalette2    = new uint[4];
        }
Exemplo n.º 4
0
 public void Destroy()
 {
     if (data != null)
     {
         UnsafeMemory.Free(data);
         data = null;
     }
     if (ffpipe != null)
     {
         ffpipe.Close();
         ffpipe = null;
     }
     if (keyColors != null)
     {
         UnsafeMemory.Free(keyColors);
     }
     if (frame != null)
     {
         UnsafeMemory.Free(frame);
         frame = null;
     }
     if (emptyFrame != null)
     {
         UnsafeMemory.Free(emptyFrame);
         emptyFrame = null;
     }
     //if (renderPush != null)
     //{
     //    renderPush.Wait();
     //}
     keyColors = null;
 }
Exemplo n.º 5
0
        public static unsafe bool InternalEqualTypes([ObjectPointerAccess] uint **a, [ObjectPointerAccess] uint **b)
        {
            var xTypeA = a[0][0];
            var xTypeB = b[0][0];

            return(xTypeA == xTypeB);
        }
Exemplo n.º 6
0
        public bool CreateOperator(byte *ctx, int numInputs, uint **shapes, int *ndims, int *dtypes, CAPI.CustomOpInfo *ret, void *state)
        {
            ret->forward  = GetFunctionPointer(new __Forward(this._opExecutor.Forward));
            ret->backward = GetFunctionPointer(new __Backward(this._opExecutor.Backward));
            ret->del      = GetFunctionPointer(new __Del(this._opExecutor.Del));

            throw new NotImplementedException();
        }
Exemplo n.º 7
0
            private static unsafe void EmitDistance(uint distance, uint **commands)
            {
                uint d        = distance + 3;
                uint nbits    = Log2FloorNonZero(d) - 1;
                uint prefix   = (d >> (int)nbits) & 1;
                uint offset   = (2 + prefix) << (int)nbits;
                uint distcode = 2 * (nbits - 1) + prefix + 80;
                uint extra    = d - offset;

                **commands = distcode | (extra << 8);
                ++(*commands);
            }
Exemplo n.º 8
0
 private static unsafe void EmitCopyLenLastDistance(
     size_t copylen, uint **commands)
 {
     if (copylen < 12)
     {
         **commands = (uint)(copylen + 20);
         ++(*commands);
     }
     else if (copylen < 72)
     {
         size_t tail     = copylen - 8;
         size_t nbits    = Log2FloorNonZero(tail) - 1;
         size_t prefix   = tail >> (int)nbits;
         size_t code     = (nbits << 1) + prefix + 28;
         size_t extra    = tail - (prefix << (int)nbits);
         **     commands = (uint)(code | (extra << 8));
         ++(*commands);
     }
     else if (copylen < 136)
     {
         size_t tail     = copylen - 8;
         size_t code     = (tail >> 5) + 54;
         size_t extra    = tail & 31;
         **     commands = (uint)(code | (extra << 8));
         ++(*commands);
         **commands = 64;
         ++(*commands);
     }
     else if (copylen < 2120)
     {
         size_t tail     = copylen - 72;
         size_t nbits    = Log2FloorNonZero(tail);
         size_t code     = nbits + 52;
         size_t extra    = tail - ((size_t)1 << (int)nbits);
         **     commands = (uint)(code | (extra << 8));
         ++(*commands);
         **commands = 64;
         ++(*commands);
     }
     else
     {
         size_t extra    = copylen - 2120;
         **     commands = (uint)(63 | (extra << 8));
         ++(*commands);
         **commands = 64;
         ++(*commands);
     }
 }
Exemplo n.º 9
0
 private static unsafe void EmitInsertLen(
     uint insertlen, uint **commands)
 {
     if (insertlen < 6)
     {
         **commands = insertlen;
     }
     else if (insertlen < 130)
     {
         uint tail     = insertlen - 2;
         uint nbits    = Log2FloorNonZero(tail) - 1u;
         uint prefix   = tail >> (int)nbits;
         uint inscode  = (nbits << 1) + prefix + 2;
         uint extra    = tail - (prefix << (int)nbits);
         **   commands = inscode | (extra << 8);
     }
     else if (insertlen < 2114)
     {
         uint tail     = insertlen - 66;
         uint nbits    = Log2FloorNonZero(tail);
         uint code     = nbits + 10;
         uint extra    = tail - (1u << (int)nbits);
         **   commands = code | (extra << 8);
     }
     else if (insertlen < 6210)
     {
         uint extra    = insertlen - 2114;
         **   commands = 21 | (extra << 8);
     }
     else if (insertlen < 22594)
     {
         uint extra    = insertlen - 6210;
         **   commands = 22 | (extra << 8);
     }
     else
     {
         uint extra    = insertlen - 22594;
         **   commands = 23 | (extra << 8);
     }
     ++(*commands);
 }
Exemplo n.º 10
0
        protected VMTable(void *Base)
        {
            if (Base != IntPtr.Zero.ToPointer())
            {
                Class_Base = (uint **)Base;
            }

            if (Class_Base == IntPtr.Zero.ToPointer())
            {
                throw new NullReferenceException("Class is NullPtr");
            }

            Old_VMTable = *Class_Base;

            VMTable_Length = VMTLength(Old_VMTable, sizeof(uint));

            if (VMTable_Length == 0)
            {
                throw new ArgumentNullException("VMTable Length is Null");
            }

            New_VMTable = (uint *)Marshal.AllocHGlobal((IntPtr)VMTable_Length);

            Buffer.MemoryCopy(Old_VMTable, New_VMTable, VMTable_Length, VMTable_Length);

            try
            {
                Protect(Class_Base, sizeof(uint));

                *Class_Base = New_VMTable;
            }
            catch
            {
                New_VMTable = (uint *)0;

                throw new AggregateException("Error create VMTable");
            }
        }
Exemplo n.º 11
0
 public static extern int XwcTextListToTextProperty(Display *display, [NativeTypeName("wchar_t **")] uint **list, int count, XICCEncodingStyle style, XTextProperty *text_prop_return);
 public int get_ExtendedSeed([NativeTypeName("ULONG **")] uint **values, [NativeTypeName("ULONG *")] uint *eCount)
 {
     return(((delegate * unmanaged <IStreamPseudoRandomBased *, uint **, uint *, int>)(lpVtbl[17]))((IStreamPseudoRandomBased *)Unsafe.AsPointer(ref this), values, eCount));
 }
Exemplo n.º 13
0
        public Canvas(int width, int height, int keyHeight, int fps, string videoName, int crf = 13, uint lineColor = 0xFF000080, string ffArg = "")
        {
            Width    = width;
            Height   = height;
            keyh     = keyHeight;
            this.fps = fps;
            string ffarg = string.Concat("ffmpeg -y -hide_banner -f rawvideo -pix_fmt rgba -s ", width, "x", height,
                                         " -r ", fps, " -i - -pix_fmt yuv420p -preset ultrafast -crf ", crf, " \"", videoName + "\" ", ffArg);

            ffpipe = CStream.OpenPipe(ffarg, "wb");
            frame  = (uint *)UnsafeMemory.Allocate((ulong)width * (ulong)height * 4);

            UnsafeMemory.Set(frame, 0, (ulong)width * (ulong)height * 4);
            data = (uint **)UnsafeMemory.Allocate((ulong)height * (ulong)sizeof(void *));
            for (uint i = 0; i < height; ++i)
            {
                data[i] = frame + (height - 1 - i) * width;
            }
            for (int i = 0; i != 128; ++i)
            {
                keyx[i] = (i / 12 * 126 + genkeyx[i % 12]) * Width / 1350;
            }
            for (int i = 0; i != 127; ++i)
            {
                keyw[i] = (i % 12) switch
                {
                    1 or 3 or 6 or 8 or 10 => width * 9 / 1350,
                    4 or 11 => keyx[i + 1] - keyx[i],
                    _ => keyx[i + 2] - keyx[i],
                }
            }
            ;
            keyw[127] = width - keyx[127];
            linc      = lineColor;

            for (int i = 0; i != 128; ++i)
            {
                keycolor[i] = (i % 12) switch
                {
                    1 or 3 or 6 or 8 or 10 => 0xFF000000,
                    _ => 0xFFFFFFFF,
                }
            }
            ;
            keyColors = (uint *)UnsafeMemory.Allocate(512);

            fixed(uint *p = keycolor) UnsafeMemory.Copy(keyColors, p, 512);

            emptyFrame = (uint *)UnsafeMemory.Allocate((ulong)width * (ulong)height * 4);
            for (int i = 0; i < Height; ++i)
            {
                for (int j = 0; j < Width; ++j)
                {
                    data[i][j] = 0xFF000000;
                }
            }
            UnsafeMemory.Copy(emptyFrame, frame, (ulong)width * (ulong)height * 4);
            //renderPush = Task.Run(() =>
            //{
            //    while (!destoryed)
            //    {
            //        if (!FrameList.IsEmpty)
            //        {
            //            FrameList.TryDequeue(out IntPtr f);
            //            void* currFrame = f.ToPointer();
            //            ffpipe.Write(currFrame, (ulong)Width * (ulong)Height, 4);
            //            UnsafeMemory.Free(currFrame);
            //        }
            //    }
            //});
        }
Exemplo n.º 14
0
 /// <summary>
 /// Adjusts a pointer to the base of a vertex to point at this element.
 /// </summary>
 /// <param name="base">Pointer to the start of a vertex in this buffer.</param>
 /// <param name="elem">Pointer to a pointer which will be set to the start of this element.</param>
 public void baseVertexPointerToElement(void *basePtr, uint **elem)
 {
     VertexElement_baseVertexPointerToElementUInt(vertexElement, basePtr, elem);
 }
Exemplo n.º 15
0
 private static extern void VertexElement_baseVertexPointerToElementUInt(IntPtr vertexElement, void *basePtr, uint **elem);
Exemplo n.º 16
0
 public static void *GetTypeHandle(uint **obj)
 {
     // Method table is located at the beginning of object (i.e. *obj )
     // Type metadata (TypeDefinition) located at the second of the method table (i.e. *(*obj + 1) )
     return((void *)*(*obj + 1));
 }
Exemplo n.º 17
0
        /// <summary>
        /// The constructor for the burn component.  This call does a lot of work under the covers,
        /// including communicating with imapi to find out whether there is an XP compatible cd drive attached.
        /// </summary>
        unsafe public XPBurnCD()
        {
            IEnumDiscMasterFormats pEnumDiscFormats;
            uint pcFetched;
            Guid guidFormatID;

            fCancel    = false;
            fIsBurning = false;
            uint  cookieValue = (uint)10;
            uint *tempCookie  = &cookieValue;

            fProgressCookie = &tempCookie;

            Debug.WriteLine(@"8/30/2003 6:59p.m. version 1");

            fMessageQueue = new XPBurnMessageQueue(this);

            fMusicDiscWriter     = null;
            fMusicRecorderDrives = new ArrayList();
            fMusicRecorders      = new ArrayList();
            fDataDiscWriter      = null;
            fDataRecorderDrives  = new ArrayList();
            fDataRecorders       = new ArrayList();

            fFiles = new Hashtable();

            try
            {
                fDiscMaster = (IDiscMaster) new MSDiscMasterObj();
            }
            catch (COMException)
            {
                throw new XPBurnException(Resource.NoMAPI);
            }

            fDiscMaster.Open();

            fDiscMaster.ProgressAdvise(new XPBurnProgressEvents(fMessageQueue), fProgressCookie);

            fDiscMaster.EnumDiscMasterFormats(out pEnumDiscFormats);

            pcFetched = 1;
            while (pcFetched == 1)
            {
                pEnumDiscFormats.Next(1, out guidFormatID, out pcFetched);
                if (guidFormatID == GUIDS.IID_IJolietDiscMaster)
                {
                    fSupportedFormats = ((SupportedRecordTypes)((int)fSupportedFormats | 1));
                }
                else
                {
                    if (guidFormatID == GUIDS.IID_IRedbookDiscMaster)
                    {
                        fSupportedFormats = ((SupportedRecordTypes)((int)fSupportedFormats | 2));
                    }
                }
            }

            if (fSupportedFormats == SupportedRecordTypes.sfNone)
            {
                fDiscMaster.Close();
                throw new XPBurnException(Resource.NoSupport);
            }


            EnumerateDiscRecorders();

            fBurnerDrive  = 0;
            fActiveFormat = RecordType.afData;

            SetDrive(fBurnerDrive);
        }
Exemplo n.º 18
0
 internal static extern unsafe int task_threads(int target_task, uint **act_list, out uint act_list_count);
Exemplo n.º 19
0
 public bool InferShape(int numInput, int *ndims, uint **shapes, void *state)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
 public static extern void XwcFreeStringList([NativeTypeName("wchar_t **")] uint **list);
Exemplo n.º 21
0
            private static unsafe void CreateCommands(byte *input,
                                                      size_t block_size, size_t input_size, byte *base_ip, int *table,
                                                      size_t table_bits, byte **literals, uint **commands)
            {
                /* "ip" is the input pointer. */
                byte * ip     = input;
                size_t shift  = 64u - table_bits;
                byte * ip_end = input + block_size;

                /* "next_emit" is a pointer to the first byte that is not covered by a
                 * previous copy. Bytes between "next_emit" and the start of the next copy or
                 * the end of the input will be emitted as literal bytes. */
                byte *next_emit = input;

                int    last_distance     = -1;
                size_t kInputMarginBytes = BROTLI_WINDOW_GAP;
                size_t kMinMatchLen      = 6;

                if ((block_size >= kInputMarginBytes))
                {
                    /* For the last block, we need to keep a 16 bytes margin so that we can be
                     * sure that all distances are at most window size - 16.
                     * For all other blocks, we only need to keep a margin of 5 bytes so that
                     * we don't go over the block size with a copy. */
                    size_t len_limit = Math.Min(block_size - kMinMatchLen,
                                                input_size - kInputMarginBytes);
                    byte *ip_limit = input + len_limit;

                    uint next_hash;
                    for (next_hash = Hash(++ip, shift);;)
                    {
                        /* Step 1: Scan forward in the input looking for a 6-byte-long match.
                         * If we get close to exhausting the input then goto emit_remainder.
                         *
                         * Heuristic match skipping: If 32 bytes are scanned with no matches
                         * found, start looking only at every other byte. If 32 more bytes are
                         * scanned, look at every third byte, etc.. When a match is found,
                         * immediately go back to looking at every byte. This is a small loss
                         * (~5% performance, ~0.1% density) for compressible data due to more
                         * bookkeeping, but for non-compressible data (such as JPEG) it's a huge
                         * win since the compressor quickly "realizes" the data is incompressible
                         * and doesn't bother looking for matches everywhere.
                         *
                         * The "skip" variable keeps track of how many bytes there are since the
                         * last match; dividing it by 32 (ie. right-shifting by five) gives the
                         * number of bytes to move ahead for each iteration. */
                        uint skip = 32;

                        byte *next_ip = ip;
                        byte *candidate;

trawl:
                        do
                        {
                            uint hash = next_hash;
                            uint bytes_between_hash_lookups = skip++ >> 5;
                            ip      = next_ip;
                            next_ip = ip + bytes_between_hash_lookups;
                            if ((next_ip > ip_limit))
                            {
                                goto emit_remainder;
                            }
                            next_hash = Hash(next_ip, shift);
                            candidate = ip - last_distance;
                            if (IsMatch(ip, candidate))
                            {
                                if ((candidate < ip))
                                {
                                    table[hash] = (int)(ip - base_ip);
                                    break;
                                }
                            }
                            candidate = base_ip + table[hash];

                            table[hash] = (int)(ip - base_ip);
                        } while ((!IsMatch(ip, candidate)));

                        /* Check copy distance. If candidate is not feasible, continue search.
                         * Checking is done outside of hot loop to reduce overhead. */
                        if (ip - candidate > MAX_DISTANCE)
                        {
                            goto trawl;
                        }

                        /* Step 2: Emit the found match together with the literal bytes from
                         * "next_emit", and then see if we can find a next match immediately
                         * afterwards. Repeat until we find no match for the input
                         * without emitting some literal bytes. */

                        {
                            /* We have a 6-byte match at ip, and we need to emit bytes in
                             * [next_emit, ip). */
                            byte * base_   = ip;
                            size_t matched = 6 + FindMatchLengthWithLimit(
                                candidate + 6, ip + 6, (size_t)(ip_end - ip) - 6);
                            int distance = (int)(base_ - candidate);  /* > 0 */
                            int insert   = (int)(base_ - next_emit);
                            ip += matched;
                            EmitInsertLen((uint)insert, commands);
                            memcpy(*literals, next_emit, (size_t)insert);
                            *literals += insert;
                            if (distance == last_distance)
                            {
                                **commands = 64;
                                ++(*commands);
                            }
                            else
                            {
                                EmitDistance((uint)distance, commands);
                                last_distance = distance;
                            }
                            EmitCopyLenLastDistance(matched, commands);

                            next_emit = ip;
                            if ((ip >= ip_limit))
                            {
                                goto emit_remainder;
                            }
                            {
                                /* We could immediately start working at ip now, but to improve
                                 * compression we first update "table" with the hashes of some
                                 * positions within the last copy. */
                                ulong input_bytes = *(ulong *)(ip - 5);
                                uint  prev_hash   = HashBytesAtOffset(input_bytes, 0, shift);
                                uint  cur_hash;
                                table[prev_hash] = (int)(ip - base_ip - 5);
                                prev_hash        = HashBytesAtOffset(input_bytes, 1, shift);
                                table[prev_hash] = (int)(ip - base_ip - 4);
                                prev_hash        = HashBytesAtOffset(input_bytes, 2, shift);
                                table[prev_hash] = (int)(ip - base_ip - 3);
                                input_bytes      = *(ulong *)(ip - 2);
                                cur_hash         = HashBytesAtOffset(input_bytes, 2, shift);
                                prev_hash        = HashBytesAtOffset(input_bytes, 0, shift);
                                table[prev_hash] = (int)(ip - base_ip - 2);
                                prev_hash        = HashBytesAtOffset(input_bytes, 1, shift);
                                table[prev_hash] = (int)(ip - base_ip - 1);

                                candidate       = base_ip + table[cur_hash];
                                table[cur_hash] = (int)(ip - base_ip);
                            }
                        }

                        while (ip - candidate <= MAX_DISTANCE && IsMatch(ip, candidate))
                        {
                            /* We have a 6-byte match at ip, and no need to emit any
                             * literal bytes prior to ip. */
                            byte * base_   = ip;
                            size_t matched = 6 + FindMatchLengthWithLimit(
                                candidate + 6, ip + 6, (size_t)(ip_end - ip) - 6);
                            ip           += matched;
                            last_distance = (int)(base_ - candidate);  /* > 0 */
                            EmitCopyLen(matched, commands);
                            EmitDistance((uint)last_distance, commands);

                            next_emit = ip;
                            if ((ip >= ip_limit))
                            {
                                goto emit_remainder;
                            }
                            {
                                /* We could immediately start working at ip now, but to improve
                                 * compression we first update "table" with the hashes of some
                                 * positions within the last copy. */
                                ulong input_bytes = *(ulong *)(ip - 5);
                                uint  prev_hash   = HashBytesAtOffset(input_bytes, 0, shift);
                                uint  cur_hash;
                                table[prev_hash] = (int)(ip - base_ip - 5);
                                prev_hash        = HashBytesAtOffset(input_bytes, 1, shift);
                                table[prev_hash] = (int)(ip - base_ip - 4);
                                prev_hash        = HashBytesAtOffset(input_bytes, 2, shift);
                                table[prev_hash] = (int)(ip - base_ip - 3);
                                input_bytes      = *(ulong *)(ip - 2);
                                cur_hash         = HashBytesAtOffset(input_bytes, 2, shift);
                                prev_hash        = HashBytesAtOffset(input_bytes, 0, shift);
                                table[prev_hash] = (int)(ip - base_ip - 2);
                                prev_hash        = HashBytesAtOffset(input_bytes, 1, shift);
                                table[prev_hash] = (int)(ip - base_ip - 1);

                                candidate       = base_ip + table[cur_hash];
                                table[cur_hash] = (int)(ip - base_ip);
                            }
                        }

                        next_hash = Hash(++ip, shift);
                    }
                }

emit_remainder:
                /* Emit the remaining bytes as literals. */
                if (next_emit < ip_end)
                {
                    uint insert = (uint)(ip_end - next_emit);
                    EmitInsertLen(insert, commands);
                    memcpy(*literals, next_emit, insert);
                    *literals += insert;
                }
            }