note description: "Write access to an internal array of pixels." author: "Louis Marchand" date: "Tue, 26 Jan 2016 19:34:13 +0000" revision: "2.1" class GAME_PIXEL_WRITER inherit GAME_PIXEL_BUFFER create make feature -- Access set_pixel (a_color: GAME_COLOR_READABLE; a_line, a_column: INTEGER_32) -- Set the color of the pixel at line a_line and column a_column to a_color require is_item_valid: is_valid is_line_valid: a_line >= 1 and then a_line <= height is_column_valid: a_line >= 1 and then a_column <= width not_indexed: not pixel_format.is_indexed local l_color_index: NATURAL_32 l_red, l_green, l_blue, l_alpha: NATURAL_8 l_position: INTEGER_32 do l_position := (a_line - 1) * pitch + (a_column - 1) * bytes_per_pixel l_color_index := {GAME_SDL_EXTERNAL}.sdl_maprgba (pixel_format.item, a_color.red, a_color.green, a_color.blue, a_color.alpha) if bytes_per_pixel = 1 then internal_item.put_natural_8 (l_color_index.to_natural_8, l_position) elseif bytes_per_pixel = 2 then internal_item.put_natural_16 (l_color_index.to_natural_16, l_position) elseif bytes_per_pixel = 3 then if Is_little_endian then internal_item.put_natural_8 (l_color_index.bit_and (255).to_natural_8, l_position); internal_item.put_natural_8 (l_color_index.bit_shift_right (8).bit_and (255).to_natural_8, l_position + 1); internal_item.put_natural_8 (l_color_index.bit_shift_right (16).bit_and (255).to_natural_8, l_position + 2) else internal_item.put_natural_8 (l_color_index.bit_shift_right (16).bit_and (255).to_natural_8, l_position); internal_item.put_natural_8 (l_color_index.bit_shift_right (8).bit_and (255).to_natural_8, l_position + 1); internal_item.put_natural_8 (l_color_index.bit_and (255).to_natural_8, l_position + 2) end elseif bytes_per_pixel = 4 then internal_item.put_natural_32 (l_color_index, l_position) end end set_index (a_index: NATURAL_8; a_line, a_column: INTEGER_32) -- Set the index of the indexed pixel at line a_line and column a_column to a_index require is_item_valid: is_valid is_line_valid: a_line >= 1 and then a_line <= height is_column_valid: a_line >= 1 and then a_column <= width indexed: pixel_format.is_indexed bits_per_pixel_valid: pixel_format.bits_per_pixel = 8 do internal_item.put_natural_8 (a_index, (a_line - 1) * pitch + (a_column - 1)) end end -- class GAME_PIXEL_WRITER
Generated by ISE EiffelStudio