3

I am accessing image data on Javascript. Now I'd like to pass this to Python process through Selenium API in the most efficient possible manner.

Passing canvas data is easy with canvas.toDataURL() method, but the downside is that the image is encoded and decoded to PNG, adding substantial overhead to the process.

I was just wondering if I could pass the raw array data from Javascript to Python via Selenium, so that

  • Either passing data in the native format (unsigned integer data)

  • Convert raw pixel data to base64 encoding, in some kind of toDataURL() manner or simply doing the processing yourself in Javascript (hopefully JIT'ed loop)

Looks like canvasContext.getImageData(0, 0, w, h).data object type is Uint8ClampedArray. What would be the best way to convert this data to some format which can be easily passed through Selenium to Python?

Selenium 2.0 RC, any Firefox version can be used.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435

1 Answers1

1

Since your communication between Selenium and the browser through getEval is string based, I think that there is no escape from base64 encoding the image data. sending raw binary data will probably not be possible.

You can probably devise your own string encoding scheme, but it'll probably be as effective as the built in methods.

Variant
  • 17,279
  • 4
  • 40
  • 65
  • Thanks. I thought so. The only gain with custom string encoding scheme would come from the fact that it can work on raw image data and skip PNG encode/decode phase. – Mikko Ohtamaa Jun 29 '11 at 21:38