Esempio n. 1
0
    def test_encode1(self):
        # test the encoded/compressed indexes that it is the same as earlier
        new_subblocks = encode(self.indexes)
        for i in new_subblocks:
            self.assertIsInstance(i, Gif.Subblock)
        for i in self.gif.blocks:
            if i.block_type == Gif.BlockType.local_image_descriptor:
                i.body.image_data.subblocks.entries = new_subblocks

        gif2 = Gif.from_file("./test_src/sample_1.gif")

        self.assertEqual(gif_to_bytearray(self.gif), gif_to_bytearray(gif2))
Esempio n. 2
0
 def setUp(self):
     # set up with small gif file and known index values
     self.gif = Gif.from_file("./test_src/sample_1.gif")
     self.indexes = [
         '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '1', '1', '1',
         '1', '1', '2', '2', '2', '2', '2', '1', '1', '1', '1', '1', '2',
         '2', '2', '2', '2', '1', '1', '1', '0', '0', '0', '0', '2', '2',
         '2', '1', '1', '1', '0', '0', '0', '0', '2', '2', '2', '2', '2',
         '2', '0', '0', '0', '0', '1', '1', '1', '2', '2', '2', '0', '0',
         '0', '0', '1', '1', '1', '2', '2', '2', '2', '2', '1', '1', '1',
         '1', '1', '2', '2', '2', '2', '2', '1', '1', '1', '1', '1', '2',
         '2', '2', '2', '2', '1', '1', '1', '1', '1'
     ]
Esempio n. 3
0
    def test_encode2(self):
        # test that changing the indexes and compressing it will still work
        self.indexes[0] = '2'
        self.indexes[6] = '1'
        new_subblocks = encode(self.indexes)
        for i in self.gif.blocks:
            if i.block_type == Gif.BlockType.local_image_descriptor:
                i.body.image_data.subblocks.entries = new_subblocks

        write_to_file(self.gif, "./test_src/res_2.gif")
        gif2 = Gif.from_file("./test_src/res_2.gif")

        for i in gif2.blocks:
            if i.block_type == Gif.BlockType.local_image_descriptor:
                resulting_index = decode(i.body.image_data)
                self.assertEqual(resulting_index, self.indexes)
Esempio n. 4
0
 def test_write_to_file(self):
     # test that writing to file does not change the gif
     write_to_file(self.gif, "./test_src/res_1.gif")
     res_gif = Gif.from_file("./test_src/res_1.gif")
     self.assertEqual(gif_to_bytearray(self.gif), gif_to_bytearray(res_gif))
Esempio n. 5
0
Usage: gif-audio-add.py <input.gif> <input.wav>

Creates new file named `<input>.a.gif` which has the recommended
file extension for Audio GIFs.
"""
        raise SystemExit

    output_file_path = os.path.splitext(original_gif_file_path)[0] + ".a.gif"

    print "Output filepath:", output_file_path

    if os.path.exists(output_file_path):
        print "Output file path exists, not overwriting. Stopping."
        raise SystemExit

    data = Gif.from_file(original_gif_file_path)

    calculated_offset = 0

    #print data.hdr.magic, # 3 bytes
    #print data.hdr.version # 3 bytes

    calculated_offset += (3 + 3)

    # logical screen descriptor # 7 bytes

    calculated_offset += 7

    if data.logical_screen_descriptor.has_color_table:

        global_color_table_byte_size = len(data._raw_global_color_table)
Esempio n. 6
0
import unittest
from preprocess import *
from gif import Gif
# Author : Jia Qin Choong
# Usage : Testing functions in preprocess.py

path = "./test_src/levi.gif"
inputgif = Gif.from_file(path)


class Test_Preprocess(unittest.TestCase):
    def test_capacity(self):
        # check to see if the count returned a value > 0
        self.assertGreater(count_available_storage(inputgif), 0,
                           "Failed to check capacity")

    def test_get_lct_index(self):
        # check to see  if the number of frames are obtained properly
        indexlist = get_lct_index(inputgif)
        blocks = inputgif.blocks
        count = 0
        for i in range(len(blocks)):
            if str(blocks[i].block_type) == "BlockType.local_image_descriptor":
                count += 1
        self.assertEqual(len(indexlist), count, "Failed to get lct index list")

    def test_setlocalCT(self):
        # check if all the local color table flag has been set to 135
        indexlist = set_local_color_table(inputgif)
        count = 0
        blocks = inputgif.blocks  # the frames are stored in blocks
                    res += bytearray(c.red.to_bytes(1, 'little'))
                    res += bytearray(c.green.to_bytes(1, 'little'))
                    res += bytearray(c.blue.to_bytes(1, 'little'))
            res += bytearray(
                i.body.image_data.lzw_min_code_size.to_bytes(1, 'little'))
            for j in i.body.image_data.subblocks.entries:
                res += bytearray(j.num_bytes.to_bytes(1, 'little'))
                res += bytearray(j.bytes)
    with open(filename, 'wb+') as f:
        f.write(res)

    print(len(res))


if __name__ == "__main__":
    data1 = Gif.from_file("../../../Downloads/safe_image.gif")
    data2 = Gif.from_file(
        "../../../Downloads/tumblr_pvk36wTOsT1ytp1fjo1_540.gif")
    # print(data1.hdr.magic)
    # print(data1.hdr.version)

    # color_table1 = data1.global_color_table.entries
    # color_table2 = data2.global_color_table.entries

    # for i in range(1, len(color_table1)):
    #     color1 = color_table1[i]
    #     color2 = color_table2[i]
    #
    #     print(i, "\t", color1.red, color1.green, color1.blue, "\t", color2.red, color2.green, color2.blue)

    # print(data2.logical_screen_descriptor.has_color_table)