コード例 #1
0
        internal PCMStream(FileMap map)
        {
            _sourceMap = map;

            RIFFHeader* header = (RIFFHeader*)_sourceMap.Address;
            _bps = header->_fmtChunk._bitsPerSample;
            _numChannels = header->_fmtChunk._channels;
            _frequency = (int)header->_fmtChunk._samplesSec;
            _numSamples = (int)(header->_dataChunk._chunkSize / header->_fmtChunk._blockAlign);

            _source = (short*)(_sourceMap.Address + header->GetSize());
            _samplePos = 0;
        }
コード例 #2
0
ファイル: ImageExports.cs プロジェクト: RoDaniel/featurehouse
        internal ImageExports(MappedImage mappedImage)
        {
            _mappedImage = mappedImage;
            _dataDirectory = mappedImage.GetDataEntry(ImageDataEntry.Export);
            _exportDirectory = mappedImage.GetExportDirectory();

            if (_exportDirectory != null)
            {
                _addressTable = (int*)mappedImage.RvaToVa(_exportDirectory->AddressOfFunctions);
                _namePointerTable = (int*)mappedImage.RvaToVa(_exportDirectory->AddressOfNames);
                _ordinalTable = (short*)mappedImage.RvaToVa(_exportDirectory->AddressOfNameOrdinals);
            }
        }
コード例 #3
0
        internal PCMStream(WaveInfo* pWAVE, VoidPtr dataAddr)
        {
            _frequency = pWAVE->_sampleRate;
            _numSamples = pWAVE->NumSamples;
            _numChannels = pWAVE->_format._channels;

            _bps = pWAVE->_format._encoding == 0 ? 8 : 16;

            if (_numSamples <= 0) return;

            _loopStart = (int)pWAVE->LoopSample;
            _loopEnd = _numSamples;

            _source = (short*)dataAddr;
            _samplePos = 0;
        }
コード例 #4
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glColor4sv(short *v);
コード例 #5
0
ファイル: EntropyCommon.cs プロジェクト: oleg-st/ZstdSharp
        private static nuint FSE_readNCount_body(short *normalizedCounter, uint *maxSVPtr, uint *tableLogPtr, void *headerBuffer, nuint hbSize)
        {
            byte *istart = (byte *)(headerBuffer);
            byte *iend   = istart + hbSize;
            byte *ip     = istart;
            int   nbBits;
            int   remaining;
            int   threshold;
            uint  bitStream;
            int   bitCount;
            uint  charnum   = 0;
            uint  maxSV1    = *maxSVPtr + 1;
            int   previous0 = 0;

            if (hbSize < 8)
            {
                sbyte *buffer = stackalloc sbyte[8];
                memset(buffer, 0, sizeof(sbyte) * 8);

                memcpy((void *)(buffer), (headerBuffer), (hbSize));

                {
                    nuint countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr, (void *)buffer, (nuint)(8));

                    if ((FSE_isError(countSize)) != 0)
                    {
                        return(countSize);
                    }

                    if (countSize > hbSize)
                    {
                        return(unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)));
                    }

                    return(countSize);
                }
            }

            assert(hbSize >= 8);
            memset((void *)(normalizedCounter), (0), ((*maxSVPtr + 1) * (nuint)(sizeof(short))));
            bitStream = MEM_readLE32((void *)ip);
            nbBits    = (int)((bitStream & 0xF) + 5);
            if (nbBits > 15)
            {
                return(unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_tableLog_tooLarge)));
            }

            bitStream >>= 4;
            bitCount    = 4;
            *tableLogPtr = (uint)nbBits;
            remaining = (1 << nbBits) + 1;
            threshold = 1 << nbBits;
            nbBits++;
            for (;;)
            {
                if (previous0 != 0)
                {
                    int repeats = (int)(FSE_ctz(~bitStream | 0x80000000) >> 1);

                    while (repeats >= 12)
                    {
                        charnum += (uint)(3 * 12);
                        if ((ip <= iend - 7))
                        {
                            ip += 3;
                        }
                        else
                        {
                            bitCount -= (int)(8 * (iend - 7 - ip));
                            bitCount &= 31;
                            ip        = iend - 4;
                        }

                        bitStream = MEM_readLE32((void *)ip) >> bitCount;
                        repeats   = (int)(FSE_ctz(~bitStream | 0x80000000) >> 1);
                    }

                    charnum    += (uint)(3 * repeats);
                    bitStream >>= 2 * repeats;
                    bitCount   += 2 * repeats;
                    assert((bitStream & 3) < 3);
                    charnum  += bitStream & 3;
                    bitCount += 2;
                    if (charnum >= maxSV1)
                    {
                        break;
                    }

                    if ((ip <= iend - 7) || (ip + (bitCount >> 3) <= iend - 4))
                    {
                        assert((bitCount >> 3) <= 3);
                        ip       += bitCount >> 3;
                        bitCount &= 7;
                    }
                    else
                    {
                        bitCount -= (int)(8 * (iend - 4 - ip));
                        bitCount &= 31;
                        ip        = iend - 4;
                    }

                    bitStream = MEM_readLE32((void *)ip) >> bitCount;
                }


                {
                    int max = (2 * threshold - 1) - remaining;
                    int count;

                    if ((bitStream & (uint)((threshold - 1))) < (uint)(max))
                    {
                        count     = (int)(bitStream & (uint)((threshold - 1)));
                        bitCount += nbBits - 1;
                    }
                    else
                    {
                        count = (int)(bitStream & (uint)((2 * threshold - 1)));
                        if (count >= threshold)
                        {
                            count -= max;
                        }

                        bitCount += nbBits;
                    }

                    count--;
                    if (count >= 0)
                    {
                        remaining -= count;
                    }
                    else
                    {
                        assert(count == -1);
                        remaining += count;
                    }

                    normalizedCounter[charnum++] = (short)(count);
                    previous0 = (count == 0 ? 1 : 0);
                    assert(threshold > 1);
                    if (remaining < threshold)
                    {
                        if (remaining <= 1)
                        {
                            break;
                        }

                        nbBits    = (int)(BIT_highbit32((uint)remaining) + 1);
                        threshold = 1 << (nbBits - 1);
                    }

                    if (charnum >= maxSV1)
                    {
                        break;
                    }

                    if ((ip <= iend - 7) || (ip + (bitCount >> 3) <= iend - 4))
                    {
                        ip       += bitCount >> 3;
                        bitCount &= 7;
                    }
                    else
                    {
                        bitCount -= (int)(8 * (iend - 4 - ip));
                        bitCount &= 31;
                        ip        = iend - 4;
                    }

                    bitStream = MEM_readLE32((void *)ip) >> bitCount;
                }
            }

            if (remaining != 1)
            {
                return(unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)));
            }

            if (charnum > maxSV1)
            {
                return(unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxSymbolValue_tooSmall)));
            }

            if (bitCount > 32)
            {
                return(unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)));
            }

            *maxSVPtr = charnum - 1;
            ip += (bitCount + 7) >> 3;
            return((nuint)(ip - istart));
        }
コード例 #6
0
 public static vImageError ConvolveMultiKernelARGB8888(ref vImageBuffer src, 
     ref vImageBuffer dest,
     IntPtr tempBuffer,
     vImagePixelCount srcOffsetToROI_X,
     vImagePixelCount srcOffsetToROI_Y,
     short [][] kernels, 		// must be 4
     uint kernel_height,
     uint kernel_width,
     int [] divisors, 		// must be 4
     int [] biases,		// must be 4
     Pixel8888 backgroundColor,
     vImageFlags flags)
 {
     if (kernels == null)
         throw new ArgumentNullException ("kernels");
     if (divisors == null)
         throw new ArgumentNullException ("divisors");
     if (biases == null)
         throw new ArgumentNullException ("biases");
     if (kernels.Length < 4)
         throw new ArgumentException ("Must contain at least four elements", "kernels");
     if (divisors.Length < 4)
         throw new ArgumentException ("Must contain at least four elements", "divisors");
     if (biases.Length < 4)
         throw new ArgumentException ("Must contain at least four elements", "biases");
     unsafe {
         fixed (short* f1 = kernels [0]) {
             fixed (short* f2 = kernels [1]) {
                 fixed (short* f3 = kernels [2]) {
                     fixed (short* f4 = kernels [3]) {
                         var ptrs = new short* [4];
                         ptrs [0] = f1;
                         ptrs [1] = f2;
                         ptrs [2] = f3;
                         ptrs [3] = f4;
                         return (vImageError) (long) vImageConvolveMultiKernel_ARGB8888 (ref src, ref dest, tempBuffer, srcOffsetToROI_X, srcOffsetToROI_Y, ptrs, kernel_height, kernel_width, divisors, biases, backgroundColor, flags);
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
 public static unsafe Vector128 <short> LoadVector128(short *address) => throw new PlatformNotSupportedException();
コード例 #8
0
ファイル: EntropyCommon.cs プロジェクト: oleg-st/ZstdSharp
 private static nuint FSE_readNCount_body_bmi2(short *normalizedCounter, uint *maxSVPtr, uint *tableLogPtr, void *headerBuffer, nuint hbSize)
 {
     return(FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize));
 }
コード例 #9
0
        static void jpeg_idct_ifast(jpeg_decompress cinfo, jpeg_component_info compptr, short[] coef_block, byte[][] output_buf, uint output_row, uint output_col)
        {
            int[] workspace = new int[DCTSIZE2];                // buffers data between passes

            unsafe
            {
                // Pass 1: process columns from input, store into work array.
                fixed(int *wsptr_ = workspace, quantptr_ = compptr.dct_table)
                {
                    int *wsptr = wsptr_, quantptr = quantptr_;

                    fixed(short *inptr_ = coef_block)
                    {
                        short *inptr = inptr_;

                        for (int ctr = DCTSIZE; ctr > 0; ctr--)
                        {
                            // Due to quantization, we will usually find that many of the input
                            // coefficients are zero, especially the AC terms. We can exploit this
                            // by short-circuiting the IDCT calculation for any column in which all
                            // the AC terms are zero. In that case each output is equal to the
                            // DC coefficient (with scale factor as needed).
                            // With typical images and quantization tables, half or more of the
                            // column DCT calculations can be simplified this way.
                            if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 && inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 4] == 0 &&
                                inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 6] == 0 && inptr[DCTSIZE * 7] == 0)
                            {
                                // AC terms all zero
                                int dcval = inptr[0] * quantptr[0];

                                wsptr[0]           = dcval;
                                wsptr[DCTSIZE * 1] = dcval;
                                wsptr[DCTSIZE * 2] = dcval;
                                wsptr[DCTSIZE * 3] = dcval;
                                wsptr[DCTSIZE * 4] = dcval;
                                wsptr[DCTSIZE * 5] = dcval;
                                wsptr[DCTSIZE * 6] = dcval;
                                wsptr[DCTSIZE * 7] = dcval;

                                inptr++;                                                        // advance pointers to next column
                                quantptr++;
                                wsptr++;

                                continue;
                            }

                            // Even part
                            int tmp0 = inptr[0] * quantptr[0];
                            int tmp1 = inptr[DCTSIZE * 2] * quantptr[DCTSIZE * 2];
                            int tmp2 = inptr[DCTSIZE * 4] * quantptr[DCTSIZE * 4];
                            int tmp3 = inptr[DCTSIZE * 6] * quantptr[DCTSIZE * 6];

                            int tmp10 = tmp0 + tmp2;                            // phase 3
                            int tmp11 = tmp0 - tmp2;

                            int tmp13 = tmp1 + tmp3;                                      // phases 5-3
                            int tmp12 = (((tmp1 - tmp3) * FIX_1_414213562) >> 8) - tmp13; // 2*c4

                            tmp0 = tmp10 + tmp13;                                         // phase 2
                            tmp3 = tmp10 - tmp13;
                            tmp1 = tmp11 + tmp12;
                            tmp2 = tmp11 - tmp12;

                            // Odd part
                            int tmp4 = inptr[DCTSIZE * 1] * quantptr[DCTSIZE * 1];
                            int tmp5 = inptr[DCTSIZE * 3] * quantptr[DCTSIZE * 3];
                            int tmp6 = inptr[DCTSIZE * 5] * quantptr[DCTSIZE * 5];
                            int tmp7 = inptr[DCTSIZE * 7] * quantptr[DCTSIZE * 7];

                            int z13 = tmp6 + tmp5;                                      // phase 6
                            int z10 = tmp6 - tmp5;
                            int z11 = tmp4 + tmp7;
                            int z12 = tmp4 - tmp7;

                            tmp7  = z11 + z13;                                          // phase 5
                            tmp11 = ((z11 - z13) * FIX_1_414213562) >> 8;               // 2*c4

                            int z5 = ((z10 + z12) * FIX_1_847759065) >> 8;              // 2*c2
                            tmp10 = ((z12 * FIX_1_082392200) >> 8) - z5;                // 2*(c2-c6)
                            tmp12 = ((z10 * -FIX_2_613125930) >> 8) + z5;               // -2*(c2+c6)

                            tmp6 = tmp12 - tmp7;                                        // phase 2
                            tmp5 = tmp11 - tmp6;
                            tmp4 = tmp10 + tmp5;

                            wsptr[0]           = tmp0 + tmp7;
                            wsptr[DCTSIZE * 7] = tmp0 - tmp7;
                            wsptr[DCTSIZE * 1] = tmp1 + tmp6;
                            wsptr[DCTSIZE * 6] = tmp1 - tmp6;
                            wsptr[DCTSIZE * 2] = tmp2 + tmp5;
                            wsptr[DCTSIZE * 5] = tmp2 - tmp5;
                            wsptr[DCTSIZE * 4] = tmp3 + tmp4;
                            wsptr[DCTSIZE * 3] = tmp3 - tmp4;

                            inptr++;                                                    // advance pointers to next column
                            quantptr++;
                            wsptr++;
                        }                 // for(...)
                    }                     // fixed(short* inptr_=coef_block)

                    // Pass 2: process rows from work array, store into output array.
                    wsptr = wsptr_;

                    for (int ctr = 0; ctr < DCTSIZE; ctr++)
                    {
                        fixed(byte *outptr = &output_buf[output_row + ctr][output_col])
                        {
                            //byte* outptr=outptr_+output_col;

                            // Rows of zeroes can be exploited in the same way as we did with columns.
                            // However, the column calculation has created many nonzero AC terms, so
                            // the simplification applies less often (typically 5% to 10% of the time).
                            // On machines with very fast multiplication, it's possible that the
                            // test takes more time than it's worth. In that case this section
                            // may be commented out.
#if !NO_ZERO_ROW_TEST
                            if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0)
                            {
                                // AC terms all zero
                                int dc = CENTERJSAMPLE + (wsptr[0] >> 5); byte dcval = (byte)((dc >= MAXJSAMPLE)?MAXJSAMPLE:((dc < 0)?0:dc));

                                outptr[0] = dcval;
                                outptr[1] = dcval;
                                outptr[2] = dcval;
                                outptr[3] = dcval;
                                outptr[4] = dcval;
                                outptr[5] = dcval;
                                outptr[6] = dcval;
                                outptr[7] = dcval;

                                wsptr += DCTSIZE;                                       // advance pointer to next row
                                continue;
                            }
#endif

                            // Even part
                            int tmp10 = wsptr[0] + wsptr[4];
                            int tmp11 = wsptr[0] - wsptr[4];

                            int tmp13 = wsptr[2] + wsptr[6];
                            int tmp12 = (((wsptr[2] - wsptr[6]) * FIX_1_414213562) >> 8) - tmp13;

                            int tmp0 = tmp10 + tmp13;
                            int tmp3 = tmp10 - tmp13;
                            int tmp1 = tmp11 + tmp12;
                            int tmp2 = tmp11 - tmp12;

                            // Odd part
                            int z13 = wsptr[5] + wsptr[3];
                            int z10 = wsptr[5] - wsptr[3];
                            int z11 = wsptr[1] + wsptr[7];
                            int z12 = wsptr[1] - wsptr[7];

                            int tmp7 = z11 + z13;                               // phase 5
                            tmp11 = ((z11 - z13) * FIX_1_414213562) >> 8;       // 2*c4

                            int z5 = ((z10 + z12) * FIX_1_847759065) >> 8;      // 2*c2
                            tmp10 = ((z12 * FIX_1_082392200) >> 8) - z5;        // 2*(c2-c6)
                            tmp12 = ((z10 * -FIX_2_613125930) >> 8) + z5;       // -2*(c2+c6)

                            int tmp6 = tmp12 - tmp7;                            // phase 2
                            int tmp5 = tmp11 - tmp6;
                            int tmp4 = tmp10 + tmp5;

                            // Final output stage: scale down by a factor of 8 and range-limit
                            int x;
                            x = CENTERJSAMPLE + ((tmp0 + tmp7) >> 5); outptr[0] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp0 - tmp7) >> 5); outptr[7] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp1 + tmp6) >> 5); outptr[1] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp1 - tmp6) >> 5); outptr[6] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp2 + tmp5) >> 5); outptr[2] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp2 - tmp5) >> 5); outptr[5] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp3 + tmp4) >> 5); outptr[4] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));
                            x = CENTERJSAMPLE + ((tmp3 - tmp4) >> 5); outptr[3] = (byte)((x >= MAXJSAMPLE)?MAXJSAMPLE:((x < 0)?0:x));

                            wsptr += DCTSIZE; // advance pointer to next row
                        }                     // fixed(byte* outptr=&output_buf[output_row+ctr][output_col])
                    }                         // for(...)
                }                             // fixed(int* wsptr_=workspace, quantptr_=compptr.dct_table)
            }                                 // unsafe
        }
コード例 #10
0
        public unsafe override void DSPCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
        {
            if (base.IsBypassed)
            {
                return;
            }
            if (base.ChannelBitwidth == 16)
            {
                short *ptr = (short *)((void *)buffer);
                for (int i = 0; i < length / 2; i++)
                {
                    this._d = (double)ptr[i] * (1.0 - this._wetDry) + this.ProcessSample((double)ptr[i]) * this._wetDry;
                    if (this._useDithering)
                    {
                        this._d = Utils.SampleDither(this._d, this._ditherFactor, 32768.0);
                    }
                    else
                    {
                        this._d = Math.Round(this._d);
                    }
                    if (this._d > 32767.0)
                    {
                        ptr[i] = short.MaxValue;
                    }
                    else if (this._d < -32768.0)
                    {
                        ptr[i] = short.MinValue;
                    }
                    else
                    {
                        ptr[i] = (short)this._d;
                    }
                }
                return;
            }
            if (base.ChannelBitwidth == 32)
            {
                float *ptr2 = (float *)((void *)buffer);
                for (int j = 0; j < length / 4; j++)
                {
                    ptr2[j] = (float)((double)ptr2[j] * (1.0 - this._wetDry) + this.ProcessSample((double)ptr2[j]) * this._wetDry);
                }
                return;
            }
            byte *ptr3 = (byte *)((void *)buffer);

            for (int k = 0; k < length; k++)
            {
                this._d = (double)((int)(ptr3[k] - 128) * 256);
                this._d = this._d * (1.0 - this._wetDry) + this.ProcessSample(this._d) * this._wetDry;
                if (this._useDithering)
                {
                    this._d = Utils.SampleDither(this._d, this._ditherFactor, 32768.0);
                }
                else
                {
                    this._d = Math.Round(this._d);
                }
                if (this._d > 32767.0)
                {
                    ptr3[k] = byte.MaxValue;
                }
                else if (this._d < -32768.0)
                {
                    ptr3[k] = 0;
                }
                else
                {
                    ptr3[k] = (byte)((int)this._d / 256 + 128);
                }
            }
        }
コード例 #11
0
ファイル: ModbusRTUDriver.cs プロジェクト: ztxyzu/SharpSCADA
        protected override unsafe int Poll()
        {
            short[] cache = (short[])_cacheReader.Cache;
            int     k     = 0;

            foreach (PDUArea area in _rangeList)
            {
                byte[] rcvBytes = _plcReader.ReadBytes(area.Start, (ushort)area.Len);//从PLC读取数据
                if (rcvBytes == null)
                {
                    _plcReader.Connect();
                    return(-1);
                }
                else
                {
                    int len = rcvBytes.Length / 2;
                    fixed(byte *p1 = rcvBytes)
                    {
                        short *prcv  = (short *)p1;
                        int    index = area.StartIndex;//index指向_items中的Tag元数据
                        int    count = index + area.Count;

                        while (index < count)
                        {
                            DeviceAddress addr    = _items[index].Address;
                            int           iShort  = addr.CacheIndex;
                            int           iShort1 = iShort - k;
                            if (addr.VarType == DataType.BOOL)
                            {
                                int           tmp  = prcv[iShort1] ^ cache[iShort];
                                DeviceAddress next = addr;
                                if (tmp != 0)
                                {
                                    while (addr.Start == next.Start)
                                    {
                                        if ((tmp & (1 << next.Bit)) > 0)
                                        {
                                            _changedList.Add(index);
                                        }
                                        if (++index < count)
                                        {
                                            next = _items[index].Address;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    while (addr.Start == next.Start && ++index < count)
                                    {
                                        next = _items[index].Address;
                                    }
                                }
                            }
                            else
                            {
                                if (addr.DataSize <= 2)
                                {
                                    if (prcv[iShort1] != cache[iShort])
                                    {
                                        _changedList.Add(index);
                                    }
                                }
                                else
                                {
                                    int size = addr.DataSize / 2;
                                    for (int i = 0; i < size; i++)
                                    {
                                        if (prcv[iShort1 + i] != cache[iShort + i])
                                        {
                                            _changedList.Add(index);
                                            break;
                                        }
                                    }
                                }
                                index++;
                            }
                        }
                        for (int j = 0; j < len; j++)
                        {
                            cache[j + k] = prcv[j];
                        }//将PLC读取的数据写入到CacheReader中
                    }

                    k += len;
                }
            }
            return(1);
        }
コード例 #12
0
ファイル: Utils.cs プロジェクト: windlex/Jx2U
    public static unsafe Mesh LoadMesh(string filename, Mesh mesh, SkinnedMeshRenderer rend, Transform transform)
    {
        byte[] filedata;
        bool   ret = OpenFile(filename, out filedata);

        if (!ret)
        {
            return(null);
        }

        mesh_head_t head = (mesh_head_t)BytesToStruct(filedata, typeof(mesh_head_t));

        fixed(byte *data = &filedata[0])
        {
            //mesh_head_t *head2 = (mesh_head_t *)data;
        }

        if (head.filemask != 0x4D455348)
        {
            return(null);
        }
        if (head.pos_offset == 0 || head.tex1_offset == 0 || head.index_buffer_offset == 0)
        {
            return(null);
        }

        #region meshinfo
        ////create the original mesh
        int mesh_option = 0;
        //if (!skin_info.d3dsi && (gpu().get_creation_parameters().vertex_processing_method == _gpu_vertex_processing_method_hardware_ || gpu().get_creation_parameters().vertex_processing_method == _gpu_vertex_processing_method_purehardware_))
        //	mesh_option |= D3DXMESH_MANAGED;		//non-skinned && hardware-vp
        //else
        //	mesh_option |= D3DXMESH_SYSTEMMEM;	//skinned or soft-vp

        if (head.vertex_count > 0x0000ffff)
        {
            mesh_option |= D3DXMESH_32BIT;
        }

        //LPD3DXMESH d3dmesh = 0;
        //if (FAILED(D3DXCreateMeshFVF(head.face_count, head.vertex_count, mesh_option, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, gpu().d3ddevice(), &d3dmesh)))
        //{
        //	clear();
        //	return;
        //}

        //head.face_count;
        //head.vertex_count;

        //load data
        //vertex buffer
        Debug.Log(head);
        Debug.LogWarning(string.Format("vertex_count = {0}", head.vertex_count));
        List <Vector3> ves = new List <Vector3>();
        fixed(byte *v = &filedata[head.pos_offset])
        {
            float3 *ff = (float3 *)v;

            for (int i = 0; i < head.vertex_count; i++, ff++)
            {
                //Debug.Log(string.Format("{0},{1},{2}", ff->x, ff->y, ff->z));
                //mesh.vertices[i] = new Vector3(ff->x, ff->y, ff->z);
                ves.Add(new Vector3(ff->x, ff->y, ff->z));
            }
        }

        mesh.SetVertices(ves);

        Debug.LogWarning(string.Format("vertex_count = {0}", head.vertex_count));
        mesh.uv = new Vector2[head.vertex_count];
        List <Vector2> uvs = new List <Vector2>();
        fixed(byte *v = &filedata[head.tex1_offset])
        {
            float3 *ff = (float3 *)v;

            for (int i = 0; i < head.vertex_count; i++, ff++)
            {
                //Debug.Log(string.Format("{0},{1},{2}", ff->x, ff->y, ff->z));
                mesh.uv[i] = new Vector2(ff->x, ff->y);
                uvs.Add(new Vector2(ff->x, 1 - ff->y));
            }
        }

        mesh.SetUVs(0, uvs);

        if (head.normal_offset != 0)
        {
            Debug.LogWarning(string.Format("normal = {0}", head.vertex_count));
            List <Vector3> normal = new List <Vector3>();
            fixed(byte *v = &filedata[head.normal_offset])
            {
                float3 *ff = (float3 *)v;

                for (int i = 0; i < head.vertex_count; i++, ff++)
                {
                    //Debug.Log(string.Format("{0},{1},{2}", ff->x, ff->y, ff->z));
                    normal.Add(new Vector2(ff->x, ff->y));
                }
            }

            mesh.SetNormals(normal);
        }

        //float3* uv = (float3*)((byte*)filedata[head.tex1_offset]);
        //float3* normal = (float3*)(filedata[head.normal_offset]);
        //int bNormal = head.normal_offset == 0 ? 1 : 0;
        //xyz_normal_uv_t* vb_v;
        //d3dmesh.LockVertexBuffer(0, (void**)&vb_v);
        //for (int i = 0; i < head.vertex_count; i++)
        //{
        //	vb_v[i].xyz = v[i];
        //	vb_v[i].uv.x = uv[i].x;
        //	vb_v[i].uv.y = uv[i].y;
        //	if (bNormal == 1)
        //		vb_v[i].normal = normal[i];
        //}
        //d3dmesh.UnlockVertexBuffer();
        //if (!normal)
        //{
        //	D3DXComputeNormals(d3dmesh, 0);
        //}

        // Build basic mesh
        //Mesh mesh = new Mesh();
        //index buffer

        Debug.LogWarning(string.Format("Face Count = {0}", head.face_count));

        int triCount = head.face_count * 3;
        mesh.triangles = new int[triCount];
        int[] trs  = new int[triCount];
        int[] trs2 = new int[triCount];
        fixed(byte *v = &filedata[head.index_buffer_offset])
        {
            short *b2 = (short *)v;
            int *  b4 = (int *)v;

            for (int i = 0; i < triCount; i++, b2++, b4++)
            {
                int t = 0;
                if ((mesh_option & D3DXMESH_32BIT) == 0)
                {
                    t = *b4;
                }
                else
                {
                    t = *b2;
                }
                //Debug.Log(string.Format("{0} {1}",i, t));
                mesh.triangles[i] = t;
                trs[i]            = t;
            }
        }

        for (int i = 0; i < triCount; i++)
        {
            trs2[i] = trs[triCount - i - 1];
        }
        mesh.SetTriangles(trs2, 0, true);

        //void* ib_f;
        //d3dmesh.LockIndexBuffer(0, (void**)&ib_f);
        //if ((mesh_option & D3DXMESH_32BIT) == 0)
        //	memcpy(ib_f, f, head.face_count * 3 * 4);
        //else
        //{
        //	for (int i = 0; i < head.face_count * 3; i++)
        //	{
        //		((byte2*)ib_f)[i] = (byte2)f[i];
        //	}
        //}
        //d3dmesh.UnlockIndexBuffer();
        mesh.RecalculateNormals();              //todo: head.normal_offset
        mesh.RecalculateBounds();
        mesh.RecalculateTangents();

        ////attribute buffer
        //int* ab_ss = 0;
        //d3dmesh.LockAttributeBuffer(0, (int**)&ab_ss);
        //if (!head.attri_buffer_offset)
        //{
        //	memset(ab_ss, 0, head.face_count * 4);
        //}
        //else
        //{
        //	int* ss = (int*)((byte*)filedata.GetBufferPointer() + head.attri_buffer_offset);
        //	memcpy(ab_ss, ss, head.face_count * 4);
        //}
        //d3dmesh.UnlockAttributeBuffer();
        ////end of creating original mesh

        ////generate geo info
        //geo_info = new mesh_geo_info_t;

        ////clear ptrs
        //geo_info.vb = 0;
        //geo_info.ib = 0;
        //geo_info.decl = 0;
        //geo_info.attri_table_buf = 0;

        //if (!skin_info.d3dsi)	//non-skinned
        //{
        //	//optimize & generate the attribute table
        //	int* adj = new int[head.face_count * 3];
        //	d3dmesh.GenerateAdjacency(0, adj);
        //	d3dmesh.OptimizeInplace(D3DXMESHOPT_ATTRSORT, adj, 0, 0, 0);
        //	SAFE_DELETE_ARRAY(adj);

        //	//retrieve datas
        //	d3dmesh.GetVertexBuffer(&geo_info.vb);
        //	geo_info.stride = d3dmesh.GetNumBytesPerVertex();
        //	d3dmesh.GetIndexBuffer(&geo_info.ib);
        //	geo_info.fvf = d3dmesh.GetFVF();
        //	d3dmesh.GetAttributeTable(0, &geo_info.subset_count);
        //	D3DXCreateBuffer(geo_info.subset_count * sizeof(D3DXATTRIBUTERANGE), &geo_info.attri_table_buf);
        //	d3dmesh.GetAttributeTable((D3DXATTRIBUTERANGE*)geo_info.attri_table_buf.GetBufferPointer(), &geo_info.subset_count);
        //	geo_info.palette_count = 0;
        //	geo_info.max_infl_count = 0;
        //}
        //else	//skinned
        //{
        //	//generate adjacency
        //	int* adj = new int[head.face_count * 3];
        //	d3dmesh.GenerateAdjacency(0, adj);

        //	//generate blended mesh
        //	LPD3DXMESH blended_mesh = 0;
        //	//pal count
        //	switch (gpu().get_creation_parameters().vertex_processing_method)
        //	{
        //	case _gpu_vertex_processing_method_software_:
        //	case _gpu_vertex_processing_method_mixed_:
        //		geo_info.palette_count = min((int)skin_info.real_bone_index_vec.size(), (256 - 17) / 3);
        //		break;
        //	default:
        //		geo_info.palette_count = min((int)skin_info.real_bone_index_vec.size(), (gpu().get_hardware_caps().max_vertex_shader_const - 17) / 3);
        //	}


        //	int flags = D3DXMESHOPT_VERTEXCACHE;
        //	switch (gpu().get_creation_parameters().vertex_processing_method)
        //	{
        //	case _gpu_vertex_processing_method_software_:
        //	case _gpu_vertex_processing_method_mixed_:
        //		flags |= D3DXMESH_SYSTEMMEM;	//if the hardware indexed skinning is avaiable, we won't use mixed or software vertex processing method
        //		break;
        //	default:
        //		flags |= D3DXMESH_MANAGED;
        //	}

        //	//convert
        //	if (FAILED(skin_info.d3dsi.ConvertToIndexedBlendedMesh(d3dmesh,
        //		flags,
        //		geo_info.palette_count,
        //		adj,
        //		0, 0, 0,
        //		(int*)&geo_info.max_infl_count,
        //		(int*)&geo_info.subset_count,
        //		&geo_info.attri_table_buf,
        //		&blended_mesh)) ||
        //		geo_info.max_infl_count > 4)
        //	{
        //		SAFE_DELETE_ARRAY(adj);
        //		SAFE_DELETE(geo_info);
        //		SAFE_RELEASE(d3dmesh);
        //		clear();
        //		return;
        //	}

        //	//retrieve datas
        //	blended_mesh.GetVertexBuffer(&geo_info.vb);
        //	geo_info.stride = blended_mesh.GetNumBytesPerVertex();
        //	blended_mesh.GetIndexBuffer(&geo_info.ib);

        //	//fvf
        //	geo_info.fvf = blended_mesh.GetFVF();

        //	//decl will be generated later

        //	SAFE_DELETE_ARRAY(adj);
        //	SAFE_RELEASE(blended_mesh);
        //}
        #endregion


        #region bone
        //skin_info = new mesh_skin_info_t;
        //skin_info.d3dsi = 0;


        // bindPoses was created earlier and was updated with the required matrix.
        // The bindPoses array will now be assigned to the bindposes in the Mesh.


        byte[]       buff = new byte[30];
        Transform[]  bones;
        Matrix4x4[]  bindPoses;
        BoneWeight[] boneweights = new BoneWeight[head.vertex_count];
        Dictionary <string, GameObject> BoneList   = new Dictionary <string, GameObject>();
        Dictionary <string, Matrix4x4>  MatrixList = new Dictionary <string, Matrix4x4>();
        Dictionary <string, int>        PoseList   = new Dictionary <string, int>();

        fixed(byte *ptrb = &filedata[head.skin_info_offset])
        {
            char *ptr       = (char *)ptrb;
            int   bone_size = *(int *)ptr;

            Debug.Log("Bone Size : " + bone_size);
            bones     = new Transform[bone_size];
            bindPoses = new Matrix4x4[bone_size];
            ptr      += 4 / 2;

            for (int i = 0; i < bone_size; i++)
            {
                //bone.name = (char *)ptr;
                //Marshal.Copy(new IntPtr(ptr), buff, 0, 30);
                //string name = Encoding.Default.GetString(buff);
                string name = Marshal.PtrToStringAnsi(new IntPtr(ptr));
                Debug.Log(name);
                ptr += 30 / 2;

                //bone.parent_name = (char *)ptr;
                //Marshal.Copy(new IntPtr(ptr), buff, 0, 30);
                string parent_anme = Marshal.PtrToStringAnsi(new IntPtr(ptr));
                //Debug.Log(parent_anme);
                ptr += 30 / 2;

                int num_child = *(int *)ptr;
                ptr += (4 + num_child * 30) / 2;

                //bone_vec[i].offset_matrix = *(matrix*)ptr;
                //matrix offset_matrix = new matrix();
                //Marshal.Copy(new IntPtr(ptr), offset_matrix, 0, sizeof(matrix));
                matrix    offset_matrix = (matrix)Marshal.PtrToStructure(new IntPtr(ptr), typeof(matrix));
                Matrix4x4 om            = (Matrix4x4)Marshal.PtrToStructure(new IntPtr(ptr), typeof(Matrix4x4));
                //om = om.inverse;
                Debug.Log(om);
                //om = om.inverse;
                if (!om.ValidTRS())
                {
                    Debug.LogError("Not TRS");
                }
                ptr += sizeof(matrix) / 2;

                Matrix4x4 bm = (Matrix4x4)Marshal.PtrToStructure(new IntPtr(ptr), typeof(Matrix4x4));
                //Debug.Log(bm);
                //om = bm;
                ptr += sizeof(matrix) / 2;

                int num_infl = *(int *)ptr;
                ptr += 4 / 2;
                //Debug.Log("num_infl : " + num_infl);

                // weights
                char *ptr1 = ptr;
                char *ptr2 = ptr + num_infl * sizeof(int) / 2;
                for (int w = 0; w < num_infl; w++)
                {
                    //real_bone_index_vec.push_back(i);
                    //skin_info.d3dsi.SetBoneInfluence((int)skin_info.real_bone_index_vec.size() - 1, num_infl, (int*)ptr, (float*)(ptr + 4 * num_infl));
                    int vecIdx = *(int *)ptr1;
                    ptr1 += sizeof(int) / 2;

                    float weight = *(float *)ptr2;
                    ptr2 += sizeof(float) / 2;

                    //Debug.Log(string.Format("{0}, {1}, {2}", w, vecIdx, weight));
                    if (boneweights[vecIdx].weight0 == 0)
                    {
                        boneweights[vecIdx].boneIndex0 = i;
                        boneweights[vecIdx].weight0    = weight;
                    }
                    else if (boneweights[vecIdx].weight1 == 0)
                    {
                        boneweights[vecIdx].boneIndex1 = i;
                        boneweights[vecIdx].weight1    = weight;
                    }
                    else if (boneweights[vecIdx].weight2 == 0)
                    {
                        boneweights[vecIdx].boneIndex2 = i;
                        boneweights[vecIdx].weight2    = weight;
                    }
                    else if (boneweights[vecIdx].weight3 == 0)
                    {
                        boneweights[vecIdx].boneIndex3 = i;
                        boneweights[vecIdx].weight3    = weight;
                    }
                    else
                    {
                        Debug.LogWarning("Bone Weight Count Error!!!");
                    }
                }
                ptr += (num_infl * (sizeof(int) + sizeof(float))) / 2;

                bones[i]        = new GameObject(name).transform;
                bones[i].parent = transform;
                // Set the position relative to the parent
                bones[i].localRotation = Quaternion.identity;                // om.ExtractRotation();//
                bones[i].localPosition = new Vector3(0, 0, 0);               //om.ExtractPosition();//

                //bones[i].localScale = om.ExtractScale();
                BoneList.Add(name, bones[i].gameObject);
                BoneTree.Add(name, parent_anme);
                MatrixList.Add(name, om);
                PoseList.Add(name, i);
                // The bind pose is bone's inverse transformation matrix
                // In this case the matrix we also make this matrix relative to the root
                // So that we can move the root game object around freely
                bindPoses[i] = Matrix4x4.identity;
                //bindPoses[i] = bones[i].worldToLocalMatrix * transform.localToWorldMatrix;
                //bindPoses[i] = om * transform.localToWorldMatrix;
                //bindPoses[i] = om.inverse;
            }
        }

        Debug.LogWarning("----------------------------------------------");
        foreach (var item in BoneTree)
        {
            string     name   = item.Key;
            string     parent = item.Value;
            GameObject go;
            GameObject goParent;
            if (BoneList.TryGetValue(name, out go) && BoneList.TryGetValue(parent, out goParent))
            {
                go.transform.SetParent(goParent.transform);
            }
        }

        List <Transform> childs = new List <Transform>();
        childs.Add(transform);

        while (childs.Count > 0)
        {
            Transform trans = childs[0];
            childs.Remove(trans);
            for (int i = 0; i < trans.childCount; i++)
            {
                childs.Add(trans.GetChild(i));
            }
            string name = trans.name;
            string parent;
            if (!BoneTree.TryGetValue(name, out parent))
            {
                continue;
            }

            Debug.Log(string.Format("2 {0} -> {1}", name, parent));
            GameObject go;
            GameObject goParent;
            if (BoneList.TryGetValue(name, out go))
            {
                Matrix4x4 om = MatrixList[name];
                Debug.Log(om);
                int pose = PoseList[name];

                go.transform.localPosition = om.ExtractPosition();
                go.transform.localRotation = om.ExtractRotation();
                //go.transform.localScale = om.ExtractScale();


                bindPoses[pose] = go.transform.ToMatrix4x4().inverse;
                if (parent != "Scene Root" && BoneList.TryGetValue(parent, out goParent))
                {
                    //Matrix4x4 im = goParent.transform.ToMatrix4x4().inverse;
                    //go.transform.localRotation = (om * im).ExtractRotation();//Quaternion.identity;//
                    //go.transform.localPosition = (om * im).ExtractPosition();//new Vector3(0, 0, 0);//
                    //go.transform.localScale = om.ExtractScale();
                    //bindPoses[pose] = go.transform.worldToLocalMatrix * goParent.transform.localToWorldMatrix;
                }
                else
                {
                    Debug.Log(string.Format("{0} no parent", name));
                    //go.transform.localPosition = om.ExtractPosition();
                    //go.transform.localRotation = om.ExtractRotation();
                    //go.transform.localScale = om.ExtractScale();
                    //bindPoses[pose] = go.transform.worldToLocalMatrix * transform.localToWorldMatrix;
                }
            }
        }

        mesh.boneWeights = boneweights;
        mesh.bindposes   = bindPoses;
        // Assign bones and bind poses
        rend.bones      = bones;
        rend.sharedMesh = mesh;

        ////non-skinned mesh
        //if (!head.skin_info_offset)
        //	return;

        ////skinned mesh
        //byte* ptr = (byte*)filedata.GetBufferPointer() + head.skin_info_offset;

        //skin_info.bone_vec.resize(*(int*)ptr);
        //ptr += 4;

        //if (!skin_info.bone_vec.empty())
        //{
        //	//create d3dx skin info (may be larger than needed)
        //	if (FAILED(D3DXCreateSkinInfoFVF(head.vertex_count, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, (int)skin_info.bone_vec.size(), &skin_info.d3dsi)))
        //	{
        //		SAFE_DELETE(skin_info);
        //		clear();
        //		return;
        //	}
        //}

        //for (int i = 0; i < skin_info.bone_vec.size(); i++)
        //{
        //	strcpy(skin_info.bone_vec[i].name, (char*)ptr);
        //	ptr += 30;

        //	skin_info.bone_vec[i].parent_name = (char*)ptr;
        //	ptr += 30;

        //	int num_child = *(int*)ptr;
        //	ptr += 4 + num_child * 30;

        //	skin_info.bone_vec[i].offset_matrix = *(matrix*)ptr;
        //	ptr += 2 * sizeof(matrix);

        //	int num_infl = *(int*)ptr;
        //	ptr += 4;
        //	if (num_infl > 0)
        //	{
        //		skin_info.real_bone_index_vec.push_back(i);
        //		skin_info.d3dsi.SetBoneInfluence((int)skin_info.real_bone_index_vec.size() - 1, num_infl, (int*)ptr, (float*)(ptr + 4 * num_infl));
        //		ptr += num_infl * (sizeof(int) + sizeof(float));
        //	}
        //}

        //if (skin_info.real_bone_index_vec.empty())
        //{
        //	//non-skinned in fact
        //	SAFE_RELEASE(skin_info.d3dsi);
        //}

        ////compute derived bone members
        ////parent index
        //for (int i = 0; i < skin_info.bone_vec.size(); i++)
        //{
        //	skin_info.bone_vec[i].parent_index = -1;

        //	for (int j = 0; j < skin_info.bone_vec.size(); j++)
        //	{
        //		if (strcmp(skin_info.bone_vec[i].parent_name.c_str(), skin_info.bone_vec[j].name) == 0)
        //		{
        //			skin_info.bone_vec[i].parent_index = j;
        //			skin_info.bone_vec[i].parent_name.clear();
        //			break;
        //		}
        //	}
        //}

        ////soft type
        //for (int i = 0; i < skin_info.bone_vec.size(); i++)
        //{
        //	if (strncmp(skin_info.bone_vec[i].name, "FL_", 3) == 0)
        //		skin_info.bone_vec[i].soft_type = _bone_soft_type_soft_;
        //	else if (strncmp(skin_info.bone_vec[i].name, "GL_", 3) == 0)
        //		skin_info.bone_vec[i].soft_type = _bone_soft_type_gravity_;
        //	else if (strncmp(skin_info.bone_vec[i].name, "AL_", 3) == 0)
        //		skin_info.bone_vec[i].soft_type = _bone_soft_type_adjsoft_;
        //	else
        //		skin_info.bone_vec[i].soft_type = _bone_soft_type_normal_;
        //}

        ////soft level
        //for (int i = 0; i < skin_info.bone_vec.size(); i++)
        //	skin_info.bone_vec[i].soft_level = -1;
        //for (int i = 0; i < skin_info.bone_vec.size(); i++)
        //	_compute_bone_soft_level_recursive(skin_info, i);

        ////inv-offset matrix & relative matrix
        //for (int i = 0; i < skin_info.bone_vec.size(); i++)
        //{
        //	D3DXMatrixInverse(&skin_info.bone_vec[i].inv_offset_matrix, 0, &skin_info.bone_vec[i].offset_matrix);
        //	if (skin_info.bone_vec[i].parent_index != -1)
        //		skin_info.bone_vec[i].relative_matrix = skin_info.bone_vec[i].inv_offset_matrix * skin_info.bone_vec[skin_info.bone_vec[i].parent_index].offset_matrix;
        //	else
        //		skin_info.bone_vec[i].relative_matrix = skin_info.bone_vec[i].inv_offset_matrix;
        //}
        ////end of computing derived bone members

        ////sockets
        //skin_info.socket_vec.resize(*(int*)ptr);
        //ptr += 4;

        //for (int i = 0; i < skin_info.socket_vec.size(); i++)
        //{
        //	strcpy(skin_info.socket_vec[i].name, (char*)ptr);
        //	ptr += 30;

        //	skin_info.socket_vec[i].parent_bone_name = (char*)ptr;
        //	ptr += 30;

        //	skin_info.socket_vec[i].relative_matrix = *(matrix*)ptr;
        //	ptr += sizeof(matrix);
        //}

        ////compute derived socket members
        //for (int i = 0; i < skin_info.socket_vec.size(); i++)
        //{
        //	skin_info.socket_vec[i].parent_bone_index = -1;

        //	for (int j = 0; j < skin_info.bone_vec.size(); j++)
        //	{
        //		if (strcmp(skin_info.socket_vec[i].parent_bone_name.c_str(), skin_info.bone_vec[j].name) == 0)
        //		{
        //			skin_info.socket_vec[i].parent_bone_index = j;
        //			skin_info.socket_vec[i].parent_bone_name.clear();
        //			break;
        //		}
        //	}
        //}

        #endregion

        //SAFE_RELEASE(d3dmesh);
        //SAFE_RELEASE(skin_info.d3dsi);
        //SAFE_RELEASE(filedata);
        return(mesh);
    }
コード例 #13
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glRectsv(short *v1, short *v2);
コード例 #14
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glTexCoord3sv(short *v);
コード例 #15
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glRasterPos4sv(short *v);
コード例 #16
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glNormal3sv(short *v);
コード例 #17
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glIndexsv(short *c);
コード例 #18
0
        /// <summary>
        /// <para>
        /// Find the best (longest) string in the window matching the
        /// string starting at strstart.
        /// </para>
        /// <para>
        /// Preconditions:
        /// <code>
        /// strstart + DeflaterConstants.MAX_MATCH &lt;= window.length.</code>
        /// </para>
        /// </summary>
        /// <param name="curMatch">The current match.</param>
        /// <returns>True if a match greater than the minimum length is found</returns>
        private bool FindLongestMatch(int curMatch)
        {
            int match;
            int scan = this.strstart;

            // scanMax is the highest position that we can look at
            int scanMax = scan + Math.Min(DeflaterConstants.MAX_MATCH, this.lookahead) - 1;
            int limit   = Math.Max(scan - DeflaterConstants.MAX_DIST, 0);

            int chainLength = this.maxChain;
            int niceLength  = Math.Min(this.niceLength, this.lookahead);

            int matchStrt = this.matchStart;

            this.matchLen = Math.Max(this.matchLen, DeflaterConstants.MIN_MATCH - 1);
            int matchLength = this.matchLen;

            if (scan + matchLength > scanMax)
            {
                return(false);
            }

            byte *pinnedWindow = this.pinnedWindowPointer;
            int   scanStart    = this.strstart;
            byte  scanEnd1     = pinnedWindow[scan + matchLength - 1];
            byte  scanEnd      = pinnedWindow[scan + matchLength];

            // Do not waste too much time if we already have a good match:
            if (matchLength >= this.goodLength)
            {
                chainLength >>= 2;
            }

            short *pinnedPrev = this.pinnedPrevPointer;

            do
            {
                match = curMatch;
                scan  = scanStart;

                if (pinnedWindow[match + matchLength] != scanEnd ||
                    pinnedWindow[match + matchLength - 1] != scanEnd1 ||
                    pinnedWindow[match] != pinnedWindow[scan] ||
                    pinnedWindow[++match] != pinnedWindow[++scan])
                {
                    continue;
                }

                // scan is set to strstart+1 and the comparison passed, so
                // scanMax - scan is the maximum number of bytes we can compare.
                // below we compare 8 bytes at a time, so first we compare
                // (scanMax - scan) % 8 bytes, so the remainder is a multiple of 8
                // n & (8 - 1) == n % 8.
                switch ((scanMax - scan) & 7)
                {
                case 1:
                    if (pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;

                case 2:
                    if (pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;

                case 3:
                    if (pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;

                case 4:
                    if (pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;

                case 5:
                    if (pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;

                case 6:
                    if (pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;

                case 7:
                    if (pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match] &&
                        pinnedWindow[++scan] == pinnedWindow[++match])
                    {
                        break;
                    }

                    break;
                }

                if (pinnedWindow[scan] == pinnedWindow[match])
                {
                    // We check for insufficient lookahead only every 8th comparison;
                    // the 256th check will be made at strstart + 258 unless lookahead is
                    // exhausted first.
                    do
                    {
                        if (scan == scanMax)
                        {
                            ++scan; // advance to first position not matched
                            ++match;

                            break;
                        }
                    }while (pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match] &&
                            pinnedWindow[++scan] == pinnedWindow[++match]);
                }

                if (scan - scanStart > matchLength)
                {
                    matchStrt   = curMatch;
                    matchLength = scan - scanStart;

                    if (matchLength >= niceLength)
                    {
                        break;
                    }

                    scanEnd1 = pinnedWindow[scan - 1];
                    scanEnd  = pinnedWindow[scan];
                }
            }while ((curMatch = pinnedPrev[curMatch & DeflaterConstants.WMASK] & 0xFFFF) > limit && --chainLength != 0);

            this.matchStart = matchStrt;
            this.matchLen   = matchLength;
            return(matchLength >= DeflaterConstants.MIN_MATCH);
        }
コード例 #19
0
        /*public static object GetType(ILContext ctx, object instance, object[] param, IType[] genericArguments)
         * {
         *  var t = ctx.AppDomain.GetType((string)param[0]);
         *  if (t != null)
         *      return t.ReflectionType;
         *  else
         *      return null;
         * }*/

        public unsafe static StackObject *InitializeArray(ILIntepreter intp, StackObject *esp, List <object> mStack, CLRMethod method, bool isNewObj)
        {
            var       ret    = esp - 1 - 1;
            AppDomain domain = intp.AppDomain;
            var       param  = esp - 1;

            byte[] data = StackObject.ToObject(param, domain, mStack) as byte[];
            intp.Free(param);
            param = esp - 1 - 1;
            object array = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            if (data == null)
            {
                return(ret);

                fixed(byte *p = data)
                {
                    if (array is int[])
                    {
                        int[] arr = array as int[];
                        int * ptr = (int *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is byte[])
                    {
                        byte[] arr = array as byte[];
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = p[i];
                        }
                    }
                    else if (array is sbyte[])
                    {
                        sbyte[] arr = array as sbyte[];
                        sbyte * ptr = (sbyte *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is short[])
                    {
                        short[] arr = array as short[];
                        short * ptr = (short *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is ushort[])
                    {
                        ushort[] arr = array as ushort[];
                        ushort * ptr = (ushort *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is char[])
                    {
                        char[] arr = array as char[];
                        char * ptr = (char *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is uint[])
                    {
                        uint[] arr = array as uint[];
                        uint * ptr = (uint *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is Int64[])
                    {
                        long[] arr = array as long[];
                        long * ptr = (long *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is UInt64[])
                    {
                        ulong[] arr = array as ulong[];
                        ulong * ptr = (ulong *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is float[])
                    {
                        float[] arr = array as float[];
                        float * ptr = (float *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is double[])
                    {
                        double[] arr = array as double[];
                        double * ptr = (double *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else if (array is bool[])
                    {
                        bool[] arr = array as bool[];
                        bool * ptr = (bool *)p;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            arr[i] = ptr[i];
                        }
                    }
                    else
                    {
                        throw new NotImplementedException("array=" + array.GetType());
                    }
                }

                return(ret);
        }
コード例 #20
0
 public static extern unsafe short th03_get_version(short *version, short port);
コード例 #21
0
        private static unsafe string EncodeObject(ref object data, EventData *dataDescriptor, byte *dataBuffer)

        /*++
         *
         * Routine Description:
         *
         * This routine is used by WriteEvent to unbox the object type and
         * to fill the passed in ETW data descriptor.
         *
         * Arguments:
         *
         * data - argument to be decoded
         *
         * dataDescriptor - pointer to the descriptor to be filled
         *
         * dataBuffer - storage buffer for storing user data, needed because cant get the address of the object
         *
         * Return Value:
         *
         * null if the object is a basic type other than string. String otherwise
         *
         * --*/
        {
            dataDescriptor->Reserved = 0;

            string sRet = data as string;

            if (sRet != null)
            {
                dataDescriptor->Size = (uint)((sRet.Length + 1) * 2);
                return(sRet);
            }

            if (data == null)
            {
                dataDescriptor->Size        = 0;
                dataDescriptor->DataPointer = 0;
            }
            else if (data is IntPtr)
            {
                dataDescriptor->Size = (uint)sizeof(IntPtr);
                IntPtr *intptrPtr = (IntPtr *)dataBuffer;
                *       intptrPtr = (IntPtr)data;
                dataDescriptor->DataPointer = (ulong)intptrPtr;
            }
            else if (data is int)
            {
                dataDescriptor->Size = (uint)sizeof(int);
                int *intptrPtr = (int *)dataBuffer;
                *    intptrPtr = (int)data;
                dataDescriptor->DataPointer = (ulong)intptrPtr;
            }
            else if (data is long)
            {
                dataDescriptor->Size = (uint)sizeof(long);
                long *longptr = (long *)dataBuffer;
                *     longptr = (long)data;
                dataDescriptor->DataPointer = (ulong)longptr;
            }
            else if (data is uint)
            {
                dataDescriptor->Size = (uint)sizeof(uint);
                uint *uintptr = (uint *)dataBuffer;
                *     uintptr = (uint)data;
                dataDescriptor->DataPointer = (ulong)uintptr;
            }
            else if (data is UInt64)
            {
                dataDescriptor->Size = (uint)sizeof(ulong);
                UInt64 *ulongptr = (ulong *)dataBuffer;
                *       ulongptr = (ulong)data;
                dataDescriptor->DataPointer = (ulong)ulongptr;
            }
            else if (data is char)
            {
                dataDescriptor->Size = (uint)sizeof(char);
                char *charptr = (char *)dataBuffer;
                *     charptr = (char)data;
                dataDescriptor->DataPointer = (ulong)charptr;
            }
            else if (data is byte)
            {
                dataDescriptor->Size = (uint)sizeof(byte);
                byte *byteptr = (byte *)dataBuffer;
                *     byteptr = (byte)data;
                dataDescriptor->DataPointer = (ulong)byteptr;
            }
            else if (data is short)
            {
                dataDescriptor->Size = (uint)sizeof(short);
                short *shortptr = (short *)dataBuffer;
                *      shortptr = (short)data;
                dataDescriptor->DataPointer = (ulong)shortptr;
            }
            else if (data is sbyte)
            {
                dataDescriptor->Size = (uint)sizeof(sbyte);
                sbyte *sbyteptr = (sbyte *)dataBuffer;
                *      sbyteptr = (sbyte)data;
                dataDescriptor->DataPointer = (ulong)sbyteptr;
            }
            else if (data is ushort)
            {
                dataDescriptor->Size = (uint)sizeof(ushort);
                ushort *ushortptr = (ushort *)dataBuffer;
                *       ushortptr = (ushort)data;
                dataDescriptor->DataPointer = (ulong)ushortptr;
            }
            else if (data is float)
            {
                dataDescriptor->Size = (uint)sizeof(float);
                float *floatptr = (float *)dataBuffer;
                *      floatptr = (float)data;
                dataDescriptor->DataPointer = (ulong)floatptr;
            }
            else if (data is double)
            {
                dataDescriptor->Size = (uint)sizeof(double);
                double *doubleptr = (double *)dataBuffer;
                *       doubleptr = (double)data;
                dataDescriptor->DataPointer = (ulong)doubleptr;
            }
            else if (data is bool)
            {
                dataDescriptor->Size = (uint)sizeof(bool);
                bool *boolptr = (bool *)dataBuffer;
                *     boolptr = (bool)data;
                dataDescriptor->DataPointer = (ulong)boolptr;
            }
            else if (data is Guid)
            {
                dataDescriptor->Size = (uint)sizeof(Guid);
                Guid *guidptr = (Guid *)dataBuffer;
                *     guidptr = (Guid)data;
                dataDescriptor->DataPointer = (ulong)guidptr;
            }
            else if (data is decimal)
            {
                dataDescriptor->Size = (uint)sizeof(decimal);
                decimal *decimalptr = (decimal *)dataBuffer;
                *        decimalptr = (decimal)data;
                dataDescriptor->DataPointer = (ulong)decimalptr;
            }
            else if (data is Boolean)
            {
                dataDescriptor->Size = (uint)sizeof(Boolean);
                Boolean *booleanptr = (Boolean *)dataBuffer;
                *        booleanptr = (Boolean)data;
                dataDescriptor->DataPointer = (ulong)booleanptr;
            }
            else
            {
                //To our eyes, everything else is a just a string
                sRet = data.ToString();
                dataDescriptor->Size = (uint)((sRet.Length + 1) * 2);
                return(sRet);
            }

            return(null);
        }
コード例 #22
0
 public static extern short TC08GetSingle(short handle,
                                          float[] temp,
                                          short *overflow_flags,
                                          TempUnit units
                                          );
コード例 #23
0
ファイル: detokenize.cs プロジェクト: sipsorcery-org/VP8.Net
        /*
         * Returns the position of the last non-zero coeff plus one
         * (and 0 if there's no coeff at all)
         */
        /* for const-casting */
        //typedef const uint8_t (*ProbaArray)[NUM_CTX] [NUM_PROBAS];
        //static int GetCoeffs(BOOL_DECODER* br, ProbaArray prob, int ctx, int n,
        //             int16_t*out)
        static int GetCoeffs(BOOL_DECODER br, byte *prob, int ctx, int n, short * @out)
        {
            int bigSlice   = NUM_CTX * NUM_PROBAS;
            int smallSlice = NUM_PROBAS;

            //const uint8_t *p = prob[n][ctx];
            byte *p = prob + n * bigSlice + ctx * smallSlice;

            if (VP8GetBit(ref br, p[0]) == 0)
            { /* first EOB is more a 'CBP' bit. */
                return(0);
            }
            while (true)
            {
                ++n;
                if (VP8GetBit(ref br, p[1]) == 0)
                {
                    //p = prob[kBands[n]][0];
                    p = prob + kBands[n] * bigSlice;
                }
                else
                { /* non zero coeff */
                    int v, j;
                    if (VP8GetBit(ref br, p[2]) == 0)
                    {
                        //p = prob[kBands[n]][1];
                        p = prob + kBands[n] * bigSlice + smallSlice;
                        v = 1;
                    }
                    else
                    {
                        if (VP8GetBit(ref br, p[3]) == 0)
                        {
                            if (VP8GetBit(ref br, p[4]) == 0)
                            {
                                v = 2;
                            }
                            else
                            {
                                v = 3 + VP8GetBit(ref br, p[5]);
                            }
                        }
                        else
                        {
                            if (VP8GetBit(ref br, p[6]) == 0)
                            {
                                if (VP8GetBit(ref br, p[7]) == 0)
                                {
                                    v = 5 + VP8GetBit(ref br, 159);
                                }
                                else
                                {
                                    v  = 7 + 2 * VP8GetBit(ref br, 165);
                                    v += VP8GetBit(ref br, 145);
                                }
                            }
                            else
                            {
                                byte *tab;
                                int   bit1 = VP8GetBit(ref br, p[8]);
                                int   bit0 = VP8GetBit(ref br, p[9 + bit1]);
                                int   cat  = 2 * bit1 + bit0;
                                v = 0;
                                fixed(byte *ptab = kCat3456[cat])
                                {
                                    for (tab = ptab; *tab > 0; ++tab)
                                    {
                                        v += v + VP8GetBit(ref br, *tab);
                                    }
                                }

                                v += 3 + (8 << cat);
                            }
                        }
                        //p = prob[kBands[n]][2];
                        p = prob + kBands[n] * bigSlice + 2 * smallSlice;
                    }
                    j = kZigzag[n - 1];

                    @out[j] = (short)GetSigned(br, v);

                    if (n == 16 || VP8GetBit(ref br, p[0]) == 0)
                    { /* EOB */
                        return(n);
                    }
                }
                if (n == 16)
                {
                    return(16);
                }
            }
        }
コード例 #24
0
 public static void Swap(short *p1, short *p2)
 {
     short f = *p1; *p1 = *p2; *p2 = f;
 }
コード例 #25
0
ファイル: detokenize.cs プロジェクト: sipsorcery-org/VP8.Net
        public static int vp8_decode_mb_tokens(VP8D_COMP dx, MACROBLOCKD x)
        {
            BOOL_DECODER  bc = x.current_bc;
            FRAME_CONTEXT fc = dx.common.fc;

            //char* eobs = x->eobs;
            sbyte[] eobs = x.eobs;

            int i;
            int nonzeros;
            int eobtotal = 0;

            //short* qcoeff_ptr;
            //ProbaArray coef_probs;
            //int coefIndex = entropy.COEF_BANDS * entropy.PREV_COEF_CONTEXTS * entropy.ENTROPY_NODES;
            //ENTROPY_CONTEXT* a_ctx = ((ENTROPY_CONTEXT*)x->above_context);
            //ENTROPY_CONTEXT* l_ctx = ((ENTROPY_CONTEXT*)x->left_context);
            //ENTROPY_CONTEXT* a;
            //ENTROPY_CONTEXT* l;

            int blockSlice = entropy.COEF_BANDS * entropy.PREV_COEF_CONTEXTS * entropy.ENTROPY_NODES;

            fixed(byte *pCoefProbs = fc.coef_probs)
            {
                byte *coef_probs = null;

                fixed(sbyte *pAboveCtx = x.above_context.get().y1, pLeftContext = x.left_context.y1)
                {
                    ENTROPY_CONTEXT *a_ctx = pAboveCtx;
                    ENTROPY_CONTEXT *l_ctx = pLeftContext;
                    ENTROPY_CONTEXT *a;
                    ENTROPY_CONTEXT *l;

                    int skip_dc = 0;

                    //qcoeff_ptr = x.qcoeff[0];
                    fixed(short *pQcoeff = x.qcoeff)
                    {
                        short *qcoeff_ptr = pQcoeff;

                        if (x.mode_info_context.get().mbmi.is_4x4 == 0)
                        {
                            a = a_ctx + 8;
                            l = l_ctx + 8;

                            //coef_probs = fc.coef_probs[1];
                            coef_probs = pCoefProbs + blockSlice;

                            nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr + 24 * 16);
                            *a = *l = (sbyte)(nonzeros > 0 ? 1 : 0);

                            eobs[24]  = (sbyte)nonzeros;
                            eobtotal += nonzeros - 16;

                            //coef_probs = fc.coef_probs[0];
                            coef_probs = pCoefProbs;

                            skip_dc = 1;
                        }
                        else
                        {
                            //coef_probs = fc.coef_probs[3];
                            coef_probs = pCoefProbs + 3 * blockSlice;

                            skip_dc = 0;
                        }

                        for (i = 0; i < 16; ++i)
                        {
                            a = a_ctx + (i & 3);
                            l = l_ctx + ((i & 0xc) >> 2);

                            nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), skip_dc, qcoeff_ptr);
                            *a = *l = (sbyte)(nonzeros > 0 ? 1 : 0);

                            nonzeros   += skip_dc;
                            eobs[i]     = (sbyte)nonzeros;
                            eobtotal   += nonzeros;
                            qcoeff_ptr += 16;
                        }

                        //coef_probs = fc.coef_probs[2];
                        coef_probs = pCoefProbs + 2 * blockSlice;

                        a_ctx += 4;
                        l_ctx += 4;
                        for (i = 16; i < 24; ++i)
                        {
                            a = a_ctx + ((i > 19 ? 1 : 0) << 1) + (i & 1);
                            l = l_ctx + ((i > 19 ? 1 : 0) << 1) + ((i & 3) > 1 ? 1 : 0);

                            nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr);
                            *a = *l = (sbyte)(nonzeros > 0 ? 1 : 0);

                            eobs[i]     = (sbyte)nonzeros;
                            eobtotal   += nonzeros;
                            qcoeff_ptr += 16;
                        }
                    }
                }
            }

            return(eobtotal);
        }
コード例 #26
0
 public int get_IsHidden([NativeTypeName("VARIANT_BOOL *")] short *pVal)
 {
     return(((delegate * unmanaged <IFsiDirectoryItem2 *, short *, int>)(lpVtbl[15]))((IFsiDirectoryItem2 *)Unsafe.AsPointer(ref this), pVal));
 }
コード例 #27
0
 public static void VertexAttribI4sv(uint index, short *v)
 {
     glVertexAttribI4sv(index, (IntPtr)v);
 }
コード例 #28
0
ファイル: EntropyCommon.cs プロジェクト: oleg-st/ZstdSharp
 /*! FSE_readNCount():
  *  Read compactly saved 'normalizedCounter' from 'rBuffer'.
  *  @return : size read from 'rBuffer',
  *            or an errorCode, which can be tested using FSE_isError().
  *            maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */
 public static nuint FSE_readNCount(short *normalizedCounter, uint *maxSVPtr, uint *tableLogPtr, void *headerBuffer, nuint hbSize)
 {
     return(FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize, 0));
 }
コード例 #29
0
ファイル: Normalization.cs プロジェクト: runefs/Marvin
		public static readonly bool IsReady = true; // always

		static Normalization ()
		{
			fixed (byte* tmp = propsArr) {
				props = tmp;
			}
			fixed (int* tmp = mappedCharsArr) {
				mappedChars = tmp;
			}
			fixed (short* tmp = charMapIndexArr) {
				charMapIndex = tmp;
			}
			fixed (short* tmp = helperIndexArr) {
				helperIndex = tmp;
			}
			fixed (ushort* tmp = mapIdxToCompositeArr) {
				mapIdxToComposite = tmp;
			}
			fixed (byte* tmp = combiningClassArr) {
				combiningClass = tmp;
			}
		}
コード例 #30
0
		/// <summary>
		/// Creates a new CudaRegisteredHostMemory_short from an existing IntPtr. IntPtr must be page size aligned (4KBytes)!
		/// </summary>
		/// <param name="hostPointer">must be page size aligned (4KBytes)</param>
		/// <param name="size">In elements</param>
		public CudaRegisteredHostMemory_short(IntPtr hostPointer, SizeT size)
		{
			_intPtr = hostPointer;
			_size = size;
			_typeSize = (SizeT)Marshal.SizeOf(typeof(short));
			_ptr = (short*)_intPtr;
		}
コード例 #31
0
        /// <summary>
        /// Generic convertor SHORT
        /// </summary>
        public static void ConvertorFloatToShortGeneric(IntPtr inputInterleavedBuffer, IntPtr[] asioOutputBuffers, int nbChannels, int nbSamples)
        {
            unsafe
            {
                float* inputSamples = (float*)inputInterleavedBuffer;
                // Use a trick (short instead of int to avoid any convertion from 16Bit to 32Bit)
                short*[] samples = new short*[nbChannels];
                for (int i = 0; i < nbChannels; i++)
                {
                    samples[i] = (short*)asioOutputBuffers[i];
                }

                for (int i = 0; i < nbSamples; i++)
                {
                    for (int j = 0; j < nbChannels; j++)
                    {
                        *(samples[i]++) = clampToShort(*inputSamples++);
                    }
                }
            }
        }
コード例 #32
0
            private static unsafe uint SearchLZFast(
                MKDS_Course_Modifier.Converters.Compression.MI_Compress.LZCompressInfo *info,
                byte *nextp,
                uint remainSize,
                ushort *offset,
                uint maxLength)
            {
                ushort num1          = 0;
                uint   num2          = 2;
                short *lzOffsetTable = info->LZOffsetTable;
                ushort windowPos     = info->windowPos;
                ushort windowLen     = info->windowLen;

                if (remainSize < 3U)
                {
                    return(0);
                }
                int index = (int)info->LZByteTable[*nextp];

                while (index != -1)
                {
                    byte *numPtr1 = index >= (int)windowPos ? nextp - (int)windowLen - (int)windowPos + index : nextp - (int)windowPos + index;
                    if ((int)numPtr1[1] != (int)nextp[1] || (int)numPtr1[2] != (int)nextp[2])
                    {
                        index = (int)lzOffsetTable[index];
                    }
                    else if (nextp - numPtr1 >= 2L)
                    {
                        uint  num3    = 3;
                        byte *numPtr2 = numPtr1 + 3;
                        byte *numPtr3 = nextp + 3;
                        while ((uint)(numPtr3 - nextp) < remainSize && (int)*numPtr3 == (int)*numPtr2)
                        {
                            ++numPtr3;
                            ++numPtr2;
                            ++num3;
                            if ((int)num3 == (int)maxLength)
                            {
                                break;
                            }
                        }
                        if (num3 > num2)
                        {
                            num2 = num3;
                            num1 = (ushort)(nextp - numPtr1);
                            if ((int)num2 == (int)maxLength || (int)num2 == (int)remainSize)
                            {
                                break;
                            }
                        }
                        index = (int)lzOffsetTable[index];
                    }
                    else
                    {
                        break;
                    }
                }
                if (num2 < 3U)
                {
                    return(0);
                }
                *offset = num1;
                return(num2);
            }
コード例 #33
0
ファイル: wGL.cs プロジェクト: soopercool101/brawltools1
 public static extern void glVertex4sv(short *v);
コード例 #34
0
 unsafe private static extern short dpGetDriverType(short *type);
コード例 #35
0
 unsafe private static extern short dpGetDriverGangSupport(short *pdwDriverGangSupport);
コード例 #36
0
ファイル: Normalization.cs プロジェクト: runefs/Marvin
		static Normalization ()
		{
			IntPtr p1, p2, p3, p4, p5, p6;
			lock (forLock) {
				load_normalization_resource (out p1, out p2, out p3, out p4, out p5, out p6);
				props = (byte*) p1;
				mappedChars = (int*) p2;
				charMapIndex = (short*) p3;
				helperIndex = (short*) p4;
				mapIdxToComposite = (ushort*) p5;
				combiningClass = (byte*) p6;
			}

			isReady = true;
		}
コード例 #37
0
 unsafe private static extern int dpGetNumHwDevices(short *num);
コード例 #38
0
        /// <summary>
        /// Generic convertor for SHORT
        /// </summary>
        public static void ConvertorShortToIntGeneric(IntPtr inputInterleavedBuffer, IntPtr[] asioOutputBuffers, int nbChannels, int nbSamples)
        {
            unsafe
            {
                short* inputSamples = (short*)inputInterleavedBuffer;
                // Use a trick (short instead of int to avoid any convertion from 16Bit to 32Bit)
                short*[] samples = new short*[nbChannels];
                for (int i = 0; i < nbChannels; i++)
                {
                    samples[i] = (short*)asioOutputBuffers[i];
                    // Point to upper 16 bits of the 32Bits.
                    samples[i]++;
                }

                for (int i = 0; i < nbSamples; i++)
                {
                    for (int j = 0; j < nbChannels; j++)
                    {
                        *samples[i] = *inputSamples++;
                        samples[i] += 2;
                    }
                }
            }
        }
コード例 #39
0
ファイル: SpanImageFilterRGB.cs プロジェクト: djlw78/Mosa
        //--------------------------------------------------------------------
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            ISpanInterpolator spanInterpolator = base.interpolator();

            spanInterpolator.Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

            int *fg = stackalloc int[3];

            byte *fg_ptr;

            fixed(short *pWeightArray = filter().weight_array())
            {
                int diameter     = (int)base.filter().diameter();
                int filter_scale = diameter << (int)image_subpixel_scale_e.Shift;

                short *weight_array = pWeightArray;

                do
                {
                    int rx;
                    int ry;
                    int rx_inv = (int)image_subpixel_scale_e.Scale;
                    int ry_inv = (int)image_subpixel_scale_e.Scale;
                    spanInterpolator.Coordinates(out x, out y);
                    spanInterpolator.LocalScale(out rx, out ry);
                    base.AdjustScale(ref rx, ref ry);

                    rx_inv = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / rx;
                    ry_inv = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / ry;

                    int radius_x = (diameter * rx) >> 1;
                    int radius_y = (diameter * ry) >> 1;
                    int len_x_lr =
                        (diameter * rx + (int)image_subpixel_scale_e.Mask) >>
                        (int)(int)image_subpixel_scale_e.Shift;

                    x += base.filter_dx_int() - radius_x;
                    y += base.filter_dy_int() - radius_y;

                    fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2;

                    int y_lr = y >> (int)(int)image_subpixel_scale_e.Shift;
                    int y_hr = (((int)image_subpixel_scale_e.Mask - (y & (int)image_subpixel_scale_e.Mask)) *
                                ry_inv) >>
                               (int)(int)image_subpixel_scale_e.Shift;
                    int total_weight = 0;
                    int x_lr         = x >> (int)(int)image_subpixel_scale_e.Shift;
                    int x_hr         = (((int)image_subpixel_scale_e.Mask - (x & (int)image_subpixel_scale_e.Mask)) *
                                        rx_inv) >>
                                       (int)(int)image_subpixel_scale_e.Shift;
                    int x_hr2 = x_hr;
                    fg_ptr = base.source().Span(x_lr, y_lr, (uint)len_x_lr);

                    for (;;)
                    {
                        int weight_y = weight_array[y_hr];
                        x_hr = x_hr2;
                        for (;;)
                        {
                            int weight = (weight_y * weight_array[x_hr] +
                                          (int)image_filter_scale_e.Scale / 2) >>
                                         downscale_shift;
                            fg[0]        += *fg_ptr++ *weight;
                            fg[1]        += *fg_ptr++ *weight;
                            fg[2]        += *fg_ptr++ *weight;
                            total_weight += weight;
                            x_hr         += rx_inv;
                            if (x_hr >= filter_scale)
                            {
                                break;
                            }
                            fg_ptr = base.source().NextX();
                        }
                        y_hr += ry_inv;
                        if (y_hr >= filter_scale)
                        {
                            break;
                        }

                        fg_ptr = base.source().NextY();
                    }

                    fg[0] /= total_weight;
                    fg[1] /= total_weight;
                    fg[2] /= total_weight;

                    if (fg[0] < 0)
                    {
                        fg[0] = 0;
                    }
                    if (fg[1] < 0)
                    {
                        fg[1] = 0;
                    }
                    if (fg[2] < 0)
                    {
                        fg[2] = 0;
                    }

                    if (fg[0] > fg[0])
                    {
                        fg[0] = fg[0];
                    }
                    if (fg[1] > fg[1])
                    {
                        fg[1] = fg[1];
                    }
                    if (fg[2] > fg[2])
                    {
                        fg[2] = fg[2];
                    }

                    span->R_Byte = (byte)fg[OrderR];
                    span->G_Byte = (byte)fg[OrderG];
                    span->B_Byte = (byte)fg[OrderB];
                    span->A_Byte = (byte)base_mask;

                    ++span;
                    interpolator().Next();
                } while(--len != 0);
            }
        }