Copy the pixel data into a new CByteArray

If pad_to_pow2 the new buffer contains artificial pixels used to make the width and the height powers of 2 for compatibility with older OpenGL.

If unmultiply, extra work is done to revert the multiplication of color values per the alpha channel applied by the Android system.

Property definitions

android :: load_image $ NativeBitmap :: copy_pixels
	# Copy the pixel data into a new `CByteArray`
	#
	# If `pad_to_pow2` the new buffer contains artificial pixels used to make
	# the width and the height powers of 2 for compatibility with older OpenGL.
	#
	# If `unmultiply`, extra work is done to revert the multiplication of color
	# values per the alpha channel applied by the Android system.
	fun copy_pixels(pad_to_pow2, unmultiply: nullable Bool): CByteArray
	do
		var height = height
		var row_bytes = row_bytes
		var bytes = row_bytes * height

		var w2 = width.next_pow(2)
		var h2 = height.next_pow(2)
		var row_bytes2 = row_bytes * w2 / width

		var capacity = bytes
		if pad_to_pow2 == true then capacity = row_bytes2 * h2

		var buf = new CByteArray(capacity)
		var java_buf = buf.to_java_nio_buffer
		copy_pixels_to_buffer java_buf

		if has_alpha and unmultiply == true then buf.native_array.unmultiply(width, height)

		if pad_to_pow2 == true then
			for r in [height-1..0[.step(-1) do
				var src_offset = row_bytes*r
				var dst_offset = row_bytes2*r
				buf.move(dst_offset, src_offset, row_bytes)
			end
		end

		return buf
	end
lib/android/load_image.nit:31,2--66,4