MCPcopy Index your code
hub / github.com/processing/p5.js / _flipPixels

Function _flipPixels

src/image/loading_displaying.js:527–553  ·  view source on GitHub ↗
(pixels, width, height)

Source from the content-addressed store, hash-verified

525 };
526
527 function _flipPixels(pixels, width, height) {
528 // extracting the pixels using readPixels returns
529 // an upside down image. we have to flip it back
530 // first. this solution is proposed by gman on
531 // this stack overflow answer:
532 // https://stackoverflow.com/questions/41969562/how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
533
534 const halfHeight = parseInt(height / 2);
535 const bytesPerRow = width * 4;
536
537 // make a temp buffer to hold one row
538 const temp = new Uint8Array(width * 4);
539 for (let y = 0; y < halfHeight; ++y) {
540 const topOffset = y * bytesPerRow;
541 const bottomOffset = (height - y - 1) * bytesPerRow;
542
543 // make copy of a row on the top half
544 temp.set(pixels.subarray(topOffset, topOffset + bytesPerRow));
545
546 // copy a row from the bottom half to the top
547 pixels.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
548
549 // copy the copy of the top half row to the bottom half
550 pixels.set(temp, bottomOffset);
551 }
552 return pixels;
553 }
554
555 function _generateGlobalPalette(frames) {
556 // make an array the size of every possible color in every possible frame

Callers 1

loadingDisplayingFunction · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected