<commit_before>//
// Copyright (c) 2011-2014 <NAME> <<EMAIL>>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use ooc-draw-gpu
use ooc-opengl
use ooc-draw
use ooc-math
import GpuPacker, GpuMapAndroid, GpuPackerBin, EglRgba
AndroidContext: class extends OpenGLES3Context {
	_packMonochrome: OpenGLES3MapPackMonochrome
	_packUv: OpenGLES3MapPackUv
	_packerBin: GpuPackerBin
	init: func {
		super()
		this _packMonochrome = OpenGLES3MapPackMonochrome new()
		this _packUv = OpenGLES3MapPackUv new()
		this _packerBin = GpuPackerBin new()
	}
	toRaster: func (gpuImage: GpuImage) -> RasterImage {
		result := null
		if(gpuImage instanceOf?(GpuYuv420Semiplanar)) {
			raster := RasterYuv420Semiplanar new(gpuImage size)
			semiPlanar := gpuImage as GpuYuv420Semiplanar
			yPacker := createPacker(semiPlanar y size, 1)
			yPacker pack(semiPlanar y, this _packMonochrome, raster y)
			yPacker recycle()
			uvPacker := createPacker(semiPlanar uv size, 2)
			uvPacker pack(semiPlanar uv, this _packUv, raster uv)
			uvPacker recycle()
			result = raster
		}
		result
	}
	recycle: func ~GpuPacker (packer: GpuPacker) {
		this _packerBin add(packer)
	}
	createPacker: func (size: IntSize2D, bytesPerPixel: UInt) -> GpuPacker {
		result := this _packerBin find(size, bytesPerPixel)
		if (result == null) {
			//result = GpuPacker new(size, bytesPerPixel, this)
		}
		result
	}
	createEglRgba: func (size: IntSize2D) -> EglRgba {
		EglRgba new(this _backend _eglDisplay, size)
	}
}

AndroidContextManager: class extends GpuContextManager {
	init: func {
		setShaderSources()
	}
	_createContext: func -> GpuContext {
		AndroidContext new()
	}
	/*
	copyPixels: func ~Monochrome (image: GpuMonochrome, destination: RasterMonochrome) {
		this _scaledPacker pack(image)
		yPixels := this _scaledPacker lock()
		memcpy(destination pointer, yPixels, 768 * 480)
		this _scaledPacker unlock()
	}
	copyPixels: func ~Yuv420Semiplanar(image: GpuYuv420Semiplanar, destination: RasterYuv420Semiplanar) {
		this _yPacker pack(image y)
		yPixels := this _yPacker lock()
		destinationPointer := destination y pointer
		destinationStride := destination y stride
		paddedBytes := 640 + 1920 - image size width;
		for(row in 0..image size height) {
			sourceRow := yPixels + row * (image size width + paddedBytes)
			destinationRow := destinationPointer + row * destinationStride
			memcpy(destinationRow, sourceRow, image size width)
		}
		this _yPacker unlock()

		this _uvPacker pack(image uv)
		uvPixels := this _uvPacker lock()
		uvOffset := destination y stride * destination y size height + (Int align(destination y size height, destination byteAlignment height) - destination y size height) * destination y stride
		uvDestination := destinationPointer + uvOffset
		for(row in 0..image size height / 2) {
			sourceRow := uvPixels + row * (image size width + paddedBytes)
			destinationRow := uvDestination + row * destinationStride
			memcpy(destinationRow, sourceRow, image size width)
		}
		this _uvPacker unlock()
	}
	*/
}<commit_msg>Implemented toRaster for Android  contexts<commit_after>//
// Copyright (c) 2011-2014 <NAME> <<EMAIL>>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use ooc-android-debug
use ooc-draw-gpu
use ooc-opengl
use ooc-draw
use ooc-math
import GpuPacker, GpuMapAndroid, GpuPackerBin, EglRgba
AndroidContext: class extends OpenGLES3Context {
	_packMonochrome: OpenGLES3MapPackMonochrome
	_packUv: OpenGLES3MapPackUv
	_packerBin: GpuPackerBin
	init: func {
		super()
		this _packMonochrome = OpenGLES3MapPackMonochrome new()
		this _packUv = OpenGLES3MapPackUv new()
		this _packerBin = GpuPackerBin new()
	}
	toRaster: func ~overwrite (gpuImage: GpuImage, rasterImage: RasterImage) {
		if(gpuImage instanceOf?(GpuYuv420Semiplanar)) {
			printAndroid("Packing YUV420")
			rasterYuv420Semiplanar := rasterImage as RasterYuv420Semiplanar
			semiPlanar := gpuImage as GpuYuv420Semiplanar
			yPacker := createPacker(semiPlanar y size, 1)
			//yPacker pack(semiPlanar y, this _packMonochrome, rasterYuv420Semiplanar y)
			yPacker recycle()
			uvPacker := createPacker(semiPlanar uv size, 2)
			//uvPacker pack(semiPlanar uv, this _packUv, rasterYuv420Semiplanar uv)
			uvPacker recycle()
		}
	}
	toRaster: func (gpuImage: GpuImage) -> RasterImage {
		result := null
		if(gpuImage instanceOf?(GpuYuv420Semiplanar)) {
			raster := RasterYuv420Semiplanar new(gpuImage size)
			semiPlanar := gpuImage as GpuYuv420Semiplanar
			yPacker := createPacker(semiPlanar y size, 1)
			yPacker pack(semiPlanar y, this _packMonochrome, raster y)
			yPacker recycle()
			uvPacker := createPacker(semiPlanar uv size, 2)
			uvPacker pack(semiPlanar uv, this _packUv, raster uv)
			uvPacker recycle()
			result = raster
		}
		result
	}
	recycle: func ~GpuPacker (packer: GpuPacker) {
		this _packerBin add(packer)
	}
	createPacker: func (size: IntSize2D, bytesPerPixel: UInt) -> GpuPacker {
		result := this _packerBin find(size, bytesPerPixel)
		if (result == null) {
			result = GpuPacker new(size, bytesPerPixel, this)
		}
		result
	}
	createEglRgba: func (size: IntSize2D) -> EglRgba {
		EglRgba new(this _backend _eglDisplay, size)
	}
}

AndroidContextManager: class extends GpuContextManager {
	init: func {
		setShaderSources()
		super(3)
	}
	_createContext: func -> GpuContext {
		AndroidContext new()
	}
}
{'fraction_non_alphanumeric': 0.08770855655900811, 'fraction_numerical': 0.015766110515842646, 'mean_word_length': 4.4, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5000686', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2199, 'n_words': 677}