typed-arrays

Chrome extension: how to pass ArrayBuffer or Blob from content script to the background without losing its type?

断了今生、忘了曾经 提交于 2019-12-17 10:29:24
问题 I have this content script that downloads some binary data using XHR, which is sent later to the background script: var self = this; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = 'arraybuffer'; xhr.onload = function(e) { if (this.status == 200) { self.data = { data: xhr.response, contentType: xhr.getResponseHeader('Content-Type') }; } }; xhr.send(); ... later ... sendResponse({data: self.data}); After receiving this data in background script, I'd like to form

Javascript Typed Arrays and Endianness

吃可爱长大的小学妹 提交于 2019-12-17 04:47:31
问题 I'm using WebGL to render a binary encoded mesh file. The binary file is written out in big-endian format (I can verify this by opening the file in a hex editor, or viewing the network traffic using fiddler). When I try to read the binary response using a Float32Array or Int32Array, the binary is interpreted as little-endian and my values are wrong: // Interpret first 32bits in buffer as an int var wrongValue = new Int32Array(binaryArrayBuffer)[0]; I can't find any references to the default

What does it mean if binary data is “4 byte single format” and how do I read it in JavaScript?

末鹿安然 提交于 2019-12-13 21:36:48
问题 I have to read a binary file which is said to be encoded 4 byte single format and never having to work with binary data, I don't know what this means. I can do this reading a file with binary data in JavaScript: d = new FileReader(); d.onload = function (e) { var i, len; // grab a "chunk" response_buffer = e.target.result.slice(0, 1024); view = new DataView(response_buffer); for (i = 0, len = response_buffer.byteLength; i < len; i += 1) { // hmhm console.log(view.getUint8(i)); } } d

C++ execute function with class from array

99封情书 提交于 2019-12-13 07:01:55
问题 I need to be able to call a function that is a member of a class by looking up the function pointer in an array. This class will have sub classes that do the same thing but call the parent class if they cannot fund the function. To make matters simple, I have cut out most of the code. What remains is shown below. The ultimate test is to create: 1) Mammal : public Animal 1.1) Cat : public Mammal 1.2) Dog : public Mammal 2) Reptile : public Animal 2.1) Bird : public Reptile I want to build this

JavaScript TypedArray mixing types

流过昼夜 提交于 2019-12-13 05:08:39
问题 I'm trying to use WebGL and would like to mix some different types into one buffer of bytes. I understand TypedArrays serve this purpose but it's not clear if I can mix types with them (OpenGL vertex data is often floats mixed with unsigned bytes or integers). In my test I want to pack 2 floats into a UInt8Array using set() , but it appears to just place the 2 floats into the first 2 elements of the UInt8Array . I would expect this to fill the array of course since we have 8 bytes of data. Is

Windows-specific issue when rendering WebGL… attribute set to zero?

旧时模样 提交于 2019-12-13 04:46:49
问题 I'm running into a hard-to-debug issue using WebGL. I was implementing a WebGL backend for the CraftyJS game framework. Everything works absolutely fine on OSX, Linux, and Android, but when a collaborator tested on windows there was an important error -- rotated sprites rendered unrotated! I was able to replicate this across IE, Chrome, and Firefox. An example of the type of vertex program I'm using, which simply renders a colored rectangle: attribute vec2 aPosition; attribute vec3

TypedArray is empty after obtainTypedArray call

人盡茶涼 提交于 2019-12-13 00:27:28
问题 I have a simple google maps implementation, I'm filling two typed arrays with doubles from my strings.xml so I can use them to fill in as longitudes and latitudes. Here is the method: @Override public void onMapReady(GoogleMap map) { map.setMyLocationEnabled(true); TypedArray lats = getResources().obtainTypedArray(R.array.Lats); TypedArray longs = getResources().obtainTypedArray(R.array.Longs); int length = longs.getIndexCount(); Log.e("MY APP LOG", "here"); Log.e("MY APP LOG", "length = " +

Is it possible to convert from 4x Uint8 into Uint32 using typed arrays in JavaScript?

假如想象 提交于 2019-12-12 10:44:34
问题 I'm doing some bitwise manipulation in a project and I wonder if the built-in typed arrays might save me some headache and maybe even give me a bit of a performance gain. let bytes = [128, 129, 130, 131] let uint32 = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3] //=> -2138996093 Can I use typed arrays to get the same answer ? // not actually working ! let uint8bytes = Uint8Array.from(bytes) let uint32 = Uint32Array.from(uint8bytes)[0] //=> ideally i'd get the same value as

Trim or cut audio recorded with mediarecorder JS

有些话、适合烂在心里 提交于 2019-12-12 08:14:43
问题 Requested Knowledge How to shorten (from the front) an array of audio blobs and still have playable audio. Goal I am ultimately trying to record a continuous 45 second loop of audio using the JS MediaRecorder API. The user will be able to push a button and the last 45s of audio will be saved. I can record, playback, and download a single recording just fine. Issue When I have an array called chunks of say 1000 blobs from the MediaRecorder and use chunks.slice(500, 1000) the resulting blob

How to “rotate” the binary data (in horizontal direction) if its size is greater than 32 bits?

佐手、 提交于 2019-12-11 07:18:08
问题 I have the following TypedArray (note that the size of this data is 80 bits): var arr = new Uint8Array([10, 110, 206, 117, 200, 35, 99, 2, 98, 125]); and I want to rotate it by N bits (where N is any integer from 0 to 79). For example, if N=50, I will represent it like this: 00001010 01101110 11001110 01110101 11001000 00100011 01100011 00000010 01100010 01111101 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ so the result should be 01101100 01100000 01001100 01001111 10100001 01001101