indexing description: "[ Pixelformat for the EiffelMedia library. ]" date: "$Date$" revision: "$Revision$" class EM_PIXELFORMAT inherit SDL_VIDEO_FUNCTIONS_EXTERNAL export {NONE} all end create make feature {NONE} -- Initialization make (a_pointer: POINTER) is -- Create from `a_pointer'. do create sdl_pixel_format_struct.make_shared (a_pointer) end feature -- Access palette: EM_PALETTE is -- Color palette -- This is only available if 'bits_per_pixel' is 8 require has_palette: has_palette do create Result.make_from_pointer (sdl_pixel_format_struct.palette) ensure palette_not_void: Result /= Void end bits_per_pixel: INTEGER is -- Number of bits for each pixel -- If the number of bits is 8 (i.e. 1 byte) then pixel-value denotes an entry in the 'palette' do Result := sdl_pixel_format_struct.bitsperpixel end bytes_per_pixel: INTEGER is -- Number of bytes for each pixel -- If the number of bytes is 1 then each pixel-value denotes an entry in the 'palette' do Result := sdl_pixel_format_struct.bytesperpixel end red_loss: INTEGER is -- Precision loss of red component -- (Used to get a full 8bit value in non-32bit mode) do Result := sdl_pixel_format_struct.rloss end green_loss: INTEGER is -- Precision loss of green component -- (Used to get a full 8bit value in non-32bit mode) do Result := sdl_pixel_format_struct.gloss end blue_loss: INTEGER is -- Precision loss of blue component -- (Used to get a full 8bit value in non-32bit mode) do Result := sdl_pixel_format_struct.bloss end alpha_loss: INTEGER is -- Precision loss of alpha component -- (Used to get a full 8bit value in non-32bit mode) do Result := sdl_pixel_format_struct.aloss end red_shift: INTEGER is -- Binary left shift of red component in a pixel value do Result := sdl_pixel_format_struct.rshift end green_shift: INTEGER is -- Binary left shift of green component in a pixel value do Result := sdl_pixel_format_struct.gshift end blue_shift: INTEGER is -- Binary left shift of blue component in a pixel value do Result := sdl_pixel_format_struct.bshift end alpha_shift: INTEGER is -- Binary left shift of alpha component in a pixel value do Result := sdl_pixel_format_struct.ashift end red_mask: INTEGER is -- Binary mask used to retrieve red component from a pixel do Result := sdl_pixel_format_struct.rmask end green_mask: INTEGER is -- Binary mask used to retrieve green component from a pixel do Result := sdl_pixel_format_struct.gmask end blue_mask: INTEGER is -- Binary mask used to retrieve blue component from a pixel do Result := sdl_pixel_format_struct.bmask end alpha_mask: INTEGER is -- Binary mask used to retrieve alpha component from a pixel do Result := sdl_pixel_format_struct.amask end colorkey: INTEGER is -- Color value that is set to be transparent do Result := sdl_pixel_format_struct.colorkey end alpha: INTEGER is -- Overall surface alpha value do Result := sdl_pixel_format_struct.alpha end feature -- Status has_palette: BOOLEAN is -- Does `Current' have a palette? do Result := sdl_pixel_format_struct.bitsperpixel = 8 end feature -- Element change set_palette (a_palette: like palette) is -- Set `palette' to `a_palette'. require has_palette: has_palette do sdl_pixel_format_struct.set_palette (a_palette.sdl_palette_struct.item) end set_bits_per_pixel (a_value: INTEGER) is -- Set `bits_per_pixel' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_bitsperpixel (a_value) end set_bytes_per_pixel (a_value: INTEGER) is -- Set `bytes_per_pixel' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_bytesperpixel (a_value) end set_red_loss (a_value: INTEGER) is -- Set `red_loss' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_rloss (a_value) end set_green_loss (a_value: INTEGER) is -- Set `green_loss' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_gloss (a_value) end set_blue_loss (a_value: INTEGER) is -- Set `blue_loss' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_bloss (a_value) end set_alpha_loss (a_value: INTEGER) is -- Set `alpha_loss' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_aloss (a_value) end set_red_shift (a_value: INTEGER) is -- Set `red_shift' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_rshift (a_value) end set_green_shift (a_value: INTEGER) is -- Set `green_shift' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_gshift (a_value) end set_blue_shift (a_value: INTEGER) is -- Set `blue_shift' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_bshift (a_value) end set_alpha_shift (a_value: INTEGER) is -- Set `alpha_shift' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_ashift (a_value) end set_red_mask (a_value: INTEGER) is -- Set `red_mask' to `a_value'. -- Note: By setting this manually you can break the application! do sdl_pixel_format_struct.set_rmask (a_value) end set_green_mask (a_value: INTEGER) is -- Set `green_mask' to `a_value'. -- Note: By setting this manually you can break the application! do sdl_pixel_format_struct.set_gmask (a_value) end set_blue_mask (a_value: INTEGER) is -- Set `blue_mask' to `a_value'. -- Note: By setting this manually you can break the application! do sdl_pixel_format_struct.set_bmask (a_value) end set_alpha_mask (a_value: INTEGER) is -- Set `alpha_mask' to `a_vlaue'. -- Note: By setting this manually you can break the application! do sdl_pixel_format_struct.set_amask (a_value) end set_colorkey (a_value: INTEGER) is -- Set `colorkey' to `a_value'. -- Note: By setting this manually you can break the application! do sdl_pixel_format_struct.set_colorkey (a_value) ensure colorkey_set: colorkey = a_value end set_alpha (a_value: INTEGER) is -- Set `alpha' to `a_value'. -- Note: By setting this manually you can break the application! require a_value_in_range: 0 <= a_value and a_value <= 255 do sdl_pixel_format_struct.set_alpha (a_value) ensure alpha_set: alpha = a_value end feature -- Conversion pixel_value_to_color (pixel_value: INTEGER): EM_COLOR is -- Convert `pixel_value' into a color object. require if_palette_pixel_value_in_range: has_palette implies 0 <= pixel_value and pixel_value < palette.number_of_colors do if has_palette then Result := palette.color (pixel_value) else create Result.make_black Result.set_red ( (((pixel_value & red_mask) |>> red_shift) & 0xFF) |<< red_loss) Result.set_green ( (((pixel_value & green_mask) |>> green_shift) & 0xFF) |<< green_loss) Result.set_blue ( (((pixel_value & blue_mask) |>> blue_shift) & 0xFF) |<< blue_loss) Result.set_alpha ( (((pixel_value & alpha_mask) |>> alpha_shift) & 0xFF) |<< alpha_loss) end ensure color_not_void: Result /= Void end color_to_pixel_value (a_color: EM_COLOR): INTEGER is -- Convert `a_color' to pixel value. do Result := sdl_map_rgba_external (sdl_pixel_format_struct.item, a_color.red, a_color.green, a_color.blue, a_color.alpha) end feature {EM_SURFACE} -- Implementation sdl_pixel_format_struct: SDL_PIXEL_FORMAT_STRUCT -- SDL struct of format end