note description: "Read 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_READER inherit GAME_PIXEL_BUFFER create make feature -- Access pixel (a_line, a_column: INTEGER_32): GAME_COLOR_READABLE -- Get the color of the pixel at line a_line and column a_column 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 do if bytes_per_pixel = 1 then l_color_index := internal_item.read_natural_8 ((a_line - 1) * pitch + (a_column - 1) * bytes_per_pixel).to_natural_32 elseif bytes_per_pixel = 2 then l_color_index := internal_item.read_natural_16 ((a_line - 1) * pitch + (a_column - 1) * bytes_per_pixel).to_natural_32 elseif bytes_per_pixel = 3 then if Is_little_endian then l_color_index := internal_item.read_natural_32_le ((a_line - 1) * pitch + (a_column - 1) * bytes_per_pixel).bit_and (16777215) else l_color_index := internal_item.read_natural_32_be ((a_line - 1) * pitch + (a_column - 1) * bytes_per_pixel).bit_shift_right (8) end elseif bytes_per_pixel = 4 then l_color_index := internal_item.read_natural_32 ((a_line - 1) * pitch + (a_column - 1) * bytes_per_pixel) end {GAME_SDL_EXTERNAL}.sdl_getrgba (l_color_index, pixel_format.item, $l_red.to_pointer, $l_green.to_pointer, $l_blue.to_pointer, $l_alpha.to_pointer) create Result.make (l_red, l_green, l_blue, l_alpha) end index (a_line, a_column: INTEGER_32): NATURAL_8 -- Get the index of the indexed pixel at line a_line and column a_column 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 Result := internal_item.read_natural_8 ((a_line - 1) * pitch + (a_column - 1)) end end -- class GAME_PIXEL_READER
Generated by ISE EiffelStudio