Skip to content
Snippets Groups Projects
Select Git revision
  • adc5b559cd2f4e80df0b4cbb94269b495ca3b63d
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

image.ts

Blame
  • user avatar
    Alexander Rose authored
    2e2d65cf
    History
    image.ts 1.04 KiB
    /**
     * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    export { PixelData }
    
    interface PixelData {
        readonly array: Uint8Array
        readonly width: number
        readonly height: number
    }
    
    namespace PixelData {
        export function create(array: Uint8Array, width: number, height: number): PixelData {
            return { array, width, height }
        }
    
        /** horizontally flips the pixel data in-place */
        export function flipY(pixelData: PixelData): PixelData {
            const { array, width, height } = pixelData
            const width4 = width * 4
            for (let i = 0, maxI = height / 2; i < maxI; ++i) {
                for (let j = 0, maxJ = width4; j < maxJ; ++j) {
                    const index1 = i * width4 + j;
                    const index2 = (height - i - 1) * width4 + j;
                    const tmp = array[index1]
                    array[index1] = array[index2]
                    array[index2] = tmp
                }
            }
            return pixelData
        }
    }