Домой Классы Статические функции Перечисления (ENUM) Записи (RECORD)

{Gif|_animated_image}


(включая защищенные члены)

CLASS {Gif|_animated_image} , UNTESTED, BYTES, BITWISE:



IMPORT : {Bitmap} , {AL4_drawing} , {File_stream} , {Bitmap_direct} , {Canvas} .

STR Path|_file


{Bitmap_direct} bitmap|_current_frame


INT last_frame|_in_bitmap


{Bitmap_direct} save_bitmap|_to_restore_back_before_next_frame


INDEXING {gif_frame}

INT Frame|_current , READ


BOOL Corrupted , READ


          

ENUMERATION {gif_code|_from} :

        'GIF_BOTH|_NATIVE_AND_AL4' ,

        'GIF_NATIVE|_ONLY' ,

        'GIF_AL4|_ONLY' .



FUN Gif_code|_from ==> {gif_code}



FUN Set_gif_code|_from ( {gif_code} Value|_to_set )



FUNCTION Load|_animated_gif ( STR Path|_of_file ) ==> {Gif} , NEW



FUNCTION From_stream|_animated_gif (
     
{Stream} S|ource_stream ) ==> {Gif} , NEW



METHOD Count|_frames ==> INT



METHOD Set_frame ( INT N|umber_of_frame_0_to_Count_minus_1 )



METHOD Duration|_of_frame|_milliseconds ==> INT



METHOD Width|_entire_gif ==> INT



METHOD Height|_entire_gif ==> INT



-------------------------------------------------------- 'load using {LZW}'

      

FUNCTION load_and_decode_gif (
     
{Stream} In|put_stream_with_gif_encoded ,
     
{Gif} Target|_gif )



METHOD read_frames ( {Stream} In|put_stream ) , OPERATORS



METHOD skip_0_sep ( {Stream} In|put_stream )



METHOD skip_until ( {Stream} In|put_stream , STR Wait|_separator )



METHOD may_be_comment ( {extension} E|xtension_item )



METHOD seek_next_frame (
     
{Stream} In|put_stream ,
     
{long} From|_position ) ==> BOOL


{gif_frame} frames|_of_gif[]


{Stream} all_frame_streams[]


{Bitmap} all_frame_bitmaps[]


STR comments[]


   

STRUCTURE {gif_frame}

      INT Index|_of_frame INDEXING {gif_frame}

      BOOL Corrupt|ed

      {Bitmap} Bitmap_|may_be_smaller_then_entire_size_

      {Geometry}.{point} Top_left|_position_of_frame_on_gif_image

      {extensions} Extensions|_list

      INT Delay|_frame

      {disposal} Disposal_method

      INT Transp_color||Transparent_color|_value|_RGB

      INT Transp_i|ndex||Transparent_color_index INDEXING {color_item}

      BOOL Transparent

      BOOL Really_transp|arent

      BOOL Interlaced

      BOOL Local_colors

      {Memory_stream} Data_|image_

      INT Size_w|idth

      INT Size_h|eight

      BYTE Packed_f|ields

      {color_item} Color_map[] .



ENUMERATION {disposal|_method} :

        'UNDEFINED' ,

        'LEAVE|_INTACT' ,

        'RESTORE_BACK|GROUND' ,

        'RESTORE_PREV|IOUS' .



FUN colors_to_bits ( INT C|olors_count ) ==> INT



-------------------------------------------------------------- 'load frame'

     

METHOD load_frame (
     
{Stream} In|put_stream ,
     
INT Index INDEXING {gif_frame} ) ==> BOOL


CONSTANT INT :

          BUFFER_SIZE = 1024 .


CONSTANT INT {image_descriptor_flags} :

          ID_LOCAL_COLOR_TABLE = 0x80

          ID_INTERLACED = 0x40

          ID_SORT|ED_COLORS = 0x20

          ID_RESERVED = 0x0C

          ID_COLOR_TABLE_SIZE = 0x07 .


CONSTANT INT :

          GCE_TRANSPARENT = 1

          GCE_USER_INPUT = 2

          GCE_DISPOSAL_METHOD = 0x1C

          GCE_RESERVED = 0xE0 .



FUN read_image_stream (
     
{Stream} In|put_stream ,
     
{Memory_stream} Out|_image_data ,
     
{gif_frame} Source_frame ) ==> {gif_frame} , OPERATORS



------------------------------------------------------- 'screen descriptor'

 

METHOD read_screen_descr|iptor (
     
{Stream} In|put_stream_with_gif_encoded )


STR Version|_GIF87a_GIF89a


{screen_descriptor} Scr|een_descriptor , READ


INT Bits_per_pixel , READ


INT Color_res|_bits , READ


  

CONSTANT INT {logical_screen_descriptor_masks} :

          LSD_GLOBAL_COLOR_TABLE|_SET_IF_GLOBAL_COLOR_TABLE_FOLLOWS_LSD = 0x80

          LSD_COLOR_RESOLUTION = 0x70

          LSD_SORT|ED_GLOBAL_COLOR_TABLE = 8

          LSD_COLOR_TABLE_SIZE|_3LOW_BITS = 7 .



STRUCTURE {screen_descriptor}

      INT W|idth|_scr|een

      INT H|eight|_scr|een

      INT Packed_f|ields

      INT Back_index||Background_color INDEXING {color_item}

      INT Aspect_r|atio .



-------------------------------------------------------- 'global color map'

   

METHOD read_global_color_map (
     
{Stream} In|put_stream_with_gif_encoded )



STRUCTURE {color_item}

      BYTE R|ed_component

      BYTE G|reen_component

      BYTE B|lue_component .



FUNCTION item_to_rgb (
     
{color_item} Item|_to_convert ) ==> INT


{color_item} Color_map[] , READ


INT Back_color||Background|_color



-------------------------------------------------------------- 'extensions'

STR Sep|arator_char_last


BOOL Looping|_defined


INT Repeat_count


          

METHOD read_extensions|_block (
     
{Stream} In|put_stream_with_gif_encoded ) ==> {extensions}



FUN is_loop_extension ( {extension} e|xtension ) ==> BOOL


CONSTANT INT :

          MAX_LOOP_COUNT = 30_000 .



FUN read_extension (
     
{Stream} In|put_stream_with_gif_encoded ) ==> {extension}



FUN read_data_block (
     
STR Lines|_to_read [] ,
     
INT Loop_count [] ,
     
{Stream} In|put_stream )


CONSTANT STR :

          CHR_EXT_INTRO|DUCER = "!"

          CHR_IMAGE_SEP|ARATOR = ","

          CHR_TRAILER = ";" .



STRUCTURE {extensions|_list}

      {extension} E|xtension_items[] .



ENUMERATION {extension_type} :

        'UNKNOWN|_EXTENSION' ,

        'GRAPHIC|_EXTENSION' ,

        'PLAIN_TEXT' ,

        'APPLICATION' ,

        'COMMENT' .


CONSTANT INT :

          EXT_LABEL_GRAPHIC = 0xF9

          EXT_LABEL_PLAIN_T|EXT = 1

          EXT_LABEL_APP|LICATION = 0xFF

          EXT_LABEL_COMMENT = 0xFE .



STRUCTURE {extension}

      {extension_type} Type|_of_extension

      STR Lines|_list[]

      INT Loop_count|s|_in_lines[]

      BYTE Block_size|_4_12_11

      BYTE Packed_f|ields

      INT Delay_time|_centiseconds

      INT Transp_index||Transparent_color_index

      BYTE Terminator

      INT Left|_position

      INT Top|_position

      INT Width|_size

      INT Height|_size

      INT Cell_w|idth

      INT Cell_h|eight

      INT Fore_i||Foreground_color_index

      INT Back_i||Background_color_index

      BYTE App_id|entifier_8_bytes[]

      BYTE Authent|ication_3_bytes[] .



---------------------------------------------------------- 'getting bitmap'

     

METHOD Bitmap|_current_frame ==> {Bitmap}



METHOD draw_frame ( INT Index|_frame_to_draw INDEXING {gif_frame} )



FUN save_ext|ension ==> STR , DEBUG


CONSTANT INT :

          OPAQUE|_ALPHA = 0xFF

          TRANSPARENT = 0 .



METHOD provide_bitmap (
     
{gif_frame} Frame|_to_provide_bitmap ) ==> {gif_frame}


{gif_frame} frame|_result


   

METHOD decode_row|_rgba_or_bgra (
     
{Bitmap_direct} b|itmap_destination ,
     
INT Y|_destination ,
     
{Memory_stream} ms|tream_bits_data ,
     
{Bitmap_direct} e|ntire_bitmap_to_draw_on ,
     
INT bpp|_bits_per_pixel ,
     
{color_item} palette|_colors [] ,
     
INT offset_r|ed_component_0_or_2 )



FUNCTION Can_load ==> BOOL



FUNCTION Can_save ==> BOOL



-------------------------------------------------------------------- 'save'

  

FUNCTION To_file|_by_path (
     
{Bitmap} B|itmap_to_convert_to_gif_and_save ,
     
STR Path|_of_file ) ==> BOOL



FUNCTION To_stream (
     
{Bitmap} B|itmap_to_convert_to_gif_and_save ,
     
{Stream} S|tream_destination ) ==> BOOL


END