RSpec.shared_examples "images ops" do
  extend SupportedOp

  before(:each) do
    TensorStream::Tensor.reset_counters
    TensorStream::Operation.reset_counters
    tf.reset_default_graph
    sess.clear_session_cache
  end

  supported_op ".decode_png" do
    it "converts png file to a tensor" do
      image_1 = File.open( File.join("spec", "fixtures", "ruby_16.png"), 'rb') { |io| io.read }
      decoded_image = tf.image.decode_png(image_1)

      expect(sess.run(decoded_image)).to eq([[[0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [178, 3, 0, 23],
                                              [211, 5, 0, 125],
                                              [218, 48, 45, 196],
                                              [231, 105, 97, 204],
                                              [202, 45, 31, 204],
                                              [187, 11, 0, 214],
                                              [177, 5, 0, 227],
                                              [148, 4, 0, 191],
                                              [123, 2, 0, 63],
                                              [0, 0, 0, 0],],
                                             [[0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [116, 0, 0, 1],
                                              [196, 8, 0, 128],
                                              [216, 13, 0, 245],
                                              [201, 18, 0, 255],
                                              [192, 17, 0, 255],
                                              [216, 24, 12, 255],
                                              [218, 101, 92, 255],
                                              [215, 127, 125, 255],
                                              [186, 82, 81, 255],
                                              [152, 40, 37, 255],
                                              [121, 8, 4, 245],
                                              [111, 1, 0, 29],],
                                             [[0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [118, 0, 0, 10],
                                              [195, 12, 0, 192],
                                              [207, 17, 0, 255],
                                              [197, 19, 1, 255],
                                              [193, 18, 1, 255],
                                              [189, 15, 0, 255],
                                              [229, 127, 122, 255],
                                              [232, 140, 132, 255],
                                              [210, 89, 82, 255],
                                              [157, 72, 70, 255],
                                              [99, 3, 0, 255],
                                              [106, 3, 0, 255],
                                              [116, 2, 0, 101],],
                                             [[0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [116, 0, 0, 10],
                                              [186, 18, 3, 194],
                                              [204, 18, 1, 255],
                                              [200, 28, 11, 255],
                                              [199, 40, 25, 255],
                                              [190, 19, 3, 255],
                                              [186, 15, 2, 255],
                                              [234, 124, 121, 255],
                                              [235, 158, 152, 255],
                                              [212, 58, 46, 255],
                                              [196, 24, 15, 255],
                                              [139, 15, 10, 255],
                                              [123, 4, 0, 255],
                                              [124, 2, 0, 102],],
                                             [[0, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [176, 22, 9, 170],
                                              [207, 45, 30, 255],
                                              [200, 26, 9, 255],
                                              [202, 55, 42, 255],
                                              [199, 55, 44, 255],
                                              [192, 39, 28, 255],
                                              [203, 46, 42, 255],
                                              [251, 201, 198, 255],
                                              [239, 179, 174, 255],
                                              [221, 91, 82, 255],
                                              [206, 32, 22, 255],
                                              [187, 14, 4, 255],
                                              [152, 5, 0, 255],
                                              [111, 2, 0, 77],],
                                             [[0, 0, 0, 0],
                                              [155, 5, 0, 84],
                                              [198, 34, 23, 255],
                                              [213, 77, 63, 255],
                                              [194, 18, 0, 255],
                                              [210, 91, 80, 255],
                                              [201, 75, 66, 255],
                                              [192, 33, 24, 255],
                                              [234, 151, 148, 255],
                                              [206, 131, 129, 255],
                                              [216, 102, 100, 255],
                                              [208, 57, 53, 255],
                                              [186, 12, 6, 255],
                                              [155, 4, 0, 255],
                                              [110, 4, 1, 255],
                                              [107, 1, 0, 51],],
                                             [[0, 0, 0, 0],
                                              [173, 8, 0, 215],
                                              [204, 50, 40, 255],
                                              [213, 98, 87, 255],
                                              [196, 52, 44, 255],
                                              [222, 141, 135, 255],
                                              [193, 61, 55, 255],
                                              [217, 121, 117, 255],
                                              [208, 103, 99, 255],
                                              [165, 9, 0, 255],
                                              [133, 3, 0, 255],
                                              [188, 8, 3, 255],
                                              [188, 4, 0, 255],
                                              [160, 4, 0, 255],
                                              [109, 15, 11, 255],
                                              [116, 0, 0, 51],],
                                             [[152, 24, 21, 65],
                                              [186, 12, 0, 255],
                                              [202, 65, 57, 255],
                                              [213, 113, 105, 255],
                                              [217, 147, 144, 255],
                                              [210, 133, 130, 255],
                                              [215, 129, 125, 255],
                                              [221, 123, 116, 255],
                                              [191, 16, 0, 255],
                                              [179, 10, 0, 255],
                                              [155, 3, 0, 255],
                                              [177, 7, 3, 255],
                                              [201, 39, 37, 255],
                                              [168, 50, 48, 255],
                                              [102, 11, 8, 255],
                                              [116, 0, 0, 16],],
                                             [[220, 137, 131, 154],
                                              [183, 12, 0, 255],
                                              [212, 135, 133, 255],
                                              [234, 189, 186, 255],
                                              [239, 203, 201, 255],
                                              [235, 178, 176, 255],
                                              [242, 189, 184, 255],
                                              [206, 61, 49, 255],
                                              [191, 16, 0, 255],
                                              [187, 10, 0, 255],
                                              [182, 4, 0, 255],
                                              [192, 4, 0, 255],
                                              [214, 59, 58, 255],
                                              [206, 141, 139, 255],
                                              [113, 3, 0, 255],
                                              [0, 0, 0, 0],],
                                             [[193, 59, 48, 192],
                                              [200, 81, 73, 255],
                                              [205, 109, 104, 255],
                                              [226, 159, 155, 255],
                                              [241, 207, 206, 255],
                                              [238, 180, 178, 255],
                                              [238, 182, 178, 255],
                                              [221, 131, 124, 255],
                                              [194, 40, 32, 255],
                                              [198, 8, 0, 255],
                                              [196, 4, 0, 255],
                                              [207, 30, 29, 255],
                                              [242, 149, 148, 255],
                                              [212, 117, 110, 255],
                                              [132, 3, 0, 244],
                                              [0, 0, 0, 0],],
                                             [[167, 9, 0, 204],
                                              [201, 123, 117, 255],
                                              [217, 91, 79, 255],
                                              [191, 18, 1, 255],
                                              [190, 92, 88, 255],
                                              [183, 87, 85, 255],
                                              [210, 7, 0, 255],
                                              [190, 48, 44, 255],
                                              [198, 65, 60, 255],
                                              [198, 32, 27, 255],
                                              [212, 81, 79, 255],
                                              [240, 171, 170, 255],
                                              [233, 93, 87, 255],
                                              [202, 64, 52, 255],
                                              [152, 4, 0, 204],
                                              [0, 0, 0, 0],],
                                             [[143, 3, 0, 204],
                                              [136, 59, 55, 255],
                                              [217, 90, 79, 255],
                                              [191, 18, 1, 255],
                                              [163, 49, 44, 255],
                                              [133, 32, 29, 255],
                                              [201, 38, 34, 255],
                                              [198, 5, 0, 255],
                                              [187, 4, 0, 255],
                                              [176, 4, 1, 255],
                                              [220, 172, 172, 255],
                                              [236, 146, 144, 255],
                                              [207, 49, 36, 255],
                                              [192, 19, 2, 255],
                                              [164, 4, 0, 204],
                                              [0, 0, 0, 0],],
                                             [[179, 5, 0, 204],
                                              [109, 3, 0, 255],
                                              [189, 63, 52, 255],
                                              [191, 18, 1, 255],
                                              [137, 11, 5, 255],
                                              [146, 4, 0, 255],
                                              [190, 33, 29, 255],
                                              [210, 41, 39, 255],
                                              [200, 46, 44, 255],
                                              [203, 117, 116, 255],
                                              [184, 47, 46, 255],
                                              [171, 31, 28, 255],
                                              [184, 27, 19, 255],
                                              [181, 11, 0, 255],
                                              [187, 6, 0, 160],
                                              [0, 0, 0, 0],],
                                             [[208, 6, 0, 139],
                                              [101, 3, 0, 255],
                                              [146, 26, 15, 255],
                                              [184, 16, 1, 255],
                                              [155, 4, 0, 255],
                                              [180, 4, 0, 255],
                                              [195, 4, 0, 255],
                                              [225, 91, 89, 255],
                                              [202, 78, 76, 255],
                                              [184, 8, 4, 255],
                                              [167, 4, 0, 255],
                                              [163, 5, 0, 255],
                                              [184, 6, 1, 255],
                                              [186, 6, 0, 255],
                                              [161, 3, 0, 163],
                                              [0, 0, 0, 6],],
                                             [[45, 0, 0, 78],
                                              [105, 2, 0, 223],
                                              [138, 4, 0, 255],
                                              [180, 10, 1, 255],
                                              [196, 68, 66, 255],
                                              [205, 80, 79, 255],
                                              [220, 97, 94, 254],
                                              [224, 84, 79, 241],
                                              [204, 42, 36, 236],
                                              [183, 15, 6, 235],
                                              [162, 11, 0, 224],
                                              [146, 6, 0, 216],
                                              [142, 3, 0, 214],
                                              [158, 3, 0, 202],
                                              [110, 1, 0, 154],
                                              [0, 0, 0, 39],],
                                             [[0, 0, 0, 9],
                                              [0, 0, 0, 35],
                                              [64, 0, 0, 68],
                                              [83, 0, 0, 96],
                                              [31, 0, 0, 90],
                                              [0, 0, 0, 93],
                                              [0, 0, 0, 94],
                                              [0, 0, 0, 94],
                                              [0, 0, 0, 94],
                                              [0, 0, 0, 89],
                                              [0, 0, 0, 80],
                                              [0, 0, 0, 67],
                                              [0, 0, 0, 51],
                                              [0, 0, 0, 31],
                                              [0, 0, 0, 12],
                                              [0, 0, 0, 1],],])
    end

    it "supports grayscale" do
      image_1 = File.open( File.join("spec", "fixtures", "ruby_16.png"), 'rb') { |io| io.read }
      decoded_image = tf.image.decode_png(image_1, channels: 1)

      expect(sess.run(decoded_image)).to eq([[[0], [0], [0], [0], [0], [0], [55], [66], [99], [142], [91], [63], [56], [47], [38], [0]],
                                             [[0], [0], [0], [0], [35], [64], [72], [71], [68], [80], [135], [153], [113], [73], [41], [34]],
                                             [[0], [0], [0], [35], [66], [72], [70], [69], [66], [157], [167], [125], [97], [31], [34], [36]],
                                             [[0], [0], [35], [67], [72], [78], [86], [69], [65], [157], [180], [103], [75], [52], [39], [38]],
                                             [[0], [0], [67], [92], [76], [98], [97], [84], [93], [216], [196], [129], [83], [65], [49], [34]],
                                             [[0], [49], [82], [116], [69], [125], [112], [80], [176], [153], [136], [102], [64], [49], [35], [33]],
                                             [[0], [57], [95], [131], [94], [165], [100], [149], [134], [55], [42], [61], [59], [50], [43], [35]],
                                             [[62], [63], [105], [142], [168], [156], [154], [152], [67], [60], [48], [58], [87], [85], [38], [35]],
                                             [[161], [62], [158], [202], [214], [195], [204], [103], [67], [62], [57], [60], [105], [160], [36], [0]],
                                             [[98], [116], [137], [179], [217], [197], [198], [157], [85], [64], [61], [83], [177], [145], [41], [0]],
                                             [[55], [146], [127], [68], [121], [116], [67], [90], [104], [81], [120], [192], [134], [104], [48], [0]],
                                             [[45], [82], [127], [68], [83], [62], [86], [62], [58], [55], [186], [173], [95], [69], [52], [0]],
                                             [[57], [34], [100], [68], [48], [46], [80], [91], [92], [143], [88], [73], [73], [61], [60], [0]],
                                             [[66], [32], [61], [65], [49], [56], [61], [131], [115], [60], [52], [52], [59], [59], [50], [0]],
                                             [[14], [33], [44], [60], [106], [117], [134], [125], [90], [64], [55], [47], [44], [49], [34], [0]],
                                             [[0], [0], [19], [25], [9], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]],])
    end

    it "supports other data types" do
      image_1 = File.open( File.join("spec", "fixtures", "ruby_16.png"), 'rb') { |io| io.read }
      decoded_image = tf.image.decode_png(image_1, channels: 1, dtype: :float32)
      expect(sess.run(decoded_image)).to eq([[[0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [55.0], [66.0], [99.0], [142.0], [91.0], [63.0], [56.0], [47.0], [38.0], [0.0]],
                                             [[0.0], [0.0], [0.0], [0.0], [35.0], [64.0], [72.0], [71.0], [68.0], [80.0], [135.0], [153.0], [113.0], [73.0], [41.0], [34.0]],
                                             [[0.0], [0.0], [0.0], [35.0], [66.0], [72.0], [70.0], [69.0], [66.0], [157.0], [167.0], [125.0], [97.0], [31.0], [34.0], [36.0]],
                                             [[0.0], [0.0], [35.0], [67.0], [72.0], [78.0], [86.0], [69.0], [65.0], [157.0], [180.0], [103.0], [75.0], [52.0], [39.0], [38.0]],
                                             [[0.0], [0.0], [67.0], [92.0], [76.0], [98.0], [97.0], [84.0], [93.0], [216.0], [196.0], [129.0], [83.0], [65.0], [49.0], [34.0]],
                                             [[0.0], [49.0], [82.0], [116.0], [69.0], [125.0], [112.0], [80.0], [176.0], [153.0], [136.0], [102.0], [64.0], [49.0], [35.0], [33.0]],
                                             [[0.0], [57.0], [95.0], [131.0], [94.0], [165.0], [100.0], [149.0], [134.0], [55.0], [42.0], [61.0], [59.0], [50.0], [43.0], [35.0]],
                                             [[62.0], [63.0], [105.0], [142.0], [168.0], [156.0], [154.0], [152.0], [67.0], [60.0], [48.0], [58.0], [87.0], [85.0], [38.0], [35.0]],
                                             [[161.0], [62.0], [158.0], [202.0], [214.0], [195.0], [204.0], [103.0], [67.0], [62.0], [57.0], [60.0], [105.0], [160.0], [36.0], [0.0]],
                                             [[98.0], [116.0], [137.0], [179.0], [217.0], [197.0], [198.0], [157.0], [85.0], [64.0], [61.0], [83.0], [177.0], [145.0], [41.0], [0.0]],
                                             [[55.0], [146.0], [127.0], [68.0], [121.0], [116.0], [67.0], [90.0], [104.0], [81.0], [120.0], [192.0], [134.0], [104.0], [48.0], [0.0]],
                                             [[45.0], [82.0], [127.0], [68.0], [83.0], [62.0], [86.0], [62.0], [58.0], [55.0], [186.0], [173.0], [95.0], [69.0], [52.0], [0.0]],
                                             [[57.0], [34.0], [100.0], [68.0], [48.0], [46.0], [80.0], [91.0], [92.0], [143.0], [88.0], [73.0], [73.0], [61.0], [60.0], [0.0]],
                                             [[66.0], [32.0], [61.0], [65.0], [49.0], [56.0], [61.0], [131.0], [115.0], [60.0], [52.0], [52.0], [59.0], [59.0], [50.0], [0.0]],
                                             [[14.0], [33.0], [44.0], [60.0], [106.0], [117.0], [134.0], [125.0], [90.0], [64.0], [55.0], [47.0], [44.0], [49.0], [34.0], [0.0]],
                                             [[0.0], [0.0], [19.0], [25.0], [9.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0]],])
    end

    specify "resampling" do
      image_1 = File.open( File.join("spec", "fixtures", "ruby_16.png"), 'rb') { |io| io.read }
      decoded_image = tf.image.decode_png(image_1, new_shape: [32, 32])
      expect(sess.run(tf.shape(decoded_image))).to eq([32, 32, 4])
    end
  end

  supported_op ".encode_png" do
    let(:image_data) {
      [[[0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [178, 3, 0, 23],
        [211, 5, 0, 125],
        [218, 48, 45, 196],
        [231, 105, 97, 204],
        [202, 45, 31, 204],
        [187, 11, 0, 214],
        [177, 5, 0, 227],
        [148, 4, 0, 191],
        [123, 2, 0, 63],
        [0, 0, 0, 0],],
       [[0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [116, 0, 0, 1],
        [196, 8, 0, 128],
        [216, 13, 0, 245],
        [201, 18, 0, 255],
        [192, 17, 0, 255],
        [216, 24, 12, 255],
        [218, 101, 92, 255],
        [215, 127, 125, 255],
        [186, 82, 81, 255],
        [152, 40, 37, 255],
        [121, 8, 4, 245],
        [111, 1, 0, 29],],
       [[0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [118, 0, 0, 10],
        [195, 12, 0, 192],
        [207, 17, 0, 255],
        [197, 19, 1, 255],
        [193, 18, 1, 255],
        [189, 15, 0, 255],
        [229, 127, 122, 255],
        [232, 140, 132, 255],
        [210, 89, 82, 255],
        [157, 72, 70, 255],
        [99, 3, 0, 255],
        [106, 3, 0, 255],
        [116, 2, 0, 101],],
       [[0, 0, 0, 0],
        [0, 0, 0, 0],
        [116, 0, 0, 10],
        [186, 18, 3, 194],
        [204, 18, 1, 255],
        [200, 28, 11, 255],
        [199, 40, 25, 255],
        [190, 19, 3, 255],
        [186, 15, 2, 255],
        [234, 124, 121, 255],
        [235, 158, 152, 255],
        [212, 58, 46, 255],
        [196, 24, 15, 255],
        [139, 15, 10, 255],
        [123, 4, 0, 255],
        [124, 2, 0, 102],],
       [[0, 0, 0, 0],
        [0, 0, 0, 0],
        [176, 22, 9, 170],
        [207, 45, 30, 255],
        [200, 26, 9, 255],
        [202, 55, 42, 255],
        [199, 55, 44, 255],
        [192, 39, 28, 255],
        [203, 46, 42, 255],
        [251, 201, 198, 255],
        [239, 179, 174, 255],
        [221, 91, 82, 255],
        [206, 32, 22, 255],
        [187, 14, 4, 255],
        [152, 5, 0, 255],
        [111, 2, 0, 77],],
       [[0, 0, 0, 0],
        [155, 5, 0, 84],
        [198, 34, 23, 255],
        [213, 77, 63, 255],
        [194, 18, 0, 255],
        [210, 91, 80, 255],
        [201, 75, 66, 255],
        [192, 33, 24, 255],
        [234, 151, 148, 255],
        [206, 131, 129, 255],
        [216, 102, 100, 255],
        [208, 57, 53, 255],
        [186, 12, 6, 255],
        [155, 4, 0, 255],
        [110, 4, 1, 255],
        [107, 1, 0, 51],],
       [[0, 0, 0, 0],
        [173, 8, 0, 215],
        [204, 50, 40, 255],
        [213, 98, 87, 255],
        [196, 52, 44, 255],
        [222, 141, 135, 255],
        [193, 61, 55, 255],
        [217, 121, 117, 255],
        [208, 103, 99, 255],
        [165, 9, 0, 255],
        [133, 3, 0, 255],
        [188, 8, 3, 255],
        [188, 4, 0, 255],
        [160, 4, 0, 255],
        [109, 15, 11, 255],
        [116, 0, 0, 51],],
       [[152, 24, 21, 65],
        [186, 12, 0, 255],
        [202, 65, 57, 255],
        [213, 113, 105, 255],
        [217, 147, 144, 255],
        [210, 133, 130, 255],
        [215, 129, 125, 255],
        [221, 123, 116, 255],
        [191, 16, 0, 255],
        [179, 10, 0, 255],
        [155, 3, 0, 255],
        [177, 7, 3, 255],
        [201, 39, 37, 255],
        [168, 50, 48, 255],
        [102, 11, 8, 255],
        [116, 0, 0, 16],],
       [[220, 137, 131, 154],
        [183, 12, 0, 255],
        [212, 135, 133, 255],
        [234, 189, 186, 255],
        [239, 203, 201, 255],
        [235, 178, 176, 255],
        [242, 189, 184, 255],
        [206, 61, 49, 255],
        [191, 16, 0, 255],
        [187, 10, 0, 255],
        [182, 4, 0, 255],
        [192, 4, 0, 255],
        [214, 59, 58, 255],
        [206, 141, 139, 255],
        [113, 3, 0, 255],
        [0, 0, 0, 0],],
       [[193, 59, 48, 192],
        [200, 81, 73, 255],
        [205, 109, 104, 255],
        [226, 159, 155, 255],
        [241, 207, 206, 255],
        [238, 180, 178, 255],
        [238, 182, 178, 255],
        [221, 131, 124, 255],
        [194, 40, 32, 255],
        [198, 8, 0, 255],
        [196, 4, 0, 255],
        [207, 30, 29, 255],
        [242, 149, 148, 255],
        [212, 117, 110, 255],
        [132, 3, 0, 244],
        [0, 0, 0, 0],],
       [[167, 9, 0, 204],
        [201, 123, 117, 255],
        [217, 91, 79, 255],
        [191, 18, 1, 255],
        [190, 92, 88, 255],
        [183, 87, 85, 255],
        [210, 7, 0, 255],
        [190, 48, 44, 255],
        [198, 65, 60, 255],
        [198, 32, 27, 255],
        [212, 81, 79, 255],
        [240, 171, 170, 255],
        [233, 93, 87, 255],
        [202, 64, 52, 255],
        [152, 4, 0, 204],
        [0, 0, 0, 0],],
       [[143, 3, 0, 204],
        [136, 59, 55, 255],
        [217, 90, 79, 255],
        [191, 18, 1, 255],
        [163, 49, 44, 255],
        [133, 32, 29, 255],
        [201, 38, 34, 255],
        [198, 5, 0, 255],
        [187, 4, 0, 255],
        [176, 4, 1, 255],
        [220, 172, 172, 255],
        [236, 146, 144, 255],
        [207, 49, 36, 255],
        [192, 19, 2, 255],
        [164, 4, 0, 204],
        [0, 0, 0, 0],],
       [[179, 5, 0, 204],
        [109, 3, 0, 255],
        [189, 63, 52, 255],
        [191, 18, 1, 255],
        [137, 11, 5, 255],
        [146, 4, 0, 255],
        [190, 33, 29, 255],
        [210, 41, 39, 255],
        [200, 46, 44, 255],
        [203, 117, 116, 255],
        [184, 47, 46, 255],
        [171, 31, 28, 255],
        [184, 27, 19, 255],
        [181, 11, 0, 255],
        [187, 6, 0, 160],
        [0, 0, 0, 0],],
       [[208, 6, 0, 139],
        [101, 3, 0, 255],
        [146, 26, 15, 255],
        [184, 16, 1, 255],
        [155, 4, 0, 255],
        [180, 4, 0, 255],
        [195, 4, 0, 255],
        [225, 91, 89, 255],
        [202, 78, 76, 255],
        [184, 8, 4, 255],
        [167, 4, 0, 255],
        [163, 5, 0, 255],
        [184, 6, 1, 255],
        [186, 6, 0, 255],
        [161, 3, 0, 163],
        [0, 0, 0, 6],],
       [[45, 0, 0, 78],
        [105, 2, 0, 223],
        [138, 4, 0, 255],
        [180, 10, 1, 255],
        [196, 68, 66, 255],
        [205, 80, 79, 255],
        [220, 97, 94, 254],
        [224, 84, 79, 241],
        [204, 42, 36, 236],
        [183, 15, 6, 235],
        [162, 11, 0, 224],
        [146, 6, 0, 216],
        [142, 3, 0, 214],
        [158, 3, 0, 202],
        [110, 1, 0, 154],
        [0, 0, 0, 39],],
       [[0, 0, 0, 9],
        [0, 0, 0, 35],
        [64, 0, 0, 68],
        [83, 0, 0, 96],
        [31, 0, 0, 90],
        [0, 0, 0, 93],
        [0, 0, 0, 94],
        [0, 0, 0, 94],
        [0, 0, 0, 94],
        [0, 0, 0, 89],
        [0, 0, 0, 80],
        [0, 0, 0, 67],
        [0, 0, 0, 51],
        [0, 0, 0, 31],
        [0, 0, 0, 12],
        [0, 0, 0, 1],],]
    }

    it "encodes tensor into an image" do
      image = tf.constant(image_data, dtype: :uint8)
      encoder = tf.image.encode_png(image)
      blob = sess.run(encoder)

      encoded_image = ChunkyPNG::Image.from_blob(blob)

      expect(encoded_image.pixels).to eq([0,
                                          0,
                                          0,
                                          0,
                                          0,
                                          0,
                                          2986541079,
                                          3540320381,
                                          3660590532,
                                          3882443212,
                                          3391954892,
                                          3138060502,
                                          2969895139,
                                          2483290303,
                                          2063728703,
                                          0,
                                          0,
                                          0,
                                          0,
                                          0,
                                          1946157057,
                                          3288858752,
                                          3624730869,
                                          3373400319,
                                          3222339839,
                                          3625454847,
                                          3664076031,
                                          3615456767,
                                          3125957119,
                                          2552767999,
                                          2030568693,
                                          1862336541,
                                          0,
                                          0,
                                          0,
                                          1979711498,
                                          3272343744,
                                          3473998079,
                                          3306357247,
                                          3239182847,
                                          3171877119,
                                          3850337023,
                                          3901523199,
                                          3529069311,
                                          2638759679,
                                          1661141247,
                                          1778581759,
                                          1946288229,
                                          0,
                                          0,
                                          1946157066,
                                          3121742786,
                                          3423732223,
                                          3357281279,
                                          3341294079,
                                          3188917247,
                                          3121545983,
                                          3934026239,
                                          3953039615,
                                          3560582911,
                                          3289911295,
                                          2333018879,
                                          2063859967,
                                          2080505958,
                                          0,
                                          0,
                                          2954234282,
                                          3475840767,
                                          3357149695,
                                          3392613119,
                                          3342281983,
                                          3223788799,
                                          3408800511,
                                          4224304895,
                                          4021530367,
                                          3713749759,
                                          3458209535,
                                          3138258175,
                                          2550464767,
                                          1862402125,
                                          0,
                                          2600796244,
                                          3324123135,
                                          3578609663,
                                          3255959807,
                                          3529199871,
                                          3377152767,
                                          3223394559,
                                          3935802623,
                                          3464724991,
                                          3630589183,
                                          3493410303,
                                          3121350399,
                                          2600730879,
                                          1845756415,
                                          1795227699,
                                          0,
                                          2902982871,
                                          3425839359,
                                          3579992063,
                                          3291753727,
                                          3733817343,
                                          3242014719,
                                          3648615935,
                                          3496436735,
                                          2768830719,
                                          2231566591,
                                          3154641919,
                                          3154379007,
                                          2684616959,
                                          1829702655,
                                          1946157107,
                                          2551715137,
                                          3121348863,
                                          3393272319,
                                          3580979711,
                                          3650326783,
                                          3531965183,
                                          3615587839,
                                          3715855615,
                                          3205497087,
                                          3003777279,
                                          2600665343,
                                          2970027007,
                                          3374786047,
                                          2821861631,
                                          1711999231,
                                          1946157072,
                                          3699999642,
                                          3071017215,
                                          3565651455,
                                          3938302719,
                                          4023110143,
                                          3954356479,
                                          4072519935,
                                          3460116991,
                                          3205497087,
                                          3137995007,
                                          3053715711,
                                          3221487871,
                                          3594205951,
                                          3465382911,
                                          1896022271,
                                          0,
                                          3241881792,
                                          3360770559,
                                          3446499583,
                                          3802110975,
                                          4056927999,
                                          4004819711,
                                          4004950783,
                                          3716381951,
                                          3257409791,
                                          3322413311,
                                          3288596735,
                                          3474857471,
                                          4069889279,
                                          3564465919,
                                          2214789364,
                                          0,
                                          2802385100,
                                          3380311551,
                                          3646640127,
                                          3205628415,
                                          3193723135,
                                          3075954175,
                                          3523674367,
                                          3190828287,
                                          3326164223,
                                          3323993087,
                                          3562098687,
                                          4037782271,
                                          3915208703,
                                          3393205503,
                                          2550399180,
                                          0,
                                          2399338700,
                                          2285582335,
                                          3646574591,
                                          3205628415,
                                          2737908991,
                                          2233474559,
                                          3374719743,
                                          3322216703,
                                          3137601791,
                                          2953052671,
                                          3702303999,
                                          3969028351,
                                          3476104447,
                                          3222471423,
                                          2751725772,
                                          0,
                                          3003449548,
                                          1828913407,
                                          3175036159,
                                          3205628415,
                                          2299201023,
                                          2449735935,
                                          3189841407,
                                          3525912575,
                                          3358469375,
                                          3413472511,
                                          3090099967,
                                          2870942975,
                                          3088782335,
                                          3037397247,
                                          3137732768,
                                          0,
                                          3490054283,
                                          1694695679,
                                          2451181567,
                                          3088056831,
                                          2600730879,
                                          3020161279,
                                          3271819519,
                                          3780860415,
                                          3394129151,
                                          3087533311,
                                          2802057471,
                                          2735014143,
                                          3087401471,
                                          3120955647,
                                          2701328547,
                                          6,
                                          754974798,
                                          1761738975,
                                          2315518207,
                                          3020554751,
                                          3292807935,
                                          3444592639,
                                          3697368830,
                                          3763621873,
                                          3425314028,
                                          3071215339,
                                          2718630112,
                                          2449866968,
                                          2382561494,
                                          2650996938,
                                          1845559450,
                                          39,
                                          9,
                                          35,
                                          1073741892,
                                          1392509024,
                                          520093786,
                                          93,
                                          94,
                                          94,
                                          94,
                                          89,
                                          80,
                                          67,
                                          51,
                                          31,
                                          12,
                                          1,])
    end

    specify "resampling" do
      image = tf.constant(image_data, dtype: :uint8)
      encoder = tf.image.encode_png(image, new_shape: [8, 8])
      blob = sess.run(encoder)
      encoded_image = ChunkyPNG::Image.from_blob(blob)
      expect([encoded_image.width, encoded_image.height]).to eq([8, 8])
    end
  end

  supported_op ".decode_jpg" do
    it "converts jpg file to a tensor" do
      image_1 = File.open( File.join("spec", "fixtures", "sample_jpeg.jpg"), 'rb') { |io| io.read }
      decoded_image = tf.image.decode_jpeg(image_1)
      expect(sess.run(tf.shape(decoded_image))).to eq([400, 600, 3])
    end

    it "converts b&w jpg file to a tensor" do
      image_1 = File.open( File.join("spec", "fixtures", "sample_jpeg_bw.jpg"), 'rb') { |io| io.read }
      decoded_image = tf.image.decode_jpeg(image_1)
      expect(sess.run(tf.shape(decoded_image))).to eq([225, 450, 3])
    end
  end
end
