Ejemplo n.º 1
0
def copy_global_ct(inputgif):
    """
    This function creates a copy of the global colour table
    :param inputgif: the input gif object
    :return: new table which is a deep copy of the global color table
    """
    global_table = inputgif.global_color_table
    new_table = Gif.ColorTable(global_table._io)
    for i in global_table.entries:
        newcolor = Gif.ColorTableEntry(None)
        newcolor.red = i.red
        newcolor.green = i.green
        newcolor.blue = i.blue
        new_table.entries.append(newcolor)

    return new_table
Ejemplo n.º 2
0
def checkGCT(inputgif):
    """
    This function checks if the GIF has GCT and if it is of size 256
    Called in count_available_storage
    :param inputgif: GIF object
    :return: GIF object
    """
    flag = inputgif.logical_screen_descriptor.flags
    if (flag & 128) != 0:  # if there is GCT
        global_table = inputgif.global_color_table
        if len(global_table.entries) == 256:  # if size of GCT is 256
            return inputgif

        else:  # if size not 256
            old_table = global_table.entries
            new_table = Gif.ColorTable(
                global_table._io)  # create new empty table
            for i in range(256):
                if i < len(old_table):  # append the old table RGB values
                    newcolor = Gif.ColorTableEntry(None)
                    newcolor.red = old_table[i].red
                    newcolor.green = old_table[i].green
                    newcolor.blue = old_table[i].blue
                    new_table.entries.append(newcolor)

                else:  # create empty RGB values for new entries
                    newcolor = Gif.ColorTableEntry(None)
                    newcolor.red = 0
                    newcolor.green = 0
                    newcolor.blue = 0
                    new_table.entries.append(newcolor)
            inputgif.global_color_table = new_table

        inputgif.logical_screen_descriptor.flags = 247  # change the flag value to indicate correct size of gct
    # else no gct just return inputgif
    return inputgif