Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ugocat

 ugocat

pixiv社外公開勉強会「うごイラTeck Talks」のスライドです。

Atsushi Takayama

August 01, 2014
Tweet

More Decks by Atsushi Takayama

Other Decks in Programming

Transcript

  1. node-canvas & ansi.js function catcanvas(ctx, width, height) { var imageData

    = ctx.getImageData(0, 0, width, height); var pixelArray = imageData.data; var cursor = ansi(process.stdout); for (var y = 0; y < height; y+=2) { for (var x = 0; x < width; x++) { var i = (y * width + x) * 4; cursor.bg.rgb( pixelArray[i], pixelArray[i + 1], pixelArray[i + 2] ).write(' '); } cursor.bg.reset(); cursor.write('\n'); } }
  2. Blob & Object URL var buf = new Blob([slice]); var

    url = URL.createObjectURL(buf); var image = new Image(); image.src = url;
  3. ここで奇跡が! // Required for iOS <6, where Blob URLs are

    not available. This is slow... // Source: https://gist.github.com/jonleighton/958841 function base64ArrayBuffer(arrayBuffer, off, byteLength) { var base64 = ''; var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; var bytes = new Uint8Array(arrayBuffer); … url = ("data:" + mime_type + ";base64," + base64ArrayBuffer(this._buf, off, end - off));
  4. DOM EventTarget var EventTarget = {}; EventTarget.prototype = require('event-target'); …

    ZipImagePlayer.prototype = { addEventListener: EventTarget.prototype.addEventListener, removeEventListener: EventTarget.prototype.removeEventListener, dispatchEvent: EventTarget.prototype.dispatchEvent,
  5. 動いた var canvas = new Canvas(width, height); var player =

    new ZipImagePlayer({ canvas: canvas, autosize: false, autoStart: true, chunkSize: 4096, source: data.src, metadata: data, }); player.addEventListener('frame', function(e) { // });
  6. node-canvasに手を入れた NAN_METHOD(Canvas::ToText) { NanScope(); Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args.This()); uint8_t *data

    = canvas->data(); ... caca_canvas_t *cv = caca_create_canvas(0, 0); ... void *text = caca_export_canvas_to_memory(cv, "utf8", &len); caca_free_canvas(cv); ... Local<String> ret = NanNew<String>((char *)text, len); free(text); NanReturnValue(ret); }