go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

libwebp_linux_amd64.go (2167052B)


      1 // Code generated for linux/amd64 by 'ccgo --goos=linux --goarch=amd64 --package-name=webp -ignore-asm-errors -o /home/jfm/Source/Personal/go-libwebp/tools/../lib/transpiled/webp/libwebp_linux_amd64.go -DNDEBUG -DHAVE_CONFIG_H -I/tmp/tmp.jLmqxibQOP -I. src/dec/alpha_dec.c src/dec/buffer_dec.c src/dec/frame_dec.c src/dec/idec_dec.c src/dec/io_dec.c src/dec/quant_dec.c src/dec/tree_dec.c src/dec/vp8_dec.c src/dec/vp8l_dec.c src/dec/webp_dec.c src/enc/alpha_enc.c src/enc/analysis_enc.c src/enc/backward_references_cost_enc.c src/enc/backward_references_enc.c src/enc/config_enc.c src/enc/cost_enc.c src/enc/filter_enc.c src/enc/frame_enc.c src/enc/histogram_enc.c src/enc/iterator_enc.c src/enc/near_lossless_enc.c src/enc/picture_csp_enc.c src/enc/picture_enc.c src/enc/picture_psnr_enc.c src/enc/picture_rescale_enc.c src/enc/picture_tools_enc.c src/enc/predictor_enc.c src/enc/quant_enc.c src/enc/syntax_enc.c src/enc/token_enc.c src/enc/tree_enc.c src/enc/vp8l_enc.c src/enc/webp_enc.c src/utils/bit_reader_utils.c src/utils/bit_writer_utils.c src/utils/color_cache_utils.c src/utils/filters_utils.c src/utils/huffman_encode_utils.c src/utils/huffman_utils.c src/utils/palette.c src/utils/quant_levels_dec_utils.c src/utils/quant_levels_utils.c src/utils/random_utils.c src/utils/rescaler_utils.c src/utils/thread_utils.c src/utils/utils.c src/dsp/alpha_processing.c src/dsp/alpha_processing_mips_dsp_r2.c src/dsp/alpha_processing_neon.c src/dsp/alpha_processing_sse2.c src/dsp/alpha_processing_sse41.c src/dsp/cost.c src/dsp/cost_mips32.c src/dsp/cost_mips_dsp_r2.c src/dsp/cost_neon.c src/dsp/cost_sse2.c src/dsp/cpu.c src/dsp/dec.c src/dsp/dec_clip_tables.c src/dsp/dec_mips32.c src/dsp/dec_mips_dsp_r2.c src/dsp/dec_msa.c src/dsp/dec_neon.c src/dsp/dec_sse2.c src/dsp/dec_sse41.c src/dsp/enc.c src/dsp/enc_mips32.c src/dsp/enc_mips_dsp_r2.c src/dsp/enc_msa.c src/dsp/enc_neon.c src/dsp/enc_sse2.c src/dsp/enc_sse41.c src/dsp/filters.c src/dsp/filters_mips_dsp_r2.c src/dsp/filters_msa.c src/dsp/filters_neon.c src/dsp/filters_sse2.c src/dsp/lossless_avx2.c src/dsp/lossless.c src/dsp/lossless_enc_avx2.c src/dsp/lossless_enc.c src/dsp/lossless_enc_mips32.c src/dsp/lossless_enc_mips_dsp_r2.c src/dsp/lossless_enc_msa.c src/dsp/lossless_enc_neon.c src/dsp/lossless_enc_sse2.c src/dsp/lossless_enc_sse41.c src/dsp/lossless_mips_dsp_r2.c src/dsp/lossless_msa.c src/dsp/lossless_neon.c src/dsp/lossless_sse2.c src/dsp/lossless_sse41.c src/dsp/rescaler.c src/dsp/rescaler_mips32.c src/dsp/rescaler_mips_dsp_r2.c src/dsp/rescaler_msa.c src/dsp/rescaler_neon.c src/dsp/rescaler_sse2.c src/dsp/ssim.c src/dsp/ssim_sse2.c src/dsp/upsampling.c src/dsp/upsampling_mips_dsp_r2.c src/dsp/upsampling_msa.c src/dsp/upsampling_neon.c src/dsp/upsampling_sse2.c src/dsp/upsampling_sse41.c src/dsp/yuv.c src/dsp/yuv_mips32.c src/dsp/yuv_mips_dsp_r2.c src/dsp/yuv_neon.c src/dsp/yuv_sse2.c src/dsp/yuv_sse41.c /home/jfm/Source/Personal/go-libwebp/tools/sharpyuv_stub.c', DO NOT EDIT.
      2 
      3 //go:build linux && amd64
      4 
      5 package webp
      6 
      7 import (
      8 	"math"
      9 	"reflect"
     10 	"unsafe"
     11 
     12 	"modernc.org/libc"
     13 )
     14 
     15 var _ = math.Pi
     16 var _ reflect.Type
     17 var _ unsafe.Pointer
     18 
     19 const ALPHA_HEADER_LEN = 1
     20 const ALPHA_LOSSLESS_COMPRESSION = 1
     21 const ALPHA_NO_COMPRESSION = 0
     22 const ALPHA_PREPROCESSED_LEVELS = 1
     23 const ANIM_CHUNK_SIZE = 6
     24 const ANMF_CHUNK_SIZE = 16
     25 const ARGB_BLACK = 0xff000000
     26 const BITS = 56
     27 const BITTRACE = 0
     28 const BPS = 32
     29 const CHUNK_HEADER_SIZE = 8
     30 const CHUNK_SIZE_BYTES = 4
     31 const CODE_LENGTH_CODES = 19
     32 const DEC_MAJ_VERSION = 1
     33 const DEC_MIN_VERSION = 6
     34 const DEC_REV_VERSION = 0
     35 const DEFAULT_CODE_LENGTH = 8
     36 const EXIT_FAILURE = 1
     37 const EXIT_SUCCESS = 0
     38 const HAVE_BUILTIN_BSWAP16 = 1
     39 const HAVE_BUILTIN_BSWAP32 = 1
     40 const HAVE_BUILTIN_BSWAP64 = 1
     41 const HAVE_CONFIG_H = 1
     42 const HUFFMAN_CODES_PER_META_CODE = 5
     43 const HUFFMAN_PACKED_BITS = 6
     44 const HUFFMAN_TABLE_BITS = 8
     45 const INT16_MAX = 0x7fff
     46 const INT32_MAX = 0x7fffffff
     47 const INT64_MAX = 0x7fffffffffffffff
     48 const INT8_MAX = 0x7f
     49 const INTMAX_MAX = "INT64_MAX"
     50 const INTMAX_MIN = "INT64_MIN"
     51 const INTPTR_MAX = "INT64_MAX"
     52 const INTPTR_MIN = "INT64_MIN"
     53 const INT_FAST16_MAX = "INT32_MAX"
     54 const INT_FAST16_MIN = "INT32_MIN"
     55 const INT_FAST32_MAX = "INT32_MAX"
     56 const INT_FAST32_MIN = "INT32_MIN"
     57 const INT_FAST64_MAX = "INT64_MAX"
     58 const INT_FAST64_MIN = "INT64_MIN"
     59 const INT_FAST8_MAX = "INT8_MAX"
     60 const INT_FAST8_MIN = "INT8_MIN"
     61 const INT_LEAST16_MAX = "INT16_MAX"
     62 const INT_LEAST16_MIN = "INT16_MIN"
     63 const INT_LEAST32_MAX = "INT32_MAX"
     64 const INT_LEAST32_MIN = "INT32_MIN"
     65 const INT_LEAST64_MAX = "INT64_MAX"
     66 const INT_LEAST64_MIN = "INT64_MIN"
     67 const INT_LEAST8_MAX = "INT8_MAX"
     68 const INT_LEAST8_MIN = "INT8_MIN"
     69 const LENGTHS_TABLE_BITS = 7
     70 const LOCAL_CLANG_VERSION = 0
     71 const MAX_ALLOWED_CODE_LENGTH = 15
     72 const MAX_CACHE_BITS = 11
     73 const MAX_COEFF_THRESH = 31
     74 const MAX_PALETTE_SIZE = 256
     75 const MIN_HUFFMAN_BITS = 2
     76 const MIN_TRANSFORM_BITS = 2
     77 const MIN_WIDTH_FOR_THREADS = 512
     78 const NDEBUG = 1
     79 const NUM_DISTANCE_CODES = 40
     80 const NUM_HUFFMAN_BITS = 3
     81 const NUM_LENGTH_CODES = 24
     82 const NUM_LITERAL_CODES = 256
     83 const NUM_TRANSFORMS = 4
     84 const NUM_TRANSFORM_BITS = 3
     85 const PRIX16 = "X"
     86 const PRIX32 = "X"
     87 const PRIX8 = "X"
     88 const PRIXFAST16 = "X"
     89 const PRIXFAST32 = "X"
     90 const PRIXFAST8 = "X"
     91 const PRIXLEAST16 = "X"
     92 const PRIXLEAST32 = "X"
     93 const PRIXLEAST8 = "X"
     94 const PRId16 = "d"
     95 const PRId32 = "d"
     96 const PRId8 = "d"
     97 const PRIdFAST16 = "d"
     98 const PRIdFAST32 = "d"
     99 const PRIdFAST8 = "d"
    100 const PRIdLEAST16 = "d"
    101 const PRIdLEAST32 = "d"
    102 const PRIdLEAST8 = "d"
    103 const PRIi16 = "i"
    104 const PRIi32 = "i"
    105 const PRIi8 = "i"
    106 const PRIiFAST16 = "i"
    107 const PRIiFAST32 = "i"
    108 const PRIiFAST8 = "i"
    109 const PRIiLEAST16 = "i"
    110 const PRIiLEAST32 = "i"
    111 const PRIiLEAST8 = "i"
    112 const PRIo16 = "o"
    113 const PRIo32 = "o"
    114 const PRIo8 = "o"
    115 const PRIoFAST16 = "o"
    116 const PRIoFAST32 = "o"
    117 const PRIoFAST8 = "o"
    118 const PRIoLEAST16 = "o"
    119 const PRIoLEAST32 = "o"
    120 const PRIoLEAST8 = "o"
    121 const PRIu16 = "u"
    122 const PRIu32 = "u"
    123 const PRIu8 = "u"
    124 const PRIuFAST16 = "u"
    125 const PRIuFAST32 = "u"
    126 const PRIuFAST8 = "u"
    127 const PRIuLEAST16 = "u"
    128 const PRIuLEAST32 = "u"
    129 const PRIuLEAST8 = "u"
    130 const PRIx16 = "x"
    131 const PRIx32 = "x"
    132 const PRIx8 = "x"
    133 const PRIxFAST16 = "x"
    134 const PRIxFAST32 = "x"
    135 const PRIxFAST8 = "x"
    136 const PRIxLEAST16 = "x"
    137 const PRIxLEAST32 = "x"
    138 const PRIxLEAST8 = "x"
    139 const PTRDIFF_MAX = "INT64_MAX"
    140 const PTRDIFF_MIN = "INT64_MIN"
    141 const RAND_MAX = 0x7fffffff
    142 const RIFF_HEADER_SIZE = 12
    143 const SCNd16 = "hd"
    144 const SCNd32 = "d"
    145 const SCNd8 = "hhd"
    146 const SCNdFAST16 = "d"
    147 const SCNdFAST32 = "d"
    148 const SCNdFAST8 = "hhd"
    149 const SCNdLEAST16 = "hd"
    150 const SCNdLEAST32 = "d"
    151 const SCNdLEAST8 = "hhd"
    152 const SCNi16 = "hi"
    153 const SCNi32 = "i"
    154 const SCNi8 = "hhi"
    155 const SCNiFAST16 = "i"
    156 const SCNiFAST32 = "i"
    157 const SCNiFAST8 = "hhi"
    158 const SCNiLEAST16 = "hi"
    159 const SCNiLEAST32 = "i"
    160 const SCNiLEAST8 = "hhi"
    161 const SCNo16 = "ho"
    162 const SCNo32 = "o"
    163 const SCNo8 = "hho"
    164 const SCNoFAST16 = "o"
    165 const SCNoFAST32 = "o"
    166 const SCNoFAST8 = "hho"
    167 const SCNoLEAST16 = "ho"
    168 const SCNoLEAST32 = "o"
    169 const SCNoLEAST8 = "hho"
    170 const SCNu16 = "hu"
    171 const SCNu32 = "u"
    172 const SCNu8 = "hhu"
    173 const SCNuFAST16 = "u"
    174 const SCNuFAST32 = "u"
    175 const SCNuFAST8 = "hhu"
    176 const SCNuLEAST16 = "hu"
    177 const SCNuLEAST32 = "u"
    178 const SCNuLEAST8 = "hhu"
    179 const SCNx16 = "hx"
    180 const SCNx32 = "x"
    181 const SCNx8 = "hhx"
    182 const SCNxFAST16 = "x"
    183 const SCNxFAST32 = "x"
    184 const SCNxFAST8 = "hhx"
    185 const SCNxLEAST16 = "hx"
    186 const SCNxLEAST32 = "x"
    187 const SCNxLEAST8 = "hhx"
    188 const SIG_ATOMIC_MAX = "INT32_MAX"
    189 const SIG_ATOMIC_MIN = "INT32_MIN"
    190 const SIZE_MAX = "UINT64_MAX"
    191 const TAG_SIZE = 4
    192 const TRANSFORM_PRESENT = 1
    193 const UINT16_MAX = 0xffff
    194 const UINT32_MAX = "0xffffffffu"
    195 const UINT64_MAX = "0xffffffffffffffffu"
    196 const UINT8_MAX = 0xff
    197 const UINTMAX_MAX = "UINT64_MAX"
    198 const UINTPTR_MAX = "UINT64_MAX"
    199 const UINT_FAST16_MAX = "UINT32_MAX"
    200 const UINT_FAST32_MAX = "UINT32_MAX"
    201 const UINT_FAST64_MAX = "UINT64_MAX"
    202 const UINT_FAST8_MAX = "UINT8_MAX"
    203 const UINT_LEAST16_MAX = "UINT16_MAX"
    204 const UINT_LEAST32_MAX = "UINT32_MAX"
    205 const UINT_LEAST64_MAX = "UINT64_MAX"
    206 const UINT_LEAST8_MAX = "UINT8_MAX"
    207 const VP8L_FRAME_HEADER_SIZE = 5
    208 const VP8L_IMAGE_SIZE_BITS = 14
    209 const VP8L_LBITS = 64
    210 const VP8L_MAGIC_BYTE = 0x2f
    211 const VP8L_MAX_NUM_BIT_READ = 24
    212 const VP8L_SIGNATURE_SIZE = 1
    213 const VP8L_VERSION = 0
    214 const VP8L_VERSION_BITS = 3
    215 const VP8L_WBITS = 32
    216 const VP8X_CHUNK_SIZE = 10
    217 const VP8_DITHER_AMP_BITS = 7
    218 const VP8_DITHER_DESCALE = 4
    219 const VP8_FRAME_HEADER_SIZE = 10
    220 const VP8_RANDOM_DITHER_FIX = 8
    221 const VP8_RANDOM_TABLE_SIZE = 55
    222 const VP8_SIGNATURE = 0x9d012a
    223 const VP8_SSIM_KERNEL = 3
    224 const WEBP_AARCH64 = 0
    225 const WEBP_ALIGN_CST = 31
    226 const WEBP_DECODER_ABI_VERSION = 528
    227 const WEBP_DSP_OMIT_C_CODE = 1
    228 const WEBP_INLINE = "inline"
    229 const WEBP_NEON_OMIT_C_CODE = 0
    230 const WEBP_NEON_WORK_AROUND_GCC = 0
    231 const WEBP_RESCALER_RFIX = 32
    232 const WEBP_RESTRICT = "__restrict__"
    233 const WEBP_SWAP_16BIT_CSP = 0
    234 const WEBP_TRANSFORM_AC3_C1 = 20091
    235 const WEBP_TRANSFORM_AC3_C2 = 35468
    236 const WINT_MAX = "UINT32_MAX"
    237 const WINT_MIN = 0
    238 const WNOHANG = 1
    239 const WUNTRACED = 2
    240 const _GNU_SOURCE = 1
    241 const _LP64 = 1
    242 const _STDC_PREDEF_H = 1
    243 const __ATOMIC_ACQUIRE = 2
    244 const __ATOMIC_ACQ_REL = 4
    245 const __ATOMIC_CONSUME = 1
    246 const __ATOMIC_HLE_ACQUIRE = 65536
    247 const __ATOMIC_HLE_RELEASE = 131072
    248 const __ATOMIC_RELAXED = 0
    249 const __ATOMIC_RELEASE = 3
    250 const __ATOMIC_SEQ_CST = 5
    251 const __BFLT16_DECIMAL_DIG__ = 4
    252 const __BFLT16_DENORM_MIN__ = "9.18354961579912115600575419704879436e-41B"
    253 const __BFLT16_DIG__ = 2
    254 const __BFLT16_EPSILON__ = "7.81250000000000000000000000000000000e-3B"
    255 const __BFLT16_HAS_DENORM__ = 1
    256 const __BFLT16_HAS_INFINITY__ = 1
    257 const __BFLT16_HAS_QUIET_NAN__ = 1
    258 const __BFLT16_IS_IEC_60559__ = 0
    259 const __BFLT16_MANT_DIG__ = 8
    260 const __BFLT16_MAX_10_EXP__ = 38
    261 const __BFLT16_MAX_EXP__ = 128
    262 const __BFLT16_MAX__ = "3.38953138925153547590470800371487867e+38B"
    263 const __BFLT16_MIN__ = "1.17549435082228750796873653722224568e-38B"
    264 const __BFLT16_NORM_MAX__ = "3.38953138925153547590470800371487867e+38B"
    265 const __BIGGEST_ALIGNMENT__ = 16
    266 const __BIG_ENDIAN = 4321
    267 const __BITINT_MAXWIDTH__ = 65535
    268 const __BYTE_ORDER = 1234
    269 const __BYTE_ORDER__ = "__ORDER_LITTLE_ENDIAN__"
    270 const __CCGO__ = 1
    271 const __CHAR_BIT__ = 8
    272 const __DBL_DECIMAL_DIG__ = 17
    273 const __DBL_DIG__ = 15
    274 const __DBL_HAS_DENORM__ = 1
    275 const __DBL_HAS_INFINITY__ = 1
    276 const __DBL_HAS_QUIET_NAN__ = 1
    277 const __DBL_IS_IEC_60559__ = 1
    278 const __DBL_MANT_DIG__ = 53
    279 const __DBL_MAX_10_EXP__ = 308
    280 const __DBL_MAX_EXP__ = 1024
    281 const __DEC128_EPSILON__ = 1e-33
    282 const __DEC128_MANT_DIG__ = 34
    283 const __DEC128_MAX_EXP__ = 6145
    284 const __DEC128_MAX__ = "9.999999999999999999999999999999999E6144"
    285 const __DEC128_MIN__ = 1e-6143
    286 const __DEC128_SUBNORMAL_MIN__ = 0.000000000000000000000000000000001e-6143
    287 const __DEC32_EPSILON__ = 1e-6
    288 const __DEC32_MANT_DIG__ = 7
    289 const __DEC32_MAX_EXP__ = 97
    290 const __DEC32_MAX__ = 9.999999e96
    291 const __DEC32_MIN__ = 1e-95
    292 const __DEC32_SUBNORMAL_MIN__ = 0.000001e-95
    293 const __DEC64X_EPSILON__ = "1E-33D64x"
    294 const __DEC64X_MANT_DIG__ = 34
    295 const __DEC64X_MAX_EXP__ = 6145
    296 const __DEC64X_MAX__ = "9.999999999999999999999999999999999E6144D64x"
    297 const __DEC64X_MIN__ = "1E-6143D64x"
    298 const __DEC64X_SUBNORMAL_MIN__ = "0.000000000000000000000000000000001E-6143D64x"
    299 const __DEC64_EPSILON__ = 1e-15
    300 const __DEC64_MANT_DIG__ = 16
    301 const __DEC64_MAX_EXP__ = 385
    302 const __DEC64_MAX__ = "9.999999999999999E384"
    303 const __DEC64_MIN__ = 1e-383
    304 const __DEC64_SUBNORMAL_MIN__ = 0.000000000000001e-383
    305 const __DECIMAL_BID_FORMAT__ = 1
    306 const __DECIMAL_DIG__ = 17
    307 const __DEC_EVAL_METHOD__ = 2
    308 const __ELF__ = 1
    309 const __FINITE_MATH_ONLY__ = 0
    310 const __FLOAT_WORD_ORDER__ = "__ORDER_LITTLE_ENDIAN__"
    311 const __FLT128_DECIMAL_DIG__ = 36
    312 const __FLT128_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    313 const __FLT128_DIG__ = 33
    314 const __FLT128_EPSILON__ = 1.92592994438723585305597794258492732e-34
    315 const __FLT128_HAS_DENORM__ = 1
    316 const __FLT128_HAS_INFINITY__ = 1
    317 const __FLT128_HAS_QUIET_NAN__ = 1
    318 const __FLT128_IS_IEC_60559__ = 1
    319 const __FLT128_MANT_DIG__ = 113
    320 const __FLT128_MAX_10_EXP__ = 4932
    321 const __FLT128_MAX_EXP__ = 16384
    322 const __FLT128_MAX__ = "1.18973149535723176508575932662800702e+4932"
    323 const __FLT128_MIN__ = 3.36210314311209350626267781732175260e-4932
    324 const __FLT128_NORM_MAX__ = "1.18973149535723176508575932662800702e+4932"
    325 const __FLT16_DECIMAL_DIG__ = 5
    326 const __FLT16_DENORM_MIN__ = 5.96046447753906250000000000000000000e-8
    327 const __FLT16_DIG__ = 3
    328 const __FLT16_EPSILON__ = 9.76562500000000000000000000000000000e-4
    329 const __FLT16_HAS_DENORM__ = 1
    330 const __FLT16_HAS_INFINITY__ = 1
    331 const __FLT16_HAS_QUIET_NAN__ = 1
    332 const __FLT16_IS_IEC_60559__ = 1
    333 const __FLT16_MANT_DIG__ = 11
    334 const __FLT16_MAX_10_EXP__ = 4
    335 const __FLT16_MAX_EXP__ = 16
    336 const __FLT16_MAX__ = 6.55040000000000000000000000000000000e+4
    337 const __FLT16_MIN__ = 6.10351562500000000000000000000000000e-5
    338 const __FLT16_NORM_MAX__ = 6.55040000000000000000000000000000000e+4
    339 const __FLT32X_DECIMAL_DIG__ = 17
    340 const __FLT32X_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    341 const __FLT32X_DIG__ = 15
    342 const __FLT32X_EPSILON__ = 2.22044604925031308084726333618164062e-16
    343 const __FLT32X_HAS_DENORM__ = 1
    344 const __FLT32X_HAS_INFINITY__ = 1
    345 const __FLT32X_HAS_QUIET_NAN__ = 1
    346 const __FLT32X_IS_IEC_60559__ = 1
    347 const __FLT32X_MANT_DIG__ = 53
    348 const __FLT32X_MAX_10_EXP__ = 308
    349 const __FLT32X_MAX_EXP__ = 1024
    350 const __FLT32X_MAX__ = 1.79769313486231570814527423731704357e+308
    351 const __FLT32X_MIN__ = 2.22507385850720138309023271733240406e-308
    352 const __FLT32X_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    353 const __FLT32_DECIMAL_DIG__ = 9
    354 const __FLT32_DENORM_MIN__ = 1.40129846432481707092372958328991613e-45
    355 const __FLT32_DIG__ = 6
    356 const __FLT32_EPSILON__ = 1.19209289550781250000000000000000000e-7
    357 const __FLT32_HAS_DENORM__ = 1
    358 const __FLT32_HAS_INFINITY__ = 1
    359 const __FLT32_HAS_QUIET_NAN__ = 1
    360 const __FLT32_IS_IEC_60559__ = 1
    361 const __FLT32_MANT_DIG__ = 24
    362 const __FLT32_MAX_10_EXP__ = 38
    363 const __FLT32_MAX_EXP__ = 128
    364 const __FLT32_MAX__ = 3.40282346638528859811704183484516925e+38
    365 const __FLT32_MIN__ = 1.17549435082228750796873653722224568e-38
    366 const __FLT32_NORM_MAX__ = 3.40282346638528859811704183484516925e+38
    367 const __FLT64X_DECIMAL_DIG__ = 36
    368 const __FLT64X_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    369 const __FLT64X_DIG__ = 33
    370 const __FLT64X_EPSILON__ = 1.92592994438723585305597794258492732e-34
    371 const __FLT64X_HAS_DENORM__ = 1
    372 const __FLT64X_HAS_INFINITY__ = 1
    373 const __FLT64X_HAS_QUIET_NAN__ = 1
    374 const __FLT64X_IS_IEC_60559__ = 1
    375 const __FLT64X_MANT_DIG__ = 113
    376 const __FLT64X_MAX_10_EXP__ = 4932
    377 const __FLT64X_MAX_EXP__ = 16384
    378 const __FLT64X_MAX__ = "1.18973149535723176508575932662800702e+4932"
    379 const __FLT64X_MIN__ = 3.36210314311209350626267781732175260e-4932
    380 const __FLT64X_NORM_MAX__ = "1.18973149535723176508575932662800702e+4932"
    381 const __FLT64_DECIMAL_DIG__ = 17
    382 const __FLT64_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    383 const __FLT64_DIG__ = 15
    384 const __FLT64_EPSILON__ = 2.22044604925031308084726333618164062e-16
    385 const __FLT64_HAS_DENORM__ = 1
    386 const __FLT64_HAS_INFINITY__ = 1
    387 const __FLT64_HAS_QUIET_NAN__ = 1
    388 const __FLT64_IS_IEC_60559__ = 1
    389 const __FLT64_MANT_DIG__ = 53
    390 const __FLT64_MAX_10_EXP__ = 308
    391 const __FLT64_MAX_EXP__ = 1024
    392 const __FLT64_MAX__ = 1.79769313486231570814527423731704357e+308
    393 const __FLT64_MIN__ = 2.22507385850720138309023271733240406e-308
    394 const __FLT64_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    395 const __FLT_DECIMAL_DIG__ = 9
    396 const __FLT_DENORM_MIN__ = 1.40129846432481707092372958328991613e-45
    397 const __FLT_DIG__ = 6
    398 const __FLT_EPSILON__ = 1.19209289550781250000000000000000000e-7
    399 const __FLT_EVAL_METHOD_TS_18661_3__ = 0
    400 const __FLT_EVAL_METHOD__ = 0
    401 const __FLT_HAS_DENORM__ = 1
    402 const __FLT_HAS_INFINITY__ = 1
    403 const __FLT_HAS_QUIET_NAN__ = 1
    404 const __FLT_IS_IEC_60559__ = 1
    405 const __FLT_MANT_DIG__ = 24
    406 const __FLT_MAX_10_EXP__ = 38
    407 const __FLT_MAX_EXP__ = 128
    408 const __FLT_MAX__ = 3.40282346638528859811704183484516925e+38
    409 const __FLT_MIN__ = 1.17549435082228750796873653722224568e-38
    410 const __FLT_NORM_MAX__ = 3.40282346638528859811704183484516925e+38
    411 const __FLT_RADIX__ = 2
    412 const __FUNCTION__ = "__func__"
    413 const __FXSR__ = 1
    414 const __GCC_ASM_FLAG_OUTPUTS__ = 1
    415 const __GCC_ATOMIC_BOOL_LOCK_FREE = 2
    416 const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2
    417 const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2
    418 const __GCC_ATOMIC_CHAR8_T_LOCK_FREE = 2
    419 const __GCC_ATOMIC_CHAR_LOCK_FREE = 2
    420 const __GCC_ATOMIC_INT_LOCK_FREE = 2
    421 const __GCC_ATOMIC_LLONG_LOCK_FREE = 2
    422 const __GCC_ATOMIC_LONG_LOCK_FREE = 2
    423 const __GCC_ATOMIC_POINTER_LOCK_FREE = 2
    424 const __GCC_ATOMIC_SHORT_LOCK_FREE = 2
    425 const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1
    426 const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2
    427 const __GCC_CONSTRUCTIVE_SIZE = 64
    428 const __GCC_DESTRUCTIVE_SIZE = 64
    429 const __GCC_HAVE_DWARF2_CFI_ASM = 1
    430 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1
    431 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1
    432 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1
    433 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1
    434 const __GCC_IEC_559 = 2
    435 const __GCC_IEC_559_COMPLEX = 2
    436 const __GNUC_EXECUTION_CHARSET_NAME = "UTF-8"
    437 const __GNUC_MINOR__ = 2
    438 const __GNUC_PATCHLEVEL__ = 1
    439 const __GNUC_STDC_INLINE__ = 1
    440 const __GNUC_WIDE_EXECUTION_CHARSET_NAME = "UTF-32LE"
    441 const __GNUC__ = 16
    442 const __GXX_ABI_VERSION = 1021
    443 const __HAVE_SPECULATION_SAFE_VALUE = 1
    444 const __INT16_MAX__ = 0x7fff
    445 const __INT32_MAX__ = 0x7fffffff
    446 const __INT32_TYPE__ = "int"
    447 const __INT64_MAX__ = 0x7fffffffffffffff
    448 const __INT8_MAX__ = 0x7f
    449 const __INTMAX_MAX__ = 0x7fffffffffffffff
    450 const __INTMAX_WIDTH__ = 64
    451 const __INTPTR_MAX__ = 0x7fffffffffffffff
    452 const __INTPTR_WIDTH__ = 64
    453 const __INT_FAST16_MAX__ = 0x7fffffffffffffff
    454 const __INT_FAST16_WIDTH__ = 64
    455 const __INT_FAST32_MAX__ = 0x7fffffffffffffff
    456 const __INT_FAST32_WIDTH__ = 64
    457 const __INT_FAST64_MAX__ = 0x7fffffffffffffff
    458 const __INT_FAST64_WIDTH__ = 64
    459 const __INT_FAST8_MAX__ = 0x7f
    460 const __INT_FAST8_WIDTH__ = 8
    461 const __INT_LEAST16_MAX__ = 0x7fff
    462 const __INT_LEAST16_WIDTH__ = 16
    463 const __INT_LEAST32_MAX__ = 0x7fffffff
    464 const __INT_LEAST32_TYPE__ = "int"
    465 const __INT_LEAST32_WIDTH__ = 32
    466 const __INT_LEAST64_MAX__ = 0x7fffffffffffffff
    467 const __INT_LEAST64_WIDTH__ = 64
    468 const __INT_LEAST8_MAX__ = 0x7f
    469 const __INT_LEAST8_WIDTH__ = 8
    470 const __INT_MAX__ = 0x7fffffff
    471 const __INT_WIDTH__ = 32
    472 const __LDBL_DECIMAL_DIG__ = 17
    473 const __LDBL_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    474 const __LDBL_DIG__ = 15
    475 const __LDBL_EPSILON__ = 2.22044604925031308084726333618164062e-16
    476 const __LDBL_HAS_DENORM__ = 1
    477 const __LDBL_HAS_INFINITY__ = 1
    478 const __LDBL_HAS_QUIET_NAN__ = 1
    479 const __LDBL_IS_IEC_60559__ = 1
    480 const __LDBL_MANT_DIG__ = 53
    481 const __LDBL_MAX_10_EXP__ = 308
    482 const __LDBL_MAX_EXP__ = 1024
    483 const __LDBL_MAX__ = 1.79769313486231570814527423731704357e+308
    484 const __LDBL_MIN__ = 2.22507385850720138309023271733240406e-308
    485 const __LDBL_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    486 const __LITTLE_ENDIAN = 1234
    487 const __LONG_DOUBLE_64__ = 1
    488 const __LONG_LONG_MAX__ = 0x7fffffffffffffff
    489 const __LONG_LONG_WIDTH__ = 64
    490 const __LONG_MAX = 0x7fffffffffffffff
    491 const __LONG_MAX__ = 0x7fffffffffffffff
    492 const __LONG_WIDTH__ = 64
    493 const __LP64__ = 1
    494 const __MMX_WITH_SSE__ = 1
    495 const __MMX__ = 1
    496 const __NO_INLINE__ = 1
    497 const __ORDER_BIG_ENDIAN__ = 4321
    498 const __ORDER_LITTLE_ENDIAN__ = 1234
    499 const __ORDER_PDP_ENDIAN__ = 3412
    500 const __PIC__ = 2
    501 const __PIE__ = 2
    502 const __PRAGMA_REDEFINE_EXTNAME = 1
    503 const __PRETTY_FUNCTION__ = "__func__"
    504 const __PRI64 = "l"
    505 const __PRIPTR = "l"
    506 const __PTRDIFF_MAX__ = 0x7fffffffffffffff
    507 const __PTRDIFF_WIDTH__ = 64
    508 const __SCHAR_MAX__ = 0x7f
    509 const __SCHAR_WIDTH__ = 8
    510 const __SEG_FS = 1
    511 const __SEG_GS = 1
    512 const __SHRT_MAX__ = 0x7fff
    513 const __SHRT_WIDTH__ = 16
    514 const __SIG_ATOMIC_MAX__ = 0x7fffffff
    515 const __SIG_ATOMIC_TYPE__ = "int"
    516 const __SIG_ATOMIC_WIDTH__ = 32
    517 const __SIZEOF_DOUBLE__ = 8
    518 const __SIZEOF_FLOAT128__ = 16
    519 const __SIZEOF_FLOAT80__ = 16
    520 const __SIZEOF_FLOAT__ = 4
    521 const __SIZEOF_INT128__ = 16
    522 const __SIZEOF_INT__ = 4
    523 const __SIZEOF_LONG_DOUBLE__ = 8
    524 const __SIZEOF_LONG_LONG__ = 8
    525 const __SIZEOF_LONG__ = 8
    526 const __SIZEOF_POINTER__ = 8
    527 const __SIZEOF_PTRDIFF_T__ = 8
    528 const __SIZEOF_SHORT__ = 2
    529 const __SIZEOF_SIZE_T__ = 8
    530 const __SIZEOF_WCHAR_T__ = 4
    531 const __SIZEOF_WINT_T__ = 4
    532 const __SIZE_MAX__ = 0xffffffffffffffff
    533 const __SIZE_WIDTH__ = 64
    534 const __SSE2_MATH__ = 1
    535 const __SSE2__ = 1
    536 const __SSE_MATH__ = 1
    537 const __SSE__ = 1
    538 const __SSP_STRONG__ = 3
    539 const __STDC_EMBED_EMPTY__ = 2
    540 const __STDC_EMBED_FOUND__ = 1
    541 const __STDC_EMBED_NOT_FOUND__ = 0
    542 const __STDC_HOSTED__ = 1
    543 const __STDC_IEC_559_COMPLEX__ = 1
    544 const __STDC_IEC_559__ = 1
    545 const __STDC_IEC_60559_BFP__ = 201404
    546 const __STDC_IEC_60559_COMPLEX__ = 201404
    547 const __STDC_ISO_10646__ = 201706
    548 const __STDC_UTF_16__ = 1
    549 const __STDC_UTF_32__ = 1
    550 const __STDC_VERSION__ = 202311
    551 const __STDC__ = 1
    552 const __UINT16_MAX__ = 0xffff
    553 const __UINT32_MAX__ = 0xffffffff
    554 const __UINT64_MAX__ = 0xffffffffffffffff
    555 const __UINT8_MAX__ = 0xff
    556 const __UINTMAX_MAX__ = 0xffffffffffffffff
    557 const __UINTPTR_MAX__ = 0xffffffffffffffff
    558 const __UINT_FAST16_MAX__ = 0xffffffffffffffff
    559 const __UINT_FAST32_MAX__ = 0xffffffffffffffff
    560 const __UINT_FAST64_MAX__ = 0xffffffffffffffff
    561 const __UINT_FAST8_MAX__ = 0xff
    562 const __UINT_LEAST16_MAX__ = 0xffff
    563 const __UINT_LEAST32_MAX__ = 0xffffffff
    564 const __UINT_LEAST64_MAX__ = 0xffffffffffffffff
    565 const __UINT_LEAST8_MAX__ = 0xff
    566 const __USE_TIME_BITS64 = 1
    567 const __VERSION__ = "16.2.1 20260810"
    568 const __WCHAR_MAX__ = 0x7fffffff
    569 const __WCHAR_TYPE__ = "int"
    570 const __WCHAR_WIDTH__ = 32
    571 const __WINT_MAX__ = 0xffffffff
    572 const __WINT_MIN__ = 0
    573 const __WINT_WIDTH__ = 32
    574 const __amd64 = 1
    575 const __amd64__ = 1
    576 const __code_model_small__ = 1
    577 const __gnu_linux__ = 1
    578 const __inline = "inline"
    579 const __k8 = 1
    580 const __k8__ = 1
    581 const __linux = 1
    582 const __linux__ = 1
    583 const __pic__ = 2
    584 const __pie__ = 2
    585 const __restrict = "restrict"
    586 const __restrict_arr = "restrict"
    587 const __unix = 1
    588 const __unix__ = 1
    589 const __x86_64 = 1
    590 const __x86_64__ = 1
    591 const alloca1 = "__builtin_alloca"
    592 const false1 = 0
    593 const linux = 1
    594 const static_assert = "_Static_assert"
    595 const true1 = 1
    596 const unix = 1
    597 
    598 /* C23 keywords, no longer defined as macros by <stdbool.h> and <stddef.h>. */
    599 
    600 type __builtin_va_list = uintptr
    601 
    602 type __predefined_size_t = uint64
    603 
    604 type __predefined_wchar_t = int32
    605 
    606 type __predefined_ptrdiff_t = int64
    607 
    608 type wchar_t = int32
    609 
    610 type size_t = uint64
    611 
    612 type div_t = struct {
    613 	Fquot int32
    614 	Frem  int32
    615 }
    616 
    617 type ldiv_t = struct {
    618 	Fquot int64
    619 	Frem  int64
    620 }
    621 
    622 type lldiv_t = struct {
    623 	Fquot int64
    624 	Frem  int64
    625 }
    626 
    627 type max_align_t = struct {
    628 	F__ll int64
    629 	F__ld float64
    630 }
    631 
    632 type ptrdiff_t = int64
    633 
    634 type uintptr_t = uint64
    635 
    636 type intptr_t = int64
    637 
    638 type int8_t = int8
    639 
    640 type int16_t = int16
    641 
    642 type int32_t = int32
    643 
    644 type int64_t = int64
    645 
    646 type intmax_t = int64
    647 
    648 type uint8_t = uint8
    649 
    650 type uint16_t = uint16
    651 
    652 type uint32_t = uint32
    653 
    654 type uint64_t = uint64
    655 
    656 type uintmax_t = uint64
    657 
    658 type int_fast8_t = int8
    659 
    660 type int_fast64_t = int64
    661 
    662 type int_least8_t = int8
    663 
    664 type int_least16_t = int16
    665 
    666 type int_least32_t = int32
    667 
    668 type int_least64_t = int64
    669 
    670 type uint_fast8_t = uint8
    671 
    672 type uint_fast64_t = uint64
    673 
    674 type uint_least8_t = uint8
    675 
    676 type uint_least16_t = uint16
    677 
    678 type uint_least32_t = uint32
    679 
    680 type uint_least64_t = uint64
    681 
    682 type int_fast16_t = int32
    683 
    684 type int_fast32_t = int32
    685 
    686 type uint_fast16_t = uint32
    687 
    688 type uint_fast32_t = uint32
    689 
    690 type imaxdiv_t = struct {
    691 	Fquot intmax_t
    692 	Frem  intmax_t
    693 }
    694 
    695 type WebPRGBABuffer = struct {
    696 	Frgba   uintptr
    697 	Fstride int32
    698 	Fsize   size_t
    699 }
    700 
    701 type WebPYUVABuffer = struct {
    702 	Fy        uintptr
    703 	Fu        uintptr
    704 	Fv        uintptr
    705 	Fa        uintptr
    706 	Fy_stride int32
    707 	Fu_stride int32
    708 	Fv_stride int32
    709 	Fa_stride int32
    710 	Fy_size   size_t
    711 	Fu_size   size_t
    712 	Fv_size   size_t
    713 	Fa_size   size_t
    714 }
    715 
    716 type WebPDecBuffer = struct {
    717 	Fcolorspace         WEBP_CSP_MODE1
    718 	Fwidth              int32
    719 	Fheight             int32
    720 	Fis_external_memory int32
    721 	Fu                  struct {
    722 		FYUVA        [0]WebPYUVABuffer
    723 		FRGBA        WebPRGBABuffer
    724 		F__ccgo_pad2 [56]byte
    725 	}
    726 	Fpad            [4]uint32_t
    727 	Fprivate_memory uintptr
    728 }
    729 
    730 type WEBP_CSP_MODE = int32
    731 
    732 const MODE_RGB = 0
    733 const MODE_RGBA = 1
    734 const MODE_BGR = 2
    735 const MODE_BGRA = 3
    736 const MODE_ARGB = 4
    737 const MODE_RGBA_4444 = 5
    738 const MODE_RGB_565 = 6
    739 const MODE_rgbA = 7
    740 const MODE_bgrA = 8
    741 const MODE_Argb = 9
    742 const MODE_rgbA_4444 = 10
    743 const MODE_YUV = 11
    744 const MODE_YUVA = 12
    745 const MODE_LAST = 13
    746 
    747 type WebPBitstreamFeatures = struct {
    748 	Fwidth         int32
    749 	Fheight        int32
    750 	Fhas_alpha     int32
    751 	Fhas_animation int32
    752 	Fformat        int32
    753 	Fpad           [5]uint32_t
    754 }
    755 
    756 type WebPDecoderOptions = struct {
    757 	Fbypass_filtering         int32
    758 	Fno_fancy_upsampling      int32
    759 	Fuse_cropping             int32
    760 	Fcrop_left                int32
    761 	Fcrop_top                 int32
    762 	Fcrop_width               int32
    763 	Fcrop_height              int32
    764 	Fuse_scaling              int32
    765 	Fscaled_width             int32
    766 	Fscaled_height            int32
    767 	Fuse_threads              int32
    768 	Fdithering_strength       int32
    769 	Fflip                     int32
    770 	Falpha_dithering_strength int32
    771 	Fpad                      [5]uint32_t
    772 }
    773 
    774 type WebPDecoderConfig = struct {
    775 	Finput   WebPBitstreamFeatures
    776 	Foutput  WebPDecBuffer
    777 	Foptions WebPDecoderOptions
    778 }
    779 
    780 type WEBP_CSP_MODE1 = int32
    781 
    782 type VP8StatusCode1 = int32
    783 
    784 type VP8StatusCode = int32
    785 
    786 const VP8_STATUS_OK = 0
    787 const VP8_STATUS_OUT_OF_MEMORY = 1
    788 const VP8_STATUS_INVALID_PARAM = 2
    789 const VP8_STATUS_BITSTREAM_ERROR = 3
    790 const VP8_STATUS_UNSUPPORTED_FEATURE = 4
    791 const VP8_STATUS_SUSPENDED = 5
    792 const VP8_STATUS_USER_ABORT = 6
    793 const VP8_STATUS_NOT_ENOUGH_DATA = 7
    794 
    795 type VP8Io = struct {
    796 	Fwidth            int32
    797 	Fheight           int32
    798 	Fmb_y             int32
    799 	Fmb_w             int32
    800 	Fmb_h             int32
    801 	Fy                uintptr
    802 	Fu                uintptr
    803 	Fv                uintptr
    804 	Fy_stride         int32
    805 	Fuv_stride        int32
    806 	Fopaque           uintptr
    807 	Fput              VP8IoPutHook
    808 	Fsetup            VP8IoSetupHook
    809 	Fteardown         VP8IoTeardownHook
    810 	Ffancy_upsampling int32
    811 	Fdata_size        size_t
    812 	Fdata             uintptr
    813 	Fbypass_filtering int32
    814 	Fuse_cropping     int32
    815 	Fcrop_left        int32
    816 	Fcrop_right       int32
    817 	Fcrop_top         int32
    818 	Fcrop_bottom      int32
    819 	Fuse_scaling      int32
    820 	Fscaled_width     int32
    821 	Fscaled_height    int32
    822 	Fa                uintptr
    823 }
    824 
    825 type VP8IoPutHook = uintptr
    826 
    827 type VP8IoSetupHook = uintptr
    828 
    829 type VP8IoTeardownHook = uintptr
    830 
    831 type VP8Decoder = struct {
    832 	Fstatus              VP8StatusCode1
    833 	Fready               int32
    834 	Ferror_msg           uintptr
    835 	Fbr                  VP8BitReader
    836 	Fincremental         int32
    837 	Ffrm_hdr             VP8FrameHeader
    838 	Fpic_hdr             VP8PictureHeader
    839 	Ffilter_hdr          VP8FilterHeader
    840 	Fsegment_hdr         VP8SegmentHeader
    841 	Fworker              WebPWorker
    842 	Fmt_method           int32
    843 	Fcache_id            int32
    844 	Fnum_caches          int32
    845 	Fthread_ctx          VP8ThreadContext
    846 	Fmb_w                int32
    847 	Fmb_h                int32
    848 	Ftl_mb_x             int32
    849 	Ftl_mb_y             int32
    850 	Fbr_mb_x             int32
    851 	Fbr_mb_y             int32
    852 	Fnum_parts_minus_one uint32_t
    853 	Fparts               [8]VP8BitReader
    854 	Fdither              int32
    855 	Fdithering_rg        VP8Random
    856 	Fdqm                 [4]VP8QuantMatrix
    857 	Fproba               VP8Proba
    858 	Fuse_skip_proba      int32
    859 	Fskip_p              uint8_t
    860 	Fintra_t             uintptr
    861 	Fintra_l             [4]uint8_t
    862 	Fyuv_t               uintptr
    863 	Fmb_info             uintptr
    864 	Ff_info              uintptr
    865 	Fyuv_b               uintptr
    866 	Fcache_y             uintptr
    867 	Fcache_u             uintptr
    868 	Fcache_v             uintptr
    869 	Fcache_y_stride      int32
    870 	Fcache_uv_stride     int32
    871 	Fmem                 uintptr
    872 	Fmem_size            size_t
    873 	Fmb_x                int32
    874 	Fmb_y                int32
    875 	Fmb_data             uintptr
    876 	Ffilter_type         int32
    877 	Ffstrengths          [4][2]VP8FInfo
    878 	Falph_dec            uintptr
    879 	Falpha_data          uintptr
    880 	Falpha_data_size     size_t
    881 	Fis_alpha_decoded    int32
    882 	Falpha_plane_mem     uintptr
    883 	Falpha_plane         uintptr
    884 	Falpha_prev_line     uintptr
    885 	Falpha_dithering     int32
    886 }
    887 
    888 type rescaler_t = uint32
    889 
    890 type WebPRescaler = struct {
    891 	Fx_expand     int32
    892 	Fy_expand     int32
    893 	Fnum_channels int32
    894 	Ffx_scale     uint32_t
    895 	Ffy_scale     uint32_t
    896 	Ffxy_scale    uint32_t
    897 	Fy_accum      int32
    898 	Fy_add        int32
    899 	Fy_sub        int32
    900 	Fx_add        int32
    901 	Fx_sub        int32
    902 	Fsrc_width    int32
    903 	Fsrc_height   int32
    904 	Fdst_width    int32
    905 	Fdst_height   int32
    906 	Fsrc_y        int32
    907 	Fdst_y        int32
    908 	Fdst          uintptr
    909 	Fdst_stride   int32
    910 	Firow         uintptr
    911 	Ffrow         uintptr
    912 }
    913 
    914 type WebPDecParams = struct {
    915 	Foutput         uintptr
    916 	Ftmp_y          uintptr
    917 	Ftmp_u          uintptr
    918 	Ftmp_v          uintptr
    919 	Flast_y         int32
    920 	Foptions        uintptr
    921 	Fscaler_y       uintptr
    922 	Fscaler_u       uintptr
    923 	Fscaler_v       uintptr
    924 	Fscaler_a       uintptr
    925 	Fmemory         uintptr
    926 	Femit           OutputFunc
    927 	Femit_alpha     OutputAlphaFunc
    928 	Femit_alpha_row OutputRowFunc
    929 }
    930 
    931 type OutputFunc = uintptr
    932 
    933 type OutputAlphaFunc = uintptr
    934 
    935 type OutputRowFunc = uintptr
    936 
    937 type WebPHeaderStructure = struct {
    938 	Fdata            uintptr
    939 	Fdata_size       size_t
    940 	Fhave_all_data   int32
    941 	Foffset          size_t
    942 	Falpha_data      uintptr
    943 	Falpha_data_size size_t
    944 	Fcompressed_size size_t
    945 	Friff_size       size_t
    946 	Fis_lossless     int32
    947 }
    948 
    949 type CPUFeature = int32
    950 
    951 const kSSE2 = 0
    952 const kSSE3 = 1
    953 const kSlowSSSE3 = 2
    954 const kSSE4_1 = 3
    955 const kAVX = 4
    956 const kAVX2 = 5
    957 const kNEON = 6
    958 const kMIPS32 = 7
    959 const kMIPSdspR2 = 8
    960 const kMSA = 9
    961 
    962 type VP8CPUInfo = uintptr
    963 
    964 type VP8Idct = uintptr
    965 
    966 type VP8Fdct = uintptr
    967 
    968 type VP8WHT = uintptr
    969 
    970 type VP8IntraPreds = uintptr
    971 
    972 type VP8Intra4Preds = uintptr
    973 
    974 type VP8Metric = uintptr
    975 
    976 type VP8WMetric = uintptr
    977 
    978 type VP8MeanMetric = uintptr
    979 
    980 type VP8BlockCopy = uintptr
    981 
    982 type VP8QuantizeBlock = uintptr
    983 
    984 type VP8Quantize2Blocks = uintptr
    985 
    986 type VP8QuantizeBlockWHT = uintptr
    987 
    988 type VP8Histogram = struct {
    989 	Fmax_value     int32
    990 	Flast_non_zero int32
    991 }
    992 
    993 type VP8CHisto = uintptr
    994 
    995 type VP8SetResidualCoeffsFunc = uintptr
    996 
    997 type VP8GetResidualCostFunc = uintptr
    998 
    999 type VP8DistoStats = struct {
   1000 	Fw   uint32_t
   1001 	Fxm  uint32_t
   1002 	Fym  uint32_t
   1003 	Fxxm uint32_t
   1004 	Fxym uint32_t
   1005 	Fyym uint32_t
   1006 }
   1007 
   1008 type VP8SSIMGetClippedFunc = uintptr
   1009 
   1010 type VP8SSIMGetFunc = uintptr
   1011 
   1012 type VP8AccumulateSSEFunc = uintptr
   1013 
   1014 type VP8DecIdct = uintptr
   1015 
   1016 type VP8DecIdct2 = uintptr
   1017 
   1018 type VP8PredFunc = uintptr
   1019 
   1020 type VP8SimpleFilterFunc = uintptr
   1021 
   1022 type VP8LumaFilterFunc = uintptr
   1023 
   1024 type VP8ChromaFilterFunc = uintptr
   1025 
   1026 type WebPUpsampleLinePairFunc = uintptr
   1027 
   1028 type WebPSamplerRowFunc = uintptr
   1029 
   1030 type WebPYUV444Converter = uintptr
   1031 
   1032 type WebPRescalerImportRowFunc = uintptr
   1033 
   1034 type WebPRescalerExportRowFunc = uintptr
   1035 
   1036 type WEBP_FILTER_TYPE = int32
   1037 
   1038 const WEBP_FILTER_NONE = 0
   1039 const WEBP_FILTER_HORIZONTAL = 1
   1040 const WEBP_FILTER_VERTICAL = 2
   1041 const WEBP_FILTER_GRADIENT = 3
   1042 const WEBP_FILTER_LAST = 4
   1043 const WEBP_FILTER_BEST = 5
   1044 const WEBP_FILTER_FAST = 6
   1045 
   1046 type WebPFilterFunc = uintptr
   1047 
   1048 type WebPUnfilterFunc = uintptr
   1049 
   1050 type VP8LDecoder = struct {
   1051 	Fstatus           VP8StatusCode1
   1052 	Fstate            VP8LDecodeState
   1053 	Fio               uintptr
   1054 	Foutput           uintptr
   1055 	Fpixels           uintptr
   1056 	Fargb_cache       uintptr
   1057 	Fbr               VP8LBitReader
   1058 	Fincremental      int32
   1059 	Fsaved_br         VP8LBitReader
   1060 	Fsaved_last_pixel int32
   1061 	Fwidth            int32
   1062 	Fheight           int32
   1063 	Flast_row         int32
   1064 	Flast_pixel       int32
   1065 	Flast_out_row     int32
   1066 	Fhdr              VP8LMetadata
   1067 	Fnext_transform   int32
   1068 	Ftransforms       [4]VP8LTransform
   1069 	Ftransforms_seen  uint32_t
   1070 	Frescaler_memory  uintptr
   1071 	Frescaler         uintptr
   1072 }
   1073 
   1074 const READ_DATA = 0
   1075 const READ_HDR = 1
   1076 const READ_DIM = 2
   1077 
   1078 type ALPHDecoder = struct {
   1079 	Fwidth          int32
   1080 	Fheight         int32
   1081 	Fmethod         int32
   1082 	Ffilter         WEBP_FILTER_TYPE
   1083 	Fpre_processing int32
   1084 	Fvp8l_dec       uintptr
   1085 	Fio             VP8Io
   1086 	Fuse_8b_decode  int32
   1087 	Foutput         uintptr
   1088 	Fprev_line      uintptr
   1089 }
   1090 
   1091 type locale_t = uintptr
   1092 
   1093 const B_DC_PRED = 0
   1094 const B_TM_PRED = 1
   1095 const B_VE_PRED = 2
   1096 const B_HE_PRED = 3
   1097 const B_RD_PRED = 4
   1098 const B_VR_PRED = 5
   1099 const B_LD_PRED = 6
   1100 const B_VL_PRED = 7
   1101 const B_HD_PRED = 8
   1102 const B_HU_PRED = 9
   1103 const NUM_BMODES = 10
   1104 const DC_PRED = 0
   1105 const V_PRED = 2
   1106 const H_PRED = 3
   1107 const TM_PRED = 1
   1108 const B_PRED = 10
   1109 const NUM_PRED_MODES = 4
   1110 const B_DC_PRED_NOTOP = 4
   1111 const B_DC_PRED_NOLEFT = 5
   1112 const B_DC_PRED_NOTOPLEFT = 6
   1113 const NUM_B_DC_MODES = 7
   1114 const MB_FEATURE_TREE_PROBS = 3
   1115 const NUM_MB_SEGMENTS = 4
   1116 const NUM_REF_LF_DELTAS = 4
   1117 const NUM_MODE_LF_DELTAS = 4
   1118 const MAX_NUM_PARTITIONS = 8
   1119 const NUM_TYPES = 4
   1120 const NUM_BANDS = 8
   1121 const NUM_CTX = 3
   1122 const NUM_PROBAS = 11
   1123 
   1124 type bit_t = uint64
   1125 
   1126 type range_t = uint32
   1127 
   1128 type VP8BitReader = struct {
   1129 	Fvalue   bit_t
   1130 	Frange1  range_t
   1131 	Fbits    int32
   1132 	Fbuf     uintptr
   1133 	Fbuf_end uintptr
   1134 	Fbuf_max uintptr
   1135 	Feof     int32
   1136 }
   1137 
   1138 type vp8l_val_t = uint64
   1139 
   1140 type VP8LBitReader = struct {
   1141 	Fval     vp8l_val_t
   1142 	Fbuf     uintptr
   1143 	Flen1    size_t
   1144 	Fpos     size_t
   1145 	Fbit_pos int32
   1146 	Feos     int32
   1147 }
   1148 
   1149 type VP8LColorCache = struct {
   1150 	Fcolors     uintptr
   1151 	Fhash_shift int32
   1152 	Fhash_bits  int32
   1153 }
   1154 
   1155 var kHashMul = uint32(0x1e35a7bd)
   1156 
   1157 type VP8LImageTransformType = int32
   1158 
   1159 const PREDICTOR_TRANSFORM = 0
   1160 const CROSS_COLOR_TRANSFORM = 1
   1161 const SUBTRACT_GREEN_TRANSFORM = 2
   1162 const COLOR_INDEXING_TRANSFORM = 3
   1163 
   1164 type HuffmanCode = struct {
   1165 	Fbits  uint8_t
   1166 	Fvalue uint16_t
   1167 }
   1168 
   1169 type HuffmanCode32 = struct {
   1170 	Fbits  int32
   1171 	Fvalue uint32_t
   1172 }
   1173 
   1174 type HuffmanTablesSegment = struct {
   1175 	Fstart      uintptr
   1176 	Fcurr_table uintptr
   1177 	Fnext       uintptr
   1178 	Fsize       int32
   1179 }
   1180 
   1181 type HuffmanTables = struct {
   1182 	Froot         HuffmanTablesSegment
   1183 	Fcurr_segment uintptr
   1184 }
   1185 
   1186 type HTreeGroup = struct {
   1187 	Fhtrees             [5]uintptr
   1188 	Fis_trivial_literal int32
   1189 	Fliteral_arb        uint32_t
   1190 	Fis_trivial_code    int32
   1191 	Fuse_packed_table   int32
   1192 	Fpacked_table       [64]HuffmanCode32
   1193 }
   1194 
   1195 type VP8LDecodeState = int32
   1196 
   1197 type VP8LTransform = struct {
   1198 	Ftype1 VP8LImageTransformType
   1199 	Fbits  int32
   1200 	Fxsize int32
   1201 	Fysize int32
   1202 	Fdata  uintptr
   1203 }
   1204 
   1205 type VP8LMetadata = struct {
   1206 	Fcolor_cache_size       int32
   1207 	Fcolor_cache            VP8LColorCache
   1208 	Fsaved_color_cache      VP8LColorCache
   1209 	Fhuffman_mask           int32
   1210 	Fhuffman_subsample_bits int32
   1211 	Fhuffman_xsize          int32
   1212 	Fhuffman_image          uintptr
   1213 	Fnum_htree_groups       int32
   1214 	Fhtree_groups           uintptr
   1215 	Fhuffman_tables         HuffmanTables
   1216 }
   1217 
   1218 type VP8Random = struct {
   1219 	Findex1 int32
   1220 	Findex2 int32
   1221 	Ftab    [55]uint32_t
   1222 	Famp    int32
   1223 }
   1224 
   1225 type WebPWorkerStatus = int32
   1226 
   1227 const NOT_OK = 0
   1228 const OK = 1
   1229 const WORK = 2
   1230 
   1231 type WebPWorkerHook = uintptr
   1232 
   1233 type WebPWorker = struct {
   1234 	Fimpl      uintptr
   1235 	Fstatus    WebPWorkerStatus
   1236 	Fhook      WebPWorkerHook
   1237 	Fdata1     uintptr
   1238 	Fdata2     uintptr
   1239 	Fhad_error int32
   1240 }
   1241 
   1242 type WebPWorkerInterface = struct {
   1243 	FInit    uintptr
   1244 	FReset   uintptr
   1245 	FSync    uintptr
   1246 	FLaunch  uintptr
   1247 	FExecute uintptr
   1248 	FEnd     uintptr
   1249 }
   1250 
   1251 type VP8FrameHeader = struct {
   1252 	Fkey_frame        uint8_t
   1253 	Fprofile          uint8_t
   1254 	Fshow             uint8_t
   1255 	Fpartition_length uint32_t
   1256 }
   1257 
   1258 type VP8PictureHeader = struct {
   1259 	Fwidth      uint16_t
   1260 	Fheight     uint16_t
   1261 	Fxscale     uint8_t
   1262 	Fyscale     uint8_t
   1263 	Fcolorspace uint8_t
   1264 	Fclamp_type uint8_t
   1265 }
   1266 
   1267 type VP8SegmentHeader = struct {
   1268 	Fuse_segment     int32
   1269 	Fupdate_map      int32
   1270 	Fabsolute_delta  int32
   1271 	Fquantizer       [4]int8_t
   1272 	Ffilter_strength [4]int8_t
   1273 }
   1274 
   1275 type VP8ProbaArray = [11]uint8_t
   1276 
   1277 type VP8BandProbas = struct {
   1278 	Fprobas [3]VP8ProbaArray
   1279 }
   1280 
   1281 type VP8Proba = struct {
   1282 	Fsegments  [3]uint8_t
   1283 	Fbands     [4][8]VP8BandProbas
   1284 	Fbands_ptr [4][17]uintptr
   1285 }
   1286 
   1287 type VP8FilterHeader = struct {
   1288 	Fsimple        int32
   1289 	Flevel         int32
   1290 	Fsharpness     int32
   1291 	Fuse_lf_delta  int32
   1292 	Fref_lf_delta  [4]int32
   1293 	Fmode_lf_delta [4]int32
   1294 }
   1295 
   1296 type VP8FInfo = struct {
   1297 	Ff_limit    uint8_t
   1298 	Ff_ilevel   uint8_t
   1299 	Ff_inner    uint8_t
   1300 	Fhev_thresh uint8_t
   1301 }
   1302 
   1303 type VP8MB = struct {
   1304 	Fnz    uint8_t
   1305 	Fnz_dc uint8_t
   1306 }
   1307 
   1308 type quant_t = [2]int32
   1309 
   1310 type VP8QuantMatrix = struct {
   1311 	Fy1_mat   quant_t
   1312 	Fy2_mat   quant_t
   1313 	Fuv_mat   quant_t
   1314 	Fuv_quant int32
   1315 	Fdither   int32
   1316 }
   1317 
   1318 type VP8MBData = struct {
   1319 	Fcoeffs      [384]int16_t
   1320 	Fis_i4x4     uint8_t
   1321 	Fimodes      [16]uint8_t
   1322 	Fuvmode      uint8_t
   1323 	Fnon_zero_y  uint32_t
   1324 	Fnon_zero_uv uint32_t
   1325 	Fdither      uint8_t
   1326 	Fskip        uint8_t
   1327 	Fsegment     uint8_t
   1328 }
   1329 
   1330 type VP8ThreadContext = struct {
   1331 	Fid         int32
   1332 	Fmb_y       int32
   1333 	Ffilter_row int32
   1334 	Ff_info     uintptr
   1335 	Fmb_data    uintptr
   1336 	Fio         VP8Io
   1337 }
   1338 
   1339 type VP8TopSamples = struct {
   1340 	Fy [16]uint8_t
   1341 	Fu [8]uint8_t
   1342 	Fv [8]uint8_t
   1343 }
   1344 
   1345 //------------------------------------------------------------------------------
   1346 
   1347 // Copyright 2010 Google Inc. All Rights Reserved.
   1348 //
   1349 // Use of this source code is governed by a BSD-style license
   1350 // that can be found in the COPYING file in the root of the source
   1351 // tree. An additional intellectual property rights grant can be found
   1352 // in the file PATENTS. All contributing project authors may
   1353 // be found in the AUTHORS file in the root of the source tree.
   1354 // -----------------------------------------------------------------------------
   1355 //
   1356 //  Main decoding functions for WebP images.
   1357 //
   1358 // Author: Skal (pascal.massimino@gmail.com)
   1359 
   1360 // Copyright 2012 Google Inc. All Rights Reserved.
   1361 //
   1362 // Use of this source code is governed by a BSD-style license
   1363 // that can be found in the COPYING file in the root of the source
   1364 // tree. An additional intellectual property rights grant can be found
   1365 // in the file PATENTS. All contributing project authors may
   1366 // be found in the AUTHORS file in the root of the source tree.
   1367 // -----------------------------------------------------------------------------
   1368 //
   1369 //  Internal header for constants related to WebP file format.
   1370 //
   1371 // Author: Urvang (urvang@google.com)
   1372 
   1373 // Copyright 2010 Google Inc. All Rights Reserved.
   1374 //
   1375 // Use of this source code is governed by a BSD-style license
   1376 // that can be found in the COPYING file in the root of the source
   1377 // tree. An additional intellectual property rights grant can be found
   1378 // in the file PATENTS. All contributing project authors may
   1379 // be found in the AUTHORS file in the root of the source tree.
   1380 // -----------------------------------------------------------------------------
   1381 //
   1382 //  Common types + memory wrappers
   1383 //
   1384 // Author: Skal (pascal.massimino@gmail.com)
   1385 
   1386 //------------------------------------------------------------------------------
   1387 // ALPHDecoder object.
   1388 
   1389 // C documentation
   1390 //
   1391 //	// Allocates a new alpha decoder instance.
   1392 func ALPHNew(tls *libc.TLS) (r uintptr) {
   1393 	var dec uintptr
   1394 	_ = dec
   1395 	dec = WebPSafeCalloc(tls, uint64(1), uint64(216))
   1396 	return dec
   1397 }
   1398 
   1399 // C documentation
   1400 //
   1401 //	// Clears and deallocates an alpha decoder instance.
   1402 func ALPHDelete(tls *libc.TLS, dec uintptr) {
   1403 	if dec != libc.UintptrFromInt32(0) {
   1404 		VP8LDelete(tls, (*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec)
   1405 		(*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec = libc.UintptrFromInt32(0)
   1406 		WebPSafeFree(tls, dec)
   1407 	}
   1408 }
   1409 
   1410 //------------------------------------------------------------------------------
   1411 // Decoding.
   1412 
   1413 // C documentation
   1414 //
   1415 //	// Initialize alpha decoding by parsing the alpha header and decoding the image
   1416 //	// header for alpha data stored using lossless compression.
   1417 //	// Returns false in case of error in alpha header (data too short, invalid
   1418 //	// compression method or filter, error in lossless header data etc).
   1419 func ALPHInit(tls *libc.TLS, dec uintptr, data uintptr, data_size size_t, src_io uintptr, output uintptr) (r int32) {
   1420 	var alpha_data, io1 uintptr
   1421 	var alpha_data_size, alpha_decoded_size size_t
   1422 	var ok, rsrv, v1 int32
   1423 	_, _, _, _, _, _, _ = alpha_data, alpha_data_size, alpha_decoded_size, io1, ok, rsrv, v1
   1424 	ok = 0
   1425 	alpha_data = data + uintptr(ALPHA_HEADER_LEN)
   1426 	alpha_data_size = data_size - uint64(ALPHA_HEADER_LEN)
   1427 	io1 = dec + 32
   1428 	VP8FiltersInit(tls)
   1429 	(*ALPHDecoder)(unsafe.Pointer(dec)).Foutput = output
   1430 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1431 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1432 	if data_size <= uint64(ALPHA_HEADER_LEN) {
   1433 		return 0
   1434 	}
   1435 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> 0 & int32(0x03)
   1436 	(*ALPHDecoder)(unsafe.Pointer(dec)).Ffilter = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> libc.Int32FromInt32(2) & libc.Int32FromInt32(0x03)
   1437 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fpre_processing = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> int32(4) & int32(0x03)
   1438 	rsrv = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> int32(6) & int32(0x03)
   1439 	if (*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod < ALPHA_NO_COMPRESSION || (*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod > int32(ALPHA_LOSSLESS_COMPRESSION) || (*ALPHDecoder)(unsafe.Pointer(dec)).Ffilter >= int32(WEBP_FILTER_LAST) || (*ALPHDecoder)(unsafe.Pointer(dec)).Fpre_processing > int32(ALPHA_PREPROCESSED_LEVELS) || rsrv != 0 {
   1440 		return 0
   1441 	}
   1442 	// Copy the necessary parameters from src_io to io
   1443 	v1 = VP8InitIoInternal(tls, io1, int32(WEBP_DECODER_ABI_VERSION))
   1444 	goto _2
   1445 _2:
   1446 	if !(v1 != 0) {
   1447 		return 0
   1448 	}
   1449 	WebPInitCustomIo(tls, libc.UintptrFromInt32(0), io1)
   1450 	(*VP8Io)(unsafe.Pointer(io1)).Fopaque = dec
   1451 	(*VP8Io)(unsafe.Pointer(io1)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1452 	(*VP8Io)(unsafe.Pointer(io1)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1453 	(*VP8Io)(unsafe.Pointer(io1)).Fuse_cropping = (*VP8Io)(unsafe.Pointer(src_io)).Fuse_cropping
   1454 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_left = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_left
   1455 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_right = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_right
   1456 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_top = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_top
   1457 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_bottom
   1458 	// No need to copy the scaling parameters.
   1459 	if (*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1460 		alpha_decoded_size = libc.Uint64FromInt32((*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth * (*ALPHDecoder)(unsafe.Pointer(dec)).Fheight)
   1461 		ok = libc.BoolInt32(alpha_data_size >= alpha_decoded_size)
   1462 	} else {
   1463 		ok = VP8LDecodeAlphaHeader(tls, dec, alpha_data, alpha_data_size)
   1464 	}
   1465 	return ok
   1466 }
   1467 
   1468 // C documentation
   1469 //
   1470 //	// Decodes, unfilters and dequantizes *at least* 'num_rows' rows of alpha
   1471 //	// starting from row number 'row'. It assumes that rows up to (row - 1) have
   1472 //	// already been decoded.
   1473 //	// Returns false in case of bitstream error.
   1474 func ALPHDecode(tls *libc.TLS, dec uintptr, row int32, num_rows int32) (r int32) {
   1475 	var alph_dec, deltas, dst, prev_line uintptr
   1476 	var height, width, y int32
   1477 	_, _, _, _, _, _, _ = alph_dec, deltas, dst, height, prev_line, width, y
   1478 	alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   1479 	width = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
   1480 	height = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fio.Fcrop_bottom
   1481 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1482 		prev_line = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line
   1483 		deltas = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data + uintptr(ALPHA_HEADER_LEN) + uintptr(row*width)
   1484 		dst = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1485 		y = 0
   1486 		for {
   1487 			if !(y < num_rows) {
   1488 				break
   1489 			}
   1490 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, deltas, dst, width)
   1491 			prev_line = dst
   1492 			dst = dst + uintptr(width)
   1493 			deltas = deltas + uintptr(width)
   1494 			goto _1
   1495 		_1:
   1496 			;
   1497 			y = y + 1
   1498 		}
   1499 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = prev_line
   1500 	} else { // alph_dec->method == ALPHA_LOSSLESS_COMPRESSION
   1501 		if !(VP8LDecodeAlphaImageStream(tls, alph_dec, row+num_rows) != 0) {
   1502 			return 0
   1503 		}
   1504 	}
   1505 	if row+num_rows >= height {
   1506 		(*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded = int32(1)
   1507 	}
   1508 	return int32(1)
   1509 }
   1510 
   1511 func AllocateAlphaPlane(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   1512 	var alpha_size uint64_t
   1513 	var height, stride int32
   1514 	_, _, _ = alpha_size, height, stride
   1515 	stride = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1516 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1517 	alpha_size = libc.Uint64FromInt32(stride) * libc.Uint64FromInt32(height)
   1518 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = WebPSafeMalloc(tls, alpha_size, uint64(1))
   1519 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem == libc.UintptrFromInt32(0) {
   1520 		return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1521 	}
   1522 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem
   1523 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = libc.UintptrFromInt32(0)
   1524 	return int32(1)
   1525 }
   1526 
   1527 func WebPDeallocateAlphaMemory(tls *libc.TLS, dec uintptr) {
   1528 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem)
   1529 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = libc.UintptrFromInt32(0)
   1530 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = libc.UintptrFromInt32(0)
   1531 	ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1532 	(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1533 }
   1534 
   1535 // ------------------------------------------------------------------------------
   1536 // Main entry point.
   1537 func VP8DecompressAlphaRows(tls *libc.TLS, dec uintptr, io uintptr, row int32, num_rows int32) (r uintptr) {
   1538 	var alpha, vp8l_dec uintptr
   1539 	var height, width, v1 int32
   1540 	_, _, _, _, _ = alpha, height, vp8l_dec, width, v1
   1541 	width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1542 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1543 	if row < 0 || num_rows <= 0 || row+num_rows > height {
   1544 		return libc.UintptrFromInt32(0)
   1545 	}
   1546 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0) {
   1547 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) { // Initialize decoder.
   1548 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = ALPHNew(tls)
   1549 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) {
   1550 				VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1551 				return libc.UintptrFromInt32(0)
   1552 			}
   1553 			if !(AllocateAlphaPlane(tls, dec, io) != 0) {
   1554 				goto Error
   1555 			}
   1556 			if !(ALPHInit(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size, io, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane) != 0) {
   1557 				vp8l_dec = (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fvp8l_dec
   1558 				if vp8l_dec == libc.UintptrFromInt32(0) {
   1559 					v1 = int32(VP8_STATUS_OUT_OF_MEMORY)
   1560 				} else {
   1561 					v1 = (*VP8LDecoder)(unsafe.Pointer(vp8l_dec)).Fstatus
   1562 				}
   1563 				VP8SetError(tls, dec, v1, __ccgo_ts)
   1564 				goto Error
   1565 			}
   1566 			// if we allowed use of alpha dithering, check whether it's needed at all
   1567 			if (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fpre_processing != int32(ALPHA_PREPROCESSED_LEVELS) {
   1568 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0 // disable dithering
   1569 			} else {
   1570 				num_rows = height - row // decode everything in one pass
   1571 			}
   1572 		}
   1573 		if !(ALPHDecode(tls, dec, row, num_rows) != 0) {
   1574 			goto Error
   1575 		}
   1576 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0 { // finished?
   1577 			ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1578 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1579 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > 0 {
   1580 				alpha = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_top*width) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   1581 				if !(WebPDequantizeLevels(tls, alpha, (*VP8Io)(unsafe.Pointer(io)).Fcrop_right-(*VP8Io)(unsafe.Pointer(io)).Fcrop_left, (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom-(*VP8Io)(unsafe.Pointer(io)).Fcrop_top, width, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering) != 0) {
   1582 					goto Error
   1583 				}
   1584 			}
   1585 		}
   1586 	}
   1587 	// Return a pointer to the current decoded row.
   1588 	return (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1589 	goto Error
   1590 Error:
   1591 	;
   1592 	WebPDeallocateAlphaMemory(tls, dec)
   1593 	return libc.UintptrFromInt32(0)
   1594 }
   1595 
   1596 var kHashMul1 = uint32(0x1e35a7bd)
   1597 
   1598 //------------------------------------------------------------------------------
   1599 
   1600 // Copyright 2010 Google Inc. All Rights Reserved.
   1601 //
   1602 // Use of this source code is governed by a BSD-style license
   1603 // that can be found in the COPYING file in the root of the source
   1604 // tree. An additional intellectual property rights grant can be found
   1605 // in the file PATENTS. All contributing project authors may
   1606 // be found in the AUTHORS file in the root of the source tree.
   1607 // -----------------------------------------------------------------------------
   1608 //
   1609 //  Main decoding functions for WebP images.
   1610 //
   1611 // Author: Skal (pascal.massimino@gmail.com)
   1612 
   1613 // Copyright 2010 Google Inc. All Rights Reserved.
   1614 //
   1615 // Use of this source code is governed by a BSD-style license
   1616 // that can be found in the COPYING file in the root of the source
   1617 // tree. An additional intellectual property rights grant can be found
   1618 // in the file PATENTS. All contributing project authors may
   1619 // be found in the AUTHORS file in the root of the source tree.
   1620 // -----------------------------------------------------------------------------
   1621 //
   1622 //  Common types + memory wrappers
   1623 //
   1624 // Author: Skal (pascal.massimino@gmail.com)
   1625 
   1626 //------------------------------------------------------------------------------
   1627 // WebPDecBuffer
   1628 
   1629 // C documentation
   1630 //
   1631 //	// Number of bytes per pixel for the different color-spaces.
   1632 var kModeBpp = [13]uint8_t{
   1633 	0:  uint8(3),
   1634 	1:  uint8(4),
   1635 	2:  uint8(3),
   1636 	3:  uint8(4),
   1637 	4:  uint8(4),
   1638 	5:  uint8(2),
   1639 	6:  uint8(2),
   1640 	7:  uint8(4),
   1641 	8:  uint8(4),
   1642 	9:  uint8(4),
   1643 	10: uint8(2),
   1644 	11: uint8(1),
   1645 	12: uint8(1),
   1646 }
   1647 
   1648 // C documentation
   1649 //
   1650 //	// Convert to an integer to handle both the unsigned/signed enum cases
   1651 //	// without the need for casting to remove type limit warnings.
   1652 func IsValidColorspace(tls *libc.TLS, webp_csp_mode int32) (r int32) {
   1653 	return libc.BoolInt32(webp_csp_mode >= int32(MODE_RGB) && webp_csp_mode < int32(MODE_LAST))
   1654 }
   1655 
   1656 // strictly speaking, the very last (or first, if flipped) row
   1657 // doesn't require padding.
   1658 
   1659 func CheckDecBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1660 	var a_size, size, u_size, v_size, y_size uint64_t
   1661 	var a_stride, height, ok, stride, u_stride, uv_height, uv_width, v_stride, width, y_stride, v1 int32
   1662 	var buf, buf1 uintptr
   1663 	var mode1 WEBP_CSP_MODE1
   1664 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_size, a_stride, buf, buf1, height, mode1, ok, size, stride, u_size, u_stride, uv_height, uv_width, v_size, v_stride, width, y_size, y_stride, v1
   1665 	ok = int32(1)
   1666 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   1667 	width = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   1668 	height = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   1669 	if !(IsValidColorspace(tls, mode1) != 0) {
   1670 		ok = 0
   1671 	} else {
   1672 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1673 		goto _2
   1674 	_2:
   1675 		if !(v1 != 0) { // YUV checks
   1676 			buf = buffer + 16
   1677 			uv_width = (width + int32(1)) / int32(2)
   1678 			uv_height = (height + int32(1)) / int32(2)
   1679 			y_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride)
   1680 			u_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
   1681 			v_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
   1682 			a_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   1683 			y_size = libc.Uint64FromInt32(y_stride)*libc.Uint64FromInt32(height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(width)
   1684 			u_size = libc.Uint64FromInt32(u_stride)*libc.Uint64FromInt32(uv_height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(uv_width)
   1685 			v_size = libc.Uint64FromInt32(v_stride)*libc.Uint64FromInt32(uv_height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(uv_width)
   1686 			a_size = libc.Uint64FromInt32(a_stride)*libc.Uint64FromInt32(height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(width)
   1687 			ok = ok & libc.BoolInt32(y_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size)
   1688 			ok = ok & libc.BoolInt32(u_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size)
   1689 			ok = ok & libc.BoolInt32(v_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size)
   1690 			ok = ok & libc.BoolInt32(y_stride >= width)
   1691 			ok = ok & libc.BoolInt32(u_stride >= uv_width)
   1692 			ok = ok & libc.BoolInt32(v_stride >= uv_width)
   1693 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy != libc.UintptrFromInt32(0))
   1694 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu != libc.UintptrFromInt32(0))
   1695 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv != libc.UintptrFromInt32(0))
   1696 			if mode1 == int32(MODE_YUVA) {
   1697 				ok = ok & libc.BoolInt32(a_stride >= width)
   1698 				ok = ok & libc.BoolInt32(a_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size)
   1699 				ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0))
   1700 			}
   1701 		} else { // RGB checks
   1702 			buf1 = buffer + 16
   1703 			stride = libc.Xabs(tls, (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride)
   1704 			size = libc.Uint64FromInt32(stride)*libc.Uint64FromInt32(height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(width)*uint64(kModeBpp[mode1])
   1705 			ok = ok & libc.BoolInt32(size <= (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize)
   1706 			ok = ok & libc.BoolInt32(stride >= width*libc.Int32FromUint8(kModeBpp[mode1]))
   1707 			ok = ok & libc.BoolInt32((*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba != libc.UintptrFromInt32(0))
   1708 		}
   1709 	}
   1710 	if ok != 0 {
   1711 		v1 = int32(VP8_STATUS_OK)
   1712 	} else {
   1713 		v1 = int32(VP8_STATUS_INVALID_PARAM)
   1714 	}
   1715 	return v1
   1716 }
   1717 
   1718 func AllocateBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1719 	var a_size, size, total_size, uv_size uint64_t
   1720 	var a_stride, h, stride, uv_stride, w, v1 int32
   1721 	var buf, buf1, output uintptr
   1722 	var mode1 WEBP_CSP_MODE1
   1723 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_size, a_stride, buf, buf1, h, mode1, output, size, stride, total_size, uv_size, uv_stride, w, v1
   1724 	w = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   1725 	h = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   1726 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   1727 	if w <= 0 || h <= 0 || !(IsValidColorspace(tls, mode1) != 0) {
   1728 		return int32(VP8_STATUS_INVALID_PARAM)
   1729 	}
   1730 	if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 && (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory == libc.UintptrFromInt32(0) {
   1731 		uv_stride = 0
   1732 		a_stride = 0
   1733 		uv_size = uint64(0)
   1734 		a_size = uint64(0)
   1735 		if uint64(libc.Uint64FromInt32(w)*uint64(kModeBpp[mode1])) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31) {
   1736 			return int32(VP8_STATUS_INVALID_PARAM)
   1737 		}
   1738 		stride = w * libc.Int32FromUint8(kModeBpp[mode1])
   1739 		size = libc.Uint64FromInt32(stride) * libc.Uint64FromInt32(h)
   1740 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1741 		goto _2
   1742 	_2:
   1743 		if !(v1 != 0) {
   1744 			uv_stride = (w + int32(1)) / int32(2)
   1745 			uv_size = libc.Uint64FromInt32(uv_stride) * libc.Uint64FromInt32((h+libc.Int32FromInt32(1))/libc.Int32FromInt32(2))
   1746 			if mode1 == int32(MODE_YUVA) {
   1747 				a_stride = w
   1748 				a_size = libc.Uint64FromInt32(a_stride) * libc.Uint64FromInt32(h)
   1749 			}
   1750 		}
   1751 		total_size = size + uint64(2)*uv_size + a_size
   1752 		output = WebPSafeMalloc(tls, total_size, uint64(1))
   1753 		if output == libc.UintptrFromInt32(0) {
   1754 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   1755 		}
   1756 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = output
   1757 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1758 		goto _4
   1759 	_4:
   1760 		if !(v1 != 0) { // YUVA initialization
   1761 			buf = buffer + 16
   1762 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy = output
   1763 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride = stride
   1764 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size = size
   1765 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu = output + uintptr(size)
   1766 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride = uv_stride
   1767 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size = uv_size
   1768 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv = output + uintptr(size) + uintptr(uv_size)
   1769 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride = uv_stride
   1770 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size = uv_size
   1771 			if mode1 == int32(MODE_YUVA) {
   1772 				(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa = output + uintptr(size) + uintptr(uint64(2)*uv_size)
   1773 			}
   1774 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size = a_size
   1775 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride = a_stride
   1776 		} else { // RGBA initialization
   1777 			buf1 = buffer + 16
   1778 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba = output
   1779 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride = stride
   1780 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize = size
   1781 		}
   1782 	}
   1783 	return CheckDecBuffer(tls, buffer)
   1784 }
   1785 
   1786 func WebPFlipBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1787 	var H int64_t
   1788 	var buf, buf1 uintptr
   1789 	var v1 int32
   1790 	_, _, _, _ = H, buf, buf1, v1
   1791 	if buffer == libc.UintptrFromInt32(0) {
   1792 		return int32(VP8_STATUS_INVALID_PARAM)
   1793 	}
   1794 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace < int32(MODE_YUV))
   1795 	goto _2
   1796 _2:
   1797 	if v1 != 0 {
   1798 		buf = buffer + 16
   1799 		**(**uintptr)(__ccgo_up(buf)) += uintptr(int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight-libc.Int32FromInt32(1)) * int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   1800 		(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride = -(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride
   1801 	} else {
   1802 		buf1 = buffer + 16
   1803 		H = int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight)
   1804 		**(**uintptr)(__ccgo_up(buf1)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride))
   1805 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride
   1806 		**(**uintptr)(__ccgo_up(buf1 + 8)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride))
   1807 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride
   1808 		**(**uintptr)(__ccgo_up(buf1 + 16)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride))
   1809 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride
   1810 		if (*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa != libc.UintptrFromInt32(0) {
   1811 			**(**uintptr)(__ccgo_up(buf1 + 24)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride))
   1812 			(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride
   1813 		}
   1814 	}
   1815 	return int32(VP8_STATUS_OK)
   1816 }
   1817 
   1818 func WebPAllocateDecBuffer(tls *libc.TLS, width int32, height int32, options uintptr, buffer uintptr) (r VP8StatusCode1) {
   1819 	bp := tls.Alloc(16)
   1820 	defer tls.Free(16)
   1821 	var ch, cw, x, y int32
   1822 	var status VP8StatusCode1
   1823 	var _ /* scaled_height at bp+4 */ int32
   1824 	var _ /* scaled_width at bp+0 */ int32
   1825 	_, _, _, _, _ = ch, cw, status, x, y
   1826 	if buffer == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
   1827 		return int32(VP8_STATUS_INVALID_PARAM)
   1828 	}
   1829 	if options != libc.UintptrFromInt32(0) { // First, apply options if there is any.
   1830 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0 {
   1831 			cw = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
   1832 			ch = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
   1833 			x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left & ^libc.Int32FromInt32(1)
   1834 			y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top & ^libc.Int32FromInt32(1)
   1835 			if !(WebPCheckCropDimensions(tls, width, height, x, y, cw, ch) != 0) {
   1836 				return int32(VP8_STATUS_INVALID_PARAM) // out of frame boundary.
   1837 			}
   1838 			width = cw
   1839 			height = ch
   1840 		}
   1841 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0 {
   1842 			**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
   1843 			**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
   1844 			if !(WebPRescalerGetScaledDimensions(tls, width, height, bp, bp+4) != 0) {
   1845 				return int32(VP8_STATUS_INVALID_PARAM)
   1846 			}
   1847 			width = **(**int32)(__ccgo_up(bp))
   1848 			height = **(**int32)(__ccgo_up(bp + 4))
   1849 		}
   1850 	}
   1851 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth = width
   1852 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight = height
   1853 	// Then, allocate buffer for real.
   1854 	status = AllocateBuffer(tls, buffer)
   1855 	if status != int32(VP8_STATUS_OK) {
   1856 		return status
   1857 	}
   1858 	// Use the stride trick if vertical flip is needed.
   1859 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   1860 		status = WebPFlipBuffer(tls, buffer)
   1861 	}
   1862 	return status
   1863 }
   1864 
   1865 //------------------------------------------------------------------------------
   1866 // constructors / destructors
   1867 
   1868 func WebPInitDecBufferInternal(tls *libc.TLS, buffer uintptr, version int32) (r int32) {
   1869 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
   1870 		return 0 // version mismatch
   1871 	}
   1872 	if buffer == libc.UintptrFromInt32(0) {
   1873 		return 0
   1874 	}
   1875 	libc.Xmemset(tls, buffer, 0, uint64(120))
   1876 	return int32(1)
   1877 }
   1878 
   1879 func WebPFreeDecBuffer(tls *libc.TLS, buffer uintptr) {
   1880 	if buffer != libc.UintptrFromInt32(0) {
   1881 		if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 {
   1882 			WebPSafeFree(tls, (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory)
   1883 		}
   1884 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = libc.UintptrFromInt32(0)
   1885 	}
   1886 }
   1887 
   1888 func WebPCopyDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   1889 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   1890 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   1891 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   1892 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fis_external_memory = int32(1) // dst buffer doesn't own the memory.
   1893 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fprivate_memory = libc.UintptrFromInt32(0)
   1894 		}
   1895 	}
   1896 }
   1897 
   1898 // C documentation
   1899 //
   1900 //	// Copy and transfer ownership from src to dst (beware of parameter order!)
   1901 func WebPGrabDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   1902 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   1903 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   1904 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   1905 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fis_external_memory = int32(1) // src relinquishes ownership
   1906 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory = libc.UintptrFromInt32(0)
   1907 		}
   1908 	}
   1909 }
   1910 
   1911 func WebPCopyDecBufferPixels(tls *libc.TLS, src_buf uintptr, dst_buf uintptr) (r VP8StatusCode1) {
   1912 	var dst, dst1, src, src1 uintptr
   1913 	var v1, v4 int32
   1914 	var v3, v6 WEBP_CSP_MODE1
   1915 	var v9 bool
   1916 	_, _, _, _, _, _, _, _, _ = dst, dst1, src, src1, v1, v3, v4, v6, v9
   1917 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fwidth = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth
   1918 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fheight = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight
   1919 	if CheckDecBuffer(tls, dst_buf) != int32(VP8_STATUS_OK) {
   1920 		return int32(VP8_STATUS_INVALID_PARAM)
   1921 	}
   1922 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace < int32(MODE_YUV))
   1923 	goto _2
   1924 _2:
   1925 	if v1 != 0 {
   1926 		src = src_buf + 16
   1927 		dst = dst_buf + 16
   1928 		WebPCopyPlane(tls, (*WebPRGBABuffer)(unsafe.Pointer(src)).Frgba, (*WebPRGBABuffer)(unsafe.Pointer(src)).Fstride, (*WebPRGBABuffer)(unsafe.Pointer(dst)).Frgba, (*WebPRGBABuffer)(unsafe.Pointer(dst)).Fstride, (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth*libc.Int32FromUint8(kModeBpp[(*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace]), (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight)
   1929 	} else {
   1930 		src1 = src_buf + 16
   1931 		dst1 = dst_buf + 16
   1932 		WebPCopyPlane(tls, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fy, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fy_stride, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fy, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fy_stride, (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth, (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight)
   1933 		WebPCopyPlane(tls, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fu, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fu_stride, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fu, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fu_stride, ((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth+int32(1))/int32(2), ((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight+int32(1))/int32(2))
   1934 		WebPCopyPlane(tls, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fv, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fv_stride, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fv, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fv_stride, ((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth+int32(1))/int32(2), ((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight+int32(1))/int32(2))
   1935 		v3 = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace
   1936 		if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   1937 			v6 = v3
   1938 			v4 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   1939 			goto _8
   1940 		_8:
   1941 		}
   1942 		v1 = libc.BoolInt32(v9 || v4 != 0)
   1943 		goto _5
   1944 	_5:
   1945 		if v1 != 0 {
   1946 			WebPCopyPlane(tls, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fa, (*WebPYUVABuffer)(unsafe.Pointer(src1)).Fa_stride, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fa, (*WebPYUVABuffer)(unsafe.Pointer(dst1)).Fa_stride, (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth, (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight)
   1947 		}
   1948 	}
   1949 	return int32(VP8_STATUS_OK)
   1950 }
   1951 
   1952 func WebPAvoidSlowMemory(tls *libc.TLS, output uintptr, features uintptr) (r int32) {
   1953 	var v1 WEBP_CSP_MODE1
   1954 	var v2 int32
   1955 	var v4 bool
   1956 	_, _, _ = v1, v2, v4
   1957 	if v4 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fis_external_memory >= int32(2); v4 {
   1958 		v1 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace
   1959 		v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   1960 		goto _3
   1961 	_3:
   1962 	}
   1963 	return libc.BoolInt32(v4 && v2 != 0 && (features != libc.UintptrFromInt32(0) && (*WebPBitstreamFeatures)(unsafe.Pointer(features)).Fhas_alpha != 0))
   1964 }
   1965 
   1966 const DITHER_AMP_TAB_SIZE = 12
   1967 const MIN_DITHER_AMP = 4
   1968 
   1969 var kHashMul2 = uint32(0x1e35a7bd)
   1970 
   1971 //------------------------------------------------------------------------------
   1972 
   1973 // Copyright 2010 Google Inc. All Rights Reserved.
   1974 //
   1975 // Use of this source code is governed by a BSD-style license
   1976 // that can be found in the COPYING file in the root of the source
   1977 // tree. An additional intellectual property rights grant can be found
   1978 // in the file PATENTS. All contributing project authors may
   1979 // be found in the AUTHORS file in the root of the source tree.
   1980 // -----------------------------------------------------------------------------
   1981 //
   1982 //  Main decoding functions for WebP images.
   1983 //
   1984 // Author: Skal (pascal.massimino@gmail.com)
   1985 
   1986 // Copyright 2010 Google Inc. All Rights Reserved.
   1987 //
   1988 // Use of this source code is governed by a BSD-style license
   1989 // that can be found in the COPYING file in the root of the source
   1990 // tree. An additional intellectual property rights grant can be found
   1991 // in the file PATENTS. All contributing project authors may
   1992 // be found in the AUTHORS file in the root of the source tree.
   1993 // -----------------------------------------------------------------------------
   1994 //
   1995 //  Common types + memory wrappers
   1996 //
   1997 // Author: Skal (pascal.massimino@gmail.com)
   1998 
   1999 //------------------------------------------------------------------------------
   2000 // Main reconstruction function.
   2001 
   2002 var kScan = [16]uint16_t{
   2003 	1:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2004 	2:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2005 	3:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2006 	4:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2007 	5:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2008 	6:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2009 	7:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2010 	8:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2011 	9:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2012 	10: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2013 	11: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2014 	12: libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2015 	13: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2016 	14: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2017 	15: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2018 }
   2019 
   2020 func CheckMode(tls *libc.TLS, mb_x int32, mb_y int32, mode int32) (r int32) {
   2021 	var v1 int32
   2022 	_ = v1
   2023 	if mode == int32(B_DC_PRED) {
   2024 		if mb_x == 0 {
   2025 			if mb_y == 0 {
   2026 				v1 = int32(B_DC_PRED_NOTOPLEFT)
   2027 			} else {
   2028 				v1 = int32(B_DC_PRED_NOLEFT)
   2029 			}
   2030 			return v1
   2031 		} else {
   2032 			if mb_y == 0 {
   2033 				v1 = int32(B_DC_PRED_NOTOP)
   2034 			} else {
   2035 				v1 = int32(B_DC_PRED)
   2036 			}
   2037 			return v1
   2038 		}
   2039 	}
   2040 	return mode
   2041 }
   2042 
   2043 func Copy32b(tls *libc.TLS, dst uintptr, src uintptr) {
   2044 	libc.Xmemcpy(tls, dst, src, uint64(4))
   2045 }
   2046 
   2047 func DoTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2048 	switch bits >> libc.Int32FromInt32(30) {
   2049 	case uint32(3):
   2050 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, src, dst, 0)
   2051 	case uint32(2):
   2052 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformAC3})))(tls, src, dst)
   2053 	case uint32(1):
   2054 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, src, dst)
   2055 	default:
   2056 		break
   2057 	}
   2058 }
   2059 
   2060 func DoUVTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2061 	if bits&uint32(0xff) != 0 { // any non-zero coeff at all?
   2062 		if bits&uint32(0xaa) != 0 { // any non-zero AC coefficient?
   2063 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformUV})))(tls, src, dst) // note we don't use the AC3 variant for U/V
   2064 		} else {
   2065 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDCUV})))(tls, src, dst)
   2066 		}
   2067 	}
   2068 }
   2069 
   2070 func ReconstructRow(tls *libc.TLS, dec uintptr, ctx uintptr) {
   2071 	var bits, bits_uv, v8, v9 uint32_t
   2072 	var block, coeffs, dst, top_right, top_yuv, u_dst, u_out, v_dst, v_out, y_dst, y_out uintptr
   2073 	var cache_id, j, mb_x, mb_y, n, pred_func, pred_func1, uv_offset, y_offset int32
   2074 	var v3, v4 uint8_t
   2075 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bits, bits_uv, block, cache_id, coeffs, dst, j, mb_x, mb_y, n, pred_func, pred_func1, top_right, top_yuv, u_dst, u_out, uv_offset, v_dst, v_out, y_dst, y_offset, y_out, v3, v4, v8, v9
   2076 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2077 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2078 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(1)+libc.Int32FromInt32(8))
   2079 	u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(1)+libc.Int32FromInt32(8)+libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16)+libc.Int32FromInt32(BPS))
   2080 	v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(1)+libc.Int32FromInt32(8)+libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16)+libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))
   2081 	// Initialize left-most block.
   2082 	j = 0
   2083 	for {
   2084 		if !(j < int32(16)) {
   2085 			break
   2086 		}
   2087 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2088 		goto _1
   2089 	_1:
   2090 		;
   2091 		j = j + 1
   2092 	}
   2093 	j = 0
   2094 	for {
   2095 		if !(j < int32(8)) {
   2096 			break
   2097 		}
   2098 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2099 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2100 		goto _2
   2101 	_2:
   2102 		;
   2103 		j = j + 1
   2104 	}
   2105 	// Init top-left sample on left column too.
   2106 	if mb_y > 0 {
   2107 		v4 = libc.Uint8FromInt32(129)
   2108 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v4
   2109 		v3 = v4
   2110 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2111 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2112 	} else {
   2113 		// we only need to do this init once at block (0,0).
   2114 		// Afterward, it remains valid for the whole topmost row.
   2115 		libc.Xmemset(tls, y_dst-uintptr(BPS)-uintptr(1), int32(127), libc.Uint64FromInt32(libc.Int32FromInt32(16)+libc.Int32FromInt32(4)+libc.Int32FromInt32(1)))
   2116 		libc.Xmemset(tls, u_dst-uintptr(BPS)-uintptr(1), int32(127), libc.Uint64FromInt32(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2117 		libc.Xmemset(tls, v_dst-uintptr(BPS)-uintptr(1), int32(127), libc.Uint64FromInt32(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2118 	}
   2119 	// Reconstruct one row.
   2120 	mb_x = 0
   2121 	for {
   2122 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   2123 			break
   2124 		}
   2125 		block = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2126 		// Rotate in the left samples from previously decoded block. We move four
   2127 		// pixels at a time for alignment reason, and because of in-loop filter.
   2128 		if mb_x > 0 {
   2129 			j = -int32(1)
   2130 			for {
   2131 				if !(j < int32(16)) {
   2132 					break
   2133 				}
   2134 				Copy32b(tls, y_dst+uintptr(j*int32(BPS)-int32(4)), y_dst+uintptr(j*int32(BPS)+int32(12)))
   2135 				goto _6
   2136 			_6:
   2137 				;
   2138 				j = j + 1
   2139 			}
   2140 			j = -int32(1)
   2141 			for {
   2142 				if !(j < int32(8)) {
   2143 					break
   2144 				}
   2145 				Copy32b(tls, u_dst+uintptr(j*int32(BPS)-int32(4)), u_dst+uintptr(j*int32(BPS)+int32(4)))
   2146 				Copy32b(tls, v_dst+uintptr(j*int32(BPS)-int32(4)), v_dst+uintptr(j*int32(BPS)+int32(4)))
   2147 				goto _7
   2148 			_7:
   2149 				;
   2150 				j = j + 1
   2151 			}
   2152 		}
   2153 		// bring top samples into the cache
   2154 		top_yuv = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t + uintptr(mb_x)*32
   2155 		coeffs = block
   2156 		bits = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y
   2157 		if mb_y > 0 {
   2158 			libc.Xmemcpy(tls, y_dst-uintptr(BPS), top_yuv, uint64(16))
   2159 			libc.Xmemcpy(tls, u_dst-uintptr(BPS), top_yuv+16, uint64(8))
   2160 			libc.Xmemcpy(tls, v_dst-uintptr(BPS), top_yuv+24, uint64(8))
   2161 		}
   2162 		// predict and add residuals
   2163 		if (*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0 { // 4x4
   2164 			top_right = y_dst - libc.UintptrFromInt32(BPS) + libc.UintptrFromInt32(16)
   2165 			if mb_y > 0 {
   2166 				if mb_x >= (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w-int32(1) { // on rightmost border
   2167 					libc.Xmemset(tls, top_right, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_yuv + 15))), uint64(4))
   2168 				} else {
   2169 					libc.Xmemcpy(tls, top_right, top_yuv+1*32, uint64(4))
   2170 				}
   2171 			}
   2172 			// replicate the top-right pixels below
   2173 			v9 = **(**uint32_t)(__ccgo_up(top_right))
   2174 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS))*4)) = v9
   2175 			v8 = v9
   2176 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS))*4)) = v8
   2177 			**(**uint32_t)(__ccgo_up(top_right + 32*4)) = v8
   2178 			// predict and add residuals for all 4x4 blocks in turn.
   2179 			n = 0
   2180 			for {
   2181 				if !(n < int32(16)) {
   2182 					break
   2183 				}
   2184 				dst = y_dst + uintptr(kScan[n])
   2185 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma4[**(**uint8_t)(__ccgo_up(block + 769 + uintptr(n)))]})))(tls, dst)
   2186 				DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, dst)
   2187 				goto _10
   2188 			_10:
   2189 				;
   2190 				n = n + 1
   2191 				bits = bits << uint32(2)
   2192 			}
   2193 		} else { // 16x16
   2194 			pred_func = CheckMode(tls, mb_x, mb_y, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(block + 769))))
   2195 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma16[pred_func]})))(tls, y_dst)
   2196 			if bits != uint32(0) {
   2197 				n = 0
   2198 				for {
   2199 					if !(n < int32(16)) {
   2200 						break
   2201 					}
   2202 					DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, y_dst+uintptr(kScan[n]))
   2203 					goto _11
   2204 				_11:
   2205 					;
   2206 					n = n + 1
   2207 					bits = bits << uint32(2)
   2208 				}
   2209 			}
   2210 		}
   2211 		// Chroma
   2212 		bits_uv = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv
   2213 		pred_func1 = CheckMode(tls, mb_x, mb_y, libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(block)).Fuvmode))
   2214 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, u_dst)
   2215 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, v_dst)
   2216 		DoUVTransform(tls, bits_uv>>0, coeffs+uintptr(libc.Int32FromInt32(16)*libc.Int32FromInt32(16))*2, u_dst)
   2217 		DoUVTransform(tls, bits_uv>>int32(8), coeffs+uintptr(libc.Int32FromInt32(20)*libc.Int32FromInt32(16))*2, v_dst)
   2218 		// stash away top samples for next block
   2219 		if mb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h-int32(1) {
   2220 			libc.Xmemcpy(tls, top_yuv, y_dst+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
   2221 			libc.Xmemcpy(tls, top_yuv+16, u_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2222 			libc.Xmemcpy(tls, top_yuv+24, v_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2223 		}
   2224 		// Transfer reconstructed samples from yuv_b cache to final destination.
   2225 		y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2226 		uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2227 		y_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(mb_x*int32(16)) + uintptr(y_offset)
   2228 		u_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2229 		v_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2230 		j = 0
   2231 		for {
   2232 			if !(j < int32(16)) {
   2233 				break
   2234 			}
   2235 			libc.Xmemcpy(tls, y_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), y_dst+uintptr(j*int32(BPS)), uint64(16))
   2236 			goto _12
   2237 		_12:
   2238 			;
   2239 			j = j + 1
   2240 		}
   2241 		j = 0
   2242 		for {
   2243 			if !(j < int32(8)) {
   2244 				break
   2245 			}
   2246 			libc.Xmemcpy(tls, u_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), u_dst+uintptr(j*int32(BPS)), uint64(8))
   2247 			libc.Xmemcpy(tls, v_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), v_dst+uintptr(j*int32(BPS)), uint64(8))
   2248 			goto _13
   2249 		_13:
   2250 			;
   2251 			j = j + 1
   2252 		}
   2253 		goto _5
   2254 	_5:
   2255 		;
   2256 		mb_x = mb_x + 1
   2257 	}
   2258 }
   2259 
   2260 //------------------------------------------------------------------------------
   2261 // Filtering
   2262 
   2263 // C documentation
   2264 //
   2265 //	// kFilterExtraRows[] = How many extra lines are needed on the MB boundary
   2266 //	// for caching, given a filtering level.
   2267 //	// Simple filter:  up to 2 luma samples are read and 1 is written.
   2268 //	// Complex filter: up to 4 luma samples are read and 3 are written. Same for
   2269 //	//                 U/V, so it's 8 samples total (because of the 2x upsampling).
   2270 var kFilterExtraRows = [3]uint8_t{
   2271 	1: uint8(2),
   2272 	2: uint8(8),
   2273 }
   2274 
   2275 func DoFilter(tls *libc.TLS, dec uintptr, mb_x int32, mb_y int32) {
   2276 	var cache_id, hev_thresh, ilevel, limit, uv_bps, y_bps int32
   2277 	var ctx, f_info, u_dst, v_dst, y_dst uintptr
   2278 	_, _, _, _, _, _, _, _, _, _, _ = cache_id, ctx, f_info, hev_thresh, ilevel, limit, u_dst, uv_bps, v_dst, y_bps, y_dst
   2279 	ctx = dec + 216
   2280 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2281 	y_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2282 	f_info = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info + uintptr(mb_x)*4
   2283 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(cache_id*int32(16)*y_bps) + uintptr(mb_x*int32(16))
   2284 	ilevel = libc.Int32FromUint8((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_ilevel)
   2285 	limit = libc.Int32FromUint8((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_limit)
   2286 	if limit == 0 {
   2287 		return
   2288 	}
   2289 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(1) { // simple
   2290 		if mb_x > 0 {
   2291 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2292 		}
   2293 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2294 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, y_bps, limit)
   2295 		}
   2296 		if mb_y > 0 {
   2297 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2298 		}
   2299 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2300 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, y_bps, limit)
   2301 		}
   2302 	} else { // complex
   2303 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2304 		u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2305 		v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2306 		hev_thresh = libc.Int32FromUint8((*VP8FInfo)(unsafe.Pointer(f_info)).Fhev_thresh)
   2307 		if mb_x > 0 {
   2308 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2309 			(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter8})))(tls, u_dst, v_dst, uv_bps, limit+int32(4), ilevel, hev_thresh)
   2310 		}
   2311 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2312 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2313 			(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter8i})))(tls, u_dst, v_dst, uv_bps, limit, ilevel, hev_thresh)
   2314 		}
   2315 		if mb_y > 0 {
   2316 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2317 			(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter8})))(tls, u_dst, v_dst, uv_bps, limit+int32(4), ilevel, hev_thresh)
   2318 		}
   2319 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2320 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2321 			(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter8i})))(tls, u_dst, v_dst, uv_bps, limit, ilevel, hev_thresh)
   2322 		}
   2323 	}
   2324 }
   2325 
   2326 // C documentation
   2327 //
   2328 //	// Filter the decoded macroblock row (if needed)
   2329 func FilterRow(tls *libc.TLS, dec uintptr) {
   2330 	var mb_x, mb_y int32
   2331 	_, _ = mb_x, mb_y
   2332 	mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_y
   2333 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2334 	for {
   2335 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2336 			break
   2337 		}
   2338 		DoFilter(tls, dec, mb_x, mb_y)
   2339 		goto _1
   2340 	_1:
   2341 		;
   2342 		mb_x = mb_x + 1
   2343 	}
   2344 }
   2345 
   2346 //------------------------------------------------------------------------------
   2347 // Precompute the filtering strength for each segment and each i4x4/i16x16 mode.
   2348 
   2349 func PrecomputeFilterStrengths(tls *libc.TLS, dec uintptr) {
   2350 	var base_level, i4x4, ilevel, level, s, v3, v4 int32
   2351 	var hdr, info uintptr
   2352 	_, _, _, _, _, _, _, _, _ = base_level, hdr, i4x4, ilevel, info, level, s, v3, v4
   2353 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2354 		hdr = dec + 84
   2355 		s = 0
   2356 		for {
   2357 			if !(s < int32(NUM_MB_SEGMENTS)) {
   2358 				break
   2359 			}
   2360 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fuse_segment != 0 {
   2361 				base_level = int32(**(**int8_t)(__ccgo_up(dec + 132 + 16 + uintptr(s))))
   2362 				if !((*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fabsolute_delta != 0) {
   2363 					base_level = base_level + (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2364 				}
   2365 			} else {
   2366 				base_level = (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2367 			}
   2368 			i4x4 = 0
   2369 			for {
   2370 				if !(i4x4 <= int32(1)) {
   2371 					break
   2372 				}
   2373 				info = dec + 2924 + uintptr(s)*8 + uintptr(i4x4)*4
   2374 				level = base_level
   2375 				if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
   2376 					level = level + **(**int32)(__ccgo_up(hdr + 16))
   2377 					if i4x4 != 0 {
   2378 						level = level + **(**int32)(__ccgo_up(hdr + 32))
   2379 					}
   2380 				}
   2381 				if level < 0 {
   2382 					v3 = 0
   2383 				} else {
   2384 					if level > int32(63) {
   2385 						v4 = int32(63)
   2386 					} else {
   2387 						v4 = level
   2388 					}
   2389 					v3 = v4
   2390 				}
   2391 				level = v3
   2392 				if level > 0 {
   2393 					ilevel = level
   2394 					if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > 0 {
   2395 						if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > int32(4) {
   2396 							ilevel = ilevel >> int32(2)
   2397 						} else {
   2398 							ilevel = ilevel >> int32(1)
   2399 						}
   2400 						if ilevel > int32(9)-(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness {
   2401 							ilevel = int32(9) - (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness
   2402 						}
   2403 					}
   2404 					if ilevel < int32(1) {
   2405 						ilevel = int32(1)
   2406 					}
   2407 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_ilevel = libc.Uint8FromInt32(ilevel)
   2408 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = libc.Uint8FromInt32(int32(2)*level + ilevel)
   2409 					if level >= int32(40) {
   2410 						v3 = int32(2)
   2411 					} else {
   2412 						if level >= int32(15) {
   2413 							v4 = int32(1)
   2414 						} else {
   2415 							v4 = 0
   2416 						}
   2417 						v3 = v4
   2418 					}
   2419 					(*VP8FInfo)(unsafe.Pointer(info)).Fhev_thresh = libc.Uint8FromInt32(v3)
   2420 				} else {
   2421 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = uint8(0) // no filtering
   2422 				}
   2423 				(*VP8FInfo)(unsafe.Pointer(info)).Ff_inner = libc.Uint8FromInt32(i4x4)
   2424 				goto _2
   2425 			_2:
   2426 				;
   2427 				i4x4 = i4x4 + 1
   2428 			}
   2429 			goto _1
   2430 		_1:
   2431 			;
   2432 			s = s + 1
   2433 		}
   2434 	}
   2435 }
   2436 
   2437 //------------------------------------------------------------------------------
   2438 // Dithering
   2439 
   2440 // minimal amp that will provide a non-zero dithering effect
   2441 
   2442 var kQuantToDitherAmp = [12]uint8_t{
   2443 	0:  uint8(8),
   2444 	1:  uint8(7),
   2445 	2:  uint8(6),
   2446 	3:  uint8(4),
   2447 	4:  uint8(4),
   2448 	5:  uint8(2),
   2449 	6:  uint8(2),
   2450 	7:  uint8(2),
   2451 	8:  uint8(1),
   2452 	9:  uint8(1),
   2453 	10: uint8(1),
   2454 	11: uint8(1),
   2455 }
   2456 
   2457 func VP8InitDithering(tls *libc.TLS, options uintptr, dec uintptr) {
   2458 	var all_amp, d, f, idx, max_amp, s, v1, v2, v4 int32
   2459 	var dqm uintptr
   2460 	_, _, _, _, _, _, _, _, _, _ = all_amp, d, dqm, f, idx, max_amp, s, v1, v2, v4
   2461 	if options != libc.UintptrFromInt32(0) {
   2462 		d = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fdithering_strength
   2463 		max_amp = libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX) - libc.Int32FromInt32(1)
   2464 		if d < 0 {
   2465 			v1 = 0
   2466 		} else {
   2467 			if d > int32(100) {
   2468 				v2 = max_amp
   2469 			} else {
   2470 				v2 = d * max_amp / int32(100)
   2471 			}
   2472 			v1 = v2
   2473 		}
   2474 		f = v1
   2475 		if f > 0 {
   2476 			all_amp = 0
   2477 			s = 0
   2478 			for {
   2479 				if !(s < int32(NUM_MB_SEGMENTS)) {
   2480 					break
   2481 				}
   2482 				dqm = dec + 1060 + uintptr(s)*32
   2483 				if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < int32(DITHER_AMP_TAB_SIZE) {
   2484 					if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < 0 {
   2485 						v4 = 0
   2486 					} else {
   2487 						v4 = (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant
   2488 					}
   2489 					idx = v4
   2490 					(*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither = f * libc.Int32FromUint8(kQuantToDitherAmp[idx]) >> int32(3)
   2491 				}
   2492 				all_amp = all_amp | (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither
   2493 				goto _3
   2494 			_3:
   2495 				;
   2496 				s = s + 1
   2497 			}
   2498 			if all_amp != 0 {
   2499 				VP8InitRandom(tls, dec+828, libc.Float32FromFloat32(1))
   2500 				(*VP8Decoder)(unsafe.Pointer(dec)).Fdither = int32(1)
   2501 			}
   2502 		}
   2503 		// potentially allow alpha dithering
   2504 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = (*WebPDecoderOptions)(unsafe.Pointer(options)).Falpha_dithering_strength
   2505 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > int32(100) {
   2506 			(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = int32(100)
   2507 		} else {
   2508 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering < 0 {
   2509 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0
   2510 			}
   2511 		}
   2512 	}
   2513 }
   2514 
   2515 // C documentation
   2516 //
   2517 //	// Convert to range: [-2,2] for dither=50, [-4,4] for dither=100
   2518 func Dither8x8(tls *libc.TLS, rg1 uintptr, dst uintptr, bps int32, amp1 int32) {
   2519 	bp := tls.Alloc(64)
   2520 	defer tls.Free(64)
   2521 	var diff, i, v3, v4, v6, v8 int32
   2522 	var v2, v5, v7 uintptr
   2523 	var _ /* dither at bp+0 */ [64]uint8_t
   2524 	_, _, _, _, _, _, _, _, _ = diff, i, v2, v3, v4, v5, v6, v7, v8
   2525 	i = 0
   2526 	for {
   2527 		if !(i < libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) {
   2528 			break
   2529 		}
   2530 		v2 = rg1
   2531 		v3 = libc.Int32FromInt32(VP8_DITHER_AMP_BITS) + libc.Int32FromInt32(1)
   2532 		diff = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(v2 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v2)).Findex1)*4)) - **(**uint32_t)(__ccgo_up(v2 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v2)).Findex2)*4)))
   2533 		if diff < libc.Int32FromInt32(0) {
   2534 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
   2535 		}
   2536 		**(**uint32_t)(__ccgo_up(v2 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v2)).Findex1)*4)) = libc.Uint32FromInt32(diff)
   2537 		v5 = v2
   2538 		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
   2539 		v4 = *(*int32)(unsafe.Pointer(v5))
   2540 		if v4 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2541 			(*VP8Random)(unsafe.Pointer(v2)).Findex1 = 0
   2542 		}
   2543 		v7 = v2 + 4
   2544 		*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
   2545 		v6 = *(*int32)(unsafe.Pointer(v7))
   2546 		if v6 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2547 			(*VP8Random)(unsafe.Pointer(v2)).Findex2 = 0
   2548 		}
   2549 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v3)
   2550 		diff = diff * amp1 >> int32(VP8_RANDOM_DITHER_FIX)
   2551 		diff = diff + int32(1)<<(v3-int32(1))
   2552 		v8 = diff
   2553 		goto _9
   2554 	_9:
   2555 		(**(**[64]uint8_t)(__ccgo_up(bp)))[i] = libc.Uint8FromInt32(v8)
   2556 		goto _1
   2557 	_1:
   2558 		;
   2559 		i = i + 1
   2560 	}
   2561 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8DitherCombine8x8})))(tls, bp, dst, bps)
   2562 }
   2563 
   2564 func DitherRow(tls *libc.TLS, dec uintptr) {
   2565 	var cache_id, mb_x, uv_bps int32
   2566 	var ctx, data, u_dst, v_dst uintptr
   2567 	_, _, _, _, _, _, _ = cache_id, ctx, data, mb_x, u_dst, uv_bps, v_dst
   2568 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2569 	for {
   2570 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2571 			break
   2572 		}
   2573 		ctx = dec + 216
   2574 		data = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2575 		cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2576 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2577 		if libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(data)).Fdither) >= int32(MIN_DITHER_AMP) {
   2578 			u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2579 			v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2580 			Dither8x8(tls, dec+828, u_dst, uv_bps, libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2581 			Dither8x8(tls, dec+828, v_dst, uv_bps, libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2582 		}
   2583 		goto _1
   2584 	_1:
   2585 		;
   2586 		mb_x = mb_x + 1
   2587 	}
   2588 }
   2589 
   2590 //------------------------------------------------------------------------------
   2591 // This function is called after a row of macroblocks is finished decoding.
   2592 // It also takes into account the following restrictions:
   2593 //  * In case of in-loop filtering, we must hold off sending some of the bottom
   2594 //    pixels as they are yet unfiltered. They will be when the next macroblock
   2595 //    row is decoded. Meanwhile, we must preserve them by rotating them in the
   2596 //    cache area. This doesn't hold for the very bottom row of the uncropped
   2597 //    picture of course.
   2598 //  * we must clip the remaining pixels against the cropping area. The VP8Io
   2599 //    struct must have the following fields set correctly before calling put():
   2600 
   2601 // C documentation
   2602 //
   2603 //	// Finalize and transmit a complete row. Return false in case of user-abort.
   2604 func FinishRow(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
   2605 	var cache_id, delta_y, extra_y_rows, is_first_row, is_last_row, mb_y, ok, uv_offset, uvsize, y_end, y_offset, y_start, ysize int32
   2606 	var ctx, dec, io, udst, vdst, ydst uintptr
   2607 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cache_id, ctx, dec, delta_y, extra_y_rows, io, is_first_row, is_last_row, mb_y, ok, udst, uv_offset, uvsize, vdst, y_end, y_offset, y_start, ydst, ysize
   2608 	dec = arg1
   2609 	io = arg2
   2610 	ok = int32(1)
   2611 	ctx = dec + 216
   2612 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2613 	extra_y_rows = libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2614 	ysize = extra_y_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2615 	uvsize = extra_y_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2616 	y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2617 	uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2618 	ydst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y - uintptr(ysize) + uintptr(y_offset)
   2619 	udst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u - uintptr(uvsize) + uintptr(uv_offset)
   2620 	vdst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v - uintptr(uvsize) + uintptr(uv_offset)
   2621 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2622 	is_first_row = libc.BoolInt32(mb_y == libc.Int32FromInt32(0))
   2623 	is_last_row = libc.BoolInt32(mb_y >= (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y-libc.Int32FromInt32(1))
   2624 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2625 		ReconstructRow(tls, dec, ctx)
   2626 	}
   2627 	if (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row != 0 {
   2628 		FilterRow(tls, dec)
   2629 	}
   2630 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fdither != 0 {
   2631 		DitherRow(tls, dec)
   2632 	}
   2633 	if (*VP8Io)(unsafe.Pointer(io)).Fput != libc.UintptrFromInt32(0) {
   2634 		y_start = mb_y * int32(16)
   2635 		y_end = (mb_y + int32(1)) * int32(16)
   2636 		if !(is_first_row != 0) {
   2637 			y_start = y_start - extra_y_rows
   2638 			(*VP8Io)(unsafe.Pointer(io)).Fy = ydst
   2639 			(*VP8Io)(unsafe.Pointer(io)).Fu = udst
   2640 			(*VP8Io)(unsafe.Pointer(io)).Fv = vdst
   2641 		} else {
   2642 			(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(y_offset)
   2643 			(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(uv_offset)
   2644 			(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(uv_offset)
   2645 		}
   2646 		if !(is_last_row != 0) {
   2647 			y_end = y_end - extra_y_rows
   2648 		}
   2649 		if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   2650 			y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
   2651 		}
   2652 		// If dec->alpha_data is not NULL, we have some alpha plane present.
   2653 		(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   2654 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && y_start < y_end {
   2655 			(*VP8Io)(unsafe.Pointer(io)).Fa = VP8DecompressAlphaRows(tls, dec, io, y_start, y_end-y_start)
   2656 			if (*VP8Io)(unsafe.Pointer(io)).Fa == libc.UintptrFromInt32(0) {
   2657 				return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+37)
   2658 			}
   2659 		}
   2660 		if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
   2661 			delta_y = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
   2662 			y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2663 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride * delta_y)
   2664 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2665 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2666 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2667 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth * delta_y)
   2668 			}
   2669 		}
   2670 		if y_start < y_end {
   2671 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2672 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2673 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2674 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2675 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2676 			}
   2677 			(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2678 			(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
   2679 			(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
   2680 			ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fput})))(tls, io)
   2681 		}
   2682 	}
   2683 	// rotate top samples if needed
   2684 	if cache_id+int32(1) == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   2685 		if !(is_last_row != 0) {
   2686 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y-uintptr(ysize), ydst+uintptr(int32(16)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), libc.Uint64FromInt32(ysize))
   2687 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u-uintptr(uvsize), udst+uintptr(int32(8)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), libc.Uint64FromInt32(uvsize))
   2688 			libc.Xmemcpy(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v-uintptr(uvsize), vdst+uintptr(int32(8)*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), libc.Uint64FromInt32(uvsize))
   2689 		}
   2690 	}
   2691 	return ok
   2692 }
   2693 
   2694 //------------------------------------------------------------------------------
   2695 
   2696 func VP8ProcessRow(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   2697 	var ctx, tmp, tmp1, worker, v2 uintptr
   2698 	var filter_row, ok, v1 int32
   2699 	_, _, _, _, _, _, _, _ = ctx, filter_row, ok, tmp, tmp1, worker, v1, v2
   2700 	ok = int32(1)
   2701 	ctx = dec + 216
   2702 	filter_row = libc.BoolInt32((*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 && (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y >= (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y && (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y <= (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y)
   2703 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == 0 {
   2704 		// ctx->id and ctx->f_info are already set
   2705 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   2706 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   2707 		ReconstructRow(tls, dec, ctx)
   2708 		ok = FinishRow(tls, dec, io)
   2709 	} else {
   2710 		worker = dec + 152
   2711 		// Finish previous job *before* updating context
   2712 		ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
   2713 		if ok != 0 { // spawn a new deblocking/output job
   2714 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fio = **(**VP8Io)(__ccgo_up(io))
   2715 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id
   2716 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   2717 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   2718 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) { // swap macroblock data
   2719 				tmp = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data
   2720 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data
   2721 				(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = tmp
   2722 			} else {
   2723 				// perform reconstruction directly in main thread
   2724 				ReconstructRow(tls, dec, ctx)
   2725 			}
   2726 			if filter_row != 0 { // swap filter info
   2727 				tmp1 = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info
   2728 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   2729 				(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = tmp1
   2730 			}
   2731 			// (reconstruct)+filter in parallel
   2732 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
   2733 			v2 = dec + 204
   2734 			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
   2735 			v1 = *(*int32)(unsafe.Pointer(v2))
   2736 			if v1 == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   2737 				(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   2738 			}
   2739 		}
   2740 	}
   2741 	return ok
   2742 }
   2743 
   2744 //------------------------------------------------------------------------------
   2745 // Finish setting up the decoding parameter once user's setup() is called.
   2746 
   2747 func VP8EnterCritical(tls *libc.TLS, dec uintptr, io uintptr) (r VP8StatusCode1) {
   2748 	var extra_pixels int32
   2749 	_ = extra_pixels
   2750 	// Call setup() first. This may trigger additional decoding features on 'io'.
   2751 	// Note: Afterward, we must call teardown() no matter what.
   2752 	if (*VP8Io)(unsafe.Pointer(io)).Fsetup != libc.UintptrFromInt32(0) && !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fsetup})))(tls, io) != 0) {
   2753 		VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+66)
   2754 		return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   2755 	}
   2756 	// Disable filtering per user request
   2757 	if (*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering != 0 {
   2758 		(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = 0
   2759 	}
   2760 	// Define the area where we can skip in-loop filtering, in case of cropping.
   2761 	//
   2762 	// 'Simple' filter reads two luma samples outside of the macroblock
   2763 	// and filters one. It doesn't filter the chroma samples. Hence, we can
   2764 	// avoid doing the in-loop filtering before crop_top/crop_left position.
   2765 	// For the 'Complex' filter, 3 samples are read and up to 3 are filtered.
   2766 	// Means: there's a dependency chain that goes all the way up to the
   2767 	// top-left corner of the picture (MB #0). We must filter all the previous
   2768 	// macroblocks.
   2769 	extra_pixels = libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2770 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(2) {
   2771 		// For complex filter, we need to preserve the dependency chain.
   2772 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   2773 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   2774 	} else {
   2775 		// For simple filter, we can filter only the cropped region.
   2776 		// We include 'extra_pixels' on the other side of the boundary, since
   2777 		// vertical or horizontal filtering of the previous macroblock can
   2778 		// modify some abutting pixels.
   2779 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_left - extra_pixels) >> int32(4)
   2780 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_top - extra_pixels) >> int32(4)
   2781 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x < 0 {
   2782 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   2783 		}
   2784 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y < 0 {
   2785 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   2786 		}
   2787 	}
   2788 	// We need some 'extra' pixels on the right/bottom.
   2789 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom + int32(15) + extra_pixels) >> int32(4)
   2790 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_right + int32(15) + extra_pixels) >> int32(4)
   2791 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w {
   2792 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   2793 	}
   2794 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h {
   2795 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h
   2796 	}
   2797 	PrecomputeFilterStrengths(tls, dec)
   2798 	return int32(VP8_STATUS_OK)
   2799 }
   2800 
   2801 func VP8ExitCritical(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   2802 	var ok int32
   2803 	_ = ok
   2804 	ok = int32(1)
   2805 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2806 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152)
   2807 	}
   2808 	if (*VP8Io)(unsafe.Pointer(io)).Fteardown != libc.UintptrFromInt32(0) {
   2809 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fteardown})))(tls, io)
   2810 	}
   2811 	return ok
   2812 }
   2813 
   2814 //------------------------------------------------------------------------------
   2815 // For multi-threaded decoding we need to use 3 rows of 16 pixels as delay line.
   2816 //
   2817 // Reason is: the deblocking filter cannot deblock the bottom horizontal edges
   2818 // immediately, and needs to wait for first few rows of the next macroblock to
   2819 // be decoded. Hence, deblocking is lagging behind by 4 or 8 pixels (depending
   2820 // on strength).
   2821 // With two threads, the vertical positions of the rows being decoded are:
   2822 // Decode:  [ 0..15][16..31][32..47][48..63][64..79][...
   2823 // Deblock:         [ 0..11][12..27][28..43][44..59][...
   2824 // If we use two threads and two caches of 16 pixels, the sequence would be:
   2825 // Decode:  [ 0..15][16..31][ 0..15!!][16..31][ 0..15][...
   2826 // Deblock:         [ 0..11][12..27!!][-4..11][12..27][...
   2827 // The problem occurs during row [12..15!!] that both the decoding and
   2828 // deblocking threads are writing simultaneously.
   2829 // With 3 cache lines, one get a safe write pattern:
   2830 // Decode:  [ 0..15][16..31][32..47][ 0..15][16..31][32..47][0..
   2831 // Deblock:         [ 0..11][12..27][28..43][-4..11][12..27][28...
   2832 // Note that multi-threaded output _without_ deblocking can make use of two
   2833 // cache lines of 16 pixels only, since there's no lagging behind. The decoding
   2834 // and output process have non-concurrent writing:
   2835 // Decode:  [ 0..15][16..31][ 0..15][16..31][...
   2836 // io->put:         [ 0..15][16..31][ 0..15][...
   2837 
   2838 // C documentation
   2839 //
   2840 //	// Initialize multi/single-thread worker
   2841 func InitThreadContext(tls *libc.TLS, dec uintptr) (r int32) {
   2842 	var worker uintptr
   2843 	var v1 int32
   2844 	_, _ = worker, v1
   2845 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   2846 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2847 		worker = dec + 152
   2848 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
   2849 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+85)
   2850 		}
   2851 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = dec
   2852 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = dec + 216 + 32
   2853 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(FinishRow)
   2854 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2855 			v1 = int32(3)
   2856 		} else {
   2857 			v1 = libc.Int32FromInt32(3) - libc.Int32FromInt32(1)
   2858 		}
   2859 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = v1
   2860 	} else {
   2861 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = int32(1)
   2862 	}
   2863 	return int32(1)
   2864 }
   2865 
   2866 func VP8GetThreadMethod(tls *libc.TLS, options uintptr, headers uintptr, width int32, height int32) (r int32) {
   2867 	if options == libc.UintptrFromInt32(0) || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_threads == 0 {
   2868 		return 0
   2869 	}
   2870 	_ = headers
   2871 	_ = width
   2872 	_ = height
   2873 	return 0
   2874 }
   2875 
   2876 //------------------------------------------------------------------------------
   2877 // Memory setup
   2878 
   2879 func AllocateMemory(tls *libc.TLS, dec uintptr) (r int32) {
   2880 	var alpha_size, needed, v5 uint64_t
   2881 	var cache_height, cache_size, f_info_size, intra_pred_mode_size, mb_data_size, mb_info_size, top_size, yuv_size size_t
   2882 	var extra_rows, extra_uv, extra_y, mb_w, num_caches, v2, v3, v6 int32
   2883 	var mem, v8 uintptr
   2884 	var v1, v4 uint64
   2885 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_size, cache_height, cache_size, extra_rows, extra_uv, extra_y, f_info_size, intra_pred_mode_size, mb_data_size, mb_info_size, mb_w, mem, needed, num_caches, top_size, yuv_size, v1, v2, v3, v4, v5, v6, v8
   2886 	num_caches = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches
   2887 	mb_w = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   2888 	// Note: we use 'size_t' when there's no overflow risk, uint64_t otherwise.
   2889 	intra_pred_mode_size = libc.Uint64FromInt32(int32(4)*mb_w) * uint64(1)
   2890 	top_size = uint64(32) * libc.Uint64FromInt32(mb_w)
   2891 	mb_info_size = libc.Uint64FromInt32(mb_w+libc.Int32FromInt32(1)) * uint64(2)
   2892 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2893 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2894 			v2 = int32(2)
   2895 		} else {
   2896 			v2 = int32(1)
   2897 		}
   2898 		v1 = libc.Uint64FromInt32(mb_w*v2) * uint64(4)
   2899 	} else {
   2900 		v1 = uint64(0)
   2901 	}
   2902 	f_info_size = v1
   2903 	yuv_size = libc.Uint64FromInt32(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(17)+libc.Int32FromInt32(BPS)*libc.Int32FromInt32(9)) * libc.Uint64FromInt64(1)
   2904 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2905 		v3 = int32(2)
   2906 	} else {
   2907 		v3 = int32(1)
   2908 	}
   2909 	mb_data_size = libc.Uint64FromInt32(v3*mb_w) * uint64(800)
   2910 	cache_height = libc.Uint64FromInt32((int32(16)*num_caches + libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])) * int32(3) / int32(2))
   2911 	cache_size = top_size * cache_height
   2912 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) {
   2913 		v4 = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fwidth) * uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fheight)
   2914 	} else {
   2915 		v4 = 0
   2916 	}
   2917 	// alpha_size is the only one that scales as width x height.
   2918 	alpha_size = v4
   2919 	needed = intra_pred_mode_size + top_size + mb_info_size + f_info_size + yuv_size + mb_data_size + cache_size + alpha_size + uint64(WEBP_ALIGN_CST)
   2920 	v5 = needed
   2921 	v6 = libc.BoolInt32(v5 == v5)
   2922 	goto _7
   2923 _7:
   2924 	if !(v6 != 0) {
   2925 		return 0
   2926 	} // check for overflow
   2927 	if needed > (*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size {
   2928 		WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
   2929 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
   2930 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = WebPSafeMalloc(tls, needed, uint64(1))
   2931 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmem == libc.UintptrFromInt32(0) {
   2932 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+115)
   2933 		}
   2934 		// down-cast is ok, thanks to WebPSafeMalloc() above.
   2935 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = needed
   2936 	}
   2937 	mem = (*VP8Decoder)(unsafe.Pointer(dec)).Fmem
   2938 	(*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t = mem
   2939 	mem = mem + uintptr(intra_pred_mode_size)
   2940 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t = mem
   2941 	mem = mem + uintptr(top_size)
   2942 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info = mem + uintptr(1)*2
   2943 	mem = mem + uintptr(mb_info_size)
   2944 	if f_info_size != 0 {
   2945 		v8 = mem
   2946 	} else {
   2947 		v8 = libc.UintptrFromInt32(0)
   2948 	}
   2949 	(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = v8
   2950 	mem = mem + uintptr(f_info_size)
   2951 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fid = 0
   2952 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   2953 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 && (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2954 		// secondary cache line. The deblocking process need to make use of the
   2955 		// filtering strength from previous macroblock row, while the new ones
   2956 		// are being decoded in parallel. We'll just swap the pointers.
   2957 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info += uintptr(mb_w) * 4
   2958 	}
   2959 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   2960 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b = mem
   2961 	mem = mem + uintptr(yuv_size)
   2962 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = mem
   2963 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data = mem
   2964 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2965 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data += uintptr(mb_w) * 800
   2966 	}
   2967 	mem = mem + uintptr(mb_data_size)
   2968 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride = int32(16) * mb_w
   2969 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride = int32(8) * mb_w
   2970 	extra_rows = libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2971 	extra_y = extra_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2972 	extra_uv = extra_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2973 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y = mem + uintptr(extra_y)
   2974 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(int32(16)*num_caches*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride) + uintptr(extra_uv)
   2975 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(int32(8)*num_caches*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride) + uintptr(extra_uv)
   2976 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   2977 	mem = mem + uintptr(cache_size)
   2978 	// alpha plane
   2979 	if alpha_size != 0 {
   2980 		v8 = mem
   2981 	} else {
   2982 		v8 = libc.UintptrFromInt32(0)
   2983 	}
   2984 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = v8
   2985 	mem = mem + uintptr(alpha_size)
   2986 	// note: left/top-info is initialized once for all.
   2987 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info-uintptr(1)*2, 0, mb_info_size)
   2988 	VP8InitScanline(tls, dec) // initialize left too.
   2989 	// initialize top
   2990 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t, int32(B_DC_PRED), intra_pred_mode_size)
   2991 	return int32(1)
   2992 }
   2993 
   2994 func InitIo(tls *libc.TLS, dec uintptr, io uintptr) {
   2995 	// prepare 'io'
   2996 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = 0
   2997 	(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y
   2998 	(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u
   2999 	(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v
   3000 	(*VP8Io)(unsafe.Pointer(io)).Fy_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   3001 	(*VP8Io)(unsafe.Pointer(io)).Fuv_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   3002 	(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   3003 }
   3004 
   3005 func VP8InitFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   3006 	if !(InitThreadContext(tls, dec) != 0) {
   3007 		return 0
   3008 	} // call first. Sets dec->num_caches.
   3009 	if !(AllocateMemory(tls, dec) != 0) {
   3010 		return 0
   3011 	}
   3012 	InitIo(tls, dec, io)
   3013 	VP8DspInit(tls) // Init critical function pointers and look-up tables.
   3014 	return int32(1)
   3015 }
   3016 
   3017 const CHUNK_SIZE = 4096
   3018 const MAX_MB_SIZE = 4096
   3019 
   3020 type WebPIDecoder = struct {
   3021 	Fstate        DecState
   3022 	Fparams       WebPDecParams
   3023 	Fis_lossless  int32
   3024 	Fdec          uintptr
   3025 	Fio           VP8Io
   3026 	Fmem          MemBuffer
   3027 	Foutput       WebPDecBuffer
   3028 	Ffinal_output uintptr
   3029 	Fchunk_size   size_t
   3030 	Flast_mb_y    int32
   3031 }
   3032 
   3033 const STATE_WEBP_HEADER = 0
   3034 const // All the data before that of the VP8/VP8L chunk.
   3035 STATE_VP8_HEADER = 1
   3036 const // The VP8 Frame header (within the VP8 chunk).
   3037 STATE_VP8_PARTS0 = 2
   3038 const STATE_VP8_DATA = 3
   3039 const STATE_VP8L_HEADER = 4
   3040 const STATE_VP8L_DATA = 5
   3041 const STATE_DONE = 6
   3042 const STATE_ERROR = 7
   3043 
   3044 var kHashMul3 = uint32(0x1e35a7bd)
   3045 
   3046 //------------------------------------------------------------------------------
   3047 
   3048 // Copyright 2010 Google Inc. All Rights Reserved.
   3049 //
   3050 // Use of this source code is governed by a BSD-style license
   3051 // that can be found in the COPYING file in the root of the source
   3052 // tree. An additional intellectual property rights grant can be found
   3053 // in the file PATENTS. All contributing project authors may
   3054 // be found in the AUTHORS file in the root of the source tree.
   3055 // -----------------------------------------------------------------------------
   3056 //
   3057 //  Main decoding functions for WebP images.
   3058 //
   3059 // Author: Skal (pascal.massimino@gmail.com)
   3060 
   3061 // Copyright 2012 Google Inc. All Rights Reserved.
   3062 //
   3063 // Use of this source code is governed by a BSD-style license
   3064 // that can be found in the COPYING file in the root of the source
   3065 // tree. An additional intellectual property rights grant can be found
   3066 // in the file PATENTS. All contributing project authors may
   3067 // be found in the AUTHORS file in the root of the source tree.
   3068 // -----------------------------------------------------------------------------
   3069 //
   3070 //  Internal header for constants related to WebP file format.
   3071 //
   3072 // Author: Urvang (urvang@google.com)
   3073 
   3074 // Copyright 2010 Google Inc. All Rights Reserved.
   3075 //
   3076 // Use of this source code is governed by a BSD-style license
   3077 // that can be found in the COPYING file in the root of the source
   3078 // tree. An additional intellectual property rights grant can be found
   3079 // in the file PATENTS. All contributing project authors may
   3080 // be found in the AUTHORS file in the root of the source tree.
   3081 // -----------------------------------------------------------------------------
   3082 //
   3083 //  Common types + memory wrappers
   3084 //
   3085 // Author: Skal (pascal.massimino@gmail.com)
   3086 
   3087 // In append mode, buffer allocations increase as multiples of this value.
   3088 // Needs to be a power of 2.
   3089 
   3090 //------------------------------------------------------------------------------
   3091 // Data structures for memory and states
   3092 
   3093 // C documentation
   3094 //
   3095 //	// Decoding states. State normally flows as:
   3096 //	// WEBP_HEADER->VP8_HEADER->VP8_PARTS0->VP8_DATA->DONE for a lossy image, and
   3097 //	// WEBP_HEADER->VP8L_HEADER->VP8L_DATA->DONE for a lossless image.
   3098 //	// If there is any error the decoder goes into state ERROR.
   3099 type DecState = int32
   3100 
   3101 // C documentation
   3102 //
   3103 //	// Operating state for the MemBuffer
   3104 type MemBufferMode = int32
   3105 
   3106 const MEM_MODE_NONE = 0
   3107 const MEM_MODE_APPEND = 1
   3108 const MEM_MODE_MAP = 2
   3109 
   3110 // C documentation
   3111 //
   3112 //	// storage for partition #0 and partial data (in a rolling fashion)
   3113 type MemBuffer = struct {
   3114 	Fmode       MemBufferMode
   3115 	Fstart      size_t
   3116 	Fend        size_t
   3117 	Fbuf_size   size_t
   3118 	Fbuf        uintptr
   3119 	Fpart0_size size_t
   3120 	Fpart0_buf  uintptr
   3121 }
   3122 
   3123 // C documentation
   3124 //
   3125 //	// MB context to restore in case VP8DecodeMB() fails
   3126 type MBContext = struct {
   3127 	Fleft     VP8MB
   3128 	Finfo     VP8MB
   3129 	Ftoken_br VP8BitReader
   3130 }
   3131 
   3132 //------------------------------------------------------------------------------
   3133 // MemBuffer: incoming data handling
   3134 
   3135 func MemDataSize(tls *libc.TLS, mem uintptr) (r size_t) {
   3136 	return (*MemBuffer)(unsafe.Pointer(mem)).Fend - (*MemBuffer)(unsafe.Pointer(mem)).Fstart
   3137 }
   3138 
   3139 // C documentation
   3140 //
   3141 //	// Check if we need to preserve the compressed alpha data, as it may not have
   3142 //	// been decoded yet.
   3143 func NeedCompressedAlpha(tls *libc.TLS, idec uintptr) (r int32) {
   3144 	var dec uintptr
   3145 	_ = dec
   3146 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3147 		// We haven't parsed the headers yet, so we don't know whether the image is
   3148 		// lossy or lossless. This also means that we haven't parsed the ALPH chunk.
   3149 		return 0
   3150 	}
   3151 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0 {
   3152 		return 0 // ALPH chunk is not present for lossless images.
   3153 	} else {
   3154 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3155 		// Must be true as idec->state != STATE_WEBP_HEADER.
   3156 		return libc.BoolInt32((*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0))
   3157 	}
   3158 	return r
   3159 }
   3160 
   3161 func DoRemap(tls *libc.TLS, idec uintptr, offset ptrdiff_t) {
   3162 	var alph_dec, alph_vp8l_dec, dec, dec1, last_start, mem, new_base uintptr
   3163 	var last_part, p uint32_t
   3164 	_, _, _, _, _, _, _, _, _ = alph_dec, alph_vp8l_dec, dec, dec1, last_part, last_start, mem, new_base, p
   3165 	mem = idec + 296
   3166 	new_base = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3167 	// note: for VP8, setting up idec->io is only really needed at the beginning
   3168 	// of the decoding, till partition #0 is complete.
   3169 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = new_base
   3170 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3171 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   3172 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3173 			dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3174 			last_part = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one
   3175 			if offset != 0 {
   3176 				p = uint32(0)
   3177 				for {
   3178 					if !(p <= last_part) {
   3179 						break
   3180 					}
   3181 					VP8RemapBitReader(tls, dec+440+uintptr(p)*48, offset)
   3182 					goto _1
   3183 				_1:
   3184 					;
   3185 					p = p + 1
   3186 				}
   3187 				// Remap partition #0 data pointer to new offset, but only in MAP
   3188 				// mode (in APPEND mode, partition #0 is copied into a fixed memory).
   3189 				if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_MAP) {
   3190 					VP8RemapBitReader(tls, dec+16, offset)
   3191 				}
   3192 			}
   3193 			last_start = (**(**VP8BitReader)(__ccgo_up(dec + 440 + uintptr(last_part)*48))).Fbuf
   3194 			// 'last_start' will be NULL when 'idec->state' is < STATE_VP8_PARTS0
   3195 			// and through a portion of that state (when there isn't enough data to
   3196 			// parse the partitions). The bitreader is only used meaningfully when
   3197 			// there is enough data to begin parsing partition 0.
   3198 			if last_start != libc.UintptrFromInt32(0) {
   3199 				VP8BitReaderSetBuffer(tls, dec+440+uintptr(last_part)*48, last_start, libc.Uint64FromInt64(int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fend))-int64(last_start)))
   3200 			}
   3201 			if NeedCompressedAlpha(tls, idec) != 0 {
   3202 				alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   3203 				**(**uintptr)(__ccgo_up(dec + 2968)) += uintptr(offset)
   3204 				if alph_dec != libc.UintptrFromInt32(0) && (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec != libc.UintptrFromInt32(0) {
   3205 					if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == int32(ALPHA_LOSSLESS_COMPRESSION) {
   3206 						alph_vp8l_dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
   3207 						VP8LBitReaderSetBuffer(tls, alph_vp8l_dec+40, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data+uintptr(ALPHA_HEADER_LEN), (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size-uint64(ALPHA_HEADER_LEN))
   3208 					} else { // alph_dec->method == ALPHA_NO_COMPRESSION
   3209 						// Nothing special to do in this case.
   3210 					}
   3211 				}
   3212 			}
   3213 		} else { // Resize lossless bitreader
   3214 			dec1 = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3215 			VP8LBitReaderSetBuffer(tls, dec1+40, new_base, MemDataSize(tls, mem))
   3216 		}
   3217 	}
   3218 }
   3219 
   3220 // C documentation
   3221 //
   3222 //	// Appends data to the end of MemBuffer->buf. It expands the allocated memory
   3223 //	// size if required and also updates VP8BitReader's if new memory is allocated.
   3224 func AppendToMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3225 	var current_size, new_mem_start size_t
   3226 	var dec, mem, new_buf, old_base, old_start, v1, v2 uintptr
   3227 	var extra_size, new_size uint64_t
   3228 	var need_compressed_alpha int32
   3229 	_, _, _, _, _, _, _, _, _, _, _, _ = current_size, dec, extra_size, mem, need_compressed_alpha, new_buf, new_mem_start, new_size, old_base, old_start, v1, v2
   3230 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3231 	mem = idec + 296
   3232 	need_compressed_alpha = NeedCompressedAlpha(tls, idec)
   3233 	if (*MemBuffer)(unsafe.Pointer(mem)).Fbuf == libc.UintptrFromInt32(0) {
   3234 		v1 = libc.UintptrFromInt32(0)
   3235 	} else {
   3236 		v1 = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3237 	}
   3238 	old_start = v1
   3239 	if need_compressed_alpha != 0 {
   3240 		v2 = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data
   3241 	} else {
   3242 		v2 = old_start
   3243 	}
   3244 	old_base = v2
   3245 	if data_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
   3246 		// security safeguard: trying to allocate more than what the format
   3247 		// allows for a chunk should be considered a smoke smell.
   3248 		return 0
   3249 	}
   3250 	if (*MemBuffer)(unsafe.Pointer(mem)).Fend+data_size > (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size { // Need some free memory
   3251 		new_mem_start = libc.Uint64FromInt64(int64(old_start) - int64(old_base))
   3252 		current_size = MemDataSize(tls, mem) + new_mem_start
   3253 		new_size = current_size + data_size
   3254 		extra_size = (new_size + uint64(CHUNK_SIZE) - uint64(1)) & libc.Uint64FromInt32(^(libc.Int32FromInt32(CHUNK_SIZE) - libc.Int32FromInt32(1)))
   3255 		new_buf = WebPSafeMalloc(tls, extra_size, uint64(1))
   3256 		if new_buf == libc.UintptrFromInt32(0) {
   3257 			return 0
   3258 		}
   3259 		if old_base != libc.UintptrFromInt32(0) {
   3260 			libc.Xmemcpy(tls, new_buf, old_base, current_size)
   3261 		}
   3262 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3263 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = new_buf
   3264 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = extra_size
   3265 		(*MemBuffer)(unsafe.Pointer(mem)).Fstart = new_mem_start
   3266 		(*MemBuffer)(unsafe.Pointer(mem)).Fend = current_size
   3267 	}
   3268 	libc.Xmemcpy(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fend), data, data_size)
   3269 	**(**size_t)(__ccgo_up(mem + 16)) += data_size
   3270 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3271 	return int32(1)
   3272 }
   3273 
   3274 func RemapMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3275 	var mem, old_buf, old_start, v1 uintptr
   3276 	var v2 size_t
   3277 	_, _, _, _, _ = mem, old_buf, old_start, v1, v2
   3278 	mem = idec + 296
   3279 	old_buf = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf
   3280 	if old_buf == libc.UintptrFromInt32(0) {
   3281 		v1 = libc.UintptrFromInt32(0)
   3282 	} else {
   3283 		v1 = old_buf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3284 	}
   3285 	old_start = v1
   3286 	if data_size < (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size {
   3287 		return 0
   3288 	} // can't remap to a shorter buffer!
   3289 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = data
   3290 	v2 = data_size
   3291 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = v2
   3292 	(*MemBuffer)(unsafe.Pointer(mem)).Fend = v2
   3293 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3294 	return int32(1)
   3295 }
   3296 
   3297 func InitMemBuffer(tls *libc.TLS, mem uintptr) {
   3298 	(*MemBuffer)(unsafe.Pointer(mem)).Fmode = int32(MEM_MODE_NONE)
   3299 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = libc.UintptrFromInt32(0)
   3300 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = uint64(0)
   3301 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = libc.UintptrFromInt32(0)
   3302 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_size = uint64(0)
   3303 }
   3304 
   3305 func ClearMemBuffer(tls *libc.TLS, mem uintptr) {
   3306 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3307 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3308 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf)
   3309 	}
   3310 }
   3311 
   3312 func CheckMemBufferMode(tls *libc.TLS, mem uintptr, expected MemBufferMode) (r int32) {
   3313 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_NONE) {
   3314 		(*MemBuffer)(unsafe.Pointer(mem)).Fmode = expected // switch to the expected mode
   3315 	} else {
   3316 		if (*MemBuffer)(unsafe.Pointer(mem)).Fmode != expected {
   3317 			return 0 // we mixed the modes => error
   3318 		}
   3319 	}
   3320 	// mode is ok
   3321 	return int32(1)
   3322 }
   3323 
   3324 // C documentation
   3325 //
   3326 //	// To be called last.
   3327 func FinishDecoding(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3328 	var options, output uintptr
   3329 	var status, status1 VP8StatusCode1
   3330 	_, _, _, _ = options, output, status, status1
   3331 	options = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions
   3332 	output = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   3333 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_DONE)
   3334 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   3335 		status = WebPFlipBuffer(tls, output)
   3336 		if status != int32(VP8_STATUS_OK) {
   3337 			return status
   3338 		}
   3339 	}
   3340 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   3341 		status1 = WebPCopyDecBufferPixels(tls, output, (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output) // do the slow-copy
   3342 		WebPFreeDecBuffer(tls, idec+352)
   3343 		if status1 != int32(VP8_STATUS_OK) {
   3344 			return status1
   3345 		}
   3346 		**(**WebPDecBuffer)(__ccgo_up(output)) = **(**WebPDecBuffer)(__ccgo_up((*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output))
   3347 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   3348 	}
   3349 	return int32(VP8_STATUS_OK)
   3350 }
   3351 
   3352 //------------------------------------------------------------------------------
   3353 // Macroblock-decoding contexts
   3354 
   3355 func SaveContext(tls *libc.TLS, dec uintptr, token_br uintptr, context uintptr) {
   3356 	(*MBContext)(unsafe.Pointer(context)).Fleft = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2))
   3357 	(*MBContext)(unsafe.Pointer(context)).Finfo = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2))
   3358 	(*MBContext)(unsafe.Pointer(context)).Ftoken_br = **(**VP8BitReader)(__ccgo_up(token_br))
   3359 }
   3360 
   3361 func RestoreContext(tls *libc.TLS, context uintptr, dec uintptr, token_br uintptr) {
   3362 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2)) = (*MBContext)(unsafe.Pointer(context)).Fleft
   3363 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2)) = (*MBContext)(unsafe.Pointer(context)).Finfo
   3364 	**(**VP8BitReader)(__ccgo_up(token_br)) = (*MBContext)(unsafe.Pointer(context)).Ftoken_br
   3365 }
   3366 
   3367 //------------------------------------------------------------------------------
   3368 
   3369 func IDecError(tls *libc.TLS, idec uintptr, error1 VP8StatusCode1) (r VP8StatusCode1) {
   3370 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3371 		// Synchronize the thread, clean-up and check for errors.
   3372 		VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   3373 	}
   3374 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR)
   3375 	return error1
   3376 }
   3377 
   3378 func ChangeState(tls *libc.TLS, idec uintptr, new_state DecState, consumed_bytes size_t) {
   3379 	var mem uintptr
   3380 	_ = mem
   3381 	mem = idec + 296
   3382 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = new_state
   3383 	**(**size_t)(__ccgo_up(mem + 8)) += consumed_bytes
   3384 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3385 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3386 }
   3387 
   3388 // C documentation
   3389 //
   3390 //	// Headers
   3391 func DecodeWebPHeaders(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3392 	bp := tls.Alloc(80)
   3393 	defer tls.Free(80)
   3394 	var curr_size size_t
   3395 	var data, dec, dec1, mem uintptr
   3396 	var status VP8StatusCode1
   3397 	var _ /* headers at bp+0 */ WebPHeaderStructure
   3398 	_, _, _, _, _, _ = curr_size, data, dec, dec1, mem, status
   3399 	mem = idec + 296
   3400 	data = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3401 	curr_size = MemDataSize(tls, mem)
   3402 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata = data
   3403 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata_size = curr_size
   3404 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fhave_all_data = 0
   3405 	status = WebPParseHeaders(tls, bp)
   3406 	if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3407 		return int32(VP8_STATUS_SUSPENDED) // We haven't found a VP8 chunk yet.
   3408 	} else {
   3409 		if status != int32(VP8_STATUS_OK) {
   3410 			return IDecError(tls, idec, status)
   3411 		}
   3412 	}
   3413 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fcompressed_size
   3414 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fis_lossless
   3415 	if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3416 		dec = VP8New(tls)
   3417 		if dec == libc.UintptrFromInt32(0) {
   3418 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3419 		}
   3420 		(*VP8Decoder)(unsafe.Pointer(dec)).Fincremental = int32(1)
   3421 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec
   3422 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data
   3423 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data_size
   3424 		ChangeState(tls, idec, int32(STATE_VP8_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3425 	} else {
   3426 		dec1 = VP8LNew(tls)
   3427 		if dec1 == libc.UintptrFromInt32(0) {
   3428 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3429 		}
   3430 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec1
   3431 		ChangeState(tls, idec, int32(STATE_VP8L_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3432 	}
   3433 	return int32(VP8_STATUS_OK)
   3434 }
   3435 
   3436 func DecodeVP8FrameHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3437 	bp := tls.Alloc(16)
   3438 	defer tls.Free(16)
   3439 	var bits uint32_t
   3440 	var curr_size size_t
   3441 	var data uintptr
   3442 	var _ /* height at bp+4 */ int32
   3443 	var _ /* width at bp+0 */ int32
   3444 	_, _, _ = bits, curr_size, data
   3445 	data = (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf + uintptr((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart)
   3446 	curr_size = MemDataSize(tls, idec+296)
   3447 	if curr_size < uint64(VP8_FRAME_HEADER_SIZE) {
   3448 		// Not enough data bytes to extract VP8 Frame Header.
   3449 		return int32(VP8_STATUS_SUSPENDED)
   3450 	}
   3451 	if !(VP8GetInfo(tls, data, curr_size, (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size, bp, bp+4) != 0) {
   3452 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3453 	}
   3454 	bits = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 1)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 2)))<<int32(16))
   3455 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size = uint64(bits>>libc.Int32FromInt32(5) + uint32(VP8_FRAME_HEADER_SIZE))
   3456 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = data
   3457 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = curr_size
   3458 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_PARTS0)
   3459 	return int32(VP8_STATUS_OK)
   3460 }
   3461 
   3462 // C documentation
   3463 //
   3464 //	// Partition #0
   3465 func CopyParts0Data(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3466 	var br, dec, mem, part0_buf uintptr
   3467 	var part_size size_t
   3468 	_, _, _, _, _ = br, dec, mem, part0_buf, part_size
   3469 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3470 	br = dec + 16
   3471 	part_size = libc.Uint64FromInt64(int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end) - int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf))
   3472 	mem = idec + 296
   3473 	// the following is a format limitation, no need for runtime check:
   3474 	if part_size == uint64(0) { // can't have zero-size partition #0
   3475 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   3476 	}
   3477 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3478 		// We copy and grab ownership of the partition #0 data.
   3479 		part0_buf = WebPSafeMalloc(tls, uint64(1), part_size)
   3480 		if part0_buf == libc.UintptrFromInt32(0) {
   3481 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3482 		}
   3483 		libc.Xmemcpy(tls, part0_buf, (*VP8BitReader)(unsafe.Pointer(br)).Fbuf, part_size)
   3484 		(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = part0_buf
   3485 		VP8BitReaderSetBuffer(tls, br, part0_buf, part_size)
   3486 	} else {
   3487 		// Else: just keep pointers to the partition #0's data in dec->br.
   3488 	}
   3489 	**(**size_t)(__ccgo_up(mem + 8)) += part_size
   3490 	return int32(VP8_STATUS_OK)
   3491 }
   3492 
   3493 func DecodePartition0(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3494 	var dec, io, output, params uintptr
   3495 	var status VP8StatusCode1
   3496 	_, _, _, _, _ = dec, io, output, params, status
   3497 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3498 	io = idec + 136
   3499 	params = idec + 8
   3500 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3501 	// Wait till we have enough data for the whole partition #0
   3502 	if MemDataSize(tls, idec+296) < (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size {
   3503 		return int32(VP8_STATUS_SUSPENDED)
   3504 	}
   3505 	if !(VP8GetHeaders(tls, dec, io) != 0) {
   3506 		status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   3507 		if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3508 			// treating NOT_ENOUGH_DATA as SUSPENDED state
   3509 			return int32(VP8_STATUS_SUSPENDED)
   3510 		}
   3511 		return IDecError(tls, idec, status)
   3512 	}
   3513 	// Allocate/Verify output buffer now
   3514 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3515 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3516 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3517 	}
   3518 	// This change must be done before calling VP8InitFrame()
   3519 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method = VP8GetThreadMethod(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, libc.UintptrFromInt32(0), (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight)
   3520 	VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
   3521 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = CopyParts0Data(tls, idec)
   3522 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3523 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3524 	}
   3525 	// Finish setting up the decoding parameters. Will call io->setup().
   3526 	if VP8EnterCritical(tls, dec, io) != int32(VP8_STATUS_OK) {
   3527 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3528 	}
   3529 	// Note: past this point, teardown() must always be called
   3530 	// in case of error.
   3531 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_DATA)
   3532 	// Allocate memory and prepare everything.
   3533 	if !(VP8InitFrame(tls, dec, io) != 0) {
   3534 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3535 	}
   3536 	return int32(VP8_STATUS_OK)
   3537 }
   3538 
   3539 // C documentation
   3540 //
   3541 //	// Remaining partitions
   3542 func DecodeRemaining(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3543 	bp := tls.Alloc(64)
   3544 	defer tls.Free(64)
   3545 	var dec, io, token_br uintptr
   3546 	var _ /* context at bp+0 */ MBContext
   3547 	_, _, _ = dec, io, token_br
   3548 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3549 	io = idec + 136
   3550 	// Make sure partition #0 has been read before, to set dec to ready.
   3551 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
   3552 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3553 	}
   3554 	for {
   3555 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h) {
   3556 			break
   3557 		}
   3558 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y != (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y {
   3559 			if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
   3560 				// note: normally, error shouldn't occur since we already have the whole
   3561 				// partition0 available here in DecodeRemaining(). Reaching EOF while
   3562 				// reading intra modes really means a BITSTREAM_ERROR.
   3563 				return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3564 			}
   3565 			(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3566 		}
   3567 		for {
   3568 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   3569 				break
   3570 			}
   3571 			token_br = dec + 440 + uintptr(libc.Uint32FromInt32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
   3572 			SaveContext(tls, dec, token_br, bp)
   3573 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
   3574 				// We shouldn't fail when MAX_MB data was available
   3575 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) && MemDataSize(tls, idec+296) > uint64(MAX_MB_SIZE) {
   3576 					return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3577 				}
   3578 				// Synchronize the threads.
   3579 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3580 					if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
   3581 						return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3582 					}
   3583 				}
   3584 				RestoreContext(tls, bp, dec, token_br)
   3585 				return int32(VP8_STATUS_SUSPENDED)
   3586 			}
   3587 			// Release buffer only if there is only one partition
   3588 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) {
   3589 				(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart = libc.Uint64FromInt64(int64((*VP8BitReader)(unsafe.Pointer(token_br)).Fbuf) - int64((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf))
   3590 			}
   3591 			goto _2
   3592 		_2:
   3593 			;
   3594 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
   3595 		}
   3596 		VP8InitScanline(tls, dec) // Prepare for next scanline
   3597 		// Reconstruct, filter and emit the row.
   3598 		if !(VP8ProcessRow(tls, dec, io) != 0) {
   3599 			return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3600 		}
   3601 		goto _1
   3602 	_1:
   3603 		;
   3604 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
   3605 	}
   3606 	// Synchronize the thread and check for errors.
   3607 	if !(VP8ExitCritical(tls, dec, io) != 0) {
   3608 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR) // prevent re-entry in IDecError
   3609 		return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3610 	}
   3611 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
   3612 	return FinishDecoding(tls, idec)
   3613 }
   3614 
   3615 func ErrorStatusLossless(tls *libc.TLS, idec uintptr, status VP8StatusCode1) (r VP8StatusCode1) {
   3616 	if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3617 		return int32(VP8_STATUS_SUSPENDED)
   3618 	}
   3619 	return IDecError(tls, idec, status)
   3620 }
   3621 
   3622 func DecodeVP8LHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3623 	var curr_size size_t
   3624 	var dec, io, output, params uintptr
   3625 	_, _, _, _, _ = curr_size, dec, io, output, params
   3626 	io = idec + 136
   3627 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3628 	params = idec + 8
   3629 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3630 	curr_size = MemDataSize(tls, idec+296)
   3631 	// Wait until there's enough data for decoding header.
   3632 	if curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size>>libc.Int32FromInt32(3) {
   3633 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3634 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3635 	}
   3636 	if !(VP8LDecodeHeader(tls, dec, io) != 0) {
   3637 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_BITSTREAM_ERROR) && curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size {
   3638 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3639 		}
   3640 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3641 	}
   3642 	// Allocate/verify output buffer now.
   3643 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3644 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3645 		return IDecError(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3646 	}
   3647 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8L_DATA)
   3648 	return int32(VP8_STATUS_OK)
   3649 }
   3650 
   3651 func DecodeVP8LData(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3652 	var curr_size size_t
   3653 	var dec uintptr
   3654 	var v1 int32
   3655 	_, _, _ = curr_size, dec, v1
   3656 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3657 	curr_size = MemDataSize(tls, idec+296)
   3658 	// Switch to incremental decoding if we don't have all the bytes available.
   3659 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental = libc.BoolInt32(curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size)
   3660 	if !(VP8LDecodeImage(tls, dec) != 0) {
   3661 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3662 	}
   3663 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
   3664 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus
   3665 	} else {
   3666 		v1 = FinishDecoding(tls, idec)
   3667 	}
   3668 	return v1
   3669 }
   3670 
   3671 // C documentation
   3672 //
   3673 //	// Main decoding loop
   3674 func IDecode(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3675 	var dec uintptr
   3676 	var status VP8StatusCode1
   3677 	_, _ = dec, status
   3678 	status = int32(VP8_STATUS_SUSPENDED)
   3679 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3680 		status = DecodeWebPHeaders(tls, idec)
   3681 	} else {
   3682 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   3683 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3684 		}
   3685 	}
   3686 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_HEADER) {
   3687 		status = DecodeVP8FrameHeader(tls, idec)
   3688 	}
   3689 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_PARTS0) {
   3690 		status = DecodePartition0(tls, idec)
   3691 	}
   3692 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3693 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3694 		if dec == libc.UintptrFromInt32(0) {
   3695 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3696 		}
   3697 		status = DecodeRemaining(tls, idec)
   3698 	}
   3699 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_HEADER) {
   3700 		status = DecodeVP8LHeader(tls, idec)
   3701 	}
   3702 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_DATA) {
   3703 		status = DecodeVP8LData(tls, idec)
   3704 	}
   3705 	return status
   3706 }
   3707 
   3708 // ------------------------------------------------------------------------------
   3709 // Internal constructor
   3710 func NewDecoder(tls *libc.TLS, output_buffer uintptr, features uintptr) (r uintptr) {
   3711 	var idec uintptr
   3712 	var v1, v3 int32
   3713 	var v5 bool
   3714 	_, _, _, _ = idec, v1, v3, v5
   3715 	idec = WebPSafeCalloc(tls, uint64(1), uint64(496))
   3716 	if idec == libc.UintptrFromInt32(0) {
   3717 		return libc.UintptrFromInt32(0)
   3718 	}
   3719 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_WEBP_HEADER)
   3720 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = uint64(0)
   3721 	(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = -int32(1)
   3722 	InitMemBuffer(tls, idec+296)
   3723 	v1 = WebPInitDecBufferInternal(tls, idec+352, int32(WEBP_DECODER_ABI_VERSION))
   3724 	goto _2
   3725 _2:
   3726 	;
   3727 	if v5 = !(v1 != 0); !v5 {
   3728 		v3 = VP8InitIoInternal(tls, idec+136, int32(WEBP_DECODER_ABI_VERSION))
   3729 		goto _4
   3730 	_4:
   3731 	}
   3732 	if v5 || !(v3 != 0) {
   3733 		WebPSafeFree(tls, idec)
   3734 		return libc.UintptrFromInt32(0)
   3735 	}
   3736 	WebPResetDecParams(tls, idec+8)
   3737 	if output_buffer == libc.UintptrFromInt32(0) || WebPAvoidSlowMemory(tls, output_buffer, features) != 0 {
   3738 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = idec + 352
   3739 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = output_buffer
   3740 		if output_buffer != libc.UintptrFromInt32(0) {
   3741 			(*WebPDecBuffer)(unsafe.Pointer((*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput)).Fcolorspace = (*WebPDecBuffer)(unsafe.Pointer(output_buffer)).Fcolorspace
   3742 		}
   3743 	} else {
   3744 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = output_buffer
   3745 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   3746 	}
   3747 	WebPInitCustomIo(tls, idec+8, idec+136) // Plug the I/O functions.
   3748 	return idec
   3749 }
   3750 
   3751 //------------------------------------------------------------------------------
   3752 // Public functions
   3753 
   3754 func WebPINewDecoder(tls *libc.TLS, output_buffer uintptr) (r uintptr) {
   3755 	return NewDecoder(tls, output_buffer, libc.UintptrFromInt32(0))
   3756 }
   3757 
   3758 func WebPIDecode(tls *libc.TLS, data1 uintptr, data_size1 size_t, config uintptr) (r uintptr) {
   3759 	bp := tls.Alloc(48)
   3760 	defer tls.Free(48)
   3761 	var features1, idec, v1 uintptr
   3762 	var v2 VP8StatusCode1
   3763 	var _ /* tmp_features at bp+0 */ WebPBitstreamFeatures
   3764 	_, _, _, _ = features1, idec, v1, v2
   3765 	if config == libc.UintptrFromInt32(0) {
   3766 		v1 = bp
   3767 	} else {
   3768 		v1 = config
   3769 	}
   3770 	features1 = v1
   3771 	libc.Xmemset(tls, bp, 0, uint64(40))
   3772 	// Parse the bitstream's features, if requested:
   3773 	if data1 != libc.UintptrFromInt32(0) && data_size1 > uint64(0) {
   3774 		v2 = WebPGetFeaturesInternal(tls, data1, data_size1, features1, int32(WEBP_DECODER_ABI_VERSION))
   3775 		goto _3
   3776 	_3:
   3777 		if v2 != int32(VP8_STATUS_OK) {
   3778 			return libc.UintptrFromInt32(0)
   3779 		}
   3780 	}
   3781 	// Create an instance of the incremental decoder
   3782 	if config != libc.UintptrFromInt32(0) {
   3783 		v1 = NewDecoder(tls, config+40, features1)
   3784 	} else {
   3785 		v1 = NewDecoder(tls, libc.UintptrFromInt32(0), features1)
   3786 	}
   3787 	idec = v1
   3788 	if idec == libc.UintptrFromInt32(0) {
   3789 		return libc.UintptrFromInt32(0)
   3790 	}
   3791 	// Finish initialization
   3792 	if config != libc.UintptrFromInt32(0) {
   3793 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions = config + 160
   3794 	}
   3795 	return idec
   3796 }
   3797 
   3798 func WebPIDelete(tls *libc.TLS, idec uintptr) {
   3799 	if idec == libc.UintptrFromInt32(0) {
   3800 		return
   3801 	}
   3802 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   3803 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3804 			if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3805 				// Synchronize the thread, clean-up and check for errors.
   3806 				// TODO(vrabaud) do we care about the return result?
   3807 				VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   3808 			}
   3809 			VP8Delete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   3810 		} else {
   3811 			VP8LDelete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   3812 		}
   3813 	}
   3814 	ClearMemBuffer(tls, idec+296)
   3815 	WebPFreeDecBuffer(tls, idec+352)
   3816 	WebPSafeFree(tls, idec)
   3817 }
   3818 
   3819 //------------------------------------------------------------------------------
   3820 // Wrapper toward WebPINewDecoder
   3821 
   3822 func WebPINewRGB(tls *libc.TLS, csp WEBP_CSP_MODE1, output_buffer uintptr, output_buffer_size size_t, output_stride int32) (r uintptr) {
   3823 	var idec uintptr
   3824 	var is_external_memory, v1 int32
   3825 	_, _, _ = idec, is_external_memory, v1
   3826 	if output_buffer != libc.UintptrFromInt32(0) {
   3827 		v1 = int32(1)
   3828 	} else {
   3829 		v1 = 0
   3830 	}
   3831 	is_external_memory = v1
   3832 	if csp >= int32(MODE_YUV) {
   3833 		return libc.UintptrFromInt32(0)
   3834 	}
   3835 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   3836 		output_buffer_size = uint64(0)
   3837 		output_stride = 0
   3838 	} else { // A buffer was passed. Validate the other params.
   3839 		if output_stride == 0 || output_buffer_size == uint64(0) {
   3840 			return libc.UintptrFromInt32(0) // invalid parameter.
   3841 		}
   3842 	}
   3843 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   3844 	if idec == libc.UintptrFromInt32(0) {
   3845 		return libc.UintptrFromInt32(0)
   3846 	}
   3847 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = csp
   3848 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   3849 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = output_buffer
   3850 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 8)) = output_stride
   3851 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 16)) = output_buffer_size
   3852 	return idec
   3853 }
   3854 
   3855 func WebPINewYUVA(tls *libc.TLS, luma uintptr, luma_size size_t, luma_stride int32, u uintptr, u_size size_t, u_stride int32, v uintptr, v_size size_t, v_stride int32, a uintptr, a_size size_t, a_stride int32) (r uintptr) {
   3856 	var colorspace WEBP_CSP_MODE1
   3857 	var idec, v8, v9 uintptr
   3858 	var is_external_memory, v1, v5, v6 int32
   3859 	var v2, v3, v4 size_t
   3860 	_, _, _, _, _, _, _, _, _, _, _ = colorspace, idec, is_external_memory, v1, v2, v3, v4, v5, v6, v8, v9
   3861 	if luma != libc.UintptrFromInt32(0) {
   3862 		v1 = int32(1)
   3863 	} else {
   3864 		v1 = 0
   3865 	}
   3866 	is_external_memory = v1
   3867 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   3868 		v4 = libc.Uint64FromInt32(0)
   3869 		a_size = v4
   3870 		v3 = v4
   3871 		v_size = v3
   3872 		v2 = v3
   3873 		u_size = v2
   3874 		luma_size = v2
   3875 		v6 = libc.Int32FromInt32(0)
   3876 		a_stride = v6
   3877 		v5 = v6
   3878 		v_stride = v5
   3879 		v1 = v5
   3880 		u_stride = v1
   3881 		luma_stride = v1
   3882 		v9 = libc.UintptrFromInt32(0)
   3883 		a = v9
   3884 		v8 = v9
   3885 		v = v8
   3886 		u = v8
   3887 		colorspace = int32(MODE_YUVA)
   3888 	} else { // A luma buffer was passed. Validate the other parameters.
   3889 		if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) {
   3890 			return libc.UintptrFromInt32(0)
   3891 		}
   3892 		if luma_size == uint64(0) || u_size == uint64(0) || v_size == uint64(0) {
   3893 			return libc.UintptrFromInt32(0)
   3894 		}
   3895 		if luma_stride == 0 || u_stride == 0 || v_stride == 0 {
   3896 			return libc.UintptrFromInt32(0)
   3897 		}
   3898 		if a != libc.UintptrFromInt32(0) {
   3899 			if a_size == uint64(0) || a_stride == 0 {
   3900 				return libc.UintptrFromInt32(0)
   3901 			}
   3902 		}
   3903 		if a == libc.UintptrFromInt32(0) {
   3904 			v1 = int32(MODE_YUV)
   3905 		} else {
   3906 			v1 = int32(MODE_YUVA)
   3907 		}
   3908 		colorspace = v1
   3909 	}
   3910 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   3911 	if idec == libc.UintptrFromInt32(0) {
   3912 		return libc.UintptrFromInt32(0)
   3913 	}
   3914 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = colorspace
   3915 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   3916 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = luma
   3917 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 32)) = luma_stride
   3918 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 48)) = luma_size
   3919 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 8)) = u
   3920 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 36)) = u_stride
   3921 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 56)) = u_size
   3922 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 16)) = v
   3923 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 40)) = v_stride
   3924 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 64)) = v_size
   3925 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 24)) = a
   3926 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 44)) = a_stride
   3927 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 72)) = a_size
   3928 	return idec
   3929 }
   3930 
   3931 func WebPINewYUV(tls *libc.TLS, luma uintptr, luma_size size_t, luma_stride int32, u uintptr, u_size size_t, u_stride int32, v uintptr, v_size size_t, v_stride int32) (r uintptr) {
   3932 	return WebPINewYUVA(tls, luma, luma_size, luma_stride, u, u_size, u_stride, v, v_size, v_stride, libc.UintptrFromInt32(0), uint64(0), 0)
   3933 }
   3934 
   3935 //------------------------------------------------------------------------------
   3936 
   3937 func IDecCheckStatus(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3938 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_ERROR) {
   3939 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   3940 	}
   3941 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_DONE) {
   3942 		return int32(VP8_STATUS_OK)
   3943 	}
   3944 	return int32(VP8_STATUS_SUSPENDED)
   3945 }
   3946 
   3947 func WebPIAppend(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   3948 	var status VP8StatusCode1
   3949 	_ = status
   3950 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   3951 		return int32(VP8_STATUS_INVALID_PARAM)
   3952 	}
   3953 	status = IDecCheckStatus(tls, idec)
   3954 	if status != int32(VP8_STATUS_SUSPENDED) {
   3955 		return status
   3956 	}
   3957 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   3958 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_APPEND)) != 0) {
   3959 		return int32(VP8_STATUS_INVALID_PARAM)
   3960 	}
   3961 	// Append data to memory buffer
   3962 	if !(AppendToMemBuffer(tls, idec, data, data_size) != 0) {
   3963 		return int32(VP8_STATUS_OUT_OF_MEMORY)
   3964 	}
   3965 	return IDecode(tls, idec)
   3966 }
   3967 
   3968 func WebPIUpdate(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   3969 	var status VP8StatusCode1
   3970 	_ = status
   3971 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   3972 		return int32(VP8_STATUS_INVALID_PARAM)
   3973 	}
   3974 	status = IDecCheckStatus(tls, idec)
   3975 	if status != int32(VP8_STATUS_SUSPENDED) {
   3976 		return status
   3977 	}
   3978 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   3979 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_MAP)) != 0) {
   3980 		return int32(VP8_STATUS_INVALID_PARAM)
   3981 	}
   3982 	// Make the memory buffer point to the new buffer
   3983 	if !(RemapMemBuffer(tls, idec, data, data_size) != 0) {
   3984 		return int32(VP8_STATUS_INVALID_PARAM)
   3985 	}
   3986 	return IDecode(tls, idec)
   3987 }
   3988 
   3989 //------------------------------------------------------------------------------
   3990 
   3991 func GetOutputBuffer(tls *libc.TLS, idec uintptr) (r uintptr) {
   3992 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   3993 		return libc.UintptrFromInt32(0)
   3994 	}
   3995 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate <= int32(STATE_VP8_PARTS0) {
   3996 		return libc.UintptrFromInt32(0)
   3997 	}
   3998 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   3999 		return libc.UintptrFromInt32(0) // not yet slow-copied
   4000 	}
   4001 	return (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   4002 }
   4003 
   4004 func WebPIDecodedArea(tls *libc.TLS, idec uintptr, left uintptr, top uintptr, width uintptr, height uintptr) (r uintptr) {
   4005 	var src uintptr
   4006 	_ = src
   4007 	src = GetOutputBuffer(tls, idec)
   4008 	if left != libc.UintptrFromInt32(0) {
   4009 		**(**int32)(__ccgo_up(left)) = 0
   4010 	}
   4011 	if top != libc.UintptrFromInt32(0) {
   4012 		**(**int32)(__ccgo_up(top)) = 0
   4013 	}
   4014 	if src != libc.UintptrFromInt32(0) {
   4015 		if width != libc.UintptrFromInt32(0) {
   4016 			**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4017 		}
   4018 		if height != libc.UintptrFromInt32(0) {
   4019 			**(**int32)(__ccgo_up(height)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4020 		}
   4021 	} else {
   4022 		if width != libc.UintptrFromInt32(0) {
   4023 			**(**int32)(__ccgo_up(width)) = 0
   4024 		}
   4025 		if height != libc.UintptrFromInt32(0) {
   4026 			**(**int32)(__ccgo_up(height)) = 0
   4027 		}
   4028 	}
   4029 	return src
   4030 }
   4031 
   4032 func WebPIDecGetRGB(tls *libc.TLS, idec uintptr, last_y uintptr, width uintptr, height uintptr, stride uintptr) (r uintptr) {
   4033 	var src uintptr
   4034 	_ = src
   4035 	src = GetOutputBuffer(tls, idec)
   4036 	if src == libc.UintptrFromInt32(0) {
   4037 		return libc.UintptrFromInt32(0)
   4038 	}
   4039 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace >= int32(MODE_YUV) {
   4040 		return libc.UintptrFromInt32(0)
   4041 	}
   4042 	if last_y != libc.UintptrFromInt32(0) {
   4043 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4044 	}
   4045 	if width != libc.UintptrFromInt32(0) {
   4046 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4047 	}
   4048 	if height != libc.UintptrFromInt32(0) {
   4049 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4050 	}
   4051 	if stride != libc.UintptrFromInt32(0) {
   4052 		**(**int32)(__ccgo_up(stride)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Fstride
   4053 	}
   4054 	return (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Frgba
   4055 }
   4056 
   4057 func WebPIDecGetYUVA(tls *libc.TLS, idec uintptr, last_y uintptr, u uintptr, v uintptr, a uintptr, width uintptr, height uintptr, stride uintptr, uv_stride uintptr, a_stride uintptr) (r uintptr) {
   4058 	var src uintptr
   4059 	_ = src
   4060 	src = GetOutputBuffer(tls, idec)
   4061 	if src == libc.UintptrFromInt32(0) {
   4062 		return libc.UintptrFromInt32(0)
   4063 	}
   4064 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace < int32(MODE_YUV) {
   4065 		return libc.UintptrFromInt32(0)
   4066 	}
   4067 	if last_y != libc.UintptrFromInt32(0) {
   4068 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4069 	}
   4070 	if u != libc.UintptrFromInt32(0) {
   4071 		**(**uintptr)(__ccgo_up(u)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu
   4072 	}
   4073 	if v != libc.UintptrFromInt32(0) {
   4074 		**(**uintptr)(__ccgo_up(v)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fv
   4075 	}
   4076 	if a != libc.UintptrFromInt32(0) {
   4077 		**(**uintptr)(__ccgo_up(a)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa
   4078 	}
   4079 	if width != libc.UintptrFromInt32(0) {
   4080 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4081 	}
   4082 	if height != libc.UintptrFromInt32(0) {
   4083 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4084 	}
   4085 	if stride != libc.UintptrFromInt32(0) {
   4086 		**(**int32)(__ccgo_up(stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy_stride
   4087 	}
   4088 	if uv_stride != libc.UintptrFromInt32(0) {
   4089 		**(**int32)(__ccgo_up(uv_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu_stride
   4090 	}
   4091 	if a_stride != libc.UintptrFromInt32(0) {
   4092 		**(**int32)(__ccgo_up(a_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa_stride
   4093 	}
   4094 	return (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy
   4095 }
   4096 
   4097 type __ccgo_fp__XWebPISetIOHooks_1 = func(*libc.TLS, uintptr) int32
   4098 
   4099 type __ccgo_fp__XWebPISetIOHooks_2 = func(*libc.TLS, uintptr) int32
   4100 
   4101 type __ccgo_fp__XWebPISetIOHooks_3 = func(*libc.TLS, uintptr)
   4102 
   4103 func WebPISetIOHooks(tls *libc.TLS, idec uintptr, __ccgo_fp_put VP8IoPutHook, __ccgo_fp_setup VP8IoSetupHook, __ccgo_fp_teardown VP8IoTeardownHook, user_data uintptr) (r int32) {
   4104 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate > int32(STATE_WEBP_HEADER) {
   4105 		return 0
   4106 	}
   4107 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fput = __ccgo_fp_put
   4108 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fsetup = __ccgo_fp_setup
   4109 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fteardown = __ccgo_fp_teardown
   4110 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fopaque = user_data
   4111 	return int32(1)
   4112 }
   4113 
   4114 var kHashMul4 = uint32(0x1e35a7bd)
   4115 
   4116 const YUV_FIX = 16
   4117 const YUV_HALF = 32768
   4118 const YUV_FIX2 = 6
   4119 const YUV_MASK2 = 16383
   4120 
   4121 //------------------------------------------------------------------------------
   4122 
   4123 // Copyright 2010 Google Inc. All Rights Reserved.
   4124 //
   4125 // Use of this source code is governed by a BSD-style license
   4126 // that can be found in the COPYING file in the root of the source
   4127 // tree. An additional intellectual property rights grant can be found
   4128 // in the file PATENTS. All contributing project authors may
   4129 // be found in the AUTHORS file in the root of the source tree.
   4130 // -----------------------------------------------------------------------------
   4131 //
   4132 //  Main decoding functions for WebP images.
   4133 //
   4134 // Author: Skal (pascal.massimino@gmail.com)
   4135 
   4136 //------------------------------------------------------------------------------
   4137 // Main YUV<->RGB conversion functions
   4138 
   4139 func EmitYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4140 	var buf, output, u_dst, v_dst, y_dst uintptr
   4141 	var mb_h, mb_w, uv_h, uv_w int32
   4142 	_, _, _, _, _, _, _, _, _ = buf, mb_h, mb_w, output, u_dst, uv_h, uv_w, v_dst, y_dst
   4143 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4144 	buf = output + 16
   4145 	y_dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4146 	u_dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y>>libc.Int32FromInt32(1))*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride))
   4147 	v_dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y>>libc.Int32FromInt32(1))*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride))
   4148 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4149 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4150 	uv_w = (mb_w + int32(1)) / int32(2)
   4151 	uv_h = (mb_h + int32(1)) / int32(2)
   4152 	WebPCopyPlane(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, y_dst, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride, mb_w, mb_h)
   4153 	WebPCopyPlane(tls, (*VP8Io)(unsafe.Pointer(io)).Fu, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, u_dst, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride, uv_w, uv_h)
   4154 	WebPCopyPlane(tls, (*VP8Io)(unsafe.Pointer(io)).Fv, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, v_dst, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride, uv_w, uv_h)
   4155 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4156 }
   4157 
   4158 // C documentation
   4159 //
   4160 //	// Point-sampling U/V sampler.
   4161 func EmitSampledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4162 	var buf, dst, output uintptr
   4163 	_, _, _ = buf, dst, output
   4164 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4165 	buf = output + 16
   4166 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4167 	WebPSamplerProcessPlane(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, (*VP8Io)(unsafe.Pointer(io)).Fu, (*VP8Io)(unsafe.Pointer(io)).Fv, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, dst, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, WebPSamplers[(*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace])
   4168 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4169 }
   4170 
   4171 //------------------------------------------------------------------------------
   4172 // Fancy upsampling
   4173 
   4174 func EmitFancyRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4175 	var buf, cur_u, cur_v, cur_y, dst, top_u, top_v uintptr
   4176 	var mb_w, num_lines_out, uv_w, y, y_end int32
   4177 	var upsample WebPUpsampleLinePairFunc
   4178 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, cur_u, cur_v, cur_y, dst, mb_w, num_lines_out, top_u, top_v, upsample, uv_w, y, y_end
   4179 	num_lines_out = (*VP8Io)(unsafe.Pointer(io)).Fmb_h // a priori guess
   4180 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4181 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4182 	upsample = WebPUpsamplers[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4183 	cur_y = (*VP8Io)(unsafe.Pointer(io)).Fy
   4184 	cur_u = (*VP8Io)(unsafe.Pointer(io)).Fu
   4185 	cur_v = (*VP8Io)(unsafe.Pointer(io)).Fv
   4186 	top_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u
   4187 	top_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v
   4188 	y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4189 	y_end = (*VP8Io)(unsafe.Pointer(io)).Fmb_y + (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4190 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4191 	uv_w = (mb_w + int32(1)) / int32(2)
   4192 	if y == 0 {
   4193 		// First line is special cased. We mirror the u/v samples at boundary.
   4194 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, cur_y, libc.UintptrFromInt32(0), cur_u, cur_v, cur_u, cur_v, dst, libc.UintptrFromInt32(0), mb_w)
   4195 	} else {
   4196 		// We can finish the left-over line from previous call.
   4197 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y, cur_y, top_u, top_v, cur_u, cur_v, dst-uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride), dst, mb_w)
   4198 		num_lines_out = num_lines_out + 1
   4199 	}
   4200 	// Loop over each output pairs of row.
   4201 	for {
   4202 		if !(y+int32(2) < y_end) {
   4203 			break
   4204 		}
   4205 		top_u = cur_u
   4206 		top_v = cur_v
   4207 		cur_u = cur_u + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4208 		cur_v = cur_v + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4209 		dst = dst + uintptr(int32(2)*(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4210 		cur_y = cur_y + uintptr(int32(2)*(*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4211 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, cur_y-uintptr((*VP8Io)(unsafe.Pointer(io)).Fy_stride), cur_y, top_u, top_v, cur_u, cur_v, dst-uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride), dst, mb_w)
   4212 		goto _1
   4213 	_1:
   4214 		;
   4215 		y = y + int32(2)
   4216 	}
   4217 	// move to last row
   4218 	cur_y = cur_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4219 	if (*VP8Io)(unsafe.Pointer(io)).Fcrop_top+y_end < (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   4220 		// Save the unfinished samples for next call (as we're not done yet).
   4221 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y, cur_y, libc.Uint64FromInt32(mb_w)*uint64(1))
   4222 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u, cur_u, libc.Uint64FromInt32(uv_w)*uint64(1))
   4223 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v, cur_v, libc.Uint64FromInt32(uv_w)*uint64(1))
   4224 		// The fancy upsampler leaves a row unfinished behind
   4225 		// (except for the very last row)
   4226 		num_lines_out = num_lines_out - 1
   4227 	} else {
   4228 		// Process the very last row of even-sized picture
   4229 		if !(y_end&libc.Int32FromInt32(1) != 0) {
   4230 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, cur_y, libc.UintptrFromInt32(0), cur_u, cur_v, cur_u, cur_v, dst+uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride), libc.UintptrFromInt32(0), mb_w)
   4231 		}
   4232 	}
   4233 	return num_lines_out
   4234 }
   4235 
   4236 //------------------------------------------------------------------------------
   4237 
   4238 func FillAlphaPlane(tls *libc.TLS, dst uintptr, w int32, h int32, stride int32) {
   4239 	var j int32
   4240 	_ = j
   4241 	j = 0
   4242 	for {
   4243 		if !(j < h) {
   4244 			break
   4245 		}
   4246 		libc.Xmemset(tls, dst, int32(0xff), libc.Uint64FromInt32(w)*uint64(1))
   4247 		dst = dst + uintptr(stride)
   4248 		goto _1
   4249 	_1:
   4250 		;
   4251 		j = j + 1
   4252 	}
   4253 }
   4254 
   4255 func EmitAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4256 	var alpha, buf, dst uintptr
   4257 	var j, mb_h, mb_w int32
   4258 	_, _, _, _, _, _ = alpha, buf, dst, j, mb_h, mb_w
   4259 	alpha = (*VP8Io)(unsafe.Pointer(io)).Fa
   4260 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4261 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4262 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4263 	dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4264 	_ = expected_num_lines_out
   4265 	if alpha != libc.UintptrFromInt32(0) {
   4266 		j = 0
   4267 		for {
   4268 			if !(j < mb_h) {
   4269 				break
   4270 			}
   4271 			libc.Xmemcpy(tls, dst, alpha, libc.Uint64FromInt32(mb_w)*uint64(1))
   4272 			alpha = alpha + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4273 			dst = dst + uintptr((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4274 			goto _1
   4275 		_1:
   4276 			;
   4277 			j = j + 1
   4278 		}
   4279 	} else {
   4280 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4281 			// the user requested alpha, but there is none, set it to opaque.
   4282 			FillAlphaPlane(tls, dst, mb_w, mb_h, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4283 		}
   4284 	}
   4285 	return 0
   4286 }
   4287 
   4288 func GetAlphaSourceRow(tls *libc.TLS, io uintptr, alpha uintptr, num_rows uintptr) (r int32) {
   4289 	var start_y int32
   4290 	_ = start_y
   4291 	start_y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4292 	**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4293 	// Compensate for the 1-line delay of the fancy upscaler.
   4294 	// This is similar to EmitFancyRGB().
   4295 	if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   4296 		if start_y == 0 {
   4297 			// We don't process the last row yet. It'll be done during the next call.
   4298 			**(**int32)(__ccgo_up(num_rows)) = **(**int32)(__ccgo_up(num_rows)) - 1
   4299 		} else {
   4300 			start_y = start_y - 1
   4301 			// Fortunately, *alpha data is persistent, so we can go back
   4302 			// one row and finish alpha blending, now that the fancy upscaler
   4303 			// completed the YUV->RGB interpolation.
   4304 			**(**uintptr)(__ccgo_up(alpha)) -= uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4305 		}
   4306 		if (*VP8Io)(unsafe.Pointer(io)).Fcrop_top+(*VP8Io)(unsafe.Pointer(io)).Fmb_y+(*VP8Io)(unsafe.Pointer(io)).Fmb_h == (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   4307 			// If it's the very last call, we process all the remaining rows!
   4308 			**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - start_y
   4309 		}
   4310 	}
   4311 	return start_y
   4312 }
   4313 
   4314 func EmitAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4315 	bp := tls.Alloc(16)
   4316 	defer tls.Free(16)
   4317 	var alpha_first, has_alpha, mb_w, start_y, v1 int32
   4318 	var base_rgba, buf, dst uintptr
   4319 	var colorspace, v2 WEBP_CSP_MODE1
   4320 	var v5 bool
   4321 	var _ /* alpha at bp+0 */ uintptr
   4322 	var _ /* num_rows at bp+8 */ int32
   4323 	_, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, has_alpha, mb_w, start_y, v1, v2, v5
   4324 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4325 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4326 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4327 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4328 		alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4329 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4330 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4331 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4332 		if alpha_first != 0 {
   4333 			v1 = 0
   4334 		} else {
   4335 			v1 = int32(3)
   4336 		}
   4337 		dst = base_rgba + uintptr(v1)
   4338 		has_alpha = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPDispatchAlpha})))(tls, **(**uintptr)(__ccgo_up(bp)), (*VP8Io)(unsafe.Pointer(io)).Fwidth, mb_w, **(**int32)(__ccgo_up(bp + 8)), dst, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4339 		_ = expected_num_lines_out
   4340 		// has_alpha is true if there's non-trivial alpha to premultiply with.
   4341 		if v5 = has_alpha != 0; v5 {
   4342 			v2 = colorspace
   4343 			v1 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4344 			goto _4
   4345 		_4:
   4346 		}
   4347 		if v5 && v1 != 0 {
   4348 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, base_rgba, alpha_first, mb_w, **(**int32)(__ccgo_up(bp + 8)), (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4349 		}
   4350 	}
   4351 	return 0
   4352 }
   4353 
   4354 func EmitAlphaRGBA4444(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4355 	bp := tls.Alloc(16)
   4356 	defer tls.Free(16)
   4357 	var alpha_dst, base_rgba, buf uintptr
   4358 	var alpha_mask, alpha_value uint32_t
   4359 	var colorspace, v3 WEBP_CSP_MODE1
   4360 	var i, j, mb_w, start_y, v4 int32
   4361 	var v6 bool
   4362 	var _ /* alpha at bp+0 */ uintptr
   4363 	var _ /* num_rows at bp+8 */ int32
   4364 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, j, mb_w, start_y, v3, v4, v6
   4365 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4366 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4367 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4368 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4369 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4370 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4371 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4372 		alpha_dst = base_rgba + uintptr(1)
   4373 		alpha_mask = uint32(0x0f)
   4374 		j = 0
   4375 		for {
   4376 			if !(j < **(**int32)(__ccgo_up(bp + 8))) {
   4377 				break
   4378 			}
   4379 			i = 0
   4380 			for {
   4381 				if !(i < mb_w) {
   4382 					break
   4383 				}
   4384 				// Fill in the alpha value (converted to 4 bits).
   4385 				alpha_value = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)))) >> int32(4))
   4386 				**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))) = uint8(libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))))&libc.Int32FromInt32(0xf0)) | alpha_value)
   4387 				alpha_mask = alpha_mask & alpha_value
   4388 				goto _2
   4389 			_2:
   4390 				;
   4391 				i = i + 1
   4392 			}
   4393 			**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4394 			alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4395 			goto _1
   4396 		_1:
   4397 			;
   4398 			j = j + 1
   4399 		}
   4400 		_ = expected_num_lines_out
   4401 		if v6 = alpha_mask != uint32(0x0f); v6 {
   4402 			v3 = colorspace
   4403 			v4 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   4404 			goto _5
   4405 		_5:
   4406 		}
   4407 		if v6 && v4 != 0 {
   4408 			(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, base_rgba, mb_w, **(**int32)(__ccgo_up(bp + 8)), (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4409 		}
   4410 	}
   4411 	return 0
   4412 }
   4413 
   4414 //------------------------------------------------------------------------------
   4415 // YUV rescaling (no final RGB conversion needed)
   4416 
   4417 func Rescale(tls *libc.TLS, src uintptr, src_stride int32, new_lines int32, wrk uintptr) (r int32) {
   4418 	var lines_in, num_lines_out int32
   4419 	_, _ = lines_in, num_lines_out
   4420 	num_lines_out = 0
   4421 	for new_lines > 0 { // import new contributions of source rows.
   4422 		lines_in = WebPRescalerImport(tls, wrk, new_lines, src, src_stride)
   4423 		src = src + uintptr(lines_in*src_stride)
   4424 		new_lines = new_lines - lines_in
   4425 		num_lines_out = num_lines_out + WebPRescalerExport(tls, wrk) // emit output row(s)
   4426 	}
   4427 	return num_lines_out
   4428 }
   4429 
   4430 func EmitRescaledYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4431 	var mb_h, num_lines_out, uv_mb_h, v2, v5 int32
   4432 	var scaler uintptr
   4433 	var v1, v4 WEBP_CSP_MODE1
   4434 	var v7 bool
   4435 	_, _, _, _, _, _, _, _, _ = mb_h, num_lines_out, scaler, uv_mb_h, v1, v2, v4, v5, v7
   4436 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4437 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4438 	scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4439 	num_lines_out = 0
   4440 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4441 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4442 		v4 = v1
   4443 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4444 		goto _6
   4445 	_6:
   4446 	}
   4447 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4448 	goto _3
   4449 _3:
   4450 	;
   4451 	if v2 != 0 && (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4452 		// Before rescaling, we premultiply the luma directly into the io->y
   4453 		// internal buffer. This is OK since these samples are not used for
   4454 		// intra-prediction (the top samples are saved in cache_y/u/v).
   4455 		// But we need to cast the const away, though.
   4456 		WebPMultRows(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, (*VP8Io)(unsafe.Pointer(io)).Fa, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, mb_h, 0)
   4457 	}
   4458 	num_lines_out = Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, mb_h, scaler)
   4459 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fu, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4460 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fv, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4461 	return num_lines_out
   4462 }
   4463 
   4464 func EmitRescaledAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4465 	var buf, dst_a, dst_y uintptr
   4466 	var num_lines_out int32
   4467 	_, _, _, _ = buf, dst_a, dst_y, num_lines_out
   4468 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4469 	dst_a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4470 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4471 		dst_y = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4472 		num_lines_out = Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fa, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4473 		if num_lines_out > 0 { // unmultiply the Y
   4474 			WebPMultRows(tls, dst_y, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride, dst_a, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride, (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width, num_lines_out, int32(1))
   4475 		}
   4476 	} else {
   4477 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4478 			// the user requested alpha, but there is none, set it to opaque.
   4479 			FillAlphaPlane(tls, dst_a, (*VP8Io)(unsafe.Pointer(io)).Fscaled_width, expected_num_lines_out, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4480 		}
   4481 	}
   4482 	return 0
   4483 }
   4484 
   4485 func InitYUVRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4486 	var buf, scalers, work, v12 uintptr
   4487 	var has_alpha, num_rescalers, out_height, out_width, uv_in_height, uv_in_width, uv_out_height, uv_out_width, v2, v5, v8 int32
   4488 	var rescaler_size, uv_work_size, work_size size_t
   4489 	var total_size, v9 uint64_t
   4490 	var v1, v4 WEBP_CSP_MODE1
   4491 	var v7 bool
   4492 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = buf, has_alpha, num_rescalers, out_height, out_width, rescaler_size, scalers, total_size, uv_in_height, uv_in_width, uv_out_height, uv_out_width, uv_work_size, work, work_size, v1, v12, v2, v4, v5, v7, v8, v9
   4493 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4494 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4495 		v4 = v1
   4496 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4497 		goto _6
   4498 	_6:
   4499 	}
   4500 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4501 	goto _3
   4502 _3:
   4503 	has_alpha = v2
   4504 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4505 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   4506 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   4507 	uv_out_width = (out_width + int32(1)) >> int32(1)
   4508 	uv_out_height = (out_height + int32(1)) >> int32(1)
   4509 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4510 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   4511 	// scratch memory for luma rescaler
   4512 	work_size = uint64(2) * libc.Uint64FromInt32(out_width)
   4513 	uv_work_size = libc.Uint64FromInt32(int32(2) * uv_out_width)
   4514 	if has_alpha != 0 {
   4515 		v8 = int32(4)
   4516 	} else {
   4517 		v8 = int32(3)
   4518 	}
   4519 	num_rescalers = v8
   4520 	total_size = (work_size + uint64(2)*uv_work_size) * uint64(4)
   4521 	if has_alpha != 0 {
   4522 		total_size = total_size + work_size*uint64(4)
   4523 	}
   4524 	rescaler_size = libc.Uint64FromInt32(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   4525 	total_size = total_size + rescaler_size
   4526 	v9 = total_size
   4527 	v2 = libc.BoolInt32(v9 == v9)
   4528 	goto _11
   4529 _11:
   4530 	if !(v2 != 0) {
   4531 		return 0
   4532 	}
   4533 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   4534 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4535 		return 0 // memory error
   4536 	}
   4537 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4538 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   4539 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   4540 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   4541 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   4542 	if has_alpha != 0 {
   4543 		v12 = scalers + 3*104
   4544 	} else {
   4545 		v12 = libc.UintptrFromInt32(0)
   4546 	}
   4547 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   4548 	if !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy, out_width, out_height, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride, int32(1), work) != 0) || !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_in_width, uv_in_height, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu, uv_out_width, uv_out_height, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride, int32(1), work+uintptr(work_size)*4) != 0) || !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v, uv_in_width, uv_in_height, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv, uv_out_width, uv_out_height, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride, int32(1), work+uintptr(work_size)*4+uintptr(uv_work_size)*4) != 0) {
   4549 		return 0
   4550 	}
   4551 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledYUV)
   4552 	if has_alpha != 0 {
   4553 		if !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa, out_width, out_height, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride, int32(1), work+uintptr(work_size)*4+uintptr(uint64(2)*uv_work_size)*4) != 0) {
   4554 			return 0
   4555 		}
   4556 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaYUV)
   4557 		WebPInitAlphaProcessing(tls)
   4558 	}
   4559 	return int32(1)
   4560 }
   4561 
   4562 //------------------------------------------------------------------------------
   4563 // RGBA rescaling
   4564 
   4565 func ExportRGB(tls *libc.TLS, p uintptr, y_pos int32) (r int32) {
   4566 	var buf, dst, v1, v10, v4, v7 uintptr
   4567 	var convert WebPYUV444Converter
   4568 	var num_lines_out, v11, v2, v5, v8 int32
   4569 	var v13 bool
   4570 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, convert, dst, num_lines_out, v1, v10, v11, v13, v2, v4, v5, v7, v8
   4571 	convert = WebPYUV444Converters[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4572 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4573 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4574 	num_lines_out = 0
   4575 	// For RGB rescaling, because of the YUV420, current scan position
   4576 	// U/V can be +1/-1 line from the Y one.  Hence the double test.
   4577 	for {
   4578 		v1 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4579 		v4 = v1
   4580 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
   4581 		goto _6
   4582 	_6:
   4583 		;
   4584 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
   4585 		goto _3
   4586 	_3:
   4587 		;
   4588 		if v13 = v2 != 0; v13 {
   4589 			v7 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u
   4590 			v10 = v7
   4591 			v11 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v10)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v10)).Fdst_height)
   4592 			goto _12
   4593 		_12:
   4594 			;
   4595 			v8 = libc.BoolInt32(!(v11 != 0) && (*WebPRescaler)(unsafe.Pointer(v7)).Fy_accum <= 0)
   4596 			goto _9
   4597 		_9:
   4598 		}
   4599 		if !(v13 && v8 != 0) {
   4600 			break
   4601 		}
   4602 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y)
   4603 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4604 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4605 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{convert})))(tls, (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y)).Fdst, (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)).Fdst, (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)).Fdst, dst, (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y)).Fdst_width)
   4606 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4607 		num_lines_out = num_lines_out + 1
   4608 	}
   4609 	return num_lines_out
   4610 }
   4611 
   4612 func EmitRescaledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4613 	var j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in int32
   4614 	_, _, _, _, _, _, _, _ = j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in
   4615 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4616 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4617 	j = 0
   4618 	uv_j = 0
   4619 	num_lines_out = 0
   4620 	for j < mb_h {
   4621 		y_lines_in = WebPRescalerImport(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y, mb_h-j, (*VP8Io)(unsafe.Pointer(io)).Fy+uintptr(int64(j)*int64((*VP8Io)(unsafe.Pointer(io)).Fy_stride)), (*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4622 		j = j + y_lines_in
   4623 		if WebPRescaleNeededLines(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_mb_h-uv_j) != 0 {
   4624 			u_lines_in = WebPRescalerImport(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_mb_h-uv_j, (*VP8Io)(unsafe.Pointer(io)).Fu+uintptr(int64(uv_j)*int64((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)), (*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4625 			v_lines_in = WebPRescalerImport(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v, uv_mb_h-uv_j, (*VP8Io)(unsafe.Pointer(io)).Fv+uintptr(int64(uv_j)*int64((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)), (*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4626 			_ = v_lines_in // remove a gcc warning
   4627 			uv_j = uv_j + u_lines_in
   4628 		}
   4629 		num_lines_out = num_lines_out + ExportRGB(tls, p, (*WebPDecParams)(unsafe.Pointer(p)).Flast_y+num_lines_out)
   4630 	}
   4631 	return num_lines_out
   4632 }
   4633 
   4634 func ExportAlpha(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4635 	var alpha_first, is_premult_alpha, num_lines_out, width, v1, v3, v6, v9 int32
   4636 	var base_rgba, buf, dst, v5, v8 uintptr
   4637 	var colorspace, v2 WEBP_CSP_MODE1
   4638 	var non_opaque uint32_t
   4639 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, is_premult_alpha, non_opaque, num_lines_out, width, v1, v2, v3, v5, v6, v8, v9
   4640 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4641 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4642 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4643 	alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4644 	if alpha_first != 0 {
   4645 		v1 = 0
   4646 	} else {
   4647 		v1 = int32(3)
   4648 	}
   4649 	dst = base_rgba + uintptr(v1)
   4650 	num_lines_out = 0
   4651 	v2 = colorspace
   4652 	v3 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4653 	goto _4
   4654 _4:
   4655 	is_premult_alpha = v3
   4656 	non_opaque = uint32(0)
   4657 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4658 	for {
   4659 		v5 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4660 		v8 = v5
   4661 		v9 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v8)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v8)).Fdst_height)
   4662 		goto _10
   4663 	_10:
   4664 		;
   4665 		v6 = libc.BoolInt32(!(v9 != 0) && (*WebPRescaler)(unsafe.Pointer(v5)).Fy_accum <= 0)
   4666 		goto _7
   4667 	_7:
   4668 		;
   4669 		if !(v6 != 0 && num_lines_out < max_lines_out) {
   4670 			break
   4671 		}
   4672 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4673 		non_opaque = non_opaque | libc.Uint32FromInt32((*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPDispatchAlpha})))(tls, (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst, 0, width, int32(1), dst, 0))
   4674 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4675 		num_lines_out = num_lines_out + 1
   4676 	}
   4677 	if is_premult_alpha != 0 && non_opaque != 0 {
   4678 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, base_rgba, alpha_first, width, num_lines_out, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4679 	}
   4680 	return num_lines_out
   4681 }
   4682 
   4683 func ExportAlphaRGBA4444(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4684 	var alpha_dst, base_rgba, buf, v4, v7 uintptr
   4685 	var alpha_mask, alpha_value uint32_t
   4686 	var colorspace, v1 WEBP_CSP_MODE1
   4687 	var i, is_premult_alpha, num_lines_out, width, v2, v5, v8 int32
   4688 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, is_premult_alpha, num_lines_out, width, v1, v2, v4, v5, v7, v8
   4689 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4690 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4691 	alpha_dst = base_rgba + uintptr(1)
   4692 	num_lines_out = 0
   4693 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4694 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4695 	v1 = colorspace
   4696 	v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   4697 	goto _3
   4698 _3:
   4699 	is_premult_alpha = v2
   4700 	alpha_mask = uint32(0x0f)
   4701 	for {
   4702 		v4 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4703 		v7 = v4
   4704 		v8 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v7)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v7)).Fdst_height)
   4705 		goto _9
   4706 	_9:
   4707 		;
   4708 		v5 = libc.BoolInt32(!(v8 != 0) && (*WebPRescaler)(unsafe.Pointer(v4)).Fy_accum <= 0)
   4709 		goto _6
   4710 	_6:
   4711 		;
   4712 		if !(v5 != 0 && num_lines_out < max_lines_out) {
   4713 			break
   4714 		}
   4715 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4716 		i = 0
   4717 		for {
   4718 			if !(i < width) {
   4719 				break
   4720 			}
   4721 			// Fill in the alpha value (converted to 4 bits).
   4722 			alpha_value = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst + uintptr(i)))) >> int32(4))
   4723 			**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))) = uint8(libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha_dst + uintptr(int32(2)*i))))&libc.Int32FromInt32(0xf0)) | alpha_value)
   4724 			alpha_mask = alpha_mask & alpha_value
   4725 			goto _10
   4726 		_10:
   4727 			;
   4728 			i = i + 1
   4729 		}
   4730 		alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4731 		num_lines_out = num_lines_out + 1
   4732 	}
   4733 	if is_premult_alpha != 0 && alpha_mask != uint32(0x0f) {
   4734 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, base_rgba, width, num_lines_out, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4735 	}
   4736 	return num_lines_out
   4737 }
   4738 
   4739 func EmitRescaledAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_out_lines int32) (r int32) {
   4740 	var lines_left, y_end int32
   4741 	var row_offset int64_t
   4742 	var scaler uintptr
   4743 	_, _, _, _ = lines_left, row_offset, scaler, y_end
   4744 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4745 		scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4746 		lines_left = expected_num_out_lines
   4747 		y_end = (*WebPDecParams)(unsafe.Pointer(p)).Flast_y + lines_left
   4748 		for lines_left > 0 {
   4749 			row_offset = int64((*WebPRescaler)(unsafe.Pointer(scaler)).Fsrc_y) - int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)
   4750 			WebPRescalerImport(tls, scaler, (*VP8Io)(unsafe.Pointer(io)).Fmb_h+(*VP8Io)(unsafe.Pointer(io)).Fmb_y-(*WebPRescaler)(unsafe.Pointer(scaler)).Fsrc_y, (*VP8Io)(unsafe.Pointer(io)).Fa+uintptr(row_offset*int64((*VP8Io)(unsafe.Pointer(io)).Fwidth)), (*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4751 			lines_left = lines_left - (*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row})))(tls, p, y_end-lines_left, lines_left)
   4752 		}
   4753 	}
   4754 	return 0
   4755 }
   4756 
   4757 func InitRGBRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4758 	var has_alpha, num_rescalers, out_height, out_width, uv_in_height, uv_in_width, v2, v5, v8 int32
   4759 	var rescaler_size, work_size size_t
   4760 	var scalers, tmp, work, v12 uintptr
   4761 	var tmp_size1, tmp_size2, total_size, v9 uint64_t
   4762 	var v1, v4 WEBP_CSP_MODE1
   4763 	var v7 bool
   4764 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = has_alpha, num_rescalers, out_height, out_width, rescaler_size, scalers, tmp, tmp_size1, tmp_size2, total_size, uv_in_height, uv_in_width, work, work_size, v1, v12, v2, v4, v5, v7, v8, v9
   4765 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4766 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4767 		v4 = v1
   4768 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4769 		goto _6
   4770 	_6:
   4771 	}
   4772 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4773 	goto _3
   4774 _3:
   4775 	has_alpha = v2
   4776 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   4777 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   4778 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4779 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   4780 	// scratch memory for one rescaler
   4781 	work_size = uint64(2) * libc.Uint64FromInt32(out_width)
   4782 	if has_alpha != 0 {
   4783 		v8 = int32(4)
   4784 	} else {
   4785 		v8 = int32(3)
   4786 	}
   4787 	num_rescalers = v8
   4788 	tmp_size1 = libc.Uint64FromInt32(num_rescalers) * work_size
   4789 	tmp_size2 = libc.Uint64FromInt32(num_rescalers) * libc.Uint64FromInt32(out_width)
   4790 	total_size = tmp_size1*uint64(4) + tmp_size2*uint64(1)
   4791 	rescaler_size = libc.Uint64FromInt32(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   4792 	total_size = total_size + rescaler_size
   4793 	v9 = total_size
   4794 	v2 = libc.BoolInt32(v9 == v9)
   4795 	goto _11
   4796 _11:
   4797 	if !(v2 != 0) {
   4798 		return 0
   4799 	}
   4800 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   4801 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4802 		return 0 // memory error
   4803 	}
   4804 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4805 	tmp = work + uintptr(tmp_size1)*4
   4806 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   4807 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   4808 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   4809 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   4810 	if has_alpha != 0 {
   4811 		v12 = scalers + 3*104
   4812 	} else {
   4813 		v12 = libc.UintptrFromInt32(0)
   4814 	}
   4815 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   4816 	if !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, tmp+uintptr(0*out_width), out_width, out_height, 0, int32(1), work+uintptr(uint64(0)*work_size)*4) != 0) || !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_in_width, uv_in_height, tmp+uintptr(int32(1)*out_width), out_width, out_height, 0, int32(1), work+uintptr(uint64(1)*work_size)*4) != 0) || !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v, uv_in_width, uv_in_height, tmp+uintptr(int32(2)*out_width), out_width, out_height, 0, int32(1), work+uintptr(uint64(2)*work_size)*4) != 0) {
   4817 		return 0
   4818 	}
   4819 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledRGB)
   4820 	WebPInitYUV444Converters(tls)
   4821 	if has_alpha != 0 {
   4822 		if !(WebPRescalerInit(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, tmp+uintptr(int32(3)*out_width), out_width, out_height, 0, int32(1), work+uintptr(uint64(3)*work_size)*4) != 0) {
   4823 			return 0
   4824 		}
   4825 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaRGB)
   4826 		if (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace == int32(MODE_RGBA_4444) || (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace == int32(MODE_rgbA_4444) {
   4827 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlphaRGBA4444)
   4828 		} else {
   4829 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlpha)
   4830 		}
   4831 		WebPInitAlphaProcessing(tls)
   4832 	}
   4833 	return int32(1)
   4834 }
   4835 
   4836 //------------------------------------------------------------------------------
   4837 // Default custom functions
   4838 
   4839 func CustomSetup(tls *libc.TLS, io uintptr) (r int32) {
   4840 	var colorspace, v3, v6 WEBP_CSP_MODE1
   4841 	var is_alpha, is_rgb, ok, uv_width, v1, v4, v7 int32
   4842 	var p, v16, v17 uintptr
   4843 	var v9 bool
   4844 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = colorspace, is_alpha, is_rgb, ok, p, uv_width, v1, v16, v17, v3, v4, v6, v7, v9
   4845 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   4846 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4847 	v1 = libc.BoolInt32(colorspace < int32(MODE_YUV))
   4848 	goto _2
   4849 _2:
   4850 	is_rgb = v1
   4851 	v3 = colorspace
   4852 	if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   4853 		v6 = v3
   4854 		v7 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   4855 		goto _8
   4856 	_8:
   4857 	}
   4858 	v4 = libc.BoolInt32(v9 || v7 != 0)
   4859 	goto _5
   4860 _5:
   4861 	is_alpha = v4
   4862 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   4863 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = libc.UintptrFromInt32(0)
   4864 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = libc.UintptrFromInt32(0)
   4865 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = libc.UintptrFromInt32(0)
   4866 	if is_alpha != 0 {
   4867 		v1 = int32(MODE_YUV)
   4868 	} else {
   4869 		v1 = int32(MODE_YUVA)
   4870 	}
   4871 	if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(p)).Foptions, io, v1) != 0) {
   4872 		return 0
   4873 	}
   4874 	if v9 = is_alpha != 0; v9 {
   4875 		v3 = colorspace
   4876 		v1 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   4877 		goto _13
   4878 	_13:
   4879 	}
   4880 	if v9 && v1 != 0 {
   4881 		WebPInitUpsamplers(tls)
   4882 	}
   4883 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
   4884 		if is_rgb != 0 {
   4885 			v1 = InitRGBRescaler(tls, io, p)
   4886 		} else {
   4887 			v1 = InitYUVRescaler(tls, io, p)
   4888 		}
   4889 		ok = v1
   4890 		if !(ok != 0) {
   4891 			return 0 // memory error
   4892 		}
   4893 	} else {
   4894 		if is_rgb != 0 {
   4895 			WebPInitSamplers(tls)
   4896 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitSampledRGB) // default
   4897 			if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   4898 				uv_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4899 				(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), libc.Uint64FromInt32((*VP8Io)(unsafe.Pointer(io)).Fmb_w+libc.Int32FromInt32(2)*uv_width))
   4900 				if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4901 					return 0 // memory error.
   4902 				}
   4903 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4904 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fmb_w)
   4905 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u + uintptr(uv_width)
   4906 				(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitFancyRGB)
   4907 				WebPInitUpsamplers(tls)
   4908 			}
   4909 		} else {
   4910 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitYUV)
   4911 		}
   4912 		if is_alpha != 0 { // need transparency output
   4913 			if colorspace == int32(MODE_RGBA_4444) || colorspace == int32(MODE_rgbA_4444) {
   4914 				v16 = __ccgo_fp(EmitAlphaRGBA4444)
   4915 			} else {
   4916 				if is_rgb != 0 {
   4917 					v17 = __ccgo_fp(EmitAlphaRGB)
   4918 				} else {
   4919 					v17 = __ccgo_fp(EmitAlphaYUV)
   4920 				}
   4921 				v16 = v17
   4922 			}
   4923 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = v16
   4924 			if is_rgb != 0 {
   4925 				WebPInitAlphaProcessing(tls)
   4926 			}
   4927 		}
   4928 	}
   4929 	return int32(1)
   4930 }
   4931 
   4932 //------------------------------------------------------------------------------
   4933 
   4934 func CustomPut(tls *libc.TLS, io uintptr) (r int32) {
   4935 	var mb_h, mb_w, num_lines_out int32
   4936 	var p uintptr
   4937 	_, _, _, _ = mb_h, mb_w, num_lines_out, p
   4938 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   4939 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4940 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4941 	if mb_w <= 0 || mb_h <= 0 {
   4942 		return 0
   4943 	}
   4944 	num_lines_out = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit})))(tls, io, p)
   4945 	if (*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha != libc.UintptrFromInt32(0) {
   4946 		(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha})))(tls, io, p, num_lines_out)
   4947 	}
   4948 	**(**int32)(__ccgo_up(p + 32)) += num_lines_out
   4949 	return int32(1)
   4950 }
   4951 
   4952 //------------------------------------------------------------------------------
   4953 
   4954 func CustomTeardown(tls *libc.TLS, io uintptr) {
   4955 	var p uintptr
   4956 	_ = p
   4957 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   4958 	WebPSafeFree(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fmemory)
   4959 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   4960 }
   4961 
   4962 //------------------------------------------------------------------------------
   4963 // Main entry point
   4964 
   4965 func WebPInitCustomIo(tls *libc.TLS, params uintptr, io uintptr) {
   4966 	(*VP8Io)(unsafe.Pointer(io)).Fput = __ccgo_fp(CustomPut)
   4967 	(*VP8Io)(unsafe.Pointer(io)).Fsetup = __ccgo_fp(CustomSetup)
   4968 	(*VP8Io)(unsafe.Pointer(io)).Fteardown = __ccgo_fp(CustomTeardown)
   4969 	(*VP8Io)(unsafe.Pointer(io)).Fopaque = params
   4970 }
   4971 
   4972 var kHashMul5 = uint32(0x1e35a7bd)
   4973 
   4974 //------------------------------------------------------------------------------
   4975 
   4976 // Copyright 2010 Google Inc. All Rights Reserved.
   4977 //
   4978 // Use of this source code is governed by a BSD-style license
   4979 // that can be found in the COPYING file in the root of the source
   4980 // tree. An additional intellectual property rights grant can be found
   4981 // in the file PATENTS. All contributing project authors may
   4982 // be found in the AUTHORS file in the root of the source tree.
   4983 // -----------------------------------------------------------------------------
   4984 //
   4985 // Boolean decoder
   4986 //
   4987 // Author: Skal (pascal.massimino@gmail.com)
   4988 //         Vikas Arora (vikaas.arora@gmail.com)
   4989 
   4990 // Copyright 2010 Google Inc. All Rights Reserved.
   4991 //
   4992 // Use of this source code is governed by a BSD-style license
   4993 // that can be found in the COPYING file in the root of the source
   4994 // tree. An additional intellectual property rights grant can be found
   4995 // in the file PATENTS. All contributing project authors may
   4996 // be found in the AUTHORS file in the root of the source tree.
   4997 // -----------------------------------------------------------------------------
   4998 //
   4999 //  Common types + memory wrappers
   5000 //
   5001 // Author: Skal (pascal.massimino@gmail.com)
   5002 
   5003 func clip(tls *libc.TLS, v int32, M int32) (r int32) {
   5004 	var v1, v2 int32
   5005 	_, _ = v1, v2
   5006 	if v < 0 {
   5007 		v1 = 0
   5008 	} else {
   5009 		if v > M {
   5010 			v2 = M
   5011 		} else {
   5012 			v2 = v
   5013 		}
   5014 		v1 = v2
   5015 	}
   5016 	return v1
   5017 }
   5018 
   5019 // C documentation
   5020 //
   5021 //	// Paragraph 14.1
   5022 var kDcTable = [128]uint8_t{
   5023 	0:   uint8(4),
   5024 	1:   uint8(5),
   5025 	2:   uint8(6),
   5026 	3:   uint8(7),
   5027 	4:   uint8(8),
   5028 	5:   uint8(9),
   5029 	6:   uint8(10),
   5030 	7:   uint8(10),
   5031 	8:   uint8(11),
   5032 	9:   uint8(12),
   5033 	10:  uint8(13),
   5034 	11:  uint8(14),
   5035 	12:  uint8(15),
   5036 	13:  uint8(16),
   5037 	14:  uint8(17),
   5038 	15:  uint8(17),
   5039 	16:  uint8(18),
   5040 	17:  uint8(19),
   5041 	18:  uint8(20),
   5042 	19:  uint8(20),
   5043 	20:  uint8(21),
   5044 	21:  uint8(21),
   5045 	22:  uint8(22),
   5046 	23:  uint8(22),
   5047 	24:  uint8(23),
   5048 	25:  uint8(23),
   5049 	26:  uint8(24),
   5050 	27:  uint8(25),
   5051 	28:  uint8(25),
   5052 	29:  uint8(26),
   5053 	30:  uint8(27),
   5054 	31:  uint8(28),
   5055 	32:  uint8(29),
   5056 	33:  uint8(30),
   5057 	34:  uint8(31),
   5058 	35:  uint8(32),
   5059 	36:  uint8(33),
   5060 	37:  uint8(34),
   5061 	38:  uint8(35),
   5062 	39:  uint8(36),
   5063 	40:  uint8(37),
   5064 	41:  uint8(37),
   5065 	42:  uint8(38),
   5066 	43:  uint8(39),
   5067 	44:  uint8(40),
   5068 	45:  uint8(41),
   5069 	46:  uint8(42),
   5070 	47:  uint8(43),
   5071 	48:  uint8(44),
   5072 	49:  uint8(45),
   5073 	50:  uint8(46),
   5074 	51:  uint8(46),
   5075 	52:  uint8(47),
   5076 	53:  uint8(48),
   5077 	54:  uint8(49),
   5078 	55:  uint8(50),
   5079 	56:  uint8(51),
   5080 	57:  uint8(52),
   5081 	58:  uint8(53),
   5082 	59:  uint8(54),
   5083 	60:  uint8(55),
   5084 	61:  uint8(56),
   5085 	62:  uint8(57),
   5086 	63:  uint8(58),
   5087 	64:  uint8(59),
   5088 	65:  uint8(60),
   5089 	66:  uint8(61),
   5090 	67:  uint8(62),
   5091 	68:  uint8(63),
   5092 	69:  uint8(64),
   5093 	70:  uint8(65),
   5094 	71:  uint8(66),
   5095 	72:  uint8(67),
   5096 	73:  uint8(68),
   5097 	74:  uint8(69),
   5098 	75:  uint8(70),
   5099 	76:  uint8(71),
   5100 	77:  uint8(72),
   5101 	78:  uint8(73),
   5102 	79:  uint8(74),
   5103 	80:  uint8(75),
   5104 	81:  uint8(76),
   5105 	82:  uint8(76),
   5106 	83:  uint8(77),
   5107 	84:  uint8(78),
   5108 	85:  uint8(79),
   5109 	86:  uint8(80),
   5110 	87:  uint8(81),
   5111 	88:  uint8(82),
   5112 	89:  uint8(83),
   5113 	90:  uint8(84),
   5114 	91:  uint8(85),
   5115 	92:  uint8(86),
   5116 	93:  uint8(87),
   5117 	94:  uint8(88),
   5118 	95:  uint8(89),
   5119 	96:  uint8(91),
   5120 	97:  uint8(93),
   5121 	98:  uint8(95),
   5122 	99:  uint8(96),
   5123 	100: uint8(98),
   5124 	101: uint8(100),
   5125 	102: uint8(101),
   5126 	103: uint8(102),
   5127 	104: uint8(104),
   5128 	105: uint8(106),
   5129 	106: uint8(108),
   5130 	107: uint8(110),
   5131 	108: uint8(112),
   5132 	109: uint8(114),
   5133 	110: uint8(116),
   5134 	111: uint8(118),
   5135 	112: uint8(122),
   5136 	113: uint8(124),
   5137 	114: uint8(126),
   5138 	115: uint8(128),
   5139 	116: uint8(130),
   5140 	117: uint8(132),
   5141 	118: uint8(134),
   5142 	119: uint8(136),
   5143 	120: uint8(138),
   5144 	121: uint8(140),
   5145 	122: uint8(143),
   5146 	123: uint8(145),
   5147 	124: uint8(148),
   5148 	125: uint8(151),
   5149 	126: uint8(154),
   5150 	127: uint8(157),
   5151 }
   5152 
   5153 var kAcTable = [128]uint16_t{
   5154 	0:   uint16(4),
   5155 	1:   uint16(5),
   5156 	2:   uint16(6),
   5157 	3:   uint16(7),
   5158 	4:   uint16(8),
   5159 	5:   uint16(9),
   5160 	6:   uint16(10),
   5161 	7:   uint16(11),
   5162 	8:   uint16(12),
   5163 	9:   uint16(13),
   5164 	10:  uint16(14),
   5165 	11:  uint16(15),
   5166 	12:  uint16(16),
   5167 	13:  uint16(17),
   5168 	14:  uint16(18),
   5169 	15:  uint16(19),
   5170 	16:  uint16(20),
   5171 	17:  uint16(21),
   5172 	18:  uint16(22),
   5173 	19:  uint16(23),
   5174 	20:  uint16(24),
   5175 	21:  uint16(25),
   5176 	22:  uint16(26),
   5177 	23:  uint16(27),
   5178 	24:  uint16(28),
   5179 	25:  uint16(29),
   5180 	26:  uint16(30),
   5181 	27:  uint16(31),
   5182 	28:  uint16(32),
   5183 	29:  uint16(33),
   5184 	30:  uint16(34),
   5185 	31:  uint16(35),
   5186 	32:  uint16(36),
   5187 	33:  uint16(37),
   5188 	34:  uint16(38),
   5189 	35:  uint16(39),
   5190 	36:  uint16(40),
   5191 	37:  uint16(41),
   5192 	38:  uint16(42),
   5193 	39:  uint16(43),
   5194 	40:  uint16(44),
   5195 	41:  uint16(45),
   5196 	42:  uint16(46),
   5197 	43:  uint16(47),
   5198 	44:  uint16(48),
   5199 	45:  uint16(49),
   5200 	46:  uint16(50),
   5201 	47:  uint16(51),
   5202 	48:  uint16(52),
   5203 	49:  uint16(53),
   5204 	50:  uint16(54),
   5205 	51:  uint16(55),
   5206 	52:  uint16(56),
   5207 	53:  uint16(57),
   5208 	54:  uint16(58),
   5209 	55:  uint16(60),
   5210 	56:  uint16(62),
   5211 	57:  uint16(64),
   5212 	58:  uint16(66),
   5213 	59:  uint16(68),
   5214 	60:  uint16(70),
   5215 	61:  uint16(72),
   5216 	62:  uint16(74),
   5217 	63:  uint16(76),
   5218 	64:  uint16(78),
   5219 	65:  uint16(80),
   5220 	66:  uint16(82),
   5221 	67:  uint16(84),
   5222 	68:  uint16(86),
   5223 	69:  uint16(88),
   5224 	70:  uint16(90),
   5225 	71:  uint16(92),
   5226 	72:  uint16(94),
   5227 	73:  uint16(96),
   5228 	74:  uint16(98),
   5229 	75:  uint16(100),
   5230 	76:  uint16(102),
   5231 	77:  uint16(104),
   5232 	78:  uint16(106),
   5233 	79:  uint16(108),
   5234 	80:  uint16(110),
   5235 	81:  uint16(112),
   5236 	82:  uint16(114),
   5237 	83:  uint16(116),
   5238 	84:  uint16(119),
   5239 	85:  uint16(122),
   5240 	86:  uint16(125),
   5241 	87:  uint16(128),
   5242 	88:  uint16(131),
   5243 	89:  uint16(134),
   5244 	90:  uint16(137),
   5245 	91:  uint16(140),
   5246 	92:  uint16(143),
   5247 	93:  uint16(146),
   5248 	94:  uint16(149),
   5249 	95:  uint16(152),
   5250 	96:  uint16(155),
   5251 	97:  uint16(158),
   5252 	98:  uint16(161),
   5253 	99:  uint16(164),
   5254 	100: uint16(167),
   5255 	101: uint16(170),
   5256 	102: uint16(173),
   5257 	103: uint16(177),
   5258 	104: uint16(181),
   5259 	105: uint16(185),
   5260 	106: uint16(189),
   5261 	107: uint16(193),
   5262 	108: uint16(197),
   5263 	109: uint16(201),
   5264 	110: uint16(205),
   5265 	111: uint16(209),
   5266 	112: uint16(213),
   5267 	113: uint16(217),
   5268 	114: uint16(221),
   5269 	115: uint16(225),
   5270 	116: uint16(229),
   5271 	117: uint16(234),
   5272 	118: uint16(239),
   5273 	119: uint16(245),
   5274 	120: uint16(249),
   5275 	121: uint16(254),
   5276 	122: uint16(259),
   5277 	123: uint16(264),
   5278 	124: uint16(269),
   5279 	125: uint16(274),
   5280 	126: uint16(279),
   5281 	127: uint16(284),
   5282 }
   5283 
   5284 //------------------------------------------------------------------------------
   5285 // Paragraph 9.6
   5286 
   5287 func VP8ParseQuant(tls *libc.TLS, dec uintptr) {
   5288 	var base_q0, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, i, q, v1, v2, v3, v4, v5 int32
   5289 	var br, hdr, m uintptr
   5290 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_q0, br, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, hdr, i, m, q, v1, v2, v3, v4, v5
   5291 	br = dec + 16
   5292 	base_q0 = libc.Int32FromUint32(VP8GetValue(tls, br, int32(7)))
   5293 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5294 		v1 = VP8GetSignedValue(tls, br, int32(4))
   5295 	} else {
   5296 		v1 = 0
   5297 	}
   5298 	dqy1_dc = v1
   5299 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5300 		v2 = VP8GetSignedValue(tls, br, int32(4))
   5301 	} else {
   5302 		v2 = 0
   5303 	}
   5304 	dqy2_dc = v2
   5305 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5306 		v3 = VP8GetSignedValue(tls, br, int32(4))
   5307 	} else {
   5308 		v3 = 0
   5309 	}
   5310 	dqy2_ac = v3
   5311 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5312 		v4 = VP8GetSignedValue(tls, br, int32(4))
   5313 	} else {
   5314 		v4 = 0
   5315 	}
   5316 	dquv_dc = v4
   5317 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5318 		v5 = VP8GetSignedValue(tls, br, int32(4))
   5319 	} else {
   5320 		v5 = 0
   5321 	}
   5322 	dquv_ac = v5
   5323 	hdr = dec + 132
   5324 	i = 0
   5325 	for {
   5326 		if !(i < int32(NUM_MB_SEGMENTS)) {
   5327 			break
   5328 		}
   5329 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
   5330 			q = int32(**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(i))))
   5331 			if !((*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta != 0) {
   5332 				q = q + base_q0
   5333 			}
   5334 		} else {
   5335 			if i > 0 {
   5336 				**(**VP8QuantMatrix)(__ccgo_up(dec + 1060 + uintptr(i)*32)) = **(**VP8QuantMatrix)(__ccgo_up(dec + 1060))
   5337 				goto _6
   5338 			} else {
   5339 				q = base_q0
   5340 			}
   5341 		}
   5342 		m = dec + 1060 + uintptr(i)*32
   5343 		**(**int32)(__ccgo_up(m)) = libc.Int32FromUint8(kDcTable[clip(tls, q+dqy1_dc, int32(127))])
   5344 		**(**int32)(__ccgo_up(m + 1*4)) = libc.Int32FromUint16(kAcTable[clip(tls, q+0, int32(127))])
   5345 		**(**int32)(__ccgo_up(m + 8)) = libc.Int32FromUint8(kDcTable[clip(tls, q+dqy2_dc, int32(127))]) * int32(2)
   5346 		// For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
   5347 		// The smallest precision for that is '(x*6349) >> 12' but 16 is a good
   5348 		// word size.
   5349 		**(**int32)(__ccgo_up(m + 8 + 1*4)) = libc.Int32FromUint16(kAcTable[clip(tls, q+dqy2_ac, int32(127))]) * int32(101581) >> int32(16)
   5350 		if **(**int32)(__ccgo_up(m + 8 + 1*4)) < int32(8) {
   5351 			**(**int32)(__ccgo_up(m + 8 + 1*4)) = int32(8)
   5352 		}
   5353 		**(**int32)(__ccgo_up(m + 16)) = libc.Int32FromUint8(kDcTable[clip(tls, q+dquv_dc, int32(117))])
   5354 		**(**int32)(__ccgo_up(m + 16 + 1*4)) = libc.Int32FromUint16(kAcTable[clip(tls, q+dquv_ac, int32(127))])
   5355 		(*VP8QuantMatrix)(unsafe.Pointer(m)).Fuv_quant = q + dquv_ac // for dithering strength evaluation
   5356 		goto _6
   5357 	_6:
   5358 		;
   5359 		i = i + 1
   5360 	}
   5361 }
   5362 
   5363 const USE_GENERIC_TREE = 1
   5364 
   5365 var kHashMul6 = uint32(0x1e35a7bd)
   5366 
   5367 type lbit_t = uint64
   5368 
   5369 // Copyright 2010 Google Inc. All Rights Reserved.
   5370 //
   5371 // Use of this source code is governed by a BSD-style license
   5372 // that can be found in the COPYING file in the root of the source
   5373 // tree. An additional intellectual property rights grant can be found
   5374 // in the file PATENTS. All contributing project authors may
   5375 // be found in the AUTHORS file in the root of the source tree.
   5376 // -----------------------------------------------------------------------------
   5377 //
   5378 // Boolean decoder
   5379 //
   5380 // Author: Skal (pascal.massimino@gmail.com)
   5381 //         Vikas Arora (vikaas.arora@gmail.com)
   5382 
   5383 // using a table is ~1-2% slower on ARM. Prefer the coded-tree approach then.
   5384 
   5385 var kYModesIntra4 = [18]int8_t{
   5386 	1:  int8(1),
   5387 	2:  int8(-int32(B_TM_PRED)),
   5388 	3:  int8(2),
   5389 	4:  int8(-int32(B_VE_PRED)),
   5390 	5:  int8(3),
   5391 	6:  int8(4),
   5392 	7:  int8(6),
   5393 	8:  int8(-int32(B_HE_PRED)),
   5394 	9:  int8(5),
   5395 	10: int8(-int32(B_RD_PRED)),
   5396 	11: int8(-int32(B_VR_PRED)),
   5397 	12: int8(-int32(B_LD_PRED)),
   5398 	13: int8(7),
   5399 	14: int8(-int32(B_VL_PRED)),
   5400 	15: int8(8),
   5401 	16: int8(-int32(B_HD_PRED)),
   5402 	17: int8(-int32(B_HU_PRED)),
   5403 }
   5404 
   5405 //------------------------------------------------------------------------------
   5406 // Default probabilities
   5407 
   5408 // C documentation
   5409 //
   5410 //	// Paragraph 13.5
   5411 
   5412 var CoeffsProba0 = [4][8][3][11]uint8_t{
   5413 	0: {
   5414 		0: {
   5415 			0: {
   5416 				0:  uint8(128),
   5417 				1:  uint8(128),
   5418 				2:  uint8(128),
   5419 				3:  uint8(128),
   5420 				4:  uint8(128),
   5421 				5:  uint8(128),
   5422 				6:  uint8(128),
   5423 				7:  uint8(128),
   5424 				8:  uint8(128),
   5425 				9:  uint8(128),
   5426 				10: uint8(128),
   5427 			},
   5428 			1: {
   5429 				0:  uint8(128),
   5430 				1:  uint8(128),
   5431 				2:  uint8(128),
   5432 				3:  uint8(128),
   5433 				4:  uint8(128),
   5434 				5:  uint8(128),
   5435 				6:  uint8(128),
   5436 				7:  uint8(128),
   5437 				8:  uint8(128),
   5438 				9:  uint8(128),
   5439 				10: uint8(128),
   5440 			},
   5441 			2: {
   5442 				0:  uint8(128),
   5443 				1:  uint8(128),
   5444 				2:  uint8(128),
   5445 				3:  uint8(128),
   5446 				4:  uint8(128),
   5447 				5:  uint8(128),
   5448 				6:  uint8(128),
   5449 				7:  uint8(128),
   5450 				8:  uint8(128),
   5451 				9:  uint8(128),
   5452 				10: uint8(128),
   5453 			},
   5454 		},
   5455 		1: {
   5456 			0: {
   5457 				0:  uint8(253),
   5458 				1:  uint8(136),
   5459 				2:  uint8(254),
   5460 				3:  uint8(255),
   5461 				4:  uint8(228),
   5462 				5:  uint8(219),
   5463 				6:  uint8(128),
   5464 				7:  uint8(128),
   5465 				8:  uint8(128),
   5466 				9:  uint8(128),
   5467 				10: uint8(128),
   5468 			},
   5469 			1: {
   5470 				0:  uint8(189),
   5471 				1:  uint8(129),
   5472 				2:  uint8(242),
   5473 				3:  uint8(255),
   5474 				4:  uint8(227),
   5475 				5:  uint8(213),
   5476 				6:  uint8(255),
   5477 				7:  uint8(219),
   5478 				8:  uint8(128),
   5479 				9:  uint8(128),
   5480 				10: uint8(128),
   5481 			},
   5482 			2: {
   5483 				0:  uint8(106),
   5484 				1:  uint8(126),
   5485 				2:  uint8(227),
   5486 				3:  uint8(252),
   5487 				4:  uint8(214),
   5488 				5:  uint8(209),
   5489 				6:  uint8(255),
   5490 				7:  uint8(255),
   5491 				8:  uint8(128),
   5492 				9:  uint8(128),
   5493 				10: uint8(128),
   5494 			},
   5495 		},
   5496 		2: {
   5497 			0: {
   5498 				0:  uint8(1),
   5499 				1:  uint8(98),
   5500 				2:  uint8(248),
   5501 				3:  uint8(255),
   5502 				4:  uint8(236),
   5503 				5:  uint8(226),
   5504 				6:  uint8(255),
   5505 				7:  uint8(255),
   5506 				8:  uint8(128),
   5507 				9:  uint8(128),
   5508 				10: uint8(128),
   5509 			},
   5510 			1: {
   5511 				0:  uint8(181),
   5512 				1:  uint8(133),
   5513 				2:  uint8(238),
   5514 				3:  uint8(254),
   5515 				4:  uint8(221),
   5516 				5:  uint8(234),
   5517 				6:  uint8(255),
   5518 				7:  uint8(154),
   5519 				8:  uint8(128),
   5520 				9:  uint8(128),
   5521 				10: uint8(128),
   5522 			},
   5523 			2: {
   5524 				0:  uint8(78),
   5525 				1:  uint8(134),
   5526 				2:  uint8(202),
   5527 				3:  uint8(247),
   5528 				4:  uint8(198),
   5529 				5:  uint8(180),
   5530 				6:  uint8(255),
   5531 				7:  uint8(219),
   5532 				8:  uint8(128),
   5533 				9:  uint8(128),
   5534 				10: uint8(128),
   5535 			},
   5536 		},
   5537 		3: {
   5538 			0: {
   5539 				0:  uint8(1),
   5540 				1:  uint8(185),
   5541 				2:  uint8(249),
   5542 				3:  uint8(255),
   5543 				4:  uint8(243),
   5544 				5:  uint8(255),
   5545 				6:  uint8(128),
   5546 				7:  uint8(128),
   5547 				8:  uint8(128),
   5548 				9:  uint8(128),
   5549 				10: uint8(128),
   5550 			},
   5551 			1: {
   5552 				0:  uint8(184),
   5553 				1:  uint8(150),
   5554 				2:  uint8(247),
   5555 				3:  uint8(255),
   5556 				4:  uint8(236),
   5557 				5:  uint8(224),
   5558 				6:  uint8(128),
   5559 				7:  uint8(128),
   5560 				8:  uint8(128),
   5561 				9:  uint8(128),
   5562 				10: uint8(128),
   5563 			},
   5564 			2: {
   5565 				0:  uint8(77),
   5566 				1:  uint8(110),
   5567 				2:  uint8(216),
   5568 				3:  uint8(255),
   5569 				4:  uint8(236),
   5570 				5:  uint8(230),
   5571 				6:  uint8(128),
   5572 				7:  uint8(128),
   5573 				8:  uint8(128),
   5574 				9:  uint8(128),
   5575 				10: uint8(128),
   5576 			},
   5577 		},
   5578 		4: {
   5579 			0: {
   5580 				0:  uint8(1),
   5581 				1:  uint8(101),
   5582 				2:  uint8(251),
   5583 				3:  uint8(255),
   5584 				4:  uint8(241),
   5585 				5:  uint8(255),
   5586 				6:  uint8(128),
   5587 				7:  uint8(128),
   5588 				8:  uint8(128),
   5589 				9:  uint8(128),
   5590 				10: uint8(128),
   5591 			},
   5592 			1: {
   5593 				0:  uint8(170),
   5594 				1:  uint8(139),
   5595 				2:  uint8(241),
   5596 				3:  uint8(252),
   5597 				4:  uint8(236),
   5598 				5:  uint8(209),
   5599 				6:  uint8(255),
   5600 				7:  uint8(255),
   5601 				8:  uint8(128),
   5602 				9:  uint8(128),
   5603 				10: uint8(128),
   5604 			},
   5605 			2: {
   5606 				0:  uint8(37),
   5607 				1:  uint8(116),
   5608 				2:  uint8(196),
   5609 				3:  uint8(243),
   5610 				4:  uint8(228),
   5611 				5:  uint8(255),
   5612 				6:  uint8(255),
   5613 				7:  uint8(255),
   5614 				8:  uint8(128),
   5615 				9:  uint8(128),
   5616 				10: uint8(128),
   5617 			},
   5618 		},
   5619 		5: {
   5620 			0: {
   5621 				0:  uint8(1),
   5622 				1:  uint8(204),
   5623 				2:  uint8(254),
   5624 				3:  uint8(255),
   5625 				4:  uint8(245),
   5626 				5:  uint8(255),
   5627 				6:  uint8(128),
   5628 				7:  uint8(128),
   5629 				8:  uint8(128),
   5630 				9:  uint8(128),
   5631 				10: uint8(128),
   5632 			},
   5633 			1: {
   5634 				0:  uint8(207),
   5635 				1:  uint8(160),
   5636 				2:  uint8(250),
   5637 				3:  uint8(255),
   5638 				4:  uint8(238),
   5639 				5:  uint8(128),
   5640 				6:  uint8(128),
   5641 				7:  uint8(128),
   5642 				8:  uint8(128),
   5643 				9:  uint8(128),
   5644 				10: uint8(128),
   5645 			},
   5646 			2: {
   5647 				0:  uint8(102),
   5648 				1:  uint8(103),
   5649 				2:  uint8(231),
   5650 				3:  uint8(255),
   5651 				4:  uint8(211),
   5652 				5:  uint8(171),
   5653 				6:  uint8(128),
   5654 				7:  uint8(128),
   5655 				8:  uint8(128),
   5656 				9:  uint8(128),
   5657 				10: uint8(128),
   5658 			},
   5659 		},
   5660 		6: {
   5661 			0: {
   5662 				0:  uint8(1),
   5663 				1:  uint8(152),
   5664 				2:  uint8(252),
   5665 				3:  uint8(255),
   5666 				4:  uint8(240),
   5667 				5:  uint8(255),
   5668 				6:  uint8(128),
   5669 				7:  uint8(128),
   5670 				8:  uint8(128),
   5671 				9:  uint8(128),
   5672 				10: uint8(128),
   5673 			},
   5674 			1: {
   5675 				0:  uint8(177),
   5676 				1:  uint8(135),
   5677 				2:  uint8(243),
   5678 				3:  uint8(255),
   5679 				4:  uint8(234),
   5680 				5:  uint8(225),
   5681 				6:  uint8(128),
   5682 				7:  uint8(128),
   5683 				8:  uint8(128),
   5684 				9:  uint8(128),
   5685 				10: uint8(128),
   5686 			},
   5687 			2: {
   5688 				0:  uint8(80),
   5689 				1:  uint8(129),
   5690 				2:  uint8(211),
   5691 				3:  uint8(255),
   5692 				4:  uint8(194),
   5693 				5:  uint8(224),
   5694 				6:  uint8(128),
   5695 				7:  uint8(128),
   5696 				8:  uint8(128),
   5697 				9:  uint8(128),
   5698 				10: uint8(128),
   5699 			},
   5700 		},
   5701 		7: {
   5702 			0: {
   5703 				0:  uint8(1),
   5704 				1:  uint8(1),
   5705 				2:  uint8(255),
   5706 				3:  uint8(128),
   5707 				4:  uint8(128),
   5708 				5:  uint8(128),
   5709 				6:  uint8(128),
   5710 				7:  uint8(128),
   5711 				8:  uint8(128),
   5712 				9:  uint8(128),
   5713 				10: uint8(128),
   5714 			},
   5715 			1: {
   5716 				0:  uint8(246),
   5717 				1:  uint8(1),
   5718 				2:  uint8(255),
   5719 				3:  uint8(128),
   5720 				4:  uint8(128),
   5721 				5:  uint8(128),
   5722 				6:  uint8(128),
   5723 				7:  uint8(128),
   5724 				8:  uint8(128),
   5725 				9:  uint8(128),
   5726 				10: uint8(128),
   5727 			},
   5728 			2: {
   5729 				0:  uint8(255),
   5730 				1:  uint8(128),
   5731 				2:  uint8(128),
   5732 				3:  uint8(128),
   5733 				4:  uint8(128),
   5734 				5:  uint8(128),
   5735 				6:  uint8(128),
   5736 				7:  uint8(128),
   5737 				8:  uint8(128),
   5738 				9:  uint8(128),
   5739 				10: uint8(128),
   5740 			},
   5741 		},
   5742 	},
   5743 	1: {
   5744 		0: {
   5745 			0: {
   5746 				0:  uint8(198),
   5747 				1:  uint8(35),
   5748 				2:  uint8(237),
   5749 				3:  uint8(223),
   5750 				4:  uint8(193),
   5751 				5:  uint8(187),
   5752 				6:  uint8(162),
   5753 				7:  uint8(160),
   5754 				8:  uint8(145),
   5755 				9:  uint8(155),
   5756 				10: uint8(62),
   5757 			},
   5758 			1: {
   5759 				0:  uint8(131),
   5760 				1:  uint8(45),
   5761 				2:  uint8(198),
   5762 				3:  uint8(221),
   5763 				4:  uint8(172),
   5764 				5:  uint8(176),
   5765 				6:  uint8(220),
   5766 				7:  uint8(157),
   5767 				8:  uint8(252),
   5768 				9:  uint8(221),
   5769 				10: uint8(1),
   5770 			},
   5771 			2: {
   5772 				0:  uint8(68),
   5773 				1:  uint8(47),
   5774 				2:  uint8(146),
   5775 				3:  uint8(208),
   5776 				4:  uint8(149),
   5777 				5:  uint8(167),
   5778 				6:  uint8(221),
   5779 				7:  uint8(162),
   5780 				8:  uint8(255),
   5781 				9:  uint8(223),
   5782 				10: uint8(128),
   5783 			},
   5784 		},
   5785 		1: {
   5786 			0: {
   5787 				0:  uint8(1),
   5788 				1:  uint8(149),
   5789 				2:  uint8(241),
   5790 				3:  uint8(255),
   5791 				4:  uint8(221),
   5792 				5:  uint8(224),
   5793 				6:  uint8(255),
   5794 				7:  uint8(255),
   5795 				8:  uint8(128),
   5796 				9:  uint8(128),
   5797 				10: uint8(128),
   5798 			},
   5799 			1: {
   5800 				0:  uint8(184),
   5801 				1:  uint8(141),
   5802 				2:  uint8(234),
   5803 				3:  uint8(253),
   5804 				4:  uint8(222),
   5805 				5:  uint8(220),
   5806 				6:  uint8(255),
   5807 				7:  uint8(199),
   5808 				8:  uint8(128),
   5809 				9:  uint8(128),
   5810 				10: uint8(128),
   5811 			},
   5812 			2: {
   5813 				0:  uint8(81),
   5814 				1:  uint8(99),
   5815 				2:  uint8(181),
   5816 				3:  uint8(242),
   5817 				4:  uint8(176),
   5818 				5:  uint8(190),
   5819 				6:  uint8(249),
   5820 				7:  uint8(202),
   5821 				8:  uint8(255),
   5822 				9:  uint8(255),
   5823 				10: uint8(128),
   5824 			},
   5825 		},
   5826 		2: {
   5827 			0: {
   5828 				0:  uint8(1),
   5829 				1:  uint8(129),
   5830 				2:  uint8(232),
   5831 				3:  uint8(253),
   5832 				4:  uint8(214),
   5833 				5:  uint8(197),
   5834 				6:  uint8(242),
   5835 				7:  uint8(196),
   5836 				8:  uint8(255),
   5837 				9:  uint8(255),
   5838 				10: uint8(128),
   5839 			},
   5840 			1: {
   5841 				0:  uint8(99),
   5842 				1:  uint8(121),
   5843 				2:  uint8(210),
   5844 				3:  uint8(250),
   5845 				4:  uint8(201),
   5846 				5:  uint8(198),
   5847 				6:  uint8(255),
   5848 				7:  uint8(202),
   5849 				8:  uint8(128),
   5850 				9:  uint8(128),
   5851 				10: uint8(128),
   5852 			},
   5853 			2: {
   5854 				0:  uint8(23),
   5855 				1:  uint8(91),
   5856 				2:  uint8(163),
   5857 				3:  uint8(242),
   5858 				4:  uint8(170),
   5859 				5:  uint8(187),
   5860 				6:  uint8(247),
   5861 				7:  uint8(210),
   5862 				8:  uint8(255),
   5863 				9:  uint8(255),
   5864 				10: uint8(128),
   5865 			},
   5866 		},
   5867 		3: {
   5868 			0: {
   5869 				0:  uint8(1),
   5870 				1:  uint8(200),
   5871 				2:  uint8(246),
   5872 				3:  uint8(255),
   5873 				4:  uint8(234),
   5874 				5:  uint8(255),
   5875 				6:  uint8(128),
   5876 				7:  uint8(128),
   5877 				8:  uint8(128),
   5878 				9:  uint8(128),
   5879 				10: uint8(128),
   5880 			},
   5881 			1: {
   5882 				0:  uint8(109),
   5883 				1:  uint8(178),
   5884 				2:  uint8(241),
   5885 				3:  uint8(255),
   5886 				4:  uint8(231),
   5887 				5:  uint8(245),
   5888 				6:  uint8(255),
   5889 				7:  uint8(255),
   5890 				8:  uint8(128),
   5891 				9:  uint8(128),
   5892 				10: uint8(128),
   5893 			},
   5894 			2: {
   5895 				0:  uint8(44),
   5896 				1:  uint8(130),
   5897 				2:  uint8(201),
   5898 				3:  uint8(253),
   5899 				4:  uint8(205),
   5900 				5:  uint8(192),
   5901 				6:  uint8(255),
   5902 				7:  uint8(255),
   5903 				8:  uint8(128),
   5904 				9:  uint8(128),
   5905 				10: uint8(128),
   5906 			},
   5907 		},
   5908 		4: {
   5909 			0: {
   5910 				0:  uint8(1),
   5911 				1:  uint8(132),
   5912 				2:  uint8(239),
   5913 				3:  uint8(251),
   5914 				4:  uint8(219),
   5915 				5:  uint8(209),
   5916 				6:  uint8(255),
   5917 				7:  uint8(165),
   5918 				8:  uint8(128),
   5919 				9:  uint8(128),
   5920 				10: uint8(128),
   5921 			},
   5922 			1: {
   5923 				0:  uint8(94),
   5924 				1:  uint8(136),
   5925 				2:  uint8(225),
   5926 				3:  uint8(251),
   5927 				4:  uint8(218),
   5928 				5:  uint8(190),
   5929 				6:  uint8(255),
   5930 				7:  uint8(255),
   5931 				8:  uint8(128),
   5932 				9:  uint8(128),
   5933 				10: uint8(128),
   5934 			},
   5935 			2: {
   5936 				0:  uint8(22),
   5937 				1:  uint8(100),
   5938 				2:  uint8(174),
   5939 				3:  uint8(245),
   5940 				4:  uint8(186),
   5941 				5:  uint8(161),
   5942 				6:  uint8(255),
   5943 				7:  uint8(199),
   5944 				8:  uint8(128),
   5945 				9:  uint8(128),
   5946 				10: uint8(128),
   5947 			},
   5948 		},
   5949 		5: {
   5950 			0: {
   5951 				0:  uint8(1),
   5952 				1:  uint8(182),
   5953 				2:  uint8(249),
   5954 				3:  uint8(255),
   5955 				4:  uint8(232),
   5956 				5:  uint8(235),
   5957 				6:  uint8(128),
   5958 				7:  uint8(128),
   5959 				8:  uint8(128),
   5960 				9:  uint8(128),
   5961 				10: uint8(128),
   5962 			},
   5963 			1: {
   5964 				0:  uint8(124),
   5965 				1:  uint8(143),
   5966 				2:  uint8(241),
   5967 				3:  uint8(255),
   5968 				4:  uint8(227),
   5969 				5:  uint8(234),
   5970 				6:  uint8(128),
   5971 				7:  uint8(128),
   5972 				8:  uint8(128),
   5973 				9:  uint8(128),
   5974 				10: uint8(128),
   5975 			},
   5976 			2: {
   5977 				0:  uint8(35),
   5978 				1:  uint8(77),
   5979 				2:  uint8(181),
   5980 				3:  uint8(251),
   5981 				4:  uint8(193),
   5982 				5:  uint8(211),
   5983 				6:  uint8(255),
   5984 				7:  uint8(205),
   5985 				8:  uint8(128),
   5986 				9:  uint8(128),
   5987 				10: uint8(128),
   5988 			},
   5989 		},
   5990 		6: {
   5991 			0: {
   5992 				0:  uint8(1),
   5993 				1:  uint8(157),
   5994 				2:  uint8(247),
   5995 				3:  uint8(255),
   5996 				4:  uint8(236),
   5997 				5:  uint8(231),
   5998 				6:  uint8(255),
   5999 				7:  uint8(255),
   6000 				8:  uint8(128),
   6001 				9:  uint8(128),
   6002 				10: uint8(128),
   6003 			},
   6004 			1: {
   6005 				0:  uint8(121),
   6006 				1:  uint8(141),
   6007 				2:  uint8(235),
   6008 				3:  uint8(255),
   6009 				4:  uint8(225),
   6010 				5:  uint8(227),
   6011 				6:  uint8(255),
   6012 				7:  uint8(255),
   6013 				8:  uint8(128),
   6014 				9:  uint8(128),
   6015 				10: uint8(128),
   6016 			},
   6017 			2: {
   6018 				0:  uint8(45),
   6019 				1:  uint8(99),
   6020 				2:  uint8(188),
   6021 				3:  uint8(251),
   6022 				4:  uint8(195),
   6023 				5:  uint8(217),
   6024 				6:  uint8(255),
   6025 				7:  uint8(224),
   6026 				8:  uint8(128),
   6027 				9:  uint8(128),
   6028 				10: uint8(128),
   6029 			},
   6030 		},
   6031 		7: {
   6032 			0: {
   6033 				0:  uint8(1),
   6034 				1:  uint8(1),
   6035 				2:  uint8(251),
   6036 				3:  uint8(255),
   6037 				4:  uint8(213),
   6038 				5:  uint8(255),
   6039 				6:  uint8(128),
   6040 				7:  uint8(128),
   6041 				8:  uint8(128),
   6042 				9:  uint8(128),
   6043 				10: uint8(128),
   6044 			},
   6045 			1: {
   6046 				0:  uint8(203),
   6047 				1:  uint8(1),
   6048 				2:  uint8(248),
   6049 				3:  uint8(255),
   6050 				4:  uint8(255),
   6051 				5:  uint8(128),
   6052 				6:  uint8(128),
   6053 				7:  uint8(128),
   6054 				8:  uint8(128),
   6055 				9:  uint8(128),
   6056 				10: uint8(128),
   6057 			},
   6058 			2: {
   6059 				0:  uint8(137),
   6060 				1:  uint8(1),
   6061 				2:  uint8(177),
   6062 				3:  uint8(255),
   6063 				4:  uint8(224),
   6064 				5:  uint8(255),
   6065 				6:  uint8(128),
   6066 				7:  uint8(128),
   6067 				8:  uint8(128),
   6068 				9:  uint8(128),
   6069 				10: uint8(128),
   6070 			},
   6071 		},
   6072 	},
   6073 	2: {
   6074 		0: {
   6075 			0: {
   6076 				0:  uint8(253),
   6077 				1:  uint8(9),
   6078 				2:  uint8(248),
   6079 				3:  uint8(251),
   6080 				4:  uint8(207),
   6081 				5:  uint8(208),
   6082 				6:  uint8(255),
   6083 				7:  uint8(192),
   6084 				8:  uint8(128),
   6085 				9:  uint8(128),
   6086 				10: uint8(128),
   6087 			},
   6088 			1: {
   6089 				0:  uint8(175),
   6090 				1:  uint8(13),
   6091 				2:  uint8(224),
   6092 				3:  uint8(243),
   6093 				4:  uint8(193),
   6094 				5:  uint8(185),
   6095 				6:  uint8(249),
   6096 				7:  uint8(198),
   6097 				8:  uint8(255),
   6098 				9:  uint8(255),
   6099 				10: uint8(128),
   6100 			},
   6101 			2: {
   6102 				0:  uint8(73),
   6103 				1:  uint8(17),
   6104 				2:  uint8(171),
   6105 				3:  uint8(221),
   6106 				4:  uint8(161),
   6107 				5:  uint8(179),
   6108 				6:  uint8(236),
   6109 				7:  uint8(167),
   6110 				8:  uint8(255),
   6111 				9:  uint8(234),
   6112 				10: uint8(128),
   6113 			},
   6114 		},
   6115 		1: {
   6116 			0: {
   6117 				0:  uint8(1),
   6118 				1:  uint8(95),
   6119 				2:  uint8(247),
   6120 				3:  uint8(253),
   6121 				4:  uint8(212),
   6122 				5:  uint8(183),
   6123 				6:  uint8(255),
   6124 				7:  uint8(255),
   6125 				8:  uint8(128),
   6126 				9:  uint8(128),
   6127 				10: uint8(128),
   6128 			},
   6129 			1: {
   6130 				0:  uint8(239),
   6131 				1:  uint8(90),
   6132 				2:  uint8(244),
   6133 				3:  uint8(250),
   6134 				4:  uint8(211),
   6135 				5:  uint8(209),
   6136 				6:  uint8(255),
   6137 				7:  uint8(255),
   6138 				8:  uint8(128),
   6139 				9:  uint8(128),
   6140 				10: uint8(128),
   6141 			},
   6142 			2: {
   6143 				0:  uint8(155),
   6144 				1:  uint8(77),
   6145 				2:  uint8(195),
   6146 				3:  uint8(248),
   6147 				4:  uint8(188),
   6148 				5:  uint8(195),
   6149 				6:  uint8(255),
   6150 				7:  uint8(255),
   6151 				8:  uint8(128),
   6152 				9:  uint8(128),
   6153 				10: uint8(128),
   6154 			},
   6155 		},
   6156 		2: {
   6157 			0: {
   6158 				0:  uint8(1),
   6159 				1:  uint8(24),
   6160 				2:  uint8(239),
   6161 				3:  uint8(251),
   6162 				4:  uint8(218),
   6163 				5:  uint8(219),
   6164 				6:  uint8(255),
   6165 				7:  uint8(205),
   6166 				8:  uint8(128),
   6167 				9:  uint8(128),
   6168 				10: uint8(128),
   6169 			},
   6170 			1: {
   6171 				0:  uint8(201),
   6172 				1:  uint8(51),
   6173 				2:  uint8(219),
   6174 				3:  uint8(255),
   6175 				4:  uint8(196),
   6176 				5:  uint8(186),
   6177 				6:  uint8(128),
   6178 				7:  uint8(128),
   6179 				8:  uint8(128),
   6180 				9:  uint8(128),
   6181 				10: uint8(128),
   6182 			},
   6183 			2: {
   6184 				0:  uint8(69),
   6185 				1:  uint8(46),
   6186 				2:  uint8(190),
   6187 				3:  uint8(239),
   6188 				4:  uint8(201),
   6189 				5:  uint8(218),
   6190 				6:  uint8(255),
   6191 				7:  uint8(228),
   6192 				8:  uint8(128),
   6193 				9:  uint8(128),
   6194 				10: uint8(128),
   6195 			},
   6196 		},
   6197 		3: {
   6198 			0: {
   6199 				0:  uint8(1),
   6200 				1:  uint8(191),
   6201 				2:  uint8(251),
   6202 				3:  uint8(255),
   6203 				4:  uint8(255),
   6204 				5:  uint8(128),
   6205 				6:  uint8(128),
   6206 				7:  uint8(128),
   6207 				8:  uint8(128),
   6208 				9:  uint8(128),
   6209 				10: uint8(128),
   6210 			},
   6211 			1: {
   6212 				0:  uint8(223),
   6213 				1:  uint8(165),
   6214 				2:  uint8(249),
   6215 				3:  uint8(255),
   6216 				4:  uint8(213),
   6217 				5:  uint8(255),
   6218 				6:  uint8(128),
   6219 				7:  uint8(128),
   6220 				8:  uint8(128),
   6221 				9:  uint8(128),
   6222 				10: uint8(128),
   6223 			},
   6224 			2: {
   6225 				0:  uint8(141),
   6226 				1:  uint8(124),
   6227 				2:  uint8(248),
   6228 				3:  uint8(255),
   6229 				4:  uint8(255),
   6230 				5:  uint8(128),
   6231 				6:  uint8(128),
   6232 				7:  uint8(128),
   6233 				8:  uint8(128),
   6234 				9:  uint8(128),
   6235 				10: uint8(128),
   6236 			},
   6237 		},
   6238 		4: {
   6239 			0: {
   6240 				0:  uint8(1),
   6241 				1:  uint8(16),
   6242 				2:  uint8(248),
   6243 				3:  uint8(255),
   6244 				4:  uint8(255),
   6245 				5:  uint8(128),
   6246 				6:  uint8(128),
   6247 				7:  uint8(128),
   6248 				8:  uint8(128),
   6249 				9:  uint8(128),
   6250 				10: uint8(128),
   6251 			},
   6252 			1: {
   6253 				0:  uint8(190),
   6254 				1:  uint8(36),
   6255 				2:  uint8(230),
   6256 				3:  uint8(255),
   6257 				4:  uint8(236),
   6258 				5:  uint8(255),
   6259 				6:  uint8(128),
   6260 				7:  uint8(128),
   6261 				8:  uint8(128),
   6262 				9:  uint8(128),
   6263 				10: uint8(128),
   6264 			},
   6265 			2: {
   6266 				0:  uint8(149),
   6267 				1:  uint8(1),
   6268 				2:  uint8(255),
   6269 				3:  uint8(128),
   6270 				4:  uint8(128),
   6271 				5:  uint8(128),
   6272 				6:  uint8(128),
   6273 				7:  uint8(128),
   6274 				8:  uint8(128),
   6275 				9:  uint8(128),
   6276 				10: uint8(128),
   6277 			},
   6278 		},
   6279 		5: {
   6280 			0: {
   6281 				0:  uint8(1),
   6282 				1:  uint8(226),
   6283 				2:  uint8(255),
   6284 				3:  uint8(128),
   6285 				4:  uint8(128),
   6286 				5:  uint8(128),
   6287 				6:  uint8(128),
   6288 				7:  uint8(128),
   6289 				8:  uint8(128),
   6290 				9:  uint8(128),
   6291 				10: uint8(128),
   6292 			},
   6293 			1: {
   6294 				0:  uint8(247),
   6295 				1:  uint8(192),
   6296 				2:  uint8(255),
   6297 				3:  uint8(128),
   6298 				4:  uint8(128),
   6299 				5:  uint8(128),
   6300 				6:  uint8(128),
   6301 				7:  uint8(128),
   6302 				8:  uint8(128),
   6303 				9:  uint8(128),
   6304 				10: uint8(128),
   6305 			},
   6306 			2: {
   6307 				0:  uint8(240),
   6308 				1:  uint8(128),
   6309 				2:  uint8(255),
   6310 				3:  uint8(128),
   6311 				4:  uint8(128),
   6312 				5:  uint8(128),
   6313 				6:  uint8(128),
   6314 				7:  uint8(128),
   6315 				8:  uint8(128),
   6316 				9:  uint8(128),
   6317 				10: uint8(128),
   6318 			},
   6319 		},
   6320 		6: {
   6321 			0: {
   6322 				0:  uint8(1),
   6323 				1:  uint8(134),
   6324 				2:  uint8(252),
   6325 				3:  uint8(255),
   6326 				4:  uint8(255),
   6327 				5:  uint8(128),
   6328 				6:  uint8(128),
   6329 				7:  uint8(128),
   6330 				8:  uint8(128),
   6331 				9:  uint8(128),
   6332 				10: uint8(128),
   6333 			},
   6334 			1: {
   6335 				0:  uint8(213),
   6336 				1:  uint8(62),
   6337 				2:  uint8(250),
   6338 				3:  uint8(255),
   6339 				4:  uint8(255),
   6340 				5:  uint8(128),
   6341 				6:  uint8(128),
   6342 				7:  uint8(128),
   6343 				8:  uint8(128),
   6344 				9:  uint8(128),
   6345 				10: uint8(128),
   6346 			},
   6347 			2: {
   6348 				0:  uint8(55),
   6349 				1:  uint8(93),
   6350 				2:  uint8(255),
   6351 				3:  uint8(128),
   6352 				4:  uint8(128),
   6353 				5:  uint8(128),
   6354 				6:  uint8(128),
   6355 				7:  uint8(128),
   6356 				8:  uint8(128),
   6357 				9:  uint8(128),
   6358 				10: uint8(128),
   6359 			},
   6360 		},
   6361 		7: {
   6362 			0: {
   6363 				0:  uint8(128),
   6364 				1:  uint8(128),
   6365 				2:  uint8(128),
   6366 				3:  uint8(128),
   6367 				4:  uint8(128),
   6368 				5:  uint8(128),
   6369 				6:  uint8(128),
   6370 				7:  uint8(128),
   6371 				8:  uint8(128),
   6372 				9:  uint8(128),
   6373 				10: uint8(128),
   6374 			},
   6375 			1: {
   6376 				0:  uint8(128),
   6377 				1:  uint8(128),
   6378 				2:  uint8(128),
   6379 				3:  uint8(128),
   6380 				4:  uint8(128),
   6381 				5:  uint8(128),
   6382 				6:  uint8(128),
   6383 				7:  uint8(128),
   6384 				8:  uint8(128),
   6385 				9:  uint8(128),
   6386 				10: uint8(128),
   6387 			},
   6388 			2: {
   6389 				0:  uint8(128),
   6390 				1:  uint8(128),
   6391 				2:  uint8(128),
   6392 				3:  uint8(128),
   6393 				4:  uint8(128),
   6394 				5:  uint8(128),
   6395 				6:  uint8(128),
   6396 				7:  uint8(128),
   6397 				8:  uint8(128),
   6398 				9:  uint8(128),
   6399 				10: uint8(128),
   6400 			},
   6401 		},
   6402 	},
   6403 	3: {
   6404 		0: {
   6405 			0: {
   6406 				0:  uint8(202),
   6407 				1:  uint8(24),
   6408 				2:  uint8(213),
   6409 				3:  uint8(235),
   6410 				4:  uint8(186),
   6411 				5:  uint8(191),
   6412 				6:  uint8(220),
   6413 				7:  uint8(160),
   6414 				8:  uint8(240),
   6415 				9:  uint8(175),
   6416 				10: uint8(255),
   6417 			},
   6418 			1: {
   6419 				0:  uint8(126),
   6420 				1:  uint8(38),
   6421 				2:  uint8(182),
   6422 				3:  uint8(232),
   6423 				4:  uint8(169),
   6424 				5:  uint8(184),
   6425 				6:  uint8(228),
   6426 				7:  uint8(174),
   6427 				8:  uint8(255),
   6428 				9:  uint8(187),
   6429 				10: uint8(128),
   6430 			},
   6431 			2: {
   6432 				0:  uint8(61),
   6433 				1:  uint8(46),
   6434 				2:  uint8(138),
   6435 				3:  uint8(219),
   6436 				4:  uint8(151),
   6437 				5:  uint8(178),
   6438 				6:  uint8(240),
   6439 				7:  uint8(170),
   6440 				8:  uint8(255),
   6441 				9:  uint8(216),
   6442 				10: uint8(128),
   6443 			},
   6444 		},
   6445 		1: {
   6446 			0: {
   6447 				0:  uint8(1),
   6448 				1:  uint8(112),
   6449 				2:  uint8(230),
   6450 				3:  uint8(250),
   6451 				4:  uint8(199),
   6452 				5:  uint8(191),
   6453 				6:  uint8(247),
   6454 				7:  uint8(159),
   6455 				8:  uint8(255),
   6456 				9:  uint8(255),
   6457 				10: uint8(128),
   6458 			},
   6459 			1: {
   6460 				0:  uint8(166),
   6461 				1:  uint8(109),
   6462 				2:  uint8(228),
   6463 				3:  uint8(252),
   6464 				4:  uint8(211),
   6465 				5:  uint8(215),
   6466 				6:  uint8(255),
   6467 				7:  uint8(174),
   6468 				8:  uint8(128),
   6469 				9:  uint8(128),
   6470 				10: uint8(128),
   6471 			},
   6472 			2: {
   6473 				0:  uint8(39),
   6474 				1:  uint8(77),
   6475 				2:  uint8(162),
   6476 				3:  uint8(232),
   6477 				4:  uint8(172),
   6478 				5:  uint8(180),
   6479 				6:  uint8(245),
   6480 				7:  uint8(178),
   6481 				8:  uint8(255),
   6482 				9:  uint8(255),
   6483 				10: uint8(128),
   6484 			},
   6485 		},
   6486 		2: {
   6487 			0: {
   6488 				0:  uint8(1),
   6489 				1:  uint8(52),
   6490 				2:  uint8(220),
   6491 				3:  uint8(246),
   6492 				4:  uint8(198),
   6493 				5:  uint8(199),
   6494 				6:  uint8(249),
   6495 				7:  uint8(220),
   6496 				8:  uint8(255),
   6497 				9:  uint8(255),
   6498 				10: uint8(128),
   6499 			},
   6500 			1: {
   6501 				0:  uint8(124),
   6502 				1:  uint8(74),
   6503 				2:  uint8(191),
   6504 				3:  uint8(243),
   6505 				4:  uint8(183),
   6506 				5:  uint8(193),
   6507 				6:  uint8(250),
   6508 				7:  uint8(221),
   6509 				8:  uint8(255),
   6510 				9:  uint8(255),
   6511 				10: uint8(128),
   6512 			},
   6513 			2: {
   6514 				0:  uint8(24),
   6515 				1:  uint8(71),
   6516 				2:  uint8(130),
   6517 				3:  uint8(219),
   6518 				4:  uint8(154),
   6519 				5:  uint8(170),
   6520 				6:  uint8(243),
   6521 				7:  uint8(182),
   6522 				8:  uint8(255),
   6523 				9:  uint8(255),
   6524 				10: uint8(128),
   6525 			},
   6526 		},
   6527 		3: {
   6528 			0: {
   6529 				0:  uint8(1),
   6530 				1:  uint8(182),
   6531 				2:  uint8(225),
   6532 				3:  uint8(249),
   6533 				4:  uint8(219),
   6534 				5:  uint8(240),
   6535 				6:  uint8(255),
   6536 				7:  uint8(224),
   6537 				8:  uint8(128),
   6538 				9:  uint8(128),
   6539 				10: uint8(128),
   6540 			},
   6541 			1: {
   6542 				0:  uint8(149),
   6543 				1:  uint8(150),
   6544 				2:  uint8(226),
   6545 				3:  uint8(252),
   6546 				4:  uint8(216),
   6547 				5:  uint8(205),
   6548 				6:  uint8(255),
   6549 				7:  uint8(171),
   6550 				8:  uint8(128),
   6551 				9:  uint8(128),
   6552 				10: uint8(128),
   6553 			},
   6554 			2: {
   6555 				0:  uint8(28),
   6556 				1:  uint8(108),
   6557 				2:  uint8(170),
   6558 				3:  uint8(242),
   6559 				4:  uint8(183),
   6560 				5:  uint8(194),
   6561 				6:  uint8(254),
   6562 				7:  uint8(223),
   6563 				8:  uint8(255),
   6564 				9:  uint8(255),
   6565 				10: uint8(128),
   6566 			},
   6567 		},
   6568 		4: {
   6569 			0: {
   6570 				0:  uint8(1),
   6571 				1:  uint8(81),
   6572 				2:  uint8(230),
   6573 				3:  uint8(252),
   6574 				4:  uint8(204),
   6575 				5:  uint8(203),
   6576 				6:  uint8(255),
   6577 				7:  uint8(192),
   6578 				8:  uint8(128),
   6579 				9:  uint8(128),
   6580 				10: uint8(128),
   6581 			},
   6582 			1: {
   6583 				0:  uint8(123),
   6584 				1:  uint8(102),
   6585 				2:  uint8(209),
   6586 				3:  uint8(247),
   6587 				4:  uint8(188),
   6588 				5:  uint8(196),
   6589 				6:  uint8(255),
   6590 				7:  uint8(233),
   6591 				8:  uint8(128),
   6592 				9:  uint8(128),
   6593 				10: uint8(128),
   6594 			},
   6595 			2: {
   6596 				0:  uint8(20),
   6597 				1:  uint8(95),
   6598 				2:  uint8(153),
   6599 				3:  uint8(243),
   6600 				4:  uint8(164),
   6601 				5:  uint8(173),
   6602 				6:  uint8(255),
   6603 				7:  uint8(203),
   6604 				8:  uint8(128),
   6605 				9:  uint8(128),
   6606 				10: uint8(128),
   6607 			},
   6608 		},
   6609 		5: {
   6610 			0: {
   6611 				0:  uint8(1),
   6612 				1:  uint8(222),
   6613 				2:  uint8(248),
   6614 				3:  uint8(255),
   6615 				4:  uint8(216),
   6616 				5:  uint8(213),
   6617 				6:  uint8(128),
   6618 				7:  uint8(128),
   6619 				8:  uint8(128),
   6620 				9:  uint8(128),
   6621 				10: uint8(128),
   6622 			},
   6623 			1: {
   6624 				0:  uint8(168),
   6625 				1:  uint8(175),
   6626 				2:  uint8(246),
   6627 				3:  uint8(252),
   6628 				4:  uint8(235),
   6629 				5:  uint8(205),
   6630 				6:  uint8(255),
   6631 				7:  uint8(255),
   6632 				8:  uint8(128),
   6633 				9:  uint8(128),
   6634 				10: uint8(128),
   6635 			},
   6636 			2: {
   6637 				0:  uint8(47),
   6638 				1:  uint8(116),
   6639 				2:  uint8(215),
   6640 				3:  uint8(255),
   6641 				4:  uint8(211),
   6642 				5:  uint8(212),
   6643 				6:  uint8(255),
   6644 				7:  uint8(255),
   6645 				8:  uint8(128),
   6646 				9:  uint8(128),
   6647 				10: uint8(128),
   6648 			},
   6649 		},
   6650 		6: {
   6651 			0: {
   6652 				0:  uint8(1),
   6653 				1:  uint8(121),
   6654 				2:  uint8(236),
   6655 				3:  uint8(253),
   6656 				4:  uint8(212),
   6657 				5:  uint8(214),
   6658 				6:  uint8(255),
   6659 				7:  uint8(255),
   6660 				8:  uint8(128),
   6661 				9:  uint8(128),
   6662 				10: uint8(128),
   6663 			},
   6664 			1: {
   6665 				0:  uint8(141),
   6666 				1:  uint8(84),
   6667 				2:  uint8(213),
   6668 				3:  uint8(252),
   6669 				4:  uint8(201),
   6670 				5:  uint8(202),
   6671 				6:  uint8(255),
   6672 				7:  uint8(219),
   6673 				8:  uint8(128),
   6674 				9:  uint8(128),
   6675 				10: uint8(128),
   6676 			},
   6677 			2: {
   6678 				0:  uint8(42),
   6679 				1:  uint8(80),
   6680 				2:  uint8(160),
   6681 				3:  uint8(240),
   6682 				4:  uint8(162),
   6683 				5:  uint8(185),
   6684 				6:  uint8(255),
   6685 				7:  uint8(205),
   6686 				8:  uint8(128),
   6687 				9:  uint8(128),
   6688 				10: uint8(128),
   6689 			},
   6690 		},
   6691 		7: {
   6692 			0: {
   6693 				0:  uint8(1),
   6694 				1:  uint8(1),
   6695 				2:  uint8(255),
   6696 				3:  uint8(128),
   6697 				4:  uint8(128),
   6698 				5:  uint8(128),
   6699 				6:  uint8(128),
   6700 				7:  uint8(128),
   6701 				8:  uint8(128),
   6702 				9:  uint8(128),
   6703 				10: uint8(128),
   6704 			},
   6705 			1: {
   6706 				0:  uint8(244),
   6707 				1:  uint8(1),
   6708 				2:  uint8(255),
   6709 				3:  uint8(128),
   6710 				4:  uint8(128),
   6711 				5:  uint8(128),
   6712 				6:  uint8(128),
   6713 				7:  uint8(128),
   6714 				8:  uint8(128),
   6715 				9:  uint8(128),
   6716 				10: uint8(128),
   6717 			},
   6718 			2: {
   6719 				0:  uint8(238),
   6720 				1:  uint8(1),
   6721 				2:  uint8(255),
   6722 				3:  uint8(128),
   6723 				4:  uint8(128),
   6724 				5:  uint8(128),
   6725 				6:  uint8(128),
   6726 				7:  uint8(128),
   6727 				8:  uint8(128),
   6728 				9:  uint8(128),
   6729 				10: uint8(128),
   6730 			},
   6731 		},
   6732 	},
   6733 }
   6734 
   6735 // C documentation
   6736 //
   6737 //	// Paragraph 11.5
   6738 var kBModesProba = [10][10][9]uint8_t{
   6739 	0: {
   6740 		0: {
   6741 			0: uint8(231),
   6742 			1: uint8(120),
   6743 			2: uint8(48),
   6744 			3: uint8(89),
   6745 			4: uint8(115),
   6746 			5: uint8(113),
   6747 			6: uint8(120),
   6748 			7: uint8(152),
   6749 			8: uint8(112),
   6750 		},
   6751 		1: {
   6752 			0: uint8(152),
   6753 			1: uint8(179),
   6754 			2: uint8(64),
   6755 			3: uint8(126),
   6756 			4: uint8(170),
   6757 			5: uint8(118),
   6758 			6: uint8(46),
   6759 			7: uint8(70),
   6760 			8: uint8(95),
   6761 		},
   6762 		2: {
   6763 			0: uint8(175),
   6764 			1: uint8(69),
   6765 			2: uint8(143),
   6766 			3: uint8(80),
   6767 			4: uint8(85),
   6768 			5: uint8(82),
   6769 			6: uint8(72),
   6770 			7: uint8(155),
   6771 			8: uint8(103),
   6772 		},
   6773 		3: {
   6774 			0: uint8(56),
   6775 			1: uint8(58),
   6776 			2: uint8(10),
   6777 			3: uint8(171),
   6778 			4: uint8(218),
   6779 			5: uint8(189),
   6780 			6: uint8(17),
   6781 			7: uint8(13),
   6782 			8: uint8(152),
   6783 		},
   6784 		4: {
   6785 			0: uint8(114),
   6786 			1: uint8(26),
   6787 			2: uint8(17),
   6788 			3: uint8(163),
   6789 			4: uint8(44),
   6790 			5: uint8(195),
   6791 			6: uint8(21),
   6792 			7: uint8(10),
   6793 			8: uint8(173),
   6794 		},
   6795 		5: {
   6796 			0: uint8(121),
   6797 			1: uint8(24),
   6798 			2: uint8(80),
   6799 			3: uint8(195),
   6800 			4: uint8(26),
   6801 			5: uint8(62),
   6802 			6: uint8(44),
   6803 			7: uint8(64),
   6804 			8: uint8(85),
   6805 		},
   6806 		6: {
   6807 			0: uint8(144),
   6808 			1: uint8(71),
   6809 			2: uint8(10),
   6810 			3: uint8(38),
   6811 			4: uint8(171),
   6812 			5: uint8(213),
   6813 			6: uint8(144),
   6814 			7: uint8(34),
   6815 			8: uint8(26),
   6816 		},
   6817 		7: {
   6818 			0: uint8(170),
   6819 			1: uint8(46),
   6820 			2: uint8(55),
   6821 			3: uint8(19),
   6822 			4: uint8(136),
   6823 			5: uint8(160),
   6824 			6: uint8(33),
   6825 			7: uint8(206),
   6826 			8: uint8(71),
   6827 		},
   6828 		8: {
   6829 			0: uint8(63),
   6830 			1: uint8(20),
   6831 			2: uint8(8),
   6832 			3: uint8(114),
   6833 			4: uint8(114),
   6834 			5: uint8(208),
   6835 			6: uint8(12),
   6836 			7: uint8(9),
   6837 			8: uint8(226),
   6838 		},
   6839 		9: {
   6840 			0: uint8(81),
   6841 			1: uint8(40),
   6842 			2: uint8(11),
   6843 			3: uint8(96),
   6844 			4: uint8(182),
   6845 			5: uint8(84),
   6846 			6: uint8(29),
   6847 			7: uint8(16),
   6848 			8: uint8(36),
   6849 		},
   6850 	},
   6851 	1: {
   6852 		0: {
   6853 			0: uint8(134),
   6854 			1: uint8(183),
   6855 			2: uint8(89),
   6856 			3: uint8(137),
   6857 			4: uint8(98),
   6858 			5: uint8(101),
   6859 			6: uint8(106),
   6860 			7: uint8(165),
   6861 			8: uint8(148),
   6862 		},
   6863 		1: {
   6864 			0: uint8(72),
   6865 			1: uint8(187),
   6866 			2: uint8(100),
   6867 			3: uint8(130),
   6868 			4: uint8(157),
   6869 			5: uint8(111),
   6870 			6: uint8(32),
   6871 			7: uint8(75),
   6872 			8: uint8(80),
   6873 		},
   6874 		2: {
   6875 			0: uint8(66),
   6876 			1: uint8(102),
   6877 			2: uint8(167),
   6878 			3: uint8(99),
   6879 			4: uint8(74),
   6880 			5: uint8(62),
   6881 			6: uint8(40),
   6882 			7: uint8(234),
   6883 			8: uint8(128),
   6884 		},
   6885 		3: {
   6886 			0: uint8(41),
   6887 			1: uint8(53),
   6888 			2: uint8(9),
   6889 			3: uint8(178),
   6890 			4: uint8(241),
   6891 			5: uint8(141),
   6892 			6: uint8(26),
   6893 			7: uint8(8),
   6894 			8: uint8(107),
   6895 		},
   6896 		4: {
   6897 			0: uint8(74),
   6898 			1: uint8(43),
   6899 			2: uint8(26),
   6900 			3: uint8(146),
   6901 			4: uint8(73),
   6902 			5: uint8(166),
   6903 			6: uint8(49),
   6904 			7: uint8(23),
   6905 			8: uint8(157),
   6906 		},
   6907 		5: {
   6908 			0: uint8(65),
   6909 			1: uint8(38),
   6910 			2: uint8(105),
   6911 			3: uint8(160),
   6912 			4: uint8(51),
   6913 			5: uint8(52),
   6914 			6: uint8(31),
   6915 			7: uint8(115),
   6916 			8: uint8(128),
   6917 		},
   6918 		6: {
   6919 			0: uint8(104),
   6920 			1: uint8(79),
   6921 			2: uint8(12),
   6922 			3: uint8(27),
   6923 			4: uint8(217),
   6924 			5: uint8(255),
   6925 			6: uint8(87),
   6926 			7: uint8(17),
   6927 			8: uint8(7),
   6928 		},
   6929 		7: {
   6930 			0: uint8(87),
   6931 			1: uint8(68),
   6932 			2: uint8(71),
   6933 			3: uint8(44),
   6934 			4: uint8(114),
   6935 			5: uint8(51),
   6936 			6: uint8(15),
   6937 			7: uint8(186),
   6938 			8: uint8(23),
   6939 		},
   6940 		8: {
   6941 			0: uint8(47),
   6942 			1: uint8(41),
   6943 			2: uint8(14),
   6944 			3: uint8(110),
   6945 			4: uint8(182),
   6946 			5: uint8(183),
   6947 			6: uint8(21),
   6948 			7: uint8(17),
   6949 			8: uint8(194),
   6950 		},
   6951 		9: {
   6952 			0: uint8(66),
   6953 			1: uint8(45),
   6954 			2: uint8(25),
   6955 			3: uint8(102),
   6956 			4: uint8(197),
   6957 			5: uint8(189),
   6958 			6: uint8(23),
   6959 			7: uint8(18),
   6960 			8: uint8(22),
   6961 		},
   6962 	},
   6963 	2: {
   6964 		0: {
   6965 			0: uint8(88),
   6966 			1: uint8(88),
   6967 			2: uint8(147),
   6968 			3: uint8(150),
   6969 			4: uint8(42),
   6970 			5: uint8(46),
   6971 			6: uint8(45),
   6972 			7: uint8(196),
   6973 			8: uint8(205),
   6974 		},
   6975 		1: {
   6976 			0: uint8(43),
   6977 			1: uint8(97),
   6978 			2: uint8(183),
   6979 			3: uint8(117),
   6980 			4: uint8(85),
   6981 			5: uint8(38),
   6982 			6: uint8(35),
   6983 			7: uint8(179),
   6984 			8: uint8(61),
   6985 		},
   6986 		2: {
   6987 			0: uint8(39),
   6988 			1: uint8(53),
   6989 			2: uint8(200),
   6990 			3: uint8(87),
   6991 			4: uint8(26),
   6992 			5: uint8(21),
   6993 			6: uint8(43),
   6994 			7: uint8(232),
   6995 			8: uint8(171),
   6996 		},
   6997 		3: {
   6998 			0: uint8(56),
   6999 			1: uint8(34),
   7000 			2: uint8(51),
   7001 			3: uint8(104),
   7002 			4: uint8(114),
   7003 			5: uint8(102),
   7004 			6: uint8(29),
   7005 			7: uint8(93),
   7006 			8: uint8(77),
   7007 		},
   7008 		4: {
   7009 			0: uint8(39),
   7010 			1: uint8(28),
   7011 			2: uint8(85),
   7012 			3: uint8(171),
   7013 			4: uint8(58),
   7014 			5: uint8(165),
   7015 			6: uint8(90),
   7016 			7: uint8(98),
   7017 			8: uint8(64),
   7018 		},
   7019 		5: {
   7020 			0: uint8(34),
   7021 			1: uint8(22),
   7022 			2: uint8(116),
   7023 			3: uint8(206),
   7024 			4: uint8(23),
   7025 			5: uint8(34),
   7026 			6: uint8(43),
   7027 			7: uint8(166),
   7028 			8: uint8(73),
   7029 		},
   7030 		6: {
   7031 			0: uint8(107),
   7032 			1: uint8(54),
   7033 			2: uint8(32),
   7034 			3: uint8(26),
   7035 			4: uint8(51),
   7036 			5: uint8(1),
   7037 			6: uint8(81),
   7038 			7: uint8(43),
   7039 			8: uint8(31),
   7040 		},
   7041 		7: {
   7042 			0: uint8(68),
   7043 			1: uint8(25),
   7044 			2: uint8(106),
   7045 			3: uint8(22),
   7046 			4: uint8(64),
   7047 			5: uint8(171),
   7048 			6: uint8(36),
   7049 			7: uint8(225),
   7050 			8: uint8(114),
   7051 		},
   7052 		8: {
   7053 			0: uint8(34),
   7054 			1: uint8(19),
   7055 			2: uint8(21),
   7056 			3: uint8(102),
   7057 			4: uint8(132),
   7058 			5: uint8(188),
   7059 			6: uint8(16),
   7060 			7: uint8(76),
   7061 			8: uint8(124),
   7062 		},
   7063 		9: {
   7064 			0: uint8(62),
   7065 			1: uint8(18),
   7066 			2: uint8(78),
   7067 			3: uint8(95),
   7068 			4: uint8(85),
   7069 			5: uint8(57),
   7070 			6: uint8(50),
   7071 			7: uint8(48),
   7072 			8: uint8(51),
   7073 		},
   7074 	},
   7075 	3: {
   7076 		0: {
   7077 			0: uint8(193),
   7078 			1: uint8(101),
   7079 			2: uint8(35),
   7080 			3: uint8(159),
   7081 			4: uint8(215),
   7082 			5: uint8(111),
   7083 			6: uint8(89),
   7084 			7: uint8(46),
   7085 			8: uint8(111),
   7086 		},
   7087 		1: {
   7088 			0: uint8(60),
   7089 			1: uint8(148),
   7090 			2: uint8(31),
   7091 			3: uint8(172),
   7092 			4: uint8(219),
   7093 			5: uint8(228),
   7094 			6: uint8(21),
   7095 			7: uint8(18),
   7096 			8: uint8(111),
   7097 		},
   7098 		2: {
   7099 			0: uint8(112),
   7100 			1: uint8(113),
   7101 			2: uint8(77),
   7102 			3: uint8(85),
   7103 			4: uint8(179),
   7104 			5: uint8(255),
   7105 			6: uint8(38),
   7106 			7: uint8(120),
   7107 			8: uint8(114),
   7108 		},
   7109 		3: {
   7110 			0: uint8(40),
   7111 			1: uint8(42),
   7112 			2: uint8(1),
   7113 			3: uint8(196),
   7114 			4: uint8(245),
   7115 			5: uint8(209),
   7116 			6: uint8(10),
   7117 			7: uint8(25),
   7118 			8: uint8(109),
   7119 		},
   7120 		4: {
   7121 			0: uint8(88),
   7122 			1: uint8(43),
   7123 			2: uint8(29),
   7124 			3: uint8(140),
   7125 			4: uint8(166),
   7126 			5: uint8(213),
   7127 			6: uint8(37),
   7128 			7: uint8(43),
   7129 			8: uint8(154),
   7130 		},
   7131 		5: {
   7132 			0: uint8(61),
   7133 			1: uint8(63),
   7134 			2: uint8(30),
   7135 			3: uint8(155),
   7136 			4: uint8(67),
   7137 			5: uint8(45),
   7138 			6: uint8(68),
   7139 			7: uint8(1),
   7140 			8: uint8(209),
   7141 		},
   7142 		6: {
   7143 			0: uint8(100),
   7144 			1: uint8(80),
   7145 			2: uint8(8),
   7146 			3: uint8(43),
   7147 			4: uint8(154),
   7148 			5: uint8(1),
   7149 			6: uint8(51),
   7150 			7: uint8(26),
   7151 			8: uint8(71),
   7152 		},
   7153 		7: {
   7154 			0: uint8(142),
   7155 			1: uint8(78),
   7156 			2: uint8(78),
   7157 			3: uint8(16),
   7158 			4: uint8(255),
   7159 			5: uint8(128),
   7160 			6: uint8(34),
   7161 			7: uint8(197),
   7162 			8: uint8(171),
   7163 		},
   7164 		8: {
   7165 			0: uint8(41),
   7166 			1: uint8(40),
   7167 			2: uint8(5),
   7168 			3: uint8(102),
   7169 			4: uint8(211),
   7170 			5: uint8(183),
   7171 			6: uint8(4),
   7172 			7: uint8(1),
   7173 			8: uint8(221),
   7174 		},
   7175 		9: {
   7176 			0: uint8(51),
   7177 			1: uint8(50),
   7178 			2: uint8(17),
   7179 			3: uint8(168),
   7180 			4: uint8(209),
   7181 			5: uint8(192),
   7182 			6: uint8(23),
   7183 			7: uint8(25),
   7184 			8: uint8(82),
   7185 		},
   7186 	},
   7187 	4: {
   7188 		0: {
   7189 			0: uint8(138),
   7190 			1: uint8(31),
   7191 			2: uint8(36),
   7192 			3: uint8(171),
   7193 			4: uint8(27),
   7194 			5: uint8(166),
   7195 			6: uint8(38),
   7196 			7: uint8(44),
   7197 			8: uint8(229),
   7198 		},
   7199 		1: {
   7200 			0: uint8(67),
   7201 			1: uint8(87),
   7202 			2: uint8(58),
   7203 			3: uint8(169),
   7204 			4: uint8(82),
   7205 			5: uint8(115),
   7206 			6: uint8(26),
   7207 			7: uint8(59),
   7208 			8: uint8(179),
   7209 		},
   7210 		2: {
   7211 			0: uint8(63),
   7212 			1: uint8(59),
   7213 			2: uint8(90),
   7214 			3: uint8(180),
   7215 			4: uint8(59),
   7216 			5: uint8(166),
   7217 			6: uint8(93),
   7218 			7: uint8(73),
   7219 			8: uint8(154),
   7220 		},
   7221 		3: {
   7222 			0: uint8(40),
   7223 			1: uint8(40),
   7224 			2: uint8(21),
   7225 			3: uint8(116),
   7226 			4: uint8(143),
   7227 			5: uint8(209),
   7228 			6: uint8(34),
   7229 			7: uint8(39),
   7230 			8: uint8(175),
   7231 		},
   7232 		4: {
   7233 			0: uint8(47),
   7234 			1: uint8(15),
   7235 			2: uint8(16),
   7236 			3: uint8(183),
   7237 			4: uint8(34),
   7238 			5: uint8(223),
   7239 			6: uint8(49),
   7240 			7: uint8(45),
   7241 			8: uint8(183),
   7242 		},
   7243 		5: {
   7244 			0: uint8(46),
   7245 			1: uint8(17),
   7246 			2: uint8(33),
   7247 			3: uint8(183),
   7248 			4: uint8(6),
   7249 			5: uint8(98),
   7250 			6: uint8(15),
   7251 			7: uint8(32),
   7252 			8: uint8(183),
   7253 		},
   7254 		6: {
   7255 			0: uint8(57),
   7256 			1: uint8(46),
   7257 			2: uint8(22),
   7258 			3: uint8(24),
   7259 			4: uint8(128),
   7260 			5: uint8(1),
   7261 			6: uint8(54),
   7262 			7: uint8(17),
   7263 			8: uint8(37),
   7264 		},
   7265 		7: {
   7266 			0: uint8(65),
   7267 			1: uint8(32),
   7268 			2: uint8(73),
   7269 			3: uint8(115),
   7270 			4: uint8(28),
   7271 			5: uint8(128),
   7272 			6: uint8(23),
   7273 			7: uint8(128),
   7274 			8: uint8(205),
   7275 		},
   7276 		8: {
   7277 			0: uint8(40),
   7278 			1: uint8(3),
   7279 			2: uint8(9),
   7280 			3: uint8(115),
   7281 			4: uint8(51),
   7282 			5: uint8(192),
   7283 			6: uint8(18),
   7284 			7: uint8(6),
   7285 			8: uint8(223),
   7286 		},
   7287 		9: {
   7288 			0: uint8(87),
   7289 			1: uint8(37),
   7290 			2: uint8(9),
   7291 			3: uint8(115),
   7292 			4: uint8(59),
   7293 			5: uint8(77),
   7294 			6: uint8(64),
   7295 			7: uint8(21),
   7296 			8: uint8(47),
   7297 		},
   7298 	},
   7299 	5: {
   7300 		0: {
   7301 			0: uint8(104),
   7302 			1: uint8(55),
   7303 			2: uint8(44),
   7304 			3: uint8(218),
   7305 			4: uint8(9),
   7306 			5: uint8(54),
   7307 			6: uint8(53),
   7308 			7: uint8(130),
   7309 			8: uint8(226),
   7310 		},
   7311 		1: {
   7312 			0: uint8(64),
   7313 			1: uint8(90),
   7314 			2: uint8(70),
   7315 			3: uint8(205),
   7316 			4: uint8(40),
   7317 			5: uint8(41),
   7318 			6: uint8(23),
   7319 			7: uint8(26),
   7320 			8: uint8(57),
   7321 		},
   7322 		2: {
   7323 			0: uint8(54),
   7324 			1: uint8(57),
   7325 			2: uint8(112),
   7326 			3: uint8(184),
   7327 			4: uint8(5),
   7328 			5: uint8(41),
   7329 			6: uint8(38),
   7330 			7: uint8(166),
   7331 			8: uint8(213),
   7332 		},
   7333 		3: {
   7334 			0: uint8(30),
   7335 			1: uint8(34),
   7336 			2: uint8(26),
   7337 			3: uint8(133),
   7338 			4: uint8(152),
   7339 			5: uint8(116),
   7340 			6: uint8(10),
   7341 			7: uint8(32),
   7342 			8: uint8(134),
   7343 		},
   7344 		4: {
   7345 			0: uint8(39),
   7346 			1: uint8(19),
   7347 			2: uint8(53),
   7348 			3: uint8(221),
   7349 			4: uint8(26),
   7350 			5: uint8(114),
   7351 			6: uint8(32),
   7352 			7: uint8(73),
   7353 			8: uint8(255),
   7354 		},
   7355 		5: {
   7356 			0: uint8(31),
   7357 			1: uint8(9),
   7358 			2: uint8(65),
   7359 			3: uint8(234),
   7360 			4: uint8(2),
   7361 			5: uint8(15),
   7362 			6: uint8(1),
   7363 			7: uint8(118),
   7364 			8: uint8(73),
   7365 		},
   7366 		6: {
   7367 			0: uint8(75),
   7368 			1: uint8(32),
   7369 			2: uint8(12),
   7370 			3: uint8(51),
   7371 			4: uint8(192),
   7372 			5: uint8(255),
   7373 			6: uint8(160),
   7374 			7: uint8(43),
   7375 			8: uint8(51),
   7376 		},
   7377 		7: {
   7378 			0: uint8(88),
   7379 			1: uint8(31),
   7380 			2: uint8(35),
   7381 			3: uint8(67),
   7382 			4: uint8(102),
   7383 			5: uint8(85),
   7384 			6: uint8(55),
   7385 			7: uint8(186),
   7386 			8: uint8(85),
   7387 		},
   7388 		8: {
   7389 			0: uint8(56),
   7390 			1: uint8(21),
   7391 			2: uint8(23),
   7392 			3: uint8(111),
   7393 			4: uint8(59),
   7394 			5: uint8(205),
   7395 			6: uint8(45),
   7396 			7: uint8(37),
   7397 			8: uint8(192),
   7398 		},
   7399 		9: {
   7400 			0: uint8(55),
   7401 			1: uint8(38),
   7402 			2: uint8(70),
   7403 			3: uint8(124),
   7404 			4: uint8(73),
   7405 			5: uint8(102),
   7406 			6: uint8(1),
   7407 			7: uint8(34),
   7408 			8: uint8(98),
   7409 		},
   7410 	},
   7411 	6: {
   7412 		0: {
   7413 			0: uint8(125),
   7414 			1: uint8(98),
   7415 			2: uint8(42),
   7416 			3: uint8(88),
   7417 			4: uint8(104),
   7418 			5: uint8(85),
   7419 			6: uint8(117),
   7420 			7: uint8(175),
   7421 			8: uint8(82),
   7422 		},
   7423 		1: {
   7424 			0: uint8(95),
   7425 			1: uint8(84),
   7426 			2: uint8(53),
   7427 			3: uint8(89),
   7428 			4: uint8(128),
   7429 			5: uint8(100),
   7430 			6: uint8(113),
   7431 			7: uint8(101),
   7432 			8: uint8(45),
   7433 		},
   7434 		2: {
   7435 			0: uint8(75),
   7436 			1: uint8(79),
   7437 			2: uint8(123),
   7438 			3: uint8(47),
   7439 			4: uint8(51),
   7440 			5: uint8(128),
   7441 			6: uint8(81),
   7442 			7: uint8(171),
   7443 			8: uint8(1),
   7444 		},
   7445 		3: {
   7446 			0: uint8(57),
   7447 			1: uint8(17),
   7448 			2: uint8(5),
   7449 			3: uint8(71),
   7450 			4: uint8(102),
   7451 			5: uint8(57),
   7452 			6: uint8(53),
   7453 			7: uint8(41),
   7454 			8: uint8(49),
   7455 		},
   7456 		4: {
   7457 			0: uint8(38),
   7458 			1: uint8(33),
   7459 			2: uint8(13),
   7460 			3: uint8(121),
   7461 			4: uint8(57),
   7462 			5: uint8(73),
   7463 			6: uint8(26),
   7464 			7: uint8(1),
   7465 			8: uint8(85),
   7466 		},
   7467 		5: {
   7468 			0: uint8(41),
   7469 			1: uint8(10),
   7470 			2: uint8(67),
   7471 			3: uint8(138),
   7472 			4: uint8(77),
   7473 			5: uint8(110),
   7474 			6: uint8(90),
   7475 			7: uint8(47),
   7476 			8: uint8(114),
   7477 		},
   7478 		6: {
   7479 			0: uint8(115),
   7480 			1: uint8(21),
   7481 			2: uint8(2),
   7482 			3: uint8(10),
   7483 			4: uint8(102),
   7484 			5: uint8(255),
   7485 			6: uint8(166),
   7486 			7: uint8(23),
   7487 			8: uint8(6),
   7488 		},
   7489 		7: {
   7490 			0: uint8(101),
   7491 			1: uint8(29),
   7492 			2: uint8(16),
   7493 			3: uint8(10),
   7494 			4: uint8(85),
   7495 			5: uint8(128),
   7496 			6: uint8(101),
   7497 			7: uint8(196),
   7498 			8: uint8(26),
   7499 		},
   7500 		8: {
   7501 			0: uint8(57),
   7502 			1: uint8(18),
   7503 			2: uint8(10),
   7504 			3: uint8(102),
   7505 			4: uint8(102),
   7506 			5: uint8(213),
   7507 			6: uint8(34),
   7508 			7: uint8(20),
   7509 			8: uint8(43),
   7510 		},
   7511 		9: {
   7512 			0: uint8(117),
   7513 			1: uint8(20),
   7514 			2: uint8(15),
   7515 			3: uint8(36),
   7516 			4: uint8(163),
   7517 			5: uint8(128),
   7518 			6: uint8(68),
   7519 			7: uint8(1),
   7520 			8: uint8(26),
   7521 		},
   7522 	},
   7523 	7: {
   7524 		0: {
   7525 			0: uint8(102),
   7526 			1: uint8(61),
   7527 			2: uint8(71),
   7528 			3: uint8(37),
   7529 			4: uint8(34),
   7530 			5: uint8(53),
   7531 			6: uint8(31),
   7532 			7: uint8(243),
   7533 			8: uint8(192),
   7534 		},
   7535 		1: {
   7536 			0: uint8(69),
   7537 			1: uint8(60),
   7538 			2: uint8(71),
   7539 			3: uint8(38),
   7540 			4: uint8(73),
   7541 			5: uint8(119),
   7542 			6: uint8(28),
   7543 			7: uint8(222),
   7544 			8: uint8(37),
   7545 		},
   7546 		2: {
   7547 			0: uint8(68),
   7548 			1: uint8(45),
   7549 			2: uint8(128),
   7550 			3: uint8(34),
   7551 			4: uint8(1),
   7552 			5: uint8(47),
   7553 			6: uint8(11),
   7554 			7: uint8(245),
   7555 			8: uint8(171),
   7556 		},
   7557 		3: {
   7558 			0: uint8(62),
   7559 			1: uint8(17),
   7560 			2: uint8(19),
   7561 			3: uint8(70),
   7562 			4: uint8(146),
   7563 			5: uint8(85),
   7564 			6: uint8(55),
   7565 			7: uint8(62),
   7566 			8: uint8(70),
   7567 		},
   7568 		4: {
   7569 			0: uint8(37),
   7570 			1: uint8(43),
   7571 			2: uint8(37),
   7572 			3: uint8(154),
   7573 			4: uint8(100),
   7574 			5: uint8(163),
   7575 			6: uint8(85),
   7576 			7: uint8(160),
   7577 			8: uint8(1),
   7578 		},
   7579 		5: {
   7580 			0: uint8(63),
   7581 			1: uint8(9),
   7582 			2: uint8(92),
   7583 			3: uint8(136),
   7584 			4: uint8(28),
   7585 			5: uint8(64),
   7586 			6: uint8(32),
   7587 			7: uint8(201),
   7588 			8: uint8(85),
   7589 		},
   7590 		6: {
   7591 			0: uint8(75),
   7592 			1: uint8(15),
   7593 			2: uint8(9),
   7594 			3: uint8(9),
   7595 			4: uint8(64),
   7596 			5: uint8(255),
   7597 			6: uint8(184),
   7598 			7: uint8(119),
   7599 			8: uint8(16),
   7600 		},
   7601 		7: {
   7602 			0: uint8(86),
   7603 			1: uint8(6),
   7604 			2: uint8(28),
   7605 			3: uint8(5),
   7606 			4: uint8(64),
   7607 			5: uint8(255),
   7608 			6: uint8(25),
   7609 			7: uint8(248),
   7610 			8: uint8(1),
   7611 		},
   7612 		8: {
   7613 			0: uint8(56),
   7614 			1: uint8(8),
   7615 			2: uint8(17),
   7616 			3: uint8(132),
   7617 			4: uint8(137),
   7618 			5: uint8(255),
   7619 			6: uint8(55),
   7620 			7: uint8(116),
   7621 			8: uint8(128),
   7622 		},
   7623 		9: {
   7624 			0: uint8(58),
   7625 			1: uint8(15),
   7626 			2: uint8(20),
   7627 			3: uint8(82),
   7628 			4: uint8(135),
   7629 			5: uint8(57),
   7630 			6: uint8(26),
   7631 			7: uint8(121),
   7632 			8: uint8(40),
   7633 		},
   7634 	},
   7635 	8: {
   7636 		0: {
   7637 			0: uint8(164),
   7638 			1: uint8(50),
   7639 			2: uint8(31),
   7640 			3: uint8(137),
   7641 			4: uint8(154),
   7642 			5: uint8(133),
   7643 			6: uint8(25),
   7644 			7: uint8(35),
   7645 			8: uint8(218),
   7646 		},
   7647 		1: {
   7648 			0: uint8(51),
   7649 			1: uint8(103),
   7650 			2: uint8(44),
   7651 			3: uint8(131),
   7652 			4: uint8(131),
   7653 			5: uint8(123),
   7654 			6: uint8(31),
   7655 			7: uint8(6),
   7656 			8: uint8(158),
   7657 		},
   7658 		2: {
   7659 			0: uint8(86),
   7660 			1: uint8(40),
   7661 			2: uint8(64),
   7662 			3: uint8(135),
   7663 			4: uint8(148),
   7664 			5: uint8(224),
   7665 			6: uint8(45),
   7666 			7: uint8(183),
   7667 			8: uint8(128),
   7668 		},
   7669 		3: {
   7670 			0: uint8(22),
   7671 			1: uint8(26),
   7672 			2: uint8(17),
   7673 			3: uint8(131),
   7674 			4: uint8(240),
   7675 			5: uint8(154),
   7676 			6: uint8(14),
   7677 			7: uint8(1),
   7678 			8: uint8(209),
   7679 		},
   7680 		4: {
   7681 			0: uint8(45),
   7682 			1: uint8(16),
   7683 			2: uint8(21),
   7684 			3: uint8(91),
   7685 			4: uint8(64),
   7686 			5: uint8(222),
   7687 			6: uint8(7),
   7688 			7: uint8(1),
   7689 			8: uint8(197),
   7690 		},
   7691 		5: {
   7692 			0: uint8(56),
   7693 			1: uint8(21),
   7694 			2: uint8(39),
   7695 			3: uint8(155),
   7696 			4: uint8(60),
   7697 			5: uint8(138),
   7698 			6: uint8(23),
   7699 			7: uint8(102),
   7700 			8: uint8(213),
   7701 		},
   7702 		6: {
   7703 			0: uint8(83),
   7704 			1: uint8(12),
   7705 			2: uint8(13),
   7706 			3: uint8(54),
   7707 			4: uint8(192),
   7708 			5: uint8(255),
   7709 			6: uint8(68),
   7710 			7: uint8(47),
   7711 			8: uint8(28),
   7712 		},
   7713 		7: {
   7714 			0: uint8(85),
   7715 			1: uint8(26),
   7716 			2: uint8(85),
   7717 			3: uint8(85),
   7718 			4: uint8(128),
   7719 			5: uint8(128),
   7720 			6: uint8(32),
   7721 			7: uint8(146),
   7722 			8: uint8(171),
   7723 		},
   7724 		8: {
   7725 			0: uint8(18),
   7726 			1: uint8(11),
   7727 			2: uint8(7),
   7728 			3: uint8(63),
   7729 			4: uint8(144),
   7730 			5: uint8(171),
   7731 			6: uint8(4),
   7732 			7: uint8(4),
   7733 			8: uint8(246),
   7734 		},
   7735 		9: {
   7736 			0: uint8(35),
   7737 			1: uint8(27),
   7738 			2: uint8(10),
   7739 			3: uint8(146),
   7740 			4: uint8(174),
   7741 			5: uint8(171),
   7742 			6: uint8(12),
   7743 			7: uint8(26),
   7744 			8: uint8(128),
   7745 		},
   7746 	},
   7747 	9: {
   7748 		0: {
   7749 			0: uint8(190),
   7750 			1: uint8(80),
   7751 			2: uint8(35),
   7752 			3: uint8(99),
   7753 			4: uint8(180),
   7754 			5: uint8(80),
   7755 			6: uint8(126),
   7756 			7: uint8(54),
   7757 			8: uint8(45),
   7758 		},
   7759 		1: {
   7760 			0: uint8(85),
   7761 			1: uint8(126),
   7762 			2: uint8(47),
   7763 			3: uint8(87),
   7764 			4: uint8(176),
   7765 			5: uint8(51),
   7766 			6: uint8(41),
   7767 			7: uint8(20),
   7768 			8: uint8(32),
   7769 		},
   7770 		2: {
   7771 			0: uint8(101),
   7772 			1: uint8(75),
   7773 			2: uint8(128),
   7774 			3: uint8(139),
   7775 			4: uint8(118),
   7776 			5: uint8(146),
   7777 			6: uint8(116),
   7778 			7: uint8(128),
   7779 			8: uint8(85),
   7780 		},
   7781 		3: {
   7782 			0: uint8(56),
   7783 			1: uint8(41),
   7784 			2: uint8(15),
   7785 			3: uint8(176),
   7786 			4: uint8(236),
   7787 			5: uint8(85),
   7788 			6: uint8(37),
   7789 			7: uint8(9),
   7790 			8: uint8(62),
   7791 		},
   7792 		4: {
   7793 			0: uint8(71),
   7794 			1: uint8(30),
   7795 			2: uint8(17),
   7796 			3: uint8(119),
   7797 			4: uint8(118),
   7798 			5: uint8(255),
   7799 			6: uint8(17),
   7800 			7: uint8(18),
   7801 			8: uint8(138),
   7802 		},
   7803 		5: {
   7804 			0: uint8(101),
   7805 			1: uint8(38),
   7806 			2: uint8(60),
   7807 			3: uint8(138),
   7808 			4: uint8(55),
   7809 			5: uint8(70),
   7810 			6: uint8(43),
   7811 			7: uint8(26),
   7812 			8: uint8(142),
   7813 		},
   7814 		6: {
   7815 			0: uint8(146),
   7816 			1: uint8(36),
   7817 			2: uint8(19),
   7818 			3: uint8(30),
   7819 			4: uint8(171),
   7820 			5: uint8(255),
   7821 			6: uint8(97),
   7822 			7: uint8(27),
   7823 			8: uint8(20),
   7824 		},
   7825 		7: {
   7826 			0: uint8(138),
   7827 			1: uint8(45),
   7828 			2: uint8(61),
   7829 			3: uint8(62),
   7830 			4: uint8(219),
   7831 			5: uint8(1),
   7832 			6: uint8(81),
   7833 			7: uint8(188),
   7834 			8: uint8(64),
   7835 		},
   7836 		8: {
   7837 			0: uint8(32),
   7838 			1: uint8(41),
   7839 			2: uint8(20),
   7840 			3: uint8(117),
   7841 			4: uint8(151),
   7842 			5: uint8(142),
   7843 			6: uint8(20),
   7844 			7: uint8(21),
   7845 			8: uint8(163),
   7846 		},
   7847 		9: {
   7848 			0: uint8(112),
   7849 			1: uint8(19),
   7850 			2: uint8(12),
   7851 			3: uint8(61),
   7852 			4: uint8(195),
   7853 			5: uint8(128),
   7854 			6: uint8(48),
   7855 			7: uint8(4),
   7856 			8: uint8(24),
   7857 		},
   7858 	},
   7859 }
   7860 
   7861 func VP8ResetProba(tls *libc.TLS, proba uintptr) {
   7862 	libc.Xmemset(tls, proba, libc.Int32FromUint32(255), uint64(3))
   7863 	// proba->bands[][] is initialized later
   7864 }
   7865 
   7866 func ParseIntraMode(tls *libc.TLS, br2 uintptr, dec uintptr, mb_x int32) {
   7867 	bp := tls.Alloc(16)
   7868 	defer tls.Free(16)
   7869 	var bit, i, pos, shift, x1, y, ymode, ymode1, v1, v14, v16, v22, v24, v30, v32, v6, v8 int32
   7870 	var bits bit_t
   7871 	var block, left, modes, prob1, top, v10, v11, v18, v19, v2, v3 uintptr
   7872 	var range1, split, value range_t
   7873 	var v12, v20, v4 uint64_t
   7874 	var _ /* in_bits at bp+0 */ lbit_t
   7875 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, block, i, left, modes, pos, prob1, range1, shift, split, top, value, x1, y, ymode, ymode1, v1, v10, v11, v12, v14, v16, v18, v19, v2, v20, v22, v24, v3, v30, v32, v4, v6, v8
   7876 	top = (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t + uintptr(int32(4)*mb_x)
   7877 	left = dec + 2816
   7878 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr(mb_x)*800
   7879 	// Note: we don't save segment map (yet), as we don't expect
   7880 	// to decode more than 1 keyframe.
   7881 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fupdate_map != 0 {
   7882 		// Hardcoded tree parsing
   7883 		v2 = br2
   7884 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   7885 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   7886 			v3 = v2
   7887 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   7888 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   7889 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   7890 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   7891 				goto _5
   7892 			_5:
   7893 				bits = v4
   7894 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   7895 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   7896 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   7897 			} else {
   7898 				VP8LoadFinalBytes(tls, v3)
   7899 			}
   7900 		}
   7901 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   7902 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dec + 1192)))) >> int32(8)
   7903 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   7904 		bit = libc.BoolInt32(value > split)
   7905 		if bit != 0 {
   7906 			range1 = range1 - split
   7907 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   7908 		} else {
   7909 			range1 = split + uint32(1)
   7910 		}
   7911 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   7912 		goto _7
   7913 	_7:
   7914 		shift = int32(7) ^ v6
   7915 		range1 = range1 << libc.Uint32FromInt32(shift)
   7916 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   7917 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   7918 		v8 = bit
   7919 		goto _9
   7920 	_9:
   7921 		if !(v8 != 0) {
   7922 			v10 = br2
   7923 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   7924 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   7925 				v11 = v10
   7926 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   7927 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   7928 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   7929 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   7930 					goto _13
   7931 				_13:
   7932 					bits = v12
   7933 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   7934 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   7935 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   7936 				} else {
   7937 					VP8LoadFinalBytes(tls, v11)
   7938 				}
   7939 			}
   7940 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   7941 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dec + 1192 + 1)))) >> int32(8)
   7942 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   7943 			bit = libc.BoolInt32(value > split)
   7944 			if bit != 0 {
   7945 				range1 = range1 - split
   7946 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   7947 			} else {
   7948 				range1 = split + uint32(1)
   7949 			}
   7950 			v14 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   7951 			goto _15
   7952 		_15:
   7953 			shift = int32(7) ^ v14
   7954 			range1 = range1 << libc.Uint32FromInt32(shift)
   7955 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   7956 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   7957 			v16 = bit
   7958 			goto _17
   7959 		_17:
   7960 			v1 = v16
   7961 		} else {
   7962 			v18 = br2
   7963 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   7964 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   7965 				v19 = v18
   7966 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   7967 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   7968 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   7969 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   7970 					goto _21
   7971 				_21:
   7972 					bits = v20
   7973 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   7974 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   7975 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   7976 				} else {
   7977 					VP8LoadFinalBytes(tls, v19)
   7978 				}
   7979 			}
   7980 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   7981 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dec + 1192 + 2)))) >> int32(8)
   7982 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   7983 			bit = libc.BoolInt32(value > split)
   7984 			if bit != 0 {
   7985 				range1 = range1 - split
   7986 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   7987 			} else {
   7988 				range1 = split + uint32(1)
   7989 			}
   7990 			v22 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   7991 			goto _23
   7992 		_23:
   7993 			shift = int32(7) ^ v22
   7994 			range1 = range1 << libc.Uint32FromInt32(shift)
   7995 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   7996 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   7997 			v24 = bit
   7998 			goto _25
   7999 		_25:
   8000 			v1 = v24 + int32(2)
   8001 		}
   8002 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = libc.Uint8FromInt32(v1)
   8003 	} else {
   8004 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = uint8(0) // default for intra
   8005 	}
   8006 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
   8007 		v2 = br2
   8008 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8009 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8010 			v3 = v2
   8011 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8012 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8013 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8014 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8015 				goto _29
   8016 			_29:
   8017 				bits = v4
   8018 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8019 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8020 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8021 			} else {
   8022 				VP8LoadFinalBytes(tls, v3)
   8023 			}
   8024 		}
   8025 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8026 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8((*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p)) >> int32(8)
   8027 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8028 		bit = libc.BoolInt32(value > split)
   8029 		if bit != 0 {
   8030 			range1 = range1 - split
   8031 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8032 		} else {
   8033 			range1 = split + uint32(1)
   8034 		}
   8035 		v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8036 		goto _31
   8037 	_31:
   8038 		shift = int32(7) ^ v1
   8039 		range1 = range1 << libc.Uint32FromInt32(shift)
   8040 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8041 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8042 		v6 = bit
   8043 		goto _33
   8044 	_33:
   8045 		(*VP8MBData)(unsafe.Pointer(block)).Fskip = libc.Uint8FromInt32(v6)
   8046 	}
   8047 	v2 = br2
   8048 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8049 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8050 		v3 = v2
   8051 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8052 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8053 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8054 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8055 			goto _37
   8056 		_37:
   8057 			bits = v4
   8058 			bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8059 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8060 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8061 		} else {
   8062 			VP8LoadFinalBytes(tls, v3)
   8063 		}
   8064 	}
   8065 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8066 	split = range1 * libc.Uint32FromInt32(int32(145)) >> int32(8)
   8067 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8068 	bit = libc.BoolInt32(value > split)
   8069 	if bit != 0 {
   8070 		range1 = range1 - split
   8071 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8072 	} else {
   8073 		range1 = split + uint32(1)
   8074 	}
   8075 	v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8076 	goto _39
   8077 _39:
   8078 	shift = int32(7) ^ v1
   8079 	range1 = range1 << libc.Uint32FromInt32(shift)
   8080 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8081 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8082 	v6 = bit
   8083 	goto _41
   8084 _41:
   8085 	(*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 = libc.BoolUint8(!(v6 != 0))
   8086 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
   8087 		v2 = br2
   8088 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8089 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8090 			v3 = v2
   8091 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8092 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8093 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8094 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8095 				goto _46
   8096 			_46:
   8097 				bits = v4
   8098 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8099 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8100 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8101 			} else {
   8102 				VP8LoadFinalBytes(tls, v3)
   8103 			}
   8104 		}
   8105 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8106 		split = range1 * libc.Uint32FromInt32(int32(156)) >> int32(8)
   8107 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8108 		bit = libc.BoolInt32(value > split)
   8109 		if bit != 0 {
   8110 			range1 = range1 - split
   8111 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8112 		} else {
   8113 			range1 = split + uint32(1)
   8114 		}
   8115 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8116 		goto _48
   8117 	_48:
   8118 		shift = int32(7) ^ v6
   8119 		range1 = range1 << libc.Uint32FromInt32(shift)
   8120 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8121 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8122 		v8 = bit
   8123 		goto _50
   8124 	_50:
   8125 		if v8 != 0 {
   8126 			v10 = br2
   8127 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8128 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8129 				v11 = v10
   8130 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8131 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8132 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8133 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8134 					goto _55
   8135 				_55:
   8136 					bits = v12
   8137 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8138 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8139 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8140 				} else {
   8141 					VP8LoadFinalBytes(tls, v11)
   8142 				}
   8143 			}
   8144 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8145 			split = range1 * libc.Uint32FromInt32(int32(128)) >> int32(8)
   8146 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8147 			bit = libc.BoolInt32(value > split)
   8148 			if bit != 0 {
   8149 				range1 = range1 - split
   8150 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8151 			} else {
   8152 				range1 = split + uint32(1)
   8153 			}
   8154 			v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8155 			goto _57
   8156 		_57:
   8157 			shift = int32(7) ^ v16
   8158 			range1 = range1 << libc.Uint32FromInt32(shift)
   8159 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8160 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8161 			v22 = bit
   8162 			goto _59
   8163 		_59:
   8164 			if v22 != 0 {
   8165 				v14 = int32(TM_PRED)
   8166 			} else {
   8167 				v14 = int32(H_PRED)
   8168 			}
   8169 			v1 = v14
   8170 		} else {
   8171 			v18 = br2
   8172 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8173 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8174 				v19 = v18
   8175 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8176 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8177 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8178 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8179 					goto _64
   8180 				_64:
   8181 					bits = v20
   8182 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8183 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8184 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8185 				} else {
   8186 					VP8LoadFinalBytes(tls, v19)
   8187 				}
   8188 			}
   8189 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8190 			split = range1 * libc.Uint32FromInt32(int32(163)) >> int32(8)
   8191 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8192 			bit = libc.BoolInt32(value > split)
   8193 			if bit != 0 {
   8194 				range1 = range1 - split
   8195 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8196 			} else {
   8197 				range1 = split + uint32(1)
   8198 			}
   8199 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8200 			goto _66
   8201 		_66:
   8202 			shift = int32(7) ^ v30
   8203 			range1 = range1 << libc.Uint32FromInt32(shift)
   8204 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8205 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8206 			v32 = bit
   8207 			goto _68
   8208 		_68:
   8209 			if v32 != 0 {
   8210 				v24 = int32(V_PRED)
   8211 			} else {
   8212 				v24 = int32(DC_PRED)
   8213 			}
   8214 			v1 = v24
   8215 		}
   8216 		// Hardcoded 16x16 intra-mode decision tree.
   8217 		ymode = v1
   8218 		**(**uint8_t)(__ccgo_up(block + 769)) = libc.Uint8FromInt32(ymode)
   8219 		libc.Xmemset(tls, top, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8220 		libc.Xmemset(tls, left, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8221 	} else {
   8222 		modes = block + 769
   8223 		y = 0
   8224 		for {
   8225 			if !(y < int32(4)) {
   8226 				break
   8227 			}
   8228 			ymode1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
   8229 			x1 = 0
   8230 			for {
   8231 				if !(x1 < int32(4)) {
   8232 					break
   8233 				}
   8234 				prob1 = uintptr(unsafe.Pointer(&kBModesProba)) + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x1))))*90 + uintptr(ymode1)*9
   8235 				v2 = br2
   8236 				range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8237 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8238 					v3 = v2
   8239 					if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8240 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8241 						**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8242 						v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8243 						goto _74
   8244 					_74:
   8245 						bits = v4
   8246 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8247 						(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8248 						**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8249 					} else {
   8250 						VP8LoadFinalBytes(tls, v3)
   8251 					}
   8252 				}
   8253 				pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8254 				split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1)))) >> int32(8)
   8255 				value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8256 				bit = libc.BoolInt32(value > split)
   8257 				if bit != 0 {
   8258 					range1 = range1 - split
   8259 					**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8260 				} else {
   8261 					range1 = split + uint32(1)
   8262 				}
   8263 				v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8264 				goto _76
   8265 			_76:
   8266 				shift = int32(7) ^ v1
   8267 				range1 = range1 << libc.Uint32FromInt32(shift)
   8268 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8269 				(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8270 				v6 = bit
   8271 				goto _78
   8272 			_78:
   8273 				// Generic tree-parsing
   8274 				i = int32(kYModesIntra4[v6])
   8275 				for i > 0 {
   8276 					v10 = br2
   8277 					range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8278 					if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8279 						v11 = v10
   8280 						if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8281 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8282 							**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8283 							v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8284 							goto _82
   8285 						_82:
   8286 							bits = v12
   8287 							bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8288 							(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8289 							**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8290 						} else {
   8291 							VP8LoadFinalBytes(tls, v11)
   8292 						}
   8293 					}
   8294 					pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8295 					split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + uintptr(i))))) >> int32(8)
   8296 					value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8297 					bit = libc.BoolInt32(value > split)
   8298 					if bit != 0 {
   8299 						range1 = range1 - split
   8300 						**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8301 					} else {
   8302 						range1 = split + uint32(1)
   8303 					}
   8304 					v8 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8305 					goto _84
   8306 				_84:
   8307 					shift = int32(7) ^ v8
   8308 					range1 = range1 << libc.Uint32FromInt32(shift)
   8309 					**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8310 					(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8311 					v14 = bit
   8312 					goto _86
   8313 				_86:
   8314 					i = int32(kYModesIntra4[int32(2)*i+v14])
   8315 				}
   8316 				ymode1 = -i
   8317 				**(**uint8_t)(__ccgo_up(top + uintptr(x1))) = libc.Uint8FromInt32(ymode1)
   8318 				goto _70
   8319 			_70:
   8320 				;
   8321 				x1 = x1 + 1
   8322 			}
   8323 			libc.Xmemcpy(tls, modes, top, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8324 			modes = modes + uintptr(4)
   8325 			**(**uint8_t)(__ccgo_up(left + uintptr(y))) = libc.Uint8FromInt32(ymode1)
   8326 			goto _69
   8327 		_69:
   8328 			;
   8329 			y = y + 1
   8330 		}
   8331 	}
   8332 	// Hardcoded UVMode decision tree
   8333 	v2 = br2
   8334 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8335 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8336 		v3 = v2
   8337 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8338 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8339 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8340 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8341 			goto _91
   8342 		_91:
   8343 			bits = v4
   8344 			bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8345 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8346 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8347 		} else {
   8348 			VP8LoadFinalBytes(tls, v3)
   8349 		}
   8350 	}
   8351 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8352 	split = range1 * libc.Uint32FromInt32(int32(142)) >> int32(8)
   8353 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8354 	bit = libc.BoolInt32(value > split)
   8355 	if bit != 0 {
   8356 		range1 = range1 - split
   8357 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8358 	} else {
   8359 		range1 = split + uint32(1)
   8360 	}
   8361 	v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8362 	goto _93
   8363 _93:
   8364 	shift = int32(7) ^ v6
   8365 	range1 = range1 << libc.Uint32FromInt32(shift)
   8366 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8367 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8368 	v8 = bit
   8369 	goto _95
   8370 _95:
   8371 	if !(v8 != 0) {
   8372 		v1 = int32(DC_PRED)
   8373 	} else {
   8374 		v10 = br2
   8375 		range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8376 		if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8377 			v11 = v10
   8378 			if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8379 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8380 				**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8381 				v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8382 				goto _100
   8383 			_100:
   8384 				bits = v12
   8385 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8386 				(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8387 				**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8388 			} else {
   8389 				VP8LoadFinalBytes(tls, v11)
   8390 			}
   8391 		}
   8392 		pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8393 		split = range1 * libc.Uint32FromInt32(int32(114)) >> int32(8)
   8394 		value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8395 		bit = libc.BoolInt32(value > split)
   8396 		if bit != 0 {
   8397 			range1 = range1 - split
   8398 			**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8399 		} else {
   8400 			range1 = split + uint32(1)
   8401 		}
   8402 		v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8403 		goto _102
   8404 	_102:
   8405 		shift = int32(7) ^ v16
   8406 		range1 = range1 << libc.Uint32FromInt32(shift)
   8407 		**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8408 		(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8409 		v22 = bit
   8410 		goto _104
   8411 	_104:
   8412 		if !(v22 != 0) {
   8413 			v14 = int32(V_PRED)
   8414 		} else {
   8415 			v18 = br2
   8416 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8417 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8418 				v19 = v18
   8419 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8420 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8421 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8422 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8423 					goto _109
   8424 				_109:
   8425 					bits = v20
   8426 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8427 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8428 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8429 				} else {
   8430 					VP8LoadFinalBytes(tls, v19)
   8431 				}
   8432 			}
   8433 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8434 			split = range1 * libc.Uint32FromInt32(int32(183)) >> int32(8)
   8435 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8436 			bit = libc.BoolInt32(value > split)
   8437 			if bit != 0 {
   8438 				range1 = range1 - split
   8439 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8440 			} else {
   8441 				range1 = split + uint32(1)
   8442 			}
   8443 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8444 			goto _111
   8445 		_111:
   8446 			shift = int32(7) ^ v30
   8447 			range1 = range1 << libc.Uint32FromInt32(shift)
   8448 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8449 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8450 			v32 = bit
   8451 			goto _113
   8452 		_113:
   8453 			if v32 != 0 {
   8454 				v24 = int32(TM_PRED)
   8455 			} else {
   8456 				v24 = int32(H_PRED)
   8457 			}
   8458 			v14 = v24
   8459 		}
   8460 		v1 = v14
   8461 	}
   8462 	(*VP8MBData)(unsafe.Pointer(block)).Fuvmode = libc.Uint8FromInt32(v1)
   8463 }
   8464 
   8465 func VP8ParseIntraModeRow(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
   8466 	var mb_x int32
   8467 	_ = mb_x
   8468 	mb_x = 0
   8469 	for {
   8470 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   8471 			break
   8472 		}
   8473 		ParseIntraMode(tls, br, dec, mb_x)
   8474 		goto _1
   8475 	_1:
   8476 		;
   8477 		mb_x = mb_x + 1
   8478 	}
   8479 	return libc.BoolInt32(!((*VP8Decoder)(unsafe.Pointer(dec)).Fbr.Feof != 0))
   8480 }
   8481 
   8482 //------------------------------------------------------------------------------
   8483 // Paragraph 13
   8484 
   8485 var CoeffsUpdateProba = [4][8][3][11]uint8_t{
   8486 	0: {
   8487 		0: {
   8488 			0: {
   8489 				0:  uint8(255),
   8490 				1:  uint8(255),
   8491 				2:  uint8(255),
   8492 				3:  uint8(255),
   8493 				4:  uint8(255),
   8494 				5:  uint8(255),
   8495 				6:  uint8(255),
   8496 				7:  uint8(255),
   8497 				8:  uint8(255),
   8498 				9:  uint8(255),
   8499 				10: uint8(255),
   8500 			},
   8501 			1: {
   8502 				0:  uint8(255),
   8503 				1:  uint8(255),
   8504 				2:  uint8(255),
   8505 				3:  uint8(255),
   8506 				4:  uint8(255),
   8507 				5:  uint8(255),
   8508 				6:  uint8(255),
   8509 				7:  uint8(255),
   8510 				8:  uint8(255),
   8511 				9:  uint8(255),
   8512 				10: uint8(255),
   8513 			},
   8514 			2: {
   8515 				0:  uint8(255),
   8516 				1:  uint8(255),
   8517 				2:  uint8(255),
   8518 				3:  uint8(255),
   8519 				4:  uint8(255),
   8520 				5:  uint8(255),
   8521 				6:  uint8(255),
   8522 				7:  uint8(255),
   8523 				8:  uint8(255),
   8524 				9:  uint8(255),
   8525 				10: uint8(255),
   8526 			},
   8527 		},
   8528 		1: {
   8529 			0: {
   8530 				0:  uint8(176),
   8531 				1:  uint8(246),
   8532 				2:  uint8(255),
   8533 				3:  uint8(255),
   8534 				4:  uint8(255),
   8535 				5:  uint8(255),
   8536 				6:  uint8(255),
   8537 				7:  uint8(255),
   8538 				8:  uint8(255),
   8539 				9:  uint8(255),
   8540 				10: uint8(255),
   8541 			},
   8542 			1: {
   8543 				0:  uint8(223),
   8544 				1:  uint8(241),
   8545 				2:  uint8(252),
   8546 				3:  uint8(255),
   8547 				4:  uint8(255),
   8548 				5:  uint8(255),
   8549 				6:  uint8(255),
   8550 				7:  uint8(255),
   8551 				8:  uint8(255),
   8552 				9:  uint8(255),
   8553 				10: uint8(255),
   8554 			},
   8555 			2: {
   8556 				0:  uint8(249),
   8557 				1:  uint8(253),
   8558 				2:  uint8(253),
   8559 				3:  uint8(255),
   8560 				4:  uint8(255),
   8561 				5:  uint8(255),
   8562 				6:  uint8(255),
   8563 				7:  uint8(255),
   8564 				8:  uint8(255),
   8565 				9:  uint8(255),
   8566 				10: uint8(255),
   8567 			},
   8568 		},
   8569 		2: {
   8570 			0: {
   8571 				0:  uint8(255),
   8572 				1:  uint8(244),
   8573 				2:  uint8(252),
   8574 				3:  uint8(255),
   8575 				4:  uint8(255),
   8576 				5:  uint8(255),
   8577 				6:  uint8(255),
   8578 				7:  uint8(255),
   8579 				8:  uint8(255),
   8580 				9:  uint8(255),
   8581 				10: uint8(255),
   8582 			},
   8583 			1: {
   8584 				0:  uint8(234),
   8585 				1:  uint8(254),
   8586 				2:  uint8(254),
   8587 				3:  uint8(255),
   8588 				4:  uint8(255),
   8589 				5:  uint8(255),
   8590 				6:  uint8(255),
   8591 				7:  uint8(255),
   8592 				8:  uint8(255),
   8593 				9:  uint8(255),
   8594 				10: uint8(255),
   8595 			},
   8596 			2: {
   8597 				0:  uint8(253),
   8598 				1:  uint8(255),
   8599 				2:  uint8(255),
   8600 				3:  uint8(255),
   8601 				4:  uint8(255),
   8602 				5:  uint8(255),
   8603 				6:  uint8(255),
   8604 				7:  uint8(255),
   8605 				8:  uint8(255),
   8606 				9:  uint8(255),
   8607 				10: uint8(255),
   8608 			},
   8609 		},
   8610 		3: {
   8611 			0: {
   8612 				0:  uint8(255),
   8613 				1:  uint8(246),
   8614 				2:  uint8(254),
   8615 				3:  uint8(255),
   8616 				4:  uint8(255),
   8617 				5:  uint8(255),
   8618 				6:  uint8(255),
   8619 				7:  uint8(255),
   8620 				8:  uint8(255),
   8621 				9:  uint8(255),
   8622 				10: uint8(255),
   8623 			},
   8624 			1: {
   8625 				0:  uint8(239),
   8626 				1:  uint8(253),
   8627 				2:  uint8(254),
   8628 				3:  uint8(255),
   8629 				4:  uint8(255),
   8630 				5:  uint8(255),
   8631 				6:  uint8(255),
   8632 				7:  uint8(255),
   8633 				8:  uint8(255),
   8634 				9:  uint8(255),
   8635 				10: uint8(255),
   8636 			},
   8637 			2: {
   8638 				0:  uint8(254),
   8639 				1:  uint8(255),
   8640 				2:  uint8(254),
   8641 				3:  uint8(255),
   8642 				4:  uint8(255),
   8643 				5:  uint8(255),
   8644 				6:  uint8(255),
   8645 				7:  uint8(255),
   8646 				8:  uint8(255),
   8647 				9:  uint8(255),
   8648 				10: uint8(255),
   8649 			},
   8650 		},
   8651 		4: {
   8652 			0: {
   8653 				0:  uint8(255),
   8654 				1:  uint8(248),
   8655 				2:  uint8(254),
   8656 				3:  uint8(255),
   8657 				4:  uint8(255),
   8658 				5:  uint8(255),
   8659 				6:  uint8(255),
   8660 				7:  uint8(255),
   8661 				8:  uint8(255),
   8662 				9:  uint8(255),
   8663 				10: uint8(255),
   8664 			},
   8665 			1: {
   8666 				0:  uint8(251),
   8667 				1:  uint8(255),
   8668 				2:  uint8(254),
   8669 				3:  uint8(255),
   8670 				4:  uint8(255),
   8671 				5:  uint8(255),
   8672 				6:  uint8(255),
   8673 				7:  uint8(255),
   8674 				8:  uint8(255),
   8675 				9:  uint8(255),
   8676 				10: uint8(255),
   8677 			},
   8678 			2: {
   8679 				0:  uint8(255),
   8680 				1:  uint8(255),
   8681 				2:  uint8(255),
   8682 				3:  uint8(255),
   8683 				4:  uint8(255),
   8684 				5:  uint8(255),
   8685 				6:  uint8(255),
   8686 				7:  uint8(255),
   8687 				8:  uint8(255),
   8688 				9:  uint8(255),
   8689 				10: uint8(255),
   8690 			},
   8691 		},
   8692 		5: {
   8693 			0: {
   8694 				0:  uint8(255),
   8695 				1:  uint8(253),
   8696 				2:  uint8(254),
   8697 				3:  uint8(255),
   8698 				4:  uint8(255),
   8699 				5:  uint8(255),
   8700 				6:  uint8(255),
   8701 				7:  uint8(255),
   8702 				8:  uint8(255),
   8703 				9:  uint8(255),
   8704 				10: uint8(255),
   8705 			},
   8706 			1: {
   8707 				0:  uint8(251),
   8708 				1:  uint8(254),
   8709 				2:  uint8(254),
   8710 				3:  uint8(255),
   8711 				4:  uint8(255),
   8712 				5:  uint8(255),
   8713 				6:  uint8(255),
   8714 				7:  uint8(255),
   8715 				8:  uint8(255),
   8716 				9:  uint8(255),
   8717 				10: uint8(255),
   8718 			},
   8719 			2: {
   8720 				0:  uint8(254),
   8721 				1:  uint8(255),
   8722 				2:  uint8(254),
   8723 				3:  uint8(255),
   8724 				4:  uint8(255),
   8725 				5:  uint8(255),
   8726 				6:  uint8(255),
   8727 				7:  uint8(255),
   8728 				8:  uint8(255),
   8729 				9:  uint8(255),
   8730 				10: uint8(255),
   8731 			},
   8732 		},
   8733 		6: {
   8734 			0: {
   8735 				0:  uint8(255),
   8736 				1:  uint8(254),
   8737 				2:  uint8(253),
   8738 				3:  uint8(255),
   8739 				4:  uint8(254),
   8740 				5:  uint8(255),
   8741 				6:  uint8(255),
   8742 				7:  uint8(255),
   8743 				8:  uint8(255),
   8744 				9:  uint8(255),
   8745 				10: uint8(255),
   8746 			},
   8747 			1: {
   8748 				0:  uint8(250),
   8749 				1:  uint8(255),
   8750 				2:  uint8(254),
   8751 				3:  uint8(255),
   8752 				4:  uint8(254),
   8753 				5:  uint8(255),
   8754 				6:  uint8(255),
   8755 				7:  uint8(255),
   8756 				8:  uint8(255),
   8757 				9:  uint8(255),
   8758 				10: uint8(255),
   8759 			},
   8760 			2: {
   8761 				0:  uint8(254),
   8762 				1:  uint8(255),
   8763 				2:  uint8(255),
   8764 				3:  uint8(255),
   8765 				4:  uint8(255),
   8766 				5:  uint8(255),
   8767 				6:  uint8(255),
   8768 				7:  uint8(255),
   8769 				8:  uint8(255),
   8770 				9:  uint8(255),
   8771 				10: uint8(255),
   8772 			},
   8773 		},
   8774 		7: {
   8775 			0: {
   8776 				0:  uint8(255),
   8777 				1:  uint8(255),
   8778 				2:  uint8(255),
   8779 				3:  uint8(255),
   8780 				4:  uint8(255),
   8781 				5:  uint8(255),
   8782 				6:  uint8(255),
   8783 				7:  uint8(255),
   8784 				8:  uint8(255),
   8785 				9:  uint8(255),
   8786 				10: uint8(255),
   8787 			},
   8788 			1: {
   8789 				0:  uint8(255),
   8790 				1:  uint8(255),
   8791 				2:  uint8(255),
   8792 				3:  uint8(255),
   8793 				4:  uint8(255),
   8794 				5:  uint8(255),
   8795 				6:  uint8(255),
   8796 				7:  uint8(255),
   8797 				8:  uint8(255),
   8798 				9:  uint8(255),
   8799 				10: uint8(255),
   8800 			},
   8801 			2: {
   8802 				0:  uint8(255),
   8803 				1:  uint8(255),
   8804 				2:  uint8(255),
   8805 				3:  uint8(255),
   8806 				4:  uint8(255),
   8807 				5:  uint8(255),
   8808 				6:  uint8(255),
   8809 				7:  uint8(255),
   8810 				8:  uint8(255),
   8811 				9:  uint8(255),
   8812 				10: uint8(255),
   8813 			},
   8814 		},
   8815 	},
   8816 	1: {
   8817 		0: {
   8818 			0: {
   8819 				0:  uint8(217),
   8820 				1:  uint8(255),
   8821 				2:  uint8(255),
   8822 				3:  uint8(255),
   8823 				4:  uint8(255),
   8824 				5:  uint8(255),
   8825 				6:  uint8(255),
   8826 				7:  uint8(255),
   8827 				8:  uint8(255),
   8828 				9:  uint8(255),
   8829 				10: uint8(255),
   8830 			},
   8831 			1: {
   8832 				0:  uint8(225),
   8833 				1:  uint8(252),
   8834 				2:  uint8(241),
   8835 				3:  uint8(253),
   8836 				4:  uint8(255),
   8837 				5:  uint8(255),
   8838 				6:  uint8(254),
   8839 				7:  uint8(255),
   8840 				8:  uint8(255),
   8841 				9:  uint8(255),
   8842 				10: uint8(255),
   8843 			},
   8844 			2: {
   8845 				0:  uint8(234),
   8846 				1:  uint8(250),
   8847 				2:  uint8(241),
   8848 				3:  uint8(250),
   8849 				4:  uint8(253),
   8850 				5:  uint8(255),
   8851 				6:  uint8(253),
   8852 				7:  uint8(254),
   8853 				8:  uint8(255),
   8854 				9:  uint8(255),
   8855 				10: uint8(255),
   8856 			},
   8857 		},
   8858 		1: {
   8859 			0: {
   8860 				0:  uint8(255),
   8861 				1:  uint8(254),
   8862 				2:  uint8(255),
   8863 				3:  uint8(255),
   8864 				4:  uint8(255),
   8865 				5:  uint8(255),
   8866 				6:  uint8(255),
   8867 				7:  uint8(255),
   8868 				8:  uint8(255),
   8869 				9:  uint8(255),
   8870 				10: uint8(255),
   8871 			},
   8872 			1: {
   8873 				0:  uint8(223),
   8874 				1:  uint8(254),
   8875 				2:  uint8(254),
   8876 				3:  uint8(255),
   8877 				4:  uint8(255),
   8878 				5:  uint8(255),
   8879 				6:  uint8(255),
   8880 				7:  uint8(255),
   8881 				8:  uint8(255),
   8882 				9:  uint8(255),
   8883 				10: uint8(255),
   8884 			},
   8885 			2: {
   8886 				0:  uint8(238),
   8887 				1:  uint8(253),
   8888 				2:  uint8(254),
   8889 				3:  uint8(254),
   8890 				4:  uint8(255),
   8891 				5:  uint8(255),
   8892 				6:  uint8(255),
   8893 				7:  uint8(255),
   8894 				8:  uint8(255),
   8895 				9:  uint8(255),
   8896 				10: uint8(255),
   8897 			},
   8898 		},
   8899 		2: {
   8900 			0: {
   8901 				0:  uint8(255),
   8902 				1:  uint8(248),
   8903 				2:  uint8(254),
   8904 				3:  uint8(255),
   8905 				4:  uint8(255),
   8906 				5:  uint8(255),
   8907 				6:  uint8(255),
   8908 				7:  uint8(255),
   8909 				8:  uint8(255),
   8910 				9:  uint8(255),
   8911 				10: uint8(255),
   8912 			},
   8913 			1: {
   8914 				0:  uint8(249),
   8915 				1:  uint8(254),
   8916 				2:  uint8(255),
   8917 				3:  uint8(255),
   8918 				4:  uint8(255),
   8919 				5:  uint8(255),
   8920 				6:  uint8(255),
   8921 				7:  uint8(255),
   8922 				8:  uint8(255),
   8923 				9:  uint8(255),
   8924 				10: uint8(255),
   8925 			},
   8926 			2: {
   8927 				0:  uint8(255),
   8928 				1:  uint8(255),
   8929 				2:  uint8(255),
   8930 				3:  uint8(255),
   8931 				4:  uint8(255),
   8932 				5:  uint8(255),
   8933 				6:  uint8(255),
   8934 				7:  uint8(255),
   8935 				8:  uint8(255),
   8936 				9:  uint8(255),
   8937 				10: uint8(255),
   8938 			},
   8939 		},
   8940 		3: {
   8941 			0: {
   8942 				0:  uint8(255),
   8943 				1:  uint8(253),
   8944 				2:  uint8(255),
   8945 				3:  uint8(255),
   8946 				4:  uint8(255),
   8947 				5:  uint8(255),
   8948 				6:  uint8(255),
   8949 				7:  uint8(255),
   8950 				8:  uint8(255),
   8951 				9:  uint8(255),
   8952 				10: uint8(255),
   8953 			},
   8954 			1: {
   8955 				0:  uint8(247),
   8956 				1:  uint8(254),
   8957 				2:  uint8(255),
   8958 				3:  uint8(255),
   8959 				4:  uint8(255),
   8960 				5:  uint8(255),
   8961 				6:  uint8(255),
   8962 				7:  uint8(255),
   8963 				8:  uint8(255),
   8964 				9:  uint8(255),
   8965 				10: uint8(255),
   8966 			},
   8967 			2: {
   8968 				0:  uint8(255),
   8969 				1:  uint8(255),
   8970 				2:  uint8(255),
   8971 				3:  uint8(255),
   8972 				4:  uint8(255),
   8973 				5:  uint8(255),
   8974 				6:  uint8(255),
   8975 				7:  uint8(255),
   8976 				8:  uint8(255),
   8977 				9:  uint8(255),
   8978 				10: uint8(255),
   8979 			},
   8980 		},
   8981 		4: {
   8982 			0: {
   8983 				0:  uint8(255),
   8984 				1:  uint8(253),
   8985 				2:  uint8(254),
   8986 				3:  uint8(255),
   8987 				4:  uint8(255),
   8988 				5:  uint8(255),
   8989 				6:  uint8(255),
   8990 				7:  uint8(255),
   8991 				8:  uint8(255),
   8992 				9:  uint8(255),
   8993 				10: uint8(255),
   8994 			},
   8995 			1: {
   8996 				0:  uint8(252),
   8997 				1:  uint8(255),
   8998 				2:  uint8(255),
   8999 				3:  uint8(255),
   9000 				4:  uint8(255),
   9001 				5:  uint8(255),
   9002 				6:  uint8(255),
   9003 				7:  uint8(255),
   9004 				8:  uint8(255),
   9005 				9:  uint8(255),
   9006 				10: uint8(255),
   9007 			},
   9008 			2: {
   9009 				0:  uint8(255),
   9010 				1:  uint8(255),
   9011 				2:  uint8(255),
   9012 				3:  uint8(255),
   9013 				4:  uint8(255),
   9014 				5:  uint8(255),
   9015 				6:  uint8(255),
   9016 				7:  uint8(255),
   9017 				8:  uint8(255),
   9018 				9:  uint8(255),
   9019 				10: uint8(255),
   9020 			},
   9021 		},
   9022 		5: {
   9023 			0: {
   9024 				0:  uint8(255),
   9025 				1:  uint8(254),
   9026 				2:  uint8(254),
   9027 				3:  uint8(255),
   9028 				4:  uint8(255),
   9029 				5:  uint8(255),
   9030 				6:  uint8(255),
   9031 				7:  uint8(255),
   9032 				8:  uint8(255),
   9033 				9:  uint8(255),
   9034 				10: uint8(255),
   9035 			},
   9036 			1: {
   9037 				0:  uint8(253),
   9038 				1:  uint8(255),
   9039 				2:  uint8(255),
   9040 				3:  uint8(255),
   9041 				4:  uint8(255),
   9042 				5:  uint8(255),
   9043 				6:  uint8(255),
   9044 				7:  uint8(255),
   9045 				8:  uint8(255),
   9046 				9:  uint8(255),
   9047 				10: uint8(255),
   9048 			},
   9049 			2: {
   9050 				0:  uint8(255),
   9051 				1:  uint8(255),
   9052 				2:  uint8(255),
   9053 				3:  uint8(255),
   9054 				4:  uint8(255),
   9055 				5:  uint8(255),
   9056 				6:  uint8(255),
   9057 				7:  uint8(255),
   9058 				8:  uint8(255),
   9059 				9:  uint8(255),
   9060 				10: uint8(255),
   9061 			},
   9062 		},
   9063 		6: {
   9064 			0: {
   9065 				0:  uint8(255),
   9066 				1:  uint8(254),
   9067 				2:  uint8(253),
   9068 				3:  uint8(255),
   9069 				4:  uint8(255),
   9070 				5:  uint8(255),
   9071 				6:  uint8(255),
   9072 				7:  uint8(255),
   9073 				8:  uint8(255),
   9074 				9:  uint8(255),
   9075 				10: uint8(255),
   9076 			},
   9077 			1: {
   9078 				0:  uint8(250),
   9079 				1:  uint8(255),
   9080 				2:  uint8(255),
   9081 				3:  uint8(255),
   9082 				4:  uint8(255),
   9083 				5:  uint8(255),
   9084 				6:  uint8(255),
   9085 				7:  uint8(255),
   9086 				8:  uint8(255),
   9087 				9:  uint8(255),
   9088 				10: uint8(255),
   9089 			},
   9090 			2: {
   9091 				0:  uint8(254),
   9092 				1:  uint8(255),
   9093 				2:  uint8(255),
   9094 				3:  uint8(255),
   9095 				4:  uint8(255),
   9096 				5:  uint8(255),
   9097 				6:  uint8(255),
   9098 				7:  uint8(255),
   9099 				8:  uint8(255),
   9100 				9:  uint8(255),
   9101 				10: uint8(255),
   9102 			},
   9103 		},
   9104 		7: {
   9105 			0: {
   9106 				0:  uint8(255),
   9107 				1:  uint8(255),
   9108 				2:  uint8(255),
   9109 				3:  uint8(255),
   9110 				4:  uint8(255),
   9111 				5:  uint8(255),
   9112 				6:  uint8(255),
   9113 				7:  uint8(255),
   9114 				8:  uint8(255),
   9115 				9:  uint8(255),
   9116 				10: uint8(255),
   9117 			},
   9118 			1: {
   9119 				0:  uint8(255),
   9120 				1:  uint8(255),
   9121 				2:  uint8(255),
   9122 				3:  uint8(255),
   9123 				4:  uint8(255),
   9124 				5:  uint8(255),
   9125 				6:  uint8(255),
   9126 				7:  uint8(255),
   9127 				8:  uint8(255),
   9128 				9:  uint8(255),
   9129 				10: uint8(255),
   9130 			},
   9131 			2: {
   9132 				0:  uint8(255),
   9133 				1:  uint8(255),
   9134 				2:  uint8(255),
   9135 				3:  uint8(255),
   9136 				4:  uint8(255),
   9137 				5:  uint8(255),
   9138 				6:  uint8(255),
   9139 				7:  uint8(255),
   9140 				8:  uint8(255),
   9141 				9:  uint8(255),
   9142 				10: uint8(255),
   9143 			},
   9144 		},
   9145 	},
   9146 	2: {
   9147 		0: {
   9148 			0: {
   9149 				0:  uint8(186),
   9150 				1:  uint8(251),
   9151 				2:  uint8(250),
   9152 				3:  uint8(255),
   9153 				4:  uint8(255),
   9154 				5:  uint8(255),
   9155 				6:  uint8(255),
   9156 				7:  uint8(255),
   9157 				8:  uint8(255),
   9158 				9:  uint8(255),
   9159 				10: uint8(255),
   9160 			},
   9161 			1: {
   9162 				0:  uint8(234),
   9163 				1:  uint8(251),
   9164 				2:  uint8(244),
   9165 				3:  uint8(254),
   9166 				4:  uint8(255),
   9167 				5:  uint8(255),
   9168 				6:  uint8(255),
   9169 				7:  uint8(255),
   9170 				8:  uint8(255),
   9171 				9:  uint8(255),
   9172 				10: uint8(255),
   9173 			},
   9174 			2: {
   9175 				0:  uint8(251),
   9176 				1:  uint8(251),
   9177 				2:  uint8(243),
   9178 				3:  uint8(253),
   9179 				4:  uint8(254),
   9180 				5:  uint8(255),
   9181 				6:  uint8(254),
   9182 				7:  uint8(255),
   9183 				8:  uint8(255),
   9184 				9:  uint8(255),
   9185 				10: uint8(255),
   9186 			},
   9187 		},
   9188 		1: {
   9189 			0: {
   9190 				0:  uint8(255),
   9191 				1:  uint8(253),
   9192 				2:  uint8(254),
   9193 				3:  uint8(255),
   9194 				4:  uint8(255),
   9195 				5:  uint8(255),
   9196 				6:  uint8(255),
   9197 				7:  uint8(255),
   9198 				8:  uint8(255),
   9199 				9:  uint8(255),
   9200 				10: uint8(255),
   9201 			},
   9202 			1: {
   9203 				0:  uint8(236),
   9204 				1:  uint8(253),
   9205 				2:  uint8(254),
   9206 				3:  uint8(255),
   9207 				4:  uint8(255),
   9208 				5:  uint8(255),
   9209 				6:  uint8(255),
   9210 				7:  uint8(255),
   9211 				8:  uint8(255),
   9212 				9:  uint8(255),
   9213 				10: uint8(255),
   9214 			},
   9215 			2: {
   9216 				0:  uint8(251),
   9217 				1:  uint8(253),
   9218 				2:  uint8(253),
   9219 				3:  uint8(254),
   9220 				4:  uint8(254),
   9221 				5:  uint8(255),
   9222 				6:  uint8(255),
   9223 				7:  uint8(255),
   9224 				8:  uint8(255),
   9225 				9:  uint8(255),
   9226 				10: uint8(255),
   9227 			},
   9228 		},
   9229 		2: {
   9230 			0: {
   9231 				0:  uint8(255),
   9232 				1:  uint8(254),
   9233 				2:  uint8(254),
   9234 				3:  uint8(255),
   9235 				4:  uint8(255),
   9236 				5:  uint8(255),
   9237 				6:  uint8(255),
   9238 				7:  uint8(255),
   9239 				8:  uint8(255),
   9240 				9:  uint8(255),
   9241 				10: uint8(255),
   9242 			},
   9243 			1: {
   9244 				0:  uint8(254),
   9245 				1:  uint8(254),
   9246 				2:  uint8(254),
   9247 				3:  uint8(255),
   9248 				4:  uint8(255),
   9249 				5:  uint8(255),
   9250 				6:  uint8(255),
   9251 				7:  uint8(255),
   9252 				8:  uint8(255),
   9253 				9:  uint8(255),
   9254 				10: uint8(255),
   9255 			},
   9256 			2: {
   9257 				0:  uint8(255),
   9258 				1:  uint8(255),
   9259 				2:  uint8(255),
   9260 				3:  uint8(255),
   9261 				4:  uint8(255),
   9262 				5:  uint8(255),
   9263 				6:  uint8(255),
   9264 				7:  uint8(255),
   9265 				8:  uint8(255),
   9266 				9:  uint8(255),
   9267 				10: uint8(255),
   9268 			},
   9269 		},
   9270 		3: {
   9271 			0: {
   9272 				0:  uint8(255),
   9273 				1:  uint8(254),
   9274 				2:  uint8(255),
   9275 				3:  uint8(255),
   9276 				4:  uint8(255),
   9277 				5:  uint8(255),
   9278 				6:  uint8(255),
   9279 				7:  uint8(255),
   9280 				8:  uint8(255),
   9281 				9:  uint8(255),
   9282 				10: uint8(255),
   9283 			},
   9284 			1: {
   9285 				0:  uint8(254),
   9286 				1:  uint8(254),
   9287 				2:  uint8(255),
   9288 				3:  uint8(255),
   9289 				4:  uint8(255),
   9290 				5:  uint8(255),
   9291 				6:  uint8(255),
   9292 				7:  uint8(255),
   9293 				8:  uint8(255),
   9294 				9:  uint8(255),
   9295 				10: uint8(255),
   9296 			},
   9297 			2: {
   9298 				0:  uint8(254),
   9299 				1:  uint8(255),
   9300 				2:  uint8(255),
   9301 				3:  uint8(255),
   9302 				4:  uint8(255),
   9303 				5:  uint8(255),
   9304 				6:  uint8(255),
   9305 				7:  uint8(255),
   9306 				8:  uint8(255),
   9307 				9:  uint8(255),
   9308 				10: uint8(255),
   9309 			},
   9310 		},
   9311 		4: {
   9312 			0: {
   9313 				0:  uint8(255),
   9314 				1:  uint8(255),
   9315 				2:  uint8(255),
   9316 				3:  uint8(255),
   9317 				4:  uint8(255),
   9318 				5:  uint8(255),
   9319 				6:  uint8(255),
   9320 				7:  uint8(255),
   9321 				8:  uint8(255),
   9322 				9:  uint8(255),
   9323 				10: uint8(255),
   9324 			},
   9325 			1: {
   9326 				0:  uint8(254),
   9327 				1:  uint8(255),
   9328 				2:  uint8(255),
   9329 				3:  uint8(255),
   9330 				4:  uint8(255),
   9331 				5:  uint8(255),
   9332 				6:  uint8(255),
   9333 				7:  uint8(255),
   9334 				8:  uint8(255),
   9335 				9:  uint8(255),
   9336 				10: uint8(255),
   9337 			},
   9338 			2: {
   9339 				0:  uint8(255),
   9340 				1:  uint8(255),
   9341 				2:  uint8(255),
   9342 				3:  uint8(255),
   9343 				4:  uint8(255),
   9344 				5:  uint8(255),
   9345 				6:  uint8(255),
   9346 				7:  uint8(255),
   9347 				8:  uint8(255),
   9348 				9:  uint8(255),
   9349 				10: uint8(255),
   9350 			},
   9351 		},
   9352 		5: {
   9353 			0: {
   9354 				0:  uint8(255),
   9355 				1:  uint8(255),
   9356 				2:  uint8(255),
   9357 				3:  uint8(255),
   9358 				4:  uint8(255),
   9359 				5:  uint8(255),
   9360 				6:  uint8(255),
   9361 				7:  uint8(255),
   9362 				8:  uint8(255),
   9363 				9:  uint8(255),
   9364 				10: uint8(255),
   9365 			},
   9366 			1: {
   9367 				0:  uint8(255),
   9368 				1:  uint8(255),
   9369 				2:  uint8(255),
   9370 				3:  uint8(255),
   9371 				4:  uint8(255),
   9372 				5:  uint8(255),
   9373 				6:  uint8(255),
   9374 				7:  uint8(255),
   9375 				8:  uint8(255),
   9376 				9:  uint8(255),
   9377 				10: uint8(255),
   9378 			},
   9379 			2: {
   9380 				0:  uint8(255),
   9381 				1:  uint8(255),
   9382 				2:  uint8(255),
   9383 				3:  uint8(255),
   9384 				4:  uint8(255),
   9385 				5:  uint8(255),
   9386 				6:  uint8(255),
   9387 				7:  uint8(255),
   9388 				8:  uint8(255),
   9389 				9:  uint8(255),
   9390 				10: uint8(255),
   9391 			},
   9392 		},
   9393 		6: {
   9394 			0: {
   9395 				0:  uint8(255),
   9396 				1:  uint8(255),
   9397 				2:  uint8(255),
   9398 				3:  uint8(255),
   9399 				4:  uint8(255),
   9400 				5:  uint8(255),
   9401 				6:  uint8(255),
   9402 				7:  uint8(255),
   9403 				8:  uint8(255),
   9404 				9:  uint8(255),
   9405 				10: uint8(255),
   9406 			},
   9407 			1: {
   9408 				0:  uint8(255),
   9409 				1:  uint8(255),
   9410 				2:  uint8(255),
   9411 				3:  uint8(255),
   9412 				4:  uint8(255),
   9413 				5:  uint8(255),
   9414 				6:  uint8(255),
   9415 				7:  uint8(255),
   9416 				8:  uint8(255),
   9417 				9:  uint8(255),
   9418 				10: uint8(255),
   9419 			},
   9420 			2: {
   9421 				0:  uint8(255),
   9422 				1:  uint8(255),
   9423 				2:  uint8(255),
   9424 				3:  uint8(255),
   9425 				4:  uint8(255),
   9426 				5:  uint8(255),
   9427 				6:  uint8(255),
   9428 				7:  uint8(255),
   9429 				8:  uint8(255),
   9430 				9:  uint8(255),
   9431 				10: uint8(255),
   9432 			},
   9433 		},
   9434 		7: {
   9435 			0: {
   9436 				0:  uint8(255),
   9437 				1:  uint8(255),
   9438 				2:  uint8(255),
   9439 				3:  uint8(255),
   9440 				4:  uint8(255),
   9441 				5:  uint8(255),
   9442 				6:  uint8(255),
   9443 				7:  uint8(255),
   9444 				8:  uint8(255),
   9445 				9:  uint8(255),
   9446 				10: uint8(255),
   9447 			},
   9448 			1: {
   9449 				0:  uint8(255),
   9450 				1:  uint8(255),
   9451 				2:  uint8(255),
   9452 				3:  uint8(255),
   9453 				4:  uint8(255),
   9454 				5:  uint8(255),
   9455 				6:  uint8(255),
   9456 				7:  uint8(255),
   9457 				8:  uint8(255),
   9458 				9:  uint8(255),
   9459 				10: uint8(255),
   9460 			},
   9461 			2: {
   9462 				0:  uint8(255),
   9463 				1:  uint8(255),
   9464 				2:  uint8(255),
   9465 				3:  uint8(255),
   9466 				4:  uint8(255),
   9467 				5:  uint8(255),
   9468 				6:  uint8(255),
   9469 				7:  uint8(255),
   9470 				8:  uint8(255),
   9471 				9:  uint8(255),
   9472 				10: uint8(255),
   9473 			},
   9474 		},
   9475 	},
   9476 	3: {
   9477 		0: {
   9478 			0: {
   9479 				0:  uint8(248),
   9480 				1:  uint8(255),
   9481 				2:  uint8(255),
   9482 				3:  uint8(255),
   9483 				4:  uint8(255),
   9484 				5:  uint8(255),
   9485 				6:  uint8(255),
   9486 				7:  uint8(255),
   9487 				8:  uint8(255),
   9488 				9:  uint8(255),
   9489 				10: uint8(255),
   9490 			},
   9491 			1: {
   9492 				0:  uint8(250),
   9493 				1:  uint8(254),
   9494 				2:  uint8(252),
   9495 				3:  uint8(254),
   9496 				4:  uint8(255),
   9497 				5:  uint8(255),
   9498 				6:  uint8(255),
   9499 				7:  uint8(255),
   9500 				8:  uint8(255),
   9501 				9:  uint8(255),
   9502 				10: uint8(255),
   9503 			},
   9504 			2: {
   9505 				0:  uint8(248),
   9506 				1:  uint8(254),
   9507 				2:  uint8(249),
   9508 				3:  uint8(253),
   9509 				4:  uint8(255),
   9510 				5:  uint8(255),
   9511 				6:  uint8(255),
   9512 				7:  uint8(255),
   9513 				8:  uint8(255),
   9514 				9:  uint8(255),
   9515 				10: uint8(255),
   9516 			},
   9517 		},
   9518 		1: {
   9519 			0: {
   9520 				0:  uint8(255),
   9521 				1:  uint8(253),
   9522 				2:  uint8(253),
   9523 				3:  uint8(255),
   9524 				4:  uint8(255),
   9525 				5:  uint8(255),
   9526 				6:  uint8(255),
   9527 				7:  uint8(255),
   9528 				8:  uint8(255),
   9529 				9:  uint8(255),
   9530 				10: uint8(255),
   9531 			},
   9532 			1: {
   9533 				0:  uint8(246),
   9534 				1:  uint8(253),
   9535 				2:  uint8(253),
   9536 				3:  uint8(255),
   9537 				4:  uint8(255),
   9538 				5:  uint8(255),
   9539 				6:  uint8(255),
   9540 				7:  uint8(255),
   9541 				8:  uint8(255),
   9542 				9:  uint8(255),
   9543 				10: uint8(255),
   9544 			},
   9545 			2: {
   9546 				0:  uint8(252),
   9547 				1:  uint8(254),
   9548 				2:  uint8(251),
   9549 				3:  uint8(254),
   9550 				4:  uint8(254),
   9551 				5:  uint8(255),
   9552 				6:  uint8(255),
   9553 				7:  uint8(255),
   9554 				8:  uint8(255),
   9555 				9:  uint8(255),
   9556 				10: uint8(255),
   9557 			},
   9558 		},
   9559 		2: {
   9560 			0: {
   9561 				0:  uint8(255),
   9562 				1:  uint8(254),
   9563 				2:  uint8(252),
   9564 				3:  uint8(255),
   9565 				4:  uint8(255),
   9566 				5:  uint8(255),
   9567 				6:  uint8(255),
   9568 				7:  uint8(255),
   9569 				8:  uint8(255),
   9570 				9:  uint8(255),
   9571 				10: uint8(255),
   9572 			},
   9573 			1: {
   9574 				0:  uint8(248),
   9575 				1:  uint8(254),
   9576 				2:  uint8(253),
   9577 				3:  uint8(255),
   9578 				4:  uint8(255),
   9579 				5:  uint8(255),
   9580 				6:  uint8(255),
   9581 				7:  uint8(255),
   9582 				8:  uint8(255),
   9583 				9:  uint8(255),
   9584 				10: uint8(255),
   9585 			},
   9586 			2: {
   9587 				0:  uint8(253),
   9588 				1:  uint8(255),
   9589 				2:  uint8(254),
   9590 				3:  uint8(254),
   9591 				4:  uint8(255),
   9592 				5:  uint8(255),
   9593 				6:  uint8(255),
   9594 				7:  uint8(255),
   9595 				8:  uint8(255),
   9596 				9:  uint8(255),
   9597 				10: uint8(255),
   9598 			},
   9599 		},
   9600 		3: {
   9601 			0: {
   9602 				0:  uint8(255),
   9603 				1:  uint8(251),
   9604 				2:  uint8(254),
   9605 				3:  uint8(255),
   9606 				4:  uint8(255),
   9607 				5:  uint8(255),
   9608 				6:  uint8(255),
   9609 				7:  uint8(255),
   9610 				8:  uint8(255),
   9611 				9:  uint8(255),
   9612 				10: uint8(255),
   9613 			},
   9614 			1: {
   9615 				0:  uint8(245),
   9616 				1:  uint8(251),
   9617 				2:  uint8(254),
   9618 				3:  uint8(255),
   9619 				4:  uint8(255),
   9620 				5:  uint8(255),
   9621 				6:  uint8(255),
   9622 				7:  uint8(255),
   9623 				8:  uint8(255),
   9624 				9:  uint8(255),
   9625 				10: uint8(255),
   9626 			},
   9627 			2: {
   9628 				0:  uint8(253),
   9629 				1:  uint8(253),
   9630 				2:  uint8(254),
   9631 				3:  uint8(255),
   9632 				4:  uint8(255),
   9633 				5:  uint8(255),
   9634 				6:  uint8(255),
   9635 				7:  uint8(255),
   9636 				8:  uint8(255),
   9637 				9:  uint8(255),
   9638 				10: uint8(255),
   9639 			},
   9640 		},
   9641 		4: {
   9642 			0: {
   9643 				0:  uint8(255),
   9644 				1:  uint8(251),
   9645 				2:  uint8(253),
   9646 				3:  uint8(255),
   9647 				4:  uint8(255),
   9648 				5:  uint8(255),
   9649 				6:  uint8(255),
   9650 				7:  uint8(255),
   9651 				8:  uint8(255),
   9652 				9:  uint8(255),
   9653 				10: uint8(255),
   9654 			},
   9655 			1: {
   9656 				0:  uint8(252),
   9657 				1:  uint8(253),
   9658 				2:  uint8(254),
   9659 				3:  uint8(255),
   9660 				4:  uint8(255),
   9661 				5:  uint8(255),
   9662 				6:  uint8(255),
   9663 				7:  uint8(255),
   9664 				8:  uint8(255),
   9665 				9:  uint8(255),
   9666 				10: uint8(255),
   9667 			},
   9668 			2: {
   9669 				0:  uint8(255),
   9670 				1:  uint8(254),
   9671 				2:  uint8(255),
   9672 				3:  uint8(255),
   9673 				4:  uint8(255),
   9674 				5:  uint8(255),
   9675 				6:  uint8(255),
   9676 				7:  uint8(255),
   9677 				8:  uint8(255),
   9678 				9:  uint8(255),
   9679 				10: uint8(255),
   9680 			},
   9681 		},
   9682 		5: {
   9683 			0: {
   9684 				0:  uint8(255),
   9685 				1:  uint8(252),
   9686 				2:  uint8(255),
   9687 				3:  uint8(255),
   9688 				4:  uint8(255),
   9689 				5:  uint8(255),
   9690 				6:  uint8(255),
   9691 				7:  uint8(255),
   9692 				8:  uint8(255),
   9693 				9:  uint8(255),
   9694 				10: uint8(255),
   9695 			},
   9696 			1: {
   9697 				0:  uint8(249),
   9698 				1:  uint8(255),
   9699 				2:  uint8(254),
   9700 				3:  uint8(255),
   9701 				4:  uint8(255),
   9702 				5:  uint8(255),
   9703 				6:  uint8(255),
   9704 				7:  uint8(255),
   9705 				8:  uint8(255),
   9706 				9:  uint8(255),
   9707 				10: uint8(255),
   9708 			},
   9709 			2: {
   9710 				0:  uint8(255),
   9711 				1:  uint8(255),
   9712 				2:  uint8(254),
   9713 				3:  uint8(255),
   9714 				4:  uint8(255),
   9715 				5:  uint8(255),
   9716 				6:  uint8(255),
   9717 				7:  uint8(255),
   9718 				8:  uint8(255),
   9719 				9:  uint8(255),
   9720 				10: uint8(255),
   9721 			},
   9722 		},
   9723 		6: {
   9724 			0: {
   9725 				0:  uint8(255),
   9726 				1:  uint8(255),
   9727 				2:  uint8(253),
   9728 				3:  uint8(255),
   9729 				4:  uint8(255),
   9730 				5:  uint8(255),
   9731 				6:  uint8(255),
   9732 				7:  uint8(255),
   9733 				8:  uint8(255),
   9734 				9:  uint8(255),
   9735 				10: uint8(255),
   9736 			},
   9737 			1: {
   9738 				0:  uint8(250),
   9739 				1:  uint8(255),
   9740 				2:  uint8(255),
   9741 				3:  uint8(255),
   9742 				4:  uint8(255),
   9743 				5:  uint8(255),
   9744 				6:  uint8(255),
   9745 				7:  uint8(255),
   9746 				8:  uint8(255),
   9747 				9:  uint8(255),
   9748 				10: uint8(255),
   9749 			},
   9750 			2: {
   9751 				0:  uint8(255),
   9752 				1:  uint8(255),
   9753 				2:  uint8(255),
   9754 				3:  uint8(255),
   9755 				4:  uint8(255),
   9756 				5:  uint8(255),
   9757 				6:  uint8(255),
   9758 				7:  uint8(255),
   9759 				8:  uint8(255),
   9760 				9:  uint8(255),
   9761 				10: uint8(255),
   9762 			},
   9763 		},
   9764 		7: {
   9765 			0: {
   9766 				0:  uint8(255),
   9767 				1:  uint8(255),
   9768 				2:  uint8(255),
   9769 				3:  uint8(255),
   9770 				4:  uint8(255),
   9771 				5:  uint8(255),
   9772 				6:  uint8(255),
   9773 				7:  uint8(255),
   9774 				8:  uint8(255),
   9775 				9:  uint8(255),
   9776 				10: uint8(255),
   9777 			},
   9778 			1: {
   9779 				0:  uint8(254),
   9780 				1:  uint8(255),
   9781 				2:  uint8(255),
   9782 				3:  uint8(255),
   9783 				4:  uint8(255),
   9784 				5:  uint8(255),
   9785 				6:  uint8(255),
   9786 				7:  uint8(255),
   9787 				8:  uint8(255),
   9788 				9:  uint8(255),
   9789 				10: uint8(255),
   9790 			},
   9791 			2: {
   9792 				0:  uint8(255),
   9793 				1:  uint8(255),
   9794 				2:  uint8(255),
   9795 				3:  uint8(255),
   9796 				4:  uint8(255),
   9797 				5:  uint8(255),
   9798 				6:  uint8(255),
   9799 				7:  uint8(255),
   9800 				8:  uint8(255),
   9801 				9:  uint8(255),
   9802 				10: uint8(255),
   9803 			},
   9804 		},
   9805 	},
   9806 }
   9807 
   9808 // Paragraph 9.9
   9809 
   9810 var kBands = [17]uint8_t{
   9811 	1:  uint8(1),
   9812 	2:  uint8(2),
   9813 	3:  uint8(3),
   9814 	4:  uint8(6),
   9815 	5:  uint8(4),
   9816 	6:  uint8(5),
   9817 	7:  uint8(6),
   9818 	8:  uint8(6),
   9819 	9:  uint8(6),
   9820 	10: uint8(6),
   9821 	11: uint8(6),
   9822 	12: uint8(6),
   9823 	13: uint8(6),
   9824 	14: uint8(6),
   9825 	15: uint8(7),
   9826 }
   9827 
   9828 func VP8ParseProba(tls *libc.TLS, br2 uintptr, dec uintptr) {
   9829 	bp := tls.Alloc(16)
   9830 	defer tls.Free(16)
   9831 	var b, bit, c, p, pos, shift, t, v, v10, v12 int32
   9832 	var bits bit_t
   9833 	var proba, v6, v7 uintptr
   9834 	var range1, split, value range_t
   9835 	var v5 uint32
   9836 	var v8 uint64_t
   9837 	var _ /* in_bits at bp+0 */ lbit_t
   9838 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, bit, bits, c, p, pos, proba, range1, shift, split, t, v, value, v10, v12, v5, v6, v7, v8
   9839 	proba = dec + 1192
   9840 	t = 0
   9841 	for {
   9842 		if !(t < int32(NUM_TYPES)) {
   9843 			break
   9844 		}
   9845 		b = 0
   9846 		for {
   9847 			if !(b < int32(NUM_BANDS)) {
   9848 				break
   9849 			}
   9850 			c = 0
   9851 			for {
   9852 				if !(c < int32(NUM_CTX)) {
   9853 					break
   9854 				}
   9855 				p = 0
   9856 				for {
   9857 					if !(p < int32(NUM_PROBAS)) {
   9858 						break
   9859 					}
   9860 					v6 = br2
   9861 					range1 = (*VP8BitReader)(unsafe.Pointer(v6)).Frange1
   9862 					if (*VP8BitReader)(unsafe.Pointer(v6)).Fbits < libc.Int32FromInt32(0) {
   9863 						v7 = v6
   9864 						if (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf_max {
   9865 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf, uint64(8))
   9866 							**(**uintptr)(__ccgo_up(v7 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   9867 							v8 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   9868 							goto _9
   9869 						_9:
   9870 							bits = v8
   9871 							bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   9872 							(*VP8BitReader)(unsafe.Pointer(v7)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v7)).Fvalue<<libc.Int32FromInt32(BITS)
   9873 							**(**int32)(__ccgo_up(v7 + 12)) += int32(BITS)
   9874 						} else {
   9875 							VP8LoadFinalBytes(tls, v7)
   9876 						}
   9877 					}
   9878 					pos = (*VP8BitReader)(unsafe.Pointer(v6)).Fbits
   9879 					split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))) >> int32(8)
   9880 					value = uint32((*VP8BitReader)(unsafe.Pointer(v6)).Fvalue >> pos)
   9881 					bit = libc.BoolInt32(value > split)
   9882 					if bit != 0 {
   9883 						range1 = range1 - split
   9884 						**(**bit_t)(__ccgo_up(v6)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   9885 					} else {
   9886 						range1 = split + uint32(1)
   9887 					}
   9888 					v10 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   9889 					goto _11
   9890 				_11:
   9891 					shift = int32(7) ^ v10
   9892 					range1 = range1 << libc.Uint32FromInt32(shift)
   9893 					**(**int32)(__ccgo_up(v6 + 12)) -= shift
   9894 					(*VP8BitReader)(unsafe.Pointer(v6)).Frange1 = range1 - uint32(1)
   9895 					v12 = bit
   9896 					goto _13
   9897 				_13:
   9898 					if v12 != 0 {
   9899 						v5 = VP8GetValue(tls, br2, int32(8))
   9900 					} else {
   9901 						v5 = uint32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
   9902 					}
   9903 					v = libc.Int32FromUint32(v5)
   9904 					**(**uint8_t)(__ccgo_up(proba + 3 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = libc.Uint8FromInt32(v)
   9905 					goto _4
   9906 				_4:
   9907 					;
   9908 					p = p + 1
   9909 				}
   9910 				goto _3
   9911 			_3:
   9912 				;
   9913 				c = c + 1
   9914 			}
   9915 			goto _2
   9916 		_2:
   9917 			;
   9918 			b = b + 1
   9919 		}
   9920 		b = 0
   9921 		for {
   9922 			if !(b < libc.Int32FromInt32(16)+libc.Int32FromInt32(1)) {
   9923 				break
   9924 			}
   9925 			**(**uintptr)(__ccgo_up(proba + 1064 + uintptr(t)*136 + uintptr(b)*8)) = proba + 3 + uintptr(t)*264 + uintptr(kBands[b])*33
   9926 			goto _14
   9927 		_14:
   9928 			;
   9929 			b = b + 1
   9930 		}
   9931 		goto _1
   9932 	_1:
   9933 		;
   9934 		t = t + 1
   9935 	}
   9936 	(*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba = libc.Int32FromUint32(VP8GetValue(tls, br2, int32(1)))
   9937 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
   9938 		(*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p = uint8(VP8GetValue(tls, br2, int32(8)))
   9939 	}
   9940 }
   9941 
   9942 var kHashMul7 = uint32(0x1e35a7bd)
   9943 
   9944 // Copyright 2010 Google Inc. All Rights Reserved.
   9945 //
   9946 // Use of this source code is governed by a BSD-style license
   9947 // that can be found in the COPYING file in the root of the source
   9948 // tree. An additional intellectual property rights grant can be found
   9949 // in the file PATENTS. All contributing project authors may
   9950 // be found in the AUTHORS file in the root of the source tree.
   9951 // -----------------------------------------------------------------------------
   9952 //
   9953 // Boolean decoder
   9954 //
   9955 // Author: Skal (pascal.massimino@gmail.com)
   9956 //         Vikas Arora (vikaas.arora@gmail.com)
   9957 
   9958 // Copyright 2011 Google Inc. All Rights Reserved.
   9959 //
   9960 // Use of this source code is governed by a BSD-style license
   9961 // that can be found in the COPYING file in the root of the source
   9962 // tree. An additional intellectual property rights grant can be found
   9963 // in the file PATENTS. All contributing project authors may
   9964 // be found in the AUTHORS file in the root of the source tree.
   9965 // -----------------------------------------------------------------------------
   9966 //
   9967 // Multi-threaded worker
   9968 //
   9969 // Author: Skal (pascal.massimino@gmail.com)
   9970 
   9971 // Copyright 2012 Google Inc. All Rights Reserved.
   9972 //
   9973 // Use of this source code is governed by a BSD-style license
   9974 // that can be found in the COPYING file in the root of the source
   9975 // tree. An additional intellectual property rights grant can be found
   9976 // in the file PATENTS. All contributing project authors may
   9977 // be found in the AUTHORS file in the root of the source tree.
   9978 // -----------------------------------------------------------------------------
   9979 //
   9980 // Misc. common utility functions
   9981 //
   9982 // Authors: Skal (pascal.massimino@gmail.com)
   9983 //          Urvang (urvang@google.com)
   9984 
   9985 // Copyright 2010 Google Inc. All Rights Reserved.
   9986 //
   9987 // Use of this source code is governed by a BSD-style license
   9988 // that can be found in the COPYING file in the root of the source
   9989 // tree. An additional intellectual property rights grant can be found
   9990 // in the file PATENTS. All contributing project authors may
   9991 // be found in the AUTHORS file in the root of the source tree.
   9992 // -----------------------------------------------------------------------------
   9993 //
   9994 //  Main decoding functions for WebP images.
   9995 //
   9996 // Author: Skal (pascal.massimino@gmail.com)
   9997 
   9998 // Copyright 2012 Google Inc. All Rights Reserved.
   9999 //
  10000 // Use of this source code is governed by a BSD-style license
  10001 // that can be found in the COPYING file in the root of the source
  10002 // tree. An additional intellectual property rights grant can be found
  10003 // in the file PATENTS. All contributing project authors may
  10004 // be found in the AUTHORS file in the root of the source tree.
  10005 // -----------------------------------------------------------------------------
  10006 //
  10007 //  Internal header for constants related to WebP file format.
  10008 //
  10009 // Author: Urvang (urvang@google.com)
  10010 
  10011 // Copyright 2010 Google Inc. All Rights Reserved.
  10012 //
  10013 // Use of this source code is governed by a BSD-style license
  10014 // that can be found in the COPYING file in the root of the source
  10015 // tree. An additional intellectual property rights grant can be found
  10016 // in the file PATENTS. All contributing project authors may
  10017 // be found in the AUTHORS file in the root of the source tree.
  10018 // -----------------------------------------------------------------------------
  10019 //
  10020 //  Common types + memory wrappers
  10021 //
  10022 // Author: Skal (pascal.massimino@gmail.com)
  10023 
  10024 //------------------------------------------------------------------------------
  10025 
  10026 func WebPGetDecoderVersion(tls *libc.TLS) (r int32) {
  10027 	return libc.Int32FromInt32(DEC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(DEC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(DEC_REV_VERSION)
  10028 }
  10029 
  10030 //------------------------------------------------------------------------------
  10031 // Signature and pointer-to-function for GetCoeffs() variants below.
  10032 
  10033 type GetCoeffsFunc = uintptr
  10034 
  10035 var GetCoeffs = uintptr(0)
  10036 
  10037 func init() {
  10038 	p := unsafe.Pointer(&GetCoeffs)
  10039 	*(*uintptr)(unsafe.Add(p, 0)) = libc.UintptrFromInt32(0)
  10040 }
  10041 
  10042 //------------------------------------------------------------------------------
  10043 // VP8Decoder
  10044 
  10045 func SetOk(tls *libc.TLS, dec uintptr) {
  10046 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  10047 	(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = __ccgo_ts + 154
  10048 }
  10049 
  10050 func VP8InitIoInternal(tls *libc.TLS, io uintptr, version int32) (r int32) {
  10051 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  10052 		return 0 // mismatch error
  10053 	}
  10054 	if io != libc.UintptrFromInt32(0) {
  10055 		libc.Xmemset(tls, io, 0, uint64(160))
  10056 	}
  10057 	return int32(1)
  10058 }
  10059 
  10060 func VP8New(tls *libc.TLS) (r uintptr) {
  10061 	var dec uintptr
  10062 	_ = dec
  10063 	dec = WebPSafeCalloc(tls, uint64(1), uint64(3024))
  10064 	if dec != libc.UintptrFromInt32(0) {
  10065 		SetOk(tls, dec)
  10066 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, dec+152)
  10067 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10068 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = uint32(0)
  10069 		InitGetCoeffs(tls)
  10070 	}
  10071 	return dec
  10072 }
  10073 
  10074 func VP8Status(tls *libc.TLS, dec uintptr) (r VP8StatusCode1) {
  10075 	if !(dec != 0) {
  10076 		return int32(VP8_STATUS_INVALID_PARAM)
  10077 	}
  10078 	return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  10079 }
  10080 
  10081 func VP8StatusMessage(tls *libc.TLS, dec uintptr) (r uintptr) {
  10082 	if dec == libc.UintptrFromInt32(0) {
  10083 		return __ccgo_ts + 157
  10084 	}
  10085 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg != 0) {
  10086 		return __ccgo_ts + 154
  10087 	}
  10088 	return (*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg
  10089 }
  10090 
  10091 func VP8Delete(tls *libc.TLS, dec uintptr) {
  10092 	if dec != libc.UintptrFromInt32(0) {
  10093 		VP8Clear(tls, dec)
  10094 		WebPSafeFree(tls, dec)
  10095 	}
  10096 }
  10097 
  10098 func VP8SetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1, msg uintptr) (r int32) {
  10099 	// VP8_STATUS_SUSPENDED is only meaningful in incremental decoding.
  10100 	// The oldest error reported takes precedence over the new one.
  10101 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) {
  10102 		(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = error1
  10103 		(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = msg
  10104 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10105 	}
  10106 	return 0
  10107 }
  10108 
  10109 //------------------------------------------------------------------------------
  10110 
  10111 func VP8CheckSignature(tls *libc.TLS, data uintptr, data_size size_t) (r int32) {
  10112 	return libc.BoolInt32(data_size >= uint64(3) && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) == int32(0x9d) && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 1))) == int32(0x01) && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 2))) == int32(0x2a))
  10113 }
  10114 
  10115 func VP8GetInfo(tls *libc.TLS, data uintptr, data_size size_t, chunk_size size_t, width uintptr, height uintptr) (r int32) {
  10116 	var bits uint32_t
  10117 	var h, key_frame, w int32
  10118 	_, _, _, _ = bits, h, key_frame, w
  10119 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8_FRAME_HEADER_SIZE) {
  10120 		return 0 // not enough data
  10121 	}
  10122 	// check signature
  10123 	if !(VP8CheckSignature(tls, data+uintptr(3), data_size-uint64(3)) != 0) {
  10124 		return 0 // Wrong signature.
  10125 	} else {
  10126 		bits = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 1)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 2)))<<int32(16))
  10127 		key_frame = libc.BoolInt32(!(bits&libc.Uint32FromInt32(1) != 0))
  10128 		w = (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 7)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 6)))) & int32(0x3fff)
  10129 		h = (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 9)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 8)))) & int32(0x3fff)
  10130 		if !(key_frame != 0) { // Not a keyframe.
  10131 			return 0
  10132 		}
  10133 		if bits>>libc.Int32FromInt32(1)&uint32(7) > uint32(3) {
  10134 			return 0 // unknown profile
  10135 		}
  10136 		if !(bits>>libc.Int32FromInt32(4)&libc.Uint32FromInt32(1) != 0) {
  10137 			return 0 // first frame is invisible!
  10138 		}
  10139 		if uint64(bits>>libc.Int32FromInt32(5)) >= chunk_size { // partition_length
  10140 			return 0 // inconsistent size information.
  10141 		}
  10142 		if w == 0 || h == 0 {
  10143 			return 0 // We don't support both width and height to be zero.
  10144 		}
  10145 		if width != 0 {
  10146 			**(**int32)(__ccgo_up(width)) = w
  10147 		}
  10148 		if height != 0 {
  10149 			**(**int32)(__ccgo_up(height)) = h
  10150 		}
  10151 		return int32(1)
  10152 	}
  10153 	return r
  10154 }
  10155 
  10156 //------------------------------------------------------------------------------
  10157 // Header parsing
  10158 
  10159 func ResetSegmentHeader(tls *libc.TLS, hdr uintptr) {
  10160 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = 0
  10161 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10162 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = int32(1)
  10163 	libc.Xmemset(tls, hdr+12, 0, uint64(4))
  10164 	libc.Xmemset(tls, hdr+16, 0, uint64(4))
  10165 }
  10166 
  10167 // C documentation
  10168 //
  10169 //	// Paragraph 9.3
  10170 func ParseSegmentHeader(tls *libc.TLS, br uintptr, hdr uintptr, proba uintptr) (r int32) {
  10171 	var s, s1, v2 int32
  10172 	var v6 uint32
  10173 	_, _, _, _ = s, s1, v2, v6
  10174 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10175 	if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
  10176 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10177 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10178 			(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10179 			s = 0
  10180 			for {
  10181 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10182 					break
  10183 				}
  10184 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10185 					v2 = VP8GetSignedValue(tls, br, int32(7))
  10186 				} else {
  10187 					v2 = 0
  10188 				}
  10189 				**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(s))) = int8(v2)
  10190 				goto _1
  10191 			_1:
  10192 				;
  10193 				s = s + 1
  10194 			}
  10195 			s = 0
  10196 			for {
  10197 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10198 					break
  10199 				}
  10200 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10201 					v2 = VP8GetSignedValue(tls, br, int32(6))
  10202 				} else {
  10203 					v2 = 0
  10204 				}
  10205 				**(**int8_t)(__ccgo_up(hdr + 16 + uintptr(s))) = int8(v2)
  10206 				goto _3
  10207 			_3:
  10208 				;
  10209 				s = s + 1
  10210 			}
  10211 		}
  10212 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  10213 			s1 = 0
  10214 			for {
  10215 				if !(s1 < int32(MB_FEATURE_TREE_PROBS)) {
  10216 					break
  10217 				}
  10218 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10219 					v6 = VP8GetValue(tls, br, int32(8))
  10220 				} else {
  10221 					v6 = uint32(255)
  10222 				}
  10223 				**(**uint8_t)(__ccgo_up(proba + uintptr(s1))) = uint8(v6)
  10224 				goto _5
  10225 			_5:
  10226 				;
  10227 				s1 = s1 + 1
  10228 			}
  10229 		}
  10230 	} else {
  10231 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10232 	}
  10233 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10234 }
  10235 
  10236 // C documentation
  10237 //
  10238 //	// Paragraph 9.5
  10239 //	// If we don't have all the necessary data in 'buf', this function returns
  10240 //	// VP8_STATUS_SUSPENDED in incremental decoding, VP8_STATUS_NOT_ENOUGH_DATA
  10241 //	// otherwise.
  10242 //	// In incremental decoding, this case is not necessarily an error. Still, no
  10243 //	// bitreader is ever initialized to make it possible to read unavailable memory.
  10244 //	// If we don't even have the partitions' sizes, then VP8_STATUS_NOT_ENOUGH_DATA
  10245 //	// is returned, and this is an unrecoverable error.
  10246 //	// If the partitions were positioned ok, VP8_STATUS_OK is returned.
  10247 func ParsePartitions(tls *libc.TLS, dec uintptr, buf uintptr, size size_t) (r VP8StatusCode1) {
  10248 	var br, buf_end, part_start, sz uintptr
  10249 	var last_part, p, psize, size_left size_t
  10250 	var v2 int32
  10251 	_, _, _, _, _, _, _, _, _ = br, buf_end, last_part, p, part_start, psize, size_left, sz, v2
  10252 	br = dec + 16
  10253 	sz = buf
  10254 	buf_end = buf + uintptr(size)
  10255 	size_left = size
  10256 	(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = libc.Uint32FromInt32(int32(1)<<VP8GetValue(tls, br, int32(2)) - int32(1))
  10257 	last_part = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)
  10258 	if size < uint64(3)*last_part {
  10259 		// we can't even read the sizes with sz[]! That's a failure.
  10260 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10261 	}
  10262 	part_start = buf + uintptr(last_part*uint64(3))
  10263 	size_left = size_left - last_part*uint64(3)
  10264 	p = uint64(0)
  10265 	for {
  10266 		if !(p < last_part) {
  10267 			break
  10268 		}
  10269 		psize = libc.Uint64FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(sz))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(sz + 1)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(sz + 2)))<<int32(16))
  10270 		if psize > size_left {
  10271 			psize = size_left
  10272 		}
  10273 		VP8InitBitReader(tls, dec+440+uintptr(p)*48, part_start, psize)
  10274 		part_start = part_start + uintptr(psize)
  10275 		size_left = size_left - psize
  10276 		sz = sz + uintptr(3)
  10277 		goto _1
  10278 	_1:
  10279 		;
  10280 		p = p + 1
  10281 	}
  10282 	VP8InitBitReader(tls, dec+440+uintptr(last_part)*48, part_start, size_left)
  10283 	if part_start < buf_end {
  10284 		return int32(VP8_STATUS_OK)
  10285 	}
  10286 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  10287 		v2 = int32(VP8_STATUS_SUSPENDED)
  10288 	} else {
  10289 		v2 = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10290 	}
  10291 	return v2
  10292 }
  10293 
  10294 // C documentation
  10295 //
  10296 //	// Paragraph 9.4
  10297 func ParseFilterHeader(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
  10298 	var hdr uintptr
  10299 	var i, v3, v4 int32
  10300 	_, _, _, _ = hdr, i, v3, v4
  10301 	hdr = dec + 84
  10302 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10303 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel = libc.Int32FromUint32(VP8GetValue(tls, br, int32(6)))
  10304 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness = libc.Int32FromUint32(VP8GetValue(tls, br, int32(3)))
  10305 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10306 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
  10307 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10308 			i = 0
  10309 			for {
  10310 				if !(i < int32(NUM_REF_LF_DELTAS)) {
  10311 					break
  10312 				}
  10313 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10314 					**(**int32)(__ccgo_up(hdr + 16 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10315 				}
  10316 				goto _1
  10317 			_1:
  10318 				;
  10319 				i = i + 1
  10320 			}
  10321 			i = 0
  10322 			for {
  10323 				if !(i < int32(NUM_MODE_LF_DELTAS)) {
  10324 					break
  10325 				}
  10326 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10327 					**(**int32)(__ccgo_up(hdr + 32 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10328 				}
  10329 				goto _2
  10330 			_2:
  10331 				;
  10332 				i = i + 1
  10333 			}
  10334 		}
  10335 	}
  10336 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel == 0 {
  10337 		v3 = 0
  10338 	} else {
  10339 		if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple != 0 {
  10340 			v4 = int32(1)
  10341 		} else {
  10342 			v4 = int32(2)
  10343 		}
  10344 		v3 = v4
  10345 	}
  10346 	(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = v3
  10347 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10348 }
  10349 
  10350 // C documentation
  10351 //
  10352 //	// Topmost call
  10353 func VP8GetHeaders(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  10354 	var bits uint32_t
  10355 	var br, buf, frm_hdr, pic_hdr uintptr
  10356 	var buf_size size_t
  10357 	var status VP8StatusCode1
  10358 	_, _, _, _, _, _, _ = bits, br, buf, buf_size, frm_hdr, pic_hdr, status
  10359 	if dec == libc.UintptrFromInt32(0) {
  10360 		return 0
  10361 	}
  10362 	SetOk(tls, dec)
  10363 	if io == libc.UintptrFromInt32(0) {
  10364 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+167)
  10365 	}
  10366 	buf = (*VP8Io)(unsafe.Pointer(io)).Fdata
  10367 	buf_size = (*VP8Io)(unsafe.Pointer(io)).Fdata_size
  10368 	if buf_size < uint64(4) {
  10369 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+204)
  10370 	}
  10371 	// Paragraph 9.1
  10372 	bits = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 1)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 2)))<<int32(16))
  10373 	frm_hdr = dec + 68
  10374 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame = libc.BoolUint8(!(bits&libc.Uint32FromInt32(1) != 0))
  10375 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile = uint8(bits >> libc.Int32FromInt32(1) & uint32(7))
  10376 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow = uint8(bits >> libc.Int32FromInt32(4) & uint32(1))
  10377 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length = bits >> libc.Int32FromInt32(5)
  10378 	if libc.Int32FromUint8((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile) > int32(3) {
  10379 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+222)
  10380 	}
  10381 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow != 0) {
  10382 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+253)
  10383 	}
  10384 	buf = buf + uintptr(3)
  10385 	buf_size = buf_size - uint64(3)
  10386 	pic_hdr = dec + 76
  10387 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10388 		// Paragraph 9.2
  10389 		if buf_size < uint64(7) {
  10390 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+276)
  10391 		}
  10392 		if !(VP8CheckSignature(tls, buf, buf_size) != 0) {
  10393 			return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+304)
  10394 		}
  10395 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth = libc.Uint16FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 4)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 3)))) & int32(0x3fff))
  10396 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fxscale = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 4))) >> int32(6)) // ratio: 1, 5/4 5/3 or 2
  10397 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight = libc.Uint16FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 6)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 5)))) & int32(0x3fff))
  10398 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fyscale = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 6))) >> int32(6))
  10399 		buf = buf + uintptr(7)
  10400 		buf_size = buf_size - uint64(7)
  10401 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w = (libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth) + int32(15)) >> int32(4)
  10402 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h = (libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight) + int32(15)) >> int32(4)
  10403 		// Setup default output area (can be later modified during io->setup())
  10404 		(*VP8Io)(unsafe.Pointer(io)).Fwidth = libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth)
  10405 		(*VP8Io)(unsafe.Pointer(io)).Fheight = libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight)
  10406 		// IMPORTANT! use some sane dimensions in crop* and scaled* fields.
  10407 		// So they can be used interchangeably without always testing for
  10408 		// 'use_cropping'.
  10409 		(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = 0
  10410 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = 0
  10411 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = 0
  10412 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10413 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10414 		(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = 0
  10415 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10416 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10417 		(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fwidth  // for soundness
  10418 		(*VP8Io)(unsafe.Pointer(io)).Fmb_h = (*VP8Io)(unsafe.Pointer(io)).Fheight // ditto
  10419 		VP8ResetProba(tls, dec+1192)
  10420 		ResetSegmentHeader(tls, dec+132)
  10421 	}
  10422 	// Check if we have all the partition #0 available, and initialize dec->br
  10423 	// to read this partition (and this partition only).
  10424 	if uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length) > buf_size {
  10425 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+318)
  10426 	}
  10427 	br = dec + 16
  10428 	VP8InitBitReader(tls, br, buf, uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length))
  10429 	buf = buf + uintptr((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10430 	buf_size = buf_size - uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10431 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10432 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fcolorspace = uint8(VP8GetValue(tls, br, int32(1)))
  10433 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fclamp_type = uint8(VP8GetValue(tls, br, int32(1)))
  10434 	}
  10435 	if !(ParseSegmentHeader(tls, br, dec+132, dec+1192) != 0) {
  10436 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+339)
  10437 	}
  10438 	// Filter specs
  10439 	if !(ParseFilterHeader(tls, br, dec) != 0) {
  10440 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+367)
  10441 	}
  10442 	status = ParsePartitions(tls, dec, buf, buf_size)
  10443 	if status != int32(VP8_STATUS_OK) {
  10444 		return VP8SetError(tls, dec, status, __ccgo_ts+394)
  10445 	}
  10446 	// quantizer change
  10447 	VP8ParseQuant(tls, dec)
  10448 	// Frame buffer marking
  10449 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0) {
  10450 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+418)
  10451 	}
  10452 	VP8GetValue(tls, br, int32(1)) // ignore the value of 'update_proba'
  10453 	VP8ParseProba(tls, br, dec)
  10454 	// sanitized state
  10455 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = int32(1)
  10456 	return int32(1)
  10457 }
  10458 
  10459 //------------------------------------------------------------------------------
  10460 // Residual decoding (Paragraph 13.2 / 13.3)
  10461 
  10462 var kCat3 = [4]uint8_t{
  10463 	0: uint8(173),
  10464 	1: uint8(148),
  10465 	2: uint8(140),
  10466 }
  10467 var kCat4 = [5]uint8_t{
  10468 	0: uint8(176),
  10469 	1: uint8(155),
  10470 	2: uint8(140),
  10471 	3: uint8(135),
  10472 }
  10473 var kCat5 = [6]uint8_t{
  10474 	0: uint8(180),
  10475 	1: uint8(157),
  10476 	2: uint8(141),
  10477 	3: uint8(134),
  10478 	4: uint8(130),
  10479 }
  10480 var kCat6 = [12]uint8_t{
  10481 	0:  uint8(254),
  10482 	1:  uint8(254),
  10483 	2:  uint8(243),
  10484 	3:  uint8(230),
  10485 	4:  uint8(196),
  10486 	5:  uint8(177),
  10487 	6:  uint8(153),
  10488 	7:  uint8(140),
  10489 	8:  uint8(133),
  10490 	9:  uint8(130),
  10491 	10: uint8(129),
  10492 }
  10493 var kCat3456 = [4]uintptr{
  10494 	0: uintptr(unsafe.Pointer(&kCat3)),
  10495 	1: uintptr(unsafe.Pointer(&kCat4)),
  10496 	2: uintptr(unsafe.Pointer(&kCat5)),
  10497 	3: uintptr(unsafe.Pointer(&kCat6)),
  10498 }
  10499 var kZigzag = [16]uint8_t{
  10500 	1:  uint8(1),
  10501 	2:  uint8(4),
  10502 	3:  uint8(8),
  10503 	4:  uint8(5),
  10504 	5:  uint8(2),
  10505 	6:  uint8(3),
  10506 	7:  uint8(6),
  10507 	8:  uint8(9),
  10508 	9:  uint8(12),
  10509 	10: uint8(13),
  10510 	11: uint8(10),
  10511 	12: uint8(7),
  10512 	13: uint8(11),
  10513 	14: uint8(14),
  10514 	15: uint8(15),
  10515 }
  10516 
  10517 // C documentation
  10518 //
  10519 //	// See section 13-2: https://datatracker.ietf.org/doc/html/rfc6386#section-13.2
  10520 func GetLargeValue(tls *libc.TLS, br2 uintptr, p uintptr) (r int32) {
  10521 	bp := tls.Alloc(16)
  10522 	defer tls.Free(16)
  10523 	var bit, bit0, bit1, cat, pos, shift, v, v13, v15, v21, v23, v5, v7 int32
  10524 	var bits bit_t
  10525 	var range1, split, value range_t
  10526 	var tab, v1, v10, v17, v18, v2, v9 uintptr
  10527 	var v11, v19, v3 uint64_t
  10528 	var _ /* in_bits at bp+0 */ lbit_t
  10529 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bit0, bit1, bits, cat, pos, range1, shift, split, tab, v, value, v1, v10, v11, v13, v15, v17, v18, v19, v2, v21, v23, v3, v5, v7, v9
  10530 	v1 = br2
  10531 	range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10532 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10533 		v2 = v1
  10534 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10535 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10536 			**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10537 			v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10538 			goto _4
  10539 		_4:
  10540 			bits = v3
  10541 			bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10542 			(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10543 			**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10544 		} else {
  10545 			VP8LoadFinalBytes(tls, v2)
  10546 		}
  10547 	}
  10548 	pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10549 	split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 3)))) >> int32(8)
  10550 	value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10551 	bit = libc.BoolInt32(value > split)
  10552 	if bit != 0 {
  10553 		range1 = range1 - split
  10554 		**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10555 	} else {
  10556 		range1 = split + uint32(1)
  10557 	}
  10558 	v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10559 	goto _6
  10560 _6:
  10561 	shift = int32(7) ^ v5
  10562 	range1 = range1 << libc.Uint32FromInt32(shift)
  10563 	**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10564 	(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10565 	v7 = bit
  10566 	goto _8
  10567 _8:
  10568 	if !(v7 != 0) {
  10569 		v9 = br2
  10570 		range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10571 		if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10572 			v10 = v9
  10573 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10574 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10575 				**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10576 				v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10577 				goto _12
  10578 			_12:
  10579 				bits = v11
  10580 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10581 				(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  10582 				**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  10583 			} else {
  10584 				VP8LoadFinalBytes(tls, v10)
  10585 			}
  10586 		}
  10587 		pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  10588 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 4)))) >> int32(8)
  10589 		value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  10590 		bit = libc.BoolInt32(value > split)
  10591 		if bit != 0 {
  10592 			range1 = range1 - split
  10593 			**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10594 		} else {
  10595 			range1 = split + uint32(1)
  10596 		}
  10597 		v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10598 		goto _14
  10599 	_14:
  10600 		shift = int32(7) ^ v13
  10601 		range1 = range1 << libc.Uint32FromInt32(shift)
  10602 		**(**int32)(__ccgo_up(v9 + 12)) -= shift
  10603 		(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  10604 		v15 = bit
  10605 		goto _16
  10606 	_16:
  10607 		if !(v15 != 0) {
  10608 			v = int32(2)
  10609 		} else {
  10610 			v1 = br2
  10611 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10612 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10613 				v2 = v1
  10614 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10615 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10616 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10617 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10618 					goto _20
  10619 				_20:
  10620 					bits = v3
  10621 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10622 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10623 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10624 				} else {
  10625 					VP8LoadFinalBytes(tls, v2)
  10626 				}
  10627 			}
  10628 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10629 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 5)))) >> int32(8)
  10630 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10631 			bit = libc.BoolInt32(value > split)
  10632 			if bit != 0 {
  10633 				range1 = range1 - split
  10634 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10635 			} else {
  10636 				range1 = split + uint32(1)
  10637 			}
  10638 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10639 			goto _22
  10640 		_22:
  10641 			shift = int32(7) ^ v5
  10642 			range1 = range1 << libc.Uint32FromInt32(shift)
  10643 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10644 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10645 			v7 = bit
  10646 			goto _24
  10647 		_24:
  10648 			v = int32(3) + v7
  10649 		}
  10650 	} else {
  10651 		v1 = br2
  10652 		range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10653 		if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10654 			v2 = v1
  10655 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10656 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10657 				**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10658 				v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10659 				goto _28
  10660 			_28:
  10661 				bits = v3
  10662 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10663 				(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10664 				**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10665 			} else {
  10666 				VP8LoadFinalBytes(tls, v2)
  10667 			}
  10668 		}
  10669 		pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10670 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 6)))) >> int32(8)
  10671 		value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10672 		bit = libc.BoolInt32(value > split)
  10673 		if bit != 0 {
  10674 			range1 = range1 - split
  10675 			**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10676 		} else {
  10677 			range1 = split + uint32(1)
  10678 		}
  10679 		v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10680 		goto _30
  10681 	_30:
  10682 		shift = int32(7) ^ v5
  10683 		range1 = range1 << libc.Uint32FromInt32(shift)
  10684 		**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10685 		(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10686 		v7 = bit
  10687 		goto _32
  10688 	_32:
  10689 		if !(v7 != 0) {
  10690 			v9 = br2
  10691 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10692 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10693 				v10 = v9
  10694 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10695 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10696 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10697 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10698 					goto _36
  10699 				_36:
  10700 					bits = v11
  10701 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10702 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  10703 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  10704 				} else {
  10705 					VP8LoadFinalBytes(tls, v10)
  10706 				}
  10707 			}
  10708 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  10709 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 7)))) >> int32(8)
  10710 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  10711 			bit = libc.BoolInt32(value > split)
  10712 			if bit != 0 {
  10713 				range1 = range1 - split
  10714 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10715 			} else {
  10716 				range1 = split + uint32(1)
  10717 			}
  10718 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10719 			goto _38
  10720 		_38:
  10721 			shift = int32(7) ^ v13
  10722 			range1 = range1 << libc.Uint32FromInt32(shift)
  10723 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  10724 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  10725 			v15 = bit
  10726 			goto _40
  10727 		_40:
  10728 			if !(v15 != 0) {
  10729 				v17 = br2
  10730 				range1 = (*VP8BitReader)(unsafe.Pointer(v17)).Frange1
  10731 				if (*VP8BitReader)(unsafe.Pointer(v17)).Fbits < libc.Int32FromInt32(0) {
  10732 					v18 = v17
  10733 					if (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf_max {
  10734 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf, uint64(8))
  10735 						**(**uintptr)(__ccgo_up(v18 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10736 						v19 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10737 						goto _44
  10738 					_44:
  10739 						bits = v19
  10740 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10741 						(*VP8BitReader)(unsafe.Pointer(v18)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v18)).Fvalue<<libc.Int32FromInt32(BITS)
  10742 						**(**int32)(__ccgo_up(v18 + 12)) += int32(BITS)
  10743 					} else {
  10744 						VP8LoadFinalBytes(tls, v18)
  10745 					}
  10746 				}
  10747 				pos = (*VP8BitReader)(unsafe.Pointer(v17)).Fbits
  10748 				split = range1 * libc.Uint32FromInt32(int32(159)) >> int32(8)
  10749 				value = uint32((*VP8BitReader)(unsafe.Pointer(v17)).Fvalue >> pos)
  10750 				bit = libc.BoolInt32(value > split)
  10751 				if bit != 0 {
  10752 					range1 = range1 - split
  10753 					**(**bit_t)(__ccgo_up(v17)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10754 				} else {
  10755 					range1 = split + uint32(1)
  10756 				}
  10757 				v21 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10758 				goto _46
  10759 			_46:
  10760 				shift = int32(7) ^ v21
  10761 				range1 = range1 << libc.Uint32FromInt32(shift)
  10762 				**(**int32)(__ccgo_up(v17 + 12)) -= shift
  10763 				(*VP8BitReader)(unsafe.Pointer(v17)).Frange1 = range1 - uint32(1)
  10764 				v23 = bit
  10765 				goto _48
  10766 			_48:
  10767 				v = int32(5) + v23
  10768 			} else {
  10769 				v1 = br2
  10770 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10771 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10772 					v2 = v1
  10773 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10774 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10775 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10776 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10777 						goto _52
  10778 					_52:
  10779 						bits = v3
  10780 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10781 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10782 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10783 					} else {
  10784 						VP8LoadFinalBytes(tls, v2)
  10785 					}
  10786 				}
  10787 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10788 				split = range1 * libc.Uint32FromInt32(int32(165)) >> int32(8)
  10789 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10790 				bit = libc.BoolInt32(value > split)
  10791 				if bit != 0 {
  10792 					range1 = range1 - split
  10793 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10794 				} else {
  10795 					range1 = split + uint32(1)
  10796 				}
  10797 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10798 				goto _54
  10799 			_54:
  10800 				shift = int32(7) ^ v5
  10801 				range1 = range1 << libc.Uint32FromInt32(shift)
  10802 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10803 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10804 				v7 = bit
  10805 				goto _56
  10806 			_56:
  10807 				v = int32(7) + int32(2)*v7
  10808 				v1 = br2
  10809 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10810 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10811 					v2 = v1
  10812 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10813 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10814 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10815 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10816 						goto _60
  10817 					_60:
  10818 						bits = v3
  10819 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10820 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10821 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10822 					} else {
  10823 						VP8LoadFinalBytes(tls, v2)
  10824 					}
  10825 				}
  10826 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10827 				split = range1 * libc.Uint32FromInt32(int32(145)) >> int32(8)
  10828 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10829 				bit = libc.BoolInt32(value > split)
  10830 				if bit != 0 {
  10831 					range1 = range1 - split
  10832 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10833 				} else {
  10834 					range1 = split + uint32(1)
  10835 				}
  10836 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10837 				goto _62
  10838 			_62:
  10839 				shift = int32(7) ^ v5
  10840 				range1 = range1 << libc.Uint32FromInt32(shift)
  10841 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10842 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10843 				v7 = bit
  10844 				goto _64
  10845 			_64:
  10846 				v = v + v7
  10847 			}
  10848 		} else {
  10849 			v1 = br2
  10850 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10851 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10852 				v2 = v1
  10853 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10854 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10855 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10856 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10857 					goto _68
  10858 				_68:
  10859 					bits = v3
  10860 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10861 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10862 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10863 				} else {
  10864 					VP8LoadFinalBytes(tls, v2)
  10865 				}
  10866 			}
  10867 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10868 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8)))) >> int32(8)
  10869 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10870 			bit = libc.BoolInt32(value > split)
  10871 			if bit != 0 {
  10872 				range1 = range1 - split
  10873 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10874 			} else {
  10875 				range1 = split + uint32(1)
  10876 			}
  10877 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10878 			goto _70
  10879 		_70:
  10880 			shift = int32(7) ^ v5
  10881 			range1 = range1 << libc.Uint32FromInt32(shift)
  10882 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10883 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10884 			v7 = bit
  10885 			goto _72
  10886 		_72:
  10887 			bit1 = v7
  10888 			v9 = br2
  10889 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10890 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10891 				v10 = v9
  10892 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10893 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10894 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10895 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10896 					goto _76
  10897 				_76:
  10898 					bits = v11
  10899 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10900 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  10901 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  10902 				} else {
  10903 					VP8LoadFinalBytes(tls, v10)
  10904 				}
  10905 			}
  10906 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  10907 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(9)+bit1))))) >> int32(8)
  10908 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  10909 			bit = libc.BoolInt32(value > split)
  10910 			if bit != 0 {
  10911 				range1 = range1 - split
  10912 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10913 			} else {
  10914 				range1 = split + uint32(1)
  10915 			}
  10916 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10917 			goto _78
  10918 		_78:
  10919 			shift = int32(7) ^ v13
  10920 			range1 = range1 << libc.Uint32FromInt32(shift)
  10921 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  10922 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  10923 			v15 = bit
  10924 			goto _80
  10925 		_80:
  10926 			bit0 = v15
  10927 			cat = int32(2)*bit1 + bit0
  10928 			v = 0
  10929 			tab = kCat3456[cat]
  10930 			for {
  10931 				if !(**(**uint8_t)(__ccgo_up(tab)) != 0) {
  10932 					break
  10933 				}
  10934 				v1 = br2
  10935 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10936 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10937 					v2 = v1
  10938 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10939 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10940 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10941 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10942 						goto _85
  10943 					_85:
  10944 						bits = v3
  10945 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10946 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10947 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10948 					} else {
  10949 						VP8LoadFinalBytes(tls, v2)
  10950 					}
  10951 				}
  10952 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10953 				split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(tab)))) >> int32(8)
  10954 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10955 				bit = libc.BoolInt32(value > split)
  10956 				if bit != 0 {
  10957 					range1 = range1 - split
  10958 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10959 				} else {
  10960 					range1 = split + uint32(1)
  10961 				}
  10962 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10963 				goto _87
  10964 			_87:
  10965 				shift = int32(7) ^ v5
  10966 				range1 = range1 << libc.Uint32FromInt32(shift)
  10967 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10968 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10969 				v7 = bit
  10970 				goto _89
  10971 			_89:
  10972 				v = v + (v + v7)
  10973 				goto _81
  10974 			_81:
  10975 				;
  10976 				tab = tab + 1
  10977 			}
  10978 			v = v + (int32(3) + int32(8)<<cat)
  10979 		}
  10980 	}
  10981 	return v
  10982 }
  10983 
  10984 // C documentation
  10985 //
  10986 //	// Returns the position of the last non-zero coeff plus one
  10987 func GetCoeffsFast(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n1 int32, out uintptr) (r int32) {
  10988 	bp := tls.Alloc(16)
  10989 	defer tls.Free(16)
  10990 	var bit, pos, pos1, shift, v1, v14, v6, v8 int32
  10991 	var bits bit_t
  10992 	var mask int32_t
  10993 	var p, p_ctx, v2, v3 uintptr
  10994 	var range1, split, split1, value, value1 range_t
  10995 	var v4 uint64_t
  10996 	var _ /* in_bits at bp+0 */ lbit_t
  10997 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v14, v2, v3, v4, v6, v8
  10998 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1)*8)) + uintptr(ctx)*11
  10999 	for {
  11000 		if !(n1 < int32(16)) {
  11001 			break
  11002 		}
  11003 		v2 = br3
  11004 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11005 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11006 			v3 = v2
  11007 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11008 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11009 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11010 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11011 				goto _5
  11012 			_5:
  11013 				bits = v4
  11014 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11015 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11016 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11017 			} else {
  11018 				VP8LoadFinalBytes(tls, v3)
  11019 			}
  11020 		}
  11021 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11022 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11023 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11024 		bit = libc.BoolInt32(value > split)
  11025 		if bit != 0 {
  11026 			range1 = range1 - split
  11027 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11028 		} else {
  11029 			range1 = split + uint32(1)
  11030 		}
  11031 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11032 		goto _7
  11033 	_7:
  11034 		shift = int32(7) ^ v6
  11035 		range1 = range1 << libc.Uint32FromInt32(shift)
  11036 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11037 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11038 		v8 = bit
  11039 		goto _9
  11040 	_9:
  11041 		if !(v8 != 0) {
  11042 			return n1 // previous coeff was last non-zero coeff
  11043 		}
  11044 		for {
  11045 			v2 = br3
  11046 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11047 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11048 				v3 = v2
  11049 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11050 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11051 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11052 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11053 					goto _13
  11054 				_13:
  11055 					bits = v4
  11056 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11057 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11058 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11059 				} else {
  11060 					VP8LoadFinalBytes(tls, v3)
  11061 				}
  11062 			}
  11063 			pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11064 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11065 			value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11066 			bit = libc.BoolInt32(value > split)
  11067 			if bit != 0 {
  11068 				range1 = range1 - split
  11069 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11070 			} else {
  11071 				range1 = split + uint32(1)
  11072 			}
  11073 			v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11074 			goto _15
  11075 		_15:
  11076 			shift = int32(7) ^ v6
  11077 			range1 = range1 << libc.Uint32FromInt32(shift)
  11078 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11079 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11080 			v8 = bit
  11081 			goto _17
  11082 		_17:
  11083 			if !!(v8 != 0) {
  11084 				break
  11085 			} // sequence of zero coeffs
  11086 			n1 = n1 + 1
  11087 			v14 = n1
  11088 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v14)*8))
  11089 			if n1 == int32(16) {
  11090 				return int32(16)
  11091 			}
  11092 		}
  11093 		// non zero coeff
  11094 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1+int32(1))*8))
  11095 		v2 = br3
  11096 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11097 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11098 			v3 = v2
  11099 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11100 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11101 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11102 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11103 				goto _22
  11104 			_22:
  11105 				bits = v4
  11106 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11107 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11108 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11109 			} else {
  11110 				VP8LoadFinalBytes(tls, v3)
  11111 			}
  11112 		}
  11113 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11114 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11115 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11116 		bit = libc.BoolInt32(value > split)
  11117 		if bit != 0 {
  11118 			range1 = range1 - split
  11119 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11120 		} else {
  11121 			range1 = split + uint32(1)
  11122 		}
  11123 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11124 		goto _24
  11125 	_24:
  11126 		shift = int32(7) ^ v6
  11127 		range1 = range1 << libc.Uint32FromInt32(shift)
  11128 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11129 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11130 		v8 = bit
  11131 		goto _26
  11132 	_26:
  11133 		if !(v8 != 0) {
  11134 			v1 = int32(1)
  11135 			p = p_ctx + 1*11
  11136 		} else {
  11137 			v1 = GetLargeValue(tls, br3, p)
  11138 			p = p_ctx + 2*11
  11139 		}
  11140 		v2 = br3
  11141 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11142 			v3 = v2
  11143 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11144 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11145 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11146 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11147 				goto _30
  11148 			_30:
  11149 				bits = v4
  11150 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11151 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11152 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11153 			} else {
  11154 				VP8LoadFinalBytes(tls, v3)
  11155 			}
  11156 		}
  11157 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11158 		split1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11159 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11160 		mask = libc.Int32FromUint32(split1-value1) >> int32(31)
  11161 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11162 		**(**range_t)(__ccgo_up(v2 + 8)) += libc.Uint32FromInt32(mask)
  11163 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11164 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split1+libc.Uint32FromInt32(1))&libc.Uint32FromInt32(mask)) << pos1
  11165 		v6 = v1 ^ mask - mask
  11166 		goto _32
  11167 	_32:
  11168 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n1])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n1 > 0)*4)))
  11169 		goto _1
  11170 	_1:
  11171 		;
  11172 		n1 = n1 + 1
  11173 	}
  11174 	return int32(16)
  11175 }
  11176 
  11177 // C documentation
  11178 //
  11179 //	// This version of GetCoeffs() uses VP8GetBitAlt() which is an alternate version
  11180 //	// of VP8GetBitAlt() targeting specific platforms.
  11181 func GetCoeffsAlt(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n int32, out uintptr) (r int32) {
  11182 	bp := tls.Alloc(16)
  11183 	defer tls.Free(16)
  11184 	var bit, pos, pos1, shift, v1, v12, v6 int32
  11185 	var bits bit_t
  11186 	var mask int32_t
  11187 	var p, p_ctx, v2, v3 uintptr
  11188 	var range1, split, split1, value, value1 range_t
  11189 	var v4 uint64_t
  11190 	var _ /* in_bits at bp+0 */ lbit_t
  11191 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v12, v2, v3, v4, v6
  11192 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n)*8)) + uintptr(ctx)*11
  11193 	for {
  11194 		if !(n < int32(16)) {
  11195 			break
  11196 		}
  11197 		v2 = br3
  11198 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11199 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11200 			v3 = v2
  11201 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11202 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11203 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11204 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11205 				goto _5
  11206 			_5:
  11207 				bits = v4
  11208 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11209 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11210 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11211 			} else {
  11212 				VP8LoadFinalBytes(tls, v3)
  11213 			}
  11214 		}
  11215 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11216 		split1 = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11217 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11218 		if value1 > split1 {
  11219 			range1 = range1 - (split1 + uint32(1))
  11220 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11221 			bit = int32(1)
  11222 		} else {
  11223 			range1 = split1
  11224 			bit = 0
  11225 		}
  11226 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11227 			shift = libc.Int32FromUint8(kVP8Log2Range[range1])
  11228 			range1 = uint32(kVP8NewRange[range1])
  11229 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11230 		}
  11231 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11232 		v6 = bit
  11233 		goto _7
  11234 	_7:
  11235 		if !(v6 != 0) {
  11236 			return n // previous coeff was last non-zero coeff
  11237 		}
  11238 		for {
  11239 			v2 = br3
  11240 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11241 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11242 				v3 = v2
  11243 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11244 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11245 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11246 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11247 					goto _11
  11248 				_11:
  11249 					bits = v4
  11250 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11251 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11252 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11253 				} else {
  11254 					VP8LoadFinalBytes(tls, v3)
  11255 				}
  11256 			}
  11257 			pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11258 			split1 = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11259 			value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11260 			if value1 > split1 {
  11261 				range1 = range1 - (split1 + uint32(1))
  11262 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11263 				bit = int32(1)
  11264 			} else {
  11265 				range1 = split1
  11266 				bit = 0
  11267 			}
  11268 			if range1 <= libc.Uint32FromInt32(0x7e) {
  11269 				shift = libc.Int32FromUint8(kVP8Log2Range[range1])
  11270 				range1 = uint32(kVP8NewRange[range1])
  11271 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11272 			}
  11273 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11274 			v6 = bit
  11275 			goto _13
  11276 		_13:
  11277 			if !!(v6 != 0) {
  11278 				break
  11279 			} // sequence of zero coeffs
  11280 			n = n + 1
  11281 			v12 = n
  11282 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v12)*8))
  11283 			if n == int32(16) {
  11284 				return int32(16)
  11285 			}
  11286 		}
  11287 		// non zero coeff
  11288 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n+int32(1))*8))
  11289 		v2 = br3
  11290 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11291 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11292 			v3 = v2
  11293 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11294 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11295 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11296 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11297 				goto _18
  11298 			_18:
  11299 				bits = v4
  11300 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11301 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11302 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11303 			} else {
  11304 				VP8LoadFinalBytes(tls, v3)
  11305 			}
  11306 		}
  11307 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11308 		split1 = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11309 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11310 		if value1 > split1 {
  11311 			range1 = range1 - (split1 + uint32(1))
  11312 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11313 			bit = int32(1)
  11314 		} else {
  11315 			range1 = split1
  11316 			bit = 0
  11317 		}
  11318 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11319 			shift = libc.Int32FromUint8(kVP8Log2Range[range1])
  11320 			range1 = uint32(kVP8NewRange[range1])
  11321 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11322 		}
  11323 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11324 		v6 = bit
  11325 		goto _20
  11326 	_20:
  11327 		if !(v6 != 0) {
  11328 			v1 = int32(1)
  11329 			p = p_ctx + 1*11
  11330 		} else {
  11331 			v1 = GetLargeValue(tls, br3, p)
  11332 			p = p_ctx + 2*11
  11333 		}
  11334 		v2 = br3
  11335 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11336 			v3 = v2
  11337 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11338 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11339 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11340 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11341 				goto _24
  11342 			_24:
  11343 				bits = v4
  11344 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11345 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11346 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11347 			} else {
  11348 				VP8LoadFinalBytes(tls, v3)
  11349 			}
  11350 		}
  11351 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11352 		split = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11353 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11354 		mask = libc.Int32FromUint32(split-value) >> int32(31)
  11355 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11356 		**(**range_t)(__ccgo_up(v2 + 8)) += libc.Uint32FromInt32(mask)
  11357 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11358 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split+libc.Uint32FromInt32(1))&libc.Uint32FromInt32(mask)) << pos
  11359 		v6 = v1 ^ mask - mask
  11360 		goto _26
  11361 	_26:
  11362 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n > 0)*4)))
  11363 		goto _1
  11364 	_1:
  11365 		;
  11366 		n = n + 1
  11367 	}
  11368 	return int32(16)
  11369 }
  11370 
  11371 func InitGetCoeffs(tls *libc.TLS) {
  11372 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  11373 		goto _1
  11374 	}
  11375 	InitGetCoeffs_body(tls)
  11376 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)), VP8GetCPUInfo)
  11377 	goto _2
  11378 _2:
  11379 	;
  11380 	goto _1
  11381 _1: /**/ //
  11382 }
  11383 
  11384 var InitGetCoeffs_body_last_cpuinfo_used = uintptr(0)
  11385 
  11386 func init() {
  11387 	p := unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)
  11388 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))
  11389 }
  11390 
  11391 func InitGetCoeffs_body(tls *libc.TLS) {
  11392 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) && (*(*func(*libc.TLS, CPUFeature) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetCPUInfo})))(tls, int32(kSlowSSSE3)) != 0 {
  11393 		GetCoeffs = __ccgo_fp(GetCoeffsAlt)
  11394 	} else {
  11395 		GetCoeffs = __ccgo_fp(GetCoeffsFast)
  11396 	}
  11397 }
  11398 
  11399 func NzCodeBits(tls *libc.TLS, nz_coeffs uint32_t, nz int32, dc_nz int32) (r uint32_t) {
  11400 	var v1, v2 int32
  11401 	_, _ = v1, v2
  11402 	nz_coeffs = nz_coeffs << uint32(2)
  11403 	if nz > int32(3) {
  11404 		v1 = int32(3)
  11405 	} else {
  11406 		if nz > int32(1) {
  11407 			v2 = int32(2)
  11408 		} else {
  11409 			v2 = dc_nz
  11410 		}
  11411 		v1 = v2
  11412 	}
  11413 	nz_coeffs = nz_coeffs | libc.Uint32FromInt32(v1)
  11414 	return nz_coeffs
  11415 }
  11416 
  11417 func ParseResiduals(tls *libc.TLS, dec uintptr, mb uintptr, token_br uintptr) (r int32) {
  11418 	bp := tls.Alloc(32)
  11419 	defer tls.Free(32)
  11420 	var ac_proba, bands, block, dst, left_mb, q uintptr
  11421 	var ch, ctx, ctx1, ctx2, dc0, first, i, l, l1, nz, nz1, nz2, x, y, v8 int32
  11422 	var lnz, tnz, v1 uint8_t
  11423 	var non_zero_uv, non_zero_y, nz_coeffs, nz_coeffs1, out_l_nz, out_t_nz uint32_t
  11424 	var _ /* dc at bp+0 */ [16]int16_t
  11425 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ac_proba, bands, block, ch, ctx, ctx1, ctx2, dc0, dst, first, i, l, l1, left_mb, lnz, non_zero_uv, non_zero_y, nz, nz1, nz2, nz_coeffs, nz_coeffs1, out_l_nz, out_t_nz, q, tnz, x, y, v1, v8
  11426 	bands = dec + 1192 + 1064
  11427 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11428 	q = dec + 1060 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*32
  11429 	dst = block
  11430 	left_mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11431 	non_zero_y = uint32(0)
  11432 	non_zero_uv = uint32(0)
  11433 	libc.Xmemset(tls, dst, 0, libc.Uint64FromInt32(384)*libc.Uint64FromInt64(2))
  11434 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) { // parse DC
  11435 		**(**[16]int16_t)(__ccgo_up(bp)) = [16]int16_t{}
  11436 		ctx = libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(mb)).Fnz_dc) + libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc)
  11437 		nz = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{GetCoeffs})))(tls, token_br, bands+1*136, ctx, q+8, 0, bp)
  11438 		v1 = libc.BoolUint8(nz > libc.Int32FromInt32(0))
  11439 		(*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc = v1
  11440 		(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v1
  11441 		if nz > int32(1) { // more than just the DC -> perform the full transform
  11442 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp, dst)
  11443 		} else {
  11444 			dc0 = (int32((**(**[16]int16_t)(__ccgo_up(bp)))[0]) + int32(3)) >> int32(3)
  11445 			i = 0
  11446 			for {
  11447 				if !(i < libc.Int32FromInt32(16)*libc.Int32FromInt32(16)) {
  11448 					break
  11449 				}
  11450 				**(**int16_t)(__ccgo_up(dst + uintptr(i)*2)) = int16(dc0)
  11451 				goto _2
  11452 			_2:
  11453 				;
  11454 				i = i + int32(16)
  11455 			}
  11456 		}
  11457 		first = int32(1)
  11458 		ac_proba = bands
  11459 	} else {
  11460 		first = 0
  11461 		ac_proba = bands + 3*136
  11462 	}
  11463 	tnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(mb)).Fnz) & int32(0x0f))
  11464 	lnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) & int32(0x0f))
  11465 	y = 0
  11466 	for {
  11467 		if !(y < int32(4)) {
  11468 			break
  11469 		}
  11470 		l = libc.Int32FromUint8(lnz) & int32(1)
  11471 		nz_coeffs = uint32(0)
  11472 		x = 0
  11473 		for {
  11474 			if !(x < int32(4)) {
  11475 				break
  11476 			}
  11477 			ctx1 = l + libc.Int32FromUint8(tnz)&int32(1)
  11478 			nz1 = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{GetCoeffs})))(tls, token_br, ac_proba, ctx1, q, first, dst)
  11479 			l = libc.BoolInt32(nz1 > first)
  11480 			tnz = libc.Uint8FromInt32(libc.Int32FromUint8(tnz)>>int32(1) | l<<int32(7))
  11481 			nz_coeffs = NzCodeBits(tls, nz_coeffs, nz1, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11482 			dst = dst + uintptr(16)*2
  11483 			goto _4
  11484 		_4:
  11485 			;
  11486 			x = x + 1
  11487 		}
  11488 		tnz = libc.Uint8FromInt32(int32(tnz) >> libc.Int32FromInt32(4))
  11489 		lnz = libc.Uint8FromInt32(libc.Int32FromUint8(lnz)>>int32(1) | l<<int32(7))
  11490 		non_zero_y = non_zero_y<<libc.Int32FromInt32(8) | nz_coeffs
  11491 		goto _3
  11492 	_3:
  11493 		;
  11494 		y = y + 1
  11495 	}
  11496 	out_t_nz = uint32(tnz)
  11497 	out_l_nz = libc.Uint32FromInt32(libc.Int32FromUint8(lnz) >> int32(4))
  11498 	ch = 0
  11499 	for {
  11500 		if !(ch < int32(4)) {
  11501 			break
  11502 		}
  11503 		nz_coeffs1 = uint32(0)
  11504 		tnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(mb)).Fnz) >> (int32(4) + ch))
  11505 		lnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) >> (int32(4) + ch))
  11506 		y = 0
  11507 		for {
  11508 			if !(y < int32(2)) {
  11509 				break
  11510 			}
  11511 			l1 = libc.Int32FromUint8(lnz) & int32(1)
  11512 			x = 0
  11513 			for {
  11514 				if !(x < int32(2)) {
  11515 					break
  11516 				}
  11517 				ctx2 = l1 + libc.Int32FromUint8(tnz)&int32(1)
  11518 				nz2 = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{GetCoeffs})))(tls, token_br, bands+2*136, ctx2, q+16, 0, dst)
  11519 				l1 = libc.BoolInt32(nz2 > 0)
  11520 				tnz = libc.Uint8FromInt32(libc.Int32FromUint8(tnz)>>int32(1) | l1<<int32(3))
  11521 				nz_coeffs1 = NzCodeBits(tls, nz_coeffs1, nz2, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11522 				dst = dst + uintptr(16)*2
  11523 				goto _7
  11524 			_7:
  11525 				;
  11526 				x = x + 1
  11527 			}
  11528 			tnz = libc.Uint8FromInt32(int32(tnz) >> libc.Int32FromInt32(2))
  11529 			lnz = libc.Uint8FromInt32(libc.Int32FromUint8(lnz)>>int32(1) | l1<<int32(5))
  11530 			goto _6
  11531 		_6:
  11532 			;
  11533 			y = y + 1
  11534 		}
  11535 		// Note: we don't really need the per-4x4 details for U/V blocks.
  11536 		non_zero_uv = non_zero_uv | nz_coeffs1<<(int32(4)*ch)
  11537 		out_t_nz = out_t_nz | libc.Uint32FromInt32(libc.Int32FromUint8(tnz)<<int32(4)<<ch)
  11538 		out_l_nz = out_l_nz | libc.Uint32FromInt32(libc.Int32FromUint8(lnz)&int32(0xf0)<<ch)
  11539 		goto _5
  11540 	_5:
  11541 		;
  11542 		ch = ch + int32(2)
  11543 	}
  11544 	(*VP8MB)(unsafe.Pointer(mb)).Fnz = uint8(out_t_nz)
  11545 	(*VP8MB)(unsafe.Pointer(left_mb)).Fnz = uint8(out_l_nz)
  11546 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = non_zero_y
  11547 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = non_zero_uv
  11548 	// We look at the mode-code of each block and check if some blocks have less
  11549 	// than three non-zero coeffs (code < 2). This is to avoid dithering flat and
  11550 	// empty blocks.
  11551 	if non_zero_uv&uint32(0xaaaa) != 0 {
  11552 		v8 = 0
  11553 	} else {
  11554 		v8 = (*VP8QuantMatrix)(unsafe.Pointer(q)).Fdither
  11555 	}
  11556 	(*VP8MBData)(unsafe.Pointer(block)).Fdither = libc.Uint8FromInt32(v8)
  11557 	return libc.BoolInt32(!(non_zero_y|non_zero_uv != 0)) // will be used for further optimization
  11558 }
  11559 
  11560 //------------------------------------------------------------------------------
  11561 // Main loop
  11562 
  11563 func VP8DecodeMB(tls *libc.TLS, dec uintptr, token_br uintptr) (r int32) {
  11564 	var block, finfo, left, mb, v4 uintptr
  11565 	var skip, v1 int32
  11566 	var v2 uint8_t
  11567 	_, _, _, _, _, _, _, _ = block, finfo, left, mb, skip, v1, v2, v4
  11568 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11569 	mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2
  11570 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11571 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  11572 		v1 = libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(block)).Fskip)
  11573 	} else {
  11574 		v1 = 0
  11575 	}
  11576 	skip = v1
  11577 	if !(skip != 0) {
  11578 		skip = ParseResiduals(tls, dec, mb, token_br)
  11579 	} else {
  11580 		v2 = libc.Uint8FromInt32(0)
  11581 		(*VP8MB)(unsafe.Pointer(mb)).Fnz = v2
  11582 		(*VP8MB)(unsafe.Pointer(left)).Fnz = v2
  11583 		if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
  11584 			v2 = libc.Uint8FromInt32(0)
  11585 			(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v2
  11586 			(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = v2
  11587 		}
  11588 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = uint32(0)
  11589 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = uint32(0)
  11590 		(*VP8MBData)(unsafe.Pointer(block)).Fdither = uint8(0)
  11591 	}
  11592 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 { // store filter info
  11593 		finfo = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*4
  11594 		**(**VP8FInfo)(__ccgo_up(finfo)) = **(**VP8FInfo)(__ccgo_up(dec + 2924 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*8 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4)*4))
  11595 		v4 = finfo + 2
  11596 		*(*uint8_t)(unsafe.Pointer(v4)) = uint8_t(int32(*(*uint8_t)(unsafe.Pointer(v4))) | libc.BoolInt32(!(skip != 0)))
  11597 	}
  11598 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(token_br)).Feof != 0))
  11599 }
  11600 
  11601 func VP8InitScanline(tls *libc.TLS, dec uintptr) {
  11602 	var left uintptr
  11603 	_ = left
  11604 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11605 	(*VP8MB)(unsafe.Pointer(left)).Fnz = uint8(0)
  11606 	(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = uint8(0)
  11607 	libc.Xmemset(tls, dec+2816, int32(B_DC_PRED), uint64(4))
  11608 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = 0
  11609 }
  11610 
  11611 func ParseFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11612 	var token_br uintptr
  11613 	_ = token_br
  11614 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = 0
  11615 	for {
  11616 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y) {
  11617 			break
  11618 		}
  11619 		// Parse bitstream for this row.
  11620 		token_br = dec + 440 + uintptr(libc.Uint32FromInt32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
  11621 		if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
  11622 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+435)
  11623 		}
  11624 		for {
  11625 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
  11626 				break
  11627 			}
  11628 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
  11629 				return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+476)
  11630 			}
  11631 			goto _2
  11632 		_2:
  11633 			;
  11634 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
  11635 		}
  11636 		VP8InitScanline(tls, dec) // Prepare for next scanline
  11637 		// Reconstruct, filter and emit the row.
  11638 		if !(VP8ProcessRow(tls, dec, io) != 0) {
  11639 			return VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+511)
  11640 		}
  11641 		goto _1
  11642 	_1:
  11643 		;
  11644 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
  11645 	}
  11646 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
  11647 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
  11648 			return 0
  11649 		}
  11650 	}
  11651 	return int32(1)
  11652 }
  11653 
  11654 // C documentation
  11655 //
  11656 //	// Main entry point
  11657 func VP8Decode(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11658 	var ok int32
  11659 	_ = ok
  11660 	ok = 0
  11661 	if dec == libc.UintptrFromInt32(0) {
  11662 		return 0
  11663 	}
  11664 	if io == libc.UintptrFromInt32(0) {
  11665 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+527)
  11666 	}
  11667 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
  11668 		if !(VP8GetHeaders(tls, dec, io) != 0) {
  11669 			return 0
  11670 		}
  11671 	}
  11672 	// Finish setting up the decoding parameter. Will call io->setup().
  11673 	ok = libc.BoolInt32(VP8EnterCritical(tls, dec, io) == int32(VP8_STATUS_OK))
  11674 	if ok != 0 { // good to go.
  11675 		// Will allocate memory and prepare everything.
  11676 		if ok != 0 {
  11677 			ok = VP8InitFrame(tls, dec, io)
  11678 		}
  11679 		// Main decoding loop
  11680 		if ok != 0 {
  11681 			ok = ParseFrame(tls, dec, io)
  11682 		}
  11683 		// Exit.
  11684 		ok = ok & VP8ExitCritical(tls, dec, io)
  11685 	}
  11686 	if !(ok != 0) {
  11687 		VP8Clear(tls, dec)
  11688 		return 0
  11689 	}
  11690 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  11691 	return ok
  11692 }
  11693 
  11694 func VP8Clear(tls *libc.TLS, dec uintptr) {
  11695 	if dec == libc.UintptrFromInt32(0) {
  11696 		return
  11697 	}
  11698 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, dec+152)
  11699 	WebPDeallocateAlphaMemory(tls, dec)
  11700 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
  11701 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = libc.UintptrFromInt32(0)
  11702 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
  11703 	libc.Xmemset(tls, dec+16, 0, uint64(48))
  11704 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  11705 }
  11706 
  11707 const APPROX_LOG_MAX = 4096
  11708 const APPROX_LOG_WITH_CORRECTION_MAX = 65536
  11709 const BITS_SPECIAL_MARKER = 256
  11710 const CODE_TO_PLANE_CODES = 120
  11711 const LOG_2_PRECISION_BITS = 23
  11712 const LOG_2_RECIPROCAL = 1.44269504088896338700465094007086
  11713 const LOG_2_RECIPROCAL_FIXED_DOUBLE = 12102203.161561485379934310913085937500
  11714 const LOG_LOOKUP_IDX_MAX = 256
  11715 const NUM_ARGB_CACHE_ROWS = 16
  11716 const NUM_CODE_LENGTH_CODES = 19
  11717 const PACKED_NON_LITERAL_CODE = 0
  11718 const PREFIX_LOOKUP_IDX_MAX = 512
  11719 const SYNC_EVERY_N_ROWS = 8
  11720 const VP8L_MAGIC_BYTE1 = 47
  11721 
  11722 var kHashMul8 = uint32(0x1e35a7bd)
  11723 
  11724 type VP8LPredictorFunc = uintptr
  11725 
  11726 type VP8LPredictorAddSubFunc = uintptr
  11727 
  11728 type VP8LProcessDecBlueAndRedFunc = uintptr
  11729 
  11730 type VP8LMultipliers = struct {
  11731 	Fgreen_to_red  uint8_t
  11732 	Fgreen_to_blue uint8_t
  11733 	Fred_to_blue   uint8_t
  11734 }
  11735 
  11736 type VP8LTransformColorInverseFunc = uintptr
  11737 
  11738 type VP8LConvertFunc = uintptr
  11739 
  11740 type VP8LMapARGBFunc = uintptr
  11741 
  11742 type VP8LMapAlphaFunc = uintptr
  11743 
  11744 type VP8LProcessEncBlueAndRedFunc = uintptr
  11745 
  11746 type VP8LTransformColorFunc = uintptr
  11747 
  11748 type VP8LCollectColorBlueTransformsFunc = uintptr
  11749 
  11750 type VP8LCollectColorRedTransformsFunc = uintptr
  11751 
  11752 type VP8LCostFunc = uintptr
  11753 
  11754 type VP8LCombinedShannonEntropyFunc = uintptr
  11755 
  11756 type VP8LShannonEntropyFunc = uintptr
  11757 
  11758 type VP8LStreaks = struct {
  11759 	Fcounts  [2]int32
  11760 	Fstreaks [2][2]int32
  11761 }
  11762 
  11763 type VP8LBitEntropy = struct {
  11764 	Fentropy      uint64_t
  11765 	Fsum          uint32_t
  11766 	Fnonzeros     int32
  11767 	Fmax_val      uint32_t
  11768 	Fnonzero_code uint32_t
  11769 }
  11770 
  11771 type VP8LGetCombinedEntropyUnrefinedFunc = uintptr
  11772 
  11773 type VP8LGetEntropyUnrefinedFunc = uintptr
  11774 
  11775 type VP8LAddVectorFunc = uintptr
  11776 
  11777 type VP8LAddVectorEqFunc = uintptr
  11778 
  11779 type VP8LVectorMismatchFunc = uintptr
  11780 
  11781 type VP8LBundleColorMapFunc = uintptr
  11782 
  11783 type VP8LFastLog2SlowFunc = uintptr
  11784 
  11785 type VP8LFastSLog2SlowFunc = uintptr
  11786 
  11787 type VP8LPrefixCode = struct {
  11788 	Fcode       int8_t
  11789 	Fextra_bits int8_t
  11790 }
  11791 
  11792 //------------------------------------------------------------------------------
  11793 // Transform-related functions used in both encoding and decoding.
  11794 
  11795 // Macros used to create a batch predictor that iteratively uses a
  11796 // one-pixel predictor.
  11797 
  11798 // The predictor is added to the output pixel (which
  11799 // is therefore considered as a residual) to get the final prediction.
  11800 
  11801 // Copyright 2010 Google Inc. All Rights Reserved.
  11802 //
  11803 // Use of this source code is governed by a BSD-style license
  11804 // that can be found in the COPYING file in the root of the source
  11805 // tree. An additional intellectual property rights grant can be found
  11806 // in the file PATENTS. All contributing project authors may
  11807 // be found in the AUTHORS file in the root of the source tree.
  11808 // -----------------------------------------------------------------------------
  11809 //
  11810 // Boolean decoder
  11811 //
  11812 // Author: Skal (pascal.massimino@gmail.com)
  11813 //         Vikas Arora (vikaas.arora@gmail.com)
  11814 
  11815 // Copyright 2012 Google Inc. All Rights Reserved.
  11816 //
  11817 // Use of this source code is governed by a BSD-style license
  11818 // that can be found in the COPYING file in the root of the source
  11819 // tree. An additional intellectual property rights grant can be found
  11820 // in the file PATENTS. All contributing project authors may
  11821 // be found in the AUTHORS file in the root of the source tree.
  11822 // -----------------------------------------------------------------------------
  11823 //
  11824 // Color Cache for WebP Lossless
  11825 //
  11826 // Authors: Jyrki Alakuijala (jyrki@google.com)
  11827 //          Urvang Joshi (urvang@google.com)
  11828 
  11829 // Copyright 2012 Google Inc. All Rights Reserved.
  11830 //
  11831 // Use of this source code is governed by a BSD-style license
  11832 // that can be found in the COPYING file in the root of the source
  11833 // tree. An additional intellectual property rights grant can be found
  11834 // in the file PATENTS. All contributing project authors may
  11835 // be found in the AUTHORS file in the root of the source tree.
  11836 // -----------------------------------------------------------------------------
  11837 //
  11838 // Utilities for building and looking up Huffman trees.
  11839 //
  11840 // Author: Urvang Joshi (urvang@google.com)
  11841 
  11842 // Copyright 2012 Google Inc. All Rights Reserved.
  11843 //
  11844 // Use of this source code is governed by a BSD-style license
  11845 // that can be found in the COPYING file in the root of the source
  11846 // tree. An additional intellectual property rights grant can be found
  11847 // in the file PATENTS. All contributing project authors may
  11848 // be found in the AUTHORS file in the root of the source tree.
  11849 // -----------------------------------------------------------------------------
  11850 //
  11851 // Rescaling functions
  11852 //
  11853 // Author: Skal (pascal.massimino@gmail.com)
  11854 
  11855 // Copyright 2012 Google Inc. All Rights Reserved.
  11856 //
  11857 // Use of this source code is governed by a BSD-style license
  11858 // that can be found in the COPYING file in the root of the source
  11859 // tree. An additional intellectual property rights grant can be found
  11860 // in the file PATENTS. All contributing project authors may
  11861 // be found in the AUTHORS file in the root of the source tree.
  11862 // -----------------------------------------------------------------------------
  11863 //
  11864 // Misc. common utility functions
  11865 //
  11866 // Authors: Skal (pascal.massimino@gmail.com)
  11867 //          Urvang (urvang@google.com)
  11868 
  11869 // Copyright 2010 Google Inc. All Rights Reserved.
  11870 //
  11871 // Use of this source code is governed by a BSD-style license
  11872 // that can be found in the COPYING file in the root of the source
  11873 // tree. An additional intellectual property rights grant can be found
  11874 // in the file PATENTS. All contributing project authors may
  11875 // be found in the AUTHORS file in the root of the source tree.
  11876 // -----------------------------------------------------------------------------
  11877 //
  11878 //  Main decoding functions for WebP images.
  11879 //
  11880 // Author: Skal (pascal.massimino@gmail.com)
  11881 
  11882 // Copyright 2012 Google Inc. All Rights Reserved.
  11883 //
  11884 // Use of this source code is governed by a BSD-style license
  11885 // that can be found in the COPYING file in the root of the source
  11886 // tree. An additional intellectual property rights grant can be found
  11887 // in the file PATENTS. All contributing project authors may
  11888 // be found in the AUTHORS file in the root of the source tree.
  11889 // -----------------------------------------------------------------------------
  11890 //
  11891 //  Internal header for constants related to WebP file format.
  11892 //
  11893 // Author: Urvang (urvang@google.com)
  11894 
  11895 // Copyright 2010 Google Inc. All Rights Reserved.
  11896 //
  11897 // Use of this source code is governed by a BSD-style license
  11898 // that can be found in the COPYING file in the root of the source
  11899 // tree. An additional intellectual property rights grant can be found
  11900 // in the file PATENTS. All contributing project authors may
  11901 // be found in the AUTHORS file in the root of the source tree.
  11902 // -----------------------------------------------------------------------------
  11903 //
  11904 //  Common types + memory wrappers
  11905 //
  11906 // Author: Skal (pascal.massimino@gmail.com)
  11907 
  11908 var kCodeLengthLiterals = int32(16)
  11909 var kCodeLengthRepeatCode = int32(16)
  11910 var kCodeLengthExtraBits = [3]uint8_t{
  11911 	0: uint8(2),
  11912 	1: uint8(3),
  11913 	2: uint8(7),
  11914 }
  11915 var kCodeLengthRepeatOffsets = [3]uint8_t{
  11916 	0: uint8(3),
  11917 	1: uint8(3),
  11918 	2: uint8(11),
  11919 }
  11920 
  11921 // C documentation
  11922 //
  11923 //	// -----------------------------------------------------------------------------
  11924 //	//  Five Huffman codes are used at each meta code:
  11925 //	//  1. green + length prefix codes + color cache codes,
  11926 //	//  2. alpha,
  11927 //	//  3. red,
  11928 //	//  4. blue, and,
  11929 //	//  5. distance prefix codes.
  11930 type HuffIndex = int32
  11931 
  11932 const GREEN = 0
  11933 const RED = 1
  11934 const BLUE = 2
  11935 const ALPHA = 3
  11936 const DIST = 4
  11937 
  11938 var kAlphabetSize = [5]uint16_t{
  11939 	0: libc.Uint16FromInt32(libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)),
  11940 	1: uint16(NUM_LITERAL_CODES),
  11941 	2: uint16(NUM_LITERAL_CODES),
  11942 	3: uint16(NUM_LITERAL_CODES),
  11943 	4: uint16(NUM_DISTANCE_CODES),
  11944 }
  11945 
  11946 var kLiteralMap = [5]uint8_t{
  11947 	1: uint8(1),
  11948 	2: uint8(1),
  11949 	3: uint8(1),
  11950 }
  11951 
  11952 var kCodeLengthCodeOrder = [19]uint8_t{
  11953 	0:  uint8(17),
  11954 	1:  uint8(18),
  11955 	3:  uint8(1),
  11956 	4:  uint8(2),
  11957 	5:  uint8(3),
  11958 	6:  uint8(4),
  11959 	7:  uint8(5),
  11960 	8:  uint8(16),
  11961 	9:  uint8(6),
  11962 	10: uint8(7),
  11963 	11: uint8(8),
  11964 	12: uint8(9),
  11965 	13: uint8(10),
  11966 	14: uint8(11),
  11967 	15: uint8(12),
  11968 	16: uint8(13),
  11969 	17: uint8(14),
  11970 	18: uint8(15),
  11971 }
  11972 
  11973 var kCodeToPlane = [120]uint8_t{
  11974 	0:   uint8(0x18),
  11975 	1:   uint8(0x07),
  11976 	2:   uint8(0x17),
  11977 	3:   uint8(0x19),
  11978 	4:   uint8(0x28),
  11979 	5:   uint8(0x06),
  11980 	6:   uint8(0x27),
  11981 	7:   uint8(0x29),
  11982 	8:   uint8(0x16),
  11983 	9:   uint8(0x1a),
  11984 	10:  uint8(0x26),
  11985 	11:  uint8(0x2a),
  11986 	12:  uint8(0x38),
  11987 	13:  uint8(0x05),
  11988 	14:  uint8(0x37),
  11989 	15:  uint8(0x39),
  11990 	16:  uint8(0x15),
  11991 	17:  uint8(0x1b),
  11992 	18:  uint8(0x36),
  11993 	19:  uint8(0x3a),
  11994 	20:  uint8(0x25),
  11995 	21:  uint8(0x2b),
  11996 	22:  uint8(0x48),
  11997 	23:  uint8(0x04),
  11998 	24:  uint8(0x47),
  11999 	25:  uint8(0x49),
  12000 	26:  uint8(0x14),
  12001 	27:  uint8(0x1c),
  12002 	28:  uint8(0x35),
  12003 	29:  uint8(0x3b),
  12004 	30:  uint8(0x46),
  12005 	31:  uint8(0x4a),
  12006 	32:  uint8(0x24),
  12007 	33:  uint8(0x2c),
  12008 	34:  uint8(0x58),
  12009 	35:  uint8(0x45),
  12010 	36:  uint8(0x4b),
  12011 	37:  uint8(0x34),
  12012 	38:  uint8(0x3c),
  12013 	39:  uint8(0x03),
  12014 	40:  uint8(0x57),
  12015 	41:  uint8(0x59),
  12016 	42:  uint8(0x13),
  12017 	43:  uint8(0x1d),
  12018 	44:  uint8(0x56),
  12019 	45:  uint8(0x5a),
  12020 	46:  uint8(0x23),
  12021 	47:  uint8(0x2d),
  12022 	48:  uint8(0x44),
  12023 	49:  uint8(0x4c),
  12024 	50:  uint8(0x55),
  12025 	51:  uint8(0x5b),
  12026 	52:  uint8(0x33),
  12027 	53:  uint8(0x3d),
  12028 	54:  uint8(0x68),
  12029 	55:  uint8(0x02),
  12030 	56:  uint8(0x67),
  12031 	57:  uint8(0x69),
  12032 	58:  uint8(0x12),
  12033 	59:  uint8(0x1e),
  12034 	60:  uint8(0x66),
  12035 	61:  uint8(0x6a),
  12036 	62:  uint8(0x22),
  12037 	63:  uint8(0x2e),
  12038 	64:  uint8(0x54),
  12039 	65:  uint8(0x5c),
  12040 	66:  uint8(0x43),
  12041 	67:  uint8(0x4d),
  12042 	68:  uint8(0x65),
  12043 	69:  uint8(0x6b),
  12044 	70:  uint8(0x32),
  12045 	71:  uint8(0x3e),
  12046 	72:  uint8(0x78),
  12047 	73:  uint8(0x01),
  12048 	74:  uint8(0x77),
  12049 	75:  uint8(0x79),
  12050 	76:  uint8(0x53),
  12051 	77:  uint8(0x5d),
  12052 	78:  uint8(0x11),
  12053 	79:  uint8(0x1f),
  12054 	80:  uint8(0x64),
  12055 	81:  uint8(0x6c),
  12056 	82:  uint8(0x42),
  12057 	83:  uint8(0x4e),
  12058 	84:  uint8(0x76),
  12059 	85:  uint8(0x7a),
  12060 	86:  uint8(0x21),
  12061 	87:  uint8(0x2f),
  12062 	88:  uint8(0x75),
  12063 	89:  uint8(0x7b),
  12064 	90:  uint8(0x31),
  12065 	91:  uint8(0x3f),
  12066 	92:  uint8(0x63),
  12067 	93:  uint8(0x6d),
  12068 	94:  uint8(0x52),
  12069 	95:  uint8(0x5e),
  12070 	97:  uint8(0x74),
  12071 	98:  uint8(0x7c),
  12072 	99:  uint8(0x41),
  12073 	100: uint8(0x4f),
  12074 	101: uint8(0x10),
  12075 	102: uint8(0x20),
  12076 	103: uint8(0x62),
  12077 	104: uint8(0x6e),
  12078 	105: uint8(0x30),
  12079 	106: uint8(0x73),
  12080 	107: uint8(0x7d),
  12081 	108: uint8(0x51),
  12082 	109: uint8(0x5f),
  12083 	110: uint8(0x40),
  12084 	111: uint8(0x72),
  12085 	112: uint8(0x7e),
  12086 	113: uint8(0x61),
  12087 	114: uint8(0x6f),
  12088 	115: uint8(0x50),
  12089 	116: uint8(0x71),
  12090 	117: uint8(0x7f),
  12091 	118: uint8(0x60),
  12092 	119: uint8(0x70),
  12093 }
  12094 
  12095 // C documentation
  12096 //
  12097 //	// Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha
  12098 //	// and distance alphabets are constant (256 for red, blue and alpha, 40 for
  12099 //	// distance) and lookup table sizes for them in worst case are 630 and 410
  12100 //	// respectively. Size of green alphabet depends on color cache size and is equal
  12101 //	// to 256 (green component values) + 24 (length prefix values)
  12102 //	// + color_cache_size (between 0 and 2048).
  12103 //	// All values computed for 8-bit first level lookup with Mark Adler's tool:
  12104 //	// https://github.com/madler/zlib/blob/v1.2.5/examples/enough.c
  12105 var kTableSize = [12]uint16_t{
  12106 	0:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(654)),
  12107 	1:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(656)),
  12108 	2:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(658)),
  12109 	3:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(662)),
  12110 	4:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(670)),
  12111 	5:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(686)),
  12112 	6:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(718)),
  12113 	7:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(782)),
  12114 	8:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(912)),
  12115 	9:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1168)),
  12116 	10: libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1680)),
  12117 	11: libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(2704)),
  12118 }
  12119 
  12120 func VP8LSetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1) (r int32) {
  12121 	// The oldest error reported takes precedence over the new one.
  12122 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) || (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
  12123 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = error1
  12124 	}
  12125 	return 0
  12126 }
  12127 
  12128 //------------------------------------------------------------------------------
  12129 
  12130 func VP8LCheckSignature(tls *libc.TLS, data uintptr, size size_t) (r int32) {
  12131 	return libc.BoolInt32(size >= uint64(VP8L_FRAME_HEADER_SIZE) && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) == int32(VP8L_MAGIC_BYTE1) && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 4)))>>int32(5) == 0) // version
  12132 }
  12133 
  12134 func ReadImageInfo(tls *libc.TLS, br uintptr, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12135 	if VP8LReadBits(tls, br, int32(8)) != uint32(VP8L_MAGIC_BYTE1) {
  12136 		return 0
  12137 	}
  12138 	**(**int32)(__ccgo_up(width)) = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12139 	**(**int32)(__ccgo_up(height)) = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12140 	**(**int32)(__ccgo_up(has_alpha)) = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)))
  12141 	if VP8LReadBits(tls, br, int32(VP8L_VERSION_BITS)) != uint32(0) {
  12142 		return 0
  12143 	}
  12144 	return libc.BoolInt32(!((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12145 }
  12146 
  12147 func VP8LGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12148 	bp := tls.Alloc(64)
  12149 	defer tls.Free(64)
  12150 	var _ /* a at bp+8 */ int32
  12151 	var _ /* br at bp+16 */ VP8LBitReader
  12152 	var _ /* h at bp+4 */ int32
  12153 	var _ /* w at bp+0 */ int32
  12154 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8L_FRAME_HEADER_SIZE) {
  12155 		return 0 // not enough data
  12156 	} else {
  12157 		if !(VP8LCheckSignature(tls, data, data_size) != 0) {
  12158 			return 0 // bad signature
  12159 		} else {
  12160 			VP8LInitBitReader(tls, bp+16, data, data_size)
  12161 			if !(ReadImageInfo(tls, bp+16, bp, bp+4, bp+8) != 0) {
  12162 				return 0
  12163 			}
  12164 			if width != libc.UintptrFromInt32(0) {
  12165 				**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp))
  12166 			}
  12167 			if height != libc.UintptrFromInt32(0) {
  12168 				**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 4))
  12169 			}
  12170 			if has_alpha != libc.UintptrFromInt32(0) {
  12171 				**(**int32)(__ccgo_up(has_alpha)) = **(**int32)(__ccgo_up(bp + 8))
  12172 			}
  12173 			return int32(1)
  12174 		}
  12175 	}
  12176 	return r
  12177 }
  12178 
  12179 //------------------------------------------------------------------------------
  12180 
  12181 func GetCopyDistance(tls *libc.TLS, distance_symbol int32, br uintptr) (r int32) {
  12182 	var extra_bits, offset int32
  12183 	_, _ = extra_bits, offset
  12184 	if distance_symbol < int32(4) {
  12185 		return distance_symbol + int32(1)
  12186 	}
  12187 	extra_bits = (distance_symbol - int32(2)) >> int32(1)
  12188 	offset = (int32(2) + distance_symbol&int32(1)) << extra_bits
  12189 	return libc.Int32FromUint32(libc.Uint32FromInt32(offset) + VP8LReadBits(tls, br, extra_bits) + uint32(1))
  12190 }
  12191 
  12192 func GetCopyLength(tls *libc.TLS, length_symbol int32, br uintptr) (r int32) {
  12193 	// Length and distance prefixes are encoded the same way.
  12194 	return GetCopyDistance(tls, length_symbol, br)
  12195 }
  12196 
  12197 func PlaneCodeToDistance(tls *libc.TLS, xsize int32, plane_code int32) (r int32) {
  12198 	var dist, dist_code, xoffset, yoffset, v1 int32
  12199 	_, _, _, _, _ = dist, dist_code, xoffset, yoffset, v1
  12200 	if plane_code > int32(CODE_TO_PLANE_CODES) {
  12201 		return plane_code - int32(CODE_TO_PLANE_CODES)
  12202 	} else {
  12203 		dist_code = libc.Int32FromUint8(kCodeToPlane[plane_code-int32(1)])
  12204 		yoffset = dist_code >> int32(4)
  12205 		xoffset = int32(8) - dist_code&int32(0xf)
  12206 		dist = yoffset*xsize + xoffset
  12207 		if dist >= int32(1) {
  12208 			v1 = dist
  12209 		} else {
  12210 			v1 = int32(1)
  12211 		}
  12212 		return v1 // dist<1 can happen if xsize is very small
  12213 	}
  12214 	return r
  12215 }
  12216 
  12217 // C documentation
  12218 //
  12219 //	//------------------------------------------------------------------------------
  12220 //	// Decodes the next Huffman code from bit-stream.
  12221 //	// VP8LFillBitWindow(br) needs to be called at minimum every second call
  12222 //	// to ReadSymbol, in order to pre-fetch enough bits.
  12223 func ReadSymbol(tls *libc.TLS, table uintptr, br2 uintptr) (r int32) {
  12224 	var nbits int32
  12225 	var val1, v2 uint32_t
  12226 	var v1 uintptr
  12227 	_, _, _, _ = nbits, val1, v1, v2
  12228 	v1 = br2
  12229 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12230 	goto _3
  12231 _3:
  12232 	val1 = v2
  12233 	table = table + uintptr(val1&libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HUFFMAN_TABLE_BITS)-libc.Int32FromInt32(1)))*4
  12234 	nbits = libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(table)).Fbits) - int32(HUFFMAN_TABLE_BITS)
  12235 	if nbits > 0 {
  12236 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + int32(HUFFMAN_TABLE_BITS)
  12237 		v1 = br2
  12238 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12239 		goto _6
  12240 	_6:
  12241 		val1 = v2
  12242 		table = table + uintptr((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)*4
  12243 		table = table + uintptr(val1&libc.Uint32FromInt32(libc.Int32FromInt32(1)<<nbits-libc.Int32FromInt32(1)))*4
  12244 	}
  12245 	(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(table)).Fbits)
  12246 	return libc.Int32FromUint16((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)
  12247 }
  12248 
  12249 // C documentation
  12250 //
  12251 //	// Reads packed symbol depending on GREEN channel
  12252 func ReadPackedSymbols(tls *libc.TLS, group uintptr, br2 uintptr, dst uintptr) (r int32) {
  12253 	var code HuffmanCode32
  12254 	var val1, v2 uint32_t
  12255 	var v1 uintptr
  12256 	_, _, _, _ = code, val1, v1, v2
  12257 	v1 = br2
  12258 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12259 	goto _3
  12260 _3:
  12261 	val1 = v2 & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS) - libc.Uint32FromInt32(1))
  12262 	code = **(**HuffmanCode32)(__ccgo_up(group + 56 + uintptr(val1)*8))
  12263 	if code.Fbits < int32(BITS_SPECIAL_MARKER) {
  12264 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits
  12265 		**(**uint32_t)(__ccgo_up(dst)) = code.Fvalue
  12266 		return PACKED_NON_LITERAL_CODE
  12267 	} else {
  12268 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits - int32(BITS_SPECIAL_MARKER)
  12269 		return libc.Int32FromUint32(code.Fvalue)
  12270 	}
  12271 	return r
  12272 }
  12273 
  12274 func AccumulateHCode(tls *libc.TLS, hcode HuffmanCode, shift int32, huff uintptr) (r int32) {
  12275 	**(**int32)(__ccgo_up(huff)) += libc.Int32FromUint8(hcode.Fbits)
  12276 	**(**uint32_t)(__ccgo_up(huff + 4)) |= uint32(hcode.Fvalue) << shift
  12277 	return libc.Int32FromUint8(hcode.Fbits)
  12278 }
  12279 
  12280 func BuildPackedTable(tls *libc.TLS, htree_group uintptr) {
  12281 	var bits, code uint32_t
  12282 	var hcode HuffmanCode
  12283 	var huff uintptr
  12284 	_, _, _, _ = bits, code, hcode, huff
  12285 	code = uint32(0)
  12286 	for {
  12287 		if !(code < libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS)) {
  12288 			break
  12289 		}
  12290 		bits = code
  12291 		huff = htree_group + 56 + uintptr(bits)*8
  12292 		hcode = **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)) + uintptr(bits)*4))
  12293 		if libc.Int32FromUint16(hcode.Fvalue) >= int32(NUM_LITERAL_CODES) {
  12294 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = libc.Int32FromUint8(hcode.Fbits) + int32(BITS_SPECIAL_MARKER)
  12295 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(hcode.Fvalue)
  12296 		} else {
  12297 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = 0
  12298 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(0)
  12299 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, hcode, int32(8), huff))
  12300 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)) + uintptr(bits)*4)), int32(16), huff))
  12301 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)) + uintptr(bits)*4)), 0, huff))
  12302 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)) + uintptr(bits)*4)), int32(24), huff))
  12303 			_ = bits
  12304 		}
  12305 		goto _1
  12306 	_1:
  12307 		;
  12308 		code = code + 1
  12309 	}
  12310 }
  12311 
  12312 func ReadHuffmanCodeLengths(tls *libc.TLS, dec uintptr, code_length_code_lengths uintptr, num_symbols int32, code_lengths uintptr) (r int32) {
  12313 	bp := tls.Alloc(48)
  12314 	defer tls.Free(48)
  12315 	var br3, p, v2 uintptr
  12316 	var code_len, extra_bits, length, length_nbits, max_symbol, ok, prev_code_len, repeat, repeat_offset, slot, symbol, use_prev, v1, v6, v7 int32
  12317 	var v4 uint32_t
  12318 	var _ /* tables at bp+0 */ HuffmanTables
  12319 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = br3, code_len, extra_bits, length, length_nbits, max_symbol, ok, p, prev_code_len, repeat, repeat_offset, slot, symbol, use_prev, v1, v2, v4, v6, v7
  12320 	ok = 0
  12321 	br3 = dec + 40
  12322 	prev_code_len = int32(DEFAULT_CODE_LENGTH)
  12323 	if !(VP8LHuffmanTablesAllocate(tls, libc.Int32FromInt32(1)<<libc.Int32FromInt32(LENGTHS_TABLE_BITS), bp) != 0) || !(VP8LBuildHuffmanTable(tls, bp, int32(LENGTHS_TABLE_BITS), code_length_code_lengths, int32(NUM_CODE_LENGTH_CODES)) != 0) {
  12324 		goto End
  12325 	}
  12326 	if VP8LReadBits(tls, br3, int32(1)) != 0 { // use length
  12327 		length_nbits = libc.Int32FromUint32(uint32(2) + uint32(2)*VP8LReadBits(tls, br3, int32(3)))
  12328 		max_symbol = libc.Int32FromUint32(uint32(2) + VP8LReadBits(tls, br3, length_nbits))
  12329 		if max_symbol > num_symbols {
  12330 			goto End
  12331 		}
  12332 	} else {
  12333 		max_symbol = num_symbols
  12334 	}
  12335 	symbol = 0
  12336 	for symbol < num_symbols {
  12337 		v1 = max_symbol
  12338 		max_symbol = max_symbol - 1
  12339 		if v1 == 0 {
  12340 			break
  12341 		}
  12342 		v2 = br3
  12343 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  12344 			VP8LDoFillBitWindow(tls, v2)
  12345 		}
  12346 		v2 = br3
  12347 		v4 = uint32((*VP8LBitReader)(unsafe.Pointer(v2)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12348 		goto _5
  12349 	_5:
  12350 		p = (*HuffmanTablesSegment)(unsafe.Pointer((**(**HuffmanTables)(__ccgo_up(bp))).Fcurr_segment)).Fstart + uintptr(v4&libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(LENGTHS_TABLE_BITS)-libc.Int32FromInt32(1)))*4
  12351 		(*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos + libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(p)).Fbits)
  12352 		code_len = libc.Int32FromUint16((*HuffmanCode)(unsafe.Pointer(p)).Fvalue)
  12353 		if code_len < kCodeLengthLiterals {
  12354 			v1 = symbol
  12355 			symbol = symbol + 1
  12356 			**(**int32)(__ccgo_up(code_lengths + uintptr(v1)*4)) = code_len
  12357 			if code_len != 0 {
  12358 				prev_code_len = code_len
  12359 			}
  12360 		} else {
  12361 			use_prev = libc.BoolInt32(code_len == kCodeLengthRepeatCode)
  12362 			slot = code_len - kCodeLengthLiterals
  12363 			extra_bits = libc.Int32FromUint8(kCodeLengthExtraBits[slot])
  12364 			repeat_offset = libc.Int32FromUint8(kCodeLengthRepeatOffsets[slot])
  12365 			repeat = libc.Int32FromUint32(VP8LReadBits(tls, br3, extra_bits) + libc.Uint32FromInt32(repeat_offset))
  12366 			if symbol+repeat > num_symbols {
  12367 				goto End
  12368 			} else {
  12369 				if use_prev != 0 {
  12370 					v1 = prev_code_len
  12371 				} else {
  12372 					v1 = 0
  12373 				}
  12374 				length = v1
  12375 				for {
  12376 					v6 = repeat
  12377 					repeat = repeat - 1
  12378 					if !(v6 > 0) {
  12379 						break
  12380 					}
  12381 					v7 = symbol
  12382 					symbol = symbol + 1
  12383 					**(**int32)(__ccgo_up(code_lengths + uintptr(v7)*4)) = length
  12384 				}
  12385 			}
  12386 		}
  12387 	}
  12388 	ok = int32(1)
  12389 	goto End
  12390 End:
  12391 	;
  12392 	VP8LHuffmanTablesDeallocate(tls, bp)
  12393 	if !(ok != 0) {
  12394 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12395 	}
  12396 	return ok
  12397 }
  12398 
  12399 // C documentation
  12400 //
  12401 //	// 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman
  12402 //	// tree.
  12403 func ReadHuffmanCode(tls *libc.TLS, alphabet_size int32, dec uintptr, code_lengths uintptr, table uintptr) (r int32) {
  12404 	bp := tls.Alloc(80)
  12405 	defer tls.Free(80)
  12406 	var br uintptr
  12407 	var first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1 int32
  12408 	var _ /* code_length_code_lengths at bp+0 */ [19]int32
  12409 	_, _, _, _, _, _, _, _, _, _ = br, first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1
  12410 	ok = 0
  12411 	size = 0
  12412 	br = dec + 40
  12413 	simple_code = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)))
  12414 	libc.Xmemset(tls, code_lengths, 0, libc.Uint64FromInt32(alphabet_size)*uint64(4))
  12415 	if simple_code != 0 { // Read symbols, codes & code lengths directly.
  12416 		num_symbols = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)) + uint32(1))
  12417 		first_symbol_len_code = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)))
  12418 		if first_symbol_len_code == 0 {
  12419 			v1 = int32(1)
  12420 		} else {
  12421 			v1 = int32(8)
  12422 		}
  12423 		// The first code is either 1 bit or 8 bit code.
  12424 		symbol = libc.Int32FromUint32(VP8LReadBits(tls, br, v1))
  12425 		**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12426 		// The second code (if present), is always 8 bits long.
  12427 		if num_symbols == int32(2) {
  12428 			symbol = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(8)))
  12429 			**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12430 		}
  12431 		ok = int32(1)
  12432 	} else {
  12433 		**(**[19]int32)(__ccgo_up(bp)) = [19]int32{}
  12434 		num_codes = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(4)) + uint32(4))
  12435 		i = 0
  12436 		for {
  12437 			if !(i < num_codes) {
  12438 				break
  12439 			}
  12440 			(**(**[19]int32)(__ccgo_up(bp)))[kCodeLengthCodeOrder[i]] = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(3)))
  12441 			goto _2
  12442 		_2:
  12443 			;
  12444 			i = i + 1
  12445 		}
  12446 		ok = ReadHuffmanCodeLengths(tls, dec, bp, alphabet_size, code_lengths)
  12447 	}
  12448 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12449 	if ok != 0 {
  12450 		size = VP8LBuildHuffmanTable(tls, table, int32(HUFFMAN_TABLE_BITS), code_lengths, alphabet_size)
  12451 	}
  12452 	if !(ok != 0) || size == 0 {
  12453 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12454 	}
  12455 	return size
  12456 }
  12457 
  12458 func ReadHuffmanCodes(tls *libc.TLS, dec uintptr, xsize int32, ysize int32, color_cache_bits int32, allow_recursion int32) (r int32) {
  12459 	bp := tls.Alloc(16)
  12460 	defer tls.Free(16)
  12461 	var br, hdr, huffman_tables, mapped_group, mapping uintptr
  12462 	var group, huffman_pixs, huffman_precision, huffman_xsize, huffman_ysize, i, num_htree_groups, num_htree_groups_max, ok, v9 int32
  12463 	var v1, v2, v4, v5 uint32_t
  12464 	var _ /* htree_groups at bp+8 */ uintptr
  12465 	var _ /* huffman_image at bp+0 */ uintptr
  12466 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = br, group, hdr, huffman_pixs, huffman_precision, huffman_tables, huffman_xsize, huffman_ysize, i, mapped_group, mapping, num_htree_groups, num_htree_groups_max, ok, v1, v2, v4, v5, v9
  12467 	br = dec + 40
  12468 	hdr = dec + 152
  12469 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  12470 	**(**uintptr)(__ccgo_up(bp + 8)) = libc.UintptrFromInt32(0)
  12471 	huffman_tables = hdr + 80
  12472 	num_htree_groups = int32(1)
  12473 	num_htree_groups_max = int32(1)
  12474 	mapping = libc.UintptrFromInt32(0)
  12475 	ok = 0
  12476 	// Check the table has been 0 initialized (through InitMetadata).
  12477 	if allow_recursion != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  12478 		// use meta Huffman codes.
  12479 		huffman_precision = libc.Int32FromUint32(uint32(MIN_HUFFMAN_BITS) + VP8LReadBits(tls, br, int32(NUM_HUFFMAN_BITS)))
  12480 		v1 = libc.Uint32FromInt32(huffman_precision)
  12481 		v2 = (libc.Uint32FromInt32(xsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  12482 		goto _3
  12483 	_3:
  12484 		huffman_xsize = libc.Int32FromUint32(v2)
  12485 		v4 = libc.Uint32FromInt32(huffman_precision)
  12486 		v5 = (libc.Uint32FromInt32(ysize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  12487 		goto _6
  12488 	_6:
  12489 		huffman_ysize = libc.Int32FromUint32(v5)
  12490 		huffman_pixs = huffman_xsize * huffman_ysize
  12491 		if !(DecodeImageStream(tls, huffman_xsize, huffman_ysize, 0, dec, bp) != 0) {
  12492 			goto Error
  12493 		}
  12494 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits = huffman_precision
  12495 		i = 0
  12496 		for {
  12497 			if !(i < huffman_pixs) {
  12498 				break
  12499 			}
  12500 			// The huffman data is stored in red and green bytes.
  12501 			group = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  12502 			**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = libc.Uint32FromInt32(group)
  12503 			if group >= num_htree_groups_max {
  12504 				num_htree_groups_max = group + int32(1)
  12505 			}
  12506 			goto _7
  12507 		_7:
  12508 			;
  12509 			i = i + 1
  12510 		}
  12511 		// Check the validity of num_htree_groups_max. If it seems too big, use a
  12512 		// smaller value for later. This will prevent big memory allocations to end
  12513 		// up with a bad bitstream anyway.
  12514 		// The value of 1000 is totally arbitrary. We know that num_htree_groups_max
  12515 		// is smaller than (1 << 16) and should be smaller than the number of pixels
  12516 		// (though the format allows it to be bigger).
  12517 		if num_htree_groups_max > int32(1000) || num_htree_groups_max > xsize*ysize {
  12518 			// Create a mapping from the used indices to the minimal set of used
  12519 			// values [0, num_htree_groups)
  12520 			mapping = WebPSafeMalloc(tls, libc.Uint64FromInt32(num_htree_groups_max), uint64(4))
  12521 			if mapping == libc.UintptrFromInt32(0) {
  12522 				VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12523 				goto Error
  12524 			}
  12525 			// -1 means a value is unmapped, and therefore unused in the Huffman
  12526 			// image.
  12527 			libc.Xmemset(tls, mapping, int32(0xff), libc.Uint64FromInt32(num_htree_groups_max)*uint64(4))
  12528 			num_htree_groups = 0
  12529 			i = libc.Int32FromInt32(0)
  12530 			for {
  12531 				if !(i < huffman_pixs) {
  12532 					break
  12533 				}
  12534 				// Get the current mapping for the group and remap the Huffman image.
  12535 				mapped_group = mapping + uintptr(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)))*4
  12536 				if **(**int32)(__ccgo_up(mapped_group)) == -int32(1) {
  12537 					v9 = num_htree_groups
  12538 					num_htree_groups = num_htree_groups + 1
  12539 					**(**int32)(__ccgo_up(mapped_group)) = v9
  12540 				}
  12541 				**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = libc.Uint32FromInt32(**(**int32)(__ccgo_up(mapped_group)))
  12542 				goto _8
  12543 			_8:
  12544 				;
  12545 				i = i + 1
  12546 			}
  12547 		} else {
  12548 			num_htree_groups = num_htree_groups_max
  12549 		}
  12550 	}
  12551 	if (*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0 {
  12552 		goto Error
  12553 	}
  12554 	if !(ReadHuffmanCodesHelper(tls, color_cache_bits, num_htree_groups, num_htree_groups_max, mapping, dec, huffman_tables, bp+8) != 0) {
  12555 		goto Error
  12556 	}
  12557 	ok = int32(1)
  12558 	// All OK. Finalize pointers.
  12559 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image = **(**uintptr)(__ccgo_up(bp))
  12560 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups = num_htree_groups
  12561 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups = **(**uintptr)(__ccgo_up(bp + 8))
  12562 	goto Error
  12563 Error:
  12564 	;
  12565 	WebPSafeFree(tls, mapping)
  12566 	if !(ok != 0) {
  12567 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  12568 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  12569 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(bp + 8)))
  12570 	}
  12571 	return ok
  12572 }
  12573 
  12574 func ReadHuffmanCodesHelper(tls *libc.TLS, color_cache_bits int32, num_htree_groups int32, num_htree_groups_max int32, mapping uintptr, dec uintptr, huffman_tables uintptr, htree_groups uintptr) (r int32) {
  12575 	var alpha, alphabet_size, alphabet_size1, blue, i, is_trivial_literal, j, k, local_max_bits, max_alphabet_size, max_bits, ok, red, size, table_size, total_size, v1 int32
  12576 	var code_lengths, htree_group, htrees uintptr
  12577 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha, alphabet_size, alphabet_size1, blue, code_lengths, htree_group, htrees, i, is_trivial_literal, j, k, local_max_bits, max_alphabet_size, max_bits, ok, red, size, table_size, total_size, v1
  12578 	ok = 0
  12579 	if color_cache_bits > 0 {
  12580 		v1 = int32(1) << color_cache_bits
  12581 	} else {
  12582 		v1 = 0
  12583 	}
  12584 	max_alphabet_size = libc.Int32FromUint16(kAlphabetSize[0]) + v1
  12585 	table_size = libc.Int32FromUint16(kTableSize[color_cache_bits])
  12586 	code_lengths = libc.UintptrFromInt32(0)
  12587 	if mapping == libc.UintptrFromInt32(0) && num_htree_groups != num_htree_groups_max || num_htree_groups > num_htree_groups_max {
  12588 		goto Error
  12589 	}
  12590 	code_lengths = WebPSafeCalloc(tls, libc.Uint64FromInt32(max_alphabet_size), uint64(4))
  12591 	**(**uintptr)(__ccgo_up(htree_groups)) = VP8LHtreeGroupsNew(tls, num_htree_groups)
  12592 	if **(**uintptr)(__ccgo_up(htree_groups)) == libc.UintptrFromInt32(0) || code_lengths == libc.UintptrFromInt32(0) || !(VP8LHuffmanTablesAllocate(tls, num_htree_groups*table_size, huffman_tables) != 0) {
  12593 		VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12594 		goto Error
  12595 	}
  12596 	i = 0
  12597 	for {
  12598 		if !(i < num_htree_groups_max) {
  12599 			break
  12600 		}
  12601 		// If the index "i" is unused in the Huffman image, just make sure the
  12602 		// coefficients are valid but do not store them.
  12603 		if mapping != libc.UintptrFromInt32(0) && **(**int32)(__ccgo_up(mapping + uintptr(i)*4)) == -int32(1) {
  12604 			j = 0
  12605 			for {
  12606 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12607 					break
  12608 				}
  12609 				alphabet_size = libc.Int32FromUint16(kAlphabetSize[j])
  12610 				if j == 0 && color_cache_bits > 0 {
  12611 					alphabet_size = alphabet_size + int32(1)<<color_cache_bits
  12612 				}
  12613 				// Passing in NULL so that nothing gets filled.
  12614 				if !(ReadHuffmanCode(tls, alphabet_size, dec, code_lengths, libc.UintptrFromInt32(0)) != 0) {
  12615 					goto Error
  12616 				}
  12617 				goto _3
  12618 			_3:
  12619 				;
  12620 				j = j + 1
  12621 			}
  12622 		} else {
  12623 			if mapping == libc.UintptrFromInt32(0) {
  12624 				v1 = i
  12625 			} else {
  12626 				v1 = **(**int32)(__ccgo_up(mapping + uintptr(i)*4))
  12627 			}
  12628 			htree_group = **(**uintptr)(__ccgo_up(htree_groups)) + uintptr(v1)*568
  12629 			htrees = htree_group
  12630 			total_size = 0
  12631 			is_trivial_literal = int32(1)
  12632 			max_bits = 0
  12633 			j = 0
  12634 			for {
  12635 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12636 					break
  12637 				}
  12638 				alphabet_size1 = libc.Int32FromUint16(kAlphabetSize[j])
  12639 				if j == 0 && color_cache_bits > 0 {
  12640 					alphabet_size1 = alphabet_size1 + int32(1)<<color_cache_bits
  12641 				}
  12642 				size = ReadHuffmanCode(tls, alphabet_size1, dec, code_lengths, huffman_tables)
  12643 				**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)) = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment)).Fcurr_table
  12644 				if size == 0 {
  12645 					goto Error
  12646 				}
  12647 				if is_trivial_literal != 0 && libc.Int32FromUint8(kLiteralMap[j]) == int32(1) {
  12648 					is_trivial_literal = libc.BoolInt32(libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits) == 0)
  12649 				}
  12650 				total_size = total_size + libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits)
  12651 				**(**uintptr)(__ccgo_up((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment + 8)) += uintptr(size) * 4
  12652 				if j <= int32(ALPHA) {
  12653 					local_max_bits = **(**int32)(__ccgo_up(code_lengths))
  12654 					k = int32(1)
  12655 					for {
  12656 						if !(k < alphabet_size1) {
  12657 							break
  12658 						}
  12659 						if **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4)) > local_max_bits {
  12660 							local_max_bits = **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4))
  12661 						}
  12662 						goto _6
  12663 					_6:
  12664 						;
  12665 						k = k + 1
  12666 					}
  12667 					max_bits = max_bits + local_max_bits
  12668 				}
  12669 				goto _5
  12670 			_5:
  12671 				;
  12672 				j = j + 1
  12673 			}
  12674 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal = is_trivial_literal
  12675 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = 0
  12676 			if is_trivial_literal != 0 {
  12677 				red = libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fvalue)
  12678 				blue = libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fvalue)
  12679 				alpha = libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fvalue)
  12680 				(*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb = libc.Uint32FromInt32(alpha)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(blue)
  12681 				if total_size == 0 && libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) < int32(NUM_LITERAL_CODES) {
  12682 					(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = int32(1)
  12683 					**(**uint32_t)(__ccgo_up(htree_group + 44)) |= libc.Uint32FromInt32(libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) << int32(8))
  12684 				}
  12685 			}
  12686 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table = libc.BoolInt32(!((*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code != 0) && max_bits < int32(HUFFMAN_PACKED_BITS))
  12687 			if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  12688 				BuildPackedTable(tls, htree_group)
  12689 			}
  12690 		}
  12691 		goto _2
  12692 	_2:
  12693 		;
  12694 		i = i + 1
  12695 	}
  12696 	ok = int32(1)
  12697 	goto Error
  12698 Error:
  12699 	;
  12700 	WebPSafeFree(tls, code_lengths)
  12701 	if !(ok != 0) {
  12702 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  12703 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(htree_groups)))
  12704 		**(**uintptr)(__ccgo_up(htree_groups)) = libc.UintptrFromInt32(0)
  12705 	}
  12706 	return ok
  12707 }
  12708 
  12709 //------------------------------------------------------------------------------
  12710 // Scaling.
  12711 
  12712 func AllocateAndInitRescaler(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  12713 	var in_height, in_width, num_channels, out_height, out_width int32
  12714 	var memory, scaled_data, work uintptr
  12715 	var memory_size, scaled_data_size, work_size uint64_t
  12716 	_, _, _, _, _, _, _, _, _, _, _ = in_height, in_width, memory, memory_size, num_channels, out_height, out_width, scaled_data, scaled_data_size, work, work_size
  12717 	num_channels = int32(4)
  12718 	in_width = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
  12719 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
  12720 	in_height = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
  12721 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
  12722 	work_size = libc.Uint64FromInt32(int32(2)*num_channels) * libc.Uint64FromInt32(out_width) // Rescaler work area.
  12723 	scaled_data_size = libc.Uint64FromInt32(out_width)                                        // Temporary storage for scaled BGRA data.
  12724 	memory_size = uint64(104) + work_size*uint64(4) + scaled_data_size*uint64(4)
  12725 	memory = WebPSafeMalloc(tls, memory_size, uint64(1))
  12726 	if memory == libc.UintptrFromInt32(0) {
  12727 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12728 	}
  12729 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = memory
  12730 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler = memory
  12731 	memory = memory + uintptr(104)
  12732 	work = memory
  12733 	memory = memory + uintptr(work_size*uint64(4))
  12734 	scaled_data = memory
  12735 	if !(WebPRescalerInit(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, in_width, in_height, scaled_data, out_width, out_height, 0, num_channels, work) != 0) {
  12736 		return 0
  12737 	}
  12738 	return int32(1)
  12739 }
  12740 
  12741 //------------------------------------------------------------------------------
  12742 // Export to ARGB
  12743 
  12744 // C documentation
  12745 //
  12746 //	// We have special "export" function since we need to convert from BGRA
  12747 func Export(tls *libc.TLS, rescaler2 uintptr, colorspace WEBP_CSP_MODE1, rgba_stride int32, rgba uintptr) (r int32) {
  12748 	var dst, src, v1, v4 uintptr
  12749 	var dst_width, num_lines_out, v2, v5 int32
  12750 	_, _, _, _, _, _, _, _ = dst, dst_width, num_lines_out, src, v1, v2, v4, v5
  12751 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  12752 	dst = rgba
  12753 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  12754 	num_lines_out = 0
  12755 	for {
  12756 		v1 = rescaler2
  12757 		v4 = v1
  12758 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  12759 		goto _6
  12760 	_6:
  12761 		;
  12762 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  12763 		goto _3
  12764 	_3:
  12765 		if !(v2 != 0) {
  12766 			break
  12767 		}
  12768 		WebPRescalerExportRow(tls, rescaler2)
  12769 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  12770 		VP8LConvertFromBGRA(tls, src, dst_width, colorspace, dst)
  12771 		dst = dst + uintptr(rgba_stride)
  12772 		num_lines_out = num_lines_out + 1
  12773 	}
  12774 	return num_lines_out
  12775 }
  12776 
  12777 // C documentation
  12778 //
  12779 //	// Emit scaled rows.
  12780 func EmitRescaledRowsRGBA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32, out uintptr, out_stride int32) (r int32) {
  12781 	var colorspace WEBP_CSP_MODE1
  12782 	var lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out int32
  12783 	var row_in, row_out uintptr
  12784 	_, _, _, _, _, _, _, _ = colorspace, lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out, row_in, row_out
  12785 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  12786 	num_lines_in = 0
  12787 	num_lines_out = 0
  12788 	for num_lines_in < mb_h {
  12789 		row_in = in + uintptr(int64(num_lines_in)*int64(in_stride))
  12790 		row_out = out + uintptr(int64(num_lines_out)*int64(out_stride))
  12791 		lines_left = mb_h - num_lines_in
  12792 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  12793 		WebPMultARGBRows(tls, row_in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  12794 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, row_in, in_stride)
  12795 		num_lines_in = num_lines_in + lines_imported
  12796 		num_lines_out = num_lines_out + Export(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, colorspace, out_stride, row_out)
  12797 	}
  12798 	return num_lines_out
  12799 }
  12800 
  12801 // C documentation
  12802 //
  12803 //	// Emit rows without any scaling.
  12804 func EmitRows(tls *libc.TLS, colorspace WEBP_CSP_MODE1, row_in uintptr, in_stride int32, mb_w int32, mb_h int32, out uintptr, out_stride int32) (r int32) {
  12805 	var lines, v1 int32
  12806 	var row_out uintptr
  12807 	_, _, _ = lines, row_out, v1
  12808 	lines = mb_h
  12809 	row_out = out
  12810 	for {
  12811 		v1 = lines
  12812 		lines = lines - 1
  12813 		if !(v1 > 0) {
  12814 			break
  12815 		}
  12816 		VP8LConvertFromBGRA(tls, row_in, mb_w, colorspace, row_out)
  12817 		row_in = row_in + uintptr(in_stride)
  12818 		row_out = row_out + uintptr(out_stride)
  12819 	}
  12820 	return mb_h // Num rows out == num rows in.
  12821 }
  12822 
  12823 //------------------------------------------------------------------------------
  12824 // Export to YUVA
  12825 
  12826 func ConvertToYUVA(tls *libc.TLS, src uintptr, width int32, y_pos int32, output uintptr) {
  12827 	var a, buf, u, v uintptr
  12828 	_, _, _, _ = a, buf, u, v
  12829 	buf = output + 16
  12830 	// first, the luma plane
  12831 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertARGBToY})))(tls, src, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy+uintptr(y_pos*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride), width)
  12832 	// then U/V planes
  12833 	u = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
  12834 	v = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
  12835 	// even lines: store values
  12836 	// odd lines: average with previous values
  12837 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertARGBToUV})))(tls, src, u, v, width, libc.BoolInt32(!(y_pos&libc.Int32FromInt32(1) != 0)))
  12838 	// Lastly, store alpha if needed.
  12839 	if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
  12840 		a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(y_pos*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
  12841 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPExtractAlpha})))(tls, src+uintptr(3), 0, width, int32(1), a, 0)
  12842 	}
  12843 }
  12844 
  12845 func ExportYUVA(tls *libc.TLS, dec uintptr, y_pos int32) (r int32) {
  12846 	var dst_width, num_lines_out, v2, v5 int32
  12847 	var rescaler2, src, v1, v4 uintptr
  12848 	_, _, _, _, _, _, _, _ = dst_width, num_lines_out, rescaler2, src, v1, v2, v4, v5
  12849 	rescaler2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler
  12850 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  12851 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  12852 	num_lines_out = 0
  12853 	for {
  12854 		v1 = rescaler2
  12855 		v4 = v1
  12856 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  12857 		goto _6
  12858 	_6:
  12859 		;
  12860 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  12861 		goto _3
  12862 	_3:
  12863 		if !(v2 != 0) {
  12864 			break
  12865 		}
  12866 		WebPRescalerExportRow(tls, rescaler2)
  12867 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  12868 		ConvertToYUVA(tls, src, dst_width, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  12869 		y_pos = y_pos + 1
  12870 		num_lines_out = num_lines_out + 1
  12871 	}
  12872 	return num_lines_out
  12873 }
  12874 
  12875 func EmitRescaledRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32) (r int32) {
  12876 	var lines_imported, lines_left, needed_lines, num_lines_in, y_pos int32
  12877 	_, _, _, _, _ = lines_imported, lines_left, needed_lines, num_lines_in, y_pos
  12878 	num_lines_in = 0
  12879 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  12880 	for num_lines_in < mb_h {
  12881 		lines_left = mb_h - num_lines_in
  12882 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  12883 		WebPMultARGBRows(tls, in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  12884 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, in, in_stride)
  12885 		num_lines_in = num_lines_in + lines_imported
  12886 		in = in + uintptr(needed_lines*in_stride)
  12887 		y_pos = y_pos + ExportYUVA(tls, dec, y_pos)
  12888 	}
  12889 	return y_pos
  12890 }
  12891 
  12892 func EmitRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_w int32, num_rows int32) (r int32) {
  12893 	var y_pos, v1 int32
  12894 	_, _ = y_pos, v1
  12895 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  12896 	for {
  12897 		v1 = num_rows
  12898 		num_rows = num_rows - 1
  12899 		if !(v1 > 0) {
  12900 			break
  12901 		}
  12902 		ConvertToYUVA(tls, in, mb_w, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  12903 		in = in + uintptr(in_stride)
  12904 		y_pos = y_pos + 1
  12905 	}
  12906 	return y_pos
  12907 }
  12908 
  12909 //------------------------------------------------------------------------------
  12910 // Cropping.
  12911 
  12912 // C documentation
  12913 //
  12914 //	// Sets io->mb_y, io->mb_h & io->mb_w according to start row, end row and
  12915 //	// crop options. Also updates the input data pointer, so that it points to the
  12916 //	// start of the cropped window. Note that pixels are in ARGB format even if
  12917 //	// 'in_data' is uint8_t*.
  12918 //	// Returns true if the crop window is not empty.
  12919 func SetCropWindow(tls *libc.TLS, io uintptr, y_start int32, y_end int32, in_data uintptr, pixel_stride int32) (r int32) {
  12920 	var delta int32
  12921 	_ = delta
  12922 	if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
  12923 		y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
  12924 	}
  12925 	if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
  12926 		delta = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
  12927 		y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  12928 		**(**uintptr)(__ccgo_up(in_data)) += uintptr(delta * pixel_stride)
  12929 	}
  12930 	if y_start >= y_end {
  12931 		return 0
  12932 	} // Crop window is empty.
  12933 	**(**uintptr)(__ccgo_up(in_data)) += uintptr(libc.Uint64FromInt32((*VP8Io)(unsafe.Pointer(io)).Fcrop_left) * uint64(4))
  12934 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  12935 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
  12936 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
  12937 	return int32(1) // Non-empty crop window.
  12938 }
  12939 
  12940 //------------------------------------------------------------------------------
  12941 
  12942 func GetMetaIndex(tls *libc.TLS, image uintptr, xsize int32, bits int32, x int32, y int32) (r int32) {
  12943 	if bits == 0 {
  12944 		return 0
  12945 	}
  12946 	return libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(image + uintptr(xsize*(y>>bits)+x>>bits)*4)))
  12947 }
  12948 
  12949 func GetHtreeGroupForPos(tls *libc.TLS, hdr uintptr, x int32, y int32) (r uintptr) {
  12950 	var meta_index int32
  12951 	_ = meta_index
  12952 	meta_index = GetMetaIndex(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_xsize, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits, x, y)
  12953 	return (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(meta_index)*568
  12954 }
  12955 
  12956 //------------------------------------------------------------------------------
  12957 // Main loop, with custom row-processing function
  12958 
  12959 type ProcessRowsFunc = uintptr
  12960 
  12961 func ApplyInverseTransforms(tls *libc.TLS, dec uintptr, start_row int32, num_rows int32, rows uintptr) {
  12962 	var cache_pixs, end_row, n, v1 int32
  12963 	var rows_in, rows_out, transform uintptr
  12964 	_, _, _, _, _, _, _ = cache_pixs, end_row, n, rows_in, rows_out, transform, v1
  12965 	n = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform
  12966 	cache_pixs = (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth * num_rows
  12967 	end_row = start_row + num_rows
  12968 	rows_in = rows
  12969 	rows_out = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  12970 	// Inverse transforms.
  12971 	for {
  12972 		v1 = n
  12973 		n = n - 1
  12974 		if !(v1 > 0) {
  12975 			break
  12976 		}
  12977 		transform = dec + 280 + uintptr(n)*24
  12978 		VP8LInverseTransform(tls, transform, start_row, end_row, rows_in, rows_out)
  12979 		rows_in = rows_out
  12980 	}
  12981 	if rows_in != rows_out {
  12982 		// No transform called, hence just copy.
  12983 		libc.Xmemcpy(tls, rows_out, rows_in, libc.Uint64FromInt32(cache_pixs)*uint64(4))
  12984 	}
  12985 }
  12986 
  12987 // C documentation
  12988 //
  12989 //	// Processes (transforms, scales & color-converts) the rows decoded after the
  12990 //	// last call.
  12991 func ProcessRows(tls *libc.TLS, dec uintptr, row int32) {
  12992 	bp := tls.Alloc(16)
  12993 	defer tls.Free(16)
  12994 	var buf, io, output, rgba, rows uintptr
  12995 	var in_stride, num_rows, num_rows_out, v1, v3 int32
  12996 	var _ /* rows_data at bp+0 */ uintptr
  12997 	_, _, _, _, _, _, _, _, _, _ = buf, in_stride, io, num_rows, num_rows_out, output, rgba, rows, v1, v3
  12998 	rows = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row)*4
  12999 	num_rows = row - (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13000 	// We can't process more than NUM_ARGB_CACHE_ROWS at a time (that's the size
  13001 	// of argb_cache), but we currently don't need more than that.
  13002 	if num_rows > 0 { // Emit output.
  13003 		io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  13004 		**(**uintptr)(__ccgo_up(bp)) = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13005 		in_stride = libc.Int32FromUint64(libc.Uint64FromInt32((*VP8Io)(unsafe.Pointer(io)).Fwidth) * uint64(4)) // in unit of RGBA
  13006 		ApplyInverseTransforms(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, num_rows, rows)
  13007 		if !(SetCropWindow(tls, io, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, row, bp, in_stride) != 0) {
  13008 			// Nothing to output (this time).
  13009 		} else {
  13010 			output = (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput
  13011 			v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace < int32(MODE_YUV))
  13012 			goto _2
  13013 		_2:
  13014 			if v1 != 0 { // convert to RGBA
  13015 				buf = output + 16
  13016 				rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
  13017 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13018 					v3 = EmitRescaledRowsRGBA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, rgba, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
  13019 				} else {
  13020 					v3 = EmitRows(tls, (*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, rgba, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
  13021 				}
  13022 				num_rows_out = v3
  13023 				// Update 'last_out_row'.
  13024 				**(**int32)(__ccgo_up(dec + 148)) += num_rows_out
  13025 			} else { // convert to YUVA
  13026 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13027 					v1 = EmitRescaledRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13028 				} else {
  13029 					v1 = EmitRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13030 				}
  13031 				(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13032 			}
  13033 		}
  13034 	}
  13035 	// Update 'last_row'.
  13036 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = row
  13037 }
  13038 
  13039 // C documentation
  13040 //
  13041 //	// Row-processing for the special case when alpha data contains only one
  13042 //	// transform (color indexing), and trivial non-green literals.
  13043 func Is8bOptimizable(tls *libc.TLS, hdr uintptr) (r int32) {
  13044 	var htrees uintptr
  13045 	var i int32
  13046 	_, _ = htrees, i
  13047 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13048 		return 0
  13049 	}
  13050 	// When the Huffman tree contains only one symbol, we can skip the
  13051 	// call to ReadSymbol() for red/blue/alpha channels.
  13052 	i = 0
  13053 	for {
  13054 		if !(i < (*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups) {
  13055 			break
  13056 		}
  13057 		htrees = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(i)*568
  13058 		if libc.Int32FromUint8((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fbits) > 0 {
  13059 			return 0
  13060 		}
  13061 		if libc.Int32FromUint8((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fbits) > 0 {
  13062 			return 0
  13063 		}
  13064 		if libc.Int32FromUint8((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fbits) > 0 {
  13065 			return 0
  13066 		}
  13067 		goto _1
  13068 	_1:
  13069 		;
  13070 		i = i + 1
  13071 	}
  13072 	return int32(1)
  13073 }
  13074 
  13075 func AlphaApplyFilter(tls *libc.TLS, alph_dec uintptr, first_row int32, last_row int32, out uintptr, stride int32) {
  13076 	var prev_line uintptr
  13077 	var y int32
  13078 	_, _ = prev_line, y
  13079 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter != int32(WEBP_FILTER_NONE) {
  13080 		prev_line = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line
  13081 		y = first_row
  13082 		for {
  13083 			if !(y < last_row) {
  13084 				break
  13085 			}
  13086 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, out, out, stride)
  13087 			prev_line = out
  13088 			out = out + uintptr(stride)
  13089 			goto _1
  13090 		_1:
  13091 			;
  13092 			y = y + 1
  13093 		}
  13094 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line = prev_line
  13095 	}
  13096 }
  13097 
  13098 func ExtractPalettedAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  13099 	var alph_dec, in, out, transform uintptr
  13100 	var first_row, top_row, width, v1, v2 int32
  13101 	_, _, _, _, _, _, _, _, _ = alph_dec, first_row, in, out, top_row, transform, width, v1, v2
  13102 	// For vertical and gradient filtering, we need to decode the part above the
  13103 	// crop_top row, in order to have the correct spatial predictors.
  13104 	alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  13105 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_NONE) || (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_HORIZONTAL) {
  13106 		v1 = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fcrop_top
  13107 	} else {
  13108 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13109 	}
  13110 	top_row = v1
  13111 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row < top_row {
  13112 		v2 = top_row
  13113 	} else {
  13114 		v2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13115 	}
  13116 	first_row = v2
  13117 	if last_row > first_row {
  13118 		// Special method for paletted alpha data. We only process the cropped area.
  13119 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth
  13120 		out = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput + uintptr(width*first_row)
  13121 		in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*first_row)
  13122 		transform = dec + 280
  13123 		VP8LColorIndexInverseTransformAlpha(tls, transform, first_row, last_row, in, out)
  13124 		AlphaApplyFilter(tls, alph_dec, first_row, last_row, out, width)
  13125 	}
  13126 	v1 = last_row
  13127 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13128 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  13129 }
  13130 
  13131 //------------------------------------------------------------------------------
  13132 // Helper functions for fast pattern copy (8b and 32b)
  13133 
  13134 // C documentation
  13135 //
  13136 //	// cyclic rotation of pattern word
  13137 func Rotate8b(tls *libc.TLS, V uint32_t) (r uint32_t) {
  13138 	return V&uint32(0xff)<<int32(24) | V>>libc.Int32FromInt32(8)
  13139 }
  13140 
  13141 // C documentation
  13142 //
  13143 //	// copy 1, 2 or 4-bytes pattern
  13144 func CopySmallPattern8b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint32_t) {
  13145 	var i int32
  13146 	var v1, v2 uintptr
  13147 	_, _, _ = i, v1, v2
  13148 	// align 'dst' to 4-bytes boundary. Adjust the pattern along the way.
  13149 	for uint64(dst)&uint64(3) != 0 {
  13150 		v1 = dst
  13151 		dst = dst + 1
  13152 		v2 = src
  13153 		src = src + 1
  13154 		**(**uint8_t)(__ccgo_up(v1)) = **(**uint8_t)(__ccgo_up(v2))
  13155 		pattern = Rotate8b(tls, pattern)
  13156 		length = length - 1
  13157 	}
  13158 	// Copy the pattern 4 bytes at a time.
  13159 	i = 0
  13160 	for {
  13161 		if !(i < length>>int32(2)) {
  13162 			break
  13163 		}
  13164 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = pattern
  13165 		goto _3
  13166 	_3:
  13167 		;
  13168 		i = i + 1
  13169 	}
  13170 	// Finish with left-overs. 'pattern' is still correctly positioned,
  13171 	// so no Rotate8b() call is needed.
  13172 	i = i << int32(2)
  13173 	for {
  13174 		if !(i < length) {
  13175 			break
  13176 		}
  13177 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13178 		goto _4
  13179 	_4:
  13180 		;
  13181 		i = i + 1
  13182 	}
  13183 }
  13184 
  13185 func CopyBlock8b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13186 	bp := tls.Alloc(16)
  13187 	defer tls.Free(16)
  13188 	var i int32
  13189 	var src uintptr
  13190 	var _ /* pattern at bp+0 */ uint32_t
  13191 	_, _ = i, src
  13192 	src = dst - uintptr(dist)
  13193 	if length >= int32(8) {
  13194 		**(**uint32_t)(__ccgo_up(bp)) = uint32(0)
  13195 		switch dist {
  13196 		case int32(1):
  13197 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(src)))
  13198 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x01010101) * **(**uint32_t)(__ccgo_up(bp))
  13199 		case int32(2):
  13200 			libc.Xmemcpy(tls, bp, src, uint64(2))
  13201 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x00010001) * **(**uint32_t)(__ccgo_up(bp))
  13202 		case int32(4):
  13203 			libc.Xmemcpy(tls, bp, src, uint64(4))
  13204 		default:
  13205 			goto Copy
  13206 		}
  13207 		CopySmallPattern8b(tls, src, dst, length, **(**uint32_t)(__ccgo_up(bp)))
  13208 		return
  13209 	}
  13210 	goto Copy
  13211 Copy:
  13212 	;
  13213 	if dist >= length { // no overlap -> use memcpy()
  13214 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(length)*uint64(1))
  13215 	} else {
  13216 		i = 0
  13217 		for {
  13218 			if !(i < length) {
  13219 				break
  13220 			}
  13221 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13222 			goto _1
  13223 		_1:
  13224 			;
  13225 			i = i + 1
  13226 		}
  13227 	}
  13228 }
  13229 
  13230 // C documentation
  13231 //
  13232 //	// copy pattern of 1 or 2 uint32_t's
  13233 func CopySmallPattern32b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint64_t) {
  13234 	var i int32
  13235 	var v1, v2 uintptr
  13236 	_, _, _ = i, v1, v2
  13237 	if uint64(dst)&uint64(4) != 0 { // Align 'dst' to 8-bytes boundary.
  13238 		v1 = dst
  13239 		dst += 4
  13240 		v2 = src
  13241 		src += 4
  13242 		**(**uint32_t)(__ccgo_up(v1)) = **(**uint32_t)(__ccgo_up(v2))
  13243 		pattern = pattern>>libc.Int32FromInt32(32) | pattern<<libc.Int32FromInt32(32)
  13244 		length = length - 1
  13245 	}
  13246 	i = 0
  13247 	for {
  13248 		if !(i < length>>int32(1)) {
  13249 			break
  13250 		}
  13251 		**(**uint64_t)(__ccgo_up(dst + uintptr(i)*8)) = pattern // Copy the pattern 8 bytes at a time.
  13252 		goto _3
  13253 	_3:
  13254 		;
  13255 		i = i + 1
  13256 	}
  13257 	if length&int32(1) != 0 { // Finish with left-over.
  13258 		**(**uint32_t)(__ccgo_up(dst + uintptr(i<<int32(1))*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i<<int32(1))*4))
  13259 	}
  13260 }
  13261 
  13262 func CopyBlock32b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13263 	bp := tls.Alloc(16)
  13264 	defer tls.Free(16)
  13265 	var i int32
  13266 	var src uintptr
  13267 	var _ /* pattern at bp+0 */ uint64_t
  13268 	_, _ = i, src
  13269 	src = dst - uintptr(dist)*4
  13270 	if dist <= int32(2) && length >= int32(4) && uint64(dst)&uint64(3) == uint64(0) {
  13271 		if dist == int32(1) {
  13272 			**(**uint64_t)(__ccgo_up(bp)) = uint64(**(**uint32_t)(__ccgo_up(src)))
  13273 			**(**uint64_t)(__ccgo_up(bp)) = **(**uint64_t)(__ccgo_up(bp)) | **(**uint64_t)(__ccgo_up(bp))<<int32(32)
  13274 		} else {
  13275 			libc.Xmemcpy(tls, bp, src, uint64(8))
  13276 		}
  13277 		CopySmallPattern32b(tls, src, dst, length, **(**uint64_t)(__ccgo_up(bp)))
  13278 	} else {
  13279 		if dist >= length { // no overlap
  13280 			libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(length)*uint64(4))
  13281 		} else {
  13282 			i = 0
  13283 			for {
  13284 				if !(i < length) {
  13285 					break
  13286 				}
  13287 				**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  13288 				goto _1
  13289 			_1:
  13290 				;
  13291 				i = i + 1
  13292 			}
  13293 		}
  13294 	}
  13295 }
  13296 
  13297 //------------------------------------------------------------------------------
  13298 
  13299 func DecodeAlphaData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32) (r int32) {
  13300 	var br2, hdr, htree_group, v1 uintptr
  13301 	var code, col, dist, dist_code, dist_symbol, end, last, len_code_limit, length, length_sym, mask, ok, pos, row, v5 int32
  13302 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = br2, code, col, dist, dist_code, dist_symbol, end, hdr, htree_group, last, len_code_limit, length, length_sym, mask, ok, pos, row, v1, v5
  13303 	ok = int32(1)
  13304 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13305 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13306 	br2 = dec + 40
  13307 	hdr = dec + 152
  13308 	pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel // current position
  13309 	end = width * height                                  // End of data
  13310 	last = width * last_row                               // Last pixel to decode
  13311 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13312 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13313 	if pos < last {
  13314 		v1 = GetHtreeGroupForPos(tls, hdr, col, row)
  13315 	} else {
  13316 		v1 = libc.UintptrFromInt32(0)
  13317 	}
  13318 	htree_group = v1
  13319 	for !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) && pos < last {
  13320 		// Only update when changing tile.
  13321 		if col&mask == 0 {
  13322 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13323 		}
  13324 		v1 = br2
  13325 		if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13326 			VP8LDoFillBitWindow(tls, v1)
  13327 		}
  13328 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13329 		if code < int32(NUM_LITERAL_CODES) { // Literal
  13330 			**(**uint8_t)(__ccgo_up(data + uintptr(pos))) = libc.Uint8FromInt32(code)
  13331 			pos = pos + 1
  13332 			col = col + 1
  13333 			if col >= width {
  13334 				col = 0
  13335 				row = row + 1
  13336 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13337 					ExtractPalettedAlphaRows(tls, dec, row)
  13338 				}
  13339 			}
  13340 		} else {
  13341 			if code < len_code_limit {
  13342 				length_sym = code - int32(NUM_LITERAL_CODES)
  13343 				length = GetCopyLength(tls, length_sym, br2)
  13344 				dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13345 				v1 = br2
  13346 				if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13347 					VP8LDoFillBitWindow(tls, v1)
  13348 				}
  13349 				dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13350 				dist = PlaneCodeToDistance(tls, width, dist_code)
  13351 				if pos >= dist && end-pos >= length {
  13352 					CopyBlock8b(tls, data+uintptr(pos), dist, length)
  13353 				} else {
  13354 					ok = 0
  13355 					goto End
  13356 				}
  13357 				pos = pos + length
  13358 				col = col + length
  13359 				for col >= width {
  13360 					col = col - width
  13361 					row = row + 1
  13362 					if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13363 						ExtractPalettedAlphaRows(tls, dec, row)
  13364 					}
  13365 				}
  13366 				if pos < last && col&mask != 0 {
  13367 					htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13368 				}
  13369 			} else { // Not reached
  13370 				ok = 0
  13371 				goto End
  13372 			}
  13373 		}
  13374 		v1 = br2
  13375 		v5 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v1)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v1)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v1)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos > int32(VP8L_LBITS))
  13376 		goto _6
  13377 	_6:
  13378 		(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13379 	}
  13380 	// Process the remaining rows corresponding to last row-block.
  13381 	if row > last_row {
  13382 		v5 = last_row
  13383 	} else {
  13384 		v5 = row
  13385 	}
  13386 	ExtractPalettedAlphaRows(tls, dec, v5)
  13387 	goto End
  13388 End:
  13389 	;
  13390 	v1 = br2
  13391 	v5 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v1)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v1)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v1)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos > int32(VP8L_LBITS))
  13392 	goto _10
  13393 _10:
  13394 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13395 	if !(ok != 0) || (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && pos < end {
  13396 		if (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 {
  13397 			v5 = int32(VP8_STATUS_SUSPENDED)
  13398 		} else {
  13399 			v5 = int32(VP8_STATUS_BITSTREAM_ERROR)
  13400 		}
  13401 		return VP8LSetError(tls, dec, v5)
  13402 	}
  13403 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = pos
  13404 	return ok
  13405 }
  13406 
  13407 func SaveState(tls *libc.TLS, dec uintptr, last_pixel int32) {
  13408 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br = (*VP8LDecoder)(unsafe.Pointer(dec)).Fbr
  13409 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel = last_pixel
  13410 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13411 		VP8LColorCacheCopy(tls, dec+152+8, dec+152+24)
  13412 	}
  13413 }
  13414 
  13415 func RestoreState(tls *libc.TLS, dec uintptr) {
  13416 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
  13417 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fbr = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br
  13418 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel
  13419 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13420 		VP8LColorCacheCopy(tls, dec+152+24, dec+152+8)
  13421 	}
  13422 }
  13423 
  13424 func DecodeImageData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32, __ccgo_fp_process_func ProcessRowsFunc) (r int32) {
  13425 	var alpha, blue, code, col, color_cache_limit, dist, dist_code, dist_symbol, key1, key2, len_code_limit, length, length_sym, mask, next_sync_row, red, row, v1 int32
  13426 	var br2, color_cache, hdr, htree_group, last_cached, src, src_end, src_last, v2, v3 uintptr
  13427 	var v21 uint32_t
  13428 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha, blue, br2, code, col, color_cache, color_cache_limit, dist, dist_code, dist_symbol, hdr, htree_group, key1, key2, last_cached, len_code_limit, length, length_sym, mask, next_sync_row, red, row, src, src_end, src_last, v1, v2, v21, v3
  13429 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13430 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13431 	br2 = dec + 40
  13432 	hdr = dec + 152
  13433 	src = data + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel)*4
  13434 	last_cached = src
  13435 	src_end = data + uintptr(width*height)*4    // End of data
  13436 	src_last = data + uintptr(width*last_row)*4 // Last pixel to decode
  13437 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13438 	color_cache_limit = len_code_limit + (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size
  13439 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  13440 		v1 = row
  13441 	} else {
  13442 		v1 = libc.Int32FromInt32(1) << libc.Int32FromInt32(24)
  13443 	}
  13444 	next_sync_row = v1
  13445 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13446 		v2 = hdr + 8
  13447 	} else {
  13448 		v2 = libc.UintptrFromInt32(0)
  13449 	}
  13450 	color_cache = v2
  13451 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13452 	if src < src_last {
  13453 		v3 = GetHtreeGroupForPos(tls, hdr, col, row)
  13454 	} else {
  13455 		v3 = libc.UintptrFromInt32(0)
  13456 	}
  13457 	htree_group = v3
  13458 _5:
  13459 	;
  13460 	if !(src < src_last) {
  13461 		goto _4
  13462 	}
  13463 	if row >= next_sync_row {
  13464 		SaveState(tls, dec, int32((int64(src)-int64(data))/4))
  13465 		next_sync_row = row + int32(SYNC_EVERY_N_ROWS)
  13466 	}
  13467 	// Only update when changing tile. Note we could use this test:
  13468 	// if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed
  13469 	// but that's actually slower and needs storing the previous col/row.
  13470 	if col&mask == 0 {
  13471 		htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13472 	}
  13473 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code != 0 {
  13474 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb
  13475 		goto AdvanceByOne
  13476 	}
  13477 	v2 = br2
  13478 	if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13479 		VP8LDoFillBitWindow(tls, v2)
  13480 	}
  13481 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  13482 		code = ReadPackedSymbols(tls, htree_group, br2, src)
  13483 		v2 = br2
  13484 		v1 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v2)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v2)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v2)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos > int32(VP8L_LBITS))
  13485 		goto _9
  13486 	_9:
  13487 		if v1 != 0 {
  13488 			goto _4
  13489 		}
  13490 		if code == PACKED_NON_LITERAL_CODE {
  13491 			goto AdvanceByOne
  13492 		}
  13493 	} else {
  13494 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13495 	}
  13496 	v2 = br2
  13497 	v1 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v2)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v2)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v2)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos > int32(VP8L_LBITS))
  13498 	goto _12
  13499 _12:
  13500 	if v1 != 0 {
  13501 		goto _4
  13502 	}
  13503 	if !(code < int32(NUM_LITERAL_CODES)) {
  13504 		goto _13
  13505 	} // Literal
  13506 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal != 0 {
  13507 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb | libc.Uint32FromInt32(code<<libc.Int32FromInt32(8))
  13508 	} else {
  13509 		red = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)), br2)
  13510 		v2 = br2
  13511 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13512 			VP8LDoFillBitWindow(tls, v2)
  13513 		}
  13514 		blue = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)), br2)
  13515 		alpha = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)), br2)
  13516 		v2 = br2
  13517 		v1 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v2)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v2)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v2)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos > int32(VP8L_LBITS))
  13518 		goto _18
  13519 	_18:
  13520 		if v1 != 0 {
  13521 			goto _4
  13522 		}
  13523 		**(**uint32_t)(__ccgo_up(src)) = libc.Uint32FromInt32(alpha)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(code<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(blue)
  13524 	}
  13525 	goto AdvanceByOne
  13526 AdvanceByOne:
  13527 	;
  13528 	src += 4
  13529 	col = col + 1
  13530 	if col >= width {
  13531 		col = 0
  13532 		row = row + 1
  13533 		if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13534 			if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13535 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13536 			}
  13537 		}
  13538 		if color_cache != libc.UintptrFromInt32(0) {
  13539 			for last_cached < src {
  13540 				v2 = last_cached
  13541 				last_cached += 4
  13542 				v3 = color_cache
  13543 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13544 				v1 = libc.Int32FromUint32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13545 				goto _23
  13546 			_23:
  13547 				key1 = v1
  13548 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13549 			}
  13550 		}
  13551 	}
  13552 	goto _14
  13553 _13:
  13554 	;
  13555 	if code < len_code_limit {
  13556 		length_sym = code - int32(NUM_LITERAL_CODES)
  13557 		length = GetCopyLength(tls, length_sym, br2)
  13558 		dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13559 		v2 = br2
  13560 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13561 			VP8LDoFillBitWindow(tls, v2)
  13562 		}
  13563 		dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13564 		dist = PlaneCodeToDistance(tls, width, dist_code)
  13565 		v2 = br2
  13566 		v1 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v2)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v2)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v2)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos > int32(VP8L_LBITS))
  13567 		goto _27
  13568 	_27:
  13569 		if v1 != 0 {
  13570 			goto _4
  13571 		}
  13572 		if (int64(src)-int64(data))/4 < int64(dist) || (int64(src_end)-int64(src))/4 < int64(length) {
  13573 			goto Error
  13574 		} else {
  13575 			CopyBlock32b(tls, src, dist, length)
  13576 		}
  13577 		src = src + uintptr(length)*4
  13578 		col = col + length
  13579 		for col >= width {
  13580 			col = col - width
  13581 			row = row + 1
  13582 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13583 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13584 					(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13585 				}
  13586 			}
  13587 		}
  13588 		// Because of the check done above (before 'src' was incremented by
  13589 		// 'length'), the following holds true.
  13590 		if col&mask != 0 {
  13591 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13592 		}
  13593 		if color_cache != libc.UintptrFromInt32(0) {
  13594 			for last_cached < src {
  13595 				v2 = last_cached
  13596 				last_cached += 4
  13597 				v3 = color_cache
  13598 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13599 				v1 = libc.Int32FromUint32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13600 				goto _32
  13601 			_32:
  13602 				key1 = v1
  13603 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13604 			}
  13605 		}
  13606 	} else {
  13607 		if code < color_cache_limit { // Color cache
  13608 			key2 = code - len_code_limit
  13609 			for last_cached < src {
  13610 				v2 = last_cached
  13611 				last_cached += 4
  13612 				v3 = color_cache
  13613 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13614 				v1 = libc.Int32FromUint32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13615 				goto _37
  13616 			_37:
  13617 				key1 = v1
  13618 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13619 			}
  13620 			v21 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors + uintptr(libc.Uint32FromInt32(key2))*4))
  13621 			goto _39
  13622 		_39:
  13623 			**(**uint32_t)(__ccgo_up(src)) = v21
  13624 			goto AdvanceByOne
  13625 		} else { // Not reached
  13626 			goto Error
  13627 		}
  13628 	}
  13629 _14:
  13630 	;
  13631 	goto _5
  13632 _4:
  13633 	;
  13634 	v2 = br2
  13635 	v1 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v2)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v2)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v2)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos > int32(VP8L_LBITS))
  13636 	goto _42
  13637 _42:
  13638 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v1
  13639 	// In incremental decoding:
  13640 	// br->eos && src < src_last: if 'br' reached the end of the buffer and
  13641 	// 'src_last' has not been reached yet, there is not enough data. 'dec' has to
  13642 	// be reset until there is more data.
  13643 	// !br->eos && src < src_last: this cannot happen as either the buffer is
  13644 	// fully read, either enough has been read to reach 'src_last'.
  13645 	// src >= src_last: 'src_last' is reached, all is fine. 'src' can actually go
  13646 	// beyond 'src_last' in case the image is cropped and an LZ77 goes further.
  13647 	// The buffer might have been enough or there is some left. 'br->eos' does
  13648 	// not matter.
  13649 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && src < src_last {
  13650 		RestoreState(tls, dec)
  13651 	} else {
  13652 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && src >= src_last || !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) {
  13653 			// Process the remaining rows corresponding to last row-block.
  13654 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13655 				if row > last_row {
  13656 					v1 = last_row
  13657 				} else {
  13658 					v1 = row
  13659 				}
  13660 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, v1)
  13661 			}
  13662 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  13663 			(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = int32((int64(src) - int64(data)) / 4) // end-of-scan marker
  13664 		} else {
  13665 			// if not incremental, and we are past the end of buffer (eos=1), then this
  13666 			// is a real bitstream error.
  13667 			goto Error
  13668 		}
  13669 	}
  13670 	return int32(1)
  13671 	goto Error
  13672 Error:
  13673 	;
  13674 	return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  13675 	return r
  13676 }
  13677 
  13678 // -----------------------------------------------------------------------------
  13679 // VP8LTransform
  13680 
  13681 func ClearTransform(tls *libc.TLS, transform uintptr) {
  13682 	WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  13683 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  13684 }
  13685 
  13686 // C documentation
  13687 //
  13688 //	// For security reason, we need to remap the color map to span
  13689 //	// the total possible bundled values, and not just the num_colors.
  13690 func ExpandColorMap(tls *libc.TLS, num_colors int32, transform uintptr) (r int32) {
  13691 	var data, new_color_map, new_data uintptr
  13692 	var final_num_colors, i int32
  13693 	_, _, _, _, _ = data, final_num_colors, i, new_color_map, new_data
  13694 	final_num_colors = int32(1) << (int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  13695 	new_color_map = WebPSafeMalloc(tls, libc.Uint64FromInt32(final_num_colors), uint64(4))
  13696 	if new_color_map == libc.UintptrFromInt32(0) {
  13697 		return 0
  13698 	} else {
  13699 		data = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  13700 		new_data = new_color_map
  13701 		**(**uint32_t)(__ccgo_up(new_color_map)) = **(**uint32_t)(__ccgo_up((*VP8LTransform)(unsafe.Pointer(transform)).Fdata))
  13702 		i = int32(4)
  13703 		for {
  13704 			if !(i < int32(4)*num_colors) {
  13705 				break
  13706 			}
  13707 			// Equivalent to VP8LAddPixels(), on a byte-basis.
  13708 			**(**uint8_t)(__ccgo_up(new_data + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(i)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(new_data + uintptr(i-int32(4)))))) & int32(0xff))
  13709 			goto _1
  13710 		_1:
  13711 			;
  13712 			i = i + 1
  13713 		}
  13714 		for {
  13715 			if !(i < int32(4)*final_num_colors) {
  13716 				break
  13717 			}
  13718 			**(**uint8_t)(__ccgo_up(new_data + uintptr(i))) = uint8(0) // black tail.
  13719 			goto _2
  13720 		_2:
  13721 			;
  13722 			i = i + 1
  13723 		}
  13724 		WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  13725 		(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = new_color_map
  13726 	}
  13727 	return int32(1)
  13728 }
  13729 
  13730 func ReadTransform(tls *libc.TLS, xsize uintptr, ysize uintptr, dec uintptr) (r int32) {
  13731 	var bits, num_colors, ok, v7, v8, v9 int32
  13732 	var br, transform uintptr
  13733 	var type1 VP8LImageTransformType
  13734 	var v1, v2, v4, v5 uint32_t
  13735 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bits, br, num_colors, ok, transform, type1, v1, v2, v4, v5, v7, v8, v9
  13736 	ok = int32(1)
  13737 	br = dec + 40
  13738 	transform = dec + 280 + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform)*24
  13739 	type1 = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(2)))
  13740 	// Each transform type can only be present once in the stream.
  13741 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen&(uint32(1)<<type1) != 0 {
  13742 		return 0 // Already there, let's not accept the second same transform.
  13743 	}
  13744 	**(**uint32_t)(__ccgo_up(dec + 376)) |= uint32(1) << type1
  13745 	(*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 = type1
  13746 	(*VP8LTransform)(unsafe.Pointer(transform)).Fxsize = **(**int32)(__ccgo_up(xsize))
  13747 	(*VP8LTransform)(unsafe.Pointer(transform)).Fysize = **(**int32)(__ccgo_up(ysize))
  13748 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  13749 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform + 1
  13750 	switch type1 {
  13751 	case int32(PREDICTOR_TRANSFORM):
  13752 		fallthrough
  13753 	case int32(CROSS_COLOR_TRANSFORM):
  13754 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = libc.Int32FromUint32(uint32(MIN_TRANSFORM_BITS) + VP8LReadBits(tls, br, int32(NUM_TRANSFORM_BITS)))
  13755 		v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  13756 		v2 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  13757 		goto _3
  13758 	_3:
  13759 		v4 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  13760 		v5 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fysize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  13761 		goto _6
  13762 	_6:
  13763 		ok = DecodeImageStream(tls, libc.Int32FromUint32(v2), libc.Int32FromUint32(v5), 0, dec, transform+16)
  13764 	case int32(COLOR_INDEXING_TRANSFORM):
  13765 		num_colors = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(8)) + uint32(1))
  13766 		if num_colors > int32(16) {
  13767 			v7 = 0
  13768 		} else {
  13769 			if num_colors > int32(4) {
  13770 				v8 = int32(1)
  13771 			} else {
  13772 				if num_colors > int32(2) {
  13773 					v9 = int32(2)
  13774 				} else {
  13775 					v9 = int32(3)
  13776 				}
  13777 				v8 = v9
  13778 			}
  13779 			v7 = v8
  13780 		}
  13781 		bits = v7
  13782 		v1 = libc.Uint32FromInt32(bits)
  13783 		v2 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  13784 		goto _12
  13785 	_12:
  13786 		**(**int32)(__ccgo_up(xsize)) = libc.Int32FromUint32(v2)
  13787 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = bits
  13788 		ok = DecodeImageStream(tls, num_colors, int32(1), 0, dec, transform+16)
  13789 		if ok != 0 && !(ExpandColorMap(tls, num_colors, transform) != 0) {
  13790 			return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13791 		}
  13792 	case int32(SUBTRACT_GREEN_TRANSFORM):
  13793 	default:
  13794 		// can't happen
  13795 		break
  13796 	}
  13797 	return ok
  13798 }
  13799 
  13800 // -----------------------------------------------------------------------------
  13801 // VP8LMetadata
  13802 
  13803 func InitMetadata(tls *libc.TLS, hdr uintptr) {
  13804 	libc.Xmemset(tls, hdr, 0, uint64(120))
  13805 }
  13806 
  13807 func ClearMetadata(tls *libc.TLS, hdr uintptr) {
  13808 	WebPSafeFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image)
  13809 	VP8LHuffmanTablesDeallocate(tls, hdr+80)
  13810 	VP8LHtreeGroupsFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups)
  13811 	VP8LColorCacheClear(tls, hdr+8)
  13812 	VP8LColorCacheClear(tls, hdr+24)
  13813 	InitMetadata(tls, hdr)
  13814 }
  13815 
  13816 // -----------------------------------------------------------------------------
  13817 // VP8LDecoder
  13818 
  13819 func VP8LNew(tls *libc.TLS) (r uintptr) {
  13820 	var dec uintptr
  13821 	_ = dec
  13822 	dec = WebPSafeCalloc(tls, uint64(1), uint64(400))
  13823 	if dec == libc.UintptrFromInt32(0) {
  13824 		return libc.UintptrFromInt32(0)
  13825 	}
  13826 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  13827 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  13828 	VP8LDspInit(tls) // Init critical function pointers.
  13829 	return dec
  13830 }
  13831 
  13832 // C documentation
  13833 //
  13834 //	// Resets the decoder in its initial state, reclaiming memory.
  13835 //	// Preserves the dec->status value.
  13836 func VP8LClear(tls *libc.TLS, dec uintptr) {
  13837 	var i int32
  13838 	_ = i
  13839 	if dec == libc.UintptrFromInt32(0) {
  13840 		return
  13841 	}
  13842 	ClearMetadata(tls, dec+152)
  13843 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels)
  13844 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = libc.UintptrFromInt32(0)
  13845 	i = 0
  13846 	for {
  13847 		if !(i < (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform) {
  13848 			break
  13849 		}
  13850 		ClearTransform(tls, dec+280+uintptr(i)*24)
  13851 		goto _1
  13852 	_1:
  13853 		;
  13854 		i = i + 1
  13855 	}
  13856 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = 0
  13857 	(*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen = uint32(0)
  13858 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory)
  13859 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = libc.UintptrFromInt32(0)
  13860 	(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = libc.UintptrFromInt32(0) // leave no trace behind
  13861 }
  13862 
  13863 func VP8LDelete(tls *libc.TLS, dec uintptr) {
  13864 	if dec != libc.UintptrFromInt32(0) {
  13865 		VP8LClear(tls, dec)
  13866 		WebPSafeFree(tls, dec)
  13867 	}
  13868 }
  13869 
  13870 func UpdateDecoder(tls *libc.TLS, dec uintptr, width int32, height int32) {
  13871 	var hdr uintptr
  13872 	var num_bits, v4 int32
  13873 	var v1, v2 uint32_t
  13874 	_, _, _, _, _ = hdr, num_bits, v1, v2, v4
  13875 	hdr = dec + 152
  13876 	num_bits = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits
  13877 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = width
  13878 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = height
  13879 	v1 = libc.Uint32FromInt32(num_bits)
  13880 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  13881 	goto _3
  13882 _3:
  13883 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_xsize = libc.Int32FromUint32(v2)
  13884 	if num_bits == 0 {
  13885 		v4 = ^libc.Int32FromInt32(0)
  13886 	} else {
  13887 		v4 = int32(1)<<num_bits - int32(1)
  13888 	}
  13889 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask = v4
  13890 }
  13891 
  13892 func DecodeImageStream(tls *libc.TLS, xsize int32, ysize int32, is_level0 int32, dec uintptr, decoded_data uintptr) (r int32) {
  13893 	bp := tls.Alloc(16)
  13894 	defer tls.Free(16)
  13895 	var br, data, hdr uintptr
  13896 	var color_cache_bits, ok int32
  13897 	var total_size uint64_t
  13898 	var _ /* transform_xsize at bp+0 */ int32
  13899 	var _ /* transform_ysize at bp+4 */ int32
  13900 	_, _, _, _, _, _ = br, color_cache_bits, data, hdr, ok, total_size
  13901 	ok = int32(1)
  13902 	**(**int32)(__ccgo_up(bp)) = xsize
  13903 	**(**int32)(__ccgo_up(bp + 4)) = ysize
  13904 	br = dec + 40
  13905 	hdr = dec + 152
  13906 	data = libc.UintptrFromInt32(0)
  13907 	color_cache_bits = 0
  13908 	// Read the transforms (may recurse).
  13909 	if is_level0 != 0 {
  13910 		for ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  13911 			ok = ReadTransform(tls, bp, bp+4, dec)
  13912 		}
  13913 	}
  13914 	// Color cache
  13915 	if ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  13916 		color_cache_bits = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(4)))
  13917 		ok = libc.BoolInt32(color_cache_bits >= int32(1) && color_cache_bits <= int32(MAX_CACHE_BITS))
  13918 		if !(ok != 0) {
  13919 			VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  13920 			goto End
  13921 		}
  13922 	}
  13923 	// Read the Huffman codes (may recurse).
  13924 	ok = libc.BoolInt32(ok != 0 && ReadHuffmanCodes(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), color_cache_bits, is_level0) != 0)
  13925 	if !(ok != 0) {
  13926 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  13927 		goto End
  13928 	}
  13929 	// Finish setting up the color-cache
  13930 	if color_cache_bits > 0 {
  13931 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = int32(1) << color_cache_bits
  13932 		if !(VP8LColorCacheInit(tls, hdr+8, color_cache_bits) != 0) {
  13933 			ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13934 			goto End
  13935 		}
  13936 	} else {
  13937 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = 0
  13938 	}
  13939 	UpdateDecoder(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
  13940 	if is_level0 != 0 { // level 0 complete
  13941 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_HDR)
  13942 		goto End
  13943 	}
  13944 	total_size = libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp))) * libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 4)))
  13945 	data = WebPSafeMalloc(tls, total_size, uint64(4))
  13946 	if data == libc.UintptrFromInt32(0) {
  13947 		ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13948 		goto End
  13949 	}
  13950 	// Use the Huffman trees to decode the LZ77 encoded data.
  13951 	ok = DecodeImageData(tls, dec, data, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), **(**int32)(__ccgo_up(bp + 4)), libc.UintptrFromInt32(0))
  13952 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  13953 	goto End
  13954 End:
  13955 	;
  13956 	if !(ok != 0) {
  13957 		WebPSafeFree(tls, data)
  13958 		ClearMetadata(tls, hdr)
  13959 	} else {
  13960 		if decoded_data != libc.UintptrFromInt32(0) {
  13961 			**(**uintptr)(__ccgo_up(decoded_data)) = data
  13962 		} else {
  13963 			// We allocate image data in this function only for transforms. At level 0
  13964 			// (that is: not the transforms), we shouldn't have allocated anything.
  13965 		}
  13966 		(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = 0 // Reset for future DECODE_DATA_FUNC() calls.
  13967 		if !(is_level0 != 0) {
  13968 			ClearMetadata(tls, hdr)
  13969 		} // Clean up temporary data behind.
  13970 	}
  13971 	return ok
  13972 }
  13973 
  13974 // C documentation
  13975 //
  13976 //	//------------------------------------------------------------------------------
  13977 //	// Allocate internal buffers dec->pixels and dec->argb_cache.
  13978 func AllocateInternalBuffers32b(tls *libc.TLS, dec uintptr, final_width int32) (r int32) {
  13979 	var cache_pixels, cache_top_pixels, num_pixels, total_num_pixels uint64_t
  13980 	_, _, _, _ = cache_pixels, cache_top_pixels, num_pixels, total_num_pixels
  13981 	num_pixels = libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  13982 	// Scratch buffer corresponding to top-prediction row for transforming the
  13983 	// first row in the row-blocks. Not needed for paletted alpha.
  13984 	cache_top_pixels = uint64(libc.Uint16FromInt32(final_width))
  13985 	// Scratch buffer for temporary BGRA storage. Not needed for paletted alpha.
  13986 	cache_pixels = libc.Uint64FromInt32(final_width) * uint64(NUM_ARGB_CACHE_ROWS)
  13987 	total_num_pixels = num_pixels + cache_top_pixels + cache_pixels
  13988 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(4))
  13989 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  13990 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  13991 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13992 	}
  13993 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr(num_pixels)*4 + uintptr(cache_top_pixels)*4
  13994 	return int32(1)
  13995 }
  13996 
  13997 func AllocateInternalBuffers8b(tls *libc.TLS, dec uintptr) (r int32) {
  13998 	var total_num_pixels uint64_t
  13999 	_ = total_num_pixels
  14000 	total_num_pixels = libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14001 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14002 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(1))
  14003 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14004 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14005 	}
  14006 	return int32(1)
  14007 }
  14008 
  14009 //------------------------------------------------------------------------------
  14010 
  14011 // C documentation
  14012 //
  14013 //	// Special row-processing that only stores the alpha data.
  14014 func ExtractAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  14015 	var alph_dec, dst, in, output, src uintptr
  14016 	var cache_pixs, cur_row, num_rows, num_rows_to_process, width, v1 int32
  14017 	_, _, _, _, _, _, _, _, _, _, _ = alph_dec, cache_pixs, cur_row, dst, in, num_rows, num_rows_to_process, output, src, width, v1
  14018 	cur_row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  14019 	num_rows = last_row - cur_row
  14020 	in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*cur_row)*4
  14021 	for num_rows > 0 {
  14022 		if num_rows > int32(NUM_ARGB_CACHE_ROWS) {
  14023 			v1 = int32(NUM_ARGB_CACHE_ROWS)
  14024 		} else {
  14025 			v1 = num_rows
  14026 		}
  14027 		num_rows_to_process = v1
  14028 		// Extract alpha (which is stored in the green plane).
  14029 		alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  14030 		output = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput
  14031 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth // the final width (!= dec->width)
  14032 		cache_pixs = width * num_rows_to_process
  14033 		dst = output + uintptr(width*cur_row)
  14034 		src = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  14035 		ApplyInverseTransforms(tls, dec, cur_row, num_rows_to_process, in)
  14036 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPExtractGreen})))(tls, src, dst, cache_pixs)
  14037 		AlphaApplyFilter(tls, alph_dec, cur_row, cur_row+num_rows_to_process, dst, width)
  14038 		num_rows = num_rows - num_rows_to_process
  14039 		in = in + uintptr(num_rows_to_process*(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth)*4
  14040 		cur_row = cur_row + num_rows_to_process
  14041 	}
  14042 	v1 = last_row
  14043 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  14044 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  14045 }
  14046 
  14047 func VP8LDecodeAlphaHeader(tls *libc.TLS, alph_dec uintptr, data uintptr, data_size size_t) (r int32) {
  14048 	var dec uintptr
  14049 	var ok int32
  14050 	_, _ = dec, ok
  14051 	ok = 0
  14052 	dec = VP8LNew(tls)
  14053 	if dec == libc.UintptrFromInt32(0) {
  14054 		return 0
  14055 	}
  14056 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14057 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14058 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = alph_dec + 32
  14059 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque = alph_dec
  14060 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14061 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14062 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14063 	VP8LInitBitReader(tls, dec+40, data, data_size)
  14064 	if !(DecodeImageStream(tls, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight, int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14065 		goto Err
  14066 	}
  14067 	// Special case: if alpha data uses only the color indexing transform and
  14068 	// doesn't use color cache (a frequent case), we will use DecodeAlphaData()
  14069 	// method that only needs allocation of 1 byte per pixel (alpha channel).
  14070 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform == int32(1) && (**(**VP8LTransform)(__ccgo_up(dec + 280))).Ftype1 == int32(COLOR_INDEXING_TRANSFORM) && Is8bOptimizable(tls, dec+152) != 0 {
  14071 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = int32(1)
  14072 		ok = AllocateInternalBuffers8b(tls, dec)
  14073 	} else {
  14074 		// Allocate internal buffers (note that dec->width may have changed here).
  14075 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = 0
  14076 		ok = AllocateInternalBuffers32b(tls, dec, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth)
  14077 	}
  14078 	if !(ok != 0) {
  14079 		goto Err
  14080 	}
  14081 	// Only set here, once we are sure it is valid (to avoid thread races).
  14082 	(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec = dec
  14083 	return int32(1)
  14084 	goto Err
  14085 Err:
  14086 	;
  14087 	VP8LDelete(tls, dec)
  14088 	return 0
  14089 }
  14090 
  14091 func VP8LDecodeAlphaImageStream(tls *libc.TLS, alph_dec uintptr, last_row int32) (r int32) {
  14092 	var dec uintptr
  14093 	var v1 int32
  14094 	_, _ = dec, v1
  14095 	dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
  14096 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row >= last_row {
  14097 		return int32(1) // done
  14098 	}
  14099 	if !((*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0) {
  14100 		WebPInitAlphaProcessing(tls)
  14101 	}
  14102 	// Decode (with special row processing).
  14103 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0 {
  14104 		v1 = DecodeAlphaData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row)
  14105 	} else {
  14106 		v1 = DecodeImageData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row, __ccgo_fp(ExtractAlphaRows))
  14107 	}
  14108 	return v1
  14109 }
  14110 
  14111 //------------------------------------------------------------------------------
  14112 
  14113 func VP8LDecodeHeader(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  14114 	bp := tls.Alloc(16)
  14115 	defer tls.Free(16)
  14116 	var _ /* has_alpha at bp+8 */ int32
  14117 	var _ /* height at bp+4 */ int32
  14118 	var _ /* width at bp+0 */ int32
  14119 	if dec == libc.UintptrFromInt32(0) {
  14120 		return 0
  14121 	}
  14122 	if io == libc.UintptrFromInt32(0) {
  14123 		return VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14124 	}
  14125 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = io
  14126 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14127 	VP8LInitBitReader(tls, dec+40, (*VP8Io)(unsafe.Pointer(io)).Fdata, (*VP8Io)(unsafe.Pointer(io)).Fdata_size)
  14128 	if !(ReadImageInfo(tls, dec+40, bp, bp+4, bp+8) != 0) {
  14129 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14130 		goto Error
  14131 	}
  14132 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14133 	(*VP8Io)(unsafe.Pointer(io)).Fwidth = **(**int32)(__ccgo_up(bp))
  14134 	(*VP8Io)(unsafe.Pointer(io)).Fheight = **(**int32)(__ccgo_up(bp + 4))
  14135 	if !(DecodeImageStream(tls, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14136 		goto Error
  14137 	}
  14138 	return int32(1)
  14139 	goto Error
  14140 Error:
  14141 	;
  14142 	VP8LClear(tls, dec)
  14143 	return 0
  14144 }
  14145 
  14146 func VP8LDecodeImage(tls *libc.TLS, dec uintptr) (r int32) {
  14147 	var io, params uintptr
  14148 	var v1 WEBP_CSP_MODE1
  14149 	var v2 int32
  14150 	var v4 bool
  14151 	_, _, _, _, _ = io, params, v1, v2, v4
  14152 	io = libc.UintptrFromInt32(0)
  14153 	params = libc.UintptrFromInt32(0)
  14154 	if dec == libc.UintptrFromInt32(0) {
  14155 		return 0
  14156 	}
  14157 	io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  14158 	params = (*VP8Io)(unsafe.Pointer(io)).Fopaque
  14159 	// Initialization.
  14160 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstate != int32(READ_DATA) {
  14161 		(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
  14162 		if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, io, int32(MODE_BGRA)) != 0) {
  14163 			VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14164 			goto Err
  14165 		}
  14166 		if !(AllocateInternalBuffers32b(tls, dec, (*VP8Io)(unsafe.Pointer(io)).Fwidth) != 0) {
  14167 			goto Err
  14168 		}
  14169 		if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 && !(AllocateAndInitRescaler(tls, dec, io) != 0) {
  14170 			goto Err
  14171 		}
  14172 		if v4 = (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0; !v4 {
  14173 			v1 = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  14174 			v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
  14175 			goto _3
  14176 		_3:
  14177 		}
  14178 		if v4 || v2 != 0 {
  14179 			// need the alpha-multiply functions for premultiplied output or rescaling
  14180 			WebPInitAlphaProcessing(tls)
  14181 		}
  14182 		v2 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace < int32(MODE_YUV))
  14183 		goto _6
  14184 	_6:
  14185 		if !(v2 != 0) {
  14186 			WebPInitConvertARGBToYUV(tls)
  14187 			if (*(*WebPYUVABuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput + 16))).Fa != libc.UintptrFromInt32(0) {
  14188 				WebPInitAlphaProcessing(tls)
  14189 			}
  14190 		}
  14191 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  14192 			if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 && (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fsaved_color_cache.Fcolors == libc.UintptrFromInt32(0) {
  14193 				if !(VP8LColorCacheInit(tls, dec+152+24, (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache.Fhash_bits) != 0) {
  14194 					VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14195 					goto Err
  14196 				}
  14197 			}
  14198 		}
  14199 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DATA)
  14200 	}
  14201 	// Decode.
  14202 	if !(DecodeImageData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom, __ccgo_fp(ProcessRows)) != 0) {
  14203 		goto Err
  14204 	}
  14205 	(*WebPDecParams)(unsafe.Pointer(params)).Flast_y = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  14206 	return int32(1)
  14207 	goto Err
  14208 Err:
  14209 	;
  14210 	VP8LClear(tls, dec)
  14211 	return 0
  14212 }
  14213 
  14214 const VP8L_MAGIC_BYTE2 = 0x2f
  14215 
  14216 var kHashMul9 = uint32(0x1e35a7bd)
  14217 
  14218 type WebPData = struct {
  14219 	Fbytes uintptr
  14220 	Fsize  size_t
  14221 }
  14222 
  14223 type WebPFeatureFlags1 = int32
  14224 
  14225 type WebPFeatureFlags = int32
  14226 
  14227 const ANIMATION_FLAG = 2
  14228 const XMP_FLAG = 4
  14229 const EXIF_FLAG = 8
  14230 const ALPHA_FLAG = 16
  14231 const ICCP_FLAG = 32
  14232 const ALL_VALID_FLAGS = 62
  14233 
  14234 type WebPMuxAnimDispose1 = int32
  14235 
  14236 type WebPMuxAnimDispose = int32
  14237 
  14238 const WEBP_MUX_DISPOSE_NONE = 0
  14239 const WEBP_MUX_DISPOSE_BACKGROUND = 1
  14240 
  14241 type WebPMuxAnimBlend1 = int32
  14242 
  14243 type WebPMuxAnimBlend = int32
  14244 
  14245 const WEBP_MUX_BLEND = 0
  14246 const WEBP_MUX_NO_BLEND = 1
  14247 
  14248 // Copyright 2010 Google Inc. All Rights Reserved.
  14249 //
  14250 // Use of this source code is governed by a BSD-style license
  14251 // that can be found in the COPYING file in the root of the source
  14252 // tree. An additional intellectual property rights grant can be found
  14253 // in the file PATENTS. All contributing project authors may
  14254 // be found in the AUTHORS file in the root of the source tree.
  14255 // -----------------------------------------------------------------------------
  14256 //
  14257 //  Common types + memory wrappers
  14258 //
  14259 // Author: Skal (pascal.massimino@gmail.com)
  14260 
  14261 //------------------------------------------------------------------------------
  14262 // RIFF layout is:
  14263 //   Offset  tag
  14264 //   0...3   "RIFF" 4-byte tag
  14265 //   4...7   size of image data (including metadata) starting at offset 8
  14266 //   8...11  "WEBP"   our form-type signature
  14267 // The RIFF container (12 bytes) is followed by appropriate chunks:
  14268 //   12..15  "VP8 ": 4-bytes tags, signaling the use of VP8 video format
  14269 //   16..19  size of the raw VP8 image data, starting at offset 20
  14270 //   20....  the VP8 bytes
  14271 // Or,
  14272 //   12..15  "VP8L": 4-bytes tags, signaling the use of VP8L lossless format
  14273 //   16..19  size of the raw VP8L image data, starting at offset 20
  14274 //   20....  the VP8L bytes
  14275 // Or,
  14276 //   12..15  "VP8X": 4-bytes tags, describing the extended-VP8 chunk.
  14277 //   16..19  size of the VP8X chunk starting at offset 20.
  14278 //   20..23  VP8X flags bit-map corresponding to the chunk-types present.
  14279 //   24..26  Width of the Canvas Image.
  14280 //   27..29  Height of the Canvas Image.
  14281 // There can be extra chunks after the "VP8X" chunk (ICCP, ANMF, VP8, VP8L,
  14282 // XMP, EXIF  ...)
  14283 // All sizes are in little-endian order.
  14284 // Note: chunk data size must be padded to multiple of 2 when written.
  14285 
  14286 // C documentation
  14287 //
  14288 //	// Validates the RIFF container (if detected) and skips over it.
  14289 //	// If a RIFF container is detected, returns:
  14290 //	//     VP8_STATUS_BITSTREAM_ERROR for invalid header,
  14291 //	//     VP8_STATUS_NOT_ENOUGH_DATA for truncated data if have_all_data is true,
  14292 //	// and VP8_STATUS_OK otherwise.
  14293 //	// In case there are not enough bytes (partial RIFF container), return 0 for
  14294 //	// *riff_size. Else return the RIFF size extracted from the header.
  14295 func ParseRIFF(tls *libc.TLS, data2 uintptr, data_size uintptr, have_all_data int32, riff_size uintptr) (r VP8StatusCode1) {
  14296 	var size, v2 uint32_t
  14297 	var v1, v4, v7 uintptr
  14298 	var v5, v8 int32
  14299 	_, _, _, _, _, _, _ = size, v1, v2, v4, v5, v7, v8
  14300 	**(**size_t)(__ccgo_up(riff_size)) = uint64(0) // Default: no RIFF present.
  14301 	if **(**size_t)(__ccgo_up(data_size)) >= uint64(RIFF_HEADER_SIZE) && !(libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data2)), __ccgo_ts+564, uint64(TAG_SIZE)) != 0) {
  14302 		if libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data2))+uintptr(8), __ccgo_ts+569, uint64(TAG_SIZE)) != 0 {
  14303 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong image file signature.
  14304 		} else {
  14305 			v1 = **(**uintptr)(__ccgo_up(data2)) + uintptr(TAG_SIZE)
  14306 			v4 = v1
  14307 			v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14308 			goto _6
  14309 		_6:
  14310 			v7 = v1 + uintptr(2)
  14311 			v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14312 			goto _9
  14313 		_9:
  14314 			v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14315 			goto _3
  14316 		_3:
  14317 			size = v2
  14318 			// Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn").
  14319 			if size < libc.Uint32FromInt32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) {
  14320 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14321 			}
  14322 			if size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14323 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14324 			}
  14325 			if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14326 				return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14327 			}
  14328 			// We have a RIFF container. Skip it.
  14329 			**(**size_t)(__ccgo_up(riff_size)) = uint64(size)
  14330 			**(**uintptr)(__ccgo_up(data2)) += uintptr(RIFF_HEADER_SIZE)
  14331 			**(**size_t)(__ccgo_up(data_size)) -= uint64(RIFF_HEADER_SIZE)
  14332 		}
  14333 	}
  14334 	return int32(VP8_STATUS_OK)
  14335 }
  14336 
  14337 // C documentation
  14338 //
  14339 //	// Validates the VP8X header and skips over it.
  14340 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid VP8X header,
  14341 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14342 //	//         VP8_STATUS_OK otherwise.
  14343 //	// If a VP8X chunk is found, found_vp8x is set to true and *width_ptr,
  14344 //	// *height_ptr and *flags_ptr are set to the corresponding values extracted
  14345 //	// from the VP8X chunk.
  14346 func ParseVP8X(tls *libc.TLS, data3 uintptr, data_size uintptr, found_vp8x uintptr, width_ptr uintptr, height_ptr uintptr, flags_ptr uintptr) (r VP8StatusCode1) {
  14347 	var chunk_size, flags, vp8x_size, v2 uint32_t
  14348 	var height, width, v5, v8 int32
  14349 	var v1, v4, v7 uintptr
  14350 	_, _, _, _, _, _, _, _, _, _, _ = chunk_size, flags, height, vp8x_size, width, v1, v2, v4, v5, v7, v8
  14351 	vp8x_size = libc.Uint32FromInt32(libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  14352 	**(**int32)(__ccgo_up(found_vp8x)) = 0
  14353 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14354 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14355 	}
  14356 	if !(libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data3)), __ccgo_ts+574, uint64(TAG_SIZE)) != 0) {
  14357 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(TAG_SIZE)
  14358 		v4 = v1
  14359 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14360 		goto _6
  14361 	_6:
  14362 		v7 = v1 + uintptr(2)
  14363 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14364 		goto _9
  14365 	_9:
  14366 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14367 		goto _3
  14368 	_3:
  14369 		chunk_size = v2
  14370 		if chunk_size != uint32(VP8X_CHUNK_SIZE) {
  14371 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong chunk size.
  14372 		}
  14373 		// Verify if enough data is available to validate the VP8X chunk.
  14374 		if **(**size_t)(__ccgo_up(data_size)) < uint64(vp8x_size) {
  14375 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14376 		}
  14377 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(8)
  14378 		v4 = v1
  14379 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14380 		goto _15
  14381 	_15:
  14382 		v7 = v1 + uintptr(2)
  14383 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14384 		goto _18
  14385 	_18:
  14386 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14387 		goto _12
  14388 	_12:
  14389 		flags = v2
  14390 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(12)
  14391 		v4 = v1
  14392 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14393 		goto _24
  14394 	_24:
  14395 		v5 = v8 | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14396 		goto _21
  14397 	_21:
  14398 		width = int32(1) + v5
  14399 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(15)
  14400 		v4 = v1
  14401 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14402 		goto _30
  14403 	_30:
  14404 		v5 = v8 | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14405 		goto _27
  14406 	_27:
  14407 		height = int32(1) + v5
  14408 		if uint64(libc.Uint64FromInt32(width)*libc.Uint64FromInt32(height)) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(32) {
  14409 			return int32(VP8_STATUS_BITSTREAM_ERROR) // image is too large
  14410 		}
  14411 		if flags_ptr != libc.UintptrFromInt32(0) {
  14412 			**(**uint32_t)(__ccgo_up(flags_ptr)) = flags
  14413 		}
  14414 		if width_ptr != libc.UintptrFromInt32(0) {
  14415 			**(**int32)(__ccgo_up(width_ptr)) = width
  14416 		}
  14417 		if height_ptr != libc.UintptrFromInt32(0) {
  14418 			**(**int32)(__ccgo_up(height_ptr)) = height
  14419 		}
  14420 		// Skip over VP8X header bytes.
  14421 		**(**uintptr)(__ccgo_up(data3)) += uintptr(vp8x_size)
  14422 		**(**size_t)(__ccgo_up(data_size)) -= uint64(vp8x_size)
  14423 		**(**int32)(__ccgo_up(found_vp8x)) = int32(1)
  14424 	}
  14425 	return int32(VP8_STATUS_OK)
  14426 }
  14427 
  14428 // C documentation
  14429 //
  14430 //	// Skips to the next VP8/VP8L chunk header in the data given the size of the
  14431 //	// RIFF chunk 'riff_size'.
  14432 //	// Returns VP8_STATUS_BITSTREAM_ERROR if any invalid chunk size is encountered,
  14433 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14434 //	//         VP8_STATUS_OK otherwise.
  14435 //	// If an alpha chunk is found, *alpha_data and *alpha_size are set
  14436 //	// appropriately.
  14437 func ParseOptionalChunks(tls *libc.TLS, data2 uintptr, data_size uintptr, riff_size size_t, alpha_data uintptr, alpha_size uintptr) (r VP8StatusCode1) {
  14438 	var buf, v1, v4, v7 uintptr
  14439 	var buf_size size_t
  14440 	var chunk_size, disk_chunk_size, total_size, v2 uint32_t
  14441 	var v5, v8 int32
  14442 	_, _, _, _, _, _, _, _, _, _, _ = buf, buf_size, chunk_size, disk_chunk_size, total_size, v1, v2, v4, v5, v7, v8
  14443 	total_size = libc.Uint32FromInt32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE)) // data.
  14444 	buf = **(**uintptr)(__ccgo_up(data2))
  14445 	buf_size = **(**size_t)(__ccgo_up(data_size))
  14446 	**(**uintptr)(__ccgo_up(alpha_data)) = libc.UintptrFromInt32(0)
  14447 	**(**size_t)(__ccgo_up(alpha_size)) = uint64(0)
  14448 	for int32(1) != 0 { // chunk_size with padding
  14449 		**(**uintptr)(__ccgo_up(data2)) = buf
  14450 		**(**size_t)(__ccgo_up(data_size)) = buf_size
  14451 		if buf_size < uint64(CHUNK_HEADER_SIZE) { // Insufficient data.
  14452 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14453 		}
  14454 		v1 = buf + uintptr(TAG_SIZE)
  14455 		v4 = v1
  14456 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14457 		goto _6
  14458 	_6:
  14459 		v7 = v1 + uintptr(2)
  14460 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14461 		goto _9
  14462 	_9:
  14463 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14464 		goto _3
  14465 	_3:
  14466 		chunk_size = v2
  14467 		if chunk_size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14468 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14469 		}
  14470 		// For odd-sized chunk-payload, there's one byte padding at the end.
  14471 		disk_chunk_size = (uint32(CHUNK_HEADER_SIZE) + chunk_size + uint32(1)) & ^libc.Uint32FromUint32(1)
  14472 		total_size = total_size + disk_chunk_size
  14473 		// Check that total bytes skipped so far does not exceed riff_size.
  14474 		if riff_size > uint64(0) && uint64(total_size) > riff_size {
  14475 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14476 		}
  14477 		// Start of a (possibly incomplete) VP8/VP8L chunk implies that we have
  14478 		// parsed all the optional chunks.
  14479 		// Note: This check must occur before the check 'buf_size < disk_chunk_size'
  14480 		// below to allow incomplete VP8/VP8L chunks.
  14481 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+579, uint64(TAG_SIZE)) != 0) || !(libc.Xmemcmp(tls, buf, __ccgo_ts+584, uint64(TAG_SIZE)) != 0) {
  14482 			return int32(VP8_STATUS_OK)
  14483 		}
  14484 		if buf_size < uint64(disk_chunk_size) { // Insufficient data.
  14485 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14486 		}
  14487 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+589, uint64(TAG_SIZE)) != 0) { // A valid ALPH header.
  14488 			**(**uintptr)(__ccgo_up(alpha_data)) = buf + uintptr(CHUNK_HEADER_SIZE)
  14489 			**(**size_t)(__ccgo_up(alpha_size)) = uint64(chunk_size)
  14490 		}
  14491 		// We have a full and valid chunk; skip it.
  14492 		buf = buf + uintptr(disk_chunk_size)
  14493 		buf_size = buf_size - uint64(disk_chunk_size)
  14494 	}
  14495 	return r
  14496 }
  14497 
  14498 // C documentation
  14499 //
  14500 //	// Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it.
  14501 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than
  14502 //	//         riff_size) VP8/VP8L header,
  14503 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14504 //	//         VP8_STATUS_OK otherwise.
  14505 //	// If a VP8/VP8L chunk is found, *chunk_size is set to the total number of bytes
  14506 //	// extracted from the VP8/VP8L chunk header.
  14507 //	// The flag '*is_lossless' is set to 1 in case of VP8L chunk / raw VP8L data.
  14508 func ParseVP8Header(tls *libc.TLS, data_ptr uintptr, data_size uintptr, have_all_data int32, riff_size size_t, chunk_size uintptr, is_lossless uintptr) (r VP8StatusCode1) {
  14509 	var data2, v1, v4, v7 uintptr
  14510 	var is_vp8, is_vp8l, v5, v8 int32
  14511 	var minimal_size, size, v2 uint32_t
  14512 	_, _, _, _, _, _, _, _, _, _, _ = data2, is_vp8, is_vp8l, minimal_size, size, v1, v2, v4, v5, v7, v8
  14513 	data2 = **(**uintptr)(__ccgo_up(data_ptr))
  14514 	is_vp8 = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+579, uint64(TAG_SIZE)) != 0))
  14515 	is_vp8l = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+584, uint64(TAG_SIZE)) != 0))
  14516 	minimal_size = libc.Uint32FromInt32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE)) // "WEBP" + "VP8 nnnn" OR
  14517 	// "WEBP" + "VP8Lnnnn"
  14518 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14519 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14520 	}
  14521 	if is_vp8 != 0 || is_vp8l != 0 {
  14522 		v1 = data2 + uintptr(TAG_SIZE)
  14523 		v4 = v1
  14524 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14525 		goto _6
  14526 	_6:
  14527 		v7 = v1 + uintptr(2)
  14528 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14529 		goto _9
  14530 	_9:
  14531 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14532 		goto _3
  14533 	_3:
  14534 		// Bitstream contains VP8/VP8L header.
  14535 		size = v2
  14536 		if riff_size >= uint64(minimal_size) && uint64(size) > riff_size-uint64(minimal_size) {
  14537 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Inconsistent size information.
  14538 		}
  14539 		if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14540 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14541 		}
  14542 		// Skip over CHUNK_HEADER_SIZE bytes from VP8/VP8L Header.
  14543 		**(**size_t)(__ccgo_up(chunk_size)) = uint64(size)
  14544 		**(**uintptr)(__ccgo_up(data_ptr)) += uintptr(CHUNK_HEADER_SIZE)
  14545 		**(**size_t)(__ccgo_up(data_size)) -= uint64(CHUNK_HEADER_SIZE)
  14546 		**(**int32)(__ccgo_up(is_lossless)) = is_vp8l
  14547 	} else {
  14548 		// Raw VP8/VP8L bitstream (no header).
  14549 		**(**int32)(__ccgo_up(is_lossless)) = VP8LCheckSignature(tls, data2, **(**size_t)(__ccgo_up(data_size)))
  14550 		**(**size_t)(__ccgo_up(chunk_size)) = **(**size_t)(__ccgo_up(data_size))
  14551 	}
  14552 	return int32(VP8_STATUS_OK)
  14553 }
  14554 
  14555 //------------------------------------------------------------------------------
  14556 
  14557 // C documentation
  14558 //
  14559 //	// Fetch '*width', '*height', '*has_alpha' and fill out 'headers' based on
  14560 //	// 'data'. All the output parameters may be NULL. If 'headers' is NULL only the
  14561 //	// minimal amount will be read to fetch the remaining parameters.
  14562 //	// If 'headers' is non-NULL this function will attempt to locate both alpha
  14563 //	// data (with or without a VP8X chunk) and the bitstream chunk (VP8/VP8L).
  14564 //	// Note: The following chunk sequences (before the raw VP8/VP8L data) are
  14565 //	// considered valid by this function:
  14566 //	// RIFF + VP8(L)
  14567 //	// RIFF + VP8X + (optional chunks) + VP8(L)
  14568 //	// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
  14569 //	// VP8(L)     <-- Not a valid WebP format: only allowed for internal purpose.
  14570 func ParseHeadersInternal(tls *libc.TLS, _data uintptr, _data_size size_t, width uintptr, height uintptr, has_alpha uintptr, has_animation uintptr, format uintptr, headers uintptr) (r VP8StatusCode1) {
  14571 	bp := tls.Alloc(128)
  14572 	defer tls.Free(128)
  14573 	*(*uintptr)(unsafe.Pointer(bp)) = _data
  14574 	*(*size_t)(unsafe.Pointer(bp + 8)) = _data_size
  14575 	var animation_present, found_riff, have_all_data, v1 int32
  14576 	var status VP8StatusCode1
  14577 	var _ /* canvas_height at bp+20 */ int32
  14578 	var _ /* canvas_width at bp+16 */ int32
  14579 	var _ /* flags at bp+112 */ uint32_t
  14580 	var _ /* found_vp8x at bp+32 */ int32
  14581 	var _ /* hdrs at bp+40 */ WebPHeaderStructure
  14582 	var _ /* image_height at bp+28 */ int32
  14583 	var _ /* image_width at bp+24 */ int32
  14584 	_, _, _, _, _ = animation_present, found_riff, have_all_data, status, v1
  14585 	**(**int32)(__ccgo_up(bp + 16)) = 0
  14586 	**(**int32)(__ccgo_up(bp + 20)) = 0
  14587 	**(**int32)(__ccgo_up(bp + 24)) = 0
  14588 	**(**int32)(__ccgo_up(bp + 28)) = 0
  14589 	found_riff = 0
  14590 	**(**int32)(__ccgo_up(bp + 32)) = 0
  14591 	animation_present = 0
  14592 	if headers != libc.UintptrFromInt32(0) {
  14593 		v1 = (*WebPHeaderStructure)(unsafe.Pointer(headers)).Fhave_all_data
  14594 	} else {
  14595 		v1 = 0
  14596 	}
  14597 	have_all_data = v1
  14598 	if **(**uintptr)(__ccgo_up(bp)) == libc.UintptrFromInt32(0) || **(**size_t)(__ccgo_up(bp + 8)) < uint64(RIFF_HEADER_SIZE) {
  14599 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14600 	}
  14601 	libc.Xmemset(tls, bp+40, 0, uint64(72))
  14602 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata = **(**uintptr)(__ccgo_up(bp))
  14603 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata_size = **(**size_t)(__ccgo_up(bp + 8))
  14604 	// Skip over RIFF header.
  14605 	status = ParseRIFF(tls, bp, bp+8, have_all_data, bp+40+56)
  14606 	if status != int32(VP8_STATUS_OK) {
  14607 		return status // Wrong RIFF header / insufficient data.
  14608 	}
  14609 	found_riff = libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size > uint64(0))
  14610 	// Skip over VP8X.
  14611 	**(**uint32_t)(__ccgo_up(bp + 112)) = uint32(0)
  14612 	status = ParseVP8X(tls, bp, bp+8, bp+32, bp+16, bp+20, bp+112)
  14613 	if status != int32(VP8_STATUS_OK) {
  14614 		return status // Wrong VP8X / insufficient data.
  14615 	}
  14616 	animation_present = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ANIMATION_FLAG) != 0))
  14617 	if !(found_riff != 0) && **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14618 		// Note: This restriction may be removed in the future, if it becomes
  14619 		// necessary to send VP8X chunk to the decoder.
  14620 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14621 	}
  14622 	if has_alpha != libc.UintptrFromInt32(0) {
  14623 		**(**int32)(__ccgo_up(has_alpha)) = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ALPHA_FLAG) != 0))
  14624 	}
  14625 	if has_animation != libc.UintptrFromInt32(0) {
  14626 		**(**int32)(__ccgo_up(has_animation)) = animation_present
  14627 	}
  14628 	if format != libc.UintptrFromInt32(0) {
  14629 		**(**int32)(__ccgo_up(format)) = 0
  14630 	} // default = undefined
  14631 	**(**int32)(__ccgo_up(bp + 24)) = **(**int32)(__ccgo_up(bp + 16))
  14632 	**(**int32)(__ccgo_up(bp + 28)) = **(**int32)(__ccgo_up(bp + 20))
  14633 	if **(**int32)(__ccgo_up(bp + 32)) != 0 && animation_present != 0 && headers == libc.UintptrFromInt32(0) {
  14634 		status = int32(VP8_STATUS_OK)
  14635 		goto ReturnWidthHeight // Just return features from VP8X header.
  14636 	}
  14637 	if **(**size_t)(__ccgo_up(bp + 8)) < uint64(TAG_SIZE) {
  14638 		status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14639 		goto ReturnWidthHeight
  14640 	}
  14641 	// Skip over optional chunks if data started with "RIFF + VP8X" or "ALPH".
  14642 	if found_riff != 0 && **(**int32)(__ccgo_up(bp + 32)) != 0 || !(found_riff != 0) && !(**(**int32)(__ccgo_up(bp + 32)) != 0) && !(libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(bp)), __ccgo_ts+589, uint64(TAG_SIZE)) != 0) {
  14643 		status = ParseOptionalChunks(tls, bp, bp+8, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+32, bp+40+40)
  14644 		if status != int32(VP8_STATUS_OK) {
  14645 			goto ReturnWidthHeight // Invalid chunk size / insufficient data.
  14646 		}
  14647 	}
  14648 	// Skip over VP8/VP8L header.
  14649 	status = ParseVP8Header(tls, bp, bp+8, have_all_data, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+48, bp+40+64)
  14650 	if status != int32(VP8_STATUS_OK) {
  14651 		goto ReturnWidthHeight // Wrong VP8/VP8L chunk-header / insufficient data.
  14652 	}
  14653 	if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fcompressed_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
  14654 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14655 	}
  14656 	if format != libc.UintptrFromInt32(0) && !(animation_present != 0) {
  14657 		if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0 {
  14658 			v1 = int32(2)
  14659 		} else {
  14660 			v1 = int32(1)
  14661 		}
  14662 		**(**int32)(__ccgo_up(format)) = v1
  14663 	}
  14664 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0) {
  14665 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8_FRAME_HEADER_SIZE) {
  14666 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14667 			goto ReturnWidthHeight
  14668 		}
  14669 		// Validates raw VP8 data.
  14670 		if !(VP8GetInfo(tls, **(**uintptr)(__ccgo_up(bp)), **(**size_t)(__ccgo_up(bp + 8)), uint64(uint32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fcompressed_size)), bp+24, bp+28) != 0) {
  14671 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14672 		}
  14673 	} else {
  14674 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8L_FRAME_HEADER_SIZE) {
  14675 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14676 			goto ReturnWidthHeight
  14677 		}
  14678 		// Validates raw VP8L data.
  14679 		if !(VP8LGetInfo(tls, **(**uintptr)(__ccgo_up(bp)), **(**size_t)(__ccgo_up(bp + 8)), bp+24, bp+28, has_alpha) != 0) {
  14680 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14681 		}
  14682 	}
  14683 	// Validates image size coherency.
  14684 	if **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14685 		if **(**int32)(__ccgo_up(bp + 16)) != **(**int32)(__ccgo_up(bp + 24)) || **(**int32)(__ccgo_up(bp + 20)) != **(**int32)(__ccgo_up(bp + 28)) {
  14686 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14687 		}
  14688 	}
  14689 	if headers != libc.UintptrFromInt32(0) {
  14690 		**(**WebPHeaderStructure)(__ccgo_up(headers)) = **(**WebPHeaderStructure)(__ccgo_up(bp + 40))
  14691 		(*WebPHeaderStructure)(unsafe.Pointer(headers)).Foffset = libc.Uint64FromInt64(int64(**(**uintptr)(__ccgo_up(bp))) - int64((*WebPHeaderStructure)(unsafe.Pointer(headers)).Fdata))
  14692 	}
  14693 	goto ReturnWidthHeight
  14694 ReturnWidthHeight:
  14695 	;
  14696 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) && **(**int32)(__ccgo_up(bp + 32)) != 0 && headers == libc.UintptrFromInt32(0) {
  14697 		if has_alpha != libc.UintptrFromInt32(0) {
  14698 			// If the data did not contain a VP8X/VP8L chunk the only definitive way
  14699 			// to set this is by looking for alpha data (from an ALPH chunk).
  14700 			**(**int32)(__ccgo_up(has_alpha)) |= libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Falpha_data != libc.UintptrFromInt32(0))
  14701 		}
  14702 		if width != libc.UintptrFromInt32(0) {
  14703 			**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp + 24))
  14704 		}
  14705 		if height != libc.UintptrFromInt32(0) {
  14706 			**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 28))
  14707 		}
  14708 		return int32(VP8_STATUS_OK)
  14709 	} else {
  14710 		return status
  14711 	}
  14712 	return r
  14713 }
  14714 
  14715 func WebPParseHeaders(tls *libc.TLS, headers uintptr) (r VP8StatusCode1) {
  14716 	bp := tls.Alloc(16)
  14717 	defer tls.Free(16)
  14718 	var status VP8StatusCode1
  14719 	var _ /* has_animation at bp+0 */ int32
  14720 	_ = status
  14721 	**(**int32)(__ccgo_up(bp)) = 0
  14722 	// fill out headers, ignore width/height/has_alpha.
  14723 	status = ParseHeadersInternal(tls, (*WebPHeaderStructure)(unsafe.Pointer(headers)).Fdata, (*WebPHeaderStructure)(unsafe.Pointer(headers)).Fdata_size, libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), bp, libc.UintptrFromInt32(0), headers)
  14724 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  14725 		// The WebPDemux API + libwebp can be used to decode individual
  14726 		// uncomposited frames or the WebPAnimDecoder can be used to fully
  14727 		// reconstruct them (see webp/demux.h).
  14728 		if **(**int32)(__ccgo_up(bp)) != 0 {
  14729 			status = int32(VP8_STATUS_UNSUPPORTED_FEATURE)
  14730 		}
  14731 	}
  14732 	return status
  14733 }
  14734 
  14735 //------------------------------------------------------------------------------
  14736 // WebPDecParams
  14737 
  14738 func WebPResetDecParams(tls *libc.TLS, params uintptr) {
  14739 	if params != libc.UintptrFromInt32(0) {
  14740 		libc.Xmemset(tls, params, 0, uint64(112))
  14741 	}
  14742 }
  14743 
  14744 //------------------------------------------------------------------------------
  14745 // "Into" decoding variants
  14746 
  14747 // C documentation
  14748 //
  14749 //	// Main flow
  14750 func DecodeInto(tls *libc.TLS, data uintptr, data_size size_t, params uintptr) (r VP8StatusCode1) {
  14751 	bp := tls.Alloc(240)
  14752 	defer tls.Free(240)
  14753 	var dec, dec1 uintptr
  14754 	var status VP8StatusCode1
  14755 	var v1 int32
  14756 	var _ /* headers at bp+160 */ WebPHeaderStructure
  14757 	var _ /* io at bp+0 */ VP8Io
  14758 	_, _, _, _ = dec, dec1, status, v1
  14759 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata = data
  14760 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size = data_size
  14761 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fhave_all_data = int32(1)
  14762 	status = WebPParseHeaders(tls, bp+160) // Process Pre-VP8 chunks.
  14763 	if status != int32(VP8_STATUS_OK) {
  14764 		return status
  14765 	}
  14766 	v1 = VP8InitIoInternal(tls, bp, int32(WEBP_DECODER_ABI_VERSION))
  14767 	goto _2
  14768 _2:
  14769 	if !(v1 != 0) {
  14770 		return int32(VP8_STATUS_INVALID_PARAM)
  14771 	}
  14772 	(**(**VP8Io)(__ccgo_up(bp))).Fdata = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata + uintptr((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset)
  14773 	(**(**VP8Io)(__ccgo_up(bp))).Fdata_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size - (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset
  14774 	WebPInitCustomIo(tls, params, bp) // Plug the I/O functions.
  14775 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fis_lossless != 0) {
  14776 		dec = VP8New(tls)
  14777 		if dec == libc.UintptrFromInt32(0) {
  14778 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  14779 		}
  14780 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data
  14781 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data_size
  14782 		// Decode bitstream header, update io->width/io->height.
  14783 		if !(VP8GetHeaders(tls, dec, bp) != 0) {
  14784 			status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus // An error occurred. Grab error status.
  14785 		} else {
  14786 			// Allocate/check output buffers.
  14787 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  14788 			if status == int32(VP8_STATUS_OK) { // Decode
  14789 				// This change must be done before calling VP8Decode()
  14790 				(*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method = VP8GetThreadMethod(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, bp+160, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight)
  14791 				VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
  14792 				if !(VP8Decode(tls, dec, bp) != 0) {
  14793 					status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  14794 				}
  14795 			}
  14796 		}
  14797 		VP8Delete(tls, dec)
  14798 	} else {
  14799 		dec1 = VP8LNew(tls)
  14800 		if dec1 == libc.UintptrFromInt32(0) {
  14801 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  14802 		}
  14803 		if !(VP8LDecodeHeader(tls, dec1, bp) != 0) {
  14804 			status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus // An error occurred. Grab error status.
  14805 		} else {
  14806 			// Allocate/check output buffers.
  14807 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  14808 			if status == int32(VP8_STATUS_OK) { // Decode
  14809 				if !(VP8LDecodeImage(tls, dec1) != 0) {
  14810 					status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus
  14811 				}
  14812 			}
  14813 		}
  14814 		VP8LDelete(tls, dec1)
  14815 	}
  14816 	if status != int32(VP8_STATUS_OK) {
  14817 		WebPFreeDecBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  14818 	} else {
  14819 		if (*WebPDecParams)(unsafe.Pointer(params)).Foptions != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(params)).Foptions)).Fflip != 0 {
  14820 			// This restores the original stride values if options->flip was used
  14821 			// during the call to WebPAllocateDecBuffer above.
  14822 			status = WebPFlipBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  14823 		}
  14824 	}
  14825 	return status
  14826 }
  14827 
  14828 // C documentation
  14829 //
  14830 //	// Helpers
  14831 func DecodeIntoRGBABuffer(tls *libc.TLS, colorspace WEBP_CSP_MODE1, data uintptr, data_size size_t, rgba uintptr, stride int32, size size_t) (r uintptr) {
  14832 	bp := tls.Alloc(240)
  14833 	defer tls.Free(240)
  14834 	var v1 int32
  14835 	var v3 bool
  14836 	var _ /* buf at bp+112 */ WebPDecBuffer
  14837 	var _ /* params at bp+0 */ WebPDecParams
  14838 	_, _ = v1, v3
  14839 	if v3 = rgba == libc.UintptrFromInt32(0); !v3 {
  14840 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  14841 		goto _2
  14842 	_2:
  14843 	}
  14844 	if v3 || !(v1 != 0) {
  14845 		return libc.UintptrFromInt32(0)
  14846 	}
  14847 	WebPResetDecParams(tls, bp)
  14848 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  14849 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = colorspace
  14850 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = rgba
  14851 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 8)) = stride
  14852 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 16)) = size
  14853 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  14854 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  14855 		return libc.UintptrFromInt32(0)
  14856 	}
  14857 	return rgba
  14858 }
  14859 
  14860 func WebPDecodeRGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  14861 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGB), data, data_size, output, stride, size)
  14862 }
  14863 
  14864 func WebPDecodeRGBAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  14865 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGBA), data, data_size, output, stride, size)
  14866 }
  14867 
  14868 func WebPDecodeARGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  14869 	return DecodeIntoRGBABuffer(tls, int32(MODE_ARGB), data, data_size, output, stride, size)
  14870 }
  14871 
  14872 func WebPDecodeBGRInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  14873 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGR), data, data_size, output, stride, size)
  14874 }
  14875 
  14876 func WebPDecodeBGRAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  14877 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGRA), data, data_size, output, stride, size)
  14878 }
  14879 
  14880 func WebPDecodeYUVInto(tls *libc.TLS, data uintptr, data_size size_t, luma uintptr, luma_size size_t, luma_stride int32, u uintptr, u_size size_t, u_stride int32, v uintptr, v_size size_t, v_stride int32) (r uintptr) {
  14881 	bp := tls.Alloc(240)
  14882 	defer tls.Free(240)
  14883 	var v1 int32
  14884 	var v3 bool
  14885 	var _ /* output at bp+112 */ WebPDecBuffer
  14886 	var _ /* params at bp+0 */ WebPDecParams
  14887 	_, _ = v1, v3
  14888 	if v3 = luma == libc.UintptrFromInt32(0); !v3 {
  14889 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  14890 		goto _2
  14891 	_2:
  14892 	}
  14893 	if v3 || !(v1 != 0) {
  14894 		return libc.UintptrFromInt32(0)
  14895 	}
  14896 	WebPResetDecParams(tls, bp)
  14897 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  14898 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = int32(MODE_YUV)
  14899 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = luma
  14900 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 32)) = luma_stride
  14901 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 48)) = luma_size
  14902 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 8)) = u
  14903 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 36)) = u_stride
  14904 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 56)) = u_size
  14905 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 16)) = v
  14906 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 40)) = v_stride
  14907 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 64)) = v_size
  14908 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  14909 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  14910 		return libc.UintptrFromInt32(0)
  14911 	}
  14912 	return luma
  14913 }
  14914 
  14915 // ------------------------------------------------------------------------------
  14916 func Decode(tls *libc.TLS, mode1 WEBP_CSP_MODE1, data uintptr, data_size size_t, width uintptr, height uintptr, keep_info uintptr) (r uintptr) {
  14917 	bp := tls.Alloc(240)
  14918 	defer tls.Free(240)
  14919 	var v1 int32
  14920 	var v3 uintptr
  14921 	var _ /* output at bp+112 */ WebPDecBuffer
  14922 	var _ /* params at bp+0 */ WebPDecParams
  14923 	_, _ = v1, v3
  14924 	v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  14925 	goto _2
  14926 _2:
  14927 	if !(v1 != 0) {
  14928 		return libc.UintptrFromInt32(0)
  14929 	}
  14930 	WebPResetDecParams(tls, bp)
  14931 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  14932 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = mode1
  14933 	// Retrieve (and report back) the required dimensions from bitstream.
  14934 	if !(WebPGetInfo(tls, data, data_size, bp+112+4, bp+112+8) != 0) {
  14935 		return libc.UintptrFromInt32(0)
  14936 	}
  14937 	if width != libc.UintptrFromInt32(0) {
  14938 		**(**int32)(__ccgo_up(width)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth
  14939 	}
  14940 	if height != libc.UintptrFromInt32(0) {
  14941 		**(**int32)(__ccgo_up(height)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight
  14942 	}
  14943 	// Decode
  14944 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  14945 		return libc.UintptrFromInt32(0)
  14946 	}
  14947 	if keep_info != libc.UintptrFromInt32(0) { // keep track of the side-info
  14948 		WebPCopyDecBuffer(tls, bp+112, keep_info)
  14949 	}
  14950 	// return decoded samples (don't clear 'output'!)
  14951 	v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
  14952 	goto _5
  14953 _5:
  14954 	if v1 != 0 {
  14955 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  14956 	} else {
  14957 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  14958 	}
  14959 	return v3
  14960 }
  14961 
  14962 func WebPDecodeRGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  14963 	return Decode(tls, int32(MODE_RGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  14964 }
  14965 
  14966 func WebPDecodeRGBA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  14967 	return Decode(tls, int32(MODE_RGBA), data, data_size, width, height, libc.UintptrFromInt32(0))
  14968 }
  14969 
  14970 func WebPDecodeARGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  14971 	return Decode(tls, int32(MODE_ARGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  14972 }
  14973 
  14974 func WebPDecodeBGR(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  14975 	return Decode(tls, int32(MODE_BGR), data, data_size, width, height, libc.UintptrFromInt32(0))
  14976 }
  14977 
  14978 func WebPDecodeBGRA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  14979 	return Decode(tls, int32(MODE_BGRA), data, data_size, width, height, libc.UintptrFromInt32(0))
  14980 }
  14981 
  14982 func WebPDecodeYUV(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr, u uintptr, v uintptr, stride uintptr, uv_stride uintptr) (r uintptr) {
  14983 	bp := tls.Alloc(128)
  14984 	defer tls.Free(128)
  14985 	var buf, out uintptr
  14986 	var _ /* output at bp+0 */ WebPDecBuffer
  14987 	_, _ = buf, out
  14988 	// data, width and height are checked by Decode().
  14989 	if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) || stride == libc.UintptrFromInt32(0) || uv_stride == libc.UintptrFromInt32(0) {
  14990 		return libc.UintptrFromInt32(0)
  14991 	}
  14992 	// only to preserve the side-infos
  14993 	out = Decode(tls, int32(MODE_YUV), data, data_size, width, height, bp)
  14994 	if out != libc.UintptrFromInt32(0) {
  14995 		buf = bp + 16
  14996 		**(**uintptr)(__ccgo_up(u)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu
  14997 		**(**uintptr)(__ccgo_up(v)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv
  14998 		**(**int32)(__ccgo_up(stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride
  14999 		**(**int32)(__ccgo_up(uv_stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride
  15000 	}
  15001 	return out
  15002 	return r
  15003 }
  15004 
  15005 func DefaultFeatures(tls *libc.TLS, features uintptr) {
  15006 	libc.Xmemset(tls, features, 0, uint64(40))
  15007 }
  15008 
  15009 func GetFeatures(tls *libc.TLS, data uintptr, data_size size_t, features uintptr) (r VP8StatusCode1) {
  15010 	if features == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
  15011 		return int32(VP8_STATUS_INVALID_PARAM)
  15012 	}
  15013 	DefaultFeatures(tls, features)
  15014 	// Only parse enough of the data to retrieve the features.
  15015 	return ParseHeadersInternal(tls, data, data_size, features, features+4, features+8, features+12, features+16, libc.UintptrFromInt32(0))
  15016 }
  15017 
  15018 //------------------------------------------------------------------------------
  15019 // WebPGetInfo()
  15020 
  15021 func WebPGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r int32) {
  15022 	bp := tls.Alloc(48)
  15023 	defer tls.Free(48)
  15024 	var _ /* features at bp+0 */ WebPBitstreamFeatures
  15025 	if GetFeatures(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15026 		return 0
  15027 	}
  15028 	if width != libc.UintptrFromInt32(0) {
  15029 		**(**int32)(__ccgo_up(width)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fwidth
  15030 	}
  15031 	if height != libc.UintptrFromInt32(0) {
  15032 		**(**int32)(__ccgo_up(height)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fheight
  15033 	}
  15034 	return int32(1)
  15035 }
  15036 
  15037 //------------------------------------------------------------------------------
  15038 // Advance decoding API
  15039 
  15040 func WebPInitDecoderConfigInternal(tls *libc.TLS, config uintptr, version int32) (r int32) {
  15041 	var v1 int32
  15042 	_ = v1
  15043 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15044 		return 0 // version mismatch
  15045 	}
  15046 	if config == libc.UintptrFromInt32(0) {
  15047 		return 0
  15048 	}
  15049 	libc.Xmemset(tls, config, 0, uint64(240))
  15050 	DefaultFeatures(tls, config)
  15051 	v1 = WebPInitDecBufferInternal(tls, config+40, int32(WEBP_DECODER_ABI_VERSION))
  15052 	goto _2
  15053 _2:
  15054 	if !(v1 != 0) {
  15055 		return 0
  15056 	}
  15057 	return int32(1)
  15058 }
  15059 
  15060 func WebPCheckCropDimensionsBasic(tls *libc.TLS, x int32, y int32, w int32, h int32) (r int32) {
  15061 	return libc.BoolInt32(!(x < 0 || y < 0 || w <= 0 || h <= 0))
  15062 }
  15063 
  15064 func WebPValidateDecoderConfig(tls *libc.TLS, config uintptr) (r int32) {
  15065 	bp := tls.Alloc(16)
  15066 	defer tls.Free(16)
  15067 	var options uintptr
  15068 	var _ /* scaled_height at bp+4 */ int32
  15069 	var _ /* scaled_width at bp+0 */ int32
  15070 	_ = options
  15071 	if config == libc.UintptrFromInt32(0) {
  15072 		return 0
  15073 	}
  15074 	if !(IsValidColorspace(tls, (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace) != 0) {
  15075 		return 0
  15076 	}
  15077 	options = config + 160
  15078 	// bypass_filtering, no_fancy_upsampling, use_cropping, use_scaling,
  15079 	// use_threads, flip can be any integer and are interpreted as boolean.
  15080 	// Check for cropping.
  15081 	if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0 && !(WebPCheckCropDimensionsBasic(tls, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height) != 0) {
  15082 		return 0
  15083 	}
  15084 	// Check for scaling.
  15085 	if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0 && ((*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width < 0 || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height < 0 || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width == 0 && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height == 0) {
  15086 		return 0
  15087 	}
  15088 	// In case the WebPBitstreamFeatures has been filled in, check further.
  15089 	if (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth > 0 || (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight > 0 {
  15090 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15091 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15092 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0 && !(WebPCheckCropDimensions(tls, (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth, (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width, (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height) != 0) {
  15093 			return 0
  15094 		}
  15095 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0 && !(WebPRescalerGetScaledDimensions(tls, (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth, (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight, bp, bp+4) != 0) {
  15096 			return 0
  15097 		}
  15098 	}
  15099 	// Check for dithering.
  15100 	if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fdithering_strength < 0 || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fdithering_strength > int32(100) || (*WebPDecoderOptions)(unsafe.Pointer(options)).Falpha_dithering_strength < 0 || (*WebPDecoderOptions)(unsafe.Pointer(options)).Falpha_dithering_strength > int32(100) {
  15101 		return 0
  15102 	}
  15103 	return int32(1)
  15104 }
  15105 
  15106 func WebPGetFeaturesInternal(tls *libc.TLS, data uintptr, data_size size_t, features uintptr, version int32) (r VP8StatusCode1) {
  15107 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15108 		return int32(VP8_STATUS_INVALID_PARAM) // version mismatch
  15109 	}
  15110 	if features == libc.UintptrFromInt32(0) {
  15111 		return int32(VP8_STATUS_INVALID_PARAM)
  15112 	}
  15113 	return GetFeatures(tls, data, data_size, features)
  15114 }
  15115 
  15116 func WebPDecode(tls *libc.TLS, data uintptr, data_size size_t, config uintptr) (r VP8StatusCode1) {
  15117 	bp := tls.Alloc(240)
  15118 	defer tls.Free(240)
  15119 	var status VP8StatusCode1
  15120 	var v1 int32
  15121 	var _ /* in_mem_buffer at bp+112 */ WebPDecBuffer
  15122 	var _ /* params at bp+0 */ WebPDecParams
  15123 	_, _ = status, v1
  15124 	if config == libc.UintptrFromInt32(0) {
  15125 		return int32(VP8_STATUS_INVALID_PARAM)
  15126 	}
  15127 	status = GetFeatures(tls, data, data_size, config)
  15128 	if status != int32(VP8_STATUS_OK) {
  15129 		if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15130 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not-enough-data treated as error.
  15131 		}
  15132 		return status
  15133 	}
  15134 	WebPResetDecParams(tls, bp)
  15135 	(**(**WebPDecParams)(__ccgo_up(bp))).Foptions = config + 160
  15136 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = config + 40
  15137 	if WebPAvoidSlowMemory(tls, (**(**WebPDecParams)(__ccgo_up(bp))).Foutput, config) != 0 {
  15138 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15139 		goto _2
  15140 	_2:
  15141 		if !(v1 != 0) {
  15142 			return int32(VP8_STATUS_INVALID_PARAM)
  15143 		}
  15144 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace
  15145 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth
  15146 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight
  15147 		(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15148 		status = DecodeInto(tls, data, data_size, bp)
  15149 		if status == int32(VP8_STATUS_OK) { // do the slow-copy
  15150 			status = WebPCopyDecBufferPixels(tls, bp+112, config+40)
  15151 		}
  15152 		WebPFreeDecBuffer(tls, bp+112)
  15153 	} else {
  15154 		status = DecodeInto(tls, data, data_size, bp)
  15155 	}
  15156 	return status
  15157 }
  15158 
  15159 //------------------------------------------------------------------------------
  15160 // Cropping and rescaling.
  15161 
  15162 func WebPCheckCropDimensions(tls *libc.TLS, image_width int32, image_height int32, x int32, y int32, w int32, h int32) (r int32) {
  15163 	return libc.BoolInt32(WebPCheckCropDimensionsBasic(tls, x, y, w, h) != 0 && !(x >= image_width || w > image_width || w > image_width-x || y >= image_height || h > image_height || h > image_height-y))
  15164 }
  15165 
  15166 func WebPIoInitFromOptions(tls *libc.TLS, options uintptr, io uintptr, src_colorspace WEBP_CSP_MODE1) (r int32) {
  15167 	bp := tls.Alloc(16)
  15168 	defer tls.Free(16)
  15169 	var H, W, h, w, x, y, v1 int32
  15170 	var _ /* scaled_height at bp+4 */ int32
  15171 	var _ /* scaled_width at bp+0 */ int32
  15172 	_, _, _, _, _, _, _ = H, W, h, w, x, y, v1
  15173 	W = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  15174 	H = (*VP8Io)(unsafe.Pointer(io)).Fheight
  15175 	x = 0
  15176 	y = 0
  15177 	w = W
  15178 	h = H
  15179 	// Cropping
  15180 	(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0)
  15181 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_cropping != 0 {
  15182 		w = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
  15183 		h = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
  15184 		x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left
  15185 		y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top
  15186 		v1 = libc.BoolInt32(src_colorspace < int32(MODE_YUV))
  15187 		goto _2
  15188 	_2:
  15189 		if !(v1 != 0) { // only snap for YUV420
  15190 			x = x & ^libc.Int32FromInt32(1)
  15191 			y = y & ^libc.Int32FromInt32(1)
  15192 		}
  15193 		if !(WebPCheckCropDimensions(tls, W, H, x, y, w, h) != 0) {
  15194 			return 0 // out of frame boundary error
  15195 		}
  15196 	}
  15197 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = x
  15198 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = y
  15199 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = x + w
  15200 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = y + h
  15201 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = w
  15202 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = h
  15203 	// Scaling
  15204 	(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0)
  15205 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15206 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15207 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15208 		if !(WebPRescalerGetScaledDimensions(tls, w, h, bp, bp+4) != 0) {
  15209 			return 0
  15210 		}
  15211 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = **(**int32)(__ccgo_up(bp))
  15212 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = **(**int32)(__ccgo_up(bp + 4))
  15213 	}
  15214 	// Filter
  15215 	(*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fbypass_filtering != 0)
  15216 	// Fancy upsampler
  15217 	(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = libc.BoolInt32(options == libc.UintptrFromInt32(0) || !((*WebPDecoderOptions)(unsafe.Pointer(options)).Fno_fancy_upsampling != 0))
  15218 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15219 		// disable filter (only for large downscaling ratio).
  15220 		**(**int32)(__ccgo_up(io + 112)) |= libc.BoolInt32((*VP8Io)(unsafe.Pointer(io)).Fscaled_width < W*int32(3)/int32(4) && (*VP8Io)(unsafe.Pointer(io)).Fscaled_height < H*int32(3)/int32(4))
  15221 		(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = 0
  15222 	}
  15223 	return int32(1)
  15224 }
  15225 
  15226 const ENC_MAJ_VERSION = 1
  15227 const ENC_MIN_VERSION = 6
  15228 const ENC_REV_VERSION = 0
  15229 const ERROR_DIFFUSION_QUALITY = 98
  15230 const HASH_BITS = 18
  15231 const MAX_COLOR_CACHE_BITS = 10
  15232 const MAX_LENGTH_BITS = 12
  15233 const MAX_REFS_BLOCK_PER_IMAGE = 16
  15234 const QFIX = 17
  15235 const U_OFF_ENC = 16
  15236 const VP8L_WRITER_BITS = 32
  15237 const VP8L_WRITER_BYTES = 4
  15238 const VP8L_WRITER_MAX_BITS = 64
  15239 const WEBP_ENCODER_ABI_VERSION = 528
  15240 const WEBP_MAX_DIMENSION = 16383
  15241 const WEBP_NEAR_LOSSLESS = 1
  15242 const WINDOW_SIZE_BITS = 20
  15243 const WSWAP = "HToLE32"
  15244 const Y_OFF_ENC = 0
  15245 
  15246 type VP8Matrix = struct {
  15247 	Fq       [16]uint16_t
  15248 	Fiq      [16]uint16_t
  15249 	Fbias    [16]uint32_t
  15250 	Fzthresh [16]uint32_t
  15251 	Fsharpen [16]uint16_t
  15252 }
  15253 
  15254 type VP8BitWriter = struct {
  15255 	Frange1  int32_t
  15256 	Fvalue   int32_t
  15257 	Frun     int32
  15258 	Fnb_bits int32
  15259 	Fbuf     uintptr
  15260 	Fpos     size_t
  15261 	Fmax_pos size_t
  15262 	Ferror1  int32
  15263 }
  15264 
  15265 type vp8l_atype_t = uint64
  15266 
  15267 type vp8l_wtype_t = uint32
  15268 
  15269 type VP8LBitWriter = struct {
  15270 	Fbits   vp8l_atype_t
  15271 	Fused   int32
  15272 	Fbuf    uintptr
  15273 	Fcur    uintptr
  15274 	Fend    uintptr
  15275 	Ferror1 int32
  15276 }
  15277 
  15278 type WebPPicture = struct {
  15279 	Fuse_argb        int32
  15280 	Fcolorspace      WebPEncCSP1
  15281 	Fwidth           int32
  15282 	Fheight          int32
  15283 	Fy               uintptr
  15284 	Fu               uintptr
  15285 	Fv               uintptr
  15286 	Fy_stride        int32
  15287 	Fuv_stride       int32
  15288 	Fa               uintptr
  15289 	Fa_stride        int32
  15290 	Fpad1            [2]uint32_t
  15291 	Fargb            uintptr
  15292 	Fargb_stride     int32
  15293 	Fpad2            [3]uint32_t
  15294 	Fwriter          WebPWriterFunction
  15295 	Fcustom_ptr      uintptr
  15296 	Fextra_info_type int32
  15297 	Fextra_info      uintptr
  15298 	Fstats           uintptr
  15299 	Ferror_code      WebPEncodingError1
  15300 	Fprogress_hook   WebPProgressHook
  15301 	Fuser_data       uintptr
  15302 	Fpad3            [3]uint32_t
  15303 	Fpad4            uintptr
  15304 	Fpad5            uintptr
  15305 	Fpad6            [8]uint32_t
  15306 	Fmemory_         uintptr
  15307 	Fmemory_argb_    uintptr
  15308 	Fpad7            [2]uintptr
  15309 }
  15310 
  15311 type WebPEncCSP = int32
  15312 
  15313 const WEBP_YUV420 = 0
  15314 const WEBP_YUV420A = 4
  15315 const WEBP_CSP_UV_MASK = 3
  15316 const WEBP_CSP_ALPHA_BIT = 4
  15317 
  15318 type WebPEncodingError = int32
  15319 
  15320 const VP8_ENC_OK = 0
  15321 const VP8_ENC_ERROR_OUT_OF_MEMORY = 1
  15322 const VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY = 2
  15323 const VP8_ENC_ERROR_NULL_PARAMETER = 3
  15324 const VP8_ENC_ERROR_INVALID_CONFIGURATION = 4
  15325 const VP8_ENC_ERROR_BAD_DIMENSION = 5
  15326 const VP8_ENC_ERROR_PARTITION0_OVERFLOW = 6
  15327 const VP8_ENC_ERROR_PARTITION_OVERFLOW = 7
  15328 const VP8_ENC_ERROR_BAD_WRITE = 8
  15329 const VP8_ENC_ERROR_FILE_TOO_BIG = 9
  15330 const VP8_ENC_ERROR_USER_ABORT = 10
  15331 const VP8_ENC_ERROR_LAST = 11
  15332 
  15333 type WebPConfig = struct {
  15334 	Flossless          int32
  15335 	Fquality           float32
  15336 	Fmethod            int32
  15337 	Fimage_hint        WebPImageHint1
  15338 	Ftarget_size       int32
  15339 	Ftarget_PSNR       float32
  15340 	Fsegments          int32
  15341 	Fsns_strength      int32
  15342 	Ffilter_strength   int32
  15343 	Ffilter_sharpness  int32
  15344 	Ffilter_type       int32
  15345 	Fautofilter        int32
  15346 	Falpha_compression int32
  15347 	Falpha_filtering   int32
  15348 	Falpha_quality     int32
  15349 	Fpass              int32
  15350 	Fshow_compressed   int32
  15351 	Fpreprocessing     int32
  15352 	Fpartitions        int32
  15353 	Fpartition_limit   int32
  15354 	Femulate_jpeg_size int32
  15355 	Fthread_level      int32
  15356 	Flow_memory        int32
  15357 	Fnear_lossless     int32
  15358 	Fexact             int32
  15359 	Fuse_delta_palette int32
  15360 	Fuse_sharp_yuv     int32
  15361 	Fqmin              int32
  15362 	Fqmax              int32
  15363 }
  15364 
  15365 type WebPImageHint = int32
  15366 
  15367 const WEBP_HINT_DEFAULT = 0
  15368 const WEBP_HINT_PICTURE = 1
  15369 const WEBP_HINT_PHOTO = 2
  15370 const WEBP_HINT_GRAPH = 3
  15371 const WEBP_HINT_LAST = 4
  15372 
  15373 type WebPAuxStats = struct {
  15374 	Fcoded_size                 int32
  15375 	FPSNR                       [5]float32
  15376 	Fblock_count                [3]int32
  15377 	Fheader_bytes               [2]int32
  15378 	Fresidual_bytes             [3][4]int32
  15379 	Fsegment_size               [4]int32
  15380 	Fsegment_quant              [4]int32
  15381 	Fsegment_level              [4]int32
  15382 	Falpha_data_size            int32
  15383 	Flayer_data_size            int32
  15384 	Flossless_features          uint32_t
  15385 	Fhistogram_bits             int32
  15386 	Ftransform_bits             int32
  15387 	Fcache_bits                 int32
  15388 	Fpalette_size               int32
  15389 	Flossless_size              int32
  15390 	Flossless_hdr_size          int32
  15391 	Flossless_data_size         int32
  15392 	Fcross_color_transform_bits int32
  15393 	Fpad                        [1]uint32_t
  15394 }
  15395 
  15396 type WebPMemoryWriter = struct {
  15397 	Fmem      uintptr
  15398 	Fsize     size_t
  15399 	Fmax_size size_t
  15400 	Fpad      [1]uint32_t
  15401 }
  15402 
  15403 type WebPImageHint1 = int32
  15404 
  15405 type WebPPreset1 = int32
  15406 
  15407 type WebPPreset = int32
  15408 
  15409 const WEBP_PRESET_DEFAULT = 0
  15410 const WEBP_PRESET_PICTURE = 1
  15411 const WEBP_PRESET_PHOTO = 2
  15412 const WEBP_PRESET_DRAWING = 3
  15413 const WEBP_PRESET_ICON = 4
  15414 const WEBP_PRESET_TEXT = 5
  15415 
  15416 type WebPWriterFunction = uintptr
  15417 
  15418 type WebPProgressHook = uintptr
  15419 
  15420 type WebPEncCSP1 = int32
  15421 
  15422 type WebPEncodingError1 = int32
  15423 
  15424 const MAX_LF_LEVELS = 64
  15425 const MAX_VARIABLE_LEVEL = 67
  15426 const MAX_LEVEL = 2047
  15427 
  15428 type VP8RDLevel = int32
  15429 
  15430 const RD_OPT_NONE = 0
  15431 const RD_OPT_BASIC = 1
  15432 const RD_OPT_TRELLIS = 2
  15433 const RD_OPT_TRELLIS_ALL = 3
  15434 
  15435 type score_t = int64
  15436 
  15437 type proba_t = uint32
  15438 
  15439 type ProbaArray = [3][11]uint8_t
  15440 
  15441 type StatsArray = [3][11]proba_t
  15442 
  15443 type CostArray = [3][68]uint16_t
  15444 
  15445 type CostArrayPtr = uintptr
  15446 
  15447 type CostArrayMap = [16][3]uintptr
  15448 
  15449 type LFStats = [4][64]float64
  15450 
  15451 type VP8Encoder = struct {
  15452 	Fconfig             uintptr
  15453 	Fpic                uintptr
  15454 	Ffilter_hdr         VP8EncFilterHeader
  15455 	Fsegment_hdr        VP8EncSegmentHeader
  15456 	Fprofile            int32
  15457 	Fmb_w               int32
  15458 	Fmb_h               int32
  15459 	Fpreds_w            int32
  15460 	Fnum_parts          int32
  15461 	Fbw                 VP8BitWriter
  15462 	Fparts              [8]VP8BitWriter
  15463 	Ftokens             VP8TBuffer
  15464 	Fpercent            int32
  15465 	Fhas_alpha          int32
  15466 	Falpha_data         uintptr
  15467 	Falpha_data_size    uint32_t
  15468 	Falpha_worker       WebPWorker
  15469 	Fdqm                [4]VP8SegmentInfo
  15470 	Fbase_quant         int32
  15471 	Falpha              int32
  15472 	Fuv_alpha           int32
  15473 	Fdq_y1_dc           int32
  15474 	Fdq_y2_dc           int32
  15475 	Fdq_y2_ac           int32
  15476 	Fdq_uv_dc           int32
  15477 	Fdq_uv_ac           int32
  15478 	Fproba              VP8EncProba
  15479 	Fsse                [4]uint64_t
  15480 	Fsse_count          uint64_t
  15481 	Fcoded_size         int32
  15482 	Fresidual_bytes     [3][4]int32
  15483 	Fblock_count        [3]int32
  15484 	Fmethod             int32
  15485 	Frd_opt_level       VP8RDLevel
  15486 	Fmax_i4_header_bits int32
  15487 	Fmb_header_limit    int32
  15488 	Fthread_level       int32
  15489 	Fdo_search          int32
  15490 	Fuse_tokens         int32
  15491 	Fmb_info            uintptr
  15492 	Fpreds              uintptr
  15493 	Fnz                 uintptr
  15494 	Fy_top              uintptr
  15495 	Fuv_top             uintptr
  15496 	Flf_stats           uintptr
  15497 	Ftop_derr           uintptr
  15498 }
  15499 
  15500 type VP8EncSegmentHeader = struct {
  15501 	Fnum_segments int32
  15502 	Fupdate_map   int32
  15503 	Fsize         int32
  15504 }
  15505 
  15506 type VP8EncProba = struct {
  15507 	Fsegments       [3]uint8_t
  15508 	Fskip_proba     uint8_t
  15509 	Fcoeffs         [4][8]ProbaArray
  15510 	Fstats          [4][8]StatsArray
  15511 	Flevel_cost     [4][8]CostArray
  15512 	Fremapped_costs [4]CostArrayMap
  15513 	Fdirty          int32
  15514 	Fuse_skip_proba int32
  15515 	Fnb_skip        int32
  15516 }
  15517 
  15518 type VP8EncFilterHeader = struct {
  15519 	Fsimple        int32
  15520 	Flevel         int32
  15521 	Fsharpness     int32
  15522 	Fi4x4_lf_delta int32
  15523 }
  15524 
  15525 type VP8MBInfo = struct {
  15526 	F__ccgo_align [0]uint32
  15527 	F__ccgo0      uint8
  15528 	Falpha        uint8_t
  15529 }
  15530 
  15531 type VP8SegmentInfo = struct {
  15532 	Fy1                 VP8Matrix
  15533 	Fy2                 VP8Matrix
  15534 	Fuv                 VP8Matrix
  15535 	Falpha              int32
  15536 	Fbeta               int32
  15537 	Fquant              int32
  15538 	Ffstrength          int32
  15539 	Fmax_edge           int32
  15540 	Fmin_disto          int32
  15541 	Flambda_i16         int32
  15542 	Flambda_i4          int32
  15543 	Flambda_uv          int32
  15544 	Flambda_mode        int32
  15545 	Flambda_trellis     int32
  15546 	Ftlambda            int32
  15547 	Flambda_trellis_i16 int32
  15548 	Flambda_trellis_i4  int32
  15549 	Flambda_trellis_uv  int32
  15550 	Fi4_penalty         score_t
  15551 }
  15552 
  15553 type DError = [2][2]int8_t
  15554 
  15555 type VP8ModeScore = struct {
  15556 	FD           score_t
  15557 	FSD          score_t
  15558 	FH           score_t
  15559 	FR           score_t
  15560 	Fscore       score_t
  15561 	Fy_dc_levels [16]int16_t
  15562 	Fy_ac_levels [16][16]int16_t
  15563 	Fuv_levels   [8][16]int16_t
  15564 	Fmode_i16    int32
  15565 	Fmodes_i4    [16]uint8_t
  15566 	Fmode_uv     int32
  15567 	Fnz          uint32_t
  15568 	Fderr        [2][3]int8_t
  15569 }
  15570 
  15571 type VP8EncIterator = struct {
  15572 	Fx            int32
  15573 	Fy            int32
  15574 	Fyuv_in       uintptr
  15575 	Fyuv_out      uintptr
  15576 	Fyuv_out2     uintptr
  15577 	Fyuv_p        uintptr
  15578 	Fenc          uintptr
  15579 	Fmb           uintptr
  15580 	Fbw           uintptr
  15581 	Fpreds        uintptr
  15582 	Fnz           uintptr
  15583 	Fi4_boundary  [37]uint8_t
  15584 	Fi4_top       uintptr
  15585 	Fi4           int32
  15586 	Ftop_nz       [9]int32
  15587 	Fleft_nz      [9]int32
  15588 	Fbit_count    [4][3]uint64_t
  15589 	Fluma_bits    uint64_t
  15590 	Fuv_bits      uint64_t
  15591 	Flf_stats     uintptr
  15592 	Fdo_trellis   int32
  15593 	Fcount_down   int32
  15594 	Fcount_down0  int32
  15595 	Fpercent0     int32
  15596 	Fleft_derr    DError
  15597 	Ftop_derr     uintptr
  15598 	Fy_left       uintptr
  15599 	Fu_left       uintptr
  15600 	Fv_left       uintptr
  15601 	Fy_top        uintptr
  15602 	Fuv_top       uintptr
  15603 	Fyuv_left_mem [88]uint8_t
  15604 	Fyuv_mem      [3359]uint8_t
  15605 }
  15606 
  15607 type VP8TBuffer = struct {
  15608 	Fpages     uintptr
  15609 	Flast_page uintptr
  15610 	Ftokens    uintptr
  15611 	Fleft      int32
  15612 	Fpage_size int32
  15613 	Ferror1    int32
  15614 }
  15615 
  15616 type Mode = int32
  15617 
  15618 const kLiteral = 0
  15619 const kCacheIdx = 1
  15620 const kCopy = 2
  15621 const kNone = 3
  15622 
  15623 type PixOrCopy = struct {
  15624 	Fmode             uint8_t
  15625 	Flen1             uint16_t
  15626 	Fargb_or_distance uint32_t
  15627 }
  15628 
  15629 type VP8LHashChain = struct {
  15630 	Foffset_length uintptr
  15631 	Fsize          int32
  15632 }
  15633 
  15634 type VP8LBackwardRefs = struct {
  15635 	Fblock_size  int32
  15636 	Ferror1      int32
  15637 	Frefs        uintptr
  15638 	Ftail        uintptr
  15639 	Ffree_blocks uintptr
  15640 	Flast_block  uintptr
  15641 }
  15642 
  15643 type VP8LRefsCursor = struct {
  15644 	Fcur_pos   uintptr
  15645 	Fcur_block uintptr
  15646 	Flast_pos  uintptr
  15647 }
  15648 
  15649 type VP8LLZ77Type = int32
  15650 
  15651 const kLZ77Standard = 1
  15652 const kLZ77RLE = 2
  15653 const kLZ77Box = 4
  15654 
  15655 type VP8LHistogram = struct {
  15656 	Fliteral           uintptr
  15657 	Fred               [256]uint32_t
  15658 	Fblue              [256]uint32_t
  15659 	Falpha             [256]uint32_t
  15660 	Fdistance          [40]uint32_t
  15661 	Fpalette_code_bits int32
  15662 	Ftrivial_symbol    [5]uint16_t
  15663 	Fbit_cost          uint64_t
  15664 	Fcosts             [5]uint64_t
  15665 	Fis_used           [5]uint8_t
  15666 	Fbin_id            uint16_t
  15667 }
  15668 
  15669 type VP8LHistogramSet = struct {
  15670 	Fsize       int32
  15671 	Fmax_size   int32
  15672 	Fhistograms uintptr
  15673 }
  15674 
  15675 type VP8LEncoderARGBContent = int32
  15676 
  15677 const kEncoderNone = 0
  15678 const kEncoderARGB = 1
  15679 const kEncoderNearLossless = 2
  15680 const kEncoderPalette = 3
  15681 
  15682 type VP8LEncoder = struct {
  15683 	Fconfig                     uintptr
  15684 	Fpic                        uintptr
  15685 	Fargb                       uintptr
  15686 	Fargb_content               VP8LEncoderARGBContent
  15687 	Fargb_scratch               uintptr
  15688 	Ftransform_data             uintptr
  15689 	Ftransform_mem              uintptr
  15690 	Ftransform_mem_size         size_t
  15691 	Fcurrent_width              int32
  15692 	Fhisto_bits                 int32
  15693 	Fpredictor_transform_bits   int32
  15694 	Fcross_color_transform_bits int32
  15695 	Fcache_bits                 int32
  15696 	Fuse_cross_color            int32
  15697 	Fuse_subtract_green         int32
  15698 	Fuse_predict                int32
  15699 	Fuse_palette                int32
  15700 	Fpalette_size               int32
  15701 	Fpalette                    [256]uint32_t
  15702 	Fpalette_sorted             [256]uint32_t
  15703 	Frefs                       [4]VP8LBackwardRefs
  15704 	Fhash_chain                 VP8LHashChain
  15705 }
  15706 
  15707 //------------------------------------------------------------------------------
  15708 
  15709 func EncodeLossless(tls *libc.TLS, data uintptr, width int32, height int32, effort_level int32, use_quality_100 int32, bw uintptr, stats uintptr) (r int32) {
  15710 	bp := tls.Alloc(384)
  15711 	defer tls.Free(384)
  15712 	var ok, v1 int32
  15713 	var v5 float32
  15714 	var _ /* config at bp+0 */ WebPConfig
  15715 	var _ /* picture at bp+120 */ WebPPicture
  15716 	_, _, _ = ok, v1, v5
  15717 	ok = 0
  15718 	v1 = WebPPictureInitInternal(tls, bp+120, int32(WEBP_ENCODER_ABI_VERSION))
  15719 	goto _2
  15720 _2:
  15721 	if !(v1 != 0) {
  15722 		return 0
  15723 	}
  15724 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fwidth = width
  15725 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fheight = height
  15726 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fuse_argb = int32(1)
  15727 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fstats = stats
  15728 	if !(WebPPictureAlloc(tls, bp+120) != 0) {
  15729 		return 0
  15730 	}
  15731 	// Transfer the alpha values to the green channel.
  15732 	(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPDispatchAlphaToGreen})))(tls, data, width, (**(**WebPPicture)(__ccgo_up(bp + 120))).Fwidth, (**(**WebPPicture)(__ccgo_up(bp + 120))).Fheight, (**(**WebPPicture)(__ccgo_up(bp + 120))).Fargb, (**(**WebPPicture)(__ccgo_up(bp + 120))).Fargb_stride)
  15733 	v1 = WebPConfigInitInternal(tls, bp, int32(WEBP_PRESET_DEFAULT), libc.Float32FromFloat32(75), int32(WEBP_ENCODER_ABI_VERSION))
  15734 	goto _4
  15735 _4:
  15736 	if !(v1 != 0) {
  15737 		return 0
  15738 	}
  15739 	(**(**WebPConfig)(__ccgo_up(bp))).Flossless = int32(1)
  15740 	// Enable exact, or it would alter RGB values of transparent alpha, which is
  15741 	// normally OK but not here since we are not encoding the input image but  an
  15742 	// internal encoding-related image containing necessary exact information in
  15743 	// RGB channels.
  15744 	(**(**WebPConfig)(__ccgo_up(bp))).Fexact = int32(1)
  15745 	(**(**WebPConfig)(__ccgo_up(bp))).Fmethod = effort_level // impact is very small
  15746 	// Set a low default quality for encoding alpha. Ensure that Alpha quality at
  15747 	// lower methods (3 and below) is less than the threshold for triggering
  15748 	// costly 'BackwardReferencesTraceBackwards'.
  15749 	// If the alpha quality is set to 100 and the method to 6, allow for a high
  15750 	// lossless quality to trigger the cruncher.
  15751 	if use_quality_100 != 0 && effort_level == int32(6) {
  15752 		v5 = libc.Float32FromInt32(100)
  15753 	} else {
  15754 		v5 = float32(libc.Float32FromFloat32(8) * float32(effort_level))
  15755 	}
  15756 	(**(**WebPConfig)(__ccgo_up(bp))).Fquality = v5
  15757 	ok = VP8LEncodeStream(tls, bp, bp+120, bw)
  15758 	WebPPictureFree(tls, bp+120)
  15759 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 != 0))
  15760 	if !(ok != 0) {
  15761 		VP8LBitWriterWipeOut(tls, bw)
  15762 		return 0
  15763 	}
  15764 	return int32(1)
  15765 }
  15766 
  15767 // -----------------------------------------------------------------------------
  15768 
  15769 // C documentation
  15770 //
  15771 //	// Small struct to hold the result of a filter mode compression attempt.
  15772 type FilterTrial = struct {
  15773 	Fscore size_t
  15774 	Fbw    VP8BitWriter
  15775 	Fstats WebPAuxStats
  15776 }
  15777 
  15778 // C documentation
  15779 //
  15780 //	// This function always returns an initialized 'bw' object, even upon error.
  15781 func EncodeAlphaInternal(tls *libc.TLS, data uintptr, width int32, height int32, method int32, filter int32, reduce_levels int32, effort_level int32, tmp_alpha uintptr, result uintptr) (r int32) {
  15782 	bp := tls.Alloc(64)
  15783 	defer tls.Free(64)
  15784 	var alpha_src, output, v1 uintptr
  15785 	var data_size, output_size, v2 size_t
  15786 	var filter_func WebPFilterFunc
  15787 	var ok int32
  15788 	var _ /* header at bp+0 */ uint8_t
  15789 	var _ /* tmp_bw at bp+8 */ VP8LBitWriter
  15790 	_, _, _, _, _, _, _, _ = alpha_src, data_size, filter_func, ok, output, output_size, v1, v2
  15791 	ok = 0
  15792 	data_size = libc.Uint64FromInt32(width * height)
  15793 	output = libc.UintptrFromInt32(0)
  15794 	output_size = uint64(0)
  15795 	// as per spec
  15796 	filter_func = WebPFilters[filter]
  15797 	if filter_func != libc.UintptrFromInt32(0) {
  15798 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{filter_func})))(tls, data, width, height, width, tmp_alpha)
  15799 		alpha_src = tmp_alpha
  15800 	} else {
  15801 		alpha_src = data
  15802 	}
  15803 	if method != ALPHA_NO_COMPRESSION {
  15804 		ok = VP8LBitWriterInit(tls, bp+8, data_size>>int32(3))
  15805 		ok = libc.BoolInt32(ok != 0 && EncodeLossless(tls, alpha_src, width, height, effort_level, libc.BoolInt32(!(reduce_levels != 0)), bp+8, result+56) != 0)
  15806 		if ok != 0 {
  15807 			output = VP8LBitWriterFinish(tls, bp+8)
  15808 			if (**(**VP8LBitWriter)(__ccgo_up(bp + 8))).Ferror1 != 0 {
  15809 				VP8LBitWriterWipeOut(tls, bp+8)
  15810 				libc.Xmemset(tls, result+8, 0, uint64(48))
  15811 				return 0
  15812 			}
  15813 			v1 = bp + 8
  15814 			v2 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  15815 			goto _3
  15816 		_3:
  15817 			output_size = v2
  15818 			if output_size > data_size {
  15819 				// compressed size is larger than source! Revert to uncompressed mode.
  15820 				method = ALPHA_NO_COMPRESSION
  15821 				VP8LBitWriterWipeOut(tls, bp+8)
  15822 			}
  15823 		} else {
  15824 			VP8LBitWriterWipeOut(tls, bp+8)
  15825 			libc.Xmemset(tls, result+8, 0, uint64(48))
  15826 			return 0
  15827 		}
  15828 	}
  15829 	if method == ALPHA_NO_COMPRESSION {
  15830 		output = alpha_src
  15831 		output_size = data_size
  15832 		ok = int32(1)
  15833 	}
  15834 	// Emit final result.
  15835 	**(**uint8_t)(__ccgo_up(bp)) = libc.Uint8FromInt32(method | filter<<int32(2))
  15836 	if reduce_levels != 0 {
  15837 		**(**uint8_t)(__ccgo_up(bp)) = libc.Uint8FromInt32(int32(**(**uint8_t)(__ccgo_up(bp))) | libc.Int32FromInt32(ALPHA_PREPROCESSED_LEVELS)<<libc.Int32FromInt32(4))
  15838 	}
  15839 	if !(VP8BitWriterInit(tls, result+8, uint64(ALPHA_HEADER_LEN)+output_size) != 0) {
  15840 		ok = 0
  15841 	}
  15842 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, bp, uint64(ALPHA_HEADER_LEN)) != 0)
  15843 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, output, output_size) != 0)
  15844 	if method != ALPHA_NO_COMPRESSION {
  15845 		VP8LBitWriterWipeOut(tls, bp+8)
  15846 	}
  15847 	ok = libc.BoolInt32(ok != 0 && !((*FilterTrial)(unsafe.Pointer(result)).Fbw.Ferror1 != 0))
  15848 	v2 = (*VP8BitWriter)(unsafe.Pointer(result + 8)).Fpos
  15849 	goto _5
  15850 _5:
  15851 	(*FilterTrial)(unsafe.Pointer(result)).Fscore = v2
  15852 	return ok
  15853 }
  15854 
  15855 // -----------------------------------------------------------------------------
  15856 
  15857 func GetNumColors(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r int32) {
  15858 	var color [256]uint8_t
  15859 	var colors, i, j int32
  15860 	var p uintptr
  15861 	_, _, _, _, _ = color, colors, i, j, p
  15862 	colors = 0
  15863 	color = [256]uint8_t{}
  15864 	j = 0
  15865 	for {
  15866 		if !(j < height) {
  15867 			break
  15868 		}
  15869 		p = data + uintptr(j*stride)
  15870 		i = 0
  15871 		for {
  15872 			if !(i < width) {
  15873 				break
  15874 			}
  15875 			color[**(**uint8_t)(__ccgo_up(p + uintptr(i)))] = uint8(1)
  15876 			goto _2
  15877 		_2:
  15878 			;
  15879 			i = i + 1
  15880 		}
  15881 		goto _1
  15882 	_1:
  15883 		;
  15884 		j = j + 1
  15885 	}
  15886 	j = 0
  15887 	for {
  15888 		if !(j < int32(256)) {
  15889 			break
  15890 		}
  15891 		if libc.Int32FromUint8(color[j]) > 0 {
  15892 			colors = colors + 1
  15893 		}
  15894 		goto _3
  15895 	_3:
  15896 		;
  15897 		j = j + 1
  15898 	}
  15899 	return colors
  15900 }
  15901 
  15902 // C documentation
  15903 //
  15904 //	// Given the input 'filter' option, return an OR'd bit-set of filters to try.
  15905 func GetFilterMap(tls *libc.TLS, alpha uintptr, width int32, height int32, filter int32, effort_level int32) (r uint32_t) {
  15906 	var bit_map uint32_t
  15907 	var kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1 int32
  15908 	_, _, _, _, _, _ = bit_map, kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1
  15909 	bit_map = 0
  15910 	if filter == int32(WEBP_FILTER_FAST) {
  15911 		// Quick estimate of the best candidate.
  15912 		try_filter_none = libc.BoolInt32(effort_level > int32(3))
  15913 		kMinColorsForFilterNone = int32(16)
  15914 		kMaxColorsForFilterNone = int32(192)
  15915 		num_colors = GetNumColors(tls, alpha, width, height, width)
  15916 		// For low number of colors, NONE yields better compression.
  15917 		if num_colors <= kMinColorsForFilterNone {
  15918 			v1 = int32(WEBP_FILTER_NONE)
  15919 		} else {
  15920 			v1 = WebPEstimateBestFilter(tls, alpha, width, height, width)
  15921 		}
  15922 		filter = v1
  15923 		bit_map = bit_map | libc.Uint32FromInt32(int32(1)<<filter)
  15924 		// For large number of colors, try FILTER_NONE in addition to the best
  15925 		// filter as well.
  15926 		if try_filter_none != 0 || num_colors > kMaxColorsForFilterNone {
  15927 			bit_map = bit_map | libc.Uint32FromInt32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE))
  15928 		}
  15929 	} else {
  15930 		if filter == int32(WEBP_FILTER_NONE) {
  15931 			bit_map = libc.Uint32FromInt32(libc.Int32FromInt32(1) << int32(WEBP_FILTER_NONE))
  15932 		} else { // WEBP_FILTER_BEST -> try all
  15933 			bit_map = libc.Uint32FromInt32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_LAST) - libc.Int32FromInt32(1))
  15934 		}
  15935 	}
  15936 	return bit_map
  15937 }
  15938 
  15939 func InitFilterTrial(tls *libc.TLS, score uintptr) {
  15940 	(*FilterTrial)(unsafe.Pointer(score)).Fscore = uint64(^libc.Uint32FromUint32(0))
  15941 	VP8BitWriterInit(tls, score+8, uint64(0))
  15942 }
  15943 
  15944 func ApplyFiltersAndEncode(tls *libc.TLS, alpha uintptr, width int32, height int32, data_size size_t, method int32, filter int32, reduce_levels int32, effort_level int32, output uintptr, output_size uintptr, stats uintptr) (r int32) {
  15945 	bp := tls.Alloc(496)
  15946 	defer tls.Free(496)
  15947 	var filtered_alpha, v4 uintptr
  15948 	var ok int32
  15949 	var try_map uint32_t
  15950 	var v2 size_t
  15951 	var _ /* best at bp+0 */ FilterTrial
  15952 	var _ /* trial at bp+248 */ FilterTrial
  15953 	_, _, _, _, _ = filtered_alpha, ok, try_map, v2, v4
  15954 	ok = int32(1)
  15955 	try_map = GetFilterMap(tls, alpha, width, height, filter, effort_level)
  15956 	InitFilterTrial(tls, bp)
  15957 	if try_map != libc.Uint32FromInt32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE)) {
  15958 		filtered_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  15959 		if filtered_alpha == libc.UintptrFromInt32(0) {
  15960 			return 0
  15961 		}
  15962 		filter = int32(WEBP_FILTER_NONE)
  15963 		for {
  15964 			if !(ok != 0 && try_map != 0) {
  15965 				break
  15966 			}
  15967 			if try_map&uint32(1) != 0 {
  15968 				ok = EncodeAlphaInternal(tls, alpha, width, height, method, filter, reduce_levels, effort_level, filtered_alpha, bp+248)
  15969 				if ok != 0 && (**(**FilterTrial)(__ccgo_up(bp + 248))).Fscore < (**(**FilterTrial)(__ccgo_up(bp))).Fscore {
  15970 					VP8BitWriterWipeOut(tls, bp+8)
  15971 					**(**FilterTrial)(__ccgo_up(bp)) = **(**FilterTrial)(__ccgo_up(bp + 248))
  15972 				} else {
  15973 					VP8BitWriterWipeOut(tls, bp+248+8)
  15974 				}
  15975 			}
  15976 			goto _1
  15977 		_1:
  15978 			;
  15979 			filter = filter + 1
  15980 			try_map = try_map >> uint32(1)
  15981 		}
  15982 		WebPSafeFree(tls, filtered_alpha)
  15983 	} else {
  15984 		ok = EncodeAlphaInternal(tls, alpha, width, height, method, int32(WEBP_FILTER_NONE), reduce_levels, effort_level, libc.UintptrFromInt32(0), bp)
  15985 	}
  15986 	if ok != 0 {
  15987 		if stats != libc.UintptrFromInt32(0) {
  15988 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_features
  15989 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fhistogram_bits
  15990 			(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Ftransform_bits
  15991 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcross_color_transform_bits
  15992 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcache_bits
  15993 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fpalette_size
  15994 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_size
  15995 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_hdr_size
  15996 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_data_size
  15997 		}
  15998 		v2 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fpos
  15999 		goto _3
  16000 	_3:
  16001 		**(**size_t)(__ccgo_up(output_size)) = v2
  16002 		v4 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fbuf
  16003 		goto _5
  16004 	_5:
  16005 		**(**uintptr)(__ccgo_up(output)) = v4
  16006 	} else {
  16007 		VP8BitWriterWipeOut(tls, bp+8)
  16008 	}
  16009 	return ok
  16010 }
  16011 
  16012 func EncodeAlpha(tls *libc.TLS, enc uintptr, quality int32, method int32, filter int32, effort_level int32, output uintptr, output_size uintptr) (r int32) {
  16013 	bp := tls.Alloc(16)
  16014 	defer tls.Free(16)
  16015 	var alpha_levels, height, ok, reduce_levels, width, v1 int32
  16016 	var data_size size_t
  16017 	var pic, quant_alpha uintptr
  16018 	var _ /* sse at bp+0 */ uint64_t
  16019 	_, _, _, _, _, _, _, _, _ = alpha_levels, data_size, height, ok, pic, quant_alpha, reduce_levels, width, v1
  16020 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  16021 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  16022 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  16023 	quant_alpha = libc.UintptrFromInt32(0)
  16024 	data_size = libc.Uint64FromInt32(width * height)
  16025 	**(**uint64_t)(__ccgo_up(bp)) = uint64(0)
  16026 	ok = int32(1)
  16027 	reduce_levels = libc.BoolInt32(quality < libc.Int32FromInt32(100))
  16028 	// quick correctness checks
  16029 	// as per spec
  16030 	if quality < 0 || quality > int32(100) {
  16031 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16032 	}
  16033 	if method < ALPHA_NO_COMPRESSION || method > int32(ALPHA_LOSSLESS_COMPRESSION) {
  16034 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16035 	}
  16036 	if method == ALPHA_NO_COMPRESSION {
  16037 		// Don't filter, as filtering will make no impact on compressed size.
  16038 		filter = int32(WEBP_FILTER_NONE)
  16039 	}
  16040 	quant_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16041 	if quant_alpha == libc.UintptrFromInt32(0) {
  16042 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16043 	}
  16044 	// Extract alpha data (width x height) from raw_data (stride x height).
  16045 	WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fa, (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride, quant_alpha, width, width, height)
  16046 	if reduce_levels != 0 {
  16047 		if quality <= int32(70) {
  16048 			v1 = int32(2) + quality/int32(5)
  16049 		} else {
  16050 			v1 = int32(16) + (quality-int32(70))*int32(8)
  16051 		} // No Quantization required for 'quality = 100'.
  16052 		// 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence
  16053 		// mapped to moderate quality 70. Hence Quality:[0, 70] -> Levels:[2, 16]
  16054 		// and Quality:]70, 100] -> Levels:]16, 256].
  16055 		alpha_levels = v1
  16056 		ok = QuantizeLevels(tls, quant_alpha, width, height, alpha_levels, bp)
  16057 	}
  16058 	if ok != 0 {
  16059 		VP8FiltersInit(tls)
  16060 		ok = ApplyFiltersAndEncode(tls, quant_alpha, width, height, data_size, method, filter, reduce_levels, effort_level, output, output_size, (*WebPPicture)(unsafe.Pointer(pic)).Fstats)
  16061 		if !(ok != 0) {
  16062 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  16063 		}
  16064 		if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) { // need stats?
  16065 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fstats)) += libc.Int32FromUint64(**(**size_t)(__ccgo_up(output_size)))
  16066 			**(**uint64_t)(__ccgo_up(enc + 23512 + 3*8)) = **(**uint64_t)(__ccgo_up(bp))
  16067 		}
  16068 	}
  16069 	WebPSafeFree(tls, quant_alpha)
  16070 	return ok
  16071 }
  16072 
  16073 //------------------------------------------------------------------------------
  16074 // Main calls
  16075 
  16076 func CompressAlphaJob(tls *libc.TLS, arg1 uintptr, unused uintptr) (r int32) {
  16077 	bp := tls.Alloc(16)
  16078 	defer tls.Free(16)
  16079 	var config, enc uintptr
  16080 	var effort_level, v1, v2 int32
  16081 	var filter WEBP_FILTER_TYPE
  16082 	var _ /* alpha_data at bp+0 */ uintptr
  16083 	var _ /* alpha_size at bp+8 */ size_t
  16084 	_, _, _, _, _, _ = config, effort_level, enc, filter, v1, v2
  16085 	enc = arg1
  16086 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  16087 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  16088 	**(**size_t)(__ccgo_up(bp + 8)) = uint64(0)
  16089 	effort_level = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  16090 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == 0 {
  16091 		v1 = int32(WEBP_FILTER_NONE)
  16092 	} else {
  16093 		if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == int32(1) {
  16094 			v2 = int32(WEBP_FILTER_FAST)
  16095 		} else {
  16096 			v2 = int32(WEBP_FILTER_BEST)
  16097 		}
  16098 		v1 = v2
  16099 	} // maps to [0..6]
  16100 	filter = v1
  16101 	if !(EncodeAlpha(tls, enc, (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality, (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression, filter, effort_level, bp, bp+8) != 0) {
  16102 		return 0
  16103 	}
  16104 	if **(**size_t)(__ccgo_up(bp + 8)) != uint64(uint32(**(**size_t)(__ccgo_up(bp + 8)))) { // Soundness check.
  16105 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  16106 		return 0
  16107 	}
  16108 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(**(**size_t)(__ccgo_up(bp + 8)))
  16109 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = **(**uintptr)(__ccgo_up(bp))
  16110 	_ = unused
  16111 	return int32(1)
  16112 }
  16113 
  16114 func VP8EncInitAlpha(tls *libc.TLS, enc uintptr) {
  16115 	var worker uintptr
  16116 	_ = worker
  16117 	WebPInitAlphaProcessing(tls)
  16118 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = WebPPictureHasTransparency(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic)
  16119 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16120 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16121 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16122 		worker = enc + 560
  16123 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, worker)
  16124 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = enc
  16125 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  16126 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(CompressAlphaJob)
  16127 	}
  16128 }
  16129 
  16130 func VP8EncStartAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16131 	var worker uintptr
  16132 	_ = worker
  16133 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16134 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16135 			worker = enc + 560
  16136 			// Makes sure worker is good to go.
  16137 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
  16138 				return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16139 			}
  16140 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
  16141 			return int32(1)
  16142 		} else {
  16143 			return CompressAlphaJob(tls, enc, libc.UintptrFromInt32(0)) // just do the job right away
  16144 		}
  16145 	}
  16146 	return int32(1)
  16147 }
  16148 
  16149 func VP8EncFinishAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16150 	var worker uintptr
  16151 	_ = worker
  16152 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16153 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16154 			worker = enc + 560
  16155 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker) != 0) {
  16156 				return 0
  16157 			} // error
  16158 		}
  16159 	}
  16160 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  16161 }
  16162 
  16163 func VP8EncDeleteAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16164 	var ok int32
  16165 	var worker uintptr
  16166 	_, _ = ok, worker
  16167 	ok = int32(1)
  16168 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16169 		worker = enc + 560
  16170 		// finish anything left in flight
  16171 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
  16172 		// still need to end the worker, even if !ok
  16173 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, worker)
  16174 	}
  16175 	WebPSafeFree(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data)
  16176 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16177 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16178 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = 0
  16179 	return ok
  16180 }
  16181 
  16182 const MAX_ALPHA = 255
  16183 const MAX_INTRA16_MODE = 2
  16184 const MAX_INTRA4_MODE = 2
  16185 const MAX_ITERS_K_MEANS = 6
  16186 const MAX_UV_MODE = 2
  16187 
  16188 //------------------------------------------------------------------------------
  16189 
  16190 // Copyright 2011 Google Inc. All Rights Reserved.
  16191 //
  16192 // Use of this source code is governed by a BSD-style license
  16193 // that can be found in the COPYING file in the root of the source
  16194 // tree. An additional intellectual property rights grant can be found
  16195 // in the file PATENTS. All contributing project authors may
  16196 // be found in the AUTHORS file in the root of the source tree.
  16197 // -----------------------------------------------------------------------------
  16198 //
  16199 // Multi-threaded worker
  16200 //
  16201 // Author: Skal (pascal.massimino@gmail.com)
  16202 
  16203 // Copyright 2012 Google Inc. All Rights Reserved.
  16204 //
  16205 // Use of this source code is governed by a BSD-style license
  16206 // that can be found in the COPYING file in the root of the source
  16207 // tree. An additional intellectual property rights grant can be found
  16208 // in the file PATENTS. All contributing project authors may
  16209 // be found in the AUTHORS file in the root of the source tree.
  16210 // -----------------------------------------------------------------------------
  16211 //
  16212 // Misc. common utility functions
  16213 //
  16214 // Authors: Skal (pascal.massimino@gmail.com)
  16215 //          Urvang (urvang@google.com)
  16216 
  16217 // Copyright 2011 Google Inc. All Rights Reserved.
  16218 //
  16219 // Use of this source code is governed by a BSD-style license
  16220 // that can be found in the COPYING file in the root of the source
  16221 // tree. An additional intellectual property rights grant can be found
  16222 // in the file PATENTS. All contributing project authors may
  16223 // be found in the AUTHORS file in the root of the source tree.
  16224 // -----------------------------------------------------------------------------
  16225 //
  16226 //   WebP encoder: main interface
  16227 //
  16228 // Author: Skal (pascal.massimino@gmail.com)
  16229 
  16230 // Copyright 2010 Google Inc. All Rights Reserved.
  16231 //
  16232 // Use of this source code is governed by a BSD-style license
  16233 // that can be found in the COPYING file in the root of the source
  16234 // tree. An additional intellectual property rights grant can be found
  16235 // in the file PATENTS. All contributing project authors may
  16236 // be found in the AUTHORS file in the root of the source tree.
  16237 // -----------------------------------------------------------------------------
  16238 //
  16239 //  Common types + memory wrappers
  16240 //
  16241 // Author: Skal (pascal.massimino@gmail.com)
  16242 
  16243 //------------------------------------------------------------------------------
  16244 // Smooth the segment map by replacing isolated block by the majority of its
  16245 // neighbours.
  16246 
  16247 func SmoothSegmentMap(tls *libc.TLS, enc uintptr) {
  16248 	var cnt [4]int32
  16249 	var h, majority_cnt_3_x_3_grid, majority_seg, n, w, x, y int32
  16250 	var mb, mb1, tmp uintptr
  16251 	_, _, _, _, _, _, _, _, _, _, _ = cnt, h, majority_cnt_3_x_3_grid, majority_seg, mb, mb1, n, tmp, w, x, y
  16252 	w = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  16253 	h = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  16254 	majority_cnt_3_x_3_grid = int32(5)
  16255 	tmp = WebPSafeMalloc(tls, libc.Uint64FromInt32(w*h), uint64(1))
  16256 	// no overflow, as per spec
  16257 	if tmp == libc.UintptrFromInt32(0) {
  16258 		return
  16259 	}
  16260 	y = int32(1)
  16261 	for {
  16262 		if !(y < h-int32(1)) {
  16263 			break
  16264 		}
  16265 		x = int32(1)
  16266 		for {
  16267 			if !(x < w-int32(1)) {
  16268 				break
  16269 			}
  16270 			cnt = [4]int32{}
  16271 			mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16272 			majority_seg = int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5))
  16273 			// Check the 8 neighbouring segment values.
  16274 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-w-int32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-w-int32(1))*4 + 0))&0x60>>5))] + 1                         // top-left
  16275 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-w+0)*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-w+0)*4 + 0))&0x60>>5))] + 1                                       // top
  16276 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-w+int32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-w+int32(1))*4 + 0))&0x60>>5))] + 1                         // top-right
  16277 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-libc.Int32FromInt32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(-libc.Int32FromInt32(1))*4 + 0))&0x60>>5))] + 1 // left
  16278 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(+libc.Int32FromInt32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(+libc.Int32FromInt32(1))*4 + 0))&0x60>>5))] + 1 // right
  16279 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(w-int32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(w-int32(1))*4 + 0))&0x60>>5))] + 1                           // bottom-left
  16280 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(w+0)*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(w+0)*4 + 0))&0x60>>5))] + 1                                         // bottom
  16281 			cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(w+int32(1))*4 + 0))&0x60>>5))] = cnt[int32(uint32(*(*uint8)(unsafe.Pointer(mb + uintptr(w+int32(1))*4 + 0))&0x60>>5))] + 1                           // bottom-right
  16282 			n = 0
  16283 			for {
  16284 				if !(n < int32(NUM_MB_SEGMENTS)) {
  16285 					break
  16286 				}
  16287 				if cnt[n] >= majority_cnt_3_x_3_grid {
  16288 					majority_seg = n
  16289 					break
  16290 				}
  16291 				goto _3
  16292 			_3:
  16293 				;
  16294 				n = n + 1
  16295 			}
  16296 			**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w))) = libc.Uint8FromInt32(majority_seg)
  16297 			goto _2
  16298 		_2:
  16299 			;
  16300 			x = x + 1
  16301 		}
  16302 		goto _1
  16303 	_1:
  16304 		;
  16305 		y = y + 1
  16306 	}
  16307 	y = int32(1)
  16308 	for {
  16309 		if !(y < h-int32(1)) {
  16310 			break
  16311 		}
  16312 		x = int32(1)
  16313 		for {
  16314 			if !(x < w-int32(1)) {
  16315 				break
  16316 			}
  16317 			mb1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16318 			libc.SetBitFieldPtr8Uint32(mb1+0, uint32(**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w)))), 5, 0x60)
  16319 			goto _5
  16320 		_5:
  16321 			;
  16322 			x = x + 1
  16323 		}
  16324 		goto _4
  16325 	_4:
  16326 		;
  16327 		y = y + 1
  16328 	}
  16329 	WebPSafeFree(tls, tmp)
  16330 }
  16331 
  16332 //------------------------------------------------------------------------------
  16333 // set segment susceptibility 'alpha' / 'beta'
  16334 
  16335 func clip1(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  16336 	var v1, v2 int32
  16337 	_, _ = v1, v2
  16338 	if v < m {
  16339 		v1 = m
  16340 	} else {
  16341 		if v > M {
  16342 			v2 = M
  16343 		} else {
  16344 			v2 = v
  16345 		}
  16346 		v1 = v2
  16347 	}
  16348 	return v1
  16349 }
  16350 
  16351 func SetSegmentAlphas(tls *libc.TLS, enc uintptr, centers uintptr, mid int32) {
  16352 	var alpha, beta, max, min, n, nb int32
  16353 	_, _, _, _, _, _ = alpha, beta, max, min, n, nb
  16354 	nb = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16355 	min = **(**int32)(__ccgo_up(centers))
  16356 	max = **(**int32)(__ccgo_up(centers))
  16357 	if nb > int32(1) {
  16358 		n = 0
  16359 		for {
  16360 			if !(n < nb) {
  16361 				break
  16362 			}
  16363 			if min > **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16364 				min = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16365 			}
  16366 			if max < **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16367 				max = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16368 			}
  16369 			goto _1
  16370 		_1:
  16371 			;
  16372 			n = n + 1
  16373 		}
  16374 	}
  16375 	if max == min {
  16376 		max = min + int32(1)
  16377 	}
  16378 	n = 0
  16379 	for {
  16380 		if !(n < nb) {
  16381 			break
  16382 		}
  16383 		alpha = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - mid) / (max - min)
  16384 		beta = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - min) / (max - min)
  16385 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Falpha = clip1(tls, alpha, -int32(127), int32(127))
  16386 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Fbeta = clip1(tls, beta, 0, int32(255))
  16387 		goto _2
  16388 	_2:
  16389 		;
  16390 		n = n + 1
  16391 	}
  16392 }
  16393 
  16394 //------------------------------------------------------------------------------
  16395 // Compute susceptibility based on DCT-coeff histograms:
  16396 // the higher, the "easier" the macroblock is to compress.
  16397 
  16398 func FinalAlphaValue(tls *libc.TLS, alpha int32) (r int32) {
  16399 	alpha = int32(MAX_ALPHA) - alpha
  16400 	return clip1(tls, alpha, 0, int32(MAX_ALPHA))
  16401 }
  16402 
  16403 func GetAlpha(tls *libc.TLS, histo uintptr) (r int32) {
  16404 	var alpha, last_non_zero, max_value, v1 int32
  16405 	_, _, _, _ = alpha, last_non_zero, max_value, v1
  16406 	// 'alpha' will later be clipped to [0..MAX_ALPHA] range, clamping outer
  16407 	// values which happen to be mostly noise. This leaves the maximum precision
  16408 	// for handling the useful small values which contribute most.
  16409 	max_value = (*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value
  16410 	last_non_zero = (*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero
  16411 	if max_value > int32(1) {
  16412 		v1 = libc.Int32FromInt32(2) * libc.Int32FromInt32(MAX_ALPHA) * last_non_zero / max_value
  16413 	} else {
  16414 		v1 = 0
  16415 	}
  16416 	alpha = v1
  16417 	return alpha
  16418 }
  16419 
  16420 func InitHistogram(tls *libc.TLS, histo uintptr) {
  16421 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = 0
  16422 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = int32(1)
  16423 }
  16424 
  16425 //------------------------------------------------------------------------------
  16426 // Simplified k-Means, to assign Nb segments based on alpha-histogram
  16427 
  16428 func AssignSegments(tls *libc.TLS, enc uintptr, alphas uintptr) {
  16429 	bp := tls.Alloc(48)
  16430 	defer tls.Free(48)
  16431 	var a, alpha, displaced, k, max_a, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1 int32
  16432 	var map1 [256]int32
  16433 	var mb uintptr
  16434 	var _ /* accum at bp+16 */ [4]int32
  16435 	var _ /* centers at bp+0 */ [4]int32
  16436 	var _ /* dist_accum at bp+32 */ [4]int32
  16437 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, alpha, displaced, k, map1, max_a, mb, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1
  16438 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  16439 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16440 	} else {
  16441 		v1 = int32(NUM_MB_SEGMENTS)
  16442 	}
  16443 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  16444 	// explicit check is needed to avoid spurious warning about 'n + 1' exceeding
  16445 	// array bounds of 'centers' with some compilers (noticed with gcc-4.9).
  16446 	nb = v1
  16447 	weighted_average = 0
  16448 	min_a = 0
  16449 	max_a = int32(MAX_ALPHA)
  16450 	// bracket the input
  16451 	n = 0
  16452 	for {
  16453 		if !(n <= int32(MAX_ALPHA) && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16454 			break
  16455 		}
  16456 		goto _2
  16457 	_2:
  16458 		;
  16459 		n = n + 1
  16460 	}
  16461 	min_a = n
  16462 	n = int32(MAX_ALPHA)
  16463 	for {
  16464 		if !(n > min_a && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16465 			break
  16466 		}
  16467 		goto _3
  16468 	_3:
  16469 		;
  16470 		n = n - 1
  16471 	}
  16472 	max_a = n
  16473 	range_a = max_a - min_a
  16474 	// Spread initial centers evenly
  16475 	k = 0
  16476 	n = libc.Int32FromInt32(1)
  16477 	for {
  16478 		if !(k < nb) {
  16479 			break
  16480 		}
  16481 		(**(**[4]int32)(__ccgo_up(bp)))[k] = min_a + n*range_a/(int32(2)*nb)
  16482 		goto _4
  16483 	_4:
  16484 		;
  16485 		k = k + 1
  16486 		n = n + int32(2)
  16487 	}
  16488 	k = 0
  16489 	for {
  16490 		if !(k < int32(MAX_ITERS_K_MEANS)) {
  16491 			break
  16492 		}
  16493 		// Reset stats
  16494 		n = 0
  16495 		for {
  16496 			if !(n < nb) {
  16497 				break
  16498 			}
  16499 			(**(**[4]int32)(__ccgo_up(bp + 16)))[n] = 0
  16500 			(**(**[4]int32)(__ccgo_up(bp + 32)))[n] = 0
  16501 			goto _6
  16502 		_6:
  16503 			;
  16504 			n = n + 1
  16505 		}
  16506 		// Assign nearest center for each 'a'
  16507 		n = 0 // track the nearest center for current 'a'
  16508 		a = min_a
  16509 		for {
  16510 			if !(a <= max_a) {
  16511 				break
  16512 			}
  16513 			if **(**int32)(__ccgo_up(alphas + uintptr(a)*4)) != 0 {
  16514 				for n+int32(1) < nb && libc.Xabs(tls, a-(**(**[4]int32)(__ccgo_up(bp)))[n+int32(1)]) < libc.Xabs(tls, a-(**(**[4]int32)(__ccgo_up(bp)))[n]) {
  16515 					n = n + 1
  16516 				}
  16517 				map1[a] = n
  16518 				// accumulate contribution into best centroid
  16519 				**(**int32)(__ccgo_up(bp + 32 + uintptr(n)*4)) += a * **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16520 				**(**int32)(__ccgo_up(bp + 16 + uintptr(n)*4)) += **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16521 			}
  16522 			goto _7
  16523 		_7:
  16524 			;
  16525 			a = a + 1
  16526 		}
  16527 		// All point are classified. Move the centroids to the
  16528 		// center of their respective cloud.
  16529 		displaced = 0
  16530 		weighted_average = 0
  16531 		total_weight = 0
  16532 		n = 0
  16533 		for {
  16534 			if !(n < nb) {
  16535 				break
  16536 			}
  16537 			if (**(**[4]int32)(__ccgo_up(bp + 16)))[n] != 0 {
  16538 				new_center = ((**(**[4]int32)(__ccgo_up(bp + 32)))[n] + (**(**[4]int32)(__ccgo_up(bp + 16)))[n]/int32(2)) / (**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16539 				displaced = displaced + libc.Xabs(tls, (**(**[4]int32)(__ccgo_up(bp)))[n]-new_center)
  16540 				(**(**[4]int32)(__ccgo_up(bp)))[n] = new_center
  16541 				weighted_average = weighted_average + new_center*(**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16542 				total_weight = total_weight + (**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16543 			}
  16544 			goto _8
  16545 		_8:
  16546 			;
  16547 			n = n + 1
  16548 		}
  16549 		weighted_average = (weighted_average + total_weight/int32(2)) / total_weight
  16550 		if displaced < int32(5) {
  16551 			break
  16552 		} // no need to keep on looping...
  16553 		goto _5
  16554 	_5:
  16555 		;
  16556 		k = k + 1
  16557 	}
  16558 	// Map each original value to the closest centroid
  16559 	n = 0
  16560 	for {
  16561 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  16562 			break
  16563 		}
  16564 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  16565 		alpha = libc.Int32FromUint8((*VP8MBInfo)(unsafe.Pointer(mb)).Falpha)
  16566 		libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(map1[alpha]), 5, 0x60)
  16567 		(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = libc.Uint8FromInt32((**(**[4]int32)(__ccgo_up(bp)))[map1[alpha]]) // for the record.
  16568 		goto _9
  16569 	_9:
  16570 		;
  16571 		n = n + 1
  16572 	}
  16573 	if nb > int32(1) {
  16574 		smooth = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpreprocessing & libc.Int32FromInt32(1)
  16575 		if smooth != 0 {
  16576 			SmoothSegmentMap(tls, enc)
  16577 		}
  16578 	}
  16579 	SetSegmentAlphas(tls, enc, bp, weighted_average) // pick some alphas.
  16580 }
  16581 
  16582 //------------------------------------------------------------------------------
  16583 // Macroblock analysis: collect histogram for each mode, deduce the maximal
  16584 // susceptibility and set best modes for this macroblock.
  16585 // Segment assignment is done later.
  16586 
  16587 // Number of modes to inspect for 'alpha' evaluation. We don't need to test all
  16588 // the possible modes during the analysis phase: we risk falling into a local
  16589 // optimum, or be subject to boundary effect
  16590 
  16591 func MBAnalyzeBestIntra16Mode(tls *libc.TLS, it uintptr) (r int32) {
  16592 	bp := tls.Alloc(16)
  16593 	defer tls.Free(16)
  16594 	var alpha, best_alpha, best_mode, max_mode, mode int32
  16595 	var _ /* histo at bp+0 */ VP8Histogram
  16596 	_, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode
  16597 	max_mode = int32(MAX_INTRA16_MODE)
  16598 	best_alpha = -int32(1)
  16599 	best_mode = 0
  16600 	VP8MakeLuma16Preds(tls, it)
  16601 	mode = 0
  16602 	for {
  16603 		if !(mode < max_mode) {
  16604 			break
  16605 		}
  16606 		InitHistogram(tls, bp)
  16607 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8CollectHistogram})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p+uintptr(VP8I16ModeOffsets[mode]), 0, int32(16), bp)
  16608 		alpha = GetAlpha(tls, bp)
  16609 		if alpha > best_alpha {
  16610 			best_alpha = alpha
  16611 			best_mode = mode
  16612 		}
  16613 		goto _1
  16614 	_1:
  16615 		;
  16616 		mode = mode + 1
  16617 	}
  16618 	VP8SetIntra16Mode(tls, it, best_mode)
  16619 	return best_alpha
  16620 }
  16621 
  16622 func FastMBAnalyze(tls *libc.TLS, it uintptr) (r int32) {
  16623 	bp := tls.Alloc(80)
  16624 	defer tls.Free(80)
  16625 	var k, q int32
  16626 	var kThreshold, m, m2 uint32_t
  16627 	var _ /* dc at bp+0 */ [16]uint32_t
  16628 	var _ /* modes at bp+64 */ [16]uint8_t
  16629 	_, _, _, _, _ = k, kThreshold, m, m2, q
  16630 	// Empirical cut-off value, should be around 16 (~=block size). We use the
  16631 	// [8-17] range and favor intra4 at high quality, intra16 for low quality.
  16632 	q = int32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fconfig)).Fquality)
  16633 	kThreshold = libc.Uint32FromInt32(int32(8) + (libc.Int32FromInt32(17)-libc.Int32FromInt32(8))*q/int32(100))
  16634 	k = 0
  16635 	for {
  16636 		if !(k < int32(16)) {
  16637 			break
  16638 		}
  16639 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8Mean16x4})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in+uintptr(libc.Int32FromInt32(Y_OFF_ENC))+uintptr(k*int32(BPS)), bp+uintptr(k)*4)
  16640 		goto _1
  16641 	_1:
  16642 		;
  16643 		k = k + int32(4)
  16644 	}
  16645 	m = uint32(0)
  16646 	m2 = uint32(0)
  16647 	k = libc.Int32FromInt32(0)
  16648 	for {
  16649 		if !(k < int32(16)) {
  16650 			break
  16651 		}
  16652 		m = m + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16653 		m2 = m2 + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]*(**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16654 		goto _2
  16655 	_2:
  16656 		;
  16657 		k = k + 1
  16658 	}
  16659 	if kThreshold*m2 < m*m {
  16660 		VP8SetIntra16Mode(tls, it, 0) // DC16
  16661 	} else {
  16662 		**(**[16]uint8_t)(__ccgo_up(bp + 64)) = [16]uint8_t{} // DC4
  16663 		VP8SetIntra4Mode(tls, it, bp+64)
  16664 	}
  16665 	return 0
  16666 }
  16667 
  16668 func MBAnalyzeBestUVMode(tls *libc.TLS, it uintptr) (r int32) {
  16669 	bp := tls.Alloc(16)
  16670 	defer tls.Free(16)
  16671 	var alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha int32
  16672 	var _ /* histo at bp+0 */ VP8Histogram
  16673 	_, _, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha
  16674 	best_alpha = -int32(1)
  16675 	smallest_alpha = 0
  16676 	best_mode = 0
  16677 	max_mode = int32(MAX_UV_MODE)
  16678 	VP8MakeChroma8Preds(tls, it)
  16679 	mode = 0
  16680 	for {
  16681 		if !(mode < max_mode) {
  16682 			break
  16683 		}
  16684 		InitHistogram(tls, bp)
  16685 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8CollectHistogram})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in+uintptr(libc.Int32FromInt32(U_OFF_ENC)), (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p+uintptr(VP8UVModeOffsets[mode]), int32(16), libc.Int32FromInt32(16)+libc.Int32FromInt32(4)+libc.Int32FromInt32(4), bp)
  16686 		alpha = GetAlpha(tls, bp)
  16687 		if alpha > best_alpha {
  16688 			best_alpha = alpha
  16689 		}
  16690 		// The best prediction mode tends to be the one with the smallest alpha.
  16691 		if mode == 0 || alpha < smallest_alpha {
  16692 			smallest_alpha = alpha
  16693 			best_mode = mode
  16694 		}
  16695 		goto _1
  16696 	_1:
  16697 		;
  16698 		mode = mode + 1
  16699 	}
  16700 	VP8SetIntraUVMode(tls, it, best_mode)
  16701 	return best_alpha
  16702 }
  16703 
  16704 func MBAnalyze(tls *libc.TLS, it uintptr, alphas uintptr, alpha uintptr, uv_alpha uintptr) {
  16705 	var best_alpha, best_uv_alpha int32
  16706 	var enc uintptr
  16707 	_, _, _ = best_alpha, best_uv_alpha, enc
  16708 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  16709 	VP8SetIntra16Mode(tls, it, 0) // default: Intra16, DC_PRED
  16710 	VP8SetSkip(tls, it, 0)        // not skipped
  16711 	VP8SetSegment(tls, it, 0)     // default segment, spec-wise.
  16712 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod <= int32(1) {
  16713 		best_alpha = FastMBAnalyze(tls, it)
  16714 	} else {
  16715 		best_alpha = MBAnalyzeBestIntra16Mode(tls, it)
  16716 	}
  16717 	best_uv_alpha = MBAnalyzeBestUVMode(tls, it)
  16718 	// Final susceptibility mix
  16719 	best_alpha = (int32(3)*best_alpha + best_uv_alpha + int32(2)) >> int32(2)
  16720 	best_alpha = FinalAlphaValue(tls, best_alpha)
  16721 	**(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) = **(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) + 1
  16722 	(*VP8MBInfo)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb)).Falpha = libc.Uint8FromInt32(best_alpha) // for later remapping.
  16723 	// Accumulate for later complexity analysis.
  16724 	**(**int32)(__ccgo_up(alpha)) += best_alpha // mixed susceptibility (not just luma)
  16725 	**(**int32)(__ccgo_up(uv_alpha)) += best_uv_alpha
  16726 }
  16727 
  16728 func DefaultMBInfo(tls *libc.TLS, mb uintptr) {
  16729 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(1), 0, 0x3) // I16x16
  16730 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 2, 0xc)
  16731 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 4, 0x10) // not skipped
  16732 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 5, 0x60) // default segment
  16733 	(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = uint8(0)
  16734 }
  16735 
  16736 //------------------------------------------------------------------------------
  16737 // Main analysis loop:
  16738 // Collect all susceptibilities for each macroblock and record their
  16739 // distribution in alphas[]. Segments is assigned a-posteriori, based on
  16740 // this histogram.
  16741 // We also pick an intra16 prediction mode, which shouldn't be considered
  16742 // final except for fast-encode settings. We can also pick some intra4 modes
  16743 // and decide intra4/intra16, but that's usually almost always a bad choice at
  16744 // this stage.
  16745 
  16746 func ResetAllMBInfo(tls *libc.TLS, enc uintptr) {
  16747 	var n int32
  16748 	_ = n
  16749 	n = 0
  16750 	for {
  16751 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  16752 			break
  16753 		}
  16754 		DefaultMBInfo(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4)
  16755 		goto _1
  16756 	_1:
  16757 		;
  16758 		n = n + 1
  16759 	}
  16760 	// Default susceptibilities.
  16761 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Falpha = 0
  16762 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fbeta = 0
  16763 	// Note: we can't compute this 'alpha' / 'uv_alpha' -> set to default value.
  16764 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = 0
  16765 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = 0
  16766 	WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  16767 }
  16768 
  16769 // C documentation
  16770 //
  16771 //	// struct used to collect job result
  16772 type SegmentJob = struct {
  16773 	Fworker         WebPWorker
  16774 	Falphas         [256]int32
  16775 	Falpha          int32
  16776 	Fuv_alpha       int32
  16777 	Fit             VP8EncIterator
  16778 	Fdelta_progress int32
  16779 }
  16780 
  16781 // C documentation
  16782 //
  16783 //	// main work call
  16784 func DoSegmentsJob(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
  16785 	bp := tls.Alloc(64)
  16786 	defer tls.Free(64)
  16787 	var it, job, scratch uintptr
  16788 	var ok int32
  16789 	var _ /* tmp at bp+0 */ [63]uint8_t
  16790 	_, _, _, _ = it, job, ok, scratch
  16791 	job = arg1
  16792 	it = arg2
  16793 	ok = int32(1)
  16794 	if !(VP8IteratorIsDone(tls, it) != 0) {
  16795 		scratch = uintptr((uintptr_t(bp) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  16796 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, it) != 0 {
  16797 			// Let's pretend we have perfect lossless reconstruction.
  16798 			VP8IteratorImport(tls, it, scratch)
  16799 			MBAnalyze(tls, it, job+48, job+1072, job+1076)
  16800 			ok = VP8IteratorProgress(tls, it, (*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress)
  16801 		}
  16802 	}
  16803 	return ok
  16804 }
  16805 
  16806 // C documentation
  16807 //
  16808 //	// initialize the job struct with some tasks to perform
  16809 func InitSegmentJob(tls *libc.TLS, enc uintptr, job uintptr, start_row int32, end_row int32) {
  16810 	var v1 int32
  16811 	_ = v1
  16812 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, job)
  16813 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata1 = job
  16814 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata2 = job + 1080
  16815 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fhook = __ccgo_fp(DoSegmentsJob)
  16816 	VP8IteratorInit(tls, enc, job+1080)
  16817 	VP8IteratorSetRow(tls, job+1080, start_row)
  16818 	VP8IteratorSetCountDown(tls, job+1080, (end_row-start_row)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  16819 	libc.Xmemset(tls, job+48, 0, uint64(1024))
  16820 	(*SegmentJob)(unsafe.Pointer(job)).Falpha = 0
  16821 	(*SegmentJob)(unsafe.Pointer(job)).Fuv_alpha = 0
  16822 	// only one of both jobs can record the progress, since we don't
  16823 	// expect the user's hook to be multi-thread safe
  16824 	if start_row == 0 {
  16825 		v1 = int32(20)
  16826 	} else {
  16827 		v1 = 0
  16828 	}
  16829 	(*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress = v1
  16830 }
  16831 
  16832 // C documentation
  16833 //
  16834 //	// main entry point
  16835 func VP8EncAnalyze(tls *libc.TLS, enc uintptr) (r int32) {
  16836 	bp := tls.Alloc(4944)
  16837 	defer tls.Free(4944)
  16838 	var do_mt, do_segments, last_row, ok, total_mb int32
  16839 	var worker_interface uintptr
  16840 	var _ /* main_job at bp+0 */ SegmentJob
  16841 	_, _, _, _, _, _ = do_mt, do_segments, last_row, ok, total_mb, worker_interface
  16842 	ok = int32(1)
  16843 	do_segments = libc.BoolInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Femulate_jpeg_size != 0 || (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments > int32(1) || (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod <= int32(1)) // for method 0 - 1, we need preds[] to be filled.
  16844 	if do_segments != 0 {
  16845 		last_row = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  16846 		total_mb = last_row * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  16847 		do_mt = 0
  16848 		worker_interface = WebPGetWorkerInterface(tls)
  16849 		if do_mt != 0 {
  16850 		} else {
  16851 			// Even for single-thread case, we use the generic Worker tools.
  16852 			InitSegmentJob(tls, enc, bp, 0, last_row)
  16853 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp)
  16854 			ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp)
  16855 		}
  16856 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp)
  16857 		if ok != 0 {
  16858 			(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = (**(**SegmentJob)(__ccgo_up(bp))).Falpha / total_mb
  16859 			(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = (**(**SegmentJob)(__ccgo_up(bp))).Fuv_alpha / total_mb
  16860 			AssignSegments(tls, enc, bp+48)
  16861 		}
  16862 	} else { // Use only one default segment.
  16863 		ResetAllMBInfo(tls, enc)
  16864 	}
  16865 	if !(ok != 0) {
  16866 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  16867 	}
  16868 	return ok
  16869 }
  16870 
  16871 const COST_CACHE_INTERVAL_SIZE_MAX = 500
  16872 const COST_MANAGER_MAX_FREE_LIST = 10
  16873 const VALUES_IN_BYTE = 256
  16874 
  16875 var kHashMul10 = uint32(0x1e35a7bd)
  16876 
  16877 type CostModel = struct {
  16878 	Falpha    [256]uint32_t
  16879 	Fred      [256]uint32_t
  16880 	Fblue     [256]uint32_t
  16881 	Fdistance [40]uint32_t
  16882 	Fliteral  uintptr
  16883 }
  16884 
  16885 func ConvertPopulationCountTableToBitEstimates(tls *libc.TLS, num_symbols int32, population_counts uintptr, output uintptr) {
  16886 	var i, nonzeros int32
  16887 	var logsum, sum, v2, v3, v7, v8 uint32_t
  16888 	var v10, v5 uint32
  16889 	_, _, _, _, _, _, _, _, _, _ = i, logsum, nonzeros, sum, v10, v2, v3, v5, v7, v8
  16890 	sum = uint32(0)
  16891 	nonzeros = 0
  16892 	i = 0
  16893 	for {
  16894 		if !(i < num_symbols) {
  16895 			break
  16896 		}
  16897 		sum = sum + **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  16898 		if **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4)) > uint32(0) {
  16899 			nonzeros = nonzeros + 1
  16900 		}
  16901 		goto _1
  16902 	_1:
  16903 		;
  16904 		i = i + 1
  16905 	}
  16906 	if nonzeros <= int32(1) {
  16907 		libc.Xmemset(tls, output, 0, libc.Uint64FromInt32(num_symbols)*uint64(4))
  16908 	} else {
  16909 		v2 = sum
  16910 		if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  16911 			v5 = kLog2Table[v2]
  16912 		} else {
  16913 			v5 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v2)
  16914 		}
  16915 		v3 = v5
  16916 		goto _4
  16917 	_4:
  16918 		logsum = v3
  16919 		i = 0
  16920 		for {
  16921 			if !(i < num_symbols) {
  16922 				break
  16923 			}
  16924 			v7 = **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  16925 			if v7 < uint32(LOG_LOOKUP_IDX_MAX) {
  16926 				v10 = kLog2Table[v7]
  16927 			} else {
  16928 				v10 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v7)
  16929 			}
  16930 			v8 = v10
  16931 			goto _9
  16932 		_9:
  16933 			**(**uint32_t)(__ccgo_up(output + uintptr(i)*4)) = logsum - v8
  16934 			goto _6
  16935 		_6:
  16936 			;
  16937 			i = i + 1
  16938 		}
  16939 	}
  16940 }
  16941 
  16942 func CostModelBuild(tls *libc.TLS, m uintptr, xsize int32, cache_bits int32, refs uintptr) (r int32) {
  16943 	var histo uintptr
  16944 	var ok, v1, v2, v4 int32
  16945 	_, _, _, _, _ = histo, ok, v1, v2, v4
  16946 	ok = 0
  16947 	histo = VP8LAllocateHistogram(tls, cache_bits)
  16948 	if histo == libc.UintptrFromInt32(0) {
  16949 		goto Error
  16950 	}
  16951 	// The following code is similar to VP8LHistogramCreate but converts the
  16952 	// distance to plane code.
  16953 	VP8LHistogramInit(tls, histo, cache_bits, int32(1))
  16954 	VP8LHistogramStoreRefs(tls, refs, __ccgo_fp(VP8LDistanceToPlaneCode), xsize, histo)
  16955 	v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  16956 	if v1 > 0 {
  16957 		v4 = int32(1) << v1
  16958 	} else {
  16959 		v4 = 0
  16960 	}
  16961 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  16962 	goto _3
  16963 _3:
  16964 	ConvertPopulationCountTableToBitEstimates(tls, v2, (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral, (*CostModel)(unsafe.Pointer(m)).Fliteral)
  16965 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+8, m+1024)
  16966 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+1032, m+2048)
  16967 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+2056, m)
  16968 	ConvertPopulationCountTableToBitEstimates(tls, int32(NUM_DISTANCE_CODES), histo+3080, m+3072)
  16969 	ok = int32(1)
  16970 	goto Error
  16971 Error:
  16972 	;
  16973 	VP8LFreeHistogram(tls, histo)
  16974 	return ok
  16975 }
  16976 
  16977 func GetLiteralCost(tls *libc.TLS, m uintptr, v uint32_t) (r int64_t) {
  16978 	return libc.Int64FromUint32(**(**uint32_t)(__ccgo_up(m + uintptr(v>>int32(24))*4))) + libc.Int64FromUint32(**(**uint32_t)(__ccgo_up(m + 1024 + uintptr(v>>libc.Int32FromInt32(16)&uint32(0xff))*4))) + libc.Int64FromUint32(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(v>>libc.Int32FromInt32(8)&uint32(0xff))*4))) + libc.Int64FromUint32(**(**uint32_t)(__ccgo_up(m + 2048 + uintptr(v&uint32(0xff))*4)))
  16979 }
  16980 
  16981 func GetCacheCost(tls *libc.TLS, m uintptr, idx uint32_t) (r int64_t) {
  16982 	var literal_idx int32
  16983 	_ = literal_idx
  16984 	literal_idx = libc.Int32FromUint32(libc.Uint32FromInt32(libc.Int32FromInt32(VALUES_IN_BYTE)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + idx)
  16985 	return libc.Int64FromUint32(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(literal_idx)*4)))
  16986 }
  16987 
  16988 func GetLengthCost(tls *libc.TLS, m uintptr, length uint32_t) (r int64_t) {
  16989 	bp := tls.Alloc(16)
  16990 	defer tls.Free(16)
  16991 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  16992 	var prefix_code VP8LPrefixCode
  16993 	var v2, v3 uintptr
  16994 	var _ /* code at bp+0 */ int32
  16995 	var _ /* extra_bits at bp+4 */ int32
  16996 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  16997 	v1 = libc.Int32FromUint32(length)
  16998 	v2 = bp
  16999 	v3 = bp + 4
  17000 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17001 		prefix_code = kPrefixEncodeCode[v1]
  17002 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17003 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17004 	} else {
  17005 		v4 = v1
  17006 		v4 = v4 - 1
  17007 		v5 = v4
  17008 		v6 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v5))
  17009 		goto _7
  17010 	_7:
  17011 		highest_bit = v6
  17012 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17013 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17014 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17015 	}
  17016 	return libc.Int64FromUint32(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(int32(VALUES_IN_BYTE)+**(**int32)(__ccgo_up(bp)))*4))) + int64(**(**int32)(__ccgo_up(bp + 4)))<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  17017 }
  17018 
  17019 func GetDistanceCost(tls *libc.TLS, m uintptr, distance2 uint32_t) (r int64_t) {
  17020 	bp := tls.Alloc(16)
  17021 	defer tls.Free(16)
  17022 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17023 	var prefix_code VP8LPrefixCode
  17024 	var v2, v3 uintptr
  17025 	var _ /* code at bp+0 */ int32
  17026 	var _ /* extra_bits at bp+4 */ int32
  17027 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17028 	v1 = libc.Int32FromUint32(distance2)
  17029 	v2 = bp
  17030 	v3 = bp + 4
  17031 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17032 		prefix_code = kPrefixEncodeCode[v1]
  17033 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17034 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17035 	} else {
  17036 		v4 = v1
  17037 		v4 = v4 - 1
  17038 		v5 = v4
  17039 		v6 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v5))
  17040 		goto _7
  17041 	_7:
  17042 		highest_bit = v6
  17043 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17044 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17045 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17046 	}
  17047 	return libc.Int64FromUint32(**(**uint32_t)(__ccgo_up(m + 3072 + uintptr(**(**int32)(__ccgo_up(bp)))*4))) + int64(**(**int32)(__ccgo_up(bp + 4)))<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  17048 }
  17049 
  17050 func AddSingleLiteralWithCostModel(tls *libc.TLS, argb3 uintptr, hashers uintptr, cost_model uintptr, idx int32, use_color_cache int32, prev_cost int64_t, cost uintptr, dist_array uintptr) {
  17051 	var color, v3 uint32_t
  17052 	var cost_val, v10, v11, v9 int64_t
  17053 	var ix, key, key1, v1, v4, v6, v8 int32
  17054 	var v13 int64
  17055 	var v2 uintptr
  17056 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = color, cost_val, ix, key, key1, v1, v10, v11, v13, v2, v3, v4, v6, v8, v9
  17057 	cost_val = prev_cost
  17058 	color = **(**uint32_t)(__ccgo_up(argb3 + uintptr(idx)*4))
  17059 	if use_color_cache != 0 {
  17060 		v2 = hashers
  17061 		v3 = color
  17062 		v4 = libc.Int32FromUint32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17063 		goto _5
  17064 	_5:
  17065 		key1 = v4
  17066 		if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key1)*4)) == v3 {
  17067 			v8 = key1
  17068 		} else {
  17069 			v8 = -int32(1)
  17070 		}
  17071 		v6 = v8
  17072 		goto _7
  17073 	_7:
  17074 		v1 = v6
  17075 	} else {
  17076 		v1 = -int32(1)
  17077 	}
  17078 	ix = v1
  17079 	if ix >= 0 {
  17080 		// use_color_cache is true and hashers contains color
  17081 		v9 = GetCacheCost(tls, cost_model, libc.Uint32FromInt32(ix)) * int64(68)
  17082 		v10 = int64(100)
  17083 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17084 			v13 = (v9 + v10/int64(2)) / v10
  17085 		} else {
  17086 			v13 = (v9 - v10/int64(2)) / v10
  17087 		}
  17088 		v11 = v13
  17089 		goto _12
  17090 	_12:
  17091 		cost_val = cost_val + v11
  17092 	} else {
  17093 		if use_color_cache != 0 {
  17094 			v2 = hashers
  17095 			v3 = color
  17096 			v1 = libc.Int32FromUint32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17097 			goto _17
  17098 		_17:
  17099 			key = v1
  17100 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v3
  17101 		}
  17102 		v9 = GetLiteralCost(tls, cost_model, color) * int64(82)
  17103 		v10 = int64(100)
  17104 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17105 			v13 = (v9 + v10/int64(2)) / v10
  17106 		} else {
  17107 			v13 = (v9 - v10/int64(2)) / v10
  17108 		}
  17109 		v11 = v13
  17110 		goto _21
  17111 	_21:
  17112 		cost_val = cost_val + v11
  17113 	}
  17114 	if **(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) > cost_val {
  17115 		**(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) = cost_val
  17116 		**(**uint16_t)(__ccgo_up(dist_array + uintptr(idx)*2)) = uint16(1) // only one is inserted.
  17117 	}
  17118 }
  17119 
  17120 // -----------------------------------------------------------------------------
  17121 // CostManager and interval handling
  17122 
  17123 // Empirical value to avoid high memory consumption but good for performance.
  17124 
  17125 // C documentation
  17126 //
  17127 //	// To perform backward reference every pixel at index 'index' is considered and
  17128 //	// the cost for the MAX_LENGTH following pixels computed. Those following pixels
  17129 //	// at index 'index' + k (k from 0 to MAX_LENGTH) have a cost of:
  17130 //	//     cost = distance cost at index + GetLengthCost(cost_model, k)
  17131 //	// and the minimum value is kept. GetLengthCost(cost_model, k) is cached in an
  17132 //	// array of size MAX_LENGTH.
  17133 //	// Instead of performing MAX_LENGTH comparisons per pixel, we keep track of the
  17134 //	// minimal values using intervals of constant cost.
  17135 //	// An interval is defined by the 'index' of the pixel that generated it and
  17136 //	// is only useful in a range of indices from 'start' to 'end' (exclusive), i.e.
  17137 //	// it contains the minimum value for pixels between start and end.
  17138 //	// Intervals are stored in a linked list and ordered by 'start'. When a new
  17139 //	// interval has a better value, old intervals are split or removed. There are
  17140 //	// therefore no overlapping intervals.
  17141 type CostInterval = struct {
  17142 	Fcost     int64_t
  17143 	Fstart    int32
  17144 	Fend      int32
  17145 	Findex    int32
  17146 	Fprevious uintptr
  17147 	Fnext     uintptr
  17148 }
  17149 
  17150 // C documentation
  17151 //
  17152 //	// The GetLengthCost(cost_model, k) are cached in a CostCacheInterval.
  17153 type CostCacheInterval = struct {
  17154 	Fcost  int64_t
  17155 	Fstart int32
  17156 	Fend   int32
  17157 }
  17158 
  17159 // C documentation
  17160 //
  17161 //	// This structure is in charge of managing intervals and costs.
  17162 //	// It caches the different CostCacheInterval, caches the different
  17163 //	// GetLengthCost(cost_model, k) in cost_cache and the CostInterval's (whose
  17164 //	// 'count' is limited by COST_CACHE_INTERVAL_SIZE_MAX).
  17165 type CostManager = struct {
  17166 	Fhead                 uintptr
  17167 	Fcount                int32
  17168 	Fcache_intervals      uintptr
  17169 	Fcache_intervals_size size_t
  17170 	Fcost_cache           [4095]int64_t
  17171 	Fcosts                uintptr
  17172 	Fdist_array           uintptr
  17173 	Fintervals            [10]CostInterval
  17174 	Ffree_intervals       uintptr
  17175 	Frecycled_intervals   uintptr
  17176 }
  17177 
  17178 func CostIntervalAddToFreeList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17179 	(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17180 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = interval
  17181 }
  17182 
  17183 func CostIntervalIsInFreeList(tls *libc.TLS, manager uintptr, interval uintptr) (r int32) {
  17184 	return libc.BoolInt32(interval >= manager+32808 && interval <= manager+32808+uintptr(libc.Int32FromInt32(COST_MANAGER_MAX_FREE_LIST)-libc.Int32FromInt32(1))*40)
  17185 }
  17186 
  17187 func CostManagerInitFreeList(tls *libc.TLS, manager uintptr) {
  17188 	var i int32
  17189 	_ = i
  17190 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = libc.UintptrFromInt32(0)
  17191 	i = 0
  17192 	for {
  17193 		if !(i < int32(COST_MANAGER_MAX_FREE_LIST)) {
  17194 			break
  17195 		}
  17196 		CostIntervalAddToFreeList(tls, manager, manager+32808+uintptr(i)*40)
  17197 		goto _1
  17198 	_1:
  17199 		;
  17200 		i = i + 1
  17201 	}
  17202 }
  17203 
  17204 func DeleteIntervalList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17205 	var next uintptr
  17206 	_ = next
  17207 	for interval != libc.UintptrFromInt32(0) {
  17208 		next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17209 		if !(CostIntervalIsInFreeList(tls, manager, interval) != 0) {
  17210 			WebPSafeFree(tls, interval)
  17211 		} // else: do nothing
  17212 		interval = next
  17213 	}
  17214 }
  17215 
  17216 func CostManagerClear(tls *libc.TLS, manager uintptr) {
  17217 	if manager == libc.UintptrFromInt32(0) {
  17218 		return
  17219 	}
  17220 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcosts)
  17221 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals)
  17222 	// Clear the interval lists.
  17223 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17224 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17225 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals)
  17226 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17227 	// Reset pointers, 'count' and 'cache_intervals_size'.
  17228 	libc.Xmemset(tls, manager, 0, uint64(33224))
  17229 	CostManagerInitFreeList(tls, manager)
  17230 }
  17231 
  17232 func CostManagerInit(tls *libc.TLS, manager uintptr, dist_array uintptr, pix_count int32, cost_model uintptr) (r int32) {
  17233 	var cost_cache_size, i, v1 int32
  17234 	var cost_val int64_t
  17235 	var cur uintptr
  17236 	_, _, _, _, _ = cost_cache_size, cost_val, cur, i, v1
  17237 	if pix_count > libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  17238 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  17239 	} else {
  17240 		v1 = pix_count
  17241 	}
  17242 	cost_cache_size = v1
  17243 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = libc.UintptrFromInt32(0)
  17244 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = libc.UintptrFromInt32(0)
  17245 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17246 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17247 	(*CostManager)(unsafe.Pointer(manager)).Fcount = 0
  17248 	(*CostManager)(unsafe.Pointer(manager)).Fdist_array = dist_array
  17249 	CostManagerInitFreeList(tls, manager)
  17250 	// Fill in the 'cost_cache'.
  17251 	// Has to be done in two passes due to a GCC bug on i686
  17252 	// related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
  17253 	i = 0
  17254 	for {
  17255 		if !(i < cost_cache_size) {
  17256 			break
  17257 		}
  17258 		**(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) = GetLengthCost(tls, cost_model, libc.Uint32FromInt32(i))
  17259 		goto _2
  17260 	_2:
  17261 		;
  17262 		i = i + 1
  17263 	}
  17264 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = uint64(1)
  17265 	i = int32(1)
  17266 	for {
  17267 		if !(i < cost_cache_size) {
  17268 			break
  17269 		}
  17270 		// Get the number of bound intervals.
  17271 		if **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) != **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i-int32(1))*8)) {
  17272 			(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size + 1
  17273 		}
  17274 		goto _3
  17275 	_3:
  17276 		;
  17277 		i = i + 1
  17278 	}
  17279 	// With the current cost model, we usually have below 20 intervals.
  17280 	// The worst case scenario with a cost model would be if every length has a
  17281 	// different cost, hence MAX_LENGTH but that is impossible with the current
  17282 	// implementation that spirals around a pixel.
  17283 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = WebPSafeMalloc(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size, uint64(16))
  17284 	if (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals == libc.UintptrFromInt32(0) {
  17285 		CostManagerClear(tls, manager)
  17286 		return 0
  17287 	}
  17288 	// Fill in the 'cache_intervals'.
  17289 	cur = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17290 	// Consecutive values in 'cost_cache' are compared and if a big enough
  17291 	// difference is found, a new interval is created and bounded.
  17292 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = 0
  17293 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = int32(1)
  17294 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = **(**int64_t)(__ccgo_up(manager + 32))
  17295 	i = int32(1)
  17296 	for {
  17297 		if !(i < cost_cache_size) {
  17298 			break
  17299 		}
  17300 		cost_val = **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8))
  17301 		if cost_val != (*CostCacheInterval)(unsafe.Pointer(cur)).Fcost {
  17302 			cur += 16
  17303 			// Initialize an interval.
  17304 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = i
  17305 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = cost_val
  17306 		}
  17307 		(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = i + int32(1)
  17308 		goto _4
  17309 	_4:
  17310 		;
  17311 		i = i + 1
  17312 	}
  17313 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = WebPSafeMalloc(tls, libc.Uint64FromInt32(pix_count), uint64(8))
  17314 	if (*CostManager)(unsafe.Pointer(manager)).Fcosts == libc.UintptrFromInt32(0) {
  17315 		CostManagerClear(tls, manager)
  17316 		return 0
  17317 	}
  17318 	// Set the initial 'costs' to INT64_MAX for every pixel as we will keep the
  17319 	// minimum.
  17320 	i = 0
  17321 	for {
  17322 		if !(i < pix_count) {
  17323 			break
  17324 		}
  17325 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  17326 		goto _5
  17327 	_5:
  17328 		;
  17329 		i = i + 1
  17330 	}
  17331 	return int32(1)
  17332 }
  17333 
  17334 // C documentation
  17335 //
  17336 //	// Given the cost and the position that define an interval, update the cost at
  17337 //	// pixel 'i' if it is smaller than the previously computed value.
  17338 func UpdateCost(tls *libc.TLS, manager uintptr, i int32, position int32, cost int64_t) {
  17339 	var k int32
  17340 	_ = k
  17341 	k = i - position
  17342 	if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) > cost {
  17343 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = cost
  17344 		**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(i)*2)) = libc.Uint16FromInt32(k + int32(1))
  17345 	}
  17346 }
  17347 
  17348 // C documentation
  17349 //
  17350 //	// Given the cost and the position that define an interval, update the cost for
  17351 //	// all the pixels between 'start' and 'end' excluded.
  17352 func UpdateCostPerInterval(tls *libc.TLS, manager uintptr, start int32, end int32, position int32, cost int64_t) {
  17353 	var i int32
  17354 	_ = i
  17355 	i = start
  17356 	for {
  17357 		if !(i < end) {
  17358 			break
  17359 		}
  17360 		UpdateCost(tls, manager, i, position, cost)
  17361 		goto _1
  17362 	_1:
  17363 		;
  17364 		i = i + 1
  17365 	}
  17366 }
  17367 
  17368 // C documentation
  17369 //
  17370 //	// Given two intervals, make 'prev' be the previous one of 'next' in 'manager'.
  17371 func ConnectIntervals(tls *libc.TLS, manager uintptr, prev uintptr, next uintptr) {
  17372 	if prev != libc.UintptrFromInt32(0) {
  17373 		(*CostInterval)(unsafe.Pointer(prev)).Fnext = next
  17374 	} else {
  17375 		(*CostManager)(unsafe.Pointer(manager)).Fhead = next
  17376 	}
  17377 	if next != libc.UintptrFromInt32(0) {
  17378 		(*CostInterval)(unsafe.Pointer(next)).Fprevious = prev
  17379 	}
  17380 }
  17381 
  17382 // C documentation
  17383 //
  17384 //	// Pop an interval in the manager.
  17385 func PopInterval(tls *libc.TLS, manager uintptr, interval uintptr) {
  17386 	if interval == libc.UintptrFromInt32(0) {
  17387 		return
  17388 	}
  17389 	ConnectIntervals(tls, manager, (*CostInterval)(unsafe.Pointer(interval)).Fprevious, (*CostInterval)(unsafe.Pointer(interval)).Fnext)
  17390 	if CostIntervalIsInFreeList(tls, manager, interval) != 0 {
  17391 		CostIntervalAddToFreeList(tls, manager, interval)
  17392 	} else { // recycle regularly malloc'd intervals too
  17393 		(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17394 		(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = interval
  17395 	}
  17396 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount - 1
  17397 }
  17398 
  17399 // C documentation
  17400 //
  17401 //	// Update the cost at index i by going over all the stored intervals that
  17402 //	// overlap with i.
  17403 //	// If 'do_clean_intervals' is set to something different than 0, intervals that
  17404 //	// end before 'i' will be popped.
  17405 func UpdateCostAtIndex(tls *libc.TLS, manager uintptr, i int32, do_clean_intervals int32) {
  17406 	var current, next uintptr
  17407 	_, _ = current, next
  17408 	current = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17409 	for current != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart <= i {
  17410 		next = (*CostInterval)(unsafe.Pointer(current)).Fnext
  17411 		if (*CostInterval)(unsafe.Pointer(current)).Fend <= i {
  17412 			if do_clean_intervals != 0 {
  17413 				// We have an outdated interval, remove it.
  17414 				PopInterval(tls, manager, current)
  17415 			}
  17416 		} else {
  17417 			UpdateCost(tls, manager, i, (*CostInterval)(unsafe.Pointer(current)).Findex, (*CostInterval)(unsafe.Pointer(current)).Fcost)
  17418 		}
  17419 		current = next
  17420 	}
  17421 }
  17422 
  17423 // C documentation
  17424 //
  17425 //	// Given a current orphan interval and its previous interval, before
  17426 //	// it was orphaned (which can be NULL), set it at the right place in the list
  17427 //	// of intervals using the 'start' ordering and the previous interval as a hint.
  17428 func PositionOrphanInterval(tls *libc.TLS, manager uintptr, current uintptr, previous uintptr) {
  17429 	if previous == libc.UintptrFromInt32(0) {
  17430 		previous = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17431 	}
  17432 	for previous != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart < (*CostInterval)(unsafe.Pointer(previous)).Fstart {
  17433 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fprevious
  17434 	}
  17435 	for previous != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(previous)).Fnext != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer((*CostInterval)(unsafe.Pointer(previous)).Fnext)).Fstart < (*CostInterval)(unsafe.Pointer(current)).Fstart {
  17436 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fnext
  17437 	}
  17438 	if previous != libc.UintptrFromInt32(0) {
  17439 		ConnectIntervals(tls, manager, current, (*CostInterval)(unsafe.Pointer(previous)).Fnext)
  17440 	} else {
  17441 		ConnectIntervals(tls, manager, current, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17442 	}
  17443 	ConnectIntervals(tls, manager, previous, current)
  17444 }
  17445 
  17446 // C documentation
  17447 //
  17448 //	// Insert an interval in the list contained in the manager by starting at
  17449 //	// 'interval_in' as a hint. The intervals are sorted by 'start' value.
  17450 func InsertInterval(tls *libc.TLS, manager uintptr, interval_in uintptr, cost int64_t, position int32, start int32, end int32) {
  17451 	var interval_new uintptr
  17452 	_ = interval_new
  17453 	if start >= end {
  17454 		return
  17455 	}
  17456 	if (*CostManager)(unsafe.Pointer(manager)).Fcount >= int32(COST_CACHE_INTERVAL_SIZE_MAX) {
  17457 		// Serialize the interval if we cannot store it.
  17458 		UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17459 		return
  17460 	}
  17461 	if (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals != libc.UintptrFromInt32(0) {
  17462 		interval_new = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17463 		(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17464 	} else {
  17465 		if (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals != libc.UintptrFromInt32(0) {
  17466 			interval_new = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17467 			(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17468 		} else { // malloc for good
  17469 			interval_new = WebPSafeMalloc(tls, uint64(1), uint64(40))
  17470 			if interval_new == libc.UintptrFromInt32(0) {
  17471 				// Write down the interval if we cannot create it.
  17472 				UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17473 				return
  17474 			}
  17475 		}
  17476 	}
  17477 	(*CostInterval)(unsafe.Pointer(interval_new)).Fcost = cost
  17478 	(*CostInterval)(unsafe.Pointer(interval_new)).Findex = position
  17479 	(*CostInterval)(unsafe.Pointer(interval_new)).Fstart = start
  17480 	(*CostInterval)(unsafe.Pointer(interval_new)).Fend = end
  17481 	PositionOrphanInterval(tls, manager, interval_new, interval_in)
  17482 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount + 1
  17483 }
  17484 
  17485 // C documentation
  17486 //
  17487 //	// Given a new cost interval defined by its start at position, its length value
  17488 //	// and distance_cost, add its contributions to the previous intervals and costs.
  17489 //	// If handling the interval or one of its subintervals becomes to heavy, its
  17490 //	// contribution is added to the costs right away.
  17491 func PushInterval(tls *libc.TLS, manager uintptr, distance_cost int64_t, position int32, len1 int32) {
  17492 	var cost, cost_tmp int64_t
  17493 	var cost_cache_intervals, interval, interval_next uintptr
  17494 	var end, end_original, j, k, kSkipDistance, start, start_new, v3 int32
  17495 	var i size_t
  17496 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = cost, cost_cache_intervals, cost_tmp, end, end_original, i, interval, interval_next, j, k, kSkipDistance, start, start_new, v3
  17497 	interval = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17498 	cost_cache_intervals = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17499 	// If the interval is small enough, no need to deal with the heavy
  17500 	// interval logic, just serialize it right away. This constant is empirical.
  17501 	kSkipDistance = int32(10)
  17502 	if len1 < kSkipDistance {
  17503 		j = position
  17504 		for {
  17505 			if !(j < position+len1) {
  17506 				break
  17507 			}
  17508 			k = j - position
  17509 			cost_tmp = distance_cost + **(**int64_t)(__ccgo_up(manager + 32 + uintptr(k)*8))
  17510 			if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) > cost_tmp {
  17511 				**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) = cost_tmp
  17512 				**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(j)*2)) = libc.Uint16FromInt32(k + int32(1))
  17513 			}
  17514 			goto _1
  17515 		_1:
  17516 			;
  17517 			j = j + 1
  17518 		}
  17519 		return
  17520 	}
  17521 	i = uint64(0)
  17522 	for {
  17523 		if !(i < (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size && (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart < len1) {
  17524 			break
  17525 		}
  17526 		// Define the intersection of the ith interval with the new one.
  17527 		start = position + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart
  17528 		if (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend > len1 {
  17529 			v3 = len1
  17530 		} else {
  17531 			v3 = (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend
  17532 		}
  17533 		end = position + v3
  17534 		cost = distance_cost + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fcost
  17535 		for {
  17536 			if !(interval != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(interval)).Fstart < end) {
  17537 				break
  17538 			}
  17539 			interval_next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17540 			// Make sure we have some overlap
  17541 			if start >= (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17542 				goto _4
  17543 			}
  17544 			if cost >= (*CostInterval)(unsafe.Pointer(interval)).Fcost {
  17545 				// When intervals are represented, the lower, the better.
  17546 				// [**********************************************************[
  17547 				// start                                                    end
  17548 				//                   [----------------------------------[
  17549 				//                   interval->start        interval->end
  17550 				// If we are worse than what we already have, add whatever we have so
  17551 				// far up to interval.
  17552 				start_new = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17553 				InsertInterval(tls, manager, interval, cost, position, start, (*CostInterval)(unsafe.Pointer(interval)).Fstart)
  17554 				start = start_new
  17555 				if start >= end {
  17556 					break
  17557 				}
  17558 				goto _4
  17559 			}
  17560 			if start <= (*CostInterval)(unsafe.Pointer(interval)).Fstart {
  17561 				if (*CostInterval)(unsafe.Pointer(interval)).Fend <= end {
  17562 					//                   [----------------------------------[
  17563 					//                   interval->start        interval->end
  17564 					// [**************************************************************[
  17565 					// start                                                        end
  17566 					// We can safely remove the old interval as it is fully included.
  17567 					PopInterval(tls, manager, interval)
  17568 				} else {
  17569 					//              [------------------------------------[
  17570 					//              interval->start          interval->end
  17571 					// [*****************************[
  17572 					// start                       end
  17573 					(*CostInterval)(unsafe.Pointer(interval)).Fstart = end
  17574 					break
  17575 				}
  17576 			} else {
  17577 				if end < (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17578 					// [--------------------------------------------------------------[
  17579 					// interval->start                                    interval->end
  17580 					//                     [*****************************[
  17581 					//                     start                       end
  17582 					// We have to split the old interval as it fully contains the new one.
  17583 					end_original = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17584 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17585 					InsertInterval(tls, manager, interval, (*CostInterval)(unsafe.Pointer(interval)).Fcost, (*CostInterval)(unsafe.Pointer(interval)).Findex, end, end_original)
  17586 					interval = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17587 					break
  17588 				} else {
  17589 					// [------------------------------------[
  17590 					// interval->start          interval->end
  17591 					//                     [*****************************[
  17592 					//                     start                       end
  17593 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17594 				}
  17595 			}
  17596 			goto _4
  17597 		_4:
  17598 			;
  17599 			interval = interval_next
  17600 		}
  17601 		// Insert the remaining interval from start to end.
  17602 		InsertInterval(tls, manager, interval, cost, position, start, end)
  17603 		goto _2
  17604 	_2:
  17605 		;
  17606 		i = i + 1
  17607 	}
  17608 }
  17609 
  17610 func BackwardReferencesHashChainDistanceOnly(tls *libc.TLS, xsize int32, ysize int32, argb uintptr, cache_bits int32, hash_chain uintptr, refs uintptr, dist_array uintptr) (r int32) {
  17611 	bp := tls.Alloc(32)
  17612 	defer tls.Free(32)
  17613 	var cc_init, code, first_offset_is_constant, i, j, len_prev, offset_prev, ok, pix_count, reach, use_color_cache, v1, v2, v4 int32
  17614 	var cost_manager, cost_model, v6 uintptr
  17615 	var cost_model_size, literal_array_size size_t
  17616 	var offset_cost, prev_cost int64_t
  17617 	var _ /* hashers at bp+0 */ VP8LColorCache
  17618 	var _ /* len at bp+20 */ int32
  17619 	var _ /* len_j at bp+28 */ int32
  17620 	var _ /* offset at bp+16 */ int32
  17621 	var _ /* offset_j at bp+24 */ int32
  17622 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cc_init, code, cost_manager, cost_model, cost_model_size, first_offset_is_constant, i, j, len_prev, literal_array_size, offset_cost, offset_prev, ok, pix_count, prev_cost, reach, use_color_cache, v1, v2, v4, v6
  17623 	ok = 0
  17624 	cc_init = 0
  17625 	pix_count = xsize * ysize
  17626 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  17627 	v1 = cache_bits
  17628 	if v1 > 0 {
  17629 		v4 = int32(1) << v1
  17630 	} else {
  17631 		v4 = 0
  17632 	}
  17633 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17634 	goto _3
  17635 _3:
  17636 	literal_array_size = uint64(4) * libc.Uint64FromInt32(v2)
  17637 	cost_model_size = uint64(3240) + literal_array_size
  17638 	cost_model = WebPSafeCalloc(tls, uint64(1), cost_model_size)
  17639 	cost_manager = WebPSafeCalloc(tls, uint64(1), uint64(33224))
  17640 	offset_prev = -int32(1)
  17641 	len_prev = -int32(1)
  17642 	offset_cost = int64(-int32(1))
  17643 	first_offset_is_constant = -int32(1) // initialized with 'impossible' value
  17644 	reach = 0
  17645 	if cost_model == libc.UintptrFromInt32(0) || cost_manager == libc.UintptrFromInt32(0) {
  17646 		goto Error
  17647 	}
  17648 	(*CostModel)(unsafe.Pointer(cost_model)).Fliteral = cost_model + libc.UintptrFromInt32(1)*3240
  17649 	if use_color_cache != 0 {
  17650 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  17651 		if !(cc_init != 0) {
  17652 			goto Error
  17653 		}
  17654 	}
  17655 	if !(CostModelBuild(tls, cost_model, xsize, cache_bits, refs) != 0) {
  17656 		goto Error
  17657 	}
  17658 	if !(CostManagerInit(tls, cost_manager, dist_array, pix_count, cost_model) != 0) {
  17659 		goto Error
  17660 	}
  17661 	// We loop one pixel at a time, but store all currently best points to
  17662 	// non-processed locations from this point.
  17663 	**(**uint16_t)(__ccgo_up(dist_array)) = uint16(0)
  17664 	// Add first pixel as literal.
  17665 	AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, 0, use_color_cache, 0, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17666 	i = int32(1)
  17667 	for {
  17668 		if !(i < pix_count) {
  17669 			break
  17670 		}
  17671 		prev_cost = **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(cost_manager)).Fcosts + uintptr(i-int32(1))*8))
  17672 		v6 = hash_chain
  17673 		v1 = i
  17674 		v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  17675 		goto _9
  17676 	_9:
  17677 		**(**int32)(__ccgo_up(bp + 16)) = v2
  17678 		v4 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  17679 		goto _11
  17680 	_11:
  17681 		**(**int32)(__ccgo_up(bp + 20)) = v4
  17682 		// Try adding the pixel as a literal.
  17683 		AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, i, use_color_cache, prev_cost, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17684 		// If we are dealing with a non-literal.
  17685 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(2) {
  17686 			if **(**int32)(__ccgo_up(bp + 16)) != offset_prev {
  17687 				code = VP8LDistanceToPlaneCode(tls, xsize, **(**int32)(__ccgo_up(bp + 16)))
  17688 				offset_cost = GetDistanceCost(tls, cost_model, libc.Uint32FromInt32(code))
  17689 				first_offset_is_constant = int32(1)
  17690 				PushInterval(tls, cost_manager, prev_cost+offset_cost, i, **(**int32)(__ccgo_up(bp + 20)))
  17691 			} else {
  17692 				// Instead of considering all contributions from a pixel i by calling:
  17693 				//         PushInterval(cost_manager, prev_cost + offset_cost, i, len);
  17694 				// we optimize these contributions in case offset_cost stays the same
  17695 				// for consecutive pixels. This describes a set of pixels similar to a
  17696 				// previous set (e.g. constant color regions).
  17697 				if first_offset_is_constant != 0 {
  17698 					reach = i - int32(1) + len_prev - int32(1)
  17699 					first_offset_is_constant = 0
  17700 				}
  17701 				if i+**(**int32)(__ccgo_up(bp + 20))-int32(1) > reach {
  17702 					**(**int32)(__ccgo_up(bp + 28)) = 0
  17703 					// Figure out the last consecutive pixel within [i, reach + 1] with
  17704 					// the same offset.
  17705 					j = i
  17706 					for {
  17707 						if !(j <= reach) {
  17708 							break
  17709 						}
  17710 						v6 = hash_chain
  17711 						v1 = j + int32(1)
  17712 						v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  17713 						goto _16
  17714 					_16:
  17715 						**(**int32)(__ccgo_up(bp + 24)) = v2
  17716 						v4 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  17717 						goto _18
  17718 					_18:
  17719 						**(**int32)(__ccgo_up(bp + 28)) = v4
  17720 						if **(**int32)(__ccgo_up(bp + 24)) != **(**int32)(__ccgo_up(bp + 16)) {
  17721 							v6 = hash_chain
  17722 							v1 = j
  17723 							v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  17724 							goto _22
  17725 						_22:
  17726 							**(**int32)(__ccgo_up(bp + 24)) = v2
  17727 							v4 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  17728 							goto _24
  17729 						_24:
  17730 							**(**int32)(__ccgo_up(bp + 28)) = v4
  17731 							break
  17732 						}
  17733 						goto _12
  17734 					_12:
  17735 						;
  17736 						j = j + 1
  17737 					}
  17738 					// Update the cost at j - 1 and j.
  17739 					UpdateCostAtIndex(tls, cost_manager, j-int32(1), 0)
  17740 					UpdateCostAtIndex(tls, cost_manager, j, 0)
  17741 					PushInterval(tls, cost_manager, **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(cost_manager)).Fcosts + uintptr(j-int32(1))*8))+offset_cost, j, **(**int32)(__ccgo_up(bp + 28)))
  17742 					reach = j + **(**int32)(__ccgo_up(bp + 28)) - int32(1)
  17743 				}
  17744 			}
  17745 		}
  17746 		UpdateCostAtIndex(tls, cost_manager, i, int32(1))
  17747 		offset_prev = **(**int32)(__ccgo_up(bp + 16))
  17748 		len_prev = **(**int32)(__ccgo_up(bp + 20))
  17749 		goto _5
  17750 	_5:
  17751 		;
  17752 		i = i + 1
  17753 	}
  17754 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  17755 	goto Error
  17756 Error:
  17757 	;
  17758 	if cc_init != 0 {
  17759 		VP8LColorCacheClear(tls, bp)
  17760 	}
  17761 	CostManagerClear(tls, cost_manager)
  17762 	WebPSafeFree(tls, cost_model)
  17763 	WebPSafeFree(tls, cost_manager)
  17764 	return ok
  17765 }
  17766 
  17767 // C documentation
  17768 //
  17769 //	// We pack the path at the end of *dist_array and return
  17770 //	// a pointer to this part of the array. Example:
  17771 //	// dist_array = [1x2xx3x2] => packed [1x2x1232], chosen_path = [1232]
  17772 func TraceBackwards(tls *libc.TLS, dist_array uintptr, dist_array_size int32, chosen_path uintptr, chosen_path_size uintptr) {
  17773 	var cur, path uintptr
  17774 	var k int32
  17775 	_, _, _ = cur, k, path
  17776 	path = dist_array + uintptr(dist_array_size)*2
  17777 	cur = dist_array + uintptr(dist_array_size)*2 - uintptr(1)*2
  17778 	for cur >= dist_array {
  17779 		k = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(cur)))
  17780 		path -= 2
  17781 		**(**uint16_t)(__ccgo_up(path)) = libc.Uint16FromInt32(k)
  17782 		cur = cur - uintptr(k)*2
  17783 	}
  17784 	**(**uintptr)(__ccgo_up(chosen_path)) = path
  17785 	**(**int32)(__ccgo_up(chosen_path_size)) = int32((int64(dist_array+uintptr(dist_array_size)*2) - int64(path)) / 2)
  17786 }
  17787 
  17788 func BackwardReferencesHashChainFollowChosenPath(tls *libc.TLS, argb4 uintptr, cache_bits int32, chosen_path uintptr, chosen_path_size int32, hash_chain uintptr, refs uintptr) (r int32) {
  17789 	bp := tls.Alloc(16)
  17790 	defer tls.Free(16)
  17791 	var cc_init, i, idx1, ix, k, key, key1, len1, offset, ok, use_color_cache, v11, v14, v2, v9 int32
  17792 	var retval, retval1, retval2, v, v4 PixOrCopy
  17793 	var v7 uintptr
  17794 	var v8 uint32_t
  17795 	var _ /* hashers at bp+0 */ VP8LColorCache
  17796 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cc_init, i, idx1, ix, k, key, key1, len1, offset, ok, retval, retval1, retval2, use_color_cache, v, v11, v14, v2, v4, v7, v8, v9
  17797 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  17798 	i = 0
  17799 	ok = 0
  17800 	cc_init = 0
  17801 	if use_color_cache != 0 {
  17802 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  17803 		if !(cc_init != 0) {
  17804 			goto Error
  17805 		}
  17806 	}
  17807 	VP8LClearBackwardRefs(tls, refs)
  17808 	ix = 0
  17809 	for {
  17810 		if !(ix < chosen_path_size) {
  17811 			break
  17812 		}
  17813 		len1 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(chosen_path + uintptr(ix)*2)))
  17814 		if len1 != int32(1) {
  17815 			v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  17816 			goto _3
  17817 		_3:
  17818 			offset = v2
  17819 			retval.Fmode = uint8(kCopy)
  17820 			retval.Fargb_or_distance = libc.Uint32FromInt32(offset)
  17821 			retval.Flen1 = libc.Uint16FromInt32(len1)
  17822 			v4 = retval
  17823 			goto _5
  17824 		_5:
  17825 			VP8LBackwardRefsCursorAdd(tls, refs, v4)
  17826 			if use_color_cache != 0 {
  17827 				k = 0
  17828 				for {
  17829 					if !(k < len1) {
  17830 						break
  17831 					}
  17832 					v7 = bp
  17833 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i+k)*4))
  17834 					v2 = libc.Int32FromUint32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  17835 					goto _10
  17836 				_10:
  17837 					key = v2
  17838 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  17839 					goto _6
  17840 				_6:
  17841 					;
  17842 					k = k + 1
  17843 				}
  17844 			}
  17845 			i = i + len1
  17846 		} else {
  17847 			if use_color_cache != 0 {
  17848 				v7 = bp
  17849 				v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  17850 				v9 = libc.Int32FromUint32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  17851 				goto _15
  17852 			_15:
  17853 				key1 = v9
  17854 				if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key1)*4)) == v8 {
  17855 					v14 = key1
  17856 				} else {
  17857 					v14 = -int32(1)
  17858 				}
  17859 				v11 = v14
  17860 				goto _17
  17861 			_17:
  17862 				v2 = v11
  17863 			} else {
  17864 				v2 = -int32(1)
  17865 			}
  17866 			idx1 = v2
  17867 			if idx1 >= 0 {
  17868 				// use_color_cache is true and hashers contains argb[i]
  17869 				// push pixel as a color cache index
  17870 				retval1.Fmode = uint8(kCacheIdx)
  17871 				retval1.Fargb_or_distance = libc.Uint32FromInt32(idx1)
  17872 				retval1.Flen1 = uint16(1)
  17873 				v4 = retval1
  17874 				goto _20
  17875 			_20:
  17876 				v = v4
  17877 			} else {
  17878 				if use_color_cache != 0 {
  17879 					v7 = bp
  17880 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  17881 					v2 = libc.Int32FromUint32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  17882 					goto _24
  17883 				_24:
  17884 					key = v2
  17885 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  17886 				}
  17887 				retval2.Fmode = uint8(kLiteral)
  17888 				retval2.Fargb_or_distance = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  17889 				retval2.Flen1 = uint16(1)
  17890 				v4 = retval2
  17891 				goto _26
  17892 			_26:
  17893 				v = v4
  17894 			}
  17895 			VP8LBackwardRefsCursorAdd(tls, refs, v)
  17896 			i = i + 1
  17897 		}
  17898 		goto _1
  17899 	_1:
  17900 		;
  17901 		ix = ix + 1
  17902 	}
  17903 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  17904 	goto Error
  17905 Error:
  17906 	;
  17907 	if cc_init != 0 {
  17908 		VP8LColorCacheClear(tls, bp)
  17909 	}
  17910 	return ok
  17911 }
  17912 
  17913 func VP8LBackwardReferencesTraceBackwards(tls *libc.TLS, xsize int32, ysize int32, argb uintptr, cache_bits int32, hash_chain uintptr, refs_src uintptr, refs_dst uintptr) (r int32) {
  17914 	bp := tls.Alloc(16)
  17915 	defer tls.Free(16)
  17916 	var dist_array uintptr
  17917 	var dist_array_size, ok int32
  17918 	var _ /* chosen_path at bp+0 */ uintptr
  17919 	var _ /* chosen_path_size at bp+8 */ int32
  17920 	_, _, _ = dist_array, dist_array_size, ok
  17921 	ok = 0
  17922 	dist_array_size = xsize * ysize
  17923 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  17924 	**(**int32)(__ccgo_up(bp + 8)) = 0
  17925 	dist_array = WebPSafeMalloc(tls, libc.Uint64FromInt32(dist_array_size), uint64(2))
  17926 	if dist_array == libc.UintptrFromInt32(0) {
  17927 		goto Error
  17928 	}
  17929 	if !(BackwardReferencesHashChainDistanceOnly(tls, xsize, ysize, argb, cache_bits, hash_chain, refs_src, dist_array) != 0) {
  17930 		goto Error
  17931 	}
  17932 	TraceBackwards(tls, dist_array, dist_array_size, bp, bp+8)
  17933 	if !(BackwardReferencesHashChainFollowChosenPath(tls, argb, cache_bits, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), hash_chain, refs_dst) != 0) {
  17934 		goto Error
  17935 	}
  17936 	ok = int32(1)
  17937 	goto Error
  17938 Error:
  17939 	;
  17940 	WebPSafeFree(tls, dist_array)
  17941 	return ok
  17942 }
  17943 
  17944 const MIN_BLOCK_SIZE = 256
  17945 const MIN_LENGTH = 4
  17946 const WINDOW_OFFSETS_SIZE_MAX = 32
  17947 
  17948 type PixOrCopyBlock = struct {
  17949 	Fnext  uintptr
  17950 	Fstart uintptr
  17951 	Fsize  int32
  17952 }
  17953 
  17954 var kHashMul11 = uint32(0x1e35a7bd)
  17955 
  17956 //------------------------------------------------------------------------------
  17957 
  17958 // Copyright 2012 Google Inc. All Rights Reserved.
  17959 //
  17960 // Use of this source code is governed by a BSD-style license
  17961 // that can be found in the COPYING file in the root of the source
  17962 // tree. An additional intellectual property rights grant can be found
  17963 // in the file PATENTS. All contributing project authors may
  17964 // be found in the AUTHORS file in the root of the source tree.
  17965 // -----------------------------------------------------------------------------
  17966 //
  17967 // Misc. common utility functions
  17968 //
  17969 // Authors: Skal (pascal.massimino@gmail.com)
  17970 //          Urvang (urvang@google.com)
  17971 
  17972 // Copyright 2011 Google Inc. All Rights Reserved.
  17973 //
  17974 // Use of this source code is governed by a BSD-style license
  17975 // that can be found in the COPYING file in the root of the source
  17976 // tree. An additional intellectual property rights grant can be found
  17977 // in the file PATENTS. All contributing project authors may
  17978 // be found in the AUTHORS file in the root of the source tree.
  17979 // -----------------------------------------------------------------------------
  17980 //
  17981 //   WebP encoder: main interface
  17982 //
  17983 // Author: Skal (pascal.massimino@gmail.com)
  17984 
  17985 // Copyright 2012 Google Inc. All Rights Reserved.
  17986 //
  17987 // Use of this source code is governed by a BSD-style license
  17988 // that can be found in the COPYING file in the root of the source
  17989 // tree. An additional intellectual property rights grant can be found
  17990 // in the file PATENTS. All contributing project authors may
  17991 // be found in the AUTHORS file in the root of the source tree.
  17992 // -----------------------------------------------------------------------------
  17993 //
  17994 //  Internal header for constants related to WebP file format.
  17995 //
  17996 // Author: Urvang (urvang@google.com)
  17997 
  17998 // Copyright 2010 Google Inc. All Rights Reserved.
  17999 //
  18000 // Use of this source code is governed by a BSD-style license
  18001 // that can be found in the COPYING file in the root of the source
  18002 // tree. An additional intellectual property rights grant can be found
  18003 // in the file PATENTS. All contributing project authors may
  18004 // be found in the AUTHORS file in the root of the source tree.
  18005 // -----------------------------------------------------------------------------
  18006 //
  18007 //  Common types + memory wrappers
  18008 //
  18009 // Author: Skal (pascal.massimino@gmail.com)
  18010 
  18011 // 1M window (4M bytes) minus 120 special codes for short distances.
  18012 
  18013 // Minimum number of pixels for which it is cheaper to encode a
  18014 // distance + length instead of each pixel as a literal.
  18015 
  18016 // -----------------------------------------------------------------------------
  18017 
  18018 var plane_to_code_lut = [128]uint8_t{
  18019 	0:   uint8(96),
  18020 	1:   uint8(73),
  18021 	2:   uint8(55),
  18022 	3:   uint8(39),
  18023 	4:   uint8(23),
  18024 	5:   uint8(13),
  18025 	6:   uint8(5),
  18026 	7:   uint8(1),
  18027 	8:   uint8(255),
  18028 	9:   uint8(255),
  18029 	10:  uint8(255),
  18030 	11:  uint8(255),
  18031 	12:  uint8(255),
  18032 	13:  uint8(255),
  18033 	14:  uint8(255),
  18034 	15:  uint8(255),
  18035 	16:  uint8(101),
  18036 	17:  uint8(78),
  18037 	18:  uint8(58),
  18038 	19:  uint8(42),
  18039 	20:  uint8(26),
  18040 	21:  uint8(16),
  18041 	22:  uint8(8),
  18042 	23:  uint8(2),
  18043 	25:  uint8(3),
  18044 	26:  uint8(9),
  18045 	27:  uint8(17),
  18046 	28:  uint8(27),
  18047 	29:  uint8(43),
  18048 	30:  uint8(59),
  18049 	31:  uint8(79),
  18050 	32:  uint8(102),
  18051 	33:  uint8(86),
  18052 	34:  uint8(62),
  18053 	35:  uint8(46),
  18054 	36:  uint8(32),
  18055 	37:  uint8(20),
  18056 	38:  uint8(10),
  18057 	39:  uint8(6),
  18058 	40:  uint8(4),
  18059 	41:  uint8(7),
  18060 	42:  uint8(11),
  18061 	43:  uint8(21),
  18062 	44:  uint8(33),
  18063 	45:  uint8(47),
  18064 	46:  uint8(63),
  18065 	47:  uint8(87),
  18066 	48:  uint8(105),
  18067 	49:  uint8(90),
  18068 	50:  uint8(70),
  18069 	51:  uint8(52),
  18070 	52:  uint8(37),
  18071 	53:  uint8(28),
  18072 	54:  uint8(18),
  18073 	55:  uint8(14),
  18074 	56:  uint8(12),
  18075 	57:  uint8(15),
  18076 	58:  uint8(19),
  18077 	59:  uint8(29),
  18078 	60:  uint8(38),
  18079 	61:  uint8(53),
  18080 	62:  uint8(71),
  18081 	63:  uint8(91),
  18082 	64:  uint8(110),
  18083 	65:  uint8(99),
  18084 	66:  uint8(82),
  18085 	67:  uint8(66),
  18086 	68:  uint8(48),
  18087 	69:  uint8(35),
  18088 	70:  uint8(30),
  18089 	71:  uint8(24),
  18090 	72:  uint8(22),
  18091 	73:  uint8(25),
  18092 	74:  uint8(31),
  18093 	75:  uint8(36),
  18094 	76:  uint8(49),
  18095 	77:  uint8(67),
  18096 	78:  uint8(83),
  18097 	79:  uint8(100),
  18098 	80:  uint8(115),
  18099 	81:  uint8(108),
  18100 	82:  uint8(94),
  18101 	83:  uint8(76),
  18102 	84:  uint8(64),
  18103 	85:  uint8(50),
  18104 	86:  uint8(44),
  18105 	87:  uint8(40),
  18106 	88:  uint8(34),
  18107 	89:  uint8(41),
  18108 	90:  uint8(45),
  18109 	91:  uint8(51),
  18110 	92:  uint8(65),
  18111 	93:  uint8(77),
  18112 	94:  uint8(95),
  18113 	95:  uint8(109),
  18114 	96:  uint8(118),
  18115 	97:  uint8(113),
  18116 	98:  uint8(103),
  18117 	99:  uint8(92),
  18118 	100: uint8(80),
  18119 	101: uint8(68),
  18120 	102: uint8(60),
  18121 	103: uint8(56),
  18122 	104: uint8(54),
  18123 	105: uint8(57),
  18124 	106: uint8(61),
  18125 	107: uint8(69),
  18126 	108: uint8(81),
  18127 	109: uint8(93),
  18128 	110: uint8(104),
  18129 	111: uint8(114),
  18130 	112: uint8(119),
  18131 	113: uint8(116),
  18132 	114: uint8(111),
  18133 	115: uint8(106),
  18134 	116: uint8(97),
  18135 	117: uint8(88),
  18136 	118: uint8(84),
  18137 	119: uint8(74),
  18138 	120: uint8(72),
  18139 	121: uint8(75),
  18140 	122: uint8(85),
  18141 	123: uint8(89),
  18142 	124: uint8(98),
  18143 	125: uint8(107),
  18144 	126: uint8(112),
  18145 	127: uint8(117),
  18146 }
  18147 
  18148 func VP8LDistanceToPlaneCode(tls *libc.TLS, xsize int32, dist int32) (r int32) {
  18149 	var xoffset, yoffset int32
  18150 	_, _ = xoffset, yoffset
  18151 	yoffset = dist / xsize
  18152 	xoffset = dist - yoffset*xsize
  18153 	if xoffset <= int32(8) && yoffset < int32(8) {
  18154 		return libc.Int32FromUint8(plane_to_code_lut[yoffset*int32(16)+int32(8)-xoffset]) + int32(1)
  18155 	} else {
  18156 		if xoffset > xsize-int32(8) && yoffset < int32(7) {
  18157 			return libc.Int32FromUint8(plane_to_code_lut[(yoffset+int32(1))*int32(16)+int32(8)+(xsize-xoffset)]) + int32(1)
  18158 		}
  18159 	}
  18160 	return dist + int32(120)
  18161 }
  18162 
  18163 // C documentation
  18164 //
  18165 //	// Returns the exact index where array1 and array2 are different. For an index
  18166 //	// inferior or equal to best_len_match, the return value just has to be strictly
  18167 //	// inferior to best_len_match. The current behavior is to return 0 if this index
  18168 //	// is best_len_match, and the index itself otherwise.
  18169 //	// If no two elements are the same, it returns max_limit.
  18170 func FindMatchLength(tls *libc.TLS, array1 uintptr, array2 uintptr, best_len_match int32, max_limit int32) (r int32) {
  18171 	// Before 'expensive' linear match, check if the two arrays match at the
  18172 	// current best length index.
  18173 	if **(**uint32_t)(__ccgo_up(array1 + uintptr(best_len_match)*4)) != **(**uint32_t)(__ccgo_up(array2 + uintptr(best_len_match)*4)) {
  18174 		return 0
  18175 	}
  18176 	return (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, array1, array2, max_limit)
  18177 }
  18178 
  18179 func VP8LClearBackwardRefs(tls *libc.TLS, refs uintptr) {
  18180 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail != libc.UintptrFromInt32(0) {
  18181 		**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks // recycle all blocks at once
  18182 	}
  18183 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18184 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18185 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = libc.UintptrFromInt32(0)
  18186 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs = libc.UintptrFromInt32(0)
  18187 }
  18188 
  18189 func VP8LBackwardRefsClear(tls *libc.TLS, refs uintptr) {
  18190 	var next uintptr
  18191 	_ = next
  18192 	VP8LClearBackwardRefs(tls, refs)
  18193 	for (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks != libc.UintptrFromInt32(0) {
  18194 		next = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)).Fnext
  18195 		WebPSafeFree(tls, (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)
  18196 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = next
  18197 	}
  18198 }
  18199 
  18200 // C documentation
  18201 //
  18202 //	// Swaps the content of two VP8LBackwardRefs.
  18203 func BackwardRefsSwap(tls *libc.TLS, refs1 uintptr, refs2 uintptr) {
  18204 	var point_to_refs1, point_to_refs2 int32
  18205 	var tmp VP8LBackwardRefs
  18206 	_, _, _ = point_to_refs1, point_to_refs2, tmp
  18207 	point_to_refs1 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail == refs1+8)
  18208 	point_to_refs2 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail == refs2+8)
  18209 	tmp = **(**VP8LBackwardRefs)(__ccgo_up(refs1))
  18210 	**(**VP8LBackwardRefs)(__ccgo_up(refs1)) = **(**VP8LBackwardRefs)(__ccgo_up(refs2))
  18211 	**(**VP8LBackwardRefs)(__ccgo_up(refs2)) = tmp
  18212 	if point_to_refs2 != 0 {
  18213 		(*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail = refs1 + 8
  18214 	}
  18215 	if point_to_refs1 != 0 {
  18216 		(*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail = refs2 + 8
  18217 	}
  18218 }
  18219 
  18220 func VP8LBackwardRefsInit(tls *libc.TLS, refs uintptr, block_size int32) {
  18221 	var v1 int32
  18222 	_ = v1
  18223 	libc.Xmemset(tls, refs, 0, uint64(40))
  18224 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18225 	if block_size < int32(MIN_BLOCK_SIZE) {
  18226 		v1 = int32(MIN_BLOCK_SIZE)
  18227 	} else {
  18228 		v1 = block_size
  18229 	}
  18230 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size = v1
  18231 }
  18232 
  18233 func VP8LRefsCursorInit(tls *libc.TLS, refs uintptr) (r VP8LRefsCursor) {
  18234 	var c VP8LRefsCursor
  18235 	_ = c
  18236 	c.Fcur_block = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18237 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs != libc.UintptrFromInt32(0) {
  18238 		c.Fcur_pos = (*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fstart
  18239 		c.Flast_pos = c.Fcur_pos + uintptr((*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fsize)*8
  18240 	} else {
  18241 		c.Fcur_pos = libc.UintptrFromInt32(0)
  18242 		c.Flast_pos = libc.UintptrFromInt32(0)
  18243 	}
  18244 	return c
  18245 }
  18246 
  18247 func VP8LRefsCursorNextBlock(tls *libc.TLS, c uintptr) {
  18248 	var b, v1 uintptr
  18249 	_, _ = b, v1
  18250 	b = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block)).Fnext
  18251 	if b == libc.UintptrFromInt32(0) {
  18252 		v1 = libc.UintptrFromInt32(0)
  18253 	} else {
  18254 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart
  18255 	}
  18256 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_pos = v1
  18257 	if b == libc.UintptrFromInt32(0) {
  18258 		v1 = libc.UintptrFromInt32(0)
  18259 	} else {
  18260 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr((*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize)*8
  18261 	}
  18262 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Flast_pos = v1
  18263 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block = b
  18264 }
  18265 
  18266 // C documentation
  18267 //
  18268 //	// Create a new block, either from the free list or allocated
  18269 func BackwardRefsNewBlock(tls *libc.TLS, refs uintptr) (r uintptr) {
  18270 	var b uintptr
  18271 	var total_size size_t
  18272 	_, _ = b, total_size
  18273 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks
  18274 	if b == libc.UintptrFromInt32(0) { // allocate new memory chunk
  18275 		total_size = uint64(24) + libc.Uint64FromInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size)*uint64(8)
  18276 		b = WebPSafeMalloc(tls, uint64(1), total_size)
  18277 		if b == libc.UintptrFromInt32(0) {
  18278 			**(**int32)(__ccgo_up(refs + 4)) |= int32(1)
  18279 			return libc.UintptrFromInt32(0)
  18280 		}
  18281 		(*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart = b + libc.UintptrFromInt64(24) // not always aligned
  18282 	} else { // recycle from free-list
  18283 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext
  18284 	}
  18285 	**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = b
  18286 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = b
  18287 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = b
  18288 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext = libc.UintptrFromInt32(0)
  18289 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize = 0
  18290 	return b
  18291 }
  18292 
  18293 // C documentation
  18294 //
  18295 //	// Return 1 on success, 0 on error.
  18296 func BackwardRefsClone(tls *libc.TLS, from uintptr, to uintptr) (r int32) {
  18297 	var block_from, block_to uintptr
  18298 	_, _ = block_from, block_to
  18299 	block_from = (*VP8LBackwardRefs)(unsafe.Pointer(from)).Frefs
  18300 	VP8LClearBackwardRefs(tls, to)
  18301 	for block_from != libc.UintptrFromInt32(0) {
  18302 		block_to = BackwardRefsNewBlock(tls, to)
  18303 		if block_to == libc.UintptrFromInt32(0) {
  18304 			return 0
  18305 		}
  18306 		libc.Xmemcpy(tls, (*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fstart, (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fstart, libc.Uint64FromInt32((*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize)*uint64(8))
  18307 		(*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fsize = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize
  18308 		block_from = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fnext
  18309 	}
  18310 	return int32(1)
  18311 }
  18312 
  18313 func VP8LBackwardRefsCursorAdd(tls *libc.TLS, refs uintptr, v PixOrCopy) {
  18314 	var b, v2 uintptr
  18315 	var v1 int32
  18316 	_, _, _ = b, v1, v2
  18317 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block
  18318 	if b == libc.UintptrFromInt32(0) || (*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize == (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size {
  18319 		b = BackwardRefsNewBlock(tls, refs)
  18320 		if b == libc.UintptrFromInt32(0) {
  18321 			return
  18322 		} // refs->error is set
  18323 	}
  18324 	v2 = b + 16
  18325 	v1 = *(*int32)(unsafe.Pointer(v2))
  18326 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  18327 	**(**PixOrCopy)(__ccgo_up((*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr(v1)*8)) = v
  18328 }
  18329 
  18330 // -----------------------------------------------------------------------------
  18331 // Hash chains
  18332 
  18333 func VP8LHashChainInit(tls *libc.TLS, p uintptr, size int32) (r int32) {
  18334 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = WebPSafeMalloc(tls, libc.Uint64FromInt32(size), uint64(4))
  18335 	if (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length == libc.UintptrFromInt32(0) {
  18336 		return 0
  18337 	}
  18338 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = size
  18339 	return int32(1)
  18340 }
  18341 
  18342 func VP8LHashChainClear(tls *libc.TLS, p uintptr) {
  18343 	WebPSafeFree(tls, (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)
  18344 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = 0
  18345 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = libc.UintptrFromInt32(0)
  18346 }
  18347 
  18348 // -----------------------------------------------------------------------------
  18349 
  18350 var kHashMultiplierHi = uint32(0xc6a4a793)
  18351 var kHashMultiplierLo = uint32(0x5bd1e996)
  18352 
  18353 func GetPixPairHash64(tls *libc.TLS, argb uintptr) (r uint32_t) {
  18354 	var key uint32_t
  18355 	_ = key
  18356 	key = **(**uint32_t)(__ccgo_up(argb + 1*4)) * kHashMultiplierHi
  18357 	key = key + **(**uint32_t)(__ccgo_up(argb))*kHashMultiplierLo
  18358 	key = key >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(HASH_BITS))
  18359 	return key
  18360 }
  18361 
  18362 // C documentation
  18363 //
  18364 //	// Returns the maximum number of hash chain lookups to do for a
  18365 //	// given compression quality. Return value in range [8, 86].
  18366 func GetMaxItersForQuality(tls *libc.TLS, quality int32) (r int32) {
  18367 	return int32(8) + quality*quality/int32(128)
  18368 }
  18369 
  18370 func GetWindowSizeForHashChain(tls *libc.TLS, quality int32, xsize int32) (r int32) {
  18371 	var max_window_size, v1, v2, v3 int32
  18372 	_, _, _, _ = max_window_size, v1, v2, v3
  18373 	if quality > int32(75) {
  18374 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18375 	} else {
  18376 		if quality > int32(50) {
  18377 			v2 = xsize << int32(8)
  18378 		} else {
  18379 			if quality > int32(25) {
  18380 				v3 = xsize << int32(6)
  18381 			} else {
  18382 				v3 = xsize << int32(4)
  18383 			}
  18384 			v2 = v3
  18385 		}
  18386 		v1 = v2
  18387 	}
  18388 	max_window_size = v1
  18389 	if max_window_size > libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS)-libc.Int32FromInt32(120) {
  18390 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18391 	} else {
  18392 		v1 = max_window_size
  18393 	}
  18394 	return v1
  18395 }
  18396 
  18397 func MaxFindCopyLength(tls *libc.TLS, len1 int32) (r int32) {
  18398 	var v1 int32
  18399 	_ = v1
  18400 	if len1 < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18401 		v1 = len1
  18402 	} else {
  18403 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  18404 	}
  18405 	return v1
  18406 }
  18407 
  18408 func VP8LHashChainFill(tls *libc.TLS, p uintptr, quality int32, argb uintptr, xsize int32, ysize int32, low_effort int32, pic uintptr, percent_range int32, percent uintptr) (r int32) {
  18409 	bp := tls.Alloc(16)
  18410 	defer tls.Free(16)
  18411 	var argb_comp, argb_comp_next, best_length, curr_length, curr_length1, iter, iter_max, length_max, max_len, min_pos, percent_start, pos, remaining_percent, size, v4 int32
  18412 	var argb_start, chain, hash_to_first_index uintptr
  18413 	var base_position, best_argb, best_distance, hash_code, len1, max_base_position, window_size, v1 uint32_t
  18414 	var v12 bool
  18415 	var v8 uint32
  18416 	var _ /* tmp at bp+0 */ [2]uint32_t
  18417 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_comp, argb_comp_next, argb_start, base_position, best_argb, best_distance, best_length, chain, curr_length, curr_length1, hash_code, hash_to_first_index, iter, iter_max, len1, length_max, max_base_position, max_len, min_pos, percent_start, pos, remaining_percent, size, window_size, v1, v12, v4, v8
  18418 	size = xsize * ysize
  18419 	iter_max = GetMaxItersForQuality(tls, quality)
  18420 	window_size = libc.Uint32FromInt32(GetWindowSizeForHashChain(tls, quality, xsize))
  18421 	remaining_percent = percent_range
  18422 	percent_start = **(**int32)(__ccgo_up(percent))
  18423 	// Temporarily use the p->offset_length as a hash chain.
  18424 	chain = (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length
  18425 	if size <= int32(2) {
  18426 		v1 = libc.Uint32FromInt32(0)
  18427 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18428 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18429 		return int32(1)
  18430 	}
  18431 	hash_to_first_index = WebPSafeMalloc(tls, libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS)), uint64(4))
  18432 	if hash_to_first_index == libc.UintptrFromInt32(0) {
  18433 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  18434 	}
  18435 	percent_range = remaining_percent / int32(2)
  18436 	remaining_percent = remaining_percent - percent_range
  18437 	// Set the int32_t array to -1.
  18438 	libc.Xmemset(tls, hash_to_first_index, int32(0xff), libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS))*libc.Uint64FromInt64(4))
  18439 	// Fill the chain linking pixels with the same hash.
  18440 	argb_comp = libc.BoolInt32(**(**uint32_t)(__ccgo_up(argb)) == **(**uint32_t)(__ccgo_up(argb + 1*4)))
  18441 	pos = 0
  18442 	for {
  18443 		if !(pos < size-int32(2)) {
  18444 			break
  18445 		}
  18446 		argb_comp_next = libc.BoolInt32(**(**uint32_t)(__ccgo_up(argb + uintptr(pos+int32(1))*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(pos+int32(2))*4)))
  18447 		if argb_comp != 0 && argb_comp_next != 0 {
  18448 			len1 = uint32(1)
  18449 			(**(**[2]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(argb + uintptr(pos)*4))
  18450 			// Figure out how far the pixels are the same.
  18451 			// The last pixel has a different 64 bit hash, as its next pixel does
  18452 			// not have the same color, so we just need to get to the last pixel equal
  18453 			// to its follower.
  18454 			for pos+libc.Int32FromUint32(len1)+int32(2) < size && **(**uint32_t)(__ccgo_up(argb + uintptr(libc.Uint32FromInt32(pos)+len1+uint32(2))*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(pos)*4)) {
  18455 				len1 = len1 + 1
  18456 			}
  18457 			if len1 > libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)) {
  18458 				// Skip the pixels that match for distance=1 and length>MAX_LENGTH
  18459 				// because they are linked to their predecessor and we automatically
  18460 				// check that in the main for loop below. Skipping means setting no
  18461 				// predecessor in the chain, hence -1.
  18462 				libc.Xmemset(tls, chain+uintptr(pos)*4, int32(0xff), uint64(len1-libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)))*uint64(4))
  18463 				pos = libc.Int32FromUint32(uint32(pos) + (len1 - libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))))
  18464 				len1 = libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1))
  18465 			}
  18466 			// Process the rest of the hash chain.
  18467 			for len1 != 0 {
  18468 				v1 = len1
  18469 				len1 = len1 - 1
  18470 				(**(**[2]uint32_t)(__ccgo_up(bp)))[int32(1)] = v1
  18471 				hash_code = GetPixPairHash64(tls, bp)
  18472 				**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18473 				v4 = pos
  18474 				pos = pos + 1
  18475 				**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18476 			}
  18477 			argb_comp = 0
  18478 		} else {
  18479 			// Just move one pixel forward.
  18480 			hash_code = GetPixPairHash64(tls, argb+uintptr(pos)*4)
  18481 			**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18482 			v4 = pos
  18483 			pos = pos + 1
  18484 			**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18485 			argb_comp = argb_comp_next
  18486 		}
  18487 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*pos/(size-int32(2)), percent) != 0) {
  18488 			WebPSafeFree(tls, hash_to_first_index)
  18489 			return 0
  18490 		}
  18491 		goto _2
  18492 	_2:
  18493 	}
  18494 	// Process the penultimate pixel.
  18495 	**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(GetPixPairHash64(tls, argb+uintptr(pos)*4))*4))
  18496 	WebPSafeFree(tls, hash_to_first_index)
  18497 	percent_start = percent_start + percent_range
  18498 	if !(WebPReportProgress(tls, pic, percent_start, percent) != 0) {
  18499 		return 0
  18500 	}
  18501 	percent_range = remaining_percent
  18502 	// Find the best match interval at each pixel, defined by an offset to the
  18503 	// pixel and a length. The right-most pixel cannot match anything to the right
  18504 	// (hence a best length of 0) and the left-most pixel nothing to the left
  18505 	// (hence an offset of 0).
  18506 	v1 = libc.Uint32FromInt32(0)
  18507 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18508 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18509 	base_position = libc.Uint32FromInt32(size - int32(2))
  18510 	for {
  18511 		if !(base_position > uint32(0)) {
  18512 			break
  18513 		}
  18514 		max_len = MaxFindCopyLength(tls, libc.Int32FromUint32(libc.Uint32FromInt32(size-int32(1))-base_position))
  18515 		argb_start = argb + uintptr(base_position)*4
  18516 		iter = iter_max
  18517 		best_length = 0
  18518 		best_distance = uint32(0)
  18519 		if base_position > window_size {
  18520 			v8 = base_position - window_size
  18521 		} else {
  18522 			v8 = uint32(0)
  18523 		}
  18524 		min_pos = libc.Int32FromUint32(v8)
  18525 		if max_len < int32(256) {
  18526 			v4 = max_len
  18527 		} else {
  18528 			v4 = int32(256)
  18529 		}
  18530 		length_max = v4
  18531 		pos = **(**int32_t)(__ccgo_up(chain + uintptr(base_position)*4))
  18532 		if !(low_effort != 0) {
  18533 			// Heuristic: use the comparison with the above line as an initialization.
  18534 			if base_position >= libc.Uint32FromInt32(xsize) {
  18535 				curr_length = FindMatchLength(tls, argb_start-uintptr(xsize)*4, argb_start, best_length, max_len)
  18536 				if curr_length > best_length {
  18537 					best_length = curr_length
  18538 					best_distance = libc.Uint32FromInt32(xsize)
  18539 				}
  18540 				iter = iter - 1
  18541 			}
  18542 			// Heuristic: compare to the previous pixel.
  18543 			curr_length = FindMatchLength(tls, argb_start-uintptr(1)*4, argb_start, best_length, max_len)
  18544 			if curr_length > best_length {
  18545 				best_length = curr_length
  18546 				best_distance = uint32(1)
  18547 			}
  18548 			iter = iter - 1
  18549 			// Skip the for loop if we already have the maximum.
  18550 			if best_length == libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18551 				pos = min_pos - int32(1)
  18552 			}
  18553 		}
  18554 		best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18555 		for {
  18556 			if v12 = pos >= min_pos; v12 {
  18557 				iter = iter - 1
  18558 				v4 = iter
  18559 			}
  18560 			if !(v12 && v4 != 0) {
  18561 				break
  18562 			}
  18563 			if **(**uint32_t)(__ccgo_up(argb + uintptr(pos+best_length)*4)) != best_argb {
  18564 				goto _10
  18565 			}
  18566 			curr_length1 = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, argb+uintptr(pos)*4, argb_start, max_len)
  18567 			if best_length < curr_length1 {
  18568 				best_length = curr_length1
  18569 				best_distance = base_position - libc.Uint32FromInt32(pos)
  18570 				best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18571 				// Stop if we have reached a good enough length.
  18572 				if best_length >= length_max {
  18573 					break
  18574 				}
  18575 			}
  18576 			goto _10
  18577 		_10:
  18578 			;
  18579 			pos = **(**int32_t)(__ccgo_up(chain + uintptr(pos)*4))
  18580 		}
  18581 		// We have the best match but in case the two intervals continue matching
  18582 		// to the left, we have the best matches for the left-extended pixels.
  18583 		max_base_position = base_position
  18584 		for int32(1) != 0 {
  18585 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(base_position)*4)) = best_distance<<libc.Int32FromInt32(MAX_LENGTH_BITS) | libc.Uint32FromInt32(best_length)
  18586 			base_position = base_position - 1
  18587 			// Stop if we don't have a match or if we are out of bounds.
  18588 			if best_distance == uint32(0) || base_position == uint32(0) {
  18589 				break
  18590 			}
  18591 			// Stop if we cannot extend the matching intervals to the left.
  18592 			if base_position < best_distance || **(**uint32_t)(__ccgo_up(argb + uintptr(base_position-best_distance)*4)) != **(**uint32_t)(__ccgo_up(argb + uintptr(base_position)*4)) {
  18593 				break
  18594 			}
  18595 			// Stop if we are matching at its limit because there could be a closer
  18596 			// matching interval with the same maximum length. Then again, if the
  18597 			// matching interval is as close as possible (best_distance == 1), we will
  18598 			// never find anything better so let's continue.
  18599 			if best_length == libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) && best_distance != uint32(1) && base_position+libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)) < max_base_position {
  18600 				break
  18601 			}
  18602 			if best_length < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18603 				best_length = best_length + 1
  18604 				max_base_position = base_position
  18605 			}
  18606 		}
  18607 		if !(WebPReportProgress(tls, pic, libc.Int32FromUint32(libc.Uint32FromInt32(percent_start)+libc.Uint32FromInt32(percent_range)*(libc.Uint32FromInt32(size-int32(2))-base_position)/libc.Uint32FromInt32(size-libc.Int32FromInt32(2))), percent) != 0) {
  18608 			return 0
  18609 		}
  18610 		goto _7
  18611 	_7:
  18612 	}
  18613 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  18614 }
  18615 
  18616 func AddSingleLiteral(tls *libc.TLS, pixel uint32_t, use_color_cache int32, hashers uintptr, refs uintptr) {
  18617 	var key2, v5 uint32_t
  18618 	var retval, retval1, v, v7 PixOrCopy
  18619 	var v1, v3 int32
  18620 	_, _, _, _, _, _, _, _ = key2, retval, retval1, v, v1, v3, v5, v7
  18621 	if use_color_cache != 0 {
  18622 		v3 = libc.Int32FromUint32(pixel * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(hashers)).Fhash_shift)
  18623 		goto _4
  18624 	_4:
  18625 		v1 = v3
  18626 		goto _2
  18627 	_2:
  18628 		key2 = libc.Uint32FromInt32(v1)
  18629 		v5 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4))
  18630 		goto _6
  18631 	_6:
  18632 		if v5 == pixel {
  18633 			retval.Fmode = uint8(kCacheIdx)
  18634 			retval.Fargb_or_distance = libc.Uint32FromInt32(libc.Int32FromUint32(key2))
  18635 			retval.Flen1 = uint16(1)
  18636 			v7 = retval
  18637 			goto _8
  18638 		_8:
  18639 			v = v7
  18640 		} else {
  18641 			retval1.Fmode = uint8(kLiteral)
  18642 			retval1.Fargb_or_distance = pixel
  18643 			retval1.Flen1 = uint16(1)
  18644 			v7 = retval1
  18645 			goto _10
  18646 		_10:
  18647 			v = v7
  18648 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4)) = pixel
  18649 		}
  18650 	} else {
  18651 		retval1.Fmode = uint8(kLiteral)
  18652 		retval1.Fargb_or_distance = pixel
  18653 		retval1.Flen1 = uint16(1)
  18654 		v7 = retval1
  18655 		goto _12
  18656 	_12:
  18657 		v = v7
  18658 	}
  18659 	VP8LBackwardRefsCursorAdd(tls, refs, v)
  18660 }
  18661 
  18662 func BackwardReferencesRle(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, refs uintptr) (r int32) {
  18663 	bp := tls.Alloc(16)
  18664 	defer tls.Free(16)
  18665 	var i, k, key, max_len, pix_count, prev_row_len, rle_len, use_color_cache, v1 int32
  18666 	var retval, v2 PixOrCopy
  18667 	var v7 uintptr
  18668 	var v8 uint32_t
  18669 	var _ /* hashers at bp+0 */ VP8LColorCache
  18670 	_, _, _, _, _, _, _, _, _, _, _, _, _ = i, k, key, max_len, pix_count, prev_row_len, retval, rle_len, use_color_cache, v1, v2, v7, v8
  18671 	pix_count = xsize * ysize
  18672 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18673 	if use_color_cache != 0 && !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  18674 		return 0
  18675 	}
  18676 	VP8LClearBackwardRefs(tls, refs)
  18677 	// Add first pixel as literal.
  18678 	AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2)), use_color_cache, bp, refs)
  18679 	i = int32(1)
  18680 	for i < pix_count {
  18681 		max_len = MaxFindCopyLength(tls, pix_count-i)
  18682 		rle_len = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(1)*4, 0, max_len)
  18683 		if i < xsize {
  18684 			v1 = 0
  18685 		} else {
  18686 			v1 = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(xsize)*4, 0, max_len)
  18687 		}
  18688 		prev_row_len = v1
  18689 		if rle_len >= prev_row_len && rle_len >= int32(MIN_LENGTH) {
  18690 			retval.Fmode = uint8(kCopy)
  18691 			retval.Fargb_or_distance = uint32(1)
  18692 			retval.Flen1 = libc.Uint16FromInt32(rle_len)
  18693 			v2 = retval
  18694 			goto _3
  18695 		_3:
  18696 			VP8LBackwardRefsCursorAdd(tls, refs, v2)
  18697 			// We don't need to update the color cache here since it is always the
  18698 			// same pixel being copied, and that does not change the color cache
  18699 			// state.
  18700 			i = i + rle_len
  18701 		} else {
  18702 			if prev_row_len >= int32(MIN_LENGTH) {
  18703 				retval.Fmode = uint8(kCopy)
  18704 				retval.Fargb_or_distance = libc.Uint32FromInt32(xsize)
  18705 				retval.Flen1 = libc.Uint16FromInt32(prev_row_len)
  18706 				v2 = retval
  18707 				goto _5
  18708 			_5:
  18709 				VP8LBackwardRefsCursorAdd(tls, refs, v2)
  18710 				if use_color_cache != 0 {
  18711 					k = 0
  18712 					for {
  18713 						if !(k < prev_row_len) {
  18714 							break
  18715 						}
  18716 						v7 = bp
  18717 						v8 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(i+k)*4))
  18718 						v1 = libc.Int32FromUint32(v8 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18719 						goto _10
  18720 					_10:
  18721 						key = v1
  18722 						**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18723 						goto _6
  18724 					_6:
  18725 						;
  18726 						k = k + 1
  18727 					}
  18728 				}
  18729 				i = i + prev_row_len
  18730 			} else {
  18731 				AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  18732 				i = i + 1
  18733 			}
  18734 		}
  18735 	}
  18736 	if use_color_cache != 0 {
  18737 		VP8LColorCacheClear(tls, bp)
  18738 	}
  18739 	return libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18740 }
  18741 
  18742 func BackwardReferencesLz77(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, hash_chain uintptr, refs uintptr) (r int32) {
  18743 	bp := tls.Alloc(32)
  18744 	defer tls.Free(32)
  18745 	var cc_init, i, i_last_check, j, j_max, key, len_ini, len_j, max_reach, ok, pix_count, reach, use_color_cache, v3, v4, v6 int32
  18746 	var retval, v14 PixOrCopy
  18747 	var v2 uintptr
  18748 	var v18 uint32_t
  18749 	var _ /* hashers at bp+0 */ VP8LColorCache
  18750 	var _ /* len at bp+20 */ int32
  18751 	var _ /* offset at bp+16 */ int32
  18752 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cc_init, i, i_last_check, j, j_max, key, len_ini, len_j, max_reach, ok, pix_count, reach, retval, use_color_cache, v14, v18, v2, v3, v4, v6
  18753 	i_last_check = -int32(1)
  18754 	ok = 0
  18755 	cc_init = 0
  18756 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18757 	pix_count = xsize * ysize
  18758 	if use_color_cache != 0 {
  18759 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  18760 		if !(cc_init != 0) {
  18761 			goto Error
  18762 		}
  18763 	}
  18764 	VP8LClearBackwardRefs(tls, refs)
  18765 	i = 0
  18766 	for {
  18767 		if !(i < pix_count) {
  18768 			break
  18769 		}
  18770 		// Alternative#1: Code the pixels starting at 'i' using backward reference.
  18771 		**(**int32)(__ccgo_up(bp + 16)) = 0
  18772 		**(**int32)(__ccgo_up(bp + 20)) = 0
  18773 		v2 = hash_chain
  18774 		v3 = i
  18775 		v4 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v2)).Foffset_length + uintptr(v3)*4)) >> int32(MAX_LENGTH_BITS))
  18776 		goto _5
  18777 	_5:
  18778 		**(**int32)(__ccgo_up(bp + 16)) = v4
  18779 		v6 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v2)).Foffset_length + uintptr(v3)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  18780 		goto _7
  18781 	_7:
  18782 		**(**int32)(__ccgo_up(bp + 20)) = v6
  18783 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(MIN_LENGTH) {
  18784 			len_ini = **(**int32)(__ccgo_up(bp + 20))
  18785 			max_reach = 0
  18786 			if i+len_ini >= pix_count {
  18787 				v3 = pix_count - int32(1)
  18788 			} else {
  18789 				v3 = i + len_ini
  18790 			}
  18791 			j_max = v3
  18792 			// Only start from what we have not checked already.
  18793 			if i > i_last_check {
  18794 				v4 = i
  18795 			} else {
  18796 				v4 = i_last_check
  18797 			}
  18798 			i_last_check = v4
  18799 			// We know the best match for the current pixel but we try to find the
  18800 			// best matches for the current pixel AND the next one combined.
  18801 			// The naive method would use the intervals:
  18802 			// [i,i+len) + [i+len, length of best match at i+len)
  18803 			// while we check if we can use:
  18804 			// [i,j) (where j<=i+len) + [j, length of best match at j)
  18805 			j = i_last_check + int32(1)
  18806 			for {
  18807 				if !(j <= j_max) {
  18808 					break
  18809 				}
  18810 				v3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(j)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  18811 				goto _12
  18812 			_12:
  18813 				len_j = v3
  18814 				if len_j >= int32(MIN_LENGTH) {
  18815 					v4 = len_j
  18816 				} else {
  18817 					v4 = int32(1)
  18818 				}
  18819 				reach = j + v4 // 1 for single literal.
  18820 				if reach > max_reach {
  18821 					**(**int32)(__ccgo_up(bp + 20)) = j - i
  18822 					max_reach = reach
  18823 					if max_reach >= pix_count {
  18824 						break
  18825 					}
  18826 				}
  18827 				goto _10
  18828 			_10:
  18829 				;
  18830 				j = j + 1
  18831 			}
  18832 		} else {
  18833 			**(**int32)(__ccgo_up(bp + 20)) = int32(1)
  18834 		}
  18835 		// Go with literal or backward reference.
  18836 		if **(**int32)(__ccgo_up(bp + 20)) == int32(1) {
  18837 			AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  18838 		} else {
  18839 			retval.Fmode = uint8(kCopy)
  18840 			retval.Fargb_or_distance = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 16)))
  18841 			retval.Flen1 = libc.Uint16FromInt32(**(**int32)(__ccgo_up(bp + 20)))
  18842 			v14 = retval
  18843 			goto _15
  18844 		_15:
  18845 			VP8LBackwardRefsCursorAdd(tls, refs, v14)
  18846 			if use_color_cache != 0 {
  18847 				j = i
  18848 				for {
  18849 					if !(j < i+**(**int32)(__ccgo_up(bp + 20))) {
  18850 						break
  18851 					}
  18852 					v2 = bp
  18853 					v18 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(j)*4))
  18854 					v3 = libc.Int32FromUint32(v18 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  18855 					goto _20
  18856 				_20:
  18857 					key = v3
  18858 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v18
  18859 					goto _16
  18860 				_16:
  18861 					;
  18862 					j = j + 1
  18863 				}
  18864 			}
  18865 		}
  18866 		i = i + **(**int32)(__ccgo_up(bp + 20))
  18867 		goto _1
  18868 	_1:
  18869 	}
  18870 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18871 	goto Error
  18872 Error:
  18873 	;
  18874 	if cc_init != 0 {
  18875 		VP8LColorCacheClear(tls, bp)
  18876 	}
  18877 	return ok
  18878 }
  18879 
  18880 // C documentation
  18881 //
  18882 //	// Compute an LZ77 by forcing matches to happen within a given distance cost.
  18883 //	// We therefore limit the algorithm to the lowest 32 values in the PlaneCode
  18884 //	// definition.
  18885 func BackwardReferencesLz77Box(tls *libc.TLS, xsize int32, ysize int32, argb uintptr, cache_bits int32, hash_chain_best uintptr, hash_chain uintptr, refs uintptr) (r int32) {
  18886 	var best_length, best_length_prev, best_offset, best_offset_prev, counts_j, counts_j_offset, curr_length, do_compute, i, ind, is_reachable, j, j1, j_offset, num_ind, offset, pix_count, plane_code, use_prev, window_offsets_new_size, window_offsets_size, x, y, v5, v9 int32
  18887 	var counts, counts_ini uintptr
  18888 	var window_offsets, window_offsets_new [32]int32
  18889 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_length, best_length_prev, best_offset, best_offset_prev, counts, counts_ini, counts_j, counts_j_offset, curr_length, do_compute, i, ind, is_reachable, j, j1, j_offset, num_ind, offset, pix_count, plane_code, use_prev, window_offsets, window_offsets_new, window_offsets_new_size, window_offsets_size, x, y, v5, v9
  18890 	pix_count = xsize * ysize
  18891 	window_offsets = [32]int32{}
  18892 	window_offsets_new = [32]int32{}
  18893 	window_offsets_size = 0
  18894 	window_offsets_new_size = 0
  18895 	counts_ini = WebPSafeMalloc(tls, libc.Uint64FromInt32(xsize*ysize), uint64(2))
  18896 	best_offset_prev = -int32(1)
  18897 	best_length_prev = -int32(1)
  18898 	if counts_ini == libc.UintptrFromInt32(0) {
  18899 		return 0
  18900 	}
  18901 	// counts[i] counts how many times a pixel is repeated starting at position i.
  18902 	i = pix_count - int32(2)
  18903 	counts = counts_ini + uintptr(i)*2
  18904 	**(**uint16_t)(__ccgo_up(counts + 1*2)) = uint16(1)
  18905 	for {
  18906 		if !(i >= 0) {
  18907 			break
  18908 		}
  18909 		if **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(i+int32(1))*4)) {
  18910 			// Max out the counts to MAX_LENGTH.
  18911 			**(**uint16_t)(__ccgo_up(counts)) = libc.Uint16FromInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(counts + 1*2))) + libc.BoolInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(counts + 1*2))) != libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)))
  18912 		} else {
  18913 			**(**uint16_t)(__ccgo_up(counts)) = uint16(1)
  18914 		}
  18915 		goto _1
  18916 	_1:
  18917 		;
  18918 		i = i - 1
  18919 		counts -= 2
  18920 	}
  18921 	// Figure out the window offsets around a pixel. They are stored in a
  18922 	// spiraling order around the pixel as defined by VP8LDistanceToPlaneCode.
  18923 	y = 0
  18924 	for {
  18925 		if !(y <= int32(6)) {
  18926 			break
  18927 		}
  18928 		x = -int32(6)
  18929 		for {
  18930 			if !(x <= int32(6)) {
  18931 				break
  18932 			}
  18933 			offset = y*xsize + x
  18934 			// Ignore offsets that bring us after the pixel.
  18935 			if offset <= 0 {
  18936 				goto _3
  18937 			}
  18938 			plane_code = VP8LDistanceToPlaneCode(tls, xsize, offset) - int32(1)
  18939 			if plane_code >= int32(WINDOW_OFFSETS_SIZE_MAX) {
  18940 				goto _3
  18941 			}
  18942 			window_offsets[plane_code] = offset
  18943 			goto _3
  18944 		_3:
  18945 			;
  18946 			x = x + 1
  18947 		}
  18948 		goto _2
  18949 	_2:
  18950 		;
  18951 		y = y + 1
  18952 	}
  18953 	// For narrow images, not all plane codes are reached, so remove those.
  18954 	i = 0
  18955 	for {
  18956 		if !(i < int32(WINDOW_OFFSETS_SIZE_MAX)) {
  18957 			break
  18958 		}
  18959 		if window_offsets[i] == 0 {
  18960 			goto _4
  18961 		}
  18962 		v5 = window_offsets_size
  18963 		window_offsets_size = window_offsets_size + 1
  18964 		window_offsets[v5] = window_offsets[i]
  18965 		goto _4
  18966 	_4:
  18967 		;
  18968 		i = i + 1
  18969 	}
  18970 	// Given a pixel P, find the offsets that reach pixels unreachable from P-1
  18971 	// with any of the offsets in window_offsets[].
  18972 	i = 0
  18973 	for {
  18974 		if !(i < window_offsets_size) {
  18975 			break
  18976 		}
  18977 		is_reachable = 0
  18978 		j = 0
  18979 		for {
  18980 			if !(j < window_offsets_size && !(is_reachable != 0)) {
  18981 				break
  18982 			}
  18983 			is_reachable = is_reachable | libc.BoolInt32(window_offsets[i] == window_offsets[j]+int32(1))
  18984 			goto _7
  18985 		_7:
  18986 			;
  18987 			j = j + 1
  18988 		}
  18989 		if !(is_reachable != 0) {
  18990 			window_offsets_new[window_offsets_new_size] = window_offsets[i]
  18991 			window_offsets_new_size = window_offsets_new_size + 1
  18992 		}
  18993 		goto _6
  18994 	_6:
  18995 		;
  18996 		i = i + 1
  18997 	}
  18998 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  18999 	i = int32(1)
  19000 	for {
  19001 		if !(i < pix_count) {
  19002 			break
  19003 		}
  19004 		v5 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain_best)).Foffset_length + uintptr(i)*4)) & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Uint32FromInt32(1)))
  19005 		goto _10
  19006 	_10:
  19007 		best_length = v5
  19008 		do_compute = int32(1)
  19009 		if best_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19010 			// Do not recompute the best match if we already have a maximal one in the
  19011 			// window.
  19012 			v9 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain_best)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  19013 			goto _12
  19014 		_12:
  19015 			best_offset = v9
  19016 			ind = 0
  19017 			for {
  19018 				if !(ind < window_offsets_size) {
  19019 					break
  19020 				}
  19021 				if best_offset == window_offsets[ind] {
  19022 					do_compute = 0
  19023 					break
  19024 				}
  19025 				goto _13
  19026 			_13:
  19027 				;
  19028 				ind = ind + 1
  19029 			}
  19030 		}
  19031 		if do_compute != 0 {
  19032 			// Figure out if we should use the offset/length from the previous pixel
  19033 			// as an initial guess and therefore only inspect the offsets in
  19034 			// window_offsets_new[].
  19035 			use_prev = libc.BoolInt32(best_length_prev > int32(1) && best_length_prev < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))
  19036 			if use_prev != 0 {
  19037 				v5 = window_offsets_new_size
  19038 			} else {
  19039 				v5 = window_offsets_size
  19040 			}
  19041 			num_ind = v5
  19042 			if use_prev != 0 {
  19043 				v9 = best_length_prev - int32(1)
  19044 			} else {
  19045 				v9 = 0
  19046 			}
  19047 			best_length = v9
  19048 			if use_prev != 0 {
  19049 				v5 = best_offset_prev
  19050 			} else {
  19051 				v5 = 0
  19052 			}
  19053 			best_offset = v5
  19054 			// Find the longest match in a window around the pixel.
  19055 			ind = 0
  19056 			for {
  19057 				if !(ind < num_ind) {
  19058 					break
  19059 				}
  19060 				curr_length = 0
  19061 				j1 = i
  19062 				if use_prev != 0 {
  19063 					v5 = i - window_offsets_new[ind]
  19064 				} else {
  19065 					v5 = i - window_offsets[ind]
  19066 				}
  19067 				j_offset = v5
  19068 				if j_offset < 0 || **(**uint32_t)(__ccgo_up(argb + uintptr(j_offset)*4)) != **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) {
  19069 					goto _17
  19070 				}
  19071 				// The longest match is the sum of how many times each pixel is
  19072 				// repeated.
  19073 				for cond := true; cond; cond = curr_length <= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) && j1 < pix_count && **(**uint32_t)(__ccgo_up(argb + uintptr(j_offset)*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(j1)*4)) {
  19074 					counts_j_offset = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j_offset)*2)))
  19075 					counts_j = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j1)*2)))
  19076 					if counts_j_offset != counts_j {
  19077 						if counts_j_offset < counts_j {
  19078 							v5 = counts_j_offset
  19079 						} else {
  19080 							v5 = counts_j
  19081 						}
  19082 						curr_length = curr_length + v5
  19083 						break
  19084 					}
  19085 					// The same color is repeated counts_pos times at j_offset and j.
  19086 					curr_length = curr_length + counts_j_offset
  19087 					j_offset = j_offset + counts_j_offset
  19088 					j1 = j1 + counts_j_offset
  19089 				}
  19090 				if best_length < curr_length {
  19091 					if use_prev != 0 {
  19092 						v5 = window_offsets_new[ind]
  19093 					} else {
  19094 						v5 = window_offsets[ind]
  19095 					}
  19096 					best_offset = v5
  19097 					if curr_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19098 						best_length = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  19099 						break
  19100 					} else {
  19101 						best_length = curr_length
  19102 					}
  19103 				}
  19104 				goto _17
  19105 			_17:
  19106 				;
  19107 				ind = ind + 1
  19108 			}
  19109 		}
  19110 		if best_length <= int32(MIN_LENGTH) {
  19111 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) = uint32(0)
  19112 			best_offset_prev = 0
  19113 			best_length_prev = 0
  19114 		} else {
  19115 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) = libc.Uint32FromInt32(best_offset<<libc.Int32FromInt32(MAX_LENGTH_BITS)) | libc.Uint32FromInt32(best_length)
  19116 			best_offset_prev = best_offset
  19117 			best_length_prev = best_length
  19118 		}
  19119 		goto _8
  19120 	_8:
  19121 		;
  19122 		i = i + 1
  19123 	}
  19124 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19125 	WebPSafeFree(tls, counts_ini)
  19126 	return BackwardReferencesLz77(tls, xsize, ysize, argb, cache_bits, hash_chain, refs)
  19127 }
  19128 
  19129 // -----------------------------------------------------------------------------
  19130 
  19131 func BackwardReferences2DLocality(tls *libc.TLS, xsize int32, refs uintptr) {
  19132 	bp := tls.Alloc(32)
  19133 	defer tls.Free(32)
  19134 	var dist, transformed_dist, v1, v3 int32
  19135 	var v5, v6, v7 uintptr
  19136 	var _ /* c at bp+0 */ VP8LRefsCursor
  19137 	_, _, _, _, _, _, _ = dist, transformed_dist, v1, v3, v5, v6, v7
  19138 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  19139 	for {
  19140 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  19141 		goto _2
  19142 	_2:
  19143 		if !(v1 != 0) {
  19144 			break
  19145 		}
  19146 		v3 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fmode) == int32(kCopy))
  19147 		goto _4
  19148 	_4:
  19149 		if v3 != 0 {
  19150 			dist = libc.Int32FromUint32((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance)
  19151 			transformed_dist = VP8LDistanceToPlaneCode(tls, xsize, dist)
  19152 			(*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance = libc.Uint32FromInt32(transformed_dist)
  19153 		}
  19154 		v5 = bp
  19155 		v7 = v5
  19156 		*(*uintptr)(unsafe.Pointer(v7)) += 8
  19157 		v6 = *(*uintptr)(unsafe.Pointer(v7))
  19158 		if v6 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19159 			VP8LRefsCursorNextBlock(tls, v5)
  19160 		}
  19161 	}
  19162 }
  19163 
  19164 // C documentation
  19165 //
  19166 //	// Evaluate optimal cache bits for the local color cache.
  19167 //	// The input *best_cache_bits sets the maximum cache bits to use (passing 0
  19168 //	// implies disabling the local color cache). The local color cache is also
  19169 //	// disabled for the lower (<= 25) quality.
  19170 //	// Returns 0 in case of memory error.
  19171 func CalculateBestCacheSize(tls *libc.TLS, argb2 uintptr, quality int32, refs uintptr, best_cache_bits uintptr) (r1 int32) {
  19172 	bp := tls.Alloc(224)
  19173 	defer tls.Free(224)
  19174 	var a, argb_prev, b, g, pix, r, v11 uint32_t
  19175 	var cache_bits_max, highest_bit, i, key2, key3, len1, ok, second_highest_bit, v1, v3, v5, v8 int32
  19176 	var cc_init [11]int32
  19177 	var entropy, entropy_min uint64_t
  19178 	var histos [11]uintptr
  19179 	var prefix_code VP8LPrefixCode
  19180 	var v, v16, v17, v18, v7 uintptr
  19181 	var _ /* c at bp+176 */ VP8LRefsCursor
  19182 	var _ /* code at bp+200 */ int32
  19183 	var _ /* extra_bits at bp+204 */ int32
  19184 	var _ /* extra_bits_value at bp+208 */ int32
  19185 	var _ /* hashers at bp+0 */ [11]VP8LColorCache
  19186 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, argb_prev, b, cache_bits_max, cc_init, entropy, entropy_min, g, highest_bit, histos, i, key2, key3, len1, ok, pix, prefix_code, r, second_highest_bit, v, v1, v11, v16, v17, v18, v3, v5, v7, v8
  19187 	if quality <= int32(25) {
  19188 		v1 = 0
  19189 	} else {
  19190 		v1 = **(**int32)(__ccgo_up(best_cache_bits))
  19191 	}
  19192 	cache_bits_max = v1
  19193 	entropy_min = uint64(^libc.Uint64FromUint64(0))
  19194 	cc_init = [11]int32{}
  19195 	**(**VP8LRefsCursor)(__ccgo_up(bp + 176)) = VP8LRefsCursorInit(tls, refs)
  19196 	histos = [11]uintptr{}
  19197 	ok = 0
  19198 	if cache_bits_max == 0 {
  19199 		**(**int32)(__ccgo_up(best_cache_bits)) = 0
  19200 		// Local color cache is disabled.
  19201 		return int32(1)
  19202 	}
  19203 	// Allocate data.
  19204 	i = 0
  19205 	for {
  19206 		if !(i <= cache_bits_max) {
  19207 			break
  19208 		}
  19209 		histos[i] = VP8LAllocateHistogram(tls, i)
  19210 		if histos[i] == libc.UintptrFromInt32(0) {
  19211 			goto Error
  19212 		}
  19213 		VP8LHistogramInit(tls, histos[i], i, int32(1))
  19214 		if i == 0 {
  19215 			goto _2
  19216 		}
  19217 		cc_init[i] = VP8LColorCacheInit(tls, bp+uintptr(i)*16, i)
  19218 		if !(cc_init[i] != 0) {
  19219 			goto Error
  19220 		}
  19221 		goto _2
  19222 	_2:
  19223 		;
  19224 		i = i + 1
  19225 	}
  19226 	// Find the cache_bits giving the lowest entropy. The search is done in a
  19227 	// brute-force way as the function (entropy w.r.t cache_bits) can be
  19228 	// anything in practice.
  19229 	for {
  19230 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+176)).Fcur_pos != libc.UintptrFromInt32(0))
  19231 		goto _4
  19232 	_4:
  19233 		if !(v1 != 0) {
  19234 			break
  19235 		}
  19236 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 176))).Fcur_pos
  19237 		v3 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19238 		goto _6
  19239 	_6:
  19240 		if v3 != 0 {
  19241 			v7 = argb2
  19242 			argb2 += 4
  19243 			pix = **(**uint32_t)(__ccgo_up(v7))
  19244 			a = pix >> libc.Int32FromInt32(24) & uint32(0xff)
  19245 			r = pix >> libc.Int32FromInt32(16) & uint32(0xff)
  19246 			g = pix >> libc.Int32FromInt32(8) & uint32(0xff)
  19247 			b = pix >> libc.Int32FromInt32(0) & uint32(0xff)
  19248 			v5 = libc.Int32FromUint32(pix * kHashMul11 >> (int32(32) - cache_bits_max))
  19249 			goto _9
  19250 		_9:
  19251 			// The keys of the caches can be derived from the longest one.
  19252 			key2 = v5
  19253 			// Do not use the color cache for cache_bits = 0.
  19254 			**(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) + 1
  19255 			**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[0])).Fliteral + uintptr(g)*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[0])).Fliteral + uintptr(g)*4)) + 1
  19256 			**(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) + 1
  19257 			**(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) + 1
  19258 			// Deal with cache_bits > 0.
  19259 			i = cache_bits_max
  19260 			for {
  19261 				if !(i >= int32(1)) {
  19262 					break
  19263 				}
  19264 				v11 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(libc.Uint32FromInt32(key2))*4))
  19265 				goto _12
  19266 			_12:
  19267 				if v11 == pix {
  19268 					**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[i])).Fliteral + uintptr(libc.Int32FromInt32(NUM_LITERAL_CODES)+libc.Int32FromInt32(NUM_LENGTH_CODES)+key2)*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[i])).Fliteral + uintptr(libc.Int32FromInt32(NUM_LITERAL_CODES)+libc.Int32FromInt32(NUM_LENGTH_CODES)+key2)*4)) + 1
  19269 				} else {
  19270 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(libc.Uint32FromInt32(key2))*4)) = pix
  19271 					**(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) + 1
  19272 					**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[i])).Fliteral + uintptr(g)*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[i])).Fliteral + uintptr(g)*4)) + 1
  19273 					**(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) + 1
  19274 					**(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) + 1
  19275 				}
  19276 				goto _10
  19277 			_10:
  19278 				;
  19279 				i = i - 1
  19280 				key2 = key2 >> int32(1)
  19281 			}
  19282 		} else {
  19283 			v11 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  19284 			goto _14
  19285 		_14:
  19286 			// We should compute the contribution of the (distance,length)
  19287 			// histograms but those are the same independently from the cache size.
  19288 			// As those constant contributions are in the end added to the other
  19289 			// histogram contributions, we can ignore them, except for the length
  19290 			// prefix that is part of the 'literal' histogram.
  19291 			len1 = libc.Int32FromUint32(v11)
  19292 			argb_prev = **(**uint32_t)(__ccgo_up(argb2)) ^ uint32(0xffffffff)
  19293 			v1 = len1
  19294 			v7 = bp + 200
  19295 			v16 = bp + 204
  19296 			v17 = bp + 208
  19297 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  19298 				prefix_code = kPrefixEncodeCode[v1]
  19299 				**(**int32)(__ccgo_up(v7)) = int32(prefix_code.Fcode)
  19300 				**(**int32)(__ccgo_up(v16)) = int32(prefix_code.Fextra_bits)
  19301 				**(**int32)(__ccgo_up(v17)) = libc.Int32FromUint8(kPrefixEncodeExtraBitsValue[v1])
  19302 			} else {
  19303 				v3 = v1
  19304 				v18 = v16
  19305 				v3 = v3 - 1
  19306 				v5 = v3
  19307 				v8 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v5))
  19308 				goto _23
  19309 			_23:
  19310 				highest_bit = v8
  19311 				second_highest_bit = v3 >> (highest_bit - int32(1)) & int32(1)
  19312 				**(**int32)(__ccgo_up(v18)) = highest_bit - int32(1)
  19313 				**(**int32)(__ccgo_up(v17)) = v3 & (int32(1)<<**(**int32)(__ccgo_up(v18)) - int32(1))
  19314 				**(**int32)(__ccgo_up(v7)) = int32(2)*highest_bit + second_highest_bit
  19315 			}
  19316 			i = 0
  19317 			for {
  19318 				if !(i <= cache_bits_max) {
  19319 					break
  19320 				}
  19321 				**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[i])).Fliteral + uintptr(int32(NUM_LITERAL_CODES)+**(**int32)(__ccgo_up(bp + 200)))*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histos[i])).Fliteral + uintptr(int32(NUM_LITERAL_CODES)+**(**int32)(__ccgo_up(bp + 200)))*4)) + 1
  19322 				goto _24
  19323 			_24:
  19324 				;
  19325 				i = i + 1
  19326 			}
  19327 			// Update the color caches.
  19328 			for {
  19329 				if **(**uint32_t)(__ccgo_up(argb2)) != argb_prev {
  19330 					v3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb2)) * kHashMul11 >> (int32(32) - cache_bits_max))
  19331 					goto _28
  19332 				_28:
  19333 					// Efficiency: insert only if the color changes.
  19334 					key3 = v3
  19335 					i = cache_bits_max
  19336 					for {
  19337 						if !(i >= int32(1)) {
  19338 							break
  19339 						}
  19340 						**(**uint32_t)(__ccgo_up((**(**[11]VP8LColorCache)(__ccgo_up(bp)))[i].Fcolors + uintptr(key3)*4)) = **(**uint32_t)(__ccgo_up(argb2))
  19341 						goto _29
  19342 					_29:
  19343 						;
  19344 						i = i - 1
  19345 						key3 = key3 >> int32(1)
  19346 					}
  19347 					argb_prev = **(**uint32_t)(__ccgo_up(argb2))
  19348 				}
  19349 				argb2 += 4
  19350 				goto _26
  19351 			_26:
  19352 				;
  19353 				len1 = len1 - 1
  19354 				v1 = len1
  19355 				if !(v1 != 0) {
  19356 					break
  19357 				}
  19358 			}
  19359 		}
  19360 		v7 = bp + 176
  19361 		v17 = v7
  19362 		*(*uintptr)(unsafe.Pointer(v17)) += 8
  19363 		v16 = *(*uintptr)(unsafe.Pointer(v17))
  19364 		if v16 == (*VP8LRefsCursor)(unsafe.Pointer(v7)).Flast_pos {
  19365 			VP8LRefsCursorNextBlock(tls, v7)
  19366 		}
  19367 	}
  19368 	i = 0
  19369 	for {
  19370 		if !(i <= cache_bits_max) {
  19371 			break
  19372 		}
  19373 		entropy = VP8LHistogramEstimateBits(tls, histos[i])
  19374 		if i == 0 || entropy < entropy_min {
  19375 			entropy_min = entropy
  19376 			**(**int32)(__ccgo_up(best_cache_bits)) = i
  19377 		}
  19378 		goto _33
  19379 	_33:
  19380 		;
  19381 		i = i + 1
  19382 	}
  19383 	ok = int32(1)
  19384 	goto Error
  19385 Error:
  19386 	;
  19387 	i = 0
  19388 	for {
  19389 		if !(i <= cache_bits_max) {
  19390 			break
  19391 		}
  19392 		if cc_init[i] != 0 {
  19393 			VP8LColorCacheClear(tls, bp+uintptr(i)*16)
  19394 		}
  19395 		VP8LFreeHistogram(tls, histos[i])
  19396 		goto _34
  19397 	_34:
  19398 		;
  19399 		i = i + 1
  19400 	}
  19401 	return ok
  19402 }
  19403 
  19404 // C documentation
  19405 //
  19406 //	// Update (in-place) backward references for specified cache_bits.
  19407 func BackwardRefsWithLocalCache(tls *libc.TLS, argb3 uintptr, cache_bits int32, refs uintptr) (r int32) {
  19408 	bp := tls.Alloc(48)
  19409 	defer tls.Free(48)
  19410 	var argb_literal, v6 uint32_t
  19411 	var ix, k, key, key1, pixel_index, v1, v11, v3, v7, v9 int32
  19412 	var retval, v12 PixOrCopy
  19413 	var v, v14, v20, v5 uintptr
  19414 	var _ /* c at bp+16 */ VP8LRefsCursor
  19415 	var _ /* hashers at bp+0 */ VP8LColorCache
  19416 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_literal, ix, k, key, key1, pixel_index, retval, v, v1, v11, v12, v14, v20, v3, v5, v6, v7, v9
  19417 	pixel_index = 0
  19418 	**(**VP8LRefsCursor)(__ccgo_up(bp + 16)) = VP8LRefsCursorInit(tls, refs)
  19419 	if !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  19420 		return 0
  19421 	}
  19422 	for {
  19423 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+16)).Fcur_pos != libc.UintptrFromInt32(0))
  19424 		goto _2
  19425 	_2:
  19426 		if !(v1 != 0) {
  19427 			break
  19428 		}
  19429 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 16))).Fcur_pos
  19430 		v3 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19431 		goto _4
  19432 	_4:
  19433 		if v3 != 0 {
  19434 			argb_literal = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  19435 			v5 = bp
  19436 			v6 = argb_literal
  19437 			v7 = libc.Int32FromUint32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19438 			goto _8
  19439 		_8:
  19440 			key1 = v7
  19441 			if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key1)*4)) == v6 {
  19442 				v11 = key1
  19443 			} else {
  19444 				v11 = -int32(1)
  19445 			}
  19446 			v9 = v11
  19447 			goto _10
  19448 		_10:
  19449 			ix = v9
  19450 			if ix >= 0 {
  19451 				// hashers contains argb_literal
  19452 				retval.Fmode = uint8(kCacheIdx)
  19453 				retval.Fargb_or_distance = libc.Uint32FromInt32(ix)
  19454 				retval.Flen1 = uint16(1)
  19455 				v12 = retval
  19456 				goto _13
  19457 			_13:
  19458 				**(**PixOrCopy)(__ccgo_up(v)) = v12
  19459 			} else {
  19460 				v5 = bp
  19461 				v6 = argb_literal
  19462 				v1 = libc.Int32FromUint32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19463 				goto _17
  19464 			_17:
  19465 				key = v1
  19466 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19467 			}
  19468 			pixel_index = pixel_index + 1
  19469 		} else {
  19470 			k = 0
  19471 			for {
  19472 				if !(k < libc.Int32FromUint16((*PixOrCopy)(unsafe.Pointer(v)).Flen1)) {
  19473 					break
  19474 				}
  19475 				v1 = pixel_index
  19476 				pixel_index = pixel_index + 1
  19477 				v5 = bp
  19478 				v6 = **(**uint32_t)(__ccgo_up(argb3 + uintptr(v1)*4))
  19479 				v3 = libc.Int32FromUint32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19480 				goto _23
  19481 			_23:
  19482 				key = v3
  19483 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19484 				goto _18
  19485 			_18:
  19486 				;
  19487 				k = k + 1
  19488 			}
  19489 		}
  19490 		v5 = bp + 16
  19491 		v20 = v5
  19492 		*(*uintptr)(unsafe.Pointer(v20)) += 8
  19493 		v14 = *(*uintptr)(unsafe.Pointer(v20))
  19494 		if v14 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19495 			VP8LRefsCursorNextBlock(tls, v5)
  19496 		}
  19497 	}
  19498 	VP8LColorCacheClear(tls, bp)
  19499 	return int32(1)
  19500 }
  19501 
  19502 func GetBackwardReferencesLowEffort(tls *libc.TLS, width int32, height int32, argb uintptr, cache_bits uintptr, hash_chain uintptr, refs_lz77 uintptr) (r uintptr) {
  19503 	**(**int32)(__ccgo_up(cache_bits)) = 0
  19504 	if !(BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_lz77) != 0) {
  19505 		return libc.UintptrFromInt32(0)
  19506 	}
  19507 	BackwardReferences2DLocality(tls, width, refs_lz77)
  19508 	return refs_lz77
  19509 }
  19510 
  19511 func GetBackwardReferences(tls *libc.TLS, width int32, height int32, argb uintptr, quality int32, lz77_types_to_try int32, cache_bits_max int32, do_no_cache int32, hash_chain uintptr, refs uintptr, cache_bits_best uintptr) (r int32) {
  19512 	bp := tls.Alloc(32)
  19513 	defer tls.Free(32)
  19514 	var bit_cost, bit_cost_trace uint64_t
  19515 	var bit_costs_best [2]uint64_t
  19516 	var cache_bits1, i, lz77_type, res, status, v1 int32
  19517 	var hash_chain_tmp, histo, refs_tmp, v6 uintptr
  19518 	var lz77_types_best [2]int32
  19519 	var _ /* cache_bits at bp+16 */ int32
  19520 	var _ /* hash_chain_box at bp+0 */ VP8LHashChain
  19521 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit_cost, bit_cost_trace, bit_costs_best, cache_bits1, hash_chain_tmp, histo, i, lz77_type, lz77_types_best, refs_tmp, res, status, v1, v6
  19522 	histo = libc.UintptrFromInt32(0)
  19523 	// Index 0 is for a color cache, index 1 for no cache (if needed).
  19524 	lz77_types_best = [2]int32{}
  19525 	bit_costs_best = [2]uint64_t{
  19526 		0: uint64(^libc.Uint64FromUint64(0)),
  19527 		1: uint64(^libc.Uint64FromUint64(0)),
  19528 	}
  19529 	if do_no_cache != 0 {
  19530 		v1 = int32(2)
  19531 	} else {
  19532 		v1 = int32(1)
  19533 	}
  19534 	refs_tmp = refs + uintptr(v1)*40
  19535 	status = 0
  19536 	libc.Xmemset(tls, bp, 0, uint64(16))
  19537 	histo = VP8LAllocateHistogram(tls, int32(MAX_COLOR_CACHE_BITS))
  19538 	if histo == libc.UintptrFromInt32(0) {
  19539 		goto Error
  19540 	}
  19541 	lz77_type = int32(1)
  19542 	for {
  19543 		if !(lz77_types_to_try != 0) {
  19544 			break
  19545 		}
  19546 		res = 0
  19547 		bit_cost = 0
  19548 		if lz77_types_to_try&lz77_type == 0 {
  19549 			goto _2
  19550 		}
  19551 		switch lz77_type {
  19552 		case int32(kLZ77RLE):
  19553 			res = BackwardReferencesRle(tls, width, height, argb, 0, refs_tmp)
  19554 		case int32(kLZ77Standard):
  19555 			// Compute LZ77 with no cache (0 bits), as the ideal LZ77 with a color
  19556 			// cache is not that different in practice.
  19557 			res = BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_tmp)
  19558 		case int32(kLZ77Box):
  19559 			if !(VP8LHashChainInit(tls, bp, width*height) != 0) {
  19560 				goto Error
  19561 			}
  19562 			res = BackwardReferencesLz77Box(tls, width, height, argb, 0, hash_chain, bp, refs_tmp)
  19563 		default:
  19564 		}
  19565 		if !(res != 0) {
  19566 			goto Error
  19567 		}
  19568 		// Start with the no color cache case.
  19569 		i = int32(1)
  19570 		for {
  19571 			if !(i >= 0) {
  19572 				break
  19573 			}
  19574 			if i == int32(1) {
  19575 				v1 = 0
  19576 			} else {
  19577 				v1 = cache_bits_max
  19578 			}
  19579 			**(**int32)(__ccgo_up(bp + 16)) = v1
  19580 			if i == int32(1) && !(do_no_cache != 0) {
  19581 				goto _3
  19582 			}
  19583 			if i == 0 {
  19584 				// Try with a color cache.
  19585 				if !(CalculateBestCacheSize(tls, argb, quality, refs_tmp, bp+16) != 0) {
  19586 					goto Error
  19587 				}
  19588 				if **(**int32)(__ccgo_up(bp + 16)) > 0 {
  19589 					if !(BackwardRefsWithLocalCache(tls, argb, **(**int32)(__ccgo_up(bp + 16)), refs_tmp) != 0) {
  19590 						goto Error
  19591 					}
  19592 				}
  19593 			}
  19594 			if i == 0 && do_no_cache != 0 && **(**int32)(__ccgo_up(bp + 16)) == 0 {
  19595 				// No need to re-compute bit_cost as it was computed at i == 1.
  19596 			} else {
  19597 				VP8LHistogramCreate(tls, histo, refs_tmp, **(**int32)(__ccgo_up(bp + 16)))
  19598 				bit_cost = VP8LHistogramEstimateBits(tls, histo)
  19599 			}
  19600 			if bit_cost < bit_costs_best[i] {
  19601 				if i == int32(1) {
  19602 					// Do not swap as the full cache analysis would have the wrong
  19603 					// VP8LBackwardRefs to start with.
  19604 					if !(BackwardRefsClone(tls, refs_tmp, refs+1*40) != 0) {
  19605 						goto Error
  19606 					}
  19607 				} else {
  19608 					BackwardRefsSwap(tls, refs_tmp, refs)
  19609 				}
  19610 				bit_costs_best[i] = bit_cost
  19611 				lz77_types_best[i] = lz77_type
  19612 				if i == 0 {
  19613 					**(**int32)(__ccgo_up(cache_bits_best)) = **(**int32)(__ccgo_up(bp + 16))
  19614 				}
  19615 			}
  19616 			goto _3
  19617 		_3:
  19618 			;
  19619 			i = i - 1
  19620 		}
  19621 		goto _2
  19622 	_2:
  19623 		;
  19624 		lz77_types_to_try = lz77_types_to_try & ^lz77_type
  19625 		lz77_type = lz77_type << int32(1)
  19626 	}
  19627 	// Improve on simple LZ77 but only for high quality (TraceBackwards is
  19628 	// costly).
  19629 	i = int32(1)
  19630 	for {
  19631 		if !(i >= 0) {
  19632 			break
  19633 		}
  19634 		if i == int32(1) && !(do_no_cache != 0) {
  19635 			goto _5
  19636 		}
  19637 		if (lz77_types_best[i] == int32(kLZ77Standard) || lz77_types_best[i] == int32(kLZ77Box)) && quality >= int32(25) {
  19638 			if lz77_types_best[i] == int32(kLZ77Standard) {
  19639 				v6 = hash_chain
  19640 			} else {
  19641 				v6 = bp
  19642 			}
  19643 			hash_chain_tmp = v6
  19644 			if i == int32(1) {
  19645 				v1 = 0
  19646 			} else {
  19647 				v1 = **(**int32)(__ccgo_up(cache_bits_best))
  19648 			}
  19649 			cache_bits1 = v1
  19650 			if !(VP8LBackwardReferencesTraceBackwards(tls, width, height, argb, cache_bits1, hash_chain_tmp, refs+uintptr(i)*40, refs_tmp) != 0) {
  19651 				goto Error
  19652 			}
  19653 			VP8LHistogramCreate(tls, histo, refs_tmp, cache_bits1)
  19654 			bit_cost_trace = VP8LHistogramEstimateBits(tls, histo)
  19655 			if bit_cost_trace < bit_costs_best[i] {
  19656 				BackwardRefsSwap(tls, refs_tmp, refs+uintptr(i)*40)
  19657 			}
  19658 		}
  19659 		BackwardReferences2DLocality(tls, width, refs+uintptr(i)*40)
  19660 		if i == int32(1) && lz77_types_best[0] == lz77_types_best[int32(1)] && **(**int32)(__ccgo_up(cache_bits_best)) == 0 {
  19661 			// If the best cache size is 0 and we have the same best LZ77, just copy
  19662 			// the data over and stop here.
  19663 			if !(BackwardRefsClone(tls, refs+1*40, refs) != 0) {
  19664 				goto Error
  19665 			}
  19666 			break
  19667 		}
  19668 		goto _5
  19669 	_5:
  19670 		;
  19671 		i = i - 1
  19672 	}
  19673 	status = int32(1)
  19674 	goto Error
  19675 Error:
  19676 	;
  19677 	VP8LHashChainClear(tls, bp)
  19678 	VP8LFreeHistogram(tls, histo)
  19679 	return status
  19680 }
  19681 
  19682 func VP8LGetBackwardReferences(tls *libc.TLS, width int32, height int32, argb uintptr, quality int32, low_effort int32, lz77_types_to_try int32, cache_bits_max int32, do_no_cache int32, hash_chain uintptr, refs uintptr, cache_bits_best uintptr, pic uintptr, percent_range int32, percent uintptr) (r int32) {
  19683 	var refs_best uintptr
  19684 	_ = refs_best
  19685 	if low_effort != 0 {
  19686 		**(**int32)(__ccgo_up(cache_bits_best)) = cache_bits_max
  19687 		refs_best = GetBackwardReferencesLowEffort(tls, width, height, argb, cache_bits_best, hash_chain, refs)
  19688 		if refs_best == libc.UintptrFromInt32(0) {
  19689 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19690 		}
  19691 		// Set it in first position.
  19692 		BackwardRefsSwap(tls, refs_best, refs)
  19693 	} else {
  19694 		if !(GetBackwardReferences(tls, width, height, argb, quality, lz77_types_to_try, cache_bits_max, do_no_cache, hash_chain, refs, cache_bits_best) != 0) {
  19695 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19696 		}
  19697 	}
  19698 	return WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent)
  19699 }
  19700 
  19701 const MAX_LEVEL1 = 9
  19702 
  19703 //------------------------------------------------------------------------------
  19704 
  19705 // Copyright 2010 Google Inc. All Rights Reserved.
  19706 //
  19707 // Use of this source code is governed by a BSD-style license
  19708 // that can be found in the COPYING file in the root of the source
  19709 // tree. An additional intellectual property rights grant can be found
  19710 // in the file PATENTS. All contributing project authors may
  19711 // be found in the AUTHORS file in the root of the source tree.
  19712 // -----------------------------------------------------------------------------
  19713 //
  19714 //  Common types + memory wrappers
  19715 //
  19716 // Author: Skal (pascal.massimino@gmail.com)
  19717 
  19718 //------------------------------------------------------------------------------
  19719 // WebPConfig
  19720 //------------------------------------------------------------------------------
  19721 
  19722 func WebPConfigInitInternal(tls *libc.TLS, config uintptr, preset WebPPreset1, quality float32, version int32) (r int32) {
  19723 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  19724 		return 0 // caller/system version mismatch!
  19725 	}
  19726 	if config == libc.UintptrFromInt32(0) {
  19727 		return 0
  19728 	}
  19729 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = quality
  19730 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_size = 0
  19731 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR = float32(0)
  19732 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = int32(4)
  19733 	(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(50)
  19734 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(60) // mid-filtering
  19735 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = 0
  19736 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_type = int32(1) // default: strong (so U/V is filtered too)
  19737 	(*WebPConfig)(unsafe.Pointer(config)).Fpartitions = 0
  19738 	(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(4)
  19739 	(*WebPConfig)(unsafe.Pointer(config)).Fpass = int32(1)
  19740 	(*WebPConfig)(unsafe.Pointer(config)).Fqmin = 0
  19741 	(*WebPConfig)(unsafe.Pointer(config)).Fqmax = int32(100)
  19742 	(*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed = 0
  19743 	(*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing = 0
  19744 	(*WebPConfig)(unsafe.Pointer(config)).Fautofilter = 0
  19745 	(*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit = 0
  19746 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_compression = int32(1)
  19747 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering = int32(1)
  19748 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_quality = int32(100)
  19749 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = 0
  19750 	(*WebPConfig)(unsafe.Pointer(config)).Fexact = 0
  19751 	(*WebPConfig)(unsafe.Pointer(config)).Fimage_hint = int32(WEBP_HINT_DEFAULT)
  19752 	(*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size = 0
  19753 	(*WebPConfig)(unsafe.Pointer(config)).Fthread_level = 0
  19754 	(*WebPConfig)(unsafe.Pointer(config)).Flow_memory = 0
  19755 	(*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless = int32(100)
  19756 	(*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv = 0
  19757 	// TODO(skal): tune.
  19758 	switch preset {
  19759 	case int32(WEBP_PRESET_PICTURE):
  19760 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  19761 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(4)
  19762 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(35)
  19763 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  19764 	case int32(WEBP_PRESET_PHOTO):
  19765 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  19766 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(3)
  19767 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(30)
  19768 		**(**int32)(__ccgo_up(config + 68)) |= int32(2)
  19769 	case int32(WEBP_PRESET_DRAWING):
  19770 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(25)
  19771 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(6)
  19772 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(10)
  19773 	case int32(WEBP_PRESET_ICON):
  19774 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  19775 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  19776 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  19777 	case int32(WEBP_PRESET_TEXT):
  19778 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  19779 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  19780 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  19781 		(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(2)
  19782 	case int32(WEBP_PRESET_DEFAULT):
  19783 		fallthrough
  19784 	default:
  19785 		break
  19786 	}
  19787 	return WebPValidateConfig(tls, config)
  19788 }
  19789 
  19790 func WebPValidateConfig(tls *libc.TLS, config uintptr) (r int32) {
  19791 	if config == libc.UintptrFromInt32(0) {
  19792 		return 0
  19793 	}
  19794 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality < libc.Float32FromInt32(0) || (*WebPConfig)(unsafe.Pointer(config)).Fquality > libc.Float32FromInt32(100) {
  19795 		return 0
  19796 	}
  19797 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_size < 0 {
  19798 		return 0
  19799 	}
  19800 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR < libc.Float32FromInt32(0) {
  19801 		return 0
  19802 	}
  19803 	if (*WebPConfig)(unsafe.Pointer(config)).Fmethod < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fmethod > int32(6) {
  19804 		return 0
  19805 	}
  19806 	if (*WebPConfig)(unsafe.Pointer(config)).Fsegments < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fsegments > int32(4) {
  19807 		return 0
  19808 	}
  19809 	if (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength > int32(100) {
  19810 		return 0
  19811 	}
  19812 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > int32(100) {
  19813 		return 0
  19814 	}
  19815 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness > int32(7) {
  19816 		return 0
  19817 	}
  19818 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type > int32(1) {
  19819 		return 0
  19820 	}
  19821 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > int32(1) {
  19822 		return 0
  19823 	}
  19824 	if (*WebPConfig)(unsafe.Pointer(config)).Fpass < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(10) {
  19825 		return 0
  19826 	}
  19827 	if (*WebPConfig)(unsafe.Pointer(config)).Fqmin < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fqmax > int32(100) || (*WebPConfig)(unsafe.Pointer(config)).Fqmin > (*WebPConfig)(unsafe.Pointer(config)).Fqmax {
  19828 		return 0
  19829 	}
  19830 	if (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed > int32(1) {
  19831 		return 0
  19832 	}
  19833 	if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing > int32(7) {
  19834 		return 0
  19835 	}
  19836 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartitions < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartitions > int32(3) {
  19837 		return 0
  19838 	}
  19839 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit > int32(100) {
  19840 		return 0
  19841 	}
  19842 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression < 0 {
  19843 		return 0
  19844 	}
  19845 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering < 0 {
  19846 		return 0
  19847 	}
  19848 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality < 0 || (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality > int32(100) {
  19849 		return 0
  19850 	}
  19851 	if (*WebPConfig)(unsafe.Pointer(config)).Flossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flossless > int32(1) {
  19852 		return 0
  19853 	}
  19854 	if (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless > int32(100) {
  19855 		return 0
  19856 	}
  19857 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint >= int32(WEBP_HINT_LAST) {
  19858 		return 0
  19859 	}
  19860 	if (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size < 0 || (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size > int32(1) {
  19861 		return 0
  19862 	}
  19863 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > int32(1) {
  19864 		return 0
  19865 	}
  19866 	if (*WebPConfig)(unsafe.Pointer(config)).Flow_memory < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flow_memory > int32(1) {
  19867 		return 0
  19868 	}
  19869 	if (*WebPConfig)(unsafe.Pointer(config)).Fexact < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fexact > int32(1) {
  19870 		return 0
  19871 	}
  19872 	if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv > int32(1) {
  19873 		return 0
  19874 	}
  19875 	return int32(1)
  19876 }
  19877 
  19878 //------------------------------------------------------------------------------
  19879 
  19880 // C documentation
  19881 //
  19882 //	// Mapping between -z level and -m / -q parameter settings.
  19883 var kLosslessPresets = [10]struct {
  19884 	Fmethod  uint8_t
  19885 	Fquality uint8_t
  19886 }{
  19887 	0: {},
  19888 	1: {
  19889 		Fmethod:  uint8(1),
  19890 		Fquality: uint8(20),
  19891 	},
  19892 	2: {
  19893 		Fmethod:  uint8(2),
  19894 		Fquality: uint8(25),
  19895 	},
  19896 	3: {
  19897 		Fmethod:  uint8(3),
  19898 		Fquality: uint8(30),
  19899 	},
  19900 	4: {
  19901 		Fmethod:  uint8(3),
  19902 		Fquality: uint8(50),
  19903 	},
  19904 	5: {
  19905 		Fmethod:  uint8(4),
  19906 		Fquality: uint8(50),
  19907 	},
  19908 	6: {
  19909 		Fmethod:  uint8(4),
  19910 		Fquality: uint8(75),
  19911 	},
  19912 	7: {
  19913 		Fmethod:  uint8(4),
  19914 		Fquality: uint8(90),
  19915 	},
  19916 	8: {
  19917 		Fmethod:  uint8(5),
  19918 		Fquality: uint8(90),
  19919 	},
  19920 	9: {
  19921 		Fmethod:  uint8(6),
  19922 		Fquality: uint8(100),
  19923 	},
  19924 }
  19925 
  19926 func WebPConfigLosslessPreset(tls *libc.TLS, config uintptr, level int32) (r int32) {
  19927 	if config == libc.UintptrFromInt32(0) || level < 0 || level > int32(MAX_LEVEL1) {
  19928 		return 0
  19929 	}
  19930 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = int32(1)
  19931 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = libc.Int32FromUint8(kLosslessPresets[level].Fmethod)
  19932 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = float32(kLosslessPresets[level].Fquality)
  19933 	return int32(1)
  19934 }
  19935 
  19936 type VP8Residual = struct {
  19937 	Ffirst      int32
  19938 	Flast       int32
  19939 	Fcoeffs     uintptr
  19940 	Fcoeff_type int32
  19941 	Fprob       uintptr
  19942 	Fstats      uintptr
  19943 	Fcosts      CostArrayPtr
  19944 }
  19945 
  19946 //------------------------------------------------------------------------------
  19947 
  19948 // Copyright 2011 Google Inc. All Rights Reserved.
  19949 //
  19950 // Use of this source code is governed by a BSD-style license
  19951 // that can be found in the COPYING file in the root of the source
  19952 // tree. An additional intellectual property rights grant can be found
  19953 // in the file PATENTS. All contributing project authors may
  19954 // be found in the AUTHORS file in the root of the source tree.
  19955 // -----------------------------------------------------------------------------
  19956 //
  19957 //   WebP encoder: internal header.
  19958 //
  19959 // Author: Skal (pascal.massimino@gmail.com)
  19960 
  19961 //------------------------------------------------------------------------------
  19962 // Level cost tables
  19963 
  19964 // C documentation
  19965 //
  19966 //	// For each given level, the following table gives the pattern of contexts to
  19967 //	// use for coding it (in [][0]) as well as the bit value to use for each
  19968 //	// context (in [][1]).
  19969 var VP8LevelCodes = [67][2]uint16_t{
  19970 	0: {
  19971 		0: uint16(0x001),
  19972 	},
  19973 	1: {
  19974 		0: uint16(0x007),
  19975 		1: uint16(0x001),
  19976 	},
  19977 	2: {
  19978 		0: uint16(0x00f),
  19979 		1: uint16(0x005),
  19980 	},
  19981 	3: {
  19982 		0: uint16(0x00f),
  19983 		1: uint16(0x00d),
  19984 	},
  19985 	4: {
  19986 		0: uint16(0x033),
  19987 		1: uint16(0x003),
  19988 	},
  19989 	5: {
  19990 		0: uint16(0x033),
  19991 		1: uint16(0x003),
  19992 	},
  19993 	6: {
  19994 		0: uint16(0x033),
  19995 		1: uint16(0x023),
  19996 	},
  19997 	7: {
  19998 		0: uint16(0x033),
  19999 		1: uint16(0x023),
  20000 	},
  20001 	8: {
  20002 		0: uint16(0x033),
  20003 		1: uint16(0x023),
  20004 	},
  20005 	9: {
  20006 		0: uint16(0x033),
  20007 		1: uint16(0x023),
  20008 	},
  20009 	10: {
  20010 		0: uint16(0x0d3),
  20011 		1: uint16(0x013),
  20012 	},
  20013 	11: {
  20014 		0: uint16(0x0d3),
  20015 		1: uint16(0x013),
  20016 	},
  20017 	12: {
  20018 		0: uint16(0x0d3),
  20019 		1: uint16(0x013),
  20020 	},
  20021 	13: {
  20022 		0: uint16(0x0d3),
  20023 		1: uint16(0x013),
  20024 	},
  20025 	14: {
  20026 		0: uint16(0x0d3),
  20027 		1: uint16(0x013),
  20028 	},
  20029 	15: {
  20030 		0: uint16(0x0d3),
  20031 		1: uint16(0x013),
  20032 	},
  20033 	16: {
  20034 		0: uint16(0x0d3),
  20035 		1: uint16(0x013),
  20036 	},
  20037 	17: {
  20038 		0: uint16(0x0d3),
  20039 		1: uint16(0x013),
  20040 	},
  20041 	18: {
  20042 		0: uint16(0x0d3),
  20043 		1: uint16(0x093),
  20044 	},
  20045 	19: {
  20046 		0: uint16(0x0d3),
  20047 		1: uint16(0x093),
  20048 	},
  20049 	20: {
  20050 		0: uint16(0x0d3),
  20051 		1: uint16(0x093),
  20052 	},
  20053 	21: {
  20054 		0: uint16(0x0d3),
  20055 		1: uint16(0x093),
  20056 	},
  20057 	22: {
  20058 		0: uint16(0x0d3),
  20059 		1: uint16(0x093),
  20060 	},
  20061 	23: {
  20062 		0: uint16(0x0d3),
  20063 		1: uint16(0x093),
  20064 	},
  20065 	24: {
  20066 		0: uint16(0x0d3),
  20067 		1: uint16(0x093),
  20068 	},
  20069 	25: {
  20070 		0: uint16(0x0d3),
  20071 		1: uint16(0x093),
  20072 	},
  20073 	26: {
  20074 		0: uint16(0x0d3),
  20075 		1: uint16(0x093),
  20076 	},
  20077 	27: {
  20078 		0: uint16(0x0d3),
  20079 		1: uint16(0x093),
  20080 	},
  20081 	28: {
  20082 		0: uint16(0x0d3),
  20083 		1: uint16(0x093),
  20084 	},
  20085 	29: {
  20086 		0: uint16(0x0d3),
  20087 		1: uint16(0x093),
  20088 	},
  20089 	30: {
  20090 		0: uint16(0x0d3),
  20091 		1: uint16(0x093),
  20092 	},
  20093 	31: {
  20094 		0: uint16(0x0d3),
  20095 		1: uint16(0x093),
  20096 	},
  20097 	32: {
  20098 		0: uint16(0x0d3),
  20099 		1: uint16(0x093),
  20100 	},
  20101 	33: {
  20102 		0: uint16(0x0d3),
  20103 		1: uint16(0x093),
  20104 	},
  20105 	34: {
  20106 		0: uint16(0x153),
  20107 		1: uint16(0x053),
  20108 	},
  20109 	35: {
  20110 		0: uint16(0x153),
  20111 		1: uint16(0x053),
  20112 	},
  20113 	36: {
  20114 		0: uint16(0x153),
  20115 		1: uint16(0x053),
  20116 	},
  20117 	37: {
  20118 		0: uint16(0x153),
  20119 		1: uint16(0x053),
  20120 	},
  20121 	38: {
  20122 		0: uint16(0x153),
  20123 		1: uint16(0x053),
  20124 	},
  20125 	39: {
  20126 		0: uint16(0x153),
  20127 		1: uint16(0x053),
  20128 	},
  20129 	40: {
  20130 		0: uint16(0x153),
  20131 		1: uint16(0x053),
  20132 	},
  20133 	41: {
  20134 		0: uint16(0x153),
  20135 		1: uint16(0x053),
  20136 	},
  20137 	42: {
  20138 		0: uint16(0x153),
  20139 		1: uint16(0x053),
  20140 	},
  20141 	43: {
  20142 		0: uint16(0x153),
  20143 		1: uint16(0x053),
  20144 	},
  20145 	44: {
  20146 		0: uint16(0x153),
  20147 		1: uint16(0x053),
  20148 	},
  20149 	45: {
  20150 		0: uint16(0x153),
  20151 		1: uint16(0x053),
  20152 	},
  20153 	46: {
  20154 		0: uint16(0x153),
  20155 		1: uint16(0x053),
  20156 	},
  20157 	47: {
  20158 		0: uint16(0x153),
  20159 		1: uint16(0x053),
  20160 	},
  20161 	48: {
  20162 		0: uint16(0x153),
  20163 		1: uint16(0x053),
  20164 	},
  20165 	49: {
  20166 		0: uint16(0x153),
  20167 		1: uint16(0x053),
  20168 	},
  20169 	50: {
  20170 		0: uint16(0x153),
  20171 		1: uint16(0x053),
  20172 	},
  20173 	51: {
  20174 		0: uint16(0x153),
  20175 		1: uint16(0x053),
  20176 	},
  20177 	52: {
  20178 		0: uint16(0x153),
  20179 		1: uint16(0x053),
  20180 	},
  20181 	53: {
  20182 		0: uint16(0x153),
  20183 		1: uint16(0x053),
  20184 	},
  20185 	54: {
  20186 		0: uint16(0x153),
  20187 		1: uint16(0x053),
  20188 	},
  20189 	55: {
  20190 		0: uint16(0x153),
  20191 		1: uint16(0x053),
  20192 	},
  20193 	56: {
  20194 		0: uint16(0x153),
  20195 		1: uint16(0x053),
  20196 	},
  20197 	57: {
  20198 		0: uint16(0x153),
  20199 		1: uint16(0x053),
  20200 	},
  20201 	58: {
  20202 		0: uint16(0x153),
  20203 		1: uint16(0x053),
  20204 	},
  20205 	59: {
  20206 		0: uint16(0x153),
  20207 		1: uint16(0x053),
  20208 	},
  20209 	60: {
  20210 		0: uint16(0x153),
  20211 		1: uint16(0x053),
  20212 	},
  20213 	61: {
  20214 		0: uint16(0x153),
  20215 		1: uint16(0x053),
  20216 	},
  20217 	62: {
  20218 		0: uint16(0x153),
  20219 		1: uint16(0x053),
  20220 	},
  20221 	63: {
  20222 		0: uint16(0x153),
  20223 		1: uint16(0x053),
  20224 	},
  20225 	64: {
  20226 		0: uint16(0x153),
  20227 		1: uint16(0x053),
  20228 	},
  20229 	65: {
  20230 		0: uint16(0x153),
  20231 		1: uint16(0x053),
  20232 	},
  20233 	66: {
  20234 		0: uint16(0x153),
  20235 		1: uint16(0x153),
  20236 	},
  20237 }
  20238 
  20239 func VariableLevelCost(tls *libc.TLS, level int32, probas uintptr) (r int32) {
  20240 	var bits, cost, i, pattern, v3, v5 int32
  20241 	var v2 uint8_t
  20242 	_, _, _, _, _, _, _ = bits, cost, i, pattern, v2, v3, v5
  20243 	pattern = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4)))
  20244 	bits = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4 + 1*2)))
  20245 	cost = 0
  20246 	i = int32(2)
  20247 	for {
  20248 		if !(pattern != 0) {
  20249 			break
  20250 		}
  20251 		if pattern&int32(1) != 0 {
  20252 			v2 = **(**uint8_t)(__ccgo_up(probas + uintptr(i)))
  20253 			if !(bits&int32(1) != 0) {
  20254 				v5 = libc.Int32FromUint16(VP8EntropyCost[v2])
  20255 			} else {
  20256 				v5 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v2)])
  20257 			}
  20258 			v3 = v5
  20259 			goto _4
  20260 		_4:
  20261 			cost = cost + v3
  20262 		}
  20263 		bits = bits >> int32(1)
  20264 		pattern = pattern >> int32(1)
  20265 		goto _1
  20266 	_1:
  20267 		;
  20268 		i = i + 1
  20269 	}
  20270 	return cost
  20271 }
  20272 
  20273 //------------------------------------------------------------------------------
  20274 // Pre-calc level costs once for all
  20275 
  20276 func VP8CalculateLevelCosts(tls *libc.TLS, proba1 uintptr) {
  20277 	var band, cost0, cost_base, ctx, ctype, n, v, v10, v12, v14, v16, v4, v6, v8 int32
  20278 	var p, table uintptr
  20279 	var v13, v5, v9 uint8_t
  20280 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = band, cost0, cost_base, ctx, ctype, n, p, table, v, v10, v12, v13, v14, v16, v4, v5, v6, v8, v9
  20281 	if !((*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty != 0) {
  20282 		return
  20283 	} // nothing to do.
  20284 	ctype = 0
  20285 	for {
  20286 		if !(ctype < int32(NUM_TYPES)) {
  20287 			break
  20288 		}
  20289 		band = 0
  20290 		for {
  20291 			if !(band < int32(NUM_BANDS)) {
  20292 				break
  20293 			}
  20294 			ctx = 0
  20295 			for {
  20296 				if !(ctx < int32(NUM_CTX)) {
  20297 					break
  20298 				}
  20299 				p = proba1 + 4 + uintptr(ctype)*264 + uintptr(band)*33 + uintptr(ctx)*11
  20300 				table = proba1 + 5284 + uintptr(ctype)*3264 + uintptr(band)*408 + uintptr(ctx)*136
  20301 				if ctx > 0 {
  20302 					v5 = **(**uint8_t)(__ccgo_up(p))
  20303 					if !(int32(1) != 0) {
  20304 						v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  20305 					} else {
  20306 						v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  20307 					}
  20308 					v6 = v8
  20309 					goto _7
  20310 				_7:
  20311 					v4 = v6
  20312 				} else {
  20313 					v4 = 0
  20314 				}
  20315 				cost0 = v4
  20316 				v9 = **(**uint8_t)(__ccgo_up(p + 1))
  20317 				if !(int32(1) != 0) {
  20318 					v12 = libc.Int32FromUint16(VP8EntropyCost[v9])
  20319 				} else {
  20320 					v12 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v9)])
  20321 				}
  20322 				v10 = v12
  20323 				goto _11
  20324 			_11:
  20325 				cost_base = v10 + cost0
  20326 				v13 = **(**uint8_t)(__ccgo_up(p + 1))
  20327 				if !(0 != 0) {
  20328 					v16 = libc.Int32FromUint16(VP8EntropyCost[v13])
  20329 				} else {
  20330 					v16 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v13)])
  20331 				}
  20332 				v14 = v16
  20333 				goto _15
  20334 			_15:
  20335 				**(**uint16_t)(__ccgo_up(table)) = libc.Uint16FromInt32(v14 + cost0)
  20336 				v = int32(1)
  20337 				for {
  20338 					if !(v <= int32(MAX_VARIABLE_LEVEL)) {
  20339 						break
  20340 					}
  20341 					**(**uint16_t)(__ccgo_up(table + uintptr(v)*2)) = libc.Uint16FromInt32(cost_base + VariableLevelCost(tls, v, p))
  20342 					goto _17
  20343 				_17:
  20344 					;
  20345 					v = v + 1
  20346 				}
  20347 				// Starting at level 67 and up, the variable part of the cost is
  20348 				// actually constant.
  20349 				goto _3
  20350 			_3:
  20351 				;
  20352 				ctx = ctx + 1
  20353 			}
  20354 			goto _2
  20355 		_2:
  20356 			;
  20357 			band = band + 1
  20358 		}
  20359 		n = 0
  20360 		for {
  20361 			if !(n < int32(16)) {
  20362 				break
  20363 			} // replicate bands. We don't need to sentinel.
  20364 			ctx = 0
  20365 			for {
  20366 				if !(ctx < int32(NUM_CTX)) {
  20367 					break
  20368 				}
  20369 				**(**uintptr)(__ccgo_up(proba1 + 18344 + uintptr(ctype)*384 + uintptr(n)*24 + uintptr(ctx)*8)) = proba1 + 5284 + uintptr(ctype)*3264 + uintptr(VP8EncBands[n])*408 + uintptr(ctx)*136
  20370 				goto _19
  20371 			_19:
  20372 				;
  20373 				ctx = ctx + 1
  20374 			}
  20375 			goto _18
  20376 		_18:
  20377 			;
  20378 			n = n + 1
  20379 		}
  20380 		goto _1
  20381 	_1:
  20382 		;
  20383 		ctype = ctype + 1
  20384 	}
  20385 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = 0
  20386 }
  20387 
  20388 //------------------------------------------------------------------------------
  20389 // helper functions for residuals struct VP8Residual.
  20390 
  20391 func VP8InitResidual(tls *libc.TLS, first int32, coeff_type int32, enc uintptr, res uintptr) {
  20392 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type = coeff_type
  20393 	(*VP8Residual)(unsafe.Pointer(res)).Fprob = enc + 3616 + 4 + uintptr(coeff_type)*264
  20394 	(*VP8Residual)(unsafe.Pointer(res)).Fstats = enc + 3616 + 1060 + uintptr(coeff_type)*1056
  20395 	(*VP8Residual)(unsafe.Pointer(res)).Fcosts = enc + 3616 + 18344 + uintptr(coeff_type)*384
  20396 	(*VP8Residual)(unsafe.Pointer(res)).Ffirst = first
  20397 }
  20398 
  20399 //------------------------------------------------------------------------------
  20400 // Mode costs
  20401 
  20402 func VP8GetCostLuma4(tls *libc.TLS, it uintptr, levels uintptr) (r int32) {
  20403 	bp := tls.Alloc(48)
  20404 	defer tls.Free(48)
  20405 	var R, ctx, x, y int32
  20406 	var enc uintptr
  20407 	var _ /* res at bp+0 */ VP8Residual
  20408 	_, _, _, _, _ = R, ctx, enc, x, y
  20409 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  20410 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> libc.Int32FromInt32(2)
  20411 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20412 	R = 0
  20413 	VP8InitResidual(tls, 0, int32(3), enc, bp)
  20414 	ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20415 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, levels, bp)
  20416 	R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20417 	return R
  20418 }
  20419 
  20420 func VP8GetCostLuma16(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20421 	bp := tls.Alloc(48)
  20422 	defer tls.Free(48)
  20423 	var R, ctx, x, y, v3 int32
  20424 	var enc uintptr
  20425 	var _ /* res at bp+0 */ VP8Residual
  20426 	_, _, _, _, _, _ = R, ctx, enc, x, y, v3
  20427 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20428 	R = 0
  20429 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20430 	// DC
  20431 	VP8InitResidual(tls, 0, int32(1), enc, bp)
  20432 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  20433 	R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  20434 	// AC
  20435 	VP8InitResidual(tls, int32(1), 0, enc, bp)
  20436 	y = 0
  20437 	for {
  20438 		if !(y < int32(4)) {
  20439 			break
  20440 		}
  20441 		x = 0
  20442 		for {
  20443 			if !(x < int32(4)) {
  20444 				break
  20445 			}
  20446 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20447 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  20448 			R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20449 			v3 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20450 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v3
  20451 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v3
  20452 			goto _2
  20453 		_2:
  20454 			;
  20455 			x = x + 1
  20456 		}
  20457 		goto _1
  20458 	_1:
  20459 		;
  20460 		y = y + 1
  20461 	}
  20462 	return R
  20463 }
  20464 
  20465 func VP8GetCostUV(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20466 	bp := tls.Alloc(48)
  20467 	defer tls.Free(48)
  20468 	var R, ch, ctx, x, y, v4 int32
  20469 	var enc uintptr
  20470 	var _ /* res at bp+0 */ VP8Residual
  20471 	_, _, _, _, _, _, _ = R, ch, ctx, enc, x, y, v4
  20472 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20473 	R = 0
  20474 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20475 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  20476 	ch = 0
  20477 	for {
  20478 		if !(ch <= int32(2)) {
  20479 			break
  20480 		}
  20481 		y = 0
  20482 		for {
  20483 			if !(y < int32(2)) {
  20484 				break
  20485 			}
  20486 			x = 0
  20487 			for {
  20488 				if !(x < int32(2)) {
  20489 					break
  20490 				}
  20491 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  20492 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  20493 				R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20494 				v4 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20495 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  20496 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  20497 				goto _3
  20498 			_3:
  20499 				;
  20500 				x = x + 1
  20501 			}
  20502 			goto _2
  20503 		_2:
  20504 			;
  20505 			y = y + 1
  20506 		}
  20507 		goto _1
  20508 	_1:
  20509 		;
  20510 		ch = ch + int32(2)
  20511 	}
  20512 	return R
  20513 }
  20514 
  20515 //------------------------------------------------------------------------------
  20516 // Recording of token probabilities.
  20517 
  20518 // We keep the table-free variant around for reference, in case.
  20519 
  20520 // C documentation
  20521 //
  20522 //	// Simulate block coding, but only record statistics.
  20523 //	// Note: no need to record the fixed probas.
  20524 func VP8RecordCoeffs(tls *libc.TLS, ctx int32, res uintptr) (r int32) {
  20525 	var bits, i, mask, n, pattern, v, v1, v4, v7 int32
  20526 	var p proba_t
  20527 	var s, v2 uintptr
  20528 	_, _, _, _, _, _, _, _, _, _, _, _ = bits, i, mask, n, p, pattern, s, v, v1, v2, v4, v7
  20529 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  20530 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  20531 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  20532 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  20533 		v1 = 0
  20534 		v2 = s + uintptr(0)*4
  20535 		p = **(**proba_t)(__ccgo_up(v2))
  20536 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20537 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20538 		}
  20539 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20540 		**(**proba_t)(__ccgo_up(v2)) = p
  20541 		_ = v1
  20542 		goto _3
  20543 	_3:
  20544 		;
  20545 		return 0
  20546 	}
  20547 	for n <= (*VP8Residual)(unsafe.Pointer(res)).Flast {
  20548 		v1 = int32(1)
  20549 		v2 = s + uintptr(0)*4
  20550 		p = **(**proba_t)(__ccgo_up(v2))
  20551 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20552 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20553 		}
  20554 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20555 		**(**proba_t)(__ccgo_up(v2)) = p
  20556 		_ = v1
  20557 		goto _6
  20558 	_6:
  20559 		; // order of record doesn't matter
  20560 		for {
  20561 			v4 = n
  20562 			n = n + 1
  20563 			v1 = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v4)*2)))
  20564 			v = v1
  20565 			if !(v1 == 0) {
  20566 				break
  20567 			}
  20568 			v7 = 0
  20569 			v2 = s + uintptr(1)*4
  20570 			p = **(**proba_t)(__ccgo_up(v2))
  20571 			if p >= libc.Uint32FromUint32(0xfffe0000) {
  20572 				p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20573 			}
  20574 			p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v7))
  20575 			**(**proba_t)(__ccgo_up(v2)) = p
  20576 			_ = v7
  20577 			goto _11
  20578 		_11:
  20579 			;
  20580 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  20581 		}
  20582 		v1 = int32(1)
  20583 		v2 = s + uintptr(1)*4
  20584 		p = **(**proba_t)(__ccgo_up(v2))
  20585 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20586 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20587 		}
  20588 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20589 		**(**proba_t)(__ccgo_up(v2)) = p
  20590 		_ = v1
  20591 		goto _14
  20592 	_14:
  20593 		;
  20594 		v1 = libc.BoolInt32(uint32(2) < libc.Uint32FromInt32(v+libc.Int32FromInt32(1)))
  20595 		v2 = s + uintptr(2)*4
  20596 		p = **(**proba_t)(__ccgo_up(v2))
  20597 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20598 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20599 		}
  20600 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20601 		**(**proba_t)(__ccgo_up(v2)) = p
  20602 		v4 = v1
  20603 		goto _18
  20604 	_18:
  20605 		if !(v4 != 0) { // v = -1 or 1
  20606 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  20607 		} else {
  20608 			v = libc.Xabs(tls, v)
  20609 			if v > int32(MAX_VARIABLE_LEVEL) {
  20610 				v = int32(MAX_VARIABLE_LEVEL)
  20611 			}
  20612 			bits = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4 + 1*2)))
  20613 			pattern = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4)))
  20614 			i = 0
  20615 			for {
  20616 				pattern = pattern >> int32(1)
  20617 				if !(pattern != 0) {
  20618 					break
  20619 				}
  20620 				mask = int32(2) << i
  20621 				if pattern&int32(1) != 0 {
  20622 					v1 = libc.BoolInt32(!!(bits&mask != 0))
  20623 					v2 = s + uintptr(3)*4 + uintptr(i)*4
  20624 					p = **(**proba_t)(__ccgo_up(v2))
  20625 					if p >= libc.Uint32FromUint32(0xfffe0000) {
  20626 						p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20627 					}
  20628 					p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20629 					**(**proba_t)(__ccgo_up(v2)) = p
  20630 					_ = v1
  20631 					goto _22
  20632 				_22:
  20633 				}
  20634 				goto _19
  20635 			_19:
  20636 				;
  20637 				i = i + 1
  20638 			}
  20639 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  20640 		}
  20641 	}
  20642 	if n < int32(16) {
  20643 		v1 = 0
  20644 		v2 = s + uintptr(0)*4
  20645 		p = **(**proba_t)(__ccgo_up(v2))
  20646 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20647 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20648 		}
  20649 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20650 		**(**proba_t)(__ccgo_up(v2)) = p
  20651 		_ = v1
  20652 		goto _25
  20653 	_25:
  20654 	}
  20655 	return int32(1)
  20656 }
  20657 
  20658 const MAX_DELTA_SIZE = 64
  20659 
  20660 //------------------------------------------------------------------------------
  20661 
  20662 // C documentation
  20663 //
  20664 //	// This table gives, for a given sharpness, the filtering strength to be
  20665 //	// used (at least) in order to filter a given edge step delta.
  20666 //	// This is constructed by brute force inspection: for all delta, we iterate
  20667 //	// over all possible filtering strength / thresh until needs_filter() returns
  20668 //	// true.
  20669 var kLevelsFromDelta = [8][64]uint8_t{
  20670 	0: {
  20671 		1:  uint8(1),
  20672 		2:  uint8(2),
  20673 		3:  uint8(3),
  20674 		4:  uint8(4),
  20675 		5:  uint8(5),
  20676 		6:  uint8(6),
  20677 		7:  uint8(7),
  20678 		8:  uint8(8),
  20679 		9:  uint8(9),
  20680 		10: uint8(10),
  20681 		11: uint8(11),
  20682 		12: uint8(12),
  20683 		13: uint8(13),
  20684 		14: uint8(14),
  20685 		15: uint8(15),
  20686 		16: uint8(16),
  20687 		17: uint8(17),
  20688 		18: uint8(18),
  20689 		19: uint8(19),
  20690 		20: uint8(20),
  20691 		21: uint8(21),
  20692 		22: uint8(22),
  20693 		23: uint8(23),
  20694 		24: uint8(24),
  20695 		25: uint8(25),
  20696 		26: uint8(26),
  20697 		27: uint8(27),
  20698 		28: uint8(28),
  20699 		29: uint8(29),
  20700 		30: uint8(30),
  20701 		31: uint8(31),
  20702 		32: uint8(32),
  20703 		33: uint8(33),
  20704 		34: uint8(34),
  20705 		35: uint8(35),
  20706 		36: uint8(36),
  20707 		37: uint8(37),
  20708 		38: uint8(38),
  20709 		39: uint8(39),
  20710 		40: uint8(40),
  20711 		41: uint8(41),
  20712 		42: uint8(42),
  20713 		43: uint8(43),
  20714 		44: uint8(44),
  20715 		45: uint8(45),
  20716 		46: uint8(46),
  20717 		47: uint8(47),
  20718 		48: uint8(48),
  20719 		49: uint8(49),
  20720 		50: uint8(50),
  20721 		51: uint8(51),
  20722 		52: uint8(52),
  20723 		53: uint8(53),
  20724 		54: uint8(54),
  20725 		55: uint8(55),
  20726 		56: uint8(56),
  20727 		57: uint8(57),
  20728 		58: uint8(58),
  20729 		59: uint8(59),
  20730 		60: uint8(60),
  20731 		61: uint8(61),
  20732 		62: uint8(62),
  20733 		63: uint8(63),
  20734 	},
  20735 	1: {
  20736 		1:  uint8(1),
  20737 		2:  uint8(2),
  20738 		3:  uint8(3),
  20739 		4:  uint8(5),
  20740 		5:  uint8(6),
  20741 		6:  uint8(7),
  20742 		7:  uint8(8),
  20743 		8:  uint8(9),
  20744 		9:  uint8(11),
  20745 		10: uint8(12),
  20746 		11: uint8(13),
  20747 		12: uint8(14),
  20748 		13: uint8(15),
  20749 		14: uint8(17),
  20750 		15: uint8(18),
  20751 		16: uint8(20),
  20752 		17: uint8(21),
  20753 		18: uint8(23),
  20754 		19: uint8(24),
  20755 		20: uint8(26),
  20756 		21: uint8(27),
  20757 		22: uint8(29),
  20758 		23: uint8(30),
  20759 		24: uint8(32),
  20760 		25: uint8(33),
  20761 		26: uint8(35),
  20762 		27: uint8(36),
  20763 		28: uint8(38),
  20764 		29: uint8(39),
  20765 		30: uint8(41),
  20766 		31: uint8(42),
  20767 		32: uint8(44),
  20768 		33: uint8(45),
  20769 		34: uint8(47),
  20770 		35: uint8(48),
  20771 		36: uint8(50),
  20772 		37: uint8(51),
  20773 		38: uint8(53),
  20774 		39: uint8(54),
  20775 		40: uint8(56),
  20776 		41: uint8(57),
  20777 		42: uint8(59),
  20778 		43: uint8(60),
  20779 		44: uint8(62),
  20780 		45: uint8(63),
  20781 		46: uint8(63),
  20782 		47: uint8(63),
  20783 		48: uint8(63),
  20784 		49: uint8(63),
  20785 		50: uint8(63),
  20786 		51: uint8(63),
  20787 		52: uint8(63),
  20788 		53: uint8(63),
  20789 		54: uint8(63),
  20790 		55: uint8(63),
  20791 		56: uint8(63),
  20792 		57: uint8(63),
  20793 		58: uint8(63),
  20794 		59: uint8(63),
  20795 		60: uint8(63),
  20796 		61: uint8(63),
  20797 		62: uint8(63),
  20798 		63: uint8(63),
  20799 	},
  20800 	2: {
  20801 		1:  uint8(1),
  20802 		2:  uint8(2),
  20803 		3:  uint8(3),
  20804 		4:  uint8(5),
  20805 		5:  uint8(6),
  20806 		6:  uint8(7),
  20807 		7:  uint8(8),
  20808 		8:  uint8(9),
  20809 		9:  uint8(11),
  20810 		10: uint8(12),
  20811 		11: uint8(13),
  20812 		12: uint8(14),
  20813 		13: uint8(16),
  20814 		14: uint8(17),
  20815 		15: uint8(19),
  20816 		16: uint8(20),
  20817 		17: uint8(22),
  20818 		18: uint8(23),
  20819 		19: uint8(25),
  20820 		20: uint8(26),
  20821 		21: uint8(28),
  20822 		22: uint8(29),
  20823 		23: uint8(31),
  20824 		24: uint8(32),
  20825 		25: uint8(34),
  20826 		26: uint8(35),
  20827 		27: uint8(37),
  20828 		28: uint8(38),
  20829 		29: uint8(40),
  20830 		30: uint8(41),
  20831 		31: uint8(43),
  20832 		32: uint8(44),
  20833 		33: uint8(46),
  20834 		34: uint8(47),
  20835 		35: uint8(49),
  20836 		36: uint8(50),
  20837 		37: uint8(52),
  20838 		38: uint8(53),
  20839 		39: uint8(55),
  20840 		40: uint8(56),
  20841 		41: uint8(58),
  20842 		42: uint8(59),
  20843 		43: uint8(61),
  20844 		44: uint8(62),
  20845 		45: uint8(63),
  20846 		46: uint8(63),
  20847 		47: uint8(63),
  20848 		48: uint8(63),
  20849 		49: uint8(63),
  20850 		50: uint8(63),
  20851 		51: uint8(63),
  20852 		52: uint8(63),
  20853 		53: uint8(63),
  20854 		54: uint8(63),
  20855 		55: uint8(63),
  20856 		56: uint8(63),
  20857 		57: uint8(63),
  20858 		58: uint8(63),
  20859 		59: uint8(63),
  20860 		60: uint8(63),
  20861 		61: uint8(63),
  20862 		62: uint8(63),
  20863 		63: uint8(63),
  20864 	},
  20865 	3: {
  20866 		1:  uint8(1),
  20867 		2:  uint8(2),
  20868 		3:  uint8(3),
  20869 		4:  uint8(5),
  20870 		5:  uint8(6),
  20871 		6:  uint8(7),
  20872 		7:  uint8(8),
  20873 		8:  uint8(9),
  20874 		9:  uint8(11),
  20875 		10: uint8(12),
  20876 		11: uint8(13),
  20877 		12: uint8(15),
  20878 		13: uint8(16),
  20879 		14: uint8(18),
  20880 		15: uint8(19),
  20881 		16: uint8(21),
  20882 		17: uint8(22),
  20883 		18: uint8(24),
  20884 		19: uint8(25),
  20885 		20: uint8(27),
  20886 		21: uint8(28),
  20887 		22: uint8(30),
  20888 		23: uint8(31),
  20889 		24: uint8(33),
  20890 		25: uint8(34),
  20891 		26: uint8(36),
  20892 		27: uint8(37),
  20893 		28: uint8(39),
  20894 		29: uint8(40),
  20895 		30: uint8(42),
  20896 		31: uint8(43),
  20897 		32: uint8(45),
  20898 		33: uint8(46),
  20899 		34: uint8(48),
  20900 		35: uint8(49),
  20901 		36: uint8(51),
  20902 		37: uint8(52),
  20903 		38: uint8(54),
  20904 		39: uint8(55),
  20905 		40: uint8(57),
  20906 		41: uint8(58),
  20907 		42: uint8(60),
  20908 		43: uint8(61),
  20909 		44: uint8(63),
  20910 		45: uint8(63),
  20911 		46: uint8(63),
  20912 		47: uint8(63),
  20913 		48: uint8(63),
  20914 		49: uint8(63),
  20915 		50: uint8(63),
  20916 		51: uint8(63),
  20917 		52: uint8(63),
  20918 		53: uint8(63),
  20919 		54: uint8(63),
  20920 		55: uint8(63),
  20921 		56: uint8(63),
  20922 		57: uint8(63),
  20923 		58: uint8(63),
  20924 		59: uint8(63),
  20925 		60: uint8(63),
  20926 		61: uint8(63),
  20927 		62: uint8(63),
  20928 		63: uint8(63),
  20929 	},
  20930 	4: {
  20931 		1:  uint8(1),
  20932 		2:  uint8(2),
  20933 		3:  uint8(3),
  20934 		4:  uint8(5),
  20935 		5:  uint8(6),
  20936 		6:  uint8(7),
  20937 		7:  uint8(8),
  20938 		8:  uint8(9),
  20939 		9:  uint8(11),
  20940 		10: uint8(12),
  20941 		11: uint8(14),
  20942 		12: uint8(15),
  20943 		13: uint8(17),
  20944 		14: uint8(18),
  20945 		15: uint8(20),
  20946 		16: uint8(21),
  20947 		17: uint8(23),
  20948 		18: uint8(24),
  20949 		19: uint8(26),
  20950 		20: uint8(27),
  20951 		21: uint8(29),
  20952 		22: uint8(30),
  20953 		23: uint8(32),
  20954 		24: uint8(33),
  20955 		25: uint8(35),
  20956 		26: uint8(36),
  20957 		27: uint8(38),
  20958 		28: uint8(39),
  20959 		29: uint8(41),
  20960 		30: uint8(42),
  20961 		31: uint8(44),
  20962 		32: uint8(45),
  20963 		33: uint8(47),
  20964 		34: uint8(48),
  20965 		35: uint8(50),
  20966 		36: uint8(51),
  20967 		37: uint8(53),
  20968 		38: uint8(54),
  20969 		39: uint8(56),
  20970 		40: uint8(57),
  20971 		41: uint8(59),
  20972 		42: uint8(60),
  20973 		43: uint8(62),
  20974 		44: uint8(63),
  20975 		45: uint8(63),
  20976 		46: uint8(63),
  20977 		47: uint8(63),
  20978 		48: uint8(63),
  20979 		49: uint8(63),
  20980 		50: uint8(63),
  20981 		51: uint8(63),
  20982 		52: uint8(63),
  20983 		53: uint8(63),
  20984 		54: uint8(63),
  20985 		55: uint8(63),
  20986 		56: uint8(63),
  20987 		57: uint8(63),
  20988 		58: uint8(63),
  20989 		59: uint8(63),
  20990 		60: uint8(63),
  20991 		61: uint8(63),
  20992 		62: uint8(63),
  20993 		63: uint8(63),
  20994 	},
  20995 	5: {
  20996 		1:  uint8(1),
  20997 		2:  uint8(2),
  20998 		3:  uint8(4),
  20999 		4:  uint8(5),
  21000 		5:  uint8(7),
  21001 		6:  uint8(8),
  21002 		7:  uint8(9),
  21003 		8:  uint8(11),
  21004 		9:  uint8(12),
  21005 		10: uint8(13),
  21006 		11: uint8(15),
  21007 		12: uint8(16),
  21008 		13: uint8(17),
  21009 		14: uint8(19),
  21010 		15: uint8(20),
  21011 		16: uint8(22),
  21012 		17: uint8(23),
  21013 		18: uint8(25),
  21014 		19: uint8(26),
  21015 		20: uint8(28),
  21016 		21: uint8(29),
  21017 		22: uint8(31),
  21018 		23: uint8(32),
  21019 		24: uint8(34),
  21020 		25: uint8(35),
  21021 		26: uint8(37),
  21022 		27: uint8(38),
  21023 		28: uint8(40),
  21024 		29: uint8(41),
  21025 		30: uint8(43),
  21026 		31: uint8(44),
  21027 		32: uint8(46),
  21028 		33: uint8(47),
  21029 		34: uint8(49),
  21030 		35: uint8(50),
  21031 		36: uint8(52),
  21032 		37: uint8(53),
  21033 		38: uint8(55),
  21034 		39: uint8(56),
  21035 		40: uint8(58),
  21036 		41: uint8(59),
  21037 		42: uint8(61),
  21038 		43: uint8(62),
  21039 		44: uint8(63),
  21040 		45: uint8(63),
  21041 		46: uint8(63),
  21042 		47: uint8(63),
  21043 		48: uint8(63),
  21044 		49: uint8(63),
  21045 		50: uint8(63),
  21046 		51: uint8(63),
  21047 		52: uint8(63),
  21048 		53: uint8(63),
  21049 		54: uint8(63),
  21050 		55: uint8(63),
  21051 		56: uint8(63),
  21052 		57: uint8(63),
  21053 		58: uint8(63),
  21054 		59: uint8(63),
  21055 		60: uint8(63),
  21056 		61: uint8(63),
  21057 		62: uint8(63),
  21058 		63: uint8(63),
  21059 	},
  21060 	6: {
  21061 		1:  uint8(1),
  21062 		2:  uint8(2),
  21063 		3:  uint8(4),
  21064 		4:  uint8(5),
  21065 		5:  uint8(7),
  21066 		6:  uint8(8),
  21067 		7:  uint8(9),
  21068 		8:  uint8(11),
  21069 		9:  uint8(12),
  21070 		10: uint8(13),
  21071 		11: uint8(15),
  21072 		12: uint8(16),
  21073 		13: uint8(18),
  21074 		14: uint8(19),
  21075 		15: uint8(21),
  21076 		16: uint8(22),
  21077 		17: uint8(24),
  21078 		18: uint8(25),
  21079 		19: uint8(27),
  21080 		20: uint8(28),
  21081 		21: uint8(30),
  21082 		22: uint8(31),
  21083 		23: uint8(33),
  21084 		24: uint8(34),
  21085 		25: uint8(36),
  21086 		26: uint8(37),
  21087 		27: uint8(39),
  21088 		28: uint8(40),
  21089 		29: uint8(42),
  21090 		30: uint8(43),
  21091 		31: uint8(45),
  21092 		32: uint8(46),
  21093 		33: uint8(48),
  21094 		34: uint8(49),
  21095 		35: uint8(51),
  21096 		36: uint8(52),
  21097 		37: uint8(54),
  21098 		38: uint8(55),
  21099 		39: uint8(57),
  21100 		40: uint8(58),
  21101 		41: uint8(60),
  21102 		42: uint8(61),
  21103 		43: uint8(63),
  21104 		44: uint8(63),
  21105 		45: uint8(63),
  21106 		46: uint8(63),
  21107 		47: uint8(63),
  21108 		48: uint8(63),
  21109 		49: uint8(63),
  21110 		50: uint8(63),
  21111 		51: uint8(63),
  21112 		52: uint8(63),
  21113 		53: uint8(63),
  21114 		54: uint8(63),
  21115 		55: uint8(63),
  21116 		56: uint8(63),
  21117 		57: uint8(63),
  21118 		58: uint8(63),
  21119 		59: uint8(63),
  21120 		60: uint8(63),
  21121 		61: uint8(63),
  21122 		62: uint8(63),
  21123 		63: uint8(63),
  21124 	},
  21125 	7: {
  21126 		1:  uint8(1),
  21127 		2:  uint8(2),
  21128 		3:  uint8(4),
  21129 		4:  uint8(5),
  21130 		5:  uint8(7),
  21131 		6:  uint8(8),
  21132 		7:  uint8(9),
  21133 		8:  uint8(11),
  21134 		9:  uint8(12),
  21135 		10: uint8(14),
  21136 		11: uint8(15),
  21137 		12: uint8(17),
  21138 		13: uint8(18),
  21139 		14: uint8(20),
  21140 		15: uint8(21),
  21141 		16: uint8(23),
  21142 		17: uint8(24),
  21143 		18: uint8(26),
  21144 		19: uint8(27),
  21145 		20: uint8(29),
  21146 		21: uint8(30),
  21147 		22: uint8(32),
  21148 		23: uint8(33),
  21149 		24: uint8(35),
  21150 		25: uint8(36),
  21151 		26: uint8(38),
  21152 		27: uint8(39),
  21153 		28: uint8(41),
  21154 		29: uint8(42),
  21155 		30: uint8(44),
  21156 		31: uint8(45),
  21157 		32: uint8(47),
  21158 		33: uint8(48),
  21159 		34: uint8(50),
  21160 		35: uint8(51),
  21161 		36: uint8(53),
  21162 		37: uint8(54),
  21163 		38: uint8(56),
  21164 		39: uint8(57),
  21165 		40: uint8(59),
  21166 		41: uint8(60),
  21167 		42: uint8(62),
  21168 		43: uint8(63),
  21169 		44: uint8(63),
  21170 		45: uint8(63),
  21171 		46: uint8(63),
  21172 		47: uint8(63),
  21173 		48: uint8(63),
  21174 		49: uint8(63),
  21175 		50: uint8(63),
  21176 		51: uint8(63),
  21177 		52: uint8(63),
  21178 		53: uint8(63),
  21179 		54: uint8(63),
  21180 		55: uint8(63),
  21181 		56: uint8(63),
  21182 		57: uint8(63),
  21183 		58: uint8(63),
  21184 		59: uint8(63),
  21185 		60: uint8(63),
  21186 		61: uint8(63),
  21187 		62: uint8(63),
  21188 		63: uint8(63),
  21189 	},
  21190 }
  21191 
  21192 func VP8FilterStrengthFromDelta(tls *libc.TLS, sharpness int32, delta int32) (r int32) {
  21193 	var pos, v1 int32
  21194 	_, _ = pos, v1
  21195 	if delta < int32(MAX_DELTA_SIZE) {
  21196 		v1 = delta
  21197 	} else {
  21198 		v1 = libc.Int32FromInt32(MAX_DELTA_SIZE) - libc.Int32FromInt32(1)
  21199 	}
  21200 	pos = v1
  21201 	return libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kLevelsFromDelta)) + uintptr(sharpness)*64 + uintptr(pos))))
  21202 }
  21203 
  21204 //------------------------------------------------------------------------------
  21205 // Paragraph 15.4: compute the inner-edge filtering strength
  21206 
  21207 func GetILevel(tls *libc.TLS, sharpness int32, level int32) (r int32) {
  21208 	if sharpness > 0 {
  21209 		if sharpness > int32(4) {
  21210 			level = level >> int32(2)
  21211 		} else {
  21212 			level = level >> int32(1)
  21213 		}
  21214 		if level > int32(9)-sharpness {
  21215 			level = int32(9) - sharpness
  21216 		}
  21217 	}
  21218 	if level < int32(1) {
  21219 		level = int32(1)
  21220 	}
  21221 	return level
  21222 }
  21223 
  21224 func DoFilter1(tls *libc.TLS, it uintptr, level int32) {
  21225 	var enc, u_dst, v_dst, y_dst uintptr
  21226 	var hev_thresh, ilevel, limit, v1, v2 int32
  21227 	_, _, _, _, _, _, _, _, _ = enc, hev_thresh, ilevel, limit, u_dst, v_dst, y_dst, v1, v2
  21228 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21229 	ilevel = GetILevel(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness, level)
  21230 	limit = int32(2)*level + ilevel
  21231 	y_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  21232 	u_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  21233 	v_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  21234 	// copy current block to yuv_out2
  21235 	libc.Xmemcpy(tls, y_dst, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out, libc.Uint64FromInt32(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))*libc.Uint64FromInt64(1))
  21236 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple == int32(1) { // simple
  21237 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, int32(BPS), limit)
  21238 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, int32(BPS), limit)
  21239 	} else {
  21240 		if level >= int32(40) {
  21241 			v1 = int32(2)
  21242 		} else {
  21243 			if level >= int32(15) {
  21244 				v2 = int32(1)
  21245 			} else {
  21246 				v2 = 0
  21247 			}
  21248 			v1 = v2
  21249 		} // complex
  21250 		hev_thresh = v1
  21251 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21252 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter8i})))(tls, u_dst, v_dst, int32(BPS), limit, ilevel, hev_thresh)
  21253 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21254 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter8i})))(tls, u_dst, v_dst, int32(BPS), limit, ilevel, hev_thresh)
  21255 	}
  21256 }
  21257 
  21258 //------------------------------------------------------------------------------
  21259 // SSIM metric for one macroblock
  21260 
  21261 func GetMBSSIM(tls *libc.TLS, yuv1 uintptr, yuv2 uintptr) (r float64) {
  21262 	var sum float64
  21263 	var x, y int32
  21264 	_, _, _ = sum, x, y
  21265 	sum = float64(0)
  21266 	// compute SSIM in a 10 x 10 window
  21267 	y = int32(VP8_SSIM_KERNEL)
  21268 	for {
  21269 		if !(y < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21270 			break
  21271 		}
  21272 		x = int32(VP8_SSIM_KERNEL)
  21273 		for {
  21274 			if !(x < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21275 				break
  21276 			}
  21277 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, yuv1+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), int32(BPS), yuv2+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), int32(BPS), x, y, int32(16), int32(16))
  21278 			goto _2
  21279 		_2:
  21280 			;
  21281 			x = x + 1
  21282 		}
  21283 		goto _1
  21284 	_1:
  21285 		;
  21286 		y = y + 1
  21287 	}
  21288 	x = int32(1)
  21289 	for {
  21290 		if !(x < int32(7)) {
  21291 			break
  21292 		}
  21293 		y = int32(1)
  21294 		for {
  21295 			if !(y < int32(7)) {
  21296 				break
  21297 			}
  21298 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, yuv1+uintptr(libc.Int32FromInt32(U_OFF_ENC)), int32(BPS), yuv2+uintptr(libc.Int32FromInt32(U_OFF_ENC)), int32(BPS), x, y, int32(8), int32(8))
  21299 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, yuv1+uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8)), int32(BPS), yuv2+uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8)), int32(BPS), x, y, int32(8), int32(8))
  21300 			goto _4
  21301 		_4:
  21302 			;
  21303 			y = y + 1
  21304 		}
  21305 		goto _3
  21306 	_3:
  21307 		;
  21308 		x = x + 1
  21309 	}
  21310 	return sum
  21311 }
  21312 
  21313 //------------------------------------------------------------------------------
  21314 // Exposed APIs: Encoder should call the following 3 functions to adjust
  21315 // loop filter strength
  21316 
  21317 func VP8InitFilter(tls *libc.TLS, it uintptr) {
  21318 	var i, s int32
  21319 	_, _ = i, s
  21320 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21321 		s = 0
  21322 		for {
  21323 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21324 				break
  21325 			}
  21326 			i = 0
  21327 			for {
  21328 				if !(i < int32(MAX_LF_LEVELS)) {
  21329 					break
  21330 				}
  21331 				**(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8)) = libc.Float64FromInt32(0)
  21332 				goto _2
  21333 			_2:
  21334 				;
  21335 				i = i + 1
  21336 			}
  21337 			goto _1
  21338 		_1:
  21339 			;
  21340 			s = s + 1
  21341 		}
  21342 		VP8SSIMDspInit(tls)
  21343 	}
  21344 }
  21345 
  21346 func VP8StoreFilterStats(tls *libc.TLS, it uintptr) {
  21347 	var d, delta_max, delta_min, level, level0, s, step_size, v1 int32
  21348 	var enc uintptr
  21349 	_, _, _, _, _, _, _, _, _ = d, delta_max, delta_min, enc, level, level0, s, step_size, v1
  21350 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21351 	s = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  21352 	level0 = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength
  21353 	// explore +/-quant range of values around level0
  21354 	delta_min = -(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21355 	delta_max = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21356 	if delta_max-delta_min >= int32(4) {
  21357 		v1 = int32(4)
  21358 	} else {
  21359 		v1 = int32(1)
  21360 	}
  21361 	step_size = v1
  21362 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats == libc.UintptrFromInt32(0) {
  21363 		return
  21364 	}
  21365 	// NOTE: Currently we are applying filter only across the sublock edges
  21366 	// There are two reasons for that.
  21367 	// 1. Applying filter on macro block edges will change the pixels in
  21368 	// the left and top macro blocks. That will be hard to restore
  21369 	// 2. Macro Blocks on the bottom and right are not yet compressed. So we
  21370 	// cannot apply filter on the right and bottom macro block edges.
  21371 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) && int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x10>>4)) != 0 {
  21372 		return
  21373 	}
  21374 	// Always try filter level  zero
  21375 	**(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512)) += GetMBSSIM(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out)
  21376 	d = delta_min
  21377 	for {
  21378 		if !(d <= delta_max) {
  21379 			break
  21380 		}
  21381 		level = level0 + d
  21382 		if level <= 0 || level >= int32(MAX_LF_LEVELS) {
  21383 			goto _2
  21384 		}
  21385 		DoFilter1(tls, it, level)
  21386 		**(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(level)*8)) += GetMBSSIM(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2)
  21387 		goto _2
  21388 	_2:
  21389 		;
  21390 		d = d + step_size
  21391 	}
  21392 }
  21393 
  21394 func VP8AdjustFilterStrength(tls *libc.TLS, it uintptr) {
  21395 	var best_level, delta, i, level, max_level, s, s1 int32
  21396 	var best_v, v float64
  21397 	var dqm, enc uintptr
  21398 	_, _, _, _, _, _, _, _, _, _, _ = best_level, best_v, delta, dqm, enc, i, level, max_level, s, s1, v
  21399 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21400 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21401 		s = 0
  21402 		for {
  21403 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21404 				break
  21405 			}
  21406 			best_level = 0
  21407 			// Improvement over filter level 0 should be at least 1e-5 (relatively)
  21408 			best_v = float64(float64(1.00001) * **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512)))
  21409 			i = int32(1)
  21410 			for {
  21411 				if !(i < int32(MAX_LF_LEVELS)) {
  21412 					break
  21413 				}
  21414 				v = **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8))
  21415 				if v > best_v {
  21416 					best_v = v
  21417 					best_level = i
  21418 				}
  21419 				goto _2
  21420 			_2:
  21421 				;
  21422 				i = i + 1
  21423 			}
  21424 			(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength = best_level
  21425 			goto _1
  21426 		_1:
  21427 			;
  21428 			s = s + 1
  21429 		}
  21430 		return
  21431 	}
  21432 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength > 0 {
  21433 		max_level = 0
  21434 		s1 = 0
  21435 		for {
  21436 			if !(s1 < int32(NUM_MB_SEGMENTS)) {
  21437 				break
  21438 			}
  21439 			dqm = enc + 608 + uintptr(s1)*744
  21440 			// this '>> 3' accounts for some inverse WHT scaling
  21441 			delta = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(dqm + 224 + 1*2))) >> int32(3)
  21442 			level = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, delta)
  21443 			if level > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21444 				(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength = level
  21445 			}
  21446 			if max_level < (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21447 				max_level = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength
  21448 			}
  21449 			goto _3
  21450 		_3:
  21451 			;
  21452 			s1 = s1 + 1
  21453 		}
  21454 		(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = max_level
  21455 	}
  21456 }
  21457 
  21458 const DEBUG_SEARCH = 0
  21459 const DQ_LIMIT = 0.4
  21460 const FP_ILOGB0 = "FP_ILOGBNAN"
  21461 const FP_INFINITE = 1
  21462 const FP_NAN = 0
  21463 const FP_NORMAL = 4
  21464 const FP_SUBNORMAL = 3
  21465 const FP_ZERO = 2
  21466 const HUGE = 3.40282346638528859812e+38
  21467 const HUGE_VALF = "INFINITY"
  21468 const MATH_ERREXCEPT = 2
  21469 const MATH_ERRNO = 1
  21470 const MIN_COUNT = 96
  21471 const M_1_PI = 0.31830988618379067154
  21472 const M_2_PI = 0.63661977236758134308
  21473 const M_2_SQRTPI = 1.12837916709551257390
  21474 const M_E = 2.7182818284590452354
  21475 const M_LN10 = 2.30258509299404568402
  21476 const M_LN2 = 0.69314718055994530942
  21477 const M_LOG10E = 0.43429448190325182765
  21478 const M_LOG2E = 1.4426950408889634074
  21479 const M_PI = 3.14159265358979323846
  21480 const M_PI_2 = 1.57079632679489661923
  21481 const M_PI_4 = 0.78539816339744830962
  21482 const M_SQRT1_2 = 0.70710678118654752440
  21483 const M_SQRT2 = 1.41421356237309504880
  21484 const SEGMENT_VISU = 0
  21485 const SKIP_PROBA_THRESHOLD = 250
  21486 const math_errhandling = 2
  21487 
  21488 type float_t = float32
  21489 
  21490 type double_t = float64
  21491 
  21492 // Alpha related constants.
  21493 
  21494 // Mux related constants.
  21495 
  21496 // Maximum chunk payload is such that adding the header and padding won't
  21497 // overflow a uint32_t.
  21498 
  21499 //------------------------------------------------------------------------------
  21500 // multi-pass convergence
  21501 
  21502 // we allow 2k of extra head-room in PARTITION0 limit.
  21503 
  21504 func Clamp(tls *libc.TLS, v float32, min float32, max float32) (r float32) {
  21505 	var v1, v2 float32
  21506 	_, _ = v1, v2
  21507 	if v < min {
  21508 		v1 = min
  21509 	} else {
  21510 		if v > max {
  21511 			v2 = max
  21512 		} else {
  21513 			v2 = v
  21514 		}
  21515 		v1 = v2
  21516 	}
  21517 	return v1
  21518 }
  21519 
  21520 type PassStats = struct {
  21521 	Fis_first       int32
  21522 	Fdq             float32
  21523 	Fq              float32
  21524 	Flast_q         float32
  21525 	Fqmin           float32
  21526 	Fqmax           float32
  21527 	Fvalue          float64
  21528 	Flast_value     float64
  21529 	Ftarget         float64
  21530 	Fdo_size_search int32
  21531 }
  21532 
  21533 func InitPassStats(tls *libc.TLS, enc uintptr, s uintptr) (r int32) {
  21534 	var do_size_search int32
  21535 	var target_PSNR, v1 float32
  21536 	var target_size uint64_t
  21537 	var v2, v3 float64
  21538 	_, _, _, _, _, _ = do_size_search, target_PSNR, target_size, v1, v2, v3
  21539 	target_size = libc.Uint64FromInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_size)
  21540 	do_size_search = libc.BoolInt32(target_size != libc.Uint64FromInt32(0))
  21541 	target_PSNR = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_PSNR
  21542 	(*PassStats)(unsafe.Pointer(s)).Fis_first = int32(1)
  21543 	(*PassStats)(unsafe.Pointer(s)).Fdq = libc.Float32FromFloat32(10)
  21544 	(*PassStats)(unsafe.Pointer(s)).Fqmin = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmin))
  21545 	(*PassStats)(unsafe.Pointer(s)).Fqmax = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmax))
  21546 	v1 = Clamp(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fquality, (*PassStats)(unsafe.Pointer(s)).Fqmin, (*PassStats)(unsafe.Pointer(s)).Fqmax)
  21547 	(*PassStats)(unsafe.Pointer(s)).Flast_q = v1
  21548 	(*PassStats)(unsafe.Pointer(s)).Fq = v1
  21549 	if do_size_search != 0 {
  21550 		v2 = float64(target_size)
  21551 	} else {
  21552 		if float64(target_PSNR) > float64(0) {
  21553 			v3 = float64(target_PSNR)
  21554 		} else {
  21555 			v3 = float64(40)
  21556 		}
  21557 		v2 = v3
  21558 	}
  21559 	(*PassStats)(unsafe.Pointer(s)).Ftarget = v2 // default, just in case
  21560 	v2 = libc.Float64FromFloat64(0)
  21561 	(*PassStats)(unsafe.Pointer(s)).Flast_value = v2
  21562 	(*PassStats)(unsafe.Pointer(s)).Fvalue = v2
  21563 	(*PassStats)(unsafe.Pointer(s)).Fdo_size_search = do_size_search
  21564 	return do_size_search
  21565 }
  21566 
  21567 func ComputeNextQ(tls *libc.TLS, s uintptr) (r float32) {
  21568 	var dq, v1 float32
  21569 	var slope float64
  21570 	_, _, _ = dq, slope, v1
  21571 	if (*PassStats)(unsafe.Pointer(s)).Fis_first != 0 {
  21572 		if (*PassStats)(unsafe.Pointer(s)).Fvalue > (*PassStats)(unsafe.Pointer(s)).Ftarget {
  21573 			v1 = -(*PassStats)(unsafe.Pointer(s)).Fdq
  21574 		} else {
  21575 			v1 = (*PassStats)(unsafe.Pointer(s)).Fdq
  21576 		}
  21577 		dq = v1
  21578 		(*PassStats)(unsafe.Pointer(s)).Fis_first = 0
  21579 	} else {
  21580 		if (*PassStats)(unsafe.Pointer(s)).Fvalue != (*PassStats)(unsafe.Pointer(s)).Flast_value {
  21581 			slope = ((*PassStats)(unsafe.Pointer(s)).Ftarget - (*PassStats)(unsafe.Pointer(s)).Fvalue) / ((*PassStats)(unsafe.Pointer(s)).Flast_value - (*PassStats)(unsafe.Pointer(s)).Fvalue)
  21582 			dq = float32(float64(slope * float64((*PassStats)(unsafe.Pointer(s)).Flast_q-(*PassStats)(unsafe.Pointer(s)).Fq)))
  21583 		} else {
  21584 			dq = float32(0) // we're done?!
  21585 		}
  21586 	}
  21587 	// Limit variable to avoid large swings.
  21588 	(*PassStats)(unsafe.Pointer(s)).Fdq = Clamp(tls, dq, -libc.Float32FromFloat32(30), libc.Float32FromFloat32(30))
  21589 	(*PassStats)(unsafe.Pointer(s)).Flast_q = (*PassStats)(unsafe.Pointer(s)).Fq
  21590 	(*PassStats)(unsafe.Pointer(s)).Flast_value = (*PassStats)(unsafe.Pointer(s)).Fvalue
  21591 	(*PassStats)(unsafe.Pointer(s)).Fq = Clamp(tls, (*PassStats)(unsafe.Pointer(s)).Fq+(*PassStats)(unsafe.Pointer(s)).Fdq, (*PassStats)(unsafe.Pointer(s)).Fqmin, (*PassStats)(unsafe.Pointer(s)).Fqmax)
  21592 	return (*PassStats)(unsafe.Pointer(s)).Fq
  21593 }
  21594 
  21595 //------------------------------------------------------------------------------
  21596 // Reset the statistics about: number of skips, token proba, level cost,...
  21597 
  21598 func ResetStats(tls *libc.TLS, enc uintptr) {
  21599 	var proba uintptr
  21600 	_ = proba
  21601 	proba = enc + 3616
  21602 	VP8CalculateLevelCosts(tls, proba)
  21603 	(*VP8EncProba)(unsafe.Pointer(proba)).Fnb_skip = 0
  21604 }
  21605 
  21606 //------------------------------------------------------------------------------
  21607 // Skip decision probability
  21608 
  21609 func CalcSkipProba(tls *libc.TLS, nb uint64_t, total uint64_t) (r int32) {
  21610 	var v1 uint64
  21611 	_ = v1
  21612 	if total != 0 {
  21613 		v1 = (total - nb) * uint64(255) / total
  21614 	} else {
  21615 		v1 = uint64(255)
  21616 	}
  21617 	return libc.Int32FromUint64(v1)
  21618 }
  21619 
  21620 // C documentation
  21621 //
  21622 //	// Returns the bit-cost for coding the skip probability.
  21623 func FinalizeSkipProba(tls *libc.TLS, enc uintptr) (r int32) {
  21624 	var nb_events, nb_mbs, size, v2, v4, v6, v8 int32
  21625 	var proba1 uintptr
  21626 	var v1, v5 uint8_t
  21627 	_, _, _, _, _, _, _, _, _, _ = nb_events, nb_mbs, proba1, size, v1, v2, v4, v5, v6, v8
  21628 	proba1 = enc + 3616
  21629 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  21630 	nb_events = (*VP8EncProba)(unsafe.Pointer(proba1)).Fnb_skip
  21631 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba = libc.Uint8FromInt32(CalcSkipProba(tls, libc.Uint64FromInt32(nb_events), libc.Uint64FromInt32(nb_mbs)))
  21632 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba = libc.BoolInt32(libc.Int32FromUint8((*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba) < int32(SKIP_PROBA_THRESHOLD))
  21633 	size = int32(256) // 'use_skip_proba' bit
  21634 	if (*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba != 0 {
  21635 		v1 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  21636 		if !(int32(1) != 0) {
  21637 			v4 = libc.Int32FromUint16(VP8EntropyCost[v1])
  21638 		} else {
  21639 			v4 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v1)])
  21640 		}
  21641 		v2 = v4
  21642 		goto _3
  21643 	_3:
  21644 		v5 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  21645 		if !(0 != 0) {
  21646 			v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  21647 		} else {
  21648 			v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  21649 		}
  21650 		v6 = v8
  21651 		goto _7
  21652 	_7:
  21653 		size = size + (nb_events*v2 + (nb_mbs-nb_events)*v6)
  21654 		size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256) // cost of signaling the 'skip_proba' itself.
  21655 	}
  21656 	return size
  21657 }
  21658 
  21659 // C documentation
  21660 //
  21661 //	// Collect statistics and deduce probabilities for next coding pass.
  21662 //	// Return the total bit-cost for coding the probability updates.
  21663 func CalcTokenProba(tls *libc.TLS, nb int32, total int32) (r int32) {
  21664 	var v1 int32
  21665 	_ = v1
  21666 	if nb != 0 {
  21667 		v1 = int32(255) - nb*int32(255)/total
  21668 	} else {
  21669 		v1 = int32(255)
  21670 	}
  21671 	return v1
  21672 }
  21673 
  21674 // C documentation
  21675 //
  21676 //	// Cost of coding 'nb' 1's and 'total-nb' 0's using 'proba' probability.
  21677 func BranchCost(tls *libc.TLS, nb int32, total int32, proba1 int32) (r int32) {
  21678 	var v1, v5 uint8_t
  21679 	var v2, v4, v6, v8 int32
  21680 	_, _, _, _, _, _ = v1, v2, v4, v5, v6, v8
  21681 	v1 = libc.Uint8FromInt32(proba1)
  21682 	if !(int32(1) != 0) {
  21683 		v4 = libc.Int32FromUint16(VP8EntropyCost[v1])
  21684 	} else {
  21685 		v4 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v1)])
  21686 	}
  21687 	v2 = v4
  21688 	goto _3
  21689 _3:
  21690 	v5 = libc.Uint8FromInt32(proba1)
  21691 	if !(0 != 0) {
  21692 		v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  21693 	} else {
  21694 		v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  21695 	}
  21696 	v6 = v8
  21697 	goto _7
  21698 _7:
  21699 	return nb*v2 + (total-nb)*v6
  21700 }
  21701 
  21702 func ResetTokenStats(tls *libc.TLS, enc uintptr) {
  21703 	var proba uintptr
  21704 	_ = proba
  21705 	proba = enc + 3616
  21706 	libc.Xmemset(tls, proba+1060, 0, uint64(4224))
  21707 }
  21708 
  21709 func FinalizeTokenProbas(tls *libc.TLS, proba1 uintptr) (r int32) {
  21710 	var b, c, has_changed, nb, new_cost, new_p, old_cost, old_p, p, size, t, total, update_proba, use_new_p, v10, v12, v14, v16, v6, v8 int32
  21711 	var stats proba_t
  21712 	var v13, v5, v9 uint8_t
  21713 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, c, has_changed, nb, new_cost, new_p, old_cost, old_p, p, size, stats, t, total, update_proba, use_new_p, v10, v12, v13, v14, v16, v5, v6, v8, v9
  21714 	has_changed = 0
  21715 	size = 0
  21716 	t = 0
  21717 	for {
  21718 		if !(t < int32(NUM_TYPES)) {
  21719 			break
  21720 		}
  21721 		b = 0
  21722 		for {
  21723 			if !(b < int32(NUM_BANDS)) {
  21724 				break
  21725 			}
  21726 			c = 0
  21727 			for {
  21728 				if !(c < int32(NUM_CTX)) {
  21729 					break
  21730 				}
  21731 				p = 0
  21732 				for {
  21733 					if !(p < int32(NUM_PROBAS)) {
  21734 						break
  21735 					}
  21736 					stats = **(**proba_t)(__ccgo_up(proba1 + 1060 + uintptr(t)*1056 + uintptr(b)*132 + uintptr(c)*44 + uintptr(p)*4))
  21737 					nb = libc.Int32FromUint32(stats >> libc.Int32FromInt32(0) & uint32(0xffff))
  21738 					total = libc.Int32FromUint32(stats >> libc.Int32FromInt32(16) & uint32(0xffff))
  21739 					update_proba = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  21740 					old_p = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  21741 					new_p = CalcTokenProba(tls, nb, total)
  21742 					v5 = libc.Uint8FromInt32(update_proba)
  21743 					if !(0 != 0) {
  21744 						v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  21745 					} else {
  21746 						v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  21747 					}
  21748 					v6 = v8
  21749 					goto _7
  21750 				_7:
  21751 					old_cost = BranchCost(tls, nb, total, old_p) + v6
  21752 					v9 = libc.Uint8FromInt32(update_proba)
  21753 					if !(int32(1) != 0) {
  21754 						v12 = libc.Int32FromUint16(VP8EntropyCost[v9])
  21755 					} else {
  21756 						v12 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v9)])
  21757 					}
  21758 					v10 = v12
  21759 					goto _11
  21760 				_11:
  21761 					new_cost = BranchCost(tls, nb, total, new_p) + v10 + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  21762 					use_new_p = libc.BoolInt32(old_cost > new_cost)
  21763 					v13 = libc.Uint8FromInt32(update_proba)
  21764 					if !(use_new_p != 0) {
  21765 						v16 = libc.Int32FromUint16(VP8EntropyCost[v13])
  21766 					} else {
  21767 						v16 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v13)])
  21768 					}
  21769 					v14 = v16
  21770 					goto _15
  21771 				_15:
  21772 					size = size + v14
  21773 					if use_new_p != 0 { // only use proba that seem meaningful enough.
  21774 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = libc.Uint8FromInt32(new_p)
  21775 						has_changed = has_changed | libc.BoolInt32(new_p != old_p)
  21776 						size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  21777 					} else {
  21778 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = libc.Uint8FromInt32(old_p)
  21779 					}
  21780 					goto _4
  21781 				_4:
  21782 					;
  21783 					p = p + 1
  21784 				}
  21785 				goto _3
  21786 			_3:
  21787 				;
  21788 				c = c + 1
  21789 			}
  21790 			goto _2
  21791 		_2:
  21792 			;
  21793 			b = b + 1
  21794 		}
  21795 		goto _1
  21796 	_1:
  21797 		;
  21798 		t = t + 1
  21799 	}
  21800 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = has_changed
  21801 	return size
  21802 }
  21803 
  21804 //------------------------------------------------------------------------------
  21805 // Finalize Segment probability based on the coding tree
  21806 
  21807 func GetProba(tls *libc.TLS, a int32, b int32) (r int32) {
  21808 	var total, v1 int32
  21809 	_, _ = total, v1
  21810 	total = a + b
  21811 	if total == 0 {
  21812 		v1 = int32(255)
  21813 	} else {
  21814 		v1 = (int32(255)*a + total/int32(2)) / total
  21815 	}
  21816 	return v1 // rounded proba
  21817 }
  21818 
  21819 func ResetSegments(tls *libc.TLS, enc uintptr) {
  21820 	var n int32
  21821 	_ = n
  21822 	n = 0
  21823 	for {
  21824 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  21825 			break
  21826 		}
  21827 		libc.SetBitFieldPtr8Uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4+0, libc.Uint32FromInt32(0), 5, 0x60)
  21828 		goto _1
  21829 	_1:
  21830 		;
  21831 		n = n + 1
  21832 	}
  21833 }
  21834 
  21835 func SetSegmentProbas(tls *libc.TLS, enc uintptr) {
  21836 	var mb, probas uintptr
  21837 	var n, v10, v12, v14, v16, v18, v20, v22, v24, v26, v28, v30, v32, v34, v4, v6, v8 int32
  21838 	var p [4]int32
  21839 	var v11, v15, v19, v23, v27, v3, v31, v7 uint8_t
  21840 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = mb, n, p, probas, v10, v11, v12, v14, v15, v16, v18, v19, v20, v22, v23, v24, v26, v27, v28, v3, v30, v31, v32, v34, v4, v6, v7, v8
  21841 	p = [4]int32{}
  21842 	n = 0
  21843 	for {
  21844 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  21845 			break
  21846 		}
  21847 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  21848 		p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] = p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] + 1
  21849 		goto _1
  21850 	_1:
  21851 		;
  21852 		n = n + 1
  21853 	}
  21854 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  21855 		n = 0
  21856 		for {
  21857 			if !(n < int32(NUM_MB_SEGMENTS)) {
  21858 				break
  21859 			}
  21860 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 92 + uintptr(n)*4)) = p[n]
  21861 			goto _2
  21862 		_2:
  21863 			;
  21864 			n = n + 1
  21865 		}
  21866 	}
  21867 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments > int32(1) {
  21868 		probas = enc + 3616
  21869 		**(**uint8_t)(__ccgo_up(probas)) = libc.Uint8FromInt32(GetProba(tls, p[0]+p[int32(1)], p[int32(2)]+p[int32(3)]))
  21870 		**(**uint8_t)(__ccgo_up(probas + 1)) = libc.Uint8FromInt32(GetProba(tls, p[0], p[int32(1)]))
  21871 		**(**uint8_t)(__ccgo_up(probas + 2)) = libc.Uint8FromInt32(GetProba(tls, p[int32(2)], p[int32(3)]))
  21872 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map = libc.BoolInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas))) != int32(255) || libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas + 1))) != int32(255) || libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas + 2))) != int32(255))
  21873 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0) {
  21874 			ResetSegments(tls, enc)
  21875 		}
  21876 		v3 = **(**uint8_t)(__ccgo_up(probas))
  21877 		if !(0 != 0) {
  21878 			v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  21879 		} else {
  21880 			v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  21881 		}
  21882 		v4 = v6
  21883 		goto _5
  21884 	_5:
  21885 		v7 = **(**uint8_t)(__ccgo_up(probas + 1))
  21886 		if !(0 != 0) {
  21887 			v10 = libc.Int32FromUint16(VP8EntropyCost[v7])
  21888 		} else {
  21889 			v10 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v7)])
  21890 		}
  21891 		v8 = v10
  21892 		goto _9
  21893 	_9:
  21894 		v11 = **(**uint8_t)(__ccgo_up(probas))
  21895 		if !(0 != 0) {
  21896 			v14 = libc.Int32FromUint16(VP8EntropyCost[v11])
  21897 		} else {
  21898 			v14 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v11)])
  21899 		}
  21900 		v12 = v14
  21901 		goto _13
  21902 	_13:
  21903 		v15 = **(**uint8_t)(__ccgo_up(probas + 1))
  21904 		if !(int32(1) != 0) {
  21905 			v18 = libc.Int32FromUint16(VP8EntropyCost[v15])
  21906 		} else {
  21907 			v18 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v15)])
  21908 		}
  21909 		v16 = v18
  21910 		goto _17
  21911 	_17:
  21912 		v19 = **(**uint8_t)(__ccgo_up(probas))
  21913 		if !(int32(1) != 0) {
  21914 			v22 = libc.Int32FromUint16(VP8EntropyCost[v19])
  21915 		} else {
  21916 			v22 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v19)])
  21917 		}
  21918 		v20 = v22
  21919 		goto _21
  21920 	_21:
  21921 		v23 = **(**uint8_t)(__ccgo_up(probas + 2))
  21922 		if !(0 != 0) {
  21923 			v26 = libc.Int32FromUint16(VP8EntropyCost[v23])
  21924 		} else {
  21925 			v26 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v23)])
  21926 		}
  21927 		v24 = v26
  21928 		goto _25
  21929 	_25:
  21930 		v27 = **(**uint8_t)(__ccgo_up(probas))
  21931 		if !(int32(1) != 0) {
  21932 			v30 = libc.Int32FromUint16(VP8EntropyCost[v27])
  21933 		} else {
  21934 			v30 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v27)])
  21935 		}
  21936 		v28 = v30
  21937 		goto _29
  21938 	_29:
  21939 		v31 = **(**uint8_t)(__ccgo_up(probas + 2))
  21940 		if !(int32(1) != 0) {
  21941 			v34 = libc.Int32FromUint16(VP8EntropyCost[v31])
  21942 		} else {
  21943 			v34 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v31)])
  21944 		}
  21945 		v32 = v34
  21946 		goto _33
  21947 	_33:
  21948 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize = p[0]*(v4+v8) + p[int32(1)]*(v12+v16) + p[int32(2)]*(v20+v24) + p[int32(3)]*(v28+v32)
  21949 	} else {
  21950 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map = 0
  21951 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize = 0
  21952 	}
  21953 }
  21954 
  21955 //------------------------------------------------------------------------------
  21956 // Coefficient coding
  21957 
  21958 func PutCoeffs(tls *libc.TLS, bw uintptr, ctx int32, res uintptr) (r int32) {
  21959 	var c, mask, n, sign, v, v1, v2 int32
  21960 	var p, tab, v3 uintptr
  21961 	_, _, _, _, _, _, _, _, _, _ = c, mask, n, p, sign, tab, v, v1, v2, v3
  21962 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  21963 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  21964 	p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx)*11
  21965 	if !(VP8PutBit(tls, bw, libc.BoolInt32((*VP8Residual)(unsafe.Pointer(res)).Flast >= 0), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  21966 		return 0
  21967 	}
  21968 	for n < int32(16) {
  21969 		v1 = n
  21970 		n = n + 1
  21971 		c = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v1)*2)))
  21972 		sign = libc.BoolInt32(c < 0)
  21973 		if sign != 0 {
  21974 			v2 = -c
  21975 		} else {
  21976 			v2 = c
  21977 		}
  21978 		v = v2
  21979 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v != 0), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1)))) != 0) {
  21980 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33
  21981 			continue
  21982 		}
  21983 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(1)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 2)))) != 0) {
  21984 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 1*11
  21985 		} else {
  21986 			if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(4)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 3)))) != 0) {
  21987 				if VP8PutBit(tls, bw, libc.BoolInt32(v != int32(2)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 4)))) != 0 {
  21988 					VP8PutBit(tls, bw, libc.BoolInt32(v == int32(4)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 5))))
  21989 				}
  21990 			} else {
  21991 				if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(10)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 6)))) != 0) {
  21992 					if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(6)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 7)))) != 0) {
  21993 						VP8PutBit(tls, bw, libc.BoolInt32(v == int32(6)), int32(159))
  21994 					} else {
  21995 						VP8PutBit(tls, bw, libc.BoolInt32(v >= int32(9)), int32(165))
  21996 						VP8PutBit(tls, bw, libc.BoolInt32(!(v&libc.Int32FromInt32(1) != 0)), int32(145))
  21997 					}
  21998 				} else {
  21999 					if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(1) { // VP8Cat3  (3b)
  22000 						VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22001 						VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 9))))
  22002 						v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  22003 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  22004 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  22005 					} else {
  22006 						if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(2) { // VP8Cat4  (4b)
  22007 							VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22008 							VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 9))))
  22009 							v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  22010 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  22011 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  22012 						} else {
  22013 							if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(3) { // VP8Cat5  (5b)
  22014 								VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22015 								VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 10))))
  22016 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  22017 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  22018 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  22019 							} else { // VP8Cat6 (11b)
  22020 								VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22021 								VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 10))))
  22022 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  22023 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  22024 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  22025 							}
  22026 						}
  22027 					}
  22028 					for mask != 0 {
  22029 						v3 = tab
  22030 						tab = tab + 1
  22031 						VP8PutBit(tls, bw, libc.BoolInt32(!!(v&mask != 0)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v3))))
  22032 						mask = mask >> int32(1)
  22033 					}
  22034 				}
  22035 			}
  22036 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 2*11
  22037 		}
  22038 		VP8PutBitUniform(tls, bw, sign)
  22039 		if n == int32(16) || !(VP8PutBit(tls, bw, libc.BoolInt32(n <= (*VP8Residual)(unsafe.Pointer(res)).Flast), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22040 			return int32(1) // EOB
  22041 		}
  22042 	}
  22043 	return int32(1)
  22044 }
  22045 
  22046 func CodeResiduals(tls *libc.TLS, bw1 uintptr, it uintptr, rd uintptr) {
  22047 	bp := tls.Alloc(48)
  22048 	defer tls.Free(48)
  22049 	var ch, ctx, ctx1, i16, segment, x, y, v4 int32
  22050 	var enc, v1 uintptr
  22051 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  22052 	var _ /* res at bp+0 */ VP8Residual
  22053 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, ctx1, enc, i16, nb_bits, pos1, pos2, pos3, segment, x, y, v1, v2, v4
  22054 	i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  22055 	segment = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  22056 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22057 	VP8IteratorNzToBytes(tls, it)
  22058 	v1 = bw1
  22059 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22060 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22061 	goto _3
  22062 _3:
  22063 	pos1 = v2
  22064 	if i16 != 0 {
  22065 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22066 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22067 		v4 = PutCoeffs(tls, bw1, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22068 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v4
  22069 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v4
  22070 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22071 	} else {
  22072 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22073 	}
  22074 	// luma-AC
  22075 	y = 0
  22076 	for {
  22077 		if !(y < int32(4)) {
  22078 			break
  22079 		}
  22080 		x = 0
  22081 		for {
  22082 			if !(x < int32(4)) {
  22083 				break
  22084 			}
  22085 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22086 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22087 			v4 = PutCoeffs(tls, bw1, ctx, bp)
  22088 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  22089 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  22090 			goto _6
  22091 		_6:
  22092 			;
  22093 			x = x + 1
  22094 		}
  22095 		goto _5
  22096 	_5:
  22097 		;
  22098 		y = y + 1
  22099 	}
  22100 	v1 = bw1
  22101 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22102 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22103 	goto _10
  22104 _10:
  22105 	pos2 = v2
  22106 	// U/V
  22107 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22108 	ch = 0
  22109 	for {
  22110 		if !(ch <= int32(2)) {
  22111 			break
  22112 		}
  22113 		y = 0
  22114 		for {
  22115 			if !(y < int32(2)) {
  22116 				break
  22117 			}
  22118 			x = 0
  22119 			for {
  22120 				if !(x < int32(2)) {
  22121 					break
  22122 				}
  22123 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22124 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22125 				v4 = PutCoeffs(tls, bw1, ctx1, bp)
  22126 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  22127 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  22128 				goto _13
  22129 			_13:
  22130 				;
  22131 				x = x + 1
  22132 			}
  22133 			goto _12
  22134 		_12:
  22135 			;
  22136 			y = y + 1
  22137 		}
  22138 		goto _11
  22139 	_11:
  22140 		;
  22141 		ch = ch + int32(2)
  22142 	}
  22143 	v1 = bw1
  22144 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22145 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22146 	goto _17
  22147 _17:
  22148 	pos3 = v2
  22149 	(*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits = pos2 - pos1
  22150 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits = pos3 - pos2
  22151 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + uintptr(i16)*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits
  22152 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + 2*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits
  22153 	VP8IteratorBytesToNz(tls, it)
  22154 }
  22155 
  22156 // C documentation
  22157 //
  22158 //	// Same as CodeResiduals, but doesn't actually write anything.
  22159 //	// Instead, it just records the event distribution.
  22160 func RecordResiduals(tls *libc.TLS, it uintptr, rd uintptr) {
  22161 	bp := tls.Alloc(48)
  22162 	defer tls.Free(48)
  22163 	var ch, ctx, ctx1, x, y, v1 int32
  22164 	var enc uintptr
  22165 	var _ /* res at bp+0 */ VP8Residual
  22166 	_, _, _, _, _, _, _ = ch, ctx, ctx1, enc, x, y, v1
  22167 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22168 	VP8IteratorNzToBytes(tls, it)
  22169 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22170 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22171 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22172 		v1 = VP8RecordCoeffs(tls, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22173 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22174 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22175 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22176 	} else {
  22177 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22178 	}
  22179 	// luma-AC
  22180 	y = 0
  22181 	for {
  22182 		if !(y < int32(4)) {
  22183 			break
  22184 		}
  22185 		x = 0
  22186 		for {
  22187 			if !(x < int32(4)) {
  22188 				break
  22189 			}
  22190 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22191 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22192 			v1 = VP8RecordCoeffs(tls, ctx, bp)
  22193 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22194 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22195 			goto _3
  22196 		_3:
  22197 			;
  22198 			x = x + 1
  22199 		}
  22200 		goto _2
  22201 	_2:
  22202 		;
  22203 		y = y + 1
  22204 	}
  22205 	// U/V
  22206 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22207 	ch = 0
  22208 	for {
  22209 		if !(ch <= int32(2)) {
  22210 			break
  22211 		}
  22212 		y = 0
  22213 		for {
  22214 			if !(y < int32(2)) {
  22215 				break
  22216 			}
  22217 			x = 0
  22218 			for {
  22219 				if !(x < int32(2)) {
  22220 					break
  22221 				}
  22222 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22223 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22224 				v1 = VP8RecordCoeffs(tls, ctx1, bp)
  22225 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22226 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22227 				goto _7
  22228 			_7:
  22229 				;
  22230 				x = x + 1
  22231 			}
  22232 			goto _6
  22233 		_6:
  22234 			;
  22235 			y = y + 1
  22236 		}
  22237 		goto _5
  22238 	_5:
  22239 		;
  22240 		ch = ch + int32(2)
  22241 	}
  22242 	VP8IteratorBytesToNz(tls, it)
  22243 }
  22244 
  22245 //------------------------------------------------------------------------------
  22246 // Token buffer
  22247 
  22248 func RecordTokens(tls *libc.TLS, it uintptr, rd uintptr, tokens uintptr) (r int32) {
  22249 	bp := tls.Alloc(48)
  22250 	defer tls.Free(48)
  22251 	var ch, ctx, ctx1, ctx2, x, y, v1 int32
  22252 	var enc uintptr
  22253 	var _ /* res at bp+0 */ VP8Residual
  22254 	_, _, _, _, _, _, _, _ = ch, ctx, ctx1, ctx2, enc, x, y, v1
  22255 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22256 	VP8IteratorNzToBytes(tls, it)
  22257 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22258 		ctx = **(**int32)(__ccgo_up(it + 132 + 8*4)) + **(**int32)(__ccgo_up(it + 168 + 8*4))
  22259 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22260 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22261 		v1 = VP8RecordCoeffTokens(tls, ctx, bp, tokens)
  22262 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22263 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22264 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22265 	} else {
  22266 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22267 	}
  22268 	// luma-AC
  22269 	y = 0
  22270 	for {
  22271 		if !(y < int32(4)) {
  22272 			break
  22273 		}
  22274 		x = 0
  22275 		for {
  22276 			if !(x < int32(4)) {
  22277 				break
  22278 			}
  22279 			ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22280 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22281 			v1 = VP8RecordCoeffTokens(tls, ctx1, bp, tokens)
  22282 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22283 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22284 			goto _3
  22285 		_3:
  22286 			;
  22287 			x = x + 1
  22288 		}
  22289 		goto _2
  22290 	_2:
  22291 		;
  22292 		y = y + 1
  22293 	}
  22294 	// U/V
  22295 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22296 	ch = 0
  22297 	for {
  22298 		if !(ch <= int32(2)) {
  22299 			break
  22300 		}
  22301 		y = 0
  22302 		for {
  22303 			if !(y < int32(2)) {
  22304 				break
  22305 			}
  22306 			x = 0
  22307 			for {
  22308 				if !(x < int32(2)) {
  22309 					break
  22310 				}
  22311 				ctx2 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22312 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22313 				v1 = VP8RecordCoeffTokens(tls, ctx2, bp, tokens)
  22314 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22315 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22316 				goto _7
  22317 			_7:
  22318 				;
  22319 				x = x + 1
  22320 			}
  22321 			goto _6
  22322 		_6:
  22323 			;
  22324 			y = y + 1
  22325 		}
  22326 		goto _5
  22327 	_5:
  22328 		;
  22329 		ch = ch + int32(2)
  22330 	}
  22331 	VP8IteratorBytesToNz(tls, it)
  22332 	return libc.BoolInt32(!((*VP8TBuffer)(unsafe.Pointer(tokens)).Ferror1 != 0))
  22333 }
  22334 
  22335 //------------------------------------------------------------------------------
  22336 // ExtraInfo map / Debug function
  22337 
  22338 func ResetSSE(tls *libc.TLS, enc uintptr) {
  22339 	**(**uint64_t)(__ccgo_up(enc + 23512)) = uint64(0)
  22340 	**(**uint64_t)(__ccgo_up(enc + 23512 + 1*8)) = uint64(0)
  22341 	**(**uint64_t)(__ccgo_up(enc + 23512 + 2*8)) = uint64(0)
  22342 	// Note: enc->sse[3] is managed by alpha.c
  22343 	(*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count = uint64(0)
  22344 }
  22345 
  22346 func StoreSSE(tls *libc.TLS, it uintptr) {
  22347 	var enc, in, out uintptr
  22348 	_, _, _ = enc, in, out
  22349 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22350 	in = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in
  22351 	out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out
  22352 	// Note: not totally accurate at boundary. And doesn't include in-loop filter.
  22353 	**(**uint64_t)(__ccgo_up(enc + 23512)) += libc.Uint64FromInt32((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x16})))(tls, in+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), out+uintptr(libc.Int32FromInt32(Y_OFF_ENC))))
  22354 	**(**uint64_t)(__ccgo_up(enc + 23512 + 1*8)) += libc.Uint64FromInt32((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE8x8})))(tls, in+uintptr(libc.Int32FromInt32(U_OFF_ENC)), out+uintptr(libc.Int32FromInt32(U_OFF_ENC))))
  22355 	**(**uint64_t)(__ccgo_up(enc + 23512 + 2*8)) += libc.Uint64FromInt32((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE8x8})))(tls, in+uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8)), out+uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))))
  22356 	**(**uint64_t)(__ccgo_up(enc + 23544)) += libc.Uint64FromInt32(libc.Int32FromInt32(16) * libc.Int32FromInt32(16))
  22357 }
  22358 
  22359 func StoreSideInfo(tls *libc.TLS, it uintptr) {
  22360 	var b, v1 int32
  22361 	var enc, info, mb, pic uintptr
  22362 	_, _, _, _, _, _ = b, enc, info, mb, pic, v1
  22363 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22364 	mb = (*VP8EncIterator)(unsafe.Pointer(it)).Fmb
  22365 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22366 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22367 		StoreSSE(tls, it)
  22368 		**(**int32)(__ccgo_up(enc + 23604)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == 0)
  22369 		**(**int32)(__ccgo_up(enc + 23604 + 1*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1))
  22370 		**(**int32)(__ccgo_up(enc + 23604 + 2*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)) != 0)
  22371 	}
  22372 	if (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info != libc.UintptrFromInt32(0) {
  22373 		info = (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx+(*VP8EncIterator)(unsafe.Pointer(it)).Fy*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  22374 		switch (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info_type {
  22375 		case int32(1):
  22376 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x3 >> 0)))
  22377 		case int32(2):
  22378 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5)))
  22379 		case int32(3):
  22380 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)))*744))).Fquant)
  22381 		case int32(4):
  22382 			if int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1) {
  22383 				v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds)))
  22384 			} else {
  22385 				v1 = int32(0xff)
  22386 			}
  22387 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(v1)
  22388 		case int32(5):
  22389 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0xc >> 2)))
  22390 		case int32(6):
  22391 			b = libc.Int32FromUint64(((*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits + (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  22392 			if b > int32(255) {
  22393 				v1 = int32(255)
  22394 			} else {
  22395 				v1 = b
  22396 			}
  22397 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(v1)
  22398 		case int32(7):
  22399 			**(**uint8_t)(__ccgo_up(info)) = (*VP8MBInfo)(unsafe.Pointer(mb)).Falpha
  22400 		default:
  22401 			**(**uint8_t)(__ccgo_up(info)) = uint8(0)
  22402 			break
  22403 		}
  22404 	}
  22405 }
  22406 
  22407 func ResetSideInfo(tls *libc.TLS, it uintptr) {
  22408 	var enc, pic uintptr
  22409 	_, _ = enc, pic
  22410 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22411 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22412 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22413 		libc.Xmemset(tls, enc+23604, 0, uint64(12))
  22414 	}
  22415 	ResetSSE(tls, enc)
  22416 }
  22417 
  22418 func GetPSNR(tls *libc.TLS, mse uint64_t, size uint64_t) (r float64) {
  22419 	var v1 float64
  22420 	_ = v1
  22421 	if mse > uint64(0) && size > uint64(0) {
  22422 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(mse)))
  22423 	} else {
  22424 		v1 = libc.Float64FromInt32(99)
  22425 	}
  22426 	return v1
  22427 }
  22428 
  22429 //------------------------------------------------------------------------------
  22430 //  StatLoop(): only collect statistics (number of skips, token usage, ...).
  22431 //  This is used for deciding optimal probabilities. It also modifies the
  22432 //  quantizer value if some target (size, PSNR) was specified.
  22433 
  22434 func SetLoopParams(tls *libc.TLS, enc uintptr, q float32) {
  22435 	// Make sure the quality parameter is inside valid bounds
  22436 	q = Clamp(tls, q, libc.Float32FromFloat32(0), libc.Float32FromFloat32(100))
  22437 	VP8SetSegmentParams(tls, enc, q) // setup segment quantizations and filters
  22438 	SetSegmentProbas(tls, enc)       // compute segment probabilities
  22439 	ResetStats(tls, enc)
  22440 	ResetSSE(tls, enc)
  22441 }
  22442 
  22443 func OneStatPass(tls *libc.TLS, enc uintptr, rd_opt VP8RDLevel, nb_mbs int32, percent_delta int32, s uintptr) (r uint64_t) {
  22444 	bp := tls.Alloc(4736)
  22445 	defer tls.Free(4736)
  22446 	var distortion, pixel_count, size, size_p0 uint64_t
  22447 	var v1 int32
  22448 	var v2 bool
  22449 	var _ /* info at bp+3848 */ VP8ModeScore
  22450 	var _ /* it at bp+0 */ VP8EncIterator
  22451 	_, _, _, _, _, _ = distortion, pixel_count, size, size_p0, v1, v2
  22452 	size = uint64(0)
  22453 	size_p0 = uint64(0)
  22454 	distortion = uint64(0)
  22455 	pixel_count = libc.Uint64FromInt32(nb_mbs) * uint64(384)
  22456 	VP8IteratorInit(tls, enc, bp)
  22457 	SetLoopParams(tls, enc, (*PassStats)(unsafe.Pointer(s)).Fq)
  22458 	for {
  22459 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22460 		if VP8Decimate(tls, bp, bp+3848, rd_opt) != 0 {
  22461 			// Just record the number of skips and act like skip_proba is not used.
  22462 			(*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip = (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip + 1
  22463 		}
  22464 		RecordResiduals(tls, bp, bp+3848)
  22465 		size = size + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FR+(**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22466 		size_p0 = size_p0 + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22467 		distortion = distortion + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FD)
  22468 		if percent_delta != 0 && !(VP8IteratorProgress(tls, bp, percent_delta) != 0) {
  22469 			return uint64(0)
  22470 		}
  22471 		VP8IteratorSaveBoundary(tls, bp)
  22472 		goto _3
  22473 	_3:
  22474 		;
  22475 		if v2 = VP8IteratorNext(tls, bp) != 0; v2 {
  22476 			nb_mbs = nb_mbs - 1
  22477 			v1 = nb_mbs
  22478 		}
  22479 		if !(v2 && v1 > 0) {
  22480 			break
  22481 		}
  22482 	}
  22483 	size_p0 = size_p0 + libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  22484 	if (*PassStats)(unsafe.Pointer(s)).Fdo_size_search != 0 {
  22485 		size = size + libc.Uint64FromInt32(FinalizeSkipProba(tls, enc))
  22486 		size = size + libc.Uint64FromInt32(FinalizeTokenProbas(tls, enc+3616))
  22487 		size = (size+size_p0+uint64(1024))>>int32(11) + libc.Uint64FromInt32(libc.Int32FromInt32(RIFF_HEADER_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8_FRAME_HEADER_SIZE))
  22488 		(*PassStats)(unsafe.Pointer(s)).Fvalue = float64(size)
  22489 	} else {
  22490 		(*PassStats)(unsafe.Pointer(s)).Fvalue = GetPSNR(tls, distortion, pixel_count)
  22491 	}
  22492 	return size_p0
  22493 }
  22494 
  22495 func StatLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22496 	bp := tls.Alloc(64)
  22497 	defer tls.Free(64)
  22498 	var do_search, fast_probe, final_percent, is_last_pass, method, nb_mbs, num_pass_left, percent_per_pass, task_percent, v1 int32
  22499 	var rd_opt VP8RDLevel
  22500 	var size_p0 uint64_t
  22501 	var _ /* stats at bp+0 */ PassStats
  22502 	_, _, _, _, _, _, _, _, _, _, _, _ = do_search, fast_probe, final_percent, is_last_pass, method, nb_mbs, num_pass_left, percent_per_pass, rd_opt, size_p0, task_percent, v1
  22503 	method = (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod
  22504 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  22505 	fast_probe = libc.BoolInt32((method == 0 || method == int32(3)) && !(do_search != 0))
  22506 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  22507 	task_percent = int32(20)
  22508 	percent_per_pass = (task_percent + num_pass_left/int32(2)) / num_pass_left
  22509 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  22510 	if method >= int32(3) || do_search != 0 {
  22511 		v1 = int32(RD_OPT_BASIC)
  22512 	} else {
  22513 		v1 = int32(RD_OPT_NONE)
  22514 	}
  22515 	rd_opt = v1
  22516 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  22517 	InitPassStats(tls, enc, bp)
  22518 	ResetTokenStats(tls, enc)
  22519 	// Fast mode: quick analysis pass over few mbs. Better than nothing.
  22520 	if fast_probe != 0 {
  22521 		if method == int32(3) { // we need more stats for method 3 to be reliable.
  22522 			if nb_mbs > int32(200) {
  22523 				v1 = nb_mbs >> int32(1)
  22524 			} else {
  22525 				v1 = int32(100)
  22526 			}
  22527 			nb_mbs = v1
  22528 		} else {
  22529 			if nb_mbs > int32(200) {
  22530 				v1 = nb_mbs >> int32(2)
  22531 			} else {
  22532 				v1 = int32(50)
  22533 			}
  22534 			nb_mbs = v1
  22535 		}
  22536 	}
  22537 	for {
  22538 		v1 = num_pass_left
  22539 		num_pass_left = num_pass_left - 1
  22540 		if !(v1 > 0) {
  22541 			break
  22542 		}
  22543 		is_last_pass = libc.BoolInt32(libc.Xfabs(tls, float64((**(**PassStats)(__ccgo_up(bp))).Fdq)) <= float64(DQ_LIMIT) || num_pass_left == 0 || (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits == 0)
  22544 		size_p0 = OneStatPass(tls, enc, rd_opt, nb_mbs, percent_per_pass, bp)
  22545 		if size_p0 == uint64(0) {
  22546 			return 0
  22547 		}
  22548 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits > 0 && size_p0 > (libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19))-libc.Uint64FromUint64(2048))<<libc.Int32FromInt32(11) {
  22549 			num_pass_left = num_pass_left + 1
  22550 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  22551 			continue                                         // ...and start over
  22552 		}
  22553 		if is_last_pass != 0 {
  22554 			break
  22555 		}
  22556 		// If no target size: just do several pass without changing 'q'
  22557 		if do_search != 0 {
  22558 			ComputeNextQ(tls, bp)
  22559 			if libc.Xfabs(tls, float64((**(**PassStats)(__ccgo_up(bp))).Fdq)) <= float64(DQ_LIMIT) {
  22560 				break
  22561 			}
  22562 		}
  22563 	}
  22564 	if !(do_search != 0) || !((**(**PassStats)(__ccgo_up(bp))).Fdo_size_search != 0) {
  22565 		// Need to finalize probas now, since it wasn't done during the search.
  22566 		FinalizeSkipProba(tls, enc)
  22567 		FinalizeTokenProbas(tls, enc+3616)
  22568 	}
  22569 	VP8CalculateLevelCosts(tls, enc+3616) // finalize costs
  22570 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, final_percent, enc+536)
  22571 }
  22572 
  22573 //------------------------------------------------------------------------------
  22574 // Main loops
  22575 //
  22576 
  22577 var kAverageBytesPerMB = [8]uint8_t{
  22578 	0: uint8(50),
  22579 	1: uint8(24),
  22580 	2: uint8(16),
  22581 	3: uint8(9),
  22582 	4: uint8(7),
  22583 	5: uint8(5),
  22584 	6: uint8(3),
  22585 	7: uint8(2),
  22586 }
  22587 
  22588 func PreLoopInitialize(tls *libc.TLS, enc uintptr) (r int32) {
  22589 	var average_bytes_per_MB, bytes_per_parts, ok, p int32
  22590 	_, _, _, _ = average_bytes_per_MB, bytes_per_parts, ok, p
  22591 	ok = int32(1)
  22592 	average_bytes_per_MB = libc.Int32FromUint8(kAverageBytesPerMB[(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant>>int32(4)])
  22593 	bytes_per_parts = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h * average_bytes_per_MB / (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts
  22594 	// Initialize the bit-writers
  22595 	p = 0
  22596 	for {
  22597 		if !(ok != 0 && p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22598 			break
  22599 		}
  22600 		ok = VP8BitWriterInit(tls, enc+112+uintptr(p)*48, libc.Uint64FromInt32(bytes_per_parts))
  22601 		goto _1
  22602 	_1:
  22603 		;
  22604 		p = p + 1
  22605 	}
  22606 	if !(ok != 0) {
  22607 		VP8EncFreeBitWriters(tls, enc) // malloc error occurred
  22608 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22609 	}
  22610 	return ok
  22611 }
  22612 
  22613 func PostLoopFinalize(tls *libc.TLS, it uintptr, ok int32) (r int32) {
  22614 	var enc uintptr
  22615 	var i, p, s int32
  22616 	_, _, _, _ = enc, i, p, s
  22617 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22618 	if ok != 0 {
  22619 		p = 0
  22620 		for {
  22621 			if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22622 				break
  22623 			}
  22624 			VP8BitWriterFinish(tls, enc+112+uintptr(p)*48)
  22625 			ok = ok & libc.BoolInt32(!((**(**VP8BitWriter)(__ccgo_up(enc + 112 + uintptr(p)*48))).Ferror1 != 0))
  22626 			goto _1
  22627 		_1:
  22628 			;
  22629 			p = p + 1
  22630 		}
  22631 	}
  22632 	if ok != 0 { // All good. Finish up.
  22633 		if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  22634 			i = 0
  22635 			for {
  22636 				if !(i <= int32(2)) {
  22637 					break
  22638 				}
  22639 				s = 0
  22640 				for {
  22641 					if !(s < int32(NUM_MB_SEGMENTS)) {
  22642 						break
  22643 					}
  22644 					**(**int32)(__ccgo_up(enc + 23556 + uintptr(i)*16 + uintptr(s)*4)) = libc.Int32FromUint64((**(**uint64_t)(__ccgo_up(it + 208 + uintptr(s)*24 + uintptr(i)*8)) + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  22645 					goto _3
  22646 				_3:
  22647 					;
  22648 					s = s + 1
  22649 				}
  22650 				goto _2
  22651 			_2:
  22652 				;
  22653 				i = i + 1
  22654 			}
  22655 		}
  22656 		VP8AdjustFilterStrength(tls, it) // ...and store filter stats.
  22657 	} else {
  22658 		// Something bad happened -> need to do some memory cleanup.
  22659 		VP8EncFreeBitWriters(tls, enc)
  22660 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22661 	}
  22662 	return ok
  22663 }
  22664 
  22665 //------------------------------------------------------------------------------
  22666 //  VP8EncLoop(): does the final bitstream coding.
  22667 
  22668 func ResetAfterSkip(tls *libc.TLS, it uintptr) {
  22669 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) {
  22670 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = uint32(0) // reset all predictors
  22671 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  22672 	} else {
  22673 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) &= libc.Uint32FromInt32(libc.Int32FromInt32(1) << libc.Int32FromInt32(24)) // preserve the dc_nz bit
  22674 	}
  22675 }
  22676 
  22677 func VP8EncLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22678 	bp := tls.Alloc(4736)
  22679 	defer tls.Free(4736)
  22680 	var dont_use_skip, ok int32
  22681 	var rd_opt VP8RDLevel
  22682 	var _ /* info at bp+3848 */ VP8ModeScore
  22683 	var _ /* it at bp+0 */ VP8EncIterator
  22684 	_, _, _ = dont_use_skip, ok, rd_opt
  22685 	ok = PreLoopInitialize(tls, enc)
  22686 	if !(ok != 0) {
  22687 		return 0
  22688 	}
  22689 	StatLoop(tls, enc) // stats-collection loop
  22690 	VP8IteratorInit(tls, enc, bp)
  22691 	VP8InitFilter(tls, bp)
  22692 	for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  22693 		dont_use_skip = libc.BoolInt32(!((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0))
  22694 		rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  22695 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22696 		// Warning! order is important: first call VP8Decimate() and
  22697 		// *then* decide how to code the skip decision if there's one.
  22698 		if !(VP8Decimate(tls, bp, bp+3848, rd_opt) != 0) || dont_use_skip != 0 {
  22699 			CodeResiduals(tls, (**(**VP8EncIterator)(__ccgo_up(bp))).Fbw, bp, bp+3848)
  22700 			if (*VP8BitWriter)(unsafe.Pointer((**(**VP8EncIterator)(__ccgo_up(bp))).Fbw)).Ferror1 != 0 {
  22701 				// enc->pic->error_code is set in PostLoopFinalize().
  22702 				ok = 0
  22703 				break
  22704 			}
  22705 		} else { // reset predictors after a skip
  22706 			ResetAfterSkip(tls, bp)
  22707 		}
  22708 		StoreSideInfo(tls, bp)
  22709 		VP8StoreFilterStats(tls, bp)
  22710 		VP8IteratorExport(tls, bp)
  22711 		ok = VP8IteratorProgress(tls, bp, int32(20))
  22712 		VP8IteratorSaveBoundary(tls, bp)
  22713 	}
  22714 	return PostLoopFinalize(tls, bp, ok)
  22715 }
  22716 
  22717 //------------------------------------------------------------------------------
  22718 // Single pass using Token Buffer.
  22719 
  22720 func VP8EncTokenLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22721 	bp := tls.Alloc(4784)
  22722 	defer tls.Free(4784)
  22723 	var cnt, do_search, is_last_pass, max_count, num_pass_left, ok, pass_progress, remaining_progress, v1 int32
  22724 	var distortion, pixel_count, size, size_p0 uint64_t
  22725 	var proba uintptr
  22726 	var rd_opt VP8RDLevel
  22727 	var v2 bool
  22728 	var _ /* info at bp+3904 */ VP8ModeScore
  22729 	var _ /* it at bp+0 */ VP8EncIterator
  22730 	var _ /* stats at bp+3848 */ PassStats
  22731 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cnt, distortion, do_search, is_last_pass, max_count, num_pass_left, ok, pass_progress, pixel_count, proba, rd_opt, remaining_progress, size, size_p0, v1, v2
  22732 	// Roughly refresh the proba eight times per pass
  22733 	max_count = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h >> int32(3)
  22734 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  22735 	remaining_progress = int32(40) // percents
  22736 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  22737 	proba = enc + 3616
  22738 	rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  22739 	pixel_count = libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) * libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) * uint64(384)
  22740 	InitPassStats(tls, enc, bp+3848)
  22741 	ok = PreLoopInitialize(tls, enc)
  22742 	if !(ok != 0) {
  22743 		return 0
  22744 	}
  22745 	if max_count < int32(MIN_COUNT) {
  22746 		max_count = int32(MIN_COUNT)
  22747 	}
  22748 	// otherwise, token-buffer won't be useful
  22749 	for {
  22750 		if v2 = ok != 0; v2 {
  22751 			v1 = num_pass_left
  22752 			num_pass_left = num_pass_left - 1
  22753 		}
  22754 		if !(v2 && v1 > 0) {
  22755 			break
  22756 		}
  22757 		is_last_pass = libc.BoolInt32(libc.Xfabs(tls, float64((**(**PassStats)(__ccgo_up(bp + 3848))).Fdq)) <= float64(DQ_LIMIT) || num_pass_left == 0 || (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits == 0)
  22758 		size_p0 = uint64(0)
  22759 		distortion = uint64(0)
  22760 		cnt = max_count
  22761 		// The final number of passes is not trivial to know in advance.
  22762 		pass_progress = remaining_progress / (int32(2) + num_pass_left)
  22763 		remaining_progress = remaining_progress - pass_progress
  22764 		VP8IteratorInit(tls, enc, bp)
  22765 		SetLoopParams(tls, enc, (**(**PassStats)(__ccgo_up(bp + 3848))).Fq)
  22766 		if is_last_pass != 0 {
  22767 			ResetTokenStats(tls, enc)
  22768 			VP8InitFilter(tls, bp) // don't collect stats until last pass (too costly)
  22769 		}
  22770 		VP8TBufferClear(tls, enc+496)
  22771 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  22772 			VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22773 			cnt = cnt - 1
  22774 			v1 = cnt
  22775 			if v1 < 0 {
  22776 				FinalizeTokenProbas(tls, proba)
  22777 				VP8CalculateLevelCosts(tls, proba) // refresh cost tables for rd-opt
  22778 				cnt = max_count
  22779 			}
  22780 			VP8Decimate(tls, bp, bp+3904, rd_opt)
  22781 			ok = RecordTokens(tls, bp, bp+3904, enc+496)
  22782 			if !(ok != 0) {
  22783 				WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22784 				break
  22785 			}
  22786 			size_p0 = size_p0 + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FH)
  22787 			distortion = distortion + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FD)
  22788 			if is_last_pass != 0 {
  22789 				StoreSideInfo(tls, bp)
  22790 				VP8StoreFilterStats(tls, bp)
  22791 				VP8IteratorExport(tls, bp)
  22792 				ok = VP8IteratorProgress(tls, bp, pass_progress)
  22793 			}
  22794 			VP8IteratorSaveBoundary(tls, bp)
  22795 		}
  22796 		if !(ok != 0) {
  22797 			break
  22798 		}
  22799 		size_p0 = size_p0 + libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  22800 		if (**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0 {
  22801 			size = libc.Uint64FromInt32(FinalizeTokenProbas(tls, enc+3616))
  22802 			size = size + VP8EstimateTokenSize(tls, enc+496, proba+4)
  22803 			size = (size + size_p0 + uint64(1024)) >> int32(11) // -> size in bytes
  22804 			size = size + libc.Uint64FromInt32(libc.Int32FromInt32(RIFF_HEADER_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8_FRAME_HEADER_SIZE))
  22805 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = float64(size)
  22806 		} else { // compute and store PSNR
  22807 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = GetPSNR(tls, distortion, pixel_count)
  22808 		}
  22809 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits > 0 && size_p0 > (libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19))-libc.Uint64FromUint64(2048))<<libc.Int32FromInt32(11) {
  22810 			num_pass_left = num_pass_left + 1
  22811 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  22812 			if is_last_pass != 0 {
  22813 				ResetSideInfo(tls, bp)
  22814 			}
  22815 			continue // ...and start over
  22816 		}
  22817 		if is_last_pass != 0 {
  22818 			break // done
  22819 		}
  22820 		if do_search != 0 {
  22821 			ComputeNextQ(tls, bp+3848) // Adjust q
  22822 		}
  22823 	}
  22824 	if ok != 0 {
  22825 		if !((**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0) {
  22826 			FinalizeTokenProbas(tls, enc+3616)
  22827 		}
  22828 		ok = VP8EmitTokens(tls, enc+496, enc+112+uintptr(0)*48, proba+4, int32(1))
  22829 	}
  22830 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+remaining_progress, enc+536) != 0)
  22831 	return PostLoopFinalize(tls, bp, ok)
  22832 }
  22833 
  22834 const MAX_HISTO_GREEDY = 100
  22835 const NUM_PARTITIONS = 4
  22836 
  22837 //------------------------------------------------------------------------------
  22838 
  22839 // Copyright 2012 Google Inc. All Rights Reserved.
  22840 //
  22841 // Use of this source code is governed by a BSD-style license
  22842 // that can be found in the COPYING file in the root of the source
  22843 // tree. An additional intellectual property rights grant can be found
  22844 // in the file PATENTS. All contributing project authors may
  22845 // be found in the AUTHORS file in the root of the source tree.
  22846 // -----------------------------------------------------------------------------
  22847 //
  22848 // Misc. common utility functions
  22849 //
  22850 // Authors: Skal (pascal.massimino@gmail.com)
  22851 //          Urvang (urvang@google.com)
  22852 
  22853 // Copyright 2011 Google Inc. All Rights Reserved.
  22854 //
  22855 // Use of this source code is governed by a BSD-style license
  22856 // that can be found in the COPYING file in the root of the source
  22857 // tree. An additional intellectual property rights grant can be found
  22858 // in the file PATENTS. All contributing project authors may
  22859 // be found in the AUTHORS file in the root of the source tree.
  22860 // -----------------------------------------------------------------------------
  22861 //
  22862 //   WebP encoder: main interface
  22863 //
  22864 // Author: Skal (pascal.massimino@gmail.com)
  22865 
  22866 // Copyright 2012 Google Inc. All Rights Reserved.
  22867 //
  22868 // Use of this source code is governed by a BSD-style license
  22869 // that can be found in the COPYING file in the root of the source
  22870 // tree. An additional intellectual property rights grant can be found
  22871 // in the file PATENTS. All contributing project authors may
  22872 // be found in the AUTHORS file in the root of the source tree.
  22873 // -----------------------------------------------------------------------------
  22874 //
  22875 //  Internal header for constants related to WebP file format.
  22876 //
  22877 // Author: Urvang (urvang@google.com)
  22878 
  22879 // Copyright 2010 Google Inc. All Rights Reserved.
  22880 //
  22881 // Use of this source code is governed by a BSD-style license
  22882 // that can be found in the COPYING file in the root of the source
  22883 // tree. An additional intellectual property rights grant can be found
  22884 // in the file PATENTS. All contributing project authors may
  22885 // be found in the AUTHORS file in the root of the source tree.
  22886 // -----------------------------------------------------------------------------
  22887 //
  22888 //  Common types + memory wrappers
  22889 //
  22890 // Author: Skal (pascal.massimino@gmail.com)
  22891 
  22892 // Number of partitions for the three dominant (literal, red and blue) symbol
  22893 // costs.
  22894 // The size of the bin-hash corresponding to the three dominant costs.
  22895 // Maximum number of histograms allowed in greedy combining algorithm.
  22896 
  22897 // C documentation
  22898 //
  22899 //	// Enum to meaningfully access the elements of the Histogram arrays.
  22900 type HistogramIndex = int32
  22901 
  22902 const LITERAL = 0
  22903 const DISTANCE = 4
  22904 
  22905 // C documentation
  22906 //
  22907 //	// Return the size of the histogram for a given cache_bits.
  22908 func GetHistogramSize(tls *libc.TLS, cache_bits int32) (r int32) {
  22909 	var literal_size, v1, v2, v4 int32
  22910 	var total_size size_t
  22911 	_, _, _, _, _ = literal_size, total_size, v1, v2, v4
  22912 	v1 = cache_bits
  22913 	if v1 > 0 {
  22914 		v4 = int32(1) << v1
  22915 	} else {
  22916 		v4 = 0
  22917 	}
  22918 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  22919 	goto _3
  22920 _3:
  22921 	literal_size = v2
  22922 	total_size = uint64(3312) + uint64(4)*libc.Uint64FromInt32(literal_size)
  22923 	return libc.Int32FromUint64(total_size)
  22924 }
  22925 
  22926 func HistogramStatsClear(tls *libc.TLS, h uintptr) {
  22927 	var i int32
  22928 	_ = i
  22929 	i = 0
  22930 	for {
  22931 		if !(i < int32(5)) {
  22932 			break
  22933 		}
  22934 		**(**uint16_t)(__ccgo_up(h + 3244 + uintptr(i)*2)) = libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))
  22935 		// By default, the histogram is assumed to be used.
  22936 		**(**uint8_t)(__ccgo_up(h + 3304 + uintptr(i))) = uint8(1)
  22937 		goto _1
  22938 	_1:
  22939 		;
  22940 		i = i + 1
  22941 	}
  22942 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = uint64(0)
  22943 	libc.Xmemset(tls, h+3264, 0, uint64(40))
  22944 }
  22945 
  22946 func HistogramClear(tls *libc.TLS, h uintptr) {
  22947 	var cache_bits, histo_size int32
  22948 	var literal uintptr
  22949 	_, _, _ = cache_bits, histo_size, literal
  22950 	literal = (*VP8LHistogram)(unsafe.Pointer(h)).Fliteral
  22951 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits
  22952 	histo_size = GetHistogramSize(tls, cache_bits)
  22953 	libc.Xmemset(tls, h, 0, libc.Uint64FromInt32(histo_size))
  22954 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = cache_bits
  22955 	(*VP8LHistogram)(unsafe.Pointer(h)).Fliteral = literal
  22956 	HistogramStatsClear(tls, h)
  22957 }
  22958 
  22959 // C documentation
  22960 //
  22961 //	// Swap two histogram pointers.
  22962 func HistogramSwap(tls *libc.TLS, h1 uintptr, h2 uintptr) {
  22963 	var tmp uintptr
  22964 	_ = tmp
  22965 	tmp = **(**uintptr)(__ccgo_up(h1))
  22966 	**(**uintptr)(__ccgo_up(h1)) = **(**uintptr)(__ccgo_up(h2))
  22967 	**(**uintptr)(__ccgo_up(h2)) = tmp
  22968 }
  22969 
  22970 func HistogramCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  22971 	var dst_cache_bits, histo_size, literal_size, v1, v2, v4 int32
  22972 	var dst_literal uintptr
  22973 	_, _, _, _, _, _, _ = dst_cache_bits, dst_literal, histo_size, literal_size, v1, v2, v4
  22974 	dst_literal = (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral
  22975 	dst_cache_bits = (*VP8LHistogram)(unsafe.Pointer(dst)).Fpalette_code_bits
  22976 	v1 = dst_cache_bits
  22977 	if v1 > 0 {
  22978 		v4 = int32(1) << v1
  22979 	} else {
  22980 		v4 = 0
  22981 	}
  22982 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  22983 	goto _3
  22984 _3:
  22985 	literal_size = v2
  22986 	histo_size = GetHistogramSize(tls, dst_cache_bits)
  22987 	libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(histo_size))
  22988 	(*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral = dst_literal
  22989 	libc.Xmemcpy(tls, (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral, (*VP8LHistogram)(unsafe.Pointer(src)).Fliteral, libc.Uint64FromInt32(literal_size)*uint64(4))
  22990 }
  22991 
  22992 func VP8LFreeHistogram(tls *libc.TLS, h uintptr) {
  22993 	WebPSafeFree(tls, h)
  22994 }
  22995 
  22996 func VP8LFreeHistogramSet(tls *libc.TLS, histograms uintptr) {
  22997 	WebPSafeFree(tls, histograms)
  22998 }
  22999 
  23000 func VP8LHistogramCreate(tls *libc.TLS, h uintptr, refs uintptr, palette_code_bits int32) {
  23001 	if palette_code_bits >= 0 {
  23002 		(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23003 	}
  23004 	HistogramClear(tls, h)
  23005 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, h)
  23006 }
  23007 
  23008 func VP8LHistogramInit(tls *libc.TLS, h uintptr, palette_code_bits int32, init_arrays int32) {
  23009 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23010 	if init_arrays != 0 {
  23011 		HistogramClear(tls, h)
  23012 	} else {
  23013 		HistogramStatsClear(tls, h)
  23014 	}
  23015 }
  23016 
  23017 func VP8LAllocateHistogram(tls *libc.TLS, cache_bits int32) (r uintptr) {
  23018 	var histo, memory uintptr
  23019 	var total_size int32
  23020 	_, _, _ = histo, memory, total_size
  23021 	histo = libc.UintptrFromInt32(0)
  23022 	total_size = GetHistogramSize(tls, cache_bits)
  23023 	memory = WebPSafeMalloc(tls, libc.Uint64FromInt32(total_size), uint64(1))
  23024 	if memory == libc.UintptrFromInt32(0) {
  23025 		return libc.UintptrFromInt32(0)
  23026 	}
  23027 	histo = memory
  23028 	// 'literal' won't necessary be aligned.
  23029 	(*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral = memory + libc.UintptrFromInt64(3312)
  23030 	VP8LHistogramInit(tls, histo, cache_bits, 0)
  23031 	return histo
  23032 }
  23033 
  23034 // C documentation
  23035 //
  23036 //	// Resets the pointers of the histograms to point to the bit buffer in the set.
  23037 func HistogramSetResetPointers(tls *libc.TLS, set uintptr, cache_bits int32) {
  23038 	var histo_size, i int32
  23039 	var memory uintptr
  23040 	_, _, _ = histo_size, i, memory
  23041 	histo_size = GetHistogramSize(tls, cache_bits)
  23042 	memory = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms
  23043 	memory = memory + uintptr(libc.Uint64FromInt32((*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size)*uint64(8))
  23044 	i = 0
  23045 	for {
  23046 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size) {
  23047 			break
  23048 		}
  23049 		memory = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23050 		**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)) = memory
  23051 		// 'literal' won't necessary be aligned.
  23052 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fliteral = memory + libc.UintptrFromInt64(3312)
  23053 		memory = memory + uintptr(histo_size)
  23054 		goto _1
  23055 	_1:
  23056 		;
  23057 		i = i + 1
  23058 	}
  23059 }
  23060 
  23061 // C documentation
  23062 //
  23063 //	// Returns the total size of the VP8LHistogramSet.
  23064 func HistogramSetTotalSize(tls *libc.TLS, size int32, cache_bits int32) (r size_t) {
  23065 	var histo_size int32
  23066 	_ = histo_size
  23067 	histo_size = GetHistogramSize(tls, cache_bits)
  23068 	return libc.Uint64FromInt64(16) + libc.Uint64FromInt32(size)*(libc.Uint64FromInt64(8)+libc.Uint64FromInt32(histo_size)+libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23069 }
  23070 
  23071 func VP8LAllocateHistogramSet(tls *libc.TLS, size int32, cache_bits int32) (r uintptr) {
  23072 	var i int32
  23073 	var memory, set uintptr
  23074 	var total_size size_t
  23075 	_, _, _, _ = i, memory, set, total_size
  23076 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23077 	memory = WebPSafeMalloc(tls, total_size, uint64(1))
  23078 	if memory == libc.UintptrFromInt32(0) {
  23079 		return libc.UintptrFromInt32(0)
  23080 	}
  23081 	set = memory
  23082 	memory = memory + uintptr(16)
  23083 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23084 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23085 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23086 	HistogramSetResetPointers(tls, set, cache_bits)
  23087 	i = 0
  23088 	for {
  23089 		if !(i < size) {
  23090 			break
  23091 		}
  23092 		VP8LHistogramInit(tls, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)), cache_bits, 0)
  23093 		goto _1
  23094 	_1:
  23095 		;
  23096 		i = i + 1
  23097 	}
  23098 	return set
  23099 }
  23100 
  23101 func VP8LHistogramSetClear(tls *libc.TLS, set uintptr) {
  23102 	var cache_bits, i, size int32
  23103 	var memory uintptr
  23104 	var total_size size_t
  23105 	_, _, _, _, _ = cache_bits, i, memory, size, total_size
  23106 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms)))).Fpalette_code_bits
  23107 	size = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size
  23108 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23109 	memory = set
  23110 	libc.Xmemset(tls, memory, 0, total_size)
  23111 	memory = memory + uintptr(16)
  23112 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23113 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23114 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23115 	HistogramSetResetPointers(tls, set, cache_bits)
  23116 	i = 0
  23117 	for {
  23118 		if !(i < size) {
  23119 			break
  23120 		}
  23121 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fpalette_code_bits = cache_bits
  23122 		goto _1
  23123 	_1:
  23124 		;
  23125 		i = i + 1
  23126 	}
  23127 }
  23128 
  23129 // C documentation
  23130 //
  23131 //	// Removes the histogram 'i' from 'set'.
  23132 func HistogramSetRemoveHistogram(tls *libc.TLS, set uintptr, i int32) {
  23133 	**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)) = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr((*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize-int32(1))*8))
  23134 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize - 1
  23135 }
  23136 
  23137 // -----------------------------------------------------------------------------
  23138 
  23139 func HistogramAddSinglePixOrCopy(tls *libc.TLS, histo uintptr, v uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32) {
  23140 	bp := tls.Alloc(16)
  23141 	defer tls.Free(16)
  23142 	var highest_bit, literal_ix, second_highest_bit, v1, v11, v17, v20 int32
  23143 	var prefix_code VP8LPrefixCode
  23144 	var v3 uint32_t
  23145 	var v18, v19 uintptr
  23146 	var _ /* code at bp+0 */ int32
  23147 	var _ /* extra_bits at bp+4 */ int32
  23148 	_, _, _, _, _, _, _, _, _, _, _ = highest_bit, literal_ix, prefix_code, second_highest_bit, v1, v11, v17, v18, v19, v20, v3
  23149 	v1 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  23150 	goto _2
  23151 _2:
  23152 	if v1 != 0 {
  23153 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(3) * libc.Int32FromInt32(8)) & uint32(0xff)
  23154 		goto _4
  23155 	_4:
  23156 		**(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) + 1
  23157 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(2) * libc.Int32FromInt32(8)) & uint32(0xff)
  23158 		goto _6
  23159 	_6:
  23160 		**(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) + 1
  23161 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(1) * libc.Int32FromInt32(8)) & uint32(0xff)
  23162 		goto _8
  23163 	_8:
  23164 		**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral + uintptr(v3)*4)) + 1
  23165 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (0 * libc.Int32FromInt32(8)) & uint32(0xff)
  23166 		goto _10
  23167 	_10:
  23168 		**(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) + 1
  23169 	} else {
  23170 		v1 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  23171 		goto _12
  23172 	_12:
  23173 		if v1 != 0 {
  23174 			v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23175 			goto _14
  23176 		_14:
  23177 			literal_ix = libc.Int32FromUint32(libc.Uint32FromInt32(libc.Int32FromInt32(NUM_LITERAL_CODES)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + v3)
  23178 			**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral + uintptr(literal_ix)*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral + uintptr(literal_ix)*4)) + 1
  23179 		} else {
  23180 			v3 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  23181 			goto _16
  23182 		_16:
  23183 			v1 = libc.Int32FromUint32(v3)
  23184 			v18 = bp
  23185 			v19 = bp + 4
  23186 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23187 				prefix_code = kPrefixEncodeCode[v1]
  23188 				**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23189 				**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23190 			} else {
  23191 				v11 = v1
  23192 				v11 = v11 - 1
  23193 				v17 = v11
  23194 				v20 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v17))
  23195 				goto _23
  23196 			_23:
  23197 				highest_bit = v20
  23198 				second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23199 				**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23200 				**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23201 			}
  23202 			**(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral + uintptr(int32(NUM_LITERAL_CODES)+**(**int32)(__ccgo_up(bp)))*4)) = **(**uint32_t)(__ccgo_up((*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral + uintptr(int32(NUM_LITERAL_CODES)+**(**int32)(__ccgo_up(bp)))*4)) + 1
  23203 			if __ccgo_fp_distance_modifier == libc.UintptrFromInt32(0) {
  23204 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23205 				goto _25
  23206 			_25:
  23207 				v1 = libc.Int32FromUint32(v3)
  23208 				v18 = bp
  23209 				v19 = bp + 4
  23210 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23211 					prefix_code = kPrefixEncodeCode[v1]
  23212 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23213 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23214 				} else {
  23215 					v11 = v1
  23216 					v11 = v11 - 1
  23217 					v17 = v11
  23218 					v20 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v17))
  23219 					goto _32
  23220 				_32:
  23221 					highest_bit = v20
  23222 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23223 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23224 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23225 				}
  23226 			} else {
  23227 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23228 				goto _34
  23229 			_34:
  23230 				v1 = (*(*func(*libc.TLS, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_distance_modifier})))(tls, distance_modifier_arg0, libc.Int32FromUint32(v3))
  23231 				v18 = bp
  23232 				v19 = bp + 4
  23233 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23234 					prefix_code = kPrefixEncodeCode[v1]
  23235 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23236 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23237 				} else {
  23238 					v11 = v1
  23239 					v11 = v11 - 1
  23240 					v17 = v11
  23241 					v20 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v17))
  23242 					goto _41
  23243 				_41:
  23244 					highest_bit = v20
  23245 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23246 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23247 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23248 				}
  23249 			}
  23250 			**(**uint32_t)(__ccgo_up(histo + 3080 + uintptr(**(**int32)(__ccgo_up(bp)))*4)) = **(**uint32_t)(__ccgo_up(histo + 3080 + uintptr(**(**int32)(__ccgo_up(bp)))*4)) + 1
  23251 		}
  23252 	}
  23253 }
  23254 
  23255 type __ccgo_fp__XVP8LHistogramStoreRefs_1 = func(*libc.TLS, int32, int32) int32
  23256 
  23257 func VP8LHistogramStoreRefs(tls *libc.TLS, refs uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32, histo uintptr) {
  23258 	bp := tls.Alloc(32)
  23259 	defer tls.Free(32)
  23260 	var v1 int32
  23261 	var v3, v4, v5 uintptr
  23262 	var _ /* c at bp+0 */ VP8LRefsCursor
  23263 	_, _, _, _ = v1, v3, v4, v5
  23264 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  23265 	for {
  23266 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  23267 		goto _2
  23268 	_2:
  23269 		if !(v1 != 0) {
  23270 			break
  23271 		}
  23272 		HistogramAddSinglePixOrCopy(tls, histo, (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos, __ccgo_fp_distance_modifier, distance_modifier_arg0)
  23273 		v3 = bp
  23274 		v5 = v3
  23275 		*(*uintptr)(unsafe.Pointer(v5)) += 8
  23276 		v4 = *(*uintptr)(unsafe.Pointer(v5))
  23277 		if v4 == (*VP8LRefsCursor)(unsafe.Pointer(v3)).Flast_pos {
  23278 			VP8LRefsCursorNextBlock(tls, v3)
  23279 		}
  23280 	}
  23281 }
  23282 
  23283 // -----------------------------------------------------------------------------
  23284 // Entropy-related functions.
  23285 
  23286 func BitsEntropyRefine(tls *libc.TLS, entropy uintptr) (r uint64_t) {
  23287 	var min_limit, mix uint64_t
  23288 	var v1, v2, v3 int64_t
  23289 	var v5 int64
  23290 	var v11 uint64
  23291 	_, _, _, _, _, _, _ = min_limit, mix, v1, v11, v2, v3, v5
  23292 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros < int32(5) {
  23293 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros <= int32(1) {
  23294 			return uint64(0)
  23295 		}
  23296 		// Two symbols, they will be 0 and 1 in a Huffman code.
  23297 		// Let's mix in a bit of entropy to favor good clustering when
  23298 		// distributions of these are combined.
  23299 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(2) {
  23300 			v1 = libc.Int64FromUint64(uint64(99)*(uint64((*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23301 			v2 = int64(100)
  23302 			if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23303 				v5 = (v1 + v2/int64(2)) / v2
  23304 			} else {
  23305 				v5 = (v1 - v2/int64(2)) / v2
  23306 			}
  23307 			v3 = v5
  23308 			goto _4
  23309 		_4:
  23310 			return libc.Uint64FromInt64(v3)
  23311 		}
  23312 		// No matter what the entropy says, we cannot be better than min_limit
  23313 		// with Huffman coding. I am mixing a bit of entropy into the
  23314 		// min_limit since it produces much better (~0.5 %) compression results
  23315 		// perhaps because of better entropy clustering.
  23316 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(3) {
  23317 			mix = uint64(950)
  23318 		} else {
  23319 			mix = uint64(700) // nonzeros == 4.
  23320 		}
  23321 	} else {
  23322 		mix = uint64(627)
  23323 	}
  23324 	min_limit = uint64(libc.Uint32FromInt32(2)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum-(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val) << int32(LOG_2_PRECISION_BITS)
  23325 	v1 = libc.Int64FromUint64(mix*min_limit + (uint64(1000)-mix)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23326 	v2 = int64(1000)
  23327 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23328 		v5 = (v1 + v2/int64(2)) / v2
  23329 	} else {
  23330 		v5 = (v1 - v2/int64(2)) / v2
  23331 	}
  23332 	v3 = v5
  23333 	goto _9
  23334 _9:
  23335 	min_limit = libc.Uint64FromInt64(v3)
  23336 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy < min_limit {
  23337 		v11 = min_limit
  23338 	} else {
  23339 		v11 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  23340 	}
  23341 	return v11
  23342 	return r
  23343 }
  23344 
  23345 func VP8LBitsEntropy(tls *libc.TLS, array uintptr, n int32) (r uint64_t) {
  23346 	bp := tls.Alloc(32)
  23347 	defer tls.Free(32)
  23348 	var _ /* entropy at bp+0 */ VP8LBitEntropy
  23349 	VP8LBitsEntropyUnrefined(tls, array, n, bp)
  23350 	return BitsEntropyRefine(tls, bp)
  23351 }
  23352 
  23353 func InitialHuffmanCost(tls *libc.TLS) (r uint64_t) {
  23354 	var v1, v2, v3 int64_t
  23355 	var v5 int64
  23356 	_, _, _, _ = v1, v2, v3, v5
  23357 	// Subtract a bias of 9.1.
  23358 	v1 = int64(libc.Int64FromInt64(91) << libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  23359 	v2 = int64(10)
  23360 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23361 		v5 = (v1 + v2/int64(2)) / v2
  23362 	} else {
  23363 		v5 = (v1 - v2/int64(2)) / v2
  23364 	}
  23365 	v3 = v5
  23366 	goto _4
  23367 _4:
  23368 	return kHuffmanCodeOfHuffmanCodeSize<<libc.Int32FromInt32(LOG_2_PRECISION_BITS) - libc.Uint64FromInt64(v3)
  23369 }
  23370 
  23371 // Small bias because Huffman code length is typically not stored in
  23372 // full length.
  23373 var kHuffmanCodeOfHuffmanCodeSize = libc.Uint64FromInt32(libc.Int32FromInt32(CODE_LENGTH_CODES) * libc.Int32FromInt32(3))
  23374 
  23375 // C documentation
  23376 //
  23377 //	// Finalize the Huffman cost based on streak numbers and length type (<3 or >=3)
  23378 func FinalHuffmanCost(tls *libc.TLS, stats uintptr) (r uint64_t) {
  23379 	var retval uint64_t
  23380 	var retval_extra uint32_t
  23381 	_, _ = retval, retval_extra
  23382 	// The constants in this function are empirical and got rounded from
  23383 	// their original values in 1/8 when switched to 1/1024.
  23384 	retval = InitialHuffmanCost(tls)
  23385 	// Second coefficient: Many zeros in the histogram are covered efficiently
  23386 	// by a run-length encode. Originally 2/8.
  23387 	retval_extra = libc.Uint32FromInt32(**(**int32)(__ccgo_up(stats))*int32(1600) + int32(240)***(**int32)(__ccgo_up(stats + 8 + 1*4)))
  23388 	// Second coefficient: Constant values are encoded less efficiently, but still
  23389 	// RLE'ed. Originally 6/8.
  23390 	retval_extra = retval_extra + libc.Uint32FromInt32(**(**int32)(__ccgo_up(stats + 1*4))*int32(2640)+int32(720)***(**int32)(__ccgo_up(stats + 8 + 1*8 + 1*4)))
  23391 	// 0s are usually encoded more efficiently than non-0s.
  23392 	// Originally 15/8.
  23393 	retval_extra = retval_extra + libc.Uint32FromInt32(int32(1840)***(**int32)(__ccgo_up(stats + 8)))
  23394 	// Originally 26/8.
  23395 	retval_extra = retval_extra + libc.Uint32FromInt32(int32(3360)***(**int32)(__ccgo_up(stats + 8 + 1*8)))
  23396 	return retval + uint64(retval_extra)<<(libc.Int32FromInt32(LOG_2_PRECISION_BITS)-libc.Int32FromInt32(10))
  23397 }
  23398 
  23399 // C documentation
  23400 //
  23401 //	// Get the symbol entropy for the distribution 'population'.
  23402 //	// Set 'trivial_sym', if there's only one symbol present in the distribution.
  23403 func PopulationCost(tls *libc.TLS, population uintptr, length int32, trivial_sym uintptr, is_used uintptr) (r uint64_t) {
  23404 	bp := tls.Alloc(48)
  23405 	defer tls.Free(48)
  23406 	var v1 uint32
  23407 	var _ /* bit_entropy at bp+0 */ VP8LBitEntropy
  23408 	var _ /* stats at bp+24 */ VP8LStreaks
  23409 	_ = v1
  23410 	(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LGetEntropyUnrefined})))(tls, population, length, bp, bp+24)
  23411 	if trivial_sym != libc.UintptrFromInt32(0) {
  23412 		if (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzeros == int32(1) {
  23413 			v1 = (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzero_code
  23414 		} else {
  23415 			v1 = uint32(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff)))
  23416 		}
  23417 		**(**uint16_t)(__ccgo_up(trivial_sym)) = uint16(v1)
  23418 	}
  23419 	if is_used != libc.UintptrFromInt32(0) {
  23420 		// The histogram is used if there is at least one non-zero streak.
  23421 		**(**uint8_t)(__ccgo_up(is_used)) = libc.BoolUint8(**(**int32)(__ccgo_up(bp + 24 + 8 + 1*8)) != 0 || **(**int32)(__ccgo_up(bp + 24 + 8 + 1*8 + 1*4)) != 0)
  23422 	}
  23423 	return BitsEntropyRefine(tls, bp) + FinalHuffmanCost(tls, bp+24)
  23424 }
  23425 
  23426 func GetPopulationInfo(tls *libc.TLS, histo uintptr, index HistogramIndex, population uintptr, length uintptr) {
  23427 	var v1, v2, v4 int32
  23428 	_, _, _ = v1, v2, v4
  23429 	switch index {
  23430 	case int32(LITERAL):
  23431 		**(**uintptr)(__ccgo_up(population)) = (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral
  23432 		v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  23433 		if v1 > 0 {
  23434 			v4 = int32(1) << v1
  23435 		} else {
  23436 			v4 = 0
  23437 		}
  23438 		v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23439 		goto _3
  23440 	_3:
  23441 		**(**int32)(__ccgo_up(length)) = v2
  23442 	case int32(RED):
  23443 		**(**uintptr)(__ccgo_up(population)) = histo + 8
  23444 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23445 	case int32(BLUE):
  23446 		**(**uintptr)(__ccgo_up(population)) = histo + 1032
  23447 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23448 	case int32(ALPHA):
  23449 		**(**uintptr)(__ccgo_up(population)) = histo + 2056
  23450 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23451 	case int32(DISTANCE):
  23452 		**(**uintptr)(__ccgo_up(population)) = histo + 3080
  23453 		**(**int32)(__ccgo_up(length)) = int32(NUM_DISTANCE_CODES)
  23454 		break
  23455 	}
  23456 }
  23457 
  23458 // C documentation
  23459 //
  23460 //	// trivial_at_end is 1 if the two histograms only have one element that is
  23461 //	// non-zero: both the zero-th one, or both the last one.
  23462 //	// 'index' is the index of the symbol in the histogram (literal, red, blue,
  23463 //	// alpha, distance).
  23464 func GetCombinedEntropy(tls *libc.TLS, h1 uintptr, h2 uintptr, index HistogramIndex) (r uint64_t) {
  23465 	bp := tls.Alloc(80)
  23466 	defer tls.Free(80)
  23467 	var is_h1_used, is_h2_used, is_trivial int32
  23468 	var _ /* X at bp+0 */ uintptr
  23469 	var _ /* Y at bp+8 */ uintptr
  23470 	var _ /* bit_entropy at bp+48 */ VP8LBitEntropy
  23471 	var _ /* length at bp+16 */ int32
  23472 	var _ /* stats at bp+20 */ VP8LStreaks
  23473 	_, _, _ = is_h1_used, is_h2_used, is_trivial
  23474 	is_h1_used = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(index))))
  23475 	is_h2_used = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(index))))
  23476 	is_trivial = libc.BoolInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(index)*2))) != libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) && libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(index)*2))) == libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h2 + 3244 + uintptr(index)*2))))
  23477 	if is_trivial != 0 || !(is_h1_used != 0) || !(is_h2_used != 0) {
  23478 		if is_h1_used != 0 {
  23479 			return **(**uint64_t)(__ccgo_up(h1 + 3264 + uintptr(index)*8))
  23480 		}
  23481 		return **(**uint64_t)(__ccgo_up(h2 + 3264 + uintptr(index)*8))
  23482 	}
  23483 	GetPopulationInfo(tls, h1, index, bp, bp+16)
  23484 	GetPopulationInfo(tls, h2, index, bp+8, bp+16)
  23485 	(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LGetCombinedEntropyUnrefined})))(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 16)), bp+48, bp+20)
  23486 	return BitsEntropyRefine(tls, bp+48) + FinalHuffmanCost(tls, bp+20)
  23487 }
  23488 
  23489 // C documentation
  23490 //
  23491 //	// Estimates the Entropy + Huffman + other block overhead size cost.
  23492 func VP8LHistogramEstimateBits(tls *libc.TLS, h uintptr) (r uint64_t) {
  23493 	bp := tls.Alloc(16)
  23494 	defer tls.Free(16)
  23495 	var cost uint64_t
  23496 	var i int32
  23497 	var _ /* length at bp+0 */ int32
  23498 	var _ /* population at bp+8 */ uintptr
  23499 	_, _ = cost, i
  23500 	cost = uint64(0)
  23501 	i = 0
  23502 	for {
  23503 		if !(i < int32(5)) {
  23504 			break
  23505 		}
  23506 		GetPopulationInfo(tls, h, i, bp+8, bp)
  23507 		cost = cost + PopulationCost(tls, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp)), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
  23508 		goto _1
  23509 	_1:
  23510 		;
  23511 		i = i + 1
  23512 	}
  23513 	cost = cost + uint64((*(*func(*libc.TLS, uintptr, int32) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LExtraCost})))(tls, (*VP8LHistogram)(unsafe.Pointer(h)).Fliteral+uintptr(NUM_LITERAL_CODES)*4, int32(NUM_LENGTH_CODES))+(*(*func(*libc.TLS, uintptr, int32) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LExtraCost})))(tls, h+3080, int32(NUM_DISTANCE_CODES)))<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  23514 	return cost
  23515 }
  23516 
  23517 // -----------------------------------------------------------------------------
  23518 // Various histogram combine/cost-eval functions
  23519 
  23520 // C documentation
  23521 //
  23522 //	// Set a + b in b, saturating at WEBP_INT64_MAX.
  23523 func SaturateAdd(tls *libc.TLS, a uint64_t, b uintptr) {
  23524 	if **(**int64_t)(__ccgo_up(b)) < 0 || libc.Int64FromUint64(a) <= libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63)-libc.Uint64FromInt32(1))-**(**int64_t)(__ccgo_up(b)) {
  23525 		**(**int64_t)(__ccgo_up(b)) += libc.Int64FromUint64(a)
  23526 	} else {
  23527 		**(**int64_t)(__ccgo_up(b)) = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  23528 	}
  23529 }
  23530 
  23531 // C documentation
  23532 //
  23533 //	// Returns 1 if the cost of the combined histogram is less than the threshold.
  23534 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23535 func GetCombinedHistogramEntropy(tls *libc.TLS, a uintptr, b uintptr, cost_threshold_in int64_t, cost uintptr, costs uintptr) (r int32) {
  23536 	var cost_threshold uint64_t
  23537 	var i int32
  23538 	_, _ = cost_threshold, i
  23539 	cost_threshold = libc.Uint64FromInt64(cost_threshold_in)
  23540 	if cost_threshold_in <= 0 {
  23541 		return 0
  23542 	}
  23543 	**(**uint64_t)(__ccgo_up(cost)) = uint64(0)
  23544 	// No need to add the extra cost for length and distance as it is a constant
  23545 	// that does not influence the histograms.
  23546 	i = 0
  23547 	for {
  23548 		if !(i < int32(5)) {
  23549 			break
  23550 		}
  23551 		**(**uint64_t)(__ccgo_up(costs + uintptr(i)*8)) = GetCombinedEntropy(tls, a, b, i)
  23552 		**(**uint64_t)(__ccgo_up(cost)) += **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  23553 		if **(**uint64_t)(__ccgo_up(cost)) >= cost_threshold {
  23554 			return 0
  23555 		}
  23556 		goto _1
  23557 	_1:
  23558 		;
  23559 		i = i + 1
  23560 	}
  23561 	return int32(1)
  23562 }
  23563 
  23564 func HistogramAdd(tls *libc.TLS, h1 uintptr, h2 uintptr, hout uintptr) {
  23565 	bp := tls.Alloc(32)
  23566 	defer tls.Free(32)
  23567 	var i, v3 int32
  23568 	var pout uintptr
  23569 	var _ /* length at bp+0 */ int32
  23570 	var _ /* p1 at bp+8 */ uintptr
  23571 	var _ /* p2 at bp+16 */ uintptr
  23572 	var _ /* pout_const at bp+24 */ uintptr
  23573 	_, _, _ = i, pout, v3
  23574 	i = 0
  23575 	for {
  23576 		if !(i < int32(5)) {
  23577 			break
  23578 		}
  23579 		GetPopulationInfo(tls, h1, i, bp+8, bp)
  23580 		GetPopulationInfo(tls, h2, i, bp+16, bp)
  23581 		GetPopulationInfo(tls, hout, i, bp+24, bp)
  23582 		pout = **(**uintptr)(__ccgo_up(bp + 24))
  23583 		if h2 == hout {
  23584 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23585 				if **(**uint8_t)(__ccgo_up(hout + 3304 + uintptr(i))) != 0 {
  23586 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pout, **(**int32)(__ccgo_up(bp)))
  23587 				} else {
  23588 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23589 				}
  23590 			}
  23591 		} else {
  23592 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23593 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23594 					(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVector})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), **(**uintptr)(__ccgo_up(bp + 16)), pout, **(**int32)(__ccgo_up(bp)))
  23595 				} else {
  23596 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23597 				}
  23598 			} else {
  23599 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23600 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 16)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23601 				} else {
  23602 					libc.Xmemset(tls, pout, 0, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23603 				}
  23604 			}
  23605 		}
  23606 		goto _1
  23607 	_1:
  23608 		;
  23609 		i = i + 1
  23610 	}
  23611 	i = 0
  23612 	for {
  23613 		if !(i < int32(5)) {
  23614 			break
  23615 		}
  23616 		if libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2))) == libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h2 + 3244 + uintptr(i)*2))) {
  23617 			v3 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2)))
  23618 		} else {
  23619 			v3 = libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff)))
  23620 		}
  23621 		**(**uint16_t)(__ccgo_up(hout + 3244 + uintptr(i)*2)) = libc.Uint16FromInt32(v3)
  23622 		**(**uint8_t)(__ccgo_up(hout + 3304 + uintptr(i))) = libc.BoolUint8(**(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 || **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0)
  23623 		goto _2
  23624 	_2:
  23625 		;
  23626 		i = i + 1
  23627 	}
  23628 }
  23629 
  23630 func UpdateHistogramCost(tls *libc.TLS, bit_cost uint64_t, costs uintptr, h uintptr) {
  23631 	var i int32
  23632 	_ = i
  23633 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = bit_cost
  23634 	i = 0
  23635 	for {
  23636 		if !(i < int32(5)) {
  23637 			break
  23638 		}
  23639 		**(**uint64_t)(__ccgo_up(h + 3264 + uintptr(i)*8)) = **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  23640 		goto _1
  23641 	_1:
  23642 		;
  23643 		i = i + 1
  23644 	}
  23645 }
  23646 
  23647 // C documentation
  23648 //
  23649 //	// Performs out = a + b, computing the cost C(a+b) - C(a) - C(b) while comparing
  23650 //	// to the threshold value 'cost_threshold'. The score returned is
  23651 //	//  Score = C(a+b) - C(a) - C(b), where C(a) + C(b) is known and fixed.
  23652 //	// Since the previous score passed is 'cost_threshold', we only need to compare
  23653 //	// the partial cost against 'cost_threshold + C(a) + C(b)' to possibly bail-out
  23654 //	// early.
  23655 //	// Returns 1 if the cost is less than the threshold.
  23656 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23657 func HistogramAddEval(tls *libc.TLS, a uintptr, b uintptr, out uintptr, _cost_threshold int64_t) (r int32) {
  23658 	bp := tls.Alloc(64)
  23659 	defer tls.Free(64)
  23660 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  23661 	var sum_cost uint64_t
  23662 	var _ /* bit_cost at bp+8 */ uint64_t
  23663 	var _ /* costs at bp+16 */ [5]uint64_t
  23664 	_ = sum_cost
  23665 	sum_cost = (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(b)).Fbit_cost
  23666 	SaturateAdd(tls, sum_cost, bp)
  23667 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  23668 		return 0
  23669 	}
  23670 	HistogramAdd(tls, a, b, out)
  23671 	UpdateHistogramCost(tls, **(**uint64_t)(__ccgo_up(bp + 8)), bp+16, out)
  23672 	return int32(1)
  23673 }
  23674 
  23675 // C documentation
  23676 //
  23677 //	// Same as HistogramAddEval(), except that the resulting histogram
  23678 //	// is not stored. Only the cost C(a+b) - C(a) is evaluated. We omit
  23679 //	// the term C(b) which is constant over all the evaluations.
  23680 //	// Returns 1 if the cost is less than the threshold.
  23681 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23682 func HistogramAddThresh(tls *libc.TLS, a uintptr, b uintptr, _cost_threshold int64_t, cost_out uintptr) (r int32) {
  23683 	bp := tls.Alloc(64)
  23684 	defer tls.Free(64)
  23685 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  23686 	var _ /* cost at bp+8 */ uint64_t
  23687 	var _ /* costs at bp+16 */ [5]uint64_t
  23688 	SaturateAdd(tls, (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost, bp)
  23689 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  23690 		return 0
  23691 	}
  23692 	**(**int64_t)(__ccgo_up(cost_out)) = libc.Int64FromUint64(**(**uint64_t)(__ccgo_up(bp + 8))) - libc.Int64FromUint64((*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost)
  23693 	return int32(1)
  23694 }
  23695 
  23696 // -----------------------------------------------------------------------------
  23697 
  23698 // C documentation
  23699 //
  23700 //	// The structure to keep track of cost range for the three dominant entropy
  23701 //	// symbols.
  23702 type DominantCostRange = struct {
  23703 	Fliteral_max uint64_t
  23704 	Fliteral_min uint64_t
  23705 	Fred_max     uint64_t
  23706 	Fred_min     uint64_t
  23707 	Fblue_max    uint64_t
  23708 	Fblue_min    uint64_t
  23709 }
  23710 
  23711 func DominantCostRangeInit(tls *libc.TLS, c uintptr) {
  23712 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = uint64(0)
  23713 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = uint64(^libc.Uint64FromUint64(0))
  23714 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = uint64(0)
  23715 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = uint64(^libc.Uint64FromUint64(0))
  23716 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = uint64(0)
  23717 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = uint64(^libc.Uint64FromUint64(0))
  23718 }
  23719 
  23720 func UpdateDominantCostRange(tls *libc.TLS, h uintptr, c uintptr) {
  23721 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  23722 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  23723 	}
  23724 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  23725 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  23726 	}
  23727 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  23728 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  23729 	}
  23730 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  23731 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  23732 	}
  23733 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  23734 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  23735 	}
  23736 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  23737 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  23738 	}
  23739 }
  23740 
  23741 func ComputeHistogramCost(tls *libc.TLS, h uintptr) {
  23742 	bp := tls.Alloc(16)
  23743 	defer tls.Free(16)
  23744 	var i int32
  23745 	var _ /* length at bp+8 */ int32
  23746 	var _ /* population at bp+0 */ uintptr
  23747 	_ = i
  23748 	// No need to add the extra cost for length and distance as it is a constant
  23749 	// that does not influence the histograms.
  23750 	i = 0
  23751 	for {
  23752 		if !(i < int32(5)) {
  23753 			break
  23754 		}
  23755 		GetPopulationInfo(tls, h, i, bp, bp+8)
  23756 		**(**uint64_t)(__ccgo_up(h + 3264 + uintptr(i)*8)) = PopulationCost(tls, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), h+3244+uintptr(i)*2, h+3304+uintptr(i))
  23757 		goto _1
  23758 	_1:
  23759 		;
  23760 		i = i + 1
  23761 	}
  23762 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) + **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) + **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) + **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(ALPHA)*8)) + **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(DISTANCE)*8))
  23763 }
  23764 
  23765 func GetBinIdForEntropy(tls *libc.TLS, min uint64_t, max uint64_t, val uint64_t) (r int32) {
  23766 	var delta, range1 uint64_t
  23767 	_, _ = delta, range1
  23768 	range1 = max - min
  23769 	if range1 > uint64(0) {
  23770 		delta = val - min
  23771 		return int32(float64((libc.Float64FromInt32(NUM_PARTITIONS)-libc.Float64FromFloat64(1e-06))*float64(delta)) / float64(range1))
  23772 	} else {
  23773 		return 0
  23774 	}
  23775 	return r
  23776 }
  23777 
  23778 func GetHistoBinIndex(tls *libc.TLS, h uintptr, c uintptr, low_effort int32) (r int32) {
  23779 	var bin_id int32
  23780 	_ = bin_id
  23781 	bin_id = GetBinIdForEntropy(tls, (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min, (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max, **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)))
  23782 	if !(low_effort != 0) {
  23783 		bin_id = bin_id*int32(NUM_PARTITIONS) + GetBinIdForEntropy(tls, (*DominantCostRange)(unsafe.Pointer(c)).Fred_min, (*DominantCostRange)(unsafe.Pointer(c)).Fred_max, **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)))
  23784 		bin_id = bin_id*int32(NUM_PARTITIONS) + GetBinIdForEntropy(tls, (*DominantCostRange)(unsafe.Pointer(c)).Fblue_min, (*DominantCostRange)(unsafe.Pointer(c)).Fblue_max, **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)))
  23785 	}
  23786 	return bin_id
  23787 }
  23788 
  23789 // C documentation
  23790 //
  23791 //	// Construct the histograms from backward references.
  23792 func HistogramBuild(tls *libc.TLS, xsize int32, histo_bits int32, backward_refs uintptr, image_histo uintptr) {
  23793 	bp := tls.Alloc(32)
  23794 	defer tls.Free(32)
  23795 	var histo_xsize, ix, x, y, v4 int32
  23796 	var histograms, v, v10, v8, v9 uintptr
  23797 	var v1, v2 uint32_t
  23798 	var _ /* c at bp+0 */ VP8LRefsCursor
  23799 	_, _, _, _, _, _, _, _, _, _, _, _ = histo_xsize, histograms, ix, v, x, y, v1, v10, v2, v4, v8, v9
  23800 	x = 0
  23801 	y = 0
  23802 	v1 = libc.Uint32FromInt32(histo_bits)
  23803 	v2 = (libc.Uint32FromInt32(xsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  23804 	goto _3
  23805 _3:
  23806 	histo_xsize = libc.Int32FromUint32(v2)
  23807 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  23808 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, backward_refs)
  23809 	VP8LHistogramSetClear(tls, image_histo)
  23810 	for {
  23811 		v4 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  23812 		goto _5
  23813 	_5:
  23814 		if !(v4 != 0) {
  23815 			break
  23816 		}
  23817 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  23818 		ix = y>>histo_bits*histo_xsize + x>>histo_bits
  23819 		HistogramAddSinglePixOrCopy(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(ix)*8)), v, libc.UintptrFromInt32(0), 0)
  23820 		v1 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  23821 		goto _7
  23822 	_7:
  23823 		x = libc.Int32FromUint32(uint32(x) + v1)
  23824 		for x >= xsize {
  23825 			x = x - xsize
  23826 			y = y + 1
  23827 		}
  23828 		v8 = bp
  23829 		v10 = v8
  23830 		*(*uintptr)(unsafe.Pointer(v10)) += 8
  23831 		v9 = *(*uintptr)(unsafe.Pointer(v10))
  23832 		if v9 == (*VP8LRefsCursor)(unsafe.Pointer(v8)).Flast_pos {
  23833 			VP8LRefsCursorNextBlock(tls, v8)
  23834 		}
  23835 	}
  23836 }
  23837 
  23838 // C documentation
  23839 //
  23840 //	// Copies the histograms and computes its bit_cost.
  23841 func HistogramCopyAndAnalyze(tls *libc.TLS, orig_histo uintptr, image_histo uintptr) {
  23842 	var histo, histograms, orig_histograms uintptr
  23843 	var i int32
  23844 	_, _, _, _ = histo, histograms, i, orig_histograms
  23845 	orig_histograms = (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fhistograms
  23846 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  23847 	(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = 0
  23848 	i = 0
  23849 	for {
  23850 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fmax_size) {
  23851 			break
  23852 		}
  23853 		histo = **(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8))
  23854 		ComputeHistogramCost(tls, histo)
  23855 		// Skip the histogram if it is completely empty, which can happen for tiles
  23856 		// with no information (when they are skipped because of LZ77).
  23857 		if !(**(**uint8_t)(__ccgo_up(histo + 3304 + uintptr(LITERAL))) != 0) && !(**(**uint8_t)(__ccgo_up(histo + 3304 + uintptr(RED))) != 0) && !(**(**uint8_t)(__ccgo_up(histo + 3304 + uintptr(BLUE))) != 0) && !(**(**uint8_t)(__ccgo_up(histo + 3304 + uintptr(ALPHA))) != 0) && !(**(**uint8_t)(__ccgo_up(histo + 3304 + uintptr(DISTANCE))) != 0) {
  23858 			// The first histogram is always used.
  23859 			**(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8)) = libc.UintptrFromInt32(0)
  23860 		} else {
  23861 			// Copy histograms from orig_histo[] to image_histo[].
  23862 			HistogramCopy(tls, histo, **(**uintptr)(__ccgo_up(histograms + uintptr((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)*8)))
  23863 			(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize + 1
  23864 		}
  23865 		goto _1
  23866 	_1:
  23867 		;
  23868 		i = i + 1
  23869 	}
  23870 }
  23871 
  23872 // C documentation
  23873 //
  23874 //	// Partition histograms to different entropy bins for three dominant (literal,
  23875 //	// red and blue) symbol costs and compute the histogram aggregate bit_cost.
  23876 func HistogramAnalyzeEntropyBin(tls *libc.TLS, image_histo uintptr, low_effort int32) {
  23877 	bp := tls.Alloc(48)
  23878 	defer tls.Free(48)
  23879 	var histo_size, i int32
  23880 	var histograms uintptr
  23881 	var _ /* cost_range at bp+0 */ DominantCostRange
  23882 	_, _, _ = histo_size, histograms, i
  23883 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  23884 	histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  23885 	DominantCostRangeInit(tls, bp)
  23886 	// Analyze the dominant (literal, red and blue) entropy costs.
  23887 	i = 0
  23888 	for {
  23889 		if !(i < histo_size) {
  23890 			break
  23891 		}
  23892 		UpdateDominantCostRange(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)), bp)
  23893 		goto _1
  23894 	_1:
  23895 		;
  23896 		i = i + 1
  23897 	}
  23898 	// bin-hash histograms on three of the dominant (literal, red and blue)
  23899 	// symbol costs and store the resulting bin_id for each histogram.
  23900 	i = 0
  23901 	for {
  23902 		if !(i < histo_size) {
  23903 			break
  23904 		}
  23905 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)))).Fbin_id = libc.Uint16FromInt32(GetHistoBinIndex(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)), bp, low_effort))
  23906 		goto _2
  23907 	_2:
  23908 		;
  23909 		i = i + 1
  23910 	}
  23911 }
  23912 
  23913 // C documentation
  23914 //
  23915 //	// Merges some histograms with same bin_id together if it's advantageous.
  23916 //	// Sets the remaining histograms to NULL.
  23917 //	// 'combine_cost_factor' has to be divided by 100.
  23918 func HistogramCombineEntropyBin(tls *libc.TLS, image_histo uintptr, _cur_combo uintptr, num_bins int32, combine_cost_factor int32_t, low_effort int32) {
  23919 	bp := tls.Alloc(16)
  23920 	defer tls.Free(16)
  23921 	*(*uintptr)(unsafe.Pointer(bp)) = _cur_combo
  23922 	var bin_id, first, idx, max_combine_failures, try_combine int32
  23923 	var bin_info [64]struct {
  23924 		Ffirst                int16_t
  23925 		Fnum_combine_failures uint16_t
  23926 	}
  23927 	var bit_cost uint64_t
  23928 	var bit_cost_thresh, v3, v4, v5 int64_t
  23929 	var histograms uintptr
  23930 	var v7 int64
  23931 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bin_id, bin_info, bit_cost, bit_cost_thresh, first, histograms, idx, max_combine_failures, try_combine, v3, v4, v5, v7
  23932 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  23933 	idx = 0
  23934 	for {
  23935 		if !(idx < num_bins) {
  23936 			break
  23937 		}
  23938 		bin_info[idx].Ffirst = int16(-int32(1))
  23939 		bin_info[idx].Fnum_combine_failures = uint16(0)
  23940 		goto _1
  23941 	_1:
  23942 		;
  23943 		idx = idx + 1
  23944 	}
  23945 	idx = 0
  23946 	for {
  23947 		if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  23948 			break
  23949 		}
  23950 		bin_id = libc.Int32FromUint16((*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbin_id)
  23951 		first = int32(bin_info[bin_id].Ffirst)
  23952 		if first == -int32(1) {
  23953 			bin_info[bin_id].Ffirst = int16(idx)
  23954 			idx = idx + 1
  23955 		} else {
  23956 			if low_effort != 0 {
  23957 				HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)))
  23958 				HistogramSetRemoveHistogram(tls, image_histo, idx)
  23959 			} else {
  23960 				// try to merge #idx into #first (both share the same bin_id)
  23961 				bit_cost = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbit_cost
  23962 				v3 = libc.Int64FromUint64(bit_cost) * int64(combine_cost_factor)
  23963 				v4 = int64(100)
  23964 				if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  23965 					v7 = (v3 + v4/int64(2)) / v4
  23966 				} else {
  23967 					v7 = (v3 - v4/int64(2)) / v4
  23968 				}
  23969 				v5 = v7
  23970 				goto _6
  23971 			_6:
  23972 				bit_cost_thresh = -v5
  23973 				if HistogramAddEval(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)), **(**uintptr)(__ccgo_up(bp)), bit_cost_thresh) != 0 {
  23974 					max_combine_failures = int32(32)
  23975 					// Try to merge two histograms only if the combo is a trivial one or
  23976 					// the two candidate histograms are already non-trivial.
  23977 					// For some images, 'try_combine' turns out to be false for a lot of
  23978 					// histogram pairs. In that case, we fallback to combining
  23979 					// histograms as usual to avoid increasing the header size.
  23980 					try_combine = libc.BoolInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 3244 + uintptr(RED)*2))) != libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) && libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 3244 + uintptr(BLUE)*2))) != libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) && libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 3244 + uintptr(ALPHA)*2))) != libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))))
  23981 					if !(try_combine != 0) {
  23982 						try_combine = libc.BoolInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)) + 3244 + uintptr(RED)*2))) == libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) || libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)) + 3244 + uintptr(BLUE)*2))) == libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) || libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)) + 3244 + uintptr(ALPHA)*2))) == libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))))
  23983 						try_combine = try_combine & libc.BoolInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)) + 3244 + uintptr(RED)*2))) == libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) || libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)) + 3244 + uintptr(BLUE)*2))) == libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))) || libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(**(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)) + 3244 + uintptr(ALPHA)*2))) == libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))))
  23984 					}
  23985 					if try_combine != 0 || libc.Int32FromUint16(bin_info[bin_id].Fnum_combine_failures) >= max_combine_failures {
  23986 						// move the (better) merged histogram to its final slot
  23987 						HistogramSwap(tls, bp, histograms+uintptr(first)*8)
  23988 						HistogramSetRemoveHistogram(tls, image_histo, idx)
  23989 					} else {
  23990 						bin_info[bin_id].Fnum_combine_failures = bin_info[bin_id].Fnum_combine_failures + 1
  23991 						idx = idx + 1
  23992 					}
  23993 				} else {
  23994 					idx = idx + 1
  23995 				}
  23996 			}
  23997 		}
  23998 		goto _2
  23999 	_2:
  24000 	}
  24001 	if low_effort != 0 {
  24002 		// for low_effort case, update the final cost when everything is merged
  24003 		idx = 0
  24004 		for {
  24005 			if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24006 				break
  24007 			}
  24008 			ComputeHistogramCost(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))
  24009 			goto _8
  24010 		_8:
  24011 			;
  24012 			idx = idx + 1
  24013 		}
  24014 	}
  24015 }
  24016 
  24017 // C documentation
  24018 //
  24019 //	// Implement a Lehmer random number generator with a multiplicative constant of
  24020 //	// 48271 and a modulo constant of 2^31 - 1.
  24021 func MyRand(tls *libc.TLS, seed uintptr) (r uint32_t) {
  24022 	**(**uint32_t)(__ccgo_up(seed)) = uint32(uint64(**(**uint32_t)(__ccgo_up(seed))) * libc.Uint64FromUint32(48271) % libc.Uint64FromUint32(2147483647))
  24023 	return **(**uint32_t)(__ccgo_up(seed))
  24024 }
  24025 
  24026 // -----------------------------------------------------------------------------
  24027 // Histogram pairs priority queue
  24028 
  24029 // C documentation
  24030 //
  24031 //	// Pair of histograms. Negative idx1 value means that pair is out-of-date.
  24032 type HistogramPair = struct {
  24033 	Fidx1       int32
  24034 	Fidx2       int32
  24035 	Fcost_diff  int64_t
  24036 	Fcost_combo uint64_t
  24037 	Fcosts      [5]uint64_t
  24038 }
  24039 
  24040 type HistoQueue = struct {
  24041 	Fqueue    uintptr
  24042 	Fsize     int32
  24043 	Fmax_size int32
  24044 }
  24045 
  24046 func HistoQueueInit(tls *libc.TLS, histo_queue uintptr, max_size int32) (r int32) {
  24047 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24048 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = max_size
  24049 	// We allocate max_size + 1 because the last element at index "size" is
  24050 	// used as temporary data (and it could be up to max_size).
  24051 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue = WebPSafeMalloc(tls, libc.Uint64FromInt32((*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size+int32(1)), uint64(64))
  24052 	return libc.BoolInt32((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue != libc.UintptrFromInt32(0))
  24053 }
  24054 
  24055 func HistoQueueClear(tls *libc.TLS, histo_queue uintptr) {
  24056 	WebPSafeFree(tls, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)
  24057 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24058 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = 0
  24059 }
  24060 
  24061 // C documentation
  24062 //
  24063 //	// Pop a specific pair in the queue by replacing it with the last one
  24064 //	// and shrinking the queue.
  24065 func HistoQueuePopPair(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24066 	**(**HistogramPair)(__ccgo_up(pair)) = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64))
  24067 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize - 1
  24068 }
  24069 
  24070 // C documentation
  24071 //
  24072 //	// Check whether a pair in the queue should be updated as head or not.
  24073 func HistoQueueUpdateHead(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24074 	var tmp HistogramPair
  24075 	_ = tmp
  24076 	if (*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff < (**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))).Fcost_diff {
  24077 		// Replace the best pair.
  24078 		tmp = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))
  24079 		**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)) = **(**HistogramPair)(__ccgo_up(pair))
  24080 		**(**HistogramPair)(__ccgo_up(pair)) = tmp
  24081 	}
  24082 }
  24083 
  24084 // C documentation
  24085 //
  24086 //	// Replaces the bad_id with good_id in the pair.
  24087 func HistoQueueFixPair(tls *libc.TLS, bad_id int32, good_id int32, pair uintptr) {
  24088 	var tmp int32
  24089 	_ = tmp
  24090 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 == bad_id {
  24091 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = good_id
  24092 	}
  24093 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 == bad_id {
  24094 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = good_id
  24095 	}
  24096 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 > (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 {
  24097 		tmp = (*HistogramPair)(unsafe.Pointer(pair)).Fidx1
  24098 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = (*HistogramPair)(unsafe.Pointer(pair)).Fidx2
  24099 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = tmp
  24100 	}
  24101 }
  24102 
  24103 // C documentation
  24104 //
  24105 //	// Update the cost diff and combo of a pair of histograms. This needs to be
  24106 //	// called when the histograms have been merged with a third one.
  24107 //	// Returns 1 if the cost diff is less than the threshold.
  24108 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24109 func HistoQueueUpdatePair(tls *libc.TLS, h1 uintptr, h2 uintptr, _cost_threshold int64_t, pair uintptr) (r int32) {
  24110 	bp := tls.Alloc(16)
  24111 	defer tls.Free(16)
  24112 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24113 	var sum_cost int64_t
  24114 	_ = sum_cost
  24115 	sum_cost = libc.Int64FromUint64((*VP8LHistogram)(unsafe.Pointer(h1)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(h2)).Fbit_cost)
  24116 	SaturateAdd(tls, libc.Uint64FromInt64(sum_cost), bp)
  24117 	if !(GetCombinedHistogramEntropy(tls, h1, h2, **(**int64_t)(__ccgo_up(bp)), pair+16, pair+24) != 0) {
  24118 		return 0
  24119 	}
  24120 	(*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff = libc.Int64FromUint64((*HistogramPair)(unsafe.Pointer(pair)).Fcost_combo) - sum_cost
  24121 	return int32(1)
  24122 }
  24123 
  24124 // C documentation
  24125 //
  24126 //	// Create a pair from indices "idx1" and "idx2" provided its cost
  24127 //	// is inferior to "threshold", a negative entropy.
  24128 //	// It returns the cost of the pair, or 0 if it superior to threshold.
  24129 func HistoQueuePush(tls *libc.TLS, histo_queue uintptr, histograms uintptr, idx1 int32, idx2 int32, threshold int64_t) (r int64_t) {
  24130 	bp := tls.Alloc(64)
  24131 	defer tls.Free(64)
  24132 	var h1, h2, v2 uintptr
  24133 	var tmp, v1 int32
  24134 	var _ /* pair at bp+0 */ HistogramPair
  24135 	_, _, _, _, _ = h1, h2, tmp, v1, v2
  24136 	// Stop here if the queue is full.
  24137 	if (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize == (*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size {
  24138 		return 0
  24139 	}
  24140 	if idx1 > idx2 {
  24141 		tmp = idx2
  24142 		idx2 = idx1
  24143 		idx1 = tmp
  24144 	}
  24145 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx1 = idx1
  24146 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx2 = idx2
  24147 	h1 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8))
  24148 	h2 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8))
  24149 	// Do not even consider the pair if it does not improve the entropy.
  24150 	if !(HistoQueueUpdatePair(tls, h1, h2, threshold, bp) != 0) {
  24151 		return 0
  24152 	}
  24153 	v2 = histo_queue + 8
  24154 	v1 = *(*int32)(unsafe.Pointer(v2))
  24155 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  24156 	**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr(v1)*64)) = **(**HistogramPair)(__ccgo_up(bp))
  24157 	HistoQueueUpdateHead(tls, histo_queue, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue+uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64)
  24158 	return (**(**HistogramPair)(__ccgo_up(bp))).Fcost_diff
  24159 }
  24160 
  24161 // -----------------------------------------------------------------------------
  24162 
  24163 // C documentation
  24164 //
  24165 //	// Combines histograms by continuously choosing the one with the highest cost
  24166 //	// reduction.
  24167 func HistogramCombineGreedy(tls *libc.TLS, image_histo uintptr) (r int32) {
  24168 	bp := tls.Alloc(16)
  24169 	defer tls.Free(16)
  24170 	var histograms, p uintptr
  24171 	var i, idx1, idx2, image_histo_size, j, ok int32
  24172 	var _ /* histo_queue at bp+0 */ HistoQueue
  24173 	_, _, _, _, _, _, _, _ = histograms, i, idx1, idx2, image_histo_size, j, ok, p
  24174 	ok = 0
  24175 	image_histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24176 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24177 	// image_histo_size^2 for the queue size is safe. If you look at
  24178 	// HistogramCombineGreedy, and imagine that UpdateQueueFront always pushes
  24179 	// data to the queue, you insert at most:
  24180 	// - image_histo_size*(image_histo_size-1)/2 (the first two for loops)
  24181 	// - image_histo_size - 1 in the last for loop at the first iteration of
  24182 	//   the while loop, image_histo_size - 2 at the second iteration ...
  24183 	//   therefore image_histo_size*(image_histo_size-1)/2 overall too
  24184 	if !(HistoQueueInit(tls, bp, image_histo_size*image_histo_size) != 0) {
  24185 		goto End
  24186 	}
  24187 	// Initialize the queue.
  24188 	i = 0
  24189 	for {
  24190 		if !(i < image_histo_size) {
  24191 			break
  24192 		}
  24193 		j = i + int32(1)
  24194 		for {
  24195 			if !(j < image_histo_size) {
  24196 				break
  24197 			}
  24198 			HistoQueuePush(tls, bp, histograms, i, j, 0)
  24199 			goto _2
  24200 		_2:
  24201 			;
  24202 			j = j + 1
  24203 		}
  24204 		goto _1
  24205 	_1:
  24206 		;
  24207 		i = i + 1
  24208 	}
  24209 	for (**(**HistoQueue)(__ccgo_up(bp))).Fsize > 0 {
  24210 		idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx1
  24211 		idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx2
  24212 		HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)))
  24213 		UpdateHistogramCost(tls, (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fcost_combo, (**(**HistoQueue)(__ccgo_up(bp))).Fqueue+24, **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)))
  24214 		// Remove merged histogram.
  24215 		HistogramSetRemoveHistogram(tls, image_histo, idx2)
  24216 		// Remove pairs intersecting the just combined best pair.
  24217 		i = 0
  24218 		for {
  24219 			if !(i < (**(**HistoQueue)(__ccgo_up(bp))).Fsize) {
  24220 				break
  24221 			}
  24222 			p = (**(**HistoQueue)(__ccgo_up(bp))).Fqueue + uintptr(i)*64
  24223 			if (*HistogramPair)(unsafe.Pointer(p)).Fidx1 == idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx2 == idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx1 == idx2 || (*HistogramPair)(unsafe.Pointer(p)).Fidx2 == idx2 {
  24224 				HistoQueuePopPair(tls, bp, p)
  24225 			} else {
  24226 				HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, idx2, p)
  24227 				HistoQueueUpdateHead(tls, bp, p)
  24228 				i = i + 1
  24229 			}
  24230 			goto _3
  24231 		_3:
  24232 		}
  24233 		// Push new pairs formed with combined histogram to the queue.
  24234 		i = 0
  24235 		for {
  24236 			if !(i < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24237 				break
  24238 			}
  24239 			if i == idx1 {
  24240 				goto _4
  24241 			}
  24242 			HistoQueuePush(tls, bp, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms, idx1, i, 0)
  24243 			goto _4
  24244 		_4:
  24245 			;
  24246 			i = i + 1
  24247 		}
  24248 	}
  24249 	ok = int32(1)
  24250 	goto End
  24251 End:
  24252 	;
  24253 	HistoQueueClear(tls, bp)
  24254 	return ok
  24255 }
  24256 
  24257 // C documentation
  24258 //
  24259 //	// Perform histogram aggregation using a stochastic approach.
  24260 //	// 'do_greedy' is set to 1 if a greedy approach needs to be performed
  24261 //	// afterwards, 0 otherwise.
  24262 func HistogramCombineStochastic(tls *libc.TLS, image_histo uintptr, min_cluster_size int32, do_greedy uintptr) (r int32) {
  24263 	bp := tls.Alloc(32)
  24264 	defer tls.Free(32)
  24265 	var best_cost, curr_cost int64_t
  24266 	var best_idx1, best_idx2, is_idx1_best, is_idx2_best, iter, j, kHistoQueueSize, num_tries, num_tries_no_success, ok, outer_iters, tries_with_no_success, v2 int32
  24267 	var histograms, p uintptr
  24268 	var idx1, idx2, rand_range, tmp uint32_t
  24269 	var v3 bool
  24270 	var v4 int64
  24271 	var _ /* histo_queue at bp+8 */ HistoQueue
  24272 	var _ /* seed at bp+0 */ uint32_t
  24273 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_cost, best_idx1, best_idx2, curr_cost, histograms, idx1, idx2, is_idx1_best, is_idx2_best, iter, j, kHistoQueueSize, num_tries, num_tries_no_success, ok, outer_iters, p, rand_range, tmp, tries_with_no_success, v2, v3, v4
  24274 	**(**uint32_t)(__ccgo_up(bp)) = uint32(1)
  24275 	tries_with_no_success = 0
  24276 	outer_iters = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24277 	num_tries_no_success = outer_iters / int32(2)
  24278 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24279 	kHistoQueueSize = int32(9)
  24280 	ok = 0
  24281 	if (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize < min_cluster_size {
  24282 		**(**int32)(__ccgo_up(do_greedy)) = int32(1)
  24283 		return int32(1)
  24284 	}
  24285 	if !(HistoQueueInit(tls, bp+8, kHistoQueueSize) != 0) {
  24286 		goto End
  24287 	}
  24288 	// Collapse similar histograms in 'image_histo'.
  24289 	iter = 0
  24290 	for {
  24291 		if v3 = iter < outer_iters && (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= min_cluster_size; v3 {
  24292 			tries_with_no_success = tries_with_no_success + 1
  24293 			v2 = tries_with_no_success
  24294 		}
  24295 		if !(v3 && v2 < num_tries_no_success) {
  24296 			break
  24297 		}
  24298 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24299 			v4 = 0
  24300 		} else {
  24301 			v4 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fcost_diff
  24302 		}
  24303 		best_cost = v4
  24304 		best_idx1 = -int32(1)
  24305 		best_idx2 = int32(1)
  24306 		rand_range = libc.Uint32FromInt32(((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize - int32(1)) * (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)
  24307 		// (image_histo->size) / 2 was chosen empirically. Less means faster but
  24308 		// worse compression.
  24309 		num_tries = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize / int32(2)
  24310 		// Pick random samples.
  24311 		j = 0
  24312 		for {
  24313 			if !((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= int32(2) && j < num_tries) {
  24314 				break
  24315 			}
  24316 			// Choose two different histograms at random and try to combine them.
  24317 			tmp = MyRand(tls, bp) % rand_range
  24318 			idx1 = tmp / libc.Uint32FromInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24319 			idx2 = tmp % libc.Uint32FromInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24320 			if idx2 >= idx1 {
  24321 				idx2 = idx2 + 1
  24322 			}
  24323 			// Calculate cost reduction on combination.
  24324 			curr_cost = HistoQueuePush(tls, bp+8, histograms, libc.Int32FromUint32(idx1), libc.Int32FromUint32(idx2), best_cost)
  24325 			if curr_cost < 0 { // found a better pair?
  24326 				best_cost = curr_cost
  24327 				// Empty the queue if we reached full capacity.
  24328 				if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == (**(**HistoQueue)(__ccgo_up(bp + 8))).Fmax_size {
  24329 					break
  24330 				}
  24331 			}
  24332 			goto _5
  24333 		_5:
  24334 			;
  24335 			j = j + 1
  24336 		}
  24337 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24338 			goto _1
  24339 		}
  24340 		// Get the best histograms.
  24341 		best_idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx1
  24342 		best_idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx2
  24343 		// Merge the histograms and remove best_idx2 from the queue.
  24344 		HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(best_idx2)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(best_idx1)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(best_idx1)*8)))
  24345 		UpdateHistogramCost(tls, (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fcost_combo, (**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue+24, **(**uintptr)(__ccgo_up(histograms + uintptr(best_idx1)*8)))
  24346 		HistogramSetRemoveHistogram(tls, image_histo, best_idx2)
  24347 		// Parse the queue and update each pair that deals with best_idx1,
  24348 		// best_idx2 or image_histo_size.
  24349 		j = 0
  24350 		for {
  24351 			if !(j < (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize) {
  24352 				break
  24353 			}
  24354 			p = (**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue + uintptr(j)*64
  24355 			is_idx1_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx2)
  24356 			is_idx2_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx2)
  24357 			// The front pair could have been duplicated by a random pick so
  24358 			// check for it all the time nevertheless.
  24359 			if is_idx1_best != 0 && is_idx2_best != 0 {
  24360 				HistoQueuePopPair(tls, bp+8, p)
  24361 				goto _6
  24362 			}
  24363 			// Any pair containing one of the two best indices should only refer to
  24364 			// best_idx1. Its cost should also be updated.
  24365 			if is_idx1_best != 0 || is_idx2_best != 0 {
  24366 				HistoQueueFixPair(tls, best_idx2, best_idx1, p)
  24367 				// Re-evaluate the cost of an updated pair.
  24368 				if !(HistoQueueUpdatePair(tls, **(**uintptr)(__ccgo_up(histograms + uintptr((*HistogramPair)(unsafe.Pointer(p)).Fidx1)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr((*HistogramPair)(unsafe.Pointer(p)).Fidx2)*8)), 0, p) != 0) {
  24369 					HistoQueuePopPair(tls, bp+8, p)
  24370 					goto _6
  24371 				}
  24372 			}
  24373 			HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, best_idx2, p)
  24374 			HistoQueueUpdateHead(tls, bp+8, p)
  24375 			j = j + 1
  24376 			goto _6
  24377 		_6:
  24378 		}
  24379 		tries_with_no_success = 0
  24380 		goto _1
  24381 	_1:
  24382 		;
  24383 		iter = iter + 1
  24384 	}
  24385 	**(**int32)(__ccgo_up(do_greedy)) = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize <= min_cluster_size)
  24386 	ok = int32(1)
  24387 	goto End
  24388 End:
  24389 	;
  24390 	HistoQueueClear(tls, bp+8)
  24391 	return ok
  24392 }
  24393 
  24394 // -----------------------------------------------------------------------------
  24395 // Histogram refinement
  24396 
  24397 // C documentation
  24398 //
  24399 //	// Find the best 'out' histogram for each of the 'in' histograms.
  24400 //	// At call-time, 'out' contains the histograms of the clusters.
  24401 //	// Note: we assume that out[]->bit_cost is already up-to-date.
  24402 func HistogramRemap(tls *libc.TLS, in uintptr, out uintptr, symbols uintptr) {
  24403 	bp := tls.Alloc(16)
  24404 	defer tls.Free(16)
  24405 	var best_bits int64_t
  24406 	var best_out, i, idx, in_size, k, out_size int32
  24407 	var in_histo, out_histo uintptr
  24408 	var _ /* cur_bits at bp+0 */ int64_t
  24409 	_, _, _, _, _, _, _, _, _ = best_bits, best_out, i, idx, in_histo, in_size, k, out_histo, out_size
  24410 	in_histo = (*VP8LHistogramSet)(unsafe.Pointer(in)).Fhistograms
  24411 	out_histo = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fhistograms
  24412 	in_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fmax_size
  24413 	out_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize
  24414 	if out_size > int32(1) {
  24415 		i = 0
  24416 		for {
  24417 			if !(i < in_size) {
  24418 				break
  24419 			}
  24420 			best_out = 0
  24421 			best_bits = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  24422 			if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24423 				// Arbitrarily set to the previous value if unused to help future LZ77.
  24424 				**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(symbols + uintptr(i-int32(1))*4))
  24425 				goto _1
  24426 			}
  24427 			k = 0
  24428 			for {
  24429 				if !(k < out_size) {
  24430 					break
  24431 				}
  24432 				if HistogramAddThresh(tls, **(**uintptr)(__ccgo_up(out_histo + uintptr(k)*8)), **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)), best_bits, bp) != 0 {
  24433 					best_bits = **(**int64_t)(__ccgo_up(bp))
  24434 					best_out = k
  24435 				}
  24436 				goto _2
  24437 			_2:
  24438 				;
  24439 				k = k + 1
  24440 			}
  24441 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = libc.Uint32FromInt32(best_out)
  24442 			goto _1
  24443 		_1:
  24444 			;
  24445 			i = i + 1
  24446 		}
  24447 	} else {
  24448 		i = 0
  24449 		for {
  24450 			if !(i < in_size) {
  24451 				break
  24452 			}
  24453 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = uint32(0)
  24454 			goto _3
  24455 		_3:
  24456 			;
  24457 			i = i + 1
  24458 		}
  24459 	}
  24460 	// Recompute each out based on raw and symbols.
  24461 	VP8LHistogramSetClear(tls, out)
  24462 	(*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize = out_size
  24463 	i = 0
  24464 	for {
  24465 		if !(i < in_size) {
  24466 			break
  24467 		}
  24468 		if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24469 			goto _4
  24470 		}
  24471 		idx = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)))
  24472 		HistogramAdd(tls, **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)), **(**uintptr)(__ccgo_up(out_histo + uintptr(idx)*8)), **(**uintptr)(__ccgo_up(out_histo + uintptr(idx)*8)))
  24473 		goto _4
  24474 	_4:
  24475 		;
  24476 		i = i + 1
  24477 	}
  24478 }
  24479 
  24480 func GetCombineCostFactor(tls *libc.TLS, histo_size int32, quality int32) (r int32_t) {
  24481 	var combine_cost_factor int32_t
  24482 	_ = combine_cost_factor
  24483 	combine_cost_factor = int32(16)
  24484 	if quality < int32(90) {
  24485 		if histo_size > int32(256) {
  24486 			combine_cost_factor = combine_cost_factor / int32(2)
  24487 		}
  24488 		if histo_size > int32(512) {
  24489 			combine_cost_factor = combine_cost_factor / int32(2)
  24490 		}
  24491 		if histo_size > int32(1024) {
  24492 			combine_cost_factor = combine_cost_factor / int32(2)
  24493 		}
  24494 		if quality <= int32(50) {
  24495 			combine_cost_factor = combine_cost_factor / int32(2)
  24496 		}
  24497 	}
  24498 	return combine_cost_factor
  24499 }
  24500 
  24501 func VP8LGetHistoImageSymbols(tls *libc.TLS, xsize int32, ysize int32, refs uintptr, quality int32, low_effort int32, histogram_bits int32, cache_bits int32, image_histo uintptr, tmp_histo uintptr, histogram_symbols uintptr, pic uintptr, percent_range int32, percent uintptr) (r int32) {
  24502 	bp := tls.Alloc(16)
  24503 	defer tls.Free(16)
  24504 	var combine_cost_factor int32_t
  24505 	var entropy_combine, entropy_combine_num_bins, histo_xsize, histo_ysize, image_histo_raw_size, threshold_size, v9 int32
  24506 	var orig_histo uintptr
  24507 	var v1, v5 uint32
  24508 	var v10, v11, v12 int64_t
  24509 	var v14 int64
  24510 	var v2, v3, v6, v7 uint32_t
  24511 	var _ /* do_greedy at bp+0 */ int32
  24512 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = combine_cost_factor, entropy_combine, entropy_combine_num_bins, histo_xsize, histo_ysize, image_histo_raw_size, orig_histo, threshold_size, v1, v10, v11, v12, v14, v2, v3, v5, v6, v7, v9
  24513 	if histogram_bits != 0 {
  24514 		v2 = libc.Uint32FromInt32(histogram_bits)
  24515 		v3 = (libc.Uint32FromInt32(xsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  24516 		goto _4
  24517 	_4:
  24518 		v1 = v3
  24519 	} else {
  24520 		v1 = uint32(1)
  24521 	}
  24522 	histo_xsize = libc.Int32FromUint32(v1)
  24523 	if histogram_bits != 0 {
  24524 		v6 = libc.Uint32FromInt32(histogram_bits)
  24525 		v7 = (libc.Uint32FromInt32(ysize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  24526 		goto _8
  24527 	_8:
  24528 		v5 = v7
  24529 	} else {
  24530 		v5 = uint32(1)
  24531 	}
  24532 	histo_ysize = libc.Int32FromUint32(v5)
  24533 	image_histo_raw_size = histo_xsize * histo_ysize
  24534 	orig_histo = VP8LAllocateHistogramSet(tls, image_histo_raw_size, cache_bits)
  24535 	if low_effort != 0 {
  24536 		v9 = int32(NUM_PARTITIONS)
  24537 	} else {
  24538 		v9 = libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS)
  24539 	}
  24540 	// Don't attempt linear bin-partition heuristic for
  24541 	// histograms of small sizes (as bin_map will be very sparse) and
  24542 	// maximum quality q==100 (to preserve the compression gains at that level).
  24543 	entropy_combine_num_bins = v9
  24544 	if orig_histo == libc.UintptrFromInt32(0) {
  24545 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24546 		goto Error
  24547 	}
  24548 	// Construct the histograms from backward references.
  24549 	HistogramBuild(tls, xsize, histogram_bits, refs, orig_histo)
  24550 	HistogramCopyAndAnalyze(tls, orig_histo, image_histo)
  24551 	entropy_combine = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize > entropy_combine_num_bins*int32(2) && quality < int32(100))
  24552 	if entropy_combine != 0 {
  24553 		combine_cost_factor = GetCombineCostFactor(tls, image_histo_raw_size, quality)
  24554 		HistogramAnalyzeEntropyBin(tls, image_histo, low_effort)
  24555 		// Collapse histograms with similar entropy.
  24556 		HistogramCombineEntropyBin(tls, image_histo, tmp_histo, entropy_combine_num_bins, combine_cost_factor, low_effort)
  24557 	}
  24558 	// Don't combine the histograms using stochastic and greedy heuristics for
  24559 	// low-effort compression mode.
  24560 	if !(low_effort != 0) || !(entropy_combine != 0) {
  24561 		v10 = int64(quality * quality * quality * (libc.Int32FromInt32(MAX_HISTO_GREEDY) - libc.Int32FromInt32(1)))
  24562 		v11 = int64(libc.Int32FromInt32(100) * libc.Int32FromInt32(100) * libc.Int32FromInt32(100))
  24563 		if libc.BoolInt32(v10 < 0) == libc.BoolInt32(v11 < 0) {
  24564 			v14 = (v10 + v11/int64(2)) / v11
  24565 		} else {
  24566 			v14 = (v10 - v11/int64(2)) / v11
  24567 		}
  24568 		v12 = v14
  24569 		goto _13
  24570 	_13:
  24571 		// cubic ramp between 1 and MAX_HISTO_GREEDY:
  24572 		threshold_size = int32(libc.Int64FromInt32(1) + v12)
  24573 		if !(HistogramCombineStochastic(tls, image_histo, threshold_size, bp) != 0) {
  24574 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24575 			goto Error
  24576 		}
  24577 		if **(**int32)(__ccgo_up(bp)) != 0 {
  24578 			if !(HistogramCombineGreedy(tls, image_histo) != 0) {
  24579 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24580 				goto Error
  24581 			}
  24582 		}
  24583 	}
  24584 	// Find the optimal map from original histograms to the final ones.
  24585 	HistogramRemap(tls, orig_histo, image_histo, histogram_symbols)
  24586 	if !(WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent) != 0) {
  24587 		goto Error
  24588 	}
  24589 	goto Error
  24590 Error:
  24591 	;
  24592 	VP8LFreeHistogramSet(tls, orig_histo)
  24593 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  24594 }
  24595 
  24596 //------------------------------------------------------------------------------
  24597 
  24598 // Copyright 2012 Google Inc. All Rights Reserved.
  24599 //
  24600 // Use of this source code is governed by a BSD-style license
  24601 // that can be found in the COPYING file in the root of the source
  24602 // tree. An additional intellectual property rights grant can be found
  24603 // in the file PATENTS. All contributing project authors may
  24604 // be found in the AUTHORS file in the root of the source tree.
  24605 // -----------------------------------------------------------------------------
  24606 //
  24607 // Misc. common utility functions
  24608 //
  24609 // Authors: Skal (pascal.massimino@gmail.com)
  24610 //          Urvang (urvang@google.com)
  24611 
  24612 // Copyright 2010 Google Inc. All Rights Reserved.
  24613 //
  24614 // Use of this source code is governed by a BSD-style license
  24615 // that can be found in the COPYING file in the root of the source
  24616 // tree. An additional intellectual property rights grant can be found
  24617 // in the file PATENTS. All contributing project authors may
  24618 // be found in the AUTHORS file in the root of the source tree.
  24619 // -----------------------------------------------------------------------------
  24620 //
  24621 //  Common types + memory wrappers
  24622 //
  24623 // Author: Skal (pascal.massimino@gmail.com)
  24624 
  24625 //------------------------------------------------------------------------------
  24626 // VP8Iterator
  24627 //------------------------------------------------------------------------------
  24628 
  24629 func InitLeft(tls *libc.TLS, it uintptr) {
  24630 	var v1, v2 uint8_t
  24631 	var v3 int32
  24632 	_, _, _ = v1, v2, v3
  24633 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy > 0 {
  24634 		v3 = int32(129)
  24635 	} else {
  24636 		v3 = int32(127)
  24637 	}
  24638 	v2 = libc.Uint8FromInt32(v3)
  24639 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  24640 	v1 = v2
  24641 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  24642 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  24643 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, int32(129), uint64(16))
  24644 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, int32(129), uint64(8))
  24645 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, int32(129), uint64(8))
  24646 	**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  24647 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  24648 		libc.Xmemset(tls, it+344, 0, uint64(4))
  24649 	}
  24650 }
  24651 
  24652 func InitTop(tls *libc.TLS, it uintptr) {
  24653 	var enc uintptr
  24654 	var top_size size_t
  24655 	_, _ = enc, top_size
  24656 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24657 	top_size = libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * int32(16))
  24658 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top, int32(127), uint64(2)*top_size)
  24659 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fnz, 0, libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  24660 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr != libc.UintptrFromInt32(0) {
  24661 		libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr, 0, libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  24662 	}
  24663 }
  24664 
  24665 func VP8IteratorSetRow(tls *libc.TLS, it uintptr, y int32) {
  24666 	var enc uintptr
  24667 	_ = enc
  24668 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24669 	(*VP8EncIterator)(unsafe.Pointer(it)).Fx = 0
  24670 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy = y
  24671 	(*VP8EncIterator)(unsafe.Pointer(it)).Fbw = enc + 112 + uintptr(y&((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))*48
  24672 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpreds = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds + uintptr(y*int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  24673 	(*VP8EncIterator)(unsafe.Pointer(it)).Fnz = (*VP8Encoder)(unsafe.Pointer(enc)).Fnz
  24674 	(*VP8EncIterator)(unsafe.Pointer(it)).Fmb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(y*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*4
  24675 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top
  24676 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top
  24677 	InitLeft(tls, it)
  24678 }
  24679 
  24680 // C documentation
  24681 //
  24682 //	// restart a scan
  24683 func VP8IteratorReset(tls *libc.TLS, it uintptr) {
  24684 	var enc uintptr
  24685 	_ = enc
  24686 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24687 	VP8IteratorSetRow(tls, it, 0)
  24688 	VP8IteratorSetCountDown(tls, it, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) // default
  24689 	InitTop(tls, it)
  24690 	libc.Xmemset(tls, it+208, 0, uint64(96))
  24691 	(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = 0
  24692 }
  24693 
  24694 func VP8IteratorSetCountDown(tls *libc.TLS, it uintptr, count_down int32) {
  24695 	var v1 int32
  24696 	_ = v1
  24697 	v1 = count_down
  24698 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 = v1
  24699 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down = v1
  24700 }
  24701 
  24702 func VP8IteratorIsDone(tls *libc.TLS, it uintptr) (r int32) {
  24703 	return libc.BoolInt32((*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down <= 0)
  24704 }
  24705 
  24706 func VP8IteratorInit(tls *libc.TLS, enc uintptr, it uintptr) {
  24707 	(*VP8EncIterator)(unsafe.Pointer(it)).Fenc = enc
  24708 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in = uintptr((uintptr_t(it+488) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  24709 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  24710 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  24711 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  24712 	(*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats = (*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats
  24713 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent
  24714 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_left = uintptr((uint64(it+400+libc.UintptrFromInt32(1)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  24715 	(*VP8EncIterator)(unsafe.Pointer(it)).Fu_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(16) + uintptr(16)
  24716 	(*VP8EncIterator)(unsafe.Pointer(it)).Fv_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(16)
  24717 	(*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr = (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr
  24718 	VP8IteratorReset(tls, it)
  24719 }
  24720 
  24721 func VP8IteratorProgress(tls *libc.TLS, it uintptr, delta int32) (r int32) {
  24722 	var done, percent, v1 int32
  24723 	var enc uintptr
  24724 	_, _, _, _ = done, enc, percent, v1
  24725 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24726 	if delta != 0 && (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fprogress_hook != libc.UintptrFromInt32(0) {
  24727 		done = (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 - (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down
  24728 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 <= 0 {
  24729 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0
  24730 		} else {
  24731 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 + delta*done/(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0
  24732 		}
  24733 		percent = v1
  24734 		return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, percent, enc+536)
  24735 	}
  24736 	return int32(1)
  24737 }
  24738 
  24739 //------------------------------------------------------------------------------
  24740 // Import the source samples into the cache. Takes care of replicating
  24741 // boundary pixels if necessary.
  24742 
  24743 func MinSize(tls *libc.TLS, a int32, b int32) (r int32) {
  24744 	var v1 int32
  24745 	_ = v1
  24746 	if a < b {
  24747 		v1 = a
  24748 	} else {
  24749 		v1 = b
  24750 	}
  24751 	return v1
  24752 }
  24753 
  24754 func ImportBlock(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, w int32, h int32, size int32) {
  24755 	var i int32
  24756 	_ = i
  24757 	i = 0
  24758 	for {
  24759 		if !(i < h) {
  24760 			break
  24761 		}
  24762 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(w))
  24763 		if w < size {
  24764 			libc.Xmemset(tls, dst+uintptr(w), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(w-int32(1))))), libc.Uint64FromInt32(size-w))
  24765 		}
  24766 		dst = dst + uintptr(BPS)
  24767 		src = src + uintptr(src_stride)
  24768 		goto _1
  24769 	_1:
  24770 		;
  24771 		i = i + 1
  24772 	}
  24773 	i = h
  24774 	for {
  24775 		if !(i < size) {
  24776 			break
  24777 		}
  24778 		libc.Xmemcpy(tls, dst, dst-uintptr(BPS), libc.Uint64FromInt32(size))
  24779 		dst = dst + uintptr(BPS)
  24780 		goto _2
  24781 	_2:
  24782 		;
  24783 		i = i + 1
  24784 	}
  24785 }
  24786 
  24787 func ImportLine(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, len1 int32, total_len int32) {
  24788 	var i int32
  24789 	_ = i
  24790 	i = 0
  24791 	for {
  24792 		if !(i < len1) {
  24793 			break
  24794 		}
  24795 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src))
  24796 		goto _1
  24797 	_1:
  24798 		;
  24799 		i = i + 1
  24800 		src = src + uintptr(src_stride)
  24801 	}
  24802 	for {
  24803 		if !(i < total_len) {
  24804 			break
  24805 		}
  24806 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(dst + uintptr(len1-int32(1))))
  24807 		goto _2
  24808 	_2:
  24809 		;
  24810 		i = i + 1
  24811 	}
  24812 }
  24813 
  24814 func VP8IteratorImport(tls *libc.TLS, it uintptr, tmp_32 uintptr) {
  24815 	var enc, pic, usrc, vsrc, ysrc uintptr
  24816 	var h, uv_h, uv_w, w, x, y int32
  24817 	var v1, v2 uint8_t
  24818 	_, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, usrc, uv_h, uv_w, vsrc, w, x, y, ysrc, v1, v2
  24819 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24820 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  24821 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  24822 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  24823 	ysrc = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  24824 	usrc = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  24825 	vsrc = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  24826 	w = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth-x*int32(16), int32(16))
  24827 	h = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fheight-y*int32(16), int32(16))
  24828 	uv_w = (w + int32(1)) >> int32(1)
  24829 	uv_h = (h + int32(1)) >> int32(1)
  24830 	ImportBlock(tls, ysrc, (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), w, h, int32(16))
  24831 	ImportBlock(tls, usrc, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in+uintptr(libc.Int32FromInt32(U_OFF_ENC)), uv_w, uv_h, int32(8))
  24832 	ImportBlock(tls, vsrc, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in+uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8)), uv_w, uv_h, int32(8))
  24833 	if tmp_32 == libc.UintptrFromInt32(0) {
  24834 		return
  24835 	}
  24836 	// Import source (uncompressed) samples into boundary.
  24837 	if x == 0 {
  24838 		InitLeft(tls, it)
  24839 	} else {
  24840 		if y == 0 {
  24841 			v2 = libc.Uint8FromInt32(127)
  24842 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  24843 			v1 = v2
  24844 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  24845 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  24846 		} else {
  24847 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = **(**uint8_t)(__ccgo_up(ysrc + uintptr(-int32(1)-(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride)))
  24848 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = **(**uint8_t)(__ccgo_up(usrc + uintptr(-int32(1)-(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride)))
  24849 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = **(**uint8_t)(__ccgo_up(vsrc + uintptr(-int32(1)-(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride)))
  24850 		}
  24851 		ImportLine(tls, ysrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, h, int32(16))
  24852 		ImportLine(tls, usrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, uv_h, int32(8))
  24853 		ImportLine(tls, vsrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, uv_h, int32(8))
  24854 	}
  24855 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = tmp_32 + uintptr(0)
  24856 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = tmp_32 + uintptr(16)
  24857 	if y == 0 {
  24858 		libc.Xmemset(tls, tmp_32, int32(127), libc.Uint64FromInt32(32)*libc.Uint64FromInt64(1))
  24859 	} else {
  24860 		ImportLine(tls, ysrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fy_stride), int32(1), tmp_32, w, int32(16))
  24861 		ImportLine(tls, usrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16), uv_w, int32(8))
  24862 		ImportLine(tls, vsrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16)+uintptr(8), uv_w, int32(8))
  24863 	}
  24864 }
  24865 
  24866 //------------------------------------------------------------------------------
  24867 // Copy back the compressed samples into user space if requested.
  24868 
  24869 func ExportBlock(tls *libc.TLS, src uintptr, dst uintptr, dst_stride int32, w int32, h int32) {
  24870 	var v1 int32
  24871 	_ = v1
  24872 	for {
  24873 		v1 = h
  24874 		h = h - 1
  24875 		if !(v1 > 0) {
  24876 			break
  24877 		}
  24878 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(w))
  24879 		dst = dst + uintptr(dst_stride)
  24880 		src = src + uintptr(BPS)
  24881 	}
  24882 }
  24883 
  24884 func VP8IteratorExport(tls *libc.TLS, it uintptr) {
  24885 	var enc, pic, udst, usrc, vdst, vsrc, ydst, ysrc uintptr
  24886 	var h, uv_h, uv_w, w, x, y int32
  24887 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, udst, usrc, uv_h, uv_w, vdst, vsrc, w, x, y, ydst, ysrc
  24888 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24889 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fshow_compressed != 0 {
  24890 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  24891 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  24892 		ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  24893 		usrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  24894 		vsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  24895 		pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  24896 		ydst = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  24897 		udst = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  24898 		vdst = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  24899 		w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - x*int32(16)
  24900 		h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - y*int32(16)
  24901 		if w > int32(16) {
  24902 			w = int32(16)
  24903 		}
  24904 		if h > int32(16) {
  24905 			h = int32(16)
  24906 		}
  24907 		// Luma plane
  24908 		ExportBlock(tls, ysrc, ydst, (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, w, h)
  24909 		// U/V planes
  24910 		uv_w = (w + int32(1)) >> int32(1)
  24911 		uv_h = (h + int32(1)) >> int32(1)
  24912 		ExportBlock(tls, usrc, udst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  24913 		ExportBlock(tls, vsrc, vdst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  24914 	}
  24915 }
  24916 
  24917 //------------------------------------------------------------------------------
  24918 // Non-zero contexts setup/teardown
  24919 
  24920 // Nz bits:
  24921 //  0  1  2  3  Y
  24922 //  4  5  6  7
  24923 //  8  9 10 11
  24924 // 12 13 14 15
  24925 // 16 17        U
  24926 // 18 19
  24927 // 20 21        V
  24928 // 22 23
  24929 // 24           DC-intra16
  24930 
  24931 // Convert packed context to byte array
  24932 
  24933 func VP8IteratorNzToBytes(tls *libc.TLS, it uintptr) {
  24934 	var left_nz, top_nz uintptr
  24935 	var lnz, tnz int32
  24936 	_, _, _, _ = left_nz, lnz, tnz, top_nz
  24937 	tnz = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)))
  24938 	lnz = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)))
  24939 	top_nz = it + 132
  24940 	left_nz = it + 168
  24941 	// Top-Y
  24942 	**(**int32)(__ccgo_up(top_nz)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(12)) != 0))
  24943 	**(**int32)(__ccgo_up(top_nz + 1*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(13)) != 0))
  24944 	**(**int32)(__ccgo_up(top_nz + 2*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(14)) != 0))
  24945 	**(**int32)(__ccgo_up(top_nz + 3*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  24946 	// Top-U
  24947 	**(**int32)(__ccgo_up(top_nz + 4*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(18)) != 0))
  24948 	**(**int32)(__ccgo_up(top_nz + 5*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  24949 	// Top-V
  24950 	**(**int32)(__ccgo_up(top_nz + 6*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(22)) != 0))
  24951 	**(**int32)(__ccgo_up(top_nz + 7*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  24952 	// DC
  24953 	**(**int32)(__ccgo_up(top_nz + 8*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) != 0))
  24954 	// left-Y
  24955 	**(**int32)(__ccgo_up(left_nz)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(3)) != 0))
  24956 	**(**int32)(__ccgo_up(left_nz + 1*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(7)) != 0))
  24957 	**(**int32)(__ccgo_up(left_nz + 2*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(11)) != 0))
  24958 	**(**int32)(__ccgo_up(left_nz + 3*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  24959 	// left-U
  24960 	**(**int32)(__ccgo_up(left_nz + 4*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(17)) != 0))
  24961 	**(**int32)(__ccgo_up(left_nz + 5*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  24962 	// left-V
  24963 	**(**int32)(__ccgo_up(left_nz + 6*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(21)) != 0))
  24964 	**(**int32)(__ccgo_up(left_nz + 7*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  24965 	// left-DC is special, iterated separately
  24966 }
  24967 
  24968 func VP8IteratorBytesToNz(tls *libc.TLS, it uintptr) {
  24969 	var left_nz, top_nz uintptr
  24970 	var nz uint32_t
  24971 	_, _, _ = left_nz, nz, top_nz
  24972 	nz = uint32(0)
  24973 	top_nz = it + 132
  24974 	left_nz = it + 168
  24975 	// top
  24976 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz))<<libc.Int32FromInt32(12)|**(**int32)(__ccgo_up(top_nz + 1*4))<<libc.Int32FromInt32(13))
  24977 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 2*4))<<libc.Int32FromInt32(14)|**(**int32)(__ccgo_up(top_nz + 3*4))<<libc.Int32FromInt32(15))
  24978 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 4*4))<<libc.Int32FromInt32(18)|**(**int32)(__ccgo_up(top_nz + 5*4))<<libc.Int32FromInt32(19))
  24979 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 6*4))<<libc.Int32FromInt32(22)|**(**int32)(__ccgo_up(top_nz + 7*4))<<libc.Int32FromInt32(23))
  24980 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 8*4))<<libc.Int32FromInt32(24)) // we propagate the _top_ bit, esp. for intra4
  24981 	// left
  24982 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(left_nz))<<libc.Int32FromInt32(3)|**(**int32)(__ccgo_up(left_nz + 1*4))<<libc.Int32FromInt32(7))
  24983 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(left_nz + 2*4))<<libc.Int32FromInt32(11))
  24984 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(left_nz + 4*4))<<libc.Int32FromInt32(17)|**(**int32)(__ccgo_up(left_nz + 6*4))<<libc.Int32FromInt32(21))
  24985 	**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = nz
  24986 }
  24987 
  24988 //------------------------------------------------------------------------------
  24989 // Advance to the next position, doing the bookkeeping.
  24990 
  24991 func VP8IteratorSaveBoundary(tls *libc.TLS, it uintptr) {
  24992 	var enc, uvsrc, ysrc uintptr
  24993 	var i, x, y int32
  24994 	_, _, _, _, _, _ = enc, i, uvsrc, x, y, ysrc
  24995 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24996 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  24997 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  24998 	ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  24999 	uvsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25000 	if x < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25001 		i = 0
  25002 		for {
  25003 			if !(i < int32(16)) {
  25004 				break
  25005 			}
  25006 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(ysrc + uintptr(int32(15)+i*int32(BPS))))
  25007 			goto _1
  25008 		_1:
  25009 			;
  25010 			i = i + 1
  25011 		}
  25012 		i = 0
  25013 		for {
  25014 			if !(i < int32(8)) {
  25015 				break
  25016 			}
  25017 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(7)+i*int32(BPS))))
  25018 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(15)+i*int32(BPS))))
  25019 			goto _2
  25020 		_2:
  25021 			;
  25022 			i = i + 1
  25023 		}
  25024 		// top-left (before 'top'!)
  25025 		**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + 15))
  25026 		**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(7))))
  25027 		**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top + uintptr(libc.Int32FromInt32(8)+libc.Int32FromInt32(7))))
  25028 	}
  25029 	if y < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h-int32(1) { // top
  25030 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top, ysrc+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
  25031 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top, uvsrc+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), libc.Uint64FromInt32(libc.Int32FromInt32(8)+libc.Int32FromInt32(8)))
  25032 	}
  25033 }
  25034 
  25035 func VP8IteratorNext(tls *libc.TLS, it uintptr) (r int32) {
  25036 	var v1, v3 int32
  25037 	var v2, v4 uintptr
  25038 	_, _, _, _ = v1, v2, v3, v4
  25039 	v2 = it
  25040 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  25041 	v1 = *(*int32)(unsafe.Pointer(v2))
  25042 	if v1 == (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_w {
  25043 		v4 = it + 4
  25044 		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
  25045 		v3 = *(*int32)(unsafe.Pointer(v4))
  25046 		VP8IteratorSetRow(tls, it, v3)
  25047 	} else {
  25048 		**(**uintptr)(__ccgo_up(it + 64)) += uintptr(4)
  25049 		**(**uintptr)(__ccgo_up(it + 48)) += uintptr(1) * 4
  25050 		**(**uintptr)(__ccgo_up(it + 72)) += uintptr(1) * 4
  25051 		**(**uintptr)(__ccgo_up(it + 384)) += uintptr(16)
  25052 		**(**uintptr)(__ccgo_up(it + 392)) += uintptr(16)
  25053 	}
  25054 	v2 = it + 332
  25055 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  25056 	v1 = *(*int32)(unsafe.Pointer(v2))
  25057 	return libc.BoolInt32(0 < v1)
  25058 }
  25059 
  25060 //------------------------------------------------------------------------------
  25061 // Helper function to set mode properties
  25062 
  25063 func VP8SetIntra16Mode(tls *libc.TLS, it uintptr, mode int32) {
  25064 	var preds uintptr
  25065 	var y int32
  25066 	_, _ = preds, y
  25067 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25068 	y = 0
  25069 	for {
  25070 		if !(y < int32(4)) {
  25071 			break
  25072 		}
  25073 		libc.Xmemset(tls, preds, mode, uint64(4))
  25074 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25075 		goto _1
  25076 	_1:
  25077 		;
  25078 		y = y + 1
  25079 	}
  25080 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(1), 0, 0x3)
  25081 }
  25082 
  25083 func VP8SetIntra4Mode(tls *libc.TLS, it uintptr, modes uintptr) {
  25084 	var preds uintptr
  25085 	var y int32
  25086 	_, _ = preds, y
  25087 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25088 	y = int32(4)
  25089 	for {
  25090 		if !(y > 0) {
  25091 			break
  25092 		}
  25093 		libc.Xmemcpy(tls, preds, modes, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
  25094 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25095 		modes = modes + uintptr(4)
  25096 		goto _1
  25097 	_1:
  25098 		;
  25099 		y = y - 1
  25100 	}
  25101 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(0), 0, 0x3)
  25102 }
  25103 
  25104 func VP8SetIntraUVMode(tls *libc.TLS, it uintptr, mode int32) {
  25105 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(mode), 2, 0xc)
  25106 }
  25107 
  25108 func VP8SetSkip(tls *libc.TLS, it uintptr, skip int32) {
  25109 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(skip), 4, 0x10)
  25110 }
  25111 
  25112 func VP8SetSegment(tls *libc.TLS, it uintptr, segment int32) {
  25113 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(segment), 5, 0x60)
  25114 }
  25115 
  25116 //------------------------------------------------------------------------------
  25117 // Intra4x4 sub-blocks iteration
  25118 //
  25119 //  We store and update the boundary samples into an array of 37 pixels. They
  25120 //  are updated as we iterate and reconstructs each intra4x4 blocks in turn.
  25121 //  The position of the samples has the following snake pattern:
  25122 //
  25123 // 16|17 18 19 20|21 22 23 24|25 26 27 28|29 30 31 32|33 34 35 36  <- Top-right
  25124 // --+-----------+-----------+-----------+-----------+
  25125 // 15|         19|         23|         27|         31|
  25126 // 14|         18|         22|         26|         30|
  25127 // 13|         17|         21|         25|         29|
  25128 // 12|13 14 15 16|17 18 19 20|21 22 23 24|25 26 27 28|
  25129 // --+-----------+-----------+-----------+-----------+
  25130 // 11|         15|         19|         23|         27|
  25131 // 10|         14|         18|         22|         26|
  25132 //  9|         13|         17|         21|         25|
  25133 //  8| 9 10 11 12|13 14 15 16|17 18 19 20|21 22 23 24|
  25134 // --+-----------+-----------+-----------+-----------+
  25135 //  7|         11|         15|         19|         23|
  25136 //  6|         10|         14|         18|         22|
  25137 //  5|          9|         13|         17|         21|
  25138 //  4| 5  6  7  8| 9 10 11 12|13 14 15 16|17 18 19 20|
  25139 // --+-----------+-----------+-----------+-----------+
  25140 //  3|          7|         11|         15|         19|
  25141 //  2|          6|         10|         14|         18|
  25142 //  1|          5|          9|         13|         17|
  25143 //  0| 1  2  3  4| 5  6  7  8| 9 10 11 12|13 14 15 16|
  25144 // --+-----------+-----------+-----------+-----------+
  25145 
  25146 // C documentation
  25147 //
  25148 //	// Array to record the position of the top sample to pass to the prediction
  25149 //	// functions in dsp.c.
  25150 var VP8TopLeftI4 = [16]uint8_t{
  25151 	0:  uint8(17),
  25152 	1:  uint8(21),
  25153 	2:  uint8(25),
  25154 	3:  uint8(29),
  25155 	4:  uint8(13),
  25156 	5:  uint8(17),
  25157 	6:  uint8(21),
  25158 	7:  uint8(25),
  25159 	8:  uint8(9),
  25160 	9:  uint8(13),
  25161 	10: uint8(17),
  25162 	11: uint8(21),
  25163 	12: uint8(5),
  25164 	13: uint8(9),
  25165 	14: uint8(13),
  25166 	15: uint8(17),
  25167 }
  25168 
  25169 func VP8IteratorStartI4(tls *libc.TLS, it uintptr) {
  25170 	var enc uintptr
  25171 	var i int32
  25172 	_, _ = enc, i
  25173 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25174 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = 0 // first 4x4 sub-block
  25175 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[0])
  25176 	// Import the boundary samples
  25177 	i = 0
  25178 	for {
  25179 		if !(i < int32(17)) {
  25180 			break
  25181 		} // left
  25182 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(int32(15)-i)))
  25183 		goto _1
  25184 	_1:
  25185 		;
  25186 		i = i + 1
  25187 	}
  25188 	i = 0
  25189 	for {
  25190 		if !(i < int32(16)) {
  25191 			break
  25192 		} // top
  25193 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25194 		goto _2
  25195 	_2:
  25196 		;
  25197 		i = i + 1
  25198 	}
  25199 	// top-right samples have a special case on the far right of the picture
  25200 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25201 		i = int32(16)
  25202 		for {
  25203 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25204 				break
  25205 			}
  25206 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25207 			goto _3
  25208 		_3:
  25209 			;
  25210 			i = i + 1
  25211 		}
  25212 	} else { // else, replicate the last valid pixel four times
  25213 		i = int32(16)
  25214 		for {
  25215 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25216 				break
  25217 			}
  25218 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up(it + 80 + uintptr(libc.Int32FromInt32(17)+libc.Int32FromInt32(15))))
  25219 			goto _4
  25220 		_4:
  25221 			;
  25222 			i = i + 1
  25223 		}
  25224 	}
  25225 	VP8IteratorNzToBytes(tls, it) // import the non-zero context
  25226 }
  25227 
  25228 func VP8IteratorRotateI4(tls *libc.TLS, it uintptr, yuv_out uintptr) (r int32) {
  25229 	var blk, top uintptr
  25230 	var i int32
  25231 	_, _, _ = blk, i, top
  25232 	blk = yuv_out + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25233 	top = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top
  25234 	// Update the cache with 7 fresh samples
  25235 	i = 0
  25236 	for {
  25237 		if !(i <= int32(3)) {
  25238 			break
  25239 		}
  25240 		**(**uint8_t)(__ccgo_up(top + uintptr(-int32(4)+i))) = **(**uint8_t)(__ccgo_up(blk + uintptr(i+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) // store future top samples
  25241 		goto _1
  25242 	_1:
  25243 		;
  25244 		i = i + 1
  25245 	}
  25246 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3) != int32(3) { // if not on the right sub-blocks #3, #7, #11, #15
  25247 		i = 0
  25248 		for {
  25249 			if !(i <= int32(2)) {
  25250 				break
  25251 			} // store future left samples
  25252 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(blk + uintptr(int32(3)+(int32(2)-i)*int32(BPS))))
  25253 			goto _2
  25254 		_2:
  25255 			;
  25256 			i = i + 1
  25257 		}
  25258 	} else { // else replicate top-right samples, as says the specs.
  25259 		i = 0
  25260 		for {
  25261 			if !(i <= int32(3)) {
  25262 				break
  25263 			}
  25264 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(top + uintptr(i+int32(4))))
  25265 			goto _3
  25266 		_3:
  25267 			;
  25268 			i = i + 1
  25269 		}
  25270 	}
  25271 	// move pointers to next sub-block
  25272 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 + 1
  25273 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 == int32(16) { // we're done
  25274 		return 0
  25275 	}
  25276 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25277 	return int32(1)
  25278 }
  25279 
  25280 const MAX_LIMIT_BITS = 5
  25281 const MIN_DIM_FOR_NEAR_LOSSLESS = 64
  25282 
  25283 //------------------------------------------------------------------------------
  25284 
  25285 // Copyright 2012 Google Inc. All Rights Reserved.
  25286 //
  25287 // Use of this source code is governed by a BSD-style license
  25288 // that can be found in the COPYING file in the root of the source
  25289 // tree. An additional intellectual property rights grant can be found
  25290 // in the file PATENTS. All contributing project authors may
  25291 // be found in the AUTHORS file in the root of the source tree.
  25292 // -----------------------------------------------------------------------------
  25293 //
  25294 // Misc. common utility functions
  25295 //
  25296 // Authors: Skal (pascal.massimino@gmail.com)
  25297 //          Urvang (urvang@google.com)
  25298 
  25299 // Copyright 2011 Google Inc. All Rights Reserved.
  25300 //
  25301 // Use of this source code is governed by a BSD-style license
  25302 // that can be found in the COPYING file in the root of the source
  25303 // tree. An additional intellectual property rights grant can be found
  25304 // in the file PATENTS. All contributing project authors may
  25305 // be found in the AUTHORS file in the root of the source tree.
  25306 // -----------------------------------------------------------------------------
  25307 //
  25308 //   WebP encoder: main interface
  25309 //
  25310 // Author: Skal (pascal.massimino@gmail.com)
  25311 
  25312 // C documentation
  25313 //
  25314 //	// Quantizes the value up or down to a multiple of 1<<bits (or to 255),
  25315 //	// choosing the closer one, resolving ties using bankers' rounding.
  25316 func FindClosestDiscretized(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25317 	var biased, mask uint32_t
  25318 	_, _ = biased, mask
  25319 	mask = uint32(1)<<bits - uint32(1)
  25320 	biased = a + mask>>libc.Int32FromInt32(1) + a>>bits&uint32(1)
  25321 	if biased > uint32(0xff) {
  25322 		return uint32(0xff)
  25323 	}
  25324 	return biased & ^mask
  25325 }
  25326 
  25327 // C documentation
  25328 //
  25329 //	// Applies FindClosestDiscretized to all channels of pixel.
  25330 func ClosestDiscretizedArgb(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25331 	return FindClosestDiscretized(tls, a>>int32(24), bits)<<libc.Int32FromInt32(24) | FindClosestDiscretized(tls, a>>libc.Int32FromInt32(16)&uint32(0xff), bits)<<libc.Int32FromInt32(16) | FindClosestDiscretized(tls, a>>libc.Int32FromInt32(8)&uint32(0xff), bits)<<libc.Int32FromInt32(8) | FindClosestDiscretized(tls, a&uint32(0xff), bits)
  25332 }
  25333 
  25334 // C documentation
  25335 //
  25336 //	// Checks if distance between corresponding channel values of pixels a and b
  25337 //	// is within the given limit.
  25338 func IsNear(tls *libc.TLS, a uint32_t, b uint32_t, limit int32) (r int32) {
  25339 	var delta, k int32
  25340 	_, _ = delta, k
  25341 	k = 0
  25342 	for {
  25343 		if !(k < int32(4)) {
  25344 			break
  25345 		}
  25346 		delta = libc.Int32FromUint32(a>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff)) - libc.Int32FromUint32(b>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff))
  25347 		if delta >= limit || delta <= -limit {
  25348 			return 0
  25349 		}
  25350 		goto _1
  25351 	_1:
  25352 		;
  25353 		k = k + 1
  25354 	}
  25355 	return int32(1)
  25356 }
  25357 
  25358 func IsSmooth(tls *libc.TLS, prev_row uintptr, curr_row uintptr, next_row uintptr, ix int32, limit int32) (r int32) {
  25359 	// Check that all pixels in 4-connected neighborhood are smooth.
  25360 	return libc.BoolInt32(IsNear(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(ix)*4)), **(**uint32_t)(__ccgo_up(curr_row + uintptr(ix-int32(1))*4)), limit) != 0 && IsNear(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(ix)*4)), **(**uint32_t)(__ccgo_up(curr_row + uintptr(ix+int32(1))*4)), limit) != 0 && IsNear(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(ix)*4)), **(**uint32_t)(__ccgo_up(prev_row + uintptr(ix)*4)), limit) != 0 && IsNear(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(ix)*4)), **(**uint32_t)(__ccgo_up(next_row + uintptr(ix)*4)), limit) != 0)
  25361 }
  25362 
  25363 // C documentation
  25364 //
  25365 //	// Adjusts pixel values of image with given maximum error.
  25366 func NearLossless(tls *libc.TLS, xsize int32, ysize int32, argb_src uintptr, stride int32, limit_bits int32, copy_buffer uintptr, argb_dst uintptr) {
  25367 	var curr_row, next_row, prev_row, temp uintptr
  25368 	var limit, x, y int32
  25369 	_, _, _, _, _, _, _ = curr_row, limit, next_row, prev_row, temp, x, y
  25370 	limit = int32(1) << limit_bits
  25371 	prev_row = copy_buffer
  25372 	curr_row = prev_row + uintptr(xsize)*4
  25373 	next_row = curr_row + uintptr(xsize)*4
  25374 	libc.Xmemcpy(tls, curr_row, argb_src, libc.Uint64FromInt32(xsize)*uint64(4))
  25375 	libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, libc.Uint64FromInt32(xsize)*uint64(4))
  25376 	y = 0
  25377 	for {
  25378 		if !(y < ysize) {
  25379 			break
  25380 		}
  25381 		if y == 0 || y == ysize-int32(1) {
  25382 			libc.Xmemcpy(tls, argb_dst, argb_src, libc.Uint64FromInt32(xsize)*uint64(4))
  25383 		} else {
  25384 			libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, libc.Uint64FromInt32(xsize)*uint64(4))
  25385 			**(**uint32_t)(__ccgo_up(argb_dst)) = **(**uint32_t)(__ccgo_up(argb_src))
  25386 			**(**uint32_t)(__ccgo_up(argb_dst + uintptr(xsize-int32(1))*4)) = **(**uint32_t)(__ccgo_up(argb_src + uintptr(xsize-int32(1))*4))
  25387 			x = int32(1)
  25388 			for {
  25389 				if !(x < xsize-int32(1)) {
  25390 					break
  25391 				}
  25392 				if IsSmooth(tls, prev_row, curr_row, next_row, x, limit) != 0 {
  25393 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  25394 				} else {
  25395 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = ClosestDiscretizedArgb(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4)), limit_bits)
  25396 				}
  25397 				goto _2
  25398 			_2:
  25399 				;
  25400 				x = x + 1
  25401 			}
  25402 		}
  25403 		// Three-way swap.
  25404 		temp = prev_row
  25405 		prev_row = curr_row
  25406 		curr_row = next_row
  25407 		next_row = temp
  25408 		goto _1
  25409 	_1:
  25410 		;
  25411 		y = y + 1
  25412 		argb_src = argb_src + uintptr(stride)*4
  25413 		argb_dst = argb_dst + uintptr(xsize)*4
  25414 	}
  25415 }
  25416 
  25417 func VP8ApplyNearLossless(tls *libc.TLS, picture uintptr, quality int32, argb_dst uintptr) (r int32) {
  25418 	var copy_buffer uintptr
  25419 	var i, limit_bits, stride, xsize, ysize, v1 int32
  25420 	_, _, _, _, _, _, _ = copy_buffer, i, limit_bits, stride, xsize, ysize, v1
  25421 	xsize = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  25422 	ysize = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  25423 	stride = (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  25424 	copy_buffer = WebPSafeMalloc(tls, libc.Uint64FromInt32(xsize*int32(3)), uint64(4))
  25425 	v1 = int32(5) - quality/int32(20)
  25426 	goto _2
  25427 _2:
  25428 	limit_bits = v1
  25429 	if copy_buffer == libc.UintptrFromInt32(0) {
  25430 		return 0
  25431 	}
  25432 	// For small icon images, don't attempt to apply near-lossless compression.
  25433 	if xsize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) && ysize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) || ysize < int32(3) {
  25434 		i = 0
  25435 		for {
  25436 			if !(i < ysize) {
  25437 				break
  25438 			}
  25439 			libc.Xmemcpy(tls, argb_dst+uintptr(i*xsize)*4, (*WebPPicture)(unsafe.Pointer(picture)).Fargb+uintptr(i*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4, libc.Uint64FromInt32(xsize)*uint64(4))
  25440 			goto _3
  25441 		_3:
  25442 			;
  25443 			i = i + 1
  25444 		}
  25445 		WebPSafeFree(tls, copy_buffer)
  25446 		return int32(1)
  25447 	}
  25448 	NearLossless(tls, xsize, ysize, (*WebPPicture)(unsafe.Pointer(picture)).Fargb, stride, limit_bits, copy_buffer, argb_dst)
  25449 	i = limit_bits - int32(1)
  25450 	for {
  25451 		if !(i != 0) {
  25452 			break
  25453 		}
  25454 		NearLossless(tls, xsize, ysize, argb_dst, xsize, i, copy_buffer, argb_dst)
  25455 		goto _4
  25456 	_4:
  25457 		;
  25458 		i = i - 1
  25459 	}
  25460 	WebPSafeFree(tls, copy_buffer)
  25461 	return int32(1)
  25462 }
  25463 
  25464 const GAMMA_FIX = 12
  25465 const GAMMA_TAB_FIX = 7
  25466 const SHARPYUV_INLINE = "inline"
  25467 const SHARPYUV_VERSION_MAJOR = 0
  25468 const SHARPYUV_VERSION_MINOR = 4
  25469 const SHARPYUV_VERSION_PATCH = 2
  25470 
  25471 type SharpYuvConversionMatrix = struct {
  25472 	Frgb_to_y [4]int32
  25473 	Frgb_to_u [4]int32
  25474 	Frgb_to_v [4]int32
  25475 }
  25476 
  25477 type SharpYuvOptions = struct {
  25478 	Fyuv_matrix    uintptr
  25479 	Ftransfer_type SharpYuvTransferFunctionType1
  25480 }
  25481 
  25482 type SharpYuvTransferFunctionType = int32
  25483 
  25484 const kSharpYuvTransferFunctionBt709 = 1
  25485 const kSharpYuvTransferFunctionBt470M = 4
  25486 const kSharpYuvTransferFunctionBt470Bg = 5
  25487 const kSharpYuvTransferFunctionBt601 = 6
  25488 const kSharpYuvTransferFunctionSmpte240 = 7
  25489 const kSharpYuvTransferFunctionLinear = 8
  25490 const kSharpYuvTransferFunctionLog100 = 9
  25491 const kSharpYuvTransferFunctionLog100_Sqrt10 = 10
  25492 const kSharpYuvTransferFunctionIec61966 = 11
  25493 const kSharpYuvTransferFunctionBt1361 = 12
  25494 const kSharpYuvTransferFunctionSrgb = 13
  25495 const kSharpYuvTransferFunctionBt2020_10Bit = 14
  25496 const kSharpYuvTransferFunctionBt2020_12Bit = 15
  25497 const kSharpYuvTransferFunctionSmpte2084 = 16
  25498 const kSharpYuvTransferFunctionSmpte428 = 17
  25499 const kSharpYuvTransferFunctionHlg = 18
  25500 const kSharpYuvTransferFunctionNum = 19
  25501 
  25502 type SharpYuvTransferFunctionType1 = int32
  25503 
  25504 type SharpYuvRange = int32
  25505 
  25506 const kSharpYuvRangeFull = 0
  25507 const kSharpYuvRangeLimited = 1
  25508 
  25509 type SharpYuvColorSpace = struct {
  25510 	Fkr        float32
  25511 	Fkb        float32
  25512 	Fbit_depth int32
  25513 	Frange1    SharpYuvRange
  25514 }
  25515 
  25516 type SharpYuvMatrixType = int32
  25517 
  25518 const kSharpYuvMatrixWebp = 0
  25519 const kSharpYuvMatrixRec601Limited = 1
  25520 const kSharpYuvMatrixRec601Full = 2
  25521 const kSharpYuvMatrixRec709Limited = 3
  25522 const kSharpYuvMatrixRec709Full = 4
  25523 const kSharpYuvMatrixNum = 5
  25524 
  25525 // Copyright 2012 Google Inc. All Rights Reserved.
  25526 //
  25527 // Use of this source code is governed by a BSD-style license
  25528 // that can be found in the COPYING file in the root of the source
  25529 // tree. An additional intellectual property rights grant can be found
  25530 // in the file PATENTS. All contributing project authors may
  25531 // be found in the AUTHORS file in the root of the source tree.
  25532 // -----------------------------------------------------------------------------
  25533 //
  25534 // Misc. common utility functions
  25535 //
  25536 // Authors: Skal (pascal.massimino@gmail.com)
  25537 //          Urvang (urvang@google.com)
  25538 
  25539 // Copyright 2011 Google Inc. All Rights Reserved.
  25540 //
  25541 // Use of this source code is governed by a BSD-style license
  25542 // that can be found in the COPYING file in the root of the source
  25543 // tree. An additional intellectual property rights grant can be found
  25544 // in the file PATENTS. All contributing project authors may
  25545 // be found in the AUTHORS file in the root of the source tree.
  25546 // -----------------------------------------------------------------------------
  25547 //
  25548 //   WebP encoder: main interface
  25549 //
  25550 // Author: Skal (pascal.massimino@gmail.com)
  25551 
  25552 // Copyright 2010 Google Inc. All Rights Reserved.
  25553 //
  25554 // Use of this source code is governed by a BSD-style license
  25555 // that can be found in the COPYING file in the root of the source
  25556 // tree. An additional intellectual property rights grant can be found
  25557 // in the file PATENTS. All contributing project authors may
  25558 // be found in the AUTHORS file in the root of the source tree.
  25559 // -----------------------------------------------------------------------------
  25560 //
  25561 //  Common types + memory wrappers
  25562 //
  25563 // Author: Skal (pascal.massimino@gmail.com)
  25564 
  25565 // Uncomment to disable gamma-compression during RGB->U/V averaging
  25566 
  25567 // If defined, use table to compute x / alpha.
  25568 
  25569 // uint32_t 0xff000000 is 0x00,00,00,ff in memory
  25570 
  25571 //------------------------------------------------------------------------------
  25572 // Detection of non-trivial transparency
  25573 
  25574 // C documentation
  25575 //
  25576 //	// Returns true if alpha[] has non-0xff values.
  25577 func CheckNonOpaque(tls *libc.TLS, alpha uintptr, width int32, height int32, x_step int32, y_step int32) (r int32) {
  25578 	var v2 int32
  25579 	_ = v2
  25580 	if alpha == libc.UintptrFromInt32(0) {
  25581 		return 0
  25582 	}
  25583 	WebPInitAlphaProcessing(tls)
  25584 	if x_step == int32(1) {
  25585 		for {
  25586 			v2 = height
  25587 			height = height - 1
  25588 			if !(v2 > 0) {
  25589 				break
  25590 			}
  25591 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha8b})))(tls, alpha, width) != 0 {
  25592 				return int32(1)
  25593 			}
  25594 			goto _1
  25595 		_1:
  25596 			;
  25597 			alpha = alpha + uintptr(y_step)
  25598 		}
  25599 	} else {
  25600 		for {
  25601 			v2 = height
  25602 			height = height - 1
  25603 			if !(v2 > 0) {
  25604 				break
  25605 			}
  25606 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha32b})))(tls, alpha, width) != 0 {
  25607 				return int32(1)
  25608 			}
  25609 			goto _3
  25610 		_3:
  25611 			;
  25612 			alpha = alpha + uintptr(y_step)
  25613 		}
  25614 	}
  25615 	return 0
  25616 }
  25617 
  25618 // C documentation
  25619 //
  25620 //	// Checking for the presence of non-opaque alpha.
  25621 func WebPPictureHasTransparency(tls *libc.TLS, picture uintptr) (r int32) {
  25622 	if picture == libc.UintptrFromInt32(0) {
  25623 		return 0
  25624 	}
  25625 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  25626 		if (*WebPPicture)(unsafe.Pointer(picture)).Fargb != libc.UintptrFromInt32(0) {
  25627 			return CheckNonOpaque(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fargb+uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(0)), (*WebPPicture)(unsafe.Pointer(picture)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture)).Fheight, int32(4), libc.Int32FromUint64(libc.Uint64FromInt32((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*uint64(4)))
  25628 		}
  25629 		return 0
  25630 	}
  25631 	return CheckNonOpaque(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fa, (*WebPPicture)(unsafe.Pointer(picture)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture)).Fheight, int32(1), (*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  25632 }
  25633 
  25634 //------------------------------------------------------------------------------
  25635 // Code for gamma correction
  25636 
  25637 // C documentation
  25638 //
  25639 //	// Gamma correction compensates loss of resolution during chroma subsampling.
  25640 var kGamma = float64(0.8)
  25641 var kGammaScale = libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_FIX) - libc.Int32FromInt32(1)
  25642 var kGammaTabScale = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX)
  25643 var kGammaTabRounder = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX) >> libc.Int32FromInt32(1)
  25644 
  25645 var kLinearToGammaTab [33]int32
  25646 var kGammaToLinearTab [256]uint16_t
  25647 var kGammaTablesOk = int32(0)
  25648 
  25649 func InitGammaTables(tls *libc.TLS) {
  25650 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  25651 		goto _1
  25652 	}
  25653 	InitGammaTables_body(tls)
  25654 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)), VP8GetCPUInfo)
  25655 	goto _2
  25656 _2:
  25657 	;
  25658 	goto _1
  25659 _1: /**/ //
  25660 }
  25661 
  25662 var InitGammaTables_body_last_cpuinfo_used = uintptr(0)
  25663 
  25664 func init() {
  25665 	p := unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)
  25666 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))
  25667 }
  25668 
  25669 func InitGammaTables_body(tls *libc.TLS) {
  25670 	var norm, scale float64
  25671 	var v int32
  25672 	_, _, _ = norm, scale, v
  25673 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&kGammaTablesOk))) != 0) {
  25674 		scale = float64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_TAB_FIX)) / float64(kGammaScale)
  25675 		norm = libc.Float64FromFloat64(1) / libc.Float64FromFloat64(255)
  25676 		v = 0
  25677 		for {
  25678 			if !(v <= int32(255)) {
  25679 				break
  25680 			}
  25681 			kGammaToLinearTab[v] = uint16(float64(libc.Xpow(tls, float64(norm*float64(v)), kGamma)*float64(kGammaScale)) + libc.Float64FromFloat64(0.5))
  25682 			goto _1
  25683 		_1:
  25684 			;
  25685 			v = v + 1
  25686 		}
  25687 		v = 0
  25688 		for {
  25689 			if !(v <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(GAMMA_FIX)-libc.Int32FromInt32(GAMMA_TAB_FIX))) {
  25690 				break
  25691 			}
  25692 			kLinearToGammaTab[v] = int32(float64(libc.Float64FromFloat64(255)*libc.Xpow(tls, float64(scale*float64(v)), float64(1)/kGamma)) + libc.Float64FromFloat64(0.5))
  25693 			goto _2
  25694 		_2:
  25695 			;
  25696 			v = v + 1
  25697 		}
  25698 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&kGammaTablesOk)), int32(1))
  25699 	}
  25700 }
  25701 
  25702 func GammaToLinear(tls *libc.TLS, v uint8_t) (r uint32_t) {
  25703 	return uint32(kGammaToLinearTab[v])
  25704 }
  25705 
  25706 func Interpolate(tls *libc.TLS, v int32) (r int32) {
  25707 	var tab_pos, v0, v1, x, y int32
  25708 	_, _, _, _, _ = tab_pos, v0, v1, x, y
  25709 	tab_pos = v >> (libc.Int32FromInt32(GAMMA_TAB_FIX) + libc.Int32FromInt32(2)) // integer part
  25710 	x = v & (kGammaTabScale<<libc.Int32FromInt32(2) - int32(1))                  // fractional part
  25711 	v0 = kLinearToGammaTab[tab_pos]
  25712 	v1 = kLinearToGammaTab[tab_pos+int32(1)]
  25713 	y = v1*x + v0*(kGammaTabScale<<libc.Int32FromInt32(2)-x) // interpolate
  25714 	return y
  25715 }
  25716 
  25717 // C documentation
  25718 //
  25719 //	// Convert a linear value 'v' to YUV_FIX+2 fixed-point precision
  25720 //	// U/V value, suitable for RGBToU/V calls.
  25721 func LinearToGamma(tls *libc.TLS, base_value uint32_t, shift int32) (r int32) {
  25722 	var y int32
  25723 	_ = y
  25724 	y = Interpolate(tls, libc.Int32FromUint32(base_value<<shift)) // final uplifted value
  25725 	return (y + kGammaTabRounder) >> int32(GAMMA_TAB_FIX)         // descale
  25726 }
  25727 
  25728 //------------------------------------------------------------------------------
  25729 // RGB -> YUV conversion
  25730 
  25731 func RGBToY(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  25732 	var diff, luma, v1, v11, v13, v15, v2, v5, v8, v9 int32
  25733 	var v10, v12, v4, v7 uintptr
  25734 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, luma, v1, v10, v11, v12, v13, v15, v2, v4, v5, v7, v8, v9
  25735 	if rg2 == libc.UintptrFromInt32(0) {
  25736 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  25737 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  25738 		goto _3
  25739 	_3:
  25740 		v1 = v2
  25741 	} else {
  25742 		v4 = rg2
  25743 		v7 = v4
  25744 		v8 = int32(YUV_FIX)
  25745 		diff = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(v7 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v7)).Findex1)*4)) - **(**uint32_t)(__ccgo_up(v7 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v7)).Findex2)*4)))
  25746 		if diff < libc.Int32FromInt32(0) {
  25747 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  25748 		}
  25749 		**(**uint32_t)(__ccgo_up(v7 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v7)).Findex1)*4)) = libc.Uint32FromInt32(diff)
  25750 		v10 = v7
  25751 		*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
  25752 		v9 = *(*int32)(unsafe.Pointer(v10))
  25753 		if v9 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  25754 			(*VP8Random)(unsafe.Pointer(v7)).Findex1 = 0
  25755 		}
  25756 		v12 = v7 + 4
  25757 		*(*int32)(unsafe.Pointer(v12)) = *(*int32)(unsafe.Pointer(v12)) + 1
  25758 		v11 = *(*int32)(unsafe.Pointer(v12))
  25759 		if v11 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  25760 			(*VP8Random)(unsafe.Pointer(v7)).Findex2 = 0
  25761 		}
  25762 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v8)
  25763 		diff = diff * (*VP8Random)(unsafe.Pointer(v4)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  25764 		diff = diff + int32(1)<<(v8-int32(1))
  25765 		v13 = diff
  25766 		goto _14
  25767 	_14:
  25768 		v5 = v13
  25769 		goto _6
  25770 	_6:
  25771 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  25772 		v15 = (luma + v5 + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  25773 		goto _16
  25774 	_16:
  25775 		v1 = v15
  25776 	}
  25777 	return v1
  25778 }
  25779 
  25780 func RGBToU(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  25781 	var diff, u, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  25782 	var v12, v15, v17, v9 uintptr
  25783 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, u, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  25784 	if rg2 == libc.UintptrFromInt32(0) {
  25785 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  25786 		v4 = u
  25787 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  25788 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  25789 			v7 = v4
  25790 		} else {
  25791 			if v4 < 0 {
  25792 				v8 = 0
  25793 			} else {
  25794 				v8 = int32(255)
  25795 			}
  25796 			v7 = v8
  25797 		}
  25798 		v5 = v7
  25799 		goto _6
  25800 	_6:
  25801 		v2 = v5
  25802 		goto _3
  25803 	_3:
  25804 		v1 = v2
  25805 	} else {
  25806 		v9 = rg2
  25807 		v12 = v9
  25808 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  25809 		diff = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) - **(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex2)*4)))
  25810 		if diff < libc.Int32FromInt32(0) {
  25811 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  25812 		}
  25813 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = libc.Uint32FromInt32(diff)
  25814 		v15 = v12
  25815 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  25816 		v14 = *(*int32)(unsafe.Pointer(v15))
  25817 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  25818 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  25819 		}
  25820 		v17 = v12 + 4
  25821 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  25822 		v16 = *(*int32)(unsafe.Pointer(v17))
  25823 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  25824 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  25825 		}
  25826 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  25827 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  25828 		diff = diff + int32(1)<<(v13-int32(1))
  25829 		v18 = diff
  25830 		goto _19
  25831 	_19:
  25832 		v10 = v18
  25833 		goto _11
  25834 	_11:
  25835 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  25836 		v22 = u
  25837 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  25838 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  25839 			v25 = v22
  25840 		} else {
  25841 			if v22 < 0 {
  25842 				v26 = 0
  25843 			} else {
  25844 				v26 = int32(255)
  25845 			}
  25846 			v25 = v26
  25847 		}
  25848 		v23 = v25
  25849 		goto _24
  25850 	_24:
  25851 		v20 = v23
  25852 		goto _21
  25853 	_21:
  25854 		v1 = v20
  25855 	}
  25856 	return v1
  25857 }
  25858 
  25859 func RGBToV(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  25860 	var diff, v, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  25861 	var v12, v15, v17, v9 uintptr
  25862 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, v, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  25863 	if rg2 == libc.UintptrFromInt32(0) {
  25864 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  25865 		v4 = v
  25866 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  25867 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  25868 			v7 = v4
  25869 		} else {
  25870 			if v4 < 0 {
  25871 				v8 = 0
  25872 			} else {
  25873 				v8 = int32(255)
  25874 			}
  25875 			v7 = v8
  25876 		}
  25877 		v5 = v7
  25878 		goto _6
  25879 	_6:
  25880 		v2 = v5
  25881 		goto _3
  25882 	_3:
  25883 		v1 = v2
  25884 	} else {
  25885 		v9 = rg2
  25886 		v12 = v9
  25887 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  25888 		diff = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) - **(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex2)*4)))
  25889 		if diff < libc.Int32FromInt32(0) {
  25890 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  25891 		}
  25892 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = libc.Uint32FromInt32(diff)
  25893 		v15 = v12
  25894 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  25895 		v14 = *(*int32)(unsafe.Pointer(v15))
  25896 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  25897 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  25898 		}
  25899 		v17 = v12 + 4
  25900 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  25901 		v16 = *(*int32)(unsafe.Pointer(v17))
  25902 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  25903 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  25904 		}
  25905 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  25906 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  25907 		diff = diff + int32(1)<<(v13-int32(1))
  25908 		v18 = diff
  25909 		goto _19
  25910 	_19:
  25911 		v10 = v18
  25912 		goto _11
  25913 	_11:
  25914 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  25915 		v22 = v
  25916 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  25917 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  25918 			v25 = v22
  25919 		} else {
  25920 			if v22 < 0 {
  25921 				v26 = 0
  25922 			} else {
  25923 				v26 = int32(255)
  25924 			}
  25925 			v25 = v26
  25926 		}
  25927 		v23 = v25
  25928 		goto _24
  25929 	_24:
  25930 		v20 = v23
  25931 		goto _21
  25932 	_21:
  25933 		v1 = v20
  25934 	}
  25935 	return v1
  25936 }
  25937 
  25938 //------------------------------------------------------------------------------
  25939 // Sharp RGB->YUV conversion
  25940 
  25941 var kMinDimensionIterativeConversion = int32(4)
  25942 
  25943 //------------------------------------------------------------------------------
  25944 // Main function
  25945 
  25946 func PreprocessARGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, picture uintptr) (r int32) {
  25947 	var ok int32
  25948 	_ = ok
  25949 	ok = SharpYuvConvert(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, int32(8), (*WebPPicture)(unsafe.Pointer(picture)).Fy, (*WebPPicture)(unsafe.Pointer(picture)).Fy_stride, (*WebPPicture)(unsafe.Pointer(picture)).Fu, (*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride, (*WebPPicture)(unsafe.Pointer(picture)).Fv, (*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride, int32(8), (*WebPPicture)(unsafe.Pointer(picture)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture)).Fheight, SharpYuvGetConversionMatrix(tls, int32(kSharpYuvMatrixWebp)))
  25950 	if !(ok != 0) {
  25951 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  25952 	}
  25953 	return ok
  25954 }
  25955 
  25956 //------------------------------------------------------------------------------
  25957 // "Fast" regular RGB->YUV
  25958 
  25959 var kAlphaFix = int32(19)
  25960 
  25961 // C documentation
  25962 //
  25963 //	// Following table is (1 << kAlphaFix) / a. The (v * kInvAlpha[a]) >> kAlphaFix
  25964 //	// formula is then equal to v / a in most (99.6%) cases. Note that this table
  25965 //	// and constant are adjusted very tightly to fit 32b arithmetic.
  25966 //	// In particular, they use the fact that the operands for 'v / a' are actually
  25967 //	// derived as v = (a0.p0 + a1.p1 + a2.p2 + a3.p3) and a = a0 + a1 + a2 + a3
  25968 //	// with ai in [0..255] and pi in [0..1<<GAMMA_FIX). The constraint to avoid
  25969 //	// overflow is: GAMMA_FIX + kAlphaFix <= 31.
  25970 var kInvAlpha = [1021]uint32_t{
  25971 	1:    uint32(524288),
  25972 	2:    uint32(262144),
  25973 	3:    uint32(174762),
  25974 	4:    uint32(131072),
  25975 	5:    uint32(104857),
  25976 	6:    uint32(87381),
  25977 	7:    uint32(74898),
  25978 	8:    uint32(65536),
  25979 	9:    uint32(58254),
  25980 	10:   uint32(52428),
  25981 	11:   uint32(47662),
  25982 	12:   uint32(43690),
  25983 	13:   uint32(40329),
  25984 	14:   uint32(37449),
  25985 	15:   uint32(34952),
  25986 	16:   uint32(32768),
  25987 	17:   uint32(30840),
  25988 	18:   uint32(29127),
  25989 	19:   uint32(27594),
  25990 	20:   uint32(26214),
  25991 	21:   uint32(24966),
  25992 	22:   uint32(23831),
  25993 	23:   uint32(22795),
  25994 	24:   uint32(21845),
  25995 	25:   uint32(20971),
  25996 	26:   uint32(20164),
  25997 	27:   uint32(19418),
  25998 	28:   uint32(18724),
  25999 	29:   uint32(18078),
  26000 	30:   uint32(17476),
  26001 	31:   uint32(16912),
  26002 	32:   uint32(16384),
  26003 	33:   uint32(15887),
  26004 	34:   uint32(15420),
  26005 	35:   uint32(14979),
  26006 	36:   uint32(14563),
  26007 	37:   uint32(14169),
  26008 	38:   uint32(13797),
  26009 	39:   uint32(13443),
  26010 	40:   uint32(13107),
  26011 	41:   uint32(12787),
  26012 	42:   uint32(12483),
  26013 	43:   uint32(12192),
  26014 	44:   uint32(11915),
  26015 	45:   uint32(11650),
  26016 	46:   uint32(11397),
  26017 	47:   uint32(11155),
  26018 	48:   uint32(10922),
  26019 	49:   uint32(10699),
  26020 	50:   uint32(10485),
  26021 	51:   uint32(10280),
  26022 	52:   uint32(10082),
  26023 	53:   uint32(9892),
  26024 	54:   uint32(9709),
  26025 	55:   uint32(9532),
  26026 	56:   uint32(9362),
  26027 	57:   uint32(9198),
  26028 	58:   uint32(9039),
  26029 	59:   uint32(8886),
  26030 	60:   uint32(8738),
  26031 	61:   uint32(8594),
  26032 	62:   uint32(8456),
  26033 	63:   uint32(8322),
  26034 	64:   uint32(8192),
  26035 	65:   uint32(8065),
  26036 	66:   uint32(7943),
  26037 	67:   uint32(7825),
  26038 	68:   uint32(7710),
  26039 	69:   uint32(7598),
  26040 	70:   uint32(7489),
  26041 	71:   uint32(7384),
  26042 	72:   uint32(7281),
  26043 	73:   uint32(7182),
  26044 	74:   uint32(7084),
  26045 	75:   uint32(6990),
  26046 	76:   uint32(6898),
  26047 	77:   uint32(6808),
  26048 	78:   uint32(6721),
  26049 	79:   uint32(6636),
  26050 	80:   uint32(6553),
  26051 	81:   uint32(6472),
  26052 	82:   uint32(6393),
  26053 	83:   uint32(6316),
  26054 	84:   uint32(6241),
  26055 	85:   uint32(6168),
  26056 	86:   uint32(6096),
  26057 	87:   uint32(6026),
  26058 	88:   uint32(5957),
  26059 	89:   uint32(5890),
  26060 	90:   uint32(5825),
  26061 	91:   uint32(5761),
  26062 	92:   uint32(5698),
  26063 	93:   uint32(5637),
  26064 	94:   uint32(5577),
  26065 	95:   uint32(5518),
  26066 	96:   uint32(5461),
  26067 	97:   uint32(5405),
  26068 	98:   uint32(5349),
  26069 	99:   uint32(5295),
  26070 	100:  uint32(5242),
  26071 	101:  uint32(5190),
  26072 	102:  uint32(5140),
  26073 	103:  uint32(5090),
  26074 	104:  uint32(5041),
  26075 	105:  uint32(4993),
  26076 	106:  uint32(4946),
  26077 	107:  uint32(4899),
  26078 	108:  uint32(4854),
  26079 	109:  uint32(4809),
  26080 	110:  uint32(4766),
  26081 	111:  uint32(4723),
  26082 	112:  uint32(4681),
  26083 	113:  uint32(4639),
  26084 	114:  uint32(4599),
  26085 	115:  uint32(4559),
  26086 	116:  uint32(4519),
  26087 	117:  uint32(4481),
  26088 	118:  uint32(4443),
  26089 	119:  uint32(4405),
  26090 	120:  uint32(4369),
  26091 	121:  uint32(4332),
  26092 	122:  uint32(4297),
  26093 	123:  uint32(4262),
  26094 	124:  uint32(4228),
  26095 	125:  uint32(4194),
  26096 	126:  uint32(4161),
  26097 	127:  uint32(4128),
  26098 	128:  uint32(4096),
  26099 	129:  uint32(4064),
  26100 	130:  uint32(4032),
  26101 	131:  uint32(4002),
  26102 	132:  uint32(3971),
  26103 	133:  uint32(3942),
  26104 	134:  uint32(3912),
  26105 	135:  uint32(3883),
  26106 	136:  uint32(3855),
  26107 	137:  uint32(3826),
  26108 	138:  uint32(3799),
  26109 	139:  uint32(3771),
  26110 	140:  uint32(3744),
  26111 	141:  uint32(3718),
  26112 	142:  uint32(3692),
  26113 	143:  uint32(3666),
  26114 	144:  uint32(3640),
  26115 	145:  uint32(3615),
  26116 	146:  uint32(3591),
  26117 	147:  uint32(3566),
  26118 	148:  uint32(3542),
  26119 	149:  uint32(3518),
  26120 	150:  uint32(3495),
  26121 	151:  uint32(3472),
  26122 	152:  uint32(3449),
  26123 	153:  uint32(3426),
  26124 	154:  uint32(3404),
  26125 	155:  uint32(3382),
  26126 	156:  uint32(3360),
  26127 	157:  uint32(3339),
  26128 	158:  uint32(3318),
  26129 	159:  uint32(3297),
  26130 	160:  uint32(3276),
  26131 	161:  uint32(3256),
  26132 	162:  uint32(3236),
  26133 	163:  uint32(3216),
  26134 	164:  uint32(3196),
  26135 	165:  uint32(3177),
  26136 	166:  uint32(3158),
  26137 	167:  uint32(3139),
  26138 	168:  uint32(3120),
  26139 	169:  uint32(3102),
  26140 	170:  uint32(3084),
  26141 	171:  uint32(3066),
  26142 	172:  uint32(3048),
  26143 	173:  uint32(3030),
  26144 	174:  uint32(3013),
  26145 	175:  uint32(2995),
  26146 	176:  uint32(2978),
  26147 	177:  uint32(2962),
  26148 	178:  uint32(2945),
  26149 	179:  uint32(2928),
  26150 	180:  uint32(2912),
  26151 	181:  uint32(2896),
  26152 	182:  uint32(2880),
  26153 	183:  uint32(2864),
  26154 	184:  uint32(2849),
  26155 	185:  uint32(2833),
  26156 	186:  uint32(2818),
  26157 	187:  uint32(2803),
  26158 	188:  uint32(2788),
  26159 	189:  uint32(2774),
  26160 	190:  uint32(2759),
  26161 	191:  uint32(2744),
  26162 	192:  uint32(2730),
  26163 	193:  uint32(2716),
  26164 	194:  uint32(2702),
  26165 	195:  uint32(2688),
  26166 	196:  uint32(2674),
  26167 	197:  uint32(2661),
  26168 	198:  uint32(2647),
  26169 	199:  uint32(2634),
  26170 	200:  uint32(2621),
  26171 	201:  uint32(2608),
  26172 	202:  uint32(2595),
  26173 	203:  uint32(2582),
  26174 	204:  uint32(2570),
  26175 	205:  uint32(2557),
  26176 	206:  uint32(2545),
  26177 	207:  uint32(2532),
  26178 	208:  uint32(2520),
  26179 	209:  uint32(2508),
  26180 	210:  uint32(2496),
  26181 	211:  uint32(2484),
  26182 	212:  uint32(2473),
  26183 	213:  uint32(2461),
  26184 	214:  uint32(2449),
  26185 	215:  uint32(2438),
  26186 	216:  uint32(2427),
  26187 	217:  uint32(2416),
  26188 	218:  uint32(2404),
  26189 	219:  uint32(2394),
  26190 	220:  uint32(2383),
  26191 	221:  uint32(2372),
  26192 	222:  uint32(2361),
  26193 	223:  uint32(2351),
  26194 	224:  uint32(2340),
  26195 	225:  uint32(2330),
  26196 	226:  uint32(2319),
  26197 	227:  uint32(2309),
  26198 	228:  uint32(2299),
  26199 	229:  uint32(2289),
  26200 	230:  uint32(2279),
  26201 	231:  uint32(2269),
  26202 	232:  uint32(2259),
  26203 	233:  uint32(2250),
  26204 	234:  uint32(2240),
  26205 	235:  uint32(2231),
  26206 	236:  uint32(2221),
  26207 	237:  uint32(2212),
  26208 	238:  uint32(2202),
  26209 	239:  uint32(2193),
  26210 	240:  uint32(2184),
  26211 	241:  uint32(2175),
  26212 	242:  uint32(2166),
  26213 	243:  uint32(2157),
  26214 	244:  uint32(2148),
  26215 	245:  uint32(2139),
  26216 	246:  uint32(2131),
  26217 	247:  uint32(2122),
  26218 	248:  uint32(2114),
  26219 	249:  uint32(2105),
  26220 	250:  uint32(2097),
  26221 	251:  uint32(2088),
  26222 	252:  uint32(2080),
  26223 	253:  uint32(2072),
  26224 	254:  uint32(2064),
  26225 	255:  uint32(2056),
  26226 	256:  uint32(2048),
  26227 	257:  uint32(2040),
  26228 	258:  uint32(2032),
  26229 	259:  uint32(2024),
  26230 	260:  uint32(2016),
  26231 	261:  uint32(2008),
  26232 	262:  uint32(2001),
  26233 	263:  uint32(1993),
  26234 	264:  uint32(1985),
  26235 	265:  uint32(1978),
  26236 	266:  uint32(1971),
  26237 	267:  uint32(1963),
  26238 	268:  uint32(1956),
  26239 	269:  uint32(1949),
  26240 	270:  uint32(1941),
  26241 	271:  uint32(1934),
  26242 	272:  uint32(1927),
  26243 	273:  uint32(1920),
  26244 	274:  uint32(1913),
  26245 	275:  uint32(1906),
  26246 	276:  uint32(1899),
  26247 	277:  uint32(1892),
  26248 	278:  uint32(1885),
  26249 	279:  uint32(1879),
  26250 	280:  uint32(1872),
  26251 	281:  uint32(1865),
  26252 	282:  uint32(1859),
  26253 	283:  uint32(1852),
  26254 	284:  uint32(1846),
  26255 	285:  uint32(1839),
  26256 	286:  uint32(1833),
  26257 	287:  uint32(1826),
  26258 	288:  uint32(1820),
  26259 	289:  uint32(1814),
  26260 	290:  uint32(1807),
  26261 	291:  uint32(1801),
  26262 	292:  uint32(1795),
  26263 	293:  uint32(1789),
  26264 	294:  uint32(1783),
  26265 	295:  uint32(1777),
  26266 	296:  uint32(1771),
  26267 	297:  uint32(1765),
  26268 	298:  uint32(1759),
  26269 	299:  uint32(1753),
  26270 	300:  uint32(1747),
  26271 	301:  uint32(1741),
  26272 	302:  uint32(1736),
  26273 	303:  uint32(1730),
  26274 	304:  uint32(1724),
  26275 	305:  uint32(1718),
  26276 	306:  uint32(1713),
  26277 	307:  uint32(1707),
  26278 	308:  uint32(1702),
  26279 	309:  uint32(1696),
  26280 	310:  uint32(1691),
  26281 	311:  uint32(1685),
  26282 	312:  uint32(1680),
  26283 	313:  uint32(1675),
  26284 	314:  uint32(1669),
  26285 	315:  uint32(1664),
  26286 	316:  uint32(1659),
  26287 	317:  uint32(1653),
  26288 	318:  uint32(1648),
  26289 	319:  uint32(1643),
  26290 	320:  uint32(1638),
  26291 	321:  uint32(1633),
  26292 	322:  uint32(1628),
  26293 	323:  uint32(1623),
  26294 	324:  uint32(1618),
  26295 	325:  uint32(1613),
  26296 	326:  uint32(1608),
  26297 	327:  uint32(1603),
  26298 	328:  uint32(1598),
  26299 	329:  uint32(1593),
  26300 	330:  uint32(1588),
  26301 	331:  uint32(1583),
  26302 	332:  uint32(1579),
  26303 	333:  uint32(1574),
  26304 	334:  uint32(1569),
  26305 	335:  uint32(1565),
  26306 	336:  uint32(1560),
  26307 	337:  uint32(1555),
  26308 	338:  uint32(1551),
  26309 	339:  uint32(1546),
  26310 	340:  uint32(1542),
  26311 	341:  uint32(1537),
  26312 	342:  uint32(1533),
  26313 	343:  uint32(1528),
  26314 	344:  uint32(1524),
  26315 	345:  uint32(1519),
  26316 	346:  uint32(1515),
  26317 	347:  uint32(1510),
  26318 	348:  uint32(1506),
  26319 	349:  uint32(1502),
  26320 	350:  uint32(1497),
  26321 	351:  uint32(1493),
  26322 	352:  uint32(1489),
  26323 	353:  uint32(1485),
  26324 	354:  uint32(1481),
  26325 	355:  uint32(1476),
  26326 	356:  uint32(1472),
  26327 	357:  uint32(1468),
  26328 	358:  uint32(1464),
  26329 	359:  uint32(1460),
  26330 	360:  uint32(1456),
  26331 	361:  uint32(1452),
  26332 	362:  uint32(1448),
  26333 	363:  uint32(1444),
  26334 	364:  uint32(1440),
  26335 	365:  uint32(1436),
  26336 	366:  uint32(1432),
  26337 	367:  uint32(1428),
  26338 	368:  uint32(1424),
  26339 	369:  uint32(1420),
  26340 	370:  uint32(1416),
  26341 	371:  uint32(1413),
  26342 	372:  uint32(1409),
  26343 	373:  uint32(1405),
  26344 	374:  uint32(1401),
  26345 	375:  uint32(1398),
  26346 	376:  uint32(1394),
  26347 	377:  uint32(1390),
  26348 	378:  uint32(1387),
  26349 	379:  uint32(1383),
  26350 	380:  uint32(1379),
  26351 	381:  uint32(1376),
  26352 	382:  uint32(1372),
  26353 	383:  uint32(1368),
  26354 	384:  uint32(1365),
  26355 	385:  uint32(1361),
  26356 	386:  uint32(1358),
  26357 	387:  uint32(1354),
  26358 	388:  uint32(1351),
  26359 	389:  uint32(1347),
  26360 	390:  uint32(1344),
  26361 	391:  uint32(1340),
  26362 	392:  uint32(1337),
  26363 	393:  uint32(1334),
  26364 	394:  uint32(1330),
  26365 	395:  uint32(1327),
  26366 	396:  uint32(1323),
  26367 	397:  uint32(1320),
  26368 	398:  uint32(1317),
  26369 	399:  uint32(1314),
  26370 	400:  uint32(1310),
  26371 	401:  uint32(1307),
  26372 	402:  uint32(1304),
  26373 	403:  uint32(1300),
  26374 	404:  uint32(1297),
  26375 	405:  uint32(1294),
  26376 	406:  uint32(1291),
  26377 	407:  uint32(1288),
  26378 	408:  uint32(1285),
  26379 	409:  uint32(1281),
  26380 	410:  uint32(1278),
  26381 	411:  uint32(1275),
  26382 	412:  uint32(1272),
  26383 	413:  uint32(1269),
  26384 	414:  uint32(1266),
  26385 	415:  uint32(1263),
  26386 	416:  uint32(1260),
  26387 	417:  uint32(1257),
  26388 	418:  uint32(1254),
  26389 	419:  uint32(1251),
  26390 	420:  uint32(1248),
  26391 	421:  uint32(1245),
  26392 	422:  uint32(1242),
  26393 	423:  uint32(1239),
  26394 	424:  uint32(1236),
  26395 	425:  uint32(1233),
  26396 	426:  uint32(1230),
  26397 	427:  uint32(1227),
  26398 	428:  uint32(1224),
  26399 	429:  uint32(1222),
  26400 	430:  uint32(1219),
  26401 	431:  uint32(1216),
  26402 	432:  uint32(1213),
  26403 	433:  uint32(1210),
  26404 	434:  uint32(1208),
  26405 	435:  uint32(1205),
  26406 	436:  uint32(1202),
  26407 	437:  uint32(1199),
  26408 	438:  uint32(1197),
  26409 	439:  uint32(1194),
  26410 	440:  uint32(1191),
  26411 	441:  uint32(1188),
  26412 	442:  uint32(1186),
  26413 	443:  uint32(1183),
  26414 	444:  uint32(1180),
  26415 	445:  uint32(1178),
  26416 	446:  uint32(1175),
  26417 	447:  uint32(1172),
  26418 	448:  uint32(1170),
  26419 	449:  uint32(1167),
  26420 	450:  uint32(1165),
  26421 	451:  uint32(1162),
  26422 	452:  uint32(1159),
  26423 	453:  uint32(1157),
  26424 	454:  uint32(1154),
  26425 	455:  uint32(1152),
  26426 	456:  uint32(1149),
  26427 	457:  uint32(1147),
  26428 	458:  uint32(1144),
  26429 	459:  uint32(1142),
  26430 	460:  uint32(1139),
  26431 	461:  uint32(1137),
  26432 	462:  uint32(1134),
  26433 	463:  uint32(1132),
  26434 	464:  uint32(1129),
  26435 	465:  uint32(1127),
  26436 	466:  uint32(1125),
  26437 	467:  uint32(1122),
  26438 	468:  uint32(1120),
  26439 	469:  uint32(1117),
  26440 	470:  uint32(1115),
  26441 	471:  uint32(1113),
  26442 	472:  uint32(1110),
  26443 	473:  uint32(1108),
  26444 	474:  uint32(1106),
  26445 	475:  uint32(1103),
  26446 	476:  uint32(1101),
  26447 	477:  uint32(1099),
  26448 	478:  uint32(1096),
  26449 	479:  uint32(1094),
  26450 	480:  uint32(1092),
  26451 	481:  uint32(1089),
  26452 	482:  uint32(1087),
  26453 	483:  uint32(1085),
  26454 	484:  uint32(1083),
  26455 	485:  uint32(1081),
  26456 	486:  uint32(1078),
  26457 	487:  uint32(1076),
  26458 	488:  uint32(1074),
  26459 	489:  uint32(1072),
  26460 	490:  uint32(1069),
  26461 	491:  uint32(1067),
  26462 	492:  uint32(1065),
  26463 	493:  uint32(1063),
  26464 	494:  uint32(1061),
  26465 	495:  uint32(1059),
  26466 	496:  uint32(1057),
  26467 	497:  uint32(1054),
  26468 	498:  uint32(1052),
  26469 	499:  uint32(1050),
  26470 	500:  uint32(1048),
  26471 	501:  uint32(1046),
  26472 	502:  uint32(1044),
  26473 	503:  uint32(1042),
  26474 	504:  uint32(1040),
  26475 	505:  uint32(1038),
  26476 	506:  uint32(1036),
  26477 	507:  uint32(1034),
  26478 	508:  uint32(1032),
  26479 	509:  uint32(1030),
  26480 	510:  uint32(1028),
  26481 	511:  uint32(1026),
  26482 	512:  uint32(1024),
  26483 	513:  uint32(1022),
  26484 	514:  uint32(1020),
  26485 	515:  uint32(1018),
  26486 	516:  uint32(1016),
  26487 	517:  uint32(1014),
  26488 	518:  uint32(1012),
  26489 	519:  uint32(1010),
  26490 	520:  uint32(1008),
  26491 	521:  uint32(1006),
  26492 	522:  uint32(1004),
  26493 	523:  uint32(1002),
  26494 	524:  uint32(1000),
  26495 	525:  uint32(998),
  26496 	526:  uint32(996),
  26497 	527:  uint32(994),
  26498 	528:  uint32(992),
  26499 	529:  uint32(991),
  26500 	530:  uint32(989),
  26501 	531:  uint32(987),
  26502 	532:  uint32(985),
  26503 	533:  uint32(983),
  26504 	534:  uint32(981),
  26505 	535:  uint32(979),
  26506 	536:  uint32(978),
  26507 	537:  uint32(976),
  26508 	538:  uint32(974),
  26509 	539:  uint32(972),
  26510 	540:  uint32(970),
  26511 	541:  uint32(969),
  26512 	542:  uint32(967),
  26513 	543:  uint32(965),
  26514 	544:  uint32(963),
  26515 	545:  uint32(961),
  26516 	546:  uint32(960),
  26517 	547:  uint32(958),
  26518 	548:  uint32(956),
  26519 	549:  uint32(954),
  26520 	550:  uint32(953),
  26521 	551:  uint32(951),
  26522 	552:  uint32(949),
  26523 	553:  uint32(948),
  26524 	554:  uint32(946),
  26525 	555:  uint32(944),
  26526 	556:  uint32(942),
  26527 	557:  uint32(941),
  26528 	558:  uint32(939),
  26529 	559:  uint32(937),
  26530 	560:  uint32(936),
  26531 	561:  uint32(934),
  26532 	562:  uint32(932),
  26533 	563:  uint32(931),
  26534 	564:  uint32(929),
  26535 	565:  uint32(927),
  26536 	566:  uint32(926),
  26537 	567:  uint32(924),
  26538 	568:  uint32(923),
  26539 	569:  uint32(921),
  26540 	570:  uint32(919),
  26541 	571:  uint32(918),
  26542 	572:  uint32(916),
  26543 	573:  uint32(914),
  26544 	574:  uint32(913),
  26545 	575:  uint32(911),
  26546 	576:  uint32(910),
  26547 	577:  uint32(908),
  26548 	578:  uint32(907),
  26549 	579:  uint32(905),
  26550 	580:  uint32(903),
  26551 	581:  uint32(902),
  26552 	582:  uint32(900),
  26553 	583:  uint32(899),
  26554 	584:  uint32(897),
  26555 	585:  uint32(896),
  26556 	586:  uint32(894),
  26557 	587:  uint32(893),
  26558 	588:  uint32(891),
  26559 	589:  uint32(890),
  26560 	590:  uint32(888),
  26561 	591:  uint32(887),
  26562 	592:  uint32(885),
  26563 	593:  uint32(884),
  26564 	594:  uint32(882),
  26565 	595:  uint32(881),
  26566 	596:  uint32(879),
  26567 	597:  uint32(878),
  26568 	598:  uint32(876),
  26569 	599:  uint32(875),
  26570 	600:  uint32(873),
  26571 	601:  uint32(872),
  26572 	602:  uint32(870),
  26573 	603:  uint32(869),
  26574 	604:  uint32(868),
  26575 	605:  uint32(866),
  26576 	606:  uint32(865),
  26577 	607:  uint32(863),
  26578 	608:  uint32(862),
  26579 	609:  uint32(860),
  26580 	610:  uint32(859),
  26581 	611:  uint32(858),
  26582 	612:  uint32(856),
  26583 	613:  uint32(855),
  26584 	614:  uint32(853),
  26585 	615:  uint32(852),
  26586 	616:  uint32(851),
  26587 	617:  uint32(849),
  26588 	618:  uint32(848),
  26589 	619:  uint32(846),
  26590 	620:  uint32(845),
  26591 	621:  uint32(844),
  26592 	622:  uint32(842),
  26593 	623:  uint32(841),
  26594 	624:  uint32(840),
  26595 	625:  uint32(838),
  26596 	626:  uint32(837),
  26597 	627:  uint32(836),
  26598 	628:  uint32(834),
  26599 	629:  uint32(833),
  26600 	630:  uint32(832),
  26601 	631:  uint32(830),
  26602 	632:  uint32(829),
  26603 	633:  uint32(828),
  26604 	634:  uint32(826),
  26605 	635:  uint32(825),
  26606 	636:  uint32(824),
  26607 	637:  uint32(823),
  26608 	638:  uint32(821),
  26609 	639:  uint32(820),
  26610 	640:  uint32(819),
  26611 	641:  uint32(817),
  26612 	642:  uint32(816),
  26613 	643:  uint32(815),
  26614 	644:  uint32(814),
  26615 	645:  uint32(812),
  26616 	646:  uint32(811),
  26617 	647:  uint32(810),
  26618 	648:  uint32(809),
  26619 	649:  uint32(807),
  26620 	650:  uint32(806),
  26621 	651:  uint32(805),
  26622 	652:  uint32(804),
  26623 	653:  uint32(802),
  26624 	654:  uint32(801),
  26625 	655:  uint32(800),
  26626 	656:  uint32(799),
  26627 	657:  uint32(798),
  26628 	658:  uint32(796),
  26629 	659:  uint32(795),
  26630 	660:  uint32(794),
  26631 	661:  uint32(793),
  26632 	662:  uint32(791),
  26633 	663:  uint32(790),
  26634 	664:  uint32(789),
  26635 	665:  uint32(788),
  26636 	666:  uint32(787),
  26637 	667:  uint32(786),
  26638 	668:  uint32(784),
  26639 	669:  uint32(783),
  26640 	670:  uint32(782),
  26641 	671:  uint32(781),
  26642 	672:  uint32(780),
  26643 	673:  uint32(779),
  26644 	674:  uint32(777),
  26645 	675:  uint32(776),
  26646 	676:  uint32(775),
  26647 	677:  uint32(774),
  26648 	678:  uint32(773),
  26649 	679:  uint32(772),
  26650 	680:  uint32(771),
  26651 	681:  uint32(769),
  26652 	682:  uint32(768),
  26653 	683:  uint32(767),
  26654 	684:  uint32(766),
  26655 	685:  uint32(765),
  26656 	686:  uint32(764),
  26657 	687:  uint32(763),
  26658 	688:  uint32(762),
  26659 	689:  uint32(760),
  26660 	690:  uint32(759),
  26661 	691:  uint32(758),
  26662 	692:  uint32(757),
  26663 	693:  uint32(756),
  26664 	694:  uint32(755),
  26665 	695:  uint32(754),
  26666 	696:  uint32(753),
  26667 	697:  uint32(752),
  26668 	698:  uint32(751),
  26669 	699:  uint32(750),
  26670 	700:  uint32(748),
  26671 	701:  uint32(747),
  26672 	702:  uint32(746),
  26673 	703:  uint32(745),
  26674 	704:  uint32(744),
  26675 	705:  uint32(743),
  26676 	706:  uint32(742),
  26677 	707:  uint32(741),
  26678 	708:  uint32(740),
  26679 	709:  uint32(739),
  26680 	710:  uint32(738),
  26681 	711:  uint32(737),
  26682 	712:  uint32(736),
  26683 	713:  uint32(735),
  26684 	714:  uint32(734),
  26685 	715:  uint32(733),
  26686 	716:  uint32(732),
  26687 	717:  uint32(731),
  26688 	718:  uint32(730),
  26689 	719:  uint32(729),
  26690 	720:  uint32(728),
  26691 	721:  uint32(727),
  26692 	722:  uint32(726),
  26693 	723:  uint32(725),
  26694 	724:  uint32(724),
  26695 	725:  uint32(723),
  26696 	726:  uint32(722),
  26697 	727:  uint32(721),
  26698 	728:  uint32(720),
  26699 	729:  uint32(719),
  26700 	730:  uint32(718),
  26701 	731:  uint32(717),
  26702 	732:  uint32(716),
  26703 	733:  uint32(715),
  26704 	734:  uint32(714),
  26705 	735:  uint32(713),
  26706 	736:  uint32(712),
  26707 	737:  uint32(711),
  26708 	738:  uint32(710),
  26709 	739:  uint32(709),
  26710 	740:  uint32(708),
  26711 	741:  uint32(707),
  26712 	742:  uint32(706),
  26713 	743:  uint32(705),
  26714 	744:  uint32(704),
  26715 	745:  uint32(703),
  26716 	746:  uint32(702),
  26717 	747:  uint32(701),
  26718 	748:  uint32(700),
  26719 	749:  uint32(699),
  26720 	750:  uint32(699),
  26721 	751:  uint32(698),
  26722 	752:  uint32(697),
  26723 	753:  uint32(696),
  26724 	754:  uint32(695),
  26725 	755:  uint32(694),
  26726 	756:  uint32(693),
  26727 	757:  uint32(692),
  26728 	758:  uint32(691),
  26729 	759:  uint32(690),
  26730 	760:  uint32(689),
  26731 	761:  uint32(688),
  26732 	762:  uint32(688),
  26733 	763:  uint32(687),
  26734 	764:  uint32(686),
  26735 	765:  uint32(685),
  26736 	766:  uint32(684),
  26737 	767:  uint32(683),
  26738 	768:  uint32(682),
  26739 	769:  uint32(681),
  26740 	770:  uint32(680),
  26741 	771:  uint32(680),
  26742 	772:  uint32(679),
  26743 	773:  uint32(678),
  26744 	774:  uint32(677),
  26745 	775:  uint32(676),
  26746 	776:  uint32(675),
  26747 	777:  uint32(674),
  26748 	778:  uint32(673),
  26749 	779:  uint32(673),
  26750 	780:  uint32(672),
  26751 	781:  uint32(671),
  26752 	782:  uint32(670),
  26753 	783:  uint32(669),
  26754 	784:  uint32(668),
  26755 	785:  uint32(667),
  26756 	786:  uint32(667),
  26757 	787:  uint32(666),
  26758 	788:  uint32(665),
  26759 	789:  uint32(664),
  26760 	790:  uint32(663),
  26761 	791:  uint32(662),
  26762 	792:  uint32(661),
  26763 	793:  uint32(661),
  26764 	794:  uint32(660),
  26765 	795:  uint32(659),
  26766 	796:  uint32(658),
  26767 	797:  uint32(657),
  26768 	798:  uint32(657),
  26769 	799:  uint32(656),
  26770 	800:  uint32(655),
  26771 	801:  uint32(654),
  26772 	802:  uint32(653),
  26773 	803:  uint32(652),
  26774 	804:  uint32(652),
  26775 	805:  uint32(651),
  26776 	806:  uint32(650),
  26777 	807:  uint32(649),
  26778 	808:  uint32(648),
  26779 	809:  uint32(648),
  26780 	810:  uint32(647),
  26781 	811:  uint32(646),
  26782 	812:  uint32(645),
  26783 	813:  uint32(644),
  26784 	814:  uint32(644),
  26785 	815:  uint32(643),
  26786 	816:  uint32(642),
  26787 	817:  uint32(641),
  26788 	818:  uint32(640),
  26789 	819:  uint32(640),
  26790 	820:  uint32(639),
  26791 	821:  uint32(638),
  26792 	822:  uint32(637),
  26793 	823:  uint32(637),
  26794 	824:  uint32(636),
  26795 	825:  uint32(635),
  26796 	826:  uint32(634),
  26797 	827:  uint32(633),
  26798 	828:  uint32(633),
  26799 	829:  uint32(632),
  26800 	830:  uint32(631),
  26801 	831:  uint32(630),
  26802 	832:  uint32(630),
  26803 	833:  uint32(629),
  26804 	834:  uint32(628),
  26805 	835:  uint32(627),
  26806 	836:  uint32(627),
  26807 	837:  uint32(626),
  26808 	838:  uint32(625),
  26809 	839:  uint32(624),
  26810 	840:  uint32(624),
  26811 	841:  uint32(623),
  26812 	842:  uint32(622),
  26813 	843:  uint32(621),
  26814 	844:  uint32(621),
  26815 	845:  uint32(620),
  26816 	846:  uint32(619),
  26817 	847:  uint32(618),
  26818 	848:  uint32(618),
  26819 	849:  uint32(617),
  26820 	850:  uint32(616),
  26821 	851:  uint32(616),
  26822 	852:  uint32(615),
  26823 	853:  uint32(614),
  26824 	854:  uint32(613),
  26825 	855:  uint32(613),
  26826 	856:  uint32(612),
  26827 	857:  uint32(611),
  26828 	858:  uint32(611),
  26829 	859:  uint32(610),
  26830 	860:  uint32(609),
  26831 	861:  uint32(608),
  26832 	862:  uint32(608),
  26833 	863:  uint32(607),
  26834 	864:  uint32(606),
  26835 	865:  uint32(606),
  26836 	866:  uint32(605),
  26837 	867:  uint32(604),
  26838 	868:  uint32(604),
  26839 	869:  uint32(603),
  26840 	870:  uint32(602),
  26841 	871:  uint32(601),
  26842 	872:  uint32(601),
  26843 	873:  uint32(600),
  26844 	874:  uint32(599),
  26845 	875:  uint32(599),
  26846 	876:  uint32(598),
  26847 	877:  uint32(597),
  26848 	878:  uint32(597),
  26849 	879:  uint32(596),
  26850 	880:  uint32(595),
  26851 	881:  uint32(595),
  26852 	882:  uint32(594),
  26853 	883:  uint32(593),
  26854 	884:  uint32(593),
  26855 	885:  uint32(592),
  26856 	886:  uint32(591),
  26857 	887:  uint32(591),
  26858 	888:  uint32(590),
  26859 	889:  uint32(589),
  26860 	890:  uint32(589),
  26861 	891:  uint32(588),
  26862 	892:  uint32(587),
  26863 	893:  uint32(587),
  26864 	894:  uint32(586),
  26865 	895:  uint32(585),
  26866 	896:  uint32(585),
  26867 	897:  uint32(584),
  26868 	898:  uint32(583),
  26869 	899:  uint32(583),
  26870 	900:  uint32(582),
  26871 	901:  uint32(581),
  26872 	902:  uint32(581),
  26873 	903:  uint32(580),
  26874 	904:  uint32(579),
  26875 	905:  uint32(579),
  26876 	906:  uint32(578),
  26877 	907:  uint32(578),
  26878 	908:  uint32(577),
  26879 	909:  uint32(576),
  26880 	910:  uint32(576),
  26881 	911:  uint32(575),
  26882 	912:  uint32(574),
  26883 	913:  uint32(574),
  26884 	914:  uint32(573),
  26885 	915:  uint32(572),
  26886 	916:  uint32(572),
  26887 	917:  uint32(571),
  26888 	918:  uint32(571),
  26889 	919:  uint32(570),
  26890 	920:  uint32(569),
  26891 	921:  uint32(569),
  26892 	922:  uint32(568),
  26893 	923:  uint32(568),
  26894 	924:  uint32(567),
  26895 	925:  uint32(566),
  26896 	926:  uint32(566),
  26897 	927:  uint32(565),
  26898 	928:  uint32(564),
  26899 	929:  uint32(564),
  26900 	930:  uint32(563),
  26901 	931:  uint32(563),
  26902 	932:  uint32(562),
  26903 	933:  uint32(561),
  26904 	934:  uint32(561),
  26905 	935:  uint32(560),
  26906 	936:  uint32(560),
  26907 	937:  uint32(559),
  26908 	938:  uint32(558),
  26909 	939:  uint32(558),
  26910 	940:  uint32(557),
  26911 	941:  uint32(557),
  26912 	942:  uint32(556),
  26913 	943:  uint32(555),
  26914 	944:  uint32(555),
  26915 	945:  uint32(554),
  26916 	946:  uint32(554),
  26917 	947:  uint32(553),
  26918 	948:  uint32(553),
  26919 	949:  uint32(552),
  26920 	950:  uint32(551),
  26921 	951:  uint32(551),
  26922 	952:  uint32(550),
  26923 	953:  uint32(550),
  26924 	954:  uint32(549),
  26925 	955:  uint32(548),
  26926 	956:  uint32(548),
  26927 	957:  uint32(547),
  26928 	958:  uint32(547),
  26929 	959:  uint32(546),
  26930 	960:  uint32(546),
  26931 	961:  uint32(545),
  26932 	962:  uint32(544),
  26933 	963:  uint32(544),
  26934 	964:  uint32(543),
  26935 	965:  uint32(543),
  26936 	966:  uint32(542),
  26937 	967:  uint32(542),
  26938 	968:  uint32(541),
  26939 	969:  uint32(541),
  26940 	970:  uint32(540),
  26941 	971:  uint32(539),
  26942 	972:  uint32(539),
  26943 	973:  uint32(538),
  26944 	974:  uint32(538),
  26945 	975:  uint32(537),
  26946 	976:  uint32(537),
  26947 	977:  uint32(536),
  26948 	978:  uint32(536),
  26949 	979:  uint32(535),
  26950 	980:  uint32(534),
  26951 	981:  uint32(534),
  26952 	982:  uint32(533),
  26953 	983:  uint32(533),
  26954 	984:  uint32(532),
  26955 	985:  uint32(532),
  26956 	986:  uint32(531),
  26957 	987:  uint32(531),
  26958 	988:  uint32(530),
  26959 	989:  uint32(530),
  26960 	990:  uint32(529),
  26961 	991:  uint32(529),
  26962 	992:  uint32(528),
  26963 	993:  uint32(527),
  26964 	994:  uint32(527),
  26965 	995:  uint32(526),
  26966 	996:  uint32(526),
  26967 	997:  uint32(525),
  26968 	998:  uint32(525),
  26969 	999:  uint32(524),
  26970 	1000: uint32(524),
  26971 	1001: uint32(523),
  26972 	1002: uint32(523),
  26973 	1003: uint32(522),
  26974 	1004: uint32(522),
  26975 	1005: uint32(521),
  26976 	1006: uint32(521),
  26977 	1007: uint32(520),
  26978 	1008: uint32(520),
  26979 	1009: uint32(519),
  26980 	1010: uint32(519),
  26981 	1011: uint32(518),
  26982 	1012: uint32(518),
  26983 	1013: uint32(517),
  26984 	1014: uint32(517),
  26985 	1015: uint32(516),
  26986 	1016: uint32(516),
  26987 	1017: uint32(515),
  26988 	1018: uint32(515),
  26989 	1019: uint32(514),
  26990 	1020: uint32(514),
  26991 }
  26992 
  26993 // Note that LinearToGamma() expects the values to be premultiplied by 4,
  26994 // so we incorporate this factor 4 inside the DIVIDE_BY_ALPHA macro directly.
  26995 
  26996 func LinearToGammaWeighted(tls *libc.TLS, src uintptr, a_ptr uintptr, total_a uint32_t, step int32, rgb_stride int32) (r int32) {
  26997 	var sum uint32_t
  26998 	_ = sum
  26999 	sum = uint32(**(**uint8_t)(__ccgo_up(a_ptr)))*GammaToLinear(tls, **(**uint8_t)(__ccgo_up(src))) + uint32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(step))))*GammaToLinear(tls, **(**uint8_t)(__ccgo_up(src + uintptr(step)))) + uint32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(rgb_stride))))*GammaToLinear(tls, **(**uint8_t)(__ccgo_up(src + uintptr(rgb_stride)))) + uint32(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(rgb_stride+step))))*GammaToLinear(tls, **(**uint8_t)(__ccgo_up(src + uintptr(rgb_stride+step))))
  27000 	return LinearToGamma(tls, sum*kInvAlpha[total_a]>>(kAlphaFix-libc.Int32FromInt32(2)), 0)
  27001 }
  27002 
  27003 func ConvertRowToY(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, dst_y uintptr, width int32, rg uintptr) {
  27004 	var i, j int32
  27005 	_, _ = i, j
  27006 	i = 0
  27007 	j = libc.Int32FromInt32(0)
  27008 	for {
  27009 		if !(i < width) {
  27010 			break
  27011 		}
  27012 		**(**uint8_t)(__ccgo_up(dst_y + uintptr(i))) = libc.Uint8FromInt32(RGBToY(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(r_ptr + uintptr(j)))), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(g_ptr + uintptr(j)))), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(b_ptr + uintptr(j)))), rg))
  27013 		goto _1
  27014 	_1:
  27015 		;
  27016 		i = i + int32(1)
  27017 		j = j + step
  27018 	}
  27019 }
  27020 
  27021 func AccumulateRGBA(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, a_ptr uintptr, rgb_stride int32, dst uintptr, width int32) {
  27022 	var a, a1 uint32_t
  27023 	var b, b1, g, g1, i, j, r, r1 int32
  27024 	_, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, g, g1, i, j, r, r1
  27025 	// we loop over 2x2 blocks and produce one R/G/B/A value for each.
  27026 	i = 0
  27027 	j = libc.Int32FromInt32(0)
  27028 	for {
  27029 		if !(i < width>>int32(1)) {
  27030 			break
  27031 		}
  27032 		a = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + uintptr(rgb_stride)))) + (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + libc.UintptrFromInt32(4)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + libc.UintptrFromInt32(4) + uintptr(rgb_stride))))))
  27033 		if a == libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a == uint32(0) {
  27034 			r = LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + 4)))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(rgb_stride))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(rgb_stride+int32(4))))), 0)
  27035 			g = LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + 4)))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(rgb_stride))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(rgb_stride+int32(4))))), 0)
  27036 			b = LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + 4)))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(rgb_stride))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(rgb_stride+int32(4))))), 0)
  27037 		} else {
  27038 			r = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27039 			g = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27040 			b = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27041 		}
  27042 		**(**uint16_t)(__ccgo_up(dst)) = libc.Uint16FromInt32(r)
  27043 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = libc.Uint16FromInt32(g)
  27044 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = libc.Uint16FromInt32(b)
  27045 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a)
  27046 		goto _1
  27047 	_1:
  27048 		;
  27049 		i = i + int32(1)
  27050 		j = j + libc.Int32FromInt32(2)*libc.Int32FromInt32(4)
  27051 		dst = dst + uintptr(4)*2
  27052 	}
  27053 	if width&int32(1) != 0 {
  27054 		a1 = uint32(2) * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(j) + uintptr(rgb_stride)))))
  27055 		if a1 == libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a1 == uint32(0) {
  27056 			r1 = LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(rgb_stride)))), int32(1))
  27057 			g1 = LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(rgb_stride)))), int32(1))
  27058 			b1 = LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(rgb_stride)))), int32(1))
  27059 		} else {
  27060 			r1 = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27061 			g1 = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27062 			b1 = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27063 		}
  27064 		**(**uint16_t)(__ccgo_up(dst)) = libc.Uint16FromInt32(r1)
  27065 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = libc.Uint16FromInt32(g1)
  27066 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = libc.Uint16FromInt32(b1)
  27067 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a1)
  27068 	}
  27069 }
  27070 
  27071 func AccumulateRGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, dst uintptr, width int32) {
  27072 	var i, j int32
  27073 	_, _ = i, j
  27074 	i = 0
  27075 	j = libc.Int32FromInt32(0)
  27076 	for {
  27077 		if !(i < width>>int32(1)) {
  27078 			break
  27079 		}
  27080 		**(**uint16_t)(__ccgo_up(dst)) = libc.Uint16FromInt32(LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(step))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(rgb_stride))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(rgb_stride+step)))), 0))
  27081 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = libc.Uint16FromInt32(LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(step))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(rgb_stride))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(rgb_stride+step)))), 0))
  27082 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = libc.Uint16FromInt32(LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(step))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(rgb_stride))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(rgb_stride+step)))), 0))
  27083 		// MemorySanitizer may raise false positives with data that passes through
  27084 		// RGBA32PackedToPlanar_16b_SSE41() due to incorrect modeling of shuffles.
  27085 		// See https://crbug.com/webp/573.
  27086 		goto _1
  27087 	_1:
  27088 		;
  27089 		i = i + int32(1)
  27090 		j = j + int32(2)*step
  27091 		dst = dst + uintptr(4)*2
  27092 	}
  27093 	if width&int32(1) != 0 {
  27094 		**(**uint16_t)(__ccgo_up(dst)) = libc.Uint16FromInt32(LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(r_ptr + uintptr(j) + uintptr(rgb_stride)))), int32(1)))
  27095 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = libc.Uint16FromInt32(LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(g_ptr + uintptr(j) + uintptr(rgb_stride)))), int32(1)))
  27096 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = libc.Uint16FromInt32(LinearToGamma(tls, GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j))))+GammaToLinear(tls, **(**uint8_t)(__ccgo_up(b_ptr + uintptr(j) + uintptr(rgb_stride)))), int32(1)))
  27097 	}
  27098 }
  27099 
  27100 func ConvertRowsToUV(tls *libc.TLS, rgb uintptr, dst_u uintptr, dst_v uintptr, width int32, rg uintptr) {
  27101 	var b, g, i, r int32
  27102 	_, _, _, _ = b, g, i, r
  27103 	i = 0
  27104 	for {
  27105 		if !(i < width) {
  27106 			break
  27107 		}
  27108 		r = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb)))
  27109 		g = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  27110 		b = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  27111 		**(**uint8_t)(__ccgo_up(dst_u + uintptr(i))) = libc.Uint8FromInt32(RGBToU(tls, r, g, b, rg))
  27112 		**(**uint8_t)(__ccgo_up(dst_v + uintptr(i))) = libc.Uint8FromInt32(RGBToV(tls, r, g, b, rg))
  27113 		goto _1
  27114 	_1:
  27115 		;
  27116 		i = i + int32(1)
  27117 		rgb = rgb + uintptr(4)*2
  27118 	}
  27119 }
  27120 
  27121 func ImportYUVAFromRGBA(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, a_ptr uintptr, step int32, rgb_stride int32, dithering float32, use_iterative_conversion int32, picture uintptr) (r int32) {
  27122 	bp := tls.Alloc(240)
  27123 	defer tls.Free(240)
  27124 	var dst_a, dst_u, dst_v, dst_y, rg, tmp_rgb uintptr
  27125 	var has_alpha, height, is_rgb, row_has_alpha, rows_have_alpha, use_dsp, uv_width, width, y, v1 int32
  27126 	var _ /* base_rg at bp+0 */ VP8Random
  27127 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = dst_a, dst_u, dst_v, dst_y, has_alpha, height, is_rgb, rg, row_has_alpha, rows_have_alpha, tmp_rgb, use_dsp, uv_width, width, y, v1
  27128 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27129 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27130 	has_alpha = CheckNonOpaque(tls, a_ptr, width, height, step, rgb_stride)
  27131 	is_rgb = libc.BoolInt32(r_ptr < b_ptr) // otherwise it's bgr
  27132 	if has_alpha != 0 {
  27133 		v1 = int32(WEBP_YUV420A)
  27134 	} else {
  27135 		v1 = int32(WEBP_YUV420)
  27136 	}
  27137 	(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = v1
  27138 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = 0
  27139 	// disable smart conversion if source is too small (overkill).
  27140 	if width < kMinDimensionIterativeConversion || height < kMinDimensionIterativeConversion {
  27141 		use_iterative_conversion = 0
  27142 	}
  27143 	if !(WebPPictureAllocYUVA(tls, picture) != 0) {
  27144 		return 0
  27145 	}
  27146 	if has_alpha != 0 {
  27147 	}
  27148 	if use_iterative_conversion != 0 {
  27149 		SharpYuvInit(tls, VP8GetCPUInfo)
  27150 		if !(PreprocessARGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, picture) != 0) {
  27151 			return 0
  27152 		}
  27153 		if has_alpha != 0 {
  27154 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPExtractAlpha})))(tls, a_ptr, rgb_stride, width, height, (*WebPPicture)(unsafe.Pointer(picture)).Fa, (*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27155 		}
  27156 	} else {
  27157 		uv_width = (width + int32(1)) >> int32(1)
  27158 		use_dsp = libc.BoolInt32(step == int32(3)) // use special function in this case
  27159 		// temporary storage for accumulated R/G/B values during conversion to U/V
  27160 		tmp_rgb = WebPSafeMalloc(tls, libc.Uint64FromInt32(int32(4)*uv_width), uint64(2))
  27161 		dst_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27162 		dst_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27163 		dst_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27164 		dst_a = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  27165 		rg = libc.UintptrFromInt32(0)
  27166 		if float64(dithering) > float64(0) {
  27167 			VP8InitRandom(tls, bp, dithering)
  27168 			rg = bp
  27169 			use_dsp = 0 // can't use dsp in this case
  27170 		}
  27171 		WebPInitConvertARGBToYUV(tls)
  27172 		InitGammaTables(tls)
  27173 		if tmp_rgb == libc.UintptrFromInt32(0) {
  27174 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  27175 		}
  27176 		// Downsample Y/U/V planes, two rows at a time
  27177 		y = 0
  27178 		for {
  27179 			if !(y < height>>libc.Int32FromInt32(1)) {
  27180 				break
  27181 			}
  27182 			rows_have_alpha = has_alpha
  27183 			if use_dsp != 0 {
  27184 				if is_rgb != 0 {
  27185 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27186 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr+uintptr(rgb_stride), dst_y+uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride), width)
  27187 				} else {
  27188 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27189 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr+uintptr(rgb_stride), dst_y+uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride), width)
  27190 				}
  27191 			} else {
  27192 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27193 				ConvertRowToY(tls, r_ptr+uintptr(rgb_stride), g_ptr+uintptr(rgb_stride), b_ptr+uintptr(rgb_stride), step, dst_y+uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride), width, rg)
  27194 			}
  27195 			dst_y = dst_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27196 			if has_alpha != 0 {
  27197 				rows_have_alpha = rows_have_alpha & libc.BoolInt32(!((*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPExtractAlpha})))(tls, a_ptr, rgb_stride, width, int32(2), dst_a, (*WebPPicture)(unsafe.Pointer(picture)).Fa_stride) != 0))
  27198 				dst_a = dst_a + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27199 			}
  27200 			// Collect averaged R/G/B(/A)
  27201 			if !(rows_have_alpha != 0) {
  27202 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, tmp_rgb, width)
  27203 			} else {
  27204 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, rgb_stride, tmp_rgb, width)
  27205 			}
  27206 			// Convert to U/V
  27207 			if rg == libc.UintptrFromInt32(0) {
  27208 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27209 			} else {
  27210 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27211 			}
  27212 			dst_u = dst_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27213 			dst_v = dst_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27214 			r_ptr = r_ptr + uintptr(int32(2)*rgb_stride)
  27215 			b_ptr = b_ptr + uintptr(int32(2)*rgb_stride)
  27216 			g_ptr = g_ptr + uintptr(int32(2)*rgb_stride)
  27217 			if has_alpha != 0 {
  27218 				a_ptr = a_ptr + uintptr(int32(2)*rgb_stride)
  27219 			}
  27220 			goto _2
  27221 		_2:
  27222 			;
  27223 			y = y + 1
  27224 		}
  27225 		if height&int32(1) != 0 { // extra last row
  27226 			row_has_alpha = has_alpha
  27227 			if use_dsp != 0 {
  27228 				if r_ptr < b_ptr {
  27229 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27230 				} else {
  27231 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27232 				}
  27233 			} else {
  27234 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27235 			}
  27236 			if row_has_alpha != 0 {
  27237 				row_has_alpha = row_has_alpha & libc.BoolInt32(!((*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPExtractAlpha})))(tls, a_ptr, 0, width, int32(1), dst_a, 0) != 0))
  27238 			}
  27239 			// Collect averaged R/G/B(/A)
  27240 			if !(row_has_alpha != 0) {
  27241 				// Collect averaged R/G/B
  27242 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, 0, tmp_rgb, width)
  27243 			} else {
  27244 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, 0, tmp_rgb, width)
  27245 			}
  27246 			if rg == libc.UintptrFromInt32(0) {
  27247 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27248 			} else {
  27249 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27250 			}
  27251 		}
  27252 		WebPSafeFree(tls, tmp_rgb)
  27253 	}
  27254 	return int32(1)
  27255 }
  27256 
  27257 //------------------------------------------------------------------------------
  27258 // call for ARGB->YUVA conversion
  27259 
  27260 func PictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32, use_iterative_conversion int32) (r1 int32) {
  27261 	var a, argb, b, g, r uintptr
  27262 	_, _, _, _, _ = a, argb, b, g, r
  27263 	if picture == libc.UintptrFromInt32(0) {
  27264 		return 0
  27265 	}
  27266 	if (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  27267 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27268 	} else {
  27269 		if colorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27270 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27271 		} else {
  27272 			argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27273 			a = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(0))
  27274 			r = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
  27275 			g = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(2))
  27276 			b = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(3))
  27277 			(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = int32(WEBP_YUV420)
  27278 			return ImportYUVAFromRGBA(tls, r, g, b, a, int32(4), int32(4)*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride, dithering, use_iterative_conversion, picture)
  27279 		}
  27280 	}
  27281 	return r1
  27282 }
  27283 
  27284 func WebPPictureARGBToYUVADithered(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32) (r int32) {
  27285 	return PictureARGBToYUVA(tls, picture, colorspace, dithering, 0)
  27286 }
  27287 
  27288 func WebPPictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1) (r int32) {
  27289 	return PictureARGBToYUVA(tls, picture, colorspace, libc.Float32FromFloat32(0), 0)
  27290 }
  27291 
  27292 func WebPPictureSharpARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27293 	return PictureARGBToYUVA(tls, picture, int32(WEBP_YUV420), libc.Float32FromFloat32(0), int32(1))
  27294 }
  27295 
  27296 // C documentation
  27297 //
  27298 //	// for backward compatibility
  27299 func WebPPictureSmartARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27300 	return WebPPictureSharpARGBToYUVA(tls, picture)
  27301 }
  27302 
  27303 //------------------------------------------------------------------------------
  27304 // call for YUVA -> ARGB conversion
  27305 
  27306 func WebPPictureYUVAToARGB(tls *libc.TLS, picture uintptr) (r int32) {
  27307 	var argb_dst, cur_u, cur_v, cur_y, dst, src, top_u, top_v uintptr
  27308 	var argb_stride, height, width, x, y int32
  27309 	var upsample WebPUpsampleLinePairFunc
  27310 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_dst, argb_stride, cur_u, cur_v, cur_y, dst, height, src, top_u, top_v, upsample, width, x, y
  27311 	if picture == libc.UintptrFromInt32(0) {
  27312 		return 0
  27313 	}
  27314 	if (*WebPPicture)(unsafe.Pointer(picture)).Fy == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(picture)).Fu == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(picture)).Fv == libc.UintptrFromInt32(0) {
  27315 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27316 	}
  27317 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 && (*WebPPicture)(unsafe.Pointer(picture)).Fa == libc.UintptrFromInt32(0) {
  27318 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27319 	}
  27320 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27321 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27322 	}
  27323 	// Allocate a new argb buffer (discarding the previous one).
  27324 	if !(WebPPictureAllocARGB(tls, picture) != 0) {
  27325 		return 0
  27326 	}
  27327 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = int32(1)
  27328 	// Convert
  27329 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27330 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27331 	argb_stride = int32(4) * (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  27332 	dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27333 	cur_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27334 	cur_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27335 	cur_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27336 	upsample = WebPGetLinePairConverter(tls, libc.BoolInt32(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) > 0))
  27337 	// First row, with replicated top samples.
  27338 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, cur_y, libc.UintptrFromInt32(0), cur_u, cur_v, cur_u, cur_v, dst, libc.UintptrFromInt32(0), width)
  27339 	cur_y = cur_y + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27340 	dst = dst + uintptr(argb_stride)
  27341 	// Center rows.
  27342 	y = int32(1)
  27343 	for {
  27344 		if !(y+int32(1) < height) {
  27345 			break
  27346 		}
  27347 		top_u = cur_u
  27348 		top_v = cur_v
  27349 		cur_u = cur_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27350 		cur_v = cur_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27351 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, cur_y, cur_y+uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride), top_u, top_v, cur_u, cur_v, dst, dst+uintptr(argb_stride), width)
  27352 		cur_y = cur_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27353 		dst = dst + uintptr(int32(2)*argb_stride)
  27354 		goto _1
  27355 	_1:
  27356 		;
  27357 		y = y + int32(2)
  27358 	}
  27359 	// Last row (if needed), with replicated bottom samples.
  27360 	if height > int32(1) && !(height&libc.Int32FromInt32(1) != 0) {
  27361 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{upsample})))(tls, cur_y, libc.UintptrFromInt32(0), cur_u, cur_v, cur_u, cur_v, dst, libc.UintptrFromInt32(0), width)
  27362 	}
  27363 	// Insert alpha values if needed, in replacement for the default 0xff ones.
  27364 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 {
  27365 		y = 0
  27366 		for {
  27367 			if !(y < height) {
  27368 				break
  27369 			}
  27370 			argb_dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27371 			src = (*WebPPicture)(unsafe.Pointer(picture)).Fa + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27372 			x = 0
  27373 			for {
  27374 				if !(x < width) {
  27375 					break
  27376 				}
  27377 				**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = **(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4))&uint32(0x00ffffff) | uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x))))<<libc.Int32FromInt32(24)
  27378 				goto _3
  27379 			_3:
  27380 				;
  27381 				x = x + 1
  27382 			}
  27383 			goto _2
  27384 		_2:
  27385 			;
  27386 			y = y + 1
  27387 		}
  27388 	}
  27389 	return int32(1)
  27390 }
  27391 
  27392 //------------------------------------------------------------------------------
  27393 // automatic import / conversion
  27394 
  27395 func Import(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32, step int32, swap_rb int32, import_alpha int32) (r int32) {
  27396 	var a_ptr, b_ptr, dst, dst1, g_ptr, r_ptr, v4 uintptr
  27397 	var do_copy, height, width, y, v1, v2, v3 int32
  27398 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_ptr, b_ptr, do_copy, dst, dst1, g_ptr, height, r_ptr, width, y, v1, v2, v3, v4
  27399 	if swap_rb != 0 {
  27400 		v1 = int32(2)
  27401 	} else {
  27402 		v1 = 0
  27403 	}
  27404 	// swap_rb -> b,g,r,a , !swap_rb -> r,g,b,a
  27405 	r_ptr = rgb + uintptr(v1)
  27406 	g_ptr = rgb + uintptr(1)
  27407 	if swap_rb != 0 {
  27408 		v2 = 0
  27409 	} else {
  27410 		v2 = int32(2)
  27411 	}
  27412 	b_ptr = rgb + uintptr(v2)
  27413 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27414 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27415 	if import_alpha != 0 {
  27416 		v3 = int32(4)
  27417 	} else {
  27418 		v3 = int32(3)
  27419 	}
  27420 	if libc.Xabs(tls, rgb_stride) < v3*width {
  27421 		return 0
  27422 	}
  27423 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  27424 		if import_alpha != 0 {
  27425 			v4 = rgb + uintptr(3)
  27426 		} else {
  27427 			v4 = libc.UintptrFromInt32(0)
  27428 		}
  27429 		a_ptr = v4
  27430 		return ImportYUVAFromRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, step, rgb_stride, libc.Float32FromFloat32(0), 0, picture)
  27431 	}
  27432 	if !(WebPPictureAlloc(tls, picture) != 0) {
  27433 		return 0
  27434 	}
  27435 	VP8LDspInit(tls)
  27436 	WebPInitAlphaProcessing(tls)
  27437 	if import_alpha != 0 {
  27438 		// dst[] byte order is {a,r,g,b} for big-endian, {b,g,r,a} for little endian
  27439 		dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27440 		do_copy = libc.BoolInt32(libc.Bool(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) == int32(3)) && swap_rb != 0)
  27441 		if do_copy != 0 {
  27442 			y = 0
  27443 			for {
  27444 				if !(y < height) {
  27445 					break
  27446 				}
  27447 				libc.Xmemcpy(tls, dst, rgb, libc.Uint64FromInt32(width*int32(4)))
  27448 				rgb = rgb + uintptr(rgb_stride)
  27449 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27450 				goto _5
  27451 			_5:
  27452 				;
  27453 				y = y + 1
  27454 			}
  27455 		} else {
  27456 			y = 0
  27457 			for {
  27458 				if !(y < height) {
  27459 					break
  27460 				}
  27461 				// RGBA input order. Need to swap R and B.
  27462 				(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, rgb, width, dst)
  27463 				rgb = rgb + uintptr(rgb_stride)
  27464 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27465 				goto _6
  27466 			_6:
  27467 				;
  27468 				y = y + 1
  27469 			}
  27470 		}
  27471 	} else {
  27472 		dst1 = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27473 		y = 0
  27474 		for {
  27475 			if !(y < height) {
  27476 				break
  27477 			}
  27478 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPPackRGB})))(tls, r_ptr, g_ptr, b_ptr, width, step, dst1)
  27479 			r_ptr = r_ptr + uintptr(rgb_stride)
  27480 			g_ptr = g_ptr + uintptr(rgb_stride)
  27481 			b_ptr = b_ptr + uintptr(rgb_stride)
  27482 			dst1 = dst1 + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27483 			goto _7
  27484 		_7:
  27485 			;
  27486 			y = y + 1
  27487 		}
  27488 	}
  27489 	return int32(1)
  27490 }
  27491 
  27492 // Public API
  27493 
  27494 func WebPPictureImportBGR(tls *libc.TLS, picture uintptr, bgr uintptr, bgr_stride int32) (r int32) {
  27495 	var v1 int32
  27496 	_ = v1
  27497 	if picture != libc.UintptrFromInt32(0) && bgr != libc.UintptrFromInt32(0) {
  27498 		v1 = Import(tls, picture, bgr, bgr_stride, int32(3), int32(1), 0)
  27499 	} else {
  27500 		v1 = 0
  27501 	}
  27502 	return v1
  27503 }
  27504 
  27505 func WebPPictureImportBGRA(tls *libc.TLS, picture uintptr, bgra uintptr, bgra_stride int32) (r int32) {
  27506 	var v1 int32
  27507 	_ = v1
  27508 	if picture != libc.UintptrFromInt32(0) && bgra != libc.UintptrFromInt32(0) {
  27509 		v1 = Import(tls, picture, bgra, bgra_stride, int32(4), int32(1), int32(1))
  27510 	} else {
  27511 		v1 = 0
  27512 	}
  27513 	return v1
  27514 }
  27515 
  27516 func WebPPictureImportBGRX(tls *libc.TLS, picture uintptr, bgrx uintptr, bgrx_stride int32) (r int32) {
  27517 	var v1 int32
  27518 	_ = v1
  27519 	if picture != libc.UintptrFromInt32(0) && bgrx != libc.UintptrFromInt32(0) {
  27520 		v1 = Import(tls, picture, bgrx, bgrx_stride, int32(4), int32(1), 0)
  27521 	} else {
  27522 		v1 = 0
  27523 	}
  27524 	return v1
  27525 }
  27526 
  27527 func WebPPictureImportRGB(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32) (r int32) {
  27528 	var v1 int32
  27529 	_ = v1
  27530 	if picture != libc.UintptrFromInt32(0) && rgb != libc.UintptrFromInt32(0) {
  27531 		v1 = Import(tls, picture, rgb, rgb_stride, int32(3), 0, 0)
  27532 	} else {
  27533 		v1 = 0
  27534 	}
  27535 	return v1
  27536 }
  27537 
  27538 func WebPPictureImportRGBA(tls *libc.TLS, picture uintptr, rgba uintptr, rgba_stride int32) (r int32) {
  27539 	var v1 int32
  27540 	_ = v1
  27541 	if picture != libc.UintptrFromInt32(0) && rgba != libc.UintptrFromInt32(0) {
  27542 		v1 = Import(tls, picture, rgba, rgba_stride, int32(4), 0, int32(1))
  27543 	} else {
  27544 		v1 = 0
  27545 	}
  27546 	return v1
  27547 }
  27548 
  27549 func WebPPictureImportRGBX(tls *libc.TLS, picture uintptr, rgbx uintptr, rgbx_stride int32) (r int32) {
  27550 	var v1 int32
  27551 	_ = v1
  27552 	if picture != libc.UintptrFromInt32(0) && rgbx != libc.UintptrFromInt32(0) {
  27553 		v1 = Import(tls, picture, rgbx, rgbx_stride, int32(4), 0, 0)
  27554 	} else {
  27555 		v1 = 0
  27556 	}
  27557 	return v1
  27558 }
  27559 
  27560 const ARG_MAX = 131072
  27561 const BC_BASE_MAX = 99
  27562 const BC_DIM_MAX = 2048
  27563 const BC_SCALE_MAX = 99
  27564 const BC_STRING_MAX = 1000
  27565 const CHARCLASS_NAME_MAX = 14
  27566 const CHAR_BIT = 8
  27567 const CHAR_MAX = 127
  27568 const COLL_WEIGHTS_MAX = 2
  27569 const DELAYTIMER_MAX = 0x7fffffff
  27570 const EXPR_NEST_MAX = 32
  27571 const FILESIZEBITS = 64
  27572 const HOST_NAME_MAX = 255
  27573 const INT_MAX = 2147483647
  27574 const IOV_MAX = 1024
  27575 const LINE_MAX = 4096
  27576 const LLONG_MAX = 0x7fffffffffffffff
  27577 const LOGIN_NAME_MAX = 256
  27578 const LONG_BIT = 64
  27579 const LONG_MAX = "__LONG_MAX"
  27580 const LOSSLESS_DEFAULT_QUALITY = 70
  27581 const MB_LEN_MAX = 4
  27582 const MQ_PRIO_MAX = 32768
  27583 const NAME_MAX = 255
  27584 const NGROUPS_MAX = 32
  27585 const NL_ARGMAX = 9
  27586 const NL_LANGMAX = 32
  27587 const NL_MSGMAX = 32767
  27588 const NL_NMAX = 16
  27589 const NL_SETMAX = 255
  27590 const NL_TEXTMAX = 2048
  27591 const NZERO = 20
  27592 const PAGESIZE = 4096
  27593 const PAGE_SIZE = "PAGESIZE"
  27594 const PATH_MAX = 4096
  27595 const PIPE_BUF = 4096
  27596 const PTHREAD_DESTRUCTOR_ITERATIONS = 4
  27597 const PTHREAD_KEYS_MAX = 128
  27598 const PTHREAD_STACK_MIN = 2048
  27599 const RE_DUP_MAX = 255
  27600 const SCHAR_MAX = 127
  27601 const SEM_NSEMS_MAX = 256
  27602 const SEM_VALUE_MAX = 0x7fffffff
  27603 const SHRT_MAX = 0x7fff
  27604 const SSIZE_MAX = "LONG_MAX"
  27605 const SYMLOOP_MAX = 40
  27606 const TTY_NAME_MAX = 32
  27607 const TZNAME_MAX = 6
  27608 const UCHAR_MAX = 255
  27609 const UINT_MAX = 0xffffffff
  27610 const USHRT_MAX = 0xffff
  27611 const WORD_BIT = 32
  27612 const _POSIX2_BC_BASE_MAX = 99
  27613 const _POSIX2_BC_DIM_MAX = 2048
  27614 const _POSIX2_BC_SCALE_MAX = 99
  27615 const _POSIX2_BC_STRING_MAX = 1000
  27616 const _POSIX2_CHARCLASS_NAME_MAX = 14
  27617 const _POSIX2_COLL_WEIGHTS_MAX = 2
  27618 const _POSIX2_EXPR_NEST_MAX = 32
  27619 const _POSIX2_LINE_MAX = 2048
  27620 const _POSIX2_RE_DUP_MAX = 255
  27621 const _POSIX_AIO_LISTIO_MAX = 2
  27622 const _POSIX_AIO_MAX = 1
  27623 const _POSIX_ARG_MAX = 4096
  27624 const _POSIX_CHILD_MAX = 25
  27625 const _POSIX_CLOCKRES_MIN = 20000000
  27626 const _POSIX_DELAYTIMER_MAX = 32
  27627 const _POSIX_HOST_NAME_MAX = 255
  27628 const _POSIX_LINK_MAX = 8
  27629 const _POSIX_LOGIN_NAME_MAX = 9
  27630 const _POSIX_MAX_CANON = 255
  27631 const _POSIX_MAX_INPUT = 255
  27632 const _POSIX_MQ_OPEN_MAX = 8
  27633 const _POSIX_MQ_PRIO_MAX = 32
  27634 const _POSIX_NAME_MAX = 14
  27635 const _POSIX_NGROUPS_MAX = 8
  27636 const _POSIX_OPEN_MAX = 20
  27637 const _POSIX_PATH_MAX = 256
  27638 const _POSIX_PIPE_BUF = 512
  27639 const _POSIX_RE_DUP_MAX = 255
  27640 const _POSIX_RTSIG_MAX = 8
  27641 const _POSIX_SEM_NSEMS_MAX = 256
  27642 const _POSIX_SEM_VALUE_MAX = 32767
  27643 const _POSIX_SIGQUEUE_MAX = 32
  27644 const _POSIX_SSIZE_MAX = 32767
  27645 const _POSIX_SS_REPL_MAX = 4
  27646 const _POSIX_STREAM_MAX = 8
  27647 const _POSIX_SYMLINK_MAX = 255
  27648 const _POSIX_SYMLOOP_MAX = 8
  27649 const _POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4
  27650 const _POSIX_THREAD_KEYS_MAX = 128
  27651 const _POSIX_THREAD_THREADS_MAX = 64
  27652 const _POSIX_TIMER_MAX = 32
  27653 const _POSIX_TRACE_EVENT_NAME_MAX = 30
  27654 const _POSIX_TRACE_NAME_MAX = 8
  27655 const _POSIX_TRACE_SYS_MAX = 8
  27656 const _POSIX_TRACE_USER_EVENT_MAX = 32
  27657 const _POSIX_TTY_NAME_MAX = 9
  27658 const _POSIX_TZNAME_MAX = 6
  27659 const _XOPEN_IOV_MAX = 16
  27660 const _XOPEN_NAME_MAX = 255
  27661 const _XOPEN_PATH_MAX = 1024
  27662 
  27663 //------------------------------------------------------------------------------
  27664 
  27665 // Copyright 2012 Google Inc. All Rights Reserved.
  27666 //
  27667 // Use of this source code is governed by a BSD-style license
  27668 // that can be found in the COPYING file in the root of the source
  27669 // tree. An additional intellectual property rights grant can be found
  27670 // in the file PATENTS. All contributing project authors may
  27671 // be found in the AUTHORS file in the root of the source tree.
  27672 // -----------------------------------------------------------------------------
  27673 //
  27674 // Misc. common utility functions
  27675 //
  27676 // Authors: Skal (pascal.massimino@gmail.com)
  27677 //          Urvang (urvang@google.com)
  27678 
  27679 // Copyright 2011 Google Inc. All Rights Reserved.
  27680 //
  27681 // Use of this source code is governed by a BSD-style license
  27682 // that can be found in the COPYING file in the root of the source
  27683 // tree. An additional intellectual property rights grant can be found
  27684 // in the file PATENTS. All contributing project authors may
  27685 // be found in the AUTHORS file in the root of the source tree.
  27686 // -----------------------------------------------------------------------------
  27687 //
  27688 //   WebP encoder: main interface
  27689 //
  27690 // Author: Skal (pascal.massimino@gmail.com)
  27691 
  27692 // Copyright 2010 Google Inc. All Rights Reserved.
  27693 //
  27694 // Use of this source code is governed by a BSD-style license
  27695 // that can be found in the COPYING file in the root of the source
  27696 // tree. An additional intellectual property rights grant can be found
  27697 // in the file PATENTS. All contributing project authors may
  27698 // be found in the AUTHORS file in the root of the source tree.
  27699 // -----------------------------------------------------------------------------
  27700 //
  27701 //  Common types + memory wrappers
  27702 //
  27703 // Author: Skal (pascal.massimino@gmail.com)
  27704 
  27705 //------------------------------------------------------------------------------
  27706 // WebPPicture
  27707 //------------------------------------------------------------------------------
  27708 
  27709 func DummyWriter(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  27710 	// The following are to prevent 'unused variable' error message.
  27711 	_ = data
  27712 	_ = data_size
  27713 	_ = picture
  27714 	return int32(1)
  27715 }
  27716 
  27717 func WebPPictureInitInternal(tls *libc.TLS, picture uintptr, version int32) (r int32) {
  27718 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  27719 		return 0 // caller/system version mismatch!
  27720 	}
  27721 	if picture != libc.UintptrFromInt32(0) {
  27722 		libc.Xmemset(tls, picture, 0, uint64(256))
  27723 		(*WebPPicture)(unsafe.Pointer(picture)).Fwriter = __ccgo_fp(DummyWriter)
  27724 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_OK))
  27725 	}
  27726 	return int32(1)
  27727 }
  27728 
  27729 //------------------------------------------------------------------------------
  27730 
  27731 func WebPValidatePicture(tls *libc.TLS, picture uintptr) (r int32) {
  27732 	if picture == libc.UintptrFromInt32(0) {
  27733 		return 0
  27734 	}
  27735 	if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fheight <= 0 {
  27736 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  27737 	}
  27738 	if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fwidth/int32(4) > libc.Int32FromInt32(INT_MAX)/libc.Int32FromInt32(4) || (*WebPPicture)(unsafe.Pointer(picture)).Fheight <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fheight/int32(4) > libc.Int32FromInt32(INT_MAX)/libc.Int32FromInt32(4) {
  27739 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  27740 	}
  27741 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420) && (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420A) {
  27742 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27743 	}
  27744 	return int32(1)
  27745 }
  27746 
  27747 func WebPPictureResetBufferARGB(tls *libc.TLS, picture uintptr) {
  27748 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = libc.UintptrFromInt32(0)
  27749 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = libc.UintptrFromInt32(0)
  27750 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = 0
  27751 }
  27752 
  27753 func WebPPictureResetBufferYUVA(tls *libc.TLS, picture uintptr) {
  27754 	var v1, v2, v3 uintptr
  27755 	var v4 int32
  27756 	_, _, _, _ = v1, v2, v3, v4
  27757 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = libc.UintptrFromInt32(0)
  27758 	v3 = libc.UintptrFromInt32(0)
  27759 	(*WebPPicture)(unsafe.Pointer(picture)).Fa = v3
  27760 	v2 = v3
  27761 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = v2
  27762 	v1 = v2
  27763 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = v1
  27764 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = v1
  27765 	v4 = libc.Int32FromInt32(0)
  27766 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = v4
  27767 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = v4
  27768 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = 0
  27769 }
  27770 
  27771 func WebPPictureResetBuffers(tls *libc.TLS, picture uintptr) {
  27772 	WebPPictureResetBufferARGB(tls, picture)
  27773 	WebPPictureResetBufferYUVA(tls, picture)
  27774 }
  27775 
  27776 func WebPPictureAllocARGB(tls *libc.TLS, picture uintptr) (r int32) {
  27777 	var argb_size uint64_t
  27778 	var height, width int32
  27779 	var memory uintptr
  27780 	_, _, _, _ = argb_size, height, memory, width
  27781 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27782 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27783 	argb_size = libc.Uint64FromInt32(width) * libc.Uint64FromInt32(height)
  27784 	if !(WebPValidatePicture(tls, picture) != 0) {
  27785 		return 0
  27786 	}
  27787 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  27788 	WebPPictureResetBufferARGB(tls, picture)
  27789 	// allocate a new buffer.
  27790 	memory = WebPSafeMalloc(tls, argb_size+uint64(WEBP_ALIGN_CST), uint64(4))
  27791 	if memory == libc.UintptrFromInt32(0) {
  27792 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  27793 	}
  27794 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = memory
  27795 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  27796 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = width
  27797 	return int32(1)
  27798 }
  27799 
  27800 func WebPPictureAllocYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27801 	var a_size, total_size, uv_size, y_size uint64_t
  27802 	var a_stride, a_width, has_alpha, height, uv_height, uv_stride, uv_width, width, y_stride, v1 int32
  27803 	var mem uintptr
  27804 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_size, a_stride, a_width, has_alpha, height, mem, total_size, uv_height, uv_size, uv_stride, uv_width, width, y_size, y_stride, v1
  27805 	has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  27806 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27807 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27808 	y_stride = width
  27809 	uv_width = int32((int64(width) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  27810 	uv_height = int32((int64(height) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  27811 	uv_stride = uv_width
  27812 	if !(WebPValidatePicture(tls, picture) != 0) {
  27813 		return 0
  27814 	}
  27815 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  27816 	WebPPictureResetBufferYUVA(tls, picture)
  27817 	// alpha
  27818 	if has_alpha != 0 {
  27819 		v1 = width
  27820 	} else {
  27821 		v1 = 0
  27822 	}
  27823 	a_width = v1
  27824 	a_stride = a_width
  27825 	y_size = libc.Uint64FromInt32(y_stride) * libc.Uint64FromInt32(height)
  27826 	uv_size = libc.Uint64FromInt32(uv_stride) * libc.Uint64FromInt32(uv_height)
  27827 	a_size = libc.Uint64FromInt32(a_stride) * libc.Uint64FromInt32(height)
  27828 	total_size = y_size + a_size + uint64(2)*uv_size
  27829 	// Security and validation checks
  27830 	if width <= 0 || height <= 0 || uv_width <= 0 || uv_height <= 0 { // u/v param error
  27831 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  27832 	}
  27833 	// allocate a new buffer.
  27834 	mem = WebPSafeMalloc(tls, total_size, uint64(1))
  27835 	if mem == libc.UintptrFromInt32(0) {
  27836 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  27837 	}
  27838 	// From now on, we're in the clear, we can no longer fail...
  27839 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = mem
  27840 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = y_stride
  27841 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = uv_stride
  27842 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = a_stride
  27843 	// TODO(skal): we could align the y/u/v planes and adjust stride.
  27844 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = mem
  27845 	mem = mem + uintptr(y_size)
  27846 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = mem
  27847 	mem = mem + uintptr(uv_size)
  27848 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = mem
  27849 	mem = mem + uintptr(uv_size)
  27850 	if a_size > uint64(0) {
  27851 		(*WebPPicture)(unsafe.Pointer(picture)).Fa = mem
  27852 		mem = mem + uintptr(a_size)
  27853 	}
  27854 	_ = mem // makes the static analyzer happy
  27855 	return int32(1)
  27856 }
  27857 
  27858 func WebPPictureAlloc(tls *libc.TLS, picture uintptr) (r int32) {
  27859 	if picture != libc.UintptrFromInt32(0) {
  27860 		WebPPictureFree(tls, picture) // erase previous buffer
  27861 		if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  27862 			return WebPPictureAllocYUVA(tls, picture)
  27863 		} else {
  27864 			return WebPPictureAllocARGB(tls, picture)
  27865 		}
  27866 	}
  27867 	return int32(1)
  27868 }
  27869 
  27870 func WebPPictureFree(tls *libc.TLS, picture uintptr) {
  27871 	if picture != libc.UintptrFromInt32(0) {
  27872 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  27873 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  27874 		WebPPictureResetBuffers(tls, picture)
  27875 	}
  27876 }
  27877 
  27878 //------------------------------------------------------------------------------
  27879 // WebPMemoryWriter: Write-to-memory
  27880 
  27881 func WebPMemoryWriterInit(tls *libc.TLS, writer uintptr) {
  27882 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem = libc.UintptrFromInt32(0)
  27883 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fsize = uint64(0)
  27884 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmax_size = uint64(0)
  27885 }
  27886 
  27887 func WebPMemoryWrite(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  27888 	var new_mem, w uintptr
  27889 	var next_max_size, next_size uint64_t
  27890 	_, _, _, _ = new_mem, next_max_size, next_size, w
  27891 	w = (*WebPPicture)(unsafe.Pointer(picture)).Fcustom_ptr
  27892 	if w == libc.UintptrFromInt32(0) {
  27893 		return int32(1)
  27894 	}
  27895 	next_size = (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize + data_size
  27896 	if next_size > (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size {
  27897 		next_max_size = uint64(2) * (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size
  27898 		if next_max_size < next_size {
  27899 			next_max_size = next_size
  27900 		}
  27901 		if next_max_size < uint64(8192) {
  27902 			next_max_size = uint64(8192)
  27903 		}
  27904 		new_mem = WebPSafeMalloc(tls, next_max_size, uint64(1))
  27905 		if new_mem == libc.UintptrFromInt32(0) {
  27906 			return 0
  27907 		}
  27908 		if (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize > uint64(0) {
  27909 			libc.Xmemcpy(tls, new_mem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize)
  27910 		}
  27911 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem)
  27912 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem = new_mem
  27913 		// down-cast is ok, thanks to WebPSafeMalloc
  27914 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size = next_max_size
  27915 	}
  27916 	if data_size > uint64(0) {
  27917 		libc.Xmemcpy(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem+uintptr((*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize), data, data_size)
  27918 		**(**size_t)(__ccgo_up(w + 8)) += data_size
  27919 	}
  27920 	return int32(1)
  27921 }
  27922 
  27923 func WebPMemoryWriterClear(tls *libc.TLS, writer uintptr) {
  27924 	if writer != libc.UintptrFromInt32(0) {
  27925 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem)
  27926 		WebPMemoryWriterInit(tls, writer)
  27927 	}
  27928 }
  27929 
  27930 //------------------------------------------------------------------------------
  27931 // Simplest high-level calls:
  27932 
  27933 type Importer = uintptr
  27934 
  27935 func Encode(tls *libc.TLS, rgba uintptr, width int32, height int32, stride int32, __ccgo_fp_import Importer, quality_factor float32, lossless int32, output uintptr) (r size_t) {
  27936 	bp := tls.Alloc(416)
  27937 	defer tls.Free(416)
  27938 	var ok, v1, v3 int32
  27939 	var v5 bool
  27940 	var _ /* config at bp+256 */ WebPConfig
  27941 	var _ /* pic at bp+0 */ WebPPicture
  27942 	var _ /* wrt at bp+376 */ WebPMemoryWriter
  27943 	_, _, _, _ = ok, v1, v3, v5
  27944 	if output == libc.UintptrFromInt32(0) {
  27945 		return uint64(0)
  27946 	}
  27947 	v1 = WebPConfigInitInternal(tls, bp+256, int32(WEBP_PRESET_DEFAULT), quality_factor, int32(WEBP_ENCODER_ABI_VERSION))
  27948 	goto _2
  27949 _2:
  27950 	;
  27951 	if v5 = !(v1 != 0); !v5 {
  27952 		v3 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  27953 		goto _4
  27954 	_4:
  27955 	}
  27956 	if v5 || !(v3 != 0) {
  27957 		return uint64(0) // shouldn't happen, except if system installation is broken
  27958 	}
  27959 	(**(**WebPConfig)(__ccgo_up(bp + 256))).Flossless = libc.BoolInt32(!!(lossless != 0))
  27960 	(**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb = libc.BoolInt32(!!(lossless != 0))
  27961 	(**(**WebPPicture)(__ccgo_up(bp))).Fwidth = width
  27962 	(**(**WebPPicture)(__ccgo_up(bp))).Fheight = height
  27963 	(**(**WebPPicture)(__ccgo_up(bp))).Fwriter = __ccgo_fp(WebPMemoryWrite)
  27964 	(**(**WebPPicture)(__ccgo_up(bp))).Fcustom_ptr = bp + 376
  27965 	WebPMemoryWriterInit(tls, bp+376)
  27966 	ok = libc.BoolInt32((*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_import})))(tls, bp, rgba, stride) != 0 && WebPEncode(tls, bp+256, bp) != 0)
  27967 	WebPPictureFree(tls, bp)
  27968 	if !(ok != 0) {
  27969 		WebPMemoryWriterClear(tls, bp+376)
  27970 		**(**uintptr)(__ccgo_up(output)) = libc.UintptrFromInt32(0)
  27971 		return uint64(0)
  27972 	}
  27973 	**(**uintptr)(__ccgo_up(output)) = (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fmem
  27974 	return (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fsize
  27975 }
  27976 
  27977 func WebPEncodeRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  27978 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), q, 0, out)
  27979 }
  27980 
  27981 func WebPEncodeRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  27982 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), q, 0, out)
  27983 }
  27984 
  27985 func WebPEncodeBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  27986 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), q, 0, out)
  27987 }
  27988 
  27989 func WebPEncodeBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  27990 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), q, 0, out)
  27991 }
  27992 
  27993 func WebPEncodeLosslessRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  27994 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), float32(70), int32(1), out)
  27995 }
  27996 
  27997 func WebPEncodeLosslessRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  27998 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), float32(70), int32(1), out)
  27999 }
  28000 
  28001 func WebPEncodeLosslessBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28002 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), float32(70), int32(1), out)
  28003 }
  28004 
  28005 func WebPEncodeLosslessBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28006 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), float32(70), int32(1), out)
  28007 }
  28008 
  28009 //------------------------------------------------------------------------------
  28010 
  28011 // Copyright 2012 Google Inc. All Rights Reserved.
  28012 //
  28013 // Use of this source code is governed by a BSD-style license
  28014 // that can be found in the COPYING file in the root of the source
  28015 // tree. An additional intellectual property rights grant can be found
  28016 // in the file PATENTS. All contributing project authors may
  28017 // be found in the AUTHORS file in the root of the source tree.
  28018 // -----------------------------------------------------------------------------
  28019 //
  28020 // Misc. common utility functions
  28021 //
  28022 // Authors: Skal (pascal.massimino@gmail.com)
  28023 //          Urvang (urvang@google.com)
  28024 
  28025 type AccumulateFunc = uintptr
  28026 
  28027 //------------------------------------------------------------------------------
  28028 // local-min distortion
  28029 //
  28030 // For every pixel in the *reference* picture, we search for the local best
  28031 // match in the compressed image. This is not a symmetrical measure.
  28032 
  28033 func AccumulateLSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28034 	var best_sse, diff, sse, total_sse, value float64
  28035 	var i, j, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6 int32
  28036 	var s uintptr
  28037 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_sse, diff, i, j, s, sse, total_sse, value, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6
  28038 	total_sse = float64(0)
  28039 	y = 0
  28040 	for {
  28041 		if !(y < h) {
  28042 			break
  28043 		}
  28044 		if y-int32(2) < 0 {
  28045 			v2 = 0
  28046 		} else {
  28047 			v2 = y - int32(2)
  28048 		}
  28049 		y_0 = v2
  28050 		if y+int32(2)+int32(1) >= h {
  28051 			v3 = h
  28052 		} else {
  28053 			v3 = y + int32(2) + int32(1)
  28054 		}
  28055 		y_1 = v3
  28056 		x = 0
  28057 		for {
  28058 			if !(x < w) {
  28059 				break
  28060 			}
  28061 			if x-int32(2) < 0 {
  28062 				v5 = 0
  28063 			} else {
  28064 				v5 = x - int32(2)
  28065 			}
  28066 			x_0 = v5
  28067 			if x+int32(2)+int32(1) >= w {
  28068 				v6 = w
  28069 			} else {
  28070 				v6 = x + int32(2) + int32(1)
  28071 			}
  28072 			x_1 = v6
  28073 			best_sse = float64(libc.Float64FromFloat64(255) * libc.Float64FromFloat64(255))
  28074 			value = float64(**(**uint8_t)(__ccgo_up(ref + uintptr(y*ref_stride+x))))
  28075 			j = y_0
  28076 			for {
  28077 				if !(j < y_1) {
  28078 					break
  28079 				}
  28080 				s = src + uintptr(j*src_stride)
  28081 				i = x_0
  28082 				for {
  28083 					if !(i < x_1) {
  28084 						break
  28085 					}
  28086 					diff = float64(**(**uint8_t)(__ccgo_up(s + uintptr(i)))) - value
  28087 					sse = float64(diff * diff)
  28088 					if sse < best_sse {
  28089 						best_sse = sse
  28090 					}
  28091 					goto _8
  28092 				_8:
  28093 					;
  28094 					i = i + 1
  28095 				}
  28096 				goto _7
  28097 			_7:
  28098 				;
  28099 				j = j + 1
  28100 			}
  28101 			total_sse = total_sse + best_sse
  28102 			goto _4
  28103 		_4:
  28104 			;
  28105 			x = x + 1
  28106 		}
  28107 		goto _1
  28108 	_1:
  28109 		;
  28110 		y = y + 1
  28111 	}
  28112 	return total_sse
  28113 }
  28114 
  28115 func AccumulateSSE(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28116 	var total_sse float64
  28117 	var y int32
  28118 	_, _ = total_sse, y
  28119 	total_sse = float64(0)
  28120 	y = 0
  28121 	for {
  28122 		if !(y < h) {
  28123 			break
  28124 		}
  28125 		total_sse = total_sse + float64((*(*func(*libc.TLS, uintptr, uintptr, int32) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8AccumulateSSE})))(tls, src, ref, w))
  28126 		src = src + uintptr(src_stride)
  28127 		ref = ref + uintptr(ref_stride)
  28128 		goto _1
  28129 	_1:
  28130 		;
  28131 		y = y + 1
  28132 	}
  28133 	return total_sse
  28134 }
  28135 
  28136 //------------------------------------------------------------------------------
  28137 
  28138 func AccumulateSSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28139 	var h0, h1, off1, off2, w0, w1, x, y, v1, v2 int32
  28140 	var sum float64
  28141 	_, _, _, _, _, _, _, _, _, _, _ = h0, h1, off1, off2, sum, w0, w1, x, y, v1, v2
  28142 	if w < int32(VP8_SSIM_KERNEL) {
  28143 		v1 = w
  28144 	} else {
  28145 		v1 = int32(VP8_SSIM_KERNEL)
  28146 	}
  28147 	w0 = v1
  28148 	w1 = w - int32(VP8_SSIM_KERNEL) - int32(1)
  28149 	if h < int32(VP8_SSIM_KERNEL) {
  28150 		v2 = h
  28151 	} else {
  28152 		v2 = int32(VP8_SSIM_KERNEL)
  28153 	}
  28154 	h0 = v2
  28155 	h1 = h - int32(VP8_SSIM_KERNEL) - int32(1)
  28156 	sum = float64(0)
  28157 	y = 0
  28158 	for {
  28159 		if !(y < h0) {
  28160 			break
  28161 		}
  28162 		x = 0
  28163 		for {
  28164 			if !(x < w) {
  28165 				break
  28166 			}
  28167 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, src, src_stride, ref, ref_stride, x, y, w, h)
  28168 			goto _4
  28169 		_4:
  28170 			;
  28171 			x = x + 1
  28172 		}
  28173 		goto _3
  28174 	_3:
  28175 		;
  28176 		y = y + 1
  28177 	}
  28178 	for {
  28179 		if !(y < h1) {
  28180 			break
  28181 		}
  28182 		x = 0
  28183 		for {
  28184 			if !(x < w0) {
  28185 				break
  28186 			}
  28187 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, src, src_stride, ref, ref_stride, x, y, w, h)
  28188 			goto _6
  28189 		_6:
  28190 			;
  28191 			x = x + 1
  28192 		}
  28193 		for {
  28194 			if !(x < w1) {
  28195 				break
  28196 			}
  28197 			off1 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*src_stride
  28198 			off2 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*ref_stride
  28199 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGet})))(tls, src+uintptr(off1), src_stride, ref+uintptr(off2), ref_stride)
  28200 			goto _7
  28201 		_7:
  28202 			;
  28203 			x = x + 1
  28204 		}
  28205 		for {
  28206 			if !(x < w) {
  28207 				break
  28208 			}
  28209 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, src, src_stride, ref, ref_stride, x, y, w, h)
  28210 			goto _8
  28211 		_8:
  28212 			;
  28213 			x = x + 1
  28214 		}
  28215 		goto _5
  28216 	_5:
  28217 		;
  28218 		y = y + 1
  28219 	}
  28220 	for {
  28221 		if !(y < h) {
  28222 			break
  28223 		}
  28224 		x = 0
  28225 		for {
  28226 			if !(x < w) {
  28227 				break
  28228 			}
  28229 			sum = sum + (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{VP8SSIMGetClipped})))(tls, src, src_stride, ref, ref_stride, x, y, w, h)
  28230 			goto _10
  28231 		_10:
  28232 			;
  28233 			x = x + 1
  28234 		}
  28235 		goto _9
  28236 	_9:
  28237 		;
  28238 		y = y + 1
  28239 	}
  28240 	return sum
  28241 }
  28242 
  28243 //------------------------------------------------------------------------------
  28244 // Distortion
  28245 
  28246 // C documentation
  28247 //
  28248 //	// Max value returned in case of exact similarity.
  28249 var kMinDistortion_dB = float64(99)
  28250 
  28251 func GetPSNR1(tls *libc.TLS, v float64, size float64) (r float64) {
  28252 	var v1 float64
  28253 	_ = v1
  28254 	if v > float64(0) && size > float64(0) {
  28255 		v1 = float64(-libc.Float64FromFloat64(4.3429448) * libc.Xlog(tls, v/float64(float64(size*libc.Float64FromInt32(255))*float64(255))))
  28256 	} else {
  28257 		v1 = kMinDistortion_dB
  28258 	}
  28259 	return v1
  28260 }
  28261 
  28262 func GetLogSSIM(tls *libc.TLS, v float64, size float64) (r float64) {
  28263 	var v1 float64
  28264 	_ = v1
  28265 	if size > float64(0) {
  28266 		v1 = v / size
  28267 	} else {
  28268 		v1 = float64(1)
  28269 	}
  28270 	v = v1
  28271 	if v < float64(1) {
  28272 		v1 = float64(-libc.Float64FromFloat64(10) * libc.Xlog10(tls, float64(1)-v))
  28273 	} else {
  28274 		v1 = kMinDistortion_dB
  28275 	}
  28276 	return v1
  28277 }
  28278 
  28279 func WebPPlaneDistortion(tls *libc.TLS, src uintptr, src_stride size_t, ref uintptr, ref_stride size_t, width int32, height int32, x_step size_t, type1 int32, distortion uintptr, result uintptr) (r int32) {
  28280 	var allocated, tmp1, tmp2, v1, v2 uintptr
  28281 	var metric AccumulateFunc
  28282 	var x, y int32
  28283 	var v5 float32
  28284 	_, _, _, _, _, _, _, _, _ = allocated, metric, tmp1, tmp2, x, y, v1, v2, v5
  28285 	allocated = libc.UintptrFromInt32(0)
  28286 	if type1 == 0 {
  28287 		v1 = __ccgo_fp(AccumulateSSE)
  28288 	} else {
  28289 		if type1 == int32(1) {
  28290 			v2 = __ccgo_fp(AccumulateSSIM)
  28291 		} else {
  28292 			v2 = __ccgo_fp(AccumulateLSIM)
  28293 		}
  28294 		v1 = v2
  28295 	}
  28296 	metric = v1
  28297 	if src == libc.UintptrFromInt32(0) || ref == libc.UintptrFromInt32(0) || src_stride < x_step*libc.Uint64FromInt32(width) || ref_stride < x_step*libc.Uint64FromInt32(width) || result == libc.UintptrFromInt32(0) || distortion == libc.UintptrFromInt32(0) {
  28298 		return 0
  28299 	}
  28300 	VP8SSIMDspInit(tls)
  28301 	if x_step != uint64(1) {
  28302 		allocated = WebPSafeMalloc(tls, uint64(uint64(2)*libc.Uint64FromInt32(width)*libc.Uint64FromInt32(height)), uint64(1))
  28303 		if allocated == libc.UintptrFromInt32(0) {
  28304 			return 0
  28305 		}
  28306 		tmp1 = allocated
  28307 		tmp2 = tmp1 + uintptr(libc.Uint64FromInt32(width)*libc.Uint64FromInt32(height))
  28308 		y = 0
  28309 		for {
  28310 			if !(y < height) {
  28311 				break
  28312 			}
  28313 			x = 0
  28314 			for {
  28315 				if !(x < width) {
  28316 					break
  28317 				}
  28318 				**(**uint8_t)(__ccgo_up(tmp1 + uintptr(x+y*width))) = **(**uint8_t)(__ccgo_up(src + uintptr(libc.Uint64FromInt32(x)*x_step+libc.Uint64FromInt32(y)*src_stride)))
  28319 				**(**uint8_t)(__ccgo_up(tmp2 + uintptr(x+y*width))) = **(**uint8_t)(__ccgo_up(ref + uintptr(libc.Uint64FromInt32(x)*x_step+libc.Uint64FromInt32(y)*ref_stride)))
  28320 				goto _4
  28321 			_4:
  28322 				;
  28323 				x = x + 1
  28324 			}
  28325 			goto _3
  28326 		_3:
  28327 			;
  28328 			y = y + 1
  28329 		}
  28330 		src = tmp1
  28331 		ref = tmp2
  28332 	}
  28333 	**(**float32)(__ccgo_up(distortion)) = float32((*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) float64)(unsafe.Pointer(&struct{ uintptr }{metric})))(tls, src, width, ref, width, width, height))
  28334 	WebPSafeFree(tls, allocated)
  28335 	if type1 == int32(1) {
  28336 		v5 = float32(GetLogSSIM(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28337 	} else {
  28338 		v5 = float32(GetPSNR1(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28339 	}
  28340 	**(**float32)(__ccgo_up(result)) = v5
  28341 	return int32(1)
  28342 }
  28343 
  28344 func WebPPictureDistortion(tls *libc.TLS, src uintptr, ref uintptr, type1 int32, results uintptr) (r int32) {
  28345 	bp := tls.Alloc(528)
  28346 	defer tls.Free(528)
  28347 	var c, h, offset, ok, w, v1, v3 int32
  28348 	var stride0, stride1 size_t
  28349 	var total_distortion, total_size float64
  28350 	var v5 bool
  28351 	var v7 float32
  28352 	var _ /* distortion at bp+512 */ float32
  28353 	var _ /* p0 at bp+0 */ WebPPicture
  28354 	var _ /* p1 at bp+256 */ WebPPicture
  28355 	_, _, _, _, _, _, _, _, _, _, _, _, _ = c, h, offset, ok, stride0, stride1, total_distortion, total_size, w, v1, v3, v5, v7
  28356 	ok = 0
  28357 	total_size = float64(0)
  28358 	total_distortion = float64(0)
  28359 	if src == libc.UintptrFromInt32(0) || ref == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(src)).Fwidth != (*WebPPicture)(unsafe.Pointer(ref)).Fwidth || (*WebPPicture)(unsafe.Pointer(src)).Fheight != (*WebPPicture)(unsafe.Pointer(ref)).Fheight || results == libc.UintptrFromInt32(0) {
  28360 		return 0
  28361 	}
  28362 	VP8SSIMDspInit(tls)
  28363 	v1 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28364 	goto _2
  28365 _2:
  28366 	;
  28367 	if v5 = !(v1 != 0); !v5 {
  28368 		v3 = WebPPictureInitInternal(tls, bp+256, int32(WEBP_ENCODER_ABI_VERSION))
  28369 		goto _4
  28370 	_4:
  28371 	}
  28372 	if v5 || !(v3 != 0) {
  28373 		return 0
  28374 	}
  28375 	w = (*WebPPicture)(unsafe.Pointer(src)).Fwidth
  28376 	h = (*WebPPicture)(unsafe.Pointer(src)).Fheight
  28377 	if !(WebPPictureView(tls, src, 0, 0, w, h, bp) != 0) {
  28378 		goto Error
  28379 	}
  28380 	if !(WebPPictureView(tls, ref, 0, 0, w, h, bp+256) != 0) {
  28381 		goto Error
  28382 	}
  28383 	// We always measure distortion in ARGB space.
  28384 	if (**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp) != 0) {
  28385 		goto Error
  28386 	}
  28387 	if (**(**WebPPicture)(__ccgo_up(bp + 256))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp+256) != 0) {
  28388 		goto Error
  28389 	}
  28390 	c = 0
  28391 	for {
  28392 		if !(c < int32(4)) {
  28393 			break
  28394 		}
  28395 		stride0 = uint64(4) * libc.Uint64FromInt32((**(**WebPPicture)(__ccgo_up(bp))).Fargb_stride)
  28396 		stride1 = uint64(4) * libc.Uint64FromInt32((**(**WebPPicture)(__ccgo_up(bp + 256))).Fargb_stride)
  28397 		// results are reported as BGRA
  28398 		offset = c ^ 0
  28399 		if !(WebPPlaneDistortion(tls, (**(**WebPPicture)(__ccgo_up(bp))).Fargb+uintptr(offset), stride0, (**(**WebPPicture)(__ccgo_up(bp + 256))).Fargb+uintptr(offset), stride1, w, h, uint64(4), type1, bp+512, results+uintptr(c)*4) != 0) {
  28400 			goto Error
  28401 		}
  28402 		total_distortion = total_distortion + float64(**(**float32)(__ccgo_up(bp + 512)))
  28403 		total_size = total_size + float64(w*h)
  28404 		goto _6
  28405 	_6:
  28406 		;
  28407 		c = c + 1
  28408 	}
  28409 	if type1 == int32(1) {
  28410 		v7 = float32(GetLogSSIM(tls, total_distortion, total_size))
  28411 	} else {
  28412 		v7 = float32(GetPSNR1(tls, total_distortion, total_size))
  28413 	}
  28414 	**(**float32)(__ccgo_up(results + 4*4)) = v7
  28415 	ok = int32(1)
  28416 	goto Error
  28417 Error:
  28418 	;
  28419 	WebPPictureFree(tls, bp)
  28420 	WebPPictureFree(tls, bp+256)
  28421 	return ok
  28422 }
  28423 
  28424 //------------------------------------------------------------------------------
  28425 
  28426 // Copyright 2012 Google Inc. All Rights Reserved.
  28427 //
  28428 // Use of this source code is governed by a BSD-style license
  28429 // that can be found in the COPYING file in the root of the source
  28430 // tree. An additional intellectual property rights grant can be found
  28431 // in the file PATENTS. All contributing project authors may
  28432 // be found in the AUTHORS file in the root of the source tree.
  28433 // -----------------------------------------------------------------------------
  28434 //
  28435 // Misc. common utility functions
  28436 //
  28437 // Authors: Skal (pascal.massimino@gmail.com)
  28438 //          Urvang (urvang@google.com)
  28439 
  28440 // C documentation
  28441 //
  28442 //	// Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
  28443 //	// into 'dst'. Mark 'dst' as not owning any memory.
  28444 func PictureGrabSpecs(tls *libc.TLS, src uintptr, dst uintptr) {
  28445 	**(**WebPPicture)(__ccgo_up(dst)) = **(**WebPPicture)(__ccgo_up(src))
  28446 	WebPPictureResetBuffers(tls, dst)
  28447 }
  28448 
  28449 //------------------------------------------------------------------------------
  28450 
  28451 // C documentation
  28452 //
  28453 //	// Adjust top-left corner to chroma sample position.
  28454 func SnapTopLeftPosition(tls *libc.TLS, pic uintptr, left uintptr, top uintptr) {
  28455 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28456 		**(**int32)(__ccgo_up(left)) &= ^libc.Int32FromInt32(1)
  28457 		**(**int32)(__ccgo_up(top)) &= ^libc.Int32FromInt32(1)
  28458 	}
  28459 }
  28460 
  28461 // C documentation
  28462 //
  28463 //	// Adjust top-left corner and verify that the sub-rectangle is valid.
  28464 func AdjustAndCheckRectangle(tls *libc.TLS, pic uintptr, left uintptr, top uintptr, width int32, height int32) (r int32) {
  28465 	SnapTopLeftPosition(tls, pic, left, top)
  28466 	if **(**int32)(__ccgo_up(left)) < 0 || **(**int32)(__ccgo_up(top)) < 0 {
  28467 		return 0
  28468 	}
  28469 	if width <= 0 || height <= 0 {
  28470 		return 0
  28471 	}
  28472 	if **(**int32)(__ccgo_up(left))+width > (*WebPPicture)(unsafe.Pointer(pic)).Fwidth {
  28473 		return 0
  28474 	}
  28475 	if **(**int32)(__ccgo_up(top))+height > (*WebPPicture)(unsafe.Pointer(pic)).Fheight {
  28476 		return 0
  28477 	}
  28478 	return int32(1)
  28479 }
  28480 
  28481 func WebPPictureCopy(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  28482 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28483 		return 0
  28484 	}
  28485 	if src == dst {
  28486 		return int32(1)
  28487 	}
  28488 	PictureGrabSpecs(tls, src, dst)
  28489 	if !(WebPPictureAlloc(tls, dst) != 0) {
  28490 		return 0
  28491 	}
  28492 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28493 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(src)).Fy, (*WebPPicture)(unsafe.Pointer(src)).Fy_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fy, (*WebPPicture)(unsafe.Pointer(dst)).Fy_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fwidth, (*WebPPicture)(unsafe.Pointer(dst)).Fheight)
  28494 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(src)).Fu, (*WebPPicture)(unsafe.Pointer(src)).Fuv_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fu, (*WebPPicture)(unsafe.Pointer(dst)).Fuv_stride, ((*WebPPicture)(unsafe.Pointer(dst)).Fwidth+int32(1))>>int32(1), ((*WebPPicture)(unsafe.Pointer(dst)).Fheight+int32(1))>>int32(1))
  28495 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(src)).Fv, (*WebPPicture)(unsafe.Pointer(src)).Fuv_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fv, (*WebPPicture)(unsafe.Pointer(dst)).Fuv_stride, ((*WebPPicture)(unsafe.Pointer(dst)).Fwidth+int32(1))>>int32(1), ((*WebPPicture)(unsafe.Pointer(dst)).Fheight+int32(1))>>int32(1))
  28496 		if (*WebPPicture)(unsafe.Pointer(dst)).Fa != libc.UintptrFromInt32(0) {
  28497 			WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(src)).Fa, (*WebPPicture)(unsafe.Pointer(src)).Fa_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fa, (*WebPPicture)(unsafe.Pointer(dst)).Fa_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fwidth, (*WebPPicture)(unsafe.Pointer(dst)).Fheight)
  28498 		}
  28499 	} else {
  28500 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(src)).Fargb, int32(4)*(*WebPPicture)(unsafe.Pointer(src)).Fargb_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fargb, int32(4)*(*WebPPicture)(unsafe.Pointer(dst)).Fargb_stride, int32(4)*(*WebPPicture)(unsafe.Pointer(dst)).Fwidth, (*WebPPicture)(unsafe.Pointer(dst)).Fheight)
  28501 	}
  28502 	return int32(1)
  28503 }
  28504 
  28505 func WebPPictureIsView(tls *libc.TLS, picture uintptr) (r int32) {
  28506 	if picture == libc.UintptrFromInt32(0) {
  28507 		return 0
  28508 	}
  28509 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  28510 		return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ == libc.UintptrFromInt32(0))
  28511 	}
  28512 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ == libc.UintptrFromInt32(0))
  28513 }
  28514 
  28515 func WebPPictureView(tls *libc.TLS, src uintptr, _left int32, _top int32, width int32, height int32, dst uintptr) (r int32) {
  28516 	bp := tls.Alloc(16)
  28517 	defer tls.Free(16)
  28518 	*(*int32)(unsafe.Pointer(bp)) = _left
  28519 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28520 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28521 		return 0
  28522 	}
  28523 	// verify rectangle position.
  28524 	if !(AdjustAndCheckRectangle(tls, src, bp, bp+4, width, height) != 0) {
  28525 		return 0
  28526 	}
  28527 	if src != dst { // beware of aliasing! We don't want to leak 'memory_'.
  28528 		PictureGrabSpecs(tls, src, dst)
  28529 	}
  28530 	(*WebPPicture)(unsafe.Pointer(dst)).Fwidth = width
  28531 	(*WebPPicture)(unsafe.Pointer(dst)).Fheight = height
  28532 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28533 		(*WebPPicture)(unsafe.Pointer(dst)).Fy = (*WebPPicture)(unsafe.Pointer(src)).Fy + uintptr(**(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(src)).Fy_stride) + uintptr(**(**int32)(__ccgo_up(bp)))
  28534 		(*WebPPicture)(unsafe.Pointer(dst)).Fu = (*WebPPicture)(unsafe.Pointer(src)).Fu + uintptr(**(**int32)(__ccgo_up(bp + 4))>>int32(1)*(*WebPPicture)(unsafe.Pointer(src)).Fuv_stride) + uintptr(**(**int32)(__ccgo_up(bp))>>libc.Int32FromInt32(1))
  28535 		(*WebPPicture)(unsafe.Pointer(dst)).Fv = (*WebPPicture)(unsafe.Pointer(src)).Fv + uintptr(**(**int32)(__ccgo_up(bp + 4))>>int32(1)*(*WebPPicture)(unsafe.Pointer(src)).Fuv_stride) + uintptr(**(**int32)(__ccgo_up(bp))>>libc.Int32FromInt32(1))
  28536 		(*WebPPicture)(unsafe.Pointer(dst)).Fy_stride = (*WebPPicture)(unsafe.Pointer(src)).Fy_stride
  28537 		(*WebPPicture)(unsafe.Pointer(dst)).Fuv_stride = (*WebPPicture)(unsafe.Pointer(src)).Fuv_stride
  28538 		if (*WebPPicture)(unsafe.Pointer(src)).Fa != libc.UintptrFromInt32(0) {
  28539 			(*WebPPicture)(unsafe.Pointer(dst)).Fa = (*WebPPicture)(unsafe.Pointer(src)).Fa + uintptr(**(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(src)).Fa_stride) + uintptr(**(**int32)(__ccgo_up(bp)))
  28540 			(*WebPPicture)(unsafe.Pointer(dst)).Fa_stride = (*WebPPicture)(unsafe.Pointer(src)).Fa_stride
  28541 		}
  28542 	} else {
  28543 		(*WebPPicture)(unsafe.Pointer(dst)).Fargb = (*WebPPicture)(unsafe.Pointer(src)).Fargb + uintptr(**(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(src)).Fargb_stride)*4 + uintptr(**(**int32)(__ccgo_up(bp)))*4
  28544 		(*WebPPicture)(unsafe.Pointer(dst)).Fargb_stride = (*WebPPicture)(unsafe.Pointer(src)).Fargb_stride
  28545 	}
  28546 	return int32(1)
  28547 }
  28548 
  28549 //------------------------------------------------------------------------------
  28550 // Picture cropping
  28551 
  28552 func WebPPictureCrop(tls *libc.TLS, pic uintptr, _left int32, _top int32, width int32, height int32) (r int32) {
  28553 	bp := tls.Alloc(272)
  28554 	defer tls.Free(272)
  28555 	*(*int32)(unsafe.Pointer(bp)) = _left
  28556 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28557 	var a_offset, uv_offset, y_offset int32
  28558 	var src uintptr
  28559 	var _ /* tmp at bp+8 */ WebPPicture
  28560 	_, _, _, _ = a_offset, src, uv_offset, y_offset
  28561 	if pic == libc.UintptrFromInt32(0) {
  28562 		return 0
  28563 	}
  28564 	if !(AdjustAndCheckRectangle(tls, pic, bp, bp+4, width, height) != 0) {
  28565 		return 0
  28566 	}
  28567 	PictureGrabSpecs(tls, pic, bp+8)
  28568 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = width
  28569 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = height
  28570 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28571 		return WebPEncodingSetError(tls, pic, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28572 	}
  28573 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28574 		y_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride + **(**int32)(__ccgo_up(bp))
  28575 		uv_offset = **(**int32)(__ccgo_up(bp + 4))/int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride + **(**int32)(__ccgo_up(bp))/int32(2)
  28576 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fy+uintptr(y_offset), (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fy, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fy_stride, width, height)
  28577 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fu+uintptr(uv_offset), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fu, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fuv_stride, (width+int32(1))>>int32(1), (height+int32(1))>>int32(1))
  28578 		WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fv+uintptr(uv_offset), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fv, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fuv_stride, (width+int32(1))>>int32(1), (height+int32(1))>>int32(1))
  28579 		if (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa != libc.UintptrFromInt32(0) {
  28580 			a_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fa_stride + **(**int32)(__ccgo_up(bp))
  28581 			WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fa+uintptr(a_offset), (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa_stride, width, height)
  28582 		}
  28583 	} else {
  28584 		src = (*WebPPicture)(unsafe.Pointer(pic)).Fargb + uintptr(**(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4 + uintptr(**(**int32)(__ccgo_up(bp)))*4
  28585 		WebPCopyPlane(tls, src, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride*int32(4), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fargb, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fargb_stride*int32(4), width*int32(4), height)
  28586 	}
  28587 	WebPPictureFree(tls, pic)
  28588 	**(**WebPPicture)(__ccgo_up(pic)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28589 	return int32(1)
  28590 }
  28591 
  28592 //------------------------------------------------------------------------------
  28593 // Simple picture rescaler
  28594 
  28595 func RescalePlane(tls *libc.TLS, src uintptr, src_width int32, src_height int32, src_stride int32, dst uintptr, dst_width int32, dst_height int32, dst_stride int32, work uintptr, num_channels int32) (r int32) {
  28596 	bp := tls.Alloc(112)
  28597 	defer tls.Free(112)
  28598 	var y int32
  28599 	var _ /* rescaler at bp+0 */ WebPRescaler
  28600 	_ = y
  28601 	y = 0
  28602 	if !(WebPRescalerInit(tls, bp, src_width, src_height, dst, dst_width, dst_height, dst_stride, num_channels, work) != 0) {
  28603 		return 0
  28604 	}
  28605 	for y < src_height {
  28606 		y = y + WebPRescalerImport(tls, bp, src_height-y, src+uintptr(y*src_stride), src_stride)
  28607 		WebPRescalerExport(tls, bp)
  28608 	}
  28609 	return int32(1)
  28610 }
  28611 
  28612 func AlphaMultiplyARGB(tls *libc.TLS, pic uintptr, inverse int32) {
  28613 	WebPMultARGBRows(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb, libc.Int32FromUint64(libc.Uint64FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*uint64(4)), (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight, inverse)
  28614 }
  28615 
  28616 func AlphaMultiplyY(tls *libc.TLS, pic uintptr, inverse int32) {
  28617 	if (*WebPPicture)(unsafe.Pointer(pic)).Fa != libc.UintptrFromInt32(0) {
  28618 		WebPMultRows(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fy, (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (*WebPPicture)(unsafe.Pointer(pic)).Fa, (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight, inverse)
  28619 	}
  28620 }
  28621 
  28622 func WebPPictureRescale(tls *libc.TLS, picture uintptr, _width int32, _height int32) (r int32) {
  28623 	bp := tls.Alloc(272)
  28624 	defer tls.Free(272)
  28625 	*(*int32)(unsafe.Pointer(bp)) = _width
  28626 	*(*int32)(unsafe.Pointer(bp + 4)) = _height
  28627 	var prev_height, prev_width int32
  28628 	var work uintptr
  28629 	var _ /* tmp at bp+8 */ WebPPicture
  28630 	_, _, _ = prev_height, prev_width, work
  28631 	if picture == libc.UintptrFromInt32(0) {
  28632 		return 0
  28633 	}
  28634 	prev_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28635 	prev_height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28636 	if !(WebPRescalerGetScaledDimensions(tls, prev_width, prev_height, bp, bp+4) != 0) {
  28637 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28638 	}
  28639 	PictureGrabSpecs(tls, picture, bp+8)
  28640 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = **(**int32)(__ccgo_up(bp))
  28641 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = **(**int32)(__ccgo_up(bp + 4))
  28642 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28643 		return WebPEncodingSetError(tls, picture, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28644 	}
  28645 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28646 		work = WebPSafeMalloc(tls, uint64(uint64(2)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))), uint64(4))
  28647 		if work == libc.UintptrFromInt32(0) {
  28648 			WebPPictureFree(tls, bp+8)
  28649 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28650 		}
  28651 		// If present, we need to rescale alpha first (for AlphaMultiplyY).
  28652 		if (*WebPPicture)(unsafe.Pointer(picture)).Fa != libc.UintptrFromInt32(0) {
  28653 			WebPInitAlphaProcessing(tls)
  28654 			if !(RescalePlane(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fa, prev_width, prev_height, (*WebPPicture)(unsafe.Pointer(picture)).Fa_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa_stride, work, int32(1)) != 0) {
  28655 				return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28656 			}
  28657 		}
  28658 		// We take transparency into account on the luma plane only. That's not
  28659 		// totally exact blending, but still is a good approximation.
  28660 		AlphaMultiplyY(tls, picture, 0)
  28661 		if !(RescalePlane(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fy, prev_width, prev_height, (*WebPPicture)(unsafe.Pointer(picture)).Fy_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fy, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fy_stride, work, int32(1)) != 0) || !(RescalePlane(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fu, (prev_width+int32(1))>>int32(1), (prev_height+int32(1))>>int32(1), (*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fu, (**(**int32)(__ccgo_up(bp))+int32(1))>>int32(1), (**(**int32)(__ccgo_up(bp + 4))+int32(1))>>int32(1), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fuv_stride, work, int32(1)) != 0) || !(RescalePlane(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fv, (prev_width+int32(1))>>int32(1), (prev_height+int32(1))>>int32(1), (*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride, (**(**WebPPicture)(__ccgo_up(bp + 8))).Fv, (**(**int32)(__ccgo_up(bp))+int32(1))>>int32(1), (**(**int32)(__ccgo_up(bp + 4))+int32(1))>>int32(1), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fuv_stride, work, int32(1)) != 0) {
  28662 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28663 		}
  28664 		AlphaMultiplyY(tls, bp+8, int32(1))
  28665 	} else {
  28666 		work = WebPSafeMalloc(tls, uint64(uint64(2)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4)), uint64(4))
  28667 		if work == libc.UintptrFromInt32(0) {
  28668 			WebPPictureFree(tls, bp+8)
  28669 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28670 		}
  28671 		// In order to correctly interpolate colors, we need to apply the alpha
  28672 		// weighting first (black-matting), scale the RGB values, and remove
  28673 		// the premultiplication afterward (while preserving the alpha channel).
  28674 		WebPInitAlphaProcessing(tls)
  28675 		AlphaMultiplyARGB(tls, picture, 0)
  28676 		if !(RescalePlane(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fargb, prev_width, prev_height, (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride*int32(4), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fargb, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), (**(**WebPPicture)(__ccgo_up(bp + 8))).Fargb_stride*int32(4), work, int32(4)) != 0) {
  28677 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28678 		}
  28679 		AlphaMultiplyARGB(tls, bp+8, int32(1))
  28680 	}
  28681 	WebPPictureFree(tls, picture)
  28682 	WebPSafeFree(tls, work)
  28683 	**(**WebPPicture)(__ccgo_up(picture)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28684 	return int32(1)
  28685 }
  28686 
  28687 //------------------------------------------------------------------------------
  28688 
  28689 // Copyright 2011 Google Inc. All Rights Reserved.
  28690 //
  28691 // Use of this source code is governed by a BSD-style license
  28692 // that can be found in the COPYING file in the root of the source
  28693 // tree. An additional intellectual property rights grant can be found
  28694 // in the file PATENTS. All contributing project authors may
  28695 // be found in the AUTHORS file in the root of the source tree.
  28696 // -----------------------------------------------------------------------------
  28697 //
  28698 //   WebP encoder: main interface
  28699 //
  28700 // Author: Skal (pascal.massimino@gmail.com)
  28701 
  28702 // Copyright 2010 Google Inc. All Rights Reserved.
  28703 //
  28704 // Use of this source code is governed by a BSD-style license
  28705 // that can be found in the COPYING file in the root of the source
  28706 // tree. An additional intellectual property rights grant can be found
  28707 // in the file PATENTS. All contributing project authors may
  28708 // be found in the AUTHORS file in the root of the source tree.
  28709 // -----------------------------------------------------------------------------
  28710 //
  28711 //  Common types + memory wrappers
  28712 //
  28713 // Author: Skal (pascal.massimino@gmail.com)
  28714 
  28715 //------------------------------------------------------------------------------
  28716 // Helper: clean up fully transparent area to help compressibility.
  28717 
  28718 func IsTransparentARGBArea(tls *libc.TLS, ptr uintptr, stride int32, size int32) (r int32) {
  28719 	var x, y int32
  28720 	_, _ = x, y
  28721 	y = 0
  28722 	for {
  28723 		if !(y < size) {
  28724 			break
  28725 		}
  28726 		x = 0
  28727 		for {
  28728 			if !(x < size) {
  28729 				break
  28730 			}
  28731 			if **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))&uint32(0xff000000) != 0 {
  28732 				return 0
  28733 			}
  28734 			goto _2
  28735 		_2:
  28736 			;
  28737 			x = x + 1
  28738 		}
  28739 		ptr = ptr + uintptr(stride)*4
  28740 		goto _1
  28741 	_1:
  28742 		;
  28743 		y = y + 1
  28744 	}
  28745 	return int32(1)
  28746 }
  28747 
  28748 func Flatten(tls *libc.TLS, ptr uintptr, v int32, stride int32, size int32) {
  28749 	var y int32
  28750 	_ = y
  28751 	y = 0
  28752 	for {
  28753 		if !(y < size) {
  28754 			break
  28755 		}
  28756 		libc.Xmemset(tls, ptr, v, libc.Uint64FromInt32(size))
  28757 		ptr = ptr + uintptr(stride)
  28758 		goto _1
  28759 	_1:
  28760 		;
  28761 		y = y + 1
  28762 	}
  28763 }
  28764 
  28765 func FlattenARGB(tls *libc.TLS, ptr uintptr, v uint32_t, stride int32, size int32) {
  28766 	var x, y int32
  28767 	_, _ = x, y
  28768 	y = 0
  28769 	for {
  28770 		if !(y < size) {
  28771 			break
  28772 		}
  28773 		x = 0
  28774 		for {
  28775 			if !(x < size) {
  28776 				break
  28777 			}
  28778 			**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = v
  28779 			goto _2
  28780 		_2:
  28781 			;
  28782 			x = x + 1
  28783 		}
  28784 		ptr = ptr + uintptr(stride)*4
  28785 		goto _1
  28786 	_1:
  28787 		;
  28788 		y = y + 1
  28789 	}
  28790 }
  28791 
  28792 // C documentation
  28793 //
  28794 //	// Smoothen the luma components of transparent pixels. Return true if the whole
  28795 //	// block is transparent.
  28796 func SmoothenBlock(tls *libc.TLS, a_ptr uintptr, a_stride int32, y_ptr uintptr, y_stride int32, width int32, height int32) (r int32) {
  28797 	var alpha_ptr, luma_ptr uintptr
  28798 	var avg_u8 uint8_t
  28799 	var count, sum, x, y int32
  28800 	_, _, _, _, _, _, _ = alpha_ptr, avg_u8, count, luma_ptr, sum, x, y
  28801 	sum = 0
  28802 	count = 0
  28803 	alpha_ptr = a_ptr
  28804 	luma_ptr = y_ptr
  28805 	y = 0
  28806 	for {
  28807 		if !(y < height) {
  28808 			break
  28809 		}
  28810 		x = 0
  28811 		for {
  28812 			if !(x < width) {
  28813 				break
  28814 			}
  28815 			if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) != 0 {
  28816 				count = count + 1
  28817 				sum = sum + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))))
  28818 			}
  28819 			goto _2
  28820 		_2:
  28821 			;
  28822 			x = x + 1
  28823 		}
  28824 		alpha_ptr = alpha_ptr + uintptr(a_stride)
  28825 		luma_ptr = luma_ptr + uintptr(y_stride)
  28826 		goto _1
  28827 	_1:
  28828 		;
  28829 		y = y + 1
  28830 	}
  28831 	if count > 0 && count < width*height {
  28832 		avg_u8 = libc.Uint8FromInt32(sum / count)
  28833 		alpha_ptr = a_ptr
  28834 		luma_ptr = y_ptr
  28835 		y = 0
  28836 		for {
  28837 			if !(y < height) {
  28838 				break
  28839 			}
  28840 			x = 0
  28841 			for {
  28842 				if !(x < width) {
  28843 					break
  28844 				}
  28845 				if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) == 0 {
  28846 					**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))) = avg_u8
  28847 				}
  28848 				goto _4
  28849 			_4:
  28850 				;
  28851 				x = x + 1
  28852 			}
  28853 			alpha_ptr = alpha_ptr + uintptr(a_stride)
  28854 			luma_ptr = luma_ptr + uintptr(y_stride)
  28855 			goto _3
  28856 		_3:
  28857 			;
  28858 			y = y + 1
  28859 		}
  28860 	}
  28861 	return libc.BoolInt32(count == 0)
  28862 }
  28863 
  28864 func WebPReplaceTransparentPixels(tls *libc.TLS, pic uintptr, color uint32_t) {
  28865 	var argb uintptr
  28866 	var y, v1 int32
  28867 	_, _, _ = argb, y, v1
  28868 	if pic != libc.UintptrFromInt32(0) && (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  28869 		y = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  28870 		argb = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  28871 		color = color & uint32(0xffffff) // force alpha=0
  28872 		WebPInitAlphaProcessing(tls)
  28873 		for {
  28874 			v1 = y
  28875 			y = y - 1
  28876 			if !(v1 > 0) {
  28877 				break
  28878 			}
  28879 			(*(*func(*libc.TLS, uintptr, int32, uint32_t))(unsafe.Pointer(&struct{ uintptr }{WebPAlphaReplace})))(tls, argb, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, color)
  28880 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  28881 		}
  28882 	}
  28883 }
  28884 
  28885 func WebPCleanupTransparentArea(tls *libc.TLS, pic uintptr) {
  28886 	var a_ptr, u_ptr, v_ptr, y_ptr uintptr
  28887 	var a_stride, h, height, need_reset, need_reset1, off, sub_height, uv_stride, w, width, x, y, y_stride int32
  28888 	var argb_value uint32_t
  28889 	var values [3]int32
  28890 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_ptr, a_stride, argb_value, h, height, need_reset, need_reset1, off, sub_height, u_ptr, uv_stride, v_ptr, values, w, width, x, y, y_ptr, y_stride
  28891 	if pic == libc.UintptrFromInt32(0) {
  28892 		return
  28893 	}
  28894 	w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth / int32(8)
  28895 	h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight / int32(8)
  28896 	// note: we ignore the left-overs on right/bottom, except for SmoothenBlock().
  28897 	if (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  28898 		argb_value = uint32(0)
  28899 		y = 0
  28900 		for {
  28901 			if !(y < h) {
  28902 				break
  28903 			}
  28904 			need_reset = int32(1)
  28905 			x = 0
  28906 			for {
  28907 				if !(x < w) {
  28908 					break
  28909 				}
  28910 				off = (y*(*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride + x) * int32(8)
  28911 				if IsTransparentARGBArea(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8)) != 0 {
  28912 					if need_reset != 0 {
  28913 						argb_value = **(**uint32_t)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fargb + uintptr(off)*4))
  28914 						need_reset = 0
  28915 					}
  28916 					FlattenARGB(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, argb_value, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8))
  28917 				} else {
  28918 					need_reset = int32(1)
  28919 				}
  28920 				goto _2
  28921 			_2:
  28922 				;
  28923 				x = x + 1
  28924 			}
  28925 			goto _1
  28926 		_1:
  28927 			;
  28928 			y = y + 1
  28929 		}
  28930 	} else {
  28931 		width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  28932 		height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  28933 		y_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride
  28934 		uv_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride
  28935 		a_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride
  28936 		y_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fy
  28937 		u_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fu
  28938 		v_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fv
  28939 		a_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fa
  28940 		values = [3]int32{}
  28941 		if a_ptr == libc.UintptrFromInt32(0) || y_ptr == libc.UintptrFromInt32(0) || u_ptr == libc.UintptrFromInt32(0) || v_ptr == libc.UintptrFromInt32(0) {
  28942 			return
  28943 		}
  28944 		y = 0
  28945 		for {
  28946 			if !(y+int32(8) <= height) {
  28947 				break
  28948 			}
  28949 			need_reset1 = int32(1)
  28950 			x = 0
  28951 			for {
  28952 				if !(x+int32(8) <= width) {
  28953 					break
  28954 				}
  28955 				if SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), int32(8)) != 0 {
  28956 					if need_reset1 != 0 {
  28957 						values[0] = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))))
  28958 						values[int32(1)] = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x>>int32(1)))))
  28959 						values[int32(2)] = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x>>int32(1)))))
  28960 						need_reset1 = 0
  28961 					}
  28962 					Flatten(tls, y_ptr+uintptr(x), values[0], y_stride, int32(8))
  28963 					Flatten(tls, u_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(1)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  28964 					Flatten(tls, v_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(2)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  28965 				} else {
  28966 					need_reset1 = int32(1)
  28967 				}
  28968 				goto _4
  28969 			_4:
  28970 				;
  28971 				x = x + int32(8)
  28972 			}
  28973 			if x < width {
  28974 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, int32(8))
  28975 			}
  28976 			a_ptr = a_ptr + uintptr(int32(8)*a_stride)
  28977 			y_ptr = y_ptr + uintptr(int32(8)*y_stride)
  28978 			u_ptr = u_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  28979 			v_ptr = v_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  28980 			goto _3
  28981 		_3:
  28982 			;
  28983 			y = y + int32(8)
  28984 		}
  28985 		if y < height {
  28986 			sub_height = height - y
  28987 			x = 0
  28988 			for {
  28989 				if !(x+int32(8) <= width) {
  28990 					break
  28991 				}
  28992 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), sub_height)
  28993 				goto _5
  28994 			_5:
  28995 				;
  28996 				x = x + int32(8)
  28997 			}
  28998 			if x < width {
  28999 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, sub_height)
  29000 			}
  29001 		}
  29002 	}
  29003 }
  29004 
  29005 //------------------------------------------------------------------------------
  29006 // Blend color and remove transparency info
  29007 
  29008 func MakeARGB32(tls *libc.TLS, r int32, g int32, b int32) (r1 uint32_t) {
  29009 	return libc.Uint32FromUint32(0xff000000) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  29010 }
  29011 
  29012 func WebPBlendAlpha(tls *libc.TLS, picture uintptr, background_rgb uint32_t) {
  29013 	var U0, V0, Y0, alpha3, b3, blue, g3, green, has_alpha, luma, r3, red, u, uv_width, v, x, y, v1, v10, v12, v13, v15, v16, v3, v5, v6, v8, v9 int32
  29014 	var a_ptr, a_ptr2, argb, u_ptr, v_ptr, y_ptr, v19 uintptr
  29015 	var alpha uint8_t
  29016 	var alpha1, alpha2, background uint32_t
  29017 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = U0, V0, Y0, a_ptr, a_ptr2, alpha, alpha1, alpha2, alpha3, argb, b3, background, blue, g3, green, has_alpha, luma, r3, red, u, u_ptr, uv_width, v, v_ptr, x, y, y_ptr, v1, v10, v12, v13, v15, v16, v19, v3, v5, v6, v8, v9
  29018 	red = libc.Int32FromUint32(background_rgb >> libc.Int32FromInt32(16) & uint32(0xff))
  29019 	green = libc.Int32FromUint32(background_rgb >> libc.Int32FromInt32(8) & uint32(0xff))
  29020 	blue = libc.Int32FromUint32(background_rgb >> libc.Int32FromInt32(0) & uint32(0xff))
  29021 	if picture == libc.UintptrFromInt32(0) {
  29022 		return
  29023 	}
  29024 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  29025 		// omit last pixel during u/v loop
  29026 		uv_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth >> libc.Int32FromInt32(1)
  29027 		luma = int32(16839)*red + int32(33059)*green + int32(6420)*blue
  29028 		v1 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  29029 		goto _2
  29030 	_2:
  29031 		Y0 = v1
  29032 		u = -int32(9719)*(int32(4)*red) - int32(19081)*(int32(4)*green) + int32(28800)*(int32(4)*blue)
  29033 		v5 = u
  29034 		v5 = (v5 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29035 		if v5 & ^libc.Int32FromInt32(0xff) == 0 {
  29036 			v8 = v5
  29037 		} else {
  29038 			if v5 < 0 {
  29039 				v9 = 0
  29040 			} else {
  29041 				v9 = int32(255)
  29042 			}
  29043 			v8 = v9
  29044 		}
  29045 		v6 = v8
  29046 		goto _7
  29047 	_7:
  29048 		v3 = v6
  29049 		goto _4
  29050 	_4:
  29051 		// VP8RGBToU/V expects the u/v values summed over four pixels
  29052 		U0 = v3
  29053 		v = +libc.Int32FromInt32(28800)*(int32(4)*red) - int32(24116)*(int32(4)*green) - int32(4684)*(int32(4)*blue)
  29054 		v12 = v
  29055 		v12 = (v12 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29056 		if v12 & ^libc.Int32FromInt32(0xff) == 0 {
  29057 			v15 = v12
  29058 		} else {
  29059 			if v12 < 0 {
  29060 				v16 = 0
  29061 			} else {
  29062 				v16 = int32(255)
  29063 			}
  29064 			v15 = v16
  29065 		}
  29066 		v13 = v15
  29067 		goto _14
  29068 	_14:
  29069 		v10 = v13
  29070 		goto _11
  29071 	_11:
  29072 		V0 = v10
  29073 		has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  29074 		y_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  29075 		u_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  29076 		v_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  29077 		a_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  29078 		if !(has_alpha != 0) || a_ptr == libc.UintptrFromInt32(0) {
  29079 			return
  29080 		} // nothing to do
  29081 		y = 0
  29082 		for {
  29083 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29084 				break
  29085 			}
  29086 			// Luma blending
  29087 			x = 0
  29088 			for {
  29089 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29090 					break
  29091 				}
  29092 				alpha = **(**uint8_t)(__ccgo_up(a_ptr + uintptr(x)))
  29093 				if libc.Int32FromUint8(alpha) < int32(0xff) {
  29094 					**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))) = libc.Uint8FromInt32(((Y0*(libc.Int32FromInt32(255)-libc.Int32FromUint8(alpha))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))))*libc.Int32FromUint8(alpha))*libc.Int32FromInt32(0x101) + libc.Int32FromInt32(256)) >> libc.Int32FromInt32(16))
  29095 				}
  29096 				goto _18
  29097 			_18:
  29098 				;
  29099 				x = x + 1
  29100 			}
  29101 			// Chroma blending every even line
  29102 			if y&int32(1) == 0 {
  29103 				if y+int32(1) == (*WebPPicture)(unsafe.Pointer(picture)).Fheight {
  29104 					v19 = a_ptr
  29105 				} else {
  29106 					v19 = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29107 				}
  29108 				a_ptr2 = v19
  29109 				x = 0
  29110 				for {
  29111 					if !(x < uv_width) {
  29112 						break
  29113 					}
  29114 					// Average four alpha values into a single blending weight.
  29115 					// TODO(skal): might lead to visible contouring. Can we do better?
  29116 					alpha1 = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(int32(2)*x+0)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(int32(2)*x+int32(1))))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr2 + uintptr(int32(2)*x+0)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr2 + uintptr(int32(2)*x+int32(1))))))
  29117 					**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))) = uint8(((libc.Uint32FromInt32(U0)*(libc.Uint32FromInt32(1020)-alpha1)+uint32(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))))*alpha1)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29118 					**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))) = uint8(((libc.Uint32FromInt32(V0)*(libc.Uint32FromInt32(1020)-alpha1)+uint32(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))))*alpha1)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29119 					goto _20
  29120 				_20:
  29121 					;
  29122 					x = x + 1
  29123 				}
  29124 				if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth&int32(1) != 0 { // rightmost pixel
  29125 					alpha2 = libc.Uint32FromInt32(int32(2) * (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr + uintptr(int32(2)*x+0)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a_ptr2 + uintptr(int32(2)*x+0))))))
  29126 					**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))) = uint8(((libc.Uint32FromInt32(U0)*(libc.Uint32FromInt32(1020)-alpha2)+uint32(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x))))*alpha2)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29127 					**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))) = uint8(((libc.Uint32FromInt32(V0)*(libc.Uint32FromInt32(1020)-alpha2)+uint32(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x))))*alpha2)*libc.Uint32FromInt32(0x101) + libc.Uint32FromInt32(1024)) >> libc.Int32FromInt32(18))
  29128 				}
  29129 			} else {
  29130 				u_ptr = u_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29131 				v_ptr = v_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29132 			}
  29133 			libc.Xmemset(tls, a_ptr, int32(0xff), libc.Uint64FromInt32((*WebPPicture)(unsafe.Pointer(picture)).Fwidth)) // reset alpha value to opaque
  29134 			a_ptr = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29135 			y_ptr = y_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  29136 			goto _17
  29137 		_17:
  29138 			;
  29139 			y = y + 1
  29140 		}
  29141 	} else {
  29142 		argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  29143 		background = MakeARGB32(tls, red, green, blue)
  29144 		y = 0
  29145 		for {
  29146 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29147 				break
  29148 			}
  29149 			x = 0
  29150 			for {
  29151 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29152 					break
  29153 				}
  29154 				alpha3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(24) & uint32(0xff))
  29155 				if alpha3 != int32(0xff) {
  29156 					if alpha3 > 0 {
  29157 						r3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(16) & uint32(0xff))
  29158 						g3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  29159 						b3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(0) & uint32(0xff))
  29160 						r3 = ((red*(int32(255)-alpha3)+r3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29161 						g3 = ((green*(int32(255)-alpha3)+g3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29162 						b3 = ((blue*(int32(255)-alpha3)+b3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29163 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = MakeARGB32(tls, r3, g3, b3)
  29164 					} else {
  29165 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = background
  29166 					}
  29167 				}
  29168 				goto _22
  29169 			_22:
  29170 				;
  29171 				x = x + 1
  29172 			}
  29173 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  29174 			goto _21
  29175 		_21:
  29176 			;
  29177 			y = y + 1
  29178 		}
  29179 	}
  29180 }
  29181 
  29182 const ARGB_BLACK1 = 4278190080
  29183 
  29184 //------------------------------------------------------------------------------
  29185 
  29186 // Copyright 2012 Google Inc. All Rights Reserved.
  29187 //
  29188 // Use of this source code is governed by a BSD-style license
  29189 // that can be found in the COPYING file in the root of the source
  29190 // tree. An additional intellectual property rights grant can be found
  29191 // in the file PATENTS. All contributing project authors may
  29192 // be found in the AUTHORS file in the root of the source tree.
  29193 // -----------------------------------------------------------------------------
  29194 //
  29195 // Misc. common utility functions
  29196 //
  29197 // Authors: Skal (pascal.massimino@gmail.com)
  29198 //          Urvang (urvang@google.com)
  29199 
  29200 // Copyright 2011 Google Inc. All Rights Reserved.
  29201 //
  29202 // Use of this source code is governed by a BSD-style license
  29203 // that can be found in the COPYING file in the root of the source
  29204 // tree. An additional intellectual property rights grant can be found
  29205 // in the file PATENTS. All contributing project authors may
  29206 // be found in the AUTHORS file in the root of the source tree.
  29207 // -----------------------------------------------------------------------------
  29208 //
  29209 //   WebP encoder: main interface
  29210 //
  29211 // Author: Skal (pascal.massimino@gmail.com)
  29212 
  29213 // Copyright 2012 Google Inc. All Rights Reserved.
  29214 //
  29215 // Use of this source code is governed by a BSD-style license
  29216 // that can be found in the COPYING file in the root of the source
  29217 // tree. An additional intellectual property rights grant can be found
  29218 // in the file PATENTS. All contributing project authors may
  29219 // be found in the AUTHORS file in the root of the source tree.
  29220 // -----------------------------------------------------------------------------
  29221 //
  29222 //  Internal header for constants related to WebP file format.
  29223 //
  29224 // Author: Urvang (urvang@google.com)
  29225 
  29226 // Copyright 2010 Google Inc. All Rights Reserved.
  29227 //
  29228 // Use of this source code is governed by a BSD-style license
  29229 // that can be found in the COPYING file in the root of the source
  29230 // tree. An additional intellectual property rights grant can be found
  29231 // in the file PATENTS. All contributing project authors may
  29232 // be found in the AUTHORS file in the root of the source tree.
  29233 // -----------------------------------------------------------------------------
  29234 //
  29235 //  Common types + memory wrappers
  29236 //
  29237 // Author: Skal (pascal.massimino@gmail.com)
  29238 
  29239 var kSpatialPredictorBias = int64(libc.Int64FromInt64(15) << libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  29240 var kPredLowEffort = int32(11)
  29241 var kMaskAlpha = uint32(0xff000000)
  29242 var kNumPredModes = int32(14)
  29243 
  29244 // C documentation
  29245 //
  29246 //	// Mostly used to reduce code size + readability
  29247 func GetMin(tls *libc.TLS, a int32, b int32) (r int32) {
  29248 	var v1 int32
  29249 	_ = v1
  29250 	if a > b {
  29251 		v1 = b
  29252 	} else {
  29253 		v1 = a
  29254 	}
  29255 	return v1
  29256 }
  29257 
  29258 func GetMax(tls *libc.TLS, a int32, b int32) (r int32) {
  29259 	var v1 int32
  29260 	_ = v1
  29261 	if a < b {
  29262 		v1 = b
  29263 	} else {
  29264 		v1 = a
  29265 	}
  29266 	return v1
  29267 }
  29268 
  29269 //------------------------------------------------------------------------------
  29270 // Methods to calculate Entropy (Shannon).
  29271 
  29272 // C documentation
  29273 //
  29274 //	// Compute a bias for prediction entropy using a global heuristic to favor
  29275 //	// values closer to 0. Hence the final negative sign.
  29276 //	// 'exp_val' has a scaling factor of 1/100.
  29277 func PredictionCostBias(tls *libc.TLS, counts uintptr, weight_0 uint64_t, exp_val uint64_t) (r int64_t) {
  29278 	var bits, exp_decay_factor uint64_t
  29279 	var i, significant_symbols int32
  29280 	var v6 int64
  29281 	var v2, v3, v4 int64_t
  29282 	_, _, _, _, _, _, _, _ = bits, exp_decay_factor, i, significant_symbols, v2, v3, v4, v6
  29283 	significant_symbols = libc.Int32FromInt32(256) >> libc.Int32FromInt32(4)
  29284 	exp_decay_factor = uint64(6) // has a scaling factor of 1/10
  29285 	bits = weight_0 * uint64(**(**uint32_t)(__ccgo_up(counts))) << int32(LOG_2_PRECISION_BITS)
  29286 	exp_val = exp_val << uint64(LOG_2_PRECISION_BITS)
  29287 	i = int32(1)
  29288 	for {
  29289 		if !(i < significant_symbols) {
  29290 			break
  29291 		}
  29292 		v2 = libc.Int64FromUint64(exp_val * uint64(**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))+**(**uint32_t)(__ccgo_up(counts + uintptr(int32(256)-i)*4))))
  29293 		v3 = int64(100)
  29294 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29295 			v6 = (v2 + v3/int64(2)) / v3
  29296 		} else {
  29297 			v6 = (v2 - v3/int64(2)) / v3
  29298 		}
  29299 		v4 = v6
  29300 		goto _5
  29301 	_5:
  29302 		bits = bits + libc.Uint64FromInt64(v4)
  29303 		v2 = libc.Int64FromUint64(exp_decay_factor * exp_val)
  29304 		v3 = int64(10)
  29305 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29306 			v6 = (v2 + v3/int64(2)) / v3
  29307 		} else {
  29308 			v6 = (v2 - v3/int64(2)) / v3
  29309 		}
  29310 		v4 = v6
  29311 		goto _10
  29312 	_10:
  29313 		exp_val = libc.Uint64FromInt64(v4)
  29314 		goto _1
  29315 	_1:
  29316 		;
  29317 		i = i + 1
  29318 	}
  29319 	v2 = libc.Int64FromUint64(bits)
  29320 	v3 = int64(10)
  29321 	if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29322 		v6 = (v2 + v3/int64(2)) / v3
  29323 	} else {
  29324 		v6 = (v2 - v3/int64(2)) / v3
  29325 	}
  29326 	v4 = v6
  29327 	goto _15
  29328 _15:
  29329 	return -v4
  29330 }
  29331 
  29332 func PredictionCostSpatialHistogram(tls *libc.TLS, accumulated uintptr, tile uintptr, mode int32, left_mode int32, above_mode int32) (r int64_t) {
  29333 	var i int32
  29334 	var kExpValue uint64_t
  29335 	var retval int64_t
  29336 	_, _, _ = i, kExpValue, retval
  29337 	retval = 0
  29338 	i = 0
  29339 	for {
  29340 		if !(i < int32(4)) {
  29341 			break
  29342 		}
  29343 		kExpValue = uint64(94)
  29344 		retval = retval + PredictionCostBias(tls, tile+uintptr(i*int32(256))*4, uint64(1), kExpValue)
  29345 		// Compute the new cost if 'tile' is added to 'accumulate' but also add the
  29346 		// cost of the current histogram to guide the spatial predictor selection.
  29347 		// Basically, favor low entropy, locally and globally.
  29348 		retval = retval + libc.Int64FromUint64((*(*func(*libc.TLS, uintptr, uintptr) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LCombinedShannonEntropy})))(tls, tile+uintptr(i*int32(256))*4, accumulated+uintptr(i*int32(256))*4))
  29349 		goto _1
  29350 	_1:
  29351 		;
  29352 		i = i + 1
  29353 	}
  29354 	// Favor keeping the areas locally similar.
  29355 	if mode == left_mode {
  29356 		retval = retval - kSpatialPredictorBias
  29357 	}
  29358 	if mode == above_mode {
  29359 		retval = retval - kSpatialPredictorBias
  29360 	}
  29361 	return retval
  29362 }
  29363 
  29364 func UpdateHisto(tls *libc.TLS, histo_argb uintptr, argb uint32_t) {
  29365 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(0)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(24))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(0)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(24))*4)) + 1
  29366 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(1)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(16)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(1)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(16)&uint32(0xff))*4)) + 1
  29367 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(8)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(256))+argb>>libc.Int32FromInt32(8)&uint32(0xff))*4)) + 1
  29368 	**(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(256))+argb&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(histo_argb + uintptr(libc.Uint32FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(256))+argb&uint32(0xff))*4)) + 1
  29369 }
  29370 
  29371 //------------------------------------------------------------------------------
  29372 // Spatial transform functions.
  29373 
  29374 func PredictBatch(tls *libc.TLS, mode int32, x_start int32, y int32, num_pixels int32, current uintptr, upper uintptr, out uintptr) {
  29375 	if x_start == 0 {
  29376 		if y == 0 {
  29377 			// ARGB_BLACK.
  29378 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(0)]})))(tls, current, libc.UintptrFromInt32(0), int32(1), out)
  29379 		} else {
  29380 			// Top one.
  29381 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(2)]})))(tls, current, upper, int32(1), out)
  29382 		}
  29383 		x_start = x_start + 1
  29384 		out += 4
  29385 		num_pixels = num_pixels - 1
  29386 	}
  29387 	if y == 0 {
  29388 		// Left one.
  29389 		(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(1)]})))(tls, current+uintptr(x_start)*4, libc.UintptrFromInt32(0), num_pixels, out)
  29390 	} else {
  29391 		(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[mode]})))(tls, current+uintptr(x_start)*4, upper+uintptr(x_start)*4, num_pixels, out)
  29392 	}
  29393 }
  29394 
  29395 func MaxDiffBetweenPixels(tls *libc.TLS, p1 uint32_t, p2 uint32_t) (r int32) {
  29396 	var diff_a, diff_b, diff_g, diff_r int32
  29397 	_, _, _, _ = diff_a, diff_b, diff_g, diff_r
  29398 	diff_a = libc.Xabs(tls, libc.Int32FromUint32(p1>>libc.Int32FromInt32(24))-libc.Int32FromUint32(p2>>libc.Int32FromInt32(24)))
  29399 	diff_r = libc.Xabs(tls, libc.Int32FromUint32(p1>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff))-libc.Int32FromUint32(p2>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff)))
  29400 	diff_g = libc.Xabs(tls, libc.Int32FromUint32(p1>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff))-libc.Int32FromUint32(p2>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff)))
  29401 	diff_b = libc.Xabs(tls, libc.Int32FromUint32(p1&libc.Uint32FromInt32(0xff))-libc.Int32FromUint32(p2&libc.Uint32FromInt32(0xff)))
  29402 	return GetMax(tls, GetMax(tls, diff_a, diff_r), GetMax(tls, diff_g, diff_b))
  29403 }
  29404 
  29405 func MaxDiffAroundPixel(tls *libc.TLS, current uint32_t, up uint32_t, down uint32_t, left uint32_t, right uint32_t) (r int32) {
  29406 	var diff_down, diff_left, diff_right, diff_up int32
  29407 	_, _, _, _ = diff_down, diff_left, diff_right, diff_up
  29408 	diff_up = MaxDiffBetweenPixels(tls, current, up)
  29409 	diff_down = MaxDiffBetweenPixels(tls, current, down)
  29410 	diff_left = MaxDiffBetweenPixels(tls, current, left)
  29411 	diff_right = MaxDiffBetweenPixels(tls, current, right)
  29412 	return GetMax(tls, GetMax(tls, diff_up, diff_down), GetMax(tls, diff_left, diff_right))
  29413 }
  29414 
  29415 func AddGreenToBlueAndRed(tls *libc.TLS, argb uint32_t) (r uint32_t) {
  29416 	var green, red_blue uint32_t
  29417 	_, _ = green, red_blue
  29418 	green = argb >> libc.Int32FromInt32(8) & uint32(0xff)
  29419 	red_blue = argb & uint32(0x00ff00ff)
  29420 	red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  29421 	red_blue = red_blue & uint32(0x00ff00ff)
  29422 	return argb&uint32(0xff00ff00) | red_blue
  29423 }
  29424 
  29425 func MaxDiffsForRow(tls *libc.TLS, width int32, stride int32, argb uintptr, max_diffs uintptr, used_subtract_green int32) {
  29426 	var current, down, left, right, up uint32_t
  29427 	var x int32
  29428 	_, _, _, _, _, _ = current, down, left, right, up, x
  29429 	if width <= int32(2) {
  29430 		return
  29431 	}
  29432 	current = **(**uint32_t)(__ccgo_up(argb))
  29433 	right = **(**uint32_t)(__ccgo_up(argb + 1*4))
  29434 	if used_subtract_green != 0 {
  29435 		current = AddGreenToBlueAndRed(tls, current)
  29436 		right = AddGreenToBlueAndRed(tls, right)
  29437 	}
  29438 	// max_diffs[0] and max_diffs[width - 1] are never used.
  29439 	x = int32(1)
  29440 	for {
  29441 		if !(x < width-int32(1)) {
  29442 			break
  29443 		}
  29444 		up = **(**uint32_t)(__ccgo_up(argb + uintptr(-stride+x)*4))
  29445 		down = **(**uint32_t)(__ccgo_up(argb + uintptr(stride+x)*4))
  29446 		left = current
  29447 		current = right
  29448 		right = **(**uint32_t)(__ccgo_up(argb + uintptr(x+int32(1))*4))
  29449 		if used_subtract_green != 0 {
  29450 			up = AddGreenToBlueAndRed(tls, up)
  29451 			down = AddGreenToBlueAndRed(tls, down)
  29452 			right = AddGreenToBlueAndRed(tls, right)
  29453 		}
  29454 		**(**uint8_t)(__ccgo_up(max_diffs + uintptr(x))) = libc.Uint8FromInt32(MaxDiffAroundPixel(tls, current, up, down, left, right))
  29455 		goto _1
  29456 	_1:
  29457 		;
  29458 		x = x + 1
  29459 	}
  29460 }
  29461 
  29462 // C documentation
  29463 //
  29464 //	// Quantize the difference between the actual component value and its prediction
  29465 //	// to a multiple of quantization, working modulo 256, taking care not to cross
  29466 //	// a boundary (inclusive upper limit).
  29467 func NearLosslessComponent(tls *libc.TLS, value uint8_t, predict uint8_t, boundary uint8_t, quantization int32) (r uint8_t) {
  29468 	var bias, boundary_residual, lower, residual, upper int32
  29469 	_, _, _, _, _ = bias, boundary_residual, lower, residual, upper
  29470 	residual = (libc.Int32FromUint8(value) - libc.Int32FromUint8(predict)) & int32(0xff)
  29471 	boundary_residual = (libc.Int32FromUint8(boundary) - libc.Int32FromUint8(predict)) & int32(0xff)
  29472 	lower = residual & ^(quantization - libc.Int32FromInt32(1))
  29473 	upper = lower + quantization
  29474 	// Resolve ties towards a value closer to the prediction (i.e. towards lower
  29475 	// if value comes after prediction and towards upper otherwise).
  29476 	bias = libc.BoolInt32((libc.Int32FromUint8(boundary)-libc.Int32FromUint8(value))&int32(0xff) < boundary_residual)
  29477 	if residual-lower < upper-residual+bias {
  29478 		// lower is closer to residual than upper.
  29479 		if residual > boundary_residual && lower <= boundary_residual {
  29480 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29481 			// on the same side of boundary as residual because midpoint >= residual
  29482 			// (since lower is closer than upper) and residual is above the boundary.
  29483 			return libc.Uint8FromInt32(lower + quantization>>int32(1))
  29484 		}
  29485 		return libc.Uint8FromInt32(lower)
  29486 	} else {
  29487 		// upper is closer to residual than lower.
  29488 		if residual <= boundary_residual && upper > boundary_residual {
  29489 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29490 			// on the same side of boundary as residual because midpoint <= residual
  29491 			// (since upper is closer than lower) and residual is below the boundary.
  29492 			return libc.Uint8FromInt32(lower + quantization>>int32(1))
  29493 		}
  29494 		return libc.Uint8FromInt32(upper & int32(0xff))
  29495 	}
  29496 	return r
  29497 }
  29498 
  29499 func NearLosslessDiff(tls *libc.TLS, a uint8_t, b uint8_t) (r uint8_t) {
  29500 	return libc.Uint8FromInt32((libc.Int32FromUint8(a) - libc.Int32FromUint8(b)) & libc.Int32FromInt32(0xff))
  29501 }
  29502 
  29503 // C documentation
  29504 //
  29505 //	// Quantize every component of the difference between the actual pixel value and
  29506 //	// its prediction to a multiple of a quantization (a power of 2, not larger than
  29507 //	// max_quantization which is a power of 2, smaller than max_diff). Take care if
  29508 //	// value and predict have undergone subtract green, which means that red and
  29509 //	// blue are represented as offsets from green.
  29510 func NearLossless1(tls *libc.TLS, value uint32_t, predict uint32_t, max_quantization int32, max_diff int32, used_subtract_green int32) (r1 uint32_t) {
  29511 	var a1, b1, g, green_diff, new_green, r uint8_t
  29512 	var alpha_and_green, red_and_blue, v1, v2, v3 uint32_t
  29513 	var quantization int32
  29514 	_, _, _, _, _, _, _, _, _, _, _, _ = a1, alpha_and_green, b1, g, green_diff, new_green, quantization, r, red_and_blue, v1, v2, v3
  29515 	new_green = uint8(0)
  29516 	green_diff = uint8(0)
  29517 	if max_diff <= int32(2) {
  29518 		v1 = value
  29519 		v2 = predict
  29520 		alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  29521 		red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  29522 		v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29523 		goto _4
  29524 	_4:
  29525 		return v3
  29526 	}
  29527 	quantization = max_quantization
  29528 	for quantization >= max_diff {
  29529 		quantization = quantization >> int32(1)
  29530 	}
  29531 	if value>>libc.Int32FromInt32(24) == uint32(0) || value>>libc.Int32FromInt32(24) == uint32(0xff) {
  29532 		// Preserve transparency of fully transparent or fully opaque pixels.
  29533 		a1 = NearLosslessDiff(tls, uint8(value>>libc.Int32FromInt32(24)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(24)&uint32(0xff)))
  29534 	} else {
  29535 		a1 = NearLosslessComponent(tls, uint8(value>>int32(24)), uint8(predict>>int32(24)), uint8(0xff), quantization)
  29536 	}
  29537 	g = NearLosslessComponent(tls, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(0xff), quantization)
  29538 	if used_subtract_green != 0 {
  29539 		// The green offset will be added to red and blue components during decoding
  29540 		// to obtain the actual red and blue values.
  29541 		new_green = uint8((predict>>libc.Int32FromInt32(8) + uint32(g)) & uint32(0xff))
  29542 		// The amount by which green has been adjusted during quantization. It is
  29543 		// subtracted from red and blue for compensation, to avoid accumulating two
  29544 		// quantization errors in them.
  29545 		green_diff = NearLosslessDiff(tls, new_green, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)))
  29546 	}
  29547 	r = NearLosslessComponent(tls, NearLosslessDiff(tls, uint8(value>>libc.Int32FromInt32(16)&uint32(0xff)), green_diff), uint8(predict>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Uint8FromInt32(int32(0xff)-libc.Int32FromUint8(new_green)), quantization)
  29548 	b1 = NearLosslessComponent(tls, NearLosslessDiff(tls, uint8(value&uint32(0xff)), green_diff), uint8(predict&uint32(0xff)), libc.Uint8FromInt32(int32(0xff)-libc.Int32FromUint8(new_green)), quantization)
  29549 	return uint32(a1)<<libc.Int32FromInt32(24) | uint32(r)<<libc.Int32FromInt32(16) | uint32(g)<<libc.Int32FromInt32(8) | uint32(b1)
  29550 }
  29551 
  29552 // C documentation
  29553 //
  29554 //	// Stores the difference between the pixel and its prediction in "out".
  29555 //	// In case of a lossy encoding, updates the source image to avoid propagating
  29556 //	// the deviation further to pixels which depend on the current pixel for their
  29557 //	// predictions.
  29558 func GetResidual(tls *libc.TLS, width int32, height int32, upper_row uintptr, current_row uintptr, max_diffs uintptr, mode int32, x_start int32, x_end int32, y int32, max_quantization int32, exact int32, used_subtract_green int32, out uintptr) {
  29559 	var alpha_and_green, alpha_and_green1, predict, red_and_blue, red_and_blue1, residual, v3, v4, v5 uint32_t
  29560 	var pred_func VP8LPredictorFunc
  29561 	var x int32
  29562 	var v2 uint32
  29563 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, alpha_and_green1, pred_func, predict, red_and_blue, red_and_blue1, residual, x, v2, v3, v4, v5
  29564 	if exact != 0 {
  29565 		PredictBatch(tls, mode, x_start, y, x_end-x_start, current_row, upper_row, out)
  29566 	} else {
  29567 		pred_func = VP8LPredictors[mode]
  29568 		x = x_start
  29569 		for {
  29570 			if !(x < x_end) {
  29571 				break
  29572 			}
  29573 			if y == 0 {
  29574 				if x == 0 {
  29575 					v2 = uint32(ARGB_BLACK1)
  29576 				} else {
  29577 					v2 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x-int32(1))*4))
  29578 				}
  29579 				predict = v2 // Left.
  29580 			} else {
  29581 				if x == 0 {
  29582 					predict = **(**uint32_t)(__ccgo_up(upper_row + uintptr(x)*4)) // Top.
  29583 				} else {
  29584 					predict = (*(*func(*libc.TLS, uintptr, uintptr) uint32_t)(unsafe.Pointer(&struct{ uintptr }{pred_func})))(tls, current_row+uintptr(x-int32(1))*4, upper_row+uintptr(x)*4)
  29585 				}
  29586 			}
  29587 			if max_quantization == int32(1) || mode == 0 || y == 0 || y == height-int32(1) || x == 0 || x == width-int32(1) {
  29588 				v3 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))
  29589 				v4 = predict
  29590 				alpha_and_green1 = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  29591 				red_and_blue1 = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  29592 				v5 = alpha_and_green1&uint32(0xff00ff00) | red_and_blue1&uint32(0x00ff00ff)
  29593 				goto _6
  29594 			_6:
  29595 				residual = v5
  29596 			} else {
  29597 				residual = NearLossless1(tls, **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)), predict, max_quantization, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(max_diffs + uintptr(x)))), used_subtract_green)
  29598 				// Update the source image.
  29599 				v3 = predict
  29600 				v4 = residual
  29601 				alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  29602 				red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  29603 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29604 				goto _10
  29605 			_10:
  29606 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = v5
  29607 				// x is never 0 here so we do not need to update upper_row like below.
  29608 			}
  29609 			if **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))&kMaskAlpha == uint32(0) {
  29610 				// If alpha is 0, cleanup RGB. We can choose the RGB values of the
  29611 				// residual for best compression. The prediction of alpha itself can be
  29612 				// non-zero and must be kept though. We choose RGB of the residual to be
  29613 				// 0.
  29614 				residual = residual & kMaskAlpha
  29615 				// Update the source image.
  29616 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = predict & ^kMaskAlpha
  29617 				// The prediction for the rightmost pixel in a row uses the leftmost
  29618 				// pixel
  29619 				// in that row as its top-right context pixel. Hence if we change the
  29620 				// leftmost pixel of current_row, the corresponding change must be
  29621 				// applied
  29622 				// to upper_row as well where top-right context is being read from.
  29623 				if x == 0 && y != 0 {
  29624 					**(**uint32_t)(__ccgo_up(upper_row + uintptr(width)*4)) = **(**uint32_t)(__ccgo_up(current_row))
  29625 				}
  29626 			}
  29627 			**(**uint32_t)(__ccgo_up(out + uintptr(x-x_start)*4)) = residual
  29628 			goto _1
  29629 		_1:
  29630 			;
  29631 			x = x + 1
  29632 		}
  29633 	}
  29634 }
  29635 
  29636 // C documentation
  29637 //
  29638 //	// Accessors to residual histograms.
  29639 func GetHistoArgb(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29640 	return all_histos + uintptr((subsampling_index*kNumPredModes+mode)*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29641 }
  29642 
  29643 func GetHistoArgbConst(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29644 	return all_histos + uintptr(subsampling_index*kNumPredModes*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256))+mode*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29645 }
  29646 
  29647 // C documentation
  29648 //
  29649 //	// Accessors to accumulated residual histogram.
  29650 func GetAccumulatedHisto(tls *libc.TLS, all_accumulated uintptr, subsampling_index int32) (r uintptr) {
  29651 	return all_accumulated + uintptr(subsampling_index*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29652 }
  29653 
  29654 // C documentation
  29655 //
  29656 //	// Find and store the best predictor for a tile at subsampling
  29657 //	// 'subsampling_index'.
  29658 func GetBestPredictorForTile(tls *libc.TLS, all_argb uintptr, subsampling_index int32, tile_x int32, tile_y int32, tiles_per_row int32, all_accumulated_argb uintptr, all_modes uintptr, all_pred_histos uintptr) {
  29659 	var above_mode, left_mode, mode int32
  29660 	var accumulated_argb, best_histo, histo_argb, modes, pred_histos uintptr
  29661 	var best_diff, cur_diff int64_t
  29662 	var best_mode uint32_t
  29663 	var v1, v2 uint32
  29664 	_, _, _, _, _, _, _, _, _, _, _, _, _ = above_mode, accumulated_argb, best_diff, best_histo, best_mode, cur_diff, histo_argb, left_mode, mode, modes, pred_histos, v1, v2
  29665 	accumulated_argb = GetAccumulatedHisto(tls, all_accumulated_argb, subsampling_index)
  29666 	modes = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  29667 	pred_histos = all_pred_histos + uintptr(subsampling_index*kNumPredModes)*4
  29668 	if tile_x > 0 {
  29669 		v1 = **(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x-int32(1))*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29670 	} else {
  29671 		v1 = uint32(0xff)
  29672 	}
  29673 	// Prediction modes of the left and above neighbor tiles.
  29674 	left_mode = libc.Int32FromUint32(v1)
  29675 	if tile_y > 0 {
  29676 		v2 = **(**uint32_t)(__ccgo_up(modes + uintptr((tile_y-int32(1))*tiles_per_row+tile_x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29677 	} else {
  29678 		v2 = uint32(0xff)
  29679 	}
  29680 	above_mode = libc.Int32FromUint32(v2)
  29681 	best_diff = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  29682 	best_mode = uint32(0)
  29683 	best_histo = GetHistoArgbConst(tls, all_argb, 0, libc.Int32FromUint32(best_mode))
  29684 	mode = 0
  29685 	for {
  29686 		if !(mode < kNumPredModes) {
  29687 			break
  29688 		}
  29689 		histo_argb = GetHistoArgbConst(tls, all_argb, subsampling_index, mode)
  29690 		cur_diff = PredictionCostSpatialHistogram(tls, accumulated_argb, histo_argb, mode, left_mode, above_mode)
  29691 		if cur_diff < best_diff {
  29692 			best_histo = histo_argb
  29693 			best_diff = cur_diff
  29694 			best_mode = libc.Uint32FromInt32(mode)
  29695 		}
  29696 		goto _3
  29697 	_3:
  29698 		;
  29699 		mode = mode + 1
  29700 	}
  29701 	// Update the accumulated histogram.
  29702 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, best_histo, accumulated_argb, libc.Int32FromInt32(4)*libc.Int32FromInt32(256))
  29703 	**(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x)*4)) = uint32(ARGB_BLACK1) | best_mode<<libc.Int32FromInt32(8)
  29704 	**(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) = **(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) + 1
  29705 }
  29706 
  29707 // C documentation
  29708 //
  29709 //	// Computes the residuals for the different predictors.
  29710 //	// If max_quantization > 1, assumes that near lossless processing will be
  29711 //	// applied, quantizing residuals to multiples of quantization levels up to
  29712 //	// max_quantization (the actual quantization level depends on smoothness near
  29713 //	// the given pixel).
  29714 func ComputeResidualsForTile(tls *libc.TLS, width int32, height int32, tile_x int32, tile_y int32, min_bits int32, update_up_to_index uint32_t, all_argb uintptr, argb_scratch uintptr, argb uintptr, max_quantization int32, exact int32, used_subtract_green int32) {
  29715 	bp := tls.Alloc(2048)
  29716 	defer tls.Free(2048)
  29717 	var context_start_x, context_width, have_left, max_x, max_y, mode, relative_x, relative_y, start_x, start_y, tile_size, y int32
  29718 	var current_row, histo_argb, max_diffs, super_histo, tmp, upper_row uintptr
  29719 	var subsampling_index uint32_t
  29720 	var _ /* residuals at bp+0 */ [512]uint32_t
  29721 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = context_start_x, context_width, current_row, have_left, histo_argb, max_diffs, max_x, max_y, mode, relative_x, relative_y, start_x, start_y, subsampling_index, super_histo, tile_size, tmp, upper_row, y
  29722 	start_x = tile_x << min_bits
  29723 	start_y = tile_y << min_bits
  29724 	tile_size = int32(1) << min_bits
  29725 	max_y = GetMin(tls, tile_size, height-start_y)
  29726 	max_x = GetMin(tls, tile_size, width-start_x)
  29727 	// Whether there exist columns just outside the tile.
  29728 	have_left = libc.BoolInt32(start_x > libc.Int32FromInt32(0))
  29729 	// Position and size of the strip covering the tile and adjacent columns if
  29730 	// they exist.
  29731 	context_start_x = start_x - have_left
  29732 	context_width = max_x + have_left + libc.BoolInt32(max_x < width-start_x)
  29733 	// The width of upper_row and current_row is one pixel larger than image width
  29734 	// to allow the top right pixel to point to the leftmost pixel of the next row
  29735 	// when at the right edge.
  29736 	upper_row = argb_scratch
  29737 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  29738 	max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  29739 	mode = 0
  29740 	for {
  29741 		if !(mode < kNumPredModes) {
  29742 			break
  29743 		}
  29744 		histo_argb = GetHistoArgb(tls, all_argb, 0, mode)
  29745 		if start_y > 0 {
  29746 			// Read the row above the tile which will become the first upper_row.
  29747 			// Include a pixel to the left if it exists; include a pixel to the right
  29748 			// in all cases (wrapping to the leftmost pixel of the next row if it does
  29749 			// not exist).
  29750 			libc.Xmemcpy(tls, current_row+uintptr(context_start_x)*4, argb+uintptr((start_y-int32(1))*width)*4+uintptr(context_start_x)*4, uint64(4)*libc.Uint64FromInt32(max_x+have_left+libc.Int32FromInt32(1)))
  29751 		}
  29752 		relative_y = 0
  29753 		for {
  29754 			if !(relative_y < max_y) {
  29755 				break
  29756 			}
  29757 			y = start_y + relative_y
  29758 			tmp = upper_row
  29759 			upper_row = current_row
  29760 			current_row = tmp
  29761 			// Read current_row. Include a pixel to the left if it exists; include a
  29762 			// pixel to the right in all cases except at the bottom right corner of
  29763 			// the image (wrapping to the leftmost pixel of the next row if it does
  29764 			// not exist in the current row).
  29765 			libc.Xmemcpy(tls, current_row+uintptr(context_start_x)*4, argb+uintptr(y*width)*4+uintptr(context_start_x)*4, uint64(4)*libc.Uint64FromInt32(max_x+have_left+libc.BoolInt32(y+libc.Int32FromInt32(1) < height)))
  29766 			if max_quantization > int32(1) && y >= int32(1) && y+int32(1) < height {
  29767 				MaxDiffsForRow(tls, context_width, width, argb+uintptr(y*width)*4+uintptr(context_start_x)*4, max_diffs+uintptr(context_start_x), used_subtract_green)
  29768 			}
  29769 			GetResidual(tls, width, height, upper_row, current_row, max_diffs, mode, start_x, start_x+max_x, y, max_quantization, exact, used_subtract_green, bp)
  29770 			relative_x = 0
  29771 			for {
  29772 				if !(relative_x < max_x) {
  29773 					break
  29774 				}
  29775 				UpdateHisto(tls, histo_argb, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  29776 				goto _3
  29777 			_3:
  29778 				;
  29779 				relative_x = relative_x + 1
  29780 			}
  29781 			if update_up_to_index > uint32(0) {
  29782 				subsampling_index = uint32(1)
  29783 				for {
  29784 					if !(subsampling_index <= update_up_to_index) {
  29785 						break
  29786 					}
  29787 					super_histo = GetHistoArgb(tls, all_argb, libc.Int32FromUint32(subsampling_index), mode)
  29788 					relative_x = 0
  29789 					for {
  29790 						if !(relative_x < max_x) {
  29791 							break
  29792 						}
  29793 						UpdateHisto(tls, super_histo, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  29794 						goto _5
  29795 					_5:
  29796 						;
  29797 						relative_x = relative_x + 1
  29798 					}
  29799 					goto _4
  29800 				_4:
  29801 					;
  29802 					subsampling_index = subsampling_index + 1
  29803 				}
  29804 			}
  29805 			goto _2
  29806 		_2:
  29807 			;
  29808 			relative_y = relative_y + 1
  29809 		}
  29810 		goto _1
  29811 	_1:
  29812 		;
  29813 		mode = mode + 1
  29814 	}
  29815 }
  29816 
  29817 // C documentation
  29818 //
  29819 //	// Converts pixels of the image to residuals with respect to predictions.
  29820 //	// If max_quantization > 1, applies near lossless processing, quantizing
  29821 //	// residuals to multiples of quantization levels up to max_quantization
  29822 //	// (the actual quantization level depends on smoothness near the given pixel).
  29823 func CopyImageWithPrediction(tls *libc.TLS, width int32, height int32, bits int32, modes uintptr, argb_scratch uintptr, argb uintptr, low_effort int32, max_quantization int32, exact int32, used_subtract_green int32) {
  29824 	var current_max_diffs, current_row, lower_max_diffs, tmp32, tmp8, upper_row uintptr
  29825 	var mode, tiles_per_row, x, x_end, y int32
  29826 	var v1, v2 uint32_t
  29827 	_, _, _, _, _, _, _, _, _, _, _, _, _ = current_max_diffs, current_row, lower_max_diffs, mode, tiles_per_row, tmp32, tmp8, upper_row, x, x_end, y, v1, v2
  29828 	v1 = libc.Uint32FromInt32(bits)
  29829 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  29830 	goto _3
  29831 _3:
  29832 	tiles_per_row = libc.Int32FromUint32(v2)
  29833 	// The width of upper_row and current_row is one pixel larger than image width
  29834 	// to allow the top right pixel to point to the leftmost pixel of the next row
  29835 	// when at the right edge.
  29836 	upper_row = argb_scratch
  29837 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  29838 	current_max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  29839 	lower_max_diffs = current_max_diffs + uintptr(width)
  29840 	y = 0
  29841 	for {
  29842 		if !(y < height) {
  29843 			break
  29844 		}
  29845 		tmp32 = upper_row
  29846 		upper_row = current_row
  29847 		current_row = tmp32
  29848 		libc.Xmemcpy(tls, current_row, argb+uintptr(y*width)*4, uint64(4)*libc.Uint64FromInt32(width+libc.BoolInt32(y+libc.Int32FromInt32(1) < height)))
  29849 		if low_effort != 0 {
  29850 			PredictBatch(tls, kPredLowEffort, 0, y, width, current_row, upper_row, argb+uintptr(y*width)*4)
  29851 		} else {
  29852 			if max_quantization > int32(1) {
  29853 				// Compute max_diffs for the lower row now, because that needs the
  29854 				// contents of argb for the current row, which we will overwrite with
  29855 				// residuals before proceeding with the next row.
  29856 				tmp8 = current_max_diffs
  29857 				current_max_diffs = lower_max_diffs
  29858 				lower_max_diffs = tmp8
  29859 				if y+int32(2) < height {
  29860 					MaxDiffsForRow(tls, width, width, argb+uintptr((y+int32(1))*width)*4, lower_max_diffs, used_subtract_green)
  29861 				}
  29862 			}
  29863 			x = 0
  29864 			for {
  29865 				if !(x < width) {
  29866 					break
  29867 				}
  29868 				mode = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(modes + uintptr(y>>bits*tiles_per_row+x>>bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  29869 				x_end = x + int32(1)<<bits
  29870 				if x_end > width {
  29871 					x_end = width
  29872 				}
  29873 				GetResidual(tls, width, height, upper_row, current_row, current_max_diffs, mode, x, x_end, y, max_quantization, exact, used_subtract_green, argb+uintptr(y*width)*4+uintptr(x)*4)
  29874 				x = x_end
  29875 				goto _5
  29876 			_5:
  29877 			}
  29878 		}
  29879 		goto _4
  29880 	_4:
  29881 		;
  29882 		y = y + 1
  29883 	}
  29884 }
  29885 
  29886 // C documentation
  29887 //
  29888 //	// Checks whether 'image' can be subsampled by finding the biggest power of 2
  29889 //	// squares (defined by 'best_bits') of uniform value it is made out of.
  29890 func VP8LOptimizeSampling(tls *libc.TLS, image uintptr, full_width int32, full_height int32, bits int32, max_bits int32, best_bits_out uintptr) {
  29891 	var best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y int32
  29892 	var v1, v2, v4, v5 uint32_t
  29893 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y, v1, v2, v4, v5
  29894 	v1 = libc.Uint32FromInt32(bits)
  29895 	v2 = (libc.Uint32FromInt32(full_width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  29896 	goto _3
  29897 _3:
  29898 	width = libc.Int32FromUint32(v2)
  29899 	v4 = libc.Uint32FromInt32(bits)
  29900 	v5 = (libc.Uint32FromInt32(full_height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  29901 	goto _6
  29902 _6:
  29903 	height = libc.Int32FromUint32(v5)
  29904 	best_bits = bits
  29905 	**(**int32)(__ccgo_up(best_bits_out)) = bits
  29906 	// Check rows first.
  29907 	for best_bits < max_bits {
  29908 		new_square_size = int32(1) << (best_bits + int32(1) - bits)
  29909 		is_good = int32(1)
  29910 		square_size = int32(1) << (best_bits - bits)
  29911 		y = 0
  29912 		for {
  29913 			if !(y+square_size < height) {
  29914 				break
  29915 			}
  29916 			// Check the first lines of consecutive line groups.
  29917 			if libc.Xmemcmp(tls, image+uintptr(y*width)*4, image+uintptr((y+square_size)*width)*4, libc.Uint64FromInt32(width)*uint64(4)) != 0 {
  29918 				is_good = 0
  29919 				break
  29920 			}
  29921 			goto _7
  29922 		_7:
  29923 			;
  29924 			y = y + new_square_size
  29925 		}
  29926 		if is_good != 0 {
  29927 			best_bits = best_bits + 1
  29928 		} else {
  29929 			break
  29930 		}
  29931 	}
  29932 	if best_bits == bits {
  29933 		return
  29934 	}
  29935 	// Check columns.
  29936 	for best_bits > bits {
  29937 		is_good1 = int32(1)
  29938 		square_size = int32(1) << (best_bits - bits)
  29939 		y = 0
  29940 		for {
  29941 			if !(is_good1 != 0 && y < height) {
  29942 				break
  29943 			}
  29944 			x = 0
  29945 			for {
  29946 				if !(is_good1 != 0 && x < width) {
  29947 					break
  29948 				}
  29949 				i = x + int32(1)
  29950 				for {
  29951 					if !(i < GetMin(tls, x+square_size, width)) {
  29952 						break
  29953 					}
  29954 					if **(**uint32_t)(__ccgo_up(image + uintptr(y*width+i)*4)) != **(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) {
  29955 						is_good1 = 0
  29956 						break
  29957 					}
  29958 					goto _10
  29959 				_10:
  29960 					;
  29961 					i = i + 1
  29962 				}
  29963 				goto _9
  29964 			_9:
  29965 				;
  29966 				x = x + square_size
  29967 			}
  29968 			goto _8
  29969 		_8:
  29970 			;
  29971 			y = y + 1
  29972 		}
  29973 		if is_good1 != 0 {
  29974 			break
  29975 		}
  29976 		best_bits = best_bits - 1
  29977 	}
  29978 	if best_bits == bits {
  29979 		return
  29980 	}
  29981 	// Subsample the image.
  29982 	old_width = width
  29983 	square_size = int32(1) << (best_bits - bits)
  29984 	v1 = libc.Uint32FromInt32(best_bits)
  29985 	v2 = (libc.Uint32FromInt32(full_width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  29986 	goto _13
  29987 _13:
  29988 	width = libc.Int32FromUint32(v2)
  29989 	v1 = libc.Uint32FromInt32(best_bits)
  29990 	v2 = (libc.Uint32FromInt32(full_height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  29991 	goto _16
  29992 _16:
  29993 	height = libc.Int32FromUint32(v2)
  29994 	y = 0
  29995 	for {
  29996 		if !(y < height) {
  29997 			break
  29998 		}
  29999 		x = 0
  30000 		for {
  30001 			if !(x < width) {
  30002 				break
  30003 			}
  30004 			**(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) = **(**uint32_t)(__ccgo_up(image + uintptr(square_size*(y*old_width+x))*4))
  30005 			goto _18
  30006 		_18:
  30007 			;
  30008 			x = x + 1
  30009 		}
  30010 		goto _17
  30011 	_17:
  30012 		;
  30013 		y = y + 1
  30014 	}
  30015 	**(**int32)(__ccgo_up(best_bits_out)) = best_bits
  30016 }
  30017 
  30018 // C documentation
  30019 //
  30020 //	// Computes the best predictor image.
  30021 //	// Finds the best predictors per tile. Once done, finds the best predictor image
  30022 //	// sampling.
  30023 //	// best_bits is set to 0 in case of error.
  30024 //	// The following requires some glossary:
  30025 //	// - a tile is a square of side 2^min_bits pixels.
  30026 //	// - a super-tile of a tile is a square of side 2^bits pixels with bits in
  30027 //	// [min_bits+1, max_bits].
  30028 //	// - the max-tile of a tile is the square of 2^max_bits pixels containing it.
  30029 //	//   If this max-tile crosses the border of an image, it is cropped.
  30030 //	// - tile, super-tiles and max_tile are aligned on powers of 2 in the original
  30031 //	//   image.
  30032 //	// - coordinates for tile, super-tile, max-tile are respectively named
  30033 //	//   tile_x, super_tile_x, max_tile_x at their bit scale.
  30034 //	// - in the max-tile, a tile has local coordinates (local_tile_x, local_tile_y).
  30035 //	// The tiles are processed in the following zigzag order to complete the
  30036 //	// super-tiles as soon as possible:
  30037 //	//   1  2|  5  6
  30038 //	//   3  4|  7  8
  30039 //	// --------------
  30040 //	//   9 10| 13 14
  30041 //	//  11 12| 15 16
  30042 //	// When computing the residuals for a tile, the histogram of the above
  30043 //	// super-tile is updated. If this super-tile is finished, its histogram is used
  30044 //	// to update the histogram of the next super-tile and so on up to the max-tile.
  30045 func GetBestPredictorsAndSubSampling(tls *libc.TLS, width int32, height int32, min_bits int32, max_bits int32, argb_scratch uintptr, argb uintptr, max_quantization int32, exact int32, used_subtract_green int32, pic uintptr, percent_range int32, percent uintptr, all_modes uintptr, best_bits uintptr, best_mode uintptr) {
  30046 	var accumulated, all_accumulated_argb, all_argb, all_pred_histos, raw_data uintptr
  30047 	var best_cost, cost int64_t
  30048 	var coord_x, coord_y, local_tile_x, local_tile_y, max_subsampling_index, max_tile_x, max_tile_y, subsampling_index, super_tile_x, super_tile_y, super_tiles_per_row, tile_x, tile_y, tiles_per_col, tiles_per_row, update_up_to_index, v1, v2, v4, v5 uint32_t
  30049 	var max_tile_size, num_accumulated_rgb, num_argb, num_predictors, percent_start, plane int32
  30050 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = accumulated, all_accumulated_argb, all_argb, all_pred_histos, best_cost, coord_x, coord_y, cost, local_tile_x, local_tile_y, max_subsampling_index, max_tile_size, max_tile_x, max_tile_y, num_accumulated_rgb, num_argb, num_predictors, percent_start, plane, raw_data, subsampling_index, super_tile_x, super_tile_y, super_tiles_per_row, tile_x, tile_y, tiles_per_col, tiles_per_row, update_up_to_index, v1, v2, v4, v5
  30051 	v1 = libc.Uint32FromInt32(min_bits)
  30052 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30053 	goto _3
  30054 _3:
  30055 	tiles_per_row = v2
  30056 	v4 = libc.Uint32FromInt32(min_bits)
  30057 	v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30058 	goto _6
  30059 _6:
  30060 	tiles_per_col = v5
  30061 	max_subsampling_index = libc.Uint32FromInt32(max_bits - min_bits)
  30062 	// Compute the needed memory size for residual histograms, accumulated
  30063 	// residual histograms and predictor histograms.
  30064 	num_argb = libc.Int32FromUint32((max_subsampling_index + uint32(1)) * libc.Uint32FromInt32(kNumPredModes) * libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30065 	num_accumulated_rgb = libc.Int32FromUint32((max_subsampling_index + uint32(1)) * libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30066 	num_predictors = libc.Int32FromUint32((max_subsampling_index + uint32(1)) * libc.Uint32FromInt32(kNumPredModes))
  30067 	raw_data = WebPSafeCalloc(tls, libc.Uint64FromInt32(num_argb+num_accumulated_rgb+num_predictors), uint64(4))
  30068 	all_argb = raw_data
  30069 	all_accumulated_argb = all_argb + uintptr(num_argb)*4
  30070 	all_pred_histos = all_accumulated_argb + uintptr(num_accumulated_rgb)*4
  30071 	max_tile_size = int32(1) << max_subsampling_index // in tile size
  30072 	percent_start = **(**int32)(__ccgo_up(percent))
  30073 	// When using the residuals of a tile for its super-tiles, you can either:
  30074 	// - use each residual to update the histogram of the super-tile, with a cost
  30075 	//   of 4 * (1<<n)^2 increment operations (4 for the number of channels, and
  30076 	//   (1<<n)^2 for the number of pixels in the tile)
  30077 	// - use the histogram of the tile to update the histogram of the super-tile,
  30078 	//   with a cost of HISTO_SIZE (1024)
  30079 	// The first method is therefore faster until n==4. 'update_up_to_index'
  30080 	// defines the maximum subsampling_index for which the residuals should be
  30081 	// individually added to the super-tile histogram.
  30082 	update_up_to_index = libc.Uint32FromInt32(GetMax(tls, GetMin(tls, int32(4), max_bits), min_bits) - min_bits)
  30083 	// Coordinates in the max-tile in tile units.
  30084 	local_tile_x = uint32(0)
  30085 	local_tile_y = uint32(0)
  30086 	max_tile_x = uint32(0)
  30087 	max_tile_y = uint32(0)
  30088 	tile_x = uint32(0)
  30089 	tile_y = uint32(0)
  30090 	**(**int32)(__ccgo_up(best_bits)) = 0
  30091 	**(**uintptr)(__ccgo_up(best_mode)) = libc.UintptrFromInt32(0)
  30092 	if raw_data == libc.UintptrFromInt32(0) {
  30093 		return
  30094 	}
  30095 	for tile_y < tiles_per_col {
  30096 		ComputeResidualsForTile(tls, width, height, libc.Int32FromUint32(tile_x), libc.Int32FromUint32(tile_y), min_bits, update_up_to_index, all_argb, argb_scratch, argb, max_quantization, exact, used_subtract_green)
  30097 		// Update all the super-tiles that are complete.
  30098 		subsampling_index = uint32(0)
  30099 		for int32(1) != 0 {
  30100 			super_tile_x = tile_x >> subsampling_index
  30101 			super_tile_y = tile_y >> subsampling_index
  30102 			v1 = libc.Uint32FromInt32(min_bits) + subsampling_index
  30103 			v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30104 			goto _9
  30105 		_9:
  30106 			super_tiles_per_row = v2
  30107 			GetBestPredictorForTile(tls, all_argb, libc.Int32FromUint32(subsampling_index), libc.Int32FromUint32(super_tile_x), libc.Int32FromUint32(super_tile_y), libc.Int32FromUint32(super_tiles_per_row), all_accumulated_argb, all_modes, all_pred_histos)
  30108 			if subsampling_index == max_subsampling_index {
  30109 				break
  30110 			}
  30111 			// Update the following super-tile histogram if it has not been updated
  30112 			// yet.
  30113 			subsampling_index = subsampling_index + 1
  30114 			if subsampling_index > update_up_to_index && subsampling_index <= max_subsampling_index {
  30115 				(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, GetHistoArgbConst(tls, all_argb, libc.Int32FromUint32(subsampling_index-uint32(1)), 0), GetHistoArgb(tls, all_argb, libc.Int32FromUint32(subsampling_index), 0), libc.Int32FromInt32(4)*libc.Int32FromInt32(256)*kNumPredModes)
  30116 			}
  30117 			// Check whether the super-tile is not complete (if the smallest tile
  30118 			// is not at the end of a line/column or at the beginning of a super-tile
  30119 			// of size (1 << subsampling_index)).
  30120 			if !((tile_x == tiles_per_row-uint32(1) || (local_tile_x+uint32(1))%libc.Uint32FromInt32(libc.Int32FromInt32(1)<<subsampling_index) == uint32(0)) && (tile_y == tiles_per_col-uint32(1) || (local_tile_y+uint32(1))%libc.Uint32FromInt32(libc.Int32FromInt32(1)<<subsampling_index) == uint32(0))) {
  30121 				subsampling_index = subsampling_index - 1
  30122 				// subsampling_index now is the index of the last finished super-tile.
  30123 				break
  30124 			}
  30125 		}
  30126 		// Reset all the histograms belonging to finished tiles.
  30127 		libc.Xmemset(tls, all_argb, 0, uint64(libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)*kNumPredModes)*(subsampling_index+uint32(1)))*uint64(4))
  30128 		if subsampling_index == max_subsampling_index {
  30129 			// If a new max-tile is started.
  30130 			if tile_x == tiles_per_row-uint32(1) {
  30131 				max_tile_x = uint32(0)
  30132 				max_tile_y = max_tile_y + 1
  30133 			} else {
  30134 				max_tile_x = max_tile_x + 1
  30135 			}
  30136 			local_tile_x = uint32(0)
  30137 			local_tile_y = uint32(0)
  30138 		} else {
  30139 			// Proceed with the Z traversal.
  30140 			coord_x = local_tile_x >> subsampling_index
  30141 			coord_y = local_tile_y >> subsampling_index
  30142 			if tile_x == tiles_per_row-uint32(1) && coord_x%uint32(2) == uint32(0) {
  30143 				coord_y = coord_y + 1
  30144 			} else {
  30145 				if coord_x%uint32(2) == uint32(0) {
  30146 					coord_x = coord_x + 1
  30147 				} else {
  30148 					// Z traversal.
  30149 					coord_y = coord_y + 1
  30150 					coord_x = coord_x - 1
  30151 				}
  30152 			}
  30153 			local_tile_x = coord_x << subsampling_index
  30154 			local_tile_y = coord_y << subsampling_index
  30155 		}
  30156 		tile_x = max_tile_x*libc.Uint32FromInt32(max_tile_size) + local_tile_x
  30157 		tile_y = max_tile_y*libc.Uint32FromInt32(max_tile_size) + local_tile_y
  30158 		if tile_x == uint32(0) && !(WebPReportProgress(tls, pic, libc.Int32FromUint32(libc.Uint32FromInt32(percent_start)+libc.Uint32FromInt32(percent_range)*tile_y/tiles_per_col), percent) != 0) {
  30159 			WebPSafeFree(tls, raw_data)
  30160 			return
  30161 		}
  30162 	}
  30163 	// Figure out the best sampling.
  30164 	best_cost = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  30165 	subsampling_index = uint32(0)
  30166 	for {
  30167 		if !(subsampling_index <= max_subsampling_index) {
  30168 			break
  30169 		}
  30170 		accumulated = GetAccumulatedHisto(tls, all_accumulated_argb, libc.Int32FromUint32(subsampling_index))
  30171 		cost = libc.Int64FromUint64((*(*func(*libc.TLS, uintptr, int32) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LShannonEntropy})))(tls, all_pred_histos+uintptr(subsampling_index*libc.Uint32FromInt32(kNumPredModes))*4, kNumPredModes))
  30172 		plane = 0
  30173 		for {
  30174 			if !(plane < int32(4)) {
  30175 				break
  30176 			}
  30177 			cost = libc.Int64FromUint64(uint64(cost) + (*(*func(*libc.TLS, uintptr, int32) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LShannonEntropy})))(tls, accumulated+uintptr(plane*int32(256))*4, int32(256)))
  30178 			goto _11
  30179 		_11:
  30180 			;
  30181 			plane = plane + 1
  30182 		}
  30183 		if cost < best_cost {
  30184 			best_cost = cost
  30185 			**(**int32)(__ccgo_up(best_bits)) = libc.Int32FromUint32(libc.Uint32FromInt32(min_bits) + subsampling_index)
  30186 			**(**uintptr)(__ccgo_up(best_mode)) = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  30187 		}
  30188 		goto _10
  30189 	_10:
  30190 		;
  30191 		subsampling_index = subsampling_index + 1
  30192 	}
  30193 	WebPSafeFree(tls, raw_data)
  30194 	VP8LOptimizeSampling(tls, **(**uintptr)(__ccgo_up(best_mode)), width, height, **(**int32)(__ccgo_up(best_bits)), libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), best_bits)
  30195 }
  30196 
  30197 // C documentation
  30198 //
  30199 //	// Finds the best predictor for each tile, and converts the image to residuals
  30200 //	// with respect to predictions. If near_lossless_quality < 100, applies
  30201 //	// near lossless processing, shaving off more bits of residuals for lower
  30202 //	// qualities.
  30203 func VP8LResidualImage(tls *libc.TLS, width int32, height int32, min_bits int32, max_bits int32, low_effort int32, argb uintptr, argb_scratch uintptr, image uintptr, near_lossless_quality1 int32, exact int32, used_subtract_green int32, pic uintptr, percent_range int32, percent uintptr, best_bits uintptr) (r int32) {
  30204 	bp := tls.Alloc(96)
  30205 	defer tls.Free(96)
  30206 	var bits, i, max_quantization, percent_start, tiles_per_col, tiles_per_col1, tiles_per_row, tiles_per_row1, v1 int32
  30207 	var modes_raw uintptr
  30208 	var num_pixels [10]uint32_t
  30209 	var sum_num_pixels, v3, v4, v6, v7 uint32_t
  30210 	var _ /* best_mode at bp+0 */ uintptr
  30211 	var _ /* modes at bp+8 */ [10]uintptr
  30212 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bits, i, max_quantization, modes_raw, num_pixels, percent_start, sum_num_pixels, tiles_per_col, tiles_per_col1, tiles_per_row, tiles_per_row1, v1, v3, v4, v6, v7
  30213 	percent_start = **(**int32)(__ccgo_up(percent))
  30214 	v1 = int32(5) - near_lossless_quality1/int32(20)
  30215 	goto _2
  30216 _2:
  30217 	max_quantization = int32(1) << v1
  30218 	if low_effort != 0 {
  30219 		v3 = libc.Uint32FromInt32(max_bits)
  30220 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30221 		goto _5
  30222 	_5:
  30223 		tiles_per_row = libc.Int32FromUint32(v4)
  30224 		v6 = libc.Uint32FromInt32(max_bits)
  30225 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30226 		goto _8
  30227 	_8:
  30228 		tiles_per_col = libc.Int32FromUint32(v7)
  30229 		i = 0
  30230 		for {
  30231 			if !(i < tiles_per_row*tiles_per_col) {
  30232 				break
  30233 			}
  30234 			**(**uint32_t)(__ccgo_up(image + uintptr(i)*4)) = uint32(ARGB_BLACK1) | libc.Uint32FromInt32(kPredLowEffort<<libc.Int32FromInt32(8))
  30235 			goto _9
  30236 		_9:
  30237 			;
  30238 			i = i + 1
  30239 		}
  30240 		**(**int32)(__ccgo_up(best_bits)) = max_bits
  30241 	} else {
  30242 		sum_num_pixels = 0
  30243 		bits = min_bits
  30244 		for {
  30245 			if !(bits <= max_bits) {
  30246 				break
  30247 			}
  30248 			v3 = libc.Uint32FromInt32(bits)
  30249 			v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30250 			goto _13
  30251 		_13:
  30252 			tiles_per_row1 = libc.Int32FromUint32(v4)
  30253 			v6 = libc.Uint32FromInt32(bits)
  30254 			v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30255 			goto _16
  30256 		_16:
  30257 			tiles_per_col1 = libc.Int32FromUint32(v7)
  30258 			num_pixels[bits] = libc.Uint32FromInt32(tiles_per_row1 * tiles_per_col1)
  30259 			sum_num_pixels = sum_num_pixels + num_pixels[bits]
  30260 			goto _10
  30261 		_10:
  30262 			;
  30263 			bits = bits + 1
  30264 		}
  30265 		modes_raw = WebPSafeMalloc(tls, uint64(sum_num_pixels), uint64(4))
  30266 		if modes_raw == libc.UintptrFromInt32(0) {
  30267 			return 0
  30268 		}
  30269 		// Have modes point to the right global memory modes_raw.
  30270 		(**(**[10]uintptr)(__ccgo_up(bp + 8)))[min_bits] = modes_raw
  30271 		bits = min_bits + int32(1)
  30272 		for {
  30273 			if !(bits <= max_bits) {
  30274 				break
  30275 			}
  30276 			(**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits] = (**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits-int32(1)] + uintptr(num_pixels[bits-int32(1)])*4
  30277 			goto _17
  30278 		_17:
  30279 			;
  30280 			bits = bits + 1
  30281 		}
  30282 		// Find the best sampling.
  30283 		GetBestPredictorsAndSubSampling(tls, width, height, min_bits, max_bits, argb_scratch, argb, max_quantization, exact, used_subtract_green, pic, percent_range, percent, bp+8+uintptr(min_bits)*8, best_bits, bp)
  30284 		if **(**int32)(__ccgo_up(best_bits)) == 0 {
  30285 			WebPSafeFree(tls, modes_raw)
  30286 			return 0
  30287 		}
  30288 		// Keep the best predictor image.
  30289 		v3 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  30290 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30291 		goto _20
  30292 	_20:
  30293 		v6 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  30294 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30295 		goto _23
  30296 	_23:
  30297 		libc.Xmemcpy(tls, image, **(**uintptr)(__ccgo_up(bp)), uint64(v4*v7)*uint64(4))
  30298 		WebPSafeFree(tls, modes_raw)
  30299 	}
  30300 	CopyImageWithPrediction(tls, width, height, **(**int32)(__ccgo_up(best_bits)), image, argb_scratch, argb, low_effort, max_quantization, exact, used_subtract_green)
  30301 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  30302 }
  30303 
  30304 //------------------------------------------------------------------------------
  30305 // Color transform functions.
  30306 
  30307 func MultipliersClear(tls *libc.TLS, m uintptr) {
  30308 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(0)
  30309 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(0)
  30310 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(0)
  30311 }
  30312 
  30313 func ColorCodeToMultipliers(tls *libc.TLS, color_code uint32_t, m uintptr) {
  30314 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  30315 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  30316 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  30317 }
  30318 
  30319 func MultipliersToColorCode(tls *libc.TLS, m uintptr) (r uint32_t) {
  30320 	return uint32(0xff000000) | uint32((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue)<<libc.Int32FromInt32(16) | uint32((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue)<<libc.Int32FromInt32(8) | uint32((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red)
  30321 }
  30322 
  30323 func PredictionCostCrossColor(tls *libc.TLS, accumulated uintptr, counts uintptr) (r int64_t) {
  30324 	return libc.Int64FromUint64((*(*func(*libc.TLS, uintptr, uintptr) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LCombinedShannonEntropy})))(tls, counts, accumulated)) + PredictionCostBias(tls, counts, uint64(3), kExpValue)
  30325 }
  30326 
  30327 // Favor low entropy, locally and globally.
  30328 // Favor small absolute values for PredictionCostSpatial
  30329 var kExpValue = uint64(240)
  30330 
  30331 func GetPredictionCostCrossColorRed(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, prev_x VP8LMultipliers, prev_y VP8LMultipliers, green_to_red int32, accumulated_red_histo uintptr) (r int64_t) {
  30332 	bp := tls.Alloc(1024)
  30333 	defer tls.Free(1024)
  30334 	var cur_diff int64_t
  30335 	var _ /* histo at bp+0 */ [256]uint32_t
  30336 	_ = cur_diff
  30337 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30338 	(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LCollectColorRedTransforms})))(tls, argb, stride, tile_width, tile_height, green_to_red, bp)
  30339 	cur_diff = PredictionCostCrossColor(tls, accumulated_red_histo, bp)
  30340 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_red)) == libc.Int32FromUint8(prev_x.Fgreen_to_red) {
  30341 		// favor keeping the areas locally similar
  30342 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30343 	}
  30344 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_red)) == libc.Int32FromUint8(prev_y.Fgreen_to_red) {
  30345 		// favor keeping the areas locally similar
  30346 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30347 	}
  30348 	if green_to_red == 0 {
  30349 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30350 	}
  30351 	return cur_diff
  30352 }
  30353 
  30354 func GetBestGreenToRed(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, prev_x VP8LMultipliers, prev_y VP8LMultipliers, quality int32, accumulated_red_histo uintptr, best_tx uintptr) {
  30355 	var best_diff, cur_diff int64_t
  30356 	var delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset int32
  30357 	_, _, _, _, _, _, _, _ = best_diff, cur_diff, delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset
  30358 	kMaxIters = int32(4) + int32(7)*quality>>int32(8) // in range [4..6]
  30359 	green_to_red_best = 0
  30360 	best_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_best, accumulated_red_histo)
  30361 	iter = 0
  30362 	for {
  30363 		if !(iter < kMaxIters) {
  30364 			break
  30365 		}
  30366 		// ColorTransformDelta is a 3.5 bit fixed point, so 32 is equal to
  30367 		// one in color computation. Having initial delta here as 1 is sufficient
  30368 		// to explore the range of (-2, 2).
  30369 		delta = int32(32) >> iter
  30370 		// Try a negative and a positive delta from the best known value.
  30371 		offset = -delta
  30372 		for {
  30373 			if !(offset <= delta) {
  30374 				break
  30375 			}
  30376 			green_to_red_cur = offset + green_to_red_best
  30377 			cur_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_cur, accumulated_red_histo)
  30378 			if cur_diff < best_diff {
  30379 				best_diff = cur_diff
  30380 				green_to_red_best = green_to_red_cur
  30381 			}
  30382 			goto _2
  30383 		_2:
  30384 			;
  30385 			offset = offset + int32(2)*delta
  30386 		}
  30387 		goto _1
  30388 	_1:
  30389 		;
  30390 		iter = iter + 1
  30391 	}
  30392 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_red = libc.Uint8FromInt32(green_to_red_best & libc.Int32FromInt32(0xff))
  30393 }
  30394 
  30395 func GetPredictionCostCrossColorBlue(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, prev_x VP8LMultipliers, prev_y VP8LMultipliers, green_to_blue int32, red_to_blue int32, accumulated_blue_histo uintptr) (r int64_t) {
  30396 	bp := tls.Alloc(1024)
  30397 	defer tls.Free(1024)
  30398 	var cur_diff int64_t
  30399 	var _ /* histo at bp+0 */ [256]uint32_t
  30400 	_ = cur_diff
  30401 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30402 	(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LCollectColorBlueTransforms})))(tls, argb, stride, tile_width, tile_height, green_to_blue, red_to_blue, bp)
  30403 	cur_diff = PredictionCostCrossColor(tls, accumulated_blue_histo, bp)
  30404 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_blue)) == libc.Int32FromUint8(prev_x.Fgreen_to_blue) {
  30405 		// favor keeping the areas locally similar
  30406 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30407 	}
  30408 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_blue)) == libc.Int32FromUint8(prev_y.Fgreen_to_blue) {
  30409 		// favor keeping the areas locally similar
  30410 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30411 	}
  30412 	if libc.Int32FromUint8(libc.Uint8FromInt32(red_to_blue)) == libc.Int32FromUint8(prev_x.Fred_to_blue) {
  30413 		// favor keeping the areas locally similar
  30414 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30415 	}
  30416 	if libc.Int32FromUint8(libc.Uint8FromInt32(red_to_blue)) == libc.Int32FromUint8(prev_y.Fred_to_blue) {
  30417 		// favor keeping the areas locally similar
  30418 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30419 	}
  30420 	if green_to_blue == 0 {
  30421 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30422 	}
  30423 	if red_to_blue == 0 {
  30424 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30425 	}
  30426 	return cur_diff
  30427 }
  30428 
  30429 func GetBestGreenRedToBlue(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, prev_x VP8LMultipliers, prev_y VP8LMultipliers, quality int32, accumulated_blue_histo uintptr, best_tx uintptr) {
  30430 	bp := tls.Alloc(16)
  30431 	defer tls.Free(16)
  30432 	var axis, delta, green_to_blue_best, green_to_blue_cur, iter, iters, red_to_blue_best, red_to_blue_cur, v1, v2 int32
  30433 	var best_diff, cur_diff int64_t
  30434 	var delta_lut [7]int8_t
  30435 	var _ /* offset at bp+0 */ [8][2]int8_t
  30436 	_, _, _, _, _, _, _, _, _, _, _, _, _ = axis, best_diff, cur_diff, delta, delta_lut, green_to_blue_best, green_to_blue_cur, iter, iters, red_to_blue_best, red_to_blue_cur, v1, v2
  30437 	**(**[8][2]int8_t)(__ccgo_up(bp)) = [8][2]int8_t{
  30438 		0: {
  30439 			1: int8(-int32(1)),
  30440 		},
  30441 		1: {
  30442 			1: int8(1),
  30443 		},
  30444 		2: {
  30445 			0: int8(-int32(1)),
  30446 		},
  30447 		3: {
  30448 			0: int8(1),
  30449 		},
  30450 		4: {
  30451 			0: int8(-int32(1)),
  30452 			1: int8(-int32(1)),
  30453 		},
  30454 		5: {
  30455 			0: int8(-int32(1)),
  30456 			1: int8(1),
  30457 		},
  30458 		6: {
  30459 			0: int8(1),
  30460 			1: int8(-int32(1)),
  30461 		},
  30462 		7: {
  30463 			0: int8(1),
  30464 			1: int8(1),
  30465 		},
  30466 	}
  30467 	delta_lut = [7]int8_t{
  30468 		0: int8(16),
  30469 		1: int8(16),
  30470 		2: int8(8),
  30471 		3: int8(4),
  30472 		4: int8(2),
  30473 		5: int8(2),
  30474 		6: int8(2),
  30475 	}
  30476 	if quality < int32(25) {
  30477 		v1 = int32(1)
  30478 	} else {
  30479 		if quality > int32(50) {
  30480 			v2 = int32(7)
  30481 		} else {
  30482 			v2 = int32(4)
  30483 		}
  30484 		v1 = v2
  30485 	}
  30486 	iters = v1
  30487 	green_to_blue_best = 0
  30488 	red_to_blue_best = 0
  30489 	// Initial value at origin:
  30490 	best_diff = GetPredictionCostCrossColorBlue(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_blue_best, red_to_blue_best, accumulated_blue_histo)
  30491 	iter = 0
  30492 	for {
  30493 		if !(iter < iters) {
  30494 			break
  30495 		}
  30496 		delta = int32(delta_lut[iter])
  30497 		axis = 0
  30498 		for {
  30499 			if !(axis < int32(8)) {
  30500 				break
  30501 			}
  30502 			green_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2)))*delta + green_to_blue_best
  30503 			red_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2 + 1)))*delta + red_to_blue_best
  30504 			cur_diff = GetPredictionCostCrossColorBlue(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_blue_cur, red_to_blue_cur, accumulated_blue_histo)
  30505 			if cur_diff < best_diff {
  30506 				best_diff = cur_diff
  30507 				green_to_blue_best = green_to_blue_cur
  30508 				red_to_blue_best = red_to_blue_cur
  30509 			}
  30510 			if quality < int32(25) && iter == int32(4) {
  30511 				// Only axis aligned diffs for lower quality.
  30512 				break // next iter.
  30513 			}
  30514 			goto _4
  30515 		_4:
  30516 			;
  30517 			axis = axis + 1
  30518 		}
  30519 		if delta == int32(2) && green_to_blue_best == 0 && red_to_blue_best == 0 {
  30520 			// Further iterations would not help.
  30521 			break // out of iter-loop.
  30522 		}
  30523 		goto _3
  30524 	_3:
  30525 		;
  30526 		iter = iter + 1
  30527 	}
  30528 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_blue = libc.Uint8FromInt32(green_to_blue_best & int32(0xff))
  30529 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fred_to_blue = libc.Uint8FromInt32(red_to_blue_best & int32(0xff))
  30530 }
  30531 
  30532 func GetBestColorTransformForTile(tls *libc.TLS, tile_x int32, tile_y int32, bits int32, prev_x VP8LMultipliers, prev_y VP8LMultipliers, quality int32, xsize int32, ysize int32, accumulated_red_histo uintptr, accumulated_blue_histo uintptr, argb uintptr) (r VP8LMultipliers) {
  30533 	bp := tls.Alloc(16)
  30534 	defer tls.Free(16)
  30535 	var all_x_max, all_y_max, max_tile_size, tile_height, tile_width, tile_x_offset, tile_y_offset int32
  30536 	var tile_argb uintptr
  30537 	var _ /* best_tx at bp+0 */ VP8LMultipliers
  30538 	_, _, _, _, _, _, _, _ = all_x_max, all_y_max, max_tile_size, tile_argb, tile_height, tile_width, tile_x_offset, tile_y_offset
  30539 	max_tile_size = int32(1) << bits
  30540 	tile_y_offset = tile_y * max_tile_size
  30541 	tile_x_offset = tile_x * max_tile_size
  30542 	all_x_max = GetMin(tls, tile_x_offset+max_tile_size, xsize)
  30543 	all_y_max = GetMin(tls, tile_y_offset+max_tile_size, ysize)
  30544 	tile_width = all_x_max - tile_x_offset
  30545 	tile_height = all_y_max - tile_y_offset
  30546 	tile_argb = argb + uintptr(tile_y_offset*xsize)*4 + uintptr(tile_x_offset)*4
  30547 	MultipliersClear(tls, bp)
  30548 	GetBestGreenToRed(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_red_histo, bp)
  30549 	GetBestGreenRedToBlue(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_blue_histo, bp)
  30550 	return **(**VP8LMultipliers)(__ccgo_up(bp))
  30551 }
  30552 
  30553 func CopyTileWithColorTransform(tls *libc.TLS, xsize int32, ysize int32, tile_x int32, tile_y int32, max_tile_size int32, _color_transform VP8LMultipliers, argb uintptr) {
  30554 	bp := tls.Alloc(16)
  30555 	defer tls.Free(16)
  30556 	*(*VP8LMultipliers)(unsafe.Pointer(bp)) = _color_transform
  30557 	var xscan, yscan, v1 int32
  30558 	_, _, _ = xscan, yscan, v1
  30559 	xscan = GetMin(tls, max_tile_size, xsize-tile_x)
  30560 	yscan = GetMin(tls, max_tile_size, ysize-tile_y)
  30561 	argb = argb + uintptr(tile_y*xsize+tile_x)*4
  30562 	for {
  30563 		v1 = yscan
  30564 		yscan = yscan - 1
  30565 		if !(v1 > 0) {
  30566 			break
  30567 		}
  30568 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColor})))(tls, bp, argb, xscan)
  30569 		argb = argb + uintptr(xsize)*4
  30570 	}
  30571 }
  30572 
  30573 func VP8LColorSpaceTransform(tls *libc.TLS, width int32, height int32, bits int32, quality int32, argb uintptr, image uintptr, pic uintptr, percent_range int32, percent uintptr, best_bits uintptr) (r int32) {
  30574 	bp := tls.Alloc(2064)
  30575 	defer tls.Free(2064)
  30576 	var all_x_max, all_y_max, ix, ix_end, max_tile_size, offset, percent_start, tile_x, tile_x_offset, tile_xsize, tile_y, tile_y_offset, tile_ysize, y int32
  30577 	var pix, v1, v2, v4, v5 uint32_t
  30578 	var _ /* accumulated_blue_histo at bp+1024 */ [256]uint32_t
  30579 	var _ /* accumulated_red_histo at bp+0 */ [256]uint32_t
  30580 	var _ /* prev_x at bp+2049 */ VP8LMultipliers
  30581 	var _ /* prev_y at bp+2052 */ VP8LMultipliers
  30582 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = all_x_max, all_y_max, ix, ix_end, max_tile_size, offset, percent_start, pix, tile_x, tile_x_offset, tile_xsize, tile_y, tile_y_offset, tile_ysize, y, v1, v2, v4, v5
  30583 	max_tile_size = int32(1) << bits
  30584 	v1 = libc.Uint32FromInt32(bits)
  30585 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30586 	goto _3
  30587 _3:
  30588 	tile_xsize = libc.Int32FromUint32(v2)
  30589 	v4 = libc.Uint32FromInt32(bits)
  30590 	v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30591 	goto _6
  30592 _6:
  30593 	tile_ysize = libc.Int32FromUint32(v5)
  30594 	percent_start = **(**int32)(__ccgo_up(percent))
  30595 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30596 	**(**[256]uint32_t)(__ccgo_up(bp + 1024)) = [256]uint32_t{}
  30597 	MultipliersClear(tls, bp+2052)
  30598 	MultipliersClear(tls, bp+2049)
  30599 	tile_y = 0
  30600 	for {
  30601 		if !(tile_y < tile_ysize) {
  30602 			break
  30603 		}
  30604 		tile_x = 0
  30605 		for {
  30606 			if !(tile_x < tile_xsize) {
  30607 				break
  30608 			}
  30609 			tile_x_offset = tile_x * max_tile_size
  30610 			tile_y_offset = tile_y * max_tile_size
  30611 			all_x_max = GetMin(tls, tile_x_offset+max_tile_size, width)
  30612 			all_y_max = GetMin(tls, tile_y_offset+max_tile_size, height)
  30613 			offset = tile_y*tile_xsize + tile_x
  30614 			if tile_y != 0 {
  30615 				ColorCodeToMultipliers(tls, **(**uint32_t)(__ccgo_up(image + uintptr(offset-tile_xsize)*4)), bp+2052)
  30616 			}
  30617 			**(**VP8LMultipliers)(__ccgo_up(bp + 2049)) = GetBestColorTransformForTile(tls, tile_x, tile_y, bits, **(**VP8LMultipliers)(__ccgo_up(bp + 2049)), **(**VP8LMultipliers)(__ccgo_up(bp + 2052)), quality, width, height, bp, bp+1024, argb)
  30618 			**(**uint32_t)(__ccgo_up(image + uintptr(offset)*4)) = MultipliersToColorCode(tls, bp+2049)
  30619 			CopyTileWithColorTransform(tls, width, height, tile_x_offset, tile_y_offset, max_tile_size, **(**VP8LMultipliers)(__ccgo_up(bp + 2049)), argb)
  30620 			// Gather accumulated histogram data.
  30621 			y = tile_y_offset
  30622 			for {
  30623 				if !(y < all_y_max) {
  30624 					break
  30625 				}
  30626 				ix = y*width + tile_x_offset
  30627 				ix_end = ix + all_x_max - tile_x_offset
  30628 				for {
  30629 					if !(ix < ix_end) {
  30630 						break
  30631 					}
  30632 					pix = **(**uint32_t)(__ccgo_up(argb + uintptr(ix)*4))
  30633 					if ix >= int32(2) && pix == **(**uint32_t)(__ccgo_up(argb + uintptr(ix-int32(2))*4)) && pix == **(**uint32_t)(__ccgo_up(argb + uintptr(ix-int32(1))*4)) {
  30634 						goto _10 // repeated pixels are handled by backward references
  30635 					}
  30636 					if ix >= width+int32(2) && **(**uint32_t)(__ccgo_up(argb + uintptr(ix-int32(2))*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(ix-width-int32(2))*4)) && **(**uint32_t)(__ccgo_up(argb + uintptr(ix-int32(1))*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(ix-width-int32(1))*4)) && pix == **(**uint32_t)(__ccgo_up(argb + uintptr(ix-width)*4)) {
  30637 						goto _10 // repeated pixels are handled by backward references
  30638 					}
  30639 					(**(**[256]uint32_t)(__ccgo_up(bp)))[pix>>libc.Int32FromInt32(16)&uint32(0xff)] = (**(**[256]uint32_t)(__ccgo_up(bp)))[pix>>libc.Int32FromInt32(16)&uint32(0xff)] + 1
  30640 					(**(**[256]uint32_t)(__ccgo_up(bp + 1024)))[pix>>libc.Int32FromInt32(0)&uint32(0xff)] = (**(**[256]uint32_t)(__ccgo_up(bp + 1024)))[pix>>libc.Int32FromInt32(0)&uint32(0xff)] + 1
  30641 					goto _10
  30642 				_10:
  30643 					;
  30644 					ix = ix + 1
  30645 				}
  30646 				goto _9
  30647 			_9:
  30648 				;
  30649 				y = y + 1
  30650 			}
  30651 			goto _8
  30652 		_8:
  30653 			;
  30654 			tile_x = tile_x + 1
  30655 		}
  30656 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*tile_y/tile_ysize, percent) != 0) {
  30657 			return 0
  30658 		}
  30659 		goto _7
  30660 	_7:
  30661 		;
  30662 		tile_y = tile_y + 1
  30663 	}
  30664 	VP8LOptimizeSampling(tls, image, width, height, bits, libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), best_bits)
  30665 	return int32(1)
  30666 }
  30667 
  30668 const DO_TRELLIS_I16 = 1
  30669 const DO_TRELLIS_I4 = 1
  30670 const DO_TRELLIS_UV = 0
  30671 const FLATNESS_LIMIT_I16 = 0
  30672 const FLATNESS_LIMIT_I4 = 3
  30673 const FLATNESS_LIMIT_UV = 2
  30674 const FLATNESS_PENALTY = 140
  30675 const FSTRENGTH_CUTOFF = 2
  30676 const IsFlat = "IsFlat_C"
  30677 const MAX_ALPHA1 = 100
  30678 const MAX_DELTA = 1
  30679 const MAX_DQ_UV = 6
  30680 const MID_ALPHA = 64
  30681 const MIN_ALPHA = 30
  30682 const MIN_DELTA = 0
  30683 const RD_DISTO_MULT = 256
  30684 const SHARPEN_BITS = 11
  30685 const SNS_TO_DQ = 0.9
  30686 const USE_TDISTO = 1
  30687 
  30688 //------------------------------------------------------------------------------
  30689 
  30690 // Copyright 2011 Google Inc. All Rights Reserved.
  30691 //
  30692 // Use of this source code is governed by a BSD-style license
  30693 // that can be found in the COPYING file in the root of the source
  30694 // tree. An additional intellectual property rights grant can be found
  30695 // in the file PATENTS. All contributing project authors may
  30696 // be found in the AUTHORS file in the root of the source tree.
  30697 // -----------------------------------------------------------------------------
  30698 //
  30699 //   WebP encoder: internal header.
  30700 //
  30701 // Author: Skal (pascal.massimino@gmail.com)
  30702 
  30703 // Copyright 2010 Google Inc. All Rights Reserved.
  30704 //
  30705 // Use of this source code is governed by a BSD-style license
  30706 // that can be found in the COPYING file in the root of the source
  30707 // tree. An additional intellectual property rights grant can be found
  30708 // in the file PATENTS. All contributing project authors may
  30709 // be found in the AUTHORS file in the root of the source tree.
  30710 // -----------------------------------------------------------------------------
  30711 //
  30712 //  Common types + memory wrappers
  30713 //
  30714 // Author: Skal (pascal.massimino@gmail.com)
  30715 
  30716 // power-law modulation. Must be strictly less than 1.
  30717 
  30718 // number of non-zero coeffs below which we consider the block very flat
  30719 // (and apply a penalty to complex predictions)
  30720 
  30721 // #define DEBUG_BLOCK
  30722 
  30723 //------------------------------------------------------------------------------
  30724 
  30725 //------------------------------------------------------------------------------
  30726 
  30727 func clip2(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  30728 	var v1, v2 int32
  30729 	_, _ = v1, v2
  30730 	if v < m {
  30731 		v1 = m
  30732 	} else {
  30733 		if v > M {
  30734 			v2 = M
  30735 		} else {
  30736 			v2 = v
  30737 		}
  30738 		v1 = v2
  30739 	}
  30740 	return v1
  30741 }
  30742 
  30743 var kZigzag1 = [16]uint8_t{
  30744 	1:  uint8(1),
  30745 	2:  uint8(4),
  30746 	3:  uint8(8),
  30747 	4:  uint8(5),
  30748 	5:  uint8(2),
  30749 	6:  uint8(3),
  30750 	7:  uint8(6),
  30751 	8:  uint8(9),
  30752 	9:  uint8(12),
  30753 	10: uint8(13),
  30754 	11: uint8(10),
  30755 	12: uint8(7),
  30756 	13: uint8(11),
  30757 	14: uint8(14),
  30758 	15: uint8(15),
  30759 }
  30760 
  30761 var kDcTable1 = [128]uint8_t{
  30762 	0:   uint8(4),
  30763 	1:   uint8(5),
  30764 	2:   uint8(6),
  30765 	3:   uint8(7),
  30766 	4:   uint8(8),
  30767 	5:   uint8(9),
  30768 	6:   uint8(10),
  30769 	7:   uint8(10),
  30770 	8:   uint8(11),
  30771 	9:   uint8(12),
  30772 	10:  uint8(13),
  30773 	11:  uint8(14),
  30774 	12:  uint8(15),
  30775 	13:  uint8(16),
  30776 	14:  uint8(17),
  30777 	15:  uint8(17),
  30778 	16:  uint8(18),
  30779 	17:  uint8(19),
  30780 	18:  uint8(20),
  30781 	19:  uint8(20),
  30782 	20:  uint8(21),
  30783 	21:  uint8(21),
  30784 	22:  uint8(22),
  30785 	23:  uint8(22),
  30786 	24:  uint8(23),
  30787 	25:  uint8(23),
  30788 	26:  uint8(24),
  30789 	27:  uint8(25),
  30790 	28:  uint8(25),
  30791 	29:  uint8(26),
  30792 	30:  uint8(27),
  30793 	31:  uint8(28),
  30794 	32:  uint8(29),
  30795 	33:  uint8(30),
  30796 	34:  uint8(31),
  30797 	35:  uint8(32),
  30798 	36:  uint8(33),
  30799 	37:  uint8(34),
  30800 	38:  uint8(35),
  30801 	39:  uint8(36),
  30802 	40:  uint8(37),
  30803 	41:  uint8(37),
  30804 	42:  uint8(38),
  30805 	43:  uint8(39),
  30806 	44:  uint8(40),
  30807 	45:  uint8(41),
  30808 	46:  uint8(42),
  30809 	47:  uint8(43),
  30810 	48:  uint8(44),
  30811 	49:  uint8(45),
  30812 	50:  uint8(46),
  30813 	51:  uint8(46),
  30814 	52:  uint8(47),
  30815 	53:  uint8(48),
  30816 	54:  uint8(49),
  30817 	55:  uint8(50),
  30818 	56:  uint8(51),
  30819 	57:  uint8(52),
  30820 	58:  uint8(53),
  30821 	59:  uint8(54),
  30822 	60:  uint8(55),
  30823 	61:  uint8(56),
  30824 	62:  uint8(57),
  30825 	63:  uint8(58),
  30826 	64:  uint8(59),
  30827 	65:  uint8(60),
  30828 	66:  uint8(61),
  30829 	67:  uint8(62),
  30830 	68:  uint8(63),
  30831 	69:  uint8(64),
  30832 	70:  uint8(65),
  30833 	71:  uint8(66),
  30834 	72:  uint8(67),
  30835 	73:  uint8(68),
  30836 	74:  uint8(69),
  30837 	75:  uint8(70),
  30838 	76:  uint8(71),
  30839 	77:  uint8(72),
  30840 	78:  uint8(73),
  30841 	79:  uint8(74),
  30842 	80:  uint8(75),
  30843 	81:  uint8(76),
  30844 	82:  uint8(76),
  30845 	83:  uint8(77),
  30846 	84:  uint8(78),
  30847 	85:  uint8(79),
  30848 	86:  uint8(80),
  30849 	87:  uint8(81),
  30850 	88:  uint8(82),
  30851 	89:  uint8(83),
  30852 	90:  uint8(84),
  30853 	91:  uint8(85),
  30854 	92:  uint8(86),
  30855 	93:  uint8(87),
  30856 	94:  uint8(88),
  30857 	95:  uint8(89),
  30858 	96:  uint8(91),
  30859 	97:  uint8(93),
  30860 	98:  uint8(95),
  30861 	99:  uint8(96),
  30862 	100: uint8(98),
  30863 	101: uint8(100),
  30864 	102: uint8(101),
  30865 	103: uint8(102),
  30866 	104: uint8(104),
  30867 	105: uint8(106),
  30868 	106: uint8(108),
  30869 	107: uint8(110),
  30870 	108: uint8(112),
  30871 	109: uint8(114),
  30872 	110: uint8(116),
  30873 	111: uint8(118),
  30874 	112: uint8(122),
  30875 	113: uint8(124),
  30876 	114: uint8(126),
  30877 	115: uint8(128),
  30878 	116: uint8(130),
  30879 	117: uint8(132),
  30880 	118: uint8(134),
  30881 	119: uint8(136),
  30882 	120: uint8(138),
  30883 	121: uint8(140),
  30884 	122: uint8(143),
  30885 	123: uint8(145),
  30886 	124: uint8(148),
  30887 	125: uint8(151),
  30888 	126: uint8(154),
  30889 	127: uint8(157),
  30890 }
  30891 
  30892 var kAcTable1 = [128]uint16_t{
  30893 	0:   uint16(4),
  30894 	1:   uint16(5),
  30895 	2:   uint16(6),
  30896 	3:   uint16(7),
  30897 	4:   uint16(8),
  30898 	5:   uint16(9),
  30899 	6:   uint16(10),
  30900 	7:   uint16(11),
  30901 	8:   uint16(12),
  30902 	9:   uint16(13),
  30903 	10:  uint16(14),
  30904 	11:  uint16(15),
  30905 	12:  uint16(16),
  30906 	13:  uint16(17),
  30907 	14:  uint16(18),
  30908 	15:  uint16(19),
  30909 	16:  uint16(20),
  30910 	17:  uint16(21),
  30911 	18:  uint16(22),
  30912 	19:  uint16(23),
  30913 	20:  uint16(24),
  30914 	21:  uint16(25),
  30915 	22:  uint16(26),
  30916 	23:  uint16(27),
  30917 	24:  uint16(28),
  30918 	25:  uint16(29),
  30919 	26:  uint16(30),
  30920 	27:  uint16(31),
  30921 	28:  uint16(32),
  30922 	29:  uint16(33),
  30923 	30:  uint16(34),
  30924 	31:  uint16(35),
  30925 	32:  uint16(36),
  30926 	33:  uint16(37),
  30927 	34:  uint16(38),
  30928 	35:  uint16(39),
  30929 	36:  uint16(40),
  30930 	37:  uint16(41),
  30931 	38:  uint16(42),
  30932 	39:  uint16(43),
  30933 	40:  uint16(44),
  30934 	41:  uint16(45),
  30935 	42:  uint16(46),
  30936 	43:  uint16(47),
  30937 	44:  uint16(48),
  30938 	45:  uint16(49),
  30939 	46:  uint16(50),
  30940 	47:  uint16(51),
  30941 	48:  uint16(52),
  30942 	49:  uint16(53),
  30943 	50:  uint16(54),
  30944 	51:  uint16(55),
  30945 	52:  uint16(56),
  30946 	53:  uint16(57),
  30947 	54:  uint16(58),
  30948 	55:  uint16(60),
  30949 	56:  uint16(62),
  30950 	57:  uint16(64),
  30951 	58:  uint16(66),
  30952 	59:  uint16(68),
  30953 	60:  uint16(70),
  30954 	61:  uint16(72),
  30955 	62:  uint16(74),
  30956 	63:  uint16(76),
  30957 	64:  uint16(78),
  30958 	65:  uint16(80),
  30959 	66:  uint16(82),
  30960 	67:  uint16(84),
  30961 	68:  uint16(86),
  30962 	69:  uint16(88),
  30963 	70:  uint16(90),
  30964 	71:  uint16(92),
  30965 	72:  uint16(94),
  30966 	73:  uint16(96),
  30967 	74:  uint16(98),
  30968 	75:  uint16(100),
  30969 	76:  uint16(102),
  30970 	77:  uint16(104),
  30971 	78:  uint16(106),
  30972 	79:  uint16(108),
  30973 	80:  uint16(110),
  30974 	81:  uint16(112),
  30975 	82:  uint16(114),
  30976 	83:  uint16(116),
  30977 	84:  uint16(119),
  30978 	85:  uint16(122),
  30979 	86:  uint16(125),
  30980 	87:  uint16(128),
  30981 	88:  uint16(131),
  30982 	89:  uint16(134),
  30983 	90:  uint16(137),
  30984 	91:  uint16(140),
  30985 	92:  uint16(143),
  30986 	93:  uint16(146),
  30987 	94:  uint16(149),
  30988 	95:  uint16(152),
  30989 	96:  uint16(155),
  30990 	97:  uint16(158),
  30991 	98:  uint16(161),
  30992 	99:  uint16(164),
  30993 	100: uint16(167),
  30994 	101: uint16(170),
  30995 	102: uint16(173),
  30996 	103: uint16(177),
  30997 	104: uint16(181),
  30998 	105: uint16(185),
  30999 	106: uint16(189),
  31000 	107: uint16(193),
  31001 	108: uint16(197),
  31002 	109: uint16(201),
  31003 	110: uint16(205),
  31004 	111: uint16(209),
  31005 	112: uint16(213),
  31006 	113: uint16(217),
  31007 	114: uint16(221),
  31008 	115: uint16(225),
  31009 	116: uint16(229),
  31010 	117: uint16(234),
  31011 	118: uint16(239),
  31012 	119: uint16(245),
  31013 	120: uint16(249),
  31014 	121: uint16(254),
  31015 	122: uint16(259),
  31016 	123: uint16(264),
  31017 	124: uint16(269),
  31018 	125: uint16(274),
  31019 	126: uint16(279),
  31020 	127: uint16(284),
  31021 }
  31022 
  31023 var kAcTable2 = [128]uint16_t{
  31024 	0:   uint16(8),
  31025 	1:   uint16(8),
  31026 	2:   uint16(9),
  31027 	3:   uint16(10),
  31028 	4:   uint16(12),
  31029 	5:   uint16(13),
  31030 	6:   uint16(15),
  31031 	7:   uint16(17),
  31032 	8:   uint16(18),
  31033 	9:   uint16(20),
  31034 	10:  uint16(21),
  31035 	11:  uint16(23),
  31036 	12:  uint16(24),
  31037 	13:  uint16(26),
  31038 	14:  uint16(27),
  31039 	15:  uint16(29),
  31040 	16:  uint16(31),
  31041 	17:  uint16(32),
  31042 	18:  uint16(34),
  31043 	19:  uint16(35),
  31044 	20:  uint16(37),
  31045 	21:  uint16(38),
  31046 	22:  uint16(40),
  31047 	23:  uint16(41),
  31048 	24:  uint16(43),
  31049 	25:  uint16(44),
  31050 	26:  uint16(46),
  31051 	27:  uint16(48),
  31052 	28:  uint16(49),
  31053 	29:  uint16(51),
  31054 	30:  uint16(52),
  31055 	31:  uint16(54),
  31056 	32:  uint16(55),
  31057 	33:  uint16(57),
  31058 	34:  uint16(58),
  31059 	35:  uint16(60),
  31060 	36:  uint16(62),
  31061 	37:  uint16(63),
  31062 	38:  uint16(65),
  31063 	39:  uint16(66),
  31064 	40:  uint16(68),
  31065 	41:  uint16(69),
  31066 	42:  uint16(71),
  31067 	43:  uint16(72),
  31068 	44:  uint16(74),
  31069 	45:  uint16(75),
  31070 	46:  uint16(77),
  31071 	47:  uint16(79),
  31072 	48:  uint16(80),
  31073 	49:  uint16(82),
  31074 	50:  uint16(83),
  31075 	51:  uint16(85),
  31076 	52:  uint16(86),
  31077 	53:  uint16(88),
  31078 	54:  uint16(89),
  31079 	55:  uint16(93),
  31080 	56:  uint16(96),
  31081 	57:  uint16(99),
  31082 	58:  uint16(102),
  31083 	59:  uint16(105),
  31084 	60:  uint16(108),
  31085 	61:  uint16(111),
  31086 	62:  uint16(114),
  31087 	63:  uint16(117),
  31088 	64:  uint16(120),
  31089 	65:  uint16(124),
  31090 	66:  uint16(127),
  31091 	67:  uint16(130),
  31092 	68:  uint16(133),
  31093 	69:  uint16(136),
  31094 	70:  uint16(139),
  31095 	71:  uint16(142),
  31096 	72:  uint16(145),
  31097 	73:  uint16(148),
  31098 	74:  uint16(151),
  31099 	75:  uint16(155),
  31100 	76:  uint16(158),
  31101 	77:  uint16(161),
  31102 	78:  uint16(164),
  31103 	79:  uint16(167),
  31104 	80:  uint16(170),
  31105 	81:  uint16(173),
  31106 	82:  uint16(176),
  31107 	83:  uint16(179),
  31108 	84:  uint16(184),
  31109 	85:  uint16(189),
  31110 	86:  uint16(193),
  31111 	87:  uint16(198),
  31112 	88:  uint16(203),
  31113 	89:  uint16(207),
  31114 	90:  uint16(212),
  31115 	91:  uint16(217),
  31116 	92:  uint16(221),
  31117 	93:  uint16(226),
  31118 	94:  uint16(230),
  31119 	95:  uint16(235),
  31120 	96:  uint16(240),
  31121 	97:  uint16(244),
  31122 	98:  uint16(249),
  31123 	99:  uint16(254),
  31124 	100: uint16(258),
  31125 	101: uint16(263),
  31126 	102: uint16(268),
  31127 	103: uint16(274),
  31128 	104: uint16(280),
  31129 	105: uint16(286),
  31130 	106: uint16(292),
  31131 	107: uint16(299),
  31132 	108: uint16(305),
  31133 	109: uint16(311),
  31134 	110: uint16(317),
  31135 	111: uint16(323),
  31136 	112: uint16(330),
  31137 	113: uint16(336),
  31138 	114: uint16(342),
  31139 	115: uint16(348),
  31140 	116: uint16(354),
  31141 	117: uint16(362),
  31142 	118: uint16(370),
  31143 	119: uint16(379),
  31144 	120: uint16(385),
  31145 	121: uint16(393),
  31146 	122: uint16(401),
  31147 	123: uint16(409),
  31148 	124: uint16(416),
  31149 	125: uint16(424),
  31150 	126: uint16(432),
  31151 	127: uint16(440),
  31152 }
  31153 
  31154 var kBiasMatrices = [3][2]uint8_t{
  31155 	0: {
  31156 		0: uint8(96),
  31157 		1: uint8(110),
  31158 	},
  31159 	1: {
  31160 		0: uint8(96),
  31161 		1: uint8(108),
  31162 	},
  31163 	2: {
  31164 		0: uint8(110),
  31165 		1: uint8(115),
  31166 	},
  31167 }
  31168 
  31169 // C documentation
  31170 //
  31171 //	// Sharpening by (slightly) raising the hi-frequency coeffs.
  31172 //	// Hack-ish but helpful for mid-bitrate range. Use with care.
  31173 var kFreqSharpening = [16]uint8_t{
  31174 	1:  uint8(30),
  31175 	2:  uint8(60),
  31176 	3:  uint8(90),
  31177 	4:  uint8(30),
  31178 	5:  uint8(60),
  31179 	6:  uint8(90),
  31180 	7:  uint8(90),
  31181 	8:  uint8(60),
  31182 	9:  uint8(90),
  31183 	10: uint8(90),
  31184 	11: uint8(90),
  31185 	12: uint8(90),
  31186 	13: uint8(90),
  31187 	14: uint8(90),
  31188 	15: uint8(90),
  31189 }
  31190 
  31191 //------------------------------------------------------------------------------
  31192 // Initialize quantization parameters in VP8Matrix
  31193 
  31194 // C documentation
  31195 //
  31196 //	// Returns the average quantizer
  31197 func ExpandMatrix(tls *libc.TLS, m uintptr, type1 int32) (r int32) {
  31198 	var bias, i, is_ac_coeff, sum int32
  31199 	_, _, _, _ = bias, i, is_ac_coeff, sum
  31200 	i = 0
  31201 	for {
  31202 		if !(i < int32(2)) {
  31203 			break
  31204 		}
  31205 		is_ac_coeff = libc.BoolInt32(i > libc.Int32FromInt32(0))
  31206 		bias = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kBiasMatrices)) + uintptr(type1)*2 + uintptr(is_ac_coeff))))
  31207 		**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)) = libc.Uint16FromInt32(libc.Int32FromInt32(1) << libc.Int32FromInt32(QFIX) / libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2))))
  31208 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = libc.Uint32FromInt32(bias << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8)))
  31209 		// zthresh is the exact value such that QUANTDIV(coeff, iQ, B) is:
  31210 		//   * zero if coeff <= zthresh
  31211 		//   * non-zero if coeff > zthresh
  31212 		**(**uint32_t)(__ccgo_up(m + 128 + uintptr(i)*4)) = (libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(QFIX)-libc.Int32FromInt32(1)) - **(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4))) / uint32(**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)))
  31213 		goto _1
  31214 	_1:
  31215 		;
  31216 		i = i + 1
  31217 	}
  31218 	i = int32(2)
  31219 	for {
  31220 		if !(i < int32(16)) {
  31221 			break
  31222 		}
  31223 		**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 1*2))
  31224 		**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 32 + 1*2))
  31225 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 64 + 1*4))
  31226 		**(**uint32_t)(__ccgo_up(m + 128 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 128 + 1*4))
  31227 		goto _2
  31228 	_2:
  31229 		;
  31230 		i = i + 1
  31231 	}
  31232 	sum = 0
  31233 	i = libc.Int32FromInt32(0)
  31234 	for {
  31235 		if !(i < int32(16)) {
  31236 			break
  31237 		}
  31238 		if type1 == 0 { // we only use sharpening for AC luma coeffs
  31239 			**(**uint16_t)(__ccgo_up(m + 192 + uintptr(i)*2)) = libc.Uint16FromInt32(libc.Int32FromUint8(kFreqSharpening[i]) * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2))) >> int32(SHARPEN_BITS))
  31240 		} else {
  31241 			**(**uint16_t)(__ccgo_up(m + 192 + uintptr(i)*2)) = uint16(0)
  31242 		}
  31243 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)))
  31244 		goto _3
  31245 	_3:
  31246 		;
  31247 		i = i + 1
  31248 	}
  31249 	return (sum + int32(8)) >> int32(4)
  31250 }
  31251 
  31252 func CheckLambdaValue(tls *libc.TLS, v uintptr) {
  31253 	if **(**int32)(__ccgo_up(v)) < int32(1) {
  31254 		**(**int32)(__ccgo_up(v)) = int32(1)
  31255 	}
  31256 }
  31257 
  31258 func SetupMatrices(tls *libc.TLS, enc uintptr) {
  31259 	var i, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1 int32
  31260 	var m uintptr
  31261 	_, _, _, _, _, _, _, _, _ = i, m, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1
  31262 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod >= int32(4) {
  31263 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength
  31264 	} else {
  31265 		v1 = 0
  31266 	}
  31267 	tlambda_scale = v1
  31268 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31269 	i = 0
  31270 	for {
  31271 		if !(i < num_segments) {
  31272 			break
  31273 		}
  31274 		m = enc + 608 + uintptr(i)*744
  31275 		q = (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant
  31276 		**(**uint16_t)(__ccgo_up(m)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, 0, int32(127))])
  31277 		**(**uint16_t)(__ccgo_up(m + 1*2)) = kAcTable1[clip2(tls, q, 0, int32(127))]
  31278 		**(**uint16_t)(__ccgo_up(m + 224)) = libc.Uint16FromInt32(libc.Int32FromUint8(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, 0, int32(127))]) * int32(2))
  31279 		**(**uint16_t)(__ccgo_up(m + 224 + 1*2)) = kAcTable2[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, 0, int32(127))]
  31280 		**(**uint16_t)(__ccgo_up(m + 448)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, 0, int32(117))])
  31281 		**(**uint16_t)(__ccgo_up(m + 448 + 1*2)) = kAcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, 0, int32(127))]
  31282 		q_i4 = ExpandMatrix(tls, m, 0)
  31283 		q_i16 = ExpandMatrix(tls, m+224, int32(1))
  31284 		q_uv = ExpandMatrix(tls, m+448, int32(2))
  31285 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i4 = int32(3) * q_i4 * q_i4 >> int32(7)
  31286 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i16 = int32(3) * q_i16 * q_i16
  31287 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_uv = int32(3) * q_uv * q_uv >> int32(6)
  31288 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_mode = int32(1) * q_i4 * q_i4 >> int32(7)
  31289 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i4 = int32(7) * q_i4 * q_i4 >> int32(3)
  31290 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i16 = q_i16 * q_i16 >> int32(2)
  31291 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_uv = q_uv * q_uv << int32(1)
  31292 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ftlambda = tlambda_scale * q_i4 >> int32(5)
  31293 		// none of these constants should be < 1
  31294 		CheckLambdaValue(tls, m+700)
  31295 		CheckLambdaValue(tls, m+696)
  31296 		CheckLambdaValue(tls, m+704)
  31297 		CheckLambdaValue(tls, m+708)
  31298 		CheckLambdaValue(tls, m+724)
  31299 		CheckLambdaValue(tls, m+720)
  31300 		CheckLambdaValue(tls, m+728)
  31301 		CheckLambdaValue(tls, m+716)
  31302 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmin_disto = int32(20) * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(m))) // quantization-aware min disto
  31303 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmax_edge = 0
  31304 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fi4_penalty = int64(int32(1000) * q_i4 * q_i4)
  31305 		goto _2
  31306 	_2:
  31307 		;
  31308 		i = i + 1
  31309 	}
  31310 }
  31311 
  31312 //------------------------------------------------------------------------------
  31313 // Initialize filtering parameters
  31314 
  31315 // Very small filter-strength values have close to no visual effect. So we can
  31316 // save a little decoding-CPU by turning filtering off for these.
  31317 
  31318 func SetupFilterStrength(tls *libc.TLS, enc uintptr) {
  31319 	var base_strength, f, i, level0, qstep, v2, v3 int32
  31320 	var m uintptr
  31321 	_, _, _, _, _, _, _, _ = base_strength, f, i, level0, m, qstep, v2, v3
  31322 	// level0 is in [0..500]. Using '-f 50' as filter_strength is mid-filtering.
  31323 	level0 = int32(5) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength
  31324 	i = 0
  31325 	for {
  31326 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31327 			break
  31328 		}
  31329 		m = enc + 608 + uintptr(i)*744
  31330 		// We focus on the quantization of AC coeffs.
  31331 		qstep = libc.Int32FromUint16(kAcTable1[clip2(tls, (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant, 0, int32(127))]) >> int32(2)
  31332 		base_strength = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, qstep)
  31333 		// Segments with lower complexity ('beta') will be less filtered.
  31334 		f = base_strength * level0 / (int32(256) + (*VP8SegmentInfo)(unsafe.Pointer(m)).Fbeta)
  31335 		if f < int32(FSTRENGTH_CUTOFF) {
  31336 			v2 = 0
  31337 		} else {
  31338 			if f > int32(63) {
  31339 				v3 = int32(63)
  31340 			} else {
  31341 				v3 = f
  31342 			}
  31343 			v2 = v3
  31344 		}
  31345 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ffstrength = v2
  31346 		goto _1
  31347 	_1:
  31348 		;
  31349 		i = i + 1
  31350 	}
  31351 	// We record the initial strength (mainly for the case of 1-segment only).
  31352 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Ffstrength
  31353 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple = libc.BoolInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_type == 0)
  31354 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness
  31355 }
  31356 
  31357 //------------------------------------------------------------------------------
  31358 
  31359 // Note: if you change the values below, remember that the max range
  31360 // allowed by the syntax for DQ_UV is [-16,16].
  31361 
  31362 // C documentation
  31363 //
  31364 //	// We want to emulate jpeg-like behaviour where the expected "good" quality
  31365 //	// is around q=75. Internally, our "good" middle is around c=50. So we
  31366 //	// map accordingly using linear piece-wise function
  31367 func QualityToCompression(tls *libc.TLS, c float64) (r float64) {
  31368 	var linear_c, v, v1 float64
  31369 	_, _, _ = linear_c, v, v1
  31370 	if c < float64(0.75) {
  31371 		v1 = float64(c * (libc.Float64FromFloat64(2) / libc.Float64FromFloat64(3)))
  31372 	} else {
  31373 		v1 = float64(float64(2)*c) - float64(1)
  31374 	}
  31375 	linear_c = v1
  31376 	// The file size roughly scales as pow(quantizer, 3.). Actually, the
  31377 	// exponent is somewhere between 2.8 and 3.2, but we're mostly interested
  31378 	// in the mid-quant range. So we scale the compressibility inversely to
  31379 	// this power-law: quant ~= compression ^ 1/3. This law holds well for
  31380 	// low quant. Finer modeling for high-quant would make use of kAcTable[]
  31381 	// more explicitly.
  31382 	v = libc.Xpow(tls, linear_c, libc.Float64FromInt32(1)/libc.Float64FromFloat64(3))
  31383 	return v
  31384 }
  31385 
  31386 func QualityToJPEGCompression(tls *libc.TLS, c float64, alpha float64) (r float64) {
  31387 	var amax, amin, exp_max, exp_min, expn, slope, v, v1, v2 float64
  31388 	_, _, _, _, _, _, _, _, _ = amax, amin, exp_max, exp_min, expn, slope, v, v1, v2
  31389 	// We map the complexity 'alpha' and quality setting 'c' to a compression
  31390 	// exponent empirically matched to the compression curve of libjpeg6b.
  31391 	// On average, the WebP output size will be roughly similar to that of a
  31392 	// JPEG file compressed with same quality factor.
  31393 	amin = float64(0.3)
  31394 	amax = float64(0.85)
  31395 	exp_min = float64(0.4)
  31396 	exp_max = float64(0.9)
  31397 	slope = (exp_min - exp_max) / (amax - amin)
  31398 	if alpha > amax {
  31399 		v1 = exp_min
  31400 	} else {
  31401 		if alpha < amin {
  31402 			v2 = exp_max
  31403 		} else {
  31404 			v2 = exp_max + float64(slope*(alpha-amin))
  31405 		}
  31406 		v1 = v2
  31407 	}
  31408 	// Linearly interpolate 'expn' from exp_min to exp_max
  31409 	// in the [amin, amax] range.
  31410 	expn = v1
  31411 	v = libc.Xpow(tls, c, expn)
  31412 	return v
  31413 }
  31414 
  31415 func SegmentsAreEquivalent(tls *libc.TLS, S1 uintptr, S2 uintptr) (r int32) {
  31416 	return libc.BoolInt32((*VP8SegmentInfo)(unsafe.Pointer(S1)).Fquant == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Fquant && (*VP8SegmentInfo)(unsafe.Pointer(S1)).Ffstrength == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Ffstrength)
  31417 }
  31418 
  31419 func SimplifySegments(tls *libc.TLS, enc uintptr) {
  31420 	var S1, S2 uintptr
  31421 	var found, i, num_final_segments, num_segments, s1, s2, v1 int32
  31422 	var map1 [4]int32
  31423 	_, _, _, _, _, _, _, _, _, _ = S1, S2, found, i, map1, num_final_segments, num_segments, s1, s2, v1
  31424 	map1 = [4]int32{
  31425 		1: int32(1),
  31426 		2: int32(2),
  31427 		3: int32(3),
  31428 	}
  31429 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  31430 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31431 	} else {
  31432 		v1 = int32(NUM_MB_SEGMENTS)
  31433 	}
  31434 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  31435 	// explicit check is needed to avoid a spurious warning about 'i' exceeding
  31436 	// array bounds of 'dqm' with some compilers (noticed with gcc-4.9).
  31437 	num_segments = v1
  31438 	num_final_segments = int32(1)
  31439 	s1 = int32(1)
  31440 	for {
  31441 		if !(s1 < num_segments) {
  31442 			break
  31443 		} // find similar segments
  31444 		S1 = enc + 608 + uintptr(s1)*744
  31445 		found = 0
  31446 		// check if we already have similar segment
  31447 		s2 = 0
  31448 		for {
  31449 			if !(s2 < num_final_segments) {
  31450 				break
  31451 			}
  31452 			S2 = enc + 608 + uintptr(s2)*744
  31453 			if SegmentsAreEquivalent(tls, S1, S2) != 0 {
  31454 				found = int32(1)
  31455 				break
  31456 			}
  31457 			goto _3
  31458 		_3:
  31459 			;
  31460 			s2 = s2 + 1
  31461 		}
  31462 		map1[s1] = s2
  31463 		if !(found != 0) {
  31464 			if num_final_segments != s1 {
  31465 				**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s1)*744))
  31466 			}
  31467 			num_final_segments = num_final_segments + 1
  31468 		}
  31469 		goto _2
  31470 	_2:
  31471 		;
  31472 		s1 = s1 + 1
  31473 	}
  31474 	if num_final_segments < num_segments { // Remap
  31475 		i = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  31476 		for {
  31477 			v1 = i
  31478 			i = i - 1
  31479 			if !(v1 > 0) {
  31480 				break
  31481 			}
  31482 			libc.SetBitFieldPtr8Uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(i)*4+0, libc.Uint32FromInt32(map1[int32(uint32(*(*uint8)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(i)*4 + 0))&0x60>>5))]), 5, 0x60)
  31483 		}
  31484 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments = num_final_segments
  31485 		// Replicate the trailing segment infos (it's mostly cosmetics)
  31486 		i = num_final_segments
  31487 		for {
  31488 			if !(i < num_segments) {
  31489 				break
  31490 			}
  31491 			**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments-int32(1))*744))
  31492 			goto _5
  31493 		_5:
  31494 			;
  31495 			i = i + 1
  31496 		}
  31497 	}
  31498 }
  31499 
  31500 func VP8SetSegmentParams(tls *libc.TLS, enc uintptr, quality float32) {
  31501 	var Q, amp, c, c_base, expn, v1 float64
  31502 	var dq_uv_ac, dq_uv_dc, i, num_segments, q int32
  31503 	_, _, _, _, _, _, _, _, _, _, _ = Q, amp, c, c_base, dq_uv_ac, dq_uv_dc, expn, i, num_segments, q, v1
  31504 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31505 	amp = float64(float64(SNS_TO_DQ)*float64((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength)) / float64(100) / float64(128)
  31506 	Q = float64(quality) / float64(100)
  31507 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Femulate_jpeg_size != 0 {
  31508 		v1 = QualityToJPEGCompression(tls, Q, float64((*VP8Encoder)(unsafe.Pointer(enc)).Falpha)/float64(255))
  31509 	} else {
  31510 		v1 = QualityToCompression(tls, Q)
  31511 	}
  31512 	c_base = v1
  31513 	i = 0
  31514 	for {
  31515 		if !(i < num_segments) {
  31516 			break
  31517 		}
  31518 		// We modulate the base coefficient to accommodate for the quantization
  31519 		// susceptibility and allow denser segments to be quantized more.
  31520 		expn = float64(1) - float64(amp*float64((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Falpha))
  31521 		c = libc.Xpow(tls, c_base, expn)
  31522 		q = int32(float64(libc.Float64FromFloat64(127) * (libc.Float64FromFloat64(1) - c)))
  31523 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = clip2(tls, q, 0, int32(127))
  31524 		goto _2
  31525 	_2:
  31526 		;
  31527 		i = i + 1
  31528 	}
  31529 	// purely indicative in the bitstream (except for the 1-segment case)
  31530 	(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fquant
  31531 	// fill-in values for the unused segments (required by the syntax)
  31532 	i = num_segments
  31533 	for {
  31534 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31535 			break
  31536 		}
  31537 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = (*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant
  31538 		goto _3
  31539 	_3:
  31540 		;
  31541 		i = i + 1
  31542 	}
  31543 	// uv_alpha is normally spread around ~60. The useful range is
  31544 	// typically ~30 (quite bad) to ~100 (ok to decimate UV more).
  31545 	// We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv.
  31546 	dq_uv_ac = ((*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha - int32(MID_ALPHA)) * (libc.Int32FromInt32(MAX_DQ_UV) - -libc.Int32FromInt32(4)) / (libc.Int32FromInt32(MAX_ALPHA1) - libc.Int32FromInt32(MIN_ALPHA))
  31547 	// we rescale by the user-defined strength of adaptation
  31548 	dq_uv_ac = dq_uv_ac * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31549 	// and make it safe.
  31550 	dq_uv_ac = clip2(tls, dq_uv_ac, -int32(4), int32(MAX_DQ_UV))
  31551 	// We also boost the dc-uv-quant a little, based on sns-strength, since
  31552 	// U/V channels are quite more reactive to high quants (flat DC-blocks
  31553 	// tend to appear, and are unpleasant).
  31554 	dq_uv_dc = -int32(4) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31555 	dq_uv_dc = clip2(tls, dq_uv_dc, -int32(15), int32(15)) // 4bit-signed max allowed
  31556 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc = 0       // TODO(skal): dq-lum
  31557 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc = 0
  31558 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac = 0
  31559 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc = dq_uv_dc
  31560 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac = dq_uv_ac
  31561 	SetupFilterStrength(tls, enc) // initialize segments' filtering, eventually
  31562 	if num_segments > int32(1) {
  31563 		SimplifySegments(tls, enc)
  31564 	}
  31565 	SetupMatrices(tls, enc) // finalize quantization matrices
  31566 }
  31567 
  31568 // C documentation
  31569 //
  31570 //	// Must be indexed using {B_DC_PRED -> B_HU_PRED} as index
  31571 var VP8I4ModeOffsets = [10]uint16_t{
  31572 	0: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0)),
  31573 	1: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(4)),
  31574 	2: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(8)),
  31575 	3: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(12)),
  31576 	4: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(16)),
  31577 	5: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(20)),
  31578 	6: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(24)),
  31579 	7: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(28)),
  31580 	8: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31581 	9: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)),
  31582 }
  31583 
  31584 func VP8MakeLuma16Preds(tls *libc.TLS, it uintptr) {
  31585 	var left, top, v1, v2 uintptr
  31586 	_, _, _, _ = left, top, v1, v2
  31587 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31588 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left
  31589 	} else {
  31590 		v1 = libc.UintptrFromInt32(0)
  31591 	}
  31592 	left = v1
  31593 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31594 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top
  31595 	} else {
  31596 		v2 = libc.UintptrFromInt32(0)
  31597 	}
  31598 	top = v2
  31599 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma16})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31600 }
  31601 
  31602 func VP8MakeChroma8Preds(tls *libc.TLS, it uintptr) {
  31603 	var left, top, v1, v2 uintptr
  31604 	_, _, _, _ = left, top, v1, v2
  31605 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31606 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left
  31607 	} else {
  31608 		v1 = libc.UintptrFromInt32(0)
  31609 	}
  31610 	left = v1
  31611 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31612 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top
  31613 	} else {
  31614 		v2 = libc.UintptrFromInt32(0)
  31615 	}
  31616 	top = v2
  31617 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredChroma8})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31618 }
  31619 
  31620 // C documentation
  31621 //
  31622 //	// Form all the ten Intra4x4 predictions in the 'yuv_p' cache
  31623 //	// for the 4x4 block it->i4
  31624 func MakeIntra4Preds(tls *libc.TLS, it uintptr) {
  31625 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma4})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top)
  31626 }
  31627 
  31628 var VP8ScanUV = [8]uint16_t{
  31629 	1: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31630 	2: libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31631 	3: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31632 	4: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31633 	5: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31634 	6: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31635 	7: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31636 }
  31637 
  31638 //------------------------------------------------------------------------------
  31639 // Distortion measurement
  31640 
  31641 var kWeightY = [16]uint16_t{
  31642 	0:  uint16(38),
  31643 	1:  uint16(32),
  31644 	2:  uint16(20),
  31645 	3:  uint16(9),
  31646 	4:  uint16(32),
  31647 	5:  uint16(28),
  31648 	6:  uint16(17),
  31649 	7:  uint16(7),
  31650 	8:  uint16(20),
  31651 	9:  uint16(17),
  31652 	10: uint16(10),
  31653 	11: uint16(4),
  31654 	12: uint16(9),
  31655 	13: uint16(7),
  31656 	14: uint16(4),
  31657 	15: uint16(2),
  31658 }
  31659 
  31660 var kWeightTrellis = [16]uint16_t{
  31661 	0:  uint16(30),
  31662 	1:  uint16(27),
  31663 	2:  uint16(19),
  31664 	3:  uint16(11),
  31665 	4:  uint16(27),
  31666 	5:  uint16(24),
  31667 	6:  uint16(17),
  31668 	7:  uint16(10),
  31669 	8:  uint16(19),
  31670 	9:  uint16(17),
  31671 	10: uint16(12),
  31672 	11: uint16(8),
  31673 	12: uint16(11),
  31674 	13: uint16(10),
  31675 	14: uint16(8),
  31676 	15: uint16(6),
  31677 }
  31678 
  31679 // C documentation
  31680 //
  31681 //	// Init/Copy the common fields in score.
  31682 func InitScore(tls *libc.TLS, rd uintptr) {
  31683 	(*VP8ModeScore)(unsafe.Pointer(rd)).FD = 0
  31684 	(*VP8ModeScore)(unsafe.Pointer(rd)).FSD = 0
  31685 	(*VP8ModeScore)(unsafe.Pointer(rd)).FR = 0
  31686 	(*VP8ModeScore)(unsafe.Pointer(rd)).FH = 0
  31687 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(0)
  31688 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  31689 }
  31690 
  31691 func CopyScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31692 	(*VP8ModeScore)(unsafe.Pointer(dst)).FD = (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31693 	(*VP8ModeScore)(unsafe.Pointer(dst)).FSD = (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31694 	(*VP8ModeScore)(unsafe.Pointer(dst)).FR = (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31695 	(*VP8ModeScore)(unsafe.Pointer(dst)).FH = (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31696 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fnz = (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // note that nz is not accumulated, but just copied.
  31697 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fscore = (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31698 }
  31699 
  31700 func AddScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31701 	**(**score_t)(__ccgo_up(dst)) += (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31702 	**(**score_t)(__ccgo_up(dst + 8)) += (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31703 	**(**score_t)(__ccgo_up(dst + 24)) += (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31704 	**(**score_t)(__ccgo_up(dst + 16)) += (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31705 	**(**uint32_t)(__ccgo_up(dst + 864)) |= (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // here, new nz bits are accumulated.
  31706 	**(**score_t)(__ccgo_up(dst + 32)) += (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31707 }
  31708 
  31709 //------------------------------------------------------------------------------
  31710 // Performs trellis-optimized quantization.
  31711 
  31712 // C documentation
  31713 //
  31714 //	// Trellis node
  31715 type Node = struct {
  31716 	Fprev  int8_t
  31717 	Fsign  int8_t
  31718 	Flevel int16_t
  31719 }
  31720 
  31721 // C documentation
  31722 //
  31723 //	// Score state
  31724 type ScoreState = struct {
  31725 	Fscore score_t
  31726 	Fcosts uintptr
  31727 }
  31728 
  31729 // If a coefficient was quantized to a value Q (using a neutral bias),
  31730 // we test all alternate possibilities between [Q-MIN_DELTA, Q+MAX_DELTA]
  31731 // We don't test negative values though.
  31732 
  31733 func SetRDScore(tls *libc.TLS, lambda int32, rd uintptr) {
  31734 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = ((*VP8ModeScore)(unsafe.Pointer(rd)).FR+(*VP8ModeScore)(unsafe.Pointer(rd)).FH)*int64(lambda) + int64(RD_DISTO_MULT)*((*VP8ModeScore)(unsafe.Pointer(rd)).FD+(*VP8ModeScore)(unsafe.Pointer(rd)).FSD)
  31735 }
  31736 
  31737 func RDScoreTrellis(tls *libc.TLS, lambda int32, rate score_t, distortion score_t) (r score_t) {
  31738 	return rate*int64(lambda) + int64(RD_DISTO_MULT)*distortion
  31739 }
  31740 
  31741 const TYPE_I16_AC = 0
  31742 const TYPE_I16_DC = 1
  31743 const TYPE_CHROMA_A = 2
  31744 const TYPE_I4_AC = 3
  31745 
  31746 func TrellisQuantizeBlock(tls *libc.TLS, enc uintptr, in uintptr, out uintptr, ctx0 int32, coeff_type int32, mtx uintptr, lambda int32) (r int32) {
  31747 	bp := tls.Alloc(192)
  31748 	defer tls.Free(192)
  31749 	var B1, Q, coeff0, iQ1 uint32_t
  31750 	var band, best_node, best_prev, ctx, delta_error, err, first, j, j1, j2, last, last_proba, level0, level1, m, n1, new_error, nz, p, sign, thresh, thresh_level, v1, v4, v6 int32
  31751 	var base_score, best_cur_score, best_score, cost, cost1, last_pos_cost, last_pos_score, rate, score score_t
  31752 	var best_path [3]int32
  31753 	var costs CostArrayPtr
  31754 	var cur, node, probas, ss_cur, ss_prev, tmp uintptr
  31755 	var v3 uint8_t
  31756 	var _ /* nodes at bp+0 */ [16][2]Node
  31757 	var _ /* score_states at bp+128 */ [2][2]ScoreState
  31758 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = B1, Q, band, base_score, best_cur_score, best_node, best_path, best_prev, best_score, coeff0, cost, cost1, costs, ctx, cur, delta_error, err, first, iQ1, j, j1, j2, last, last_pos_cost, last_pos_score, last_proba, level0, level1, m, n1, new_error, node, nz, p, probas, rate, score, sign, ss_cur, ss_prev, thresh, thresh_level, tmp, v1, v3, v4, v6
  31759 	probas = enc + 3616 + 4 + uintptr(coeff_type)*264
  31760 	costs = enc + 3616 + 18344 + uintptr(coeff_type)*384
  31761 	if coeff_type == int32(TYPE_I16_AC) {
  31762 		v1 = int32(1)
  31763 	} else {
  31764 		v1 = 0
  31765 	}
  31766 	first = v1
  31767 	ss_cur = bp + 128 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  31768 	ss_prev = bp + 128 + 1*32 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  31769 	best_path = [3]int32{
  31770 		0: -int32(1),
  31771 		1: -int32(1),
  31772 		2: -int32(1),
  31773 	}
  31774 	thresh = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 1*2))) * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 1*2))) / int32(4)
  31775 	last_proba = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas + uintptr(VP8EncBands[first])*33 + uintptr(ctx0)*11)))
  31776 	// compute the position of the last interesting coefficient
  31777 	last = first - int32(1)
  31778 	n1 = int32(15)
  31779 	for {
  31780 		if !(n1 >= first) {
  31781 			break
  31782 		}
  31783 		j = libc.Int32FromUint8(kZigzag1[n1])
  31784 		err = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) * int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  31785 		if err > thresh {
  31786 			last = n1
  31787 			break
  31788 		}
  31789 		goto _2
  31790 	_2:
  31791 		;
  31792 		n1 = n1 - 1
  31793 	}
  31794 	// we don't need to go inspect up to n = 16 coeffs. We can just go up
  31795 	// to last + 1 (inclusive) without losing much.
  31796 	if last < int32(15) {
  31797 		last = last + 1
  31798 	}
  31799 	// compute 'skip' score. This is the max score one can do.
  31800 	v3 = libc.Uint8FromInt32(last_proba)
  31801 	if !(0 != 0) {
  31802 		v4 = libc.Int32FromUint16(VP8EntropyCost[v3])
  31803 	} else {
  31804 		v4 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  31805 	}
  31806 	v1 = v4
  31807 	goto _5
  31808 _5:
  31809 	cost = int64(v1)
  31810 	best_score = RDScoreTrellis(tls, lambda, cost, 0)
  31811 	// initialize source node.
  31812 	m = -MIN_DELTA
  31813 	for {
  31814 		if !(m <= int32(MAX_DELTA)) {
  31815 			break
  31816 		}
  31817 		if ctx0 == 0 {
  31818 			v3 = libc.Uint8FromInt32(last_proba)
  31819 			if !(int32(1) != 0) {
  31820 				v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  31821 			} else {
  31822 				v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  31823 			}
  31824 			v4 = v6
  31825 			goto _11
  31826 		_11:
  31827 			v1 = v4
  31828 		} else {
  31829 			v1 = 0
  31830 		}
  31831 		rate = int64(v1)
  31832 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = RDScoreTrellis(tls, lambda, rate, 0)
  31833 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(first)*24 + uintptr(ctx0)*8))
  31834 		goto _7
  31835 	_7:
  31836 		;
  31837 		m = m + 1
  31838 	}
  31839 	// traverse trellis.
  31840 	n1 = first
  31841 	for {
  31842 		if !(n1 <= last) {
  31843 			break
  31844 		}
  31845 		j1 = libc.Int32FromUint8(kZigzag1[n1])
  31846 		Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j1)*2)))
  31847 		iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j1)*2)))
  31848 		B1 = libc.Uint32FromInt32(libc.Int32FromInt32(0x00) << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8))) // neutral bias
  31849 		// note: it's important to take sign of the _original_ coeff,
  31850 		// so we don't have to consider level < 0 afterward.
  31851 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2))) < libc.Int32FromInt32(0))
  31852 		if sign != 0 {
  31853 			v1 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  31854 		} else {
  31855 			v1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  31856 		}
  31857 		coeff0 = libc.Uint32FromInt32(v1 + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j1)*2))))
  31858 		v4 = libc.Int32FromUint32((coeff0*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  31859 		goto _16
  31860 	_16:
  31861 		level0 = v4
  31862 		v6 = libc.Int32FromUint32((coeff0*iQ1 + libc.Uint32FromInt32(libc.Int32FromInt32(0x80)<<(libc.Int32FromInt32(QFIX)-libc.Int32FromInt32(8)))) >> libc.Int32FromInt32(QFIX))
  31863 		goto _18
  31864 	_18:
  31865 		thresh_level = v6
  31866 		if thresh_level > int32(MAX_LEVEL) {
  31867 			thresh_level = int32(MAX_LEVEL)
  31868 		}
  31869 		if level0 > int32(MAX_LEVEL) {
  31870 			level0 = int32(MAX_LEVEL)
  31871 		}
  31872 		// Swap current and previous score states
  31873 		tmp = ss_cur
  31874 		ss_cur = ss_prev
  31875 		ss_prev = tmp
  31876 		// test all alternate level values around level0.
  31877 		m = -MIN_DELTA
  31878 		for {
  31879 			if !(m <= int32(MAX_DELTA)) {
  31880 				break
  31881 			}
  31882 			cur = bp + uintptr(n1)*8 + uintptr(m+MIN_DELTA)*4
  31883 			level1 = level0 + m
  31884 			if level1 > int32(2) {
  31885 				v1 = int32(2)
  31886 			} else {
  31887 				v1 = level1
  31888 			}
  31889 			ctx = v1
  31890 			band = libc.Int32FromUint8(VP8EncBands[n1+int32(1)])
  31891 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(n1+int32(1))*24 + uintptr(ctx)*8))
  31892 			if level1 < 0 || level1 > thresh_level {
  31893 				(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  31894 				// Node is dead.
  31895 				goto _19
  31896 			}
  31897 			// Compute delta_error = how much coding this level will
  31898 			// subtract to max_error as distortion.
  31899 			// Here, distortion = sum of (|coeff_i| - level_i * Q_i)^2
  31900 			new_error = libc.Int32FromUint32(coeff0 - libc.Uint32FromInt32(level1)*Q)
  31901 			delta_error = libc.Int32FromUint32(uint32(kWeightTrellis[j1]) * (libc.Uint32FromInt32(new_error*new_error) - coeff0*coeff0))
  31902 			base_score = RDScoreTrellis(tls, lambda, 0, int64(delta_error))
  31903 			// Inspect all possible non-dead predecessors. Retain only the best one.
  31904 			// The base_score is added to all scores so it is only added for the final
  31905 			// value after the loop.
  31906 			v1 = level1
  31907 			if v1 > int32(MAX_VARIABLE_LEVEL) {
  31908 				v6 = int32(MAX_VARIABLE_LEVEL)
  31909 			} else {
  31910 				v6 = v1
  31911 			}
  31912 			v4 = libc.Int32FromUint16(VP8LevelFixedCosts[v1]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fcosts + uintptr(v6)*2)))
  31913 			goto _23
  31914 		_23:
  31915 			cost1 = int64(v4)
  31916 			best_cur_score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  31917 			best_prev = -MIN_DELTA
  31918 			p = -libc.Int32FromInt32(MIN_DELTA) + libc.Int32FromInt32(1)
  31919 			for {
  31920 				if !(p <= int32(MAX_DELTA)) {
  31921 					break
  31922 				}
  31923 				// Dead nodes (with ss_prev[p].score >= MAX_COST) are automatically
  31924 				// eliminated since their score can't be better than the current best.
  31925 				v1 = level1
  31926 				if v1 > int32(MAX_VARIABLE_LEVEL) {
  31927 					v6 = int32(MAX_VARIABLE_LEVEL)
  31928 				} else {
  31929 					v6 = v1
  31930 				}
  31931 				v4 = libc.Int32FromUint16(VP8LevelFixedCosts[v1]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fcosts + uintptr(v6)*2)))
  31932 				goto _28
  31933 			_28:
  31934 				cost1 = int64(v4)
  31935 				// Examine node assuming it's a non-terminal one.
  31936 				score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  31937 				if score < best_cur_score {
  31938 					best_cur_score = score
  31939 					best_prev = p
  31940 				}
  31941 				goto _25
  31942 			_25:
  31943 				;
  31944 				p = p + 1
  31945 			}
  31946 			best_cur_score = best_cur_score + base_score
  31947 			// Store best finding in current node.
  31948 			(*Node)(unsafe.Pointer(cur)).Fsign = int8(sign)
  31949 			(*Node)(unsafe.Pointer(cur)).Flevel = int16(level1)
  31950 			(*Node)(unsafe.Pointer(cur)).Fprev = int8(best_prev)
  31951 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = best_cur_score
  31952 			// Now, record best terminal node (and thus best entry in the graph).
  31953 			if level1 != 0 && best_cur_score < best_score {
  31954 				if n1 < int32(15) {
  31955 					v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(band)*33 + uintptr(ctx)*11))
  31956 					if !(0 != 0) {
  31957 						v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  31958 					} else {
  31959 						v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  31960 					}
  31961 					v4 = v6
  31962 					goto _33
  31963 				_33:
  31964 					v1 = v4
  31965 				} else {
  31966 					v1 = 0
  31967 				}
  31968 				last_pos_cost = int64(v1)
  31969 				last_pos_score = RDScoreTrellis(tls, lambda, last_pos_cost, 0)
  31970 				score = best_cur_score + last_pos_score
  31971 				if score < best_score {
  31972 					best_score = score
  31973 					best_path[0] = n1               // best eob position
  31974 					best_path[int32(1)] = m         // best node index
  31975 					best_path[int32(2)] = best_prev // best predecessor
  31976 				}
  31977 			}
  31978 			goto _19
  31979 		_19:
  31980 			;
  31981 			m = m + 1
  31982 		}
  31983 		goto _13
  31984 	_13:
  31985 		;
  31986 		n1 = n1 + 1
  31987 	}
  31988 	// Fresh start
  31989 	// Beware! We must preserve in[0]/out[0] value for TYPE_I16_AC case.
  31990 	if coeff_type == int32(TYPE_I16_AC) {
  31991 		libc.Xmemset(tls, in+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  31992 		libc.Xmemset(tls, out+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  31993 	} else {
  31994 		libc.Xmemset(tls, in, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  31995 		libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  31996 	}
  31997 	if best_path[0] == -int32(1) {
  31998 		return 0 // skip!
  31999 	}
  32000 	// Unwind the best path.
  32001 	// Note: best-prev on terminal node is not necessarily equal to the
  32002 	// best_prev for non-terminal. So we patch best_path[2] in.
  32003 	nz = 0
  32004 	best_node = best_path[int32(1)]
  32005 	n1 = best_path[0]
  32006 	(**(**Node)(__ccgo_up(bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4))).Fprev = int8(best_path[int32(2)]) // force best-prev for terminal
  32007 	for {
  32008 		if !(n1 >= first) {
  32009 			break
  32010 		}
  32011 		node = bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4
  32012 		j2 = libc.Int32FromUint8(kZigzag1[n1])
  32013 		if (*Node)(unsafe.Pointer(node)).Fsign != 0 {
  32014 			v1 = -int32((*Node)(unsafe.Pointer(node)).Flevel)
  32015 		} else {
  32016 			v1 = int32((*Node)(unsafe.Pointer(node)).Flevel)
  32017 		}
  32018 		**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(v1)
  32019 		nz = nz | int32((*Node)(unsafe.Pointer(node)).Flevel)
  32020 		**(**int16_t)(__ccgo_up(in + uintptr(j2)*2)) = int16(int32(**(**int16_t)(__ccgo_up(out + uintptr(n1)*2))) * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + uintptr(j2)*2))))
  32021 		best_node = int32((*Node)(unsafe.Pointer(node)).Fprev)
  32022 		goto _35
  32023 	_35:
  32024 		;
  32025 		n1 = n1 - 1
  32026 	}
  32027 	return libc.BoolInt32(nz != 0)
  32028 	return r
  32029 }
  32030 
  32031 //------------------------------------------------------------------------------
  32032 // Performs: difference, transform, quantize, back-transform, add
  32033 // all at once. Output is the reconstructed block in *yuv_out, and the
  32034 // quantized levels in *levels.
  32035 
  32036 func ReconstructIntra16(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32037 	bp := tls.Alloc(544)
  32038 	defer tls.Free(544)
  32039 	var ctx, n, non_zero, nz, x, y, v4 int32
  32040 	var dqm, enc, ref, src uintptr
  32041 	var v6 int16_t
  32042 	var _ /* dc_tmp at bp+512 */ [16]int16_t
  32043 	var _ /* tmp at bp+0 */ [16][16]int16_t
  32044 	_, _, _, _, _, _, _, _, _, _, _, _ = ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v4, v6
  32045 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32046 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  32047 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32048 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32049 	nz = 0
  32050 	n = 0
  32051 	for {
  32052 		if !(n < int32(16)) {
  32053 			break
  32054 		}
  32055 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8Scan[n]), ref+uintptr(VP8Scan[n]), bp+uintptr(n)*32)
  32056 		goto _1
  32057 	_1:
  32058 		;
  32059 		n = n + int32(2)
  32060 	}
  32061 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransformWHT})))(tls, bp, bp+512)
  32062 	nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlockWHT})))(tls, bp+512, rd+40, dqm+224)<<int32(24)
  32063 	if libc.Bool(int32(DO_TRELLIS_I16) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32064 		VP8IteratorNzToBytes(tls, it)
  32065 		y = 0
  32066 		n = libc.Int32FromInt32(0)
  32067 		for {
  32068 			if !(y < int32(4)) {
  32069 				break
  32070 			}
  32071 			x = 0
  32072 			for {
  32073 				if !(x < int32(4)) {
  32074 					break
  32075 				}
  32076 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32077 				non_zero = TrellisQuantizeBlock(tls, enc, bp+uintptr(n)*32, rd+72+uintptr(n)*32, ctx, int32(TYPE_I16_AC), dqm, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_trellis_i16)
  32078 				v4 = non_zero
  32079 				**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  32080 				**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  32081 				**(**int16_t)(__ccgo_up(rd + 72 + uintptr(n)*32)) = 0
  32082 				nz = nz | non_zero<<n
  32083 				goto _3
  32084 			_3:
  32085 				;
  32086 				x = x + 1
  32087 				n = n + 1
  32088 			}
  32089 			goto _2
  32090 		_2:
  32091 			;
  32092 			y = y + 1
  32093 		}
  32094 	} else {
  32095 		n = 0
  32096 		for {
  32097 			if !(n < int32(16)) {
  32098 				break
  32099 			}
  32100 			// Zero-out the first coeff, so that: a) nz is correct below, and
  32101 			// b) finding 'last' non-zero coeffs in SetResidualCoeffs() is simplified.
  32102 			v6 = libc.Int16FromInt32(0)
  32103 			**(**int16_t)(__ccgo_up(bp + uintptr(n+int32(1))*32)) = v6
  32104 			**(**int16_t)(__ccgo_up(bp + uintptr(n)*32)) = v6
  32105 			nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantize2Blocks})))(tls, bp+uintptr(n)*32, rd+72+uintptr(n)*32, dqm)<<n
  32106 			goto _5
  32107 		_5:
  32108 			;
  32109 			n = n + int32(2)
  32110 		}
  32111 	}
  32112 	// Transform back
  32113 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp+512, bp)
  32114 	n = 0
  32115 	for {
  32116 		if !(n < int32(16)) {
  32117 			break
  32118 		}
  32119 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8ITransform})))(tls, ref+uintptr(VP8Scan[n]), bp+uintptr(n)*32, yuv_out+uintptr(VP8Scan[n]), int32(1))
  32120 		goto _7
  32121 	_7:
  32122 		;
  32123 		n = n + int32(2)
  32124 	}
  32125 	return nz
  32126 }
  32127 
  32128 func ReconstructIntra4(tls *libc.TLS, it uintptr, levels uintptr, src uintptr, yuv_out uintptr, mode int32) (r int32) {
  32129 	bp := tls.Alloc(32)
  32130 	defer tls.Free(32)
  32131 	var ctx, nz, x, y int32
  32132 	var dqm, enc, ref uintptr
  32133 	var _ /* tmp at bp+0 */ [16]int16_t
  32134 	_, _, _, _, _, _, _ = ctx, dqm, enc, nz, ref, x, y
  32135 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32136 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  32137 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32138 	nz = 0
  32139 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, bp)
  32140 	if libc.Bool(int32(DO_TRELLIS_I4) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32141 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & int32(3)
  32142 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32143 		ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32144 		nz = TrellisQuantizeBlock(tls, enc, bp, levels, ctx, int32(TYPE_I4_AC), dqm, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_trellis_i4)
  32145 	} else {
  32146 		nz = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlock})))(tls, bp, levels, dqm)
  32147 	}
  32148 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8ITransform})))(tls, ref, bp, yuv_out, 0)
  32149 	return nz
  32150 }
  32151 
  32152 //------------------------------------------------------------------------------
  32153 // DC-error diffusion
  32154 
  32155 // Diffusion weights. We under-correct a bit (15/16th of the error is actually
  32156 // diffused) to avoid 'rainbow' chessboard pattern of blocks at q~=0.
  32157 
  32158 // C documentation
  32159 //
  32160 //	// Quantize as usual, but also compute and return the quantization error.
  32161 //	// Error is already divided by DSHIFT.
  32162 func QuantizeSingle(tls *libc.TLS, v uintptr, mtx uintptr) (r int32) {
  32163 	var V, err, qV, sign, v1, v3 int32
  32164 	_, _, _, _, _, _ = V, err, qV, sign, v1, v3
  32165 	V = int32(**(**int16_t)(__ccgo_up(v)))
  32166 	sign = libc.BoolInt32(V < libc.Int32FromInt32(0))
  32167 	if sign != 0 {
  32168 		V = -V
  32169 	}
  32170 	if V > libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(mtx + 128))) {
  32171 		v1 = libc.Int32FromUint32((libc.Uint32FromInt32(V)*uint32(**(**uint16_t)(__ccgo_up(mtx + 32))) + **(**uint32_t)(__ccgo_up(mtx + 64))) >> libc.Int32FromInt32(QFIX))
  32172 		goto _2
  32173 	_2:
  32174 		qV = v1 * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx)))
  32175 		err = V - qV
  32176 		if sign != 0 {
  32177 			v3 = -qV
  32178 		} else {
  32179 			v3 = qV
  32180 		}
  32181 		**(**int16_t)(__ccgo_up(v)) = int16(v3)
  32182 		if sign != 0 {
  32183 			v1 = -err
  32184 		} else {
  32185 			v1 = err
  32186 		}
  32187 		return v1 >> int32(1)
  32188 	}
  32189 	**(**int16_t)(__ccgo_up(v)) = 0
  32190 	if sign != 0 {
  32191 		v1 = -V
  32192 	} else {
  32193 		v1 = V
  32194 	}
  32195 	return v1 >> int32(1)
  32196 }
  32197 
  32198 func CorrectDCValues(tls *libc.TLS, it uintptr, mtx uintptr, tmp uintptr, rd uintptr) {
  32199 	var c, left, top, v2 uintptr
  32200 	var ch, err0, err1, err2, err3 int32
  32201 	_, _, _, _, _, _, _, _, _ = c, ch, err0, err1, err2, err3, left, top, v2
  32202 	ch = 0
  32203 	for {
  32204 		if !(ch <= int32(1)) {
  32205 			break
  32206 		}
  32207 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32208 		left = it + 344 + uintptr(ch)*2
  32209 		c = tmp + uintptr(ch*int32(4))*32
  32210 		v2 = c
  32211 		*(*int16_t)(unsafe.Pointer(v2)) = int16_t(int32(*(*int16_t)(unsafe.Pointer(v2))) + (libc.Int32FromInt32(7)*int32(**(**int8_t)(__ccgo_up(top)))+libc.Int32FromInt32(8)*int32(**(**int8_t)(__ccgo_up(left))))>>(libc.Int32FromInt32(4)-libc.Int32FromInt32(1)))
  32212 		err0 = QuantizeSingle(tls, c, mtx)
  32213 		v2 = c + 1*32
  32214 		*(*int16_t)(unsafe.Pointer(v2)) = int16_t(int32(*(*int16_t)(unsafe.Pointer(v2))) + (libc.Int32FromInt32(7)*int32(**(**int8_t)(__ccgo_up(top + 1)))+libc.Int32FromInt32(8)*err0)>>(libc.Int32FromInt32(4)-libc.Int32FromInt32(1)))
  32215 		err1 = QuantizeSingle(tls, c+1*32, mtx)
  32216 		v2 = c + 2*32
  32217 		*(*int16_t)(unsafe.Pointer(v2)) = int16_t(int32(*(*int16_t)(unsafe.Pointer(v2))) + (libc.Int32FromInt32(7)*err0+libc.Int32FromInt32(8)*int32(**(**int8_t)(__ccgo_up(left + 1))))>>(libc.Int32FromInt32(4)-libc.Int32FromInt32(1)))
  32218 		err2 = QuantizeSingle(tls, c+2*32, mtx)
  32219 		v2 = c + 3*32
  32220 		*(*int16_t)(unsafe.Pointer(v2)) = int16_t(int32(*(*int16_t)(unsafe.Pointer(v2))) + (libc.Int32FromInt32(7)*err1+libc.Int32FromInt32(8)*err2)>>(libc.Int32FromInt32(4)-libc.Int32FromInt32(1)))
  32221 		err3 = QuantizeSingle(tls, c+3*32, mtx)
  32222 		// error 'err' is bounded by mtx->q[0] which is 132 at max. Hence
  32223 		// err >> DSCALE will fit in an int8_t type if DSCALE>=1.
  32224 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3)) = int8(err1)
  32225 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1)) = int8(err2)
  32226 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 2)) = int8(err3)
  32227 		goto _1
  32228 	_1:
  32229 		;
  32230 		ch = ch + 1
  32231 	}
  32232 }
  32233 
  32234 func StoreDiffusionErrors(tls *libc.TLS, it uintptr, rd uintptr) {
  32235 	var ch int32
  32236 	var left, top uintptr
  32237 	_, _, _ = ch, left, top
  32238 	ch = 0
  32239 	for {
  32240 		if !(ch <= int32(1)) {
  32241 			break
  32242 		}
  32243 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32244 		left = it + 344 + uintptr(ch)*2
  32245 		**(**int8_t)(__ccgo_up(left)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3))                                                                // restore err1
  32246 		**(**int8_t)(__ccgo_up(left + 1)) = int8(int32(3) * int32(**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 2))) >> int32(2))                    //     ... 3/4th of err3
  32247 		**(**int8_t)(__ccgo_up(top)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1))                                                             //     ... err2
  32248 		**(**int8_t)(__ccgo_up(top + 1)) = int8(int32(**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 2))) - int32(**(**int8_t)(__ccgo_up(left + 1)))) //     ... 1/4th of err3.
  32249 		goto _1
  32250 	_1:
  32251 		;
  32252 		ch = ch + 1
  32253 	}
  32254 }
  32255 
  32256 //------------------------------------------------------------------------------
  32257 
  32258 func ReconstructUV(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32259 	bp := tls.Alloc(256)
  32260 	defer tls.Free(256)
  32261 	var ch, ctx, n, non_zero, nz, x, y, v5 int32
  32262 	var dqm, enc, ref, src uintptr
  32263 	var _ /* tmp at bp+0 */ [8][16]int16_t
  32264 	_, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v5
  32265 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32266 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  32267 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32268 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32269 	nz = 0
  32270 	n = 0
  32271 	for {
  32272 		if !(n < int32(8)) {
  32273 			break
  32274 		}
  32275 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8ScanUV[n]), ref+uintptr(VP8ScanUV[n]), bp+uintptr(n)*32)
  32276 		goto _1
  32277 	_1:
  32278 		;
  32279 		n = n + int32(2)
  32280 	}
  32281 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  32282 		CorrectDCValues(tls, it, dqm+448, bp, rd)
  32283 	}
  32284 	if libc.Bool(DO_TRELLIS_UV != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32285 		ch = 0
  32286 		n = libc.Int32FromInt32(0)
  32287 		for {
  32288 			if !(ch <= int32(2)) {
  32289 				break
  32290 			}
  32291 			y = 0
  32292 			for {
  32293 				if !(y < int32(2)) {
  32294 					break
  32295 				}
  32296 				x = 0
  32297 				for {
  32298 					if !(x < int32(2)) {
  32299 						break
  32300 					}
  32301 					ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  32302 					non_zero = TrellisQuantizeBlock(tls, enc, bp+uintptr(n)*32, rd+584+uintptr(n)*32, ctx, int32(TYPE_CHROMA_A), dqm+448, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_trellis_uv)
  32303 					v5 = non_zero
  32304 					**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v5
  32305 					**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v5
  32306 					nz = nz | non_zero<<n
  32307 					goto _4
  32308 				_4:
  32309 					;
  32310 					x = x + 1
  32311 					n = n + 1
  32312 				}
  32313 				goto _3
  32314 			_3:
  32315 				;
  32316 				y = y + 1
  32317 			}
  32318 			goto _2
  32319 		_2:
  32320 			;
  32321 			ch = ch + int32(2)
  32322 		}
  32323 	} else {
  32324 		n = 0
  32325 		for {
  32326 			if !(n < int32(8)) {
  32327 				break
  32328 			}
  32329 			nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantize2Blocks})))(tls, bp+uintptr(n)*32, rd+584+uintptr(n)*32, dqm+448)<<n
  32330 			goto _6
  32331 		_6:
  32332 			;
  32333 			n = n + int32(2)
  32334 		}
  32335 	}
  32336 	n = 0
  32337 	for {
  32338 		if !(n < int32(8)) {
  32339 			break
  32340 		}
  32341 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8ITransform})))(tls, ref+uintptr(VP8ScanUV[n]), bp+uintptr(n)*32, yuv_out+uintptr(VP8ScanUV[n]), int32(1))
  32342 		goto _7
  32343 	_7:
  32344 		;
  32345 		n = n + int32(2)
  32346 	}
  32347 	return nz << int32(16)
  32348 }
  32349 
  32350 //------------------------------------------------------------------------------
  32351 // RD-opt decision. Reconstruct each modes, evalue distortion and bit-cost.
  32352 // Pick the mode is lower RD-cost = Rate + lambda * Distortion.
  32353 
  32354 func StoreMaxDelta(tls *libc.TLS, dqm uintptr, DCs uintptr) {
  32355 	var max_v, v0, v1, v2, v11, v21 int32
  32356 	_, _, _, _, _, _ = max_v, v0, v1, v2, v11, v21
  32357 	// We look at the first three AC coefficients to determine what is the average
  32358 	// delta between each sub-4x4 block.
  32359 	v0 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 1*2))))
  32360 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 2*2))))
  32361 	v2 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 4*2))))
  32362 	if v1 > v0 {
  32363 		v11 = v1
  32364 	} else {
  32365 		v11 = v0
  32366 	}
  32367 	max_v = v11
  32368 	if v2 > max_v {
  32369 		v21 = v2
  32370 	} else {
  32371 		v21 = max_v
  32372 	}
  32373 	max_v = v21
  32374 	if max_v > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge {
  32375 		(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge = max_v
  32376 	}
  32377 }
  32378 
  32379 func SwapModeScore(tls *libc.TLS, a uintptr, b uintptr) {
  32380 	var tmp uintptr
  32381 	_ = tmp
  32382 	tmp = **(**uintptr)(__ccgo_up(a))
  32383 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32384 	**(**uintptr)(__ccgo_up(b)) = tmp
  32385 }
  32386 
  32387 func SwapPtr(tls *libc.TLS, a uintptr, b uintptr) {
  32388 	var tmp uintptr
  32389 	_ = tmp
  32390 	tmp = **(**uintptr)(__ccgo_up(a))
  32391 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32392 	**(**uintptr)(__ccgo_up(b)) = tmp
  32393 }
  32394 
  32395 func SwapOut(tls *libc.TLS, it uintptr) {
  32396 	SwapPtr(tls, it+16, it+24)
  32397 }
  32398 
  32399 func PickBestIntra16(tls *libc.TLS, it uintptr, rd uintptr) {
  32400 	bp := tls.Alloc(912)
  32401 	defer tls.Free(912)
  32402 	var dqm, src1, tmp_dst, v1 uintptr
  32403 	var i, i1, is_flat, kNumBlocks, lambda, mode, score, tlambda, v3, v6, v8 int32
  32404 	var _ /* rd_best at bp+896 */ uintptr
  32405 	var _ /* rd_cur at bp+888 */ uintptr
  32406 	var _ /* rd_tmp at bp+8 */ VP8ModeScore
  32407 	var _ /* v at bp+0 */ uint32_t
  32408 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, i, i1, is_flat, kNumBlocks, lambda, mode, score, src1, tlambda, tmp_dst, v1, v3, v6, v8
  32409 	kNumBlocks = int32(16)
  32410 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32411 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i16
  32412 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32413 	src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32414 	**(**uintptr)(__ccgo_up(bp + 888)) = bp + 8
  32415 	**(**uintptr)(__ccgo_up(bp + 896)) = rd
  32416 	v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32417 	**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v1))) * uint32(0x01010101)
  32418 	i1 = libc.Int32FromInt32(0)
  32419 	for {
  32420 		if !(i1 < libc.Int32FromInt32(16)) {
  32421 			break
  32422 		}
  32423 		if libc.Xmemcmp(tls, v1+uintptr(0), bp, uint64(4)) != 0 || libc.Xmemcmp(tls, v1+uintptr(4), bp, uint64(4)) != 0 || libc.Xmemcmp(tls, v1+uintptr(8), bp, uint64(4)) != 0 || libc.Xmemcmp(tls, v1+uintptr(12), bp, uint64(4)) != 0 {
  32424 			v3 = 0
  32425 			goto _4
  32426 		}
  32427 		v1 = v1 + uintptr(BPS)
  32428 		goto _2
  32429 	_2:
  32430 		;
  32431 		i1 = i1 + 1
  32432 	}
  32433 	v3 = int32(1)
  32434 	goto _4
  32435 _4:
  32436 	is_flat = v3
  32437 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16 = -int32(1)
  32438 	mode = 0
  32439 	for {
  32440 		if !(mode < int32(NUM_PRED_MODES)) {
  32441 			break
  32442 		}
  32443 		tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) // scratch buffer
  32444 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fmode_i16 = mode
  32445 		// Reconstruct
  32446 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fnz = libc.Uint32FromInt32(ReconstructIntra16(tls, it, **(**uintptr)(__ccgo_up(bp + 888)), tmp_dst, mode))
  32447 		// Measure RD-score
  32448 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FD = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x16})))(tls, src1, tmp_dst))
  32449 		if tlambda != 0 {
  32450 			v3 = (tlambda*(*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8TDisto16x16})))(tls, src1, tmp_dst, uintptr(unsafe.Pointer(&kWeightY))) + int32(128)) >> int32(8)
  32451 		} else {
  32452 			v3 = 0
  32453 		}
  32454 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FSD = int64(v3)
  32455 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FH = libc.Int64FromUint16(VP8FixedCostsI16[mode])
  32456 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FR = int64(VP8GetCostLuma16(tls, it, **(**uintptr)(__ccgo_up(bp + 888))))
  32457 		if is_flat != 0 {
  32458 			// refine the first impression (which was in pixel space)
  32459 			v1 = **(**uintptr)(__ccgo_up(bp + 888)) + 72
  32460 			v3 = kNumBlocks
  32461 			score = 0
  32462 			for {
  32463 				v6 = v3
  32464 				v3 = v3 - 1
  32465 				if !(v6 > libc.Int32FromInt32(0)) {
  32466 					break
  32467 				}
  32468 				i = libc.Int32FromInt32(1)
  32469 				for {
  32470 					if !(i < libc.Int32FromInt32(16)) {
  32471 						break
  32472 					}
  32473 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v1 + uintptr(i)*2))) != 0)
  32474 					if score > FLATNESS_LIMIT_I16 {
  32475 						v8 = 0
  32476 						goto _12
  32477 					}
  32478 					goto _10
  32479 				_10:
  32480 					;
  32481 					i = i + 1
  32482 				}
  32483 				v1 = v1 + uintptr(16)*2
  32484 			}
  32485 			v8 = int32(1)
  32486 			goto _12
  32487 		_12:
  32488 			is_flat = v8
  32489 			if is_flat != 0 {
  32490 				// Block is very flat. We put emphasis on the distortion being very low!
  32491 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)))) *= int64(2)
  32492 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)) + 8)) *= int64(2)
  32493 			}
  32494 		}
  32495 		// Since we always examine Intra16 first, we can overwrite *rd directly.
  32496 		SetRDScore(tls, lambda, **(**uintptr)(__ccgo_up(bp + 888)))
  32497 		if mode == 0 || (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fscore < (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 896)))).Fscore {
  32498 			SwapModeScore(tls, bp+888, bp+896)
  32499 			SwapOut(tls, it)
  32500 		}
  32501 		goto _5
  32502 	_5:
  32503 		;
  32504 		mode = mode + 1
  32505 	}
  32506 	if **(**uintptr)(__ccgo_up(bp + 896)) != rd {
  32507 		libc.Xmemcpy(tls, rd, **(**uintptr)(__ccgo_up(bp + 896)), uint64(880))
  32508 	}
  32509 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, rd) // finalize score for mode decision.
  32510 	VP8SetIntra16Mode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16)
  32511 	// we have a blocky macroblock (only DCs are non-zero) with fairly high
  32512 	// distortion, record max delta so we can later adjust the minimal filtering
  32513 	// strength needed to smooth these blocks out.
  32514 	if (*VP8ModeScore)(unsafe.Pointer(rd)).Fnz&uint32(0x100ffff) == uint32(0x1000000) && (*VP8ModeScore)(unsafe.Pointer(rd)).FD > int64((*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmin_disto) {
  32515 		StoreMaxDelta(tls, dqm, rd+40)
  32516 	}
  32517 }
  32518 
  32519 //------------------------------------------------------------------------------
  32520 
  32521 // C documentation
  32522 //
  32523 //	// return the cost array corresponding to the surrounding prediction modes.
  32524 func GetCostModeI4(tls *libc.TLS, it uintptr, modes uintptr) (r uintptr) {
  32525 	var left, preds_w, top, x, y, v1, v2 int32
  32526 	_, _, _, _, _, _, _ = left, preds_w, top, x, y, v1, v2
  32527 	preds_w = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w
  32528 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  32529 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32530 	if x == 0 {
  32531 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(y*preds_w-int32(1)))))
  32532 	} else {
  32533 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(1)))))
  32534 	}
  32535 	left = v1
  32536 	if y == 0 {
  32537 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(-preds_w+x))))
  32538 	} else {
  32539 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(4)))))
  32540 	}
  32541 	top = v2
  32542 	return uintptr(unsafe.Pointer(&VP8FixedCostsI4)) + uintptr(top)*200 + uintptr(left)*20
  32543 }
  32544 
  32545 func PickBestIntra4(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  32546 	bp := tls.Alloc(2688)
  32547 	defer tls.Free(2688)
  32548 	var best_blocks, dqm, enc, mode_costs, src, src0, v3 uintptr
  32549 	var best_mode, i, kNumBlocks, lambda, mode, score, tlambda, total_header_bits, v2, v4, v5 int32
  32550 	var v9 bool
  32551 	var _ /* best_block at bp+1760 */ uintptr
  32552 	var _ /* rd_best at bp+0 */ VP8ModeScore
  32553 	var _ /* rd_i4 at bp+880 */ VP8ModeScore
  32554 	var _ /* rd_tmp at bp+1776 */ VP8ModeScore
  32555 	var _ /* tmp_dst at bp+1768 */ uintptr
  32556 	var _ /* tmp_levels at bp+2656 */ [16]int16_t
  32557 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_blocks, best_mode, dqm, enc, i, kNumBlocks, lambda, mode, mode_costs, score, src, src0, tlambda, total_header_bits, v2, v3, v4, v5, v9
  32558 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32559 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32560 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i4
  32561 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32562 	src0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32563 	best_blocks = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32564 	total_header_bits = 0
  32565 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits == 0 {
  32566 		return 0
  32567 	}
  32568 	InitScore(tls, bp)
  32569 	(**(**VP8ModeScore)(__ccgo_up(bp))).FH = int64(211) // '211' is the value of VP8BitCost(0, 145)
  32570 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp)
  32571 	VP8IteratorStartI4(tls, it)
  32572 	for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, best_blocks) != 0 {
  32573 		kNumBlocks = int32(1)
  32574 		best_mode = -int32(1)
  32575 		src = src0 + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32576 		mode_costs = GetCostModeI4(tls, it, rd+844)
  32577 		**(**uintptr)(__ccgo_up(bp + 1760)) = best_blocks + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32578 		**(**uintptr)(__ccgo_up(bp + 1768)) = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)) // scratch buffer.
  32579 		InitScore(tls, bp+880)
  32580 		MakeIntra4Preds(tls, it)
  32581 		mode = 0
  32582 		for {
  32583 			if !(mode < int32(NUM_BMODES)) {
  32584 				break
  32585 			}
  32586 			// Reconstruct
  32587 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fnz = libc.Uint32FromInt32(ReconstructIntra4(tls, it, bp+2656, src, **(**uintptr)(__ccgo_up(bp + 1768)), mode) << (*VP8EncIterator)(unsafe.Pointer(it)).Fi4)
  32588 			// Compute RD-score
  32589 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FD = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE4x4})))(tls, src, **(**uintptr)(__ccgo_up(bp + 1768))))
  32590 			if tlambda != 0 {
  32591 				v2 = (tlambda*(*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8TDisto4x4})))(tls, src, **(**uintptr)(__ccgo_up(bp + 1768)), uintptr(unsafe.Pointer(&kWeightY))) + int32(128)) >> int32(8)
  32592 			} else {
  32593 				v2 = 0
  32594 			}
  32595 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FSD = int64(v2)
  32596 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FH = libc.Int64FromUint16(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(mode)*2)))
  32597 			// Add flatness penalty, to avoid flat area to be mispredicted
  32598 			// by a complex mode.
  32599 			if v9 = mode > 0; v9 {
  32600 				v3 = bp + 2656
  32601 				v2 = kNumBlocks
  32602 				score = 0
  32603 				for {
  32604 					v4 = v2
  32605 					v2 = v2 - 1
  32606 					if !(v4 > libc.Int32FromInt32(0)) {
  32607 						break
  32608 					}
  32609 					i = libc.Int32FromInt32(1)
  32610 					for {
  32611 						if !(i < libc.Int32FromInt32(16)) {
  32612 							break
  32613 						}
  32614 						score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v3 + uintptr(i)*2))) != 0)
  32615 						if score > int32(FLATNESS_LIMIT_I4) {
  32616 							v5 = 0
  32617 							goto _8
  32618 						}
  32619 						goto _6
  32620 					_6:
  32621 						;
  32622 						i = i + 1
  32623 					}
  32624 					v3 = v3 + uintptr(16)*2
  32625 				}
  32626 				v5 = int32(1)
  32627 				goto _8
  32628 			_8:
  32629 			}
  32630 			if v9 && v5 != 0 {
  32631 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  32632 			} else {
  32633 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = 0
  32634 			}
  32635 			// early-out check
  32636 			SetRDScore(tls, lambda, bp+1776)
  32637 			if best_mode >= 0 && (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore >= (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32638 				goto _1
  32639 			}
  32640 			// finish computing score
  32641 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR += int64(VP8GetCostLuma4(tls, it, bp+2656))
  32642 			SetRDScore(tls, lambda, bp+1776)
  32643 			if best_mode < 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32644 				CopyScore(tls, bp+880, bp+1776)
  32645 				best_mode = mode
  32646 				SwapPtr(tls, bp+1768, bp+1760)
  32647 				libc.Xmemcpy(tls, bp+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, bp+2656, uint64(32))
  32648 			}
  32649 			goto _1
  32650 		_1:
  32651 			;
  32652 			mode = mode + 1
  32653 		}
  32654 		SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp+880)
  32655 		AddScore(tls, bp, bp+880)
  32656 		if (**(**VP8ModeScore)(__ccgo_up(bp))).Fscore >= (*VP8ModeScore)(unsafe.Pointer(rd)).Fscore {
  32657 			return 0
  32658 		}
  32659 		total_header_bits = total_header_bits + int32((**(**VP8ModeScore)(__ccgo_up(bp + 880))).FH) // <- equal to mode_costs[best_mode];
  32660 		if total_header_bits > (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits {
  32661 			return 0
  32662 		}
  32663 		// Copy selected samples if not in the right place already.
  32664 		if **(**uintptr)(__ccgo_up(bp + 1760)) != best_blocks+uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4]) {
  32665 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8Copy4x4})))(tls, **(**uintptr)(__ccgo_up(bp + 1760)), best_blocks+uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4]))
  32666 		}
  32667 		**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = libc.Uint8FromInt32(best_mode)
  32668 		if (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fnz != 0 {
  32669 			v4 = int32(1)
  32670 		} else {
  32671 			v4 = 0
  32672 		}
  32673 		v2 = v4
  32674 		**(**int32)(__ccgo_up(it + 168 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4>>int32(2))*4)) = v2
  32675 		**(**int32)(__ccgo_up(it + 132 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3))*4)) = v2
  32676 	}
  32677 	// finalize state
  32678 	CopyScore(tls, rd, bp)
  32679 	VP8SetIntra4Mode(tls, it, rd+844)
  32680 	SwapOut(tls, it)
  32681 	libc.Xmemcpy(tls, rd+72, bp+72, uint64(512))
  32682 	return int32(1) // select intra4x4 over intra16x16
  32683 }
  32684 
  32685 //------------------------------------------------------------------------------
  32686 
  32687 func PickBestUV(tls *libc.TLS, it uintptr, rd uintptr) {
  32688 	bp := tls.Alloc(1776)
  32689 	defer tls.Free(1776)
  32690 	var dqm, dst0, src, v2 uintptr
  32691 	var i, kNumBlocks, lambda, mode, score, v3, v4, v6 int32
  32692 	var v8 bool
  32693 	var _ /* dst at bp+8 */ uintptr
  32694 	var _ /* rd_best at bp+16 */ VP8ModeScore
  32695 	var _ /* rd_uv at bp+896 */ VP8ModeScore
  32696 	var _ /* tmp_dst at bp+0 */ uintptr
  32697 	_, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, dst0, i, kNumBlocks, lambda, mode, score, src, v2, v3, v4, v6, v8
  32698 	kNumBlocks = int32(8)
  32699 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32700 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_uv
  32701 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32702 	**(**uintptr)(__ccgo_up(bp)) = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC)) // scratch buffer
  32703 	dst0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32704 	**(**uintptr)(__ccgo_up(bp + 8)) = dst0
  32705 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = -int32(1)
  32706 	InitScore(tls, bp+16)
  32707 	mode = 0
  32708 	for {
  32709 		if !(mode < int32(NUM_PRED_MODES)) {
  32710 			break
  32711 		}
  32712 		// Reconstruct
  32713 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fnz = libc.Uint32FromInt32(ReconstructUV(tls, it, bp+896, **(**uintptr)(__ccgo_up(bp)), mode))
  32714 		// Compute RD-score
  32715 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FD = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x8})))(tls, src, **(**uintptr)(__ccgo_up(bp))))
  32716 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FSD = 0 // not calling TDisto here: it tends to flatten areas.
  32717 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FH = libc.Int64FromUint16(VP8FixedCostsUV[mode])
  32718 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR = int64(VP8GetCostUV(tls, it, bp+896))
  32719 		if v8 = mode > 0; v8 {
  32720 			v2 = bp + 896 + 584
  32721 			v3 = kNumBlocks
  32722 			score = 0
  32723 			for {
  32724 				v4 = v3
  32725 				v3 = v3 - 1
  32726 				if !(v4 > libc.Int32FromInt32(0)) {
  32727 					break
  32728 				}
  32729 				i = libc.Int32FromInt32(1)
  32730 				for {
  32731 					if !(i < libc.Int32FromInt32(16)) {
  32732 						break
  32733 					}
  32734 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v2 + uintptr(i)*2))) != 0)
  32735 					if score > int32(FLATNESS_LIMIT_UV) {
  32736 						v6 = 0
  32737 						goto _7
  32738 					}
  32739 					goto _5
  32740 				_5:
  32741 					;
  32742 					i = i + 1
  32743 				}
  32744 				v2 = v2 + uintptr(16)*2
  32745 			}
  32746 			v6 = int32(1)
  32747 			goto _7
  32748 		_7:
  32749 		}
  32750 		if v8 && v6 != 0 {
  32751 			(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR += int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  32752 		}
  32753 		SetRDScore(tls, lambda, bp+896)
  32754 		if mode == 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 16))).Fscore {
  32755 			CopyScore(tls, bp+16, bp+896)
  32756 			(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = mode
  32757 			libc.Xmemcpy(tls, rd+584, bp+896+584, uint64(256))
  32758 			if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  32759 				libc.Xmemcpy(tls, rd+868, bp+896+868, uint64(6))
  32760 			}
  32761 			SwapPtr(tls, bp+8, bp)
  32762 		}
  32763 		goto _1
  32764 	_1:
  32765 		;
  32766 		mode = mode + 1
  32767 	}
  32768 	VP8SetIntraUVMode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv)
  32769 	AddScore(tls, rd, bp+16)
  32770 	if **(**uintptr)(__ccgo_up(bp + 8)) != dst0 { // copy 16x8 block if needed
  32771 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8Copy16x8})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), dst0)
  32772 	}
  32773 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) { // store diffusion errors for next block
  32774 		StoreDiffusionErrors(tls, it, rd)
  32775 	}
  32776 }
  32777 
  32778 //------------------------------------------------------------------------------
  32779 // Final reconstruction and quantization.
  32780 
  32781 func SimpleQuantize(tls *libc.TLS, it uintptr, rd uintptr) {
  32782 	var dst, enc, src uintptr
  32783 	var is_i16, mode, nz int32
  32784 	_, _, _, _, _, _ = dst, enc, is_i16, mode, nz, src
  32785 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32786 	is_i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  32787 	nz = 0
  32788 	if is_i16 != 0 {
  32789 		nz = ReconstructIntra16(tls, it, rd, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds))))
  32790 	} else {
  32791 		VP8IteratorStartI4(tls, it)
  32792 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  32793 			mode = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3)+(*VP8EncIterator)(unsafe.Pointer(it)).Fi4>>int32(2)*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w))))
  32794 			src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32795 			dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32796 			MakeIntra4Preds(tls, it)
  32797 			nz = nz | ReconstructIntra4(tls, it, rd+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, src, dst, mode)<<(*VP8EncIterator)(unsafe.Pointer(it)).Fi4
  32798 		}
  32799 	}
  32800 	nz = nz | ReconstructUV(tls, it, rd, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(U_OFF_ENC)), int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0xc>>2)))
  32801 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = libc.Uint32FromInt32(nz)
  32802 }
  32803 
  32804 // C documentation
  32805 //
  32806 //	// Refine intra16/intra4 sub-modes based on distortion only (not rate).
  32807 func RefineUsingDistortion(tls *libc.TLS, it uintptr, try_both_modes int32, refine_uv_mode int32, rd uintptr) {
  32808 	bp := tls.Alloc(16)
  32809 	defer tls.Free(16)
  32810 	var best_i4_mode, best_mode, best_mode1, i, is_i16, lambda_d_i16, lambda_d_i4, lambda_d_uv, mode, nz, v5, v7 int32
  32811 	var best_i4_score, best_score, best_uv_score, bit_limit, i4_bit_sum, score, score1, score2, score_i4 score_t
  32812 	var dqm, mode_costs, ref, ref1, ref2, src1, src2, src3, tmp_dst, v3 uintptr
  32813 	var v1 int64
  32814 	var _ /* v at bp+0 */ uint32_t
  32815 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_i4_mode, best_i4_score, best_mode, best_mode1, best_score, best_uv_score, bit_limit, dqm, i, i4_bit_sum, is_i16, lambda_d_i16, lambda_d_i4, lambda_d_uv, mode, mode_costs, nz, ref, ref1, ref2, score, score1, score2, score_i4, src1, src2, src3, tmp_dst, v1, v3, v5, v7
  32816 	best_score = libc.Int64FromInt64(0x7fffffffffffff)
  32817 	nz = 0
  32818 	is_i16 = libc.BoolInt32(try_both_modes != 0 || int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1))
  32819 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32820 	// Some empiric constants, of approximate order of magnitude.
  32821 	lambda_d_i16 = int32(106)
  32822 	lambda_d_i4 = int32(11)
  32823 	lambda_d_uv = int32(120)
  32824 	score_i4 = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fi4_penalty
  32825 	i4_bit_sum = 0
  32826 	if try_both_modes != 0 {
  32827 		v1 = int64((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_header_limit)
  32828 	} else {
  32829 		v1 = libc.Int64FromInt64(0x7fffffffffffff)
  32830 	}
  32831 	bit_limit = v1   // no early-out allowed
  32832 	if is_i16 != 0 { // First, evaluate Intra16 distortion
  32833 		best_mode = -int32(1)
  32834 		src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32835 		mode = 0
  32836 		for {
  32837 			if !(mode < int32(NUM_PRED_MODES)) {
  32838 				break
  32839 			}
  32840 			ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  32841 			score = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x16})))(tls, src1, ref))*int64(RD_DISTO_MULT) + int64(libc.Int32FromUint16(VP8FixedCostsI16[mode])*lambda_d_i16)
  32842 			if mode > 0 && libc.Int64FromUint16(VP8FixedCostsI16[mode]) > bit_limit {
  32843 				goto _2
  32844 			}
  32845 			if score < best_score {
  32846 				best_mode = mode
  32847 				best_score = score
  32848 			}
  32849 			goto _2
  32850 		_2:
  32851 			;
  32852 			mode = mode + 1
  32853 		}
  32854 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 || (*VP8EncIterator)(unsafe.Pointer(it)).Fy == 0 {
  32855 			// avoid starting a checkerboard resonance from the border. See bug #432.
  32856 			v3 = src1
  32857 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v3))) * uint32(0x01010101)
  32858 			i = libc.Int32FromInt32(0)
  32859 			for {
  32860 				if !(i < libc.Int32FromInt32(16)) {
  32861 					break
  32862 				}
  32863 				if libc.Xmemcmp(tls, v3+uintptr(0), bp, uint64(4)) != 0 || libc.Xmemcmp(tls, v3+uintptr(4), bp, uint64(4)) != 0 || libc.Xmemcmp(tls, v3+uintptr(8), bp, uint64(4)) != 0 || libc.Xmemcmp(tls, v3+uintptr(12), bp, uint64(4)) != 0 {
  32864 					v5 = 0
  32865 					goto _6
  32866 				}
  32867 				v3 = v3 + uintptr(BPS)
  32868 				goto _4
  32869 			_4:
  32870 				;
  32871 				i = i + 1
  32872 			}
  32873 			v5 = int32(1)
  32874 			goto _6
  32875 		_6:
  32876 			if v5 != 0 {
  32877 				if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 {
  32878 					v7 = 0
  32879 				} else {
  32880 					v7 = int32(2)
  32881 				}
  32882 				best_mode = v7
  32883 				try_both_modes = 0 // stick to i16
  32884 			}
  32885 		}
  32886 		VP8SetIntra16Mode(tls, it, best_mode)
  32887 		// we'll reconstruct later, if i16 mode actually gets selected
  32888 	}
  32889 	// Next, evaluate Intra4
  32890 	if try_both_modes != 0 || !(is_i16 != 0) {
  32891 		// We don't evaluate the rate here, but just account for it through a
  32892 		// constant penalty (i4 mode usually needs more bits compared to i16).
  32893 		is_i16 = 0
  32894 		VP8IteratorStartI4(tls, it)
  32895 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  32896 			best_i4_mode = -int32(1)
  32897 			best_i4_score = libc.Int64FromInt64(0x7fffffffffffff)
  32898 			src2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32899 			mode_costs = GetCostModeI4(tls, it, rd+844)
  32900 			MakeIntra4Preds(tls, it)
  32901 			mode = 0
  32902 			for {
  32903 				if !(mode < int32(NUM_BMODES)) {
  32904 					break
  32905 				}
  32906 				ref1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  32907 				score1 = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE4x4})))(tls, src2, ref1)*int32(RD_DISTO_MULT) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(mode)*2)))*lambda_d_i4)
  32908 				if score1 < best_i4_score {
  32909 					best_i4_mode = mode
  32910 					best_i4_score = score1
  32911 				}
  32912 				goto _8
  32913 			_8:
  32914 				;
  32915 				mode = mode + 1
  32916 			}
  32917 			i4_bit_sum = i4_bit_sum + libc.Int64FromUint16(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(best_i4_mode)*2)))
  32918 			**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = libc.Uint8FromInt32(best_i4_mode)
  32919 			score_i4 = score_i4 + best_i4_score
  32920 			if score_i4 >= best_score || i4_bit_sum > bit_limit {
  32921 				// Intra4 won't be better than Intra16. Bail out and pick Intra16.
  32922 				is_i16 = int32(1)
  32923 				break
  32924 			} else { // reconstruct partial block inside yuv_out2 buffer
  32925 				tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32926 				nz = nz | ReconstructIntra4(tls, it, rd+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, src2, tmp_dst, best_i4_mode)<<(*VP8EncIterator)(unsafe.Pointer(it)).Fi4
  32927 			}
  32928 		}
  32929 	}
  32930 	// Final reconstruction, depending on which mode is selected.
  32931 	if !(is_i16 != 0) {
  32932 		VP8SetIntra4Mode(tls, it, rd+844)
  32933 		SwapOut(tls, it)
  32934 		best_score = score_i4
  32935 	} else {
  32936 		nz = ReconstructIntra16(tls, it, rd, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds))))
  32937 	}
  32938 	// ... and UV!
  32939 	if refine_uv_mode != 0 {
  32940 		best_mode1 = -int32(1)
  32941 		best_uv_score = libc.Int64FromInt64(0x7fffffffffffff)
  32942 		src3 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32943 		mode = 0
  32944 		for {
  32945 			if !(mode < int32(NUM_PRED_MODES)) {
  32946 				break
  32947 			}
  32948 			ref2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  32949 			score2 = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x8})))(tls, src3, ref2)*int32(RD_DISTO_MULT) + libc.Int32FromUint16(VP8FixedCostsUV[mode])*lambda_d_uv)
  32950 			if score2 < best_uv_score {
  32951 				best_mode1 = mode
  32952 				best_uv_score = score2
  32953 			}
  32954 			goto _9
  32955 		_9:
  32956 			;
  32957 			mode = mode + 1
  32958 		}
  32959 		VP8SetIntraUVMode(tls, it, best_mode1)
  32960 	}
  32961 	nz = nz | ReconstructUV(tls, it, rd, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(U_OFF_ENC)), int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0xc>>2)))
  32962 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = libc.Uint32FromInt32(nz)
  32963 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = best_score
  32964 }
  32965 
  32966 //------------------------------------------------------------------------------
  32967 // Entry point
  32968 
  32969 func VP8Decimate(tls *libc.TLS, it uintptr, rd uintptr, rd_opt VP8RDLevel) (r int32) {
  32970 	var is_skipped, method int32
  32971 	_, _ = is_skipped, method
  32972 	method = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmethod
  32973 	InitScore(tls, rd)
  32974 	// We can perform predictions for Luma16x16 and Chroma8x8 already.
  32975 	// Luma4x4 predictions needs to be done as-we-go.
  32976 	VP8MakeLuma16Preds(tls, it)
  32977 	VP8MakeChroma8Preds(tls, it)
  32978 	if rd_opt > int32(RD_OPT_NONE) {
  32979 		(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = libc.BoolInt32(rd_opt >= int32(RD_OPT_TRELLIS_ALL))
  32980 		PickBestIntra16(tls, it, rd)
  32981 		if method >= int32(2) {
  32982 			PickBestIntra4(tls, it, rd)
  32983 		}
  32984 		PickBestUV(tls, it, rd)
  32985 		if rd_opt == int32(RD_OPT_TRELLIS) { // finish off with trellis-optim now
  32986 			(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = int32(1)
  32987 			SimpleQuantize(tls, it, rd)
  32988 		}
  32989 	} else {
  32990 		// At this point we have heuristically decided intra16 / intra4.
  32991 		// For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower).
  32992 		// For method <= 1, we don't re-examine the decision but just go ahead with
  32993 		// quantization/reconstruction.
  32994 		RefineUsingDistortion(tls, it, libc.BoolInt32(method >= int32(2)), libc.BoolInt32(method >= int32(1)), rd)
  32995 	}
  32996 	is_skipped = libc.BoolInt32((*VP8ModeScore)(unsafe.Pointer(rd)).Fnz == uint32(0))
  32997 	VP8SetSkip(tls, it, is_skipped)
  32998 	return is_skipped
  32999 }
  33000 
  33001 const ARGB_BLACK2 = 0xff000000
  33002 const VP8_SIGNATURE1 = 10289450
  33003 
  33004 //------------------------------------------------------------------------------
  33005 // Helper functions
  33006 
  33007 func IsVP8XNeeded(tls *libc.TLS, enc uintptr) (r int32) {
  33008 	return libc.BoolInt32(!!((*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0)) // Currently the only case when VP8X is needed.
  33009 	// This could change in the future.
  33010 }
  33011 
  33012 func PutPaddingByte(tls *libc.TLS, pic uintptr) (r int32) {
  33013 	bp := tls.Alloc(16)
  33014 	defer tls.Free(16)
  33015 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  33016 	**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  33017 	return libc.BoolInt32(!!((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(1), pic) != 0))
  33018 }
  33019 
  33020 //------------------------------------------------------------------------------
  33021 // Writers for header's various pieces (in order of appearance)
  33022 
  33023 func PutRIFFHeader(tls *libc.TLS, enc uintptr, riff_size size_t) (r WebPEncodingError1) {
  33024 	bp := tls.Alloc(16)
  33025 	defer tls.Free(16)
  33026 	var pic, v1, v3, v5 uintptr
  33027 	var v2 uint32_t
  33028 	var v4, v6 int32
  33029 	var _ /* riff at bp+0 */ [12]uint8_t
  33030 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33031 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33032 	**(**[12]uint8_t)(__ccgo_up(bp)) = [12]uint8_t{
  33033 		0:  uint8('R'),
  33034 		1:  uint8('I'),
  33035 		2:  uint8('F'),
  33036 		3:  uint8('F'),
  33037 		8:  uint8('W'),
  33038 		9:  uint8('E'),
  33039 		10: uint8('B'),
  33040 		11: uint8('P'),
  33041 	}
  33042 	v1 = bp + uintptr(TAG_SIZE)
  33043 	v2 = uint32(riff_size)
  33044 	v3 = v1
  33045 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33046 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33047 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33048 	v5 = v1 + uintptr(2)
  33049 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33050 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33051 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33052 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(12), pic) != 0) {
  33053 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33054 	}
  33055 	return int32(VP8_ENC_OK)
  33056 }
  33057 
  33058 func PutVP8XHeader(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33059 	bp := tls.Alloc(32)
  33060 	defer tls.Free(32)
  33061 	var flags, v2 uint32_t
  33062 	var pic, v1, v3, v5 uintptr
  33063 	var v4, v6 int32
  33064 	var _ /* vp8x at bp+0 */ [18]uint8_t
  33065 	_, _, _, _, _, _, _, _ = flags, pic, v1, v2, v3, v4, v5, v6
  33066 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33067 	**(**[18]uint8_t)(__ccgo_up(bp)) = [18]uint8_t{
  33068 		0: uint8('V'),
  33069 		1: uint8('P'),
  33070 		2: uint8('8'),
  33071 		3: uint8('X'),
  33072 	}
  33073 	flags = uint32(0)
  33074 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33075 		flags = flags | uint32(ALPHA_FLAG)
  33076 	}
  33077 	v1 = bp + uintptr(TAG_SIZE)
  33078 	v2 = uint32(VP8X_CHUNK_SIZE)
  33079 	v3 = v1
  33080 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33081 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33082 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33083 	v5 = v1 + uintptr(2)
  33084 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33085 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33086 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33087 	v1 = bp + uintptr(CHUNK_HEADER_SIZE)
  33088 	v2 = flags
  33089 	v3 = v1
  33090 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33091 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33092 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33093 	v5 = v1 + uintptr(2)
  33094 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33095 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33096 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33097 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(4)
  33098 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  33099 	v3 = v1
  33100 	v6 = v4 & int32(0xffff)
  33101 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33102 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33103 	**(**uint8_t)(__ccgo_up(v1 + 2)) = libc.Uint8FromInt32(v4 >> int32(16) & int32(0xff))
  33104 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(7)
  33105 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  33106 	v3 = v1
  33107 	v6 = v4 & int32(0xffff)
  33108 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33109 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33110 	**(**uint8_t)(__ccgo_up(v1 + 2)) = libc.Uint8FromInt32(v4 >> int32(16) & int32(0xff))
  33111 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(18), pic) != 0) {
  33112 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33113 	}
  33114 	return int32(VP8_ENC_OK)
  33115 }
  33116 
  33117 func PutAlphaChunk(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33118 	bp := tls.Alloc(16)
  33119 	defer tls.Free(16)
  33120 	var pic, v1, v3, v5 uintptr
  33121 	var v2 uint32_t
  33122 	var v4, v6 int32
  33123 	var _ /* alpha_chunk_hdr at bp+0 */ [8]uint8_t
  33124 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33125 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33126 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33127 		0: uint8('A'),
  33128 		1: uint8('L'),
  33129 		2: uint8('P'),
  33130 		3: uint8('H'),
  33131 	}
  33132 	// Alpha chunk header.
  33133 	v1 = bp + uintptr(TAG_SIZE)
  33134 	v2 = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size
  33135 	v3 = v1
  33136 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33137 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33138 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33139 	v5 = v1 + uintptr(2)
  33140 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33141 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33142 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33143 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33144 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33145 	}
  33146 	// Alpha chunk data.
  33147 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data, uint64((*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size), pic) != 0) {
  33148 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33149 	}
  33150 	// Padding.
  33151 	if (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1) != 0 && !(PutPaddingByte(tls, pic) != 0) {
  33152 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33153 	}
  33154 	return int32(VP8_ENC_OK)
  33155 }
  33156 
  33157 func PutVP8Header(tls *libc.TLS, pic uintptr, vp8_size size_t) (r WebPEncodingError1) {
  33158 	bp := tls.Alloc(16)
  33159 	defer tls.Free(16)
  33160 	var v1, v3, v5 uintptr
  33161 	var v2 uint32_t
  33162 	var v4, v6 int32
  33163 	var _ /* vp8_chunk_hdr at bp+0 */ [8]uint8_t
  33164 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  33165 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33166 		0: uint8('V'),
  33167 		1: uint8('P'),
  33168 		2: uint8('8'),
  33169 		3: uint8(' '),
  33170 	}
  33171 	v1 = bp + uintptr(TAG_SIZE)
  33172 	v2 = uint32(vp8_size)
  33173 	v3 = v1
  33174 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33175 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33176 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33177 	v5 = v1 + uintptr(2)
  33178 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33179 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33180 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33181 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33182 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33183 	}
  33184 	return int32(VP8_ENC_OK)
  33185 }
  33186 
  33187 func PutVP8FrameHeader(tls *libc.TLS, pic uintptr, profile int32, size0 size_t) (r WebPEncodingError1) {
  33188 	bp := tls.Alloc(16)
  33189 	defer tls.Free(16)
  33190 	var bits uint32_t
  33191 	var _ /* vp8_frm_hdr at bp+0 */ [10]uint8_t
  33192 	_ = bits
  33193 	if size0 >= libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) { // partition #0 is too big to fit
  33194 		return int32(VP8_ENC_ERROR_PARTITION0_OVERFLOW)
  33195 	}
  33196 	// Paragraph 9.1.
  33197 	bits = libc.Uint32FromInt32(0|profile<<int32(1)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(4)) | uint32(size0)<<libc.Int32FromInt32(5) // partition length (19b)
  33198 	(**(**[10]uint8_t)(__ccgo_up(bp)))[0] = uint8(bits >> libc.Int32FromInt32(0) & uint32(0xff))
  33199 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(1)] = uint8(bits >> libc.Int32FromInt32(8) & uint32(0xff))
  33200 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(2)] = uint8(bits >> libc.Int32FromInt32(16) & uint32(0xff))
  33201 	// signature
  33202 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(3)] = libc.Uint8FromInt32(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(16) & libc.Int32FromInt32(0xff))
  33203 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(4)] = libc.Uint8FromInt32(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff))
  33204 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(5)] = libc.Uint8FromInt32(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(0) & libc.Int32FromInt32(0xff))
  33205 	// dimensions
  33206 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(6)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fwidth & int32(0xff))
  33207 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(7)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fwidth >> int32(8))
  33208 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(8)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fheight & int32(0xff))
  33209 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(9)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fheight >> int32(8))
  33210 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(10), pic) != 0) {
  33211 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33212 	}
  33213 	return int32(VP8_ENC_OK)
  33214 }
  33215 
  33216 // C documentation
  33217 //
  33218 //	// WebP Headers.
  33219 func PutWebPHeaders(tls *libc.TLS, enc uintptr, size0 size_t, vp8_size size_t, riff_size size_t) (r int32) {
  33220 	var err WebPEncodingError1
  33221 	var pic uintptr
  33222 	_, _ = err, pic
  33223 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33224 	err = int32(VP8_ENC_OK)
  33225 	// RIFF header.
  33226 	err = PutRIFFHeader(tls, enc, riff_size)
  33227 	if err != int32(VP8_ENC_OK) {
  33228 		goto Error
  33229 	}
  33230 	// VP8X.
  33231 	if IsVP8XNeeded(tls, enc) != 0 {
  33232 		err = PutVP8XHeader(tls, enc)
  33233 		if err != int32(VP8_ENC_OK) {
  33234 			goto Error
  33235 		}
  33236 	}
  33237 	// Alpha.
  33238 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33239 		err = PutAlphaChunk(tls, enc)
  33240 		if err != int32(VP8_ENC_OK) {
  33241 			goto Error
  33242 		}
  33243 	}
  33244 	// VP8 header.
  33245 	err = PutVP8Header(tls, pic, vp8_size)
  33246 	if err != int32(VP8_ENC_OK) {
  33247 		goto Error
  33248 	}
  33249 	// VP8 frame header.
  33250 	err = PutVP8FrameHeader(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fprofile, size0)
  33251 	if err != int32(VP8_ENC_OK) {
  33252 		goto Error
  33253 	}
  33254 	// All OK.
  33255 	return int32(1)
  33256 	// Error.
  33257 	goto Error
  33258 Error:
  33259 	;
  33260 	return WebPEncodingSetError(tls, pic, err)
  33261 	return r
  33262 }
  33263 
  33264 // C documentation
  33265 //
  33266 //	// Segmentation header
  33267 func PutSegmentHeader(tls *libc.TLS, bw uintptr, enc uintptr) {
  33268 	var hdr, proba uintptr
  33269 	var s, update_data int32
  33270 	_, _, _, _ = hdr, proba, s, update_data
  33271 	hdr = enc + 32
  33272 	proba = enc + 3616
  33273 	if VP8PutBitUniform(tls, bw, libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))) != 0 {
  33274 		// We always 'update' the quant and filter strength values
  33275 		update_data = int32(1)
  33276 		VP8PutBitUniform(tls, bw, (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map)
  33277 		if VP8PutBitUniform(tls, bw, update_data) != 0 {
  33278 			// we always use absolute values, not relative ones
  33279 			VP8PutBitUniform(tls, bw, int32(1)) // (segment_feature_mode = 1. Paragraph 9.3.)
  33280 			s = 0
  33281 			for {
  33282 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33283 					break
  33284 				}
  33285 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant, int32(7))
  33286 				goto _1
  33287 			_1:
  33288 				;
  33289 				s = s + 1
  33290 			}
  33291 			s = 0
  33292 			for {
  33293 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33294 					break
  33295 				}
  33296 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength, int32(6))
  33297 				goto _2
  33298 			_2:
  33299 				;
  33300 				s = s + 1
  33301 			}
  33302 		}
  33303 		if (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  33304 			s = 0
  33305 			for {
  33306 				if !(s < int32(3)) {
  33307 					break
  33308 				}
  33309 				if VP8PutBitUniform(tls, bw, libc.BoolInt32(uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))) != uint32(255))) != 0 {
  33310 					VP8PutBits(tls, bw, uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))), int32(8))
  33311 				}
  33312 				goto _3
  33313 			_3:
  33314 				;
  33315 				s = s + 1
  33316 			}
  33317 		}
  33318 	}
  33319 }
  33320 
  33321 // C documentation
  33322 //
  33323 //	// Filtering parameters header
  33324 func PutFilterHeader(tls *libc.TLS, bw uintptr, hdr uintptr) {
  33325 	var need_update, use_lf_delta int32
  33326 	_, _ = need_update, use_lf_delta
  33327 	use_lf_delta = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33328 	VP8PutBitUniform(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple)
  33329 	VP8PutBits(tls, bw, libc.Uint32FromInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel), int32(6))
  33330 	VP8PutBits(tls, bw, libc.Uint32FromInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness), int32(3))
  33331 	if VP8PutBitUniform(tls, bw, use_lf_delta) != 0 {
  33332 		// '0' is the default value for i4x4_lf_delta at frame #0.
  33333 		need_update = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33334 		if VP8PutBitUniform(tls, bw, need_update) != 0 {
  33335 			// we don't use ref_lf_delta => emit four 0 bits
  33336 			VP8PutBits(tls, bw, uint32(0), int32(4))
  33337 			// we use mode_lf_delta for i4x4
  33338 			VP8PutSignedBits(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta, int32(6))
  33339 			VP8PutBits(tls, bw, uint32(0), int32(3)) // all others unused
  33340 		}
  33341 	}
  33342 }
  33343 
  33344 // C documentation
  33345 //
  33346 //	// Nominal quantization parameters
  33347 func PutQuant(tls *libc.TLS, bw uintptr, enc uintptr) {
  33348 	VP8PutBits(tls, bw, libc.Uint32FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant), int32(7))
  33349 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, int32(4))
  33350 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, int32(4))
  33351 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, int32(4))
  33352 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, int32(4))
  33353 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, int32(4))
  33354 }
  33355 
  33356 // C documentation
  33357 //
  33358 //	// Partition sizes
  33359 func EmitPartitionsSize(tls *libc.TLS, enc uintptr, pic uintptr) (r int32) {
  33360 	bp := tls.Alloc(32)
  33361 	defer tls.Free(32)
  33362 	var p int32
  33363 	var part_size, v2 size_t
  33364 	var _ /* buf at bp+0 */ [21]uint8_t
  33365 	_, _, _ = p, part_size, v2
  33366 	p = 0
  33367 	for {
  33368 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)) {
  33369 			break
  33370 		}
  33371 		v2 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33372 		goto _3
  33373 	_3:
  33374 		part_size = v2
  33375 		if part_size >= libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) {
  33376 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_PARTITION_OVERFLOW))
  33377 		}
  33378 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+0] = uint8(part_size >> libc.Int32FromInt32(0) & uint64(0xff))
  33379 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(1)] = uint8(part_size >> libc.Int32FromInt32(8) & uint64(0xff))
  33380 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(2)] = uint8(part_size >> libc.Int32FromInt32(16) & uint64(0xff))
  33381 		goto _1
  33382 	_1:
  33383 		;
  33384 		p = p + 1
  33385 	}
  33386 	if p != 0 && !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, libc.Uint64FromInt32(int32(3)*p), pic) != 0) {
  33387 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33388 	}
  33389 	return int32(1)
  33390 }
  33391 
  33392 //------------------------------------------------------------------------------
  33393 
  33394 func GeneratePartition0(tls *libc.TLS, enc uintptr) (r int32) {
  33395 	var bw1, v1 uintptr
  33396 	var mb_size, v4, v5, v6 int32
  33397 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  33398 	_, _, _, _, _, _, _, _, _, _, _ = bw1, mb_size, nb_bits, pos1, pos2, pos3, v1, v2, v4, v5, v6
  33399 	bw1 = enc + 64
  33400 	mb_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  33401 	v1 = bw1
  33402 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33403 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33404 	goto _3
  33405 _3:
  33406 	pos1 = v2
  33407 	if !(VP8BitWriterInit(tls, bw1, libc.Uint64FromInt32(mb_size*int32(7)/int32(8))) != 0) { // ~7 bits per macroblock
  33408 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33409 	}
  33410 	VP8PutBitUniform(tls, bw1, 0) // colorspace
  33411 	VP8PutBitUniform(tls, bw1, 0) // clamp type
  33412 	PutSegmentHeader(tls, bw1, enc)
  33413 	PutFilterHeader(tls, bw1, enc+16)
  33414 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(8) {
  33415 		v4 = int32(3)
  33416 	} else {
  33417 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(4) {
  33418 			v5 = int32(2)
  33419 		} else {
  33420 			if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(2) {
  33421 				v6 = int32(1)
  33422 			} else {
  33423 				v6 = 0
  33424 			}
  33425 			v5 = v6
  33426 		}
  33427 		v4 = v5
  33428 	}
  33429 	VP8PutBits(tls, bw1, libc.Uint32FromInt32(v4), int32(2))
  33430 	PutQuant(tls, bw1, enc)
  33431 	VP8PutBitUniform(tls, bw1, 0) // no proba update
  33432 	VP8WriteProbas(tls, bw1, enc+3616)
  33433 	v1 = bw1
  33434 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33435 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33436 	goto _9
  33437 _9:
  33438 	pos2 = v2
  33439 	VP8CodeIntraModes(tls, enc)
  33440 	VP8BitWriterFinish(tls, bw1)
  33441 	v1 = bw1
  33442 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33443 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33444 	goto _12
  33445 _12:
  33446 	pos3 = v2
  33447 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != 0 {
  33448 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36)) = libc.Int32FromUint64((pos2 - pos1 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33449 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36 + 1*4)) = libc.Int32FromUint64((pos3 - pos2 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33450 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats)).Falpha_data_size = libc.Int32FromUint32((*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size)
  33451 	}
  33452 	if (*VP8BitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  33453 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33454 	}
  33455 	return int32(1)
  33456 }
  33457 
  33458 func VP8EncFreeBitWriters(tls *libc.TLS, enc uintptr) {
  33459 	var p int32
  33460 	_ = p
  33461 	VP8BitWriterWipeOut(tls, enc+64)
  33462 	p = 0
  33463 	for {
  33464 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33465 			break
  33466 		}
  33467 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48)
  33468 		goto _1
  33469 	_1:
  33470 		;
  33471 		p = p + 1
  33472 	}
  33473 }
  33474 
  33475 func VP8EncWrite(tls *libc.TLS, enc uintptr) (r int32) {
  33476 	var buf, bw2, part0, pic, v6 uintptr
  33477 	var final_percent, ok, p, percent_per_part, task_percent int32
  33478 	var pad, riff_size, size, size0, vp8_size, v1 size_t
  33479 	var padded_alpha_size uint32_t
  33480 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = buf, bw2, final_percent, ok, p, pad, padded_alpha_size, part0, percent_per_part, pic, riff_size, size, size0, task_percent, vp8_size, v1, v6
  33481 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33482 	bw2 = enc + 64
  33483 	task_percent = int32(19)
  33484 	percent_per_part = task_percent / (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts
  33485 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  33486 	ok = 0
  33487 	// Partition #0 with header and partition sizes
  33488 	ok = GeneratePartition0(tls, enc)
  33489 	if !(ok != 0) {
  33490 		return 0
  33491 	}
  33492 	// Compute VP8 size
  33493 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33494 	goto _2
  33495 _2:
  33496 	vp8_size = uint64(VP8_FRAME_HEADER_SIZE) + v1 + libc.Uint64FromInt32(int32(3)*((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))
  33497 	p = 0
  33498 	for {
  33499 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33500 			break
  33501 		}
  33502 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33503 		goto _5
  33504 	_5:
  33505 		vp8_size = vp8_size + v1
  33506 		goto _3
  33507 	_3:
  33508 		;
  33509 		p = p + 1
  33510 	}
  33511 	pad = vp8_size & uint64(1)
  33512 	vp8_size = vp8_size + pad
  33513 	// Compute RIFF size
  33514 	// At the minimum it is: "WEBPVP8 nnnn" + VP8 data size.
  33515 	riff_size = libc.Uint64FromInt32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8_size
  33516 	if IsVP8XNeeded(tls, enc) != 0 { // Add size for: VP8X header + data.
  33517 		riff_size = riff_size + libc.Uint64FromInt32(libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  33518 	}
  33519 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 { // Add size for: ALPH header + data.
  33520 		padded_alpha_size = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size + (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1)
  33521 		riff_size = riff_size + uint64(uint32(CHUNK_HEADER_SIZE)+padded_alpha_size)
  33522 	}
  33523 	// RIFF size should fit in 32-bits.
  33524 	if riff_size > uint64(0xfffffffe) {
  33525 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_FILE_TOO_BIG))
  33526 	}
  33527 	// Emit headers and partition #0
  33528 	v6 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fbuf
  33529 	goto _7
  33530 _7:
  33531 	part0 = v6
  33532 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33533 	goto _9
  33534 _9:
  33535 	size0 = v1
  33536 	ok = libc.BoolInt32(ok != 0 && PutWebPHeaders(tls, enc, size0, vp8_size, riff_size) != 0 && (*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, part0, size0, pic) != 0 && EmitPartitionsSize(tls, enc, pic) != 0)
  33537 	VP8BitWriterWipeOut(tls, bw2) // will free the internal buffer.
  33538 	// Token partitions
  33539 	p = 0
  33540 	for {
  33541 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33542 			break
  33543 		}
  33544 		v6 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fbuf
  33545 		goto _12
  33546 	_12:
  33547 		buf = v6
  33548 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33549 		goto _14
  33550 	_14:
  33551 		size = v1
  33552 		if size != 0 {
  33553 			ok = libc.BoolInt32(ok != 0 && (*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, buf, size, pic) != 0)
  33554 		}
  33555 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48) // will free the internal buffer.
  33556 		ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+percent_per_part, enc+536) != 0)
  33557 		goto _10
  33558 	_10:
  33559 		;
  33560 		p = p + 1
  33561 	}
  33562 	// Padding byte
  33563 	if ok != 0 && pad != 0 {
  33564 		ok = PutPaddingByte(tls, pic)
  33565 	}
  33566 	(*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size = libc.Int32FromUint64(libc.Uint64FromInt32(CHUNK_HEADER_SIZE) + riff_size)
  33567 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, final_percent, enc+536) != 0)
  33568 	if !(ok != 0) {
  33569 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33570 	}
  33571 	return ok
  33572 }
  33573 
  33574 const MIN_PAGE_SIZE = 8192
  33575 
  33576 type VP8Tokens = struct {
  33577 	Fnext uintptr
  33578 }
  33579 
  33580 //------------------------------------------------------------------------------
  33581 
  33582 // Copyright 2011 Google Inc. All Rights Reserved.
  33583 //
  33584 // Use of this source code is governed by a BSD-style license
  33585 // that can be found in the COPYING file in the root of the source
  33586 // tree. An additional intellectual property rights grant can be found
  33587 // in the file PATENTS. All contributing project authors may
  33588 // be found in the AUTHORS file in the root of the source tree.
  33589 // -----------------------------------------------------------------------------
  33590 //
  33591 //   WebP encoder: internal header.
  33592 //
  33593 // Author: Skal (pascal.massimino@gmail.com)
  33594 
  33595 // Copyright 2011 Google Inc. All Rights Reserved.
  33596 //
  33597 // Use of this source code is governed by a BSD-style license
  33598 // that can be found in the COPYING file in the root of the source
  33599 // tree. An additional intellectual property rights grant can be found
  33600 // in the file PATENTS. All contributing project authors may
  33601 // be found in the AUTHORS file in the root of the source tree.
  33602 // -----------------------------------------------------------------------------
  33603 //
  33604 // Bit writing and boolean coder
  33605 //
  33606 // Author: Skal (pascal.massimino@gmail.com)
  33607 
  33608 // Copyright 2012 Google Inc. All Rights Reserved.
  33609 //
  33610 // Use of this source code is governed by a BSD-style license
  33611 // that can be found in the COPYING file in the root of the source
  33612 // tree. An additional intellectual property rights grant can be found
  33613 // in the file PATENTS. All contributing project authors may
  33614 // be found in the AUTHORS file in the root of the source tree.
  33615 // -----------------------------------------------------------------------------
  33616 //
  33617 // Misc. common utility functions
  33618 //
  33619 // Authors: Skal (pascal.massimino@gmail.com)
  33620 //          Urvang (urvang@google.com)
  33621 
  33622 // Copyright 2010 Google Inc. All Rights Reserved.
  33623 //
  33624 // Use of this source code is governed by a BSD-style license
  33625 // that can be found in the COPYING file in the root of the source
  33626 // tree. An additional intellectual property rights grant can be found
  33627 // in the file PATENTS. All contributing project authors may
  33628 // be found in the AUTHORS file in the root of the source tree.
  33629 // -----------------------------------------------------------------------------
  33630 //
  33631 //  Common types + memory wrappers
  33632 //
  33633 // Author: Skal (pascal.massimino@gmail.com)
  33634 
  33635 // we use pages to reduce the number of memcpy()
  33636 
  33637 type token_t = uint16
  33638 
  33639 // Token data is located in memory just after the 'next' field.
  33640 // This macro is used to return their address and hide the trick.
  33641 
  33642 //------------------------------------------------------------------------------
  33643 
  33644 func VP8TBufferInit(tls *libc.TLS, b uintptr, page_size int32) {
  33645 	var v1 int32
  33646 	_ = v1
  33647 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = libc.UintptrFromInt32(0)
  33648 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  33649 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = b
  33650 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = 0
  33651 	if page_size < int32(MIN_PAGE_SIZE) {
  33652 		v1 = int32(MIN_PAGE_SIZE)
  33653 	} else {
  33654 		v1 = page_size
  33655 	}
  33656 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size = v1
  33657 	(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = 0
  33658 }
  33659 
  33660 func VP8TBufferClear(tls *libc.TLS, b uintptr) {
  33661 	var next, p uintptr
  33662 	_, _ = next, p
  33663 	if b != libc.UintptrFromInt32(0) {
  33664 		p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  33665 		for p != libc.UintptrFromInt32(0) {
  33666 			next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  33667 			WebPSafeFree(tls, p)
  33668 			p = next
  33669 		}
  33670 		VP8TBufferInit(tls, b, (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)
  33671 	}
  33672 }
  33673 
  33674 func TBufferNewPage(tls *libc.TLS, b uintptr) (r int32) {
  33675 	var page uintptr
  33676 	var size size_t
  33677 	_, _ = page, size
  33678 	page = libc.UintptrFromInt32(0)
  33679 	if !((*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 != 0) {
  33680 		size = uint64(8) + libc.Uint64FromInt32((*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)*uint64(2)
  33681 		page = WebPSafeMalloc(tls, uint64(1), size)
  33682 	}
  33683 	if page == libc.UintptrFromInt32(0) {
  33684 		(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = int32(1)
  33685 		return 0
  33686 	}
  33687 	(*VP8Tokens)(unsafe.Pointer(page)).Fnext = libc.UintptrFromInt32(0)
  33688 	**(**uintptr)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Flast_page)) = page
  33689 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = page
  33690 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  33691 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = page + 1*8
  33692 	return int32(1)
  33693 }
  33694 
  33695 //------------------------------------------------------------------------------
  33696 
  33697 func AddToken(tls *libc.TLS, b uintptr, bit1 uint32_t, proba_idx uint32_t, stats1 uintptr) (r uint32_t) {
  33698 	var p proba_t
  33699 	var slot, v1 int32
  33700 	var v2 uintptr
  33701 	_, _, _, _ = p, slot, v1, v2
  33702 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  33703 		v2 = b + 24
  33704 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  33705 		v1 = *(*int32)(unsafe.Pointer(v2))
  33706 		slot = v1
  33707 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit1<<libc.Int32FromInt32(15) | proba_idx)
  33708 	}
  33709 	v1 = libc.Int32FromUint32(bit1)
  33710 	v2 = stats1
  33711 	p = **(**proba_t)(__ccgo_up(v2))
  33712 	if p >= libc.Uint32FromUint32(0xfffe0000) {
  33713 		p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  33714 	}
  33715 	p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  33716 	**(**proba_t)(__ccgo_up(v2)) = p
  33717 	_ = v1
  33718 	goto _5
  33719 _5:
  33720 	;
  33721 	return bit1
  33722 }
  33723 
  33724 func AddConstantToken(tls *libc.TLS, b uintptr, bit uint32_t, proba uint32_t) {
  33725 	var slot, v1 int32
  33726 	var v2 uintptr
  33727 	_, _, _ = slot, v1, v2
  33728 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  33729 		v2 = b + 24
  33730 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  33731 		v1 = *(*int32)(unsafe.Pointer(v2))
  33732 		slot = v1
  33733 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit<<libc.Int32FromInt32(15) | libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14) | proba)
  33734 	}
  33735 }
  33736 
  33737 func VP8RecordCoeffTokens(tls *libc.TLS, ctx int32, res uintptr, tokens uintptr) (r int32) {
  33738 	var base_id, residue, v uint32_t
  33739 	var c, coeff_type, last, mask, n, sign, v1, v2 int32
  33740 	var coeffs, s, tab, v3 uintptr
  33741 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_id, c, coeff_type, coeffs, last, mask, n, residue, s, sign, tab, v, v1, v2, v3
  33742 	coeffs = (*VP8Residual)(unsafe.Pointer(res)).Fcoeffs
  33743 	coeff_type = (*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type
  33744 	last = (*VP8Residual)(unsafe.Pointer(res)).Flast
  33745 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  33746 	base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (ctx + int32(NUM_CTX)*(n+int32(NUM_BANDS)*coeff_type)))
  33747 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  33748 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  33749 	if !(AddToken(tls, tokens, libc.BoolUint32(last >= 0), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  33750 		return 0
  33751 	}
  33752 	for n < int32(16) {
  33753 		v1 = n
  33754 		n = n + 1
  33755 		c = int32(**(**int16_t)(__ccgo_up(coeffs + uintptr(v1)*2)))
  33756 		sign = libc.BoolInt32(c < 0)
  33757 		if sign != 0 {
  33758 			v2 = -c
  33759 		} else {
  33760 			v2 = c
  33761 		}
  33762 		v = libc.Uint32FromInt32(v2)
  33763 		if !(AddToken(tls, tokens, libc.BoolUint32(v != uint32(0)), base_id+uint32(1), s+uintptr(1)*4) != 0) {
  33764 			base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (libc.Int32FromInt32(0) + int32(NUM_CTX)*(libc.Int32FromUint8(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=0
  33765 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  33766 			continue
  33767 		}
  33768 		if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(1)), base_id+uint32(2), s+uintptr(2)*4) != 0) {
  33769 			base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (libc.Int32FromInt32(1) + int32(NUM_CTX)*(libc.Int32FromUint8(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=1
  33770 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  33771 		} else {
  33772 			if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(4)), base_id+uint32(3), s+uintptr(3)*4) != 0) {
  33773 				if AddToken(tls, tokens, libc.BoolUint32(v != uint32(2)), base_id+uint32(4), s+uintptr(4)*4) != 0 {
  33774 					AddToken(tls, tokens, libc.BoolUint32(v == uint32(4)), base_id+uint32(5), s+uintptr(5)*4)
  33775 				}
  33776 			} else {
  33777 				if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(10)), base_id+uint32(6), s+uintptr(6)*4) != 0) {
  33778 					if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(6)), base_id+uint32(7), s+uintptr(7)*4) != 0) {
  33779 						AddConstantToken(tls, tokens, libc.BoolUint32(v == uint32(6)), uint32(159))
  33780 					} else {
  33781 						AddConstantToken(tls, tokens, libc.BoolUint32(v >= uint32(9)), uint32(165))
  33782 						AddConstantToken(tls, tokens, libc.BoolUint32(!(v&libc.Uint32FromInt32(1) != 0)), uint32(145))
  33783 					}
  33784 				} else {
  33785 					residue = v - uint32(3)
  33786 					if residue < libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1)) { // VP8Cat3  (3b)
  33787 						AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  33788 						AddToken(tls, tokens, uint32(0), base_id+uint32(9), s+uintptr(9)*4)
  33789 						residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  33790 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  33791 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  33792 					} else {
  33793 						if residue < libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2)) { // VP8Cat4  (4b)
  33794 							AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  33795 							AddToken(tls, tokens, uint32(1), base_id+uint32(9), s+uintptr(9)*4)
  33796 							residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  33797 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  33798 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  33799 						} else {
  33800 							if residue < libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3)) { // VP8Cat5  (5b)
  33801 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  33802 								AddToken(tls, tokens, uint32(0), base_id+uint32(10), s+uintptr(9)*4)
  33803 								residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  33804 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  33805 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  33806 							} else { // VP8Cat6 (11b)
  33807 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  33808 								AddToken(tls, tokens, uint32(1), base_id+uint32(10), s+uintptr(9)*4)
  33809 								residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  33810 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  33811 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  33812 							}
  33813 						}
  33814 					}
  33815 					for mask != 0 {
  33816 						v3 = tab
  33817 						tab = tab + 1
  33818 						AddConstantToken(tls, tokens, libc.BoolUint32(!!(residue&libc.Uint32FromInt32(mask) != 0)), uint32(**(**uint8_t)(__ccgo_up(v3))))
  33819 						mask = mask >> int32(1)
  33820 					}
  33821 				}
  33822 			}
  33823 			base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (libc.Int32FromInt32(2) + int32(NUM_CTX)*(libc.Int32FromUint8(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=2
  33824 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  33825 		}
  33826 		AddConstantToken(tls, tokens, libc.Uint32FromInt32(sign), uint32(128))
  33827 		if n == int32(16) || !(AddToken(tls, tokens, libc.BoolUint32(n <= last), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  33828 			return int32(1) // EOB
  33829 		}
  33830 	}
  33831 	return int32(1)
  33832 }
  33833 
  33834 //------------------------------------------------------------------------------
  33835 // Final coding pass, with known probabilities
  33836 
  33837 func VP8EmitTokens(tls *libc.TLS, b uintptr, bw uintptr, probas uintptr, final_pass int32) (r int32) {
  33838 	var N, bit, n, v1, v2 int32
  33839 	var next, p, tokens uintptr
  33840 	var token token_t
  33841 	_, _, _, _, _, _, _, _, _ = N, bit, n, next, p, token, tokens, v1, v2
  33842 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  33843 	for p != libc.UintptrFromInt32(0) {
  33844 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  33845 		if next == libc.UintptrFromInt32(0) {
  33846 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  33847 		} else {
  33848 			v1 = 0
  33849 		}
  33850 		N = v1
  33851 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  33852 		tokens = p + 1*8
  33853 		for {
  33854 			v2 = n
  33855 			n = n - 1
  33856 			if !(v2 > N) {
  33857 				break
  33858 			}
  33859 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  33860 			bit = libc.Int32FromUint16(token) >> int32(15) & int32(1)
  33861 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  33862 				VP8PutBit(tls, bw, bit, libc.Int32FromUint32(uint32(token)&uint32(0xff))) // constant proba
  33863 			} else {
  33864 				VP8PutBit(tls, bw, bit, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))))
  33865 			}
  33866 		}
  33867 		if final_pass != 0 {
  33868 			WebPSafeFree(tls, p)
  33869 		}
  33870 		p = next
  33871 	}
  33872 	if final_pass != 0 {
  33873 		(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  33874 	}
  33875 	return int32(1)
  33876 }
  33877 
  33878 // C documentation
  33879 //
  33880 //	// Size estimation
  33881 func VP8EstimateTokenSize(tls *libc.TLS, b uintptr, probas uintptr) (r size_t) {
  33882 	var N, bit1, n, v1, v2, v4, v6 int32
  33883 	var next, p, tokens uintptr
  33884 	var size size_t
  33885 	var token token_t
  33886 	var v3 uint8_t
  33887 	_, _, _, _, _, _, _, _, _, _, _, _, _ = N, bit1, n, next, p, size, token, tokens, v1, v2, v3, v4, v6
  33888 	size = uint64(0)
  33889 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  33890 	for p != libc.UintptrFromInt32(0) {
  33891 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  33892 		if next == libc.UintptrFromInt32(0) {
  33893 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  33894 		} else {
  33895 			v1 = 0
  33896 		}
  33897 		N = v1
  33898 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  33899 		tokens = p + 1*8
  33900 		for {
  33901 			v2 = n
  33902 			n = n - 1
  33903 			if !(v2 > N) {
  33904 				break
  33905 			}
  33906 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  33907 			bit1 = libc.Int32FromUint16(token) & (libc.Int32FromInt32(1) << libc.Int32FromInt32(15))
  33908 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  33909 				v3 = uint8(uint32(token) & uint32(0xff))
  33910 				if !(bit1 != 0) {
  33911 					v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  33912 				} else {
  33913 					v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  33914 				}
  33915 				v4 = v6
  33916 				goto _5
  33917 			_5:
  33918 				size = size + libc.Uint64FromInt32(v4)
  33919 			} else {
  33920 				v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))
  33921 				if !(bit1 != 0) {
  33922 					v2 = libc.Int32FromUint16(VP8EntropyCost[v3])
  33923 				} else {
  33924 					v2 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  33925 				}
  33926 				v1 = v2
  33927 				goto _9
  33928 			_9:
  33929 				size = size + libc.Uint64FromInt32(v1)
  33930 			}
  33931 		}
  33932 		p = next
  33933 	}
  33934 	return size
  33935 }
  33936 
  33937 func VP8DefaultProbas(tls *libc.TLS, enc uintptr) {
  33938 	var probas uintptr
  33939 	_ = probas
  33940 	probas = enc + 3616
  33941 	(*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba = 0
  33942 	libc.Xmemset(tls, probas, libc.Int32FromUint32(255), uint64(3))
  33943 	libc.Xmemcpy(tls, probas+4, uintptr(unsafe.Pointer(&VP8CoeffsProba0)), uint64(1056))
  33944 	// Note: we could hard-code the level_costs corresponding to VP8CoeffsProba0,
  33945 	// but that's ~11k of static data. Better call VP8CalculateLevelCosts() later.
  33946 	(*VP8EncProba)(unsafe.Pointer(probas)).Fdirty = int32(1)
  33947 }
  33948 
  33949 // C documentation
  33950 //
  33951 //	// Paragraph 11.5.  900bytes.
  33952 var kBModesProba1 = [10][10][9]uint8_t{
  33953 	0: {
  33954 		0: {
  33955 			0: uint8(231),
  33956 			1: uint8(120),
  33957 			2: uint8(48),
  33958 			3: uint8(89),
  33959 			4: uint8(115),
  33960 			5: uint8(113),
  33961 			6: uint8(120),
  33962 			7: uint8(152),
  33963 			8: uint8(112),
  33964 		},
  33965 		1: {
  33966 			0: uint8(152),
  33967 			1: uint8(179),
  33968 			2: uint8(64),
  33969 			3: uint8(126),
  33970 			4: uint8(170),
  33971 			5: uint8(118),
  33972 			6: uint8(46),
  33973 			7: uint8(70),
  33974 			8: uint8(95),
  33975 		},
  33976 		2: {
  33977 			0: uint8(175),
  33978 			1: uint8(69),
  33979 			2: uint8(143),
  33980 			3: uint8(80),
  33981 			4: uint8(85),
  33982 			5: uint8(82),
  33983 			6: uint8(72),
  33984 			7: uint8(155),
  33985 			8: uint8(103),
  33986 		},
  33987 		3: {
  33988 			0: uint8(56),
  33989 			1: uint8(58),
  33990 			2: uint8(10),
  33991 			3: uint8(171),
  33992 			4: uint8(218),
  33993 			5: uint8(189),
  33994 			6: uint8(17),
  33995 			7: uint8(13),
  33996 			8: uint8(152),
  33997 		},
  33998 		4: {
  33999 			0: uint8(114),
  34000 			1: uint8(26),
  34001 			2: uint8(17),
  34002 			3: uint8(163),
  34003 			4: uint8(44),
  34004 			5: uint8(195),
  34005 			6: uint8(21),
  34006 			7: uint8(10),
  34007 			8: uint8(173),
  34008 		},
  34009 		5: {
  34010 			0: uint8(121),
  34011 			1: uint8(24),
  34012 			2: uint8(80),
  34013 			3: uint8(195),
  34014 			4: uint8(26),
  34015 			5: uint8(62),
  34016 			6: uint8(44),
  34017 			7: uint8(64),
  34018 			8: uint8(85),
  34019 		},
  34020 		6: {
  34021 			0: uint8(144),
  34022 			1: uint8(71),
  34023 			2: uint8(10),
  34024 			3: uint8(38),
  34025 			4: uint8(171),
  34026 			5: uint8(213),
  34027 			6: uint8(144),
  34028 			7: uint8(34),
  34029 			8: uint8(26),
  34030 		},
  34031 		7: {
  34032 			0: uint8(170),
  34033 			1: uint8(46),
  34034 			2: uint8(55),
  34035 			3: uint8(19),
  34036 			4: uint8(136),
  34037 			5: uint8(160),
  34038 			6: uint8(33),
  34039 			7: uint8(206),
  34040 			8: uint8(71),
  34041 		},
  34042 		8: {
  34043 			0: uint8(63),
  34044 			1: uint8(20),
  34045 			2: uint8(8),
  34046 			3: uint8(114),
  34047 			4: uint8(114),
  34048 			5: uint8(208),
  34049 			6: uint8(12),
  34050 			7: uint8(9),
  34051 			8: uint8(226),
  34052 		},
  34053 		9: {
  34054 			0: uint8(81),
  34055 			1: uint8(40),
  34056 			2: uint8(11),
  34057 			3: uint8(96),
  34058 			4: uint8(182),
  34059 			5: uint8(84),
  34060 			6: uint8(29),
  34061 			7: uint8(16),
  34062 			8: uint8(36),
  34063 		},
  34064 	},
  34065 	1: {
  34066 		0: {
  34067 			0: uint8(134),
  34068 			1: uint8(183),
  34069 			2: uint8(89),
  34070 			3: uint8(137),
  34071 			4: uint8(98),
  34072 			5: uint8(101),
  34073 			6: uint8(106),
  34074 			7: uint8(165),
  34075 			8: uint8(148),
  34076 		},
  34077 		1: {
  34078 			0: uint8(72),
  34079 			1: uint8(187),
  34080 			2: uint8(100),
  34081 			3: uint8(130),
  34082 			4: uint8(157),
  34083 			5: uint8(111),
  34084 			6: uint8(32),
  34085 			7: uint8(75),
  34086 			8: uint8(80),
  34087 		},
  34088 		2: {
  34089 			0: uint8(66),
  34090 			1: uint8(102),
  34091 			2: uint8(167),
  34092 			3: uint8(99),
  34093 			4: uint8(74),
  34094 			5: uint8(62),
  34095 			6: uint8(40),
  34096 			7: uint8(234),
  34097 			8: uint8(128),
  34098 		},
  34099 		3: {
  34100 			0: uint8(41),
  34101 			1: uint8(53),
  34102 			2: uint8(9),
  34103 			3: uint8(178),
  34104 			4: uint8(241),
  34105 			5: uint8(141),
  34106 			6: uint8(26),
  34107 			7: uint8(8),
  34108 			8: uint8(107),
  34109 		},
  34110 		4: {
  34111 			0: uint8(74),
  34112 			1: uint8(43),
  34113 			2: uint8(26),
  34114 			3: uint8(146),
  34115 			4: uint8(73),
  34116 			5: uint8(166),
  34117 			6: uint8(49),
  34118 			7: uint8(23),
  34119 			8: uint8(157),
  34120 		},
  34121 		5: {
  34122 			0: uint8(65),
  34123 			1: uint8(38),
  34124 			2: uint8(105),
  34125 			3: uint8(160),
  34126 			4: uint8(51),
  34127 			5: uint8(52),
  34128 			6: uint8(31),
  34129 			7: uint8(115),
  34130 			8: uint8(128),
  34131 		},
  34132 		6: {
  34133 			0: uint8(104),
  34134 			1: uint8(79),
  34135 			2: uint8(12),
  34136 			3: uint8(27),
  34137 			4: uint8(217),
  34138 			5: uint8(255),
  34139 			6: uint8(87),
  34140 			7: uint8(17),
  34141 			8: uint8(7),
  34142 		},
  34143 		7: {
  34144 			0: uint8(87),
  34145 			1: uint8(68),
  34146 			2: uint8(71),
  34147 			3: uint8(44),
  34148 			4: uint8(114),
  34149 			5: uint8(51),
  34150 			6: uint8(15),
  34151 			7: uint8(186),
  34152 			8: uint8(23),
  34153 		},
  34154 		8: {
  34155 			0: uint8(47),
  34156 			1: uint8(41),
  34157 			2: uint8(14),
  34158 			3: uint8(110),
  34159 			4: uint8(182),
  34160 			5: uint8(183),
  34161 			6: uint8(21),
  34162 			7: uint8(17),
  34163 			8: uint8(194),
  34164 		},
  34165 		9: {
  34166 			0: uint8(66),
  34167 			1: uint8(45),
  34168 			2: uint8(25),
  34169 			3: uint8(102),
  34170 			4: uint8(197),
  34171 			5: uint8(189),
  34172 			6: uint8(23),
  34173 			7: uint8(18),
  34174 			8: uint8(22),
  34175 		},
  34176 	},
  34177 	2: {
  34178 		0: {
  34179 			0: uint8(88),
  34180 			1: uint8(88),
  34181 			2: uint8(147),
  34182 			3: uint8(150),
  34183 			4: uint8(42),
  34184 			5: uint8(46),
  34185 			6: uint8(45),
  34186 			7: uint8(196),
  34187 			8: uint8(205),
  34188 		},
  34189 		1: {
  34190 			0: uint8(43),
  34191 			1: uint8(97),
  34192 			2: uint8(183),
  34193 			3: uint8(117),
  34194 			4: uint8(85),
  34195 			5: uint8(38),
  34196 			6: uint8(35),
  34197 			7: uint8(179),
  34198 			8: uint8(61),
  34199 		},
  34200 		2: {
  34201 			0: uint8(39),
  34202 			1: uint8(53),
  34203 			2: uint8(200),
  34204 			3: uint8(87),
  34205 			4: uint8(26),
  34206 			5: uint8(21),
  34207 			6: uint8(43),
  34208 			7: uint8(232),
  34209 			8: uint8(171),
  34210 		},
  34211 		3: {
  34212 			0: uint8(56),
  34213 			1: uint8(34),
  34214 			2: uint8(51),
  34215 			3: uint8(104),
  34216 			4: uint8(114),
  34217 			5: uint8(102),
  34218 			6: uint8(29),
  34219 			7: uint8(93),
  34220 			8: uint8(77),
  34221 		},
  34222 		4: {
  34223 			0: uint8(39),
  34224 			1: uint8(28),
  34225 			2: uint8(85),
  34226 			3: uint8(171),
  34227 			4: uint8(58),
  34228 			5: uint8(165),
  34229 			6: uint8(90),
  34230 			7: uint8(98),
  34231 			8: uint8(64),
  34232 		},
  34233 		5: {
  34234 			0: uint8(34),
  34235 			1: uint8(22),
  34236 			2: uint8(116),
  34237 			3: uint8(206),
  34238 			4: uint8(23),
  34239 			5: uint8(34),
  34240 			6: uint8(43),
  34241 			7: uint8(166),
  34242 			8: uint8(73),
  34243 		},
  34244 		6: {
  34245 			0: uint8(107),
  34246 			1: uint8(54),
  34247 			2: uint8(32),
  34248 			3: uint8(26),
  34249 			4: uint8(51),
  34250 			5: uint8(1),
  34251 			6: uint8(81),
  34252 			7: uint8(43),
  34253 			8: uint8(31),
  34254 		},
  34255 		7: {
  34256 			0: uint8(68),
  34257 			1: uint8(25),
  34258 			2: uint8(106),
  34259 			3: uint8(22),
  34260 			4: uint8(64),
  34261 			5: uint8(171),
  34262 			6: uint8(36),
  34263 			7: uint8(225),
  34264 			8: uint8(114),
  34265 		},
  34266 		8: {
  34267 			0: uint8(34),
  34268 			1: uint8(19),
  34269 			2: uint8(21),
  34270 			3: uint8(102),
  34271 			4: uint8(132),
  34272 			5: uint8(188),
  34273 			6: uint8(16),
  34274 			7: uint8(76),
  34275 			8: uint8(124),
  34276 		},
  34277 		9: {
  34278 			0: uint8(62),
  34279 			1: uint8(18),
  34280 			2: uint8(78),
  34281 			3: uint8(95),
  34282 			4: uint8(85),
  34283 			5: uint8(57),
  34284 			6: uint8(50),
  34285 			7: uint8(48),
  34286 			8: uint8(51),
  34287 		},
  34288 	},
  34289 	3: {
  34290 		0: {
  34291 			0: uint8(193),
  34292 			1: uint8(101),
  34293 			2: uint8(35),
  34294 			3: uint8(159),
  34295 			4: uint8(215),
  34296 			5: uint8(111),
  34297 			6: uint8(89),
  34298 			7: uint8(46),
  34299 			8: uint8(111),
  34300 		},
  34301 		1: {
  34302 			0: uint8(60),
  34303 			1: uint8(148),
  34304 			2: uint8(31),
  34305 			3: uint8(172),
  34306 			4: uint8(219),
  34307 			5: uint8(228),
  34308 			6: uint8(21),
  34309 			7: uint8(18),
  34310 			8: uint8(111),
  34311 		},
  34312 		2: {
  34313 			0: uint8(112),
  34314 			1: uint8(113),
  34315 			2: uint8(77),
  34316 			3: uint8(85),
  34317 			4: uint8(179),
  34318 			5: uint8(255),
  34319 			6: uint8(38),
  34320 			7: uint8(120),
  34321 			8: uint8(114),
  34322 		},
  34323 		3: {
  34324 			0: uint8(40),
  34325 			1: uint8(42),
  34326 			2: uint8(1),
  34327 			3: uint8(196),
  34328 			4: uint8(245),
  34329 			5: uint8(209),
  34330 			6: uint8(10),
  34331 			7: uint8(25),
  34332 			8: uint8(109),
  34333 		},
  34334 		4: {
  34335 			0: uint8(88),
  34336 			1: uint8(43),
  34337 			2: uint8(29),
  34338 			3: uint8(140),
  34339 			4: uint8(166),
  34340 			5: uint8(213),
  34341 			6: uint8(37),
  34342 			7: uint8(43),
  34343 			8: uint8(154),
  34344 		},
  34345 		5: {
  34346 			0: uint8(61),
  34347 			1: uint8(63),
  34348 			2: uint8(30),
  34349 			3: uint8(155),
  34350 			4: uint8(67),
  34351 			5: uint8(45),
  34352 			6: uint8(68),
  34353 			7: uint8(1),
  34354 			8: uint8(209),
  34355 		},
  34356 		6: {
  34357 			0: uint8(100),
  34358 			1: uint8(80),
  34359 			2: uint8(8),
  34360 			3: uint8(43),
  34361 			4: uint8(154),
  34362 			5: uint8(1),
  34363 			6: uint8(51),
  34364 			7: uint8(26),
  34365 			8: uint8(71),
  34366 		},
  34367 		7: {
  34368 			0: uint8(142),
  34369 			1: uint8(78),
  34370 			2: uint8(78),
  34371 			3: uint8(16),
  34372 			4: uint8(255),
  34373 			5: uint8(128),
  34374 			6: uint8(34),
  34375 			7: uint8(197),
  34376 			8: uint8(171),
  34377 		},
  34378 		8: {
  34379 			0: uint8(41),
  34380 			1: uint8(40),
  34381 			2: uint8(5),
  34382 			3: uint8(102),
  34383 			4: uint8(211),
  34384 			5: uint8(183),
  34385 			6: uint8(4),
  34386 			7: uint8(1),
  34387 			8: uint8(221),
  34388 		},
  34389 		9: {
  34390 			0: uint8(51),
  34391 			1: uint8(50),
  34392 			2: uint8(17),
  34393 			3: uint8(168),
  34394 			4: uint8(209),
  34395 			5: uint8(192),
  34396 			6: uint8(23),
  34397 			7: uint8(25),
  34398 			8: uint8(82),
  34399 		},
  34400 	},
  34401 	4: {
  34402 		0: {
  34403 			0: uint8(138),
  34404 			1: uint8(31),
  34405 			2: uint8(36),
  34406 			3: uint8(171),
  34407 			4: uint8(27),
  34408 			5: uint8(166),
  34409 			6: uint8(38),
  34410 			7: uint8(44),
  34411 			8: uint8(229),
  34412 		},
  34413 		1: {
  34414 			0: uint8(67),
  34415 			1: uint8(87),
  34416 			2: uint8(58),
  34417 			3: uint8(169),
  34418 			4: uint8(82),
  34419 			5: uint8(115),
  34420 			6: uint8(26),
  34421 			7: uint8(59),
  34422 			8: uint8(179),
  34423 		},
  34424 		2: {
  34425 			0: uint8(63),
  34426 			1: uint8(59),
  34427 			2: uint8(90),
  34428 			3: uint8(180),
  34429 			4: uint8(59),
  34430 			5: uint8(166),
  34431 			6: uint8(93),
  34432 			7: uint8(73),
  34433 			8: uint8(154),
  34434 		},
  34435 		3: {
  34436 			0: uint8(40),
  34437 			1: uint8(40),
  34438 			2: uint8(21),
  34439 			3: uint8(116),
  34440 			4: uint8(143),
  34441 			5: uint8(209),
  34442 			6: uint8(34),
  34443 			7: uint8(39),
  34444 			8: uint8(175),
  34445 		},
  34446 		4: {
  34447 			0: uint8(47),
  34448 			1: uint8(15),
  34449 			2: uint8(16),
  34450 			3: uint8(183),
  34451 			4: uint8(34),
  34452 			5: uint8(223),
  34453 			6: uint8(49),
  34454 			7: uint8(45),
  34455 			8: uint8(183),
  34456 		},
  34457 		5: {
  34458 			0: uint8(46),
  34459 			1: uint8(17),
  34460 			2: uint8(33),
  34461 			3: uint8(183),
  34462 			4: uint8(6),
  34463 			5: uint8(98),
  34464 			6: uint8(15),
  34465 			7: uint8(32),
  34466 			8: uint8(183),
  34467 		},
  34468 		6: {
  34469 			0: uint8(57),
  34470 			1: uint8(46),
  34471 			2: uint8(22),
  34472 			3: uint8(24),
  34473 			4: uint8(128),
  34474 			5: uint8(1),
  34475 			6: uint8(54),
  34476 			7: uint8(17),
  34477 			8: uint8(37),
  34478 		},
  34479 		7: {
  34480 			0: uint8(65),
  34481 			1: uint8(32),
  34482 			2: uint8(73),
  34483 			3: uint8(115),
  34484 			4: uint8(28),
  34485 			5: uint8(128),
  34486 			6: uint8(23),
  34487 			7: uint8(128),
  34488 			8: uint8(205),
  34489 		},
  34490 		8: {
  34491 			0: uint8(40),
  34492 			1: uint8(3),
  34493 			2: uint8(9),
  34494 			3: uint8(115),
  34495 			4: uint8(51),
  34496 			5: uint8(192),
  34497 			6: uint8(18),
  34498 			7: uint8(6),
  34499 			8: uint8(223),
  34500 		},
  34501 		9: {
  34502 			0: uint8(87),
  34503 			1: uint8(37),
  34504 			2: uint8(9),
  34505 			3: uint8(115),
  34506 			4: uint8(59),
  34507 			5: uint8(77),
  34508 			6: uint8(64),
  34509 			7: uint8(21),
  34510 			8: uint8(47),
  34511 		},
  34512 	},
  34513 	5: {
  34514 		0: {
  34515 			0: uint8(104),
  34516 			1: uint8(55),
  34517 			2: uint8(44),
  34518 			3: uint8(218),
  34519 			4: uint8(9),
  34520 			5: uint8(54),
  34521 			6: uint8(53),
  34522 			7: uint8(130),
  34523 			8: uint8(226),
  34524 		},
  34525 		1: {
  34526 			0: uint8(64),
  34527 			1: uint8(90),
  34528 			2: uint8(70),
  34529 			3: uint8(205),
  34530 			4: uint8(40),
  34531 			5: uint8(41),
  34532 			6: uint8(23),
  34533 			7: uint8(26),
  34534 			8: uint8(57),
  34535 		},
  34536 		2: {
  34537 			0: uint8(54),
  34538 			1: uint8(57),
  34539 			2: uint8(112),
  34540 			3: uint8(184),
  34541 			4: uint8(5),
  34542 			5: uint8(41),
  34543 			6: uint8(38),
  34544 			7: uint8(166),
  34545 			8: uint8(213),
  34546 		},
  34547 		3: {
  34548 			0: uint8(30),
  34549 			1: uint8(34),
  34550 			2: uint8(26),
  34551 			3: uint8(133),
  34552 			4: uint8(152),
  34553 			5: uint8(116),
  34554 			6: uint8(10),
  34555 			7: uint8(32),
  34556 			8: uint8(134),
  34557 		},
  34558 		4: {
  34559 			0: uint8(39),
  34560 			1: uint8(19),
  34561 			2: uint8(53),
  34562 			3: uint8(221),
  34563 			4: uint8(26),
  34564 			5: uint8(114),
  34565 			6: uint8(32),
  34566 			7: uint8(73),
  34567 			8: uint8(255),
  34568 		},
  34569 		5: {
  34570 			0: uint8(31),
  34571 			1: uint8(9),
  34572 			2: uint8(65),
  34573 			3: uint8(234),
  34574 			4: uint8(2),
  34575 			5: uint8(15),
  34576 			6: uint8(1),
  34577 			7: uint8(118),
  34578 			8: uint8(73),
  34579 		},
  34580 		6: {
  34581 			0: uint8(75),
  34582 			1: uint8(32),
  34583 			2: uint8(12),
  34584 			3: uint8(51),
  34585 			4: uint8(192),
  34586 			5: uint8(255),
  34587 			6: uint8(160),
  34588 			7: uint8(43),
  34589 			8: uint8(51),
  34590 		},
  34591 		7: {
  34592 			0: uint8(88),
  34593 			1: uint8(31),
  34594 			2: uint8(35),
  34595 			3: uint8(67),
  34596 			4: uint8(102),
  34597 			5: uint8(85),
  34598 			6: uint8(55),
  34599 			7: uint8(186),
  34600 			8: uint8(85),
  34601 		},
  34602 		8: {
  34603 			0: uint8(56),
  34604 			1: uint8(21),
  34605 			2: uint8(23),
  34606 			3: uint8(111),
  34607 			4: uint8(59),
  34608 			5: uint8(205),
  34609 			6: uint8(45),
  34610 			7: uint8(37),
  34611 			8: uint8(192),
  34612 		},
  34613 		9: {
  34614 			0: uint8(55),
  34615 			1: uint8(38),
  34616 			2: uint8(70),
  34617 			3: uint8(124),
  34618 			4: uint8(73),
  34619 			5: uint8(102),
  34620 			6: uint8(1),
  34621 			7: uint8(34),
  34622 			8: uint8(98),
  34623 		},
  34624 	},
  34625 	6: {
  34626 		0: {
  34627 			0: uint8(125),
  34628 			1: uint8(98),
  34629 			2: uint8(42),
  34630 			3: uint8(88),
  34631 			4: uint8(104),
  34632 			5: uint8(85),
  34633 			6: uint8(117),
  34634 			7: uint8(175),
  34635 			8: uint8(82),
  34636 		},
  34637 		1: {
  34638 			0: uint8(95),
  34639 			1: uint8(84),
  34640 			2: uint8(53),
  34641 			3: uint8(89),
  34642 			4: uint8(128),
  34643 			5: uint8(100),
  34644 			6: uint8(113),
  34645 			7: uint8(101),
  34646 			8: uint8(45),
  34647 		},
  34648 		2: {
  34649 			0: uint8(75),
  34650 			1: uint8(79),
  34651 			2: uint8(123),
  34652 			3: uint8(47),
  34653 			4: uint8(51),
  34654 			5: uint8(128),
  34655 			6: uint8(81),
  34656 			7: uint8(171),
  34657 			8: uint8(1),
  34658 		},
  34659 		3: {
  34660 			0: uint8(57),
  34661 			1: uint8(17),
  34662 			2: uint8(5),
  34663 			3: uint8(71),
  34664 			4: uint8(102),
  34665 			5: uint8(57),
  34666 			6: uint8(53),
  34667 			7: uint8(41),
  34668 			8: uint8(49),
  34669 		},
  34670 		4: {
  34671 			0: uint8(38),
  34672 			1: uint8(33),
  34673 			2: uint8(13),
  34674 			3: uint8(121),
  34675 			4: uint8(57),
  34676 			5: uint8(73),
  34677 			6: uint8(26),
  34678 			7: uint8(1),
  34679 			8: uint8(85),
  34680 		},
  34681 		5: {
  34682 			0: uint8(41),
  34683 			1: uint8(10),
  34684 			2: uint8(67),
  34685 			3: uint8(138),
  34686 			4: uint8(77),
  34687 			5: uint8(110),
  34688 			6: uint8(90),
  34689 			7: uint8(47),
  34690 			8: uint8(114),
  34691 		},
  34692 		6: {
  34693 			0: uint8(115),
  34694 			1: uint8(21),
  34695 			2: uint8(2),
  34696 			3: uint8(10),
  34697 			4: uint8(102),
  34698 			5: uint8(255),
  34699 			6: uint8(166),
  34700 			7: uint8(23),
  34701 			8: uint8(6),
  34702 		},
  34703 		7: {
  34704 			0: uint8(101),
  34705 			1: uint8(29),
  34706 			2: uint8(16),
  34707 			3: uint8(10),
  34708 			4: uint8(85),
  34709 			5: uint8(128),
  34710 			6: uint8(101),
  34711 			7: uint8(196),
  34712 			8: uint8(26),
  34713 		},
  34714 		8: {
  34715 			0: uint8(57),
  34716 			1: uint8(18),
  34717 			2: uint8(10),
  34718 			3: uint8(102),
  34719 			4: uint8(102),
  34720 			5: uint8(213),
  34721 			6: uint8(34),
  34722 			7: uint8(20),
  34723 			8: uint8(43),
  34724 		},
  34725 		9: {
  34726 			0: uint8(117),
  34727 			1: uint8(20),
  34728 			2: uint8(15),
  34729 			3: uint8(36),
  34730 			4: uint8(163),
  34731 			5: uint8(128),
  34732 			6: uint8(68),
  34733 			7: uint8(1),
  34734 			8: uint8(26),
  34735 		},
  34736 	},
  34737 	7: {
  34738 		0: {
  34739 			0: uint8(102),
  34740 			1: uint8(61),
  34741 			2: uint8(71),
  34742 			3: uint8(37),
  34743 			4: uint8(34),
  34744 			5: uint8(53),
  34745 			6: uint8(31),
  34746 			7: uint8(243),
  34747 			8: uint8(192),
  34748 		},
  34749 		1: {
  34750 			0: uint8(69),
  34751 			1: uint8(60),
  34752 			2: uint8(71),
  34753 			3: uint8(38),
  34754 			4: uint8(73),
  34755 			5: uint8(119),
  34756 			6: uint8(28),
  34757 			7: uint8(222),
  34758 			8: uint8(37),
  34759 		},
  34760 		2: {
  34761 			0: uint8(68),
  34762 			1: uint8(45),
  34763 			2: uint8(128),
  34764 			3: uint8(34),
  34765 			4: uint8(1),
  34766 			5: uint8(47),
  34767 			6: uint8(11),
  34768 			7: uint8(245),
  34769 			8: uint8(171),
  34770 		},
  34771 		3: {
  34772 			0: uint8(62),
  34773 			1: uint8(17),
  34774 			2: uint8(19),
  34775 			3: uint8(70),
  34776 			4: uint8(146),
  34777 			5: uint8(85),
  34778 			6: uint8(55),
  34779 			7: uint8(62),
  34780 			8: uint8(70),
  34781 		},
  34782 		4: {
  34783 			0: uint8(37),
  34784 			1: uint8(43),
  34785 			2: uint8(37),
  34786 			3: uint8(154),
  34787 			4: uint8(100),
  34788 			5: uint8(163),
  34789 			6: uint8(85),
  34790 			7: uint8(160),
  34791 			8: uint8(1),
  34792 		},
  34793 		5: {
  34794 			0: uint8(63),
  34795 			1: uint8(9),
  34796 			2: uint8(92),
  34797 			3: uint8(136),
  34798 			4: uint8(28),
  34799 			5: uint8(64),
  34800 			6: uint8(32),
  34801 			7: uint8(201),
  34802 			8: uint8(85),
  34803 		},
  34804 		6: {
  34805 			0: uint8(75),
  34806 			1: uint8(15),
  34807 			2: uint8(9),
  34808 			3: uint8(9),
  34809 			4: uint8(64),
  34810 			5: uint8(255),
  34811 			6: uint8(184),
  34812 			7: uint8(119),
  34813 			8: uint8(16),
  34814 		},
  34815 		7: {
  34816 			0: uint8(86),
  34817 			1: uint8(6),
  34818 			2: uint8(28),
  34819 			3: uint8(5),
  34820 			4: uint8(64),
  34821 			5: uint8(255),
  34822 			6: uint8(25),
  34823 			7: uint8(248),
  34824 			8: uint8(1),
  34825 		},
  34826 		8: {
  34827 			0: uint8(56),
  34828 			1: uint8(8),
  34829 			2: uint8(17),
  34830 			3: uint8(132),
  34831 			4: uint8(137),
  34832 			5: uint8(255),
  34833 			6: uint8(55),
  34834 			7: uint8(116),
  34835 			8: uint8(128),
  34836 		},
  34837 		9: {
  34838 			0: uint8(58),
  34839 			1: uint8(15),
  34840 			2: uint8(20),
  34841 			3: uint8(82),
  34842 			4: uint8(135),
  34843 			5: uint8(57),
  34844 			6: uint8(26),
  34845 			7: uint8(121),
  34846 			8: uint8(40),
  34847 		},
  34848 	},
  34849 	8: {
  34850 		0: {
  34851 			0: uint8(164),
  34852 			1: uint8(50),
  34853 			2: uint8(31),
  34854 			3: uint8(137),
  34855 			4: uint8(154),
  34856 			5: uint8(133),
  34857 			6: uint8(25),
  34858 			7: uint8(35),
  34859 			8: uint8(218),
  34860 		},
  34861 		1: {
  34862 			0: uint8(51),
  34863 			1: uint8(103),
  34864 			2: uint8(44),
  34865 			3: uint8(131),
  34866 			4: uint8(131),
  34867 			5: uint8(123),
  34868 			6: uint8(31),
  34869 			7: uint8(6),
  34870 			8: uint8(158),
  34871 		},
  34872 		2: {
  34873 			0: uint8(86),
  34874 			1: uint8(40),
  34875 			2: uint8(64),
  34876 			3: uint8(135),
  34877 			4: uint8(148),
  34878 			5: uint8(224),
  34879 			6: uint8(45),
  34880 			7: uint8(183),
  34881 			8: uint8(128),
  34882 		},
  34883 		3: {
  34884 			0: uint8(22),
  34885 			1: uint8(26),
  34886 			2: uint8(17),
  34887 			3: uint8(131),
  34888 			4: uint8(240),
  34889 			5: uint8(154),
  34890 			6: uint8(14),
  34891 			7: uint8(1),
  34892 			8: uint8(209),
  34893 		},
  34894 		4: {
  34895 			0: uint8(45),
  34896 			1: uint8(16),
  34897 			2: uint8(21),
  34898 			3: uint8(91),
  34899 			4: uint8(64),
  34900 			5: uint8(222),
  34901 			6: uint8(7),
  34902 			7: uint8(1),
  34903 			8: uint8(197),
  34904 		},
  34905 		5: {
  34906 			0: uint8(56),
  34907 			1: uint8(21),
  34908 			2: uint8(39),
  34909 			3: uint8(155),
  34910 			4: uint8(60),
  34911 			5: uint8(138),
  34912 			6: uint8(23),
  34913 			7: uint8(102),
  34914 			8: uint8(213),
  34915 		},
  34916 		6: {
  34917 			0: uint8(83),
  34918 			1: uint8(12),
  34919 			2: uint8(13),
  34920 			3: uint8(54),
  34921 			4: uint8(192),
  34922 			5: uint8(255),
  34923 			6: uint8(68),
  34924 			7: uint8(47),
  34925 			8: uint8(28),
  34926 		},
  34927 		7: {
  34928 			0: uint8(85),
  34929 			1: uint8(26),
  34930 			2: uint8(85),
  34931 			3: uint8(85),
  34932 			4: uint8(128),
  34933 			5: uint8(128),
  34934 			6: uint8(32),
  34935 			7: uint8(146),
  34936 			8: uint8(171),
  34937 		},
  34938 		8: {
  34939 			0: uint8(18),
  34940 			1: uint8(11),
  34941 			2: uint8(7),
  34942 			3: uint8(63),
  34943 			4: uint8(144),
  34944 			5: uint8(171),
  34945 			6: uint8(4),
  34946 			7: uint8(4),
  34947 			8: uint8(246),
  34948 		},
  34949 		9: {
  34950 			0: uint8(35),
  34951 			1: uint8(27),
  34952 			2: uint8(10),
  34953 			3: uint8(146),
  34954 			4: uint8(174),
  34955 			5: uint8(171),
  34956 			6: uint8(12),
  34957 			7: uint8(26),
  34958 			8: uint8(128),
  34959 		},
  34960 	},
  34961 	9: {
  34962 		0: {
  34963 			0: uint8(190),
  34964 			1: uint8(80),
  34965 			2: uint8(35),
  34966 			3: uint8(99),
  34967 			4: uint8(180),
  34968 			5: uint8(80),
  34969 			6: uint8(126),
  34970 			7: uint8(54),
  34971 			8: uint8(45),
  34972 		},
  34973 		1: {
  34974 			0: uint8(85),
  34975 			1: uint8(126),
  34976 			2: uint8(47),
  34977 			3: uint8(87),
  34978 			4: uint8(176),
  34979 			5: uint8(51),
  34980 			6: uint8(41),
  34981 			7: uint8(20),
  34982 			8: uint8(32),
  34983 		},
  34984 		2: {
  34985 			0: uint8(101),
  34986 			1: uint8(75),
  34987 			2: uint8(128),
  34988 			3: uint8(139),
  34989 			4: uint8(118),
  34990 			5: uint8(146),
  34991 			6: uint8(116),
  34992 			7: uint8(128),
  34993 			8: uint8(85),
  34994 		},
  34995 		3: {
  34996 			0: uint8(56),
  34997 			1: uint8(41),
  34998 			2: uint8(15),
  34999 			3: uint8(176),
  35000 			4: uint8(236),
  35001 			5: uint8(85),
  35002 			6: uint8(37),
  35003 			7: uint8(9),
  35004 			8: uint8(62),
  35005 		},
  35006 		4: {
  35007 			0: uint8(71),
  35008 			1: uint8(30),
  35009 			2: uint8(17),
  35010 			3: uint8(119),
  35011 			4: uint8(118),
  35012 			5: uint8(255),
  35013 			6: uint8(17),
  35014 			7: uint8(18),
  35015 			8: uint8(138),
  35016 		},
  35017 		5: {
  35018 			0: uint8(101),
  35019 			1: uint8(38),
  35020 			2: uint8(60),
  35021 			3: uint8(138),
  35022 			4: uint8(55),
  35023 			5: uint8(70),
  35024 			6: uint8(43),
  35025 			7: uint8(26),
  35026 			8: uint8(142),
  35027 		},
  35028 		6: {
  35029 			0: uint8(146),
  35030 			1: uint8(36),
  35031 			2: uint8(19),
  35032 			3: uint8(30),
  35033 			4: uint8(171),
  35034 			5: uint8(255),
  35035 			6: uint8(97),
  35036 			7: uint8(27),
  35037 			8: uint8(20),
  35038 		},
  35039 		7: {
  35040 			0: uint8(138),
  35041 			1: uint8(45),
  35042 			2: uint8(61),
  35043 			3: uint8(62),
  35044 			4: uint8(219),
  35045 			5: uint8(1),
  35046 			6: uint8(81),
  35047 			7: uint8(188),
  35048 			8: uint8(64),
  35049 		},
  35050 		8: {
  35051 			0: uint8(32),
  35052 			1: uint8(41),
  35053 			2: uint8(20),
  35054 			3: uint8(117),
  35055 			4: uint8(151),
  35056 			5: uint8(142),
  35057 			6: uint8(20),
  35058 			7: uint8(21),
  35059 			8: uint8(163),
  35060 		},
  35061 		9: {
  35062 			0: uint8(112),
  35063 			1: uint8(19),
  35064 			2: uint8(12),
  35065 			3: uint8(61),
  35066 			4: uint8(195),
  35067 			5: uint8(128),
  35068 			6: uint8(48),
  35069 			7: uint8(4),
  35070 			8: uint8(24),
  35071 		},
  35072 	},
  35073 }
  35074 
  35075 func PutI4Mode(tls *libc.TLS, bw uintptr, mode int32, prob uintptr) (r int32) {
  35076 	if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_DC_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob)))) != 0 {
  35077 		if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_TM_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 1)))) != 0 {
  35078 			if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VE_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 2)))) != 0 {
  35079 				if !(VP8PutBit(tls, bw, libc.BoolInt32(mode >= int32(B_LD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 3)))) != 0) {
  35080 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HE_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 4)))) != 0 {
  35081 						VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_RD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 5))))
  35082 					}
  35083 				} else {
  35084 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_LD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 6)))) != 0 {
  35085 						if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VL_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 7)))) != 0 {
  35086 							VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 8))))
  35087 						}
  35088 					}
  35089 				}
  35090 			}
  35091 		}
  35092 	}
  35093 	return mode
  35094 }
  35095 
  35096 func PutI16Mode(tls *libc.TLS, bw uintptr, mode int32) {
  35097 	if VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED) || mode == int32(H_PRED)), int32(156)) != 0 {
  35098 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED)), int32(128)) // TM or HE
  35099 	} else {
  35100 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(V_PRED)), int32(163)) // VE or DC
  35101 	}
  35102 }
  35103 
  35104 func PutUVMode(tls *libc.TLS, bw uintptr, uv_mode int32) {
  35105 	if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(DC_PRED)), int32(142)) != 0 {
  35106 		if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(V_PRED)), int32(114)) != 0 {
  35107 			VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(H_PRED)), int32(183)) // else: TM_PRED
  35108 		}
  35109 	}
  35110 }
  35111 
  35112 func PutSegment(tls *libc.TLS, bw uintptr, s int32, p uintptr) {
  35113 	if VP8PutBit(tls, bw, libc.BoolInt32(s >= int32(2)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) != 0 {
  35114 		p = p + uintptr(1)
  35115 	}
  35116 	VP8PutBit(tls, bw, s&int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1))))
  35117 }
  35118 
  35119 func VP8CodeIntraModes(tls *libc.TLS, enc uintptr) {
  35120 	bp := tls.Alloc(3856)
  35121 	defer tls.Free(3856)
  35122 	var bw, mb, preds, probas, top_pred uintptr
  35123 	var left, preds_w, x, y int32
  35124 	var _ /* it at bp+0 */ VP8EncIterator
  35125 	_, _, _, _, _, _, _, _, _ = bw, left, mb, preds, preds_w, probas, top_pred, x, y
  35126 	bw = enc + 64
  35127 	VP8IteratorInit(tls, enc, bp)
  35128 	for cond := true; cond; cond = VP8IteratorNext(tls, bp) != 0 {
  35129 		mb = (**(**VP8EncIterator)(__ccgo_up(bp))).Fmb
  35130 		preds = (**(**VP8EncIterator)(__ccgo_up(bp))).Fpreds
  35131 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0 {
  35132 			PutSegment(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)), enc+3616)
  35133 		}
  35134 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0 {
  35135 			VP8PutBit(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)), libc.Int32FromUint8((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fskip_proba))
  35136 		}
  35137 		if VP8PutBit(tls, bw, libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) != 0), int32(145)) != 0 { // i16x16
  35138 			PutI16Mode(tls, bw, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(preds))))
  35139 		} else {
  35140 			preds_w = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w
  35141 			top_pred = preds - uintptr(preds_w)
  35142 			y = 0
  35143 			for {
  35144 				if !(y < int32(4)) {
  35145 					break
  35146 				}
  35147 				left = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(preds + uintptr(-libc.Int32FromInt32(1)))))
  35148 				x = 0
  35149 				for {
  35150 					if !(x < int32(4)) {
  35151 						break
  35152 					}
  35153 					probas = uintptr(unsafe.Pointer(&kBModesProba1)) + uintptr(**(**uint8_t)(__ccgo_up(top_pred + uintptr(x))))*90 + uintptr(left)*9
  35154 					left = PutI4Mode(tls, bw, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(preds + uintptr(x)))), probas)
  35155 					goto _2
  35156 				_2:
  35157 					;
  35158 					x = x + 1
  35159 				}
  35160 				top_pred = preds
  35161 				preds = preds + uintptr(preds_w)
  35162 				goto _1
  35163 			_1:
  35164 				;
  35165 				y = y + 1
  35166 			}
  35167 		}
  35168 		PutUVMode(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0xc>>2)))
  35169 	}
  35170 }
  35171 
  35172 func VP8WriteProbas(tls *libc.TLS, bw uintptr, probas uintptr) {
  35173 	var b, c, p, t, update int32
  35174 	var p0 uint8_t
  35175 	_, _, _, _, _, _ = b, c, p, p0, t, update
  35176 	t = 0
  35177 	for {
  35178 		if !(t < int32(NUM_TYPES)) {
  35179 			break
  35180 		}
  35181 		b = 0
  35182 		for {
  35183 			if !(b < int32(NUM_BANDS)) {
  35184 				break
  35185 			}
  35186 			c = 0
  35187 			for {
  35188 				if !(c < int32(NUM_CTX)) {
  35189 					break
  35190 				}
  35191 				p = 0
  35192 				for {
  35193 					if !(p < int32(NUM_PROBAS)) {
  35194 						break
  35195 					}
  35196 					p0 = **(**uint8_t)(__ccgo_up(probas + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p)))
  35197 					update = libc.BoolInt32(libc.Int32FromUint8(p0) != libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p)))))
  35198 					if VP8PutBit(tls, bw, update, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))) != 0 {
  35199 						VP8PutBits(tls, bw, uint32(p0), int32(8))
  35200 					}
  35201 					goto _4
  35202 				_4:
  35203 					;
  35204 					p = p + 1
  35205 				}
  35206 				goto _3
  35207 			_3:
  35208 				;
  35209 				c = c + 1
  35210 			}
  35211 			goto _2
  35212 		_2:
  35213 			;
  35214 			b = b + 1
  35215 		}
  35216 		goto _1
  35217 	_1:
  35218 		;
  35219 		t = t + 1
  35220 	}
  35221 	if VP8PutBitUniform(tls, bw, (*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba) != 0 {
  35222 		VP8PutBits(tls, bw, uint32((*VP8EncProba)(unsafe.Pointer(probas)).Fskip_proba), int32(8))
  35223 	}
  35224 }
  35225 
  35226 const MAX_HUFF_IMAGE_SIZE = 2600
  35227 const NUM_BUCKETS = 256
  35228 const VP8L_MAGIC_BYTE3 = 47
  35229 const VP8_SIGNATURE2 = 0x9d012a
  35230 
  35231 type HuffmanTreeToken = struct {
  35232 	Fcode       uint8_t
  35233 	Fextra_bits uint8_t
  35234 }
  35235 
  35236 type HuffmanTreeCode = struct {
  35237 	Fnum_symbols  int32
  35238 	Fcode_lengths uintptr
  35239 	Fcodes        uintptr
  35240 }
  35241 
  35242 type HuffmanTree = struct {
  35243 	Ftotal_count      uint32_t
  35244 	Fvalue            int32
  35245 	Fpool_index_left  int32
  35246 	Fpool_index_right int32
  35247 }
  35248 
  35249 type PaletteSorting1 = int32
  35250 
  35251 type PaletteSorting = int32
  35252 
  35253 const kSortedDefault = 0
  35254 const kMinimizeDelta = 1
  35255 const kModifiedZeng = 2
  35256 const kUnusedPalette = 3
  35257 const kPaletteSortingNum = 4
  35258 
  35259 // Copyright 2011 Google Inc. All Rights Reserved.
  35260 //
  35261 // Use of this source code is governed by a BSD-style license
  35262 // that can be found in the COPYING file in the root of the source
  35263 // tree. An additional intellectual property rights grant can be found
  35264 // in the file PATENTS. All contributing project authors may
  35265 // be found in the AUTHORS file in the root of the source tree.
  35266 // -----------------------------------------------------------------------------
  35267 //
  35268 // Multi-threaded worker
  35269 //
  35270 // Author: Skal (pascal.massimino@gmail.com)
  35271 
  35272 // Copyright 2012 Google Inc. All Rights Reserved.
  35273 //
  35274 // Use of this source code is governed by a BSD-style license
  35275 // that can be found in the COPYING file in the root of the source
  35276 // tree. An additional intellectual property rights grant can be found
  35277 // in the file PATENTS. All contributing project authors may
  35278 // be found in the AUTHORS file in the root of the source tree.
  35279 // -----------------------------------------------------------------------------
  35280 //
  35281 // Misc. common utility functions
  35282 //
  35283 // Authors: Skal (pascal.massimino@gmail.com)
  35284 //          Urvang (urvang@google.com)
  35285 
  35286 // Copyright 2011 Google Inc. All Rights Reserved.
  35287 //
  35288 // Use of this source code is governed by a BSD-style license
  35289 // that can be found in the COPYING file in the root of the source
  35290 // tree. An additional intellectual property rights grant can be found
  35291 // in the file PATENTS. All contributing project authors may
  35292 // be found in the AUTHORS file in the root of the source tree.
  35293 // -----------------------------------------------------------------------------
  35294 //
  35295 //   WebP encoder: main interface
  35296 //
  35297 // Author: Skal (pascal.massimino@gmail.com)
  35298 
  35299 // Copyright 2012 Google Inc. All Rights Reserved.
  35300 //
  35301 // Use of this source code is governed by a BSD-style license
  35302 // that can be found in the COPYING file in the root of the source
  35303 // tree. An additional intellectual property rights grant can be found
  35304 // in the file PATENTS. All contributing project authors may
  35305 // be found in the AUTHORS file in the root of the source tree.
  35306 // -----------------------------------------------------------------------------
  35307 //
  35308 //  Internal header for constants related to WebP file format.
  35309 //
  35310 // Author: Urvang (urvang@google.com)
  35311 
  35312 // Copyright 2010 Google Inc. All Rights Reserved.
  35313 //
  35314 // Use of this source code is governed by a BSD-style license
  35315 // that can be found in the COPYING file in the root of the source
  35316 // tree. An additional intellectual property rights grant can be found
  35317 // in the file PATENTS. All contributing project authors may
  35318 // be found in the AUTHORS file in the root of the source tree.
  35319 // -----------------------------------------------------------------------------
  35320 //
  35321 //  Common types + memory wrappers
  35322 //
  35323 // Author: Skal (pascal.massimino@gmail.com)
  35324 
  35325 // Maximum number of histogram images (sub-blocks).
  35326 // Empirical value for which it becomes too computationally expensive to
  35327 // compute the best predictor image.
  35328 
  35329 // -----------------------------------------------------------------------------
  35330 // Palette
  35331 
  35332 // C documentation
  35333 //
  35334 //	// These five modes are evaluated and their respective entropy is computed.
  35335 type EntropyIx = int32
  35336 
  35337 const kDirect = 0
  35338 const kSpatial = 1
  35339 const kSubGreen = 2
  35340 const kSpatialSubGreen = 3
  35341 const kPalette = 4
  35342 const kPaletteAndSpatial = 5
  35343 const kNumEntropyIx = 6
  35344 
  35345 type HistoIx = int32
  35346 
  35347 const kHistoAlpha = 0
  35348 const kHistoAlphaPred = 1
  35349 const kHistoGreen = 2
  35350 const kHistoGreenPred = 3
  35351 const kHistoRed = 4
  35352 const kHistoRedPred = 5
  35353 const kHistoBlue = 6
  35354 const kHistoBluePred = 7
  35355 const kHistoRedSubGreen = 8
  35356 const kHistoRedPredSubGreen = 9
  35357 const kHistoBlueSubGreen = 10
  35358 const kHistoBluePredSubGreen = 11
  35359 const kHistoPalette = 12
  35360 const kHistoTotal = 13
  35361 
  35362 type HistogramBuckets = [256]uint32_t
  35363 
  35364 // C documentation
  35365 //
  35366 //	// Keeping track of histograms, indexed by HistoIx.
  35367 //	// Ideally, this would just be a struct with meaningful fields, but the
  35368 //	// calculation of `entropy_comp` uses the index. One refactoring at a time :)
  35369 type Histograms = struct {
  35370 	Fcategory [13]HistogramBuckets
  35371 }
  35372 
  35373 func AddSingleSubGreen(tls *libc.TLS, p uint32_t, r uintptr, b uintptr) {
  35374 	var green int32
  35375 	_ = green
  35376 	green = libc.Int32FromUint32(p) >> int32(8) // The upper bits are masked away later.
  35377 	**(**uint32_t)(__ccgo_up(r + uintptr((libc.Int32FromUint32(p)>>int32(16)-green)&int32(0xff))*4)) = **(**uint32_t)(__ccgo_up(r + uintptr((libc.Int32FromUint32(p)>>int32(16)-green)&int32(0xff))*4)) + 1
  35378 	**(**uint32_t)(__ccgo_up(b + uintptr((libc.Int32FromUint32(p)>>0-green)&int32(0xff))*4)) = **(**uint32_t)(__ccgo_up(b + uintptr((libc.Int32FromUint32(p)>>0-green)&int32(0xff))*4)) + 1
  35379 }
  35380 
  35381 func AddSingle(tls *libc.TLS, p uint32_t, a uintptr, r uintptr, g uintptr, b uintptr) {
  35382 	**(**uint32_t)(__ccgo_up(a + uintptr(p>>libc.Int32FromInt32(24)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(a + uintptr(p>>libc.Int32FromInt32(24)&uint32(0xff))*4)) + 1
  35383 	**(**uint32_t)(__ccgo_up(r + uintptr(p>>libc.Int32FromInt32(16)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(r + uintptr(p>>libc.Int32FromInt32(16)&uint32(0xff))*4)) + 1
  35384 	**(**uint32_t)(__ccgo_up(g + uintptr(p>>libc.Int32FromInt32(8)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(g + uintptr(p>>libc.Int32FromInt32(8)&uint32(0xff))*4)) + 1
  35385 	**(**uint32_t)(__ccgo_up(b + uintptr(p>>libc.Int32FromInt32(0)&uint32(0xff))*4)) = **(**uint32_t)(__ccgo_up(b + uintptr(p>>libc.Int32FromInt32(0)&uint32(0xff))*4)) + 1
  35386 }
  35387 
  35388 func HashPix(tls *libc.TLS, pix uint32_t) (r uint8_t) {
  35389 	// Note that masking with 0xffffffffu is for preventing an
  35390 	// 'unsigned int overflow' warning. Doesn't impact the compiled code.
  35391 	return uint8((uint64(pix) + uint64(pix>>libc.Int32FromInt32(19))) * uint64(0x39c5fba7) & uint64(0xffffffff) >> int32(24))
  35392 }
  35393 
  35394 func AnalyzeEntropy(tls *libc.TLS, argb uintptr, width int32, height int32, argb_stride int32, use_palette int32, palette_size int32, transform_bits int32, min_entropy_ix uintptr, red_and_blue_always_zero uintptr) (r int32) {
  35395 	bp := tls.Alloc(48)
  35396 	defer tls.Free(48)
  35397 	var alpha_and_green, pix, pix_diff, pix_prev, red_and_blue, v10, v12, v3, v4, v5, v9 uint32_t
  35398 	var blue_histo, curr_row, histo, prev_row, red_histo, v29 uintptr
  35399 	var entropy_comp [13]uint64_t
  35400 	var hash uint8_t
  35401 	var i, j, k, last_mode_to_analyze, x, y, v7 int32
  35402 	var v18 uint32
  35403 	var _ /* entropy at bp+0 */ [6]uint64_t
  35404 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, blue_histo, curr_row, entropy_comp, hash, histo, i, j, k, last_mode_to_analyze, pix, pix_diff, pix_prev, prev_row, red_and_blue, red_histo, x, y, v10, v12, v18, v29, v3, v4, v5, v7, v9
  35405 	if use_palette != 0 && palette_size <= int32(16) {
  35406 		// In the case of small palettes, we pack 2, 4 or 8 pixels together. In
  35407 		// practice, small palettes are better than any other transform.
  35408 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kPalette)
  35409 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35410 		return int32(1)
  35411 	}
  35412 	histo = WebPSafeCalloc(tls, uint64(1), uint64(13312))
  35413 	if histo != libc.UintptrFromInt32(0) {
  35414 		prev_row = libc.UintptrFromInt32(0)
  35415 		curr_row = argb
  35416 		pix_prev = **(**uint32_t)(__ccgo_up(argb)) // Skip the first pixel.
  35417 		y = 0
  35418 		for {
  35419 			if !(y < height) {
  35420 				break
  35421 			}
  35422 			x = 0
  35423 			for {
  35424 				if !(x < width) {
  35425 					break
  35426 				}
  35427 				pix = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  35428 				v3 = pix
  35429 				v4 = pix_prev
  35430 				alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  35431 				red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  35432 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  35433 				goto _6
  35434 			_6:
  35435 				pix_diff = v5
  35436 				pix_prev = pix
  35437 				if pix_diff == uint32(0) || prev_row != libc.UintptrFromInt32(0) && pix == **(**uint32_t)(__ccgo_up(prev_row + uintptr(x)*4)) {
  35438 					goto _2
  35439 				}
  35440 				AddSingle(tls, pix, histo+uintptr(kHistoAlpha)*1024, histo+uintptr(kHistoRed)*1024, histo+uintptr(kHistoGreen)*1024, histo+uintptr(kHistoBlue)*1024)
  35441 				AddSingle(tls, pix_diff, histo+uintptr(kHistoAlphaPred)*1024, histo+uintptr(kHistoRedPred)*1024, histo+uintptr(kHistoGreenPred)*1024, histo+uintptr(kHistoBluePred)*1024)
  35442 				AddSingleSubGreen(tls, pix, histo+uintptr(kHistoRedSubGreen)*1024, histo+uintptr(kHistoBlueSubGreen)*1024)
  35443 				AddSingleSubGreen(tls, pix_diff, histo+uintptr(kHistoRedPredSubGreen)*1024, histo+uintptr(kHistoBluePredSubGreen)*1024)
  35444 				// Approximate the palette by the entropy of the multiplicative hash.
  35445 				hash = HashPix(tls, pix)
  35446 				**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) + 1
  35447 				goto _2
  35448 			_2:
  35449 				;
  35450 				x = x + 1
  35451 			}
  35452 			prev_row = curr_row
  35453 			curr_row = curr_row + uintptr(argb_stride)*4
  35454 			goto _1
  35455 		_1:
  35456 			;
  35457 			y = y + 1
  35458 		}
  35459 		if use_palette != 0 {
  35460 			v7 = int32(kPalette)
  35461 		} else {
  35462 			v7 = int32(kSpatialSubGreen)
  35463 		}
  35464 		last_mode_to_analyze = v7
  35465 		// Let's add one zero to the predicted histograms. The zeros are removed
  35466 		// too efficiently by the pix_diff == 0 comparison, at least one of the
  35467 		// zeros is likely to exist.
  35468 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) + 1
  35469 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) + 1
  35470 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) + 1
  35471 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) + 1
  35472 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) + 1
  35473 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) + 1
  35474 		j = 0
  35475 		for {
  35476 			if !(j < int32(kHistoTotal)) {
  35477 				break
  35478 			}
  35479 			entropy_comp[j] = VP8LBitsEntropy(tls, histo+uintptr(j)*1024, int32(NUM_BUCKETS))
  35480 			goto _8
  35481 		_8:
  35482 			;
  35483 			j = j + 1
  35484 		}
  35485 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kDirect)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRed)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlue)]
  35486 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatial)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPred)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePred)]
  35487 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSubGreen)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRedSubGreen)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlueSubGreen)]
  35488 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatialSubGreen)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPredSubGreen)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePredSubGreen)]
  35489 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kPalette)] = entropy_comp[int32(kHistoPalette)]
  35490 		// When including transforms, there is an overhead in bits from
  35491 		// storing them. This overhead is small but matters for small images.
  35492 		// For spatial, there are 14 transformations.
  35493 		v3 = libc.Uint32FromInt32(transform_bits)
  35494 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35495 		goto _11
  35496 	_11:
  35497 		v5 = libc.Uint32FromInt32(transform_bits)
  35498 		v9 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35499 		goto _14
  35500 	_14:
  35501 		v10 = uint32(14)
  35502 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35503 			v18 = kLog2Table[v10]
  35504 		} else {
  35505 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35506 		}
  35507 		v12 = v18
  35508 		goto _17
  35509 	_17:
  35510 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatial)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35511 		// For color transforms: 24 as only 3 channels are considered in a
  35512 		// ColorTransformElement.
  35513 		v3 = libc.Uint32FromInt32(transform_bits)
  35514 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35515 		goto _21
  35516 	_21:
  35517 		v5 = libc.Uint32FromInt32(transform_bits)
  35518 		v9 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35519 		goto _24
  35520 	_24:
  35521 		v10 = uint32(24)
  35522 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35523 			v18 = kLog2Table[v10]
  35524 		} else {
  35525 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35526 		}
  35527 		v12 = v18
  35528 		goto _27
  35529 	_27:
  35530 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatialSubGreen)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35531 		// For palettes, add the cost of storing the palette.
  35532 		// We empirically estimate the cost of a compressed entry as 8 bits.
  35533 		// The palette is differential-coded when compressed hence a much
  35534 		// lower cost than sizeof(uint32_t)*8.
  35535 		v29 = bp + uintptr(kPalette)*8
  35536 		*(*uint64_t)(unsafe.Pointer(v29)) = uint64_t(*(*uint64_t)(unsafe.Pointer(v29)) + libc.Uint64FromInt32(palette_size)*libc.Uint64FromUint64(8)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  35537 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kDirect)
  35538 		k = int32(kDirect) + libc.Int32FromInt32(1)
  35539 		for {
  35540 			if !(k <= last_mode_to_analyze) {
  35541 				break
  35542 			}
  35543 			if (**(**[6]uint64_t)(__ccgo_up(bp)))[**(**EntropyIx)(__ccgo_up(min_entropy_ix))] > (**(**[6]uint64_t)(__ccgo_up(bp)))[k] {
  35544 				**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = k
  35545 			}
  35546 			goto _30
  35547 		_30:
  35548 			;
  35549 			k = k + 1
  35550 		}
  35551 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35552 		red_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2)))*1024
  35553 		blue_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2 + 1)))*1024
  35554 		i = int32(1)
  35555 		for {
  35556 			if !(i < int32(NUM_BUCKETS)) {
  35557 				break
  35558 			}
  35559 			if **(**uint32_t)(__ccgo_up(red_histo + uintptr(i)*4))|**(**uint32_t)(__ccgo_up(blue_histo + uintptr(i)*4)) != uint32(0) {
  35560 				**(**int32)(__ccgo_up(red_and_blue_always_zero)) = 0
  35561 				break
  35562 			}
  35563 			goto _31
  35564 		_31:
  35565 			;
  35566 			i = i + 1
  35567 		}
  35568 		WebPSafeFree(tls, histo)
  35569 		return int32(1)
  35570 	} else {
  35571 		return 0
  35572 	}
  35573 	return r
  35574 }
  35575 
  35576 // Let's check if the histogram of the chosen entropy mode has
  35577 // non-zero red and blue values. If all are zero, we can later skip
  35578 // the cross color optimization.
  35579 
  35580 var kHistoPairs = [5][2]uint8_t{
  35581 	0: {
  35582 		0: uint8(kHistoRed),
  35583 		1: uint8(kHistoBlue),
  35584 	},
  35585 	1: {
  35586 		0: uint8(kHistoRedPred),
  35587 		1: uint8(kHistoBluePred),
  35588 	},
  35589 	2: {
  35590 		0: uint8(kHistoRedSubGreen),
  35591 		1: uint8(kHistoBlueSubGreen),
  35592 	},
  35593 	3: {
  35594 		0: uint8(kHistoRedPredSubGreen),
  35595 		1: uint8(kHistoBluePredSubGreen),
  35596 	},
  35597 	4: {
  35598 		0: uint8(kHistoRed),
  35599 		1: uint8(kHistoBlue),
  35600 	},
  35601 }
  35602 
  35603 // C documentation
  35604 //
  35605 //	// Clamp histogram and transform bits.
  35606 func ClampBits(tls *libc.TLS, width int32, height int32, bits int32, min_bits int32, max_bits int32, image_size_max int32) (r int32) {
  35607 	var image_size, v1, v2 int32
  35608 	var v3, v4, v6, v7 uint32_t
  35609 	_, _, _, _, _, _, _ = image_size, v1, v2, v3, v4, v6, v7
  35610 	if bits < min_bits {
  35611 		v1 = min_bits
  35612 	} else {
  35613 		if bits > max_bits {
  35614 			v2 = max_bits
  35615 		} else {
  35616 			v2 = bits
  35617 		}
  35618 		v1 = v2
  35619 	}
  35620 	bits = v1
  35621 	v3 = libc.Uint32FromInt32(bits)
  35622 	v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35623 	goto _5
  35624 _5:
  35625 	v6 = libc.Uint32FromInt32(bits)
  35626 	v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35627 	goto _8
  35628 _8:
  35629 	image_size = libc.Int32FromUint32(v4 * v7)
  35630 	for bits < max_bits && image_size > image_size_max {
  35631 		bits = bits + 1
  35632 		v3 = libc.Uint32FromInt32(bits)
  35633 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35634 		goto _11
  35635 	_11:
  35636 		v6 = libc.Uint32FromInt32(bits)
  35637 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35638 		goto _14
  35639 	_14:
  35640 		image_size = libc.Int32FromUint32(v4 * v7)
  35641 	}
  35642 	// In case the bits reduce the image too much, choose the smallest value
  35643 	// setting the histogram image size to 1.
  35644 	for bits > min_bits && image_size == int32(1) {
  35645 		v3 = libc.Uint32FromInt32(bits - int32(1))
  35646 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35647 		goto _17
  35648 	_17:
  35649 		v6 = libc.Uint32FromInt32(bits - int32(1))
  35650 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35651 		goto _20
  35652 	_20:
  35653 		image_size = libc.Int32FromUint32(v4 * v7)
  35654 		if image_size != int32(1) {
  35655 			break
  35656 		}
  35657 		bits = bits - 1
  35658 	}
  35659 	return bits
  35660 }
  35661 
  35662 func GetHistoBits(tls *libc.TLS, method int32, use_palette int32, width int32, height int32) (r int32) {
  35663 	var histo_bits, v1 int32
  35664 	_, _ = histo_bits, v1
  35665 	if use_palette != 0 {
  35666 		v1 = int32(9)
  35667 	} else {
  35668 		v1 = int32(7)
  35669 	}
  35670 	// Make tile size a function of encoding method (Range: 0 to 6).
  35671 	histo_bits = v1 - method
  35672 	return ClampBits(tls, width, height, histo_bits, int32(MIN_HUFFMAN_BITS), libc.Int32FromInt32(MIN_HUFFMAN_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_HUFFMAN_BITS)-libc.Int32FromInt32(1), int32(MAX_HUFF_IMAGE_SIZE))
  35673 }
  35674 
  35675 func GetTransformBits(tls *libc.TLS, method int32, histo_bits int32) (r int32) {
  35676 	var max_transform_bits, res, v1, v2, v3 int32
  35677 	_, _, _, _, _ = max_transform_bits, res, v1, v2, v3
  35678 	if method < int32(4) {
  35679 		v1 = int32(6)
  35680 	} else {
  35681 		if method > int32(4) {
  35682 			v2 = int32(4)
  35683 		} else {
  35684 			v2 = int32(5)
  35685 		}
  35686 		v1 = v2
  35687 	}
  35688 	max_transform_bits = v1
  35689 	if histo_bits > max_transform_bits {
  35690 		v3 = max_transform_bits
  35691 	} else {
  35692 		v3 = histo_bits
  35693 	}
  35694 	res = v3
  35695 	return res
  35696 }
  35697 
  35698 // C documentation
  35699 //
  35700 //	// Set of parameters to be used in each iteration of the cruncher.
  35701 type CrunchSubConfig = struct {
  35702 	Flz77        int32
  35703 	Fdo_no_cache int32
  35704 }
  35705 
  35706 type CrunchConfig = struct {
  35707 	Fentropy_idx          int32
  35708 	Fpalette_sorting_type PaletteSorting1
  35709 	Fsub_configs          [2]CrunchSubConfig
  35710 	Fsub_configs_size     int32
  35711 }
  35712 
  35713 // +2 because we add a palette sorting configuration for kPalette and
  35714 // kPaletteAndSpatial.
  35715 
  35716 func EncoderAnalyze(tls *libc.TLS, enc uintptr, crunch_configs uintptr, crunch_configs_size uintptr, red_and_blue_always_zero uintptr) (r int32) {
  35717 	bp := tls.Alloc(16)
  35718 	defer tls.Free(16)
  35719 	var config, pic uintptr
  35720 	var do_no_cache, height, i, j, low_effort, method, n_lz77s, sorting_method, transform_bits, use_palette, width, v1 int32
  35721 	var typed_sorting_method PaletteSorting1
  35722 	var _ /* min_entropy_ix at bp+0 */ EntropyIx
  35723 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = config, do_no_cache, height, i, j, low_effort, method, n_lz77s, pic, sorting_method, transform_bits, typed_sorting_method, use_palette, width, v1
  35724 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  35725 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  35726 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  35727 	config = (*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig
  35728 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  35729 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  35730 	// If set to 0, analyze the cache with the computed cache value. If 1, also
  35731 	// analyze with no-cache.
  35732 	do_no_cache = 0
  35733 	// Check whether a palette is possible.
  35734 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = GetColorPalette(tls, pic, enc+1128)
  35735 	use_palette = libc.BoolInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(MAX_PALETTE_SIZE))
  35736 	if !(use_palette != 0) {
  35737 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = 0
  35738 	}
  35739 	// Empirical bit sizes.
  35740 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits = GetHistoBits(tls, method, use_palette, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight)
  35741 	transform_bits = GetTransformBits(tls, method, (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits)
  35742 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpredictor_transform_bits = transform_bits
  35743 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits = transform_bits
  35744 	if low_effort != 0 {
  35745 		// AnalyzeEntropy is somewhat slow.
  35746 		if use_palette != 0 {
  35747 			v1 = int32(kPalette)
  35748 		} else {
  35749 			v1 = int32(kSpatialSubGreen)
  35750 		}
  35751 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = v1
  35752 		if use_palette != 0 {
  35753 			v1 = int32(kSortedDefault)
  35754 		} else {
  35755 			v1 = int32(kUnusedPalette)
  35756 		}
  35757 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  35758 		n_lz77s = int32(1)
  35759 		**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  35760 	} else {
  35761 		// Try out multiple LZ77 on images with few colors.
  35762 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size > 0 && (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(16) {
  35763 			v1 = int32(2)
  35764 		} else {
  35765 			v1 = int32(1)
  35766 		}
  35767 		n_lz77s = v1
  35768 		if !(AnalyzeEntropy(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb, width, height, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, use_palette, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size, transform_bits, bp, red_and_blue_always_zero) != 0) {
  35769 			return 0
  35770 		}
  35771 		if method == int32(6) && (*WebPConfig)(unsafe.Pointer(config)).Fquality == libc.Float32FromInt32(100) {
  35772 			do_no_cache = int32(1)
  35773 			// Go brute force on all transforms.
  35774 			**(**int32)(__ccgo_up(crunch_configs_size)) = 0
  35775 			i = 0
  35776 			for {
  35777 				if !(i < int32(kNumEntropyIx)) {
  35778 					break
  35779 				}
  35780 				// We can only apply kPalette or kPaletteAndSpatial if we can indeed use
  35781 				// a palette.
  35782 				if i != int32(kPalette) && i != int32(kPaletteAndSpatial) || use_palette != 0 {
  35783 					if use_palette != 0 && (i == int32(kPalette) || i == int32(kPaletteAndSpatial)) {
  35784 						sorting_method = 0
  35785 						for {
  35786 							if !(sorting_method < int32(kPaletteSortingNum)) {
  35787 								break
  35788 							}
  35789 							typed_sorting_method = sorting_method
  35790 							// TODO(vrabaud) kSortedDefault should be tested. It is omitted
  35791 							// for now for backward compatibility.
  35792 							if typed_sorting_method == int32(kUnusedPalette) || typed_sorting_method == int32(kSortedDefault) {
  35793 								goto _5
  35794 							}
  35795 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  35796 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = typed_sorting_method
  35797 							**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  35798 							goto _5
  35799 						_5:
  35800 							;
  35801 							sorting_method = sorting_method + 1
  35802 						}
  35803 					} else {
  35804 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  35805 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = int32(kUnusedPalette)
  35806 						**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  35807 					}
  35808 				}
  35809 				goto _4
  35810 			_4:
  35811 				;
  35812 				i = i + 1
  35813 			}
  35814 		} else {
  35815 			// Only choose the guessed best transform.
  35816 			**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  35817 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = **(**EntropyIx)(__ccgo_up(bp))
  35818 			if use_palette != 0 {
  35819 				v1 = int32(kMinimizeDelta)
  35820 			} else {
  35821 				v1 = int32(kUnusedPalette)
  35822 			}
  35823 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  35824 			if (*WebPConfig)(unsafe.Pointer(config)).Fquality >= libc.Float32FromInt32(75) && method == int32(5) {
  35825 				// Test with and without color cache.
  35826 				do_no_cache = int32(1)
  35827 				// If we have a palette, also check in combination with spatial.
  35828 				if **(**EntropyIx)(__ccgo_up(bp)) == int32(kPalette) {
  35829 					**(**int32)(__ccgo_up(crunch_configs_size)) = int32(2)
  35830 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fentropy_idx = int32(kPaletteAndSpatial)
  35831 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fpalette_sorting_type = int32(kMinimizeDelta)
  35832 				}
  35833 			}
  35834 		}
  35835 	}
  35836 	// Fill in the different LZ77s.
  35837 	i = 0
  35838 	for {
  35839 		if !(i < **(**int32)(__ccgo_up(crunch_configs_size))) {
  35840 			break
  35841 		}
  35842 		j = 0
  35843 		for {
  35844 			if !(j < n_lz77s) {
  35845 				break
  35846 			}
  35847 			if j == 0 {
  35848 				v1 = int32(kLZ77Standard) | int32(kLZ77RLE)
  35849 			} else {
  35850 				v1 = int32(kLZ77Box)
  35851 			}
  35852 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Flz77 = v1
  35853 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Fdo_no_cache = do_no_cache
  35854 			goto _8
  35855 		_8:
  35856 			;
  35857 			j = j + 1
  35858 		}
  35859 		(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(i)*28))).Fsub_configs_size = n_lz77s
  35860 		goto _7
  35861 	_7:
  35862 		;
  35863 		i = i + 1
  35864 	}
  35865 	return int32(1)
  35866 }
  35867 
  35868 func EncoderInit(tls *libc.TLS, enc uintptr) (r int32) {
  35869 	var height, i, pix_cnt, refs_block_size, width int32
  35870 	var pic uintptr
  35871 	_, _, _, _, _, _ = height, i, pic, pix_cnt, refs_block_size, width
  35872 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  35873 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  35874 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  35875 	pix_cnt = width * height
  35876 	// we round the block size up, so we're guaranteed to have
  35877 	// at most MAX_REFS_BLOCK_PER_IMAGE blocks used:
  35878 	refs_block_size = (pix_cnt-int32(1))/int32(MAX_REFS_BLOCK_PER_IMAGE) + int32(1)
  35879 	if !(VP8LHashChainInit(tls, enc+2312, pix_cnt) != 0) {
  35880 		return 0
  35881 	}
  35882 	i = 0
  35883 	for {
  35884 		if !(i < int32(4)) {
  35885 			break
  35886 		}
  35887 		VP8LBackwardRefsInit(tls, enc+2152+uintptr(i)*40, refs_block_size)
  35888 		goto _1
  35889 	_1:
  35890 		;
  35891 		i = i + 1
  35892 	}
  35893 	return int32(1)
  35894 }
  35895 
  35896 // C documentation
  35897 //
  35898 //	// Returns false in case of memory error.
  35899 func GetHuffBitLengthsAndCodes(tls *libc.TLS, histogram_image uintptr, huffman_codes uintptr) (r int32) {
  35900 	var bit_length, histogram_image_size, i, k, max_num_symbols, num_symbols, ok, v3, v4, v5, v7, v8 int32
  35901 	var buf_rle, codes, codes1, codes2, histo, histo1, huff_tree, lengths, mem_buf uintptr
  35902 	var total_length_size uint64_t
  35903 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit_length, buf_rle, codes, codes1, codes2, histo, histo1, histogram_image_size, huff_tree, i, k, lengths, max_num_symbols, mem_buf, num_symbols, ok, total_length_size, v3, v4, v5, v7, v8
  35904 	ok = 0
  35905 	total_length_size = uint64(0)
  35906 	mem_buf = libc.UintptrFromInt32(0)
  35907 	histogram_image_size = (*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize
  35908 	max_num_symbols = 0
  35909 	buf_rle = libc.UintptrFromInt32(0)
  35910 	huff_tree = libc.UintptrFromInt32(0)
  35911 	// Iterate over all histograms and get the aggregate number of codes used.
  35912 	i = 0
  35913 	for {
  35914 		if !(i < histogram_image_size) {
  35915 			break
  35916 		}
  35917 		histo = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  35918 		codes = huffman_codes + uintptr(int32(5)*i)*24
  35919 		k = 0
  35920 		for {
  35921 			if !(k < int32(5)) {
  35922 				break
  35923 			}
  35924 			if k == 0 {
  35925 				v4 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  35926 				if v4 > 0 {
  35927 					v7 = int32(1) << v4
  35928 				} else {
  35929 					v7 = 0
  35930 				}
  35931 				v5 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v7
  35932 				goto _6
  35933 			_6:
  35934 				v3 = v5
  35935 			} else {
  35936 				if k == int32(4) {
  35937 					v8 = int32(NUM_DISTANCE_CODES)
  35938 				} else {
  35939 					v8 = int32(256)
  35940 				}
  35941 				v3 = v8
  35942 			}
  35943 			num_symbols = v3
  35944 			(**(**HuffmanTreeCode)(__ccgo_up(codes + uintptr(k)*24))).Fnum_symbols = num_symbols
  35945 			total_length_size = total_length_size + libc.Uint64FromInt32(num_symbols)
  35946 			goto _2
  35947 		_2:
  35948 			;
  35949 			k = k + 1
  35950 		}
  35951 		goto _1
  35952 	_1:
  35953 		;
  35954 		i = i + 1
  35955 	}
  35956 	// Allocate and Set Huffman codes.
  35957 	mem_buf = WebPSafeCalloc(tls, total_length_size, libc.Uint64FromInt64(1)+libc.Uint64FromInt64(2))
  35958 	if mem_buf == libc.UintptrFromInt32(0) {
  35959 		goto End
  35960 	}
  35961 	codes1 = mem_buf
  35962 	lengths = codes1 + uintptr(total_length_size)*2
  35963 	i = 0
  35964 	for {
  35965 		if !(i < int32(5)*histogram_image_size) {
  35966 			break
  35967 		}
  35968 		bit_length = (**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fnum_symbols
  35969 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcodes = codes1
  35970 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcode_lengths = lengths
  35971 		codes1 = codes1 + uintptr(bit_length)*2
  35972 		lengths = lengths + uintptr(bit_length)
  35973 		if max_num_symbols < bit_length {
  35974 			max_num_symbols = bit_length
  35975 		}
  35976 		goto _9
  35977 	_9:
  35978 		;
  35979 		i = i + 1
  35980 	}
  35981 	buf_rle = WebPSafeMalloc(tls, uint64(1), libc.Uint64FromInt32(max_num_symbols))
  35982 	huff_tree = WebPSafeMalloc(tls, uint64(uint64(3)*libc.Uint64FromInt32(max_num_symbols)), uint64(16))
  35983 	if buf_rle == libc.UintptrFromInt32(0) || huff_tree == libc.UintptrFromInt32(0) {
  35984 		goto End
  35985 	}
  35986 	// Create Huffman trees.
  35987 	i = 0
  35988 	for {
  35989 		if !(i < histogram_image_size) {
  35990 			break
  35991 		}
  35992 		codes2 = huffman_codes + uintptr(int32(5)*i)*24
  35993 		histo1 = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  35994 		VP8LCreateHuffmanTree(tls, (*VP8LHistogram)(unsafe.Pointer(histo1)).Fliteral, int32(15), buf_rle, huff_tree, codes2+uintptr(0)*24)
  35995 		VP8LCreateHuffmanTree(tls, histo1+8, int32(15), buf_rle, huff_tree, codes2+uintptr(1)*24)
  35996 		VP8LCreateHuffmanTree(tls, histo1+1032, int32(15), buf_rle, huff_tree, codes2+uintptr(2)*24)
  35997 		VP8LCreateHuffmanTree(tls, histo1+2056, int32(15), buf_rle, huff_tree, codes2+uintptr(3)*24)
  35998 		VP8LCreateHuffmanTree(tls, histo1+3080, int32(15), buf_rle, huff_tree, codes2+uintptr(4)*24)
  35999 		goto _10
  36000 	_10:
  36001 		;
  36002 		i = i + 1
  36003 	}
  36004 	ok = int32(1)
  36005 	goto End
  36006 End:
  36007 	;
  36008 	WebPSafeFree(tls, huff_tree)
  36009 	WebPSafeFree(tls, buf_rle)
  36010 	if !(ok != 0) {
  36011 		WebPSafeFree(tls, mem_buf)
  36012 		libc.Xmemset(tls, huffman_codes, 0, libc.Uint64FromInt32(int32(5)*histogram_image_size)*uint64(24))
  36013 	}
  36014 	return ok
  36015 }
  36016 
  36017 func StoreHuffmanTreeOfHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, code_length_bitdepth uintptr) {
  36018 	var codes_to_store, i, v4 int32
  36019 	var v2 uintptr
  36020 	var v3 uint32_t
  36021 	_, _, _, _, _ = codes_to_store, i, v2, v3, v4
  36022 	// Throw away trailing zeros:
  36023 	codes_to_store = int32(CODE_LENGTH_CODES)
  36024 	for {
  36025 		if !(codes_to_store > int32(4)) {
  36026 			break
  36027 		}
  36028 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[codes_to_store-int32(1)])))) != 0 {
  36029 			break
  36030 		}
  36031 		goto _1
  36032 	_1:
  36033 		;
  36034 		codes_to_store = codes_to_store - 1
  36035 	}
  36036 	v2 = bw1
  36037 	v3 = libc.Uint32FromInt32(codes_to_store - int32(4))
  36038 	v4 = int32(4)
  36039 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36040 		if v4 > libc.Int32FromInt32(0) {
  36041 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36042 				VP8LPutBitsFlushBits(tls, v2)
  36043 			}
  36044 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36045 			**(**int32)(__ccgo_up(v2 + 8)) += v4
  36046 		}
  36047 	} else {
  36048 		VP8LPutBitsInternal(tls, v2, v3, v4)
  36049 	}
  36050 	i = 0
  36051 	for {
  36052 		if !(i < codes_to_store) {
  36053 			break
  36054 		}
  36055 		v2 = bw1
  36056 		v3 = uint32(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[i]))))
  36057 		v4 = int32(3)
  36058 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36059 			if v4 > libc.Int32FromInt32(0) {
  36060 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36061 					VP8LPutBitsFlushBits(tls, v2)
  36062 				}
  36063 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36064 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36065 			}
  36066 		} else {
  36067 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36068 		}
  36069 		goto _5
  36070 	_5:
  36071 		;
  36072 		i = i + 1
  36073 	}
  36074 }
  36075 
  36076 // RFC 1951 will calm you down if you are worried about this funny sequence.
  36077 // This sequence is tuned from that, but more weighted for lower symbol count,
  36078 // and more spiking histograms.
  36079 var kStorageOrder = [19]uint8_t{
  36080 	0:  uint8(17),
  36081 	1:  uint8(18),
  36082 	3:  uint8(1),
  36083 	4:  uint8(2),
  36084 	5:  uint8(3),
  36085 	6:  uint8(4),
  36086 	7:  uint8(5),
  36087 	8:  uint8(16),
  36088 	9:  uint8(6),
  36089 	10: uint8(7),
  36090 	11: uint8(8),
  36091 	12: uint8(9),
  36092 	13: uint8(10),
  36093 	14: uint8(11),
  36094 	15: uint8(12),
  36095 	16: uint8(13),
  36096 	17: uint8(14),
  36097 	18: uint8(15),
  36098 }
  36099 
  36100 func ClearHuffmanTreeIfOnlyOneSymbol(tls *libc.TLS, huffman_code uintptr) {
  36101 	var count, k int32
  36102 	_, _ = count, k
  36103 	count = 0
  36104 	k = 0
  36105 	for {
  36106 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36107 			break
  36108 		}
  36109 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k)))) != 0 {
  36110 			count = count + 1
  36111 			if count > int32(1) {
  36112 				return
  36113 			}
  36114 		}
  36115 		goto _1
  36116 	_1:
  36117 		;
  36118 		k = k + 1
  36119 	}
  36120 	k = 0
  36121 	for {
  36122 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36123 			break
  36124 		}
  36125 		**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k))) = uint8(0)
  36126 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(k)*2)) = uint16(0)
  36127 		goto _2
  36128 	_2:
  36129 		;
  36130 		k = k + 1
  36131 	}
  36132 }
  36133 
  36134 func StoreHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, tokens uintptr, num_tokens int32, huffman_code uintptr) {
  36135 	var extra_bits, i, ix, v4 int32
  36136 	var v2 uintptr
  36137 	var v3 uint32_t
  36138 	_, _, _, _, _, _ = extra_bits, i, ix, v2, v3, v4
  36139 	i = 0
  36140 	for {
  36141 		if !(i < num_tokens) {
  36142 			break
  36143 		}
  36144 		ix = libc.Int32FromUint8((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fcode)
  36145 		extra_bits = libc.Int32FromUint8((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fextra_bits)
  36146 		v2 = bw1
  36147 		v3 = uint32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(ix)*2)))
  36148 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(ix))))
  36149 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36150 			if v4 > libc.Int32FromInt32(0) {
  36151 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36152 					VP8LPutBitsFlushBits(tls, v2)
  36153 				}
  36154 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36155 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36156 			}
  36157 		} else {
  36158 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36159 		}
  36160 		switch ix {
  36161 		case int32(16):
  36162 			v2 = bw1
  36163 			v3 = libc.Uint32FromInt32(extra_bits)
  36164 			v4 = int32(2)
  36165 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36166 				if v4 > libc.Int32FromInt32(0) {
  36167 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36168 						VP8LPutBitsFlushBits(tls, v2)
  36169 					}
  36170 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36171 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36172 				}
  36173 			} else {
  36174 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36175 			}
  36176 		case int32(17):
  36177 			v2 = bw1
  36178 			v3 = libc.Uint32FromInt32(extra_bits)
  36179 			v4 = int32(3)
  36180 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36181 				if v4 > libc.Int32FromInt32(0) {
  36182 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36183 						VP8LPutBitsFlushBits(tls, v2)
  36184 					}
  36185 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36186 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36187 				}
  36188 			} else {
  36189 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36190 			}
  36191 		case int32(18):
  36192 			v2 = bw1
  36193 			v3 = libc.Uint32FromInt32(extra_bits)
  36194 			v4 = int32(7)
  36195 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36196 				if v4 > libc.Int32FromInt32(0) {
  36197 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36198 						VP8LPutBitsFlushBits(tls, v2)
  36199 					}
  36200 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36201 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36202 				}
  36203 			} else {
  36204 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36205 			}
  36206 			break
  36207 		}
  36208 		goto _1
  36209 	_1:
  36210 		;
  36211 		i = i + 1
  36212 	}
  36213 }
  36214 
  36215 // C documentation
  36216 //
  36217 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36218 func StoreFullHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, tree uintptr) {
  36219 	bp := tls.Alloc(192)
  36220 	defer tls.Free(192)
  36221 	var i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v3 int32
  36222 	var v1 uintptr
  36223 	var v2 uint32_t
  36224 	var _ /* buf_rle at bp+164 */ [19]uint8_t
  36225 	var _ /* code_length_bitdepth at bp+0 */ [19]uint8_t
  36226 	var _ /* code_length_bitdepth_symbols at bp+20 */ [19]uint16_t
  36227 	var _ /* histogram at bp+88 */ [19]uint32_t
  36228 	var _ /* huffman_code at bp+64 */ HuffmanTreeCode
  36229 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v1, v2, v3
  36230 	**(**[19]uint8_t)(__ccgo_up(bp)) = [19]uint8_t{}
  36231 	**(**[19]uint16_t)(__ccgo_up(bp + 20)) = [19]uint16_t{}
  36232 	max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  36233 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fnum_symbols = int32(CODE_LENGTH_CODES)
  36234 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcode_lengths = bp
  36235 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcodes = bp + 20
  36236 	v1 = bw1
  36237 	v2 = uint32(0)
  36238 	v3 = int32(1)
  36239 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36240 		if v3 > libc.Int32FromInt32(0) {
  36241 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36242 				VP8LPutBitsFlushBits(tls, v1)
  36243 			}
  36244 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36245 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36246 		}
  36247 	} else {
  36248 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36249 	}
  36250 	num_tokens = VP8LCreateCompressedHuffmanTree(tls, tree, tokens, max_tokens)
  36251 	**(**[19]uint32_t)(__ccgo_up(bp + 88)) = [19]uint32_t{}
  36252 	**(**[19]uint8_t)(__ccgo_up(bp + 164)) = [19]uint8_t{}
  36253 	i = 0
  36254 	for {
  36255 		if !(i < num_tokens) {
  36256 			break
  36257 		}
  36258 		(**(**[19]uint32_t)(__ccgo_up(bp + 88)))[(**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fcode] = (**(**[19]uint32_t)(__ccgo_up(bp + 88)))[(**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fcode] + 1
  36259 		goto _4
  36260 	_4:
  36261 		;
  36262 		i = i + 1
  36263 	}
  36264 	VP8LCreateHuffmanTree(tls, bp+88, int32(7), bp+164, huff_tree, bp+64)
  36265 	StoreHuffmanTreeOfHuffmanTreeToBitMask(tls, bw1, bp)
  36266 	ClearHuffmanTreeIfOnlyOneSymbol(tls, bp+64)
  36267 	trailing_zero_bits = 0
  36268 	trimmed_length = num_tokens
  36269 	i1 = num_tokens
  36270 	for {
  36271 		v3 = i1
  36272 		i1 = i1 - 1
  36273 		if !(v3 > 0) {
  36274 			break
  36275 		}
  36276 		ix = libc.Int32FromUint8((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i1)*2))).Fcode)
  36277 		if ix == 0 || ix == int32(17) || ix == int32(18) {
  36278 			trimmed_length = trimmed_length - 1 // discount trailing zeros
  36279 			trailing_zero_bits = trailing_zero_bits + libc.Int32FromUint8((**(**[19]uint8_t)(__ccgo_up(bp)))[ix])
  36280 			if ix == int32(17) {
  36281 				trailing_zero_bits = trailing_zero_bits + int32(3)
  36282 			} else {
  36283 				if ix == int32(18) {
  36284 					trailing_zero_bits = trailing_zero_bits + int32(7)
  36285 				}
  36286 			}
  36287 		} else {
  36288 			break
  36289 		}
  36290 	}
  36291 	write_trimmed_length = libc.BoolInt32(trimmed_length > int32(1) && trailing_zero_bits > int32(12))
  36292 	if write_trimmed_length != 0 {
  36293 		v3 = trimmed_length
  36294 	} else {
  36295 		v3 = num_tokens
  36296 	}
  36297 	length = v3
  36298 	v1 = bw1
  36299 	v2 = libc.Uint32FromInt32(write_trimmed_length)
  36300 	v3 = int32(1)
  36301 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36302 		if v3 > libc.Int32FromInt32(0) {
  36303 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36304 				VP8LPutBitsFlushBits(tls, v1)
  36305 			}
  36306 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36307 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36308 		}
  36309 	} else {
  36310 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36311 	}
  36312 	if write_trimmed_length != 0 {
  36313 		if trimmed_length == int32(2) {
  36314 			v1 = bw1
  36315 			v2 = uint32(0)
  36316 			v3 = libc.Int32FromInt32(3) + libc.Int32FromInt32(2)
  36317 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36318 				if v3 > libc.Int32FromInt32(0) {
  36319 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36320 						VP8LPutBitsFlushBits(tls, v1)
  36321 					}
  36322 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36323 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36324 				}
  36325 			} else {
  36326 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36327 			} // nbitpairs=1, trimmed_length=2
  36328 		} else {
  36329 			v3 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(trimmed_length-int32(2)))
  36330 			goto _14
  36331 		_14:
  36332 			nbits = v3
  36333 			nbitpairs = nbits/int32(2) + int32(1)
  36334 			v1 = bw1
  36335 			v2 = libc.Uint32FromInt32(nbitpairs - int32(1))
  36336 			v3 = int32(3)
  36337 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36338 				if v3 > libc.Int32FromInt32(0) {
  36339 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36340 						VP8LPutBitsFlushBits(tls, v1)
  36341 					}
  36342 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36343 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36344 				}
  36345 			} else {
  36346 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36347 			}
  36348 			v1 = bw1
  36349 			v2 = libc.Uint32FromInt32(trimmed_length - int32(2))
  36350 			v3 = nbitpairs * int32(2)
  36351 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36352 				if v3 > libc.Int32FromInt32(0) {
  36353 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36354 						VP8LPutBitsFlushBits(tls, v1)
  36355 					}
  36356 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36357 					**(**int32)(__ccgo_up(v1 + 8)) += v3
  36358 				}
  36359 			} else {
  36360 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36361 			}
  36362 		}
  36363 	}
  36364 	StoreHuffmanTreeToBitMask(tls, bw1, tokens, length, bp+64)
  36365 }
  36366 
  36367 // C documentation
  36368 //
  36369 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36370 func StoreHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, huffman_code uintptr) {
  36371 	var count, i, kMaxBits, kMaxSymbol, v4 int32
  36372 	var symbols [2]int32
  36373 	var v2 uintptr
  36374 	var v3 uint32_t
  36375 	_, _, _, _, _, _, _, _ = count, i, kMaxBits, kMaxSymbol, symbols, v2, v3, v4
  36376 	count = 0
  36377 	symbols = [2]int32{}
  36378 	kMaxBits = int32(8)
  36379 	kMaxSymbol = int32(1) << kMaxBits
  36380 	// Check whether it's a small tree.
  36381 	i = 0
  36382 	for {
  36383 		if !(i < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols && count < int32(3)) {
  36384 			break
  36385 		}
  36386 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(i)))) != 0 {
  36387 			if count < int32(2) {
  36388 				symbols[count] = i
  36389 			}
  36390 			count = count + 1
  36391 		}
  36392 		goto _1
  36393 	_1:
  36394 		;
  36395 		i = i + 1
  36396 	}
  36397 	if count == 0 { // emit minimal tree for empty cases
  36398 		// bits: small tree marker: 1, count-1: 0, large 8-bit code: 0, code: 0
  36399 		v2 = bw1
  36400 		v3 = uint32(0x01)
  36401 		v4 = int32(4)
  36402 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36403 			if v4 > libc.Int32FromInt32(0) {
  36404 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36405 					VP8LPutBitsFlushBits(tls, v2)
  36406 				}
  36407 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36408 				**(**int32)(__ccgo_up(v2 + 8)) += v4
  36409 			}
  36410 		} else {
  36411 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36412 		}
  36413 	} else {
  36414 		if count <= int32(2) && symbols[0] < kMaxSymbol && symbols[int32(1)] < kMaxSymbol {
  36415 			v2 = bw1
  36416 			v3 = uint32(1)
  36417 			v4 = int32(1)
  36418 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36419 				if v4 > libc.Int32FromInt32(0) {
  36420 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36421 						VP8LPutBitsFlushBits(tls, v2)
  36422 					}
  36423 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36424 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36425 				}
  36426 			} else {
  36427 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36428 			} // Small tree marker to encode 1 or 2 symbols.
  36429 			v2 = bw1
  36430 			v3 = libc.Uint32FromInt32(count - int32(1))
  36431 			v4 = int32(1)
  36432 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36433 				if v4 > libc.Int32FromInt32(0) {
  36434 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36435 						VP8LPutBitsFlushBits(tls, v2)
  36436 					}
  36437 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36438 					**(**int32)(__ccgo_up(v2 + 8)) += v4
  36439 				}
  36440 			} else {
  36441 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36442 			}
  36443 			if symbols[0] <= int32(1) {
  36444 				v2 = bw1
  36445 				v3 = uint32(0)
  36446 				v4 = int32(1)
  36447 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36448 					if v4 > libc.Int32FromInt32(0) {
  36449 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36450 							VP8LPutBitsFlushBits(tls, v2)
  36451 						}
  36452 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36453 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36454 					}
  36455 				} else {
  36456 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36457 				} // Code bit for small (1 bit) symbol value.
  36458 				v2 = bw1
  36459 				v3 = libc.Uint32FromInt32(symbols[0])
  36460 				v4 = int32(1)
  36461 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36462 					if v4 > libc.Int32FromInt32(0) {
  36463 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36464 							VP8LPutBitsFlushBits(tls, v2)
  36465 						}
  36466 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36467 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36468 					}
  36469 				} else {
  36470 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36471 				}
  36472 			} else {
  36473 				v2 = bw1
  36474 				v3 = uint32(1)
  36475 				v4 = int32(1)
  36476 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36477 					if v4 > libc.Int32FromInt32(0) {
  36478 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36479 							VP8LPutBitsFlushBits(tls, v2)
  36480 						}
  36481 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36482 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36483 					}
  36484 				} else {
  36485 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36486 				}
  36487 				v2 = bw1
  36488 				v3 = libc.Uint32FromInt32(symbols[0])
  36489 				v4 = int32(8)
  36490 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36491 					if v4 > libc.Int32FromInt32(0) {
  36492 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36493 							VP8LPutBitsFlushBits(tls, v2)
  36494 						}
  36495 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36496 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36497 					}
  36498 				} else {
  36499 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36500 				}
  36501 			}
  36502 			if count == int32(2) {
  36503 				v2 = bw1
  36504 				v3 = libc.Uint32FromInt32(symbols[int32(1)])
  36505 				v4 = int32(8)
  36506 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36507 					if v4 > libc.Int32FromInt32(0) {
  36508 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36509 							VP8LPutBitsFlushBits(tls, v2)
  36510 						}
  36511 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36512 						**(**int32)(__ccgo_up(v2 + 8)) += v4
  36513 					}
  36514 				} else {
  36515 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36516 				}
  36517 			}
  36518 		} else {
  36519 			StoreFullHuffmanCode(tls, bw1, huff_tree, tokens, huffman_code)
  36520 		}
  36521 	}
  36522 }
  36523 
  36524 func WriteHuffmanCode(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32) {
  36525 	var depth, symbol, v3 int32
  36526 	var v1 uintptr
  36527 	var v2 uint32_t
  36528 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36529 	depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36530 	symbol = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36531 	v1 = bw1
  36532 	v2 = libc.Uint32FromInt32(symbol)
  36533 	v3 = depth
  36534 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36535 		if v3 > libc.Int32FromInt32(0) {
  36536 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36537 				VP8LPutBitsFlushBits(tls, v1)
  36538 			}
  36539 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36540 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36541 		}
  36542 	} else {
  36543 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36544 	}
  36545 }
  36546 
  36547 func WriteHuffmanCodeWithExtraBits(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32, bits1 int32, n_bits1 int32) {
  36548 	var depth, symbol, v3 int32
  36549 	var v1 uintptr
  36550 	var v2 uint32_t
  36551 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36552 	depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36553 	symbol = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36554 	v1 = bw1
  36555 	v2 = libc.Uint32FromInt32(bits1<<depth | symbol)
  36556 	v3 = depth + n_bits1
  36557 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36558 		if v3 > libc.Int32FromInt32(0) {
  36559 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36560 				VP8LPutBitsFlushBits(tls, v1)
  36561 			}
  36562 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36563 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36564 		}
  36565 	} else {
  36566 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36567 	}
  36568 }
  36569 
  36570 func StoreImageToBitMask(tls *libc.TLS, bw1 uintptr, width int32, histo_bits int32, refs uintptr, histogram_symbols uintptr, huffman_codes uintptr, pic uintptr) (r int32) {
  36571 	bp := tls.Alloc(48)
  36572 	defer tls.Free(48)
  36573 	var code2, code3, distance2, highest_bit, histo_xsize, histogram_ix, k, literal_ix, second_highest_bit, tile_mask, tile_x, tile_y, x, y, v13, v5, v6, v8 int32
  36574 	var codes, v, v20, v21, v22, v24 uintptr
  36575 	var prefix_code VP8LPrefixCode
  36576 	var v1 uint32
  36577 	var v2, v3 uint32_t
  36578 	var _ /* bits at bp+24 */ int32
  36579 	var _ /* c at bp+0 */ VP8LRefsCursor
  36580 	var _ /* code at bp+32 */ int32
  36581 	var _ /* n_bits at bp+28 */ int32
  36582 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = code2, code3, codes, distance2, highest_bit, histo_xsize, histogram_ix, k, literal_ix, prefix_code, second_highest_bit, tile_mask, tile_x, tile_y, v, x, y, v1, v13, v2, v20, v21, v22, v24, v3, v5, v6, v8
  36583 	if histo_bits != 0 {
  36584 		v2 = libc.Uint32FromInt32(histo_bits)
  36585 		v3 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  36586 		goto _4
  36587 	_4:
  36588 		v1 = v3
  36589 	} else {
  36590 		v1 = uint32(1)
  36591 	}
  36592 	histo_xsize = libc.Int32FromUint32(v1)
  36593 	if histo_bits == 0 {
  36594 		v5 = 0
  36595 	} else {
  36596 		v5 = -(int32(1) << histo_bits)
  36597 	}
  36598 	tile_mask = v5
  36599 	// x and y trace the position in the image.
  36600 	x = 0
  36601 	y = 0
  36602 	tile_x = x & tile_mask
  36603 	tile_y = y & tile_mask
  36604 	histogram_ix = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(histogram_symbols)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36605 	codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36606 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  36607 	for {
  36608 		v6 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  36609 		goto _7
  36610 	_7:
  36611 		if !(v6 != 0) {
  36612 			break
  36613 		}
  36614 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  36615 		if tile_x != x&tile_mask || tile_y != y&tile_mask {
  36616 			tile_x = x & tile_mask
  36617 			tile_y = y & tile_mask
  36618 			histogram_ix = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(histogram_symbols + uintptr(y>>histo_bits*histo_xsize+x>>histo_bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36619 			codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36620 		}
  36621 		v5 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  36622 		goto _9
  36623 	_9:
  36624 		if v5 != 0 {
  36625 			k = 0
  36626 			for {
  36627 				if !(k < int32(4)) {
  36628 					break
  36629 				}
  36630 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (libc.Int32FromUint8(order[k]) * libc.Int32FromInt32(8)) & uint32(0xff)
  36631 				goto _12
  36632 			_12:
  36633 				code2 = libc.Int32FromUint32(v2)
  36634 				WriteHuffmanCode(tls, bw1, codes+uintptr(k)*24, code2)
  36635 				goto _10
  36636 			_10:
  36637 				;
  36638 				k = k + 1
  36639 			}
  36640 		} else {
  36641 			v5 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  36642 			goto _14
  36643 		_14:
  36644 			if v5 != 0 {
  36645 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36646 				goto _16
  36647 			_16:
  36648 				code3 = libc.Int32FromUint32(v2)
  36649 				literal_ix = libc.Int32FromInt32(256) + libc.Int32FromInt32(NUM_LENGTH_CODES) + code3
  36650 				WriteHuffmanCode(tls, bw1, codes, literal_ix)
  36651 			} else {
  36652 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36653 				goto _18
  36654 			_18:
  36655 				distance2 = libc.Int32FromUint32(v2)
  36656 				v5 = libc.Int32FromUint16((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  36657 				v20 = bp + 32
  36658 				v21 = bp + 28
  36659 				v22 = bp + 24
  36660 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36661 					prefix_code = kPrefixEncodeCode[v5]
  36662 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36663 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36664 					**(**int32)(__ccgo_up(v22)) = libc.Int32FromUint8(kPrefixEncodeExtraBitsValue[v5])
  36665 				} else {
  36666 					v6 = v5
  36667 					v24 = v21
  36668 					v6 = v6 - 1
  36669 					v8 = v6
  36670 					v13 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v8))
  36671 					goto _27
  36672 				_27:
  36673 					highest_bit = v13
  36674 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36675 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36676 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36677 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36678 				}
  36679 				WriteHuffmanCodeWithExtraBits(tls, bw1, codes, int32(256)+**(**int32)(__ccgo_up(bp + 32)), **(**int32)(__ccgo_up(bp + 24)), **(**int32)(__ccgo_up(bp + 28)))
  36680 				// Don't write the distance with the extra bits code since
  36681 				// the distance can be up to 18 bits of extra bits, and the prefix
  36682 				// 15 bits, totaling to 33, and our PutBits only supports up to 32 bits.
  36683 				v5 = distance2
  36684 				v20 = bp + 32
  36685 				v21 = bp + 28
  36686 				v22 = bp + 24
  36687 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36688 					prefix_code = kPrefixEncodeCode[v5]
  36689 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36690 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36691 					**(**int32)(__ccgo_up(v22)) = libc.Int32FromUint8(kPrefixEncodeExtraBitsValue[v5])
  36692 				} else {
  36693 					v6 = v5
  36694 					v24 = v21
  36695 					v6 = v6 - 1
  36696 					v8 = v6
  36697 					v13 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v8))
  36698 					goto _36
  36699 				_36:
  36700 					highest_bit = v13
  36701 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36702 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36703 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36704 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36705 				}
  36706 				WriteHuffmanCode(tls, bw1, codes+uintptr(4)*24, **(**int32)(__ccgo_up(bp + 32)))
  36707 				v20 = bw1
  36708 				v2 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 24)))
  36709 				v5 = **(**int32)(__ccgo_up(bp + 28))
  36710 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36711 					if v5 > libc.Int32FromInt32(0) {
  36712 						if (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused >= libc.Int32FromInt32(32) {
  36713 							VP8LPutBitsFlushBits(tls, v20)
  36714 						}
  36715 						**(**vp8l_atype_t)(__ccgo_up(v20)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused
  36716 						**(**int32)(__ccgo_up(v20 + 8)) += v5
  36717 					}
  36718 				} else {
  36719 					VP8LPutBitsInternal(tls, v20, v2, v5)
  36720 				}
  36721 			}
  36722 		}
  36723 		v2 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  36724 		goto _41
  36725 	_41:
  36726 		x = libc.Int32FromUint32(uint32(x) + v2)
  36727 		for x >= width {
  36728 			x = x - width
  36729 			y = y + 1
  36730 		}
  36731 		v20 = bp
  36732 		v22 = v20
  36733 		*(*uintptr)(unsafe.Pointer(v22)) += 8
  36734 		v21 = *(*uintptr)(unsafe.Pointer(v22))
  36735 		if v21 == (*VP8LRefsCursor)(unsafe.Pointer(v20)).Flast_pos {
  36736 			VP8LRefsCursorNextBlock(tls, v20)
  36737 		}
  36738 	}
  36739 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  36740 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36741 	}
  36742 	return int32(1)
  36743 }
  36744 
  36745 var order = [4]uint8_t{
  36746 	0: uint8(1),
  36747 	1: uint8(2),
  36748 	3: uint8(3),
  36749 }
  36750 
  36751 // C documentation
  36752 //
  36753 //	// Special case of EncodeImageInternal() for cache-bits=0, histo_bits=31.
  36754 //	// pic and percent are for progress.
  36755 func EncodeImageNoHuffman(tls *libc.TLS, bw1 uintptr, argb uintptr, hash_chain uintptr, refs_array uintptr, width int32, height int32, quality int32, low_effort int32, pic uintptr, percent_range int32, percent uintptr) (r int32) {
  36756 	bp := tls.Alloc(128)
  36757 	defer tls.Free(128)
  36758 	var codes, codes1, histogram_image, huff_tree, refs, tokens, v1 uintptr
  36759 	var i, max_tokens, v3 int32
  36760 	var v2 uint32_t
  36761 	var _ /* cache_bits at bp+124 */ int32
  36762 	var _ /* histogram_symbols at bp+120 */ [1]uint32_t
  36763 	var _ /* huffman_codes at bp+0 */ [5]HuffmanTreeCode
  36764 	_, _, _, _, _, _, _, _, _, _, _ = codes, codes1, histogram_image, huff_tree, i, max_tokens, refs, tokens, v1, v2, v3
  36765 	max_tokens = 0
  36766 	tokens = libc.UintptrFromInt32(0)
  36767 	**(**[5]HuffmanTreeCode)(__ccgo_up(bp)) = [5]HuffmanTreeCode{}
  36768 	**(**[1]uint32_t)(__ccgo_up(bp + 120)) = [1]uint32_t{} // only one tree, one symbol
  36769 	**(**int32)(__ccgo_up(bp + 124)) = 0
  36770 	histogram_image = libc.UintptrFromInt32(0)
  36771 	huff_tree = WebPSafeMalloc(tls, uint64(libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES)), uint64(16))
  36772 	if huff_tree == libc.UintptrFromInt32(0) {
  36773 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36774 		goto Error
  36775 	}
  36776 	// Calculate backward references from ARGB image.
  36777 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range/int32(2), percent) != 0) {
  36778 		goto Error
  36779 	}
  36780 	if !(VP8LGetBackwardReferences(tls, width, height, argb, quality, 0, int32(kLZ77Standard)|int32(kLZ77RLE), **(**int32)(__ccgo_up(bp + 124)), 0, hash_chain, refs_array, bp+124, pic, percent_range-percent_range/int32(2), percent) != 0) {
  36781 		goto Error
  36782 	}
  36783 	refs = refs_array
  36784 	histogram_image = VP8LAllocateHistogramSet(tls, int32(1), **(**int32)(__ccgo_up(bp + 124)))
  36785 	if histogram_image == libc.UintptrFromInt32(0) {
  36786 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36787 		goto Error
  36788 	}
  36789 	VP8LHistogramSetClear(tls, histogram_image)
  36790 	// Build histogram image and symbols from backward references.
  36791 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms)))
  36792 	// Create Huffman bit lengths and codes for each histogram image.
  36793 	if !(GetHuffBitLengthsAndCodes(tls, histogram_image, bp) != 0) {
  36794 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36795 		goto Error
  36796 	}
  36797 	// No color cache, no Huffman image.
  36798 	v1 = bw1
  36799 	v2 = uint32(0)
  36800 	v3 = int32(1)
  36801 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36802 		if v3 > libc.Int32FromInt32(0) {
  36803 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36804 				VP8LPutBitsFlushBits(tls, v1)
  36805 			}
  36806 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36807 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  36808 		}
  36809 	} else {
  36810 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36811 	}
  36812 	// Find maximum number of symbols for the huffman tree-set.
  36813 	i = 0
  36814 	for {
  36815 		if !(i < int32(5)) {
  36816 			break
  36817 		}
  36818 		codes = bp + uintptr(i)*24
  36819 		if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  36820 			max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  36821 		}
  36822 		goto _4
  36823 	_4:
  36824 		;
  36825 		i = i + 1
  36826 	}
  36827 	tokens = WebPSafeMalloc(tls, libc.Uint64FromInt32(max_tokens), uint64(2))
  36828 	if tokens == libc.UintptrFromInt32(0) {
  36829 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36830 		goto Error
  36831 	}
  36832 	// Store Huffman codes.
  36833 	i = 0
  36834 	for {
  36835 		if !(i < int32(5)) {
  36836 			break
  36837 		}
  36838 		codes1 = bp + uintptr(i)*24
  36839 		StoreHuffmanCode(tls, bw1, huff_tree, tokens, codes1)
  36840 		ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  36841 		goto _5
  36842 	_5:
  36843 		;
  36844 		i = i + 1
  36845 	}
  36846 	// Store actual literals.
  36847 	if !(StoreImageToBitMask(tls, bw1, width, 0, refs, bp+120, bp, pic) != 0) {
  36848 		goto Error
  36849 	}
  36850 	goto Error
  36851 Error:
  36852 	;
  36853 	WebPSafeFree(tls, tokens)
  36854 	WebPSafeFree(tls, huff_tree)
  36855 	VP8LFreeHistogramSet(tls, histogram_image)
  36856 	WebPSafeFree(tls, (**(**[5]HuffmanTreeCode)(__ccgo_up(bp)))[0].Fcodes)
  36857 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  36858 }
  36859 
  36860 // C documentation
  36861 //
  36862 //	// pic and percent are for progress.
  36863 func EncodeImageInternal(tls *libc.TLS, bw2 uintptr, argb uintptr, hash_chain uintptr, refs_array uintptr, width int32, height int32, quality int32, low_effort int32, config uintptr, cache_bits uintptr, histogram_bits_in int32, init_byte_position size_t, hdr_size uintptr, data_size uintptr, pic uintptr, percent_range int32, percent uintptr) (r int32) {
  36864 	bp := tls.Alloc(128)
  36865 	defer tls.Free(128)
  36866 	var bit_array_size, bw_size_best, v37, v40 size_t
  36867 	var cache_bits_init, cache_bits_tmp, hdr_size_tmp, i_cache, i_percent_range, i_remaining_percent, max_tokens, percent_start, remaining_percent, sub_configs_idx, write_histogram_image, v10, v7 int32
  36868 	var codes, codes1, histogram_argb, histogram_image, huff_tree, huffman_codes, sub_config, tmp_histo, tokens, v12, v15 uintptr
  36869 	var histogram_image_size, histogram_image_xysize, i, v1, v2, v4, v5 uint32_t
  36870 	var _ /* bw_best at bp+48 */ VP8LBitWriter
  36871 	var _ /* bw_init at bp+0 */ VP8LBitWriter
  36872 	var _ /* cache_bits_best at bp+112 */ int32
  36873 	var _ /* hash_chain_histogram at bp+96 */ VP8LHashChain
  36874 	var _ /* histogram_bits at bp+116 */ int32
  36875 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit_array_size, bw_size_best, cache_bits_init, cache_bits_tmp, codes, codes1, hdr_size_tmp, histogram_argb, histogram_image, histogram_image_size, histogram_image_xysize, huff_tree, huffman_codes, i, i_cache, i_percent_range, i_remaining_percent, max_tokens, percent_start, remaining_percent, sub_config, sub_configs_idx, tmp_histo, tokens, write_histogram_image, v1, v10, v12, v15, v2, v37, v4, v40, v5, v7
  36876 	v1 = libc.Uint32FromInt32(histogram_bits_in)
  36877 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  36878 	goto _3
  36879 _3:
  36880 	v4 = libc.Uint32FromInt32(histogram_bits_in)
  36881 	v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  36882 	goto _6
  36883 _6:
  36884 	histogram_image_xysize = v2 * v5
  36885 	remaining_percent = percent_range
  36886 	percent_start = **(**int32)(__ccgo_up(percent))
  36887 	histogram_image = libc.UintptrFromInt32(0)
  36888 	tmp_histo = libc.UintptrFromInt32(0)
  36889 	histogram_image_size = uint32(0)
  36890 	bit_array_size = uint64(0)
  36891 	huff_tree = WebPSafeMalloc(tls, uint64(libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES)), uint64(16))
  36892 	tokens = libc.UintptrFromInt32(0)
  36893 	huffman_codes = libc.UintptrFromInt32(0)
  36894 	histogram_argb = WebPSafeMalloc(tls, uint64(histogram_image_xysize), uint64(4))
  36895 	**(**VP8LBitWriter)(__ccgo_up(bp)) = **(**VP8LBitWriter)(__ccgo_up(bw2)) // histogram image hash chain
  36896 	bw_size_best = ^libc.Uint64FromInt32(0)
  36897 	libc.Xmemset(tls, bp+96, 0, uint64(16))
  36898 	if !(VP8LBitWriterInit(tls, bp+48, uint64(0)) != 0) {
  36899 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36900 		goto Error
  36901 	}
  36902 	// Make sure we can allocate the different objects.
  36903 	if huff_tree == libc.UintptrFromInt32(0) || histogram_argb == libc.UintptrFromInt32(0) || !(VP8LHashChainInit(tls, bp+96, libc.Int32FromUint32(histogram_image_xysize)) != 0) {
  36904 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36905 		goto Error
  36906 	}
  36907 	percent_range = remaining_percent / int32(5)
  36908 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range, percent) != 0) {
  36909 		goto Error
  36910 	}
  36911 	percent_start = percent_start + percent_range
  36912 	remaining_percent = remaining_percent - percent_range
  36913 	// If the value is different from zero, it has been set during the palette
  36914 	// analysis.
  36915 	if **(**int32)(__ccgo_up(cache_bits)) == 0 {
  36916 		v7 = int32(MAX_COLOR_CACHE_BITS)
  36917 	} else {
  36918 		v7 = **(**int32)(__ccgo_up(cache_bits))
  36919 	}
  36920 	cache_bits_init = v7
  36921 	// If several iterations will happen, clone into bw_best.
  36922 	if ((*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size > int32(1) || (**(**CrunchSubConfig)(__ccgo_up(config + 8))).Fdo_no_cache != 0) && !(VP8LBitWriterClone(tls, bw2, bp+48) != 0) {
  36923 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36924 		goto Error
  36925 	}
  36926 	sub_configs_idx = 0
  36927 	for {
  36928 		if !(sub_configs_idx < (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size) {
  36929 			break
  36930 		}
  36931 		sub_config = config + 8 + uintptr(sub_configs_idx)*8
  36932 		i_remaining_percent = remaining_percent / (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size
  36933 		i_percent_range = i_remaining_percent / int32(4)
  36934 		i_remaining_percent = i_remaining_percent - i_percent_range
  36935 		if !(VP8LGetBackwardReferences(tls, width, height, argb, quality, low_effort, (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Flz77, cache_bits_init, (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Fdo_no_cache, hash_chain, refs_array, bp+112, pic, i_percent_range, percent) != 0) {
  36936 			goto Error
  36937 		}
  36938 		i_cache = 0
  36939 		for {
  36940 			if (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Fdo_no_cache != 0 {
  36941 				v7 = int32(2)
  36942 			} else {
  36943 				v7 = int32(1)
  36944 			}
  36945 			if !(i_cache < v7) {
  36946 				break
  36947 			}
  36948 			if i_cache == 0 {
  36949 				v10 = **(**int32)(__ccgo_up(bp + 112))
  36950 			} else {
  36951 				v10 = 0
  36952 			}
  36953 			cache_bits_tmp = v10
  36954 			**(**int32)(__ccgo_up(bp + 116)) = histogram_bits_in
  36955 			// Speed-up: no need to study the no-cache case if it was already studied
  36956 			// in i_cache == 0.
  36957 			if i_cache == int32(1) && **(**int32)(__ccgo_up(bp + 112)) == 0 {
  36958 				break
  36959 			}
  36960 			// Reset the bit writer for this iteration.
  36961 			VP8LBitWriterReset(tls, bp, bw2)
  36962 			// Build histogram image and symbols from backward references.
  36963 			histogram_image = VP8LAllocateHistogramSet(tls, libc.Int32FromUint32(histogram_image_xysize), cache_bits_tmp)
  36964 			tmp_histo = VP8LAllocateHistogram(tls, cache_bits_tmp)
  36965 			if histogram_image == libc.UintptrFromInt32(0) || tmp_histo == libc.UintptrFromInt32(0) {
  36966 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36967 				goto Error
  36968 			}
  36969 			i_percent_range = i_remaining_percent / int32(3)
  36970 			i_remaining_percent = i_remaining_percent - i_percent_range
  36971 			if !(VP8LGetHistoImageSymbols(tls, width, height, refs_array+uintptr(i_cache)*40, quality, low_effort, **(**int32)(__ccgo_up(bp + 116)), cache_bits_tmp, histogram_image, tmp_histo, histogram_argb, pic, i_percent_range, percent) != 0) {
  36972 				goto Error
  36973 			}
  36974 			// Create Huffman bit lengths and codes for each histogram image.
  36975 			histogram_image_size = libc.Uint32FromInt32((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize)
  36976 			bit_array_size = uint64(uint32(5) * histogram_image_size)
  36977 			huffman_codes = WebPSafeCalloc(tls, bit_array_size, uint64(24))
  36978 			// Note: some histogram_image entries may point to tmp_histos[], so the
  36979 			// latter need to outlive the following call to
  36980 			// GetHuffBitLengthsAndCodes().
  36981 			if huffman_codes == libc.UintptrFromInt32(0) || !(GetHuffBitLengthsAndCodes(tls, histogram_image, huffman_codes) != 0) {
  36982 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  36983 				goto Error
  36984 			}
  36985 			// Free combined histograms.
  36986 			VP8LFreeHistogramSet(tls, histogram_image)
  36987 			histogram_image = libc.UintptrFromInt32(0)
  36988 			// Free scratch histograms.
  36989 			VP8LFreeHistogram(tls, tmp_histo)
  36990 			tmp_histo = libc.UintptrFromInt32(0)
  36991 			// Color Cache parameters.
  36992 			if cache_bits_tmp > 0 {
  36993 				v12 = bw2
  36994 				v1 = uint32(1)
  36995 				v7 = int32(1)
  36996 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  36997 					if v7 > libc.Int32FromInt32(0) {
  36998 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  36999 							VP8LPutBitsFlushBits(tls, v12)
  37000 						}
  37001 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37002 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37003 					}
  37004 				} else {
  37005 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37006 				}
  37007 				v12 = bw2
  37008 				v1 = libc.Uint32FromInt32(cache_bits_tmp)
  37009 				v7 = int32(4)
  37010 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37011 					if v7 > libc.Int32FromInt32(0) {
  37012 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37013 							VP8LPutBitsFlushBits(tls, v12)
  37014 						}
  37015 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37016 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37017 					}
  37018 				} else {
  37019 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37020 				}
  37021 			} else {
  37022 				v12 = bw2
  37023 				v1 = uint32(0)
  37024 				v7 = int32(1)
  37025 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37026 					if v7 > libc.Int32FromInt32(0) {
  37027 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37028 							VP8LPutBitsFlushBits(tls, v12)
  37029 						}
  37030 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37031 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37032 					}
  37033 				} else {
  37034 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37035 				}
  37036 			}
  37037 			// Huffman image + meta huffman.
  37038 			histogram_image_size = uint32(0)
  37039 			i = uint32(0)
  37040 			for {
  37041 				if !(i < histogram_image_xysize) {
  37042 					break
  37043 				}
  37044 				if **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) >= histogram_image_size {
  37045 					histogram_image_size = **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) + uint32(1)
  37046 				}
  37047 				**(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) <<= uint32(8)
  37048 				goto _21
  37049 			_21:
  37050 				;
  37051 				i = i + 1
  37052 			}
  37053 			write_histogram_image = libc.BoolInt32(histogram_image_size > uint32(1))
  37054 			v12 = bw2
  37055 			v1 = libc.Uint32FromInt32(write_histogram_image)
  37056 			v7 = int32(1)
  37057 			if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37058 				if v7 > libc.Int32FromInt32(0) {
  37059 					if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37060 						VP8LPutBitsFlushBits(tls, v12)
  37061 					}
  37062 					**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37063 					**(**int32)(__ccgo_up(v12 + 8)) += v7
  37064 				}
  37065 			} else {
  37066 				VP8LPutBitsInternal(tls, v12, v1, v7)
  37067 			}
  37068 			if write_histogram_image != 0 {
  37069 				VP8LOptimizeSampling(tls, histogram_argb, width, height, histogram_bits_in, libc.Int32FromInt32(MIN_HUFFMAN_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_HUFFMAN_BITS)-libc.Int32FromInt32(1), bp+116)
  37070 				v12 = bw2
  37071 				v1 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 116)) - int32(2))
  37072 				v7 = int32(3)
  37073 				if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37074 					if v7 > libc.Int32FromInt32(0) {
  37075 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37076 							VP8LPutBitsFlushBits(tls, v12)
  37077 						}
  37078 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= uint64(v1) << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37079 						**(**int32)(__ccgo_up(v12 + 8)) += v7
  37080 					}
  37081 				} else {
  37082 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37083 				}
  37084 				i_percent_range = i_remaining_percent / int32(2)
  37085 				i_remaining_percent = i_remaining_percent - i_percent_range
  37086 				v1 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 116)))
  37087 				v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37088 				goto _30
  37089 			_30:
  37090 				v4 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 116)))
  37091 				v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37092 				goto _33
  37093 			_33:
  37094 				if !(EncodeImageNoHuffman(tls, bw2, histogram_argb, bp+96, refs_array+2*40, libc.Int32FromUint32(v2), libc.Int32FromUint32(v5), quality, low_effort, pic, i_percent_range, percent) != 0) {
  37095 					goto Error
  37096 				}
  37097 			}
  37098 			// Store Huffman codes.
  37099 			max_tokens = 0
  37100 			// Find maximum number of symbols for the huffman tree-set.
  37101 			i = uint32(0)
  37102 			for {
  37103 				if !(i < uint32(5)*histogram_image_size) {
  37104 					break
  37105 				}
  37106 				codes = huffman_codes + uintptr(i)*24
  37107 				if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37108 					max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37109 				}
  37110 				goto _34
  37111 			_34:
  37112 				;
  37113 				i = i + 1
  37114 			}
  37115 			tokens = WebPSafeMalloc(tls, libc.Uint64FromInt32(max_tokens), uint64(2))
  37116 			if tokens == libc.UintptrFromInt32(0) {
  37117 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37118 				goto Error
  37119 			}
  37120 			i = uint32(0)
  37121 			for {
  37122 				if !(i < uint32(5)*histogram_image_size) {
  37123 					break
  37124 				}
  37125 				codes1 = huffman_codes + uintptr(i)*24
  37126 				StoreHuffmanCode(tls, bw2, huff_tree, tokens, codes1)
  37127 				ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37128 				goto _35
  37129 			_35:
  37130 				;
  37131 				i = i + 1
  37132 			}
  37133 			// Store actual literals.
  37134 			v12 = bw2
  37135 			v37 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v12)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37136 			goto _38
  37137 		_38:
  37138 			hdr_size_tmp = libc.Int32FromUint64(v37 - init_byte_position)
  37139 			if !(StoreImageToBitMask(tls, bw2, width, **(**int32)(__ccgo_up(bp + 116)), refs_array+uintptr(i_cache)*40, histogram_argb, huffman_codes, pic) != 0) {
  37140 				goto Error
  37141 			}
  37142 			// Keep track of the smallest image so far.
  37143 			v12 = bw2
  37144 			v37 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v12)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37145 			goto _41
  37146 		_41:
  37147 			if v37 < bw_size_best {
  37148 				v15 = bw2
  37149 				v40 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v15)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v15)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v15)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37150 				goto _44
  37151 			_44:
  37152 				bw_size_best = v40
  37153 				**(**int32)(__ccgo_up(cache_bits)) = cache_bits_tmp
  37154 				**(**int32)(__ccgo_up(hdr_size)) = hdr_size_tmp
  37155 				v12 = bw2
  37156 				v37 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v12)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v12)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37157 				goto _47
  37158 			_47:
  37159 				**(**int32)(__ccgo_up(data_size)) = libc.Int32FromUint64(v37 - init_byte_position - libc.Uint64FromInt32(**(**int32)(__ccgo_up(hdr_size))))
  37160 				VP8LBitWriterSwap(tls, bw2, bp+48)
  37161 			}
  37162 			WebPSafeFree(tls, tokens)
  37163 			tokens = libc.UintptrFromInt32(0)
  37164 			if huffman_codes != libc.UintptrFromInt32(0) {
  37165 				WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37166 				WebPSafeFree(tls, huffman_codes)
  37167 				huffman_codes = libc.UintptrFromInt32(0)
  37168 			}
  37169 			goto _9
  37170 		_9:
  37171 			;
  37172 			i_cache = i_cache + 1
  37173 		}
  37174 		goto _8
  37175 	_8:
  37176 		;
  37177 		sub_configs_idx = sub_configs_idx + 1
  37178 	}
  37179 	VP8LBitWriterSwap(tls, bw2, bp+48)
  37180 	if !(WebPReportProgress(tls, pic, percent_start+remaining_percent, percent) != 0) {
  37181 		goto Error
  37182 	}
  37183 	goto Error
  37184 Error:
  37185 	;
  37186 	WebPSafeFree(tls, tokens)
  37187 	WebPSafeFree(tls, huff_tree)
  37188 	VP8LFreeHistogramSet(tls, histogram_image)
  37189 	VP8LFreeHistogram(tls, tmp_histo)
  37190 	VP8LHashChainClear(tls, bp+96)
  37191 	if huffman_codes != libc.UintptrFromInt32(0) {
  37192 		WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37193 		WebPSafeFree(tls, huffman_codes)
  37194 	}
  37195 	WebPSafeFree(tls, histogram_argb)
  37196 	VP8LBitWriterWipeOut(tls, bp+48)
  37197 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37198 }
  37199 
  37200 // -----------------------------------------------------------------------------
  37201 // Transforms
  37202 
  37203 func ApplySubtractGreen(tls *libc.TLS, enc uintptr, width int32, height int32, bw1 uintptr) {
  37204 	var v1 uintptr
  37205 	var v2 uint32_t
  37206 	var v3 int32
  37207 	_, _, _ = v1, v2, v3
  37208 	v1 = bw1
  37209 	v2 = uint32(TRANSFORM_PRESENT)
  37210 	v3 = int32(1)
  37211 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37212 		if v3 > libc.Int32FromInt32(0) {
  37213 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37214 				VP8LPutBitsFlushBits(tls, v1)
  37215 			}
  37216 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37217 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37218 		}
  37219 	} else {
  37220 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37221 	}
  37222 	v1 = bw1
  37223 	v2 = uint32(SUBTRACT_GREEN_TRANSFORM)
  37224 	v3 = int32(2)
  37225 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37226 		if v3 > libc.Int32FromInt32(0) {
  37227 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37228 				VP8LPutBitsFlushBits(tls, v1)
  37229 			}
  37230 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37231 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37232 		}
  37233 	} else {
  37234 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37235 	}
  37236 	(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LSubtractGreenFromBlueAndRed})))(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, width*height)
  37237 }
  37238 
  37239 func ApplyPredictFilter(tls *libc.TLS, enc uintptr, width int32, height int32, quality int32, low_effort int32, used_subtract_green int32, bw1 uintptr, percent_range int32, percent uintptr, best_bits uintptr) (r int32) {
  37240 	var max_bits, min_bits, near_lossless_strength, v1, v2 int32
  37241 	var v10, v12, v4, v7 uint32_t
  37242 	var v3 uintptr
  37243 	_, _, _, _, _, _, _, _, _, _ = max_bits, min_bits, near_lossless_strength, v1, v10, v12, v2, v3, v4, v7
  37244 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  37245 		v1 = int32(100)
  37246 	} else {
  37247 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fnear_lossless
  37248 	}
  37249 	near_lossless_strength = v1
  37250 	max_bits = ClampBits(tls, width, height, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpredictor_transform_bits, int32(MIN_TRANSFORM_BITS), libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), libc.Int32FromInt32(1)<<libc.Int32FromInt32(14))
  37251 	if (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod > int32(4) {
  37252 		v2 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod - int32(4)
  37253 	} else {
  37254 		v2 = 0
  37255 	}
  37256 	min_bits = ClampBits(tls, width, height, max_bits-int32(2)*v2, int32(MIN_TRANSFORM_BITS), libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), libc.Int32FromInt32(1)<<libc.Int32FromInt32(14))
  37257 	if !(VP8LResidualImage(tls, width, height, min_bits, max_bits, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_scratch, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data, near_lossless_strength, (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fexact, used_subtract_green, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range/int32(2), percent, best_bits) != 0) {
  37258 		return 0
  37259 	}
  37260 	v3 = bw1
  37261 	v4 = uint32(TRANSFORM_PRESENT)
  37262 	v1 = int32(1)
  37263 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37264 		if v1 > libc.Int32FromInt32(0) {
  37265 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37266 				VP8LPutBitsFlushBits(tls, v3)
  37267 			}
  37268 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37269 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37270 		}
  37271 	} else {
  37272 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37273 	}
  37274 	v3 = bw1
  37275 	v4 = uint32(PREDICTOR_TRANSFORM)
  37276 	v1 = int32(2)
  37277 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37278 		if v1 > libc.Int32FromInt32(0) {
  37279 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37280 				VP8LPutBitsFlushBits(tls, v3)
  37281 			}
  37282 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37283 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37284 		}
  37285 	} else {
  37286 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37287 	}
  37288 	v3 = bw1
  37289 	v4 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37290 	v1 = int32(NUM_TRANSFORM_BITS)
  37291 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37292 		if v1 > libc.Int32FromInt32(0) {
  37293 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37294 				VP8LPutBitsFlushBits(tls, v3)
  37295 			}
  37296 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= uint64(v4) << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37297 			**(**int32)(__ccgo_up(v3 + 8)) += v1
  37298 		}
  37299 	} else {
  37300 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37301 	}
  37302 	v4 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37303 	v7 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37304 	goto _14
  37305 _14:
  37306 	v10 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37307 	v12 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v10) - uint32(1)) >> v10
  37308 	goto _17
  37309 _17:
  37310 	return EncodeImageNoHuffman(tls, bw1, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data, enc+2312, enc+2152, libc.Int32FromUint32(v7), libc.Int32FromUint32(v12), quality, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range-percent_range/int32(2), percent)
  37311 }
  37312 
  37313 func ApplyCrossColorFilter(tls *libc.TLS, enc uintptr, width int32, height int32, quality int32, low_effort int32, bw1 uintptr, percent_range int32, percent uintptr, best_bits uintptr) (r int32) {
  37314 	var min_bits, v3 int32
  37315 	var v1 uintptr
  37316 	var v10, v2, v5, v8 uint32_t
  37317 	_, _, _, _, _, _, _ = min_bits, v1, v10, v2, v3, v5, v8
  37318 	min_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits
  37319 	if !(VP8LColorSpaceTransform(tls, width, height, min_bits, quality, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range/int32(2), percent, best_bits) != 0) {
  37320 		return 0
  37321 	}
  37322 	v1 = bw1
  37323 	v2 = uint32(TRANSFORM_PRESENT)
  37324 	v3 = int32(1)
  37325 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37326 		if v3 > libc.Int32FromInt32(0) {
  37327 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37328 				VP8LPutBitsFlushBits(tls, v1)
  37329 			}
  37330 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37331 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37332 		}
  37333 	} else {
  37334 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37335 	}
  37336 	v1 = bw1
  37337 	v2 = uint32(CROSS_COLOR_TRANSFORM)
  37338 	v3 = int32(2)
  37339 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37340 		if v3 > libc.Int32FromInt32(0) {
  37341 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37342 				VP8LPutBitsFlushBits(tls, v1)
  37343 			}
  37344 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37345 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37346 		}
  37347 	} else {
  37348 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37349 	}
  37350 	v1 = bw1
  37351 	v2 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37352 	v3 = int32(NUM_TRANSFORM_BITS)
  37353 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37354 		if v3 > libc.Int32FromInt32(0) {
  37355 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37356 				VP8LPutBitsFlushBits(tls, v1)
  37357 			}
  37358 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37359 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37360 		}
  37361 	} else {
  37362 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37363 	}
  37364 	v2 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37365 	v5 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  37366 	goto _12
  37367 _12:
  37368 	v8 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37369 	v10 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v8) - uint32(1)) >> v8
  37370 	goto _15
  37371 _15:
  37372 	return EncodeImageNoHuffman(tls, bw1, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data, enc+2312, enc+2152, libc.Int32FromUint32(v5), libc.Int32FromUint32(v10), quality, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range-percent_range/int32(2), percent)
  37373 }
  37374 
  37375 // -----------------------------------------------------------------------------
  37376 
  37377 func WriteRiffHeader(tls *libc.TLS, pic uintptr, riff_size size_t, vp8l_size size_t) (r int32) {
  37378 	bp := tls.Alloc(32)
  37379 	defer tls.Free(32)
  37380 	var v1, v3, v5 uintptr
  37381 	var v4, v6 int32
  37382 	var v2 uint32_t
  37383 	var _ /* riff at bp+0 */ [21]uint8_t
  37384 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  37385 	**(**[21]uint8_t)(__ccgo_up(bp)) = [21]uint8_t{
  37386 		0:  uint8('R'),
  37387 		1:  uint8('I'),
  37388 		2:  uint8('F'),
  37389 		3:  uint8('F'),
  37390 		8:  uint8('W'),
  37391 		9:  uint8('E'),
  37392 		10: uint8('B'),
  37393 		11: uint8('P'),
  37394 		12: uint8('V'),
  37395 		13: uint8('P'),
  37396 		14: uint8('8'),
  37397 		15: uint8('L'),
  37398 		20: uint8(VP8L_MAGIC_BYTE3),
  37399 	}
  37400 	v1 = bp + uintptr(TAG_SIZE)
  37401 	v2 = uint32(riff_size)
  37402 	v3 = v1
  37403 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  37404 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  37405 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  37406 	v5 = v1 + uintptr(2)
  37407 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  37408 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  37409 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  37410 	v1 = bp + uintptr(RIFF_HEADER_SIZE) + uintptr(TAG_SIZE)
  37411 	v2 = uint32(vp8l_size)
  37412 	v3 = v1
  37413 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  37414 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  37415 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  37416 	v5 = v1 + uintptr(2)
  37417 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  37418 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  37419 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  37420 	return (*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(21), pic)
  37421 }
  37422 
  37423 func WriteImageSize(tls *libc.TLS, pic uintptr, bw1 uintptr) (r int32) {
  37424 	var height, width, v3 int32
  37425 	var v1 uintptr
  37426 	var v2 uint32_t
  37427 	_, _, _, _, _ = height, width, v1, v2, v3
  37428 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  37429 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  37430 	v1 = bw1
  37431 	v2 = libc.Uint32FromInt32(width)
  37432 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37433 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37434 		if v3 > libc.Int32FromInt32(0) {
  37435 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37436 				VP8LPutBitsFlushBits(tls, v1)
  37437 			}
  37438 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37439 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37440 		}
  37441 	} else {
  37442 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37443 	}
  37444 	v1 = bw1
  37445 	v2 = libc.Uint32FromInt32(height)
  37446 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37447 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37448 		if v3 > libc.Int32FromInt32(0) {
  37449 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37450 				VP8LPutBitsFlushBits(tls, v1)
  37451 			}
  37452 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37453 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37454 		}
  37455 	} else {
  37456 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37457 	}
  37458 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37459 }
  37460 
  37461 func WriteRealAlphaAndVersion(tls *libc.TLS, bw1 uintptr, has_alpha int32) (r int32) {
  37462 	var v1 uintptr
  37463 	var v2 uint32_t
  37464 	var v3 int32
  37465 	_, _, _ = v1, v2, v3
  37466 	v1 = bw1
  37467 	v2 = libc.Uint32FromInt32(has_alpha)
  37468 	v3 = int32(1)
  37469 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37470 		if v3 > libc.Int32FromInt32(0) {
  37471 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37472 				VP8LPutBitsFlushBits(tls, v1)
  37473 			}
  37474 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37475 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37476 		}
  37477 	} else {
  37478 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37479 	}
  37480 	v1 = bw1
  37481 	v2 = uint32(VP8L_VERSION)
  37482 	v3 = int32(VP8L_VERSION_BITS)
  37483 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37484 		if v3 > libc.Int32FromInt32(0) {
  37485 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37486 				VP8LPutBitsFlushBits(tls, v1)
  37487 			}
  37488 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v2) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37489 			**(**int32)(__ccgo_up(v1 + 8)) += v3
  37490 		}
  37491 	} else {
  37492 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37493 	}
  37494 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37495 }
  37496 
  37497 func WriteImage(tls *libc.TLS, pic uintptr, bw1 uintptr, coded_size uintptr) (r int32) {
  37498 	bp := tls.Alloc(16)
  37499 	defer tls.Free(16)
  37500 	var pad, riff_size, vp8l_size, webpll_size, v2 size_t
  37501 	var webpll_data, v1 uintptr
  37502 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  37503 	_, _, _, _, _, _, _ = pad, riff_size, vp8l_size, webpll_data, webpll_size, v1, v2
  37504 	webpll_data = VP8LBitWriterFinish(tls, bw1)
  37505 	v1 = bw1
  37506 	v2 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  37507 	goto _3
  37508 _3:
  37509 	webpll_size = v2
  37510 	vp8l_size = uint64(VP8L_SIGNATURE_SIZE) + webpll_size
  37511 	pad = vp8l_size & uint64(1)
  37512 	riff_size = libc.Uint64FromInt32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8l_size + pad
  37513 	**(**size_t)(__ccgo_up(coded_size)) = uint64(0)
  37514 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37515 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37516 	}
  37517 	if !(WriteRiffHeader(tls, pic, riff_size, vp8l_size) != 0) || !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, webpll_data, webpll_size, pic) != 0) {
  37518 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37519 	}
  37520 	if pad != 0 {
  37521 		**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  37522 		if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(1), pic) != 0) {
  37523 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37524 		}
  37525 	}
  37526 	**(**size_t)(__ccgo_up(coded_size)) = uint64(CHUNK_HEADER_SIZE) + riff_size
  37527 	return int32(1)
  37528 }
  37529 
  37530 // -----------------------------------------------------------------------------
  37531 
  37532 func ClearTransformBuffer(tls *libc.TLS, enc uintptr) {
  37533 	WebPSafeFree(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem)
  37534 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = libc.UintptrFromInt32(0)
  37535 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = uint64(0)
  37536 }
  37537 
  37538 // C documentation
  37539 //
  37540 //	// Allocates the memory for argb (W x H) buffer, 2 rows of context for
  37541 //	// prediction and transform data.
  37542 //	// Flags influencing the memory allocated:
  37543 //	//  enc->transform_bits
  37544 //	//  enc->use_predict, enc->use_cross_color
  37545 func AllocateTransformBuffer(tls *libc.TLS, enc uintptr, width int32, height int32) (r int32) {
  37546 	var argb_scratch_size, image_size, max_alignment_in_words, mem_size, transform_data_size uint64_t
  37547 	var mem uintptr
  37548 	var v1, v2 uint64
  37549 	var v3, v4, v6, v7 uint32_t
  37550 	_, _, _, _, _, _, _, _, _, _, _, _ = argb_scratch_size, image_size, max_alignment_in_words, mem, mem_size, transform_data_size, v1, v2, v3, v4, v6, v7
  37551 	image_size = libc.Uint64FromInt32(width) * libc.Uint64FromInt32(height)
  37552 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  37553 		v1 = libc.Uint64FromInt32((width+int32(1))*int32(2)) + (libc.Uint64FromInt32(width*int32(2))+uint64(4)-uint64(1))/uint64(4)
  37554 	} else {
  37555 		v1 = uint64(0)
  37556 	}
  37557 	// VP8LResidualImage needs room for 2 scanlines of uint32 pixels with an extra
  37558 	// pixel in each, plus 2 regular scanlines of bytes.
  37559 	// TODO(skal): Clean up by using arithmetic in bytes instead of words.
  37560 	argb_scratch_size = v1
  37561 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  37562 		v3 = uint32(MIN_TRANSFORM_BITS)
  37563 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  37564 		goto _5
  37565 	_5:
  37566 		v6 = uint32(MIN_TRANSFORM_BITS)
  37567 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  37568 		goto _8
  37569 	_8:
  37570 		v2 = uint64(v4) * uint64(v7)
  37571 	} else {
  37572 		v2 = uint64(0)
  37573 	}
  37574 	transform_data_size = v2
  37575 	max_alignment_in_words = (libc.Uint64FromInt32(WEBP_ALIGN_CST) + libc.Uint64FromInt64(4) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt64(4)
  37576 	mem_size = image_size + max_alignment_in_words + argb_scratch_size + max_alignment_in_words + transform_data_size
  37577 	mem = (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem
  37578 	if mem == libc.UintptrFromInt32(0) || mem_size > (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size {
  37579 		ClearTransformBuffer(tls, enc)
  37580 		mem = WebPSafeMalloc(tls, mem_size, uint64(4))
  37581 		if mem == libc.UintptrFromInt32(0) {
  37582 			return WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37583 		}
  37584 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = mem
  37585 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = mem_size
  37586 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  37587 	}
  37588 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb = mem
  37589 	mem = uintptr((uint64(mem+uintptr(image_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37590 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_scratch = mem
  37591 	mem = uintptr((uint64(mem+uintptr(argb_scratch_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37592 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data = mem
  37593 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width = width
  37594 	return int32(1)
  37595 }
  37596 
  37597 func MakeInputImageCopy(tls *libc.TLS, enc uintptr) (r int32) {
  37598 	var dst, picture, src uintptr
  37599 	var height, width, y int32
  37600 	_, _, _, _, _, _ = dst, height, picture, src, width, y
  37601 	picture = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  37602 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  37603 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  37604 	if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  37605 		return 0
  37606 	}
  37607 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content == int32(kEncoderARGB) {
  37608 		return int32(1)
  37609 	}
  37610 	dst = (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb
  37611 	src = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  37612 	y = 0
  37613 	for {
  37614 		if !(y < height) {
  37615 			break
  37616 		}
  37617 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(width)*uint64(4))
  37618 		dst = dst + uintptr(width)*4
  37619 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  37620 		goto _1
  37621 	_1:
  37622 		;
  37623 		y = y + 1
  37624 	}
  37625 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderARGB)
  37626 	return int32(1)
  37627 }
  37628 
  37629 // -----------------------------------------------------------------------------
  37630 
  37631 func SearchColorGreedy(tls *libc.TLS, palette uintptr, palette_size int32, color uint32_t) (r uint32_t) {
  37632 	_ = palette_size
  37633 	if color == **(**uint32_t)(__ccgo_up(palette)) {
  37634 		return uint32(0)
  37635 	}
  37636 	if color == **(**uint32_t)(__ccgo_up(palette + 1*4)) {
  37637 		return uint32(1)
  37638 	}
  37639 	if color == **(**uint32_t)(__ccgo_up(palette + 2*4)) {
  37640 		return uint32(2)
  37641 	}
  37642 	return uint32(3)
  37643 }
  37644 
  37645 func ApplyPaletteHash0(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37646 	// Focus on the green color.
  37647 	return color >> libc.Int32FromInt32(8) & uint32(0xff)
  37648 }
  37649 
  37650 func ApplyPaletteHash1(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37651 	// Forget about alpha.
  37652 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*libc.Uint64FromUint64(4222244071)) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37653 }
  37654 
  37655 func ApplyPaletteHash2(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37656 	// Forget about alpha.
  37657 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31)-libc.Uint64FromInt32(1))) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37658 }
  37659 
  37660 // Use 1 pixel cache for ARGB pixels.
  37661 
  37662 // C documentation
  37663 //
  37664 //	// Remap argb values in src[] to packed palettes entries in dst[]
  37665 //	// using 'row' as a temporary buffer of size 'width'.
  37666 //	// We assume that all src[] values have a corresponding entry in the palette.
  37667 //	// Note: src[] can be the same as dst[]
  37668 func ApplyPalette(tls *libc.TLS, src uintptr, src_stride uint32_t, dst uintptr, dst_stride uint32_t, palette uintptr, palette_size int32, width int32, height int32, xbits int32, pic uintptr) (r int32) {
  37669 	bp := tls.Alloc(6144)
  37670 	defer tls.Free(6144)
  37671 	var hash_functions [3]uintptr
  37672 	var i, j, use_LUT, x, y int32
  37673 	var ind, pix, pix1, pix2, pix3, pix4, prev_idx, prev_idx1, prev_idx2, prev_idx3, prev_idx4, prev_pix, prev_pix1, prev_pix2, prev_pix3, prev_pix4 uint32_t
  37674 	var tmp_row uintptr
  37675 	var _ /* buffer at bp+0 */ [2048]uint16_t
  37676 	var _ /* idx_map at bp+4096 */ [256]uint32_t
  37677 	var _ /* palette_sorted at bp+5120 */ [256]uint32_t
  37678 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = hash_functions, i, ind, j, pix, pix1, pix2, pix3, pix4, prev_idx, prev_idx1, prev_idx2, prev_idx3, prev_idx4, prev_pix, prev_pix1, prev_pix2, prev_pix3, prev_pix4, tmp_row, use_LUT, x, y
  37679 	// TODO(skal): this tmp buffer is not needed if VP8LBundleColorMap() can be
  37680 	// made to work in-place.
  37681 	tmp_row = WebPSafeMalloc(tls, libc.Uint64FromInt32(width), uint64(1))
  37682 	if tmp_row == libc.UintptrFromInt32(0) {
  37683 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37684 	}
  37685 	if palette_size < int32(4) {
  37686 		prev_pix = **(**uint32_t)(__ccgo_up(palette))
  37687 		prev_idx = uint32(0)
  37688 		y = 0
  37689 		for {
  37690 			if !(y < height) {
  37691 				break
  37692 			}
  37693 			x = 0
  37694 			for {
  37695 				if !(x < width) {
  37696 					break
  37697 				}
  37698 				pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37699 				if pix != prev_pix {
  37700 					prev_idx = SearchColorGreedy(tls, palette, palette_size, pix)
  37701 					prev_pix = pix
  37702 				}
  37703 				**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx)
  37704 				goto _2
  37705 			_2:
  37706 				;
  37707 				x = x + 1
  37708 			}
  37709 			(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  37710 			src = src + uintptr(src_stride)*4
  37711 			dst = dst + uintptr(dst_stride)*4
  37712 			goto _1
  37713 		_1:
  37714 			;
  37715 			y = y + 1
  37716 		}
  37717 	} else {
  37718 		hash_functions = [3]uintptr{
  37719 			0: __ccgo_fp(ApplyPaletteHash0),
  37720 			1: __ccgo_fp(ApplyPaletteHash1),
  37721 			2: __ccgo_fp(ApplyPaletteHash2),
  37722 		}
  37723 		// Try to find a perfect hash function able to go from a color to an index
  37724 		// within 1 << PALETTE_INV_SIZE_BITS in order to build a hash map to go
  37725 		// from color to index in palette.
  37726 		i = 0
  37727 		for {
  37728 			if !(i < int32(3)) {
  37729 				break
  37730 			}
  37731 			use_LUT = int32(1)
  37732 			// Set each element in buffer to max uint16_t.
  37733 			libc.Xmemset(tls, bp, int32(0xff), uint64(4096))
  37734 			j = 0
  37735 			for {
  37736 				if !(j < palette_size) {
  37737 					break
  37738 				}
  37739 				ind = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{hash_functions[i]})))(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(j)*4)))
  37740 				if uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ind]) != uint32(0xffff) {
  37741 					use_LUT = 0
  37742 					break
  37743 				} else {
  37744 					(**(**[2048]uint16_t)(__ccgo_up(bp)))[ind] = libc.Uint16FromInt32(j)
  37745 				}
  37746 				goto _4
  37747 			_4:
  37748 				;
  37749 				j = j + 1
  37750 			}
  37751 			if use_LUT != 0 {
  37752 				break
  37753 			}
  37754 			goto _3
  37755 		_3:
  37756 			;
  37757 			i = i + 1
  37758 		}
  37759 		if i == 0 {
  37760 			prev_pix1 = **(**uint32_t)(__ccgo_up(palette))
  37761 			prev_idx1 = uint32(0)
  37762 			y = 0
  37763 			for {
  37764 				if !(y < height) {
  37765 					break
  37766 				}
  37767 				x = 0
  37768 				for {
  37769 					if !(x < width) {
  37770 						break
  37771 					}
  37772 					pix1 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37773 					if pix1 != prev_pix1 {
  37774 						prev_idx1 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash0(tls, pix1)])
  37775 						prev_pix1 = pix1
  37776 					}
  37777 					**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx1)
  37778 					goto _6
  37779 				_6:
  37780 					;
  37781 					x = x + 1
  37782 				}
  37783 				(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  37784 				src = src + uintptr(src_stride)*4
  37785 				dst = dst + uintptr(dst_stride)*4
  37786 				goto _5
  37787 			_5:
  37788 				;
  37789 				y = y + 1
  37790 			}
  37791 		} else {
  37792 			if i == int32(1) {
  37793 				prev_pix2 = **(**uint32_t)(__ccgo_up(palette))
  37794 				prev_idx2 = uint32(0)
  37795 				y = 0
  37796 				for {
  37797 					if !(y < height) {
  37798 						break
  37799 					}
  37800 					x = 0
  37801 					for {
  37802 						if !(x < width) {
  37803 							break
  37804 						}
  37805 						pix2 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37806 						if pix2 != prev_pix2 {
  37807 							prev_idx2 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash1(tls, pix2)])
  37808 							prev_pix2 = pix2
  37809 						}
  37810 						**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx2)
  37811 						goto _8
  37812 					_8:
  37813 						;
  37814 						x = x + 1
  37815 					}
  37816 					(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  37817 					src = src + uintptr(src_stride)*4
  37818 					dst = dst + uintptr(dst_stride)*4
  37819 					goto _7
  37820 				_7:
  37821 					;
  37822 					y = y + 1
  37823 				}
  37824 			} else {
  37825 				if i == int32(2) {
  37826 					prev_pix3 = **(**uint32_t)(__ccgo_up(palette))
  37827 					prev_idx3 = uint32(0)
  37828 					y = 0
  37829 					for {
  37830 						if !(y < height) {
  37831 							break
  37832 						}
  37833 						x = 0
  37834 						for {
  37835 							if !(x < width) {
  37836 								break
  37837 							}
  37838 							pix3 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37839 							if pix3 != prev_pix3 {
  37840 								prev_idx3 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash2(tls, pix3)])
  37841 								prev_pix3 = pix3
  37842 							}
  37843 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx3)
  37844 							goto _10
  37845 						_10:
  37846 							;
  37847 							x = x + 1
  37848 						}
  37849 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  37850 						src = src + uintptr(src_stride)*4
  37851 						dst = dst + uintptr(dst_stride)*4
  37852 						goto _9
  37853 					_9:
  37854 						;
  37855 						y = y + 1
  37856 					}
  37857 				} else {
  37858 					PrepareMapToPalette(tls, palette, libc.Uint32FromInt32(palette_size), bp+5120, bp+4096)
  37859 					prev_pix4 = **(**uint32_t)(__ccgo_up(palette))
  37860 					prev_idx4 = uint32(0)
  37861 					y = 0
  37862 					for {
  37863 						if !(y < height) {
  37864 							break
  37865 						}
  37866 						x = 0
  37867 						for {
  37868 							if !(x < width) {
  37869 								break
  37870 							}
  37871 							pix4 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37872 							if pix4 != prev_pix4 {
  37873 								prev_idx4 = (**(**[256]uint32_t)(__ccgo_up(bp + 4096)))[SearchColorNoIdx(tls, bp+5120, pix4, palette_size)]
  37874 								prev_pix4 = pix4
  37875 							}
  37876 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx4)
  37877 							goto _12
  37878 						_12:
  37879 							;
  37880 							x = x + 1
  37881 						}
  37882 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  37883 						src = src + uintptr(src_stride)*4
  37884 						dst = dst + uintptr(dst_stride)*4
  37885 						goto _11
  37886 					_11:
  37887 						;
  37888 						y = y + 1
  37889 					}
  37890 				}
  37891 			}
  37892 		}
  37893 	}
  37894 	WebPSafeFree(tls, tmp_row)
  37895 	return int32(1)
  37896 }
  37897 
  37898 // C documentation
  37899 //
  37900 //	// Note: Expects "enc->palette" to be set properly.
  37901 func MapImageFromPalette(tls *libc.TLS, enc uintptr) (r int32) {
  37902 	var height, palette_size, width, xbits, v1 int32
  37903 	var palette, pic uintptr
  37904 	var v3, v4 uint32_t
  37905 	_, _, _, _, _, _, _, _, _ = height, palette, palette_size, pic, width, xbits, v1, v3, v4
  37906 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  37907 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  37908 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  37909 	palette = enc + 104
  37910 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  37911 	// Replace each input pixel by corresponding palette index.
  37912 	// This is done line by line.
  37913 	if palette_size <= int32(4) {
  37914 		if palette_size <= int32(2) {
  37915 			v1 = int32(3)
  37916 		} else {
  37917 			v1 = int32(2)
  37918 		}
  37919 		xbits = v1
  37920 	} else {
  37921 		if palette_size <= int32(16) {
  37922 			v1 = int32(1)
  37923 		} else {
  37924 			v1 = 0
  37925 		}
  37926 		xbits = v1
  37927 	}
  37928 	v3 = libc.Uint32FromInt32(xbits)
  37929 	v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  37930 	goto _5
  37931 _5:
  37932 	if !(AllocateTransformBuffer(tls, enc, libc.Int32FromUint32(v4), height) != 0) {
  37933 		return 0
  37934 	}
  37935 	if !(ApplyPalette(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb, libc.Uint32FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride), (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, libc.Uint32FromInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width), palette, palette_size, width, height, xbits, pic) != 0) {
  37936 		return 0
  37937 	}
  37938 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderPalette)
  37939 	return int32(1)
  37940 }
  37941 
  37942 // C documentation
  37943 //
  37944 //	// Save palette[] to bitstream.
  37945 func EncodePalette(tls *libc.TLS, bw1 uintptr, low_effort int32, enc uintptr, percent_range int32, percent uintptr) (r int32) {
  37946 	bp := tls.Alloc(1024)
  37947 	defer tls.Free(1024)
  37948 	var alpha_and_green, encoded_palette_size, red_and_blue, v3, v6, v9 uint32_t
  37949 	var i, palette_size, v1, v4 int32
  37950 	var palette, v2 uintptr
  37951 	var _ /* tmp_palette at bp+0 */ [256]uint32_t
  37952 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, encoded_palette_size, i, palette, palette_size, red_and_blue, v1, v2, v3, v4, v6, v9
  37953 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  37954 	palette = enc + 104
  37955 	if **(**uint32_t)(__ccgo_up(enc + 104 + uintptr(palette_size-int32(1))*4)) == uint32(0) && palette_size > int32(17) {
  37956 		v1 = palette_size - int32(1)
  37957 	} else {
  37958 		v1 = palette_size
  37959 	}
  37960 	// If the last element is 0, do not store it and count on automatic palette
  37961 	// 0-filling. This can only happen if there is no pixel packing, hence if
  37962 	// there are strictly more than 16 colors (after 0 is removed).
  37963 	encoded_palette_size = libc.Uint32FromInt32(v1)
  37964 	v2 = bw1
  37965 	v3 = uint32(TRANSFORM_PRESENT)
  37966 	v4 = int32(1)
  37967 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37968 		if v4 > libc.Int32FromInt32(0) {
  37969 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  37970 				VP8LPutBitsFlushBits(tls, v2)
  37971 			}
  37972 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  37973 			**(**int32)(__ccgo_up(v2 + 8)) += v4
  37974 		}
  37975 	} else {
  37976 		VP8LPutBitsInternal(tls, v2, v3, v4)
  37977 	}
  37978 	v2 = bw1
  37979 	v3 = uint32(COLOR_INDEXING_TRANSFORM)
  37980 	v1 = int32(2)
  37981 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37982 		if v1 > libc.Int32FromInt32(0) {
  37983 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  37984 				VP8LPutBitsFlushBits(tls, v2)
  37985 			}
  37986 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  37987 			**(**int32)(__ccgo_up(v2 + 8)) += v1
  37988 		}
  37989 	} else {
  37990 		VP8LPutBitsInternal(tls, v2, v3, v1)
  37991 	}
  37992 	v2 = bw1
  37993 	v3 = encoded_palette_size - uint32(1)
  37994 	v1 = int32(8)
  37995 	if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  37996 		if v1 > libc.Int32FromInt32(0) {
  37997 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  37998 				VP8LPutBitsFlushBits(tls, v2)
  37999 			}
  38000 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= uint64(v3) << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38001 			**(**int32)(__ccgo_up(v2 + 8)) += v1
  38002 		}
  38003 	} else {
  38004 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38005 	}
  38006 	i = libc.Int32FromUint32(encoded_palette_size - uint32(1))
  38007 	for {
  38008 		if !(i >= int32(1)) {
  38009 			break
  38010 		}
  38011 		v3 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  38012 		v6 = **(**uint32_t)(__ccgo_up(palette + uintptr(i-int32(1))*4))
  38013 		alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v6&uint32(0xff00ff00)
  38014 		red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v6&uint32(0x00ff00ff)
  38015 		v9 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  38016 		goto _15
  38017 	_15:
  38018 		(**(**[256]uint32_t)(__ccgo_up(bp)))[i] = v9
  38019 		goto _11
  38020 	_11:
  38021 		;
  38022 		i = i - 1
  38023 	}
  38024 	(**(**[256]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(palette))
  38025 	return EncodeImageNoHuffman(tls, bw1, bp, enc+2312, enc+2152, libc.Int32FromUint32(encoded_palette_size), int32(1), int32(20), low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, percent_range, percent)
  38026 }
  38027 
  38028 // -----------------------------------------------------------------------------
  38029 // VP8LEncoder
  38030 
  38031 func VP8LEncoderNew(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  38032 	var enc uintptr
  38033 	_ = enc
  38034 	enc = WebPSafeCalloc(tls, uint64(1), uint64(2328))
  38035 	if enc == libc.UintptrFromInt32(0) {
  38036 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38037 		return libc.UintptrFromInt32(0)
  38038 	}
  38039 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig = config
  38040 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpic = picture
  38041 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38042 	VP8LEncDspInit(tls)
  38043 	return enc
  38044 }
  38045 
  38046 func VP8LEncoderDelete(tls *libc.TLS, enc uintptr) {
  38047 	var i int32
  38048 	_ = i
  38049 	if enc != libc.UintptrFromInt32(0) {
  38050 		VP8LHashChainClear(tls, enc+2312)
  38051 		i = 0
  38052 		for {
  38053 			if !(i < int32(4)) {
  38054 				break
  38055 			}
  38056 			VP8LBackwardRefsClear(tls, enc+2152+uintptr(i)*40)
  38057 			goto _1
  38058 		_1:
  38059 			;
  38060 			i = i + 1
  38061 		}
  38062 		ClearTransformBuffer(tls, enc)
  38063 		WebPSafeFree(tls, enc)
  38064 	}
  38065 }
  38066 
  38067 // -----------------------------------------------------------------------------
  38068 // Main call
  38069 
  38070 type StreamEncodeContext = struct {
  38071 	Fconfig                   uintptr
  38072 	Fpicture                  uintptr
  38073 	Fbw                       uintptr
  38074 	Fenc                      uintptr
  38075 	Fcrunch_configs           [14]CrunchConfig
  38076 	Fnum_crunch_configs       int32
  38077 	Fred_and_blue_always_zero int32
  38078 	Fstats                    uintptr
  38079 }
  38080 
  38081 func EncodeStreamHook(tls *libc.TLS, input uintptr, data2 uintptr) (r int32) {
  38082 	bp := tls.Alloc(128)
  38083 	defer tls.Free(128)
  38084 	var best_size, byte_position, v12, v2 size_t
  38085 	var bw2, config, crunch_configs, enc, params, picture, stats, v1, v8 uintptr
  38086 	var entropy_idx, height, idx, low_effort, num_crunch_configs, percent_range, quality, red_and_blue_always_zero, remaining_percent, use_near_lossless, width, v5 int32
  38087 	var v9 uint32_t
  38088 	var _ /* bw_best at bp+64 */ VP8LBitWriter
  38089 	var _ /* bw_init at bp+16 */ VP8LBitWriter
  38090 	var _ /* cross_color_transform_bits at bp+116 */ int32
  38091 	var _ /* data_size at bp+8 */ int32
  38092 	var _ /* hdr_size at bp+4 */ int32
  38093 	var _ /* percent at bp+0 */ int32
  38094 	var _ /* predictor_transform_bits at bp+112 */ int32
  38095 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_size, bw2, byte_position, config, crunch_configs, enc, entropy_idx, height, idx, low_effort, num_crunch_configs, params, percent_range, picture, quality, red_and_blue_always_zero, remaining_percent, stats, use_near_lossless, width, v1, v12, v2, v5, v8, v9
  38096 	params = input
  38097 	config = (*StreamEncodeContext)(unsafe.Pointer(params)).Fconfig
  38098 	picture = (*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture
  38099 	bw2 = (*StreamEncodeContext)(unsafe.Pointer(params)).Fbw
  38100 	enc = (*StreamEncodeContext)(unsafe.Pointer(params)).Fenc
  38101 	crunch_configs = params + 32
  38102 	num_crunch_configs = (*StreamEncodeContext)(unsafe.Pointer(params)).Fnum_crunch_configs
  38103 	red_and_blue_always_zero = (*StreamEncodeContext)(unsafe.Pointer(params)).Fred_and_blue_always_zero
  38104 	stats = (*StreamEncodeContext)(unsafe.Pointer(params)).Fstats
  38105 	quality = int32((*WebPConfig)(unsafe.Pointer(config)).Fquality)
  38106 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  38107 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38108 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38109 	v1 = bw2
  38110 	v2 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38111 	goto _3
  38112 _3:
  38113 	byte_position = v2
  38114 	**(**int32)(__ccgo_up(bp)) = int32(2) // for WebPProgressHook
  38115 	use_near_lossless = 0
  38116 	**(**int32)(__ccgo_up(bp + 4)) = 0
  38117 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38118 	best_size = ^libc.Uint64FromInt32(0)
  38119 	**(**VP8LBitWriter)(__ccgo_up(bp + 16)) = **(**VP8LBitWriter)(__ccgo_up(bw2))
  38120 	_ = data2
  38121 	if !(VP8LBitWriterInit(tls, bp+64, uint64(0)) != 0) || num_crunch_configs > int32(1) && !(VP8LBitWriterClone(tls, bw2, bp+64) != 0) {
  38122 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38123 		goto Error
  38124 	}
  38125 	idx = 0
  38126 	for {
  38127 		if !(idx < num_crunch_configs) {
  38128 			break
  38129 		}
  38130 		entropy_idx = (**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(idx)*28))).Fentropy_idx
  38131 		remaining_percent = int32(97) / num_crunch_configs
  38132 		**(**int32)(__ccgo_up(bp + 112)) = 0
  38133 		**(**int32)(__ccgo_up(bp + 116)) = 0
  38134 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette = libc.BoolInt32(entropy_idx == int32(kPalette) || entropy_idx == int32(kPaletteAndSpatial))
  38135 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green = libc.BoolInt32(entropy_idx == int32(kSubGreen) || entropy_idx == int32(kSpatialSubGreen))
  38136 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict = libc.BoolInt32(entropy_idx == int32(kSpatial) || entropy_idx == int32(kSpatialSubGreen) || entropy_idx == int32(kPaletteAndSpatial))
  38137 		// When using a palette, R/B==0, hence no need to test for cross-color.
  38138 		if low_effort != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38139 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = 0
  38140 		} else {
  38141 			if red_and_blue_always_zero != 0 {
  38142 				v5 = 0
  38143 			} else {
  38144 				v5 = (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict
  38145 			}
  38146 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = v5
  38147 		}
  38148 		// Reset any parameter in the encoder that is set in the previous iteration.
  38149 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = 0
  38150 		VP8LBackwardRefsClear(tls, enc+2152)
  38151 		VP8LBackwardRefsClear(tls, enc+2152+1*40)
  38152 		// Apply near-lossless preprocessing.
  38153 		use_near_lossless = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless < int32(100) && !((*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0) && !((*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0))
  38154 		if use_near_lossless != 0 {
  38155 			if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  38156 				goto Error
  38157 			}
  38158 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && !(VP8ApplyNearLossless(tls, picture, (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb) != 0) {
  38159 				WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38160 				goto Error
  38161 			}
  38162 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNearLossless)
  38163 		} else {
  38164 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38165 		}
  38166 		// Encode palette
  38167 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38168 			if !(PaletteSort(tls, (**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(idx)*28))).Fpalette_sorting_type, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, enc+1128, libc.Uint32FromInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size), enc+104) != 0) {
  38169 				WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38170 				goto Error
  38171 			}
  38172 			percent_range = remaining_percent / int32(4)
  38173 			if !(EncodePalette(tls, bw2, low_effort, enc, percent_range, bp) != 0) {
  38174 				goto Error
  38175 			}
  38176 			remaining_percent = remaining_percent - percent_range
  38177 			if !(MapImageFromPalette(tls, enc) != 0) {
  38178 				goto Error
  38179 			}
  38180 			// If using a color cache, do not have it bigger than the number of
  38181 			// colors.
  38182 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_COLOR_CACHE_BITS) {
  38183 				v5 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size))
  38184 				goto _7
  38185 			_7:
  38186 				(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = v5 + int32(1)
  38187 			}
  38188 		}
  38189 		// In case image is not packed.
  38190 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderPalette) {
  38191 			if !(MakeInputImageCopy(tls, enc) != 0) {
  38192 				goto Error
  38193 			}
  38194 		}
  38195 		// -------------------------------------------------------------------------
  38196 		// Apply transforms and write transform data.
  38197 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38198 			ApplySubtractGreen(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, bw2)
  38199 		}
  38200 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38201 			percent_range = remaining_percent / int32(3)
  38202 			if !(ApplyPredictFilter(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green, bw2, percent_range, bp, bp+112) != 0) {
  38203 				goto Error
  38204 			}
  38205 			remaining_percent = remaining_percent - percent_range
  38206 		}
  38207 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38208 			percent_range = remaining_percent / int32(2)
  38209 			if !(ApplyCrossColorFilter(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, bw2, percent_range, bp, bp+116) != 0) {
  38210 				goto Error
  38211 			}
  38212 			remaining_percent = remaining_percent - percent_range
  38213 		}
  38214 		v1 = bw2
  38215 		v9 = libc.BoolUint32(!(libc.Int32FromInt32(TRANSFORM_PRESENT) != 0))
  38216 		v5 = int32(1)
  38217 		if libc.Uint64FromInt64(4) == libc.Uint64FromInt32(4) {
  38218 			if v5 > libc.Int32FromInt32(0) {
  38219 				if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  38220 					VP8LPutBitsFlushBits(tls, v1)
  38221 				}
  38222 				**(**vp8l_atype_t)(__ccgo_up(v1)) |= uint64(v9) << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  38223 				**(**int32)(__ccgo_up(v1 + 8)) += v5
  38224 			}
  38225 		} else {
  38226 			VP8LPutBitsInternal(tls, v1, v9, v5)
  38227 		} // No more transforms.
  38228 		// -------------------------------------------------------------------------
  38229 		// Encode and write the transformed image.
  38230 		if !(EncodeImageInternal(tls, bw2, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, enc+2312, enc+2152, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, crunch_configs+uintptr(idx)*28, enc+80, (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits, byte_position, bp+4, bp+8, picture, remaining_percent, bp) != 0) {
  38231 			goto Error
  38232 		}
  38233 		// If we are better than what we already have.
  38234 		v1 = bw2
  38235 		v2 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v1)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v1)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38236 		goto _13
  38237 	_13:
  38238 		if v2 < best_size {
  38239 			v8 = bw2
  38240 			v12 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v8)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38241 			goto _16
  38242 		_16:
  38243 			best_size = v12
  38244 			// Store the BitWriter.
  38245 			VP8LBitWriterSwap(tls, bw2, bp+64)
  38246 			// Update the stats.
  38247 			if stats != libc.UintptrFromInt32(0) {
  38248 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = uint32(0)
  38249 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38250 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(1)
  38251 				}
  38252 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38253 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(2)
  38254 				}
  38255 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38256 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(4)
  38257 				}
  38258 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38259 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(8)
  38260 				}
  38261 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits
  38262 				(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = **(**int32)(__ccgo_up(bp + 112))
  38263 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = **(**int32)(__ccgo_up(bp + 116))
  38264 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits
  38265 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38266 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = libc.Int32FromUint64(best_size - byte_position)
  38267 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = **(**int32)(__ccgo_up(bp + 4))
  38268 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = **(**int32)(__ccgo_up(bp + 8))
  38269 			}
  38270 		}
  38271 		// Reset the bit writer for the following iteration if any.
  38272 		if num_crunch_configs > int32(1) {
  38273 			VP8LBitWriterReset(tls, bp+16, bw2)
  38274 		}
  38275 		goto _4
  38276 	_4:
  38277 		;
  38278 		idx = idx + 1
  38279 	}
  38280 	VP8LBitWriterSwap(tls, bp+64, bw2)
  38281 	goto Error
  38282 Error:
  38283 	;
  38284 	VP8LBitWriterWipeOut(tls, bp+64)
  38285 	// The hook should return false in case of error.
  38286 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer((*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture)).Ferror_code == int32(VP8_ENC_OK))
  38287 }
  38288 
  38289 func VP8LEncodeStream(tls *libc.TLS, config uintptr, picture1 uintptr, bw_main uintptr) (r int32) {
  38290 	bp := tls.Alloc(1872)
  38291 	defer tls.Free(1872)
  38292 	var enc_main, enc_side, param, worker, worker_interface, v7, v8 uintptr
  38293 	var idx, num_crunch_configs_side, ok_main, ok_side, params_size, v1 int32
  38294 	var v11, v14 size_t
  38295 	var _ /* bw_side at bp+1568 */ VP8LBitWriter
  38296 	var _ /* crunch_configs at bp+0 */ [14]CrunchConfig
  38297 	var _ /* num_crunch_configs_main at bp+392 */ int32
  38298 	var _ /* params_main at bp+496 */ StreamEncodeContext
  38299 	var _ /* params_side at bp+936 */ StreamEncodeContext
  38300 	var _ /* picture_side at bp+1616 */ WebPPicture
  38301 	var _ /* red_and_blue_always_zero at bp+396 */ int32
  38302 	var _ /* stats_side at bp+1376 */ WebPAuxStats
  38303 	var _ /* worker_main at bp+400 */ WebPWorker
  38304 	var _ /* worker_side at bp+448 */ WebPWorker
  38305 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc_main, enc_side, idx, num_crunch_configs_side, ok_main, ok_side, param, params_size, worker, worker_interface, v1, v11, v14, v7, v8
  38306 	enc_main = VP8LEncoderNew(tls, config, picture1)
  38307 	enc_side = libc.UintptrFromInt32(0)
  38308 	num_crunch_configs_side = 0
  38309 	**(**int32)(__ccgo_up(bp + 396)) = 0
  38310 	worker_interface = WebPGetWorkerInterface(tls)
  38311 	if enc_main == libc.UintptrFromInt32(0) || !(VP8LBitWriterInit(tls, bp+1568, uint64(0)) != 0) {
  38312 		VP8LEncoderDelete(tls, enc_main)
  38313 		return WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38314 	}
  38315 	// Avoid "garbage value" error from Clang's static analysis tool.
  38316 	v1 = WebPPictureInitInternal(tls, bp+1616, int32(WEBP_ENCODER_ABI_VERSION))
  38317 	goto _2
  38318 _2:
  38319 	if !(v1 != 0) {
  38320 		goto Error
  38321 	}
  38322 	// Analyze image (entropy, num_palettes etc)
  38323 	if !(EncoderAnalyze(tls, enc_main, bp, bp+392, bp+396) != 0) || !(EncoderInit(tls, enc_main) != 0) {
  38324 		WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38325 		goto Error
  38326 	}
  38327 	// Split the configs between the main and side threads (if any).
  38328 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > 0 {
  38329 		num_crunch_configs_side = **(**int32)(__ccgo_up(bp + 392)) / int32(2)
  38330 		idx = 0
  38331 		for {
  38332 			if !(idx < num_crunch_configs_side) {
  38333 				break
  38334 			}
  38335 			**(**CrunchConfig)(__ccgo_up(bp + 936 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[**(**int32)(__ccgo_up(bp + 392))-num_crunch_configs_side+idx]
  38336 			goto _3
  38337 		_3:
  38338 			;
  38339 			idx = idx + 1
  38340 		}
  38341 		(**(**StreamEncodeContext)(__ccgo_up(bp + 936))).Fnum_crunch_configs = num_crunch_configs_side
  38342 	}
  38343 	**(**int32)(__ccgo_up(bp + 392)) = **(**int32)(__ccgo_up(bp + 392)) - num_crunch_configs_side
  38344 	idx = 0
  38345 	for {
  38346 		if !(idx < **(**int32)(__ccgo_up(bp + 392))) {
  38347 			break
  38348 		}
  38349 		**(**CrunchConfig)(__ccgo_up(bp + 496 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[idx]
  38350 		goto _4
  38351 	_4:
  38352 		;
  38353 		idx = idx + 1
  38354 	}
  38355 	(**(**StreamEncodeContext)(__ccgo_up(bp + 496))).Fnum_crunch_configs = **(**int32)(__ccgo_up(bp + 392))
  38356 	// Fill in the parameters for the thread workers.
  38357 	if num_crunch_configs_side > 0 {
  38358 		v1 = int32(2)
  38359 	} else {
  38360 		v1 = int32(1)
  38361 	}
  38362 	params_size = v1
  38363 	idx = 0
  38364 	for {
  38365 		if !(idx < params_size) {
  38366 			break
  38367 		}
  38368 		if idx == 0 {
  38369 			v7 = bp + 400
  38370 		} else {
  38371 			v7 = bp + 448
  38372 		}
  38373 		// Create the parameters for each worker.
  38374 		worker = v7
  38375 		if idx == 0 {
  38376 			v8 = bp + 496
  38377 		} else {
  38378 			v8 = bp + 936
  38379 		}
  38380 		param = v8
  38381 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fconfig = config
  38382 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fred_and_blue_always_zero = **(**int32)(__ccgo_up(bp + 396))
  38383 		if idx == 0 {
  38384 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = picture1
  38385 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = (*WebPPicture)(unsafe.Pointer(picture1)).Fstats
  38386 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bw_main
  38387 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_main
  38388 		} else {
  38389 			// Create a side picture (error_code is not thread-safe).
  38390 			if !(WebPPictureView(tls, picture1, 0, 0, (*WebPPicture)(unsafe.Pointer(picture1)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture1)).Fheight, bp+1616) != 0) {
  38391 			}
  38392 			(**(**WebPPicture)(__ccgo_up(bp + 1616))).Fprogress_hook = libc.UintptrFromInt32(0) // Progress hook is not thread-safe.
  38393 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = bp + 1616                  // No need to free a view afterwards.
  38394 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats == libc.UintptrFromInt32(0) {
  38395 				v7 = libc.UintptrFromInt32(0)
  38396 			} else {
  38397 				v7 = bp + 1376
  38398 			}
  38399 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = v7
  38400 			// Create a side bit writer.
  38401 			if !(VP8LBitWriterClone(tls, bw_main, bp+1568) != 0) {
  38402 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38403 				goto Error
  38404 			}
  38405 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bp + 1568
  38406 			// Create a side encoder.
  38407 			enc_side = VP8LEncoderNew(tls, config, bp+1616)
  38408 			if enc_side == libc.UintptrFromInt32(0) || !(EncoderInit(tls, enc_side) != 0) {
  38409 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38410 				goto Error
  38411 			}
  38412 			// Copy the values that were computed for the main encoder.
  38413 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fhisto_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fhisto_bits
  38414 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpredictor_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpredictor_transform_bits
  38415 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fcross_color_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fcross_color_transform_bits
  38416 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpalette_size
  38417 			libc.Xmemcpy(tls, enc_side+104, enc_main+104, uint64(1024))
  38418 			libc.Xmemcpy(tls, enc_side+1128, enc_main+1128, uint64(1024))
  38419 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_side
  38420 		}
  38421 		// Create the workers.
  38422 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FInit})))(tls, worker)
  38423 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = param
  38424 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  38425 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(EncodeStreamHook)
  38426 		goto _6
  38427 	_6:
  38428 		;
  38429 		idx = idx + 1
  38430 	}
  38431 	// Start the second thread if needed.
  38432 	if num_crunch_configs_side != 0 {
  38433 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FReset})))(tls, bp+448) != 0) {
  38434 			WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38435 			goto Error
  38436 		}
  38437 		// This line is here and not in the param initialization above to remove a
  38438 		// Clang static analyzer warning.
  38439 		if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38440 			libc.Xmemcpy(tls, bp+1376, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, uint64(188))
  38441 		}
  38442 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FLaunch})))(tls, bp+448)
  38443 	}
  38444 	// Execute the main thread.
  38445 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp+400)
  38446 	ok_main = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+400)
  38447 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+400)
  38448 	if num_crunch_configs_side != 0 {
  38449 		// Wait for the second thread.
  38450 		ok_side = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+448)
  38451 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+448)
  38452 		if !(ok_main != 0) || !(ok_side != 0) {
  38453 			if (*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK) {
  38454 				WebPEncodingSetError(tls, picture1, (**(**WebPPicture)(__ccgo_up(bp + 1616))).Ferror_code)
  38455 			}
  38456 			goto Error
  38457 		}
  38458 		v7 = bp + 1568
  38459 		v11 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v7)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v7)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v7)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38460 		goto _12
  38461 	_12:
  38462 		v8 = bw_main
  38463 		v14 = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(v8)).Fbuf) + int64(((*VP8LBitWriter)(unsafe.Pointer(v8)).Fused+libc.Int32FromInt32(7))>>libc.Int32FromInt32(3)))
  38464 		goto _15
  38465 	_15:
  38466 		if v11 < v14 {
  38467 			VP8LBitWriterSwap(tls, bw_main, bp+1568)
  38468 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38469 				libc.Xmemcpy(tls, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, bp+1376, uint64(188))
  38470 			}
  38471 		}
  38472 	}
  38473 	goto Error
  38474 Error:
  38475 	;
  38476 	VP8LBitWriterWipeOut(tls, bp+1568)
  38477 	VP8LEncoderDelete(tls, enc_main)
  38478 	VP8LEncoderDelete(tls, enc_side)
  38479 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK))
  38480 }
  38481 
  38482 func VP8LEncodeImage(tls *libc.TLS, config uintptr, picture uintptr) (r int32) {
  38483 	bp := tls.Alloc(64)
  38484 	defer tls.Free(64)
  38485 	var has_alpha, height, initial_size, mb_h, mb_w, width, v1 int32
  38486 	var stats uintptr
  38487 	var _ /* bw at bp+16 */ VP8LBitWriter
  38488 	var _ /* coded_size at bp+0 */ size_t
  38489 	var _ /* percent at bp+8 */ int32
  38490 	_, _, _, _, _, _, _, _ = has_alpha, height, initial_size, mb_h, mb_w, stats, width, v1
  38491 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38492 	if picture == libc.UintptrFromInt32(0) {
  38493 		return 0
  38494 	}
  38495 	if config == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  38496 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  38497 	}
  38498 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38499 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38500 	// Initialize BitWriter with size corresponding to 16 bpp to photo images and
  38501 	// 8 bpp for graphical images.
  38502 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint == int32(WEBP_HINT_GRAPH) {
  38503 		v1 = width * height
  38504 	} else {
  38505 		v1 = width * height * int32(2)
  38506 	}
  38507 	initial_size = v1
  38508 	if !(VP8LBitWriterInit(tls, bp+16, libc.Uint64FromInt32(initial_size)) != 0) {
  38509 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38510 		goto Error
  38511 	}
  38512 	if !!(WebPReportProgress(tls, picture, int32(1), bp+8) != 0) {
  38513 		goto _2
  38514 	}
  38515 	goto UserAbort
  38516 UserAbort:
  38517 	;
  38518 	WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_USER_ABORT))
  38519 	goto Error
  38520 _2:
  38521 	;
  38522 	// Reset stats (for pure lossless coding)
  38523 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38524 		stats = (*WebPPicture)(unsafe.Pointer(picture)).Fstats
  38525 		libc.Xmemset(tls, stats, 0, uint64(188))
  38526 		**(**float32)(__ccgo_up(stats + 4)) = libc.Float32FromFloat32(99)
  38527 		**(**float32)(__ccgo_up(stats + 4 + 1*4)) = libc.Float32FromFloat32(99)
  38528 		**(**float32)(__ccgo_up(stats + 4 + 2*4)) = libc.Float32FromFloat32(99)
  38529 		**(**float32)(__ccgo_up(stats + 4 + 3*4)) = libc.Float32FromFloat32(99)
  38530 		**(**float32)(__ccgo_up(stats + 4 + 4*4)) = libc.Float32FromFloat32(99)
  38531 	}
  38532 	// Write image size.
  38533 	if !(WriteImageSize(tls, picture, bp+16) != 0) {
  38534 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38535 		goto Error
  38536 	}
  38537 	has_alpha = WebPPictureHasTransparency(tls, picture)
  38538 	// Write the non-trivial Alpha flag and lossless version.
  38539 	if !(WriteRealAlphaAndVersion(tls, bp+16, has_alpha) != 0) {
  38540 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38541 		goto Error
  38542 	}
  38543 	if !(WebPReportProgress(tls, picture, int32(2), bp+8) != 0) {
  38544 		goto UserAbort
  38545 	}
  38546 	// Encode main image stream.
  38547 	if !(VP8LEncodeStream(tls, config, picture, bp+16) != 0) {
  38548 		goto Error
  38549 	}
  38550 	if !(WebPReportProgress(tls, picture, int32(99), bp+8) != 0) {
  38551 		goto UserAbort
  38552 	}
  38553 	// Finish the RIFF chunk.
  38554 	if !(WriteImage(tls, picture, bp+16, bp) != 0) {
  38555 		goto Error
  38556 	}
  38557 	if !(WebPReportProgress(tls, picture, int32(100), bp+8) != 0) {
  38558 		goto UserAbort
  38559 	}
  38560 	// Save size.
  38561 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38562 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(picture)).Fstats)) += libc.Int32FromUint64(**(**size_t)(__ccgo_up(bp)))
  38563 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer(picture)).Fstats)).Flossless_size = libc.Int32FromUint64(**(**size_t)(__ccgo_up(bp)))
  38564 	}
  38565 	if (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info != libc.UintptrFromInt32(0) {
  38566 		mb_w = (width + int32(15)) >> int32(4)
  38567 		mb_h = (height + int32(15)) >> int32(4)
  38568 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info, 0, libc.Uint64FromInt32(mb_w*mb_h)*uint64(1))
  38569 	}
  38570 	goto Error
  38571 Error:
  38572 	;
  38573 	if (**(**VP8LBitWriter)(__ccgo_up(bp + 16))).Ferror1 != 0 {
  38574 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38575 	}
  38576 	VP8LBitWriterWipeOut(tls, bp+16)
  38577 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Ferror_code == int32(VP8_ENC_OK))
  38578 }
  38579 
  38580 const VP8L_MAGIC_BYTE4 = 0x2f
  38581 
  38582 //------------------------------------------------------------------------------
  38583 
  38584 // Copyright 2012 Google Inc. All Rights Reserved.
  38585 //
  38586 // Use of this source code is governed by a BSD-style license
  38587 // that can be found in the COPYING file in the root of the source
  38588 // tree. An additional intellectual property rights grant can be found
  38589 // in the file PATENTS. All contributing project authors may
  38590 // be found in the AUTHORS file in the root of the source tree.
  38591 // -----------------------------------------------------------------------------
  38592 //
  38593 // Misc. common utility functions
  38594 //
  38595 // Authors: Skal (pascal.massimino@gmail.com)
  38596 //          Urvang (urvang@google.com)
  38597 
  38598 // Copyright 2011 Google Inc. All Rights Reserved.
  38599 //
  38600 // Use of this source code is governed by a BSD-style license
  38601 // that can be found in the COPYING file in the root of the source
  38602 // tree. An additional intellectual property rights grant can be found
  38603 // in the file PATENTS. All contributing project authors may
  38604 // be found in the AUTHORS file in the root of the source tree.
  38605 // -----------------------------------------------------------------------------
  38606 //
  38607 //   WebP encoder: main interface
  38608 //
  38609 // Author: Skal (pascal.massimino@gmail.com)
  38610 
  38611 // #define PRINT_MEMORY_INFO
  38612 
  38613 //------------------------------------------------------------------------------
  38614 
  38615 func WebPGetEncoderVersion(tls *libc.TLS) (r int32) {
  38616 	return libc.Int32FromInt32(ENC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(ENC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(ENC_REV_VERSION)
  38617 }
  38618 
  38619 //------------------------------------------------------------------------------
  38620 // VP8Encoder
  38621 //------------------------------------------------------------------------------
  38622 
  38623 func ResetSegmentHeader1(tls *libc.TLS, enc uintptr) {
  38624 	var hdr uintptr
  38625 	_ = hdr
  38626 	hdr = enc + 32
  38627 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsegments
  38628 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))
  38629 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fsize = 0
  38630 }
  38631 
  38632 func ResetFilterHeader(tls *libc.TLS, enc uintptr) {
  38633 	var hdr uintptr
  38634 	_ = hdr
  38635 	hdr = enc + 16
  38636 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple = int32(1)
  38637 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel = 0
  38638 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness = 0
  38639 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta = 0
  38640 }
  38641 
  38642 func ResetBoundaryPredictions(tls *libc.TLS, enc uintptr) {
  38643 	var i int32
  38644 	var left, top uintptr
  38645 	_, _, _ = i, left, top
  38646 	top = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  38647 	left = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr(1)
  38648 	i = -int32(1)
  38649 	for {
  38650 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) {
  38651 			break
  38652 		}
  38653 		**(**uint8_t)(__ccgo_up(top + uintptr(i))) = uint8(B_DC_PRED)
  38654 		goto _1
  38655 	_1:
  38656 		;
  38657 		i = i + 1
  38658 	}
  38659 	i = 0
  38660 	for {
  38661 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  38662 			break
  38663 		}
  38664 		**(**uint8_t)(__ccgo_up(left + uintptr(i*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w))) = uint8(B_DC_PRED)
  38665 		goto _2
  38666 	_2:
  38667 		;
  38668 		i = i + 1
  38669 	}
  38670 	**(**uint32_t)(__ccgo_up((*VP8Encoder)(unsafe.Pointer(enc)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)) = uint32(0) // constant
  38671 }
  38672 
  38673 // Mapping from config->method to coding tools used.
  38674 //-------------------+---+---+---+---+---+---+---+
  38675 //   Method          | 0 | 1 | 2 | 3 |(4)| 5 | 6 |
  38676 //-------------------+---+---+---+---+---+---+---+
  38677 // fast probe        | x |   |   | x |   |   |   |
  38678 //-------------------+---+---+---+---+---+---+---+
  38679 // dynamic proba     | ~ | x | x | x | x | x | x |
  38680 //-------------------+---+---+---+---+---+---+---+
  38681 // fast mode analysis|[x]|[x]|   |   | x | x | x |
  38682 //-------------------+---+---+---+---+---+---+---+
  38683 // basic rd-opt      |   |   |   | x | x | x | x |
  38684 //-------------------+---+---+---+---+---+---+---+
  38685 // disto-refine i4/16| x | x | x |   |   |   |   |
  38686 //-------------------+---+---+---+---+---+---+---+
  38687 // disto-refine uv   |   | x | x |   |   |   |   |
  38688 //-------------------+---+---+---+---+---+---+---+
  38689 // rd-opt i4/16      |   |   | ~ | x | x | x | x |
  38690 //-------------------+---+---+---+---+---+---+---+
  38691 // token buffer (opt)|   |   |   | x | x | x | x |
  38692 //-------------------+---+---+---+---+---+---+---+
  38693 // Trellis           |   |   |   |   |   | x |Ful|
  38694 //-------------------+---+---+---+---+---+---+---+
  38695 // full-SNS          |   |   |   |   | x | x | x |
  38696 //-------------------+---+---+---+---+---+---+---+
  38697 
  38698 func MapConfigToTools(tls *libc.TLS, enc uintptr) {
  38699 	var config uintptr
  38700 	var limit, method, v1, v2, v3 int32
  38701 	_, _, _, _, _, _ = config, limit, method, v1, v2, v3
  38702 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  38703 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  38704 	limit = int32(100) - (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit
  38705 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmethod = method
  38706 	if method >= int32(6) {
  38707 		v1 = int32(RD_OPT_TRELLIS_ALL)
  38708 	} else {
  38709 		if method >= int32(5) {
  38710 			v2 = int32(RD_OPT_TRELLIS)
  38711 		} else {
  38712 			if method >= int32(3) {
  38713 				v3 = int32(RD_OPT_BASIC)
  38714 			} else {
  38715 				v3 = int32(RD_OPT_NONE)
  38716 			}
  38717 			v2 = v3
  38718 		}
  38719 		v1 = v2
  38720 	}
  38721 	(*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level = v1
  38722 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits = libc.Int32FromInt32(256) * libc.Int32FromInt32(16) * libc.Int32FromInt32(16) * (limit * limit) / (libc.Int32FromInt32(100) * libc.Int32FromInt32(100)) // ... modulated with a quadratic curve.
  38723 	// partition0 = 512k max.
  38724 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_header_limit = int32(libc.Int64FromInt32(256) * libc.Int64FromInt32(510) * libc.Int64FromInt32(8) * libc.Int64FromInt32(1024) / int64((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h))
  38725 	(*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level = (*WebPConfig)(unsafe.Pointer(config)).Fthread_level
  38726 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ftarget_size > 0 || (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR > libc.Float32FromInt32(0))
  38727 	if !((*WebPConfig)(unsafe.Pointer(config)).Flow_memory != 0) {
  38728 		(*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens = libc.BoolInt32((*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level >= int32(RD_OPT_BASIC)) // need rd stats
  38729 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0 {
  38730 			(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) // doesn't work with multi-partition
  38731 		}
  38732 	}
  38733 }
  38734 
  38735 // Memory scaling with dimensions:
  38736 //  memory (bytes) ~= 2.25 * w + 0.0625 * w * h
  38737 //
  38738 // Typical memory footprint (614x440 picture)
  38739 //              encoder: 22111
  38740 //                 info: 4368
  38741 //                preds: 17741
  38742 //          top samples: 1263
  38743 //             non-zero: 175
  38744 //             lf-stats: 0
  38745 //                total: 45658
  38746 // Transient object sizes:
  38747 //       VP8EncIterator: 3360
  38748 //         VP8ModeScore: 872
  38749 //       VP8SegmentInfo: 732
  38750 //          VP8EncProba: 18352
  38751 //              LFStats: 2048
  38752 // Picture size (yuv): 419328
  38753 
  38754 func InitVP8Encoder(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  38755 	var enc, mem, v3 uintptr
  38756 	var info_size, lf_stats_size, nz_size, preds_size, samples_size, top_derr_size size_t
  38757 	var mb_h, mb_w, preds_h, preds_w, top_stride, use_filter, v5, v6 int32
  38758 	var scale float32
  38759 	var size uint64_t
  38760 	var v1, v2 uint64
  38761 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, info_size, lf_stats_size, mb_h, mb_w, mem, nz_size, preds_h, preds_size, preds_w, samples_size, scale, size, top_derr_size, top_stride, use_filter, v1, v2, v3, v5, v6
  38762 	use_filter = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > 0)
  38763 	mb_w = ((*WebPPicture)(unsafe.Pointer(picture)).Fwidth + int32(15)) >> int32(4)
  38764 	mb_h = ((*WebPPicture)(unsafe.Pointer(picture)).Fheight + int32(15)) >> int32(4)
  38765 	preds_w = int32(4)*mb_w + int32(1)
  38766 	preds_h = int32(4)*mb_h + int32(1)
  38767 	preds_size = libc.Uint64FromInt32(preds_w*preds_h) * uint64(1)
  38768 	top_stride = mb_w * int32(16)
  38769 	nz_size = libc.Uint64FromInt32(mb_w+libc.Int32FromInt32(1))*uint64(4) + uint64(WEBP_ALIGN_CST)
  38770 	info_size = libc.Uint64FromInt32(mb_w*mb_h) * uint64(4)
  38771 	samples_size = libc.Uint64FromInt32(int32(2)*top_stride)*uint64(1) + uint64(WEBP_ALIGN_CST)
  38772 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter != 0 {
  38773 		v1 = libc.Uint64FromInt64(2048) + libc.Uint64FromInt32(WEBP_ALIGN_CST)
  38774 	} else {
  38775 		v1 = uint64(0)
  38776 	} // align all
  38777 	lf_stats_size = v1
  38778 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality <= libc.Float32FromInt32(ERROR_DIFFUSION_QUALITY) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(1) {
  38779 		v2 = libc.Uint64FromInt32(mb_w) * uint64(4)
  38780 	} else {
  38781 		v2 = uint64(0)
  38782 	}
  38783 	top_derr_size = v2
  38784 	size = libc.Uint64FromInt64(23704) + libc.Uint64FromInt32(WEBP_ALIGN_CST) + info_size + preds_size + samples_size + top_derr_size + nz_size + lf_stats_size // autofilter stats
  38785 	mem = WebPSafeMalloc(tls, size, uint64(1))
  38786 	if mem == libc.UintptrFromInt32(0) {
  38787 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38788 		return libc.UintptrFromInt32(0)
  38789 	}
  38790 	enc = mem
  38791 	mem = uintptr((uint64(mem+libc.UintptrFromInt64(23704)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  38792 	libc.Xmemset(tls, enc, 0, uint64(23704))
  38793 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) << (*WebPConfig)(unsafe.Pointer(config)).Fpartitions
  38794 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w = mb_w
  38795 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h = mb_h
  38796 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w = preds_w
  38797 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info = mem
  38798 	mem = mem + uintptr(info_size)
  38799 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds = mem + uintptr(1) + uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  38800 	mem = mem + uintptr(preds_size)
  38801 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnz = uintptr(1)*4 + uintptr((uint64(mem)+libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  38802 	mem = mem + uintptr(nz_size)
  38803 	if lf_stats_size != 0 {
  38804 		v3 = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  38805 	} else {
  38806 		v3 = libc.UintptrFromInt32(0)
  38807 	}
  38808 	(*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats = v3
  38809 	mem = mem + uintptr(lf_stats_size)
  38810 	// top samples (all 16-aligned)
  38811 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  38812 	(*VP8Encoder)(unsafe.Pointer(enc)).Fy_top = mem
  38813 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top + uintptr(top_stride)
  38814 	mem = mem + uintptr(int32(2)*top_stride)
  38815 	if top_derr_size != 0 {
  38816 		v3 = mem
  38817 	} else {
  38818 		v3 = libc.UintptrFromInt32(0)
  38819 	}
  38820 	(*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr = v3
  38821 	mem = mem + uintptr(top_derr_size)
  38822 	(*VP8Encoder)(unsafe.Pointer(enc)).Fconfig = config
  38823 	if use_filter != 0 {
  38824 		if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type == int32(1) {
  38825 			v6 = 0
  38826 		} else {
  38827 			v6 = int32(1)
  38828 		}
  38829 		v5 = v6
  38830 	} else {
  38831 		v5 = int32(2)
  38832 	}
  38833 	(*VP8Encoder)(unsafe.Pointer(enc)).Fprofile = v5
  38834 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpic = picture
  38835 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpercent = 0
  38836 	MapConfigToTools(tls, enc)
  38837 	VP8EncDspInit(tls)
  38838 	VP8DefaultProbas(tls, enc)
  38839 	ResetSegmentHeader1(tls, enc)
  38840 	ResetFilterHeader(tls, enc)
  38841 	ResetBoundaryPredictions(tls, enc)
  38842 	VP8EncDspCostInit(tls)
  38843 	VP8EncInitAlpha(tls, enc)
  38844 	// lower quality means smaller output -> we modulate a little the page
  38845 	// size based on quality. This is just a crude 1rst-order prediction.
  38846 	scale = libc.Float32FromFloat32(1) + float32((*WebPConfig)(unsafe.Pointer(config)).Fquality*libc.Float32FromFloat32(5))/libc.Float32FromFloat32(100) // in [1,6]
  38847 	VP8TBufferInit(tls, enc+496, int32(float32(float32(mb_w*mb_h*libc.Int32FromInt32(4))*scale)))
  38848 	return enc
  38849 }
  38850 
  38851 func DeleteVP8Encoder(tls *libc.TLS, enc uintptr) (r int32) {
  38852 	var ok int32
  38853 	_ = ok
  38854 	ok = int32(1)
  38855 	if enc != libc.UintptrFromInt32(0) {
  38856 		ok = VP8EncDeleteAlpha(tls, enc)
  38857 		VP8TBufferClear(tls, enc+496)
  38858 		WebPSafeFree(tls, enc)
  38859 	}
  38860 	return ok
  38861 }
  38862 
  38863 //------------------------------------------------------------------------------
  38864 
  38865 func GetPSNR2(tls *libc.TLS, err uint64_t, size uint64_t) (r float64) {
  38866 	var v1 float64
  38867 	_ = v1
  38868 	if err > uint64(0) && size > uint64(0) {
  38869 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(err)))
  38870 	} else {
  38871 		v1 = float64(99)
  38872 	}
  38873 	return v1
  38874 }
  38875 
  38876 func FinalizePSNR(tls *libc.TLS, enc uintptr) {
  38877 	var size uint64_t
  38878 	var sse, stats uintptr
  38879 	_, _, _ = size, sse, stats
  38880 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  38881 	size = (*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count
  38882 	sse = enc + 23512
  38883 	**(**float32)(__ccgo_up(stats + 4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse)), size))
  38884 	**(**float32)(__ccgo_up(stats + 4 + 1*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 1*8)), size/uint64(4)))
  38885 	**(**float32)(__ccgo_up(stats + 4 + 2*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 2*8)), size/uint64(4)))
  38886 	**(**float32)(__ccgo_up(stats + 4 + 3*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse))+**(**uint64_t)(__ccgo_up(sse + 1*8))+**(**uint64_t)(__ccgo_up(sse + 2*8)), size*uint64(3)/uint64(2)))
  38887 	**(**float32)(__ccgo_up(stats + 4 + 4*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 3*8)), size))
  38888 }
  38889 
  38890 func StoreStats(tls *libc.TLS, enc uintptr) {
  38891 	var i, s int32
  38892 	var stats uintptr
  38893 	_, _, _ = i, s, stats
  38894 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  38895 	if stats != libc.UintptrFromInt32(0) {
  38896 		i = 0
  38897 		for {
  38898 			if !(i < int32(NUM_MB_SEGMENTS)) {
  38899 				break
  38900 			}
  38901 			**(**int32)(__ccgo_up(stats + 124 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Ffstrength
  38902 			**(**int32)(__ccgo_up(stats + 108 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant
  38903 			s = 0
  38904 			for {
  38905 				if !(s <= int32(2)) {
  38906 					break
  38907 				}
  38908 				**(**int32)(__ccgo_up(stats + 44 + uintptr(s)*16 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23556 + uintptr(s)*16 + uintptr(i)*4))
  38909 				goto _2
  38910 			_2:
  38911 				;
  38912 				s = s + 1
  38913 			}
  38914 			goto _1
  38915 		_1:
  38916 			;
  38917 			i = i + 1
  38918 		}
  38919 		FinalizePSNR(tls, enc)
  38920 		(*WebPAuxStats)(unsafe.Pointer(stats)).Fcoded_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size
  38921 		i = 0
  38922 		for {
  38923 			if !(i < int32(3)) {
  38924 				break
  38925 			}
  38926 			**(**int32)(__ccgo_up(stats + 24 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23604 + uintptr(i)*4))
  38927 			goto _3
  38928 		_3:
  38929 			;
  38930 			i = i + 1
  38931 		}
  38932 	}
  38933 }
  38934 
  38935 func WebPEncodingSetError(tls *libc.TLS, pic uintptr, error1 WebPEncodingError1) (r int32) {
  38936 	// The oldest error reported takes precedence over the new one.
  38937 	if (*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK) {
  38938 		(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = error1
  38939 	}
  38940 	return 0
  38941 }
  38942 
  38943 func WebPReportProgress(tls *libc.TLS, pic uintptr, percent int32, percent_store uintptr) (r int32) {
  38944 	if percent_store != libc.UintptrFromInt32(0) && percent != **(**int32)(__ccgo_up(percent_store)) {
  38945 		**(**int32)(__ccgo_up(percent_store)) = percent
  38946 		if (*WebPPicture)(unsafe.Pointer(pic)).Fprogress_hook != 0 && !((*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fprogress_hook})))(tls, percent, pic) != 0) {
  38947 			// user abort requested
  38948 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_USER_ABORT))
  38949 		}
  38950 	}
  38951 	return int32(1) // ok
  38952 }
  38953 
  38954 //------------------------------------------------------------------------------
  38955 
  38956 func WebPEncode(tls *libc.TLS, config uintptr, pic uintptr) (r int32) {
  38957 	var dithering, x, x2 float32
  38958 	var enc uintptr
  38959 	var ok int32
  38960 	_, _, _, _, _ = dithering, enc, ok, x, x2
  38961 	ok = 0
  38962 	if pic == libc.UintptrFromInt32(0) {
  38963 		return 0
  38964 	}
  38965 	(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = int32(VP8_ENC_OK) // all ok so far
  38966 	if config == libc.UintptrFromInt32(0) {                             // bad params
  38967 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  38968 	}
  38969 	if !(WebPValidateConfig(tls, config) != 0) {
  38970 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  38971 	}
  38972 	if !(WebPValidatePicture(tls, pic) != 0) {
  38973 		return 0
  38974 	}
  38975 	if (*WebPPicture)(unsafe.Pointer(pic)).Fwidth > int32(WEBP_MAX_DIMENSION) || (*WebPPicture)(unsafe.Pointer(pic)).Fheight > int32(WEBP_MAX_DIMENSION) {
  38976 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  38977 	}
  38978 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  38979 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fstats, 0, uint64(188))
  38980 	}
  38981 	if !((*WebPConfig)(unsafe.Pointer(config)).Flossless != 0) {
  38982 		enc = libc.UintptrFromInt32(0)
  38983 		if (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 || (*WebPPicture)(unsafe.Pointer(pic)).Fy == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(pic)).Fu == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(pic)).Fv == libc.UintptrFromInt32(0) {
  38984 			// Make sure we have YUVA samples.
  38985 			if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv != 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(4) != 0 {
  38986 				if !(WebPPictureSharpARGBToYUVA(tls, pic) != 0) {
  38987 					return 0
  38988 				}
  38989 			} else {
  38990 				dithering = libc.Float32FromFloat32(0)
  38991 				if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(2) != 0 {
  38992 					x = (*WebPConfig)(unsafe.Pointer(config)).Fquality / libc.Float32FromFloat32(100)
  38993 					x2 = float32(x * x)
  38994 					// slowly decreasing from max dithering at low quality (q->0)
  38995 					// to 0.5 dithering amplitude at high quality (q->100)
  38996 					dithering = libc.Float32FromFloat32(1) + float32(float32((libc.Float32FromFloat32(0.5)-libc.Float32FromFloat32(1))*x2)*x2)
  38997 				}
  38998 				if !(WebPPictureARGBToYUVADithered(tls, pic, int32(WEBP_YUV420), dithering) != 0) {
  38999 					return 0
  39000 				}
  39001 			}
  39002 		}
  39003 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39004 			WebPCleanupTransparentArea(tls, pic)
  39005 		}
  39006 		enc = InitVP8Encoder(tls, config, pic)
  39007 		if enc == libc.UintptrFromInt32(0) {
  39008 			return 0
  39009 		} // pic->error is already set.
  39010 		// Note: each of the tasks below account for 20% in the progress report.
  39011 		ok = VP8EncAnalyze(tls, enc)
  39012 		// Analysis is done, proceed to actual coding.
  39013 		ok = libc.BoolInt32(ok != 0 && VP8EncStartAlpha(tls, enc) != 0) // possibly done in parallel
  39014 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0) {
  39015 			ok = libc.BoolInt32(ok != 0 && VP8EncLoop(tls, enc) != 0)
  39016 		} else {
  39017 			ok = libc.BoolInt32(ok != 0 && VP8EncTokenLoop(tls, enc) != 0)
  39018 		}
  39019 		ok = libc.BoolInt32(ok != 0 && VP8EncFinishAlpha(tls, enc) != 0)
  39020 		ok = libc.BoolInt32(ok != 0 && VP8EncWrite(tls, enc) != 0)
  39021 		StoreStats(tls, enc)
  39022 		if !(ok != 0) {
  39023 			VP8EncFreeBitWriters(tls, enc)
  39024 		}
  39025 		ok = ok & DeleteVP8Encoder(tls, enc) // must always be called, even if !ok
  39026 	} else {
  39027 		// Make sure we have ARGB samples.
  39028 		if (*WebPPicture)(unsafe.Pointer(pic)).Fargb == libc.UintptrFromInt32(0) && !(WebPPictureYUVAToARGB(tls, pic) != 0) {
  39029 			return 0
  39030 		}
  39031 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39032 			WebPReplaceTransparentPixels(tls, pic, uint32(0x000000))
  39033 		}
  39034 		ok = VP8LEncodeImage(tls, config, pic) // Sets pic->error in case of problem.
  39035 	}
  39036 	return ok
  39037 }
  39038 
  39039 const VP8L_LOG8_WBITS = 4
  39040 
  39041 // Copyright 2010 Google Inc. All Rights Reserved.
  39042 //
  39043 // Use of this source code is governed by a BSD-style license
  39044 // that can be found in the COPYING file in the root of the source
  39045 // tree. An additional intellectual property rights grant can be found
  39046 // in the file PATENTS. All contributing project authors may
  39047 // be found in the AUTHORS file in the root of the source tree.
  39048 // -----------------------------------------------------------------------------
  39049 //
  39050 // Boolean decoder
  39051 //
  39052 // Author: Skal (pascal.massimino@gmail.com)
  39053 //         Vikas Arora (vikaas.arora@gmail.com)
  39054 
  39055 // Copyright 2014 Google Inc. All Rights Reserved.
  39056 //
  39057 // Use of this source code is governed by a BSD-style license
  39058 // that can be found in the COPYING file in the root of the source
  39059 // tree. An additional intellectual property rights grant can be found
  39060 // in the file PATENTS. All contributing project authors may
  39061 // be found in the AUTHORS file in the root of the source tree.
  39062 // -----------------------------------------------------------------------------
  39063 //
  39064 // Endian related functions.
  39065 
  39066 // Copyright 2012 Google Inc. All Rights Reserved.
  39067 //
  39068 // Use of this source code is governed by a BSD-style license
  39069 // that can be found in the COPYING file in the root of the source
  39070 // tree. An additional intellectual property rights grant can be found
  39071 // in the file PATENTS. All contributing project authors may
  39072 // be found in the AUTHORS file in the root of the source tree.
  39073 // -----------------------------------------------------------------------------
  39074 //
  39075 // Misc. common utility functions
  39076 //
  39077 // Authors: Skal (pascal.massimino@gmail.com)
  39078 //          Urvang (urvang@google.com)
  39079 
  39080 //------------------------------------------------------------------------------
  39081 // VP8BitReader
  39082 
  39083 func VP8BitReaderSetBuffer(tls *libc.TLS, br uintptr, start uintptr, size size_t) {
  39084 	var v1 uintptr
  39085 	_ = v1
  39086 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf = start
  39087 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end = start + uintptr(size)
  39088 	if size >= uint64(8) {
  39089 		v1 = start + uintptr(size) - uintptr(8) + uintptr(1)
  39090 	} else {
  39091 		v1 = start
  39092 	}
  39093 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_max = v1
  39094 }
  39095 
  39096 func VP8InitBitReader(tls *libc.TLS, br1 uintptr, start uintptr, size size_t) {
  39097 	bp := tls.Alloc(16)
  39098 	defer tls.Free(16)
  39099 	var bits bit_t
  39100 	var v1 uintptr
  39101 	var v2 uint64_t
  39102 	var _ /* in_bits at bp+0 */ lbit_t
  39103 	_, _, _ = bits, v1, v2
  39104 	// limit ensured by format and upstream checks
  39105 	(*VP8BitReader)(unsafe.Pointer(br1)).Frange1 = libc.Uint32FromInt32(libc.Int32FromInt32(255) - libc.Int32FromInt32(1))
  39106 	(*VP8BitReader)(unsafe.Pointer(br1)).Fvalue = uint64(0)
  39107 	(*VP8BitReader)(unsafe.Pointer(br1)).Fbits = -int32(8) // to load the very first 8bits
  39108 	(*VP8BitReader)(unsafe.Pointer(br1)).Feof = 0
  39109 	VP8BitReaderSetBuffer(tls, br1, start, size)
  39110 	v1 = br1
  39111 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf_max {
  39112 		libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf, uint64(8))
  39113 		**(**uintptr)(__ccgo_up(v1 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39114 		v2 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39115 		goto _3
  39116 	_3:
  39117 		bits = v2
  39118 		bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39119 		(*VP8BitReader)(unsafe.Pointer(v1)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v1)).Fvalue<<libc.Int32FromInt32(BITS)
  39120 		**(**int32)(__ccgo_up(v1 + 12)) += int32(BITS)
  39121 	} else {
  39122 		VP8LoadFinalBytes(tls, v1)
  39123 	}
  39124 }
  39125 
  39126 func VP8RemapBitReader(tls *libc.TLS, br uintptr, offset ptrdiff_t) {
  39127 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf != libc.UintptrFromInt32(0) {
  39128 		**(**uintptr)(__ccgo_up(br + 16)) += uintptr(offset)
  39129 		**(**uintptr)(__ccgo_up(br + 24)) += uintptr(offset)
  39130 		**(**uintptr)(__ccgo_up(br + 32)) += uintptr(offset)
  39131 	}
  39132 }
  39133 
  39134 func VP8LoadFinalBytes(tls *libc.TLS, br uintptr) {
  39135 	var v1, v2 uintptr
  39136 	_, _ = v1, v2
  39137 	// Only read 8bits at a time
  39138 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf < (*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end {
  39139 		**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39140 		v2 = br + 16
  39141 		v1 = *(*uintptr)(unsafe.Pointer(v2))
  39142 		*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  39143 		(*VP8BitReader)(unsafe.Pointer(br)).Fvalue = uint64(**(**uint8_t)(__ccgo_up(v1))) | (*VP8BitReader)(unsafe.Pointer(br)).Fvalue<<libc.Int32FromInt32(8)
  39144 	} else {
  39145 		if !((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0) {
  39146 			**(**bit_t)(__ccgo_up(br)) <<= uint64(8)
  39147 			**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39148 			(*VP8BitReader)(unsafe.Pointer(br)).Feof = int32(1)
  39149 		} else {
  39150 			(*VP8BitReader)(unsafe.Pointer(br)).Fbits = 0 // This is to avoid undefined behaviour with shifts.
  39151 		}
  39152 	}
  39153 }
  39154 
  39155 //------------------------------------------------------------------------------
  39156 // Higher-level calls
  39157 
  39158 func VP8GetValue(tls *libc.TLS, br2 uintptr, bits1 int32) (r uint32_t) {
  39159 	bp := tls.Alloc(16)
  39160 	defer tls.Free(16)
  39161 	var bit, pos, shift, v1, v6, v8 int32
  39162 	var bits bit_t
  39163 	var range1, split, value range_t
  39164 	var v uint32_t
  39165 	var v2, v3 uintptr
  39166 	var v4 uint64_t
  39167 	var _ /* in_bits at bp+0 */ lbit_t
  39168 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, pos, range1, shift, split, v, value, v1, v2, v3, v4, v6, v8
  39169 	v = uint32(0)
  39170 	for {
  39171 		v1 = bits1
  39172 		bits1 = bits1 - 1
  39173 		if !(v1 > 0) {
  39174 			break
  39175 		}
  39176 		v2 = br2
  39177 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  39178 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  39179 			v3 = v2
  39180 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  39181 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  39182 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39183 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39184 				goto _5
  39185 			_5:
  39186 				bits = v4
  39187 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39188 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  39189 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  39190 			} else {
  39191 				VP8LoadFinalBytes(tls, v3)
  39192 			}
  39193 		}
  39194 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  39195 		split = range1 * libc.Uint32FromInt32(int32(0x80)) >> int32(8)
  39196 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  39197 		bit = libc.BoolInt32(value > split)
  39198 		if bit != 0 {
  39199 			range1 = range1 - split
  39200 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  39201 		} else {
  39202 			range1 = split + uint32(1)
  39203 		}
  39204 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  39205 		goto _7
  39206 	_7:
  39207 		shift = int32(7) ^ v6
  39208 		range1 = range1 << libc.Uint32FromInt32(shift)
  39209 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  39210 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  39211 		v8 = bit
  39212 		goto _9
  39213 	_9:
  39214 		v = v | libc.Uint32FromInt32(v8<<bits1)
  39215 	}
  39216 	return v
  39217 }
  39218 
  39219 func VP8GetSignedValue(tls *libc.TLS, br uintptr, bits int32) (r int32_t) {
  39220 	var value, v1 int32
  39221 	_, _ = value, v1
  39222 	value = libc.Int32FromUint32(VP8GetValue(tls, br, bits))
  39223 	if VP8GetValue(tls, br, int32(1)) != 0 {
  39224 		v1 = -value
  39225 	} else {
  39226 		v1 = value
  39227 	}
  39228 	return v1
  39229 }
  39230 
  39231 //------------------------------------------------------------------------------
  39232 // VP8LBitReader
  39233 
  39234 var kBitMask = [25]uint32_t{
  39235 	1:  uint32(0x000001),
  39236 	2:  uint32(0x000003),
  39237 	3:  uint32(0x000007),
  39238 	4:  uint32(0x00000f),
  39239 	5:  uint32(0x00001f),
  39240 	6:  uint32(0x00003f),
  39241 	7:  uint32(0x00007f),
  39242 	8:  uint32(0x0000ff),
  39243 	9:  uint32(0x0001ff),
  39244 	10: uint32(0x0003ff),
  39245 	11: uint32(0x0007ff),
  39246 	12: uint32(0x000fff),
  39247 	13: uint32(0x001fff),
  39248 	14: uint32(0x003fff),
  39249 	15: uint32(0x007fff),
  39250 	16: uint32(0x00ffff),
  39251 	17: uint32(0x01ffff),
  39252 	18: uint32(0x03ffff),
  39253 	19: uint32(0x07ffff),
  39254 	20: uint32(0x0fffff),
  39255 	21: uint32(0x1fffff),
  39256 	22: uint32(0x3fffff),
  39257 	23: uint32(0x7fffff),
  39258 	24: uint32(0xffffff),
  39259 }
  39260 
  39261 func VP8LInitBitReader(tls *libc.TLS, br uintptr, start uintptr, length size_t) {
  39262 	var i size_t
  39263 	var value vp8l_val_t
  39264 	_, _ = i, value
  39265 	value = uint64(0)
  39266 	// can't happen with a RIFF chunk.
  39267 	(*VP8LBitReader)(unsafe.Pointer(br)).Flen1 = length
  39268 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = uint64(0)
  39269 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0
  39270 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = 0
  39271 	if length > uint64(8) {
  39272 		length = uint64(8)
  39273 	}
  39274 	i = uint64(0)
  39275 	for {
  39276 		if !(i < length) {
  39277 			break
  39278 		}
  39279 		value = value | uint64(**(**uint8_t)(__ccgo_up(start + uintptr(i))))<<(uint64(8)*i)
  39280 		goto _1
  39281 	_1:
  39282 		;
  39283 		i = i + 1
  39284 	}
  39285 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = value
  39286 	(*VP8LBitReader)(unsafe.Pointer(br)).Fpos = length
  39287 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbuf = start
  39288 }
  39289 
  39290 func VP8LBitReaderSetBuffer(tls *libc.TLS, br1 uintptr, buf uintptr, len1 size_t) {
  39291 	var v1 uintptr
  39292 	var v2 int32
  39293 	var v4 bool
  39294 	_, _, _ = v1, v2, v4
  39295 	// can't happen with a RIFF chunk.
  39296 	(*VP8LBitReader)(unsafe.Pointer(br1)).Fbuf = buf
  39297 	(*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 = len1
  39298 	// 'pos' > 'len' should be considered a param error.
  39299 	if v4 = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos > (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1; !v4 {
  39300 		v1 = br1
  39301 		v2 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v1)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v1)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v1)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos > int32(VP8L_LBITS))
  39302 		goto _3
  39303 	_3:
  39304 	}
  39305 	(*VP8LBitReader)(unsafe.Pointer(br1)).Feos = libc.BoolInt32(v4 || v2 != 0)
  39306 }
  39307 
  39308 func VP8LSetEndOfStream(tls *libc.TLS, br uintptr) {
  39309 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = int32(1)
  39310 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0 // To avoid undefined behaviour with shifts.
  39311 }
  39312 
  39313 // C documentation
  39314 //
  39315 //	// If not at EOS, reload up to VP8L_LBITS byte-by-byte
  39316 func ShiftBytes(tls *libc.TLS, br1 uintptr) {
  39317 	var v1 uintptr
  39318 	var v2 int32
  39319 	_, _ = v1, v2
  39320 	for (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos >= int32(8) && (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos < (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 {
  39321 		**(**vp8l_val_t)(__ccgo_up(br1)) >>= uint64(8)
  39322 		**(**vp8l_val_t)(__ccgo_up(br1)) |= uint64(**(**uint8_t)(__ccgo_up((*VP8LBitReader)(unsafe.Pointer(br1)).Fbuf + uintptr((*VP8LBitReader)(unsafe.Pointer(br1)).Fpos)))) << (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(8))
  39323 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fpos = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos + 1
  39324 		**(**int32)(__ccgo_up(br1 + 32)) -= int32(8)
  39325 	}
  39326 	v1 = br1
  39327 	v2 = libc.BoolInt32((*VP8LBitReader)(unsafe.Pointer(v1)).Feos != 0 || (*VP8LBitReader)(unsafe.Pointer(v1)).Fpos == (*VP8LBitReader)(unsafe.Pointer(v1)).Flen1 && (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos > int32(VP8L_LBITS))
  39328 	goto _3
  39329 _3:
  39330 	if v2 != 0 {
  39331 		VP8LSetEndOfStream(tls, br1)
  39332 	}
  39333 }
  39334 
  39335 func VP8LDoFillBitWindow(tls *libc.TLS, br uintptr) {
  39336 	bp := tls.Alloc(16)
  39337 	defer tls.Free(16)
  39338 	var v1 uint32_t
  39339 	var _ /* A at bp+0 */ uint32_t
  39340 	_ = v1
  39341 	if (*VP8LBitReader)(unsafe.Pointer(br)).Fpos+uint64(8) < (*VP8LBitReader)(unsafe.Pointer(br)).Flen1 {
  39342 		**(**vp8l_val_t)(__ccgo_up(br)) >>= uint64(VP8L_WBITS)
  39343 		**(**int32)(__ccgo_up(br + 32)) -= int32(VP8L_WBITS)
  39344 		libc.Xmemcpy(tls, bp, (*VP8LBitReader)(unsafe.Pointer(br)).Fbuf+uintptr((*VP8LBitReader)(unsafe.Pointer(br)).Fpos), uint64(4))
  39345 		v1 = **(**uint32_t)(__ccgo_up(bp))
  39346 		goto _2
  39347 	_2:
  39348 		**(**vp8l_val_t)(__ccgo_up(br)) |= uint64(v1) << (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(VP8L_WBITS))
  39349 		**(**size_t)(__ccgo_up(br + 24)) += uint64(VP8L_LOG8_WBITS)
  39350 		return
  39351 	}
  39352 	ShiftBytes(tls, br) // Slow path.
  39353 }
  39354 
  39355 func VP8LReadBits(tls *libc.TLS, br1 uintptr, n_bits int32) (r uint32_t) {
  39356 	var new_bits int32
  39357 	var val, v2 uint32_t
  39358 	var v1 uintptr
  39359 	_, _, _, _ = new_bits, val, v1, v2
  39360 	// Flag an error if end_of_stream or n_bits is more than allowed limit.
  39361 	if !((*VP8LBitReader)(unsafe.Pointer(br1)).Feos != 0) && n_bits <= int32(VP8L_MAX_NUM_BIT_READ) {
  39362 		v1 = br1
  39363 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  39364 		goto _3
  39365 	_3:
  39366 		val = v2 & kBitMask[n_bits]
  39367 		new_bits = (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos + n_bits
  39368 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos = new_bits
  39369 		ShiftBytes(tls, br1)
  39370 		return val
  39371 	} else {
  39372 		VP8LSetEndOfStream(tls, br1)
  39373 		return uint32(0)
  39374 	}
  39375 	return r
  39376 }
  39377 
  39378 const MIN_EXTRA_SIZE = 32768
  39379 
  39380 //------------------------------------------------------------------------------
  39381 
  39382 //------------------------------------------------------------------------------
  39383 // VP8BitWriter
  39384 
  39385 func BitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  39386 	var needed_size, new_size size_t
  39387 	var needed_size_64b uint64_t
  39388 	var new_buf uintptr
  39389 	_, _, _, _ = needed_size, needed_size_64b, new_buf, new_size
  39390 	needed_size_64b = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos + extra_size
  39391 	needed_size = needed_size_64b
  39392 	if needed_size_64b != needed_size {
  39393 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39394 		return 0
  39395 	}
  39396 	if needed_size <= (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos {
  39397 		return int32(1)
  39398 	}
  39399 	// If the following line wraps over 32bit, the test just after will catch it.
  39400 	new_size = uint64(2) * (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos
  39401 	if new_size < needed_size {
  39402 		new_size = needed_size
  39403 	}
  39404 	if new_size < uint64(1024) {
  39405 		new_size = uint64(1024)
  39406 	}
  39407 	new_buf = WebPSafeMalloc(tls, uint64(1), new_size)
  39408 	if new_buf == libc.UintptrFromInt32(0) {
  39409 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39410 		return 0
  39411 	}
  39412 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos > uint64(0) {
  39413 		libc.Xmemcpy(tls, new_buf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos)
  39414 	}
  39415 	WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  39416 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = new_buf
  39417 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = new_size
  39418 	return int32(1)
  39419 }
  39420 
  39421 func Flush(tls *libc.TLS, bw uintptr) {
  39422 	var bits int32_t
  39423 	var pos, v3 size_t
  39424 	var s, value, v1 int32
  39425 	_, _, _, _, _, _ = bits, pos, s, value, v1, v3
  39426 	s = int32(8) + (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits
  39427 	bits = (*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue >> s
  39428 	**(**int32_t)(__ccgo_up(bw + 4)) -= bits << s
  39429 	**(**int32)(__ccgo_up(bw + 12)) -= int32(8)
  39430 	if bits&int32(0xff) != int32(0xff) {
  39431 		pos = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos
  39432 		if !(BitWriterResize(tls, bw, libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(bw)).Frun+int32(1))) != 0) {
  39433 			return
  39434 		}
  39435 		if bits&int32(0x100) != 0 { // overflow -> propagate carry over pending 0xff's
  39436 			if pos > uint64(0) {
  39437 				**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(pos-uint64(1)))) = **(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(pos-uint64(1)))) + 1
  39438 			}
  39439 		}
  39440 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0 {
  39441 			if bits&int32(0x100) != 0 {
  39442 				v1 = 0x00
  39443 			} else {
  39444 				v1 = int32(0xff)
  39445 			}
  39446 			value = v1
  39447 			for {
  39448 				if !((*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0) {
  39449 					break
  39450 				}
  39451 				v3 = pos
  39452 				pos = pos + 1
  39453 				**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = libc.Uint8FromInt32(value)
  39454 				goto _2
  39455 			_2:
  39456 				;
  39457 				(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun - 1
  39458 			}
  39459 		}
  39460 		v3 = pos
  39461 		pos = pos + 1
  39462 		**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = libc.Uint8FromInt32(bits & int32(0xff))
  39463 		(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = pos
  39464 	} else {
  39465 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun + 1 // delay writing of bytes 0xff, pending eventual carry.
  39466 	}
  39467 }
  39468 
  39469 //------------------------------------------------------------------------------
  39470 // renormalization
  39471 
  39472 var kNorm = [128]uint8_t{
  39473 	0:   uint8(7),
  39474 	1:   uint8(6),
  39475 	2:   uint8(6),
  39476 	3:   uint8(5),
  39477 	4:   uint8(5),
  39478 	5:   uint8(5),
  39479 	6:   uint8(5),
  39480 	7:   uint8(4),
  39481 	8:   uint8(4),
  39482 	9:   uint8(4),
  39483 	10:  uint8(4),
  39484 	11:  uint8(4),
  39485 	12:  uint8(4),
  39486 	13:  uint8(4),
  39487 	14:  uint8(4),
  39488 	15:  uint8(3),
  39489 	16:  uint8(3),
  39490 	17:  uint8(3),
  39491 	18:  uint8(3),
  39492 	19:  uint8(3),
  39493 	20:  uint8(3),
  39494 	21:  uint8(3),
  39495 	22:  uint8(3),
  39496 	23:  uint8(3),
  39497 	24:  uint8(3),
  39498 	25:  uint8(3),
  39499 	26:  uint8(3),
  39500 	27:  uint8(3),
  39501 	28:  uint8(3),
  39502 	29:  uint8(3),
  39503 	30:  uint8(3),
  39504 	31:  uint8(2),
  39505 	32:  uint8(2),
  39506 	33:  uint8(2),
  39507 	34:  uint8(2),
  39508 	35:  uint8(2),
  39509 	36:  uint8(2),
  39510 	37:  uint8(2),
  39511 	38:  uint8(2),
  39512 	39:  uint8(2),
  39513 	40:  uint8(2),
  39514 	41:  uint8(2),
  39515 	42:  uint8(2),
  39516 	43:  uint8(2),
  39517 	44:  uint8(2),
  39518 	45:  uint8(2),
  39519 	46:  uint8(2),
  39520 	47:  uint8(2),
  39521 	48:  uint8(2),
  39522 	49:  uint8(2),
  39523 	50:  uint8(2),
  39524 	51:  uint8(2),
  39525 	52:  uint8(2),
  39526 	53:  uint8(2),
  39527 	54:  uint8(2),
  39528 	55:  uint8(2),
  39529 	56:  uint8(2),
  39530 	57:  uint8(2),
  39531 	58:  uint8(2),
  39532 	59:  uint8(2),
  39533 	60:  uint8(2),
  39534 	61:  uint8(2),
  39535 	62:  uint8(2),
  39536 	63:  uint8(1),
  39537 	64:  uint8(1),
  39538 	65:  uint8(1),
  39539 	66:  uint8(1),
  39540 	67:  uint8(1),
  39541 	68:  uint8(1),
  39542 	69:  uint8(1),
  39543 	70:  uint8(1),
  39544 	71:  uint8(1),
  39545 	72:  uint8(1),
  39546 	73:  uint8(1),
  39547 	74:  uint8(1),
  39548 	75:  uint8(1),
  39549 	76:  uint8(1),
  39550 	77:  uint8(1),
  39551 	78:  uint8(1),
  39552 	79:  uint8(1),
  39553 	80:  uint8(1),
  39554 	81:  uint8(1),
  39555 	82:  uint8(1),
  39556 	83:  uint8(1),
  39557 	84:  uint8(1),
  39558 	85:  uint8(1),
  39559 	86:  uint8(1),
  39560 	87:  uint8(1),
  39561 	88:  uint8(1),
  39562 	89:  uint8(1),
  39563 	90:  uint8(1),
  39564 	91:  uint8(1),
  39565 	92:  uint8(1),
  39566 	93:  uint8(1),
  39567 	94:  uint8(1),
  39568 	95:  uint8(1),
  39569 	96:  uint8(1),
  39570 	97:  uint8(1),
  39571 	98:  uint8(1),
  39572 	99:  uint8(1),
  39573 	100: uint8(1),
  39574 	101: uint8(1),
  39575 	102: uint8(1),
  39576 	103: uint8(1),
  39577 	104: uint8(1),
  39578 	105: uint8(1),
  39579 	106: uint8(1),
  39580 	107: uint8(1),
  39581 	108: uint8(1),
  39582 	109: uint8(1),
  39583 	110: uint8(1),
  39584 	111: uint8(1),
  39585 	112: uint8(1),
  39586 	113: uint8(1),
  39587 	114: uint8(1),
  39588 	115: uint8(1),
  39589 	116: uint8(1),
  39590 	117: uint8(1),
  39591 	118: uint8(1),
  39592 	119: uint8(1),
  39593 	120: uint8(1),
  39594 	121: uint8(1),
  39595 	122: uint8(1),
  39596 	123: uint8(1),
  39597 	124: uint8(1),
  39598 	125: uint8(1),
  39599 	126: uint8(1),
  39600 }
  39601 
  39602 // C documentation
  39603 //
  39604 //	// range = ((range + 1) << kVP8Log2Range[range]) - 1
  39605 var kNewRange = [128]uint8_t{
  39606 	0:   uint8(127),
  39607 	1:   uint8(127),
  39608 	2:   uint8(191),
  39609 	3:   uint8(127),
  39610 	4:   uint8(159),
  39611 	5:   uint8(191),
  39612 	6:   uint8(223),
  39613 	7:   uint8(127),
  39614 	8:   uint8(143),
  39615 	9:   uint8(159),
  39616 	10:  uint8(175),
  39617 	11:  uint8(191),
  39618 	12:  uint8(207),
  39619 	13:  uint8(223),
  39620 	14:  uint8(239),
  39621 	15:  uint8(127),
  39622 	16:  uint8(135),
  39623 	17:  uint8(143),
  39624 	18:  uint8(151),
  39625 	19:  uint8(159),
  39626 	20:  uint8(167),
  39627 	21:  uint8(175),
  39628 	22:  uint8(183),
  39629 	23:  uint8(191),
  39630 	24:  uint8(199),
  39631 	25:  uint8(207),
  39632 	26:  uint8(215),
  39633 	27:  uint8(223),
  39634 	28:  uint8(231),
  39635 	29:  uint8(239),
  39636 	30:  uint8(247),
  39637 	31:  uint8(127),
  39638 	32:  uint8(131),
  39639 	33:  uint8(135),
  39640 	34:  uint8(139),
  39641 	35:  uint8(143),
  39642 	36:  uint8(147),
  39643 	37:  uint8(151),
  39644 	38:  uint8(155),
  39645 	39:  uint8(159),
  39646 	40:  uint8(163),
  39647 	41:  uint8(167),
  39648 	42:  uint8(171),
  39649 	43:  uint8(175),
  39650 	44:  uint8(179),
  39651 	45:  uint8(183),
  39652 	46:  uint8(187),
  39653 	47:  uint8(191),
  39654 	48:  uint8(195),
  39655 	49:  uint8(199),
  39656 	50:  uint8(203),
  39657 	51:  uint8(207),
  39658 	52:  uint8(211),
  39659 	53:  uint8(215),
  39660 	54:  uint8(219),
  39661 	55:  uint8(223),
  39662 	56:  uint8(227),
  39663 	57:  uint8(231),
  39664 	58:  uint8(235),
  39665 	59:  uint8(239),
  39666 	60:  uint8(243),
  39667 	61:  uint8(247),
  39668 	62:  uint8(251),
  39669 	63:  uint8(127),
  39670 	64:  uint8(129),
  39671 	65:  uint8(131),
  39672 	66:  uint8(133),
  39673 	67:  uint8(135),
  39674 	68:  uint8(137),
  39675 	69:  uint8(139),
  39676 	70:  uint8(141),
  39677 	71:  uint8(143),
  39678 	72:  uint8(145),
  39679 	73:  uint8(147),
  39680 	74:  uint8(149),
  39681 	75:  uint8(151),
  39682 	76:  uint8(153),
  39683 	77:  uint8(155),
  39684 	78:  uint8(157),
  39685 	79:  uint8(159),
  39686 	80:  uint8(161),
  39687 	81:  uint8(163),
  39688 	82:  uint8(165),
  39689 	83:  uint8(167),
  39690 	84:  uint8(169),
  39691 	85:  uint8(171),
  39692 	86:  uint8(173),
  39693 	87:  uint8(175),
  39694 	88:  uint8(177),
  39695 	89:  uint8(179),
  39696 	90:  uint8(181),
  39697 	91:  uint8(183),
  39698 	92:  uint8(185),
  39699 	93:  uint8(187),
  39700 	94:  uint8(189),
  39701 	95:  uint8(191),
  39702 	96:  uint8(193),
  39703 	97:  uint8(195),
  39704 	98:  uint8(197),
  39705 	99:  uint8(199),
  39706 	100: uint8(201),
  39707 	101: uint8(203),
  39708 	102: uint8(205),
  39709 	103: uint8(207),
  39710 	104: uint8(209),
  39711 	105: uint8(211),
  39712 	106: uint8(213),
  39713 	107: uint8(215),
  39714 	108: uint8(217),
  39715 	109: uint8(219),
  39716 	110: uint8(221),
  39717 	111: uint8(223),
  39718 	112: uint8(225),
  39719 	113: uint8(227),
  39720 	114: uint8(229),
  39721 	115: uint8(231),
  39722 	116: uint8(233),
  39723 	117: uint8(235),
  39724 	118: uint8(237),
  39725 	119: uint8(239),
  39726 	120: uint8(241),
  39727 	121: uint8(243),
  39728 	122: uint8(245),
  39729 	123: uint8(247),
  39730 	124: uint8(249),
  39731 	125: uint8(251),
  39732 	126: uint8(253),
  39733 	127: uint8(127),
  39734 }
  39735 
  39736 func VP8PutBit(tls *libc.TLS, bw uintptr, bit int32, prob int32) (r int32) {
  39737 	var shift, split int32
  39738 	_, _ = shift, split
  39739 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 * prob >> int32(8)
  39740 	if bit != 0 {
  39741 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  39742 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  39743 	} else {
  39744 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  39745 	}
  39746 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) { // emit 'shift' bits out and renormalize
  39747 		shift = libc.Int32FromUint8(kNorm[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  39748 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromUint8(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  39749 		**(**int32_t)(__ccgo_up(bw + 4)) <<= shift
  39750 		**(**int32)(__ccgo_up(bw + 12)) += shift
  39751 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  39752 			Flush(tls, bw)
  39753 		}
  39754 	}
  39755 	return bit
  39756 }
  39757 
  39758 func VP8PutBitUniform(tls *libc.TLS, bw uintptr, bit int32) (r int32) {
  39759 	var split int32
  39760 	_ = split
  39761 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 >> int32(1)
  39762 	if bit != 0 {
  39763 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  39764 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  39765 	} else {
  39766 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  39767 	}
  39768 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) {
  39769 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromUint8(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  39770 		**(**int32_t)(__ccgo_up(bw + 4)) <<= int32(1)
  39771 		**(**int32)(__ccgo_up(bw + 12)) += int32(1)
  39772 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  39773 			Flush(tls, bw)
  39774 		}
  39775 	}
  39776 	return bit
  39777 }
  39778 
  39779 func VP8PutBits(tls *libc.TLS, bw uintptr, value uint32_t, nb_bits int32) {
  39780 	var mask uint32_t
  39781 	_ = mask
  39782 	mask = uint32(1) << (nb_bits - int32(1))
  39783 	for {
  39784 		if !(mask != 0) {
  39785 			break
  39786 		}
  39787 		VP8PutBitUniform(tls, bw, libc.Int32FromUint32(value&mask))
  39788 		goto _1
  39789 	_1:
  39790 		;
  39791 		mask = mask >> uint32(1)
  39792 	}
  39793 }
  39794 
  39795 func VP8PutSignedBits(tls *libc.TLS, bw uintptr, value int32, nb_bits int32) {
  39796 	if !(VP8PutBitUniform(tls, bw, libc.BoolInt32(value != 0)) != 0) {
  39797 		return
  39798 	}
  39799 	if value < 0 {
  39800 		VP8PutBits(tls, bw, libc.Uint32FromInt32(-value<<int32(1)|int32(1)), nb_bits+int32(1))
  39801 	} else {
  39802 		VP8PutBits(tls, bw, libc.Uint32FromInt32(value<<int32(1)), nb_bits+int32(1))
  39803 	}
  39804 }
  39805 
  39806 //------------------------------------------------------------------------------
  39807 
  39808 func VP8BitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  39809 	var v1 int32
  39810 	_ = v1
  39811 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromInt32(255) - libc.Int32FromInt32(1)
  39812 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue = 0
  39813 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = 0
  39814 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = -int32(8)
  39815 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = uint64(0)
  39816 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = uint64(0)
  39817 	(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = 0
  39818 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = libc.UintptrFromInt32(0)
  39819 	if expected_size > uint64(0) {
  39820 		v1 = BitWriterResize(tls, bw, expected_size)
  39821 	} else {
  39822 		v1 = int32(1)
  39823 	}
  39824 	return v1
  39825 }
  39826 
  39827 func VP8BitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  39828 	VP8PutBits(tls, bw, uint32(0), int32(9)-(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits)
  39829 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = 0 // pad with zeroes
  39830 	Flush(tls, bw)
  39831 	return (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf
  39832 }
  39833 
  39834 func VP8BitWriterAppend(tls *libc.TLS, bw uintptr, data uintptr, size size_t) (r int32) {
  39835 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits != -int32(8) {
  39836 		return 0
  39837 	} // Flush() must have been called
  39838 	if !(BitWriterResize(tls, bw, size) != 0) {
  39839 		return 0
  39840 	}
  39841 	libc.Xmemcpy(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf+uintptr((*VP8BitWriter)(unsafe.Pointer(bw)).Fpos), data, size)
  39842 	**(**size_t)(__ccgo_up(bw + 24)) += size
  39843 	return int32(1)
  39844 }
  39845 
  39846 func VP8BitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  39847 	if bw != libc.UintptrFromInt32(0) {
  39848 		WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  39849 		libc.Xmemset(tls, bw, 0, uint64(48))
  39850 	}
  39851 }
  39852 
  39853 //------------------------------------------------------------------------------
  39854 // VP8LBitWriter
  39855 
  39856 // This is the minimum amount of size the memory buffer is guaranteed to grow
  39857 // when extra space is needed.
  39858 
  39859 // C documentation
  39860 //
  39861 //	// Returns 1 on success.
  39862 func VP8LBitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  39863 	var allocated_buf uintptr
  39864 	var allocated_size, current_size, max_bytes, size_required size_t
  39865 	var size_required_64b uint64_t
  39866 	_, _, _, _, _, _ = allocated_buf, allocated_size, current_size, max_bytes, size_required, size_required_64b
  39867 	max_bytes = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  39868 	current_size = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  39869 	size_required_64b = current_size + extra_size
  39870 	size_required = size_required_64b
  39871 	if size_required != size_required_64b {
  39872 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39873 		return 0
  39874 	}
  39875 	if max_bytes > uint64(0) && size_required <= max_bytes {
  39876 		return int32(1)
  39877 	}
  39878 	allocated_size = uint64(3) * max_bytes >> int32(1)
  39879 	if allocated_size < size_required {
  39880 		allocated_size = size_required
  39881 	}
  39882 	// make allocated size multiple of 1k
  39883 	allocated_size = (allocated_size>>libc.Int32FromInt32(10) + libc.Uint64FromInt32(1)) << libc.Int32FromInt32(10)
  39884 	allocated_buf = WebPSafeMalloc(tls, uint64(1), allocated_size)
  39885 	if allocated_buf == libc.UintptrFromInt32(0) {
  39886 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39887 		return 0
  39888 	}
  39889 	if current_size > uint64(0) {
  39890 		libc.Xmemcpy(tls, allocated_buf, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf, current_size)
  39891 	}
  39892 	WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  39893 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf = allocated_buf
  39894 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(current_size)
  39895 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fend = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(allocated_size)
  39896 	return int32(1)
  39897 }
  39898 
  39899 func VP8LBitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  39900 	libc.Xmemset(tls, bw, 0, uint64(48))
  39901 	return VP8LBitWriterResize(tls, bw, expected_size)
  39902 }
  39903 
  39904 func VP8LBitWriterClone(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  39905 	var current_size size_t
  39906 	_ = current_size
  39907 	current_size = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf))
  39908 	if !(VP8LBitWriterResize(tls, dst, current_size) != 0) {
  39909 		return 0
  39910 	}
  39911 	libc.Xmemcpy(tls, (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf, (*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf, current_size)
  39912 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(src)).Fbits
  39913 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fused = (*VP8LBitWriter)(unsafe.Pointer(src)).Fused
  39914 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(src)).Ferror1
  39915 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf + uintptr(current_size)
  39916 	return int32(1)
  39917 }
  39918 
  39919 func VP8LBitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  39920 	if bw != libc.UintptrFromInt32(0) {
  39921 		WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  39922 		libc.Xmemset(tls, bw, 0, uint64(48))
  39923 	}
  39924 }
  39925 
  39926 func VP8LBitWriterReset(tls *libc.TLS, bw_init uintptr, bw uintptr) {
  39927 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fbits
  39928 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fused
  39929 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(int64((*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fcur)-int64((*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fbuf))
  39930 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Ferror1
  39931 }
  39932 
  39933 func VP8LBitWriterSwap(tls *libc.TLS, src uintptr, dst uintptr) {
  39934 	var tmp VP8LBitWriter
  39935 	_ = tmp
  39936 	tmp = **(**VP8LBitWriter)(__ccgo_up(src))
  39937 	**(**VP8LBitWriter)(__ccgo_up(src)) = **(**VP8LBitWriter)(__ccgo_up(dst))
  39938 	**(**VP8LBitWriter)(__ccgo_up(dst)) = tmp
  39939 }
  39940 
  39941 func VP8LPutBitsFlushBits(tls *libc.TLS, bw uintptr) {
  39942 	var extra_size, v1 uint64_t
  39943 	var v2 int32
  39944 	_, _, _ = extra_size, v1, v2
  39945 	// If needed, make some room by flushing some bits out.
  39946 	if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  39947 		extra_size = uint64(libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768))
  39948 		v1 = extra_size
  39949 		v2 = libc.BoolInt32(v1 == v1)
  39950 		goto _3
  39951 	_3:
  39952 		;
  39953 		if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  39954 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  39955 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39956 			return
  39957 		}
  39958 	}
  39959 	**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint32((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  39960 	**(**uintptr)(__ccgo_up(bw + 24)) += uintptr(VP8L_WRITER_BYTES)
  39961 	**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint64(VP8L_WRITER_BITS)
  39962 	**(**int32)(__ccgo_up(bw + 8)) -= int32(VP8L_WRITER_BITS)
  39963 }
  39964 
  39965 func VP8LPutBitsInternal(tls *libc.TLS, bw uintptr, bits uint32_t, n_bits int32) {
  39966 	var extra_size, v1 uint64_t
  39967 	var lbits vp8l_atype_t
  39968 	var used, v2 int32
  39969 	_, _, _, _, _ = extra_size, lbits, used, v1, v2
  39970 	// That's the max we can handle:
  39971 	if n_bits > 0 {
  39972 		lbits = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits
  39973 		used = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused
  39974 		// Special case of overflow handling for 32bit accumulator (2-steps flush).
  39975 		// If needed, make some room by flushing some bits out.
  39976 		for used >= int32(VP8L_WRITER_BITS) {
  39977 			if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  39978 				extra_size = uint64(libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768))
  39979 				v1 = extra_size
  39980 				v2 = libc.BoolInt32(v1 == v1)
  39981 				goto _3
  39982 			_3:
  39983 				;
  39984 				if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  39985 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  39986 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39987 					return
  39988 				}
  39989 			}
  39990 			**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint32(lbits)
  39991 			**(**uintptr)(__ccgo_up(bw + 24)) += uintptr(VP8L_WRITER_BYTES)
  39992 			lbits = lbits >> uint64(VP8L_WRITER_BITS)
  39993 			used = used - int32(VP8L_WRITER_BITS)
  39994 		}
  39995 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = lbits | uint64(bits)<<used
  39996 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = used + n_bits
  39997 	}
  39998 }
  39999 
  40000 func VP8LBitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40001 	var v1, v2 uintptr
  40002 	_, _ = v1, v2
  40003 	// flush leftover bits
  40004 	if VP8LBitWriterResize(tls, bw, libc.Uint64FromInt32(((*VP8LBitWriter)(unsafe.Pointer(bw)).Fused+int32(7))>>int32(3))) != 0 {
  40005 		for (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused > 0 {
  40006 			v2 = bw + 24
  40007 			v1 = *(*uintptr)(unsafe.Pointer(v2))
  40008 			*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  40009 			**(**uint8_t)(__ccgo_up(v1)) = uint8((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40010 			**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint64(8)
  40011 			**(**int32)(__ccgo_up(bw + 8)) -= int32(8)
  40012 		}
  40013 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = 0
  40014 	}
  40015 	return (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40016 }
  40017 
  40018 var kHashMul12 = uint32(0x1e35a7bd)
  40019 
  40020 //------------------------------------------------------------------------------
  40021 
  40022 //------------------------------------------------------------------------------
  40023 // VP8LColorCache.
  40024 
  40025 func VP8LColorCacheInit(tls *libc.TLS, color_cache uintptr, hash_bits int32) (r int32) {
  40026 	var hash_size int32
  40027 	_ = hash_size
  40028 	hash_size = int32(1) << hash_bits
  40029 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = WebPSafeCalloc(tls, libc.Uint64FromInt32(hash_size), uint64(4))
  40030 	if (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors == libc.UintptrFromInt32(0) {
  40031 		return 0
  40032 	}
  40033 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_shift = int32(32) - hash_bits
  40034 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_bits = hash_bits
  40035 	return int32(1)
  40036 }
  40037 
  40038 func VP8LColorCacheClear(tls *libc.TLS, color_cache uintptr) {
  40039 	if color_cache != libc.UintptrFromInt32(0) {
  40040 		WebPSafeFree(tls, (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors)
  40041 		(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = libc.UintptrFromInt32(0)
  40042 	}
  40043 }
  40044 
  40045 func VP8LColorCacheCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  40046 	libc.Xmemcpy(tls, (*VP8LColorCache)(unsafe.Pointer(dst)).Fcolors, (*VP8LColorCache)(unsafe.Pointer(src)).Fcolors, libc.Uint64FromUint32(1)<<(*VP8LColorCache)(unsafe.Pointer(dst)).Fhash_bits*uint64(4))
  40047 }
  40048 
  40049 // -----------------------------------------------------------------------------
  40050 // Quick estimate of a potentially interesting filter mode to try.
  40051 
  40052 func GradientPredictor(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  40053 	var g, v1, v2 int32
  40054 	_, _, _ = g, v1, v2
  40055 	g = libc.Int32FromUint8(a) + libc.Int32FromUint8(b) - libc.Int32FromUint8(c)
  40056 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  40057 		v1 = g
  40058 	} else {
  40059 		if g < 0 {
  40060 			v2 = 0
  40061 		} else {
  40062 			v2 = int32(255)
  40063 		}
  40064 		v1 = v2
  40065 	}
  40066 	return v1 // clip to 8bit
  40067 }
  40068 
  40069 func WebPEstimateBestFilter(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r WEBP_FILTER_TYPE) {
  40070 	bp := tls.Alloc(256)
  40071 	defer tls.Free(256)
  40072 	var best_filter WEBP_FILTER_TYPE
  40073 	var best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, score int32
  40074 	var p uintptr
  40075 	var _ /* bins at bp+0 */ [4][16]int32
  40076 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_filter, best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, p, score
  40077 	libc.Xmemset(tls, bp, 0, uint64(256))
  40078 	// We only sample every other pixels. That's enough.
  40079 	j = int32(2)
  40080 	for {
  40081 		if !(j < height-int32(1)) {
  40082 			break
  40083 		}
  40084 		p = data + uintptr(j*stride)
  40085 		mean = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  40086 		i = int32(2)
  40087 		for {
  40088 			if !(i < width-int32(1)) {
  40089 				break
  40090 			}
  40091 			diff0 = libc.Xabs(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-mean) >> libc.Int32FromInt32(4)
  40092 			diff1 = libc.Xabs(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i-int32(1)))))) >> libc.Int32FromInt32(4)
  40093 			diff2 = libc.Xabs(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i-width))))) >> libc.Int32FromInt32(4)
  40094 			grad_pred = GradientPredictor(tls, **(**uint8_t)(__ccgo_up(p + uintptr(i-int32(1)))), **(**uint8_t)(__ccgo_up(p + uintptr(i-width))), **(**uint8_t)(__ccgo_up(p + uintptr(i-width-int32(1)))))
  40095 			diff3 = libc.Xabs(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-grad_pred) >> libc.Int32FromInt32(4)
  40096 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_NONE)*64 + uintptr(diff0)*4)) = int32(1)
  40097 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_HORIZONTAL)*64 + uintptr(diff1)*4)) = int32(1)
  40098 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_VERTICAL)*64 + uintptr(diff2)*4)) = int32(1)
  40099 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_GRADIENT)*64 + uintptr(diff3)*4)) = int32(1)
  40100 			mean = (int32(3)*mean + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i)))) + int32(2)) >> int32(2)
  40101 			goto _2
  40102 		_2:
  40103 			;
  40104 			i = i + int32(2)
  40105 		}
  40106 		goto _1
  40107 	_1:
  40108 		;
  40109 		j = j + int32(2)
  40110 	}
  40111 	best_filter = int32(WEBP_FILTER_NONE)
  40112 	best_score = int32(0x7fffffff)
  40113 	filter = int32(WEBP_FILTER_NONE)
  40114 	for {
  40115 		if !(filter < int32(WEBP_FILTER_LAST)) {
  40116 			break
  40117 		}
  40118 		score = 0
  40119 		i = 0
  40120 		for {
  40121 			if !(i < int32(16)) {
  40122 				break
  40123 			}
  40124 			if **(**int32)(__ccgo_up(bp + uintptr(filter)*64 + uintptr(i)*4)) > 0 {
  40125 				score = score + i
  40126 			}
  40127 			goto _4
  40128 		_4:
  40129 			;
  40130 			i = i + 1
  40131 		}
  40132 		if score < best_score {
  40133 			best_score = score
  40134 			best_filter = filter
  40135 		}
  40136 		goto _3
  40137 	_3:
  40138 		;
  40139 		filter = filter + 1
  40140 	}
  40141 	return best_filter
  40142 	return r
  40143 }
  40144 
  40145 // Alpha related constants.
  40146 
  40147 // Mux related constants.
  40148 
  40149 // Maximum chunk payload is such that adding the header and padding won't
  40150 // overflow a uint32_t.
  40151 
  40152 // -----------------------------------------------------------------------------
  40153 // Util function to optimize the symbol map for RLE coding
  40154 
  40155 // C documentation
  40156 //
  40157 //	// Heuristics for selecting the stride ranges to collapse.
  40158 func ValuesShouldBeCollapsedToStrideAverage(tls *libc.TLS, a int32, b int32) (r int32) {
  40159 	return libc.BoolInt32(libc.Xabs(tls, a-b) < int32(4))
  40160 }
  40161 
  40162 // C documentation
  40163 //
  40164 //	// Change the population counts in a way that the consequent
  40165 //	// Huffman tree compression, especially its RLE-part, give smaller output.
  40166 func OptimizeHuffmanForRle(tls *libc.TLS, length int32, good_for_rle uintptr, counts uintptr) {
  40167 	var count, k1, limit, stride1, sum, symbol uint32_t
  40168 	var i, k, stride int32
  40169 	_, _, _, _, _, _, _, _, _ = count, i, k, k1, limit, stride, stride1, sum, symbol
  40170 	for {
  40171 		if !(length >= 0) {
  40172 			break
  40173 		}
  40174 		if length == 0 {
  40175 			return // All zeros.
  40176 		}
  40177 		if **(**uint32_t)(__ccgo_up(counts + uintptr(length-int32(1))*4)) != uint32(0) {
  40178 			// Now counts[0..length - 1] does not have trailing zeros.
  40179 			break
  40180 		}
  40181 		goto _1
  40182 	_1:
  40183 		;
  40184 		length = length - 1
  40185 	}
  40186 	// 2) Let's mark all population counts that already can be encoded
  40187 	// with an rle code.
  40188 	// Let's not spoil any of the existing good rle codes.
  40189 	// Mark any seq of 0's that is longer as 5 as a good_for_rle.
  40190 	// Mark any seq of non-0's that is longer as 7 as a good_for_rle.
  40191 	symbol = **(**uint32_t)(__ccgo_up(counts))
  40192 	stride = 0
  40193 	i = 0
  40194 	for {
  40195 		if !(i < length+int32(1)) {
  40196 			break
  40197 		}
  40198 		if i == length || **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4)) != symbol {
  40199 			if symbol == uint32(0) && stride >= int32(5) || symbol != uint32(0) && stride >= int32(7) {
  40200 				k = 0
  40201 				for {
  40202 					if !(k < stride) {
  40203 						break
  40204 					}
  40205 					**(**uint8_t)(__ccgo_up(good_for_rle + uintptr(i-k-int32(1)))) = uint8(1)
  40206 					goto _3
  40207 				_3:
  40208 					;
  40209 					k = k + 1
  40210 				}
  40211 			}
  40212 			stride = int32(1)
  40213 			if i != length {
  40214 				symbol = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40215 			}
  40216 		} else {
  40217 			stride = stride + 1
  40218 		}
  40219 		goto _2
  40220 	_2:
  40221 		;
  40222 		i = i + 1
  40223 	}
  40224 	// 3) Let's replace those population counts that lead to more rle codes.
  40225 	stride1 = uint32(0)
  40226 	limit = **(**uint32_t)(__ccgo_up(counts))
  40227 	sum = uint32(0)
  40228 	i = 0
  40229 	for {
  40230 		if !(i < length+int32(1)) {
  40231 			break
  40232 		}
  40233 		if i == length || **(**uint8_t)(__ccgo_up(good_for_rle + uintptr(i))) != 0 || i != 0 && **(**uint8_t)(__ccgo_up(good_for_rle + uintptr(i-int32(1)))) != 0 || !(ValuesShouldBeCollapsedToStrideAverage(tls, libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))), libc.Int32FromUint32(limit)) != 0) {
  40234 			if stride1 >= uint32(4) || stride1 >= uint32(3) && sum == uint32(0) {
  40235 				// The stride must end, collapse what we have, if we have enough (4).
  40236 				count = (sum + stride1/uint32(2)) / stride1
  40237 				if count < uint32(1) {
  40238 					count = uint32(1)
  40239 				}
  40240 				if sum == uint32(0) {
  40241 					// Don't make an all zeros stride to be upgraded to ones.
  40242 					count = uint32(0)
  40243 				}
  40244 				k1 = uint32(0)
  40245 				for {
  40246 					if !(k1 < stride1) {
  40247 						break
  40248 					}
  40249 					// We don't want to change value at counts[i],
  40250 					// that is already belonging to the next stride. Thus - 1.
  40251 					**(**uint32_t)(__ccgo_up(counts + uintptr(libc.Uint32FromInt32(i)-k1-uint32(1))*4)) = count
  40252 					goto _5
  40253 				_5:
  40254 					;
  40255 					k1 = k1 + 1
  40256 				}
  40257 			}
  40258 			stride1 = uint32(0)
  40259 			sum = uint32(0)
  40260 			if i < length-int32(3) {
  40261 				// All interesting strides have a count of at least 4,
  40262 				// at least when non-zeros.
  40263 				limit = (**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(counts + uintptr(i+int32(1))*4)) + **(**uint32_t)(__ccgo_up(counts + uintptr(i+int32(2))*4)) + **(**uint32_t)(__ccgo_up(counts + uintptr(i+int32(3))*4)) + uint32(2)) / uint32(4)
  40264 			} else {
  40265 				if i < length {
  40266 					limit = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40267 				} else {
  40268 					limit = uint32(0)
  40269 				}
  40270 			}
  40271 		}
  40272 		stride1 = stride1 + 1
  40273 		if i != length {
  40274 			sum = sum + **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40275 			if stride1 >= uint32(4) {
  40276 				limit = (sum + stride1/uint32(2)) / stride1
  40277 			}
  40278 		}
  40279 		goto _4
  40280 	_4:
  40281 		;
  40282 		i = i + 1
  40283 	}
  40284 }
  40285 
  40286 // C documentation
  40287 //
  40288 //	// A comparer function for two Huffman trees: sorts first by 'total count'
  40289 //	// (more comes first), and then by 'value' (more comes first).
  40290 func CompareHuffmanTrees(tls *libc.TLS, ptr1 uintptr, ptr2 uintptr) (r int32) {
  40291 	var t1, t2 uintptr
  40292 	var v1 int32
  40293 	_, _, _ = t1, t2, v1
  40294 	t1 = ptr1
  40295 	t2 = ptr2
  40296 	if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count > (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40297 		return -int32(1)
  40298 	} else {
  40299 		if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count < (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40300 			return int32(1)
  40301 		} else {
  40302 			if (*HuffmanTree)(unsafe.Pointer(t1)).Fvalue < (*HuffmanTree)(unsafe.Pointer(t2)).Fvalue {
  40303 				v1 = -int32(1)
  40304 			} else {
  40305 				v1 = int32(1)
  40306 			}
  40307 			return v1
  40308 		}
  40309 	}
  40310 	return r
  40311 }
  40312 
  40313 func SetBitDepths(tls *libc.TLS, tree uintptr, pool uintptr, bit_depths uintptr, level int32) {
  40314 	if (*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left >= 0 {
  40315 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left)*16, pool, bit_depths, level+int32(1))
  40316 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_right)*16, pool, bit_depths, level+int32(1))
  40317 	} else {
  40318 		**(**uint8_t)(__ccgo_up(bit_depths + uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fvalue))) = libc.Uint8FromInt32(level)
  40319 	}
  40320 }
  40321 
  40322 // C documentation
  40323 //
  40324 //	// Create an optimal Huffman tree.
  40325 //	//
  40326 //	// (data,length): population counts.
  40327 //	// tree_limit: maximum bit depth (inclusive) of the codes.
  40328 //	// bit_depths[]: how many bits are used for the symbol.
  40329 //	//
  40330 //	// Returns 0 when an error has occurred.
  40331 //	//
  40332 //	// The catch here is that the tree cannot be arbitrarily deep
  40333 //	//
  40334 //	// count_limit is the value that is to be faked as the minimum value
  40335 //	// and this minimum value is raised until the tree matches the
  40336 //	// maximum length requirement.
  40337 //	//
  40338 //	// This algorithm is not of excellent performance for very long data blocks,
  40339 //	// especially when population counts are longer than 2**tree_limit, but
  40340 //	// we are not planning to use this with extremely long blocks.
  40341 //	//
  40342 //	// See https://en.wikipedia.org/wiki/Huffman_coding
  40343 func GenerateOptimalTree(tls *libc.TLS, histogram uintptr, histogram_size int32, tree uintptr, tree_depth_limit int32, bit_depths uintptr) {
  40344 	var count, count1, count_min uint32_t
  40345 	var i, idx, j, k, max_depth, tree_pool_size, tree_size, tree_size_orig, v5 int32
  40346 	var tree_pool uintptr
  40347 	var v4 uint32
  40348 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = count, count1, count_min, i, idx, j, k, max_depth, tree_pool, tree_pool_size, tree_size, tree_size_orig, v4, v5
  40349 	tree_size_orig = 0
  40350 	i = 0
  40351 	for {
  40352 		if !(i < histogram_size) {
  40353 			break
  40354 		}
  40355 		if **(**uint32_t)(__ccgo_up(histogram + uintptr(i)*4)) != uint32(0) {
  40356 			tree_size_orig = tree_size_orig + 1
  40357 		}
  40358 		goto _1
  40359 	_1:
  40360 		;
  40361 		i = i + 1
  40362 	}
  40363 	if tree_size_orig == 0 { // pretty optimal already!
  40364 		return
  40365 	}
  40366 	tree_pool = tree + uintptr(tree_size_orig)*16
  40367 	// For block sizes with less than 64k symbols we never need to do a
  40368 	// second iteration of this loop.
  40369 	// If we actually start running inside this loop a lot, we would perhaps
  40370 	// be better off with the Katajainen algorithm.
  40371 	count_min = uint32(1)
  40372 	for {
  40373 		tree_size = tree_size_orig
  40374 		// We need to pack the Huffman tree in tree_depth_limit bits.
  40375 		// So, we try by faking histogram entries to be at least 'count_min'.
  40376 		idx = 0
  40377 		j = 0
  40378 		for {
  40379 			if !(j < histogram_size) {
  40380 				break
  40381 			}
  40382 			if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) != uint32(0) {
  40383 				if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) < count_min {
  40384 					v4 = count_min
  40385 				} else {
  40386 					v4 = **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4))
  40387 				}
  40388 				count = v4
  40389 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Ftotal_count = count
  40390 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fvalue = j
  40391 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_left = -int32(1)
  40392 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_right = -int32(1)
  40393 				idx = idx + 1
  40394 			}
  40395 			goto _3
  40396 		_3:
  40397 			;
  40398 			j = j + 1
  40399 		}
  40400 		// Build the Huffman tree.
  40401 		libc.Xqsort(tls, tree, libc.Uint64FromInt32(tree_size), uint64(16), __ccgo_fp(CompareHuffmanTrees))
  40402 		if tree_size > int32(1) { // Normal case.
  40403 			tree_pool_size = 0
  40404 			for tree_size > int32(1) {
  40405 				v5 = tree_pool_size
  40406 				tree_pool_size = tree_pool_size + 1
  40407 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(1))*16))
  40408 				v5 = tree_pool_size
  40409 				tree_pool_size = tree_pool_size + 1
  40410 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(2))*16))
  40411 				count1 = (**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(tree_pool_size-int32(1))*16))).Ftotal_count + (**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(tree_pool_size-int32(2))*16))).Ftotal_count
  40412 				tree_size = tree_size - int32(2)
  40413 				k = 0
  40414 				for {
  40415 					if !(k < tree_size) {
  40416 						break
  40417 					}
  40418 					if (**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count <= count1 {
  40419 						break
  40420 					}
  40421 					goto _7
  40422 				_7:
  40423 					;
  40424 					k = k + 1
  40425 				}
  40426 				libc.Xmemmove(tls, tree+uintptr(k+libc.Int32FromInt32(1))*16, tree+uintptr(k)*16, libc.Uint64FromInt32(tree_size-k)*uint64(16))
  40427 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count = count1
  40428 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fvalue = -int32(1)
  40429 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_left = tree_pool_size - int32(1)
  40430 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_right = tree_pool_size - int32(2)
  40431 				tree_size = tree_size + int32(1)
  40432 			}
  40433 			SetBitDepths(tls, tree, tree_pool, bit_depths, 0)
  40434 		} else {
  40435 			if tree_size == int32(1) { // Trivial case: only one element.
  40436 				**(**uint8_t)(__ccgo_up(bit_depths + uintptr((**(**HuffmanTree)(__ccgo_up(tree))).Fvalue))) = uint8(1)
  40437 			}
  40438 		}
  40439 		// Test if this Huffman tree satisfies our 'tree_depth_limit' criteria.
  40440 		max_depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bit_depths)))
  40441 		j = int32(1)
  40442 		for {
  40443 			if !(j < histogram_size) {
  40444 				break
  40445 			}
  40446 			if max_depth < libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j)))) {
  40447 				max_depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j))))
  40448 			}
  40449 			goto _8
  40450 		_8:
  40451 			;
  40452 			j = j + 1
  40453 		}
  40454 		if max_depth <= tree_depth_limit {
  40455 			break
  40456 		}
  40457 		goto _2
  40458 	_2:
  40459 		;
  40460 		count_min = count_min * uint32(2)
  40461 	}
  40462 }
  40463 
  40464 // -----------------------------------------------------------------------------
  40465 // Coding of the Huffman tree values
  40466 
  40467 func CodeRepeatedValues(tls *libc.TLS, repetitions int32, tokens uintptr, value int32, prev_value int32) (r uintptr) {
  40468 	var i int32
  40469 	_ = i
  40470 	if value != prev_value {
  40471 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = libc.Uint8FromInt32(value)
  40472 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40473 		tokens += 2
  40474 		repetitions = repetitions - 1
  40475 	}
  40476 	for repetitions >= int32(1) {
  40477 		if repetitions < int32(3) {
  40478 			i = 0
  40479 			for {
  40480 				if !(i < repetitions) {
  40481 					break
  40482 				}
  40483 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = libc.Uint8FromInt32(value)
  40484 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40485 				tokens += 2
  40486 				goto _1
  40487 			_1:
  40488 				;
  40489 				i = i + 1
  40490 			}
  40491 			break
  40492 		} else {
  40493 			if repetitions < int32(7) {
  40494 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40495 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = libc.Uint8FromInt32(repetitions - int32(3))
  40496 				tokens += 2
  40497 				break
  40498 			} else {
  40499 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40500 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(3)
  40501 				tokens += 2
  40502 				repetitions = repetitions - int32(6)
  40503 			}
  40504 		}
  40505 	}
  40506 	return tokens
  40507 }
  40508 
  40509 func CodeRepeatedZeros(tls *libc.TLS, repetitions int32, tokens uintptr) (r uintptr) {
  40510 	var i int32
  40511 	_ = i
  40512 	for repetitions >= int32(1) {
  40513 		if repetitions < int32(3) {
  40514 			i = 0
  40515 			for {
  40516 				if !(i < repetitions) {
  40517 					break
  40518 				}
  40519 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(0) // 0-value
  40520 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40521 				tokens += 2
  40522 				goto _1
  40523 			_1:
  40524 				;
  40525 				i = i + 1
  40526 			}
  40527 			break
  40528 		} else {
  40529 			if repetitions < int32(11) {
  40530 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(17)
  40531 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = libc.Uint8FromInt32(repetitions - int32(3))
  40532 				tokens += 2
  40533 				break
  40534 			} else {
  40535 				if repetitions < int32(139) {
  40536 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40537 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = libc.Uint8FromInt32(repetitions - int32(11))
  40538 					tokens += 2
  40539 					break
  40540 				} else {
  40541 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40542 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0x7f) // 138 repeated 0s
  40543 					tokens += 2
  40544 					repetitions = repetitions - int32(138)
  40545 				}
  40546 			}
  40547 		}
  40548 	}
  40549 	return tokens
  40550 }
  40551 
  40552 func VP8LCreateCompressedHuffmanTree(tls *libc.TLS, tree uintptr, tokens uintptr, max_tokens int32) (r int32) {
  40553 	var depth_size, i, k, prev_value, runs, value int32
  40554 	var ending_token, starting_token uintptr
  40555 	_, _, _, _, _, _, _, _ = depth_size, ending_token, i, k, prev_value, runs, starting_token, value
  40556 	starting_token = tokens
  40557 	ending_token = tokens + uintptr(max_tokens)*2
  40558 	depth_size = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40559 	prev_value = int32(8) // 8 is the initial value for rle.
  40560 	i = 0
  40561 	for i < depth_size {
  40562 		value = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40563 		k = i + int32(1)
  40564 		for k < depth_size && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(k)))) == value {
  40565 			k = k + 1
  40566 		}
  40567 		runs = k - i
  40568 		if value == 0 {
  40569 			tokens = CodeRepeatedZeros(tls, runs, tokens)
  40570 		} else {
  40571 			tokens = CodeRepeatedValues(tls, runs, tokens, value, prev_value)
  40572 			prev_value = value
  40573 		}
  40574 		i = i + runs
  40575 	}
  40576 	_ = ending_token // suppress 'unused variable' warning
  40577 	return int32((int64(tokens) - int64(starting_token)) / 2)
  40578 }
  40579 
  40580 // -----------------------------------------------------------------------------
  40581 
  40582 // C documentation
  40583 //
  40584 //	// Pre-reversed 4-bit values.
  40585 var kReversedBits = [16]uint8_t{
  40586 	1:  uint8(0x8),
  40587 	2:  uint8(0x4),
  40588 	3:  uint8(0xc),
  40589 	4:  uint8(0x2),
  40590 	5:  uint8(0xa),
  40591 	6:  uint8(0x6),
  40592 	7:  uint8(0xe),
  40593 	8:  uint8(0x1),
  40594 	9:  uint8(0x9),
  40595 	10: uint8(0x5),
  40596 	11: uint8(0xd),
  40597 	12: uint8(0x3),
  40598 	13: uint8(0xb),
  40599 	14: uint8(0x7),
  40600 	15: uint8(0xf),
  40601 }
  40602 
  40603 func ReverseBits(tls *libc.TLS, num_bits int32, bits uint32_t) (r uint32_t) {
  40604 	var i int32
  40605 	var retval uint32_t
  40606 	_, _ = i, retval
  40607 	retval = uint32(0)
  40608 	i = 0
  40609 	for i < num_bits {
  40610 		i = i + int32(4)
  40611 		retval = retval | libc.Uint32FromInt32(libc.Int32FromUint8(kReversedBits[bits&uint32(0xf)])<<(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-i))
  40612 		bits = bits >> uint32(4)
  40613 	}
  40614 	retval = retval >> libc.Uint32FromInt32(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-num_bits)
  40615 	return retval
  40616 }
  40617 
  40618 // C documentation
  40619 //
  40620 //	// Get the actual bit values for a tree of bit depths.
  40621 func ConvertBitDepthsToSymbols(tls *libc.TLS, tree uintptr) {
  40622 	bp := tls.Alloc(64)
  40623 	defer tls.Free(64)
  40624 	var code, v4 uint32_t
  40625 	var code_length, code_length1, i, len1 int32
  40626 	var depth_count [16]int32
  40627 	var v5 uintptr
  40628 	var _ /* next_code at bp+0 */ [16]uint32_t
  40629 	_, _, _, _, _, _, _, _ = code, code_length, code_length1, depth_count, i, len1, v4, v5
  40630 	depth_count = [16]int32{}
  40631 	len1 = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40632 	i = 0
  40633 	for {
  40634 		if !(i < len1) {
  40635 			break
  40636 		}
  40637 		code_length = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40638 		depth_count[code_length] = depth_count[code_length] + 1
  40639 		goto _1
  40640 	_1:
  40641 		;
  40642 		i = i + 1
  40643 	}
  40644 	depth_count[0] = 0 // ignore unused symbol
  40645 	(**(**[16]uint32_t)(__ccgo_up(bp)))[0] = uint32(0)
  40646 	code = uint32(0)
  40647 	i = int32(1)
  40648 	for {
  40649 		if !(i <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  40650 			break
  40651 		}
  40652 		code = (code + libc.Uint32FromInt32(depth_count[i-int32(1)])) << int32(1)
  40653 		(**(**[16]uint32_t)(__ccgo_up(bp)))[i] = code
  40654 		goto _2
  40655 	_2:
  40656 		;
  40657 		i = i + 1
  40658 	}
  40659 	i = 0
  40660 	for {
  40661 		if !(i < len1) {
  40662 			break
  40663 		}
  40664 		code_length1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40665 		v5 = bp + uintptr(code_length1)*4
  40666 		v4 = *(*uint32_t)(unsafe.Pointer(v5))
  40667 		*(*uint32_t)(unsafe.Pointer(v5)) = *(*uint32_t)(unsafe.Pointer(v5)) + 1
  40668 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcodes + uintptr(i)*2)) = uint16(ReverseBits(tls, code_length1, v4))
  40669 		goto _3
  40670 	_3:
  40671 		;
  40672 		i = i + 1
  40673 	}
  40674 }
  40675 
  40676 // -----------------------------------------------------------------------------
  40677 // Main entry point
  40678 
  40679 func VP8LCreateHuffmanTree(tls *libc.TLS, histogram uintptr, tree_depth_limit int32, buf_rle uintptr, huff_tree uintptr, huff_code uintptr) {
  40680 	var num_symbols int32
  40681 	_ = num_symbols
  40682 	num_symbols = (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fnum_symbols
  40683 	libc.Xmemset(tls, buf_rle, 0, libc.Uint64FromInt32(num_symbols)*uint64(1))
  40684 	OptimizeHuffmanForRle(tls, num_symbols, buf_rle, histogram)
  40685 	GenerateOptimalTree(tls, histogram, num_symbols, huff_tree, tree_depth_limit, (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fcode_lengths)
  40686 	// Create the actual bit codes for the bit lengths.
  40687 	ConvertBitDepthsToSymbols(tls, huff_code)
  40688 }
  40689 
  40690 const MAX_HTREE_GROUPS = 0x10000
  40691 const SORTED_SIZE_CUTOFF = 512
  40692 
  40693 //------------------------------------------------------------------------------
  40694 
  40695 // Copyright 2012 Google Inc. All Rights Reserved.
  40696 //
  40697 // Use of this source code is governed by a BSD-style license
  40698 // that can be found in the COPYING file in the root of the source
  40699 // tree. An additional intellectual property rights grant can be found
  40700 // in the file PATENTS. All contributing project authors may
  40701 // be found in the AUTHORS file in the root of the source tree.
  40702 // -----------------------------------------------------------------------------
  40703 //
  40704 //  Internal header for constants related to WebP file format.
  40705 //
  40706 // Author: Urvang (urvang@google.com)
  40707 
  40708 // Copyright 2010 Google Inc. All Rights Reserved.
  40709 //
  40710 // Use of this source code is governed by a BSD-style license
  40711 // that can be found in the COPYING file in the root of the source
  40712 // tree. An additional intellectual property rights grant can be found
  40713 // in the file PATENTS. All contributing project authors may
  40714 // be found in the AUTHORS file in the root of the source tree.
  40715 // -----------------------------------------------------------------------------
  40716 //
  40717 //  Common types + memory wrappers
  40718 //
  40719 // Author: Skal (pascal.massimino@gmail.com)
  40720 
  40721 // Huffman data read via DecodeImageStream is represented in two (red and green)
  40722 // bytes.
  40723 
  40724 func VP8LHtreeGroupsNew(tls *libc.TLS, num_htree_groups int32) (r uintptr) {
  40725 	var htree_groups uintptr
  40726 	_ = htree_groups
  40727 	htree_groups = WebPSafeMalloc(tls, libc.Uint64FromInt32(num_htree_groups), uint64(568))
  40728 	if htree_groups == libc.UintptrFromInt32(0) {
  40729 		return libc.UintptrFromInt32(0)
  40730 	}
  40731 	return htree_groups
  40732 }
  40733 
  40734 func VP8LHtreeGroupsFree(tls *libc.TLS, htree_groups uintptr) {
  40735 	if htree_groups != libc.UintptrFromInt32(0) {
  40736 		WebPSafeFree(tls, htree_groups)
  40737 	}
  40738 }
  40739 
  40740 // C documentation
  40741 //
  40742 //	// Returns reverse(reverse(key, len) + 1, len), where reverse(key, len) is the
  40743 //	// bit-wise reversal of the len least significant bits of key.
  40744 func GetNextKey(tls *libc.TLS, key uint32_t, len1 int32) (r uint32_t) {
  40745 	var step uint32_t
  40746 	var v1 uint32
  40747 	_, _ = step, v1
  40748 	step = libc.Uint32FromInt32(int32(1) << (len1 - int32(1)))
  40749 	for key&step != 0 {
  40750 		step = step >> uint32(1)
  40751 	}
  40752 	if step != 0 {
  40753 		v1 = key&(step-uint32(1)) + step
  40754 	} else {
  40755 		v1 = key
  40756 	}
  40757 	return v1
  40758 }
  40759 
  40760 // C documentation
  40761 //
  40762 //	// Stores code in table[0], table[step], table[2*step], ..., table[end].
  40763 //	// Assumes that end is an integer multiple of step.
  40764 func ReplicateValue(tls *libc.TLS, table uintptr, step int32, end int32, code HuffmanCode) {
  40765 	for cond := true; cond; cond = end > 0 {
  40766 		end = end - step
  40767 		**(**HuffmanCode)(__ccgo_up(table + uintptr(end)*4)) = code
  40768 	}
  40769 }
  40770 
  40771 // C documentation
  40772 //
  40773 //	// Returns the table width of the next 2nd level table. count is the histogram
  40774 //	// of bit lengths for the remaining symbols, len is the code length of the next
  40775 //	// processed symbol
  40776 func NextTableBitSize(tls *libc.TLS, count uintptr, len1 int32, root_bits int32) (r int32) {
  40777 	var left int32
  40778 	_ = left
  40779 	left = int32(1) << (len1 - root_bits)
  40780 	for len1 < int32(MAX_ALLOWED_CODE_LENGTH) {
  40781 		left = left - **(**int32)(__ccgo_up(count + uintptr(len1)*4))
  40782 		if left <= 0 {
  40783 			break
  40784 		}
  40785 		len1 = len1 + 1
  40786 		left = left << int32(1)
  40787 	}
  40788 	return len1 - root_bits
  40789 }
  40790 
  40791 // C documentation
  40792 //
  40793 //	// sorted[code_lengths_size] is a pre-allocated array for sorting symbols
  40794 //	// by code length.
  40795 func BuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32, sorted uintptr) (r int32) {
  40796 	bp := tls.Alloc(128)
  40797 	defer tls.Free(128)
  40798 	var code, code1, code2 HuffmanCode
  40799 	var key, low, mask uint32_t
  40800 	var len1, num_nodes, num_open, step, symbol, symbol_code_length, table_bits, table_size, total_size, v4 int32
  40801 	var table, v5 uintptr
  40802 	var _ /* count at bp+0 */ [16]int32
  40803 	var _ /* offset at bp+64 */ [16]int32
  40804 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = code, code1, code2, key, len1, low, mask, num_nodes, num_open, step, symbol, symbol_code_length, table, table_bits, table_size, total_size, v4, v5
  40805 	table = root_table                 // next available space in table
  40806 	total_size = int32(1) << root_bits // symbol index in original or sorted table
  40807 	// number of codes of each length:
  40808 	**(**[16]int32)(__ccgo_up(bp)) = [16]int32{}
  40809 	// Build histogram of code lengths.
  40810 	symbol = 0
  40811 	for {
  40812 		if !(symbol < code_lengths_size) {
  40813 			break
  40814 		}
  40815 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > int32(MAX_ALLOWED_CODE_LENGTH) {
  40816 			return 0
  40817 		}
  40818 		(**(**[16]int32)(__ccgo_up(bp)))[**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4))] = (**(**[16]int32)(__ccgo_up(bp)))[**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4))] + 1
  40819 		goto _1
  40820 	_1:
  40821 		;
  40822 		symbol = symbol + 1
  40823 	}
  40824 	// Error, all code lengths are zeros.
  40825 	if (**(**[16]int32)(__ccgo_up(bp)))[0] == code_lengths_size {
  40826 		return 0
  40827 	}
  40828 	// Generate offsets into sorted symbol table by code length.
  40829 	(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(1)] = 0
  40830 	len1 = int32(1)
  40831 	for {
  40832 		if !(len1 < int32(MAX_ALLOWED_CODE_LENGTH)) {
  40833 			break
  40834 		}
  40835 		if (**(**[16]int32)(__ccgo_up(bp)))[len1] > int32(1)<<len1 {
  40836 			return 0
  40837 		}
  40838 		(**(**[16]int32)(__ccgo_up(bp + 64)))[len1+int32(1)] = (**(**[16]int32)(__ccgo_up(bp + 64)))[len1] + (**(**[16]int32)(__ccgo_up(bp)))[len1]
  40839 		goto _2
  40840 	_2:
  40841 		;
  40842 		len1 = len1 + 1
  40843 	}
  40844 	// Sort symbols by length, by symbol order within each length.
  40845 	symbol = 0
  40846 	for {
  40847 		if !(symbol < code_lengths_size) {
  40848 			break
  40849 		}
  40850 		symbol_code_length = **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4))
  40851 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > 0 {
  40852 			if sorted != libc.UintptrFromInt32(0) {
  40853 				if (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] >= code_lengths_size {
  40854 					return 0
  40855 				}
  40856 				v5 = bp + 64 + uintptr(symbol_code_length)*4
  40857 				v4 = *(*int32)(unsafe.Pointer(v5))
  40858 				*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
  40859 				**(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2)) = libc.Uint16FromInt32(symbol)
  40860 			} else {
  40861 				(**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] = (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] + 1
  40862 			}
  40863 		}
  40864 		goto _3
  40865 	_3:
  40866 		;
  40867 		symbol = symbol + 1
  40868 	}
  40869 	// Special case code with only one value.
  40870 	if (**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)] == int32(1) {
  40871 		if sorted != libc.UintptrFromInt32(0) {
  40872 			code.Fbits = uint8(0)
  40873 			code.Fvalue = **(**uint16_t)(__ccgo_up(sorted))
  40874 			ReplicateValue(tls, table, int32(1), total_size, code)
  40875 		}
  40876 		return total_size
  40877 	}
  40878 	// step size to replicate values in current table
  40879 	low = uint32(0xffffffff)                           // low bits for current root entry
  40880 	mask = libc.Uint32FromInt32(total_size - int32(1)) // mask for low bits
  40881 	key = uint32(0)                                    // reversed prefix code
  40882 	num_nodes = int32(1)                               // number of Huffman tree nodes
  40883 	num_open = int32(1)                                // number of open branches in current tree level
  40884 	table_bits = root_bits                             // key length of current table
  40885 	table_size = int32(1) << table_bits                // size of current table
  40886 	symbol = 0
  40887 	// Fill in root table.
  40888 	len1 = int32(1)
  40889 	step = libc.Int32FromInt32(2)
  40890 	for {
  40891 		if !(len1 <= root_bits) {
  40892 			break
  40893 		}
  40894 		num_open = num_open << int32(1)
  40895 		num_nodes = num_nodes + num_open
  40896 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  40897 		if num_open < 0 {
  40898 			return 0
  40899 		}
  40900 		if root_table == libc.UintptrFromInt32(0) {
  40901 			goto _6
  40902 		}
  40903 		for {
  40904 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  40905 				break
  40906 			}
  40907 			code1.Fbits = libc.Uint8FromInt32(len1)
  40908 			v4 = symbol
  40909 			symbol = symbol + 1
  40910 			code1.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  40911 			ReplicateValue(tls, table+uintptr(key)*4, step, table_size, code1)
  40912 			key = GetNextKey(tls, key, len1)
  40913 			goto _7
  40914 		_7:
  40915 			;
  40916 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  40917 		}
  40918 		goto _6
  40919 	_6:
  40920 		;
  40921 		len1 = len1 + 1
  40922 		step = step << int32(1)
  40923 	}
  40924 	// Fill in 2nd level tables and add pointers to root table.
  40925 	len1 = root_bits + int32(1)
  40926 	step = libc.Int32FromInt32(2)
  40927 	for {
  40928 		if !(len1 <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  40929 			break
  40930 		}
  40931 		num_open = num_open << int32(1)
  40932 		num_nodes = num_nodes + num_open
  40933 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  40934 		if num_open < 0 {
  40935 			return 0
  40936 		}
  40937 		for {
  40938 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  40939 				break
  40940 			}
  40941 			if key&mask != low {
  40942 				if root_table != libc.UintptrFromInt32(0) {
  40943 					table = table + uintptr(table_size)*4
  40944 				}
  40945 				table_bits = NextTableBitSize(tls, bp, len1, root_bits)
  40946 				table_size = int32(1) << table_bits
  40947 				total_size = total_size + table_size
  40948 				low = key & mask
  40949 				if root_table != libc.UintptrFromInt32(0) {
  40950 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fbits = libc.Uint8FromInt32(table_bits + root_bits)
  40951 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fvalue = libc.Uint16FromInt64((int64(table)-int64(root_table))/4 - libc.Int64FromUint32(low))
  40952 				}
  40953 			}
  40954 			if root_table != libc.UintptrFromInt32(0) {
  40955 				code2.Fbits = libc.Uint8FromInt32(len1 - root_bits)
  40956 				v4 = symbol
  40957 				symbol = symbol + 1
  40958 				code2.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  40959 				ReplicateValue(tls, table+uintptr(key>>root_bits)*4, step, table_size, code2)
  40960 			}
  40961 			key = GetNextKey(tls, key, len1)
  40962 			goto _10
  40963 		_10:
  40964 			;
  40965 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  40966 		}
  40967 		goto _9
  40968 	_9:
  40969 		;
  40970 		len1 = len1 + 1
  40971 		step = step << int32(1)
  40972 	}
  40973 	// Check if tree is full.
  40974 	if num_nodes != int32(2)*(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)]-int32(1) {
  40975 		return 0
  40976 	}
  40977 	return total_size
  40978 }
  40979 
  40980 // C documentation
  40981 //
  40982 //	// Maximum code_lengths_size is 2328 (reached for 11-bit color_cache_bits).
  40983 //	// More commonly, the value is around ~280.
  40984 //	// Cut-off value for switching between heap and stack allocation.
  40985 func VP8LBuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32) (r int32) {
  40986 	bp := tls.Alloc(1024)
  40987 	defer tls.Free(1024)
  40988 	var next, sorted1 uintptr
  40989 	var segment_size, total_size, v1 int32
  40990 	var _ /* sorted at bp+0 */ [512]uint16_t
  40991 	_, _, _, _, _ = next, segment_size, sorted1, total_size, v1
  40992 	total_size = BuildHuffmanTable(tls, libc.UintptrFromInt32(0), root_bits, code_lengths, code_lengths_size, libc.UintptrFromInt32(0))
  40993 	if total_size == 0 || root_table == libc.UintptrFromInt32(0) {
  40994 		return total_size
  40995 	}
  40996 	if (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table+uintptr(total_size)*4 >= (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fstart+uintptr((*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fsize)*4 {
  40997 		// If 'root_table' does not have enough memory, allocate a new segment.
  40998 		// The available part of root_table->curr_segment is left unused because we
  40999 		// need a contiguous buffer.
  41000 		segment_size = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fsize
  41001 		next = WebPSafeMalloc(tls, uint64(1), uint64(32))
  41002 		if next == libc.UintptrFromInt32(0) {
  41003 			return 0
  41004 		}
  41005 		// Fill the new segment.
  41006 		// We need at least 'total_size' but if that value is small, it is better to
  41007 		// allocate a big chunk to prevent more allocations later. 'segment_size' is
  41008 		// therefore chosen (any other arbitrary value could be chosen).
  41009 		if total_size > segment_size {
  41010 			v1 = total_size
  41011 		} else {
  41012 			v1 = segment_size
  41013 		}
  41014 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize = v1
  41015 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart = WebPSafeMalloc(tls, libc.Uint64FromInt32((*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize), uint64(4))
  41016 		if (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart == libc.UintptrFromInt32(0) {
  41017 			WebPSafeFree(tls, next)
  41018 			return 0
  41019 		}
  41020 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart
  41021 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fnext = libc.UintptrFromInt32(0)
  41022 		// Point to the new segment.
  41023 		(*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fnext = next
  41024 		(*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment = next
  41025 	}
  41026 	if code_lengths_size <= int32(SORTED_SIZE_CUTOFF) {
  41027 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, bp)
  41028 	} else { // rare case. Use heap allocation.
  41029 		sorted1 = WebPSafeMalloc(tls, libc.Uint64FromInt32(code_lengths_size), uint64(2))
  41030 		if sorted1 == libc.UintptrFromInt32(0) {
  41031 			return 0
  41032 		}
  41033 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, sorted1)
  41034 		WebPSafeFree(tls, sorted1)
  41035 	}
  41036 	return total_size
  41037 }
  41038 
  41039 func VP8LHuffmanTablesAllocate(tls *libc.TLS, size int32, huffman_tables uintptr) (r int32) {
  41040 	var root uintptr
  41041 	_ = root
  41042 	// Have 'segment' point to the first segment for now, 'root'.
  41043 	root = huffman_tables
  41044 	(*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment = root
  41045 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fnext = libc.UintptrFromInt32(0)
  41046 	// Allocate root.
  41047 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart = WebPSafeMalloc(tls, libc.Uint64FromInt32(size), uint64(4))
  41048 	if (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart == libc.UintptrFromInt32(0) {
  41049 		return 0
  41050 	}
  41051 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart
  41052 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fsize = size
  41053 	return int32(1)
  41054 }
  41055 
  41056 func VP8LHuffmanTablesDeallocate(tls *libc.TLS, huffman_tables uintptr) {
  41057 	var current, next uintptr
  41058 	_, _ = current, next
  41059 	if huffman_tables == libc.UintptrFromInt32(0) {
  41060 		return
  41061 	}
  41062 	// Free the root node.
  41063 	current = huffman_tables
  41064 	next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41065 	WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41066 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart = libc.UintptrFromInt32(0)
  41067 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext = libc.UintptrFromInt32(0)
  41068 	current = next
  41069 	// Free the following nodes.
  41070 	for current != libc.UintptrFromInt32(0) {
  41071 		next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41072 		WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41073 		WebPSafeFree(tls, current)
  41074 		current = next
  41075 	}
  41076 }
  41077 
  41078 var kHashMul13 = uint32(0x1e35a7bd)
  41079 
  41080 // Alpha related constants.
  41081 
  41082 // Mux related constants.
  41083 
  41084 // Maximum chunk payload is such that adding the header and padding won't
  41085 // overflow a uint32_t.
  41086 
  41087 // Copyright 2010 Google Inc. All Rights Reserved.
  41088 //
  41089 // Use of this source code is governed by a BSD-style license
  41090 // that can be found in the COPYING file in the root of the source
  41091 // tree. An additional intellectual property rights grant can be found
  41092 // in the file PATENTS. All contributing project authors may
  41093 // be found in the AUTHORS file in the root of the source tree.
  41094 // -----------------------------------------------------------------------------
  41095 //
  41096 //  Common types + memory wrappers
  41097 //
  41098 // Author: Skal (pascal.massimino@gmail.com)
  41099 
  41100 // -----------------------------------------------------------------------------
  41101 
  41102 // Palette reordering for smaller sum of deltas (and for smaller storage).
  41103 
  41104 func PaletteCompareColorsForQsort(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
  41105 	bp := tls.Alloc(16)
  41106 	defer tls.Free(16)
  41107 	var a, b, v1, v3 uint32_t
  41108 	var v5 int32
  41109 	var _ /* A at bp+0 */ uint32_t
  41110 	_, _, _, _, _ = a, b, v1, v3, v5
  41111 	libc.Xmemcpy(tls, bp, p1, uint64(4))
  41112 	v1 = **(**uint32_t)(__ccgo_up(bp))
  41113 	goto _2
  41114 _2:
  41115 	a = v1
  41116 	libc.Xmemcpy(tls, bp, p2, uint64(4))
  41117 	v3 = **(**uint32_t)(__ccgo_up(bp))
  41118 	goto _4
  41119 _4:
  41120 	b = v3
  41121 	if a < b {
  41122 		v5 = -int32(1)
  41123 	} else {
  41124 		v5 = int32(1)
  41125 	}
  41126 	return v5
  41127 }
  41128 
  41129 func PaletteComponentDistance(tls *libc.TLS, v uint32_t) (r uint32_t) {
  41130 	var v1 uint32
  41131 	_ = v1
  41132 	if v <= uint32(128) {
  41133 		v1 = v
  41134 	} else {
  41135 		v1 = uint32(256) - v
  41136 	}
  41137 	return v1
  41138 }
  41139 
  41140 // C documentation
  41141 //
  41142 //	// Computes a value that is related to the entropy created by the
  41143 //	// palette entry diff.
  41144 //	//
  41145 //	// Note that the last & 0xff is a no-operation in the next statement, but
  41146 //	// removed by most compilers and is here only for regularity of the code.
  41147 func PaletteColorDistance(tls *libc.TLS, col1 uint32_t, col2 uint32_t) (r uint32_t) {
  41148 	var alpha_and_green, diff, red_and_blue, score, v1, v2, v3 uint32_t
  41149 	var kMoreWeightForRGBThanForAlpha int32
  41150 	_, _, _, _, _, _, _, _ = alpha_and_green, diff, kMoreWeightForRGBThanForAlpha, red_and_blue, score, v1, v2, v3
  41151 	v1 = col1
  41152 	v2 = col2
  41153 	alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  41154 	red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  41155 	v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41156 	goto _4
  41157 _4:
  41158 	diff = v3
  41159 	kMoreWeightForRGBThanForAlpha = int32(9)
  41160 	score = PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(0)&uint32(0xff))
  41161 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(8)&uint32(0xff))
  41162 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(16)&uint32(0xff))
  41163 	score = score * libc.Uint32FromInt32(kMoreWeightForRGBThanForAlpha)
  41164 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(24)&uint32(0xff))
  41165 	return score
  41166 }
  41167 
  41168 func SwapColor(tls *libc.TLS, col1 uintptr, col2 uintptr) {
  41169 	var tmp uint32_t
  41170 	_ = tmp
  41171 	tmp = **(**uint32_t)(__ccgo_up(col1))
  41172 	**(**uint32_t)(__ccgo_up(col1)) = **(**uint32_t)(__ccgo_up(col2))
  41173 	**(**uint32_t)(__ccgo_up(col2)) = tmp
  41174 }
  41175 
  41176 func SearchColorNoIdx(tls *libc.TLS, sorted uintptr, color uint32_t, num_colors int32) (r int32) {
  41177 	var hi, low, mid int32
  41178 	_, _, _ = hi, low, mid
  41179 	low = 0
  41180 	hi = num_colors
  41181 	if **(**uint32_t)(__ccgo_up(sorted + uintptr(low)*4)) == color {
  41182 		return low
  41183 	} // loop invariant: sorted[low] != color
  41184 	for int32(1) != 0 {
  41185 		mid = (low + hi) >> int32(1)
  41186 		if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) == color {
  41187 			return mid
  41188 		} else {
  41189 			if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) < color {
  41190 				low = mid
  41191 			} else {
  41192 				hi = mid
  41193 			}
  41194 		}
  41195 	}
  41196 	return 0
  41197 }
  41198 
  41199 func PrepareMapToPalette(tls *libc.TLS, palette uintptr, num_colors uint32_t, sorted uintptr, idx_map uintptr) {
  41200 	var i uint32_t
  41201 	_ = i
  41202 	libc.Xmemcpy(tls, sorted, palette, uint64(num_colors)*uint64(4))
  41203 	libc.Xqsort(tls, sorted, uint64(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41204 	i = uint32(0)
  41205 	for {
  41206 		if !(i < num_colors) {
  41207 			break
  41208 		}
  41209 		**(**uint32_t)(__ccgo_up(idx_map + uintptr(SearchColorNoIdx(tls, sorted, **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4)), libc.Int32FromUint32(num_colors)))*4)) = i
  41210 		goto _1
  41211 	_1:
  41212 		;
  41213 		i = i + 1
  41214 	}
  41215 }
  41216 
  41217 //------------------------------------------------------------------------------
  41218 
  41219 func GetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  41220 	var argb1 uintptr
  41221 	var colors [1024]uint32_t
  41222 	var height, i, key, num_colors, width, x, y, v3 int32
  41223 	var in_use [1024]uint8_t
  41224 	var last_pix uint32_t
  41225 	_, _, _, _, _, _, _, _, _, _, _, _ = argb1, colors, height, i, in_use, key, last_pix, num_colors, width, x, y, v3
  41226 	num_colors = 0
  41227 	in_use = [1024]uint8_t{}
  41228 	colors = [1024]uint32_t{}
  41229 	argb1 = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41230 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  41231 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  41232 	last_pix = ^**(**uint32_t)(__ccgo_up(argb1)) // so we're sure that last_pix != argb[0]
  41233 	y = 0
  41234 	for {
  41235 		if !(y < height) {
  41236 			break
  41237 		}
  41238 		x = 0
  41239 		for {
  41240 			if !(x < width) {
  41241 				break
  41242 			}
  41243 			if **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4)) == last_pix {
  41244 				goto _2
  41245 			}
  41246 			last_pix = **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4))
  41247 			v3 = libc.Int32FromUint32(last_pix * kHashMul13 >> int32(22))
  41248 			goto _4
  41249 		_4:
  41250 			key = v3
  41251 			for int32(1) != 0 {
  41252 				if !(in_use[key] != 0) {
  41253 					colors[key] = last_pix
  41254 					in_use[key] = uint8(1)
  41255 					num_colors = num_colors + 1
  41256 					if num_colors > int32(MAX_PALETTE_SIZE) {
  41257 						return libc.Int32FromInt32(MAX_PALETTE_SIZE) + libc.Int32FromInt32(1) // Exact count not needed.
  41258 					}
  41259 					break
  41260 				} else {
  41261 					if colors[key] == last_pix {
  41262 						break // The color is already there.
  41263 					} else {
  41264 						// Some other color sits here, so do linear conflict resolution.
  41265 						key = key + 1
  41266 						key = key & (libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4) - libc.Int32FromInt32(1)) // Key mask.
  41267 					}
  41268 				}
  41269 			}
  41270 			goto _2
  41271 		_2:
  41272 			;
  41273 			x = x + 1
  41274 		}
  41275 		argb1 = argb1 + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41276 		goto _1
  41277 	_1:
  41278 		;
  41279 		y = y + 1
  41280 	}
  41281 	if palette != libc.UintptrFromInt32(0) { // Fill the colors into palette.
  41282 		num_colors = 0
  41283 		i = 0
  41284 		for {
  41285 			if !(i < libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4)) {
  41286 				break
  41287 			}
  41288 			if in_use[i] != 0 {
  41289 				**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors)*4)) = colors[i]
  41290 				num_colors = num_colors + 1
  41291 			}
  41292 			goto _5
  41293 		_5:
  41294 			;
  41295 			i = i + 1
  41296 		}
  41297 		libc.Xqsort(tls, palette, libc.Uint64FromInt32(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41298 	}
  41299 	return num_colors
  41300 }
  41301 
  41302 // -----------------------------------------------------------------------------
  41303 
  41304 // C documentation
  41305 //
  41306 //	// The palette has been sorted by alpha. This function checks if the other
  41307 //	// components of the palette have a monotonic development with regards to
  41308 //	// position in the palette. If all have monotonic development, there is
  41309 //	// no benefit to re-organize them greedily. A monotonic development
  41310 //	// would be spotted in green-only situations (like lossy alpha) or gray-scale
  41311 //	// images.
  41312 func PaletteHasNonMonotonousDeltas(tls *libc.TLS, palette uintptr, num_colors int32) (r int32) {
  41313 	var alpha_and_green, diff, predict, red_and_blue, v2, v3, v4 uint32_t
  41314 	var bd, gd, rd, sign_found uint8_t
  41315 	var i, v6 int32
  41316 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, bd, diff, gd, i, predict, rd, red_and_blue, sign_found, v2, v3, v4, v6
  41317 	predict = uint32(0x000000)
  41318 	sign_found = uint8(0x00)
  41319 	i = 0
  41320 	for {
  41321 		if !(i < num_colors) {
  41322 			break
  41323 		}
  41324 		v2 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41325 		v3 = predict
  41326 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  41327 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  41328 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41329 		goto _5
  41330 	_5:
  41331 		diff = v4
  41332 		rd = uint8(diff >> libc.Int32FromInt32(16) & uint32(0xff))
  41333 		gd = uint8(diff >> libc.Int32FromInt32(8) & uint32(0xff))
  41334 		bd = uint8(diff >> libc.Int32FromInt32(0) & uint32(0xff))
  41335 		if libc.Int32FromUint8(rd) != 0x00 {
  41336 			if libc.Int32FromUint8(rd) < int32(0x80) {
  41337 				v6 = int32(1)
  41338 			} else {
  41339 				v6 = int32(2)
  41340 			}
  41341 			sign_found = libc.Uint8FromInt32(int32(sign_found) | v6)
  41342 		}
  41343 		if libc.Int32FromUint8(gd) != 0x00 {
  41344 			if libc.Int32FromUint8(gd) < int32(0x80) {
  41345 				v6 = int32(8)
  41346 			} else {
  41347 				v6 = int32(16)
  41348 			}
  41349 			sign_found = libc.Uint8FromInt32(int32(sign_found) | v6)
  41350 		}
  41351 		if libc.Int32FromUint8(bd) != 0x00 {
  41352 			if libc.Int32FromUint8(bd) < int32(0x80) {
  41353 				v6 = int32(64)
  41354 			} else {
  41355 				v6 = int32(128)
  41356 			}
  41357 			sign_found = libc.Uint8FromInt32(int32(sign_found) | v6)
  41358 		}
  41359 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41360 		goto _1
  41361 	_1:
  41362 		;
  41363 		i = i + 1
  41364 	}
  41365 	return libc.BoolInt32(libc.Int32FromUint8(sign_found)&(libc.Int32FromUint8(sign_found)<<int32(1)) != 0) // two consequent signs.
  41366 }
  41367 
  41368 func PaletteSortMinimizeDeltas(tls *libc.TLS, palette_sorted uintptr, num_colors int32, palette uintptr) {
  41369 	var best_ix, i, k int32
  41370 	var best_score, cur_score, predict uint32_t
  41371 	_, _, _, _, _, _ = best_ix, best_score, cur_score, i, k, predict
  41372 	predict = uint32(0x00000000)
  41373 	libc.Xmemcpy(tls, palette, palette_sorted, libc.Uint64FromInt32(num_colors)*uint64(4))
  41374 	if !(PaletteHasNonMonotonousDeltas(tls, palette_sorted, num_colors) != 0) {
  41375 		return
  41376 	}
  41377 	// Find greedily always the closest color of the predicted color to minimize
  41378 	// deltas in the palette. This reduces storage needs since the
  41379 	// palette is stored with delta encoding.
  41380 	if num_colors > int32(17) {
  41381 		if **(**uint32_t)(__ccgo_up(palette)) == uint32(0) {
  41382 			num_colors = num_colors - 1
  41383 			SwapColor(tls, palette+uintptr(num_colors)*4, palette)
  41384 		}
  41385 	}
  41386 	i = 0
  41387 	for {
  41388 		if !(i < num_colors) {
  41389 			break
  41390 		}
  41391 		best_ix = i
  41392 		best_score = ^libc.Uint32FromUint32(0)
  41393 		k = i
  41394 		for {
  41395 			if !(k < num_colors) {
  41396 				break
  41397 			}
  41398 			cur_score = PaletteColorDistance(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(k)*4)), predict)
  41399 			if best_score > cur_score {
  41400 				best_score = cur_score
  41401 				best_ix = k
  41402 			}
  41403 			goto _2
  41404 		_2:
  41405 			;
  41406 			k = k + 1
  41407 		}
  41408 		SwapColor(tls, palette+uintptr(best_ix)*4, palette+uintptr(i)*4)
  41409 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41410 		goto _1
  41411 	_1:
  41412 		;
  41413 		i = i + 1
  41414 	}
  41415 }
  41416 
  41417 // -----------------------------------------------------------------------------
  41418 // Modified Zeng method from "A Survey on Palette Reordering
  41419 // Methods for Improving the Compression of Color-Indexed Images" by Armando J.
  41420 // Pinho and Antonio J. R. Neves.
  41421 
  41422 // C documentation
  41423 //
  41424 //	// Finds the biggest cooccurrence in the matrix.
  41425 func CoOccurrenceFindMax(tls *libc.TLS, cooccurrence uintptr, num_colors uint32_t, c1 uintptr, c2 uintptr) {
  41426 	var best_cooccurrence, best_sum, i, j, sum uint32_t
  41427 	_, _, _, _, _ = best_cooccurrence, best_sum, i, j, sum
  41428 	// Find the index that is most frequently located adjacent to other
  41429 	// (different) indexes.
  41430 	best_sum = 0
  41431 	**(**uint8_t)(__ccgo_up(c1)) = 0
  41432 	i = uint32(0)
  41433 	for {
  41434 		if !(i < num_colors) {
  41435 			break
  41436 		}
  41437 		sum = uint32(0)
  41438 		j = uint32(0)
  41439 		for {
  41440 			if !(j < num_colors) {
  41441 				break
  41442 			}
  41443 			sum = sum + **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(i*num_colors+j)*4))
  41444 			goto _2
  41445 		_2:
  41446 			;
  41447 			j = j + 1
  41448 		}
  41449 		if sum > best_sum {
  41450 			best_sum = sum
  41451 			**(**uint8_t)(__ccgo_up(c1)) = uint8(i)
  41452 		}
  41453 		goto _1
  41454 	_1:
  41455 		;
  41456 		i = i + 1
  41457 	}
  41458 	// Find the index that is most frequently found adjacent to *c1.
  41459 	**(**uint8_t)(__ccgo_up(c2)) = 0
  41460 	best_cooccurrence = 0
  41461 	i = uint32(0)
  41462 	for {
  41463 		if !(i < num_colors) {
  41464 			break
  41465 		}
  41466 		if **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4)) > best_cooccurrence {
  41467 			best_cooccurrence = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4))
  41468 			**(**uint8_t)(__ccgo_up(c2)) = uint8(i)
  41469 		}
  41470 		goto _3
  41471 	_3:
  41472 		;
  41473 		i = i + 1
  41474 	}
  41475 }
  41476 
  41477 // C documentation
  41478 //
  41479 //	// Builds the cooccurrence matrix
  41480 func CoOccurrenceBuild(tls *libc.TLS, pic uintptr, palette uintptr, num_colors uint32_t, cooccurrence uintptr) (r int32) {
  41481 	bp := tls.Alloc(2048)
  41482 	defer tls.Free(2048)
  41483 	var left_idx, pix, prev_idx, prev_pix, top_idx uint32_t
  41484 	var line_current, line_tmp, line_top, lines, src uintptr
  41485 	var x, y int32
  41486 	var _ /* idx_map at bp+0 */ [256]uint32_t
  41487 	var _ /* palette_sorted at bp+1024 */ [256]uint32_t
  41488 	_, _, _, _, _, _, _, _, _, _, _, _ = left_idx, line_current, line_tmp, line_top, lines, pix, prev_idx, prev_pix, src, top_idx, x, y
  41489 	src = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41490 	prev_pix = ^**(**uint32_t)(__ccgo_up(src))
  41491 	prev_idx = 0
  41492 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  41493 	lines = WebPSafeMalloc(tls, libc.Uint64FromInt32(int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fwidth), uint64(4))
  41494 	if lines == libc.UintptrFromInt32(0) {
  41495 		return 0
  41496 	}
  41497 	line_top = lines
  41498 	line_current = lines + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fwidth)*4
  41499 	PrepareMapToPalette(tls, palette, num_colors, bp+1024, bp)
  41500 	y = 0
  41501 	for {
  41502 		if !(y < (*WebPPicture)(unsafe.Pointer(pic)).Fheight) {
  41503 			break
  41504 		}
  41505 		x = 0
  41506 		for {
  41507 			if !(x < (*WebPPicture)(unsafe.Pointer(pic)).Fwidth) {
  41508 				break
  41509 			}
  41510 			pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  41511 			if pix != prev_pix {
  41512 				prev_idx = (**(**[256]uint32_t)(__ccgo_up(bp)))[SearchColorNoIdx(tls, bp+1024, pix, libc.Int32FromUint32(num_colors))]
  41513 				prev_pix = pix
  41514 			}
  41515 			**(**uint32_t)(__ccgo_up(line_current + uintptr(x)*4)) = prev_idx
  41516 			// 4-connectivity is what works best as mentioned in "On the relation
  41517 			// between Memon's and the modified Zeng's palette reordering methods".
  41518 			if x > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4)) {
  41519 				left_idx = **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4))
  41520 				**(**uint32_t)(__ccgo_up(cooccurrence + uintptr(prev_idx*num_colors+left_idx)*4)) = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(prev_idx*num_colors+left_idx)*4)) + 1
  41521 				**(**uint32_t)(__ccgo_up(cooccurrence + uintptr(left_idx*num_colors+prev_idx)*4)) = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(left_idx*num_colors+prev_idx)*4)) + 1
  41522 			}
  41523 			if y > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4)) {
  41524 				top_idx = **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4))
  41525 				**(**uint32_t)(__ccgo_up(cooccurrence + uintptr(prev_idx*num_colors+top_idx)*4)) = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(prev_idx*num_colors+top_idx)*4)) + 1
  41526 				**(**uint32_t)(__ccgo_up(cooccurrence + uintptr(top_idx*num_colors+prev_idx)*4)) = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(top_idx*num_colors+prev_idx)*4)) + 1
  41527 			}
  41528 			goto _2
  41529 		_2:
  41530 			;
  41531 			x = x + 1
  41532 		}
  41533 		line_tmp = line_top
  41534 		line_top = line_current
  41535 		line_current = line_tmp
  41536 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41537 		goto _1
  41538 	_1:
  41539 		;
  41540 		y = y + 1
  41541 	}
  41542 	WebPSafeFree(tls, lines)
  41543 	return int32(1)
  41544 }
  41545 
  41546 type Sum = struct {
  41547 	Findex uint8_t
  41548 	Fsum   uint32_t
  41549 }
  41550 
  41551 func PaletteSortModifiedZeng(tls *libc.TLS, pic uintptr, palette_in uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41552 	bp := tls.Alloc(2304)
  41553 	defer tls.Free(2304)
  41554 	var best_index uint8_t
  41555 	var best_sum, cooccurrence uintptr
  41556 	var delta, n int32_t
  41557 	var first, i, ind, j, last, num_sums uint32_t
  41558 	var l_j uint16_t
  41559 	var v3 uint32
  41560 	var _ /* remapping at bp+0 */ [256]uint8_t
  41561 	var _ /* sums at bp+256 */ [256]Sum
  41562 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_index, best_sum, cooccurrence, delta, first, i, ind, j, l_j, last, n, num_sums, v3
  41563 	// TODO(vrabaud) check whether one color images should use palette or not.
  41564 	if num_colors <= uint32(1) {
  41565 		return int32(1)
  41566 	}
  41567 	// Build the co-occurrence matrix.
  41568 	cooccurrence = WebPSafeCalloc(tls, uint64(num_colors*num_colors), uint64(4))
  41569 	if cooccurrence == libc.UintptrFromInt32(0) {
  41570 		return 0
  41571 	}
  41572 	if !(CoOccurrenceBuild(tls, pic, palette_in, num_colors, cooccurrence) != 0) {
  41573 		WebPSafeFree(tls, cooccurrence)
  41574 		return 0
  41575 	}
  41576 	// Initialize the mapping list with the two best indices.
  41577 	CoOccurrenceFindMax(tls, cooccurrence, num_colors, bp, bp+1)
  41578 	// We need to append and prepend to the list of remapping. To this end, we
  41579 	// actually define the next start/end of the list as indices in a vector (with
  41580 	// a wrap around when the end is reached).
  41581 	first = uint32(0)
  41582 	last = uint32(1)
  41583 	num_sums = num_colors - uint32(2) // -2 because we know the first two values
  41584 	if num_sums > uint32(0) {
  41585 		// Initialize the sums with the first two remappings and find the best one
  41586 		best_sum = bp + 256
  41587 		(*Sum)(unsafe.Pointer(best_sum)).Findex = 0
  41588 		(*Sum)(unsafe.Pointer(best_sum)).Fsum = 0
  41589 		i = uint32(0)
  41590 		j = libc.Uint32FromInt32(0)
  41591 		for {
  41592 			if !(i < num_colors) {
  41593 				break
  41594 			}
  41595 			if i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[0]) || i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[int32(1)]) {
  41596 				goto _1
  41597 			}
  41598 			(**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Findex = uint8(i)
  41599 			(**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Fsum = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(i*num_colors+uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[0]))*4)) + **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(i*num_colors+uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[int32(1)]))*4))
  41600 			if (**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41601 				best_sum = bp + 256 + uintptr(j)*8
  41602 			}
  41603 			j = j + 1
  41604 			goto _1
  41605 		_1:
  41606 			;
  41607 			i = i + 1
  41608 		}
  41609 		for num_sums > uint32(0) {
  41610 			best_index = (*Sum)(unsafe.Pointer(best_sum)).Findex
  41611 			// Compute delta to know if we need to prepend or append the best index.
  41612 			delta = 0
  41613 			n = libc.Int32FromUint32(num_colors - num_sums)
  41614 			ind = first
  41615 			j = libc.Uint32FromInt32(0)
  41616 			for {
  41617 				if !((ind+j)%num_colors != last+uint32(1)) {
  41618 					break
  41619 				}
  41620 				l_j = uint16((**(**[256]uint8_t)(__ccgo_up(bp)))[(ind+j)%num_colors])
  41621 				delta = delta + (n-int32(1)-int32(2)*libc.Int32FromUint32(j))*libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(best_index)*num_colors+uint32(l_j))*4)))
  41622 				goto _2
  41623 			_2:
  41624 				;
  41625 				j = j + 1
  41626 			}
  41627 			if delta > 0 {
  41628 				if first == uint32(0) {
  41629 					v3 = num_colors - uint32(1)
  41630 				} else {
  41631 					v3 = first - uint32(1)
  41632 				}
  41633 				first = v3
  41634 				(**(**[256]uint8_t)(__ccgo_up(bp)))[first] = best_index
  41635 			} else {
  41636 				last = last + 1
  41637 				(**(**[256]uint8_t)(__ccgo_up(bp)))[last] = best_index
  41638 			}
  41639 			// Remove best_sum from sums.
  41640 			**(**Sum)(__ccgo_up(best_sum)) = (**(**[256]Sum)(__ccgo_up(bp + 256)))[num_sums-uint32(1)]
  41641 			num_sums = num_sums - 1
  41642 			// Update all the sums and find the best one.
  41643 			best_sum = bp + 256
  41644 			i = uint32(0)
  41645 			for {
  41646 				if !(i < num_sums) {
  41647 					break
  41648 				}
  41649 				(**(**[256]Sum)(__ccgo_up(bp + 256)))[i].Fsum += **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(best_index)*num_colors+uint32((**(**[256]Sum)(__ccgo_up(bp + 256)))[i].Findex))*4))
  41650 				if (**(**[256]Sum)(__ccgo_up(bp + 256)))[i].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41651 					best_sum = bp + 256 + uintptr(i)*8
  41652 				}
  41653 				goto _4
  41654 			_4:
  41655 				;
  41656 				i = i + 1
  41657 			}
  41658 		}
  41659 	}
  41660 	WebPSafeFree(tls, cooccurrence)
  41661 	// Re-map the palette.
  41662 	i = uint32(0)
  41663 	for {
  41664 		if !(i < num_colors) {
  41665 			break
  41666 		}
  41667 		**(**uint32_t)(__ccgo_up(palette + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(palette_in + uintptr((**(**[256]uint8_t)(__ccgo_up(bp)))[(first+i)%num_colors])*4))
  41668 		goto _5
  41669 	_5:
  41670 		;
  41671 		i = i + 1
  41672 	}
  41673 	return int32(1)
  41674 }
  41675 
  41676 // -----------------------------------------------------------------------------
  41677 
  41678 func PaletteSort(tls *libc.TLS, method PaletteSorting1, pic uintptr, palette_sorted uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41679 	switch method {
  41680 	case int32(kSortedDefault):
  41681 		if **(**uint32_t)(__ccgo_up(palette_sorted)) == uint32(0) && num_colors > uint32(17) {
  41682 			libc.Xmemcpy(tls, palette, palette_sorted+uintptr(1)*4, uint64(num_colors-libc.Uint32FromInt32(1))*uint64(4))
  41683 			**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors-uint32(1))*4)) = uint32(0)
  41684 		} else {
  41685 			libc.Xmemcpy(tls, palette, palette_sorted, uint64(num_colors)*uint64(4))
  41686 		}
  41687 		return int32(1)
  41688 	case int32(kMinimizeDelta):
  41689 		PaletteSortMinimizeDeltas(tls, palette_sorted, libc.Int32FromUint32(num_colors), palette)
  41690 		return int32(1)
  41691 	case int32(kModifiedZeng):
  41692 		return PaletteSortModifiedZeng(tls, pic, palette_sorted, num_colors, palette)
  41693 	case int32(kUnusedPalette):
  41694 		fallthrough
  41695 	case int32(kPaletteSortingNum):
  41696 		break
  41697 	}
  41698 	return 0
  41699 }
  41700 
  41701 const DFIX = 0
  41702 const FIX = 16
  41703 const LFIX = 2
  41704 
  41705 //------------------------------------------------------------------------------
  41706 
  41707 // Copyright 2010 Google Inc. All Rights Reserved.
  41708 //
  41709 // Use of this source code is governed by a BSD-style license
  41710 // that can be found in the COPYING file in the root of the source
  41711 // tree. An additional intellectual property rights grant can be found
  41712 // in the file PATENTS. All contributing project authors may
  41713 // be found in the AUTHORS file in the root of the source tree.
  41714 // -----------------------------------------------------------------------------
  41715 //
  41716 //  Common types + memory wrappers
  41717 //
  41718 // Author: Skal (pascal.massimino@gmail.com)
  41719 
  41720 // #define USE_DITHERING   // uncomment to enable ordered dithering (not vital)
  41721 
  41722 type SmoothParams = struct {
  41723 	Fwidth          int32
  41724 	Fheight         int32
  41725 	Fstride         int32
  41726 	Frow            int32
  41727 	Fsrc            uintptr
  41728 	Fdst            uintptr
  41729 	Fradius         int32
  41730 	Fscale          int32
  41731 	Fmem            uintptr
  41732 	Fstart          uintptr
  41733 	Fcur            uintptr
  41734 	Fend            uintptr
  41735 	Ftop            uintptr
  41736 	Faverage        uintptr
  41737 	Fnum_levels     int32
  41738 	Fmin            int32
  41739 	Fmax            int32
  41740 	Fmin_level_dist int32
  41741 	Fcorrection     uintptr
  41742 }
  41743 
  41744 //------------------------------------------------------------------------------
  41745 
  41746 func clip_8b(tls *libc.TLS, v int32) (r uint8_t) {
  41747 	var v1, v2 uint32
  41748 	_, _ = v1, v2
  41749 	if !(v&libc.Int32FromUint32(^libc.Uint32FromUint32(0)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(DFIX))) != 0) {
  41750 		v1 = uint32(libc.Uint8FromInt32(v >> libc.Int32FromInt32(DFIX)))
  41751 	} else {
  41752 		if v < 0 {
  41753 			v2 = 0
  41754 		} else {
  41755 			v2 = uint32(255)
  41756 		}
  41757 		v1 = v2
  41758 	}
  41759 	return uint8(v1)
  41760 }
  41761 
  41762 // C documentation
  41763 //
  41764 //	// vertical accumulation
  41765 func VFilter(tls *libc.TLS, p uintptr) {
  41766 	var cur, out, src, top uintptr
  41767 	var new_value, sum uint16_t
  41768 	var w, x int32
  41769 	_, _, _, _, _, _, _, _ = cur, new_value, out, src, sum, top, w, x
  41770 	src = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  41771 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  41772 	cur = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  41773 	top = (*SmoothParams)(unsafe.Pointer(p)).Ftop
  41774 	out = (*SmoothParams)(unsafe.Pointer(p)).Fend
  41775 	sum = uint16(0)
  41776 	x = 0
  41777 	for {
  41778 		if !(x < w) {
  41779 			break
  41780 		}
  41781 		sum = libc.Uint16FromInt32(int32(sum) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + uintptr(x)))))
  41782 		new_value = libc.Uint16FromInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(top + uintptr(x)*2))) + libc.Int32FromUint16(sum))
  41783 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = libc.Uint16FromInt32(libc.Int32FromUint16(new_value) - libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(cur + uintptr(x)*2)))) // vertical sum of 'r' pixels.
  41784 		**(**uint16_t)(__ccgo_up(cur + uintptr(x)*2)) = new_value
  41785 		goto _1
  41786 	_1:
  41787 		;
  41788 		x = x + 1
  41789 	}
  41790 	// move input pointers one row down
  41791 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  41792 	**(**uintptr)(__ccgo_up(p + 56)) += uintptr(w) * 2
  41793 	if (*SmoothParams)(unsafe.Pointer(p)).Fcur == (*SmoothParams)(unsafe.Pointer(p)).Fend {
  41794 		(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  41795 	} // roll-over
  41796 	// We replicate edges, as it's somewhat easier as a boundary condition.
  41797 	// That's why we don't update the 'src' pointer on top/bottom area:
  41798 	if (*SmoothParams)(unsafe.Pointer(p)).Frow >= 0 && (*SmoothParams)(unsafe.Pointer(p)).Frow < (*SmoothParams)(unsafe.Pointer(p)).Fheight-int32(1) {
  41799 		**(**uintptr)(__ccgo_up(p + 16)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  41800 	}
  41801 }
  41802 
  41803 // C documentation
  41804 //
  41805 //	// horizontal accumulation. We use mirror replication of missing pixels, as it's
  41806 //	// a little easier to implement (surprisingly).
  41807 func HFilter(tls *libc.TLS, p uintptr) {
  41808 	var delta, delta1, delta2 uint16_t
  41809 	var in, out uintptr
  41810 	var r, w, x int32
  41811 	var scale uint32_t
  41812 	_, _, _, _, _, _, _, _, _ = delta, delta1, delta2, in, out, r, scale, w, x
  41813 	in = (*SmoothParams)(unsafe.Pointer(p)).Fend
  41814 	out = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  41815 	scale = libc.Uint32FromInt32((*SmoothParams)(unsafe.Pointer(p)).Fscale)
  41816 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  41817 	r = (*SmoothParams)(unsafe.Pointer(p)).Fradius
  41818 	x = 0
  41819 	for {
  41820 		if !(x <= r) {
  41821 			break
  41822 		} // left mirroring
  41823 		delta = libc.Uint16FromInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(x+r-int32(1))*2))) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(r-x)*2))))
  41824 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta) * scale >> int32(FIX))
  41825 		goto _1
  41826 	_1:
  41827 		;
  41828 		x = x + 1
  41829 	}
  41830 	for {
  41831 		if !(x < w-r) {
  41832 			break
  41833 		} // bulk middle run
  41834 		delta1 = libc.Uint16FromInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(x+r)*2))) - libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(x-r-int32(1))*2))))
  41835 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta1) * scale >> int32(FIX))
  41836 		goto _2
  41837 	_2:
  41838 		;
  41839 		x = x + 1
  41840 	}
  41841 	for {
  41842 		if !(x < w) {
  41843 			break
  41844 		} // right mirroring
  41845 		delta2 = libc.Uint16FromInt32(int32(2)*libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(w-int32(1))*2))) - libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(int32(2)*w-int32(2)-r-x)*2))) - libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(in + uintptr(x-r-int32(1))*2))))
  41846 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta2) * scale >> int32(FIX))
  41847 		goto _3
  41848 	_3:
  41849 		;
  41850 		x = x + 1
  41851 	}
  41852 }
  41853 
  41854 // C documentation
  41855 //
  41856 //	// emit one filtered output row
  41857 func ApplyFilter(tls *libc.TLS, p uintptr) {
  41858 	var average, correction, dst uintptr
  41859 	var c, v, w, x int32
  41860 	_, _, _, _, _, _, _ = average, c, correction, dst, v, w, x
  41861 	average = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  41862 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  41863 	correction = (*SmoothParams)(unsafe.Pointer(p)).Fcorrection
  41864 	dst = (*SmoothParams)(unsafe.Pointer(p)).Fdst
  41865 	x = 0
  41866 	for {
  41867 		if !(x < w) {
  41868 			break
  41869 		}
  41870 		v = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(x))))
  41871 		if v < (*SmoothParams)(unsafe.Pointer(p)).Fmax && v > (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  41872 			c = v<<libc.Int32FromInt32(DFIX) + int32(**(**int16_t)(__ccgo_up(correction + uintptr(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(average + uintptr(x)*2)))-v<<libc.Int32FromInt32(LFIX))*2)))
  41873 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = clip_8b(tls, c)
  41874 		}
  41875 		goto _1
  41876 	_1:
  41877 		;
  41878 		x = x + 1
  41879 	}
  41880 	**(**uintptr)(__ccgo_up(p + 24)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride) // advance output pointer
  41881 }
  41882 
  41883 //------------------------------------------------------------------------------
  41884 // Initialize correction table
  41885 
  41886 func InitCorrectionLUT(tls *libc.TLS, lut uintptr, min_dist int32) {
  41887 	var c, delta, i, max_threshold, threshold1, threshold2, v2, v3 int32
  41888 	_, _, _, _, _, _, _, _ = c, delta, i, max_threshold, threshold1, threshold2, v2, v3
  41889 	// The correction curve is:
  41890 	//   f(x) = x for x <= threshold2
  41891 	//   f(x) = 0 for x >= threshold1
  41892 	// and a linear interpolation for range x=[threshold2, threshold1]
  41893 	// (along with f(-x) = -f(x) symmetry).
  41894 	// Note that: threshold2 = 3/4 * threshold1
  41895 	threshold1 = min_dist << int32(LFIX)
  41896 	threshold2 = int32(3) * threshold1 >> int32(2)
  41897 	max_threshold = threshold2 << DFIX
  41898 	delta = threshold1 - threshold2
  41899 	i = int32(1)
  41900 	for {
  41901 		if !(i <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1)) {
  41902 			break
  41903 		}
  41904 		if i <= threshold2 {
  41905 			v2 = i << DFIX
  41906 		} else {
  41907 			if i < threshold1 {
  41908 				v3 = max_threshold * (threshold1 - i) / delta
  41909 			} else {
  41910 				v3 = 0
  41911 			}
  41912 			v2 = v3
  41913 		}
  41914 		c = v2
  41915 		c = c >> int32(LFIX)
  41916 		**(**int16_t)(__ccgo_up(lut + uintptr(+i)*2)) = int16(+c)
  41917 		**(**int16_t)(__ccgo_up(lut + uintptr(-i)*2)) = int16(-c)
  41918 		goto _1
  41919 	_1:
  41920 		;
  41921 		i = i + 1
  41922 	}
  41923 	**(**int16_t)(__ccgo_up(lut)) = 0
  41924 }
  41925 
  41926 func CountLevels(tls *libc.TLS, p uintptr) {
  41927 	var data uintptr
  41928 	var i, j, last_level, level_dist, v int32
  41929 	var used_levels [256]uint8_t
  41930 	_, _, _, _, _, _, _ = data, i, j, last_level, level_dist, used_levels, v
  41931 	used_levels = [256]uint8_t{}
  41932 	data = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  41933 	(*SmoothParams)(unsafe.Pointer(p)).Fmin = int32(255)
  41934 	(*SmoothParams)(unsafe.Pointer(p)).Fmax = 0
  41935 	j = 0
  41936 	for {
  41937 		if !(j < (*SmoothParams)(unsafe.Pointer(p)).Fheight) {
  41938 			break
  41939 		}
  41940 		i = 0
  41941 		for {
  41942 			if !(i < (*SmoothParams)(unsafe.Pointer(p)).Fwidth) {
  41943 				break
  41944 			}
  41945 			v = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(i))))
  41946 			if v < (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  41947 				(*SmoothParams)(unsafe.Pointer(p)).Fmin = v
  41948 			}
  41949 			if v > (*SmoothParams)(unsafe.Pointer(p)).Fmax {
  41950 				(*SmoothParams)(unsafe.Pointer(p)).Fmax = v
  41951 			}
  41952 			used_levels[v] = uint8(1)
  41953 			goto _2
  41954 		_2:
  41955 			;
  41956 			i = i + 1
  41957 		}
  41958 		data = data + uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  41959 		goto _1
  41960 	_1:
  41961 		;
  41962 		j = j + 1
  41963 	}
  41964 	// Compute the mininum distance between two non-zero levels.
  41965 	(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = (*SmoothParams)(unsafe.Pointer(p)).Fmax - (*SmoothParams)(unsafe.Pointer(p)).Fmin
  41966 	last_level = -int32(1)
  41967 	i = 0
  41968 	for {
  41969 		if !(i < int32(256)) {
  41970 			break
  41971 		}
  41972 		if used_levels[i] != 0 {
  41973 			(*SmoothParams)(unsafe.Pointer(p)).Fnum_levels = (*SmoothParams)(unsafe.Pointer(p)).Fnum_levels + 1
  41974 			if last_level >= 0 {
  41975 				level_dist = i - last_level
  41976 				if level_dist < (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist {
  41977 					(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = level_dist
  41978 				}
  41979 			}
  41980 			last_level = i
  41981 		}
  41982 		goto _3
  41983 	_3:
  41984 		;
  41985 		i = i + 1
  41986 	}
  41987 }
  41988 
  41989 // C documentation
  41990 //
  41991 //	// Initialize all params.
  41992 func InitParams(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, radius int32, p uintptr) (r int32) {
  41993 	var R int32
  41994 	var mem uintptr
  41995 	var size_lut, size_m, size_scratch_m, total_size size_t
  41996 	_, _, _, _, _, _ = R, mem, size_lut, size_m, size_scratch_m, total_size
  41997 	R = int32(2)*radius + int32(1) // total size of the kernel
  41998 	size_scratch_m = libc.Uint64FromInt32((R+int32(1))*width) * uint64(2)
  41999 	size_m = libc.Uint64FromInt32(width) * uint64(2)
  42000 	size_lut = libc.Uint64FromInt32(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))) * libc.Uint64FromInt64(2)
  42001 	total_size = size_scratch_m + size_m + size_lut
  42002 	mem = WebPSafeMalloc(tls, uint64(1), total_size)
  42003 	if mem == libc.UintptrFromInt32(0) {
  42004 		return 0
  42005 	}
  42006 	(*SmoothParams)(unsafe.Pointer(p)).Fmem = mem
  42007 	(*SmoothParams)(unsafe.Pointer(p)).Fstart = mem
  42008 	(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42009 	(*SmoothParams)(unsafe.Pointer(p)).Fend = (*SmoothParams)(unsafe.Pointer(p)).Fstart + uintptr(R*width)*2
  42010 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fend - uintptr(width)*2
  42011 	libc.Xmemset(tls, (*SmoothParams)(unsafe.Pointer(p)).Ftop, 0, libc.Uint64FromInt32(width)*uint64(2))
  42012 	mem = mem + uintptr(size_scratch_m)
  42013 	(*SmoothParams)(unsafe.Pointer(p)).Faverage = mem
  42014 	mem = mem + uintptr(size_m)
  42015 	(*SmoothParams)(unsafe.Pointer(p)).Fwidth = width
  42016 	(*SmoothParams)(unsafe.Pointer(p)).Fheight = height
  42017 	(*SmoothParams)(unsafe.Pointer(p)).Fstride = stride
  42018 	(*SmoothParams)(unsafe.Pointer(p)).Fsrc = data
  42019 	(*SmoothParams)(unsafe.Pointer(p)).Fdst = data
  42020 	(*SmoothParams)(unsafe.Pointer(p)).Fradius = radius
  42021 	(*SmoothParams)(unsafe.Pointer(p)).Fscale = libc.Int32FromInt32(1) << (libc.Int32FromInt32(FIX) + libc.Int32FromInt32(LFIX)) / (R * R) // normalization constant
  42022 	(*SmoothParams)(unsafe.Pointer(p)).Frow = -radius
  42023 	// analyze the input distribution so we can best-fit the threshold
  42024 	CountLevels(tls, p)
  42025 	// correction table
  42026 	(*SmoothParams)(unsafe.Pointer(p)).Fcorrection = mem + uintptr(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))*2
  42027 	InitCorrectionLUT(tls, (*SmoothParams)(unsafe.Pointer(p)).Fcorrection, (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist)
  42028 	return int32(1)
  42029 }
  42030 
  42031 func CleanupParams(tls *libc.TLS, p uintptr) {
  42032 	WebPSafeFree(tls, (*SmoothParams)(unsafe.Pointer(p)).Fmem)
  42033 }
  42034 
  42035 func WebPDequantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, strength int32) (r int32) {
  42036 	bp := tls.Alloc(112)
  42037 	defer tls.Free(112)
  42038 	var radius int32
  42039 	var _ /* p at bp+0 */ SmoothParams
  42040 	_ = radius
  42041 	radius = int32(4) * strength / int32(100)
  42042 	if strength < 0 || strength > int32(100) {
  42043 		return 0
  42044 	}
  42045 	if data == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
  42046 		return 0
  42047 	} // bad params
  42048 	// limit the filter size to not exceed the image dimensions
  42049 	if int32(2)*radius+int32(1) > width {
  42050 		radius = (width - int32(1)) >> int32(1)
  42051 	}
  42052 	if int32(2)*radius+int32(1) > height {
  42053 		radius = (height - int32(1)) >> int32(1)
  42054 	}
  42055 	if radius > 0 {
  42056 		libc.Xmemset(tls, bp, 0, uint64(112))
  42057 		if !(InitParams(tls, data, width, height, stride, radius, bp) != 0) {
  42058 			return 0
  42059 		}
  42060 		if (**(**SmoothParams)(__ccgo_up(bp))).Fnum_levels > int32(2) {
  42061 			for {
  42062 				if !((**(**SmoothParams)(__ccgo_up(bp))).Frow < (**(**SmoothParams)(__ccgo_up(bp))).Fheight) {
  42063 					break
  42064 				}
  42065 				VFilter(tls, bp) // accumulate average of input
  42066 				// Need to wait few rows in order to prime the filter,
  42067 				// before emitting some output.
  42068 				if (**(**SmoothParams)(__ccgo_up(bp))).Frow >= (**(**SmoothParams)(__ccgo_up(bp))).Fradius {
  42069 					HFilter(tls, bp)
  42070 					ApplyFilter(tls, bp)
  42071 				}
  42072 				goto _1
  42073 			_1:
  42074 				;
  42075 				(**(**SmoothParams)(__ccgo_up(bp))).Frow = (**(**SmoothParams)(__ccgo_up(bp))).Frow + 1
  42076 			}
  42077 		}
  42078 		CleanupParams(tls, bp)
  42079 	}
  42080 	return int32(1)
  42081 }
  42082 
  42083 const ERROR_THRESHOLD = 0.0001
  42084 const MAX_ITER = 6
  42085 const NUM_SYMBOLS = 256
  42086 
  42087 // -----------------------------------------------------------------------------
  42088 // Quantize levels.
  42089 
  42090 func QuantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, num_levels int32, sse uintptr) (r int32) {
  42091 	bp := tls.Alloc(4096)
  42092 	defer tls.Free(4096)
  42093 	var count, err, err_threshold, error1, last_err float64
  42094 	var data_size, n, n1 size_t
  42095 	var freq, q_level [256]int32
  42096 	var i, iter, max_s, min_s, num_levels_in, s, s1, slot, slot1 int32
  42097 	var inv_q_level [256]float64
  42098 	var map1 [256]uint8_t
  42099 	var _ /* q_count at bp+2048 */ [256]float64
  42100 	var _ /* q_sum at bp+0 */ [256]float64
  42101 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = count, data_size, err, err_threshold, error1, freq, i, inv_q_level, iter, last_err, map1, max_s, min_s, n, n1, num_levels_in, q_level, s, s1, slot, slot1
  42102 	freq = [256]int32{}
  42103 	q_level = [256]int32{}
  42104 	inv_q_level = [256]float64{}
  42105 	min_s = int32(255)
  42106 	max_s = 0
  42107 	data_size = libc.Uint64FromInt32(height * width)
  42108 	last_err = float64(1e+38)
  42109 	err = float64(0)
  42110 	err_threshold = float64(float64(0.0001) * float64(data_size))
  42111 	if data == libc.UintptrFromInt32(0) {
  42112 		return 0
  42113 	}
  42114 	if width <= 0 || height <= 0 {
  42115 		return 0
  42116 	}
  42117 	if num_levels < int32(2) || num_levels > int32(256) {
  42118 		return 0
  42119 	}
  42120 	num_levels_in = 0
  42121 	n = uint64(0)
  42122 	for {
  42123 		if !(n < data_size) {
  42124 			break
  42125 		}
  42126 		num_levels_in = num_levels_in + libc.BoolInt32(freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] == 0)
  42127 		if min_s > libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42128 			min_s = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42129 		}
  42130 		if max_s < libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42131 			max_s = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42132 		}
  42133 		freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] = freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] + 1
  42134 		goto _1
  42135 	_1:
  42136 		;
  42137 		n = n + 1
  42138 	}
  42139 	if num_levels_in <= num_levels {
  42140 		goto End
  42141 	} // nothing to do!
  42142 	// Start with uniformly spread centroids.
  42143 	i = 0
  42144 	for {
  42145 		if !(i < num_levels) {
  42146 			break
  42147 		}
  42148 		inv_q_level[i] = float64(min_s) + float64(float64(max_s-min_s)*float64(i))/float64(num_levels-libc.Int32FromInt32(1))
  42149 		goto _2
  42150 	_2:
  42151 		;
  42152 		i = i + 1
  42153 	}
  42154 	// Fixed values. Won't be changed.
  42155 	q_level[min_s] = 0
  42156 	q_level[max_s] = num_levels - int32(1)
  42157 	// k-Means iterations.
  42158 	iter = 0
  42159 	for {
  42160 		if !(iter < int32(MAX_ITER)) {
  42161 			break
  42162 		}
  42163 		**(**[256]float64)(__ccgo_up(bp)) = [256]float64{}
  42164 		**(**[256]float64)(__ccgo_up(bp + 2048)) = [256]float64{}
  42165 		slot = 0
  42166 		// Assign classes to representatives.
  42167 		s = min_s
  42168 		for {
  42169 			if !(s <= max_s) {
  42170 				break
  42171 			}
  42172 			// Keep track of the nearest neighbour 'slot'
  42173 			for slot < num_levels-int32(1) && float64(int32(2)*s) > inv_q_level[slot]+inv_q_level[slot+int32(1)] {
  42174 				slot = slot + 1
  42175 			}
  42176 			if freq[s] > 0 {
  42177 				**(**float64)(__ccgo_up(bp + uintptr(slot)*8)) += float64(s * freq[s])
  42178 				**(**float64)(__ccgo_up(bp + 2048 + uintptr(slot)*8)) += float64(freq[s])
  42179 			}
  42180 			q_level[s] = slot
  42181 			goto _4
  42182 		_4:
  42183 			;
  42184 			s = s + 1
  42185 		}
  42186 		// Assign new representatives to classes.
  42187 		if num_levels > int32(2) {
  42188 			slot = int32(1)
  42189 			for {
  42190 				if !(slot < num_levels-int32(1)) {
  42191 					break
  42192 				}
  42193 				count = (**(**[256]float64)(__ccgo_up(bp + 2048)))[slot]
  42194 				if count > float64(0) {
  42195 					inv_q_level[slot] = (**(**[256]float64)(__ccgo_up(bp)))[slot] / count
  42196 				}
  42197 				goto _5
  42198 			_5:
  42199 				;
  42200 				slot = slot + 1
  42201 			}
  42202 		}
  42203 		// Compute convergence error.
  42204 		err = float64(0)
  42205 		s = min_s
  42206 		for {
  42207 			if !(s <= max_s) {
  42208 				break
  42209 			}
  42210 			error1 = float64(s) - inv_q_level[q_level[s]]
  42211 			err = err + float64(float64(float64(freq[s])*error1)*error1)
  42212 			goto _6
  42213 		_6:
  42214 			;
  42215 			s = s + 1
  42216 		}
  42217 		// Check for convergence: we stop as soon as the error is no
  42218 		// longer improving.
  42219 		if last_err-err < err_threshold {
  42220 			break
  42221 		}
  42222 		last_err = err
  42223 		goto _3
  42224 	_3:
  42225 		;
  42226 		iter = iter + 1
  42227 	}
  42228 	// Remap the alpha plane to quantized values.
  42229 	s1 = min_s
  42230 	for {
  42231 		if !(s1 <= max_s) {
  42232 			break
  42233 		}
  42234 		slot1 = q_level[s1]
  42235 		map1[s1] = uint8(inv_q_level[slot1] + libc.Float64FromFloat64(0.5))
  42236 		goto _7
  42237 	_7:
  42238 		;
  42239 		s1 = s1 + 1
  42240 	}
  42241 	// Final pass.
  42242 	n1 = uint64(0)
  42243 	for {
  42244 		if !(n1 < data_size) {
  42245 			break
  42246 		}
  42247 		**(**uint8_t)(__ccgo_up(data + uintptr(n1))) = map1[**(**uint8_t)(__ccgo_up(data + uintptr(n1)))]
  42248 		goto _8
  42249 	_8:
  42250 		;
  42251 		n1 = n1 + 1
  42252 	}
  42253 	goto End
  42254 End:
  42255 	;
  42256 	// Store sum of squared error if needed.
  42257 	if sse != libc.UintptrFromInt32(0) {
  42258 		**(**uint64_t)(__ccgo_up(sse)) = uint64(err)
  42259 	}
  42260 	return int32(1)
  42261 }
  42262 
  42263 //------------------------------------------------------------------------------
  42264 
  42265 // C documentation
  42266 //
  42267 //	// 31b-range values
  42268 var kRandomTable = [55]uint32_t{
  42269 	0:  uint32(0x0de15230),
  42270 	1:  uint32(0x03b31886),
  42271 	2:  uint32(0x775faccb),
  42272 	3:  uint32(0x1c88626a),
  42273 	4:  uint32(0x68385c55),
  42274 	5:  uint32(0x14b3b828),
  42275 	6:  uint32(0x4a85fef8),
  42276 	7:  uint32(0x49ddb84b),
  42277 	8:  uint32(0x64fcf397),
  42278 	9:  uint32(0x5c550289),
  42279 	10: uint32(0x4a290000),
  42280 	11: uint32(0x0d7ec1da),
  42281 	12: uint32(0x5940b7ab),
  42282 	13: uint32(0x5492577d),
  42283 	14: uint32(0x4e19ca72),
  42284 	15: uint32(0x38d38c69),
  42285 	16: uint32(0x0c01ee65),
  42286 	17: uint32(0x32a1755f),
  42287 	18: uint32(0x5437f652),
  42288 	19: uint32(0x5abb2c32),
  42289 	20: uint32(0x0faa57b1),
  42290 	21: uint32(0x73f533e7),
  42291 	22: uint32(0x685feeda),
  42292 	23: uint32(0x7563cce2),
  42293 	24: uint32(0x6e990e83),
  42294 	25: uint32(0x4730a7ed),
  42295 	26: uint32(0x4fc0d9c6),
  42296 	27: uint32(0x496b153c),
  42297 	28: uint32(0x4f1403fa),
  42298 	29: uint32(0x541afb0c),
  42299 	30: uint32(0x73990b32),
  42300 	31: uint32(0x26d7cb1c),
  42301 	32: uint32(0x6fcc3706),
  42302 	33: uint32(0x2cbb77d8),
  42303 	34: uint32(0x75762f2a),
  42304 	35: uint32(0x6425ccdd),
  42305 	36: uint32(0x24b35461),
  42306 	37: uint32(0x0a7d8715),
  42307 	38: uint32(0x220414a8),
  42308 	39: uint32(0x141ebf67),
  42309 	40: uint32(0x56b41583),
  42310 	41: uint32(0x73e502e3),
  42311 	42: uint32(0x44cab16f),
  42312 	43: uint32(0x28264d42),
  42313 	44: uint32(0x73baaefb),
  42314 	45: uint32(0x0a50ebed),
  42315 	46: uint32(0x1d6ab6fb),
  42316 	47: uint32(0x0d3ad40b),
  42317 	48: uint32(0x35db3b68),
  42318 	49: uint32(0x2b081e83),
  42319 	50: uint32(0x77ce6b95),
  42320 	51: uint32(0x5181e5f0),
  42321 	52: uint32(0x78853bbc),
  42322 	53: uint32(0x009f9494),
  42323 	54: uint32(0x27e5ed3c),
  42324 }
  42325 
  42326 func VP8InitRandom(tls *libc.TLS, rg uintptr, dithering float32) {
  42327 	var v1, v2 uint32
  42328 	_, _ = v1, v2
  42329 	libc.Xmemcpy(tls, rg+8, uintptr(unsafe.Pointer(&kRandomTable)), uint64(220))
  42330 	(*VP8Random)(unsafe.Pointer(rg)).Findex1 = 0
  42331 	(*VP8Random)(unsafe.Pointer(rg)).Findex2 = int32(31)
  42332 	if float64(dithering) < float64(0) {
  42333 		v1 = uint32(0)
  42334 	} else {
  42335 		if float64(dithering) > float64(1) {
  42336 			v2 = libc.Uint32FromInt32(libc.Int32FromInt32(1) << libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX))
  42337 		} else {
  42338 			v2 = uint32(float32(float32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX)) * dithering))
  42339 		}
  42340 		v1 = v2
  42341 	}
  42342 	(*VP8Random)(unsafe.Pointer(rg)).Famp = libc.Int32FromUint32(v1)
  42343 }
  42344 
  42345 //------------------------------------------------------------------------------
  42346 
  42347 //------------------------------------------------------------------------------
  42348 
  42349 func WebPRescalerInit(tls *libc.TLS, rescaler uintptr, src_width int32, src_height int32, dst uintptr, dst_width int32, dst_height int32, dst_stride int32, num_channels int32, work uintptr) (r int32) {
  42350 	var den, num, ratio, total_size, v1 uint64_t
  42351 	var x_add, x_sub, y_add, y_sub, v2 int32
  42352 	_, _, _, _, _, _, _, _, _, _ = den, num, ratio, total_size, x_add, x_sub, y_add, y_sub, v1, v2
  42353 	x_add = src_width
  42354 	x_sub = dst_width
  42355 	y_add = src_height
  42356 	y_sub = dst_height
  42357 	total_size = uint64(uint64(2) * libc.Uint64FromInt32(dst_width) * libc.Uint64FromInt32(num_channels) * uint64(4))
  42358 	v1 = total_size
  42359 	v2 = libc.BoolInt32(v1 == v1)
  42360 	goto _3
  42361 _3:
  42362 	if !(v2 != 0) {
  42363 		return 0
  42364 	}
  42365 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand = libc.BoolInt32(src_width < dst_width)
  42366 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand = libc.BoolInt32(src_height < dst_height)
  42367 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_width = src_width
  42368 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_height = src_height
  42369 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_width = dst_width
  42370 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_height = dst_height
  42371 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_y = 0
  42372 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_y = 0
  42373 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst = dst
  42374 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_stride = dst_stride
  42375 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fnum_channels = num_channels
  42376 	// for 'x_expand', we use bilinear interpolation
  42377 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42378 		v2 = x_sub - int32(1)
  42379 	} else {
  42380 		v2 = x_add
  42381 	}
  42382 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add = v2
  42383 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42384 		v2 = x_add - int32(1)
  42385 	} else {
  42386 		v2 = x_sub
  42387 	}
  42388 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub = v2
  42389 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0) { // fx_scale is not used otherwise
  42390 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffx_scale = uint32(libc.Uint64FromInt32(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub))
  42391 	}
  42392 	// vertical scaling parameters
  42393 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42394 		v2 = y_add - int32(1)
  42395 	} else {
  42396 		v2 = y_add
  42397 	}
  42398 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add = v2
  42399 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42400 		v2 = y_sub - int32(1)
  42401 	} else {
  42402 		v2 = y_sub
  42403 	}
  42404 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub = v2
  42405 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42406 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42407 	} else {
  42408 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add
  42409 	}
  42410 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum = v2
  42411 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0) {
  42412 		// This is WEBP_RESCALER_FRAC(dst_height, x_add * y_add) without the cast.
  42413 		// Its value is <= WEBP_RESCALER_ONE, because dst_height <= rescaler->y_add
  42414 		// and rescaler->x_add >= 1;
  42415 		num = uint64(uint64(libc.Uint64FromInt32(dst_height)) * (libc.Uint64FromUint64(1) << libc.Int32FromInt32(WEBP_RESCALER_RFIX)))
  42416 		den = libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add) * libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add)
  42417 		ratio = num / den
  42418 		if ratio != uint64(uint32(ratio)) {
  42419 			// When ratio == WEBP_RESCALER_ONE, we can't represent the ratio with the
  42420 			// current fixed-point precision. This happens when src_height ==
  42421 			// rescaler->y_add (which == src_height), and rescaler->x_add == 1.
  42422 			// => We special-case fxy_scale = 0, in WebPRescalerExportRow().
  42423 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(0)
  42424 		} else {
  42425 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(ratio)
  42426 		}
  42427 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffy_scale = uint32(libc.Uint64FromInt32(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub))
  42428 	} else {
  42429 		(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffy_scale = uint32(libc.Uint64FromInt32(libc.Int32FromInt32(1)) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add))
  42430 		// rescaler->fxy_scale is unused here.
  42431 	}
  42432 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Firow = work
  42433 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffrow = work + uintptr(num_channels*dst_width)*4
  42434 	libc.Xmemset(tls, work, 0, total_size)
  42435 	WebPRescalerDspInit(tls)
  42436 	return int32(1)
  42437 }
  42438 
  42439 func WebPRescalerGetScaledDimensions(tls *libc.TLS, src_width int32, src_height int32, scaled_width uintptr, scaled_height uintptr) (r int32) {
  42440 	var height, max_size, width int32
  42441 	_, _, _ = height, max_size, width
  42442 	width = **(**int32)(__ccgo_up(scaled_width))
  42443 	height = **(**int32)(__ccgo_up(scaled_height))
  42444 	max_size = libc.Int32FromInt32(INT_MAX) / libc.Int32FromInt32(2)
  42445 	// if width is unspecified, scale original proportionally to height ratio.
  42446 	if width == 0 && src_height > 0 {
  42447 		width = libc.Int32FromUint64((libc.Uint64FromInt32(src_width)*libc.Uint64FromInt32(height) + libc.Uint64FromInt32(src_height) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt32(src_height))
  42448 	}
  42449 	// if height is unspecified, scale original proportionally to width ratio.
  42450 	if height == 0 && src_width > 0 {
  42451 		height = libc.Int32FromUint64((libc.Uint64FromInt32(src_height)*libc.Uint64FromInt32(width) + libc.Uint64FromInt32(src_width) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt32(src_width))
  42452 	}
  42453 	// Check if the overall dimensions still make sense.
  42454 	if width <= 0 || height <= 0 || width > max_size || height > max_size {
  42455 		return 0
  42456 	}
  42457 	**(**int32)(__ccgo_up(scaled_width)) = width
  42458 	**(**int32)(__ccgo_up(scaled_height)) = height
  42459 	return int32(1)
  42460 	return r
  42461 }
  42462 
  42463 //------------------------------------------------------------------------------
  42464 // all-in-one calls
  42465 
  42466 func WebPRescaleNeededLines(tls *libc.TLS, rescaler uintptr, max_num_lines int32) (r int32) {
  42467 	var num_lines, v1 int32
  42468 	_, _ = num_lines, v1
  42469 	num_lines = ((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum + (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub - int32(1)) / (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42470 	if num_lines > max_num_lines {
  42471 		v1 = max_num_lines
  42472 	} else {
  42473 		v1 = num_lines
  42474 	}
  42475 	return v1
  42476 }
  42477 
  42478 func WebPRescalerImport(tls *libc.TLS, rescaler2 uintptr, num_lines int32, src uintptr, src_stride int32) (r int32) {
  42479 	var tmp, v1, v4 uintptr
  42480 	var total_imported, x, v2, v5 int32
  42481 	var v7 bool
  42482 	_, _, _, _, _, _, _, _ = tmp, total_imported, x, v1, v2, v4, v5, v7
  42483 	total_imported = 0
  42484 	for {
  42485 		if v7 = total_imported < num_lines; v7 {
  42486 			v1 = rescaler2
  42487 			v4 = v1
  42488 			v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42489 			goto _6
  42490 		_6:
  42491 			;
  42492 			v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42493 			goto _3
  42494 		_3:
  42495 		}
  42496 		if !(v7 && !(v2 != 0)) {
  42497 			break
  42498 		}
  42499 		if (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0 {
  42500 			tmp = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow
  42501 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow
  42502 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow = tmp
  42503 		}
  42504 		WebPRescalerImportRow(tls, rescaler2, src)
  42505 		if !((*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0) {
  42506 			x = 0
  42507 			for {
  42508 				if !(x < (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width) {
  42509 					break
  42510 				}
  42511 				**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow + uintptr(x)*4)) += **(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow + uintptr(x)*4))
  42512 				goto _8
  42513 			_8:
  42514 				;
  42515 				x = x + 1
  42516 			}
  42517 		}
  42518 		(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y + 1
  42519 		src = src + uintptr(src_stride)
  42520 		total_imported = total_imported + 1
  42521 		**(**int32)(__ccgo_up(rescaler2 + 24)) -= (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_sub
  42522 	}
  42523 	return total_imported
  42524 }
  42525 
  42526 func WebPRescalerExport(tls *libc.TLS, rescaler2 uintptr) (r int32) {
  42527 	var total_exported, v2, v5 int32
  42528 	var v1, v4 uintptr
  42529 	_, _, _, _, _ = total_exported, v1, v2, v4, v5
  42530 	total_exported = 0
  42531 	for {
  42532 		v1 = rescaler2
  42533 		v4 = v1
  42534 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42535 		goto _6
  42536 	_6:
  42537 		;
  42538 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42539 		goto _3
  42540 	_3:
  42541 		if !(v2 != 0) {
  42542 			break
  42543 		}
  42544 		WebPRescalerExportRow(tls, rescaler2)
  42545 		total_exported = total_exported + 1
  42546 	}
  42547 	return total_exported
  42548 }
  42549 
  42550 //------------------------------------------------------------------------------
  42551 
  42552 //------------------------------------------------------------------------------
  42553 
  42554 func Init(tls *libc.TLS, worker uintptr) {
  42555 	libc.Xmemset(tls, worker, 0, uint64(48))
  42556 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42557 }
  42558 
  42559 func Sync(tls *libc.TLS, worker uintptr) (r int32) {
  42560 	return libc.BoolInt32(!((*WebPWorker)(unsafe.Pointer(worker)).Fhad_error != 0))
  42561 }
  42562 
  42563 func Reset(tls *libc.TLS, worker uintptr) (r int32) {
  42564 	var ok int32
  42565 	_ = ok
  42566 	ok = int32(1)
  42567 	(*WebPWorker)(unsafe.Pointer(worker)).Fhad_error = 0
  42568 	if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus < int32(OK) {
  42569 		(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(OK)
  42570 	} else {
  42571 		if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus > int32(OK) {
  42572 			ok = Sync(tls, worker)
  42573 		}
  42574 	}
  42575 	return ok
  42576 }
  42577 
  42578 func Execute(tls *libc.TLS, worker uintptr) {
  42579 	if (*WebPWorker)(unsafe.Pointer(worker)).Fhook != libc.UintptrFromInt32(0) {
  42580 		**(**int32)(__ccgo_up(worker + 40)) |= libc.BoolInt32(!((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorker)(unsafe.Pointer(worker)).Fhook})))(tls, (*WebPWorker)(unsafe.Pointer(worker)).Fdata1, (*WebPWorker)(unsafe.Pointer(worker)).Fdata2) != 0))
  42581 	}
  42582 }
  42583 
  42584 func Launch(tls *libc.TLS, worker uintptr) {
  42585 	Execute(tls, worker)
  42586 }
  42587 
  42588 func End(tls *libc.TLS, worker uintptr) {
  42589 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42590 }
  42591 
  42592 //------------------------------------------------------------------------------
  42593 
  42594 var g_worker_interface = WebPWorkerInterface{}
  42595 
  42596 func init() {
  42597 	p := unsafe.Pointer(&g_worker_interface)
  42598 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(Init)
  42599 	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(Reset)
  42600 	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(Sync)
  42601 	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(Launch)
  42602 	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(Execute)
  42603 	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(End)
  42604 }
  42605 
  42606 func WebPSetWorkerInterface(tls *libc.TLS, winterface uintptr) (r int32) {
  42607 	if winterface == libc.UintptrFromInt32(0) || (*WebPWorkerInterface)(unsafe.Pointer(winterface)).FInit == libc.UintptrFromInt32(0) || (*WebPWorkerInterface)(unsafe.Pointer(winterface)).FReset == libc.UintptrFromInt32(0) || (*WebPWorkerInterface)(unsafe.Pointer(winterface)).FSync == libc.UintptrFromInt32(0) || (*WebPWorkerInterface)(unsafe.Pointer(winterface)).FLaunch == libc.UintptrFromInt32(0) || (*WebPWorkerInterface)(unsafe.Pointer(winterface)).FExecute == libc.UintptrFromInt32(0) || (*WebPWorkerInterface)(unsafe.Pointer(winterface)).FEnd == libc.UintptrFromInt32(0) {
  42608 		return 0
  42609 	}
  42610 	g_worker_interface = **(**WebPWorkerInterface)(__ccgo_up(winterface))
  42611 	return int32(1)
  42612 }
  42613 
  42614 func WebPGetWorkerInterface(tls *libc.TLS) (r uintptr) {
  42615 	return uintptr(unsafe.Pointer(&g_worker_interface))
  42616 }
  42617 
  42618 //------------------------------------------------------------------------------
  42619 
  42620 // If PRINT_MEM_INFO is defined, extra info (like total memory used, number of
  42621 // alloc/free etc) is printed. For debugging/tuning purpose only (it's slow,
  42622 // and not multi-thread safe!).
  42623 // An interesting alternative is valgrind's 'massif' tool:
  42624 //    https://valgrind.org/docs/manual/ms-manual.html
  42625 // Here is an example command line:
  42626 /*    valgrind --tool=massif --massif-out-file=massif.out                --stacks=yes --alloc-fn=WebPSafeMalloc --alloc-fn=WebPSafeCalloc
  42627       ms_print massif.out
  42628 */
  42629 // In addition:
  42630 // * if PRINT_MEM_TRAFFIC is defined, all the details of the malloc/free cycles
  42631 //   are printed.
  42632 // * if MALLOC_FAIL_AT is defined, the global environment variable
  42633 //   $MALLOC_FAIL_AT is used to simulate a memory error when calloc or malloc
  42634 //   is called for the nth time. Example usage:
  42635 //   export MALLOC_FAIL_AT=50 && ./examples/cwebp input.png
  42636 // * if MALLOC_LIMIT is defined, the global environment variable $MALLOC_LIMIT
  42637 //   sets the maximum amount of memory (in bytes) made available to libwebp.
  42638 //   This can be used to emulate environment with very limited memory.
  42639 //   Example: export MALLOC_LIMIT=64000000 && ./examples/dwebp picture.webp
  42640 
  42641 // #define PRINT_MEM_INFO
  42642 // #define PRINT_MEM_TRAFFIC
  42643 // #define MALLOC_FAIL_AT
  42644 // #define MALLOC_LIMIT
  42645 
  42646 //------------------------------------------------------------------------------
  42647 // Checked memory allocation
  42648 
  42649 // C documentation
  42650 //
  42651 //	// Returns 0 in case of overflow of nmemb * size.
  42652 func CheckSizeArgumentsOverflow(tls *libc.TLS, nmemb uint64_t, size1 size_t) (r int32) {
  42653 	var total_size, v1 uint64_t
  42654 	var v2 int32
  42655 	_, _, _ = total_size, v1, v2
  42656 	total_size = nmemb * size1
  42657 	if nmemb == uint64(0) {
  42658 		return int32(1)
  42659 	}
  42660 	if size1 > libc.Uint64FromUint64(1)<<libc.Int32FromInt32(34)/nmemb {
  42661 		return 0
  42662 	}
  42663 	v1 = total_size
  42664 	v2 = libc.BoolInt32(v1 == v1)
  42665 	goto _3
  42666 _3:
  42667 	if !(v2 != 0) {
  42668 		return 0
  42669 	}
  42670 	return int32(1)
  42671 }
  42672 
  42673 func WebPSafeMalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42674 	var ptr uintptr
  42675 	_ = ptr
  42676 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42677 		return libc.UintptrFromInt32(0)
  42678 	}
  42679 	ptr = libc.Xmalloc(tls, nmemb*size)
  42680 	return ptr
  42681 }
  42682 
  42683 func WebPSafeCalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42684 	var ptr uintptr
  42685 	_ = ptr
  42686 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42687 		return libc.UintptrFromInt32(0)
  42688 	}
  42689 	ptr = libc.Xcalloc(tls, nmemb, size)
  42690 	return ptr
  42691 }
  42692 
  42693 func WebPSafeFree(tls *libc.TLS, ptr uintptr) {
  42694 	if ptr != libc.UintptrFromInt32(0) {
  42695 	}
  42696 	libc.Xfree(tls, ptr)
  42697 }
  42698 
  42699 // Public API functions.
  42700 
  42701 func WebPMalloc(tls *libc.TLS, size size_t) (r uintptr) {
  42702 	return WebPSafeMalloc(tls, uint64(1), size)
  42703 }
  42704 
  42705 func WebPFree(tls *libc.TLS, ptr uintptr) {
  42706 	WebPSafeFree(tls, ptr)
  42707 }
  42708 
  42709 //------------------------------------------------------------------------------
  42710 
  42711 func WebPCopyPlane(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, dst_stride int32, width int32, height int32) {
  42712 	var v1 int32
  42713 	_ = v1
  42714 	for {
  42715 		v1 = height
  42716 		height = height - 1
  42717 		if !(v1 > 0) {
  42718 			break
  42719 		}
  42720 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(width))
  42721 		src = src + uintptr(src_stride)
  42722 		dst = dst + uintptr(dst_stride)
  42723 	}
  42724 }
  42725 
  42726 func WebPCopyPixels(tls *libc.TLS, src uintptr, dst uintptr) {
  42727 	WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(src)).Fargb, int32(4)*(*WebPPicture)(unsafe.Pointer(src)).Fargb_stride, (*WebPPicture)(unsafe.Pointer(dst)).Fargb, int32(4)*(*WebPPicture)(unsafe.Pointer(dst)).Fargb_stride, int32(4)*(*WebPPicture)(unsafe.Pointer(src)).Fwidth, (*WebPPicture)(unsafe.Pointer(src)).Fheight)
  42728 }
  42729 
  42730 //------------------------------------------------------------------------------
  42731 
  42732 func WebPGetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  42733 	return GetColorPalette(tls, pic, palette)
  42734 }
  42735 
  42736 const USE_TABLES_FOR_ALPHA_MULT = 0
  42737 
  42738 // Copyright 2010 Google Inc. All Rights Reserved.
  42739 //
  42740 // Use of this source code is governed by a BSD-style license
  42741 // that can be found in the COPYING file in the root of the source
  42742 // tree. An additional intellectual property rights grant can be found
  42743 // in the file PATENTS. All contributing project authors may
  42744 // be found in the AUTHORS file in the root of the source tree.
  42745 // -----------------------------------------------------------------------------
  42746 //
  42747 //  Common types + memory wrappers
  42748 //
  42749 // Author: Skal (pascal.massimino@gmail.com)
  42750 
  42751 // Tables can be faster on some platform but incur some extra binary size (~2k).
  42752 
  42753 // -----------------------------------------------------------------------------
  42754 
  42755 func Mult(tls *libc.TLS, x uint8_t, mult uint32_t) (r uint32_t) {
  42756 	var v uint32_t
  42757 	_ = v
  42758 	v = (uint32(x)*mult + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(24)>>libc.Int32FromInt32(1)) >> int32(24)
  42759 	// <- 24bit precision is enough to ensure that.
  42760 	return v
  42761 }
  42762 
  42763 func GetScale(tls *libc.TLS, a uint32_t, inverse int32) (r uint32_t) {
  42764 	var v1 uint32
  42765 	_ = v1
  42766 	if inverse != 0 {
  42767 		v1 = libc.Uint32FromUint32(255) << libc.Int32FromInt32(24) / a
  42768 	} else {
  42769 		v1 = a * (libc.Uint32FromUint32(1) << libc.Int32FromInt32(24) / libc.Uint32FromUint32(255))
  42770 	}
  42771 	return v1
  42772 }
  42773 
  42774 func WebPMultARGBRow_C(tls *libc.TLS, ptr uintptr, width int32, inverse int32) {
  42775 	var alpha, argb, out, scale uint32_t
  42776 	var x int32
  42777 	_, _, _, _, _ = alpha, argb, out, scale, x
  42778 	x = 0
  42779 	for {
  42780 		if !(x < width) {
  42781 			break
  42782 		}
  42783 		argb = **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))
  42784 		if argb < uint32(0xff000000) { // alpha < 255
  42785 			if argb <= uint32(0x00ffffff) { // alpha == 0
  42786 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = uint32(0)
  42787 			} else {
  42788 				alpha = argb >> libc.Int32FromInt32(24) & uint32(0xff)
  42789 				scale = GetScale(tls, alpha, inverse)
  42790 				out = argb & uint32(0xff000000)
  42791 				out = out | Mult(tls, uint8(argb>>0), scale)<<0
  42792 				out = out | Mult(tls, uint8(argb>>int32(8)), scale)<<int32(8)
  42793 				out = out | Mult(tls, uint8(argb>>int32(16)), scale)<<int32(16)
  42794 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = out
  42795 			}
  42796 		}
  42797 		goto _1
  42798 	_1:
  42799 		;
  42800 		x = x + 1
  42801 	}
  42802 }
  42803 
  42804 func WebPMultRow_C(tls *libc.TLS, ptr uintptr, alpha uintptr, width int32, inverse int32) {
  42805 	var a, scale uint32_t
  42806 	var x int32
  42807 	_, _, _ = a, scale, x
  42808 	x = 0
  42809 	for {
  42810 		if !(x < width) {
  42811 			break
  42812 		}
  42813 		a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(x))))
  42814 		if a != uint32(255) {
  42815 			if a == uint32(0) {
  42816 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(0)
  42817 			} else {
  42818 				scale = GetScale(tls, a, inverse)
  42819 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(Mult(tls, **(**uint8_t)(__ccgo_up(ptr + uintptr(x))), scale))
  42820 			}
  42821 		}
  42822 		goto _1
  42823 	_1:
  42824 		;
  42825 		x = x + 1
  42826 	}
  42827 }
  42828 
  42829 //------------------------------------------------------------------------------
  42830 // Generic per-plane calls
  42831 
  42832 func WebPMultARGBRows(tls *libc.TLS, ptr uintptr, stride int32, width int32, num_rows int32, inverse int32) {
  42833 	var n int32
  42834 	_ = n
  42835 	n = 0
  42836 	for {
  42837 		if !(n < num_rows) {
  42838 			break
  42839 		}
  42840 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, ptr, width, inverse)
  42841 		ptr = ptr + uintptr(stride)
  42842 		goto _1
  42843 	_1:
  42844 		;
  42845 		n = n + 1
  42846 	}
  42847 }
  42848 
  42849 func WebPMultRows(tls *libc.TLS, ptr uintptr, stride int32, alpha uintptr, alpha_stride int32, width int32, num_rows int32, inverse int32) {
  42850 	var n int32
  42851 	_ = n
  42852 	n = 0
  42853 	for {
  42854 		if !(n < num_rows) {
  42855 			break
  42856 		}
  42857 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultRow})))(tls, ptr, alpha, width, inverse)
  42858 		ptr = ptr + uintptr(stride)
  42859 		alpha = alpha + uintptr(alpha_stride)
  42860 		goto _1
  42861 	_1:
  42862 		;
  42863 		n = n + 1
  42864 	}
  42865 }
  42866 
  42867 //------------------------------------------------------------------------------
  42868 // Premultiplied modes
  42869 
  42870 // non dithered-modes
  42871 
  42872 // (x * a * 32897) >> 23 is bit-wise equivalent to (int)(x * a / 255.)
  42873 // for all 8bit x or a. For bit-wise equivalence to (int)(x * a / 255. + .5),
  42874 // one can use instead: (x * a * 65793 + (1 << 23)) >> 24
  42875 
  42876 func ApplyAlphaMultiply_C(tls *libc.TLS, rgba uintptr, alpha_first int32, w int32, h int32, stride int32) {
  42877 	var a, mult uint32_t
  42878 	var alpha, rgb uintptr
  42879 	var i, v1, v2, v3 int32
  42880 	_, _, _, _, _, _, _, _ = a, alpha, i, mult, rgb, v1, v2, v3
  42881 	for {
  42882 		v1 = h
  42883 		h = h - 1
  42884 		if !(v1 > 0) {
  42885 			break
  42886 		}
  42887 		if alpha_first != 0 {
  42888 			v2 = int32(1)
  42889 		} else {
  42890 			v2 = 0
  42891 		}
  42892 		rgb = rgba + uintptr(v2)
  42893 		if alpha_first != 0 {
  42894 			v3 = 0
  42895 		} else {
  42896 			v3 = int32(3)
  42897 		}
  42898 		alpha = rgba + uintptr(v3)
  42899 		i = 0
  42900 		for {
  42901 			if !(i < w) {
  42902 				break
  42903 			}
  42904 			a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(int32(4)*i))))
  42905 			if a != uint32(0xff) {
  42906 				mult = a * libc.Uint32FromUint32(32897)
  42907 				**(**uint8_t)(__ccgo_up(rgb + uintptr(int32(4)*i+0))) = uint8(uint32(**(**uint8_t)(__ccgo_up(rgb + uintptr(int32(4)*i+0)))) * mult >> libc.Int32FromInt32(23))
  42908 				**(**uint8_t)(__ccgo_up(rgb + uintptr(int32(4)*i+int32(1)))) = uint8(uint32(**(**uint8_t)(__ccgo_up(rgb + uintptr(int32(4)*i+int32(1))))) * mult >> libc.Int32FromInt32(23))
  42909 				**(**uint8_t)(__ccgo_up(rgb + uintptr(int32(4)*i+int32(2)))) = uint8(uint32(**(**uint8_t)(__ccgo_up(rgb + uintptr(int32(4)*i+int32(2))))) * mult >> libc.Int32FromInt32(23))
  42910 			}
  42911 			goto _4
  42912 		_4:
  42913 			;
  42914 			i = i + 1
  42915 		}
  42916 		rgba = rgba + uintptr(stride)
  42917 	}
  42918 }
  42919 
  42920 // rgbA4444
  42921 
  42922 func dither_hi(tls *libc.TLS, x uint8_t) (r uint8_t) {
  42923 	return libc.Uint8FromInt32(libc.Int32FromUint8(x)&int32(0xf0) | libc.Int32FromUint8(x)>>int32(4))
  42924 }
  42925 
  42926 func dither_lo(tls *libc.TLS, x uint8_t) (r uint8_t) {
  42927 	return libc.Uint8FromInt32(libc.Int32FromUint8(x)&int32(0x0f) | libc.Int32FromUint8(x)<<int32(4))
  42928 }
  42929 
  42930 func multiply(tls *libc.TLS, x uint8_t, m uint32_t) (r uint8_t) {
  42931 	return uint8(uint32(x) * m >> int32(16))
  42932 }
  42933 
  42934 func ApplyAlphaMultiply4444_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32, rg_byte_pos int32) {
  42935 	var a, b, g, r uint8_t
  42936 	var ba, mult, rg uint32_t
  42937 	var i, v1 int32
  42938 	_, _, _, _, _, _, _, _, _ = a, b, ba, g, i, mult, r, rg, v1
  42939 	for {
  42940 		v1 = h
  42941 		h = h - 1
  42942 		if !(v1 > 0) {
  42943 			break
  42944 		}
  42945 		i = 0
  42946 		for {
  42947 			if !(i < w) {
  42948 				break
  42949 			}
  42950 			rg = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))))
  42951 			ba = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))))
  42952 			a = uint8(ba & uint32(0x0f))
  42953 			mult = libc.Uint32FromInt32(libc.Int32FromUint8(a) * libc.Int32FromInt32(0x1111))
  42954 			r = multiply(tls, dither_hi(tls, uint8(rg)), mult)
  42955 			g = multiply(tls, dither_lo(tls, uint8(rg)), mult)
  42956 			b = multiply(tls, dither_hi(tls, uint8(ba)), mult)
  42957 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))) = libc.Uint8FromInt32(libc.Int32FromUint8(r)&int32(0xf0) | libc.Int32FromUint8(g)>>int32(4)&int32(0x0f))
  42958 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))) = libc.Uint8FromInt32(libc.Int32FromUint8(b)&int32(0xf0) | libc.Int32FromUint8(a))
  42959 			goto _2
  42960 		_2:
  42961 			;
  42962 			i = i + 1
  42963 		}
  42964 		rgba4444 = rgba4444 + uintptr(stride)
  42965 	}
  42966 }
  42967 
  42968 func ApplyAlphaMultiply_16b_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32) {
  42969 	ApplyAlphaMultiply4444_C(tls, rgba4444, w, h, stride, 0)
  42970 }
  42971 
  42972 func DispatchAlpha_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) (r int32) {
  42973 	var alpha_mask, alpha_value uint32_t
  42974 	var i, j int32
  42975 	_, _, _, _ = alpha_mask, alpha_value, i, j
  42976 	alpha_mask = uint32(0xff)
  42977 	j = 0
  42978 	for {
  42979 		if !(j < height) {
  42980 			break
  42981 		}
  42982 		i = 0
  42983 		for {
  42984 			if !(i < width) {
  42985 				break
  42986 			}
  42987 			alpha_value = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(i))))
  42988 			**(**uint8_t)(__ccgo_up(dst + uintptr(int32(4)*i))) = uint8(alpha_value)
  42989 			alpha_mask = alpha_mask & alpha_value
  42990 			goto _2
  42991 		_2:
  42992 			;
  42993 			i = i + 1
  42994 		}
  42995 		alpha = alpha + uintptr(alpha_stride)
  42996 		dst = dst + uintptr(dst_stride)
  42997 		goto _1
  42998 	_1:
  42999 		;
  43000 		j = j + 1
  43001 	}
  43002 	return libc.BoolInt32(alpha_mask != uint32(0xff))
  43003 }
  43004 
  43005 func DispatchAlphaToGreen_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) {
  43006 	var i, j int32
  43007 	_, _ = i, j
  43008 	j = 0
  43009 	for {
  43010 		if !(j < height) {
  43011 			break
  43012 		}
  43013 		i = 0
  43014 		for {
  43015 			if !(i < width) {
  43016 				break
  43017 			}
  43018 			**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha + uintptr(i)))) << int32(8)) // leave A/R/B channels zero'd.
  43019 			goto _2
  43020 		_2:
  43021 			;
  43022 			i = i + 1
  43023 		}
  43024 		alpha = alpha + uintptr(alpha_stride)
  43025 		dst = dst + uintptr(dst_stride)*4
  43026 		goto _1
  43027 	_1:
  43028 		;
  43029 		j = j + 1
  43030 	}
  43031 }
  43032 
  43033 func ExtractAlpha_C(tls *libc.TLS, argb uintptr, argb_stride int32, width int32, height int32, alpha uintptr, alpha_stride int32) (r int32) {
  43034 	var alpha_mask, alpha_value uint8_t
  43035 	var i, j int32
  43036 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43037 	alpha_mask = uint8(0xff)
  43038 	j = 0
  43039 	for {
  43040 		if !(j < height) {
  43041 			break
  43042 		}
  43043 		i = 0
  43044 		for {
  43045 			if !(i < width) {
  43046 				break
  43047 			}
  43048 			alpha_value = **(**uint8_t)(__ccgo_up(argb + uintptr(int32(4)*i)))
  43049 			**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = alpha_value
  43050 			alpha_mask = libc.Uint8FromInt32(int32(alpha_mask) & libc.Int32FromUint8(alpha_value))
  43051 			goto _2
  43052 		_2:
  43053 			;
  43054 			i = i + 1
  43055 		}
  43056 		argb = argb + uintptr(argb_stride)
  43057 		alpha = alpha + uintptr(alpha_stride)
  43058 		goto _1
  43059 	_1:
  43060 		;
  43061 		j = j + 1
  43062 	}
  43063 	return libc.BoolInt32(libc.Int32FromUint8(alpha_mask) == int32(0xff))
  43064 }
  43065 
  43066 func ExtractGreen_C(tls *libc.TLS, argb uintptr, alpha uintptr, size int32) {
  43067 	var i int32
  43068 	_ = i
  43069 	i = 0
  43070 	for {
  43071 		if !(i < size) {
  43072 			break
  43073 		}
  43074 		**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = uint8(**(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) >> int32(8))
  43075 		goto _1
  43076 	_1:
  43077 		;
  43078 		i = i + 1
  43079 	}
  43080 }
  43081 
  43082 //------------------------------------------------------------------------------
  43083 
  43084 func HasAlpha8b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43085 	var v1 int32
  43086 	var v2 uintptr
  43087 	_, _ = v1, v2
  43088 	for {
  43089 		v1 = length
  43090 		length = length - 1
  43091 		if !(v1 > 0) {
  43092 			break
  43093 		}
  43094 		v2 = src
  43095 		src = src + 1
  43096 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v2))) != int32(0xff) {
  43097 			return int32(1)
  43098 		}
  43099 	}
  43100 	return 0
  43101 }
  43102 
  43103 func HasAlpha32b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43104 	var x, v2 int32
  43105 	_, _ = x, v2
  43106 	x = 0
  43107 	for {
  43108 		v2 = length
  43109 		length = length - 1
  43110 		if !(v2 > 0) {
  43111 			break
  43112 		}
  43113 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + uintptr(x)))) != int32(0xff) {
  43114 			return int32(1)
  43115 		}
  43116 		goto _1
  43117 	_1:
  43118 		;
  43119 		x = x + int32(4)
  43120 	}
  43121 	return 0
  43122 }
  43123 
  43124 func AlphaReplace_C(tls *libc.TLS, src uintptr, length int32, color uint32_t) {
  43125 	var x int32
  43126 	_ = x
  43127 	x = 0
  43128 	for {
  43129 		if !(x < length) {
  43130 			break
  43131 		}
  43132 		if **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))>>libc.Int32FromInt32(24) == uint32(0) {
  43133 			**(**uint32_t)(__ccgo_up(src + uintptr(x)*4)) = color
  43134 		}
  43135 		goto _1
  43136 	_1:
  43137 		;
  43138 		x = x + 1
  43139 	}
  43140 }
  43141 
  43142 //------------------------------------------------------------------------------
  43143 // Simple channel manipulations.
  43144 
  43145 func MakeARGB321(tls *libc.TLS, a int32, r int32, g int32, b int32) (r1 uint32_t) {
  43146 	return libc.Uint32FromInt32(a)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  43147 }
  43148 
  43149 func PackRGB_C(tls *libc.TLS, r uintptr, g uintptr, b uintptr, len1 int32, step int32, out uintptr) {
  43150 	var i, offset int32
  43151 	_, _ = i, offset
  43152 	offset = 0
  43153 	i = 0
  43154 	for {
  43155 		if !(i < len1) {
  43156 			break
  43157 		}
  43158 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = MakeARGB321(tls, int32(0xff), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(r + uintptr(offset)))), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(g + uintptr(offset)))), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(b + uintptr(offset)))))
  43159 		offset = offset + step
  43160 		goto _1
  43161 	_1:
  43162 		;
  43163 		i = i + 1
  43164 	}
  43165 }
  43166 
  43167 func WebPInitAlphaProcessing(tls *libc.TLS) {
  43168 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43169 		goto _1
  43170 	}
  43171 	WebPInitAlphaProcessing_body(tls)
  43172 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43173 	goto _2
  43174 _2:
  43175 	;
  43176 	goto _1
  43177 _1: /**/ //
  43178 }
  43179 
  43180 var WebPInitAlphaProcessing_body_last_cpuinfo_used = uintptr(0)
  43181 
  43182 func init() {
  43183 	p := unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)
  43184 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))
  43185 }
  43186 
  43187 func WebPInitAlphaProcessing_body(tls *libc.TLS) {
  43188 	WebPMultARGBRow = __ccgo_fp(WebPMultARGBRow_C)
  43189 	WebPMultRow = __ccgo_fp(WebPMultRow_C)
  43190 	WebPApplyAlphaMultiply4444 = __ccgo_fp(ApplyAlphaMultiply_16b_C)
  43191 	WebPPackRGB = __ccgo_fp(PackRGB_C)
  43192 	WebPApplyAlphaMultiply = __ccgo_fp(ApplyAlphaMultiply_C)
  43193 	WebPDispatchAlpha = __ccgo_fp(DispatchAlpha_C)
  43194 	WebPDispatchAlphaToGreen = __ccgo_fp(DispatchAlphaToGreen_C)
  43195 	WebPExtractAlpha = __ccgo_fp(ExtractAlpha_C)
  43196 	WebPExtractGreen = __ccgo_fp(ExtractGreen_C)
  43197 	WebPHasAlpha8b = __ccgo_fp(HasAlpha8b_C)
  43198 	WebPHasAlpha32b = __ccgo_fp(HasAlpha32b_C)
  43199 	WebPAlphaReplace = __ccgo_fp(AlphaReplace_C)
  43200 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43201 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43202 	}
  43203 }
  43204 
  43205 func WebPInitAlphaProcessingMIPSdspR2(tls *libc.TLS) {
  43206 }
  43207 
  43208 func WebPInitAlphaProcessingNEON(tls *libc.TLS) {
  43209 }
  43210 
  43211 func WebPInitAlphaProcessingSSE2(tls *libc.TLS) {
  43212 }
  43213 
  43214 func WebPInitAlphaProcessingSSE41(tls *libc.TLS) {
  43215 }
  43216 
  43217 //------------------------------------------------------------------------------
  43218 // Mode costs
  43219 
  43220 func GetResidualCost_C(tls *libc.TLS, ctx0 int32, res uintptr) (r int32) {
  43221 	var b, cost, ctx, ctx1, last_p0, n, p0, v, v1, v11, v3, v5, v7, v9 int32
  43222 	var costs CostArrayPtr
  43223 	var t uintptr
  43224 	var v2, v6 uint8_t
  43225 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, cost, costs, ctx, ctx1, last_p0, n, p0, t, v, v1, v11, v2, v3, v5, v6, v7, v9
  43226 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  43227 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  43228 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx0)*11)))
  43229 	costs = (*VP8Residual)(unsafe.Pointer(res)).Fcosts
  43230 	t = **(**uintptr)(__ccgo_up(costs + uintptr(n)*24 + uintptr(ctx0)*8))
  43231 	if ctx0 == 0 {
  43232 		v2 = libc.Uint8FromInt32(p0)
  43233 		if !(int32(1) != 0) {
  43234 			v5 = libc.Int32FromUint16(VP8EntropyCost[v2])
  43235 		} else {
  43236 			v5 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v2)])
  43237 		}
  43238 		v3 = v5
  43239 		goto _4
  43240 	_4:
  43241 		v11 = v3
  43242 	} else {
  43243 		v11 = 0
  43244 	}
  43245 	// bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
  43246 	// (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
  43247 	// be missing during the loop.
  43248 	cost = v11
  43249 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  43250 		v6 = libc.Uint8FromInt32(p0)
  43251 		if !(0 != 0) {
  43252 			v9 = libc.Int32FromUint16(VP8EntropyCost[v6])
  43253 		} else {
  43254 			v9 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v6)])
  43255 		}
  43256 		v7 = v9
  43257 		goto _8
  43258 	_8:
  43259 		return v7
  43260 	}
  43261 	for {
  43262 		if !(n < (*VP8Residual)(unsafe.Pointer(res)).Flast) {
  43263 			break
  43264 		}
  43265 		v = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43266 		if v >= int32(2) {
  43267 			v11 = int32(2)
  43268 		} else {
  43269 			v11 = v
  43270 		}
  43271 		ctx = v11
  43272 		v3 = v
  43273 		if v3 > int32(MAX_VARIABLE_LEVEL) {
  43274 			v7 = int32(MAX_VARIABLE_LEVEL)
  43275 		} else {
  43276 			v7 = v3
  43277 		}
  43278 		v5 = libc.Int32FromUint16(VP8LevelFixedCosts[v3]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(t + uintptr(v7)*2)))
  43279 		goto _14
  43280 	_14:
  43281 		cost = cost + v5
  43282 		t = **(**uintptr)(__ccgo_up(costs + uintptr(n+int32(1))*24 + uintptr(ctx)*8))
  43283 		goto _10
  43284 	_10:
  43285 		;
  43286 		n = n + 1
  43287 	}
  43288 	// Last coefficient is always non-zero
  43289 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43290 	v11 = v1
  43291 	if v11 > int32(MAX_VARIABLE_LEVEL) {
  43292 		v5 = int32(MAX_VARIABLE_LEVEL)
  43293 	} else {
  43294 		v5 = v11
  43295 	}
  43296 	v3 = libc.Int32FromUint16(VP8LevelFixedCosts[v11]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(t + uintptr(v5)*2)))
  43297 	goto _18
  43298 _18:
  43299 	cost = cost + v3
  43300 	if n < int32(15) {
  43301 		b = libc.Int32FromUint8(VP8EncBands[n+int32(1)])
  43302 		if v1 == int32(1) {
  43303 			v11 = int32(1)
  43304 		} else {
  43305 			v11 = int32(2)
  43306 		}
  43307 		ctx1 = v11
  43308 		last_p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(b)*33 + uintptr(ctx1)*11)))
  43309 		v2 = libc.Uint8FromInt32(last_p0)
  43310 		if !(0 != 0) {
  43311 			v5 = libc.Int32FromUint16(VP8EntropyCost[v2])
  43312 		} else {
  43313 			v5 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v2)])
  43314 		}
  43315 		v3 = v5
  43316 		goto _23
  43317 	_23:
  43318 		cost = cost + v3
  43319 	}
  43320 	return cost
  43321 }
  43322 
  43323 func SetResidualCoeffs_C(tls *libc.TLS, coeffs uintptr, res uintptr) {
  43324 	var n int32
  43325 	_ = n
  43326 	(*VP8Residual)(unsafe.Pointer(res)).Flast = -int32(1)
  43327 	n = int32(15)
  43328 	for {
  43329 		if !(n >= 0) {
  43330 			break
  43331 		}
  43332 		if **(**int16_t)(__ccgo_up(coeffs + uintptr(n)*2)) != 0 {
  43333 			(*VP8Residual)(unsafe.Pointer(res)).Flast = n
  43334 			break
  43335 		}
  43336 		goto _1
  43337 	_1:
  43338 		;
  43339 		n = n - 1
  43340 	}
  43341 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeffs = coeffs
  43342 }
  43343 
  43344 func VP8EncDspCostInit(tls *libc.TLS) {
  43345 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43346 		goto _1
  43347 	}
  43348 	VP8EncDspCostInit_body(tls)
  43349 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43350 	goto _2
  43351 _2:
  43352 	;
  43353 	goto _1
  43354 _1: /**/ //
  43355 }
  43356 
  43357 var VP8EncDspCostInit_body_last_cpuinfo_used = uintptr(0)
  43358 
  43359 func init() {
  43360 	p := unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)
  43361 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))
  43362 }
  43363 
  43364 func VP8EncDspCostInit_body(tls *libc.TLS) {
  43365 	VP8GetResidualCost = __ccgo_fp(GetResidualCost_C)
  43366 	VP8SetResidualCoeffs = __ccgo_fp(SetResidualCoeffs_C)
  43367 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43368 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43369 	}
  43370 }
  43371 
  43372 func VP8EncDspCostInitMIPS32(tls *libc.TLS) {
  43373 }
  43374 
  43375 func VP8EncDspCostInitMIPSdspR2(tls *libc.TLS) {
  43376 }
  43377 
  43378 func VP8EncDspCostInitNEON(tls *libc.TLS) {
  43379 }
  43380 
  43381 func VP8EncDspCostInitSSE2(tls *libc.TLS) {
  43382 }
  43383 
  43384 // Copyright 2010 Google Inc. All Rights Reserved.
  43385 //
  43386 // Use of this source code is governed by a BSD-style license
  43387 // that can be found in the COPYING file in the root of the source
  43388 // tree. An additional intellectual property rights grant can be found
  43389 // in the file PATENTS. All contributing project authors may
  43390 // be found in the AUTHORS file in the root of the source tree.
  43391 // -----------------------------------------------------------------------------
  43392 //
  43393 //  Common types + memory wrappers
  43394 //
  43395 // Author: Skal (pascal.massimino@gmail.com)
  43396 
  43397 //------------------------------------------------------------------------------
  43398 // SSE2 detection.
  43399 //
  43400 
  43401 // C documentation
  43402 //
  43403 //	// apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC.
  43404 func GetCPUInfo(tls *libc.TLS, cpu_info uintptr, info_type int32) {
  43405 	//   __asm__ volatile (
  43406 	//     "cpuid\n"
  43407 	//     : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
  43408 	//     : "a"(info_type), "c"(0));
  43409 	libc.X__assert_fail(tls, __ccgo_ts+594, __ccgo_ts+629, 45, __ccgo_ts+635)
  43410 }
  43411 
  43412 // C documentation
  43413 //
  43414 //	// NaCl has no support for xgetbv or the raw opcode.
  43415 func xgetbv(tls *libc.TLS) (r uint64_t) {
  43416 	var eax, ecx, edx uint32_t
  43417 	_, _, _ = eax, ecx, edx
  43418 	ecx = uint32(0)
  43419 	// Use the raw opcode for xgetbv for compatibility with older toolchains.
  43420 	//   // Use the raw opcode for xgetbv for compatibility with older toolchains.
  43421 	//   __asm__ volatile (
  43422 	//     ".byte 0x0f, 0x01, 0xd0\n"
  43423 	//     : "=a"(eax), "=d"(edx) : "c" (ecx));
  43424 	libc.X__assert_fail(tls, __ccgo_ts+594, __ccgo_ts+629, 70, __ccgo_ts+646)
  43425 	return uint64(edx)<<libc.Int32FromInt32(32) | uint64(eax)
  43426 }
  43427 
  43428 // C documentation
  43429 //
  43430 //	// helper function for run-time detection of slow SSSE3 platforms
  43431 func CheckSlowModel(tls *libc.TLS, info int32) (r int32) {
  43432 	var family, model uint32_t
  43433 	var i size_t
  43434 	_, _, _ = family, i, model
  43435 	model = libc.Uint32FromInt32(info&int32(0xf0000)>>int32(12) | info>>int32(4)&int32(0xf))
  43436 	family = libc.Uint32FromInt32(info >> int32(8) & int32(0xf))
  43437 	if family == uint32(0x06) {
  43438 		i = uint64(0)
  43439 		for {
  43440 			if !(i < libc.Uint64FromInt64(6)/libc.Uint64FromInt64(1)) {
  43441 				break
  43442 			}
  43443 			if model == uint32(kSlowModels[i]) {
  43444 				return int32(1)
  43445 			}
  43446 			goto _1
  43447 		_1:
  43448 			;
  43449 			i = i + 1
  43450 		}
  43451 	}
  43452 	return 0
  43453 }
  43454 
  43455 // Table listing display models with longer latencies for the bsr instruction
  43456 // (ie 2 cycles vs 10/16 cycles) and some SSSE3 instructions like pshufb.
  43457 // Refer to Intel 64 and IA-32 Architectures Optimization Reference Manual.
  43458 var kSlowModels = [6]uint8_t{
  43459 	0: uint8(0x37),
  43460 	1: uint8(0x4a),
  43461 	2: uint8(0x4d),
  43462 	3: uint8(0x1c),
  43463 	4: uint8(0x26),
  43464 	5: uint8(0x27),
  43465 }
  43466 
  43467 func x86CPUInfo(tls *libc.TLS, feature CPUFeature) (r int32) {
  43468 	bp := tls.Alloc(16)
  43469 	defer tls.Free(16)
  43470 	var VENDOR_ID_INTEL_EBX, VENDOR_ID_INTEL_ECX, VENDOR_ID_INTEL_EDX, is_intel, max_cpuid_value int32
  43471 	var _ /* cpu_info at bp+0 */ [4]int32
  43472 	_, _, _, _, _ = VENDOR_ID_INTEL_EBX, VENDOR_ID_INTEL_ECX, VENDOR_ID_INTEL_EDX, is_intel, max_cpuid_value
  43473 	is_intel = 0
  43474 	// get the highest feature value cpuid supports
  43475 	GetCPUInfo(tls, bp, 0)
  43476 	max_cpuid_value = (**(**[4]int32)(__ccgo_up(bp)))[0]
  43477 	if max_cpuid_value < int32(1) {
  43478 		return 0
  43479 	} else {
  43480 		VENDOR_ID_INTEL_EBX = int32(0x756e6547)                                                                                                                                                                                             // uneG
  43481 		VENDOR_ID_INTEL_EDX = int32(0x49656e69)                                                                                                                                                                                             // Ieni
  43482 		VENDOR_ID_INTEL_ECX = int32(0x6c65746e)                                                                                                                                                                                             // letn
  43483 		is_intel = libc.BoolInt32((**(**[4]int32)(__ccgo_up(bp)))[int32(1)] == VENDOR_ID_INTEL_EBX && (**(**[4]int32)(__ccgo_up(bp)))[int32(2)] == VENDOR_ID_INTEL_ECX && (**(**[4]int32)(__ccgo_up(bp)))[int32(3)] == VENDOR_ID_INTEL_EDX) // genuine Intel?
  43484 	}
  43485 	GetCPUInfo(tls, bp, int32(1))
  43486 	if feature == int32(kSSE2) {
  43487 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(3)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(26)) != 0))
  43488 	}
  43489 	if feature == int32(kSSE3) {
  43490 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(0)) != 0))
  43491 	}
  43492 	if feature == int32(kSlowSSSE3) {
  43493 		if is_intel != 0 && (**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(9)) != 0 { // SSSE3?
  43494 			return CheckSlowModel(tls, (**(**[4]int32)(__ccgo_up(bp)))[0])
  43495 		}
  43496 		return 0
  43497 	}
  43498 	if feature == int32(kSSE4_1) {
  43499 		return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  43500 	}
  43501 	if feature == int32(kAVX) {
  43502 		// bits 27 (OSXSAVE) & 28 (256-bit AVX)
  43503 		if (**(**[4]int32)(__ccgo_up(bp)))[int32(2)]&int32(0x18000000) == int32(0x18000000) {
  43504 			// XMM state and YMM state enabled by the OS.
  43505 			return libc.BoolInt32(xgetbv(tls)&uint64(0x6) == uint64(0x6))
  43506 		}
  43507 	}
  43508 	if feature == int32(kAVX2) {
  43509 		if x86CPUInfo(tls, int32(kAVX)) != 0 && max_cpuid_value >= int32(7) {
  43510 			GetCPUInfo(tls, bp, int32(7))
  43511 			return libc.BoolInt32(!!((**(**[4]int32)(__ccgo_up(bp)))[int32(1)]&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(5)) != 0))
  43512 		}
  43513 	}
  43514 	return 0
  43515 }
  43516 
  43517 func init() {
  43518 	p := unsafe.Pointer(&VP8GetCPUInfo)
  43519 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(x86CPUInfo)
  43520 }
  43521 
  43522 var kHashMul14 = uint32(0x1e35a7bd)
  43523 
  43524 //------------------------------------------------------------------------------
  43525 
  43526 // Copyright 2010 Google Inc. All Rights Reserved.
  43527 //
  43528 // Use of this source code is governed by a BSD-style license
  43529 // that can be found in the COPYING file in the root of the source
  43530 // tree. An additional intellectual property rights grant can be found
  43531 // in the file PATENTS. All contributing project authors may
  43532 // be found in the AUTHORS file in the root of the source tree.
  43533 // -----------------------------------------------------------------------------
  43534 //
  43535 //  Common types + memory wrappers
  43536 //
  43537 // Author: Skal (pascal.massimino@gmail.com)
  43538 
  43539 //------------------------------------------------------------------------------
  43540 
  43541 func clip_8b1(tls *libc.TLS, v int32) (r uint8_t) {
  43542 	var v1, v2 int32
  43543 	_, _ = v1, v2
  43544 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  43545 		v1 = v
  43546 	} else {
  43547 		if v < 0 {
  43548 			v2 = 0
  43549 		} else {
  43550 			v2 = int32(255)
  43551 		}
  43552 		v1 = v2
  43553 	}
  43554 	return libc.Uint8FromInt32(v1)
  43555 }
  43556 
  43557 //------------------------------------------------------------------------------
  43558 // Transforms (Paragraph 14.4)
  43559 
  43560 func TransformOne_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43561 	bp := tls.Alloc(64)
  43562 	defer tls.Free(64)
  43563 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  43564 	var tmp uintptr
  43565 	var _ /* C at bp+0 */ [16]int32
  43566 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  43567 	tmp = bp
  43568 	i = 0
  43569 	for {
  43570 		if !(i < int32(4)) {
  43571 			break
  43572 		} // vertical pass
  43573 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4096, 4094]
  43574 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4095, 4095]
  43575 		c = int32(**(**int16_t)(__ccgo_up(in + 4*2)))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16) - (int32(**(**int16_t)(__ccgo_up(in + 12*2)))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + int32(**(**int16_t)(__ccgo_up(in + 12*2)))) // [-3783, 3783]
  43576 		d = int32(**(**int16_t)(__ccgo_up(in + 4*2)))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + int32(**(**int16_t)(__ccgo_up(in + 4*2))) + int32(**(**int16_t)(__ccgo_up(in + 12*2)))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16)    // [-3785, 3781]
  43577 		**(**int32)(__ccgo_up(tmp)) = a + d                                                                                                                                                                                       // [-7881, 7875]
  43578 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c                                                                                                                                                                                 // [-7878, 7878]
  43579 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c                                                                                                                                                                                 // [-7878, 7878]
  43580 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d                                                                                                                                                                                 // [-7877, 7879]
  43581 		tmp = tmp + uintptr(4)*4
  43582 		in += 2
  43583 		goto _1
  43584 	_1:
  43585 		;
  43586 		i = i + 1
  43587 	}
  43588 	// Each pass is expanding the dynamic range by ~3.85 (upper bound).
  43589 	// The exact value is (2. + (20091 + 35468) / 65536).
  43590 	// After the second pass, maximum interval is [-3794, 3794], assuming
  43591 	// an input in [-2048, 2047] interval. We then need to add a dst value
  43592 	// in the [0, 255] range.
  43593 	// In the worst case scenario, the input to clip_8b() can be as large as
  43594 	// [-60713, 60968].
  43595 	tmp = bp
  43596 	i = 0
  43597 	for {
  43598 		if !(i < int32(4)) {
  43599 			break
  43600 		} // horizontal pass
  43601 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  43602 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  43603 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  43604 		c1 = **(**int32)(__ccgo_up(tmp + 4*4))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16) - (**(**int32)(__ccgo_up(tmp + 12*4))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + **(**int32)(__ccgo_up(tmp + 12*4)))
  43605 		d1 = **(**int32)(__ccgo_up(tmp + 4*4))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + **(**int32)(__ccgo_up(tmp + 4*4)) + **(**int32)(__ccgo_up(tmp + 12*4))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16)
  43606 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(a1+d1)>>int32(3))
  43607 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(b1+c1)>>int32(3))
  43608 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(b1-c1)>>int32(3))
  43609 		**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(a1-d1)>>int32(3))
  43610 		tmp += 4
  43611 		dst = dst + uintptr(BPS)
  43612 		goto _2
  43613 	_2:
  43614 		;
  43615 		i = i + 1
  43616 	}
  43617 }
  43618 
  43619 // C documentation
  43620 //
  43621 //	// Simplified transform when only in[0], in[1] and in[4] are non-zero
  43622 func TransformAC3_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43623 	var DC, DC1, DC2, DC3, a, c1, c4, d1, d4 int32
  43624 	_, _, _, _, _, _, _, _, _ = DC, DC1, DC2, DC3, a, c1, c4, d1, d4
  43625 	a = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  43626 	c4 = int32(**(**int16_t)(__ccgo_up(in + 4*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43627 	d4 = int32(**(**int16_t)(__ccgo_up(in + 4*2)))*libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C1)>>libc.Int32FromInt32(16) + int32(**(**int16_t)(__ccgo_up(in + 4*2)))
  43628 	c1 = int32(**(**int16_t)(__ccgo_up(in + 1*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43629 	d1 = int32(**(**int16_t)(__ccgo_up(in + 1*2)))*libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C1)>>libc.Int32FromInt32(16) + int32(**(**int16_t)(__ccgo_up(in + 1*2)))
  43630 	DC = a + d4
  43631 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC+d1)>>int32(3))
  43632 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC+c1)>>int32(3))
  43633 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC-c1)>>int32(3))
  43634 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))+(DC-d1)>>int32(3))
  43635 	DC1 = a + c4
  43636 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1+d1)>>int32(3))
  43637 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1+c1)>>int32(3))
  43638 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1-c1)>>int32(3))
  43639 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))+(DC1-d1)>>int32(3))
  43640 	DC2 = a - c4
  43641 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2+d1)>>int32(3))
  43642 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2+c1)>>int32(3))
  43643 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2-c1)>>int32(3))
  43644 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))+(DC2-d1)>>int32(3))
  43645 	DC3 = a - d4
  43646 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3+d1)>>int32(3))
  43647 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3+c1)>>int32(3))
  43648 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3-c1)>>int32(3))
  43649 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))+(DC3-d1)>>int32(3))
  43650 }
  43651 
  43652 func TransformTwo_C(tls *libc.TLS, in uintptr, dst uintptr, do_two int32) {
  43653 	TransformOne_C(tls, in, dst)
  43654 	if do_two != 0 {
  43655 		TransformOne_C(tls, in+uintptr(16)*2, dst+uintptr(4))
  43656 	}
  43657 }
  43658 
  43659 func TransformUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43660 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst, int32(1))
  43661 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, in+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2, dst+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)), int32(1))
  43662 }
  43663 
  43664 func TransformDC_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43665 	var DC, i, j int32
  43666 	_, _, _ = DC, i, j
  43667 	DC = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  43668 	j = 0
  43669 	for {
  43670 		if !(j < int32(4)) {
  43671 			break
  43672 		}
  43673 		i = 0
  43674 		for {
  43675 			if !(i < int32(4)) {
  43676 				break
  43677 			}
  43678 			**(**uint8_t)(__ccgo_up(dst + uintptr(i+j*int32(BPS)))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i+j*int32(BPS)))))+DC>>libc.Int32FromInt32(3))
  43679 			goto _2
  43680 		_2:
  43681 			;
  43682 			i = i + 1
  43683 		}
  43684 		goto _1
  43685 	_1:
  43686 		;
  43687 		j = j + 1
  43688 	}
  43689 }
  43690 
  43691 func TransformDCUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43692 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2)) != 0 {
  43693 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst)
  43694 	}
  43695 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2)) != 0 {
  43696 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2, dst+uintptr(4))
  43697 	}
  43698 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2)) != 0 {
  43699 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2, dst+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)))
  43700 	}
  43701 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2)) != 0 {
  43702 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2, dst+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS))+uintptr(4))
  43703 	}
  43704 }
  43705 
  43706 //------------------------------------------------------------------------------
  43707 // Paragraph 14.3
  43708 
  43709 func TransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  43710 	var a0, a01, a1, a11, a2, a21, a3, a31, dc, i int32
  43711 	var tmp [16]int32
  43712 	_, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, dc, i, tmp
  43713 	i = 0
  43714 	for {
  43715 		if !(i < int32(4)) {
  43716 			break
  43717 		}
  43718 		a0 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  43719 		a1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  43720 		a2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  43721 		a3 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  43722 		tmp[0+i] = a0 + a1
  43723 		tmp[int32(8)+i] = a0 - a1
  43724 		tmp[int32(4)+i] = a3 + a2
  43725 		tmp[int32(12)+i] = a3 - a2
  43726 		goto _1
  43727 	_1:
  43728 		;
  43729 		i = i + 1
  43730 	}
  43731 	i = 0
  43732 	for {
  43733 		if !(i < int32(4)) {
  43734 			break
  43735 		}
  43736 		dc = tmp[0+i*int32(4)] + int32(3) // w/ rounder
  43737 		a01 = dc + tmp[int32(3)+i*int32(4)]
  43738 		a11 = tmp[int32(1)+i*int32(4)] + tmp[int32(2)+i*int32(4)]
  43739 		a21 = tmp[int32(1)+i*int32(4)] - tmp[int32(2)+i*int32(4)]
  43740 		a31 = dc - tmp[int32(3)+i*int32(4)]
  43741 		**(**int16_t)(__ccgo_up(out)) = int16((a01 + a11) >> int32(3))
  43742 		**(**int16_t)(__ccgo_up(out + 16*2)) = int16((a31 + a21) >> int32(3))
  43743 		**(**int16_t)(__ccgo_up(out + 32*2)) = int16((a01 - a11) >> int32(3))
  43744 		**(**int16_t)(__ccgo_up(out + 48*2)) = int16((a31 - a21) >> int32(3))
  43745 		out = out + uintptr(64)*2
  43746 		goto _2
  43747 	_2:
  43748 		;
  43749 		i = i + 1
  43750 	}
  43751 }
  43752 
  43753 //------------------------------------------------------------------------------
  43754 // Intra predictions
  43755 
  43756 func TrueMotion(tls *libc.TLS, dst uintptr, size int32) {
  43757 	var clip, clip0, top uintptr
  43758 	var x, y int32
  43759 	_, _, _, _, _ = clip, clip0, top, x, y
  43760 	top = dst - uintptr(BPS)
  43761 	clip0 = VP8kclip1 - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  43762 	y = 0
  43763 	for {
  43764 		if !(y < size) {
  43765 			break
  43766 		}
  43767 		clip = clip0 + uintptr(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  43768 		x = 0
  43769 		for {
  43770 			if !(x < size) {
  43771 				break
  43772 			}
  43773 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  43774 			goto _2
  43775 		_2:
  43776 			;
  43777 			x = x + 1
  43778 		}
  43779 		dst = dst + uintptr(BPS)
  43780 		goto _1
  43781 	_1:
  43782 		;
  43783 		y = y + 1
  43784 	}
  43785 }
  43786 
  43787 func TM4_C(tls *libc.TLS, dst uintptr) {
  43788 	TrueMotion(tls, dst, int32(4))
  43789 }
  43790 
  43791 func TM8uv_C(tls *libc.TLS, dst uintptr) {
  43792 	TrueMotion(tls, dst, int32(8))
  43793 }
  43794 
  43795 func TM16_C(tls *libc.TLS, dst uintptr) {
  43796 	TrueMotion(tls, dst, int32(16))
  43797 }
  43798 
  43799 //------------------------------------------------------------------------------
  43800 // 16x16
  43801 
  43802 func VE16_C(tls *libc.TLS, dst uintptr) {
  43803 	var j int32
  43804 	_ = j
  43805 	j = 0
  43806 	for {
  43807 		if !(j < int32(16)) {
  43808 			break
  43809 		}
  43810 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(16))
  43811 		goto _1
  43812 	_1:
  43813 		;
  43814 		j = j + 1
  43815 	}
  43816 }
  43817 
  43818 func HE16_C(tls *libc.TLS, dst uintptr) {
  43819 	var j int32
  43820 	_ = j
  43821 	j = int32(16)
  43822 	for {
  43823 		if !(j > 0) {
  43824 			break
  43825 		}
  43826 		libc.Xmemset(tls, dst, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(16))
  43827 		dst = dst + uintptr(BPS)
  43828 		goto _1
  43829 	_1:
  43830 		;
  43831 		j = j - 1
  43832 	}
  43833 }
  43834 
  43835 func Put16(tls *libc.TLS, v int32, dst uintptr) {
  43836 	var j int32
  43837 	_ = j
  43838 	j = 0
  43839 	for {
  43840 		if !(j < int32(16)) {
  43841 			break
  43842 		}
  43843 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), v, uint64(16))
  43844 		goto _1
  43845 	_1:
  43846 		;
  43847 		j = j + 1
  43848 	}
  43849 }
  43850 
  43851 func DC16_C(tls *libc.TLS, dst uintptr) {
  43852 	var DC, j int32
  43853 	_, _ = DC, j // DC
  43854 	DC = int32(16)
  43855 	j = 0
  43856 	for {
  43857 		if !(j < int32(16)) {
  43858 			break
  43859 		}
  43860 		DC = DC + (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS))))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(j-int32(BPS))))))
  43861 		goto _1
  43862 	_1:
  43863 		;
  43864 		j = j + 1
  43865 	}
  43866 	Put16(tls, DC>>int32(5), dst)
  43867 }
  43868 
  43869 func DC16NoTop_C(tls *libc.TLS, dst uintptr) {
  43870 	var DC, j int32
  43871 	_, _ = DC, j // DC with top samples not available
  43872 	DC = int32(8)
  43873 	j = 0
  43874 	for {
  43875 		if !(j < int32(16)) {
  43876 			break
  43877 		}
  43878 		DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS)))))
  43879 		goto _1
  43880 	_1:
  43881 		;
  43882 		j = j + 1
  43883 	}
  43884 	Put16(tls, DC>>int32(4), dst)
  43885 }
  43886 
  43887 func DC16NoLeft_C(tls *libc.TLS, dst uintptr) {
  43888 	var DC, i int32
  43889 	_, _ = DC, i // DC with left samples not available
  43890 	DC = int32(8)
  43891 	i = 0
  43892 	for {
  43893 		if !(i < int32(16)) {
  43894 			break
  43895 		}
  43896 		DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  43897 		goto _1
  43898 	_1:
  43899 		;
  43900 		i = i + 1
  43901 	}
  43902 	Put16(tls, DC>>int32(4), dst)
  43903 }
  43904 
  43905 func DC16NoTopLeft_C(tls *libc.TLS, dst uintptr) {
  43906 	// DC with no top and left samples
  43907 	Put16(tls, int32(0x80), dst)
  43908 }
  43909 
  43910 //------------------------------------------------------------------------------
  43911 // 4x4
  43912 
  43913 func VE4_C(tls *libc.TLS, dst uintptr) {
  43914 	bp := tls.Alloc(16)
  43915 	defer tls.Free(16)
  43916 	var i int32
  43917 	var top uintptr
  43918 	var _ /* vals at bp+0 */ [4]uint8_t
  43919 	_, _ = i, top // vertical
  43920 	top = dst - uintptr(BPS)
  43921 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  43922 		0: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  43923 		1: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  43924 		2: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  43925 		3: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 4))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  43926 	}
  43927 	i = 0
  43928 	for {
  43929 		if !(i < int32(4)) {
  43930 			break
  43931 		}
  43932 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  43933 		goto _1
  43934 	_1:
  43935 		;
  43936 		i = i + 1
  43937 	}
  43938 }
  43939 
  43940 func HE4_C(tls *libc.TLS, dst uintptr) {
  43941 	bp := tls.Alloc(16)
  43942 	defer tls.Free(16)
  43943 	var A, B, C, D, E int32
  43944 	var v1 uint32_t
  43945 	_, _, _, _, _, _ = A, B, C, D, E, v1 // horizontal
  43946 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  43947 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  43948 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(BPS)))))
  43949 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  43950 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  43951 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((A+libc.Int32FromInt32(2)*B+C+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  43952 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  43953 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  43954 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((B+libc.Int32FromInt32(2)*C+D+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  43955 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  43956 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  43957 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((C+libc.Int32FromInt32(2)*D+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  43958 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  43959 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  43960 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((D+libc.Int32FromInt32(2)*E+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  43961 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  43962 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  43963 }
  43964 
  43965 func DC4_C(tls *libc.TLS, dst uintptr) {
  43966 	var dc uint32_t
  43967 	var i int32
  43968 	_, _ = dc, i // DC
  43969 	dc = uint32(4)
  43970 	i = 0
  43971 	for {
  43972 		if !(i < int32(4)) {
  43973 			break
  43974 		}
  43975 		dc = dc + libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS))))))
  43976 		goto _1
  43977 	_1:
  43978 		;
  43979 		i = i + 1
  43980 	}
  43981 	dc = dc >> uint32(3)
  43982 	i = 0
  43983 	for {
  43984 		if !(i < int32(4)) {
  43985 			break
  43986 		}
  43987 		libc.Xmemset(tls, dst+uintptr(i*int32(BPS)), libc.Int32FromUint32(dc), uint64(4))
  43988 		goto _2
  43989 	_2:
  43990 		;
  43991 		i = i + 1
  43992 	}
  43993 }
  43994 
  43995 func RD4_C(tls *libc.TLS, dst uintptr) {
  43996 	var A, B, C, D, I, J, K, L, X int32
  43997 	var v1, v2, v3 uint8_t
  43998 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3 // Down-right
  43999 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44000 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44001 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44002 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44003 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44004 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44005 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44006 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44007 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44008 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44009 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44010 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44011 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44012 	v2 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44013 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44014 	v1 = v2
  44015 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44016 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44017 	v3 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44018 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v3
  44019 	v2 = v3
  44020 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44021 	v1 = v2
  44022 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44023 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44024 	v2 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44025 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v2
  44026 	v1 = v2
  44027 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44028 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44029 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44030 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44031 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44032 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*C + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44033 }
  44034 
  44035 func LD4_C(tls *libc.TLS, dst uintptr) {
  44036 	var A, B, C, D, E, F, G, H int32
  44037 	var v1, v2, v3 uint8_t
  44038 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3 // Down-Left
  44039 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44040 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44041 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44042 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44043 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44044 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44045 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44046 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44047 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44048 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44049 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44050 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44051 	v2 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44052 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44053 	v1 = v2
  44054 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44055 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44056 	v3 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44057 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44058 	v2 = v3
  44059 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44060 	v1 = v2
  44061 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44062 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44063 	v2 = libc.Uint8FromInt32((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44064 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44065 	v1 = v2
  44066 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44067 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44068 	v1 = libc.Uint8FromInt32((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44069 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44070 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44071 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((G + libc.Int32FromInt32(2)*H + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44072 }
  44073 
  44074 func VR4_C(tls *libc.TLS, dst uintptr) {
  44075 	var A, B, C, D, I, J, K, X int32
  44076 	var v1 uint8_t
  44077 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1 // Vertical-Right
  44078 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44079 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44080 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44081 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44082 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44083 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44084 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44085 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44086 	v1 = libc.Uint8FromInt32((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44087 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44088 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44089 	v1 = libc.Uint8FromInt32((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44090 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44091 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44092 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44093 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44094 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44095 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44096 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44097 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44098 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44099 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44100 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44101 	v1 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44102 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44103 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44104 	v1 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44105 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44106 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44107 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44108 }
  44109 
  44110 func VL4_C(tls *libc.TLS, dst uintptr) {
  44111 	var A, B, C, D, E, F, G, H int32
  44112 	var v1 uint8_t
  44113 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1 // Vertical-Left
  44114 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44115 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44116 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44117 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44118 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44119 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44120 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44121 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44122 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44123 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44124 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44125 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44126 	v1 = libc.Uint8FromInt32((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44127 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44128 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44129 	v1 = libc.Uint8FromInt32((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44130 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44131 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44132 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44133 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44134 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44135 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44136 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44137 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44138 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44139 	v1 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44140 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44141 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44142 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44143 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44144 }
  44145 
  44146 func HU4_C(tls *libc.TLS, dst uintptr) {
  44147 	var I, J, K, L int32
  44148 	var v1, v2, v3, v4, v5 uint8_t
  44149 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5 // Horizontal-Up
  44150 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44151 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44152 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44153 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44154 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((I + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44155 	v1 = libc.Uint8FromInt32((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44156 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44157 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44158 	v1 = libc.Uint8FromInt32((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44159 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44160 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44161 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44162 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44163 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44164 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44165 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44166 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44167 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44168 	v5 = libc.Uint8FromInt32(L)
  44169 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  44170 	v4 = v5
  44171 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  44172 	v3 = v4
  44173 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44174 	v2 = v3
  44175 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44176 	v1 = v2
  44177 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44178 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44179 }
  44180 
  44181 func HD4_C(tls *libc.TLS, dst uintptr) {
  44182 	var A, B, C, I, J, K, L, X int32
  44183 	var v1 uint8_t
  44184 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1 // Horizontal-Down
  44185 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44186 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44187 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44188 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44189 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44190 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44191 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44192 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44193 	v1 = libc.Uint8FromInt32((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44194 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44195 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44196 	v1 = libc.Uint8FromInt32((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44197 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44198 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44199 	v1 = libc.Uint8FromInt32((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44200 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44201 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44202 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((L + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44203 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44204 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44205 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44206 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44207 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44208 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44209 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44210 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44211 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44212 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44213 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44214 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((L + libc.Int32FromInt32(2)*K + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44215 }
  44216 
  44217 //------------------------------------------------------------------------------
  44218 // Chroma
  44219 
  44220 func VE8uv_C(tls *libc.TLS, dst uintptr) {
  44221 	var j int32
  44222 	_ = j
  44223 	j = 0
  44224 	for {
  44225 		if !(j < int32(8)) {
  44226 			break
  44227 		}
  44228 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(8))
  44229 		goto _1
  44230 	_1:
  44231 		;
  44232 		j = j + 1
  44233 	}
  44234 }
  44235 
  44236 func HE8uv_C(tls *libc.TLS, dst uintptr) {
  44237 	var j int32
  44238 	_ = j
  44239 	j = 0
  44240 	for {
  44241 		if !(j < int32(8)) {
  44242 			break
  44243 		}
  44244 		libc.Xmemset(tls, dst, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(8))
  44245 		dst = dst + uintptr(BPS)
  44246 		goto _1
  44247 	_1:
  44248 		;
  44249 		j = j + 1
  44250 	}
  44251 }
  44252 
  44253 // C documentation
  44254 //
  44255 //	// helper for chroma-DC predictions
  44256 func Put8x8uv(tls *libc.TLS, value uint8_t, dst uintptr) {
  44257 	var j int32
  44258 	_ = j
  44259 	j = 0
  44260 	for {
  44261 		if !(j < int32(8)) {
  44262 			break
  44263 		}
  44264 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), libc.Int32FromUint8(value), uint64(8))
  44265 		goto _1
  44266 	_1:
  44267 		;
  44268 		j = j + 1
  44269 	}
  44270 }
  44271 
  44272 func DC8uv_C(tls *libc.TLS, dst uintptr) {
  44273 	var dc0, i int32
  44274 	_, _ = dc0, i // DC
  44275 	dc0 = int32(8)
  44276 	i = 0
  44277 	for {
  44278 		if !(i < int32(8)) {
  44279 			break
  44280 		}
  44281 		dc0 = dc0 + (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS))))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS))))))
  44282 		goto _1
  44283 	_1:
  44284 		;
  44285 		i = i + 1
  44286 	}
  44287 	Put8x8uv(tls, libc.Uint8FromInt32(dc0>>int32(4)), dst)
  44288 }
  44289 
  44290 func DC8uvNoLeft_C(tls *libc.TLS, dst uintptr) {
  44291 	var dc0, i int32
  44292 	_, _ = dc0, i // DC with no left samples
  44293 	dc0 = int32(4)
  44294 	i = 0
  44295 	for {
  44296 		if !(i < int32(8)) {
  44297 			break
  44298 		}
  44299 		dc0 = dc0 + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44300 		goto _1
  44301 	_1:
  44302 		;
  44303 		i = i + 1
  44304 	}
  44305 	Put8x8uv(tls, libc.Uint8FromInt32(dc0>>int32(3)), dst)
  44306 }
  44307 
  44308 func DC8uvNoTop_C(tls *libc.TLS, dst uintptr) {
  44309 	var dc0, i int32
  44310 	_, _ = dc0, i // DC with no top samples
  44311 	dc0 = int32(4)
  44312 	i = 0
  44313 	for {
  44314 		if !(i < int32(8)) {
  44315 			break
  44316 		}
  44317 		dc0 = dc0 + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS)))))
  44318 		goto _1
  44319 	_1:
  44320 		;
  44321 		i = i + 1
  44322 	}
  44323 	Put8x8uv(tls, libc.Uint8FromInt32(dc0>>int32(3)), dst)
  44324 }
  44325 
  44326 func DC8uvNoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44327 	// DC with nothing
  44328 	Put8x8uv(tls, uint8(0x80), dst)
  44329 }
  44330 
  44331 //------------------------------------------------------------------------------
  44332 // Edge filtering functions
  44333 
  44334 // C documentation
  44335 //
  44336 //	// 4 pixels in, 2 pixels out
  44337 func DoFilter2_C(tls *libc.TLS, p uintptr, step int32) {
  44338 	var a, a1, a2, p0, p1, q0, q1 int32
  44339 	_, _, _, _, _, _, _ = a, a1, a2, p0, p1, q0, q1
  44340 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44341 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44342 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44343 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44344 	a = int32(3)*(q0-p0) + int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1)))) // in [-893,892]
  44345 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))  // in [-16,15]
  44346 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44347 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44348 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44349 }
  44350 
  44351 // C documentation
  44352 //
  44353 //	// 4 pixels in, 4 pixels out
  44354 func DoFilter4_C(tls *libc.TLS, p uintptr, step int32) {
  44355 	var a, a1, a2, a3, p0, p1, q0, q1 int32
  44356 	_, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, q0, q1
  44357 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44358 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44359 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44360 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44361 	a = int32(3) * (q0 - p0)
  44362 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))
  44363 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44364 	a3 = (a1 + int32(1)) >> int32(1)
  44365 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a3)))
  44366 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44367 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44368 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a3)))
  44369 }
  44370 
  44371 // C documentation
  44372 //
  44373 //	// 6 pixels in, 6 pixels out
  44374 func DoFilter6_C(tls *libc.TLS, p uintptr, step int32) {
  44375 	var a, a1, a2, a3, p0, p1, p2, q0, q1, q2 int32
  44376 	_, _, _, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, p2, q0, q1, q2
  44377 	p2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44378 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44379 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44380 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44381 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44382 	q2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44383 	a = int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(int32(3)*(q0-p0)+int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1))))))))
  44384 	// a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
  44385 	a1 = (int32(27)*a + int32(63)) >> int32(7) // eq. to ((3 * a + 7) * 9) >> 7
  44386 	a2 = (int32(18)*a + int32(63)) >> int32(7) // eq. to ((2 * a + 7) * 9) >> 7
  44387 	a3 = (int32(9)*a + int32(63)) >> int32(7)  // eq. to ((1 * a + 7) * 9) >> 7
  44388 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p2+a3)))
  44389 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a2)))
  44390 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a1)))
  44391 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44392 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a2)))
  44393 	**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q2-a3)))
  44394 }
  44395 
  44396 func Hev(tls *libc.TLS, p uintptr, step int32, thresh int32) (r int32) {
  44397 	var p0, p1, q0, q1 int32
  44398 	_, _, _, _ = p0, p1, q0, q1
  44399 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44400 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44401 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44402 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44403 	return libc.BoolInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-p0)))) > thresh || libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q1-q0)))) > thresh)
  44404 }
  44405 
  44406 func NeedsFilter_C(tls *libc.TLS, p uintptr, step int32, t int32) (r int32) {
  44407 	var p0, p1, q0, q1 int32
  44408 	_, _, _, _ = p0, p1, q0, q1
  44409 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44410 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44411 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44412 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44413 	return libc.BoolInt32(int32(4)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) <= t)
  44414 }
  44415 
  44416 func NeedsFilter2_C(tls *libc.TLS, p uintptr, step int32, t int32, it int32) (r int32) {
  44417 	var p0, p1, p2, p3, q0, q1, q2, q3 int32
  44418 	_, _, _, _, _, _, _, _ = p0, p1, p2, p3, q0, q1, q2, q3
  44419 	p3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(4)*step))))
  44420 	p2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44421 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44422 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44423 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44424 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44425 	q2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44426 	q3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(3)*step))))
  44427 	if int32(4)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) > t {
  44428 		return 0
  44429 	}
  44430 	return libc.BoolInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p3-p2)))) <= it && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p2-p1)))) <= it && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-p0)))) <= it && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q3-q2)))) <= it && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q2-q1)))) <= it && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(q1-q0)))) <= it)
  44431 }
  44432 
  44433 //------------------------------------------------------------------------------
  44434 // Simple In-loop filtering (Paragraph 15.2)
  44435 
  44436 func SimpleVFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44437 	var i, thresh2 int32
  44438 	_, _ = i, thresh2
  44439 	thresh2 = int32(2)*thresh + int32(1)
  44440 	i = 0
  44441 	for {
  44442 		if !(i < int32(16)) {
  44443 			break
  44444 		}
  44445 		if NeedsFilter_C(tls, p+uintptr(i), stride, thresh2) != 0 {
  44446 			DoFilter2_C(tls, p+uintptr(i), stride)
  44447 		}
  44448 		goto _1
  44449 	_1:
  44450 		;
  44451 		i = i + 1
  44452 	}
  44453 }
  44454 
  44455 func SimpleHFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44456 	var i, thresh2 int32
  44457 	_, _ = i, thresh2
  44458 	thresh2 = int32(2)*thresh + int32(1)
  44459 	i = 0
  44460 	for {
  44461 		if !(i < int32(16)) {
  44462 			break
  44463 		}
  44464 		if NeedsFilter_C(tls, p+uintptr(i*stride), int32(1), thresh2) != 0 {
  44465 			DoFilter2_C(tls, p+uintptr(i*stride), int32(1))
  44466 		}
  44467 		goto _1
  44468 	_1:
  44469 		;
  44470 		i = i + 1
  44471 	}
  44472 }
  44473 
  44474 func SimpleVFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44475 	var k int32
  44476 	_ = k
  44477 	k = int32(3)
  44478 	for {
  44479 		if !(k > 0) {
  44480 			break
  44481 		}
  44482 		p = p + uintptr(int32(4)*stride)
  44483 		SimpleVFilter16_C(tls, p, stride, thresh)
  44484 		goto _1
  44485 	_1:
  44486 		;
  44487 		k = k - 1
  44488 	}
  44489 }
  44490 
  44491 func SimpleHFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44492 	var k int32
  44493 	_ = k
  44494 	k = int32(3)
  44495 	for {
  44496 		if !(k > 0) {
  44497 			break
  44498 		}
  44499 		p = p + uintptr(4)
  44500 		SimpleHFilter16_C(tls, p, stride, thresh)
  44501 		goto _1
  44502 	_1:
  44503 		;
  44504 		k = k - 1
  44505 	}
  44506 }
  44507 
  44508 //------------------------------------------------------------------------------
  44509 // Complex In-loop filtering (Paragraph 15.3)
  44510 
  44511 func FilterLoop26_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44512 	var thresh2, v1 int32
  44513 	_, _ = thresh2, v1
  44514 	thresh2 = int32(2)*thresh + int32(1)
  44515 	for {
  44516 		v1 = size
  44517 		size = size - 1
  44518 		if !(v1 > 0) {
  44519 			break
  44520 		}
  44521 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44522 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44523 				DoFilter2_C(tls, p, hstride)
  44524 			} else {
  44525 				DoFilter6_C(tls, p, hstride)
  44526 			}
  44527 		}
  44528 		p = p + uintptr(vstride)
  44529 	}
  44530 }
  44531 
  44532 func FilterLoop24_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44533 	var thresh2, v1 int32
  44534 	_, _ = thresh2, v1
  44535 	thresh2 = int32(2)*thresh + int32(1)
  44536 	for {
  44537 		v1 = size
  44538 		size = size - 1
  44539 		if !(v1 > 0) {
  44540 			break
  44541 		}
  44542 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44543 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44544 				DoFilter2_C(tls, p, hstride)
  44545 			} else {
  44546 				DoFilter4_C(tls, p, hstride)
  44547 			}
  44548 		}
  44549 		p = p + uintptr(vstride)
  44550 	}
  44551 }
  44552 
  44553 // C documentation
  44554 //
  44555 //	// on macroblock edges
  44556 func VFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44557 	FilterLoop26_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44558 }
  44559 
  44560 func HFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44561 	FilterLoop26_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44562 }
  44563 
  44564 // C documentation
  44565 //
  44566 //	// on three inner edges
  44567 func VFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44568 	var k int32
  44569 	_ = k
  44570 	k = int32(3)
  44571 	for {
  44572 		if !(k > 0) {
  44573 			break
  44574 		}
  44575 		p = p + uintptr(int32(4)*stride)
  44576 		FilterLoop24_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44577 		goto _1
  44578 	_1:
  44579 		;
  44580 		k = k - 1
  44581 	}
  44582 }
  44583 
  44584 func HFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44585 	var k int32
  44586 	_ = k
  44587 	k = int32(3)
  44588 	for {
  44589 		if !(k > 0) {
  44590 			break
  44591 		}
  44592 		p = p + uintptr(4)
  44593 		FilterLoop24_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44594 		goto _1
  44595 	_1:
  44596 		;
  44597 		k = k - 1
  44598 	}
  44599 }
  44600 
  44601 // C documentation
  44602 //
  44603 //	// 8-pixels wide variant, for chroma filtering
  44604 func VFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44605 	FilterLoop26_C(tls, u, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44606 	FilterLoop26_C(tls, v, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44607 }
  44608 
  44609 func HFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44610 	FilterLoop26_C(tls, u, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44611 	FilterLoop26_C(tls, v, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44612 }
  44613 
  44614 func VFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44615 	FilterLoop24_C(tls, u+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44616 	FilterLoop24_C(tls, v+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44617 }
  44618 
  44619 func HFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44620 	FilterLoop24_C(tls, u+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44621 	FilterLoop24_C(tls, v+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44622 }
  44623 
  44624 //------------------------------------------------------------------------------
  44625 
  44626 func DitherCombine8x8_C(tls *libc.TLS, dither uintptr, dst uintptr, dst_stride int32) {
  44627 	var delta0, delta1, i, j int32
  44628 	_, _, _, _ = delta0, delta1, i, j
  44629 	j = 0
  44630 	for {
  44631 		if !(j < int32(8)) {
  44632 			break
  44633 		}
  44634 		i = 0
  44635 		for {
  44636 			if !(i < int32(8)) {
  44637 				break
  44638 			}
  44639 			delta0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dither + uintptr(i)))) - libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_DITHER_AMP_BITS)
  44640 			delta1 = (delta0 + libc.Int32FromInt32(1)<<(libc.Int32FromInt32(VP8_DITHER_DESCALE)-libc.Int32FromInt32(1))) >> int32(VP8_DITHER_DESCALE)
  44641 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i))))+delta1)
  44642 			goto _2
  44643 		_2:
  44644 			;
  44645 			i = i + 1
  44646 		}
  44647 		dst = dst + uintptr(dst_stride)
  44648 		dither = dither + uintptr(8)
  44649 		goto _1
  44650 	_1:
  44651 		;
  44652 		j = j + 1
  44653 	}
  44654 }
  44655 
  44656 func VP8DspInit(tls *libc.TLS) {
  44657 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  44658 		goto _1
  44659 	}
  44660 	VP8DspInit_body(tls)
  44661 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  44662 	goto _2
  44663 _2:
  44664 	;
  44665 	goto _1
  44666 _1: /**/ //
  44667 }
  44668 
  44669 var VP8DspInit_body_last_cpuinfo_used = uintptr(0)
  44670 
  44671 func init() {
  44672 	p := unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)
  44673 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))
  44674 }
  44675 
  44676 func VP8DspInit_body(tls *libc.TLS) {
  44677 	VP8InitClipTables(tls)
  44678 	VP8TransformWHT = __ccgo_fp(TransformWHT_C)
  44679 	VP8Transform = __ccgo_fp(TransformTwo_C)
  44680 	VP8TransformDC = __ccgo_fp(TransformDC_C)
  44681 	VP8TransformAC3 = __ccgo_fp(TransformAC3_C)
  44682 	VP8TransformUV = __ccgo_fp(TransformUV_C)
  44683 	VP8TransformDCUV = __ccgo_fp(TransformDCUV_C)
  44684 	VP8VFilter16 = __ccgo_fp(VFilter16_C)
  44685 	VP8VFilter16i = __ccgo_fp(VFilter16i_C)
  44686 	VP8HFilter16 = __ccgo_fp(HFilter16_C)
  44687 	VP8VFilter8 = __ccgo_fp(VFilter8_C)
  44688 	VP8VFilter8i = __ccgo_fp(VFilter8i_C)
  44689 	VP8SimpleVFilter16 = __ccgo_fp(SimpleVFilter16_C)
  44690 	VP8SimpleHFilter16 = __ccgo_fp(SimpleHFilter16_C)
  44691 	VP8SimpleVFilter16i = __ccgo_fp(SimpleVFilter16i_C)
  44692 	VP8SimpleHFilter16i = __ccgo_fp(SimpleHFilter16i_C)
  44693 	VP8HFilter16i = __ccgo_fp(HFilter16i_C)
  44694 	VP8HFilter8 = __ccgo_fp(HFilter8_C)
  44695 	VP8HFilter8i = __ccgo_fp(HFilter8i_C)
  44696 	VP8PredLuma4[0] = __ccgo_fp(DC4_C)
  44697 	VP8PredLuma4[int32(1)] = __ccgo_fp(TM4_C)
  44698 	VP8PredLuma4[int32(2)] = __ccgo_fp(VE4_C)
  44699 	VP8PredLuma4[int32(4)] = __ccgo_fp(RD4_C)
  44700 	VP8PredLuma4[int32(6)] = __ccgo_fp(LD4_C)
  44701 	VP8PredLuma4[int32(3)] = __ccgo_fp(HE4_C)
  44702 	VP8PredLuma4[int32(5)] = __ccgo_fp(VR4_C)
  44703 	VP8PredLuma4[int32(7)] = __ccgo_fp(VL4_C)
  44704 	VP8PredLuma4[int32(8)] = __ccgo_fp(HD4_C)
  44705 	VP8PredLuma4[int32(9)] = __ccgo_fp(HU4_C)
  44706 	VP8PredLuma16[0] = __ccgo_fp(DC16_C)
  44707 	VP8PredLuma16[int32(1)] = __ccgo_fp(TM16_C)
  44708 	VP8PredLuma16[int32(2)] = __ccgo_fp(VE16_C)
  44709 	VP8PredLuma16[int32(3)] = __ccgo_fp(HE16_C)
  44710 	VP8PredLuma16[int32(4)] = __ccgo_fp(DC16NoTop_C)
  44711 	VP8PredLuma16[int32(5)] = __ccgo_fp(DC16NoLeft_C)
  44712 	VP8PredLuma16[int32(6)] = __ccgo_fp(DC16NoTopLeft_C)
  44713 	VP8PredChroma8[0] = __ccgo_fp(DC8uv_C)
  44714 	VP8PredChroma8[int32(1)] = __ccgo_fp(TM8uv_C)
  44715 	VP8PredChroma8[int32(2)] = __ccgo_fp(VE8uv_C)
  44716 	VP8PredChroma8[int32(3)] = __ccgo_fp(HE8uv_C)
  44717 	VP8PredChroma8[int32(4)] = __ccgo_fp(DC8uvNoTop_C)
  44718 	VP8PredChroma8[int32(5)] = __ccgo_fp(DC8uvNoLeft_C)
  44719 	VP8PredChroma8[int32(6)] = __ccgo_fp(DC8uvNoTopLeft_C)
  44720 	VP8DitherCombine8x8 = __ccgo_fp(DitherCombine8x8_C)
  44721 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  44722 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  44723 	}
  44724 }
  44725 
  44726 const USE_STATIC_TABLES = 1
  44727 
  44728 // define to 0 to have run-time table initialization
  44729 
  44730 var abs0 = [511]uint8_t{
  44731 	0:   uint8(0xff),
  44732 	1:   uint8(0xfe),
  44733 	2:   uint8(0xfd),
  44734 	3:   uint8(0xfc),
  44735 	4:   uint8(0xfb),
  44736 	5:   uint8(0xfa),
  44737 	6:   uint8(0xf9),
  44738 	7:   uint8(0xf8),
  44739 	8:   uint8(0xf7),
  44740 	9:   uint8(0xf6),
  44741 	10:  uint8(0xf5),
  44742 	11:  uint8(0xf4),
  44743 	12:  uint8(0xf3),
  44744 	13:  uint8(0xf2),
  44745 	14:  uint8(0xf1),
  44746 	15:  uint8(0xf0),
  44747 	16:  uint8(0xef),
  44748 	17:  uint8(0xee),
  44749 	18:  uint8(0xed),
  44750 	19:  uint8(0xec),
  44751 	20:  uint8(0xeb),
  44752 	21:  uint8(0xea),
  44753 	22:  uint8(0xe9),
  44754 	23:  uint8(0xe8),
  44755 	24:  uint8(0xe7),
  44756 	25:  uint8(0xe6),
  44757 	26:  uint8(0xe5),
  44758 	27:  uint8(0xe4),
  44759 	28:  uint8(0xe3),
  44760 	29:  uint8(0xe2),
  44761 	30:  uint8(0xe1),
  44762 	31:  uint8(0xe0),
  44763 	32:  uint8(0xdf),
  44764 	33:  uint8(0xde),
  44765 	34:  uint8(0xdd),
  44766 	35:  uint8(0xdc),
  44767 	36:  uint8(0xdb),
  44768 	37:  uint8(0xda),
  44769 	38:  uint8(0xd9),
  44770 	39:  uint8(0xd8),
  44771 	40:  uint8(0xd7),
  44772 	41:  uint8(0xd6),
  44773 	42:  uint8(0xd5),
  44774 	43:  uint8(0xd4),
  44775 	44:  uint8(0xd3),
  44776 	45:  uint8(0xd2),
  44777 	46:  uint8(0xd1),
  44778 	47:  uint8(0xd0),
  44779 	48:  uint8(0xcf),
  44780 	49:  uint8(0xce),
  44781 	50:  uint8(0xcd),
  44782 	51:  uint8(0xcc),
  44783 	52:  uint8(0xcb),
  44784 	53:  uint8(0xca),
  44785 	54:  uint8(0xc9),
  44786 	55:  uint8(0xc8),
  44787 	56:  uint8(0xc7),
  44788 	57:  uint8(0xc6),
  44789 	58:  uint8(0xc5),
  44790 	59:  uint8(0xc4),
  44791 	60:  uint8(0xc3),
  44792 	61:  uint8(0xc2),
  44793 	62:  uint8(0xc1),
  44794 	63:  uint8(0xc0),
  44795 	64:  uint8(0xbf),
  44796 	65:  uint8(0xbe),
  44797 	66:  uint8(0xbd),
  44798 	67:  uint8(0xbc),
  44799 	68:  uint8(0xbb),
  44800 	69:  uint8(0xba),
  44801 	70:  uint8(0xb9),
  44802 	71:  uint8(0xb8),
  44803 	72:  uint8(0xb7),
  44804 	73:  uint8(0xb6),
  44805 	74:  uint8(0xb5),
  44806 	75:  uint8(0xb4),
  44807 	76:  uint8(0xb3),
  44808 	77:  uint8(0xb2),
  44809 	78:  uint8(0xb1),
  44810 	79:  uint8(0xb0),
  44811 	80:  uint8(0xaf),
  44812 	81:  uint8(0xae),
  44813 	82:  uint8(0xad),
  44814 	83:  uint8(0xac),
  44815 	84:  uint8(0xab),
  44816 	85:  uint8(0xaa),
  44817 	86:  uint8(0xa9),
  44818 	87:  uint8(0xa8),
  44819 	88:  uint8(0xa7),
  44820 	89:  uint8(0xa6),
  44821 	90:  uint8(0xa5),
  44822 	91:  uint8(0xa4),
  44823 	92:  uint8(0xa3),
  44824 	93:  uint8(0xa2),
  44825 	94:  uint8(0xa1),
  44826 	95:  uint8(0xa0),
  44827 	96:  uint8(0x9f),
  44828 	97:  uint8(0x9e),
  44829 	98:  uint8(0x9d),
  44830 	99:  uint8(0x9c),
  44831 	100: uint8(0x9b),
  44832 	101: uint8(0x9a),
  44833 	102: uint8(0x99),
  44834 	103: uint8(0x98),
  44835 	104: uint8(0x97),
  44836 	105: uint8(0x96),
  44837 	106: uint8(0x95),
  44838 	107: uint8(0x94),
  44839 	108: uint8(0x93),
  44840 	109: uint8(0x92),
  44841 	110: uint8(0x91),
  44842 	111: uint8(0x90),
  44843 	112: uint8(0x8f),
  44844 	113: uint8(0x8e),
  44845 	114: uint8(0x8d),
  44846 	115: uint8(0x8c),
  44847 	116: uint8(0x8b),
  44848 	117: uint8(0x8a),
  44849 	118: uint8(0x89),
  44850 	119: uint8(0x88),
  44851 	120: uint8(0x87),
  44852 	121: uint8(0x86),
  44853 	122: uint8(0x85),
  44854 	123: uint8(0x84),
  44855 	124: uint8(0x83),
  44856 	125: uint8(0x82),
  44857 	126: uint8(0x81),
  44858 	127: uint8(0x80),
  44859 	128: uint8(0x7f),
  44860 	129: uint8(0x7e),
  44861 	130: uint8(0x7d),
  44862 	131: uint8(0x7c),
  44863 	132: uint8(0x7b),
  44864 	133: uint8(0x7a),
  44865 	134: uint8(0x79),
  44866 	135: uint8(0x78),
  44867 	136: uint8(0x77),
  44868 	137: uint8(0x76),
  44869 	138: uint8(0x75),
  44870 	139: uint8(0x74),
  44871 	140: uint8(0x73),
  44872 	141: uint8(0x72),
  44873 	142: uint8(0x71),
  44874 	143: uint8(0x70),
  44875 	144: uint8(0x6f),
  44876 	145: uint8(0x6e),
  44877 	146: uint8(0x6d),
  44878 	147: uint8(0x6c),
  44879 	148: uint8(0x6b),
  44880 	149: uint8(0x6a),
  44881 	150: uint8(0x69),
  44882 	151: uint8(0x68),
  44883 	152: uint8(0x67),
  44884 	153: uint8(0x66),
  44885 	154: uint8(0x65),
  44886 	155: uint8(0x64),
  44887 	156: uint8(0x63),
  44888 	157: uint8(0x62),
  44889 	158: uint8(0x61),
  44890 	159: uint8(0x60),
  44891 	160: uint8(0x5f),
  44892 	161: uint8(0x5e),
  44893 	162: uint8(0x5d),
  44894 	163: uint8(0x5c),
  44895 	164: uint8(0x5b),
  44896 	165: uint8(0x5a),
  44897 	166: uint8(0x59),
  44898 	167: uint8(0x58),
  44899 	168: uint8(0x57),
  44900 	169: uint8(0x56),
  44901 	170: uint8(0x55),
  44902 	171: uint8(0x54),
  44903 	172: uint8(0x53),
  44904 	173: uint8(0x52),
  44905 	174: uint8(0x51),
  44906 	175: uint8(0x50),
  44907 	176: uint8(0x4f),
  44908 	177: uint8(0x4e),
  44909 	178: uint8(0x4d),
  44910 	179: uint8(0x4c),
  44911 	180: uint8(0x4b),
  44912 	181: uint8(0x4a),
  44913 	182: uint8(0x49),
  44914 	183: uint8(0x48),
  44915 	184: uint8(0x47),
  44916 	185: uint8(0x46),
  44917 	186: uint8(0x45),
  44918 	187: uint8(0x44),
  44919 	188: uint8(0x43),
  44920 	189: uint8(0x42),
  44921 	190: uint8(0x41),
  44922 	191: uint8(0x40),
  44923 	192: uint8(0x3f),
  44924 	193: uint8(0x3e),
  44925 	194: uint8(0x3d),
  44926 	195: uint8(0x3c),
  44927 	196: uint8(0x3b),
  44928 	197: uint8(0x3a),
  44929 	198: uint8(0x39),
  44930 	199: uint8(0x38),
  44931 	200: uint8(0x37),
  44932 	201: uint8(0x36),
  44933 	202: uint8(0x35),
  44934 	203: uint8(0x34),
  44935 	204: uint8(0x33),
  44936 	205: uint8(0x32),
  44937 	206: uint8(0x31),
  44938 	207: uint8(0x30),
  44939 	208: uint8(0x2f),
  44940 	209: uint8(0x2e),
  44941 	210: uint8(0x2d),
  44942 	211: uint8(0x2c),
  44943 	212: uint8(0x2b),
  44944 	213: uint8(0x2a),
  44945 	214: uint8(0x29),
  44946 	215: uint8(0x28),
  44947 	216: uint8(0x27),
  44948 	217: uint8(0x26),
  44949 	218: uint8(0x25),
  44950 	219: uint8(0x24),
  44951 	220: uint8(0x23),
  44952 	221: uint8(0x22),
  44953 	222: uint8(0x21),
  44954 	223: uint8(0x20),
  44955 	224: uint8(0x1f),
  44956 	225: uint8(0x1e),
  44957 	226: uint8(0x1d),
  44958 	227: uint8(0x1c),
  44959 	228: uint8(0x1b),
  44960 	229: uint8(0x1a),
  44961 	230: uint8(0x19),
  44962 	231: uint8(0x18),
  44963 	232: uint8(0x17),
  44964 	233: uint8(0x16),
  44965 	234: uint8(0x15),
  44966 	235: uint8(0x14),
  44967 	236: uint8(0x13),
  44968 	237: uint8(0x12),
  44969 	238: uint8(0x11),
  44970 	239: uint8(0x10),
  44971 	240: uint8(0x0f),
  44972 	241: uint8(0x0e),
  44973 	242: uint8(0x0d),
  44974 	243: uint8(0x0c),
  44975 	244: uint8(0x0b),
  44976 	245: uint8(0x0a),
  44977 	246: uint8(0x09),
  44978 	247: uint8(0x08),
  44979 	248: uint8(0x07),
  44980 	249: uint8(0x06),
  44981 	250: uint8(0x05),
  44982 	251: uint8(0x04),
  44983 	252: uint8(0x03),
  44984 	253: uint8(0x02),
  44985 	254: uint8(0x01),
  44986 	256: uint8(0x01),
  44987 	257: uint8(0x02),
  44988 	258: uint8(0x03),
  44989 	259: uint8(0x04),
  44990 	260: uint8(0x05),
  44991 	261: uint8(0x06),
  44992 	262: uint8(0x07),
  44993 	263: uint8(0x08),
  44994 	264: uint8(0x09),
  44995 	265: uint8(0x0a),
  44996 	266: uint8(0x0b),
  44997 	267: uint8(0x0c),
  44998 	268: uint8(0x0d),
  44999 	269: uint8(0x0e),
  45000 	270: uint8(0x0f),
  45001 	271: uint8(0x10),
  45002 	272: uint8(0x11),
  45003 	273: uint8(0x12),
  45004 	274: uint8(0x13),
  45005 	275: uint8(0x14),
  45006 	276: uint8(0x15),
  45007 	277: uint8(0x16),
  45008 	278: uint8(0x17),
  45009 	279: uint8(0x18),
  45010 	280: uint8(0x19),
  45011 	281: uint8(0x1a),
  45012 	282: uint8(0x1b),
  45013 	283: uint8(0x1c),
  45014 	284: uint8(0x1d),
  45015 	285: uint8(0x1e),
  45016 	286: uint8(0x1f),
  45017 	287: uint8(0x20),
  45018 	288: uint8(0x21),
  45019 	289: uint8(0x22),
  45020 	290: uint8(0x23),
  45021 	291: uint8(0x24),
  45022 	292: uint8(0x25),
  45023 	293: uint8(0x26),
  45024 	294: uint8(0x27),
  45025 	295: uint8(0x28),
  45026 	296: uint8(0x29),
  45027 	297: uint8(0x2a),
  45028 	298: uint8(0x2b),
  45029 	299: uint8(0x2c),
  45030 	300: uint8(0x2d),
  45031 	301: uint8(0x2e),
  45032 	302: uint8(0x2f),
  45033 	303: uint8(0x30),
  45034 	304: uint8(0x31),
  45035 	305: uint8(0x32),
  45036 	306: uint8(0x33),
  45037 	307: uint8(0x34),
  45038 	308: uint8(0x35),
  45039 	309: uint8(0x36),
  45040 	310: uint8(0x37),
  45041 	311: uint8(0x38),
  45042 	312: uint8(0x39),
  45043 	313: uint8(0x3a),
  45044 	314: uint8(0x3b),
  45045 	315: uint8(0x3c),
  45046 	316: uint8(0x3d),
  45047 	317: uint8(0x3e),
  45048 	318: uint8(0x3f),
  45049 	319: uint8(0x40),
  45050 	320: uint8(0x41),
  45051 	321: uint8(0x42),
  45052 	322: uint8(0x43),
  45053 	323: uint8(0x44),
  45054 	324: uint8(0x45),
  45055 	325: uint8(0x46),
  45056 	326: uint8(0x47),
  45057 	327: uint8(0x48),
  45058 	328: uint8(0x49),
  45059 	329: uint8(0x4a),
  45060 	330: uint8(0x4b),
  45061 	331: uint8(0x4c),
  45062 	332: uint8(0x4d),
  45063 	333: uint8(0x4e),
  45064 	334: uint8(0x4f),
  45065 	335: uint8(0x50),
  45066 	336: uint8(0x51),
  45067 	337: uint8(0x52),
  45068 	338: uint8(0x53),
  45069 	339: uint8(0x54),
  45070 	340: uint8(0x55),
  45071 	341: uint8(0x56),
  45072 	342: uint8(0x57),
  45073 	343: uint8(0x58),
  45074 	344: uint8(0x59),
  45075 	345: uint8(0x5a),
  45076 	346: uint8(0x5b),
  45077 	347: uint8(0x5c),
  45078 	348: uint8(0x5d),
  45079 	349: uint8(0x5e),
  45080 	350: uint8(0x5f),
  45081 	351: uint8(0x60),
  45082 	352: uint8(0x61),
  45083 	353: uint8(0x62),
  45084 	354: uint8(0x63),
  45085 	355: uint8(0x64),
  45086 	356: uint8(0x65),
  45087 	357: uint8(0x66),
  45088 	358: uint8(0x67),
  45089 	359: uint8(0x68),
  45090 	360: uint8(0x69),
  45091 	361: uint8(0x6a),
  45092 	362: uint8(0x6b),
  45093 	363: uint8(0x6c),
  45094 	364: uint8(0x6d),
  45095 	365: uint8(0x6e),
  45096 	366: uint8(0x6f),
  45097 	367: uint8(0x70),
  45098 	368: uint8(0x71),
  45099 	369: uint8(0x72),
  45100 	370: uint8(0x73),
  45101 	371: uint8(0x74),
  45102 	372: uint8(0x75),
  45103 	373: uint8(0x76),
  45104 	374: uint8(0x77),
  45105 	375: uint8(0x78),
  45106 	376: uint8(0x79),
  45107 	377: uint8(0x7a),
  45108 	378: uint8(0x7b),
  45109 	379: uint8(0x7c),
  45110 	380: uint8(0x7d),
  45111 	381: uint8(0x7e),
  45112 	382: uint8(0x7f),
  45113 	383: uint8(0x80),
  45114 	384: uint8(0x81),
  45115 	385: uint8(0x82),
  45116 	386: uint8(0x83),
  45117 	387: uint8(0x84),
  45118 	388: uint8(0x85),
  45119 	389: uint8(0x86),
  45120 	390: uint8(0x87),
  45121 	391: uint8(0x88),
  45122 	392: uint8(0x89),
  45123 	393: uint8(0x8a),
  45124 	394: uint8(0x8b),
  45125 	395: uint8(0x8c),
  45126 	396: uint8(0x8d),
  45127 	397: uint8(0x8e),
  45128 	398: uint8(0x8f),
  45129 	399: uint8(0x90),
  45130 	400: uint8(0x91),
  45131 	401: uint8(0x92),
  45132 	402: uint8(0x93),
  45133 	403: uint8(0x94),
  45134 	404: uint8(0x95),
  45135 	405: uint8(0x96),
  45136 	406: uint8(0x97),
  45137 	407: uint8(0x98),
  45138 	408: uint8(0x99),
  45139 	409: uint8(0x9a),
  45140 	410: uint8(0x9b),
  45141 	411: uint8(0x9c),
  45142 	412: uint8(0x9d),
  45143 	413: uint8(0x9e),
  45144 	414: uint8(0x9f),
  45145 	415: uint8(0xa0),
  45146 	416: uint8(0xa1),
  45147 	417: uint8(0xa2),
  45148 	418: uint8(0xa3),
  45149 	419: uint8(0xa4),
  45150 	420: uint8(0xa5),
  45151 	421: uint8(0xa6),
  45152 	422: uint8(0xa7),
  45153 	423: uint8(0xa8),
  45154 	424: uint8(0xa9),
  45155 	425: uint8(0xaa),
  45156 	426: uint8(0xab),
  45157 	427: uint8(0xac),
  45158 	428: uint8(0xad),
  45159 	429: uint8(0xae),
  45160 	430: uint8(0xaf),
  45161 	431: uint8(0xb0),
  45162 	432: uint8(0xb1),
  45163 	433: uint8(0xb2),
  45164 	434: uint8(0xb3),
  45165 	435: uint8(0xb4),
  45166 	436: uint8(0xb5),
  45167 	437: uint8(0xb6),
  45168 	438: uint8(0xb7),
  45169 	439: uint8(0xb8),
  45170 	440: uint8(0xb9),
  45171 	441: uint8(0xba),
  45172 	442: uint8(0xbb),
  45173 	443: uint8(0xbc),
  45174 	444: uint8(0xbd),
  45175 	445: uint8(0xbe),
  45176 	446: uint8(0xbf),
  45177 	447: uint8(0xc0),
  45178 	448: uint8(0xc1),
  45179 	449: uint8(0xc2),
  45180 	450: uint8(0xc3),
  45181 	451: uint8(0xc4),
  45182 	452: uint8(0xc5),
  45183 	453: uint8(0xc6),
  45184 	454: uint8(0xc7),
  45185 	455: uint8(0xc8),
  45186 	456: uint8(0xc9),
  45187 	457: uint8(0xca),
  45188 	458: uint8(0xcb),
  45189 	459: uint8(0xcc),
  45190 	460: uint8(0xcd),
  45191 	461: uint8(0xce),
  45192 	462: uint8(0xcf),
  45193 	463: uint8(0xd0),
  45194 	464: uint8(0xd1),
  45195 	465: uint8(0xd2),
  45196 	466: uint8(0xd3),
  45197 	467: uint8(0xd4),
  45198 	468: uint8(0xd5),
  45199 	469: uint8(0xd6),
  45200 	470: uint8(0xd7),
  45201 	471: uint8(0xd8),
  45202 	472: uint8(0xd9),
  45203 	473: uint8(0xda),
  45204 	474: uint8(0xdb),
  45205 	475: uint8(0xdc),
  45206 	476: uint8(0xdd),
  45207 	477: uint8(0xde),
  45208 	478: uint8(0xdf),
  45209 	479: uint8(0xe0),
  45210 	480: uint8(0xe1),
  45211 	481: uint8(0xe2),
  45212 	482: uint8(0xe3),
  45213 	483: uint8(0xe4),
  45214 	484: uint8(0xe5),
  45215 	485: uint8(0xe6),
  45216 	486: uint8(0xe7),
  45217 	487: uint8(0xe8),
  45218 	488: uint8(0xe9),
  45219 	489: uint8(0xea),
  45220 	490: uint8(0xeb),
  45221 	491: uint8(0xec),
  45222 	492: uint8(0xed),
  45223 	493: uint8(0xee),
  45224 	494: uint8(0xef),
  45225 	495: uint8(0xf0),
  45226 	496: uint8(0xf1),
  45227 	497: uint8(0xf2),
  45228 	498: uint8(0xf3),
  45229 	499: uint8(0xf4),
  45230 	500: uint8(0xf5),
  45231 	501: uint8(0xf6),
  45232 	502: uint8(0xf7),
  45233 	503: uint8(0xf8),
  45234 	504: uint8(0xf9),
  45235 	505: uint8(0xfa),
  45236 	506: uint8(0xfb),
  45237 	507: uint8(0xfc),
  45238 	508: uint8(0xfd),
  45239 	509: uint8(0xfe),
  45240 	510: uint8(0xff),
  45241 }
  45242 
  45243 var sclip1 = [2041]uint8_t{
  45244 	0:    uint8(0x80),
  45245 	1:    uint8(0x80),
  45246 	2:    uint8(0x80),
  45247 	3:    uint8(0x80),
  45248 	4:    uint8(0x80),
  45249 	5:    uint8(0x80),
  45250 	6:    uint8(0x80),
  45251 	7:    uint8(0x80),
  45252 	8:    uint8(0x80),
  45253 	9:    uint8(0x80),
  45254 	10:   uint8(0x80),
  45255 	11:   uint8(0x80),
  45256 	12:   uint8(0x80),
  45257 	13:   uint8(0x80),
  45258 	14:   uint8(0x80),
  45259 	15:   uint8(0x80),
  45260 	16:   uint8(0x80),
  45261 	17:   uint8(0x80),
  45262 	18:   uint8(0x80),
  45263 	19:   uint8(0x80),
  45264 	20:   uint8(0x80),
  45265 	21:   uint8(0x80),
  45266 	22:   uint8(0x80),
  45267 	23:   uint8(0x80),
  45268 	24:   uint8(0x80),
  45269 	25:   uint8(0x80),
  45270 	26:   uint8(0x80),
  45271 	27:   uint8(0x80),
  45272 	28:   uint8(0x80),
  45273 	29:   uint8(0x80),
  45274 	30:   uint8(0x80),
  45275 	31:   uint8(0x80),
  45276 	32:   uint8(0x80),
  45277 	33:   uint8(0x80),
  45278 	34:   uint8(0x80),
  45279 	35:   uint8(0x80),
  45280 	36:   uint8(0x80),
  45281 	37:   uint8(0x80),
  45282 	38:   uint8(0x80),
  45283 	39:   uint8(0x80),
  45284 	40:   uint8(0x80),
  45285 	41:   uint8(0x80),
  45286 	42:   uint8(0x80),
  45287 	43:   uint8(0x80),
  45288 	44:   uint8(0x80),
  45289 	45:   uint8(0x80),
  45290 	46:   uint8(0x80),
  45291 	47:   uint8(0x80),
  45292 	48:   uint8(0x80),
  45293 	49:   uint8(0x80),
  45294 	50:   uint8(0x80),
  45295 	51:   uint8(0x80),
  45296 	52:   uint8(0x80),
  45297 	53:   uint8(0x80),
  45298 	54:   uint8(0x80),
  45299 	55:   uint8(0x80),
  45300 	56:   uint8(0x80),
  45301 	57:   uint8(0x80),
  45302 	58:   uint8(0x80),
  45303 	59:   uint8(0x80),
  45304 	60:   uint8(0x80),
  45305 	61:   uint8(0x80),
  45306 	62:   uint8(0x80),
  45307 	63:   uint8(0x80),
  45308 	64:   uint8(0x80),
  45309 	65:   uint8(0x80),
  45310 	66:   uint8(0x80),
  45311 	67:   uint8(0x80),
  45312 	68:   uint8(0x80),
  45313 	69:   uint8(0x80),
  45314 	70:   uint8(0x80),
  45315 	71:   uint8(0x80),
  45316 	72:   uint8(0x80),
  45317 	73:   uint8(0x80),
  45318 	74:   uint8(0x80),
  45319 	75:   uint8(0x80),
  45320 	76:   uint8(0x80),
  45321 	77:   uint8(0x80),
  45322 	78:   uint8(0x80),
  45323 	79:   uint8(0x80),
  45324 	80:   uint8(0x80),
  45325 	81:   uint8(0x80),
  45326 	82:   uint8(0x80),
  45327 	83:   uint8(0x80),
  45328 	84:   uint8(0x80),
  45329 	85:   uint8(0x80),
  45330 	86:   uint8(0x80),
  45331 	87:   uint8(0x80),
  45332 	88:   uint8(0x80),
  45333 	89:   uint8(0x80),
  45334 	90:   uint8(0x80),
  45335 	91:   uint8(0x80),
  45336 	92:   uint8(0x80),
  45337 	93:   uint8(0x80),
  45338 	94:   uint8(0x80),
  45339 	95:   uint8(0x80),
  45340 	96:   uint8(0x80),
  45341 	97:   uint8(0x80),
  45342 	98:   uint8(0x80),
  45343 	99:   uint8(0x80),
  45344 	100:  uint8(0x80),
  45345 	101:  uint8(0x80),
  45346 	102:  uint8(0x80),
  45347 	103:  uint8(0x80),
  45348 	104:  uint8(0x80),
  45349 	105:  uint8(0x80),
  45350 	106:  uint8(0x80),
  45351 	107:  uint8(0x80),
  45352 	108:  uint8(0x80),
  45353 	109:  uint8(0x80),
  45354 	110:  uint8(0x80),
  45355 	111:  uint8(0x80),
  45356 	112:  uint8(0x80),
  45357 	113:  uint8(0x80),
  45358 	114:  uint8(0x80),
  45359 	115:  uint8(0x80),
  45360 	116:  uint8(0x80),
  45361 	117:  uint8(0x80),
  45362 	118:  uint8(0x80),
  45363 	119:  uint8(0x80),
  45364 	120:  uint8(0x80),
  45365 	121:  uint8(0x80),
  45366 	122:  uint8(0x80),
  45367 	123:  uint8(0x80),
  45368 	124:  uint8(0x80),
  45369 	125:  uint8(0x80),
  45370 	126:  uint8(0x80),
  45371 	127:  uint8(0x80),
  45372 	128:  uint8(0x80),
  45373 	129:  uint8(0x80),
  45374 	130:  uint8(0x80),
  45375 	131:  uint8(0x80),
  45376 	132:  uint8(0x80),
  45377 	133:  uint8(0x80),
  45378 	134:  uint8(0x80),
  45379 	135:  uint8(0x80),
  45380 	136:  uint8(0x80),
  45381 	137:  uint8(0x80),
  45382 	138:  uint8(0x80),
  45383 	139:  uint8(0x80),
  45384 	140:  uint8(0x80),
  45385 	141:  uint8(0x80),
  45386 	142:  uint8(0x80),
  45387 	143:  uint8(0x80),
  45388 	144:  uint8(0x80),
  45389 	145:  uint8(0x80),
  45390 	146:  uint8(0x80),
  45391 	147:  uint8(0x80),
  45392 	148:  uint8(0x80),
  45393 	149:  uint8(0x80),
  45394 	150:  uint8(0x80),
  45395 	151:  uint8(0x80),
  45396 	152:  uint8(0x80),
  45397 	153:  uint8(0x80),
  45398 	154:  uint8(0x80),
  45399 	155:  uint8(0x80),
  45400 	156:  uint8(0x80),
  45401 	157:  uint8(0x80),
  45402 	158:  uint8(0x80),
  45403 	159:  uint8(0x80),
  45404 	160:  uint8(0x80),
  45405 	161:  uint8(0x80),
  45406 	162:  uint8(0x80),
  45407 	163:  uint8(0x80),
  45408 	164:  uint8(0x80),
  45409 	165:  uint8(0x80),
  45410 	166:  uint8(0x80),
  45411 	167:  uint8(0x80),
  45412 	168:  uint8(0x80),
  45413 	169:  uint8(0x80),
  45414 	170:  uint8(0x80),
  45415 	171:  uint8(0x80),
  45416 	172:  uint8(0x80),
  45417 	173:  uint8(0x80),
  45418 	174:  uint8(0x80),
  45419 	175:  uint8(0x80),
  45420 	176:  uint8(0x80),
  45421 	177:  uint8(0x80),
  45422 	178:  uint8(0x80),
  45423 	179:  uint8(0x80),
  45424 	180:  uint8(0x80),
  45425 	181:  uint8(0x80),
  45426 	182:  uint8(0x80),
  45427 	183:  uint8(0x80),
  45428 	184:  uint8(0x80),
  45429 	185:  uint8(0x80),
  45430 	186:  uint8(0x80),
  45431 	187:  uint8(0x80),
  45432 	188:  uint8(0x80),
  45433 	189:  uint8(0x80),
  45434 	190:  uint8(0x80),
  45435 	191:  uint8(0x80),
  45436 	192:  uint8(0x80),
  45437 	193:  uint8(0x80),
  45438 	194:  uint8(0x80),
  45439 	195:  uint8(0x80),
  45440 	196:  uint8(0x80),
  45441 	197:  uint8(0x80),
  45442 	198:  uint8(0x80),
  45443 	199:  uint8(0x80),
  45444 	200:  uint8(0x80),
  45445 	201:  uint8(0x80),
  45446 	202:  uint8(0x80),
  45447 	203:  uint8(0x80),
  45448 	204:  uint8(0x80),
  45449 	205:  uint8(0x80),
  45450 	206:  uint8(0x80),
  45451 	207:  uint8(0x80),
  45452 	208:  uint8(0x80),
  45453 	209:  uint8(0x80),
  45454 	210:  uint8(0x80),
  45455 	211:  uint8(0x80),
  45456 	212:  uint8(0x80),
  45457 	213:  uint8(0x80),
  45458 	214:  uint8(0x80),
  45459 	215:  uint8(0x80),
  45460 	216:  uint8(0x80),
  45461 	217:  uint8(0x80),
  45462 	218:  uint8(0x80),
  45463 	219:  uint8(0x80),
  45464 	220:  uint8(0x80),
  45465 	221:  uint8(0x80),
  45466 	222:  uint8(0x80),
  45467 	223:  uint8(0x80),
  45468 	224:  uint8(0x80),
  45469 	225:  uint8(0x80),
  45470 	226:  uint8(0x80),
  45471 	227:  uint8(0x80),
  45472 	228:  uint8(0x80),
  45473 	229:  uint8(0x80),
  45474 	230:  uint8(0x80),
  45475 	231:  uint8(0x80),
  45476 	232:  uint8(0x80),
  45477 	233:  uint8(0x80),
  45478 	234:  uint8(0x80),
  45479 	235:  uint8(0x80),
  45480 	236:  uint8(0x80),
  45481 	237:  uint8(0x80),
  45482 	238:  uint8(0x80),
  45483 	239:  uint8(0x80),
  45484 	240:  uint8(0x80),
  45485 	241:  uint8(0x80),
  45486 	242:  uint8(0x80),
  45487 	243:  uint8(0x80),
  45488 	244:  uint8(0x80),
  45489 	245:  uint8(0x80),
  45490 	246:  uint8(0x80),
  45491 	247:  uint8(0x80),
  45492 	248:  uint8(0x80),
  45493 	249:  uint8(0x80),
  45494 	250:  uint8(0x80),
  45495 	251:  uint8(0x80),
  45496 	252:  uint8(0x80),
  45497 	253:  uint8(0x80),
  45498 	254:  uint8(0x80),
  45499 	255:  uint8(0x80),
  45500 	256:  uint8(0x80),
  45501 	257:  uint8(0x80),
  45502 	258:  uint8(0x80),
  45503 	259:  uint8(0x80),
  45504 	260:  uint8(0x80),
  45505 	261:  uint8(0x80),
  45506 	262:  uint8(0x80),
  45507 	263:  uint8(0x80),
  45508 	264:  uint8(0x80),
  45509 	265:  uint8(0x80),
  45510 	266:  uint8(0x80),
  45511 	267:  uint8(0x80),
  45512 	268:  uint8(0x80),
  45513 	269:  uint8(0x80),
  45514 	270:  uint8(0x80),
  45515 	271:  uint8(0x80),
  45516 	272:  uint8(0x80),
  45517 	273:  uint8(0x80),
  45518 	274:  uint8(0x80),
  45519 	275:  uint8(0x80),
  45520 	276:  uint8(0x80),
  45521 	277:  uint8(0x80),
  45522 	278:  uint8(0x80),
  45523 	279:  uint8(0x80),
  45524 	280:  uint8(0x80),
  45525 	281:  uint8(0x80),
  45526 	282:  uint8(0x80),
  45527 	283:  uint8(0x80),
  45528 	284:  uint8(0x80),
  45529 	285:  uint8(0x80),
  45530 	286:  uint8(0x80),
  45531 	287:  uint8(0x80),
  45532 	288:  uint8(0x80),
  45533 	289:  uint8(0x80),
  45534 	290:  uint8(0x80),
  45535 	291:  uint8(0x80),
  45536 	292:  uint8(0x80),
  45537 	293:  uint8(0x80),
  45538 	294:  uint8(0x80),
  45539 	295:  uint8(0x80),
  45540 	296:  uint8(0x80),
  45541 	297:  uint8(0x80),
  45542 	298:  uint8(0x80),
  45543 	299:  uint8(0x80),
  45544 	300:  uint8(0x80),
  45545 	301:  uint8(0x80),
  45546 	302:  uint8(0x80),
  45547 	303:  uint8(0x80),
  45548 	304:  uint8(0x80),
  45549 	305:  uint8(0x80),
  45550 	306:  uint8(0x80),
  45551 	307:  uint8(0x80),
  45552 	308:  uint8(0x80),
  45553 	309:  uint8(0x80),
  45554 	310:  uint8(0x80),
  45555 	311:  uint8(0x80),
  45556 	312:  uint8(0x80),
  45557 	313:  uint8(0x80),
  45558 	314:  uint8(0x80),
  45559 	315:  uint8(0x80),
  45560 	316:  uint8(0x80),
  45561 	317:  uint8(0x80),
  45562 	318:  uint8(0x80),
  45563 	319:  uint8(0x80),
  45564 	320:  uint8(0x80),
  45565 	321:  uint8(0x80),
  45566 	322:  uint8(0x80),
  45567 	323:  uint8(0x80),
  45568 	324:  uint8(0x80),
  45569 	325:  uint8(0x80),
  45570 	326:  uint8(0x80),
  45571 	327:  uint8(0x80),
  45572 	328:  uint8(0x80),
  45573 	329:  uint8(0x80),
  45574 	330:  uint8(0x80),
  45575 	331:  uint8(0x80),
  45576 	332:  uint8(0x80),
  45577 	333:  uint8(0x80),
  45578 	334:  uint8(0x80),
  45579 	335:  uint8(0x80),
  45580 	336:  uint8(0x80),
  45581 	337:  uint8(0x80),
  45582 	338:  uint8(0x80),
  45583 	339:  uint8(0x80),
  45584 	340:  uint8(0x80),
  45585 	341:  uint8(0x80),
  45586 	342:  uint8(0x80),
  45587 	343:  uint8(0x80),
  45588 	344:  uint8(0x80),
  45589 	345:  uint8(0x80),
  45590 	346:  uint8(0x80),
  45591 	347:  uint8(0x80),
  45592 	348:  uint8(0x80),
  45593 	349:  uint8(0x80),
  45594 	350:  uint8(0x80),
  45595 	351:  uint8(0x80),
  45596 	352:  uint8(0x80),
  45597 	353:  uint8(0x80),
  45598 	354:  uint8(0x80),
  45599 	355:  uint8(0x80),
  45600 	356:  uint8(0x80),
  45601 	357:  uint8(0x80),
  45602 	358:  uint8(0x80),
  45603 	359:  uint8(0x80),
  45604 	360:  uint8(0x80),
  45605 	361:  uint8(0x80),
  45606 	362:  uint8(0x80),
  45607 	363:  uint8(0x80),
  45608 	364:  uint8(0x80),
  45609 	365:  uint8(0x80),
  45610 	366:  uint8(0x80),
  45611 	367:  uint8(0x80),
  45612 	368:  uint8(0x80),
  45613 	369:  uint8(0x80),
  45614 	370:  uint8(0x80),
  45615 	371:  uint8(0x80),
  45616 	372:  uint8(0x80),
  45617 	373:  uint8(0x80),
  45618 	374:  uint8(0x80),
  45619 	375:  uint8(0x80),
  45620 	376:  uint8(0x80),
  45621 	377:  uint8(0x80),
  45622 	378:  uint8(0x80),
  45623 	379:  uint8(0x80),
  45624 	380:  uint8(0x80),
  45625 	381:  uint8(0x80),
  45626 	382:  uint8(0x80),
  45627 	383:  uint8(0x80),
  45628 	384:  uint8(0x80),
  45629 	385:  uint8(0x80),
  45630 	386:  uint8(0x80),
  45631 	387:  uint8(0x80),
  45632 	388:  uint8(0x80),
  45633 	389:  uint8(0x80),
  45634 	390:  uint8(0x80),
  45635 	391:  uint8(0x80),
  45636 	392:  uint8(0x80),
  45637 	393:  uint8(0x80),
  45638 	394:  uint8(0x80),
  45639 	395:  uint8(0x80),
  45640 	396:  uint8(0x80),
  45641 	397:  uint8(0x80),
  45642 	398:  uint8(0x80),
  45643 	399:  uint8(0x80),
  45644 	400:  uint8(0x80),
  45645 	401:  uint8(0x80),
  45646 	402:  uint8(0x80),
  45647 	403:  uint8(0x80),
  45648 	404:  uint8(0x80),
  45649 	405:  uint8(0x80),
  45650 	406:  uint8(0x80),
  45651 	407:  uint8(0x80),
  45652 	408:  uint8(0x80),
  45653 	409:  uint8(0x80),
  45654 	410:  uint8(0x80),
  45655 	411:  uint8(0x80),
  45656 	412:  uint8(0x80),
  45657 	413:  uint8(0x80),
  45658 	414:  uint8(0x80),
  45659 	415:  uint8(0x80),
  45660 	416:  uint8(0x80),
  45661 	417:  uint8(0x80),
  45662 	418:  uint8(0x80),
  45663 	419:  uint8(0x80),
  45664 	420:  uint8(0x80),
  45665 	421:  uint8(0x80),
  45666 	422:  uint8(0x80),
  45667 	423:  uint8(0x80),
  45668 	424:  uint8(0x80),
  45669 	425:  uint8(0x80),
  45670 	426:  uint8(0x80),
  45671 	427:  uint8(0x80),
  45672 	428:  uint8(0x80),
  45673 	429:  uint8(0x80),
  45674 	430:  uint8(0x80),
  45675 	431:  uint8(0x80),
  45676 	432:  uint8(0x80),
  45677 	433:  uint8(0x80),
  45678 	434:  uint8(0x80),
  45679 	435:  uint8(0x80),
  45680 	436:  uint8(0x80),
  45681 	437:  uint8(0x80),
  45682 	438:  uint8(0x80),
  45683 	439:  uint8(0x80),
  45684 	440:  uint8(0x80),
  45685 	441:  uint8(0x80),
  45686 	442:  uint8(0x80),
  45687 	443:  uint8(0x80),
  45688 	444:  uint8(0x80),
  45689 	445:  uint8(0x80),
  45690 	446:  uint8(0x80),
  45691 	447:  uint8(0x80),
  45692 	448:  uint8(0x80),
  45693 	449:  uint8(0x80),
  45694 	450:  uint8(0x80),
  45695 	451:  uint8(0x80),
  45696 	452:  uint8(0x80),
  45697 	453:  uint8(0x80),
  45698 	454:  uint8(0x80),
  45699 	455:  uint8(0x80),
  45700 	456:  uint8(0x80),
  45701 	457:  uint8(0x80),
  45702 	458:  uint8(0x80),
  45703 	459:  uint8(0x80),
  45704 	460:  uint8(0x80),
  45705 	461:  uint8(0x80),
  45706 	462:  uint8(0x80),
  45707 	463:  uint8(0x80),
  45708 	464:  uint8(0x80),
  45709 	465:  uint8(0x80),
  45710 	466:  uint8(0x80),
  45711 	467:  uint8(0x80),
  45712 	468:  uint8(0x80),
  45713 	469:  uint8(0x80),
  45714 	470:  uint8(0x80),
  45715 	471:  uint8(0x80),
  45716 	472:  uint8(0x80),
  45717 	473:  uint8(0x80),
  45718 	474:  uint8(0x80),
  45719 	475:  uint8(0x80),
  45720 	476:  uint8(0x80),
  45721 	477:  uint8(0x80),
  45722 	478:  uint8(0x80),
  45723 	479:  uint8(0x80),
  45724 	480:  uint8(0x80),
  45725 	481:  uint8(0x80),
  45726 	482:  uint8(0x80),
  45727 	483:  uint8(0x80),
  45728 	484:  uint8(0x80),
  45729 	485:  uint8(0x80),
  45730 	486:  uint8(0x80),
  45731 	487:  uint8(0x80),
  45732 	488:  uint8(0x80),
  45733 	489:  uint8(0x80),
  45734 	490:  uint8(0x80),
  45735 	491:  uint8(0x80),
  45736 	492:  uint8(0x80),
  45737 	493:  uint8(0x80),
  45738 	494:  uint8(0x80),
  45739 	495:  uint8(0x80),
  45740 	496:  uint8(0x80),
  45741 	497:  uint8(0x80),
  45742 	498:  uint8(0x80),
  45743 	499:  uint8(0x80),
  45744 	500:  uint8(0x80),
  45745 	501:  uint8(0x80),
  45746 	502:  uint8(0x80),
  45747 	503:  uint8(0x80),
  45748 	504:  uint8(0x80),
  45749 	505:  uint8(0x80),
  45750 	506:  uint8(0x80),
  45751 	507:  uint8(0x80),
  45752 	508:  uint8(0x80),
  45753 	509:  uint8(0x80),
  45754 	510:  uint8(0x80),
  45755 	511:  uint8(0x80),
  45756 	512:  uint8(0x80),
  45757 	513:  uint8(0x80),
  45758 	514:  uint8(0x80),
  45759 	515:  uint8(0x80),
  45760 	516:  uint8(0x80),
  45761 	517:  uint8(0x80),
  45762 	518:  uint8(0x80),
  45763 	519:  uint8(0x80),
  45764 	520:  uint8(0x80),
  45765 	521:  uint8(0x80),
  45766 	522:  uint8(0x80),
  45767 	523:  uint8(0x80),
  45768 	524:  uint8(0x80),
  45769 	525:  uint8(0x80),
  45770 	526:  uint8(0x80),
  45771 	527:  uint8(0x80),
  45772 	528:  uint8(0x80),
  45773 	529:  uint8(0x80),
  45774 	530:  uint8(0x80),
  45775 	531:  uint8(0x80),
  45776 	532:  uint8(0x80),
  45777 	533:  uint8(0x80),
  45778 	534:  uint8(0x80),
  45779 	535:  uint8(0x80),
  45780 	536:  uint8(0x80),
  45781 	537:  uint8(0x80),
  45782 	538:  uint8(0x80),
  45783 	539:  uint8(0x80),
  45784 	540:  uint8(0x80),
  45785 	541:  uint8(0x80),
  45786 	542:  uint8(0x80),
  45787 	543:  uint8(0x80),
  45788 	544:  uint8(0x80),
  45789 	545:  uint8(0x80),
  45790 	546:  uint8(0x80),
  45791 	547:  uint8(0x80),
  45792 	548:  uint8(0x80),
  45793 	549:  uint8(0x80),
  45794 	550:  uint8(0x80),
  45795 	551:  uint8(0x80),
  45796 	552:  uint8(0x80),
  45797 	553:  uint8(0x80),
  45798 	554:  uint8(0x80),
  45799 	555:  uint8(0x80),
  45800 	556:  uint8(0x80),
  45801 	557:  uint8(0x80),
  45802 	558:  uint8(0x80),
  45803 	559:  uint8(0x80),
  45804 	560:  uint8(0x80),
  45805 	561:  uint8(0x80),
  45806 	562:  uint8(0x80),
  45807 	563:  uint8(0x80),
  45808 	564:  uint8(0x80),
  45809 	565:  uint8(0x80),
  45810 	566:  uint8(0x80),
  45811 	567:  uint8(0x80),
  45812 	568:  uint8(0x80),
  45813 	569:  uint8(0x80),
  45814 	570:  uint8(0x80),
  45815 	571:  uint8(0x80),
  45816 	572:  uint8(0x80),
  45817 	573:  uint8(0x80),
  45818 	574:  uint8(0x80),
  45819 	575:  uint8(0x80),
  45820 	576:  uint8(0x80),
  45821 	577:  uint8(0x80),
  45822 	578:  uint8(0x80),
  45823 	579:  uint8(0x80),
  45824 	580:  uint8(0x80),
  45825 	581:  uint8(0x80),
  45826 	582:  uint8(0x80),
  45827 	583:  uint8(0x80),
  45828 	584:  uint8(0x80),
  45829 	585:  uint8(0x80),
  45830 	586:  uint8(0x80),
  45831 	587:  uint8(0x80),
  45832 	588:  uint8(0x80),
  45833 	589:  uint8(0x80),
  45834 	590:  uint8(0x80),
  45835 	591:  uint8(0x80),
  45836 	592:  uint8(0x80),
  45837 	593:  uint8(0x80),
  45838 	594:  uint8(0x80),
  45839 	595:  uint8(0x80),
  45840 	596:  uint8(0x80),
  45841 	597:  uint8(0x80),
  45842 	598:  uint8(0x80),
  45843 	599:  uint8(0x80),
  45844 	600:  uint8(0x80),
  45845 	601:  uint8(0x80),
  45846 	602:  uint8(0x80),
  45847 	603:  uint8(0x80),
  45848 	604:  uint8(0x80),
  45849 	605:  uint8(0x80),
  45850 	606:  uint8(0x80),
  45851 	607:  uint8(0x80),
  45852 	608:  uint8(0x80),
  45853 	609:  uint8(0x80),
  45854 	610:  uint8(0x80),
  45855 	611:  uint8(0x80),
  45856 	612:  uint8(0x80),
  45857 	613:  uint8(0x80),
  45858 	614:  uint8(0x80),
  45859 	615:  uint8(0x80),
  45860 	616:  uint8(0x80),
  45861 	617:  uint8(0x80),
  45862 	618:  uint8(0x80),
  45863 	619:  uint8(0x80),
  45864 	620:  uint8(0x80),
  45865 	621:  uint8(0x80),
  45866 	622:  uint8(0x80),
  45867 	623:  uint8(0x80),
  45868 	624:  uint8(0x80),
  45869 	625:  uint8(0x80),
  45870 	626:  uint8(0x80),
  45871 	627:  uint8(0x80),
  45872 	628:  uint8(0x80),
  45873 	629:  uint8(0x80),
  45874 	630:  uint8(0x80),
  45875 	631:  uint8(0x80),
  45876 	632:  uint8(0x80),
  45877 	633:  uint8(0x80),
  45878 	634:  uint8(0x80),
  45879 	635:  uint8(0x80),
  45880 	636:  uint8(0x80),
  45881 	637:  uint8(0x80),
  45882 	638:  uint8(0x80),
  45883 	639:  uint8(0x80),
  45884 	640:  uint8(0x80),
  45885 	641:  uint8(0x80),
  45886 	642:  uint8(0x80),
  45887 	643:  uint8(0x80),
  45888 	644:  uint8(0x80),
  45889 	645:  uint8(0x80),
  45890 	646:  uint8(0x80),
  45891 	647:  uint8(0x80),
  45892 	648:  uint8(0x80),
  45893 	649:  uint8(0x80),
  45894 	650:  uint8(0x80),
  45895 	651:  uint8(0x80),
  45896 	652:  uint8(0x80),
  45897 	653:  uint8(0x80),
  45898 	654:  uint8(0x80),
  45899 	655:  uint8(0x80),
  45900 	656:  uint8(0x80),
  45901 	657:  uint8(0x80),
  45902 	658:  uint8(0x80),
  45903 	659:  uint8(0x80),
  45904 	660:  uint8(0x80),
  45905 	661:  uint8(0x80),
  45906 	662:  uint8(0x80),
  45907 	663:  uint8(0x80),
  45908 	664:  uint8(0x80),
  45909 	665:  uint8(0x80),
  45910 	666:  uint8(0x80),
  45911 	667:  uint8(0x80),
  45912 	668:  uint8(0x80),
  45913 	669:  uint8(0x80),
  45914 	670:  uint8(0x80),
  45915 	671:  uint8(0x80),
  45916 	672:  uint8(0x80),
  45917 	673:  uint8(0x80),
  45918 	674:  uint8(0x80),
  45919 	675:  uint8(0x80),
  45920 	676:  uint8(0x80),
  45921 	677:  uint8(0x80),
  45922 	678:  uint8(0x80),
  45923 	679:  uint8(0x80),
  45924 	680:  uint8(0x80),
  45925 	681:  uint8(0x80),
  45926 	682:  uint8(0x80),
  45927 	683:  uint8(0x80),
  45928 	684:  uint8(0x80),
  45929 	685:  uint8(0x80),
  45930 	686:  uint8(0x80),
  45931 	687:  uint8(0x80),
  45932 	688:  uint8(0x80),
  45933 	689:  uint8(0x80),
  45934 	690:  uint8(0x80),
  45935 	691:  uint8(0x80),
  45936 	692:  uint8(0x80),
  45937 	693:  uint8(0x80),
  45938 	694:  uint8(0x80),
  45939 	695:  uint8(0x80),
  45940 	696:  uint8(0x80),
  45941 	697:  uint8(0x80),
  45942 	698:  uint8(0x80),
  45943 	699:  uint8(0x80),
  45944 	700:  uint8(0x80),
  45945 	701:  uint8(0x80),
  45946 	702:  uint8(0x80),
  45947 	703:  uint8(0x80),
  45948 	704:  uint8(0x80),
  45949 	705:  uint8(0x80),
  45950 	706:  uint8(0x80),
  45951 	707:  uint8(0x80),
  45952 	708:  uint8(0x80),
  45953 	709:  uint8(0x80),
  45954 	710:  uint8(0x80),
  45955 	711:  uint8(0x80),
  45956 	712:  uint8(0x80),
  45957 	713:  uint8(0x80),
  45958 	714:  uint8(0x80),
  45959 	715:  uint8(0x80),
  45960 	716:  uint8(0x80),
  45961 	717:  uint8(0x80),
  45962 	718:  uint8(0x80),
  45963 	719:  uint8(0x80),
  45964 	720:  uint8(0x80),
  45965 	721:  uint8(0x80),
  45966 	722:  uint8(0x80),
  45967 	723:  uint8(0x80),
  45968 	724:  uint8(0x80),
  45969 	725:  uint8(0x80),
  45970 	726:  uint8(0x80),
  45971 	727:  uint8(0x80),
  45972 	728:  uint8(0x80),
  45973 	729:  uint8(0x80),
  45974 	730:  uint8(0x80),
  45975 	731:  uint8(0x80),
  45976 	732:  uint8(0x80),
  45977 	733:  uint8(0x80),
  45978 	734:  uint8(0x80),
  45979 	735:  uint8(0x80),
  45980 	736:  uint8(0x80),
  45981 	737:  uint8(0x80),
  45982 	738:  uint8(0x80),
  45983 	739:  uint8(0x80),
  45984 	740:  uint8(0x80),
  45985 	741:  uint8(0x80),
  45986 	742:  uint8(0x80),
  45987 	743:  uint8(0x80),
  45988 	744:  uint8(0x80),
  45989 	745:  uint8(0x80),
  45990 	746:  uint8(0x80),
  45991 	747:  uint8(0x80),
  45992 	748:  uint8(0x80),
  45993 	749:  uint8(0x80),
  45994 	750:  uint8(0x80),
  45995 	751:  uint8(0x80),
  45996 	752:  uint8(0x80),
  45997 	753:  uint8(0x80),
  45998 	754:  uint8(0x80),
  45999 	755:  uint8(0x80),
  46000 	756:  uint8(0x80),
  46001 	757:  uint8(0x80),
  46002 	758:  uint8(0x80),
  46003 	759:  uint8(0x80),
  46004 	760:  uint8(0x80),
  46005 	761:  uint8(0x80),
  46006 	762:  uint8(0x80),
  46007 	763:  uint8(0x80),
  46008 	764:  uint8(0x80),
  46009 	765:  uint8(0x80),
  46010 	766:  uint8(0x80),
  46011 	767:  uint8(0x80),
  46012 	768:  uint8(0x80),
  46013 	769:  uint8(0x80),
  46014 	770:  uint8(0x80),
  46015 	771:  uint8(0x80),
  46016 	772:  uint8(0x80),
  46017 	773:  uint8(0x80),
  46018 	774:  uint8(0x80),
  46019 	775:  uint8(0x80),
  46020 	776:  uint8(0x80),
  46021 	777:  uint8(0x80),
  46022 	778:  uint8(0x80),
  46023 	779:  uint8(0x80),
  46024 	780:  uint8(0x80),
  46025 	781:  uint8(0x80),
  46026 	782:  uint8(0x80),
  46027 	783:  uint8(0x80),
  46028 	784:  uint8(0x80),
  46029 	785:  uint8(0x80),
  46030 	786:  uint8(0x80),
  46031 	787:  uint8(0x80),
  46032 	788:  uint8(0x80),
  46033 	789:  uint8(0x80),
  46034 	790:  uint8(0x80),
  46035 	791:  uint8(0x80),
  46036 	792:  uint8(0x80),
  46037 	793:  uint8(0x80),
  46038 	794:  uint8(0x80),
  46039 	795:  uint8(0x80),
  46040 	796:  uint8(0x80),
  46041 	797:  uint8(0x80),
  46042 	798:  uint8(0x80),
  46043 	799:  uint8(0x80),
  46044 	800:  uint8(0x80),
  46045 	801:  uint8(0x80),
  46046 	802:  uint8(0x80),
  46047 	803:  uint8(0x80),
  46048 	804:  uint8(0x80),
  46049 	805:  uint8(0x80),
  46050 	806:  uint8(0x80),
  46051 	807:  uint8(0x80),
  46052 	808:  uint8(0x80),
  46053 	809:  uint8(0x80),
  46054 	810:  uint8(0x80),
  46055 	811:  uint8(0x80),
  46056 	812:  uint8(0x80),
  46057 	813:  uint8(0x80),
  46058 	814:  uint8(0x80),
  46059 	815:  uint8(0x80),
  46060 	816:  uint8(0x80),
  46061 	817:  uint8(0x80),
  46062 	818:  uint8(0x80),
  46063 	819:  uint8(0x80),
  46064 	820:  uint8(0x80),
  46065 	821:  uint8(0x80),
  46066 	822:  uint8(0x80),
  46067 	823:  uint8(0x80),
  46068 	824:  uint8(0x80),
  46069 	825:  uint8(0x80),
  46070 	826:  uint8(0x80),
  46071 	827:  uint8(0x80),
  46072 	828:  uint8(0x80),
  46073 	829:  uint8(0x80),
  46074 	830:  uint8(0x80),
  46075 	831:  uint8(0x80),
  46076 	832:  uint8(0x80),
  46077 	833:  uint8(0x80),
  46078 	834:  uint8(0x80),
  46079 	835:  uint8(0x80),
  46080 	836:  uint8(0x80),
  46081 	837:  uint8(0x80),
  46082 	838:  uint8(0x80),
  46083 	839:  uint8(0x80),
  46084 	840:  uint8(0x80),
  46085 	841:  uint8(0x80),
  46086 	842:  uint8(0x80),
  46087 	843:  uint8(0x80),
  46088 	844:  uint8(0x80),
  46089 	845:  uint8(0x80),
  46090 	846:  uint8(0x80),
  46091 	847:  uint8(0x80),
  46092 	848:  uint8(0x80),
  46093 	849:  uint8(0x80),
  46094 	850:  uint8(0x80),
  46095 	851:  uint8(0x80),
  46096 	852:  uint8(0x80),
  46097 	853:  uint8(0x80),
  46098 	854:  uint8(0x80),
  46099 	855:  uint8(0x80),
  46100 	856:  uint8(0x80),
  46101 	857:  uint8(0x80),
  46102 	858:  uint8(0x80),
  46103 	859:  uint8(0x80),
  46104 	860:  uint8(0x80),
  46105 	861:  uint8(0x80),
  46106 	862:  uint8(0x80),
  46107 	863:  uint8(0x80),
  46108 	864:  uint8(0x80),
  46109 	865:  uint8(0x80),
  46110 	866:  uint8(0x80),
  46111 	867:  uint8(0x80),
  46112 	868:  uint8(0x80),
  46113 	869:  uint8(0x80),
  46114 	870:  uint8(0x80),
  46115 	871:  uint8(0x80),
  46116 	872:  uint8(0x80),
  46117 	873:  uint8(0x80),
  46118 	874:  uint8(0x80),
  46119 	875:  uint8(0x80),
  46120 	876:  uint8(0x80),
  46121 	877:  uint8(0x80),
  46122 	878:  uint8(0x80),
  46123 	879:  uint8(0x80),
  46124 	880:  uint8(0x80),
  46125 	881:  uint8(0x80),
  46126 	882:  uint8(0x80),
  46127 	883:  uint8(0x80),
  46128 	884:  uint8(0x80),
  46129 	885:  uint8(0x80),
  46130 	886:  uint8(0x80),
  46131 	887:  uint8(0x80),
  46132 	888:  uint8(0x80),
  46133 	889:  uint8(0x80),
  46134 	890:  uint8(0x80),
  46135 	891:  uint8(0x80),
  46136 	892:  uint8(0x80),
  46137 	893:  uint8(0x81),
  46138 	894:  uint8(0x82),
  46139 	895:  uint8(0x83),
  46140 	896:  uint8(0x84),
  46141 	897:  uint8(0x85),
  46142 	898:  uint8(0x86),
  46143 	899:  uint8(0x87),
  46144 	900:  uint8(0x88),
  46145 	901:  uint8(0x89),
  46146 	902:  uint8(0x8a),
  46147 	903:  uint8(0x8b),
  46148 	904:  uint8(0x8c),
  46149 	905:  uint8(0x8d),
  46150 	906:  uint8(0x8e),
  46151 	907:  uint8(0x8f),
  46152 	908:  uint8(0x90),
  46153 	909:  uint8(0x91),
  46154 	910:  uint8(0x92),
  46155 	911:  uint8(0x93),
  46156 	912:  uint8(0x94),
  46157 	913:  uint8(0x95),
  46158 	914:  uint8(0x96),
  46159 	915:  uint8(0x97),
  46160 	916:  uint8(0x98),
  46161 	917:  uint8(0x99),
  46162 	918:  uint8(0x9a),
  46163 	919:  uint8(0x9b),
  46164 	920:  uint8(0x9c),
  46165 	921:  uint8(0x9d),
  46166 	922:  uint8(0x9e),
  46167 	923:  uint8(0x9f),
  46168 	924:  uint8(0xa0),
  46169 	925:  uint8(0xa1),
  46170 	926:  uint8(0xa2),
  46171 	927:  uint8(0xa3),
  46172 	928:  uint8(0xa4),
  46173 	929:  uint8(0xa5),
  46174 	930:  uint8(0xa6),
  46175 	931:  uint8(0xa7),
  46176 	932:  uint8(0xa8),
  46177 	933:  uint8(0xa9),
  46178 	934:  uint8(0xaa),
  46179 	935:  uint8(0xab),
  46180 	936:  uint8(0xac),
  46181 	937:  uint8(0xad),
  46182 	938:  uint8(0xae),
  46183 	939:  uint8(0xaf),
  46184 	940:  uint8(0xb0),
  46185 	941:  uint8(0xb1),
  46186 	942:  uint8(0xb2),
  46187 	943:  uint8(0xb3),
  46188 	944:  uint8(0xb4),
  46189 	945:  uint8(0xb5),
  46190 	946:  uint8(0xb6),
  46191 	947:  uint8(0xb7),
  46192 	948:  uint8(0xb8),
  46193 	949:  uint8(0xb9),
  46194 	950:  uint8(0xba),
  46195 	951:  uint8(0xbb),
  46196 	952:  uint8(0xbc),
  46197 	953:  uint8(0xbd),
  46198 	954:  uint8(0xbe),
  46199 	955:  uint8(0xbf),
  46200 	956:  uint8(0xc0),
  46201 	957:  uint8(0xc1),
  46202 	958:  uint8(0xc2),
  46203 	959:  uint8(0xc3),
  46204 	960:  uint8(0xc4),
  46205 	961:  uint8(0xc5),
  46206 	962:  uint8(0xc6),
  46207 	963:  uint8(0xc7),
  46208 	964:  uint8(0xc8),
  46209 	965:  uint8(0xc9),
  46210 	966:  uint8(0xca),
  46211 	967:  uint8(0xcb),
  46212 	968:  uint8(0xcc),
  46213 	969:  uint8(0xcd),
  46214 	970:  uint8(0xce),
  46215 	971:  uint8(0xcf),
  46216 	972:  uint8(0xd0),
  46217 	973:  uint8(0xd1),
  46218 	974:  uint8(0xd2),
  46219 	975:  uint8(0xd3),
  46220 	976:  uint8(0xd4),
  46221 	977:  uint8(0xd5),
  46222 	978:  uint8(0xd6),
  46223 	979:  uint8(0xd7),
  46224 	980:  uint8(0xd8),
  46225 	981:  uint8(0xd9),
  46226 	982:  uint8(0xda),
  46227 	983:  uint8(0xdb),
  46228 	984:  uint8(0xdc),
  46229 	985:  uint8(0xdd),
  46230 	986:  uint8(0xde),
  46231 	987:  uint8(0xdf),
  46232 	988:  uint8(0xe0),
  46233 	989:  uint8(0xe1),
  46234 	990:  uint8(0xe2),
  46235 	991:  uint8(0xe3),
  46236 	992:  uint8(0xe4),
  46237 	993:  uint8(0xe5),
  46238 	994:  uint8(0xe6),
  46239 	995:  uint8(0xe7),
  46240 	996:  uint8(0xe8),
  46241 	997:  uint8(0xe9),
  46242 	998:  uint8(0xea),
  46243 	999:  uint8(0xeb),
  46244 	1000: uint8(0xec),
  46245 	1001: uint8(0xed),
  46246 	1002: uint8(0xee),
  46247 	1003: uint8(0xef),
  46248 	1004: uint8(0xf0),
  46249 	1005: uint8(0xf1),
  46250 	1006: uint8(0xf2),
  46251 	1007: uint8(0xf3),
  46252 	1008: uint8(0xf4),
  46253 	1009: uint8(0xf5),
  46254 	1010: uint8(0xf6),
  46255 	1011: uint8(0xf7),
  46256 	1012: uint8(0xf8),
  46257 	1013: uint8(0xf9),
  46258 	1014: uint8(0xfa),
  46259 	1015: uint8(0xfb),
  46260 	1016: uint8(0xfc),
  46261 	1017: uint8(0xfd),
  46262 	1018: uint8(0xfe),
  46263 	1019: uint8(0xff),
  46264 	1021: uint8(0x01),
  46265 	1022: uint8(0x02),
  46266 	1023: uint8(0x03),
  46267 	1024: uint8(0x04),
  46268 	1025: uint8(0x05),
  46269 	1026: uint8(0x06),
  46270 	1027: uint8(0x07),
  46271 	1028: uint8(0x08),
  46272 	1029: uint8(0x09),
  46273 	1030: uint8(0x0a),
  46274 	1031: uint8(0x0b),
  46275 	1032: uint8(0x0c),
  46276 	1033: uint8(0x0d),
  46277 	1034: uint8(0x0e),
  46278 	1035: uint8(0x0f),
  46279 	1036: uint8(0x10),
  46280 	1037: uint8(0x11),
  46281 	1038: uint8(0x12),
  46282 	1039: uint8(0x13),
  46283 	1040: uint8(0x14),
  46284 	1041: uint8(0x15),
  46285 	1042: uint8(0x16),
  46286 	1043: uint8(0x17),
  46287 	1044: uint8(0x18),
  46288 	1045: uint8(0x19),
  46289 	1046: uint8(0x1a),
  46290 	1047: uint8(0x1b),
  46291 	1048: uint8(0x1c),
  46292 	1049: uint8(0x1d),
  46293 	1050: uint8(0x1e),
  46294 	1051: uint8(0x1f),
  46295 	1052: uint8(0x20),
  46296 	1053: uint8(0x21),
  46297 	1054: uint8(0x22),
  46298 	1055: uint8(0x23),
  46299 	1056: uint8(0x24),
  46300 	1057: uint8(0x25),
  46301 	1058: uint8(0x26),
  46302 	1059: uint8(0x27),
  46303 	1060: uint8(0x28),
  46304 	1061: uint8(0x29),
  46305 	1062: uint8(0x2a),
  46306 	1063: uint8(0x2b),
  46307 	1064: uint8(0x2c),
  46308 	1065: uint8(0x2d),
  46309 	1066: uint8(0x2e),
  46310 	1067: uint8(0x2f),
  46311 	1068: uint8(0x30),
  46312 	1069: uint8(0x31),
  46313 	1070: uint8(0x32),
  46314 	1071: uint8(0x33),
  46315 	1072: uint8(0x34),
  46316 	1073: uint8(0x35),
  46317 	1074: uint8(0x36),
  46318 	1075: uint8(0x37),
  46319 	1076: uint8(0x38),
  46320 	1077: uint8(0x39),
  46321 	1078: uint8(0x3a),
  46322 	1079: uint8(0x3b),
  46323 	1080: uint8(0x3c),
  46324 	1081: uint8(0x3d),
  46325 	1082: uint8(0x3e),
  46326 	1083: uint8(0x3f),
  46327 	1084: uint8(0x40),
  46328 	1085: uint8(0x41),
  46329 	1086: uint8(0x42),
  46330 	1087: uint8(0x43),
  46331 	1088: uint8(0x44),
  46332 	1089: uint8(0x45),
  46333 	1090: uint8(0x46),
  46334 	1091: uint8(0x47),
  46335 	1092: uint8(0x48),
  46336 	1093: uint8(0x49),
  46337 	1094: uint8(0x4a),
  46338 	1095: uint8(0x4b),
  46339 	1096: uint8(0x4c),
  46340 	1097: uint8(0x4d),
  46341 	1098: uint8(0x4e),
  46342 	1099: uint8(0x4f),
  46343 	1100: uint8(0x50),
  46344 	1101: uint8(0x51),
  46345 	1102: uint8(0x52),
  46346 	1103: uint8(0x53),
  46347 	1104: uint8(0x54),
  46348 	1105: uint8(0x55),
  46349 	1106: uint8(0x56),
  46350 	1107: uint8(0x57),
  46351 	1108: uint8(0x58),
  46352 	1109: uint8(0x59),
  46353 	1110: uint8(0x5a),
  46354 	1111: uint8(0x5b),
  46355 	1112: uint8(0x5c),
  46356 	1113: uint8(0x5d),
  46357 	1114: uint8(0x5e),
  46358 	1115: uint8(0x5f),
  46359 	1116: uint8(0x60),
  46360 	1117: uint8(0x61),
  46361 	1118: uint8(0x62),
  46362 	1119: uint8(0x63),
  46363 	1120: uint8(0x64),
  46364 	1121: uint8(0x65),
  46365 	1122: uint8(0x66),
  46366 	1123: uint8(0x67),
  46367 	1124: uint8(0x68),
  46368 	1125: uint8(0x69),
  46369 	1126: uint8(0x6a),
  46370 	1127: uint8(0x6b),
  46371 	1128: uint8(0x6c),
  46372 	1129: uint8(0x6d),
  46373 	1130: uint8(0x6e),
  46374 	1131: uint8(0x6f),
  46375 	1132: uint8(0x70),
  46376 	1133: uint8(0x71),
  46377 	1134: uint8(0x72),
  46378 	1135: uint8(0x73),
  46379 	1136: uint8(0x74),
  46380 	1137: uint8(0x75),
  46381 	1138: uint8(0x76),
  46382 	1139: uint8(0x77),
  46383 	1140: uint8(0x78),
  46384 	1141: uint8(0x79),
  46385 	1142: uint8(0x7a),
  46386 	1143: uint8(0x7b),
  46387 	1144: uint8(0x7c),
  46388 	1145: uint8(0x7d),
  46389 	1146: uint8(0x7e),
  46390 	1147: uint8(0x7f),
  46391 	1148: uint8(0x7f),
  46392 	1149: uint8(0x7f),
  46393 	1150: uint8(0x7f),
  46394 	1151: uint8(0x7f),
  46395 	1152: uint8(0x7f),
  46396 	1153: uint8(0x7f),
  46397 	1154: uint8(0x7f),
  46398 	1155: uint8(0x7f),
  46399 	1156: uint8(0x7f),
  46400 	1157: uint8(0x7f),
  46401 	1158: uint8(0x7f),
  46402 	1159: uint8(0x7f),
  46403 	1160: uint8(0x7f),
  46404 	1161: uint8(0x7f),
  46405 	1162: uint8(0x7f),
  46406 	1163: uint8(0x7f),
  46407 	1164: uint8(0x7f),
  46408 	1165: uint8(0x7f),
  46409 	1166: uint8(0x7f),
  46410 	1167: uint8(0x7f),
  46411 	1168: uint8(0x7f),
  46412 	1169: uint8(0x7f),
  46413 	1170: uint8(0x7f),
  46414 	1171: uint8(0x7f),
  46415 	1172: uint8(0x7f),
  46416 	1173: uint8(0x7f),
  46417 	1174: uint8(0x7f),
  46418 	1175: uint8(0x7f),
  46419 	1176: uint8(0x7f),
  46420 	1177: uint8(0x7f),
  46421 	1178: uint8(0x7f),
  46422 	1179: uint8(0x7f),
  46423 	1180: uint8(0x7f),
  46424 	1181: uint8(0x7f),
  46425 	1182: uint8(0x7f),
  46426 	1183: uint8(0x7f),
  46427 	1184: uint8(0x7f),
  46428 	1185: uint8(0x7f),
  46429 	1186: uint8(0x7f),
  46430 	1187: uint8(0x7f),
  46431 	1188: uint8(0x7f),
  46432 	1189: uint8(0x7f),
  46433 	1190: uint8(0x7f),
  46434 	1191: uint8(0x7f),
  46435 	1192: uint8(0x7f),
  46436 	1193: uint8(0x7f),
  46437 	1194: uint8(0x7f),
  46438 	1195: uint8(0x7f),
  46439 	1196: uint8(0x7f),
  46440 	1197: uint8(0x7f),
  46441 	1198: uint8(0x7f),
  46442 	1199: uint8(0x7f),
  46443 	1200: uint8(0x7f),
  46444 	1201: uint8(0x7f),
  46445 	1202: uint8(0x7f),
  46446 	1203: uint8(0x7f),
  46447 	1204: uint8(0x7f),
  46448 	1205: uint8(0x7f),
  46449 	1206: uint8(0x7f),
  46450 	1207: uint8(0x7f),
  46451 	1208: uint8(0x7f),
  46452 	1209: uint8(0x7f),
  46453 	1210: uint8(0x7f),
  46454 	1211: uint8(0x7f),
  46455 	1212: uint8(0x7f),
  46456 	1213: uint8(0x7f),
  46457 	1214: uint8(0x7f),
  46458 	1215: uint8(0x7f),
  46459 	1216: uint8(0x7f),
  46460 	1217: uint8(0x7f),
  46461 	1218: uint8(0x7f),
  46462 	1219: uint8(0x7f),
  46463 	1220: uint8(0x7f),
  46464 	1221: uint8(0x7f),
  46465 	1222: uint8(0x7f),
  46466 	1223: uint8(0x7f),
  46467 	1224: uint8(0x7f),
  46468 	1225: uint8(0x7f),
  46469 	1226: uint8(0x7f),
  46470 	1227: uint8(0x7f),
  46471 	1228: uint8(0x7f),
  46472 	1229: uint8(0x7f),
  46473 	1230: uint8(0x7f),
  46474 	1231: uint8(0x7f),
  46475 	1232: uint8(0x7f),
  46476 	1233: uint8(0x7f),
  46477 	1234: uint8(0x7f),
  46478 	1235: uint8(0x7f),
  46479 	1236: uint8(0x7f),
  46480 	1237: uint8(0x7f),
  46481 	1238: uint8(0x7f),
  46482 	1239: uint8(0x7f),
  46483 	1240: uint8(0x7f),
  46484 	1241: uint8(0x7f),
  46485 	1242: uint8(0x7f),
  46486 	1243: uint8(0x7f),
  46487 	1244: uint8(0x7f),
  46488 	1245: uint8(0x7f),
  46489 	1246: uint8(0x7f),
  46490 	1247: uint8(0x7f),
  46491 	1248: uint8(0x7f),
  46492 	1249: uint8(0x7f),
  46493 	1250: uint8(0x7f),
  46494 	1251: uint8(0x7f),
  46495 	1252: uint8(0x7f),
  46496 	1253: uint8(0x7f),
  46497 	1254: uint8(0x7f),
  46498 	1255: uint8(0x7f),
  46499 	1256: uint8(0x7f),
  46500 	1257: uint8(0x7f),
  46501 	1258: uint8(0x7f),
  46502 	1259: uint8(0x7f),
  46503 	1260: uint8(0x7f),
  46504 	1261: uint8(0x7f),
  46505 	1262: uint8(0x7f),
  46506 	1263: uint8(0x7f),
  46507 	1264: uint8(0x7f),
  46508 	1265: uint8(0x7f),
  46509 	1266: uint8(0x7f),
  46510 	1267: uint8(0x7f),
  46511 	1268: uint8(0x7f),
  46512 	1269: uint8(0x7f),
  46513 	1270: uint8(0x7f),
  46514 	1271: uint8(0x7f),
  46515 	1272: uint8(0x7f),
  46516 	1273: uint8(0x7f),
  46517 	1274: uint8(0x7f),
  46518 	1275: uint8(0x7f),
  46519 	1276: uint8(0x7f),
  46520 	1277: uint8(0x7f),
  46521 	1278: uint8(0x7f),
  46522 	1279: uint8(0x7f),
  46523 	1280: uint8(0x7f),
  46524 	1281: uint8(0x7f),
  46525 	1282: uint8(0x7f),
  46526 	1283: uint8(0x7f),
  46527 	1284: uint8(0x7f),
  46528 	1285: uint8(0x7f),
  46529 	1286: uint8(0x7f),
  46530 	1287: uint8(0x7f),
  46531 	1288: uint8(0x7f),
  46532 	1289: uint8(0x7f),
  46533 	1290: uint8(0x7f),
  46534 	1291: uint8(0x7f),
  46535 	1292: uint8(0x7f),
  46536 	1293: uint8(0x7f),
  46537 	1294: uint8(0x7f),
  46538 	1295: uint8(0x7f),
  46539 	1296: uint8(0x7f),
  46540 	1297: uint8(0x7f),
  46541 	1298: uint8(0x7f),
  46542 	1299: uint8(0x7f),
  46543 	1300: uint8(0x7f),
  46544 	1301: uint8(0x7f),
  46545 	1302: uint8(0x7f),
  46546 	1303: uint8(0x7f),
  46547 	1304: uint8(0x7f),
  46548 	1305: uint8(0x7f),
  46549 	1306: uint8(0x7f),
  46550 	1307: uint8(0x7f),
  46551 	1308: uint8(0x7f),
  46552 	1309: uint8(0x7f),
  46553 	1310: uint8(0x7f),
  46554 	1311: uint8(0x7f),
  46555 	1312: uint8(0x7f),
  46556 	1313: uint8(0x7f),
  46557 	1314: uint8(0x7f),
  46558 	1315: uint8(0x7f),
  46559 	1316: uint8(0x7f),
  46560 	1317: uint8(0x7f),
  46561 	1318: uint8(0x7f),
  46562 	1319: uint8(0x7f),
  46563 	1320: uint8(0x7f),
  46564 	1321: uint8(0x7f),
  46565 	1322: uint8(0x7f),
  46566 	1323: uint8(0x7f),
  46567 	1324: uint8(0x7f),
  46568 	1325: uint8(0x7f),
  46569 	1326: uint8(0x7f),
  46570 	1327: uint8(0x7f),
  46571 	1328: uint8(0x7f),
  46572 	1329: uint8(0x7f),
  46573 	1330: uint8(0x7f),
  46574 	1331: uint8(0x7f),
  46575 	1332: uint8(0x7f),
  46576 	1333: uint8(0x7f),
  46577 	1334: uint8(0x7f),
  46578 	1335: uint8(0x7f),
  46579 	1336: uint8(0x7f),
  46580 	1337: uint8(0x7f),
  46581 	1338: uint8(0x7f),
  46582 	1339: uint8(0x7f),
  46583 	1340: uint8(0x7f),
  46584 	1341: uint8(0x7f),
  46585 	1342: uint8(0x7f),
  46586 	1343: uint8(0x7f),
  46587 	1344: uint8(0x7f),
  46588 	1345: uint8(0x7f),
  46589 	1346: uint8(0x7f),
  46590 	1347: uint8(0x7f),
  46591 	1348: uint8(0x7f),
  46592 	1349: uint8(0x7f),
  46593 	1350: uint8(0x7f),
  46594 	1351: uint8(0x7f),
  46595 	1352: uint8(0x7f),
  46596 	1353: uint8(0x7f),
  46597 	1354: uint8(0x7f),
  46598 	1355: uint8(0x7f),
  46599 	1356: uint8(0x7f),
  46600 	1357: uint8(0x7f),
  46601 	1358: uint8(0x7f),
  46602 	1359: uint8(0x7f),
  46603 	1360: uint8(0x7f),
  46604 	1361: uint8(0x7f),
  46605 	1362: uint8(0x7f),
  46606 	1363: uint8(0x7f),
  46607 	1364: uint8(0x7f),
  46608 	1365: uint8(0x7f),
  46609 	1366: uint8(0x7f),
  46610 	1367: uint8(0x7f),
  46611 	1368: uint8(0x7f),
  46612 	1369: uint8(0x7f),
  46613 	1370: uint8(0x7f),
  46614 	1371: uint8(0x7f),
  46615 	1372: uint8(0x7f),
  46616 	1373: uint8(0x7f),
  46617 	1374: uint8(0x7f),
  46618 	1375: uint8(0x7f),
  46619 	1376: uint8(0x7f),
  46620 	1377: uint8(0x7f),
  46621 	1378: uint8(0x7f),
  46622 	1379: uint8(0x7f),
  46623 	1380: uint8(0x7f),
  46624 	1381: uint8(0x7f),
  46625 	1382: uint8(0x7f),
  46626 	1383: uint8(0x7f),
  46627 	1384: uint8(0x7f),
  46628 	1385: uint8(0x7f),
  46629 	1386: uint8(0x7f),
  46630 	1387: uint8(0x7f),
  46631 	1388: uint8(0x7f),
  46632 	1389: uint8(0x7f),
  46633 	1390: uint8(0x7f),
  46634 	1391: uint8(0x7f),
  46635 	1392: uint8(0x7f),
  46636 	1393: uint8(0x7f),
  46637 	1394: uint8(0x7f),
  46638 	1395: uint8(0x7f),
  46639 	1396: uint8(0x7f),
  46640 	1397: uint8(0x7f),
  46641 	1398: uint8(0x7f),
  46642 	1399: uint8(0x7f),
  46643 	1400: uint8(0x7f),
  46644 	1401: uint8(0x7f),
  46645 	1402: uint8(0x7f),
  46646 	1403: uint8(0x7f),
  46647 	1404: uint8(0x7f),
  46648 	1405: uint8(0x7f),
  46649 	1406: uint8(0x7f),
  46650 	1407: uint8(0x7f),
  46651 	1408: uint8(0x7f),
  46652 	1409: uint8(0x7f),
  46653 	1410: uint8(0x7f),
  46654 	1411: uint8(0x7f),
  46655 	1412: uint8(0x7f),
  46656 	1413: uint8(0x7f),
  46657 	1414: uint8(0x7f),
  46658 	1415: uint8(0x7f),
  46659 	1416: uint8(0x7f),
  46660 	1417: uint8(0x7f),
  46661 	1418: uint8(0x7f),
  46662 	1419: uint8(0x7f),
  46663 	1420: uint8(0x7f),
  46664 	1421: uint8(0x7f),
  46665 	1422: uint8(0x7f),
  46666 	1423: uint8(0x7f),
  46667 	1424: uint8(0x7f),
  46668 	1425: uint8(0x7f),
  46669 	1426: uint8(0x7f),
  46670 	1427: uint8(0x7f),
  46671 	1428: uint8(0x7f),
  46672 	1429: uint8(0x7f),
  46673 	1430: uint8(0x7f),
  46674 	1431: uint8(0x7f),
  46675 	1432: uint8(0x7f),
  46676 	1433: uint8(0x7f),
  46677 	1434: uint8(0x7f),
  46678 	1435: uint8(0x7f),
  46679 	1436: uint8(0x7f),
  46680 	1437: uint8(0x7f),
  46681 	1438: uint8(0x7f),
  46682 	1439: uint8(0x7f),
  46683 	1440: uint8(0x7f),
  46684 	1441: uint8(0x7f),
  46685 	1442: uint8(0x7f),
  46686 	1443: uint8(0x7f),
  46687 	1444: uint8(0x7f),
  46688 	1445: uint8(0x7f),
  46689 	1446: uint8(0x7f),
  46690 	1447: uint8(0x7f),
  46691 	1448: uint8(0x7f),
  46692 	1449: uint8(0x7f),
  46693 	1450: uint8(0x7f),
  46694 	1451: uint8(0x7f),
  46695 	1452: uint8(0x7f),
  46696 	1453: uint8(0x7f),
  46697 	1454: uint8(0x7f),
  46698 	1455: uint8(0x7f),
  46699 	1456: uint8(0x7f),
  46700 	1457: uint8(0x7f),
  46701 	1458: uint8(0x7f),
  46702 	1459: uint8(0x7f),
  46703 	1460: uint8(0x7f),
  46704 	1461: uint8(0x7f),
  46705 	1462: uint8(0x7f),
  46706 	1463: uint8(0x7f),
  46707 	1464: uint8(0x7f),
  46708 	1465: uint8(0x7f),
  46709 	1466: uint8(0x7f),
  46710 	1467: uint8(0x7f),
  46711 	1468: uint8(0x7f),
  46712 	1469: uint8(0x7f),
  46713 	1470: uint8(0x7f),
  46714 	1471: uint8(0x7f),
  46715 	1472: uint8(0x7f),
  46716 	1473: uint8(0x7f),
  46717 	1474: uint8(0x7f),
  46718 	1475: uint8(0x7f),
  46719 	1476: uint8(0x7f),
  46720 	1477: uint8(0x7f),
  46721 	1478: uint8(0x7f),
  46722 	1479: uint8(0x7f),
  46723 	1480: uint8(0x7f),
  46724 	1481: uint8(0x7f),
  46725 	1482: uint8(0x7f),
  46726 	1483: uint8(0x7f),
  46727 	1484: uint8(0x7f),
  46728 	1485: uint8(0x7f),
  46729 	1486: uint8(0x7f),
  46730 	1487: uint8(0x7f),
  46731 	1488: uint8(0x7f),
  46732 	1489: uint8(0x7f),
  46733 	1490: uint8(0x7f),
  46734 	1491: uint8(0x7f),
  46735 	1492: uint8(0x7f),
  46736 	1493: uint8(0x7f),
  46737 	1494: uint8(0x7f),
  46738 	1495: uint8(0x7f),
  46739 	1496: uint8(0x7f),
  46740 	1497: uint8(0x7f),
  46741 	1498: uint8(0x7f),
  46742 	1499: uint8(0x7f),
  46743 	1500: uint8(0x7f),
  46744 	1501: uint8(0x7f),
  46745 	1502: uint8(0x7f),
  46746 	1503: uint8(0x7f),
  46747 	1504: uint8(0x7f),
  46748 	1505: uint8(0x7f),
  46749 	1506: uint8(0x7f),
  46750 	1507: uint8(0x7f),
  46751 	1508: uint8(0x7f),
  46752 	1509: uint8(0x7f),
  46753 	1510: uint8(0x7f),
  46754 	1511: uint8(0x7f),
  46755 	1512: uint8(0x7f),
  46756 	1513: uint8(0x7f),
  46757 	1514: uint8(0x7f),
  46758 	1515: uint8(0x7f),
  46759 	1516: uint8(0x7f),
  46760 	1517: uint8(0x7f),
  46761 	1518: uint8(0x7f),
  46762 	1519: uint8(0x7f),
  46763 	1520: uint8(0x7f),
  46764 	1521: uint8(0x7f),
  46765 	1522: uint8(0x7f),
  46766 	1523: uint8(0x7f),
  46767 	1524: uint8(0x7f),
  46768 	1525: uint8(0x7f),
  46769 	1526: uint8(0x7f),
  46770 	1527: uint8(0x7f),
  46771 	1528: uint8(0x7f),
  46772 	1529: uint8(0x7f),
  46773 	1530: uint8(0x7f),
  46774 	1531: uint8(0x7f),
  46775 	1532: uint8(0x7f),
  46776 	1533: uint8(0x7f),
  46777 	1534: uint8(0x7f),
  46778 	1535: uint8(0x7f),
  46779 	1536: uint8(0x7f),
  46780 	1537: uint8(0x7f),
  46781 	1538: uint8(0x7f),
  46782 	1539: uint8(0x7f),
  46783 	1540: uint8(0x7f),
  46784 	1541: uint8(0x7f),
  46785 	1542: uint8(0x7f),
  46786 	1543: uint8(0x7f),
  46787 	1544: uint8(0x7f),
  46788 	1545: uint8(0x7f),
  46789 	1546: uint8(0x7f),
  46790 	1547: uint8(0x7f),
  46791 	1548: uint8(0x7f),
  46792 	1549: uint8(0x7f),
  46793 	1550: uint8(0x7f),
  46794 	1551: uint8(0x7f),
  46795 	1552: uint8(0x7f),
  46796 	1553: uint8(0x7f),
  46797 	1554: uint8(0x7f),
  46798 	1555: uint8(0x7f),
  46799 	1556: uint8(0x7f),
  46800 	1557: uint8(0x7f),
  46801 	1558: uint8(0x7f),
  46802 	1559: uint8(0x7f),
  46803 	1560: uint8(0x7f),
  46804 	1561: uint8(0x7f),
  46805 	1562: uint8(0x7f),
  46806 	1563: uint8(0x7f),
  46807 	1564: uint8(0x7f),
  46808 	1565: uint8(0x7f),
  46809 	1566: uint8(0x7f),
  46810 	1567: uint8(0x7f),
  46811 	1568: uint8(0x7f),
  46812 	1569: uint8(0x7f),
  46813 	1570: uint8(0x7f),
  46814 	1571: uint8(0x7f),
  46815 	1572: uint8(0x7f),
  46816 	1573: uint8(0x7f),
  46817 	1574: uint8(0x7f),
  46818 	1575: uint8(0x7f),
  46819 	1576: uint8(0x7f),
  46820 	1577: uint8(0x7f),
  46821 	1578: uint8(0x7f),
  46822 	1579: uint8(0x7f),
  46823 	1580: uint8(0x7f),
  46824 	1581: uint8(0x7f),
  46825 	1582: uint8(0x7f),
  46826 	1583: uint8(0x7f),
  46827 	1584: uint8(0x7f),
  46828 	1585: uint8(0x7f),
  46829 	1586: uint8(0x7f),
  46830 	1587: uint8(0x7f),
  46831 	1588: uint8(0x7f),
  46832 	1589: uint8(0x7f),
  46833 	1590: uint8(0x7f),
  46834 	1591: uint8(0x7f),
  46835 	1592: uint8(0x7f),
  46836 	1593: uint8(0x7f),
  46837 	1594: uint8(0x7f),
  46838 	1595: uint8(0x7f),
  46839 	1596: uint8(0x7f),
  46840 	1597: uint8(0x7f),
  46841 	1598: uint8(0x7f),
  46842 	1599: uint8(0x7f),
  46843 	1600: uint8(0x7f),
  46844 	1601: uint8(0x7f),
  46845 	1602: uint8(0x7f),
  46846 	1603: uint8(0x7f),
  46847 	1604: uint8(0x7f),
  46848 	1605: uint8(0x7f),
  46849 	1606: uint8(0x7f),
  46850 	1607: uint8(0x7f),
  46851 	1608: uint8(0x7f),
  46852 	1609: uint8(0x7f),
  46853 	1610: uint8(0x7f),
  46854 	1611: uint8(0x7f),
  46855 	1612: uint8(0x7f),
  46856 	1613: uint8(0x7f),
  46857 	1614: uint8(0x7f),
  46858 	1615: uint8(0x7f),
  46859 	1616: uint8(0x7f),
  46860 	1617: uint8(0x7f),
  46861 	1618: uint8(0x7f),
  46862 	1619: uint8(0x7f),
  46863 	1620: uint8(0x7f),
  46864 	1621: uint8(0x7f),
  46865 	1622: uint8(0x7f),
  46866 	1623: uint8(0x7f),
  46867 	1624: uint8(0x7f),
  46868 	1625: uint8(0x7f),
  46869 	1626: uint8(0x7f),
  46870 	1627: uint8(0x7f),
  46871 	1628: uint8(0x7f),
  46872 	1629: uint8(0x7f),
  46873 	1630: uint8(0x7f),
  46874 	1631: uint8(0x7f),
  46875 	1632: uint8(0x7f),
  46876 	1633: uint8(0x7f),
  46877 	1634: uint8(0x7f),
  46878 	1635: uint8(0x7f),
  46879 	1636: uint8(0x7f),
  46880 	1637: uint8(0x7f),
  46881 	1638: uint8(0x7f),
  46882 	1639: uint8(0x7f),
  46883 	1640: uint8(0x7f),
  46884 	1641: uint8(0x7f),
  46885 	1642: uint8(0x7f),
  46886 	1643: uint8(0x7f),
  46887 	1644: uint8(0x7f),
  46888 	1645: uint8(0x7f),
  46889 	1646: uint8(0x7f),
  46890 	1647: uint8(0x7f),
  46891 	1648: uint8(0x7f),
  46892 	1649: uint8(0x7f),
  46893 	1650: uint8(0x7f),
  46894 	1651: uint8(0x7f),
  46895 	1652: uint8(0x7f),
  46896 	1653: uint8(0x7f),
  46897 	1654: uint8(0x7f),
  46898 	1655: uint8(0x7f),
  46899 	1656: uint8(0x7f),
  46900 	1657: uint8(0x7f),
  46901 	1658: uint8(0x7f),
  46902 	1659: uint8(0x7f),
  46903 	1660: uint8(0x7f),
  46904 	1661: uint8(0x7f),
  46905 	1662: uint8(0x7f),
  46906 	1663: uint8(0x7f),
  46907 	1664: uint8(0x7f),
  46908 	1665: uint8(0x7f),
  46909 	1666: uint8(0x7f),
  46910 	1667: uint8(0x7f),
  46911 	1668: uint8(0x7f),
  46912 	1669: uint8(0x7f),
  46913 	1670: uint8(0x7f),
  46914 	1671: uint8(0x7f),
  46915 	1672: uint8(0x7f),
  46916 	1673: uint8(0x7f),
  46917 	1674: uint8(0x7f),
  46918 	1675: uint8(0x7f),
  46919 	1676: uint8(0x7f),
  46920 	1677: uint8(0x7f),
  46921 	1678: uint8(0x7f),
  46922 	1679: uint8(0x7f),
  46923 	1680: uint8(0x7f),
  46924 	1681: uint8(0x7f),
  46925 	1682: uint8(0x7f),
  46926 	1683: uint8(0x7f),
  46927 	1684: uint8(0x7f),
  46928 	1685: uint8(0x7f),
  46929 	1686: uint8(0x7f),
  46930 	1687: uint8(0x7f),
  46931 	1688: uint8(0x7f),
  46932 	1689: uint8(0x7f),
  46933 	1690: uint8(0x7f),
  46934 	1691: uint8(0x7f),
  46935 	1692: uint8(0x7f),
  46936 	1693: uint8(0x7f),
  46937 	1694: uint8(0x7f),
  46938 	1695: uint8(0x7f),
  46939 	1696: uint8(0x7f),
  46940 	1697: uint8(0x7f),
  46941 	1698: uint8(0x7f),
  46942 	1699: uint8(0x7f),
  46943 	1700: uint8(0x7f),
  46944 	1701: uint8(0x7f),
  46945 	1702: uint8(0x7f),
  46946 	1703: uint8(0x7f),
  46947 	1704: uint8(0x7f),
  46948 	1705: uint8(0x7f),
  46949 	1706: uint8(0x7f),
  46950 	1707: uint8(0x7f),
  46951 	1708: uint8(0x7f),
  46952 	1709: uint8(0x7f),
  46953 	1710: uint8(0x7f),
  46954 	1711: uint8(0x7f),
  46955 	1712: uint8(0x7f),
  46956 	1713: uint8(0x7f),
  46957 	1714: uint8(0x7f),
  46958 	1715: uint8(0x7f),
  46959 	1716: uint8(0x7f),
  46960 	1717: uint8(0x7f),
  46961 	1718: uint8(0x7f),
  46962 	1719: uint8(0x7f),
  46963 	1720: uint8(0x7f),
  46964 	1721: uint8(0x7f),
  46965 	1722: uint8(0x7f),
  46966 	1723: uint8(0x7f),
  46967 	1724: uint8(0x7f),
  46968 	1725: uint8(0x7f),
  46969 	1726: uint8(0x7f),
  46970 	1727: uint8(0x7f),
  46971 	1728: uint8(0x7f),
  46972 	1729: uint8(0x7f),
  46973 	1730: uint8(0x7f),
  46974 	1731: uint8(0x7f),
  46975 	1732: uint8(0x7f),
  46976 	1733: uint8(0x7f),
  46977 	1734: uint8(0x7f),
  46978 	1735: uint8(0x7f),
  46979 	1736: uint8(0x7f),
  46980 	1737: uint8(0x7f),
  46981 	1738: uint8(0x7f),
  46982 	1739: uint8(0x7f),
  46983 	1740: uint8(0x7f),
  46984 	1741: uint8(0x7f),
  46985 	1742: uint8(0x7f),
  46986 	1743: uint8(0x7f),
  46987 	1744: uint8(0x7f),
  46988 	1745: uint8(0x7f),
  46989 	1746: uint8(0x7f),
  46990 	1747: uint8(0x7f),
  46991 	1748: uint8(0x7f),
  46992 	1749: uint8(0x7f),
  46993 	1750: uint8(0x7f),
  46994 	1751: uint8(0x7f),
  46995 	1752: uint8(0x7f),
  46996 	1753: uint8(0x7f),
  46997 	1754: uint8(0x7f),
  46998 	1755: uint8(0x7f),
  46999 	1756: uint8(0x7f),
  47000 	1757: uint8(0x7f),
  47001 	1758: uint8(0x7f),
  47002 	1759: uint8(0x7f),
  47003 	1760: uint8(0x7f),
  47004 	1761: uint8(0x7f),
  47005 	1762: uint8(0x7f),
  47006 	1763: uint8(0x7f),
  47007 	1764: uint8(0x7f),
  47008 	1765: uint8(0x7f),
  47009 	1766: uint8(0x7f),
  47010 	1767: uint8(0x7f),
  47011 	1768: uint8(0x7f),
  47012 	1769: uint8(0x7f),
  47013 	1770: uint8(0x7f),
  47014 	1771: uint8(0x7f),
  47015 	1772: uint8(0x7f),
  47016 	1773: uint8(0x7f),
  47017 	1774: uint8(0x7f),
  47018 	1775: uint8(0x7f),
  47019 	1776: uint8(0x7f),
  47020 	1777: uint8(0x7f),
  47021 	1778: uint8(0x7f),
  47022 	1779: uint8(0x7f),
  47023 	1780: uint8(0x7f),
  47024 	1781: uint8(0x7f),
  47025 	1782: uint8(0x7f),
  47026 	1783: uint8(0x7f),
  47027 	1784: uint8(0x7f),
  47028 	1785: uint8(0x7f),
  47029 	1786: uint8(0x7f),
  47030 	1787: uint8(0x7f),
  47031 	1788: uint8(0x7f),
  47032 	1789: uint8(0x7f),
  47033 	1790: uint8(0x7f),
  47034 	1791: uint8(0x7f),
  47035 	1792: uint8(0x7f),
  47036 	1793: uint8(0x7f),
  47037 	1794: uint8(0x7f),
  47038 	1795: uint8(0x7f),
  47039 	1796: uint8(0x7f),
  47040 	1797: uint8(0x7f),
  47041 	1798: uint8(0x7f),
  47042 	1799: uint8(0x7f),
  47043 	1800: uint8(0x7f),
  47044 	1801: uint8(0x7f),
  47045 	1802: uint8(0x7f),
  47046 	1803: uint8(0x7f),
  47047 	1804: uint8(0x7f),
  47048 	1805: uint8(0x7f),
  47049 	1806: uint8(0x7f),
  47050 	1807: uint8(0x7f),
  47051 	1808: uint8(0x7f),
  47052 	1809: uint8(0x7f),
  47053 	1810: uint8(0x7f),
  47054 	1811: uint8(0x7f),
  47055 	1812: uint8(0x7f),
  47056 	1813: uint8(0x7f),
  47057 	1814: uint8(0x7f),
  47058 	1815: uint8(0x7f),
  47059 	1816: uint8(0x7f),
  47060 	1817: uint8(0x7f),
  47061 	1818: uint8(0x7f),
  47062 	1819: uint8(0x7f),
  47063 	1820: uint8(0x7f),
  47064 	1821: uint8(0x7f),
  47065 	1822: uint8(0x7f),
  47066 	1823: uint8(0x7f),
  47067 	1824: uint8(0x7f),
  47068 	1825: uint8(0x7f),
  47069 	1826: uint8(0x7f),
  47070 	1827: uint8(0x7f),
  47071 	1828: uint8(0x7f),
  47072 	1829: uint8(0x7f),
  47073 	1830: uint8(0x7f),
  47074 	1831: uint8(0x7f),
  47075 	1832: uint8(0x7f),
  47076 	1833: uint8(0x7f),
  47077 	1834: uint8(0x7f),
  47078 	1835: uint8(0x7f),
  47079 	1836: uint8(0x7f),
  47080 	1837: uint8(0x7f),
  47081 	1838: uint8(0x7f),
  47082 	1839: uint8(0x7f),
  47083 	1840: uint8(0x7f),
  47084 	1841: uint8(0x7f),
  47085 	1842: uint8(0x7f),
  47086 	1843: uint8(0x7f),
  47087 	1844: uint8(0x7f),
  47088 	1845: uint8(0x7f),
  47089 	1846: uint8(0x7f),
  47090 	1847: uint8(0x7f),
  47091 	1848: uint8(0x7f),
  47092 	1849: uint8(0x7f),
  47093 	1850: uint8(0x7f),
  47094 	1851: uint8(0x7f),
  47095 	1852: uint8(0x7f),
  47096 	1853: uint8(0x7f),
  47097 	1854: uint8(0x7f),
  47098 	1855: uint8(0x7f),
  47099 	1856: uint8(0x7f),
  47100 	1857: uint8(0x7f),
  47101 	1858: uint8(0x7f),
  47102 	1859: uint8(0x7f),
  47103 	1860: uint8(0x7f),
  47104 	1861: uint8(0x7f),
  47105 	1862: uint8(0x7f),
  47106 	1863: uint8(0x7f),
  47107 	1864: uint8(0x7f),
  47108 	1865: uint8(0x7f),
  47109 	1866: uint8(0x7f),
  47110 	1867: uint8(0x7f),
  47111 	1868: uint8(0x7f),
  47112 	1869: uint8(0x7f),
  47113 	1870: uint8(0x7f),
  47114 	1871: uint8(0x7f),
  47115 	1872: uint8(0x7f),
  47116 	1873: uint8(0x7f),
  47117 	1874: uint8(0x7f),
  47118 	1875: uint8(0x7f),
  47119 	1876: uint8(0x7f),
  47120 	1877: uint8(0x7f),
  47121 	1878: uint8(0x7f),
  47122 	1879: uint8(0x7f),
  47123 	1880: uint8(0x7f),
  47124 	1881: uint8(0x7f),
  47125 	1882: uint8(0x7f),
  47126 	1883: uint8(0x7f),
  47127 	1884: uint8(0x7f),
  47128 	1885: uint8(0x7f),
  47129 	1886: uint8(0x7f),
  47130 	1887: uint8(0x7f),
  47131 	1888: uint8(0x7f),
  47132 	1889: uint8(0x7f),
  47133 	1890: uint8(0x7f),
  47134 	1891: uint8(0x7f),
  47135 	1892: uint8(0x7f),
  47136 	1893: uint8(0x7f),
  47137 	1894: uint8(0x7f),
  47138 	1895: uint8(0x7f),
  47139 	1896: uint8(0x7f),
  47140 	1897: uint8(0x7f),
  47141 	1898: uint8(0x7f),
  47142 	1899: uint8(0x7f),
  47143 	1900: uint8(0x7f),
  47144 	1901: uint8(0x7f),
  47145 	1902: uint8(0x7f),
  47146 	1903: uint8(0x7f),
  47147 	1904: uint8(0x7f),
  47148 	1905: uint8(0x7f),
  47149 	1906: uint8(0x7f),
  47150 	1907: uint8(0x7f),
  47151 	1908: uint8(0x7f),
  47152 	1909: uint8(0x7f),
  47153 	1910: uint8(0x7f),
  47154 	1911: uint8(0x7f),
  47155 	1912: uint8(0x7f),
  47156 	1913: uint8(0x7f),
  47157 	1914: uint8(0x7f),
  47158 	1915: uint8(0x7f),
  47159 	1916: uint8(0x7f),
  47160 	1917: uint8(0x7f),
  47161 	1918: uint8(0x7f),
  47162 	1919: uint8(0x7f),
  47163 	1920: uint8(0x7f),
  47164 	1921: uint8(0x7f),
  47165 	1922: uint8(0x7f),
  47166 	1923: uint8(0x7f),
  47167 	1924: uint8(0x7f),
  47168 	1925: uint8(0x7f),
  47169 	1926: uint8(0x7f),
  47170 	1927: uint8(0x7f),
  47171 	1928: uint8(0x7f),
  47172 	1929: uint8(0x7f),
  47173 	1930: uint8(0x7f),
  47174 	1931: uint8(0x7f),
  47175 	1932: uint8(0x7f),
  47176 	1933: uint8(0x7f),
  47177 	1934: uint8(0x7f),
  47178 	1935: uint8(0x7f),
  47179 	1936: uint8(0x7f),
  47180 	1937: uint8(0x7f),
  47181 	1938: uint8(0x7f),
  47182 	1939: uint8(0x7f),
  47183 	1940: uint8(0x7f),
  47184 	1941: uint8(0x7f),
  47185 	1942: uint8(0x7f),
  47186 	1943: uint8(0x7f),
  47187 	1944: uint8(0x7f),
  47188 	1945: uint8(0x7f),
  47189 	1946: uint8(0x7f),
  47190 	1947: uint8(0x7f),
  47191 	1948: uint8(0x7f),
  47192 	1949: uint8(0x7f),
  47193 	1950: uint8(0x7f),
  47194 	1951: uint8(0x7f),
  47195 	1952: uint8(0x7f),
  47196 	1953: uint8(0x7f),
  47197 	1954: uint8(0x7f),
  47198 	1955: uint8(0x7f),
  47199 	1956: uint8(0x7f),
  47200 	1957: uint8(0x7f),
  47201 	1958: uint8(0x7f),
  47202 	1959: uint8(0x7f),
  47203 	1960: uint8(0x7f),
  47204 	1961: uint8(0x7f),
  47205 	1962: uint8(0x7f),
  47206 	1963: uint8(0x7f),
  47207 	1964: uint8(0x7f),
  47208 	1965: uint8(0x7f),
  47209 	1966: uint8(0x7f),
  47210 	1967: uint8(0x7f),
  47211 	1968: uint8(0x7f),
  47212 	1969: uint8(0x7f),
  47213 	1970: uint8(0x7f),
  47214 	1971: uint8(0x7f),
  47215 	1972: uint8(0x7f),
  47216 	1973: uint8(0x7f),
  47217 	1974: uint8(0x7f),
  47218 	1975: uint8(0x7f),
  47219 	1976: uint8(0x7f),
  47220 	1977: uint8(0x7f),
  47221 	1978: uint8(0x7f),
  47222 	1979: uint8(0x7f),
  47223 	1980: uint8(0x7f),
  47224 	1981: uint8(0x7f),
  47225 	1982: uint8(0x7f),
  47226 	1983: uint8(0x7f),
  47227 	1984: uint8(0x7f),
  47228 	1985: uint8(0x7f),
  47229 	1986: uint8(0x7f),
  47230 	1987: uint8(0x7f),
  47231 	1988: uint8(0x7f),
  47232 	1989: uint8(0x7f),
  47233 	1990: uint8(0x7f),
  47234 	1991: uint8(0x7f),
  47235 	1992: uint8(0x7f),
  47236 	1993: uint8(0x7f),
  47237 	1994: uint8(0x7f),
  47238 	1995: uint8(0x7f),
  47239 	1996: uint8(0x7f),
  47240 	1997: uint8(0x7f),
  47241 	1998: uint8(0x7f),
  47242 	1999: uint8(0x7f),
  47243 	2000: uint8(0x7f),
  47244 	2001: uint8(0x7f),
  47245 	2002: uint8(0x7f),
  47246 	2003: uint8(0x7f),
  47247 	2004: uint8(0x7f),
  47248 	2005: uint8(0x7f),
  47249 	2006: uint8(0x7f),
  47250 	2007: uint8(0x7f),
  47251 	2008: uint8(0x7f),
  47252 	2009: uint8(0x7f),
  47253 	2010: uint8(0x7f),
  47254 	2011: uint8(0x7f),
  47255 	2012: uint8(0x7f),
  47256 	2013: uint8(0x7f),
  47257 	2014: uint8(0x7f),
  47258 	2015: uint8(0x7f),
  47259 	2016: uint8(0x7f),
  47260 	2017: uint8(0x7f),
  47261 	2018: uint8(0x7f),
  47262 	2019: uint8(0x7f),
  47263 	2020: uint8(0x7f),
  47264 	2021: uint8(0x7f),
  47265 	2022: uint8(0x7f),
  47266 	2023: uint8(0x7f),
  47267 	2024: uint8(0x7f),
  47268 	2025: uint8(0x7f),
  47269 	2026: uint8(0x7f),
  47270 	2027: uint8(0x7f),
  47271 	2028: uint8(0x7f),
  47272 	2029: uint8(0x7f),
  47273 	2030: uint8(0x7f),
  47274 	2031: uint8(0x7f),
  47275 	2032: uint8(0x7f),
  47276 	2033: uint8(0x7f),
  47277 	2034: uint8(0x7f),
  47278 	2035: uint8(0x7f),
  47279 	2036: uint8(0x7f),
  47280 	2037: uint8(0x7f),
  47281 	2038: uint8(0x7f),
  47282 	2039: uint8(0x7f),
  47283 }
  47284 
  47285 var sclip2 = [225]uint8_t{
  47286 	0:   uint8(0xf0),
  47287 	1:   uint8(0xf0),
  47288 	2:   uint8(0xf0),
  47289 	3:   uint8(0xf0),
  47290 	4:   uint8(0xf0),
  47291 	5:   uint8(0xf0),
  47292 	6:   uint8(0xf0),
  47293 	7:   uint8(0xf0),
  47294 	8:   uint8(0xf0),
  47295 	9:   uint8(0xf0),
  47296 	10:  uint8(0xf0),
  47297 	11:  uint8(0xf0),
  47298 	12:  uint8(0xf0),
  47299 	13:  uint8(0xf0),
  47300 	14:  uint8(0xf0),
  47301 	15:  uint8(0xf0),
  47302 	16:  uint8(0xf0),
  47303 	17:  uint8(0xf0),
  47304 	18:  uint8(0xf0),
  47305 	19:  uint8(0xf0),
  47306 	20:  uint8(0xf0),
  47307 	21:  uint8(0xf0),
  47308 	22:  uint8(0xf0),
  47309 	23:  uint8(0xf0),
  47310 	24:  uint8(0xf0),
  47311 	25:  uint8(0xf0),
  47312 	26:  uint8(0xf0),
  47313 	27:  uint8(0xf0),
  47314 	28:  uint8(0xf0),
  47315 	29:  uint8(0xf0),
  47316 	30:  uint8(0xf0),
  47317 	31:  uint8(0xf0),
  47318 	32:  uint8(0xf0),
  47319 	33:  uint8(0xf0),
  47320 	34:  uint8(0xf0),
  47321 	35:  uint8(0xf0),
  47322 	36:  uint8(0xf0),
  47323 	37:  uint8(0xf0),
  47324 	38:  uint8(0xf0),
  47325 	39:  uint8(0xf0),
  47326 	40:  uint8(0xf0),
  47327 	41:  uint8(0xf0),
  47328 	42:  uint8(0xf0),
  47329 	43:  uint8(0xf0),
  47330 	44:  uint8(0xf0),
  47331 	45:  uint8(0xf0),
  47332 	46:  uint8(0xf0),
  47333 	47:  uint8(0xf0),
  47334 	48:  uint8(0xf0),
  47335 	49:  uint8(0xf0),
  47336 	50:  uint8(0xf0),
  47337 	51:  uint8(0xf0),
  47338 	52:  uint8(0xf0),
  47339 	53:  uint8(0xf0),
  47340 	54:  uint8(0xf0),
  47341 	55:  uint8(0xf0),
  47342 	56:  uint8(0xf0),
  47343 	57:  uint8(0xf0),
  47344 	58:  uint8(0xf0),
  47345 	59:  uint8(0xf0),
  47346 	60:  uint8(0xf0),
  47347 	61:  uint8(0xf0),
  47348 	62:  uint8(0xf0),
  47349 	63:  uint8(0xf0),
  47350 	64:  uint8(0xf0),
  47351 	65:  uint8(0xf0),
  47352 	66:  uint8(0xf0),
  47353 	67:  uint8(0xf0),
  47354 	68:  uint8(0xf0),
  47355 	69:  uint8(0xf0),
  47356 	70:  uint8(0xf0),
  47357 	71:  uint8(0xf0),
  47358 	72:  uint8(0xf0),
  47359 	73:  uint8(0xf0),
  47360 	74:  uint8(0xf0),
  47361 	75:  uint8(0xf0),
  47362 	76:  uint8(0xf0),
  47363 	77:  uint8(0xf0),
  47364 	78:  uint8(0xf0),
  47365 	79:  uint8(0xf0),
  47366 	80:  uint8(0xf0),
  47367 	81:  uint8(0xf0),
  47368 	82:  uint8(0xf0),
  47369 	83:  uint8(0xf0),
  47370 	84:  uint8(0xf0),
  47371 	85:  uint8(0xf0),
  47372 	86:  uint8(0xf0),
  47373 	87:  uint8(0xf0),
  47374 	88:  uint8(0xf0),
  47375 	89:  uint8(0xf0),
  47376 	90:  uint8(0xf0),
  47377 	91:  uint8(0xf0),
  47378 	92:  uint8(0xf0),
  47379 	93:  uint8(0xf0),
  47380 	94:  uint8(0xf0),
  47381 	95:  uint8(0xf0),
  47382 	96:  uint8(0xf0),
  47383 	97:  uint8(0xf1),
  47384 	98:  uint8(0xf2),
  47385 	99:  uint8(0xf3),
  47386 	100: uint8(0xf4),
  47387 	101: uint8(0xf5),
  47388 	102: uint8(0xf6),
  47389 	103: uint8(0xf7),
  47390 	104: uint8(0xf8),
  47391 	105: uint8(0xf9),
  47392 	106: uint8(0xfa),
  47393 	107: uint8(0xfb),
  47394 	108: uint8(0xfc),
  47395 	109: uint8(0xfd),
  47396 	110: uint8(0xfe),
  47397 	111: uint8(0xff),
  47398 	113: uint8(0x01),
  47399 	114: uint8(0x02),
  47400 	115: uint8(0x03),
  47401 	116: uint8(0x04),
  47402 	117: uint8(0x05),
  47403 	118: uint8(0x06),
  47404 	119: uint8(0x07),
  47405 	120: uint8(0x08),
  47406 	121: uint8(0x09),
  47407 	122: uint8(0x0a),
  47408 	123: uint8(0x0b),
  47409 	124: uint8(0x0c),
  47410 	125: uint8(0x0d),
  47411 	126: uint8(0x0e),
  47412 	127: uint8(0x0f),
  47413 	128: uint8(0x0f),
  47414 	129: uint8(0x0f),
  47415 	130: uint8(0x0f),
  47416 	131: uint8(0x0f),
  47417 	132: uint8(0x0f),
  47418 	133: uint8(0x0f),
  47419 	134: uint8(0x0f),
  47420 	135: uint8(0x0f),
  47421 	136: uint8(0x0f),
  47422 	137: uint8(0x0f),
  47423 	138: uint8(0x0f),
  47424 	139: uint8(0x0f),
  47425 	140: uint8(0x0f),
  47426 	141: uint8(0x0f),
  47427 	142: uint8(0x0f),
  47428 	143: uint8(0x0f),
  47429 	144: uint8(0x0f),
  47430 	145: uint8(0x0f),
  47431 	146: uint8(0x0f),
  47432 	147: uint8(0x0f),
  47433 	148: uint8(0x0f),
  47434 	149: uint8(0x0f),
  47435 	150: uint8(0x0f),
  47436 	151: uint8(0x0f),
  47437 	152: uint8(0x0f),
  47438 	153: uint8(0x0f),
  47439 	154: uint8(0x0f),
  47440 	155: uint8(0x0f),
  47441 	156: uint8(0x0f),
  47442 	157: uint8(0x0f),
  47443 	158: uint8(0x0f),
  47444 	159: uint8(0x0f),
  47445 	160: uint8(0x0f),
  47446 	161: uint8(0x0f),
  47447 	162: uint8(0x0f),
  47448 	163: uint8(0x0f),
  47449 	164: uint8(0x0f),
  47450 	165: uint8(0x0f),
  47451 	166: uint8(0x0f),
  47452 	167: uint8(0x0f),
  47453 	168: uint8(0x0f),
  47454 	169: uint8(0x0f),
  47455 	170: uint8(0x0f),
  47456 	171: uint8(0x0f),
  47457 	172: uint8(0x0f),
  47458 	173: uint8(0x0f),
  47459 	174: uint8(0x0f),
  47460 	175: uint8(0x0f),
  47461 	176: uint8(0x0f),
  47462 	177: uint8(0x0f),
  47463 	178: uint8(0x0f),
  47464 	179: uint8(0x0f),
  47465 	180: uint8(0x0f),
  47466 	181: uint8(0x0f),
  47467 	182: uint8(0x0f),
  47468 	183: uint8(0x0f),
  47469 	184: uint8(0x0f),
  47470 	185: uint8(0x0f),
  47471 	186: uint8(0x0f),
  47472 	187: uint8(0x0f),
  47473 	188: uint8(0x0f),
  47474 	189: uint8(0x0f),
  47475 	190: uint8(0x0f),
  47476 	191: uint8(0x0f),
  47477 	192: uint8(0x0f),
  47478 	193: uint8(0x0f),
  47479 	194: uint8(0x0f),
  47480 	195: uint8(0x0f),
  47481 	196: uint8(0x0f),
  47482 	197: uint8(0x0f),
  47483 	198: uint8(0x0f),
  47484 	199: uint8(0x0f),
  47485 	200: uint8(0x0f),
  47486 	201: uint8(0x0f),
  47487 	202: uint8(0x0f),
  47488 	203: uint8(0x0f),
  47489 	204: uint8(0x0f),
  47490 	205: uint8(0x0f),
  47491 	206: uint8(0x0f),
  47492 	207: uint8(0x0f),
  47493 	208: uint8(0x0f),
  47494 	209: uint8(0x0f),
  47495 	210: uint8(0x0f),
  47496 	211: uint8(0x0f),
  47497 	212: uint8(0x0f),
  47498 	213: uint8(0x0f),
  47499 	214: uint8(0x0f),
  47500 	215: uint8(0x0f),
  47501 	216: uint8(0x0f),
  47502 	217: uint8(0x0f),
  47503 	218: uint8(0x0f),
  47504 	219: uint8(0x0f),
  47505 	220: uint8(0x0f),
  47506 	221: uint8(0x0f),
  47507 	222: uint8(0x0f),
  47508 	223: uint8(0x0f),
  47509 }
  47510 
  47511 var clip11 = [767]uint8_t{
  47512 	256: uint8(0x01),
  47513 	257: uint8(0x02),
  47514 	258: uint8(0x03),
  47515 	259: uint8(0x04),
  47516 	260: uint8(0x05),
  47517 	261: uint8(0x06),
  47518 	262: uint8(0x07),
  47519 	263: uint8(0x08),
  47520 	264: uint8(0x09),
  47521 	265: uint8(0x0a),
  47522 	266: uint8(0x0b),
  47523 	267: uint8(0x0c),
  47524 	268: uint8(0x0d),
  47525 	269: uint8(0x0e),
  47526 	270: uint8(0x0f),
  47527 	271: uint8(0x10),
  47528 	272: uint8(0x11),
  47529 	273: uint8(0x12),
  47530 	274: uint8(0x13),
  47531 	275: uint8(0x14),
  47532 	276: uint8(0x15),
  47533 	277: uint8(0x16),
  47534 	278: uint8(0x17),
  47535 	279: uint8(0x18),
  47536 	280: uint8(0x19),
  47537 	281: uint8(0x1a),
  47538 	282: uint8(0x1b),
  47539 	283: uint8(0x1c),
  47540 	284: uint8(0x1d),
  47541 	285: uint8(0x1e),
  47542 	286: uint8(0x1f),
  47543 	287: uint8(0x20),
  47544 	288: uint8(0x21),
  47545 	289: uint8(0x22),
  47546 	290: uint8(0x23),
  47547 	291: uint8(0x24),
  47548 	292: uint8(0x25),
  47549 	293: uint8(0x26),
  47550 	294: uint8(0x27),
  47551 	295: uint8(0x28),
  47552 	296: uint8(0x29),
  47553 	297: uint8(0x2a),
  47554 	298: uint8(0x2b),
  47555 	299: uint8(0x2c),
  47556 	300: uint8(0x2d),
  47557 	301: uint8(0x2e),
  47558 	302: uint8(0x2f),
  47559 	303: uint8(0x30),
  47560 	304: uint8(0x31),
  47561 	305: uint8(0x32),
  47562 	306: uint8(0x33),
  47563 	307: uint8(0x34),
  47564 	308: uint8(0x35),
  47565 	309: uint8(0x36),
  47566 	310: uint8(0x37),
  47567 	311: uint8(0x38),
  47568 	312: uint8(0x39),
  47569 	313: uint8(0x3a),
  47570 	314: uint8(0x3b),
  47571 	315: uint8(0x3c),
  47572 	316: uint8(0x3d),
  47573 	317: uint8(0x3e),
  47574 	318: uint8(0x3f),
  47575 	319: uint8(0x40),
  47576 	320: uint8(0x41),
  47577 	321: uint8(0x42),
  47578 	322: uint8(0x43),
  47579 	323: uint8(0x44),
  47580 	324: uint8(0x45),
  47581 	325: uint8(0x46),
  47582 	326: uint8(0x47),
  47583 	327: uint8(0x48),
  47584 	328: uint8(0x49),
  47585 	329: uint8(0x4a),
  47586 	330: uint8(0x4b),
  47587 	331: uint8(0x4c),
  47588 	332: uint8(0x4d),
  47589 	333: uint8(0x4e),
  47590 	334: uint8(0x4f),
  47591 	335: uint8(0x50),
  47592 	336: uint8(0x51),
  47593 	337: uint8(0x52),
  47594 	338: uint8(0x53),
  47595 	339: uint8(0x54),
  47596 	340: uint8(0x55),
  47597 	341: uint8(0x56),
  47598 	342: uint8(0x57),
  47599 	343: uint8(0x58),
  47600 	344: uint8(0x59),
  47601 	345: uint8(0x5a),
  47602 	346: uint8(0x5b),
  47603 	347: uint8(0x5c),
  47604 	348: uint8(0x5d),
  47605 	349: uint8(0x5e),
  47606 	350: uint8(0x5f),
  47607 	351: uint8(0x60),
  47608 	352: uint8(0x61),
  47609 	353: uint8(0x62),
  47610 	354: uint8(0x63),
  47611 	355: uint8(0x64),
  47612 	356: uint8(0x65),
  47613 	357: uint8(0x66),
  47614 	358: uint8(0x67),
  47615 	359: uint8(0x68),
  47616 	360: uint8(0x69),
  47617 	361: uint8(0x6a),
  47618 	362: uint8(0x6b),
  47619 	363: uint8(0x6c),
  47620 	364: uint8(0x6d),
  47621 	365: uint8(0x6e),
  47622 	366: uint8(0x6f),
  47623 	367: uint8(0x70),
  47624 	368: uint8(0x71),
  47625 	369: uint8(0x72),
  47626 	370: uint8(0x73),
  47627 	371: uint8(0x74),
  47628 	372: uint8(0x75),
  47629 	373: uint8(0x76),
  47630 	374: uint8(0x77),
  47631 	375: uint8(0x78),
  47632 	376: uint8(0x79),
  47633 	377: uint8(0x7a),
  47634 	378: uint8(0x7b),
  47635 	379: uint8(0x7c),
  47636 	380: uint8(0x7d),
  47637 	381: uint8(0x7e),
  47638 	382: uint8(0x7f),
  47639 	383: uint8(0x80),
  47640 	384: uint8(0x81),
  47641 	385: uint8(0x82),
  47642 	386: uint8(0x83),
  47643 	387: uint8(0x84),
  47644 	388: uint8(0x85),
  47645 	389: uint8(0x86),
  47646 	390: uint8(0x87),
  47647 	391: uint8(0x88),
  47648 	392: uint8(0x89),
  47649 	393: uint8(0x8a),
  47650 	394: uint8(0x8b),
  47651 	395: uint8(0x8c),
  47652 	396: uint8(0x8d),
  47653 	397: uint8(0x8e),
  47654 	398: uint8(0x8f),
  47655 	399: uint8(0x90),
  47656 	400: uint8(0x91),
  47657 	401: uint8(0x92),
  47658 	402: uint8(0x93),
  47659 	403: uint8(0x94),
  47660 	404: uint8(0x95),
  47661 	405: uint8(0x96),
  47662 	406: uint8(0x97),
  47663 	407: uint8(0x98),
  47664 	408: uint8(0x99),
  47665 	409: uint8(0x9a),
  47666 	410: uint8(0x9b),
  47667 	411: uint8(0x9c),
  47668 	412: uint8(0x9d),
  47669 	413: uint8(0x9e),
  47670 	414: uint8(0x9f),
  47671 	415: uint8(0xa0),
  47672 	416: uint8(0xa1),
  47673 	417: uint8(0xa2),
  47674 	418: uint8(0xa3),
  47675 	419: uint8(0xa4),
  47676 	420: uint8(0xa5),
  47677 	421: uint8(0xa6),
  47678 	422: uint8(0xa7),
  47679 	423: uint8(0xa8),
  47680 	424: uint8(0xa9),
  47681 	425: uint8(0xaa),
  47682 	426: uint8(0xab),
  47683 	427: uint8(0xac),
  47684 	428: uint8(0xad),
  47685 	429: uint8(0xae),
  47686 	430: uint8(0xaf),
  47687 	431: uint8(0xb0),
  47688 	432: uint8(0xb1),
  47689 	433: uint8(0xb2),
  47690 	434: uint8(0xb3),
  47691 	435: uint8(0xb4),
  47692 	436: uint8(0xb5),
  47693 	437: uint8(0xb6),
  47694 	438: uint8(0xb7),
  47695 	439: uint8(0xb8),
  47696 	440: uint8(0xb9),
  47697 	441: uint8(0xba),
  47698 	442: uint8(0xbb),
  47699 	443: uint8(0xbc),
  47700 	444: uint8(0xbd),
  47701 	445: uint8(0xbe),
  47702 	446: uint8(0xbf),
  47703 	447: uint8(0xc0),
  47704 	448: uint8(0xc1),
  47705 	449: uint8(0xc2),
  47706 	450: uint8(0xc3),
  47707 	451: uint8(0xc4),
  47708 	452: uint8(0xc5),
  47709 	453: uint8(0xc6),
  47710 	454: uint8(0xc7),
  47711 	455: uint8(0xc8),
  47712 	456: uint8(0xc9),
  47713 	457: uint8(0xca),
  47714 	458: uint8(0xcb),
  47715 	459: uint8(0xcc),
  47716 	460: uint8(0xcd),
  47717 	461: uint8(0xce),
  47718 	462: uint8(0xcf),
  47719 	463: uint8(0xd0),
  47720 	464: uint8(0xd1),
  47721 	465: uint8(0xd2),
  47722 	466: uint8(0xd3),
  47723 	467: uint8(0xd4),
  47724 	468: uint8(0xd5),
  47725 	469: uint8(0xd6),
  47726 	470: uint8(0xd7),
  47727 	471: uint8(0xd8),
  47728 	472: uint8(0xd9),
  47729 	473: uint8(0xda),
  47730 	474: uint8(0xdb),
  47731 	475: uint8(0xdc),
  47732 	476: uint8(0xdd),
  47733 	477: uint8(0xde),
  47734 	478: uint8(0xdf),
  47735 	479: uint8(0xe0),
  47736 	480: uint8(0xe1),
  47737 	481: uint8(0xe2),
  47738 	482: uint8(0xe3),
  47739 	483: uint8(0xe4),
  47740 	484: uint8(0xe5),
  47741 	485: uint8(0xe6),
  47742 	486: uint8(0xe7),
  47743 	487: uint8(0xe8),
  47744 	488: uint8(0xe9),
  47745 	489: uint8(0xea),
  47746 	490: uint8(0xeb),
  47747 	491: uint8(0xec),
  47748 	492: uint8(0xed),
  47749 	493: uint8(0xee),
  47750 	494: uint8(0xef),
  47751 	495: uint8(0xf0),
  47752 	496: uint8(0xf1),
  47753 	497: uint8(0xf2),
  47754 	498: uint8(0xf3),
  47755 	499: uint8(0xf4),
  47756 	500: uint8(0xf5),
  47757 	501: uint8(0xf6),
  47758 	502: uint8(0xf7),
  47759 	503: uint8(0xf8),
  47760 	504: uint8(0xf9),
  47761 	505: uint8(0xfa),
  47762 	506: uint8(0xfb),
  47763 	507: uint8(0xfc),
  47764 	508: uint8(0xfd),
  47765 	509: uint8(0xfe),
  47766 	510: uint8(0xff),
  47767 	511: uint8(0xff),
  47768 	512: uint8(0xff),
  47769 	513: uint8(0xff),
  47770 	514: uint8(0xff),
  47771 	515: uint8(0xff),
  47772 	516: uint8(0xff),
  47773 	517: uint8(0xff),
  47774 	518: uint8(0xff),
  47775 	519: uint8(0xff),
  47776 	520: uint8(0xff),
  47777 	521: uint8(0xff),
  47778 	522: uint8(0xff),
  47779 	523: uint8(0xff),
  47780 	524: uint8(0xff),
  47781 	525: uint8(0xff),
  47782 	526: uint8(0xff),
  47783 	527: uint8(0xff),
  47784 	528: uint8(0xff),
  47785 	529: uint8(0xff),
  47786 	530: uint8(0xff),
  47787 	531: uint8(0xff),
  47788 	532: uint8(0xff),
  47789 	533: uint8(0xff),
  47790 	534: uint8(0xff),
  47791 	535: uint8(0xff),
  47792 	536: uint8(0xff),
  47793 	537: uint8(0xff),
  47794 	538: uint8(0xff),
  47795 	539: uint8(0xff),
  47796 	540: uint8(0xff),
  47797 	541: uint8(0xff),
  47798 	542: uint8(0xff),
  47799 	543: uint8(0xff),
  47800 	544: uint8(0xff),
  47801 	545: uint8(0xff),
  47802 	546: uint8(0xff),
  47803 	547: uint8(0xff),
  47804 	548: uint8(0xff),
  47805 	549: uint8(0xff),
  47806 	550: uint8(0xff),
  47807 	551: uint8(0xff),
  47808 	552: uint8(0xff),
  47809 	553: uint8(0xff),
  47810 	554: uint8(0xff),
  47811 	555: uint8(0xff),
  47812 	556: uint8(0xff),
  47813 	557: uint8(0xff),
  47814 	558: uint8(0xff),
  47815 	559: uint8(0xff),
  47816 	560: uint8(0xff),
  47817 	561: uint8(0xff),
  47818 	562: uint8(0xff),
  47819 	563: uint8(0xff),
  47820 	564: uint8(0xff),
  47821 	565: uint8(0xff),
  47822 	566: uint8(0xff),
  47823 	567: uint8(0xff),
  47824 	568: uint8(0xff),
  47825 	569: uint8(0xff),
  47826 	570: uint8(0xff),
  47827 	571: uint8(0xff),
  47828 	572: uint8(0xff),
  47829 	573: uint8(0xff),
  47830 	574: uint8(0xff),
  47831 	575: uint8(0xff),
  47832 	576: uint8(0xff),
  47833 	577: uint8(0xff),
  47834 	578: uint8(0xff),
  47835 	579: uint8(0xff),
  47836 	580: uint8(0xff),
  47837 	581: uint8(0xff),
  47838 	582: uint8(0xff),
  47839 	583: uint8(0xff),
  47840 	584: uint8(0xff),
  47841 	585: uint8(0xff),
  47842 	586: uint8(0xff),
  47843 	587: uint8(0xff),
  47844 	588: uint8(0xff),
  47845 	589: uint8(0xff),
  47846 	590: uint8(0xff),
  47847 	591: uint8(0xff),
  47848 	592: uint8(0xff),
  47849 	593: uint8(0xff),
  47850 	594: uint8(0xff),
  47851 	595: uint8(0xff),
  47852 	596: uint8(0xff),
  47853 	597: uint8(0xff),
  47854 	598: uint8(0xff),
  47855 	599: uint8(0xff),
  47856 	600: uint8(0xff),
  47857 	601: uint8(0xff),
  47858 	602: uint8(0xff),
  47859 	603: uint8(0xff),
  47860 	604: uint8(0xff),
  47861 	605: uint8(0xff),
  47862 	606: uint8(0xff),
  47863 	607: uint8(0xff),
  47864 	608: uint8(0xff),
  47865 	609: uint8(0xff),
  47866 	610: uint8(0xff),
  47867 	611: uint8(0xff),
  47868 	612: uint8(0xff),
  47869 	613: uint8(0xff),
  47870 	614: uint8(0xff),
  47871 	615: uint8(0xff),
  47872 	616: uint8(0xff),
  47873 	617: uint8(0xff),
  47874 	618: uint8(0xff),
  47875 	619: uint8(0xff),
  47876 	620: uint8(0xff),
  47877 	621: uint8(0xff),
  47878 	622: uint8(0xff),
  47879 	623: uint8(0xff),
  47880 	624: uint8(0xff),
  47881 	625: uint8(0xff),
  47882 	626: uint8(0xff),
  47883 	627: uint8(0xff),
  47884 	628: uint8(0xff),
  47885 	629: uint8(0xff),
  47886 	630: uint8(0xff),
  47887 	631: uint8(0xff),
  47888 	632: uint8(0xff),
  47889 	633: uint8(0xff),
  47890 	634: uint8(0xff),
  47891 	635: uint8(0xff),
  47892 	636: uint8(0xff),
  47893 	637: uint8(0xff),
  47894 	638: uint8(0xff),
  47895 	639: uint8(0xff),
  47896 	640: uint8(0xff),
  47897 	641: uint8(0xff),
  47898 	642: uint8(0xff),
  47899 	643: uint8(0xff),
  47900 	644: uint8(0xff),
  47901 	645: uint8(0xff),
  47902 	646: uint8(0xff),
  47903 	647: uint8(0xff),
  47904 	648: uint8(0xff),
  47905 	649: uint8(0xff),
  47906 	650: uint8(0xff),
  47907 	651: uint8(0xff),
  47908 	652: uint8(0xff),
  47909 	653: uint8(0xff),
  47910 	654: uint8(0xff),
  47911 	655: uint8(0xff),
  47912 	656: uint8(0xff),
  47913 	657: uint8(0xff),
  47914 	658: uint8(0xff),
  47915 	659: uint8(0xff),
  47916 	660: uint8(0xff),
  47917 	661: uint8(0xff),
  47918 	662: uint8(0xff),
  47919 	663: uint8(0xff),
  47920 	664: uint8(0xff),
  47921 	665: uint8(0xff),
  47922 	666: uint8(0xff),
  47923 	667: uint8(0xff),
  47924 	668: uint8(0xff),
  47925 	669: uint8(0xff),
  47926 	670: uint8(0xff),
  47927 	671: uint8(0xff),
  47928 	672: uint8(0xff),
  47929 	673: uint8(0xff),
  47930 	674: uint8(0xff),
  47931 	675: uint8(0xff),
  47932 	676: uint8(0xff),
  47933 	677: uint8(0xff),
  47934 	678: uint8(0xff),
  47935 	679: uint8(0xff),
  47936 	680: uint8(0xff),
  47937 	681: uint8(0xff),
  47938 	682: uint8(0xff),
  47939 	683: uint8(0xff),
  47940 	684: uint8(0xff),
  47941 	685: uint8(0xff),
  47942 	686: uint8(0xff),
  47943 	687: uint8(0xff),
  47944 	688: uint8(0xff),
  47945 	689: uint8(0xff),
  47946 	690: uint8(0xff),
  47947 	691: uint8(0xff),
  47948 	692: uint8(0xff),
  47949 	693: uint8(0xff),
  47950 	694: uint8(0xff),
  47951 	695: uint8(0xff),
  47952 	696: uint8(0xff),
  47953 	697: uint8(0xff),
  47954 	698: uint8(0xff),
  47955 	699: uint8(0xff),
  47956 	700: uint8(0xff),
  47957 	701: uint8(0xff),
  47958 	702: uint8(0xff),
  47959 	703: uint8(0xff),
  47960 	704: uint8(0xff),
  47961 	705: uint8(0xff),
  47962 	706: uint8(0xff),
  47963 	707: uint8(0xff),
  47964 	708: uint8(0xff),
  47965 	709: uint8(0xff),
  47966 	710: uint8(0xff),
  47967 	711: uint8(0xff),
  47968 	712: uint8(0xff),
  47969 	713: uint8(0xff),
  47970 	714: uint8(0xff),
  47971 	715: uint8(0xff),
  47972 	716: uint8(0xff),
  47973 	717: uint8(0xff),
  47974 	718: uint8(0xff),
  47975 	719: uint8(0xff),
  47976 	720: uint8(0xff),
  47977 	721: uint8(0xff),
  47978 	722: uint8(0xff),
  47979 	723: uint8(0xff),
  47980 	724: uint8(0xff),
  47981 	725: uint8(0xff),
  47982 	726: uint8(0xff),
  47983 	727: uint8(0xff),
  47984 	728: uint8(0xff),
  47985 	729: uint8(0xff),
  47986 	730: uint8(0xff),
  47987 	731: uint8(0xff),
  47988 	732: uint8(0xff),
  47989 	733: uint8(0xff),
  47990 	734: uint8(0xff),
  47991 	735: uint8(0xff),
  47992 	736: uint8(0xff),
  47993 	737: uint8(0xff),
  47994 	738: uint8(0xff),
  47995 	739: uint8(0xff),
  47996 	740: uint8(0xff),
  47997 	741: uint8(0xff),
  47998 	742: uint8(0xff),
  47999 	743: uint8(0xff),
  48000 	744: uint8(0xff),
  48001 	745: uint8(0xff),
  48002 	746: uint8(0xff),
  48003 	747: uint8(0xff),
  48004 	748: uint8(0xff),
  48005 	749: uint8(0xff),
  48006 	750: uint8(0xff),
  48007 	751: uint8(0xff),
  48008 	752: uint8(0xff),
  48009 	753: uint8(0xff),
  48010 	754: uint8(0xff),
  48011 	755: uint8(0xff),
  48012 	756: uint8(0xff),
  48013 	757: uint8(0xff),
  48014 	758: uint8(0xff),
  48015 	759: uint8(0xff),
  48016 	760: uint8(0xff),
  48017 	761: uint8(0xff),
  48018 	762: uint8(0xff),
  48019 	763: uint8(0xff),
  48020 	764: uint8(0xff),
  48021 	765: uint8(0xff),
  48022 }
  48023 
  48024 func VP8InitClipTables(tls *libc.TLS) {
  48025 }
  48026 
  48027 func VP8DspInitMIPS32(tls *libc.TLS) {
  48028 }
  48029 
  48030 func VP8DspInitMIPSdspR2(tls *libc.TLS) {
  48031 }
  48032 
  48033 func VP8DspInitMSA(tls *libc.TLS) {
  48034 }
  48035 
  48036 func VP8DspInitNEON(tls *libc.TLS) {
  48037 }
  48038 
  48039 func VP8DspInitSSE2(tls *libc.TLS) {
  48040 }
  48041 
  48042 func VP8DspInitSSE41(tls *libc.TLS) {
  48043 }
  48044 
  48045 //------------------------------------------------------------------------------
  48046 
  48047 // Copyright 2012 Google Inc. All Rights Reserved.
  48048 //
  48049 // Use of this source code is governed by a BSD-style license
  48050 // that can be found in the COPYING file in the root of the source
  48051 // tree. An additional intellectual property rights grant can be found
  48052 // in the file PATENTS. All contributing project authors may
  48053 // be found in the AUTHORS file in the root of the source tree.
  48054 // -----------------------------------------------------------------------------
  48055 //
  48056 // Misc. common utility functions
  48057 //
  48058 // Authors: Skal (pascal.massimino@gmail.com)
  48059 //          Urvang (urvang@google.com)
  48060 
  48061 // Copyright 2010 Google Inc. All Rights Reserved.
  48062 //
  48063 // Use of this source code is governed by a BSD-style license
  48064 // that can be found in the COPYING file in the root of the source
  48065 // tree. An additional intellectual property rights grant can be found
  48066 // in the file PATENTS. All contributing project authors may
  48067 // be found in the AUTHORS file in the root of the source tree.
  48068 // -----------------------------------------------------------------------------
  48069 //
  48070 //  Common types + memory wrappers
  48071 //
  48072 // Author: Skal (pascal.massimino@gmail.com)
  48073 
  48074 func clip_8b2(tls *libc.TLS, v int32) (r uint8_t) {
  48075 	var v1, v2 int32
  48076 	_, _ = v1, v2
  48077 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  48078 		v1 = v
  48079 	} else {
  48080 		if v < 0 {
  48081 			v2 = 0
  48082 		} else {
  48083 			v2 = int32(255)
  48084 		}
  48085 		v1 = v2
  48086 	}
  48087 	return libc.Uint8FromInt32(v1)
  48088 }
  48089 
  48090 func clip_max(tls *libc.TLS, v int32, max int32) (r int32) {
  48091 	var v1 int32
  48092 	_ = v1
  48093 	if v > max {
  48094 		v1 = max
  48095 	} else {
  48096 		v1 = v
  48097 	}
  48098 	return v1
  48099 }
  48100 
  48101 // C documentation
  48102 //
  48103 //	// general-purpose util function
  48104 func VP8SetHistogramData(tls *libc.TLS, distribution uintptr, histo uintptr) {
  48105 	var k, last_non_zero, max_value, value int32
  48106 	_, _, _, _ = k, last_non_zero, max_value, value
  48107 	max_value = 0
  48108 	last_non_zero = int32(1)
  48109 	k = 0
  48110 	for {
  48111 		if !(k <= int32(MAX_COEFF_THRESH)) {
  48112 			break
  48113 		}
  48114 		value = **(**int32)(__ccgo_up(distribution + uintptr(k)*4))
  48115 		if value > 0 {
  48116 			if value > max_value {
  48117 				max_value = value
  48118 			}
  48119 			last_non_zero = k
  48120 		}
  48121 		goto _1
  48122 	_1:
  48123 		;
  48124 		k = k + 1
  48125 	}
  48126 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = max_value
  48127 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = last_non_zero
  48128 }
  48129 
  48130 func CollectHistogram_C(tls *libc.TLS, ref uintptr, pred uintptr, start_block int32, end_block int32, histo uintptr) {
  48131 	bp := tls.Alloc(160)
  48132 	defer tls.Free(160)
  48133 	var clipped_value, j, k, v int32
  48134 	var _ /* distribution at bp+0 */ [32]int32
  48135 	var _ /* out at bp+128 */ [16]int16_t
  48136 	_, _, _, _ = clipped_value, j, k, v
  48137 	**(**[32]int32)(__ccgo_up(bp)) = [32]int32{}
  48138 	j = start_block
  48139 	for {
  48140 		if !(j < end_block) {
  48141 			break
  48142 		}
  48143 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, ref+uintptr(VP8DspScan[j]), pred+uintptr(VP8DspScan[j]), bp+128)
  48144 		// Convert coefficients to bin.
  48145 		k = 0
  48146 		for {
  48147 			if !(k < int32(16)) {
  48148 				break
  48149 			}
  48150 			v = libc.Xabs(tls, int32((**(**[16]int16_t)(__ccgo_up(bp + 128)))[k])) >> int32(3)
  48151 			clipped_value = clip_max(tls, v, int32(MAX_COEFF_THRESH))
  48152 			(**(**[32]int32)(__ccgo_up(bp)))[clipped_value] = (**(**[32]int32)(__ccgo_up(bp)))[clipped_value] + 1
  48153 			goto _2
  48154 		_2:
  48155 			;
  48156 			k = k + 1
  48157 		}
  48158 		goto _1
  48159 	_1:
  48160 		;
  48161 		j = j + 1
  48162 	}
  48163 	VP8SetHistogramData(tls, bp, histo)
  48164 }
  48165 
  48166 //------------------------------------------------------------------------------
  48167 // run-time tables (~4k)
  48168 
  48169 var clip12 [766]uint8_t // clips [-255,510] to [0,255]
  48170 
  48171 // C documentation
  48172 //
  48173 //	// We declare this variable 'volatile' to prevent instruction reordering
  48174 //	// and make sure it's set to true _last_ (so as to be thread-safe)
  48175 var tables_ok = int32(0)
  48176 
  48177 func InitTables(tls *libc.TLS) {
  48178 	var i int32
  48179 	_ = i
  48180 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&tables_ok))) != 0) {
  48181 		i = -int32(255)
  48182 		for {
  48183 			if !(i <= libc.Int32FromInt32(255)+libc.Int32FromInt32(255)) {
  48184 				break
  48185 			}
  48186 			clip12[int32(255)+i] = clip_8b2(tls, i)
  48187 			goto _1
  48188 		_1:
  48189 			;
  48190 			i = i + 1
  48191 		}
  48192 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&tables_ok)), int32(1))
  48193 	}
  48194 }
  48195 
  48196 //------------------------------------------------------------------------------
  48197 // Transforms (Paragraph 14.4)
  48198 
  48199 func ITransformOne(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr) {
  48200 	bp := tls.Alloc(64)
  48201 	defer tls.Free(64)
  48202 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  48203 	var tmp uintptr
  48204 	var _ /* C at bp+0 */ [16]int32
  48205 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  48206 	tmp = bp
  48207 	i = 0
  48208 	for {
  48209 		if !(i < int32(4)) {
  48210 			break
  48211 		} // vertical pass
  48212 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48213 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48214 		c = int32(**(**int16_t)(__ccgo_up(in + 4*2)))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16) - (int32(**(**int16_t)(__ccgo_up(in + 12*2)))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + int32(**(**int16_t)(__ccgo_up(in + 12*2))))
  48215 		d = int32(**(**int16_t)(__ccgo_up(in + 4*2)))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + int32(**(**int16_t)(__ccgo_up(in + 4*2))) + int32(**(**int16_t)(__ccgo_up(in + 12*2)))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16)
  48216 		**(**int32)(__ccgo_up(tmp)) = a + d
  48217 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c
  48218 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c
  48219 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d
  48220 		tmp = tmp + uintptr(4)*4
  48221 		in += 2
  48222 		goto _1
  48223 	_1:
  48224 		;
  48225 		i = i + 1
  48226 	}
  48227 	tmp = bp
  48228 	i = 0
  48229 	for {
  48230 		if !(i < int32(4)) {
  48231 			break
  48232 		} // horizontal pass
  48233 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  48234 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  48235 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  48236 		c1 = **(**int32)(__ccgo_up(tmp + 4*4))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16) - (**(**int32)(__ccgo_up(tmp + 12*4))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + **(**int32)(__ccgo_up(tmp + 12*4)))
  48237 		d1 = **(**int32)(__ccgo_up(tmp + 4*4))*int32(WEBP_TRANSFORM_AC3_C1)>>int32(16) + **(**int32)(__ccgo_up(tmp + 4*4)) + **(**int32)(__ccgo_up(tmp + 12*4))*int32(WEBP_TRANSFORM_AC3_C2)>>int32(16)
  48238 		**(**uint8_t)(__ccgo_up(dst + uintptr(0+i*int32(BPS)))) = clip_8b2(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + uintptr(0+i*int32(BPS)))))+(a1+d1)>>int32(3))
  48239 		**(**uint8_t)(__ccgo_up(dst + uintptr(int32(1)+i*int32(BPS)))) = clip_8b2(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + uintptr(int32(1)+i*int32(BPS)))))+(b1+c1)>>int32(3))
  48240 		**(**uint8_t)(__ccgo_up(dst + uintptr(int32(2)+i*int32(BPS)))) = clip_8b2(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + uintptr(int32(2)+i*int32(BPS)))))+(b1-c1)>>int32(3))
  48241 		**(**uint8_t)(__ccgo_up(dst + uintptr(int32(3)+i*int32(BPS)))) = clip_8b2(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + uintptr(int32(3)+i*int32(BPS)))))+(a1-d1)>>int32(3))
  48242 		tmp += 4
  48243 		goto _2
  48244 	_2:
  48245 		;
  48246 		i = i + 1
  48247 	}
  48248 }
  48249 
  48250 func ITransform_C(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr, do_two int32) {
  48251 	ITransformOne(tls, ref, in, dst)
  48252 	if do_two != 0 {
  48253 		ITransformOne(tls, ref+uintptr(4), in+uintptr(16)*2, dst+uintptr(4))
  48254 	}
  48255 }
  48256 
  48257 func FTransform_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48258 	var a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i int32
  48259 	var tmp [16]int32
  48260 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i, tmp
  48261 	i = 0
  48262 	for {
  48263 		if !(i < int32(4)) {
  48264 			break
  48265 		}
  48266 		d0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref))) // 9bit dynamic range ([-255,255])
  48267 		d1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + 1))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + 1)))
  48268 		d2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + 2))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + 2)))
  48269 		d3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + 3))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + 3)))
  48270 		a0 = d0 + d3 // 10b                      [-510,510]
  48271 		a1 = d1 + d2
  48272 		a2 = d1 - d2
  48273 		a3 = d0 - d3
  48274 		tmp[0+i*int32(4)] = (a0 + a1) * int32(8)                                               // 14b                      [-8160,8160]
  48275 		tmp[int32(1)+i*int32(4)] = (a2*int32(2217) + a3*int32(5352) + int32(1812)) >> int32(9) // [-7536,7542]
  48276 		tmp[int32(2)+i*int32(4)] = (a0 - a1) * int32(8)
  48277 		tmp[int32(3)+i*int32(4)] = (a3*int32(2217) - a2*int32(5352) + int32(937)) >> int32(9)
  48278 		goto _1
  48279 	_1:
  48280 		;
  48281 		i = i + 1
  48282 		src = src + uintptr(BPS)
  48283 		ref = ref + uintptr(BPS)
  48284 	}
  48285 	i = 0
  48286 	for {
  48287 		if !(i < int32(4)) {
  48288 			break
  48289 		}
  48290 		a01 = tmp[0+i] + tmp[int32(12)+i] // 15b
  48291 		a11 = tmp[int32(4)+i] + tmp[int32(8)+i]
  48292 		a21 = tmp[int32(4)+i] - tmp[int32(8)+i]
  48293 		a31 = tmp[0+i] - tmp[int32(12)+i]
  48294 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16((a01 + a11 + int32(7)) >> int32(4)) // 12b
  48295 		**(**int16_t)(__ccgo_up(out + uintptr(int32(4)+i)*2)) = int16((a21*int32(2217)+a31*int32(5352)+int32(12000))>>int32(16) + libc.BoolInt32(a31 != 0))
  48296 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16((a01 - a11 + int32(7)) >> int32(4))
  48297 		**(**int16_t)(__ccgo_up(out + uintptr(int32(12)+i)*2)) = int16((a31*libc.Int32FromInt32(2217) - a21*libc.Int32FromInt32(5352) + libc.Int32FromInt32(51000)) >> libc.Int32FromInt32(16))
  48298 		goto _2
  48299 	_2:
  48300 		;
  48301 		i = i + 1
  48302 	}
  48303 }
  48304 
  48305 func FTransform2_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48306 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, out)
  48307 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src+uintptr(4), ref+uintptr(4), out+uintptr(16)*2)
  48308 }
  48309 
  48310 func FTransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  48311 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i int32
  48312 	var tmp [16]int32_t
  48313 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, tmp
  48314 	i = 0
  48315 	for {
  48316 		if !(i < int32(4)) {
  48317 			break
  48318 		}
  48319 		a0 = int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2))) // 13b
  48320 		a1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2)))
  48321 		a2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2)))
  48322 		a3 = int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2)))
  48323 		tmp[0+i*int32(4)] = a0 + a1 // 14b
  48324 		tmp[int32(1)+i*int32(4)] = a3 + a2
  48325 		tmp[int32(2)+i*int32(4)] = a3 - a2
  48326 		tmp[int32(3)+i*int32(4)] = a0 - a1
  48327 		goto _1
  48328 	_1:
  48329 		;
  48330 		i = i + 1
  48331 		in = in + uintptr(64)*2
  48332 	}
  48333 	i = 0
  48334 	for {
  48335 		if !(i < int32(4)) {
  48336 			break
  48337 		}
  48338 		a01 = tmp[0+i] + tmp[int32(8)+i] // 15b
  48339 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  48340 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  48341 		a31 = tmp[0+i] - tmp[int32(8)+i]
  48342 		b0 = a01 + a11 // 16b
  48343 		b1 = a31 + a21
  48344 		b2 = a31 - a21
  48345 		b3 = a01 - a11
  48346 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16(b0 >> int32(1)) // 15b
  48347 		**(**int16_t)(__ccgo_up(out + uintptr(int32(4)+i)*2)) = int16(b1 >> int32(1))
  48348 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16(b2 >> int32(1))
  48349 		**(**int16_t)(__ccgo_up(out + uintptr(int32(12)+i)*2)) = int16(b3 >> int32(1))
  48350 		goto _2
  48351 	_2:
  48352 		;
  48353 		i = i + 1
  48354 	}
  48355 }
  48356 
  48357 //------------------------------------------------------------------------------
  48358 // Intra predictions
  48359 
  48360 func Fill(tls *libc.TLS, dst uintptr, value int32, size int32) {
  48361 	var j int32
  48362 	_ = j
  48363 	j = 0
  48364 	for {
  48365 		if !(j < size) {
  48366 			break
  48367 		}
  48368 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), value, libc.Uint64FromInt32(size))
  48369 		goto _1
  48370 	_1:
  48371 		;
  48372 		j = j + 1
  48373 	}
  48374 }
  48375 
  48376 func VerticalPred(tls *libc.TLS, dst uintptr, top uintptr, size int32) {
  48377 	var j int32
  48378 	_ = j
  48379 	if top != libc.UintptrFromInt32(0) {
  48380 		j = 0
  48381 		for {
  48382 			if !(j < size) {
  48383 				break
  48384 			}
  48385 			libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), top, libc.Uint64FromInt32(size))
  48386 			goto _1
  48387 		_1:
  48388 			;
  48389 			j = j + 1
  48390 		}
  48391 	} else {
  48392 		Fill(tls, dst, int32(127), size)
  48393 	}
  48394 }
  48395 
  48396 func HorizontalPred(tls *libc.TLS, dst uintptr, left uintptr, size int32) {
  48397 	var j int32
  48398 	_ = j
  48399 	if left != libc.UintptrFromInt32(0) {
  48400 		j = 0
  48401 		for {
  48402 			if !(j < size) {
  48403 				break
  48404 			}
  48405 			libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(j)))), libc.Uint64FromInt32(size))
  48406 			goto _1
  48407 		_1:
  48408 			;
  48409 			j = j + 1
  48410 		}
  48411 	} else {
  48412 		Fill(tls, dst, int32(129), size)
  48413 	}
  48414 }
  48415 
  48416 func TrueMotion1(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32) {
  48417 	var clip, clip_table uintptr
  48418 	var x, y int32
  48419 	_, _, _, _ = clip, clip_table, x, y
  48420 	if left != libc.UintptrFromInt32(0) {
  48421 		if top != libc.UintptrFromInt32(0) {
  48422 			clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(-libc.Int32FromInt32(1)))))
  48423 			y = 0
  48424 			for {
  48425 				if !(y < size) {
  48426 					break
  48427 				}
  48428 				clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
  48429 				x = 0
  48430 				for {
  48431 					if !(x < size) {
  48432 						break
  48433 					}
  48434 					**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  48435 					goto _2
  48436 				_2:
  48437 					;
  48438 					x = x + 1
  48439 				}
  48440 				dst = dst + uintptr(BPS)
  48441 				goto _1
  48442 			_1:
  48443 				;
  48444 				y = y + 1
  48445 			}
  48446 		} else {
  48447 			HorizontalPred(tls, dst, left, size)
  48448 		}
  48449 	} else {
  48450 		// true motion without left samples (hence: with default 129 value)
  48451 		// is equivalent to VE prediction where you just copy the top samples.
  48452 		// Note that if top samples are not available, the default value is
  48453 		// then 129, and not 127 as in the VerticalPred case.
  48454 		if top != libc.UintptrFromInt32(0) {
  48455 			VerticalPred(tls, dst, top, size)
  48456 		} else {
  48457 			Fill(tls, dst, int32(129), size)
  48458 		}
  48459 	}
  48460 }
  48461 
  48462 func DCMode(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32, round int32, shift int32) {
  48463 	var DC, j int32
  48464 	_, _ = DC, j
  48465 	DC = 0
  48466 	if top != libc.UintptrFromInt32(0) {
  48467 		j = 0
  48468 		for {
  48469 			if !(j < size) {
  48470 				break
  48471 			}
  48472 			DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(j))))
  48473 			goto _1
  48474 		_1:
  48475 			;
  48476 			j = j + 1
  48477 		}
  48478 		if left != libc.UintptrFromInt32(0) { // top and left present
  48479 			j = 0
  48480 			for {
  48481 				if !(j < size) {
  48482 					break
  48483 				}
  48484 				DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48485 				goto _2
  48486 			_2:
  48487 				;
  48488 				j = j + 1
  48489 			}
  48490 		} else { // top, but no left
  48491 			DC = DC + DC
  48492 		}
  48493 		DC = (DC + round) >> shift
  48494 	} else {
  48495 		if left != libc.UintptrFromInt32(0) { // left but no top
  48496 			j = 0
  48497 			for {
  48498 				if !(j < size) {
  48499 					break
  48500 				}
  48501 				DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48502 				goto _3
  48503 			_3:
  48504 				;
  48505 				j = j + 1
  48506 			}
  48507 			DC = DC + DC
  48508 			DC = (DC + round) >> shift
  48509 		} else { // no top, no left, nothing.
  48510 			DC = int32(0x80)
  48511 		}
  48512 	}
  48513 	Fill(tls, dst, DC, size)
  48514 }
  48515 
  48516 //------------------------------------------------------------------------------
  48517 // Chroma 8x8 prediction (paragraph 12.2)
  48518 
  48519 func IntraChromaPreds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48520 	// U block
  48521 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48522 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48523 	HorizontalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, int32(8))
  48524 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48525 	// V block
  48526 	dst = dst + uintptr(8)
  48527 	if top != libc.UintptrFromInt32(0) {
  48528 		top = top + uintptr(8)
  48529 	}
  48530 	if left != libc.UintptrFromInt32(0) {
  48531 		left = left + uintptr(16)
  48532 	}
  48533 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48534 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48535 	HorizontalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, int32(8))
  48536 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48537 }
  48538 
  48539 //------------------------------------------------------------------------------
  48540 // luma 16x16 prediction (paragraph 12.3)
  48541 
  48542 func Intra16Preds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48543 	DCMode(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(16), int32(16), int32(5))
  48544 	VerticalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, top, int32(16))
  48545 	HorizontalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, int32(16))
  48546 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, top, int32(16))
  48547 }
  48548 
  48549 //------------------------------------------------------------------------------
  48550 // luma 4x4 prediction
  48551 
  48552 // C documentation
  48553 //
  48554 //	// vertical
  48555 func VE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48556 	bp := tls.Alloc(16)
  48557 	defer tls.Free(16)
  48558 	var i int32
  48559 	var _ /* vals at bp+0 */ [4]uint8_t
  48560 	_ = i
  48561 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  48562 		0: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48563 		1: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48564 		2: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48565 		3: libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2))) + libc.Int32FromInt32(2)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 4))) + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2)),
  48566 	}
  48567 	i = 0
  48568 	for {
  48569 		if !(i < int32(4)) {
  48570 			break
  48571 		}
  48572 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  48573 		goto _1
  48574 	_1:
  48575 		;
  48576 		i = i + 1
  48577 	}
  48578 }
  48579 
  48580 // C documentation
  48581 //
  48582 //	// horizontal
  48583 func HE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48584 	bp := tls.Alloc(16)
  48585 	defer tls.Free(16)
  48586 	var I, J, K, L, X int32
  48587 	var v1 uint32_t
  48588 	_, _, _, _, _, _ = I, J, K, L, X, v1
  48589 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48590 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48591 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48592 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48593 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48594 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((X+libc.Int32FromInt32(2)*I+J+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48595 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48596 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48597 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((I+libc.Int32FromInt32(2)*J+K+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48598 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48599 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48600 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((J+libc.Int32FromInt32(2)*K+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48601 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48602 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48603 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((K+libc.Int32FromInt32(2)*L+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48604 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48605 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48606 }
  48607 
  48608 func DC4(tls *libc.TLS, dst uintptr, top uintptr) {
  48609 	var dc uint32_t
  48610 	var i int32
  48611 	_, _ = dc, i
  48612 	dc = uint32(4)
  48613 	i = 0
  48614 	for {
  48615 		if !(i < int32(4)) {
  48616 			break
  48617 		}
  48618 		dc = dc + libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(i))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(5)+i)))))
  48619 		goto _1
  48620 	_1:
  48621 		;
  48622 		i = i + 1
  48623 	}
  48624 	Fill(tls, dst, libc.Int32FromUint32(dc>>int32(3)), int32(4))
  48625 }
  48626 
  48627 func RD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48628 	var A, B, C, D, I, J, K, L, X int32
  48629 	var v1, v2, v3 uint8_t
  48630 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3
  48631 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48632 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48633 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48634 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48635 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48636 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48637 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48638 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48639 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48640 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48641 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48642 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48643 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48644 	v2 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48645 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48646 	v1 = v2
  48647 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48648 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48649 	v3 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48650 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48651 	v2 = v3
  48652 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48653 	v1 = v2
  48654 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48655 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48656 	v2 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48657 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48658 	v1 = v2
  48659 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48660 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48661 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48662 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48663 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48664 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*C + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48665 }
  48666 
  48667 func LD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48668 	var A, B, C, D, E, F, G, H int32
  48669 	var v1, v2, v3 uint8_t
  48670 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3
  48671 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48672 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48673 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48674 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48675 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 4)))
  48676 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 5)))
  48677 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 6)))
  48678 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 7)))
  48679 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48680 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48681 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48682 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48683 	v2 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48684 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48685 	v1 = v2
  48686 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48687 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48688 	v3 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48689 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48690 	v2 = v3
  48691 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48692 	v1 = v2
  48693 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48694 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48695 	v2 = libc.Uint8FromInt32((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48696 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48697 	v1 = v2
  48698 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48699 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48700 	v1 = libc.Uint8FromInt32((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48701 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48702 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48703 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((G + libc.Int32FromInt32(2)*H + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48704 }
  48705 
  48706 func VR4(tls *libc.TLS, dst uintptr, top uintptr) {
  48707 	var A, B, C, D, I, J, K, X int32
  48708 	var v1 uint8_t
  48709 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1
  48710 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48711 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48712 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48713 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48714 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48715 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48716 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48717 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48718 	v1 = libc.Uint8FromInt32((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48719 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48720 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48721 	v1 = libc.Uint8FromInt32((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48722 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48723 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48724 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48725 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48726 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48727 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48728 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48729 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48730 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48731 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48732 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48733 	v1 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48734 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48735 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48736 	v1 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48737 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48738 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48739 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48740 }
  48741 
  48742 func VL4(tls *libc.TLS, dst uintptr, top uintptr) {
  48743 	var A, B, C, D, E, F, G, H int32
  48744 	var v1 uint8_t
  48745 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1
  48746 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48747 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48748 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48749 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48750 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 4)))
  48751 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 5)))
  48752 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 6)))
  48753 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 7)))
  48754 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48755 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48756 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48757 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48758 	v1 = libc.Uint8FromInt32((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48759 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48760 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48761 	v1 = libc.Uint8FromInt32((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48762 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48763 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48764 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48765 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48766 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48767 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48768 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48769 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48770 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48771 	v1 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48772 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48773 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48774 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48775 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48776 }
  48777 
  48778 func HU4(tls *libc.TLS, dst uintptr, top uintptr) {
  48779 	var I, J, K, L int32
  48780 	var v1, v2, v3, v4, v5 uint8_t
  48781 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5
  48782 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48783 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48784 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48785 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48786 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((I + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48787 	v1 = libc.Uint8FromInt32((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48788 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48789 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48790 	v1 = libc.Uint8FromInt32((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48791 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48792 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48793 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48794 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48795 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48796 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48797 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48798 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48799 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48800 	v5 = libc.Uint8FromInt32(L)
  48801 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  48802 	v4 = v5
  48803 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  48804 	v3 = v4
  48805 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48806 	v2 = v3
  48807 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48808 	v1 = v2
  48809 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48810 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48811 }
  48812 
  48813 func HD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48814 	var A, B, C, I, J, K, L, X int32
  48815 	var v1 uint8_t
  48816 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1
  48817 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48818 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48819 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48820 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48821 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48822 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48823 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48824 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48825 	v1 = libc.Uint8FromInt32((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48826 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48827 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48828 	v1 = libc.Uint8FromInt32((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48829 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48830 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48831 	v1 = libc.Uint8FromInt32((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48832 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48833 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48834 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((L + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48835 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48836 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48837 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48838 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48839 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48840 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48841 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48842 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48843 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48844 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48845 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48846 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = libc.Uint8FromInt32((L + libc.Int32FromInt32(2)*K + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48847 }
  48848 
  48849 func TM4(tls *libc.TLS, dst uintptr, top uintptr) {
  48850 	var clip, clip_table uintptr
  48851 	var x, y int32
  48852 	_, _, _, _ = clip, clip_table, x, y
  48853 	clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48854 	y = 0
  48855 	for {
  48856 		if !(y < int32(4)) {
  48857 			break
  48858 		}
  48859 		clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(2)-y))))
  48860 		x = 0
  48861 		for {
  48862 			if !(x < int32(4)) {
  48863 				break
  48864 			}
  48865 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  48866 			goto _2
  48867 		_2:
  48868 			;
  48869 			x = x + 1
  48870 		}
  48871 		dst = dst + uintptr(BPS)
  48872 		goto _1
  48873 	_1:
  48874 		;
  48875 		y = y + 1
  48876 	}
  48877 }
  48878 
  48879 // C documentation
  48880 //
  48881 //	// Left samples are top[-5 .. -2], top_left is top[-1], top are
  48882 //	// located at top[0..3], and top right is top[4..7]
  48883 func Intra4Preds_C(tls *libc.TLS, dst uintptr, top uintptr) {
  48884 	DC4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0))+dst, top)
  48885 	TM4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(4))+dst, top)
  48886 	VE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(8))+dst, top)
  48887 	HE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(12))+dst, top)
  48888 	RD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(16))+dst, top)
  48889 	VR4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(20))+dst, top)
  48890 	LD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(24))+dst, top)
  48891 	VL4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(28))+dst, top)
  48892 	HD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS))+dst, top)
  48893 	HU4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4))+dst, top)
  48894 }
  48895 
  48896 //------------------------------------------------------------------------------
  48897 // Metric
  48898 
  48899 func GetSSE(tls *libc.TLS, a uintptr, b uintptr, w int32, h int32) (r int32) {
  48900 	var count, diff, x, y int32
  48901 	_, _, _, _ = count, diff, x, y
  48902 	count = 0
  48903 	y = 0
  48904 	for {
  48905 		if !(y < h) {
  48906 			break
  48907 		}
  48908 		x = 0
  48909 		for {
  48910 			if !(x < w) {
  48911 				break
  48912 			}
  48913 			diff = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a + uintptr(x)))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(b + uintptr(x))))
  48914 			count = count + diff*diff
  48915 			goto _2
  48916 		_2:
  48917 			;
  48918 			x = x + 1
  48919 		}
  48920 		a = a + uintptr(BPS)
  48921 		b = b + uintptr(BPS)
  48922 		goto _1
  48923 	_1:
  48924 		;
  48925 		y = y + 1
  48926 	}
  48927 	return count
  48928 }
  48929 
  48930 func SSE16x16_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  48931 	return GetSSE(tls, a, b, int32(16), int32(16))
  48932 }
  48933 
  48934 func SSE16x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  48935 	return GetSSE(tls, a, b, int32(16), int32(8))
  48936 }
  48937 
  48938 func SSE8x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  48939 	return GetSSE(tls, a, b, int32(8), int32(8))
  48940 }
  48941 
  48942 func SSE4x4_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  48943 	return GetSSE(tls, a, b, int32(4), int32(4))
  48944 }
  48945 
  48946 func Mean16x4_C(tls *libc.TLS, ref uintptr, dc uintptr) {
  48947 	var avg uint32_t
  48948 	var k, x, y int32
  48949 	_, _, _, _ = avg, k, x, y
  48950 	k = 0
  48951 	for {
  48952 		if !(k < int32(4)) {
  48953 			break
  48954 		}
  48955 		avg = uint32(0)
  48956 		y = 0
  48957 		for {
  48958 			if !(y < int32(4)) {
  48959 				break
  48960 			}
  48961 			x = 0
  48962 			for {
  48963 				if !(x < int32(4)) {
  48964 					break
  48965 				}
  48966 				avg = avg + uint32(**(**uint8_t)(__ccgo_up(ref + uintptr(x+y*int32(BPS)))))
  48967 				goto _3
  48968 			_3:
  48969 				;
  48970 				x = x + 1
  48971 			}
  48972 			goto _2
  48973 		_2:
  48974 			;
  48975 			y = y + 1
  48976 		}
  48977 		**(**uint32_t)(__ccgo_up(dc + uintptr(k)*4)) = avg
  48978 		ref = ref + uintptr(4) // go to next 4x4 block.
  48979 		goto _1
  48980 	_1:
  48981 		;
  48982 		k = k + 1
  48983 	}
  48984 }
  48985 
  48986 //------------------------------------------------------------------------------
  48987 // Texture distortion
  48988 //
  48989 // We try to match the spectral content (weighted) between source and
  48990 // reconstructed samples.
  48991 
  48992 // C documentation
  48993 //
  48994 //	// Hadamard transform
  48995 //	// Returns the weighted sum of the absolute value of transformed coefficients.
  48996 //	// w[] contains a row-major 4 by 4 symmetric matrix.
  48997 func TTransform(tls *libc.TLS, in uintptr, w uintptr) (r int32) {
  48998 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum int32
  48999 	var tmp [16]int32
  49000 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum, tmp
  49001 	sum = 0
  49002 	// horizontal pass
  49003 	i = 0
  49004 	for {
  49005 		if !(i < int32(4)) {
  49006 			break
  49007 		}
  49008 		a0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 2)))
  49009 		a1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 1))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 3)))
  49010 		a2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 1))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 3)))
  49011 		a3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 2)))
  49012 		tmp[0+i*int32(4)] = a0 + a1
  49013 		tmp[int32(1)+i*int32(4)] = a3 + a2
  49014 		tmp[int32(2)+i*int32(4)] = a3 - a2
  49015 		tmp[int32(3)+i*int32(4)] = a0 - a1
  49016 		goto _1
  49017 	_1:
  49018 		;
  49019 		i = i + 1
  49020 		in = in + uintptr(BPS)
  49021 	}
  49022 	// vertical pass
  49023 	i = 0
  49024 	for {
  49025 		if !(i < int32(4)) {
  49026 			break
  49027 		}
  49028 		a01 = tmp[0+i] + tmp[int32(8)+i]
  49029 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  49030 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  49031 		a31 = tmp[0+i] - tmp[int32(8)+i]
  49032 		b0 = a01 + a11
  49033 		b1 = a31 + a21
  49034 		b2 = a31 - a21
  49035 		b3 = a01 - a11
  49036 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w)))*libc.Xabs(tls, b0)
  49037 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w + 4*2)))*libc.Xabs(tls, b1)
  49038 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w + 8*2)))*libc.Xabs(tls, b2)
  49039 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w + 12*2)))*libc.Xabs(tls, b3)
  49040 		goto _2
  49041 	_2:
  49042 		;
  49043 		i = i + 1
  49044 		w += 2
  49045 	}
  49046 	return sum
  49047 }
  49048 
  49049 func Disto4x4_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49050 	var sum1, sum2 int32
  49051 	_, _ = sum1, sum2
  49052 	sum1 = TTransform(tls, a, w)
  49053 	sum2 = TTransform(tls, b, w)
  49054 	return libc.Xabs(tls, sum2-sum1) >> int32(5)
  49055 }
  49056 
  49057 func Disto16x16_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49058 	var D, x, y int32
  49059 	_, _, _ = D, x, y
  49060 	D = 0
  49061 	y = 0
  49062 	for {
  49063 		if !(y < libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)) {
  49064 			break
  49065 		}
  49066 		x = 0
  49067 		for {
  49068 			if !(x < int32(16)) {
  49069 				break
  49070 			}
  49071 			D = D + Disto4x4_C(tls, a+uintptr(x)+uintptr(y), b+uintptr(x)+uintptr(y), w)
  49072 			goto _2
  49073 		_2:
  49074 			;
  49075 			x = x + int32(4)
  49076 		}
  49077 		goto _1
  49078 	_1:
  49079 		;
  49080 		y = y + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)
  49081 	}
  49082 	return D
  49083 }
  49084 
  49085 //------------------------------------------------------------------------------
  49086 // Quantization
  49087 //
  49088 
  49089 var kZigzag2 = [16]uint8_t{
  49090 	1:  uint8(1),
  49091 	2:  uint8(4),
  49092 	3:  uint8(8),
  49093 	4:  uint8(5),
  49094 	5:  uint8(2),
  49095 	6:  uint8(3),
  49096 	7:  uint8(6),
  49097 	8:  uint8(9),
  49098 	9:  uint8(12),
  49099 	10: uint8(13),
  49100 	11: uint8(10),
  49101 	12: uint8(7),
  49102 	13: uint8(11),
  49103 	14: uint8(14),
  49104 	15: uint8(15),
  49105 }
  49106 
  49107 // C documentation
  49108 //
  49109 //	// Simple quantization
  49110 func QuantizeBlock_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49111 	var B1, Q, coeff, iQ1 uint32_t
  49112 	var j, last, level, n1, sign, v2, v3 int32
  49113 	_, _, _, _, _, _, _, _, _, _, _ = B1, Q, coeff, iQ1, j, last, level, n1, sign, v2, v3
  49114 	last = -int32(1)
  49115 	n1 = 0
  49116 	for {
  49117 		if !(n1 < int32(16)) {
  49118 			break
  49119 		}
  49120 		j = libc.Int32FromUint8(kZigzag2[n1])
  49121 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) < libc.Int32FromInt32(0))
  49122 		if sign != 0 {
  49123 			v2 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49124 		} else {
  49125 			v2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49126 		}
  49127 		coeff = libc.Uint32FromInt32(v2 + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j)*2))))
  49128 		if coeff > **(**uint32_t)(__ccgo_up(mtx + 128 + uintptr(j)*4)) {
  49129 			Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j)*2)))
  49130 			iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j)*2)))
  49131 			B1 = **(**uint32_t)(__ccgo_up(mtx + 64 + uintptr(j)*4))
  49132 			v3 = libc.Int32FromUint32((coeff*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  49133 			goto _4
  49134 		_4:
  49135 			level = v3
  49136 			if level > int32(MAX_LEVEL) {
  49137 				level = int32(MAX_LEVEL)
  49138 			}
  49139 			if sign != 0 {
  49140 				level = -level
  49141 			}
  49142 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = int16(level * libc.Int32FromUint32(Q))
  49143 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(level)
  49144 			if level != 0 {
  49145 				last = n1
  49146 			}
  49147 		} else {
  49148 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = 0
  49149 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = 0
  49150 		}
  49151 		goto _1
  49152 	_1:
  49153 		;
  49154 		n1 = n1 + 1
  49155 	}
  49156 	return libc.BoolInt32(last >= 0)
  49157 }
  49158 
  49159 func Quantize2Blocks_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49160 	var nz int32
  49161 	_ = nz
  49162 	nz = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlock})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, out+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, mtx) << 0
  49163 	nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlock})))(tls, in+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2, out+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2, mtx)<<int32(1)
  49164 	return nz
  49165 }
  49166 
  49167 //------------------------------------------------------------------------------
  49168 // Block copy
  49169 
  49170 func Copy(tls *libc.TLS, src uintptr, dst uintptr, w int32, h int32) {
  49171 	var y int32
  49172 	_ = y
  49173 	y = 0
  49174 	for {
  49175 		if !(y < h) {
  49176 			break
  49177 		}
  49178 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(w))
  49179 		src = src + uintptr(BPS)
  49180 		dst = dst + uintptr(BPS)
  49181 		goto _1
  49182 	_1:
  49183 		;
  49184 		y = y + 1
  49185 	}
  49186 }
  49187 
  49188 func Copy4x4_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49189 	Copy(tls, src, dst, int32(4), int32(4))
  49190 }
  49191 
  49192 func Copy16x8_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49193 	Copy(tls, src, dst, int32(16), int32(8))
  49194 }
  49195 
  49196 func VP8EncDspInit(tls *libc.TLS) {
  49197 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49198 		goto _1
  49199 	}
  49200 	VP8EncDspInit_body(tls)
  49201 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49202 	goto _2
  49203 _2:
  49204 	;
  49205 	goto _1
  49206 _1: /**/ //
  49207 }
  49208 
  49209 var VP8EncDspInit_body_last_cpuinfo_used = uintptr(0)
  49210 
  49211 func init() {
  49212 	p := unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)
  49213 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))
  49214 }
  49215 
  49216 func VP8EncDspInit_body(tls *libc.TLS) {
  49217 	VP8DspInit(tls) // common inverse transforms
  49218 	InitTables(tls)
  49219 	// default C implementations
  49220 	VP8ITransform = __ccgo_fp(ITransform_C)
  49221 	VP8FTransform = __ccgo_fp(FTransform_C)
  49222 	VP8FTransformWHT = __ccgo_fp(FTransformWHT_C)
  49223 	VP8TDisto4x4 = __ccgo_fp(Disto4x4_C)
  49224 	VP8TDisto16x16 = __ccgo_fp(Disto16x16_C)
  49225 	VP8CollectHistogram = __ccgo_fp(CollectHistogram_C)
  49226 	VP8SSE16x16 = __ccgo_fp(SSE16x16_C)
  49227 	VP8SSE16x8 = __ccgo_fp(SSE16x8_C)
  49228 	VP8SSE8x8 = __ccgo_fp(SSE8x8_C)
  49229 	VP8SSE4x4 = __ccgo_fp(SSE4x4_C)
  49230 	VP8EncQuantizeBlock = __ccgo_fp(QuantizeBlock_C)
  49231 	VP8EncQuantize2Blocks = __ccgo_fp(Quantize2Blocks_C)
  49232 	VP8EncQuantizeBlockWHT = __ccgo_fp(QuantizeBlock_C)
  49233 	VP8EncPredLuma4 = __ccgo_fp(Intra4Preds_C)
  49234 	VP8EncPredLuma16 = __ccgo_fp(Intra16Preds_C)
  49235 	VP8FTransform2 = __ccgo_fp(FTransform2_C)
  49236 	VP8EncPredChroma8 = __ccgo_fp(IntraChromaPreds_C)
  49237 	VP8Mean16x4 = __ccgo_fp(Mean16x4_C)
  49238 	VP8Copy4x4 = __ccgo_fp(Copy4x4_C)
  49239 	VP8Copy16x8 = __ccgo_fp(Copy16x8_C)
  49240 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  49241 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49242 	}
  49243 }
  49244 
  49245 func VP8EncDspInitMIPS32(tls *libc.TLS) {
  49246 }
  49247 
  49248 func VP8EncDspInitMIPSdspR2(tls *libc.TLS) {
  49249 }
  49250 
  49251 func VP8EncDspInitMSA(tls *libc.TLS) {
  49252 }
  49253 
  49254 func VP8EncDspInitNEON(tls *libc.TLS) {
  49255 }
  49256 
  49257 func VP8EncDspInitSSE2(tls *libc.TLS) {
  49258 }
  49259 
  49260 func VP8EncDspInitSSE41(tls *libc.TLS) {
  49261 }
  49262 
  49263 // Copyright 2010 Google Inc. All Rights Reserved.
  49264 //
  49265 // Use of this source code is governed by a BSD-style license
  49266 // that can be found in the COPYING file in the root of the source
  49267 // tree. An additional intellectual property rights grant can be found
  49268 // in the file PATENTS. All contributing project authors may
  49269 // be found in the AUTHORS file in the root of the source tree.
  49270 // -----------------------------------------------------------------------------
  49271 //
  49272 //  Common types + memory wrappers
  49273 //
  49274 // Author: Skal (pascal.massimino@gmail.com)
  49275 
  49276 //------------------------------------------------------------------------------
  49277 // Helpful macro.
  49278 
  49279 func PredictLine_C(tls *libc.TLS, src uintptr, pred uintptr, dst uintptr, length int32) {
  49280 	var i int32
  49281 	_ = i
  49282 	i = 0
  49283 	for {
  49284 		if !(i < length) {
  49285 			break
  49286 		}
  49287 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + uintptr(i)))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(pred + uintptr(i)))))
  49288 		goto _1
  49289 	_1:
  49290 		;
  49291 		i = i + 1
  49292 	}
  49293 }
  49294 
  49295 //------------------------------------------------------------------------------
  49296 // Horizontal filter.
  49297 
  49298 func DoHorizontalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49299 	var preds uintptr
  49300 	var row int32
  49301 	_, _ = preds, row
  49302 	preds = in
  49303 	// Leftmost pixel is the same as input for topmost scanline.
  49304 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49305 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49306 	preds = preds + uintptr(stride)
  49307 	in = in + uintptr(stride)
  49308 	out = out + uintptr(stride)
  49309 	// Filter line-by-line.
  49310 	row = int32(1)
  49311 	for {
  49312 		if !(row < height) {
  49313 			break
  49314 		}
  49315 		// Leftmost pixel is predicted from above.
  49316 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49317 		PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49318 		preds = preds + uintptr(stride)
  49319 		in = in + uintptr(stride)
  49320 		out = out + uintptr(stride)
  49321 		goto _1
  49322 	_1:
  49323 		;
  49324 		row = row + 1
  49325 	}
  49326 }
  49327 
  49328 //------------------------------------------------------------------------------
  49329 // Vertical filter.
  49330 
  49331 func DoVerticalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49332 	var preds uintptr
  49333 	var row int32
  49334 	_, _ = preds, row
  49335 	preds = in
  49336 	// Very first top-left pixel is copied.
  49337 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49338 	// Rest of top scan-line is left-predicted.
  49339 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49340 	in = in + uintptr(stride)
  49341 	out = out + uintptr(stride)
  49342 	// Filter line-by-line.
  49343 	row = int32(1)
  49344 	for {
  49345 		if !(row < height) {
  49346 			break
  49347 		}
  49348 		PredictLine_C(tls, in, preds, out, width)
  49349 		preds = preds + uintptr(stride)
  49350 		in = in + uintptr(stride)
  49351 		out = out + uintptr(stride)
  49352 		goto _1
  49353 	_1:
  49354 		;
  49355 		row = row + 1
  49356 	}
  49357 }
  49358 
  49359 //------------------------------------------------------------------------------
  49360 // Gradient filter.
  49361 
  49362 func GradientPredictor_C(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  49363 	var g, v1, v2 int32
  49364 	_, _, _ = g, v1, v2
  49365 	g = libc.Int32FromUint8(a) + libc.Int32FromUint8(b) - libc.Int32FromUint8(c)
  49366 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  49367 		v1 = g
  49368 	} else {
  49369 		if g < 0 {
  49370 			v2 = 0
  49371 		} else {
  49372 			v2 = int32(255)
  49373 		}
  49374 		v1 = v2
  49375 	}
  49376 	return v1 // clip to 8bit
  49377 }
  49378 
  49379 func DoGradientFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49380 	var pred, row, w int32
  49381 	var preds uintptr
  49382 	_, _, _, _ = pred, preds, row, w
  49383 	preds = in
  49384 	// left prediction for top scan-line
  49385 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49386 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49387 	preds = preds + uintptr(stride)
  49388 	in = in + uintptr(stride)
  49389 	out = out + uintptr(stride)
  49390 	// Filter line-by-line.
  49391 	row = int32(1)
  49392 	for {
  49393 		if !(row < height) {
  49394 			break
  49395 		}
  49396 		// leftmost pixel: predict from above.
  49397 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49398 		w = int32(1)
  49399 		for {
  49400 			if !(w < width) {
  49401 				break
  49402 			}
  49403 			pred = GradientPredictor_C(tls, **(**uint8_t)(__ccgo_up(preds + uintptr(w-int32(1)))), **(**uint8_t)(__ccgo_up(preds + uintptr(w-stride))), **(**uint8_t)(__ccgo_up(preds + uintptr(w-stride-int32(1)))))
  49404 			**(**uint8_t)(__ccgo_up(out + uintptr(w))) = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(w)))) - pred)
  49405 			goto _2
  49406 		_2:
  49407 			;
  49408 			w = w + 1
  49409 		}
  49410 		preds = preds + uintptr(stride)
  49411 		in = in + uintptr(stride)
  49412 		out = out + uintptr(stride)
  49413 		goto _1
  49414 	_1:
  49415 		;
  49416 		row = row + 1
  49417 	}
  49418 }
  49419 
  49420 //------------------------------------------------------------------------------
  49421 
  49422 func HorizontalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49423 	DoHorizontalFilter_C(tls, data, width, height, stride, filtered_data)
  49424 }
  49425 
  49426 func VerticalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49427 	DoVerticalFilter_C(tls, data, width, height, stride, filtered_data)
  49428 }
  49429 
  49430 func GradientFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49431 	DoGradientFilter_C(tls, data, width, height, stride, filtered_data)
  49432 }
  49433 
  49434 //------------------------------------------------------------------------------
  49435 
  49436 func NoneUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49437 	_ = prev
  49438 	if out != in {
  49439 		libc.Xmemcpy(tls, out, in, libc.Uint64FromInt32(width)*uint64(1))
  49440 	}
  49441 }
  49442 
  49443 func HorizontalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49444 	var i, v1 int32
  49445 	var pred uint8_t
  49446 	_, _, _ = i, pred, v1
  49447 	if prev == libc.UintptrFromInt32(0) {
  49448 		v1 = 0
  49449 	} else {
  49450 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prev)))
  49451 	}
  49452 	pred = libc.Uint8FromInt32(v1)
  49453 	i = 0
  49454 	for {
  49455 		if !(i < width) {
  49456 			break
  49457 		}
  49458 		**(**uint8_t)(__ccgo_up(out + uintptr(i))) = libc.Uint8FromInt32(libc.Int32FromUint8(pred) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49459 		pred = **(**uint8_t)(__ccgo_up(out + uintptr(i)))
  49460 		goto _2
  49461 	_2:
  49462 		;
  49463 		i = i + 1
  49464 	}
  49465 }
  49466 
  49467 func VerticalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49468 	var i int32
  49469 	_ = i
  49470 	if prev == libc.UintptrFromInt32(0) {
  49471 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49472 	} else {
  49473 		i = 0
  49474 		for {
  49475 			if !(i < width) {
  49476 				break
  49477 			}
  49478 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prev + uintptr(i)))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49479 			goto _1
  49480 		_1:
  49481 			;
  49482 			i = i + 1
  49483 		}
  49484 	}
  49485 }
  49486 
  49487 func GradientUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49488 	var i int32
  49489 	var left, top, top_left uint8_t
  49490 	_, _, _, _ = i, left, top, top_left
  49491 	if prev == libc.UintptrFromInt32(0) {
  49492 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49493 	} else {
  49494 		top = **(**uint8_t)(__ccgo_up(prev))
  49495 		top_left = top
  49496 		left = top
  49497 		i = 0
  49498 		for {
  49499 			if !(i < width) {
  49500 				break
  49501 			}
  49502 			top = **(**uint8_t)(__ccgo_up(prev + uintptr(i))) // need to read this first, in case prev==out
  49503 			left = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(i)))) + GradientPredictor_C(tls, left, top, top_left))
  49504 			top_left = top
  49505 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = left
  49506 			goto _1
  49507 		_1:
  49508 			;
  49509 			i = i + 1
  49510 		}
  49511 	}
  49512 }
  49513 
  49514 func VP8FiltersInit(tls *libc.TLS) {
  49515 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49516 		goto _1
  49517 	}
  49518 	VP8FiltersInit_body(tls)
  49519 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49520 	goto _2
  49521 _2:
  49522 	;
  49523 	goto _1
  49524 _1: /**/ //
  49525 }
  49526 
  49527 var VP8FiltersInit_body_last_cpuinfo_used = uintptr(0)
  49528 
  49529 func init() {
  49530 	p := unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)
  49531 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))
  49532 }
  49533 
  49534 func VP8FiltersInit_body(tls *libc.TLS) {
  49535 	WebPUnfilters[int32(WEBP_FILTER_NONE)] = __ccgo_fp(NoneUnfilter_C)
  49536 	WebPUnfilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalUnfilter_C)
  49537 	WebPUnfilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalUnfilter_C)
  49538 	WebPUnfilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientUnfilter_C)
  49539 	WebPFilters[int32(WEBP_FILTER_NONE)] = libc.UintptrFromInt32(0)
  49540 	WebPFilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalFilter_C)
  49541 	WebPFilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalFilter_C)
  49542 	WebPFilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientFilter_C)
  49543 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49544 	}
  49545 }
  49546 
  49547 func VP8FiltersInitMIPSdspR2(tls *libc.TLS) {
  49548 }
  49549 
  49550 func VP8FiltersInitMSA(tls *libc.TLS) {
  49551 }
  49552 
  49553 func VP8FiltersInitNEON(tls *libc.TLS) {
  49554 }
  49555 
  49556 func VP8FiltersInitSSE2(tls *libc.TLS) {
  49557 }
  49558 
  49559 func VP8LDspInitAVX2(tls *libc.TLS) {
  49560 }
  49561 
  49562 const ARGB_BLACK3 = 4278190080
  49563 
  49564 var kHashMul15 = uint32(0x1e35a7bd)
  49565 
  49566 // Copyright 2012 Google Inc. All Rights Reserved.
  49567 //
  49568 // Use of this source code is governed by a BSD-style license
  49569 // that can be found in the COPYING file in the root of the source
  49570 // tree. An additional intellectual property rights grant can be found
  49571 // in the file PATENTS. All contributing project authors may
  49572 // be found in the AUTHORS file in the root of the source tree.
  49573 // -----------------------------------------------------------------------------
  49574 //
  49575 // Misc. common utility functions
  49576 //
  49577 // Authors: Skal (pascal.massimino@gmail.com)
  49578 //          Urvang (urvang@google.com)
  49579 
  49580 // Copyright 2010 Google Inc. All Rights Reserved.
  49581 //
  49582 // Use of this source code is governed by a BSD-style license
  49583 // that can be found in the COPYING file in the root of the source
  49584 // tree. An additional intellectual property rights grant can be found
  49585 // in the file PATENTS. All contributing project authors may
  49586 // be found in the AUTHORS file in the root of the source tree.
  49587 // -----------------------------------------------------------------------------
  49588 //
  49589 //  Main decoding functions for WebP images.
  49590 //
  49591 // Author: Skal (pascal.massimino@gmail.com)
  49592 
  49593 // Copyright 2012 Google Inc. All Rights Reserved.
  49594 //
  49595 // Use of this source code is governed by a BSD-style license
  49596 // that can be found in the COPYING file in the root of the source
  49597 // tree. An additional intellectual property rights grant can be found
  49598 // in the file PATENTS. All contributing project authors may
  49599 // be found in the AUTHORS file in the root of the source tree.
  49600 // -----------------------------------------------------------------------------
  49601 //
  49602 //  Internal header for constants related to WebP file format.
  49603 //
  49604 // Author: Urvang (urvang@google.com)
  49605 
  49606 // Copyright 2010 Google Inc. All Rights Reserved.
  49607 //
  49608 // Use of this source code is governed by a BSD-style license
  49609 // that can be found in the COPYING file in the root of the source
  49610 // tree. An additional intellectual property rights grant can be found
  49611 // in the file PATENTS. All contributing project authors may
  49612 // be found in the AUTHORS file in the root of the source tree.
  49613 // -----------------------------------------------------------------------------
  49614 //
  49615 //  Common types + memory wrappers
  49616 //
  49617 // Author: Skal (pascal.massimino@gmail.com)
  49618 
  49619 //------------------------------------------------------------------------------
  49620 // Image transforms.
  49621 
  49622 func Average2(tls *libc.TLS, a0 uint32_t, a1 uint32_t) (r uint32_t) {
  49623 	return (a0^a1)&uint32(0xfefefefe)>>int32(1) + a0&a1
  49624 }
  49625 
  49626 func Average3(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t) (r uint32_t) {
  49627 	return Average2(tls, Average2(tls, a0, a2), a1)
  49628 }
  49629 
  49630 func Average4(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t, a3 uint32_t) (r uint32_t) {
  49631 	return Average2(tls, Average2(tls, a0, a1), Average2(tls, a2, a3))
  49632 }
  49633 
  49634 func Clip255(tls *libc.TLS, a uint32_t) (r uint32_t) {
  49635 	if a < uint32(256) {
  49636 		return a
  49637 	}
  49638 	// return 0, when a is a negative integer.
  49639 	// return 255, when a is positive.
  49640 	return ^a >> int32(24)
  49641 }
  49642 
  49643 func AddSubtractComponentFull(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  49644 	return libc.Int32FromUint32(Clip255(tls, libc.Uint32FromInt32(a+b-c)))
  49645 }
  49646 
  49647 func ClampedAddSubtractFull(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  49648 	var a, b, g, r int32
  49649 	_, _, _, _ = a, b, g, r
  49650 	a = AddSubtractComponentFull(tls, libc.Int32FromUint32(c0>>int32(24)), libc.Int32FromUint32(c1>>int32(24)), libc.Int32FromUint32(c2>>int32(24)))
  49651 	r = AddSubtractComponentFull(tls, libc.Int32FromUint32(c0>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Int32FromUint32(c1>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  49652 	g = AddSubtractComponentFull(tls, libc.Int32FromUint32(c0>>libc.Int32FromInt32(8)&uint32(0xff)), libc.Int32FromUint32(c1>>libc.Int32FromInt32(8)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  49653 	b = AddSubtractComponentFull(tls, libc.Int32FromUint32(c0&uint32(0xff)), libc.Int32FromUint32(c1&uint32(0xff)), libc.Int32FromUint32(c2&uint32(0xff)))
  49654 	return libc.Uint32FromInt32(a)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  49655 }
  49656 
  49657 func AddSubtractComponentHalf(tls *libc.TLS, a int32, b int32) (r int32) {
  49658 	return libc.Int32FromUint32(Clip255(tls, libc.Uint32FromInt32(a+(a-b)/libc.Int32FromInt32(2))))
  49659 }
  49660 
  49661 func ClampedAddSubtractHalf(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  49662 	var a, b, g, r int32
  49663 	var ave uint32_t
  49664 	_, _, _, _, _ = a, ave, b, g, r
  49665 	ave = Average2(tls, c0, c1)
  49666 	a = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>int32(24)), libc.Int32FromUint32(c2>>int32(24)))
  49667 	r = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  49668 	g = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>libc.Int32FromInt32(8)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  49669 	b = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>libc.Int32FromInt32(0)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(0)&uint32(0xff)))
  49670 	return libc.Uint32FromInt32(a)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  49671 }
  49672 
  49673 // gcc <= 4.9 on ARM generates incorrect code in Select() when Sub3() is
  49674 // inlined.
  49675 
  49676 func Sub3(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  49677 	var pa, pb int32
  49678 	_, _ = pa, pb
  49679 	pb = b - c
  49680 	pa = a - c
  49681 	return libc.Xabs(tls, pb) - libc.Xabs(tls, pa)
  49682 }
  49683 
  49684 func Select(tls *libc.TLS, a uint32_t, b uint32_t, c uint32_t) (r uint32_t) {
  49685 	var pa_minus_pb int32
  49686 	var v1 uint32
  49687 	_, _ = pa_minus_pb, v1
  49688 	pa_minus_pb = Sub3(tls, libc.Int32FromUint32(a>>libc.Int32FromInt32(24)), libc.Int32FromUint32(b>>libc.Int32FromInt32(24)), libc.Int32FromUint32(c>>libc.Int32FromInt32(24))) + Sub3(tls, libc.Int32FromUint32(a>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Int32FromUint32(b>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Int32FromUint32(c>>libc.Int32FromInt32(16)&uint32(0xff))) + Sub3(tls, libc.Int32FromUint32(a>>libc.Int32FromInt32(8)&uint32(0xff)), libc.Int32FromUint32(b>>libc.Int32FromInt32(8)&uint32(0xff)), libc.Int32FromUint32(c>>libc.Int32FromInt32(8)&uint32(0xff))) + Sub3(tls, libc.Int32FromUint32(a&uint32(0xff)), libc.Int32FromUint32(b&uint32(0xff)), libc.Int32FromUint32(c&uint32(0xff)))
  49689 	if pa_minus_pb <= 0 {
  49690 		v1 = a
  49691 	} else {
  49692 		v1 = b
  49693 	}
  49694 	return v1
  49695 }
  49696 
  49697 //------------------------------------------------------------------------------
  49698 // Predictors
  49699 
  49700 func VP8LPredictor0_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49701 	_ = top
  49702 	_ = left
  49703 	return uint32(ARGB_BLACK3)
  49704 }
  49705 
  49706 func VP8LPredictor1_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49707 	_ = top
  49708 	return **(**uint32_t)(__ccgo_up(left))
  49709 }
  49710 
  49711 func VP8LPredictor2_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49712 	_ = left
  49713 	return **(**uint32_t)(__ccgo_up(top))
  49714 }
  49715 
  49716 func VP8LPredictor3_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49717 	_ = left
  49718 	return **(**uint32_t)(__ccgo_up(top + 1*4))
  49719 }
  49720 
  49721 func VP8LPredictor4_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49722 	_ = left
  49723 	return **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4))
  49724 }
  49725 
  49726 func VP8LPredictor5_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49727 	var pred uint32_t
  49728 	_ = pred
  49729 	pred = Average3(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  49730 	return pred
  49731 }
  49732 
  49733 func VP8LPredictor6_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49734 	var pred uint32_t
  49735 	_ = pred
  49736 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49737 	return pred
  49738 }
  49739 
  49740 func VP8LPredictor7_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49741 	var pred uint32_t
  49742 	_ = pred
  49743 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)))
  49744 	return pred
  49745 }
  49746 
  49747 func VP8LPredictor8_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49748 	var pred uint32_t
  49749 	_ = pred
  49750 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)), **(**uint32_t)(__ccgo_up(top)))
  49751 	_ = left
  49752 	return pred
  49753 }
  49754 
  49755 func VP8LPredictor9_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49756 	var pred uint32_t
  49757 	_ = pred
  49758 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  49759 	_ = left
  49760 	return pred
  49761 }
  49762 
  49763 func VP8LPredictor10_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49764 	var pred uint32_t
  49765 	_ = pred
  49766 	pred = Average4(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  49767 	return pred
  49768 }
  49769 
  49770 func VP8LPredictor11_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49771 	var pred uint32_t
  49772 	_ = pred
  49773 	pred = Select(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49774 	return pred
  49775 }
  49776 
  49777 func VP8LPredictor12_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49778 	var pred uint32_t
  49779 	_ = pred
  49780 	pred = ClampedAddSubtractFull(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49781 	return pred
  49782 }
  49783 
  49784 func VP8LPredictor13_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49785 	var pred uint32_t
  49786 	_ = pred
  49787 	pred = ClampedAddSubtractHalf(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49788 	return pred
  49789 }
  49790 
  49791 func PredictorAdd0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49792 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  49793 	var x int32
  49794 	_, _, _, _, _, _ = alpha_and_green, red_and_blue, x, v2, v3, v4
  49795 	_ = upper
  49796 	x = 0
  49797 	for {
  49798 		if !(x < num_pixels) {
  49799 			break
  49800 		}
  49801 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49802 		v3 = uint32(ARGB_BLACK3)
  49803 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49804 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49805 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49806 		goto _5
  49807 	_5:
  49808 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49809 		goto _1
  49810 	_1:
  49811 		;
  49812 		x = x + 1
  49813 	}
  49814 }
  49815 
  49816 func PredictorAdd1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49817 	var alpha_and_green, left, red_and_blue, v2, v3, v4, v5 uint32_t
  49818 	var i int32
  49819 	_, _, _, _, _, _, _, _ = alpha_and_green, i, left, red_and_blue, v2, v3, v4, v5
  49820 	left = **(**uint32_t)(__ccgo_up(out + uintptr(-libc.Int32FromInt32(1))*4))
  49821 	_ = upper
  49822 	i = 0
  49823 	for {
  49824 		if !(i < num_pixels) {
  49825 			break
  49826 		}
  49827 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  49828 		v4 = left
  49829 		alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  49830 		red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  49831 		v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49832 		goto _6
  49833 	_6:
  49834 		v2 = v5
  49835 		left = v2
  49836 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v2
  49837 		goto _1
  49838 	_1:
  49839 		;
  49840 		i = i + 1
  49841 	}
  49842 }
  49843 
  49844 func PredictorAdd2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49845 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49846 	var x int32
  49847 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49848 	x = 0
  49849 	for {
  49850 		if !(x < num_pixels) {
  49851 			break
  49852 		}
  49853 		pred = VP8LPredictor2_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  49854 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49855 		v3 = pred
  49856 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49857 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49858 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49859 		goto _5
  49860 	_5:
  49861 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49862 		goto _1
  49863 	_1:
  49864 		;
  49865 		x = x + 1
  49866 	}
  49867 }
  49868 
  49869 func PredictorAdd3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49870 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49871 	var x int32
  49872 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49873 	x = 0
  49874 	for {
  49875 		if !(x < num_pixels) {
  49876 			break
  49877 		}
  49878 		pred = VP8LPredictor3_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  49879 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49880 		v3 = pred
  49881 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49882 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49883 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49884 		goto _5
  49885 	_5:
  49886 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49887 		goto _1
  49888 	_1:
  49889 		;
  49890 		x = x + 1
  49891 	}
  49892 }
  49893 
  49894 func PredictorAdd4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49895 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49896 	var x int32
  49897 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49898 	x = 0
  49899 	for {
  49900 		if !(x < num_pixels) {
  49901 			break
  49902 		}
  49903 		pred = VP8LPredictor4_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  49904 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49905 		v3 = pred
  49906 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49907 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49908 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49909 		goto _5
  49910 	_5:
  49911 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49912 		goto _1
  49913 	_1:
  49914 		;
  49915 		x = x + 1
  49916 	}
  49917 }
  49918 
  49919 func PredictorAdd5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49920 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49921 	var x int32
  49922 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49923 	x = 0
  49924 	for {
  49925 		if !(x < num_pixels) {
  49926 			break
  49927 		}
  49928 		pred = VP8LPredictor5_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  49929 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49930 		v3 = pred
  49931 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49932 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49933 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49934 		goto _5
  49935 	_5:
  49936 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49937 		goto _1
  49938 	_1:
  49939 		;
  49940 		x = x + 1
  49941 	}
  49942 }
  49943 
  49944 func PredictorAdd6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49945 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49946 	var x int32
  49947 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49948 	x = 0
  49949 	for {
  49950 		if !(x < num_pixels) {
  49951 			break
  49952 		}
  49953 		pred = VP8LPredictor6_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  49954 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49955 		v3 = pred
  49956 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49957 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49958 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49959 		goto _5
  49960 	_5:
  49961 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49962 		goto _1
  49963 	_1:
  49964 		;
  49965 		x = x + 1
  49966 	}
  49967 }
  49968 
  49969 func PredictorAdd7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49970 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49971 	var x int32
  49972 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49973 	x = 0
  49974 	for {
  49975 		if !(x < num_pixels) {
  49976 			break
  49977 		}
  49978 		pred = VP8LPredictor7_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  49979 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49980 		v3 = pred
  49981 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49982 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49983 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49984 		goto _5
  49985 	_5:
  49986 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49987 		goto _1
  49988 	_1:
  49989 		;
  49990 		x = x + 1
  49991 	}
  49992 }
  49993 
  49994 func PredictorAdd8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49995 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  49996 	var x int32
  49997 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  49998 	x = 0
  49999 	for {
  50000 		if !(x < num_pixels) {
  50001 			break
  50002 		}
  50003 		pred = VP8LPredictor8_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50004 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50005 		v3 = pred
  50006 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50007 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50008 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50009 		goto _5
  50010 	_5:
  50011 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50012 		goto _1
  50013 	_1:
  50014 		;
  50015 		x = x + 1
  50016 	}
  50017 }
  50018 
  50019 func PredictorAdd9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50020 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50021 	var x int32
  50022 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50023 	x = 0
  50024 	for {
  50025 		if !(x < num_pixels) {
  50026 			break
  50027 		}
  50028 		pred = VP8LPredictor9_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50029 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50030 		v3 = pred
  50031 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50032 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50033 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50034 		goto _5
  50035 	_5:
  50036 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50037 		goto _1
  50038 	_1:
  50039 		;
  50040 		x = x + 1
  50041 	}
  50042 }
  50043 
  50044 func PredictorAdd10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50045 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50046 	var x int32
  50047 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50048 	x = 0
  50049 	for {
  50050 		if !(x < num_pixels) {
  50051 			break
  50052 		}
  50053 		pred = VP8LPredictor10_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50054 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50055 		v3 = pred
  50056 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50057 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50058 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50059 		goto _5
  50060 	_5:
  50061 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50062 		goto _1
  50063 	_1:
  50064 		;
  50065 		x = x + 1
  50066 	}
  50067 }
  50068 
  50069 func PredictorAdd11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50070 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50071 	var x int32
  50072 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50073 	x = 0
  50074 	for {
  50075 		if !(x < num_pixels) {
  50076 			break
  50077 		}
  50078 		pred = VP8LPredictor11_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50079 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50080 		v3 = pred
  50081 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50082 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50083 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50084 		goto _5
  50085 	_5:
  50086 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50087 		goto _1
  50088 	_1:
  50089 		;
  50090 		x = x + 1
  50091 	}
  50092 }
  50093 
  50094 func PredictorAdd12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50095 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50096 	var x int32
  50097 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50098 	x = 0
  50099 	for {
  50100 		if !(x < num_pixels) {
  50101 			break
  50102 		}
  50103 		pred = VP8LPredictor12_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50104 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50105 		v3 = pred
  50106 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50107 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50108 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50109 		goto _5
  50110 	_5:
  50111 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50112 		goto _1
  50113 	_1:
  50114 		;
  50115 		x = x + 1
  50116 	}
  50117 }
  50118 
  50119 func PredictorAdd13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50120 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50121 	var x int32
  50122 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50123 	x = 0
  50124 	for {
  50125 		if !(x < num_pixels) {
  50126 			break
  50127 		}
  50128 		pred = VP8LPredictor13_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50129 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50130 		v3 = pred
  50131 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50132 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50133 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50134 		goto _5
  50135 	_5:
  50136 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50137 		goto _1
  50138 	_1:
  50139 		;
  50140 		x = x + 1
  50141 	}
  50142 }
  50143 
  50144 //------------------------------------------------------------------------------
  50145 
  50146 // C documentation
  50147 //
  50148 //	// Inverse prediction.
  50149 func PredictorInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, in uintptr, out uintptr) {
  50150 	var mask, tile_width, tiles_per_row, width, x, x_end, y int32
  50151 	var pred_func VP8LPredictorAddSubFunc
  50152 	var pred_mode_base, pred_mode_src, v4 uintptr
  50153 	var v1, v2 uint32_t
  50154 	_, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred_func, pred_mode_base, pred_mode_src, tile_width, tiles_per_row, width, x, x_end, y, v1, v2, v4
  50155 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50156 	if y_start == 0 { // First Row follows the L (mode=1) mode.
  50157 		PredictorAdd0_C(tls, in, libc.UintptrFromInt32(0), int32(1), out)
  50158 		PredictorAdd1_C(tls, in+uintptr(1)*4, libc.UintptrFromInt32(0), width-int32(1), out+uintptr(1)*4)
  50159 		in = in + uintptr(width)*4
  50160 		out = out + uintptr(width)*4
  50161 		y_start = y_start + 1
  50162 	}
  50163 	y = y_start
  50164 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50165 	mask = tile_width - int32(1)
  50166 	v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50167 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50168 	goto _3
  50169 _3:
  50170 	tiles_per_row = libc.Int32FromUint32(v2)
  50171 	pred_mode_base = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50172 	for y < y_end {
  50173 		pred_mode_src = pred_mode_base
  50174 		x = int32(1)
  50175 		// First pixel follows the T (mode=2) mode.
  50176 		PredictorAdd2_C(tls, in, out-uintptr(width)*4, int32(1), out)
  50177 		// .. the rest:
  50178 		for x < width {
  50179 			v4 = pred_mode_src
  50180 			pred_mode_src += 4
  50181 			pred_func = VP8LPredictorsAdd[**(**uint32_t)(__ccgo_up(v4))>>libc.Int32FromInt32(8)&uint32(0xf)]
  50182 			x_end = x & ^mask + tile_width
  50183 			if x_end > width {
  50184 				x_end = width
  50185 			}
  50186 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{pred_func})))(tls, in+uintptr(x)*4, out+uintptr(x)*4-uintptr(width)*4, x_end-x, out+uintptr(x)*4)
  50187 			x = x_end
  50188 		}
  50189 		in = in + uintptr(width)*4
  50190 		out = out + uintptr(width)*4
  50191 		y = y + 1
  50192 		if y&mask == 0 { // Use the same mask, since tiles are squares.
  50193 			pred_mode_base = pred_mode_base + uintptr(tiles_per_row)*4
  50194 		}
  50195 	}
  50196 }
  50197 
  50198 // C documentation
  50199 //
  50200 //	// Add green to blue and red channels (i.e. perform the inverse transform of
  50201 //	// 'subtract green').
  50202 func VP8LAddGreenToBlueAndRed_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50203 	var argb, green, red_blue uint32_t
  50204 	var i int32
  50205 	_, _, _, _ = argb, green, i, red_blue
  50206 	i = 0
  50207 	for {
  50208 		if !(i < num_pixels) {
  50209 			break
  50210 		}
  50211 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50212 		green = argb >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xff)
  50213 		red_blue = argb & libc.Uint32FromUint32(0x00ff00ff)
  50214 		red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  50215 		red_blue = red_blue & uint32(0x00ff00ff)
  50216 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | red_blue
  50217 		goto _1
  50218 	_1:
  50219 		;
  50220 		i = i + 1
  50221 	}
  50222 }
  50223 
  50224 func ColorTransformDelta(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  50225 	return int32(color_pred) * int32(color) >> int32(5)
  50226 }
  50227 
  50228 func ColorCodeToMultipliers1(tls *libc.TLS, color_code uint32_t, m uintptr) {
  50229 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  50230 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  50231 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  50232 }
  50233 
  50234 func VP8LTransformColorInverse_C(tls *libc.TLS, m uintptr, src uintptr, num_pixels int32, dst uintptr) {
  50235 	var argb, red uint32_t
  50236 	var green int8_t
  50237 	var i, new_blue, new_red int32
  50238 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  50239 	i = 0
  50240 	for {
  50241 		if !(i < num_pixels) {
  50242 			break
  50243 		}
  50244 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50245 		green = libc.Int8FromUint32(argb >> libc.Int32FromInt32(8))
  50246 		red = argb >> int32(16)
  50247 		new_red = libc.Int32FromUint32(red & uint32(0xff))
  50248 		new_blue = libc.Int32FromUint32(argb & uint32(0xff))
  50249 		new_red = new_red + ColorTransformDelta(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  50250 		new_red = new_red & int32(0xff)
  50251 		new_blue = new_blue + ColorTransformDelta(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  50252 		new_blue = new_blue + ColorTransformDelta(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), int8(new_red))
  50253 		new_blue = new_blue & int32(0xff)
  50254 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | libc.Uint32FromInt32(new_red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(new_blue)
  50255 		goto _1
  50256 	_1:
  50257 		;
  50258 		i = i + 1
  50259 	}
  50260 }
  50261 
  50262 // C documentation
  50263 //
  50264 //	// Color space inverse transform.
  50265 func ColorSpaceInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50266 	bp := tls.Alloc(16)
  50267 	defer tls.Free(16)
  50268 	var mask, remaining_width, safe_width, tile_width, tiles_per_row, width, y int32
  50269 	var pred, pred_row, src_end, src_safe_end, v4 uintptr
  50270 	var v1, v2 uint32_t
  50271 	var _ /* m at bp+0 */ VP8LMultipliers
  50272 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred, pred_row, remaining_width, safe_width, src_end, src_safe_end, tile_width, tiles_per_row, width, y, v1, v2, v4
  50273 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50274 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50275 	mask = tile_width - int32(1)
  50276 	safe_width = width & ^mask
  50277 	remaining_width = width - safe_width
  50278 	v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50279 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50280 	goto _3
  50281 _3:
  50282 	tiles_per_row = libc.Int32FromUint32(v2)
  50283 	y = y_start
  50284 	pred_row = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50285 	for y < y_end {
  50286 		pred = pred_row
  50287 		**(**VP8LMultipliers)(__ccgo_up(bp)) = VP8LMultipliers{}
  50288 		src_safe_end = src + uintptr(safe_width)*4
  50289 		src_end = src + uintptr(width)*4
  50290 		for src < src_safe_end {
  50291 			v4 = pred
  50292 			pred += 4
  50293 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50294 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, tile_width, dst)
  50295 			src = src + uintptr(tile_width)*4
  50296 			dst = dst + uintptr(tile_width)*4
  50297 		}
  50298 		if src < src_end { // Left-overs using C-version.
  50299 			v4 = pred
  50300 			pred += 4
  50301 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50302 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, remaining_width, dst)
  50303 			src = src + uintptr(remaining_width)*4
  50304 			dst = dst + uintptr(remaining_width)*4
  50305 		}
  50306 		y = y + 1
  50307 		if y&mask == 0 {
  50308 			pred_row = pred_row + uintptr(tiles_per_row)*4
  50309 		}
  50310 	}
  50311 }
  50312 
  50313 // Separate out pixels packed together using pixel-bundling.
  50314 // We define two methods for ARGB data (uint32_t) and alpha-only data (uint8_t).
  50315 func MapARGB_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50316 	var x, y int32
  50317 	var v3, v4 uintptr
  50318 	var v5, v7 uint32_t
  50319 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50320 	y = y_start
  50321 	for {
  50322 		if !(y < y_end) {
  50323 			break
  50324 		}
  50325 		x = 0
  50326 		for {
  50327 			if !(x < width) {
  50328 				break
  50329 			}
  50330 			v3 = dst
  50331 			dst += 4
  50332 			v4 = src
  50333 			src += 4
  50334 			v5 = **(**uint32_t)(__ccgo_up(v4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50335 			goto _6
  50336 		_6:
  50337 			v7 = **(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4))
  50338 			goto _8
  50339 		_8:
  50340 			**(**uint32_t)(__ccgo_up(v3)) = v7
  50341 			goto _2
  50342 		_2:
  50343 			;
  50344 			x = x + 1
  50345 		}
  50346 		goto _1
  50347 	_1:
  50348 		;
  50349 		y = y + 1
  50350 	}
  50351 }
  50352 
  50353 func ColorIndexInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50354 	var bit_mask, packed_pixels, v4 uint32_t
  50355 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50356 	var color_map, v3 uintptr
  50357 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50358 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50359 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50360 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50361 	if bits_per_pixel < int32(8) {
  50362 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50363 		count_mask = pixels_per_byte - int32(1)
  50364 		bit_mask = libc.Uint32FromInt32(int32(1)<<bits_per_pixel - int32(1))
  50365 		y = y_start
  50366 		for {
  50367 			if !(y < y_end) {
  50368 				break
  50369 			}
  50370 			packed_pixels = uint32(0)
  50371 			x = 0
  50372 			for {
  50373 				if !(x < width) {
  50374 					break
  50375 				} /* We need to load fresh 'packed_pixels' once every                */ /* 'pixels_per_byte' increments of x. Fortunately, pixels_per_byte */ /* is a power of 2, so can just use a mask for that, instead of    */ /* decrementing a counter.                                         */
  50376 				if x&count_mask == 0 {
  50377 					v3 = src
  50378 					src += 4
  50379 					v4 = **(**uint32_t)(__ccgo_up(v3)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50380 					goto _5
  50381 				_5:
  50382 					packed_pixels = v4
  50383 				}
  50384 				v3 = dst
  50385 				dst += 4
  50386 				v4 = **(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4))
  50387 				goto _8
  50388 			_8:
  50389 				**(**uint32_t)(__ccgo_up(v3)) = v4
  50390 				packed_pixels = packed_pixels >> libc.Uint32FromInt32(bits_per_pixel)
  50391 				goto _2
  50392 			_2:
  50393 				;
  50394 				x = x + 1
  50395 			}
  50396 			goto _1
  50397 		_1:
  50398 			;
  50399 			y = y + 1
  50400 		}
  50401 	} else {
  50402 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor32b})))(tls, src, color_map, dst, y_start, y_end, width)
  50403 	}
  50404 }
  50405 
  50406 func MapAlpha_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50407 	var x, y int32
  50408 	var v3, v4 uintptr
  50409 	var v5, v7 uint8_t
  50410 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50411 	y = y_start
  50412 	for {
  50413 		if !(y < y_end) {
  50414 			break
  50415 		}
  50416 		x = 0
  50417 		for {
  50418 			if !(x < width) {
  50419 				break
  50420 			}
  50421 			v3 = dst
  50422 			dst = dst + 1
  50423 			v4 = src
  50424 			src = src + 1
  50425 			v5 = **(**uint8_t)(__ccgo_up(v4))
  50426 			goto _6
  50427 		_6:
  50428 			v7 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50429 			goto _8
  50430 		_8:
  50431 			**(**uint8_t)(__ccgo_up(v3)) = v7
  50432 			goto _2
  50433 		_2:
  50434 			;
  50435 			x = x + 1
  50436 		}
  50437 		goto _1
  50438 	_1:
  50439 		;
  50440 		y = y + 1
  50441 	}
  50442 }
  50443 
  50444 func VP8LColorIndexInverseTransformAlpha(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50445 	var bit_mask, packed_pixels uint32_t
  50446 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50447 	var color_map, v3 uintptr
  50448 	var v4 uint8_t
  50449 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50450 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50451 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50452 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50453 	if bits_per_pixel < int32(8) {
  50454 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50455 		count_mask = pixels_per_byte - int32(1)
  50456 		bit_mask = libc.Uint32FromInt32(int32(1)<<bits_per_pixel - int32(1))
  50457 		y = y_start
  50458 		for {
  50459 			if !(y < y_end) {
  50460 				break
  50461 			}
  50462 			packed_pixels = uint32(0)
  50463 			x = 0
  50464 			for {
  50465 				if !(x < width) {
  50466 					break
  50467 				} /* We need to load fresh 'packed_pixels' once every                */ /* 'pixels_per_byte' increments of x. Fortunately, pixels_per_byte */ /* is a power of 2, so can just use a mask for that, instead of    */ /* decrementing a counter.                                         */
  50468 				if x&count_mask == 0 {
  50469 					v3 = src
  50470 					src = src + 1
  50471 					v4 = **(**uint8_t)(__ccgo_up(v3))
  50472 					goto _5
  50473 				_5:
  50474 					packed_pixels = uint32(v4)
  50475 				}
  50476 				v3 = dst
  50477 				dst = dst + 1
  50478 				v4 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50479 				goto _8
  50480 			_8:
  50481 				**(**uint8_t)(__ccgo_up(v3)) = v4
  50482 				packed_pixels = packed_pixels >> libc.Uint32FromInt32(bits_per_pixel)
  50483 				goto _2
  50484 			_2:
  50485 				;
  50486 				x = x + 1
  50487 			}
  50488 			goto _1
  50489 		_1:
  50490 			;
  50491 			y = y + 1
  50492 		}
  50493 	} else {
  50494 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor8b})))(tls, src, color_map, dst, y_start, y_end, width)
  50495 	}
  50496 }
  50497 
  50498 func VP8LInverseTransform(tls *libc.TLS, transform uintptr, row_start int32, row_end int32, in uintptr, out uintptr) {
  50499 	var in_stride, out_stride, width int32
  50500 	var src uintptr
  50501 	var v1, v2 uint32_t
  50502 	_, _, _, _, _, _ = in_stride, out_stride, src, width, v1, v2
  50503 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50504 	switch (*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 {
  50505 	case int32(SUBTRACT_GREEN_TRANSFORM):
  50506 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LAddGreenToBlueAndRed})))(tls, in, (row_end-row_start)*width, out)
  50507 	case int32(PREDICTOR_TRANSFORM):
  50508 		PredictorInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50509 		if row_end != (*VP8LTransform)(unsafe.Pointer(transform)).Fysize {
  50510 			// The last predicted row in this iteration will be the top-pred row
  50511 			// for the first row in next iteration.
  50512 			libc.Xmemcpy(tls, out-uintptr(width)*4, out+uintptr((row_end-row_start-int32(1))*width)*4, libc.Uint64FromInt32(width)*uint64(4))
  50513 		}
  50514 	case int32(CROSS_COLOR_TRANSFORM):
  50515 		ColorSpaceInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50516 	case int32(COLOR_INDEXING_TRANSFORM):
  50517 		if in == out && (*VP8LTransform)(unsafe.Pointer(transform)).Fbits > 0 {
  50518 			// Move packed pixels to the end of unpacked region, so that unpacking
  50519 			// can occur seamlessly.
  50520 			// Also, note that this is the only transform that applies on
  50521 			// the effective width of VP8LSubSampleSize(xsize, bits). All other
  50522 			// transforms work on effective width of 'xsize'.
  50523 			out_stride = (row_end - row_start) * width
  50524 			v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50525 			v2 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50526 			goto _3
  50527 		_3:
  50528 			in_stride = libc.Int32FromUint32(libc.Uint32FromInt32(row_end-row_start) * v2)
  50529 			src = out + uintptr(out_stride)*4 - uintptr(in_stride)*4
  50530 			libc.Xmemmove(tls, src, out, libc.Uint64FromInt32(in_stride)*uint64(4))
  50531 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, src, out)
  50532 		} else {
  50533 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50534 		}
  50535 		break
  50536 	}
  50537 }
  50538 
  50539 //------------------------------------------------------------------------------
  50540 // Color space conversion.
  50541 
  50542 func is_big_endian(tls *libc.TLS) (r int32) {
  50543 	return libc.BoolInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&tmp))))) != int32(1))
  50544 }
  50545 
  50546 var tmp = *(*struct {
  50547 	Fb [0][2]uint8_t
  50548 	Fw uint16_t
  50549 })(unsafe.Pointer(&[1]uint16{0x1}))
  50550 
  50551 func VP8LConvertBGRAToRGB_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50552 	var argb uint32_t
  50553 	var src_end, v1, v2 uintptr
  50554 	_, _, _, _ = argb, src_end, v1, v2
  50555 	src_end = src + uintptr(num_pixels)*4
  50556 	for src < src_end {
  50557 		v1 = src
  50558 		src += 4
  50559 		argb = **(**uint32_t)(__ccgo_up(v1))
  50560 		v2 = dst
  50561 		dst = dst + 1
  50562 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50563 		v1 = dst
  50564 		dst = dst + 1
  50565 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50566 		v1 = dst
  50567 		dst = dst + 1
  50568 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50569 	}
  50570 }
  50571 
  50572 func VP8LConvertBGRAToRGBA_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50573 	var argb uint32_t
  50574 	var src_end, v1, v2 uintptr
  50575 	_, _, _, _ = argb, src_end, v1, v2
  50576 	src_end = src + uintptr(num_pixels)*4
  50577 	for src < src_end {
  50578 		v1 = src
  50579 		src += 4
  50580 		argb = **(**uint32_t)(__ccgo_up(v1))
  50581 		v2 = dst
  50582 		dst = dst + 1
  50583 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50584 		v1 = dst
  50585 		dst = dst + 1
  50586 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50587 		v1 = dst
  50588 		dst = dst + 1
  50589 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50590 		v1 = dst
  50591 		dst = dst + 1
  50592 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(24) & uint32(0xff))
  50593 	}
  50594 }
  50595 
  50596 func VP8LConvertBGRAToRGBA4444_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50597 	var argb uint32_t
  50598 	var ba, rg uint8_t
  50599 	var src_end, v1, v2 uintptr
  50600 	_, _, _, _, _, _ = argb, ba, rg, src_end, v1, v2
  50601 	src_end = src + uintptr(num_pixels)*4
  50602 	for src < src_end {
  50603 		v1 = src
  50604 		src += 4
  50605 		argb = **(**uint32_t)(__ccgo_up(v1))
  50606 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf0) | argb>>libc.Int32FromInt32(12)&uint32(0xf))
  50607 		ba = uint8(argb>>libc.Int32FromInt32(0)&uint32(0xf0) | argb>>libc.Int32FromInt32(28)&uint32(0xf))
  50608 		v2 = dst
  50609 		dst = dst + 1
  50610 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50611 		v1 = dst
  50612 		dst = dst + 1
  50613 		**(**uint8_t)(__ccgo_up(v1)) = ba
  50614 	}
  50615 }
  50616 
  50617 func VP8LConvertBGRAToRGB565_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50618 	var argb uint32_t
  50619 	var gb, rg uint8_t
  50620 	var src_end, v1, v2 uintptr
  50621 	_, _, _, _, _, _ = argb, gb, rg, src_end, v1, v2
  50622 	src_end = src + uintptr(num_pixels)*4
  50623 	for src < src_end {
  50624 		v1 = src
  50625 		src += 4
  50626 		argb = **(**uint32_t)(__ccgo_up(v1))
  50627 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf8) | argb>>libc.Int32FromInt32(13)&uint32(0x7))
  50628 		gb = uint8(argb>>libc.Int32FromInt32(5)&uint32(0xe0) | argb>>libc.Int32FromInt32(3)&uint32(0x1f))
  50629 		v2 = dst
  50630 		dst = dst + 1
  50631 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50632 		v1 = dst
  50633 		dst = dst + 1
  50634 		**(**uint8_t)(__ccgo_up(v1)) = gb
  50635 	}
  50636 }
  50637 
  50638 func VP8LConvertBGRAToBGR_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50639 	var argb uint32_t
  50640 	var src_end, v1, v2 uintptr
  50641 	_, _, _, _ = argb, src_end, v1, v2
  50642 	src_end = src + uintptr(num_pixels)*4
  50643 	for src < src_end {
  50644 		v1 = src
  50645 		src += 4
  50646 		argb = **(**uint32_t)(__ccgo_up(v1))
  50647 		v2 = dst
  50648 		dst = dst + 1
  50649 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50650 		v1 = dst
  50651 		dst = dst + 1
  50652 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50653 		v1 = dst
  50654 		dst = dst + 1
  50655 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50656 	}
  50657 }
  50658 
  50659 func CopyOrSwap(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr, swap_on_big_endian int32) {
  50660 	bp := tls.Alloc(16)
  50661 	defer tls.Free(16)
  50662 	var argb, v2, v4 uint32_t
  50663 	var src_end, v1 uintptr
  50664 	_, _, _, _, _ = argb, src_end, v1, v2, v4
  50665 	if is_big_endian(tls) == swap_on_big_endian {
  50666 		src_end = src + uintptr(num_pixels)*4
  50667 		for src < src_end {
  50668 			v1 = src
  50669 			src += 4
  50670 			argb = **(**uint32_t)(__ccgo_up(v1))
  50671 			v2 = libc.X__builtin_bswap32(tls, argb)
  50672 			goto _3
  50673 		_3:
  50674 			v4 = v2
  50675 			*(*uint32_t)(unsafe.Pointer(bp)) = v4
  50676 			libc.Xmemcpy(tls, dst, bp, uint64(4))
  50677 			dst = dst + uintptr(4)
  50678 		}
  50679 	} else {
  50680 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(num_pixels)*uint64(4))
  50681 	}
  50682 }
  50683 
  50684 func VP8LConvertFromBGRA(tls *libc.TLS, in_data uintptr, num_pixels int32, out_colorspace WEBP_CSP_MODE1, rgba uintptr) {
  50685 	switch out_colorspace {
  50686 	case int32(MODE_RGB):
  50687 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB})))(tls, in_data, num_pixels, rgba)
  50688 	case int32(MODE_RGBA):
  50689 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  50690 	case int32(MODE_rgbA):
  50691 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  50692 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  50693 	case int32(MODE_BGR):
  50694 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToBGR})))(tls, in_data, num_pixels, rgba)
  50695 	case int32(MODE_BGRA):
  50696 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  50697 	case int32(MODE_bgrA):
  50698 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  50699 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  50700 	case int32(MODE_ARGB):
  50701 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  50702 	case int32(MODE_Argb):
  50703 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  50704 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, int32(1), num_pixels, int32(1), 0)
  50705 	case int32(MODE_RGBA_4444):
  50706 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  50707 	case int32(MODE_rgbA_4444):
  50708 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  50709 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, rgba, num_pixels, int32(1), 0)
  50710 	case int32(MODE_RGB_565):
  50711 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB565})))(tls, in_data, num_pixels, rgba)
  50712 	default:
  50713 		// Code flow should not reach here.
  50714 	}
  50715 }
  50716 
  50717 func VP8LDspInit(tls *libc.TLS) {
  50718 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  50719 		goto _1
  50720 	}
  50721 	VP8LDspInit_body(tls)
  50722 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  50723 	goto _2
  50724 _2:
  50725 	;
  50726 	goto _1
  50727 _1: /**/ //
  50728 }
  50729 
  50730 var VP8LDspInit_body_last_cpuinfo_used = uintptr(0)
  50731 
  50732 func init() {
  50733 	p := unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)
  50734 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))
  50735 }
  50736 
  50737 func VP8LDspInit_body(tls *libc.TLS) {
  50738 	VP8LPredictors[0] = __ccgo_fp(VP8LPredictor0_C)
  50739 	VP8LPredictors[int32(1)] = __ccgo_fp(VP8LPredictor1_C)
  50740 	VP8LPredictors[int32(2)] = __ccgo_fp(VP8LPredictor2_C)
  50741 	VP8LPredictors[int32(3)] = __ccgo_fp(VP8LPredictor3_C)
  50742 	VP8LPredictors[int32(4)] = __ccgo_fp(VP8LPredictor4_C)
  50743 	VP8LPredictors[int32(5)] = __ccgo_fp(VP8LPredictor5_C)
  50744 	VP8LPredictors[int32(6)] = __ccgo_fp(VP8LPredictor6_C)
  50745 	VP8LPredictors[int32(7)] = __ccgo_fp(VP8LPredictor7_C)
  50746 	VP8LPredictors[int32(8)] = __ccgo_fp(VP8LPredictor8_C)
  50747 	VP8LPredictors[int32(9)] = __ccgo_fp(VP8LPredictor9_C)
  50748 	VP8LPredictors[int32(10)] = __ccgo_fp(VP8LPredictor10_C)
  50749 	VP8LPredictors[int32(11)] = __ccgo_fp(VP8LPredictor11_C)
  50750 	VP8LPredictors[int32(12)] = __ccgo_fp(VP8LPredictor12_C)
  50751 	VP8LPredictors[int32(13)] = __ccgo_fp(VP8LPredictor13_C)
  50752 	VP8LPredictors[int32(14)] = __ccgo_fp(VP8LPredictor0_C) /* <- padding security sentinels*/
  50753 	VP8LPredictors[int32(15)] = __ccgo_fp(VP8LPredictor0_C)
  50754 	VP8LPredictorsAdd[0] = __ccgo_fp(PredictorAdd0_C)
  50755 	VP8LPredictorsAdd[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  50756 	VP8LPredictorsAdd[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  50757 	VP8LPredictorsAdd[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  50758 	VP8LPredictorsAdd[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  50759 	VP8LPredictorsAdd[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  50760 	VP8LPredictorsAdd[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  50761 	VP8LPredictorsAdd[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  50762 	VP8LPredictorsAdd[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  50763 	VP8LPredictorsAdd[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  50764 	VP8LPredictorsAdd[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  50765 	VP8LPredictorsAdd[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  50766 	VP8LPredictorsAdd[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  50767 	VP8LPredictorsAdd[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  50768 	VP8LPredictorsAdd[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  50769 	VP8LPredictorsAdd[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  50770 	VP8LPredictorsAdd_C[0] = __ccgo_fp(PredictorAdd0_C)
  50771 	VP8LPredictorsAdd_C[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  50772 	VP8LPredictorsAdd_C[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  50773 	VP8LPredictorsAdd_C[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  50774 	VP8LPredictorsAdd_C[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  50775 	VP8LPredictorsAdd_C[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  50776 	VP8LPredictorsAdd_C[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  50777 	VP8LPredictorsAdd_C[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  50778 	VP8LPredictorsAdd_C[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  50779 	VP8LPredictorsAdd_C[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  50780 	VP8LPredictorsAdd_C[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  50781 	VP8LPredictorsAdd_C[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  50782 	VP8LPredictorsAdd_C[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  50783 	VP8LPredictorsAdd_C[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  50784 	VP8LPredictorsAdd_C[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  50785 	VP8LPredictorsAdd_C[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  50786 	VP8LAddGreenToBlueAndRed = __ccgo_fp(VP8LAddGreenToBlueAndRed_C)
  50787 	VP8LTransformColorInverse = __ccgo_fp(VP8LTransformColorInverse_C)
  50788 	VP8LConvertBGRAToRGBA = __ccgo_fp(VP8LConvertBGRAToRGBA_C)
  50789 	VP8LConvertBGRAToRGB = __ccgo_fp(VP8LConvertBGRAToRGB_C)
  50790 	VP8LConvertBGRAToBGR = __ccgo_fp(VP8LConvertBGRAToBGR_C)
  50791 	VP8LConvertBGRAToRGBA4444 = __ccgo_fp(VP8LConvertBGRAToRGBA4444_C)
  50792 	VP8LConvertBGRAToRGB565 = __ccgo_fp(VP8LConvertBGRAToRGB565_C)
  50793 	VP8LMapColor32b = __ccgo_fp(MapARGB_C)
  50794 	VP8LMapColor8b = __ccgo_fp(MapAlpha_C)
  50795 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  50796 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  50797 	}
  50798 }
  50799 
  50800 func VP8LEncDspInitAVX2(tls *libc.TLS) {
  50801 }
  50802 
  50803 const LOG_2_RECIPROCAL_FIXED_DOUBLE1 = 1.2102203161561485e+07
  50804 
  50805 func FastSLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint64_t) {
  50806 	var correction, log_cnt, orig_v uint64_t
  50807 	var y uint32_t
  50808 	var v1 int32
  50809 	_, _, _, _, _ = correction, log_cnt, orig_v, y, v1
  50810 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  50811 		orig_v = uint64(v)
  50812 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  50813 		goto _2
  50814 	_2:
  50815 		// use clz if available
  50816 		log_cnt = libc.Uint64FromInt32(v1 - int32(7))
  50817 		y = libc.Uint32FromInt32(int32(1) << log_cnt)
  50818 		v = uint32(uint64(v) >> log_cnt)
  50819 		// vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256
  50820 		// Xf = floor(Xf) * (1 + (v % y) / v)
  50821 		// log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v)
  50822 		// The correction factor: log(1 + d) ~ d; for very small d values, so
  50823 		// log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
  50824 		correction = libc.Uint64FromInt32(12102203) * (orig_v & uint64(y-libc.Uint32FromInt32(1)))
  50825 		return orig_v*(uint64(kLog2Table[v])+log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + correction
  50826 	} else {
  50827 		return uint64(float64(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*float64(v))*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  50828 	}
  50829 	return r
  50830 }
  50831 
  50832 func FastLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint32_t) {
  50833 	var correction uint64_t
  50834 	var log_2, log_cnt, orig_v, y uint32_t
  50835 	var v1 int32
  50836 	var v3, v4, v5 int64_t
  50837 	var v7 int64
  50838 	_, _, _, _, _, _, _, _, _, _ = correction, log_2, log_cnt, orig_v, y, v1, v3, v4, v5, v7
  50839 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  50840 		orig_v = v
  50841 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  50842 		goto _2
  50843 	_2:
  50844 		// use clz if available
  50845 		log_cnt = libc.Uint32FromInt32(v1 - int32(7))
  50846 		y = libc.Uint32FromInt32(int32(1) << log_cnt)
  50847 		v = v >> log_cnt
  50848 		log_2 = kLog2Table[v] + log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  50849 		if orig_v >= uint32(APPROX_LOG_MAX) {
  50850 			// Since the division is still expensive, add this correction factor only
  50851 			// for large values of 'v'.
  50852 			correction = libc.Uint64FromInt32(12102203) * uint64(orig_v&(y-libc.Uint32FromInt32(1)))
  50853 			v3 = libc.Int64FromUint64(correction)
  50854 			v4 = libc.Int64FromUint32(orig_v)
  50855 			if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  50856 				v7 = (v3 + v4/int64(2)) / v4
  50857 			} else {
  50858 				v7 = (v3 - v4/int64(2)) / v4
  50859 			}
  50860 			v5 = v7
  50861 			goto _6
  50862 		_6:
  50863 			log_2 = log_2 + libc.Uint32FromInt64(v5)
  50864 		}
  50865 		return log_2
  50866 	} else {
  50867 		return uint32(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  50868 	}
  50869 	return r
  50870 }
  50871 
  50872 //------------------------------------------------------------------------------
  50873 // Methods to calculate Entropy (Shannon).
  50874 
  50875 // C documentation
  50876 //
  50877 //	// Compute the combined Shanon's entropy for distribution {X} and {X+Y}
  50878 func CombinedShannonEntropy_C(tls *libc.TLS, X uintptr, Y uintptr) (r uint64_t) {
  50879 	var i int32
  50880 	var retval, v3, v7 uint64_t
  50881 	var sumX, sumXY, x, xy, v2, v6 uint32_t
  50882 	var v5, v9 uint64
  50883 	_, _, _, _, _, _, _, _, _, _, _, _ = i, retval, sumX, sumXY, x, xy, v2, v3, v5, v6, v7, v9
  50884 	retval = uint64(0)
  50885 	sumX = uint32(0)
  50886 	sumXY = uint32(0)
  50887 	i = 0
  50888 	for {
  50889 		if !(i < int32(256)) {
  50890 			break
  50891 		}
  50892 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  50893 		if x != uint32(0) {
  50894 			xy = x + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  50895 			sumX = sumX + x
  50896 			v2 = x
  50897 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  50898 				v5 = kSLog2Table[v2]
  50899 			} else {
  50900 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  50901 			}
  50902 			v3 = v5
  50903 			goto _4
  50904 		_4:
  50905 			retval = retval + v3
  50906 			sumXY = sumXY + xy
  50907 			v2 = xy
  50908 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  50909 				v5 = kSLog2Table[v2]
  50910 			} else {
  50911 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  50912 			}
  50913 			v3 = v5
  50914 			goto _8
  50915 		_8:
  50916 			retval = retval + v3
  50917 		} else {
  50918 			if **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4)) != uint32(0) {
  50919 				sumXY = sumXY + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  50920 				v2 = **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  50921 				if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  50922 					v5 = kSLog2Table[v2]
  50923 				} else {
  50924 					v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  50925 				}
  50926 				v3 = v5
  50927 				goto _12
  50928 			_12:
  50929 				retval = retval + v3
  50930 			}
  50931 		}
  50932 		goto _1
  50933 	_1:
  50934 		;
  50935 		i = i + 1
  50936 	}
  50937 	v2 = sumX
  50938 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  50939 		v5 = kSLog2Table[v2]
  50940 	} else {
  50941 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  50942 	}
  50943 	v3 = v5
  50944 	goto _16
  50945 _16:
  50946 	v6 = sumXY
  50947 	if v6 < uint32(LOG_LOOKUP_IDX_MAX) {
  50948 		v9 = kSLog2Table[v6]
  50949 	} else {
  50950 		v9 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v6)
  50951 	}
  50952 	v7 = v9
  50953 	goto _20
  50954 _20:
  50955 	retval = v3 + v7 - retval
  50956 	return retval
  50957 }
  50958 
  50959 func ShannonEntropy_C(tls *libc.TLS, X uintptr, n int32) (r uint64_t) {
  50960 	var i, x int32
  50961 	var retval, v3 uint64_t
  50962 	var sumX, v2 uint32_t
  50963 	var v5 uint64
  50964 	_, _, _, _, _, _, _ = i, retval, sumX, x, v2, v3, v5
  50965 	retval = uint64(0)
  50966 	sumX = uint32(0)
  50967 	i = 0
  50968 	for {
  50969 		if !(i < n) {
  50970 			break
  50971 		}
  50972 		x = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(X + uintptr(i)*4)))
  50973 		if x != 0 {
  50974 			sumX = sumX + libc.Uint32FromInt32(x)
  50975 			v2 = libc.Uint32FromInt32(x)
  50976 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  50977 				v5 = kSLog2Table[v2]
  50978 			} else {
  50979 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  50980 			}
  50981 			v3 = v5
  50982 			goto _4
  50983 		_4:
  50984 			retval = retval + v3
  50985 		}
  50986 		goto _1
  50987 	_1:
  50988 		;
  50989 		i = i + 1
  50990 	}
  50991 	v2 = sumX
  50992 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  50993 		v5 = kSLog2Table[v2]
  50994 	} else {
  50995 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  50996 	}
  50997 	v3 = v5
  50998 	goto _8
  50999 _8:
  51000 	retval = v3 - retval
  51001 	return retval
  51002 }
  51003 
  51004 func VP8LBitEntropyInit(tls *libc.TLS, entropy uintptr) {
  51005 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = uint64(0)
  51006 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum = uint32(0)
  51007 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = 0
  51008 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = uint32(0)
  51009 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = uint32(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff)))
  51010 }
  51011 
  51012 func VP8LBitsEntropyUnrefined(tls *libc.TLS, array uintptr, n int32, entropy uintptr) {
  51013 	var i int32
  51014 	var v2 uint32_t
  51015 	var v3 uint64_t
  51016 	var v5 uint64
  51017 	_, _, _, _ = i, v2, v3, v5
  51018 	VP8LBitEntropyInit(tls, entropy)
  51019 	i = 0
  51020 	for {
  51021 		if !(i < n) {
  51022 			break
  51023 		}
  51024 		if **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) != uint32(0) {
  51025 			**(**uint32_t)(__ccgo_up(entropy + 8)) += **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51026 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = libc.Uint32FromInt32(i)
  51027 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros + 1
  51028 			v2 = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51029 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51030 				v5 = kSLog2Table[v2]
  51031 			} else {
  51032 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51033 			}
  51034 			v3 = v5
  51035 			goto _4
  51036 		_4:
  51037 			**(**uint64_t)(__ccgo_up(entropy)) += v3
  51038 			if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) {
  51039 				(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51040 			}
  51041 		}
  51042 		goto _1
  51043 	_1:
  51044 		;
  51045 		i = i + 1
  51046 	}
  51047 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum
  51048 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51049 		v5 = kSLog2Table[v2]
  51050 	} else {
  51051 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51052 	}
  51053 	v3 = v5
  51054 	goto _8
  51055 _8:
  51056 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  51057 }
  51058 
  51059 func GetEntropyUnrefinedHelper(tls *libc.TLS, val uint32_t, i int32, val_prev uintptr, i_prev uintptr, bit_entropy uintptr, stats uintptr) {
  51060 	var streak int32
  51061 	var v1 uint32_t
  51062 	var v2 uint64_t
  51063 	var v4 uint64
  51064 	_, _, _, _ = streak, v1, v2, v4
  51065 	streak = i - **(**int32)(__ccgo_up(i_prev))
  51066 	// Gather info for the bit entropy.
  51067 	if **(**uint32_t)(__ccgo_up(val_prev)) != uint32(0) {
  51068 		**(**uint32_t)(__ccgo_up(bit_entropy + 8)) += **(**uint32_t)(__ccgo_up(val_prev)) * libc.Uint32FromInt32(streak)
  51069 		**(**int32)(__ccgo_up(bit_entropy + 12)) += streak
  51070 		(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fnonzero_code = libc.Uint32FromInt32(**(**int32)(__ccgo_up(i_prev)))
  51071 		v1 = **(**uint32_t)(__ccgo_up(val_prev))
  51072 		if v1 < uint32(LOG_LOOKUP_IDX_MAX) {
  51073 			v4 = kSLog2Table[v1]
  51074 		} else {
  51075 			v4 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v1)
  51076 		}
  51077 		v2 = v4
  51078 		goto _3
  51079 	_3:
  51080 		**(**uint64_t)(__ccgo_up(bit_entropy)) += v2 * libc.Uint64FromInt32(streak)
  51081 		if (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(val_prev)) {
  51082 			(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(val_prev))
  51083 		}
  51084 	}
  51085 	// Gather info for the Huffman cost.
  51086 	**(**int32)(__ccgo_up(stats + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*4)) += libc.BoolInt32(streak > int32(3))
  51087 	**(**int32)(__ccgo_up(stats + 8 + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*8 + libc.BoolUintptr(streak > libc.Int32FromInt32(3))*4)) += streak
  51088 	**(**uint32_t)(__ccgo_up(val_prev)) = val
  51089 	**(**int32)(__ccgo_up(i_prev)) = i
  51090 }
  51091 
  51092 func GetEntropyUnrefined_C(tls *libc.TLS, X uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51093 	bp := tls.Alloc(16)
  51094 	defer tls.Free(16)
  51095 	var i int32
  51096 	var x, v2 uint32_t
  51097 	var v3 uint64_t
  51098 	var v5 uint64
  51099 	var _ /* i_prev at bp+0 */ int32
  51100 	var _ /* x_prev at bp+4 */ uint32_t
  51101 	_, _, _, _, _ = i, x, v2, v3, v5
  51102 	**(**int32)(__ccgo_up(bp)) = 0
  51103 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X))
  51104 	libc.Xmemset(tls, stats, 0, uint64(24))
  51105 	VP8LBitEntropyInit(tls, bit_entropy)
  51106 	i = int32(1)
  51107 	for {
  51108 		if !(i < length) {
  51109 			break
  51110 		}
  51111 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51112 		if x != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51113 			GetEntropyUnrefinedHelper(tls, x, i, bp+4, bp, bit_entropy, stats)
  51114 		}
  51115 		goto _1
  51116 	_1:
  51117 		;
  51118 		i = i + 1
  51119 	}
  51120 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51121 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51122 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51123 		v5 = kSLog2Table[v2]
  51124 	} else {
  51125 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51126 	}
  51127 	v3 = v5
  51128 	goto _4
  51129 _4:
  51130 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51131 }
  51132 
  51133 func GetCombinedEntropyUnrefined_C(tls *libc.TLS, X uintptr, Y uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51134 	bp := tls.Alloc(16)
  51135 	defer tls.Free(16)
  51136 	var i int32
  51137 	var xy, v2 uint32_t
  51138 	var v3 uint64_t
  51139 	var v5 uint64
  51140 	var _ /* i_prev at bp+0 */ int32
  51141 	var _ /* xy_prev at bp+4 */ uint32_t
  51142 	_, _, _, _, _ = i, xy, v2, v3, v5
  51143 	i = int32(1)
  51144 	**(**int32)(__ccgo_up(bp)) = 0
  51145 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X)) + **(**uint32_t)(__ccgo_up(Y))
  51146 	libc.Xmemset(tls, stats, 0, uint64(24))
  51147 	VP8LBitEntropyInit(tls, bit_entropy)
  51148 	i = int32(1)
  51149 	for {
  51150 		if !(i < length) {
  51151 			break
  51152 		}
  51153 		xy = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51154 		if xy != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51155 			GetEntropyUnrefinedHelper(tls, xy, i, bp+4, bp, bit_entropy, stats)
  51156 		}
  51157 		goto _1
  51158 	_1:
  51159 		;
  51160 		i = i + 1
  51161 	}
  51162 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51163 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51164 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51165 		v5 = kSLog2Table[v2]
  51166 	} else {
  51167 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51168 	}
  51169 	v3 = v5
  51170 	goto _4
  51171 _4:
  51172 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51173 }
  51174 
  51175 //------------------------------------------------------------------------------
  51176 
  51177 func VP8LSubtractGreenFromBlueAndRed_C(tls *libc.TLS, argb_data uintptr, num_pixels int32) {
  51178 	var argb, green, i int32
  51179 	var new_b, new_r uint32_t
  51180 	_, _, _, _, _ = argb, green, i, new_b, new_r
  51181 	i = 0
  51182 	for {
  51183 		if !(i < num_pixels) {
  51184 			break
  51185 		}
  51186 		argb = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)))
  51187 		green = argb >> libc.Int32FromInt32(8) & int32(0xff)
  51188 		new_r = libc.Uint32FromInt32((argb>>libc.Int32FromInt32(16)&int32(0xff) - green) & int32(0xff))
  51189 		new_b = libc.Uint32FromInt32((argb>>libc.Int32FromInt32(0)&int32(0xff) - green) & int32(0xff))
  51190 		**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)) = libc.Uint32FromInt32(argb)&uint32(0xff00ff00) | new_r<<libc.Int32FromInt32(16) | new_b
  51191 		goto _1
  51192 	_1:
  51193 		;
  51194 		i = i + 1
  51195 	}
  51196 }
  51197 
  51198 func ColorTransformDelta1(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  51199 	return int32(color_pred) * int32(color) >> int32(5)
  51200 }
  51201 
  51202 func U32ToS8(tls *libc.TLS, v uint32_t) (r int8_t) {
  51203 	return libc.Int8FromUint32(v & libc.Uint32FromInt32(0xff))
  51204 }
  51205 
  51206 func VP8LTransformColor_C(tls *libc.TLS, m uintptr, data uintptr, num_pixels int32) {
  51207 	var argb uint32_t
  51208 	var green, red int8_t
  51209 	var i, new_blue, new_red int32
  51210 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  51211 	i = 0
  51212 	for {
  51213 		if !(i < num_pixels) {
  51214 			break
  51215 		}
  51216 		argb = **(**uint32_t)(__ccgo_up(data + uintptr(i)*4))
  51217 		green = U32ToS8(tls, argb>>int32(8))
  51218 		red = U32ToS8(tls, argb>>int32(16))
  51219 		new_red = int32(red) & int32(0xff)
  51220 		new_blue = libc.Int32FromUint32(argb & uint32(0xff))
  51221 		new_red = new_red - ColorTransformDelta1(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  51222 		new_red = new_red & int32(0xff)
  51223 		new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  51224 		new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), red)
  51225 		new_blue = new_blue & int32(0xff)
  51226 		**(**uint32_t)(__ccgo_up(data + uintptr(i)*4)) = argb&uint32(0xff00ff00) | libc.Uint32FromInt32(new_red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(new_blue)
  51227 		goto _1
  51228 	_1:
  51229 		;
  51230 		i = i + 1
  51231 	}
  51232 }
  51233 
  51234 func TransformColorRed(tls *libc.TLS, green_to_red uint8_t, argb uint32_t) (r uint8_t) {
  51235 	var green int8_t
  51236 	var new_red int32
  51237 	_, _ = green, new_red
  51238 	green = U32ToS8(tls, argb>>int32(8))
  51239 	new_red = libc.Int32FromUint32(argb >> int32(16))
  51240 	new_red = new_red - ColorTransformDelta1(tls, libc.Int8FromUint8(green_to_red), green)
  51241 	return libc.Uint8FromInt32(new_red & libc.Int32FromInt32(0xff))
  51242 }
  51243 
  51244 func TransformColorBlue(tls *libc.TLS, green_to_blue uint8_t, red_to_blue uint8_t, argb uint32_t) (r uint8_t) {
  51245 	var green, red int8_t
  51246 	var new_blue int32
  51247 	_, _, _ = green, new_blue, red
  51248 	green = U32ToS8(tls, argb>>int32(8))
  51249 	red = U32ToS8(tls, argb>>int32(16))
  51250 	new_blue = libc.Int32FromUint32(argb & uint32(0xff))
  51251 	new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8(green_to_blue), green)
  51252 	new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8(red_to_blue), red)
  51253 	return libc.Uint8FromInt32(new_blue & libc.Int32FromInt32(0xff))
  51254 }
  51255 
  51256 func VP8LCollectColorRedTransforms_C(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, green_to_red int32, histo uintptr) {
  51257 	var x, v1 int32
  51258 	_, _ = x, v1
  51259 	for {
  51260 		v1 = tile_height
  51261 		tile_height = tile_height - 1
  51262 		if !(v1 > 0) {
  51263 			break
  51264 		}
  51265 		x = 0
  51266 		for {
  51267 			if !(x < tile_width) {
  51268 				break
  51269 			}
  51270 			**(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorRed(tls, libc.Uint8FromInt32(green_to_red), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorRed(tls, libc.Uint8FromInt32(green_to_red), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) + 1
  51271 			goto _2
  51272 		_2:
  51273 			;
  51274 			x = x + 1
  51275 		}
  51276 		argb = argb + uintptr(stride)*4
  51277 	}
  51278 }
  51279 
  51280 func VP8LCollectColorBlueTransforms_C(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, green_to_blue int32, red_to_blue int32, histo uintptr) {
  51281 	var x, v1 int32
  51282 	_, _ = x, v1
  51283 	for {
  51284 		v1 = tile_height
  51285 		tile_height = tile_height - 1
  51286 		if !(v1 > 0) {
  51287 			break
  51288 		}
  51289 		x = 0
  51290 		for {
  51291 			if !(x < tile_width) {
  51292 				break
  51293 			}
  51294 			**(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorBlue(tls, libc.Uint8FromInt32(green_to_blue), libc.Uint8FromInt32(red_to_blue), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(TransformColorBlue(tls, libc.Uint8FromInt32(green_to_blue), libc.Uint8FromInt32(red_to_blue), **(**uint32_t)(__ccgo_up(argb + uintptr(x)*4))))*4)) + 1
  51295 			goto _2
  51296 		_2:
  51297 			;
  51298 			x = x + 1
  51299 		}
  51300 		argb = argb + uintptr(stride)*4
  51301 	}
  51302 }
  51303 
  51304 //------------------------------------------------------------------------------
  51305 
  51306 func VectorMismatch_C(tls *libc.TLS, array1 uintptr, array2 uintptr, length int32) (r int32) {
  51307 	var match_len int32
  51308 	_ = match_len
  51309 	match_len = 0
  51310 	for match_len < length && **(**uint32_t)(__ccgo_up(array1 + uintptr(match_len)*4)) == **(**uint32_t)(__ccgo_up(array2 + uintptr(match_len)*4)) {
  51311 		match_len = match_len + 1
  51312 	}
  51313 	return match_len
  51314 }
  51315 
  51316 // C documentation
  51317 //
  51318 //	// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
  51319 func VP8LBundleColorMap_C(tls *libc.TLS, row uintptr, width int32, xbits int32, dst uintptr) {
  51320 	var bit_depth, mask, x, xsub int32
  51321 	var code uint32_t
  51322 	_, _, _, _, _ = bit_depth, code, mask, x, xsub
  51323 	if xbits > 0 {
  51324 		bit_depth = int32(1) << (int32(3) - xbits)
  51325 		mask = int32(1)<<xbits - int32(1)
  51326 		code = uint32(0xff000000)
  51327 		x = 0
  51328 		for {
  51329 			if !(x < width) {
  51330 				break
  51331 			}
  51332 			xsub = x & mask
  51333 			if xsub == 0 {
  51334 				code = uint32(0xff000000)
  51335 			}
  51336 			code = code | libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<(int32(8)+bit_depth*xsub))
  51337 			**(**uint32_t)(__ccgo_up(dst + uintptr(x>>xbits)*4)) = code
  51338 			goto _1
  51339 		_1:
  51340 			;
  51341 			x = x + 1
  51342 		}
  51343 	} else {
  51344 		x = 0
  51345 		for {
  51346 			if !(x < width) {
  51347 				break
  51348 			}
  51349 			**(**uint32_t)(__ccgo_up(dst + uintptr(x)*4)) = uint32(0xff000000) | libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<libc.Int32FromInt32(8))
  51350 			goto _2
  51351 		_2:
  51352 			;
  51353 			x = x + 1
  51354 		}
  51355 	}
  51356 }
  51357 
  51358 //------------------------------------------------------------------------------
  51359 
  51360 func ExtraCost_C(tls *libc.TLS, population uintptr, length int32) (r uint32_t) {
  51361 	var cost uint32_t
  51362 	var i int32
  51363 	_, _ = cost, i
  51364 	cost = **(**uint32_t)(__ccgo_up(population + 4*4)) + **(**uint32_t)(__ccgo_up(population + 5*4))
  51365 	i = int32(2)
  51366 	for {
  51367 		if !(i < length/int32(2)-int32(1)) {
  51368 			break
  51369 		}
  51370 		cost = cost + libc.Uint32FromInt32(i)*(**(**uint32_t)(__ccgo_up(population + uintptr(int32(2)*i+int32(2))*4))+**(**uint32_t)(__ccgo_up(population + uintptr(int32(2)*i+int32(3))*4)))
  51371 		goto _1
  51372 	_1:
  51373 		;
  51374 		i = i + 1
  51375 	}
  51376 	return cost
  51377 }
  51378 
  51379 //------------------------------------------------------------------------------
  51380 
  51381 func AddVector_C(tls *libc.TLS, a uintptr, b uintptr, out uintptr, size int32) {
  51382 	var i int32
  51383 	_ = i
  51384 	i = 0
  51385 	for {
  51386 		if !(i < size) {
  51387 			break
  51388 		}
  51389 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(a + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(b + uintptr(i)*4))
  51390 		goto _1
  51391 	_1:
  51392 		;
  51393 		i = i + 1
  51394 	}
  51395 }
  51396 
  51397 func AddVectorEq_C(tls *libc.TLS, a uintptr, out uintptr, size int32) {
  51398 	var i int32
  51399 	_ = i
  51400 	i = 0
  51401 	for {
  51402 		if !(i < size) {
  51403 			break
  51404 		}
  51405 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) += **(**uint32_t)(__ccgo_up(a + uintptr(i)*4))
  51406 		goto _1
  51407 	_1:
  51408 		;
  51409 		i = i + 1
  51410 	}
  51411 }
  51412 
  51413 //------------------------------------------------------------------------------
  51414 // Image transforms.
  51415 
  51416 func PredictorSub0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51417 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51418 	var i int32
  51419 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51420 	i = 0
  51421 	for {
  51422 		if !(i < num_pixels) {
  51423 			break
  51424 		}
  51425 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51426 		v3 = uint32(ARGB_BLACK3)
  51427 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51428 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51429 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51430 		goto _5
  51431 	_5:
  51432 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51433 		goto _1
  51434 	_1:
  51435 		;
  51436 		i = i + 1
  51437 	}
  51438 	_ = upper
  51439 }
  51440 
  51441 func PredictorSub1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51442 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51443 	var i int32
  51444 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51445 	i = 0
  51446 	for {
  51447 		if !(i < num_pixels) {
  51448 			break
  51449 		}
  51450 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51451 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i-int32(1))*4))
  51452 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51453 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51454 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51455 		goto _5
  51456 	_5:
  51457 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51458 		goto _1
  51459 	_1:
  51460 		;
  51461 		i = i + 1
  51462 	}
  51463 	_ = upper
  51464 }
  51465 
  51466 // It subtracts the prediction from the input pixel and stores the residual
  51467 // in the output pixel.
  51468 func PredictorSub2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51469 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51470 	var x int32
  51471 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51472 	x = 0
  51473 	for {
  51474 		if !(x < num_pixels) {
  51475 			break
  51476 		}
  51477 		pred = VP8LPredictor2_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51478 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51479 		v3 = pred
  51480 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51481 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51482 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51483 		goto _5
  51484 	_5:
  51485 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51486 		goto _1
  51487 	_1:
  51488 		;
  51489 		x = x + 1
  51490 	}
  51491 }
  51492 
  51493 func PredictorSub3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51494 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51495 	var x int32
  51496 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51497 	x = 0
  51498 	for {
  51499 		if !(x < num_pixels) {
  51500 			break
  51501 		}
  51502 		pred = VP8LPredictor3_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51503 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51504 		v3 = pred
  51505 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51506 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51507 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51508 		goto _5
  51509 	_5:
  51510 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51511 		goto _1
  51512 	_1:
  51513 		;
  51514 		x = x + 1
  51515 	}
  51516 }
  51517 
  51518 func PredictorSub4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51519 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51520 	var x int32
  51521 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51522 	x = 0
  51523 	for {
  51524 		if !(x < num_pixels) {
  51525 			break
  51526 		}
  51527 		pred = VP8LPredictor4_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51528 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51529 		v3 = pred
  51530 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51531 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51532 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51533 		goto _5
  51534 	_5:
  51535 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51536 		goto _1
  51537 	_1:
  51538 		;
  51539 		x = x + 1
  51540 	}
  51541 }
  51542 
  51543 func PredictorSub5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51544 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51545 	var x int32
  51546 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51547 	x = 0
  51548 	for {
  51549 		if !(x < num_pixels) {
  51550 			break
  51551 		}
  51552 		pred = VP8LPredictor5_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51553 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51554 		v3 = pred
  51555 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51556 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51557 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51558 		goto _5
  51559 	_5:
  51560 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51561 		goto _1
  51562 	_1:
  51563 		;
  51564 		x = x + 1
  51565 	}
  51566 }
  51567 
  51568 func PredictorSub6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51569 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51570 	var x int32
  51571 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51572 	x = 0
  51573 	for {
  51574 		if !(x < num_pixels) {
  51575 			break
  51576 		}
  51577 		pred = VP8LPredictor6_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51578 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51579 		v3 = pred
  51580 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51581 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51582 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51583 		goto _5
  51584 	_5:
  51585 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51586 		goto _1
  51587 	_1:
  51588 		;
  51589 		x = x + 1
  51590 	}
  51591 }
  51592 
  51593 func PredictorSub7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51594 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51595 	var x int32
  51596 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51597 	x = 0
  51598 	for {
  51599 		if !(x < num_pixels) {
  51600 			break
  51601 		}
  51602 		pred = VP8LPredictor7_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51603 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51604 		v3 = pred
  51605 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51606 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51607 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51608 		goto _5
  51609 	_5:
  51610 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51611 		goto _1
  51612 	_1:
  51613 		;
  51614 		x = x + 1
  51615 	}
  51616 }
  51617 
  51618 func PredictorSub8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51619 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51620 	var x int32
  51621 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51622 	x = 0
  51623 	for {
  51624 		if !(x < num_pixels) {
  51625 			break
  51626 		}
  51627 		pred = VP8LPredictor8_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51628 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51629 		v3 = pred
  51630 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51631 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51632 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51633 		goto _5
  51634 	_5:
  51635 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51636 		goto _1
  51637 	_1:
  51638 		;
  51639 		x = x + 1
  51640 	}
  51641 }
  51642 
  51643 func PredictorSub9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51644 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51645 	var x int32
  51646 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51647 	x = 0
  51648 	for {
  51649 		if !(x < num_pixels) {
  51650 			break
  51651 		}
  51652 		pred = VP8LPredictor9_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51653 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51654 		v3 = pred
  51655 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51656 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51657 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51658 		goto _5
  51659 	_5:
  51660 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51661 		goto _1
  51662 	_1:
  51663 		;
  51664 		x = x + 1
  51665 	}
  51666 }
  51667 
  51668 func PredictorSub10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51669 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51670 	var x int32
  51671 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51672 	x = 0
  51673 	for {
  51674 		if !(x < num_pixels) {
  51675 			break
  51676 		}
  51677 		pred = VP8LPredictor10_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51678 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51679 		v3 = pred
  51680 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51681 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51682 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51683 		goto _5
  51684 	_5:
  51685 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51686 		goto _1
  51687 	_1:
  51688 		;
  51689 		x = x + 1
  51690 	}
  51691 }
  51692 
  51693 func PredictorSub11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51694 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51695 	var x int32
  51696 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51697 	x = 0
  51698 	for {
  51699 		if !(x < num_pixels) {
  51700 			break
  51701 		}
  51702 		pred = VP8LPredictor11_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51703 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51704 		v3 = pred
  51705 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51706 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51707 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51708 		goto _5
  51709 	_5:
  51710 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51711 		goto _1
  51712 	_1:
  51713 		;
  51714 		x = x + 1
  51715 	}
  51716 }
  51717 
  51718 func PredictorSub12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51719 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51720 	var x int32
  51721 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51722 	x = 0
  51723 	for {
  51724 		if !(x < num_pixels) {
  51725 			break
  51726 		}
  51727 		pred = VP8LPredictor12_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51728 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51729 		v3 = pred
  51730 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51731 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51732 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51733 		goto _5
  51734 	_5:
  51735 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51736 		goto _1
  51737 	_1:
  51738 		;
  51739 		x = x + 1
  51740 	}
  51741 }
  51742 
  51743 func PredictorSub13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51744 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51745 	var x int32
  51746 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51747 	x = 0
  51748 	for {
  51749 		if !(x < num_pixels) {
  51750 			break
  51751 		}
  51752 		pred = VP8LPredictor13_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51753 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51754 		v3 = pred
  51755 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51756 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51757 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51758 		goto _5
  51759 	_5:
  51760 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51761 		goto _1
  51762 	_1:
  51763 		;
  51764 		x = x + 1
  51765 	}
  51766 }
  51767 
  51768 func VP8LEncDspInit(tls *libc.TLS) {
  51769 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  51770 		goto _1
  51771 	}
  51772 	VP8LEncDspInit_body(tls)
  51773 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  51774 	goto _2
  51775 _2:
  51776 	;
  51777 	goto _1
  51778 _1: /**/ //
  51779 }
  51780 
  51781 var VP8LEncDspInit_body_last_cpuinfo_used = uintptr(0)
  51782 
  51783 func init() {
  51784 	p := unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)
  51785 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))
  51786 }
  51787 
  51788 func VP8LEncDspInit_body(tls *libc.TLS) {
  51789 	VP8LDspInit(tls)
  51790 	VP8LSubtractGreenFromBlueAndRed = __ccgo_fp(VP8LSubtractGreenFromBlueAndRed_C)
  51791 	VP8LTransformColor = __ccgo_fp(VP8LTransformColor_C)
  51792 	VP8LCollectColorBlueTransforms = __ccgo_fp(VP8LCollectColorBlueTransforms_C)
  51793 	VP8LCollectColorRedTransforms = __ccgo_fp(VP8LCollectColorRedTransforms_C)
  51794 	VP8LFastLog2Slow = __ccgo_fp(FastLog2Slow_C)
  51795 	VP8LFastSLog2Slow = __ccgo_fp(FastSLog2Slow_C)
  51796 	VP8LExtraCost = __ccgo_fp(ExtraCost_C)
  51797 	VP8LCombinedShannonEntropy = __ccgo_fp(CombinedShannonEntropy_C)
  51798 	VP8LShannonEntropy = __ccgo_fp(ShannonEntropy_C)
  51799 	VP8LGetEntropyUnrefined = __ccgo_fp(GetEntropyUnrefined_C)
  51800 	VP8LGetCombinedEntropyUnrefined = __ccgo_fp(GetCombinedEntropyUnrefined_C)
  51801 	VP8LAddVector = __ccgo_fp(AddVector_C)
  51802 	VP8LAddVectorEq = __ccgo_fp(AddVectorEq_C)
  51803 	VP8LVectorMismatch = __ccgo_fp(VectorMismatch_C)
  51804 	VP8LBundleColorMap = __ccgo_fp(VP8LBundleColorMap_C)
  51805 	VP8LPredictorsSub[0] = __ccgo_fp(PredictorSub0_C)
  51806 	VP8LPredictorsSub[int32(1)] = __ccgo_fp(PredictorSub1_C)
  51807 	VP8LPredictorsSub[int32(2)] = __ccgo_fp(PredictorSub2_C)
  51808 	VP8LPredictorsSub[int32(3)] = __ccgo_fp(PredictorSub3_C)
  51809 	VP8LPredictorsSub[int32(4)] = __ccgo_fp(PredictorSub4_C)
  51810 	VP8LPredictorsSub[int32(5)] = __ccgo_fp(PredictorSub5_C)
  51811 	VP8LPredictorsSub[int32(6)] = __ccgo_fp(PredictorSub6_C)
  51812 	VP8LPredictorsSub[int32(7)] = __ccgo_fp(PredictorSub7_C)
  51813 	VP8LPredictorsSub[int32(8)] = __ccgo_fp(PredictorSub8_C)
  51814 	VP8LPredictorsSub[int32(9)] = __ccgo_fp(PredictorSub9_C)
  51815 	VP8LPredictorsSub[int32(10)] = __ccgo_fp(PredictorSub10_C)
  51816 	VP8LPredictorsSub[int32(11)] = __ccgo_fp(PredictorSub11_C)
  51817 	VP8LPredictorsSub[int32(12)] = __ccgo_fp(PredictorSub12_C)
  51818 	VP8LPredictorsSub[int32(13)] = __ccgo_fp(PredictorSub13_C)
  51819 	VP8LPredictorsSub[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  51820 	VP8LPredictorsSub[int32(15)] = __ccgo_fp(PredictorSub0_C)
  51821 	VP8LPredictorsSub_C[0] = __ccgo_fp(PredictorSub0_C)
  51822 	VP8LPredictorsSub_C[int32(1)] = __ccgo_fp(PredictorSub1_C)
  51823 	VP8LPredictorsSub_C[int32(2)] = __ccgo_fp(PredictorSub2_C)
  51824 	VP8LPredictorsSub_C[int32(3)] = __ccgo_fp(PredictorSub3_C)
  51825 	VP8LPredictorsSub_C[int32(4)] = __ccgo_fp(PredictorSub4_C)
  51826 	VP8LPredictorsSub_C[int32(5)] = __ccgo_fp(PredictorSub5_C)
  51827 	VP8LPredictorsSub_C[int32(6)] = __ccgo_fp(PredictorSub6_C)
  51828 	VP8LPredictorsSub_C[int32(7)] = __ccgo_fp(PredictorSub7_C)
  51829 	VP8LPredictorsSub_C[int32(8)] = __ccgo_fp(PredictorSub8_C)
  51830 	VP8LPredictorsSub_C[int32(9)] = __ccgo_fp(PredictorSub9_C)
  51831 	VP8LPredictorsSub_C[int32(10)] = __ccgo_fp(PredictorSub10_C)
  51832 	VP8LPredictorsSub_C[int32(11)] = __ccgo_fp(PredictorSub11_C)
  51833 	VP8LPredictorsSub_C[int32(12)] = __ccgo_fp(PredictorSub12_C)
  51834 	VP8LPredictorsSub_C[int32(13)] = __ccgo_fp(PredictorSub13_C)
  51835 	VP8LPredictorsSub_C[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  51836 	VP8LPredictorsSub_C[int32(15)] = __ccgo_fp(PredictorSub0_C)
  51837 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  51838 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  51839 	}
  51840 }
  51841 
  51842 const LOG_2_RECIPROCAL_FIXED_DOUBLE2 = 12102203.161561485379934310913085937500
  51843 
  51844 func VP8LEncDspInitMIPS32(tls *libc.TLS) {
  51845 }
  51846 
  51847 func VP8LEncDspInitMIPSdspR2(tls *libc.TLS) {
  51848 }
  51849 
  51850 func VP8LEncDspInitMSA(tls *libc.TLS) {
  51851 }
  51852 
  51853 func VP8LEncDspInitNEON(tls *libc.TLS) {
  51854 }
  51855 
  51856 func VP8LEncDspInitSSE2(tls *libc.TLS) {
  51857 }
  51858 
  51859 func VP8LEncDspInitSSE41(tls *libc.TLS) {
  51860 }
  51861 
  51862 func VP8LDspInitMIPSdspR2(tls *libc.TLS) {
  51863 }
  51864 
  51865 func VP8LDspInitMSA(tls *libc.TLS) {
  51866 }
  51867 
  51868 func VP8LDspInitNEON(tls *libc.TLS) {
  51869 }
  51870 
  51871 func VP8LDspInitSSE2(tls *libc.TLS) {
  51872 }
  51873 
  51874 func VP8LDspInitSSE41(tls *libc.TLS) {
  51875 }
  51876 
  51877 //------------------------------------------------------------------------------
  51878 
  51879 //------------------------------------------------------------------------------
  51880 // Implementations of critical functions ImportRow / ExportRow
  51881 
  51882 //------------------------------------------------------------------------------
  51883 // Row import
  51884 
  51885 func WebPRescalerImportRowExpand_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  51886 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  51887 	var left, right rescaler_t
  51888 	var v2 uint32
  51889 	_, _, _, _, _, _, _, _, _ = accum, channel, left, right, x_in, x_out, x_out_max, x_stride, v2
  51890 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  51891 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  51892 	channel = 0
  51893 	for {
  51894 		if !(channel < x_stride) {
  51895 			break
  51896 		}
  51897 		x_in = channel
  51898 		x_out = channel
  51899 		// simple bilinear interpolation
  51900 		accum = (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  51901 		left = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  51902 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fsrc_width > int32(1) {
  51903 			v2 = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in+x_stride))))
  51904 		} else {
  51905 			v2 = left
  51906 		}
  51907 		right = v2
  51908 		x_in = x_in + x_stride
  51909 		for int32(1) != 0 {
  51910 			**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow + uintptr(x_out)*4)) = right*libc.Uint32FromInt32((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add) + (left-right)*libc.Uint32FromInt32(accum)
  51911 			x_out = x_out + x_stride
  51912 			if x_out >= x_out_max {
  51913 				break
  51914 			}
  51915 			accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  51916 			if accum < 0 {
  51917 				left = right
  51918 				x_in = x_in + x_stride
  51919 				right = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  51920 				accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  51921 			}
  51922 		}
  51923 		goto _1
  51924 	_1:
  51925 		;
  51926 		channel = channel + 1
  51927 	}
  51928 }
  51929 
  51930 func WebPRescalerImportRowShrink_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  51931 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  51932 	var base, sum uint32_t
  51933 	var frac rescaler_t
  51934 	_, _, _, _, _, _, _, _, _ = accum, base, channel, frac, sum, x_in, x_out, x_out_max, x_stride
  51935 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  51936 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  51937 	channel = 0
  51938 	for {
  51939 		if !(channel < x_stride) {
  51940 			break
  51941 		}
  51942 		x_in = channel
  51943 		x_out = channel
  51944 		sum = uint32(0)
  51945 		accum = 0
  51946 		for x_out < x_out_max {
  51947 			base = uint32(0)
  51948 			accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  51949 			for accum > 0 {
  51950 				accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  51951 				base = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  51952 				sum = sum + base
  51953 				x_in = x_in + x_stride
  51954 			}
  51955 			// Emit next horizontal pixel.
  51956 			frac = base * libc.Uint32FromInt32(-accum)
  51957 			**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow + uintptr(x_out)*4)) = sum*libc.Uint32FromInt32((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub) - frac
  51958 			// fresh fractional start for next pixel
  51959 			sum = libc.Uint32FromInt32(libc.Int32FromUint64((uint64(frac)*uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Ffx_scale) + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX)))
  51960 			x_out = x_out + x_stride
  51961 		}
  51962 		goto _1
  51963 	_1:
  51964 		;
  51965 		channel = channel + 1
  51966 	}
  51967 }
  51968 
  51969 //------------------------------------------------------------------------------
  51970 // Row export
  51971 
  51972 func WebPRescalerExportRowExpand_C(tls *libc.TLS, wrk uintptr) {
  51973 	var A, B, J, J1 uint32_t
  51974 	var I uint64_t
  51975 	var dst, frow, irow uintptr
  51976 	var v, v1, x_out, x_out_max int32
  51977 	var v2 uint32
  51978 	_, _, _, _, _, _, _, _, _, _, _, _, _ = A, B, I, J, J1, dst, frow, irow, v, v1, x_out, x_out_max, v2
  51979 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  51980 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  51981 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  51982 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  51983 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum == 0 {
  51984 		x_out = 0
  51985 		for {
  51986 			if !(x_out < x_out_max) {
  51987 				break
  51988 			}
  51989 			J = **(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))
  51990 			v = libc.Int32FromUint64((uint64(J)*uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Ffy_scale) + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  51991 			if v > int32(255) {
  51992 				v2 = uint32(255)
  51993 			} else {
  51994 				v2 = uint32(libc.Uint8FromInt32(v))
  51995 			}
  51996 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  51997 			goto _1
  51998 		_1:
  51999 			;
  52000 			x_out = x_out + 1
  52001 		}
  52002 	} else {
  52003 		B = uint32(libc.Uint64FromInt32(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(wrk)).Fy_sub))
  52004 		A = uint32(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX) - uint64(B))
  52005 		x_out = 0
  52006 		for {
  52007 			if !(x_out < x_out_max) {
  52008 				break
  52009 			}
  52010 			I = uint64(A)*uint64(**(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))) + uint64(B)*uint64(**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)))
  52011 			J1 = uint32((I + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52012 			v1 = libc.Int32FromUint64((uint64(J1)*uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Ffy_scale) + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52013 			if v1 > int32(255) {
  52014 				v2 = uint32(255)
  52015 			} else {
  52016 				v2 = uint32(libc.Uint8FromInt32(v1))
  52017 			}
  52018 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52019 			goto _3
  52020 		_3:
  52021 			;
  52022 			x_out = x_out + 1
  52023 		}
  52024 	}
  52025 }
  52026 
  52027 func WebPRescalerExportRowShrink_C(tls *libc.TLS, wrk uintptr) {
  52028 	var dst, frow, irow uintptr
  52029 	var frac, yscale uint32_t
  52030 	var v, v1, x_out, x_out_max int32
  52031 	var v2 uint32
  52032 	_, _, _, _, _, _, _, _, _, _ = dst, frac, frow, irow, v, v1, x_out, x_out_max, yscale, v2
  52033 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52034 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52035 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52036 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52037 	yscale = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffy_scale * libc.Uint32FromInt32(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum)
  52038 	if yscale != 0 {
  52039 		x_out = 0
  52040 		for {
  52041 			if !(x_out < x_out_max) {
  52042 				break
  52043 			}
  52044 			frac = uint32(uint64(**(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))) * uint64(yscale) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52045 			v = libc.Int32FromUint64((uint64(**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4))-frac)*uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Ffxy_scale) + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52046 			if v > int32(255) {
  52047 				v2 = uint32(255)
  52048 			} else {
  52049 				v2 = uint32(libc.Uint8FromInt32(v))
  52050 			}
  52051 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52052 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = frac // new fractional start
  52053 			goto _1
  52054 		_1:
  52055 			;
  52056 			x_out = x_out + 1
  52057 		}
  52058 	} else {
  52059 		x_out = 0
  52060 		for {
  52061 			if !(x_out < x_out_max) {
  52062 				break
  52063 			}
  52064 			v1 = libc.Int32FromUint64((uint64(**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)))*uint64((*WebPRescaler)(unsafe.Pointer(wrk)).Ffxy_scale) + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52065 			if v1 > int32(255) {
  52066 				v2 = uint32(255)
  52067 			} else {
  52068 				v2 = uint32(libc.Uint8FromInt32(v1))
  52069 			}
  52070 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52071 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = uint32(0)
  52072 			goto _3
  52073 		_3:
  52074 			;
  52075 			x_out = x_out + 1
  52076 		}
  52077 	}
  52078 }
  52079 
  52080 //------------------------------------------------------------------------------
  52081 // Main entry calls
  52082 
  52083 func WebPRescalerImportRow(tls *libc.TLS, wrk uintptr, src uintptr) {
  52084 	if !((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_expand != 0) {
  52085 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowShrink})))(tls, wrk, src)
  52086 	} else {
  52087 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowExpand})))(tls, wrk, src)
  52088 	}
  52089 }
  52090 
  52091 func WebPRescalerExportRow(tls *libc.TLS, wrk uintptr) {
  52092 	var i int32
  52093 	_ = i
  52094 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum <= 0 {
  52095 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_expand != 0 {
  52096 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowExpand})))(tls, wrk)
  52097 		} else {
  52098 			if (*WebPRescaler)(unsafe.Pointer(wrk)).Ffxy_scale != 0 {
  52099 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowShrink})))(tls, wrk)
  52100 			} else {
  52101 				i = 0
  52102 				for {
  52103 					if !(i < (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width) {
  52104 						break
  52105 					}
  52106 					**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst + uintptr(i))) = uint8(**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)))
  52107 					**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)) = uint32(0)
  52108 					goto _1
  52109 				_1:
  52110 					;
  52111 					i = i + 1
  52112 				}
  52113 			}
  52114 		}
  52115 		**(**int32)(__ccgo_up(wrk + 24)) += (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_add
  52116 		**(**uintptr)(__ccgo_up(wrk + 72)) += uintptr((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_stride)
  52117 		(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y + 1
  52118 	}
  52119 }
  52120 
  52121 func WebPRescalerDspInit(tls *libc.TLS) {
  52122 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52123 		goto _1
  52124 	}
  52125 	WebPRescalerDspInit_body(tls)
  52126 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52127 	goto _2
  52128 _2:
  52129 	;
  52130 	goto _1
  52131 _1: /**/ //
  52132 }
  52133 
  52134 var WebPRescalerDspInit_body_last_cpuinfo_used = uintptr(0)
  52135 
  52136 func init() {
  52137 	p := unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)
  52138 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))
  52139 }
  52140 
  52141 func WebPRescalerDspInit_body(tls *libc.TLS) {
  52142 	WebPRescalerExportRowExpand = __ccgo_fp(WebPRescalerExportRowExpand_C)
  52143 	WebPRescalerExportRowShrink = __ccgo_fp(WebPRescalerExportRowShrink_C)
  52144 	WebPRescalerImportRowExpand = __ccgo_fp(WebPRescalerImportRowExpand_C)
  52145 	WebPRescalerImportRowShrink = __ccgo_fp(WebPRescalerImportRowShrink_C)
  52146 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52147 	}
  52148 }
  52149 
  52150 func WebPRescalerDspInitMIPS32(tls *libc.TLS) {
  52151 }
  52152 
  52153 func WebPRescalerDspInitMIPSdspR2(tls *libc.TLS) {
  52154 }
  52155 
  52156 func WebPRescalerDspInitMSA(tls *libc.TLS) {
  52157 }
  52158 
  52159 func WebPRescalerDspInitNEON(tls *libc.TLS) {
  52160 }
  52161 
  52162 func WebPRescalerDspInitSSE2(tls *libc.TLS) {
  52163 }
  52164 
  52165 // Copyright 2010 Google Inc. All Rights Reserved.
  52166 //
  52167 // Use of this source code is governed by a BSD-style license
  52168 // that can be found in the COPYING file in the root of the source
  52169 // tree. An additional intellectual property rights grant can be found
  52170 // in the file PATENTS. All contributing project authors may
  52171 // be found in the AUTHORS file in the root of the source tree.
  52172 // -----------------------------------------------------------------------------
  52173 //
  52174 //  Common types + memory wrappers
  52175 //
  52176 // Author: Skal (pascal.massimino@gmail.com)
  52177 
  52178 //------------------------------------------------------------------------------
  52179 // SSIM / PSNR
  52180 
  52181 // C documentation
  52182 //
  52183 //	// hat-shaped filter. Sum of coefficients is equal to 16.
  52184 var kWeight = [7]uint32_t{
  52185 	0: uint32(1),
  52186 	1: uint32(2),
  52187 	2: uint32(3),
  52188 	3: uint32(4),
  52189 	4: uint32(3),
  52190 	5: uint32(2),
  52191 	6: uint32(1),
  52192 }
  52193 var kWeightSum = libc.Uint32FromInt32(libc.Int32FromInt32(16) * libc.Int32FromInt32(16)) // sum{kWeight}^2
  52194 
  52195 func SSIMCalculation(tls *libc.TLS, stats uintptr, N uint32_t) (r1 float64) {
  52196 	var C1, C2, C3, w2 uint32_t
  52197 	var den_S, fden, fnum, num_S, sxx, syy, xmxm, ymym uint64_t
  52198 	var r float64
  52199 	var sxy, xmym int64_t
  52200 	var v1 int64
  52201 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = C1, C2, C3, den_S, fden, fnum, num_S, r, sxx, sxy, syy, w2, xmxm, xmym, ymym, v1
  52202 	w2 = N * N
  52203 	C1 = uint32(20) * w2
  52204 	C2 = uint32(60) * w2
  52205 	C3 = libc.Uint32FromInt32(libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) * w2 // 'dark' limit ~= 6
  52206 	xmxm = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm)
  52207 	ymym = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52208 	if xmxm+ymym >= uint64(C3) {
  52209 		xmym = libc.Int64FromUint32((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * libc.Int64FromUint32((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52210 		sxy = libc.Int64FromUint32((*VP8DistoStats)(unsafe.Pointer(stats)).Fxym)*libc.Int64FromUint32(N) - xmym // can be negative
  52211 		sxx = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxxm)*uint64(N) - xmxm
  52212 		syy = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fyym)*uint64(N) - ymym
  52213 		if sxy < 0 {
  52214 			v1 = 0
  52215 		} else {
  52216 			v1 = sxy
  52217 		}
  52218 		// we descale by 8 to prevent overflow during the fnum/fden multiply.
  52219 		num_S = (uint64(2)*libc.Uint64FromInt64(v1) + uint64(C2)) >> int32(8)
  52220 		den_S = (sxx + syy + uint64(C2)) >> int32(8)
  52221 		fnum = libc.Uint64FromInt64(libc.Int64FromInt32(2)*xmym+libc.Int64FromUint32(C1)) * num_S
  52222 		fden = (xmxm + ymym + uint64(C1)) * den_S
  52223 		r = float64(fnum) / float64(fden)
  52224 		return r
  52225 	}
  52226 	return float64(1) // area is too dark to contribute meaningfully
  52227 }
  52228 
  52229 func VP8SSIMFromStats(tls *libc.TLS, stats uintptr) (r float64) {
  52230 	return SSIMCalculation(tls, stats, kWeightSum)
  52231 }
  52232 
  52233 func VP8SSIMFromStatsClipped(tls *libc.TLS, stats uintptr) (r float64) {
  52234 	return SSIMCalculation(tls, stats, (*VP8DistoStats)(unsafe.Pointer(stats)).Fw)
  52235 }
  52236 
  52237 func SSIMGetClipped_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32, xo int32, yo int32, W int32, H int32) (r float64) {
  52238 	bp := tls.Alloc(32)
  52239 	defer tls.Free(32)
  52240 	var s1, s2, w uint32_t
  52241 	var x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4 int32
  52242 	var _ /* stats at bp+0 */ VP8DistoStats
  52243 	_, _, _, _, _, _, _, _, _, _, _, _, _ = s1, s2, w, x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4
  52244 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52245 	if yo-int32(VP8_SSIM_KERNEL) < 0 {
  52246 		v1 = 0
  52247 	} else {
  52248 		v1 = yo - int32(VP8_SSIM_KERNEL)
  52249 	}
  52250 	ymin = v1
  52251 	if yo+int32(VP8_SSIM_KERNEL) > H-int32(1) {
  52252 		v2 = H - int32(1)
  52253 	} else {
  52254 		v2 = yo + int32(VP8_SSIM_KERNEL)
  52255 	}
  52256 	ymax = v2
  52257 	if xo-int32(VP8_SSIM_KERNEL) < 0 {
  52258 		v3 = 0
  52259 	} else {
  52260 		v3 = xo - int32(VP8_SSIM_KERNEL)
  52261 	}
  52262 	xmin = v3
  52263 	if xo+int32(VP8_SSIM_KERNEL) > W-int32(1) {
  52264 		v4 = W - int32(1)
  52265 	} else {
  52266 		v4 = xo + int32(VP8_SSIM_KERNEL)
  52267 	}
  52268 	xmax = v4
  52269 	src1 = src1 + uintptr(ymin*stride1)
  52270 	src2 = src2 + uintptr(ymin*stride2)
  52271 	y = ymin
  52272 	for {
  52273 		if !(y <= ymax) {
  52274 			break
  52275 		}
  52276 		x = xmin
  52277 		for {
  52278 			if !(x <= xmax) {
  52279 				break
  52280 			}
  52281 			w = kWeight[int32(VP8_SSIM_KERNEL)+x-xo] * kWeight[int32(VP8_SSIM_KERNEL)+y-yo]
  52282 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52283 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52284 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fw += w
  52285 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52286 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52287 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52288 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52289 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52290 			goto _6
  52291 		_6:
  52292 			;
  52293 			x = x + 1
  52294 		}
  52295 		goto _5
  52296 	_5:
  52297 		;
  52298 		y = y + 1
  52299 		src1 = src1 + uintptr(stride1)
  52300 		src2 = src2 + uintptr(stride2)
  52301 	}
  52302 	return VP8SSIMFromStatsClipped(tls, bp)
  52303 }
  52304 
  52305 func SSIMGet_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32) (r float64) {
  52306 	bp := tls.Alloc(32)
  52307 	defer tls.Free(32)
  52308 	var s1, s2, w uint32_t
  52309 	var x, y int32
  52310 	var _ /* stats at bp+0 */ VP8DistoStats
  52311 	_, _, _, _, _ = s1, s2, w, x, y
  52312 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52313 	y = 0
  52314 	for {
  52315 		if !(y <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52316 			break
  52317 		}
  52318 		x = 0
  52319 		for {
  52320 			if !(x <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52321 				break
  52322 			}
  52323 			w = kWeight[x] * kWeight[y]
  52324 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52325 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52326 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52327 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52328 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52329 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52330 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52331 			goto _2
  52332 		_2:
  52333 			;
  52334 			x = x + 1
  52335 		}
  52336 		goto _1
  52337 	_1:
  52338 		;
  52339 		y = y + 1
  52340 		src1 = src1 + uintptr(stride1)
  52341 		src2 = src2 + uintptr(stride2)
  52342 	}
  52343 	return VP8SSIMFromStats(tls, bp)
  52344 }
  52345 
  52346 //------------------------------------------------------------------------------
  52347 
  52348 func AccumulateSSE_C(tls *libc.TLS, src1 uintptr, src2 uintptr, len1 int32) (r uint32_t) {
  52349 	var diff int32_t
  52350 	var i int32
  52351 	var sse2 uint32_t
  52352 	_, _, _ = diff, i, sse2
  52353 	sse2 = uint32(0)
  52354 	// to ensure that accumulation fits within uint32_t
  52355 	i = 0
  52356 	for {
  52357 		if !(i < len1) {
  52358 			break
  52359 		}
  52360 		diff = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src1 + uintptr(i)))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src2 + uintptr(i))))
  52361 		sse2 = sse2 + libc.Uint32FromInt32(diff*diff)
  52362 		goto _1
  52363 	_1:
  52364 		;
  52365 		i = i + 1
  52366 	}
  52367 	return sse2
  52368 }
  52369 
  52370 func VP8SSIMDspInit(tls *libc.TLS) {
  52371 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52372 		goto _1
  52373 	}
  52374 	VP8SSIMDspInit_body(tls)
  52375 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52376 	goto _2
  52377 _2:
  52378 	;
  52379 	goto _1
  52380 _1: /**/ //
  52381 }
  52382 
  52383 var VP8SSIMDspInit_body_last_cpuinfo_used = uintptr(0)
  52384 
  52385 func init() {
  52386 	p := unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)
  52387 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))
  52388 }
  52389 
  52390 func VP8SSIMDspInit_body(tls *libc.TLS) {
  52391 	VP8SSIMGetClipped = __ccgo_fp(SSIMGetClipped_C)
  52392 	VP8SSIMGet = __ccgo_fp(SSIMGet_C)
  52393 	VP8AccumulateSSE = __ccgo_fp(AccumulateSSE_C)
  52394 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52395 	}
  52396 }
  52397 
  52398 func VP8SSIMDspInitSSE2(tls *libc.TLS) {
  52399 }
  52400 
  52401 // Given samples laid out in a square as:
  52402 //  [a b]
  52403 //  [c d]
  52404 // we interpolate u/v as:
  52405 //  ([9*a + 3*b + 3*c +   d    3*a + 9*b + 3*c +   d] + [8 8]) / 16
  52406 //  ([3*a +   b + 9*c + 3*d      a + 3*b + 3*c + 9*d]   [8 8]) / 16
  52407 
  52408 // We process u and v together stashed into 32bit (16bit each).
  52409 
  52410 // C documentation
  52411 //
  52412 //	// All variants implemented.
  52413 func UpsampleRgbaLinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  52414 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  52415 	var last_pixel_pair, x, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  52416 	var v1, v5 uintptr
  52417 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, diag_03, diag_12, l_uv, last_pixel_pair, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v5, v6, v8
  52418 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  52419 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  52420 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  52421 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  52422 	v1 = top_dst
  52423 	v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  52424 	v3 = libc.Int32FromUint8(uint8(uv0 & uint32(0xff)))
  52425 	v4 = libc.Int32FromUint8(uint8(uv0 >> libc.Int32FromInt32(16)))
  52426 	v5 = v1
  52427 	v8 = v2 * int32(19077) >> int32(8)
  52428 	goto _9
  52429 _9:
  52430 	v10 = v4 * int32(26149) >> int32(8)
  52431 	goto _11
  52432 _11:
  52433 	v12 = v8 + v10 - int32(14234)
  52434 	if v12 & ^int32(YUV_MASK2) == 0 {
  52435 		v15 = v12 >> int32(YUV_FIX2)
  52436 	} else {
  52437 		if v12 < 0 {
  52438 			v16 = 0
  52439 		} else {
  52440 			v16 = int32(255)
  52441 		}
  52442 		v15 = v16
  52443 	}
  52444 	v13 = v15
  52445 	goto _14
  52446 _14:
  52447 	v6 = v13
  52448 	goto _7
  52449 _7:
  52450 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52451 	v19 = v2 * int32(19077) >> int32(8)
  52452 	goto _20
  52453 _20:
  52454 	v21 = v3 * int32(6419) >> int32(8)
  52455 	goto _22
  52456 _22:
  52457 	v23 = v4 * int32(13320) >> int32(8)
  52458 	goto _24
  52459 _24:
  52460 	v25 = v19 - v21 - v23 + int32(8708)
  52461 	if v25 & ^int32(YUV_MASK2) == 0 {
  52462 		v28 = v25 >> int32(YUV_FIX2)
  52463 	} else {
  52464 		if v25 < 0 {
  52465 			v29 = 0
  52466 		} else {
  52467 			v29 = int32(255)
  52468 		}
  52469 		v28 = v29
  52470 	}
  52471 	v26 = v28
  52472 	goto _27
  52473 _27:
  52474 	v17 = v26
  52475 	goto _18
  52476 _18:
  52477 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52478 	v32 = v2 * int32(19077) >> int32(8)
  52479 	goto _33
  52480 _33:
  52481 	v34 = v3 * int32(33050) >> int32(8)
  52482 	goto _35
  52483 _35:
  52484 	v36 = v32 + v34 - int32(17685)
  52485 	if v36 & ^int32(YUV_MASK2) == 0 {
  52486 		v39 = v36 >> int32(YUV_FIX2)
  52487 	} else {
  52488 		if v36 < 0 {
  52489 			v40 = 0
  52490 		} else {
  52491 			v40 = int32(255)
  52492 		}
  52493 		v39 = v40
  52494 	}
  52495 	v37 = v39
  52496 	goto _38
  52497 _38:
  52498 	v30 = v37
  52499 	goto _31
  52500 _31:
  52501 	**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52502 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52503 	if bottom_y != libc.UintptrFromInt32(0) {
  52504 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  52505 		v1 = bottom_dst
  52506 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  52507 		v3 = libc.Int32FromUint8(uint8(uv01 & uint32(0xff)))
  52508 		v4 = libc.Int32FromUint8(uint8(uv01 >> libc.Int32FromInt32(16)))
  52509 		v5 = v1
  52510 		v8 = v2 * int32(19077) >> int32(8)
  52511 		goto _49
  52512 	_49:
  52513 		v10 = v4 * int32(26149) >> int32(8)
  52514 		goto _51
  52515 	_51:
  52516 		v12 = v8 + v10 - int32(14234)
  52517 		if v12 & ^int32(YUV_MASK2) == 0 {
  52518 			v15 = v12 >> int32(YUV_FIX2)
  52519 		} else {
  52520 			if v12 < 0 {
  52521 				v16 = 0
  52522 			} else {
  52523 				v16 = int32(255)
  52524 			}
  52525 			v15 = v16
  52526 		}
  52527 		v13 = v15
  52528 		goto _54
  52529 	_54:
  52530 		v6 = v13
  52531 		goto _47
  52532 	_47:
  52533 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52534 		v19 = v2 * int32(19077) >> int32(8)
  52535 		goto _60
  52536 	_60:
  52537 		v21 = v3 * int32(6419) >> int32(8)
  52538 		goto _62
  52539 	_62:
  52540 		v23 = v4 * int32(13320) >> int32(8)
  52541 		goto _64
  52542 	_64:
  52543 		v25 = v19 - v21 - v23 + int32(8708)
  52544 		if v25 & ^int32(YUV_MASK2) == 0 {
  52545 			v28 = v25 >> int32(YUV_FIX2)
  52546 		} else {
  52547 			if v25 < 0 {
  52548 				v29 = 0
  52549 			} else {
  52550 				v29 = int32(255)
  52551 			}
  52552 			v28 = v29
  52553 		}
  52554 		v26 = v28
  52555 		goto _67
  52556 	_67:
  52557 		v17 = v26
  52558 		goto _58
  52559 	_58:
  52560 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52561 		v32 = v2 * int32(19077) >> int32(8)
  52562 		goto _73
  52563 	_73:
  52564 		v34 = v3 * int32(33050) >> int32(8)
  52565 		goto _75
  52566 	_75:
  52567 		v36 = v32 + v34 - int32(17685)
  52568 		if v36 & ^int32(YUV_MASK2) == 0 {
  52569 			v39 = v36 >> int32(YUV_FIX2)
  52570 		} else {
  52571 			if v36 < 0 {
  52572 				v40 = 0
  52573 			} else {
  52574 				v40 = int32(255)
  52575 			}
  52576 			v39 = v40
  52577 		}
  52578 		v37 = v39
  52579 		goto _78
  52580 	_78:
  52581 		v30 = v37
  52582 		goto _71
  52583 	_71:
  52584 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52585 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52586 	}
  52587 	x = int32(1)
  52588 	for {
  52589 		if !(x <= last_pixel_pair) {
  52590 			break
  52591 		}
  52592 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  52593 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  52594 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  52595 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  52596 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  52597 		uv02 = (diag_12 + tl_uv) >> int32(1)
  52598 		uv1 = (diag_03 + t_uv) >> int32(1)
  52599 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  52600 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  52601 		v3 = libc.Int32FromUint8(uint8(uv02 & uint32(0xff)))
  52602 		v4 = libc.Int32FromUint8(uint8(uv02 >> libc.Int32FromInt32(16)))
  52603 		v5 = v1
  52604 		v8 = v2 * int32(19077) >> int32(8)
  52605 		goto _90
  52606 	_90:
  52607 		v10 = v4 * int32(26149) >> int32(8)
  52608 		goto _92
  52609 	_92:
  52610 		v12 = v8 + v10 - int32(14234)
  52611 		if v12 & ^int32(YUV_MASK2) == 0 {
  52612 			v15 = v12 >> int32(YUV_FIX2)
  52613 		} else {
  52614 			if v12 < 0 {
  52615 				v16 = 0
  52616 			} else {
  52617 				v16 = int32(255)
  52618 			}
  52619 			v15 = v16
  52620 		}
  52621 		v13 = v15
  52622 		goto _95
  52623 	_95:
  52624 		v6 = v13
  52625 		goto _88
  52626 	_88:
  52627 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52628 		v19 = v2 * int32(19077) >> int32(8)
  52629 		goto _101
  52630 	_101:
  52631 		v21 = v3 * int32(6419) >> int32(8)
  52632 		goto _103
  52633 	_103:
  52634 		v23 = v4 * int32(13320) >> int32(8)
  52635 		goto _105
  52636 	_105:
  52637 		v25 = v19 - v21 - v23 + int32(8708)
  52638 		if v25 & ^int32(YUV_MASK2) == 0 {
  52639 			v28 = v25 >> int32(YUV_FIX2)
  52640 		} else {
  52641 			if v25 < 0 {
  52642 				v29 = 0
  52643 			} else {
  52644 				v29 = int32(255)
  52645 			}
  52646 			v28 = v29
  52647 		}
  52648 		v26 = v28
  52649 		goto _108
  52650 	_108:
  52651 		v17 = v26
  52652 		goto _99
  52653 	_99:
  52654 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52655 		v32 = v2 * int32(19077) >> int32(8)
  52656 		goto _114
  52657 	_114:
  52658 		v34 = v3 * int32(33050) >> int32(8)
  52659 		goto _116
  52660 	_116:
  52661 		v36 = v32 + v34 - int32(17685)
  52662 		if v36 & ^int32(YUV_MASK2) == 0 {
  52663 			v39 = v36 >> int32(YUV_FIX2)
  52664 		} else {
  52665 			if v36 < 0 {
  52666 				v40 = 0
  52667 			} else {
  52668 				v40 = int32(255)
  52669 			}
  52670 			v39 = v40
  52671 		}
  52672 		v37 = v39
  52673 		goto _119
  52674 	_119:
  52675 		v30 = v37
  52676 		goto _112
  52677 	_112:
  52678 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52679 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52680 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  52681 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  52682 		v3 = libc.Int32FromUint8(uint8(uv1 & uint32(0xff)))
  52683 		v4 = libc.Int32FromUint8(uint8(uv1 >> libc.Int32FromInt32(16)))
  52684 		v5 = v1
  52685 		v8 = v2 * int32(19077) >> int32(8)
  52686 		goto _130
  52687 	_130:
  52688 		v10 = v4 * int32(26149) >> int32(8)
  52689 		goto _132
  52690 	_132:
  52691 		v12 = v8 + v10 - int32(14234)
  52692 		if v12 & ^int32(YUV_MASK2) == 0 {
  52693 			v15 = v12 >> int32(YUV_FIX2)
  52694 		} else {
  52695 			if v12 < 0 {
  52696 				v16 = 0
  52697 			} else {
  52698 				v16 = int32(255)
  52699 			}
  52700 			v15 = v16
  52701 		}
  52702 		v13 = v15
  52703 		goto _135
  52704 	_135:
  52705 		v6 = v13
  52706 		goto _128
  52707 	_128:
  52708 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52709 		v19 = v2 * int32(19077) >> int32(8)
  52710 		goto _141
  52711 	_141:
  52712 		v21 = v3 * int32(6419) >> int32(8)
  52713 		goto _143
  52714 	_143:
  52715 		v23 = v4 * int32(13320) >> int32(8)
  52716 		goto _145
  52717 	_145:
  52718 		v25 = v19 - v21 - v23 + int32(8708)
  52719 		if v25 & ^int32(YUV_MASK2) == 0 {
  52720 			v28 = v25 >> int32(YUV_FIX2)
  52721 		} else {
  52722 			if v25 < 0 {
  52723 				v29 = 0
  52724 			} else {
  52725 				v29 = int32(255)
  52726 			}
  52727 			v28 = v29
  52728 		}
  52729 		v26 = v28
  52730 		goto _148
  52731 	_148:
  52732 		v17 = v26
  52733 		goto _139
  52734 	_139:
  52735 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52736 		v32 = v2 * int32(19077) >> int32(8)
  52737 		goto _154
  52738 	_154:
  52739 		v34 = v3 * int32(33050) >> int32(8)
  52740 		goto _156
  52741 	_156:
  52742 		v36 = v32 + v34 - int32(17685)
  52743 		if v36 & ^int32(YUV_MASK2) == 0 {
  52744 			v39 = v36 >> int32(YUV_FIX2)
  52745 		} else {
  52746 			if v36 < 0 {
  52747 				v40 = 0
  52748 			} else {
  52749 				v40 = int32(255)
  52750 			}
  52751 			v39 = v40
  52752 		}
  52753 		v37 = v39
  52754 		goto _159
  52755 	_159:
  52756 		v30 = v37
  52757 		goto _152
  52758 	_152:
  52759 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52760 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52761 		if bottom_y != libc.UintptrFromInt32(0) {
  52762 			uv03 = (diag_03 + l_uv) >> int32(1)
  52763 			uv11 = (diag_12 + uv) >> int32(1)
  52764 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  52765 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  52766 			v3 = libc.Int32FromUint8(uint8(uv03 & uint32(0xff)))
  52767 			v4 = libc.Int32FromUint8(uint8(uv03 >> libc.Int32FromInt32(16)))
  52768 			v5 = v1
  52769 			v8 = v2 * int32(19077) >> int32(8)
  52770 			goto _170
  52771 		_170:
  52772 			v10 = v4 * int32(26149) >> int32(8)
  52773 			goto _172
  52774 		_172:
  52775 			v12 = v8 + v10 - int32(14234)
  52776 			if v12 & ^int32(YUV_MASK2) == 0 {
  52777 				v15 = v12 >> int32(YUV_FIX2)
  52778 			} else {
  52779 				if v12 < 0 {
  52780 					v16 = 0
  52781 				} else {
  52782 					v16 = int32(255)
  52783 				}
  52784 				v15 = v16
  52785 			}
  52786 			v13 = v15
  52787 			goto _175
  52788 		_175:
  52789 			v6 = v13
  52790 			goto _168
  52791 		_168:
  52792 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52793 			v19 = v2 * int32(19077) >> int32(8)
  52794 			goto _181
  52795 		_181:
  52796 			v21 = v3 * int32(6419) >> int32(8)
  52797 			goto _183
  52798 		_183:
  52799 			v23 = v4 * int32(13320) >> int32(8)
  52800 			goto _185
  52801 		_185:
  52802 			v25 = v19 - v21 - v23 + int32(8708)
  52803 			if v25 & ^int32(YUV_MASK2) == 0 {
  52804 				v28 = v25 >> int32(YUV_FIX2)
  52805 			} else {
  52806 				if v25 < 0 {
  52807 					v29 = 0
  52808 				} else {
  52809 					v29 = int32(255)
  52810 				}
  52811 				v28 = v29
  52812 			}
  52813 			v26 = v28
  52814 			goto _188
  52815 		_188:
  52816 			v17 = v26
  52817 			goto _179
  52818 		_179:
  52819 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52820 			v32 = v2 * int32(19077) >> int32(8)
  52821 			goto _194
  52822 		_194:
  52823 			v34 = v3 * int32(33050) >> int32(8)
  52824 			goto _196
  52825 		_196:
  52826 			v36 = v32 + v34 - int32(17685)
  52827 			if v36 & ^int32(YUV_MASK2) == 0 {
  52828 				v39 = v36 >> int32(YUV_FIX2)
  52829 			} else {
  52830 				if v36 < 0 {
  52831 					v40 = 0
  52832 				} else {
  52833 					v40 = int32(255)
  52834 				}
  52835 				v39 = v40
  52836 			}
  52837 			v37 = v39
  52838 			goto _199
  52839 		_199:
  52840 			v30 = v37
  52841 			goto _192
  52842 		_192:
  52843 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52844 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52845 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  52846 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  52847 			v3 = libc.Int32FromUint8(uint8(uv11 & uint32(0xff)))
  52848 			v4 = libc.Int32FromUint8(uint8(uv11 >> libc.Int32FromInt32(16)))
  52849 			v5 = v1
  52850 			v8 = v2 * int32(19077) >> int32(8)
  52851 			goto _210
  52852 		_210:
  52853 			v10 = v4 * int32(26149) >> int32(8)
  52854 			goto _212
  52855 		_212:
  52856 			v12 = v8 + v10 - int32(14234)
  52857 			if v12 & ^int32(YUV_MASK2) == 0 {
  52858 				v15 = v12 >> int32(YUV_FIX2)
  52859 			} else {
  52860 				if v12 < 0 {
  52861 					v16 = 0
  52862 				} else {
  52863 					v16 = int32(255)
  52864 				}
  52865 				v15 = v16
  52866 			}
  52867 			v13 = v15
  52868 			goto _215
  52869 		_215:
  52870 			v6 = v13
  52871 			goto _208
  52872 		_208:
  52873 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52874 			v19 = v2 * int32(19077) >> int32(8)
  52875 			goto _221
  52876 		_221:
  52877 			v21 = v3 * int32(6419) >> int32(8)
  52878 			goto _223
  52879 		_223:
  52880 			v23 = v4 * int32(13320) >> int32(8)
  52881 			goto _225
  52882 		_225:
  52883 			v25 = v19 - v21 - v23 + int32(8708)
  52884 			if v25 & ^int32(YUV_MASK2) == 0 {
  52885 				v28 = v25 >> int32(YUV_FIX2)
  52886 			} else {
  52887 				if v25 < 0 {
  52888 					v29 = 0
  52889 				} else {
  52890 					v29 = int32(255)
  52891 				}
  52892 				v28 = v29
  52893 			}
  52894 			v26 = v28
  52895 			goto _228
  52896 		_228:
  52897 			v17 = v26
  52898 			goto _219
  52899 		_219:
  52900 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52901 			v32 = v2 * int32(19077) >> int32(8)
  52902 			goto _234
  52903 		_234:
  52904 			v34 = v3 * int32(33050) >> int32(8)
  52905 			goto _236
  52906 		_236:
  52907 			v36 = v32 + v34 - int32(17685)
  52908 			if v36 & ^int32(YUV_MASK2) == 0 {
  52909 				v39 = v36 >> int32(YUV_FIX2)
  52910 			} else {
  52911 				if v36 < 0 {
  52912 					v40 = 0
  52913 				} else {
  52914 					v40 = int32(255)
  52915 				}
  52916 				v39 = v40
  52917 			}
  52918 			v37 = v39
  52919 			goto _239
  52920 		_239:
  52921 			v30 = v37
  52922 			goto _232
  52923 		_232:
  52924 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52925 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52926 		}
  52927 		tl_uv = t_uv
  52928 		l_uv = uv
  52929 		goto _81
  52930 	_81:
  52931 		;
  52932 		x = x + 1
  52933 	}
  52934 	if !(len1&libc.Int32FromInt32(1) != 0) {
  52935 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  52936 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  52937 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  52938 		v3 = libc.Int32FromUint8(uint8(uv04 & uint32(0xff)))
  52939 		v4 = libc.Int32FromUint8(uint8(uv04 >> libc.Int32FromInt32(16)))
  52940 		v5 = v1
  52941 		v8 = v2 * int32(19077) >> int32(8)
  52942 		goto _250
  52943 	_250:
  52944 		v10 = v4 * int32(26149) >> int32(8)
  52945 		goto _252
  52946 	_252:
  52947 		v12 = v8 + v10 - int32(14234)
  52948 		if v12 & ^int32(YUV_MASK2) == 0 {
  52949 			v15 = v12 >> int32(YUV_FIX2)
  52950 		} else {
  52951 			if v12 < 0 {
  52952 				v16 = 0
  52953 			} else {
  52954 				v16 = int32(255)
  52955 			}
  52956 			v15 = v16
  52957 		}
  52958 		v13 = v15
  52959 		goto _255
  52960 	_255:
  52961 		v6 = v13
  52962 		goto _248
  52963 	_248:
  52964 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52965 		v19 = v2 * int32(19077) >> int32(8)
  52966 		goto _261
  52967 	_261:
  52968 		v21 = v3 * int32(6419) >> int32(8)
  52969 		goto _263
  52970 	_263:
  52971 		v23 = v4 * int32(13320) >> int32(8)
  52972 		goto _265
  52973 	_265:
  52974 		v25 = v19 - v21 - v23 + int32(8708)
  52975 		if v25 & ^int32(YUV_MASK2) == 0 {
  52976 			v28 = v25 >> int32(YUV_FIX2)
  52977 		} else {
  52978 			if v25 < 0 {
  52979 				v29 = 0
  52980 			} else {
  52981 				v29 = int32(255)
  52982 			}
  52983 			v28 = v29
  52984 		}
  52985 		v26 = v28
  52986 		goto _268
  52987 	_268:
  52988 		v17 = v26
  52989 		goto _259
  52990 	_259:
  52991 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52992 		v32 = v2 * int32(19077) >> int32(8)
  52993 		goto _274
  52994 	_274:
  52995 		v34 = v3 * int32(33050) >> int32(8)
  52996 		goto _276
  52997 	_276:
  52998 		v36 = v32 + v34 - int32(17685)
  52999 		if v36 & ^int32(YUV_MASK2) == 0 {
  53000 			v39 = v36 >> int32(YUV_FIX2)
  53001 		} else {
  53002 			if v36 < 0 {
  53003 				v40 = 0
  53004 			} else {
  53005 				v40 = int32(255)
  53006 			}
  53007 			v39 = v40
  53008 		}
  53009 		v37 = v39
  53010 		goto _279
  53011 	_279:
  53012 		v30 = v37
  53013 		goto _272
  53014 	_272:
  53015 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53016 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53017 		if bottom_y != libc.UintptrFromInt32(0) {
  53018 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53019 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  53020 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  53021 			v3 = libc.Int32FromUint8(uint8(uv05 & uint32(0xff)))
  53022 			v4 = libc.Int32FromUint8(uint8(uv05 >> libc.Int32FromInt32(16)))
  53023 			v5 = v1
  53024 			v8 = v2 * int32(19077) >> int32(8)
  53025 			goto _290
  53026 		_290:
  53027 			v10 = v4 * int32(26149) >> int32(8)
  53028 			goto _292
  53029 		_292:
  53030 			v12 = v8 + v10 - int32(14234)
  53031 			if v12 & ^int32(YUV_MASK2) == 0 {
  53032 				v15 = v12 >> int32(YUV_FIX2)
  53033 			} else {
  53034 				if v12 < 0 {
  53035 					v16 = 0
  53036 				} else {
  53037 					v16 = int32(255)
  53038 				}
  53039 				v15 = v16
  53040 			}
  53041 			v13 = v15
  53042 			goto _295
  53043 		_295:
  53044 			v6 = v13
  53045 			goto _288
  53046 		_288:
  53047 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53048 			v19 = v2 * int32(19077) >> int32(8)
  53049 			goto _301
  53050 		_301:
  53051 			v21 = v3 * int32(6419) >> int32(8)
  53052 			goto _303
  53053 		_303:
  53054 			v23 = v4 * int32(13320) >> int32(8)
  53055 			goto _305
  53056 		_305:
  53057 			v25 = v19 - v21 - v23 + int32(8708)
  53058 			if v25 & ^int32(YUV_MASK2) == 0 {
  53059 				v28 = v25 >> int32(YUV_FIX2)
  53060 			} else {
  53061 				if v25 < 0 {
  53062 					v29 = 0
  53063 				} else {
  53064 					v29 = int32(255)
  53065 				}
  53066 				v28 = v29
  53067 			}
  53068 			v26 = v28
  53069 			goto _308
  53070 		_308:
  53071 			v17 = v26
  53072 			goto _299
  53073 		_299:
  53074 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53075 			v32 = v2 * int32(19077) >> int32(8)
  53076 			goto _314
  53077 		_314:
  53078 			v34 = v3 * int32(33050) >> int32(8)
  53079 			goto _316
  53080 		_316:
  53081 			v36 = v32 + v34 - int32(17685)
  53082 			if v36 & ^int32(YUV_MASK2) == 0 {
  53083 				v39 = v36 >> int32(YUV_FIX2)
  53084 			} else {
  53085 				if v36 < 0 {
  53086 					v40 = 0
  53087 				} else {
  53088 					v40 = int32(255)
  53089 				}
  53090 				v39 = v40
  53091 			}
  53092 			v37 = v39
  53093 			goto _319
  53094 		_319:
  53095 			v30 = v37
  53096 			goto _312
  53097 		_312:
  53098 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53099 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53100 		}
  53101 	}
  53102 }
  53103 
  53104 func UpsampleBgraLinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  53105 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  53106 	var last_pixel_pair, x, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  53107 	var v1, v5 uintptr
  53108 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, diag_03, diag_12, l_uv, last_pixel_pair, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v5, v6, v8
  53109 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  53110 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  53111 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  53112 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53113 	v1 = top_dst
  53114 	v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  53115 	v3 = libc.Int32FromUint8(uint8(uv0 & uint32(0xff)))
  53116 	v4 = libc.Int32FromUint8(uint8(uv0 >> libc.Int32FromInt32(16)))
  53117 	v5 = v1
  53118 	v8 = v2 * int32(19077) >> int32(8)
  53119 	goto _9
  53120 _9:
  53121 	v10 = v3 * int32(33050) >> int32(8)
  53122 	goto _11
  53123 _11:
  53124 	v12 = v8 + v10 - int32(17685)
  53125 	if v12 & ^int32(YUV_MASK2) == 0 {
  53126 		v15 = v12 >> int32(YUV_FIX2)
  53127 	} else {
  53128 		if v12 < 0 {
  53129 			v16 = 0
  53130 		} else {
  53131 			v16 = int32(255)
  53132 		}
  53133 		v15 = v16
  53134 	}
  53135 	v13 = v15
  53136 	goto _14
  53137 _14:
  53138 	v6 = v13
  53139 	goto _7
  53140 _7:
  53141 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53142 	v19 = v2 * int32(19077) >> int32(8)
  53143 	goto _20
  53144 _20:
  53145 	v21 = v3 * int32(6419) >> int32(8)
  53146 	goto _22
  53147 _22:
  53148 	v23 = v4 * int32(13320) >> int32(8)
  53149 	goto _24
  53150 _24:
  53151 	v25 = v19 - v21 - v23 + int32(8708)
  53152 	if v25 & ^int32(YUV_MASK2) == 0 {
  53153 		v28 = v25 >> int32(YUV_FIX2)
  53154 	} else {
  53155 		if v25 < 0 {
  53156 			v29 = 0
  53157 		} else {
  53158 			v29 = int32(255)
  53159 		}
  53160 		v28 = v29
  53161 	}
  53162 	v26 = v28
  53163 	goto _27
  53164 _27:
  53165 	v17 = v26
  53166 	goto _18
  53167 _18:
  53168 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53169 	v32 = v2 * int32(19077) >> int32(8)
  53170 	goto _33
  53171 _33:
  53172 	v34 = v4 * int32(26149) >> int32(8)
  53173 	goto _35
  53174 _35:
  53175 	v36 = v32 + v34 - int32(14234)
  53176 	if v36 & ^int32(YUV_MASK2) == 0 {
  53177 		v39 = v36 >> int32(YUV_FIX2)
  53178 	} else {
  53179 		if v36 < 0 {
  53180 			v40 = 0
  53181 		} else {
  53182 			v40 = int32(255)
  53183 		}
  53184 		v39 = v40
  53185 	}
  53186 	v37 = v39
  53187 	goto _38
  53188 _38:
  53189 	v30 = v37
  53190 	goto _31
  53191 _31:
  53192 	**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53193 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53194 	if bottom_y != libc.UintptrFromInt32(0) {
  53195 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53196 		v1 = bottom_dst
  53197 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  53198 		v3 = libc.Int32FromUint8(uint8(uv01 & uint32(0xff)))
  53199 		v4 = libc.Int32FromUint8(uint8(uv01 >> libc.Int32FromInt32(16)))
  53200 		v5 = v1
  53201 		v8 = v2 * int32(19077) >> int32(8)
  53202 		goto _49
  53203 	_49:
  53204 		v10 = v3 * int32(33050) >> int32(8)
  53205 		goto _51
  53206 	_51:
  53207 		v12 = v8 + v10 - int32(17685)
  53208 		if v12 & ^int32(YUV_MASK2) == 0 {
  53209 			v15 = v12 >> int32(YUV_FIX2)
  53210 		} else {
  53211 			if v12 < 0 {
  53212 				v16 = 0
  53213 			} else {
  53214 				v16 = int32(255)
  53215 			}
  53216 			v15 = v16
  53217 		}
  53218 		v13 = v15
  53219 		goto _54
  53220 	_54:
  53221 		v6 = v13
  53222 		goto _47
  53223 	_47:
  53224 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53225 		v19 = v2 * int32(19077) >> int32(8)
  53226 		goto _60
  53227 	_60:
  53228 		v21 = v3 * int32(6419) >> int32(8)
  53229 		goto _62
  53230 	_62:
  53231 		v23 = v4 * int32(13320) >> int32(8)
  53232 		goto _64
  53233 	_64:
  53234 		v25 = v19 - v21 - v23 + int32(8708)
  53235 		if v25 & ^int32(YUV_MASK2) == 0 {
  53236 			v28 = v25 >> int32(YUV_FIX2)
  53237 		} else {
  53238 			if v25 < 0 {
  53239 				v29 = 0
  53240 			} else {
  53241 				v29 = int32(255)
  53242 			}
  53243 			v28 = v29
  53244 		}
  53245 		v26 = v28
  53246 		goto _67
  53247 	_67:
  53248 		v17 = v26
  53249 		goto _58
  53250 	_58:
  53251 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53252 		v32 = v2 * int32(19077) >> int32(8)
  53253 		goto _73
  53254 	_73:
  53255 		v34 = v4 * int32(26149) >> int32(8)
  53256 		goto _75
  53257 	_75:
  53258 		v36 = v32 + v34 - int32(14234)
  53259 		if v36 & ^int32(YUV_MASK2) == 0 {
  53260 			v39 = v36 >> int32(YUV_FIX2)
  53261 		} else {
  53262 			if v36 < 0 {
  53263 				v40 = 0
  53264 			} else {
  53265 				v40 = int32(255)
  53266 			}
  53267 			v39 = v40
  53268 		}
  53269 		v37 = v39
  53270 		goto _78
  53271 	_78:
  53272 		v30 = v37
  53273 		goto _71
  53274 	_71:
  53275 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53276 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53277 	}
  53278 	x = int32(1)
  53279 	for {
  53280 		if !(x <= last_pixel_pair) {
  53281 			break
  53282 		}
  53283 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  53284 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  53285 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  53286 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  53287 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  53288 		uv02 = (diag_12 + tl_uv) >> int32(1)
  53289 		uv1 = (diag_03 + t_uv) >> int32(1)
  53290 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53291 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  53292 		v3 = libc.Int32FromUint8(uint8(uv02 & uint32(0xff)))
  53293 		v4 = libc.Int32FromUint8(uint8(uv02 >> libc.Int32FromInt32(16)))
  53294 		v5 = v1
  53295 		v8 = v2 * int32(19077) >> int32(8)
  53296 		goto _90
  53297 	_90:
  53298 		v10 = v3 * int32(33050) >> int32(8)
  53299 		goto _92
  53300 	_92:
  53301 		v12 = v8 + v10 - int32(17685)
  53302 		if v12 & ^int32(YUV_MASK2) == 0 {
  53303 			v15 = v12 >> int32(YUV_FIX2)
  53304 		} else {
  53305 			if v12 < 0 {
  53306 				v16 = 0
  53307 			} else {
  53308 				v16 = int32(255)
  53309 			}
  53310 			v15 = v16
  53311 		}
  53312 		v13 = v15
  53313 		goto _95
  53314 	_95:
  53315 		v6 = v13
  53316 		goto _88
  53317 	_88:
  53318 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53319 		v19 = v2 * int32(19077) >> int32(8)
  53320 		goto _101
  53321 	_101:
  53322 		v21 = v3 * int32(6419) >> int32(8)
  53323 		goto _103
  53324 	_103:
  53325 		v23 = v4 * int32(13320) >> int32(8)
  53326 		goto _105
  53327 	_105:
  53328 		v25 = v19 - v21 - v23 + int32(8708)
  53329 		if v25 & ^int32(YUV_MASK2) == 0 {
  53330 			v28 = v25 >> int32(YUV_FIX2)
  53331 		} else {
  53332 			if v25 < 0 {
  53333 				v29 = 0
  53334 			} else {
  53335 				v29 = int32(255)
  53336 			}
  53337 			v28 = v29
  53338 		}
  53339 		v26 = v28
  53340 		goto _108
  53341 	_108:
  53342 		v17 = v26
  53343 		goto _99
  53344 	_99:
  53345 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53346 		v32 = v2 * int32(19077) >> int32(8)
  53347 		goto _114
  53348 	_114:
  53349 		v34 = v4 * int32(26149) >> int32(8)
  53350 		goto _116
  53351 	_116:
  53352 		v36 = v32 + v34 - int32(14234)
  53353 		if v36 & ^int32(YUV_MASK2) == 0 {
  53354 			v39 = v36 >> int32(YUV_FIX2)
  53355 		} else {
  53356 			if v36 < 0 {
  53357 				v40 = 0
  53358 			} else {
  53359 				v40 = int32(255)
  53360 			}
  53361 			v39 = v40
  53362 		}
  53363 		v37 = v39
  53364 		goto _119
  53365 	_119:
  53366 		v30 = v37
  53367 		goto _112
  53368 	_112:
  53369 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53370 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53371 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  53372 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  53373 		v3 = libc.Int32FromUint8(uint8(uv1 & uint32(0xff)))
  53374 		v4 = libc.Int32FromUint8(uint8(uv1 >> libc.Int32FromInt32(16)))
  53375 		v5 = v1
  53376 		v8 = v2 * int32(19077) >> int32(8)
  53377 		goto _130
  53378 	_130:
  53379 		v10 = v3 * int32(33050) >> int32(8)
  53380 		goto _132
  53381 	_132:
  53382 		v12 = v8 + v10 - int32(17685)
  53383 		if v12 & ^int32(YUV_MASK2) == 0 {
  53384 			v15 = v12 >> int32(YUV_FIX2)
  53385 		} else {
  53386 			if v12 < 0 {
  53387 				v16 = 0
  53388 			} else {
  53389 				v16 = int32(255)
  53390 			}
  53391 			v15 = v16
  53392 		}
  53393 		v13 = v15
  53394 		goto _135
  53395 	_135:
  53396 		v6 = v13
  53397 		goto _128
  53398 	_128:
  53399 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53400 		v19 = v2 * int32(19077) >> int32(8)
  53401 		goto _141
  53402 	_141:
  53403 		v21 = v3 * int32(6419) >> int32(8)
  53404 		goto _143
  53405 	_143:
  53406 		v23 = v4 * int32(13320) >> int32(8)
  53407 		goto _145
  53408 	_145:
  53409 		v25 = v19 - v21 - v23 + int32(8708)
  53410 		if v25 & ^int32(YUV_MASK2) == 0 {
  53411 			v28 = v25 >> int32(YUV_FIX2)
  53412 		} else {
  53413 			if v25 < 0 {
  53414 				v29 = 0
  53415 			} else {
  53416 				v29 = int32(255)
  53417 			}
  53418 			v28 = v29
  53419 		}
  53420 		v26 = v28
  53421 		goto _148
  53422 	_148:
  53423 		v17 = v26
  53424 		goto _139
  53425 	_139:
  53426 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53427 		v32 = v2 * int32(19077) >> int32(8)
  53428 		goto _154
  53429 	_154:
  53430 		v34 = v4 * int32(26149) >> int32(8)
  53431 		goto _156
  53432 	_156:
  53433 		v36 = v32 + v34 - int32(14234)
  53434 		if v36 & ^int32(YUV_MASK2) == 0 {
  53435 			v39 = v36 >> int32(YUV_FIX2)
  53436 		} else {
  53437 			if v36 < 0 {
  53438 				v40 = 0
  53439 			} else {
  53440 				v40 = int32(255)
  53441 			}
  53442 			v39 = v40
  53443 		}
  53444 		v37 = v39
  53445 		goto _159
  53446 	_159:
  53447 		v30 = v37
  53448 		goto _152
  53449 	_152:
  53450 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53451 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53452 		if bottom_y != libc.UintptrFromInt32(0) {
  53453 			uv03 = (diag_03 + l_uv) >> int32(1)
  53454 			uv11 = (diag_12 + uv) >> int32(1)
  53455 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53456 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  53457 			v3 = libc.Int32FromUint8(uint8(uv03 & uint32(0xff)))
  53458 			v4 = libc.Int32FromUint8(uint8(uv03 >> libc.Int32FromInt32(16)))
  53459 			v5 = v1
  53460 			v8 = v2 * int32(19077) >> int32(8)
  53461 			goto _170
  53462 		_170:
  53463 			v10 = v3 * int32(33050) >> int32(8)
  53464 			goto _172
  53465 		_172:
  53466 			v12 = v8 + v10 - int32(17685)
  53467 			if v12 & ^int32(YUV_MASK2) == 0 {
  53468 				v15 = v12 >> int32(YUV_FIX2)
  53469 			} else {
  53470 				if v12 < 0 {
  53471 					v16 = 0
  53472 				} else {
  53473 					v16 = int32(255)
  53474 				}
  53475 				v15 = v16
  53476 			}
  53477 			v13 = v15
  53478 			goto _175
  53479 		_175:
  53480 			v6 = v13
  53481 			goto _168
  53482 		_168:
  53483 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53484 			v19 = v2 * int32(19077) >> int32(8)
  53485 			goto _181
  53486 		_181:
  53487 			v21 = v3 * int32(6419) >> int32(8)
  53488 			goto _183
  53489 		_183:
  53490 			v23 = v4 * int32(13320) >> int32(8)
  53491 			goto _185
  53492 		_185:
  53493 			v25 = v19 - v21 - v23 + int32(8708)
  53494 			if v25 & ^int32(YUV_MASK2) == 0 {
  53495 				v28 = v25 >> int32(YUV_FIX2)
  53496 			} else {
  53497 				if v25 < 0 {
  53498 					v29 = 0
  53499 				} else {
  53500 					v29 = int32(255)
  53501 				}
  53502 				v28 = v29
  53503 			}
  53504 			v26 = v28
  53505 			goto _188
  53506 		_188:
  53507 			v17 = v26
  53508 			goto _179
  53509 		_179:
  53510 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53511 			v32 = v2 * int32(19077) >> int32(8)
  53512 			goto _194
  53513 		_194:
  53514 			v34 = v4 * int32(26149) >> int32(8)
  53515 			goto _196
  53516 		_196:
  53517 			v36 = v32 + v34 - int32(14234)
  53518 			if v36 & ^int32(YUV_MASK2) == 0 {
  53519 				v39 = v36 >> int32(YUV_FIX2)
  53520 			} else {
  53521 				if v36 < 0 {
  53522 					v40 = 0
  53523 				} else {
  53524 					v40 = int32(255)
  53525 				}
  53526 				v39 = v40
  53527 			}
  53528 			v37 = v39
  53529 			goto _199
  53530 		_199:
  53531 			v30 = v37
  53532 			goto _192
  53533 		_192:
  53534 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53535 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53536 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53537 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53538 			v3 = libc.Int32FromUint8(uint8(uv11 & uint32(0xff)))
  53539 			v4 = libc.Int32FromUint8(uint8(uv11 >> libc.Int32FromInt32(16)))
  53540 			v5 = v1
  53541 			v8 = v2 * int32(19077) >> int32(8)
  53542 			goto _210
  53543 		_210:
  53544 			v10 = v3 * int32(33050) >> int32(8)
  53545 			goto _212
  53546 		_212:
  53547 			v12 = v8 + v10 - int32(17685)
  53548 			if v12 & ^int32(YUV_MASK2) == 0 {
  53549 				v15 = v12 >> int32(YUV_FIX2)
  53550 			} else {
  53551 				if v12 < 0 {
  53552 					v16 = 0
  53553 				} else {
  53554 					v16 = int32(255)
  53555 				}
  53556 				v15 = v16
  53557 			}
  53558 			v13 = v15
  53559 			goto _215
  53560 		_215:
  53561 			v6 = v13
  53562 			goto _208
  53563 		_208:
  53564 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53565 			v19 = v2 * int32(19077) >> int32(8)
  53566 			goto _221
  53567 		_221:
  53568 			v21 = v3 * int32(6419) >> int32(8)
  53569 			goto _223
  53570 		_223:
  53571 			v23 = v4 * int32(13320) >> int32(8)
  53572 			goto _225
  53573 		_225:
  53574 			v25 = v19 - v21 - v23 + int32(8708)
  53575 			if v25 & ^int32(YUV_MASK2) == 0 {
  53576 				v28 = v25 >> int32(YUV_FIX2)
  53577 			} else {
  53578 				if v25 < 0 {
  53579 					v29 = 0
  53580 				} else {
  53581 					v29 = int32(255)
  53582 				}
  53583 				v28 = v29
  53584 			}
  53585 			v26 = v28
  53586 			goto _228
  53587 		_228:
  53588 			v17 = v26
  53589 			goto _219
  53590 		_219:
  53591 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53592 			v32 = v2 * int32(19077) >> int32(8)
  53593 			goto _234
  53594 		_234:
  53595 			v34 = v4 * int32(26149) >> int32(8)
  53596 			goto _236
  53597 		_236:
  53598 			v36 = v32 + v34 - int32(14234)
  53599 			if v36 & ^int32(YUV_MASK2) == 0 {
  53600 				v39 = v36 >> int32(YUV_FIX2)
  53601 			} else {
  53602 				if v36 < 0 {
  53603 					v40 = 0
  53604 				} else {
  53605 					v40 = int32(255)
  53606 				}
  53607 				v39 = v40
  53608 			}
  53609 			v37 = v39
  53610 			goto _239
  53611 		_239:
  53612 			v30 = v37
  53613 			goto _232
  53614 		_232:
  53615 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53616 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53617 		}
  53618 		tl_uv = t_uv
  53619 		l_uv = uv
  53620 		goto _81
  53621 	_81:
  53622 		;
  53623 		x = x + 1
  53624 	}
  53625 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53626 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53627 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53628 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53629 		v3 = libc.Int32FromUint8(uint8(uv04 & uint32(0xff)))
  53630 		v4 = libc.Int32FromUint8(uint8(uv04 >> libc.Int32FromInt32(16)))
  53631 		v5 = v1
  53632 		v8 = v2 * int32(19077) >> int32(8)
  53633 		goto _250
  53634 	_250:
  53635 		v10 = v3 * int32(33050) >> int32(8)
  53636 		goto _252
  53637 	_252:
  53638 		v12 = v8 + v10 - int32(17685)
  53639 		if v12 & ^int32(YUV_MASK2) == 0 {
  53640 			v15 = v12 >> int32(YUV_FIX2)
  53641 		} else {
  53642 			if v12 < 0 {
  53643 				v16 = 0
  53644 			} else {
  53645 				v16 = int32(255)
  53646 			}
  53647 			v15 = v16
  53648 		}
  53649 		v13 = v15
  53650 		goto _255
  53651 	_255:
  53652 		v6 = v13
  53653 		goto _248
  53654 	_248:
  53655 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53656 		v19 = v2 * int32(19077) >> int32(8)
  53657 		goto _261
  53658 	_261:
  53659 		v21 = v3 * int32(6419) >> int32(8)
  53660 		goto _263
  53661 	_263:
  53662 		v23 = v4 * int32(13320) >> int32(8)
  53663 		goto _265
  53664 	_265:
  53665 		v25 = v19 - v21 - v23 + int32(8708)
  53666 		if v25 & ^int32(YUV_MASK2) == 0 {
  53667 			v28 = v25 >> int32(YUV_FIX2)
  53668 		} else {
  53669 			if v25 < 0 {
  53670 				v29 = 0
  53671 			} else {
  53672 				v29 = int32(255)
  53673 			}
  53674 			v28 = v29
  53675 		}
  53676 		v26 = v28
  53677 		goto _268
  53678 	_268:
  53679 		v17 = v26
  53680 		goto _259
  53681 	_259:
  53682 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53683 		v32 = v2 * int32(19077) >> int32(8)
  53684 		goto _274
  53685 	_274:
  53686 		v34 = v4 * int32(26149) >> int32(8)
  53687 		goto _276
  53688 	_276:
  53689 		v36 = v32 + v34 - int32(14234)
  53690 		if v36 & ^int32(YUV_MASK2) == 0 {
  53691 			v39 = v36 >> int32(YUV_FIX2)
  53692 		} else {
  53693 			if v36 < 0 {
  53694 				v40 = 0
  53695 			} else {
  53696 				v40 = int32(255)
  53697 			}
  53698 			v39 = v40
  53699 		}
  53700 		v37 = v39
  53701 		goto _279
  53702 	_279:
  53703 		v30 = v37
  53704 		goto _272
  53705 	_272:
  53706 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53707 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53708 		if bottom_y != libc.UintptrFromInt32(0) {
  53709 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53710 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  53711 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  53712 			v3 = libc.Int32FromUint8(uint8(uv05 & uint32(0xff)))
  53713 			v4 = libc.Int32FromUint8(uint8(uv05 >> libc.Int32FromInt32(16)))
  53714 			v5 = v1
  53715 			v8 = v2 * int32(19077) >> int32(8)
  53716 			goto _290
  53717 		_290:
  53718 			v10 = v3 * int32(33050) >> int32(8)
  53719 			goto _292
  53720 		_292:
  53721 			v12 = v8 + v10 - int32(17685)
  53722 			if v12 & ^int32(YUV_MASK2) == 0 {
  53723 				v15 = v12 >> int32(YUV_FIX2)
  53724 			} else {
  53725 				if v12 < 0 {
  53726 					v16 = 0
  53727 				} else {
  53728 					v16 = int32(255)
  53729 				}
  53730 				v15 = v16
  53731 			}
  53732 			v13 = v15
  53733 			goto _295
  53734 		_295:
  53735 			v6 = v13
  53736 			goto _288
  53737 		_288:
  53738 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53739 			v19 = v2 * int32(19077) >> int32(8)
  53740 			goto _301
  53741 		_301:
  53742 			v21 = v3 * int32(6419) >> int32(8)
  53743 			goto _303
  53744 		_303:
  53745 			v23 = v4 * int32(13320) >> int32(8)
  53746 			goto _305
  53747 		_305:
  53748 			v25 = v19 - v21 - v23 + int32(8708)
  53749 			if v25 & ^int32(YUV_MASK2) == 0 {
  53750 				v28 = v25 >> int32(YUV_FIX2)
  53751 			} else {
  53752 				if v25 < 0 {
  53753 					v29 = 0
  53754 				} else {
  53755 					v29 = int32(255)
  53756 				}
  53757 				v28 = v29
  53758 			}
  53759 			v26 = v28
  53760 			goto _308
  53761 		_308:
  53762 			v17 = v26
  53763 			goto _299
  53764 		_299:
  53765 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53766 			v32 = v2 * int32(19077) >> int32(8)
  53767 			goto _314
  53768 		_314:
  53769 			v34 = v4 * int32(26149) >> int32(8)
  53770 			goto _316
  53771 		_316:
  53772 			v36 = v32 + v34 - int32(14234)
  53773 			if v36 & ^int32(YUV_MASK2) == 0 {
  53774 				v39 = v36 >> int32(YUV_FIX2)
  53775 			} else {
  53776 				if v36 < 0 {
  53777 					v40 = 0
  53778 				} else {
  53779 					v40 = int32(255)
  53780 				}
  53781 				v39 = v40
  53782 			}
  53783 			v37 = v39
  53784 			goto _319
  53785 		_319:
  53786 			v30 = v37
  53787 			goto _312
  53788 		_312:
  53789 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53790 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53791 		}
  53792 	}
  53793 }
  53794 
  53795 func UpsampleArgbLinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  53796 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  53797 	var last_pixel_pair, x, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  53798 	var v1, v5 uintptr
  53799 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, diag_03, diag_12, l_uv, last_pixel_pair, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v5, v6, v8
  53800 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  53801 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  53802 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  53803 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53804 	v1 = top_dst
  53805 	**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  53806 	v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  53807 	v3 = libc.Int32FromUint8(uint8(uv0 & uint32(0xff)))
  53808 	v4 = libc.Int32FromUint8(uint8(uv0 >> libc.Int32FromInt32(16)))
  53809 	v5 = v1 + uintptr(1)
  53810 	v8 = v2 * int32(19077) >> int32(8)
  53811 	goto _9
  53812 _9:
  53813 	v10 = v4 * int32(26149) >> int32(8)
  53814 	goto _11
  53815 _11:
  53816 	v12 = v8 + v10 - int32(14234)
  53817 	if v12 & ^int32(YUV_MASK2) == 0 {
  53818 		v15 = v12 >> int32(YUV_FIX2)
  53819 	} else {
  53820 		if v12 < 0 {
  53821 			v16 = 0
  53822 		} else {
  53823 			v16 = int32(255)
  53824 		}
  53825 		v15 = v16
  53826 	}
  53827 	v13 = v15
  53828 	goto _14
  53829 _14:
  53830 	v6 = v13
  53831 	goto _7
  53832 _7:
  53833 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53834 	v19 = v2 * int32(19077) >> int32(8)
  53835 	goto _20
  53836 _20:
  53837 	v21 = v3 * int32(6419) >> int32(8)
  53838 	goto _22
  53839 _22:
  53840 	v23 = v4 * int32(13320) >> int32(8)
  53841 	goto _24
  53842 _24:
  53843 	v25 = v19 - v21 - v23 + int32(8708)
  53844 	if v25 & ^int32(YUV_MASK2) == 0 {
  53845 		v28 = v25 >> int32(YUV_FIX2)
  53846 	} else {
  53847 		if v25 < 0 {
  53848 			v29 = 0
  53849 		} else {
  53850 			v29 = int32(255)
  53851 		}
  53852 		v28 = v29
  53853 	}
  53854 	v26 = v28
  53855 	goto _27
  53856 _27:
  53857 	v17 = v26
  53858 	goto _18
  53859 _18:
  53860 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53861 	v32 = v2 * int32(19077) >> int32(8)
  53862 	goto _33
  53863 _33:
  53864 	v34 = v3 * int32(33050) >> int32(8)
  53865 	goto _35
  53866 _35:
  53867 	v36 = v32 + v34 - int32(17685)
  53868 	if v36 & ^int32(YUV_MASK2) == 0 {
  53869 		v39 = v36 >> int32(YUV_FIX2)
  53870 	} else {
  53871 		if v36 < 0 {
  53872 			v40 = 0
  53873 		} else {
  53874 			v40 = int32(255)
  53875 		}
  53876 		v39 = v40
  53877 	}
  53878 	v37 = v39
  53879 	goto _38
  53880 _38:
  53881 	v30 = v37
  53882 	goto _31
  53883 _31:
  53884 	**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53885 	if bottom_y != libc.UintptrFromInt32(0) {
  53886 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53887 		v1 = bottom_dst
  53888 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  53889 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  53890 		v3 = libc.Int32FromUint8(uint8(uv01 & uint32(0xff)))
  53891 		v4 = libc.Int32FromUint8(uint8(uv01 >> libc.Int32FromInt32(16)))
  53892 		v5 = v1 + uintptr(1)
  53893 		v8 = v2 * int32(19077) >> int32(8)
  53894 		goto _49
  53895 	_49:
  53896 		v10 = v4 * int32(26149) >> int32(8)
  53897 		goto _51
  53898 	_51:
  53899 		v12 = v8 + v10 - int32(14234)
  53900 		if v12 & ^int32(YUV_MASK2) == 0 {
  53901 			v15 = v12 >> int32(YUV_FIX2)
  53902 		} else {
  53903 			if v12 < 0 {
  53904 				v16 = 0
  53905 			} else {
  53906 				v16 = int32(255)
  53907 			}
  53908 			v15 = v16
  53909 		}
  53910 		v13 = v15
  53911 		goto _54
  53912 	_54:
  53913 		v6 = v13
  53914 		goto _47
  53915 	_47:
  53916 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53917 		v19 = v2 * int32(19077) >> int32(8)
  53918 		goto _60
  53919 	_60:
  53920 		v21 = v3 * int32(6419) >> int32(8)
  53921 		goto _62
  53922 	_62:
  53923 		v23 = v4 * int32(13320) >> int32(8)
  53924 		goto _64
  53925 	_64:
  53926 		v25 = v19 - v21 - v23 + int32(8708)
  53927 		if v25 & ^int32(YUV_MASK2) == 0 {
  53928 			v28 = v25 >> int32(YUV_FIX2)
  53929 		} else {
  53930 			if v25 < 0 {
  53931 				v29 = 0
  53932 			} else {
  53933 				v29 = int32(255)
  53934 			}
  53935 			v28 = v29
  53936 		}
  53937 		v26 = v28
  53938 		goto _67
  53939 	_67:
  53940 		v17 = v26
  53941 		goto _58
  53942 	_58:
  53943 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53944 		v32 = v2 * int32(19077) >> int32(8)
  53945 		goto _73
  53946 	_73:
  53947 		v34 = v3 * int32(33050) >> int32(8)
  53948 		goto _75
  53949 	_75:
  53950 		v36 = v32 + v34 - int32(17685)
  53951 		if v36 & ^int32(YUV_MASK2) == 0 {
  53952 			v39 = v36 >> int32(YUV_FIX2)
  53953 		} else {
  53954 			if v36 < 0 {
  53955 				v40 = 0
  53956 			} else {
  53957 				v40 = int32(255)
  53958 			}
  53959 			v39 = v40
  53960 		}
  53961 		v37 = v39
  53962 		goto _78
  53963 	_78:
  53964 		v30 = v37
  53965 		goto _71
  53966 	_71:
  53967 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53968 	}
  53969 	x = int32(1)
  53970 	for {
  53971 		if !(x <= last_pixel_pair) {
  53972 			break
  53973 		}
  53974 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  53975 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  53976 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  53977 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  53978 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  53979 		uv02 = (diag_12 + tl_uv) >> int32(1)
  53980 		uv1 = (diag_03 + t_uv) >> int32(1)
  53981 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53982 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  53983 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  53984 		v3 = libc.Int32FromUint8(uint8(uv02 & uint32(0xff)))
  53985 		v4 = libc.Int32FromUint8(uint8(uv02 >> libc.Int32FromInt32(16)))
  53986 		v5 = v1 + uintptr(1)
  53987 		v8 = v2 * int32(19077) >> int32(8)
  53988 		goto _90
  53989 	_90:
  53990 		v10 = v4 * int32(26149) >> int32(8)
  53991 		goto _92
  53992 	_92:
  53993 		v12 = v8 + v10 - int32(14234)
  53994 		if v12 & ^int32(YUV_MASK2) == 0 {
  53995 			v15 = v12 >> int32(YUV_FIX2)
  53996 		} else {
  53997 			if v12 < 0 {
  53998 				v16 = 0
  53999 			} else {
  54000 				v16 = int32(255)
  54001 			}
  54002 			v15 = v16
  54003 		}
  54004 		v13 = v15
  54005 		goto _95
  54006 	_95:
  54007 		v6 = v13
  54008 		goto _88
  54009 	_88:
  54010 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54011 		v19 = v2 * int32(19077) >> int32(8)
  54012 		goto _101
  54013 	_101:
  54014 		v21 = v3 * int32(6419) >> int32(8)
  54015 		goto _103
  54016 	_103:
  54017 		v23 = v4 * int32(13320) >> int32(8)
  54018 		goto _105
  54019 	_105:
  54020 		v25 = v19 - v21 - v23 + int32(8708)
  54021 		if v25 & ^int32(YUV_MASK2) == 0 {
  54022 			v28 = v25 >> int32(YUV_FIX2)
  54023 		} else {
  54024 			if v25 < 0 {
  54025 				v29 = 0
  54026 			} else {
  54027 				v29 = int32(255)
  54028 			}
  54029 			v28 = v29
  54030 		}
  54031 		v26 = v28
  54032 		goto _108
  54033 	_108:
  54034 		v17 = v26
  54035 		goto _99
  54036 	_99:
  54037 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54038 		v32 = v2 * int32(19077) >> int32(8)
  54039 		goto _114
  54040 	_114:
  54041 		v34 = v3 * int32(33050) >> int32(8)
  54042 		goto _116
  54043 	_116:
  54044 		v36 = v32 + v34 - int32(17685)
  54045 		if v36 & ^int32(YUV_MASK2) == 0 {
  54046 			v39 = v36 >> int32(YUV_FIX2)
  54047 		} else {
  54048 			if v36 < 0 {
  54049 				v40 = 0
  54050 			} else {
  54051 				v40 = int32(255)
  54052 			}
  54053 			v39 = v40
  54054 		}
  54055 		v37 = v39
  54056 		goto _119
  54057 	_119:
  54058 		v30 = v37
  54059 		goto _112
  54060 	_112:
  54061 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54062 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  54063 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54064 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  54065 		v3 = libc.Int32FromUint8(uint8(uv1 & uint32(0xff)))
  54066 		v4 = libc.Int32FromUint8(uint8(uv1 >> libc.Int32FromInt32(16)))
  54067 		v5 = v1 + uintptr(1)
  54068 		v8 = v2 * int32(19077) >> int32(8)
  54069 		goto _130
  54070 	_130:
  54071 		v10 = v4 * int32(26149) >> int32(8)
  54072 		goto _132
  54073 	_132:
  54074 		v12 = v8 + v10 - int32(14234)
  54075 		if v12 & ^int32(YUV_MASK2) == 0 {
  54076 			v15 = v12 >> int32(YUV_FIX2)
  54077 		} else {
  54078 			if v12 < 0 {
  54079 				v16 = 0
  54080 			} else {
  54081 				v16 = int32(255)
  54082 			}
  54083 			v15 = v16
  54084 		}
  54085 		v13 = v15
  54086 		goto _135
  54087 	_135:
  54088 		v6 = v13
  54089 		goto _128
  54090 	_128:
  54091 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54092 		v19 = v2 * int32(19077) >> int32(8)
  54093 		goto _141
  54094 	_141:
  54095 		v21 = v3 * int32(6419) >> int32(8)
  54096 		goto _143
  54097 	_143:
  54098 		v23 = v4 * int32(13320) >> int32(8)
  54099 		goto _145
  54100 	_145:
  54101 		v25 = v19 - v21 - v23 + int32(8708)
  54102 		if v25 & ^int32(YUV_MASK2) == 0 {
  54103 			v28 = v25 >> int32(YUV_FIX2)
  54104 		} else {
  54105 			if v25 < 0 {
  54106 				v29 = 0
  54107 			} else {
  54108 				v29 = int32(255)
  54109 			}
  54110 			v28 = v29
  54111 		}
  54112 		v26 = v28
  54113 		goto _148
  54114 	_148:
  54115 		v17 = v26
  54116 		goto _139
  54117 	_139:
  54118 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54119 		v32 = v2 * int32(19077) >> int32(8)
  54120 		goto _154
  54121 	_154:
  54122 		v34 = v3 * int32(33050) >> int32(8)
  54123 		goto _156
  54124 	_156:
  54125 		v36 = v32 + v34 - int32(17685)
  54126 		if v36 & ^int32(YUV_MASK2) == 0 {
  54127 			v39 = v36 >> int32(YUV_FIX2)
  54128 		} else {
  54129 			if v36 < 0 {
  54130 				v40 = 0
  54131 			} else {
  54132 				v40 = int32(255)
  54133 			}
  54134 			v39 = v40
  54135 		}
  54136 		v37 = v39
  54137 		goto _159
  54138 	_159:
  54139 		v30 = v37
  54140 		goto _152
  54141 	_152:
  54142 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54143 		if bottom_y != libc.UintptrFromInt32(0) {
  54144 			uv03 = (diag_03 + l_uv) >> int32(1)
  54145 			uv11 = (diag_12 + uv) >> int32(1)
  54146 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54147 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54148 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  54149 			v3 = libc.Int32FromUint8(uint8(uv03 & uint32(0xff)))
  54150 			v4 = libc.Int32FromUint8(uint8(uv03 >> libc.Int32FromInt32(16)))
  54151 			v5 = v1 + uintptr(1)
  54152 			v8 = v2 * int32(19077) >> int32(8)
  54153 			goto _170
  54154 		_170:
  54155 			v10 = v4 * int32(26149) >> int32(8)
  54156 			goto _172
  54157 		_172:
  54158 			v12 = v8 + v10 - int32(14234)
  54159 			if v12 & ^int32(YUV_MASK2) == 0 {
  54160 				v15 = v12 >> int32(YUV_FIX2)
  54161 			} else {
  54162 				if v12 < 0 {
  54163 					v16 = 0
  54164 				} else {
  54165 					v16 = int32(255)
  54166 				}
  54167 				v15 = v16
  54168 			}
  54169 			v13 = v15
  54170 			goto _175
  54171 		_175:
  54172 			v6 = v13
  54173 			goto _168
  54174 		_168:
  54175 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54176 			v19 = v2 * int32(19077) >> int32(8)
  54177 			goto _181
  54178 		_181:
  54179 			v21 = v3 * int32(6419) >> int32(8)
  54180 			goto _183
  54181 		_183:
  54182 			v23 = v4 * int32(13320) >> int32(8)
  54183 			goto _185
  54184 		_185:
  54185 			v25 = v19 - v21 - v23 + int32(8708)
  54186 			if v25 & ^int32(YUV_MASK2) == 0 {
  54187 				v28 = v25 >> int32(YUV_FIX2)
  54188 			} else {
  54189 				if v25 < 0 {
  54190 					v29 = 0
  54191 				} else {
  54192 					v29 = int32(255)
  54193 				}
  54194 				v28 = v29
  54195 			}
  54196 			v26 = v28
  54197 			goto _188
  54198 		_188:
  54199 			v17 = v26
  54200 			goto _179
  54201 		_179:
  54202 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54203 			v32 = v2 * int32(19077) >> int32(8)
  54204 			goto _194
  54205 		_194:
  54206 			v34 = v3 * int32(33050) >> int32(8)
  54207 			goto _196
  54208 		_196:
  54209 			v36 = v32 + v34 - int32(17685)
  54210 			if v36 & ^int32(YUV_MASK2) == 0 {
  54211 				v39 = v36 >> int32(YUV_FIX2)
  54212 			} else {
  54213 				if v36 < 0 {
  54214 					v40 = 0
  54215 				} else {
  54216 					v40 = int32(255)
  54217 				}
  54218 				v39 = v40
  54219 			}
  54220 			v37 = v39
  54221 			goto _199
  54222 		_199:
  54223 			v30 = v37
  54224 			goto _192
  54225 		_192:
  54226 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54227 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  54228 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54229 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  54230 			v3 = libc.Int32FromUint8(uint8(uv11 & uint32(0xff)))
  54231 			v4 = libc.Int32FromUint8(uint8(uv11 >> libc.Int32FromInt32(16)))
  54232 			v5 = v1 + uintptr(1)
  54233 			v8 = v2 * int32(19077) >> int32(8)
  54234 			goto _210
  54235 		_210:
  54236 			v10 = v4 * int32(26149) >> int32(8)
  54237 			goto _212
  54238 		_212:
  54239 			v12 = v8 + v10 - int32(14234)
  54240 			if v12 & ^int32(YUV_MASK2) == 0 {
  54241 				v15 = v12 >> int32(YUV_FIX2)
  54242 			} else {
  54243 				if v12 < 0 {
  54244 					v16 = 0
  54245 				} else {
  54246 					v16 = int32(255)
  54247 				}
  54248 				v15 = v16
  54249 			}
  54250 			v13 = v15
  54251 			goto _215
  54252 		_215:
  54253 			v6 = v13
  54254 			goto _208
  54255 		_208:
  54256 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54257 			v19 = v2 * int32(19077) >> int32(8)
  54258 			goto _221
  54259 		_221:
  54260 			v21 = v3 * int32(6419) >> int32(8)
  54261 			goto _223
  54262 		_223:
  54263 			v23 = v4 * int32(13320) >> int32(8)
  54264 			goto _225
  54265 		_225:
  54266 			v25 = v19 - v21 - v23 + int32(8708)
  54267 			if v25 & ^int32(YUV_MASK2) == 0 {
  54268 				v28 = v25 >> int32(YUV_FIX2)
  54269 			} else {
  54270 				if v25 < 0 {
  54271 					v29 = 0
  54272 				} else {
  54273 					v29 = int32(255)
  54274 				}
  54275 				v28 = v29
  54276 			}
  54277 			v26 = v28
  54278 			goto _228
  54279 		_228:
  54280 			v17 = v26
  54281 			goto _219
  54282 		_219:
  54283 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54284 			v32 = v2 * int32(19077) >> int32(8)
  54285 			goto _234
  54286 		_234:
  54287 			v34 = v3 * int32(33050) >> int32(8)
  54288 			goto _236
  54289 		_236:
  54290 			v36 = v32 + v34 - int32(17685)
  54291 			if v36 & ^int32(YUV_MASK2) == 0 {
  54292 				v39 = v36 >> int32(YUV_FIX2)
  54293 			} else {
  54294 				if v36 < 0 {
  54295 					v40 = 0
  54296 				} else {
  54297 					v40 = int32(255)
  54298 				}
  54299 				v39 = v40
  54300 			}
  54301 			v37 = v39
  54302 			goto _239
  54303 		_239:
  54304 			v30 = v37
  54305 			goto _232
  54306 		_232:
  54307 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54308 		}
  54309 		tl_uv = t_uv
  54310 		l_uv = uv
  54311 		goto _81
  54312 	_81:
  54313 		;
  54314 		x = x + 1
  54315 	}
  54316 	if !(len1&libc.Int32FromInt32(1) != 0) {
  54317 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54318 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  54319 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54320 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  54321 		v3 = libc.Int32FromUint8(uint8(uv04 & uint32(0xff)))
  54322 		v4 = libc.Int32FromUint8(uint8(uv04 >> libc.Int32FromInt32(16)))
  54323 		v5 = v1 + uintptr(1)
  54324 		v8 = v2 * int32(19077) >> int32(8)
  54325 		goto _250
  54326 	_250:
  54327 		v10 = v4 * int32(26149) >> int32(8)
  54328 		goto _252
  54329 	_252:
  54330 		v12 = v8 + v10 - int32(14234)
  54331 		if v12 & ^int32(YUV_MASK2) == 0 {
  54332 			v15 = v12 >> int32(YUV_FIX2)
  54333 		} else {
  54334 			if v12 < 0 {
  54335 				v16 = 0
  54336 			} else {
  54337 				v16 = int32(255)
  54338 			}
  54339 			v15 = v16
  54340 		}
  54341 		v13 = v15
  54342 		goto _255
  54343 	_255:
  54344 		v6 = v13
  54345 		goto _248
  54346 	_248:
  54347 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54348 		v19 = v2 * int32(19077) >> int32(8)
  54349 		goto _261
  54350 	_261:
  54351 		v21 = v3 * int32(6419) >> int32(8)
  54352 		goto _263
  54353 	_263:
  54354 		v23 = v4 * int32(13320) >> int32(8)
  54355 		goto _265
  54356 	_265:
  54357 		v25 = v19 - v21 - v23 + int32(8708)
  54358 		if v25 & ^int32(YUV_MASK2) == 0 {
  54359 			v28 = v25 >> int32(YUV_FIX2)
  54360 		} else {
  54361 			if v25 < 0 {
  54362 				v29 = 0
  54363 			} else {
  54364 				v29 = int32(255)
  54365 			}
  54366 			v28 = v29
  54367 		}
  54368 		v26 = v28
  54369 		goto _268
  54370 	_268:
  54371 		v17 = v26
  54372 		goto _259
  54373 	_259:
  54374 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54375 		v32 = v2 * int32(19077) >> int32(8)
  54376 		goto _274
  54377 	_274:
  54378 		v34 = v3 * int32(33050) >> int32(8)
  54379 		goto _276
  54380 	_276:
  54381 		v36 = v32 + v34 - int32(17685)
  54382 		if v36 & ^int32(YUV_MASK2) == 0 {
  54383 			v39 = v36 >> int32(YUV_FIX2)
  54384 		} else {
  54385 			if v36 < 0 {
  54386 				v40 = 0
  54387 			} else {
  54388 				v40 = int32(255)
  54389 			}
  54390 			v39 = v40
  54391 		}
  54392 		v37 = v39
  54393 		goto _279
  54394 	_279:
  54395 		v30 = v37
  54396 		goto _272
  54397 	_272:
  54398 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54399 		if bottom_y != libc.UintptrFromInt32(0) {
  54400 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54401 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  54402 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54403 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  54404 			v3 = libc.Int32FromUint8(uint8(uv05 & uint32(0xff)))
  54405 			v4 = libc.Int32FromUint8(uint8(uv05 >> libc.Int32FromInt32(16)))
  54406 			v5 = v1 + uintptr(1)
  54407 			v8 = v2 * int32(19077) >> int32(8)
  54408 			goto _290
  54409 		_290:
  54410 			v10 = v4 * int32(26149) >> int32(8)
  54411 			goto _292
  54412 		_292:
  54413 			v12 = v8 + v10 - int32(14234)
  54414 			if v12 & ^int32(YUV_MASK2) == 0 {
  54415 				v15 = v12 >> int32(YUV_FIX2)
  54416 			} else {
  54417 				if v12 < 0 {
  54418 					v16 = 0
  54419 				} else {
  54420 					v16 = int32(255)
  54421 				}
  54422 				v15 = v16
  54423 			}
  54424 			v13 = v15
  54425 			goto _295
  54426 		_295:
  54427 			v6 = v13
  54428 			goto _288
  54429 		_288:
  54430 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54431 			v19 = v2 * int32(19077) >> int32(8)
  54432 			goto _301
  54433 		_301:
  54434 			v21 = v3 * int32(6419) >> int32(8)
  54435 			goto _303
  54436 		_303:
  54437 			v23 = v4 * int32(13320) >> int32(8)
  54438 			goto _305
  54439 		_305:
  54440 			v25 = v19 - v21 - v23 + int32(8708)
  54441 			if v25 & ^int32(YUV_MASK2) == 0 {
  54442 				v28 = v25 >> int32(YUV_FIX2)
  54443 			} else {
  54444 				if v25 < 0 {
  54445 					v29 = 0
  54446 				} else {
  54447 					v29 = int32(255)
  54448 				}
  54449 				v28 = v29
  54450 			}
  54451 			v26 = v28
  54452 			goto _308
  54453 		_308:
  54454 			v17 = v26
  54455 			goto _299
  54456 		_299:
  54457 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54458 			v32 = v2 * int32(19077) >> int32(8)
  54459 			goto _314
  54460 		_314:
  54461 			v34 = v3 * int32(33050) >> int32(8)
  54462 			goto _316
  54463 		_316:
  54464 			v36 = v32 + v34 - int32(17685)
  54465 			if v36 & ^int32(YUV_MASK2) == 0 {
  54466 				v39 = v36 >> int32(YUV_FIX2)
  54467 			} else {
  54468 				if v36 < 0 {
  54469 					v40 = 0
  54470 				} else {
  54471 					v40 = int32(255)
  54472 				}
  54473 				v39 = v40
  54474 			}
  54475 			v37 = v39
  54476 			goto _319
  54477 		_319:
  54478 			v30 = v37
  54479 			goto _312
  54480 		_312:
  54481 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54482 		}
  54483 	}
  54484 }
  54485 
  54486 func UpsampleRgbLinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  54487 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  54488 	var last_pixel_pair, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v5, v7, v9 int32
  54489 	var v4 uintptr
  54490 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, diag_03, diag_12, l_uv, last_pixel_pair, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v5, v7, v9
  54491 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  54492 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  54493 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  54494 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54495 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  54496 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  54497 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  54498 	v4 = top_dst
  54499 	v7 = v1 * int32(19077) >> int32(8)
  54500 	goto _8
  54501 _8:
  54502 	v9 = v3 * int32(26149) >> int32(8)
  54503 	goto _10
  54504 _10:
  54505 	v11 = v7 + v9 - int32(14234)
  54506 	if v11 & ^int32(YUV_MASK2) == 0 {
  54507 		v14 = v11 >> int32(YUV_FIX2)
  54508 	} else {
  54509 		if v11 < 0 {
  54510 			v15 = 0
  54511 		} else {
  54512 			v15 = int32(255)
  54513 		}
  54514 		v14 = v15
  54515 	}
  54516 	v12 = v14
  54517 	goto _13
  54518 _13:
  54519 	v5 = v12
  54520 	goto _6
  54521 _6:
  54522 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54523 	v18 = v1 * int32(19077) >> int32(8)
  54524 	goto _19
  54525 _19:
  54526 	v20 = v2 * int32(6419) >> int32(8)
  54527 	goto _21
  54528 _21:
  54529 	v22 = v3 * int32(13320) >> int32(8)
  54530 	goto _23
  54531 _23:
  54532 	v24 = v18 - v20 - v22 + int32(8708)
  54533 	if v24 & ^int32(YUV_MASK2) == 0 {
  54534 		v27 = v24 >> int32(YUV_FIX2)
  54535 	} else {
  54536 		if v24 < 0 {
  54537 			v28 = 0
  54538 		} else {
  54539 			v28 = int32(255)
  54540 		}
  54541 		v27 = v28
  54542 	}
  54543 	v25 = v27
  54544 	goto _26
  54545 _26:
  54546 	v16 = v25
  54547 	goto _17
  54548 _17:
  54549 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54550 	v31 = v1 * int32(19077) >> int32(8)
  54551 	goto _32
  54552 _32:
  54553 	v33 = v2 * int32(33050) >> int32(8)
  54554 	goto _34
  54555 _34:
  54556 	v35 = v31 + v33 - int32(17685)
  54557 	if v35 & ^int32(YUV_MASK2) == 0 {
  54558 		v38 = v35 >> int32(YUV_FIX2)
  54559 	} else {
  54560 		if v35 < 0 {
  54561 			v39 = 0
  54562 		} else {
  54563 			v39 = int32(255)
  54564 		}
  54565 		v38 = v39
  54566 	}
  54567 	v36 = v38
  54568 	goto _37
  54569 _37:
  54570 	v29 = v36
  54571 	goto _30
  54572 _30:
  54573 	**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54574 	if bottom_y != libc.UintptrFromInt32(0) {
  54575 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54576 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  54577 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  54578 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  54579 		v4 = bottom_dst
  54580 		v7 = v1 * int32(19077) >> int32(8)
  54581 		goto _47
  54582 	_47:
  54583 		v9 = v3 * int32(26149) >> int32(8)
  54584 		goto _49
  54585 	_49:
  54586 		v11 = v7 + v9 - int32(14234)
  54587 		if v11 & ^int32(YUV_MASK2) == 0 {
  54588 			v14 = v11 >> int32(YUV_FIX2)
  54589 		} else {
  54590 			if v11 < 0 {
  54591 				v15 = 0
  54592 			} else {
  54593 				v15 = int32(255)
  54594 			}
  54595 			v14 = v15
  54596 		}
  54597 		v12 = v14
  54598 		goto _52
  54599 	_52:
  54600 		v5 = v12
  54601 		goto _45
  54602 	_45:
  54603 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54604 		v18 = v1 * int32(19077) >> int32(8)
  54605 		goto _58
  54606 	_58:
  54607 		v20 = v2 * int32(6419) >> int32(8)
  54608 		goto _60
  54609 	_60:
  54610 		v22 = v3 * int32(13320) >> int32(8)
  54611 		goto _62
  54612 	_62:
  54613 		v24 = v18 - v20 - v22 + int32(8708)
  54614 		if v24 & ^int32(YUV_MASK2) == 0 {
  54615 			v27 = v24 >> int32(YUV_FIX2)
  54616 		} else {
  54617 			if v24 < 0 {
  54618 				v28 = 0
  54619 			} else {
  54620 				v28 = int32(255)
  54621 			}
  54622 			v27 = v28
  54623 		}
  54624 		v25 = v27
  54625 		goto _65
  54626 	_65:
  54627 		v16 = v25
  54628 		goto _56
  54629 	_56:
  54630 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54631 		v31 = v1 * int32(19077) >> int32(8)
  54632 		goto _71
  54633 	_71:
  54634 		v33 = v2 * int32(33050) >> int32(8)
  54635 		goto _73
  54636 	_73:
  54637 		v35 = v31 + v33 - int32(17685)
  54638 		if v35 & ^int32(YUV_MASK2) == 0 {
  54639 			v38 = v35 >> int32(YUV_FIX2)
  54640 		} else {
  54641 			if v35 < 0 {
  54642 				v39 = 0
  54643 			} else {
  54644 				v39 = int32(255)
  54645 			}
  54646 			v38 = v39
  54647 		}
  54648 		v36 = v38
  54649 		goto _76
  54650 	_76:
  54651 		v29 = v36
  54652 		goto _69
  54653 	_69:
  54654 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54655 	}
  54656 	x = int32(1)
  54657 	for {
  54658 		if !(x <= last_pixel_pair) {
  54659 			break
  54660 		}
  54661 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  54662 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  54663 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  54664 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  54665 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  54666 		uv02 = (diag_12 + tl_uv) >> int32(1)
  54667 		uv1 = (diag_03 + t_uv) >> int32(1)
  54668 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  54669 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  54670 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  54671 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  54672 		v7 = v1 * int32(19077) >> int32(8)
  54673 		goto _87
  54674 	_87:
  54675 		v9 = v3 * int32(26149) >> int32(8)
  54676 		goto _89
  54677 	_89:
  54678 		v11 = v7 + v9 - int32(14234)
  54679 		if v11 & ^int32(YUV_MASK2) == 0 {
  54680 			v14 = v11 >> int32(YUV_FIX2)
  54681 		} else {
  54682 			if v11 < 0 {
  54683 				v15 = 0
  54684 			} else {
  54685 				v15 = int32(255)
  54686 			}
  54687 			v14 = v15
  54688 		}
  54689 		v12 = v14
  54690 		goto _92
  54691 	_92:
  54692 		v5 = v12
  54693 		goto _85
  54694 	_85:
  54695 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54696 		v18 = v1 * int32(19077) >> int32(8)
  54697 		goto _98
  54698 	_98:
  54699 		v20 = v2 * int32(6419) >> int32(8)
  54700 		goto _100
  54701 	_100:
  54702 		v22 = v3 * int32(13320) >> int32(8)
  54703 		goto _102
  54704 	_102:
  54705 		v24 = v18 - v20 - v22 + int32(8708)
  54706 		if v24 & ^int32(YUV_MASK2) == 0 {
  54707 			v27 = v24 >> int32(YUV_FIX2)
  54708 		} else {
  54709 			if v24 < 0 {
  54710 				v28 = 0
  54711 			} else {
  54712 				v28 = int32(255)
  54713 			}
  54714 			v27 = v28
  54715 		}
  54716 		v25 = v27
  54717 		goto _105
  54718 	_105:
  54719 		v16 = v25
  54720 		goto _96
  54721 	_96:
  54722 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54723 		v31 = v1 * int32(19077) >> int32(8)
  54724 		goto _111
  54725 	_111:
  54726 		v33 = v2 * int32(33050) >> int32(8)
  54727 		goto _113
  54728 	_113:
  54729 		v35 = v31 + v33 - int32(17685)
  54730 		if v35 & ^int32(YUV_MASK2) == 0 {
  54731 			v38 = v35 >> int32(YUV_FIX2)
  54732 		} else {
  54733 			if v35 < 0 {
  54734 				v39 = 0
  54735 			} else {
  54736 				v39 = int32(255)
  54737 			}
  54738 			v38 = v39
  54739 		}
  54740 		v36 = v38
  54741 		goto _116
  54742 	_116:
  54743 		v29 = v36
  54744 		goto _109
  54745 	_109:
  54746 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54747 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  54748 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  54749 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  54750 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  54751 		v7 = v1 * int32(19077) >> int32(8)
  54752 		goto _126
  54753 	_126:
  54754 		v9 = v3 * int32(26149) >> int32(8)
  54755 		goto _128
  54756 	_128:
  54757 		v11 = v7 + v9 - int32(14234)
  54758 		if v11 & ^int32(YUV_MASK2) == 0 {
  54759 			v14 = v11 >> int32(YUV_FIX2)
  54760 		} else {
  54761 			if v11 < 0 {
  54762 				v15 = 0
  54763 			} else {
  54764 				v15 = int32(255)
  54765 			}
  54766 			v14 = v15
  54767 		}
  54768 		v12 = v14
  54769 		goto _131
  54770 	_131:
  54771 		v5 = v12
  54772 		goto _124
  54773 	_124:
  54774 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54775 		v18 = v1 * int32(19077) >> int32(8)
  54776 		goto _137
  54777 	_137:
  54778 		v20 = v2 * int32(6419) >> int32(8)
  54779 		goto _139
  54780 	_139:
  54781 		v22 = v3 * int32(13320) >> int32(8)
  54782 		goto _141
  54783 	_141:
  54784 		v24 = v18 - v20 - v22 + int32(8708)
  54785 		if v24 & ^int32(YUV_MASK2) == 0 {
  54786 			v27 = v24 >> int32(YUV_FIX2)
  54787 		} else {
  54788 			if v24 < 0 {
  54789 				v28 = 0
  54790 			} else {
  54791 				v28 = int32(255)
  54792 			}
  54793 			v27 = v28
  54794 		}
  54795 		v25 = v27
  54796 		goto _144
  54797 	_144:
  54798 		v16 = v25
  54799 		goto _135
  54800 	_135:
  54801 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54802 		v31 = v1 * int32(19077) >> int32(8)
  54803 		goto _150
  54804 	_150:
  54805 		v33 = v2 * int32(33050) >> int32(8)
  54806 		goto _152
  54807 	_152:
  54808 		v35 = v31 + v33 - int32(17685)
  54809 		if v35 & ^int32(YUV_MASK2) == 0 {
  54810 			v38 = v35 >> int32(YUV_FIX2)
  54811 		} else {
  54812 			if v35 < 0 {
  54813 				v39 = 0
  54814 			} else {
  54815 				v39 = int32(255)
  54816 			}
  54817 			v38 = v39
  54818 		}
  54819 		v36 = v38
  54820 		goto _155
  54821 	_155:
  54822 		v29 = v36
  54823 		goto _148
  54824 	_148:
  54825 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54826 		if bottom_y != libc.UintptrFromInt32(0) {
  54827 			uv03 = (diag_03 + l_uv) >> int32(1)
  54828 			uv11 = (diag_12 + uv) >> int32(1)
  54829 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  54830 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  54831 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  54832 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  54833 			v7 = v1 * int32(19077) >> int32(8)
  54834 			goto _165
  54835 		_165:
  54836 			v9 = v3 * int32(26149) >> int32(8)
  54837 			goto _167
  54838 		_167:
  54839 			v11 = v7 + v9 - int32(14234)
  54840 			if v11 & ^int32(YUV_MASK2) == 0 {
  54841 				v14 = v11 >> int32(YUV_FIX2)
  54842 			} else {
  54843 				if v11 < 0 {
  54844 					v15 = 0
  54845 				} else {
  54846 					v15 = int32(255)
  54847 				}
  54848 				v14 = v15
  54849 			}
  54850 			v12 = v14
  54851 			goto _170
  54852 		_170:
  54853 			v5 = v12
  54854 			goto _163
  54855 		_163:
  54856 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54857 			v18 = v1 * int32(19077) >> int32(8)
  54858 			goto _176
  54859 		_176:
  54860 			v20 = v2 * int32(6419) >> int32(8)
  54861 			goto _178
  54862 		_178:
  54863 			v22 = v3 * int32(13320) >> int32(8)
  54864 			goto _180
  54865 		_180:
  54866 			v24 = v18 - v20 - v22 + int32(8708)
  54867 			if v24 & ^int32(YUV_MASK2) == 0 {
  54868 				v27 = v24 >> int32(YUV_FIX2)
  54869 			} else {
  54870 				if v24 < 0 {
  54871 					v28 = 0
  54872 				} else {
  54873 					v28 = int32(255)
  54874 				}
  54875 				v27 = v28
  54876 			}
  54877 			v25 = v27
  54878 			goto _183
  54879 		_183:
  54880 			v16 = v25
  54881 			goto _174
  54882 		_174:
  54883 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54884 			v31 = v1 * int32(19077) >> int32(8)
  54885 			goto _189
  54886 		_189:
  54887 			v33 = v2 * int32(33050) >> int32(8)
  54888 			goto _191
  54889 		_191:
  54890 			v35 = v31 + v33 - int32(17685)
  54891 			if v35 & ^int32(YUV_MASK2) == 0 {
  54892 				v38 = v35 >> int32(YUV_FIX2)
  54893 			} else {
  54894 				if v35 < 0 {
  54895 					v39 = 0
  54896 				} else {
  54897 					v39 = int32(255)
  54898 				}
  54899 				v38 = v39
  54900 			}
  54901 			v36 = v38
  54902 			goto _194
  54903 		_194:
  54904 			v29 = v36
  54905 			goto _187
  54906 		_187:
  54907 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54908 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  54909 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  54910 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  54911 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  54912 			v7 = v1 * int32(19077) >> int32(8)
  54913 			goto _204
  54914 		_204:
  54915 			v9 = v3 * int32(26149) >> int32(8)
  54916 			goto _206
  54917 		_206:
  54918 			v11 = v7 + v9 - int32(14234)
  54919 			if v11 & ^int32(YUV_MASK2) == 0 {
  54920 				v14 = v11 >> int32(YUV_FIX2)
  54921 			} else {
  54922 				if v11 < 0 {
  54923 					v15 = 0
  54924 				} else {
  54925 					v15 = int32(255)
  54926 				}
  54927 				v14 = v15
  54928 			}
  54929 			v12 = v14
  54930 			goto _209
  54931 		_209:
  54932 			v5 = v12
  54933 			goto _202
  54934 		_202:
  54935 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54936 			v18 = v1 * int32(19077) >> int32(8)
  54937 			goto _215
  54938 		_215:
  54939 			v20 = v2 * int32(6419) >> int32(8)
  54940 			goto _217
  54941 		_217:
  54942 			v22 = v3 * int32(13320) >> int32(8)
  54943 			goto _219
  54944 		_219:
  54945 			v24 = v18 - v20 - v22 + int32(8708)
  54946 			if v24 & ^int32(YUV_MASK2) == 0 {
  54947 				v27 = v24 >> int32(YUV_FIX2)
  54948 			} else {
  54949 				if v24 < 0 {
  54950 					v28 = 0
  54951 				} else {
  54952 					v28 = int32(255)
  54953 				}
  54954 				v27 = v28
  54955 			}
  54956 			v25 = v27
  54957 			goto _222
  54958 		_222:
  54959 			v16 = v25
  54960 			goto _213
  54961 		_213:
  54962 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54963 			v31 = v1 * int32(19077) >> int32(8)
  54964 			goto _228
  54965 		_228:
  54966 			v33 = v2 * int32(33050) >> int32(8)
  54967 			goto _230
  54968 		_230:
  54969 			v35 = v31 + v33 - int32(17685)
  54970 			if v35 & ^int32(YUV_MASK2) == 0 {
  54971 				v38 = v35 >> int32(YUV_FIX2)
  54972 			} else {
  54973 				if v35 < 0 {
  54974 					v39 = 0
  54975 				} else {
  54976 					v39 = int32(255)
  54977 				}
  54978 				v38 = v39
  54979 			}
  54980 			v36 = v38
  54981 			goto _233
  54982 		_233:
  54983 			v29 = v36
  54984 			goto _226
  54985 		_226:
  54986 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54987 		}
  54988 		tl_uv = t_uv
  54989 		l_uv = uv
  54990 		goto _79
  54991 	_79:
  54992 		;
  54993 		x = x + 1
  54994 	}
  54995 	if !(len1&libc.Int32FromInt32(1) != 0) {
  54996 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54997 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  54998 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  54999 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  55000 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  55001 		v7 = v1 * int32(19077) >> int32(8)
  55002 		goto _243
  55003 	_243:
  55004 		v9 = v3 * int32(26149) >> int32(8)
  55005 		goto _245
  55006 	_245:
  55007 		v11 = v7 + v9 - int32(14234)
  55008 		if v11 & ^int32(YUV_MASK2) == 0 {
  55009 			v14 = v11 >> int32(YUV_FIX2)
  55010 		} else {
  55011 			if v11 < 0 {
  55012 				v15 = 0
  55013 			} else {
  55014 				v15 = int32(255)
  55015 			}
  55016 			v14 = v15
  55017 		}
  55018 		v12 = v14
  55019 		goto _248
  55020 	_248:
  55021 		v5 = v12
  55022 		goto _241
  55023 	_241:
  55024 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55025 		v18 = v1 * int32(19077) >> int32(8)
  55026 		goto _254
  55027 	_254:
  55028 		v20 = v2 * int32(6419) >> int32(8)
  55029 		goto _256
  55030 	_256:
  55031 		v22 = v3 * int32(13320) >> int32(8)
  55032 		goto _258
  55033 	_258:
  55034 		v24 = v18 - v20 - v22 + int32(8708)
  55035 		if v24 & ^int32(YUV_MASK2) == 0 {
  55036 			v27 = v24 >> int32(YUV_FIX2)
  55037 		} else {
  55038 			if v24 < 0 {
  55039 				v28 = 0
  55040 			} else {
  55041 				v28 = int32(255)
  55042 			}
  55043 			v27 = v28
  55044 		}
  55045 		v25 = v27
  55046 		goto _261
  55047 	_261:
  55048 		v16 = v25
  55049 		goto _252
  55050 	_252:
  55051 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55052 		v31 = v1 * int32(19077) >> int32(8)
  55053 		goto _267
  55054 	_267:
  55055 		v33 = v2 * int32(33050) >> int32(8)
  55056 		goto _269
  55057 	_269:
  55058 		v35 = v31 + v33 - int32(17685)
  55059 		if v35 & ^int32(YUV_MASK2) == 0 {
  55060 			v38 = v35 >> int32(YUV_FIX2)
  55061 		} else {
  55062 			if v35 < 0 {
  55063 				v39 = 0
  55064 			} else {
  55065 				v39 = int32(255)
  55066 			}
  55067 			v38 = v39
  55068 		}
  55069 		v36 = v38
  55070 		goto _272
  55071 	_272:
  55072 		v29 = v36
  55073 		goto _265
  55074 	_265:
  55075 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55076 		if bottom_y != libc.UintptrFromInt32(0) {
  55077 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55078 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  55079 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  55080 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  55081 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  55082 			v7 = v1 * int32(19077) >> int32(8)
  55083 			goto _282
  55084 		_282:
  55085 			v9 = v3 * int32(26149) >> int32(8)
  55086 			goto _284
  55087 		_284:
  55088 			v11 = v7 + v9 - int32(14234)
  55089 			if v11 & ^int32(YUV_MASK2) == 0 {
  55090 				v14 = v11 >> int32(YUV_FIX2)
  55091 			} else {
  55092 				if v11 < 0 {
  55093 					v15 = 0
  55094 				} else {
  55095 					v15 = int32(255)
  55096 				}
  55097 				v14 = v15
  55098 			}
  55099 			v12 = v14
  55100 			goto _287
  55101 		_287:
  55102 			v5 = v12
  55103 			goto _280
  55104 		_280:
  55105 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55106 			v18 = v1 * int32(19077) >> int32(8)
  55107 			goto _293
  55108 		_293:
  55109 			v20 = v2 * int32(6419) >> int32(8)
  55110 			goto _295
  55111 		_295:
  55112 			v22 = v3 * int32(13320) >> int32(8)
  55113 			goto _297
  55114 		_297:
  55115 			v24 = v18 - v20 - v22 + int32(8708)
  55116 			if v24 & ^int32(YUV_MASK2) == 0 {
  55117 				v27 = v24 >> int32(YUV_FIX2)
  55118 			} else {
  55119 				if v24 < 0 {
  55120 					v28 = 0
  55121 				} else {
  55122 					v28 = int32(255)
  55123 				}
  55124 				v27 = v28
  55125 			}
  55126 			v25 = v27
  55127 			goto _300
  55128 		_300:
  55129 			v16 = v25
  55130 			goto _291
  55131 		_291:
  55132 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55133 			v31 = v1 * int32(19077) >> int32(8)
  55134 			goto _306
  55135 		_306:
  55136 			v33 = v2 * int32(33050) >> int32(8)
  55137 			goto _308
  55138 		_308:
  55139 			v35 = v31 + v33 - int32(17685)
  55140 			if v35 & ^int32(YUV_MASK2) == 0 {
  55141 				v38 = v35 >> int32(YUV_FIX2)
  55142 			} else {
  55143 				if v35 < 0 {
  55144 					v39 = 0
  55145 				} else {
  55146 					v39 = int32(255)
  55147 				}
  55148 				v38 = v39
  55149 			}
  55150 			v36 = v38
  55151 			goto _311
  55152 		_311:
  55153 			v29 = v36
  55154 			goto _304
  55155 		_304:
  55156 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55157 		}
  55158 	}
  55159 }
  55160 
  55161 func UpsampleBgrLinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  55162 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  55163 	var last_pixel_pair, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v5, v7, v9 int32
  55164 	var v4 uintptr
  55165 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, diag_03, diag_12, l_uv, last_pixel_pair, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v5, v7, v9
  55166 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  55167 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  55168 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  55169 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55170 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  55171 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  55172 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  55173 	v4 = top_dst
  55174 	v7 = v1 * int32(19077) >> int32(8)
  55175 	goto _8
  55176 _8:
  55177 	v9 = v2 * int32(33050) >> int32(8)
  55178 	goto _10
  55179 _10:
  55180 	v11 = v7 + v9 - int32(17685)
  55181 	if v11 & ^int32(YUV_MASK2) == 0 {
  55182 		v14 = v11 >> int32(YUV_FIX2)
  55183 	} else {
  55184 		if v11 < 0 {
  55185 			v15 = 0
  55186 		} else {
  55187 			v15 = int32(255)
  55188 		}
  55189 		v14 = v15
  55190 	}
  55191 	v12 = v14
  55192 	goto _13
  55193 _13:
  55194 	v5 = v12
  55195 	goto _6
  55196 _6:
  55197 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55198 	v18 = v1 * int32(19077) >> int32(8)
  55199 	goto _19
  55200 _19:
  55201 	v20 = v2 * int32(6419) >> int32(8)
  55202 	goto _21
  55203 _21:
  55204 	v22 = v3 * int32(13320) >> int32(8)
  55205 	goto _23
  55206 _23:
  55207 	v24 = v18 - v20 - v22 + int32(8708)
  55208 	if v24 & ^int32(YUV_MASK2) == 0 {
  55209 		v27 = v24 >> int32(YUV_FIX2)
  55210 	} else {
  55211 		if v24 < 0 {
  55212 			v28 = 0
  55213 		} else {
  55214 			v28 = int32(255)
  55215 		}
  55216 		v27 = v28
  55217 	}
  55218 	v25 = v27
  55219 	goto _26
  55220 _26:
  55221 	v16 = v25
  55222 	goto _17
  55223 _17:
  55224 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55225 	v31 = v1 * int32(19077) >> int32(8)
  55226 	goto _32
  55227 _32:
  55228 	v33 = v3 * int32(26149) >> int32(8)
  55229 	goto _34
  55230 _34:
  55231 	v35 = v31 + v33 - int32(14234)
  55232 	if v35 & ^int32(YUV_MASK2) == 0 {
  55233 		v38 = v35 >> int32(YUV_FIX2)
  55234 	} else {
  55235 		if v35 < 0 {
  55236 			v39 = 0
  55237 		} else {
  55238 			v39 = int32(255)
  55239 		}
  55240 		v38 = v39
  55241 	}
  55242 	v36 = v38
  55243 	goto _37
  55244 _37:
  55245 	v29 = v36
  55246 	goto _30
  55247 _30:
  55248 	**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55249 	if bottom_y != libc.UintptrFromInt32(0) {
  55250 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55251 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  55252 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  55253 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  55254 		v4 = bottom_dst
  55255 		v7 = v1 * int32(19077) >> int32(8)
  55256 		goto _47
  55257 	_47:
  55258 		v9 = v2 * int32(33050) >> int32(8)
  55259 		goto _49
  55260 	_49:
  55261 		v11 = v7 + v9 - int32(17685)
  55262 		if v11 & ^int32(YUV_MASK2) == 0 {
  55263 			v14 = v11 >> int32(YUV_FIX2)
  55264 		} else {
  55265 			if v11 < 0 {
  55266 				v15 = 0
  55267 			} else {
  55268 				v15 = int32(255)
  55269 			}
  55270 			v14 = v15
  55271 		}
  55272 		v12 = v14
  55273 		goto _52
  55274 	_52:
  55275 		v5 = v12
  55276 		goto _45
  55277 	_45:
  55278 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55279 		v18 = v1 * int32(19077) >> int32(8)
  55280 		goto _58
  55281 	_58:
  55282 		v20 = v2 * int32(6419) >> int32(8)
  55283 		goto _60
  55284 	_60:
  55285 		v22 = v3 * int32(13320) >> int32(8)
  55286 		goto _62
  55287 	_62:
  55288 		v24 = v18 - v20 - v22 + int32(8708)
  55289 		if v24 & ^int32(YUV_MASK2) == 0 {
  55290 			v27 = v24 >> int32(YUV_FIX2)
  55291 		} else {
  55292 			if v24 < 0 {
  55293 				v28 = 0
  55294 			} else {
  55295 				v28 = int32(255)
  55296 			}
  55297 			v27 = v28
  55298 		}
  55299 		v25 = v27
  55300 		goto _65
  55301 	_65:
  55302 		v16 = v25
  55303 		goto _56
  55304 	_56:
  55305 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55306 		v31 = v1 * int32(19077) >> int32(8)
  55307 		goto _71
  55308 	_71:
  55309 		v33 = v3 * int32(26149) >> int32(8)
  55310 		goto _73
  55311 	_73:
  55312 		v35 = v31 + v33 - int32(14234)
  55313 		if v35 & ^int32(YUV_MASK2) == 0 {
  55314 			v38 = v35 >> int32(YUV_FIX2)
  55315 		} else {
  55316 			if v35 < 0 {
  55317 				v39 = 0
  55318 			} else {
  55319 				v39 = int32(255)
  55320 			}
  55321 			v38 = v39
  55322 		}
  55323 		v36 = v38
  55324 		goto _76
  55325 	_76:
  55326 		v29 = v36
  55327 		goto _69
  55328 	_69:
  55329 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55330 	}
  55331 	x = int32(1)
  55332 	for {
  55333 		if !(x <= last_pixel_pair) {
  55334 			break
  55335 		}
  55336 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  55337 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  55338 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  55339 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  55340 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  55341 		uv02 = (diag_12 + tl_uv) >> int32(1)
  55342 		uv1 = (diag_03 + t_uv) >> int32(1)
  55343 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  55344 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  55345 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  55346 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55347 		v7 = v1 * int32(19077) >> int32(8)
  55348 		goto _87
  55349 	_87:
  55350 		v9 = v2 * int32(33050) >> int32(8)
  55351 		goto _89
  55352 	_89:
  55353 		v11 = v7 + v9 - int32(17685)
  55354 		if v11 & ^int32(YUV_MASK2) == 0 {
  55355 			v14 = v11 >> int32(YUV_FIX2)
  55356 		} else {
  55357 			if v11 < 0 {
  55358 				v15 = 0
  55359 			} else {
  55360 				v15 = int32(255)
  55361 			}
  55362 			v14 = v15
  55363 		}
  55364 		v12 = v14
  55365 		goto _92
  55366 	_92:
  55367 		v5 = v12
  55368 		goto _85
  55369 	_85:
  55370 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55371 		v18 = v1 * int32(19077) >> int32(8)
  55372 		goto _98
  55373 	_98:
  55374 		v20 = v2 * int32(6419) >> int32(8)
  55375 		goto _100
  55376 	_100:
  55377 		v22 = v3 * int32(13320) >> int32(8)
  55378 		goto _102
  55379 	_102:
  55380 		v24 = v18 - v20 - v22 + int32(8708)
  55381 		if v24 & ^int32(YUV_MASK2) == 0 {
  55382 			v27 = v24 >> int32(YUV_FIX2)
  55383 		} else {
  55384 			if v24 < 0 {
  55385 				v28 = 0
  55386 			} else {
  55387 				v28 = int32(255)
  55388 			}
  55389 			v27 = v28
  55390 		}
  55391 		v25 = v27
  55392 		goto _105
  55393 	_105:
  55394 		v16 = v25
  55395 		goto _96
  55396 	_96:
  55397 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55398 		v31 = v1 * int32(19077) >> int32(8)
  55399 		goto _111
  55400 	_111:
  55401 		v33 = v3 * int32(26149) >> int32(8)
  55402 		goto _113
  55403 	_113:
  55404 		v35 = v31 + v33 - int32(14234)
  55405 		if v35 & ^int32(YUV_MASK2) == 0 {
  55406 			v38 = v35 >> int32(YUV_FIX2)
  55407 		} else {
  55408 			if v35 < 0 {
  55409 				v39 = 0
  55410 			} else {
  55411 				v39 = int32(255)
  55412 			}
  55413 			v38 = v39
  55414 		}
  55415 		v36 = v38
  55416 		goto _116
  55417 	_116:
  55418 		v29 = v36
  55419 		goto _109
  55420 	_109:
  55421 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55422 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  55423 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  55424 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  55425 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  55426 		v7 = v1 * int32(19077) >> int32(8)
  55427 		goto _126
  55428 	_126:
  55429 		v9 = v2 * int32(33050) >> int32(8)
  55430 		goto _128
  55431 	_128:
  55432 		v11 = v7 + v9 - int32(17685)
  55433 		if v11 & ^int32(YUV_MASK2) == 0 {
  55434 			v14 = v11 >> int32(YUV_FIX2)
  55435 		} else {
  55436 			if v11 < 0 {
  55437 				v15 = 0
  55438 			} else {
  55439 				v15 = int32(255)
  55440 			}
  55441 			v14 = v15
  55442 		}
  55443 		v12 = v14
  55444 		goto _131
  55445 	_131:
  55446 		v5 = v12
  55447 		goto _124
  55448 	_124:
  55449 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55450 		v18 = v1 * int32(19077) >> int32(8)
  55451 		goto _137
  55452 	_137:
  55453 		v20 = v2 * int32(6419) >> int32(8)
  55454 		goto _139
  55455 	_139:
  55456 		v22 = v3 * int32(13320) >> int32(8)
  55457 		goto _141
  55458 	_141:
  55459 		v24 = v18 - v20 - v22 + int32(8708)
  55460 		if v24 & ^int32(YUV_MASK2) == 0 {
  55461 			v27 = v24 >> int32(YUV_FIX2)
  55462 		} else {
  55463 			if v24 < 0 {
  55464 				v28 = 0
  55465 			} else {
  55466 				v28 = int32(255)
  55467 			}
  55468 			v27 = v28
  55469 		}
  55470 		v25 = v27
  55471 		goto _144
  55472 	_144:
  55473 		v16 = v25
  55474 		goto _135
  55475 	_135:
  55476 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55477 		v31 = v1 * int32(19077) >> int32(8)
  55478 		goto _150
  55479 	_150:
  55480 		v33 = v3 * int32(26149) >> int32(8)
  55481 		goto _152
  55482 	_152:
  55483 		v35 = v31 + v33 - int32(14234)
  55484 		if v35 & ^int32(YUV_MASK2) == 0 {
  55485 			v38 = v35 >> int32(YUV_FIX2)
  55486 		} else {
  55487 			if v35 < 0 {
  55488 				v39 = 0
  55489 			} else {
  55490 				v39 = int32(255)
  55491 			}
  55492 			v38 = v39
  55493 		}
  55494 		v36 = v38
  55495 		goto _155
  55496 	_155:
  55497 		v29 = v36
  55498 		goto _148
  55499 	_148:
  55500 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55501 		if bottom_y != libc.UintptrFromInt32(0) {
  55502 			uv03 = (diag_03 + l_uv) >> int32(1)
  55503 			uv11 = (diag_12 + uv) >> int32(1)
  55504 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  55505 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  55506 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  55507 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55508 			v7 = v1 * int32(19077) >> int32(8)
  55509 			goto _165
  55510 		_165:
  55511 			v9 = v2 * int32(33050) >> int32(8)
  55512 			goto _167
  55513 		_167:
  55514 			v11 = v7 + v9 - int32(17685)
  55515 			if v11 & ^int32(YUV_MASK2) == 0 {
  55516 				v14 = v11 >> int32(YUV_FIX2)
  55517 			} else {
  55518 				if v11 < 0 {
  55519 					v15 = 0
  55520 				} else {
  55521 					v15 = int32(255)
  55522 				}
  55523 				v14 = v15
  55524 			}
  55525 			v12 = v14
  55526 			goto _170
  55527 		_170:
  55528 			v5 = v12
  55529 			goto _163
  55530 		_163:
  55531 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55532 			v18 = v1 * int32(19077) >> int32(8)
  55533 			goto _176
  55534 		_176:
  55535 			v20 = v2 * int32(6419) >> int32(8)
  55536 			goto _178
  55537 		_178:
  55538 			v22 = v3 * int32(13320) >> int32(8)
  55539 			goto _180
  55540 		_180:
  55541 			v24 = v18 - v20 - v22 + int32(8708)
  55542 			if v24 & ^int32(YUV_MASK2) == 0 {
  55543 				v27 = v24 >> int32(YUV_FIX2)
  55544 			} else {
  55545 				if v24 < 0 {
  55546 					v28 = 0
  55547 				} else {
  55548 					v28 = int32(255)
  55549 				}
  55550 				v27 = v28
  55551 			}
  55552 			v25 = v27
  55553 			goto _183
  55554 		_183:
  55555 			v16 = v25
  55556 			goto _174
  55557 		_174:
  55558 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55559 			v31 = v1 * int32(19077) >> int32(8)
  55560 			goto _189
  55561 		_189:
  55562 			v33 = v3 * int32(26149) >> int32(8)
  55563 			goto _191
  55564 		_191:
  55565 			v35 = v31 + v33 - int32(14234)
  55566 			if v35 & ^int32(YUV_MASK2) == 0 {
  55567 				v38 = v35 >> int32(YUV_FIX2)
  55568 			} else {
  55569 				if v35 < 0 {
  55570 					v39 = 0
  55571 				} else {
  55572 					v39 = int32(255)
  55573 				}
  55574 				v38 = v39
  55575 			}
  55576 			v36 = v38
  55577 			goto _194
  55578 		_194:
  55579 			v29 = v36
  55580 			goto _187
  55581 		_187:
  55582 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55583 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55584 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  55585 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  55586 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55587 			v7 = v1 * int32(19077) >> int32(8)
  55588 			goto _204
  55589 		_204:
  55590 			v9 = v2 * int32(33050) >> int32(8)
  55591 			goto _206
  55592 		_206:
  55593 			v11 = v7 + v9 - int32(17685)
  55594 			if v11 & ^int32(YUV_MASK2) == 0 {
  55595 				v14 = v11 >> int32(YUV_FIX2)
  55596 			} else {
  55597 				if v11 < 0 {
  55598 					v15 = 0
  55599 				} else {
  55600 					v15 = int32(255)
  55601 				}
  55602 				v14 = v15
  55603 			}
  55604 			v12 = v14
  55605 			goto _209
  55606 		_209:
  55607 			v5 = v12
  55608 			goto _202
  55609 		_202:
  55610 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55611 			v18 = v1 * int32(19077) >> int32(8)
  55612 			goto _215
  55613 		_215:
  55614 			v20 = v2 * int32(6419) >> int32(8)
  55615 			goto _217
  55616 		_217:
  55617 			v22 = v3 * int32(13320) >> int32(8)
  55618 			goto _219
  55619 		_219:
  55620 			v24 = v18 - v20 - v22 + int32(8708)
  55621 			if v24 & ^int32(YUV_MASK2) == 0 {
  55622 				v27 = v24 >> int32(YUV_FIX2)
  55623 			} else {
  55624 				if v24 < 0 {
  55625 					v28 = 0
  55626 				} else {
  55627 					v28 = int32(255)
  55628 				}
  55629 				v27 = v28
  55630 			}
  55631 			v25 = v27
  55632 			goto _222
  55633 		_222:
  55634 			v16 = v25
  55635 			goto _213
  55636 		_213:
  55637 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55638 			v31 = v1 * int32(19077) >> int32(8)
  55639 			goto _228
  55640 		_228:
  55641 			v33 = v3 * int32(26149) >> int32(8)
  55642 			goto _230
  55643 		_230:
  55644 			v35 = v31 + v33 - int32(14234)
  55645 			if v35 & ^int32(YUV_MASK2) == 0 {
  55646 				v38 = v35 >> int32(YUV_FIX2)
  55647 			} else {
  55648 				if v35 < 0 {
  55649 					v39 = 0
  55650 				} else {
  55651 					v39 = int32(255)
  55652 				}
  55653 				v38 = v39
  55654 			}
  55655 			v36 = v38
  55656 			goto _233
  55657 		_233:
  55658 			v29 = v36
  55659 			goto _226
  55660 		_226:
  55661 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55662 		}
  55663 		tl_uv = t_uv
  55664 		l_uv = uv
  55665 		goto _79
  55666 	_79:
  55667 		;
  55668 		x = x + 1
  55669 	}
  55670 	if !(len1&libc.Int32FromInt32(1) != 0) {
  55671 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55672 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  55673 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  55674 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  55675 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  55676 		v7 = v1 * int32(19077) >> int32(8)
  55677 		goto _243
  55678 	_243:
  55679 		v9 = v2 * int32(33050) >> int32(8)
  55680 		goto _245
  55681 	_245:
  55682 		v11 = v7 + v9 - int32(17685)
  55683 		if v11 & ^int32(YUV_MASK2) == 0 {
  55684 			v14 = v11 >> int32(YUV_FIX2)
  55685 		} else {
  55686 			if v11 < 0 {
  55687 				v15 = 0
  55688 			} else {
  55689 				v15 = int32(255)
  55690 			}
  55691 			v14 = v15
  55692 		}
  55693 		v12 = v14
  55694 		goto _248
  55695 	_248:
  55696 		v5 = v12
  55697 		goto _241
  55698 	_241:
  55699 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55700 		v18 = v1 * int32(19077) >> int32(8)
  55701 		goto _254
  55702 	_254:
  55703 		v20 = v2 * int32(6419) >> int32(8)
  55704 		goto _256
  55705 	_256:
  55706 		v22 = v3 * int32(13320) >> int32(8)
  55707 		goto _258
  55708 	_258:
  55709 		v24 = v18 - v20 - v22 + int32(8708)
  55710 		if v24 & ^int32(YUV_MASK2) == 0 {
  55711 			v27 = v24 >> int32(YUV_FIX2)
  55712 		} else {
  55713 			if v24 < 0 {
  55714 				v28 = 0
  55715 			} else {
  55716 				v28 = int32(255)
  55717 			}
  55718 			v27 = v28
  55719 		}
  55720 		v25 = v27
  55721 		goto _261
  55722 	_261:
  55723 		v16 = v25
  55724 		goto _252
  55725 	_252:
  55726 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55727 		v31 = v1 * int32(19077) >> int32(8)
  55728 		goto _267
  55729 	_267:
  55730 		v33 = v3 * int32(26149) >> int32(8)
  55731 		goto _269
  55732 	_269:
  55733 		v35 = v31 + v33 - int32(14234)
  55734 		if v35 & ^int32(YUV_MASK2) == 0 {
  55735 			v38 = v35 >> int32(YUV_FIX2)
  55736 		} else {
  55737 			if v35 < 0 {
  55738 				v39 = 0
  55739 			} else {
  55740 				v39 = int32(255)
  55741 			}
  55742 			v38 = v39
  55743 		}
  55744 		v36 = v38
  55745 		goto _272
  55746 	_272:
  55747 		v29 = v36
  55748 		goto _265
  55749 	_265:
  55750 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55751 		if bottom_y != libc.UintptrFromInt32(0) {
  55752 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55753 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  55754 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  55755 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  55756 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  55757 			v7 = v1 * int32(19077) >> int32(8)
  55758 			goto _282
  55759 		_282:
  55760 			v9 = v2 * int32(33050) >> int32(8)
  55761 			goto _284
  55762 		_284:
  55763 			v11 = v7 + v9 - int32(17685)
  55764 			if v11 & ^int32(YUV_MASK2) == 0 {
  55765 				v14 = v11 >> int32(YUV_FIX2)
  55766 			} else {
  55767 				if v11 < 0 {
  55768 					v15 = 0
  55769 				} else {
  55770 					v15 = int32(255)
  55771 				}
  55772 				v14 = v15
  55773 			}
  55774 			v12 = v14
  55775 			goto _287
  55776 		_287:
  55777 			v5 = v12
  55778 			goto _280
  55779 		_280:
  55780 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55781 			v18 = v1 * int32(19077) >> int32(8)
  55782 			goto _293
  55783 		_293:
  55784 			v20 = v2 * int32(6419) >> int32(8)
  55785 			goto _295
  55786 		_295:
  55787 			v22 = v3 * int32(13320) >> int32(8)
  55788 			goto _297
  55789 		_297:
  55790 			v24 = v18 - v20 - v22 + int32(8708)
  55791 			if v24 & ^int32(YUV_MASK2) == 0 {
  55792 				v27 = v24 >> int32(YUV_FIX2)
  55793 			} else {
  55794 				if v24 < 0 {
  55795 					v28 = 0
  55796 				} else {
  55797 					v28 = int32(255)
  55798 				}
  55799 				v27 = v28
  55800 			}
  55801 			v25 = v27
  55802 			goto _300
  55803 		_300:
  55804 			v16 = v25
  55805 			goto _291
  55806 		_291:
  55807 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55808 			v31 = v1 * int32(19077) >> int32(8)
  55809 			goto _306
  55810 		_306:
  55811 			v33 = v3 * int32(26149) >> int32(8)
  55812 			goto _308
  55813 		_308:
  55814 			v35 = v31 + v33 - int32(14234)
  55815 			if v35 & ^int32(YUV_MASK2) == 0 {
  55816 				v38 = v35 >> int32(YUV_FIX2)
  55817 			} else {
  55818 				if v35 < 0 {
  55819 					v39 = 0
  55820 				} else {
  55821 					v39 = int32(255)
  55822 				}
  55823 				v38 = v39
  55824 			}
  55825 			v36 = v38
  55826 			goto _311
  55827 		_311:
  55828 			v29 = v36
  55829 			goto _304
  55830 		_304:
  55831 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55832 		}
  55833 	}
  55834 }
  55835 
  55836 func UpsampleRgba4444LinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  55837 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  55838 	var b, ba, g, last_pixel_pair, r, rg, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v5, v7, v9 int32
  55839 	var v4 uintptr
  55840 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, b, ba, diag_03, diag_12, g, l_uv, last_pixel_pair, r, rg, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v5, v7, v9
  55841 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  55842 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  55843 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  55844 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55845 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  55846 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  55847 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  55848 	v4 = top_dst
  55849 	v7 = v1 * int32(19077) >> int32(8)
  55850 	goto _8
  55851 _8:
  55852 	v9 = v3 * int32(26149) >> int32(8)
  55853 	goto _10
  55854 _10:
  55855 	v11 = v7 + v9 - int32(14234)
  55856 	if v11 & ^int32(YUV_MASK2) == 0 {
  55857 		v14 = v11 >> int32(YUV_FIX2)
  55858 	} else {
  55859 		if v11 < 0 {
  55860 			v15 = 0
  55861 		} else {
  55862 			v15 = int32(255)
  55863 		}
  55864 		v14 = v15
  55865 	}
  55866 	v12 = v14
  55867 	goto _13
  55868 _13:
  55869 	v5 = v12
  55870 	goto _6
  55871 _6:
  55872 	r = v5
  55873 	v18 = v1 * int32(19077) >> int32(8)
  55874 	goto _19
  55875 _19:
  55876 	v20 = v2 * int32(6419) >> int32(8)
  55877 	goto _21
  55878 _21:
  55879 	v22 = v3 * int32(13320) >> int32(8)
  55880 	goto _23
  55881 _23:
  55882 	v24 = v18 - v20 - v22 + int32(8708)
  55883 	if v24 & ^int32(YUV_MASK2) == 0 {
  55884 		v27 = v24 >> int32(YUV_FIX2)
  55885 	} else {
  55886 		if v24 < 0 {
  55887 			v28 = 0
  55888 		} else {
  55889 			v28 = int32(255)
  55890 		}
  55891 		v27 = v28
  55892 	}
  55893 	v25 = v27
  55894 	goto _26
  55895 _26:
  55896 	v16 = v25
  55897 	goto _17
  55898 _17:
  55899 	g = v16
  55900 	v31 = v1 * int32(19077) >> int32(8)
  55901 	goto _32
  55902 _32:
  55903 	v33 = v2 * int32(33050) >> int32(8)
  55904 	goto _34
  55905 _34:
  55906 	v35 = v31 + v33 - int32(17685)
  55907 	if v35 & ^int32(YUV_MASK2) == 0 {
  55908 		v38 = v35 >> int32(YUV_FIX2)
  55909 	} else {
  55910 		if v35 < 0 {
  55911 			v39 = 0
  55912 		} else {
  55913 			v39 = int32(255)
  55914 		}
  55915 		v38 = v39
  55916 	}
  55917 	v36 = v38
  55918 	goto _37
  55919 _37:
  55920 	v29 = v36
  55921 	goto _30
  55922 _30:
  55923 	b = v29
  55924 	rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  55925 	ba = b&int32(0xf0) | int32(0x0f)
  55926 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  55927 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  55928 	if bottom_y != libc.UintptrFromInt32(0) {
  55929 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55930 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  55931 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  55932 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  55933 		v4 = bottom_dst
  55934 		v7 = v1 * int32(19077) >> int32(8)
  55935 		goto _47
  55936 	_47:
  55937 		v9 = v3 * int32(26149) >> int32(8)
  55938 		goto _49
  55939 	_49:
  55940 		v11 = v7 + v9 - int32(14234)
  55941 		if v11 & ^int32(YUV_MASK2) == 0 {
  55942 			v14 = v11 >> int32(YUV_FIX2)
  55943 		} else {
  55944 			if v11 < 0 {
  55945 				v15 = 0
  55946 			} else {
  55947 				v15 = int32(255)
  55948 			}
  55949 			v14 = v15
  55950 		}
  55951 		v12 = v14
  55952 		goto _52
  55953 	_52:
  55954 		v5 = v12
  55955 		goto _45
  55956 	_45:
  55957 		r = v5
  55958 		v18 = v1 * int32(19077) >> int32(8)
  55959 		goto _58
  55960 	_58:
  55961 		v20 = v2 * int32(6419) >> int32(8)
  55962 		goto _60
  55963 	_60:
  55964 		v22 = v3 * int32(13320) >> int32(8)
  55965 		goto _62
  55966 	_62:
  55967 		v24 = v18 - v20 - v22 + int32(8708)
  55968 		if v24 & ^int32(YUV_MASK2) == 0 {
  55969 			v27 = v24 >> int32(YUV_FIX2)
  55970 		} else {
  55971 			if v24 < 0 {
  55972 				v28 = 0
  55973 			} else {
  55974 				v28 = int32(255)
  55975 			}
  55976 			v27 = v28
  55977 		}
  55978 		v25 = v27
  55979 		goto _65
  55980 	_65:
  55981 		v16 = v25
  55982 		goto _56
  55983 	_56:
  55984 		g = v16
  55985 		v31 = v1 * int32(19077) >> int32(8)
  55986 		goto _71
  55987 	_71:
  55988 		v33 = v2 * int32(33050) >> int32(8)
  55989 		goto _73
  55990 	_73:
  55991 		v35 = v31 + v33 - int32(17685)
  55992 		if v35 & ^int32(YUV_MASK2) == 0 {
  55993 			v38 = v35 >> int32(YUV_FIX2)
  55994 		} else {
  55995 			if v35 < 0 {
  55996 				v39 = 0
  55997 			} else {
  55998 				v39 = int32(255)
  55999 			}
  56000 			v38 = v39
  56001 		}
  56002 		v36 = v38
  56003 		goto _76
  56004 	_76:
  56005 		v29 = v36
  56006 		goto _69
  56007 	_69:
  56008 		b = v29
  56009 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56010 		ba = b&int32(0xf0) | int32(0x0f)
  56011 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56012 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56013 	}
  56014 	x = int32(1)
  56015 	for {
  56016 		if !(x <= last_pixel_pair) {
  56017 			break
  56018 		}
  56019 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  56020 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  56021 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  56022 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  56023 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  56024 		uv02 = (diag_12 + tl_uv) >> int32(1)
  56025 		uv1 = (diag_03 + t_uv) >> int32(1)
  56026 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  56027 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  56028 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  56029 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56030 		v7 = v1 * int32(19077) >> int32(8)
  56031 		goto _87
  56032 	_87:
  56033 		v9 = v3 * int32(26149) >> int32(8)
  56034 		goto _89
  56035 	_89:
  56036 		v11 = v7 + v9 - int32(14234)
  56037 		if v11 & ^int32(YUV_MASK2) == 0 {
  56038 			v14 = v11 >> int32(YUV_FIX2)
  56039 		} else {
  56040 			if v11 < 0 {
  56041 				v15 = 0
  56042 			} else {
  56043 				v15 = int32(255)
  56044 			}
  56045 			v14 = v15
  56046 		}
  56047 		v12 = v14
  56048 		goto _92
  56049 	_92:
  56050 		v5 = v12
  56051 		goto _85
  56052 	_85:
  56053 		r = v5
  56054 		v18 = v1 * int32(19077) >> int32(8)
  56055 		goto _98
  56056 	_98:
  56057 		v20 = v2 * int32(6419) >> int32(8)
  56058 		goto _100
  56059 	_100:
  56060 		v22 = v3 * int32(13320) >> int32(8)
  56061 		goto _102
  56062 	_102:
  56063 		v24 = v18 - v20 - v22 + int32(8708)
  56064 		if v24 & ^int32(YUV_MASK2) == 0 {
  56065 			v27 = v24 >> int32(YUV_FIX2)
  56066 		} else {
  56067 			if v24 < 0 {
  56068 				v28 = 0
  56069 			} else {
  56070 				v28 = int32(255)
  56071 			}
  56072 			v27 = v28
  56073 		}
  56074 		v25 = v27
  56075 		goto _105
  56076 	_105:
  56077 		v16 = v25
  56078 		goto _96
  56079 	_96:
  56080 		g = v16
  56081 		v31 = v1 * int32(19077) >> int32(8)
  56082 		goto _111
  56083 	_111:
  56084 		v33 = v2 * int32(33050) >> int32(8)
  56085 		goto _113
  56086 	_113:
  56087 		v35 = v31 + v33 - int32(17685)
  56088 		if v35 & ^int32(YUV_MASK2) == 0 {
  56089 			v38 = v35 >> int32(YUV_FIX2)
  56090 		} else {
  56091 			if v35 < 0 {
  56092 				v39 = 0
  56093 			} else {
  56094 				v39 = int32(255)
  56095 			}
  56096 			v38 = v39
  56097 		}
  56098 		v36 = v38
  56099 		goto _116
  56100 	_116:
  56101 		v29 = v36
  56102 		goto _109
  56103 	_109:
  56104 		b = v29
  56105 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56106 		ba = b&int32(0xf0) | int32(0x0f)
  56107 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56108 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56109 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  56110 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  56111 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  56112 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  56113 		v7 = v1 * int32(19077) >> int32(8)
  56114 		goto _126
  56115 	_126:
  56116 		v9 = v3 * int32(26149) >> int32(8)
  56117 		goto _128
  56118 	_128:
  56119 		v11 = v7 + v9 - int32(14234)
  56120 		if v11 & ^int32(YUV_MASK2) == 0 {
  56121 			v14 = v11 >> int32(YUV_FIX2)
  56122 		} else {
  56123 			if v11 < 0 {
  56124 				v15 = 0
  56125 			} else {
  56126 				v15 = int32(255)
  56127 			}
  56128 			v14 = v15
  56129 		}
  56130 		v12 = v14
  56131 		goto _131
  56132 	_131:
  56133 		v5 = v12
  56134 		goto _124
  56135 	_124:
  56136 		r = v5
  56137 		v18 = v1 * int32(19077) >> int32(8)
  56138 		goto _137
  56139 	_137:
  56140 		v20 = v2 * int32(6419) >> int32(8)
  56141 		goto _139
  56142 	_139:
  56143 		v22 = v3 * int32(13320) >> int32(8)
  56144 		goto _141
  56145 	_141:
  56146 		v24 = v18 - v20 - v22 + int32(8708)
  56147 		if v24 & ^int32(YUV_MASK2) == 0 {
  56148 			v27 = v24 >> int32(YUV_FIX2)
  56149 		} else {
  56150 			if v24 < 0 {
  56151 				v28 = 0
  56152 			} else {
  56153 				v28 = int32(255)
  56154 			}
  56155 			v27 = v28
  56156 		}
  56157 		v25 = v27
  56158 		goto _144
  56159 	_144:
  56160 		v16 = v25
  56161 		goto _135
  56162 	_135:
  56163 		g = v16
  56164 		v31 = v1 * int32(19077) >> int32(8)
  56165 		goto _150
  56166 	_150:
  56167 		v33 = v2 * int32(33050) >> int32(8)
  56168 		goto _152
  56169 	_152:
  56170 		v35 = v31 + v33 - int32(17685)
  56171 		if v35 & ^int32(YUV_MASK2) == 0 {
  56172 			v38 = v35 >> int32(YUV_FIX2)
  56173 		} else {
  56174 			if v35 < 0 {
  56175 				v39 = 0
  56176 			} else {
  56177 				v39 = int32(255)
  56178 			}
  56179 			v38 = v39
  56180 		}
  56181 		v36 = v38
  56182 		goto _155
  56183 	_155:
  56184 		v29 = v36
  56185 		goto _148
  56186 	_148:
  56187 		b = v29
  56188 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56189 		ba = b&int32(0xf0) | int32(0x0f)
  56190 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56191 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56192 		if bottom_y != libc.UintptrFromInt32(0) {
  56193 			uv03 = (diag_03 + l_uv) >> int32(1)
  56194 			uv11 = (diag_12 + uv) >> int32(1)
  56195 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  56196 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  56197 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  56198 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56199 			v7 = v1 * int32(19077) >> int32(8)
  56200 			goto _165
  56201 		_165:
  56202 			v9 = v3 * int32(26149) >> int32(8)
  56203 			goto _167
  56204 		_167:
  56205 			v11 = v7 + v9 - int32(14234)
  56206 			if v11 & ^int32(YUV_MASK2) == 0 {
  56207 				v14 = v11 >> int32(YUV_FIX2)
  56208 			} else {
  56209 				if v11 < 0 {
  56210 					v15 = 0
  56211 				} else {
  56212 					v15 = int32(255)
  56213 				}
  56214 				v14 = v15
  56215 			}
  56216 			v12 = v14
  56217 			goto _170
  56218 		_170:
  56219 			v5 = v12
  56220 			goto _163
  56221 		_163:
  56222 			r = v5
  56223 			v18 = v1 * int32(19077) >> int32(8)
  56224 			goto _176
  56225 		_176:
  56226 			v20 = v2 * int32(6419) >> int32(8)
  56227 			goto _178
  56228 		_178:
  56229 			v22 = v3 * int32(13320) >> int32(8)
  56230 			goto _180
  56231 		_180:
  56232 			v24 = v18 - v20 - v22 + int32(8708)
  56233 			if v24 & ^int32(YUV_MASK2) == 0 {
  56234 				v27 = v24 >> int32(YUV_FIX2)
  56235 			} else {
  56236 				if v24 < 0 {
  56237 					v28 = 0
  56238 				} else {
  56239 					v28 = int32(255)
  56240 				}
  56241 				v27 = v28
  56242 			}
  56243 			v25 = v27
  56244 			goto _183
  56245 		_183:
  56246 			v16 = v25
  56247 			goto _174
  56248 		_174:
  56249 			g = v16
  56250 			v31 = v1 * int32(19077) >> int32(8)
  56251 			goto _189
  56252 		_189:
  56253 			v33 = v2 * int32(33050) >> int32(8)
  56254 			goto _191
  56255 		_191:
  56256 			v35 = v31 + v33 - int32(17685)
  56257 			if v35 & ^int32(YUV_MASK2) == 0 {
  56258 				v38 = v35 >> int32(YUV_FIX2)
  56259 			} else {
  56260 				if v35 < 0 {
  56261 					v39 = 0
  56262 				} else {
  56263 					v39 = int32(255)
  56264 				}
  56265 				v38 = v39
  56266 			}
  56267 			v36 = v38
  56268 			goto _194
  56269 		_194:
  56270 			v29 = v36
  56271 			goto _187
  56272 		_187:
  56273 			b = v29
  56274 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56275 			ba = b&int32(0xf0) | int32(0x0f)
  56276 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56277 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56278 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  56279 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  56280 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  56281 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  56282 			v7 = v1 * int32(19077) >> int32(8)
  56283 			goto _204
  56284 		_204:
  56285 			v9 = v3 * int32(26149) >> int32(8)
  56286 			goto _206
  56287 		_206:
  56288 			v11 = v7 + v9 - int32(14234)
  56289 			if v11 & ^int32(YUV_MASK2) == 0 {
  56290 				v14 = v11 >> int32(YUV_FIX2)
  56291 			} else {
  56292 				if v11 < 0 {
  56293 					v15 = 0
  56294 				} else {
  56295 					v15 = int32(255)
  56296 				}
  56297 				v14 = v15
  56298 			}
  56299 			v12 = v14
  56300 			goto _209
  56301 		_209:
  56302 			v5 = v12
  56303 			goto _202
  56304 		_202:
  56305 			r = v5
  56306 			v18 = v1 * int32(19077) >> int32(8)
  56307 			goto _215
  56308 		_215:
  56309 			v20 = v2 * int32(6419) >> int32(8)
  56310 			goto _217
  56311 		_217:
  56312 			v22 = v3 * int32(13320) >> int32(8)
  56313 			goto _219
  56314 		_219:
  56315 			v24 = v18 - v20 - v22 + int32(8708)
  56316 			if v24 & ^int32(YUV_MASK2) == 0 {
  56317 				v27 = v24 >> int32(YUV_FIX2)
  56318 			} else {
  56319 				if v24 < 0 {
  56320 					v28 = 0
  56321 				} else {
  56322 					v28 = int32(255)
  56323 				}
  56324 				v27 = v28
  56325 			}
  56326 			v25 = v27
  56327 			goto _222
  56328 		_222:
  56329 			v16 = v25
  56330 			goto _213
  56331 		_213:
  56332 			g = v16
  56333 			v31 = v1 * int32(19077) >> int32(8)
  56334 			goto _228
  56335 		_228:
  56336 			v33 = v2 * int32(33050) >> int32(8)
  56337 			goto _230
  56338 		_230:
  56339 			v35 = v31 + v33 - int32(17685)
  56340 			if v35 & ^int32(YUV_MASK2) == 0 {
  56341 				v38 = v35 >> int32(YUV_FIX2)
  56342 			} else {
  56343 				if v35 < 0 {
  56344 					v39 = 0
  56345 				} else {
  56346 					v39 = int32(255)
  56347 				}
  56348 				v38 = v39
  56349 			}
  56350 			v36 = v38
  56351 			goto _233
  56352 		_233:
  56353 			v29 = v36
  56354 			goto _226
  56355 		_226:
  56356 			b = v29
  56357 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56358 			ba = b&int32(0xf0) | int32(0x0f)
  56359 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56360 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56361 		}
  56362 		tl_uv = t_uv
  56363 		l_uv = uv
  56364 		goto _79
  56365 	_79:
  56366 		;
  56367 		x = x + 1
  56368 	}
  56369 	if !(len1&libc.Int32FromInt32(1) != 0) {
  56370 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56371 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  56372 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  56373 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  56374 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  56375 		v7 = v1 * int32(19077) >> int32(8)
  56376 		goto _243
  56377 	_243:
  56378 		v9 = v3 * int32(26149) >> int32(8)
  56379 		goto _245
  56380 	_245:
  56381 		v11 = v7 + v9 - int32(14234)
  56382 		if v11 & ^int32(YUV_MASK2) == 0 {
  56383 			v14 = v11 >> int32(YUV_FIX2)
  56384 		} else {
  56385 			if v11 < 0 {
  56386 				v15 = 0
  56387 			} else {
  56388 				v15 = int32(255)
  56389 			}
  56390 			v14 = v15
  56391 		}
  56392 		v12 = v14
  56393 		goto _248
  56394 	_248:
  56395 		v5 = v12
  56396 		goto _241
  56397 	_241:
  56398 		r = v5
  56399 		v18 = v1 * int32(19077) >> int32(8)
  56400 		goto _254
  56401 	_254:
  56402 		v20 = v2 * int32(6419) >> int32(8)
  56403 		goto _256
  56404 	_256:
  56405 		v22 = v3 * int32(13320) >> int32(8)
  56406 		goto _258
  56407 	_258:
  56408 		v24 = v18 - v20 - v22 + int32(8708)
  56409 		if v24 & ^int32(YUV_MASK2) == 0 {
  56410 			v27 = v24 >> int32(YUV_FIX2)
  56411 		} else {
  56412 			if v24 < 0 {
  56413 				v28 = 0
  56414 			} else {
  56415 				v28 = int32(255)
  56416 			}
  56417 			v27 = v28
  56418 		}
  56419 		v25 = v27
  56420 		goto _261
  56421 	_261:
  56422 		v16 = v25
  56423 		goto _252
  56424 	_252:
  56425 		g = v16
  56426 		v31 = v1 * int32(19077) >> int32(8)
  56427 		goto _267
  56428 	_267:
  56429 		v33 = v2 * int32(33050) >> int32(8)
  56430 		goto _269
  56431 	_269:
  56432 		v35 = v31 + v33 - int32(17685)
  56433 		if v35 & ^int32(YUV_MASK2) == 0 {
  56434 			v38 = v35 >> int32(YUV_FIX2)
  56435 		} else {
  56436 			if v35 < 0 {
  56437 				v39 = 0
  56438 			} else {
  56439 				v39 = int32(255)
  56440 			}
  56441 			v38 = v39
  56442 		}
  56443 		v36 = v38
  56444 		goto _272
  56445 	_272:
  56446 		v29 = v36
  56447 		goto _265
  56448 	_265:
  56449 		b = v29
  56450 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56451 		ba = b&int32(0xf0) | int32(0x0f)
  56452 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56453 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56454 		if bottom_y != libc.UintptrFromInt32(0) {
  56455 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56456 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  56457 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  56458 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  56459 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  56460 			v7 = v1 * int32(19077) >> int32(8)
  56461 			goto _282
  56462 		_282:
  56463 			v9 = v3 * int32(26149) >> int32(8)
  56464 			goto _284
  56465 		_284:
  56466 			v11 = v7 + v9 - int32(14234)
  56467 			if v11 & ^int32(YUV_MASK2) == 0 {
  56468 				v14 = v11 >> int32(YUV_FIX2)
  56469 			} else {
  56470 				if v11 < 0 {
  56471 					v15 = 0
  56472 				} else {
  56473 					v15 = int32(255)
  56474 				}
  56475 				v14 = v15
  56476 			}
  56477 			v12 = v14
  56478 			goto _287
  56479 		_287:
  56480 			v5 = v12
  56481 			goto _280
  56482 		_280:
  56483 			r = v5
  56484 			v18 = v1 * int32(19077) >> int32(8)
  56485 			goto _293
  56486 		_293:
  56487 			v20 = v2 * int32(6419) >> int32(8)
  56488 			goto _295
  56489 		_295:
  56490 			v22 = v3 * int32(13320) >> int32(8)
  56491 			goto _297
  56492 		_297:
  56493 			v24 = v18 - v20 - v22 + int32(8708)
  56494 			if v24 & ^int32(YUV_MASK2) == 0 {
  56495 				v27 = v24 >> int32(YUV_FIX2)
  56496 			} else {
  56497 				if v24 < 0 {
  56498 					v28 = 0
  56499 				} else {
  56500 					v28 = int32(255)
  56501 				}
  56502 				v27 = v28
  56503 			}
  56504 			v25 = v27
  56505 			goto _300
  56506 		_300:
  56507 			v16 = v25
  56508 			goto _291
  56509 		_291:
  56510 			g = v16
  56511 			v31 = v1 * int32(19077) >> int32(8)
  56512 			goto _306
  56513 		_306:
  56514 			v33 = v2 * int32(33050) >> int32(8)
  56515 			goto _308
  56516 		_308:
  56517 			v35 = v31 + v33 - int32(17685)
  56518 			if v35 & ^int32(YUV_MASK2) == 0 {
  56519 				v38 = v35 >> int32(YUV_FIX2)
  56520 			} else {
  56521 				if v35 < 0 {
  56522 					v39 = 0
  56523 				} else {
  56524 					v39 = int32(255)
  56525 				}
  56526 				v38 = v39
  56527 			}
  56528 			v36 = v38
  56529 			goto _311
  56530 		_311:
  56531 			v29 = v36
  56532 			goto _304
  56533 		_304:
  56534 			b = v29
  56535 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56536 			ba = b&int32(0xf0) | int32(0x0f)
  56537 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56538 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56539 		}
  56540 	}
  56541 }
  56542 
  56543 func UpsampleRgb565LinePair_C(tls *libc.TLS, top_y uintptr, bottom_y uintptr, top_u uintptr, top_v uintptr, cur_u uintptr, cur_v uintptr, top_dst uintptr, bottom_dst uintptr, len1 int32) {
  56544 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56545 	var b, g, gb, last_pixel_pair, r, rg, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v5, v7, v9 int32
  56546 	var v4 uintptr
  56547 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = avg, b, diag_03, diag_12, g, gb, l_uv, last_pixel_pair, r, rg, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11, x, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v5, v7, v9
  56548 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56549 	tl_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v)))<<libc.Int32FromInt32(16)) /* top-left sample */
  56550 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56551 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56552 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  56553 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  56554 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  56555 	v4 = top_dst
  56556 	v7 = v1 * int32(19077) >> int32(8)
  56557 	goto _8
  56558 _8:
  56559 	v9 = v3 * int32(26149) >> int32(8)
  56560 	goto _10
  56561 _10:
  56562 	v11 = v7 + v9 - int32(14234)
  56563 	if v11 & ^int32(YUV_MASK2) == 0 {
  56564 		v14 = v11 >> int32(YUV_FIX2)
  56565 	} else {
  56566 		if v11 < 0 {
  56567 			v15 = 0
  56568 		} else {
  56569 			v15 = int32(255)
  56570 		}
  56571 		v14 = v15
  56572 	}
  56573 	v12 = v14
  56574 	goto _13
  56575 _13:
  56576 	v5 = v12
  56577 	goto _6
  56578 _6:
  56579 	r = v5
  56580 	v18 = v1 * int32(19077) >> int32(8)
  56581 	goto _19
  56582 _19:
  56583 	v20 = v2 * int32(6419) >> int32(8)
  56584 	goto _21
  56585 _21:
  56586 	v22 = v3 * int32(13320) >> int32(8)
  56587 	goto _23
  56588 _23:
  56589 	v24 = v18 - v20 - v22 + int32(8708)
  56590 	if v24 & ^int32(YUV_MASK2) == 0 {
  56591 		v27 = v24 >> int32(YUV_FIX2)
  56592 	} else {
  56593 		if v24 < 0 {
  56594 			v28 = 0
  56595 		} else {
  56596 			v28 = int32(255)
  56597 		}
  56598 		v27 = v28
  56599 	}
  56600 	v25 = v27
  56601 	goto _26
  56602 _26:
  56603 	v16 = v25
  56604 	goto _17
  56605 _17:
  56606 	g = v16
  56607 	v31 = v1 * int32(19077) >> int32(8)
  56608 	goto _32
  56609 _32:
  56610 	v33 = v2 * int32(33050) >> int32(8)
  56611 	goto _34
  56612 _34:
  56613 	v35 = v31 + v33 - int32(17685)
  56614 	if v35 & ^int32(YUV_MASK2) == 0 {
  56615 		v38 = v35 >> int32(YUV_FIX2)
  56616 	} else {
  56617 		if v35 < 0 {
  56618 			v39 = 0
  56619 		} else {
  56620 			v39 = int32(255)
  56621 		}
  56622 		v38 = v39
  56623 	}
  56624 	v36 = v38
  56625 	goto _37
  56626 _37:
  56627 	v29 = v36
  56628 	goto _30
  56629 _30:
  56630 	b = v29
  56631 	rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56632 	gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56633 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56634 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56635 	if bottom_y != libc.UintptrFromInt32(0) {
  56636 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56637 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  56638 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  56639 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  56640 		v4 = bottom_dst
  56641 		v7 = v1 * int32(19077) >> int32(8)
  56642 		goto _47
  56643 	_47:
  56644 		v9 = v3 * int32(26149) >> int32(8)
  56645 		goto _49
  56646 	_49:
  56647 		v11 = v7 + v9 - int32(14234)
  56648 		if v11 & ^int32(YUV_MASK2) == 0 {
  56649 			v14 = v11 >> int32(YUV_FIX2)
  56650 		} else {
  56651 			if v11 < 0 {
  56652 				v15 = 0
  56653 			} else {
  56654 				v15 = int32(255)
  56655 			}
  56656 			v14 = v15
  56657 		}
  56658 		v12 = v14
  56659 		goto _52
  56660 	_52:
  56661 		v5 = v12
  56662 		goto _45
  56663 	_45:
  56664 		r = v5
  56665 		v18 = v1 * int32(19077) >> int32(8)
  56666 		goto _58
  56667 	_58:
  56668 		v20 = v2 * int32(6419) >> int32(8)
  56669 		goto _60
  56670 	_60:
  56671 		v22 = v3 * int32(13320) >> int32(8)
  56672 		goto _62
  56673 	_62:
  56674 		v24 = v18 - v20 - v22 + int32(8708)
  56675 		if v24 & ^int32(YUV_MASK2) == 0 {
  56676 			v27 = v24 >> int32(YUV_FIX2)
  56677 		} else {
  56678 			if v24 < 0 {
  56679 				v28 = 0
  56680 			} else {
  56681 				v28 = int32(255)
  56682 			}
  56683 			v27 = v28
  56684 		}
  56685 		v25 = v27
  56686 		goto _65
  56687 	_65:
  56688 		v16 = v25
  56689 		goto _56
  56690 	_56:
  56691 		g = v16
  56692 		v31 = v1 * int32(19077) >> int32(8)
  56693 		goto _71
  56694 	_71:
  56695 		v33 = v2 * int32(33050) >> int32(8)
  56696 		goto _73
  56697 	_73:
  56698 		v35 = v31 + v33 - int32(17685)
  56699 		if v35 & ^int32(YUV_MASK2) == 0 {
  56700 			v38 = v35 >> int32(YUV_FIX2)
  56701 		} else {
  56702 			if v35 < 0 {
  56703 				v39 = 0
  56704 			} else {
  56705 				v39 = int32(255)
  56706 			}
  56707 			v38 = v39
  56708 		}
  56709 		v36 = v38
  56710 		goto _76
  56711 	_76:
  56712 		v29 = v36
  56713 		goto _69
  56714 	_69:
  56715 		b = v29
  56716 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56717 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56718 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56719 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56720 	}
  56721 	x = int32(1)
  56722 	for {
  56723 		if !(x <= last_pixel_pair) {
  56724 			break
  56725 		}
  56726 		t_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_v + uintptr(x))))<<libc.Int32FromInt32(16)) /* top sample */
  56727 		uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u + uintptr(x)))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v + uintptr(x))))<<libc.Int32FromInt32(16))   /* sample */ /* precompute invariant values associated with first and second diagonals*/
  56728 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  56729 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  56730 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  56731 		uv02 = (diag_12 + tl_uv) >> int32(1)
  56732 		uv1 = (diag_03 + t_uv) >> int32(1)
  56733 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  56734 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  56735 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  56736 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56737 		v7 = v1 * int32(19077) >> int32(8)
  56738 		goto _87
  56739 	_87:
  56740 		v9 = v3 * int32(26149) >> int32(8)
  56741 		goto _89
  56742 	_89:
  56743 		v11 = v7 + v9 - int32(14234)
  56744 		if v11 & ^int32(YUV_MASK2) == 0 {
  56745 			v14 = v11 >> int32(YUV_FIX2)
  56746 		} else {
  56747 			if v11 < 0 {
  56748 				v15 = 0
  56749 			} else {
  56750 				v15 = int32(255)
  56751 			}
  56752 			v14 = v15
  56753 		}
  56754 		v12 = v14
  56755 		goto _92
  56756 	_92:
  56757 		v5 = v12
  56758 		goto _85
  56759 	_85:
  56760 		r = v5
  56761 		v18 = v1 * int32(19077) >> int32(8)
  56762 		goto _98
  56763 	_98:
  56764 		v20 = v2 * int32(6419) >> int32(8)
  56765 		goto _100
  56766 	_100:
  56767 		v22 = v3 * int32(13320) >> int32(8)
  56768 		goto _102
  56769 	_102:
  56770 		v24 = v18 - v20 - v22 + int32(8708)
  56771 		if v24 & ^int32(YUV_MASK2) == 0 {
  56772 			v27 = v24 >> int32(YUV_FIX2)
  56773 		} else {
  56774 			if v24 < 0 {
  56775 				v28 = 0
  56776 			} else {
  56777 				v28 = int32(255)
  56778 			}
  56779 			v27 = v28
  56780 		}
  56781 		v25 = v27
  56782 		goto _105
  56783 	_105:
  56784 		v16 = v25
  56785 		goto _96
  56786 	_96:
  56787 		g = v16
  56788 		v31 = v1 * int32(19077) >> int32(8)
  56789 		goto _111
  56790 	_111:
  56791 		v33 = v2 * int32(33050) >> int32(8)
  56792 		goto _113
  56793 	_113:
  56794 		v35 = v31 + v33 - int32(17685)
  56795 		if v35 & ^int32(YUV_MASK2) == 0 {
  56796 			v38 = v35 >> int32(YUV_FIX2)
  56797 		} else {
  56798 			if v35 < 0 {
  56799 				v39 = 0
  56800 			} else {
  56801 				v39 = int32(255)
  56802 			}
  56803 			v38 = v39
  56804 		}
  56805 		v36 = v38
  56806 		goto _116
  56807 	_116:
  56808 		v29 = v36
  56809 		goto _109
  56810 	_109:
  56811 		b = v29
  56812 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56813 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56814 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56815 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56816 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  56817 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  56818 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  56819 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  56820 		v7 = v1 * int32(19077) >> int32(8)
  56821 		goto _126
  56822 	_126:
  56823 		v9 = v3 * int32(26149) >> int32(8)
  56824 		goto _128
  56825 	_128:
  56826 		v11 = v7 + v9 - int32(14234)
  56827 		if v11 & ^int32(YUV_MASK2) == 0 {
  56828 			v14 = v11 >> int32(YUV_FIX2)
  56829 		} else {
  56830 			if v11 < 0 {
  56831 				v15 = 0
  56832 			} else {
  56833 				v15 = int32(255)
  56834 			}
  56835 			v14 = v15
  56836 		}
  56837 		v12 = v14
  56838 		goto _131
  56839 	_131:
  56840 		v5 = v12
  56841 		goto _124
  56842 	_124:
  56843 		r = v5
  56844 		v18 = v1 * int32(19077) >> int32(8)
  56845 		goto _137
  56846 	_137:
  56847 		v20 = v2 * int32(6419) >> int32(8)
  56848 		goto _139
  56849 	_139:
  56850 		v22 = v3 * int32(13320) >> int32(8)
  56851 		goto _141
  56852 	_141:
  56853 		v24 = v18 - v20 - v22 + int32(8708)
  56854 		if v24 & ^int32(YUV_MASK2) == 0 {
  56855 			v27 = v24 >> int32(YUV_FIX2)
  56856 		} else {
  56857 			if v24 < 0 {
  56858 				v28 = 0
  56859 			} else {
  56860 				v28 = int32(255)
  56861 			}
  56862 			v27 = v28
  56863 		}
  56864 		v25 = v27
  56865 		goto _144
  56866 	_144:
  56867 		v16 = v25
  56868 		goto _135
  56869 	_135:
  56870 		g = v16
  56871 		v31 = v1 * int32(19077) >> int32(8)
  56872 		goto _150
  56873 	_150:
  56874 		v33 = v2 * int32(33050) >> int32(8)
  56875 		goto _152
  56876 	_152:
  56877 		v35 = v31 + v33 - int32(17685)
  56878 		if v35 & ^int32(YUV_MASK2) == 0 {
  56879 			v38 = v35 >> int32(YUV_FIX2)
  56880 		} else {
  56881 			if v35 < 0 {
  56882 				v39 = 0
  56883 			} else {
  56884 				v39 = int32(255)
  56885 			}
  56886 			v38 = v39
  56887 		}
  56888 		v36 = v38
  56889 		goto _155
  56890 	_155:
  56891 		v29 = v36
  56892 		goto _148
  56893 	_148:
  56894 		b = v29
  56895 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56896 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56897 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56898 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56899 		if bottom_y != libc.UintptrFromInt32(0) {
  56900 			uv03 = (diag_03 + l_uv) >> int32(1)
  56901 			uv11 = (diag_12 + uv) >> int32(1)
  56902 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  56903 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  56904 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  56905 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56906 			v7 = v1 * int32(19077) >> int32(8)
  56907 			goto _165
  56908 		_165:
  56909 			v9 = v3 * int32(26149) >> int32(8)
  56910 			goto _167
  56911 		_167:
  56912 			v11 = v7 + v9 - int32(14234)
  56913 			if v11 & ^int32(YUV_MASK2) == 0 {
  56914 				v14 = v11 >> int32(YUV_FIX2)
  56915 			} else {
  56916 				if v11 < 0 {
  56917 					v15 = 0
  56918 				} else {
  56919 					v15 = int32(255)
  56920 				}
  56921 				v14 = v15
  56922 			}
  56923 			v12 = v14
  56924 			goto _170
  56925 		_170:
  56926 			v5 = v12
  56927 			goto _163
  56928 		_163:
  56929 			r = v5
  56930 			v18 = v1 * int32(19077) >> int32(8)
  56931 			goto _176
  56932 		_176:
  56933 			v20 = v2 * int32(6419) >> int32(8)
  56934 			goto _178
  56935 		_178:
  56936 			v22 = v3 * int32(13320) >> int32(8)
  56937 			goto _180
  56938 		_180:
  56939 			v24 = v18 - v20 - v22 + int32(8708)
  56940 			if v24 & ^int32(YUV_MASK2) == 0 {
  56941 				v27 = v24 >> int32(YUV_FIX2)
  56942 			} else {
  56943 				if v24 < 0 {
  56944 					v28 = 0
  56945 				} else {
  56946 					v28 = int32(255)
  56947 				}
  56948 				v27 = v28
  56949 			}
  56950 			v25 = v27
  56951 			goto _183
  56952 		_183:
  56953 			v16 = v25
  56954 			goto _174
  56955 		_174:
  56956 			g = v16
  56957 			v31 = v1 * int32(19077) >> int32(8)
  56958 			goto _189
  56959 		_189:
  56960 			v33 = v2 * int32(33050) >> int32(8)
  56961 			goto _191
  56962 		_191:
  56963 			v35 = v31 + v33 - int32(17685)
  56964 			if v35 & ^int32(YUV_MASK2) == 0 {
  56965 				v38 = v35 >> int32(YUV_FIX2)
  56966 			} else {
  56967 				if v35 < 0 {
  56968 					v39 = 0
  56969 				} else {
  56970 					v39 = int32(255)
  56971 				}
  56972 				v38 = v39
  56973 			}
  56974 			v36 = v38
  56975 			goto _194
  56976 		_194:
  56977 			v29 = v36
  56978 			goto _187
  56979 		_187:
  56980 			b = v29
  56981 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56982 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56983 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56984 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56985 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  56986 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  56987 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  56988 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  56989 			v7 = v1 * int32(19077) >> int32(8)
  56990 			goto _204
  56991 		_204:
  56992 			v9 = v3 * int32(26149) >> int32(8)
  56993 			goto _206
  56994 		_206:
  56995 			v11 = v7 + v9 - int32(14234)
  56996 			if v11 & ^int32(YUV_MASK2) == 0 {
  56997 				v14 = v11 >> int32(YUV_FIX2)
  56998 			} else {
  56999 				if v11 < 0 {
  57000 					v15 = 0
  57001 				} else {
  57002 					v15 = int32(255)
  57003 				}
  57004 				v14 = v15
  57005 			}
  57006 			v12 = v14
  57007 			goto _209
  57008 		_209:
  57009 			v5 = v12
  57010 			goto _202
  57011 		_202:
  57012 			r = v5
  57013 			v18 = v1 * int32(19077) >> int32(8)
  57014 			goto _215
  57015 		_215:
  57016 			v20 = v2 * int32(6419) >> int32(8)
  57017 			goto _217
  57018 		_217:
  57019 			v22 = v3 * int32(13320) >> int32(8)
  57020 			goto _219
  57021 		_219:
  57022 			v24 = v18 - v20 - v22 + int32(8708)
  57023 			if v24 & ^int32(YUV_MASK2) == 0 {
  57024 				v27 = v24 >> int32(YUV_FIX2)
  57025 			} else {
  57026 				if v24 < 0 {
  57027 					v28 = 0
  57028 				} else {
  57029 					v28 = int32(255)
  57030 				}
  57031 				v27 = v28
  57032 			}
  57033 			v25 = v27
  57034 			goto _222
  57035 		_222:
  57036 			v16 = v25
  57037 			goto _213
  57038 		_213:
  57039 			g = v16
  57040 			v31 = v1 * int32(19077) >> int32(8)
  57041 			goto _228
  57042 		_228:
  57043 			v33 = v2 * int32(33050) >> int32(8)
  57044 			goto _230
  57045 		_230:
  57046 			v35 = v31 + v33 - int32(17685)
  57047 			if v35 & ^int32(YUV_MASK2) == 0 {
  57048 				v38 = v35 >> int32(YUV_FIX2)
  57049 			} else {
  57050 				if v35 < 0 {
  57051 					v39 = 0
  57052 				} else {
  57053 					v39 = int32(255)
  57054 				}
  57055 				v38 = v39
  57056 			}
  57057 			v36 = v38
  57058 			goto _233
  57059 		_233:
  57060 			v29 = v36
  57061 			goto _226
  57062 		_226:
  57063 			b = v29
  57064 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57065 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57066 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57067 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57068 		}
  57069 		tl_uv = t_uv
  57070 		l_uv = uv
  57071 		goto _79
  57072 	_79:
  57073 		;
  57074 		x = x + 1
  57075 	}
  57076 	if !(len1&libc.Int32FromInt32(1) != 0) {
  57077 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  57078 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  57079 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  57080 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  57081 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  57082 		v7 = v1 * int32(19077) >> int32(8)
  57083 		goto _243
  57084 	_243:
  57085 		v9 = v3 * int32(26149) >> int32(8)
  57086 		goto _245
  57087 	_245:
  57088 		v11 = v7 + v9 - int32(14234)
  57089 		if v11 & ^int32(YUV_MASK2) == 0 {
  57090 			v14 = v11 >> int32(YUV_FIX2)
  57091 		} else {
  57092 			if v11 < 0 {
  57093 				v15 = 0
  57094 			} else {
  57095 				v15 = int32(255)
  57096 			}
  57097 			v14 = v15
  57098 		}
  57099 		v12 = v14
  57100 		goto _248
  57101 	_248:
  57102 		v5 = v12
  57103 		goto _241
  57104 	_241:
  57105 		r = v5
  57106 		v18 = v1 * int32(19077) >> int32(8)
  57107 		goto _254
  57108 	_254:
  57109 		v20 = v2 * int32(6419) >> int32(8)
  57110 		goto _256
  57111 	_256:
  57112 		v22 = v3 * int32(13320) >> int32(8)
  57113 		goto _258
  57114 	_258:
  57115 		v24 = v18 - v20 - v22 + int32(8708)
  57116 		if v24 & ^int32(YUV_MASK2) == 0 {
  57117 			v27 = v24 >> int32(YUV_FIX2)
  57118 		} else {
  57119 			if v24 < 0 {
  57120 				v28 = 0
  57121 			} else {
  57122 				v28 = int32(255)
  57123 			}
  57124 			v27 = v28
  57125 		}
  57126 		v25 = v27
  57127 		goto _261
  57128 	_261:
  57129 		v16 = v25
  57130 		goto _252
  57131 	_252:
  57132 		g = v16
  57133 		v31 = v1 * int32(19077) >> int32(8)
  57134 		goto _267
  57135 	_267:
  57136 		v33 = v2 * int32(33050) >> int32(8)
  57137 		goto _269
  57138 	_269:
  57139 		v35 = v31 + v33 - int32(17685)
  57140 		if v35 & ^int32(YUV_MASK2) == 0 {
  57141 			v38 = v35 >> int32(YUV_FIX2)
  57142 		} else {
  57143 			if v35 < 0 {
  57144 				v39 = 0
  57145 			} else {
  57146 				v39 = int32(255)
  57147 			}
  57148 			v38 = v39
  57149 		}
  57150 		v36 = v38
  57151 		goto _272
  57152 	_272:
  57153 		v29 = v36
  57154 		goto _265
  57155 	_265:
  57156 		b = v29
  57157 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57158 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57159 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57160 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57161 		if bottom_y != libc.UintptrFromInt32(0) {
  57162 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  57163 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  57164 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  57165 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  57166 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  57167 			v7 = v1 * int32(19077) >> int32(8)
  57168 			goto _282
  57169 		_282:
  57170 			v9 = v3 * int32(26149) >> int32(8)
  57171 			goto _284
  57172 		_284:
  57173 			v11 = v7 + v9 - int32(14234)
  57174 			if v11 & ^int32(YUV_MASK2) == 0 {
  57175 				v14 = v11 >> int32(YUV_FIX2)
  57176 			} else {
  57177 				if v11 < 0 {
  57178 					v15 = 0
  57179 				} else {
  57180 					v15 = int32(255)
  57181 				}
  57182 				v14 = v15
  57183 			}
  57184 			v12 = v14
  57185 			goto _287
  57186 		_287:
  57187 			v5 = v12
  57188 			goto _280
  57189 		_280:
  57190 			r = v5
  57191 			v18 = v1 * int32(19077) >> int32(8)
  57192 			goto _293
  57193 		_293:
  57194 			v20 = v2 * int32(6419) >> int32(8)
  57195 			goto _295
  57196 		_295:
  57197 			v22 = v3 * int32(13320) >> int32(8)
  57198 			goto _297
  57199 		_297:
  57200 			v24 = v18 - v20 - v22 + int32(8708)
  57201 			if v24 & ^int32(YUV_MASK2) == 0 {
  57202 				v27 = v24 >> int32(YUV_FIX2)
  57203 			} else {
  57204 				if v24 < 0 {
  57205 					v28 = 0
  57206 				} else {
  57207 					v28 = int32(255)
  57208 				}
  57209 				v27 = v28
  57210 			}
  57211 			v25 = v27
  57212 			goto _300
  57213 		_300:
  57214 			v16 = v25
  57215 			goto _291
  57216 		_291:
  57217 			g = v16
  57218 			v31 = v1 * int32(19077) >> int32(8)
  57219 			goto _306
  57220 		_306:
  57221 			v33 = v2 * int32(33050) >> int32(8)
  57222 			goto _308
  57223 		_308:
  57224 			v35 = v31 + v33 - int32(17685)
  57225 			if v35 & ^int32(YUV_MASK2) == 0 {
  57226 				v38 = v35 >> int32(YUV_FIX2)
  57227 			} else {
  57228 				if v35 < 0 {
  57229 					v39 = 0
  57230 				} else {
  57231 					v39 = int32(255)
  57232 				}
  57233 				v38 = v39
  57234 			}
  57235 			v36 = v38
  57236 			goto _311
  57237 		_311:
  57238 			v29 = v36
  57239 			goto _304
  57240 		_304:
  57241 			b = v29
  57242 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57243 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57244 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57245 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57246 		}
  57247 	}
  57248 }
  57249 
  57250 //------------------------------------------------------------------------------
  57251 
  57252 func WebPGetLinePairConverter(tls *libc.TLS, alpha_is_last int32) (r WebPUpsampleLinePairFunc) {
  57253 	var v1 int32
  57254 	_ = v1
  57255 	WebPInitUpsamplers(tls)
  57256 	if alpha_is_last != 0 {
  57257 		v1 = int32(MODE_BGRA)
  57258 	} else {
  57259 		v1 = int32(MODE_ARGB)
  57260 	}
  57261 	return WebPUpsamplers[v1]
  57262 }
  57263 
  57264 func WebPYuv444ToRgba_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57265 	var i, v11, v13, v14, v16, v17, v18, v20, v22, v24, v26, v27, v29, v3, v30, v31, v33, v35, v37, v38, v4, v40, v41, v5, v7, v9 int32
  57266 	var v2, v61 uintptr
  57267 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, v11, v13, v14, v16, v17, v18, v2, v20, v22, v24, v26, v27, v29, v3, v30, v31, v33, v35, v37, v38, v4, v40, v41, v5, v61, v7, v9
  57268 	i = 0
  57269 	for {
  57270 		if !(i < len1) {
  57271 			break
  57272 		}
  57273 		v2 = dst + uintptr(i*int32(4))
  57274 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57275 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57276 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57277 		v61 = v2
  57278 		v9 = v3 * int32(19077) >> int32(8)
  57279 		goto _10
  57280 	_10:
  57281 		v11 = v5 * int32(26149) >> int32(8)
  57282 		goto _12
  57283 	_12:
  57284 		v13 = v9 + v11 - int32(14234)
  57285 		if v13 & ^int32(YUV_MASK2) == 0 {
  57286 			v16 = v13 >> int32(YUV_FIX2)
  57287 		} else {
  57288 			if v13 < 0 {
  57289 				v17 = 0
  57290 			} else {
  57291 				v17 = int32(255)
  57292 			}
  57293 			v16 = v17
  57294 		}
  57295 		v14 = v16
  57296 		goto _15
  57297 	_15:
  57298 		v7 = v14
  57299 		goto _8
  57300 	_8:
  57301 		**(**uint8_t)(__ccgo_up(v61)) = libc.Uint8FromInt32(v7)
  57302 		v20 = v3 * int32(19077) >> int32(8)
  57303 		goto _21
  57304 	_21:
  57305 		v22 = v4 * int32(6419) >> int32(8)
  57306 		goto _23
  57307 	_23:
  57308 		v24 = v5 * int32(13320) >> int32(8)
  57309 		goto _25
  57310 	_25:
  57311 		v26 = v20 - v22 - v24 + int32(8708)
  57312 		if v26 & ^int32(YUV_MASK2) == 0 {
  57313 			v29 = v26 >> int32(YUV_FIX2)
  57314 		} else {
  57315 			if v26 < 0 {
  57316 				v30 = 0
  57317 			} else {
  57318 				v30 = int32(255)
  57319 			}
  57320 			v29 = v30
  57321 		}
  57322 		v27 = v29
  57323 		goto _28
  57324 	_28:
  57325 		v18 = v27
  57326 		goto _19
  57327 	_19:
  57328 		**(**uint8_t)(__ccgo_up(v61 + 1)) = libc.Uint8FromInt32(v18)
  57329 		v33 = v3 * int32(19077) >> int32(8)
  57330 		goto _34
  57331 	_34:
  57332 		v35 = v4 * int32(33050) >> int32(8)
  57333 		goto _36
  57334 	_36:
  57335 		v37 = v33 + v35 - int32(17685)
  57336 		if v37 & ^int32(YUV_MASK2) == 0 {
  57337 			v40 = v37 >> int32(YUV_FIX2)
  57338 		} else {
  57339 			if v37 < 0 {
  57340 				v41 = 0
  57341 			} else {
  57342 				v41 = int32(255)
  57343 			}
  57344 			v40 = v41
  57345 		}
  57346 		v38 = v40
  57347 		goto _39
  57348 	_39:
  57349 		v31 = v38
  57350 		goto _32
  57351 	_32:
  57352 		**(**uint8_t)(__ccgo_up(v61 + 2)) = libc.Uint8FromInt32(v31)
  57353 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57354 		goto _1
  57355 	_1:
  57356 		;
  57357 		i = i + 1
  57358 	}
  57359 }
  57360 
  57361 func WebPYuv444ToBgra_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57362 	var i, v11, v13, v14, v16, v17, v18, v20, v22, v24, v26, v27, v29, v3, v30, v31, v33, v35, v37, v38, v4, v40, v41, v5, v7, v9 int32
  57363 	var v2, v61 uintptr
  57364 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, v11, v13, v14, v16, v17, v18, v2, v20, v22, v24, v26, v27, v29, v3, v30, v31, v33, v35, v37, v38, v4, v40, v41, v5, v61, v7, v9
  57365 	i = 0
  57366 	for {
  57367 		if !(i < len1) {
  57368 			break
  57369 		}
  57370 		v2 = dst + uintptr(i*int32(4))
  57371 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57372 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57373 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57374 		v61 = v2
  57375 		v9 = v3 * int32(19077) >> int32(8)
  57376 		goto _10
  57377 	_10:
  57378 		v11 = v4 * int32(33050) >> int32(8)
  57379 		goto _12
  57380 	_12:
  57381 		v13 = v9 + v11 - int32(17685)
  57382 		if v13 & ^int32(YUV_MASK2) == 0 {
  57383 			v16 = v13 >> int32(YUV_FIX2)
  57384 		} else {
  57385 			if v13 < 0 {
  57386 				v17 = 0
  57387 			} else {
  57388 				v17 = int32(255)
  57389 			}
  57390 			v16 = v17
  57391 		}
  57392 		v14 = v16
  57393 		goto _15
  57394 	_15:
  57395 		v7 = v14
  57396 		goto _8
  57397 	_8:
  57398 		**(**uint8_t)(__ccgo_up(v61)) = libc.Uint8FromInt32(v7)
  57399 		v20 = v3 * int32(19077) >> int32(8)
  57400 		goto _21
  57401 	_21:
  57402 		v22 = v4 * int32(6419) >> int32(8)
  57403 		goto _23
  57404 	_23:
  57405 		v24 = v5 * int32(13320) >> int32(8)
  57406 		goto _25
  57407 	_25:
  57408 		v26 = v20 - v22 - v24 + int32(8708)
  57409 		if v26 & ^int32(YUV_MASK2) == 0 {
  57410 			v29 = v26 >> int32(YUV_FIX2)
  57411 		} else {
  57412 			if v26 < 0 {
  57413 				v30 = 0
  57414 			} else {
  57415 				v30 = int32(255)
  57416 			}
  57417 			v29 = v30
  57418 		}
  57419 		v27 = v29
  57420 		goto _28
  57421 	_28:
  57422 		v18 = v27
  57423 		goto _19
  57424 	_19:
  57425 		**(**uint8_t)(__ccgo_up(v61 + 1)) = libc.Uint8FromInt32(v18)
  57426 		v33 = v3 * int32(19077) >> int32(8)
  57427 		goto _34
  57428 	_34:
  57429 		v35 = v5 * int32(26149) >> int32(8)
  57430 		goto _36
  57431 	_36:
  57432 		v37 = v33 + v35 - int32(14234)
  57433 		if v37 & ^int32(YUV_MASK2) == 0 {
  57434 			v40 = v37 >> int32(YUV_FIX2)
  57435 		} else {
  57436 			if v37 < 0 {
  57437 				v41 = 0
  57438 			} else {
  57439 				v41 = int32(255)
  57440 			}
  57441 			v40 = v41
  57442 		}
  57443 		v38 = v40
  57444 		goto _39
  57445 	_39:
  57446 		v31 = v38
  57447 		goto _32
  57448 	_32:
  57449 		**(**uint8_t)(__ccgo_up(v61 + 2)) = libc.Uint8FromInt32(v31)
  57450 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57451 		goto _1
  57452 	_1:
  57453 		;
  57454 		i = i + 1
  57455 	}
  57456 }
  57457 
  57458 func WebPYuv444ToRgb_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57459 	var i, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  57460 	var v51 uintptr
  57461 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v51, v6, v8
  57462 	i = 0
  57463 	for {
  57464 		if !(i < len1) {
  57465 			break
  57466 		}
  57467 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57468 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57469 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57470 		v51 = dst + uintptr(i*int32(3))
  57471 		v8 = v2 * int32(19077) >> int32(8)
  57472 		goto _9
  57473 	_9:
  57474 		v10 = v4 * int32(26149) >> int32(8)
  57475 		goto _11
  57476 	_11:
  57477 		v12 = v8 + v10 - int32(14234)
  57478 		if v12 & ^int32(YUV_MASK2) == 0 {
  57479 			v15 = v12 >> int32(YUV_FIX2)
  57480 		} else {
  57481 			if v12 < 0 {
  57482 				v16 = 0
  57483 			} else {
  57484 				v16 = int32(255)
  57485 			}
  57486 			v15 = v16
  57487 		}
  57488 		v13 = v15
  57489 		goto _14
  57490 	_14:
  57491 		v6 = v13
  57492 		goto _7
  57493 	_7:
  57494 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(v6)
  57495 		v19 = v2 * int32(19077) >> int32(8)
  57496 		goto _20
  57497 	_20:
  57498 		v21 = v3 * int32(6419) >> int32(8)
  57499 		goto _22
  57500 	_22:
  57501 		v23 = v4 * int32(13320) >> int32(8)
  57502 		goto _24
  57503 	_24:
  57504 		v25 = v19 - v21 - v23 + int32(8708)
  57505 		if v25 & ^int32(YUV_MASK2) == 0 {
  57506 			v28 = v25 >> int32(YUV_FIX2)
  57507 		} else {
  57508 			if v25 < 0 {
  57509 				v29 = 0
  57510 			} else {
  57511 				v29 = int32(255)
  57512 			}
  57513 			v28 = v29
  57514 		}
  57515 		v26 = v28
  57516 		goto _27
  57517 	_27:
  57518 		v17 = v26
  57519 		goto _18
  57520 	_18:
  57521 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(v17)
  57522 		v32 = v2 * int32(19077) >> int32(8)
  57523 		goto _33
  57524 	_33:
  57525 		v34 = v3 * int32(33050) >> int32(8)
  57526 		goto _35
  57527 	_35:
  57528 		v36 = v32 + v34 - int32(17685)
  57529 		if v36 & ^int32(YUV_MASK2) == 0 {
  57530 			v39 = v36 >> int32(YUV_FIX2)
  57531 		} else {
  57532 			if v36 < 0 {
  57533 				v40 = 0
  57534 			} else {
  57535 				v40 = int32(255)
  57536 			}
  57537 			v39 = v40
  57538 		}
  57539 		v37 = v39
  57540 		goto _38
  57541 	_38:
  57542 		v30 = v37
  57543 		goto _31
  57544 	_31:
  57545 		**(**uint8_t)(__ccgo_up(v51 + 2)) = libc.Uint8FromInt32(v30)
  57546 		goto _1
  57547 	_1:
  57548 		;
  57549 		i = i + 1
  57550 	}
  57551 }
  57552 
  57553 func WebPYuv444ToBgr_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57554 	var i, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  57555 	var v51 uintptr
  57556 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v51, v6, v8
  57557 	i = 0
  57558 	for {
  57559 		if !(i < len1) {
  57560 			break
  57561 		}
  57562 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57563 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57564 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57565 		v51 = dst + uintptr(i*int32(3))
  57566 		v8 = v2 * int32(19077) >> int32(8)
  57567 		goto _9
  57568 	_9:
  57569 		v10 = v3 * int32(33050) >> int32(8)
  57570 		goto _11
  57571 	_11:
  57572 		v12 = v8 + v10 - int32(17685)
  57573 		if v12 & ^int32(YUV_MASK2) == 0 {
  57574 			v15 = v12 >> int32(YUV_FIX2)
  57575 		} else {
  57576 			if v12 < 0 {
  57577 				v16 = 0
  57578 			} else {
  57579 				v16 = int32(255)
  57580 			}
  57581 			v15 = v16
  57582 		}
  57583 		v13 = v15
  57584 		goto _14
  57585 	_14:
  57586 		v6 = v13
  57587 		goto _7
  57588 	_7:
  57589 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(v6)
  57590 		v19 = v2 * int32(19077) >> int32(8)
  57591 		goto _20
  57592 	_20:
  57593 		v21 = v3 * int32(6419) >> int32(8)
  57594 		goto _22
  57595 	_22:
  57596 		v23 = v4 * int32(13320) >> int32(8)
  57597 		goto _24
  57598 	_24:
  57599 		v25 = v19 - v21 - v23 + int32(8708)
  57600 		if v25 & ^int32(YUV_MASK2) == 0 {
  57601 			v28 = v25 >> int32(YUV_FIX2)
  57602 		} else {
  57603 			if v25 < 0 {
  57604 				v29 = 0
  57605 			} else {
  57606 				v29 = int32(255)
  57607 			}
  57608 			v28 = v29
  57609 		}
  57610 		v26 = v28
  57611 		goto _27
  57612 	_27:
  57613 		v17 = v26
  57614 		goto _18
  57615 	_18:
  57616 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(v17)
  57617 		v32 = v2 * int32(19077) >> int32(8)
  57618 		goto _33
  57619 	_33:
  57620 		v34 = v4 * int32(26149) >> int32(8)
  57621 		goto _35
  57622 	_35:
  57623 		v36 = v32 + v34 - int32(14234)
  57624 		if v36 & ^int32(YUV_MASK2) == 0 {
  57625 			v39 = v36 >> int32(YUV_FIX2)
  57626 		} else {
  57627 			if v36 < 0 {
  57628 				v40 = 0
  57629 			} else {
  57630 				v40 = int32(255)
  57631 			}
  57632 			v39 = v40
  57633 		}
  57634 		v37 = v39
  57635 		goto _38
  57636 	_38:
  57637 		v30 = v37
  57638 		goto _31
  57639 	_31:
  57640 		**(**uint8_t)(__ccgo_up(v51 + 2)) = libc.Uint8FromInt32(v30)
  57641 		goto _1
  57642 	_1:
  57643 		;
  57644 		i = i + 1
  57645 	}
  57646 }
  57647 
  57648 func WebPYuv444ToArgb_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57649 	var i, v11, v13, v14, v16, v17, v18, v20, v22, v24, v26, v27, v29, v3, v30, v31, v33, v35, v37, v38, v4, v40, v41, v5, v7, v9 int32
  57650 	var v2, v61 uintptr
  57651 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, v11, v13, v14, v16, v17, v18, v2, v20, v22, v24, v26, v27, v29, v3, v30, v31, v33, v35, v37, v38, v4, v40, v41, v5, v61, v7, v9
  57652 	i = 0
  57653 	for {
  57654 		if !(i < len1) {
  57655 			break
  57656 		}
  57657 		v2 = dst + uintptr(i*int32(4))
  57658 		**(**uint8_t)(__ccgo_up(v2)) = uint8(0xff)
  57659 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57660 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57661 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57662 		v61 = v2 + uintptr(1)
  57663 		v9 = v3 * int32(19077) >> int32(8)
  57664 		goto _10
  57665 	_10:
  57666 		v11 = v5 * int32(26149) >> int32(8)
  57667 		goto _12
  57668 	_12:
  57669 		v13 = v9 + v11 - int32(14234)
  57670 		if v13 & ^int32(YUV_MASK2) == 0 {
  57671 			v16 = v13 >> int32(YUV_FIX2)
  57672 		} else {
  57673 			if v13 < 0 {
  57674 				v17 = 0
  57675 			} else {
  57676 				v17 = int32(255)
  57677 			}
  57678 			v16 = v17
  57679 		}
  57680 		v14 = v16
  57681 		goto _15
  57682 	_15:
  57683 		v7 = v14
  57684 		goto _8
  57685 	_8:
  57686 		**(**uint8_t)(__ccgo_up(v61)) = libc.Uint8FromInt32(v7)
  57687 		v20 = v3 * int32(19077) >> int32(8)
  57688 		goto _21
  57689 	_21:
  57690 		v22 = v4 * int32(6419) >> int32(8)
  57691 		goto _23
  57692 	_23:
  57693 		v24 = v5 * int32(13320) >> int32(8)
  57694 		goto _25
  57695 	_25:
  57696 		v26 = v20 - v22 - v24 + int32(8708)
  57697 		if v26 & ^int32(YUV_MASK2) == 0 {
  57698 			v29 = v26 >> int32(YUV_FIX2)
  57699 		} else {
  57700 			if v26 < 0 {
  57701 				v30 = 0
  57702 			} else {
  57703 				v30 = int32(255)
  57704 			}
  57705 			v29 = v30
  57706 		}
  57707 		v27 = v29
  57708 		goto _28
  57709 	_28:
  57710 		v18 = v27
  57711 		goto _19
  57712 	_19:
  57713 		**(**uint8_t)(__ccgo_up(v61 + 1)) = libc.Uint8FromInt32(v18)
  57714 		v33 = v3 * int32(19077) >> int32(8)
  57715 		goto _34
  57716 	_34:
  57717 		v35 = v4 * int32(33050) >> int32(8)
  57718 		goto _36
  57719 	_36:
  57720 		v37 = v33 + v35 - int32(17685)
  57721 		if v37 & ^int32(YUV_MASK2) == 0 {
  57722 			v40 = v37 >> int32(YUV_FIX2)
  57723 		} else {
  57724 			if v37 < 0 {
  57725 				v41 = 0
  57726 			} else {
  57727 				v41 = int32(255)
  57728 			}
  57729 			v40 = v41
  57730 		}
  57731 		v38 = v40
  57732 		goto _39
  57733 	_39:
  57734 		v31 = v38
  57735 		goto _32
  57736 	_32:
  57737 		**(**uint8_t)(__ccgo_up(v61 + 2)) = libc.Uint8FromInt32(v31)
  57738 		goto _1
  57739 	_1:
  57740 		;
  57741 		i = i + 1
  57742 	}
  57743 }
  57744 
  57745 func WebPYuv444ToRgba4444_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57746 	var b, ba, g, i, r, rg, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  57747 	var v51 uintptr
  57748 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, ba, g, i, r, rg, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v51, v6, v8
  57749 	i = 0
  57750 	for {
  57751 		if !(i < len1) {
  57752 			break
  57753 		}
  57754 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57755 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57756 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57757 		v51 = dst + uintptr(i*int32(2))
  57758 		v8 = v2 * int32(19077) >> int32(8)
  57759 		goto _9
  57760 	_9:
  57761 		v10 = v4 * int32(26149) >> int32(8)
  57762 		goto _11
  57763 	_11:
  57764 		v12 = v8 + v10 - int32(14234)
  57765 		if v12 & ^int32(YUV_MASK2) == 0 {
  57766 			v15 = v12 >> int32(YUV_FIX2)
  57767 		} else {
  57768 			if v12 < 0 {
  57769 				v16 = 0
  57770 			} else {
  57771 				v16 = int32(255)
  57772 			}
  57773 			v15 = v16
  57774 		}
  57775 		v13 = v15
  57776 		goto _14
  57777 	_14:
  57778 		v6 = v13
  57779 		goto _7
  57780 	_7:
  57781 		r = v6
  57782 		v19 = v2 * int32(19077) >> int32(8)
  57783 		goto _20
  57784 	_20:
  57785 		v21 = v3 * int32(6419) >> int32(8)
  57786 		goto _22
  57787 	_22:
  57788 		v23 = v4 * int32(13320) >> int32(8)
  57789 		goto _24
  57790 	_24:
  57791 		v25 = v19 - v21 - v23 + int32(8708)
  57792 		if v25 & ^int32(YUV_MASK2) == 0 {
  57793 			v28 = v25 >> int32(YUV_FIX2)
  57794 		} else {
  57795 			if v25 < 0 {
  57796 				v29 = 0
  57797 			} else {
  57798 				v29 = int32(255)
  57799 			}
  57800 			v28 = v29
  57801 		}
  57802 		v26 = v28
  57803 		goto _27
  57804 	_27:
  57805 		v17 = v26
  57806 		goto _18
  57807 	_18:
  57808 		g = v17
  57809 		v32 = v2 * int32(19077) >> int32(8)
  57810 		goto _33
  57811 	_33:
  57812 		v34 = v3 * int32(33050) >> int32(8)
  57813 		goto _35
  57814 	_35:
  57815 		v36 = v32 + v34 - int32(17685)
  57816 		if v36 & ^int32(YUV_MASK2) == 0 {
  57817 			v39 = v36 >> int32(YUV_FIX2)
  57818 		} else {
  57819 			if v36 < 0 {
  57820 				v40 = 0
  57821 			} else {
  57822 				v40 = int32(255)
  57823 			}
  57824 			v39 = v40
  57825 		}
  57826 		v37 = v39
  57827 		goto _38
  57828 	_38:
  57829 		v30 = v37
  57830 		goto _31
  57831 	_31:
  57832 		b = v30
  57833 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  57834 		ba = b&int32(0xf0) | int32(0x0f)
  57835 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(rg)
  57836 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(ba)
  57837 		goto _1
  57838 	_1:
  57839 		;
  57840 		i = i + 1
  57841 	}
  57842 }
  57843 
  57844 func WebPYuv444ToRgb565_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57845 	var b, g, gb, i, r, rg, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v6, v8 int32
  57846 	var v51 uintptr
  57847 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, g, gb, i, r, rg, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v51, v6, v8
  57848 	i = 0
  57849 	for {
  57850 		if !(i < len1) {
  57851 			break
  57852 		}
  57853 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57854 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57855 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57856 		v51 = dst + uintptr(i*int32(2))
  57857 		v8 = v2 * int32(19077) >> int32(8)
  57858 		goto _9
  57859 	_9:
  57860 		v10 = v4 * int32(26149) >> int32(8)
  57861 		goto _11
  57862 	_11:
  57863 		v12 = v8 + v10 - int32(14234)
  57864 		if v12 & ^int32(YUV_MASK2) == 0 {
  57865 			v15 = v12 >> int32(YUV_FIX2)
  57866 		} else {
  57867 			if v12 < 0 {
  57868 				v16 = 0
  57869 			} else {
  57870 				v16 = int32(255)
  57871 			}
  57872 			v15 = v16
  57873 		}
  57874 		v13 = v15
  57875 		goto _14
  57876 	_14:
  57877 		v6 = v13
  57878 		goto _7
  57879 	_7:
  57880 		r = v6
  57881 		v19 = v2 * int32(19077) >> int32(8)
  57882 		goto _20
  57883 	_20:
  57884 		v21 = v3 * int32(6419) >> int32(8)
  57885 		goto _22
  57886 	_22:
  57887 		v23 = v4 * int32(13320) >> int32(8)
  57888 		goto _24
  57889 	_24:
  57890 		v25 = v19 - v21 - v23 + int32(8708)
  57891 		if v25 & ^int32(YUV_MASK2) == 0 {
  57892 			v28 = v25 >> int32(YUV_FIX2)
  57893 		} else {
  57894 			if v25 < 0 {
  57895 				v29 = 0
  57896 			} else {
  57897 				v29 = int32(255)
  57898 			}
  57899 			v28 = v29
  57900 		}
  57901 		v26 = v28
  57902 		goto _27
  57903 	_27:
  57904 		v17 = v26
  57905 		goto _18
  57906 	_18:
  57907 		g = v17
  57908 		v32 = v2 * int32(19077) >> int32(8)
  57909 		goto _33
  57910 	_33:
  57911 		v34 = v3 * int32(33050) >> int32(8)
  57912 		goto _35
  57913 	_35:
  57914 		v36 = v32 + v34 - int32(17685)
  57915 		if v36 & ^int32(YUV_MASK2) == 0 {
  57916 			v39 = v36 >> int32(YUV_FIX2)
  57917 		} else {
  57918 			if v36 < 0 {
  57919 				v40 = 0
  57920 			} else {
  57921 				v40 = int32(255)
  57922 			}
  57923 			v39 = v40
  57924 		}
  57925 		v37 = v39
  57926 		goto _38
  57927 	_38:
  57928 		v30 = v37
  57929 		goto _31
  57930 	_31:
  57931 		b = v30
  57932 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57933 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57934 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(rg)
  57935 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(gb)
  57936 		goto _1
  57937 	_1:
  57938 		;
  57939 		i = i + 1
  57940 	}
  57941 }
  57942 
  57943 func WebPInitYUV444Converters(tls *libc.TLS) {
  57944 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  57945 		goto _1
  57946 	}
  57947 	WebPInitYUV444Converters_body(tls)
  57948 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)), VP8GetCPUInfo)
  57949 	goto _2
  57950 _2:
  57951 	;
  57952 	goto _1
  57953 _1: /**/ //
  57954 }
  57955 
  57956 var WebPInitYUV444Converters_body_last_cpuinfo_used = uintptr(0)
  57957 
  57958 func init() {
  57959 	p := unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)
  57960 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))
  57961 }
  57962 
  57963 func WebPInitYUV444Converters_body(tls *libc.TLS) {
  57964 	WebPYUV444Converters[int32(MODE_RGBA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  57965 	WebPYUV444Converters[int32(MODE_BGRA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  57966 	WebPYUV444Converters[int32(MODE_RGB)] = __ccgo_fp(WebPYuv444ToRgb_C)
  57967 	WebPYUV444Converters[int32(MODE_BGR)] = __ccgo_fp(WebPYuv444ToBgr_C)
  57968 	WebPYUV444Converters[int32(MODE_ARGB)] = __ccgo_fp(WebPYuv444ToArgb_C)
  57969 	WebPYUV444Converters[int32(MODE_RGBA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  57970 	WebPYUV444Converters[int32(MODE_RGB_565)] = __ccgo_fp(WebPYuv444ToRgb565_C)
  57971 	WebPYUV444Converters[int32(MODE_rgbA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  57972 	WebPYUV444Converters[int32(MODE_bgrA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  57973 	WebPYUV444Converters[int32(MODE_Argb)] = __ccgo_fp(WebPYuv444ToArgb_C)
  57974 	WebPYUV444Converters[int32(MODE_rgbA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  57975 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  57976 	}
  57977 }
  57978 
  57979 func WebPInitUpsamplers(tls *libc.TLS) {
  57980 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  57981 		goto _1
  57982 	}
  57983 	WebPInitUpsamplers_body(tls)
  57984 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  57985 	goto _2
  57986 _2:
  57987 	;
  57988 	goto _1
  57989 _1: /**/ //
  57990 }
  57991 
  57992 var WebPInitUpsamplers_body_last_cpuinfo_used = uintptr(0)
  57993 
  57994 func init() {
  57995 	p := unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)
  57996 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))
  57997 }
  57998 
  57999 func WebPInitUpsamplers_body(tls *libc.TLS) {
  58000 	WebPUpsamplers[int32(MODE_RGBA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58001 	WebPUpsamplers[int32(MODE_BGRA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58002 	WebPUpsamplers[int32(MODE_rgbA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58003 	WebPUpsamplers[int32(MODE_bgrA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58004 	WebPUpsamplers[int32(MODE_RGB)] = __ccgo_fp(UpsampleRgbLinePair_C)
  58005 	WebPUpsamplers[int32(MODE_BGR)] = __ccgo_fp(UpsampleBgrLinePair_C)
  58006 	WebPUpsamplers[int32(MODE_ARGB)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58007 	WebPUpsamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58008 	WebPUpsamplers[int32(MODE_RGB_565)] = __ccgo_fp(UpsampleRgb565LinePair_C)
  58009 	WebPUpsamplers[int32(MODE_Argb)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58010 	WebPUpsamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58011 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  58012 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58013 	}
  58014 }
  58015 
  58016 func WebPInitYUV444ConvertersMIPSdspR2(tls *libc.TLS) {
  58017 }
  58018 
  58019 func WebPInitUpsamplersMIPSdspR2(tls *libc.TLS) {
  58020 }
  58021 
  58022 func WebPInitUpsamplersMSA(tls *libc.TLS) {
  58023 }
  58024 
  58025 func WebPInitUpsamplersNEON(tls *libc.TLS) {
  58026 }
  58027 
  58028 func WebPInitYUV444ConvertersSSE2(tls *libc.TLS) {
  58029 }
  58030 
  58031 func WebPInitUpsamplersSSE2(tls *libc.TLS) {
  58032 }
  58033 
  58034 func WebPInitYUV444ConvertersSSE41(tls *libc.TLS) {
  58035 }
  58036 
  58037 func WebPInitUpsamplersSSE41(tls *libc.TLS) {
  58038 }
  58039 
  58040 // Copyright 2010 Google Inc. All Rights Reserved.
  58041 //
  58042 // Use of this source code is governed by a BSD-style license
  58043 // that can be found in the COPYING file in the root of the source
  58044 // tree. An additional intellectual property rights grant can be found
  58045 // in the file PATENTS. All contributing project authors may
  58046 // be found in the AUTHORS file in the root of the source tree.
  58047 // -----------------------------------------------------------------------------
  58048 //
  58049 //  Main decoding functions for WebP images.
  58050 //
  58051 // Author: Skal (pascal.massimino@gmail.com)
  58052 
  58053 //-----------------------------------------------------------------------------
  58054 // Plain-C version
  58055 
  58056 // C documentation
  58057 //
  58058 //	// All variants implemented.
  58059 func YuvToRgbRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58060 	var end, v4 uintptr
  58061 	var v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v51, v7, v9 int32
  58062 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = end, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v51, v7, v9
  58063 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58064 	for dst != end {
  58065 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58066 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58067 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58068 		v4 = dst
  58069 		v7 = v1 * int32(19077) >> int32(8)
  58070 		goto _8
  58071 	_8:
  58072 		v9 = v3 * int32(26149) >> int32(8)
  58073 		goto _10
  58074 	_10:
  58075 		v11 = v7 + v9 - int32(14234)
  58076 		if v11 & ^int32(YUV_MASK2) == 0 {
  58077 			v14 = v11 >> int32(YUV_FIX2)
  58078 		} else {
  58079 			if v11 < 0 {
  58080 				v15 = 0
  58081 			} else {
  58082 				v15 = int32(255)
  58083 			}
  58084 			v14 = v15
  58085 		}
  58086 		v12 = v14
  58087 		goto _13
  58088 	_13:
  58089 		v51 = v12
  58090 		goto _6
  58091 	_6:
  58092 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58093 		v18 = v1 * int32(19077) >> int32(8)
  58094 		goto _19
  58095 	_19:
  58096 		v20 = v2 * int32(6419) >> int32(8)
  58097 		goto _21
  58098 	_21:
  58099 		v22 = v3 * int32(13320) >> int32(8)
  58100 		goto _23
  58101 	_23:
  58102 		v24 = v18 - v20 - v22 + int32(8708)
  58103 		if v24 & ^int32(YUV_MASK2) == 0 {
  58104 			v27 = v24 >> int32(YUV_FIX2)
  58105 		} else {
  58106 			if v24 < 0 {
  58107 				v28 = 0
  58108 			} else {
  58109 				v28 = int32(255)
  58110 			}
  58111 			v27 = v28
  58112 		}
  58113 		v25 = v27
  58114 		goto _26
  58115 	_26:
  58116 		v16 = v25
  58117 		goto _17
  58118 	_17:
  58119 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58120 		v31 = v1 * int32(19077) >> int32(8)
  58121 		goto _32
  58122 	_32:
  58123 		v33 = v2 * int32(33050) >> int32(8)
  58124 		goto _34
  58125 	_34:
  58126 		v35 = v31 + v33 - int32(17685)
  58127 		if v35 & ^int32(YUV_MASK2) == 0 {
  58128 			v38 = v35 >> int32(YUV_FIX2)
  58129 		} else {
  58130 			if v35 < 0 {
  58131 				v39 = 0
  58132 			} else {
  58133 				v39 = int32(255)
  58134 			}
  58135 			v38 = v39
  58136 		}
  58137 		v36 = v38
  58138 		goto _37
  58139 	_37:
  58140 		v29 = v36
  58141 		goto _30
  58142 	_30:
  58143 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58144 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58145 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58146 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58147 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58148 		v7 = v1 * int32(19077) >> int32(8)
  58149 		goto _47
  58150 	_47:
  58151 		v9 = v3 * int32(26149) >> int32(8)
  58152 		goto _49
  58153 	_49:
  58154 		v11 = v7 + v9 - int32(14234)
  58155 		if v11 & ^int32(YUV_MASK2) == 0 {
  58156 			v14 = v11 >> int32(YUV_FIX2)
  58157 		} else {
  58158 			if v11 < 0 {
  58159 				v15 = 0
  58160 			} else {
  58161 				v15 = int32(255)
  58162 			}
  58163 			v14 = v15
  58164 		}
  58165 		v12 = v14
  58166 		goto _52
  58167 	_52:
  58168 		v51 = v12
  58169 		goto _45
  58170 	_45:
  58171 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58172 		v18 = v1 * int32(19077) >> int32(8)
  58173 		goto _58
  58174 	_58:
  58175 		v20 = v2 * int32(6419) >> int32(8)
  58176 		goto _60
  58177 	_60:
  58178 		v22 = v3 * int32(13320) >> int32(8)
  58179 		goto _62
  58180 	_62:
  58181 		v24 = v18 - v20 - v22 + int32(8708)
  58182 		if v24 & ^int32(YUV_MASK2) == 0 {
  58183 			v27 = v24 >> int32(YUV_FIX2)
  58184 		} else {
  58185 			if v24 < 0 {
  58186 				v28 = 0
  58187 			} else {
  58188 				v28 = int32(255)
  58189 			}
  58190 			v27 = v28
  58191 		}
  58192 		v25 = v27
  58193 		goto _65
  58194 	_65:
  58195 		v16 = v25
  58196 		goto _56
  58197 	_56:
  58198 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58199 		v31 = v1 * int32(19077) >> int32(8)
  58200 		goto _71
  58201 	_71:
  58202 		v33 = v2 * int32(33050) >> int32(8)
  58203 		goto _73
  58204 	_73:
  58205 		v35 = v31 + v33 - int32(17685)
  58206 		if v35 & ^int32(YUV_MASK2) == 0 {
  58207 			v38 = v35 >> int32(YUV_FIX2)
  58208 		} else {
  58209 			if v35 < 0 {
  58210 				v39 = 0
  58211 			} else {
  58212 				v39 = int32(255)
  58213 			}
  58214 			v38 = v39
  58215 		}
  58216 		v36 = v38
  58217 		goto _76
  58218 	_76:
  58219 		v29 = v36
  58220 		goto _69
  58221 	_69:
  58222 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58223 		y4 = y4 + uintptr(2)
  58224 		u3 = u3 + 1
  58225 		v5 = v5 + 1
  58226 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58227 	}
  58228 	if len1&int32(1) != 0 {
  58229 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58230 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58231 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58232 		v4 = dst
  58233 		v7 = v1 * int32(19077) >> int32(8)
  58234 		goto _86
  58235 	_86:
  58236 		v9 = v3 * int32(26149) >> int32(8)
  58237 		goto _88
  58238 	_88:
  58239 		v11 = v7 + v9 - int32(14234)
  58240 		if v11 & ^int32(YUV_MASK2) == 0 {
  58241 			v14 = v11 >> int32(YUV_FIX2)
  58242 		} else {
  58243 			if v11 < 0 {
  58244 				v15 = 0
  58245 			} else {
  58246 				v15 = int32(255)
  58247 			}
  58248 			v14 = v15
  58249 		}
  58250 		v12 = v14
  58251 		goto _91
  58252 	_91:
  58253 		v51 = v12
  58254 		goto _84
  58255 	_84:
  58256 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58257 		v18 = v1 * int32(19077) >> int32(8)
  58258 		goto _97
  58259 	_97:
  58260 		v20 = v2 * int32(6419) >> int32(8)
  58261 		goto _99
  58262 	_99:
  58263 		v22 = v3 * int32(13320) >> int32(8)
  58264 		goto _101
  58265 	_101:
  58266 		v24 = v18 - v20 - v22 + int32(8708)
  58267 		if v24 & ^int32(YUV_MASK2) == 0 {
  58268 			v27 = v24 >> int32(YUV_FIX2)
  58269 		} else {
  58270 			if v24 < 0 {
  58271 				v28 = 0
  58272 			} else {
  58273 				v28 = int32(255)
  58274 			}
  58275 			v27 = v28
  58276 		}
  58277 		v25 = v27
  58278 		goto _104
  58279 	_104:
  58280 		v16 = v25
  58281 		goto _95
  58282 	_95:
  58283 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58284 		v31 = v1 * int32(19077) >> int32(8)
  58285 		goto _110
  58286 	_110:
  58287 		v33 = v2 * int32(33050) >> int32(8)
  58288 		goto _112
  58289 	_112:
  58290 		v35 = v31 + v33 - int32(17685)
  58291 		if v35 & ^int32(YUV_MASK2) == 0 {
  58292 			v38 = v35 >> int32(YUV_FIX2)
  58293 		} else {
  58294 			if v35 < 0 {
  58295 				v39 = 0
  58296 			} else {
  58297 				v39 = int32(255)
  58298 			}
  58299 			v38 = v39
  58300 		}
  58301 		v36 = v38
  58302 		goto _115
  58303 	_115:
  58304 		v29 = v36
  58305 		goto _108
  58306 	_108:
  58307 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58308 	}
  58309 }
  58310 
  58311 func YuvToBgrRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58312 	var end, v4 uintptr
  58313 	var v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v51, v7, v9 int32
  58314 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = end, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v51, v7, v9
  58315 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58316 	for dst != end {
  58317 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58318 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58319 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58320 		v4 = dst
  58321 		v7 = v1 * int32(19077) >> int32(8)
  58322 		goto _8
  58323 	_8:
  58324 		v9 = v2 * int32(33050) >> int32(8)
  58325 		goto _10
  58326 	_10:
  58327 		v11 = v7 + v9 - int32(17685)
  58328 		if v11 & ^int32(YUV_MASK2) == 0 {
  58329 			v14 = v11 >> int32(YUV_FIX2)
  58330 		} else {
  58331 			if v11 < 0 {
  58332 				v15 = 0
  58333 			} else {
  58334 				v15 = int32(255)
  58335 			}
  58336 			v14 = v15
  58337 		}
  58338 		v12 = v14
  58339 		goto _13
  58340 	_13:
  58341 		v51 = v12
  58342 		goto _6
  58343 	_6:
  58344 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58345 		v18 = v1 * int32(19077) >> int32(8)
  58346 		goto _19
  58347 	_19:
  58348 		v20 = v2 * int32(6419) >> int32(8)
  58349 		goto _21
  58350 	_21:
  58351 		v22 = v3 * int32(13320) >> int32(8)
  58352 		goto _23
  58353 	_23:
  58354 		v24 = v18 - v20 - v22 + int32(8708)
  58355 		if v24 & ^int32(YUV_MASK2) == 0 {
  58356 			v27 = v24 >> int32(YUV_FIX2)
  58357 		} else {
  58358 			if v24 < 0 {
  58359 				v28 = 0
  58360 			} else {
  58361 				v28 = int32(255)
  58362 			}
  58363 			v27 = v28
  58364 		}
  58365 		v25 = v27
  58366 		goto _26
  58367 	_26:
  58368 		v16 = v25
  58369 		goto _17
  58370 	_17:
  58371 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58372 		v31 = v1 * int32(19077) >> int32(8)
  58373 		goto _32
  58374 	_32:
  58375 		v33 = v3 * int32(26149) >> int32(8)
  58376 		goto _34
  58377 	_34:
  58378 		v35 = v31 + v33 - int32(14234)
  58379 		if v35 & ^int32(YUV_MASK2) == 0 {
  58380 			v38 = v35 >> int32(YUV_FIX2)
  58381 		} else {
  58382 			if v35 < 0 {
  58383 				v39 = 0
  58384 			} else {
  58385 				v39 = int32(255)
  58386 			}
  58387 			v38 = v39
  58388 		}
  58389 		v36 = v38
  58390 		goto _37
  58391 	_37:
  58392 		v29 = v36
  58393 		goto _30
  58394 	_30:
  58395 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58396 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58397 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58398 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58399 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58400 		v7 = v1 * int32(19077) >> int32(8)
  58401 		goto _47
  58402 	_47:
  58403 		v9 = v2 * int32(33050) >> int32(8)
  58404 		goto _49
  58405 	_49:
  58406 		v11 = v7 + v9 - int32(17685)
  58407 		if v11 & ^int32(YUV_MASK2) == 0 {
  58408 			v14 = v11 >> int32(YUV_FIX2)
  58409 		} else {
  58410 			if v11 < 0 {
  58411 				v15 = 0
  58412 			} else {
  58413 				v15 = int32(255)
  58414 			}
  58415 			v14 = v15
  58416 		}
  58417 		v12 = v14
  58418 		goto _52
  58419 	_52:
  58420 		v51 = v12
  58421 		goto _45
  58422 	_45:
  58423 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58424 		v18 = v1 * int32(19077) >> int32(8)
  58425 		goto _58
  58426 	_58:
  58427 		v20 = v2 * int32(6419) >> int32(8)
  58428 		goto _60
  58429 	_60:
  58430 		v22 = v3 * int32(13320) >> int32(8)
  58431 		goto _62
  58432 	_62:
  58433 		v24 = v18 - v20 - v22 + int32(8708)
  58434 		if v24 & ^int32(YUV_MASK2) == 0 {
  58435 			v27 = v24 >> int32(YUV_FIX2)
  58436 		} else {
  58437 			if v24 < 0 {
  58438 				v28 = 0
  58439 			} else {
  58440 				v28 = int32(255)
  58441 			}
  58442 			v27 = v28
  58443 		}
  58444 		v25 = v27
  58445 		goto _65
  58446 	_65:
  58447 		v16 = v25
  58448 		goto _56
  58449 	_56:
  58450 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58451 		v31 = v1 * int32(19077) >> int32(8)
  58452 		goto _71
  58453 	_71:
  58454 		v33 = v3 * int32(26149) >> int32(8)
  58455 		goto _73
  58456 	_73:
  58457 		v35 = v31 + v33 - int32(14234)
  58458 		if v35 & ^int32(YUV_MASK2) == 0 {
  58459 			v38 = v35 >> int32(YUV_FIX2)
  58460 		} else {
  58461 			if v35 < 0 {
  58462 				v39 = 0
  58463 			} else {
  58464 				v39 = int32(255)
  58465 			}
  58466 			v38 = v39
  58467 		}
  58468 		v36 = v38
  58469 		goto _76
  58470 	_76:
  58471 		v29 = v36
  58472 		goto _69
  58473 	_69:
  58474 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58475 		y4 = y4 + uintptr(2)
  58476 		u3 = u3 + 1
  58477 		v5 = v5 + 1
  58478 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58479 	}
  58480 	if len1&int32(1) != 0 {
  58481 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58482 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58483 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58484 		v4 = dst
  58485 		v7 = v1 * int32(19077) >> int32(8)
  58486 		goto _86
  58487 	_86:
  58488 		v9 = v2 * int32(33050) >> int32(8)
  58489 		goto _88
  58490 	_88:
  58491 		v11 = v7 + v9 - int32(17685)
  58492 		if v11 & ^int32(YUV_MASK2) == 0 {
  58493 			v14 = v11 >> int32(YUV_FIX2)
  58494 		} else {
  58495 			if v11 < 0 {
  58496 				v15 = 0
  58497 			} else {
  58498 				v15 = int32(255)
  58499 			}
  58500 			v14 = v15
  58501 		}
  58502 		v12 = v14
  58503 		goto _91
  58504 	_91:
  58505 		v51 = v12
  58506 		goto _84
  58507 	_84:
  58508 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58509 		v18 = v1 * int32(19077) >> int32(8)
  58510 		goto _97
  58511 	_97:
  58512 		v20 = v2 * int32(6419) >> int32(8)
  58513 		goto _99
  58514 	_99:
  58515 		v22 = v3 * int32(13320) >> int32(8)
  58516 		goto _101
  58517 	_101:
  58518 		v24 = v18 - v20 - v22 + int32(8708)
  58519 		if v24 & ^int32(YUV_MASK2) == 0 {
  58520 			v27 = v24 >> int32(YUV_FIX2)
  58521 		} else {
  58522 			if v24 < 0 {
  58523 				v28 = 0
  58524 			} else {
  58525 				v28 = int32(255)
  58526 			}
  58527 			v27 = v28
  58528 		}
  58529 		v25 = v27
  58530 		goto _104
  58531 	_104:
  58532 		v16 = v25
  58533 		goto _95
  58534 	_95:
  58535 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58536 		v31 = v1 * int32(19077) >> int32(8)
  58537 		goto _110
  58538 	_110:
  58539 		v33 = v3 * int32(26149) >> int32(8)
  58540 		goto _112
  58541 	_112:
  58542 		v35 = v31 + v33 - int32(14234)
  58543 		if v35 & ^int32(YUV_MASK2) == 0 {
  58544 			v38 = v35 >> int32(YUV_FIX2)
  58545 		} else {
  58546 			if v35 < 0 {
  58547 				v39 = 0
  58548 			} else {
  58549 				v39 = int32(255)
  58550 			}
  58551 			v38 = v39
  58552 		}
  58553 		v36 = v38
  58554 		goto _115
  58555 	_115:
  58556 		v29 = v36
  58557 		goto _108
  58558 	_108:
  58559 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58560 	}
  58561 }
  58562 
  58563 func YuvToRgbaRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58564 	var end, v1, v5 uintptr
  58565 	var v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v61, v8 int32
  58566 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = end, v1, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v5, v61, v8
  58567 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  58568 	for dst != end {
  58569 		v1 = dst
  58570 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58571 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58572 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58573 		v5 = v1
  58574 		v8 = v2 * int32(19077) >> int32(8)
  58575 		goto _9
  58576 	_9:
  58577 		v10 = v4 * int32(26149) >> int32(8)
  58578 		goto _11
  58579 	_11:
  58580 		v12 = v8 + v10 - int32(14234)
  58581 		if v12 & ^int32(YUV_MASK2) == 0 {
  58582 			v15 = v12 >> int32(YUV_FIX2)
  58583 		} else {
  58584 			if v12 < 0 {
  58585 				v16 = 0
  58586 			} else {
  58587 				v16 = int32(255)
  58588 			}
  58589 			v15 = v16
  58590 		}
  58591 		v13 = v15
  58592 		goto _14
  58593 	_14:
  58594 		v61 = v13
  58595 		goto _7
  58596 	_7:
  58597 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58598 		v19 = v2 * int32(19077) >> int32(8)
  58599 		goto _20
  58600 	_20:
  58601 		v21 = v3 * int32(6419) >> int32(8)
  58602 		goto _22
  58603 	_22:
  58604 		v23 = v4 * int32(13320) >> int32(8)
  58605 		goto _24
  58606 	_24:
  58607 		v25 = v19 - v21 - v23 + int32(8708)
  58608 		if v25 & ^int32(YUV_MASK2) == 0 {
  58609 			v28 = v25 >> int32(YUV_FIX2)
  58610 		} else {
  58611 			if v25 < 0 {
  58612 				v29 = 0
  58613 			} else {
  58614 				v29 = int32(255)
  58615 			}
  58616 			v28 = v29
  58617 		}
  58618 		v26 = v28
  58619 		goto _27
  58620 	_27:
  58621 		v17 = v26
  58622 		goto _18
  58623 	_18:
  58624 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58625 		v32 = v2 * int32(19077) >> int32(8)
  58626 		goto _33
  58627 	_33:
  58628 		v34 = v3 * int32(33050) >> int32(8)
  58629 		goto _35
  58630 	_35:
  58631 		v36 = v32 + v34 - int32(17685)
  58632 		if v36 & ^int32(YUV_MASK2) == 0 {
  58633 			v39 = v36 >> int32(YUV_FIX2)
  58634 		} else {
  58635 			if v36 < 0 {
  58636 				v40 = 0
  58637 			} else {
  58638 				v40 = int32(255)
  58639 			}
  58640 			v39 = v40
  58641 		}
  58642 		v37 = v39
  58643 		goto _38
  58644 	_38:
  58645 		v30 = v37
  58646 		goto _31
  58647 	_31:
  58648 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58649 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58650 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  58651 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + 1)))
  58652 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58653 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58654 		v5 = v1
  58655 		v8 = v2 * int32(19077) >> int32(8)
  58656 		goto _49
  58657 	_49:
  58658 		v10 = v4 * int32(26149) >> int32(8)
  58659 		goto _51
  58660 	_51:
  58661 		v12 = v8 + v10 - int32(14234)
  58662 		if v12 & ^int32(YUV_MASK2) == 0 {
  58663 			v15 = v12 >> int32(YUV_FIX2)
  58664 		} else {
  58665 			if v12 < 0 {
  58666 				v16 = 0
  58667 			} else {
  58668 				v16 = int32(255)
  58669 			}
  58670 			v15 = v16
  58671 		}
  58672 		v13 = v15
  58673 		goto _54
  58674 	_54:
  58675 		v61 = v13
  58676 		goto _47
  58677 	_47:
  58678 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58679 		v19 = v2 * int32(19077) >> int32(8)
  58680 		goto _60
  58681 	_60:
  58682 		v21 = v3 * int32(6419) >> int32(8)
  58683 		goto _62
  58684 	_62:
  58685 		v23 = v4 * int32(13320) >> int32(8)
  58686 		goto _64
  58687 	_64:
  58688 		v25 = v19 - v21 - v23 + int32(8708)
  58689 		if v25 & ^int32(YUV_MASK2) == 0 {
  58690 			v28 = v25 >> int32(YUV_FIX2)
  58691 		} else {
  58692 			if v25 < 0 {
  58693 				v29 = 0
  58694 			} else {
  58695 				v29 = int32(255)
  58696 			}
  58697 			v28 = v29
  58698 		}
  58699 		v26 = v28
  58700 		goto _67
  58701 	_67:
  58702 		v17 = v26
  58703 		goto _58
  58704 	_58:
  58705 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58706 		v32 = v2 * int32(19077) >> int32(8)
  58707 		goto _73
  58708 	_73:
  58709 		v34 = v3 * int32(33050) >> int32(8)
  58710 		goto _75
  58711 	_75:
  58712 		v36 = v32 + v34 - int32(17685)
  58713 		if v36 & ^int32(YUV_MASK2) == 0 {
  58714 			v39 = v36 >> int32(YUV_FIX2)
  58715 		} else {
  58716 			if v36 < 0 {
  58717 				v40 = 0
  58718 			} else {
  58719 				v40 = int32(255)
  58720 			}
  58721 			v39 = v40
  58722 		}
  58723 		v37 = v39
  58724 		goto _78
  58725 	_78:
  58726 		v30 = v37
  58727 		goto _71
  58728 	_71:
  58729 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58730 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58731 		y5 = y5 + uintptr(2)
  58732 		u4 = u4 + 1
  58733 		v6 = v6 + 1
  58734 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  58735 	}
  58736 	if len1&int32(1) != 0 {
  58737 		v1 = dst
  58738 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58739 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58740 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58741 		v5 = v1
  58742 		v8 = v2 * int32(19077) >> int32(8)
  58743 		goto _89
  58744 	_89:
  58745 		v10 = v4 * int32(26149) >> int32(8)
  58746 		goto _91
  58747 	_91:
  58748 		v12 = v8 + v10 - int32(14234)
  58749 		if v12 & ^int32(YUV_MASK2) == 0 {
  58750 			v15 = v12 >> int32(YUV_FIX2)
  58751 		} else {
  58752 			if v12 < 0 {
  58753 				v16 = 0
  58754 			} else {
  58755 				v16 = int32(255)
  58756 			}
  58757 			v15 = v16
  58758 		}
  58759 		v13 = v15
  58760 		goto _94
  58761 	_94:
  58762 		v61 = v13
  58763 		goto _87
  58764 	_87:
  58765 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58766 		v19 = v2 * int32(19077) >> int32(8)
  58767 		goto _100
  58768 	_100:
  58769 		v21 = v3 * int32(6419) >> int32(8)
  58770 		goto _102
  58771 	_102:
  58772 		v23 = v4 * int32(13320) >> int32(8)
  58773 		goto _104
  58774 	_104:
  58775 		v25 = v19 - v21 - v23 + int32(8708)
  58776 		if v25 & ^int32(YUV_MASK2) == 0 {
  58777 			v28 = v25 >> int32(YUV_FIX2)
  58778 		} else {
  58779 			if v25 < 0 {
  58780 				v29 = 0
  58781 			} else {
  58782 				v29 = int32(255)
  58783 			}
  58784 			v28 = v29
  58785 		}
  58786 		v26 = v28
  58787 		goto _107
  58788 	_107:
  58789 		v17 = v26
  58790 		goto _98
  58791 	_98:
  58792 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58793 		v32 = v2 * int32(19077) >> int32(8)
  58794 		goto _113
  58795 	_113:
  58796 		v34 = v3 * int32(33050) >> int32(8)
  58797 		goto _115
  58798 	_115:
  58799 		v36 = v32 + v34 - int32(17685)
  58800 		if v36 & ^int32(YUV_MASK2) == 0 {
  58801 			v39 = v36 >> int32(YUV_FIX2)
  58802 		} else {
  58803 			if v36 < 0 {
  58804 				v40 = 0
  58805 			} else {
  58806 				v40 = int32(255)
  58807 			}
  58808 			v39 = v40
  58809 		}
  58810 		v37 = v39
  58811 		goto _118
  58812 	_118:
  58813 		v30 = v37
  58814 		goto _111
  58815 	_111:
  58816 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58817 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58818 	}
  58819 }
  58820 
  58821 func YuvToBgraRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58822 	var end, v1, v5 uintptr
  58823 	var v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v61, v8 int32
  58824 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = end, v1, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v5, v61, v8
  58825 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  58826 	for dst != end {
  58827 		v1 = dst
  58828 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58829 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58830 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58831 		v5 = v1
  58832 		v8 = v2 * int32(19077) >> int32(8)
  58833 		goto _9
  58834 	_9:
  58835 		v10 = v3 * int32(33050) >> int32(8)
  58836 		goto _11
  58837 	_11:
  58838 		v12 = v8 + v10 - int32(17685)
  58839 		if v12 & ^int32(YUV_MASK2) == 0 {
  58840 			v15 = v12 >> int32(YUV_FIX2)
  58841 		} else {
  58842 			if v12 < 0 {
  58843 				v16 = 0
  58844 			} else {
  58845 				v16 = int32(255)
  58846 			}
  58847 			v15 = v16
  58848 		}
  58849 		v13 = v15
  58850 		goto _14
  58851 	_14:
  58852 		v61 = v13
  58853 		goto _7
  58854 	_7:
  58855 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58856 		v19 = v2 * int32(19077) >> int32(8)
  58857 		goto _20
  58858 	_20:
  58859 		v21 = v3 * int32(6419) >> int32(8)
  58860 		goto _22
  58861 	_22:
  58862 		v23 = v4 * int32(13320) >> int32(8)
  58863 		goto _24
  58864 	_24:
  58865 		v25 = v19 - v21 - v23 + int32(8708)
  58866 		if v25 & ^int32(YUV_MASK2) == 0 {
  58867 			v28 = v25 >> int32(YUV_FIX2)
  58868 		} else {
  58869 			if v25 < 0 {
  58870 				v29 = 0
  58871 			} else {
  58872 				v29 = int32(255)
  58873 			}
  58874 			v28 = v29
  58875 		}
  58876 		v26 = v28
  58877 		goto _27
  58878 	_27:
  58879 		v17 = v26
  58880 		goto _18
  58881 	_18:
  58882 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58883 		v32 = v2 * int32(19077) >> int32(8)
  58884 		goto _33
  58885 	_33:
  58886 		v34 = v4 * int32(26149) >> int32(8)
  58887 		goto _35
  58888 	_35:
  58889 		v36 = v32 + v34 - int32(14234)
  58890 		if v36 & ^int32(YUV_MASK2) == 0 {
  58891 			v39 = v36 >> int32(YUV_FIX2)
  58892 		} else {
  58893 			if v36 < 0 {
  58894 				v40 = 0
  58895 			} else {
  58896 				v40 = int32(255)
  58897 			}
  58898 			v39 = v40
  58899 		}
  58900 		v37 = v39
  58901 		goto _38
  58902 	_38:
  58903 		v30 = v37
  58904 		goto _31
  58905 	_31:
  58906 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58907 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58908 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  58909 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + 1)))
  58910 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58911 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58912 		v5 = v1
  58913 		v8 = v2 * int32(19077) >> int32(8)
  58914 		goto _49
  58915 	_49:
  58916 		v10 = v3 * int32(33050) >> int32(8)
  58917 		goto _51
  58918 	_51:
  58919 		v12 = v8 + v10 - int32(17685)
  58920 		if v12 & ^int32(YUV_MASK2) == 0 {
  58921 			v15 = v12 >> int32(YUV_FIX2)
  58922 		} else {
  58923 			if v12 < 0 {
  58924 				v16 = 0
  58925 			} else {
  58926 				v16 = int32(255)
  58927 			}
  58928 			v15 = v16
  58929 		}
  58930 		v13 = v15
  58931 		goto _54
  58932 	_54:
  58933 		v61 = v13
  58934 		goto _47
  58935 	_47:
  58936 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58937 		v19 = v2 * int32(19077) >> int32(8)
  58938 		goto _60
  58939 	_60:
  58940 		v21 = v3 * int32(6419) >> int32(8)
  58941 		goto _62
  58942 	_62:
  58943 		v23 = v4 * int32(13320) >> int32(8)
  58944 		goto _64
  58945 	_64:
  58946 		v25 = v19 - v21 - v23 + int32(8708)
  58947 		if v25 & ^int32(YUV_MASK2) == 0 {
  58948 			v28 = v25 >> int32(YUV_FIX2)
  58949 		} else {
  58950 			if v25 < 0 {
  58951 				v29 = 0
  58952 			} else {
  58953 				v29 = int32(255)
  58954 			}
  58955 			v28 = v29
  58956 		}
  58957 		v26 = v28
  58958 		goto _67
  58959 	_67:
  58960 		v17 = v26
  58961 		goto _58
  58962 	_58:
  58963 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58964 		v32 = v2 * int32(19077) >> int32(8)
  58965 		goto _73
  58966 	_73:
  58967 		v34 = v4 * int32(26149) >> int32(8)
  58968 		goto _75
  58969 	_75:
  58970 		v36 = v32 + v34 - int32(14234)
  58971 		if v36 & ^int32(YUV_MASK2) == 0 {
  58972 			v39 = v36 >> int32(YUV_FIX2)
  58973 		} else {
  58974 			if v36 < 0 {
  58975 				v40 = 0
  58976 			} else {
  58977 				v40 = int32(255)
  58978 			}
  58979 			v39 = v40
  58980 		}
  58981 		v37 = v39
  58982 		goto _78
  58983 	_78:
  58984 		v30 = v37
  58985 		goto _71
  58986 	_71:
  58987 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58988 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58989 		y5 = y5 + uintptr(2)
  58990 		u4 = u4 + 1
  58991 		v6 = v6 + 1
  58992 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  58993 	}
  58994 	if len1&int32(1) != 0 {
  58995 		v1 = dst
  58996 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58997 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58998 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58999 		v5 = v1
  59000 		v8 = v2 * int32(19077) >> int32(8)
  59001 		goto _89
  59002 	_89:
  59003 		v10 = v3 * int32(33050) >> int32(8)
  59004 		goto _91
  59005 	_91:
  59006 		v12 = v8 + v10 - int32(17685)
  59007 		if v12 & ^int32(YUV_MASK2) == 0 {
  59008 			v15 = v12 >> int32(YUV_FIX2)
  59009 		} else {
  59010 			if v12 < 0 {
  59011 				v16 = 0
  59012 			} else {
  59013 				v16 = int32(255)
  59014 			}
  59015 			v15 = v16
  59016 		}
  59017 		v13 = v15
  59018 		goto _94
  59019 	_94:
  59020 		v61 = v13
  59021 		goto _87
  59022 	_87:
  59023 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59024 		v19 = v2 * int32(19077) >> int32(8)
  59025 		goto _100
  59026 	_100:
  59027 		v21 = v3 * int32(6419) >> int32(8)
  59028 		goto _102
  59029 	_102:
  59030 		v23 = v4 * int32(13320) >> int32(8)
  59031 		goto _104
  59032 	_104:
  59033 		v25 = v19 - v21 - v23 + int32(8708)
  59034 		if v25 & ^int32(YUV_MASK2) == 0 {
  59035 			v28 = v25 >> int32(YUV_FIX2)
  59036 		} else {
  59037 			if v25 < 0 {
  59038 				v29 = 0
  59039 			} else {
  59040 				v29 = int32(255)
  59041 			}
  59042 			v28 = v29
  59043 		}
  59044 		v26 = v28
  59045 		goto _107
  59046 	_107:
  59047 		v17 = v26
  59048 		goto _98
  59049 	_98:
  59050 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59051 		v32 = v2 * int32(19077) >> int32(8)
  59052 		goto _113
  59053 	_113:
  59054 		v34 = v4 * int32(26149) >> int32(8)
  59055 		goto _115
  59056 	_115:
  59057 		v36 = v32 + v34 - int32(14234)
  59058 		if v36 & ^int32(YUV_MASK2) == 0 {
  59059 			v39 = v36 >> int32(YUV_FIX2)
  59060 		} else {
  59061 			if v36 < 0 {
  59062 				v40 = 0
  59063 			} else {
  59064 				v40 = int32(255)
  59065 			}
  59066 			v39 = v40
  59067 		}
  59068 		v37 = v39
  59069 		goto _118
  59070 	_118:
  59071 		v30 = v37
  59072 		goto _111
  59073 	_111:
  59074 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59075 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59076 	}
  59077 }
  59078 
  59079 func YuvToArgbRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  59080 	var end, v1, v5 uintptr
  59081 	var v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v61, v8 int32
  59082 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = end, v1, v10, v12, v13, v15, v16, v17, v19, v2, v21, v23, v25, v26, v28, v29, v3, v30, v32, v34, v36, v37, v39, v4, v40, v5, v61, v8
  59083 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  59084 	for dst != end {
  59085 		v1 = dst
  59086 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59087 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  59088 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59089 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59090 		v5 = v1 + uintptr(1)
  59091 		v8 = v2 * int32(19077) >> int32(8)
  59092 		goto _9
  59093 	_9:
  59094 		v10 = v4 * int32(26149) >> int32(8)
  59095 		goto _11
  59096 	_11:
  59097 		v12 = v8 + v10 - int32(14234)
  59098 		if v12 & ^int32(YUV_MASK2) == 0 {
  59099 			v15 = v12 >> int32(YUV_FIX2)
  59100 		} else {
  59101 			if v12 < 0 {
  59102 				v16 = 0
  59103 			} else {
  59104 				v16 = int32(255)
  59105 			}
  59106 			v15 = v16
  59107 		}
  59108 		v13 = v15
  59109 		goto _14
  59110 	_14:
  59111 		v61 = v13
  59112 		goto _7
  59113 	_7:
  59114 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59115 		v19 = v2 * int32(19077) >> int32(8)
  59116 		goto _20
  59117 	_20:
  59118 		v21 = v3 * int32(6419) >> int32(8)
  59119 		goto _22
  59120 	_22:
  59121 		v23 = v4 * int32(13320) >> int32(8)
  59122 		goto _24
  59123 	_24:
  59124 		v25 = v19 - v21 - v23 + int32(8708)
  59125 		if v25 & ^int32(YUV_MASK2) == 0 {
  59126 			v28 = v25 >> int32(YUV_FIX2)
  59127 		} else {
  59128 			if v25 < 0 {
  59129 				v29 = 0
  59130 			} else {
  59131 				v29 = int32(255)
  59132 			}
  59133 			v28 = v29
  59134 		}
  59135 		v26 = v28
  59136 		goto _27
  59137 	_27:
  59138 		v17 = v26
  59139 		goto _18
  59140 	_18:
  59141 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59142 		v32 = v2 * int32(19077) >> int32(8)
  59143 		goto _33
  59144 	_33:
  59145 		v34 = v3 * int32(33050) >> int32(8)
  59146 		goto _35
  59147 	_35:
  59148 		v36 = v32 + v34 - int32(17685)
  59149 		if v36 & ^int32(YUV_MASK2) == 0 {
  59150 			v39 = v36 >> int32(YUV_FIX2)
  59151 		} else {
  59152 			if v36 < 0 {
  59153 				v40 = 0
  59154 			} else {
  59155 				v40 = int32(255)
  59156 			}
  59157 			v39 = v40
  59158 		}
  59159 		v37 = v39
  59160 		goto _38
  59161 	_38:
  59162 		v30 = v37
  59163 		goto _31
  59164 	_31:
  59165 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59166 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59167 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59168 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59169 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59170 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59171 		v5 = v1 + uintptr(1)
  59172 		v8 = v2 * int32(19077) >> int32(8)
  59173 		goto _49
  59174 	_49:
  59175 		v10 = v4 * int32(26149) >> int32(8)
  59176 		goto _51
  59177 	_51:
  59178 		v12 = v8 + v10 - int32(14234)
  59179 		if v12 & ^int32(YUV_MASK2) == 0 {
  59180 			v15 = v12 >> int32(YUV_FIX2)
  59181 		} else {
  59182 			if v12 < 0 {
  59183 				v16 = 0
  59184 			} else {
  59185 				v16 = int32(255)
  59186 			}
  59187 			v15 = v16
  59188 		}
  59189 		v13 = v15
  59190 		goto _54
  59191 	_54:
  59192 		v61 = v13
  59193 		goto _47
  59194 	_47:
  59195 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59196 		v19 = v2 * int32(19077) >> int32(8)
  59197 		goto _60
  59198 	_60:
  59199 		v21 = v3 * int32(6419) >> int32(8)
  59200 		goto _62
  59201 	_62:
  59202 		v23 = v4 * int32(13320) >> int32(8)
  59203 		goto _64
  59204 	_64:
  59205 		v25 = v19 - v21 - v23 + int32(8708)
  59206 		if v25 & ^int32(YUV_MASK2) == 0 {
  59207 			v28 = v25 >> int32(YUV_FIX2)
  59208 		} else {
  59209 			if v25 < 0 {
  59210 				v29 = 0
  59211 			} else {
  59212 				v29 = int32(255)
  59213 			}
  59214 			v28 = v29
  59215 		}
  59216 		v26 = v28
  59217 		goto _67
  59218 	_67:
  59219 		v17 = v26
  59220 		goto _58
  59221 	_58:
  59222 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59223 		v32 = v2 * int32(19077) >> int32(8)
  59224 		goto _73
  59225 	_73:
  59226 		v34 = v3 * int32(33050) >> int32(8)
  59227 		goto _75
  59228 	_75:
  59229 		v36 = v32 + v34 - int32(17685)
  59230 		if v36 & ^int32(YUV_MASK2) == 0 {
  59231 			v39 = v36 >> int32(YUV_FIX2)
  59232 		} else {
  59233 			if v36 < 0 {
  59234 				v40 = 0
  59235 			} else {
  59236 				v40 = int32(255)
  59237 			}
  59238 			v39 = v40
  59239 		}
  59240 		v37 = v39
  59241 		goto _78
  59242 	_78:
  59243 		v30 = v37
  59244 		goto _71
  59245 	_71:
  59246 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59247 		y5 = y5 + uintptr(2)
  59248 		u4 = u4 + 1
  59249 		v6 = v6 + 1
  59250 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59251 	}
  59252 	if len1&int32(1) != 0 {
  59253 		v1 = dst
  59254 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59255 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  59256 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59257 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59258 		v5 = v1 + uintptr(1)
  59259 		v8 = v2 * int32(19077) >> int32(8)
  59260 		goto _89
  59261 	_89:
  59262 		v10 = v4 * int32(26149) >> int32(8)
  59263 		goto _91
  59264 	_91:
  59265 		v12 = v8 + v10 - int32(14234)
  59266 		if v12 & ^int32(YUV_MASK2) == 0 {
  59267 			v15 = v12 >> int32(YUV_FIX2)
  59268 		} else {
  59269 			if v12 < 0 {
  59270 				v16 = 0
  59271 			} else {
  59272 				v16 = int32(255)
  59273 			}
  59274 			v15 = v16
  59275 		}
  59276 		v13 = v15
  59277 		goto _94
  59278 	_94:
  59279 		v61 = v13
  59280 		goto _87
  59281 	_87:
  59282 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59283 		v19 = v2 * int32(19077) >> int32(8)
  59284 		goto _100
  59285 	_100:
  59286 		v21 = v3 * int32(6419) >> int32(8)
  59287 		goto _102
  59288 	_102:
  59289 		v23 = v4 * int32(13320) >> int32(8)
  59290 		goto _104
  59291 	_104:
  59292 		v25 = v19 - v21 - v23 + int32(8708)
  59293 		if v25 & ^int32(YUV_MASK2) == 0 {
  59294 			v28 = v25 >> int32(YUV_FIX2)
  59295 		} else {
  59296 			if v25 < 0 {
  59297 				v29 = 0
  59298 			} else {
  59299 				v29 = int32(255)
  59300 			}
  59301 			v28 = v29
  59302 		}
  59303 		v26 = v28
  59304 		goto _107
  59305 	_107:
  59306 		v17 = v26
  59307 		goto _98
  59308 	_98:
  59309 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59310 		v32 = v2 * int32(19077) >> int32(8)
  59311 		goto _113
  59312 	_113:
  59313 		v34 = v3 * int32(33050) >> int32(8)
  59314 		goto _115
  59315 	_115:
  59316 		v36 = v32 + v34 - int32(17685)
  59317 		if v36 & ^int32(YUV_MASK2) == 0 {
  59318 			v39 = v36 >> int32(YUV_FIX2)
  59319 		} else {
  59320 			if v36 < 0 {
  59321 				v40 = 0
  59322 			} else {
  59323 				v40 = int32(255)
  59324 			}
  59325 			v39 = v40
  59326 		}
  59327 		v37 = v39
  59328 		goto _118
  59329 	_118:
  59330 		v30 = v37
  59331 		goto _111
  59332 	_111:
  59333 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59334 	}
  59335 }
  59336 
  59337 func YuvToRgba4444Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59338 	var b, ba, g, r, rg, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v51, v7, v9 int32
  59339 	var end, v4 uintptr
  59340 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, ba, end, g, r, rg, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v51, v7, v9
  59341 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59342 	for dst != end {
  59343 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59344 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59345 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59346 		v4 = dst
  59347 		v7 = v1 * int32(19077) >> int32(8)
  59348 		goto _8
  59349 	_8:
  59350 		v9 = v3 * int32(26149) >> int32(8)
  59351 		goto _10
  59352 	_10:
  59353 		v11 = v7 + v9 - int32(14234)
  59354 		if v11 & ^int32(YUV_MASK2) == 0 {
  59355 			v14 = v11 >> int32(YUV_FIX2)
  59356 		} else {
  59357 			if v11 < 0 {
  59358 				v15 = 0
  59359 			} else {
  59360 				v15 = int32(255)
  59361 			}
  59362 			v14 = v15
  59363 		}
  59364 		v12 = v14
  59365 		goto _13
  59366 	_13:
  59367 		v51 = v12
  59368 		goto _6
  59369 	_6:
  59370 		r = v51
  59371 		v18 = v1 * int32(19077) >> int32(8)
  59372 		goto _19
  59373 	_19:
  59374 		v20 = v2 * int32(6419) >> int32(8)
  59375 		goto _21
  59376 	_21:
  59377 		v22 = v3 * int32(13320) >> int32(8)
  59378 		goto _23
  59379 	_23:
  59380 		v24 = v18 - v20 - v22 + int32(8708)
  59381 		if v24 & ^int32(YUV_MASK2) == 0 {
  59382 			v27 = v24 >> int32(YUV_FIX2)
  59383 		} else {
  59384 			if v24 < 0 {
  59385 				v28 = 0
  59386 			} else {
  59387 				v28 = int32(255)
  59388 			}
  59389 			v27 = v28
  59390 		}
  59391 		v25 = v27
  59392 		goto _26
  59393 	_26:
  59394 		v16 = v25
  59395 		goto _17
  59396 	_17:
  59397 		g = v16
  59398 		v31 = v1 * int32(19077) >> int32(8)
  59399 		goto _32
  59400 	_32:
  59401 		v33 = v2 * int32(33050) >> int32(8)
  59402 		goto _34
  59403 	_34:
  59404 		v35 = v31 + v33 - int32(17685)
  59405 		if v35 & ^int32(YUV_MASK2) == 0 {
  59406 			v38 = v35 >> int32(YUV_FIX2)
  59407 		} else {
  59408 			if v35 < 0 {
  59409 				v39 = 0
  59410 			} else {
  59411 				v39 = int32(255)
  59412 			}
  59413 			v38 = v39
  59414 		}
  59415 		v36 = v38
  59416 		goto _37
  59417 	_37:
  59418 		v29 = v36
  59419 		goto _30
  59420 	_30:
  59421 		b = v29
  59422 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59423 		ba = b&int32(0xf0) | int32(0x0f)
  59424 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59425 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  59426 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  59427 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59428 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59429 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  59430 		v7 = v1 * int32(19077) >> int32(8)
  59431 		goto _47
  59432 	_47:
  59433 		v9 = v3 * int32(26149) >> int32(8)
  59434 		goto _49
  59435 	_49:
  59436 		v11 = v7 + v9 - int32(14234)
  59437 		if v11 & ^int32(YUV_MASK2) == 0 {
  59438 			v14 = v11 >> int32(YUV_FIX2)
  59439 		} else {
  59440 			if v11 < 0 {
  59441 				v15 = 0
  59442 			} else {
  59443 				v15 = int32(255)
  59444 			}
  59445 			v14 = v15
  59446 		}
  59447 		v12 = v14
  59448 		goto _52
  59449 	_52:
  59450 		v51 = v12
  59451 		goto _45
  59452 	_45:
  59453 		r = v51
  59454 		v18 = v1 * int32(19077) >> int32(8)
  59455 		goto _58
  59456 	_58:
  59457 		v20 = v2 * int32(6419) >> int32(8)
  59458 		goto _60
  59459 	_60:
  59460 		v22 = v3 * int32(13320) >> int32(8)
  59461 		goto _62
  59462 	_62:
  59463 		v24 = v18 - v20 - v22 + int32(8708)
  59464 		if v24 & ^int32(YUV_MASK2) == 0 {
  59465 			v27 = v24 >> int32(YUV_FIX2)
  59466 		} else {
  59467 			if v24 < 0 {
  59468 				v28 = 0
  59469 			} else {
  59470 				v28 = int32(255)
  59471 			}
  59472 			v27 = v28
  59473 		}
  59474 		v25 = v27
  59475 		goto _65
  59476 	_65:
  59477 		v16 = v25
  59478 		goto _56
  59479 	_56:
  59480 		g = v16
  59481 		v31 = v1 * int32(19077) >> int32(8)
  59482 		goto _71
  59483 	_71:
  59484 		v33 = v2 * int32(33050) >> int32(8)
  59485 		goto _73
  59486 	_73:
  59487 		v35 = v31 + v33 - int32(17685)
  59488 		if v35 & ^int32(YUV_MASK2) == 0 {
  59489 			v38 = v35 >> int32(YUV_FIX2)
  59490 		} else {
  59491 			if v35 < 0 {
  59492 				v39 = 0
  59493 			} else {
  59494 				v39 = int32(255)
  59495 			}
  59496 			v38 = v39
  59497 		}
  59498 		v36 = v38
  59499 		goto _76
  59500 	_76:
  59501 		v29 = v36
  59502 		goto _69
  59503 	_69:
  59504 		b = v29
  59505 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59506 		ba = b&int32(0xf0) | int32(0x0f)
  59507 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59508 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  59509 		y4 = y4 + uintptr(2)
  59510 		u3 = u3 + 1
  59511 		v5 = v5 + 1
  59512 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  59513 	}
  59514 	if len1&int32(1) != 0 {
  59515 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59516 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59517 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59518 		v4 = dst
  59519 		v7 = v1 * int32(19077) >> int32(8)
  59520 		goto _86
  59521 	_86:
  59522 		v9 = v3 * int32(26149) >> int32(8)
  59523 		goto _88
  59524 	_88:
  59525 		v11 = v7 + v9 - int32(14234)
  59526 		if v11 & ^int32(YUV_MASK2) == 0 {
  59527 			v14 = v11 >> int32(YUV_FIX2)
  59528 		} else {
  59529 			if v11 < 0 {
  59530 				v15 = 0
  59531 			} else {
  59532 				v15 = int32(255)
  59533 			}
  59534 			v14 = v15
  59535 		}
  59536 		v12 = v14
  59537 		goto _91
  59538 	_91:
  59539 		v51 = v12
  59540 		goto _84
  59541 	_84:
  59542 		r = v51
  59543 		v18 = v1 * int32(19077) >> int32(8)
  59544 		goto _97
  59545 	_97:
  59546 		v20 = v2 * int32(6419) >> int32(8)
  59547 		goto _99
  59548 	_99:
  59549 		v22 = v3 * int32(13320) >> int32(8)
  59550 		goto _101
  59551 	_101:
  59552 		v24 = v18 - v20 - v22 + int32(8708)
  59553 		if v24 & ^int32(YUV_MASK2) == 0 {
  59554 			v27 = v24 >> int32(YUV_FIX2)
  59555 		} else {
  59556 			if v24 < 0 {
  59557 				v28 = 0
  59558 			} else {
  59559 				v28 = int32(255)
  59560 			}
  59561 			v27 = v28
  59562 		}
  59563 		v25 = v27
  59564 		goto _104
  59565 	_104:
  59566 		v16 = v25
  59567 		goto _95
  59568 	_95:
  59569 		g = v16
  59570 		v31 = v1 * int32(19077) >> int32(8)
  59571 		goto _110
  59572 	_110:
  59573 		v33 = v2 * int32(33050) >> int32(8)
  59574 		goto _112
  59575 	_112:
  59576 		v35 = v31 + v33 - int32(17685)
  59577 		if v35 & ^int32(YUV_MASK2) == 0 {
  59578 			v38 = v35 >> int32(YUV_FIX2)
  59579 		} else {
  59580 			if v35 < 0 {
  59581 				v39 = 0
  59582 			} else {
  59583 				v39 = int32(255)
  59584 			}
  59585 			v38 = v39
  59586 		}
  59587 		v36 = v38
  59588 		goto _115
  59589 	_115:
  59590 		v29 = v36
  59591 		goto _108
  59592 	_108:
  59593 		b = v29
  59594 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59595 		ba = b&int32(0xf0) | int32(0x0f)
  59596 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59597 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  59598 	}
  59599 }
  59600 
  59601 func YuvToRgb565Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59602 	var b, g, gb, r, rg, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v51, v7, v9 int32
  59603 	var end, v4 uintptr
  59604 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, end, g, gb, r, rg, v1, v11, v12, v14, v15, v16, v18, v2, v20, v22, v24, v25, v27, v28, v29, v3, v31, v33, v35, v36, v38, v39, v4, v51, v7, v9
  59605 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59606 	for dst != end {
  59607 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59608 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59609 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59610 		v4 = dst
  59611 		v7 = v1 * int32(19077) >> int32(8)
  59612 		goto _8
  59613 	_8:
  59614 		v9 = v3 * int32(26149) >> int32(8)
  59615 		goto _10
  59616 	_10:
  59617 		v11 = v7 + v9 - int32(14234)
  59618 		if v11 & ^int32(YUV_MASK2) == 0 {
  59619 			v14 = v11 >> int32(YUV_FIX2)
  59620 		} else {
  59621 			if v11 < 0 {
  59622 				v15 = 0
  59623 			} else {
  59624 				v15 = int32(255)
  59625 			}
  59626 			v14 = v15
  59627 		}
  59628 		v12 = v14
  59629 		goto _13
  59630 	_13:
  59631 		v51 = v12
  59632 		goto _6
  59633 	_6:
  59634 		r = v51
  59635 		v18 = v1 * int32(19077) >> int32(8)
  59636 		goto _19
  59637 	_19:
  59638 		v20 = v2 * int32(6419) >> int32(8)
  59639 		goto _21
  59640 	_21:
  59641 		v22 = v3 * int32(13320) >> int32(8)
  59642 		goto _23
  59643 	_23:
  59644 		v24 = v18 - v20 - v22 + int32(8708)
  59645 		if v24 & ^int32(YUV_MASK2) == 0 {
  59646 			v27 = v24 >> int32(YUV_FIX2)
  59647 		} else {
  59648 			if v24 < 0 {
  59649 				v28 = 0
  59650 			} else {
  59651 				v28 = int32(255)
  59652 			}
  59653 			v27 = v28
  59654 		}
  59655 		v25 = v27
  59656 		goto _26
  59657 	_26:
  59658 		v16 = v25
  59659 		goto _17
  59660 	_17:
  59661 		g = v16
  59662 		v31 = v1 * int32(19077) >> int32(8)
  59663 		goto _32
  59664 	_32:
  59665 		v33 = v2 * int32(33050) >> int32(8)
  59666 		goto _34
  59667 	_34:
  59668 		v35 = v31 + v33 - int32(17685)
  59669 		if v35 & ^int32(YUV_MASK2) == 0 {
  59670 			v38 = v35 >> int32(YUV_FIX2)
  59671 		} else {
  59672 			if v35 < 0 {
  59673 				v39 = 0
  59674 			} else {
  59675 				v39 = int32(255)
  59676 			}
  59677 			v38 = v39
  59678 		}
  59679 		v36 = v38
  59680 		goto _37
  59681 	_37:
  59682 		v29 = v36
  59683 		goto _30
  59684 	_30:
  59685 		b = v29
  59686 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  59687 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  59688 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59689 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  59690 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  59691 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59692 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59693 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  59694 		v7 = v1 * int32(19077) >> int32(8)
  59695 		goto _47
  59696 	_47:
  59697 		v9 = v3 * int32(26149) >> int32(8)
  59698 		goto _49
  59699 	_49:
  59700 		v11 = v7 + v9 - int32(14234)
  59701 		if v11 & ^int32(YUV_MASK2) == 0 {
  59702 			v14 = v11 >> int32(YUV_FIX2)
  59703 		} else {
  59704 			if v11 < 0 {
  59705 				v15 = 0
  59706 			} else {
  59707 				v15 = int32(255)
  59708 			}
  59709 			v14 = v15
  59710 		}
  59711 		v12 = v14
  59712 		goto _52
  59713 	_52:
  59714 		v51 = v12
  59715 		goto _45
  59716 	_45:
  59717 		r = v51
  59718 		v18 = v1 * int32(19077) >> int32(8)
  59719 		goto _58
  59720 	_58:
  59721 		v20 = v2 * int32(6419) >> int32(8)
  59722 		goto _60
  59723 	_60:
  59724 		v22 = v3 * int32(13320) >> int32(8)
  59725 		goto _62
  59726 	_62:
  59727 		v24 = v18 - v20 - v22 + int32(8708)
  59728 		if v24 & ^int32(YUV_MASK2) == 0 {
  59729 			v27 = v24 >> int32(YUV_FIX2)
  59730 		} else {
  59731 			if v24 < 0 {
  59732 				v28 = 0
  59733 			} else {
  59734 				v28 = int32(255)
  59735 			}
  59736 			v27 = v28
  59737 		}
  59738 		v25 = v27
  59739 		goto _65
  59740 	_65:
  59741 		v16 = v25
  59742 		goto _56
  59743 	_56:
  59744 		g = v16
  59745 		v31 = v1 * int32(19077) >> int32(8)
  59746 		goto _71
  59747 	_71:
  59748 		v33 = v2 * int32(33050) >> int32(8)
  59749 		goto _73
  59750 	_73:
  59751 		v35 = v31 + v33 - int32(17685)
  59752 		if v35 & ^int32(YUV_MASK2) == 0 {
  59753 			v38 = v35 >> int32(YUV_FIX2)
  59754 		} else {
  59755 			if v35 < 0 {
  59756 				v39 = 0
  59757 			} else {
  59758 				v39 = int32(255)
  59759 			}
  59760 			v38 = v39
  59761 		}
  59762 		v36 = v38
  59763 		goto _76
  59764 	_76:
  59765 		v29 = v36
  59766 		goto _69
  59767 	_69:
  59768 		b = v29
  59769 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  59770 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  59771 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59772 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  59773 		y4 = y4 + uintptr(2)
  59774 		u3 = u3 + 1
  59775 		v5 = v5 + 1
  59776 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  59777 	}
  59778 	if len1&int32(1) != 0 {
  59779 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59780 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59781 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59782 		v4 = dst
  59783 		v7 = v1 * int32(19077) >> int32(8)
  59784 		goto _86
  59785 	_86:
  59786 		v9 = v3 * int32(26149) >> int32(8)
  59787 		goto _88
  59788 	_88:
  59789 		v11 = v7 + v9 - int32(14234)
  59790 		if v11 & ^int32(YUV_MASK2) == 0 {
  59791 			v14 = v11 >> int32(YUV_FIX2)
  59792 		} else {
  59793 			if v11 < 0 {
  59794 				v15 = 0
  59795 			} else {
  59796 				v15 = int32(255)
  59797 			}
  59798 			v14 = v15
  59799 		}
  59800 		v12 = v14
  59801 		goto _91
  59802 	_91:
  59803 		v51 = v12
  59804 		goto _84
  59805 	_84:
  59806 		r = v51
  59807 		v18 = v1 * int32(19077) >> int32(8)
  59808 		goto _97
  59809 	_97:
  59810 		v20 = v2 * int32(6419) >> int32(8)
  59811 		goto _99
  59812 	_99:
  59813 		v22 = v3 * int32(13320) >> int32(8)
  59814 		goto _101
  59815 	_101:
  59816 		v24 = v18 - v20 - v22 + int32(8708)
  59817 		if v24 & ^int32(YUV_MASK2) == 0 {
  59818 			v27 = v24 >> int32(YUV_FIX2)
  59819 		} else {
  59820 			if v24 < 0 {
  59821 				v28 = 0
  59822 			} else {
  59823 				v28 = int32(255)
  59824 			}
  59825 			v27 = v28
  59826 		}
  59827 		v25 = v27
  59828 		goto _104
  59829 	_104:
  59830 		v16 = v25
  59831 		goto _95
  59832 	_95:
  59833 		g = v16
  59834 		v31 = v1 * int32(19077) >> int32(8)
  59835 		goto _110
  59836 	_110:
  59837 		v33 = v2 * int32(33050) >> int32(8)
  59838 		goto _112
  59839 	_112:
  59840 		v35 = v31 + v33 - int32(17685)
  59841 		if v35 & ^int32(YUV_MASK2) == 0 {
  59842 			v38 = v35 >> int32(YUV_FIX2)
  59843 		} else {
  59844 			if v35 < 0 {
  59845 				v39 = 0
  59846 			} else {
  59847 				v39 = int32(255)
  59848 			}
  59849 			v38 = v39
  59850 		}
  59851 		v36 = v38
  59852 		goto _115
  59853 	_115:
  59854 		v29 = v36
  59855 		goto _108
  59856 	_108:
  59857 		b = v29
  59858 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  59859 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  59860 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59861 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  59862 	}
  59863 }
  59864 
  59865 type __ccgo_fp__XWebPSamplerProcessPlane_9 = func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32)
  59866 
  59867 // C documentation
  59868 //
  59869 //	// Main call for processing a plane with a WebPSamplerRowFunc function:
  59870 func WebPSamplerProcessPlane(tls *libc.TLS, y uintptr, y_stride int32, u uintptr, v uintptr, uv_stride int32, dst uintptr, dst_stride int32, width int32, height int32, __ccgo_fp_func WebPSamplerRowFunc) {
  59871 	var j int32
  59872 	_ = j
  59873 	j = 0
  59874 	for {
  59875 		if !(j < height) {
  59876 			break
  59877 		}
  59878 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_func})))(tls, y, u, v, dst, width)
  59879 		y = y + uintptr(y_stride)
  59880 		if j&int32(1) != 0 {
  59881 			u = u + uintptr(uv_stride)
  59882 			v = v + uintptr(uv_stride)
  59883 		}
  59884 		dst = dst + uintptr(dst_stride)
  59885 		goto _1
  59886 	_1:
  59887 		;
  59888 		j = j + 1
  59889 	}
  59890 }
  59891 
  59892 func WebPInitSamplers(tls *libc.TLS) {
  59893 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  59894 		goto _1
  59895 	}
  59896 	WebPInitSamplers_body(tls)
  59897 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  59898 	goto _2
  59899 _2:
  59900 	;
  59901 	goto _1
  59902 _1: /**/ //
  59903 }
  59904 
  59905 var WebPInitSamplers_body_last_cpuinfo_used = uintptr(0)
  59906 
  59907 func init() {
  59908 	p := unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)
  59909 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))
  59910 }
  59911 
  59912 func WebPInitSamplers_body(tls *libc.TLS) {
  59913 	WebPSamplers[int32(MODE_RGB)] = __ccgo_fp(YuvToRgbRow)
  59914 	WebPSamplers[int32(MODE_RGBA)] = __ccgo_fp(YuvToRgbaRow)
  59915 	WebPSamplers[int32(MODE_BGR)] = __ccgo_fp(YuvToBgrRow)
  59916 	WebPSamplers[int32(MODE_BGRA)] = __ccgo_fp(YuvToBgraRow)
  59917 	WebPSamplers[int32(MODE_ARGB)] = __ccgo_fp(YuvToArgbRow)
  59918 	WebPSamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  59919 	WebPSamplers[int32(MODE_RGB_565)] = __ccgo_fp(YuvToRgb565Row)
  59920 	WebPSamplers[int32(MODE_rgbA)] = __ccgo_fp(YuvToRgbaRow)
  59921 	WebPSamplers[int32(MODE_bgrA)] = __ccgo_fp(YuvToBgraRow)
  59922 	WebPSamplers[int32(MODE_Argb)] = __ccgo_fp(YuvToArgbRow)
  59923 	WebPSamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  59924 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  59925 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  59926 	}
  59927 }
  59928 
  59929 //-----------------------------------------------------------------------------
  59930 // ARGB -> YUV converters
  59931 
  59932 func ConvertARGBToY_C(tls *libc.TLS, argb uintptr, y uintptr, width int32) {
  59933 	var i, luma, v2 int32
  59934 	var p uint32_t
  59935 	_, _, _, _ = i, luma, p, v2
  59936 	i = 0
  59937 	for {
  59938 		if !(i < width) {
  59939 			break
  59940 		}
  59941 		p = **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4))
  59942 		luma = int32(16839)*libc.Int32FromUint32(p>>libc.Int32FromInt32(16)&uint32(0xff)) + int32(33059)*libc.Int32FromUint32(p>>libc.Int32FromInt32(8)&uint32(0xff)) + int32(6420)*libc.Int32FromUint32(p>>libc.Int32FromInt32(0)&uint32(0xff))
  59943 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  59944 		goto _3
  59945 	_3:
  59946 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = libc.Uint8FromInt32(v2)
  59947 		goto _1
  59948 	_1:
  59949 		;
  59950 		i = i + 1
  59951 	}
  59952 }
  59953 
  59954 func WebPConvertARGBToUV_C(tls *libc.TLS, argb uintptr, u1 uintptr, v1 uintptr, src_width int32, do_store int32) {
  59955 	var b2, b3, g2, g3, i, r2, r3, tmp_u, tmp_u1, tmp_v, tmp_v1, u, uv_width, v, v111, v12, v14, v15, v2, v4, v5, v7, v8, v9 int32
  59956 	var v0, v01, v11 uint32_t
  59957 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b2, b3, g2, g3, i, r2, r3, tmp_u, tmp_u1, tmp_v, tmp_v1, u, uv_width, v, v0, v01, v11, v111, v12, v14, v15, v2, v4, v5, v7, v8, v9
  59958 	// No rounding. Last pixel is dealt with separately.
  59959 	uv_width = src_width >> int32(1)
  59960 	i = 0
  59961 	for {
  59962 		if !(i < uv_width) {
  59963 			break
  59964 		}
  59965 		v0 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  59966 		v11 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+int32(1))*4))
  59967 		// VP8RGBToU/V expects four accumulated pixels. Hence we need to
  59968 		// scale r/g/b value by a factor 2. We just shift v0/v1 one bit less.
  59969 		r2 = libc.Int32FromUint32(v0>>libc.Int32FromInt32(15)&uint32(0x1fe) + v11>>libc.Int32FromInt32(15)&uint32(0x1fe))
  59970 		g2 = libc.Int32FromUint32(v0>>libc.Int32FromInt32(7)&uint32(0x1fe) + v11>>libc.Int32FromInt32(7)&uint32(0x1fe))
  59971 		b2 = libc.Int32FromUint32(v0<<libc.Int32FromInt32(1)&uint32(0x1fe) + v11<<libc.Int32FromInt32(1)&uint32(0x1fe))
  59972 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  59973 		v4 = u
  59974 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  59975 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  59976 			v7 = v4
  59977 		} else {
  59978 			if v4 < 0 {
  59979 				v8 = 0
  59980 			} else {
  59981 				v8 = int32(255)
  59982 			}
  59983 			v7 = v8
  59984 		}
  59985 		v5 = v7
  59986 		goto _6
  59987 	_6:
  59988 		v2 = v5
  59989 		goto _3
  59990 	_3:
  59991 		tmp_u = v2
  59992 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  59993 		v111 = v
  59994 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  59995 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  59996 			v14 = v111
  59997 		} else {
  59998 			if v111 < 0 {
  59999 				v15 = 0
  60000 			} else {
  60001 				v15 = int32(255)
  60002 			}
  60003 			v14 = v15
  60004 		}
  60005 		v12 = v14
  60006 		goto _13
  60007 	_13:
  60008 		v9 = v12
  60009 		goto _10
  60010 	_10:
  60011 		tmp_v = v9
  60012 		if do_store != 0 {
  60013 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32(tmp_u)
  60014 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32(tmp_v)
  60015 		} else {
  60016 			// Approximated average-of-four. But it's an acceptable diff.
  60017 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u + int32(1)) >> int32(1))
  60018 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v + int32(1)) >> int32(1))
  60019 		}
  60020 		goto _1
  60021 	_1:
  60022 		;
  60023 		i = i + 1
  60024 	}
  60025 	if src_width&int32(1) != 0 { // last pixel
  60026 		v01 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60027 		r3 = libc.Int32FromUint32(v01 >> libc.Int32FromInt32(14) & uint32(0x3fc))
  60028 		g3 = libc.Int32FromUint32(v01 >> libc.Int32FromInt32(6) & uint32(0x3fc))
  60029 		b3 = libc.Int32FromUint32(v01 << libc.Int32FromInt32(2) & uint32(0x3fc))
  60030 		u = -int32(9719)*r3 - int32(19081)*g3 + int32(28800)*b3
  60031 		v4 = u
  60032 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60033 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60034 			v7 = v4
  60035 		} else {
  60036 			if v4 < 0 {
  60037 				v8 = 0
  60038 			} else {
  60039 				v8 = int32(255)
  60040 			}
  60041 			v7 = v8
  60042 		}
  60043 		v5 = v7
  60044 		goto _20
  60045 	_20:
  60046 		v2 = v5
  60047 		goto _17
  60048 	_17:
  60049 		tmp_u1 = v2
  60050 		v = +libc.Int32FromInt32(28800)*r3 - int32(24116)*g3 - int32(4684)*b3
  60051 		v111 = v
  60052 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60053 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60054 			v14 = v111
  60055 		} else {
  60056 			if v111 < 0 {
  60057 				v15 = 0
  60058 			} else {
  60059 				v15 = int32(255)
  60060 			}
  60061 			v14 = v15
  60062 		}
  60063 		v12 = v14
  60064 		goto _27
  60065 	_27:
  60066 		v9 = v12
  60067 		goto _24
  60068 	_24:
  60069 		tmp_v1 = v9
  60070 		if do_store != 0 {
  60071 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32(tmp_u1)
  60072 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32(tmp_v1)
  60073 		} else {
  60074 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u1 + int32(1)) >> int32(1))
  60075 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v1 + int32(1)) >> int32(1))
  60076 		}
  60077 	}
  60078 }
  60079 
  60080 //-----------------------------------------------------------------------------
  60081 
  60082 func ConvertRGB24ToY_C(tls *libc.TLS, rgb uintptr, y uintptr, width int32) {
  60083 	var i, luma, v2 int32
  60084 	_, _, _ = i, luma, v2
  60085 	i = 0
  60086 	for {
  60087 		if !(i < width) {
  60088 			break
  60089 		}
  60090 		luma = int32(16839)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(rgb))) + int32(33059)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(rgb + 1))) + int32(6420)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(rgb + 2)))
  60091 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60092 		goto _3
  60093 	_3:
  60094 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = libc.Uint8FromInt32(v2)
  60095 		goto _1
  60096 	_1:
  60097 		;
  60098 		i = i + 1
  60099 		rgb = rgb + uintptr(3)
  60100 	}
  60101 }
  60102 
  60103 func ConvertBGR24ToY_C(tls *libc.TLS, bgr uintptr, y uintptr, width int32) {
  60104 	var i, luma, v2 int32
  60105 	_, _, _ = i, luma, v2
  60106 	i = 0
  60107 	for {
  60108 		if !(i < width) {
  60109 			break
  60110 		}
  60111 		luma = int32(16839)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bgr + 2))) + int32(33059)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bgr + 1))) + int32(6420)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bgr)))
  60112 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60113 		goto _3
  60114 	_3:
  60115 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = libc.Uint8FromInt32(v2)
  60116 		goto _1
  60117 	_1:
  60118 		;
  60119 		i = i + 1
  60120 		bgr = bgr + uintptr(3)
  60121 	}
  60122 }
  60123 
  60124 func WebPConvertRGBA32ToUV_C(tls *libc.TLS, rgb uintptr, u1 uintptr, v1 uintptr, width int32) {
  60125 	var b2, g2, i, r2, u, v, v2, v4, v5, v7, v8 int32
  60126 	_, _, _, _, _, _, _, _, _, _, _ = b2, g2, i, r2, u, v, v2, v4, v5, v7, v8
  60127 	i = 0
  60128 	for {
  60129 		if !(i < width) {
  60130 			break
  60131 		}
  60132 		r2 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb)))
  60133 		g2 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  60134 		b2 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  60135 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60136 		v4 = u
  60137 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60138 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60139 			v7 = v4
  60140 		} else {
  60141 			if v4 < 0 {
  60142 				v8 = 0
  60143 			} else {
  60144 				v8 = int32(255)
  60145 			}
  60146 			v7 = v8
  60147 		}
  60148 		v5 = v7
  60149 		goto _6
  60150 	_6:
  60151 		v2 = v5
  60152 		goto _3
  60153 	_3:
  60154 		**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32(v2)
  60155 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60156 		v4 = v
  60157 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60158 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60159 			v7 = v4
  60160 		} else {
  60161 			if v4 < 0 {
  60162 				v8 = 0
  60163 			} else {
  60164 				v8 = int32(255)
  60165 			}
  60166 			v7 = v8
  60167 		}
  60168 		v5 = v7
  60169 		goto _13
  60170 	_13:
  60171 		v2 = v5
  60172 		goto _10
  60173 	_10:
  60174 		**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32(v2)
  60175 		goto _1
  60176 	_1:
  60177 		;
  60178 		i = i + int32(1)
  60179 		rgb = rgb + uintptr(4)*2
  60180 	}
  60181 }
  60182 
  60183 func WebPInitConvertARGBToYUV(tls *libc.TLS) {
  60184 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60185 		goto _1
  60186 	}
  60187 	WebPInitConvertARGBToYUV_body(tls)
  60188 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60189 	goto _2
  60190 _2:
  60191 	;
  60192 	goto _1
  60193 _1: /**/ //
  60194 }
  60195 
  60196 var WebPInitConvertARGBToYUV_body_last_cpuinfo_used = uintptr(0)
  60197 
  60198 func init() {
  60199 	p := unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)
  60200 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))
  60201 }
  60202 
  60203 func WebPInitConvertARGBToYUV_body(tls *libc.TLS) {
  60204 	WebPConvertARGBToY = __ccgo_fp(ConvertARGBToY_C)
  60205 	WebPConvertARGBToUV = __ccgo_fp(WebPConvertARGBToUV_C)
  60206 	WebPConvertRGB24ToY = __ccgo_fp(ConvertRGB24ToY_C)
  60207 	WebPConvertBGR24ToY = __ccgo_fp(ConvertBGR24ToY_C)
  60208 	WebPConvertRGBA32ToUV = __ccgo_fp(WebPConvertRGBA32ToUV_C)
  60209 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60210 	}
  60211 }
  60212 
  60213 func WebPInitSamplersMIPS32(tls *libc.TLS) {
  60214 }
  60215 
  60216 func WebPInitSamplersMIPSdspR2(tls *libc.TLS) {
  60217 }
  60218 
  60219 func WebPInitConvertARGBToYUVNEON(tls *libc.TLS) {
  60220 }
  60221 
  60222 func WebPInitSamplersSSE2(tls *libc.TLS) {
  60223 }
  60224 
  60225 func WebPInitConvertARGBToYUVSSE2(tls *libc.TLS) {
  60226 }
  60227 
  60228 func WebPInitSamplersSSE41(tls *libc.TLS) {
  60229 }
  60230 
  60231 func WebPInitConvertARGBToYUVSSE41(tls *libc.TLS) {
  60232 }
  60233 
  60234 type __ccgo_fp__XSharpYuvInit_0 = func(*libc.TLS, int32) int32
  60235 
  60236 func SharpYuvInit(tls *libc.TLS, __ccgo_fp_cpu_info_func VP8CPUInfo) {
  60237 	_ = __ccgo_fp_cpu_info_func
  60238 }
  60239 
  60240 func SharpYuvGetConversionMatrix(tls *libc.TLS, matrix_type SharpYuvMatrixType) (r uintptr) {
  60241 	_ = matrix_type
  60242 	return libc.UintptrFromInt32(0)
  60243 }
  60244 
  60245 func SharpYuvConvert(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, rgb_step int32, rgb_stride int32, rgb_bit_depth int32, y_ptr uintptr, y_stride int32, u_ptr uintptr, u_stride int32, v_ptr uintptr, v_stride int32, yuv_bit_depth int32, width int32, height int32, yuv_matrix uintptr) (r int32) {
  60246 	_ = r_ptr
  60247 	_ = g_ptr
  60248 	_ = b_ptr
  60249 	_ = rgb_step
  60250 	_ = rgb_stride
  60251 	_ = rgb_bit_depth
  60252 	_ = y_ptr
  60253 	_ = y_stride
  60254 	_ = u_ptr
  60255 	_ = u_stride
  60256 	_ = v_ptr
  60257 	_ = v_stride
  60258 	_ = yuv_bit_depth
  60259 	_ = width
  60260 	_ = height
  60261 	_ = yuv_matrix
  60262 	return 0
  60263 }
  60264 
  60265 func __ccgo_fp(f interface{}) uintptr {
  60266 	type iface [2]uintptr
  60267 	return (*iface)(unsafe.Pointer(&f))[1]
  60268 }
  60269 
  60270 func __ccgo_up(n uintptr) unsafe.Pointer {
  60271 	return unsafe.Pointer(&n)
  60272 }
  60273 
  60274 var VP8AccumulateSSE VP8AccumulateSSEFunc
  60275 
  60276 //------------------------------------------------------------------------------
  60277 // Tables for level coding
  60278 
  60279 var VP8Cat3 = [3]uint8_t{
  60280 	0: uint8(173),
  60281 	1: uint8(148),
  60282 	2: uint8(140),
  60283 }
  60284 
  60285 var VP8Cat4 = [4]uint8_t{
  60286 	0: uint8(176),
  60287 	1: uint8(155),
  60288 	2: uint8(140),
  60289 	3: uint8(135),
  60290 }
  60291 
  60292 var VP8Cat5 = [5]uint8_t{
  60293 	0: uint8(180),
  60294 	1: uint8(157),
  60295 	2: uint8(141),
  60296 	3: uint8(134),
  60297 	4: uint8(130),
  60298 }
  60299 
  60300 var VP8Cat6 = [11]uint8_t{
  60301 	0:  uint8(254),
  60302 	1:  uint8(254),
  60303 	2:  uint8(243),
  60304 	3:  uint8(230),
  60305 	4:  uint8(196),
  60306 	5:  uint8(177),
  60307 	6:  uint8(153),
  60308 	7:  uint8(140),
  60309 	8:  uint8(133),
  60310 	9:  uint8(130),
  60311 	10: uint8(129),
  60312 }
  60313 
  60314 //------------------------------------------------------------------------------
  60315 
  60316 // Copyright 2011 Google Inc. All Rights Reserved.
  60317 //
  60318 // Use of this source code is governed by a BSD-style license
  60319 // that can be found in the COPYING file in the root of the source
  60320 // tree. An additional intellectual property rights grant can be found
  60321 // in the file PATENTS. All contributing project authors may
  60322 // be found in the AUTHORS file in the root of the source tree.
  60323 // -----------------------------------------------------------------------------
  60324 //
  60325 // Bit writing and boolean coder
  60326 //
  60327 // Author: Skal (pascal.massimino@gmail.com)
  60328 
  60329 //------------------------------------------------------------------------------
  60330 // Default probabilities
  60331 
  60332 // C documentation
  60333 //
  60334 //	// Paragraph 13.5
  60335 
  60336 var VP8CoeffsProba0 = [4][8][3][11]uint8_t{
  60337 	0: {
  60338 		0: {
  60339 			0: {
  60340 				0:  uint8(128),
  60341 				1:  uint8(128),
  60342 				2:  uint8(128),
  60343 				3:  uint8(128),
  60344 				4:  uint8(128),
  60345 				5:  uint8(128),
  60346 				6:  uint8(128),
  60347 				7:  uint8(128),
  60348 				8:  uint8(128),
  60349 				9:  uint8(128),
  60350 				10: uint8(128),
  60351 			},
  60352 			1: {
  60353 				0:  uint8(128),
  60354 				1:  uint8(128),
  60355 				2:  uint8(128),
  60356 				3:  uint8(128),
  60357 				4:  uint8(128),
  60358 				5:  uint8(128),
  60359 				6:  uint8(128),
  60360 				7:  uint8(128),
  60361 				8:  uint8(128),
  60362 				9:  uint8(128),
  60363 				10: uint8(128),
  60364 			},
  60365 			2: {
  60366 				0:  uint8(128),
  60367 				1:  uint8(128),
  60368 				2:  uint8(128),
  60369 				3:  uint8(128),
  60370 				4:  uint8(128),
  60371 				5:  uint8(128),
  60372 				6:  uint8(128),
  60373 				7:  uint8(128),
  60374 				8:  uint8(128),
  60375 				9:  uint8(128),
  60376 				10: uint8(128),
  60377 			},
  60378 		},
  60379 		1: {
  60380 			0: {
  60381 				0:  uint8(253),
  60382 				1:  uint8(136),
  60383 				2:  uint8(254),
  60384 				3:  uint8(255),
  60385 				4:  uint8(228),
  60386 				5:  uint8(219),
  60387 				6:  uint8(128),
  60388 				7:  uint8(128),
  60389 				8:  uint8(128),
  60390 				9:  uint8(128),
  60391 				10: uint8(128),
  60392 			},
  60393 			1: {
  60394 				0:  uint8(189),
  60395 				1:  uint8(129),
  60396 				2:  uint8(242),
  60397 				3:  uint8(255),
  60398 				4:  uint8(227),
  60399 				5:  uint8(213),
  60400 				6:  uint8(255),
  60401 				7:  uint8(219),
  60402 				8:  uint8(128),
  60403 				9:  uint8(128),
  60404 				10: uint8(128),
  60405 			},
  60406 			2: {
  60407 				0:  uint8(106),
  60408 				1:  uint8(126),
  60409 				2:  uint8(227),
  60410 				3:  uint8(252),
  60411 				4:  uint8(214),
  60412 				5:  uint8(209),
  60413 				6:  uint8(255),
  60414 				7:  uint8(255),
  60415 				8:  uint8(128),
  60416 				9:  uint8(128),
  60417 				10: uint8(128),
  60418 			},
  60419 		},
  60420 		2: {
  60421 			0: {
  60422 				0:  uint8(1),
  60423 				1:  uint8(98),
  60424 				2:  uint8(248),
  60425 				3:  uint8(255),
  60426 				4:  uint8(236),
  60427 				5:  uint8(226),
  60428 				6:  uint8(255),
  60429 				7:  uint8(255),
  60430 				8:  uint8(128),
  60431 				9:  uint8(128),
  60432 				10: uint8(128),
  60433 			},
  60434 			1: {
  60435 				0:  uint8(181),
  60436 				1:  uint8(133),
  60437 				2:  uint8(238),
  60438 				3:  uint8(254),
  60439 				4:  uint8(221),
  60440 				5:  uint8(234),
  60441 				6:  uint8(255),
  60442 				7:  uint8(154),
  60443 				8:  uint8(128),
  60444 				9:  uint8(128),
  60445 				10: uint8(128),
  60446 			},
  60447 			2: {
  60448 				0:  uint8(78),
  60449 				1:  uint8(134),
  60450 				2:  uint8(202),
  60451 				3:  uint8(247),
  60452 				4:  uint8(198),
  60453 				5:  uint8(180),
  60454 				6:  uint8(255),
  60455 				7:  uint8(219),
  60456 				8:  uint8(128),
  60457 				9:  uint8(128),
  60458 				10: uint8(128),
  60459 			},
  60460 		},
  60461 		3: {
  60462 			0: {
  60463 				0:  uint8(1),
  60464 				1:  uint8(185),
  60465 				2:  uint8(249),
  60466 				3:  uint8(255),
  60467 				4:  uint8(243),
  60468 				5:  uint8(255),
  60469 				6:  uint8(128),
  60470 				7:  uint8(128),
  60471 				8:  uint8(128),
  60472 				9:  uint8(128),
  60473 				10: uint8(128),
  60474 			},
  60475 			1: {
  60476 				0:  uint8(184),
  60477 				1:  uint8(150),
  60478 				2:  uint8(247),
  60479 				3:  uint8(255),
  60480 				4:  uint8(236),
  60481 				5:  uint8(224),
  60482 				6:  uint8(128),
  60483 				7:  uint8(128),
  60484 				8:  uint8(128),
  60485 				9:  uint8(128),
  60486 				10: uint8(128),
  60487 			},
  60488 			2: {
  60489 				0:  uint8(77),
  60490 				1:  uint8(110),
  60491 				2:  uint8(216),
  60492 				3:  uint8(255),
  60493 				4:  uint8(236),
  60494 				5:  uint8(230),
  60495 				6:  uint8(128),
  60496 				7:  uint8(128),
  60497 				8:  uint8(128),
  60498 				9:  uint8(128),
  60499 				10: uint8(128),
  60500 			},
  60501 		},
  60502 		4: {
  60503 			0: {
  60504 				0:  uint8(1),
  60505 				1:  uint8(101),
  60506 				2:  uint8(251),
  60507 				3:  uint8(255),
  60508 				4:  uint8(241),
  60509 				5:  uint8(255),
  60510 				6:  uint8(128),
  60511 				7:  uint8(128),
  60512 				8:  uint8(128),
  60513 				9:  uint8(128),
  60514 				10: uint8(128),
  60515 			},
  60516 			1: {
  60517 				0:  uint8(170),
  60518 				1:  uint8(139),
  60519 				2:  uint8(241),
  60520 				3:  uint8(252),
  60521 				4:  uint8(236),
  60522 				5:  uint8(209),
  60523 				6:  uint8(255),
  60524 				7:  uint8(255),
  60525 				8:  uint8(128),
  60526 				9:  uint8(128),
  60527 				10: uint8(128),
  60528 			},
  60529 			2: {
  60530 				0:  uint8(37),
  60531 				1:  uint8(116),
  60532 				2:  uint8(196),
  60533 				3:  uint8(243),
  60534 				4:  uint8(228),
  60535 				5:  uint8(255),
  60536 				6:  uint8(255),
  60537 				7:  uint8(255),
  60538 				8:  uint8(128),
  60539 				9:  uint8(128),
  60540 				10: uint8(128),
  60541 			},
  60542 		},
  60543 		5: {
  60544 			0: {
  60545 				0:  uint8(1),
  60546 				1:  uint8(204),
  60547 				2:  uint8(254),
  60548 				3:  uint8(255),
  60549 				4:  uint8(245),
  60550 				5:  uint8(255),
  60551 				6:  uint8(128),
  60552 				7:  uint8(128),
  60553 				8:  uint8(128),
  60554 				9:  uint8(128),
  60555 				10: uint8(128),
  60556 			},
  60557 			1: {
  60558 				0:  uint8(207),
  60559 				1:  uint8(160),
  60560 				2:  uint8(250),
  60561 				3:  uint8(255),
  60562 				4:  uint8(238),
  60563 				5:  uint8(128),
  60564 				6:  uint8(128),
  60565 				7:  uint8(128),
  60566 				8:  uint8(128),
  60567 				9:  uint8(128),
  60568 				10: uint8(128),
  60569 			},
  60570 			2: {
  60571 				0:  uint8(102),
  60572 				1:  uint8(103),
  60573 				2:  uint8(231),
  60574 				3:  uint8(255),
  60575 				4:  uint8(211),
  60576 				5:  uint8(171),
  60577 				6:  uint8(128),
  60578 				7:  uint8(128),
  60579 				8:  uint8(128),
  60580 				9:  uint8(128),
  60581 				10: uint8(128),
  60582 			},
  60583 		},
  60584 		6: {
  60585 			0: {
  60586 				0:  uint8(1),
  60587 				1:  uint8(152),
  60588 				2:  uint8(252),
  60589 				3:  uint8(255),
  60590 				4:  uint8(240),
  60591 				5:  uint8(255),
  60592 				6:  uint8(128),
  60593 				7:  uint8(128),
  60594 				8:  uint8(128),
  60595 				9:  uint8(128),
  60596 				10: uint8(128),
  60597 			},
  60598 			1: {
  60599 				0:  uint8(177),
  60600 				1:  uint8(135),
  60601 				2:  uint8(243),
  60602 				3:  uint8(255),
  60603 				4:  uint8(234),
  60604 				5:  uint8(225),
  60605 				6:  uint8(128),
  60606 				7:  uint8(128),
  60607 				8:  uint8(128),
  60608 				9:  uint8(128),
  60609 				10: uint8(128),
  60610 			},
  60611 			2: {
  60612 				0:  uint8(80),
  60613 				1:  uint8(129),
  60614 				2:  uint8(211),
  60615 				3:  uint8(255),
  60616 				4:  uint8(194),
  60617 				5:  uint8(224),
  60618 				6:  uint8(128),
  60619 				7:  uint8(128),
  60620 				8:  uint8(128),
  60621 				9:  uint8(128),
  60622 				10: uint8(128),
  60623 			},
  60624 		},
  60625 		7: {
  60626 			0: {
  60627 				0:  uint8(1),
  60628 				1:  uint8(1),
  60629 				2:  uint8(255),
  60630 				3:  uint8(128),
  60631 				4:  uint8(128),
  60632 				5:  uint8(128),
  60633 				6:  uint8(128),
  60634 				7:  uint8(128),
  60635 				8:  uint8(128),
  60636 				9:  uint8(128),
  60637 				10: uint8(128),
  60638 			},
  60639 			1: {
  60640 				0:  uint8(246),
  60641 				1:  uint8(1),
  60642 				2:  uint8(255),
  60643 				3:  uint8(128),
  60644 				4:  uint8(128),
  60645 				5:  uint8(128),
  60646 				6:  uint8(128),
  60647 				7:  uint8(128),
  60648 				8:  uint8(128),
  60649 				9:  uint8(128),
  60650 				10: uint8(128),
  60651 			},
  60652 			2: {
  60653 				0:  uint8(255),
  60654 				1:  uint8(128),
  60655 				2:  uint8(128),
  60656 				3:  uint8(128),
  60657 				4:  uint8(128),
  60658 				5:  uint8(128),
  60659 				6:  uint8(128),
  60660 				7:  uint8(128),
  60661 				8:  uint8(128),
  60662 				9:  uint8(128),
  60663 				10: uint8(128),
  60664 			},
  60665 		},
  60666 	},
  60667 	1: {
  60668 		0: {
  60669 			0: {
  60670 				0:  uint8(198),
  60671 				1:  uint8(35),
  60672 				2:  uint8(237),
  60673 				3:  uint8(223),
  60674 				4:  uint8(193),
  60675 				5:  uint8(187),
  60676 				6:  uint8(162),
  60677 				7:  uint8(160),
  60678 				8:  uint8(145),
  60679 				9:  uint8(155),
  60680 				10: uint8(62),
  60681 			},
  60682 			1: {
  60683 				0:  uint8(131),
  60684 				1:  uint8(45),
  60685 				2:  uint8(198),
  60686 				3:  uint8(221),
  60687 				4:  uint8(172),
  60688 				5:  uint8(176),
  60689 				6:  uint8(220),
  60690 				7:  uint8(157),
  60691 				8:  uint8(252),
  60692 				9:  uint8(221),
  60693 				10: uint8(1),
  60694 			},
  60695 			2: {
  60696 				0:  uint8(68),
  60697 				1:  uint8(47),
  60698 				2:  uint8(146),
  60699 				3:  uint8(208),
  60700 				4:  uint8(149),
  60701 				5:  uint8(167),
  60702 				6:  uint8(221),
  60703 				7:  uint8(162),
  60704 				8:  uint8(255),
  60705 				9:  uint8(223),
  60706 				10: uint8(128),
  60707 			},
  60708 		},
  60709 		1: {
  60710 			0: {
  60711 				0:  uint8(1),
  60712 				1:  uint8(149),
  60713 				2:  uint8(241),
  60714 				3:  uint8(255),
  60715 				4:  uint8(221),
  60716 				5:  uint8(224),
  60717 				6:  uint8(255),
  60718 				7:  uint8(255),
  60719 				8:  uint8(128),
  60720 				9:  uint8(128),
  60721 				10: uint8(128),
  60722 			},
  60723 			1: {
  60724 				0:  uint8(184),
  60725 				1:  uint8(141),
  60726 				2:  uint8(234),
  60727 				3:  uint8(253),
  60728 				4:  uint8(222),
  60729 				5:  uint8(220),
  60730 				6:  uint8(255),
  60731 				7:  uint8(199),
  60732 				8:  uint8(128),
  60733 				9:  uint8(128),
  60734 				10: uint8(128),
  60735 			},
  60736 			2: {
  60737 				0:  uint8(81),
  60738 				1:  uint8(99),
  60739 				2:  uint8(181),
  60740 				3:  uint8(242),
  60741 				4:  uint8(176),
  60742 				5:  uint8(190),
  60743 				6:  uint8(249),
  60744 				7:  uint8(202),
  60745 				8:  uint8(255),
  60746 				9:  uint8(255),
  60747 				10: uint8(128),
  60748 			},
  60749 		},
  60750 		2: {
  60751 			0: {
  60752 				0:  uint8(1),
  60753 				1:  uint8(129),
  60754 				2:  uint8(232),
  60755 				3:  uint8(253),
  60756 				4:  uint8(214),
  60757 				5:  uint8(197),
  60758 				6:  uint8(242),
  60759 				7:  uint8(196),
  60760 				8:  uint8(255),
  60761 				9:  uint8(255),
  60762 				10: uint8(128),
  60763 			},
  60764 			1: {
  60765 				0:  uint8(99),
  60766 				1:  uint8(121),
  60767 				2:  uint8(210),
  60768 				3:  uint8(250),
  60769 				4:  uint8(201),
  60770 				5:  uint8(198),
  60771 				6:  uint8(255),
  60772 				7:  uint8(202),
  60773 				8:  uint8(128),
  60774 				9:  uint8(128),
  60775 				10: uint8(128),
  60776 			},
  60777 			2: {
  60778 				0:  uint8(23),
  60779 				1:  uint8(91),
  60780 				2:  uint8(163),
  60781 				3:  uint8(242),
  60782 				4:  uint8(170),
  60783 				5:  uint8(187),
  60784 				6:  uint8(247),
  60785 				7:  uint8(210),
  60786 				8:  uint8(255),
  60787 				9:  uint8(255),
  60788 				10: uint8(128),
  60789 			},
  60790 		},
  60791 		3: {
  60792 			0: {
  60793 				0:  uint8(1),
  60794 				1:  uint8(200),
  60795 				2:  uint8(246),
  60796 				3:  uint8(255),
  60797 				4:  uint8(234),
  60798 				5:  uint8(255),
  60799 				6:  uint8(128),
  60800 				7:  uint8(128),
  60801 				8:  uint8(128),
  60802 				9:  uint8(128),
  60803 				10: uint8(128),
  60804 			},
  60805 			1: {
  60806 				0:  uint8(109),
  60807 				1:  uint8(178),
  60808 				2:  uint8(241),
  60809 				3:  uint8(255),
  60810 				4:  uint8(231),
  60811 				5:  uint8(245),
  60812 				6:  uint8(255),
  60813 				7:  uint8(255),
  60814 				8:  uint8(128),
  60815 				9:  uint8(128),
  60816 				10: uint8(128),
  60817 			},
  60818 			2: {
  60819 				0:  uint8(44),
  60820 				1:  uint8(130),
  60821 				2:  uint8(201),
  60822 				3:  uint8(253),
  60823 				4:  uint8(205),
  60824 				5:  uint8(192),
  60825 				6:  uint8(255),
  60826 				7:  uint8(255),
  60827 				8:  uint8(128),
  60828 				9:  uint8(128),
  60829 				10: uint8(128),
  60830 			},
  60831 		},
  60832 		4: {
  60833 			0: {
  60834 				0:  uint8(1),
  60835 				1:  uint8(132),
  60836 				2:  uint8(239),
  60837 				3:  uint8(251),
  60838 				4:  uint8(219),
  60839 				5:  uint8(209),
  60840 				6:  uint8(255),
  60841 				7:  uint8(165),
  60842 				8:  uint8(128),
  60843 				9:  uint8(128),
  60844 				10: uint8(128),
  60845 			},
  60846 			1: {
  60847 				0:  uint8(94),
  60848 				1:  uint8(136),
  60849 				2:  uint8(225),
  60850 				3:  uint8(251),
  60851 				4:  uint8(218),
  60852 				5:  uint8(190),
  60853 				6:  uint8(255),
  60854 				7:  uint8(255),
  60855 				8:  uint8(128),
  60856 				9:  uint8(128),
  60857 				10: uint8(128),
  60858 			},
  60859 			2: {
  60860 				0:  uint8(22),
  60861 				1:  uint8(100),
  60862 				2:  uint8(174),
  60863 				3:  uint8(245),
  60864 				4:  uint8(186),
  60865 				5:  uint8(161),
  60866 				6:  uint8(255),
  60867 				7:  uint8(199),
  60868 				8:  uint8(128),
  60869 				9:  uint8(128),
  60870 				10: uint8(128),
  60871 			},
  60872 		},
  60873 		5: {
  60874 			0: {
  60875 				0:  uint8(1),
  60876 				1:  uint8(182),
  60877 				2:  uint8(249),
  60878 				3:  uint8(255),
  60879 				4:  uint8(232),
  60880 				5:  uint8(235),
  60881 				6:  uint8(128),
  60882 				7:  uint8(128),
  60883 				8:  uint8(128),
  60884 				9:  uint8(128),
  60885 				10: uint8(128),
  60886 			},
  60887 			1: {
  60888 				0:  uint8(124),
  60889 				1:  uint8(143),
  60890 				2:  uint8(241),
  60891 				3:  uint8(255),
  60892 				4:  uint8(227),
  60893 				5:  uint8(234),
  60894 				6:  uint8(128),
  60895 				7:  uint8(128),
  60896 				8:  uint8(128),
  60897 				9:  uint8(128),
  60898 				10: uint8(128),
  60899 			},
  60900 			2: {
  60901 				0:  uint8(35),
  60902 				1:  uint8(77),
  60903 				2:  uint8(181),
  60904 				3:  uint8(251),
  60905 				4:  uint8(193),
  60906 				5:  uint8(211),
  60907 				6:  uint8(255),
  60908 				7:  uint8(205),
  60909 				8:  uint8(128),
  60910 				9:  uint8(128),
  60911 				10: uint8(128),
  60912 			},
  60913 		},
  60914 		6: {
  60915 			0: {
  60916 				0:  uint8(1),
  60917 				1:  uint8(157),
  60918 				2:  uint8(247),
  60919 				3:  uint8(255),
  60920 				4:  uint8(236),
  60921 				5:  uint8(231),
  60922 				6:  uint8(255),
  60923 				7:  uint8(255),
  60924 				8:  uint8(128),
  60925 				9:  uint8(128),
  60926 				10: uint8(128),
  60927 			},
  60928 			1: {
  60929 				0:  uint8(121),
  60930 				1:  uint8(141),
  60931 				2:  uint8(235),
  60932 				3:  uint8(255),
  60933 				4:  uint8(225),
  60934 				5:  uint8(227),
  60935 				6:  uint8(255),
  60936 				7:  uint8(255),
  60937 				8:  uint8(128),
  60938 				9:  uint8(128),
  60939 				10: uint8(128),
  60940 			},
  60941 			2: {
  60942 				0:  uint8(45),
  60943 				1:  uint8(99),
  60944 				2:  uint8(188),
  60945 				3:  uint8(251),
  60946 				4:  uint8(195),
  60947 				5:  uint8(217),
  60948 				6:  uint8(255),
  60949 				7:  uint8(224),
  60950 				8:  uint8(128),
  60951 				9:  uint8(128),
  60952 				10: uint8(128),
  60953 			},
  60954 		},
  60955 		7: {
  60956 			0: {
  60957 				0:  uint8(1),
  60958 				1:  uint8(1),
  60959 				2:  uint8(251),
  60960 				3:  uint8(255),
  60961 				4:  uint8(213),
  60962 				5:  uint8(255),
  60963 				6:  uint8(128),
  60964 				7:  uint8(128),
  60965 				8:  uint8(128),
  60966 				9:  uint8(128),
  60967 				10: uint8(128),
  60968 			},
  60969 			1: {
  60970 				0:  uint8(203),
  60971 				1:  uint8(1),
  60972 				2:  uint8(248),
  60973 				3:  uint8(255),
  60974 				4:  uint8(255),
  60975 				5:  uint8(128),
  60976 				6:  uint8(128),
  60977 				7:  uint8(128),
  60978 				8:  uint8(128),
  60979 				9:  uint8(128),
  60980 				10: uint8(128),
  60981 			},
  60982 			2: {
  60983 				0:  uint8(137),
  60984 				1:  uint8(1),
  60985 				2:  uint8(177),
  60986 				3:  uint8(255),
  60987 				4:  uint8(224),
  60988 				5:  uint8(255),
  60989 				6:  uint8(128),
  60990 				7:  uint8(128),
  60991 				8:  uint8(128),
  60992 				9:  uint8(128),
  60993 				10: uint8(128),
  60994 			},
  60995 		},
  60996 	},
  60997 	2: {
  60998 		0: {
  60999 			0: {
  61000 				0:  uint8(253),
  61001 				1:  uint8(9),
  61002 				2:  uint8(248),
  61003 				3:  uint8(251),
  61004 				4:  uint8(207),
  61005 				5:  uint8(208),
  61006 				6:  uint8(255),
  61007 				7:  uint8(192),
  61008 				8:  uint8(128),
  61009 				9:  uint8(128),
  61010 				10: uint8(128),
  61011 			},
  61012 			1: {
  61013 				0:  uint8(175),
  61014 				1:  uint8(13),
  61015 				2:  uint8(224),
  61016 				3:  uint8(243),
  61017 				4:  uint8(193),
  61018 				5:  uint8(185),
  61019 				6:  uint8(249),
  61020 				7:  uint8(198),
  61021 				8:  uint8(255),
  61022 				9:  uint8(255),
  61023 				10: uint8(128),
  61024 			},
  61025 			2: {
  61026 				0:  uint8(73),
  61027 				1:  uint8(17),
  61028 				2:  uint8(171),
  61029 				3:  uint8(221),
  61030 				4:  uint8(161),
  61031 				5:  uint8(179),
  61032 				6:  uint8(236),
  61033 				7:  uint8(167),
  61034 				8:  uint8(255),
  61035 				9:  uint8(234),
  61036 				10: uint8(128),
  61037 			},
  61038 		},
  61039 		1: {
  61040 			0: {
  61041 				0:  uint8(1),
  61042 				1:  uint8(95),
  61043 				2:  uint8(247),
  61044 				3:  uint8(253),
  61045 				4:  uint8(212),
  61046 				5:  uint8(183),
  61047 				6:  uint8(255),
  61048 				7:  uint8(255),
  61049 				8:  uint8(128),
  61050 				9:  uint8(128),
  61051 				10: uint8(128),
  61052 			},
  61053 			1: {
  61054 				0:  uint8(239),
  61055 				1:  uint8(90),
  61056 				2:  uint8(244),
  61057 				3:  uint8(250),
  61058 				4:  uint8(211),
  61059 				5:  uint8(209),
  61060 				6:  uint8(255),
  61061 				7:  uint8(255),
  61062 				8:  uint8(128),
  61063 				9:  uint8(128),
  61064 				10: uint8(128),
  61065 			},
  61066 			2: {
  61067 				0:  uint8(155),
  61068 				1:  uint8(77),
  61069 				2:  uint8(195),
  61070 				3:  uint8(248),
  61071 				4:  uint8(188),
  61072 				5:  uint8(195),
  61073 				6:  uint8(255),
  61074 				7:  uint8(255),
  61075 				8:  uint8(128),
  61076 				9:  uint8(128),
  61077 				10: uint8(128),
  61078 			},
  61079 		},
  61080 		2: {
  61081 			0: {
  61082 				0:  uint8(1),
  61083 				1:  uint8(24),
  61084 				2:  uint8(239),
  61085 				3:  uint8(251),
  61086 				4:  uint8(218),
  61087 				5:  uint8(219),
  61088 				6:  uint8(255),
  61089 				7:  uint8(205),
  61090 				8:  uint8(128),
  61091 				9:  uint8(128),
  61092 				10: uint8(128),
  61093 			},
  61094 			1: {
  61095 				0:  uint8(201),
  61096 				1:  uint8(51),
  61097 				2:  uint8(219),
  61098 				3:  uint8(255),
  61099 				4:  uint8(196),
  61100 				5:  uint8(186),
  61101 				6:  uint8(128),
  61102 				7:  uint8(128),
  61103 				8:  uint8(128),
  61104 				9:  uint8(128),
  61105 				10: uint8(128),
  61106 			},
  61107 			2: {
  61108 				0:  uint8(69),
  61109 				1:  uint8(46),
  61110 				2:  uint8(190),
  61111 				3:  uint8(239),
  61112 				4:  uint8(201),
  61113 				5:  uint8(218),
  61114 				6:  uint8(255),
  61115 				7:  uint8(228),
  61116 				8:  uint8(128),
  61117 				9:  uint8(128),
  61118 				10: uint8(128),
  61119 			},
  61120 		},
  61121 		3: {
  61122 			0: {
  61123 				0:  uint8(1),
  61124 				1:  uint8(191),
  61125 				2:  uint8(251),
  61126 				3:  uint8(255),
  61127 				4:  uint8(255),
  61128 				5:  uint8(128),
  61129 				6:  uint8(128),
  61130 				7:  uint8(128),
  61131 				8:  uint8(128),
  61132 				9:  uint8(128),
  61133 				10: uint8(128),
  61134 			},
  61135 			1: {
  61136 				0:  uint8(223),
  61137 				1:  uint8(165),
  61138 				2:  uint8(249),
  61139 				3:  uint8(255),
  61140 				4:  uint8(213),
  61141 				5:  uint8(255),
  61142 				6:  uint8(128),
  61143 				7:  uint8(128),
  61144 				8:  uint8(128),
  61145 				9:  uint8(128),
  61146 				10: uint8(128),
  61147 			},
  61148 			2: {
  61149 				0:  uint8(141),
  61150 				1:  uint8(124),
  61151 				2:  uint8(248),
  61152 				3:  uint8(255),
  61153 				4:  uint8(255),
  61154 				5:  uint8(128),
  61155 				6:  uint8(128),
  61156 				7:  uint8(128),
  61157 				8:  uint8(128),
  61158 				9:  uint8(128),
  61159 				10: uint8(128),
  61160 			},
  61161 		},
  61162 		4: {
  61163 			0: {
  61164 				0:  uint8(1),
  61165 				1:  uint8(16),
  61166 				2:  uint8(248),
  61167 				3:  uint8(255),
  61168 				4:  uint8(255),
  61169 				5:  uint8(128),
  61170 				6:  uint8(128),
  61171 				7:  uint8(128),
  61172 				8:  uint8(128),
  61173 				9:  uint8(128),
  61174 				10: uint8(128),
  61175 			},
  61176 			1: {
  61177 				0:  uint8(190),
  61178 				1:  uint8(36),
  61179 				2:  uint8(230),
  61180 				3:  uint8(255),
  61181 				4:  uint8(236),
  61182 				5:  uint8(255),
  61183 				6:  uint8(128),
  61184 				7:  uint8(128),
  61185 				8:  uint8(128),
  61186 				9:  uint8(128),
  61187 				10: uint8(128),
  61188 			},
  61189 			2: {
  61190 				0:  uint8(149),
  61191 				1:  uint8(1),
  61192 				2:  uint8(255),
  61193 				3:  uint8(128),
  61194 				4:  uint8(128),
  61195 				5:  uint8(128),
  61196 				6:  uint8(128),
  61197 				7:  uint8(128),
  61198 				8:  uint8(128),
  61199 				9:  uint8(128),
  61200 				10: uint8(128),
  61201 			},
  61202 		},
  61203 		5: {
  61204 			0: {
  61205 				0:  uint8(1),
  61206 				1:  uint8(226),
  61207 				2:  uint8(255),
  61208 				3:  uint8(128),
  61209 				4:  uint8(128),
  61210 				5:  uint8(128),
  61211 				6:  uint8(128),
  61212 				7:  uint8(128),
  61213 				8:  uint8(128),
  61214 				9:  uint8(128),
  61215 				10: uint8(128),
  61216 			},
  61217 			1: {
  61218 				0:  uint8(247),
  61219 				1:  uint8(192),
  61220 				2:  uint8(255),
  61221 				3:  uint8(128),
  61222 				4:  uint8(128),
  61223 				5:  uint8(128),
  61224 				6:  uint8(128),
  61225 				7:  uint8(128),
  61226 				8:  uint8(128),
  61227 				9:  uint8(128),
  61228 				10: uint8(128),
  61229 			},
  61230 			2: {
  61231 				0:  uint8(240),
  61232 				1:  uint8(128),
  61233 				2:  uint8(255),
  61234 				3:  uint8(128),
  61235 				4:  uint8(128),
  61236 				5:  uint8(128),
  61237 				6:  uint8(128),
  61238 				7:  uint8(128),
  61239 				8:  uint8(128),
  61240 				9:  uint8(128),
  61241 				10: uint8(128),
  61242 			},
  61243 		},
  61244 		6: {
  61245 			0: {
  61246 				0:  uint8(1),
  61247 				1:  uint8(134),
  61248 				2:  uint8(252),
  61249 				3:  uint8(255),
  61250 				4:  uint8(255),
  61251 				5:  uint8(128),
  61252 				6:  uint8(128),
  61253 				7:  uint8(128),
  61254 				8:  uint8(128),
  61255 				9:  uint8(128),
  61256 				10: uint8(128),
  61257 			},
  61258 			1: {
  61259 				0:  uint8(213),
  61260 				1:  uint8(62),
  61261 				2:  uint8(250),
  61262 				3:  uint8(255),
  61263 				4:  uint8(255),
  61264 				5:  uint8(128),
  61265 				6:  uint8(128),
  61266 				7:  uint8(128),
  61267 				8:  uint8(128),
  61268 				9:  uint8(128),
  61269 				10: uint8(128),
  61270 			},
  61271 			2: {
  61272 				0:  uint8(55),
  61273 				1:  uint8(93),
  61274 				2:  uint8(255),
  61275 				3:  uint8(128),
  61276 				4:  uint8(128),
  61277 				5:  uint8(128),
  61278 				6:  uint8(128),
  61279 				7:  uint8(128),
  61280 				8:  uint8(128),
  61281 				9:  uint8(128),
  61282 				10: uint8(128),
  61283 			},
  61284 		},
  61285 		7: {
  61286 			0: {
  61287 				0:  uint8(128),
  61288 				1:  uint8(128),
  61289 				2:  uint8(128),
  61290 				3:  uint8(128),
  61291 				4:  uint8(128),
  61292 				5:  uint8(128),
  61293 				6:  uint8(128),
  61294 				7:  uint8(128),
  61295 				8:  uint8(128),
  61296 				9:  uint8(128),
  61297 				10: uint8(128),
  61298 			},
  61299 			1: {
  61300 				0:  uint8(128),
  61301 				1:  uint8(128),
  61302 				2:  uint8(128),
  61303 				3:  uint8(128),
  61304 				4:  uint8(128),
  61305 				5:  uint8(128),
  61306 				6:  uint8(128),
  61307 				7:  uint8(128),
  61308 				8:  uint8(128),
  61309 				9:  uint8(128),
  61310 				10: uint8(128),
  61311 			},
  61312 			2: {
  61313 				0:  uint8(128),
  61314 				1:  uint8(128),
  61315 				2:  uint8(128),
  61316 				3:  uint8(128),
  61317 				4:  uint8(128),
  61318 				5:  uint8(128),
  61319 				6:  uint8(128),
  61320 				7:  uint8(128),
  61321 				8:  uint8(128),
  61322 				9:  uint8(128),
  61323 				10: uint8(128),
  61324 			},
  61325 		},
  61326 	},
  61327 	3: {
  61328 		0: {
  61329 			0: {
  61330 				0:  uint8(202),
  61331 				1:  uint8(24),
  61332 				2:  uint8(213),
  61333 				3:  uint8(235),
  61334 				4:  uint8(186),
  61335 				5:  uint8(191),
  61336 				6:  uint8(220),
  61337 				7:  uint8(160),
  61338 				8:  uint8(240),
  61339 				9:  uint8(175),
  61340 				10: uint8(255),
  61341 			},
  61342 			1: {
  61343 				0:  uint8(126),
  61344 				1:  uint8(38),
  61345 				2:  uint8(182),
  61346 				3:  uint8(232),
  61347 				4:  uint8(169),
  61348 				5:  uint8(184),
  61349 				6:  uint8(228),
  61350 				7:  uint8(174),
  61351 				8:  uint8(255),
  61352 				9:  uint8(187),
  61353 				10: uint8(128),
  61354 			},
  61355 			2: {
  61356 				0:  uint8(61),
  61357 				1:  uint8(46),
  61358 				2:  uint8(138),
  61359 				3:  uint8(219),
  61360 				4:  uint8(151),
  61361 				5:  uint8(178),
  61362 				6:  uint8(240),
  61363 				7:  uint8(170),
  61364 				8:  uint8(255),
  61365 				9:  uint8(216),
  61366 				10: uint8(128),
  61367 			},
  61368 		},
  61369 		1: {
  61370 			0: {
  61371 				0:  uint8(1),
  61372 				1:  uint8(112),
  61373 				2:  uint8(230),
  61374 				3:  uint8(250),
  61375 				4:  uint8(199),
  61376 				5:  uint8(191),
  61377 				6:  uint8(247),
  61378 				7:  uint8(159),
  61379 				8:  uint8(255),
  61380 				9:  uint8(255),
  61381 				10: uint8(128),
  61382 			},
  61383 			1: {
  61384 				0:  uint8(166),
  61385 				1:  uint8(109),
  61386 				2:  uint8(228),
  61387 				3:  uint8(252),
  61388 				4:  uint8(211),
  61389 				5:  uint8(215),
  61390 				6:  uint8(255),
  61391 				7:  uint8(174),
  61392 				8:  uint8(128),
  61393 				9:  uint8(128),
  61394 				10: uint8(128),
  61395 			},
  61396 			2: {
  61397 				0:  uint8(39),
  61398 				1:  uint8(77),
  61399 				2:  uint8(162),
  61400 				3:  uint8(232),
  61401 				4:  uint8(172),
  61402 				5:  uint8(180),
  61403 				6:  uint8(245),
  61404 				7:  uint8(178),
  61405 				8:  uint8(255),
  61406 				9:  uint8(255),
  61407 				10: uint8(128),
  61408 			},
  61409 		},
  61410 		2: {
  61411 			0: {
  61412 				0:  uint8(1),
  61413 				1:  uint8(52),
  61414 				2:  uint8(220),
  61415 				3:  uint8(246),
  61416 				4:  uint8(198),
  61417 				5:  uint8(199),
  61418 				6:  uint8(249),
  61419 				7:  uint8(220),
  61420 				8:  uint8(255),
  61421 				9:  uint8(255),
  61422 				10: uint8(128),
  61423 			},
  61424 			1: {
  61425 				0:  uint8(124),
  61426 				1:  uint8(74),
  61427 				2:  uint8(191),
  61428 				3:  uint8(243),
  61429 				4:  uint8(183),
  61430 				5:  uint8(193),
  61431 				6:  uint8(250),
  61432 				7:  uint8(221),
  61433 				8:  uint8(255),
  61434 				9:  uint8(255),
  61435 				10: uint8(128),
  61436 			},
  61437 			2: {
  61438 				0:  uint8(24),
  61439 				1:  uint8(71),
  61440 				2:  uint8(130),
  61441 				3:  uint8(219),
  61442 				4:  uint8(154),
  61443 				5:  uint8(170),
  61444 				6:  uint8(243),
  61445 				7:  uint8(182),
  61446 				8:  uint8(255),
  61447 				9:  uint8(255),
  61448 				10: uint8(128),
  61449 			},
  61450 		},
  61451 		3: {
  61452 			0: {
  61453 				0:  uint8(1),
  61454 				1:  uint8(182),
  61455 				2:  uint8(225),
  61456 				3:  uint8(249),
  61457 				4:  uint8(219),
  61458 				5:  uint8(240),
  61459 				6:  uint8(255),
  61460 				7:  uint8(224),
  61461 				8:  uint8(128),
  61462 				9:  uint8(128),
  61463 				10: uint8(128),
  61464 			},
  61465 			1: {
  61466 				0:  uint8(149),
  61467 				1:  uint8(150),
  61468 				2:  uint8(226),
  61469 				3:  uint8(252),
  61470 				4:  uint8(216),
  61471 				5:  uint8(205),
  61472 				6:  uint8(255),
  61473 				7:  uint8(171),
  61474 				8:  uint8(128),
  61475 				9:  uint8(128),
  61476 				10: uint8(128),
  61477 			},
  61478 			2: {
  61479 				0:  uint8(28),
  61480 				1:  uint8(108),
  61481 				2:  uint8(170),
  61482 				3:  uint8(242),
  61483 				4:  uint8(183),
  61484 				5:  uint8(194),
  61485 				6:  uint8(254),
  61486 				7:  uint8(223),
  61487 				8:  uint8(255),
  61488 				9:  uint8(255),
  61489 				10: uint8(128),
  61490 			},
  61491 		},
  61492 		4: {
  61493 			0: {
  61494 				0:  uint8(1),
  61495 				1:  uint8(81),
  61496 				2:  uint8(230),
  61497 				3:  uint8(252),
  61498 				4:  uint8(204),
  61499 				5:  uint8(203),
  61500 				6:  uint8(255),
  61501 				7:  uint8(192),
  61502 				8:  uint8(128),
  61503 				9:  uint8(128),
  61504 				10: uint8(128),
  61505 			},
  61506 			1: {
  61507 				0:  uint8(123),
  61508 				1:  uint8(102),
  61509 				2:  uint8(209),
  61510 				3:  uint8(247),
  61511 				4:  uint8(188),
  61512 				5:  uint8(196),
  61513 				6:  uint8(255),
  61514 				7:  uint8(233),
  61515 				8:  uint8(128),
  61516 				9:  uint8(128),
  61517 				10: uint8(128),
  61518 			},
  61519 			2: {
  61520 				0:  uint8(20),
  61521 				1:  uint8(95),
  61522 				2:  uint8(153),
  61523 				3:  uint8(243),
  61524 				4:  uint8(164),
  61525 				5:  uint8(173),
  61526 				6:  uint8(255),
  61527 				7:  uint8(203),
  61528 				8:  uint8(128),
  61529 				9:  uint8(128),
  61530 				10: uint8(128),
  61531 			},
  61532 		},
  61533 		5: {
  61534 			0: {
  61535 				0:  uint8(1),
  61536 				1:  uint8(222),
  61537 				2:  uint8(248),
  61538 				3:  uint8(255),
  61539 				4:  uint8(216),
  61540 				5:  uint8(213),
  61541 				6:  uint8(128),
  61542 				7:  uint8(128),
  61543 				8:  uint8(128),
  61544 				9:  uint8(128),
  61545 				10: uint8(128),
  61546 			},
  61547 			1: {
  61548 				0:  uint8(168),
  61549 				1:  uint8(175),
  61550 				2:  uint8(246),
  61551 				3:  uint8(252),
  61552 				4:  uint8(235),
  61553 				5:  uint8(205),
  61554 				6:  uint8(255),
  61555 				7:  uint8(255),
  61556 				8:  uint8(128),
  61557 				9:  uint8(128),
  61558 				10: uint8(128),
  61559 			},
  61560 			2: {
  61561 				0:  uint8(47),
  61562 				1:  uint8(116),
  61563 				2:  uint8(215),
  61564 				3:  uint8(255),
  61565 				4:  uint8(211),
  61566 				5:  uint8(212),
  61567 				6:  uint8(255),
  61568 				7:  uint8(255),
  61569 				8:  uint8(128),
  61570 				9:  uint8(128),
  61571 				10: uint8(128),
  61572 			},
  61573 		},
  61574 		6: {
  61575 			0: {
  61576 				0:  uint8(1),
  61577 				1:  uint8(121),
  61578 				2:  uint8(236),
  61579 				3:  uint8(253),
  61580 				4:  uint8(212),
  61581 				5:  uint8(214),
  61582 				6:  uint8(255),
  61583 				7:  uint8(255),
  61584 				8:  uint8(128),
  61585 				9:  uint8(128),
  61586 				10: uint8(128),
  61587 			},
  61588 			1: {
  61589 				0:  uint8(141),
  61590 				1:  uint8(84),
  61591 				2:  uint8(213),
  61592 				3:  uint8(252),
  61593 				4:  uint8(201),
  61594 				5:  uint8(202),
  61595 				6:  uint8(255),
  61596 				7:  uint8(219),
  61597 				8:  uint8(128),
  61598 				9:  uint8(128),
  61599 				10: uint8(128),
  61600 			},
  61601 			2: {
  61602 				0:  uint8(42),
  61603 				1:  uint8(80),
  61604 				2:  uint8(160),
  61605 				3:  uint8(240),
  61606 				4:  uint8(162),
  61607 				5:  uint8(185),
  61608 				6:  uint8(255),
  61609 				7:  uint8(205),
  61610 				8:  uint8(128),
  61611 				9:  uint8(128),
  61612 				10: uint8(128),
  61613 			},
  61614 		},
  61615 		7: {
  61616 			0: {
  61617 				0:  uint8(1),
  61618 				1:  uint8(1),
  61619 				2:  uint8(255),
  61620 				3:  uint8(128),
  61621 				4:  uint8(128),
  61622 				5:  uint8(128),
  61623 				6:  uint8(128),
  61624 				7:  uint8(128),
  61625 				8:  uint8(128),
  61626 				9:  uint8(128),
  61627 				10: uint8(128),
  61628 			},
  61629 			1: {
  61630 				0:  uint8(244),
  61631 				1:  uint8(1),
  61632 				2:  uint8(255),
  61633 				3:  uint8(128),
  61634 				4:  uint8(128),
  61635 				5:  uint8(128),
  61636 				6:  uint8(128),
  61637 				7:  uint8(128),
  61638 				8:  uint8(128),
  61639 				9:  uint8(128),
  61640 				10: uint8(128),
  61641 			},
  61642 			2: {
  61643 				0:  uint8(238),
  61644 				1:  uint8(1),
  61645 				2:  uint8(255),
  61646 				3:  uint8(128),
  61647 				4:  uint8(128),
  61648 				5:  uint8(128),
  61649 				6:  uint8(128),
  61650 				7:  uint8(128),
  61651 				8:  uint8(128),
  61652 				9:  uint8(128),
  61653 				10: uint8(128),
  61654 			},
  61655 		},
  61656 	},
  61657 }
  61658 
  61659 //------------------------------------------------------------------------------
  61660 // Paragraph 13
  61661 
  61662 var VP8CoeffsUpdateProba = [4][8][3][11]uint8_t{
  61663 	0: {
  61664 		0: {
  61665 			0: {
  61666 				0:  uint8(255),
  61667 				1:  uint8(255),
  61668 				2:  uint8(255),
  61669 				3:  uint8(255),
  61670 				4:  uint8(255),
  61671 				5:  uint8(255),
  61672 				6:  uint8(255),
  61673 				7:  uint8(255),
  61674 				8:  uint8(255),
  61675 				9:  uint8(255),
  61676 				10: uint8(255),
  61677 			},
  61678 			1: {
  61679 				0:  uint8(255),
  61680 				1:  uint8(255),
  61681 				2:  uint8(255),
  61682 				3:  uint8(255),
  61683 				4:  uint8(255),
  61684 				5:  uint8(255),
  61685 				6:  uint8(255),
  61686 				7:  uint8(255),
  61687 				8:  uint8(255),
  61688 				9:  uint8(255),
  61689 				10: uint8(255),
  61690 			},
  61691 			2: {
  61692 				0:  uint8(255),
  61693 				1:  uint8(255),
  61694 				2:  uint8(255),
  61695 				3:  uint8(255),
  61696 				4:  uint8(255),
  61697 				5:  uint8(255),
  61698 				6:  uint8(255),
  61699 				7:  uint8(255),
  61700 				8:  uint8(255),
  61701 				9:  uint8(255),
  61702 				10: uint8(255),
  61703 			},
  61704 		},
  61705 		1: {
  61706 			0: {
  61707 				0:  uint8(176),
  61708 				1:  uint8(246),
  61709 				2:  uint8(255),
  61710 				3:  uint8(255),
  61711 				4:  uint8(255),
  61712 				5:  uint8(255),
  61713 				6:  uint8(255),
  61714 				7:  uint8(255),
  61715 				8:  uint8(255),
  61716 				9:  uint8(255),
  61717 				10: uint8(255),
  61718 			},
  61719 			1: {
  61720 				0:  uint8(223),
  61721 				1:  uint8(241),
  61722 				2:  uint8(252),
  61723 				3:  uint8(255),
  61724 				4:  uint8(255),
  61725 				5:  uint8(255),
  61726 				6:  uint8(255),
  61727 				7:  uint8(255),
  61728 				8:  uint8(255),
  61729 				9:  uint8(255),
  61730 				10: uint8(255),
  61731 			},
  61732 			2: {
  61733 				0:  uint8(249),
  61734 				1:  uint8(253),
  61735 				2:  uint8(253),
  61736 				3:  uint8(255),
  61737 				4:  uint8(255),
  61738 				5:  uint8(255),
  61739 				6:  uint8(255),
  61740 				7:  uint8(255),
  61741 				8:  uint8(255),
  61742 				9:  uint8(255),
  61743 				10: uint8(255),
  61744 			},
  61745 		},
  61746 		2: {
  61747 			0: {
  61748 				0:  uint8(255),
  61749 				1:  uint8(244),
  61750 				2:  uint8(252),
  61751 				3:  uint8(255),
  61752 				4:  uint8(255),
  61753 				5:  uint8(255),
  61754 				6:  uint8(255),
  61755 				7:  uint8(255),
  61756 				8:  uint8(255),
  61757 				9:  uint8(255),
  61758 				10: uint8(255),
  61759 			},
  61760 			1: {
  61761 				0:  uint8(234),
  61762 				1:  uint8(254),
  61763 				2:  uint8(254),
  61764 				3:  uint8(255),
  61765 				4:  uint8(255),
  61766 				5:  uint8(255),
  61767 				6:  uint8(255),
  61768 				7:  uint8(255),
  61769 				8:  uint8(255),
  61770 				9:  uint8(255),
  61771 				10: uint8(255),
  61772 			},
  61773 			2: {
  61774 				0:  uint8(253),
  61775 				1:  uint8(255),
  61776 				2:  uint8(255),
  61777 				3:  uint8(255),
  61778 				4:  uint8(255),
  61779 				5:  uint8(255),
  61780 				6:  uint8(255),
  61781 				7:  uint8(255),
  61782 				8:  uint8(255),
  61783 				9:  uint8(255),
  61784 				10: uint8(255),
  61785 			},
  61786 		},
  61787 		3: {
  61788 			0: {
  61789 				0:  uint8(255),
  61790 				1:  uint8(246),
  61791 				2:  uint8(254),
  61792 				3:  uint8(255),
  61793 				4:  uint8(255),
  61794 				5:  uint8(255),
  61795 				6:  uint8(255),
  61796 				7:  uint8(255),
  61797 				8:  uint8(255),
  61798 				9:  uint8(255),
  61799 				10: uint8(255),
  61800 			},
  61801 			1: {
  61802 				0:  uint8(239),
  61803 				1:  uint8(253),
  61804 				2:  uint8(254),
  61805 				3:  uint8(255),
  61806 				4:  uint8(255),
  61807 				5:  uint8(255),
  61808 				6:  uint8(255),
  61809 				7:  uint8(255),
  61810 				8:  uint8(255),
  61811 				9:  uint8(255),
  61812 				10: uint8(255),
  61813 			},
  61814 			2: {
  61815 				0:  uint8(254),
  61816 				1:  uint8(255),
  61817 				2:  uint8(254),
  61818 				3:  uint8(255),
  61819 				4:  uint8(255),
  61820 				5:  uint8(255),
  61821 				6:  uint8(255),
  61822 				7:  uint8(255),
  61823 				8:  uint8(255),
  61824 				9:  uint8(255),
  61825 				10: uint8(255),
  61826 			},
  61827 		},
  61828 		4: {
  61829 			0: {
  61830 				0:  uint8(255),
  61831 				1:  uint8(248),
  61832 				2:  uint8(254),
  61833 				3:  uint8(255),
  61834 				4:  uint8(255),
  61835 				5:  uint8(255),
  61836 				6:  uint8(255),
  61837 				7:  uint8(255),
  61838 				8:  uint8(255),
  61839 				9:  uint8(255),
  61840 				10: uint8(255),
  61841 			},
  61842 			1: {
  61843 				0:  uint8(251),
  61844 				1:  uint8(255),
  61845 				2:  uint8(254),
  61846 				3:  uint8(255),
  61847 				4:  uint8(255),
  61848 				5:  uint8(255),
  61849 				6:  uint8(255),
  61850 				7:  uint8(255),
  61851 				8:  uint8(255),
  61852 				9:  uint8(255),
  61853 				10: uint8(255),
  61854 			},
  61855 			2: {
  61856 				0:  uint8(255),
  61857 				1:  uint8(255),
  61858 				2:  uint8(255),
  61859 				3:  uint8(255),
  61860 				4:  uint8(255),
  61861 				5:  uint8(255),
  61862 				6:  uint8(255),
  61863 				7:  uint8(255),
  61864 				8:  uint8(255),
  61865 				9:  uint8(255),
  61866 				10: uint8(255),
  61867 			},
  61868 		},
  61869 		5: {
  61870 			0: {
  61871 				0:  uint8(255),
  61872 				1:  uint8(253),
  61873 				2:  uint8(254),
  61874 				3:  uint8(255),
  61875 				4:  uint8(255),
  61876 				5:  uint8(255),
  61877 				6:  uint8(255),
  61878 				7:  uint8(255),
  61879 				8:  uint8(255),
  61880 				9:  uint8(255),
  61881 				10: uint8(255),
  61882 			},
  61883 			1: {
  61884 				0:  uint8(251),
  61885 				1:  uint8(254),
  61886 				2:  uint8(254),
  61887 				3:  uint8(255),
  61888 				4:  uint8(255),
  61889 				5:  uint8(255),
  61890 				6:  uint8(255),
  61891 				7:  uint8(255),
  61892 				8:  uint8(255),
  61893 				9:  uint8(255),
  61894 				10: uint8(255),
  61895 			},
  61896 			2: {
  61897 				0:  uint8(254),
  61898 				1:  uint8(255),
  61899 				2:  uint8(254),
  61900 				3:  uint8(255),
  61901 				4:  uint8(255),
  61902 				5:  uint8(255),
  61903 				6:  uint8(255),
  61904 				7:  uint8(255),
  61905 				8:  uint8(255),
  61906 				9:  uint8(255),
  61907 				10: uint8(255),
  61908 			},
  61909 		},
  61910 		6: {
  61911 			0: {
  61912 				0:  uint8(255),
  61913 				1:  uint8(254),
  61914 				2:  uint8(253),
  61915 				3:  uint8(255),
  61916 				4:  uint8(254),
  61917 				5:  uint8(255),
  61918 				6:  uint8(255),
  61919 				7:  uint8(255),
  61920 				8:  uint8(255),
  61921 				9:  uint8(255),
  61922 				10: uint8(255),
  61923 			},
  61924 			1: {
  61925 				0:  uint8(250),
  61926 				1:  uint8(255),
  61927 				2:  uint8(254),
  61928 				3:  uint8(255),
  61929 				4:  uint8(254),
  61930 				5:  uint8(255),
  61931 				6:  uint8(255),
  61932 				7:  uint8(255),
  61933 				8:  uint8(255),
  61934 				9:  uint8(255),
  61935 				10: uint8(255),
  61936 			},
  61937 			2: {
  61938 				0:  uint8(254),
  61939 				1:  uint8(255),
  61940 				2:  uint8(255),
  61941 				3:  uint8(255),
  61942 				4:  uint8(255),
  61943 				5:  uint8(255),
  61944 				6:  uint8(255),
  61945 				7:  uint8(255),
  61946 				8:  uint8(255),
  61947 				9:  uint8(255),
  61948 				10: uint8(255),
  61949 			},
  61950 		},
  61951 		7: {
  61952 			0: {
  61953 				0:  uint8(255),
  61954 				1:  uint8(255),
  61955 				2:  uint8(255),
  61956 				3:  uint8(255),
  61957 				4:  uint8(255),
  61958 				5:  uint8(255),
  61959 				6:  uint8(255),
  61960 				7:  uint8(255),
  61961 				8:  uint8(255),
  61962 				9:  uint8(255),
  61963 				10: uint8(255),
  61964 			},
  61965 			1: {
  61966 				0:  uint8(255),
  61967 				1:  uint8(255),
  61968 				2:  uint8(255),
  61969 				3:  uint8(255),
  61970 				4:  uint8(255),
  61971 				5:  uint8(255),
  61972 				6:  uint8(255),
  61973 				7:  uint8(255),
  61974 				8:  uint8(255),
  61975 				9:  uint8(255),
  61976 				10: uint8(255),
  61977 			},
  61978 			2: {
  61979 				0:  uint8(255),
  61980 				1:  uint8(255),
  61981 				2:  uint8(255),
  61982 				3:  uint8(255),
  61983 				4:  uint8(255),
  61984 				5:  uint8(255),
  61985 				6:  uint8(255),
  61986 				7:  uint8(255),
  61987 				8:  uint8(255),
  61988 				9:  uint8(255),
  61989 				10: uint8(255),
  61990 			},
  61991 		},
  61992 	},
  61993 	1: {
  61994 		0: {
  61995 			0: {
  61996 				0:  uint8(217),
  61997 				1:  uint8(255),
  61998 				2:  uint8(255),
  61999 				3:  uint8(255),
  62000 				4:  uint8(255),
  62001 				5:  uint8(255),
  62002 				6:  uint8(255),
  62003 				7:  uint8(255),
  62004 				8:  uint8(255),
  62005 				9:  uint8(255),
  62006 				10: uint8(255),
  62007 			},
  62008 			1: {
  62009 				0:  uint8(225),
  62010 				1:  uint8(252),
  62011 				2:  uint8(241),
  62012 				3:  uint8(253),
  62013 				4:  uint8(255),
  62014 				5:  uint8(255),
  62015 				6:  uint8(254),
  62016 				7:  uint8(255),
  62017 				8:  uint8(255),
  62018 				9:  uint8(255),
  62019 				10: uint8(255),
  62020 			},
  62021 			2: {
  62022 				0:  uint8(234),
  62023 				1:  uint8(250),
  62024 				2:  uint8(241),
  62025 				3:  uint8(250),
  62026 				4:  uint8(253),
  62027 				5:  uint8(255),
  62028 				6:  uint8(253),
  62029 				7:  uint8(254),
  62030 				8:  uint8(255),
  62031 				9:  uint8(255),
  62032 				10: uint8(255),
  62033 			},
  62034 		},
  62035 		1: {
  62036 			0: {
  62037 				0:  uint8(255),
  62038 				1:  uint8(254),
  62039 				2:  uint8(255),
  62040 				3:  uint8(255),
  62041 				4:  uint8(255),
  62042 				5:  uint8(255),
  62043 				6:  uint8(255),
  62044 				7:  uint8(255),
  62045 				8:  uint8(255),
  62046 				9:  uint8(255),
  62047 				10: uint8(255),
  62048 			},
  62049 			1: {
  62050 				0:  uint8(223),
  62051 				1:  uint8(254),
  62052 				2:  uint8(254),
  62053 				3:  uint8(255),
  62054 				4:  uint8(255),
  62055 				5:  uint8(255),
  62056 				6:  uint8(255),
  62057 				7:  uint8(255),
  62058 				8:  uint8(255),
  62059 				9:  uint8(255),
  62060 				10: uint8(255),
  62061 			},
  62062 			2: {
  62063 				0:  uint8(238),
  62064 				1:  uint8(253),
  62065 				2:  uint8(254),
  62066 				3:  uint8(254),
  62067 				4:  uint8(255),
  62068 				5:  uint8(255),
  62069 				6:  uint8(255),
  62070 				7:  uint8(255),
  62071 				8:  uint8(255),
  62072 				9:  uint8(255),
  62073 				10: uint8(255),
  62074 			},
  62075 		},
  62076 		2: {
  62077 			0: {
  62078 				0:  uint8(255),
  62079 				1:  uint8(248),
  62080 				2:  uint8(254),
  62081 				3:  uint8(255),
  62082 				4:  uint8(255),
  62083 				5:  uint8(255),
  62084 				6:  uint8(255),
  62085 				7:  uint8(255),
  62086 				8:  uint8(255),
  62087 				9:  uint8(255),
  62088 				10: uint8(255),
  62089 			},
  62090 			1: {
  62091 				0:  uint8(249),
  62092 				1:  uint8(254),
  62093 				2:  uint8(255),
  62094 				3:  uint8(255),
  62095 				4:  uint8(255),
  62096 				5:  uint8(255),
  62097 				6:  uint8(255),
  62098 				7:  uint8(255),
  62099 				8:  uint8(255),
  62100 				9:  uint8(255),
  62101 				10: uint8(255),
  62102 			},
  62103 			2: {
  62104 				0:  uint8(255),
  62105 				1:  uint8(255),
  62106 				2:  uint8(255),
  62107 				3:  uint8(255),
  62108 				4:  uint8(255),
  62109 				5:  uint8(255),
  62110 				6:  uint8(255),
  62111 				7:  uint8(255),
  62112 				8:  uint8(255),
  62113 				9:  uint8(255),
  62114 				10: uint8(255),
  62115 			},
  62116 		},
  62117 		3: {
  62118 			0: {
  62119 				0:  uint8(255),
  62120 				1:  uint8(253),
  62121 				2:  uint8(255),
  62122 				3:  uint8(255),
  62123 				4:  uint8(255),
  62124 				5:  uint8(255),
  62125 				6:  uint8(255),
  62126 				7:  uint8(255),
  62127 				8:  uint8(255),
  62128 				9:  uint8(255),
  62129 				10: uint8(255),
  62130 			},
  62131 			1: {
  62132 				0:  uint8(247),
  62133 				1:  uint8(254),
  62134 				2:  uint8(255),
  62135 				3:  uint8(255),
  62136 				4:  uint8(255),
  62137 				5:  uint8(255),
  62138 				6:  uint8(255),
  62139 				7:  uint8(255),
  62140 				8:  uint8(255),
  62141 				9:  uint8(255),
  62142 				10: uint8(255),
  62143 			},
  62144 			2: {
  62145 				0:  uint8(255),
  62146 				1:  uint8(255),
  62147 				2:  uint8(255),
  62148 				3:  uint8(255),
  62149 				4:  uint8(255),
  62150 				5:  uint8(255),
  62151 				6:  uint8(255),
  62152 				7:  uint8(255),
  62153 				8:  uint8(255),
  62154 				9:  uint8(255),
  62155 				10: uint8(255),
  62156 			},
  62157 		},
  62158 		4: {
  62159 			0: {
  62160 				0:  uint8(255),
  62161 				1:  uint8(253),
  62162 				2:  uint8(254),
  62163 				3:  uint8(255),
  62164 				4:  uint8(255),
  62165 				5:  uint8(255),
  62166 				6:  uint8(255),
  62167 				7:  uint8(255),
  62168 				8:  uint8(255),
  62169 				9:  uint8(255),
  62170 				10: uint8(255),
  62171 			},
  62172 			1: {
  62173 				0:  uint8(252),
  62174 				1:  uint8(255),
  62175 				2:  uint8(255),
  62176 				3:  uint8(255),
  62177 				4:  uint8(255),
  62178 				5:  uint8(255),
  62179 				6:  uint8(255),
  62180 				7:  uint8(255),
  62181 				8:  uint8(255),
  62182 				9:  uint8(255),
  62183 				10: uint8(255),
  62184 			},
  62185 			2: {
  62186 				0:  uint8(255),
  62187 				1:  uint8(255),
  62188 				2:  uint8(255),
  62189 				3:  uint8(255),
  62190 				4:  uint8(255),
  62191 				5:  uint8(255),
  62192 				6:  uint8(255),
  62193 				7:  uint8(255),
  62194 				8:  uint8(255),
  62195 				9:  uint8(255),
  62196 				10: uint8(255),
  62197 			},
  62198 		},
  62199 		5: {
  62200 			0: {
  62201 				0:  uint8(255),
  62202 				1:  uint8(254),
  62203 				2:  uint8(254),
  62204 				3:  uint8(255),
  62205 				4:  uint8(255),
  62206 				5:  uint8(255),
  62207 				6:  uint8(255),
  62208 				7:  uint8(255),
  62209 				8:  uint8(255),
  62210 				9:  uint8(255),
  62211 				10: uint8(255),
  62212 			},
  62213 			1: {
  62214 				0:  uint8(253),
  62215 				1:  uint8(255),
  62216 				2:  uint8(255),
  62217 				3:  uint8(255),
  62218 				4:  uint8(255),
  62219 				5:  uint8(255),
  62220 				6:  uint8(255),
  62221 				7:  uint8(255),
  62222 				8:  uint8(255),
  62223 				9:  uint8(255),
  62224 				10: uint8(255),
  62225 			},
  62226 			2: {
  62227 				0:  uint8(255),
  62228 				1:  uint8(255),
  62229 				2:  uint8(255),
  62230 				3:  uint8(255),
  62231 				4:  uint8(255),
  62232 				5:  uint8(255),
  62233 				6:  uint8(255),
  62234 				7:  uint8(255),
  62235 				8:  uint8(255),
  62236 				9:  uint8(255),
  62237 				10: uint8(255),
  62238 			},
  62239 		},
  62240 		6: {
  62241 			0: {
  62242 				0:  uint8(255),
  62243 				1:  uint8(254),
  62244 				2:  uint8(253),
  62245 				3:  uint8(255),
  62246 				4:  uint8(255),
  62247 				5:  uint8(255),
  62248 				6:  uint8(255),
  62249 				7:  uint8(255),
  62250 				8:  uint8(255),
  62251 				9:  uint8(255),
  62252 				10: uint8(255),
  62253 			},
  62254 			1: {
  62255 				0:  uint8(250),
  62256 				1:  uint8(255),
  62257 				2:  uint8(255),
  62258 				3:  uint8(255),
  62259 				4:  uint8(255),
  62260 				5:  uint8(255),
  62261 				6:  uint8(255),
  62262 				7:  uint8(255),
  62263 				8:  uint8(255),
  62264 				9:  uint8(255),
  62265 				10: uint8(255),
  62266 			},
  62267 			2: {
  62268 				0:  uint8(254),
  62269 				1:  uint8(255),
  62270 				2:  uint8(255),
  62271 				3:  uint8(255),
  62272 				4:  uint8(255),
  62273 				5:  uint8(255),
  62274 				6:  uint8(255),
  62275 				7:  uint8(255),
  62276 				8:  uint8(255),
  62277 				9:  uint8(255),
  62278 				10: uint8(255),
  62279 			},
  62280 		},
  62281 		7: {
  62282 			0: {
  62283 				0:  uint8(255),
  62284 				1:  uint8(255),
  62285 				2:  uint8(255),
  62286 				3:  uint8(255),
  62287 				4:  uint8(255),
  62288 				5:  uint8(255),
  62289 				6:  uint8(255),
  62290 				7:  uint8(255),
  62291 				8:  uint8(255),
  62292 				9:  uint8(255),
  62293 				10: uint8(255),
  62294 			},
  62295 			1: {
  62296 				0:  uint8(255),
  62297 				1:  uint8(255),
  62298 				2:  uint8(255),
  62299 				3:  uint8(255),
  62300 				4:  uint8(255),
  62301 				5:  uint8(255),
  62302 				6:  uint8(255),
  62303 				7:  uint8(255),
  62304 				8:  uint8(255),
  62305 				9:  uint8(255),
  62306 				10: uint8(255),
  62307 			},
  62308 			2: {
  62309 				0:  uint8(255),
  62310 				1:  uint8(255),
  62311 				2:  uint8(255),
  62312 				3:  uint8(255),
  62313 				4:  uint8(255),
  62314 				5:  uint8(255),
  62315 				6:  uint8(255),
  62316 				7:  uint8(255),
  62317 				8:  uint8(255),
  62318 				9:  uint8(255),
  62319 				10: uint8(255),
  62320 			},
  62321 		},
  62322 	},
  62323 	2: {
  62324 		0: {
  62325 			0: {
  62326 				0:  uint8(186),
  62327 				1:  uint8(251),
  62328 				2:  uint8(250),
  62329 				3:  uint8(255),
  62330 				4:  uint8(255),
  62331 				5:  uint8(255),
  62332 				6:  uint8(255),
  62333 				7:  uint8(255),
  62334 				8:  uint8(255),
  62335 				9:  uint8(255),
  62336 				10: uint8(255),
  62337 			},
  62338 			1: {
  62339 				0:  uint8(234),
  62340 				1:  uint8(251),
  62341 				2:  uint8(244),
  62342 				3:  uint8(254),
  62343 				4:  uint8(255),
  62344 				5:  uint8(255),
  62345 				6:  uint8(255),
  62346 				7:  uint8(255),
  62347 				8:  uint8(255),
  62348 				9:  uint8(255),
  62349 				10: uint8(255),
  62350 			},
  62351 			2: {
  62352 				0:  uint8(251),
  62353 				1:  uint8(251),
  62354 				2:  uint8(243),
  62355 				3:  uint8(253),
  62356 				4:  uint8(254),
  62357 				5:  uint8(255),
  62358 				6:  uint8(254),
  62359 				7:  uint8(255),
  62360 				8:  uint8(255),
  62361 				9:  uint8(255),
  62362 				10: uint8(255),
  62363 			},
  62364 		},
  62365 		1: {
  62366 			0: {
  62367 				0:  uint8(255),
  62368 				1:  uint8(253),
  62369 				2:  uint8(254),
  62370 				3:  uint8(255),
  62371 				4:  uint8(255),
  62372 				5:  uint8(255),
  62373 				6:  uint8(255),
  62374 				7:  uint8(255),
  62375 				8:  uint8(255),
  62376 				9:  uint8(255),
  62377 				10: uint8(255),
  62378 			},
  62379 			1: {
  62380 				0:  uint8(236),
  62381 				1:  uint8(253),
  62382 				2:  uint8(254),
  62383 				3:  uint8(255),
  62384 				4:  uint8(255),
  62385 				5:  uint8(255),
  62386 				6:  uint8(255),
  62387 				7:  uint8(255),
  62388 				8:  uint8(255),
  62389 				9:  uint8(255),
  62390 				10: uint8(255),
  62391 			},
  62392 			2: {
  62393 				0:  uint8(251),
  62394 				1:  uint8(253),
  62395 				2:  uint8(253),
  62396 				3:  uint8(254),
  62397 				4:  uint8(254),
  62398 				5:  uint8(255),
  62399 				6:  uint8(255),
  62400 				7:  uint8(255),
  62401 				8:  uint8(255),
  62402 				9:  uint8(255),
  62403 				10: uint8(255),
  62404 			},
  62405 		},
  62406 		2: {
  62407 			0: {
  62408 				0:  uint8(255),
  62409 				1:  uint8(254),
  62410 				2:  uint8(254),
  62411 				3:  uint8(255),
  62412 				4:  uint8(255),
  62413 				5:  uint8(255),
  62414 				6:  uint8(255),
  62415 				7:  uint8(255),
  62416 				8:  uint8(255),
  62417 				9:  uint8(255),
  62418 				10: uint8(255),
  62419 			},
  62420 			1: {
  62421 				0:  uint8(254),
  62422 				1:  uint8(254),
  62423 				2:  uint8(254),
  62424 				3:  uint8(255),
  62425 				4:  uint8(255),
  62426 				5:  uint8(255),
  62427 				6:  uint8(255),
  62428 				7:  uint8(255),
  62429 				8:  uint8(255),
  62430 				9:  uint8(255),
  62431 				10: uint8(255),
  62432 			},
  62433 			2: {
  62434 				0:  uint8(255),
  62435 				1:  uint8(255),
  62436 				2:  uint8(255),
  62437 				3:  uint8(255),
  62438 				4:  uint8(255),
  62439 				5:  uint8(255),
  62440 				6:  uint8(255),
  62441 				7:  uint8(255),
  62442 				8:  uint8(255),
  62443 				9:  uint8(255),
  62444 				10: uint8(255),
  62445 			},
  62446 		},
  62447 		3: {
  62448 			0: {
  62449 				0:  uint8(255),
  62450 				1:  uint8(254),
  62451 				2:  uint8(255),
  62452 				3:  uint8(255),
  62453 				4:  uint8(255),
  62454 				5:  uint8(255),
  62455 				6:  uint8(255),
  62456 				7:  uint8(255),
  62457 				8:  uint8(255),
  62458 				9:  uint8(255),
  62459 				10: uint8(255),
  62460 			},
  62461 			1: {
  62462 				0:  uint8(254),
  62463 				1:  uint8(254),
  62464 				2:  uint8(255),
  62465 				3:  uint8(255),
  62466 				4:  uint8(255),
  62467 				5:  uint8(255),
  62468 				6:  uint8(255),
  62469 				7:  uint8(255),
  62470 				8:  uint8(255),
  62471 				9:  uint8(255),
  62472 				10: uint8(255),
  62473 			},
  62474 			2: {
  62475 				0:  uint8(254),
  62476 				1:  uint8(255),
  62477 				2:  uint8(255),
  62478 				3:  uint8(255),
  62479 				4:  uint8(255),
  62480 				5:  uint8(255),
  62481 				6:  uint8(255),
  62482 				7:  uint8(255),
  62483 				8:  uint8(255),
  62484 				9:  uint8(255),
  62485 				10: uint8(255),
  62486 			},
  62487 		},
  62488 		4: {
  62489 			0: {
  62490 				0:  uint8(255),
  62491 				1:  uint8(255),
  62492 				2:  uint8(255),
  62493 				3:  uint8(255),
  62494 				4:  uint8(255),
  62495 				5:  uint8(255),
  62496 				6:  uint8(255),
  62497 				7:  uint8(255),
  62498 				8:  uint8(255),
  62499 				9:  uint8(255),
  62500 				10: uint8(255),
  62501 			},
  62502 			1: {
  62503 				0:  uint8(254),
  62504 				1:  uint8(255),
  62505 				2:  uint8(255),
  62506 				3:  uint8(255),
  62507 				4:  uint8(255),
  62508 				5:  uint8(255),
  62509 				6:  uint8(255),
  62510 				7:  uint8(255),
  62511 				8:  uint8(255),
  62512 				9:  uint8(255),
  62513 				10: uint8(255),
  62514 			},
  62515 			2: {
  62516 				0:  uint8(255),
  62517 				1:  uint8(255),
  62518 				2:  uint8(255),
  62519 				3:  uint8(255),
  62520 				4:  uint8(255),
  62521 				5:  uint8(255),
  62522 				6:  uint8(255),
  62523 				7:  uint8(255),
  62524 				8:  uint8(255),
  62525 				9:  uint8(255),
  62526 				10: uint8(255),
  62527 			},
  62528 		},
  62529 		5: {
  62530 			0: {
  62531 				0:  uint8(255),
  62532 				1:  uint8(255),
  62533 				2:  uint8(255),
  62534 				3:  uint8(255),
  62535 				4:  uint8(255),
  62536 				5:  uint8(255),
  62537 				6:  uint8(255),
  62538 				7:  uint8(255),
  62539 				8:  uint8(255),
  62540 				9:  uint8(255),
  62541 				10: uint8(255),
  62542 			},
  62543 			1: {
  62544 				0:  uint8(255),
  62545 				1:  uint8(255),
  62546 				2:  uint8(255),
  62547 				3:  uint8(255),
  62548 				4:  uint8(255),
  62549 				5:  uint8(255),
  62550 				6:  uint8(255),
  62551 				7:  uint8(255),
  62552 				8:  uint8(255),
  62553 				9:  uint8(255),
  62554 				10: uint8(255),
  62555 			},
  62556 			2: {
  62557 				0:  uint8(255),
  62558 				1:  uint8(255),
  62559 				2:  uint8(255),
  62560 				3:  uint8(255),
  62561 				4:  uint8(255),
  62562 				5:  uint8(255),
  62563 				6:  uint8(255),
  62564 				7:  uint8(255),
  62565 				8:  uint8(255),
  62566 				9:  uint8(255),
  62567 				10: uint8(255),
  62568 			},
  62569 		},
  62570 		6: {
  62571 			0: {
  62572 				0:  uint8(255),
  62573 				1:  uint8(255),
  62574 				2:  uint8(255),
  62575 				3:  uint8(255),
  62576 				4:  uint8(255),
  62577 				5:  uint8(255),
  62578 				6:  uint8(255),
  62579 				7:  uint8(255),
  62580 				8:  uint8(255),
  62581 				9:  uint8(255),
  62582 				10: uint8(255),
  62583 			},
  62584 			1: {
  62585 				0:  uint8(255),
  62586 				1:  uint8(255),
  62587 				2:  uint8(255),
  62588 				3:  uint8(255),
  62589 				4:  uint8(255),
  62590 				5:  uint8(255),
  62591 				6:  uint8(255),
  62592 				7:  uint8(255),
  62593 				8:  uint8(255),
  62594 				9:  uint8(255),
  62595 				10: uint8(255),
  62596 			},
  62597 			2: {
  62598 				0:  uint8(255),
  62599 				1:  uint8(255),
  62600 				2:  uint8(255),
  62601 				3:  uint8(255),
  62602 				4:  uint8(255),
  62603 				5:  uint8(255),
  62604 				6:  uint8(255),
  62605 				7:  uint8(255),
  62606 				8:  uint8(255),
  62607 				9:  uint8(255),
  62608 				10: uint8(255),
  62609 			},
  62610 		},
  62611 		7: {
  62612 			0: {
  62613 				0:  uint8(255),
  62614 				1:  uint8(255),
  62615 				2:  uint8(255),
  62616 				3:  uint8(255),
  62617 				4:  uint8(255),
  62618 				5:  uint8(255),
  62619 				6:  uint8(255),
  62620 				7:  uint8(255),
  62621 				8:  uint8(255),
  62622 				9:  uint8(255),
  62623 				10: uint8(255),
  62624 			},
  62625 			1: {
  62626 				0:  uint8(255),
  62627 				1:  uint8(255),
  62628 				2:  uint8(255),
  62629 				3:  uint8(255),
  62630 				4:  uint8(255),
  62631 				5:  uint8(255),
  62632 				6:  uint8(255),
  62633 				7:  uint8(255),
  62634 				8:  uint8(255),
  62635 				9:  uint8(255),
  62636 				10: uint8(255),
  62637 			},
  62638 			2: {
  62639 				0:  uint8(255),
  62640 				1:  uint8(255),
  62641 				2:  uint8(255),
  62642 				3:  uint8(255),
  62643 				4:  uint8(255),
  62644 				5:  uint8(255),
  62645 				6:  uint8(255),
  62646 				7:  uint8(255),
  62647 				8:  uint8(255),
  62648 				9:  uint8(255),
  62649 				10: uint8(255),
  62650 			},
  62651 		},
  62652 	},
  62653 	3: {
  62654 		0: {
  62655 			0: {
  62656 				0:  uint8(248),
  62657 				1:  uint8(255),
  62658 				2:  uint8(255),
  62659 				3:  uint8(255),
  62660 				4:  uint8(255),
  62661 				5:  uint8(255),
  62662 				6:  uint8(255),
  62663 				7:  uint8(255),
  62664 				8:  uint8(255),
  62665 				9:  uint8(255),
  62666 				10: uint8(255),
  62667 			},
  62668 			1: {
  62669 				0:  uint8(250),
  62670 				1:  uint8(254),
  62671 				2:  uint8(252),
  62672 				3:  uint8(254),
  62673 				4:  uint8(255),
  62674 				5:  uint8(255),
  62675 				6:  uint8(255),
  62676 				7:  uint8(255),
  62677 				8:  uint8(255),
  62678 				9:  uint8(255),
  62679 				10: uint8(255),
  62680 			},
  62681 			2: {
  62682 				0:  uint8(248),
  62683 				1:  uint8(254),
  62684 				2:  uint8(249),
  62685 				3:  uint8(253),
  62686 				4:  uint8(255),
  62687 				5:  uint8(255),
  62688 				6:  uint8(255),
  62689 				7:  uint8(255),
  62690 				8:  uint8(255),
  62691 				9:  uint8(255),
  62692 				10: uint8(255),
  62693 			},
  62694 		},
  62695 		1: {
  62696 			0: {
  62697 				0:  uint8(255),
  62698 				1:  uint8(253),
  62699 				2:  uint8(253),
  62700 				3:  uint8(255),
  62701 				4:  uint8(255),
  62702 				5:  uint8(255),
  62703 				6:  uint8(255),
  62704 				7:  uint8(255),
  62705 				8:  uint8(255),
  62706 				9:  uint8(255),
  62707 				10: uint8(255),
  62708 			},
  62709 			1: {
  62710 				0:  uint8(246),
  62711 				1:  uint8(253),
  62712 				2:  uint8(253),
  62713 				3:  uint8(255),
  62714 				4:  uint8(255),
  62715 				5:  uint8(255),
  62716 				6:  uint8(255),
  62717 				7:  uint8(255),
  62718 				8:  uint8(255),
  62719 				9:  uint8(255),
  62720 				10: uint8(255),
  62721 			},
  62722 			2: {
  62723 				0:  uint8(252),
  62724 				1:  uint8(254),
  62725 				2:  uint8(251),
  62726 				3:  uint8(254),
  62727 				4:  uint8(254),
  62728 				5:  uint8(255),
  62729 				6:  uint8(255),
  62730 				7:  uint8(255),
  62731 				8:  uint8(255),
  62732 				9:  uint8(255),
  62733 				10: uint8(255),
  62734 			},
  62735 		},
  62736 		2: {
  62737 			0: {
  62738 				0:  uint8(255),
  62739 				1:  uint8(254),
  62740 				2:  uint8(252),
  62741 				3:  uint8(255),
  62742 				4:  uint8(255),
  62743 				5:  uint8(255),
  62744 				6:  uint8(255),
  62745 				7:  uint8(255),
  62746 				8:  uint8(255),
  62747 				9:  uint8(255),
  62748 				10: uint8(255),
  62749 			},
  62750 			1: {
  62751 				0:  uint8(248),
  62752 				1:  uint8(254),
  62753 				2:  uint8(253),
  62754 				3:  uint8(255),
  62755 				4:  uint8(255),
  62756 				5:  uint8(255),
  62757 				6:  uint8(255),
  62758 				7:  uint8(255),
  62759 				8:  uint8(255),
  62760 				9:  uint8(255),
  62761 				10: uint8(255),
  62762 			},
  62763 			2: {
  62764 				0:  uint8(253),
  62765 				1:  uint8(255),
  62766 				2:  uint8(254),
  62767 				3:  uint8(254),
  62768 				4:  uint8(255),
  62769 				5:  uint8(255),
  62770 				6:  uint8(255),
  62771 				7:  uint8(255),
  62772 				8:  uint8(255),
  62773 				9:  uint8(255),
  62774 				10: uint8(255),
  62775 			},
  62776 		},
  62777 		3: {
  62778 			0: {
  62779 				0:  uint8(255),
  62780 				1:  uint8(251),
  62781 				2:  uint8(254),
  62782 				3:  uint8(255),
  62783 				4:  uint8(255),
  62784 				5:  uint8(255),
  62785 				6:  uint8(255),
  62786 				7:  uint8(255),
  62787 				8:  uint8(255),
  62788 				9:  uint8(255),
  62789 				10: uint8(255),
  62790 			},
  62791 			1: {
  62792 				0:  uint8(245),
  62793 				1:  uint8(251),
  62794 				2:  uint8(254),
  62795 				3:  uint8(255),
  62796 				4:  uint8(255),
  62797 				5:  uint8(255),
  62798 				6:  uint8(255),
  62799 				7:  uint8(255),
  62800 				8:  uint8(255),
  62801 				9:  uint8(255),
  62802 				10: uint8(255),
  62803 			},
  62804 			2: {
  62805 				0:  uint8(253),
  62806 				1:  uint8(253),
  62807 				2:  uint8(254),
  62808 				3:  uint8(255),
  62809 				4:  uint8(255),
  62810 				5:  uint8(255),
  62811 				6:  uint8(255),
  62812 				7:  uint8(255),
  62813 				8:  uint8(255),
  62814 				9:  uint8(255),
  62815 				10: uint8(255),
  62816 			},
  62817 		},
  62818 		4: {
  62819 			0: {
  62820 				0:  uint8(255),
  62821 				1:  uint8(251),
  62822 				2:  uint8(253),
  62823 				3:  uint8(255),
  62824 				4:  uint8(255),
  62825 				5:  uint8(255),
  62826 				6:  uint8(255),
  62827 				7:  uint8(255),
  62828 				8:  uint8(255),
  62829 				9:  uint8(255),
  62830 				10: uint8(255),
  62831 			},
  62832 			1: {
  62833 				0:  uint8(252),
  62834 				1:  uint8(253),
  62835 				2:  uint8(254),
  62836 				3:  uint8(255),
  62837 				4:  uint8(255),
  62838 				5:  uint8(255),
  62839 				6:  uint8(255),
  62840 				7:  uint8(255),
  62841 				8:  uint8(255),
  62842 				9:  uint8(255),
  62843 				10: uint8(255),
  62844 			},
  62845 			2: {
  62846 				0:  uint8(255),
  62847 				1:  uint8(254),
  62848 				2:  uint8(255),
  62849 				3:  uint8(255),
  62850 				4:  uint8(255),
  62851 				5:  uint8(255),
  62852 				6:  uint8(255),
  62853 				7:  uint8(255),
  62854 				8:  uint8(255),
  62855 				9:  uint8(255),
  62856 				10: uint8(255),
  62857 			},
  62858 		},
  62859 		5: {
  62860 			0: {
  62861 				0:  uint8(255),
  62862 				1:  uint8(252),
  62863 				2:  uint8(255),
  62864 				3:  uint8(255),
  62865 				4:  uint8(255),
  62866 				5:  uint8(255),
  62867 				6:  uint8(255),
  62868 				7:  uint8(255),
  62869 				8:  uint8(255),
  62870 				9:  uint8(255),
  62871 				10: uint8(255),
  62872 			},
  62873 			1: {
  62874 				0:  uint8(249),
  62875 				1:  uint8(255),
  62876 				2:  uint8(254),
  62877 				3:  uint8(255),
  62878 				4:  uint8(255),
  62879 				5:  uint8(255),
  62880 				6:  uint8(255),
  62881 				7:  uint8(255),
  62882 				8:  uint8(255),
  62883 				9:  uint8(255),
  62884 				10: uint8(255),
  62885 			},
  62886 			2: {
  62887 				0:  uint8(255),
  62888 				1:  uint8(255),
  62889 				2:  uint8(254),
  62890 				3:  uint8(255),
  62891 				4:  uint8(255),
  62892 				5:  uint8(255),
  62893 				6:  uint8(255),
  62894 				7:  uint8(255),
  62895 				8:  uint8(255),
  62896 				9:  uint8(255),
  62897 				10: uint8(255),
  62898 			},
  62899 		},
  62900 		6: {
  62901 			0: {
  62902 				0:  uint8(255),
  62903 				1:  uint8(255),
  62904 				2:  uint8(253),
  62905 				3:  uint8(255),
  62906 				4:  uint8(255),
  62907 				5:  uint8(255),
  62908 				6:  uint8(255),
  62909 				7:  uint8(255),
  62910 				8:  uint8(255),
  62911 				9:  uint8(255),
  62912 				10: uint8(255),
  62913 			},
  62914 			1: {
  62915 				0:  uint8(250),
  62916 				1:  uint8(255),
  62917 				2:  uint8(255),
  62918 				3:  uint8(255),
  62919 				4:  uint8(255),
  62920 				5:  uint8(255),
  62921 				6:  uint8(255),
  62922 				7:  uint8(255),
  62923 				8:  uint8(255),
  62924 				9:  uint8(255),
  62925 				10: uint8(255),
  62926 			},
  62927 			2: {
  62928 				0:  uint8(255),
  62929 				1:  uint8(255),
  62930 				2:  uint8(255),
  62931 				3:  uint8(255),
  62932 				4:  uint8(255),
  62933 				5:  uint8(255),
  62934 				6:  uint8(255),
  62935 				7:  uint8(255),
  62936 				8:  uint8(255),
  62937 				9:  uint8(255),
  62938 				10: uint8(255),
  62939 			},
  62940 		},
  62941 		7: {
  62942 			0: {
  62943 				0:  uint8(255),
  62944 				1:  uint8(255),
  62945 				2:  uint8(255),
  62946 				3:  uint8(255),
  62947 				4:  uint8(255),
  62948 				5:  uint8(255),
  62949 				6:  uint8(255),
  62950 				7:  uint8(255),
  62951 				8:  uint8(255),
  62952 				9:  uint8(255),
  62953 				10: uint8(255),
  62954 			},
  62955 			1: {
  62956 				0:  uint8(254),
  62957 				1:  uint8(255),
  62958 				2:  uint8(255),
  62959 				3:  uint8(255),
  62960 				4:  uint8(255),
  62961 				5:  uint8(255),
  62962 				6:  uint8(255),
  62963 				7:  uint8(255),
  62964 				8:  uint8(255),
  62965 				9:  uint8(255),
  62966 				10: uint8(255),
  62967 			},
  62968 			2: {
  62969 				0:  uint8(255),
  62970 				1:  uint8(255),
  62971 				2:  uint8(255),
  62972 				3:  uint8(255),
  62973 				4:  uint8(255),
  62974 				5:  uint8(255),
  62975 				6:  uint8(255),
  62976 				7:  uint8(255),
  62977 				8:  uint8(255),
  62978 				9:  uint8(255),
  62979 				10: uint8(255),
  62980 			},
  62981 		},
  62982 	},
  62983 }
  62984 
  62985 //------------------------------------------------------------------------------
  62986 // Initialization
  62987 
  62988 // C documentation
  62989 //
  62990 //	// Speed-critical function pointers. We have to initialize them to the default
  62991 //	// implementations within VP8EncDspInit().
  62992 var VP8CollectHistogram VP8CHisto
  62993 
  62994 var VP8Copy16x8 VP8BlockCopy
  62995 
  62996 var VP8Copy4x4 VP8BlockCopy
  62997 
  62998 var VP8DitherCombine8x8 uintptr
  62999 
  63000 //------------------------------------------------------------------------------
  63001 // Compute susceptibility based on DCT-coeff histograms:
  63002 // the higher, the "easier" the macroblock is to compress.
  63003 
  63004 var VP8DspScan = [24]int32{
  63005 	1:  libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63006 	2:  libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63007 	3:  libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63008 	4:  libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63009 	5:  libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63010 	6:  libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63011 	7:  libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63012 	8:  libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63013 	9:  libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63014 	10: libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63015 	11: libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63016 	12: libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63017 	13: libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63018 	14: libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63019 	15: libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63020 	17: libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63021 	18: libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63022 	19: libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63023 	20: libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63024 	21: libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63025 	22: libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63026 	23: libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63027 }
  63028 
  63029 //------------------------------------------------------------------------------
  63030 // Tables for level coding
  63031 
  63032 var VP8EncBands = [17]uint8_t{
  63033 	1:  uint8(1),
  63034 	2:  uint8(2),
  63035 	3:  uint8(3),
  63036 	4:  uint8(6),
  63037 	5:  uint8(4),
  63038 	6:  uint8(5),
  63039 	7:  uint8(6),
  63040 	8:  uint8(6),
  63041 	9:  uint8(6),
  63042 	10: uint8(6),
  63043 	11: uint8(6),
  63044 	12: uint8(6),
  63045 	13: uint8(6),
  63046 	14: uint8(6),
  63047 	15: uint8(7),
  63048 }
  63049 
  63050 var VP8EncPredChroma8 VP8IntraPreds
  63051 
  63052 var VP8EncPredLuma16 VP8IntraPreds
  63053 
  63054 var VP8EncPredLuma4 VP8Intra4Preds
  63055 
  63056 var VP8EncQuantize2Blocks VP8Quantize2Blocks
  63057 
  63058 var VP8EncQuantizeBlock VP8QuantizeBlock
  63059 
  63060 var VP8EncQuantizeBlockWHT VP8QuantizeBlockWHT
  63061 
  63062 //------------------------------------------------------------------------------
  63063 
  63064 // Copyright 2011 Google Inc. All Rights Reserved.
  63065 //
  63066 // Use of this source code is governed by a BSD-style license
  63067 // that can be found in the COPYING file in the root of the source
  63068 // tree. An additional intellectual property rights grant can be found
  63069 // in the file PATENTS. All contributing project authors may
  63070 // be found in the AUTHORS file in the root of the source tree.
  63071 // -----------------------------------------------------------------------------
  63072 //
  63073 //   WebP encoder: internal header.
  63074 //
  63075 // Author: Skal (pascal.massimino@gmail.com)
  63076 
  63077 //------------------------------------------------------------------------------
  63078 // Boolean-cost cost table
  63079 
  63080 var VP8EntropyCost = [256]uint16_t{
  63081 	0:   uint16(1792),
  63082 	1:   uint16(1792),
  63083 	2:   uint16(1792),
  63084 	3:   uint16(1536),
  63085 	4:   uint16(1536),
  63086 	5:   uint16(1408),
  63087 	6:   uint16(1366),
  63088 	7:   uint16(1280),
  63089 	8:   uint16(1280),
  63090 	9:   uint16(1216),
  63091 	10:  uint16(1178),
  63092 	11:  uint16(1152),
  63093 	12:  uint16(1110),
  63094 	13:  uint16(1076),
  63095 	14:  uint16(1061),
  63096 	15:  uint16(1024),
  63097 	16:  uint16(1024),
  63098 	17:  uint16(992),
  63099 	18:  uint16(968),
  63100 	19:  uint16(951),
  63101 	20:  uint16(939),
  63102 	21:  uint16(911),
  63103 	22:  uint16(896),
  63104 	23:  uint16(878),
  63105 	24:  uint16(871),
  63106 	25:  uint16(854),
  63107 	26:  uint16(838),
  63108 	27:  uint16(820),
  63109 	28:  uint16(811),
  63110 	29:  uint16(794),
  63111 	30:  uint16(786),
  63112 	31:  uint16(768),
  63113 	32:  uint16(768),
  63114 	33:  uint16(752),
  63115 	34:  uint16(740),
  63116 	35:  uint16(732),
  63117 	36:  uint16(720),
  63118 	37:  uint16(709),
  63119 	38:  uint16(704),
  63120 	39:  uint16(690),
  63121 	40:  uint16(683),
  63122 	41:  uint16(672),
  63123 	42:  uint16(666),
  63124 	43:  uint16(655),
  63125 	44:  uint16(647),
  63126 	45:  uint16(640),
  63127 	46:  uint16(631),
  63128 	47:  uint16(622),
  63129 	48:  uint16(615),
  63130 	49:  uint16(607),
  63131 	50:  uint16(598),
  63132 	51:  uint16(592),
  63133 	52:  uint16(586),
  63134 	53:  uint16(576),
  63135 	54:  uint16(572),
  63136 	55:  uint16(564),
  63137 	56:  uint16(559),
  63138 	57:  uint16(555),
  63139 	58:  uint16(547),
  63140 	59:  uint16(541),
  63141 	60:  uint16(534),
  63142 	61:  uint16(528),
  63143 	62:  uint16(522),
  63144 	63:  uint16(512),
  63145 	64:  uint16(512),
  63146 	65:  uint16(504),
  63147 	66:  uint16(500),
  63148 	67:  uint16(494),
  63149 	68:  uint16(488),
  63150 	69:  uint16(483),
  63151 	70:  uint16(477),
  63152 	71:  uint16(473),
  63153 	72:  uint16(467),
  63154 	73:  uint16(461),
  63155 	74:  uint16(458),
  63156 	75:  uint16(452),
  63157 	76:  uint16(448),
  63158 	77:  uint16(443),
  63159 	78:  uint16(438),
  63160 	79:  uint16(434),
  63161 	80:  uint16(427),
  63162 	81:  uint16(424),
  63163 	82:  uint16(419),
  63164 	83:  uint16(415),
  63165 	84:  uint16(410),
  63166 	85:  uint16(406),
  63167 	86:  uint16(403),
  63168 	87:  uint16(399),
  63169 	88:  uint16(394),
  63170 	89:  uint16(390),
  63171 	90:  uint16(384),
  63172 	91:  uint16(384),
  63173 	92:  uint16(377),
  63174 	93:  uint16(374),
  63175 	94:  uint16(370),
  63176 	95:  uint16(366),
  63177 	96:  uint16(362),
  63178 	97:  uint16(359),
  63179 	98:  uint16(355),
  63180 	99:  uint16(351),
  63181 	100: uint16(347),
  63182 	101: uint16(342),
  63183 	102: uint16(342),
  63184 	103: uint16(336),
  63185 	104: uint16(333),
  63186 	105: uint16(330),
  63187 	106: uint16(326),
  63188 	107: uint16(323),
  63189 	108: uint16(320),
  63190 	109: uint16(316),
  63191 	110: uint16(312),
  63192 	111: uint16(308),
  63193 	112: uint16(305),
  63194 	113: uint16(302),
  63195 	114: uint16(299),
  63196 	115: uint16(296),
  63197 	116: uint16(293),
  63198 	117: uint16(288),
  63199 	118: uint16(287),
  63200 	119: uint16(283),
  63201 	120: uint16(280),
  63202 	121: uint16(277),
  63203 	122: uint16(274),
  63204 	123: uint16(272),
  63205 	124: uint16(268),
  63206 	125: uint16(266),
  63207 	126: uint16(262),
  63208 	127: uint16(256),
  63209 	128: uint16(256),
  63210 	129: uint16(256),
  63211 	130: uint16(251),
  63212 	131: uint16(248),
  63213 	132: uint16(245),
  63214 	133: uint16(242),
  63215 	134: uint16(240),
  63216 	135: uint16(237),
  63217 	136: uint16(234),
  63218 	137: uint16(232),
  63219 	138: uint16(228),
  63220 	139: uint16(226),
  63221 	140: uint16(223),
  63222 	141: uint16(221),
  63223 	142: uint16(218),
  63224 	143: uint16(216),
  63225 	144: uint16(214),
  63226 	145: uint16(211),
  63227 	146: uint16(208),
  63228 	147: uint16(205),
  63229 	148: uint16(203),
  63230 	149: uint16(201),
  63231 	150: uint16(198),
  63232 	151: uint16(196),
  63233 	152: uint16(192),
  63234 	153: uint16(191),
  63235 	154: uint16(188),
  63236 	155: uint16(187),
  63237 	156: uint16(183),
  63238 	157: uint16(181),
  63239 	158: uint16(179),
  63240 	159: uint16(176),
  63241 	160: uint16(175),
  63242 	161: uint16(171),
  63243 	162: uint16(171),
  63244 	163: uint16(168),
  63245 	164: uint16(165),
  63246 	165: uint16(163),
  63247 	166: uint16(160),
  63248 	167: uint16(159),
  63249 	168: uint16(156),
  63250 	169: uint16(154),
  63251 	170: uint16(152),
  63252 	171: uint16(150),
  63253 	172: uint16(148),
  63254 	173: uint16(146),
  63255 	174: uint16(144),
  63256 	175: uint16(142),
  63257 	176: uint16(139),
  63258 	177: uint16(138),
  63259 	178: uint16(135),
  63260 	179: uint16(133),
  63261 	180: uint16(131),
  63262 	181: uint16(128),
  63263 	182: uint16(128),
  63264 	183: uint16(125),
  63265 	184: uint16(123),
  63266 	185: uint16(121),
  63267 	186: uint16(119),
  63268 	187: uint16(117),
  63269 	188: uint16(115),
  63270 	189: uint16(113),
  63271 	190: uint16(111),
  63272 	191: uint16(110),
  63273 	192: uint16(107),
  63274 	193: uint16(105),
  63275 	194: uint16(103),
  63276 	195: uint16(102),
  63277 	196: uint16(100),
  63278 	197: uint16(98),
  63279 	198: uint16(96),
  63280 	199: uint16(94),
  63281 	200: uint16(92),
  63282 	201: uint16(91),
  63283 	202: uint16(89),
  63284 	203: uint16(86),
  63285 	204: uint16(86),
  63286 	205: uint16(83),
  63287 	206: uint16(82),
  63288 	207: uint16(80),
  63289 	208: uint16(77),
  63290 	209: uint16(76),
  63291 	210: uint16(74),
  63292 	211: uint16(73),
  63293 	212: uint16(71),
  63294 	213: uint16(69),
  63295 	214: uint16(67),
  63296 	215: uint16(66),
  63297 	216: uint16(64),
  63298 	217: uint16(63),
  63299 	218: uint16(61),
  63300 	219: uint16(59),
  63301 	220: uint16(57),
  63302 	221: uint16(55),
  63303 	222: uint16(54),
  63304 	223: uint16(52),
  63305 	224: uint16(51),
  63306 	225: uint16(49),
  63307 	226: uint16(47),
  63308 	227: uint16(46),
  63309 	228: uint16(44),
  63310 	229: uint16(43),
  63311 	230: uint16(41),
  63312 	231: uint16(40),
  63313 	232: uint16(38),
  63314 	233: uint16(36),
  63315 	234: uint16(35),
  63316 	235: uint16(33),
  63317 	236: uint16(32),
  63318 	237: uint16(30),
  63319 	238: uint16(29),
  63320 	239: uint16(27),
  63321 	240: uint16(25),
  63322 	241: uint16(24),
  63323 	242: uint16(22),
  63324 	243: uint16(21),
  63325 	244: uint16(19),
  63326 	245: uint16(18),
  63327 	246: uint16(16),
  63328 	247: uint16(15),
  63329 	248: uint16(13),
  63330 	249: uint16(12),
  63331 	250: uint16(10),
  63332 	251: uint16(9),
  63333 	252: uint16(7),
  63334 	253: uint16(6),
  63335 	254: uint16(4),
  63336 	255: uint16(3),
  63337 }
  63338 
  63339 var VP8FTransform VP8Fdct
  63340 
  63341 var VP8FTransform2 VP8Fdct
  63342 
  63343 var VP8FTransformWHT VP8WHT
  63344 
  63345 // C documentation
  63346 //
  63347 //	// note: these values include the fixed VP8BitCost(1, 145) mode selection cost.
  63348 var VP8FixedCostsI16 = [4]uint16_t{
  63349 	0: uint16(663),
  63350 	1: uint16(919),
  63351 	2: uint16(872),
  63352 	3: uint16(919),
  63353 }
  63354 
  63355 var VP8FixedCostsI4 = [10][10][10]uint16_t{
  63356 	0: {
  63357 		0: {
  63358 			0: uint16(40),
  63359 			1: uint16(1151),
  63360 			2: uint16(1723),
  63361 			3: uint16(1874),
  63362 			4: uint16(2103),
  63363 			5: uint16(2019),
  63364 			6: uint16(1628),
  63365 			7: uint16(1777),
  63366 			8: uint16(2226),
  63367 			9: uint16(2137),
  63368 		},
  63369 		1: {
  63370 			0: uint16(192),
  63371 			1: uint16(469),
  63372 			2: uint16(1296),
  63373 			3: uint16(1308),
  63374 			4: uint16(1849),
  63375 			5: uint16(1794),
  63376 			6: uint16(1781),
  63377 			7: uint16(1703),
  63378 			8: uint16(1713),
  63379 			9: uint16(1522),
  63380 		},
  63381 		2: {
  63382 			0: uint16(142),
  63383 			1: uint16(910),
  63384 			2: uint16(762),
  63385 			3: uint16(1684),
  63386 			4: uint16(1849),
  63387 			5: uint16(1576),
  63388 			6: uint16(1460),
  63389 			7: uint16(1305),
  63390 			8: uint16(1801),
  63391 			9: uint16(1657),
  63392 		},
  63393 		3: {
  63394 			0: uint16(559),
  63395 			1: uint16(641),
  63396 			2: uint16(1370),
  63397 			3: uint16(421),
  63398 			4: uint16(1182),
  63399 			5: uint16(1569),
  63400 			6: uint16(1612),
  63401 			7: uint16(1725),
  63402 			8: uint16(863),
  63403 			9: uint16(1007),
  63404 		},
  63405 		4: {
  63406 			0: uint16(299),
  63407 			1: uint16(1059),
  63408 			2: uint16(1256),
  63409 			3: uint16(1108),
  63410 			4: uint16(636),
  63411 			5: uint16(1068),
  63412 			6: uint16(1581),
  63413 			7: uint16(1883),
  63414 			8: uint16(869),
  63415 			9: uint16(1142),
  63416 		},
  63417 		5: {
  63418 			0: uint16(277),
  63419 			1: uint16(1111),
  63420 			2: uint16(707),
  63421 			3: uint16(1362),
  63422 			4: uint16(1089),
  63423 			5: uint16(672),
  63424 			6: uint16(1603),
  63425 			7: uint16(1541),
  63426 			8: uint16(1545),
  63427 			9: uint16(1291),
  63428 		},
  63429 		6: {
  63430 			0: uint16(214),
  63431 			1: uint16(781),
  63432 			2: uint16(1609),
  63433 			3: uint16(1303),
  63434 			4: uint16(1632),
  63435 			5: uint16(2229),
  63436 			6: uint16(726),
  63437 			7: uint16(1560),
  63438 			8: uint16(1713),
  63439 			9: uint16(918),
  63440 		},
  63441 		7: {
  63442 			0: uint16(152),
  63443 			1: uint16(1037),
  63444 			2: uint16(1046),
  63445 			3: uint16(1759),
  63446 			4: uint16(1983),
  63447 			5: uint16(2174),
  63448 			6: uint16(1358),
  63449 			7: uint16(742),
  63450 			8: uint16(1740),
  63451 			9: uint16(1390),
  63452 		},
  63453 		8: {
  63454 			0: uint16(512),
  63455 			1: uint16(1046),
  63456 			2: uint16(1420),
  63457 			3: uint16(753),
  63458 			4: uint16(752),
  63459 			5: uint16(1297),
  63460 			6: uint16(1486),
  63461 			7: uint16(1613),
  63462 			8: uint16(460),
  63463 			9: uint16(1207),
  63464 		},
  63465 		9: {
  63466 			0: uint16(424),
  63467 			1: uint16(827),
  63468 			2: uint16(1362),
  63469 			3: uint16(719),
  63470 			4: uint16(1462),
  63471 			5: uint16(1202),
  63472 			6: uint16(1199),
  63473 			7: uint16(1476),
  63474 			8: uint16(1199),
  63475 			9: uint16(538),
  63476 		},
  63477 	},
  63478 	1: {
  63479 		0: {
  63480 			0: uint16(240),
  63481 			1: uint16(402),
  63482 			2: uint16(1134),
  63483 			3: uint16(1491),
  63484 			4: uint16(1659),
  63485 			5: uint16(1505),
  63486 			6: uint16(1517),
  63487 			7: uint16(1555),
  63488 			8: uint16(1979),
  63489 			9: uint16(2099),
  63490 		},
  63491 		1: {
  63492 			0: uint16(467),
  63493 			1: uint16(242),
  63494 			2: uint16(960),
  63495 			3: uint16(1232),
  63496 			4: uint16(1714),
  63497 			5: uint16(1620),
  63498 			6: uint16(1834),
  63499 			7: uint16(1570),
  63500 			8: uint16(1676),
  63501 			9: uint16(1391),
  63502 		},
  63503 		2: {
  63504 			0: uint16(500),
  63505 			1: uint16(455),
  63506 			2: uint16(463),
  63507 			3: uint16(1507),
  63508 			4: uint16(1699),
  63509 			5: uint16(1282),
  63510 			6: uint16(1564),
  63511 			7: uint16(982),
  63512 			8: uint16(2114),
  63513 			9: uint16(2114),
  63514 		},
  63515 		3: {
  63516 			0: uint16(672),
  63517 			1: uint16(643),
  63518 			2: uint16(1372),
  63519 			3: uint16(331),
  63520 			4: uint16(1589),
  63521 			5: uint16(1667),
  63522 			6: uint16(1453),
  63523 			7: uint16(1938),
  63524 			8: uint16(996),
  63525 			9: uint16(876),
  63526 		},
  63527 		4: {
  63528 			0: uint16(458),
  63529 			1: uint16(783),
  63530 			2: uint16(1037),
  63531 			3: uint16(911),
  63532 			4: uint16(738),
  63533 			5: uint16(968),
  63534 			6: uint16(1165),
  63535 			7: uint16(1518),
  63536 			8: uint16(859),
  63537 			9: uint16(1033),
  63538 		},
  63539 		5: {
  63540 			0: uint16(504),
  63541 			1: uint16(815),
  63542 			2: uint16(504),
  63543 			3: uint16(1139),
  63544 			4: uint16(1219),
  63545 			5: uint16(719),
  63546 			6: uint16(1506),
  63547 			7: uint16(1085),
  63548 			8: uint16(1268),
  63549 			9: uint16(1268),
  63550 		},
  63551 		6: {
  63552 			0: uint16(333),
  63553 			1: uint16(630),
  63554 			2: uint16(1445),
  63555 			3: uint16(1239),
  63556 			4: uint16(1883),
  63557 			5: uint16(3672),
  63558 			6: uint16(799),
  63559 			7: uint16(1548),
  63560 			8: uint16(1865),
  63561 			9: uint16(598),
  63562 		},
  63563 		7: {
  63564 			0: uint16(399),
  63565 			1: uint16(644),
  63566 			2: uint16(746),
  63567 			3: uint16(1342),
  63568 			4: uint16(1856),
  63569 			5: uint16(1350),
  63570 			6: uint16(1493),
  63571 			7: uint16(613),
  63572 			8: uint16(1855),
  63573 			9: uint16(1015),
  63574 		},
  63575 		8: {
  63576 			0: uint16(622),
  63577 			1: uint16(749),
  63578 			2: uint16(1205),
  63579 			3: uint16(608),
  63580 			4: uint16(1066),
  63581 			5: uint16(1408),
  63582 			6: uint16(1290),
  63583 			7: uint16(1406),
  63584 			8: uint16(546),
  63585 			9: uint16(971),
  63586 		},
  63587 		9: {
  63588 			0: uint16(500),
  63589 			1: uint16(753),
  63590 			2: uint16(1041),
  63591 			3: uint16(668),
  63592 			4: uint16(1230),
  63593 			5: uint16(1617),
  63594 			6: uint16(1297),
  63595 			7: uint16(1425),
  63596 			8: uint16(1383),
  63597 			9: uint16(523),
  63598 		},
  63599 	},
  63600 	2: {
  63601 		0: {
  63602 			0: uint16(394),
  63603 			1: uint16(553),
  63604 			2: uint16(523),
  63605 			3: uint16(1502),
  63606 			4: uint16(1536),
  63607 			5: uint16(981),
  63608 			6: uint16(1608),
  63609 			7: uint16(1142),
  63610 			8: uint16(1666),
  63611 			9: uint16(2181),
  63612 		},
  63613 		1: {
  63614 			0: uint16(655),
  63615 			1: uint16(430),
  63616 			2: uint16(375),
  63617 			3: uint16(1411),
  63618 			4: uint16(1861),
  63619 			5: uint16(1220),
  63620 			6: uint16(1677),
  63621 			7: uint16(1135),
  63622 			8: uint16(1978),
  63623 			9: uint16(1553),
  63624 		},
  63625 		2: {
  63626 			0: uint16(690),
  63627 			1: uint16(640),
  63628 			2: uint16(245),
  63629 			3: uint16(1954),
  63630 			4: uint16(2070),
  63631 			5: uint16(1194),
  63632 			6: uint16(1528),
  63633 			7: uint16(982),
  63634 			8: uint16(1972),
  63635 			9: uint16(2232),
  63636 		},
  63637 		3: {
  63638 			0: uint16(559),
  63639 			1: uint16(834),
  63640 			2: uint16(741),
  63641 			3: uint16(867),
  63642 			4: uint16(1131),
  63643 			5: uint16(980),
  63644 			6: uint16(1225),
  63645 			7: uint16(852),
  63646 			8: uint16(1092),
  63647 			9: uint16(784),
  63648 		},
  63649 		4: {
  63650 			0: uint16(690),
  63651 			1: uint16(875),
  63652 			2: uint16(516),
  63653 			3: uint16(959),
  63654 			4: uint16(673),
  63655 			5: uint16(894),
  63656 			6: uint16(1056),
  63657 			7: uint16(1190),
  63658 			8: uint16(1528),
  63659 			9: uint16(1126),
  63660 		},
  63661 		5: {
  63662 			0: uint16(740),
  63663 			1: uint16(951),
  63664 			2: uint16(384),
  63665 			3: uint16(1277),
  63666 			4: uint16(1177),
  63667 			5: uint16(492),
  63668 			6: uint16(1579),
  63669 			7: uint16(1155),
  63670 			8: uint16(1846),
  63671 			9: uint16(1513),
  63672 		},
  63673 		6: {
  63674 			0: uint16(323),
  63675 			1: uint16(775),
  63676 			2: uint16(1062),
  63677 			3: uint16(1776),
  63678 			4: uint16(3062),
  63679 			5: uint16(1274),
  63680 			6: uint16(813),
  63681 			7: uint16(1188),
  63682 			8: uint16(1372),
  63683 			9: uint16(655),
  63684 		},
  63685 		7: {
  63686 			0: uint16(488),
  63687 			1: uint16(971),
  63688 			2: uint16(484),
  63689 			3: uint16(1767),
  63690 			4: uint16(1515),
  63691 			5: uint16(1775),
  63692 			6: uint16(1115),
  63693 			7: uint16(503),
  63694 			8: uint16(1539),
  63695 			9: uint16(1461),
  63696 		},
  63697 		8: {
  63698 			0: uint16(740),
  63699 			1: uint16(1006),
  63700 			2: uint16(998),
  63701 			3: uint16(709),
  63702 			4: uint16(851),
  63703 			5: uint16(1230),
  63704 			6: uint16(1337),
  63705 			7: uint16(788),
  63706 			8: uint16(741),
  63707 			9: uint16(721),
  63708 		},
  63709 		9: {
  63710 			0: uint16(522),
  63711 			1: uint16(1073),
  63712 			2: uint16(573),
  63713 			3: uint16(1045),
  63714 			4: uint16(1346),
  63715 			5: uint16(887),
  63716 			6: uint16(1046),
  63717 			7: uint16(1146),
  63718 			8: uint16(1203),
  63719 			9: uint16(697),
  63720 		},
  63721 	},
  63722 	3: {
  63723 		0: {
  63724 			0: uint16(105),
  63725 			1: uint16(864),
  63726 			2: uint16(1442),
  63727 			3: uint16(1009),
  63728 			4: uint16(1934),
  63729 			5: uint16(1840),
  63730 			6: uint16(1519),
  63731 			7: uint16(1920),
  63732 			8: uint16(1673),
  63733 			9: uint16(1579),
  63734 		},
  63735 		1: {
  63736 			0: uint16(534),
  63737 			1: uint16(305),
  63738 			2: uint16(1193),
  63739 			3: uint16(683),
  63740 			4: uint16(1388),
  63741 			5: uint16(2164),
  63742 			6: uint16(1802),
  63743 			7: uint16(1894),
  63744 			8: uint16(1264),
  63745 			9: uint16(1170),
  63746 		},
  63747 		2: {
  63748 			0: uint16(305),
  63749 			1: uint16(518),
  63750 			2: uint16(877),
  63751 			3: uint16(1108),
  63752 			4: uint16(1426),
  63753 			5: uint16(3215),
  63754 			6: uint16(1425),
  63755 			7: uint16(1064),
  63756 			8: uint16(1320),
  63757 			9: uint16(1242),
  63758 		},
  63759 		3: {
  63760 			0: uint16(683),
  63761 			1: uint16(732),
  63762 			2: uint16(1927),
  63763 			3: uint16(257),
  63764 			4: uint16(1493),
  63765 			5: uint16(2048),
  63766 			6: uint16(1858),
  63767 			7: uint16(1552),
  63768 			8: uint16(1055),
  63769 			9: uint16(947),
  63770 		},
  63771 		4: {
  63772 			0: uint16(394),
  63773 			1: uint16(814),
  63774 			2: uint16(1024),
  63775 			3: uint16(660),
  63776 			4: uint16(959),
  63777 			5: uint16(1556),
  63778 			6: uint16(1282),
  63779 			7: uint16(1289),
  63780 			8: uint16(893),
  63781 			9: uint16(1047),
  63782 		},
  63783 		5: {
  63784 			0: uint16(528),
  63785 			1: uint16(615),
  63786 			2: uint16(996),
  63787 			3: uint16(940),
  63788 			4: uint16(1201),
  63789 			5: uint16(635),
  63790 			6: uint16(1094),
  63791 			7: uint16(2515),
  63792 			8: uint16(803),
  63793 			9: uint16(1358),
  63794 		},
  63795 		6: {
  63796 			0: uint16(347),
  63797 			1: uint16(614),
  63798 			2: uint16(1609),
  63799 			3: uint16(1187),
  63800 			4: uint16(3133),
  63801 			5: uint16(1345),
  63802 			6: uint16(1007),
  63803 			7: uint16(1339),
  63804 			8: uint16(1017),
  63805 			9: uint16(667),
  63806 		},
  63807 		7: {
  63808 			0: uint16(218),
  63809 			1: uint16(740),
  63810 			2: uint16(878),
  63811 			3: uint16(1605),
  63812 			4: uint16(3650),
  63813 			5: uint16(3650),
  63814 			6: uint16(1345),
  63815 			7: uint16(758),
  63816 			8: uint16(1357),
  63817 			9: uint16(1617),
  63818 		},
  63819 		8: {
  63820 			0: uint16(672),
  63821 			1: uint16(750),
  63822 			2: uint16(1541),
  63823 			3: uint16(558),
  63824 			4: uint16(1257),
  63825 			5: uint16(1599),
  63826 			6: uint16(1870),
  63827 			7: uint16(2135),
  63828 			8: uint16(402),
  63829 			9: uint16(1087),
  63830 		},
  63831 		9: {
  63832 			0: uint16(592),
  63833 			1: uint16(684),
  63834 			2: uint16(1161),
  63835 			3: uint16(430),
  63836 			4: uint16(1092),
  63837 			5: uint16(1497),
  63838 			6: uint16(1475),
  63839 			7: uint16(1489),
  63840 			8: uint16(1095),
  63841 			9: uint16(822),
  63842 		},
  63843 	},
  63844 	4: {
  63845 		0: {
  63846 			0: uint16(228),
  63847 			1: uint16(1056),
  63848 			2: uint16(1059),
  63849 			3: uint16(1368),
  63850 			4: uint16(752),
  63851 			5: uint16(982),
  63852 			6: uint16(1512),
  63853 			7: uint16(1518),
  63854 			8: uint16(987),
  63855 			9: uint16(1782),
  63856 		},
  63857 		1: {
  63858 			0: uint16(494),
  63859 			1: uint16(514),
  63860 			2: uint16(818),
  63861 			3: uint16(942),
  63862 			4: uint16(965),
  63863 			5: uint16(892),
  63864 			6: uint16(1610),
  63865 			7: uint16(1356),
  63866 			8: uint16(1048),
  63867 			9: uint16(1363),
  63868 		},
  63869 		2: {
  63870 			0: uint16(512),
  63871 			1: uint16(648),
  63872 			2: uint16(591),
  63873 			3: uint16(1042),
  63874 			4: uint16(761),
  63875 			5: uint16(991),
  63876 			6: uint16(1196),
  63877 			7: uint16(1454),
  63878 			8: uint16(1309),
  63879 			9: uint16(1463),
  63880 		},
  63881 		3: {
  63882 			0: uint16(683),
  63883 			1: uint16(749),
  63884 			2: uint16(1043),
  63885 			3: uint16(676),
  63886 			4: uint16(841),
  63887 			5: uint16(1396),
  63888 			6: uint16(1133),
  63889 			7: uint16(1138),
  63890 			8: uint16(654),
  63891 			9: uint16(939),
  63892 		},
  63893 		4: {
  63894 			0: uint16(622),
  63895 			1: uint16(1101),
  63896 			2: uint16(1126),
  63897 			3: uint16(994),
  63898 			4: uint16(361),
  63899 			5: uint16(1077),
  63900 			6: uint16(1203),
  63901 			7: uint16(1318),
  63902 			8: uint16(877),
  63903 			9: uint16(1219),
  63904 		},
  63905 		5: {
  63906 			0: uint16(631),
  63907 			1: uint16(1068),
  63908 			2: uint16(857),
  63909 			3: uint16(1650),
  63910 			4: uint16(651),
  63911 			5: uint16(477),
  63912 			6: uint16(1650),
  63913 			7: uint16(1419),
  63914 			8: uint16(828),
  63915 			9: uint16(1170),
  63916 		},
  63917 		6: {
  63918 			0: uint16(555),
  63919 			1: uint16(727),
  63920 			2: uint16(1068),
  63921 			3: uint16(1335),
  63922 			4: uint16(3127),
  63923 			5: uint16(1339),
  63924 			6: uint16(820),
  63925 			7: uint16(1331),
  63926 			8: uint16(1077),
  63927 			9: uint16(429),
  63928 		},
  63929 		7: {
  63930 			0: uint16(504),
  63931 			1: uint16(879),
  63932 			2: uint16(624),
  63933 			3: uint16(1398),
  63934 			4: uint16(889),
  63935 			5: uint16(889),
  63936 			6: uint16(1392),
  63937 			7: uint16(808),
  63938 			8: uint16(891),
  63939 			9: uint16(1406),
  63940 		},
  63941 		8: {
  63942 			0: uint16(683),
  63943 			1: uint16(1602),
  63944 			2: uint16(1289),
  63945 			3: uint16(977),
  63946 			4: uint16(578),
  63947 			5: uint16(983),
  63948 			6: uint16(1280),
  63949 			7: uint16(1708),
  63950 			8: uint16(406),
  63951 			9: uint16(1122),
  63952 		},
  63953 		9: {
  63954 			0: uint16(399),
  63955 			1: uint16(865),
  63956 			2: uint16(1433),
  63957 			3: uint16(1070),
  63958 			4: uint16(1072),
  63959 			5: uint16(764),
  63960 			6: uint16(968),
  63961 			7: uint16(1477),
  63962 			8: uint16(1223),
  63963 			9: uint16(678),
  63964 		},
  63965 	},
  63966 	5: {
  63967 		0: {
  63968 			0: uint16(333),
  63969 			1: uint16(760),
  63970 			2: uint16(935),
  63971 			3: uint16(1638),
  63972 			4: uint16(1010),
  63973 			5: uint16(529),
  63974 			6: uint16(1646),
  63975 			7: uint16(1410),
  63976 			8: uint16(1472),
  63977 			9: uint16(2219),
  63978 		},
  63979 		1: {
  63980 			0: uint16(512),
  63981 			1: uint16(494),
  63982 			2: uint16(750),
  63983 			3: uint16(1160),
  63984 			4: uint16(1215),
  63985 			5: uint16(610),
  63986 			6: uint16(1870),
  63987 			7: uint16(1868),
  63988 			8: uint16(1628),
  63989 			9: uint16(1169),
  63990 		},
  63991 		2: {
  63992 			0: uint16(572),
  63993 			1: uint16(646),
  63994 			2: uint16(492),
  63995 			3: uint16(1934),
  63996 			4: uint16(1208),
  63997 			5: uint16(603),
  63998 			6: uint16(1580),
  63999 			7: uint16(1099),
  64000 			8: uint16(1398),
  64001 			9: uint16(1995),
  64002 		},
  64003 		3: {
  64004 			0: uint16(786),
  64005 			1: uint16(789),
  64006 			2: uint16(942),
  64007 			3: uint16(581),
  64008 			4: uint16(1018),
  64009 			5: uint16(951),
  64010 			6: uint16(1599),
  64011 			7: uint16(1207),
  64012 			8: uint16(731),
  64013 			9: uint16(768),
  64014 		},
  64015 		4: {
  64016 			0: uint16(690),
  64017 			1: uint16(1015),
  64018 			2: uint16(672),
  64019 			3: uint16(1078),
  64020 			4: uint16(582),
  64021 			5: uint16(504),
  64022 			6: uint16(1693),
  64023 			7: uint16(1438),
  64024 			8: uint16(1108),
  64025 			9: uint16(2897),
  64026 		},
  64027 		5: {
  64028 			0: uint16(768),
  64029 			1: uint16(1267),
  64030 			2: uint16(571),
  64031 			3: uint16(2005),
  64032 			4: uint16(1243),
  64033 			5: uint16(244),
  64034 			6: uint16(2881),
  64035 			7: uint16(1380),
  64036 			8: uint16(1786),
  64037 			9: uint16(1453),
  64038 		},
  64039 		6: {
  64040 			0: uint16(452),
  64041 			1: uint16(899),
  64042 			2: uint16(1293),
  64043 			3: uint16(903),
  64044 			4: uint16(1311),
  64045 			5: uint16(3100),
  64046 			6: uint16(465),
  64047 			7: uint16(1311),
  64048 			8: uint16(1319),
  64049 			9: uint16(813),
  64050 		},
  64051 		7: {
  64052 			0: uint16(394),
  64053 			1: uint16(927),
  64054 			2: uint16(942),
  64055 			3: uint16(1103),
  64056 			4: uint16(1358),
  64057 			5: uint16(1104),
  64058 			6: uint16(946),
  64059 			7: uint16(593),
  64060 			8: uint16(1363),
  64061 			9: uint16(1109),
  64062 		},
  64063 		8: {
  64064 			0: uint16(559),
  64065 			1: uint16(1005),
  64066 			2: uint16(1007),
  64067 			3: uint16(1016),
  64068 			4: uint16(658),
  64069 			5: uint16(1173),
  64070 			6: uint16(1021),
  64071 			7: uint16(1164),
  64072 			8: uint16(623),
  64073 			9: uint16(1028),
  64074 		},
  64075 		9: {
  64076 			0: uint16(564),
  64077 			1: uint16(796),
  64078 			2: uint16(632),
  64079 			3: uint16(1005),
  64080 			4: uint16(1014),
  64081 			5: uint16(863),
  64082 			6: uint16(2316),
  64083 			7: uint16(1268),
  64084 			8: uint16(938),
  64085 			9: uint16(764),
  64086 		},
  64087 	},
  64088 	6: {
  64089 		0: {
  64090 			0: uint16(266),
  64091 			1: uint16(606),
  64092 			2: uint16(1098),
  64093 			3: uint16(1228),
  64094 			4: uint16(1497),
  64095 			5: uint16(1243),
  64096 			6: uint16(948),
  64097 			7: uint16(1030),
  64098 			8: uint16(1734),
  64099 			9: uint16(1461),
  64100 		},
  64101 		1: {
  64102 			0: uint16(366),
  64103 			1: uint16(585),
  64104 			2: uint16(901),
  64105 			3: uint16(1060),
  64106 			4: uint16(1407),
  64107 			5: uint16(1247),
  64108 			6: uint16(876),
  64109 			7: uint16(1134),
  64110 			8: uint16(1620),
  64111 			9: uint16(1054),
  64112 		},
  64113 		2: {
  64114 			0: uint16(452),
  64115 			1: uint16(565),
  64116 			2: uint16(542),
  64117 			3: uint16(1729),
  64118 			4: uint16(1479),
  64119 			5: uint16(1479),
  64120 			6: uint16(1016),
  64121 			7: uint16(886),
  64122 			8: uint16(2938),
  64123 			9: uint16(1150),
  64124 		},
  64125 		3: {
  64126 			0: uint16(555),
  64127 			1: uint16(1088),
  64128 			2: uint16(1533),
  64129 			3: uint16(950),
  64130 			4: uint16(1354),
  64131 			5: uint16(895),
  64132 			6: uint16(834),
  64133 			7: uint16(1019),
  64134 			8: uint16(1021),
  64135 			9: uint16(496),
  64136 		},
  64137 		4: {
  64138 			0: uint16(704),
  64139 			1: uint16(815),
  64140 			2: uint16(1193),
  64141 			3: uint16(971),
  64142 			4: uint16(973),
  64143 			5: uint16(640),
  64144 			6: uint16(1217),
  64145 			7: uint16(2214),
  64146 			8: uint16(832),
  64147 			9: uint16(578),
  64148 		},
  64149 		5: {
  64150 			0: uint16(672),
  64151 			1: uint16(1245),
  64152 			2: uint16(579),
  64153 			3: uint16(871),
  64154 			4: uint16(875),
  64155 			5: uint16(774),
  64156 			6: uint16(872),
  64157 			7: uint16(1273),
  64158 			8: uint16(1027),
  64159 			9: uint16(949),
  64160 		},
  64161 		6: {
  64162 			0: uint16(296),
  64163 			1: uint16(1134),
  64164 			2: uint16(2050),
  64165 			3: uint16(1784),
  64166 			4: uint16(1636),
  64167 			5: uint16(3425),
  64168 			6: uint16(442),
  64169 			7: uint16(1550),
  64170 			8: uint16(2076),
  64171 			9: uint16(722),
  64172 		},
  64173 		7: {
  64174 			0: uint16(342),
  64175 			1: uint16(982),
  64176 			2: uint16(1259),
  64177 			3: uint16(1846),
  64178 			4: uint16(1848),
  64179 			5: uint16(1848),
  64180 			6: uint16(622),
  64181 			7: uint16(568),
  64182 			8: uint16(1847),
  64183 			9: uint16(1052),
  64184 		},
  64185 		8: {
  64186 			0: uint16(555),
  64187 			1: uint16(1064),
  64188 			2: uint16(1304),
  64189 			3: uint16(828),
  64190 			4: uint16(746),
  64191 			5: uint16(1343),
  64192 			6: uint16(1075),
  64193 			7: uint16(1329),
  64194 			8: uint16(1078),
  64195 			9: uint16(494),
  64196 		},
  64197 		9: {
  64198 			0: uint16(288),
  64199 			1: uint16(1167),
  64200 			2: uint16(1285),
  64201 			3: uint16(1174),
  64202 			4: uint16(1639),
  64203 			5: uint16(1639),
  64204 			6: uint16(833),
  64205 			7: uint16(2254),
  64206 			8: uint16(1304),
  64207 			9: uint16(509),
  64208 		},
  64209 	},
  64210 	7: {
  64211 		0: {
  64212 			0: uint16(342),
  64213 			1: uint16(719),
  64214 			2: uint16(767),
  64215 			3: uint16(1866),
  64216 			4: uint16(1757),
  64217 			5: uint16(1270),
  64218 			6: uint16(1246),
  64219 			7: uint16(550),
  64220 			8: uint16(1746),
  64221 			9: uint16(2151),
  64222 		},
  64223 		1: {
  64224 			0: uint16(483),
  64225 			1: uint16(653),
  64226 			2: uint16(694),
  64227 			3: uint16(1509),
  64228 			4: uint16(1459),
  64229 			5: uint16(1410),
  64230 			6: uint16(1218),
  64231 			7: uint16(507),
  64232 			8: uint16(1914),
  64233 			9: uint16(1266),
  64234 		},
  64235 		2: {
  64236 			0: uint16(488),
  64237 			1: uint16(757),
  64238 			2: uint16(447),
  64239 			3: uint16(2979),
  64240 			4: uint16(1813),
  64241 			5: uint16(1268),
  64242 			6: uint16(1654),
  64243 			7: uint16(539),
  64244 			8: uint16(1849),
  64245 			9: uint16(2109),
  64246 		},
  64247 		3: {
  64248 			0: uint16(522),
  64249 			1: uint16(1097),
  64250 			2: uint16(1085),
  64251 			3: uint16(851),
  64252 			4: uint16(1365),
  64253 			5: uint16(1111),
  64254 			6: uint16(851),
  64255 			7: uint16(901),
  64256 			8: uint16(961),
  64257 			9: uint16(605),
  64258 		},
  64259 		4: {
  64260 			0: uint16(709),
  64261 			1: uint16(716),
  64262 			2: uint16(841),
  64263 			3: uint16(728),
  64264 			4: uint16(736),
  64265 			5: uint16(945),
  64266 			6: uint16(941),
  64267 			7: uint16(862),
  64268 			8: uint16(2845),
  64269 			9: uint16(1057),
  64270 		},
  64271 		5: {
  64272 			0: uint16(512),
  64273 			1: uint16(1323),
  64274 			2: uint16(500),
  64275 			3: uint16(1336),
  64276 			4: uint16(1083),
  64277 			5: uint16(681),
  64278 			6: uint16(1342),
  64279 			7: uint16(717),
  64280 			8: uint16(1604),
  64281 			9: uint16(1350),
  64282 		},
  64283 		6: {
  64284 			0: uint16(452),
  64285 			1: uint16(1155),
  64286 			2: uint16(1372),
  64287 			3: uint16(1900),
  64288 			4: uint16(1501),
  64289 			5: uint16(3290),
  64290 			6: uint16(311),
  64291 			7: uint16(944),
  64292 			8: uint16(1919),
  64293 			9: uint16(922),
  64294 		},
  64295 		7: {
  64296 			0: uint16(403),
  64297 			1: uint16(1520),
  64298 			2: uint16(977),
  64299 			3: uint16(2132),
  64300 			4: uint16(1733),
  64301 			5: uint16(3522),
  64302 			6: uint16(1076),
  64303 			7: uint16(276),
  64304 			8: uint16(3335),
  64305 			9: uint16(1547),
  64306 		},
  64307 		8: {
  64308 			0: uint16(559),
  64309 			1: uint16(1374),
  64310 			2: uint16(1101),
  64311 			3: uint16(615),
  64312 			4: uint16(673),
  64313 			5: uint16(2462),
  64314 			6: uint16(974),
  64315 			7: uint16(795),
  64316 			8: uint16(984),
  64317 			9: uint16(984),
  64318 		},
  64319 		9: {
  64320 			0: uint16(547),
  64321 			1: uint16(1122),
  64322 			2: uint16(1062),
  64323 			3: uint16(812),
  64324 			4: uint16(1410),
  64325 			5: uint16(951),
  64326 			6: uint16(1140),
  64327 			7: uint16(622),
  64328 			8: uint16(1268),
  64329 			9: uint16(651),
  64330 		},
  64331 	},
  64332 	8: {
  64333 		0: {
  64334 			0: uint16(165),
  64335 			1: uint16(982),
  64336 			2: uint16(1235),
  64337 			3: uint16(938),
  64338 			4: uint16(1334),
  64339 			5: uint16(1366),
  64340 			6: uint16(1659),
  64341 			7: uint16(1578),
  64342 			8: uint16(964),
  64343 			9: uint16(1612),
  64344 		},
  64345 		1: {
  64346 			0: uint16(592),
  64347 			1: uint16(422),
  64348 			2: uint16(925),
  64349 			3: uint16(847),
  64350 			4: uint16(1139),
  64351 			5: uint16(1112),
  64352 			6: uint16(1387),
  64353 			7: uint16(2036),
  64354 			8: uint16(861),
  64355 			9: uint16(1041),
  64356 		},
  64357 		2: {
  64358 			0: uint16(403),
  64359 			1: uint16(837),
  64360 			2: uint16(732),
  64361 			3: uint16(770),
  64362 			4: uint16(941),
  64363 			5: uint16(1658),
  64364 			6: uint16(1250),
  64365 			7: uint16(809),
  64366 			8: uint16(1407),
  64367 			9: uint16(1407),
  64368 		},
  64369 		3: {
  64370 			0: uint16(896),
  64371 			1: uint16(874),
  64372 			2: uint16(1071),
  64373 			3: uint16(381),
  64374 			4: uint16(1568),
  64375 			5: uint16(1722),
  64376 			6: uint16(1437),
  64377 			7: uint16(2192),
  64378 			8: uint16(480),
  64379 			9: uint16(1035),
  64380 		},
  64381 		4: {
  64382 			0: uint16(640),
  64383 			1: uint16(1098),
  64384 			2: uint16(1012),
  64385 			3: uint16(1032),
  64386 			4: uint16(684),
  64387 			5: uint16(1382),
  64388 			6: uint16(1581),
  64389 			7: uint16(2106),
  64390 			8: uint16(416),
  64391 			9: uint16(865),
  64392 		},
  64393 		5: {
  64394 			0: uint16(559),
  64395 			1: uint16(1005),
  64396 			2: uint16(819),
  64397 			3: uint16(914),
  64398 			4: uint16(710),
  64399 			5: uint16(770),
  64400 			6: uint16(1418),
  64401 			7: uint16(920),
  64402 			8: uint16(838),
  64403 			9: uint16(1435),
  64404 		},
  64405 		6: {
  64406 			0: uint16(415),
  64407 			1: uint16(1258),
  64408 			2: uint16(1245),
  64409 			3: uint16(870),
  64410 			4: uint16(1278),
  64411 			5: uint16(3067),
  64412 			6: uint16(770),
  64413 			7: uint16(1021),
  64414 			8: uint16(1287),
  64415 			9: uint16(522),
  64416 		},
  64417 		7: {
  64418 			0: uint16(406),
  64419 			1: uint16(990),
  64420 			2: uint16(601),
  64421 			3: uint16(1009),
  64422 			4: uint16(1265),
  64423 			5: uint16(1265),
  64424 			6: uint16(1267),
  64425 			7: uint16(759),
  64426 			8: uint16(1017),
  64427 			9: uint16(1277),
  64428 		},
  64429 		8: {
  64430 			0: uint16(968),
  64431 			1: uint16(1182),
  64432 			2: uint16(1329),
  64433 			3: uint16(788),
  64434 			4: uint16(1032),
  64435 			5: uint16(1292),
  64436 			6: uint16(1705),
  64437 			7: uint16(1714),
  64438 			8: uint16(203),
  64439 			9: uint16(1403),
  64440 		},
  64441 		9: {
  64442 			0: uint16(732),
  64443 			1: uint16(877),
  64444 			2: uint16(1279),
  64445 			3: uint16(471),
  64446 			4: uint16(901),
  64447 			5: uint16(1161),
  64448 			6: uint16(1545),
  64449 			7: uint16(1294),
  64450 			8: uint16(755),
  64451 			9: uint16(755),
  64452 		},
  64453 	},
  64454 	9: {
  64455 		0: {
  64456 			0: uint16(111),
  64457 			1: uint16(931),
  64458 			2: uint16(1378),
  64459 			3: uint16(1185),
  64460 			4: uint16(1933),
  64461 			5: uint16(1648),
  64462 			6: uint16(1148),
  64463 			7: uint16(1714),
  64464 			8: uint16(1873),
  64465 			9: uint16(1307),
  64466 		},
  64467 		1: {
  64468 			0: uint16(406),
  64469 			1: uint16(414),
  64470 			2: uint16(1030),
  64471 			3: uint16(1023),
  64472 			4: uint16(1910),
  64473 			5: uint16(1404),
  64474 			6: uint16(1313),
  64475 			7: uint16(1647),
  64476 			8: uint16(1509),
  64477 			9: uint16(793),
  64478 		},
  64479 		2: {
  64480 			0: uint16(342),
  64481 			1: uint16(640),
  64482 			2: uint16(575),
  64483 			3: uint16(1088),
  64484 			4: uint16(1241),
  64485 			5: uint16(1349),
  64486 			6: uint16(1161),
  64487 			7: uint16(1350),
  64488 			8: uint16(1756),
  64489 			9: uint16(1502),
  64490 		},
  64491 		3: {
  64492 			0: uint16(559),
  64493 			1: uint16(766),
  64494 			2: uint16(1185),
  64495 			3: uint16(357),
  64496 			4: uint16(1682),
  64497 			5: uint16(1428),
  64498 			6: uint16(1329),
  64499 			7: uint16(1897),
  64500 			8: uint16(1219),
  64501 			9: uint16(802),
  64502 		},
  64503 		4: {
  64504 			0: uint16(473),
  64505 			1: uint16(909),
  64506 			2: uint16(1164),
  64507 			3: uint16(771),
  64508 			4: uint16(719),
  64509 			5: uint16(2508),
  64510 			6: uint16(1427),
  64511 			7: uint16(1432),
  64512 			8: uint16(722),
  64513 			9: uint16(782),
  64514 		},
  64515 		5: {
  64516 			0: uint16(342),
  64517 			1: uint16(892),
  64518 			2: uint16(785),
  64519 			3: uint16(1145),
  64520 			4: uint16(1150),
  64521 			5: uint16(794),
  64522 			6: uint16(1296),
  64523 			7: uint16(1550),
  64524 			8: uint16(973),
  64525 			9: uint16(1057),
  64526 		},
  64527 		6: {
  64528 			0: uint16(208),
  64529 			1: uint16(1036),
  64530 			2: uint16(1326),
  64531 			3: uint16(1343),
  64532 			4: uint16(1606),
  64533 			5: uint16(3395),
  64534 			6: uint16(815),
  64535 			7: uint16(1455),
  64536 			8: uint16(1618),
  64537 			9: uint16(712),
  64538 		},
  64539 		7: {
  64540 			0: uint16(228),
  64541 			1: uint16(928),
  64542 			2: uint16(890),
  64543 			3: uint16(1046),
  64544 			4: uint16(3499),
  64545 			5: uint16(1711),
  64546 			6: uint16(994),
  64547 			7: uint16(829),
  64548 			8: uint16(1720),
  64549 			9: uint16(1318),
  64550 		},
  64551 		8: {
  64552 			0: uint16(768),
  64553 			1: uint16(724),
  64554 			2: uint16(1058),
  64555 			3: uint16(636),
  64556 			4: uint16(991),
  64557 			5: uint16(1075),
  64558 			6: uint16(1319),
  64559 			7: uint16(1324),
  64560 			8: uint16(616),
  64561 			9: uint16(825),
  64562 		},
  64563 		9: {
  64564 			0: uint16(305),
  64565 			1: uint16(1167),
  64566 			2: uint16(1358),
  64567 			3: uint16(899),
  64568 			4: uint16(1587),
  64569 			5: uint16(1587),
  64570 			6: uint16(987),
  64571 			7: uint16(1988),
  64572 			8: uint16(1332),
  64573 			9: uint16(501),
  64574 		},
  64575 	},
  64576 }
  64577 
  64578 //------------------------------------------------------------------------------
  64579 // Mode cost tables.
  64580 
  64581 // C documentation
  64582 //
  64583 //	// These are the fixed probabilities (in the coding trees) turned into bit-cost
  64584 //	// by calling VP8BitCost().
  64585 var VP8FixedCostsUV = [4]uint16_t{
  64586 	0: uint16(302),
  64587 	1: uint16(984),
  64588 	2: uint16(439),
  64589 	3: uint16(642),
  64590 }
  64591 
  64592 var VP8GetCPUInfo = uintptr(0)
  64593 
  64594 //------------------------------------------------------------------------------
  64595 // init function
  64596 
  64597 var VP8GetResidualCost VP8GetResidualCostFunc
  64598 
  64599 var VP8HFilter16 VP8LumaFilterFunc
  64600 
  64601 var VP8HFilter16i VP8LumaFilterFunc
  64602 
  64603 var VP8HFilter8 VP8ChromaFilterFunc
  64604 
  64605 var VP8HFilter8i VP8ChromaFilterFunc
  64606 
  64607 //------------------------------------------------------------------------------
  64608 // Form the predictions in cache
  64609 
  64610 // C documentation
  64611 //
  64612 //	// Must be ordered using {DC_PRED, TM_PRED, V_PRED, H_PRED} as index
  64613 var VP8I16ModeOffsets = [4]uint16_t{
  64614 	1: libc.Uint16FromInt32(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64615 	2: libc.Uint16FromInt32(libc.Int32FromInt32(1) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  64616 	3: libc.Uint16FromInt32(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64617 }
  64618 
  64619 var VP8ITransform VP8Idct
  64620 
  64621 //------------------------------------------------------------------------------
  64622 
  64623 var VP8LAddGreenToBlueAndRed VP8LProcessDecBlueAndRedFunc
  64624 
  64625 var VP8LAddGreenToBlueAndRed_SSE VP8LProcessDecBlueAndRedFunc
  64626 
  64627 var VP8LAddVector VP8LAddVectorFunc
  64628 
  64629 var VP8LAddVectorEq VP8LAddVectorEqFunc
  64630 
  64631 var VP8LBundleColorMap VP8LBundleColorMapFunc
  64632 
  64633 var VP8LBundleColorMap_SSE VP8LBundleColorMapFunc
  64634 
  64635 var VP8LCollectColorBlueTransforms VP8LCollectColorBlueTransformsFunc
  64636 
  64637 var VP8LCollectColorBlueTransforms_SSE VP8LCollectColorBlueTransformsFunc
  64638 
  64639 var VP8LCollectColorRedTransforms VP8LCollectColorRedTransformsFunc
  64640 
  64641 var VP8LCollectColorRedTransforms_SSE VP8LCollectColorRedTransformsFunc
  64642 
  64643 var VP8LCombinedShannonEntropy VP8LCombinedShannonEntropyFunc
  64644 
  64645 var VP8LConvertBGRAToBGR VP8LConvertFunc
  64646 
  64647 var VP8LConvertBGRAToRGB VP8LConvertFunc
  64648 
  64649 var VP8LConvertBGRAToRGB565 VP8LConvertFunc
  64650 
  64651 var VP8LConvertBGRAToRGBA VP8LConvertFunc
  64652 
  64653 var VP8LConvertBGRAToRGBA4444 VP8LConvertFunc
  64654 
  64655 var VP8LConvertBGRAToRGBA_SSE VP8LConvertFunc
  64656 
  64657 var VP8LConvertBGRAToRGB_SSE VP8LConvertFunc
  64658 
  64659 var VP8LExtraCost VP8LCostFunc
  64660 
  64661 var VP8LFastLog2Slow VP8LFastLog2SlowFunc
  64662 
  64663 var VP8LFastSLog2Slow VP8LFastSLog2SlowFunc
  64664 
  64665 var VP8LGetCombinedEntropyUnrefined VP8LGetCombinedEntropyUnrefinedFunc
  64666 
  64667 var VP8LGetEntropyUnrefined VP8LGetEntropyUnrefinedFunc
  64668 
  64669 var VP8LMapColor32b VP8LMapARGBFunc
  64670 
  64671 var VP8LMapColor8b VP8LMapAlphaFunc
  64672 
  64673 var VP8LPredictors [16]VP8LPredictorFunc
  64674 
  64675 var VP8LPredictorsAdd [16]VP8LPredictorAddSubFunc
  64676 
  64677 // C documentation
  64678 //
  64679 //	// exposed plain-C implementations
  64680 var VP8LPredictorsAdd_C [16]VP8LPredictorAddSubFunc
  64681 
  64682 var VP8LPredictorsAdd_SSE [16]VP8LPredictorAddSubFunc
  64683 
  64684 var VP8LPredictorsSub [16]VP8LPredictorAddSubFunc
  64685 
  64686 var VP8LPredictorsSub_C [16]VP8LPredictorAddSubFunc
  64687 
  64688 var VP8LPredictorsSub_SSE [16]VP8LPredictorAddSubFunc
  64689 
  64690 var VP8LShannonEntropy VP8LShannonEntropyFunc
  64691 
  64692 //------------------------------------------------------------------------------
  64693 
  64694 var VP8LSubtractGreenFromBlueAndRed VP8LProcessEncBlueAndRedFunc
  64695 
  64696 var VP8LSubtractGreenFromBlueAndRed_SSE VP8LProcessEncBlueAndRedFunc
  64697 
  64698 var VP8LTransformColor VP8LTransformColorFunc
  64699 
  64700 var VP8LTransformColorInverse VP8LTransformColorInverseFunc
  64701 
  64702 var VP8LTransformColorInverse_SSE VP8LTransformColorInverseFunc
  64703 
  64704 var VP8LTransformColor_SSE VP8LTransformColorFunc
  64705 
  64706 var VP8LVectorMismatch VP8LVectorMismatchFunc
  64707 
  64708 //------------------------------------------------------------------------------
  64709 // Level cost tables
  64710 
  64711 // C documentation
  64712 //
  64713 //	// fixed costs for coding levels, deduce from the coding tree.
  64714 //	// This is only the part that doesn't depend on the probability state.
  64715 var VP8LevelFixedCosts = [2048]uint16_t{
  64716 	1:    uint16(256),
  64717 	2:    uint16(256),
  64718 	3:    uint16(256),
  64719 	4:    uint16(256),
  64720 	5:    uint16(432),
  64721 	6:    uint16(618),
  64722 	7:    uint16(630),
  64723 	8:    uint16(731),
  64724 	9:    uint16(640),
  64725 	10:   uint16(640),
  64726 	11:   uint16(828),
  64727 	12:   uint16(901),
  64728 	13:   uint16(948),
  64729 	14:   uint16(1021),
  64730 	15:   uint16(1101),
  64731 	16:   uint16(1174),
  64732 	17:   uint16(1221),
  64733 	18:   uint16(1294),
  64734 	19:   uint16(1042),
  64735 	20:   uint16(1085),
  64736 	21:   uint16(1115),
  64737 	22:   uint16(1158),
  64738 	23:   uint16(1202),
  64739 	24:   uint16(1245),
  64740 	25:   uint16(1275),
  64741 	26:   uint16(1318),
  64742 	27:   uint16(1337),
  64743 	28:   uint16(1380),
  64744 	29:   uint16(1410),
  64745 	30:   uint16(1453),
  64746 	31:   uint16(1497),
  64747 	32:   uint16(1540),
  64748 	33:   uint16(1570),
  64749 	34:   uint16(1613),
  64750 	35:   uint16(1280),
  64751 	36:   uint16(1295),
  64752 	37:   uint16(1317),
  64753 	38:   uint16(1332),
  64754 	39:   uint16(1358),
  64755 	40:   uint16(1373),
  64756 	41:   uint16(1395),
  64757 	42:   uint16(1410),
  64758 	43:   uint16(1454),
  64759 	44:   uint16(1469),
  64760 	45:   uint16(1491),
  64761 	46:   uint16(1506),
  64762 	47:   uint16(1532),
  64763 	48:   uint16(1547),
  64764 	49:   uint16(1569),
  64765 	50:   uint16(1584),
  64766 	51:   uint16(1601),
  64767 	52:   uint16(1616),
  64768 	53:   uint16(1638),
  64769 	54:   uint16(1653),
  64770 	55:   uint16(1679),
  64771 	56:   uint16(1694),
  64772 	57:   uint16(1716),
  64773 	58:   uint16(1731),
  64774 	59:   uint16(1775),
  64775 	60:   uint16(1790),
  64776 	61:   uint16(1812),
  64777 	62:   uint16(1827),
  64778 	63:   uint16(1853),
  64779 	64:   uint16(1868),
  64780 	65:   uint16(1890),
  64781 	66:   uint16(1905),
  64782 	67:   uint16(1727),
  64783 	68:   uint16(1733),
  64784 	69:   uint16(1742),
  64785 	70:   uint16(1748),
  64786 	71:   uint16(1759),
  64787 	72:   uint16(1765),
  64788 	73:   uint16(1774),
  64789 	74:   uint16(1780),
  64790 	75:   uint16(1800),
  64791 	76:   uint16(1806),
  64792 	77:   uint16(1815),
  64793 	78:   uint16(1821),
  64794 	79:   uint16(1832),
  64795 	80:   uint16(1838),
  64796 	81:   uint16(1847),
  64797 	82:   uint16(1853),
  64798 	83:   uint16(1878),
  64799 	84:   uint16(1884),
  64800 	85:   uint16(1893),
  64801 	86:   uint16(1899),
  64802 	87:   uint16(1910),
  64803 	88:   uint16(1916),
  64804 	89:   uint16(1925),
  64805 	90:   uint16(1931),
  64806 	91:   uint16(1951),
  64807 	92:   uint16(1957),
  64808 	93:   uint16(1966),
  64809 	94:   uint16(1972),
  64810 	95:   uint16(1983),
  64811 	96:   uint16(1989),
  64812 	97:   uint16(1998),
  64813 	98:   uint16(2004),
  64814 	99:   uint16(2027),
  64815 	100:  uint16(2033),
  64816 	101:  uint16(2042),
  64817 	102:  uint16(2048),
  64818 	103:  uint16(2059),
  64819 	104:  uint16(2065),
  64820 	105:  uint16(2074),
  64821 	106:  uint16(2080),
  64822 	107:  uint16(2100),
  64823 	108:  uint16(2106),
  64824 	109:  uint16(2115),
  64825 	110:  uint16(2121),
  64826 	111:  uint16(2132),
  64827 	112:  uint16(2138),
  64828 	113:  uint16(2147),
  64829 	114:  uint16(2153),
  64830 	115:  uint16(2178),
  64831 	116:  uint16(2184),
  64832 	117:  uint16(2193),
  64833 	118:  uint16(2199),
  64834 	119:  uint16(2210),
  64835 	120:  uint16(2216),
  64836 	121:  uint16(2225),
  64837 	122:  uint16(2231),
  64838 	123:  uint16(2251),
  64839 	124:  uint16(2257),
  64840 	125:  uint16(2266),
  64841 	126:  uint16(2272),
  64842 	127:  uint16(2283),
  64843 	128:  uint16(2289),
  64844 	129:  uint16(2298),
  64845 	130:  uint16(2304),
  64846 	131:  uint16(2168),
  64847 	132:  uint16(2174),
  64848 	133:  uint16(2183),
  64849 	134:  uint16(2189),
  64850 	135:  uint16(2200),
  64851 	136:  uint16(2206),
  64852 	137:  uint16(2215),
  64853 	138:  uint16(2221),
  64854 	139:  uint16(2241),
  64855 	140:  uint16(2247),
  64856 	141:  uint16(2256),
  64857 	142:  uint16(2262),
  64858 	143:  uint16(2273),
  64859 	144:  uint16(2279),
  64860 	145:  uint16(2288),
  64861 	146:  uint16(2294),
  64862 	147:  uint16(2319),
  64863 	148:  uint16(2325),
  64864 	149:  uint16(2334),
  64865 	150:  uint16(2340),
  64866 	151:  uint16(2351),
  64867 	152:  uint16(2357),
  64868 	153:  uint16(2366),
  64869 	154:  uint16(2372),
  64870 	155:  uint16(2392),
  64871 	156:  uint16(2398),
  64872 	157:  uint16(2407),
  64873 	158:  uint16(2413),
  64874 	159:  uint16(2424),
  64875 	160:  uint16(2430),
  64876 	161:  uint16(2439),
  64877 	162:  uint16(2445),
  64878 	163:  uint16(2468),
  64879 	164:  uint16(2474),
  64880 	165:  uint16(2483),
  64881 	166:  uint16(2489),
  64882 	167:  uint16(2500),
  64883 	168:  uint16(2506),
  64884 	169:  uint16(2515),
  64885 	170:  uint16(2521),
  64886 	171:  uint16(2541),
  64887 	172:  uint16(2547),
  64888 	173:  uint16(2556),
  64889 	174:  uint16(2562),
  64890 	175:  uint16(2573),
  64891 	176:  uint16(2579),
  64892 	177:  uint16(2588),
  64893 	178:  uint16(2594),
  64894 	179:  uint16(2619),
  64895 	180:  uint16(2625),
  64896 	181:  uint16(2634),
  64897 	182:  uint16(2640),
  64898 	183:  uint16(2651),
  64899 	184:  uint16(2657),
  64900 	185:  uint16(2666),
  64901 	186:  uint16(2672),
  64902 	187:  uint16(2692),
  64903 	188:  uint16(2698),
  64904 	189:  uint16(2707),
  64905 	190:  uint16(2713),
  64906 	191:  uint16(2724),
  64907 	192:  uint16(2730),
  64908 	193:  uint16(2739),
  64909 	194:  uint16(2745),
  64910 	195:  uint16(2540),
  64911 	196:  uint16(2546),
  64912 	197:  uint16(2555),
  64913 	198:  uint16(2561),
  64914 	199:  uint16(2572),
  64915 	200:  uint16(2578),
  64916 	201:  uint16(2587),
  64917 	202:  uint16(2593),
  64918 	203:  uint16(2613),
  64919 	204:  uint16(2619),
  64920 	205:  uint16(2628),
  64921 	206:  uint16(2634),
  64922 	207:  uint16(2645),
  64923 	208:  uint16(2651),
  64924 	209:  uint16(2660),
  64925 	210:  uint16(2666),
  64926 	211:  uint16(2691),
  64927 	212:  uint16(2697),
  64928 	213:  uint16(2706),
  64929 	214:  uint16(2712),
  64930 	215:  uint16(2723),
  64931 	216:  uint16(2729),
  64932 	217:  uint16(2738),
  64933 	218:  uint16(2744),
  64934 	219:  uint16(2764),
  64935 	220:  uint16(2770),
  64936 	221:  uint16(2779),
  64937 	222:  uint16(2785),
  64938 	223:  uint16(2796),
  64939 	224:  uint16(2802),
  64940 	225:  uint16(2811),
  64941 	226:  uint16(2817),
  64942 	227:  uint16(2840),
  64943 	228:  uint16(2846),
  64944 	229:  uint16(2855),
  64945 	230:  uint16(2861),
  64946 	231:  uint16(2872),
  64947 	232:  uint16(2878),
  64948 	233:  uint16(2887),
  64949 	234:  uint16(2893),
  64950 	235:  uint16(2913),
  64951 	236:  uint16(2919),
  64952 	237:  uint16(2928),
  64953 	238:  uint16(2934),
  64954 	239:  uint16(2945),
  64955 	240:  uint16(2951),
  64956 	241:  uint16(2960),
  64957 	242:  uint16(2966),
  64958 	243:  uint16(2991),
  64959 	244:  uint16(2997),
  64960 	245:  uint16(3006),
  64961 	246:  uint16(3012),
  64962 	247:  uint16(3023),
  64963 	248:  uint16(3029),
  64964 	249:  uint16(3038),
  64965 	250:  uint16(3044),
  64966 	251:  uint16(3064),
  64967 	252:  uint16(3070),
  64968 	253:  uint16(3079),
  64969 	254:  uint16(3085),
  64970 	255:  uint16(3096),
  64971 	256:  uint16(3102),
  64972 	257:  uint16(3111),
  64973 	258:  uint16(3117),
  64974 	259:  uint16(2981),
  64975 	260:  uint16(2987),
  64976 	261:  uint16(2996),
  64977 	262:  uint16(3002),
  64978 	263:  uint16(3013),
  64979 	264:  uint16(3019),
  64980 	265:  uint16(3028),
  64981 	266:  uint16(3034),
  64982 	267:  uint16(3054),
  64983 	268:  uint16(3060),
  64984 	269:  uint16(3069),
  64985 	270:  uint16(3075),
  64986 	271:  uint16(3086),
  64987 	272:  uint16(3092),
  64988 	273:  uint16(3101),
  64989 	274:  uint16(3107),
  64990 	275:  uint16(3132),
  64991 	276:  uint16(3138),
  64992 	277:  uint16(3147),
  64993 	278:  uint16(3153),
  64994 	279:  uint16(3164),
  64995 	280:  uint16(3170),
  64996 	281:  uint16(3179),
  64997 	282:  uint16(3185),
  64998 	283:  uint16(3205),
  64999 	284:  uint16(3211),
  65000 	285:  uint16(3220),
  65001 	286:  uint16(3226),
  65002 	287:  uint16(3237),
  65003 	288:  uint16(3243),
  65004 	289:  uint16(3252),
  65005 	290:  uint16(3258),
  65006 	291:  uint16(3281),
  65007 	292:  uint16(3287),
  65008 	293:  uint16(3296),
  65009 	294:  uint16(3302),
  65010 	295:  uint16(3313),
  65011 	296:  uint16(3319),
  65012 	297:  uint16(3328),
  65013 	298:  uint16(3334),
  65014 	299:  uint16(3354),
  65015 	300:  uint16(3360),
  65016 	301:  uint16(3369),
  65017 	302:  uint16(3375),
  65018 	303:  uint16(3386),
  65019 	304:  uint16(3392),
  65020 	305:  uint16(3401),
  65021 	306:  uint16(3407),
  65022 	307:  uint16(3432),
  65023 	308:  uint16(3438),
  65024 	309:  uint16(3447),
  65025 	310:  uint16(3453),
  65026 	311:  uint16(3464),
  65027 	312:  uint16(3470),
  65028 	313:  uint16(3479),
  65029 	314:  uint16(3485),
  65030 	315:  uint16(3505),
  65031 	316:  uint16(3511),
  65032 	317:  uint16(3520),
  65033 	318:  uint16(3526),
  65034 	319:  uint16(3537),
  65035 	320:  uint16(3543),
  65036 	321:  uint16(3552),
  65037 	322:  uint16(3558),
  65038 	323:  uint16(2816),
  65039 	324:  uint16(2822),
  65040 	325:  uint16(2831),
  65041 	326:  uint16(2837),
  65042 	327:  uint16(2848),
  65043 	328:  uint16(2854),
  65044 	329:  uint16(2863),
  65045 	330:  uint16(2869),
  65046 	331:  uint16(2889),
  65047 	332:  uint16(2895),
  65048 	333:  uint16(2904),
  65049 	334:  uint16(2910),
  65050 	335:  uint16(2921),
  65051 	336:  uint16(2927),
  65052 	337:  uint16(2936),
  65053 	338:  uint16(2942),
  65054 	339:  uint16(2967),
  65055 	340:  uint16(2973),
  65056 	341:  uint16(2982),
  65057 	342:  uint16(2988),
  65058 	343:  uint16(2999),
  65059 	344:  uint16(3005),
  65060 	345:  uint16(3014),
  65061 	346:  uint16(3020),
  65062 	347:  uint16(3040),
  65063 	348:  uint16(3046),
  65064 	349:  uint16(3055),
  65065 	350:  uint16(3061),
  65066 	351:  uint16(3072),
  65067 	352:  uint16(3078),
  65068 	353:  uint16(3087),
  65069 	354:  uint16(3093),
  65070 	355:  uint16(3116),
  65071 	356:  uint16(3122),
  65072 	357:  uint16(3131),
  65073 	358:  uint16(3137),
  65074 	359:  uint16(3148),
  65075 	360:  uint16(3154),
  65076 	361:  uint16(3163),
  65077 	362:  uint16(3169),
  65078 	363:  uint16(3189),
  65079 	364:  uint16(3195),
  65080 	365:  uint16(3204),
  65081 	366:  uint16(3210),
  65082 	367:  uint16(3221),
  65083 	368:  uint16(3227),
  65084 	369:  uint16(3236),
  65085 	370:  uint16(3242),
  65086 	371:  uint16(3267),
  65087 	372:  uint16(3273),
  65088 	373:  uint16(3282),
  65089 	374:  uint16(3288),
  65090 	375:  uint16(3299),
  65091 	376:  uint16(3305),
  65092 	377:  uint16(3314),
  65093 	378:  uint16(3320),
  65094 	379:  uint16(3340),
  65095 	380:  uint16(3346),
  65096 	381:  uint16(3355),
  65097 	382:  uint16(3361),
  65098 	383:  uint16(3372),
  65099 	384:  uint16(3378),
  65100 	385:  uint16(3387),
  65101 	386:  uint16(3393),
  65102 	387:  uint16(3257),
  65103 	388:  uint16(3263),
  65104 	389:  uint16(3272),
  65105 	390:  uint16(3278),
  65106 	391:  uint16(3289),
  65107 	392:  uint16(3295),
  65108 	393:  uint16(3304),
  65109 	394:  uint16(3310),
  65110 	395:  uint16(3330),
  65111 	396:  uint16(3336),
  65112 	397:  uint16(3345),
  65113 	398:  uint16(3351),
  65114 	399:  uint16(3362),
  65115 	400:  uint16(3368),
  65116 	401:  uint16(3377),
  65117 	402:  uint16(3383),
  65118 	403:  uint16(3408),
  65119 	404:  uint16(3414),
  65120 	405:  uint16(3423),
  65121 	406:  uint16(3429),
  65122 	407:  uint16(3440),
  65123 	408:  uint16(3446),
  65124 	409:  uint16(3455),
  65125 	410:  uint16(3461),
  65126 	411:  uint16(3481),
  65127 	412:  uint16(3487),
  65128 	413:  uint16(3496),
  65129 	414:  uint16(3502),
  65130 	415:  uint16(3513),
  65131 	416:  uint16(3519),
  65132 	417:  uint16(3528),
  65133 	418:  uint16(3534),
  65134 	419:  uint16(3557),
  65135 	420:  uint16(3563),
  65136 	421:  uint16(3572),
  65137 	422:  uint16(3578),
  65138 	423:  uint16(3589),
  65139 	424:  uint16(3595),
  65140 	425:  uint16(3604),
  65141 	426:  uint16(3610),
  65142 	427:  uint16(3630),
  65143 	428:  uint16(3636),
  65144 	429:  uint16(3645),
  65145 	430:  uint16(3651),
  65146 	431:  uint16(3662),
  65147 	432:  uint16(3668),
  65148 	433:  uint16(3677),
  65149 	434:  uint16(3683),
  65150 	435:  uint16(3708),
  65151 	436:  uint16(3714),
  65152 	437:  uint16(3723),
  65153 	438:  uint16(3729),
  65154 	439:  uint16(3740),
  65155 	440:  uint16(3746),
  65156 	441:  uint16(3755),
  65157 	442:  uint16(3761),
  65158 	443:  uint16(3781),
  65159 	444:  uint16(3787),
  65160 	445:  uint16(3796),
  65161 	446:  uint16(3802),
  65162 	447:  uint16(3813),
  65163 	448:  uint16(3819),
  65164 	449:  uint16(3828),
  65165 	450:  uint16(3834),
  65166 	451:  uint16(3629),
  65167 	452:  uint16(3635),
  65168 	453:  uint16(3644),
  65169 	454:  uint16(3650),
  65170 	455:  uint16(3661),
  65171 	456:  uint16(3667),
  65172 	457:  uint16(3676),
  65173 	458:  uint16(3682),
  65174 	459:  uint16(3702),
  65175 	460:  uint16(3708),
  65176 	461:  uint16(3717),
  65177 	462:  uint16(3723),
  65178 	463:  uint16(3734),
  65179 	464:  uint16(3740),
  65180 	465:  uint16(3749),
  65181 	466:  uint16(3755),
  65182 	467:  uint16(3780),
  65183 	468:  uint16(3786),
  65184 	469:  uint16(3795),
  65185 	470:  uint16(3801),
  65186 	471:  uint16(3812),
  65187 	472:  uint16(3818),
  65188 	473:  uint16(3827),
  65189 	474:  uint16(3833),
  65190 	475:  uint16(3853),
  65191 	476:  uint16(3859),
  65192 	477:  uint16(3868),
  65193 	478:  uint16(3874),
  65194 	479:  uint16(3885),
  65195 	480:  uint16(3891),
  65196 	481:  uint16(3900),
  65197 	482:  uint16(3906),
  65198 	483:  uint16(3929),
  65199 	484:  uint16(3935),
  65200 	485:  uint16(3944),
  65201 	486:  uint16(3950),
  65202 	487:  uint16(3961),
  65203 	488:  uint16(3967),
  65204 	489:  uint16(3976),
  65205 	490:  uint16(3982),
  65206 	491:  uint16(4002),
  65207 	492:  uint16(4008),
  65208 	493:  uint16(4017),
  65209 	494:  uint16(4023),
  65210 	495:  uint16(4034),
  65211 	496:  uint16(4040),
  65212 	497:  uint16(4049),
  65213 	498:  uint16(4055),
  65214 	499:  uint16(4080),
  65215 	500:  uint16(4086),
  65216 	501:  uint16(4095),
  65217 	502:  uint16(4101),
  65218 	503:  uint16(4112),
  65219 	504:  uint16(4118),
  65220 	505:  uint16(4127),
  65221 	506:  uint16(4133),
  65222 	507:  uint16(4153),
  65223 	508:  uint16(4159),
  65224 	509:  uint16(4168),
  65225 	510:  uint16(4174),
  65226 	511:  uint16(4185),
  65227 	512:  uint16(4191),
  65228 	513:  uint16(4200),
  65229 	514:  uint16(4206),
  65230 	515:  uint16(4070),
  65231 	516:  uint16(4076),
  65232 	517:  uint16(4085),
  65233 	518:  uint16(4091),
  65234 	519:  uint16(4102),
  65235 	520:  uint16(4108),
  65236 	521:  uint16(4117),
  65237 	522:  uint16(4123),
  65238 	523:  uint16(4143),
  65239 	524:  uint16(4149),
  65240 	525:  uint16(4158),
  65241 	526:  uint16(4164),
  65242 	527:  uint16(4175),
  65243 	528:  uint16(4181),
  65244 	529:  uint16(4190),
  65245 	530:  uint16(4196),
  65246 	531:  uint16(4221),
  65247 	532:  uint16(4227),
  65248 	533:  uint16(4236),
  65249 	534:  uint16(4242),
  65250 	535:  uint16(4253),
  65251 	536:  uint16(4259),
  65252 	537:  uint16(4268),
  65253 	538:  uint16(4274),
  65254 	539:  uint16(4294),
  65255 	540:  uint16(4300),
  65256 	541:  uint16(4309),
  65257 	542:  uint16(4315),
  65258 	543:  uint16(4326),
  65259 	544:  uint16(4332),
  65260 	545:  uint16(4341),
  65261 	546:  uint16(4347),
  65262 	547:  uint16(4370),
  65263 	548:  uint16(4376),
  65264 	549:  uint16(4385),
  65265 	550:  uint16(4391),
  65266 	551:  uint16(4402),
  65267 	552:  uint16(4408),
  65268 	553:  uint16(4417),
  65269 	554:  uint16(4423),
  65270 	555:  uint16(4443),
  65271 	556:  uint16(4449),
  65272 	557:  uint16(4458),
  65273 	558:  uint16(4464),
  65274 	559:  uint16(4475),
  65275 	560:  uint16(4481),
  65276 	561:  uint16(4490),
  65277 	562:  uint16(4496),
  65278 	563:  uint16(4521),
  65279 	564:  uint16(4527),
  65280 	565:  uint16(4536),
  65281 	566:  uint16(4542),
  65282 	567:  uint16(4553),
  65283 	568:  uint16(4559),
  65284 	569:  uint16(4568),
  65285 	570:  uint16(4574),
  65286 	571:  uint16(4594),
  65287 	572:  uint16(4600),
  65288 	573:  uint16(4609),
  65289 	574:  uint16(4615),
  65290 	575:  uint16(4626),
  65291 	576:  uint16(4632),
  65292 	577:  uint16(4641),
  65293 	578:  uint16(4647),
  65294 	579:  uint16(3515),
  65295 	580:  uint16(3521),
  65296 	581:  uint16(3530),
  65297 	582:  uint16(3536),
  65298 	583:  uint16(3547),
  65299 	584:  uint16(3553),
  65300 	585:  uint16(3562),
  65301 	586:  uint16(3568),
  65302 	587:  uint16(3588),
  65303 	588:  uint16(3594),
  65304 	589:  uint16(3603),
  65305 	590:  uint16(3609),
  65306 	591:  uint16(3620),
  65307 	592:  uint16(3626),
  65308 	593:  uint16(3635),
  65309 	594:  uint16(3641),
  65310 	595:  uint16(3666),
  65311 	596:  uint16(3672),
  65312 	597:  uint16(3681),
  65313 	598:  uint16(3687),
  65314 	599:  uint16(3698),
  65315 	600:  uint16(3704),
  65316 	601:  uint16(3713),
  65317 	602:  uint16(3719),
  65318 	603:  uint16(3739),
  65319 	604:  uint16(3745),
  65320 	605:  uint16(3754),
  65321 	606:  uint16(3760),
  65322 	607:  uint16(3771),
  65323 	608:  uint16(3777),
  65324 	609:  uint16(3786),
  65325 	610:  uint16(3792),
  65326 	611:  uint16(3815),
  65327 	612:  uint16(3821),
  65328 	613:  uint16(3830),
  65329 	614:  uint16(3836),
  65330 	615:  uint16(3847),
  65331 	616:  uint16(3853),
  65332 	617:  uint16(3862),
  65333 	618:  uint16(3868),
  65334 	619:  uint16(3888),
  65335 	620:  uint16(3894),
  65336 	621:  uint16(3903),
  65337 	622:  uint16(3909),
  65338 	623:  uint16(3920),
  65339 	624:  uint16(3926),
  65340 	625:  uint16(3935),
  65341 	626:  uint16(3941),
  65342 	627:  uint16(3966),
  65343 	628:  uint16(3972),
  65344 	629:  uint16(3981),
  65345 	630:  uint16(3987),
  65346 	631:  uint16(3998),
  65347 	632:  uint16(4004),
  65348 	633:  uint16(4013),
  65349 	634:  uint16(4019),
  65350 	635:  uint16(4039),
  65351 	636:  uint16(4045),
  65352 	637:  uint16(4054),
  65353 	638:  uint16(4060),
  65354 	639:  uint16(4071),
  65355 	640:  uint16(4077),
  65356 	641:  uint16(4086),
  65357 	642:  uint16(4092),
  65358 	643:  uint16(3956),
  65359 	644:  uint16(3962),
  65360 	645:  uint16(3971),
  65361 	646:  uint16(3977),
  65362 	647:  uint16(3988),
  65363 	648:  uint16(3994),
  65364 	649:  uint16(4003),
  65365 	650:  uint16(4009),
  65366 	651:  uint16(4029),
  65367 	652:  uint16(4035),
  65368 	653:  uint16(4044),
  65369 	654:  uint16(4050),
  65370 	655:  uint16(4061),
  65371 	656:  uint16(4067),
  65372 	657:  uint16(4076),
  65373 	658:  uint16(4082),
  65374 	659:  uint16(4107),
  65375 	660:  uint16(4113),
  65376 	661:  uint16(4122),
  65377 	662:  uint16(4128),
  65378 	663:  uint16(4139),
  65379 	664:  uint16(4145),
  65380 	665:  uint16(4154),
  65381 	666:  uint16(4160),
  65382 	667:  uint16(4180),
  65383 	668:  uint16(4186),
  65384 	669:  uint16(4195),
  65385 	670:  uint16(4201),
  65386 	671:  uint16(4212),
  65387 	672:  uint16(4218),
  65388 	673:  uint16(4227),
  65389 	674:  uint16(4233),
  65390 	675:  uint16(4256),
  65391 	676:  uint16(4262),
  65392 	677:  uint16(4271),
  65393 	678:  uint16(4277),
  65394 	679:  uint16(4288),
  65395 	680:  uint16(4294),
  65396 	681:  uint16(4303),
  65397 	682:  uint16(4309),
  65398 	683:  uint16(4329),
  65399 	684:  uint16(4335),
  65400 	685:  uint16(4344),
  65401 	686:  uint16(4350),
  65402 	687:  uint16(4361),
  65403 	688:  uint16(4367),
  65404 	689:  uint16(4376),
  65405 	690:  uint16(4382),
  65406 	691:  uint16(4407),
  65407 	692:  uint16(4413),
  65408 	693:  uint16(4422),
  65409 	694:  uint16(4428),
  65410 	695:  uint16(4439),
  65411 	696:  uint16(4445),
  65412 	697:  uint16(4454),
  65413 	698:  uint16(4460),
  65414 	699:  uint16(4480),
  65415 	700:  uint16(4486),
  65416 	701:  uint16(4495),
  65417 	702:  uint16(4501),
  65418 	703:  uint16(4512),
  65419 	704:  uint16(4518),
  65420 	705:  uint16(4527),
  65421 	706:  uint16(4533),
  65422 	707:  uint16(4328),
  65423 	708:  uint16(4334),
  65424 	709:  uint16(4343),
  65425 	710:  uint16(4349),
  65426 	711:  uint16(4360),
  65427 	712:  uint16(4366),
  65428 	713:  uint16(4375),
  65429 	714:  uint16(4381),
  65430 	715:  uint16(4401),
  65431 	716:  uint16(4407),
  65432 	717:  uint16(4416),
  65433 	718:  uint16(4422),
  65434 	719:  uint16(4433),
  65435 	720:  uint16(4439),
  65436 	721:  uint16(4448),
  65437 	722:  uint16(4454),
  65438 	723:  uint16(4479),
  65439 	724:  uint16(4485),
  65440 	725:  uint16(4494),
  65441 	726:  uint16(4500),
  65442 	727:  uint16(4511),
  65443 	728:  uint16(4517),
  65444 	729:  uint16(4526),
  65445 	730:  uint16(4532),
  65446 	731:  uint16(4552),
  65447 	732:  uint16(4558),
  65448 	733:  uint16(4567),
  65449 	734:  uint16(4573),
  65450 	735:  uint16(4584),
  65451 	736:  uint16(4590),
  65452 	737:  uint16(4599),
  65453 	738:  uint16(4605),
  65454 	739:  uint16(4628),
  65455 	740:  uint16(4634),
  65456 	741:  uint16(4643),
  65457 	742:  uint16(4649),
  65458 	743:  uint16(4660),
  65459 	744:  uint16(4666),
  65460 	745:  uint16(4675),
  65461 	746:  uint16(4681),
  65462 	747:  uint16(4701),
  65463 	748:  uint16(4707),
  65464 	749:  uint16(4716),
  65465 	750:  uint16(4722),
  65466 	751:  uint16(4733),
  65467 	752:  uint16(4739),
  65468 	753:  uint16(4748),
  65469 	754:  uint16(4754),
  65470 	755:  uint16(4779),
  65471 	756:  uint16(4785),
  65472 	757:  uint16(4794),
  65473 	758:  uint16(4800),
  65474 	759:  uint16(4811),
  65475 	760:  uint16(4817),
  65476 	761:  uint16(4826),
  65477 	762:  uint16(4832),
  65478 	763:  uint16(4852),
  65479 	764:  uint16(4858),
  65480 	765:  uint16(4867),
  65481 	766:  uint16(4873),
  65482 	767:  uint16(4884),
  65483 	768:  uint16(4890),
  65484 	769:  uint16(4899),
  65485 	770:  uint16(4905),
  65486 	771:  uint16(4769),
  65487 	772:  uint16(4775),
  65488 	773:  uint16(4784),
  65489 	774:  uint16(4790),
  65490 	775:  uint16(4801),
  65491 	776:  uint16(4807),
  65492 	777:  uint16(4816),
  65493 	778:  uint16(4822),
  65494 	779:  uint16(4842),
  65495 	780:  uint16(4848),
  65496 	781:  uint16(4857),
  65497 	782:  uint16(4863),
  65498 	783:  uint16(4874),
  65499 	784:  uint16(4880),
  65500 	785:  uint16(4889),
  65501 	786:  uint16(4895),
  65502 	787:  uint16(4920),
  65503 	788:  uint16(4926),
  65504 	789:  uint16(4935),
  65505 	790:  uint16(4941),
  65506 	791:  uint16(4952),
  65507 	792:  uint16(4958),
  65508 	793:  uint16(4967),
  65509 	794:  uint16(4973),
  65510 	795:  uint16(4993),
  65511 	796:  uint16(4999),
  65512 	797:  uint16(5008),
  65513 	798:  uint16(5014),
  65514 	799:  uint16(5025),
  65515 	800:  uint16(5031),
  65516 	801:  uint16(5040),
  65517 	802:  uint16(5046),
  65518 	803:  uint16(5069),
  65519 	804:  uint16(5075),
  65520 	805:  uint16(5084),
  65521 	806:  uint16(5090),
  65522 	807:  uint16(5101),
  65523 	808:  uint16(5107),
  65524 	809:  uint16(5116),
  65525 	810:  uint16(5122),
  65526 	811:  uint16(5142),
  65527 	812:  uint16(5148),
  65528 	813:  uint16(5157),
  65529 	814:  uint16(5163),
  65530 	815:  uint16(5174),
  65531 	816:  uint16(5180),
  65532 	817:  uint16(5189),
  65533 	818:  uint16(5195),
  65534 	819:  uint16(5220),
  65535 	820:  uint16(5226),
  65536 	821:  uint16(5235),
  65537 	822:  uint16(5241),
  65538 	823:  uint16(5252),
  65539 	824:  uint16(5258),
  65540 	825:  uint16(5267),
  65541 	826:  uint16(5273),
  65542 	827:  uint16(5293),
  65543 	828:  uint16(5299),
  65544 	829:  uint16(5308),
  65545 	830:  uint16(5314),
  65546 	831:  uint16(5325),
  65547 	832:  uint16(5331),
  65548 	833:  uint16(5340),
  65549 	834:  uint16(5346),
  65550 	835:  uint16(4604),
  65551 	836:  uint16(4610),
  65552 	837:  uint16(4619),
  65553 	838:  uint16(4625),
  65554 	839:  uint16(4636),
  65555 	840:  uint16(4642),
  65556 	841:  uint16(4651),
  65557 	842:  uint16(4657),
  65558 	843:  uint16(4677),
  65559 	844:  uint16(4683),
  65560 	845:  uint16(4692),
  65561 	846:  uint16(4698),
  65562 	847:  uint16(4709),
  65563 	848:  uint16(4715),
  65564 	849:  uint16(4724),
  65565 	850:  uint16(4730),
  65566 	851:  uint16(4755),
  65567 	852:  uint16(4761),
  65568 	853:  uint16(4770),
  65569 	854:  uint16(4776),
  65570 	855:  uint16(4787),
  65571 	856:  uint16(4793),
  65572 	857:  uint16(4802),
  65573 	858:  uint16(4808),
  65574 	859:  uint16(4828),
  65575 	860:  uint16(4834),
  65576 	861:  uint16(4843),
  65577 	862:  uint16(4849),
  65578 	863:  uint16(4860),
  65579 	864:  uint16(4866),
  65580 	865:  uint16(4875),
  65581 	866:  uint16(4881),
  65582 	867:  uint16(4904),
  65583 	868:  uint16(4910),
  65584 	869:  uint16(4919),
  65585 	870:  uint16(4925),
  65586 	871:  uint16(4936),
  65587 	872:  uint16(4942),
  65588 	873:  uint16(4951),
  65589 	874:  uint16(4957),
  65590 	875:  uint16(4977),
  65591 	876:  uint16(4983),
  65592 	877:  uint16(4992),
  65593 	878:  uint16(4998),
  65594 	879:  uint16(5009),
  65595 	880:  uint16(5015),
  65596 	881:  uint16(5024),
  65597 	882:  uint16(5030),
  65598 	883:  uint16(5055),
  65599 	884:  uint16(5061),
  65600 	885:  uint16(5070),
  65601 	886:  uint16(5076),
  65602 	887:  uint16(5087),
  65603 	888:  uint16(5093),
  65604 	889:  uint16(5102),
  65605 	890:  uint16(5108),
  65606 	891:  uint16(5128),
  65607 	892:  uint16(5134),
  65608 	893:  uint16(5143),
  65609 	894:  uint16(5149),
  65610 	895:  uint16(5160),
  65611 	896:  uint16(5166),
  65612 	897:  uint16(5175),
  65613 	898:  uint16(5181),
  65614 	899:  uint16(5045),
  65615 	900:  uint16(5051),
  65616 	901:  uint16(5060),
  65617 	902:  uint16(5066),
  65618 	903:  uint16(5077),
  65619 	904:  uint16(5083),
  65620 	905:  uint16(5092),
  65621 	906:  uint16(5098),
  65622 	907:  uint16(5118),
  65623 	908:  uint16(5124),
  65624 	909:  uint16(5133),
  65625 	910:  uint16(5139),
  65626 	911:  uint16(5150),
  65627 	912:  uint16(5156),
  65628 	913:  uint16(5165),
  65629 	914:  uint16(5171),
  65630 	915:  uint16(5196),
  65631 	916:  uint16(5202),
  65632 	917:  uint16(5211),
  65633 	918:  uint16(5217),
  65634 	919:  uint16(5228),
  65635 	920:  uint16(5234),
  65636 	921:  uint16(5243),
  65637 	922:  uint16(5249),
  65638 	923:  uint16(5269),
  65639 	924:  uint16(5275),
  65640 	925:  uint16(5284),
  65641 	926:  uint16(5290),
  65642 	927:  uint16(5301),
  65643 	928:  uint16(5307),
  65644 	929:  uint16(5316),
  65645 	930:  uint16(5322),
  65646 	931:  uint16(5345),
  65647 	932:  uint16(5351),
  65648 	933:  uint16(5360),
  65649 	934:  uint16(5366),
  65650 	935:  uint16(5377),
  65651 	936:  uint16(5383),
  65652 	937:  uint16(5392),
  65653 	938:  uint16(5398),
  65654 	939:  uint16(5418),
  65655 	940:  uint16(5424),
  65656 	941:  uint16(5433),
  65657 	942:  uint16(5439),
  65658 	943:  uint16(5450),
  65659 	944:  uint16(5456),
  65660 	945:  uint16(5465),
  65661 	946:  uint16(5471),
  65662 	947:  uint16(5496),
  65663 	948:  uint16(5502),
  65664 	949:  uint16(5511),
  65665 	950:  uint16(5517),
  65666 	951:  uint16(5528),
  65667 	952:  uint16(5534),
  65668 	953:  uint16(5543),
  65669 	954:  uint16(5549),
  65670 	955:  uint16(5569),
  65671 	956:  uint16(5575),
  65672 	957:  uint16(5584),
  65673 	958:  uint16(5590),
  65674 	959:  uint16(5601),
  65675 	960:  uint16(5607),
  65676 	961:  uint16(5616),
  65677 	962:  uint16(5622),
  65678 	963:  uint16(5417),
  65679 	964:  uint16(5423),
  65680 	965:  uint16(5432),
  65681 	966:  uint16(5438),
  65682 	967:  uint16(5449),
  65683 	968:  uint16(5455),
  65684 	969:  uint16(5464),
  65685 	970:  uint16(5470),
  65686 	971:  uint16(5490),
  65687 	972:  uint16(5496),
  65688 	973:  uint16(5505),
  65689 	974:  uint16(5511),
  65690 	975:  uint16(5522),
  65691 	976:  uint16(5528),
  65692 	977:  uint16(5537),
  65693 	978:  uint16(5543),
  65694 	979:  uint16(5568),
  65695 	980:  uint16(5574),
  65696 	981:  uint16(5583),
  65697 	982:  uint16(5589),
  65698 	983:  uint16(5600),
  65699 	984:  uint16(5606),
  65700 	985:  uint16(5615),
  65701 	986:  uint16(5621),
  65702 	987:  uint16(5641),
  65703 	988:  uint16(5647),
  65704 	989:  uint16(5656),
  65705 	990:  uint16(5662),
  65706 	991:  uint16(5673),
  65707 	992:  uint16(5679),
  65708 	993:  uint16(5688),
  65709 	994:  uint16(5694),
  65710 	995:  uint16(5717),
  65711 	996:  uint16(5723),
  65712 	997:  uint16(5732),
  65713 	998:  uint16(5738),
  65714 	999:  uint16(5749),
  65715 	1000: uint16(5755),
  65716 	1001: uint16(5764),
  65717 	1002: uint16(5770),
  65718 	1003: uint16(5790),
  65719 	1004: uint16(5796),
  65720 	1005: uint16(5805),
  65721 	1006: uint16(5811),
  65722 	1007: uint16(5822),
  65723 	1008: uint16(5828),
  65724 	1009: uint16(5837),
  65725 	1010: uint16(5843),
  65726 	1011: uint16(5868),
  65727 	1012: uint16(5874),
  65728 	1013: uint16(5883),
  65729 	1014: uint16(5889),
  65730 	1015: uint16(5900),
  65731 	1016: uint16(5906),
  65732 	1017: uint16(5915),
  65733 	1018: uint16(5921),
  65734 	1019: uint16(5941),
  65735 	1020: uint16(5947),
  65736 	1021: uint16(5956),
  65737 	1022: uint16(5962),
  65738 	1023: uint16(5973),
  65739 	1024: uint16(5979),
  65740 	1025: uint16(5988),
  65741 	1026: uint16(5994),
  65742 	1027: uint16(5858),
  65743 	1028: uint16(5864),
  65744 	1029: uint16(5873),
  65745 	1030: uint16(5879),
  65746 	1031: uint16(5890),
  65747 	1032: uint16(5896),
  65748 	1033: uint16(5905),
  65749 	1034: uint16(5911),
  65750 	1035: uint16(5931),
  65751 	1036: uint16(5937),
  65752 	1037: uint16(5946),
  65753 	1038: uint16(5952),
  65754 	1039: uint16(5963),
  65755 	1040: uint16(5969),
  65756 	1041: uint16(5978),
  65757 	1042: uint16(5984),
  65758 	1043: uint16(6009),
  65759 	1044: uint16(6015),
  65760 	1045: uint16(6024),
  65761 	1046: uint16(6030),
  65762 	1047: uint16(6041),
  65763 	1048: uint16(6047),
  65764 	1049: uint16(6056),
  65765 	1050: uint16(6062),
  65766 	1051: uint16(6082),
  65767 	1052: uint16(6088),
  65768 	1053: uint16(6097),
  65769 	1054: uint16(6103),
  65770 	1055: uint16(6114),
  65771 	1056: uint16(6120),
  65772 	1057: uint16(6129),
  65773 	1058: uint16(6135),
  65774 	1059: uint16(6158),
  65775 	1060: uint16(6164),
  65776 	1061: uint16(6173),
  65777 	1062: uint16(6179),
  65778 	1063: uint16(6190),
  65779 	1064: uint16(6196),
  65780 	1065: uint16(6205),
  65781 	1066: uint16(6211),
  65782 	1067: uint16(6231),
  65783 	1068: uint16(6237),
  65784 	1069: uint16(6246),
  65785 	1070: uint16(6252),
  65786 	1071: uint16(6263),
  65787 	1072: uint16(6269),
  65788 	1073: uint16(6278),
  65789 	1074: uint16(6284),
  65790 	1075: uint16(6309),
  65791 	1076: uint16(6315),
  65792 	1077: uint16(6324),
  65793 	1078: uint16(6330),
  65794 	1079: uint16(6341),
  65795 	1080: uint16(6347),
  65796 	1081: uint16(6356),
  65797 	1082: uint16(6362),
  65798 	1083: uint16(6382),
  65799 	1084: uint16(6388),
  65800 	1085: uint16(6397),
  65801 	1086: uint16(6403),
  65802 	1087: uint16(6414),
  65803 	1088: uint16(6420),
  65804 	1089: uint16(6429),
  65805 	1090: uint16(6435),
  65806 	1091: uint16(3515),
  65807 	1092: uint16(3521),
  65808 	1093: uint16(3530),
  65809 	1094: uint16(3536),
  65810 	1095: uint16(3547),
  65811 	1096: uint16(3553),
  65812 	1097: uint16(3562),
  65813 	1098: uint16(3568),
  65814 	1099: uint16(3588),
  65815 	1100: uint16(3594),
  65816 	1101: uint16(3603),
  65817 	1102: uint16(3609),
  65818 	1103: uint16(3620),
  65819 	1104: uint16(3626),
  65820 	1105: uint16(3635),
  65821 	1106: uint16(3641),
  65822 	1107: uint16(3666),
  65823 	1108: uint16(3672),
  65824 	1109: uint16(3681),
  65825 	1110: uint16(3687),
  65826 	1111: uint16(3698),
  65827 	1112: uint16(3704),
  65828 	1113: uint16(3713),
  65829 	1114: uint16(3719),
  65830 	1115: uint16(3739),
  65831 	1116: uint16(3745),
  65832 	1117: uint16(3754),
  65833 	1118: uint16(3760),
  65834 	1119: uint16(3771),
  65835 	1120: uint16(3777),
  65836 	1121: uint16(3786),
  65837 	1122: uint16(3792),
  65838 	1123: uint16(3815),
  65839 	1124: uint16(3821),
  65840 	1125: uint16(3830),
  65841 	1126: uint16(3836),
  65842 	1127: uint16(3847),
  65843 	1128: uint16(3853),
  65844 	1129: uint16(3862),
  65845 	1130: uint16(3868),
  65846 	1131: uint16(3888),
  65847 	1132: uint16(3894),
  65848 	1133: uint16(3903),
  65849 	1134: uint16(3909),
  65850 	1135: uint16(3920),
  65851 	1136: uint16(3926),
  65852 	1137: uint16(3935),
  65853 	1138: uint16(3941),
  65854 	1139: uint16(3966),
  65855 	1140: uint16(3972),
  65856 	1141: uint16(3981),
  65857 	1142: uint16(3987),
  65858 	1143: uint16(3998),
  65859 	1144: uint16(4004),
  65860 	1145: uint16(4013),
  65861 	1146: uint16(4019),
  65862 	1147: uint16(4039),
  65863 	1148: uint16(4045),
  65864 	1149: uint16(4054),
  65865 	1150: uint16(4060),
  65866 	1151: uint16(4071),
  65867 	1152: uint16(4077),
  65868 	1153: uint16(4086),
  65869 	1154: uint16(4092),
  65870 	1155: uint16(3956),
  65871 	1156: uint16(3962),
  65872 	1157: uint16(3971),
  65873 	1158: uint16(3977),
  65874 	1159: uint16(3988),
  65875 	1160: uint16(3994),
  65876 	1161: uint16(4003),
  65877 	1162: uint16(4009),
  65878 	1163: uint16(4029),
  65879 	1164: uint16(4035),
  65880 	1165: uint16(4044),
  65881 	1166: uint16(4050),
  65882 	1167: uint16(4061),
  65883 	1168: uint16(4067),
  65884 	1169: uint16(4076),
  65885 	1170: uint16(4082),
  65886 	1171: uint16(4107),
  65887 	1172: uint16(4113),
  65888 	1173: uint16(4122),
  65889 	1174: uint16(4128),
  65890 	1175: uint16(4139),
  65891 	1176: uint16(4145),
  65892 	1177: uint16(4154),
  65893 	1178: uint16(4160),
  65894 	1179: uint16(4180),
  65895 	1180: uint16(4186),
  65896 	1181: uint16(4195),
  65897 	1182: uint16(4201),
  65898 	1183: uint16(4212),
  65899 	1184: uint16(4218),
  65900 	1185: uint16(4227),
  65901 	1186: uint16(4233),
  65902 	1187: uint16(4256),
  65903 	1188: uint16(4262),
  65904 	1189: uint16(4271),
  65905 	1190: uint16(4277),
  65906 	1191: uint16(4288),
  65907 	1192: uint16(4294),
  65908 	1193: uint16(4303),
  65909 	1194: uint16(4309),
  65910 	1195: uint16(4329),
  65911 	1196: uint16(4335),
  65912 	1197: uint16(4344),
  65913 	1198: uint16(4350),
  65914 	1199: uint16(4361),
  65915 	1200: uint16(4367),
  65916 	1201: uint16(4376),
  65917 	1202: uint16(4382),
  65918 	1203: uint16(4407),
  65919 	1204: uint16(4413),
  65920 	1205: uint16(4422),
  65921 	1206: uint16(4428),
  65922 	1207: uint16(4439),
  65923 	1208: uint16(4445),
  65924 	1209: uint16(4454),
  65925 	1210: uint16(4460),
  65926 	1211: uint16(4480),
  65927 	1212: uint16(4486),
  65928 	1213: uint16(4495),
  65929 	1214: uint16(4501),
  65930 	1215: uint16(4512),
  65931 	1216: uint16(4518),
  65932 	1217: uint16(4527),
  65933 	1218: uint16(4533),
  65934 	1219: uint16(4328),
  65935 	1220: uint16(4334),
  65936 	1221: uint16(4343),
  65937 	1222: uint16(4349),
  65938 	1223: uint16(4360),
  65939 	1224: uint16(4366),
  65940 	1225: uint16(4375),
  65941 	1226: uint16(4381),
  65942 	1227: uint16(4401),
  65943 	1228: uint16(4407),
  65944 	1229: uint16(4416),
  65945 	1230: uint16(4422),
  65946 	1231: uint16(4433),
  65947 	1232: uint16(4439),
  65948 	1233: uint16(4448),
  65949 	1234: uint16(4454),
  65950 	1235: uint16(4479),
  65951 	1236: uint16(4485),
  65952 	1237: uint16(4494),
  65953 	1238: uint16(4500),
  65954 	1239: uint16(4511),
  65955 	1240: uint16(4517),
  65956 	1241: uint16(4526),
  65957 	1242: uint16(4532),
  65958 	1243: uint16(4552),
  65959 	1244: uint16(4558),
  65960 	1245: uint16(4567),
  65961 	1246: uint16(4573),
  65962 	1247: uint16(4584),
  65963 	1248: uint16(4590),
  65964 	1249: uint16(4599),
  65965 	1250: uint16(4605),
  65966 	1251: uint16(4628),
  65967 	1252: uint16(4634),
  65968 	1253: uint16(4643),
  65969 	1254: uint16(4649),
  65970 	1255: uint16(4660),
  65971 	1256: uint16(4666),
  65972 	1257: uint16(4675),
  65973 	1258: uint16(4681),
  65974 	1259: uint16(4701),
  65975 	1260: uint16(4707),
  65976 	1261: uint16(4716),
  65977 	1262: uint16(4722),
  65978 	1263: uint16(4733),
  65979 	1264: uint16(4739),
  65980 	1265: uint16(4748),
  65981 	1266: uint16(4754),
  65982 	1267: uint16(4779),
  65983 	1268: uint16(4785),
  65984 	1269: uint16(4794),
  65985 	1270: uint16(4800),
  65986 	1271: uint16(4811),
  65987 	1272: uint16(4817),
  65988 	1273: uint16(4826),
  65989 	1274: uint16(4832),
  65990 	1275: uint16(4852),
  65991 	1276: uint16(4858),
  65992 	1277: uint16(4867),
  65993 	1278: uint16(4873),
  65994 	1279: uint16(4884),
  65995 	1280: uint16(4890),
  65996 	1281: uint16(4899),
  65997 	1282: uint16(4905),
  65998 	1283: uint16(4769),
  65999 	1284: uint16(4775),
  66000 	1285: uint16(4784),
  66001 	1286: uint16(4790),
  66002 	1287: uint16(4801),
  66003 	1288: uint16(4807),
  66004 	1289: uint16(4816),
  66005 	1290: uint16(4822),
  66006 	1291: uint16(4842),
  66007 	1292: uint16(4848),
  66008 	1293: uint16(4857),
  66009 	1294: uint16(4863),
  66010 	1295: uint16(4874),
  66011 	1296: uint16(4880),
  66012 	1297: uint16(4889),
  66013 	1298: uint16(4895),
  66014 	1299: uint16(4920),
  66015 	1300: uint16(4926),
  66016 	1301: uint16(4935),
  66017 	1302: uint16(4941),
  66018 	1303: uint16(4952),
  66019 	1304: uint16(4958),
  66020 	1305: uint16(4967),
  66021 	1306: uint16(4973),
  66022 	1307: uint16(4993),
  66023 	1308: uint16(4999),
  66024 	1309: uint16(5008),
  66025 	1310: uint16(5014),
  66026 	1311: uint16(5025),
  66027 	1312: uint16(5031),
  66028 	1313: uint16(5040),
  66029 	1314: uint16(5046),
  66030 	1315: uint16(5069),
  66031 	1316: uint16(5075),
  66032 	1317: uint16(5084),
  66033 	1318: uint16(5090),
  66034 	1319: uint16(5101),
  66035 	1320: uint16(5107),
  66036 	1321: uint16(5116),
  66037 	1322: uint16(5122),
  66038 	1323: uint16(5142),
  66039 	1324: uint16(5148),
  66040 	1325: uint16(5157),
  66041 	1326: uint16(5163),
  66042 	1327: uint16(5174),
  66043 	1328: uint16(5180),
  66044 	1329: uint16(5189),
  66045 	1330: uint16(5195),
  66046 	1331: uint16(5220),
  66047 	1332: uint16(5226),
  66048 	1333: uint16(5235),
  66049 	1334: uint16(5241),
  66050 	1335: uint16(5252),
  66051 	1336: uint16(5258),
  66052 	1337: uint16(5267),
  66053 	1338: uint16(5273),
  66054 	1339: uint16(5293),
  66055 	1340: uint16(5299),
  66056 	1341: uint16(5308),
  66057 	1342: uint16(5314),
  66058 	1343: uint16(5325),
  66059 	1344: uint16(5331),
  66060 	1345: uint16(5340),
  66061 	1346: uint16(5346),
  66062 	1347: uint16(4604),
  66063 	1348: uint16(4610),
  66064 	1349: uint16(4619),
  66065 	1350: uint16(4625),
  66066 	1351: uint16(4636),
  66067 	1352: uint16(4642),
  66068 	1353: uint16(4651),
  66069 	1354: uint16(4657),
  66070 	1355: uint16(4677),
  66071 	1356: uint16(4683),
  66072 	1357: uint16(4692),
  66073 	1358: uint16(4698),
  66074 	1359: uint16(4709),
  66075 	1360: uint16(4715),
  66076 	1361: uint16(4724),
  66077 	1362: uint16(4730),
  66078 	1363: uint16(4755),
  66079 	1364: uint16(4761),
  66080 	1365: uint16(4770),
  66081 	1366: uint16(4776),
  66082 	1367: uint16(4787),
  66083 	1368: uint16(4793),
  66084 	1369: uint16(4802),
  66085 	1370: uint16(4808),
  66086 	1371: uint16(4828),
  66087 	1372: uint16(4834),
  66088 	1373: uint16(4843),
  66089 	1374: uint16(4849),
  66090 	1375: uint16(4860),
  66091 	1376: uint16(4866),
  66092 	1377: uint16(4875),
  66093 	1378: uint16(4881),
  66094 	1379: uint16(4904),
  66095 	1380: uint16(4910),
  66096 	1381: uint16(4919),
  66097 	1382: uint16(4925),
  66098 	1383: uint16(4936),
  66099 	1384: uint16(4942),
  66100 	1385: uint16(4951),
  66101 	1386: uint16(4957),
  66102 	1387: uint16(4977),
  66103 	1388: uint16(4983),
  66104 	1389: uint16(4992),
  66105 	1390: uint16(4998),
  66106 	1391: uint16(5009),
  66107 	1392: uint16(5015),
  66108 	1393: uint16(5024),
  66109 	1394: uint16(5030),
  66110 	1395: uint16(5055),
  66111 	1396: uint16(5061),
  66112 	1397: uint16(5070),
  66113 	1398: uint16(5076),
  66114 	1399: uint16(5087),
  66115 	1400: uint16(5093),
  66116 	1401: uint16(5102),
  66117 	1402: uint16(5108),
  66118 	1403: uint16(5128),
  66119 	1404: uint16(5134),
  66120 	1405: uint16(5143),
  66121 	1406: uint16(5149),
  66122 	1407: uint16(5160),
  66123 	1408: uint16(5166),
  66124 	1409: uint16(5175),
  66125 	1410: uint16(5181),
  66126 	1411: uint16(5045),
  66127 	1412: uint16(5051),
  66128 	1413: uint16(5060),
  66129 	1414: uint16(5066),
  66130 	1415: uint16(5077),
  66131 	1416: uint16(5083),
  66132 	1417: uint16(5092),
  66133 	1418: uint16(5098),
  66134 	1419: uint16(5118),
  66135 	1420: uint16(5124),
  66136 	1421: uint16(5133),
  66137 	1422: uint16(5139),
  66138 	1423: uint16(5150),
  66139 	1424: uint16(5156),
  66140 	1425: uint16(5165),
  66141 	1426: uint16(5171),
  66142 	1427: uint16(5196),
  66143 	1428: uint16(5202),
  66144 	1429: uint16(5211),
  66145 	1430: uint16(5217),
  66146 	1431: uint16(5228),
  66147 	1432: uint16(5234),
  66148 	1433: uint16(5243),
  66149 	1434: uint16(5249),
  66150 	1435: uint16(5269),
  66151 	1436: uint16(5275),
  66152 	1437: uint16(5284),
  66153 	1438: uint16(5290),
  66154 	1439: uint16(5301),
  66155 	1440: uint16(5307),
  66156 	1441: uint16(5316),
  66157 	1442: uint16(5322),
  66158 	1443: uint16(5345),
  66159 	1444: uint16(5351),
  66160 	1445: uint16(5360),
  66161 	1446: uint16(5366),
  66162 	1447: uint16(5377),
  66163 	1448: uint16(5383),
  66164 	1449: uint16(5392),
  66165 	1450: uint16(5398),
  66166 	1451: uint16(5418),
  66167 	1452: uint16(5424),
  66168 	1453: uint16(5433),
  66169 	1454: uint16(5439),
  66170 	1455: uint16(5450),
  66171 	1456: uint16(5456),
  66172 	1457: uint16(5465),
  66173 	1458: uint16(5471),
  66174 	1459: uint16(5496),
  66175 	1460: uint16(5502),
  66176 	1461: uint16(5511),
  66177 	1462: uint16(5517),
  66178 	1463: uint16(5528),
  66179 	1464: uint16(5534),
  66180 	1465: uint16(5543),
  66181 	1466: uint16(5549),
  66182 	1467: uint16(5569),
  66183 	1468: uint16(5575),
  66184 	1469: uint16(5584),
  66185 	1470: uint16(5590),
  66186 	1471: uint16(5601),
  66187 	1472: uint16(5607),
  66188 	1473: uint16(5616),
  66189 	1474: uint16(5622),
  66190 	1475: uint16(5417),
  66191 	1476: uint16(5423),
  66192 	1477: uint16(5432),
  66193 	1478: uint16(5438),
  66194 	1479: uint16(5449),
  66195 	1480: uint16(5455),
  66196 	1481: uint16(5464),
  66197 	1482: uint16(5470),
  66198 	1483: uint16(5490),
  66199 	1484: uint16(5496),
  66200 	1485: uint16(5505),
  66201 	1486: uint16(5511),
  66202 	1487: uint16(5522),
  66203 	1488: uint16(5528),
  66204 	1489: uint16(5537),
  66205 	1490: uint16(5543),
  66206 	1491: uint16(5568),
  66207 	1492: uint16(5574),
  66208 	1493: uint16(5583),
  66209 	1494: uint16(5589),
  66210 	1495: uint16(5600),
  66211 	1496: uint16(5606),
  66212 	1497: uint16(5615),
  66213 	1498: uint16(5621),
  66214 	1499: uint16(5641),
  66215 	1500: uint16(5647),
  66216 	1501: uint16(5656),
  66217 	1502: uint16(5662),
  66218 	1503: uint16(5673),
  66219 	1504: uint16(5679),
  66220 	1505: uint16(5688),
  66221 	1506: uint16(5694),
  66222 	1507: uint16(5717),
  66223 	1508: uint16(5723),
  66224 	1509: uint16(5732),
  66225 	1510: uint16(5738),
  66226 	1511: uint16(5749),
  66227 	1512: uint16(5755),
  66228 	1513: uint16(5764),
  66229 	1514: uint16(5770),
  66230 	1515: uint16(5790),
  66231 	1516: uint16(5796),
  66232 	1517: uint16(5805),
  66233 	1518: uint16(5811),
  66234 	1519: uint16(5822),
  66235 	1520: uint16(5828),
  66236 	1521: uint16(5837),
  66237 	1522: uint16(5843),
  66238 	1523: uint16(5868),
  66239 	1524: uint16(5874),
  66240 	1525: uint16(5883),
  66241 	1526: uint16(5889),
  66242 	1527: uint16(5900),
  66243 	1528: uint16(5906),
  66244 	1529: uint16(5915),
  66245 	1530: uint16(5921),
  66246 	1531: uint16(5941),
  66247 	1532: uint16(5947),
  66248 	1533: uint16(5956),
  66249 	1534: uint16(5962),
  66250 	1535: uint16(5973),
  66251 	1536: uint16(5979),
  66252 	1537: uint16(5988),
  66253 	1538: uint16(5994),
  66254 	1539: uint16(5858),
  66255 	1540: uint16(5864),
  66256 	1541: uint16(5873),
  66257 	1542: uint16(5879),
  66258 	1543: uint16(5890),
  66259 	1544: uint16(5896),
  66260 	1545: uint16(5905),
  66261 	1546: uint16(5911),
  66262 	1547: uint16(5931),
  66263 	1548: uint16(5937),
  66264 	1549: uint16(5946),
  66265 	1550: uint16(5952),
  66266 	1551: uint16(5963),
  66267 	1552: uint16(5969),
  66268 	1553: uint16(5978),
  66269 	1554: uint16(5984),
  66270 	1555: uint16(6009),
  66271 	1556: uint16(6015),
  66272 	1557: uint16(6024),
  66273 	1558: uint16(6030),
  66274 	1559: uint16(6041),
  66275 	1560: uint16(6047),
  66276 	1561: uint16(6056),
  66277 	1562: uint16(6062),
  66278 	1563: uint16(6082),
  66279 	1564: uint16(6088),
  66280 	1565: uint16(6097),
  66281 	1566: uint16(6103),
  66282 	1567: uint16(6114),
  66283 	1568: uint16(6120),
  66284 	1569: uint16(6129),
  66285 	1570: uint16(6135),
  66286 	1571: uint16(6158),
  66287 	1572: uint16(6164),
  66288 	1573: uint16(6173),
  66289 	1574: uint16(6179),
  66290 	1575: uint16(6190),
  66291 	1576: uint16(6196),
  66292 	1577: uint16(6205),
  66293 	1578: uint16(6211),
  66294 	1579: uint16(6231),
  66295 	1580: uint16(6237),
  66296 	1581: uint16(6246),
  66297 	1582: uint16(6252),
  66298 	1583: uint16(6263),
  66299 	1584: uint16(6269),
  66300 	1585: uint16(6278),
  66301 	1586: uint16(6284),
  66302 	1587: uint16(6309),
  66303 	1588: uint16(6315),
  66304 	1589: uint16(6324),
  66305 	1590: uint16(6330),
  66306 	1591: uint16(6341),
  66307 	1592: uint16(6347),
  66308 	1593: uint16(6356),
  66309 	1594: uint16(6362),
  66310 	1595: uint16(6382),
  66311 	1596: uint16(6388),
  66312 	1597: uint16(6397),
  66313 	1598: uint16(6403),
  66314 	1599: uint16(6414),
  66315 	1600: uint16(6420),
  66316 	1601: uint16(6429),
  66317 	1602: uint16(6435),
  66318 	1603: uint16(5303),
  66319 	1604: uint16(5309),
  66320 	1605: uint16(5318),
  66321 	1606: uint16(5324),
  66322 	1607: uint16(5335),
  66323 	1608: uint16(5341),
  66324 	1609: uint16(5350),
  66325 	1610: uint16(5356),
  66326 	1611: uint16(5376),
  66327 	1612: uint16(5382),
  66328 	1613: uint16(5391),
  66329 	1614: uint16(5397),
  66330 	1615: uint16(5408),
  66331 	1616: uint16(5414),
  66332 	1617: uint16(5423),
  66333 	1618: uint16(5429),
  66334 	1619: uint16(5454),
  66335 	1620: uint16(5460),
  66336 	1621: uint16(5469),
  66337 	1622: uint16(5475),
  66338 	1623: uint16(5486),
  66339 	1624: uint16(5492),
  66340 	1625: uint16(5501),
  66341 	1626: uint16(5507),
  66342 	1627: uint16(5527),
  66343 	1628: uint16(5533),
  66344 	1629: uint16(5542),
  66345 	1630: uint16(5548),
  66346 	1631: uint16(5559),
  66347 	1632: uint16(5565),
  66348 	1633: uint16(5574),
  66349 	1634: uint16(5580),
  66350 	1635: uint16(5603),
  66351 	1636: uint16(5609),
  66352 	1637: uint16(5618),
  66353 	1638: uint16(5624),
  66354 	1639: uint16(5635),
  66355 	1640: uint16(5641),
  66356 	1641: uint16(5650),
  66357 	1642: uint16(5656),
  66358 	1643: uint16(5676),
  66359 	1644: uint16(5682),
  66360 	1645: uint16(5691),
  66361 	1646: uint16(5697),
  66362 	1647: uint16(5708),
  66363 	1648: uint16(5714),
  66364 	1649: uint16(5723),
  66365 	1650: uint16(5729),
  66366 	1651: uint16(5754),
  66367 	1652: uint16(5760),
  66368 	1653: uint16(5769),
  66369 	1654: uint16(5775),
  66370 	1655: uint16(5786),
  66371 	1656: uint16(5792),
  66372 	1657: uint16(5801),
  66373 	1658: uint16(5807),
  66374 	1659: uint16(5827),
  66375 	1660: uint16(5833),
  66376 	1661: uint16(5842),
  66377 	1662: uint16(5848),
  66378 	1663: uint16(5859),
  66379 	1664: uint16(5865),
  66380 	1665: uint16(5874),
  66381 	1666: uint16(5880),
  66382 	1667: uint16(5744),
  66383 	1668: uint16(5750),
  66384 	1669: uint16(5759),
  66385 	1670: uint16(5765),
  66386 	1671: uint16(5776),
  66387 	1672: uint16(5782),
  66388 	1673: uint16(5791),
  66389 	1674: uint16(5797),
  66390 	1675: uint16(5817),
  66391 	1676: uint16(5823),
  66392 	1677: uint16(5832),
  66393 	1678: uint16(5838),
  66394 	1679: uint16(5849),
  66395 	1680: uint16(5855),
  66396 	1681: uint16(5864),
  66397 	1682: uint16(5870),
  66398 	1683: uint16(5895),
  66399 	1684: uint16(5901),
  66400 	1685: uint16(5910),
  66401 	1686: uint16(5916),
  66402 	1687: uint16(5927),
  66403 	1688: uint16(5933),
  66404 	1689: uint16(5942),
  66405 	1690: uint16(5948),
  66406 	1691: uint16(5968),
  66407 	1692: uint16(5974),
  66408 	1693: uint16(5983),
  66409 	1694: uint16(5989),
  66410 	1695: uint16(6000),
  66411 	1696: uint16(6006),
  66412 	1697: uint16(6015),
  66413 	1698: uint16(6021),
  66414 	1699: uint16(6044),
  66415 	1700: uint16(6050),
  66416 	1701: uint16(6059),
  66417 	1702: uint16(6065),
  66418 	1703: uint16(6076),
  66419 	1704: uint16(6082),
  66420 	1705: uint16(6091),
  66421 	1706: uint16(6097),
  66422 	1707: uint16(6117),
  66423 	1708: uint16(6123),
  66424 	1709: uint16(6132),
  66425 	1710: uint16(6138),
  66426 	1711: uint16(6149),
  66427 	1712: uint16(6155),
  66428 	1713: uint16(6164),
  66429 	1714: uint16(6170),
  66430 	1715: uint16(6195),
  66431 	1716: uint16(6201),
  66432 	1717: uint16(6210),
  66433 	1718: uint16(6216),
  66434 	1719: uint16(6227),
  66435 	1720: uint16(6233),
  66436 	1721: uint16(6242),
  66437 	1722: uint16(6248),
  66438 	1723: uint16(6268),
  66439 	1724: uint16(6274),
  66440 	1725: uint16(6283),
  66441 	1726: uint16(6289),
  66442 	1727: uint16(6300),
  66443 	1728: uint16(6306),
  66444 	1729: uint16(6315),
  66445 	1730: uint16(6321),
  66446 	1731: uint16(6116),
  66447 	1732: uint16(6122),
  66448 	1733: uint16(6131),
  66449 	1734: uint16(6137),
  66450 	1735: uint16(6148),
  66451 	1736: uint16(6154),
  66452 	1737: uint16(6163),
  66453 	1738: uint16(6169),
  66454 	1739: uint16(6189),
  66455 	1740: uint16(6195),
  66456 	1741: uint16(6204),
  66457 	1742: uint16(6210),
  66458 	1743: uint16(6221),
  66459 	1744: uint16(6227),
  66460 	1745: uint16(6236),
  66461 	1746: uint16(6242),
  66462 	1747: uint16(6267),
  66463 	1748: uint16(6273),
  66464 	1749: uint16(6282),
  66465 	1750: uint16(6288),
  66466 	1751: uint16(6299),
  66467 	1752: uint16(6305),
  66468 	1753: uint16(6314),
  66469 	1754: uint16(6320),
  66470 	1755: uint16(6340),
  66471 	1756: uint16(6346),
  66472 	1757: uint16(6355),
  66473 	1758: uint16(6361),
  66474 	1759: uint16(6372),
  66475 	1760: uint16(6378),
  66476 	1761: uint16(6387),
  66477 	1762: uint16(6393),
  66478 	1763: uint16(6416),
  66479 	1764: uint16(6422),
  66480 	1765: uint16(6431),
  66481 	1766: uint16(6437),
  66482 	1767: uint16(6448),
  66483 	1768: uint16(6454),
  66484 	1769: uint16(6463),
  66485 	1770: uint16(6469),
  66486 	1771: uint16(6489),
  66487 	1772: uint16(6495),
  66488 	1773: uint16(6504),
  66489 	1774: uint16(6510),
  66490 	1775: uint16(6521),
  66491 	1776: uint16(6527),
  66492 	1777: uint16(6536),
  66493 	1778: uint16(6542),
  66494 	1779: uint16(6567),
  66495 	1780: uint16(6573),
  66496 	1781: uint16(6582),
  66497 	1782: uint16(6588),
  66498 	1783: uint16(6599),
  66499 	1784: uint16(6605),
  66500 	1785: uint16(6614),
  66501 	1786: uint16(6620),
  66502 	1787: uint16(6640),
  66503 	1788: uint16(6646),
  66504 	1789: uint16(6655),
  66505 	1790: uint16(6661),
  66506 	1791: uint16(6672),
  66507 	1792: uint16(6678),
  66508 	1793: uint16(6687),
  66509 	1794: uint16(6693),
  66510 	1795: uint16(6557),
  66511 	1796: uint16(6563),
  66512 	1797: uint16(6572),
  66513 	1798: uint16(6578),
  66514 	1799: uint16(6589),
  66515 	1800: uint16(6595),
  66516 	1801: uint16(6604),
  66517 	1802: uint16(6610),
  66518 	1803: uint16(6630),
  66519 	1804: uint16(6636),
  66520 	1805: uint16(6645),
  66521 	1806: uint16(6651),
  66522 	1807: uint16(6662),
  66523 	1808: uint16(6668),
  66524 	1809: uint16(6677),
  66525 	1810: uint16(6683),
  66526 	1811: uint16(6708),
  66527 	1812: uint16(6714),
  66528 	1813: uint16(6723),
  66529 	1814: uint16(6729),
  66530 	1815: uint16(6740),
  66531 	1816: uint16(6746),
  66532 	1817: uint16(6755),
  66533 	1818: uint16(6761),
  66534 	1819: uint16(6781),
  66535 	1820: uint16(6787),
  66536 	1821: uint16(6796),
  66537 	1822: uint16(6802),
  66538 	1823: uint16(6813),
  66539 	1824: uint16(6819),
  66540 	1825: uint16(6828),
  66541 	1826: uint16(6834),
  66542 	1827: uint16(6857),
  66543 	1828: uint16(6863),
  66544 	1829: uint16(6872),
  66545 	1830: uint16(6878),
  66546 	1831: uint16(6889),
  66547 	1832: uint16(6895),
  66548 	1833: uint16(6904),
  66549 	1834: uint16(6910),
  66550 	1835: uint16(6930),
  66551 	1836: uint16(6936),
  66552 	1837: uint16(6945),
  66553 	1838: uint16(6951),
  66554 	1839: uint16(6962),
  66555 	1840: uint16(6968),
  66556 	1841: uint16(6977),
  66557 	1842: uint16(6983),
  66558 	1843: uint16(7008),
  66559 	1844: uint16(7014),
  66560 	1845: uint16(7023),
  66561 	1846: uint16(7029),
  66562 	1847: uint16(7040),
  66563 	1848: uint16(7046),
  66564 	1849: uint16(7055),
  66565 	1850: uint16(7061),
  66566 	1851: uint16(7081),
  66567 	1852: uint16(7087),
  66568 	1853: uint16(7096),
  66569 	1854: uint16(7102),
  66570 	1855: uint16(7113),
  66571 	1856: uint16(7119),
  66572 	1857: uint16(7128),
  66573 	1858: uint16(7134),
  66574 	1859: uint16(6392),
  66575 	1860: uint16(6398),
  66576 	1861: uint16(6407),
  66577 	1862: uint16(6413),
  66578 	1863: uint16(6424),
  66579 	1864: uint16(6430),
  66580 	1865: uint16(6439),
  66581 	1866: uint16(6445),
  66582 	1867: uint16(6465),
  66583 	1868: uint16(6471),
  66584 	1869: uint16(6480),
  66585 	1870: uint16(6486),
  66586 	1871: uint16(6497),
  66587 	1872: uint16(6503),
  66588 	1873: uint16(6512),
  66589 	1874: uint16(6518),
  66590 	1875: uint16(6543),
  66591 	1876: uint16(6549),
  66592 	1877: uint16(6558),
  66593 	1878: uint16(6564),
  66594 	1879: uint16(6575),
  66595 	1880: uint16(6581),
  66596 	1881: uint16(6590),
  66597 	1882: uint16(6596),
  66598 	1883: uint16(6616),
  66599 	1884: uint16(6622),
  66600 	1885: uint16(6631),
  66601 	1886: uint16(6637),
  66602 	1887: uint16(6648),
  66603 	1888: uint16(6654),
  66604 	1889: uint16(6663),
  66605 	1890: uint16(6669),
  66606 	1891: uint16(6692),
  66607 	1892: uint16(6698),
  66608 	1893: uint16(6707),
  66609 	1894: uint16(6713),
  66610 	1895: uint16(6724),
  66611 	1896: uint16(6730),
  66612 	1897: uint16(6739),
  66613 	1898: uint16(6745),
  66614 	1899: uint16(6765),
  66615 	1900: uint16(6771),
  66616 	1901: uint16(6780),
  66617 	1902: uint16(6786),
  66618 	1903: uint16(6797),
  66619 	1904: uint16(6803),
  66620 	1905: uint16(6812),
  66621 	1906: uint16(6818),
  66622 	1907: uint16(6843),
  66623 	1908: uint16(6849),
  66624 	1909: uint16(6858),
  66625 	1910: uint16(6864),
  66626 	1911: uint16(6875),
  66627 	1912: uint16(6881),
  66628 	1913: uint16(6890),
  66629 	1914: uint16(6896),
  66630 	1915: uint16(6916),
  66631 	1916: uint16(6922),
  66632 	1917: uint16(6931),
  66633 	1918: uint16(6937),
  66634 	1919: uint16(6948),
  66635 	1920: uint16(6954),
  66636 	1921: uint16(6963),
  66637 	1922: uint16(6969),
  66638 	1923: uint16(6833),
  66639 	1924: uint16(6839),
  66640 	1925: uint16(6848),
  66641 	1926: uint16(6854),
  66642 	1927: uint16(6865),
  66643 	1928: uint16(6871),
  66644 	1929: uint16(6880),
  66645 	1930: uint16(6886),
  66646 	1931: uint16(6906),
  66647 	1932: uint16(6912),
  66648 	1933: uint16(6921),
  66649 	1934: uint16(6927),
  66650 	1935: uint16(6938),
  66651 	1936: uint16(6944),
  66652 	1937: uint16(6953),
  66653 	1938: uint16(6959),
  66654 	1939: uint16(6984),
  66655 	1940: uint16(6990),
  66656 	1941: uint16(6999),
  66657 	1942: uint16(7005),
  66658 	1943: uint16(7016),
  66659 	1944: uint16(7022),
  66660 	1945: uint16(7031),
  66661 	1946: uint16(7037),
  66662 	1947: uint16(7057),
  66663 	1948: uint16(7063),
  66664 	1949: uint16(7072),
  66665 	1950: uint16(7078),
  66666 	1951: uint16(7089),
  66667 	1952: uint16(7095),
  66668 	1953: uint16(7104),
  66669 	1954: uint16(7110),
  66670 	1955: uint16(7133),
  66671 	1956: uint16(7139),
  66672 	1957: uint16(7148),
  66673 	1958: uint16(7154),
  66674 	1959: uint16(7165),
  66675 	1960: uint16(7171),
  66676 	1961: uint16(7180),
  66677 	1962: uint16(7186),
  66678 	1963: uint16(7206),
  66679 	1964: uint16(7212),
  66680 	1965: uint16(7221),
  66681 	1966: uint16(7227),
  66682 	1967: uint16(7238),
  66683 	1968: uint16(7244),
  66684 	1969: uint16(7253),
  66685 	1970: uint16(7259),
  66686 	1971: uint16(7284),
  66687 	1972: uint16(7290),
  66688 	1973: uint16(7299),
  66689 	1974: uint16(7305),
  66690 	1975: uint16(7316),
  66691 	1976: uint16(7322),
  66692 	1977: uint16(7331),
  66693 	1978: uint16(7337),
  66694 	1979: uint16(7357),
  66695 	1980: uint16(7363),
  66696 	1981: uint16(7372),
  66697 	1982: uint16(7378),
  66698 	1983: uint16(7389),
  66699 	1984: uint16(7395),
  66700 	1985: uint16(7404),
  66701 	1986: uint16(7410),
  66702 	1987: uint16(7205),
  66703 	1988: uint16(7211),
  66704 	1989: uint16(7220),
  66705 	1990: uint16(7226),
  66706 	1991: uint16(7237),
  66707 	1992: uint16(7243),
  66708 	1993: uint16(7252),
  66709 	1994: uint16(7258),
  66710 	1995: uint16(7278),
  66711 	1996: uint16(7284),
  66712 	1997: uint16(7293),
  66713 	1998: uint16(7299),
  66714 	1999: uint16(7310),
  66715 	2000: uint16(7316),
  66716 	2001: uint16(7325),
  66717 	2002: uint16(7331),
  66718 	2003: uint16(7356),
  66719 	2004: uint16(7362),
  66720 	2005: uint16(7371),
  66721 	2006: uint16(7377),
  66722 	2007: uint16(7388),
  66723 	2008: uint16(7394),
  66724 	2009: uint16(7403),
  66725 	2010: uint16(7409),
  66726 	2011: uint16(7429),
  66727 	2012: uint16(7435),
  66728 	2013: uint16(7444),
  66729 	2014: uint16(7450),
  66730 	2015: uint16(7461),
  66731 	2016: uint16(7467),
  66732 	2017: uint16(7476),
  66733 	2018: uint16(7482),
  66734 	2019: uint16(7505),
  66735 	2020: uint16(7511),
  66736 	2021: uint16(7520),
  66737 	2022: uint16(7526),
  66738 	2023: uint16(7537),
  66739 	2024: uint16(7543),
  66740 	2025: uint16(7552),
  66741 	2026: uint16(7558),
  66742 	2027: uint16(7578),
  66743 	2028: uint16(7584),
  66744 	2029: uint16(7593),
  66745 	2030: uint16(7599),
  66746 	2031: uint16(7610),
  66747 	2032: uint16(7616),
  66748 	2033: uint16(7625),
  66749 	2034: uint16(7631),
  66750 	2035: uint16(7656),
  66751 	2036: uint16(7662),
  66752 	2037: uint16(7671),
  66753 	2038: uint16(7677),
  66754 	2039: uint16(7688),
  66755 	2040: uint16(7694),
  66756 	2041: uint16(7703),
  66757 	2042: uint16(7709),
  66758 	2043: uint16(7729),
  66759 	2044: uint16(7735),
  66760 	2045: uint16(7744),
  66761 	2046: uint16(7750),
  66762 	2047: uint16(7761),
  66763 }
  66764 
  66765 var VP8Mean16x4 VP8MeanMetric
  66766 
  66767 var VP8PredChroma8 [7]VP8PredFunc
  66768 
  66769 var VP8PredLuma16 [7]VP8PredFunc
  66770 
  66771 var VP8PredLuma4 [10]VP8PredFunc
  66772 
  66773 var VP8SSE16x16 VP8Metric
  66774 
  66775 var VP8SSE16x8 VP8Metric
  66776 
  66777 var VP8SSE4x4 VP8Metric
  66778 
  66779 var VP8SSE8x8 VP8Metric
  66780 
  66781 //------------------------------------------------------------------------------
  66782 
  66783 var VP8SSIMGet VP8SSIMGetFunc
  66784 
  66785 var VP8SSIMGetClipped VP8SSIMGetClippedFunc
  66786 
  66787 //------------------------------------------------------------------------------
  66788 // Quantize
  66789 
  66790 // Layout:
  66791 // +----+----+
  66792 // |YYYY|UUVV| 0
  66793 // |YYYY|UUVV| 4
  66794 // |YYYY|....| 8
  66795 // |YYYY|....| 12
  66796 // +----+----+
  66797 
  66798 var VP8Scan = [16]uint16_t{
  66799 	1:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  66800 	2:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  66801 	3:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  66802 	4:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66803 	5:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66804 	6:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66805 	7:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66806 	8:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66807 	9:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66808 	10: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66809 	11: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66810 	12: libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66811 	13: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66812 	14: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66813 	15: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66814 }
  66815 
  66816 var VP8SetResidualCoeffs VP8SetResidualCoeffsFunc
  66817 
  66818 var VP8SimpleHFilter16 VP8SimpleFilterFunc
  66819 
  66820 var VP8SimpleHFilter16i VP8SimpleFilterFunc
  66821 
  66822 var VP8SimpleVFilter16 VP8SimpleFilterFunc
  66823 
  66824 var VP8SimpleVFilter16i VP8SimpleFilterFunc
  66825 
  66826 var VP8TDisto16x16 VP8WMetric
  66827 
  66828 var VP8TDisto4x4 VP8WMetric
  66829 
  66830 //------------------------------------------------------------------------------
  66831 
  66832 var VP8Transform VP8DecIdct2
  66833 
  66834 var VP8TransformAC3 VP8DecIdct
  66835 
  66836 var VP8TransformDC VP8DecIdct
  66837 
  66838 var VP8TransformDCUV VP8DecIdct
  66839 
  66840 var VP8TransformUV VP8DecIdct
  66841 
  66842 var VP8TransformWHT VP8WHT
  66843 
  66844 var VP8UVModeOffsets = [4]uint16_t{
  66845 	0: libc.Uint16FromInt32(libc.Int32FromInt32(2) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  66846 	1: libc.Uint16FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  66847 	2: libc.Uint16FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66848 	3: libc.Uint16FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  66849 }
  66850 
  66851 var VP8VFilter16 VP8LumaFilterFunc
  66852 
  66853 var VP8VFilter16i VP8LumaFilterFunc
  66854 
  66855 var VP8VFilter8 VP8ChromaFilterFunc
  66856 
  66857 var VP8VFilter8i VP8ChromaFilterFunc
  66858 
  66859 var VP8kabs0 = uintptr(unsafe.Pointer(&abs0)) + 255
  66860 
  66861 var VP8kclip1 = uintptr(unsafe.Pointer(&clip11)) + 255
  66862 
  66863 var VP8ksclip1 = uintptr(unsafe.Pointer(&sclip1)) + 1020
  66864 
  66865 var VP8ksclip2 = uintptr(unsafe.Pointer(&sclip2)) + 112
  66866 
  66867 var WebPAlphaReplace uintptr
  66868 
  66869 var WebPApplyAlphaMultiply uintptr
  66870 
  66871 var WebPApplyAlphaMultiply4444 uintptr
  66872 
  66873 var WebPConvertARGBToUV uintptr
  66874 
  66875 var WebPConvertARGBToY uintptr
  66876 
  66877 var WebPConvertBGR24ToY uintptr
  66878 
  66879 //-----------------------------------------------------------------------------
  66880 
  66881 var WebPConvertRGB24ToY uintptr
  66882 
  66883 var WebPConvertRGBA32ToUV uintptr
  66884 
  66885 var WebPDispatchAlpha uintptr
  66886 
  66887 var WebPDispatchAlphaToGreen uintptr
  66888 
  66889 var WebPExtractAlpha uintptr
  66890 
  66891 var WebPExtractGreen uintptr
  66892 
  66893 //------------------------------------------------------------------------------
  66894 // Init function
  66895 
  66896 var WebPFilters [4]WebPFilterFunc
  66897 
  66898 var WebPHasAlpha32b uintptr
  66899 
  66900 var WebPHasAlpha8b uintptr
  66901 
  66902 var WebPMultARGBRow uintptr
  66903 
  66904 var WebPMultRow uintptr
  66905 
  66906 var WebPPackRGB uintptr
  66907 
  66908 var WebPRescalerExportRowExpand WebPRescalerExportRowFunc
  66909 
  66910 var WebPRescalerExportRowShrink WebPRescalerExportRowFunc
  66911 
  66912 //------------------------------------------------------------------------------
  66913 
  66914 var WebPRescalerImportRowExpand WebPRescalerImportRowFunc
  66915 
  66916 var WebPRescalerImportRowShrink WebPRescalerImportRowFunc
  66917 
  66918 //-----------------------------------------------------------------------------
  66919 // Main call
  66920 
  66921 var WebPSamplers [13]WebPSamplerRowFunc
  66922 
  66923 var WebPUnfilters [4]WebPUnfilterFunc
  66924 
  66925 // Copyright 2010 Google Inc. All Rights Reserved.
  66926 //
  66927 // Use of this source code is governed by a BSD-style license
  66928 // that can be found in the COPYING file in the root of the source
  66929 // tree. An additional intellectual property rights grant can be found
  66930 // in the file PATENTS. All contributing project authors may
  66931 // be found in the AUTHORS file in the root of the source tree.
  66932 // -----------------------------------------------------------------------------
  66933 //
  66934 //  Main decoding functions for WebP images.
  66935 //
  66936 // Author: Skal (pascal.massimino@gmail.com)
  66937 
  66938 //------------------------------------------------------------------------------
  66939 // Fancy upsampler
  66940 
  66941 // C documentation
  66942 //
  66943 //	// Fancy upsampling functions to convert YUV to RGB
  66944 var WebPUpsamplers [13]WebPUpsampleLinePairFunc
  66945 
  66946 var WebPYUV444Converters [13]WebPYUV444Converter
  66947 
  66948 // Copyright 2012 Google Inc. All Rights Reserved.
  66949 //
  66950 // Use of this source code is governed by a BSD-style license
  66951 // that can be found in the COPYING file in the root of the source
  66952 // tree. An additional intellectual property rights grant can be found
  66953 // in the file PATENTS. All contributing project authors may
  66954 // be found in the AUTHORS file in the root of the source tree.
  66955 // -----------------------------------------------------------------------------
  66956 //
  66957 // Misc. common utility functions
  66958 //
  66959 // Authors: Skal (pascal.massimino@gmail.com)
  66960 //          Urvang (urvang@google.com)
  66961 
  66962 // Copyright 2012 Google Inc. All Rights Reserved.
  66963 //
  66964 // Use of this source code is governed by a BSD-style license
  66965 // that can be found in the COPYING file in the root of the source
  66966 // tree. An additional intellectual property rights grant can be found
  66967 // in the file PATENTS. All contributing project authors may
  66968 // be found in the AUTHORS file in the root of the source tree.
  66969 // -----------------------------------------------------------------------------
  66970 //
  66971 //  Internal header for constants related to WebP file format.
  66972 //
  66973 // Author: Urvang (urvang@google.com)
  66974 
  66975 // Copyright 2010 Google Inc. All Rights Reserved.
  66976 //
  66977 // Use of this source code is governed by a BSD-style license
  66978 // that can be found in the COPYING file in the root of the source
  66979 // tree. An additional intellectual property rights grant can be found
  66980 // in the file PATENTS. All contributing project authors may
  66981 // be found in the AUTHORS file in the root of the source tree.
  66982 // -----------------------------------------------------------------------------
  66983 //
  66984 //  Common types + memory wrappers
  66985 //
  66986 // Author: Skal (pascal.massimino@gmail.com)
  66987 
  66988 // C documentation
  66989 //
  66990 //	// lookup table for small values of log2(int) * (1 << LOG_2_PRECISION_BITS).
  66991 //	// Obtained in Python with:
  66992 //	// a = [ str(round((1<<23)*math.log2(i))) if i else "0" for i in range(256)]
  66993 //	// print(',\n'.join(['  '+','.join(v)
  66994 //	//       for v in batched([i.rjust(9) for i in a],7)]))
  66995 var kLog2Table = [256]uint32_t{
  66996 	2:   uint32(8388608),
  66997 	3:   uint32(13295629),
  66998 	4:   uint32(16777216),
  66999 	5:   uint32(19477745),
  67000 	6:   uint32(21684237),
  67001 	7:   uint32(23549800),
  67002 	8:   uint32(25165824),
  67003 	9:   uint32(26591258),
  67004 	10:  uint32(27866353),
  67005 	11:  uint32(29019816),
  67006 	12:  uint32(30072845),
  67007 	13:  uint32(31041538),
  67008 	14:  uint32(31938408),
  67009 	15:  uint32(32773374),
  67010 	16:  uint32(33554432),
  67011 	17:  uint32(34288123),
  67012 	18:  uint32(34979866),
  67013 	19:  uint32(35634199),
  67014 	20:  uint32(36254961),
  67015 	21:  uint32(36845429),
  67016 	22:  uint32(37408424),
  67017 	23:  uint32(37946388),
  67018 	24:  uint32(38461453),
  67019 	25:  uint32(38955489),
  67020 	26:  uint32(39430146),
  67021 	27:  uint32(39886887),
  67022 	28:  uint32(40327016),
  67023 	29:  uint32(40751698),
  67024 	30:  uint32(41161982),
  67025 	31:  uint32(41558811),
  67026 	32:  uint32(41943040),
  67027 	33:  uint32(42315445),
  67028 	34:  uint32(42676731),
  67029 	35:  uint32(43027545),
  67030 	36:  uint32(43368474),
  67031 	37:  uint32(43700062),
  67032 	38:  uint32(44022807),
  67033 	39:  uint32(44337167),
  67034 	40:  uint32(44643569),
  67035 	41:  uint32(44942404),
  67036 	42:  uint32(45234037),
  67037 	43:  uint32(45518808),
  67038 	44:  uint32(45797032),
  67039 	45:  uint32(46069003),
  67040 	46:  uint32(46334996),
  67041 	47:  uint32(46595268),
  67042 	48:  uint32(46850061),
  67043 	49:  uint32(47099600),
  67044 	50:  uint32(47344097),
  67045 	51:  uint32(47583753),
  67046 	52:  uint32(47818754),
  67047 	53:  uint32(48049279),
  67048 	54:  uint32(48275495),
  67049 	55:  uint32(48497560),
  67050 	56:  uint32(48715624),
  67051 	57:  uint32(48929828),
  67052 	58:  uint32(49140306),
  67053 	59:  uint32(49347187),
  67054 	60:  uint32(49550590),
  67055 	61:  uint32(49750631),
  67056 	62:  uint32(49947419),
  67057 	63:  uint32(50141058),
  67058 	64:  uint32(50331648),
  67059 	65:  uint32(50519283),
  67060 	66:  uint32(50704053),
  67061 	67:  uint32(50886044),
  67062 	68:  uint32(51065339),
  67063 	69:  uint32(51242017),
  67064 	70:  uint32(51416153),
  67065 	71:  uint32(51587818),
  67066 	72:  uint32(51757082),
  67067 	73:  uint32(51924012),
  67068 	74:  uint32(52088670),
  67069 	75:  uint32(52251118),
  67070 	76:  uint32(52411415),
  67071 	77:  uint32(52569616),
  67072 	78:  uint32(52725775),
  67073 	79:  uint32(52879946),
  67074 	80:  uint32(53032177),
  67075 	81:  uint32(53182516),
  67076 	82:  uint32(53331012),
  67077 	83:  uint32(53477707),
  67078 	84:  uint32(53622645),
  67079 	85:  uint32(53765868),
  67080 	86:  uint32(53907416),
  67081 	87:  uint32(54047327),
  67082 	88:  uint32(54185640),
  67083 	89:  uint32(54322389),
  67084 	90:  uint32(54457611),
  67085 	91:  uint32(54591338),
  67086 	92:  uint32(54723604),
  67087 	93:  uint32(54854440),
  67088 	94:  uint32(54983876),
  67089 	95:  uint32(55111943),
  67090 	96:  uint32(55238669),
  67091 	97:  uint32(55364082),
  67092 	98:  uint32(55488208),
  67093 	99:  uint32(55611074),
  67094 	100: uint32(55732705),
  67095 	101: uint32(55853126),
  67096 	102: uint32(55972361),
  67097 	103: uint32(56090432),
  67098 	104: uint32(56207362),
  67099 	105: uint32(56323174),
  67100 	106: uint32(56437887),
  67101 	107: uint32(56551524),
  67102 	108: uint32(56664103),
  67103 	109: uint32(56775645),
  67104 	110: uint32(56886168),
  67105 	111: uint32(56995691),
  67106 	112: uint32(57104232),
  67107 	113: uint32(57211808),
  67108 	114: uint32(57318436),
  67109 	115: uint32(57424133),
  67110 	116: uint32(57528914),
  67111 	117: uint32(57632796),
  67112 	118: uint32(57735795),
  67113 	119: uint32(57837923),
  67114 	120: uint32(57939198),
  67115 	121: uint32(58039632),
  67116 	122: uint32(58139239),
  67117 	123: uint32(58238033),
  67118 	124: uint32(58336027),
  67119 	125: uint32(58433234),
  67120 	126: uint32(58529666),
  67121 	127: uint32(58625336),
  67122 	128: uint32(58720256),
  67123 	129: uint32(58814437),
  67124 	130: uint32(58907891),
  67125 	131: uint32(59000628),
  67126 	132: uint32(59092661),
  67127 	133: uint32(59183999),
  67128 	134: uint32(59274652),
  67129 	135: uint32(59364632),
  67130 	136: uint32(59453947),
  67131 	137: uint32(59542609),
  67132 	138: uint32(59630625),
  67133 	139: uint32(59718006),
  67134 	140: uint32(59804761),
  67135 	141: uint32(59890898),
  67136 	142: uint32(59976426),
  67137 	143: uint32(60061354),
  67138 	144: uint32(60145690),
  67139 	145: uint32(60229443),
  67140 	146: uint32(60312620),
  67141 	147: uint32(60395229),
  67142 	148: uint32(60477278),
  67143 	149: uint32(60558775),
  67144 	150: uint32(60639726),
  67145 	151: uint32(60720140),
  67146 	152: uint32(60800023),
  67147 	153: uint32(60879382),
  67148 	154: uint32(60958224),
  67149 	155: uint32(61036555),
  67150 	156: uint32(61114383),
  67151 	157: uint32(61191714),
  67152 	158: uint32(61268554),
  67153 	159: uint32(61344908),
  67154 	160: uint32(61420785),
  67155 	161: uint32(61496188),
  67156 	162: uint32(61571124),
  67157 	163: uint32(61645600),
  67158 	164: uint32(61719620),
  67159 	165: uint32(61793189),
  67160 	166: uint32(61866315),
  67161 	167: uint32(61939001),
  67162 	168: uint32(62011253),
  67163 	169: uint32(62083076),
  67164 	170: uint32(62154476),
  67165 	171: uint32(62225457),
  67166 	172: uint32(62296024),
  67167 	173: uint32(62366182),
  67168 	174: uint32(62435935),
  67169 	175: uint32(62505289),
  67170 	176: uint32(62574248),
  67171 	177: uint32(62642816),
  67172 	178: uint32(62710997),
  67173 	179: uint32(62778797),
  67174 	180: uint32(62846219),
  67175 	181: uint32(62913267),
  67176 	182: uint32(62979946),
  67177 	183: uint32(63046260),
  67178 	184: uint32(63112212),
  67179 	185: uint32(63177807),
  67180 	186: uint32(63243048),
  67181 	187: uint32(63307939),
  67182 	188: uint32(63372484),
  67183 	189: uint32(63436687),
  67184 	190: uint32(63500551),
  67185 	191: uint32(63564080),
  67186 	192: uint32(63627277),
  67187 	193: uint32(63690146),
  67188 	194: uint32(63752690),
  67189 	195: uint32(63814912),
  67190 	196: uint32(63876816),
  67191 	197: uint32(63938405),
  67192 	198: uint32(63999682),
  67193 	199: uint32(64060650),
  67194 	200: uint32(64121313),
  67195 	201: uint32(64181673),
  67196 	202: uint32(64241734),
  67197 	203: uint32(64301498),
  67198 	204: uint32(64360969),
  67199 	205: uint32(64420148),
  67200 	206: uint32(64479040),
  67201 	207: uint32(64537646),
  67202 	208: uint32(64595970),
  67203 	209: uint32(64654014),
  67204 	210: uint32(64711782),
  67205 	211: uint32(64769274),
  67206 	212: uint32(64826495),
  67207 	213: uint32(64883447),
  67208 	214: uint32(64940132),
  67209 	215: uint32(64996553),
  67210 	216: uint32(65052711),
  67211 	217: uint32(65108611),
  67212 	218: uint32(65164253),
  67213 	219: uint32(65219641),
  67214 	220: uint32(65274776),
  67215 	221: uint32(65329662),
  67216 	222: uint32(65384299),
  67217 	223: uint32(65438691),
  67218 	224: uint32(65492840),
  67219 	225: uint32(65546747),
  67220 	226: uint32(65600416),
  67221 	227: uint32(65653847),
  67222 	228: uint32(65707044),
  67223 	229: uint32(65760008),
  67224 	230: uint32(65812741),
  67225 	231: uint32(65865245),
  67226 	232: uint32(65917522),
  67227 	233: uint32(65969575),
  67228 	234: uint32(66021404),
  67229 	235: uint32(66073013),
  67230 	236: uint32(66124403),
  67231 	237: uint32(66175575),
  67232 	238: uint32(66226531),
  67233 	239: uint32(66277275),
  67234 	240: uint32(66327806),
  67235 	241: uint32(66378127),
  67236 	242: uint32(66428240),
  67237 	243: uint32(66478146),
  67238 	244: uint32(66527847),
  67239 	245: uint32(66577345),
  67240 	246: uint32(66626641),
  67241 	247: uint32(66675737),
  67242 	248: uint32(66724635),
  67243 	249: uint32(66773336),
  67244 	250: uint32(66821842),
  67245 	251: uint32(66870154),
  67246 	252: uint32(66918274),
  67247 	253: uint32(66966204),
  67248 	254: uint32(67013944),
  67249 	255: uint32(67061497),
  67250 }
  67251 
  67252 var kPrefixEncodeCode = [512]VP8LPrefixCode{
  67253 	0: {},
  67254 	1: {},
  67255 	2: {
  67256 		Fcode: int8(1),
  67257 	},
  67258 	3: {
  67259 		Fcode: int8(2),
  67260 	},
  67261 	4: {
  67262 		Fcode: int8(3),
  67263 	},
  67264 	5: {
  67265 		Fcode:       int8(4),
  67266 		Fextra_bits: int8(1),
  67267 	},
  67268 	6: {
  67269 		Fcode:       int8(4),
  67270 		Fextra_bits: int8(1),
  67271 	},
  67272 	7: {
  67273 		Fcode:       int8(5),
  67274 		Fextra_bits: int8(1),
  67275 	},
  67276 	8: {
  67277 		Fcode:       int8(5),
  67278 		Fextra_bits: int8(1),
  67279 	},
  67280 	9: {
  67281 		Fcode:       int8(6),
  67282 		Fextra_bits: int8(2),
  67283 	},
  67284 	10: {
  67285 		Fcode:       int8(6),
  67286 		Fextra_bits: int8(2),
  67287 	},
  67288 	11: {
  67289 		Fcode:       int8(6),
  67290 		Fextra_bits: int8(2),
  67291 	},
  67292 	12: {
  67293 		Fcode:       int8(6),
  67294 		Fextra_bits: int8(2),
  67295 	},
  67296 	13: {
  67297 		Fcode:       int8(7),
  67298 		Fextra_bits: int8(2),
  67299 	},
  67300 	14: {
  67301 		Fcode:       int8(7),
  67302 		Fextra_bits: int8(2),
  67303 	},
  67304 	15: {
  67305 		Fcode:       int8(7),
  67306 		Fextra_bits: int8(2),
  67307 	},
  67308 	16: {
  67309 		Fcode:       int8(7),
  67310 		Fextra_bits: int8(2),
  67311 	},
  67312 	17: {
  67313 		Fcode:       int8(8),
  67314 		Fextra_bits: int8(3),
  67315 	},
  67316 	18: {
  67317 		Fcode:       int8(8),
  67318 		Fextra_bits: int8(3),
  67319 	},
  67320 	19: {
  67321 		Fcode:       int8(8),
  67322 		Fextra_bits: int8(3),
  67323 	},
  67324 	20: {
  67325 		Fcode:       int8(8),
  67326 		Fextra_bits: int8(3),
  67327 	},
  67328 	21: {
  67329 		Fcode:       int8(8),
  67330 		Fextra_bits: int8(3),
  67331 	},
  67332 	22: {
  67333 		Fcode:       int8(8),
  67334 		Fextra_bits: int8(3),
  67335 	},
  67336 	23: {
  67337 		Fcode:       int8(8),
  67338 		Fextra_bits: int8(3),
  67339 	},
  67340 	24: {
  67341 		Fcode:       int8(8),
  67342 		Fextra_bits: int8(3),
  67343 	},
  67344 	25: {
  67345 		Fcode:       int8(9),
  67346 		Fextra_bits: int8(3),
  67347 	},
  67348 	26: {
  67349 		Fcode:       int8(9),
  67350 		Fextra_bits: int8(3),
  67351 	},
  67352 	27: {
  67353 		Fcode:       int8(9),
  67354 		Fextra_bits: int8(3),
  67355 	},
  67356 	28: {
  67357 		Fcode:       int8(9),
  67358 		Fextra_bits: int8(3),
  67359 	},
  67360 	29: {
  67361 		Fcode:       int8(9),
  67362 		Fextra_bits: int8(3),
  67363 	},
  67364 	30: {
  67365 		Fcode:       int8(9),
  67366 		Fextra_bits: int8(3),
  67367 	},
  67368 	31: {
  67369 		Fcode:       int8(9),
  67370 		Fextra_bits: int8(3),
  67371 	},
  67372 	32: {
  67373 		Fcode:       int8(9),
  67374 		Fextra_bits: int8(3),
  67375 	},
  67376 	33: {
  67377 		Fcode:       int8(10),
  67378 		Fextra_bits: int8(4),
  67379 	},
  67380 	34: {
  67381 		Fcode:       int8(10),
  67382 		Fextra_bits: int8(4),
  67383 	},
  67384 	35: {
  67385 		Fcode:       int8(10),
  67386 		Fextra_bits: int8(4),
  67387 	},
  67388 	36: {
  67389 		Fcode:       int8(10),
  67390 		Fextra_bits: int8(4),
  67391 	},
  67392 	37: {
  67393 		Fcode:       int8(10),
  67394 		Fextra_bits: int8(4),
  67395 	},
  67396 	38: {
  67397 		Fcode:       int8(10),
  67398 		Fextra_bits: int8(4),
  67399 	},
  67400 	39: {
  67401 		Fcode:       int8(10),
  67402 		Fextra_bits: int8(4),
  67403 	},
  67404 	40: {
  67405 		Fcode:       int8(10),
  67406 		Fextra_bits: int8(4),
  67407 	},
  67408 	41: {
  67409 		Fcode:       int8(10),
  67410 		Fextra_bits: int8(4),
  67411 	},
  67412 	42: {
  67413 		Fcode:       int8(10),
  67414 		Fextra_bits: int8(4),
  67415 	},
  67416 	43: {
  67417 		Fcode:       int8(10),
  67418 		Fextra_bits: int8(4),
  67419 	},
  67420 	44: {
  67421 		Fcode:       int8(10),
  67422 		Fextra_bits: int8(4),
  67423 	},
  67424 	45: {
  67425 		Fcode:       int8(10),
  67426 		Fextra_bits: int8(4),
  67427 	},
  67428 	46: {
  67429 		Fcode:       int8(10),
  67430 		Fextra_bits: int8(4),
  67431 	},
  67432 	47: {
  67433 		Fcode:       int8(10),
  67434 		Fextra_bits: int8(4),
  67435 	},
  67436 	48: {
  67437 		Fcode:       int8(10),
  67438 		Fextra_bits: int8(4),
  67439 	},
  67440 	49: {
  67441 		Fcode:       int8(11),
  67442 		Fextra_bits: int8(4),
  67443 	},
  67444 	50: {
  67445 		Fcode:       int8(11),
  67446 		Fextra_bits: int8(4),
  67447 	},
  67448 	51: {
  67449 		Fcode:       int8(11),
  67450 		Fextra_bits: int8(4),
  67451 	},
  67452 	52: {
  67453 		Fcode:       int8(11),
  67454 		Fextra_bits: int8(4),
  67455 	},
  67456 	53: {
  67457 		Fcode:       int8(11),
  67458 		Fextra_bits: int8(4),
  67459 	},
  67460 	54: {
  67461 		Fcode:       int8(11),
  67462 		Fextra_bits: int8(4),
  67463 	},
  67464 	55: {
  67465 		Fcode:       int8(11),
  67466 		Fextra_bits: int8(4),
  67467 	},
  67468 	56: {
  67469 		Fcode:       int8(11),
  67470 		Fextra_bits: int8(4),
  67471 	},
  67472 	57: {
  67473 		Fcode:       int8(11),
  67474 		Fextra_bits: int8(4),
  67475 	},
  67476 	58: {
  67477 		Fcode:       int8(11),
  67478 		Fextra_bits: int8(4),
  67479 	},
  67480 	59: {
  67481 		Fcode:       int8(11),
  67482 		Fextra_bits: int8(4),
  67483 	},
  67484 	60: {
  67485 		Fcode:       int8(11),
  67486 		Fextra_bits: int8(4),
  67487 	},
  67488 	61: {
  67489 		Fcode:       int8(11),
  67490 		Fextra_bits: int8(4),
  67491 	},
  67492 	62: {
  67493 		Fcode:       int8(11),
  67494 		Fextra_bits: int8(4),
  67495 	},
  67496 	63: {
  67497 		Fcode:       int8(11),
  67498 		Fextra_bits: int8(4),
  67499 	},
  67500 	64: {
  67501 		Fcode:       int8(11),
  67502 		Fextra_bits: int8(4),
  67503 	},
  67504 	65: {
  67505 		Fcode:       int8(12),
  67506 		Fextra_bits: int8(5),
  67507 	},
  67508 	66: {
  67509 		Fcode:       int8(12),
  67510 		Fextra_bits: int8(5),
  67511 	},
  67512 	67: {
  67513 		Fcode:       int8(12),
  67514 		Fextra_bits: int8(5),
  67515 	},
  67516 	68: {
  67517 		Fcode:       int8(12),
  67518 		Fextra_bits: int8(5),
  67519 	},
  67520 	69: {
  67521 		Fcode:       int8(12),
  67522 		Fextra_bits: int8(5),
  67523 	},
  67524 	70: {
  67525 		Fcode:       int8(12),
  67526 		Fextra_bits: int8(5),
  67527 	},
  67528 	71: {
  67529 		Fcode:       int8(12),
  67530 		Fextra_bits: int8(5),
  67531 	},
  67532 	72: {
  67533 		Fcode:       int8(12),
  67534 		Fextra_bits: int8(5),
  67535 	},
  67536 	73: {
  67537 		Fcode:       int8(12),
  67538 		Fextra_bits: int8(5),
  67539 	},
  67540 	74: {
  67541 		Fcode:       int8(12),
  67542 		Fextra_bits: int8(5),
  67543 	},
  67544 	75: {
  67545 		Fcode:       int8(12),
  67546 		Fextra_bits: int8(5),
  67547 	},
  67548 	76: {
  67549 		Fcode:       int8(12),
  67550 		Fextra_bits: int8(5),
  67551 	},
  67552 	77: {
  67553 		Fcode:       int8(12),
  67554 		Fextra_bits: int8(5),
  67555 	},
  67556 	78: {
  67557 		Fcode:       int8(12),
  67558 		Fextra_bits: int8(5),
  67559 	},
  67560 	79: {
  67561 		Fcode:       int8(12),
  67562 		Fextra_bits: int8(5),
  67563 	},
  67564 	80: {
  67565 		Fcode:       int8(12),
  67566 		Fextra_bits: int8(5),
  67567 	},
  67568 	81: {
  67569 		Fcode:       int8(12),
  67570 		Fextra_bits: int8(5),
  67571 	},
  67572 	82: {
  67573 		Fcode:       int8(12),
  67574 		Fextra_bits: int8(5),
  67575 	},
  67576 	83: {
  67577 		Fcode:       int8(12),
  67578 		Fextra_bits: int8(5),
  67579 	},
  67580 	84: {
  67581 		Fcode:       int8(12),
  67582 		Fextra_bits: int8(5),
  67583 	},
  67584 	85: {
  67585 		Fcode:       int8(12),
  67586 		Fextra_bits: int8(5),
  67587 	},
  67588 	86: {
  67589 		Fcode:       int8(12),
  67590 		Fextra_bits: int8(5),
  67591 	},
  67592 	87: {
  67593 		Fcode:       int8(12),
  67594 		Fextra_bits: int8(5),
  67595 	},
  67596 	88: {
  67597 		Fcode:       int8(12),
  67598 		Fextra_bits: int8(5),
  67599 	},
  67600 	89: {
  67601 		Fcode:       int8(12),
  67602 		Fextra_bits: int8(5),
  67603 	},
  67604 	90: {
  67605 		Fcode:       int8(12),
  67606 		Fextra_bits: int8(5),
  67607 	},
  67608 	91: {
  67609 		Fcode:       int8(12),
  67610 		Fextra_bits: int8(5),
  67611 	},
  67612 	92: {
  67613 		Fcode:       int8(12),
  67614 		Fextra_bits: int8(5),
  67615 	},
  67616 	93: {
  67617 		Fcode:       int8(12),
  67618 		Fextra_bits: int8(5),
  67619 	},
  67620 	94: {
  67621 		Fcode:       int8(12),
  67622 		Fextra_bits: int8(5),
  67623 	},
  67624 	95: {
  67625 		Fcode:       int8(12),
  67626 		Fextra_bits: int8(5),
  67627 	},
  67628 	96: {
  67629 		Fcode:       int8(12),
  67630 		Fextra_bits: int8(5),
  67631 	},
  67632 	97: {
  67633 		Fcode:       int8(13),
  67634 		Fextra_bits: int8(5),
  67635 	},
  67636 	98: {
  67637 		Fcode:       int8(13),
  67638 		Fextra_bits: int8(5),
  67639 	},
  67640 	99: {
  67641 		Fcode:       int8(13),
  67642 		Fextra_bits: int8(5),
  67643 	},
  67644 	100: {
  67645 		Fcode:       int8(13),
  67646 		Fextra_bits: int8(5),
  67647 	},
  67648 	101: {
  67649 		Fcode:       int8(13),
  67650 		Fextra_bits: int8(5),
  67651 	},
  67652 	102: {
  67653 		Fcode:       int8(13),
  67654 		Fextra_bits: int8(5),
  67655 	},
  67656 	103: {
  67657 		Fcode:       int8(13),
  67658 		Fextra_bits: int8(5),
  67659 	},
  67660 	104: {
  67661 		Fcode:       int8(13),
  67662 		Fextra_bits: int8(5),
  67663 	},
  67664 	105: {
  67665 		Fcode:       int8(13),
  67666 		Fextra_bits: int8(5),
  67667 	},
  67668 	106: {
  67669 		Fcode:       int8(13),
  67670 		Fextra_bits: int8(5),
  67671 	},
  67672 	107: {
  67673 		Fcode:       int8(13),
  67674 		Fextra_bits: int8(5),
  67675 	},
  67676 	108: {
  67677 		Fcode:       int8(13),
  67678 		Fextra_bits: int8(5),
  67679 	},
  67680 	109: {
  67681 		Fcode:       int8(13),
  67682 		Fextra_bits: int8(5),
  67683 	},
  67684 	110: {
  67685 		Fcode:       int8(13),
  67686 		Fextra_bits: int8(5),
  67687 	},
  67688 	111: {
  67689 		Fcode:       int8(13),
  67690 		Fextra_bits: int8(5),
  67691 	},
  67692 	112: {
  67693 		Fcode:       int8(13),
  67694 		Fextra_bits: int8(5),
  67695 	},
  67696 	113: {
  67697 		Fcode:       int8(13),
  67698 		Fextra_bits: int8(5),
  67699 	},
  67700 	114: {
  67701 		Fcode:       int8(13),
  67702 		Fextra_bits: int8(5),
  67703 	},
  67704 	115: {
  67705 		Fcode:       int8(13),
  67706 		Fextra_bits: int8(5),
  67707 	},
  67708 	116: {
  67709 		Fcode:       int8(13),
  67710 		Fextra_bits: int8(5),
  67711 	},
  67712 	117: {
  67713 		Fcode:       int8(13),
  67714 		Fextra_bits: int8(5),
  67715 	},
  67716 	118: {
  67717 		Fcode:       int8(13),
  67718 		Fextra_bits: int8(5),
  67719 	},
  67720 	119: {
  67721 		Fcode:       int8(13),
  67722 		Fextra_bits: int8(5),
  67723 	},
  67724 	120: {
  67725 		Fcode:       int8(13),
  67726 		Fextra_bits: int8(5),
  67727 	},
  67728 	121: {
  67729 		Fcode:       int8(13),
  67730 		Fextra_bits: int8(5),
  67731 	},
  67732 	122: {
  67733 		Fcode:       int8(13),
  67734 		Fextra_bits: int8(5),
  67735 	},
  67736 	123: {
  67737 		Fcode:       int8(13),
  67738 		Fextra_bits: int8(5),
  67739 	},
  67740 	124: {
  67741 		Fcode:       int8(13),
  67742 		Fextra_bits: int8(5),
  67743 	},
  67744 	125: {
  67745 		Fcode:       int8(13),
  67746 		Fextra_bits: int8(5),
  67747 	},
  67748 	126: {
  67749 		Fcode:       int8(13),
  67750 		Fextra_bits: int8(5),
  67751 	},
  67752 	127: {
  67753 		Fcode:       int8(13),
  67754 		Fextra_bits: int8(5),
  67755 	},
  67756 	128: {
  67757 		Fcode:       int8(13),
  67758 		Fextra_bits: int8(5),
  67759 	},
  67760 	129: {
  67761 		Fcode:       int8(14),
  67762 		Fextra_bits: int8(6),
  67763 	},
  67764 	130: {
  67765 		Fcode:       int8(14),
  67766 		Fextra_bits: int8(6),
  67767 	},
  67768 	131: {
  67769 		Fcode:       int8(14),
  67770 		Fextra_bits: int8(6),
  67771 	},
  67772 	132: {
  67773 		Fcode:       int8(14),
  67774 		Fextra_bits: int8(6),
  67775 	},
  67776 	133: {
  67777 		Fcode:       int8(14),
  67778 		Fextra_bits: int8(6),
  67779 	},
  67780 	134: {
  67781 		Fcode:       int8(14),
  67782 		Fextra_bits: int8(6),
  67783 	},
  67784 	135: {
  67785 		Fcode:       int8(14),
  67786 		Fextra_bits: int8(6),
  67787 	},
  67788 	136: {
  67789 		Fcode:       int8(14),
  67790 		Fextra_bits: int8(6),
  67791 	},
  67792 	137: {
  67793 		Fcode:       int8(14),
  67794 		Fextra_bits: int8(6),
  67795 	},
  67796 	138: {
  67797 		Fcode:       int8(14),
  67798 		Fextra_bits: int8(6),
  67799 	},
  67800 	139: {
  67801 		Fcode:       int8(14),
  67802 		Fextra_bits: int8(6),
  67803 	},
  67804 	140: {
  67805 		Fcode:       int8(14),
  67806 		Fextra_bits: int8(6),
  67807 	},
  67808 	141: {
  67809 		Fcode:       int8(14),
  67810 		Fextra_bits: int8(6),
  67811 	},
  67812 	142: {
  67813 		Fcode:       int8(14),
  67814 		Fextra_bits: int8(6),
  67815 	},
  67816 	143: {
  67817 		Fcode:       int8(14),
  67818 		Fextra_bits: int8(6),
  67819 	},
  67820 	144: {
  67821 		Fcode:       int8(14),
  67822 		Fextra_bits: int8(6),
  67823 	},
  67824 	145: {
  67825 		Fcode:       int8(14),
  67826 		Fextra_bits: int8(6),
  67827 	},
  67828 	146: {
  67829 		Fcode:       int8(14),
  67830 		Fextra_bits: int8(6),
  67831 	},
  67832 	147: {
  67833 		Fcode:       int8(14),
  67834 		Fextra_bits: int8(6),
  67835 	},
  67836 	148: {
  67837 		Fcode:       int8(14),
  67838 		Fextra_bits: int8(6),
  67839 	},
  67840 	149: {
  67841 		Fcode:       int8(14),
  67842 		Fextra_bits: int8(6),
  67843 	},
  67844 	150: {
  67845 		Fcode:       int8(14),
  67846 		Fextra_bits: int8(6),
  67847 	},
  67848 	151: {
  67849 		Fcode:       int8(14),
  67850 		Fextra_bits: int8(6),
  67851 	},
  67852 	152: {
  67853 		Fcode:       int8(14),
  67854 		Fextra_bits: int8(6),
  67855 	},
  67856 	153: {
  67857 		Fcode:       int8(14),
  67858 		Fextra_bits: int8(6),
  67859 	},
  67860 	154: {
  67861 		Fcode:       int8(14),
  67862 		Fextra_bits: int8(6),
  67863 	},
  67864 	155: {
  67865 		Fcode:       int8(14),
  67866 		Fextra_bits: int8(6),
  67867 	},
  67868 	156: {
  67869 		Fcode:       int8(14),
  67870 		Fextra_bits: int8(6),
  67871 	},
  67872 	157: {
  67873 		Fcode:       int8(14),
  67874 		Fextra_bits: int8(6),
  67875 	},
  67876 	158: {
  67877 		Fcode:       int8(14),
  67878 		Fextra_bits: int8(6),
  67879 	},
  67880 	159: {
  67881 		Fcode:       int8(14),
  67882 		Fextra_bits: int8(6),
  67883 	},
  67884 	160: {
  67885 		Fcode:       int8(14),
  67886 		Fextra_bits: int8(6),
  67887 	},
  67888 	161: {
  67889 		Fcode:       int8(14),
  67890 		Fextra_bits: int8(6),
  67891 	},
  67892 	162: {
  67893 		Fcode:       int8(14),
  67894 		Fextra_bits: int8(6),
  67895 	},
  67896 	163: {
  67897 		Fcode:       int8(14),
  67898 		Fextra_bits: int8(6),
  67899 	},
  67900 	164: {
  67901 		Fcode:       int8(14),
  67902 		Fextra_bits: int8(6),
  67903 	},
  67904 	165: {
  67905 		Fcode:       int8(14),
  67906 		Fextra_bits: int8(6),
  67907 	},
  67908 	166: {
  67909 		Fcode:       int8(14),
  67910 		Fextra_bits: int8(6),
  67911 	},
  67912 	167: {
  67913 		Fcode:       int8(14),
  67914 		Fextra_bits: int8(6),
  67915 	},
  67916 	168: {
  67917 		Fcode:       int8(14),
  67918 		Fextra_bits: int8(6),
  67919 	},
  67920 	169: {
  67921 		Fcode:       int8(14),
  67922 		Fextra_bits: int8(6),
  67923 	},
  67924 	170: {
  67925 		Fcode:       int8(14),
  67926 		Fextra_bits: int8(6),
  67927 	},
  67928 	171: {
  67929 		Fcode:       int8(14),
  67930 		Fextra_bits: int8(6),
  67931 	},
  67932 	172: {
  67933 		Fcode:       int8(14),
  67934 		Fextra_bits: int8(6),
  67935 	},
  67936 	173: {
  67937 		Fcode:       int8(14),
  67938 		Fextra_bits: int8(6),
  67939 	},
  67940 	174: {
  67941 		Fcode:       int8(14),
  67942 		Fextra_bits: int8(6),
  67943 	},
  67944 	175: {
  67945 		Fcode:       int8(14),
  67946 		Fextra_bits: int8(6),
  67947 	},
  67948 	176: {
  67949 		Fcode:       int8(14),
  67950 		Fextra_bits: int8(6),
  67951 	},
  67952 	177: {
  67953 		Fcode:       int8(14),
  67954 		Fextra_bits: int8(6),
  67955 	},
  67956 	178: {
  67957 		Fcode:       int8(14),
  67958 		Fextra_bits: int8(6),
  67959 	},
  67960 	179: {
  67961 		Fcode:       int8(14),
  67962 		Fextra_bits: int8(6),
  67963 	},
  67964 	180: {
  67965 		Fcode:       int8(14),
  67966 		Fextra_bits: int8(6),
  67967 	},
  67968 	181: {
  67969 		Fcode:       int8(14),
  67970 		Fextra_bits: int8(6),
  67971 	},
  67972 	182: {
  67973 		Fcode:       int8(14),
  67974 		Fextra_bits: int8(6),
  67975 	},
  67976 	183: {
  67977 		Fcode:       int8(14),
  67978 		Fextra_bits: int8(6),
  67979 	},
  67980 	184: {
  67981 		Fcode:       int8(14),
  67982 		Fextra_bits: int8(6),
  67983 	},
  67984 	185: {
  67985 		Fcode:       int8(14),
  67986 		Fextra_bits: int8(6),
  67987 	},
  67988 	186: {
  67989 		Fcode:       int8(14),
  67990 		Fextra_bits: int8(6),
  67991 	},
  67992 	187: {
  67993 		Fcode:       int8(14),
  67994 		Fextra_bits: int8(6),
  67995 	},
  67996 	188: {
  67997 		Fcode:       int8(14),
  67998 		Fextra_bits: int8(6),
  67999 	},
  68000 	189: {
  68001 		Fcode:       int8(14),
  68002 		Fextra_bits: int8(6),
  68003 	},
  68004 	190: {
  68005 		Fcode:       int8(14),
  68006 		Fextra_bits: int8(6),
  68007 	},
  68008 	191: {
  68009 		Fcode:       int8(14),
  68010 		Fextra_bits: int8(6),
  68011 	},
  68012 	192: {
  68013 		Fcode:       int8(14),
  68014 		Fextra_bits: int8(6),
  68015 	},
  68016 	193: {
  68017 		Fcode:       int8(15),
  68018 		Fextra_bits: int8(6),
  68019 	},
  68020 	194: {
  68021 		Fcode:       int8(15),
  68022 		Fextra_bits: int8(6),
  68023 	},
  68024 	195: {
  68025 		Fcode:       int8(15),
  68026 		Fextra_bits: int8(6),
  68027 	},
  68028 	196: {
  68029 		Fcode:       int8(15),
  68030 		Fextra_bits: int8(6),
  68031 	},
  68032 	197: {
  68033 		Fcode:       int8(15),
  68034 		Fextra_bits: int8(6),
  68035 	},
  68036 	198: {
  68037 		Fcode:       int8(15),
  68038 		Fextra_bits: int8(6),
  68039 	},
  68040 	199: {
  68041 		Fcode:       int8(15),
  68042 		Fextra_bits: int8(6),
  68043 	},
  68044 	200: {
  68045 		Fcode:       int8(15),
  68046 		Fextra_bits: int8(6),
  68047 	},
  68048 	201: {
  68049 		Fcode:       int8(15),
  68050 		Fextra_bits: int8(6),
  68051 	},
  68052 	202: {
  68053 		Fcode:       int8(15),
  68054 		Fextra_bits: int8(6),
  68055 	},
  68056 	203: {
  68057 		Fcode:       int8(15),
  68058 		Fextra_bits: int8(6),
  68059 	},
  68060 	204: {
  68061 		Fcode:       int8(15),
  68062 		Fextra_bits: int8(6),
  68063 	},
  68064 	205: {
  68065 		Fcode:       int8(15),
  68066 		Fextra_bits: int8(6),
  68067 	},
  68068 	206: {
  68069 		Fcode:       int8(15),
  68070 		Fextra_bits: int8(6),
  68071 	},
  68072 	207: {
  68073 		Fcode:       int8(15),
  68074 		Fextra_bits: int8(6),
  68075 	},
  68076 	208: {
  68077 		Fcode:       int8(15),
  68078 		Fextra_bits: int8(6),
  68079 	},
  68080 	209: {
  68081 		Fcode:       int8(15),
  68082 		Fextra_bits: int8(6),
  68083 	},
  68084 	210: {
  68085 		Fcode:       int8(15),
  68086 		Fextra_bits: int8(6),
  68087 	},
  68088 	211: {
  68089 		Fcode:       int8(15),
  68090 		Fextra_bits: int8(6),
  68091 	},
  68092 	212: {
  68093 		Fcode:       int8(15),
  68094 		Fextra_bits: int8(6),
  68095 	},
  68096 	213: {
  68097 		Fcode:       int8(15),
  68098 		Fextra_bits: int8(6),
  68099 	},
  68100 	214: {
  68101 		Fcode:       int8(15),
  68102 		Fextra_bits: int8(6),
  68103 	},
  68104 	215: {
  68105 		Fcode:       int8(15),
  68106 		Fextra_bits: int8(6),
  68107 	},
  68108 	216: {
  68109 		Fcode:       int8(15),
  68110 		Fextra_bits: int8(6),
  68111 	},
  68112 	217: {
  68113 		Fcode:       int8(15),
  68114 		Fextra_bits: int8(6),
  68115 	},
  68116 	218: {
  68117 		Fcode:       int8(15),
  68118 		Fextra_bits: int8(6),
  68119 	},
  68120 	219: {
  68121 		Fcode:       int8(15),
  68122 		Fextra_bits: int8(6),
  68123 	},
  68124 	220: {
  68125 		Fcode:       int8(15),
  68126 		Fextra_bits: int8(6),
  68127 	},
  68128 	221: {
  68129 		Fcode:       int8(15),
  68130 		Fextra_bits: int8(6),
  68131 	},
  68132 	222: {
  68133 		Fcode:       int8(15),
  68134 		Fextra_bits: int8(6),
  68135 	},
  68136 	223: {
  68137 		Fcode:       int8(15),
  68138 		Fextra_bits: int8(6),
  68139 	},
  68140 	224: {
  68141 		Fcode:       int8(15),
  68142 		Fextra_bits: int8(6),
  68143 	},
  68144 	225: {
  68145 		Fcode:       int8(15),
  68146 		Fextra_bits: int8(6),
  68147 	},
  68148 	226: {
  68149 		Fcode:       int8(15),
  68150 		Fextra_bits: int8(6),
  68151 	},
  68152 	227: {
  68153 		Fcode:       int8(15),
  68154 		Fextra_bits: int8(6),
  68155 	},
  68156 	228: {
  68157 		Fcode:       int8(15),
  68158 		Fextra_bits: int8(6),
  68159 	},
  68160 	229: {
  68161 		Fcode:       int8(15),
  68162 		Fextra_bits: int8(6),
  68163 	},
  68164 	230: {
  68165 		Fcode:       int8(15),
  68166 		Fextra_bits: int8(6),
  68167 	},
  68168 	231: {
  68169 		Fcode:       int8(15),
  68170 		Fextra_bits: int8(6),
  68171 	},
  68172 	232: {
  68173 		Fcode:       int8(15),
  68174 		Fextra_bits: int8(6),
  68175 	},
  68176 	233: {
  68177 		Fcode:       int8(15),
  68178 		Fextra_bits: int8(6),
  68179 	},
  68180 	234: {
  68181 		Fcode:       int8(15),
  68182 		Fextra_bits: int8(6),
  68183 	},
  68184 	235: {
  68185 		Fcode:       int8(15),
  68186 		Fextra_bits: int8(6),
  68187 	},
  68188 	236: {
  68189 		Fcode:       int8(15),
  68190 		Fextra_bits: int8(6),
  68191 	},
  68192 	237: {
  68193 		Fcode:       int8(15),
  68194 		Fextra_bits: int8(6),
  68195 	},
  68196 	238: {
  68197 		Fcode:       int8(15),
  68198 		Fextra_bits: int8(6),
  68199 	},
  68200 	239: {
  68201 		Fcode:       int8(15),
  68202 		Fextra_bits: int8(6),
  68203 	},
  68204 	240: {
  68205 		Fcode:       int8(15),
  68206 		Fextra_bits: int8(6),
  68207 	},
  68208 	241: {
  68209 		Fcode:       int8(15),
  68210 		Fextra_bits: int8(6),
  68211 	},
  68212 	242: {
  68213 		Fcode:       int8(15),
  68214 		Fextra_bits: int8(6),
  68215 	},
  68216 	243: {
  68217 		Fcode:       int8(15),
  68218 		Fextra_bits: int8(6),
  68219 	},
  68220 	244: {
  68221 		Fcode:       int8(15),
  68222 		Fextra_bits: int8(6),
  68223 	},
  68224 	245: {
  68225 		Fcode:       int8(15),
  68226 		Fextra_bits: int8(6),
  68227 	},
  68228 	246: {
  68229 		Fcode:       int8(15),
  68230 		Fextra_bits: int8(6),
  68231 	},
  68232 	247: {
  68233 		Fcode:       int8(15),
  68234 		Fextra_bits: int8(6),
  68235 	},
  68236 	248: {
  68237 		Fcode:       int8(15),
  68238 		Fextra_bits: int8(6),
  68239 	},
  68240 	249: {
  68241 		Fcode:       int8(15),
  68242 		Fextra_bits: int8(6),
  68243 	},
  68244 	250: {
  68245 		Fcode:       int8(15),
  68246 		Fextra_bits: int8(6),
  68247 	},
  68248 	251: {
  68249 		Fcode:       int8(15),
  68250 		Fextra_bits: int8(6),
  68251 	},
  68252 	252: {
  68253 		Fcode:       int8(15),
  68254 		Fextra_bits: int8(6),
  68255 	},
  68256 	253: {
  68257 		Fcode:       int8(15),
  68258 		Fextra_bits: int8(6),
  68259 	},
  68260 	254: {
  68261 		Fcode:       int8(15),
  68262 		Fextra_bits: int8(6),
  68263 	},
  68264 	255: {
  68265 		Fcode:       int8(15),
  68266 		Fextra_bits: int8(6),
  68267 	},
  68268 	256: {
  68269 		Fcode:       int8(15),
  68270 		Fextra_bits: int8(6),
  68271 	},
  68272 	257: {
  68273 		Fcode:       int8(16),
  68274 		Fextra_bits: int8(7),
  68275 	},
  68276 	258: {
  68277 		Fcode:       int8(16),
  68278 		Fextra_bits: int8(7),
  68279 	},
  68280 	259: {
  68281 		Fcode:       int8(16),
  68282 		Fextra_bits: int8(7),
  68283 	},
  68284 	260: {
  68285 		Fcode:       int8(16),
  68286 		Fextra_bits: int8(7),
  68287 	},
  68288 	261: {
  68289 		Fcode:       int8(16),
  68290 		Fextra_bits: int8(7),
  68291 	},
  68292 	262: {
  68293 		Fcode:       int8(16),
  68294 		Fextra_bits: int8(7),
  68295 	},
  68296 	263: {
  68297 		Fcode:       int8(16),
  68298 		Fextra_bits: int8(7),
  68299 	},
  68300 	264: {
  68301 		Fcode:       int8(16),
  68302 		Fextra_bits: int8(7),
  68303 	},
  68304 	265: {
  68305 		Fcode:       int8(16),
  68306 		Fextra_bits: int8(7),
  68307 	},
  68308 	266: {
  68309 		Fcode:       int8(16),
  68310 		Fextra_bits: int8(7),
  68311 	},
  68312 	267: {
  68313 		Fcode:       int8(16),
  68314 		Fextra_bits: int8(7),
  68315 	},
  68316 	268: {
  68317 		Fcode:       int8(16),
  68318 		Fextra_bits: int8(7),
  68319 	},
  68320 	269: {
  68321 		Fcode:       int8(16),
  68322 		Fextra_bits: int8(7),
  68323 	},
  68324 	270: {
  68325 		Fcode:       int8(16),
  68326 		Fextra_bits: int8(7),
  68327 	},
  68328 	271: {
  68329 		Fcode:       int8(16),
  68330 		Fextra_bits: int8(7),
  68331 	},
  68332 	272: {
  68333 		Fcode:       int8(16),
  68334 		Fextra_bits: int8(7),
  68335 	},
  68336 	273: {
  68337 		Fcode:       int8(16),
  68338 		Fextra_bits: int8(7),
  68339 	},
  68340 	274: {
  68341 		Fcode:       int8(16),
  68342 		Fextra_bits: int8(7),
  68343 	},
  68344 	275: {
  68345 		Fcode:       int8(16),
  68346 		Fextra_bits: int8(7),
  68347 	},
  68348 	276: {
  68349 		Fcode:       int8(16),
  68350 		Fextra_bits: int8(7),
  68351 	},
  68352 	277: {
  68353 		Fcode:       int8(16),
  68354 		Fextra_bits: int8(7),
  68355 	},
  68356 	278: {
  68357 		Fcode:       int8(16),
  68358 		Fextra_bits: int8(7),
  68359 	},
  68360 	279: {
  68361 		Fcode:       int8(16),
  68362 		Fextra_bits: int8(7),
  68363 	},
  68364 	280: {
  68365 		Fcode:       int8(16),
  68366 		Fextra_bits: int8(7),
  68367 	},
  68368 	281: {
  68369 		Fcode:       int8(16),
  68370 		Fextra_bits: int8(7),
  68371 	},
  68372 	282: {
  68373 		Fcode:       int8(16),
  68374 		Fextra_bits: int8(7),
  68375 	},
  68376 	283: {
  68377 		Fcode:       int8(16),
  68378 		Fextra_bits: int8(7),
  68379 	},
  68380 	284: {
  68381 		Fcode:       int8(16),
  68382 		Fextra_bits: int8(7),
  68383 	},
  68384 	285: {
  68385 		Fcode:       int8(16),
  68386 		Fextra_bits: int8(7),
  68387 	},
  68388 	286: {
  68389 		Fcode:       int8(16),
  68390 		Fextra_bits: int8(7),
  68391 	},
  68392 	287: {
  68393 		Fcode:       int8(16),
  68394 		Fextra_bits: int8(7),
  68395 	},
  68396 	288: {
  68397 		Fcode:       int8(16),
  68398 		Fextra_bits: int8(7),
  68399 	},
  68400 	289: {
  68401 		Fcode:       int8(16),
  68402 		Fextra_bits: int8(7),
  68403 	},
  68404 	290: {
  68405 		Fcode:       int8(16),
  68406 		Fextra_bits: int8(7),
  68407 	},
  68408 	291: {
  68409 		Fcode:       int8(16),
  68410 		Fextra_bits: int8(7),
  68411 	},
  68412 	292: {
  68413 		Fcode:       int8(16),
  68414 		Fextra_bits: int8(7),
  68415 	},
  68416 	293: {
  68417 		Fcode:       int8(16),
  68418 		Fextra_bits: int8(7),
  68419 	},
  68420 	294: {
  68421 		Fcode:       int8(16),
  68422 		Fextra_bits: int8(7),
  68423 	},
  68424 	295: {
  68425 		Fcode:       int8(16),
  68426 		Fextra_bits: int8(7),
  68427 	},
  68428 	296: {
  68429 		Fcode:       int8(16),
  68430 		Fextra_bits: int8(7),
  68431 	},
  68432 	297: {
  68433 		Fcode:       int8(16),
  68434 		Fextra_bits: int8(7),
  68435 	},
  68436 	298: {
  68437 		Fcode:       int8(16),
  68438 		Fextra_bits: int8(7),
  68439 	},
  68440 	299: {
  68441 		Fcode:       int8(16),
  68442 		Fextra_bits: int8(7),
  68443 	},
  68444 	300: {
  68445 		Fcode:       int8(16),
  68446 		Fextra_bits: int8(7),
  68447 	},
  68448 	301: {
  68449 		Fcode:       int8(16),
  68450 		Fextra_bits: int8(7),
  68451 	},
  68452 	302: {
  68453 		Fcode:       int8(16),
  68454 		Fextra_bits: int8(7),
  68455 	},
  68456 	303: {
  68457 		Fcode:       int8(16),
  68458 		Fextra_bits: int8(7),
  68459 	},
  68460 	304: {
  68461 		Fcode:       int8(16),
  68462 		Fextra_bits: int8(7),
  68463 	},
  68464 	305: {
  68465 		Fcode:       int8(16),
  68466 		Fextra_bits: int8(7),
  68467 	},
  68468 	306: {
  68469 		Fcode:       int8(16),
  68470 		Fextra_bits: int8(7),
  68471 	},
  68472 	307: {
  68473 		Fcode:       int8(16),
  68474 		Fextra_bits: int8(7),
  68475 	},
  68476 	308: {
  68477 		Fcode:       int8(16),
  68478 		Fextra_bits: int8(7),
  68479 	},
  68480 	309: {
  68481 		Fcode:       int8(16),
  68482 		Fextra_bits: int8(7),
  68483 	},
  68484 	310: {
  68485 		Fcode:       int8(16),
  68486 		Fextra_bits: int8(7),
  68487 	},
  68488 	311: {
  68489 		Fcode:       int8(16),
  68490 		Fextra_bits: int8(7),
  68491 	},
  68492 	312: {
  68493 		Fcode:       int8(16),
  68494 		Fextra_bits: int8(7),
  68495 	},
  68496 	313: {
  68497 		Fcode:       int8(16),
  68498 		Fextra_bits: int8(7),
  68499 	},
  68500 	314: {
  68501 		Fcode:       int8(16),
  68502 		Fextra_bits: int8(7),
  68503 	},
  68504 	315: {
  68505 		Fcode:       int8(16),
  68506 		Fextra_bits: int8(7),
  68507 	},
  68508 	316: {
  68509 		Fcode:       int8(16),
  68510 		Fextra_bits: int8(7),
  68511 	},
  68512 	317: {
  68513 		Fcode:       int8(16),
  68514 		Fextra_bits: int8(7),
  68515 	},
  68516 	318: {
  68517 		Fcode:       int8(16),
  68518 		Fextra_bits: int8(7),
  68519 	},
  68520 	319: {
  68521 		Fcode:       int8(16),
  68522 		Fextra_bits: int8(7),
  68523 	},
  68524 	320: {
  68525 		Fcode:       int8(16),
  68526 		Fextra_bits: int8(7),
  68527 	},
  68528 	321: {
  68529 		Fcode:       int8(16),
  68530 		Fextra_bits: int8(7),
  68531 	},
  68532 	322: {
  68533 		Fcode:       int8(16),
  68534 		Fextra_bits: int8(7),
  68535 	},
  68536 	323: {
  68537 		Fcode:       int8(16),
  68538 		Fextra_bits: int8(7),
  68539 	},
  68540 	324: {
  68541 		Fcode:       int8(16),
  68542 		Fextra_bits: int8(7),
  68543 	},
  68544 	325: {
  68545 		Fcode:       int8(16),
  68546 		Fextra_bits: int8(7),
  68547 	},
  68548 	326: {
  68549 		Fcode:       int8(16),
  68550 		Fextra_bits: int8(7),
  68551 	},
  68552 	327: {
  68553 		Fcode:       int8(16),
  68554 		Fextra_bits: int8(7),
  68555 	},
  68556 	328: {
  68557 		Fcode:       int8(16),
  68558 		Fextra_bits: int8(7),
  68559 	},
  68560 	329: {
  68561 		Fcode:       int8(16),
  68562 		Fextra_bits: int8(7),
  68563 	},
  68564 	330: {
  68565 		Fcode:       int8(16),
  68566 		Fextra_bits: int8(7),
  68567 	},
  68568 	331: {
  68569 		Fcode:       int8(16),
  68570 		Fextra_bits: int8(7),
  68571 	},
  68572 	332: {
  68573 		Fcode:       int8(16),
  68574 		Fextra_bits: int8(7),
  68575 	},
  68576 	333: {
  68577 		Fcode:       int8(16),
  68578 		Fextra_bits: int8(7),
  68579 	},
  68580 	334: {
  68581 		Fcode:       int8(16),
  68582 		Fextra_bits: int8(7),
  68583 	},
  68584 	335: {
  68585 		Fcode:       int8(16),
  68586 		Fextra_bits: int8(7),
  68587 	},
  68588 	336: {
  68589 		Fcode:       int8(16),
  68590 		Fextra_bits: int8(7),
  68591 	},
  68592 	337: {
  68593 		Fcode:       int8(16),
  68594 		Fextra_bits: int8(7),
  68595 	},
  68596 	338: {
  68597 		Fcode:       int8(16),
  68598 		Fextra_bits: int8(7),
  68599 	},
  68600 	339: {
  68601 		Fcode:       int8(16),
  68602 		Fextra_bits: int8(7),
  68603 	},
  68604 	340: {
  68605 		Fcode:       int8(16),
  68606 		Fextra_bits: int8(7),
  68607 	},
  68608 	341: {
  68609 		Fcode:       int8(16),
  68610 		Fextra_bits: int8(7),
  68611 	},
  68612 	342: {
  68613 		Fcode:       int8(16),
  68614 		Fextra_bits: int8(7),
  68615 	},
  68616 	343: {
  68617 		Fcode:       int8(16),
  68618 		Fextra_bits: int8(7),
  68619 	},
  68620 	344: {
  68621 		Fcode:       int8(16),
  68622 		Fextra_bits: int8(7),
  68623 	},
  68624 	345: {
  68625 		Fcode:       int8(16),
  68626 		Fextra_bits: int8(7),
  68627 	},
  68628 	346: {
  68629 		Fcode:       int8(16),
  68630 		Fextra_bits: int8(7),
  68631 	},
  68632 	347: {
  68633 		Fcode:       int8(16),
  68634 		Fextra_bits: int8(7),
  68635 	},
  68636 	348: {
  68637 		Fcode:       int8(16),
  68638 		Fextra_bits: int8(7),
  68639 	},
  68640 	349: {
  68641 		Fcode:       int8(16),
  68642 		Fextra_bits: int8(7),
  68643 	},
  68644 	350: {
  68645 		Fcode:       int8(16),
  68646 		Fextra_bits: int8(7),
  68647 	},
  68648 	351: {
  68649 		Fcode:       int8(16),
  68650 		Fextra_bits: int8(7),
  68651 	},
  68652 	352: {
  68653 		Fcode:       int8(16),
  68654 		Fextra_bits: int8(7),
  68655 	},
  68656 	353: {
  68657 		Fcode:       int8(16),
  68658 		Fextra_bits: int8(7),
  68659 	},
  68660 	354: {
  68661 		Fcode:       int8(16),
  68662 		Fextra_bits: int8(7),
  68663 	},
  68664 	355: {
  68665 		Fcode:       int8(16),
  68666 		Fextra_bits: int8(7),
  68667 	},
  68668 	356: {
  68669 		Fcode:       int8(16),
  68670 		Fextra_bits: int8(7),
  68671 	},
  68672 	357: {
  68673 		Fcode:       int8(16),
  68674 		Fextra_bits: int8(7),
  68675 	},
  68676 	358: {
  68677 		Fcode:       int8(16),
  68678 		Fextra_bits: int8(7),
  68679 	},
  68680 	359: {
  68681 		Fcode:       int8(16),
  68682 		Fextra_bits: int8(7),
  68683 	},
  68684 	360: {
  68685 		Fcode:       int8(16),
  68686 		Fextra_bits: int8(7),
  68687 	},
  68688 	361: {
  68689 		Fcode:       int8(16),
  68690 		Fextra_bits: int8(7),
  68691 	},
  68692 	362: {
  68693 		Fcode:       int8(16),
  68694 		Fextra_bits: int8(7),
  68695 	},
  68696 	363: {
  68697 		Fcode:       int8(16),
  68698 		Fextra_bits: int8(7),
  68699 	},
  68700 	364: {
  68701 		Fcode:       int8(16),
  68702 		Fextra_bits: int8(7),
  68703 	},
  68704 	365: {
  68705 		Fcode:       int8(16),
  68706 		Fextra_bits: int8(7),
  68707 	},
  68708 	366: {
  68709 		Fcode:       int8(16),
  68710 		Fextra_bits: int8(7),
  68711 	},
  68712 	367: {
  68713 		Fcode:       int8(16),
  68714 		Fextra_bits: int8(7),
  68715 	},
  68716 	368: {
  68717 		Fcode:       int8(16),
  68718 		Fextra_bits: int8(7),
  68719 	},
  68720 	369: {
  68721 		Fcode:       int8(16),
  68722 		Fextra_bits: int8(7),
  68723 	},
  68724 	370: {
  68725 		Fcode:       int8(16),
  68726 		Fextra_bits: int8(7),
  68727 	},
  68728 	371: {
  68729 		Fcode:       int8(16),
  68730 		Fextra_bits: int8(7),
  68731 	},
  68732 	372: {
  68733 		Fcode:       int8(16),
  68734 		Fextra_bits: int8(7),
  68735 	},
  68736 	373: {
  68737 		Fcode:       int8(16),
  68738 		Fextra_bits: int8(7),
  68739 	},
  68740 	374: {
  68741 		Fcode:       int8(16),
  68742 		Fextra_bits: int8(7),
  68743 	},
  68744 	375: {
  68745 		Fcode:       int8(16),
  68746 		Fextra_bits: int8(7),
  68747 	},
  68748 	376: {
  68749 		Fcode:       int8(16),
  68750 		Fextra_bits: int8(7),
  68751 	},
  68752 	377: {
  68753 		Fcode:       int8(16),
  68754 		Fextra_bits: int8(7),
  68755 	},
  68756 	378: {
  68757 		Fcode:       int8(16),
  68758 		Fextra_bits: int8(7),
  68759 	},
  68760 	379: {
  68761 		Fcode:       int8(16),
  68762 		Fextra_bits: int8(7),
  68763 	},
  68764 	380: {
  68765 		Fcode:       int8(16),
  68766 		Fextra_bits: int8(7),
  68767 	},
  68768 	381: {
  68769 		Fcode:       int8(16),
  68770 		Fextra_bits: int8(7),
  68771 	},
  68772 	382: {
  68773 		Fcode:       int8(16),
  68774 		Fextra_bits: int8(7),
  68775 	},
  68776 	383: {
  68777 		Fcode:       int8(16),
  68778 		Fextra_bits: int8(7),
  68779 	},
  68780 	384: {
  68781 		Fcode:       int8(16),
  68782 		Fextra_bits: int8(7),
  68783 	},
  68784 	385: {
  68785 		Fcode:       int8(17),
  68786 		Fextra_bits: int8(7),
  68787 	},
  68788 	386: {
  68789 		Fcode:       int8(17),
  68790 		Fextra_bits: int8(7),
  68791 	},
  68792 	387: {
  68793 		Fcode:       int8(17),
  68794 		Fextra_bits: int8(7),
  68795 	},
  68796 	388: {
  68797 		Fcode:       int8(17),
  68798 		Fextra_bits: int8(7),
  68799 	},
  68800 	389: {
  68801 		Fcode:       int8(17),
  68802 		Fextra_bits: int8(7),
  68803 	},
  68804 	390: {
  68805 		Fcode:       int8(17),
  68806 		Fextra_bits: int8(7),
  68807 	},
  68808 	391: {
  68809 		Fcode:       int8(17),
  68810 		Fextra_bits: int8(7),
  68811 	},
  68812 	392: {
  68813 		Fcode:       int8(17),
  68814 		Fextra_bits: int8(7),
  68815 	},
  68816 	393: {
  68817 		Fcode:       int8(17),
  68818 		Fextra_bits: int8(7),
  68819 	},
  68820 	394: {
  68821 		Fcode:       int8(17),
  68822 		Fextra_bits: int8(7),
  68823 	},
  68824 	395: {
  68825 		Fcode:       int8(17),
  68826 		Fextra_bits: int8(7),
  68827 	},
  68828 	396: {
  68829 		Fcode:       int8(17),
  68830 		Fextra_bits: int8(7),
  68831 	},
  68832 	397: {
  68833 		Fcode:       int8(17),
  68834 		Fextra_bits: int8(7),
  68835 	},
  68836 	398: {
  68837 		Fcode:       int8(17),
  68838 		Fextra_bits: int8(7),
  68839 	},
  68840 	399: {
  68841 		Fcode:       int8(17),
  68842 		Fextra_bits: int8(7),
  68843 	},
  68844 	400: {
  68845 		Fcode:       int8(17),
  68846 		Fextra_bits: int8(7),
  68847 	},
  68848 	401: {
  68849 		Fcode:       int8(17),
  68850 		Fextra_bits: int8(7),
  68851 	},
  68852 	402: {
  68853 		Fcode:       int8(17),
  68854 		Fextra_bits: int8(7),
  68855 	},
  68856 	403: {
  68857 		Fcode:       int8(17),
  68858 		Fextra_bits: int8(7),
  68859 	},
  68860 	404: {
  68861 		Fcode:       int8(17),
  68862 		Fextra_bits: int8(7),
  68863 	},
  68864 	405: {
  68865 		Fcode:       int8(17),
  68866 		Fextra_bits: int8(7),
  68867 	},
  68868 	406: {
  68869 		Fcode:       int8(17),
  68870 		Fextra_bits: int8(7),
  68871 	},
  68872 	407: {
  68873 		Fcode:       int8(17),
  68874 		Fextra_bits: int8(7),
  68875 	},
  68876 	408: {
  68877 		Fcode:       int8(17),
  68878 		Fextra_bits: int8(7),
  68879 	},
  68880 	409: {
  68881 		Fcode:       int8(17),
  68882 		Fextra_bits: int8(7),
  68883 	},
  68884 	410: {
  68885 		Fcode:       int8(17),
  68886 		Fextra_bits: int8(7),
  68887 	},
  68888 	411: {
  68889 		Fcode:       int8(17),
  68890 		Fextra_bits: int8(7),
  68891 	},
  68892 	412: {
  68893 		Fcode:       int8(17),
  68894 		Fextra_bits: int8(7),
  68895 	},
  68896 	413: {
  68897 		Fcode:       int8(17),
  68898 		Fextra_bits: int8(7),
  68899 	},
  68900 	414: {
  68901 		Fcode:       int8(17),
  68902 		Fextra_bits: int8(7),
  68903 	},
  68904 	415: {
  68905 		Fcode:       int8(17),
  68906 		Fextra_bits: int8(7),
  68907 	},
  68908 	416: {
  68909 		Fcode:       int8(17),
  68910 		Fextra_bits: int8(7),
  68911 	},
  68912 	417: {
  68913 		Fcode:       int8(17),
  68914 		Fextra_bits: int8(7),
  68915 	},
  68916 	418: {
  68917 		Fcode:       int8(17),
  68918 		Fextra_bits: int8(7),
  68919 	},
  68920 	419: {
  68921 		Fcode:       int8(17),
  68922 		Fextra_bits: int8(7),
  68923 	},
  68924 	420: {
  68925 		Fcode:       int8(17),
  68926 		Fextra_bits: int8(7),
  68927 	},
  68928 	421: {
  68929 		Fcode:       int8(17),
  68930 		Fextra_bits: int8(7),
  68931 	},
  68932 	422: {
  68933 		Fcode:       int8(17),
  68934 		Fextra_bits: int8(7),
  68935 	},
  68936 	423: {
  68937 		Fcode:       int8(17),
  68938 		Fextra_bits: int8(7),
  68939 	},
  68940 	424: {
  68941 		Fcode:       int8(17),
  68942 		Fextra_bits: int8(7),
  68943 	},
  68944 	425: {
  68945 		Fcode:       int8(17),
  68946 		Fextra_bits: int8(7),
  68947 	},
  68948 	426: {
  68949 		Fcode:       int8(17),
  68950 		Fextra_bits: int8(7),
  68951 	},
  68952 	427: {
  68953 		Fcode:       int8(17),
  68954 		Fextra_bits: int8(7),
  68955 	},
  68956 	428: {
  68957 		Fcode:       int8(17),
  68958 		Fextra_bits: int8(7),
  68959 	},
  68960 	429: {
  68961 		Fcode:       int8(17),
  68962 		Fextra_bits: int8(7),
  68963 	},
  68964 	430: {
  68965 		Fcode:       int8(17),
  68966 		Fextra_bits: int8(7),
  68967 	},
  68968 	431: {
  68969 		Fcode:       int8(17),
  68970 		Fextra_bits: int8(7),
  68971 	},
  68972 	432: {
  68973 		Fcode:       int8(17),
  68974 		Fextra_bits: int8(7),
  68975 	},
  68976 	433: {
  68977 		Fcode:       int8(17),
  68978 		Fextra_bits: int8(7),
  68979 	},
  68980 	434: {
  68981 		Fcode:       int8(17),
  68982 		Fextra_bits: int8(7),
  68983 	},
  68984 	435: {
  68985 		Fcode:       int8(17),
  68986 		Fextra_bits: int8(7),
  68987 	},
  68988 	436: {
  68989 		Fcode:       int8(17),
  68990 		Fextra_bits: int8(7),
  68991 	},
  68992 	437: {
  68993 		Fcode:       int8(17),
  68994 		Fextra_bits: int8(7),
  68995 	},
  68996 	438: {
  68997 		Fcode:       int8(17),
  68998 		Fextra_bits: int8(7),
  68999 	},
  69000 	439: {
  69001 		Fcode:       int8(17),
  69002 		Fextra_bits: int8(7),
  69003 	},
  69004 	440: {
  69005 		Fcode:       int8(17),
  69006 		Fextra_bits: int8(7),
  69007 	},
  69008 	441: {
  69009 		Fcode:       int8(17),
  69010 		Fextra_bits: int8(7),
  69011 	},
  69012 	442: {
  69013 		Fcode:       int8(17),
  69014 		Fextra_bits: int8(7),
  69015 	},
  69016 	443: {
  69017 		Fcode:       int8(17),
  69018 		Fextra_bits: int8(7),
  69019 	},
  69020 	444: {
  69021 		Fcode:       int8(17),
  69022 		Fextra_bits: int8(7),
  69023 	},
  69024 	445: {
  69025 		Fcode:       int8(17),
  69026 		Fextra_bits: int8(7),
  69027 	},
  69028 	446: {
  69029 		Fcode:       int8(17),
  69030 		Fextra_bits: int8(7),
  69031 	},
  69032 	447: {
  69033 		Fcode:       int8(17),
  69034 		Fextra_bits: int8(7),
  69035 	},
  69036 	448: {
  69037 		Fcode:       int8(17),
  69038 		Fextra_bits: int8(7),
  69039 	},
  69040 	449: {
  69041 		Fcode:       int8(17),
  69042 		Fextra_bits: int8(7),
  69043 	},
  69044 	450: {
  69045 		Fcode:       int8(17),
  69046 		Fextra_bits: int8(7),
  69047 	},
  69048 	451: {
  69049 		Fcode:       int8(17),
  69050 		Fextra_bits: int8(7),
  69051 	},
  69052 	452: {
  69053 		Fcode:       int8(17),
  69054 		Fextra_bits: int8(7),
  69055 	},
  69056 	453: {
  69057 		Fcode:       int8(17),
  69058 		Fextra_bits: int8(7),
  69059 	},
  69060 	454: {
  69061 		Fcode:       int8(17),
  69062 		Fextra_bits: int8(7),
  69063 	},
  69064 	455: {
  69065 		Fcode:       int8(17),
  69066 		Fextra_bits: int8(7),
  69067 	},
  69068 	456: {
  69069 		Fcode:       int8(17),
  69070 		Fextra_bits: int8(7),
  69071 	},
  69072 	457: {
  69073 		Fcode:       int8(17),
  69074 		Fextra_bits: int8(7),
  69075 	},
  69076 	458: {
  69077 		Fcode:       int8(17),
  69078 		Fextra_bits: int8(7),
  69079 	},
  69080 	459: {
  69081 		Fcode:       int8(17),
  69082 		Fextra_bits: int8(7),
  69083 	},
  69084 	460: {
  69085 		Fcode:       int8(17),
  69086 		Fextra_bits: int8(7),
  69087 	},
  69088 	461: {
  69089 		Fcode:       int8(17),
  69090 		Fextra_bits: int8(7),
  69091 	},
  69092 	462: {
  69093 		Fcode:       int8(17),
  69094 		Fextra_bits: int8(7),
  69095 	},
  69096 	463: {
  69097 		Fcode:       int8(17),
  69098 		Fextra_bits: int8(7),
  69099 	},
  69100 	464: {
  69101 		Fcode:       int8(17),
  69102 		Fextra_bits: int8(7),
  69103 	},
  69104 	465: {
  69105 		Fcode:       int8(17),
  69106 		Fextra_bits: int8(7),
  69107 	},
  69108 	466: {
  69109 		Fcode:       int8(17),
  69110 		Fextra_bits: int8(7),
  69111 	},
  69112 	467: {
  69113 		Fcode:       int8(17),
  69114 		Fextra_bits: int8(7),
  69115 	},
  69116 	468: {
  69117 		Fcode:       int8(17),
  69118 		Fextra_bits: int8(7),
  69119 	},
  69120 	469: {
  69121 		Fcode:       int8(17),
  69122 		Fextra_bits: int8(7),
  69123 	},
  69124 	470: {
  69125 		Fcode:       int8(17),
  69126 		Fextra_bits: int8(7),
  69127 	},
  69128 	471: {
  69129 		Fcode:       int8(17),
  69130 		Fextra_bits: int8(7),
  69131 	},
  69132 	472: {
  69133 		Fcode:       int8(17),
  69134 		Fextra_bits: int8(7),
  69135 	},
  69136 	473: {
  69137 		Fcode:       int8(17),
  69138 		Fextra_bits: int8(7),
  69139 	},
  69140 	474: {
  69141 		Fcode:       int8(17),
  69142 		Fextra_bits: int8(7),
  69143 	},
  69144 	475: {
  69145 		Fcode:       int8(17),
  69146 		Fextra_bits: int8(7),
  69147 	},
  69148 	476: {
  69149 		Fcode:       int8(17),
  69150 		Fextra_bits: int8(7),
  69151 	},
  69152 	477: {
  69153 		Fcode:       int8(17),
  69154 		Fextra_bits: int8(7),
  69155 	},
  69156 	478: {
  69157 		Fcode:       int8(17),
  69158 		Fextra_bits: int8(7),
  69159 	},
  69160 	479: {
  69161 		Fcode:       int8(17),
  69162 		Fextra_bits: int8(7),
  69163 	},
  69164 	480: {
  69165 		Fcode:       int8(17),
  69166 		Fextra_bits: int8(7),
  69167 	},
  69168 	481: {
  69169 		Fcode:       int8(17),
  69170 		Fextra_bits: int8(7),
  69171 	},
  69172 	482: {
  69173 		Fcode:       int8(17),
  69174 		Fextra_bits: int8(7),
  69175 	},
  69176 	483: {
  69177 		Fcode:       int8(17),
  69178 		Fextra_bits: int8(7),
  69179 	},
  69180 	484: {
  69181 		Fcode:       int8(17),
  69182 		Fextra_bits: int8(7),
  69183 	},
  69184 	485: {
  69185 		Fcode:       int8(17),
  69186 		Fextra_bits: int8(7),
  69187 	},
  69188 	486: {
  69189 		Fcode:       int8(17),
  69190 		Fextra_bits: int8(7),
  69191 	},
  69192 	487: {
  69193 		Fcode:       int8(17),
  69194 		Fextra_bits: int8(7),
  69195 	},
  69196 	488: {
  69197 		Fcode:       int8(17),
  69198 		Fextra_bits: int8(7),
  69199 	},
  69200 	489: {
  69201 		Fcode:       int8(17),
  69202 		Fextra_bits: int8(7),
  69203 	},
  69204 	490: {
  69205 		Fcode:       int8(17),
  69206 		Fextra_bits: int8(7),
  69207 	},
  69208 	491: {
  69209 		Fcode:       int8(17),
  69210 		Fextra_bits: int8(7),
  69211 	},
  69212 	492: {
  69213 		Fcode:       int8(17),
  69214 		Fextra_bits: int8(7),
  69215 	},
  69216 	493: {
  69217 		Fcode:       int8(17),
  69218 		Fextra_bits: int8(7),
  69219 	},
  69220 	494: {
  69221 		Fcode:       int8(17),
  69222 		Fextra_bits: int8(7),
  69223 	},
  69224 	495: {
  69225 		Fcode:       int8(17),
  69226 		Fextra_bits: int8(7),
  69227 	},
  69228 	496: {
  69229 		Fcode:       int8(17),
  69230 		Fextra_bits: int8(7),
  69231 	},
  69232 	497: {
  69233 		Fcode:       int8(17),
  69234 		Fextra_bits: int8(7),
  69235 	},
  69236 	498: {
  69237 		Fcode:       int8(17),
  69238 		Fextra_bits: int8(7),
  69239 	},
  69240 	499: {
  69241 		Fcode:       int8(17),
  69242 		Fextra_bits: int8(7),
  69243 	},
  69244 	500: {
  69245 		Fcode:       int8(17),
  69246 		Fextra_bits: int8(7),
  69247 	},
  69248 	501: {
  69249 		Fcode:       int8(17),
  69250 		Fextra_bits: int8(7),
  69251 	},
  69252 	502: {
  69253 		Fcode:       int8(17),
  69254 		Fextra_bits: int8(7),
  69255 	},
  69256 	503: {
  69257 		Fcode:       int8(17),
  69258 		Fextra_bits: int8(7),
  69259 	},
  69260 	504: {
  69261 		Fcode:       int8(17),
  69262 		Fextra_bits: int8(7),
  69263 	},
  69264 	505: {
  69265 		Fcode:       int8(17),
  69266 		Fextra_bits: int8(7),
  69267 	},
  69268 	506: {
  69269 		Fcode:       int8(17),
  69270 		Fextra_bits: int8(7),
  69271 	},
  69272 	507: {
  69273 		Fcode:       int8(17),
  69274 		Fextra_bits: int8(7),
  69275 	},
  69276 	508: {
  69277 		Fcode:       int8(17),
  69278 		Fextra_bits: int8(7),
  69279 	},
  69280 	509: {
  69281 		Fcode:       int8(17),
  69282 		Fextra_bits: int8(7),
  69283 	},
  69284 	510: {
  69285 		Fcode:       int8(17),
  69286 		Fextra_bits: int8(7),
  69287 	},
  69288 	511: {
  69289 		Fcode:       int8(17),
  69290 		Fextra_bits: int8(7),
  69291 	},
  69292 }
  69293 
  69294 var kPrefixEncodeExtraBitsValue = [512]uint8_t{
  69295 	6:   uint8(1),
  69296 	8:   uint8(1),
  69297 	10:  uint8(1),
  69298 	11:  uint8(2),
  69299 	12:  uint8(3),
  69300 	14:  uint8(1),
  69301 	15:  uint8(2),
  69302 	16:  uint8(3),
  69303 	18:  uint8(1),
  69304 	19:  uint8(2),
  69305 	20:  uint8(3),
  69306 	21:  uint8(4),
  69307 	22:  uint8(5),
  69308 	23:  uint8(6),
  69309 	24:  uint8(7),
  69310 	26:  uint8(1),
  69311 	27:  uint8(2),
  69312 	28:  uint8(3),
  69313 	29:  uint8(4),
  69314 	30:  uint8(5),
  69315 	31:  uint8(6),
  69316 	32:  uint8(7),
  69317 	34:  uint8(1),
  69318 	35:  uint8(2),
  69319 	36:  uint8(3),
  69320 	37:  uint8(4),
  69321 	38:  uint8(5),
  69322 	39:  uint8(6),
  69323 	40:  uint8(7),
  69324 	41:  uint8(8),
  69325 	42:  uint8(9),
  69326 	43:  uint8(10),
  69327 	44:  uint8(11),
  69328 	45:  uint8(12),
  69329 	46:  uint8(13),
  69330 	47:  uint8(14),
  69331 	48:  uint8(15),
  69332 	50:  uint8(1),
  69333 	51:  uint8(2),
  69334 	52:  uint8(3),
  69335 	53:  uint8(4),
  69336 	54:  uint8(5),
  69337 	55:  uint8(6),
  69338 	56:  uint8(7),
  69339 	57:  uint8(8),
  69340 	58:  uint8(9),
  69341 	59:  uint8(10),
  69342 	60:  uint8(11),
  69343 	61:  uint8(12),
  69344 	62:  uint8(13),
  69345 	63:  uint8(14),
  69346 	64:  uint8(15),
  69347 	66:  uint8(1),
  69348 	67:  uint8(2),
  69349 	68:  uint8(3),
  69350 	69:  uint8(4),
  69351 	70:  uint8(5),
  69352 	71:  uint8(6),
  69353 	72:  uint8(7),
  69354 	73:  uint8(8),
  69355 	74:  uint8(9),
  69356 	75:  uint8(10),
  69357 	76:  uint8(11),
  69358 	77:  uint8(12),
  69359 	78:  uint8(13),
  69360 	79:  uint8(14),
  69361 	80:  uint8(15),
  69362 	81:  uint8(16),
  69363 	82:  uint8(17),
  69364 	83:  uint8(18),
  69365 	84:  uint8(19),
  69366 	85:  uint8(20),
  69367 	86:  uint8(21),
  69368 	87:  uint8(22),
  69369 	88:  uint8(23),
  69370 	89:  uint8(24),
  69371 	90:  uint8(25),
  69372 	91:  uint8(26),
  69373 	92:  uint8(27),
  69374 	93:  uint8(28),
  69375 	94:  uint8(29),
  69376 	95:  uint8(30),
  69377 	96:  uint8(31),
  69378 	98:  uint8(1),
  69379 	99:  uint8(2),
  69380 	100: uint8(3),
  69381 	101: uint8(4),
  69382 	102: uint8(5),
  69383 	103: uint8(6),
  69384 	104: uint8(7),
  69385 	105: uint8(8),
  69386 	106: uint8(9),
  69387 	107: uint8(10),
  69388 	108: uint8(11),
  69389 	109: uint8(12),
  69390 	110: uint8(13),
  69391 	111: uint8(14),
  69392 	112: uint8(15),
  69393 	113: uint8(16),
  69394 	114: uint8(17),
  69395 	115: uint8(18),
  69396 	116: uint8(19),
  69397 	117: uint8(20),
  69398 	118: uint8(21),
  69399 	119: uint8(22),
  69400 	120: uint8(23),
  69401 	121: uint8(24),
  69402 	122: uint8(25),
  69403 	123: uint8(26),
  69404 	124: uint8(27),
  69405 	125: uint8(28),
  69406 	126: uint8(29),
  69407 	127: uint8(30),
  69408 	128: uint8(31),
  69409 	130: uint8(1),
  69410 	131: uint8(2),
  69411 	132: uint8(3),
  69412 	133: uint8(4),
  69413 	134: uint8(5),
  69414 	135: uint8(6),
  69415 	136: uint8(7),
  69416 	137: uint8(8),
  69417 	138: uint8(9),
  69418 	139: uint8(10),
  69419 	140: uint8(11),
  69420 	141: uint8(12),
  69421 	142: uint8(13),
  69422 	143: uint8(14),
  69423 	144: uint8(15),
  69424 	145: uint8(16),
  69425 	146: uint8(17),
  69426 	147: uint8(18),
  69427 	148: uint8(19),
  69428 	149: uint8(20),
  69429 	150: uint8(21),
  69430 	151: uint8(22),
  69431 	152: uint8(23),
  69432 	153: uint8(24),
  69433 	154: uint8(25),
  69434 	155: uint8(26),
  69435 	156: uint8(27),
  69436 	157: uint8(28),
  69437 	158: uint8(29),
  69438 	159: uint8(30),
  69439 	160: uint8(31),
  69440 	161: uint8(32),
  69441 	162: uint8(33),
  69442 	163: uint8(34),
  69443 	164: uint8(35),
  69444 	165: uint8(36),
  69445 	166: uint8(37),
  69446 	167: uint8(38),
  69447 	168: uint8(39),
  69448 	169: uint8(40),
  69449 	170: uint8(41),
  69450 	171: uint8(42),
  69451 	172: uint8(43),
  69452 	173: uint8(44),
  69453 	174: uint8(45),
  69454 	175: uint8(46),
  69455 	176: uint8(47),
  69456 	177: uint8(48),
  69457 	178: uint8(49),
  69458 	179: uint8(50),
  69459 	180: uint8(51),
  69460 	181: uint8(52),
  69461 	182: uint8(53),
  69462 	183: uint8(54),
  69463 	184: uint8(55),
  69464 	185: uint8(56),
  69465 	186: uint8(57),
  69466 	187: uint8(58),
  69467 	188: uint8(59),
  69468 	189: uint8(60),
  69469 	190: uint8(61),
  69470 	191: uint8(62),
  69471 	192: uint8(63),
  69472 	194: uint8(1),
  69473 	195: uint8(2),
  69474 	196: uint8(3),
  69475 	197: uint8(4),
  69476 	198: uint8(5),
  69477 	199: uint8(6),
  69478 	200: uint8(7),
  69479 	201: uint8(8),
  69480 	202: uint8(9),
  69481 	203: uint8(10),
  69482 	204: uint8(11),
  69483 	205: uint8(12),
  69484 	206: uint8(13),
  69485 	207: uint8(14),
  69486 	208: uint8(15),
  69487 	209: uint8(16),
  69488 	210: uint8(17),
  69489 	211: uint8(18),
  69490 	212: uint8(19),
  69491 	213: uint8(20),
  69492 	214: uint8(21),
  69493 	215: uint8(22),
  69494 	216: uint8(23),
  69495 	217: uint8(24),
  69496 	218: uint8(25),
  69497 	219: uint8(26),
  69498 	220: uint8(27),
  69499 	221: uint8(28),
  69500 	222: uint8(29),
  69501 	223: uint8(30),
  69502 	224: uint8(31),
  69503 	225: uint8(32),
  69504 	226: uint8(33),
  69505 	227: uint8(34),
  69506 	228: uint8(35),
  69507 	229: uint8(36),
  69508 	230: uint8(37),
  69509 	231: uint8(38),
  69510 	232: uint8(39),
  69511 	233: uint8(40),
  69512 	234: uint8(41),
  69513 	235: uint8(42),
  69514 	236: uint8(43),
  69515 	237: uint8(44),
  69516 	238: uint8(45),
  69517 	239: uint8(46),
  69518 	240: uint8(47),
  69519 	241: uint8(48),
  69520 	242: uint8(49),
  69521 	243: uint8(50),
  69522 	244: uint8(51),
  69523 	245: uint8(52),
  69524 	246: uint8(53),
  69525 	247: uint8(54),
  69526 	248: uint8(55),
  69527 	249: uint8(56),
  69528 	250: uint8(57),
  69529 	251: uint8(58),
  69530 	252: uint8(59),
  69531 	253: uint8(60),
  69532 	254: uint8(61),
  69533 	255: uint8(62),
  69534 	256: uint8(63),
  69535 	258: uint8(1),
  69536 	259: uint8(2),
  69537 	260: uint8(3),
  69538 	261: uint8(4),
  69539 	262: uint8(5),
  69540 	263: uint8(6),
  69541 	264: uint8(7),
  69542 	265: uint8(8),
  69543 	266: uint8(9),
  69544 	267: uint8(10),
  69545 	268: uint8(11),
  69546 	269: uint8(12),
  69547 	270: uint8(13),
  69548 	271: uint8(14),
  69549 	272: uint8(15),
  69550 	273: uint8(16),
  69551 	274: uint8(17),
  69552 	275: uint8(18),
  69553 	276: uint8(19),
  69554 	277: uint8(20),
  69555 	278: uint8(21),
  69556 	279: uint8(22),
  69557 	280: uint8(23),
  69558 	281: uint8(24),
  69559 	282: uint8(25),
  69560 	283: uint8(26),
  69561 	284: uint8(27),
  69562 	285: uint8(28),
  69563 	286: uint8(29),
  69564 	287: uint8(30),
  69565 	288: uint8(31),
  69566 	289: uint8(32),
  69567 	290: uint8(33),
  69568 	291: uint8(34),
  69569 	292: uint8(35),
  69570 	293: uint8(36),
  69571 	294: uint8(37),
  69572 	295: uint8(38),
  69573 	296: uint8(39),
  69574 	297: uint8(40),
  69575 	298: uint8(41),
  69576 	299: uint8(42),
  69577 	300: uint8(43),
  69578 	301: uint8(44),
  69579 	302: uint8(45),
  69580 	303: uint8(46),
  69581 	304: uint8(47),
  69582 	305: uint8(48),
  69583 	306: uint8(49),
  69584 	307: uint8(50),
  69585 	308: uint8(51),
  69586 	309: uint8(52),
  69587 	310: uint8(53),
  69588 	311: uint8(54),
  69589 	312: uint8(55),
  69590 	313: uint8(56),
  69591 	314: uint8(57),
  69592 	315: uint8(58),
  69593 	316: uint8(59),
  69594 	317: uint8(60),
  69595 	318: uint8(61),
  69596 	319: uint8(62),
  69597 	320: uint8(63),
  69598 	321: uint8(64),
  69599 	322: uint8(65),
  69600 	323: uint8(66),
  69601 	324: uint8(67),
  69602 	325: uint8(68),
  69603 	326: uint8(69),
  69604 	327: uint8(70),
  69605 	328: uint8(71),
  69606 	329: uint8(72),
  69607 	330: uint8(73),
  69608 	331: uint8(74),
  69609 	332: uint8(75),
  69610 	333: uint8(76),
  69611 	334: uint8(77),
  69612 	335: uint8(78),
  69613 	336: uint8(79),
  69614 	337: uint8(80),
  69615 	338: uint8(81),
  69616 	339: uint8(82),
  69617 	340: uint8(83),
  69618 	341: uint8(84),
  69619 	342: uint8(85),
  69620 	343: uint8(86),
  69621 	344: uint8(87),
  69622 	345: uint8(88),
  69623 	346: uint8(89),
  69624 	347: uint8(90),
  69625 	348: uint8(91),
  69626 	349: uint8(92),
  69627 	350: uint8(93),
  69628 	351: uint8(94),
  69629 	352: uint8(95),
  69630 	353: uint8(96),
  69631 	354: uint8(97),
  69632 	355: uint8(98),
  69633 	356: uint8(99),
  69634 	357: uint8(100),
  69635 	358: uint8(101),
  69636 	359: uint8(102),
  69637 	360: uint8(103),
  69638 	361: uint8(104),
  69639 	362: uint8(105),
  69640 	363: uint8(106),
  69641 	364: uint8(107),
  69642 	365: uint8(108),
  69643 	366: uint8(109),
  69644 	367: uint8(110),
  69645 	368: uint8(111),
  69646 	369: uint8(112),
  69647 	370: uint8(113),
  69648 	371: uint8(114),
  69649 	372: uint8(115),
  69650 	373: uint8(116),
  69651 	374: uint8(117),
  69652 	375: uint8(118),
  69653 	376: uint8(119),
  69654 	377: uint8(120),
  69655 	378: uint8(121),
  69656 	379: uint8(122),
  69657 	380: uint8(123),
  69658 	381: uint8(124),
  69659 	382: uint8(125),
  69660 	383: uint8(126),
  69661 	384: uint8(127),
  69662 	386: uint8(1),
  69663 	387: uint8(2),
  69664 	388: uint8(3),
  69665 	389: uint8(4),
  69666 	390: uint8(5),
  69667 	391: uint8(6),
  69668 	392: uint8(7),
  69669 	393: uint8(8),
  69670 	394: uint8(9),
  69671 	395: uint8(10),
  69672 	396: uint8(11),
  69673 	397: uint8(12),
  69674 	398: uint8(13),
  69675 	399: uint8(14),
  69676 	400: uint8(15),
  69677 	401: uint8(16),
  69678 	402: uint8(17),
  69679 	403: uint8(18),
  69680 	404: uint8(19),
  69681 	405: uint8(20),
  69682 	406: uint8(21),
  69683 	407: uint8(22),
  69684 	408: uint8(23),
  69685 	409: uint8(24),
  69686 	410: uint8(25),
  69687 	411: uint8(26),
  69688 	412: uint8(27),
  69689 	413: uint8(28),
  69690 	414: uint8(29),
  69691 	415: uint8(30),
  69692 	416: uint8(31),
  69693 	417: uint8(32),
  69694 	418: uint8(33),
  69695 	419: uint8(34),
  69696 	420: uint8(35),
  69697 	421: uint8(36),
  69698 	422: uint8(37),
  69699 	423: uint8(38),
  69700 	424: uint8(39),
  69701 	425: uint8(40),
  69702 	426: uint8(41),
  69703 	427: uint8(42),
  69704 	428: uint8(43),
  69705 	429: uint8(44),
  69706 	430: uint8(45),
  69707 	431: uint8(46),
  69708 	432: uint8(47),
  69709 	433: uint8(48),
  69710 	434: uint8(49),
  69711 	435: uint8(50),
  69712 	436: uint8(51),
  69713 	437: uint8(52),
  69714 	438: uint8(53),
  69715 	439: uint8(54),
  69716 	440: uint8(55),
  69717 	441: uint8(56),
  69718 	442: uint8(57),
  69719 	443: uint8(58),
  69720 	444: uint8(59),
  69721 	445: uint8(60),
  69722 	446: uint8(61),
  69723 	447: uint8(62),
  69724 	448: uint8(63),
  69725 	449: uint8(64),
  69726 	450: uint8(65),
  69727 	451: uint8(66),
  69728 	452: uint8(67),
  69729 	453: uint8(68),
  69730 	454: uint8(69),
  69731 	455: uint8(70),
  69732 	456: uint8(71),
  69733 	457: uint8(72),
  69734 	458: uint8(73),
  69735 	459: uint8(74),
  69736 	460: uint8(75),
  69737 	461: uint8(76),
  69738 	462: uint8(77),
  69739 	463: uint8(78),
  69740 	464: uint8(79),
  69741 	465: uint8(80),
  69742 	466: uint8(81),
  69743 	467: uint8(82),
  69744 	468: uint8(83),
  69745 	469: uint8(84),
  69746 	470: uint8(85),
  69747 	471: uint8(86),
  69748 	472: uint8(87),
  69749 	473: uint8(88),
  69750 	474: uint8(89),
  69751 	475: uint8(90),
  69752 	476: uint8(91),
  69753 	477: uint8(92),
  69754 	478: uint8(93),
  69755 	479: uint8(94),
  69756 	480: uint8(95),
  69757 	481: uint8(96),
  69758 	482: uint8(97),
  69759 	483: uint8(98),
  69760 	484: uint8(99),
  69761 	485: uint8(100),
  69762 	486: uint8(101),
  69763 	487: uint8(102),
  69764 	488: uint8(103),
  69765 	489: uint8(104),
  69766 	490: uint8(105),
  69767 	491: uint8(106),
  69768 	492: uint8(107),
  69769 	493: uint8(108),
  69770 	494: uint8(109),
  69771 	495: uint8(110),
  69772 	496: uint8(111),
  69773 	497: uint8(112),
  69774 	498: uint8(113),
  69775 	499: uint8(114),
  69776 	500: uint8(115),
  69777 	501: uint8(116),
  69778 	502: uint8(117),
  69779 	503: uint8(118),
  69780 	504: uint8(119),
  69781 	505: uint8(120),
  69782 	506: uint8(121),
  69783 	507: uint8(122),
  69784 	508: uint8(123),
  69785 	509: uint8(124),
  69786 	510: uint8(125),
  69787 	511: uint8(126),
  69788 }
  69789 
  69790 // C documentation
  69791 //
  69792 //	// lookup table for small values of int*log2(int) * (1 << LOG_2_PRECISION_BITS).
  69793 //	// Obtained in Python with:
  69794 //	// a=[ "%d"%i if i<(1<<32) else "%dull"%i
  69795 //	//     for i in [ round((1<<LOG_2_PRECISION_BITS)*math.log2(i)*i) if i
  69796 //	//     else 0 for i in range(256)]]
  69797 //	// print(',\n '.join([','.join(v) for v in batched([i.rjust(15)
  69798 //	//                      for i in a],4)]))
  69799 var kSLog2Table = [256]uint64_t{
  69800 	2:   uint64(16777216),
  69801 	3:   uint64(39886887),
  69802 	4:   uint64(67108864),
  69803 	5:   uint64(97388723),
  69804 	6:   uint64(130105423),
  69805 	7:   uint64(164848600),
  69806 	8:   uint64(201326592),
  69807 	9:   uint64(239321324),
  69808 	10:  uint64(278663526),
  69809 	11:  uint64(319217973),
  69810 	12:  uint64(360874141),
  69811 	13:  uint64(403539997),
  69812 	14:  uint64(447137711),
  69813 	15:  uint64(491600606),
  69814 	16:  uint64(536870912),
  69815 	17:  uint64(582898099),
  69816 	18:  uint64(629637592),
  69817 	19:  uint64(677049776),
  69818 	20:  uint64(725099212),
  69819 	21:  uint64(773754010),
  69820 	22:  uint64(822985323),
  69821 	23:  uint64(872766924),
  69822 	24:  uint64(923074875),
  69823 	25:  uint64(973887230),
  69824 	26:  uint64(1025183802),
  69825 	27:  uint64(1076945958),
  69826 	28:  uint64(1129156447),
  69827 	29:  uint64(1181799249),
  69828 	30:  uint64(1234859451),
  69829 	31:  uint64(1288323135),
  69830 	32:  uint64(1342177280),
  69831 	33:  uint64(1396409681),
  69832 	34:  uint64(1451008871),
  69833 	35:  uint64(1505964059),
  69834 	36:  uint64(1561265072),
  69835 	37:  uint64(1616902301),
  69836 	38:  uint64(1672866655),
  69837 	39:  uint64(1729149526),
  69838 	40:  uint64(1785742744),
  69839 	41:  uint64(1842638548),
  69840 	42:  uint64(1899829557),
  69841 	43:  uint64(1957308741),
  69842 	44:  uint64(2015069397),
  69843 	45:  uint64(2073105127),
  69844 	46:  uint64(2131409817),
  69845 	47:  uint64(2189977618),
  69846 	48:  uint64(2248802933),
  69847 	49:  uint64(2307880396),
  69848 	50:  uint64(2367204859),
  69849 	51:  uint64(2426771383),
  69850 	52:  uint64(2486575220),
  69851 	53:  uint64(2546611805),
  69852 	54:  uint64(2606876748),
  69853 	55:  uint64(2667365819),
  69854 	56:  uint64(2728074942),
  69855 	57:  uint64(2789000187),
  69856 	58:  uint64(2850137762),
  69857 	59:  uint64(2911484006),
  69858 	60:  uint64(2973035382),
  69859 	61:  uint64(3034788471),
  69860 	62:  uint64(3096739966),
  69861 	63:  uint64(3158886666),
  69862 	64:  uint64(3221225472),
  69863 	65:  uint64(3283753383),
  69864 	66:  uint64(3346467489),
  69865 	67:  uint64(3409364969),
  69866 	68:  uint64(3472443085),
  69867 	69:  uint64(3535699182),
  69868 	70:  uint64(3599130679),
  69869 	71:  uint64(3662735070),
  69870 	72:  uint64(3726509920),
  69871 	73:  uint64(3790452862),
  69872 	74:  uint64(3854561593),
  69873 	75:  uint64(3918833872),
  69874 	76:  uint64(3983267519),
  69875 	77:  uint64(4047860410),
  69876 	78:  uint64(4112610476),
  69877 	79:  uint64(4177515704),
  69878 	80:  uint64(4242574127),
  69879 	81:  uint64(4307783833),
  69880 	82:  uint64(4373142952),
  69881 	83:  uint64(4438649662),
  69882 	84:  uint64(4504302186),
  69883 	85:  uint64(4570098787),
  69884 	86:  uint64(4636037770),
  69885 	87:  uint64(4702117480),
  69886 	88:  uint64(4768336298),
  69887 	89:  uint64(4834692645),
  69888 	90:  uint64(4901184974),
  69889 	91:  uint64(4967811774),
  69890 	92:  uint64(5034571569),
  69891 	93:  uint64(5101462912),
  69892 	94:  uint64(5168484389),
  69893 	95:  uint64(5235634615),
  69894 	96:  uint64(5302912235),
  69895 	97:  uint64(5370315922),
  69896 	98:  uint64(5437844376),
  69897 	99:  uint64(5505496324),
  69898 	100: uint64(5573270518),
  69899 	101: uint64(5641165737),
  69900 	102: uint64(5709180782),
  69901 	103: uint64(5777314477),
  69902 	104: uint64(5845565671),
  69903 	105: uint64(5913933235),
  69904 	106: uint64(5982416059),
  69905 	107: uint64(6051013057),
  69906 	108: uint64(6119723161),
  69907 	109: uint64(6188545324),
  69908 	110: uint64(6257478518),
  69909 	111: uint64(6326521733),
  69910 	112: uint64(6395673979),
  69911 	113: uint64(6464934282),
  69912 	114: uint64(6534301685),
  69913 	115: uint64(6603775250),
  69914 	116: uint64(6673354052),
  69915 	117: uint64(6743037185),
  69916 	118: uint64(6812823756),
  69917 	119: uint64(6882712890),
  69918 	120: uint64(6952703725),
  69919 	121: uint64(7022795412),
  69920 	122: uint64(7092987118),
  69921 	123: uint64(7163278025),
  69922 	124: uint64(7233667324),
  69923 	125: uint64(7304154222),
  69924 	126: uint64(7374737939),
  69925 	127: uint64(7445417707),
  69926 	128: uint64(7516192768),
  69927 	129: uint64(7587062379),
  69928 	130: uint64(7658025806),
  69929 	131: uint64(7729082328),
  69930 	132: uint64(7800231234),
  69931 	133: uint64(7871471825),
  69932 	134: uint64(7942803410),
  69933 	135: uint64(8014225311),
  69934 	136: uint64(8085736859),
  69935 	137: uint64(8157337394),
  69936 	138: uint64(8229026267),
  69937 	139: uint64(8300802839),
  69938 	140: uint64(8372666477),
  69939 	141: uint64(8444616560),
  69940 	142: uint64(8516652476),
  69941 	143: uint64(8588773618),
  69942 	144: uint64(8660979393),
  69943 	145: uint64(8733269211),
  69944 	146: uint64(8805642493),
  69945 	147: uint64(8878098667),
  69946 	148: uint64(8950637170),
  69947 	149: uint64(9023257446),
  69948 	150: uint64(9095958945),
  69949 	151: uint64(9168741125),
  69950 	152: uint64(9241603454),
  69951 	153: uint64(9314545403),
  69952 	154: uint64(9387566451),
  69953 	155: uint64(9460666086),
  69954 	156: uint64(9533843800),
  69955 	157: uint64(9607099093),
  69956 	158: uint64(9680431471),
  69957 	159: uint64(9753840445),
  69958 	160: uint64(9827325535),
  69959 	161: uint64(9900886263),
  69960 	162: uint64(9974522161),
  69961 	163: uint64(10048232765),
  69962 	164: uint64(10122017615),
  69963 	165: uint64(10195876260),
  69964 	166: uint64(10269808253),
  69965 	167: uint64(10343813150),
  69966 	168: uint64(10417890516),
  69967 	169: uint64(10492039919),
  69968 	170: uint64(10566260934),
  69969 	171: uint64(10640553138),
  69970 	172: uint64(10714916116),
  69971 	173: uint64(10789349456),
  69972 	174: uint64(10863852751),
  69973 	175: uint64(10938425600),
  69974 	176: uint64(11013067604),
  69975 	177: uint64(11087778372),
  69976 	178: uint64(11162557513),
  69977 	179: uint64(11237404645),
  69978 	180: uint64(11312319387),
  69979 	181: uint64(11387301364),
  69980 	182: uint64(11462350205),
  69981 	183: uint64(11537465541),
  69982 	184: uint64(11612647010),
  69983 	185: uint64(11687894253),
  69984 	186: uint64(11763206912),
  69985 	187: uint64(11838584638),
  69986 	188: uint64(11914027082),
  69987 	189: uint64(11989533899),
  69988 	190: uint64(12065104750),
  69989 	191: uint64(12140739296),
  69990 	192: uint64(12216437206),
  69991 	193: uint64(12292198148),
  69992 	194: uint64(12368021795),
  69993 	195: uint64(12443907826),
  69994 	196: uint64(12519855920),
  69995 	197: uint64(12595865759),
  69996 	198: uint64(12671937032),
  69997 	199: uint64(12748069427),
  69998 	200: uint64(12824262637),
  69999 	201: uint64(12900516358),
  70000 	202: uint64(12976830290),
  70001 	203: uint64(13053204134),
  70002 	204: uint64(13129637595),
  70003 	205: uint64(13206130381),
  70004 	206: uint64(13282682202),
  70005 	207: uint64(13359292772),
  70006 	208: uint64(13435961806),
  70007 	209: uint64(13512689025),
  70008 	210: uint64(13589474149),
  70009 	211: uint64(13666316903),
  70010 	212: uint64(13743217014),
  70011 	213: uint64(13820174211),
  70012 	214: uint64(13897188225),
  70013 	215: uint64(13974258793),
  70014 	216: uint64(14051385649),
  70015 	217: uint64(14128568535),
  70016 	218: uint64(14205807192),
  70017 	219: uint64(14283101363),
  70018 	220: uint64(14360450796),
  70019 	221: uint64(14437855239),
  70020 	222: uint64(14515314443),
  70021 	223: uint64(14592828162),
  70022 	224: uint64(14670396151),
  70023 	225: uint64(14748018167),
  70024 	226: uint64(14825693972),
  70025 	227: uint64(14903423326),
  70026 	228: uint64(14981205995),
  70027 	229: uint64(15059041743),
  70028 	230: uint64(15136930339),
  70029 	231: uint64(15214871554),
  70030 	232: uint64(15292865160),
  70031 	233: uint64(15370910930),
  70032 	234: uint64(15449008641),
  70033 	235: uint64(15527158071),
  70034 	236: uint64(15605359001),
  70035 	237: uint64(15683611210),
  70036 	238: uint64(15761914485),
  70037 	239: uint64(15840268608),
  70038 	240: uint64(15918673369),
  70039 	241: uint64(15997128556),
  70040 	242: uint64(16075633960),
  70041 	243: uint64(16154189373),
  70042 	244: uint64(16232794589),
  70043 	245: uint64(16311449405),
  70044 	246: uint64(16390153617),
  70045 	247: uint64(16468907026),
  70046 	248: uint64(16547709431),
  70047 	249: uint64(16626560636),
  70048 	250: uint64(16705460444),
  70049 	251: uint64(16784408661),
  70050 	252: uint64(16863405094),
  70051 	253: uint64(16942449552),
  70052 	254: uint64(17021541845),
  70053 	255: uint64(17100681785),
  70054 }
  70055 
  70056 var kVP8Log2Range = [128]uint8_t{
  70057 	0:   uint8(7),
  70058 	1:   uint8(6),
  70059 	2:   uint8(6),
  70060 	3:   uint8(5),
  70061 	4:   uint8(5),
  70062 	5:   uint8(5),
  70063 	6:   uint8(5),
  70064 	7:   uint8(4),
  70065 	8:   uint8(4),
  70066 	9:   uint8(4),
  70067 	10:  uint8(4),
  70068 	11:  uint8(4),
  70069 	12:  uint8(4),
  70070 	13:  uint8(4),
  70071 	14:  uint8(4),
  70072 	15:  uint8(3),
  70073 	16:  uint8(3),
  70074 	17:  uint8(3),
  70075 	18:  uint8(3),
  70076 	19:  uint8(3),
  70077 	20:  uint8(3),
  70078 	21:  uint8(3),
  70079 	22:  uint8(3),
  70080 	23:  uint8(3),
  70081 	24:  uint8(3),
  70082 	25:  uint8(3),
  70083 	26:  uint8(3),
  70084 	27:  uint8(3),
  70085 	28:  uint8(3),
  70086 	29:  uint8(3),
  70087 	30:  uint8(3),
  70088 	31:  uint8(2),
  70089 	32:  uint8(2),
  70090 	33:  uint8(2),
  70091 	34:  uint8(2),
  70092 	35:  uint8(2),
  70093 	36:  uint8(2),
  70094 	37:  uint8(2),
  70095 	38:  uint8(2),
  70096 	39:  uint8(2),
  70097 	40:  uint8(2),
  70098 	41:  uint8(2),
  70099 	42:  uint8(2),
  70100 	43:  uint8(2),
  70101 	44:  uint8(2),
  70102 	45:  uint8(2),
  70103 	46:  uint8(2),
  70104 	47:  uint8(2),
  70105 	48:  uint8(2),
  70106 	49:  uint8(2),
  70107 	50:  uint8(2),
  70108 	51:  uint8(2),
  70109 	52:  uint8(2),
  70110 	53:  uint8(2),
  70111 	54:  uint8(2),
  70112 	55:  uint8(2),
  70113 	56:  uint8(2),
  70114 	57:  uint8(2),
  70115 	58:  uint8(2),
  70116 	59:  uint8(2),
  70117 	60:  uint8(2),
  70118 	61:  uint8(2),
  70119 	62:  uint8(2),
  70120 	63:  uint8(1),
  70121 	64:  uint8(1),
  70122 	65:  uint8(1),
  70123 	66:  uint8(1),
  70124 	67:  uint8(1),
  70125 	68:  uint8(1),
  70126 	69:  uint8(1),
  70127 	70:  uint8(1),
  70128 	71:  uint8(1),
  70129 	72:  uint8(1),
  70130 	73:  uint8(1),
  70131 	74:  uint8(1),
  70132 	75:  uint8(1),
  70133 	76:  uint8(1),
  70134 	77:  uint8(1),
  70135 	78:  uint8(1),
  70136 	79:  uint8(1),
  70137 	80:  uint8(1),
  70138 	81:  uint8(1),
  70139 	82:  uint8(1),
  70140 	83:  uint8(1),
  70141 	84:  uint8(1),
  70142 	85:  uint8(1),
  70143 	86:  uint8(1),
  70144 	87:  uint8(1),
  70145 	88:  uint8(1),
  70146 	89:  uint8(1),
  70147 	90:  uint8(1),
  70148 	91:  uint8(1),
  70149 	92:  uint8(1),
  70150 	93:  uint8(1),
  70151 	94:  uint8(1),
  70152 	95:  uint8(1),
  70153 	96:  uint8(1),
  70154 	97:  uint8(1),
  70155 	98:  uint8(1),
  70156 	99:  uint8(1),
  70157 	100: uint8(1),
  70158 	101: uint8(1),
  70159 	102: uint8(1),
  70160 	103: uint8(1),
  70161 	104: uint8(1),
  70162 	105: uint8(1),
  70163 	106: uint8(1),
  70164 	107: uint8(1),
  70165 	108: uint8(1),
  70166 	109: uint8(1),
  70167 	110: uint8(1),
  70168 	111: uint8(1),
  70169 	112: uint8(1),
  70170 	113: uint8(1),
  70171 	114: uint8(1),
  70172 	115: uint8(1),
  70173 	116: uint8(1),
  70174 	117: uint8(1),
  70175 	118: uint8(1),
  70176 	119: uint8(1),
  70177 	120: uint8(1),
  70178 	121: uint8(1),
  70179 	122: uint8(1),
  70180 	123: uint8(1),
  70181 	124: uint8(1),
  70182 	125: uint8(1),
  70183 	126: uint8(1),
  70184 }
  70185 
  70186 // C documentation
  70187 //
  70188 //	// range = ((range - 1) << kVP8Log2Range[range]) + 1
  70189 var kVP8NewRange = [128]uint8_t{
  70190 	0:   uint8(127),
  70191 	1:   uint8(127),
  70192 	2:   uint8(191),
  70193 	3:   uint8(127),
  70194 	4:   uint8(159),
  70195 	5:   uint8(191),
  70196 	6:   uint8(223),
  70197 	7:   uint8(127),
  70198 	8:   uint8(143),
  70199 	9:   uint8(159),
  70200 	10:  uint8(175),
  70201 	11:  uint8(191),
  70202 	12:  uint8(207),
  70203 	13:  uint8(223),
  70204 	14:  uint8(239),
  70205 	15:  uint8(127),
  70206 	16:  uint8(135),
  70207 	17:  uint8(143),
  70208 	18:  uint8(151),
  70209 	19:  uint8(159),
  70210 	20:  uint8(167),
  70211 	21:  uint8(175),
  70212 	22:  uint8(183),
  70213 	23:  uint8(191),
  70214 	24:  uint8(199),
  70215 	25:  uint8(207),
  70216 	26:  uint8(215),
  70217 	27:  uint8(223),
  70218 	28:  uint8(231),
  70219 	29:  uint8(239),
  70220 	30:  uint8(247),
  70221 	31:  uint8(127),
  70222 	32:  uint8(131),
  70223 	33:  uint8(135),
  70224 	34:  uint8(139),
  70225 	35:  uint8(143),
  70226 	36:  uint8(147),
  70227 	37:  uint8(151),
  70228 	38:  uint8(155),
  70229 	39:  uint8(159),
  70230 	40:  uint8(163),
  70231 	41:  uint8(167),
  70232 	42:  uint8(171),
  70233 	43:  uint8(175),
  70234 	44:  uint8(179),
  70235 	45:  uint8(183),
  70236 	46:  uint8(187),
  70237 	47:  uint8(191),
  70238 	48:  uint8(195),
  70239 	49:  uint8(199),
  70240 	50:  uint8(203),
  70241 	51:  uint8(207),
  70242 	52:  uint8(211),
  70243 	53:  uint8(215),
  70244 	54:  uint8(219),
  70245 	55:  uint8(223),
  70246 	56:  uint8(227),
  70247 	57:  uint8(231),
  70248 	58:  uint8(235),
  70249 	59:  uint8(239),
  70250 	60:  uint8(243),
  70251 	61:  uint8(247),
  70252 	62:  uint8(251),
  70253 	63:  uint8(127),
  70254 	64:  uint8(129),
  70255 	65:  uint8(131),
  70256 	66:  uint8(133),
  70257 	67:  uint8(135),
  70258 	68:  uint8(137),
  70259 	69:  uint8(139),
  70260 	70:  uint8(141),
  70261 	71:  uint8(143),
  70262 	72:  uint8(145),
  70263 	73:  uint8(147),
  70264 	74:  uint8(149),
  70265 	75:  uint8(151),
  70266 	76:  uint8(153),
  70267 	77:  uint8(155),
  70268 	78:  uint8(157),
  70269 	79:  uint8(159),
  70270 	80:  uint8(161),
  70271 	81:  uint8(163),
  70272 	82:  uint8(165),
  70273 	83:  uint8(167),
  70274 	84:  uint8(169),
  70275 	85:  uint8(171),
  70276 	86:  uint8(173),
  70277 	87:  uint8(175),
  70278 	88:  uint8(177),
  70279 	89:  uint8(179),
  70280 	90:  uint8(181),
  70281 	91:  uint8(183),
  70282 	92:  uint8(185),
  70283 	93:  uint8(187),
  70284 	94:  uint8(189),
  70285 	95:  uint8(191),
  70286 	96:  uint8(193),
  70287 	97:  uint8(195),
  70288 	98:  uint8(197),
  70289 	99:  uint8(199),
  70290 	100: uint8(201),
  70291 	101: uint8(203),
  70292 	102: uint8(205),
  70293 	103: uint8(207),
  70294 	104: uint8(209),
  70295 	105: uint8(211),
  70296 	106: uint8(213),
  70297 	107: uint8(215),
  70298 	108: uint8(217),
  70299 	109: uint8(219),
  70300 	110: uint8(221),
  70301 	111: uint8(223),
  70302 	112: uint8(225),
  70303 	113: uint8(227),
  70304 	114: uint8(229),
  70305 	115: uint8(231),
  70306 	116: uint8(233),
  70307 	117: uint8(235),
  70308 	118: uint8(237),
  70309 	119: uint8(239),
  70310 	120: uint8(241),
  70311 	121: uint8(243),
  70312 	122: uint8(245),
  70313 	123: uint8(247),
  70314 	124: uint8(249),
  70315 	125: uint8(251),
  70316 	126: uint8(253),
  70317 	127: uint8(127),
  70318 }
  70319 
  70320 var __ccgo_ts = (*reflect.StringHeader)(unsafe.Pointer(&__ccgo_ts1)).Data
  70321 
  70322 var __ccgo_ts1 = "Alpha decoder initialization failed.\x00Could not decode alpha data.\x00Frame setup failed\x00thread initialization failed.\x00no memory during frame initialization.\x00OK\x00no object\x00null VP8Io passed to VP8GetHeaders()\x00Truncated header.\x00Incorrect keyframe parameters.\x00Frame not displayable.\x00cannot parse picture header\x00Bad code word\x00bad partition length\x00cannot parse segment header\x00cannot parse filter header\x00cannot parse partitions\x00Not a key frame.\x00Premature end-of-partition0 encountered.\x00Premature end-of-file encountered.\x00Output aborted.\x00NULL VP8Io parameter in VP8Decode().\x00RIFF\x00WEBP\x00VP8X\x00VP8 \x00VP8L\x00ALPH\x00assembler statements not supported\x00cpu.c\x00GetCPUInfo\x00xgetbv\x00"