go-libwebp

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

libwebp_linux_arm64.go (2175472B)


      1 // Code generated for linux/arm64 by 'ccgo --goos=linux --goarch=arm64 --package-name=webp -ignore-asm-errors --cpp=aarch64-linux-gnu-gcc -o /home/jfm/Source/Personal/go-libwebp/tools/../lib/transpiled/webp/libwebp_linux_arm64.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 && arm64
      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 = 1
    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 __AARCH64EL__ = 1
    244 const __AARCH64_CMODEL_SMALL__ = 1
    245 const __ARM_64BIT_STATE = 1
    246 const __ARM_ALIGN_MAX_PWR = 28
    247 const __ARM_ALIGN_MAX_STACK_PWR = 16
    248 const __ARM_ARCH = 8
    249 const __ARM_ARCH_8A = 1
    250 const __ARM_ARCH_ISA_A64 = 1
    251 const __ARM_ARCH_PROFILE = 65
    252 const __ARM_BUILDATTR64_FV = 65
    253 const __ARM_FEATURE_CLZ = 1
    254 const __ARM_FEATURE_FMA = 1
    255 const __ARM_FEATURE_IDIV = 1
    256 const __ARM_FEATURE_NUMERIC_MAXMIN = 1
    257 const __ARM_FEATURE_UNALIGNED = 1
    258 const __ARM_FP = 14
    259 const __ARM_FP16_ARGS = 1
    260 const __ARM_FP16_FORMAT_IEEE = 1
    261 const __ARM_NEON = 1
    262 const __ARM_NEON_SVE_BRIDGE = 1
    263 const __ARM_PCS_AAPCS64 = 1
    264 const __ARM_SIZEOF_MINIMAL_ENUM = 4
    265 const __ARM_SIZEOF_WCHAR_T = 4
    266 const __ARM_STATE_ZA = 1
    267 const __ARM_STATE_ZT0 = 1
    268 const __ATOMIC_ACQUIRE = 2
    269 const __ATOMIC_ACQ_REL = 4
    270 const __ATOMIC_CONSUME = 1
    271 const __ATOMIC_RELAXED = 0
    272 const __ATOMIC_RELEASE = 3
    273 const __ATOMIC_SEQ_CST = 5
    274 const __BFLT16_DECIMAL_DIG__ = 4
    275 const __BFLT16_DENORM_MIN__ = "9.18354961579912115600575419704879436e-41B"
    276 const __BFLT16_DIG__ = 2
    277 const __BFLT16_EPSILON__ = "7.81250000000000000000000000000000000e-3B"
    278 const __BFLT16_HAS_DENORM__ = 1
    279 const __BFLT16_HAS_INFINITY__ = 1
    280 const __BFLT16_HAS_QUIET_NAN__ = 1
    281 const __BFLT16_IS_IEC_60559__ = 0
    282 const __BFLT16_MANT_DIG__ = 8
    283 const __BFLT16_MAX_10_EXP__ = 38
    284 const __BFLT16_MAX_EXP__ = 128
    285 const __BFLT16_MAX__ = "3.38953138925153547590470800371487867e+38B"
    286 const __BFLT16_MIN__ = "1.17549435082228750796873653722224568e-38B"
    287 const __BFLT16_NORM_MAX__ = "3.38953138925153547590470800371487867e+38B"
    288 const __BIGGEST_ALIGNMENT__ = 16
    289 const __BIG_ENDIAN = 4321
    290 const __BITINT_MAXWIDTH__ = 65535
    291 const __BYTE_ORDER = 1234
    292 const __BYTE_ORDER__ = "__ORDER_LITTLE_ENDIAN__"
    293 const __CCGO__ = 1
    294 const __CHAR_BIT__ = 8
    295 const __CHAR_UNSIGNED__ = 1
    296 const __DBL_DECIMAL_DIG__ = 17
    297 const __DBL_DIG__ = 15
    298 const __DBL_HAS_DENORM__ = 1
    299 const __DBL_HAS_INFINITY__ = 1
    300 const __DBL_HAS_QUIET_NAN__ = 1
    301 const __DBL_IS_IEC_60559__ = 1
    302 const __DBL_MANT_DIG__ = 53
    303 const __DBL_MAX_10_EXP__ = 308
    304 const __DBL_MAX_EXP__ = 1024
    305 const __DEC128_EPSILON__ = 1e-33
    306 const __DEC128_MANT_DIG__ = 34
    307 const __DEC128_MAX_EXP__ = 6145
    308 const __DEC128_MAX__ = "9.999999999999999999999999999999999E6144"
    309 const __DEC128_MIN__ = 1e-6143
    310 const __DEC128_SUBNORMAL_MIN__ = 0.000000000000000000000000000000001e-6143
    311 const __DEC32_EPSILON__ = 1e-6
    312 const __DEC32_MANT_DIG__ = 7
    313 const __DEC32_MAX_EXP__ = 97
    314 const __DEC32_MAX__ = 9.999999e96
    315 const __DEC32_MIN__ = 1e-95
    316 const __DEC32_SUBNORMAL_MIN__ = 0.000001e-95
    317 const __DEC64X_EPSILON__ = "1E-33D64x"
    318 const __DEC64X_MANT_DIG__ = 34
    319 const __DEC64X_MAX_EXP__ = 6145
    320 const __DEC64X_MAX__ = "9.999999999999999999999999999999999E6144D64x"
    321 const __DEC64X_MIN__ = "1E-6143D64x"
    322 const __DEC64X_SUBNORMAL_MIN__ = "0.000000000000000000000000000000001E-6143D64x"
    323 const __DEC64_EPSILON__ = 1e-15
    324 const __DEC64_MANT_DIG__ = 16
    325 const __DEC64_MAX_EXP__ = 385
    326 const __DEC64_MAX__ = "9.999999999999999E384"
    327 const __DEC64_MIN__ = 1e-383
    328 const __DEC64_SUBNORMAL_MIN__ = 0.000000000000001e-383
    329 const __DECIMAL_BID_FORMAT__ = 1
    330 const __DECIMAL_DIG__ = 36
    331 const __DEC_EVAL_METHOD__ = 2
    332 const __ELF__ = 1
    333 const __FINITE_MATH_ONLY__ = 0
    334 const __FLOAT_WORD_ORDER__ = "__ORDER_LITTLE_ENDIAN__"
    335 const __FLT128_DECIMAL_DIG__ = 36
    336 const __FLT128_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    337 const __FLT128_DIG__ = 33
    338 const __FLT128_EPSILON__ = 1.92592994438723585305597794258492732e-34
    339 const __FLT128_HAS_DENORM__ = 1
    340 const __FLT128_HAS_INFINITY__ = 1
    341 const __FLT128_HAS_QUIET_NAN__ = 1
    342 const __FLT128_IS_IEC_60559__ = 1
    343 const __FLT128_MANT_DIG__ = 113
    344 const __FLT128_MAX_10_EXP__ = 4932
    345 const __FLT128_MAX_EXP__ = 16384
    346 const __FLT128_MAX__ = "1.18973149535723176508575932662800702e+4932"
    347 const __FLT128_MIN__ = 3.36210314311209350626267781732175260e-4932
    348 const __FLT128_NORM_MAX__ = "1.18973149535723176508575932662800702e+4932"
    349 const __FLT16_DECIMAL_DIG__ = 5
    350 const __FLT16_DENORM_MIN__ = 5.96046447753906250000000000000000000e-8
    351 const __FLT16_DIG__ = 3
    352 const __FLT16_EPSILON__ = 9.76562500000000000000000000000000000e-4
    353 const __FLT16_HAS_DENORM__ = 1
    354 const __FLT16_HAS_INFINITY__ = 1
    355 const __FLT16_HAS_QUIET_NAN__ = 1
    356 const __FLT16_IS_IEC_60559__ = 1
    357 const __FLT16_MANT_DIG__ = 11
    358 const __FLT16_MAX_10_EXP__ = 4
    359 const __FLT16_MAX_EXP__ = 16
    360 const __FLT16_MAX__ = 6.55040000000000000000000000000000000e+4
    361 const __FLT16_MIN__ = 6.10351562500000000000000000000000000e-5
    362 const __FLT16_NORM_MAX__ = 6.55040000000000000000000000000000000e+4
    363 const __FLT32X_DECIMAL_DIG__ = 17
    364 const __FLT32X_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    365 const __FLT32X_DIG__ = 15
    366 const __FLT32X_EPSILON__ = 2.22044604925031308084726333618164062e-16
    367 const __FLT32X_HAS_DENORM__ = 1
    368 const __FLT32X_HAS_INFINITY__ = 1
    369 const __FLT32X_HAS_QUIET_NAN__ = 1
    370 const __FLT32X_IS_IEC_60559__ = 1
    371 const __FLT32X_MANT_DIG__ = 53
    372 const __FLT32X_MAX_10_EXP__ = 308
    373 const __FLT32X_MAX_EXP__ = 1024
    374 const __FLT32X_MAX__ = 1.79769313486231570814527423731704357e+308
    375 const __FLT32X_MIN__ = 2.22507385850720138309023271733240406e-308
    376 const __FLT32X_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    377 const __FLT32_DECIMAL_DIG__ = 9
    378 const __FLT32_DENORM_MIN__ = 1.40129846432481707092372958328991613e-45
    379 const __FLT32_DIG__ = 6
    380 const __FLT32_EPSILON__ = 1.19209289550781250000000000000000000e-7
    381 const __FLT32_HAS_DENORM__ = 1
    382 const __FLT32_HAS_INFINITY__ = 1
    383 const __FLT32_HAS_QUIET_NAN__ = 1
    384 const __FLT32_IS_IEC_60559__ = 1
    385 const __FLT32_MANT_DIG__ = 24
    386 const __FLT32_MAX_10_EXP__ = 38
    387 const __FLT32_MAX_EXP__ = 128
    388 const __FLT32_MAX__ = 3.40282346638528859811704183484516925e+38
    389 const __FLT32_MIN__ = 1.17549435082228750796873653722224568e-38
    390 const __FLT32_NORM_MAX__ = 3.40282346638528859811704183484516925e+38
    391 const __FLT64X_DECIMAL_DIG__ = 36
    392 const __FLT64X_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    393 const __FLT64X_DIG__ = 33
    394 const __FLT64X_EPSILON__ = 1.92592994438723585305597794258492732e-34
    395 const __FLT64X_HAS_DENORM__ = 1
    396 const __FLT64X_HAS_INFINITY__ = 1
    397 const __FLT64X_HAS_QUIET_NAN__ = 1
    398 const __FLT64X_IS_IEC_60559__ = 1
    399 const __FLT64X_MANT_DIG__ = 113
    400 const __FLT64X_MAX_10_EXP__ = 4932
    401 const __FLT64X_MAX_EXP__ = 16384
    402 const __FLT64X_MAX__ = "1.18973149535723176508575932662800702e+4932"
    403 const __FLT64X_MIN__ = 3.36210314311209350626267781732175260e-4932
    404 const __FLT64X_NORM_MAX__ = "1.18973149535723176508575932662800702e+4932"
    405 const __FLT64_DECIMAL_DIG__ = 17
    406 const __FLT64_DENORM_MIN__ = 4.94065645841246544176568792868221372e-324
    407 const __FLT64_DIG__ = 15
    408 const __FLT64_EPSILON__ = 2.22044604925031308084726333618164062e-16
    409 const __FLT64_HAS_DENORM__ = 1
    410 const __FLT64_HAS_INFINITY__ = 1
    411 const __FLT64_HAS_QUIET_NAN__ = 1
    412 const __FLT64_IS_IEC_60559__ = 1
    413 const __FLT64_MANT_DIG__ = 53
    414 const __FLT64_MAX_10_EXP__ = 308
    415 const __FLT64_MAX_EXP__ = 1024
    416 const __FLT64_MAX__ = 1.79769313486231570814527423731704357e+308
    417 const __FLT64_MIN__ = 2.22507385850720138309023271733240406e-308
    418 const __FLT64_NORM_MAX__ = 1.79769313486231570814527423731704357e+308
    419 const __FLT_DECIMAL_DIG__ = 9
    420 const __FLT_DENORM_MIN__ = 1.40129846432481707092372958328991613e-45
    421 const __FLT_DIG__ = 6
    422 const __FLT_EPSILON__ = 1.19209289550781250000000000000000000e-7
    423 const __FLT_EVAL_METHOD_C99__ = 0
    424 const __FLT_EVAL_METHOD_TS_18661_3__ = 0
    425 const __FLT_EVAL_METHOD__ = 0
    426 const __FLT_HAS_DENORM__ = 1
    427 const __FLT_HAS_INFINITY__ = 1
    428 const __FLT_HAS_QUIET_NAN__ = 1
    429 const __FLT_IS_IEC_60559__ = 1
    430 const __FLT_MANT_DIG__ = 24
    431 const __FLT_MAX_10_EXP__ = 38
    432 const __FLT_MAX_EXP__ = 128
    433 const __FLT_MAX__ = 3.40282346638528859811704183484516925e+38
    434 const __FLT_MIN__ = 1.17549435082228750796873653722224568e-38
    435 const __FLT_NORM_MAX__ = 3.40282346638528859811704183484516925e+38
    436 const __FLT_RADIX__ = 2
    437 const __FP_FAST_FMA = 1
    438 const __FP_FAST_FMAF = 1
    439 const __FP_FAST_FMAF32 = 1
    440 const __FP_FAST_FMAF32x = 1
    441 const __FP_FAST_FMAF64 = 1
    442 const __FUNCTION__ = "__func__"
    443 const __GCC_ASM_FLAG_OUTPUTS__ = 1
    444 const __GCC_ATOMIC_BOOL_LOCK_FREE = 2
    445 const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2
    446 const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2
    447 const __GCC_ATOMIC_CHAR8_T_LOCK_FREE = 2
    448 const __GCC_ATOMIC_CHAR_LOCK_FREE = 2
    449 const __GCC_ATOMIC_INT_LOCK_FREE = 2
    450 const __GCC_ATOMIC_LLONG_LOCK_FREE = 2
    451 const __GCC_ATOMIC_LONG_LOCK_FREE = 2
    452 const __GCC_ATOMIC_POINTER_LOCK_FREE = 2
    453 const __GCC_ATOMIC_SHORT_LOCK_FREE = 2
    454 const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1
    455 const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2
    456 const __GCC_CONSTRUCTIVE_SIZE = 64
    457 const __GCC_DESTRUCTIVE_SIZE = 256
    458 const __GCC_HAVE_DWARF2_CFI_ASM = 1
    459 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1
    460 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 = 1
    461 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1
    462 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1
    463 const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1
    464 const __GCC_IEC_559 = 2
    465 const __GCC_IEC_559_COMPLEX = 2
    466 const __GNUC_EXECUTION_CHARSET_NAME = "UTF-8"
    467 const __GNUC_MINOR__ = 1
    468 const __GNUC_PATCHLEVEL__ = 0
    469 const __GNUC_STDC_INLINE__ = 1
    470 const __GNUC_WIDE_EXECUTION_CHARSET_NAME = "UTF-32LE"
    471 const __GNUC__ = 16
    472 const __GXX_ABI_VERSION = 1021
    473 const __HAVE_FUNCTION_MULTI_VERSIONING = 1
    474 const __HAVE_SPECULATION_SAFE_VALUE = 1
    475 const __INT16_MAX__ = 0x7fff
    476 const __INT32_MAX__ = 0x7fffffff
    477 const __INT32_TYPE__ = "int"
    478 const __INT64_MAX__ = 0x7fffffffffffffff
    479 const __INT8_MAX__ = 0x7f
    480 const __INTMAX_MAX__ = 0x7fffffffffffffff
    481 const __INTMAX_WIDTH__ = 64
    482 const __INTPTR_MAX__ = 0x7fffffffffffffff
    483 const __INTPTR_WIDTH__ = 64
    484 const __INT_FAST16_MAX__ = 0x7fffffffffffffff
    485 const __INT_FAST16_WIDTH__ = 64
    486 const __INT_FAST32_MAX__ = 0x7fffffffffffffff
    487 const __INT_FAST32_WIDTH__ = 64
    488 const __INT_FAST64_MAX__ = 0x7fffffffffffffff
    489 const __INT_FAST64_WIDTH__ = 64
    490 const __INT_FAST8_MAX__ = 0x7f
    491 const __INT_FAST8_WIDTH__ = 8
    492 const __INT_LEAST16_MAX__ = 0x7fff
    493 const __INT_LEAST16_WIDTH__ = 16
    494 const __INT_LEAST32_MAX__ = 0x7fffffff
    495 const __INT_LEAST32_TYPE__ = "int"
    496 const __INT_LEAST32_WIDTH__ = 32
    497 const __INT_LEAST64_MAX__ = 0x7fffffffffffffff
    498 const __INT_LEAST64_WIDTH__ = 64
    499 const __INT_LEAST8_MAX__ = 0x7f
    500 const __INT_LEAST8_WIDTH__ = 8
    501 const __INT_MAX__ = 0x7fffffff
    502 const __INT_WIDTH__ = 32
    503 const __LDBL_DECIMAL_DIG__ = 36
    504 const __LDBL_DENORM_MIN__ = 6.47517511943802511092443895822764655e-4966
    505 const __LDBL_DIG__ = 33
    506 const __LDBL_EPSILON__ = 1.92592994438723585305597794258492732e-34
    507 const __LDBL_HAS_DENORM__ = 1
    508 const __LDBL_HAS_INFINITY__ = 1
    509 const __LDBL_HAS_QUIET_NAN__ = 1
    510 const __LDBL_IS_IEC_60559__ = 1
    511 const __LDBL_MANT_DIG__ = 113
    512 const __LDBL_MAX_10_EXP__ = 4932
    513 const __LDBL_MAX_EXP__ = 16384
    514 const __LDBL_MAX__ = "1.18973149535723176508575932662800702e+4932"
    515 const __LDBL_MIN__ = 3.36210314311209350626267781732175260e-4932
    516 const __LDBL_NORM_MAX__ = "1.18973149535723176508575932662800702e+4932"
    517 const __LITTLE_ENDIAN = 1234
    518 const __LONG_LONG_MAX__ = 0x7fffffffffffffff
    519 const __LONG_LONG_WIDTH__ = 64
    520 const __LONG_MAX = 0x7fffffffffffffff
    521 const __LONG_MAX__ = 0x7fffffffffffffff
    522 const __LONG_WIDTH__ = 64
    523 const __LP64__ = 1
    524 const __NO_INLINE__ = 1
    525 const __ORDER_BIG_ENDIAN__ = 4321
    526 const __ORDER_LITTLE_ENDIAN__ = 1234
    527 const __ORDER_PDP_ENDIAN__ = 3412
    528 const __PIC__ = 2
    529 const __PIE__ = 2
    530 const __PRAGMA_REDEFINE_EXTNAME = 1
    531 const __PRETTY_FUNCTION__ = "__func__"
    532 const __PRI64 = "l"
    533 const __PRIPTR = "l"
    534 const __PTRDIFF_MAX__ = 0x7fffffffffffffff
    535 const __PTRDIFF_WIDTH__ = 64
    536 const __SCHAR_MAX__ = 0x7f
    537 const __SCHAR_WIDTH__ = 8
    538 const __SHRT_MAX__ = 0x7fff
    539 const __SHRT_WIDTH__ = 16
    540 const __SIG_ATOMIC_MAX__ = 0x7fffffff
    541 const __SIG_ATOMIC_TYPE__ = "int"
    542 const __SIG_ATOMIC_WIDTH__ = 32
    543 const __SIZEOF_DOUBLE__ = 8
    544 const __SIZEOF_FLOAT__ = 4
    545 const __SIZEOF_INT128__ = 16
    546 const __SIZEOF_INT__ = 4
    547 const __SIZEOF_LONG_DOUBLE__ = 8
    548 const __SIZEOF_LONG_LONG__ = 8
    549 const __SIZEOF_LONG__ = 8
    550 const __SIZEOF_POINTER__ = 8
    551 const __SIZEOF_PTRDIFF_T__ = 8
    552 const __SIZEOF_SHORT__ = 2
    553 const __SIZEOF_SIZE_T__ = 8
    554 const __SIZEOF_WCHAR_T__ = 4
    555 const __SIZEOF_WINT_T__ = 4
    556 const __SIZE_MAX__ = 0xffffffffffffffff
    557 const __SIZE_WIDTH__ = 64
    558 const __STDC_EMBED_EMPTY__ = 2
    559 const __STDC_EMBED_FOUND__ = 1
    560 const __STDC_EMBED_NOT_FOUND__ = 0
    561 const __STDC_HOSTED__ = 1
    562 const __STDC_IEC_559_COMPLEX__ = 1
    563 const __STDC_IEC_559__ = 1
    564 const __STDC_IEC_60559_BFP__ = 201404
    565 const __STDC_IEC_60559_COMPLEX__ = 201404
    566 const __STDC_ISO_10646__ = 201706
    567 const __STDC_UTF_16__ = 1
    568 const __STDC_UTF_32__ = 1
    569 const __STDC_VERSION__ = 202311
    570 const __STDC__ = 1
    571 const __UINT16_MAX__ = 0xffff
    572 const __UINT32_MAX__ = 0xffffffff
    573 const __UINT64_MAX__ = 0xffffffffffffffff
    574 const __UINT8_MAX__ = 0xff
    575 const __UINTMAX_MAX__ = 0xffffffffffffffff
    576 const __UINTPTR_MAX__ = 0xffffffffffffffff
    577 const __UINT_FAST16_MAX__ = 0xffffffffffffffff
    578 const __UINT_FAST32_MAX__ = 0xffffffffffffffff
    579 const __UINT_FAST64_MAX__ = 0xffffffffffffffff
    580 const __UINT_FAST8_MAX__ = 0xff
    581 const __UINT_LEAST16_MAX__ = 0xffff
    582 const __UINT_LEAST32_MAX__ = 0xffffffff
    583 const __UINT_LEAST64_MAX__ = 0xffffffffffffffff
    584 const __UINT_LEAST8_MAX__ = 0xff
    585 const __USE_TIME_BITS64 = 1
    586 const __VERSION__ = "16.1.0"
    587 const __WCHAR_MAX__ = 0xffffffff
    588 const __WCHAR_MIN__ = 0
    589 const __WCHAR_WIDTH__ = 32
    590 const __WINT_MAX__ = 0xffffffff
    591 const __WINT_MIN__ = 0
    592 const __WINT_WIDTH__ = 32
    593 const __aarch64__ = 1
    594 const __gnu_linux__ = 1
    595 const __inline = "inline"
    596 const __linux = 1
    597 const __linux__ = 1
    598 const __pic__ = 2
    599 const __pie__ = 2
    600 const __restrict = "restrict"
    601 const __restrict_arr = "restrict"
    602 const __unix = 1
    603 const __unix__ = 1
    604 const alloca1 = "__builtin_alloca"
    605 const false1 = 0
    606 const linux = 1
    607 const static_assert = "_Static_assert"
    608 const true1 = 1
    609 const unix = 1
    610 
    611 /* C23 keywords, no longer defined as macros by <stdbool.h> and <stddef.h>. */
    612 
    613 type __builtin_va_list = uintptr
    614 
    615 type __predefined_size_t = uint64
    616 
    617 type __predefined_wchar_t = uint32
    618 
    619 type __predefined_ptrdiff_t = int64
    620 
    621 type wchar_t = uint32
    622 
    623 type size_t = uint64
    624 
    625 type div_t = struct {
    626 	Fquot int32
    627 	Frem  int32
    628 }
    629 
    630 type ldiv_t = struct {
    631 	Fquot int64
    632 	Frem  int64
    633 }
    634 
    635 type lldiv_t = struct {
    636 	Fquot int64
    637 	Frem  int64
    638 }
    639 
    640 type max_align_t = struct {
    641 	F__ll int64
    642 	F__ld float64
    643 }
    644 
    645 type ptrdiff_t = int64
    646 
    647 type uintptr_t = uint64
    648 
    649 type intptr_t = int64
    650 
    651 type int8_t = int8
    652 
    653 type int16_t = int16
    654 
    655 type int32_t = int32
    656 
    657 type int64_t = int64
    658 
    659 type intmax_t = int64
    660 
    661 type uint8_t = uint8
    662 
    663 type uint16_t = uint16
    664 
    665 type uint32_t = uint32
    666 
    667 type uint64_t = uint64
    668 
    669 type uintmax_t = uint64
    670 
    671 type int_fast8_t = int8
    672 
    673 type int_fast64_t = int64
    674 
    675 type int_least8_t = int8
    676 
    677 type int_least16_t = int16
    678 
    679 type int_least32_t = int32
    680 
    681 type int_least64_t = int64
    682 
    683 type uint_fast8_t = uint8
    684 
    685 type uint_fast64_t = uint64
    686 
    687 type uint_least8_t = uint8
    688 
    689 type uint_least16_t = uint16
    690 
    691 type uint_least32_t = uint32
    692 
    693 type uint_least64_t = uint64
    694 
    695 type int_fast16_t = int32
    696 
    697 type int_fast32_t = int32
    698 
    699 type uint_fast16_t = uint32
    700 
    701 type uint_fast32_t = uint32
    702 
    703 type imaxdiv_t = struct {
    704 	Fquot intmax_t
    705 	Frem  intmax_t
    706 }
    707 
    708 type WebPRGBABuffer = struct {
    709 	Frgba   uintptr
    710 	Fstride int32
    711 	Fsize   size_t
    712 }
    713 
    714 type WebPYUVABuffer = struct {
    715 	Fy        uintptr
    716 	Fu        uintptr
    717 	Fv        uintptr
    718 	Fa        uintptr
    719 	Fy_stride int32
    720 	Fu_stride int32
    721 	Fv_stride int32
    722 	Fa_stride int32
    723 	Fy_size   size_t
    724 	Fu_size   size_t
    725 	Fv_size   size_t
    726 	Fa_size   size_t
    727 }
    728 
    729 type WebPDecBuffer = struct {
    730 	Fcolorspace         WEBP_CSP_MODE1
    731 	Fwidth              int32
    732 	Fheight             int32
    733 	Fis_external_memory int32
    734 	Fu                  struct {
    735 		FYUVA        [0]WebPYUVABuffer
    736 		FRGBA        WebPRGBABuffer
    737 		F__ccgo_pad2 [56]byte
    738 	}
    739 	Fpad            [4]uint32_t
    740 	Fprivate_memory uintptr
    741 }
    742 
    743 type WEBP_CSP_MODE = int32
    744 
    745 const MODE_RGB = 0
    746 const MODE_RGBA = 1
    747 const MODE_BGR = 2
    748 const MODE_BGRA = 3
    749 const MODE_ARGB = 4
    750 const MODE_RGBA_4444 = 5
    751 const MODE_RGB_565 = 6
    752 const MODE_rgbA = 7
    753 const MODE_bgrA = 8
    754 const MODE_Argb = 9
    755 const MODE_rgbA_4444 = 10
    756 const MODE_YUV = 11
    757 const MODE_YUVA = 12
    758 const MODE_LAST = 13
    759 
    760 type WebPBitstreamFeatures = struct {
    761 	Fwidth         int32
    762 	Fheight        int32
    763 	Fhas_alpha     int32
    764 	Fhas_animation int32
    765 	Fformat        int32
    766 	Fpad           [5]uint32_t
    767 }
    768 
    769 type WebPDecoderOptions = struct {
    770 	Fbypass_filtering         int32
    771 	Fno_fancy_upsampling      int32
    772 	Fuse_cropping             int32
    773 	Fcrop_left                int32
    774 	Fcrop_top                 int32
    775 	Fcrop_width               int32
    776 	Fcrop_height              int32
    777 	Fuse_scaling              int32
    778 	Fscaled_width             int32
    779 	Fscaled_height            int32
    780 	Fuse_threads              int32
    781 	Fdithering_strength       int32
    782 	Fflip                     int32
    783 	Falpha_dithering_strength int32
    784 	Fpad                      [5]uint32_t
    785 }
    786 
    787 type WebPDecoderConfig = struct {
    788 	Finput   WebPBitstreamFeatures
    789 	Foutput  WebPDecBuffer
    790 	Foptions WebPDecoderOptions
    791 }
    792 
    793 type WEBP_CSP_MODE1 = int32
    794 
    795 type VP8StatusCode1 = int32
    796 
    797 type VP8StatusCode = int32
    798 
    799 const VP8_STATUS_OK = 0
    800 const VP8_STATUS_OUT_OF_MEMORY = 1
    801 const VP8_STATUS_INVALID_PARAM = 2
    802 const VP8_STATUS_BITSTREAM_ERROR = 3
    803 const VP8_STATUS_UNSUPPORTED_FEATURE = 4
    804 const VP8_STATUS_SUSPENDED = 5
    805 const VP8_STATUS_USER_ABORT = 6
    806 const VP8_STATUS_NOT_ENOUGH_DATA = 7
    807 
    808 type VP8Io = struct {
    809 	Fwidth            int32
    810 	Fheight           int32
    811 	Fmb_y             int32
    812 	Fmb_w             int32
    813 	Fmb_h             int32
    814 	Fy                uintptr
    815 	Fu                uintptr
    816 	Fv                uintptr
    817 	Fy_stride         int32
    818 	Fuv_stride        int32
    819 	Fopaque           uintptr
    820 	Fput              VP8IoPutHook
    821 	Fsetup            VP8IoSetupHook
    822 	Fteardown         VP8IoTeardownHook
    823 	Ffancy_upsampling int32
    824 	Fdata_size        size_t
    825 	Fdata             uintptr
    826 	Fbypass_filtering int32
    827 	Fuse_cropping     int32
    828 	Fcrop_left        int32
    829 	Fcrop_right       int32
    830 	Fcrop_top         int32
    831 	Fcrop_bottom      int32
    832 	Fuse_scaling      int32
    833 	Fscaled_width     int32
    834 	Fscaled_height    int32
    835 	Fa                uintptr
    836 }
    837 
    838 type VP8IoPutHook = uintptr
    839 
    840 type VP8IoSetupHook = uintptr
    841 
    842 type VP8IoTeardownHook = uintptr
    843 
    844 type VP8Decoder = struct {
    845 	Fstatus              VP8StatusCode1
    846 	Fready               int32
    847 	Ferror_msg           uintptr
    848 	Fbr                  VP8BitReader
    849 	Fincremental         int32
    850 	Ffrm_hdr             VP8FrameHeader
    851 	Fpic_hdr             VP8PictureHeader
    852 	Ffilter_hdr          VP8FilterHeader
    853 	Fsegment_hdr         VP8SegmentHeader
    854 	Fworker              WebPWorker
    855 	Fmt_method           int32
    856 	Fcache_id            int32
    857 	Fnum_caches          int32
    858 	Fthread_ctx          VP8ThreadContext
    859 	Fmb_w                int32
    860 	Fmb_h                int32
    861 	Ftl_mb_x             int32
    862 	Ftl_mb_y             int32
    863 	Fbr_mb_x             int32
    864 	Fbr_mb_y             int32
    865 	Fnum_parts_minus_one uint32_t
    866 	Fparts               [8]VP8BitReader
    867 	Fdither              int32
    868 	Fdithering_rg        VP8Random
    869 	Fdqm                 [4]VP8QuantMatrix
    870 	Fproba               VP8Proba
    871 	Fuse_skip_proba      int32
    872 	Fskip_p              uint8_t
    873 	Fintra_t             uintptr
    874 	Fintra_l             [4]uint8_t
    875 	Fyuv_t               uintptr
    876 	Fmb_info             uintptr
    877 	Ff_info              uintptr
    878 	Fyuv_b               uintptr
    879 	Fcache_y             uintptr
    880 	Fcache_u             uintptr
    881 	Fcache_v             uintptr
    882 	Fcache_y_stride      int32
    883 	Fcache_uv_stride     int32
    884 	Fmem                 uintptr
    885 	Fmem_size            size_t
    886 	Fmb_x                int32
    887 	Fmb_y                int32
    888 	Fmb_data             uintptr
    889 	Ffilter_type         int32
    890 	Ffstrengths          [4][2]VP8FInfo
    891 	Falph_dec            uintptr
    892 	Falpha_data          uintptr
    893 	Falpha_data_size     size_t
    894 	Fis_alpha_decoded    int32
    895 	Falpha_plane_mem     uintptr
    896 	Falpha_plane         uintptr
    897 	Falpha_prev_line     uintptr
    898 	Falpha_dithering     int32
    899 }
    900 
    901 type rescaler_t = uint32
    902 
    903 type WebPRescaler = struct {
    904 	Fx_expand     int32
    905 	Fy_expand     int32
    906 	Fnum_channels int32
    907 	Ffx_scale     uint32_t
    908 	Ffy_scale     uint32_t
    909 	Ffxy_scale    uint32_t
    910 	Fy_accum      int32
    911 	Fy_add        int32
    912 	Fy_sub        int32
    913 	Fx_add        int32
    914 	Fx_sub        int32
    915 	Fsrc_width    int32
    916 	Fsrc_height   int32
    917 	Fdst_width    int32
    918 	Fdst_height   int32
    919 	Fsrc_y        int32
    920 	Fdst_y        int32
    921 	Fdst          uintptr
    922 	Fdst_stride   int32
    923 	Firow         uintptr
    924 	Ffrow         uintptr
    925 }
    926 
    927 type WebPDecParams = struct {
    928 	Foutput         uintptr
    929 	Ftmp_y          uintptr
    930 	Ftmp_u          uintptr
    931 	Ftmp_v          uintptr
    932 	Flast_y         int32
    933 	Foptions        uintptr
    934 	Fscaler_y       uintptr
    935 	Fscaler_u       uintptr
    936 	Fscaler_v       uintptr
    937 	Fscaler_a       uintptr
    938 	Fmemory         uintptr
    939 	Femit           OutputFunc
    940 	Femit_alpha     OutputAlphaFunc
    941 	Femit_alpha_row OutputRowFunc
    942 }
    943 
    944 type OutputFunc = uintptr
    945 
    946 type OutputAlphaFunc = uintptr
    947 
    948 type OutputRowFunc = uintptr
    949 
    950 type WebPHeaderStructure = struct {
    951 	Fdata            uintptr
    952 	Fdata_size       size_t
    953 	Fhave_all_data   int32
    954 	Foffset          size_t
    955 	Falpha_data      uintptr
    956 	Falpha_data_size size_t
    957 	Fcompressed_size size_t
    958 	Friff_size       size_t
    959 	Fis_lossless     int32
    960 }
    961 
    962 type CPUFeature = int32
    963 
    964 const kSSE2 = 0
    965 const kSSE3 = 1
    966 const kSlowSSSE3 = 2
    967 const kSSE4_1 = 3
    968 const kAVX = 4
    969 const kAVX2 = 5
    970 const kNEON = 6
    971 const kMIPS32 = 7
    972 const kMIPSdspR2 = 8
    973 const kMSA = 9
    974 
    975 type VP8CPUInfo = uintptr
    976 
    977 type VP8Idct = uintptr
    978 
    979 type VP8Fdct = uintptr
    980 
    981 type VP8WHT = uintptr
    982 
    983 type VP8IntraPreds = uintptr
    984 
    985 type VP8Intra4Preds = uintptr
    986 
    987 type VP8Metric = uintptr
    988 
    989 type VP8WMetric = uintptr
    990 
    991 type VP8MeanMetric = uintptr
    992 
    993 type VP8BlockCopy = uintptr
    994 
    995 type VP8QuantizeBlock = uintptr
    996 
    997 type VP8Quantize2Blocks = uintptr
    998 
    999 type VP8QuantizeBlockWHT = uintptr
   1000 
   1001 type VP8Histogram = struct {
   1002 	Fmax_value     int32
   1003 	Flast_non_zero int32
   1004 }
   1005 
   1006 type VP8CHisto = uintptr
   1007 
   1008 type VP8SetResidualCoeffsFunc = uintptr
   1009 
   1010 type VP8GetResidualCostFunc = uintptr
   1011 
   1012 type VP8DistoStats = struct {
   1013 	Fw   uint32_t
   1014 	Fxm  uint32_t
   1015 	Fym  uint32_t
   1016 	Fxxm uint32_t
   1017 	Fxym uint32_t
   1018 	Fyym uint32_t
   1019 }
   1020 
   1021 type VP8SSIMGetClippedFunc = uintptr
   1022 
   1023 type VP8SSIMGetFunc = uintptr
   1024 
   1025 type VP8AccumulateSSEFunc = uintptr
   1026 
   1027 type VP8DecIdct = uintptr
   1028 
   1029 type VP8DecIdct2 = uintptr
   1030 
   1031 type VP8PredFunc = uintptr
   1032 
   1033 type VP8SimpleFilterFunc = uintptr
   1034 
   1035 type VP8LumaFilterFunc = uintptr
   1036 
   1037 type VP8ChromaFilterFunc = uintptr
   1038 
   1039 type WebPUpsampleLinePairFunc = uintptr
   1040 
   1041 type WebPSamplerRowFunc = uintptr
   1042 
   1043 type WebPYUV444Converter = uintptr
   1044 
   1045 type WebPRescalerImportRowFunc = uintptr
   1046 
   1047 type WebPRescalerExportRowFunc = uintptr
   1048 
   1049 type WEBP_FILTER_TYPE = int32
   1050 
   1051 const WEBP_FILTER_NONE = 0
   1052 const WEBP_FILTER_HORIZONTAL = 1
   1053 const WEBP_FILTER_VERTICAL = 2
   1054 const WEBP_FILTER_GRADIENT = 3
   1055 const WEBP_FILTER_LAST = 4
   1056 const WEBP_FILTER_BEST = 5
   1057 const WEBP_FILTER_FAST = 6
   1058 
   1059 type WebPFilterFunc = uintptr
   1060 
   1061 type WebPUnfilterFunc = uintptr
   1062 
   1063 type VP8LDecoder = struct {
   1064 	Fstatus           VP8StatusCode1
   1065 	Fstate            VP8LDecodeState
   1066 	Fio               uintptr
   1067 	Foutput           uintptr
   1068 	Fpixels           uintptr
   1069 	Fargb_cache       uintptr
   1070 	Fbr               VP8LBitReader
   1071 	Fincremental      int32
   1072 	Fsaved_br         VP8LBitReader
   1073 	Fsaved_last_pixel int32
   1074 	Fwidth            int32
   1075 	Fheight           int32
   1076 	Flast_row         int32
   1077 	Flast_pixel       int32
   1078 	Flast_out_row     int32
   1079 	Fhdr              VP8LMetadata
   1080 	Fnext_transform   int32
   1081 	Ftransforms       [4]VP8LTransform
   1082 	Ftransforms_seen  uint32_t
   1083 	Frescaler_memory  uintptr
   1084 	Frescaler         uintptr
   1085 }
   1086 
   1087 const READ_DATA = 0
   1088 const READ_HDR = 1
   1089 const READ_DIM = 2
   1090 
   1091 type ALPHDecoder = struct {
   1092 	Fwidth          int32
   1093 	Fheight         int32
   1094 	Fmethod         int32
   1095 	Ffilter         WEBP_FILTER_TYPE
   1096 	Fpre_processing int32
   1097 	Fvp8l_dec       uintptr
   1098 	Fio             VP8Io
   1099 	Fuse_8b_decode  int32
   1100 	Foutput         uintptr
   1101 	Fprev_line      uintptr
   1102 }
   1103 
   1104 type locale_t = uintptr
   1105 
   1106 const B_DC_PRED = 0
   1107 const B_TM_PRED = 1
   1108 const B_VE_PRED = 2
   1109 const B_HE_PRED = 3
   1110 const B_RD_PRED = 4
   1111 const B_VR_PRED = 5
   1112 const B_LD_PRED = 6
   1113 const B_VL_PRED = 7
   1114 const B_HD_PRED = 8
   1115 const B_HU_PRED = 9
   1116 const NUM_BMODES = 10
   1117 const DC_PRED = 0
   1118 const V_PRED = 2
   1119 const H_PRED = 3
   1120 const TM_PRED = 1
   1121 const B_PRED = 10
   1122 const NUM_PRED_MODES = 4
   1123 const B_DC_PRED_NOTOP = 4
   1124 const B_DC_PRED_NOLEFT = 5
   1125 const B_DC_PRED_NOTOPLEFT = 6
   1126 const NUM_B_DC_MODES = 7
   1127 const MB_FEATURE_TREE_PROBS = 3
   1128 const NUM_MB_SEGMENTS = 4
   1129 const NUM_REF_LF_DELTAS = 4
   1130 const NUM_MODE_LF_DELTAS = 4
   1131 const MAX_NUM_PARTITIONS = 8
   1132 const NUM_TYPES = 4
   1133 const NUM_BANDS = 8
   1134 const NUM_CTX = 3
   1135 const NUM_PROBAS = 11
   1136 
   1137 type bit_t = uint64
   1138 
   1139 type range_t = uint32
   1140 
   1141 type VP8BitReader = struct {
   1142 	Fvalue   bit_t
   1143 	Frange1  range_t
   1144 	Fbits    int32
   1145 	Fbuf     uintptr
   1146 	Fbuf_end uintptr
   1147 	Fbuf_max uintptr
   1148 	Feof     int32
   1149 }
   1150 
   1151 type vp8l_val_t = uint64
   1152 
   1153 type VP8LBitReader = struct {
   1154 	Fval     vp8l_val_t
   1155 	Fbuf     uintptr
   1156 	Flen1    size_t
   1157 	Fpos     size_t
   1158 	Fbit_pos int32
   1159 	Feos     int32
   1160 }
   1161 
   1162 type VP8LColorCache = struct {
   1163 	Fcolors     uintptr
   1164 	Fhash_shift int32
   1165 	Fhash_bits  int32
   1166 }
   1167 
   1168 var kHashMul = uint32(0x1e35a7bd)
   1169 
   1170 type VP8LImageTransformType = int32
   1171 
   1172 const PREDICTOR_TRANSFORM = 0
   1173 const CROSS_COLOR_TRANSFORM = 1
   1174 const SUBTRACT_GREEN_TRANSFORM = 2
   1175 const COLOR_INDEXING_TRANSFORM = 3
   1176 
   1177 type HuffmanCode = struct {
   1178 	Fbits  uint8_t
   1179 	Fvalue uint16_t
   1180 }
   1181 
   1182 type HuffmanCode32 = struct {
   1183 	Fbits  int32
   1184 	Fvalue uint32_t
   1185 }
   1186 
   1187 type HuffmanTablesSegment = struct {
   1188 	Fstart      uintptr
   1189 	Fcurr_table uintptr
   1190 	Fnext       uintptr
   1191 	Fsize       int32
   1192 }
   1193 
   1194 type HuffmanTables = struct {
   1195 	Froot         HuffmanTablesSegment
   1196 	Fcurr_segment uintptr
   1197 }
   1198 
   1199 type HTreeGroup = struct {
   1200 	Fhtrees             [5]uintptr
   1201 	Fis_trivial_literal int32
   1202 	Fliteral_arb        uint32_t
   1203 	Fis_trivial_code    int32
   1204 	Fuse_packed_table   int32
   1205 	Fpacked_table       [64]HuffmanCode32
   1206 }
   1207 
   1208 type VP8LDecodeState = int32
   1209 
   1210 type VP8LTransform = struct {
   1211 	Ftype1 VP8LImageTransformType
   1212 	Fbits  int32
   1213 	Fxsize int32
   1214 	Fysize int32
   1215 	Fdata  uintptr
   1216 }
   1217 
   1218 type VP8LMetadata = struct {
   1219 	Fcolor_cache_size       int32
   1220 	Fcolor_cache            VP8LColorCache
   1221 	Fsaved_color_cache      VP8LColorCache
   1222 	Fhuffman_mask           int32
   1223 	Fhuffman_subsample_bits int32
   1224 	Fhuffman_xsize          int32
   1225 	Fhuffman_image          uintptr
   1226 	Fnum_htree_groups       int32
   1227 	Fhtree_groups           uintptr
   1228 	Fhuffman_tables         HuffmanTables
   1229 }
   1230 
   1231 type VP8Random = struct {
   1232 	Findex1 int32
   1233 	Findex2 int32
   1234 	Ftab    [55]uint32_t
   1235 	Famp    int32
   1236 }
   1237 
   1238 type WebPWorkerStatus = int32
   1239 
   1240 const NOT_OK = 0
   1241 const OK = 1
   1242 const WORK = 2
   1243 
   1244 type WebPWorkerHook = uintptr
   1245 
   1246 type WebPWorker = struct {
   1247 	Fimpl      uintptr
   1248 	Fstatus    WebPWorkerStatus
   1249 	Fhook      WebPWorkerHook
   1250 	Fdata1     uintptr
   1251 	Fdata2     uintptr
   1252 	Fhad_error int32
   1253 }
   1254 
   1255 type WebPWorkerInterface = struct {
   1256 	FInit    uintptr
   1257 	FReset   uintptr
   1258 	FSync    uintptr
   1259 	FLaunch  uintptr
   1260 	FExecute uintptr
   1261 	FEnd     uintptr
   1262 }
   1263 
   1264 type VP8FrameHeader = struct {
   1265 	Fkey_frame        uint8_t
   1266 	Fprofile          uint8_t
   1267 	Fshow             uint8_t
   1268 	Fpartition_length uint32_t
   1269 }
   1270 
   1271 type VP8PictureHeader = struct {
   1272 	Fwidth      uint16_t
   1273 	Fheight     uint16_t
   1274 	Fxscale     uint8_t
   1275 	Fyscale     uint8_t
   1276 	Fcolorspace uint8_t
   1277 	Fclamp_type uint8_t
   1278 }
   1279 
   1280 type VP8SegmentHeader = struct {
   1281 	Fuse_segment     int32
   1282 	Fupdate_map      int32
   1283 	Fabsolute_delta  int32
   1284 	Fquantizer       [4]int8_t
   1285 	Ffilter_strength [4]int8_t
   1286 }
   1287 
   1288 type VP8ProbaArray = [11]uint8_t
   1289 
   1290 type VP8BandProbas = struct {
   1291 	Fprobas [3]VP8ProbaArray
   1292 }
   1293 
   1294 type VP8Proba = struct {
   1295 	Fsegments  [3]uint8_t
   1296 	Fbands     [4][8]VP8BandProbas
   1297 	Fbands_ptr [4][17]uintptr
   1298 }
   1299 
   1300 type VP8FilterHeader = struct {
   1301 	Fsimple        int32
   1302 	Flevel         int32
   1303 	Fsharpness     int32
   1304 	Fuse_lf_delta  int32
   1305 	Fref_lf_delta  [4]int32
   1306 	Fmode_lf_delta [4]int32
   1307 }
   1308 
   1309 type VP8FInfo = struct {
   1310 	Ff_limit    uint8_t
   1311 	Ff_ilevel   uint8_t
   1312 	Ff_inner    uint8_t
   1313 	Fhev_thresh uint8_t
   1314 }
   1315 
   1316 type VP8MB = struct {
   1317 	Fnz    uint8_t
   1318 	Fnz_dc uint8_t
   1319 }
   1320 
   1321 type quant_t = [2]int32
   1322 
   1323 type VP8QuantMatrix = struct {
   1324 	Fy1_mat   quant_t
   1325 	Fy2_mat   quant_t
   1326 	Fuv_mat   quant_t
   1327 	Fuv_quant int32
   1328 	Fdither   int32
   1329 }
   1330 
   1331 type VP8MBData = struct {
   1332 	Fcoeffs      [384]int16_t
   1333 	Fis_i4x4     uint8_t
   1334 	Fimodes      [16]uint8_t
   1335 	Fuvmode      uint8_t
   1336 	Fnon_zero_y  uint32_t
   1337 	Fnon_zero_uv uint32_t
   1338 	Fdither      uint8_t
   1339 	Fskip        uint8_t
   1340 	Fsegment     uint8_t
   1341 }
   1342 
   1343 type VP8ThreadContext = struct {
   1344 	Fid         int32
   1345 	Fmb_y       int32
   1346 	Ffilter_row int32
   1347 	Ff_info     uintptr
   1348 	Fmb_data    uintptr
   1349 	Fio         VP8Io
   1350 }
   1351 
   1352 type VP8TopSamples = struct {
   1353 	Fy [16]uint8_t
   1354 	Fu [8]uint8_t
   1355 	Fv [8]uint8_t
   1356 }
   1357 
   1358 //------------------------------------------------------------------------------
   1359 
   1360 // Copyright 2010 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 //  Main decoding functions for WebP images.
   1370 //
   1371 // Author: Skal (pascal.massimino@gmail.com)
   1372 
   1373 // Copyright 2012 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 //  Internal header for constants related to WebP file format.
   1383 //
   1384 // Author: Urvang (urvang@google.com)
   1385 
   1386 // Copyright 2010 Google Inc. All Rights Reserved.
   1387 //
   1388 // Use of this source code is governed by a BSD-style license
   1389 // that can be found in the COPYING file in the root of the source
   1390 // tree. An additional intellectual property rights grant can be found
   1391 // in the file PATENTS. All contributing project authors may
   1392 // be found in the AUTHORS file in the root of the source tree.
   1393 // -----------------------------------------------------------------------------
   1394 //
   1395 //  Common types + memory wrappers
   1396 //
   1397 // Author: Skal (pascal.massimino@gmail.com)
   1398 
   1399 //------------------------------------------------------------------------------
   1400 // ALPHDecoder object.
   1401 
   1402 // C documentation
   1403 //
   1404 //	// Allocates a new alpha decoder instance.
   1405 func ALPHNew(tls *libc.TLS) (r uintptr) {
   1406 	var dec uintptr
   1407 	_ = dec
   1408 	dec = WebPSafeCalloc(tls, uint64(1), uint64(216))
   1409 	return dec
   1410 }
   1411 
   1412 // C documentation
   1413 //
   1414 //	// Clears and deallocates an alpha decoder instance.
   1415 func ALPHDelete(tls *libc.TLS, dec uintptr) {
   1416 	if dec != libc.UintptrFromInt32(0) {
   1417 		VP8LDelete(tls, (*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec)
   1418 		(*ALPHDecoder)(unsafe.Pointer(dec)).Fvp8l_dec = libc.UintptrFromInt32(0)
   1419 		WebPSafeFree(tls, dec)
   1420 	}
   1421 }
   1422 
   1423 //------------------------------------------------------------------------------
   1424 // Decoding.
   1425 
   1426 // C documentation
   1427 //
   1428 //	// Initialize alpha decoding by parsing the alpha header and decoding the image
   1429 //	// header for alpha data stored using lossless compression.
   1430 //	// Returns false in case of error in alpha header (data too short, invalid
   1431 //	// compression method or filter, error in lossless header data etc).
   1432 func ALPHInit(tls *libc.TLS, dec uintptr, data uintptr, data_size size_t, src_io uintptr, output uintptr) (r int32) {
   1433 	var alpha_data, io1 uintptr
   1434 	var alpha_data_size, alpha_decoded_size size_t
   1435 	var ok, rsrv, v1 int32
   1436 	_, _, _, _, _, _, _ = alpha_data, alpha_data_size, alpha_decoded_size, io1, ok, rsrv, v1
   1437 	ok = 0
   1438 	alpha_data = data + uintptr(ALPHA_HEADER_LEN)
   1439 	alpha_data_size = data_size - uint64(ALPHA_HEADER_LEN)
   1440 	io1 = dec + 32
   1441 	VP8FiltersInit(tls)
   1442 	(*ALPHDecoder)(unsafe.Pointer(dec)).Foutput = output
   1443 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1444 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1445 	if data_size <= uint64(ALPHA_HEADER_LEN) {
   1446 		return 0
   1447 	}
   1448 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> 0 & int32(0x03)
   1449 	(*ALPHDecoder)(unsafe.Pointer(dec)).Ffilter = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> libc.Int32FromInt32(2) & libc.Int32FromInt32(0x03)
   1450 	(*ALPHDecoder)(unsafe.Pointer(dec)).Fpre_processing = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> int32(4) & int32(0x03)
   1451 	rsrv = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data))) >> int32(6) & int32(0x03)
   1452 	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 {
   1453 		return 0
   1454 	}
   1455 	// Copy the necessary parameters from src_io to io
   1456 	v1 = VP8InitIoInternal(tls, io1, int32(WEBP_DECODER_ABI_VERSION))
   1457 	goto _2
   1458 _2:
   1459 	if !(v1 != 0) {
   1460 		return 0
   1461 	}
   1462 	WebPInitCustomIo(tls, libc.UintptrFromInt32(0), io1)
   1463 	(*VP8Io)(unsafe.Pointer(io1)).Fopaque = dec
   1464 	(*VP8Io)(unsafe.Pointer(io1)).Fwidth = (*VP8Io)(unsafe.Pointer(src_io)).Fwidth
   1465 	(*VP8Io)(unsafe.Pointer(io1)).Fheight = (*VP8Io)(unsafe.Pointer(src_io)).Fheight
   1466 	(*VP8Io)(unsafe.Pointer(io1)).Fuse_cropping = (*VP8Io)(unsafe.Pointer(src_io)).Fuse_cropping
   1467 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_left = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_left
   1468 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_right = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_right
   1469 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_top = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_top
   1470 	(*VP8Io)(unsafe.Pointer(io1)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(src_io)).Fcrop_bottom
   1471 	// No need to copy the scaling parameters.
   1472 	if (*ALPHDecoder)(unsafe.Pointer(dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1473 		alpha_decoded_size = libc.Uint64FromInt32((*ALPHDecoder)(unsafe.Pointer(dec)).Fwidth * (*ALPHDecoder)(unsafe.Pointer(dec)).Fheight)
   1474 		ok = libc.BoolInt32(alpha_data_size >= alpha_decoded_size)
   1475 	} else {
   1476 		ok = VP8LDecodeAlphaHeader(tls, dec, alpha_data, alpha_data_size)
   1477 	}
   1478 	return ok
   1479 }
   1480 
   1481 // C documentation
   1482 //
   1483 //	// Decodes, unfilters and dequantizes *at least* 'num_rows' rows of alpha
   1484 //	// starting from row number 'row'. It assumes that rows up to (row - 1) have
   1485 //	// already been decoded.
   1486 //	// Returns false in case of bitstream error.
   1487 func ALPHDecode(tls *libc.TLS, dec uintptr, row int32, num_rows int32) (r int32) {
   1488 	var alph_dec, deltas, dst, prev_line uintptr
   1489 	var height, width, y int32
   1490 	_, _, _, _, _, _, _ = alph_dec, deltas, dst, height, prev_line, width, y
   1491 	alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   1492 	width = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
   1493 	height = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fio.Fcrop_bottom
   1494 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == ALPHA_NO_COMPRESSION {
   1495 		prev_line = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line
   1496 		deltas = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data + uintptr(ALPHA_HEADER_LEN) + uintptr(row*width)
   1497 		dst = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1498 		y = 0
   1499 		for {
   1500 			if !(y < num_rows) {
   1501 				break
   1502 			}
   1503 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, deltas, dst, width)
   1504 			prev_line = dst
   1505 			dst = dst + uintptr(width)
   1506 			deltas = deltas + uintptr(width)
   1507 			goto _1
   1508 		_1:
   1509 			;
   1510 			y = y + 1
   1511 		}
   1512 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = prev_line
   1513 	} else { // alph_dec->method == ALPHA_LOSSLESS_COMPRESSION
   1514 		if !(VP8LDecodeAlphaImageStream(tls, alph_dec, row+num_rows) != 0) {
   1515 			return 0
   1516 		}
   1517 	}
   1518 	if row+num_rows >= height {
   1519 		(*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded = int32(1)
   1520 	}
   1521 	return int32(1)
   1522 }
   1523 
   1524 func AllocateAlphaPlane(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   1525 	var alpha_size uint64_t
   1526 	var height, stride int32
   1527 	_, _, _ = alpha_size, height, stride
   1528 	stride = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1529 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1530 	alpha_size = libc.Uint64FromInt32(stride) * libc.Uint64FromInt32(height)
   1531 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = WebPSafeMalloc(tls, alpha_size, uint64(1))
   1532 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem == libc.UintptrFromInt32(0) {
   1533 		return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1534 	}
   1535 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem
   1536 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_prev_line = libc.UintptrFromInt32(0)
   1537 	return int32(1)
   1538 }
   1539 
   1540 func WebPDeallocateAlphaMemory(tls *libc.TLS, dec uintptr) {
   1541 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem)
   1542 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane_mem = libc.UintptrFromInt32(0)
   1543 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = libc.UintptrFromInt32(0)
   1544 	ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1545 	(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1546 }
   1547 
   1548 // ------------------------------------------------------------------------------
   1549 // Main entry point.
   1550 func VP8DecompressAlphaRows(tls *libc.TLS, dec uintptr, io uintptr, row int32, num_rows int32) (r uintptr) {
   1551 	var alpha, vp8l_dec uintptr
   1552 	var height, width, v1 int32
   1553 	_, _, _, _, _ = alpha, height, vp8l_dec, width, v1
   1554 	width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
   1555 	height = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom
   1556 	if row < 0 || num_rows <= 0 || row+num_rows > height {
   1557 		return libc.UintptrFromInt32(0)
   1558 	}
   1559 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0) {
   1560 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) { // Initialize decoder.
   1561 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = ALPHNew(tls)
   1562 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec == libc.UintptrFromInt32(0) {
   1563 				VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts)
   1564 				return libc.UintptrFromInt32(0)
   1565 			}
   1566 			if !(AllocateAlphaPlane(tls, dec, io) != 0) {
   1567 				goto Error
   1568 			}
   1569 			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) {
   1570 				vp8l_dec = (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fvp8l_dec
   1571 				if vp8l_dec == libc.UintptrFromInt32(0) {
   1572 					v1 = int32(VP8_STATUS_OUT_OF_MEMORY)
   1573 				} else {
   1574 					v1 = (*VP8LDecoder)(unsafe.Pointer(vp8l_dec)).Fstatus
   1575 				}
   1576 				VP8SetError(tls, dec, v1, __ccgo_ts)
   1577 				goto Error
   1578 			}
   1579 			// if we allowed use of alpha dithering, check whether it's needed at all
   1580 			if (*ALPHDecoder)(unsafe.Pointer((*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)).Fpre_processing != int32(ALPHA_PREPROCESSED_LEVELS) {
   1581 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0 // disable dithering
   1582 			} else {
   1583 				num_rows = height - row // decode everything in one pass
   1584 			}
   1585 		}
   1586 		if !(ALPHDecode(tls, dec, row, num_rows) != 0) {
   1587 			goto Error
   1588 		}
   1589 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0 { // finished?
   1590 			ALPHDelete(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec)
   1591 			(*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec = libc.UintptrFromInt32(0)
   1592 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > 0 {
   1593 				alpha = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_top*width) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   1594 				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) {
   1595 					goto Error
   1596 				}
   1597 			}
   1598 		}
   1599 	}
   1600 	// Return a pointer to the current decoded row.
   1601 	return (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane + uintptr(row*width)
   1602 	goto Error
   1603 Error:
   1604 	;
   1605 	WebPDeallocateAlphaMemory(tls, dec)
   1606 	return libc.UintptrFromInt32(0)
   1607 }
   1608 
   1609 var kHashMul1 = uint32(0x1e35a7bd)
   1610 
   1611 //------------------------------------------------------------------------------
   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 //  Main decoding functions for WebP images.
   1623 //
   1624 // Author: Skal (pascal.massimino@gmail.com)
   1625 
   1626 // Copyright 2010 Google Inc. All Rights Reserved.
   1627 //
   1628 // Use of this source code is governed by a BSD-style license
   1629 // that can be found in the COPYING file in the root of the source
   1630 // tree. An additional intellectual property rights grant can be found
   1631 // in the file PATENTS. All contributing project authors may
   1632 // be found in the AUTHORS file in the root of the source tree.
   1633 // -----------------------------------------------------------------------------
   1634 //
   1635 //  Common types + memory wrappers
   1636 //
   1637 // Author: Skal (pascal.massimino@gmail.com)
   1638 
   1639 //------------------------------------------------------------------------------
   1640 // WebPDecBuffer
   1641 
   1642 // C documentation
   1643 //
   1644 //	// Number of bytes per pixel for the different color-spaces.
   1645 var kModeBpp = [13]uint8_t{
   1646 	0:  uint8(3),
   1647 	1:  uint8(4),
   1648 	2:  uint8(3),
   1649 	3:  uint8(4),
   1650 	4:  uint8(4),
   1651 	5:  uint8(2),
   1652 	6:  uint8(2),
   1653 	7:  uint8(4),
   1654 	8:  uint8(4),
   1655 	9:  uint8(4),
   1656 	10: uint8(2),
   1657 	11: uint8(1),
   1658 	12: uint8(1),
   1659 }
   1660 
   1661 // C documentation
   1662 //
   1663 //	// Convert to an integer to handle both the unsigned/signed enum cases
   1664 //	// without the need for casting to remove type limit warnings.
   1665 func IsValidColorspace(tls *libc.TLS, webp_csp_mode int32) (r int32) {
   1666 	return libc.BoolInt32(webp_csp_mode >= int32(MODE_RGB) && webp_csp_mode < int32(MODE_LAST))
   1667 }
   1668 
   1669 // strictly speaking, the very last (or first, if flipped) row
   1670 // doesn't require padding.
   1671 
   1672 func CheckDecBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1673 	var a_size, size, u_size, v_size, y_size uint64_t
   1674 	var a_stride, height, ok, stride, u_stride, uv_height, uv_width, v_stride, width, y_stride, v1 int32
   1675 	var buf, buf1 uintptr
   1676 	var mode1 WEBP_CSP_MODE1
   1677 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   1678 	ok = int32(1)
   1679 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   1680 	width = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   1681 	height = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   1682 	if !(IsValidColorspace(tls, mode1) != 0) {
   1683 		ok = 0
   1684 	} else {
   1685 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1686 		goto _2
   1687 	_2:
   1688 		if !(v1 != 0) { // YUV checks
   1689 			buf = buffer + 16
   1690 			uv_width = (width + int32(1)) / int32(2)
   1691 			uv_height = (height + int32(1)) / int32(2)
   1692 			y_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride)
   1693 			u_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
   1694 			v_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
   1695 			a_stride = libc.Xabs(tls, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   1696 			y_size = libc.Uint64FromInt32(y_stride)*libc.Uint64FromInt32(height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(width)
   1697 			u_size = libc.Uint64FromInt32(u_stride)*libc.Uint64FromInt32(uv_height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(uv_width)
   1698 			v_size = libc.Uint64FromInt32(v_stride)*libc.Uint64FromInt32(uv_height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(uv_width)
   1699 			a_size = libc.Uint64FromInt32(a_stride)*libc.Uint64FromInt32(height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(width)
   1700 			ok = ok & libc.BoolInt32(y_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size)
   1701 			ok = ok & libc.BoolInt32(u_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size)
   1702 			ok = ok & libc.BoolInt32(v_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size)
   1703 			ok = ok & libc.BoolInt32(y_stride >= width)
   1704 			ok = ok & libc.BoolInt32(u_stride >= uv_width)
   1705 			ok = ok & libc.BoolInt32(v_stride >= uv_width)
   1706 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy != libc.UintptrFromInt32(0))
   1707 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu != libc.UintptrFromInt32(0))
   1708 			ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv != libc.UintptrFromInt32(0))
   1709 			if mode1 == int32(MODE_YUVA) {
   1710 				ok = ok & libc.BoolInt32(a_stride >= width)
   1711 				ok = ok & libc.BoolInt32(a_size <= (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size)
   1712 				ok = ok & libc.BoolInt32((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0))
   1713 			}
   1714 		} else { // RGB checks
   1715 			buf1 = buffer + 16
   1716 			stride = libc.Xabs(tls, (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride)
   1717 			size = libc.Uint64FromInt32(stride)*libc.Uint64FromInt32(height-libc.Int32FromInt32(1)) + libc.Uint64FromInt32(width)*uint64(kModeBpp[mode1])
   1718 			ok = ok & libc.BoolInt32(size <= (*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize)
   1719 			ok = ok & libc.BoolInt32(stride >= width*libc.Int32FromUint8(kModeBpp[mode1]))
   1720 			ok = ok & libc.BoolInt32((*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba != libc.UintptrFromInt32(0))
   1721 		}
   1722 	}
   1723 	if ok != 0 {
   1724 		v1 = int32(VP8_STATUS_OK)
   1725 	} else {
   1726 		v1 = int32(VP8_STATUS_INVALID_PARAM)
   1727 	}
   1728 	return v1
   1729 }
   1730 
   1731 func AllocateBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1732 	var a_size, size, total_size, uv_size uint64_t
   1733 	var a_stride, h, stride, uv_stride, w, v1 int32
   1734 	var buf, buf1, output uintptr
   1735 	var mode1 WEBP_CSP_MODE1
   1736 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_size, a_stride, buf, buf1, h, mode1, output, size, stride, total_size, uv_size, uv_stride, w, v1
   1737 	w = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth
   1738 	h = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight
   1739 	mode1 = (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace
   1740 	if w <= 0 || h <= 0 || !(IsValidColorspace(tls, mode1) != 0) {
   1741 		return int32(VP8_STATUS_INVALID_PARAM)
   1742 	}
   1743 	if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 && (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory == libc.UintptrFromInt32(0) {
   1744 		uv_stride = 0
   1745 		a_stride = 0
   1746 		uv_size = uint64(0)
   1747 		a_size = uint64(0)
   1748 		if uint64(libc.Uint64FromInt32(w)*uint64(kModeBpp[mode1])) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31) {
   1749 			return int32(VP8_STATUS_INVALID_PARAM)
   1750 		}
   1751 		stride = w * libc.Int32FromUint8(kModeBpp[mode1])
   1752 		size = libc.Uint64FromInt32(stride) * libc.Uint64FromInt32(h)
   1753 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1754 		goto _2
   1755 	_2:
   1756 		if !(v1 != 0) {
   1757 			uv_stride = (w + int32(1)) / int32(2)
   1758 			uv_size = libc.Uint64FromInt32(uv_stride) * libc.Uint64FromInt32((h+libc.Int32FromInt32(1))/libc.Int32FromInt32(2))
   1759 			if mode1 == int32(MODE_YUVA) {
   1760 				a_stride = w
   1761 				a_size = libc.Uint64FromInt32(a_stride) * libc.Uint64FromInt32(h)
   1762 			}
   1763 		}
   1764 		total_size = size + uint64(2)*uv_size + a_size
   1765 		output = WebPSafeMalloc(tls, total_size, uint64(1))
   1766 		if output == libc.UintptrFromInt32(0) {
   1767 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   1768 		}
   1769 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = output
   1770 		v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
   1771 		goto _4
   1772 	_4:
   1773 		if !(v1 != 0) { // YUVA initialization
   1774 			buf = buffer + 16
   1775 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy = output
   1776 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride = stride
   1777 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_size = size
   1778 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu = output + uintptr(size)
   1779 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride = uv_stride
   1780 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_size = uv_size
   1781 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv = output + uintptr(size) + uintptr(uv_size)
   1782 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride = uv_stride
   1783 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_size = uv_size
   1784 			if mode1 == int32(MODE_YUVA) {
   1785 				(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa = output + uintptr(size) + uintptr(uint64(2)*uv_size)
   1786 			}
   1787 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_size = a_size
   1788 			(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride = a_stride
   1789 		} else { // RGBA initialization
   1790 			buf1 = buffer + 16
   1791 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Frgba = output
   1792 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fstride = stride
   1793 			(*WebPRGBABuffer)(unsafe.Pointer(buf1)).Fsize = size
   1794 		}
   1795 	}
   1796 	return CheckDecBuffer(tls, buffer)
   1797 }
   1798 
   1799 func WebPFlipBuffer(tls *libc.TLS, buffer uintptr) (r VP8StatusCode1) {
   1800 	var H int64_t
   1801 	var buf, buf1 uintptr
   1802 	var v1 int32
   1803 	_, _, _, _ = H, buf, buf1, v1
   1804 	if buffer == libc.UintptrFromInt32(0) {
   1805 		return int32(VP8_STATUS_INVALID_PARAM)
   1806 	}
   1807 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fcolorspace < int32(MODE_YUV))
   1808 	goto _2
   1809 _2:
   1810 	if v1 != 0 {
   1811 		buf = buffer + 16
   1812 		**(**uintptr)(__ccgo_up(buf)) += uintptr(int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight-libc.Int32FromInt32(1)) * int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   1813 		(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride = -(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride
   1814 	} else {
   1815 		buf1 = buffer + 16
   1816 		H = int64((*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight)
   1817 		**(**uintptr)(__ccgo_up(buf1)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride))
   1818 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fy_stride
   1819 		**(**uintptr)(__ccgo_up(buf1 + 8)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride))
   1820 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fu_stride
   1821 		**(**uintptr)(__ccgo_up(buf1 + 16)) += uintptr((H - int64(1)) >> int32(1) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride))
   1822 		(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fv_stride
   1823 		if (*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa != libc.UintptrFromInt32(0) {
   1824 			**(**uintptr)(__ccgo_up(buf1 + 24)) += uintptr((H - int64(1)) * int64((*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride))
   1825 			(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride = -(*WebPYUVABuffer)(unsafe.Pointer(buf1)).Fa_stride
   1826 		}
   1827 	}
   1828 	return int32(VP8_STATUS_OK)
   1829 }
   1830 
   1831 func WebPAllocateDecBuffer(tls *libc.TLS, width int32, height int32, options uintptr, buffer uintptr) (r VP8StatusCode1) {
   1832 	bp := tls.Alloc(16)
   1833 	defer tls.Free(16)
   1834 	var ch, cw, x, y int32
   1835 	var status VP8StatusCode1
   1836 	var _ /* scaled_height at bp+4 */ int32
   1837 	var _ /* scaled_width at bp+0 */ int32
   1838 	_, _, _, _, _ = ch, cw, status, x, y
   1839 	if buffer == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
   1840 		return int32(VP8_STATUS_INVALID_PARAM)
   1841 	}
   1842 	if options != libc.UintptrFromInt32(0) { // First, apply options if there is any.
   1843 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0 {
   1844 			cw = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
   1845 			ch = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
   1846 			x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left & ^libc.Int32FromInt32(1)
   1847 			y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top & ^libc.Int32FromInt32(1)
   1848 			if !(WebPCheckCropDimensions(tls, width, height, x, y, cw, ch) != 0) {
   1849 				return int32(VP8_STATUS_INVALID_PARAM) // out of frame boundary.
   1850 			}
   1851 			width = cw
   1852 			height = ch
   1853 		}
   1854 		if (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0 {
   1855 			**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
   1856 			**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
   1857 			if !(WebPRescalerGetScaledDimensions(tls, width, height, bp, bp+4) != 0) {
   1858 				return int32(VP8_STATUS_INVALID_PARAM)
   1859 			}
   1860 			width = **(**int32)(__ccgo_up(bp))
   1861 			height = **(**int32)(__ccgo_up(bp + 4))
   1862 		}
   1863 	}
   1864 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fwidth = width
   1865 	(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fheight = height
   1866 	// Then, allocate buffer for real.
   1867 	status = AllocateBuffer(tls, buffer)
   1868 	if status != int32(VP8_STATUS_OK) {
   1869 		return status
   1870 	}
   1871 	// Use the stride trick if vertical flip is needed.
   1872 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   1873 		status = WebPFlipBuffer(tls, buffer)
   1874 	}
   1875 	return status
   1876 }
   1877 
   1878 //------------------------------------------------------------------------------
   1879 // constructors / destructors
   1880 
   1881 func WebPInitDecBufferInternal(tls *libc.TLS, buffer uintptr, version int32) (r int32) {
   1882 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
   1883 		return 0 // version mismatch
   1884 	}
   1885 	if buffer == libc.UintptrFromInt32(0) {
   1886 		return 0
   1887 	}
   1888 	libc.Xmemset(tls, buffer, 0, uint64(120))
   1889 	return int32(1)
   1890 }
   1891 
   1892 func WebPFreeDecBuffer(tls *libc.TLS, buffer uintptr) {
   1893 	if buffer != libc.UintptrFromInt32(0) {
   1894 		if (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fis_external_memory <= 0 {
   1895 			WebPSafeFree(tls, (*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory)
   1896 		}
   1897 		(*WebPDecBuffer)(unsafe.Pointer(buffer)).Fprivate_memory = libc.UintptrFromInt32(0)
   1898 	}
   1899 }
   1900 
   1901 func WebPCopyDecBuffer(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(dst)).Fis_external_memory = int32(1) // dst buffer doesn't own the memory.
   1906 			(*WebPDecBuffer)(unsafe.Pointer(dst)).Fprivate_memory = libc.UintptrFromInt32(0)
   1907 		}
   1908 	}
   1909 }
   1910 
   1911 // C documentation
   1912 //
   1913 //	// Copy and transfer ownership from src to dst (beware of parameter order!)
   1914 func WebPGrabDecBuffer(tls *libc.TLS, src uintptr, dst uintptr) {
   1915 	if src != libc.UintptrFromInt32(0) && dst != libc.UintptrFromInt32(0) {
   1916 		**(**WebPDecBuffer)(__ccgo_up(dst)) = **(**WebPDecBuffer)(__ccgo_up(src))
   1917 		if (*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory != libc.UintptrFromInt32(0) {
   1918 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fis_external_memory = int32(1) // src relinquishes ownership
   1919 			(*WebPDecBuffer)(unsafe.Pointer(src)).Fprivate_memory = libc.UintptrFromInt32(0)
   1920 		}
   1921 	}
   1922 }
   1923 
   1924 func WebPCopyDecBufferPixels(tls *libc.TLS, src_buf uintptr, dst_buf uintptr) (r VP8StatusCode1) {
   1925 	var dst, dst1, src, src1 uintptr
   1926 	var v1, v4 int32
   1927 	var v3, v6 WEBP_CSP_MODE1
   1928 	var v9 bool
   1929 	_, _, _, _, _, _, _, _, _ = dst, dst1, src, src1, v1, v3, v4, v6, v9
   1930 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fwidth = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fwidth
   1931 	(*WebPDecBuffer)(unsafe.Pointer(dst_buf)).Fheight = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fheight
   1932 	if CheckDecBuffer(tls, dst_buf) != int32(VP8_STATUS_OK) {
   1933 		return int32(VP8_STATUS_INVALID_PARAM)
   1934 	}
   1935 	v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace < int32(MODE_YUV))
   1936 	goto _2
   1937 _2:
   1938 	if v1 != 0 {
   1939 		src = src_buf + 16
   1940 		dst = dst_buf + 16
   1941 		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)
   1942 	} else {
   1943 		src1 = src_buf + 16
   1944 		dst1 = dst_buf + 16
   1945 		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)
   1946 		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))
   1947 		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))
   1948 		v3 = (*WebPDecBuffer)(unsafe.Pointer(src_buf)).Fcolorspace
   1949 		if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   1950 			v6 = v3
   1951 			v4 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   1952 			goto _8
   1953 		_8:
   1954 		}
   1955 		v1 = libc.BoolInt32(v9 || v4 != 0)
   1956 		goto _5
   1957 	_5:
   1958 		if v1 != 0 {
   1959 			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)
   1960 		}
   1961 	}
   1962 	return int32(VP8_STATUS_OK)
   1963 }
   1964 
   1965 func WebPAvoidSlowMemory(tls *libc.TLS, output uintptr, features uintptr) (r int32) {
   1966 	var v1 WEBP_CSP_MODE1
   1967 	var v2 int32
   1968 	var v4 bool
   1969 	_, _, _ = v1, v2, v4
   1970 	if v4 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fis_external_memory >= int32(2); v4 {
   1971 		v1 = (*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace
   1972 		v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   1973 		goto _3
   1974 	_3:
   1975 	}
   1976 	return libc.BoolInt32(v4 && v2 != 0 && (features != libc.UintptrFromInt32(0) && (*WebPBitstreamFeatures)(unsafe.Pointer(features)).Fhas_alpha != 0))
   1977 }
   1978 
   1979 const DITHER_AMP_TAB_SIZE = 12
   1980 const MIN_DITHER_AMP = 4
   1981 
   1982 var kHashMul2 = uint32(0x1e35a7bd)
   1983 
   1984 //------------------------------------------------------------------------------
   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 //  Main decoding functions for WebP images.
   1996 //
   1997 // Author: Skal (pascal.massimino@gmail.com)
   1998 
   1999 // Copyright 2010 Google Inc. All Rights Reserved.
   2000 //
   2001 // Use of this source code is governed by a BSD-style license
   2002 // that can be found in the COPYING file in the root of the source
   2003 // tree. An additional intellectual property rights grant can be found
   2004 // in the file PATENTS. All contributing project authors may
   2005 // be found in the AUTHORS file in the root of the source tree.
   2006 // -----------------------------------------------------------------------------
   2007 //
   2008 //  Common types + memory wrappers
   2009 //
   2010 // Author: Skal (pascal.massimino@gmail.com)
   2011 
   2012 //------------------------------------------------------------------------------
   2013 // Main reconstruction function.
   2014 
   2015 var kScan = [16]uint16_t{
   2016 	1:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2017 	2:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2018 	3:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
   2019 	4:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2020 	5:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2021 	6:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2022 	7:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
   2023 	8:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2024 	9:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2025 	10: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2026 	11: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
   2027 	12: libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2028 	13: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2029 	14: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2030 	15: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
   2031 }
   2032 
   2033 func CheckMode(tls *libc.TLS, mb_x int32, mb_y int32, mode int32) (r int32) {
   2034 	var v1 int32
   2035 	_ = v1
   2036 	if mode == int32(B_DC_PRED) {
   2037 		if mb_x == 0 {
   2038 			if mb_y == 0 {
   2039 				v1 = int32(B_DC_PRED_NOTOPLEFT)
   2040 			} else {
   2041 				v1 = int32(B_DC_PRED_NOLEFT)
   2042 			}
   2043 			return v1
   2044 		} else {
   2045 			if mb_y == 0 {
   2046 				v1 = int32(B_DC_PRED_NOTOP)
   2047 			} else {
   2048 				v1 = int32(B_DC_PRED)
   2049 			}
   2050 			return v1
   2051 		}
   2052 	}
   2053 	return mode
   2054 }
   2055 
   2056 func Copy32b(tls *libc.TLS, dst uintptr, src uintptr) {
   2057 	libc.Xmemcpy(tls, dst, src, uint64(4))
   2058 }
   2059 
   2060 func DoTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2061 	switch bits >> libc.Int32FromInt32(30) {
   2062 	case uint32(3):
   2063 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, src, dst, 0)
   2064 	case uint32(2):
   2065 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformAC3})))(tls, src, dst)
   2066 	case uint32(1):
   2067 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, src, dst)
   2068 	default:
   2069 		break
   2070 	}
   2071 }
   2072 
   2073 func DoUVTransform(tls *libc.TLS, bits uint32_t, src uintptr, dst uintptr) {
   2074 	if bits&uint32(0xff) != 0 { // any non-zero coeff at all?
   2075 		if bits&uint32(0xaa) != 0 { // any non-zero AC coefficient?
   2076 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformUV})))(tls, src, dst) // note we don't use the AC3 variant for U/V
   2077 		} else {
   2078 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDCUV})))(tls, src, dst)
   2079 		}
   2080 	}
   2081 }
   2082 
   2083 func ReconstructRow(tls *libc.TLS, dec uintptr, ctx uintptr) {
   2084 	var bits, bits_uv, v8, v9 uint32_t
   2085 	var block, coeffs, dst, top_right, top_yuv, u_dst, u_out, v_dst, v_out, y_dst, y_out uintptr
   2086 	var cache_id, j, mb_x, mb_y, n, pred_func, pred_func1, uv_offset, y_offset int32
   2087 	var v3, v4 uint8_t
   2088 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2089 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2090 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2091 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(1)+libc.Int32FromInt32(8))
   2092 	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))
   2093 	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))
   2094 	// Initialize left-most block.
   2095 	j = 0
   2096 	for {
   2097 		if !(j < int32(16)) {
   2098 			break
   2099 		}
   2100 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2101 		goto _1
   2102 	_1:
   2103 		;
   2104 		j = j + 1
   2105 	}
   2106 	j = 0
   2107 	for {
   2108 		if !(j < int32(8)) {
   2109 			break
   2110 		}
   2111 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2112 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(j*int32(BPS)-int32(1)))) = uint8(129)
   2113 		goto _2
   2114 	_2:
   2115 		;
   2116 		j = j + 1
   2117 	}
   2118 	// Init top-left sample on left column too.
   2119 	if mb_y > 0 {
   2120 		v4 = libc.Uint8FromInt32(129)
   2121 		**(**uint8_t)(__ccgo_up(v_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v4
   2122 		v3 = v4
   2123 		**(**uint8_t)(__ccgo_up(u_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2124 		**(**uint8_t)(__ccgo_up(y_dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))) = v3
   2125 	} else {
   2126 		// we only need to do this init once at block (0,0).
   2127 		// Afterward, it remains valid for the whole topmost row.
   2128 		libc.Xmemset(tls, y_dst-uintptr(BPS)-uintptr(1), int32(127), libc.Uint64FromInt32(libc.Int32FromInt32(16)+libc.Int32FromInt32(4)+libc.Int32FromInt32(1)))
   2129 		libc.Xmemset(tls, u_dst-uintptr(BPS)-uintptr(1), int32(127), libc.Uint64FromInt32(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2130 		libc.Xmemset(tls, v_dst-uintptr(BPS)-uintptr(1), int32(127), libc.Uint64FromInt32(libc.Int32FromInt32(8)+libc.Int32FromInt32(1)))
   2131 	}
   2132 	// Reconstruct one row.
   2133 	mb_x = 0
   2134 	for {
   2135 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   2136 			break
   2137 		}
   2138 		block = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2139 		// Rotate in the left samples from previously decoded block. We move four
   2140 		// pixels at a time for alignment reason, and because of in-loop filter.
   2141 		if mb_x > 0 {
   2142 			j = -int32(1)
   2143 			for {
   2144 				if !(j < int32(16)) {
   2145 					break
   2146 				}
   2147 				Copy32b(tls, y_dst+uintptr(j*int32(BPS)-int32(4)), y_dst+uintptr(j*int32(BPS)+int32(12)))
   2148 				goto _6
   2149 			_6:
   2150 				;
   2151 				j = j + 1
   2152 			}
   2153 			j = -int32(1)
   2154 			for {
   2155 				if !(j < int32(8)) {
   2156 					break
   2157 				}
   2158 				Copy32b(tls, u_dst+uintptr(j*int32(BPS)-int32(4)), u_dst+uintptr(j*int32(BPS)+int32(4)))
   2159 				Copy32b(tls, v_dst+uintptr(j*int32(BPS)-int32(4)), v_dst+uintptr(j*int32(BPS)+int32(4)))
   2160 				goto _7
   2161 			_7:
   2162 				;
   2163 				j = j + 1
   2164 			}
   2165 		}
   2166 		// bring top samples into the cache
   2167 		top_yuv = (*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t + uintptr(mb_x)*32
   2168 		coeffs = block
   2169 		bits = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y
   2170 		if mb_y > 0 {
   2171 			libc.Xmemcpy(tls, y_dst-uintptr(BPS), top_yuv, uint64(16))
   2172 			libc.Xmemcpy(tls, u_dst-uintptr(BPS), top_yuv+16, uint64(8))
   2173 			libc.Xmemcpy(tls, v_dst-uintptr(BPS), top_yuv+24, uint64(8))
   2174 		}
   2175 		// predict and add residuals
   2176 		if (*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0 { // 4x4
   2177 			top_right = y_dst - libc.UintptrFromInt32(BPS) + libc.UintptrFromInt32(16)
   2178 			if mb_y > 0 {
   2179 				if mb_x >= (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w-int32(1) { // on rightmost border
   2180 					libc.Xmemset(tls, top_right, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_yuv + 15))), uint64(4))
   2181 				} else {
   2182 					libc.Xmemcpy(tls, top_right, top_yuv+1*32, uint64(4))
   2183 				}
   2184 			}
   2185 			// replicate the top-right pixels below
   2186 			v9 = **(**uint32_t)(__ccgo_up(top_right))
   2187 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS))*4)) = v9
   2188 			v8 = v9
   2189 			**(**uint32_t)(__ccgo_up(top_right + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS))*4)) = v8
   2190 			**(**uint32_t)(__ccgo_up(top_right + 32*4)) = v8
   2191 			// predict and add residuals for all 4x4 blocks in turn.
   2192 			n = 0
   2193 			for {
   2194 				if !(n < int32(16)) {
   2195 					break
   2196 				}
   2197 				dst = y_dst + uintptr(kScan[n])
   2198 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma4[**(**uint8_t)(__ccgo_up(block + 769 + uintptr(n)))]})))(tls, dst)
   2199 				DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, dst)
   2200 				goto _10
   2201 			_10:
   2202 				;
   2203 				n = n + 1
   2204 				bits = bits << uint32(2)
   2205 			}
   2206 		} else { // 16x16
   2207 			pred_func = CheckMode(tls, mb_x, mb_y, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(block + 769))))
   2208 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredLuma16[pred_func]})))(tls, y_dst)
   2209 			if bits != uint32(0) {
   2210 				n = 0
   2211 				for {
   2212 					if !(n < int32(16)) {
   2213 						break
   2214 					}
   2215 					DoTransform(tls, bits, coeffs+uintptr(n*int32(16))*2, y_dst+uintptr(kScan[n]))
   2216 					goto _11
   2217 				_11:
   2218 					;
   2219 					n = n + 1
   2220 					bits = bits << uint32(2)
   2221 				}
   2222 			}
   2223 		}
   2224 		// Chroma
   2225 		bits_uv = (*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv
   2226 		pred_func1 = CheckMode(tls, mb_x, mb_y, libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(block)).Fuvmode))
   2227 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, u_dst)
   2228 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8PredChroma8[pred_func1]})))(tls, v_dst)
   2229 		DoUVTransform(tls, bits_uv>>0, coeffs+uintptr(libc.Int32FromInt32(16)*libc.Int32FromInt32(16))*2, u_dst)
   2230 		DoUVTransform(tls, bits_uv>>int32(8), coeffs+uintptr(libc.Int32FromInt32(20)*libc.Int32FromInt32(16))*2, v_dst)
   2231 		// stash away top samples for next block
   2232 		if mb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h-int32(1) {
   2233 			libc.Xmemcpy(tls, top_yuv, y_dst+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
   2234 			libc.Xmemcpy(tls, top_yuv+16, u_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2235 			libc.Xmemcpy(tls, top_yuv+24, v_dst+uintptr(libc.Int32FromInt32(7)*libc.Int32FromInt32(BPS)), uint64(8))
   2236 		}
   2237 		// Transfer reconstructed samples from yuv_b cache to final destination.
   2238 		y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2239 		uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2240 		y_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(mb_x*int32(16)) + uintptr(y_offset)
   2241 		u_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2242 		v_out = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(mb_x*int32(8)) + uintptr(uv_offset)
   2243 		j = 0
   2244 		for {
   2245 			if !(j < int32(16)) {
   2246 				break
   2247 			}
   2248 			libc.Xmemcpy(tls, y_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride), y_dst+uintptr(j*int32(BPS)), uint64(16))
   2249 			goto _12
   2250 		_12:
   2251 			;
   2252 			j = j + 1
   2253 		}
   2254 		j = 0
   2255 		for {
   2256 			if !(j < int32(8)) {
   2257 				break
   2258 			}
   2259 			libc.Xmemcpy(tls, u_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), u_dst+uintptr(j*int32(BPS)), uint64(8))
   2260 			libc.Xmemcpy(tls, v_out+uintptr(j*(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride), v_dst+uintptr(j*int32(BPS)), uint64(8))
   2261 			goto _13
   2262 		_13:
   2263 			;
   2264 			j = j + 1
   2265 		}
   2266 		goto _5
   2267 	_5:
   2268 		;
   2269 		mb_x = mb_x + 1
   2270 	}
   2271 }
   2272 
   2273 //------------------------------------------------------------------------------
   2274 // Filtering
   2275 
   2276 // C documentation
   2277 //
   2278 //	// kFilterExtraRows[] = How many extra lines are needed on the MB boundary
   2279 //	// for caching, given a filtering level.
   2280 //	// Simple filter:  up to 2 luma samples are read and 1 is written.
   2281 //	// Complex filter: up to 4 luma samples are read and 3 are written. Same for
   2282 //	//                 U/V, so it's 8 samples total (because of the 2x upsampling).
   2283 var kFilterExtraRows = [3]uint8_t{
   2284 	1: uint8(2),
   2285 	2: uint8(8),
   2286 }
   2287 
   2288 func DoFilter(tls *libc.TLS, dec uintptr, mb_x int32, mb_y int32) {
   2289 	var cache_id, hev_thresh, ilevel, limit, uv_bps, y_bps int32
   2290 	var ctx, f_info, u_dst, v_dst, y_dst uintptr
   2291 	_, _, _, _, _, _, _, _, _, _, _ = cache_id, ctx, f_info, hev_thresh, ilevel, limit, u_dst, uv_bps, v_dst, y_bps, y_dst
   2292 	ctx = dec + 216
   2293 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2294 	y_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2295 	f_info = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info + uintptr(mb_x)*4
   2296 	y_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(cache_id*int32(16)*y_bps) + uintptr(mb_x*int32(16))
   2297 	ilevel = libc.Int32FromUint8((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_ilevel)
   2298 	limit = libc.Int32FromUint8((*VP8FInfo)(unsafe.Pointer(f_info)).Ff_limit)
   2299 	if limit == 0 {
   2300 		return
   2301 	}
   2302 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(1) { // simple
   2303 		if mb_x > 0 {
   2304 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2305 		}
   2306 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2307 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, y_bps, limit)
   2308 		}
   2309 		if mb_y > 0 {
   2310 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16})))(tls, y_dst, y_bps, limit+int32(4))
   2311 		}
   2312 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2313 			(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, y_bps, limit)
   2314 		}
   2315 	} else { // complex
   2316 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2317 		u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2318 		v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2319 		hev_thresh = libc.Int32FromUint8((*VP8FInfo)(unsafe.Pointer(f_info)).Fhev_thresh)
   2320 		if mb_x > 0 {
   2321 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2322 			(*(*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)
   2323 		}
   2324 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2325 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2326 			(*(*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)
   2327 		}
   2328 		if mb_y > 0 {
   2329 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16})))(tls, y_dst, y_bps, limit+int32(4), ilevel, hev_thresh)
   2330 			(*(*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)
   2331 		}
   2332 		if (*VP8FInfo)(unsafe.Pointer(f_info)).Ff_inner != 0 {
   2333 			(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, y_bps, limit, ilevel, hev_thresh)
   2334 			(*(*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)
   2335 		}
   2336 	}
   2337 }
   2338 
   2339 // C documentation
   2340 //
   2341 //	// Filter the decoded macroblock row (if needed)
   2342 func FilterRow(tls *libc.TLS, dec uintptr) {
   2343 	var mb_x, mb_y int32
   2344 	_, _ = mb_x, mb_y
   2345 	mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_y
   2346 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2347 	for {
   2348 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2349 			break
   2350 		}
   2351 		DoFilter(tls, dec, mb_x, mb_y)
   2352 		goto _1
   2353 	_1:
   2354 		;
   2355 		mb_x = mb_x + 1
   2356 	}
   2357 }
   2358 
   2359 //------------------------------------------------------------------------------
   2360 // Precompute the filtering strength for each segment and each i4x4/i16x16 mode.
   2361 
   2362 func PrecomputeFilterStrengths(tls *libc.TLS, dec uintptr) {
   2363 	var base_level, i4x4, ilevel, level, s, v3, v4 int32
   2364 	var hdr, info uintptr
   2365 	_, _, _, _, _, _, _, _, _ = base_level, hdr, i4x4, ilevel, info, level, s, v3, v4
   2366 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2367 		hdr = dec + 84
   2368 		s = 0
   2369 		for {
   2370 			if !(s < int32(NUM_MB_SEGMENTS)) {
   2371 				break
   2372 			}
   2373 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fuse_segment != 0 {
   2374 				base_level = int32(**(**int8_t)(__ccgo_up(dec + 132 + 16 + uintptr(s))))
   2375 				if !((*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fabsolute_delta != 0) {
   2376 					base_level = base_level + (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2377 				}
   2378 			} else {
   2379 				base_level = (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel
   2380 			}
   2381 			i4x4 = 0
   2382 			for {
   2383 				if !(i4x4 <= int32(1)) {
   2384 					break
   2385 				}
   2386 				info = dec + 2924 + uintptr(s)*8 + uintptr(i4x4)*4
   2387 				level = base_level
   2388 				if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
   2389 					level = level + **(**int32)(__ccgo_up(hdr + 16))
   2390 					if i4x4 != 0 {
   2391 						level = level + **(**int32)(__ccgo_up(hdr + 32))
   2392 					}
   2393 				}
   2394 				if level < 0 {
   2395 					v3 = 0
   2396 				} else {
   2397 					if level > int32(63) {
   2398 						v4 = int32(63)
   2399 					} else {
   2400 						v4 = level
   2401 					}
   2402 					v3 = v4
   2403 				}
   2404 				level = v3
   2405 				if level > 0 {
   2406 					ilevel = level
   2407 					if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > 0 {
   2408 						if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness > int32(4) {
   2409 							ilevel = ilevel >> int32(2)
   2410 						} else {
   2411 							ilevel = ilevel >> int32(1)
   2412 						}
   2413 						if ilevel > int32(9)-(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness {
   2414 							ilevel = int32(9) - (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness
   2415 						}
   2416 					}
   2417 					if ilevel < int32(1) {
   2418 						ilevel = int32(1)
   2419 					}
   2420 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_ilevel = libc.Uint8FromInt32(ilevel)
   2421 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = libc.Uint8FromInt32(int32(2)*level + ilevel)
   2422 					if level >= int32(40) {
   2423 						v3 = int32(2)
   2424 					} else {
   2425 						if level >= int32(15) {
   2426 							v4 = int32(1)
   2427 						} else {
   2428 							v4 = 0
   2429 						}
   2430 						v3 = v4
   2431 					}
   2432 					(*VP8FInfo)(unsafe.Pointer(info)).Fhev_thresh = libc.Uint8FromInt32(v3)
   2433 				} else {
   2434 					(*VP8FInfo)(unsafe.Pointer(info)).Ff_limit = uint8(0) // no filtering
   2435 				}
   2436 				(*VP8FInfo)(unsafe.Pointer(info)).Ff_inner = libc.Uint8FromInt32(i4x4)
   2437 				goto _2
   2438 			_2:
   2439 				;
   2440 				i4x4 = i4x4 + 1
   2441 			}
   2442 			goto _1
   2443 		_1:
   2444 			;
   2445 			s = s + 1
   2446 		}
   2447 	}
   2448 }
   2449 
   2450 //------------------------------------------------------------------------------
   2451 // Dithering
   2452 
   2453 // minimal amp that will provide a non-zero dithering effect
   2454 
   2455 var kQuantToDitherAmp = [12]uint8_t{
   2456 	0:  uint8(8),
   2457 	1:  uint8(7),
   2458 	2:  uint8(6),
   2459 	3:  uint8(4),
   2460 	4:  uint8(4),
   2461 	5:  uint8(2),
   2462 	6:  uint8(2),
   2463 	7:  uint8(2),
   2464 	8:  uint8(1),
   2465 	9:  uint8(1),
   2466 	10: uint8(1),
   2467 	11: uint8(1),
   2468 }
   2469 
   2470 func VP8InitDithering(tls *libc.TLS, options uintptr, dec uintptr) {
   2471 	var all_amp, d, f, idx, max_amp, s, v1, v2, v4 int32
   2472 	var dqm uintptr
   2473 	_, _, _, _, _, _, _, _, _, _ = all_amp, d, dqm, f, idx, max_amp, s, v1, v2, v4
   2474 	if options != libc.UintptrFromInt32(0) {
   2475 		d = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fdithering_strength
   2476 		max_amp = libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX) - libc.Int32FromInt32(1)
   2477 		if d < 0 {
   2478 			v1 = 0
   2479 		} else {
   2480 			if d > int32(100) {
   2481 				v2 = max_amp
   2482 			} else {
   2483 				v2 = d * max_amp / int32(100)
   2484 			}
   2485 			v1 = v2
   2486 		}
   2487 		f = v1
   2488 		if f > 0 {
   2489 			all_amp = 0
   2490 			s = 0
   2491 			for {
   2492 				if !(s < int32(NUM_MB_SEGMENTS)) {
   2493 					break
   2494 				}
   2495 				dqm = dec + 1060 + uintptr(s)*32
   2496 				if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < int32(DITHER_AMP_TAB_SIZE) {
   2497 					if (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant < 0 {
   2498 						v4 = 0
   2499 					} else {
   2500 						v4 = (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fuv_quant
   2501 					}
   2502 					idx = v4
   2503 					(*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither = f * libc.Int32FromUint8(kQuantToDitherAmp[idx]) >> int32(3)
   2504 				}
   2505 				all_amp = all_amp | (*VP8QuantMatrix)(unsafe.Pointer(dqm)).Fdither
   2506 				goto _3
   2507 			_3:
   2508 				;
   2509 				s = s + 1
   2510 			}
   2511 			if all_amp != 0 {
   2512 				VP8InitRandom(tls, dec+828, libc.Float32FromFloat32(1))
   2513 				(*VP8Decoder)(unsafe.Pointer(dec)).Fdither = int32(1)
   2514 			}
   2515 		}
   2516 		// potentially allow alpha dithering
   2517 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = (*WebPDecoderOptions)(unsafe.Pointer(options)).Falpha_dithering_strength
   2518 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering > int32(100) {
   2519 			(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = int32(100)
   2520 		} else {
   2521 			if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering < 0 {
   2522 				(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_dithering = 0
   2523 			}
   2524 		}
   2525 	}
   2526 }
   2527 
   2528 // C documentation
   2529 //
   2530 //	// Convert to range: [-2,2] for dither=50, [-4,4] for dither=100
   2531 func Dither8x8(tls *libc.TLS, rg1 uintptr, dst uintptr, bps int32, amp1 int32) {
   2532 	bp := tls.Alloc(64)
   2533 	defer tls.Free(64)
   2534 	var diff, i, v3, v4, v6, v8 int32
   2535 	var v2, v5, v7 uintptr
   2536 	var _ /* dither at bp+0 */ [64]uint8_t
   2537 	_, _, _, _, _, _, _, _, _ = diff, i, v2, v3, v4, v5, v6, v7, v8
   2538 	i = 0
   2539 	for {
   2540 		if !(i < libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) {
   2541 			break
   2542 		}
   2543 		v2 = rg1
   2544 		v3 = libc.Int32FromInt32(VP8_DITHER_AMP_BITS) + libc.Int32FromInt32(1)
   2545 		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)))
   2546 		if diff < libc.Int32FromInt32(0) {
   2547 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
   2548 		}
   2549 		**(**uint32_t)(__ccgo_up(v2 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v2)).Findex1)*4)) = libc.Uint32FromInt32(diff)
   2550 		v5 = v2
   2551 		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
   2552 		v4 = *(*int32)(unsafe.Pointer(v5))
   2553 		if v4 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2554 			(*VP8Random)(unsafe.Pointer(v2)).Findex1 = 0
   2555 		}
   2556 		v7 = v2 + 4
   2557 		*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
   2558 		v6 = *(*int32)(unsafe.Pointer(v7))
   2559 		if v6 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
   2560 			(*VP8Random)(unsafe.Pointer(v2)).Findex2 = 0
   2561 		}
   2562 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v3)
   2563 		diff = diff * amp1 >> int32(VP8_RANDOM_DITHER_FIX)
   2564 		diff = diff + int32(1)<<(v3-int32(1))
   2565 		v8 = diff
   2566 		goto _9
   2567 	_9:
   2568 		(**(**[64]uint8_t)(__ccgo_up(bp)))[i] = libc.Uint8FromInt32(v8)
   2569 		goto _1
   2570 	_1:
   2571 		;
   2572 		i = i + 1
   2573 	}
   2574 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8DitherCombine8x8})))(tls, bp, dst, bps)
   2575 }
   2576 
   2577 func DitherRow(tls *libc.TLS, dec uintptr) {
   2578 	var cache_id, mb_x, uv_bps int32
   2579 	var ctx, data, u_dst, v_dst uintptr
   2580 	_, _, _, _, _, _, _ = cache_id, ctx, data, mb_x, u_dst, uv_bps, v_dst
   2581 	mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x
   2582 	for {
   2583 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x) {
   2584 			break
   2585 		}
   2586 		ctx = dec + 216
   2587 		data = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data + uintptr(mb_x)*800
   2588 		cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2589 		uv_bps = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2590 		if libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(data)).Fdither) >= int32(MIN_DITHER_AMP) {
   2591 			u_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2592 			v_dst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(cache_id*int32(8)*uv_bps) + uintptr(mb_x*int32(8))
   2593 			Dither8x8(tls, dec+828, u_dst, uv_bps, libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2594 			Dither8x8(tls, dec+828, v_dst, uv_bps, libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(data)).Fdither))
   2595 		}
   2596 		goto _1
   2597 	_1:
   2598 		;
   2599 		mb_x = mb_x + 1
   2600 	}
   2601 }
   2602 
   2603 //------------------------------------------------------------------------------
   2604 // This function is called after a row of macroblocks is finished decoding.
   2605 // It also takes into account the following restrictions:
   2606 //  * In case of in-loop filtering, we must hold off sending some of the bottom
   2607 //    pixels as they are yet unfiltered. They will be when the next macroblock
   2608 //    row is decoded. Meanwhile, we must preserve them by rotating them in the
   2609 //    cache area. This doesn't hold for the very bottom row of the uncropped
   2610 //    picture of course.
   2611 //  * we must clip the remaining pixels against the cropping area. The VP8Io
   2612 //    struct must have the following fields set correctly before calling put():
   2613 
   2614 // C documentation
   2615 //
   2616 //	// Finalize and transmit a complete row. Return false in case of user-abort.
   2617 func FinishRow(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
   2618 	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
   2619 	var ctx, dec, io, udst, vdst, ydst uintptr
   2620 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2621 	dec = arg1
   2622 	io = arg2
   2623 	ok = int32(1)
   2624 	ctx = dec + 216
   2625 	cache_id = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid
   2626 	extra_y_rows = libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2627 	ysize = extra_y_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2628 	uvsize = extra_y_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2629 	y_offset = cache_id * int32(16) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2630 	uv_offset = cache_id * int32(8) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2631 	ydst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y - uintptr(ysize) + uintptr(y_offset)
   2632 	udst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u - uintptr(uvsize) + uintptr(uv_offset)
   2633 	vdst = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v - uintptr(uvsize) + uintptr(uv_offset)
   2634 	mb_y = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y
   2635 	is_first_row = libc.BoolInt32(mb_y == libc.Int32FromInt32(0))
   2636 	is_last_row = libc.BoolInt32(mb_y >= (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y-libc.Int32FromInt32(1))
   2637 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2638 		ReconstructRow(tls, dec, ctx)
   2639 	}
   2640 	if (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row != 0 {
   2641 		FilterRow(tls, dec)
   2642 	}
   2643 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fdither != 0 {
   2644 		DitherRow(tls, dec)
   2645 	}
   2646 	if (*VP8Io)(unsafe.Pointer(io)).Fput != libc.UintptrFromInt32(0) {
   2647 		y_start = mb_y * int32(16)
   2648 		y_end = (mb_y + int32(1)) * int32(16)
   2649 		if !(is_first_row != 0) {
   2650 			y_start = y_start - extra_y_rows
   2651 			(*VP8Io)(unsafe.Pointer(io)).Fy = ydst
   2652 			(*VP8Io)(unsafe.Pointer(io)).Fu = udst
   2653 			(*VP8Io)(unsafe.Pointer(io)).Fv = vdst
   2654 		} else {
   2655 			(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y + uintptr(y_offset)
   2656 			(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u + uintptr(uv_offset)
   2657 			(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v + uintptr(uv_offset)
   2658 		}
   2659 		if !(is_last_row != 0) {
   2660 			y_end = y_end - extra_y_rows
   2661 		}
   2662 		if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   2663 			y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
   2664 		}
   2665 		// If dec->alpha_data is not NULL, we have some alpha plane present.
   2666 		(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   2667 		if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && y_start < y_end {
   2668 			(*VP8Io)(unsafe.Pointer(io)).Fa = VP8DecompressAlphaRows(tls, dec, io, y_start, y_end-y_start)
   2669 			if (*VP8Io)(unsafe.Pointer(io)).Fa == libc.UintptrFromInt32(0) {
   2670 				return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+37)
   2671 			}
   2672 		}
   2673 		if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
   2674 			delta_y = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
   2675 			y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2676 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride * delta_y)
   2677 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2678 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride * (delta_y >> libc.Int32FromInt32(1)))
   2679 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2680 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth * delta_y)
   2681 			}
   2682 		}
   2683 		if y_start < y_end {
   2684 			**(**uintptr)(__ccgo_up(io + 24)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2685 			**(**uintptr)(__ccgo_up(io + 32)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2686 			**(**uintptr)(__ccgo_up(io + 40)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left >> int32(1))
   2687 			if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   2688 				**(**uintptr)(__ccgo_up(io + 152)) += uintptr((*VP8Io)(unsafe.Pointer(io)).Fcrop_left)
   2689 			}
   2690 			(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
   2691 			(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
   2692 			(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
   2693 			ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fput})))(tls, io)
   2694 		}
   2695 	}
   2696 	// rotate top samples if needed
   2697 	if cache_id+int32(1) == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   2698 		if !(is_last_row != 0) {
   2699 			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))
   2700 			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))
   2701 			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))
   2702 		}
   2703 	}
   2704 	return ok
   2705 }
   2706 
   2707 //------------------------------------------------------------------------------
   2708 
   2709 func VP8ProcessRow(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   2710 	var ctx, tmp, tmp1, worker, v2 uintptr
   2711 	var filter_row, ok, v1 int32
   2712 	_, _, _, _, _, _, _, _ = ctx, filter_row, ok, tmp, tmp1, worker, v1, v2
   2713 	ok = int32(1)
   2714 	ctx = dec + 216
   2715 	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)
   2716 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == 0 {
   2717 		// ctx->id and ctx->f_info are already set
   2718 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   2719 		(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   2720 		ReconstructRow(tls, dec, ctx)
   2721 		ok = FinishRow(tls, dec, io)
   2722 	} else {
   2723 		worker = dec + 152
   2724 		// Finish previous job *before* updating context
   2725 		ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
   2726 		if ok != 0 { // spawn a new deblocking/output job
   2727 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fio = **(**VP8Io)(__ccgo_up(io))
   2728 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fid = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id
   2729 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   2730 			(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ffilter_row = filter_row
   2731 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) { // swap macroblock data
   2732 				tmp = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data
   2733 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Fmb_data = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data
   2734 				(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = tmp
   2735 			} else {
   2736 				// perform reconstruction directly in main thread
   2737 				ReconstructRow(tls, dec, ctx)
   2738 			}
   2739 			if filter_row != 0 { // swap filter info
   2740 				tmp1 = (*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info
   2741 				(*VP8ThreadContext)(unsafe.Pointer(ctx)).Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   2742 				(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = tmp1
   2743 			}
   2744 			// (reconstruct)+filter in parallel
   2745 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
   2746 			v2 = dec + 204
   2747 			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
   2748 			v1 = *(*int32)(unsafe.Pointer(v2))
   2749 			if v1 == (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches {
   2750 				(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   2751 			}
   2752 		}
   2753 	}
   2754 	return ok
   2755 }
   2756 
   2757 //------------------------------------------------------------------------------
   2758 // Finish setting up the decoding parameter once user's setup() is called.
   2759 
   2760 func VP8EnterCritical(tls *libc.TLS, dec uintptr, io uintptr) (r VP8StatusCode1) {
   2761 	var extra_pixels int32
   2762 	_ = extra_pixels
   2763 	// Call setup() first. This may trigger additional decoding features on 'io'.
   2764 	// Note: Afterward, we must call teardown() no matter what.
   2765 	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) {
   2766 		VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+66)
   2767 		return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   2768 	}
   2769 	// Disable filtering per user request
   2770 	if (*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering != 0 {
   2771 		(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = 0
   2772 	}
   2773 	// Define the area where we can skip in-loop filtering, in case of cropping.
   2774 	//
   2775 	// 'Simple' filter reads two luma samples outside of the macroblock
   2776 	// and filters one. It doesn't filter the chroma samples. Hence, we can
   2777 	// avoid doing the in-loop filtering before crop_top/crop_left position.
   2778 	// For the 'Complex' filter, 3 samples are read and up to 3 are filtered.
   2779 	// Means: there's a dependency chain that goes all the way up to the
   2780 	// top-left corner of the picture (MB #0). We must filter all the previous
   2781 	// macroblocks.
   2782 	extra_pixels = libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2783 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type == int32(2) {
   2784 		// For complex filter, we need to preserve the dependency chain.
   2785 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   2786 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   2787 	} else {
   2788 		// For simple filter, we can filter only the cropped region.
   2789 		// We include 'extra_pixels' on the other side of the boundary, since
   2790 		// vertical or horizontal filtering of the previous macroblock can
   2791 		// modify some abutting pixels.
   2792 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_left - extra_pixels) >> int32(4)
   2793 		(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_top - extra_pixels) >> int32(4)
   2794 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x < 0 {
   2795 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_x = 0
   2796 		}
   2797 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y < 0 {
   2798 			(*VP8Decoder)(unsafe.Pointer(dec)).Ftl_mb_y = 0
   2799 		}
   2800 	}
   2801 	// We need some 'extra' pixels on the right/bottom.
   2802 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom + int32(15) + extra_pixels) >> int32(4)
   2803 	(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = ((*VP8Io)(unsafe.Pointer(io)).Fcrop_right + int32(15) + extra_pixels) >> int32(4)
   2804 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w {
   2805 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   2806 	}
   2807 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y > (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h {
   2808 		(*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h
   2809 	}
   2810 	PrecomputeFilterStrengths(tls, dec)
   2811 	return int32(VP8_STATUS_OK)
   2812 }
   2813 
   2814 func VP8ExitCritical(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   2815 	var ok int32
   2816 	_ = ok
   2817 	ok = int32(1)
   2818 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2819 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152)
   2820 	}
   2821 	if (*VP8Io)(unsafe.Pointer(io)).Fteardown != libc.UintptrFromInt32(0) {
   2822 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*VP8Io)(unsafe.Pointer(io)).Fteardown})))(tls, io)
   2823 	}
   2824 	return ok
   2825 }
   2826 
   2827 //------------------------------------------------------------------------------
   2828 // For multi-threaded decoding we need to use 3 rows of 16 pixels as delay line.
   2829 //
   2830 // Reason is: the deblocking filter cannot deblock the bottom horizontal edges
   2831 // immediately, and needs to wait for first few rows of the next macroblock to
   2832 // be decoded. Hence, deblocking is lagging behind by 4 or 8 pixels (depending
   2833 // on strength).
   2834 // With two threads, the vertical positions of the rows being decoded are:
   2835 // Decode:  [ 0..15][16..31][32..47][48..63][64..79][...
   2836 // Deblock:         [ 0..11][12..27][28..43][44..59][...
   2837 // If we use two threads and two caches of 16 pixels, the sequence would be:
   2838 // Decode:  [ 0..15][16..31][ 0..15!!][16..31][ 0..15][...
   2839 // Deblock:         [ 0..11][12..27!!][-4..11][12..27][...
   2840 // The problem occurs during row [12..15!!] that both the decoding and
   2841 // deblocking threads are writing simultaneously.
   2842 // With 3 cache lines, one get a safe write pattern:
   2843 // Decode:  [ 0..15][16..31][32..47][ 0..15][16..31][32..47][0..
   2844 // Deblock:         [ 0..11][12..27][28..43][-4..11][12..27][28...
   2845 // Note that multi-threaded output _without_ deblocking can make use of two
   2846 // cache lines of 16 pixels only, since there's no lagging behind. The decoding
   2847 // and output process have non-concurrent writing:
   2848 // Decode:  [ 0..15][16..31][ 0..15][16..31][...
   2849 // io->put:         [ 0..15][16..31][ 0..15][...
   2850 
   2851 // C documentation
   2852 //
   2853 //	// Initialize multi/single-thread worker
   2854 func InitThreadContext(tls *libc.TLS, dec uintptr) (r int32) {
   2855 	var worker uintptr
   2856 	var v1 int32
   2857 	_, _ = worker, v1
   2858 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   2859 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2860 		worker = dec + 152
   2861 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
   2862 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+85)
   2863 		}
   2864 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = dec
   2865 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = dec + 216 + 32
   2866 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(FinishRow)
   2867 		if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2868 			v1 = int32(3)
   2869 		} else {
   2870 			v1 = libc.Int32FromInt32(3) - libc.Int32FromInt32(1)
   2871 		}
   2872 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = v1
   2873 	} else {
   2874 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches = int32(1)
   2875 	}
   2876 	return int32(1)
   2877 }
   2878 
   2879 func VP8GetThreadMethod(tls *libc.TLS, options uintptr, headers uintptr, width int32, height int32) (r int32) {
   2880 	if options == libc.UintptrFromInt32(0) || (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_threads == 0 {
   2881 		return 0
   2882 	}
   2883 	_ = headers
   2884 	_ = width
   2885 	_ = height
   2886 	return 0
   2887 }
   2888 
   2889 //------------------------------------------------------------------------------
   2890 // Memory setup
   2891 
   2892 func AllocateMemory(tls *libc.TLS, dec uintptr) (r int32) {
   2893 	var alpha_size, needed, v5 uint64_t
   2894 	var cache_height, cache_size, f_info_size, intra_pred_mode_size, mb_data_size, mb_info_size, top_size, yuv_size size_t
   2895 	var extra_rows, extra_uv, extra_y, mb_w, num_caches, v2, v3, v6 int32
   2896 	var mem, v8 uintptr
   2897 	var v1, v4 uint64
   2898 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   2899 	num_caches = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_caches
   2900 	mb_w = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w
   2901 	// Note: we use 'size_t' when there's no overflow risk, uint64_t otherwise.
   2902 	intra_pred_mode_size = libc.Uint64FromInt32(int32(4)*mb_w) * uint64(1)
   2903 	top_size = uint64(32) * libc.Uint64FromInt32(mb_w)
   2904 	mb_info_size = libc.Uint64FromInt32(mb_w+libc.Int32FromInt32(1)) * uint64(2)
   2905 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 {
   2906 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2907 			v2 = int32(2)
   2908 		} else {
   2909 			v2 = int32(1)
   2910 		}
   2911 		v1 = libc.Uint64FromInt32(mb_w*v2) * uint64(4)
   2912 	} else {
   2913 		v1 = uint64(0)
   2914 	}
   2915 	f_info_size = v1
   2916 	yuv_size = libc.Uint64FromInt32(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(17)+libc.Int32FromInt32(BPS)*libc.Int32FromInt32(9)) * libc.Uint64FromInt64(1)
   2917 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2918 		v3 = int32(2)
   2919 	} else {
   2920 		v3 = int32(1)
   2921 	}
   2922 	mb_data_size = libc.Uint64FromInt32(v3*mb_w) * uint64(800)
   2923 	cache_height = libc.Uint64FromInt32((int32(16)*num_caches + libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])) * int32(3) / int32(2))
   2924 	cache_size = top_size * cache_height
   2925 	if (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) {
   2926 		v4 = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fwidth) * uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fpic_hdr.Fheight)
   2927 	} else {
   2928 		v4 = 0
   2929 	}
   2930 	// alpha_size is the only one that scales as width x height.
   2931 	alpha_size = v4
   2932 	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)
   2933 	v5 = needed
   2934 	v6 = libc.BoolInt32(v5 == v5)
   2935 	goto _7
   2936 _7:
   2937 	if !(v6 != 0) {
   2938 		return 0
   2939 	} // check for overflow
   2940 	if needed > (*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size {
   2941 		WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
   2942 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
   2943 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = WebPSafeMalloc(tls, needed, uint64(1))
   2944 		if (*VP8Decoder)(unsafe.Pointer(dec)).Fmem == libc.UintptrFromInt32(0) {
   2945 			return VP8SetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY), __ccgo_ts+115)
   2946 		}
   2947 		// down-cast is ok, thanks to WebPSafeMalloc() above.
   2948 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = needed
   2949 	}
   2950 	mem = (*VP8Decoder)(unsafe.Pointer(dec)).Fmem
   2951 	(*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t = mem
   2952 	mem = mem + uintptr(intra_pred_mode_size)
   2953 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_t = mem
   2954 	mem = mem + uintptr(top_size)
   2955 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info = mem + uintptr(1)*2
   2956 	mem = mem + uintptr(mb_info_size)
   2957 	if f_info_size != 0 {
   2958 		v8 = mem
   2959 	} else {
   2960 		v8 = libc.UintptrFromInt32(0)
   2961 	}
   2962 	(*VP8Decoder)(unsafe.Pointer(dec)).Ff_info = v8
   2963 	mem = mem + uintptr(f_info_size)
   2964 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fid = 0
   2965 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info
   2966 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 && (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   2967 		// secondary cache line. The deblocking process need to make use of the
   2968 		// filtering strength from previous macroblock row, while the new ones
   2969 		// are being decoded in parallel. We'll just swap the pointers.
   2970 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Ff_info += uintptr(mb_w) * 4
   2971 	}
   2972 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   2973 	(*VP8Decoder)(unsafe.Pointer(dec)).Fyuv_b = mem
   2974 	mem = mem + uintptr(yuv_size)
   2975 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data = mem
   2976 	(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data = mem
   2977 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method == int32(2) {
   2978 		(*VP8Decoder)(unsafe.Pointer(dec)).Fthread_ctx.Fmb_data += uintptr(mb_w) * 800
   2979 	}
   2980 	mem = mem + uintptr(mb_data_size)
   2981 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride = int32(16) * mb_w
   2982 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride = int32(8) * mb_w
   2983 	extra_rows = libc.Int32FromUint8(kFilterExtraRows[(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type])
   2984 	extra_y = extra_rows * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   2985 	extra_uv = extra_rows / int32(2) * (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   2986 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y = mem + uintptr(extra_y)
   2987 	(*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)
   2988 	(*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)
   2989 	(*VP8Decoder)(unsafe.Pointer(dec)).Fcache_id = 0
   2990 	mem = mem + uintptr(cache_size)
   2991 	// alpha plane
   2992 	if alpha_size != 0 {
   2993 		v8 = mem
   2994 	} else {
   2995 		v8 = libc.UintptrFromInt32(0)
   2996 	}
   2997 	(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_plane = v8
   2998 	mem = mem + uintptr(alpha_size)
   2999 	// note: left/top-info is initialized once for all.
   3000 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info-uintptr(1)*2, 0, mb_info_size)
   3001 	VP8InitScanline(tls, dec) // initialize left too.
   3002 	// initialize top
   3003 	libc.Xmemset(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t, int32(B_DC_PRED), intra_pred_mode_size)
   3004 	return int32(1)
   3005 }
   3006 
   3007 func InitIo(tls *libc.TLS, dec uintptr, io uintptr) {
   3008 	// prepare 'io'
   3009 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = 0
   3010 	(*VP8Io)(unsafe.Pointer(io)).Fy = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y
   3011 	(*VP8Io)(unsafe.Pointer(io)).Fu = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_u
   3012 	(*VP8Io)(unsafe.Pointer(io)).Fv = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_v
   3013 	(*VP8Io)(unsafe.Pointer(io)).Fy_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_y_stride
   3014 	(*VP8Io)(unsafe.Pointer(io)).Fuv_stride = (*VP8Decoder)(unsafe.Pointer(dec)).Fcache_uv_stride
   3015 	(*VP8Io)(unsafe.Pointer(io)).Fa = libc.UintptrFromInt32(0)
   3016 }
   3017 
   3018 func VP8InitFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
   3019 	if !(InitThreadContext(tls, dec) != 0) {
   3020 		return 0
   3021 	} // call first. Sets dec->num_caches.
   3022 	if !(AllocateMemory(tls, dec) != 0) {
   3023 		return 0
   3024 	}
   3025 	InitIo(tls, dec, io)
   3026 	VP8DspInit(tls) // Init critical function pointers and look-up tables.
   3027 	return int32(1)
   3028 }
   3029 
   3030 const CHUNK_SIZE = 4096
   3031 const MAX_MB_SIZE = 4096
   3032 
   3033 type WebPIDecoder = struct {
   3034 	Fstate        DecState
   3035 	Fparams       WebPDecParams
   3036 	Fis_lossless  int32
   3037 	Fdec          uintptr
   3038 	Fio           VP8Io
   3039 	Fmem          MemBuffer
   3040 	Foutput       WebPDecBuffer
   3041 	Ffinal_output uintptr
   3042 	Fchunk_size   size_t
   3043 	Flast_mb_y    int32
   3044 }
   3045 
   3046 const STATE_WEBP_HEADER = 0
   3047 const // All the data before that of the VP8/VP8L chunk.
   3048 STATE_VP8_HEADER = 1
   3049 const // The VP8 Frame header (within the VP8 chunk).
   3050 STATE_VP8_PARTS0 = 2
   3051 const STATE_VP8_DATA = 3
   3052 const STATE_VP8L_HEADER = 4
   3053 const STATE_VP8L_DATA = 5
   3054 const STATE_DONE = 6
   3055 const STATE_ERROR = 7
   3056 
   3057 var kHashMul3 = uint32(0x1e35a7bd)
   3058 
   3059 //------------------------------------------------------------------------------
   3060 
   3061 // Copyright 2010 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 //  Main decoding functions for WebP images.
   3071 //
   3072 // Author: Skal (pascal.massimino@gmail.com)
   3073 
   3074 // Copyright 2012 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 //  Internal header for constants related to WebP file format.
   3084 //
   3085 // Author: Urvang (urvang@google.com)
   3086 
   3087 // Copyright 2010 Google Inc. All Rights Reserved.
   3088 //
   3089 // Use of this source code is governed by a BSD-style license
   3090 // that can be found in the COPYING file in the root of the source
   3091 // tree. An additional intellectual property rights grant can be found
   3092 // in the file PATENTS. All contributing project authors may
   3093 // be found in the AUTHORS file in the root of the source tree.
   3094 // -----------------------------------------------------------------------------
   3095 //
   3096 //  Common types + memory wrappers
   3097 //
   3098 // Author: Skal (pascal.massimino@gmail.com)
   3099 
   3100 // In append mode, buffer allocations increase as multiples of this value.
   3101 // Needs to be a power of 2.
   3102 
   3103 //------------------------------------------------------------------------------
   3104 // Data structures for memory and states
   3105 
   3106 // C documentation
   3107 //
   3108 //	// Decoding states. State normally flows as:
   3109 //	// WEBP_HEADER->VP8_HEADER->VP8_PARTS0->VP8_DATA->DONE for a lossy image, and
   3110 //	// WEBP_HEADER->VP8L_HEADER->VP8L_DATA->DONE for a lossless image.
   3111 //	// If there is any error the decoder goes into state ERROR.
   3112 type DecState = int32
   3113 
   3114 // C documentation
   3115 //
   3116 //	// Operating state for the MemBuffer
   3117 type MemBufferMode = int32
   3118 
   3119 const MEM_MODE_NONE = 0
   3120 const MEM_MODE_APPEND = 1
   3121 const MEM_MODE_MAP = 2
   3122 
   3123 // C documentation
   3124 //
   3125 //	// storage for partition #0 and partial data (in a rolling fashion)
   3126 type MemBuffer = struct {
   3127 	Fmode       MemBufferMode
   3128 	Fstart      size_t
   3129 	Fend        size_t
   3130 	Fbuf_size   size_t
   3131 	Fbuf        uintptr
   3132 	Fpart0_size size_t
   3133 	Fpart0_buf  uintptr
   3134 }
   3135 
   3136 // C documentation
   3137 //
   3138 //	// MB context to restore in case VP8DecodeMB() fails
   3139 type MBContext = struct {
   3140 	Fleft     VP8MB
   3141 	Finfo     VP8MB
   3142 	Ftoken_br VP8BitReader
   3143 }
   3144 
   3145 //------------------------------------------------------------------------------
   3146 // MemBuffer: incoming data handling
   3147 
   3148 func MemDataSize(tls *libc.TLS, mem uintptr) (r size_t) {
   3149 	return (*MemBuffer)(unsafe.Pointer(mem)).Fend - (*MemBuffer)(unsafe.Pointer(mem)).Fstart
   3150 }
   3151 
   3152 // C documentation
   3153 //
   3154 //	// Check if we need to preserve the compressed alpha data, as it may not have
   3155 //	// been decoded yet.
   3156 func NeedCompressedAlpha(tls *libc.TLS, idec uintptr) (r int32) {
   3157 	var dec uintptr
   3158 	_ = dec
   3159 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3160 		// We haven't parsed the headers yet, so we don't know whether the image is
   3161 		// lossy or lossless. This also means that we haven't parsed the ALPH chunk.
   3162 		return 0
   3163 	}
   3164 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0 {
   3165 		return 0 // ALPH chunk is not present for lossless images.
   3166 	} else {
   3167 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3168 		// Must be true as idec->state != STATE_WEBP_HEADER.
   3169 		return libc.BoolInt32((*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data != libc.UintptrFromInt32(0) && !((*VP8Decoder)(unsafe.Pointer(dec)).Fis_alpha_decoded != 0))
   3170 	}
   3171 	return r
   3172 }
   3173 
   3174 func DoRemap(tls *libc.TLS, idec uintptr, offset ptrdiff_t) {
   3175 	var alph_dec, alph_vp8l_dec, dec, dec1, last_start, mem, new_base uintptr
   3176 	var last_part, p uint32_t
   3177 	_, _, _, _, _, _, _, _, _ = alph_dec, alph_vp8l_dec, dec, dec1, last_part, last_start, mem, new_base, p
   3178 	mem = idec + 296
   3179 	new_base = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3180 	// note: for VP8, setting up idec->io is only really needed at the beginning
   3181 	// of the decoding, till partition #0 is complete.
   3182 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = new_base
   3183 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3184 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   3185 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3186 			dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3187 			last_part = (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one
   3188 			if offset != 0 {
   3189 				p = uint32(0)
   3190 				for {
   3191 					if !(p <= last_part) {
   3192 						break
   3193 					}
   3194 					VP8RemapBitReader(tls, dec+440+uintptr(p)*48, offset)
   3195 					goto _1
   3196 				_1:
   3197 					;
   3198 					p = p + 1
   3199 				}
   3200 				// Remap partition #0 data pointer to new offset, but only in MAP
   3201 				// mode (in APPEND mode, partition #0 is copied into a fixed memory).
   3202 				if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_MAP) {
   3203 					VP8RemapBitReader(tls, dec+16, offset)
   3204 				}
   3205 			}
   3206 			last_start = (**(**VP8BitReader)(__ccgo_up(dec + 440 + uintptr(last_part)*48))).Fbuf
   3207 			// 'last_start' will be NULL when 'idec->state' is < STATE_VP8_PARTS0
   3208 			// and through a portion of that state (when there isn't enough data to
   3209 			// parse the partitions). The bitreader is only used meaningfully when
   3210 			// there is enough data to begin parsing partition 0.
   3211 			if last_start != libc.UintptrFromInt32(0) {
   3212 				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)))
   3213 			}
   3214 			if NeedCompressedAlpha(tls, idec) != 0 {
   3215 				alph_dec = (*VP8Decoder)(unsafe.Pointer(dec)).Falph_dec
   3216 				**(**uintptr)(__ccgo_up(dec + 2968)) += uintptr(offset)
   3217 				if alph_dec != libc.UintptrFromInt32(0) && (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec != libc.UintptrFromInt32(0) {
   3218 					if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fmethod == int32(ALPHA_LOSSLESS_COMPRESSION) {
   3219 						alph_vp8l_dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
   3220 						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))
   3221 					} else { // alph_dec->method == ALPHA_NO_COMPRESSION
   3222 						// Nothing special to do in this case.
   3223 					}
   3224 				}
   3225 			}
   3226 		} else { // Resize lossless bitreader
   3227 			dec1 = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3228 			VP8LBitReaderSetBuffer(tls, dec1+40, new_base, MemDataSize(tls, mem))
   3229 		}
   3230 	}
   3231 }
   3232 
   3233 // C documentation
   3234 //
   3235 //	// Appends data to the end of MemBuffer->buf. It expands the allocated memory
   3236 //	// size if required and also updates VP8BitReader's if new memory is allocated.
   3237 func AppendToMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3238 	var current_size, new_mem_start size_t
   3239 	var dec, mem, new_buf, old_base, old_start, v1, v2 uintptr
   3240 	var extra_size, new_size uint64_t
   3241 	var need_compressed_alpha int32
   3242 	_, _, _, _, _, _, _, _, _, _, _, _ = current_size, dec, extra_size, mem, need_compressed_alpha, new_buf, new_mem_start, new_size, old_base, old_start, v1, v2
   3243 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3244 	mem = idec + 296
   3245 	need_compressed_alpha = NeedCompressedAlpha(tls, idec)
   3246 	if (*MemBuffer)(unsafe.Pointer(mem)).Fbuf == libc.UintptrFromInt32(0) {
   3247 		v1 = libc.UintptrFromInt32(0)
   3248 	} else {
   3249 		v1 = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3250 	}
   3251 	old_start = v1
   3252 	if need_compressed_alpha != 0 {
   3253 		v2 = (*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data
   3254 	} else {
   3255 		v2 = old_start
   3256 	}
   3257 	old_base = v2
   3258 	if data_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
   3259 		// security safeguard: trying to allocate more than what the format
   3260 		// allows for a chunk should be considered a smoke smell.
   3261 		return 0
   3262 	}
   3263 	if (*MemBuffer)(unsafe.Pointer(mem)).Fend+data_size > (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size { // Need some free memory
   3264 		new_mem_start = libc.Uint64FromInt64(int64(old_start) - int64(old_base))
   3265 		current_size = MemDataSize(tls, mem) + new_mem_start
   3266 		new_size = current_size + data_size
   3267 		extra_size = (new_size + uint64(CHUNK_SIZE) - uint64(1)) & libc.Uint64FromInt32(^(libc.Int32FromInt32(CHUNK_SIZE) - libc.Int32FromInt32(1)))
   3268 		new_buf = WebPSafeMalloc(tls, extra_size, uint64(1))
   3269 		if new_buf == libc.UintptrFromInt32(0) {
   3270 			return 0
   3271 		}
   3272 		if old_base != libc.UintptrFromInt32(0) {
   3273 			libc.Xmemcpy(tls, new_buf, old_base, current_size)
   3274 		}
   3275 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3276 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = new_buf
   3277 		(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = extra_size
   3278 		(*MemBuffer)(unsafe.Pointer(mem)).Fstart = new_mem_start
   3279 		(*MemBuffer)(unsafe.Pointer(mem)).Fend = current_size
   3280 	}
   3281 	libc.Xmemcpy(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fend), data, data_size)
   3282 	**(**size_t)(__ccgo_up(mem + 16)) += data_size
   3283 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3284 	return int32(1)
   3285 }
   3286 
   3287 func RemapMemBuffer(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r int32) {
   3288 	var mem, old_buf, old_start, v1 uintptr
   3289 	var v2 size_t
   3290 	_, _, _, _, _ = mem, old_buf, old_start, v1, v2
   3291 	mem = idec + 296
   3292 	old_buf = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf
   3293 	if old_buf == libc.UintptrFromInt32(0) {
   3294 		v1 = libc.UintptrFromInt32(0)
   3295 	} else {
   3296 		v1 = old_buf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3297 	}
   3298 	old_start = v1
   3299 	if data_size < (*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size {
   3300 		return 0
   3301 	} // can't remap to a shorter buffer!
   3302 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = data
   3303 	v2 = data_size
   3304 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = v2
   3305 	(*MemBuffer)(unsafe.Pointer(mem)).Fend = v2
   3306 	DoRemap(tls, idec, int64((*MemBuffer)(unsafe.Pointer(mem)).Fbuf+uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart))-int64(old_start))
   3307 	return int32(1)
   3308 }
   3309 
   3310 func InitMemBuffer(tls *libc.TLS, mem uintptr) {
   3311 	(*MemBuffer)(unsafe.Pointer(mem)).Fmode = int32(MEM_MODE_NONE)
   3312 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf = libc.UintptrFromInt32(0)
   3313 	(*MemBuffer)(unsafe.Pointer(mem)).Fbuf_size = uint64(0)
   3314 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = libc.UintptrFromInt32(0)
   3315 	(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_size = uint64(0)
   3316 }
   3317 
   3318 func ClearMemBuffer(tls *libc.TLS, mem uintptr) {
   3319 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3320 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fbuf)
   3321 		WebPSafeFree(tls, (*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf)
   3322 	}
   3323 }
   3324 
   3325 func CheckMemBufferMode(tls *libc.TLS, mem uintptr, expected MemBufferMode) (r int32) {
   3326 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_NONE) {
   3327 		(*MemBuffer)(unsafe.Pointer(mem)).Fmode = expected // switch to the expected mode
   3328 	} else {
   3329 		if (*MemBuffer)(unsafe.Pointer(mem)).Fmode != expected {
   3330 			return 0 // we mixed the modes => error
   3331 		}
   3332 	}
   3333 	// mode is ok
   3334 	return int32(1)
   3335 }
   3336 
   3337 // C documentation
   3338 //
   3339 //	// To be called last.
   3340 func FinishDecoding(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3341 	var options, output uintptr
   3342 	var status, status1 VP8StatusCode1
   3343 	_, _, _, _ = options, output, status, status1
   3344 	options = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions
   3345 	output = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   3346 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_DONE)
   3347 	if options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fflip != 0 {
   3348 		status = WebPFlipBuffer(tls, output)
   3349 		if status != int32(VP8_STATUS_OK) {
   3350 			return status
   3351 		}
   3352 	}
   3353 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   3354 		status1 = WebPCopyDecBufferPixels(tls, output, (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output) // do the slow-copy
   3355 		WebPFreeDecBuffer(tls, idec+352)
   3356 		if status1 != int32(VP8_STATUS_OK) {
   3357 			return status1
   3358 		}
   3359 		**(**WebPDecBuffer)(__ccgo_up(output)) = **(**WebPDecBuffer)(__ccgo_up((*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output))
   3360 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   3361 	}
   3362 	return int32(VP8_STATUS_OK)
   3363 }
   3364 
   3365 //------------------------------------------------------------------------------
   3366 // Macroblock-decoding contexts
   3367 
   3368 func SaveContext(tls *libc.TLS, dec uintptr, token_br uintptr, context uintptr) {
   3369 	(*MBContext)(unsafe.Pointer(context)).Fleft = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2))
   3370 	(*MBContext)(unsafe.Pointer(context)).Finfo = **(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2))
   3371 	(*MBContext)(unsafe.Pointer(context)).Ftoken_br = **(**VP8BitReader)(__ccgo_up(token_br))
   3372 }
   3373 
   3374 func RestoreContext(tls *libc.TLS, context uintptr, dec uintptr, token_br uintptr) {
   3375 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr(-libc.Int32FromInt32(1))*2)) = (*MBContext)(unsafe.Pointer(context)).Fleft
   3376 	**(**VP8MB)(__ccgo_up((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2)) = (*MBContext)(unsafe.Pointer(context)).Finfo
   3377 	**(**VP8BitReader)(__ccgo_up(token_br)) = (*MBContext)(unsafe.Pointer(context)).Ftoken_br
   3378 }
   3379 
   3380 //------------------------------------------------------------------------------
   3381 
   3382 func IDecError(tls *libc.TLS, idec uintptr, error1 VP8StatusCode1) (r VP8StatusCode1) {
   3383 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3384 		// Synchronize the thread, clean-up and check for errors.
   3385 		VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   3386 	}
   3387 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR)
   3388 	return error1
   3389 }
   3390 
   3391 func ChangeState(tls *libc.TLS, idec uintptr, new_state DecState, consumed_bytes size_t) {
   3392 	var mem uintptr
   3393 	_ = mem
   3394 	mem = idec + 296
   3395 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = new_state
   3396 	**(**size_t)(__ccgo_up(mem + 8)) += consumed_bytes
   3397 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3398 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = MemDataSize(tls, mem)
   3399 }
   3400 
   3401 // C documentation
   3402 //
   3403 //	// Headers
   3404 func DecodeWebPHeaders(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3405 	bp := tls.Alloc(80)
   3406 	defer tls.Free(80)
   3407 	var curr_size size_t
   3408 	var data, dec, dec1, mem uintptr
   3409 	var status VP8StatusCode1
   3410 	var _ /* headers at bp+0 */ WebPHeaderStructure
   3411 	_, _, _, _, _, _ = curr_size, data, dec, dec1, mem, status
   3412 	mem = idec + 296
   3413 	data = (*MemBuffer)(unsafe.Pointer(mem)).Fbuf + uintptr((*MemBuffer)(unsafe.Pointer(mem)).Fstart)
   3414 	curr_size = MemDataSize(tls, mem)
   3415 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata = data
   3416 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fdata_size = curr_size
   3417 	(**(**WebPHeaderStructure)(__ccgo_up(bp))).Fhave_all_data = 0
   3418 	status = WebPParseHeaders(tls, bp)
   3419 	if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3420 		return int32(VP8_STATUS_SUSPENDED) // We haven't found a VP8 chunk yet.
   3421 	} else {
   3422 		if status != int32(VP8_STATUS_OK) {
   3423 			return IDecError(tls, idec, status)
   3424 		}
   3425 	}
   3426 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fcompressed_size
   3427 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Fis_lossless
   3428 	if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3429 		dec = VP8New(tls)
   3430 		if dec == libc.UintptrFromInt32(0) {
   3431 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3432 		}
   3433 		(*VP8Decoder)(unsafe.Pointer(dec)).Fincremental = int32(1)
   3434 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec
   3435 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data
   3436 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp))).Falpha_data_size
   3437 		ChangeState(tls, idec, int32(STATE_VP8_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3438 	} else {
   3439 		dec1 = VP8LNew(tls)
   3440 		if dec1 == libc.UintptrFromInt32(0) {
   3441 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3442 		}
   3443 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fdec = dec1
   3444 		ChangeState(tls, idec, int32(STATE_VP8L_HEADER), (**(**WebPHeaderStructure)(__ccgo_up(bp))).Foffset)
   3445 	}
   3446 	return int32(VP8_STATUS_OK)
   3447 }
   3448 
   3449 func DecodeVP8FrameHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3450 	bp := tls.Alloc(16)
   3451 	defer tls.Free(16)
   3452 	var bits uint32_t
   3453 	var curr_size size_t
   3454 	var data uintptr
   3455 	var _ /* height at bp+4 */ int32
   3456 	var _ /* width at bp+0 */ int32
   3457 	_, _, _ = bits, curr_size, data
   3458 	data = (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf + uintptr((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart)
   3459 	curr_size = MemDataSize(tls, idec+296)
   3460 	if curr_size < uint64(VP8_FRAME_HEADER_SIZE) {
   3461 		// Not enough data bytes to extract VP8 Frame Header.
   3462 		return int32(VP8_STATUS_SUSPENDED)
   3463 	}
   3464 	if !(VP8GetInfo(tls, data, curr_size, (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size, bp, bp+4) != 0) {
   3465 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3466 	}
   3467 	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))
   3468 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size = uint64(bits>>libc.Int32FromInt32(5) + uint32(VP8_FRAME_HEADER_SIZE))
   3469 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata = data
   3470 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fdata_size = curr_size
   3471 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_PARTS0)
   3472 	return int32(VP8_STATUS_OK)
   3473 }
   3474 
   3475 // C documentation
   3476 //
   3477 //	// Partition #0
   3478 func CopyParts0Data(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3479 	var br, dec, mem, part0_buf uintptr
   3480 	var part_size size_t
   3481 	_, _, _, _, _ = br, dec, mem, part0_buf, part_size
   3482 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3483 	br = dec + 16
   3484 	part_size = libc.Uint64FromInt64(int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end) - int64((*VP8BitReader)(unsafe.Pointer(br)).Fbuf))
   3485 	mem = idec + 296
   3486 	// the following is a format limitation, no need for runtime check:
   3487 	if part_size == uint64(0) { // can't have zero-size partition #0
   3488 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   3489 	}
   3490 	if (*MemBuffer)(unsafe.Pointer(mem)).Fmode == int32(MEM_MODE_APPEND) {
   3491 		// We copy and grab ownership of the partition #0 data.
   3492 		part0_buf = WebPSafeMalloc(tls, uint64(1), part_size)
   3493 		if part0_buf == libc.UintptrFromInt32(0) {
   3494 			return int32(VP8_STATUS_OUT_OF_MEMORY)
   3495 		}
   3496 		libc.Xmemcpy(tls, part0_buf, (*VP8BitReader)(unsafe.Pointer(br)).Fbuf, part_size)
   3497 		(*MemBuffer)(unsafe.Pointer(mem)).Fpart0_buf = part0_buf
   3498 		VP8BitReaderSetBuffer(tls, br, part0_buf, part_size)
   3499 	} else {
   3500 		// Else: just keep pointers to the partition #0's data in dec->br.
   3501 	}
   3502 	**(**size_t)(__ccgo_up(mem + 8)) += part_size
   3503 	return int32(VP8_STATUS_OK)
   3504 }
   3505 
   3506 func DecodePartition0(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3507 	var dec, io, output, params uintptr
   3508 	var status VP8StatusCode1
   3509 	_, _, _, _, _ = dec, io, output, params, status
   3510 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3511 	io = idec + 136
   3512 	params = idec + 8
   3513 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3514 	// Wait till we have enough data for the whole partition #0
   3515 	if MemDataSize(tls, idec+296) < (*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fpart0_size {
   3516 		return int32(VP8_STATUS_SUSPENDED)
   3517 	}
   3518 	if !(VP8GetHeaders(tls, dec, io) != 0) {
   3519 		status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
   3520 		if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3521 			// treating NOT_ENOUGH_DATA as SUSPENDED state
   3522 			return int32(VP8_STATUS_SUSPENDED)
   3523 		}
   3524 		return IDecError(tls, idec, status)
   3525 	}
   3526 	// Allocate/Verify output buffer now
   3527 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3528 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3529 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3530 	}
   3531 	// This change must be done before calling VP8InitFrame()
   3532 	(*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)
   3533 	VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
   3534 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = CopyParts0Data(tls, idec)
   3535 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3536 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3537 	}
   3538 	// Finish setting up the decoding parameters. Will call io->setup().
   3539 	if VP8EnterCritical(tls, dec, io) != int32(VP8_STATUS_OK) {
   3540 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3541 	}
   3542 	// Note: past this point, teardown() must always be called
   3543 	// in case of error.
   3544 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8_DATA)
   3545 	// Allocate memory and prepare everything.
   3546 	if !(VP8InitFrame(tls, dec, io) != 0) {
   3547 		return IDecError(tls, idec, (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus)
   3548 	}
   3549 	return int32(VP8_STATUS_OK)
   3550 }
   3551 
   3552 // C documentation
   3553 //
   3554 //	// Remaining partitions
   3555 func DecodeRemaining(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3556 	bp := tls.Alloc(64)
   3557 	defer tls.Free(64)
   3558 	var dec, io, token_br uintptr
   3559 	var _ /* context at bp+0 */ MBContext
   3560 	_, _, _ = dec, io, token_br
   3561 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3562 	io = idec + 136
   3563 	// Make sure partition #0 has been read before, to set dec to ready.
   3564 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
   3565 		return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3566 	}
   3567 	for {
   3568 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h) {
   3569 			break
   3570 		}
   3571 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y != (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y {
   3572 			if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
   3573 				// note: normally, error shouldn't occur since we already have the whole
   3574 				// partition0 available here in DecodeRemaining(). Reaching EOF while
   3575 				// reading intra modes really means a BITSTREAM_ERROR.
   3576 				return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3577 			}
   3578 			(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y
   3579 		}
   3580 		for {
   3581 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   3582 				break
   3583 			}
   3584 			token_br = dec + 440 + uintptr(libc.Uint32FromInt32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
   3585 			SaveContext(tls, dec, token_br, bp)
   3586 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
   3587 				// We shouldn't fail when MAX_MB data was available
   3588 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) && MemDataSize(tls, idec+296) > uint64(MAX_MB_SIZE) {
   3589 					return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3590 				}
   3591 				// Synchronize the threads.
   3592 				if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
   3593 					if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
   3594 						return IDecError(tls, idec, int32(VP8_STATUS_BITSTREAM_ERROR))
   3595 					}
   3596 				}
   3597 				RestoreContext(tls, bp, dec, token_br)
   3598 				return int32(VP8_STATUS_SUSPENDED)
   3599 			}
   3600 			// Release buffer only if there is only one partition
   3601 			if (*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one == uint32(0) {
   3602 				(*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fstart = libc.Uint64FromInt64(int64((*VP8BitReader)(unsafe.Pointer(token_br)).Fbuf) - int64((*WebPIDecoder)(unsafe.Pointer(idec)).Fmem.Fbuf))
   3603 			}
   3604 			goto _2
   3605 		_2:
   3606 			;
   3607 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
   3608 		}
   3609 		VP8InitScanline(tls, dec) // Prepare for next scanline
   3610 		// Reconstruct, filter and emit the row.
   3611 		if !(VP8ProcessRow(tls, dec, io) != 0) {
   3612 			return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3613 		}
   3614 		goto _1
   3615 	_1:
   3616 		;
   3617 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
   3618 	}
   3619 	// Synchronize the thread and check for errors.
   3620 	if !(VP8ExitCritical(tls, dec, io) != 0) {
   3621 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_ERROR) // prevent re-entry in IDecError
   3622 		return IDecError(tls, idec, int32(VP8_STATUS_USER_ABORT))
   3623 	}
   3624 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
   3625 	return FinishDecoding(tls, idec)
   3626 }
   3627 
   3628 func ErrorStatusLossless(tls *libc.TLS, idec uintptr, status VP8StatusCode1) (r VP8StatusCode1) {
   3629 	if status == int32(VP8_STATUS_SUSPENDED) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
   3630 		return int32(VP8_STATUS_SUSPENDED)
   3631 	}
   3632 	return IDecError(tls, idec, status)
   3633 }
   3634 
   3635 func DecodeVP8LHeader(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3636 	var curr_size size_t
   3637 	var dec, io, output, params uintptr
   3638 	_, _, _, _, _ = curr_size, dec, io, output, params
   3639 	io = idec + 136
   3640 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3641 	params = idec + 8
   3642 	output = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
   3643 	curr_size = MemDataSize(tls, idec+296)
   3644 	// Wait until there's enough data for decoding header.
   3645 	if curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size>>libc.Int32FromInt32(3) {
   3646 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3647 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3648 	}
   3649 	if !(VP8LDecodeHeader(tls, dec, io) != 0) {
   3650 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_BITSTREAM_ERROR) && curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size {
   3651 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
   3652 		}
   3653 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3654 	}
   3655 	// Allocate/verify output buffer now.
   3656 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = WebPAllocateDecBuffer(tls, (*VP8Io)(unsafe.Pointer(io)).Fwidth, (*VP8Io)(unsafe.Pointer(io)).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, output)
   3657 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus != int32(VP8_STATUS_OK) {
   3658 		return IDecError(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3659 	}
   3660 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_VP8L_DATA)
   3661 	return int32(VP8_STATUS_OK)
   3662 }
   3663 
   3664 func DecodeVP8LData(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3665 	var curr_size size_t
   3666 	var dec uintptr
   3667 	var v1 int32
   3668 	_, _, _ = curr_size, dec, v1
   3669 	dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3670 	curr_size = MemDataSize(tls, idec+296)
   3671 	// Switch to incremental decoding if we don't have all the bytes available.
   3672 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental = libc.BoolInt32(curr_size < (*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size)
   3673 	if !(VP8LDecodeImage(tls, dec) != 0) {
   3674 		return ErrorStatusLossless(tls, idec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus)
   3675 	}
   3676 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
   3677 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus
   3678 	} else {
   3679 		v1 = FinishDecoding(tls, idec)
   3680 	}
   3681 	return v1
   3682 }
   3683 
   3684 // C documentation
   3685 //
   3686 //	// Main decoding loop
   3687 func IDecode(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3688 	var dec uintptr
   3689 	var status VP8StatusCode1
   3690 	_, _ = dec, status
   3691 	status = int32(VP8_STATUS_SUSPENDED)
   3692 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_WEBP_HEADER) {
   3693 		status = DecodeWebPHeaders(tls, idec)
   3694 	} else {
   3695 		if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   3696 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3697 		}
   3698 	}
   3699 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_HEADER) {
   3700 		status = DecodeVP8FrameHeader(tls, idec)
   3701 	}
   3702 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_PARTS0) {
   3703 		status = DecodePartition0(tls, idec)
   3704 	}
   3705 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3706 		dec = (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec
   3707 		if dec == libc.UintptrFromInt32(0) {
   3708 			return int32(VP8_STATUS_SUSPENDED) // can't continue if we have no decoder.
   3709 		}
   3710 		status = DecodeRemaining(tls, idec)
   3711 	}
   3712 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_HEADER) {
   3713 		status = DecodeVP8LHeader(tls, idec)
   3714 	}
   3715 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8L_DATA) {
   3716 		status = DecodeVP8LData(tls, idec)
   3717 	}
   3718 	return status
   3719 }
   3720 
   3721 // ------------------------------------------------------------------------------
   3722 // Internal constructor
   3723 func NewDecoder(tls *libc.TLS, output_buffer uintptr, features uintptr) (r uintptr) {
   3724 	var idec uintptr
   3725 	var v1, v3 int32
   3726 	var v5 bool
   3727 	_, _, _, _ = idec, v1, v3, v5
   3728 	idec = WebPSafeCalloc(tls, uint64(1), uint64(496))
   3729 	if idec == libc.UintptrFromInt32(0) {
   3730 		return libc.UintptrFromInt32(0)
   3731 	}
   3732 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fstate = int32(STATE_WEBP_HEADER)
   3733 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fchunk_size = uint64(0)
   3734 	(*WebPIDecoder)(unsafe.Pointer(idec)).Flast_mb_y = -int32(1)
   3735 	InitMemBuffer(tls, idec+296)
   3736 	v1 = WebPInitDecBufferInternal(tls, idec+352, int32(WEBP_DECODER_ABI_VERSION))
   3737 	goto _2
   3738 _2:
   3739 	;
   3740 	if v5 = !(v1 != 0); !v5 {
   3741 		v3 = VP8InitIoInternal(tls, idec+136, int32(WEBP_DECODER_ABI_VERSION))
   3742 		goto _4
   3743 	_4:
   3744 	}
   3745 	if v5 || !(v3 != 0) {
   3746 		WebPSafeFree(tls, idec)
   3747 		return libc.UintptrFromInt32(0)
   3748 	}
   3749 	WebPResetDecParams(tls, idec+8)
   3750 	if output_buffer == libc.UintptrFromInt32(0) || WebPAvoidSlowMemory(tls, output_buffer, features) != 0 {
   3751 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = idec + 352
   3752 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = output_buffer
   3753 		if output_buffer != libc.UintptrFromInt32(0) {
   3754 			(*WebPDecBuffer)(unsafe.Pointer((*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput)).Fcolorspace = (*WebPDecBuffer)(unsafe.Pointer(output_buffer)).Fcolorspace
   3755 		}
   3756 	} else {
   3757 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput = output_buffer
   3758 		(*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output = libc.UintptrFromInt32(0)
   3759 	}
   3760 	WebPInitCustomIo(tls, idec+8, idec+136) // Plug the I/O functions.
   3761 	return idec
   3762 }
   3763 
   3764 //------------------------------------------------------------------------------
   3765 // Public functions
   3766 
   3767 func WebPINewDecoder(tls *libc.TLS, output_buffer uintptr) (r uintptr) {
   3768 	return NewDecoder(tls, output_buffer, libc.UintptrFromInt32(0))
   3769 }
   3770 
   3771 func WebPIDecode(tls *libc.TLS, data1 uintptr, data_size1 size_t, config uintptr) (r uintptr) {
   3772 	bp := tls.Alloc(48)
   3773 	defer tls.Free(48)
   3774 	var features1, idec, v1 uintptr
   3775 	var v2 VP8StatusCode1
   3776 	var _ /* tmp_features at bp+0 */ WebPBitstreamFeatures
   3777 	_, _, _, _ = features1, idec, v1, v2
   3778 	if config == libc.UintptrFromInt32(0) {
   3779 		v1 = bp
   3780 	} else {
   3781 		v1 = config
   3782 	}
   3783 	features1 = v1
   3784 	libc.Xmemset(tls, bp, 0, uint64(40))
   3785 	// Parse the bitstream's features, if requested:
   3786 	if data1 != libc.UintptrFromInt32(0) && data_size1 > uint64(0) {
   3787 		v2 = WebPGetFeaturesInternal(tls, data1, data_size1, features1, int32(WEBP_DECODER_ABI_VERSION))
   3788 		goto _3
   3789 	_3:
   3790 		if v2 != int32(VP8_STATUS_OK) {
   3791 			return libc.UintptrFromInt32(0)
   3792 		}
   3793 	}
   3794 	// Create an instance of the incremental decoder
   3795 	if config != libc.UintptrFromInt32(0) {
   3796 		v1 = NewDecoder(tls, config+40, features1)
   3797 	} else {
   3798 		v1 = NewDecoder(tls, libc.UintptrFromInt32(0), features1)
   3799 	}
   3800 	idec = v1
   3801 	if idec == libc.UintptrFromInt32(0) {
   3802 		return libc.UintptrFromInt32(0)
   3803 	}
   3804 	// Finish initialization
   3805 	if config != libc.UintptrFromInt32(0) {
   3806 		(*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foptions = config + 160
   3807 	}
   3808 	return idec
   3809 }
   3810 
   3811 func WebPIDelete(tls *libc.TLS, idec uintptr) {
   3812 	if idec == libc.UintptrFromInt32(0) {
   3813 		return
   3814 	}
   3815 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec != libc.UintptrFromInt32(0) {
   3816 		if !((*WebPIDecoder)(unsafe.Pointer(idec)).Fis_lossless != 0) {
   3817 			if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_VP8_DATA) {
   3818 				// Synchronize the thread, clean-up and check for errors.
   3819 				// TODO(vrabaud) do we care about the return result?
   3820 				VP8ExitCritical(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec, idec+136)
   3821 			}
   3822 			VP8Delete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   3823 		} else {
   3824 			VP8LDelete(tls, (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec)
   3825 		}
   3826 	}
   3827 	ClearMemBuffer(tls, idec+296)
   3828 	WebPFreeDecBuffer(tls, idec+352)
   3829 	WebPSafeFree(tls, idec)
   3830 }
   3831 
   3832 //------------------------------------------------------------------------------
   3833 // Wrapper toward WebPINewDecoder
   3834 
   3835 func WebPINewRGB(tls *libc.TLS, csp WEBP_CSP_MODE1, output_buffer uintptr, output_buffer_size size_t, output_stride int32) (r uintptr) {
   3836 	var idec uintptr
   3837 	var is_external_memory, v1 int32
   3838 	_, _, _ = idec, is_external_memory, v1
   3839 	if output_buffer != libc.UintptrFromInt32(0) {
   3840 		v1 = int32(1)
   3841 	} else {
   3842 		v1 = 0
   3843 	}
   3844 	is_external_memory = v1
   3845 	if csp >= int32(MODE_YUV) {
   3846 		return libc.UintptrFromInt32(0)
   3847 	}
   3848 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   3849 		output_buffer_size = uint64(0)
   3850 		output_stride = 0
   3851 	} else { // A buffer was passed. Validate the other params.
   3852 		if output_stride == 0 || output_buffer_size == uint64(0) {
   3853 			return libc.UintptrFromInt32(0) // invalid parameter.
   3854 		}
   3855 	}
   3856 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   3857 	if idec == libc.UintptrFromInt32(0) {
   3858 		return libc.UintptrFromInt32(0)
   3859 	}
   3860 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = csp
   3861 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   3862 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = output_buffer
   3863 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 8)) = output_stride
   3864 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 16)) = output_buffer_size
   3865 	return idec
   3866 }
   3867 
   3868 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) {
   3869 	var colorspace WEBP_CSP_MODE1
   3870 	var idec, v8, v9 uintptr
   3871 	var is_external_memory, v1, v5, v6 int32
   3872 	var v2, v3, v4 size_t
   3873 	_, _, _, _, _, _, _, _, _, _, _ = colorspace, idec, is_external_memory, v1, v2, v3, v4, v5, v6, v8, v9
   3874 	if luma != libc.UintptrFromInt32(0) {
   3875 		v1 = int32(1)
   3876 	} else {
   3877 		v1 = 0
   3878 	}
   3879 	is_external_memory = v1
   3880 	if is_external_memory == 0 { // Overwrite parameters to sane values.
   3881 		v4 = libc.Uint64FromInt32(0)
   3882 		a_size = v4
   3883 		v3 = v4
   3884 		v_size = v3
   3885 		v2 = v3
   3886 		u_size = v2
   3887 		luma_size = v2
   3888 		v6 = libc.Int32FromInt32(0)
   3889 		a_stride = v6
   3890 		v5 = v6
   3891 		v_stride = v5
   3892 		v1 = v5
   3893 		u_stride = v1
   3894 		luma_stride = v1
   3895 		v9 = libc.UintptrFromInt32(0)
   3896 		a = v9
   3897 		v8 = v9
   3898 		v = v8
   3899 		u = v8
   3900 		colorspace = int32(MODE_YUVA)
   3901 	} else { // A luma buffer was passed. Validate the other parameters.
   3902 		if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) {
   3903 			return libc.UintptrFromInt32(0)
   3904 		}
   3905 		if luma_size == uint64(0) || u_size == uint64(0) || v_size == uint64(0) {
   3906 			return libc.UintptrFromInt32(0)
   3907 		}
   3908 		if luma_stride == 0 || u_stride == 0 || v_stride == 0 {
   3909 			return libc.UintptrFromInt32(0)
   3910 		}
   3911 		if a != libc.UintptrFromInt32(0) {
   3912 			if a_size == uint64(0) || a_stride == 0 {
   3913 				return libc.UintptrFromInt32(0)
   3914 			}
   3915 		}
   3916 		if a == libc.UintptrFromInt32(0) {
   3917 			v1 = int32(MODE_YUV)
   3918 		} else {
   3919 			v1 = int32(MODE_YUVA)
   3920 		}
   3921 		colorspace = v1
   3922 	}
   3923 	idec = WebPINewDecoder(tls, libc.UintptrFromInt32(0))
   3924 	if idec == libc.UintptrFromInt32(0) {
   3925 		return libc.UintptrFromInt32(0)
   3926 	}
   3927 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fcolorspace = colorspace
   3928 	(*WebPIDecoder)(unsafe.Pointer(idec)).Foutput.Fis_external_memory = is_external_memory
   3929 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16)) = luma
   3930 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 32)) = luma_stride
   3931 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 48)) = luma_size
   3932 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 8)) = u
   3933 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 36)) = u_stride
   3934 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 56)) = u_size
   3935 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 16)) = v
   3936 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 40)) = v_stride
   3937 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 64)) = v_size
   3938 	*(*uintptr)(unsafe.Pointer(idec + 352 + 16 + 24)) = a
   3939 	*(*int32)(unsafe.Pointer(idec + 352 + 16 + 44)) = a_stride
   3940 	*(*size_t)(unsafe.Pointer(idec + 352 + 16 + 72)) = a_size
   3941 	return idec
   3942 }
   3943 
   3944 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) {
   3945 	return WebPINewYUVA(tls, luma, luma_size, luma_stride, u, u_size, u_stride, v, v_size, v_stride, libc.UintptrFromInt32(0), uint64(0), 0)
   3946 }
   3947 
   3948 //------------------------------------------------------------------------------
   3949 
   3950 func IDecCheckStatus(tls *libc.TLS, idec uintptr) (r VP8StatusCode1) {
   3951 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_ERROR) {
   3952 		return int32(VP8_STATUS_BITSTREAM_ERROR)
   3953 	}
   3954 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate == int32(STATE_DONE) {
   3955 		return int32(VP8_STATUS_OK)
   3956 	}
   3957 	return int32(VP8_STATUS_SUSPENDED)
   3958 }
   3959 
   3960 func WebPIAppend(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   3961 	var status VP8StatusCode1
   3962 	_ = status
   3963 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   3964 		return int32(VP8_STATUS_INVALID_PARAM)
   3965 	}
   3966 	status = IDecCheckStatus(tls, idec)
   3967 	if status != int32(VP8_STATUS_SUSPENDED) {
   3968 		return status
   3969 	}
   3970 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   3971 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_APPEND)) != 0) {
   3972 		return int32(VP8_STATUS_INVALID_PARAM)
   3973 	}
   3974 	// Append data to memory buffer
   3975 	if !(AppendToMemBuffer(tls, idec, data, data_size) != 0) {
   3976 		return int32(VP8_STATUS_OUT_OF_MEMORY)
   3977 	}
   3978 	return IDecode(tls, idec)
   3979 }
   3980 
   3981 func WebPIUpdate(tls *libc.TLS, idec uintptr, data uintptr, data_size size_t) (r VP8StatusCode1) {
   3982 	var status VP8StatusCode1
   3983 	_ = status
   3984 	if idec == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
   3985 		return int32(VP8_STATUS_INVALID_PARAM)
   3986 	}
   3987 	status = IDecCheckStatus(tls, idec)
   3988 	if status != int32(VP8_STATUS_SUSPENDED) {
   3989 		return status
   3990 	}
   3991 	// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
   3992 	if !(CheckMemBufferMode(tls, idec+296, int32(MEM_MODE_MAP)) != 0) {
   3993 		return int32(VP8_STATUS_INVALID_PARAM)
   3994 	}
   3995 	// Make the memory buffer point to the new buffer
   3996 	if !(RemapMemBuffer(tls, idec, data, data_size) != 0) {
   3997 		return int32(VP8_STATUS_INVALID_PARAM)
   3998 	}
   3999 	return IDecode(tls, idec)
   4000 }
   4001 
   4002 //------------------------------------------------------------------------------
   4003 
   4004 func GetOutputBuffer(tls *libc.TLS, idec uintptr) (r uintptr) {
   4005 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fdec == libc.UintptrFromInt32(0) {
   4006 		return libc.UintptrFromInt32(0)
   4007 	}
   4008 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate <= int32(STATE_VP8_PARTS0) {
   4009 		return libc.UintptrFromInt32(0)
   4010 	}
   4011 	if (*WebPIDecoder)(unsafe.Pointer(idec)).Ffinal_output != libc.UintptrFromInt32(0) {
   4012 		return libc.UintptrFromInt32(0) // not yet slow-copied
   4013 	}
   4014 	return (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Foutput
   4015 }
   4016 
   4017 func WebPIDecodedArea(tls *libc.TLS, idec uintptr, left uintptr, top uintptr, width uintptr, height uintptr) (r uintptr) {
   4018 	var src uintptr
   4019 	_ = src
   4020 	src = GetOutputBuffer(tls, idec)
   4021 	if left != libc.UintptrFromInt32(0) {
   4022 		**(**int32)(__ccgo_up(left)) = 0
   4023 	}
   4024 	if top != libc.UintptrFromInt32(0) {
   4025 		**(**int32)(__ccgo_up(top)) = 0
   4026 	}
   4027 	if src != libc.UintptrFromInt32(0) {
   4028 		if width != libc.UintptrFromInt32(0) {
   4029 			**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4030 		}
   4031 		if height != libc.UintptrFromInt32(0) {
   4032 			**(**int32)(__ccgo_up(height)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4033 		}
   4034 	} else {
   4035 		if width != libc.UintptrFromInt32(0) {
   4036 			**(**int32)(__ccgo_up(width)) = 0
   4037 		}
   4038 		if height != libc.UintptrFromInt32(0) {
   4039 			**(**int32)(__ccgo_up(height)) = 0
   4040 		}
   4041 	}
   4042 	return src
   4043 }
   4044 
   4045 func WebPIDecGetRGB(tls *libc.TLS, idec uintptr, last_y uintptr, width uintptr, height uintptr, stride uintptr) (r uintptr) {
   4046 	var src uintptr
   4047 	_ = src
   4048 	src = GetOutputBuffer(tls, idec)
   4049 	if src == libc.UintptrFromInt32(0) {
   4050 		return libc.UintptrFromInt32(0)
   4051 	}
   4052 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace >= int32(MODE_YUV) {
   4053 		return libc.UintptrFromInt32(0)
   4054 	}
   4055 	if last_y != libc.UintptrFromInt32(0) {
   4056 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4057 	}
   4058 	if width != libc.UintptrFromInt32(0) {
   4059 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4060 	}
   4061 	if height != libc.UintptrFromInt32(0) {
   4062 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4063 	}
   4064 	if stride != libc.UintptrFromInt32(0) {
   4065 		**(**int32)(__ccgo_up(stride)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Fstride
   4066 	}
   4067 	return (*WebPDecBuffer)(unsafe.Pointer(src)).Fu.FRGBA.Frgba
   4068 }
   4069 
   4070 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) {
   4071 	var src uintptr
   4072 	_ = src
   4073 	src = GetOutputBuffer(tls, idec)
   4074 	if src == libc.UintptrFromInt32(0) {
   4075 		return libc.UintptrFromInt32(0)
   4076 	}
   4077 	if (*WebPDecBuffer)(unsafe.Pointer(src)).Fcolorspace < int32(MODE_YUV) {
   4078 		return libc.UintptrFromInt32(0)
   4079 	}
   4080 	if last_y != libc.UintptrFromInt32(0) {
   4081 		**(**int32)(__ccgo_up(last_y)) = (*WebPIDecoder)(unsafe.Pointer(idec)).Fparams.Flast_y
   4082 	}
   4083 	if u != libc.UintptrFromInt32(0) {
   4084 		**(**uintptr)(__ccgo_up(u)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu
   4085 	}
   4086 	if v != libc.UintptrFromInt32(0) {
   4087 		**(**uintptr)(__ccgo_up(v)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fv
   4088 	}
   4089 	if a != libc.UintptrFromInt32(0) {
   4090 		**(**uintptr)(__ccgo_up(a)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa
   4091 	}
   4092 	if width != libc.UintptrFromInt32(0) {
   4093 		**(**int32)(__ccgo_up(width)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fwidth
   4094 	}
   4095 	if height != libc.UintptrFromInt32(0) {
   4096 		**(**int32)(__ccgo_up(height)) = (*WebPDecBuffer)(unsafe.Pointer(src)).Fheight
   4097 	}
   4098 	if stride != libc.UintptrFromInt32(0) {
   4099 		**(**int32)(__ccgo_up(stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy_stride
   4100 	}
   4101 	if uv_stride != libc.UintptrFromInt32(0) {
   4102 		**(**int32)(__ccgo_up(uv_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fu_stride
   4103 	}
   4104 	if a_stride != libc.UintptrFromInt32(0) {
   4105 		**(**int32)(__ccgo_up(a_stride)) = (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fa_stride
   4106 	}
   4107 	return (*(*WebPYUVABuffer)(unsafe.Pointer(src + 16))).Fy
   4108 }
   4109 
   4110 type __ccgo_fp__XWebPISetIOHooks_1 = func(*libc.TLS, uintptr) int32
   4111 
   4112 type __ccgo_fp__XWebPISetIOHooks_2 = func(*libc.TLS, uintptr) int32
   4113 
   4114 type __ccgo_fp__XWebPISetIOHooks_3 = func(*libc.TLS, uintptr)
   4115 
   4116 func WebPISetIOHooks(tls *libc.TLS, idec uintptr, __ccgo_fp_put VP8IoPutHook, __ccgo_fp_setup VP8IoSetupHook, __ccgo_fp_teardown VP8IoTeardownHook, user_data uintptr) (r int32) {
   4117 	if idec == libc.UintptrFromInt32(0) || (*WebPIDecoder)(unsafe.Pointer(idec)).Fstate > int32(STATE_WEBP_HEADER) {
   4118 		return 0
   4119 	}
   4120 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fput = __ccgo_fp_put
   4121 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fsetup = __ccgo_fp_setup
   4122 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fteardown = __ccgo_fp_teardown
   4123 	(*WebPIDecoder)(unsafe.Pointer(idec)).Fio.Fopaque = user_data
   4124 	return int32(1)
   4125 }
   4126 
   4127 var kHashMul4 = uint32(0x1e35a7bd)
   4128 
   4129 const YUV_FIX = 16
   4130 const YUV_HALF = 32768
   4131 const YUV_FIX2 = 6
   4132 const YUV_MASK2 = 16383
   4133 
   4134 //------------------------------------------------------------------------------
   4135 
   4136 // Copyright 2010 Google Inc. All Rights Reserved.
   4137 //
   4138 // Use of this source code is governed by a BSD-style license
   4139 // that can be found in the COPYING file in the root of the source
   4140 // tree. An additional intellectual property rights grant can be found
   4141 // in the file PATENTS. All contributing project authors may
   4142 // be found in the AUTHORS file in the root of the source tree.
   4143 // -----------------------------------------------------------------------------
   4144 //
   4145 //  Main decoding functions for WebP images.
   4146 //
   4147 // Author: Skal (pascal.massimino@gmail.com)
   4148 
   4149 //------------------------------------------------------------------------------
   4150 // Main YUV<->RGB conversion functions
   4151 
   4152 func EmitYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4153 	var buf, output, u_dst, v_dst, y_dst uintptr
   4154 	var mb_h, mb_w, uv_h, uv_w int32
   4155 	_, _, _, _, _, _, _, _, _ = buf, mb_h, mb_w, output, u_dst, uv_h, uv_w, v_dst, y_dst
   4156 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4157 	buf = output + 16
   4158 	y_dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4159 	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))
   4160 	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))
   4161 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4162 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4163 	uv_w = (mb_w + int32(1)) / int32(2)
   4164 	uv_h = (mb_h + int32(1)) / int32(2)
   4165 	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)
   4166 	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)
   4167 	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)
   4168 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4169 }
   4170 
   4171 // C documentation
   4172 //
   4173 //	// Point-sampling U/V sampler.
   4174 func EmitSampledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4175 	var buf, dst, output uintptr
   4176 	_, _, _ = buf, dst, output
   4177 	output = (*WebPDecParams)(unsafe.Pointer(p)).Foutput
   4178 	buf = output + 16
   4179 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4180 	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])
   4181 	return (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4182 }
   4183 
   4184 //------------------------------------------------------------------------------
   4185 // Fancy upsampling
   4186 
   4187 func EmitFancyRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4188 	var buf, cur_u, cur_v, cur_y, dst, top_u, top_v uintptr
   4189 	var mb_w, num_lines_out, uv_w, y, y_end int32
   4190 	var upsample WebPUpsampleLinePairFunc
   4191 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, cur_u, cur_v, cur_y, dst, mb_w, num_lines_out, top_u, top_v, upsample, uv_w, y, y_end
   4192 	num_lines_out = (*VP8Io)(unsafe.Pointer(io)).Fmb_h // a priori guess
   4193 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4194 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4195 	upsample = WebPUpsamplers[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4196 	cur_y = (*VP8Io)(unsafe.Pointer(io)).Fy
   4197 	cur_u = (*VP8Io)(unsafe.Pointer(io)).Fu
   4198 	cur_v = (*VP8Io)(unsafe.Pointer(io)).Fv
   4199 	top_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u
   4200 	top_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v
   4201 	y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4202 	y_end = (*VP8Io)(unsafe.Pointer(io)).Fmb_y + (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4203 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4204 	uv_w = (mb_w + int32(1)) / int32(2)
   4205 	if y == 0 {
   4206 		// First line is special cased. We mirror the u/v samples at boundary.
   4207 		(*(*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)
   4208 	} else {
   4209 		// We can finish the left-over line from previous call.
   4210 		(*(*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)
   4211 		num_lines_out = num_lines_out + 1
   4212 	}
   4213 	// Loop over each output pairs of row.
   4214 	for {
   4215 		if !(y+int32(2) < y_end) {
   4216 			break
   4217 		}
   4218 		top_u = cur_u
   4219 		top_v = cur_v
   4220 		cur_u = cur_u + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4221 		cur_v = cur_v + uintptr((*VP8Io)(unsafe.Pointer(io)).Fuv_stride)
   4222 		dst = dst + uintptr(int32(2)*(*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4223 		cur_y = cur_y + uintptr(int32(2)*(*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4224 		(*(*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)
   4225 		goto _1
   4226 	_1:
   4227 		;
   4228 		y = y + int32(2)
   4229 	}
   4230 	// move to last row
   4231 	cur_y = cur_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fy_stride)
   4232 	if (*VP8Io)(unsafe.Pointer(io)).Fcrop_top+y_end < (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
   4233 		// Save the unfinished samples for next call (as we're not done yet).
   4234 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y, cur_y, libc.Uint64FromInt32(mb_w)*uint64(1))
   4235 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u, cur_u, libc.Uint64FromInt32(uv_w)*uint64(1))
   4236 		libc.Xmemcpy(tls, (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v, cur_v, libc.Uint64FromInt32(uv_w)*uint64(1))
   4237 		// The fancy upsampler leaves a row unfinished behind
   4238 		// (except for the very last row)
   4239 		num_lines_out = num_lines_out - 1
   4240 	} else {
   4241 		// Process the very last row of even-sized picture
   4242 		if !(y_end&libc.Int32FromInt32(1) != 0) {
   4243 			(*(*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)
   4244 		}
   4245 	}
   4246 	return num_lines_out
   4247 }
   4248 
   4249 //------------------------------------------------------------------------------
   4250 
   4251 func FillAlphaPlane(tls *libc.TLS, dst uintptr, w int32, h int32, stride int32) {
   4252 	var j int32
   4253 	_ = j
   4254 	j = 0
   4255 	for {
   4256 		if !(j < h) {
   4257 			break
   4258 		}
   4259 		libc.Xmemset(tls, dst, int32(0xff), libc.Uint64FromInt32(w)*uint64(1))
   4260 		dst = dst + uintptr(stride)
   4261 		goto _1
   4262 	_1:
   4263 		;
   4264 		j = j + 1
   4265 	}
   4266 }
   4267 
   4268 func EmitAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4269 	var alpha, buf, dst uintptr
   4270 	var j, mb_h, mb_w int32
   4271 	_, _, _, _, _, _ = alpha, buf, dst, j, mb_h, mb_w
   4272 	alpha = (*VP8Io)(unsafe.Pointer(io)).Fa
   4273 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4274 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4275 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4276 	dst = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4277 	_ = expected_num_lines_out
   4278 	if alpha != libc.UintptrFromInt32(0) {
   4279 		j = 0
   4280 		for {
   4281 			if !(j < mb_h) {
   4282 				break
   4283 			}
   4284 			libc.Xmemcpy(tls, dst, alpha, libc.Uint64FromInt32(mb_w)*uint64(1))
   4285 			alpha = alpha + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4286 			dst = dst + uintptr((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4287 			goto _1
   4288 		_1:
   4289 			;
   4290 			j = j + 1
   4291 		}
   4292 	} else {
   4293 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4294 			// the user requested alpha, but there is none, set it to opaque.
   4295 			FillAlphaPlane(tls, dst, mb_w, mb_h, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4296 		}
   4297 	}
   4298 	return 0
   4299 }
   4300 
   4301 func GetAlphaSourceRow(tls *libc.TLS, io uintptr, alpha uintptr, num_rows uintptr) (r int32) {
   4302 	var start_y int32
   4303 	_ = start_y
   4304 	start_y = (*VP8Io)(unsafe.Pointer(io)).Fmb_y
   4305 	**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4306 	// Compensate for the 1-line delay of the fancy upscaler.
   4307 	// This is similar to EmitFancyRGB().
   4308 	if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   4309 		if start_y == 0 {
   4310 			// We don't process the last row yet. It'll be done during the next call.
   4311 			**(**int32)(__ccgo_up(num_rows)) = **(**int32)(__ccgo_up(num_rows)) - 1
   4312 		} else {
   4313 			start_y = start_y - 1
   4314 			// Fortunately, *alpha data is persistent, so we can go back
   4315 			// one row and finish alpha blending, now that the fancy upscaler
   4316 			// completed the YUV->RGB interpolation.
   4317 			**(**uintptr)(__ccgo_up(alpha)) -= uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4318 		}
   4319 		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 {
   4320 			// If it's the very last call, we process all the remaining rows!
   4321 			**(**int32)(__ccgo_up(num_rows)) = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - start_y
   4322 		}
   4323 	}
   4324 	return start_y
   4325 }
   4326 
   4327 func EmitAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4328 	bp := tls.Alloc(16)
   4329 	defer tls.Free(16)
   4330 	var alpha_first, has_alpha, mb_w, start_y, v1 int32
   4331 	var base_rgba, buf, dst uintptr
   4332 	var colorspace, v2 WEBP_CSP_MODE1
   4333 	var v5 bool
   4334 	var _ /* alpha at bp+0 */ uintptr
   4335 	var _ /* num_rows at bp+8 */ int32
   4336 	_, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, has_alpha, mb_w, start_y, v1, v2, v5
   4337 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4338 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4339 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4340 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4341 		alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4342 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4343 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4344 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4345 		if alpha_first != 0 {
   4346 			v1 = 0
   4347 		} else {
   4348 			v1 = int32(3)
   4349 		}
   4350 		dst = base_rgba + uintptr(v1)
   4351 		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)
   4352 		_ = expected_num_lines_out
   4353 		// has_alpha is true if there's non-trivial alpha to premultiply with.
   4354 		if v5 = has_alpha != 0; v5 {
   4355 			v2 = colorspace
   4356 			v1 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4357 			goto _4
   4358 		_4:
   4359 		}
   4360 		if v5 && v1 != 0 {
   4361 			(*(*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)
   4362 		}
   4363 	}
   4364 	return 0
   4365 }
   4366 
   4367 func EmitAlphaRGBA4444(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4368 	bp := tls.Alloc(16)
   4369 	defer tls.Free(16)
   4370 	var alpha_dst, base_rgba, buf uintptr
   4371 	var alpha_mask, alpha_value uint32_t
   4372 	var colorspace, v3 WEBP_CSP_MODE1
   4373 	var i, j, mb_w, start_y, v4 int32
   4374 	var v6 bool
   4375 	var _ /* alpha at bp+0 */ uintptr
   4376 	var _ /* num_rows at bp+8 */ int32
   4377 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, j, mb_w, start_y, v3, v4, v6
   4378 	**(**uintptr)(__ccgo_up(bp)) = (*VP8Io)(unsafe.Pointer(io)).Fa
   4379 	if **(**uintptr)(__ccgo_up(bp)) != libc.UintptrFromInt32(0) {
   4380 		mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4381 		colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4382 		buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4383 		start_y = GetAlphaSourceRow(tls, io, bp, bp+8)
   4384 		base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(start_y)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4385 		alpha_dst = base_rgba + uintptr(1)
   4386 		alpha_mask = uint32(0x0f)
   4387 		j = 0
   4388 		for {
   4389 			if !(j < **(**int32)(__ccgo_up(bp + 8))) {
   4390 				break
   4391 			}
   4392 			i = 0
   4393 			for {
   4394 				if !(i < mb_w) {
   4395 					break
   4396 				}
   4397 				// Fill in the alpha value (converted to 4 bits).
   4398 				alpha_value = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)))) >> int32(4))
   4399 				**(**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)
   4400 				alpha_mask = alpha_mask & alpha_value
   4401 				goto _2
   4402 			_2:
   4403 				;
   4404 				i = i + 1
   4405 			}
   4406 			**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr((*VP8Io)(unsafe.Pointer(io)).Fwidth)
   4407 			alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4408 			goto _1
   4409 		_1:
   4410 			;
   4411 			j = j + 1
   4412 		}
   4413 		_ = expected_num_lines_out
   4414 		if v6 = alpha_mask != uint32(0x0f); v6 {
   4415 			v3 = colorspace
   4416 			v4 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   4417 			goto _5
   4418 		_5:
   4419 		}
   4420 		if v6 && v4 != 0 {
   4421 			(*(*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)
   4422 		}
   4423 	}
   4424 	return 0
   4425 }
   4426 
   4427 //------------------------------------------------------------------------------
   4428 // YUV rescaling (no final RGB conversion needed)
   4429 
   4430 func Rescale(tls *libc.TLS, src uintptr, src_stride int32, new_lines int32, wrk uintptr) (r int32) {
   4431 	var lines_in, num_lines_out int32
   4432 	_, _ = lines_in, num_lines_out
   4433 	num_lines_out = 0
   4434 	for new_lines > 0 { // import new contributions of source rows.
   4435 		lines_in = WebPRescalerImport(tls, wrk, new_lines, src, src_stride)
   4436 		src = src + uintptr(lines_in*src_stride)
   4437 		new_lines = new_lines - lines_in
   4438 		num_lines_out = num_lines_out + WebPRescalerExport(tls, wrk) // emit output row(s)
   4439 	}
   4440 	return num_lines_out
   4441 }
   4442 
   4443 func EmitRescaledYUV(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4444 	var mb_h, num_lines_out, uv_mb_h, v2, v5 int32
   4445 	var scaler uintptr
   4446 	var v1, v4 WEBP_CSP_MODE1
   4447 	var v7 bool
   4448 	_, _, _, _, _, _, _, _, _ = mb_h, num_lines_out, scaler, uv_mb_h, v1, v2, v4, v5, v7
   4449 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4450 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4451 	scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4452 	num_lines_out = 0
   4453 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4454 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4455 		v4 = v1
   4456 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4457 		goto _6
   4458 	_6:
   4459 	}
   4460 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4461 	goto _3
   4462 _3:
   4463 	;
   4464 	if v2 != 0 && (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4465 		// Before rescaling, we premultiply the luma directly into the io->y
   4466 		// internal buffer. This is OK since these samples are not used for
   4467 		// intra-prediction (the top samples are saved in cache_y/u/v).
   4468 		// But we need to cast the const away, though.
   4469 		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)
   4470 	}
   4471 	num_lines_out = Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fy, (*VP8Io)(unsafe.Pointer(io)).Fy_stride, mb_h, scaler)
   4472 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fu, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4473 	Rescale(tls, (*VP8Io)(unsafe.Pointer(io)).Fv, (*VP8Io)(unsafe.Pointer(io)).Fuv_stride, uv_mb_h, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4474 	return num_lines_out
   4475 }
   4476 
   4477 func EmitRescaledAlphaYUV(tls *libc.TLS, io uintptr, p uintptr, expected_num_lines_out int32) (r int32) {
   4478 	var buf, dst_a, dst_y uintptr
   4479 	var num_lines_out int32
   4480 	_, _, _, _ = buf, dst_a, dst_y, num_lines_out
   4481 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4482 	dst_a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride))
   4483 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4484 		dst_y = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy + uintptr(int64((*WebPDecParams)(unsafe.Pointer(p)).Flast_y)*int64((*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride))
   4485 		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)
   4486 		if num_lines_out > 0 { // unmultiply the Y
   4487 			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))
   4488 		}
   4489 	} else {
   4490 		if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
   4491 			// the user requested alpha, but there is none, set it to opaque.
   4492 			FillAlphaPlane(tls, dst_a, (*VP8Io)(unsafe.Pointer(io)).Fscaled_width, expected_num_lines_out, (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
   4493 		}
   4494 	}
   4495 	return 0
   4496 }
   4497 
   4498 func InitYUVRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4499 	var buf, scalers, work, v12 uintptr
   4500 	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
   4501 	var rescaler_size, uv_work_size, work_size size_t
   4502 	var total_size, v9 uint64_t
   4503 	var v1, v4 WEBP_CSP_MODE1
   4504 	var v7 bool
   4505 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   4506 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4507 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4508 		v4 = v1
   4509 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4510 		goto _6
   4511 	_6:
   4512 	}
   4513 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4514 	goto _3
   4515 _3:
   4516 	has_alpha = v2
   4517 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4518 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   4519 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   4520 	uv_out_width = (out_width + int32(1)) >> int32(1)
   4521 	uv_out_height = (out_height + int32(1)) >> int32(1)
   4522 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4523 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   4524 	// scratch memory for luma rescaler
   4525 	work_size = uint64(2) * libc.Uint64FromInt32(out_width)
   4526 	uv_work_size = libc.Uint64FromInt32(int32(2) * uv_out_width)
   4527 	if has_alpha != 0 {
   4528 		v8 = int32(4)
   4529 	} else {
   4530 		v8 = int32(3)
   4531 	}
   4532 	num_rescalers = v8
   4533 	total_size = (work_size + uint64(2)*uv_work_size) * uint64(4)
   4534 	if has_alpha != 0 {
   4535 		total_size = total_size + work_size*uint64(4)
   4536 	}
   4537 	rescaler_size = libc.Uint64FromInt32(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   4538 	total_size = total_size + rescaler_size
   4539 	v9 = total_size
   4540 	v2 = libc.BoolInt32(v9 == v9)
   4541 	goto _11
   4542 _11:
   4543 	if !(v2 != 0) {
   4544 		return 0
   4545 	}
   4546 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   4547 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4548 		return 0 // memory error
   4549 	}
   4550 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4551 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   4552 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   4553 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   4554 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   4555 	if has_alpha != 0 {
   4556 		v12 = scalers + 3*104
   4557 	} else {
   4558 		v12 = libc.UintptrFromInt32(0)
   4559 	}
   4560 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   4561 	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) {
   4562 		return 0
   4563 	}
   4564 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledYUV)
   4565 	if has_alpha != 0 {
   4566 		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) {
   4567 			return 0
   4568 		}
   4569 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaYUV)
   4570 		WebPInitAlphaProcessing(tls)
   4571 	}
   4572 	return int32(1)
   4573 }
   4574 
   4575 //------------------------------------------------------------------------------
   4576 // RGBA rescaling
   4577 
   4578 func ExportRGB(tls *libc.TLS, p uintptr, y_pos int32) (r int32) {
   4579 	var buf, dst, v1, v10, v4, v7 uintptr
   4580 	var convert WebPYUV444Converter
   4581 	var num_lines_out, v11, v2, v5, v8 int32
   4582 	var v13 bool
   4583 	_, _, _, _, _, _, _, _, _, _, _, _, _ = buf, convert, dst, num_lines_out, v1, v10, v11, v13, v2, v4, v5, v7, v8
   4584 	convert = WebPYUV444Converters[(*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace]
   4585 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4586 	dst = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4587 	num_lines_out = 0
   4588 	// For RGB rescaling, because of the YUV420, current scan position
   4589 	// U/V can be +1/-1 line from the Y one.  Hence the double test.
   4590 	for {
   4591 		v1 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y
   4592 		v4 = v1
   4593 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
   4594 		goto _6
   4595 	_6:
   4596 		;
   4597 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
   4598 		goto _3
   4599 	_3:
   4600 		;
   4601 		if v13 = v2 != 0; v13 {
   4602 			v7 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u
   4603 			v10 = v7
   4604 			v11 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v10)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v10)).Fdst_height)
   4605 			goto _12
   4606 		_12:
   4607 			;
   4608 			v8 = libc.BoolInt32(!(v11 != 0) && (*WebPRescaler)(unsafe.Pointer(v7)).Fy_accum <= 0)
   4609 			goto _9
   4610 		_9:
   4611 		}
   4612 		if !(v13 && v8 != 0) {
   4613 			break
   4614 		}
   4615 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y)
   4616 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u)
   4617 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v)
   4618 		(*(*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)
   4619 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4620 		num_lines_out = num_lines_out + 1
   4621 	}
   4622 	return num_lines_out
   4623 }
   4624 
   4625 func EmitRescaledRGB(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4626 	var j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in int32
   4627 	_, _, _, _, _, _, _, _ = j, mb_h, num_lines_out, u_lines_in, uv_j, uv_mb_h, v_lines_in, y_lines_in
   4628 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4629 	uv_mb_h = (mb_h + int32(1)) >> int32(1)
   4630 	j = 0
   4631 	uv_j = 0
   4632 	num_lines_out = 0
   4633 	for j < mb_h {
   4634 		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)
   4635 		j = j + y_lines_in
   4636 		if WebPRescaleNeededLines(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u, uv_mb_h-uv_j) != 0 {
   4637 			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)
   4638 			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)
   4639 			_ = v_lines_in // remove a gcc warning
   4640 			uv_j = uv_j + u_lines_in
   4641 		}
   4642 		num_lines_out = num_lines_out + ExportRGB(tls, p, (*WebPDecParams)(unsafe.Pointer(p)).Flast_y+num_lines_out)
   4643 	}
   4644 	return num_lines_out
   4645 }
   4646 
   4647 func ExportAlpha(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4648 	var alpha_first, is_premult_alpha, num_lines_out, width, v1, v3, v6, v9 int32
   4649 	var base_rgba, buf, dst, v5, v8 uintptr
   4650 	var colorspace, v2 WEBP_CSP_MODE1
   4651 	var non_opaque uint32_t
   4652 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_first, base_rgba, buf, colorspace, dst, is_premult_alpha, non_opaque, num_lines_out, width, v1, v2, v3, v5, v6, v8, v9
   4653 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4654 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4655 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4656 	alpha_first = libc.BoolInt32(colorspace == int32(MODE_ARGB) || colorspace == int32(MODE_Argb))
   4657 	if alpha_first != 0 {
   4658 		v1 = 0
   4659 	} else {
   4660 		v1 = int32(3)
   4661 	}
   4662 	dst = base_rgba + uintptr(v1)
   4663 	num_lines_out = 0
   4664 	v2 = colorspace
   4665 	v3 = libc.BoolInt32(v2 == int32(MODE_rgbA) || v2 == int32(MODE_bgrA) || v2 == int32(MODE_Argb) || v2 == int32(MODE_rgbA_4444))
   4666 	goto _4
   4667 _4:
   4668 	is_premult_alpha = v3
   4669 	non_opaque = uint32(0)
   4670 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4671 	for {
   4672 		v5 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4673 		v8 = v5
   4674 		v9 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v8)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v8)).Fdst_height)
   4675 		goto _10
   4676 	_10:
   4677 		;
   4678 		v6 = libc.BoolInt32(!(v9 != 0) && (*WebPRescaler)(unsafe.Pointer(v5)).Fy_accum <= 0)
   4679 		goto _7
   4680 	_7:
   4681 		;
   4682 		if !(v6 != 0 && num_lines_out < max_lines_out) {
   4683 			break
   4684 		}
   4685 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4686 		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))
   4687 		dst = dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4688 		num_lines_out = num_lines_out + 1
   4689 	}
   4690 	if is_premult_alpha != 0 && non_opaque != 0 {
   4691 		(*(*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)
   4692 	}
   4693 	return num_lines_out
   4694 }
   4695 
   4696 func ExportAlphaRGBA4444(tls *libc.TLS, p uintptr, y_pos int32, max_lines_out int32) (r int32) {
   4697 	var alpha_dst, base_rgba, buf, v4, v7 uintptr
   4698 	var alpha_mask, alpha_value uint32_t
   4699 	var colorspace, v1 WEBP_CSP_MODE1
   4700 	var i, is_premult_alpha, num_lines_out, width, v2, v5, v8 int32
   4701 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_dst, alpha_mask, alpha_value, base_rgba, buf, colorspace, i, is_premult_alpha, num_lines_out, width, v1, v2, v4, v5, v7, v8
   4702 	buf = (*WebPDecParams)(unsafe.Pointer(p)).Foutput + 16
   4703 	base_rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64(y_pos)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
   4704 	alpha_dst = base_rgba + uintptr(1)
   4705 	num_lines_out = 0
   4706 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4707 	width = (*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst_width
   4708 	v1 = colorspace
   4709 	v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
   4710 	goto _3
   4711 _3:
   4712 	is_premult_alpha = v2
   4713 	alpha_mask = uint32(0x0f)
   4714 	for {
   4715 		v4 = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4716 		v7 = v4
   4717 		v8 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v7)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v7)).Fdst_height)
   4718 		goto _9
   4719 	_9:
   4720 		;
   4721 		v5 = libc.BoolInt32(!(v8 != 0) && (*WebPRescaler)(unsafe.Pointer(v4)).Fy_accum <= 0)
   4722 		goto _6
   4723 	_6:
   4724 		;
   4725 		if !(v5 != 0 && num_lines_out < max_lines_out) {
   4726 			break
   4727 		}
   4728 		WebPRescalerExportRow(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)
   4729 		i = 0
   4730 		for {
   4731 			if !(i < width) {
   4732 				break
   4733 			}
   4734 			// Fill in the alpha value (converted to 4 bits).
   4735 			alpha_value = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a)).Fdst + uintptr(i)))) >> int32(4))
   4736 			**(**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)
   4737 			alpha_mask = alpha_mask & alpha_value
   4738 			goto _10
   4739 		_10:
   4740 			;
   4741 			i = i + 1
   4742 		}
   4743 		alpha_dst = alpha_dst + uintptr((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4744 		num_lines_out = num_lines_out + 1
   4745 	}
   4746 	if is_premult_alpha != 0 && alpha_mask != uint32(0x0f) {
   4747 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, base_rgba, width, num_lines_out, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
   4748 	}
   4749 	return num_lines_out
   4750 }
   4751 
   4752 func EmitRescaledAlphaRGB(tls *libc.TLS, io uintptr, p uintptr, expected_num_out_lines int32) (r int32) {
   4753 	var lines_left, y_end int32
   4754 	var row_offset int64_t
   4755 	var scaler uintptr
   4756 	_, _, _, _ = lines_left, row_offset, scaler, y_end
   4757 	if (*VP8Io)(unsafe.Pointer(io)).Fa != libc.UintptrFromInt32(0) {
   4758 		scaler = (*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a
   4759 		lines_left = expected_num_out_lines
   4760 		y_end = (*WebPDecParams)(unsafe.Pointer(p)).Flast_y + lines_left
   4761 		for lines_left > 0 {
   4762 			row_offset = int64((*WebPRescaler)(unsafe.Pointer(scaler)).Fsrc_y) - int64((*VP8Io)(unsafe.Pointer(io)).Fmb_y)
   4763 			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)
   4764 			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)
   4765 		}
   4766 	}
   4767 	return 0
   4768 }
   4769 
   4770 func InitRGBRescaler(tls *libc.TLS, io uintptr, p uintptr) (r int32) {
   4771 	var has_alpha, num_rescalers, out_height, out_width, uv_in_height, uv_in_width, v2, v5, v8 int32
   4772 	var rescaler_size, work_size size_t
   4773 	var scalers, tmp, work, v12 uintptr
   4774 	var tmp_size1, tmp_size2, total_size, v9 uint64_t
   4775 	var v1, v4 WEBP_CSP_MODE1
   4776 	var v7 bool
   4777 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
   4778 	v1 = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4779 	if v7 = v1 == int32(MODE_RGBA) || v1 == int32(MODE_BGRA) || v1 == int32(MODE_ARGB) || v1 == int32(MODE_RGBA_4444) || v1 == int32(MODE_YUVA); !v7 {
   4780 		v4 = v1
   4781 		v5 = libc.BoolInt32(v4 == int32(MODE_rgbA) || v4 == int32(MODE_bgrA) || v4 == int32(MODE_Argb) || v4 == int32(MODE_rgbA_4444))
   4782 		goto _6
   4783 	_6:
   4784 	}
   4785 	v2 = libc.BoolInt32(v7 || v5 != 0)
   4786 	goto _3
   4787 _3:
   4788 	has_alpha = v2
   4789 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
   4790 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
   4791 	uv_in_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4792 	uv_in_height = ((*VP8Io)(unsafe.Pointer(io)).Fmb_h + int32(1)) >> int32(1)
   4793 	// scratch memory for one rescaler
   4794 	work_size = uint64(2) * libc.Uint64FromInt32(out_width)
   4795 	if has_alpha != 0 {
   4796 		v8 = int32(4)
   4797 	} else {
   4798 		v8 = int32(3)
   4799 	}
   4800 	num_rescalers = v8
   4801 	tmp_size1 = libc.Uint64FromInt32(num_rescalers) * work_size
   4802 	tmp_size2 = libc.Uint64FromInt32(num_rescalers) * libc.Uint64FromInt32(out_width)
   4803 	total_size = tmp_size1*uint64(4) + tmp_size2*uint64(1)
   4804 	rescaler_size = libc.Uint64FromInt32(num_rescalers)*uint64(104) + uint64(WEBP_ALIGN_CST)
   4805 	total_size = total_size + rescaler_size
   4806 	v9 = total_size
   4807 	v2 = libc.BoolInt32(v9 == v9)
   4808 	goto _11
   4809 _11:
   4810 	if !(v2 != 0) {
   4811 		return 0
   4812 	}
   4813 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), total_size)
   4814 	if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4815 		return 0 // memory error
   4816 	}
   4817 	work = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4818 	tmp = work + uintptr(tmp_size1)*4
   4819 	scalers = uintptr((uint64(work+uintptr(total_size)-uintptr(rescaler_size)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
   4820 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_y = scalers
   4821 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_u = scalers + 1*104
   4822 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_v = scalers + 2*104
   4823 	if has_alpha != 0 {
   4824 		v12 = scalers + 3*104
   4825 	} else {
   4826 		v12 = libc.UintptrFromInt32(0)
   4827 	}
   4828 	(*WebPDecParams)(unsafe.Pointer(p)).Fscaler_a = v12
   4829 	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) {
   4830 		return 0
   4831 	}
   4832 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitRescaledRGB)
   4833 	WebPInitYUV444Converters(tls)
   4834 	if has_alpha != 0 {
   4835 		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) {
   4836 			return 0
   4837 		}
   4838 		(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = __ccgo_fp(EmitRescaledAlphaRGB)
   4839 		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) {
   4840 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlphaRGBA4444)
   4841 		} else {
   4842 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = __ccgo_fp(ExportAlpha)
   4843 		}
   4844 		WebPInitAlphaProcessing(tls)
   4845 	}
   4846 	return int32(1)
   4847 }
   4848 
   4849 //------------------------------------------------------------------------------
   4850 // Default custom functions
   4851 
   4852 func CustomSetup(tls *libc.TLS, io uintptr) (r int32) {
   4853 	var colorspace, v3, v6 WEBP_CSP_MODE1
   4854 	var is_alpha, is_rgb, ok, uv_width, v1, v4, v7 int32
   4855 	var p, v16, v17 uintptr
   4856 	var v9 bool
   4857 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = colorspace, is_alpha, is_rgb, ok, p, uv_width, v1, v16, v17, v3, v4, v6, v7, v9
   4858 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   4859 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(p)).Foutput)).Fcolorspace
   4860 	v1 = libc.BoolInt32(colorspace < int32(MODE_YUV))
   4861 	goto _2
   4862 _2:
   4863 	is_rgb = v1
   4864 	v3 = colorspace
   4865 	if v9 = v3 == int32(MODE_RGBA) || v3 == int32(MODE_BGRA) || v3 == int32(MODE_ARGB) || v3 == int32(MODE_RGBA_4444) || v3 == int32(MODE_YUVA); !v9 {
   4866 		v6 = v3
   4867 		v7 = libc.BoolInt32(v6 == int32(MODE_rgbA) || v6 == int32(MODE_bgrA) || v6 == int32(MODE_Argb) || v6 == int32(MODE_rgbA_4444))
   4868 		goto _8
   4869 	_8:
   4870 	}
   4871 	v4 = libc.BoolInt32(v9 || v7 != 0)
   4872 	goto _5
   4873 _5:
   4874 	is_alpha = v4
   4875 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   4876 	(*WebPDecParams)(unsafe.Pointer(p)).Femit = libc.UintptrFromInt32(0)
   4877 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = libc.UintptrFromInt32(0)
   4878 	(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha_row = libc.UintptrFromInt32(0)
   4879 	if is_alpha != 0 {
   4880 		v1 = int32(MODE_YUV)
   4881 	} else {
   4882 		v1 = int32(MODE_YUVA)
   4883 	}
   4884 	if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(p)).Foptions, io, v1) != 0) {
   4885 		return 0
   4886 	}
   4887 	if v9 = is_alpha != 0; v9 {
   4888 		v3 = colorspace
   4889 		v1 = libc.BoolInt32(v3 == int32(MODE_rgbA) || v3 == int32(MODE_bgrA) || v3 == int32(MODE_Argb) || v3 == int32(MODE_rgbA_4444))
   4890 		goto _13
   4891 	_13:
   4892 	}
   4893 	if v9 && v1 != 0 {
   4894 		WebPInitUpsamplers(tls)
   4895 	}
   4896 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
   4897 		if is_rgb != 0 {
   4898 			v1 = InitRGBRescaler(tls, io, p)
   4899 		} else {
   4900 			v1 = InitYUVRescaler(tls, io, p)
   4901 		}
   4902 		ok = v1
   4903 		if !(ok != 0) {
   4904 			return 0 // memory error
   4905 		}
   4906 	} else {
   4907 		if is_rgb != 0 {
   4908 			WebPInitSamplers(tls)
   4909 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitSampledRGB) // default
   4910 			if (*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling != 0 {
   4911 				uv_width = ((*VP8Io)(unsafe.Pointer(io)).Fmb_w + int32(1)) >> int32(1)
   4912 				(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = WebPSafeMalloc(tls, uint64(1), libc.Uint64FromInt32((*VP8Io)(unsafe.Pointer(io)).Fmb_w+libc.Int32FromInt32(2)*uv_width))
   4913 				if (*WebPDecParams)(unsafe.Pointer(p)).Fmemory == libc.UintptrFromInt32(0) {
   4914 					return 0 // memory error.
   4915 				}
   4916 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y = (*WebPDecParams)(unsafe.Pointer(p)).Fmemory
   4917 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_y + uintptr((*VP8Io)(unsafe.Pointer(io)).Fmb_w)
   4918 				(*WebPDecParams)(unsafe.Pointer(p)).Ftmp_v = (*WebPDecParams)(unsafe.Pointer(p)).Ftmp_u + uintptr(uv_width)
   4919 				(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitFancyRGB)
   4920 				WebPInitUpsamplers(tls)
   4921 			}
   4922 		} else {
   4923 			(*WebPDecParams)(unsafe.Pointer(p)).Femit = __ccgo_fp(EmitYUV)
   4924 		}
   4925 		if is_alpha != 0 { // need transparency output
   4926 			if colorspace == int32(MODE_RGBA_4444) || colorspace == int32(MODE_rgbA_4444) {
   4927 				v16 = __ccgo_fp(EmitAlphaRGBA4444)
   4928 			} else {
   4929 				if is_rgb != 0 {
   4930 					v17 = __ccgo_fp(EmitAlphaRGB)
   4931 				} else {
   4932 					v17 = __ccgo_fp(EmitAlphaYUV)
   4933 				}
   4934 				v16 = v17
   4935 			}
   4936 			(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha = v16
   4937 			if is_rgb != 0 {
   4938 				WebPInitAlphaProcessing(tls)
   4939 			}
   4940 		}
   4941 	}
   4942 	return int32(1)
   4943 }
   4944 
   4945 //------------------------------------------------------------------------------
   4946 
   4947 func CustomPut(tls *libc.TLS, io uintptr) (r int32) {
   4948 	var mb_h, mb_w, num_lines_out int32
   4949 	var p uintptr
   4950 	_, _, _, _ = mb_h, mb_w, num_lines_out, p
   4951 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   4952 	mb_w = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
   4953 	mb_h = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
   4954 	if mb_w <= 0 || mb_h <= 0 {
   4955 		return 0
   4956 	}
   4957 	num_lines_out = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit})))(tls, io, p)
   4958 	if (*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha != libc.UintptrFromInt32(0) {
   4959 		(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPDecParams)(unsafe.Pointer(p)).Femit_alpha})))(tls, io, p, num_lines_out)
   4960 	}
   4961 	**(**int32)(__ccgo_up(p + 32)) += num_lines_out
   4962 	return int32(1)
   4963 }
   4964 
   4965 //------------------------------------------------------------------------------
   4966 
   4967 func CustomTeardown(tls *libc.TLS, io uintptr) {
   4968 	var p uintptr
   4969 	_ = p
   4970 	p = (*VP8Io)(unsafe.Pointer(io)).Fopaque
   4971 	WebPSafeFree(tls, (*WebPDecParams)(unsafe.Pointer(p)).Fmemory)
   4972 	(*WebPDecParams)(unsafe.Pointer(p)).Fmemory = libc.UintptrFromInt32(0)
   4973 }
   4974 
   4975 //------------------------------------------------------------------------------
   4976 // Main entry point
   4977 
   4978 func WebPInitCustomIo(tls *libc.TLS, params uintptr, io uintptr) {
   4979 	(*VP8Io)(unsafe.Pointer(io)).Fput = __ccgo_fp(CustomPut)
   4980 	(*VP8Io)(unsafe.Pointer(io)).Fsetup = __ccgo_fp(CustomSetup)
   4981 	(*VP8Io)(unsafe.Pointer(io)).Fteardown = __ccgo_fp(CustomTeardown)
   4982 	(*VP8Io)(unsafe.Pointer(io)).Fopaque = params
   4983 }
   4984 
   4985 var kHashMul5 = uint32(0x1e35a7bd)
   4986 
   4987 //------------------------------------------------------------------------------
   4988 
   4989 // Copyright 2010 Google Inc. All Rights Reserved.
   4990 //
   4991 // Use of this source code is governed by a BSD-style license
   4992 // that can be found in the COPYING file in the root of the source
   4993 // tree. An additional intellectual property rights grant can be found
   4994 // in the file PATENTS. All contributing project authors may
   4995 // be found in the AUTHORS file in the root of the source tree.
   4996 // -----------------------------------------------------------------------------
   4997 //
   4998 // Boolean decoder
   4999 //
   5000 // Author: Skal (pascal.massimino@gmail.com)
   5001 //         Vikas Arora (vikaas.arora@gmail.com)
   5002 
   5003 // Copyright 2010 Google Inc. All Rights Reserved.
   5004 //
   5005 // Use of this source code is governed by a BSD-style license
   5006 // that can be found in the COPYING file in the root of the source
   5007 // tree. An additional intellectual property rights grant can be found
   5008 // in the file PATENTS. All contributing project authors may
   5009 // be found in the AUTHORS file in the root of the source tree.
   5010 // -----------------------------------------------------------------------------
   5011 //
   5012 //  Common types + memory wrappers
   5013 //
   5014 // Author: Skal (pascal.massimino@gmail.com)
   5015 
   5016 func clip(tls *libc.TLS, v int32, M int32) (r int32) {
   5017 	var v1, v2 int32
   5018 	_, _ = v1, v2
   5019 	if v < 0 {
   5020 		v1 = 0
   5021 	} else {
   5022 		if v > M {
   5023 			v2 = M
   5024 		} else {
   5025 			v2 = v
   5026 		}
   5027 		v1 = v2
   5028 	}
   5029 	return v1
   5030 }
   5031 
   5032 // C documentation
   5033 //
   5034 //	// Paragraph 14.1
   5035 var kDcTable = [128]uint8_t{
   5036 	0:   uint8(4),
   5037 	1:   uint8(5),
   5038 	2:   uint8(6),
   5039 	3:   uint8(7),
   5040 	4:   uint8(8),
   5041 	5:   uint8(9),
   5042 	6:   uint8(10),
   5043 	7:   uint8(10),
   5044 	8:   uint8(11),
   5045 	9:   uint8(12),
   5046 	10:  uint8(13),
   5047 	11:  uint8(14),
   5048 	12:  uint8(15),
   5049 	13:  uint8(16),
   5050 	14:  uint8(17),
   5051 	15:  uint8(17),
   5052 	16:  uint8(18),
   5053 	17:  uint8(19),
   5054 	18:  uint8(20),
   5055 	19:  uint8(20),
   5056 	20:  uint8(21),
   5057 	21:  uint8(21),
   5058 	22:  uint8(22),
   5059 	23:  uint8(22),
   5060 	24:  uint8(23),
   5061 	25:  uint8(23),
   5062 	26:  uint8(24),
   5063 	27:  uint8(25),
   5064 	28:  uint8(25),
   5065 	29:  uint8(26),
   5066 	30:  uint8(27),
   5067 	31:  uint8(28),
   5068 	32:  uint8(29),
   5069 	33:  uint8(30),
   5070 	34:  uint8(31),
   5071 	35:  uint8(32),
   5072 	36:  uint8(33),
   5073 	37:  uint8(34),
   5074 	38:  uint8(35),
   5075 	39:  uint8(36),
   5076 	40:  uint8(37),
   5077 	41:  uint8(37),
   5078 	42:  uint8(38),
   5079 	43:  uint8(39),
   5080 	44:  uint8(40),
   5081 	45:  uint8(41),
   5082 	46:  uint8(42),
   5083 	47:  uint8(43),
   5084 	48:  uint8(44),
   5085 	49:  uint8(45),
   5086 	50:  uint8(46),
   5087 	51:  uint8(46),
   5088 	52:  uint8(47),
   5089 	53:  uint8(48),
   5090 	54:  uint8(49),
   5091 	55:  uint8(50),
   5092 	56:  uint8(51),
   5093 	57:  uint8(52),
   5094 	58:  uint8(53),
   5095 	59:  uint8(54),
   5096 	60:  uint8(55),
   5097 	61:  uint8(56),
   5098 	62:  uint8(57),
   5099 	63:  uint8(58),
   5100 	64:  uint8(59),
   5101 	65:  uint8(60),
   5102 	66:  uint8(61),
   5103 	67:  uint8(62),
   5104 	68:  uint8(63),
   5105 	69:  uint8(64),
   5106 	70:  uint8(65),
   5107 	71:  uint8(66),
   5108 	72:  uint8(67),
   5109 	73:  uint8(68),
   5110 	74:  uint8(69),
   5111 	75:  uint8(70),
   5112 	76:  uint8(71),
   5113 	77:  uint8(72),
   5114 	78:  uint8(73),
   5115 	79:  uint8(74),
   5116 	80:  uint8(75),
   5117 	81:  uint8(76),
   5118 	82:  uint8(76),
   5119 	83:  uint8(77),
   5120 	84:  uint8(78),
   5121 	85:  uint8(79),
   5122 	86:  uint8(80),
   5123 	87:  uint8(81),
   5124 	88:  uint8(82),
   5125 	89:  uint8(83),
   5126 	90:  uint8(84),
   5127 	91:  uint8(85),
   5128 	92:  uint8(86),
   5129 	93:  uint8(87),
   5130 	94:  uint8(88),
   5131 	95:  uint8(89),
   5132 	96:  uint8(91),
   5133 	97:  uint8(93),
   5134 	98:  uint8(95),
   5135 	99:  uint8(96),
   5136 	100: uint8(98),
   5137 	101: uint8(100),
   5138 	102: uint8(101),
   5139 	103: uint8(102),
   5140 	104: uint8(104),
   5141 	105: uint8(106),
   5142 	106: uint8(108),
   5143 	107: uint8(110),
   5144 	108: uint8(112),
   5145 	109: uint8(114),
   5146 	110: uint8(116),
   5147 	111: uint8(118),
   5148 	112: uint8(122),
   5149 	113: uint8(124),
   5150 	114: uint8(126),
   5151 	115: uint8(128),
   5152 	116: uint8(130),
   5153 	117: uint8(132),
   5154 	118: uint8(134),
   5155 	119: uint8(136),
   5156 	120: uint8(138),
   5157 	121: uint8(140),
   5158 	122: uint8(143),
   5159 	123: uint8(145),
   5160 	124: uint8(148),
   5161 	125: uint8(151),
   5162 	126: uint8(154),
   5163 	127: uint8(157),
   5164 }
   5165 
   5166 var kAcTable = [128]uint16_t{
   5167 	0:   uint16(4),
   5168 	1:   uint16(5),
   5169 	2:   uint16(6),
   5170 	3:   uint16(7),
   5171 	4:   uint16(8),
   5172 	5:   uint16(9),
   5173 	6:   uint16(10),
   5174 	7:   uint16(11),
   5175 	8:   uint16(12),
   5176 	9:   uint16(13),
   5177 	10:  uint16(14),
   5178 	11:  uint16(15),
   5179 	12:  uint16(16),
   5180 	13:  uint16(17),
   5181 	14:  uint16(18),
   5182 	15:  uint16(19),
   5183 	16:  uint16(20),
   5184 	17:  uint16(21),
   5185 	18:  uint16(22),
   5186 	19:  uint16(23),
   5187 	20:  uint16(24),
   5188 	21:  uint16(25),
   5189 	22:  uint16(26),
   5190 	23:  uint16(27),
   5191 	24:  uint16(28),
   5192 	25:  uint16(29),
   5193 	26:  uint16(30),
   5194 	27:  uint16(31),
   5195 	28:  uint16(32),
   5196 	29:  uint16(33),
   5197 	30:  uint16(34),
   5198 	31:  uint16(35),
   5199 	32:  uint16(36),
   5200 	33:  uint16(37),
   5201 	34:  uint16(38),
   5202 	35:  uint16(39),
   5203 	36:  uint16(40),
   5204 	37:  uint16(41),
   5205 	38:  uint16(42),
   5206 	39:  uint16(43),
   5207 	40:  uint16(44),
   5208 	41:  uint16(45),
   5209 	42:  uint16(46),
   5210 	43:  uint16(47),
   5211 	44:  uint16(48),
   5212 	45:  uint16(49),
   5213 	46:  uint16(50),
   5214 	47:  uint16(51),
   5215 	48:  uint16(52),
   5216 	49:  uint16(53),
   5217 	50:  uint16(54),
   5218 	51:  uint16(55),
   5219 	52:  uint16(56),
   5220 	53:  uint16(57),
   5221 	54:  uint16(58),
   5222 	55:  uint16(60),
   5223 	56:  uint16(62),
   5224 	57:  uint16(64),
   5225 	58:  uint16(66),
   5226 	59:  uint16(68),
   5227 	60:  uint16(70),
   5228 	61:  uint16(72),
   5229 	62:  uint16(74),
   5230 	63:  uint16(76),
   5231 	64:  uint16(78),
   5232 	65:  uint16(80),
   5233 	66:  uint16(82),
   5234 	67:  uint16(84),
   5235 	68:  uint16(86),
   5236 	69:  uint16(88),
   5237 	70:  uint16(90),
   5238 	71:  uint16(92),
   5239 	72:  uint16(94),
   5240 	73:  uint16(96),
   5241 	74:  uint16(98),
   5242 	75:  uint16(100),
   5243 	76:  uint16(102),
   5244 	77:  uint16(104),
   5245 	78:  uint16(106),
   5246 	79:  uint16(108),
   5247 	80:  uint16(110),
   5248 	81:  uint16(112),
   5249 	82:  uint16(114),
   5250 	83:  uint16(116),
   5251 	84:  uint16(119),
   5252 	85:  uint16(122),
   5253 	86:  uint16(125),
   5254 	87:  uint16(128),
   5255 	88:  uint16(131),
   5256 	89:  uint16(134),
   5257 	90:  uint16(137),
   5258 	91:  uint16(140),
   5259 	92:  uint16(143),
   5260 	93:  uint16(146),
   5261 	94:  uint16(149),
   5262 	95:  uint16(152),
   5263 	96:  uint16(155),
   5264 	97:  uint16(158),
   5265 	98:  uint16(161),
   5266 	99:  uint16(164),
   5267 	100: uint16(167),
   5268 	101: uint16(170),
   5269 	102: uint16(173),
   5270 	103: uint16(177),
   5271 	104: uint16(181),
   5272 	105: uint16(185),
   5273 	106: uint16(189),
   5274 	107: uint16(193),
   5275 	108: uint16(197),
   5276 	109: uint16(201),
   5277 	110: uint16(205),
   5278 	111: uint16(209),
   5279 	112: uint16(213),
   5280 	113: uint16(217),
   5281 	114: uint16(221),
   5282 	115: uint16(225),
   5283 	116: uint16(229),
   5284 	117: uint16(234),
   5285 	118: uint16(239),
   5286 	119: uint16(245),
   5287 	120: uint16(249),
   5288 	121: uint16(254),
   5289 	122: uint16(259),
   5290 	123: uint16(264),
   5291 	124: uint16(269),
   5292 	125: uint16(274),
   5293 	126: uint16(279),
   5294 	127: uint16(284),
   5295 }
   5296 
   5297 //------------------------------------------------------------------------------
   5298 // Paragraph 9.6
   5299 
   5300 func VP8ParseQuant(tls *libc.TLS, dec uintptr) {
   5301 	var base_q0, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, i, q, v1, v2, v3, v4, v5 int32
   5302 	var br, hdr, m uintptr
   5303 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_q0, br, dquv_ac, dquv_dc, dqy1_dc, dqy2_ac, dqy2_dc, hdr, i, m, q, v1, v2, v3, v4, v5
   5304 	br = dec + 16
   5305 	base_q0 = libc.Int32FromUint32(VP8GetValue(tls, br, int32(7)))
   5306 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5307 		v1 = VP8GetSignedValue(tls, br, int32(4))
   5308 	} else {
   5309 		v1 = 0
   5310 	}
   5311 	dqy1_dc = v1
   5312 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5313 		v2 = VP8GetSignedValue(tls, br, int32(4))
   5314 	} else {
   5315 		v2 = 0
   5316 	}
   5317 	dqy2_dc = v2
   5318 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5319 		v3 = VP8GetSignedValue(tls, br, int32(4))
   5320 	} else {
   5321 		v3 = 0
   5322 	}
   5323 	dqy2_ac = v3
   5324 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5325 		v4 = VP8GetSignedValue(tls, br, int32(4))
   5326 	} else {
   5327 		v4 = 0
   5328 	}
   5329 	dquv_dc = v4
   5330 	if VP8GetValue(tls, br, int32(1)) != 0 {
   5331 		v5 = VP8GetSignedValue(tls, br, int32(4))
   5332 	} else {
   5333 		v5 = 0
   5334 	}
   5335 	dquv_ac = v5
   5336 	hdr = dec + 132
   5337 	i = 0
   5338 	for {
   5339 		if !(i < int32(NUM_MB_SEGMENTS)) {
   5340 			break
   5341 		}
   5342 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
   5343 			q = int32(**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(i))))
   5344 			if !((*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta != 0) {
   5345 				q = q + base_q0
   5346 			}
   5347 		} else {
   5348 			if i > 0 {
   5349 				**(**VP8QuantMatrix)(__ccgo_up(dec + 1060 + uintptr(i)*32)) = **(**VP8QuantMatrix)(__ccgo_up(dec + 1060))
   5350 				goto _6
   5351 			} else {
   5352 				q = base_q0
   5353 			}
   5354 		}
   5355 		m = dec + 1060 + uintptr(i)*32
   5356 		**(**int32)(__ccgo_up(m)) = libc.Int32FromUint8(kDcTable[clip(tls, q+dqy1_dc, int32(127))])
   5357 		**(**int32)(__ccgo_up(m + 1*4)) = libc.Int32FromUint16(kAcTable[clip(tls, q+0, int32(127))])
   5358 		**(**int32)(__ccgo_up(m + 8)) = libc.Int32FromUint8(kDcTable[clip(tls, q+dqy2_dc, int32(127))]) * int32(2)
   5359 		// For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
   5360 		// The smallest precision for that is '(x*6349) >> 12' but 16 is a good
   5361 		// word size.
   5362 		**(**int32)(__ccgo_up(m + 8 + 1*4)) = libc.Int32FromUint16(kAcTable[clip(tls, q+dqy2_ac, int32(127))]) * int32(101581) >> int32(16)
   5363 		if **(**int32)(__ccgo_up(m + 8 + 1*4)) < int32(8) {
   5364 			**(**int32)(__ccgo_up(m + 8 + 1*4)) = int32(8)
   5365 		}
   5366 		**(**int32)(__ccgo_up(m + 16)) = libc.Int32FromUint8(kDcTable[clip(tls, q+dquv_dc, int32(117))])
   5367 		**(**int32)(__ccgo_up(m + 16 + 1*4)) = libc.Int32FromUint16(kAcTable[clip(tls, q+dquv_ac, int32(127))])
   5368 		(*VP8QuantMatrix)(unsafe.Pointer(m)).Fuv_quant = q + dquv_ac // for dithering strength evaluation
   5369 		goto _6
   5370 	_6:
   5371 		;
   5372 		i = i + 1
   5373 	}
   5374 }
   5375 
   5376 const USE_GENERIC_TREE = 0
   5377 
   5378 var kHashMul6 = uint32(0x1e35a7bd)
   5379 
   5380 type lbit_t = uint64
   5381 
   5382 // Copyright 2010 Google Inc. All Rights Reserved.
   5383 //
   5384 // Use of this source code is governed by a BSD-style license
   5385 // that can be found in the COPYING file in the root of the source
   5386 // tree. An additional intellectual property rights grant can be found
   5387 // in the file PATENTS. All contributing project authors may
   5388 // be found in the AUTHORS file in the root of the source tree.
   5389 // -----------------------------------------------------------------------------
   5390 //
   5391 // Boolean decoder
   5392 //
   5393 // Author: Skal (pascal.massimino@gmail.com)
   5394 //         Vikas Arora (vikaas.arora@gmail.com)
   5395 
   5396 //------------------------------------------------------------------------------
   5397 // Default probabilities
   5398 
   5399 // C documentation
   5400 //
   5401 //	// Paragraph 13.5
   5402 
   5403 var CoeffsProba0 = [4][8][3][11]uint8_t{
   5404 	0: {
   5405 		0: {
   5406 			0: {
   5407 				0:  uint8(128),
   5408 				1:  uint8(128),
   5409 				2:  uint8(128),
   5410 				3:  uint8(128),
   5411 				4:  uint8(128),
   5412 				5:  uint8(128),
   5413 				6:  uint8(128),
   5414 				7:  uint8(128),
   5415 				8:  uint8(128),
   5416 				9:  uint8(128),
   5417 				10: uint8(128),
   5418 			},
   5419 			1: {
   5420 				0:  uint8(128),
   5421 				1:  uint8(128),
   5422 				2:  uint8(128),
   5423 				3:  uint8(128),
   5424 				4:  uint8(128),
   5425 				5:  uint8(128),
   5426 				6:  uint8(128),
   5427 				7:  uint8(128),
   5428 				8:  uint8(128),
   5429 				9:  uint8(128),
   5430 				10: uint8(128),
   5431 			},
   5432 			2: {
   5433 				0:  uint8(128),
   5434 				1:  uint8(128),
   5435 				2:  uint8(128),
   5436 				3:  uint8(128),
   5437 				4:  uint8(128),
   5438 				5:  uint8(128),
   5439 				6:  uint8(128),
   5440 				7:  uint8(128),
   5441 				8:  uint8(128),
   5442 				9:  uint8(128),
   5443 				10: uint8(128),
   5444 			},
   5445 		},
   5446 		1: {
   5447 			0: {
   5448 				0:  uint8(253),
   5449 				1:  uint8(136),
   5450 				2:  uint8(254),
   5451 				3:  uint8(255),
   5452 				4:  uint8(228),
   5453 				5:  uint8(219),
   5454 				6:  uint8(128),
   5455 				7:  uint8(128),
   5456 				8:  uint8(128),
   5457 				9:  uint8(128),
   5458 				10: uint8(128),
   5459 			},
   5460 			1: {
   5461 				0:  uint8(189),
   5462 				1:  uint8(129),
   5463 				2:  uint8(242),
   5464 				3:  uint8(255),
   5465 				4:  uint8(227),
   5466 				5:  uint8(213),
   5467 				6:  uint8(255),
   5468 				7:  uint8(219),
   5469 				8:  uint8(128),
   5470 				9:  uint8(128),
   5471 				10: uint8(128),
   5472 			},
   5473 			2: {
   5474 				0:  uint8(106),
   5475 				1:  uint8(126),
   5476 				2:  uint8(227),
   5477 				3:  uint8(252),
   5478 				4:  uint8(214),
   5479 				5:  uint8(209),
   5480 				6:  uint8(255),
   5481 				7:  uint8(255),
   5482 				8:  uint8(128),
   5483 				9:  uint8(128),
   5484 				10: uint8(128),
   5485 			},
   5486 		},
   5487 		2: {
   5488 			0: {
   5489 				0:  uint8(1),
   5490 				1:  uint8(98),
   5491 				2:  uint8(248),
   5492 				3:  uint8(255),
   5493 				4:  uint8(236),
   5494 				5:  uint8(226),
   5495 				6:  uint8(255),
   5496 				7:  uint8(255),
   5497 				8:  uint8(128),
   5498 				9:  uint8(128),
   5499 				10: uint8(128),
   5500 			},
   5501 			1: {
   5502 				0:  uint8(181),
   5503 				1:  uint8(133),
   5504 				2:  uint8(238),
   5505 				3:  uint8(254),
   5506 				4:  uint8(221),
   5507 				5:  uint8(234),
   5508 				6:  uint8(255),
   5509 				7:  uint8(154),
   5510 				8:  uint8(128),
   5511 				9:  uint8(128),
   5512 				10: uint8(128),
   5513 			},
   5514 			2: {
   5515 				0:  uint8(78),
   5516 				1:  uint8(134),
   5517 				2:  uint8(202),
   5518 				3:  uint8(247),
   5519 				4:  uint8(198),
   5520 				5:  uint8(180),
   5521 				6:  uint8(255),
   5522 				7:  uint8(219),
   5523 				8:  uint8(128),
   5524 				9:  uint8(128),
   5525 				10: uint8(128),
   5526 			},
   5527 		},
   5528 		3: {
   5529 			0: {
   5530 				0:  uint8(1),
   5531 				1:  uint8(185),
   5532 				2:  uint8(249),
   5533 				3:  uint8(255),
   5534 				4:  uint8(243),
   5535 				5:  uint8(255),
   5536 				6:  uint8(128),
   5537 				7:  uint8(128),
   5538 				8:  uint8(128),
   5539 				9:  uint8(128),
   5540 				10: uint8(128),
   5541 			},
   5542 			1: {
   5543 				0:  uint8(184),
   5544 				1:  uint8(150),
   5545 				2:  uint8(247),
   5546 				3:  uint8(255),
   5547 				4:  uint8(236),
   5548 				5:  uint8(224),
   5549 				6:  uint8(128),
   5550 				7:  uint8(128),
   5551 				8:  uint8(128),
   5552 				9:  uint8(128),
   5553 				10: uint8(128),
   5554 			},
   5555 			2: {
   5556 				0:  uint8(77),
   5557 				1:  uint8(110),
   5558 				2:  uint8(216),
   5559 				3:  uint8(255),
   5560 				4:  uint8(236),
   5561 				5:  uint8(230),
   5562 				6:  uint8(128),
   5563 				7:  uint8(128),
   5564 				8:  uint8(128),
   5565 				9:  uint8(128),
   5566 				10: uint8(128),
   5567 			},
   5568 		},
   5569 		4: {
   5570 			0: {
   5571 				0:  uint8(1),
   5572 				1:  uint8(101),
   5573 				2:  uint8(251),
   5574 				3:  uint8(255),
   5575 				4:  uint8(241),
   5576 				5:  uint8(255),
   5577 				6:  uint8(128),
   5578 				7:  uint8(128),
   5579 				8:  uint8(128),
   5580 				9:  uint8(128),
   5581 				10: uint8(128),
   5582 			},
   5583 			1: {
   5584 				0:  uint8(170),
   5585 				1:  uint8(139),
   5586 				2:  uint8(241),
   5587 				3:  uint8(252),
   5588 				4:  uint8(236),
   5589 				5:  uint8(209),
   5590 				6:  uint8(255),
   5591 				7:  uint8(255),
   5592 				8:  uint8(128),
   5593 				9:  uint8(128),
   5594 				10: uint8(128),
   5595 			},
   5596 			2: {
   5597 				0:  uint8(37),
   5598 				1:  uint8(116),
   5599 				2:  uint8(196),
   5600 				3:  uint8(243),
   5601 				4:  uint8(228),
   5602 				5:  uint8(255),
   5603 				6:  uint8(255),
   5604 				7:  uint8(255),
   5605 				8:  uint8(128),
   5606 				9:  uint8(128),
   5607 				10: uint8(128),
   5608 			},
   5609 		},
   5610 		5: {
   5611 			0: {
   5612 				0:  uint8(1),
   5613 				1:  uint8(204),
   5614 				2:  uint8(254),
   5615 				3:  uint8(255),
   5616 				4:  uint8(245),
   5617 				5:  uint8(255),
   5618 				6:  uint8(128),
   5619 				7:  uint8(128),
   5620 				8:  uint8(128),
   5621 				9:  uint8(128),
   5622 				10: uint8(128),
   5623 			},
   5624 			1: {
   5625 				0:  uint8(207),
   5626 				1:  uint8(160),
   5627 				2:  uint8(250),
   5628 				3:  uint8(255),
   5629 				4:  uint8(238),
   5630 				5:  uint8(128),
   5631 				6:  uint8(128),
   5632 				7:  uint8(128),
   5633 				8:  uint8(128),
   5634 				9:  uint8(128),
   5635 				10: uint8(128),
   5636 			},
   5637 			2: {
   5638 				0:  uint8(102),
   5639 				1:  uint8(103),
   5640 				2:  uint8(231),
   5641 				3:  uint8(255),
   5642 				4:  uint8(211),
   5643 				5:  uint8(171),
   5644 				6:  uint8(128),
   5645 				7:  uint8(128),
   5646 				8:  uint8(128),
   5647 				9:  uint8(128),
   5648 				10: uint8(128),
   5649 			},
   5650 		},
   5651 		6: {
   5652 			0: {
   5653 				0:  uint8(1),
   5654 				1:  uint8(152),
   5655 				2:  uint8(252),
   5656 				3:  uint8(255),
   5657 				4:  uint8(240),
   5658 				5:  uint8(255),
   5659 				6:  uint8(128),
   5660 				7:  uint8(128),
   5661 				8:  uint8(128),
   5662 				9:  uint8(128),
   5663 				10: uint8(128),
   5664 			},
   5665 			1: {
   5666 				0:  uint8(177),
   5667 				1:  uint8(135),
   5668 				2:  uint8(243),
   5669 				3:  uint8(255),
   5670 				4:  uint8(234),
   5671 				5:  uint8(225),
   5672 				6:  uint8(128),
   5673 				7:  uint8(128),
   5674 				8:  uint8(128),
   5675 				9:  uint8(128),
   5676 				10: uint8(128),
   5677 			},
   5678 			2: {
   5679 				0:  uint8(80),
   5680 				1:  uint8(129),
   5681 				2:  uint8(211),
   5682 				3:  uint8(255),
   5683 				4:  uint8(194),
   5684 				5:  uint8(224),
   5685 				6:  uint8(128),
   5686 				7:  uint8(128),
   5687 				8:  uint8(128),
   5688 				9:  uint8(128),
   5689 				10: uint8(128),
   5690 			},
   5691 		},
   5692 		7: {
   5693 			0: {
   5694 				0:  uint8(1),
   5695 				1:  uint8(1),
   5696 				2:  uint8(255),
   5697 				3:  uint8(128),
   5698 				4:  uint8(128),
   5699 				5:  uint8(128),
   5700 				6:  uint8(128),
   5701 				7:  uint8(128),
   5702 				8:  uint8(128),
   5703 				9:  uint8(128),
   5704 				10: uint8(128),
   5705 			},
   5706 			1: {
   5707 				0:  uint8(246),
   5708 				1:  uint8(1),
   5709 				2:  uint8(255),
   5710 				3:  uint8(128),
   5711 				4:  uint8(128),
   5712 				5:  uint8(128),
   5713 				6:  uint8(128),
   5714 				7:  uint8(128),
   5715 				8:  uint8(128),
   5716 				9:  uint8(128),
   5717 				10: uint8(128),
   5718 			},
   5719 			2: {
   5720 				0:  uint8(255),
   5721 				1:  uint8(128),
   5722 				2:  uint8(128),
   5723 				3:  uint8(128),
   5724 				4:  uint8(128),
   5725 				5:  uint8(128),
   5726 				6:  uint8(128),
   5727 				7:  uint8(128),
   5728 				8:  uint8(128),
   5729 				9:  uint8(128),
   5730 				10: uint8(128),
   5731 			},
   5732 		},
   5733 	},
   5734 	1: {
   5735 		0: {
   5736 			0: {
   5737 				0:  uint8(198),
   5738 				1:  uint8(35),
   5739 				2:  uint8(237),
   5740 				3:  uint8(223),
   5741 				4:  uint8(193),
   5742 				5:  uint8(187),
   5743 				6:  uint8(162),
   5744 				7:  uint8(160),
   5745 				8:  uint8(145),
   5746 				9:  uint8(155),
   5747 				10: uint8(62),
   5748 			},
   5749 			1: {
   5750 				0:  uint8(131),
   5751 				1:  uint8(45),
   5752 				2:  uint8(198),
   5753 				3:  uint8(221),
   5754 				4:  uint8(172),
   5755 				5:  uint8(176),
   5756 				6:  uint8(220),
   5757 				7:  uint8(157),
   5758 				8:  uint8(252),
   5759 				9:  uint8(221),
   5760 				10: uint8(1),
   5761 			},
   5762 			2: {
   5763 				0:  uint8(68),
   5764 				1:  uint8(47),
   5765 				2:  uint8(146),
   5766 				3:  uint8(208),
   5767 				4:  uint8(149),
   5768 				5:  uint8(167),
   5769 				6:  uint8(221),
   5770 				7:  uint8(162),
   5771 				8:  uint8(255),
   5772 				9:  uint8(223),
   5773 				10: uint8(128),
   5774 			},
   5775 		},
   5776 		1: {
   5777 			0: {
   5778 				0:  uint8(1),
   5779 				1:  uint8(149),
   5780 				2:  uint8(241),
   5781 				3:  uint8(255),
   5782 				4:  uint8(221),
   5783 				5:  uint8(224),
   5784 				6:  uint8(255),
   5785 				7:  uint8(255),
   5786 				8:  uint8(128),
   5787 				9:  uint8(128),
   5788 				10: uint8(128),
   5789 			},
   5790 			1: {
   5791 				0:  uint8(184),
   5792 				1:  uint8(141),
   5793 				2:  uint8(234),
   5794 				3:  uint8(253),
   5795 				4:  uint8(222),
   5796 				5:  uint8(220),
   5797 				6:  uint8(255),
   5798 				7:  uint8(199),
   5799 				8:  uint8(128),
   5800 				9:  uint8(128),
   5801 				10: uint8(128),
   5802 			},
   5803 			2: {
   5804 				0:  uint8(81),
   5805 				1:  uint8(99),
   5806 				2:  uint8(181),
   5807 				3:  uint8(242),
   5808 				4:  uint8(176),
   5809 				5:  uint8(190),
   5810 				6:  uint8(249),
   5811 				7:  uint8(202),
   5812 				8:  uint8(255),
   5813 				9:  uint8(255),
   5814 				10: uint8(128),
   5815 			},
   5816 		},
   5817 		2: {
   5818 			0: {
   5819 				0:  uint8(1),
   5820 				1:  uint8(129),
   5821 				2:  uint8(232),
   5822 				3:  uint8(253),
   5823 				4:  uint8(214),
   5824 				5:  uint8(197),
   5825 				6:  uint8(242),
   5826 				7:  uint8(196),
   5827 				8:  uint8(255),
   5828 				9:  uint8(255),
   5829 				10: uint8(128),
   5830 			},
   5831 			1: {
   5832 				0:  uint8(99),
   5833 				1:  uint8(121),
   5834 				2:  uint8(210),
   5835 				3:  uint8(250),
   5836 				4:  uint8(201),
   5837 				5:  uint8(198),
   5838 				6:  uint8(255),
   5839 				7:  uint8(202),
   5840 				8:  uint8(128),
   5841 				9:  uint8(128),
   5842 				10: uint8(128),
   5843 			},
   5844 			2: {
   5845 				0:  uint8(23),
   5846 				1:  uint8(91),
   5847 				2:  uint8(163),
   5848 				3:  uint8(242),
   5849 				4:  uint8(170),
   5850 				5:  uint8(187),
   5851 				6:  uint8(247),
   5852 				7:  uint8(210),
   5853 				8:  uint8(255),
   5854 				9:  uint8(255),
   5855 				10: uint8(128),
   5856 			},
   5857 		},
   5858 		3: {
   5859 			0: {
   5860 				0:  uint8(1),
   5861 				1:  uint8(200),
   5862 				2:  uint8(246),
   5863 				3:  uint8(255),
   5864 				4:  uint8(234),
   5865 				5:  uint8(255),
   5866 				6:  uint8(128),
   5867 				7:  uint8(128),
   5868 				8:  uint8(128),
   5869 				9:  uint8(128),
   5870 				10: uint8(128),
   5871 			},
   5872 			1: {
   5873 				0:  uint8(109),
   5874 				1:  uint8(178),
   5875 				2:  uint8(241),
   5876 				3:  uint8(255),
   5877 				4:  uint8(231),
   5878 				5:  uint8(245),
   5879 				6:  uint8(255),
   5880 				7:  uint8(255),
   5881 				8:  uint8(128),
   5882 				9:  uint8(128),
   5883 				10: uint8(128),
   5884 			},
   5885 			2: {
   5886 				0:  uint8(44),
   5887 				1:  uint8(130),
   5888 				2:  uint8(201),
   5889 				3:  uint8(253),
   5890 				4:  uint8(205),
   5891 				5:  uint8(192),
   5892 				6:  uint8(255),
   5893 				7:  uint8(255),
   5894 				8:  uint8(128),
   5895 				9:  uint8(128),
   5896 				10: uint8(128),
   5897 			},
   5898 		},
   5899 		4: {
   5900 			0: {
   5901 				0:  uint8(1),
   5902 				1:  uint8(132),
   5903 				2:  uint8(239),
   5904 				3:  uint8(251),
   5905 				4:  uint8(219),
   5906 				5:  uint8(209),
   5907 				6:  uint8(255),
   5908 				7:  uint8(165),
   5909 				8:  uint8(128),
   5910 				9:  uint8(128),
   5911 				10: uint8(128),
   5912 			},
   5913 			1: {
   5914 				0:  uint8(94),
   5915 				1:  uint8(136),
   5916 				2:  uint8(225),
   5917 				3:  uint8(251),
   5918 				4:  uint8(218),
   5919 				5:  uint8(190),
   5920 				6:  uint8(255),
   5921 				7:  uint8(255),
   5922 				8:  uint8(128),
   5923 				9:  uint8(128),
   5924 				10: uint8(128),
   5925 			},
   5926 			2: {
   5927 				0:  uint8(22),
   5928 				1:  uint8(100),
   5929 				2:  uint8(174),
   5930 				3:  uint8(245),
   5931 				4:  uint8(186),
   5932 				5:  uint8(161),
   5933 				6:  uint8(255),
   5934 				7:  uint8(199),
   5935 				8:  uint8(128),
   5936 				9:  uint8(128),
   5937 				10: uint8(128),
   5938 			},
   5939 		},
   5940 		5: {
   5941 			0: {
   5942 				0:  uint8(1),
   5943 				1:  uint8(182),
   5944 				2:  uint8(249),
   5945 				3:  uint8(255),
   5946 				4:  uint8(232),
   5947 				5:  uint8(235),
   5948 				6:  uint8(128),
   5949 				7:  uint8(128),
   5950 				8:  uint8(128),
   5951 				9:  uint8(128),
   5952 				10: uint8(128),
   5953 			},
   5954 			1: {
   5955 				0:  uint8(124),
   5956 				1:  uint8(143),
   5957 				2:  uint8(241),
   5958 				3:  uint8(255),
   5959 				4:  uint8(227),
   5960 				5:  uint8(234),
   5961 				6:  uint8(128),
   5962 				7:  uint8(128),
   5963 				8:  uint8(128),
   5964 				9:  uint8(128),
   5965 				10: uint8(128),
   5966 			},
   5967 			2: {
   5968 				0:  uint8(35),
   5969 				1:  uint8(77),
   5970 				2:  uint8(181),
   5971 				3:  uint8(251),
   5972 				4:  uint8(193),
   5973 				5:  uint8(211),
   5974 				6:  uint8(255),
   5975 				7:  uint8(205),
   5976 				8:  uint8(128),
   5977 				9:  uint8(128),
   5978 				10: uint8(128),
   5979 			},
   5980 		},
   5981 		6: {
   5982 			0: {
   5983 				0:  uint8(1),
   5984 				1:  uint8(157),
   5985 				2:  uint8(247),
   5986 				3:  uint8(255),
   5987 				4:  uint8(236),
   5988 				5:  uint8(231),
   5989 				6:  uint8(255),
   5990 				7:  uint8(255),
   5991 				8:  uint8(128),
   5992 				9:  uint8(128),
   5993 				10: uint8(128),
   5994 			},
   5995 			1: {
   5996 				0:  uint8(121),
   5997 				1:  uint8(141),
   5998 				2:  uint8(235),
   5999 				3:  uint8(255),
   6000 				4:  uint8(225),
   6001 				5:  uint8(227),
   6002 				6:  uint8(255),
   6003 				7:  uint8(255),
   6004 				8:  uint8(128),
   6005 				9:  uint8(128),
   6006 				10: uint8(128),
   6007 			},
   6008 			2: {
   6009 				0:  uint8(45),
   6010 				1:  uint8(99),
   6011 				2:  uint8(188),
   6012 				3:  uint8(251),
   6013 				4:  uint8(195),
   6014 				5:  uint8(217),
   6015 				6:  uint8(255),
   6016 				7:  uint8(224),
   6017 				8:  uint8(128),
   6018 				9:  uint8(128),
   6019 				10: uint8(128),
   6020 			},
   6021 		},
   6022 		7: {
   6023 			0: {
   6024 				0:  uint8(1),
   6025 				1:  uint8(1),
   6026 				2:  uint8(251),
   6027 				3:  uint8(255),
   6028 				4:  uint8(213),
   6029 				5:  uint8(255),
   6030 				6:  uint8(128),
   6031 				7:  uint8(128),
   6032 				8:  uint8(128),
   6033 				9:  uint8(128),
   6034 				10: uint8(128),
   6035 			},
   6036 			1: {
   6037 				0:  uint8(203),
   6038 				1:  uint8(1),
   6039 				2:  uint8(248),
   6040 				3:  uint8(255),
   6041 				4:  uint8(255),
   6042 				5:  uint8(128),
   6043 				6:  uint8(128),
   6044 				7:  uint8(128),
   6045 				8:  uint8(128),
   6046 				9:  uint8(128),
   6047 				10: uint8(128),
   6048 			},
   6049 			2: {
   6050 				0:  uint8(137),
   6051 				1:  uint8(1),
   6052 				2:  uint8(177),
   6053 				3:  uint8(255),
   6054 				4:  uint8(224),
   6055 				5:  uint8(255),
   6056 				6:  uint8(128),
   6057 				7:  uint8(128),
   6058 				8:  uint8(128),
   6059 				9:  uint8(128),
   6060 				10: uint8(128),
   6061 			},
   6062 		},
   6063 	},
   6064 	2: {
   6065 		0: {
   6066 			0: {
   6067 				0:  uint8(253),
   6068 				1:  uint8(9),
   6069 				2:  uint8(248),
   6070 				3:  uint8(251),
   6071 				4:  uint8(207),
   6072 				5:  uint8(208),
   6073 				6:  uint8(255),
   6074 				7:  uint8(192),
   6075 				8:  uint8(128),
   6076 				9:  uint8(128),
   6077 				10: uint8(128),
   6078 			},
   6079 			1: {
   6080 				0:  uint8(175),
   6081 				1:  uint8(13),
   6082 				2:  uint8(224),
   6083 				3:  uint8(243),
   6084 				4:  uint8(193),
   6085 				5:  uint8(185),
   6086 				6:  uint8(249),
   6087 				7:  uint8(198),
   6088 				8:  uint8(255),
   6089 				9:  uint8(255),
   6090 				10: uint8(128),
   6091 			},
   6092 			2: {
   6093 				0:  uint8(73),
   6094 				1:  uint8(17),
   6095 				2:  uint8(171),
   6096 				3:  uint8(221),
   6097 				4:  uint8(161),
   6098 				5:  uint8(179),
   6099 				6:  uint8(236),
   6100 				7:  uint8(167),
   6101 				8:  uint8(255),
   6102 				9:  uint8(234),
   6103 				10: uint8(128),
   6104 			},
   6105 		},
   6106 		1: {
   6107 			0: {
   6108 				0:  uint8(1),
   6109 				1:  uint8(95),
   6110 				2:  uint8(247),
   6111 				3:  uint8(253),
   6112 				4:  uint8(212),
   6113 				5:  uint8(183),
   6114 				6:  uint8(255),
   6115 				7:  uint8(255),
   6116 				8:  uint8(128),
   6117 				9:  uint8(128),
   6118 				10: uint8(128),
   6119 			},
   6120 			1: {
   6121 				0:  uint8(239),
   6122 				1:  uint8(90),
   6123 				2:  uint8(244),
   6124 				3:  uint8(250),
   6125 				4:  uint8(211),
   6126 				5:  uint8(209),
   6127 				6:  uint8(255),
   6128 				7:  uint8(255),
   6129 				8:  uint8(128),
   6130 				9:  uint8(128),
   6131 				10: uint8(128),
   6132 			},
   6133 			2: {
   6134 				0:  uint8(155),
   6135 				1:  uint8(77),
   6136 				2:  uint8(195),
   6137 				3:  uint8(248),
   6138 				4:  uint8(188),
   6139 				5:  uint8(195),
   6140 				6:  uint8(255),
   6141 				7:  uint8(255),
   6142 				8:  uint8(128),
   6143 				9:  uint8(128),
   6144 				10: uint8(128),
   6145 			},
   6146 		},
   6147 		2: {
   6148 			0: {
   6149 				0:  uint8(1),
   6150 				1:  uint8(24),
   6151 				2:  uint8(239),
   6152 				3:  uint8(251),
   6153 				4:  uint8(218),
   6154 				5:  uint8(219),
   6155 				6:  uint8(255),
   6156 				7:  uint8(205),
   6157 				8:  uint8(128),
   6158 				9:  uint8(128),
   6159 				10: uint8(128),
   6160 			},
   6161 			1: {
   6162 				0:  uint8(201),
   6163 				1:  uint8(51),
   6164 				2:  uint8(219),
   6165 				3:  uint8(255),
   6166 				4:  uint8(196),
   6167 				5:  uint8(186),
   6168 				6:  uint8(128),
   6169 				7:  uint8(128),
   6170 				8:  uint8(128),
   6171 				9:  uint8(128),
   6172 				10: uint8(128),
   6173 			},
   6174 			2: {
   6175 				0:  uint8(69),
   6176 				1:  uint8(46),
   6177 				2:  uint8(190),
   6178 				3:  uint8(239),
   6179 				4:  uint8(201),
   6180 				5:  uint8(218),
   6181 				6:  uint8(255),
   6182 				7:  uint8(228),
   6183 				8:  uint8(128),
   6184 				9:  uint8(128),
   6185 				10: uint8(128),
   6186 			},
   6187 		},
   6188 		3: {
   6189 			0: {
   6190 				0:  uint8(1),
   6191 				1:  uint8(191),
   6192 				2:  uint8(251),
   6193 				3:  uint8(255),
   6194 				4:  uint8(255),
   6195 				5:  uint8(128),
   6196 				6:  uint8(128),
   6197 				7:  uint8(128),
   6198 				8:  uint8(128),
   6199 				9:  uint8(128),
   6200 				10: uint8(128),
   6201 			},
   6202 			1: {
   6203 				0:  uint8(223),
   6204 				1:  uint8(165),
   6205 				2:  uint8(249),
   6206 				3:  uint8(255),
   6207 				4:  uint8(213),
   6208 				5:  uint8(255),
   6209 				6:  uint8(128),
   6210 				7:  uint8(128),
   6211 				8:  uint8(128),
   6212 				9:  uint8(128),
   6213 				10: uint8(128),
   6214 			},
   6215 			2: {
   6216 				0:  uint8(141),
   6217 				1:  uint8(124),
   6218 				2:  uint8(248),
   6219 				3:  uint8(255),
   6220 				4:  uint8(255),
   6221 				5:  uint8(128),
   6222 				6:  uint8(128),
   6223 				7:  uint8(128),
   6224 				8:  uint8(128),
   6225 				9:  uint8(128),
   6226 				10: uint8(128),
   6227 			},
   6228 		},
   6229 		4: {
   6230 			0: {
   6231 				0:  uint8(1),
   6232 				1:  uint8(16),
   6233 				2:  uint8(248),
   6234 				3:  uint8(255),
   6235 				4:  uint8(255),
   6236 				5:  uint8(128),
   6237 				6:  uint8(128),
   6238 				7:  uint8(128),
   6239 				8:  uint8(128),
   6240 				9:  uint8(128),
   6241 				10: uint8(128),
   6242 			},
   6243 			1: {
   6244 				0:  uint8(190),
   6245 				1:  uint8(36),
   6246 				2:  uint8(230),
   6247 				3:  uint8(255),
   6248 				4:  uint8(236),
   6249 				5:  uint8(255),
   6250 				6:  uint8(128),
   6251 				7:  uint8(128),
   6252 				8:  uint8(128),
   6253 				9:  uint8(128),
   6254 				10: uint8(128),
   6255 			},
   6256 			2: {
   6257 				0:  uint8(149),
   6258 				1:  uint8(1),
   6259 				2:  uint8(255),
   6260 				3:  uint8(128),
   6261 				4:  uint8(128),
   6262 				5:  uint8(128),
   6263 				6:  uint8(128),
   6264 				7:  uint8(128),
   6265 				8:  uint8(128),
   6266 				9:  uint8(128),
   6267 				10: uint8(128),
   6268 			},
   6269 		},
   6270 		5: {
   6271 			0: {
   6272 				0:  uint8(1),
   6273 				1:  uint8(226),
   6274 				2:  uint8(255),
   6275 				3:  uint8(128),
   6276 				4:  uint8(128),
   6277 				5:  uint8(128),
   6278 				6:  uint8(128),
   6279 				7:  uint8(128),
   6280 				8:  uint8(128),
   6281 				9:  uint8(128),
   6282 				10: uint8(128),
   6283 			},
   6284 			1: {
   6285 				0:  uint8(247),
   6286 				1:  uint8(192),
   6287 				2:  uint8(255),
   6288 				3:  uint8(128),
   6289 				4:  uint8(128),
   6290 				5:  uint8(128),
   6291 				6:  uint8(128),
   6292 				7:  uint8(128),
   6293 				8:  uint8(128),
   6294 				9:  uint8(128),
   6295 				10: uint8(128),
   6296 			},
   6297 			2: {
   6298 				0:  uint8(240),
   6299 				1:  uint8(128),
   6300 				2:  uint8(255),
   6301 				3:  uint8(128),
   6302 				4:  uint8(128),
   6303 				5:  uint8(128),
   6304 				6:  uint8(128),
   6305 				7:  uint8(128),
   6306 				8:  uint8(128),
   6307 				9:  uint8(128),
   6308 				10: uint8(128),
   6309 			},
   6310 		},
   6311 		6: {
   6312 			0: {
   6313 				0:  uint8(1),
   6314 				1:  uint8(134),
   6315 				2:  uint8(252),
   6316 				3:  uint8(255),
   6317 				4:  uint8(255),
   6318 				5:  uint8(128),
   6319 				6:  uint8(128),
   6320 				7:  uint8(128),
   6321 				8:  uint8(128),
   6322 				9:  uint8(128),
   6323 				10: uint8(128),
   6324 			},
   6325 			1: {
   6326 				0:  uint8(213),
   6327 				1:  uint8(62),
   6328 				2:  uint8(250),
   6329 				3:  uint8(255),
   6330 				4:  uint8(255),
   6331 				5:  uint8(128),
   6332 				6:  uint8(128),
   6333 				7:  uint8(128),
   6334 				8:  uint8(128),
   6335 				9:  uint8(128),
   6336 				10: uint8(128),
   6337 			},
   6338 			2: {
   6339 				0:  uint8(55),
   6340 				1:  uint8(93),
   6341 				2:  uint8(255),
   6342 				3:  uint8(128),
   6343 				4:  uint8(128),
   6344 				5:  uint8(128),
   6345 				6:  uint8(128),
   6346 				7:  uint8(128),
   6347 				8:  uint8(128),
   6348 				9:  uint8(128),
   6349 				10: uint8(128),
   6350 			},
   6351 		},
   6352 		7: {
   6353 			0: {
   6354 				0:  uint8(128),
   6355 				1:  uint8(128),
   6356 				2:  uint8(128),
   6357 				3:  uint8(128),
   6358 				4:  uint8(128),
   6359 				5:  uint8(128),
   6360 				6:  uint8(128),
   6361 				7:  uint8(128),
   6362 				8:  uint8(128),
   6363 				9:  uint8(128),
   6364 				10: uint8(128),
   6365 			},
   6366 			1: {
   6367 				0:  uint8(128),
   6368 				1:  uint8(128),
   6369 				2:  uint8(128),
   6370 				3:  uint8(128),
   6371 				4:  uint8(128),
   6372 				5:  uint8(128),
   6373 				6:  uint8(128),
   6374 				7:  uint8(128),
   6375 				8:  uint8(128),
   6376 				9:  uint8(128),
   6377 				10: uint8(128),
   6378 			},
   6379 			2: {
   6380 				0:  uint8(128),
   6381 				1:  uint8(128),
   6382 				2:  uint8(128),
   6383 				3:  uint8(128),
   6384 				4:  uint8(128),
   6385 				5:  uint8(128),
   6386 				6:  uint8(128),
   6387 				7:  uint8(128),
   6388 				8:  uint8(128),
   6389 				9:  uint8(128),
   6390 				10: uint8(128),
   6391 			},
   6392 		},
   6393 	},
   6394 	3: {
   6395 		0: {
   6396 			0: {
   6397 				0:  uint8(202),
   6398 				1:  uint8(24),
   6399 				2:  uint8(213),
   6400 				3:  uint8(235),
   6401 				4:  uint8(186),
   6402 				5:  uint8(191),
   6403 				6:  uint8(220),
   6404 				7:  uint8(160),
   6405 				8:  uint8(240),
   6406 				9:  uint8(175),
   6407 				10: uint8(255),
   6408 			},
   6409 			1: {
   6410 				0:  uint8(126),
   6411 				1:  uint8(38),
   6412 				2:  uint8(182),
   6413 				3:  uint8(232),
   6414 				4:  uint8(169),
   6415 				5:  uint8(184),
   6416 				6:  uint8(228),
   6417 				7:  uint8(174),
   6418 				8:  uint8(255),
   6419 				9:  uint8(187),
   6420 				10: uint8(128),
   6421 			},
   6422 			2: {
   6423 				0:  uint8(61),
   6424 				1:  uint8(46),
   6425 				2:  uint8(138),
   6426 				3:  uint8(219),
   6427 				4:  uint8(151),
   6428 				5:  uint8(178),
   6429 				6:  uint8(240),
   6430 				7:  uint8(170),
   6431 				8:  uint8(255),
   6432 				9:  uint8(216),
   6433 				10: uint8(128),
   6434 			},
   6435 		},
   6436 		1: {
   6437 			0: {
   6438 				0:  uint8(1),
   6439 				1:  uint8(112),
   6440 				2:  uint8(230),
   6441 				3:  uint8(250),
   6442 				4:  uint8(199),
   6443 				5:  uint8(191),
   6444 				6:  uint8(247),
   6445 				7:  uint8(159),
   6446 				8:  uint8(255),
   6447 				9:  uint8(255),
   6448 				10: uint8(128),
   6449 			},
   6450 			1: {
   6451 				0:  uint8(166),
   6452 				1:  uint8(109),
   6453 				2:  uint8(228),
   6454 				3:  uint8(252),
   6455 				4:  uint8(211),
   6456 				5:  uint8(215),
   6457 				6:  uint8(255),
   6458 				7:  uint8(174),
   6459 				8:  uint8(128),
   6460 				9:  uint8(128),
   6461 				10: uint8(128),
   6462 			},
   6463 			2: {
   6464 				0:  uint8(39),
   6465 				1:  uint8(77),
   6466 				2:  uint8(162),
   6467 				3:  uint8(232),
   6468 				4:  uint8(172),
   6469 				5:  uint8(180),
   6470 				6:  uint8(245),
   6471 				7:  uint8(178),
   6472 				8:  uint8(255),
   6473 				9:  uint8(255),
   6474 				10: uint8(128),
   6475 			},
   6476 		},
   6477 		2: {
   6478 			0: {
   6479 				0:  uint8(1),
   6480 				1:  uint8(52),
   6481 				2:  uint8(220),
   6482 				3:  uint8(246),
   6483 				4:  uint8(198),
   6484 				5:  uint8(199),
   6485 				6:  uint8(249),
   6486 				7:  uint8(220),
   6487 				8:  uint8(255),
   6488 				9:  uint8(255),
   6489 				10: uint8(128),
   6490 			},
   6491 			1: {
   6492 				0:  uint8(124),
   6493 				1:  uint8(74),
   6494 				2:  uint8(191),
   6495 				3:  uint8(243),
   6496 				4:  uint8(183),
   6497 				5:  uint8(193),
   6498 				6:  uint8(250),
   6499 				7:  uint8(221),
   6500 				8:  uint8(255),
   6501 				9:  uint8(255),
   6502 				10: uint8(128),
   6503 			},
   6504 			2: {
   6505 				0:  uint8(24),
   6506 				1:  uint8(71),
   6507 				2:  uint8(130),
   6508 				3:  uint8(219),
   6509 				4:  uint8(154),
   6510 				5:  uint8(170),
   6511 				6:  uint8(243),
   6512 				7:  uint8(182),
   6513 				8:  uint8(255),
   6514 				9:  uint8(255),
   6515 				10: uint8(128),
   6516 			},
   6517 		},
   6518 		3: {
   6519 			0: {
   6520 				0:  uint8(1),
   6521 				1:  uint8(182),
   6522 				2:  uint8(225),
   6523 				3:  uint8(249),
   6524 				4:  uint8(219),
   6525 				5:  uint8(240),
   6526 				6:  uint8(255),
   6527 				7:  uint8(224),
   6528 				8:  uint8(128),
   6529 				9:  uint8(128),
   6530 				10: uint8(128),
   6531 			},
   6532 			1: {
   6533 				0:  uint8(149),
   6534 				1:  uint8(150),
   6535 				2:  uint8(226),
   6536 				3:  uint8(252),
   6537 				4:  uint8(216),
   6538 				5:  uint8(205),
   6539 				6:  uint8(255),
   6540 				7:  uint8(171),
   6541 				8:  uint8(128),
   6542 				9:  uint8(128),
   6543 				10: uint8(128),
   6544 			},
   6545 			2: {
   6546 				0:  uint8(28),
   6547 				1:  uint8(108),
   6548 				2:  uint8(170),
   6549 				3:  uint8(242),
   6550 				4:  uint8(183),
   6551 				5:  uint8(194),
   6552 				6:  uint8(254),
   6553 				7:  uint8(223),
   6554 				8:  uint8(255),
   6555 				9:  uint8(255),
   6556 				10: uint8(128),
   6557 			},
   6558 		},
   6559 		4: {
   6560 			0: {
   6561 				0:  uint8(1),
   6562 				1:  uint8(81),
   6563 				2:  uint8(230),
   6564 				3:  uint8(252),
   6565 				4:  uint8(204),
   6566 				5:  uint8(203),
   6567 				6:  uint8(255),
   6568 				7:  uint8(192),
   6569 				8:  uint8(128),
   6570 				9:  uint8(128),
   6571 				10: uint8(128),
   6572 			},
   6573 			1: {
   6574 				0:  uint8(123),
   6575 				1:  uint8(102),
   6576 				2:  uint8(209),
   6577 				3:  uint8(247),
   6578 				4:  uint8(188),
   6579 				5:  uint8(196),
   6580 				6:  uint8(255),
   6581 				7:  uint8(233),
   6582 				8:  uint8(128),
   6583 				9:  uint8(128),
   6584 				10: uint8(128),
   6585 			},
   6586 			2: {
   6587 				0:  uint8(20),
   6588 				1:  uint8(95),
   6589 				2:  uint8(153),
   6590 				3:  uint8(243),
   6591 				4:  uint8(164),
   6592 				5:  uint8(173),
   6593 				6:  uint8(255),
   6594 				7:  uint8(203),
   6595 				8:  uint8(128),
   6596 				9:  uint8(128),
   6597 				10: uint8(128),
   6598 			},
   6599 		},
   6600 		5: {
   6601 			0: {
   6602 				0:  uint8(1),
   6603 				1:  uint8(222),
   6604 				2:  uint8(248),
   6605 				3:  uint8(255),
   6606 				4:  uint8(216),
   6607 				5:  uint8(213),
   6608 				6:  uint8(128),
   6609 				7:  uint8(128),
   6610 				8:  uint8(128),
   6611 				9:  uint8(128),
   6612 				10: uint8(128),
   6613 			},
   6614 			1: {
   6615 				0:  uint8(168),
   6616 				1:  uint8(175),
   6617 				2:  uint8(246),
   6618 				3:  uint8(252),
   6619 				4:  uint8(235),
   6620 				5:  uint8(205),
   6621 				6:  uint8(255),
   6622 				7:  uint8(255),
   6623 				8:  uint8(128),
   6624 				9:  uint8(128),
   6625 				10: uint8(128),
   6626 			},
   6627 			2: {
   6628 				0:  uint8(47),
   6629 				1:  uint8(116),
   6630 				2:  uint8(215),
   6631 				3:  uint8(255),
   6632 				4:  uint8(211),
   6633 				5:  uint8(212),
   6634 				6:  uint8(255),
   6635 				7:  uint8(255),
   6636 				8:  uint8(128),
   6637 				9:  uint8(128),
   6638 				10: uint8(128),
   6639 			},
   6640 		},
   6641 		6: {
   6642 			0: {
   6643 				0:  uint8(1),
   6644 				1:  uint8(121),
   6645 				2:  uint8(236),
   6646 				3:  uint8(253),
   6647 				4:  uint8(212),
   6648 				5:  uint8(214),
   6649 				6:  uint8(255),
   6650 				7:  uint8(255),
   6651 				8:  uint8(128),
   6652 				9:  uint8(128),
   6653 				10: uint8(128),
   6654 			},
   6655 			1: {
   6656 				0:  uint8(141),
   6657 				1:  uint8(84),
   6658 				2:  uint8(213),
   6659 				3:  uint8(252),
   6660 				4:  uint8(201),
   6661 				5:  uint8(202),
   6662 				6:  uint8(255),
   6663 				7:  uint8(219),
   6664 				8:  uint8(128),
   6665 				9:  uint8(128),
   6666 				10: uint8(128),
   6667 			},
   6668 			2: {
   6669 				0:  uint8(42),
   6670 				1:  uint8(80),
   6671 				2:  uint8(160),
   6672 				3:  uint8(240),
   6673 				4:  uint8(162),
   6674 				5:  uint8(185),
   6675 				6:  uint8(255),
   6676 				7:  uint8(205),
   6677 				8:  uint8(128),
   6678 				9:  uint8(128),
   6679 				10: uint8(128),
   6680 			},
   6681 		},
   6682 		7: {
   6683 			0: {
   6684 				0:  uint8(1),
   6685 				1:  uint8(1),
   6686 				2:  uint8(255),
   6687 				3:  uint8(128),
   6688 				4:  uint8(128),
   6689 				5:  uint8(128),
   6690 				6:  uint8(128),
   6691 				7:  uint8(128),
   6692 				8:  uint8(128),
   6693 				9:  uint8(128),
   6694 				10: uint8(128),
   6695 			},
   6696 			1: {
   6697 				0:  uint8(244),
   6698 				1:  uint8(1),
   6699 				2:  uint8(255),
   6700 				3:  uint8(128),
   6701 				4:  uint8(128),
   6702 				5:  uint8(128),
   6703 				6:  uint8(128),
   6704 				7:  uint8(128),
   6705 				8:  uint8(128),
   6706 				9:  uint8(128),
   6707 				10: uint8(128),
   6708 			},
   6709 			2: {
   6710 				0:  uint8(238),
   6711 				1:  uint8(1),
   6712 				2:  uint8(255),
   6713 				3:  uint8(128),
   6714 				4:  uint8(128),
   6715 				5:  uint8(128),
   6716 				6:  uint8(128),
   6717 				7:  uint8(128),
   6718 				8:  uint8(128),
   6719 				9:  uint8(128),
   6720 				10: uint8(128),
   6721 			},
   6722 		},
   6723 	},
   6724 }
   6725 
   6726 // C documentation
   6727 //
   6728 //	// Paragraph 11.5
   6729 var kBModesProba = [10][10][9]uint8_t{
   6730 	0: {
   6731 		0: {
   6732 			0: uint8(231),
   6733 			1: uint8(120),
   6734 			2: uint8(48),
   6735 			3: uint8(89),
   6736 			4: uint8(115),
   6737 			5: uint8(113),
   6738 			6: uint8(120),
   6739 			7: uint8(152),
   6740 			8: uint8(112),
   6741 		},
   6742 		1: {
   6743 			0: uint8(152),
   6744 			1: uint8(179),
   6745 			2: uint8(64),
   6746 			3: uint8(126),
   6747 			4: uint8(170),
   6748 			5: uint8(118),
   6749 			6: uint8(46),
   6750 			7: uint8(70),
   6751 			8: uint8(95),
   6752 		},
   6753 		2: {
   6754 			0: uint8(175),
   6755 			1: uint8(69),
   6756 			2: uint8(143),
   6757 			3: uint8(80),
   6758 			4: uint8(85),
   6759 			5: uint8(82),
   6760 			6: uint8(72),
   6761 			7: uint8(155),
   6762 			8: uint8(103),
   6763 		},
   6764 		3: {
   6765 			0: uint8(56),
   6766 			1: uint8(58),
   6767 			2: uint8(10),
   6768 			3: uint8(171),
   6769 			4: uint8(218),
   6770 			5: uint8(189),
   6771 			6: uint8(17),
   6772 			7: uint8(13),
   6773 			8: uint8(152),
   6774 		},
   6775 		4: {
   6776 			0: uint8(114),
   6777 			1: uint8(26),
   6778 			2: uint8(17),
   6779 			3: uint8(163),
   6780 			4: uint8(44),
   6781 			5: uint8(195),
   6782 			6: uint8(21),
   6783 			7: uint8(10),
   6784 			8: uint8(173),
   6785 		},
   6786 		5: {
   6787 			0: uint8(121),
   6788 			1: uint8(24),
   6789 			2: uint8(80),
   6790 			3: uint8(195),
   6791 			4: uint8(26),
   6792 			5: uint8(62),
   6793 			6: uint8(44),
   6794 			7: uint8(64),
   6795 			8: uint8(85),
   6796 		},
   6797 		6: {
   6798 			0: uint8(144),
   6799 			1: uint8(71),
   6800 			2: uint8(10),
   6801 			3: uint8(38),
   6802 			4: uint8(171),
   6803 			5: uint8(213),
   6804 			6: uint8(144),
   6805 			7: uint8(34),
   6806 			8: uint8(26),
   6807 		},
   6808 		7: {
   6809 			0: uint8(170),
   6810 			1: uint8(46),
   6811 			2: uint8(55),
   6812 			3: uint8(19),
   6813 			4: uint8(136),
   6814 			5: uint8(160),
   6815 			6: uint8(33),
   6816 			7: uint8(206),
   6817 			8: uint8(71),
   6818 		},
   6819 		8: {
   6820 			0: uint8(63),
   6821 			1: uint8(20),
   6822 			2: uint8(8),
   6823 			3: uint8(114),
   6824 			4: uint8(114),
   6825 			5: uint8(208),
   6826 			6: uint8(12),
   6827 			7: uint8(9),
   6828 			8: uint8(226),
   6829 		},
   6830 		9: {
   6831 			0: uint8(81),
   6832 			1: uint8(40),
   6833 			2: uint8(11),
   6834 			3: uint8(96),
   6835 			4: uint8(182),
   6836 			5: uint8(84),
   6837 			6: uint8(29),
   6838 			7: uint8(16),
   6839 			8: uint8(36),
   6840 		},
   6841 	},
   6842 	1: {
   6843 		0: {
   6844 			0: uint8(134),
   6845 			1: uint8(183),
   6846 			2: uint8(89),
   6847 			3: uint8(137),
   6848 			4: uint8(98),
   6849 			5: uint8(101),
   6850 			6: uint8(106),
   6851 			7: uint8(165),
   6852 			8: uint8(148),
   6853 		},
   6854 		1: {
   6855 			0: uint8(72),
   6856 			1: uint8(187),
   6857 			2: uint8(100),
   6858 			3: uint8(130),
   6859 			4: uint8(157),
   6860 			5: uint8(111),
   6861 			6: uint8(32),
   6862 			7: uint8(75),
   6863 			8: uint8(80),
   6864 		},
   6865 		2: {
   6866 			0: uint8(66),
   6867 			1: uint8(102),
   6868 			2: uint8(167),
   6869 			3: uint8(99),
   6870 			4: uint8(74),
   6871 			5: uint8(62),
   6872 			6: uint8(40),
   6873 			7: uint8(234),
   6874 			8: uint8(128),
   6875 		},
   6876 		3: {
   6877 			0: uint8(41),
   6878 			1: uint8(53),
   6879 			2: uint8(9),
   6880 			3: uint8(178),
   6881 			4: uint8(241),
   6882 			5: uint8(141),
   6883 			6: uint8(26),
   6884 			7: uint8(8),
   6885 			8: uint8(107),
   6886 		},
   6887 		4: {
   6888 			0: uint8(74),
   6889 			1: uint8(43),
   6890 			2: uint8(26),
   6891 			3: uint8(146),
   6892 			4: uint8(73),
   6893 			5: uint8(166),
   6894 			6: uint8(49),
   6895 			7: uint8(23),
   6896 			8: uint8(157),
   6897 		},
   6898 		5: {
   6899 			0: uint8(65),
   6900 			1: uint8(38),
   6901 			2: uint8(105),
   6902 			3: uint8(160),
   6903 			4: uint8(51),
   6904 			5: uint8(52),
   6905 			6: uint8(31),
   6906 			7: uint8(115),
   6907 			8: uint8(128),
   6908 		},
   6909 		6: {
   6910 			0: uint8(104),
   6911 			1: uint8(79),
   6912 			2: uint8(12),
   6913 			3: uint8(27),
   6914 			4: uint8(217),
   6915 			5: uint8(255),
   6916 			6: uint8(87),
   6917 			7: uint8(17),
   6918 			8: uint8(7),
   6919 		},
   6920 		7: {
   6921 			0: uint8(87),
   6922 			1: uint8(68),
   6923 			2: uint8(71),
   6924 			3: uint8(44),
   6925 			4: uint8(114),
   6926 			5: uint8(51),
   6927 			6: uint8(15),
   6928 			7: uint8(186),
   6929 			8: uint8(23),
   6930 		},
   6931 		8: {
   6932 			0: uint8(47),
   6933 			1: uint8(41),
   6934 			2: uint8(14),
   6935 			3: uint8(110),
   6936 			4: uint8(182),
   6937 			5: uint8(183),
   6938 			6: uint8(21),
   6939 			7: uint8(17),
   6940 			8: uint8(194),
   6941 		},
   6942 		9: {
   6943 			0: uint8(66),
   6944 			1: uint8(45),
   6945 			2: uint8(25),
   6946 			3: uint8(102),
   6947 			4: uint8(197),
   6948 			5: uint8(189),
   6949 			6: uint8(23),
   6950 			7: uint8(18),
   6951 			8: uint8(22),
   6952 		},
   6953 	},
   6954 	2: {
   6955 		0: {
   6956 			0: uint8(88),
   6957 			1: uint8(88),
   6958 			2: uint8(147),
   6959 			3: uint8(150),
   6960 			4: uint8(42),
   6961 			5: uint8(46),
   6962 			6: uint8(45),
   6963 			7: uint8(196),
   6964 			8: uint8(205),
   6965 		},
   6966 		1: {
   6967 			0: uint8(43),
   6968 			1: uint8(97),
   6969 			2: uint8(183),
   6970 			3: uint8(117),
   6971 			4: uint8(85),
   6972 			5: uint8(38),
   6973 			6: uint8(35),
   6974 			7: uint8(179),
   6975 			8: uint8(61),
   6976 		},
   6977 		2: {
   6978 			0: uint8(39),
   6979 			1: uint8(53),
   6980 			2: uint8(200),
   6981 			3: uint8(87),
   6982 			4: uint8(26),
   6983 			5: uint8(21),
   6984 			6: uint8(43),
   6985 			7: uint8(232),
   6986 			8: uint8(171),
   6987 		},
   6988 		3: {
   6989 			0: uint8(56),
   6990 			1: uint8(34),
   6991 			2: uint8(51),
   6992 			3: uint8(104),
   6993 			4: uint8(114),
   6994 			5: uint8(102),
   6995 			6: uint8(29),
   6996 			7: uint8(93),
   6997 			8: uint8(77),
   6998 		},
   6999 		4: {
   7000 			0: uint8(39),
   7001 			1: uint8(28),
   7002 			2: uint8(85),
   7003 			3: uint8(171),
   7004 			4: uint8(58),
   7005 			5: uint8(165),
   7006 			6: uint8(90),
   7007 			7: uint8(98),
   7008 			8: uint8(64),
   7009 		},
   7010 		5: {
   7011 			0: uint8(34),
   7012 			1: uint8(22),
   7013 			2: uint8(116),
   7014 			3: uint8(206),
   7015 			4: uint8(23),
   7016 			5: uint8(34),
   7017 			6: uint8(43),
   7018 			7: uint8(166),
   7019 			8: uint8(73),
   7020 		},
   7021 		6: {
   7022 			0: uint8(107),
   7023 			1: uint8(54),
   7024 			2: uint8(32),
   7025 			3: uint8(26),
   7026 			4: uint8(51),
   7027 			5: uint8(1),
   7028 			6: uint8(81),
   7029 			7: uint8(43),
   7030 			8: uint8(31),
   7031 		},
   7032 		7: {
   7033 			0: uint8(68),
   7034 			1: uint8(25),
   7035 			2: uint8(106),
   7036 			3: uint8(22),
   7037 			4: uint8(64),
   7038 			5: uint8(171),
   7039 			6: uint8(36),
   7040 			7: uint8(225),
   7041 			8: uint8(114),
   7042 		},
   7043 		8: {
   7044 			0: uint8(34),
   7045 			1: uint8(19),
   7046 			2: uint8(21),
   7047 			3: uint8(102),
   7048 			4: uint8(132),
   7049 			5: uint8(188),
   7050 			6: uint8(16),
   7051 			7: uint8(76),
   7052 			8: uint8(124),
   7053 		},
   7054 		9: {
   7055 			0: uint8(62),
   7056 			1: uint8(18),
   7057 			2: uint8(78),
   7058 			3: uint8(95),
   7059 			4: uint8(85),
   7060 			5: uint8(57),
   7061 			6: uint8(50),
   7062 			7: uint8(48),
   7063 			8: uint8(51),
   7064 		},
   7065 	},
   7066 	3: {
   7067 		0: {
   7068 			0: uint8(193),
   7069 			1: uint8(101),
   7070 			2: uint8(35),
   7071 			3: uint8(159),
   7072 			4: uint8(215),
   7073 			5: uint8(111),
   7074 			6: uint8(89),
   7075 			7: uint8(46),
   7076 			8: uint8(111),
   7077 		},
   7078 		1: {
   7079 			0: uint8(60),
   7080 			1: uint8(148),
   7081 			2: uint8(31),
   7082 			3: uint8(172),
   7083 			4: uint8(219),
   7084 			5: uint8(228),
   7085 			6: uint8(21),
   7086 			7: uint8(18),
   7087 			8: uint8(111),
   7088 		},
   7089 		2: {
   7090 			0: uint8(112),
   7091 			1: uint8(113),
   7092 			2: uint8(77),
   7093 			3: uint8(85),
   7094 			4: uint8(179),
   7095 			5: uint8(255),
   7096 			6: uint8(38),
   7097 			7: uint8(120),
   7098 			8: uint8(114),
   7099 		},
   7100 		3: {
   7101 			0: uint8(40),
   7102 			1: uint8(42),
   7103 			2: uint8(1),
   7104 			3: uint8(196),
   7105 			4: uint8(245),
   7106 			5: uint8(209),
   7107 			6: uint8(10),
   7108 			7: uint8(25),
   7109 			8: uint8(109),
   7110 		},
   7111 		4: {
   7112 			0: uint8(88),
   7113 			1: uint8(43),
   7114 			2: uint8(29),
   7115 			3: uint8(140),
   7116 			4: uint8(166),
   7117 			5: uint8(213),
   7118 			6: uint8(37),
   7119 			7: uint8(43),
   7120 			8: uint8(154),
   7121 		},
   7122 		5: {
   7123 			0: uint8(61),
   7124 			1: uint8(63),
   7125 			2: uint8(30),
   7126 			3: uint8(155),
   7127 			4: uint8(67),
   7128 			5: uint8(45),
   7129 			6: uint8(68),
   7130 			7: uint8(1),
   7131 			8: uint8(209),
   7132 		},
   7133 		6: {
   7134 			0: uint8(100),
   7135 			1: uint8(80),
   7136 			2: uint8(8),
   7137 			3: uint8(43),
   7138 			4: uint8(154),
   7139 			5: uint8(1),
   7140 			6: uint8(51),
   7141 			7: uint8(26),
   7142 			8: uint8(71),
   7143 		},
   7144 		7: {
   7145 			0: uint8(142),
   7146 			1: uint8(78),
   7147 			2: uint8(78),
   7148 			3: uint8(16),
   7149 			4: uint8(255),
   7150 			5: uint8(128),
   7151 			6: uint8(34),
   7152 			7: uint8(197),
   7153 			8: uint8(171),
   7154 		},
   7155 		8: {
   7156 			0: uint8(41),
   7157 			1: uint8(40),
   7158 			2: uint8(5),
   7159 			3: uint8(102),
   7160 			4: uint8(211),
   7161 			5: uint8(183),
   7162 			6: uint8(4),
   7163 			7: uint8(1),
   7164 			8: uint8(221),
   7165 		},
   7166 		9: {
   7167 			0: uint8(51),
   7168 			1: uint8(50),
   7169 			2: uint8(17),
   7170 			3: uint8(168),
   7171 			4: uint8(209),
   7172 			5: uint8(192),
   7173 			6: uint8(23),
   7174 			7: uint8(25),
   7175 			8: uint8(82),
   7176 		},
   7177 	},
   7178 	4: {
   7179 		0: {
   7180 			0: uint8(138),
   7181 			1: uint8(31),
   7182 			2: uint8(36),
   7183 			3: uint8(171),
   7184 			4: uint8(27),
   7185 			5: uint8(166),
   7186 			6: uint8(38),
   7187 			7: uint8(44),
   7188 			8: uint8(229),
   7189 		},
   7190 		1: {
   7191 			0: uint8(67),
   7192 			1: uint8(87),
   7193 			2: uint8(58),
   7194 			3: uint8(169),
   7195 			4: uint8(82),
   7196 			5: uint8(115),
   7197 			6: uint8(26),
   7198 			7: uint8(59),
   7199 			8: uint8(179),
   7200 		},
   7201 		2: {
   7202 			0: uint8(63),
   7203 			1: uint8(59),
   7204 			2: uint8(90),
   7205 			3: uint8(180),
   7206 			4: uint8(59),
   7207 			5: uint8(166),
   7208 			6: uint8(93),
   7209 			7: uint8(73),
   7210 			8: uint8(154),
   7211 		},
   7212 		3: {
   7213 			0: uint8(40),
   7214 			1: uint8(40),
   7215 			2: uint8(21),
   7216 			3: uint8(116),
   7217 			4: uint8(143),
   7218 			5: uint8(209),
   7219 			6: uint8(34),
   7220 			7: uint8(39),
   7221 			8: uint8(175),
   7222 		},
   7223 		4: {
   7224 			0: uint8(47),
   7225 			1: uint8(15),
   7226 			2: uint8(16),
   7227 			3: uint8(183),
   7228 			4: uint8(34),
   7229 			5: uint8(223),
   7230 			6: uint8(49),
   7231 			7: uint8(45),
   7232 			8: uint8(183),
   7233 		},
   7234 		5: {
   7235 			0: uint8(46),
   7236 			1: uint8(17),
   7237 			2: uint8(33),
   7238 			3: uint8(183),
   7239 			4: uint8(6),
   7240 			5: uint8(98),
   7241 			6: uint8(15),
   7242 			7: uint8(32),
   7243 			8: uint8(183),
   7244 		},
   7245 		6: {
   7246 			0: uint8(57),
   7247 			1: uint8(46),
   7248 			2: uint8(22),
   7249 			3: uint8(24),
   7250 			4: uint8(128),
   7251 			5: uint8(1),
   7252 			6: uint8(54),
   7253 			7: uint8(17),
   7254 			8: uint8(37),
   7255 		},
   7256 		7: {
   7257 			0: uint8(65),
   7258 			1: uint8(32),
   7259 			2: uint8(73),
   7260 			3: uint8(115),
   7261 			4: uint8(28),
   7262 			5: uint8(128),
   7263 			6: uint8(23),
   7264 			7: uint8(128),
   7265 			8: uint8(205),
   7266 		},
   7267 		8: {
   7268 			0: uint8(40),
   7269 			1: uint8(3),
   7270 			2: uint8(9),
   7271 			3: uint8(115),
   7272 			4: uint8(51),
   7273 			5: uint8(192),
   7274 			6: uint8(18),
   7275 			7: uint8(6),
   7276 			8: uint8(223),
   7277 		},
   7278 		9: {
   7279 			0: uint8(87),
   7280 			1: uint8(37),
   7281 			2: uint8(9),
   7282 			3: uint8(115),
   7283 			4: uint8(59),
   7284 			5: uint8(77),
   7285 			6: uint8(64),
   7286 			7: uint8(21),
   7287 			8: uint8(47),
   7288 		},
   7289 	},
   7290 	5: {
   7291 		0: {
   7292 			0: uint8(104),
   7293 			1: uint8(55),
   7294 			2: uint8(44),
   7295 			3: uint8(218),
   7296 			4: uint8(9),
   7297 			5: uint8(54),
   7298 			6: uint8(53),
   7299 			7: uint8(130),
   7300 			8: uint8(226),
   7301 		},
   7302 		1: {
   7303 			0: uint8(64),
   7304 			1: uint8(90),
   7305 			2: uint8(70),
   7306 			3: uint8(205),
   7307 			4: uint8(40),
   7308 			5: uint8(41),
   7309 			6: uint8(23),
   7310 			7: uint8(26),
   7311 			8: uint8(57),
   7312 		},
   7313 		2: {
   7314 			0: uint8(54),
   7315 			1: uint8(57),
   7316 			2: uint8(112),
   7317 			3: uint8(184),
   7318 			4: uint8(5),
   7319 			5: uint8(41),
   7320 			6: uint8(38),
   7321 			7: uint8(166),
   7322 			8: uint8(213),
   7323 		},
   7324 		3: {
   7325 			0: uint8(30),
   7326 			1: uint8(34),
   7327 			2: uint8(26),
   7328 			3: uint8(133),
   7329 			4: uint8(152),
   7330 			5: uint8(116),
   7331 			6: uint8(10),
   7332 			7: uint8(32),
   7333 			8: uint8(134),
   7334 		},
   7335 		4: {
   7336 			0: uint8(39),
   7337 			1: uint8(19),
   7338 			2: uint8(53),
   7339 			3: uint8(221),
   7340 			4: uint8(26),
   7341 			5: uint8(114),
   7342 			6: uint8(32),
   7343 			7: uint8(73),
   7344 			8: uint8(255),
   7345 		},
   7346 		5: {
   7347 			0: uint8(31),
   7348 			1: uint8(9),
   7349 			2: uint8(65),
   7350 			3: uint8(234),
   7351 			4: uint8(2),
   7352 			5: uint8(15),
   7353 			6: uint8(1),
   7354 			7: uint8(118),
   7355 			8: uint8(73),
   7356 		},
   7357 		6: {
   7358 			0: uint8(75),
   7359 			1: uint8(32),
   7360 			2: uint8(12),
   7361 			3: uint8(51),
   7362 			4: uint8(192),
   7363 			5: uint8(255),
   7364 			6: uint8(160),
   7365 			7: uint8(43),
   7366 			8: uint8(51),
   7367 		},
   7368 		7: {
   7369 			0: uint8(88),
   7370 			1: uint8(31),
   7371 			2: uint8(35),
   7372 			3: uint8(67),
   7373 			4: uint8(102),
   7374 			5: uint8(85),
   7375 			6: uint8(55),
   7376 			7: uint8(186),
   7377 			8: uint8(85),
   7378 		},
   7379 		8: {
   7380 			0: uint8(56),
   7381 			1: uint8(21),
   7382 			2: uint8(23),
   7383 			3: uint8(111),
   7384 			4: uint8(59),
   7385 			5: uint8(205),
   7386 			6: uint8(45),
   7387 			7: uint8(37),
   7388 			8: uint8(192),
   7389 		},
   7390 		9: {
   7391 			0: uint8(55),
   7392 			1: uint8(38),
   7393 			2: uint8(70),
   7394 			3: uint8(124),
   7395 			4: uint8(73),
   7396 			5: uint8(102),
   7397 			6: uint8(1),
   7398 			7: uint8(34),
   7399 			8: uint8(98),
   7400 		},
   7401 	},
   7402 	6: {
   7403 		0: {
   7404 			0: uint8(125),
   7405 			1: uint8(98),
   7406 			2: uint8(42),
   7407 			3: uint8(88),
   7408 			4: uint8(104),
   7409 			5: uint8(85),
   7410 			6: uint8(117),
   7411 			7: uint8(175),
   7412 			8: uint8(82),
   7413 		},
   7414 		1: {
   7415 			0: uint8(95),
   7416 			1: uint8(84),
   7417 			2: uint8(53),
   7418 			3: uint8(89),
   7419 			4: uint8(128),
   7420 			5: uint8(100),
   7421 			6: uint8(113),
   7422 			7: uint8(101),
   7423 			8: uint8(45),
   7424 		},
   7425 		2: {
   7426 			0: uint8(75),
   7427 			1: uint8(79),
   7428 			2: uint8(123),
   7429 			3: uint8(47),
   7430 			4: uint8(51),
   7431 			5: uint8(128),
   7432 			6: uint8(81),
   7433 			7: uint8(171),
   7434 			8: uint8(1),
   7435 		},
   7436 		3: {
   7437 			0: uint8(57),
   7438 			1: uint8(17),
   7439 			2: uint8(5),
   7440 			3: uint8(71),
   7441 			4: uint8(102),
   7442 			5: uint8(57),
   7443 			6: uint8(53),
   7444 			7: uint8(41),
   7445 			8: uint8(49),
   7446 		},
   7447 		4: {
   7448 			0: uint8(38),
   7449 			1: uint8(33),
   7450 			2: uint8(13),
   7451 			3: uint8(121),
   7452 			4: uint8(57),
   7453 			5: uint8(73),
   7454 			6: uint8(26),
   7455 			7: uint8(1),
   7456 			8: uint8(85),
   7457 		},
   7458 		5: {
   7459 			0: uint8(41),
   7460 			1: uint8(10),
   7461 			2: uint8(67),
   7462 			3: uint8(138),
   7463 			4: uint8(77),
   7464 			5: uint8(110),
   7465 			6: uint8(90),
   7466 			7: uint8(47),
   7467 			8: uint8(114),
   7468 		},
   7469 		6: {
   7470 			0: uint8(115),
   7471 			1: uint8(21),
   7472 			2: uint8(2),
   7473 			3: uint8(10),
   7474 			4: uint8(102),
   7475 			5: uint8(255),
   7476 			6: uint8(166),
   7477 			7: uint8(23),
   7478 			8: uint8(6),
   7479 		},
   7480 		7: {
   7481 			0: uint8(101),
   7482 			1: uint8(29),
   7483 			2: uint8(16),
   7484 			3: uint8(10),
   7485 			4: uint8(85),
   7486 			5: uint8(128),
   7487 			6: uint8(101),
   7488 			7: uint8(196),
   7489 			8: uint8(26),
   7490 		},
   7491 		8: {
   7492 			0: uint8(57),
   7493 			1: uint8(18),
   7494 			2: uint8(10),
   7495 			3: uint8(102),
   7496 			4: uint8(102),
   7497 			5: uint8(213),
   7498 			6: uint8(34),
   7499 			7: uint8(20),
   7500 			8: uint8(43),
   7501 		},
   7502 		9: {
   7503 			0: uint8(117),
   7504 			1: uint8(20),
   7505 			2: uint8(15),
   7506 			3: uint8(36),
   7507 			4: uint8(163),
   7508 			5: uint8(128),
   7509 			6: uint8(68),
   7510 			7: uint8(1),
   7511 			8: uint8(26),
   7512 		},
   7513 	},
   7514 	7: {
   7515 		0: {
   7516 			0: uint8(102),
   7517 			1: uint8(61),
   7518 			2: uint8(71),
   7519 			3: uint8(37),
   7520 			4: uint8(34),
   7521 			5: uint8(53),
   7522 			6: uint8(31),
   7523 			7: uint8(243),
   7524 			8: uint8(192),
   7525 		},
   7526 		1: {
   7527 			0: uint8(69),
   7528 			1: uint8(60),
   7529 			2: uint8(71),
   7530 			3: uint8(38),
   7531 			4: uint8(73),
   7532 			5: uint8(119),
   7533 			6: uint8(28),
   7534 			7: uint8(222),
   7535 			8: uint8(37),
   7536 		},
   7537 		2: {
   7538 			0: uint8(68),
   7539 			1: uint8(45),
   7540 			2: uint8(128),
   7541 			3: uint8(34),
   7542 			4: uint8(1),
   7543 			5: uint8(47),
   7544 			6: uint8(11),
   7545 			7: uint8(245),
   7546 			8: uint8(171),
   7547 		},
   7548 		3: {
   7549 			0: uint8(62),
   7550 			1: uint8(17),
   7551 			2: uint8(19),
   7552 			3: uint8(70),
   7553 			4: uint8(146),
   7554 			5: uint8(85),
   7555 			6: uint8(55),
   7556 			7: uint8(62),
   7557 			8: uint8(70),
   7558 		},
   7559 		4: {
   7560 			0: uint8(37),
   7561 			1: uint8(43),
   7562 			2: uint8(37),
   7563 			3: uint8(154),
   7564 			4: uint8(100),
   7565 			5: uint8(163),
   7566 			6: uint8(85),
   7567 			7: uint8(160),
   7568 			8: uint8(1),
   7569 		},
   7570 		5: {
   7571 			0: uint8(63),
   7572 			1: uint8(9),
   7573 			2: uint8(92),
   7574 			3: uint8(136),
   7575 			4: uint8(28),
   7576 			5: uint8(64),
   7577 			6: uint8(32),
   7578 			7: uint8(201),
   7579 			8: uint8(85),
   7580 		},
   7581 		6: {
   7582 			0: uint8(75),
   7583 			1: uint8(15),
   7584 			2: uint8(9),
   7585 			3: uint8(9),
   7586 			4: uint8(64),
   7587 			5: uint8(255),
   7588 			6: uint8(184),
   7589 			7: uint8(119),
   7590 			8: uint8(16),
   7591 		},
   7592 		7: {
   7593 			0: uint8(86),
   7594 			1: uint8(6),
   7595 			2: uint8(28),
   7596 			3: uint8(5),
   7597 			4: uint8(64),
   7598 			5: uint8(255),
   7599 			6: uint8(25),
   7600 			7: uint8(248),
   7601 			8: uint8(1),
   7602 		},
   7603 		8: {
   7604 			0: uint8(56),
   7605 			1: uint8(8),
   7606 			2: uint8(17),
   7607 			3: uint8(132),
   7608 			4: uint8(137),
   7609 			5: uint8(255),
   7610 			6: uint8(55),
   7611 			7: uint8(116),
   7612 			8: uint8(128),
   7613 		},
   7614 		9: {
   7615 			0: uint8(58),
   7616 			1: uint8(15),
   7617 			2: uint8(20),
   7618 			3: uint8(82),
   7619 			4: uint8(135),
   7620 			5: uint8(57),
   7621 			6: uint8(26),
   7622 			7: uint8(121),
   7623 			8: uint8(40),
   7624 		},
   7625 	},
   7626 	8: {
   7627 		0: {
   7628 			0: uint8(164),
   7629 			1: uint8(50),
   7630 			2: uint8(31),
   7631 			3: uint8(137),
   7632 			4: uint8(154),
   7633 			5: uint8(133),
   7634 			6: uint8(25),
   7635 			7: uint8(35),
   7636 			8: uint8(218),
   7637 		},
   7638 		1: {
   7639 			0: uint8(51),
   7640 			1: uint8(103),
   7641 			2: uint8(44),
   7642 			3: uint8(131),
   7643 			4: uint8(131),
   7644 			5: uint8(123),
   7645 			6: uint8(31),
   7646 			7: uint8(6),
   7647 			8: uint8(158),
   7648 		},
   7649 		2: {
   7650 			0: uint8(86),
   7651 			1: uint8(40),
   7652 			2: uint8(64),
   7653 			3: uint8(135),
   7654 			4: uint8(148),
   7655 			5: uint8(224),
   7656 			6: uint8(45),
   7657 			7: uint8(183),
   7658 			8: uint8(128),
   7659 		},
   7660 		3: {
   7661 			0: uint8(22),
   7662 			1: uint8(26),
   7663 			2: uint8(17),
   7664 			3: uint8(131),
   7665 			4: uint8(240),
   7666 			5: uint8(154),
   7667 			6: uint8(14),
   7668 			7: uint8(1),
   7669 			8: uint8(209),
   7670 		},
   7671 		4: {
   7672 			0: uint8(45),
   7673 			1: uint8(16),
   7674 			2: uint8(21),
   7675 			3: uint8(91),
   7676 			4: uint8(64),
   7677 			5: uint8(222),
   7678 			6: uint8(7),
   7679 			7: uint8(1),
   7680 			8: uint8(197),
   7681 		},
   7682 		5: {
   7683 			0: uint8(56),
   7684 			1: uint8(21),
   7685 			2: uint8(39),
   7686 			3: uint8(155),
   7687 			4: uint8(60),
   7688 			5: uint8(138),
   7689 			6: uint8(23),
   7690 			7: uint8(102),
   7691 			8: uint8(213),
   7692 		},
   7693 		6: {
   7694 			0: uint8(83),
   7695 			1: uint8(12),
   7696 			2: uint8(13),
   7697 			3: uint8(54),
   7698 			4: uint8(192),
   7699 			5: uint8(255),
   7700 			6: uint8(68),
   7701 			7: uint8(47),
   7702 			8: uint8(28),
   7703 		},
   7704 		7: {
   7705 			0: uint8(85),
   7706 			1: uint8(26),
   7707 			2: uint8(85),
   7708 			3: uint8(85),
   7709 			4: uint8(128),
   7710 			5: uint8(128),
   7711 			6: uint8(32),
   7712 			7: uint8(146),
   7713 			8: uint8(171),
   7714 		},
   7715 		8: {
   7716 			0: uint8(18),
   7717 			1: uint8(11),
   7718 			2: uint8(7),
   7719 			3: uint8(63),
   7720 			4: uint8(144),
   7721 			5: uint8(171),
   7722 			6: uint8(4),
   7723 			7: uint8(4),
   7724 			8: uint8(246),
   7725 		},
   7726 		9: {
   7727 			0: uint8(35),
   7728 			1: uint8(27),
   7729 			2: uint8(10),
   7730 			3: uint8(146),
   7731 			4: uint8(174),
   7732 			5: uint8(171),
   7733 			6: uint8(12),
   7734 			7: uint8(26),
   7735 			8: uint8(128),
   7736 		},
   7737 	},
   7738 	9: {
   7739 		0: {
   7740 			0: uint8(190),
   7741 			1: uint8(80),
   7742 			2: uint8(35),
   7743 			3: uint8(99),
   7744 			4: uint8(180),
   7745 			5: uint8(80),
   7746 			6: uint8(126),
   7747 			7: uint8(54),
   7748 			8: uint8(45),
   7749 		},
   7750 		1: {
   7751 			0: uint8(85),
   7752 			1: uint8(126),
   7753 			2: uint8(47),
   7754 			3: uint8(87),
   7755 			4: uint8(176),
   7756 			5: uint8(51),
   7757 			6: uint8(41),
   7758 			7: uint8(20),
   7759 			8: uint8(32),
   7760 		},
   7761 		2: {
   7762 			0: uint8(101),
   7763 			1: uint8(75),
   7764 			2: uint8(128),
   7765 			3: uint8(139),
   7766 			4: uint8(118),
   7767 			5: uint8(146),
   7768 			6: uint8(116),
   7769 			7: uint8(128),
   7770 			8: uint8(85),
   7771 		},
   7772 		3: {
   7773 			0: uint8(56),
   7774 			1: uint8(41),
   7775 			2: uint8(15),
   7776 			3: uint8(176),
   7777 			4: uint8(236),
   7778 			5: uint8(85),
   7779 			6: uint8(37),
   7780 			7: uint8(9),
   7781 			8: uint8(62),
   7782 		},
   7783 		4: {
   7784 			0: uint8(71),
   7785 			1: uint8(30),
   7786 			2: uint8(17),
   7787 			3: uint8(119),
   7788 			4: uint8(118),
   7789 			5: uint8(255),
   7790 			6: uint8(17),
   7791 			7: uint8(18),
   7792 			8: uint8(138),
   7793 		},
   7794 		5: {
   7795 			0: uint8(101),
   7796 			1: uint8(38),
   7797 			2: uint8(60),
   7798 			3: uint8(138),
   7799 			4: uint8(55),
   7800 			5: uint8(70),
   7801 			6: uint8(43),
   7802 			7: uint8(26),
   7803 			8: uint8(142),
   7804 		},
   7805 		6: {
   7806 			0: uint8(146),
   7807 			1: uint8(36),
   7808 			2: uint8(19),
   7809 			3: uint8(30),
   7810 			4: uint8(171),
   7811 			5: uint8(255),
   7812 			6: uint8(97),
   7813 			7: uint8(27),
   7814 			8: uint8(20),
   7815 		},
   7816 		7: {
   7817 			0: uint8(138),
   7818 			1: uint8(45),
   7819 			2: uint8(61),
   7820 			3: uint8(62),
   7821 			4: uint8(219),
   7822 			5: uint8(1),
   7823 			6: uint8(81),
   7824 			7: uint8(188),
   7825 			8: uint8(64),
   7826 		},
   7827 		8: {
   7828 			0: uint8(32),
   7829 			1: uint8(41),
   7830 			2: uint8(20),
   7831 			3: uint8(117),
   7832 			4: uint8(151),
   7833 			5: uint8(142),
   7834 			6: uint8(20),
   7835 			7: uint8(21),
   7836 			8: uint8(163),
   7837 		},
   7838 		9: {
   7839 			0: uint8(112),
   7840 			1: uint8(19),
   7841 			2: uint8(12),
   7842 			3: uint8(61),
   7843 			4: uint8(195),
   7844 			5: uint8(128),
   7845 			6: uint8(48),
   7846 			7: uint8(4),
   7847 			8: uint8(24),
   7848 		},
   7849 	},
   7850 }
   7851 
   7852 func VP8ResetProba(tls *libc.TLS, proba uintptr) {
   7853 	libc.Xmemset(tls, proba, libc.Int32FromUint32(255), uint64(3))
   7854 	// proba->bands[][] is initialized later
   7855 }
   7856 
   7857 func ParseIntraMode(tls *libc.TLS, br2 uintptr, dec uintptr, mb_x int32) {
   7858 	bp := tls.Alloc(16)
   7859 	defer tls.Free(16)
   7860 	var bit, pos, shift, x1, y, ymode, ymode1, v1, v14, v16, v22, v24, v30, v32, v38, v40, v42, v47, v49, v51, v56, v58, v6, v60, v65, v67, v71, v76, v78, v8, v80, v85, v87, v89 int32
   7861 	var bits bit_t
   7862 	var block, left, modes, prob1, top, v10, v11, v18, v19, v2, v26, v27, v3, v34, v35, v43, v44, v52, v53, v61, v62, v72, v73 uintptr
   7863 	var range1, split, value range_t
   7864 	var v12, v20, v28, v36, v4, v45, v54, v63, v74 uint64_t
   7865 	var _ /* in_bits at bp+0 */ lbit_t
   7866 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, block, 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, v26, v27, v28, v3, v30, v32, v34, v35, v36, v38, v4, v40, v42, v43, v44, v45, v47, v49, v51, v52, v53, v54, v56, v58, v6, v60, v61, v62, v63, v65, v67, v71, v72, v73, v74, v76, v78, v8, v80, v85, v87, v89
   7867 	top = (*VP8Decoder)(unsafe.Pointer(dec)).Fintra_t + uintptr(int32(4)*mb_x)
   7868 	left = dec + 2816
   7869 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr(mb_x)*800
   7870 	// Note: we don't save segment map (yet), as we don't expect
   7871 	// to decode more than 1 keyframe.
   7872 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fsegment_hdr.Fupdate_map != 0 {
   7873 		// Hardcoded tree parsing
   7874 		v2 = br2
   7875 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   7876 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   7877 			v3 = v2
   7878 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   7879 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   7880 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   7881 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   7882 				goto _5
   7883 			_5:
   7884 				bits = v4
   7885 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   7886 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   7887 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   7888 			} else {
   7889 				VP8LoadFinalBytes(tls, v3)
   7890 			}
   7891 		}
   7892 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   7893 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dec + 1192)))) >> int32(8)
   7894 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   7895 		bit = libc.BoolInt32(value > split)
   7896 		if bit != 0 {
   7897 			range1 = range1 - split
   7898 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   7899 		} else {
   7900 			range1 = split + uint32(1)
   7901 		}
   7902 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   7903 		goto _7
   7904 	_7:
   7905 		shift = int32(7) ^ v6
   7906 		range1 = range1 << libc.Uint32FromInt32(shift)
   7907 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   7908 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   7909 		v8 = bit
   7910 		goto _9
   7911 	_9:
   7912 		if !(v8 != 0) {
   7913 			v10 = br2
   7914 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   7915 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   7916 				v11 = v10
   7917 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   7918 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   7919 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   7920 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   7921 					goto _13
   7922 				_13:
   7923 					bits = v12
   7924 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   7925 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   7926 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   7927 				} else {
   7928 					VP8LoadFinalBytes(tls, v11)
   7929 				}
   7930 			}
   7931 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   7932 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dec + 1192 + 1)))) >> int32(8)
   7933 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   7934 			bit = libc.BoolInt32(value > split)
   7935 			if bit != 0 {
   7936 				range1 = range1 - split
   7937 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   7938 			} else {
   7939 				range1 = split + uint32(1)
   7940 			}
   7941 			v14 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   7942 			goto _15
   7943 		_15:
   7944 			shift = int32(7) ^ v14
   7945 			range1 = range1 << libc.Uint32FromInt32(shift)
   7946 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   7947 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   7948 			v16 = bit
   7949 			goto _17
   7950 		_17:
   7951 			v1 = v16
   7952 		} else {
   7953 			v18 = br2
   7954 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   7955 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   7956 				v19 = v18
   7957 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   7958 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   7959 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   7960 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   7961 					goto _21
   7962 				_21:
   7963 					bits = v20
   7964 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   7965 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   7966 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   7967 				} else {
   7968 					VP8LoadFinalBytes(tls, v19)
   7969 				}
   7970 			}
   7971 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   7972 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dec + 1192 + 2)))) >> int32(8)
   7973 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   7974 			bit = libc.BoolInt32(value > split)
   7975 			if bit != 0 {
   7976 				range1 = range1 - split
   7977 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   7978 			} else {
   7979 				range1 = split + uint32(1)
   7980 			}
   7981 			v22 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   7982 			goto _23
   7983 		_23:
   7984 			shift = int32(7) ^ v22
   7985 			range1 = range1 << libc.Uint32FromInt32(shift)
   7986 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   7987 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   7988 			v24 = bit
   7989 			goto _25
   7990 		_25:
   7991 			v1 = v24 + int32(2)
   7992 		}
   7993 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = libc.Uint8FromInt32(v1)
   7994 	} else {
   7995 		(*VP8MBData)(unsafe.Pointer(block)).Fsegment = uint8(0) // default for intra
   7996 	}
   7997 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
   7998 		v2 = br2
   7999 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8000 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8001 			v3 = v2
   8002 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8003 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8004 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8005 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8006 				goto _29
   8007 			_29:
   8008 				bits = v4
   8009 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8010 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8011 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8012 			} else {
   8013 				VP8LoadFinalBytes(tls, v3)
   8014 			}
   8015 		}
   8016 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8017 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8((*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p)) >> int32(8)
   8018 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8019 		bit = libc.BoolInt32(value > split)
   8020 		if bit != 0 {
   8021 			range1 = range1 - split
   8022 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8023 		} else {
   8024 			range1 = split + uint32(1)
   8025 		}
   8026 		v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8027 		goto _31
   8028 	_31:
   8029 		shift = int32(7) ^ v1
   8030 		range1 = range1 << libc.Uint32FromInt32(shift)
   8031 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8032 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8033 		v6 = bit
   8034 		goto _33
   8035 	_33:
   8036 		(*VP8MBData)(unsafe.Pointer(block)).Fskip = libc.Uint8FromInt32(v6)
   8037 	}
   8038 	v2 = br2
   8039 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8040 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8041 		v3 = v2
   8042 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8043 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8044 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8045 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8046 			goto _37
   8047 		_37:
   8048 			bits = v4
   8049 			bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8050 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8051 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8052 		} else {
   8053 			VP8LoadFinalBytes(tls, v3)
   8054 		}
   8055 	}
   8056 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8057 	split = range1 * libc.Uint32FromInt32(int32(145)) >> int32(8)
   8058 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8059 	bit = libc.BoolInt32(value > split)
   8060 	if bit != 0 {
   8061 		range1 = range1 - split
   8062 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8063 	} else {
   8064 		range1 = split + uint32(1)
   8065 	}
   8066 	v1 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8067 	goto _39
   8068 _39:
   8069 	shift = int32(7) ^ v1
   8070 	range1 = range1 << libc.Uint32FromInt32(shift)
   8071 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8072 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8073 	v6 = bit
   8074 	goto _41
   8075 _41:
   8076 	(*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 = libc.BoolUint8(!(v6 != 0))
   8077 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
   8078 		v2 = br2
   8079 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8080 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8081 			v3 = v2
   8082 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8083 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8084 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8085 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8086 				goto _46
   8087 			_46:
   8088 				bits = v4
   8089 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8090 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8091 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8092 			} else {
   8093 				VP8LoadFinalBytes(tls, v3)
   8094 			}
   8095 		}
   8096 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8097 		split = range1 * libc.Uint32FromInt32(int32(156)) >> int32(8)
   8098 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8099 		bit = libc.BoolInt32(value > split)
   8100 		if bit != 0 {
   8101 			range1 = range1 - split
   8102 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8103 		} else {
   8104 			range1 = split + uint32(1)
   8105 		}
   8106 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8107 		goto _48
   8108 	_48:
   8109 		shift = int32(7) ^ v6
   8110 		range1 = range1 << libc.Uint32FromInt32(shift)
   8111 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8112 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8113 		v8 = bit
   8114 		goto _50
   8115 	_50:
   8116 		if v8 != 0 {
   8117 			v10 = br2
   8118 			range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8119 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8120 				v11 = v10
   8121 				if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8122 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8123 					**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8124 					v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8125 					goto _55
   8126 				_55:
   8127 					bits = v12
   8128 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8129 					(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8130 					**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8131 				} else {
   8132 					VP8LoadFinalBytes(tls, v11)
   8133 				}
   8134 			}
   8135 			pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8136 			split = range1 * libc.Uint32FromInt32(int32(128)) >> int32(8)
   8137 			value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8138 			bit = libc.BoolInt32(value > split)
   8139 			if bit != 0 {
   8140 				range1 = range1 - split
   8141 				**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8142 			} else {
   8143 				range1 = split + uint32(1)
   8144 			}
   8145 			v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8146 			goto _57
   8147 		_57:
   8148 			shift = int32(7) ^ v16
   8149 			range1 = range1 << libc.Uint32FromInt32(shift)
   8150 			**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8151 			(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8152 			v22 = bit
   8153 			goto _59
   8154 		_59:
   8155 			if v22 != 0 {
   8156 				v14 = int32(TM_PRED)
   8157 			} else {
   8158 				v14 = int32(H_PRED)
   8159 			}
   8160 			v1 = v14
   8161 		} else {
   8162 			v18 = br2
   8163 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8164 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8165 				v19 = v18
   8166 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8167 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8168 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8169 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8170 					goto _64
   8171 				_64:
   8172 					bits = v20
   8173 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8174 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8175 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8176 				} else {
   8177 					VP8LoadFinalBytes(tls, v19)
   8178 				}
   8179 			}
   8180 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8181 			split = range1 * libc.Uint32FromInt32(int32(163)) >> int32(8)
   8182 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8183 			bit = libc.BoolInt32(value > split)
   8184 			if bit != 0 {
   8185 				range1 = range1 - split
   8186 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8187 			} else {
   8188 				range1 = split + uint32(1)
   8189 			}
   8190 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8191 			goto _66
   8192 		_66:
   8193 			shift = int32(7) ^ v30
   8194 			range1 = range1 << libc.Uint32FromInt32(shift)
   8195 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8196 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8197 			v32 = bit
   8198 			goto _68
   8199 		_68:
   8200 			if v32 != 0 {
   8201 				v24 = int32(V_PRED)
   8202 			} else {
   8203 				v24 = int32(DC_PRED)
   8204 			}
   8205 			v1 = v24
   8206 		}
   8207 		// Hardcoded 16x16 intra-mode decision tree.
   8208 		ymode = v1
   8209 		**(**uint8_t)(__ccgo_up(block + 769)) = libc.Uint8FromInt32(ymode)
   8210 		libc.Xmemset(tls, top, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8211 		libc.Xmemset(tls, left, ymode, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8212 	} else {
   8213 		modes = block + 769
   8214 		y = 0
   8215 		for {
   8216 			if !(y < int32(4)) {
   8217 				break
   8218 			}
   8219 			ymode1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
   8220 			x1 = 0
   8221 			for {
   8222 				if !(x1 < int32(4)) {
   8223 					break
   8224 				}
   8225 				prob1 = uintptr(unsafe.Pointer(&kBModesProba)) + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x1))))*90 + uintptr(ymode1)*9
   8226 				// Hardcoded tree parsing
   8227 				v2 = br2
   8228 				range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8229 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8230 					v3 = v2
   8231 					if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8232 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8233 						**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8234 						v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8235 						goto _75
   8236 					_75:
   8237 						bits = v4
   8238 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8239 						(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8240 						**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8241 					} else {
   8242 						VP8LoadFinalBytes(tls, v3)
   8243 					}
   8244 				}
   8245 				pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8246 				split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1)))) >> int32(8)
   8247 				value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8248 				bit = libc.BoolInt32(value > split)
   8249 				if bit != 0 {
   8250 					range1 = range1 - split
   8251 					**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8252 				} else {
   8253 					range1 = split + uint32(1)
   8254 				}
   8255 				v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8256 				goto _77
   8257 			_77:
   8258 				shift = int32(7) ^ v6
   8259 				range1 = range1 << libc.Uint32FromInt32(shift)
   8260 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8261 				(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8262 				v8 = bit
   8263 				goto _79
   8264 			_79:
   8265 				if !(v8 != 0) {
   8266 					v1 = int32(B_DC_PRED)
   8267 				} else {
   8268 					v10 = br2
   8269 					range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8270 					if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8271 						v11 = v10
   8272 						if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8273 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8274 							**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8275 							v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8276 							goto _84
   8277 						_84:
   8278 							bits = v12
   8279 							bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8280 							(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8281 							**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8282 						} else {
   8283 							VP8LoadFinalBytes(tls, v11)
   8284 						}
   8285 					}
   8286 					pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8287 					split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 1)))) >> int32(8)
   8288 					value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8289 					bit = libc.BoolInt32(value > split)
   8290 					if bit != 0 {
   8291 						range1 = range1 - split
   8292 						**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8293 					} else {
   8294 						range1 = split + uint32(1)
   8295 					}
   8296 					v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8297 					goto _86
   8298 				_86:
   8299 					shift = int32(7) ^ v16
   8300 					range1 = range1 << libc.Uint32FromInt32(shift)
   8301 					**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8302 					(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8303 					v22 = bit
   8304 					goto _88
   8305 				_88:
   8306 					if !(v22 != 0) {
   8307 						v14 = int32(B_TM_PRED)
   8308 					} else {
   8309 						v18 = br2
   8310 						range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8311 						if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8312 							v19 = v18
   8313 							if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8314 								libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8315 								**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8316 								v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8317 								goto _93
   8318 							_93:
   8319 								bits = v20
   8320 								bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8321 								(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8322 								**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8323 							} else {
   8324 								VP8LoadFinalBytes(tls, v19)
   8325 							}
   8326 						}
   8327 						pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8328 						split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 2)))) >> int32(8)
   8329 						value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8330 						bit = libc.BoolInt32(value > split)
   8331 						if bit != 0 {
   8332 							range1 = range1 - split
   8333 							**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8334 						} else {
   8335 							range1 = split + uint32(1)
   8336 						}
   8337 						v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8338 						goto _95
   8339 					_95:
   8340 						shift = int32(7) ^ v30
   8341 						range1 = range1 << libc.Uint32FromInt32(shift)
   8342 						**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8343 						(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8344 						v32 = bit
   8345 						goto _97
   8346 					_97:
   8347 						if !(v32 != 0) {
   8348 							v24 = int32(B_VE_PRED)
   8349 						} else {
   8350 							v26 = br2
   8351 							range1 = (*VP8BitReader)(unsafe.Pointer(v26)).Frange1
   8352 							if (*VP8BitReader)(unsafe.Pointer(v26)).Fbits < libc.Int32FromInt32(0) {
   8353 								v27 = v26
   8354 								if (*VP8BitReader)(unsafe.Pointer(v27)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v27)).Fbuf_max {
   8355 									libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v27)).Fbuf, uint64(8))
   8356 									**(**uintptr)(__ccgo_up(v27 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8357 									v28 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8358 									goto _102
   8359 								_102:
   8360 									bits = v28
   8361 									bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8362 									(*VP8BitReader)(unsafe.Pointer(v27)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v27)).Fvalue<<libc.Int32FromInt32(BITS)
   8363 									**(**int32)(__ccgo_up(v27 + 12)) += int32(BITS)
   8364 								} else {
   8365 									VP8LoadFinalBytes(tls, v27)
   8366 								}
   8367 							}
   8368 							pos = (*VP8BitReader)(unsafe.Pointer(v26)).Fbits
   8369 							split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 3)))) >> int32(8)
   8370 							value = uint32((*VP8BitReader)(unsafe.Pointer(v26)).Fvalue >> pos)
   8371 							bit = libc.BoolInt32(value > split)
   8372 							if bit != 0 {
   8373 								range1 = range1 - split
   8374 								**(**bit_t)(__ccgo_up(v26)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8375 							} else {
   8376 								range1 = split + uint32(1)
   8377 							}
   8378 							v40 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8379 							goto _104
   8380 						_104:
   8381 							shift = int32(7) ^ v40
   8382 							range1 = range1 << libc.Uint32FromInt32(shift)
   8383 							**(**int32)(__ccgo_up(v26 + 12)) -= shift
   8384 							(*VP8BitReader)(unsafe.Pointer(v26)).Frange1 = range1 - uint32(1)
   8385 							v42 = bit
   8386 							goto _106
   8387 						_106:
   8388 							if !(v42 != 0) {
   8389 								v34 = br2
   8390 								range1 = (*VP8BitReader)(unsafe.Pointer(v34)).Frange1
   8391 								if (*VP8BitReader)(unsafe.Pointer(v34)).Fbits < libc.Int32FromInt32(0) {
   8392 									v35 = v34
   8393 									if (*VP8BitReader)(unsafe.Pointer(v35)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v35)).Fbuf_max {
   8394 										libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v35)).Fbuf, uint64(8))
   8395 										**(**uintptr)(__ccgo_up(v35 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8396 										v36 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8397 										goto _111
   8398 									_111:
   8399 										bits = v36
   8400 										bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8401 										(*VP8BitReader)(unsafe.Pointer(v35)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v35)).Fvalue<<libc.Int32FromInt32(BITS)
   8402 										**(**int32)(__ccgo_up(v35 + 12)) += int32(BITS)
   8403 									} else {
   8404 										VP8LoadFinalBytes(tls, v35)
   8405 									}
   8406 								}
   8407 								pos = (*VP8BitReader)(unsafe.Pointer(v34)).Fbits
   8408 								split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 4)))) >> int32(8)
   8409 								value = uint32((*VP8BitReader)(unsafe.Pointer(v34)).Fvalue >> pos)
   8410 								bit = libc.BoolInt32(value > split)
   8411 								if bit != 0 {
   8412 									range1 = range1 - split
   8413 									**(**bit_t)(__ccgo_up(v34)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8414 								} else {
   8415 									range1 = split + uint32(1)
   8416 								}
   8417 								v49 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8418 								goto _113
   8419 							_113:
   8420 								shift = int32(7) ^ v49
   8421 								range1 = range1 << libc.Uint32FromInt32(shift)
   8422 								**(**int32)(__ccgo_up(v34 + 12)) -= shift
   8423 								(*VP8BitReader)(unsafe.Pointer(v34)).Frange1 = range1 - uint32(1)
   8424 								v51 = bit
   8425 								goto _115
   8426 							_115:
   8427 								if !(v51 != 0) {
   8428 									v47 = int32(B_HE_PRED)
   8429 								} else {
   8430 									v43 = br2
   8431 									range1 = (*VP8BitReader)(unsafe.Pointer(v43)).Frange1
   8432 									if (*VP8BitReader)(unsafe.Pointer(v43)).Fbits < libc.Int32FromInt32(0) {
   8433 										v44 = v43
   8434 										if (*VP8BitReader)(unsafe.Pointer(v44)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v44)).Fbuf_max {
   8435 											libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v44)).Fbuf, uint64(8))
   8436 											**(**uintptr)(__ccgo_up(v44 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8437 											v45 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8438 											goto _120
   8439 										_120:
   8440 											bits = v45
   8441 											bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8442 											(*VP8BitReader)(unsafe.Pointer(v44)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v44)).Fvalue<<libc.Int32FromInt32(BITS)
   8443 											**(**int32)(__ccgo_up(v44 + 12)) += int32(BITS)
   8444 										} else {
   8445 											VP8LoadFinalBytes(tls, v44)
   8446 										}
   8447 									}
   8448 									pos = (*VP8BitReader)(unsafe.Pointer(v43)).Fbits
   8449 									split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 5)))) >> int32(8)
   8450 									value = uint32((*VP8BitReader)(unsafe.Pointer(v43)).Fvalue >> pos)
   8451 									bit = libc.BoolInt32(value > split)
   8452 									if bit != 0 {
   8453 										range1 = range1 - split
   8454 										**(**bit_t)(__ccgo_up(v43)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8455 									} else {
   8456 										range1 = split + uint32(1)
   8457 									}
   8458 									v58 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8459 									goto _122
   8460 								_122:
   8461 									shift = int32(7) ^ v58
   8462 									range1 = range1 << libc.Uint32FromInt32(shift)
   8463 									**(**int32)(__ccgo_up(v43 + 12)) -= shift
   8464 									(*VP8BitReader)(unsafe.Pointer(v43)).Frange1 = range1 - uint32(1)
   8465 									v60 = bit
   8466 									goto _124
   8467 								_124:
   8468 									if !(v60 != 0) {
   8469 										v56 = int32(B_RD_PRED)
   8470 									} else {
   8471 										v56 = int32(B_VR_PRED)
   8472 									}
   8473 									v47 = v56
   8474 								}
   8475 								v38 = v47
   8476 							} else {
   8477 								v52 = br2
   8478 								range1 = (*VP8BitReader)(unsafe.Pointer(v52)).Frange1
   8479 								if (*VP8BitReader)(unsafe.Pointer(v52)).Fbits < libc.Int32FromInt32(0) {
   8480 									v53 = v52
   8481 									if (*VP8BitReader)(unsafe.Pointer(v53)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v53)).Fbuf_max {
   8482 										libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v53)).Fbuf, uint64(8))
   8483 										**(**uintptr)(__ccgo_up(v53 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8484 										v54 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8485 										goto _129
   8486 									_129:
   8487 										bits = v54
   8488 										bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8489 										(*VP8BitReader)(unsafe.Pointer(v53)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v53)).Fvalue<<libc.Int32FromInt32(BITS)
   8490 										**(**int32)(__ccgo_up(v53 + 12)) += int32(BITS)
   8491 									} else {
   8492 										VP8LoadFinalBytes(tls, v53)
   8493 									}
   8494 								}
   8495 								pos = (*VP8BitReader)(unsafe.Pointer(v52)).Fbits
   8496 								split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 6)))) >> int32(8)
   8497 								value = uint32((*VP8BitReader)(unsafe.Pointer(v52)).Fvalue >> pos)
   8498 								bit = libc.BoolInt32(value > split)
   8499 								if bit != 0 {
   8500 									range1 = range1 - split
   8501 									**(**bit_t)(__ccgo_up(v52)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8502 								} else {
   8503 									range1 = split + uint32(1)
   8504 								}
   8505 								v67 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8506 								goto _131
   8507 							_131:
   8508 								shift = int32(7) ^ v67
   8509 								range1 = range1 << libc.Uint32FromInt32(shift)
   8510 								**(**int32)(__ccgo_up(v52 + 12)) -= shift
   8511 								(*VP8BitReader)(unsafe.Pointer(v52)).Frange1 = range1 - uint32(1)
   8512 								v71 = bit
   8513 								goto _133
   8514 							_133:
   8515 								if !(v71 != 0) {
   8516 									v65 = int32(B_LD_PRED)
   8517 								} else {
   8518 									v61 = br2
   8519 									range1 = (*VP8BitReader)(unsafe.Pointer(v61)).Frange1
   8520 									if (*VP8BitReader)(unsafe.Pointer(v61)).Fbits < libc.Int32FromInt32(0) {
   8521 										v62 = v61
   8522 										if (*VP8BitReader)(unsafe.Pointer(v62)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v62)).Fbuf_max {
   8523 											libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v62)).Fbuf, uint64(8))
   8524 											**(**uintptr)(__ccgo_up(v62 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8525 											v63 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8526 											goto _138
   8527 										_138:
   8528 											bits = v63
   8529 											bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8530 											(*VP8BitReader)(unsafe.Pointer(v62)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v62)).Fvalue<<libc.Int32FromInt32(BITS)
   8531 											**(**int32)(__ccgo_up(v62 + 12)) += int32(BITS)
   8532 										} else {
   8533 											VP8LoadFinalBytes(tls, v62)
   8534 										}
   8535 									}
   8536 									pos = (*VP8BitReader)(unsafe.Pointer(v61)).Fbits
   8537 									split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 7)))) >> int32(8)
   8538 									value = uint32((*VP8BitReader)(unsafe.Pointer(v61)).Fvalue >> pos)
   8539 									bit = libc.BoolInt32(value > split)
   8540 									if bit != 0 {
   8541 										range1 = range1 - split
   8542 										**(**bit_t)(__ccgo_up(v61)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8543 									} else {
   8544 										range1 = split + uint32(1)
   8545 									}
   8546 									v78 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8547 									goto _140
   8548 								_140:
   8549 									shift = int32(7) ^ v78
   8550 									range1 = range1 << libc.Uint32FromInt32(shift)
   8551 									**(**int32)(__ccgo_up(v61 + 12)) -= shift
   8552 									(*VP8BitReader)(unsafe.Pointer(v61)).Frange1 = range1 - uint32(1)
   8553 									v80 = bit
   8554 									goto _142
   8555 								_142:
   8556 									if !(v80 != 0) {
   8557 										v76 = int32(B_VL_PRED)
   8558 									} else {
   8559 										v72 = br2
   8560 										range1 = (*VP8BitReader)(unsafe.Pointer(v72)).Frange1
   8561 										if (*VP8BitReader)(unsafe.Pointer(v72)).Fbits < libc.Int32FromInt32(0) {
   8562 											v73 = v72
   8563 											if (*VP8BitReader)(unsafe.Pointer(v73)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v73)).Fbuf_max {
   8564 												libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v73)).Fbuf, uint64(8))
   8565 												**(**uintptr)(__ccgo_up(v73 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8566 												v74 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8567 												goto _147
   8568 											_147:
   8569 												bits = v74
   8570 												bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8571 												(*VP8BitReader)(unsafe.Pointer(v73)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v73)).Fvalue<<libc.Int32FromInt32(BITS)
   8572 												**(**int32)(__ccgo_up(v73 + 12)) += int32(BITS)
   8573 											} else {
   8574 												VP8LoadFinalBytes(tls, v73)
   8575 											}
   8576 										}
   8577 										pos = (*VP8BitReader)(unsafe.Pointer(v72)).Fbits
   8578 										split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob1 + 8)))) >> int32(8)
   8579 										value = uint32((*VP8BitReader)(unsafe.Pointer(v72)).Fvalue >> pos)
   8580 										bit = libc.BoolInt32(value > split)
   8581 										if bit != 0 {
   8582 											range1 = range1 - split
   8583 											**(**bit_t)(__ccgo_up(v72)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8584 										} else {
   8585 											range1 = split + uint32(1)
   8586 										}
   8587 										v87 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8588 										goto _149
   8589 									_149:
   8590 										shift = int32(7) ^ v87
   8591 										range1 = range1 << libc.Uint32FromInt32(shift)
   8592 										**(**int32)(__ccgo_up(v72 + 12)) -= shift
   8593 										(*VP8BitReader)(unsafe.Pointer(v72)).Frange1 = range1 - uint32(1)
   8594 										v89 = bit
   8595 										goto _151
   8596 									_151:
   8597 										if !(v89 != 0) {
   8598 											v85 = int32(B_HD_PRED)
   8599 										} else {
   8600 											v85 = int32(B_HU_PRED)
   8601 										}
   8602 										v76 = v85
   8603 									}
   8604 									v65 = v76
   8605 								}
   8606 								v38 = v65
   8607 							}
   8608 							v24 = v38
   8609 						}
   8610 						v14 = v24
   8611 					}
   8612 					v1 = v14
   8613 				}
   8614 				ymode1 = v1
   8615 				**(**uint8_t)(__ccgo_up(top + uintptr(x1))) = libc.Uint8FromInt32(ymode1)
   8616 				goto _70
   8617 			_70:
   8618 				;
   8619 				x1 = x1 + 1
   8620 			}
   8621 			libc.Xmemcpy(tls, modes, top, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
   8622 			modes = modes + uintptr(4)
   8623 			**(**uint8_t)(__ccgo_up(left + uintptr(y))) = libc.Uint8FromInt32(ymode1)
   8624 			goto _69
   8625 		_69:
   8626 			;
   8627 			y = y + 1
   8628 		}
   8629 	}
   8630 	// Hardcoded UVMode decision tree
   8631 	v2 = br2
   8632 	range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
   8633 	if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
   8634 		v3 = v2
   8635 		if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
   8636 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
   8637 			**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8638 			v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8639 			goto _156
   8640 		_156:
   8641 			bits = v4
   8642 			bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8643 			(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
   8644 			**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
   8645 		} else {
   8646 			VP8LoadFinalBytes(tls, v3)
   8647 		}
   8648 	}
   8649 	pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
   8650 	split = range1 * libc.Uint32FromInt32(int32(142)) >> int32(8)
   8651 	value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
   8652 	bit = libc.BoolInt32(value > split)
   8653 	if bit != 0 {
   8654 		range1 = range1 - split
   8655 		**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8656 	} else {
   8657 		range1 = split + uint32(1)
   8658 	}
   8659 	v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8660 	goto _158
   8661 _158:
   8662 	shift = int32(7) ^ v6
   8663 	range1 = range1 << libc.Uint32FromInt32(shift)
   8664 	**(**int32)(__ccgo_up(v2 + 12)) -= shift
   8665 	(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
   8666 	v8 = bit
   8667 	goto _160
   8668 _160:
   8669 	if !(v8 != 0) {
   8670 		v1 = int32(DC_PRED)
   8671 	} else {
   8672 		v10 = br2
   8673 		range1 = (*VP8BitReader)(unsafe.Pointer(v10)).Frange1
   8674 		if (*VP8BitReader)(unsafe.Pointer(v10)).Fbits < libc.Int32FromInt32(0) {
   8675 			v11 = v10
   8676 			if (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf_max {
   8677 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v11)).Fbuf, uint64(8))
   8678 				**(**uintptr)(__ccgo_up(v11 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8679 				v12 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8680 				goto _165
   8681 			_165:
   8682 				bits = v12
   8683 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8684 				(*VP8BitReader)(unsafe.Pointer(v11)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v11)).Fvalue<<libc.Int32FromInt32(BITS)
   8685 				**(**int32)(__ccgo_up(v11 + 12)) += int32(BITS)
   8686 			} else {
   8687 				VP8LoadFinalBytes(tls, v11)
   8688 			}
   8689 		}
   8690 		pos = (*VP8BitReader)(unsafe.Pointer(v10)).Fbits
   8691 		split = range1 * libc.Uint32FromInt32(int32(114)) >> int32(8)
   8692 		value = uint32((*VP8BitReader)(unsafe.Pointer(v10)).Fvalue >> pos)
   8693 		bit = libc.BoolInt32(value > split)
   8694 		if bit != 0 {
   8695 			range1 = range1 - split
   8696 			**(**bit_t)(__ccgo_up(v10)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8697 		} else {
   8698 			range1 = split + uint32(1)
   8699 		}
   8700 		v16 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8701 		goto _167
   8702 	_167:
   8703 		shift = int32(7) ^ v16
   8704 		range1 = range1 << libc.Uint32FromInt32(shift)
   8705 		**(**int32)(__ccgo_up(v10 + 12)) -= shift
   8706 		(*VP8BitReader)(unsafe.Pointer(v10)).Frange1 = range1 - uint32(1)
   8707 		v22 = bit
   8708 		goto _169
   8709 	_169:
   8710 		if !(v22 != 0) {
   8711 			v14 = int32(V_PRED)
   8712 		} else {
   8713 			v18 = br2
   8714 			range1 = (*VP8BitReader)(unsafe.Pointer(v18)).Frange1
   8715 			if (*VP8BitReader)(unsafe.Pointer(v18)).Fbits < libc.Int32FromInt32(0) {
   8716 				v19 = v18
   8717 				if (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf_max {
   8718 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v19)).Fbuf, uint64(8))
   8719 					**(**uintptr)(__ccgo_up(v19 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
   8720 					v20 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
   8721 					goto _174
   8722 				_174:
   8723 					bits = v20
   8724 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
   8725 					(*VP8BitReader)(unsafe.Pointer(v19)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v19)).Fvalue<<libc.Int32FromInt32(BITS)
   8726 					**(**int32)(__ccgo_up(v19 + 12)) += int32(BITS)
   8727 				} else {
   8728 					VP8LoadFinalBytes(tls, v19)
   8729 				}
   8730 			}
   8731 			pos = (*VP8BitReader)(unsafe.Pointer(v18)).Fbits
   8732 			split = range1 * libc.Uint32FromInt32(int32(183)) >> int32(8)
   8733 			value = uint32((*VP8BitReader)(unsafe.Pointer(v18)).Fvalue >> pos)
   8734 			bit = libc.BoolInt32(value > split)
   8735 			if bit != 0 {
   8736 				range1 = range1 - split
   8737 				**(**bit_t)(__ccgo_up(v18)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
   8738 			} else {
   8739 				range1 = split + uint32(1)
   8740 			}
   8741 			v30 = int32(31) ^ libc.X__builtin_clz(tls, range1)
   8742 			goto _176
   8743 		_176:
   8744 			shift = int32(7) ^ v30
   8745 			range1 = range1 << libc.Uint32FromInt32(shift)
   8746 			**(**int32)(__ccgo_up(v18 + 12)) -= shift
   8747 			(*VP8BitReader)(unsafe.Pointer(v18)).Frange1 = range1 - uint32(1)
   8748 			v32 = bit
   8749 			goto _178
   8750 		_178:
   8751 			if v32 != 0 {
   8752 				v24 = int32(TM_PRED)
   8753 			} else {
   8754 				v24 = int32(H_PRED)
   8755 			}
   8756 			v14 = v24
   8757 		}
   8758 		v1 = v14
   8759 	}
   8760 	(*VP8MBData)(unsafe.Pointer(block)).Fuvmode = libc.Uint8FromInt32(v1)
   8761 }
   8762 
   8763 func VP8ParseIntraModeRow(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
   8764 	var mb_x int32
   8765 	_ = mb_x
   8766 	mb_x = 0
   8767 	for {
   8768 		if !(mb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
   8769 			break
   8770 		}
   8771 		ParseIntraMode(tls, br, dec, mb_x)
   8772 		goto _1
   8773 	_1:
   8774 		;
   8775 		mb_x = mb_x + 1
   8776 	}
   8777 	return libc.BoolInt32(!((*VP8Decoder)(unsafe.Pointer(dec)).Fbr.Feof != 0))
   8778 }
   8779 
   8780 //------------------------------------------------------------------------------
   8781 // Paragraph 13
   8782 
   8783 var CoeffsUpdateProba = [4][8][3][11]uint8_t{
   8784 	0: {
   8785 		0: {
   8786 			0: {
   8787 				0:  uint8(255),
   8788 				1:  uint8(255),
   8789 				2:  uint8(255),
   8790 				3:  uint8(255),
   8791 				4:  uint8(255),
   8792 				5:  uint8(255),
   8793 				6:  uint8(255),
   8794 				7:  uint8(255),
   8795 				8:  uint8(255),
   8796 				9:  uint8(255),
   8797 				10: uint8(255),
   8798 			},
   8799 			1: {
   8800 				0:  uint8(255),
   8801 				1:  uint8(255),
   8802 				2:  uint8(255),
   8803 				3:  uint8(255),
   8804 				4:  uint8(255),
   8805 				5:  uint8(255),
   8806 				6:  uint8(255),
   8807 				7:  uint8(255),
   8808 				8:  uint8(255),
   8809 				9:  uint8(255),
   8810 				10: uint8(255),
   8811 			},
   8812 			2: {
   8813 				0:  uint8(255),
   8814 				1:  uint8(255),
   8815 				2:  uint8(255),
   8816 				3:  uint8(255),
   8817 				4:  uint8(255),
   8818 				5:  uint8(255),
   8819 				6:  uint8(255),
   8820 				7:  uint8(255),
   8821 				8:  uint8(255),
   8822 				9:  uint8(255),
   8823 				10: uint8(255),
   8824 			},
   8825 		},
   8826 		1: {
   8827 			0: {
   8828 				0:  uint8(176),
   8829 				1:  uint8(246),
   8830 				2:  uint8(255),
   8831 				3:  uint8(255),
   8832 				4:  uint8(255),
   8833 				5:  uint8(255),
   8834 				6:  uint8(255),
   8835 				7:  uint8(255),
   8836 				8:  uint8(255),
   8837 				9:  uint8(255),
   8838 				10: uint8(255),
   8839 			},
   8840 			1: {
   8841 				0:  uint8(223),
   8842 				1:  uint8(241),
   8843 				2:  uint8(252),
   8844 				3:  uint8(255),
   8845 				4:  uint8(255),
   8846 				5:  uint8(255),
   8847 				6:  uint8(255),
   8848 				7:  uint8(255),
   8849 				8:  uint8(255),
   8850 				9:  uint8(255),
   8851 				10: uint8(255),
   8852 			},
   8853 			2: {
   8854 				0:  uint8(249),
   8855 				1:  uint8(253),
   8856 				2:  uint8(253),
   8857 				3:  uint8(255),
   8858 				4:  uint8(255),
   8859 				5:  uint8(255),
   8860 				6:  uint8(255),
   8861 				7:  uint8(255),
   8862 				8:  uint8(255),
   8863 				9:  uint8(255),
   8864 				10: uint8(255),
   8865 			},
   8866 		},
   8867 		2: {
   8868 			0: {
   8869 				0:  uint8(255),
   8870 				1:  uint8(244),
   8871 				2:  uint8(252),
   8872 				3:  uint8(255),
   8873 				4:  uint8(255),
   8874 				5:  uint8(255),
   8875 				6:  uint8(255),
   8876 				7:  uint8(255),
   8877 				8:  uint8(255),
   8878 				9:  uint8(255),
   8879 				10: uint8(255),
   8880 			},
   8881 			1: {
   8882 				0:  uint8(234),
   8883 				1:  uint8(254),
   8884 				2:  uint8(254),
   8885 				3:  uint8(255),
   8886 				4:  uint8(255),
   8887 				5:  uint8(255),
   8888 				6:  uint8(255),
   8889 				7:  uint8(255),
   8890 				8:  uint8(255),
   8891 				9:  uint8(255),
   8892 				10: uint8(255),
   8893 			},
   8894 			2: {
   8895 				0:  uint8(253),
   8896 				1:  uint8(255),
   8897 				2:  uint8(255),
   8898 				3:  uint8(255),
   8899 				4:  uint8(255),
   8900 				5:  uint8(255),
   8901 				6:  uint8(255),
   8902 				7:  uint8(255),
   8903 				8:  uint8(255),
   8904 				9:  uint8(255),
   8905 				10: uint8(255),
   8906 			},
   8907 		},
   8908 		3: {
   8909 			0: {
   8910 				0:  uint8(255),
   8911 				1:  uint8(246),
   8912 				2:  uint8(254),
   8913 				3:  uint8(255),
   8914 				4:  uint8(255),
   8915 				5:  uint8(255),
   8916 				6:  uint8(255),
   8917 				7:  uint8(255),
   8918 				8:  uint8(255),
   8919 				9:  uint8(255),
   8920 				10: uint8(255),
   8921 			},
   8922 			1: {
   8923 				0:  uint8(239),
   8924 				1:  uint8(253),
   8925 				2:  uint8(254),
   8926 				3:  uint8(255),
   8927 				4:  uint8(255),
   8928 				5:  uint8(255),
   8929 				6:  uint8(255),
   8930 				7:  uint8(255),
   8931 				8:  uint8(255),
   8932 				9:  uint8(255),
   8933 				10: uint8(255),
   8934 			},
   8935 			2: {
   8936 				0:  uint8(254),
   8937 				1:  uint8(255),
   8938 				2:  uint8(254),
   8939 				3:  uint8(255),
   8940 				4:  uint8(255),
   8941 				5:  uint8(255),
   8942 				6:  uint8(255),
   8943 				7:  uint8(255),
   8944 				8:  uint8(255),
   8945 				9:  uint8(255),
   8946 				10: uint8(255),
   8947 			},
   8948 		},
   8949 		4: {
   8950 			0: {
   8951 				0:  uint8(255),
   8952 				1:  uint8(248),
   8953 				2:  uint8(254),
   8954 				3:  uint8(255),
   8955 				4:  uint8(255),
   8956 				5:  uint8(255),
   8957 				6:  uint8(255),
   8958 				7:  uint8(255),
   8959 				8:  uint8(255),
   8960 				9:  uint8(255),
   8961 				10: uint8(255),
   8962 			},
   8963 			1: {
   8964 				0:  uint8(251),
   8965 				1:  uint8(255),
   8966 				2:  uint8(254),
   8967 				3:  uint8(255),
   8968 				4:  uint8(255),
   8969 				5:  uint8(255),
   8970 				6:  uint8(255),
   8971 				7:  uint8(255),
   8972 				8:  uint8(255),
   8973 				9:  uint8(255),
   8974 				10: uint8(255),
   8975 			},
   8976 			2: {
   8977 				0:  uint8(255),
   8978 				1:  uint8(255),
   8979 				2:  uint8(255),
   8980 				3:  uint8(255),
   8981 				4:  uint8(255),
   8982 				5:  uint8(255),
   8983 				6:  uint8(255),
   8984 				7:  uint8(255),
   8985 				8:  uint8(255),
   8986 				9:  uint8(255),
   8987 				10: uint8(255),
   8988 			},
   8989 		},
   8990 		5: {
   8991 			0: {
   8992 				0:  uint8(255),
   8993 				1:  uint8(253),
   8994 				2:  uint8(254),
   8995 				3:  uint8(255),
   8996 				4:  uint8(255),
   8997 				5:  uint8(255),
   8998 				6:  uint8(255),
   8999 				7:  uint8(255),
   9000 				8:  uint8(255),
   9001 				9:  uint8(255),
   9002 				10: uint8(255),
   9003 			},
   9004 			1: {
   9005 				0:  uint8(251),
   9006 				1:  uint8(254),
   9007 				2:  uint8(254),
   9008 				3:  uint8(255),
   9009 				4:  uint8(255),
   9010 				5:  uint8(255),
   9011 				6:  uint8(255),
   9012 				7:  uint8(255),
   9013 				8:  uint8(255),
   9014 				9:  uint8(255),
   9015 				10: uint8(255),
   9016 			},
   9017 			2: {
   9018 				0:  uint8(254),
   9019 				1:  uint8(255),
   9020 				2:  uint8(254),
   9021 				3:  uint8(255),
   9022 				4:  uint8(255),
   9023 				5:  uint8(255),
   9024 				6:  uint8(255),
   9025 				7:  uint8(255),
   9026 				8:  uint8(255),
   9027 				9:  uint8(255),
   9028 				10: uint8(255),
   9029 			},
   9030 		},
   9031 		6: {
   9032 			0: {
   9033 				0:  uint8(255),
   9034 				1:  uint8(254),
   9035 				2:  uint8(253),
   9036 				3:  uint8(255),
   9037 				4:  uint8(254),
   9038 				5:  uint8(255),
   9039 				6:  uint8(255),
   9040 				7:  uint8(255),
   9041 				8:  uint8(255),
   9042 				9:  uint8(255),
   9043 				10: uint8(255),
   9044 			},
   9045 			1: {
   9046 				0:  uint8(250),
   9047 				1:  uint8(255),
   9048 				2:  uint8(254),
   9049 				3:  uint8(255),
   9050 				4:  uint8(254),
   9051 				5:  uint8(255),
   9052 				6:  uint8(255),
   9053 				7:  uint8(255),
   9054 				8:  uint8(255),
   9055 				9:  uint8(255),
   9056 				10: uint8(255),
   9057 			},
   9058 			2: {
   9059 				0:  uint8(254),
   9060 				1:  uint8(255),
   9061 				2:  uint8(255),
   9062 				3:  uint8(255),
   9063 				4:  uint8(255),
   9064 				5:  uint8(255),
   9065 				6:  uint8(255),
   9066 				7:  uint8(255),
   9067 				8:  uint8(255),
   9068 				9:  uint8(255),
   9069 				10: uint8(255),
   9070 			},
   9071 		},
   9072 		7: {
   9073 			0: {
   9074 				0:  uint8(255),
   9075 				1:  uint8(255),
   9076 				2:  uint8(255),
   9077 				3:  uint8(255),
   9078 				4:  uint8(255),
   9079 				5:  uint8(255),
   9080 				6:  uint8(255),
   9081 				7:  uint8(255),
   9082 				8:  uint8(255),
   9083 				9:  uint8(255),
   9084 				10: uint8(255),
   9085 			},
   9086 			1: {
   9087 				0:  uint8(255),
   9088 				1:  uint8(255),
   9089 				2:  uint8(255),
   9090 				3:  uint8(255),
   9091 				4:  uint8(255),
   9092 				5:  uint8(255),
   9093 				6:  uint8(255),
   9094 				7:  uint8(255),
   9095 				8:  uint8(255),
   9096 				9:  uint8(255),
   9097 				10: uint8(255),
   9098 			},
   9099 			2: {
   9100 				0:  uint8(255),
   9101 				1:  uint8(255),
   9102 				2:  uint8(255),
   9103 				3:  uint8(255),
   9104 				4:  uint8(255),
   9105 				5:  uint8(255),
   9106 				6:  uint8(255),
   9107 				7:  uint8(255),
   9108 				8:  uint8(255),
   9109 				9:  uint8(255),
   9110 				10: uint8(255),
   9111 			},
   9112 		},
   9113 	},
   9114 	1: {
   9115 		0: {
   9116 			0: {
   9117 				0:  uint8(217),
   9118 				1:  uint8(255),
   9119 				2:  uint8(255),
   9120 				3:  uint8(255),
   9121 				4:  uint8(255),
   9122 				5:  uint8(255),
   9123 				6:  uint8(255),
   9124 				7:  uint8(255),
   9125 				8:  uint8(255),
   9126 				9:  uint8(255),
   9127 				10: uint8(255),
   9128 			},
   9129 			1: {
   9130 				0:  uint8(225),
   9131 				1:  uint8(252),
   9132 				2:  uint8(241),
   9133 				3:  uint8(253),
   9134 				4:  uint8(255),
   9135 				5:  uint8(255),
   9136 				6:  uint8(254),
   9137 				7:  uint8(255),
   9138 				8:  uint8(255),
   9139 				9:  uint8(255),
   9140 				10: uint8(255),
   9141 			},
   9142 			2: {
   9143 				0:  uint8(234),
   9144 				1:  uint8(250),
   9145 				2:  uint8(241),
   9146 				3:  uint8(250),
   9147 				4:  uint8(253),
   9148 				5:  uint8(255),
   9149 				6:  uint8(253),
   9150 				7:  uint8(254),
   9151 				8:  uint8(255),
   9152 				9:  uint8(255),
   9153 				10: uint8(255),
   9154 			},
   9155 		},
   9156 		1: {
   9157 			0: {
   9158 				0:  uint8(255),
   9159 				1:  uint8(254),
   9160 				2:  uint8(255),
   9161 				3:  uint8(255),
   9162 				4:  uint8(255),
   9163 				5:  uint8(255),
   9164 				6:  uint8(255),
   9165 				7:  uint8(255),
   9166 				8:  uint8(255),
   9167 				9:  uint8(255),
   9168 				10: uint8(255),
   9169 			},
   9170 			1: {
   9171 				0:  uint8(223),
   9172 				1:  uint8(254),
   9173 				2:  uint8(254),
   9174 				3:  uint8(255),
   9175 				4:  uint8(255),
   9176 				5:  uint8(255),
   9177 				6:  uint8(255),
   9178 				7:  uint8(255),
   9179 				8:  uint8(255),
   9180 				9:  uint8(255),
   9181 				10: uint8(255),
   9182 			},
   9183 			2: {
   9184 				0:  uint8(238),
   9185 				1:  uint8(253),
   9186 				2:  uint8(254),
   9187 				3:  uint8(254),
   9188 				4:  uint8(255),
   9189 				5:  uint8(255),
   9190 				6:  uint8(255),
   9191 				7:  uint8(255),
   9192 				8:  uint8(255),
   9193 				9:  uint8(255),
   9194 				10: uint8(255),
   9195 			},
   9196 		},
   9197 		2: {
   9198 			0: {
   9199 				0:  uint8(255),
   9200 				1:  uint8(248),
   9201 				2:  uint8(254),
   9202 				3:  uint8(255),
   9203 				4:  uint8(255),
   9204 				5:  uint8(255),
   9205 				6:  uint8(255),
   9206 				7:  uint8(255),
   9207 				8:  uint8(255),
   9208 				9:  uint8(255),
   9209 				10: uint8(255),
   9210 			},
   9211 			1: {
   9212 				0:  uint8(249),
   9213 				1:  uint8(254),
   9214 				2:  uint8(255),
   9215 				3:  uint8(255),
   9216 				4:  uint8(255),
   9217 				5:  uint8(255),
   9218 				6:  uint8(255),
   9219 				7:  uint8(255),
   9220 				8:  uint8(255),
   9221 				9:  uint8(255),
   9222 				10: uint8(255),
   9223 			},
   9224 			2: {
   9225 				0:  uint8(255),
   9226 				1:  uint8(255),
   9227 				2:  uint8(255),
   9228 				3:  uint8(255),
   9229 				4:  uint8(255),
   9230 				5:  uint8(255),
   9231 				6:  uint8(255),
   9232 				7:  uint8(255),
   9233 				8:  uint8(255),
   9234 				9:  uint8(255),
   9235 				10: uint8(255),
   9236 			},
   9237 		},
   9238 		3: {
   9239 			0: {
   9240 				0:  uint8(255),
   9241 				1:  uint8(253),
   9242 				2:  uint8(255),
   9243 				3:  uint8(255),
   9244 				4:  uint8(255),
   9245 				5:  uint8(255),
   9246 				6:  uint8(255),
   9247 				7:  uint8(255),
   9248 				8:  uint8(255),
   9249 				9:  uint8(255),
   9250 				10: uint8(255),
   9251 			},
   9252 			1: {
   9253 				0:  uint8(247),
   9254 				1:  uint8(254),
   9255 				2:  uint8(255),
   9256 				3:  uint8(255),
   9257 				4:  uint8(255),
   9258 				5:  uint8(255),
   9259 				6:  uint8(255),
   9260 				7:  uint8(255),
   9261 				8:  uint8(255),
   9262 				9:  uint8(255),
   9263 				10: uint8(255),
   9264 			},
   9265 			2: {
   9266 				0:  uint8(255),
   9267 				1:  uint8(255),
   9268 				2:  uint8(255),
   9269 				3:  uint8(255),
   9270 				4:  uint8(255),
   9271 				5:  uint8(255),
   9272 				6:  uint8(255),
   9273 				7:  uint8(255),
   9274 				8:  uint8(255),
   9275 				9:  uint8(255),
   9276 				10: uint8(255),
   9277 			},
   9278 		},
   9279 		4: {
   9280 			0: {
   9281 				0:  uint8(255),
   9282 				1:  uint8(253),
   9283 				2:  uint8(254),
   9284 				3:  uint8(255),
   9285 				4:  uint8(255),
   9286 				5:  uint8(255),
   9287 				6:  uint8(255),
   9288 				7:  uint8(255),
   9289 				8:  uint8(255),
   9290 				9:  uint8(255),
   9291 				10: uint8(255),
   9292 			},
   9293 			1: {
   9294 				0:  uint8(252),
   9295 				1:  uint8(255),
   9296 				2:  uint8(255),
   9297 				3:  uint8(255),
   9298 				4:  uint8(255),
   9299 				5:  uint8(255),
   9300 				6:  uint8(255),
   9301 				7:  uint8(255),
   9302 				8:  uint8(255),
   9303 				9:  uint8(255),
   9304 				10: uint8(255),
   9305 			},
   9306 			2: {
   9307 				0:  uint8(255),
   9308 				1:  uint8(255),
   9309 				2:  uint8(255),
   9310 				3:  uint8(255),
   9311 				4:  uint8(255),
   9312 				5:  uint8(255),
   9313 				6:  uint8(255),
   9314 				7:  uint8(255),
   9315 				8:  uint8(255),
   9316 				9:  uint8(255),
   9317 				10: uint8(255),
   9318 			},
   9319 		},
   9320 		5: {
   9321 			0: {
   9322 				0:  uint8(255),
   9323 				1:  uint8(254),
   9324 				2:  uint8(254),
   9325 				3:  uint8(255),
   9326 				4:  uint8(255),
   9327 				5:  uint8(255),
   9328 				6:  uint8(255),
   9329 				7:  uint8(255),
   9330 				8:  uint8(255),
   9331 				9:  uint8(255),
   9332 				10: uint8(255),
   9333 			},
   9334 			1: {
   9335 				0:  uint8(253),
   9336 				1:  uint8(255),
   9337 				2:  uint8(255),
   9338 				3:  uint8(255),
   9339 				4:  uint8(255),
   9340 				5:  uint8(255),
   9341 				6:  uint8(255),
   9342 				7:  uint8(255),
   9343 				8:  uint8(255),
   9344 				9:  uint8(255),
   9345 				10: uint8(255),
   9346 			},
   9347 			2: {
   9348 				0:  uint8(255),
   9349 				1:  uint8(255),
   9350 				2:  uint8(255),
   9351 				3:  uint8(255),
   9352 				4:  uint8(255),
   9353 				5:  uint8(255),
   9354 				6:  uint8(255),
   9355 				7:  uint8(255),
   9356 				8:  uint8(255),
   9357 				9:  uint8(255),
   9358 				10: uint8(255),
   9359 			},
   9360 		},
   9361 		6: {
   9362 			0: {
   9363 				0:  uint8(255),
   9364 				1:  uint8(254),
   9365 				2:  uint8(253),
   9366 				3:  uint8(255),
   9367 				4:  uint8(255),
   9368 				5:  uint8(255),
   9369 				6:  uint8(255),
   9370 				7:  uint8(255),
   9371 				8:  uint8(255),
   9372 				9:  uint8(255),
   9373 				10: uint8(255),
   9374 			},
   9375 			1: {
   9376 				0:  uint8(250),
   9377 				1:  uint8(255),
   9378 				2:  uint8(255),
   9379 				3:  uint8(255),
   9380 				4:  uint8(255),
   9381 				5:  uint8(255),
   9382 				6:  uint8(255),
   9383 				7:  uint8(255),
   9384 				8:  uint8(255),
   9385 				9:  uint8(255),
   9386 				10: uint8(255),
   9387 			},
   9388 			2: {
   9389 				0:  uint8(254),
   9390 				1:  uint8(255),
   9391 				2:  uint8(255),
   9392 				3:  uint8(255),
   9393 				4:  uint8(255),
   9394 				5:  uint8(255),
   9395 				6:  uint8(255),
   9396 				7:  uint8(255),
   9397 				8:  uint8(255),
   9398 				9:  uint8(255),
   9399 				10: uint8(255),
   9400 			},
   9401 		},
   9402 		7: {
   9403 			0: {
   9404 				0:  uint8(255),
   9405 				1:  uint8(255),
   9406 				2:  uint8(255),
   9407 				3:  uint8(255),
   9408 				4:  uint8(255),
   9409 				5:  uint8(255),
   9410 				6:  uint8(255),
   9411 				7:  uint8(255),
   9412 				8:  uint8(255),
   9413 				9:  uint8(255),
   9414 				10: uint8(255),
   9415 			},
   9416 			1: {
   9417 				0:  uint8(255),
   9418 				1:  uint8(255),
   9419 				2:  uint8(255),
   9420 				3:  uint8(255),
   9421 				4:  uint8(255),
   9422 				5:  uint8(255),
   9423 				6:  uint8(255),
   9424 				7:  uint8(255),
   9425 				8:  uint8(255),
   9426 				9:  uint8(255),
   9427 				10: uint8(255),
   9428 			},
   9429 			2: {
   9430 				0:  uint8(255),
   9431 				1:  uint8(255),
   9432 				2:  uint8(255),
   9433 				3:  uint8(255),
   9434 				4:  uint8(255),
   9435 				5:  uint8(255),
   9436 				6:  uint8(255),
   9437 				7:  uint8(255),
   9438 				8:  uint8(255),
   9439 				9:  uint8(255),
   9440 				10: uint8(255),
   9441 			},
   9442 		},
   9443 	},
   9444 	2: {
   9445 		0: {
   9446 			0: {
   9447 				0:  uint8(186),
   9448 				1:  uint8(251),
   9449 				2:  uint8(250),
   9450 				3:  uint8(255),
   9451 				4:  uint8(255),
   9452 				5:  uint8(255),
   9453 				6:  uint8(255),
   9454 				7:  uint8(255),
   9455 				8:  uint8(255),
   9456 				9:  uint8(255),
   9457 				10: uint8(255),
   9458 			},
   9459 			1: {
   9460 				0:  uint8(234),
   9461 				1:  uint8(251),
   9462 				2:  uint8(244),
   9463 				3:  uint8(254),
   9464 				4:  uint8(255),
   9465 				5:  uint8(255),
   9466 				6:  uint8(255),
   9467 				7:  uint8(255),
   9468 				8:  uint8(255),
   9469 				9:  uint8(255),
   9470 				10: uint8(255),
   9471 			},
   9472 			2: {
   9473 				0:  uint8(251),
   9474 				1:  uint8(251),
   9475 				2:  uint8(243),
   9476 				3:  uint8(253),
   9477 				4:  uint8(254),
   9478 				5:  uint8(255),
   9479 				6:  uint8(254),
   9480 				7:  uint8(255),
   9481 				8:  uint8(255),
   9482 				9:  uint8(255),
   9483 				10: uint8(255),
   9484 			},
   9485 		},
   9486 		1: {
   9487 			0: {
   9488 				0:  uint8(255),
   9489 				1:  uint8(253),
   9490 				2:  uint8(254),
   9491 				3:  uint8(255),
   9492 				4:  uint8(255),
   9493 				5:  uint8(255),
   9494 				6:  uint8(255),
   9495 				7:  uint8(255),
   9496 				8:  uint8(255),
   9497 				9:  uint8(255),
   9498 				10: uint8(255),
   9499 			},
   9500 			1: {
   9501 				0:  uint8(236),
   9502 				1:  uint8(253),
   9503 				2:  uint8(254),
   9504 				3:  uint8(255),
   9505 				4:  uint8(255),
   9506 				5:  uint8(255),
   9507 				6:  uint8(255),
   9508 				7:  uint8(255),
   9509 				8:  uint8(255),
   9510 				9:  uint8(255),
   9511 				10: uint8(255),
   9512 			},
   9513 			2: {
   9514 				0:  uint8(251),
   9515 				1:  uint8(253),
   9516 				2:  uint8(253),
   9517 				3:  uint8(254),
   9518 				4:  uint8(254),
   9519 				5:  uint8(255),
   9520 				6:  uint8(255),
   9521 				7:  uint8(255),
   9522 				8:  uint8(255),
   9523 				9:  uint8(255),
   9524 				10: uint8(255),
   9525 			},
   9526 		},
   9527 		2: {
   9528 			0: {
   9529 				0:  uint8(255),
   9530 				1:  uint8(254),
   9531 				2:  uint8(254),
   9532 				3:  uint8(255),
   9533 				4:  uint8(255),
   9534 				5:  uint8(255),
   9535 				6:  uint8(255),
   9536 				7:  uint8(255),
   9537 				8:  uint8(255),
   9538 				9:  uint8(255),
   9539 				10: uint8(255),
   9540 			},
   9541 			1: {
   9542 				0:  uint8(254),
   9543 				1:  uint8(254),
   9544 				2:  uint8(254),
   9545 				3:  uint8(255),
   9546 				4:  uint8(255),
   9547 				5:  uint8(255),
   9548 				6:  uint8(255),
   9549 				7:  uint8(255),
   9550 				8:  uint8(255),
   9551 				9:  uint8(255),
   9552 				10: uint8(255),
   9553 			},
   9554 			2: {
   9555 				0:  uint8(255),
   9556 				1:  uint8(255),
   9557 				2:  uint8(255),
   9558 				3:  uint8(255),
   9559 				4:  uint8(255),
   9560 				5:  uint8(255),
   9561 				6:  uint8(255),
   9562 				7:  uint8(255),
   9563 				8:  uint8(255),
   9564 				9:  uint8(255),
   9565 				10: uint8(255),
   9566 			},
   9567 		},
   9568 		3: {
   9569 			0: {
   9570 				0:  uint8(255),
   9571 				1:  uint8(254),
   9572 				2:  uint8(255),
   9573 				3:  uint8(255),
   9574 				4:  uint8(255),
   9575 				5:  uint8(255),
   9576 				6:  uint8(255),
   9577 				7:  uint8(255),
   9578 				8:  uint8(255),
   9579 				9:  uint8(255),
   9580 				10: uint8(255),
   9581 			},
   9582 			1: {
   9583 				0:  uint8(254),
   9584 				1:  uint8(254),
   9585 				2:  uint8(255),
   9586 				3:  uint8(255),
   9587 				4:  uint8(255),
   9588 				5:  uint8(255),
   9589 				6:  uint8(255),
   9590 				7:  uint8(255),
   9591 				8:  uint8(255),
   9592 				9:  uint8(255),
   9593 				10: uint8(255),
   9594 			},
   9595 			2: {
   9596 				0:  uint8(254),
   9597 				1:  uint8(255),
   9598 				2:  uint8(255),
   9599 				3:  uint8(255),
   9600 				4:  uint8(255),
   9601 				5:  uint8(255),
   9602 				6:  uint8(255),
   9603 				7:  uint8(255),
   9604 				8:  uint8(255),
   9605 				9:  uint8(255),
   9606 				10: uint8(255),
   9607 			},
   9608 		},
   9609 		4: {
   9610 			0: {
   9611 				0:  uint8(255),
   9612 				1:  uint8(255),
   9613 				2:  uint8(255),
   9614 				3:  uint8(255),
   9615 				4:  uint8(255),
   9616 				5:  uint8(255),
   9617 				6:  uint8(255),
   9618 				7:  uint8(255),
   9619 				8:  uint8(255),
   9620 				9:  uint8(255),
   9621 				10: uint8(255),
   9622 			},
   9623 			1: {
   9624 				0:  uint8(254),
   9625 				1:  uint8(255),
   9626 				2:  uint8(255),
   9627 				3:  uint8(255),
   9628 				4:  uint8(255),
   9629 				5:  uint8(255),
   9630 				6:  uint8(255),
   9631 				7:  uint8(255),
   9632 				8:  uint8(255),
   9633 				9:  uint8(255),
   9634 				10: uint8(255),
   9635 			},
   9636 			2: {
   9637 				0:  uint8(255),
   9638 				1:  uint8(255),
   9639 				2:  uint8(255),
   9640 				3:  uint8(255),
   9641 				4:  uint8(255),
   9642 				5:  uint8(255),
   9643 				6:  uint8(255),
   9644 				7:  uint8(255),
   9645 				8:  uint8(255),
   9646 				9:  uint8(255),
   9647 				10: uint8(255),
   9648 			},
   9649 		},
   9650 		5: {
   9651 			0: {
   9652 				0:  uint8(255),
   9653 				1:  uint8(255),
   9654 				2:  uint8(255),
   9655 				3:  uint8(255),
   9656 				4:  uint8(255),
   9657 				5:  uint8(255),
   9658 				6:  uint8(255),
   9659 				7:  uint8(255),
   9660 				8:  uint8(255),
   9661 				9:  uint8(255),
   9662 				10: uint8(255),
   9663 			},
   9664 			1: {
   9665 				0:  uint8(255),
   9666 				1:  uint8(255),
   9667 				2:  uint8(255),
   9668 				3:  uint8(255),
   9669 				4:  uint8(255),
   9670 				5:  uint8(255),
   9671 				6:  uint8(255),
   9672 				7:  uint8(255),
   9673 				8:  uint8(255),
   9674 				9:  uint8(255),
   9675 				10: uint8(255),
   9676 			},
   9677 			2: {
   9678 				0:  uint8(255),
   9679 				1:  uint8(255),
   9680 				2:  uint8(255),
   9681 				3:  uint8(255),
   9682 				4:  uint8(255),
   9683 				5:  uint8(255),
   9684 				6:  uint8(255),
   9685 				7:  uint8(255),
   9686 				8:  uint8(255),
   9687 				9:  uint8(255),
   9688 				10: uint8(255),
   9689 			},
   9690 		},
   9691 		6: {
   9692 			0: {
   9693 				0:  uint8(255),
   9694 				1:  uint8(255),
   9695 				2:  uint8(255),
   9696 				3:  uint8(255),
   9697 				4:  uint8(255),
   9698 				5:  uint8(255),
   9699 				6:  uint8(255),
   9700 				7:  uint8(255),
   9701 				8:  uint8(255),
   9702 				9:  uint8(255),
   9703 				10: uint8(255),
   9704 			},
   9705 			1: {
   9706 				0:  uint8(255),
   9707 				1:  uint8(255),
   9708 				2:  uint8(255),
   9709 				3:  uint8(255),
   9710 				4:  uint8(255),
   9711 				5:  uint8(255),
   9712 				6:  uint8(255),
   9713 				7:  uint8(255),
   9714 				8:  uint8(255),
   9715 				9:  uint8(255),
   9716 				10: uint8(255),
   9717 			},
   9718 			2: {
   9719 				0:  uint8(255),
   9720 				1:  uint8(255),
   9721 				2:  uint8(255),
   9722 				3:  uint8(255),
   9723 				4:  uint8(255),
   9724 				5:  uint8(255),
   9725 				6:  uint8(255),
   9726 				7:  uint8(255),
   9727 				8:  uint8(255),
   9728 				9:  uint8(255),
   9729 				10: uint8(255),
   9730 			},
   9731 		},
   9732 		7: {
   9733 			0: {
   9734 				0:  uint8(255),
   9735 				1:  uint8(255),
   9736 				2:  uint8(255),
   9737 				3:  uint8(255),
   9738 				4:  uint8(255),
   9739 				5:  uint8(255),
   9740 				6:  uint8(255),
   9741 				7:  uint8(255),
   9742 				8:  uint8(255),
   9743 				9:  uint8(255),
   9744 				10: uint8(255),
   9745 			},
   9746 			1: {
   9747 				0:  uint8(255),
   9748 				1:  uint8(255),
   9749 				2:  uint8(255),
   9750 				3:  uint8(255),
   9751 				4:  uint8(255),
   9752 				5:  uint8(255),
   9753 				6:  uint8(255),
   9754 				7:  uint8(255),
   9755 				8:  uint8(255),
   9756 				9:  uint8(255),
   9757 				10: uint8(255),
   9758 			},
   9759 			2: {
   9760 				0:  uint8(255),
   9761 				1:  uint8(255),
   9762 				2:  uint8(255),
   9763 				3:  uint8(255),
   9764 				4:  uint8(255),
   9765 				5:  uint8(255),
   9766 				6:  uint8(255),
   9767 				7:  uint8(255),
   9768 				8:  uint8(255),
   9769 				9:  uint8(255),
   9770 				10: uint8(255),
   9771 			},
   9772 		},
   9773 	},
   9774 	3: {
   9775 		0: {
   9776 			0: {
   9777 				0:  uint8(248),
   9778 				1:  uint8(255),
   9779 				2:  uint8(255),
   9780 				3:  uint8(255),
   9781 				4:  uint8(255),
   9782 				5:  uint8(255),
   9783 				6:  uint8(255),
   9784 				7:  uint8(255),
   9785 				8:  uint8(255),
   9786 				9:  uint8(255),
   9787 				10: uint8(255),
   9788 			},
   9789 			1: {
   9790 				0:  uint8(250),
   9791 				1:  uint8(254),
   9792 				2:  uint8(252),
   9793 				3:  uint8(254),
   9794 				4:  uint8(255),
   9795 				5:  uint8(255),
   9796 				6:  uint8(255),
   9797 				7:  uint8(255),
   9798 				8:  uint8(255),
   9799 				9:  uint8(255),
   9800 				10: uint8(255),
   9801 			},
   9802 			2: {
   9803 				0:  uint8(248),
   9804 				1:  uint8(254),
   9805 				2:  uint8(249),
   9806 				3:  uint8(253),
   9807 				4:  uint8(255),
   9808 				5:  uint8(255),
   9809 				6:  uint8(255),
   9810 				7:  uint8(255),
   9811 				8:  uint8(255),
   9812 				9:  uint8(255),
   9813 				10: uint8(255),
   9814 			},
   9815 		},
   9816 		1: {
   9817 			0: {
   9818 				0:  uint8(255),
   9819 				1:  uint8(253),
   9820 				2:  uint8(253),
   9821 				3:  uint8(255),
   9822 				4:  uint8(255),
   9823 				5:  uint8(255),
   9824 				6:  uint8(255),
   9825 				7:  uint8(255),
   9826 				8:  uint8(255),
   9827 				9:  uint8(255),
   9828 				10: uint8(255),
   9829 			},
   9830 			1: {
   9831 				0:  uint8(246),
   9832 				1:  uint8(253),
   9833 				2:  uint8(253),
   9834 				3:  uint8(255),
   9835 				4:  uint8(255),
   9836 				5:  uint8(255),
   9837 				6:  uint8(255),
   9838 				7:  uint8(255),
   9839 				8:  uint8(255),
   9840 				9:  uint8(255),
   9841 				10: uint8(255),
   9842 			},
   9843 			2: {
   9844 				0:  uint8(252),
   9845 				1:  uint8(254),
   9846 				2:  uint8(251),
   9847 				3:  uint8(254),
   9848 				4:  uint8(254),
   9849 				5:  uint8(255),
   9850 				6:  uint8(255),
   9851 				7:  uint8(255),
   9852 				8:  uint8(255),
   9853 				9:  uint8(255),
   9854 				10: uint8(255),
   9855 			},
   9856 		},
   9857 		2: {
   9858 			0: {
   9859 				0:  uint8(255),
   9860 				1:  uint8(254),
   9861 				2:  uint8(252),
   9862 				3:  uint8(255),
   9863 				4:  uint8(255),
   9864 				5:  uint8(255),
   9865 				6:  uint8(255),
   9866 				7:  uint8(255),
   9867 				8:  uint8(255),
   9868 				9:  uint8(255),
   9869 				10: uint8(255),
   9870 			},
   9871 			1: {
   9872 				0:  uint8(248),
   9873 				1:  uint8(254),
   9874 				2:  uint8(253),
   9875 				3:  uint8(255),
   9876 				4:  uint8(255),
   9877 				5:  uint8(255),
   9878 				6:  uint8(255),
   9879 				7:  uint8(255),
   9880 				8:  uint8(255),
   9881 				9:  uint8(255),
   9882 				10: uint8(255),
   9883 			},
   9884 			2: {
   9885 				0:  uint8(253),
   9886 				1:  uint8(255),
   9887 				2:  uint8(254),
   9888 				3:  uint8(254),
   9889 				4:  uint8(255),
   9890 				5:  uint8(255),
   9891 				6:  uint8(255),
   9892 				7:  uint8(255),
   9893 				8:  uint8(255),
   9894 				9:  uint8(255),
   9895 				10: uint8(255),
   9896 			},
   9897 		},
   9898 		3: {
   9899 			0: {
   9900 				0:  uint8(255),
   9901 				1:  uint8(251),
   9902 				2:  uint8(254),
   9903 				3:  uint8(255),
   9904 				4:  uint8(255),
   9905 				5:  uint8(255),
   9906 				6:  uint8(255),
   9907 				7:  uint8(255),
   9908 				8:  uint8(255),
   9909 				9:  uint8(255),
   9910 				10: uint8(255),
   9911 			},
   9912 			1: {
   9913 				0:  uint8(245),
   9914 				1:  uint8(251),
   9915 				2:  uint8(254),
   9916 				3:  uint8(255),
   9917 				4:  uint8(255),
   9918 				5:  uint8(255),
   9919 				6:  uint8(255),
   9920 				7:  uint8(255),
   9921 				8:  uint8(255),
   9922 				9:  uint8(255),
   9923 				10: uint8(255),
   9924 			},
   9925 			2: {
   9926 				0:  uint8(253),
   9927 				1:  uint8(253),
   9928 				2:  uint8(254),
   9929 				3:  uint8(255),
   9930 				4:  uint8(255),
   9931 				5:  uint8(255),
   9932 				6:  uint8(255),
   9933 				7:  uint8(255),
   9934 				8:  uint8(255),
   9935 				9:  uint8(255),
   9936 				10: uint8(255),
   9937 			},
   9938 		},
   9939 		4: {
   9940 			0: {
   9941 				0:  uint8(255),
   9942 				1:  uint8(251),
   9943 				2:  uint8(253),
   9944 				3:  uint8(255),
   9945 				4:  uint8(255),
   9946 				5:  uint8(255),
   9947 				6:  uint8(255),
   9948 				7:  uint8(255),
   9949 				8:  uint8(255),
   9950 				9:  uint8(255),
   9951 				10: uint8(255),
   9952 			},
   9953 			1: {
   9954 				0:  uint8(252),
   9955 				1:  uint8(253),
   9956 				2:  uint8(254),
   9957 				3:  uint8(255),
   9958 				4:  uint8(255),
   9959 				5:  uint8(255),
   9960 				6:  uint8(255),
   9961 				7:  uint8(255),
   9962 				8:  uint8(255),
   9963 				9:  uint8(255),
   9964 				10: uint8(255),
   9965 			},
   9966 			2: {
   9967 				0:  uint8(255),
   9968 				1:  uint8(254),
   9969 				2:  uint8(255),
   9970 				3:  uint8(255),
   9971 				4:  uint8(255),
   9972 				5:  uint8(255),
   9973 				6:  uint8(255),
   9974 				7:  uint8(255),
   9975 				8:  uint8(255),
   9976 				9:  uint8(255),
   9977 				10: uint8(255),
   9978 			},
   9979 		},
   9980 		5: {
   9981 			0: {
   9982 				0:  uint8(255),
   9983 				1:  uint8(252),
   9984 				2:  uint8(255),
   9985 				3:  uint8(255),
   9986 				4:  uint8(255),
   9987 				5:  uint8(255),
   9988 				6:  uint8(255),
   9989 				7:  uint8(255),
   9990 				8:  uint8(255),
   9991 				9:  uint8(255),
   9992 				10: uint8(255),
   9993 			},
   9994 			1: {
   9995 				0:  uint8(249),
   9996 				1:  uint8(255),
   9997 				2:  uint8(254),
   9998 				3:  uint8(255),
   9999 				4:  uint8(255),
  10000 				5:  uint8(255),
  10001 				6:  uint8(255),
  10002 				7:  uint8(255),
  10003 				8:  uint8(255),
  10004 				9:  uint8(255),
  10005 				10: uint8(255),
  10006 			},
  10007 			2: {
  10008 				0:  uint8(255),
  10009 				1:  uint8(255),
  10010 				2:  uint8(254),
  10011 				3:  uint8(255),
  10012 				4:  uint8(255),
  10013 				5:  uint8(255),
  10014 				6:  uint8(255),
  10015 				7:  uint8(255),
  10016 				8:  uint8(255),
  10017 				9:  uint8(255),
  10018 				10: uint8(255),
  10019 			},
  10020 		},
  10021 		6: {
  10022 			0: {
  10023 				0:  uint8(255),
  10024 				1:  uint8(255),
  10025 				2:  uint8(253),
  10026 				3:  uint8(255),
  10027 				4:  uint8(255),
  10028 				5:  uint8(255),
  10029 				6:  uint8(255),
  10030 				7:  uint8(255),
  10031 				8:  uint8(255),
  10032 				9:  uint8(255),
  10033 				10: uint8(255),
  10034 			},
  10035 			1: {
  10036 				0:  uint8(250),
  10037 				1:  uint8(255),
  10038 				2:  uint8(255),
  10039 				3:  uint8(255),
  10040 				4:  uint8(255),
  10041 				5:  uint8(255),
  10042 				6:  uint8(255),
  10043 				7:  uint8(255),
  10044 				8:  uint8(255),
  10045 				9:  uint8(255),
  10046 				10: uint8(255),
  10047 			},
  10048 			2: {
  10049 				0:  uint8(255),
  10050 				1:  uint8(255),
  10051 				2:  uint8(255),
  10052 				3:  uint8(255),
  10053 				4:  uint8(255),
  10054 				5:  uint8(255),
  10055 				6:  uint8(255),
  10056 				7:  uint8(255),
  10057 				8:  uint8(255),
  10058 				9:  uint8(255),
  10059 				10: uint8(255),
  10060 			},
  10061 		},
  10062 		7: {
  10063 			0: {
  10064 				0:  uint8(255),
  10065 				1:  uint8(255),
  10066 				2:  uint8(255),
  10067 				3:  uint8(255),
  10068 				4:  uint8(255),
  10069 				5:  uint8(255),
  10070 				6:  uint8(255),
  10071 				7:  uint8(255),
  10072 				8:  uint8(255),
  10073 				9:  uint8(255),
  10074 				10: uint8(255),
  10075 			},
  10076 			1: {
  10077 				0:  uint8(254),
  10078 				1:  uint8(255),
  10079 				2:  uint8(255),
  10080 				3:  uint8(255),
  10081 				4:  uint8(255),
  10082 				5:  uint8(255),
  10083 				6:  uint8(255),
  10084 				7:  uint8(255),
  10085 				8:  uint8(255),
  10086 				9:  uint8(255),
  10087 				10: uint8(255),
  10088 			},
  10089 			2: {
  10090 				0:  uint8(255),
  10091 				1:  uint8(255),
  10092 				2:  uint8(255),
  10093 				3:  uint8(255),
  10094 				4:  uint8(255),
  10095 				5:  uint8(255),
  10096 				6:  uint8(255),
  10097 				7:  uint8(255),
  10098 				8:  uint8(255),
  10099 				9:  uint8(255),
  10100 				10: uint8(255),
  10101 			},
  10102 		},
  10103 	},
  10104 }
  10105 
  10106 // Paragraph 9.9
  10107 
  10108 var kBands = [17]uint8_t{
  10109 	1:  uint8(1),
  10110 	2:  uint8(2),
  10111 	3:  uint8(3),
  10112 	4:  uint8(6),
  10113 	5:  uint8(4),
  10114 	6:  uint8(5),
  10115 	7:  uint8(6),
  10116 	8:  uint8(6),
  10117 	9:  uint8(6),
  10118 	10: uint8(6),
  10119 	11: uint8(6),
  10120 	12: uint8(6),
  10121 	13: uint8(6),
  10122 	14: uint8(6),
  10123 	15: uint8(7),
  10124 }
  10125 
  10126 func VP8ParseProba(tls *libc.TLS, br2 uintptr, dec uintptr) {
  10127 	bp := tls.Alloc(16)
  10128 	defer tls.Free(16)
  10129 	var b, bit, c, p, pos, shift, t, v, v10, v12 int32
  10130 	var bits bit_t
  10131 	var proba, v6, v7 uintptr
  10132 	var range1, split, value range_t
  10133 	var v5 uint32
  10134 	var v8 uint64_t
  10135 	var _ /* in_bits at bp+0 */ lbit_t
  10136 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, bit, bits, c, p, pos, proba, range1, shift, split, t, v, value, v10, v12, v5, v6, v7, v8
  10137 	proba = dec + 1192
  10138 	t = 0
  10139 	for {
  10140 		if !(t < int32(NUM_TYPES)) {
  10141 			break
  10142 		}
  10143 		b = 0
  10144 		for {
  10145 			if !(b < int32(NUM_BANDS)) {
  10146 				break
  10147 			}
  10148 			c = 0
  10149 			for {
  10150 				if !(c < int32(NUM_CTX)) {
  10151 					break
  10152 				}
  10153 				p = 0
  10154 				for {
  10155 					if !(p < int32(NUM_PROBAS)) {
  10156 						break
  10157 					}
  10158 					v6 = br2
  10159 					range1 = (*VP8BitReader)(unsafe.Pointer(v6)).Frange1
  10160 					if (*VP8BitReader)(unsafe.Pointer(v6)).Fbits < libc.Int32FromInt32(0) {
  10161 						v7 = v6
  10162 						if (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf_max {
  10163 							libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v7)).Fbuf, uint64(8))
  10164 							**(**uintptr)(__ccgo_up(v7 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10165 							v8 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10166 							goto _9
  10167 						_9:
  10168 							bits = v8
  10169 							bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10170 							(*VP8BitReader)(unsafe.Pointer(v7)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v7)).Fvalue<<libc.Int32FromInt32(BITS)
  10171 							**(**int32)(__ccgo_up(v7 + 12)) += int32(BITS)
  10172 						} else {
  10173 							VP8LoadFinalBytes(tls, v7)
  10174 						}
  10175 					}
  10176 					pos = (*VP8BitReader)(unsafe.Pointer(v6)).Fbits
  10177 					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)
  10178 					value = uint32((*VP8BitReader)(unsafe.Pointer(v6)).Fvalue >> pos)
  10179 					bit = libc.BoolInt32(value > split)
  10180 					if bit != 0 {
  10181 						range1 = range1 - split
  10182 						**(**bit_t)(__ccgo_up(v6)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10183 					} else {
  10184 						range1 = split + uint32(1)
  10185 					}
  10186 					v10 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10187 					goto _11
  10188 				_11:
  10189 					shift = int32(7) ^ v10
  10190 					range1 = range1 << libc.Uint32FromInt32(shift)
  10191 					**(**int32)(__ccgo_up(v6 + 12)) -= shift
  10192 					(*VP8BitReader)(unsafe.Pointer(v6)).Frange1 = range1 - uint32(1)
  10193 					v12 = bit
  10194 					goto _13
  10195 				_13:
  10196 					if v12 != 0 {
  10197 						v5 = VP8GetValue(tls, br2, int32(8))
  10198 					} else {
  10199 						v5 = uint32(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  10200 					}
  10201 					v = libc.Int32FromUint32(v5)
  10202 					**(**uint8_t)(__ccgo_up(proba + 3 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = libc.Uint8FromInt32(v)
  10203 					goto _4
  10204 				_4:
  10205 					;
  10206 					p = p + 1
  10207 				}
  10208 				goto _3
  10209 			_3:
  10210 				;
  10211 				c = c + 1
  10212 			}
  10213 			goto _2
  10214 		_2:
  10215 			;
  10216 			b = b + 1
  10217 		}
  10218 		b = 0
  10219 		for {
  10220 			if !(b < libc.Int32FromInt32(16)+libc.Int32FromInt32(1)) {
  10221 				break
  10222 			}
  10223 			**(**uintptr)(__ccgo_up(proba + 1064 + uintptr(t)*136 + uintptr(b)*8)) = proba + 3 + uintptr(t)*264 + uintptr(kBands[b])*33
  10224 			goto _14
  10225 		_14:
  10226 			;
  10227 			b = b + 1
  10228 		}
  10229 		goto _1
  10230 	_1:
  10231 		;
  10232 		t = t + 1
  10233 	}
  10234 	(*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba = libc.Int32FromUint32(VP8GetValue(tls, br2, int32(1)))
  10235 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  10236 		(*VP8Decoder)(unsafe.Pointer(dec)).Fskip_p = uint8(VP8GetValue(tls, br2, int32(8)))
  10237 	}
  10238 }
  10239 
  10240 var kHashMul7 = uint32(0x1e35a7bd)
  10241 
  10242 // Copyright 2010 Google Inc. All Rights Reserved.
  10243 //
  10244 // Use of this source code is governed by a BSD-style license
  10245 // that can be found in the COPYING file in the root of the source
  10246 // tree. An additional intellectual property rights grant can be found
  10247 // in the file PATENTS. All contributing project authors may
  10248 // be found in the AUTHORS file in the root of the source tree.
  10249 // -----------------------------------------------------------------------------
  10250 //
  10251 // Boolean decoder
  10252 //
  10253 // Author: Skal (pascal.massimino@gmail.com)
  10254 //         Vikas Arora (vikaas.arora@gmail.com)
  10255 
  10256 // Copyright 2011 Google Inc. All Rights Reserved.
  10257 //
  10258 // Use of this source code is governed by a BSD-style license
  10259 // that can be found in the COPYING file in the root of the source
  10260 // tree. An additional intellectual property rights grant can be found
  10261 // in the file PATENTS. All contributing project authors may
  10262 // be found in the AUTHORS file in the root of the source tree.
  10263 // -----------------------------------------------------------------------------
  10264 //
  10265 // Multi-threaded worker
  10266 //
  10267 // Author: Skal (pascal.massimino@gmail.com)
  10268 
  10269 // Copyright 2012 Google Inc. All Rights Reserved.
  10270 //
  10271 // Use of this source code is governed by a BSD-style license
  10272 // that can be found in the COPYING file in the root of the source
  10273 // tree. An additional intellectual property rights grant can be found
  10274 // in the file PATENTS. All contributing project authors may
  10275 // be found in the AUTHORS file in the root of the source tree.
  10276 // -----------------------------------------------------------------------------
  10277 //
  10278 // Misc. common utility functions
  10279 //
  10280 // Authors: Skal (pascal.massimino@gmail.com)
  10281 //          Urvang (urvang@google.com)
  10282 
  10283 // Copyright 2010 Google Inc. All Rights Reserved.
  10284 //
  10285 // Use of this source code is governed by a BSD-style license
  10286 // that can be found in the COPYING file in the root of the source
  10287 // tree. An additional intellectual property rights grant can be found
  10288 // in the file PATENTS. All contributing project authors may
  10289 // be found in the AUTHORS file in the root of the source tree.
  10290 // -----------------------------------------------------------------------------
  10291 //
  10292 //  Main decoding functions for WebP images.
  10293 //
  10294 // Author: Skal (pascal.massimino@gmail.com)
  10295 
  10296 // Copyright 2012 Google Inc. All Rights Reserved.
  10297 //
  10298 // Use of this source code is governed by a BSD-style license
  10299 // that can be found in the COPYING file in the root of the source
  10300 // tree. An additional intellectual property rights grant can be found
  10301 // in the file PATENTS. All contributing project authors may
  10302 // be found in the AUTHORS file in the root of the source tree.
  10303 // -----------------------------------------------------------------------------
  10304 //
  10305 //  Internal header for constants related to WebP file format.
  10306 //
  10307 // Author: Urvang (urvang@google.com)
  10308 
  10309 // Copyright 2010 Google Inc. All Rights Reserved.
  10310 //
  10311 // Use of this source code is governed by a BSD-style license
  10312 // that can be found in the COPYING file in the root of the source
  10313 // tree. An additional intellectual property rights grant can be found
  10314 // in the file PATENTS. All contributing project authors may
  10315 // be found in the AUTHORS file in the root of the source tree.
  10316 // -----------------------------------------------------------------------------
  10317 //
  10318 //  Common types + memory wrappers
  10319 //
  10320 // Author: Skal (pascal.massimino@gmail.com)
  10321 
  10322 //------------------------------------------------------------------------------
  10323 
  10324 func WebPGetDecoderVersion(tls *libc.TLS) (r int32) {
  10325 	return libc.Int32FromInt32(DEC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(DEC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(DEC_REV_VERSION)
  10326 }
  10327 
  10328 //------------------------------------------------------------------------------
  10329 // Signature and pointer-to-function for GetCoeffs() variants below.
  10330 
  10331 type GetCoeffsFunc = uintptr
  10332 
  10333 var GetCoeffs = uintptr(0)
  10334 
  10335 func init() {
  10336 	p := unsafe.Pointer(&GetCoeffs)
  10337 	*(*uintptr)(unsafe.Add(p, 0)) = libc.UintptrFromInt32(0)
  10338 }
  10339 
  10340 //------------------------------------------------------------------------------
  10341 // VP8Decoder
  10342 
  10343 func SetOk(tls *libc.TLS, dec uintptr) {
  10344 	(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  10345 	(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = __ccgo_ts + 154
  10346 }
  10347 
  10348 func VP8InitIoInternal(tls *libc.TLS, io uintptr, version int32) (r int32) {
  10349 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  10350 		return 0 // mismatch error
  10351 	}
  10352 	if io != libc.UintptrFromInt32(0) {
  10353 		libc.Xmemset(tls, io, 0, uint64(160))
  10354 	}
  10355 	return int32(1)
  10356 }
  10357 
  10358 func VP8New(tls *libc.TLS) (r uintptr) {
  10359 	var dec uintptr
  10360 	_ = dec
  10361 	dec = WebPSafeCalloc(tls, uint64(1), uint64(3024))
  10362 	if dec != libc.UintptrFromInt32(0) {
  10363 		SetOk(tls, dec)
  10364 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, dec+152)
  10365 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10366 		(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = uint32(0)
  10367 		InitGetCoeffs(tls)
  10368 	}
  10369 	return dec
  10370 }
  10371 
  10372 func VP8Status(tls *libc.TLS, dec uintptr) (r VP8StatusCode1) {
  10373 	if !(dec != 0) {
  10374 		return int32(VP8_STATUS_INVALID_PARAM)
  10375 	}
  10376 	return (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  10377 }
  10378 
  10379 func VP8StatusMessage(tls *libc.TLS, dec uintptr) (r uintptr) {
  10380 	if dec == libc.UintptrFromInt32(0) {
  10381 		return __ccgo_ts + 157
  10382 	}
  10383 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg != 0) {
  10384 		return __ccgo_ts + 154
  10385 	}
  10386 	return (*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg
  10387 }
  10388 
  10389 func VP8Delete(tls *libc.TLS, dec uintptr) {
  10390 	if dec != libc.UintptrFromInt32(0) {
  10391 		VP8Clear(tls, dec)
  10392 		WebPSafeFree(tls, dec)
  10393 	}
  10394 }
  10395 
  10396 func VP8SetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1, msg uintptr) (r int32) {
  10397 	// VP8_STATUS_SUSPENDED is only meaningful in incremental decoding.
  10398 	// The oldest error reported takes precedence over the new one.
  10399 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) {
  10400 		(*VP8Decoder)(unsafe.Pointer(dec)).Fstatus = error1
  10401 		(*VP8Decoder)(unsafe.Pointer(dec)).Ferror_msg = msg
  10402 		(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  10403 	}
  10404 	return 0
  10405 }
  10406 
  10407 //------------------------------------------------------------------------------
  10408 
  10409 func VP8CheckSignature(tls *libc.TLS, data uintptr, data_size size_t) (r int32) {
  10410 	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))
  10411 }
  10412 
  10413 func VP8GetInfo(tls *libc.TLS, data uintptr, data_size size_t, chunk_size size_t, width uintptr, height uintptr) (r int32) {
  10414 	var bits uint32_t
  10415 	var h, key_frame, w int32
  10416 	_, _, _, _ = bits, h, key_frame, w
  10417 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8_FRAME_HEADER_SIZE) {
  10418 		return 0 // not enough data
  10419 	}
  10420 	// check signature
  10421 	if !(VP8CheckSignature(tls, data+uintptr(3), data_size-uint64(3)) != 0) {
  10422 		return 0 // Wrong signature.
  10423 	} else {
  10424 		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))
  10425 		key_frame = libc.BoolInt32(!(bits&libc.Uint32FromInt32(1) != 0))
  10426 		w = (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 7)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 6)))) & int32(0x3fff)
  10427 		h = (libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 9)))<<int32(8) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + 8)))) & int32(0x3fff)
  10428 		if !(key_frame != 0) { // Not a keyframe.
  10429 			return 0
  10430 		}
  10431 		if bits>>libc.Int32FromInt32(1)&uint32(7) > uint32(3) {
  10432 			return 0 // unknown profile
  10433 		}
  10434 		if !(bits>>libc.Int32FromInt32(4)&libc.Uint32FromInt32(1) != 0) {
  10435 			return 0 // first frame is invisible!
  10436 		}
  10437 		if uint64(bits>>libc.Int32FromInt32(5)) >= chunk_size { // partition_length
  10438 			return 0 // inconsistent size information.
  10439 		}
  10440 		if w == 0 || h == 0 {
  10441 			return 0 // We don't support both width and height to be zero.
  10442 		}
  10443 		if width != 0 {
  10444 			**(**int32)(__ccgo_up(width)) = w
  10445 		}
  10446 		if height != 0 {
  10447 			**(**int32)(__ccgo_up(height)) = h
  10448 		}
  10449 		return int32(1)
  10450 	}
  10451 	return r
  10452 }
  10453 
  10454 //------------------------------------------------------------------------------
  10455 // Header parsing
  10456 
  10457 func ResetSegmentHeader(tls *libc.TLS, hdr uintptr) {
  10458 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = 0
  10459 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10460 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = int32(1)
  10461 	libc.Xmemset(tls, hdr+12, 0, uint64(4))
  10462 	libc.Xmemset(tls, hdr+16, 0, uint64(4))
  10463 }
  10464 
  10465 // C documentation
  10466 //
  10467 //	// Paragraph 9.3
  10468 func ParseSegmentHeader(tls *libc.TLS, br uintptr, hdr uintptr, proba uintptr) (r int32) {
  10469 	var s, s1, v2 int32
  10470 	var v6 uint32
  10471 	_, _, _, _ = s, s1, v2, v6
  10472 	(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10473 	if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fuse_segment != 0 {
  10474 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10475 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10476 			(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fabsolute_delta = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10477 			s = 0
  10478 			for {
  10479 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10480 					break
  10481 				}
  10482 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10483 					v2 = VP8GetSignedValue(tls, br, int32(7))
  10484 				} else {
  10485 					v2 = 0
  10486 				}
  10487 				**(**int8_t)(__ccgo_up(hdr + 12 + uintptr(s))) = int8(v2)
  10488 				goto _1
  10489 			_1:
  10490 				;
  10491 				s = s + 1
  10492 			}
  10493 			s = 0
  10494 			for {
  10495 				if !(s < int32(NUM_MB_SEGMENTS)) {
  10496 					break
  10497 				}
  10498 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10499 					v2 = VP8GetSignedValue(tls, br, int32(6))
  10500 				} else {
  10501 					v2 = 0
  10502 				}
  10503 				**(**int8_t)(__ccgo_up(hdr + 16 + uintptr(s))) = int8(v2)
  10504 				goto _3
  10505 			_3:
  10506 				;
  10507 				s = s + 1
  10508 			}
  10509 		}
  10510 		if (*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  10511 			s1 = 0
  10512 			for {
  10513 				if !(s1 < int32(MB_FEATURE_TREE_PROBS)) {
  10514 					break
  10515 				}
  10516 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10517 					v6 = VP8GetValue(tls, br, int32(8))
  10518 				} else {
  10519 					v6 = uint32(255)
  10520 				}
  10521 				**(**uint8_t)(__ccgo_up(proba + uintptr(s1))) = uint8(v6)
  10522 				goto _5
  10523 			_5:
  10524 				;
  10525 				s1 = s1 + 1
  10526 			}
  10527 		}
  10528 	} else {
  10529 		(*VP8SegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = 0
  10530 	}
  10531 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10532 }
  10533 
  10534 // C documentation
  10535 //
  10536 //	// Paragraph 9.5
  10537 //	// If we don't have all the necessary data in 'buf', this function returns
  10538 //	// VP8_STATUS_SUSPENDED in incremental decoding, VP8_STATUS_NOT_ENOUGH_DATA
  10539 //	// otherwise.
  10540 //	// In incremental decoding, this case is not necessarily an error. Still, no
  10541 //	// bitreader is ever initialized to make it possible to read unavailable memory.
  10542 //	// If we don't even have the partitions' sizes, then VP8_STATUS_NOT_ENOUGH_DATA
  10543 //	// is returned, and this is an unrecoverable error.
  10544 //	// If the partitions were positioned ok, VP8_STATUS_OK is returned.
  10545 func ParsePartitions(tls *libc.TLS, dec uintptr, buf uintptr, size size_t) (r VP8StatusCode1) {
  10546 	var br, buf_end, part_start, sz uintptr
  10547 	var last_part, p, psize, size_left size_t
  10548 	var v2 int32
  10549 	_, _, _, _, _, _, _, _, _ = br, buf_end, last_part, p, part_start, psize, size_left, sz, v2
  10550 	br = dec + 16
  10551 	sz = buf
  10552 	buf_end = buf + uintptr(size)
  10553 	size_left = size
  10554 	(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one = libc.Uint32FromInt32(int32(1)<<VP8GetValue(tls, br, int32(2)) - int32(1))
  10555 	last_part = uint64((*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)
  10556 	if size < uint64(3)*last_part {
  10557 		// we can't even read the sizes with sz[]! That's a failure.
  10558 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10559 	}
  10560 	part_start = buf + uintptr(last_part*uint64(3))
  10561 	size_left = size_left - last_part*uint64(3)
  10562 	p = uint64(0)
  10563 	for {
  10564 		if !(p < last_part) {
  10565 			break
  10566 		}
  10567 		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))
  10568 		if psize > size_left {
  10569 			psize = size_left
  10570 		}
  10571 		VP8InitBitReader(tls, dec+440+uintptr(p)*48, part_start, psize)
  10572 		part_start = part_start + uintptr(psize)
  10573 		size_left = size_left - psize
  10574 		sz = sz + uintptr(3)
  10575 		goto _1
  10576 	_1:
  10577 		;
  10578 		p = p + 1
  10579 	}
  10580 	VP8InitBitReader(tls, dec+440+uintptr(last_part)*48, part_start, size_left)
  10581 	if part_start < buf_end {
  10582 		return int32(VP8_STATUS_OK)
  10583 	}
  10584 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  10585 		v2 = int32(VP8_STATUS_SUSPENDED)
  10586 	} else {
  10587 		v2 = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  10588 	}
  10589 	return v2
  10590 }
  10591 
  10592 // C documentation
  10593 //
  10594 //	// Paragraph 9.4
  10595 func ParseFilterHeader(tls *libc.TLS, br uintptr, dec uintptr) (r int32) {
  10596 	var hdr uintptr
  10597 	var i, v3, v4 int32
  10598 	_, _, _, _ = hdr, i, v3, v4
  10599 	hdr = dec + 84
  10600 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10601 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel = libc.Int32FromUint32(VP8GetValue(tls, br, int32(6)))
  10602 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsharpness = libc.Int32FromUint32(VP8GetValue(tls, br, int32(3)))
  10603 	(*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta = libc.Int32FromUint32(VP8GetValue(tls, br, int32(1)))
  10604 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fuse_lf_delta != 0 {
  10605 		if VP8GetValue(tls, br, int32(1)) != 0 {
  10606 			i = 0
  10607 			for {
  10608 				if !(i < int32(NUM_REF_LF_DELTAS)) {
  10609 					break
  10610 				}
  10611 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10612 					**(**int32)(__ccgo_up(hdr + 16 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10613 				}
  10614 				goto _1
  10615 			_1:
  10616 				;
  10617 				i = i + 1
  10618 			}
  10619 			i = 0
  10620 			for {
  10621 				if !(i < int32(NUM_MODE_LF_DELTAS)) {
  10622 					break
  10623 				}
  10624 				if VP8GetValue(tls, br, int32(1)) != 0 {
  10625 					**(**int32)(__ccgo_up(hdr + 32 + uintptr(i)*4)) = VP8GetSignedValue(tls, br, int32(6))
  10626 				}
  10627 				goto _2
  10628 			_2:
  10629 				;
  10630 				i = i + 1
  10631 			}
  10632 		}
  10633 	}
  10634 	if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Flevel == 0 {
  10635 		v3 = 0
  10636 	} else {
  10637 		if (*VP8FilterHeader)(unsafe.Pointer(hdr)).Fsimple != 0 {
  10638 			v4 = int32(1)
  10639 		} else {
  10640 			v4 = int32(2)
  10641 		}
  10642 		v3 = v4
  10643 	}
  10644 	(*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type = v3
  10645 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0))
  10646 }
  10647 
  10648 // C documentation
  10649 //
  10650 //	// Topmost call
  10651 func VP8GetHeaders(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  10652 	var bits uint32_t
  10653 	var br, buf, frm_hdr, pic_hdr uintptr
  10654 	var buf_size size_t
  10655 	var status VP8StatusCode1
  10656 	_, _, _, _, _, _, _ = bits, br, buf, buf_size, frm_hdr, pic_hdr, status
  10657 	if dec == libc.UintptrFromInt32(0) {
  10658 		return 0
  10659 	}
  10660 	SetOk(tls, dec)
  10661 	if io == libc.UintptrFromInt32(0) {
  10662 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+167)
  10663 	}
  10664 	buf = (*VP8Io)(unsafe.Pointer(io)).Fdata
  10665 	buf_size = (*VP8Io)(unsafe.Pointer(io)).Fdata_size
  10666 	if buf_size < uint64(4) {
  10667 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+204)
  10668 	}
  10669 	// Paragraph 9.1
  10670 	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))
  10671 	frm_hdr = dec + 68
  10672 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame = libc.BoolUint8(!(bits&libc.Uint32FromInt32(1) != 0))
  10673 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile = uint8(bits >> libc.Int32FromInt32(1) & uint32(7))
  10674 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow = uint8(bits >> libc.Int32FromInt32(4) & uint32(1))
  10675 	(*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length = bits >> libc.Int32FromInt32(5)
  10676 	if libc.Int32FromUint8((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fprofile) > int32(3) {
  10677 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+222)
  10678 	}
  10679 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fshow != 0) {
  10680 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+253)
  10681 	}
  10682 	buf = buf + uintptr(3)
  10683 	buf_size = buf_size - uint64(3)
  10684 	pic_hdr = dec + 76
  10685 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10686 		// Paragraph 9.2
  10687 		if buf_size < uint64(7) {
  10688 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+276)
  10689 		}
  10690 		if !(VP8CheckSignature(tls, buf, buf_size) != 0) {
  10691 			return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+304)
  10692 		}
  10693 		(*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))
  10694 		(*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
  10695 		(*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))
  10696 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fyscale = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(buf + 6))) >> int32(6))
  10697 		buf = buf + uintptr(7)
  10698 		buf_size = buf_size - uint64(7)
  10699 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w = (libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth) + int32(15)) >> int32(4)
  10700 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_h = (libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight) + int32(15)) >> int32(4)
  10701 		// Setup default output area (can be later modified during io->setup())
  10702 		(*VP8Io)(unsafe.Pointer(io)).Fwidth = libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fwidth)
  10703 		(*VP8Io)(unsafe.Pointer(io)).Fheight = libc.Int32FromUint16((*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fheight)
  10704 		// IMPORTANT! use some sane dimensions in crop* and scaled* fields.
  10705 		// So they can be used interchangeably without always testing for
  10706 		// 'use_cropping'.
  10707 		(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = 0
  10708 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = 0
  10709 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = 0
  10710 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10711 		(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10712 		(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = 0
  10713 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  10714 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = (*VP8Io)(unsafe.Pointer(io)).Fheight
  10715 		(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fwidth  // for soundness
  10716 		(*VP8Io)(unsafe.Pointer(io)).Fmb_h = (*VP8Io)(unsafe.Pointer(io)).Fheight // ditto
  10717 		VP8ResetProba(tls, dec+1192)
  10718 		ResetSegmentHeader(tls, dec+132)
  10719 	}
  10720 	// Check if we have all the partition #0 available, and initialize dec->br
  10721 	// to read this partition (and this partition only).
  10722 	if uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length) > buf_size {
  10723 		return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+318)
  10724 	}
  10725 	br = dec + 16
  10726 	VP8InitBitReader(tls, br, buf, uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length))
  10727 	buf = buf + uintptr((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10728 	buf_size = buf_size - uint64((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fpartition_length)
  10729 	if (*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0 {
  10730 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fcolorspace = uint8(VP8GetValue(tls, br, int32(1)))
  10731 		(*VP8PictureHeader)(unsafe.Pointer(pic_hdr)).Fclamp_type = uint8(VP8GetValue(tls, br, int32(1)))
  10732 	}
  10733 	if !(ParseSegmentHeader(tls, br, dec+132, dec+1192) != 0) {
  10734 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+339)
  10735 	}
  10736 	// Filter specs
  10737 	if !(ParseFilterHeader(tls, br, dec) != 0) {
  10738 		return VP8SetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR), __ccgo_ts+367)
  10739 	}
  10740 	status = ParsePartitions(tls, dec, buf, buf_size)
  10741 	if status != int32(VP8_STATUS_OK) {
  10742 		return VP8SetError(tls, dec, status, __ccgo_ts+394)
  10743 	}
  10744 	// quantizer change
  10745 	VP8ParseQuant(tls, dec)
  10746 	// Frame buffer marking
  10747 	if !((*VP8FrameHeader)(unsafe.Pointer(frm_hdr)).Fkey_frame != 0) {
  10748 		return VP8SetError(tls, dec, int32(VP8_STATUS_UNSUPPORTED_FEATURE), __ccgo_ts+418)
  10749 	}
  10750 	VP8GetValue(tls, br, int32(1)) // ignore the value of 'update_proba'
  10751 	VP8ParseProba(tls, br, dec)
  10752 	// sanitized state
  10753 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = int32(1)
  10754 	return int32(1)
  10755 }
  10756 
  10757 //------------------------------------------------------------------------------
  10758 // Residual decoding (Paragraph 13.2 / 13.3)
  10759 
  10760 var kCat3 = [4]uint8_t{
  10761 	0: uint8(173),
  10762 	1: uint8(148),
  10763 	2: uint8(140),
  10764 }
  10765 var kCat4 = [5]uint8_t{
  10766 	0: uint8(176),
  10767 	1: uint8(155),
  10768 	2: uint8(140),
  10769 	3: uint8(135),
  10770 }
  10771 var kCat5 = [6]uint8_t{
  10772 	0: uint8(180),
  10773 	1: uint8(157),
  10774 	2: uint8(141),
  10775 	3: uint8(134),
  10776 	4: uint8(130),
  10777 }
  10778 var kCat6 = [12]uint8_t{
  10779 	0:  uint8(254),
  10780 	1:  uint8(254),
  10781 	2:  uint8(243),
  10782 	3:  uint8(230),
  10783 	4:  uint8(196),
  10784 	5:  uint8(177),
  10785 	6:  uint8(153),
  10786 	7:  uint8(140),
  10787 	8:  uint8(133),
  10788 	9:  uint8(130),
  10789 	10: uint8(129),
  10790 }
  10791 var kCat3456 = [4]uintptr{
  10792 	0: uintptr(unsafe.Pointer(&kCat3)),
  10793 	1: uintptr(unsafe.Pointer(&kCat4)),
  10794 	2: uintptr(unsafe.Pointer(&kCat5)),
  10795 	3: uintptr(unsafe.Pointer(&kCat6)),
  10796 }
  10797 var kZigzag = [16]uint8_t{
  10798 	1:  uint8(1),
  10799 	2:  uint8(4),
  10800 	3:  uint8(8),
  10801 	4:  uint8(5),
  10802 	5:  uint8(2),
  10803 	6:  uint8(3),
  10804 	7:  uint8(6),
  10805 	8:  uint8(9),
  10806 	9:  uint8(12),
  10807 	10: uint8(13),
  10808 	11: uint8(10),
  10809 	12: uint8(7),
  10810 	13: uint8(11),
  10811 	14: uint8(14),
  10812 	15: uint8(15),
  10813 }
  10814 
  10815 // C documentation
  10816 //
  10817 //	// See section 13-2: https://datatracker.ietf.org/doc/html/rfc6386#section-13.2
  10818 func GetLargeValue(tls *libc.TLS, br2 uintptr, p uintptr) (r int32) {
  10819 	bp := tls.Alloc(16)
  10820 	defer tls.Free(16)
  10821 	var bit, bit0, bit1, cat, pos, shift, v, v13, v15, v21, v23, v5, v7 int32
  10822 	var bits bit_t
  10823 	var range1, split, value range_t
  10824 	var tab, v1, v10, v17, v18, v2, v9 uintptr
  10825 	var v11, v19, v3 uint64_t
  10826 	var _ /* in_bits at bp+0 */ lbit_t
  10827 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  10828 	v1 = br2
  10829 	range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10830 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10831 		v2 = v1
  10832 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10833 			libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10834 			**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10835 			v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10836 			goto _4
  10837 		_4:
  10838 			bits = v3
  10839 			bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10840 			(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10841 			**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10842 		} else {
  10843 			VP8LoadFinalBytes(tls, v2)
  10844 		}
  10845 	}
  10846 	pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10847 	split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 3)))) >> int32(8)
  10848 	value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10849 	bit = libc.BoolInt32(value > split)
  10850 	if bit != 0 {
  10851 		range1 = range1 - split
  10852 		**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10853 	} else {
  10854 		range1 = split + uint32(1)
  10855 	}
  10856 	v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10857 	goto _6
  10858 _6:
  10859 	shift = int32(7) ^ v5
  10860 	range1 = range1 << libc.Uint32FromInt32(shift)
  10861 	**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10862 	(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10863 	v7 = bit
  10864 	goto _8
  10865 _8:
  10866 	if !(v7 != 0) {
  10867 		v9 = br2
  10868 		range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10869 		if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10870 			v10 = v9
  10871 			if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10872 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10873 				**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10874 				v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10875 				goto _12
  10876 			_12:
  10877 				bits = v11
  10878 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10879 				(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  10880 				**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  10881 			} else {
  10882 				VP8LoadFinalBytes(tls, v10)
  10883 			}
  10884 		}
  10885 		pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  10886 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 4)))) >> int32(8)
  10887 		value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  10888 		bit = libc.BoolInt32(value > split)
  10889 		if bit != 0 {
  10890 			range1 = range1 - split
  10891 			**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10892 		} else {
  10893 			range1 = split + uint32(1)
  10894 		}
  10895 		v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10896 		goto _14
  10897 	_14:
  10898 		shift = int32(7) ^ v13
  10899 		range1 = range1 << libc.Uint32FromInt32(shift)
  10900 		**(**int32)(__ccgo_up(v9 + 12)) -= shift
  10901 		(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  10902 		v15 = bit
  10903 		goto _16
  10904 	_16:
  10905 		if !(v15 != 0) {
  10906 			v = int32(2)
  10907 		} else {
  10908 			v1 = br2
  10909 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10910 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10911 				v2 = v1
  10912 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10913 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10914 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10915 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10916 					goto _20
  10917 				_20:
  10918 					bits = v3
  10919 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10920 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10921 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10922 				} else {
  10923 					VP8LoadFinalBytes(tls, v2)
  10924 				}
  10925 			}
  10926 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10927 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 5)))) >> int32(8)
  10928 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10929 			bit = libc.BoolInt32(value > split)
  10930 			if bit != 0 {
  10931 				range1 = range1 - split
  10932 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10933 			} else {
  10934 				range1 = split + uint32(1)
  10935 			}
  10936 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10937 			goto _22
  10938 		_22:
  10939 			shift = int32(7) ^ v5
  10940 			range1 = range1 << libc.Uint32FromInt32(shift)
  10941 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10942 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10943 			v7 = bit
  10944 			goto _24
  10945 		_24:
  10946 			v = int32(3) + v7
  10947 		}
  10948 	} else {
  10949 		v1 = br2
  10950 		range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  10951 		if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  10952 			v2 = v1
  10953 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  10954 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  10955 				**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10956 				v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10957 				goto _28
  10958 			_28:
  10959 				bits = v3
  10960 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  10961 				(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  10962 				**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  10963 			} else {
  10964 				VP8LoadFinalBytes(tls, v2)
  10965 			}
  10966 		}
  10967 		pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  10968 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 6)))) >> int32(8)
  10969 		value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  10970 		bit = libc.BoolInt32(value > split)
  10971 		if bit != 0 {
  10972 			range1 = range1 - split
  10973 			**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  10974 		} else {
  10975 			range1 = split + uint32(1)
  10976 		}
  10977 		v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  10978 		goto _30
  10979 	_30:
  10980 		shift = int32(7) ^ v5
  10981 		range1 = range1 << libc.Uint32FromInt32(shift)
  10982 		**(**int32)(__ccgo_up(v1 + 12)) -= shift
  10983 		(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  10984 		v7 = bit
  10985 		goto _32
  10986 	_32:
  10987 		if !(v7 != 0) {
  10988 			v9 = br2
  10989 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  10990 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  10991 				v10 = v9
  10992 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  10993 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  10994 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  10995 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  10996 					goto _36
  10997 				_36:
  10998 					bits = v11
  10999 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11000 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  11001 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  11002 				} else {
  11003 					VP8LoadFinalBytes(tls, v10)
  11004 				}
  11005 			}
  11006 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  11007 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 7)))) >> int32(8)
  11008 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  11009 			bit = libc.BoolInt32(value > split)
  11010 			if bit != 0 {
  11011 				range1 = range1 - split
  11012 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11013 			} else {
  11014 				range1 = split + uint32(1)
  11015 			}
  11016 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11017 			goto _38
  11018 		_38:
  11019 			shift = int32(7) ^ v13
  11020 			range1 = range1 << libc.Uint32FromInt32(shift)
  11021 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  11022 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  11023 			v15 = bit
  11024 			goto _40
  11025 		_40:
  11026 			if !(v15 != 0) {
  11027 				v17 = br2
  11028 				range1 = (*VP8BitReader)(unsafe.Pointer(v17)).Frange1
  11029 				if (*VP8BitReader)(unsafe.Pointer(v17)).Fbits < libc.Int32FromInt32(0) {
  11030 					v18 = v17
  11031 					if (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf_max {
  11032 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v18)).Fbuf, uint64(8))
  11033 						**(**uintptr)(__ccgo_up(v18 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11034 						v19 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11035 						goto _44
  11036 					_44:
  11037 						bits = v19
  11038 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11039 						(*VP8BitReader)(unsafe.Pointer(v18)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v18)).Fvalue<<libc.Int32FromInt32(BITS)
  11040 						**(**int32)(__ccgo_up(v18 + 12)) += int32(BITS)
  11041 					} else {
  11042 						VP8LoadFinalBytes(tls, v18)
  11043 					}
  11044 				}
  11045 				pos = (*VP8BitReader)(unsafe.Pointer(v17)).Fbits
  11046 				split = range1 * libc.Uint32FromInt32(int32(159)) >> int32(8)
  11047 				value = uint32((*VP8BitReader)(unsafe.Pointer(v17)).Fvalue >> pos)
  11048 				bit = libc.BoolInt32(value > split)
  11049 				if bit != 0 {
  11050 					range1 = range1 - split
  11051 					**(**bit_t)(__ccgo_up(v17)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11052 				} else {
  11053 					range1 = split + uint32(1)
  11054 				}
  11055 				v21 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11056 				goto _46
  11057 			_46:
  11058 				shift = int32(7) ^ v21
  11059 				range1 = range1 << libc.Uint32FromInt32(shift)
  11060 				**(**int32)(__ccgo_up(v17 + 12)) -= shift
  11061 				(*VP8BitReader)(unsafe.Pointer(v17)).Frange1 = range1 - uint32(1)
  11062 				v23 = bit
  11063 				goto _48
  11064 			_48:
  11065 				v = int32(5) + v23
  11066 			} else {
  11067 				v1 = br2
  11068 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11069 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11070 					v2 = v1
  11071 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11072 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11073 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11074 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11075 						goto _52
  11076 					_52:
  11077 						bits = v3
  11078 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11079 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11080 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11081 					} else {
  11082 						VP8LoadFinalBytes(tls, v2)
  11083 					}
  11084 				}
  11085 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11086 				split = range1 * libc.Uint32FromInt32(int32(165)) >> int32(8)
  11087 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11088 				bit = libc.BoolInt32(value > split)
  11089 				if bit != 0 {
  11090 					range1 = range1 - split
  11091 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11092 				} else {
  11093 					range1 = split + uint32(1)
  11094 				}
  11095 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11096 				goto _54
  11097 			_54:
  11098 				shift = int32(7) ^ v5
  11099 				range1 = range1 << libc.Uint32FromInt32(shift)
  11100 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11101 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11102 				v7 = bit
  11103 				goto _56
  11104 			_56:
  11105 				v = int32(7) + int32(2)*v7
  11106 				v1 = br2
  11107 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11108 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11109 					v2 = v1
  11110 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11111 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11112 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11113 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11114 						goto _60
  11115 					_60:
  11116 						bits = v3
  11117 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11118 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11119 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11120 					} else {
  11121 						VP8LoadFinalBytes(tls, v2)
  11122 					}
  11123 				}
  11124 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11125 				split = range1 * libc.Uint32FromInt32(int32(145)) >> int32(8)
  11126 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11127 				bit = libc.BoolInt32(value > split)
  11128 				if bit != 0 {
  11129 					range1 = range1 - split
  11130 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11131 				} else {
  11132 					range1 = split + uint32(1)
  11133 				}
  11134 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11135 				goto _62
  11136 			_62:
  11137 				shift = int32(7) ^ v5
  11138 				range1 = range1 << libc.Uint32FromInt32(shift)
  11139 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11140 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11141 				v7 = bit
  11142 				goto _64
  11143 			_64:
  11144 				v = v + v7
  11145 			}
  11146 		} else {
  11147 			v1 = br2
  11148 			range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11149 			if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11150 				v2 = v1
  11151 				if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11152 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11153 					**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11154 					v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11155 					goto _68
  11156 				_68:
  11157 					bits = v3
  11158 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11159 					(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11160 					**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11161 				} else {
  11162 					VP8LoadFinalBytes(tls, v2)
  11163 				}
  11164 			}
  11165 			pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11166 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8)))) >> int32(8)
  11167 			value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11168 			bit = libc.BoolInt32(value > split)
  11169 			if bit != 0 {
  11170 				range1 = range1 - split
  11171 				**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11172 			} else {
  11173 				range1 = split + uint32(1)
  11174 			}
  11175 			v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11176 			goto _70
  11177 		_70:
  11178 			shift = int32(7) ^ v5
  11179 			range1 = range1 << libc.Uint32FromInt32(shift)
  11180 			**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11181 			(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11182 			v7 = bit
  11183 			goto _72
  11184 		_72:
  11185 			bit1 = v7
  11186 			v9 = br2
  11187 			range1 = (*VP8BitReader)(unsafe.Pointer(v9)).Frange1
  11188 			if (*VP8BitReader)(unsafe.Pointer(v9)).Fbits < libc.Int32FromInt32(0) {
  11189 				v10 = v9
  11190 				if (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf_max {
  11191 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v10)).Fbuf, uint64(8))
  11192 					**(**uintptr)(__ccgo_up(v10 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11193 					v11 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11194 					goto _76
  11195 				_76:
  11196 					bits = v11
  11197 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11198 					(*VP8BitReader)(unsafe.Pointer(v10)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v10)).Fvalue<<libc.Int32FromInt32(BITS)
  11199 					**(**int32)(__ccgo_up(v10 + 12)) += int32(BITS)
  11200 				} else {
  11201 					VP8LoadFinalBytes(tls, v10)
  11202 				}
  11203 			}
  11204 			pos = (*VP8BitReader)(unsafe.Pointer(v9)).Fbits
  11205 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(9)+bit1))))) >> int32(8)
  11206 			value = uint32((*VP8BitReader)(unsafe.Pointer(v9)).Fvalue >> pos)
  11207 			bit = libc.BoolInt32(value > split)
  11208 			if bit != 0 {
  11209 				range1 = range1 - split
  11210 				**(**bit_t)(__ccgo_up(v9)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11211 			} else {
  11212 				range1 = split + uint32(1)
  11213 			}
  11214 			v13 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11215 			goto _78
  11216 		_78:
  11217 			shift = int32(7) ^ v13
  11218 			range1 = range1 << libc.Uint32FromInt32(shift)
  11219 			**(**int32)(__ccgo_up(v9 + 12)) -= shift
  11220 			(*VP8BitReader)(unsafe.Pointer(v9)).Frange1 = range1 - uint32(1)
  11221 			v15 = bit
  11222 			goto _80
  11223 		_80:
  11224 			bit0 = v15
  11225 			cat = int32(2)*bit1 + bit0
  11226 			v = 0
  11227 			tab = kCat3456[cat]
  11228 			for {
  11229 				if !(**(**uint8_t)(__ccgo_up(tab)) != 0) {
  11230 					break
  11231 				}
  11232 				v1 = br2
  11233 				range1 = (*VP8BitReader)(unsafe.Pointer(v1)).Frange1
  11234 				if (*VP8BitReader)(unsafe.Pointer(v1)).Fbits < libc.Int32FromInt32(0) {
  11235 					v2 = v1
  11236 					if (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf_max {
  11237 						libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v2)).Fbuf, uint64(8))
  11238 						**(**uintptr)(__ccgo_up(v2 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11239 						v3 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11240 						goto _85
  11241 					_85:
  11242 						bits = v3
  11243 						bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11244 						(*VP8BitReader)(unsafe.Pointer(v2)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v2)).Fvalue<<libc.Int32FromInt32(BITS)
  11245 						**(**int32)(__ccgo_up(v2 + 12)) += int32(BITS)
  11246 					} else {
  11247 						VP8LoadFinalBytes(tls, v2)
  11248 					}
  11249 				}
  11250 				pos = (*VP8BitReader)(unsafe.Pointer(v1)).Fbits
  11251 				split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(tab)))) >> int32(8)
  11252 				value = uint32((*VP8BitReader)(unsafe.Pointer(v1)).Fvalue >> pos)
  11253 				bit = libc.BoolInt32(value > split)
  11254 				if bit != 0 {
  11255 					range1 = range1 - split
  11256 					**(**bit_t)(__ccgo_up(v1)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11257 				} else {
  11258 					range1 = split + uint32(1)
  11259 				}
  11260 				v5 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11261 				goto _87
  11262 			_87:
  11263 				shift = int32(7) ^ v5
  11264 				range1 = range1 << libc.Uint32FromInt32(shift)
  11265 				**(**int32)(__ccgo_up(v1 + 12)) -= shift
  11266 				(*VP8BitReader)(unsafe.Pointer(v1)).Frange1 = range1 - uint32(1)
  11267 				v7 = bit
  11268 				goto _89
  11269 			_89:
  11270 				v = v + (v + v7)
  11271 				goto _81
  11272 			_81:
  11273 				;
  11274 				tab = tab + 1
  11275 			}
  11276 			v = v + (int32(3) + int32(8)<<cat)
  11277 		}
  11278 	}
  11279 	return v
  11280 }
  11281 
  11282 // C documentation
  11283 //
  11284 //	// Returns the position of the last non-zero coeff plus one
  11285 func GetCoeffsFast(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n1 int32, out uintptr) (r int32) {
  11286 	bp := tls.Alloc(16)
  11287 	defer tls.Free(16)
  11288 	var bit, pos, pos1, shift, v1, v14, v6, v8 int32
  11289 	var bits bit_t
  11290 	var mask int32_t
  11291 	var p, p_ctx, v2, v3 uintptr
  11292 	var range1, split, split1, value, value1 range_t
  11293 	var v4 uint64_t
  11294 	var _ /* in_bits at bp+0 */ lbit_t
  11295 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v14, v2, v3, v4, v6, v8
  11296 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1)*8)) + uintptr(ctx)*11
  11297 	for {
  11298 		if !(n1 < int32(16)) {
  11299 			break
  11300 		}
  11301 		v2 = br3
  11302 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11303 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11304 			v3 = v2
  11305 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11306 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11307 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11308 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11309 				goto _5
  11310 			_5:
  11311 				bits = v4
  11312 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11313 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11314 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11315 			} else {
  11316 				VP8LoadFinalBytes(tls, v3)
  11317 			}
  11318 		}
  11319 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11320 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11321 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11322 		bit = libc.BoolInt32(value > split)
  11323 		if bit != 0 {
  11324 			range1 = range1 - split
  11325 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11326 		} else {
  11327 			range1 = split + uint32(1)
  11328 		}
  11329 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11330 		goto _7
  11331 	_7:
  11332 		shift = int32(7) ^ v6
  11333 		range1 = range1 << libc.Uint32FromInt32(shift)
  11334 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11335 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11336 		v8 = bit
  11337 		goto _9
  11338 	_9:
  11339 		if !(v8 != 0) {
  11340 			return n1 // previous coeff was last non-zero coeff
  11341 		}
  11342 		for {
  11343 			v2 = br3
  11344 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11345 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11346 				v3 = v2
  11347 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11348 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11349 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11350 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11351 					goto _13
  11352 				_13:
  11353 					bits = v4
  11354 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11355 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11356 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11357 				} else {
  11358 					VP8LoadFinalBytes(tls, v3)
  11359 				}
  11360 			}
  11361 			pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11362 			split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11363 			value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11364 			bit = libc.BoolInt32(value > split)
  11365 			if bit != 0 {
  11366 				range1 = range1 - split
  11367 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11368 			} else {
  11369 				range1 = split + uint32(1)
  11370 			}
  11371 			v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11372 			goto _15
  11373 		_15:
  11374 			shift = int32(7) ^ v6
  11375 			range1 = range1 << libc.Uint32FromInt32(shift)
  11376 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11377 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11378 			v8 = bit
  11379 			goto _17
  11380 		_17:
  11381 			if !!(v8 != 0) {
  11382 				break
  11383 			} // sequence of zero coeffs
  11384 			n1 = n1 + 1
  11385 			v14 = n1
  11386 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v14)*8))
  11387 			if n1 == int32(16) {
  11388 				return int32(16)
  11389 			}
  11390 		}
  11391 		// non zero coeff
  11392 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n1+int32(1))*8))
  11393 		v2 = br3
  11394 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11395 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11396 			v3 = v2
  11397 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11398 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11399 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11400 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11401 				goto _22
  11402 			_22:
  11403 				bits = v4
  11404 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11405 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11406 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11407 			} else {
  11408 				VP8LoadFinalBytes(tls, v3)
  11409 			}
  11410 		}
  11411 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11412 		split = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11413 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11414 		bit = libc.BoolInt32(value > split)
  11415 		if bit != 0 {
  11416 			range1 = range1 - split
  11417 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  11418 		} else {
  11419 			range1 = split + uint32(1)
  11420 		}
  11421 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  11422 		goto _24
  11423 	_24:
  11424 		shift = int32(7) ^ v6
  11425 		range1 = range1 << libc.Uint32FromInt32(shift)
  11426 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11427 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  11428 		v8 = bit
  11429 		goto _26
  11430 	_26:
  11431 		if !(v8 != 0) {
  11432 			v1 = int32(1)
  11433 			p = p_ctx + 1*11
  11434 		} else {
  11435 			v1 = GetLargeValue(tls, br3, p)
  11436 			p = p_ctx + 2*11
  11437 		}
  11438 		v2 = br3
  11439 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11440 			v3 = v2
  11441 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11442 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11443 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11444 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11445 				goto _30
  11446 			_30:
  11447 				bits = v4
  11448 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11449 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11450 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11451 			} else {
  11452 				VP8LoadFinalBytes(tls, v3)
  11453 			}
  11454 		}
  11455 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11456 		split1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11457 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11458 		mask = libc.Int32FromUint32(split1-value1) >> int32(31)
  11459 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11460 		**(**range_t)(__ccgo_up(v2 + 8)) += libc.Uint32FromInt32(mask)
  11461 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11462 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split1+libc.Uint32FromInt32(1))&libc.Uint32FromInt32(mask)) << pos1
  11463 		v6 = v1 ^ mask - mask
  11464 		goto _32
  11465 	_32:
  11466 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n1])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n1 > 0)*4)))
  11467 		goto _1
  11468 	_1:
  11469 		;
  11470 		n1 = n1 + 1
  11471 	}
  11472 	return int32(16)
  11473 }
  11474 
  11475 // C documentation
  11476 //
  11477 //	// This version of GetCoeffs() uses VP8GetBitAlt() which is an alternate version
  11478 //	// of VP8GetBitAlt() targeting specific platforms.
  11479 func GetCoeffsAlt(tls *libc.TLS, br3 uintptr, prob1 uintptr, ctx int32, dq uintptr, n int32, out uintptr) (r int32) {
  11480 	bp := tls.Alloc(16)
  11481 	defer tls.Free(16)
  11482 	var bit, pos, pos1, shift, v1, v12, v6 int32
  11483 	var bits bit_t
  11484 	var mask int32_t
  11485 	var p, p_ctx, v2, v3 uintptr
  11486 	var range1, split, split1, value, value1 range_t
  11487 	var v4 uint64_t
  11488 	var _ /* in_bits at bp+0 */ lbit_t
  11489 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, mask, p, p_ctx, pos, pos1, range1, shift, split, split1, v1, value, value1, v12, v2, v3, v4, v6
  11490 	p = **(**uintptr)(__ccgo_up(prob1 + uintptr(n)*8)) + uintptr(ctx)*11
  11491 	for {
  11492 		if !(n < int32(16)) {
  11493 			break
  11494 		}
  11495 		v2 = br3
  11496 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11497 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11498 			v3 = v2
  11499 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11500 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11501 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11502 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11503 				goto _5
  11504 			_5:
  11505 				bits = v4
  11506 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11507 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11508 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11509 			} else {
  11510 				VP8LoadFinalBytes(tls, v3)
  11511 			}
  11512 		}
  11513 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11514 		split1 = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) >> int32(8)
  11515 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11516 		if value1 > split1 {
  11517 			range1 = range1 - (split1 + uint32(1))
  11518 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11519 			bit = int32(1)
  11520 		} else {
  11521 			range1 = split1
  11522 			bit = 0
  11523 		}
  11524 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11525 			shift = libc.Int32FromUint8(kVP8Log2Range[range1])
  11526 			range1 = uint32(kVP8NewRange[range1])
  11527 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11528 		}
  11529 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11530 		v6 = bit
  11531 		goto _7
  11532 	_7:
  11533 		if !(v6 != 0) {
  11534 			return n // previous coeff was last non-zero coeff
  11535 		}
  11536 		for {
  11537 			v2 = br3
  11538 			range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11539 			if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11540 				v3 = v2
  11541 				if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11542 					libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11543 					**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11544 					v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11545 					goto _11
  11546 				_11:
  11547 					bits = v4
  11548 					bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11549 					(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11550 					**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11551 				} else {
  11552 					VP8LoadFinalBytes(tls, v3)
  11553 				}
  11554 			}
  11555 			pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11556 			split1 = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1)))) >> int32(8)
  11557 			value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11558 			if value1 > split1 {
  11559 				range1 = range1 - (split1 + uint32(1))
  11560 				**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11561 				bit = int32(1)
  11562 			} else {
  11563 				range1 = split1
  11564 				bit = 0
  11565 			}
  11566 			if range1 <= libc.Uint32FromInt32(0x7e) {
  11567 				shift = libc.Int32FromUint8(kVP8Log2Range[range1])
  11568 				range1 = uint32(kVP8NewRange[range1])
  11569 				**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11570 			}
  11571 			(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11572 			v6 = bit
  11573 			goto _13
  11574 		_13:
  11575 			if !!(v6 != 0) {
  11576 				break
  11577 			} // sequence of zero coeffs
  11578 			n = n + 1
  11579 			v12 = n
  11580 			p = **(**uintptr)(__ccgo_up(prob1 + uintptr(v12)*8))
  11581 			if n == int32(16) {
  11582 				return int32(16)
  11583 			}
  11584 		}
  11585 		// non zero coeff
  11586 		p_ctx = **(**uintptr)(__ccgo_up(prob1 + uintptr(n+int32(1))*8))
  11587 		v2 = br3
  11588 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  11589 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11590 			v3 = v2
  11591 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11592 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11593 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11594 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11595 				goto _18
  11596 			_18:
  11597 				bits = v4
  11598 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11599 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11600 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11601 			} else {
  11602 				VP8LoadFinalBytes(tls, v3)
  11603 			}
  11604 		}
  11605 		pos1 = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11606 		split1 = range1 * libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 2)))) >> int32(8)
  11607 		value1 = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos1)
  11608 		if value1 > split1 {
  11609 			range1 = range1 - (split1 + uint32(1))
  11610 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split1+libc.Uint32FromInt32(1)) << pos1
  11611 			bit = int32(1)
  11612 		} else {
  11613 			range1 = split1
  11614 			bit = 0
  11615 		}
  11616 		if range1 <= libc.Uint32FromInt32(0x7e) {
  11617 			shift = libc.Int32FromUint8(kVP8Log2Range[range1])
  11618 			range1 = uint32(kVP8NewRange[range1])
  11619 			**(**int32)(__ccgo_up(v2 + 12)) -= shift
  11620 		}
  11621 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1
  11622 		v6 = bit
  11623 		goto _20
  11624 	_20:
  11625 		if !(v6 != 0) {
  11626 			v1 = int32(1)
  11627 			p = p_ctx + 1*11
  11628 		} else {
  11629 			v1 = GetLargeValue(tls, br3, p)
  11630 			p = p_ctx + 2*11
  11631 		}
  11632 		v2 = br3
  11633 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  11634 			v3 = v2
  11635 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  11636 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  11637 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  11638 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  11639 				goto _24
  11640 			_24:
  11641 				bits = v4
  11642 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  11643 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  11644 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  11645 			} else {
  11646 				VP8LoadFinalBytes(tls, v3)
  11647 			}
  11648 		}
  11649 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  11650 		split = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1 >> int32(1)
  11651 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  11652 		mask = libc.Int32FromUint32(split-value) >> int32(31)
  11653 		**(**int32)(__ccgo_up(v2 + 12)) -= int32(1)
  11654 		**(**range_t)(__ccgo_up(v2 + 8)) += libc.Uint32FromInt32(mask)
  11655 		**(**range_t)(__ccgo_up(v2 + 8)) |= uint32(1)
  11656 		**(**bit_t)(__ccgo_up(v2)) -= uint64((split+libc.Uint32FromInt32(1))&libc.Uint32FromInt32(mask)) << pos
  11657 		v6 = v1 ^ mask - mask
  11658 		goto _26
  11659 	_26:
  11660 		**(**int16_t)(__ccgo_up(out + uintptr(kZigzag[n])*2)) = int16(v6 * **(**int32)(__ccgo_up(dq + libc.BoolUintptr(n > 0)*4)))
  11661 		goto _1
  11662 	_1:
  11663 		;
  11664 		n = n + 1
  11665 	}
  11666 	return int32(16)
  11667 }
  11668 
  11669 func InitGetCoeffs(tls *libc.TLS) {
  11670 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  11671 		goto _1
  11672 	}
  11673 	InitGetCoeffs_body(tls)
  11674 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)), VP8GetCPUInfo)
  11675 	goto _2
  11676 _2:
  11677 	;
  11678 	goto _1
  11679 _1: /**/ //
  11680 }
  11681 
  11682 var InitGetCoeffs_body_last_cpuinfo_used = uintptr(0)
  11683 
  11684 func init() {
  11685 	p := unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used)
  11686 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGetCoeffs_body_last_cpuinfo_used))
  11687 }
  11688 
  11689 func InitGetCoeffs_body(tls *libc.TLS) {
  11690 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) && (*(*func(*libc.TLS, CPUFeature) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetCPUInfo})))(tls, int32(kSlowSSSE3)) != 0 {
  11691 		GetCoeffs = __ccgo_fp(GetCoeffsAlt)
  11692 	} else {
  11693 		GetCoeffs = __ccgo_fp(GetCoeffsFast)
  11694 	}
  11695 }
  11696 
  11697 func NzCodeBits(tls *libc.TLS, nz_coeffs uint32_t, nz int32, dc_nz int32) (r uint32_t) {
  11698 	var v1, v2 int32
  11699 	_, _ = v1, v2
  11700 	nz_coeffs = nz_coeffs << uint32(2)
  11701 	if nz > int32(3) {
  11702 		v1 = int32(3)
  11703 	} else {
  11704 		if nz > int32(1) {
  11705 			v2 = int32(2)
  11706 		} else {
  11707 			v2 = dc_nz
  11708 		}
  11709 		v1 = v2
  11710 	}
  11711 	nz_coeffs = nz_coeffs | libc.Uint32FromInt32(v1)
  11712 	return nz_coeffs
  11713 }
  11714 
  11715 func ParseResiduals(tls *libc.TLS, dec uintptr, mb uintptr, token_br uintptr) (r int32) {
  11716 	bp := tls.Alloc(32)
  11717 	defer tls.Free(32)
  11718 	var ac_proba, bands, block, dst, left_mb, q uintptr
  11719 	var ch, ctx, ctx1, ctx2, dc0, first, i, l, l1, nz, nz1, nz2, x, y, v8 int32
  11720 	var lnz, tnz, v1 uint8_t
  11721 	var non_zero_uv, non_zero_y, nz_coeffs, nz_coeffs1, out_l_nz, out_t_nz uint32_t
  11722 	var _ /* dc at bp+0 */ [16]int16_t
  11723 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  11724 	bands = dec + 1192 + 1064
  11725 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11726 	q = dec + 1060 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*32
  11727 	dst = block
  11728 	left_mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11729 	non_zero_y = uint32(0)
  11730 	non_zero_uv = uint32(0)
  11731 	libc.Xmemset(tls, dst, 0, libc.Uint64FromInt32(384)*libc.Uint64FromInt64(2))
  11732 	if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) { // parse DC
  11733 		**(**[16]int16_t)(__ccgo_up(bp)) = [16]int16_t{}
  11734 		ctx = libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(mb)).Fnz_dc) + libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc)
  11735 		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)
  11736 		v1 = libc.BoolUint8(nz > libc.Int32FromInt32(0))
  11737 		(*VP8MB)(unsafe.Pointer(left_mb)).Fnz_dc = v1
  11738 		(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v1
  11739 		if nz > int32(1) { // more than just the DC -> perform the full transform
  11740 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp, dst)
  11741 		} else {
  11742 			dc0 = (int32((**(**[16]int16_t)(__ccgo_up(bp)))[0]) + int32(3)) >> int32(3)
  11743 			i = 0
  11744 			for {
  11745 				if !(i < libc.Int32FromInt32(16)*libc.Int32FromInt32(16)) {
  11746 					break
  11747 				}
  11748 				**(**int16_t)(__ccgo_up(dst + uintptr(i)*2)) = int16(dc0)
  11749 				goto _2
  11750 			_2:
  11751 				;
  11752 				i = i + int32(16)
  11753 			}
  11754 		}
  11755 		first = int32(1)
  11756 		ac_proba = bands
  11757 	} else {
  11758 		first = 0
  11759 		ac_proba = bands + 3*136
  11760 	}
  11761 	tnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(mb)).Fnz) & int32(0x0f))
  11762 	lnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) & int32(0x0f))
  11763 	y = 0
  11764 	for {
  11765 		if !(y < int32(4)) {
  11766 			break
  11767 		}
  11768 		l = libc.Int32FromUint8(lnz) & int32(1)
  11769 		nz_coeffs = uint32(0)
  11770 		x = 0
  11771 		for {
  11772 			if !(x < int32(4)) {
  11773 				break
  11774 			}
  11775 			ctx1 = l + libc.Int32FromUint8(tnz)&int32(1)
  11776 			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)
  11777 			l = libc.BoolInt32(nz1 > first)
  11778 			tnz = libc.Uint8FromInt32(libc.Int32FromUint8(tnz)>>int32(1) | l<<int32(7))
  11779 			nz_coeffs = NzCodeBits(tls, nz_coeffs, nz1, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11780 			dst = dst + uintptr(16)*2
  11781 			goto _4
  11782 		_4:
  11783 			;
  11784 			x = x + 1
  11785 		}
  11786 		tnz = libc.Uint8FromInt32(int32(tnz) >> libc.Int32FromInt32(4))
  11787 		lnz = libc.Uint8FromInt32(libc.Int32FromUint8(lnz)>>int32(1) | l<<int32(7))
  11788 		non_zero_y = non_zero_y<<libc.Int32FromInt32(8) | nz_coeffs
  11789 		goto _3
  11790 	_3:
  11791 		;
  11792 		y = y + 1
  11793 	}
  11794 	out_t_nz = uint32(tnz)
  11795 	out_l_nz = libc.Uint32FromInt32(libc.Int32FromUint8(lnz) >> int32(4))
  11796 	ch = 0
  11797 	for {
  11798 		if !(ch < int32(4)) {
  11799 			break
  11800 		}
  11801 		nz_coeffs1 = uint32(0)
  11802 		tnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(mb)).Fnz) >> (int32(4) + ch))
  11803 		lnz = libc.Uint8FromInt32(libc.Int32FromUint8((*VP8MB)(unsafe.Pointer(left_mb)).Fnz) >> (int32(4) + ch))
  11804 		y = 0
  11805 		for {
  11806 			if !(y < int32(2)) {
  11807 				break
  11808 			}
  11809 			l1 = libc.Int32FromUint8(lnz) & int32(1)
  11810 			x = 0
  11811 			for {
  11812 				if !(x < int32(2)) {
  11813 					break
  11814 				}
  11815 				ctx2 = l1 + libc.Int32FromUint8(tnz)&int32(1)
  11816 				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)
  11817 				l1 = libc.BoolInt32(nz2 > 0)
  11818 				tnz = libc.Uint8FromInt32(libc.Int32FromUint8(tnz)>>int32(1) | l1<<int32(3))
  11819 				nz_coeffs1 = NzCodeBits(tls, nz_coeffs1, nz2, libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(dst))) != 0))
  11820 				dst = dst + uintptr(16)*2
  11821 				goto _7
  11822 			_7:
  11823 				;
  11824 				x = x + 1
  11825 			}
  11826 			tnz = libc.Uint8FromInt32(int32(tnz) >> libc.Int32FromInt32(2))
  11827 			lnz = libc.Uint8FromInt32(libc.Int32FromUint8(lnz)>>int32(1) | l1<<int32(5))
  11828 			goto _6
  11829 		_6:
  11830 			;
  11831 			y = y + 1
  11832 		}
  11833 		// Note: we don't really need the per-4x4 details for U/V blocks.
  11834 		non_zero_uv = non_zero_uv | nz_coeffs1<<(int32(4)*ch)
  11835 		out_t_nz = out_t_nz | libc.Uint32FromInt32(libc.Int32FromUint8(tnz)<<int32(4)<<ch)
  11836 		out_l_nz = out_l_nz | libc.Uint32FromInt32(libc.Int32FromUint8(lnz)&int32(0xf0)<<ch)
  11837 		goto _5
  11838 	_5:
  11839 		;
  11840 		ch = ch + int32(2)
  11841 	}
  11842 	(*VP8MB)(unsafe.Pointer(mb)).Fnz = uint8(out_t_nz)
  11843 	(*VP8MB)(unsafe.Pointer(left_mb)).Fnz = uint8(out_l_nz)
  11844 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = non_zero_y
  11845 	(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = non_zero_uv
  11846 	// We look at the mode-code of each block and check if some blocks have less
  11847 	// than three non-zero coeffs (code < 2). This is to avoid dithering flat and
  11848 	// empty blocks.
  11849 	if non_zero_uv&uint32(0xaaaa) != 0 {
  11850 		v8 = 0
  11851 	} else {
  11852 		v8 = (*VP8QuantMatrix)(unsafe.Pointer(q)).Fdither
  11853 	}
  11854 	(*VP8MBData)(unsafe.Pointer(block)).Fdither = libc.Uint8FromInt32(v8)
  11855 	return libc.BoolInt32(!(non_zero_y|non_zero_uv != 0)) // will be used for further optimization
  11856 }
  11857 
  11858 //------------------------------------------------------------------------------
  11859 // Main loop
  11860 
  11861 func VP8DecodeMB(tls *libc.TLS, dec uintptr, token_br uintptr) (r int32) {
  11862 	var block, finfo, left, mb, v4 uintptr
  11863 	var skip, v1 int32
  11864 	var v2 uint8_t
  11865 	_, _, _, _, _, _, _, _ = block, finfo, left, mb, skip, v1, v2, v4
  11866 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11867 	mb = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*2
  11868 	block = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_data + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*800
  11869 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fuse_skip_proba != 0 {
  11870 		v1 = libc.Int32FromUint8((*VP8MBData)(unsafe.Pointer(block)).Fskip)
  11871 	} else {
  11872 		v1 = 0
  11873 	}
  11874 	skip = v1
  11875 	if !(skip != 0) {
  11876 		skip = ParseResiduals(tls, dec, mb, token_br)
  11877 	} else {
  11878 		v2 = libc.Uint8FromInt32(0)
  11879 		(*VP8MB)(unsafe.Pointer(mb)).Fnz = v2
  11880 		(*VP8MB)(unsafe.Pointer(left)).Fnz = v2
  11881 		if !((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4 != 0) {
  11882 			v2 = libc.Uint8FromInt32(0)
  11883 			(*VP8MB)(unsafe.Pointer(mb)).Fnz_dc = v2
  11884 			(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = v2
  11885 		}
  11886 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_y = uint32(0)
  11887 		(*VP8MBData)(unsafe.Pointer(block)).Fnon_zero_uv = uint32(0)
  11888 		(*VP8MBData)(unsafe.Pointer(block)).Fdither = uint8(0)
  11889 	}
  11890 	if (*VP8Decoder)(unsafe.Pointer(dec)).Ffilter_type > 0 { // store filter info
  11891 		finfo = (*VP8Decoder)(unsafe.Pointer(dec)).Ff_info + uintptr((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x)*4
  11892 		**(**VP8FInfo)(__ccgo_up(finfo)) = **(**VP8FInfo)(__ccgo_up(dec + 2924 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fsegment)*8 + uintptr((*VP8MBData)(unsafe.Pointer(block)).Fis_i4x4)*4))
  11893 		v4 = finfo + 2
  11894 		*(*uint8_t)(unsafe.Pointer(v4)) = uint8_t(int32(*(*uint8_t)(unsafe.Pointer(v4))) | libc.BoolInt32(!(skip != 0)))
  11895 	}
  11896 	return libc.BoolInt32(!((*VP8BitReader)(unsafe.Pointer(token_br)).Feof != 0))
  11897 }
  11898 
  11899 func VP8InitScanline(tls *libc.TLS, dec uintptr) {
  11900 	var left uintptr
  11901 	_ = left
  11902 	left = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_info - uintptr(1)*2
  11903 	(*VP8MB)(unsafe.Pointer(left)).Fnz = uint8(0)
  11904 	(*VP8MB)(unsafe.Pointer(left)).Fnz_dc = uint8(0)
  11905 	libc.Xmemset(tls, dec+2816, int32(B_DC_PRED), uint64(4))
  11906 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = 0
  11907 }
  11908 
  11909 func ParseFrame(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11910 	var token_br uintptr
  11911 	_ = token_br
  11912 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = 0
  11913 	for {
  11914 		if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y < (*VP8Decoder)(unsafe.Pointer(dec)).Fbr_mb_y) {
  11915 			break
  11916 		}
  11917 		// Parse bitstream for this row.
  11918 		token_br = dec + 440 + uintptr(libc.Uint32FromInt32((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y)&(*VP8Decoder)(unsafe.Pointer(dec)).Fnum_parts_minus_one)*48
  11919 		if !(VP8ParseIntraModeRow(tls, dec+16, dec) != 0) {
  11920 			return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+435)
  11921 		}
  11922 		for {
  11923 			if !((*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x < (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_w) {
  11924 				break
  11925 			}
  11926 			if !(VP8DecodeMB(tls, dec, token_br) != 0) {
  11927 				return VP8SetError(tls, dec, int32(VP8_STATUS_NOT_ENOUGH_DATA), __ccgo_ts+476)
  11928 			}
  11929 			goto _2
  11930 		_2:
  11931 			;
  11932 			(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_x + 1
  11933 		}
  11934 		VP8InitScanline(tls, dec) // Prepare for next scanline
  11935 		// Reconstruct, filter and emit the row.
  11936 		if !(VP8ProcessRow(tls, dec, io) != 0) {
  11937 			return VP8SetError(tls, dec, int32(VP8_STATUS_USER_ABORT), __ccgo_ts+511)
  11938 		}
  11939 		goto _1
  11940 	_1:
  11941 		;
  11942 		(*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y = (*VP8Decoder)(unsafe.Pointer(dec)).Fmb_y + 1
  11943 	}
  11944 	if (*VP8Decoder)(unsafe.Pointer(dec)).Fmt_method > 0 {
  11945 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, dec+152) != 0) {
  11946 			return 0
  11947 		}
  11948 	}
  11949 	return int32(1)
  11950 }
  11951 
  11952 // C documentation
  11953 //
  11954 //	// Main entry point
  11955 func VP8Decode(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  11956 	var ok int32
  11957 	_ = ok
  11958 	ok = 0
  11959 	if dec == libc.UintptrFromInt32(0) {
  11960 		return 0
  11961 	}
  11962 	if io == libc.UintptrFromInt32(0) {
  11963 		return VP8SetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM), __ccgo_ts+527)
  11964 	}
  11965 	if !((*VP8Decoder)(unsafe.Pointer(dec)).Fready != 0) {
  11966 		if !(VP8GetHeaders(tls, dec, io) != 0) {
  11967 			return 0
  11968 		}
  11969 	}
  11970 	// Finish setting up the decoding parameter. Will call io->setup().
  11971 	ok = libc.BoolInt32(VP8EnterCritical(tls, dec, io) == int32(VP8_STATUS_OK))
  11972 	if ok != 0 { // good to go.
  11973 		// Will allocate memory and prepare everything.
  11974 		if ok != 0 {
  11975 			ok = VP8InitFrame(tls, dec, io)
  11976 		}
  11977 		// Main decoding loop
  11978 		if ok != 0 {
  11979 			ok = ParseFrame(tls, dec, io)
  11980 		}
  11981 		// Exit.
  11982 		ok = ok & VP8ExitCritical(tls, dec, io)
  11983 	}
  11984 	if !(ok != 0) {
  11985 		VP8Clear(tls, dec)
  11986 		return 0
  11987 	}
  11988 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  11989 	return ok
  11990 }
  11991 
  11992 func VP8Clear(tls *libc.TLS, dec uintptr) {
  11993 	if dec == libc.UintptrFromInt32(0) {
  11994 		return
  11995 	}
  11996 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, dec+152)
  11997 	WebPDeallocateAlphaMemory(tls, dec)
  11998 	WebPSafeFree(tls, (*VP8Decoder)(unsafe.Pointer(dec)).Fmem)
  11999 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem = libc.UintptrFromInt32(0)
  12000 	(*VP8Decoder)(unsafe.Pointer(dec)).Fmem_size = uint64(0)
  12001 	libc.Xmemset(tls, dec+16, 0, uint64(48))
  12002 	(*VP8Decoder)(unsafe.Pointer(dec)).Fready = 0
  12003 }
  12004 
  12005 const APPROX_LOG_MAX = 4096
  12006 const APPROX_LOG_WITH_CORRECTION_MAX = 65536
  12007 const BITS_SPECIAL_MARKER = 256
  12008 const CODE_TO_PLANE_CODES = 120
  12009 const LOG_2_PRECISION_BITS = 23
  12010 const LOG_2_RECIPROCAL = 1.44269504088896338700465094007086
  12011 const LOG_2_RECIPROCAL_FIXED_DOUBLE = 12102203.161561485379934310913085937500
  12012 const LOG_LOOKUP_IDX_MAX = 256
  12013 const NUM_ARGB_CACHE_ROWS = 16
  12014 const NUM_CODE_LENGTH_CODES = 19
  12015 const PACKED_NON_LITERAL_CODE = 0
  12016 const PREFIX_LOOKUP_IDX_MAX = 512
  12017 const SYNC_EVERY_N_ROWS = 8
  12018 const VP8L_MAGIC_BYTE1 = 47
  12019 
  12020 var kHashMul8 = uint32(0x1e35a7bd)
  12021 
  12022 type VP8LPredictorFunc = uintptr
  12023 
  12024 type VP8LPredictorAddSubFunc = uintptr
  12025 
  12026 type VP8LProcessDecBlueAndRedFunc = uintptr
  12027 
  12028 type VP8LMultipliers = struct {
  12029 	Fgreen_to_red  uint8_t
  12030 	Fgreen_to_blue uint8_t
  12031 	Fred_to_blue   uint8_t
  12032 }
  12033 
  12034 type VP8LTransformColorInverseFunc = uintptr
  12035 
  12036 type VP8LConvertFunc = uintptr
  12037 
  12038 type VP8LMapARGBFunc = uintptr
  12039 
  12040 type VP8LMapAlphaFunc = uintptr
  12041 
  12042 type VP8LProcessEncBlueAndRedFunc = uintptr
  12043 
  12044 type VP8LTransformColorFunc = uintptr
  12045 
  12046 type VP8LCollectColorBlueTransformsFunc = uintptr
  12047 
  12048 type VP8LCollectColorRedTransformsFunc = uintptr
  12049 
  12050 type VP8LCostFunc = uintptr
  12051 
  12052 type VP8LCombinedShannonEntropyFunc = uintptr
  12053 
  12054 type VP8LShannonEntropyFunc = uintptr
  12055 
  12056 type VP8LStreaks = struct {
  12057 	Fcounts  [2]int32
  12058 	Fstreaks [2][2]int32
  12059 }
  12060 
  12061 type VP8LBitEntropy = struct {
  12062 	Fentropy      uint64_t
  12063 	Fsum          uint32_t
  12064 	Fnonzeros     int32
  12065 	Fmax_val      uint32_t
  12066 	Fnonzero_code uint32_t
  12067 }
  12068 
  12069 type VP8LGetCombinedEntropyUnrefinedFunc = uintptr
  12070 
  12071 type VP8LGetEntropyUnrefinedFunc = uintptr
  12072 
  12073 type VP8LAddVectorFunc = uintptr
  12074 
  12075 type VP8LAddVectorEqFunc = uintptr
  12076 
  12077 type VP8LVectorMismatchFunc = uintptr
  12078 
  12079 type VP8LBundleColorMapFunc = uintptr
  12080 
  12081 type VP8LFastLog2SlowFunc = uintptr
  12082 
  12083 type VP8LFastSLog2SlowFunc = uintptr
  12084 
  12085 type VP8LPrefixCode = struct {
  12086 	Fcode       int8_t
  12087 	Fextra_bits int8_t
  12088 }
  12089 
  12090 //------------------------------------------------------------------------------
  12091 // Transform-related functions used in both encoding and decoding.
  12092 
  12093 // Macros used to create a batch predictor that iteratively uses a
  12094 // one-pixel predictor.
  12095 
  12096 // The predictor is added to the output pixel (which
  12097 // is therefore considered as a residual) to get the final prediction.
  12098 
  12099 // Copyright 2010 Google Inc. All Rights Reserved.
  12100 //
  12101 // Use of this source code is governed by a BSD-style license
  12102 // that can be found in the COPYING file in the root of the source
  12103 // tree. An additional intellectual property rights grant can be found
  12104 // in the file PATENTS. All contributing project authors may
  12105 // be found in the AUTHORS file in the root of the source tree.
  12106 // -----------------------------------------------------------------------------
  12107 //
  12108 // Boolean decoder
  12109 //
  12110 // Author: Skal (pascal.massimino@gmail.com)
  12111 //         Vikas Arora (vikaas.arora@gmail.com)
  12112 
  12113 // Copyright 2012 Google Inc. All Rights Reserved.
  12114 //
  12115 // Use of this source code is governed by a BSD-style license
  12116 // that can be found in the COPYING file in the root of the source
  12117 // tree. An additional intellectual property rights grant can be found
  12118 // in the file PATENTS. All contributing project authors may
  12119 // be found in the AUTHORS file in the root of the source tree.
  12120 // -----------------------------------------------------------------------------
  12121 //
  12122 // Color Cache for WebP Lossless
  12123 //
  12124 // Authors: Jyrki Alakuijala (jyrki@google.com)
  12125 //          Urvang Joshi (urvang@google.com)
  12126 
  12127 // Copyright 2012 Google Inc. All Rights Reserved.
  12128 //
  12129 // Use of this source code is governed by a BSD-style license
  12130 // that can be found in the COPYING file in the root of the source
  12131 // tree. An additional intellectual property rights grant can be found
  12132 // in the file PATENTS. All contributing project authors may
  12133 // be found in the AUTHORS file in the root of the source tree.
  12134 // -----------------------------------------------------------------------------
  12135 //
  12136 // Utilities for building and looking up Huffman trees.
  12137 //
  12138 // Author: Urvang Joshi (urvang@google.com)
  12139 
  12140 // Copyright 2012 Google Inc. All Rights Reserved.
  12141 //
  12142 // Use of this source code is governed by a BSD-style license
  12143 // that can be found in the COPYING file in the root of the source
  12144 // tree. An additional intellectual property rights grant can be found
  12145 // in the file PATENTS. All contributing project authors may
  12146 // be found in the AUTHORS file in the root of the source tree.
  12147 // -----------------------------------------------------------------------------
  12148 //
  12149 // Rescaling functions
  12150 //
  12151 // Author: Skal (pascal.massimino@gmail.com)
  12152 
  12153 // Copyright 2012 Google Inc. All Rights Reserved.
  12154 //
  12155 // Use of this source code is governed by a BSD-style license
  12156 // that can be found in the COPYING file in the root of the source
  12157 // tree. An additional intellectual property rights grant can be found
  12158 // in the file PATENTS. All contributing project authors may
  12159 // be found in the AUTHORS file in the root of the source tree.
  12160 // -----------------------------------------------------------------------------
  12161 //
  12162 // Misc. common utility functions
  12163 //
  12164 // Authors: Skal (pascal.massimino@gmail.com)
  12165 //          Urvang (urvang@google.com)
  12166 
  12167 // Copyright 2010 Google Inc. All Rights Reserved.
  12168 //
  12169 // Use of this source code is governed by a BSD-style license
  12170 // that can be found in the COPYING file in the root of the source
  12171 // tree. An additional intellectual property rights grant can be found
  12172 // in the file PATENTS. All contributing project authors may
  12173 // be found in the AUTHORS file in the root of the source tree.
  12174 // -----------------------------------------------------------------------------
  12175 //
  12176 //  Main decoding functions for WebP images.
  12177 //
  12178 // Author: Skal (pascal.massimino@gmail.com)
  12179 
  12180 // Copyright 2012 Google Inc. All Rights Reserved.
  12181 //
  12182 // Use of this source code is governed by a BSD-style license
  12183 // that can be found in the COPYING file in the root of the source
  12184 // tree. An additional intellectual property rights grant can be found
  12185 // in the file PATENTS. All contributing project authors may
  12186 // be found in the AUTHORS file in the root of the source tree.
  12187 // -----------------------------------------------------------------------------
  12188 //
  12189 //  Internal header for constants related to WebP file format.
  12190 //
  12191 // Author: Urvang (urvang@google.com)
  12192 
  12193 // Copyright 2010 Google Inc. All Rights Reserved.
  12194 //
  12195 // Use of this source code is governed by a BSD-style license
  12196 // that can be found in the COPYING file in the root of the source
  12197 // tree. An additional intellectual property rights grant can be found
  12198 // in the file PATENTS. All contributing project authors may
  12199 // be found in the AUTHORS file in the root of the source tree.
  12200 // -----------------------------------------------------------------------------
  12201 //
  12202 //  Common types + memory wrappers
  12203 //
  12204 // Author: Skal (pascal.massimino@gmail.com)
  12205 
  12206 var kCodeLengthLiterals = int32(16)
  12207 var kCodeLengthRepeatCode = int32(16)
  12208 var kCodeLengthExtraBits = [3]uint8_t{
  12209 	0: uint8(2),
  12210 	1: uint8(3),
  12211 	2: uint8(7),
  12212 }
  12213 var kCodeLengthRepeatOffsets = [3]uint8_t{
  12214 	0: uint8(3),
  12215 	1: uint8(3),
  12216 	2: uint8(11),
  12217 }
  12218 
  12219 // C documentation
  12220 //
  12221 //	// -----------------------------------------------------------------------------
  12222 //	//  Five Huffman codes are used at each meta code:
  12223 //	//  1. green + length prefix codes + color cache codes,
  12224 //	//  2. alpha,
  12225 //	//  3. red,
  12226 //	//  4. blue, and,
  12227 //	//  5. distance prefix codes.
  12228 type HuffIndex = int32
  12229 
  12230 const GREEN = 0
  12231 const RED = 1
  12232 const BLUE = 2
  12233 const ALPHA = 3
  12234 const DIST = 4
  12235 
  12236 var kAlphabetSize = [5]uint16_t{
  12237 	0: libc.Uint16FromInt32(libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)),
  12238 	1: uint16(NUM_LITERAL_CODES),
  12239 	2: uint16(NUM_LITERAL_CODES),
  12240 	3: uint16(NUM_LITERAL_CODES),
  12241 	4: uint16(NUM_DISTANCE_CODES),
  12242 }
  12243 
  12244 var kLiteralMap = [5]uint8_t{
  12245 	1: uint8(1),
  12246 	2: uint8(1),
  12247 	3: uint8(1),
  12248 }
  12249 
  12250 var kCodeLengthCodeOrder = [19]uint8_t{
  12251 	0:  uint8(17),
  12252 	1:  uint8(18),
  12253 	3:  uint8(1),
  12254 	4:  uint8(2),
  12255 	5:  uint8(3),
  12256 	6:  uint8(4),
  12257 	7:  uint8(5),
  12258 	8:  uint8(16),
  12259 	9:  uint8(6),
  12260 	10: uint8(7),
  12261 	11: uint8(8),
  12262 	12: uint8(9),
  12263 	13: uint8(10),
  12264 	14: uint8(11),
  12265 	15: uint8(12),
  12266 	16: uint8(13),
  12267 	17: uint8(14),
  12268 	18: uint8(15),
  12269 }
  12270 
  12271 var kCodeToPlane = [120]uint8_t{
  12272 	0:   uint8(0x18),
  12273 	1:   uint8(0x07),
  12274 	2:   uint8(0x17),
  12275 	3:   uint8(0x19),
  12276 	4:   uint8(0x28),
  12277 	5:   uint8(0x06),
  12278 	6:   uint8(0x27),
  12279 	7:   uint8(0x29),
  12280 	8:   uint8(0x16),
  12281 	9:   uint8(0x1a),
  12282 	10:  uint8(0x26),
  12283 	11:  uint8(0x2a),
  12284 	12:  uint8(0x38),
  12285 	13:  uint8(0x05),
  12286 	14:  uint8(0x37),
  12287 	15:  uint8(0x39),
  12288 	16:  uint8(0x15),
  12289 	17:  uint8(0x1b),
  12290 	18:  uint8(0x36),
  12291 	19:  uint8(0x3a),
  12292 	20:  uint8(0x25),
  12293 	21:  uint8(0x2b),
  12294 	22:  uint8(0x48),
  12295 	23:  uint8(0x04),
  12296 	24:  uint8(0x47),
  12297 	25:  uint8(0x49),
  12298 	26:  uint8(0x14),
  12299 	27:  uint8(0x1c),
  12300 	28:  uint8(0x35),
  12301 	29:  uint8(0x3b),
  12302 	30:  uint8(0x46),
  12303 	31:  uint8(0x4a),
  12304 	32:  uint8(0x24),
  12305 	33:  uint8(0x2c),
  12306 	34:  uint8(0x58),
  12307 	35:  uint8(0x45),
  12308 	36:  uint8(0x4b),
  12309 	37:  uint8(0x34),
  12310 	38:  uint8(0x3c),
  12311 	39:  uint8(0x03),
  12312 	40:  uint8(0x57),
  12313 	41:  uint8(0x59),
  12314 	42:  uint8(0x13),
  12315 	43:  uint8(0x1d),
  12316 	44:  uint8(0x56),
  12317 	45:  uint8(0x5a),
  12318 	46:  uint8(0x23),
  12319 	47:  uint8(0x2d),
  12320 	48:  uint8(0x44),
  12321 	49:  uint8(0x4c),
  12322 	50:  uint8(0x55),
  12323 	51:  uint8(0x5b),
  12324 	52:  uint8(0x33),
  12325 	53:  uint8(0x3d),
  12326 	54:  uint8(0x68),
  12327 	55:  uint8(0x02),
  12328 	56:  uint8(0x67),
  12329 	57:  uint8(0x69),
  12330 	58:  uint8(0x12),
  12331 	59:  uint8(0x1e),
  12332 	60:  uint8(0x66),
  12333 	61:  uint8(0x6a),
  12334 	62:  uint8(0x22),
  12335 	63:  uint8(0x2e),
  12336 	64:  uint8(0x54),
  12337 	65:  uint8(0x5c),
  12338 	66:  uint8(0x43),
  12339 	67:  uint8(0x4d),
  12340 	68:  uint8(0x65),
  12341 	69:  uint8(0x6b),
  12342 	70:  uint8(0x32),
  12343 	71:  uint8(0x3e),
  12344 	72:  uint8(0x78),
  12345 	73:  uint8(0x01),
  12346 	74:  uint8(0x77),
  12347 	75:  uint8(0x79),
  12348 	76:  uint8(0x53),
  12349 	77:  uint8(0x5d),
  12350 	78:  uint8(0x11),
  12351 	79:  uint8(0x1f),
  12352 	80:  uint8(0x64),
  12353 	81:  uint8(0x6c),
  12354 	82:  uint8(0x42),
  12355 	83:  uint8(0x4e),
  12356 	84:  uint8(0x76),
  12357 	85:  uint8(0x7a),
  12358 	86:  uint8(0x21),
  12359 	87:  uint8(0x2f),
  12360 	88:  uint8(0x75),
  12361 	89:  uint8(0x7b),
  12362 	90:  uint8(0x31),
  12363 	91:  uint8(0x3f),
  12364 	92:  uint8(0x63),
  12365 	93:  uint8(0x6d),
  12366 	94:  uint8(0x52),
  12367 	95:  uint8(0x5e),
  12368 	97:  uint8(0x74),
  12369 	98:  uint8(0x7c),
  12370 	99:  uint8(0x41),
  12371 	100: uint8(0x4f),
  12372 	101: uint8(0x10),
  12373 	102: uint8(0x20),
  12374 	103: uint8(0x62),
  12375 	104: uint8(0x6e),
  12376 	105: uint8(0x30),
  12377 	106: uint8(0x73),
  12378 	107: uint8(0x7d),
  12379 	108: uint8(0x51),
  12380 	109: uint8(0x5f),
  12381 	110: uint8(0x40),
  12382 	111: uint8(0x72),
  12383 	112: uint8(0x7e),
  12384 	113: uint8(0x61),
  12385 	114: uint8(0x6f),
  12386 	115: uint8(0x50),
  12387 	116: uint8(0x71),
  12388 	117: uint8(0x7f),
  12389 	118: uint8(0x60),
  12390 	119: uint8(0x70),
  12391 }
  12392 
  12393 // C documentation
  12394 //
  12395 //	// Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha
  12396 //	// and distance alphabets are constant (256 for red, blue and alpha, 40 for
  12397 //	// distance) and lookup table sizes for them in worst case are 630 and 410
  12398 //	// respectively. Size of green alphabet depends on color cache size and is equal
  12399 //	// to 256 (green component values) + 24 (length prefix values)
  12400 //	// + color_cache_size (between 0 and 2048).
  12401 //	// All values computed for 8-bit first level lookup with Mark Adler's tool:
  12402 //	// https://github.com/madler/zlib/blob/v1.2.5/examples/enough.c
  12403 var kTableSize = [12]uint16_t{
  12404 	0:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(654)),
  12405 	1:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(656)),
  12406 	2:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(658)),
  12407 	3:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(662)),
  12408 	4:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(670)),
  12409 	5:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(686)),
  12410 	6:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(718)),
  12411 	7:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(782)),
  12412 	8:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(912)),
  12413 	9:  libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1168)),
  12414 	10: libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(1680)),
  12415 	11: libc.Uint16FromInt32(libc.Int32FromInt32(630)*libc.Int32FromInt32(3) + libc.Int32FromInt32(410) + libc.Int32FromInt32(2704)),
  12416 }
  12417 
  12418 func VP8LSetError(tls *libc.TLS, dec uintptr, error1 VP8StatusCode1) (r int32) {
  12419 	// The oldest error reported takes precedence over the new one.
  12420 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_OK) || (*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus == int32(VP8_STATUS_SUSPENDED) {
  12421 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = error1
  12422 	}
  12423 	return 0
  12424 }
  12425 
  12426 //------------------------------------------------------------------------------
  12427 
  12428 func VP8LCheckSignature(tls *libc.TLS, data uintptr, size size_t) (r int32) {
  12429 	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
  12430 }
  12431 
  12432 func ReadImageInfo(tls *libc.TLS, br uintptr, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12433 	if VP8LReadBits(tls, br, int32(8)) != uint32(VP8L_MAGIC_BYTE1) {
  12434 		return 0
  12435 	}
  12436 	**(**int32)(__ccgo_up(width)) = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12437 	**(**int32)(__ccgo_up(height)) = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(VP8L_IMAGE_SIZE_BITS)) + uint32(1))
  12438 	**(**int32)(__ccgo_up(has_alpha)) = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)))
  12439 	if VP8LReadBits(tls, br, int32(VP8L_VERSION_BITS)) != uint32(0) {
  12440 		return 0
  12441 	}
  12442 	return libc.BoolInt32(!((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12443 }
  12444 
  12445 func VP8LGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr, has_alpha uintptr) (r int32) {
  12446 	bp := tls.Alloc(64)
  12447 	defer tls.Free(64)
  12448 	var _ /* a at bp+8 */ int32
  12449 	var _ /* br at bp+16 */ VP8LBitReader
  12450 	var _ /* h at bp+4 */ int32
  12451 	var _ /* w at bp+0 */ int32
  12452 	if data == libc.UintptrFromInt32(0) || data_size < uint64(VP8L_FRAME_HEADER_SIZE) {
  12453 		return 0 // not enough data
  12454 	} else {
  12455 		if !(VP8LCheckSignature(tls, data, data_size) != 0) {
  12456 			return 0 // bad signature
  12457 		} else {
  12458 			VP8LInitBitReader(tls, bp+16, data, data_size)
  12459 			if !(ReadImageInfo(tls, bp+16, bp, bp+4, bp+8) != 0) {
  12460 				return 0
  12461 			}
  12462 			if width != libc.UintptrFromInt32(0) {
  12463 				**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp))
  12464 			}
  12465 			if height != libc.UintptrFromInt32(0) {
  12466 				**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 4))
  12467 			}
  12468 			if has_alpha != libc.UintptrFromInt32(0) {
  12469 				**(**int32)(__ccgo_up(has_alpha)) = **(**int32)(__ccgo_up(bp + 8))
  12470 			}
  12471 			return int32(1)
  12472 		}
  12473 	}
  12474 	return r
  12475 }
  12476 
  12477 //------------------------------------------------------------------------------
  12478 
  12479 func GetCopyDistance(tls *libc.TLS, distance_symbol int32, br uintptr) (r int32) {
  12480 	var extra_bits, offset int32
  12481 	_, _ = extra_bits, offset
  12482 	if distance_symbol < int32(4) {
  12483 		return distance_symbol + int32(1)
  12484 	}
  12485 	extra_bits = (distance_symbol - int32(2)) >> int32(1)
  12486 	offset = (int32(2) + distance_symbol&int32(1)) << extra_bits
  12487 	return libc.Int32FromUint32(libc.Uint32FromInt32(offset) + VP8LReadBits(tls, br, extra_bits) + uint32(1))
  12488 }
  12489 
  12490 func GetCopyLength(tls *libc.TLS, length_symbol int32, br uintptr) (r int32) {
  12491 	// Length and distance prefixes are encoded the same way.
  12492 	return GetCopyDistance(tls, length_symbol, br)
  12493 }
  12494 
  12495 func PlaneCodeToDistance(tls *libc.TLS, xsize int32, plane_code int32) (r int32) {
  12496 	var dist, dist_code, xoffset, yoffset, v1 int32
  12497 	_, _, _, _, _ = dist, dist_code, xoffset, yoffset, v1
  12498 	if plane_code > int32(CODE_TO_PLANE_CODES) {
  12499 		return plane_code - int32(CODE_TO_PLANE_CODES)
  12500 	} else {
  12501 		dist_code = libc.Int32FromUint8(kCodeToPlane[plane_code-int32(1)])
  12502 		yoffset = dist_code >> int32(4)
  12503 		xoffset = int32(8) - dist_code&int32(0xf)
  12504 		dist = yoffset*xsize + xoffset
  12505 		if dist >= int32(1) {
  12506 			v1 = dist
  12507 		} else {
  12508 			v1 = int32(1)
  12509 		}
  12510 		return v1 // dist<1 can happen if xsize is very small
  12511 	}
  12512 	return r
  12513 }
  12514 
  12515 // C documentation
  12516 //
  12517 //	//------------------------------------------------------------------------------
  12518 //	// Decodes the next Huffman code from bit-stream.
  12519 //	// VP8LFillBitWindow(br) needs to be called at minimum every second call
  12520 //	// to ReadSymbol, in order to pre-fetch enough bits.
  12521 func ReadSymbol(tls *libc.TLS, table uintptr, br2 uintptr) (r int32) {
  12522 	var nbits int32
  12523 	var val1, v2 uint32_t
  12524 	var v1 uintptr
  12525 	_, _, _, _ = nbits, val1, v1, v2
  12526 	v1 = br2
  12527 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12528 	goto _3
  12529 _3:
  12530 	val1 = v2
  12531 	table = table + uintptr(val1&libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HUFFMAN_TABLE_BITS)-libc.Int32FromInt32(1)))*4
  12532 	nbits = libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(table)).Fbits) - int32(HUFFMAN_TABLE_BITS)
  12533 	if nbits > 0 {
  12534 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + int32(HUFFMAN_TABLE_BITS)
  12535 		v1 = br2
  12536 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12537 		goto _6
  12538 	_6:
  12539 		val1 = v2
  12540 		table = table + uintptr((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)*4
  12541 		table = table + uintptr(val1&libc.Uint32FromInt32(libc.Int32FromInt32(1)<<nbits-libc.Int32FromInt32(1)))*4
  12542 	}
  12543 	(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(table)).Fbits)
  12544 	return libc.Int32FromUint16((*HuffmanCode)(unsafe.Pointer(table)).Fvalue)
  12545 }
  12546 
  12547 // C documentation
  12548 //
  12549 //	// Reads packed symbol depending on GREEN channel
  12550 func ReadPackedSymbols(tls *libc.TLS, group uintptr, br2 uintptr, dst uintptr) (r int32) {
  12551 	var code HuffmanCode32
  12552 	var val1, v2 uint32_t
  12553 	var v1 uintptr
  12554 	_, _, _, _ = code, val1, v1, v2
  12555 	v1 = br2
  12556 	v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12557 	goto _3
  12558 _3:
  12559 	val1 = v2 & (libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS) - libc.Uint32FromInt32(1))
  12560 	code = **(**HuffmanCode32)(__ccgo_up(group + 56 + uintptr(val1)*8))
  12561 	if code.Fbits < int32(BITS_SPECIAL_MARKER) {
  12562 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits
  12563 		**(**uint32_t)(__ccgo_up(dst)) = code.Fvalue
  12564 		return PACKED_NON_LITERAL_CODE
  12565 	} else {
  12566 		(*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br2)).Fbit_pos + code.Fbits - int32(BITS_SPECIAL_MARKER)
  12567 		return libc.Int32FromUint32(code.Fvalue)
  12568 	}
  12569 	return r
  12570 }
  12571 
  12572 func AccumulateHCode(tls *libc.TLS, hcode HuffmanCode, shift int32, huff uintptr) (r int32) {
  12573 	**(**int32)(__ccgo_up(huff)) += libc.Int32FromUint8(hcode.Fbits)
  12574 	**(**uint32_t)(__ccgo_up(huff + 4)) |= uint32(hcode.Fvalue) << shift
  12575 	return libc.Int32FromUint8(hcode.Fbits)
  12576 }
  12577 
  12578 func BuildPackedTable(tls *libc.TLS, htree_group uintptr) {
  12579 	var bits, code uint32_t
  12580 	var hcode HuffmanCode
  12581 	var huff uintptr
  12582 	_, _, _, _ = bits, code, hcode, huff
  12583 	code = uint32(0)
  12584 	for {
  12585 		if !(code < libc.Uint32FromUint32(1)<<libc.Int32FromInt32(HUFFMAN_PACKED_BITS)) {
  12586 			break
  12587 		}
  12588 		bits = code
  12589 		huff = htree_group + 56 + uintptr(bits)*8
  12590 		hcode = **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)) + uintptr(bits)*4))
  12591 		if libc.Int32FromUint16(hcode.Fvalue) >= int32(NUM_LITERAL_CODES) {
  12592 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = libc.Int32FromUint8(hcode.Fbits) + int32(BITS_SPECIAL_MARKER)
  12593 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(hcode.Fvalue)
  12594 		} else {
  12595 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fbits = 0
  12596 			(*HuffmanCode32)(unsafe.Pointer(huff)).Fvalue = uint32(0)
  12597 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, hcode, int32(8), huff))
  12598 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)) + uintptr(bits)*4)), int32(16), huff))
  12599 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)) + uintptr(bits)*4)), 0, huff))
  12600 			bits = bits >> libc.Uint32FromInt32(AccumulateHCode(tls, **(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)) + uintptr(bits)*4)), int32(24), huff))
  12601 			_ = bits
  12602 		}
  12603 		goto _1
  12604 	_1:
  12605 		;
  12606 		code = code + 1
  12607 	}
  12608 }
  12609 
  12610 func ReadHuffmanCodeLengths(tls *libc.TLS, dec uintptr, code_length_code_lengths uintptr, num_symbols int32, code_lengths uintptr) (r int32) {
  12611 	bp := tls.Alloc(48)
  12612 	defer tls.Free(48)
  12613 	var br3, p, v2 uintptr
  12614 	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
  12615 	var v4 uint32_t
  12616 	var _ /* tables at bp+0 */ HuffmanTables
  12617 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12618 	ok = 0
  12619 	br3 = dec + 40
  12620 	prev_code_len = int32(DEFAULT_CODE_LENGTH)
  12621 	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) {
  12622 		goto End
  12623 	}
  12624 	if VP8LReadBits(tls, br3, int32(1)) != 0 { // use length
  12625 		length_nbits = libc.Int32FromUint32(uint32(2) + uint32(2)*VP8LReadBits(tls, br3, int32(3)))
  12626 		max_symbol = libc.Int32FromUint32(uint32(2) + VP8LReadBits(tls, br3, length_nbits))
  12627 		if max_symbol > num_symbols {
  12628 			goto End
  12629 		}
  12630 	} else {
  12631 		max_symbol = num_symbols
  12632 	}
  12633 	symbol = 0
  12634 	for symbol < num_symbols {
  12635 		v1 = max_symbol
  12636 		max_symbol = max_symbol - 1
  12637 		if v1 == 0 {
  12638 			break
  12639 		}
  12640 		v2 = br3
  12641 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  12642 			VP8LDoFillBitWindow(tls, v2)
  12643 		}
  12644 		v2 = br3
  12645 		v4 = uint32((*VP8LBitReader)(unsafe.Pointer(v2)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  12646 		goto _5
  12647 	_5:
  12648 		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
  12649 		(*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos = (*VP8LBitReader)(unsafe.Pointer(br3)).Fbit_pos + libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(p)).Fbits)
  12650 		code_len = libc.Int32FromUint16((*HuffmanCode)(unsafe.Pointer(p)).Fvalue)
  12651 		if code_len < kCodeLengthLiterals {
  12652 			v1 = symbol
  12653 			symbol = symbol + 1
  12654 			**(**int32)(__ccgo_up(code_lengths + uintptr(v1)*4)) = code_len
  12655 			if code_len != 0 {
  12656 				prev_code_len = code_len
  12657 			}
  12658 		} else {
  12659 			use_prev = libc.BoolInt32(code_len == kCodeLengthRepeatCode)
  12660 			slot = code_len - kCodeLengthLiterals
  12661 			extra_bits = libc.Int32FromUint8(kCodeLengthExtraBits[slot])
  12662 			repeat_offset = libc.Int32FromUint8(kCodeLengthRepeatOffsets[slot])
  12663 			repeat = libc.Int32FromUint32(VP8LReadBits(tls, br3, extra_bits) + libc.Uint32FromInt32(repeat_offset))
  12664 			if symbol+repeat > num_symbols {
  12665 				goto End
  12666 			} else {
  12667 				if use_prev != 0 {
  12668 					v1 = prev_code_len
  12669 				} else {
  12670 					v1 = 0
  12671 				}
  12672 				length = v1
  12673 				for {
  12674 					v6 = repeat
  12675 					repeat = repeat - 1
  12676 					if !(v6 > 0) {
  12677 						break
  12678 					}
  12679 					v7 = symbol
  12680 					symbol = symbol + 1
  12681 					**(**int32)(__ccgo_up(code_lengths + uintptr(v7)*4)) = length
  12682 				}
  12683 			}
  12684 		}
  12685 	}
  12686 	ok = int32(1)
  12687 	goto End
  12688 End:
  12689 	;
  12690 	VP8LHuffmanTablesDeallocate(tls, bp)
  12691 	if !(ok != 0) {
  12692 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12693 	}
  12694 	return ok
  12695 }
  12696 
  12697 // C documentation
  12698 //
  12699 //	// 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman
  12700 //	// tree.
  12701 func ReadHuffmanCode(tls *libc.TLS, alphabet_size int32, dec uintptr, code_lengths uintptr, table uintptr) (r int32) {
  12702 	bp := tls.Alloc(80)
  12703 	defer tls.Free(80)
  12704 	var br uintptr
  12705 	var first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1 int32
  12706 	var _ /* code_length_code_lengths at bp+0 */ [19]int32
  12707 	_, _, _, _, _, _, _, _, _, _ = br, first_symbol_len_code, i, num_codes, num_symbols, ok, simple_code, size, symbol, v1
  12708 	ok = 0
  12709 	size = 0
  12710 	br = dec + 40
  12711 	simple_code = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)))
  12712 	libc.Xmemset(tls, code_lengths, 0, libc.Uint64FromInt32(alphabet_size)*uint64(4))
  12713 	if simple_code != 0 { // Read symbols, codes & code lengths directly.
  12714 		num_symbols = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)) + uint32(1))
  12715 		first_symbol_len_code = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(1)))
  12716 		if first_symbol_len_code == 0 {
  12717 			v1 = int32(1)
  12718 		} else {
  12719 			v1 = int32(8)
  12720 		}
  12721 		// The first code is either 1 bit or 8 bit code.
  12722 		symbol = libc.Int32FromUint32(VP8LReadBits(tls, br, v1))
  12723 		**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12724 		// The second code (if present), is always 8 bits long.
  12725 		if num_symbols == int32(2) {
  12726 			symbol = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(8)))
  12727 			**(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) = int32(1)
  12728 		}
  12729 		ok = int32(1)
  12730 	} else {
  12731 		**(**[19]int32)(__ccgo_up(bp)) = [19]int32{}
  12732 		num_codes = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(4)) + uint32(4))
  12733 		i = 0
  12734 		for {
  12735 			if !(i < num_codes) {
  12736 				break
  12737 			}
  12738 			(**(**[19]int32)(__ccgo_up(bp)))[kCodeLengthCodeOrder[i]] = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(3)))
  12739 			goto _2
  12740 		_2:
  12741 			;
  12742 			i = i + 1
  12743 		}
  12744 		ok = ReadHuffmanCodeLengths(tls, dec, bp, alphabet_size, code_lengths)
  12745 	}
  12746 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  12747 	if ok != 0 {
  12748 		size = VP8LBuildHuffmanTable(tls, table, int32(HUFFMAN_TABLE_BITS), code_lengths, alphabet_size)
  12749 	}
  12750 	if !(ok != 0) || size == 0 {
  12751 		return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  12752 	}
  12753 	return size
  12754 }
  12755 
  12756 func ReadHuffmanCodes(tls *libc.TLS, dec uintptr, xsize int32, ysize int32, color_cache_bits int32, allow_recursion int32) (r int32) {
  12757 	bp := tls.Alloc(16)
  12758 	defer tls.Free(16)
  12759 	var br, hdr, huffman_tables, mapped_group, mapping uintptr
  12760 	var group, huffman_pixs, huffman_precision, huffman_xsize, huffman_ysize, i, num_htree_groups, num_htree_groups_max, ok, v9 int32
  12761 	var v1, v2, v4, v5 uint32_t
  12762 	var _ /* htree_groups at bp+8 */ uintptr
  12763 	var _ /* huffman_image at bp+0 */ uintptr
  12764 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12765 	br = dec + 40
  12766 	hdr = dec + 152
  12767 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  12768 	**(**uintptr)(__ccgo_up(bp + 8)) = libc.UintptrFromInt32(0)
  12769 	huffman_tables = hdr + 80
  12770 	num_htree_groups = int32(1)
  12771 	num_htree_groups_max = int32(1)
  12772 	mapping = libc.UintptrFromInt32(0)
  12773 	ok = 0
  12774 	// Check the table has been 0 initialized (through InitMetadata).
  12775 	if allow_recursion != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  12776 		// use meta Huffman codes.
  12777 		huffman_precision = libc.Int32FromUint32(uint32(MIN_HUFFMAN_BITS) + VP8LReadBits(tls, br, int32(NUM_HUFFMAN_BITS)))
  12778 		v1 = libc.Uint32FromInt32(huffman_precision)
  12779 		v2 = (libc.Uint32FromInt32(xsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  12780 		goto _3
  12781 	_3:
  12782 		huffman_xsize = libc.Int32FromUint32(v2)
  12783 		v4 = libc.Uint32FromInt32(huffman_precision)
  12784 		v5 = (libc.Uint32FromInt32(ysize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  12785 		goto _6
  12786 	_6:
  12787 		huffman_ysize = libc.Int32FromUint32(v5)
  12788 		huffman_pixs = huffman_xsize * huffman_ysize
  12789 		if !(DecodeImageStream(tls, huffman_xsize, huffman_ysize, 0, dec, bp) != 0) {
  12790 			goto Error
  12791 		}
  12792 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits = huffman_precision
  12793 		i = 0
  12794 		for {
  12795 			if !(i < huffman_pixs) {
  12796 				break
  12797 			}
  12798 			// The huffman data is stored in red and green bytes.
  12799 			group = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  12800 			**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = libc.Uint32FromInt32(group)
  12801 			if group >= num_htree_groups_max {
  12802 				num_htree_groups_max = group + int32(1)
  12803 			}
  12804 			goto _7
  12805 		_7:
  12806 			;
  12807 			i = i + 1
  12808 		}
  12809 		// Check the validity of num_htree_groups_max. If it seems too big, use a
  12810 		// smaller value for later. This will prevent big memory allocations to end
  12811 		// up with a bad bitstream anyway.
  12812 		// The value of 1000 is totally arbitrary. We know that num_htree_groups_max
  12813 		// is smaller than (1 << 16) and should be smaller than the number of pixels
  12814 		// (though the format allows it to be bigger).
  12815 		if num_htree_groups_max > int32(1000) || num_htree_groups_max > xsize*ysize {
  12816 			// Create a mapping from the used indices to the minimal set of used
  12817 			// values [0, num_htree_groups)
  12818 			mapping = WebPSafeMalloc(tls, libc.Uint64FromInt32(num_htree_groups_max), uint64(4))
  12819 			if mapping == libc.UintptrFromInt32(0) {
  12820 				VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12821 				goto Error
  12822 			}
  12823 			// -1 means a value is unmapped, and therefore unused in the Huffman
  12824 			// image.
  12825 			libc.Xmemset(tls, mapping, int32(0xff), libc.Uint64FromInt32(num_htree_groups_max)*uint64(4))
  12826 			num_htree_groups = 0
  12827 			i = libc.Int32FromInt32(0)
  12828 			for {
  12829 				if !(i < huffman_pixs) {
  12830 					break
  12831 				}
  12832 				// Get the current mapping for the group and remap the Huffman image.
  12833 				mapped_group = mapping + uintptr(**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)))*4
  12834 				if **(**int32)(__ccgo_up(mapped_group)) == -int32(1) {
  12835 					v9 = num_htree_groups
  12836 					num_htree_groups = num_htree_groups + 1
  12837 					**(**int32)(__ccgo_up(mapped_group)) = v9
  12838 				}
  12839 				**(**uint32_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) = libc.Uint32FromInt32(**(**int32)(__ccgo_up(mapped_group)))
  12840 				goto _8
  12841 			_8:
  12842 				;
  12843 				i = i + 1
  12844 			}
  12845 		} else {
  12846 			num_htree_groups = num_htree_groups_max
  12847 		}
  12848 	}
  12849 	if (*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0 {
  12850 		goto Error
  12851 	}
  12852 	if !(ReadHuffmanCodesHelper(tls, color_cache_bits, num_htree_groups, num_htree_groups_max, mapping, dec, huffman_tables, bp+8) != 0) {
  12853 		goto Error
  12854 	}
  12855 	ok = int32(1)
  12856 	// All OK. Finalize pointers.
  12857 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image = **(**uintptr)(__ccgo_up(bp))
  12858 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups = num_htree_groups
  12859 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups = **(**uintptr)(__ccgo_up(bp + 8))
  12860 	goto Error
  12861 Error:
  12862 	;
  12863 	WebPSafeFree(tls, mapping)
  12864 	if !(ok != 0) {
  12865 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  12866 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  12867 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(bp + 8)))
  12868 	}
  12869 	return ok
  12870 }
  12871 
  12872 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) {
  12873 	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
  12874 	var code_lengths, htree_group, htrees uintptr
  12875 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  12876 	ok = 0
  12877 	if color_cache_bits > 0 {
  12878 		v1 = int32(1) << color_cache_bits
  12879 	} else {
  12880 		v1 = 0
  12881 	}
  12882 	max_alphabet_size = libc.Int32FromUint16(kAlphabetSize[0]) + v1
  12883 	table_size = libc.Int32FromUint16(kTableSize[color_cache_bits])
  12884 	code_lengths = libc.UintptrFromInt32(0)
  12885 	if mapping == libc.UintptrFromInt32(0) && num_htree_groups != num_htree_groups_max || num_htree_groups > num_htree_groups_max {
  12886 		goto Error
  12887 	}
  12888 	code_lengths = WebPSafeCalloc(tls, libc.Uint64FromInt32(max_alphabet_size), uint64(4))
  12889 	**(**uintptr)(__ccgo_up(htree_groups)) = VP8LHtreeGroupsNew(tls, num_htree_groups)
  12890 	if **(**uintptr)(__ccgo_up(htree_groups)) == libc.UintptrFromInt32(0) || code_lengths == libc.UintptrFromInt32(0) || !(VP8LHuffmanTablesAllocate(tls, num_htree_groups*table_size, huffman_tables) != 0) {
  12891 		VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  12892 		goto Error
  12893 	}
  12894 	i = 0
  12895 	for {
  12896 		if !(i < num_htree_groups_max) {
  12897 			break
  12898 		}
  12899 		// If the index "i" is unused in the Huffman image, just make sure the
  12900 		// coefficients are valid but do not store them.
  12901 		if mapping != libc.UintptrFromInt32(0) && **(**int32)(__ccgo_up(mapping + uintptr(i)*4)) == -int32(1) {
  12902 			j = 0
  12903 			for {
  12904 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12905 					break
  12906 				}
  12907 				alphabet_size = libc.Int32FromUint16(kAlphabetSize[j])
  12908 				if j == 0 && color_cache_bits > 0 {
  12909 					alphabet_size = alphabet_size + int32(1)<<color_cache_bits
  12910 				}
  12911 				// Passing in NULL so that nothing gets filled.
  12912 				if !(ReadHuffmanCode(tls, alphabet_size, dec, code_lengths, libc.UintptrFromInt32(0)) != 0) {
  12913 					goto Error
  12914 				}
  12915 				goto _3
  12916 			_3:
  12917 				;
  12918 				j = j + 1
  12919 			}
  12920 		} else {
  12921 			if mapping == libc.UintptrFromInt32(0) {
  12922 				v1 = i
  12923 			} else {
  12924 				v1 = **(**int32)(__ccgo_up(mapping + uintptr(i)*4))
  12925 			}
  12926 			htree_group = **(**uintptr)(__ccgo_up(htree_groups)) + uintptr(v1)*568
  12927 			htrees = htree_group
  12928 			total_size = 0
  12929 			is_trivial_literal = int32(1)
  12930 			max_bits = 0
  12931 			j = 0
  12932 			for {
  12933 				if !(j < int32(HUFFMAN_CODES_PER_META_CODE)) {
  12934 					break
  12935 				}
  12936 				alphabet_size1 = libc.Int32FromUint16(kAlphabetSize[j])
  12937 				if j == 0 && color_cache_bits > 0 {
  12938 					alphabet_size1 = alphabet_size1 + int32(1)<<color_cache_bits
  12939 				}
  12940 				size = ReadHuffmanCode(tls, alphabet_size1, dec, code_lengths, huffman_tables)
  12941 				**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)) = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment)).Fcurr_table
  12942 				if size == 0 {
  12943 					goto Error
  12944 				}
  12945 				if is_trivial_literal != 0 && libc.Int32FromUint8(kLiteralMap[j]) == int32(1) {
  12946 					is_trivial_literal = libc.BoolInt32(libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits) == 0)
  12947 				}
  12948 				total_size = total_size + libc.Int32FromUint8((*HuffmanCode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(htrees + uintptr(j)*8)))).Fbits)
  12949 				**(**uintptr)(__ccgo_up((*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment + 8)) += uintptr(size) * 4
  12950 				if j <= int32(ALPHA) {
  12951 					local_max_bits = **(**int32)(__ccgo_up(code_lengths))
  12952 					k = int32(1)
  12953 					for {
  12954 						if !(k < alphabet_size1) {
  12955 							break
  12956 						}
  12957 						if **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4)) > local_max_bits {
  12958 							local_max_bits = **(**int32)(__ccgo_up(code_lengths + uintptr(k)*4))
  12959 						}
  12960 						goto _6
  12961 					_6:
  12962 						;
  12963 						k = k + 1
  12964 					}
  12965 					max_bits = max_bits + local_max_bits
  12966 				}
  12967 				goto _5
  12968 			_5:
  12969 				;
  12970 				j = j + 1
  12971 			}
  12972 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal = is_trivial_literal
  12973 			(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = 0
  12974 			if is_trivial_literal != 0 {
  12975 				red = libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fvalue)
  12976 				blue = libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fvalue)
  12977 				alpha = libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fvalue)
  12978 				(*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb = libc.Uint32FromInt32(alpha)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(blue)
  12979 				if total_size == 0 && libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) < int32(NUM_LITERAL_CODES) {
  12980 					(*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code = int32(1)
  12981 					**(**uint32_t)(__ccgo_up(htree_group + 44)) |= libc.Uint32FromInt32(libc.Int32FromUint16((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(GREEN)*8))))).Fvalue) << int32(8))
  12982 				}
  12983 			}
  12984 			(*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))
  12985 			if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  12986 				BuildPackedTable(tls, htree_group)
  12987 			}
  12988 		}
  12989 		goto _2
  12990 	_2:
  12991 		;
  12992 		i = i + 1
  12993 	}
  12994 	ok = int32(1)
  12995 	goto Error
  12996 Error:
  12997 	;
  12998 	WebPSafeFree(tls, code_lengths)
  12999 	if !(ok != 0) {
  13000 		VP8LHuffmanTablesDeallocate(tls, huffman_tables)
  13001 		VP8LHtreeGroupsFree(tls, **(**uintptr)(__ccgo_up(htree_groups)))
  13002 		**(**uintptr)(__ccgo_up(htree_groups)) = libc.UintptrFromInt32(0)
  13003 	}
  13004 	return ok
  13005 }
  13006 
  13007 //------------------------------------------------------------------------------
  13008 // Scaling.
  13009 
  13010 func AllocateAndInitRescaler(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  13011 	var in_height, in_width, num_channels, out_height, out_width int32
  13012 	var memory, scaled_data, work uintptr
  13013 	var memory_size, scaled_data_size, work_size uint64_t
  13014 	_, _, _, _, _, _, _, _, _, _, _ = in_height, in_width, memory, memory_size, num_channels, out_height, out_width, scaled_data, scaled_data_size, work, work_size
  13015 	num_channels = int32(4)
  13016 	in_width = (*VP8Io)(unsafe.Pointer(io)).Fmb_w
  13017 	out_width = (*VP8Io)(unsafe.Pointer(io)).Fscaled_width
  13018 	in_height = (*VP8Io)(unsafe.Pointer(io)).Fmb_h
  13019 	out_height = (*VP8Io)(unsafe.Pointer(io)).Fscaled_height
  13020 	work_size = libc.Uint64FromInt32(int32(2)*num_channels) * libc.Uint64FromInt32(out_width) // Rescaler work area.
  13021 	scaled_data_size = libc.Uint64FromInt32(out_width)                                        // Temporary storage for scaled BGRA data.
  13022 	memory_size = uint64(104) + work_size*uint64(4) + scaled_data_size*uint64(4)
  13023 	memory = WebPSafeMalloc(tls, memory_size, uint64(1))
  13024 	if memory == libc.UintptrFromInt32(0) {
  13025 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  13026 	}
  13027 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = memory
  13028 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler = memory
  13029 	memory = memory + uintptr(104)
  13030 	work = memory
  13031 	memory = memory + uintptr(work_size*uint64(4))
  13032 	scaled_data = memory
  13033 	if !(WebPRescalerInit(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, in_width, in_height, scaled_data, out_width, out_height, 0, num_channels, work) != 0) {
  13034 		return 0
  13035 	}
  13036 	return int32(1)
  13037 }
  13038 
  13039 //------------------------------------------------------------------------------
  13040 // Export to ARGB
  13041 
  13042 // C documentation
  13043 //
  13044 //	// We have special "export" function since we need to convert from BGRA
  13045 func Export(tls *libc.TLS, rescaler2 uintptr, colorspace WEBP_CSP_MODE1, rgba_stride int32, rgba uintptr) (r int32) {
  13046 	var dst, src, v1, v4 uintptr
  13047 	var dst_width, num_lines_out, v2, v5 int32
  13048 	_, _, _, _, _, _, _, _ = dst, dst_width, num_lines_out, src, v1, v2, v4, v5
  13049 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  13050 	dst = rgba
  13051 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  13052 	num_lines_out = 0
  13053 	for {
  13054 		v1 = rescaler2
  13055 		v4 = v1
  13056 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  13057 		goto _6
  13058 	_6:
  13059 		;
  13060 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  13061 		goto _3
  13062 	_3:
  13063 		if !(v2 != 0) {
  13064 			break
  13065 		}
  13066 		WebPRescalerExportRow(tls, rescaler2)
  13067 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  13068 		VP8LConvertFromBGRA(tls, src, dst_width, colorspace, dst)
  13069 		dst = dst + uintptr(rgba_stride)
  13070 		num_lines_out = num_lines_out + 1
  13071 	}
  13072 	return num_lines_out
  13073 }
  13074 
  13075 // C documentation
  13076 //
  13077 //	// Emit scaled rows.
  13078 func EmitRescaledRowsRGBA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32, out uintptr, out_stride int32) (r int32) {
  13079 	var colorspace WEBP_CSP_MODE1
  13080 	var lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out int32
  13081 	var row_in, row_out uintptr
  13082 	_, _, _, _, _, _, _, _ = colorspace, lines_imported, lines_left, needed_lines, num_lines_in, num_lines_out, row_in, row_out
  13083 	colorspace = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  13084 	num_lines_in = 0
  13085 	num_lines_out = 0
  13086 	for num_lines_in < mb_h {
  13087 		row_in = in + uintptr(int64(num_lines_in)*int64(in_stride))
  13088 		row_out = out + uintptr(int64(num_lines_out)*int64(out_stride))
  13089 		lines_left = mb_h - num_lines_in
  13090 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  13091 		WebPMultARGBRows(tls, row_in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  13092 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, row_in, in_stride)
  13093 		num_lines_in = num_lines_in + lines_imported
  13094 		num_lines_out = num_lines_out + Export(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, colorspace, out_stride, row_out)
  13095 	}
  13096 	return num_lines_out
  13097 }
  13098 
  13099 // C documentation
  13100 //
  13101 //	// Emit rows without any scaling.
  13102 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) {
  13103 	var lines, v1 int32
  13104 	var row_out uintptr
  13105 	_, _, _ = lines, row_out, v1
  13106 	lines = mb_h
  13107 	row_out = out
  13108 	for {
  13109 		v1 = lines
  13110 		lines = lines - 1
  13111 		if !(v1 > 0) {
  13112 			break
  13113 		}
  13114 		VP8LConvertFromBGRA(tls, row_in, mb_w, colorspace, row_out)
  13115 		row_in = row_in + uintptr(in_stride)
  13116 		row_out = row_out + uintptr(out_stride)
  13117 	}
  13118 	return mb_h // Num rows out == num rows in.
  13119 }
  13120 
  13121 //------------------------------------------------------------------------------
  13122 // Export to YUVA
  13123 
  13124 func ConvertToYUVA(tls *libc.TLS, src uintptr, width int32, y_pos int32, output uintptr) {
  13125 	var a, buf, u, v uintptr
  13126 	_, _, _, _ = a, buf, u, v
  13127 	buf = output + 16
  13128 	// first, the luma plane
  13129 	(*(*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)
  13130 	// then U/V planes
  13131 	u = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride)
  13132 	v = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv + uintptr(y_pos>>int32(1)*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv_stride)
  13133 	// even lines: store values
  13134 	// odd lines: average with previous values
  13135 	(*(*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)))
  13136 	// Lastly, store alpha if needed.
  13137 	if (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa != libc.UintptrFromInt32(0) {
  13138 		a = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa + uintptr(y_pos*(*WebPYUVABuffer)(unsafe.Pointer(buf)).Fa_stride)
  13139 		(*(*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)
  13140 	}
  13141 }
  13142 
  13143 func ExportYUVA(tls *libc.TLS, dec uintptr, y_pos int32) (r int32) {
  13144 	var dst_width, num_lines_out, v2, v5 int32
  13145 	var rescaler2, src, v1, v4 uintptr
  13146 	_, _, _, _, _, _, _, _ = dst_width, num_lines_out, rescaler2, src, v1, v2, v4, v5
  13147 	rescaler2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler
  13148 	src = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst
  13149 	dst_width = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width
  13150 	num_lines_out = 0
  13151 	for {
  13152 		v1 = rescaler2
  13153 		v4 = v1
  13154 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  13155 		goto _6
  13156 	_6:
  13157 		;
  13158 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  13159 		goto _3
  13160 	_3:
  13161 		if !(v2 != 0) {
  13162 			break
  13163 		}
  13164 		WebPRescalerExportRow(tls, rescaler2)
  13165 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, src, dst_width, int32(1))
  13166 		ConvertToYUVA(tls, src, dst_width, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  13167 		y_pos = y_pos + 1
  13168 		num_lines_out = num_lines_out + 1
  13169 	}
  13170 	return num_lines_out
  13171 }
  13172 
  13173 func EmitRescaledRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_h int32) (r int32) {
  13174 	var lines_imported, lines_left, needed_lines, num_lines_in, y_pos int32
  13175 	_, _, _, _, _ = lines_imported, lines_left, needed_lines, num_lines_in, y_pos
  13176 	num_lines_in = 0
  13177 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  13178 	for num_lines_in < mb_h {
  13179 		lines_left = mb_h - num_lines_in
  13180 		needed_lines = WebPRescaleNeededLines(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left)
  13181 		WebPMultARGBRows(tls, in, in_stride, (*WebPRescaler)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler)).Fsrc_width, needed_lines, 0)
  13182 		lines_imported = WebPRescalerImport(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler, lines_left, in, in_stride)
  13183 		num_lines_in = num_lines_in + lines_imported
  13184 		in = in + uintptr(needed_lines*in_stride)
  13185 		y_pos = y_pos + ExportYUVA(tls, dec, y_pos)
  13186 	}
  13187 	return y_pos
  13188 }
  13189 
  13190 func EmitRowsYUVA(tls *libc.TLS, dec uintptr, in uintptr, in_stride int32, mb_w int32, num_rows int32) (r int32) {
  13191 	var y_pos, v1 int32
  13192 	_, _ = y_pos, v1
  13193 	y_pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  13194 	for {
  13195 		v1 = num_rows
  13196 		num_rows = num_rows - 1
  13197 		if !(v1 > 0) {
  13198 			break
  13199 		}
  13200 		ConvertToYUVA(tls, in, mb_w, y_pos, (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)
  13201 		in = in + uintptr(in_stride)
  13202 		y_pos = y_pos + 1
  13203 	}
  13204 	return y_pos
  13205 }
  13206 
  13207 //------------------------------------------------------------------------------
  13208 // Cropping.
  13209 
  13210 // C documentation
  13211 //
  13212 //	// Sets io->mb_y, io->mb_h & io->mb_w according to start row, end row and
  13213 //	// crop options. Also updates the input data pointer, so that it points to the
  13214 //	// start of the cropped window. Note that pixels are in ARGB format even if
  13215 //	// 'in_data' is uint8_t*.
  13216 //	// Returns true if the crop window is not empty.
  13217 func SetCropWindow(tls *libc.TLS, io uintptr, y_start int32, y_end int32, in_data uintptr, pixel_stride int32) (r int32) {
  13218 	var delta int32
  13219 	_ = delta
  13220 	if y_end > (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom {
  13221 		y_end = (*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom // make sure we don't overflow on last row.
  13222 	}
  13223 	if y_start < (*VP8Io)(unsafe.Pointer(io)).Fcrop_top {
  13224 		delta = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top - y_start
  13225 		y_start = (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  13226 		**(**uintptr)(__ccgo_up(in_data)) += uintptr(delta * pixel_stride)
  13227 	}
  13228 	if y_start >= y_end {
  13229 		return 0
  13230 	} // Crop window is empty.
  13231 	**(**uintptr)(__ccgo_up(in_data)) += uintptr(libc.Uint64FromInt32((*VP8Io)(unsafe.Pointer(io)).Fcrop_left) * uint64(4))
  13232 	(*VP8Io)(unsafe.Pointer(io)).Fmb_y = y_start - (*VP8Io)(unsafe.Pointer(io)).Fcrop_top
  13233 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = (*VP8Io)(unsafe.Pointer(io)).Fcrop_right - (*VP8Io)(unsafe.Pointer(io)).Fcrop_left
  13234 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = y_end - y_start
  13235 	return int32(1) // Non-empty crop window.
  13236 }
  13237 
  13238 //------------------------------------------------------------------------------
  13239 
  13240 func GetMetaIndex(tls *libc.TLS, image uintptr, xsize int32, bits int32, x int32, y int32) (r int32) {
  13241 	if bits == 0 {
  13242 		return 0
  13243 	}
  13244 	return libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(image + uintptr(xsize*(y>>bits)+x>>bits)*4)))
  13245 }
  13246 
  13247 func GetHtreeGroupForPos(tls *libc.TLS, hdr uintptr, x int32, y int32) (r uintptr) {
  13248 	var meta_index int32
  13249 	_ = meta_index
  13250 	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)
  13251 	return (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(meta_index)*568
  13252 }
  13253 
  13254 //------------------------------------------------------------------------------
  13255 // Main loop, with custom row-processing function
  13256 
  13257 type ProcessRowsFunc = uintptr
  13258 
  13259 func ApplyInverseTransforms(tls *libc.TLS, dec uintptr, start_row int32, num_rows int32, rows uintptr) {
  13260 	var cache_pixs, end_row, n, v1 int32
  13261 	var rows_in, rows_out, transform uintptr
  13262 	_, _, _, _, _, _, _ = cache_pixs, end_row, n, rows_in, rows_out, transform, v1
  13263 	n = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform
  13264 	cache_pixs = (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth * num_rows
  13265 	end_row = start_row + num_rows
  13266 	rows_in = rows
  13267 	rows_out = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13268 	// Inverse transforms.
  13269 	for {
  13270 		v1 = n
  13271 		n = n - 1
  13272 		if !(v1 > 0) {
  13273 			break
  13274 		}
  13275 		transform = dec + 280 + uintptr(n)*24
  13276 		VP8LInverseTransform(tls, transform, start_row, end_row, rows_in, rows_out)
  13277 		rows_in = rows_out
  13278 	}
  13279 	if rows_in != rows_out {
  13280 		// No transform called, hence just copy.
  13281 		libc.Xmemcpy(tls, rows_out, rows_in, libc.Uint64FromInt32(cache_pixs)*uint64(4))
  13282 	}
  13283 }
  13284 
  13285 // C documentation
  13286 //
  13287 //	// Processes (transforms, scales & color-converts) the rows decoded after the
  13288 //	// last call.
  13289 func ProcessRows(tls *libc.TLS, dec uintptr, row int32) {
  13290 	bp := tls.Alloc(16)
  13291 	defer tls.Free(16)
  13292 	var buf, io, output, rgba, rows uintptr
  13293 	var in_stride, num_rows, num_rows_out, v1, v3 int32
  13294 	var _ /* rows_data at bp+0 */ uintptr
  13295 	_, _, _, _, _, _, _, _, _, _ = buf, in_stride, io, num_rows, num_rows_out, output, rgba, rows, v1, v3
  13296 	rows = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row)*4
  13297 	num_rows = row - (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13298 	// We can't process more than NUM_ARGB_CACHE_ROWS at a time (that's the size
  13299 	// of argb_cache), but we currently don't need more than that.
  13300 	if num_rows > 0 { // Emit output.
  13301 		io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  13302 		**(**uintptr)(__ccgo_up(bp)) = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  13303 		in_stride = libc.Int32FromUint64(libc.Uint64FromInt32((*VP8Io)(unsafe.Pointer(io)).Fwidth) * uint64(4)) // in unit of RGBA
  13304 		ApplyInverseTransforms(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, num_rows, rows)
  13305 		if !(SetCropWindow(tls, io, (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row, row, bp, in_stride) != 0) {
  13306 			// Nothing to output (this time).
  13307 		} else {
  13308 			output = (*VP8LDecoder)(unsafe.Pointer(dec)).Foutput
  13309 			v1 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer(output)).Fcolorspace < int32(MODE_YUV))
  13310 			goto _2
  13311 		_2:
  13312 			if v1 != 0 { // convert to RGBA
  13313 				buf = output + 16
  13314 				rgba = (*WebPRGBABuffer)(unsafe.Pointer(buf)).Frgba + uintptr(int64((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row)*int64((*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride))
  13315 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13316 					v3 = EmitRescaledRowsRGBA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h, rgba, (*WebPRGBABuffer)(unsafe.Pointer(buf)).Fstride)
  13317 				} else {
  13318 					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)
  13319 				}
  13320 				num_rows_out = v3
  13321 				// Update 'last_out_row'.
  13322 				**(**int32)(__ccgo_up(dec + 148)) += num_rows_out
  13323 			} else { // convert to YUVA
  13324 				if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  13325 					v1 = EmitRescaledRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13326 				} else {
  13327 					v1 = EmitRowsYUVA(tls, dec, **(**uintptr)(__ccgo_up(bp)), in_stride, (*VP8Io)(unsafe.Pointer(io)).Fmb_w, (*VP8Io)(unsafe.Pointer(io)).Fmb_h)
  13328 				}
  13329 				(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13330 			}
  13331 		}
  13332 	}
  13333 	// Update 'last_row'.
  13334 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = row
  13335 }
  13336 
  13337 // C documentation
  13338 //
  13339 //	// Row-processing for the special case when alpha data contains only one
  13340 //	// transform (color indexing), and trivial non-green literals.
  13341 func Is8bOptimizable(tls *libc.TLS, hdr uintptr) (r int32) {
  13342 	var htrees uintptr
  13343 	var i int32
  13344 	_, _ = htrees, i
  13345 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13346 		return 0
  13347 	}
  13348 	// When the Huffman tree contains only one symbol, we can skip the
  13349 	// call to ReadSymbol() for red/blue/alpha channels.
  13350 	i = 0
  13351 	for {
  13352 		if !(i < (*VP8LMetadata)(unsafe.Pointer(hdr)).Fnum_htree_groups) {
  13353 			break
  13354 		}
  13355 		htrees = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups + uintptr(i)*568
  13356 		if libc.Int32FromUint8((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(RED)*8))))).Fbits) > 0 {
  13357 			return 0
  13358 		}
  13359 		if libc.Int32FromUint8((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(BLUE)*8))))).Fbits) > 0 {
  13360 			return 0
  13361 		}
  13362 		if libc.Int32FromUint8((**(**HuffmanCode)(__ccgo_up(**(**uintptr)(__ccgo_up(htrees + uintptr(ALPHA)*8))))).Fbits) > 0 {
  13363 			return 0
  13364 		}
  13365 		goto _1
  13366 	_1:
  13367 		;
  13368 		i = i + 1
  13369 	}
  13370 	return int32(1)
  13371 }
  13372 
  13373 func AlphaApplyFilter(tls *libc.TLS, alph_dec uintptr, first_row int32, last_row int32, out uintptr, stride int32) {
  13374 	var prev_line uintptr
  13375 	var y int32
  13376 	_, _ = prev_line, y
  13377 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter != int32(WEBP_FILTER_NONE) {
  13378 		prev_line = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line
  13379 		y = first_row
  13380 		for {
  13381 			if !(y < last_row) {
  13382 				break
  13383 			}
  13384 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPUnfilters[(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter]})))(tls, prev_line, out, out, stride)
  13385 			prev_line = out
  13386 			out = out + uintptr(stride)
  13387 			goto _1
  13388 		_1:
  13389 			;
  13390 			y = y + 1
  13391 		}
  13392 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fprev_line = prev_line
  13393 	}
  13394 }
  13395 
  13396 func ExtractPalettedAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  13397 	var alph_dec, in, out, transform uintptr
  13398 	var first_row, top_row, width, v1, v2 int32
  13399 	_, _, _, _, _, _, _, _, _ = alph_dec, first_row, in, out, top_row, transform, width, v1, v2
  13400 	// For vertical and gradient filtering, we need to decode the part above the
  13401 	// crop_top row, in order to have the correct spatial predictors.
  13402 	alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  13403 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_NONE) || (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Ffilter == int32(WEBP_FILTER_HORIZONTAL) {
  13404 		v1 = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fcrop_top
  13405 	} else {
  13406 		v1 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13407 	}
  13408 	top_row = v1
  13409 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row < top_row {
  13410 		v2 = top_row
  13411 	} else {
  13412 		v2 = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  13413 	}
  13414 	first_row = v2
  13415 	if last_row > first_row {
  13416 		// Special method for paletted alpha data. We only process the cropped area.
  13417 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth
  13418 		out = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput + uintptr(width*first_row)
  13419 		in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*first_row)
  13420 		transform = dec + 280
  13421 		VP8LColorIndexInverseTransformAlpha(tls, transform, first_row, last_row, in, out)
  13422 		AlphaApplyFilter(tls, alph_dec, first_row, last_row, out, width)
  13423 	}
  13424 	v1 = last_row
  13425 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  13426 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  13427 }
  13428 
  13429 //------------------------------------------------------------------------------
  13430 // Helper functions for fast pattern copy (8b and 32b)
  13431 
  13432 // C documentation
  13433 //
  13434 //	// cyclic rotation of pattern word
  13435 func Rotate8b(tls *libc.TLS, V uint32_t) (r uint32_t) {
  13436 	return V&uint32(0xff)<<int32(24) | V>>libc.Int32FromInt32(8)
  13437 }
  13438 
  13439 // C documentation
  13440 //
  13441 //	// copy 1, 2 or 4-bytes pattern
  13442 func CopySmallPattern8b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint32_t) {
  13443 	var i int32
  13444 	var v1, v2 uintptr
  13445 	_, _, _ = i, v1, v2
  13446 	// align 'dst' to 4-bytes boundary. Adjust the pattern along the way.
  13447 	for uint64(dst)&uint64(3) != 0 {
  13448 		v1 = dst
  13449 		dst = dst + 1
  13450 		v2 = src
  13451 		src = src + 1
  13452 		**(**uint8_t)(__ccgo_up(v1)) = **(**uint8_t)(__ccgo_up(v2))
  13453 		pattern = Rotate8b(tls, pattern)
  13454 		length = length - 1
  13455 	}
  13456 	// Copy the pattern 4 bytes at a time.
  13457 	i = 0
  13458 	for {
  13459 		if !(i < length>>int32(2)) {
  13460 			break
  13461 		}
  13462 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = pattern
  13463 		goto _3
  13464 	_3:
  13465 		;
  13466 		i = i + 1
  13467 	}
  13468 	// Finish with left-overs. 'pattern' is still correctly positioned,
  13469 	// so no Rotate8b() call is needed.
  13470 	i = i << int32(2)
  13471 	for {
  13472 		if !(i < length) {
  13473 			break
  13474 		}
  13475 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13476 		goto _4
  13477 	_4:
  13478 		;
  13479 		i = i + 1
  13480 	}
  13481 }
  13482 
  13483 func CopyBlock8b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13484 	bp := tls.Alloc(16)
  13485 	defer tls.Free(16)
  13486 	var i int32
  13487 	var src uintptr
  13488 	var _ /* pattern at bp+0 */ uint32_t
  13489 	_, _ = i, src
  13490 	src = dst - uintptr(dist)
  13491 	if length >= int32(8) {
  13492 		**(**uint32_t)(__ccgo_up(bp)) = uint32(0)
  13493 		switch dist {
  13494 		case int32(1):
  13495 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(src)))
  13496 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x01010101) * **(**uint32_t)(__ccgo_up(bp))
  13497 		case int32(2):
  13498 			libc.Xmemcpy(tls, bp, src, uint64(2))
  13499 			**(**uint32_t)(__ccgo_up(bp)) = uint32(0x00010001) * **(**uint32_t)(__ccgo_up(bp))
  13500 		case int32(4):
  13501 			libc.Xmemcpy(tls, bp, src, uint64(4))
  13502 		default:
  13503 			goto Copy
  13504 		}
  13505 		CopySmallPattern8b(tls, src, dst, length, **(**uint32_t)(__ccgo_up(bp)))
  13506 		return
  13507 	}
  13508 	goto Copy
  13509 Copy:
  13510 	;
  13511 	if dist >= length { // no overlap -> use memcpy()
  13512 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(length)*uint64(1))
  13513 	} else {
  13514 		i = 0
  13515 		for {
  13516 			if !(i < length) {
  13517 				break
  13518 			}
  13519 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src + uintptr(i)))
  13520 			goto _1
  13521 		_1:
  13522 			;
  13523 			i = i + 1
  13524 		}
  13525 	}
  13526 }
  13527 
  13528 // C documentation
  13529 //
  13530 //	// copy pattern of 1 or 2 uint32_t's
  13531 func CopySmallPattern32b(tls *libc.TLS, src uintptr, dst uintptr, length int32, pattern uint64_t) {
  13532 	var i int32
  13533 	var v1, v2 uintptr
  13534 	_, _, _ = i, v1, v2
  13535 	if uint64(dst)&uint64(4) != 0 { // Align 'dst' to 8-bytes boundary.
  13536 		v1 = dst
  13537 		dst += 4
  13538 		v2 = src
  13539 		src += 4
  13540 		**(**uint32_t)(__ccgo_up(v1)) = **(**uint32_t)(__ccgo_up(v2))
  13541 		pattern = pattern>>libc.Int32FromInt32(32) | pattern<<libc.Int32FromInt32(32)
  13542 		length = length - 1
  13543 	}
  13544 	i = 0
  13545 	for {
  13546 		if !(i < length>>int32(1)) {
  13547 			break
  13548 		}
  13549 		**(**uint64_t)(__ccgo_up(dst + uintptr(i)*8)) = pattern // Copy the pattern 8 bytes at a time.
  13550 		goto _3
  13551 	_3:
  13552 		;
  13553 		i = i + 1
  13554 	}
  13555 	if length&int32(1) != 0 { // Finish with left-over.
  13556 		**(**uint32_t)(__ccgo_up(dst + uintptr(i<<int32(1))*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i<<int32(1))*4))
  13557 	}
  13558 }
  13559 
  13560 func CopyBlock32b(tls *libc.TLS, dst uintptr, dist int32, length int32) {
  13561 	bp := tls.Alloc(16)
  13562 	defer tls.Free(16)
  13563 	var i int32
  13564 	var src uintptr
  13565 	var _ /* pattern at bp+0 */ uint64_t
  13566 	_, _ = i, src
  13567 	src = dst - uintptr(dist)*4
  13568 	if dist <= int32(2) && length >= int32(4) && uint64(dst)&uint64(3) == uint64(0) {
  13569 		if dist == int32(1) {
  13570 			**(**uint64_t)(__ccgo_up(bp)) = uint64(**(**uint32_t)(__ccgo_up(src)))
  13571 			**(**uint64_t)(__ccgo_up(bp)) = **(**uint64_t)(__ccgo_up(bp)) | **(**uint64_t)(__ccgo_up(bp))<<int32(32)
  13572 		} else {
  13573 			libc.Xmemcpy(tls, bp, src, uint64(8))
  13574 		}
  13575 		CopySmallPattern32b(tls, src, dst, length, **(**uint64_t)(__ccgo_up(bp)))
  13576 	} else {
  13577 		if dist >= length { // no overlap
  13578 			libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(length)*uint64(4))
  13579 		} else {
  13580 			i = 0
  13581 			for {
  13582 				if !(i < length) {
  13583 					break
  13584 				}
  13585 				**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  13586 				goto _1
  13587 			_1:
  13588 				;
  13589 				i = i + 1
  13590 			}
  13591 		}
  13592 	}
  13593 }
  13594 
  13595 //------------------------------------------------------------------------------
  13596 
  13597 func DecodeAlphaData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32) (r int32) {
  13598 	var br2, hdr, htree_group, v1 uintptr
  13599 	var code, col, dist, dist_code, dist_symbol, end, last, len_code_limit, length, length_sym, mask, ok, pos, row, v5 int32
  13600 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  13601 	ok = int32(1)
  13602 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13603 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13604 	br2 = dec + 40
  13605 	hdr = dec + 152
  13606 	pos = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel // current position
  13607 	end = width * height                                  // End of data
  13608 	last = width * last_row                               // Last pixel to decode
  13609 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13610 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13611 	if pos < last {
  13612 		v1 = GetHtreeGroupForPos(tls, hdr, col, row)
  13613 	} else {
  13614 		v1 = libc.UintptrFromInt32(0)
  13615 	}
  13616 	htree_group = v1
  13617 	for !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) && pos < last {
  13618 		// Only update when changing tile.
  13619 		if col&mask == 0 {
  13620 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13621 		}
  13622 		v1 = br2
  13623 		if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13624 			VP8LDoFillBitWindow(tls, v1)
  13625 		}
  13626 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13627 		if code < int32(NUM_LITERAL_CODES) { // Literal
  13628 			**(**uint8_t)(__ccgo_up(data + uintptr(pos))) = libc.Uint8FromInt32(code)
  13629 			pos = pos + 1
  13630 			col = col + 1
  13631 			if col >= width {
  13632 				col = 0
  13633 				row = row + 1
  13634 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13635 					ExtractPalettedAlphaRows(tls, dec, row)
  13636 				}
  13637 			}
  13638 		} else {
  13639 			if code < len_code_limit {
  13640 				length_sym = code - int32(NUM_LITERAL_CODES)
  13641 				length = GetCopyLength(tls, length_sym, br2)
  13642 				dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13643 				v1 = br2
  13644 				if (*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13645 					VP8LDoFillBitWindow(tls, v1)
  13646 				}
  13647 				dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13648 				dist = PlaneCodeToDistance(tls, width, dist_code)
  13649 				if pos >= dist && end-pos >= length {
  13650 					CopyBlock8b(tls, data+uintptr(pos), dist, length)
  13651 				} else {
  13652 					ok = 0
  13653 					goto End
  13654 				}
  13655 				pos = pos + length
  13656 				col = col + length
  13657 				for col >= width {
  13658 					col = col - width
  13659 					row = row + 1
  13660 					if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13661 						ExtractPalettedAlphaRows(tls, dec, row)
  13662 					}
  13663 				}
  13664 				if pos < last && col&mask != 0 {
  13665 					htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13666 				}
  13667 			} else { // Not reached
  13668 				ok = 0
  13669 				goto End
  13670 			}
  13671 		}
  13672 		v1 = br2
  13673 		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))
  13674 		goto _6
  13675 	_6:
  13676 		(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13677 	}
  13678 	// Process the remaining rows corresponding to last row-block.
  13679 	if row > last_row {
  13680 		v5 = last_row
  13681 	} else {
  13682 		v5 = row
  13683 	}
  13684 	ExtractPalettedAlphaRows(tls, dec, v5)
  13685 	goto End
  13686 End:
  13687 	;
  13688 	v1 = br2
  13689 	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))
  13690 	goto _10
  13691 _10:
  13692 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v5
  13693 	if !(ok != 0) || (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && pos < end {
  13694 		if (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 {
  13695 			v5 = int32(VP8_STATUS_SUSPENDED)
  13696 		} else {
  13697 			v5 = int32(VP8_STATUS_BITSTREAM_ERROR)
  13698 		}
  13699 		return VP8LSetError(tls, dec, v5)
  13700 	}
  13701 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = pos
  13702 	return ok
  13703 }
  13704 
  13705 func SaveState(tls *libc.TLS, dec uintptr, last_pixel int32) {
  13706 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br = (*VP8LDecoder)(unsafe.Pointer(dec)).Fbr
  13707 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel = last_pixel
  13708 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13709 		VP8LColorCacheCopy(tls, dec+152+8, dec+152+24)
  13710 	}
  13711 }
  13712 
  13713 func RestoreState(tls *libc.TLS, dec uintptr) {
  13714 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_SUSPENDED)
  13715 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fbr = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_br
  13716 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = (*VP8LDecoder)(unsafe.Pointer(dec)).Fsaved_last_pixel
  13717 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 {
  13718 		VP8LColorCacheCopy(tls, dec+152+24, dec+152+8)
  13719 	}
  13720 }
  13721 
  13722 func DecodeImageData(tls *libc.TLS, dec uintptr, data uintptr, width int32, height int32, last_row int32, __ccgo_fp_process_func ProcessRowsFunc) (r int32) {
  13723 	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
  13724 	var br2, color_cache, hdr, htree_group, last_cached, src, src_end, src_last, v2, v3 uintptr
  13725 	var v21 uint32_t
  13726 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  13727 	row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel / width
  13728 	col = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel % width
  13729 	br2 = dec + 40
  13730 	hdr = dec + 152
  13731 	src = data + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel)*4
  13732 	last_cached = src
  13733 	src_end = data + uintptr(width*height)*4    // End of data
  13734 	src_last = data + uintptr(width*last_row)*4 // Last pixel to decode
  13735 	len_code_limit = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES)
  13736 	color_cache_limit = len_code_limit + (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size
  13737 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  13738 		v1 = row
  13739 	} else {
  13740 		v1 = libc.Int32FromInt32(1) << libc.Int32FromInt32(24)
  13741 	}
  13742 	next_sync_row = v1
  13743 	if (*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size > 0 {
  13744 		v2 = hdr + 8
  13745 	} else {
  13746 		v2 = libc.UintptrFromInt32(0)
  13747 	}
  13748 	color_cache = v2
  13749 	mask = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask
  13750 	if src < src_last {
  13751 		v3 = GetHtreeGroupForPos(tls, hdr, col, row)
  13752 	} else {
  13753 		v3 = libc.UintptrFromInt32(0)
  13754 	}
  13755 	htree_group = v3
  13756 _5:
  13757 	;
  13758 	if !(src < src_last) {
  13759 		goto _4
  13760 	}
  13761 	if row >= next_sync_row {
  13762 		SaveState(tls, dec, int32((int64(src)-int64(data))/4))
  13763 		next_sync_row = row + int32(SYNC_EVERY_N_ROWS)
  13764 	}
  13765 	// Only update when changing tile. Note we could use this test:
  13766 	// if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed
  13767 	// but that's actually slower and needs storing the previous col/row.
  13768 	if col&mask == 0 {
  13769 		htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13770 	}
  13771 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_code != 0 {
  13772 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb
  13773 		goto AdvanceByOne
  13774 	}
  13775 	v2 = br2
  13776 	if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13777 		VP8LDoFillBitWindow(tls, v2)
  13778 	}
  13779 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fuse_packed_table != 0 {
  13780 		code = ReadPackedSymbols(tls, htree_group, br2, src)
  13781 		v2 = br2
  13782 		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))
  13783 		goto _9
  13784 	_9:
  13785 		if v1 != 0 {
  13786 			goto _4
  13787 		}
  13788 		if code == PACKED_NON_LITERAL_CODE {
  13789 			goto AdvanceByOne
  13790 		}
  13791 	} else {
  13792 		code = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(GREEN)*8)), br2)
  13793 	}
  13794 	v2 = br2
  13795 	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))
  13796 	goto _12
  13797 _12:
  13798 	if v1 != 0 {
  13799 		goto _4
  13800 	}
  13801 	if !(code < int32(NUM_LITERAL_CODES)) {
  13802 		goto _13
  13803 	} // Literal
  13804 	if (*HTreeGroup)(unsafe.Pointer(htree_group)).Fis_trivial_literal != 0 {
  13805 		**(**uint32_t)(__ccgo_up(src)) = (*HTreeGroup)(unsafe.Pointer(htree_group)).Fliteral_arb | libc.Uint32FromInt32(code<<libc.Int32FromInt32(8))
  13806 	} else {
  13807 		red = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(RED)*8)), br2)
  13808 		v2 = br2
  13809 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13810 			VP8LDoFillBitWindow(tls, v2)
  13811 		}
  13812 		blue = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(BLUE)*8)), br2)
  13813 		alpha = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(ALPHA)*8)), br2)
  13814 		v2 = br2
  13815 		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))
  13816 		goto _18
  13817 	_18:
  13818 		if v1 != 0 {
  13819 			goto _4
  13820 		}
  13821 		**(**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)
  13822 	}
  13823 	goto AdvanceByOne
  13824 AdvanceByOne:
  13825 	;
  13826 	src += 4
  13827 	col = col + 1
  13828 	if col >= width {
  13829 		col = 0
  13830 		row = row + 1
  13831 		if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13832 			if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13833 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13834 			}
  13835 		}
  13836 		if color_cache != libc.UintptrFromInt32(0) {
  13837 			for last_cached < src {
  13838 				v2 = last_cached
  13839 				last_cached += 4
  13840 				v3 = color_cache
  13841 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13842 				v1 = libc.Int32FromUint32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13843 				goto _23
  13844 			_23:
  13845 				key1 = v1
  13846 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13847 			}
  13848 		}
  13849 	}
  13850 	goto _14
  13851 _13:
  13852 	;
  13853 	if code < len_code_limit {
  13854 		length_sym = code - int32(NUM_LITERAL_CODES)
  13855 		length = GetCopyLength(tls, length_sym, br2)
  13856 		dist_symbol = ReadSymbol(tls, **(**uintptr)(__ccgo_up(htree_group + uintptr(DIST)*8)), br2)
  13857 		v2 = br2
  13858 		if (*VP8LBitReader)(unsafe.Pointer(v2)).Fbit_pos >= libc.Int32FromInt32(VP8L_WBITS) {
  13859 			VP8LDoFillBitWindow(tls, v2)
  13860 		}
  13861 		dist_code = GetCopyDistance(tls, dist_symbol, br2)
  13862 		dist = PlaneCodeToDistance(tls, width, dist_code)
  13863 		v2 = br2
  13864 		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))
  13865 		goto _27
  13866 	_27:
  13867 		if v1 != 0 {
  13868 			goto _4
  13869 		}
  13870 		if (int64(src)-int64(data))/4 < int64(dist) || (int64(src_end)-int64(src))/4 < int64(length) {
  13871 			goto Error
  13872 		} else {
  13873 			CopyBlock32b(tls, src, dist, length)
  13874 		}
  13875 		src = src + uintptr(length)*4
  13876 		col = col + length
  13877 		for col >= width {
  13878 			col = col - width
  13879 			row = row + 1
  13880 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13881 				if row <= last_row && row%int32(NUM_ARGB_CACHE_ROWS) == 0 {
  13882 					(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, row)
  13883 				}
  13884 			}
  13885 		}
  13886 		// Because of the check done above (before 'src' was incremented by
  13887 		// 'length'), the following holds true.
  13888 		if col&mask != 0 {
  13889 			htree_group = GetHtreeGroupForPos(tls, hdr, col, row)
  13890 		}
  13891 		if color_cache != libc.UintptrFromInt32(0) {
  13892 			for last_cached < src {
  13893 				v2 = last_cached
  13894 				last_cached += 4
  13895 				v3 = color_cache
  13896 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13897 				v1 = libc.Int32FromUint32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13898 				goto _32
  13899 			_32:
  13900 				key1 = v1
  13901 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13902 			}
  13903 		}
  13904 	} else {
  13905 		if code < color_cache_limit { // Color cache
  13906 			key2 = code - len_code_limit
  13907 			for last_cached < src {
  13908 				v2 = last_cached
  13909 				last_cached += 4
  13910 				v3 = color_cache
  13911 				v21 = **(**uint32_t)(__ccgo_up(v2))
  13912 				v1 = libc.Int32FromUint32(v21 * kHashMul8 >> (*VP8LColorCache)(unsafe.Pointer(v3)).Fhash_shift)
  13913 				goto _37
  13914 			_37:
  13915 				key1 = v1
  13916 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v3)).Fcolors + uintptr(key1)*4)) = v21
  13917 			}
  13918 			v21 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors + uintptr(libc.Uint32FromInt32(key2))*4))
  13919 			goto _39
  13920 		_39:
  13921 			**(**uint32_t)(__ccgo_up(src)) = v21
  13922 			goto AdvanceByOne
  13923 		} else { // Not reached
  13924 			goto Error
  13925 		}
  13926 	}
  13927 _14:
  13928 	;
  13929 	goto _5
  13930 _4:
  13931 	;
  13932 	v2 = br2
  13933 	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))
  13934 	goto _42
  13935 _42:
  13936 	(*VP8LBitReader)(unsafe.Pointer(br2)).Feos = v1
  13937 	// In incremental decoding:
  13938 	// br->eos && src < src_last: if 'br' reached the end of the buffer and
  13939 	// 'src_last' has not been reached yet, there is not enough data. 'dec' has to
  13940 	// be reset until there is more data.
  13941 	// !br->eos && src < src_last: this cannot happen as either the buffer is
  13942 	// fully read, either enough has been read to reach 'src_last'.
  13943 	// src >= src_last: 'src_last' is reached, all is fine. 'src' can actually go
  13944 	// beyond 'src_last' in case the image is cropped and an LZ77 goes further.
  13945 	// The buffer might have been enough or there is some left. 'br->eos' does
  13946 	// not matter.
  13947 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && (*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0 && src < src_last {
  13948 		RestoreState(tls, dec)
  13949 	} else {
  13950 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 && src >= src_last || !((*VP8LBitReader)(unsafe.Pointer(br2)).Feos != 0) {
  13951 			// Process the remaining rows corresponding to last row-block.
  13952 			if __ccgo_fp_process_func != libc.UintptrFromInt32(0) {
  13953 				if row > last_row {
  13954 					v1 = last_row
  13955 				} else {
  13956 					v1 = row
  13957 				}
  13958 				(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_process_func})))(tls, dec, v1)
  13959 			}
  13960 			(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  13961 			(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = int32((int64(src) - int64(data)) / 4) // end-of-scan marker
  13962 		} else {
  13963 			// if not incremental, and we are past the end of buffer (eos=1), then this
  13964 			// is a real bitstream error.
  13965 			goto Error
  13966 		}
  13967 	}
  13968 	return int32(1)
  13969 	goto Error
  13970 Error:
  13971 	;
  13972 	return VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  13973 	return r
  13974 }
  13975 
  13976 // -----------------------------------------------------------------------------
  13977 // VP8LTransform
  13978 
  13979 func ClearTransform(tls *libc.TLS, transform uintptr) {
  13980 	WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  13981 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  13982 }
  13983 
  13984 // C documentation
  13985 //
  13986 //	// For security reason, we need to remap the color map to span
  13987 //	// the total possible bundled values, and not just the num_colors.
  13988 func ExpandColorMap(tls *libc.TLS, num_colors int32, transform uintptr) (r int32) {
  13989 	var data, new_color_map, new_data uintptr
  13990 	var final_num_colors, i int32
  13991 	_, _, _, _, _ = data, final_num_colors, i, new_color_map, new_data
  13992 	final_num_colors = int32(1) << (int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  13993 	new_color_map = WebPSafeMalloc(tls, libc.Uint64FromInt32(final_num_colors), uint64(4))
  13994 	if new_color_map == libc.UintptrFromInt32(0) {
  13995 		return 0
  13996 	} else {
  13997 		data = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  13998 		new_data = new_color_map
  13999 		**(**uint32_t)(__ccgo_up(new_color_map)) = **(**uint32_t)(__ccgo_up((*VP8LTransform)(unsafe.Pointer(transform)).Fdata))
  14000 		i = int32(4)
  14001 		for {
  14002 			if !(i < int32(4)*num_colors) {
  14003 				break
  14004 			}
  14005 			// Equivalent to VP8LAddPixels(), on a byte-basis.
  14006 			**(**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))
  14007 			goto _1
  14008 		_1:
  14009 			;
  14010 			i = i + 1
  14011 		}
  14012 		for {
  14013 			if !(i < int32(4)*final_num_colors) {
  14014 				break
  14015 			}
  14016 			**(**uint8_t)(__ccgo_up(new_data + uintptr(i))) = uint8(0) // black tail.
  14017 			goto _2
  14018 		_2:
  14019 			;
  14020 			i = i + 1
  14021 		}
  14022 		WebPSafeFree(tls, (*VP8LTransform)(unsafe.Pointer(transform)).Fdata)
  14023 		(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = new_color_map
  14024 	}
  14025 	return int32(1)
  14026 }
  14027 
  14028 func ReadTransform(tls *libc.TLS, xsize uintptr, ysize uintptr, dec uintptr) (r int32) {
  14029 	var bits, num_colors, ok, v7, v8, v9 int32
  14030 	var br, transform uintptr
  14031 	var type1 VP8LImageTransformType
  14032 	var v1, v2, v4, v5 uint32_t
  14033 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bits, br, num_colors, ok, transform, type1, v1, v2, v4, v5, v7, v8, v9
  14034 	ok = int32(1)
  14035 	br = dec + 40
  14036 	transform = dec + 280 + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform)*24
  14037 	type1 = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(2)))
  14038 	// Each transform type can only be present once in the stream.
  14039 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen&(uint32(1)<<type1) != 0 {
  14040 		return 0 // Already there, let's not accept the second same transform.
  14041 	}
  14042 	**(**uint32_t)(__ccgo_up(dec + 376)) |= uint32(1) << type1
  14043 	(*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 = type1
  14044 	(*VP8LTransform)(unsafe.Pointer(transform)).Fxsize = **(**int32)(__ccgo_up(xsize))
  14045 	(*VP8LTransform)(unsafe.Pointer(transform)).Fysize = **(**int32)(__ccgo_up(ysize))
  14046 	(*VP8LTransform)(unsafe.Pointer(transform)).Fdata = libc.UintptrFromInt32(0)
  14047 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform + 1
  14048 	switch type1 {
  14049 	case int32(PREDICTOR_TRANSFORM):
  14050 		fallthrough
  14051 	case int32(CROSS_COLOR_TRANSFORM):
  14052 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = libc.Int32FromUint32(uint32(MIN_TRANSFORM_BITS) + VP8LReadBits(tls, br, int32(NUM_TRANSFORM_BITS)))
  14053 		v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  14054 		v2 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14055 		goto _3
  14056 	_3:
  14057 		v4 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  14058 		v5 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fysize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  14059 		goto _6
  14060 	_6:
  14061 		ok = DecodeImageStream(tls, libc.Int32FromUint32(v2), libc.Int32FromUint32(v5), 0, dec, transform+16)
  14062 	case int32(COLOR_INDEXING_TRANSFORM):
  14063 		num_colors = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(8)) + uint32(1))
  14064 		if num_colors > int32(16) {
  14065 			v7 = 0
  14066 		} else {
  14067 			if num_colors > int32(4) {
  14068 				v8 = int32(1)
  14069 			} else {
  14070 				if num_colors > int32(2) {
  14071 					v9 = int32(2)
  14072 				} else {
  14073 					v9 = int32(3)
  14074 				}
  14075 				v8 = v9
  14076 			}
  14077 			v7 = v8
  14078 		}
  14079 		bits = v7
  14080 		v1 = libc.Uint32FromInt32(bits)
  14081 		v2 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14082 		goto _12
  14083 	_12:
  14084 		**(**int32)(__ccgo_up(xsize)) = libc.Int32FromUint32(v2)
  14085 		(*VP8LTransform)(unsafe.Pointer(transform)).Fbits = bits
  14086 		ok = DecodeImageStream(tls, num_colors, int32(1), 0, dec, transform+16)
  14087 		if ok != 0 && !(ExpandColorMap(tls, num_colors, transform) != 0) {
  14088 			return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14089 		}
  14090 	case int32(SUBTRACT_GREEN_TRANSFORM):
  14091 	default:
  14092 		// can't happen
  14093 		break
  14094 	}
  14095 	return ok
  14096 }
  14097 
  14098 // -----------------------------------------------------------------------------
  14099 // VP8LMetadata
  14100 
  14101 func InitMetadata(tls *libc.TLS, hdr uintptr) {
  14102 	libc.Xmemset(tls, hdr, 0, uint64(120))
  14103 }
  14104 
  14105 func ClearMetadata(tls *libc.TLS, hdr uintptr) {
  14106 	WebPSafeFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_image)
  14107 	VP8LHuffmanTablesDeallocate(tls, hdr+80)
  14108 	VP8LHtreeGroupsFree(tls, (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhtree_groups)
  14109 	VP8LColorCacheClear(tls, hdr+8)
  14110 	VP8LColorCacheClear(tls, hdr+24)
  14111 	InitMetadata(tls, hdr)
  14112 }
  14113 
  14114 // -----------------------------------------------------------------------------
  14115 // VP8LDecoder
  14116 
  14117 func VP8LNew(tls *libc.TLS) (r uintptr) {
  14118 	var dec uintptr
  14119 	_ = dec
  14120 	dec = WebPSafeCalloc(tls, uint64(1), uint64(400))
  14121 	if dec == libc.UintptrFromInt32(0) {
  14122 		return libc.UintptrFromInt32(0)
  14123 	}
  14124 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14125 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14126 	VP8LDspInit(tls) // Init critical function pointers.
  14127 	return dec
  14128 }
  14129 
  14130 // C documentation
  14131 //
  14132 //	// Resets the decoder in its initial state, reclaiming memory.
  14133 //	// Preserves the dec->status value.
  14134 func VP8LClear(tls *libc.TLS, dec uintptr) {
  14135 	var i int32
  14136 	_ = i
  14137 	if dec == libc.UintptrFromInt32(0) {
  14138 		return
  14139 	}
  14140 	ClearMetadata(tls, dec+152)
  14141 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels)
  14142 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = libc.UintptrFromInt32(0)
  14143 	i = 0
  14144 	for {
  14145 		if !(i < (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform) {
  14146 			break
  14147 		}
  14148 		ClearTransform(tls, dec+280+uintptr(i)*24)
  14149 		goto _1
  14150 	_1:
  14151 		;
  14152 		i = i + 1
  14153 	}
  14154 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform = 0
  14155 	(*VP8LDecoder)(unsafe.Pointer(dec)).Ftransforms_seen = uint32(0)
  14156 	WebPSafeFree(tls, (*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory)
  14157 	(*VP8LDecoder)(unsafe.Pointer(dec)).Frescaler_memory = libc.UintptrFromInt32(0)
  14158 	(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = libc.UintptrFromInt32(0) // leave no trace behind
  14159 }
  14160 
  14161 func VP8LDelete(tls *libc.TLS, dec uintptr) {
  14162 	if dec != libc.UintptrFromInt32(0) {
  14163 		VP8LClear(tls, dec)
  14164 		WebPSafeFree(tls, dec)
  14165 	}
  14166 }
  14167 
  14168 func UpdateDecoder(tls *libc.TLS, dec uintptr, width int32, height int32) {
  14169 	var hdr uintptr
  14170 	var num_bits, v4 int32
  14171 	var v1, v2 uint32_t
  14172 	_, _, _, _, _ = hdr, num_bits, v1, v2, v4
  14173 	hdr = dec + 152
  14174 	num_bits = (*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_subsample_bits
  14175 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = width
  14176 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = height
  14177 	v1 = libc.Uint32FromInt32(num_bits)
  14178 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  14179 	goto _3
  14180 _3:
  14181 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_xsize = libc.Int32FromUint32(v2)
  14182 	if num_bits == 0 {
  14183 		v4 = ^libc.Int32FromInt32(0)
  14184 	} else {
  14185 		v4 = int32(1)<<num_bits - int32(1)
  14186 	}
  14187 	(*VP8LMetadata)(unsafe.Pointer(hdr)).Fhuffman_mask = v4
  14188 }
  14189 
  14190 func DecodeImageStream(tls *libc.TLS, xsize int32, ysize int32, is_level0 int32, dec uintptr, decoded_data uintptr) (r int32) {
  14191 	bp := tls.Alloc(16)
  14192 	defer tls.Free(16)
  14193 	var br, data, hdr uintptr
  14194 	var color_cache_bits, ok int32
  14195 	var total_size uint64_t
  14196 	var _ /* transform_xsize at bp+0 */ int32
  14197 	var _ /* transform_ysize at bp+4 */ int32
  14198 	_, _, _, _, _, _ = br, color_cache_bits, data, hdr, ok, total_size
  14199 	ok = int32(1)
  14200 	**(**int32)(__ccgo_up(bp)) = xsize
  14201 	**(**int32)(__ccgo_up(bp + 4)) = ysize
  14202 	br = dec + 40
  14203 	hdr = dec + 152
  14204 	data = libc.UintptrFromInt32(0)
  14205 	color_cache_bits = 0
  14206 	// Read the transforms (may recurse).
  14207 	if is_level0 != 0 {
  14208 		for ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  14209 			ok = ReadTransform(tls, bp, bp+4, dec)
  14210 		}
  14211 	}
  14212 	// Color cache
  14213 	if ok != 0 && VP8LReadBits(tls, br, int32(1)) != 0 {
  14214 		color_cache_bits = libc.Int32FromUint32(VP8LReadBits(tls, br, int32(4)))
  14215 		ok = libc.BoolInt32(color_cache_bits >= int32(1) && color_cache_bits <= int32(MAX_CACHE_BITS))
  14216 		if !(ok != 0) {
  14217 			VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14218 			goto End
  14219 		}
  14220 	}
  14221 	// Read the Huffman codes (may recurse).
  14222 	ok = libc.BoolInt32(ok != 0 && ReadHuffmanCodes(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), color_cache_bits, is_level0) != 0)
  14223 	if !(ok != 0) {
  14224 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14225 		goto End
  14226 	}
  14227 	// Finish setting up the color-cache
  14228 	if color_cache_bits > 0 {
  14229 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = int32(1) << color_cache_bits
  14230 		if !(VP8LColorCacheInit(tls, hdr+8, color_cache_bits) != 0) {
  14231 			ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14232 			goto End
  14233 		}
  14234 	} else {
  14235 		(*VP8LMetadata)(unsafe.Pointer(hdr)).Fcolor_cache_size = 0
  14236 	}
  14237 	UpdateDecoder(tls, dec, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
  14238 	if is_level0 != 0 { // level 0 complete
  14239 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_HDR)
  14240 		goto End
  14241 	}
  14242 	total_size = libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp))) * libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 4)))
  14243 	data = WebPSafeMalloc(tls, total_size, uint64(4))
  14244 	if data == libc.UintptrFromInt32(0) {
  14245 		ok = VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14246 		goto End
  14247 	}
  14248 	// Use the Huffman trees to decode the LZ77 encoded data.
  14249 	ok = DecodeImageData(tls, dec, data, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), **(**int32)(__ccgo_up(bp + 4)), libc.UintptrFromInt32(0))
  14250 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitReader)(unsafe.Pointer(br)).Feos != 0))
  14251 	goto End
  14252 End:
  14253 	;
  14254 	if !(ok != 0) {
  14255 		WebPSafeFree(tls, data)
  14256 		ClearMetadata(tls, hdr)
  14257 	} else {
  14258 		if decoded_data != libc.UintptrFromInt32(0) {
  14259 			**(**uintptr)(__ccgo_up(decoded_data)) = data
  14260 		} else {
  14261 			// We allocate image data in this function only for transforms. At level 0
  14262 			// (that is: not the transforms), we shouldn't have allocated anything.
  14263 		}
  14264 		(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_pixel = 0 // Reset for future DECODE_DATA_FUNC() calls.
  14265 		if !(is_level0 != 0) {
  14266 			ClearMetadata(tls, hdr)
  14267 		} // Clean up temporary data behind.
  14268 	}
  14269 	return ok
  14270 }
  14271 
  14272 // C documentation
  14273 //
  14274 //	//------------------------------------------------------------------------------
  14275 //	// Allocate internal buffers dec->pixels and dec->argb_cache.
  14276 func AllocateInternalBuffers32b(tls *libc.TLS, dec uintptr, final_width int32) (r int32) {
  14277 	var cache_pixels, cache_top_pixels, num_pixels, total_num_pixels uint64_t
  14278 	_, _, _, _ = cache_pixels, cache_top_pixels, num_pixels, total_num_pixels
  14279 	num_pixels = libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14280 	// Scratch buffer corresponding to top-prediction row for transforming the
  14281 	// first row in the row-blocks. Not needed for paletted alpha.
  14282 	cache_top_pixels = uint64(libc.Uint16FromInt32(final_width))
  14283 	// Scratch buffer for temporary BGRA storage. Not needed for paletted alpha.
  14284 	cache_pixels = libc.Uint64FromInt32(final_width) * uint64(NUM_ARGB_CACHE_ROWS)
  14285 	total_num_pixels = num_pixels + cache_top_pixels + cache_pixels
  14286 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(4))
  14287 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14288 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14289 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14290 	}
  14291 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr(num_pixels)*4 + uintptr(cache_top_pixels)*4
  14292 	return int32(1)
  14293 }
  14294 
  14295 func AllocateInternalBuffers8b(tls *libc.TLS, dec uintptr) (r int32) {
  14296 	var total_num_pixels uint64_t
  14297 	_ = total_num_pixels
  14298 	total_num_pixels = libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth) * libc.Uint64FromInt32((*VP8LDecoder)(unsafe.Pointer(dec)).Fheight)
  14299 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache = libc.UintptrFromInt32(0) // for soundness
  14300 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels = WebPSafeMalloc(tls, total_num_pixels, uint64(1))
  14301 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels == libc.UintptrFromInt32(0) {
  14302 		return VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14303 	}
  14304 	return int32(1)
  14305 }
  14306 
  14307 //------------------------------------------------------------------------------
  14308 
  14309 // C documentation
  14310 //
  14311 //	// Special row-processing that only stores the alpha data.
  14312 func ExtractAlphaRows(tls *libc.TLS, dec uintptr, last_row int32) {
  14313 	var alph_dec, dst, in, output, src uintptr
  14314 	var cache_pixs, cur_row, num_rows, num_rows_to_process, width, v1 int32
  14315 	_, _, _, _, _, _, _, _, _, _, _ = alph_dec, cache_pixs, cur_row, dst, in, num_rows, num_rows_to_process, output, src, width, v1
  14316 	cur_row = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row
  14317 	num_rows = last_row - cur_row
  14318 	in = (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels + uintptr((*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth*cur_row)*4
  14319 	for num_rows > 0 {
  14320 		if num_rows > int32(NUM_ARGB_CACHE_ROWS) {
  14321 			v1 = int32(NUM_ARGB_CACHE_ROWS)
  14322 		} else {
  14323 			v1 = num_rows
  14324 		}
  14325 		num_rows_to_process = v1
  14326 		// Extract alpha (which is stored in the green plane).
  14327 		alph_dec = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque
  14328 		output = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Foutput
  14329 		width = (*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth // the final width (!= dec->width)
  14330 		cache_pixs = width * num_rows_to_process
  14331 		dst = output + uintptr(width*cur_row)
  14332 		src = (*VP8LDecoder)(unsafe.Pointer(dec)).Fargb_cache
  14333 		ApplyInverseTransforms(tls, dec, cur_row, num_rows_to_process, in)
  14334 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPExtractGreen})))(tls, src, dst, cache_pixs)
  14335 		AlphaApplyFilter(tls, alph_dec, cur_row, cur_row+num_rows_to_process, dst, width)
  14336 		num_rows = num_rows - num_rows_to_process
  14337 		in = in + uintptr(num_rows_to_process*(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth)*4
  14338 		cur_row = cur_row + num_rows_to_process
  14339 	}
  14340 	v1 = last_row
  14341 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row = v1
  14342 	(*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row = v1
  14343 }
  14344 
  14345 func VP8LDecodeAlphaHeader(tls *libc.TLS, alph_dec uintptr, data uintptr, data_size size_t) (r int32) {
  14346 	var dec uintptr
  14347 	var ok int32
  14348 	_, _ = dec, ok
  14349 	ok = 0
  14350 	dec = VP8LNew(tls)
  14351 	if dec == libc.UintptrFromInt32(0) {
  14352 		return 0
  14353 	}
  14354 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14355 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14356 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = alph_dec + 32
  14357 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fopaque = alph_dec
  14358 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fwidth = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth
  14359 	(*VP8Io)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Fio)).Fheight = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight
  14360 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14361 	VP8LInitBitReader(tls, dec+40, data, data_size)
  14362 	if !(DecodeImageStream(tls, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fheight, int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14363 		goto Err
  14364 	}
  14365 	// Special case: if alpha data uses only the color indexing transform and
  14366 	// doesn't use color cache (a frequent case), we will use DecodeAlphaData()
  14367 	// method that only needs allocation of 1 byte per pixel (alpha channel).
  14368 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fnext_transform == int32(1) && (**(**VP8LTransform)(__ccgo_up(dec + 280))).Ftype1 == int32(COLOR_INDEXING_TRANSFORM) && Is8bOptimizable(tls, dec+152) != 0 {
  14369 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = int32(1)
  14370 		ok = AllocateInternalBuffers8b(tls, dec)
  14371 	} else {
  14372 		// Allocate internal buffers (note that dec->width may have changed here).
  14373 		(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode = 0
  14374 		ok = AllocateInternalBuffers32b(tls, dec, (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fwidth)
  14375 	}
  14376 	if !(ok != 0) {
  14377 		goto Err
  14378 	}
  14379 	// Only set here, once we are sure it is valid (to avoid thread races).
  14380 	(*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec = dec
  14381 	return int32(1)
  14382 	goto Err
  14383 Err:
  14384 	;
  14385 	VP8LDelete(tls, dec)
  14386 	return 0
  14387 }
  14388 
  14389 func VP8LDecodeAlphaImageStream(tls *libc.TLS, alph_dec uintptr, last_row int32) (r int32) {
  14390 	var dec uintptr
  14391 	var v1 int32
  14392 	_, _ = dec, v1
  14393 	dec = (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fvp8l_dec
  14394 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_row >= last_row {
  14395 		return int32(1) // done
  14396 	}
  14397 	if !((*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0) {
  14398 		WebPInitAlphaProcessing(tls)
  14399 	}
  14400 	// Decode (with special row processing).
  14401 	if (*ALPHDecoder)(unsafe.Pointer(alph_dec)).Fuse_8b_decode != 0 {
  14402 		v1 = DecodeAlphaData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row)
  14403 	} else {
  14404 		v1 = DecodeImageData(tls, dec, (*VP8LDecoder)(unsafe.Pointer(dec)).Fpixels, (*VP8LDecoder)(unsafe.Pointer(dec)).Fwidth, (*VP8LDecoder)(unsafe.Pointer(dec)).Fheight, last_row, __ccgo_fp(ExtractAlphaRows))
  14405 	}
  14406 	return v1
  14407 }
  14408 
  14409 //------------------------------------------------------------------------------
  14410 
  14411 func VP8LDecodeHeader(tls *libc.TLS, dec uintptr, io uintptr) (r int32) {
  14412 	bp := tls.Alloc(16)
  14413 	defer tls.Free(16)
  14414 	var _ /* has_alpha at bp+8 */ int32
  14415 	var _ /* height at bp+4 */ int32
  14416 	var _ /* width at bp+0 */ int32
  14417 	if dec == libc.UintptrFromInt32(0) {
  14418 		return 0
  14419 	}
  14420 	if io == libc.UintptrFromInt32(0) {
  14421 		return VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14422 	}
  14423 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fio = io
  14424 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstatus = int32(VP8_STATUS_OK)
  14425 	VP8LInitBitReader(tls, dec+40, (*VP8Io)(unsafe.Pointer(io)).Fdata, (*VP8Io)(unsafe.Pointer(io)).Fdata_size)
  14426 	if !(ReadImageInfo(tls, dec+40, bp, bp+4, bp+8) != 0) {
  14427 		VP8LSetError(tls, dec, int32(VP8_STATUS_BITSTREAM_ERROR))
  14428 		goto Error
  14429 	}
  14430 	(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DIM)
  14431 	(*VP8Io)(unsafe.Pointer(io)).Fwidth = **(**int32)(__ccgo_up(bp))
  14432 	(*VP8Io)(unsafe.Pointer(io)).Fheight = **(**int32)(__ccgo_up(bp + 4))
  14433 	if !(DecodeImageStream(tls, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), int32(1), dec, libc.UintptrFromInt32(0)) != 0) {
  14434 		goto Error
  14435 	}
  14436 	return int32(1)
  14437 	goto Error
  14438 Error:
  14439 	;
  14440 	VP8LClear(tls, dec)
  14441 	return 0
  14442 }
  14443 
  14444 func VP8LDecodeImage(tls *libc.TLS, dec uintptr) (r int32) {
  14445 	var io, params uintptr
  14446 	var v1 WEBP_CSP_MODE1
  14447 	var v2 int32
  14448 	var v4 bool
  14449 	_, _, _, _, _ = io, params, v1, v2, v4
  14450 	io = libc.UintptrFromInt32(0)
  14451 	params = libc.UintptrFromInt32(0)
  14452 	if dec == libc.UintptrFromInt32(0) {
  14453 		return 0
  14454 	}
  14455 	io = (*VP8LDecoder)(unsafe.Pointer(dec)).Fio
  14456 	params = (*VP8Io)(unsafe.Pointer(io)).Fopaque
  14457 	// Initialization.
  14458 	if (*VP8LDecoder)(unsafe.Pointer(dec)).Fstate != int32(READ_DATA) {
  14459 		(*VP8LDecoder)(unsafe.Pointer(dec)).Foutput = (*WebPDecParams)(unsafe.Pointer(params)).Foutput
  14460 		if !(WebPIoInitFromOptions(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, io, int32(MODE_BGRA)) != 0) {
  14461 			VP8LSetError(tls, dec, int32(VP8_STATUS_INVALID_PARAM))
  14462 			goto Err
  14463 		}
  14464 		if !(AllocateInternalBuffers32b(tls, dec, (*VP8Io)(unsafe.Pointer(io)).Fwidth) != 0) {
  14465 			goto Err
  14466 		}
  14467 		if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 && !(AllocateAndInitRescaler(tls, dec, io) != 0) {
  14468 			goto Err
  14469 		}
  14470 		if v4 = (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0; !v4 {
  14471 			v1 = (*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace
  14472 			v2 = libc.BoolInt32(v1 == int32(MODE_rgbA) || v1 == int32(MODE_bgrA) || v1 == int32(MODE_Argb) || v1 == int32(MODE_rgbA_4444))
  14473 			goto _3
  14474 		_3:
  14475 		}
  14476 		if v4 || v2 != 0 {
  14477 			// need the alpha-multiply functions for premultiplied output or rescaling
  14478 			WebPInitAlphaProcessing(tls)
  14479 		}
  14480 		v2 = libc.BoolInt32((*WebPDecBuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput)).Fcolorspace < int32(MODE_YUV))
  14481 		goto _6
  14482 	_6:
  14483 		if !(v2 != 0) {
  14484 			WebPInitConvertARGBToYUV(tls)
  14485 			if (*(*WebPYUVABuffer)(unsafe.Pointer((*VP8LDecoder)(unsafe.Pointer(dec)).Foutput + 16))).Fa != libc.UintptrFromInt32(0) {
  14486 				WebPInitAlphaProcessing(tls)
  14487 			}
  14488 		}
  14489 		if (*VP8LDecoder)(unsafe.Pointer(dec)).Fincremental != 0 {
  14490 			if (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache_size > 0 && (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fsaved_color_cache.Fcolors == libc.UintptrFromInt32(0) {
  14491 				if !(VP8LColorCacheInit(tls, dec+152+24, (*VP8LDecoder)(unsafe.Pointer(dec)).Fhdr.Fcolor_cache.Fhash_bits) != 0) {
  14492 					VP8LSetError(tls, dec, int32(VP8_STATUS_OUT_OF_MEMORY))
  14493 					goto Err
  14494 				}
  14495 			}
  14496 		}
  14497 		(*VP8LDecoder)(unsafe.Pointer(dec)).Fstate = int32(READ_DATA)
  14498 	}
  14499 	// Decode.
  14500 	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) {
  14501 		goto Err
  14502 	}
  14503 	(*WebPDecParams)(unsafe.Pointer(params)).Flast_y = (*VP8LDecoder)(unsafe.Pointer(dec)).Flast_out_row
  14504 	return int32(1)
  14505 	goto Err
  14506 Err:
  14507 	;
  14508 	VP8LClear(tls, dec)
  14509 	return 0
  14510 }
  14511 
  14512 const VP8L_MAGIC_BYTE2 = 0x2f
  14513 
  14514 var kHashMul9 = uint32(0x1e35a7bd)
  14515 
  14516 type WebPData = struct {
  14517 	Fbytes uintptr
  14518 	Fsize  size_t
  14519 }
  14520 
  14521 type WebPFeatureFlags1 = int32
  14522 
  14523 type WebPFeatureFlags = int32
  14524 
  14525 const ANIMATION_FLAG = 2
  14526 const XMP_FLAG = 4
  14527 const EXIF_FLAG = 8
  14528 const ALPHA_FLAG = 16
  14529 const ICCP_FLAG = 32
  14530 const ALL_VALID_FLAGS = 62
  14531 
  14532 type WebPMuxAnimDispose1 = int32
  14533 
  14534 type WebPMuxAnimDispose = int32
  14535 
  14536 const WEBP_MUX_DISPOSE_NONE = 0
  14537 const WEBP_MUX_DISPOSE_BACKGROUND = 1
  14538 
  14539 type WebPMuxAnimBlend1 = int32
  14540 
  14541 type WebPMuxAnimBlend = int32
  14542 
  14543 const WEBP_MUX_BLEND = 0
  14544 const WEBP_MUX_NO_BLEND = 1
  14545 
  14546 // Copyright 2010 Google Inc. All Rights Reserved.
  14547 //
  14548 // Use of this source code is governed by a BSD-style license
  14549 // that can be found in the COPYING file in the root of the source
  14550 // tree. An additional intellectual property rights grant can be found
  14551 // in the file PATENTS. All contributing project authors may
  14552 // be found in the AUTHORS file in the root of the source tree.
  14553 // -----------------------------------------------------------------------------
  14554 //
  14555 //  Common types + memory wrappers
  14556 //
  14557 // Author: Skal (pascal.massimino@gmail.com)
  14558 
  14559 //------------------------------------------------------------------------------
  14560 // RIFF layout is:
  14561 //   Offset  tag
  14562 //   0...3   "RIFF" 4-byte tag
  14563 //   4...7   size of image data (including metadata) starting at offset 8
  14564 //   8...11  "WEBP"   our form-type signature
  14565 // The RIFF container (12 bytes) is followed by appropriate chunks:
  14566 //   12..15  "VP8 ": 4-bytes tags, signaling the use of VP8 video format
  14567 //   16..19  size of the raw VP8 image data, starting at offset 20
  14568 //   20....  the VP8 bytes
  14569 // Or,
  14570 //   12..15  "VP8L": 4-bytes tags, signaling the use of VP8L lossless format
  14571 //   16..19  size of the raw VP8L image data, starting at offset 20
  14572 //   20....  the VP8L bytes
  14573 // Or,
  14574 //   12..15  "VP8X": 4-bytes tags, describing the extended-VP8 chunk.
  14575 //   16..19  size of the VP8X chunk starting at offset 20.
  14576 //   20..23  VP8X flags bit-map corresponding to the chunk-types present.
  14577 //   24..26  Width of the Canvas Image.
  14578 //   27..29  Height of the Canvas Image.
  14579 // There can be extra chunks after the "VP8X" chunk (ICCP, ANMF, VP8, VP8L,
  14580 // XMP, EXIF  ...)
  14581 // All sizes are in little-endian order.
  14582 // Note: chunk data size must be padded to multiple of 2 when written.
  14583 
  14584 // C documentation
  14585 //
  14586 //	// Validates the RIFF container (if detected) and skips over it.
  14587 //	// If a RIFF container is detected, returns:
  14588 //	//     VP8_STATUS_BITSTREAM_ERROR for invalid header,
  14589 //	//     VP8_STATUS_NOT_ENOUGH_DATA for truncated data if have_all_data is true,
  14590 //	// and VP8_STATUS_OK otherwise.
  14591 //	// In case there are not enough bytes (partial RIFF container), return 0 for
  14592 //	// *riff_size. Else return the RIFF size extracted from the header.
  14593 func ParseRIFF(tls *libc.TLS, data2 uintptr, data_size uintptr, have_all_data int32, riff_size uintptr) (r VP8StatusCode1) {
  14594 	var size, v2 uint32_t
  14595 	var v1, v4, v7 uintptr
  14596 	var v5, v8 int32
  14597 	_, _, _, _, _, _, _ = size, v1, v2, v4, v5, v7, v8
  14598 	**(**size_t)(__ccgo_up(riff_size)) = uint64(0) // Default: no RIFF present.
  14599 	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) {
  14600 		if libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data2))+uintptr(8), __ccgo_ts+569, uint64(TAG_SIZE)) != 0 {
  14601 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong image file signature.
  14602 		} else {
  14603 			v1 = **(**uintptr)(__ccgo_up(data2)) + uintptr(TAG_SIZE)
  14604 			v4 = v1
  14605 			v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14606 			goto _6
  14607 		_6:
  14608 			v7 = v1 + uintptr(2)
  14609 			v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14610 			goto _9
  14611 		_9:
  14612 			v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14613 			goto _3
  14614 		_3:
  14615 			size = v2
  14616 			// Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn").
  14617 			if size < libc.Uint32FromInt32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) {
  14618 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14619 			}
  14620 			if size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14621 				return int32(VP8_STATUS_BITSTREAM_ERROR)
  14622 			}
  14623 			if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14624 				return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14625 			}
  14626 			// We have a RIFF container. Skip it.
  14627 			**(**size_t)(__ccgo_up(riff_size)) = uint64(size)
  14628 			**(**uintptr)(__ccgo_up(data2)) += uintptr(RIFF_HEADER_SIZE)
  14629 			**(**size_t)(__ccgo_up(data_size)) -= uint64(RIFF_HEADER_SIZE)
  14630 		}
  14631 	}
  14632 	return int32(VP8_STATUS_OK)
  14633 }
  14634 
  14635 // C documentation
  14636 //
  14637 //	// Validates the VP8X header and skips over it.
  14638 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid VP8X header,
  14639 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14640 //	//         VP8_STATUS_OK otherwise.
  14641 //	// If a VP8X chunk is found, found_vp8x is set to true and *width_ptr,
  14642 //	// *height_ptr and *flags_ptr are set to the corresponding values extracted
  14643 //	// from the VP8X chunk.
  14644 func ParseVP8X(tls *libc.TLS, data3 uintptr, data_size uintptr, found_vp8x uintptr, width_ptr uintptr, height_ptr uintptr, flags_ptr uintptr) (r VP8StatusCode1) {
  14645 	var chunk_size, flags, vp8x_size, v2 uint32_t
  14646 	var height, width, v5, v8 int32
  14647 	var v1, v4, v7 uintptr
  14648 	_, _, _, _, _, _, _, _, _, _, _ = chunk_size, flags, height, vp8x_size, width, v1, v2, v4, v5, v7, v8
  14649 	vp8x_size = libc.Uint32FromInt32(libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  14650 	**(**int32)(__ccgo_up(found_vp8x)) = 0
  14651 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14652 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14653 	}
  14654 	if !(libc.Xmemcmp(tls, **(**uintptr)(__ccgo_up(data3)), __ccgo_ts+574, uint64(TAG_SIZE)) != 0) {
  14655 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(TAG_SIZE)
  14656 		v4 = v1
  14657 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14658 		goto _6
  14659 	_6:
  14660 		v7 = v1 + uintptr(2)
  14661 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14662 		goto _9
  14663 	_9:
  14664 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14665 		goto _3
  14666 	_3:
  14667 		chunk_size = v2
  14668 		if chunk_size != uint32(VP8X_CHUNK_SIZE) {
  14669 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Wrong chunk size.
  14670 		}
  14671 		// Verify if enough data is available to validate the VP8X chunk.
  14672 		if **(**size_t)(__ccgo_up(data_size)) < uint64(vp8x_size) {
  14673 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14674 		}
  14675 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(8)
  14676 		v4 = v1
  14677 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14678 		goto _15
  14679 	_15:
  14680 		v7 = v1 + uintptr(2)
  14681 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14682 		goto _18
  14683 	_18:
  14684 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14685 		goto _12
  14686 	_12:
  14687 		flags = v2
  14688 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(12)
  14689 		v4 = v1
  14690 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14691 		goto _24
  14692 	_24:
  14693 		v5 = v8 | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14694 		goto _21
  14695 	_21:
  14696 		width = int32(1) + v5
  14697 		v1 = **(**uintptr)(__ccgo_up(data3)) + uintptr(15)
  14698 		v4 = v1
  14699 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14700 		goto _30
  14701 	_30:
  14702 		v5 = v8 | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + 2)))<<int32(16)
  14703 		goto _27
  14704 	_27:
  14705 		height = int32(1) + v5
  14706 		if uint64(libc.Uint64FromInt32(width)*libc.Uint64FromInt32(height)) >= libc.Uint64FromUint64(1)<<libc.Int32FromInt32(32) {
  14707 			return int32(VP8_STATUS_BITSTREAM_ERROR) // image is too large
  14708 		}
  14709 		if flags_ptr != libc.UintptrFromInt32(0) {
  14710 			**(**uint32_t)(__ccgo_up(flags_ptr)) = flags
  14711 		}
  14712 		if width_ptr != libc.UintptrFromInt32(0) {
  14713 			**(**int32)(__ccgo_up(width_ptr)) = width
  14714 		}
  14715 		if height_ptr != libc.UintptrFromInt32(0) {
  14716 			**(**int32)(__ccgo_up(height_ptr)) = height
  14717 		}
  14718 		// Skip over VP8X header bytes.
  14719 		**(**uintptr)(__ccgo_up(data3)) += uintptr(vp8x_size)
  14720 		**(**size_t)(__ccgo_up(data_size)) -= uint64(vp8x_size)
  14721 		**(**int32)(__ccgo_up(found_vp8x)) = int32(1)
  14722 	}
  14723 	return int32(VP8_STATUS_OK)
  14724 }
  14725 
  14726 // C documentation
  14727 //
  14728 //	// Skips to the next VP8/VP8L chunk header in the data given the size of the
  14729 //	// RIFF chunk 'riff_size'.
  14730 //	// Returns VP8_STATUS_BITSTREAM_ERROR if any invalid chunk size is encountered,
  14731 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14732 //	//         VP8_STATUS_OK otherwise.
  14733 //	// If an alpha chunk is found, *alpha_data and *alpha_size are set
  14734 //	// appropriately.
  14735 func ParseOptionalChunks(tls *libc.TLS, data2 uintptr, data_size uintptr, riff_size size_t, alpha_data uintptr, alpha_size uintptr) (r VP8StatusCode1) {
  14736 	var buf, v1, v4, v7 uintptr
  14737 	var buf_size size_t
  14738 	var chunk_size, disk_chunk_size, total_size, v2 uint32_t
  14739 	var v5, v8 int32
  14740 	_, _, _, _, _, _, _, _, _, _, _ = buf, buf_size, chunk_size, disk_chunk_size, total_size, v1, v2, v4, v5, v7, v8
  14741 	total_size = libc.Uint32FromInt32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE) + libc.Int32FromInt32(VP8X_CHUNK_SIZE)) // data.
  14742 	buf = **(**uintptr)(__ccgo_up(data2))
  14743 	buf_size = **(**size_t)(__ccgo_up(data_size))
  14744 	**(**uintptr)(__ccgo_up(alpha_data)) = libc.UintptrFromInt32(0)
  14745 	**(**size_t)(__ccgo_up(alpha_size)) = uint64(0)
  14746 	for int32(1) != 0 { // chunk_size with padding
  14747 		**(**uintptr)(__ccgo_up(data2)) = buf
  14748 		**(**size_t)(__ccgo_up(data_size)) = buf_size
  14749 		if buf_size < uint64(CHUNK_HEADER_SIZE) { // Insufficient data.
  14750 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14751 		}
  14752 		v1 = buf + uintptr(TAG_SIZE)
  14753 		v4 = v1
  14754 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14755 		goto _6
  14756 	_6:
  14757 		v7 = v1 + uintptr(2)
  14758 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14759 		goto _9
  14760 	_9:
  14761 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14762 		goto _3
  14763 	_3:
  14764 		chunk_size = v2
  14765 		if chunk_size > ^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1) {
  14766 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14767 		}
  14768 		// For odd-sized chunk-payload, there's one byte padding at the end.
  14769 		disk_chunk_size = (uint32(CHUNK_HEADER_SIZE) + chunk_size + uint32(1)) & ^libc.Uint32FromUint32(1)
  14770 		total_size = total_size + disk_chunk_size
  14771 		// Check that total bytes skipped so far does not exceed riff_size.
  14772 		if riff_size > uint64(0) && uint64(total_size) > riff_size {
  14773 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not a valid chunk size.
  14774 		}
  14775 		// Start of a (possibly incomplete) VP8/VP8L chunk implies that we have
  14776 		// parsed all the optional chunks.
  14777 		// Note: This check must occur before the check 'buf_size < disk_chunk_size'
  14778 		// below to allow incomplete VP8/VP8L chunks.
  14779 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+579, uint64(TAG_SIZE)) != 0) || !(libc.Xmemcmp(tls, buf, __ccgo_ts+584, uint64(TAG_SIZE)) != 0) {
  14780 			return int32(VP8_STATUS_OK)
  14781 		}
  14782 		if buf_size < uint64(disk_chunk_size) { // Insufficient data.
  14783 			return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14784 		}
  14785 		if !(libc.Xmemcmp(tls, buf, __ccgo_ts+589, uint64(TAG_SIZE)) != 0) { // A valid ALPH header.
  14786 			**(**uintptr)(__ccgo_up(alpha_data)) = buf + uintptr(CHUNK_HEADER_SIZE)
  14787 			**(**size_t)(__ccgo_up(alpha_size)) = uint64(chunk_size)
  14788 		}
  14789 		// We have a full and valid chunk; skip it.
  14790 		buf = buf + uintptr(disk_chunk_size)
  14791 		buf_size = buf_size - uint64(disk_chunk_size)
  14792 	}
  14793 	return r
  14794 }
  14795 
  14796 // C documentation
  14797 //
  14798 //	// Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it.
  14799 //	// Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than
  14800 //	//         riff_size) VP8/VP8L header,
  14801 //	//         VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and
  14802 //	//         VP8_STATUS_OK otherwise.
  14803 //	// If a VP8/VP8L chunk is found, *chunk_size is set to the total number of bytes
  14804 //	// extracted from the VP8/VP8L chunk header.
  14805 //	// The flag '*is_lossless' is set to 1 in case of VP8L chunk / raw VP8L data.
  14806 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) {
  14807 	var data2, v1, v4, v7 uintptr
  14808 	var is_vp8, is_vp8l, v5, v8 int32
  14809 	var minimal_size, size, v2 uint32_t
  14810 	_, _, _, _, _, _, _, _, _, _, _ = data2, is_vp8, is_vp8l, minimal_size, size, v1, v2, v4, v5, v7, v8
  14811 	data2 = **(**uintptr)(__ccgo_up(data_ptr))
  14812 	is_vp8 = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+579, uint64(TAG_SIZE)) != 0))
  14813 	is_vp8l = libc.BoolInt32(!(libc.Xmemcmp(tls, data2, __ccgo_ts+584, uint64(TAG_SIZE)) != 0))
  14814 	minimal_size = libc.Uint32FromInt32(libc.Int32FromInt32(TAG_SIZE) + libc.Int32FromInt32(CHUNK_HEADER_SIZE)) // "WEBP" + "VP8 nnnn" OR
  14815 	// "WEBP" + "VP8Lnnnn"
  14816 	if **(**size_t)(__ccgo_up(data_size)) < uint64(CHUNK_HEADER_SIZE) {
  14817 		return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Insufficient data.
  14818 	}
  14819 	if is_vp8 != 0 || is_vp8l != 0 {
  14820 		v1 = data2 + uintptr(TAG_SIZE)
  14821 		v4 = v1
  14822 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v4 + 1)))<<int32(8)
  14823 		goto _6
  14824 	_6:
  14825 		v7 = v1 + uintptr(2)
  14826 		v8 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7)))<<libc.Int32FromInt32(0) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v7 + 1)))<<int32(8)
  14827 		goto _9
  14828 	_9:
  14829 		v2 = libc.Uint32FromInt32(v5) | libc.Uint32FromInt32(v8)<<libc.Int32FromInt32(16)
  14830 		goto _3
  14831 	_3:
  14832 		// Bitstream contains VP8/VP8L header.
  14833 		size = v2
  14834 		if riff_size >= uint64(minimal_size) && uint64(size) > riff_size-uint64(minimal_size) {
  14835 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Inconsistent size information.
  14836 		}
  14837 		if have_all_data != 0 && uint64(size) > **(**size_t)(__ccgo_up(data_size))-uint64(CHUNK_HEADER_SIZE) {
  14838 			return int32(VP8_STATUS_NOT_ENOUGH_DATA) // Truncated bitstream.
  14839 		}
  14840 		// Skip over CHUNK_HEADER_SIZE bytes from VP8/VP8L Header.
  14841 		**(**size_t)(__ccgo_up(chunk_size)) = uint64(size)
  14842 		**(**uintptr)(__ccgo_up(data_ptr)) += uintptr(CHUNK_HEADER_SIZE)
  14843 		**(**size_t)(__ccgo_up(data_size)) -= uint64(CHUNK_HEADER_SIZE)
  14844 		**(**int32)(__ccgo_up(is_lossless)) = is_vp8l
  14845 	} else {
  14846 		// Raw VP8/VP8L bitstream (no header).
  14847 		**(**int32)(__ccgo_up(is_lossless)) = VP8LCheckSignature(tls, data2, **(**size_t)(__ccgo_up(data_size)))
  14848 		**(**size_t)(__ccgo_up(chunk_size)) = **(**size_t)(__ccgo_up(data_size))
  14849 	}
  14850 	return int32(VP8_STATUS_OK)
  14851 }
  14852 
  14853 //------------------------------------------------------------------------------
  14854 
  14855 // C documentation
  14856 //
  14857 //	// Fetch '*width', '*height', '*has_alpha' and fill out 'headers' based on
  14858 //	// 'data'. All the output parameters may be NULL. If 'headers' is NULL only the
  14859 //	// minimal amount will be read to fetch the remaining parameters.
  14860 //	// If 'headers' is non-NULL this function will attempt to locate both alpha
  14861 //	// data (with or without a VP8X chunk) and the bitstream chunk (VP8/VP8L).
  14862 //	// Note: The following chunk sequences (before the raw VP8/VP8L data) are
  14863 //	// considered valid by this function:
  14864 //	// RIFF + VP8(L)
  14865 //	// RIFF + VP8X + (optional chunks) + VP8(L)
  14866 //	// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
  14867 //	// VP8(L)     <-- Not a valid WebP format: only allowed for internal purpose.
  14868 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) {
  14869 	bp := tls.Alloc(128)
  14870 	defer tls.Free(128)
  14871 	*(*uintptr)(unsafe.Pointer(bp)) = _data
  14872 	*(*size_t)(unsafe.Pointer(bp + 8)) = _data_size
  14873 	var animation_present, found_riff, have_all_data, v1 int32
  14874 	var status VP8StatusCode1
  14875 	var _ /* canvas_height at bp+20 */ int32
  14876 	var _ /* canvas_width at bp+16 */ int32
  14877 	var _ /* flags at bp+112 */ uint32_t
  14878 	var _ /* found_vp8x at bp+32 */ int32
  14879 	var _ /* hdrs at bp+40 */ WebPHeaderStructure
  14880 	var _ /* image_height at bp+28 */ int32
  14881 	var _ /* image_width at bp+24 */ int32
  14882 	_, _, _, _, _ = animation_present, found_riff, have_all_data, status, v1
  14883 	**(**int32)(__ccgo_up(bp + 16)) = 0
  14884 	**(**int32)(__ccgo_up(bp + 20)) = 0
  14885 	**(**int32)(__ccgo_up(bp + 24)) = 0
  14886 	**(**int32)(__ccgo_up(bp + 28)) = 0
  14887 	found_riff = 0
  14888 	**(**int32)(__ccgo_up(bp + 32)) = 0
  14889 	animation_present = 0
  14890 	if headers != libc.UintptrFromInt32(0) {
  14891 		v1 = (*WebPHeaderStructure)(unsafe.Pointer(headers)).Fhave_all_data
  14892 	} else {
  14893 		v1 = 0
  14894 	}
  14895 	have_all_data = v1
  14896 	if **(**uintptr)(__ccgo_up(bp)) == libc.UintptrFromInt32(0) || **(**size_t)(__ccgo_up(bp + 8)) < uint64(RIFF_HEADER_SIZE) {
  14897 		return int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14898 	}
  14899 	libc.Xmemset(tls, bp+40, 0, uint64(72))
  14900 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata = **(**uintptr)(__ccgo_up(bp))
  14901 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fdata_size = **(**size_t)(__ccgo_up(bp + 8))
  14902 	// Skip over RIFF header.
  14903 	status = ParseRIFF(tls, bp, bp+8, have_all_data, bp+40+56)
  14904 	if status != int32(VP8_STATUS_OK) {
  14905 		return status // Wrong RIFF header / insufficient data.
  14906 	}
  14907 	found_riff = libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size > uint64(0))
  14908 	// Skip over VP8X.
  14909 	**(**uint32_t)(__ccgo_up(bp + 112)) = uint32(0)
  14910 	status = ParseVP8X(tls, bp, bp+8, bp+32, bp+16, bp+20, bp+112)
  14911 	if status != int32(VP8_STATUS_OK) {
  14912 		return status // Wrong VP8X / insufficient data.
  14913 	}
  14914 	animation_present = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ANIMATION_FLAG) != 0))
  14915 	if !(found_riff != 0) && **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14916 		// Note: This restriction may be removed in the future, if it becomes
  14917 		// necessary to send VP8X chunk to the decoder.
  14918 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14919 	}
  14920 	if has_alpha != libc.UintptrFromInt32(0) {
  14921 		**(**int32)(__ccgo_up(has_alpha)) = libc.BoolInt32(!!(**(**uint32_t)(__ccgo_up(bp + 112))&uint32(ALPHA_FLAG) != 0))
  14922 	}
  14923 	if has_animation != libc.UintptrFromInt32(0) {
  14924 		**(**int32)(__ccgo_up(has_animation)) = animation_present
  14925 	}
  14926 	if format != libc.UintptrFromInt32(0) {
  14927 		**(**int32)(__ccgo_up(format)) = 0
  14928 	} // default = undefined
  14929 	**(**int32)(__ccgo_up(bp + 24)) = **(**int32)(__ccgo_up(bp + 16))
  14930 	**(**int32)(__ccgo_up(bp + 28)) = **(**int32)(__ccgo_up(bp + 20))
  14931 	if **(**int32)(__ccgo_up(bp + 32)) != 0 && animation_present != 0 && headers == libc.UintptrFromInt32(0) {
  14932 		status = int32(VP8_STATUS_OK)
  14933 		goto ReturnWidthHeight // Just return features from VP8X header.
  14934 	}
  14935 	if **(**size_t)(__ccgo_up(bp + 8)) < uint64(TAG_SIZE) {
  14936 		status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14937 		goto ReturnWidthHeight
  14938 	}
  14939 	// Skip over optional chunks if data started with "RIFF + VP8X" or "ALPH".
  14940 	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) {
  14941 		status = ParseOptionalChunks(tls, bp, bp+8, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+32, bp+40+40)
  14942 		if status != int32(VP8_STATUS_OK) {
  14943 			goto ReturnWidthHeight // Invalid chunk size / insufficient data.
  14944 		}
  14945 	}
  14946 	// Skip over VP8/VP8L header.
  14947 	status = ParseVP8Header(tls, bp, bp+8, have_all_data, (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Friff_size, bp+40+48, bp+40+64)
  14948 	if status != int32(VP8_STATUS_OK) {
  14949 		goto ReturnWidthHeight // Wrong VP8/VP8L chunk-header / insufficient data.
  14950 	}
  14951 	if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fcompressed_size > uint64(^libc.Uint32FromUint32(0)-libc.Uint32FromInt32(CHUNK_HEADER_SIZE)-libc.Uint32FromInt32(1)) {
  14952 		return int32(VP8_STATUS_BITSTREAM_ERROR)
  14953 	}
  14954 	if format != libc.UintptrFromInt32(0) && !(animation_present != 0) {
  14955 		if (**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0 {
  14956 			v1 = int32(2)
  14957 		} else {
  14958 			v1 = int32(1)
  14959 		}
  14960 		**(**int32)(__ccgo_up(format)) = v1
  14961 	}
  14962 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Fis_lossless != 0) {
  14963 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8_FRAME_HEADER_SIZE) {
  14964 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14965 			goto ReturnWidthHeight
  14966 		}
  14967 		// Validates raw VP8 data.
  14968 		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) {
  14969 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14970 		}
  14971 	} else {
  14972 		if **(**size_t)(__ccgo_up(bp + 8)) < uint64(VP8L_FRAME_HEADER_SIZE) {
  14973 			status = int32(VP8_STATUS_NOT_ENOUGH_DATA)
  14974 			goto ReturnWidthHeight
  14975 		}
  14976 		// Validates raw VP8L data.
  14977 		if !(VP8LGetInfo(tls, **(**uintptr)(__ccgo_up(bp)), **(**size_t)(__ccgo_up(bp + 8)), bp+24, bp+28, has_alpha) != 0) {
  14978 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14979 		}
  14980 	}
  14981 	// Validates image size coherency.
  14982 	if **(**int32)(__ccgo_up(bp + 32)) != 0 {
  14983 		if **(**int32)(__ccgo_up(bp + 16)) != **(**int32)(__ccgo_up(bp + 24)) || **(**int32)(__ccgo_up(bp + 20)) != **(**int32)(__ccgo_up(bp + 28)) {
  14984 			return int32(VP8_STATUS_BITSTREAM_ERROR)
  14985 		}
  14986 	}
  14987 	if headers != libc.UintptrFromInt32(0) {
  14988 		**(**WebPHeaderStructure)(__ccgo_up(headers)) = **(**WebPHeaderStructure)(__ccgo_up(bp + 40))
  14989 		(*WebPHeaderStructure)(unsafe.Pointer(headers)).Foffset = libc.Uint64FromInt64(int64(**(**uintptr)(__ccgo_up(bp))) - int64((*WebPHeaderStructure)(unsafe.Pointer(headers)).Fdata))
  14990 	}
  14991 	goto ReturnWidthHeight
  14992 ReturnWidthHeight:
  14993 	;
  14994 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) && **(**int32)(__ccgo_up(bp + 32)) != 0 && headers == libc.UintptrFromInt32(0) {
  14995 		if has_alpha != libc.UintptrFromInt32(0) {
  14996 			// If the data did not contain a VP8X/VP8L chunk the only definitive way
  14997 			// to set this is by looking for alpha data (from an ALPH chunk).
  14998 			**(**int32)(__ccgo_up(has_alpha)) |= libc.BoolInt32((**(**WebPHeaderStructure)(__ccgo_up(bp + 40))).Falpha_data != libc.UintptrFromInt32(0))
  14999 		}
  15000 		if width != libc.UintptrFromInt32(0) {
  15001 			**(**int32)(__ccgo_up(width)) = **(**int32)(__ccgo_up(bp + 24))
  15002 		}
  15003 		if height != libc.UintptrFromInt32(0) {
  15004 			**(**int32)(__ccgo_up(height)) = **(**int32)(__ccgo_up(bp + 28))
  15005 		}
  15006 		return int32(VP8_STATUS_OK)
  15007 	} else {
  15008 		return status
  15009 	}
  15010 	return r
  15011 }
  15012 
  15013 func WebPParseHeaders(tls *libc.TLS, headers uintptr) (r VP8StatusCode1) {
  15014 	bp := tls.Alloc(16)
  15015 	defer tls.Free(16)
  15016 	var status VP8StatusCode1
  15017 	var _ /* has_animation at bp+0 */ int32
  15018 	_ = status
  15019 	**(**int32)(__ccgo_up(bp)) = 0
  15020 	// fill out headers, ignore width/height/has_alpha.
  15021 	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)
  15022 	if status == int32(VP8_STATUS_OK) || status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15023 		// The WebPDemux API + libwebp can be used to decode individual
  15024 		// uncomposited frames or the WebPAnimDecoder can be used to fully
  15025 		// reconstruct them (see webp/demux.h).
  15026 		if **(**int32)(__ccgo_up(bp)) != 0 {
  15027 			status = int32(VP8_STATUS_UNSUPPORTED_FEATURE)
  15028 		}
  15029 	}
  15030 	return status
  15031 }
  15032 
  15033 //------------------------------------------------------------------------------
  15034 // WebPDecParams
  15035 
  15036 func WebPResetDecParams(tls *libc.TLS, params uintptr) {
  15037 	if params != libc.UintptrFromInt32(0) {
  15038 		libc.Xmemset(tls, params, 0, uint64(112))
  15039 	}
  15040 }
  15041 
  15042 //------------------------------------------------------------------------------
  15043 // "Into" decoding variants
  15044 
  15045 // C documentation
  15046 //
  15047 //	// Main flow
  15048 func DecodeInto(tls *libc.TLS, data uintptr, data_size size_t, params uintptr) (r VP8StatusCode1) {
  15049 	bp := tls.Alloc(240)
  15050 	defer tls.Free(240)
  15051 	var dec, dec1 uintptr
  15052 	var status VP8StatusCode1
  15053 	var v1 int32
  15054 	var _ /* headers at bp+160 */ WebPHeaderStructure
  15055 	var _ /* io at bp+0 */ VP8Io
  15056 	_, _, _, _ = dec, dec1, status, v1
  15057 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata = data
  15058 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size = data_size
  15059 	(**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fhave_all_data = int32(1)
  15060 	status = WebPParseHeaders(tls, bp+160) // Process Pre-VP8 chunks.
  15061 	if status != int32(VP8_STATUS_OK) {
  15062 		return status
  15063 	}
  15064 	v1 = VP8InitIoInternal(tls, bp, int32(WEBP_DECODER_ABI_VERSION))
  15065 	goto _2
  15066 _2:
  15067 	if !(v1 != 0) {
  15068 		return int32(VP8_STATUS_INVALID_PARAM)
  15069 	}
  15070 	(**(**VP8Io)(__ccgo_up(bp))).Fdata = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata + uintptr((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset)
  15071 	(**(**VP8Io)(__ccgo_up(bp))).Fdata_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fdata_size - (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Foffset
  15072 	WebPInitCustomIo(tls, params, bp) // Plug the I/O functions.
  15073 	if !((**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Fis_lossless != 0) {
  15074 		dec = VP8New(tls)
  15075 		if dec == libc.UintptrFromInt32(0) {
  15076 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  15077 		}
  15078 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data
  15079 		(*VP8Decoder)(unsafe.Pointer(dec)).Falpha_data_size = (**(**WebPHeaderStructure)(__ccgo_up(bp + 160))).Falpha_data_size
  15080 		// Decode bitstream header, update io->width/io->height.
  15081 		if !(VP8GetHeaders(tls, dec, bp) != 0) {
  15082 			status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus // An error occurred. Grab error status.
  15083 		} else {
  15084 			// Allocate/check output buffers.
  15085 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15086 			if status == int32(VP8_STATUS_OK) { // Decode
  15087 				// This change must be done before calling VP8Decode()
  15088 				(*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)
  15089 				VP8InitDithering(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, dec)
  15090 				if !(VP8Decode(tls, dec, bp) != 0) {
  15091 					status = (*VP8Decoder)(unsafe.Pointer(dec)).Fstatus
  15092 				}
  15093 			}
  15094 		}
  15095 		VP8Delete(tls, dec)
  15096 	} else {
  15097 		dec1 = VP8LNew(tls)
  15098 		if dec1 == libc.UintptrFromInt32(0) {
  15099 			return int32(VP8_STATUS_OUT_OF_MEMORY)
  15100 		}
  15101 		if !(VP8LDecodeHeader(tls, dec1, bp) != 0) {
  15102 			status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus // An error occurred. Grab error status.
  15103 		} else {
  15104 			// Allocate/check output buffers.
  15105 			status = WebPAllocateDecBuffer(tls, (**(**VP8Io)(__ccgo_up(bp))).Fwidth, (**(**VP8Io)(__ccgo_up(bp))).Fheight, (*WebPDecParams)(unsafe.Pointer(params)).Foptions, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15106 			if status == int32(VP8_STATUS_OK) { // Decode
  15107 				if !(VP8LDecodeImage(tls, dec1) != 0) {
  15108 					status = (*VP8LDecoder)(unsafe.Pointer(dec1)).Fstatus
  15109 				}
  15110 			}
  15111 		}
  15112 		VP8LDelete(tls, dec1)
  15113 	}
  15114 	if status != int32(VP8_STATUS_OK) {
  15115 		WebPFreeDecBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15116 	} else {
  15117 		if (*WebPDecParams)(unsafe.Pointer(params)).Foptions != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer((*WebPDecParams)(unsafe.Pointer(params)).Foptions)).Fflip != 0 {
  15118 			// This restores the original stride values if options->flip was used
  15119 			// during the call to WebPAllocateDecBuffer above.
  15120 			status = WebPFlipBuffer(tls, (*WebPDecParams)(unsafe.Pointer(params)).Foutput)
  15121 		}
  15122 	}
  15123 	return status
  15124 }
  15125 
  15126 // C documentation
  15127 //
  15128 //	// Helpers
  15129 func DecodeIntoRGBABuffer(tls *libc.TLS, colorspace WEBP_CSP_MODE1, data uintptr, data_size size_t, rgba uintptr, stride int32, size size_t) (r uintptr) {
  15130 	bp := tls.Alloc(240)
  15131 	defer tls.Free(240)
  15132 	var v1 int32
  15133 	var v3 bool
  15134 	var _ /* buf at bp+112 */ WebPDecBuffer
  15135 	var _ /* params at bp+0 */ WebPDecParams
  15136 	_, _ = v1, v3
  15137 	if v3 = rgba == libc.UintptrFromInt32(0); !v3 {
  15138 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15139 		goto _2
  15140 	_2:
  15141 	}
  15142 	if v3 || !(v1 != 0) {
  15143 		return libc.UintptrFromInt32(0)
  15144 	}
  15145 	WebPResetDecParams(tls, bp)
  15146 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15147 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = colorspace
  15148 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = rgba
  15149 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 8)) = stride
  15150 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 16)) = size
  15151 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  15152 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15153 		return libc.UintptrFromInt32(0)
  15154 	}
  15155 	return rgba
  15156 }
  15157 
  15158 func WebPDecodeRGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15159 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGB), data, data_size, output, stride, size)
  15160 }
  15161 
  15162 func WebPDecodeRGBAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15163 	return DecodeIntoRGBABuffer(tls, int32(MODE_RGBA), data, data_size, output, stride, size)
  15164 }
  15165 
  15166 func WebPDecodeARGBInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15167 	return DecodeIntoRGBABuffer(tls, int32(MODE_ARGB), data, data_size, output, stride, size)
  15168 }
  15169 
  15170 func WebPDecodeBGRInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15171 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGR), data, data_size, output, stride, size)
  15172 }
  15173 
  15174 func WebPDecodeBGRAInto(tls *libc.TLS, data uintptr, data_size size_t, output uintptr, size size_t, stride int32) (r uintptr) {
  15175 	return DecodeIntoRGBABuffer(tls, int32(MODE_BGRA), data, data_size, output, stride, size)
  15176 }
  15177 
  15178 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) {
  15179 	bp := tls.Alloc(240)
  15180 	defer tls.Free(240)
  15181 	var v1 int32
  15182 	var v3 bool
  15183 	var _ /* output at bp+112 */ WebPDecBuffer
  15184 	var _ /* params at bp+0 */ WebPDecParams
  15185 	_, _ = v1, v3
  15186 	if v3 = luma == libc.UintptrFromInt32(0); !v3 {
  15187 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15188 		goto _2
  15189 	_2:
  15190 	}
  15191 	if v3 || !(v1 != 0) {
  15192 		return libc.UintptrFromInt32(0)
  15193 	}
  15194 	WebPResetDecParams(tls, bp)
  15195 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15196 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = int32(MODE_YUV)
  15197 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = luma
  15198 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 32)) = luma_stride
  15199 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 48)) = luma_size
  15200 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 8)) = u
  15201 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 36)) = u_stride
  15202 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 56)) = u_size
  15203 	*(*uintptr)(unsafe.Pointer(bp + 112 + 16 + 16)) = v
  15204 	*(*int32)(unsafe.Pointer(bp + 112 + 16 + 40)) = v_stride
  15205 	*(*size_t)(unsafe.Pointer(bp + 112 + 16 + 64)) = v_size
  15206 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fis_external_memory = int32(1)
  15207 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15208 		return libc.UintptrFromInt32(0)
  15209 	}
  15210 	return luma
  15211 }
  15212 
  15213 // ------------------------------------------------------------------------------
  15214 func Decode(tls *libc.TLS, mode1 WEBP_CSP_MODE1, data uintptr, data_size size_t, width uintptr, height uintptr, keep_info uintptr) (r uintptr) {
  15215 	bp := tls.Alloc(240)
  15216 	defer tls.Free(240)
  15217 	var v1 int32
  15218 	var v3 uintptr
  15219 	var _ /* output at bp+112 */ WebPDecBuffer
  15220 	var _ /* params at bp+0 */ WebPDecParams
  15221 	_, _ = v1, v3
  15222 	v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15223 	goto _2
  15224 _2:
  15225 	if !(v1 != 0) {
  15226 		return libc.UintptrFromInt32(0)
  15227 	}
  15228 	WebPResetDecParams(tls, bp)
  15229 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15230 	(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = mode1
  15231 	// Retrieve (and report back) the required dimensions from bitstream.
  15232 	if !(WebPGetInfo(tls, data, data_size, bp+112+4, bp+112+8) != 0) {
  15233 		return libc.UintptrFromInt32(0)
  15234 	}
  15235 	if width != libc.UintptrFromInt32(0) {
  15236 		**(**int32)(__ccgo_up(width)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth
  15237 	}
  15238 	if height != libc.UintptrFromInt32(0) {
  15239 		**(**int32)(__ccgo_up(height)) = (**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight
  15240 	}
  15241 	// Decode
  15242 	if DecodeInto(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15243 		return libc.UintptrFromInt32(0)
  15244 	}
  15245 	if keep_info != libc.UintptrFromInt32(0) { // keep track of the side-info
  15246 		WebPCopyDecBuffer(tls, bp+112, keep_info)
  15247 	}
  15248 	// return decoded samples (don't clear 'output'!)
  15249 	v1 = libc.BoolInt32(mode1 < int32(MODE_YUV))
  15250 	goto _5
  15251 _5:
  15252 	if v1 != 0 {
  15253 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  15254 	} else {
  15255 		v3 = *(*uintptr)(unsafe.Pointer(bp + 112 + 16))
  15256 	}
  15257 	return v3
  15258 }
  15259 
  15260 func WebPDecodeRGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15261 	return Decode(tls, int32(MODE_RGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  15262 }
  15263 
  15264 func WebPDecodeRGBA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15265 	return Decode(tls, int32(MODE_RGBA), data, data_size, width, height, libc.UintptrFromInt32(0))
  15266 }
  15267 
  15268 func WebPDecodeARGB(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15269 	return Decode(tls, int32(MODE_ARGB), data, data_size, width, height, libc.UintptrFromInt32(0))
  15270 }
  15271 
  15272 func WebPDecodeBGR(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15273 	return Decode(tls, int32(MODE_BGR), data, data_size, width, height, libc.UintptrFromInt32(0))
  15274 }
  15275 
  15276 func WebPDecodeBGRA(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r uintptr) {
  15277 	return Decode(tls, int32(MODE_BGRA), data, data_size, width, height, libc.UintptrFromInt32(0))
  15278 }
  15279 
  15280 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) {
  15281 	bp := tls.Alloc(128)
  15282 	defer tls.Free(128)
  15283 	var buf, out uintptr
  15284 	var _ /* output at bp+0 */ WebPDecBuffer
  15285 	_, _ = buf, out
  15286 	// data, width and height are checked by Decode().
  15287 	if u == libc.UintptrFromInt32(0) || v == libc.UintptrFromInt32(0) || stride == libc.UintptrFromInt32(0) || uv_stride == libc.UintptrFromInt32(0) {
  15288 		return libc.UintptrFromInt32(0)
  15289 	}
  15290 	// only to preserve the side-infos
  15291 	out = Decode(tls, int32(MODE_YUV), data, data_size, width, height, bp)
  15292 	if out != libc.UintptrFromInt32(0) {
  15293 		buf = bp + 16
  15294 		**(**uintptr)(__ccgo_up(u)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu
  15295 		**(**uintptr)(__ccgo_up(v)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fv
  15296 		**(**int32)(__ccgo_up(stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fy_stride
  15297 		**(**int32)(__ccgo_up(uv_stride)) = (*WebPYUVABuffer)(unsafe.Pointer(buf)).Fu_stride
  15298 	}
  15299 	return out
  15300 	return r
  15301 }
  15302 
  15303 func DefaultFeatures(tls *libc.TLS, features uintptr) {
  15304 	libc.Xmemset(tls, features, 0, uint64(40))
  15305 }
  15306 
  15307 func GetFeatures(tls *libc.TLS, data uintptr, data_size size_t, features uintptr) (r VP8StatusCode1) {
  15308 	if features == libc.UintptrFromInt32(0) || data == libc.UintptrFromInt32(0) {
  15309 		return int32(VP8_STATUS_INVALID_PARAM)
  15310 	}
  15311 	DefaultFeatures(tls, features)
  15312 	// Only parse enough of the data to retrieve the features.
  15313 	return ParseHeadersInternal(tls, data, data_size, features, features+4, features+8, features+12, features+16, libc.UintptrFromInt32(0))
  15314 }
  15315 
  15316 //------------------------------------------------------------------------------
  15317 // WebPGetInfo()
  15318 
  15319 func WebPGetInfo(tls *libc.TLS, data uintptr, data_size size_t, width uintptr, height uintptr) (r int32) {
  15320 	bp := tls.Alloc(48)
  15321 	defer tls.Free(48)
  15322 	var _ /* features at bp+0 */ WebPBitstreamFeatures
  15323 	if GetFeatures(tls, data, data_size, bp) != int32(VP8_STATUS_OK) {
  15324 		return 0
  15325 	}
  15326 	if width != libc.UintptrFromInt32(0) {
  15327 		**(**int32)(__ccgo_up(width)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fwidth
  15328 	}
  15329 	if height != libc.UintptrFromInt32(0) {
  15330 		**(**int32)(__ccgo_up(height)) = (**(**WebPBitstreamFeatures)(__ccgo_up(bp))).Fheight
  15331 	}
  15332 	return int32(1)
  15333 }
  15334 
  15335 //------------------------------------------------------------------------------
  15336 // Advance decoding API
  15337 
  15338 func WebPInitDecoderConfigInternal(tls *libc.TLS, config uintptr, version int32) (r int32) {
  15339 	var v1 int32
  15340 	_ = v1
  15341 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15342 		return 0 // version mismatch
  15343 	}
  15344 	if config == libc.UintptrFromInt32(0) {
  15345 		return 0
  15346 	}
  15347 	libc.Xmemset(tls, config, 0, uint64(240))
  15348 	DefaultFeatures(tls, config)
  15349 	v1 = WebPInitDecBufferInternal(tls, config+40, int32(WEBP_DECODER_ABI_VERSION))
  15350 	goto _2
  15351 _2:
  15352 	if !(v1 != 0) {
  15353 		return 0
  15354 	}
  15355 	return int32(1)
  15356 }
  15357 
  15358 func WebPCheckCropDimensionsBasic(tls *libc.TLS, x int32, y int32, w int32, h int32) (r int32) {
  15359 	return libc.BoolInt32(!(x < 0 || y < 0 || w <= 0 || h <= 0))
  15360 }
  15361 
  15362 func WebPValidateDecoderConfig(tls *libc.TLS, config uintptr) (r int32) {
  15363 	bp := tls.Alloc(16)
  15364 	defer tls.Free(16)
  15365 	var options uintptr
  15366 	var _ /* scaled_height at bp+4 */ int32
  15367 	var _ /* scaled_width at bp+0 */ int32
  15368 	_ = options
  15369 	if config == libc.UintptrFromInt32(0) {
  15370 		return 0
  15371 	}
  15372 	if !(IsValidColorspace(tls, (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace) != 0) {
  15373 		return 0
  15374 	}
  15375 	options = config + 160
  15376 	// bypass_filtering, no_fancy_upsampling, use_cropping, use_scaling,
  15377 	// use_threads, flip can be any integer and are interpreted as boolean.
  15378 	// Check for cropping.
  15379 	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) {
  15380 		return 0
  15381 	}
  15382 	// Check for scaling.
  15383 	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) {
  15384 		return 0
  15385 	}
  15386 	// In case the WebPBitstreamFeatures has been filled in, check further.
  15387 	if (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth > 0 || (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight > 0 {
  15388 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15389 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15390 		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) {
  15391 			return 0
  15392 		}
  15393 		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) {
  15394 			return 0
  15395 		}
  15396 	}
  15397 	// Check for dithering.
  15398 	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) {
  15399 		return 0
  15400 	}
  15401 	return int32(1)
  15402 }
  15403 
  15404 func WebPGetFeaturesInternal(tls *libc.TLS, data uintptr, data_size size_t, features uintptr, version int32) (r VP8StatusCode1) {
  15405 	if version>>int32(8) != libc.Int32FromInt32(WEBP_DECODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  15406 		return int32(VP8_STATUS_INVALID_PARAM) // version mismatch
  15407 	}
  15408 	if features == libc.UintptrFromInt32(0) {
  15409 		return int32(VP8_STATUS_INVALID_PARAM)
  15410 	}
  15411 	return GetFeatures(tls, data, data_size, features)
  15412 }
  15413 
  15414 func WebPDecode(tls *libc.TLS, data uintptr, data_size size_t, config uintptr) (r VP8StatusCode1) {
  15415 	bp := tls.Alloc(240)
  15416 	defer tls.Free(240)
  15417 	var status VP8StatusCode1
  15418 	var v1 int32
  15419 	var _ /* in_mem_buffer at bp+112 */ WebPDecBuffer
  15420 	var _ /* params at bp+0 */ WebPDecParams
  15421 	_, _ = status, v1
  15422 	if config == libc.UintptrFromInt32(0) {
  15423 		return int32(VP8_STATUS_INVALID_PARAM)
  15424 	}
  15425 	status = GetFeatures(tls, data, data_size, config)
  15426 	if status != int32(VP8_STATUS_OK) {
  15427 		if status == int32(VP8_STATUS_NOT_ENOUGH_DATA) {
  15428 			return int32(VP8_STATUS_BITSTREAM_ERROR) // Not-enough-data treated as error.
  15429 		}
  15430 		return status
  15431 	}
  15432 	WebPResetDecParams(tls, bp)
  15433 	(**(**WebPDecParams)(__ccgo_up(bp))).Foptions = config + 160
  15434 	(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = config + 40
  15435 	if WebPAvoidSlowMemory(tls, (**(**WebPDecParams)(__ccgo_up(bp))).Foutput, config) != 0 {
  15436 		v1 = WebPInitDecBufferInternal(tls, bp+112, int32(WEBP_DECODER_ABI_VERSION))
  15437 		goto _2
  15438 	_2:
  15439 		if !(v1 != 0) {
  15440 			return int32(VP8_STATUS_INVALID_PARAM)
  15441 		}
  15442 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fcolorspace = (*WebPDecoderConfig)(unsafe.Pointer(config)).Foutput.Fcolorspace
  15443 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fwidth = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fwidth
  15444 		(**(**WebPDecBuffer)(__ccgo_up(bp + 112))).Fheight = (*WebPDecoderConfig)(unsafe.Pointer(config)).Finput.Fheight
  15445 		(**(**WebPDecParams)(__ccgo_up(bp))).Foutput = bp + 112
  15446 		status = DecodeInto(tls, data, data_size, bp)
  15447 		if status == int32(VP8_STATUS_OK) { // do the slow-copy
  15448 			status = WebPCopyDecBufferPixels(tls, bp+112, config+40)
  15449 		}
  15450 		WebPFreeDecBuffer(tls, bp+112)
  15451 	} else {
  15452 		status = DecodeInto(tls, data, data_size, bp)
  15453 	}
  15454 	return status
  15455 }
  15456 
  15457 //------------------------------------------------------------------------------
  15458 // Cropping and rescaling.
  15459 
  15460 func WebPCheckCropDimensions(tls *libc.TLS, image_width int32, image_height int32, x int32, y int32, w int32, h int32) (r int32) {
  15461 	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))
  15462 }
  15463 
  15464 func WebPIoInitFromOptions(tls *libc.TLS, options uintptr, io uintptr, src_colorspace WEBP_CSP_MODE1) (r int32) {
  15465 	bp := tls.Alloc(16)
  15466 	defer tls.Free(16)
  15467 	var H, W, h, w, x, y, v1 int32
  15468 	var _ /* scaled_height at bp+4 */ int32
  15469 	var _ /* scaled_width at bp+0 */ int32
  15470 	_, _, _, _, _, _, _ = H, W, h, w, x, y, v1
  15471 	W = (*VP8Io)(unsafe.Pointer(io)).Fwidth
  15472 	H = (*VP8Io)(unsafe.Pointer(io)).Fheight
  15473 	x = 0
  15474 	y = 0
  15475 	w = W
  15476 	h = H
  15477 	// Cropping
  15478 	(*VP8Io)(unsafe.Pointer(io)).Fuse_cropping = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_cropping != 0)
  15479 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_cropping != 0 {
  15480 		w = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_width
  15481 		h = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_height
  15482 		x = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_left
  15483 		y = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fcrop_top
  15484 		v1 = libc.BoolInt32(src_colorspace < int32(MODE_YUV))
  15485 		goto _2
  15486 	_2:
  15487 		if !(v1 != 0) { // only snap for YUV420
  15488 			x = x & ^libc.Int32FromInt32(1)
  15489 			y = y & ^libc.Int32FromInt32(1)
  15490 		}
  15491 		if !(WebPCheckCropDimensions(tls, W, H, x, y, w, h) != 0) {
  15492 			return 0 // out of frame boundary error
  15493 		}
  15494 	}
  15495 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_left = x
  15496 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_top = y
  15497 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_right = x + w
  15498 	(*VP8Io)(unsafe.Pointer(io)).Fcrop_bottom = y + h
  15499 	(*VP8Io)(unsafe.Pointer(io)).Fmb_w = w
  15500 	(*VP8Io)(unsafe.Pointer(io)).Fmb_h = h
  15501 	// Scaling
  15502 	(*VP8Io)(unsafe.Pointer(io)).Fuse_scaling = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fuse_scaling != 0)
  15503 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15504 		**(**int32)(__ccgo_up(bp)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_width
  15505 		**(**int32)(__ccgo_up(bp + 4)) = (*WebPDecoderOptions)(unsafe.Pointer(options)).Fscaled_height
  15506 		if !(WebPRescalerGetScaledDimensions(tls, w, h, bp, bp+4) != 0) {
  15507 			return 0
  15508 		}
  15509 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_width = **(**int32)(__ccgo_up(bp))
  15510 		(*VP8Io)(unsafe.Pointer(io)).Fscaled_height = **(**int32)(__ccgo_up(bp + 4))
  15511 	}
  15512 	// Filter
  15513 	(*VP8Io)(unsafe.Pointer(io)).Fbypass_filtering = libc.BoolInt32(options != libc.UintptrFromInt32(0) && (*WebPDecoderOptions)(unsafe.Pointer(options)).Fbypass_filtering != 0)
  15514 	// Fancy upsampler
  15515 	(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = libc.BoolInt32(options == libc.UintptrFromInt32(0) || !((*WebPDecoderOptions)(unsafe.Pointer(options)).Fno_fancy_upsampling != 0))
  15516 	if (*VP8Io)(unsafe.Pointer(io)).Fuse_scaling != 0 {
  15517 		// disable filter (only for large downscaling ratio).
  15518 		**(**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))
  15519 		(*VP8Io)(unsafe.Pointer(io)).Ffancy_upsampling = 0
  15520 	}
  15521 	return int32(1)
  15522 }
  15523 
  15524 const ENC_MAJ_VERSION = 1
  15525 const ENC_MIN_VERSION = 6
  15526 const ENC_REV_VERSION = 0
  15527 const ERROR_DIFFUSION_QUALITY = 98
  15528 const HASH_BITS = 18
  15529 const MAX_COLOR_CACHE_BITS = 10
  15530 const MAX_LENGTH_BITS = 12
  15531 const MAX_REFS_BLOCK_PER_IMAGE = 16
  15532 const QFIX = 17
  15533 const U_OFF_ENC = 16
  15534 const VP8L_WRITER_BITS = 16
  15535 const VP8L_WRITER_BYTES = 2
  15536 const VP8L_WRITER_MAX_BITS = 32
  15537 const WEBP_ENCODER_ABI_VERSION = 528
  15538 const WEBP_MAX_DIMENSION = 16383
  15539 const WEBP_NEAR_LOSSLESS = 1
  15540 const WINDOW_SIZE_BITS = 20
  15541 const WSWAP = "HToLE16"
  15542 const Y_OFF_ENC = 0
  15543 
  15544 type VP8Matrix = struct {
  15545 	Fq       [16]uint16_t
  15546 	Fiq      [16]uint16_t
  15547 	Fbias    [16]uint32_t
  15548 	Fzthresh [16]uint32_t
  15549 	Fsharpen [16]uint16_t
  15550 }
  15551 
  15552 type VP8BitWriter = struct {
  15553 	Frange1  int32_t
  15554 	Fvalue   int32_t
  15555 	Frun     int32
  15556 	Fnb_bits int32
  15557 	Fbuf     uintptr
  15558 	Fpos     size_t
  15559 	Fmax_pos size_t
  15560 	Ferror1  int32
  15561 }
  15562 
  15563 type vp8l_atype_t = uint32
  15564 
  15565 type vp8l_wtype_t = uint16
  15566 
  15567 type VP8LBitWriter = struct {
  15568 	Fbits   vp8l_atype_t
  15569 	Fused   int32
  15570 	Fbuf    uintptr
  15571 	Fcur    uintptr
  15572 	Fend    uintptr
  15573 	Ferror1 int32
  15574 }
  15575 
  15576 type WebPPicture = struct {
  15577 	Fuse_argb        int32
  15578 	Fcolorspace      WebPEncCSP1
  15579 	Fwidth           int32
  15580 	Fheight          int32
  15581 	Fy               uintptr
  15582 	Fu               uintptr
  15583 	Fv               uintptr
  15584 	Fy_stride        int32
  15585 	Fuv_stride       int32
  15586 	Fa               uintptr
  15587 	Fa_stride        int32
  15588 	Fpad1            [2]uint32_t
  15589 	Fargb            uintptr
  15590 	Fargb_stride     int32
  15591 	Fpad2            [3]uint32_t
  15592 	Fwriter          WebPWriterFunction
  15593 	Fcustom_ptr      uintptr
  15594 	Fextra_info_type int32
  15595 	Fextra_info      uintptr
  15596 	Fstats           uintptr
  15597 	Ferror_code      WebPEncodingError1
  15598 	Fprogress_hook   WebPProgressHook
  15599 	Fuser_data       uintptr
  15600 	Fpad3            [3]uint32_t
  15601 	Fpad4            uintptr
  15602 	Fpad5            uintptr
  15603 	Fpad6            [8]uint32_t
  15604 	Fmemory_         uintptr
  15605 	Fmemory_argb_    uintptr
  15606 	Fpad7            [2]uintptr
  15607 }
  15608 
  15609 type WebPEncCSP = int32
  15610 
  15611 const WEBP_YUV420 = 0
  15612 const WEBP_YUV420A = 4
  15613 const WEBP_CSP_UV_MASK = 3
  15614 const WEBP_CSP_ALPHA_BIT = 4
  15615 
  15616 type WebPEncodingError = int32
  15617 
  15618 const VP8_ENC_OK = 0
  15619 const VP8_ENC_ERROR_OUT_OF_MEMORY = 1
  15620 const VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY = 2
  15621 const VP8_ENC_ERROR_NULL_PARAMETER = 3
  15622 const VP8_ENC_ERROR_INVALID_CONFIGURATION = 4
  15623 const VP8_ENC_ERROR_BAD_DIMENSION = 5
  15624 const VP8_ENC_ERROR_PARTITION0_OVERFLOW = 6
  15625 const VP8_ENC_ERROR_PARTITION_OVERFLOW = 7
  15626 const VP8_ENC_ERROR_BAD_WRITE = 8
  15627 const VP8_ENC_ERROR_FILE_TOO_BIG = 9
  15628 const VP8_ENC_ERROR_USER_ABORT = 10
  15629 const VP8_ENC_ERROR_LAST = 11
  15630 
  15631 type WebPConfig = struct {
  15632 	Flossless          int32
  15633 	Fquality           float32
  15634 	Fmethod            int32
  15635 	Fimage_hint        WebPImageHint1
  15636 	Ftarget_size       int32
  15637 	Ftarget_PSNR       float32
  15638 	Fsegments          int32
  15639 	Fsns_strength      int32
  15640 	Ffilter_strength   int32
  15641 	Ffilter_sharpness  int32
  15642 	Ffilter_type       int32
  15643 	Fautofilter        int32
  15644 	Falpha_compression int32
  15645 	Falpha_filtering   int32
  15646 	Falpha_quality     int32
  15647 	Fpass              int32
  15648 	Fshow_compressed   int32
  15649 	Fpreprocessing     int32
  15650 	Fpartitions        int32
  15651 	Fpartition_limit   int32
  15652 	Femulate_jpeg_size int32
  15653 	Fthread_level      int32
  15654 	Flow_memory        int32
  15655 	Fnear_lossless     int32
  15656 	Fexact             int32
  15657 	Fuse_delta_palette int32
  15658 	Fuse_sharp_yuv     int32
  15659 	Fqmin              int32
  15660 	Fqmax              int32
  15661 }
  15662 
  15663 type WebPImageHint = int32
  15664 
  15665 const WEBP_HINT_DEFAULT = 0
  15666 const WEBP_HINT_PICTURE = 1
  15667 const WEBP_HINT_PHOTO = 2
  15668 const WEBP_HINT_GRAPH = 3
  15669 const WEBP_HINT_LAST = 4
  15670 
  15671 type WebPAuxStats = struct {
  15672 	Fcoded_size                 int32
  15673 	FPSNR                       [5]float32
  15674 	Fblock_count                [3]int32
  15675 	Fheader_bytes               [2]int32
  15676 	Fresidual_bytes             [3][4]int32
  15677 	Fsegment_size               [4]int32
  15678 	Fsegment_quant              [4]int32
  15679 	Fsegment_level              [4]int32
  15680 	Falpha_data_size            int32
  15681 	Flayer_data_size            int32
  15682 	Flossless_features          uint32_t
  15683 	Fhistogram_bits             int32
  15684 	Ftransform_bits             int32
  15685 	Fcache_bits                 int32
  15686 	Fpalette_size               int32
  15687 	Flossless_size              int32
  15688 	Flossless_hdr_size          int32
  15689 	Flossless_data_size         int32
  15690 	Fcross_color_transform_bits int32
  15691 	Fpad                        [1]uint32_t
  15692 }
  15693 
  15694 type WebPMemoryWriter = struct {
  15695 	Fmem      uintptr
  15696 	Fsize     size_t
  15697 	Fmax_size size_t
  15698 	Fpad      [1]uint32_t
  15699 }
  15700 
  15701 type WebPImageHint1 = int32
  15702 
  15703 type WebPPreset1 = int32
  15704 
  15705 type WebPPreset = int32
  15706 
  15707 const WEBP_PRESET_DEFAULT = 0
  15708 const WEBP_PRESET_PICTURE = 1
  15709 const WEBP_PRESET_PHOTO = 2
  15710 const WEBP_PRESET_DRAWING = 3
  15711 const WEBP_PRESET_ICON = 4
  15712 const WEBP_PRESET_TEXT = 5
  15713 
  15714 type WebPWriterFunction = uintptr
  15715 
  15716 type WebPProgressHook = uintptr
  15717 
  15718 type WebPEncCSP1 = int32
  15719 
  15720 type WebPEncodingError1 = int32
  15721 
  15722 const MAX_LF_LEVELS = 64
  15723 const MAX_VARIABLE_LEVEL = 67
  15724 const MAX_LEVEL = 2047
  15725 
  15726 type VP8RDLevel = int32
  15727 
  15728 const RD_OPT_NONE = 0
  15729 const RD_OPT_BASIC = 1
  15730 const RD_OPT_TRELLIS = 2
  15731 const RD_OPT_TRELLIS_ALL = 3
  15732 
  15733 type score_t = int64
  15734 
  15735 type proba_t = uint32
  15736 
  15737 type ProbaArray = [3][11]uint8_t
  15738 
  15739 type StatsArray = [3][11]proba_t
  15740 
  15741 type CostArray = [3][68]uint16_t
  15742 
  15743 type CostArrayPtr = uintptr
  15744 
  15745 type CostArrayMap = [16][3]uintptr
  15746 
  15747 type LFStats = [4][64]float64
  15748 
  15749 type VP8Encoder = struct {
  15750 	Fconfig             uintptr
  15751 	Fpic                uintptr
  15752 	Ffilter_hdr         VP8EncFilterHeader
  15753 	Fsegment_hdr        VP8EncSegmentHeader
  15754 	Fprofile            int32
  15755 	Fmb_w               int32
  15756 	Fmb_h               int32
  15757 	Fpreds_w            int32
  15758 	Fnum_parts          int32
  15759 	Fbw                 VP8BitWriter
  15760 	Fparts              [8]VP8BitWriter
  15761 	Ftokens             VP8TBuffer
  15762 	Fpercent            int32
  15763 	Fhas_alpha          int32
  15764 	Falpha_data         uintptr
  15765 	Falpha_data_size    uint32_t
  15766 	Falpha_worker       WebPWorker
  15767 	Fdqm                [4]VP8SegmentInfo
  15768 	Fbase_quant         int32
  15769 	Falpha              int32
  15770 	Fuv_alpha           int32
  15771 	Fdq_y1_dc           int32
  15772 	Fdq_y2_dc           int32
  15773 	Fdq_y2_ac           int32
  15774 	Fdq_uv_dc           int32
  15775 	Fdq_uv_ac           int32
  15776 	Fproba              VP8EncProba
  15777 	Fsse                [4]uint64_t
  15778 	Fsse_count          uint64_t
  15779 	Fcoded_size         int32
  15780 	Fresidual_bytes     [3][4]int32
  15781 	Fblock_count        [3]int32
  15782 	Fmethod             int32
  15783 	Frd_opt_level       VP8RDLevel
  15784 	Fmax_i4_header_bits int32
  15785 	Fmb_header_limit    int32
  15786 	Fthread_level       int32
  15787 	Fdo_search          int32
  15788 	Fuse_tokens         int32
  15789 	Fmb_info            uintptr
  15790 	Fpreds              uintptr
  15791 	Fnz                 uintptr
  15792 	Fy_top              uintptr
  15793 	Fuv_top             uintptr
  15794 	Flf_stats           uintptr
  15795 	Ftop_derr           uintptr
  15796 }
  15797 
  15798 type VP8EncSegmentHeader = struct {
  15799 	Fnum_segments int32
  15800 	Fupdate_map   int32
  15801 	Fsize         int32
  15802 }
  15803 
  15804 type VP8EncProba = struct {
  15805 	Fsegments       [3]uint8_t
  15806 	Fskip_proba     uint8_t
  15807 	Fcoeffs         [4][8]ProbaArray
  15808 	Fstats          [4][8]StatsArray
  15809 	Flevel_cost     [4][8]CostArray
  15810 	Fremapped_costs [4]CostArrayMap
  15811 	Fdirty          int32
  15812 	Fuse_skip_proba int32
  15813 	Fnb_skip        int32
  15814 }
  15815 
  15816 type VP8EncFilterHeader = struct {
  15817 	Fsimple        int32
  15818 	Flevel         int32
  15819 	Fsharpness     int32
  15820 	Fi4x4_lf_delta int32
  15821 }
  15822 
  15823 type VP8MBInfo = struct {
  15824 	F__ccgo_align [0]uint32
  15825 	F__ccgo0      uint8
  15826 	Falpha        uint8_t
  15827 }
  15828 
  15829 type VP8SegmentInfo = struct {
  15830 	Fy1                 VP8Matrix
  15831 	Fy2                 VP8Matrix
  15832 	Fuv                 VP8Matrix
  15833 	Falpha              int32
  15834 	Fbeta               int32
  15835 	Fquant              int32
  15836 	Ffstrength          int32
  15837 	Fmax_edge           int32
  15838 	Fmin_disto          int32
  15839 	Flambda_i16         int32
  15840 	Flambda_i4          int32
  15841 	Flambda_uv          int32
  15842 	Flambda_mode        int32
  15843 	Flambda_trellis     int32
  15844 	Ftlambda            int32
  15845 	Flambda_trellis_i16 int32
  15846 	Flambda_trellis_i4  int32
  15847 	Flambda_trellis_uv  int32
  15848 	Fi4_penalty         score_t
  15849 }
  15850 
  15851 type DError = [2][2]int8_t
  15852 
  15853 type VP8ModeScore = struct {
  15854 	FD           score_t
  15855 	FSD          score_t
  15856 	FH           score_t
  15857 	FR           score_t
  15858 	Fscore       score_t
  15859 	Fy_dc_levels [16]int16_t
  15860 	Fy_ac_levels [16][16]int16_t
  15861 	Fuv_levels   [8][16]int16_t
  15862 	Fmode_i16    int32
  15863 	Fmodes_i4    [16]uint8_t
  15864 	Fmode_uv     int32
  15865 	Fnz          uint32_t
  15866 	Fderr        [2][3]int8_t
  15867 }
  15868 
  15869 type VP8EncIterator = struct {
  15870 	Fx            int32
  15871 	Fy            int32
  15872 	Fyuv_in       uintptr
  15873 	Fyuv_out      uintptr
  15874 	Fyuv_out2     uintptr
  15875 	Fyuv_p        uintptr
  15876 	Fenc          uintptr
  15877 	Fmb           uintptr
  15878 	Fbw           uintptr
  15879 	Fpreds        uintptr
  15880 	Fnz           uintptr
  15881 	Fi4_boundary  [40]uint8_t
  15882 	Fi4_top       uintptr
  15883 	Fi4           int32
  15884 	Ftop_nz       [9]int32
  15885 	Fleft_nz      [9]int32
  15886 	Fbit_count    [4][3]uint64_t
  15887 	Fluma_bits    uint64_t
  15888 	Fuv_bits      uint64_t
  15889 	Flf_stats     uintptr
  15890 	Fdo_trellis   int32
  15891 	Fcount_down   int32
  15892 	Fcount_down0  int32
  15893 	Fpercent0     int32
  15894 	Fleft_derr    DError
  15895 	Ftop_derr     uintptr
  15896 	Fy_left       uintptr
  15897 	Fu_left       uintptr
  15898 	Fv_left       uintptr
  15899 	Fy_top        uintptr
  15900 	Fuv_top       uintptr
  15901 	Fyuv_left_mem [88]uint8_t
  15902 	Fyuv_mem      [3359]uint8_t
  15903 }
  15904 
  15905 type VP8TBuffer = struct {
  15906 	Fpages     uintptr
  15907 	Flast_page uintptr
  15908 	Ftokens    uintptr
  15909 	Fleft      int32
  15910 	Fpage_size int32
  15911 	Ferror1    int32
  15912 }
  15913 
  15914 type Mode = int32
  15915 
  15916 const kLiteral = 0
  15917 const kCacheIdx = 1
  15918 const kCopy = 2
  15919 const kNone = 3
  15920 
  15921 type PixOrCopy = struct {
  15922 	Fmode             uint8_t
  15923 	Flen1             uint16_t
  15924 	Fargb_or_distance uint32_t
  15925 }
  15926 
  15927 type VP8LHashChain = struct {
  15928 	Foffset_length uintptr
  15929 	Fsize          int32
  15930 }
  15931 
  15932 type VP8LBackwardRefs = struct {
  15933 	Fblock_size  int32
  15934 	Ferror1      int32
  15935 	Frefs        uintptr
  15936 	Ftail        uintptr
  15937 	Ffree_blocks uintptr
  15938 	Flast_block  uintptr
  15939 }
  15940 
  15941 type VP8LRefsCursor = struct {
  15942 	Fcur_pos   uintptr
  15943 	Fcur_block uintptr
  15944 	Flast_pos  uintptr
  15945 }
  15946 
  15947 type VP8LLZ77Type = int32
  15948 
  15949 const kLZ77Standard = 1
  15950 const kLZ77RLE = 2
  15951 const kLZ77Box = 4
  15952 
  15953 type VP8LHistogram = struct {
  15954 	Fliteral           uintptr
  15955 	Fred               [256]uint32_t
  15956 	Fblue              [256]uint32_t
  15957 	Falpha             [256]uint32_t
  15958 	Fdistance          [40]uint32_t
  15959 	Fpalette_code_bits int32
  15960 	Ftrivial_symbol    [5]uint16_t
  15961 	Fbit_cost          uint64_t
  15962 	Fcosts             [5]uint64_t
  15963 	Fis_used           [5]uint8_t
  15964 	Fbin_id            uint16_t
  15965 }
  15966 
  15967 type VP8LHistogramSet = struct {
  15968 	Fsize       int32
  15969 	Fmax_size   int32
  15970 	Fhistograms uintptr
  15971 }
  15972 
  15973 type VP8LEncoderARGBContent = int32
  15974 
  15975 const kEncoderNone = 0
  15976 const kEncoderARGB = 1
  15977 const kEncoderNearLossless = 2
  15978 const kEncoderPalette = 3
  15979 
  15980 type VP8LEncoder = struct {
  15981 	Fconfig                     uintptr
  15982 	Fpic                        uintptr
  15983 	Fargb                       uintptr
  15984 	Fargb_content               VP8LEncoderARGBContent
  15985 	Fargb_scratch               uintptr
  15986 	Ftransform_data             uintptr
  15987 	Ftransform_mem              uintptr
  15988 	Ftransform_mem_size         size_t
  15989 	Fcurrent_width              int32
  15990 	Fhisto_bits                 int32
  15991 	Fpredictor_transform_bits   int32
  15992 	Fcross_color_transform_bits int32
  15993 	Fcache_bits                 int32
  15994 	Fuse_cross_color            int32
  15995 	Fuse_subtract_green         int32
  15996 	Fuse_predict                int32
  15997 	Fuse_palette                int32
  15998 	Fpalette_size               int32
  15999 	Fpalette                    [256]uint32_t
  16000 	Fpalette_sorted             [256]uint32_t
  16001 	Frefs                       [4]VP8LBackwardRefs
  16002 	Fhash_chain                 VP8LHashChain
  16003 }
  16004 
  16005 //------------------------------------------------------------------------------
  16006 
  16007 func EncodeLossless(tls *libc.TLS, data uintptr, width int32, height int32, effort_level int32, use_quality_100 int32, bw uintptr, stats uintptr) (r int32) {
  16008 	bp := tls.Alloc(384)
  16009 	defer tls.Free(384)
  16010 	var ok, v1 int32
  16011 	var v5 float32
  16012 	var _ /* config at bp+0 */ WebPConfig
  16013 	var _ /* picture at bp+120 */ WebPPicture
  16014 	_, _, _ = ok, v1, v5
  16015 	ok = 0
  16016 	v1 = WebPPictureInitInternal(tls, bp+120, int32(WEBP_ENCODER_ABI_VERSION))
  16017 	goto _2
  16018 _2:
  16019 	if !(v1 != 0) {
  16020 		return 0
  16021 	}
  16022 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fwidth = width
  16023 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fheight = height
  16024 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fuse_argb = int32(1)
  16025 	(**(**WebPPicture)(__ccgo_up(bp + 120))).Fstats = stats
  16026 	if !(WebPPictureAlloc(tls, bp+120) != 0) {
  16027 		return 0
  16028 	}
  16029 	// Transfer the alpha values to the green channel.
  16030 	(*(*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)
  16031 	v1 = WebPConfigInitInternal(tls, bp, int32(WEBP_PRESET_DEFAULT), libc.Float32FromFloat32(75), int32(WEBP_ENCODER_ABI_VERSION))
  16032 	goto _4
  16033 _4:
  16034 	if !(v1 != 0) {
  16035 		return 0
  16036 	}
  16037 	(**(**WebPConfig)(__ccgo_up(bp))).Flossless = int32(1)
  16038 	// Enable exact, or it would alter RGB values of transparent alpha, which is
  16039 	// normally OK but not here since we are not encoding the input image but  an
  16040 	// internal encoding-related image containing necessary exact information in
  16041 	// RGB channels.
  16042 	(**(**WebPConfig)(__ccgo_up(bp))).Fexact = int32(1)
  16043 	(**(**WebPConfig)(__ccgo_up(bp))).Fmethod = effort_level // impact is very small
  16044 	// Set a low default quality for encoding alpha. Ensure that Alpha quality at
  16045 	// lower methods (3 and below) is less than the threshold for triggering
  16046 	// costly 'BackwardReferencesTraceBackwards'.
  16047 	// If the alpha quality is set to 100 and the method to 6, allow for a high
  16048 	// lossless quality to trigger the cruncher.
  16049 	if use_quality_100 != 0 && effort_level == int32(6) {
  16050 		v5 = libc.Float32FromInt32(100)
  16051 	} else {
  16052 		v5 = float32(libc.Float32FromFloat32(8) * float32(effort_level))
  16053 	}
  16054 	(**(**WebPConfig)(__ccgo_up(bp))).Fquality = v5
  16055 	ok = VP8LEncodeStream(tls, bp, bp+120, bw)
  16056 	WebPPictureFree(tls, bp+120)
  16057 	ok = libc.BoolInt32(ok != 0 && !((*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 != 0))
  16058 	if !(ok != 0) {
  16059 		VP8LBitWriterWipeOut(tls, bw)
  16060 		return 0
  16061 	}
  16062 	return int32(1)
  16063 }
  16064 
  16065 // -----------------------------------------------------------------------------
  16066 
  16067 // C documentation
  16068 //
  16069 //	// Small struct to hold the result of a filter mode compression attempt.
  16070 type FilterTrial = struct {
  16071 	Fscore size_t
  16072 	Fbw    VP8BitWriter
  16073 	Fstats WebPAuxStats
  16074 }
  16075 
  16076 // C documentation
  16077 //
  16078 //	// This function always returns an initialized 'bw' object, even upon error.
  16079 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) {
  16080 	bp := tls.Alloc(48)
  16081 	defer tls.Free(48)
  16082 	var alpha_src, output, v1 uintptr
  16083 	var data_size, output_size, v2 size_t
  16084 	var filter_func WebPFilterFunc
  16085 	var ok int32
  16086 	var _ /* header at bp+0 */ uint8_t
  16087 	var _ /* tmp_bw at bp+8 */ VP8LBitWriter
  16088 	_, _, _, _, _, _, _, _ = alpha_src, data_size, filter_func, ok, output, output_size, v1, v2
  16089 	ok = 0
  16090 	data_size = libc.Uint64FromInt32(width * height)
  16091 	output = libc.UintptrFromInt32(0)
  16092 	output_size = uint64(0)
  16093 	// as per spec
  16094 	filter_func = WebPFilters[filter]
  16095 	if filter_func != libc.UintptrFromInt32(0) {
  16096 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{filter_func})))(tls, data, width, height, width, tmp_alpha)
  16097 		alpha_src = tmp_alpha
  16098 	} else {
  16099 		alpha_src = data
  16100 	}
  16101 	if method != ALPHA_NO_COMPRESSION {
  16102 		ok = VP8LBitWriterInit(tls, bp+8, data_size>>int32(3))
  16103 		ok = libc.BoolInt32(ok != 0 && EncodeLossless(tls, alpha_src, width, height, effort_level, libc.BoolInt32(!(reduce_levels != 0)), bp+8, result+56) != 0)
  16104 		if ok != 0 {
  16105 			output = VP8LBitWriterFinish(tls, bp+8)
  16106 			if (**(**VP8LBitWriter)(__ccgo_up(bp + 8))).Ferror1 != 0 {
  16107 				VP8LBitWriterWipeOut(tls, bp+8)
  16108 				libc.Xmemset(tls, result+8, 0, uint64(48))
  16109 				return 0
  16110 			}
  16111 			v1 = bp + 8
  16112 			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)))
  16113 			goto _3
  16114 		_3:
  16115 			output_size = v2
  16116 			if output_size > data_size {
  16117 				// compressed size is larger than source! Revert to uncompressed mode.
  16118 				method = ALPHA_NO_COMPRESSION
  16119 				VP8LBitWriterWipeOut(tls, bp+8)
  16120 			}
  16121 		} else {
  16122 			VP8LBitWriterWipeOut(tls, bp+8)
  16123 			libc.Xmemset(tls, result+8, 0, uint64(48))
  16124 			return 0
  16125 		}
  16126 	}
  16127 	if method == ALPHA_NO_COMPRESSION {
  16128 		output = alpha_src
  16129 		output_size = data_size
  16130 		ok = int32(1)
  16131 	}
  16132 	// Emit final result.
  16133 	**(**uint8_t)(__ccgo_up(bp)) = libc.Uint8FromInt32(method | filter<<int32(2))
  16134 	if reduce_levels != 0 {
  16135 		**(**uint8_t)(__ccgo_up(bp)) = libc.Uint8FromInt32(int32(**(**uint8_t)(__ccgo_up(bp))) | libc.Int32FromInt32(ALPHA_PREPROCESSED_LEVELS)<<libc.Int32FromInt32(4))
  16136 	}
  16137 	if !(VP8BitWriterInit(tls, result+8, uint64(ALPHA_HEADER_LEN)+output_size) != 0) {
  16138 		ok = 0
  16139 	}
  16140 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, bp, uint64(ALPHA_HEADER_LEN)) != 0)
  16141 	ok = libc.BoolInt32(ok != 0 && VP8BitWriterAppend(tls, result+8, output, output_size) != 0)
  16142 	if method != ALPHA_NO_COMPRESSION {
  16143 		VP8LBitWriterWipeOut(tls, bp+8)
  16144 	}
  16145 	ok = libc.BoolInt32(ok != 0 && !((*FilterTrial)(unsafe.Pointer(result)).Fbw.Ferror1 != 0))
  16146 	v2 = (*VP8BitWriter)(unsafe.Pointer(result + 8)).Fpos
  16147 	goto _5
  16148 _5:
  16149 	(*FilterTrial)(unsafe.Pointer(result)).Fscore = v2
  16150 	return ok
  16151 }
  16152 
  16153 // -----------------------------------------------------------------------------
  16154 
  16155 func GetNumColors(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r int32) {
  16156 	var color [256]uint8_t
  16157 	var colors, i, j int32
  16158 	var p uintptr
  16159 	_, _, _, _, _ = color, colors, i, j, p
  16160 	colors = 0
  16161 	color = [256]uint8_t{}
  16162 	j = 0
  16163 	for {
  16164 		if !(j < height) {
  16165 			break
  16166 		}
  16167 		p = data + uintptr(j*stride)
  16168 		i = 0
  16169 		for {
  16170 			if !(i < width) {
  16171 				break
  16172 			}
  16173 			color[**(**uint8_t)(__ccgo_up(p + uintptr(i)))] = uint8(1)
  16174 			goto _2
  16175 		_2:
  16176 			;
  16177 			i = i + 1
  16178 		}
  16179 		goto _1
  16180 	_1:
  16181 		;
  16182 		j = j + 1
  16183 	}
  16184 	j = 0
  16185 	for {
  16186 		if !(j < int32(256)) {
  16187 			break
  16188 		}
  16189 		if libc.Int32FromUint8(color[j]) > 0 {
  16190 			colors = colors + 1
  16191 		}
  16192 		goto _3
  16193 	_3:
  16194 		;
  16195 		j = j + 1
  16196 	}
  16197 	return colors
  16198 }
  16199 
  16200 // C documentation
  16201 //
  16202 //	// Given the input 'filter' option, return an OR'd bit-set of filters to try.
  16203 func GetFilterMap(tls *libc.TLS, alpha uintptr, width int32, height int32, filter int32, effort_level int32) (r uint32_t) {
  16204 	var bit_map uint32_t
  16205 	var kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1 int32
  16206 	_, _, _, _, _, _ = bit_map, kMaxColorsForFilterNone, kMinColorsForFilterNone, num_colors, try_filter_none, v1
  16207 	bit_map = 0
  16208 	if filter == int32(WEBP_FILTER_FAST) {
  16209 		// Quick estimate of the best candidate.
  16210 		try_filter_none = libc.BoolInt32(effort_level > int32(3))
  16211 		kMinColorsForFilterNone = int32(16)
  16212 		kMaxColorsForFilterNone = int32(192)
  16213 		num_colors = GetNumColors(tls, alpha, width, height, width)
  16214 		// For low number of colors, NONE yields better compression.
  16215 		if num_colors <= kMinColorsForFilterNone {
  16216 			v1 = int32(WEBP_FILTER_NONE)
  16217 		} else {
  16218 			v1 = WebPEstimateBestFilter(tls, alpha, width, height, width)
  16219 		}
  16220 		filter = v1
  16221 		bit_map = bit_map | libc.Uint32FromInt32(int32(1)<<filter)
  16222 		// For large number of colors, try FILTER_NONE in addition to the best
  16223 		// filter as well.
  16224 		if try_filter_none != 0 || num_colors > kMaxColorsForFilterNone {
  16225 			bit_map = bit_map | libc.Uint32FromInt32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE))
  16226 		}
  16227 	} else {
  16228 		if filter == int32(WEBP_FILTER_NONE) {
  16229 			bit_map = libc.Uint32FromInt32(libc.Int32FromInt32(1) << int32(WEBP_FILTER_NONE))
  16230 		} else { // WEBP_FILTER_BEST -> try all
  16231 			bit_map = libc.Uint32FromInt32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_LAST) - libc.Int32FromInt32(1))
  16232 		}
  16233 	}
  16234 	return bit_map
  16235 }
  16236 
  16237 func InitFilterTrial(tls *libc.TLS, score uintptr) {
  16238 	(*FilterTrial)(unsafe.Pointer(score)).Fscore = uint64(^libc.Uint32FromUint32(0))
  16239 	VP8BitWriterInit(tls, score+8, uint64(0))
  16240 }
  16241 
  16242 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) {
  16243 	bp := tls.Alloc(496)
  16244 	defer tls.Free(496)
  16245 	var filtered_alpha, v4 uintptr
  16246 	var ok int32
  16247 	var try_map uint32_t
  16248 	var v2 size_t
  16249 	var _ /* best at bp+0 */ FilterTrial
  16250 	var _ /* trial at bp+248 */ FilterTrial
  16251 	_, _, _, _, _ = filtered_alpha, ok, try_map, v2, v4
  16252 	ok = int32(1)
  16253 	try_map = GetFilterMap(tls, alpha, width, height, filter, effort_level)
  16254 	InitFilterTrial(tls, bp)
  16255 	if try_map != libc.Uint32FromInt32(libc.Int32FromInt32(1)<<int32(WEBP_FILTER_NONE)) {
  16256 		filtered_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16257 		if filtered_alpha == libc.UintptrFromInt32(0) {
  16258 			return 0
  16259 		}
  16260 		filter = int32(WEBP_FILTER_NONE)
  16261 		for {
  16262 			if !(ok != 0 && try_map != 0) {
  16263 				break
  16264 			}
  16265 			if try_map&uint32(1) != 0 {
  16266 				ok = EncodeAlphaInternal(tls, alpha, width, height, method, filter, reduce_levels, effort_level, filtered_alpha, bp+248)
  16267 				if ok != 0 && (**(**FilterTrial)(__ccgo_up(bp + 248))).Fscore < (**(**FilterTrial)(__ccgo_up(bp))).Fscore {
  16268 					VP8BitWriterWipeOut(tls, bp+8)
  16269 					**(**FilterTrial)(__ccgo_up(bp)) = **(**FilterTrial)(__ccgo_up(bp + 248))
  16270 				} else {
  16271 					VP8BitWriterWipeOut(tls, bp+248+8)
  16272 				}
  16273 			}
  16274 			goto _1
  16275 		_1:
  16276 			;
  16277 			filter = filter + 1
  16278 			try_map = try_map >> uint32(1)
  16279 		}
  16280 		WebPSafeFree(tls, filtered_alpha)
  16281 	} else {
  16282 		ok = EncodeAlphaInternal(tls, alpha, width, height, method, int32(WEBP_FILTER_NONE), reduce_levels, effort_level, libc.UintptrFromInt32(0), bp)
  16283 	}
  16284 	if ok != 0 {
  16285 		if stats != libc.UintptrFromInt32(0) {
  16286 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_features
  16287 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fhistogram_bits
  16288 			(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Ftransform_bits
  16289 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcross_color_transform_bits
  16290 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fcache_bits
  16291 			(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Fpalette_size
  16292 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_size
  16293 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_hdr_size
  16294 			(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = (**(**FilterTrial)(__ccgo_up(bp))).Fstats.Flossless_data_size
  16295 		}
  16296 		v2 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fpos
  16297 		goto _3
  16298 	_3:
  16299 		**(**size_t)(__ccgo_up(output_size)) = v2
  16300 		v4 = (*VP8BitWriter)(unsafe.Pointer(bp + 8)).Fbuf
  16301 		goto _5
  16302 	_5:
  16303 		**(**uintptr)(__ccgo_up(output)) = v4
  16304 	} else {
  16305 		VP8BitWriterWipeOut(tls, bp+8)
  16306 	}
  16307 	return ok
  16308 }
  16309 
  16310 func EncodeAlpha(tls *libc.TLS, enc uintptr, quality int32, method int32, filter int32, effort_level int32, output uintptr, output_size uintptr) (r int32) {
  16311 	bp := tls.Alloc(16)
  16312 	defer tls.Free(16)
  16313 	var alpha_levels, height, ok, reduce_levels, width, v1 int32
  16314 	var data_size size_t
  16315 	var pic, quant_alpha uintptr
  16316 	var _ /* sse at bp+0 */ uint64_t
  16317 	_, _, _, _, _, _, _, _, _ = alpha_levels, data_size, height, ok, pic, quant_alpha, reduce_levels, width, v1
  16318 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  16319 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  16320 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  16321 	quant_alpha = libc.UintptrFromInt32(0)
  16322 	data_size = libc.Uint64FromInt32(width * height)
  16323 	**(**uint64_t)(__ccgo_up(bp)) = uint64(0)
  16324 	ok = int32(1)
  16325 	reduce_levels = libc.BoolInt32(quality < libc.Int32FromInt32(100))
  16326 	// quick correctness checks
  16327 	// as per spec
  16328 	if quality < 0 || quality > int32(100) {
  16329 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16330 	}
  16331 	if method < ALPHA_NO_COMPRESSION || method > int32(ALPHA_LOSSLESS_COMPRESSION) {
  16332 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  16333 	}
  16334 	if method == ALPHA_NO_COMPRESSION {
  16335 		// Don't filter, as filtering will make no impact on compressed size.
  16336 		filter = int32(WEBP_FILTER_NONE)
  16337 	}
  16338 	quant_alpha = WebPSafeMalloc(tls, uint64(1), data_size)
  16339 	if quant_alpha == libc.UintptrFromInt32(0) {
  16340 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16341 	}
  16342 	// Extract alpha data (width x height) from raw_data (stride x height).
  16343 	WebPCopyPlane(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fa, (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride, quant_alpha, width, width, height)
  16344 	if reduce_levels != 0 {
  16345 		if quality <= int32(70) {
  16346 			v1 = int32(2) + quality/int32(5)
  16347 		} else {
  16348 			v1 = int32(16) + (quality-int32(70))*int32(8)
  16349 		} // No Quantization required for 'quality = 100'.
  16350 		// 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence
  16351 		// mapped to moderate quality 70. Hence Quality:[0, 70] -> Levels:[2, 16]
  16352 		// and Quality:]70, 100] -> Levels:]16, 256].
  16353 		alpha_levels = v1
  16354 		ok = QuantizeLevels(tls, quant_alpha, width, height, alpha_levels, bp)
  16355 	}
  16356 	if ok != 0 {
  16357 		VP8FiltersInit(tls)
  16358 		ok = ApplyFiltersAndEncode(tls, quant_alpha, width, height, data_size, method, filter, reduce_levels, effort_level, output, output_size, (*WebPPicture)(unsafe.Pointer(pic)).Fstats)
  16359 		if !(ok != 0) {
  16360 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  16361 		}
  16362 		if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) { // need stats?
  16363 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fstats)) += libc.Int32FromUint64(**(**size_t)(__ccgo_up(output_size)))
  16364 			**(**uint64_t)(__ccgo_up(enc + 23512 + 3*8)) = **(**uint64_t)(__ccgo_up(bp))
  16365 		}
  16366 	}
  16367 	WebPSafeFree(tls, quant_alpha)
  16368 	return ok
  16369 }
  16370 
  16371 //------------------------------------------------------------------------------
  16372 // Main calls
  16373 
  16374 func CompressAlphaJob(tls *libc.TLS, arg1 uintptr, unused uintptr) (r int32) {
  16375 	bp := tls.Alloc(16)
  16376 	defer tls.Free(16)
  16377 	var config, enc uintptr
  16378 	var effort_level, v1, v2 int32
  16379 	var filter WEBP_FILTER_TYPE
  16380 	var _ /* alpha_data at bp+0 */ uintptr
  16381 	var _ /* alpha_size at bp+8 */ size_t
  16382 	_, _, _, _, _, _ = config, effort_level, enc, filter, v1, v2
  16383 	enc = arg1
  16384 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  16385 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  16386 	**(**size_t)(__ccgo_up(bp + 8)) = uint64(0)
  16387 	effort_level = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  16388 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == 0 {
  16389 		v1 = int32(WEBP_FILTER_NONE)
  16390 	} else {
  16391 		if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering == int32(1) {
  16392 			v2 = int32(WEBP_FILTER_FAST)
  16393 		} else {
  16394 			v2 = int32(WEBP_FILTER_BEST)
  16395 		}
  16396 		v1 = v2
  16397 	} // maps to [0..6]
  16398 	filter = v1
  16399 	if !(EncodeAlpha(tls, enc, (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality, (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression, filter, effort_level, bp, bp+8) != 0) {
  16400 		return 0
  16401 	}
  16402 	if **(**size_t)(__ccgo_up(bp + 8)) != uint64(uint32(**(**size_t)(__ccgo_up(bp + 8)))) { // Soundness check.
  16403 		WebPSafeFree(tls, **(**uintptr)(__ccgo_up(bp)))
  16404 		return 0
  16405 	}
  16406 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(**(**size_t)(__ccgo_up(bp + 8)))
  16407 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = **(**uintptr)(__ccgo_up(bp))
  16408 	_ = unused
  16409 	return int32(1)
  16410 }
  16411 
  16412 func VP8EncInitAlpha(tls *libc.TLS, enc uintptr) {
  16413 	var worker uintptr
  16414 	_ = worker
  16415 	WebPInitAlphaProcessing(tls)
  16416 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = WebPPictureHasTransparency(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic)
  16417 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16418 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16419 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16420 		worker = enc + 560
  16421 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, worker)
  16422 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = enc
  16423 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  16424 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(CompressAlphaJob)
  16425 	}
  16426 }
  16427 
  16428 func VP8EncStartAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16429 	var worker uintptr
  16430 	_ = worker
  16431 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16432 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16433 			worker = enc + 560
  16434 			// Makes sure worker is good to go.
  16435 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FReset})))(tls, worker) != 0) {
  16436 				return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  16437 			}
  16438 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FLaunch})))(tls, worker)
  16439 			return int32(1)
  16440 		} else {
  16441 			return CompressAlphaJob(tls, enc, libc.UintptrFromInt32(0)) // just do the job right away
  16442 		}
  16443 	}
  16444 	return int32(1)
  16445 }
  16446 
  16447 func VP8EncFinishAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16448 	var worker uintptr
  16449 	_ = worker
  16450 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  16451 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16452 			worker = enc + 560
  16453 			if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker) != 0) {
  16454 				return 0
  16455 			} // error
  16456 		}
  16457 	}
  16458 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  16459 }
  16460 
  16461 func VP8EncDeleteAlpha(tls *libc.TLS, enc uintptr) (r int32) {
  16462 	var ok int32
  16463 	var worker uintptr
  16464 	_, _ = ok, worker
  16465 	ok = int32(1)
  16466 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level > 0 {
  16467 		worker = enc + 560
  16468 		// finish anything left in flight
  16469 		ok = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FSync})))(tls, worker)
  16470 		// still need to end the worker, even if !ok
  16471 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FEnd})))(tls, worker)
  16472 	}
  16473 	WebPSafeFree(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data)
  16474 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data = libc.UintptrFromInt32(0)
  16475 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size = uint32(0)
  16476 	(*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha = 0
  16477 	return ok
  16478 }
  16479 
  16480 const MAX_ALPHA = 255
  16481 const MAX_INTRA16_MODE = 2
  16482 const MAX_INTRA4_MODE = 2
  16483 const MAX_ITERS_K_MEANS = 6
  16484 const MAX_UV_MODE = 2
  16485 
  16486 //------------------------------------------------------------------------------
  16487 
  16488 // Copyright 2011 Google Inc. All Rights Reserved.
  16489 //
  16490 // Use of this source code is governed by a BSD-style license
  16491 // that can be found in the COPYING file in the root of the source
  16492 // tree. An additional intellectual property rights grant can be found
  16493 // in the file PATENTS. All contributing project authors may
  16494 // be found in the AUTHORS file in the root of the source tree.
  16495 // -----------------------------------------------------------------------------
  16496 //
  16497 // Multi-threaded worker
  16498 //
  16499 // Author: Skal (pascal.massimino@gmail.com)
  16500 
  16501 // Copyright 2012 Google Inc. All Rights Reserved.
  16502 //
  16503 // Use of this source code is governed by a BSD-style license
  16504 // that can be found in the COPYING file in the root of the source
  16505 // tree. An additional intellectual property rights grant can be found
  16506 // in the file PATENTS. All contributing project authors may
  16507 // be found in the AUTHORS file in the root of the source tree.
  16508 // -----------------------------------------------------------------------------
  16509 //
  16510 // Misc. common utility functions
  16511 //
  16512 // Authors: Skal (pascal.massimino@gmail.com)
  16513 //          Urvang (urvang@google.com)
  16514 
  16515 // Copyright 2011 Google Inc. All Rights Reserved.
  16516 //
  16517 // Use of this source code is governed by a BSD-style license
  16518 // that can be found in the COPYING file in the root of the source
  16519 // tree. An additional intellectual property rights grant can be found
  16520 // in the file PATENTS. All contributing project authors may
  16521 // be found in the AUTHORS file in the root of the source tree.
  16522 // -----------------------------------------------------------------------------
  16523 //
  16524 //   WebP encoder: main interface
  16525 //
  16526 // Author: Skal (pascal.massimino@gmail.com)
  16527 
  16528 // Copyright 2010 Google Inc. All Rights Reserved.
  16529 //
  16530 // Use of this source code is governed by a BSD-style license
  16531 // that can be found in the COPYING file in the root of the source
  16532 // tree. An additional intellectual property rights grant can be found
  16533 // in the file PATENTS. All contributing project authors may
  16534 // be found in the AUTHORS file in the root of the source tree.
  16535 // -----------------------------------------------------------------------------
  16536 //
  16537 //  Common types + memory wrappers
  16538 //
  16539 // Author: Skal (pascal.massimino@gmail.com)
  16540 
  16541 //------------------------------------------------------------------------------
  16542 // Smooth the segment map by replacing isolated block by the majority of its
  16543 // neighbours.
  16544 
  16545 func SmoothSegmentMap(tls *libc.TLS, enc uintptr) {
  16546 	var cnt [4]int32
  16547 	var h, majority_cnt_3_x_3_grid, majority_seg, n, w, x, y int32
  16548 	var mb, mb1, tmp uintptr
  16549 	_, _, _, _, _, _, _, _, _, _, _ = cnt, h, majority_cnt_3_x_3_grid, majority_seg, mb, mb1, n, tmp, w, x, y
  16550 	w = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  16551 	h = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  16552 	majority_cnt_3_x_3_grid = int32(5)
  16553 	tmp = WebPSafeMalloc(tls, libc.Uint64FromInt32(w*h), uint64(1))
  16554 	// no overflow, as per spec
  16555 	if tmp == libc.UintptrFromInt32(0) {
  16556 		return
  16557 	}
  16558 	y = int32(1)
  16559 	for {
  16560 		if !(y < h-int32(1)) {
  16561 			break
  16562 		}
  16563 		x = int32(1)
  16564 		for {
  16565 			if !(x < w-int32(1)) {
  16566 				break
  16567 			}
  16568 			cnt = [4]int32{}
  16569 			mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16570 			majority_seg = int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5))
  16571 			// Check the 8 neighbouring segment values.
  16572 			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
  16573 			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
  16574 			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
  16575 			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
  16576 			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
  16577 			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
  16578 			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
  16579 			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
  16580 			n = 0
  16581 			for {
  16582 				if !(n < int32(NUM_MB_SEGMENTS)) {
  16583 					break
  16584 				}
  16585 				if cnt[n] >= majority_cnt_3_x_3_grid {
  16586 					majority_seg = n
  16587 					break
  16588 				}
  16589 				goto _3
  16590 			_3:
  16591 				;
  16592 				n = n + 1
  16593 			}
  16594 			**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w))) = libc.Uint8FromInt32(majority_seg)
  16595 			goto _2
  16596 		_2:
  16597 			;
  16598 			x = x + 1
  16599 		}
  16600 		goto _1
  16601 	_1:
  16602 		;
  16603 		y = y + 1
  16604 	}
  16605 	y = int32(1)
  16606 	for {
  16607 		if !(y < h-int32(1)) {
  16608 			break
  16609 		}
  16610 		x = int32(1)
  16611 		for {
  16612 			if !(x < w-int32(1)) {
  16613 				break
  16614 			}
  16615 			mb1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(x+w*y)*4
  16616 			libc.SetBitFieldPtr8Uint32(mb1+0, uint32(**(**uint8_t)(__ccgo_up(tmp + uintptr(x+y*w)))), 5, 0x60)
  16617 			goto _5
  16618 		_5:
  16619 			;
  16620 			x = x + 1
  16621 		}
  16622 		goto _4
  16623 	_4:
  16624 		;
  16625 		y = y + 1
  16626 	}
  16627 	WebPSafeFree(tls, tmp)
  16628 }
  16629 
  16630 //------------------------------------------------------------------------------
  16631 // set segment susceptibility 'alpha' / 'beta'
  16632 
  16633 func clip1(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  16634 	var v1, v2 int32
  16635 	_, _ = v1, v2
  16636 	if v < m {
  16637 		v1 = m
  16638 	} else {
  16639 		if v > M {
  16640 			v2 = M
  16641 		} else {
  16642 			v2 = v
  16643 		}
  16644 		v1 = v2
  16645 	}
  16646 	return v1
  16647 }
  16648 
  16649 func SetSegmentAlphas(tls *libc.TLS, enc uintptr, centers uintptr, mid int32) {
  16650 	var alpha, beta, max, min, n, nb int32
  16651 	_, _, _, _, _, _ = alpha, beta, max, min, n, nb
  16652 	nb = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16653 	min = **(**int32)(__ccgo_up(centers))
  16654 	max = **(**int32)(__ccgo_up(centers))
  16655 	if nb > int32(1) {
  16656 		n = 0
  16657 		for {
  16658 			if !(n < nb) {
  16659 				break
  16660 			}
  16661 			if min > **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16662 				min = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16663 			}
  16664 			if max < **(**int32)(__ccgo_up(centers + uintptr(n)*4)) {
  16665 				max = **(**int32)(__ccgo_up(centers + uintptr(n)*4))
  16666 			}
  16667 			goto _1
  16668 		_1:
  16669 			;
  16670 			n = n + 1
  16671 		}
  16672 	}
  16673 	if max == min {
  16674 		max = min + int32(1)
  16675 	}
  16676 	n = 0
  16677 	for {
  16678 		if !(n < nb) {
  16679 			break
  16680 		}
  16681 		alpha = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - mid) / (max - min)
  16682 		beta = int32(255) * (**(**int32)(__ccgo_up(centers + uintptr(n)*4)) - min) / (max - min)
  16683 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Falpha = clip1(tls, alpha, -int32(127), int32(127))
  16684 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(n)*744))).Fbeta = clip1(tls, beta, 0, int32(255))
  16685 		goto _2
  16686 	_2:
  16687 		;
  16688 		n = n + 1
  16689 	}
  16690 }
  16691 
  16692 //------------------------------------------------------------------------------
  16693 // Compute susceptibility based on DCT-coeff histograms:
  16694 // the higher, the "easier" the macroblock is to compress.
  16695 
  16696 func FinalAlphaValue(tls *libc.TLS, alpha int32) (r int32) {
  16697 	alpha = int32(MAX_ALPHA) - alpha
  16698 	return clip1(tls, alpha, 0, int32(MAX_ALPHA))
  16699 }
  16700 
  16701 func GetAlpha(tls *libc.TLS, histo uintptr) (r int32) {
  16702 	var alpha, last_non_zero, max_value, v1 int32
  16703 	_, _, _, _ = alpha, last_non_zero, max_value, v1
  16704 	// 'alpha' will later be clipped to [0..MAX_ALPHA] range, clamping outer
  16705 	// values which happen to be mostly noise. This leaves the maximum precision
  16706 	// for handling the useful small values which contribute most.
  16707 	max_value = (*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value
  16708 	last_non_zero = (*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero
  16709 	if max_value > int32(1) {
  16710 		v1 = libc.Int32FromInt32(2) * libc.Int32FromInt32(MAX_ALPHA) * last_non_zero / max_value
  16711 	} else {
  16712 		v1 = 0
  16713 	}
  16714 	alpha = v1
  16715 	return alpha
  16716 }
  16717 
  16718 func InitHistogram(tls *libc.TLS, histo uintptr) {
  16719 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = 0
  16720 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = int32(1)
  16721 }
  16722 
  16723 //------------------------------------------------------------------------------
  16724 // Simplified k-Means, to assign Nb segments based on alpha-histogram
  16725 
  16726 func AssignSegments(tls *libc.TLS, enc uintptr, alphas uintptr) {
  16727 	bp := tls.Alloc(48)
  16728 	defer tls.Free(48)
  16729 	var a, alpha, displaced, k, max_a, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1 int32
  16730 	var map1 [256]int32
  16731 	var mb uintptr
  16732 	var _ /* accum at bp+16 */ [4]int32
  16733 	var _ /* centers at bp+0 */ [4]int32
  16734 	var _ /* dist_accum at bp+32 */ [4]int32
  16735 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, alpha, displaced, k, map1, max_a, mb, min_a, n, nb, new_center, range_a, smooth, total_weight, weighted_average, v1
  16736 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  16737 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  16738 	} else {
  16739 		v1 = int32(NUM_MB_SEGMENTS)
  16740 	}
  16741 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  16742 	// explicit check is needed to avoid spurious warning about 'n + 1' exceeding
  16743 	// array bounds of 'centers' with some compilers (noticed with gcc-4.9).
  16744 	nb = v1
  16745 	weighted_average = 0
  16746 	min_a = 0
  16747 	max_a = int32(MAX_ALPHA)
  16748 	// bracket the input
  16749 	n = 0
  16750 	for {
  16751 		if !(n <= int32(MAX_ALPHA) && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16752 			break
  16753 		}
  16754 		goto _2
  16755 	_2:
  16756 		;
  16757 		n = n + 1
  16758 	}
  16759 	min_a = n
  16760 	n = int32(MAX_ALPHA)
  16761 	for {
  16762 		if !(n > min_a && **(**int32)(__ccgo_up(alphas + uintptr(n)*4)) == 0) {
  16763 			break
  16764 		}
  16765 		goto _3
  16766 	_3:
  16767 		;
  16768 		n = n - 1
  16769 	}
  16770 	max_a = n
  16771 	range_a = max_a - min_a
  16772 	// Spread initial centers evenly
  16773 	k = 0
  16774 	n = libc.Int32FromInt32(1)
  16775 	for {
  16776 		if !(k < nb) {
  16777 			break
  16778 		}
  16779 		(**(**[4]int32)(__ccgo_up(bp)))[k] = min_a + n*range_a/(int32(2)*nb)
  16780 		goto _4
  16781 	_4:
  16782 		;
  16783 		k = k + 1
  16784 		n = n + int32(2)
  16785 	}
  16786 	k = 0
  16787 	for {
  16788 		if !(k < int32(MAX_ITERS_K_MEANS)) {
  16789 			break
  16790 		}
  16791 		// Reset stats
  16792 		n = 0
  16793 		for {
  16794 			if !(n < nb) {
  16795 				break
  16796 			}
  16797 			(**(**[4]int32)(__ccgo_up(bp + 16)))[n] = 0
  16798 			(**(**[4]int32)(__ccgo_up(bp + 32)))[n] = 0
  16799 			goto _6
  16800 		_6:
  16801 			;
  16802 			n = n + 1
  16803 		}
  16804 		// Assign nearest center for each 'a'
  16805 		n = 0 // track the nearest center for current 'a'
  16806 		a = min_a
  16807 		for {
  16808 			if !(a <= max_a) {
  16809 				break
  16810 			}
  16811 			if **(**int32)(__ccgo_up(alphas + uintptr(a)*4)) != 0 {
  16812 				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]) {
  16813 					n = n + 1
  16814 				}
  16815 				map1[a] = n
  16816 				// accumulate contribution into best centroid
  16817 				**(**int32)(__ccgo_up(bp + 32 + uintptr(n)*4)) += a * **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16818 				**(**int32)(__ccgo_up(bp + 16 + uintptr(n)*4)) += **(**int32)(__ccgo_up(alphas + uintptr(a)*4))
  16819 			}
  16820 			goto _7
  16821 		_7:
  16822 			;
  16823 			a = a + 1
  16824 		}
  16825 		// All point are classified. Move the centroids to the
  16826 		// center of their respective cloud.
  16827 		displaced = 0
  16828 		weighted_average = 0
  16829 		total_weight = 0
  16830 		n = 0
  16831 		for {
  16832 			if !(n < nb) {
  16833 				break
  16834 			}
  16835 			if (**(**[4]int32)(__ccgo_up(bp + 16)))[n] != 0 {
  16836 				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]
  16837 				displaced = displaced + libc.Xabs(tls, (**(**[4]int32)(__ccgo_up(bp)))[n]-new_center)
  16838 				(**(**[4]int32)(__ccgo_up(bp)))[n] = new_center
  16839 				weighted_average = weighted_average + new_center*(**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16840 				total_weight = total_weight + (**(**[4]int32)(__ccgo_up(bp + 16)))[n]
  16841 			}
  16842 			goto _8
  16843 		_8:
  16844 			;
  16845 			n = n + 1
  16846 		}
  16847 		weighted_average = (weighted_average + total_weight/int32(2)) / total_weight
  16848 		if displaced < int32(5) {
  16849 			break
  16850 		} // no need to keep on looping...
  16851 		goto _5
  16852 	_5:
  16853 		;
  16854 		k = k + 1
  16855 	}
  16856 	// Map each original value to the closest centroid
  16857 	n = 0
  16858 	for {
  16859 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  16860 			break
  16861 		}
  16862 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  16863 		alpha = libc.Int32FromUint8((*VP8MBInfo)(unsafe.Pointer(mb)).Falpha)
  16864 		libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(map1[alpha]), 5, 0x60)
  16865 		(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = libc.Uint8FromInt32((**(**[4]int32)(__ccgo_up(bp)))[map1[alpha]]) // for the record.
  16866 		goto _9
  16867 	_9:
  16868 		;
  16869 		n = n + 1
  16870 	}
  16871 	if nb > int32(1) {
  16872 		smooth = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpreprocessing & libc.Int32FromInt32(1)
  16873 		if smooth != 0 {
  16874 			SmoothSegmentMap(tls, enc)
  16875 		}
  16876 	}
  16877 	SetSegmentAlphas(tls, enc, bp, weighted_average) // pick some alphas.
  16878 }
  16879 
  16880 //------------------------------------------------------------------------------
  16881 // Macroblock analysis: collect histogram for each mode, deduce the maximal
  16882 // susceptibility and set best modes for this macroblock.
  16883 // Segment assignment is done later.
  16884 
  16885 // Number of modes to inspect for 'alpha' evaluation. We don't need to test all
  16886 // the possible modes during the analysis phase: we risk falling into a local
  16887 // optimum, or be subject to boundary effect
  16888 
  16889 func MBAnalyzeBestIntra16Mode(tls *libc.TLS, it uintptr) (r int32) {
  16890 	bp := tls.Alloc(16)
  16891 	defer tls.Free(16)
  16892 	var alpha, best_alpha, best_mode, max_mode, mode int32
  16893 	var _ /* histo at bp+0 */ VP8Histogram
  16894 	_, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode
  16895 	max_mode = int32(MAX_INTRA16_MODE)
  16896 	best_alpha = -int32(1)
  16897 	best_mode = 0
  16898 	VP8MakeLuma16Preds(tls, it)
  16899 	mode = 0
  16900 	for {
  16901 		if !(mode < max_mode) {
  16902 			break
  16903 		}
  16904 		InitHistogram(tls, bp)
  16905 		(*(*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)
  16906 		alpha = GetAlpha(tls, bp)
  16907 		if alpha > best_alpha {
  16908 			best_alpha = alpha
  16909 			best_mode = mode
  16910 		}
  16911 		goto _1
  16912 	_1:
  16913 		;
  16914 		mode = mode + 1
  16915 	}
  16916 	VP8SetIntra16Mode(tls, it, best_mode)
  16917 	return best_alpha
  16918 }
  16919 
  16920 func FastMBAnalyze(tls *libc.TLS, it uintptr) (r int32) {
  16921 	bp := tls.Alloc(80)
  16922 	defer tls.Free(80)
  16923 	var k, q int32
  16924 	var kThreshold, m, m2 uint32_t
  16925 	var _ /* dc at bp+0 */ [16]uint32_t
  16926 	var _ /* modes at bp+64 */ [16]uint8_t
  16927 	_, _, _, _, _ = k, kThreshold, m, m2, q
  16928 	// Empirical cut-off value, should be around 16 (~=block size). We use the
  16929 	// [8-17] range and favor intra4 at high quality, intra16 for low quality.
  16930 	q = int32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fconfig)).Fquality)
  16931 	kThreshold = libc.Uint32FromInt32(int32(8) + (libc.Int32FromInt32(17)-libc.Int32FromInt32(8))*q/int32(100))
  16932 	k = 0
  16933 	for {
  16934 		if !(k < int32(16)) {
  16935 			break
  16936 		}
  16937 		(*(*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)
  16938 		goto _1
  16939 	_1:
  16940 		;
  16941 		k = k + int32(4)
  16942 	}
  16943 	m = uint32(0)
  16944 	m2 = uint32(0)
  16945 	k = libc.Int32FromInt32(0)
  16946 	for {
  16947 		if !(k < int32(16)) {
  16948 			break
  16949 		}
  16950 		m = m + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16951 		m2 = m2 + (**(**[16]uint32_t)(__ccgo_up(bp)))[k]*(**(**[16]uint32_t)(__ccgo_up(bp)))[k]
  16952 		goto _2
  16953 	_2:
  16954 		;
  16955 		k = k + 1
  16956 	}
  16957 	if kThreshold*m2 < m*m {
  16958 		VP8SetIntra16Mode(tls, it, 0) // DC16
  16959 	} else {
  16960 		**(**[16]uint8_t)(__ccgo_up(bp + 64)) = [16]uint8_t{} // DC4
  16961 		VP8SetIntra4Mode(tls, it, bp+64)
  16962 	}
  16963 	return 0
  16964 }
  16965 
  16966 func MBAnalyzeBestUVMode(tls *libc.TLS, it uintptr) (r int32) {
  16967 	bp := tls.Alloc(16)
  16968 	defer tls.Free(16)
  16969 	var alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha int32
  16970 	var _ /* histo at bp+0 */ VP8Histogram
  16971 	_, _, _, _, _, _ = alpha, best_alpha, best_mode, max_mode, mode, smallest_alpha
  16972 	best_alpha = -int32(1)
  16973 	smallest_alpha = 0
  16974 	best_mode = 0
  16975 	max_mode = int32(MAX_UV_MODE)
  16976 	VP8MakeChroma8Preds(tls, it)
  16977 	mode = 0
  16978 	for {
  16979 		if !(mode < max_mode) {
  16980 			break
  16981 		}
  16982 		InitHistogram(tls, bp)
  16983 		(*(*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)
  16984 		alpha = GetAlpha(tls, bp)
  16985 		if alpha > best_alpha {
  16986 			best_alpha = alpha
  16987 		}
  16988 		// The best prediction mode tends to be the one with the smallest alpha.
  16989 		if mode == 0 || alpha < smallest_alpha {
  16990 			smallest_alpha = alpha
  16991 			best_mode = mode
  16992 		}
  16993 		goto _1
  16994 	_1:
  16995 		;
  16996 		mode = mode + 1
  16997 	}
  16998 	VP8SetIntraUVMode(tls, it, best_mode)
  16999 	return best_alpha
  17000 }
  17001 
  17002 func MBAnalyze(tls *libc.TLS, it uintptr, alphas uintptr, alpha uintptr, uv_alpha uintptr) {
  17003 	var best_alpha, best_uv_alpha int32
  17004 	var enc uintptr
  17005 	_, _, _ = best_alpha, best_uv_alpha, enc
  17006 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  17007 	VP8SetIntra16Mode(tls, it, 0) // default: Intra16, DC_PRED
  17008 	VP8SetSkip(tls, it, 0)        // not skipped
  17009 	VP8SetSegment(tls, it, 0)     // default segment, spec-wise.
  17010 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod <= int32(1) {
  17011 		best_alpha = FastMBAnalyze(tls, it)
  17012 	} else {
  17013 		best_alpha = MBAnalyzeBestIntra16Mode(tls, it)
  17014 	}
  17015 	best_uv_alpha = MBAnalyzeBestUVMode(tls, it)
  17016 	// Final susceptibility mix
  17017 	best_alpha = (int32(3)*best_alpha + best_uv_alpha + int32(2)) >> int32(2)
  17018 	best_alpha = FinalAlphaValue(tls, best_alpha)
  17019 	**(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) = **(**int32)(__ccgo_up(alphas + uintptr(best_alpha)*4)) + 1
  17020 	(*VP8MBInfo)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb)).Falpha = libc.Uint8FromInt32(best_alpha) // for later remapping.
  17021 	// Accumulate for later complexity analysis.
  17022 	**(**int32)(__ccgo_up(alpha)) += best_alpha // mixed susceptibility (not just luma)
  17023 	**(**int32)(__ccgo_up(uv_alpha)) += best_uv_alpha
  17024 }
  17025 
  17026 func DefaultMBInfo(tls *libc.TLS, mb uintptr) {
  17027 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(1), 0, 0x3) // I16x16
  17028 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 2, 0xc)
  17029 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 4, 0x10) // not skipped
  17030 	libc.SetBitFieldPtr8Uint32(mb+0, libc.Uint32FromInt32(0), 5, 0x60) // default segment
  17031 	(*VP8MBInfo)(unsafe.Pointer(mb)).Falpha = uint8(0)
  17032 }
  17033 
  17034 //------------------------------------------------------------------------------
  17035 // Main analysis loop:
  17036 // Collect all susceptibilities for each macroblock and record their
  17037 // distribution in alphas[]. Segments is assigned a-posteriori, based on
  17038 // this histogram.
  17039 // We also pick an intra16 prediction mode, which shouldn't be considered
  17040 // final except for fast-encode settings. We can also pick some intra4 modes
  17041 // and decide intra4/intra16, but that's usually almost always a bad choice at
  17042 // this stage.
  17043 
  17044 func ResetAllMBInfo(tls *libc.TLS, enc uintptr) {
  17045 	var n int32
  17046 	_ = n
  17047 	n = 0
  17048 	for {
  17049 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  17050 			break
  17051 		}
  17052 		DefaultMBInfo(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4)
  17053 		goto _1
  17054 	_1:
  17055 		;
  17056 		n = n + 1
  17057 	}
  17058 	// Default susceptibilities.
  17059 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Falpha = 0
  17060 	(**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fbeta = 0
  17061 	// Note: we can't compute this 'alpha' / 'uv_alpha' -> set to default value.
  17062 	(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = 0
  17063 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = 0
  17064 	WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+int32(20), enc+536)
  17065 }
  17066 
  17067 // C documentation
  17068 //
  17069 //	// struct used to collect job result
  17070 type SegmentJob = struct {
  17071 	Fworker         WebPWorker
  17072 	Falphas         [256]int32
  17073 	Falpha          int32
  17074 	Fuv_alpha       int32
  17075 	Fit             VP8EncIterator
  17076 	Fdelta_progress int32
  17077 }
  17078 
  17079 // C documentation
  17080 //
  17081 //	// main work call
  17082 func DoSegmentsJob(tls *libc.TLS, arg1 uintptr, arg2 uintptr) (r int32) {
  17083 	bp := tls.Alloc(64)
  17084 	defer tls.Free(64)
  17085 	var it, job, scratch uintptr
  17086 	var ok int32
  17087 	var _ /* tmp at bp+0 */ [63]uint8_t
  17088 	_, _, _, _ = it, job, ok, scratch
  17089 	job = arg1
  17090 	it = arg2
  17091 	ok = int32(1)
  17092 	if !(VP8IteratorIsDone(tls, it) != 0) {
  17093 		scratch = uintptr((uintptr_t(bp) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  17094 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, it) != 0 {
  17095 			// Let's pretend we have perfect lossless reconstruction.
  17096 			VP8IteratorImport(tls, it, scratch)
  17097 			MBAnalyze(tls, it, job+48, job+1072, job+1076)
  17098 			ok = VP8IteratorProgress(tls, it, (*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress)
  17099 		}
  17100 	}
  17101 	return ok
  17102 }
  17103 
  17104 // C documentation
  17105 //
  17106 //	// initialize the job struct with some tasks to perform
  17107 func InitSegmentJob(tls *libc.TLS, enc uintptr, job uintptr, start_row int32, end_row int32) {
  17108 	var v1 int32
  17109 	_ = v1
  17110 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(WebPGetWorkerInterface(tls))).FInit})))(tls, job)
  17111 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata1 = job
  17112 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fdata2 = job + 1080
  17113 	(*SegmentJob)(unsafe.Pointer(job)).Fworker.Fhook = __ccgo_fp(DoSegmentsJob)
  17114 	VP8IteratorInit(tls, enc, job+1080)
  17115 	VP8IteratorSetRow(tls, job+1080, start_row)
  17116 	VP8IteratorSetCountDown(tls, job+1080, (end_row-start_row)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  17117 	libc.Xmemset(tls, job+48, 0, uint64(1024))
  17118 	(*SegmentJob)(unsafe.Pointer(job)).Falpha = 0
  17119 	(*SegmentJob)(unsafe.Pointer(job)).Fuv_alpha = 0
  17120 	// only one of both jobs can record the progress, since we don't
  17121 	// expect the user's hook to be multi-thread safe
  17122 	if start_row == 0 {
  17123 		v1 = int32(20)
  17124 	} else {
  17125 		v1 = 0
  17126 	}
  17127 	(*SegmentJob)(unsafe.Pointer(job)).Fdelta_progress = v1
  17128 }
  17129 
  17130 // C documentation
  17131 //
  17132 //	// main entry point
  17133 func VP8EncAnalyze(tls *libc.TLS, enc uintptr) (r int32) {
  17134 	bp := tls.Alloc(4944)
  17135 	defer tls.Free(4944)
  17136 	var do_mt, do_segments, last_row, ok, total_mb int32
  17137 	var worker_interface uintptr
  17138 	var _ /* main_job at bp+0 */ SegmentJob
  17139 	_, _, _, _, _, _ = do_mt, do_segments, last_row, ok, total_mb, worker_interface
  17140 	ok = int32(1)
  17141 	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.
  17142 	if do_segments != 0 {
  17143 		last_row = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  17144 		total_mb = last_row * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w
  17145 		do_mt = 0
  17146 		worker_interface = WebPGetWorkerInterface(tls)
  17147 		if do_mt != 0 {
  17148 		} else {
  17149 			// Even for single-thread case, we use the generic Worker tools.
  17150 			InitSegmentJob(tls, enc, bp, 0, last_row)
  17151 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp)
  17152 			ok = ok & (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp)
  17153 		}
  17154 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp)
  17155 		if ok != 0 {
  17156 			(*VP8Encoder)(unsafe.Pointer(enc)).Falpha = (**(**SegmentJob)(__ccgo_up(bp))).Falpha / total_mb
  17157 			(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_alpha = (**(**SegmentJob)(__ccgo_up(bp))).Fuv_alpha / total_mb
  17158 			AssignSegments(tls, enc, bp+48)
  17159 		}
  17160 	} else { // Use only one default segment.
  17161 		ResetAllMBInfo(tls, enc)
  17162 	}
  17163 	if !(ok != 0) {
  17164 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY)) // imprecise
  17165 	}
  17166 	return ok
  17167 }
  17168 
  17169 const COST_CACHE_INTERVAL_SIZE_MAX = 500
  17170 const COST_MANAGER_MAX_FREE_LIST = 10
  17171 const VALUES_IN_BYTE = 256
  17172 
  17173 var kHashMul10 = uint32(0x1e35a7bd)
  17174 
  17175 type CostModel = struct {
  17176 	Falpha    [256]uint32_t
  17177 	Fred      [256]uint32_t
  17178 	Fblue     [256]uint32_t
  17179 	Fdistance [40]uint32_t
  17180 	Fliteral  uintptr
  17181 }
  17182 
  17183 func ConvertPopulationCountTableToBitEstimates(tls *libc.TLS, num_symbols int32, population_counts uintptr, output uintptr) {
  17184 	var i, nonzeros int32
  17185 	var logsum, sum, v2, v3, v7, v8 uint32_t
  17186 	var v10, v5 uint32
  17187 	_, _, _, _, _, _, _, _, _, _ = i, logsum, nonzeros, sum, v10, v2, v3, v5, v7, v8
  17188 	sum = uint32(0)
  17189 	nonzeros = 0
  17190 	i = 0
  17191 	for {
  17192 		if !(i < num_symbols) {
  17193 			break
  17194 		}
  17195 		sum = sum + **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  17196 		if **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4)) > uint32(0) {
  17197 			nonzeros = nonzeros + 1
  17198 		}
  17199 		goto _1
  17200 	_1:
  17201 		;
  17202 		i = i + 1
  17203 	}
  17204 	if nonzeros <= int32(1) {
  17205 		libc.Xmemset(tls, output, 0, libc.Uint64FromInt32(num_symbols)*uint64(4))
  17206 	} else {
  17207 		v2 = sum
  17208 		if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  17209 			v5 = kLog2Table[v2]
  17210 		} else {
  17211 			v5 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v2)
  17212 		}
  17213 		v3 = v5
  17214 		goto _4
  17215 	_4:
  17216 		logsum = v3
  17217 		i = 0
  17218 		for {
  17219 			if !(i < num_symbols) {
  17220 				break
  17221 			}
  17222 			v7 = **(**uint32_t)(__ccgo_up(population_counts + uintptr(i)*4))
  17223 			if v7 < uint32(LOG_LOOKUP_IDX_MAX) {
  17224 				v10 = kLog2Table[v7]
  17225 			} else {
  17226 				v10 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v7)
  17227 			}
  17228 			v8 = v10
  17229 			goto _9
  17230 		_9:
  17231 			**(**uint32_t)(__ccgo_up(output + uintptr(i)*4)) = logsum - v8
  17232 			goto _6
  17233 		_6:
  17234 			;
  17235 			i = i + 1
  17236 		}
  17237 	}
  17238 }
  17239 
  17240 func CostModelBuild(tls *libc.TLS, m uintptr, xsize int32, cache_bits int32, refs uintptr) (r int32) {
  17241 	var histo uintptr
  17242 	var ok, v1, v2, v4 int32
  17243 	_, _, _, _, _ = histo, ok, v1, v2, v4
  17244 	ok = 0
  17245 	histo = VP8LAllocateHistogram(tls, cache_bits)
  17246 	if histo == libc.UintptrFromInt32(0) {
  17247 		goto Error
  17248 	}
  17249 	// The following code is similar to VP8LHistogramCreate but converts the
  17250 	// distance to plane code.
  17251 	VP8LHistogramInit(tls, histo, cache_bits, int32(1))
  17252 	VP8LHistogramStoreRefs(tls, refs, __ccgo_fp(VP8LDistanceToPlaneCode), xsize, histo)
  17253 	v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  17254 	if v1 > 0 {
  17255 		v4 = int32(1) << v1
  17256 	} else {
  17257 		v4 = 0
  17258 	}
  17259 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17260 	goto _3
  17261 _3:
  17262 	ConvertPopulationCountTableToBitEstimates(tls, v2, (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral, (*CostModel)(unsafe.Pointer(m)).Fliteral)
  17263 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+8, m+1024)
  17264 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+1032, m+2048)
  17265 	ConvertPopulationCountTableToBitEstimates(tls, int32(VALUES_IN_BYTE), histo+2056, m)
  17266 	ConvertPopulationCountTableToBitEstimates(tls, int32(NUM_DISTANCE_CODES), histo+3080, m+3072)
  17267 	ok = int32(1)
  17268 	goto Error
  17269 Error:
  17270 	;
  17271 	VP8LFreeHistogram(tls, histo)
  17272 	return ok
  17273 }
  17274 
  17275 func GetLiteralCost(tls *libc.TLS, m uintptr, v uint32_t) (r int64_t) {
  17276 	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)))
  17277 }
  17278 
  17279 func GetCacheCost(tls *libc.TLS, m uintptr, idx uint32_t) (r int64_t) {
  17280 	var literal_idx int32
  17281 	_ = literal_idx
  17282 	literal_idx = libc.Int32FromUint32(libc.Uint32FromInt32(libc.Int32FromInt32(VALUES_IN_BYTE)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + idx)
  17283 	return libc.Int64FromUint32(**(**uint32_t)(__ccgo_up((*CostModel)(unsafe.Pointer(m)).Fliteral + uintptr(literal_idx)*4)))
  17284 }
  17285 
  17286 func GetLengthCost(tls *libc.TLS, m uintptr, length uint32_t) (r int64_t) {
  17287 	bp := tls.Alloc(16)
  17288 	defer tls.Free(16)
  17289 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17290 	var prefix_code VP8LPrefixCode
  17291 	var v2, v3 uintptr
  17292 	var _ /* code at bp+0 */ int32
  17293 	var _ /* extra_bits at bp+4 */ int32
  17294 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17295 	v1 = libc.Int32FromUint32(length)
  17296 	v2 = bp
  17297 	v3 = bp + 4
  17298 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17299 		prefix_code = kPrefixEncodeCode[v1]
  17300 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17301 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17302 	} else {
  17303 		v4 = v1
  17304 		v4 = v4 - 1
  17305 		v5 = v4
  17306 		v6 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v5))
  17307 		goto _7
  17308 	_7:
  17309 		highest_bit = v6
  17310 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17311 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17312 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17313 	}
  17314 	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)
  17315 }
  17316 
  17317 func GetDistanceCost(tls *libc.TLS, m uintptr, distance2 uint32_t) (r int64_t) {
  17318 	bp := tls.Alloc(16)
  17319 	defer tls.Free(16)
  17320 	var highest_bit, second_highest_bit, v1, v4, v5, v6 int32
  17321 	var prefix_code VP8LPrefixCode
  17322 	var v2, v3 uintptr
  17323 	var _ /* code at bp+0 */ int32
  17324 	var _ /* extra_bits at bp+4 */ int32
  17325 	_, _, _, _, _, _, _, _, _ = highest_bit, prefix_code, second_highest_bit, v1, v2, v3, v4, v5, v6
  17326 	v1 = libc.Int32FromUint32(distance2)
  17327 	v2 = bp
  17328 	v3 = bp + 4
  17329 	if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  17330 		prefix_code = kPrefixEncodeCode[v1]
  17331 		**(**int32)(__ccgo_up(v2)) = int32(prefix_code.Fcode)
  17332 		**(**int32)(__ccgo_up(v3)) = int32(prefix_code.Fextra_bits)
  17333 	} else {
  17334 		v4 = v1
  17335 		v4 = v4 - 1
  17336 		v5 = v4
  17337 		v6 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v5))
  17338 		goto _7
  17339 	_7:
  17340 		highest_bit = v6
  17341 		second_highest_bit = v4 >> (highest_bit - int32(1)) & int32(1)
  17342 		**(**int32)(__ccgo_up(v3)) = highest_bit - int32(1)
  17343 		**(**int32)(__ccgo_up(v2)) = int32(2)*highest_bit + second_highest_bit
  17344 	}
  17345 	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)
  17346 }
  17347 
  17348 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) {
  17349 	var color, v3 uint32_t
  17350 	var cost_val, v10, v11, v9 int64_t
  17351 	var ix, key, key1, v1, v4, v6, v8 int32
  17352 	var v13 int64
  17353 	var v2 uintptr
  17354 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = color, cost_val, ix, key, key1, v1, v10, v11, v13, v2, v3, v4, v6, v8, v9
  17355 	cost_val = prev_cost
  17356 	color = **(**uint32_t)(__ccgo_up(argb3 + uintptr(idx)*4))
  17357 	if use_color_cache != 0 {
  17358 		v2 = hashers
  17359 		v3 = color
  17360 		v4 = libc.Int32FromUint32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17361 		goto _5
  17362 	_5:
  17363 		key1 = v4
  17364 		if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key1)*4)) == v3 {
  17365 			v8 = key1
  17366 		} else {
  17367 			v8 = -int32(1)
  17368 		}
  17369 		v6 = v8
  17370 		goto _7
  17371 	_7:
  17372 		v1 = v6
  17373 	} else {
  17374 		v1 = -int32(1)
  17375 	}
  17376 	ix = v1
  17377 	if ix >= 0 {
  17378 		// use_color_cache is true and hashers contains color
  17379 		v9 = GetCacheCost(tls, cost_model, libc.Uint32FromInt32(ix)) * int64(68)
  17380 		v10 = int64(100)
  17381 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17382 			v13 = (v9 + v10/int64(2)) / v10
  17383 		} else {
  17384 			v13 = (v9 - v10/int64(2)) / v10
  17385 		}
  17386 		v11 = v13
  17387 		goto _12
  17388 	_12:
  17389 		cost_val = cost_val + v11
  17390 	} else {
  17391 		if use_color_cache != 0 {
  17392 			v2 = hashers
  17393 			v3 = color
  17394 			v1 = libc.Int32FromUint32(v3 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  17395 			goto _17
  17396 		_17:
  17397 			key = v1
  17398 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v3
  17399 		}
  17400 		v9 = GetLiteralCost(tls, cost_model, color) * int64(82)
  17401 		v10 = int64(100)
  17402 		if libc.BoolInt32(v9 < 0) == libc.BoolInt32(v10 < 0) {
  17403 			v13 = (v9 + v10/int64(2)) / v10
  17404 		} else {
  17405 			v13 = (v9 - v10/int64(2)) / v10
  17406 		}
  17407 		v11 = v13
  17408 		goto _21
  17409 	_21:
  17410 		cost_val = cost_val + v11
  17411 	}
  17412 	if **(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) > cost_val {
  17413 		**(**int64_t)(__ccgo_up(cost + uintptr(idx)*8)) = cost_val
  17414 		**(**uint16_t)(__ccgo_up(dist_array + uintptr(idx)*2)) = uint16(1) // only one is inserted.
  17415 	}
  17416 }
  17417 
  17418 // -----------------------------------------------------------------------------
  17419 // CostManager and interval handling
  17420 
  17421 // Empirical value to avoid high memory consumption but good for performance.
  17422 
  17423 // C documentation
  17424 //
  17425 //	// To perform backward reference every pixel at index 'index' is considered and
  17426 //	// the cost for the MAX_LENGTH following pixels computed. Those following pixels
  17427 //	// at index 'index' + k (k from 0 to MAX_LENGTH) have a cost of:
  17428 //	//     cost = distance cost at index + GetLengthCost(cost_model, k)
  17429 //	// and the minimum value is kept. GetLengthCost(cost_model, k) is cached in an
  17430 //	// array of size MAX_LENGTH.
  17431 //	// Instead of performing MAX_LENGTH comparisons per pixel, we keep track of the
  17432 //	// minimal values using intervals of constant cost.
  17433 //	// An interval is defined by the 'index' of the pixel that generated it and
  17434 //	// is only useful in a range of indices from 'start' to 'end' (exclusive), i.e.
  17435 //	// it contains the minimum value for pixels between start and end.
  17436 //	// Intervals are stored in a linked list and ordered by 'start'. When a new
  17437 //	// interval has a better value, old intervals are split or removed. There are
  17438 //	// therefore no overlapping intervals.
  17439 type CostInterval = struct {
  17440 	Fcost     int64_t
  17441 	Fstart    int32
  17442 	Fend      int32
  17443 	Findex    int32
  17444 	Fprevious uintptr
  17445 	Fnext     uintptr
  17446 }
  17447 
  17448 // C documentation
  17449 //
  17450 //	// The GetLengthCost(cost_model, k) are cached in a CostCacheInterval.
  17451 type CostCacheInterval = struct {
  17452 	Fcost  int64_t
  17453 	Fstart int32
  17454 	Fend   int32
  17455 }
  17456 
  17457 // C documentation
  17458 //
  17459 //	// This structure is in charge of managing intervals and costs.
  17460 //	// It caches the different CostCacheInterval, caches the different
  17461 //	// GetLengthCost(cost_model, k) in cost_cache and the CostInterval's (whose
  17462 //	// 'count' is limited by COST_CACHE_INTERVAL_SIZE_MAX).
  17463 type CostManager = struct {
  17464 	Fhead                 uintptr
  17465 	Fcount                int32
  17466 	Fcache_intervals      uintptr
  17467 	Fcache_intervals_size size_t
  17468 	Fcost_cache           [4095]int64_t
  17469 	Fcosts                uintptr
  17470 	Fdist_array           uintptr
  17471 	Fintervals            [10]CostInterval
  17472 	Ffree_intervals       uintptr
  17473 	Frecycled_intervals   uintptr
  17474 }
  17475 
  17476 func CostIntervalAddToFreeList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17477 	(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17478 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = interval
  17479 }
  17480 
  17481 func CostIntervalIsInFreeList(tls *libc.TLS, manager uintptr, interval uintptr) (r int32) {
  17482 	return libc.BoolInt32(interval >= manager+32808 && interval <= manager+32808+uintptr(libc.Int32FromInt32(COST_MANAGER_MAX_FREE_LIST)-libc.Int32FromInt32(1))*40)
  17483 }
  17484 
  17485 func CostManagerInitFreeList(tls *libc.TLS, manager uintptr) {
  17486 	var i int32
  17487 	_ = i
  17488 	(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = libc.UintptrFromInt32(0)
  17489 	i = 0
  17490 	for {
  17491 		if !(i < int32(COST_MANAGER_MAX_FREE_LIST)) {
  17492 			break
  17493 		}
  17494 		CostIntervalAddToFreeList(tls, manager, manager+32808+uintptr(i)*40)
  17495 		goto _1
  17496 	_1:
  17497 		;
  17498 		i = i + 1
  17499 	}
  17500 }
  17501 
  17502 func DeleteIntervalList(tls *libc.TLS, manager uintptr, interval uintptr) {
  17503 	var next uintptr
  17504 	_ = next
  17505 	for interval != libc.UintptrFromInt32(0) {
  17506 		next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17507 		if !(CostIntervalIsInFreeList(tls, manager, interval) != 0) {
  17508 			WebPSafeFree(tls, interval)
  17509 		} // else: do nothing
  17510 		interval = next
  17511 	}
  17512 }
  17513 
  17514 func CostManagerClear(tls *libc.TLS, manager uintptr) {
  17515 	if manager == libc.UintptrFromInt32(0) {
  17516 		return
  17517 	}
  17518 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcosts)
  17519 	WebPSafeFree(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals)
  17520 	// Clear the interval lists.
  17521 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17522 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17523 	DeleteIntervalList(tls, manager, (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals)
  17524 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17525 	// Reset pointers, 'count' and 'cache_intervals_size'.
  17526 	libc.Xmemset(tls, manager, 0, uint64(33224))
  17527 	CostManagerInitFreeList(tls, manager)
  17528 }
  17529 
  17530 func CostManagerInit(tls *libc.TLS, manager uintptr, dist_array uintptr, pix_count int32, cost_model uintptr) (r int32) {
  17531 	var cost_cache_size, i, v1 int32
  17532 	var cost_val int64_t
  17533 	var cur uintptr
  17534 	_, _, _, _, _ = cost_cache_size, cost_val, cur, i, v1
  17535 	if pix_count > libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  17536 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  17537 	} else {
  17538 		v1 = pix_count
  17539 	}
  17540 	cost_cache_size = v1
  17541 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = libc.UintptrFromInt32(0)
  17542 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = libc.UintptrFromInt32(0)
  17543 	(*CostManager)(unsafe.Pointer(manager)).Fhead = libc.UintptrFromInt32(0)
  17544 	(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = libc.UintptrFromInt32(0)
  17545 	(*CostManager)(unsafe.Pointer(manager)).Fcount = 0
  17546 	(*CostManager)(unsafe.Pointer(manager)).Fdist_array = dist_array
  17547 	CostManagerInitFreeList(tls, manager)
  17548 	// Fill in the 'cost_cache'.
  17549 	// Has to be done in two passes due to a GCC bug on i686
  17550 	// related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
  17551 	i = 0
  17552 	for {
  17553 		if !(i < cost_cache_size) {
  17554 			break
  17555 		}
  17556 		**(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) = GetLengthCost(tls, cost_model, libc.Uint32FromInt32(i))
  17557 		goto _2
  17558 	_2:
  17559 		;
  17560 		i = i + 1
  17561 	}
  17562 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = uint64(1)
  17563 	i = int32(1)
  17564 	for {
  17565 		if !(i < cost_cache_size) {
  17566 			break
  17567 		}
  17568 		// Get the number of bound intervals.
  17569 		if **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8)) != **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i-int32(1))*8)) {
  17570 			(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size + 1
  17571 		}
  17572 		goto _3
  17573 	_3:
  17574 		;
  17575 		i = i + 1
  17576 	}
  17577 	// With the current cost model, we usually have below 20 intervals.
  17578 	// The worst case scenario with a cost model would be if every length has a
  17579 	// different cost, hence MAX_LENGTH but that is impossible with the current
  17580 	// implementation that spirals around a pixel.
  17581 	(*CostManager)(unsafe.Pointer(manager)).Fcache_intervals = WebPSafeMalloc(tls, (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size, uint64(16))
  17582 	if (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals == libc.UintptrFromInt32(0) {
  17583 		CostManagerClear(tls, manager)
  17584 		return 0
  17585 	}
  17586 	// Fill in the 'cache_intervals'.
  17587 	cur = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17588 	// Consecutive values in 'cost_cache' are compared and if a big enough
  17589 	// difference is found, a new interval is created and bounded.
  17590 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = 0
  17591 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = int32(1)
  17592 	(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = **(**int64_t)(__ccgo_up(manager + 32))
  17593 	i = int32(1)
  17594 	for {
  17595 		if !(i < cost_cache_size) {
  17596 			break
  17597 		}
  17598 		cost_val = **(**int64_t)(__ccgo_up(manager + 32 + uintptr(i)*8))
  17599 		if cost_val != (*CostCacheInterval)(unsafe.Pointer(cur)).Fcost {
  17600 			cur += 16
  17601 			// Initialize an interval.
  17602 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fstart = i
  17603 			(*CostCacheInterval)(unsafe.Pointer(cur)).Fcost = cost_val
  17604 		}
  17605 		(*CostCacheInterval)(unsafe.Pointer(cur)).Fend = i + int32(1)
  17606 		goto _4
  17607 	_4:
  17608 		;
  17609 		i = i + 1
  17610 	}
  17611 	(*CostManager)(unsafe.Pointer(manager)).Fcosts = WebPSafeMalloc(tls, libc.Uint64FromInt32(pix_count), uint64(8))
  17612 	if (*CostManager)(unsafe.Pointer(manager)).Fcosts == libc.UintptrFromInt32(0) {
  17613 		CostManagerClear(tls, manager)
  17614 		return 0
  17615 	}
  17616 	// Set the initial 'costs' to INT64_MAX for every pixel as we will keep the
  17617 	// minimum.
  17618 	i = 0
  17619 	for {
  17620 		if !(i < pix_count) {
  17621 			break
  17622 		}
  17623 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  17624 		goto _5
  17625 	_5:
  17626 		;
  17627 		i = i + 1
  17628 	}
  17629 	return int32(1)
  17630 }
  17631 
  17632 // C documentation
  17633 //
  17634 //	// Given the cost and the position that define an interval, update the cost at
  17635 //	// pixel 'i' if it is smaller than the previously computed value.
  17636 func UpdateCost(tls *libc.TLS, manager uintptr, i int32, position int32, cost int64_t) {
  17637 	var k int32
  17638 	_ = k
  17639 	k = i - position
  17640 	if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) > cost {
  17641 		**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(i)*8)) = cost
  17642 		**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(i)*2)) = libc.Uint16FromInt32(k + int32(1))
  17643 	}
  17644 }
  17645 
  17646 // C documentation
  17647 //
  17648 //	// Given the cost and the position that define an interval, update the cost for
  17649 //	// all the pixels between 'start' and 'end' excluded.
  17650 func UpdateCostPerInterval(tls *libc.TLS, manager uintptr, start int32, end int32, position int32, cost int64_t) {
  17651 	var i int32
  17652 	_ = i
  17653 	i = start
  17654 	for {
  17655 		if !(i < end) {
  17656 			break
  17657 		}
  17658 		UpdateCost(tls, manager, i, position, cost)
  17659 		goto _1
  17660 	_1:
  17661 		;
  17662 		i = i + 1
  17663 	}
  17664 }
  17665 
  17666 // C documentation
  17667 //
  17668 //	// Given two intervals, make 'prev' be the previous one of 'next' in 'manager'.
  17669 func ConnectIntervals(tls *libc.TLS, manager uintptr, prev uintptr, next uintptr) {
  17670 	if prev != libc.UintptrFromInt32(0) {
  17671 		(*CostInterval)(unsafe.Pointer(prev)).Fnext = next
  17672 	} else {
  17673 		(*CostManager)(unsafe.Pointer(manager)).Fhead = next
  17674 	}
  17675 	if next != libc.UintptrFromInt32(0) {
  17676 		(*CostInterval)(unsafe.Pointer(next)).Fprevious = prev
  17677 	}
  17678 }
  17679 
  17680 // C documentation
  17681 //
  17682 //	// Pop an interval in the manager.
  17683 func PopInterval(tls *libc.TLS, manager uintptr, interval uintptr) {
  17684 	if interval == libc.UintptrFromInt32(0) {
  17685 		return
  17686 	}
  17687 	ConnectIntervals(tls, manager, (*CostInterval)(unsafe.Pointer(interval)).Fprevious, (*CostInterval)(unsafe.Pointer(interval)).Fnext)
  17688 	if CostIntervalIsInFreeList(tls, manager, interval) != 0 {
  17689 		CostIntervalAddToFreeList(tls, manager, interval)
  17690 	} else { // recycle regularly malloc'd intervals too
  17691 		(*CostInterval)(unsafe.Pointer(interval)).Fnext = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17692 		(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = interval
  17693 	}
  17694 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount - 1
  17695 }
  17696 
  17697 // C documentation
  17698 //
  17699 //	// Update the cost at index i by going over all the stored intervals that
  17700 //	// overlap with i.
  17701 //	// If 'do_clean_intervals' is set to something different than 0, intervals that
  17702 //	// end before 'i' will be popped.
  17703 func UpdateCostAtIndex(tls *libc.TLS, manager uintptr, i int32, do_clean_intervals int32) {
  17704 	var current, next uintptr
  17705 	_, _ = current, next
  17706 	current = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17707 	for current != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart <= i {
  17708 		next = (*CostInterval)(unsafe.Pointer(current)).Fnext
  17709 		if (*CostInterval)(unsafe.Pointer(current)).Fend <= i {
  17710 			if do_clean_intervals != 0 {
  17711 				// We have an outdated interval, remove it.
  17712 				PopInterval(tls, manager, current)
  17713 			}
  17714 		} else {
  17715 			UpdateCost(tls, manager, i, (*CostInterval)(unsafe.Pointer(current)).Findex, (*CostInterval)(unsafe.Pointer(current)).Fcost)
  17716 		}
  17717 		current = next
  17718 	}
  17719 }
  17720 
  17721 // C documentation
  17722 //
  17723 //	// Given a current orphan interval and its previous interval, before
  17724 //	// it was orphaned (which can be NULL), set it at the right place in the list
  17725 //	// of intervals using the 'start' ordering and the previous interval as a hint.
  17726 func PositionOrphanInterval(tls *libc.TLS, manager uintptr, current uintptr, previous uintptr) {
  17727 	if previous == libc.UintptrFromInt32(0) {
  17728 		previous = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17729 	}
  17730 	for previous != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(current)).Fstart < (*CostInterval)(unsafe.Pointer(previous)).Fstart {
  17731 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fprevious
  17732 	}
  17733 	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 {
  17734 		previous = (*CostInterval)(unsafe.Pointer(previous)).Fnext
  17735 	}
  17736 	if previous != libc.UintptrFromInt32(0) {
  17737 		ConnectIntervals(tls, manager, current, (*CostInterval)(unsafe.Pointer(previous)).Fnext)
  17738 	} else {
  17739 		ConnectIntervals(tls, manager, current, (*CostManager)(unsafe.Pointer(manager)).Fhead)
  17740 	}
  17741 	ConnectIntervals(tls, manager, previous, current)
  17742 }
  17743 
  17744 // C documentation
  17745 //
  17746 //	// Insert an interval in the list contained in the manager by starting at
  17747 //	// 'interval_in' as a hint. The intervals are sorted by 'start' value.
  17748 func InsertInterval(tls *libc.TLS, manager uintptr, interval_in uintptr, cost int64_t, position int32, start int32, end int32) {
  17749 	var interval_new uintptr
  17750 	_ = interval_new
  17751 	if start >= end {
  17752 		return
  17753 	}
  17754 	if (*CostManager)(unsafe.Pointer(manager)).Fcount >= int32(COST_CACHE_INTERVAL_SIZE_MAX) {
  17755 		// Serialize the interval if we cannot store it.
  17756 		UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17757 		return
  17758 	}
  17759 	if (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals != libc.UintptrFromInt32(0) {
  17760 		interval_new = (*CostManager)(unsafe.Pointer(manager)).Ffree_intervals
  17761 		(*CostManager)(unsafe.Pointer(manager)).Ffree_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17762 	} else {
  17763 		if (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals != libc.UintptrFromInt32(0) {
  17764 			interval_new = (*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals
  17765 			(*CostManager)(unsafe.Pointer(manager)).Frecycled_intervals = (*CostInterval)(unsafe.Pointer(interval_new)).Fnext
  17766 		} else { // malloc for good
  17767 			interval_new = WebPSafeMalloc(tls, uint64(1), uint64(40))
  17768 			if interval_new == libc.UintptrFromInt32(0) {
  17769 				// Write down the interval if we cannot create it.
  17770 				UpdateCostPerInterval(tls, manager, start, end, position, cost)
  17771 				return
  17772 			}
  17773 		}
  17774 	}
  17775 	(*CostInterval)(unsafe.Pointer(interval_new)).Fcost = cost
  17776 	(*CostInterval)(unsafe.Pointer(interval_new)).Findex = position
  17777 	(*CostInterval)(unsafe.Pointer(interval_new)).Fstart = start
  17778 	(*CostInterval)(unsafe.Pointer(interval_new)).Fend = end
  17779 	PositionOrphanInterval(tls, manager, interval_new, interval_in)
  17780 	(*CostManager)(unsafe.Pointer(manager)).Fcount = (*CostManager)(unsafe.Pointer(manager)).Fcount + 1
  17781 }
  17782 
  17783 // C documentation
  17784 //
  17785 //	// Given a new cost interval defined by its start at position, its length value
  17786 //	// and distance_cost, add its contributions to the previous intervals and costs.
  17787 //	// If handling the interval or one of its subintervals becomes to heavy, its
  17788 //	// contribution is added to the costs right away.
  17789 func PushInterval(tls *libc.TLS, manager uintptr, distance_cost int64_t, position int32, len1 int32) {
  17790 	var cost, cost_tmp int64_t
  17791 	var cost_cache_intervals, interval, interval_next uintptr
  17792 	var end, end_original, j, k, kSkipDistance, start, start_new, v3 int32
  17793 	var i size_t
  17794 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = cost, cost_cache_intervals, cost_tmp, end, end_original, i, interval, interval_next, j, k, kSkipDistance, start, start_new, v3
  17795 	interval = (*CostManager)(unsafe.Pointer(manager)).Fhead
  17796 	cost_cache_intervals = (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals
  17797 	// If the interval is small enough, no need to deal with the heavy
  17798 	// interval logic, just serialize it right away. This constant is empirical.
  17799 	kSkipDistance = int32(10)
  17800 	if len1 < kSkipDistance {
  17801 		j = position
  17802 		for {
  17803 			if !(j < position+len1) {
  17804 				break
  17805 			}
  17806 			k = j - position
  17807 			cost_tmp = distance_cost + **(**int64_t)(__ccgo_up(manager + 32 + uintptr(k)*8))
  17808 			if **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) > cost_tmp {
  17809 				**(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fcosts + uintptr(j)*8)) = cost_tmp
  17810 				**(**uint16_t)(__ccgo_up((*CostManager)(unsafe.Pointer(manager)).Fdist_array + uintptr(j)*2)) = libc.Uint16FromInt32(k + int32(1))
  17811 			}
  17812 			goto _1
  17813 		_1:
  17814 			;
  17815 			j = j + 1
  17816 		}
  17817 		return
  17818 	}
  17819 	i = uint64(0)
  17820 	for {
  17821 		if !(i < (*CostManager)(unsafe.Pointer(manager)).Fcache_intervals_size && (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart < len1) {
  17822 			break
  17823 		}
  17824 		// Define the intersection of the ith interval with the new one.
  17825 		start = position + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fstart
  17826 		if (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend > len1 {
  17827 			v3 = len1
  17828 		} else {
  17829 			v3 = (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fend
  17830 		}
  17831 		end = position + v3
  17832 		cost = distance_cost + (**(**CostCacheInterval)(__ccgo_up(cost_cache_intervals + uintptr(i)*16))).Fcost
  17833 		for {
  17834 			if !(interval != libc.UintptrFromInt32(0) && (*CostInterval)(unsafe.Pointer(interval)).Fstart < end) {
  17835 				break
  17836 			}
  17837 			interval_next = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17838 			// Make sure we have some overlap
  17839 			if start >= (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17840 				goto _4
  17841 			}
  17842 			if cost >= (*CostInterval)(unsafe.Pointer(interval)).Fcost {
  17843 				// When intervals are represented, the lower, the better.
  17844 				// [**********************************************************[
  17845 				// start                                                    end
  17846 				//                   [----------------------------------[
  17847 				//                   interval->start        interval->end
  17848 				// If we are worse than what we already have, add whatever we have so
  17849 				// far up to interval.
  17850 				start_new = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17851 				InsertInterval(tls, manager, interval, cost, position, start, (*CostInterval)(unsafe.Pointer(interval)).Fstart)
  17852 				start = start_new
  17853 				if start >= end {
  17854 					break
  17855 				}
  17856 				goto _4
  17857 			}
  17858 			if start <= (*CostInterval)(unsafe.Pointer(interval)).Fstart {
  17859 				if (*CostInterval)(unsafe.Pointer(interval)).Fend <= end {
  17860 					//                   [----------------------------------[
  17861 					//                   interval->start        interval->end
  17862 					// [**************************************************************[
  17863 					// start                                                        end
  17864 					// We can safely remove the old interval as it is fully included.
  17865 					PopInterval(tls, manager, interval)
  17866 				} else {
  17867 					//              [------------------------------------[
  17868 					//              interval->start          interval->end
  17869 					// [*****************************[
  17870 					// start                       end
  17871 					(*CostInterval)(unsafe.Pointer(interval)).Fstart = end
  17872 					break
  17873 				}
  17874 			} else {
  17875 				if end < (*CostInterval)(unsafe.Pointer(interval)).Fend {
  17876 					// [--------------------------------------------------------------[
  17877 					// interval->start                                    interval->end
  17878 					//                     [*****************************[
  17879 					//                     start                       end
  17880 					// We have to split the old interval as it fully contains the new one.
  17881 					end_original = (*CostInterval)(unsafe.Pointer(interval)).Fend
  17882 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17883 					InsertInterval(tls, manager, interval, (*CostInterval)(unsafe.Pointer(interval)).Fcost, (*CostInterval)(unsafe.Pointer(interval)).Findex, end, end_original)
  17884 					interval = (*CostInterval)(unsafe.Pointer(interval)).Fnext
  17885 					break
  17886 				} else {
  17887 					// [------------------------------------[
  17888 					// interval->start          interval->end
  17889 					//                     [*****************************[
  17890 					//                     start                       end
  17891 					(*CostInterval)(unsafe.Pointer(interval)).Fend = start
  17892 				}
  17893 			}
  17894 			goto _4
  17895 		_4:
  17896 			;
  17897 			interval = interval_next
  17898 		}
  17899 		// Insert the remaining interval from start to end.
  17900 		InsertInterval(tls, manager, interval, cost, position, start, end)
  17901 		goto _2
  17902 	_2:
  17903 		;
  17904 		i = i + 1
  17905 	}
  17906 }
  17907 
  17908 func BackwardReferencesHashChainDistanceOnly(tls *libc.TLS, xsize int32, ysize int32, argb uintptr, cache_bits int32, hash_chain uintptr, refs uintptr, dist_array uintptr) (r int32) {
  17909 	bp := tls.Alloc(32)
  17910 	defer tls.Free(32)
  17911 	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
  17912 	var cost_manager, cost_model, v6 uintptr
  17913 	var cost_model_size, literal_array_size size_t
  17914 	var offset_cost, prev_cost int64_t
  17915 	var _ /* hashers at bp+0 */ VP8LColorCache
  17916 	var _ /* len at bp+20 */ int32
  17917 	var _ /* len_j at bp+28 */ int32
  17918 	var _ /* offset at bp+16 */ int32
  17919 	var _ /* offset_j at bp+24 */ int32
  17920 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  17921 	ok = 0
  17922 	cc_init = 0
  17923 	pix_count = xsize * ysize
  17924 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  17925 	v1 = cache_bits
  17926 	if v1 > 0 {
  17927 		v4 = int32(1) << v1
  17928 	} else {
  17929 		v4 = 0
  17930 	}
  17931 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  17932 	goto _3
  17933 _3:
  17934 	literal_array_size = uint64(4) * libc.Uint64FromInt32(v2)
  17935 	cost_model_size = uint64(3240) + literal_array_size
  17936 	cost_model = WebPSafeCalloc(tls, uint64(1), cost_model_size)
  17937 	cost_manager = WebPSafeCalloc(tls, uint64(1), uint64(33224))
  17938 	offset_prev = -int32(1)
  17939 	len_prev = -int32(1)
  17940 	offset_cost = int64(-int32(1))
  17941 	first_offset_is_constant = -int32(1) // initialized with 'impossible' value
  17942 	reach = 0
  17943 	if cost_model == libc.UintptrFromInt32(0) || cost_manager == libc.UintptrFromInt32(0) {
  17944 		goto Error
  17945 	}
  17946 	(*CostModel)(unsafe.Pointer(cost_model)).Fliteral = cost_model + libc.UintptrFromInt32(1)*3240
  17947 	if use_color_cache != 0 {
  17948 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  17949 		if !(cc_init != 0) {
  17950 			goto Error
  17951 		}
  17952 	}
  17953 	if !(CostModelBuild(tls, cost_model, xsize, cache_bits, refs) != 0) {
  17954 		goto Error
  17955 	}
  17956 	if !(CostManagerInit(tls, cost_manager, dist_array, pix_count, cost_model) != 0) {
  17957 		goto Error
  17958 	}
  17959 	// We loop one pixel at a time, but store all currently best points to
  17960 	// non-processed locations from this point.
  17961 	**(**uint16_t)(__ccgo_up(dist_array)) = uint16(0)
  17962 	// Add first pixel as literal.
  17963 	AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, 0, use_color_cache, 0, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17964 	i = int32(1)
  17965 	for {
  17966 		if !(i < pix_count) {
  17967 			break
  17968 		}
  17969 		prev_cost = **(**int64_t)(__ccgo_up((*CostManager)(unsafe.Pointer(cost_manager)).Fcosts + uintptr(i-int32(1))*8))
  17970 		v6 = hash_chain
  17971 		v1 = i
  17972 		v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  17973 		goto _9
  17974 	_9:
  17975 		**(**int32)(__ccgo_up(bp + 16)) = v2
  17976 		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)))
  17977 		goto _11
  17978 	_11:
  17979 		**(**int32)(__ccgo_up(bp + 20)) = v4
  17980 		// Try adding the pixel as a literal.
  17981 		AddSingleLiteralWithCostModel(tls, argb, bp, cost_model, i, use_color_cache, prev_cost, (*CostManager)(unsafe.Pointer(cost_manager)).Fcosts, dist_array)
  17982 		// If we are dealing with a non-literal.
  17983 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(2) {
  17984 			if **(**int32)(__ccgo_up(bp + 16)) != offset_prev {
  17985 				code = VP8LDistanceToPlaneCode(tls, xsize, **(**int32)(__ccgo_up(bp + 16)))
  17986 				offset_cost = GetDistanceCost(tls, cost_model, libc.Uint32FromInt32(code))
  17987 				first_offset_is_constant = int32(1)
  17988 				PushInterval(tls, cost_manager, prev_cost+offset_cost, i, **(**int32)(__ccgo_up(bp + 20)))
  17989 			} else {
  17990 				// Instead of considering all contributions from a pixel i by calling:
  17991 				//         PushInterval(cost_manager, prev_cost + offset_cost, i, len);
  17992 				// we optimize these contributions in case offset_cost stays the same
  17993 				// for consecutive pixels. This describes a set of pixels similar to a
  17994 				// previous set (e.g. constant color regions).
  17995 				if first_offset_is_constant != 0 {
  17996 					reach = i - int32(1) + len_prev - int32(1)
  17997 					first_offset_is_constant = 0
  17998 				}
  17999 				if i+**(**int32)(__ccgo_up(bp + 20))-int32(1) > reach {
  18000 					**(**int32)(__ccgo_up(bp + 28)) = 0
  18001 					// Figure out the last consecutive pixel within [i, reach + 1] with
  18002 					// the same offset.
  18003 					j = i
  18004 					for {
  18005 						if !(j <= reach) {
  18006 							break
  18007 						}
  18008 						v6 = hash_chain
  18009 						v1 = j + int32(1)
  18010 						v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  18011 						goto _16
  18012 					_16:
  18013 						**(**int32)(__ccgo_up(bp + 24)) = v2
  18014 						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)))
  18015 						goto _18
  18016 					_18:
  18017 						**(**int32)(__ccgo_up(bp + 28)) = v4
  18018 						if **(**int32)(__ccgo_up(bp + 24)) != **(**int32)(__ccgo_up(bp + 16)) {
  18019 							v6 = hash_chain
  18020 							v1 = j
  18021 							v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v6)).Foffset_length + uintptr(v1)*4)) >> int32(MAX_LENGTH_BITS))
  18022 							goto _22
  18023 						_22:
  18024 							**(**int32)(__ccgo_up(bp + 24)) = v2
  18025 							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)))
  18026 							goto _24
  18027 						_24:
  18028 							**(**int32)(__ccgo_up(bp + 28)) = v4
  18029 							break
  18030 						}
  18031 						goto _12
  18032 					_12:
  18033 						;
  18034 						j = j + 1
  18035 					}
  18036 					// Update the cost at j - 1 and j.
  18037 					UpdateCostAtIndex(tls, cost_manager, j-int32(1), 0)
  18038 					UpdateCostAtIndex(tls, cost_manager, j, 0)
  18039 					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)))
  18040 					reach = j + **(**int32)(__ccgo_up(bp + 28)) - int32(1)
  18041 				}
  18042 			}
  18043 		}
  18044 		UpdateCostAtIndex(tls, cost_manager, i, int32(1))
  18045 		offset_prev = **(**int32)(__ccgo_up(bp + 16))
  18046 		len_prev = **(**int32)(__ccgo_up(bp + 20))
  18047 		goto _5
  18048 	_5:
  18049 		;
  18050 		i = i + 1
  18051 	}
  18052 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18053 	goto Error
  18054 Error:
  18055 	;
  18056 	if cc_init != 0 {
  18057 		VP8LColorCacheClear(tls, bp)
  18058 	}
  18059 	CostManagerClear(tls, cost_manager)
  18060 	WebPSafeFree(tls, cost_model)
  18061 	WebPSafeFree(tls, cost_manager)
  18062 	return ok
  18063 }
  18064 
  18065 // C documentation
  18066 //
  18067 //	// We pack the path at the end of *dist_array and return
  18068 //	// a pointer to this part of the array. Example:
  18069 //	// dist_array = [1x2xx3x2] => packed [1x2x1232], chosen_path = [1232]
  18070 func TraceBackwards(tls *libc.TLS, dist_array uintptr, dist_array_size int32, chosen_path uintptr, chosen_path_size uintptr) {
  18071 	var cur, path uintptr
  18072 	var k int32
  18073 	_, _, _ = cur, k, path
  18074 	path = dist_array + uintptr(dist_array_size)*2
  18075 	cur = dist_array + uintptr(dist_array_size)*2 - uintptr(1)*2
  18076 	for cur >= dist_array {
  18077 		k = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(cur)))
  18078 		path -= 2
  18079 		**(**uint16_t)(__ccgo_up(path)) = libc.Uint16FromInt32(k)
  18080 		cur = cur - uintptr(k)*2
  18081 	}
  18082 	**(**uintptr)(__ccgo_up(chosen_path)) = path
  18083 	**(**int32)(__ccgo_up(chosen_path_size)) = int32((int64(dist_array+uintptr(dist_array_size)*2) - int64(path)) / 2)
  18084 }
  18085 
  18086 func BackwardReferencesHashChainFollowChosenPath(tls *libc.TLS, argb4 uintptr, cache_bits int32, chosen_path uintptr, chosen_path_size int32, hash_chain uintptr, refs uintptr) (r int32) {
  18087 	bp := tls.Alloc(16)
  18088 	defer tls.Free(16)
  18089 	var cc_init, i, idx1, ix, k, key, key1, len1, offset, ok, use_color_cache, v11, v14, v2, v9 int32
  18090 	var retval, retval1, retval2, v, v4 PixOrCopy
  18091 	var v7 uintptr
  18092 	var v8 uint32_t
  18093 	var _ /* hashers at bp+0 */ VP8LColorCache
  18094 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  18095 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18096 	i = 0
  18097 	ok = 0
  18098 	cc_init = 0
  18099 	if use_color_cache != 0 {
  18100 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  18101 		if !(cc_init != 0) {
  18102 			goto Error
  18103 		}
  18104 	}
  18105 	VP8LClearBackwardRefs(tls, refs)
  18106 	ix = 0
  18107 	for {
  18108 		if !(ix < chosen_path_size) {
  18109 			break
  18110 		}
  18111 		len1 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(chosen_path + uintptr(ix)*2)))
  18112 		if len1 != int32(1) {
  18113 			v2 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  18114 			goto _3
  18115 		_3:
  18116 			offset = v2
  18117 			retval.Fmode = uint8(kCopy)
  18118 			retval.Fargb_or_distance = libc.Uint32FromInt32(offset)
  18119 			retval.Flen1 = libc.Uint16FromInt32(len1)
  18120 			v4 = retval
  18121 			goto _5
  18122 		_5:
  18123 			VP8LBackwardRefsCursorAdd(tls, refs, v4)
  18124 			if use_color_cache != 0 {
  18125 				k = 0
  18126 				for {
  18127 					if !(k < len1) {
  18128 						break
  18129 					}
  18130 					v7 = bp
  18131 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i+k)*4))
  18132 					v2 = libc.Int32FromUint32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18133 					goto _10
  18134 				_10:
  18135 					key = v2
  18136 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18137 					goto _6
  18138 				_6:
  18139 					;
  18140 					k = k + 1
  18141 				}
  18142 			}
  18143 			i = i + len1
  18144 		} else {
  18145 			if use_color_cache != 0 {
  18146 				v7 = bp
  18147 				v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18148 				v9 = libc.Int32FromUint32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18149 				goto _15
  18150 			_15:
  18151 				key1 = v9
  18152 				if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key1)*4)) == v8 {
  18153 					v14 = key1
  18154 				} else {
  18155 					v14 = -int32(1)
  18156 				}
  18157 				v11 = v14
  18158 				goto _17
  18159 			_17:
  18160 				v2 = v11
  18161 			} else {
  18162 				v2 = -int32(1)
  18163 			}
  18164 			idx1 = v2
  18165 			if idx1 >= 0 {
  18166 				// use_color_cache is true and hashers contains argb[i]
  18167 				// push pixel as a color cache index
  18168 				retval1.Fmode = uint8(kCacheIdx)
  18169 				retval1.Fargb_or_distance = libc.Uint32FromInt32(idx1)
  18170 				retval1.Flen1 = uint16(1)
  18171 				v4 = retval1
  18172 				goto _20
  18173 			_20:
  18174 				v = v4
  18175 			} else {
  18176 				if use_color_cache != 0 {
  18177 					v7 = bp
  18178 					v8 = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18179 					v2 = libc.Int32FromUint32(v8 * kHashMul10 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  18180 					goto _24
  18181 				_24:
  18182 					key = v2
  18183 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  18184 				}
  18185 				retval2.Fmode = uint8(kLiteral)
  18186 				retval2.Fargb_or_distance = **(**uint32_t)(__ccgo_up(argb4 + uintptr(i)*4))
  18187 				retval2.Flen1 = uint16(1)
  18188 				v4 = retval2
  18189 				goto _26
  18190 			_26:
  18191 				v = v4
  18192 			}
  18193 			VP8LBackwardRefsCursorAdd(tls, refs, v)
  18194 			i = i + 1
  18195 		}
  18196 		goto _1
  18197 	_1:
  18198 		;
  18199 		ix = ix + 1
  18200 	}
  18201 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  18202 	goto Error
  18203 Error:
  18204 	;
  18205 	if cc_init != 0 {
  18206 		VP8LColorCacheClear(tls, bp)
  18207 	}
  18208 	return ok
  18209 }
  18210 
  18211 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) {
  18212 	bp := tls.Alloc(16)
  18213 	defer tls.Free(16)
  18214 	var dist_array uintptr
  18215 	var dist_array_size, ok int32
  18216 	var _ /* chosen_path at bp+0 */ uintptr
  18217 	var _ /* chosen_path_size at bp+8 */ int32
  18218 	_, _, _ = dist_array, dist_array_size, ok
  18219 	ok = 0
  18220 	dist_array_size = xsize * ysize
  18221 	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
  18222 	**(**int32)(__ccgo_up(bp + 8)) = 0
  18223 	dist_array = WebPSafeMalloc(tls, libc.Uint64FromInt32(dist_array_size), uint64(2))
  18224 	if dist_array == libc.UintptrFromInt32(0) {
  18225 		goto Error
  18226 	}
  18227 	if !(BackwardReferencesHashChainDistanceOnly(tls, xsize, ysize, argb, cache_bits, hash_chain, refs_src, dist_array) != 0) {
  18228 		goto Error
  18229 	}
  18230 	TraceBackwards(tls, dist_array, dist_array_size, bp, bp+8)
  18231 	if !(BackwardReferencesHashChainFollowChosenPath(tls, argb, cache_bits, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), hash_chain, refs_dst) != 0) {
  18232 		goto Error
  18233 	}
  18234 	ok = int32(1)
  18235 	goto Error
  18236 Error:
  18237 	;
  18238 	WebPSafeFree(tls, dist_array)
  18239 	return ok
  18240 }
  18241 
  18242 const MIN_BLOCK_SIZE = 256
  18243 const MIN_LENGTH = 4
  18244 const WINDOW_OFFSETS_SIZE_MAX = 32
  18245 
  18246 type PixOrCopyBlock = struct {
  18247 	Fnext  uintptr
  18248 	Fstart uintptr
  18249 	Fsize  int32
  18250 }
  18251 
  18252 var kHashMul11 = uint32(0x1e35a7bd)
  18253 
  18254 //------------------------------------------------------------------------------
  18255 
  18256 // Copyright 2012 Google Inc. All Rights Reserved.
  18257 //
  18258 // Use of this source code is governed by a BSD-style license
  18259 // that can be found in the COPYING file in the root of the source
  18260 // tree. An additional intellectual property rights grant can be found
  18261 // in the file PATENTS. All contributing project authors may
  18262 // be found in the AUTHORS file in the root of the source tree.
  18263 // -----------------------------------------------------------------------------
  18264 //
  18265 // Misc. common utility functions
  18266 //
  18267 // Authors: Skal (pascal.massimino@gmail.com)
  18268 //          Urvang (urvang@google.com)
  18269 
  18270 // Copyright 2011 Google Inc. All Rights Reserved.
  18271 //
  18272 // Use of this source code is governed by a BSD-style license
  18273 // that can be found in the COPYING file in the root of the source
  18274 // tree. An additional intellectual property rights grant can be found
  18275 // in the file PATENTS. All contributing project authors may
  18276 // be found in the AUTHORS file in the root of the source tree.
  18277 // -----------------------------------------------------------------------------
  18278 //
  18279 //   WebP encoder: main interface
  18280 //
  18281 // Author: Skal (pascal.massimino@gmail.com)
  18282 
  18283 // Copyright 2012 Google Inc. All Rights Reserved.
  18284 //
  18285 // Use of this source code is governed by a BSD-style license
  18286 // that can be found in the COPYING file in the root of the source
  18287 // tree. An additional intellectual property rights grant can be found
  18288 // in the file PATENTS. All contributing project authors may
  18289 // be found in the AUTHORS file in the root of the source tree.
  18290 // -----------------------------------------------------------------------------
  18291 //
  18292 //  Internal header for constants related to WebP file format.
  18293 //
  18294 // Author: Urvang (urvang@google.com)
  18295 
  18296 // Copyright 2010 Google Inc. All Rights Reserved.
  18297 //
  18298 // Use of this source code is governed by a BSD-style license
  18299 // that can be found in the COPYING file in the root of the source
  18300 // tree. An additional intellectual property rights grant can be found
  18301 // in the file PATENTS. All contributing project authors may
  18302 // be found in the AUTHORS file in the root of the source tree.
  18303 // -----------------------------------------------------------------------------
  18304 //
  18305 //  Common types + memory wrappers
  18306 //
  18307 // Author: Skal (pascal.massimino@gmail.com)
  18308 
  18309 // 1M window (4M bytes) minus 120 special codes for short distances.
  18310 
  18311 // Minimum number of pixels for which it is cheaper to encode a
  18312 // distance + length instead of each pixel as a literal.
  18313 
  18314 // -----------------------------------------------------------------------------
  18315 
  18316 var plane_to_code_lut = [128]uint8_t{
  18317 	0:   uint8(96),
  18318 	1:   uint8(73),
  18319 	2:   uint8(55),
  18320 	3:   uint8(39),
  18321 	4:   uint8(23),
  18322 	5:   uint8(13),
  18323 	6:   uint8(5),
  18324 	7:   uint8(1),
  18325 	8:   uint8(255),
  18326 	9:   uint8(255),
  18327 	10:  uint8(255),
  18328 	11:  uint8(255),
  18329 	12:  uint8(255),
  18330 	13:  uint8(255),
  18331 	14:  uint8(255),
  18332 	15:  uint8(255),
  18333 	16:  uint8(101),
  18334 	17:  uint8(78),
  18335 	18:  uint8(58),
  18336 	19:  uint8(42),
  18337 	20:  uint8(26),
  18338 	21:  uint8(16),
  18339 	22:  uint8(8),
  18340 	23:  uint8(2),
  18341 	25:  uint8(3),
  18342 	26:  uint8(9),
  18343 	27:  uint8(17),
  18344 	28:  uint8(27),
  18345 	29:  uint8(43),
  18346 	30:  uint8(59),
  18347 	31:  uint8(79),
  18348 	32:  uint8(102),
  18349 	33:  uint8(86),
  18350 	34:  uint8(62),
  18351 	35:  uint8(46),
  18352 	36:  uint8(32),
  18353 	37:  uint8(20),
  18354 	38:  uint8(10),
  18355 	39:  uint8(6),
  18356 	40:  uint8(4),
  18357 	41:  uint8(7),
  18358 	42:  uint8(11),
  18359 	43:  uint8(21),
  18360 	44:  uint8(33),
  18361 	45:  uint8(47),
  18362 	46:  uint8(63),
  18363 	47:  uint8(87),
  18364 	48:  uint8(105),
  18365 	49:  uint8(90),
  18366 	50:  uint8(70),
  18367 	51:  uint8(52),
  18368 	52:  uint8(37),
  18369 	53:  uint8(28),
  18370 	54:  uint8(18),
  18371 	55:  uint8(14),
  18372 	56:  uint8(12),
  18373 	57:  uint8(15),
  18374 	58:  uint8(19),
  18375 	59:  uint8(29),
  18376 	60:  uint8(38),
  18377 	61:  uint8(53),
  18378 	62:  uint8(71),
  18379 	63:  uint8(91),
  18380 	64:  uint8(110),
  18381 	65:  uint8(99),
  18382 	66:  uint8(82),
  18383 	67:  uint8(66),
  18384 	68:  uint8(48),
  18385 	69:  uint8(35),
  18386 	70:  uint8(30),
  18387 	71:  uint8(24),
  18388 	72:  uint8(22),
  18389 	73:  uint8(25),
  18390 	74:  uint8(31),
  18391 	75:  uint8(36),
  18392 	76:  uint8(49),
  18393 	77:  uint8(67),
  18394 	78:  uint8(83),
  18395 	79:  uint8(100),
  18396 	80:  uint8(115),
  18397 	81:  uint8(108),
  18398 	82:  uint8(94),
  18399 	83:  uint8(76),
  18400 	84:  uint8(64),
  18401 	85:  uint8(50),
  18402 	86:  uint8(44),
  18403 	87:  uint8(40),
  18404 	88:  uint8(34),
  18405 	89:  uint8(41),
  18406 	90:  uint8(45),
  18407 	91:  uint8(51),
  18408 	92:  uint8(65),
  18409 	93:  uint8(77),
  18410 	94:  uint8(95),
  18411 	95:  uint8(109),
  18412 	96:  uint8(118),
  18413 	97:  uint8(113),
  18414 	98:  uint8(103),
  18415 	99:  uint8(92),
  18416 	100: uint8(80),
  18417 	101: uint8(68),
  18418 	102: uint8(60),
  18419 	103: uint8(56),
  18420 	104: uint8(54),
  18421 	105: uint8(57),
  18422 	106: uint8(61),
  18423 	107: uint8(69),
  18424 	108: uint8(81),
  18425 	109: uint8(93),
  18426 	110: uint8(104),
  18427 	111: uint8(114),
  18428 	112: uint8(119),
  18429 	113: uint8(116),
  18430 	114: uint8(111),
  18431 	115: uint8(106),
  18432 	116: uint8(97),
  18433 	117: uint8(88),
  18434 	118: uint8(84),
  18435 	119: uint8(74),
  18436 	120: uint8(72),
  18437 	121: uint8(75),
  18438 	122: uint8(85),
  18439 	123: uint8(89),
  18440 	124: uint8(98),
  18441 	125: uint8(107),
  18442 	126: uint8(112),
  18443 	127: uint8(117),
  18444 }
  18445 
  18446 func VP8LDistanceToPlaneCode(tls *libc.TLS, xsize int32, dist int32) (r int32) {
  18447 	var xoffset, yoffset int32
  18448 	_, _ = xoffset, yoffset
  18449 	yoffset = dist / xsize
  18450 	xoffset = dist - yoffset*xsize
  18451 	if xoffset <= int32(8) && yoffset < int32(8) {
  18452 		return libc.Int32FromUint8(plane_to_code_lut[yoffset*int32(16)+int32(8)-xoffset]) + int32(1)
  18453 	} else {
  18454 		if xoffset > xsize-int32(8) && yoffset < int32(7) {
  18455 			return libc.Int32FromUint8(plane_to_code_lut[(yoffset+int32(1))*int32(16)+int32(8)+(xsize-xoffset)]) + int32(1)
  18456 		}
  18457 	}
  18458 	return dist + int32(120)
  18459 }
  18460 
  18461 // C documentation
  18462 //
  18463 //	// Returns the exact index where array1 and array2 are different. For an index
  18464 //	// inferior or equal to best_len_match, the return value just has to be strictly
  18465 //	// inferior to best_len_match. The current behavior is to return 0 if this index
  18466 //	// is best_len_match, and the index itself otherwise.
  18467 //	// If no two elements are the same, it returns max_limit.
  18468 func FindMatchLength(tls *libc.TLS, array1 uintptr, array2 uintptr, best_len_match int32, max_limit int32) (r int32) {
  18469 	// Before 'expensive' linear match, check if the two arrays match at the
  18470 	// current best length index.
  18471 	if **(**uint32_t)(__ccgo_up(array1 + uintptr(best_len_match)*4)) != **(**uint32_t)(__ccgo_up(array2 + uintptr(best_len_match)*4)) {
  18472 		return 0
  18473 	}
  18474 	return (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, array1, array2, max_limit)
  18475 }
  18476 
  18477 func VP8LClearBackwardRefs(tls *libc.TLS, refs uintptr) {
  18478 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail != libc.UintptrFromInt32(0) {
  18479 		**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks // recycle all blocks at once
  18480 	}
  18481 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18482 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18483 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = libc.UintptrFromInt32(0)
  18484 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs = libc.UintptrFromInt32(0)
  18485 }
  18486 
  18487 func VP8LBackwardRefsClear(tls *libc.TLS, refs uintptr) {
  18488 	var next uintptr
  18489 	_ = next
  18490 	VP8LClearBackwardRefs(tls, refs)
  18491 	for (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks != libc.UintptrFromInt32(0) {
  18492 		next = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)).Fnext
  18493 		WebPSafeFree(tls, (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks)
  18494 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = next
  18495 	}
  18496 }
  18497 
  18498 // C documentation
  18499 //
  18500 //	// Swaps the content of two VP8LBackwardRefs.
  18501 func BackwardRefsSwap(tls *libc.TLS, refs1 uintptr, refs2 uintptr) {
  18502 	var point_to_refs1, point_to_refs2 int32
  18503 	var tmp VP8LBackwardRefs
  18504 	_, _, _ = point_to_refs1, point_to_refs2, tmp
  18505 	point_to_refs1 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail == refs1+8)
  18506 	point_to_refs2 = libc.BoolInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail != libc.UintptrFromInt32(0) && (*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail == refs2+8)
  18507 	tmp = **(**VP8LBackwardRefs)(__ccgo_up(refs1))
  18508 	**(**VP8LBackwardRefs)(__ccgo_up(refs1)) = **(**VP8LBackwardRefs)(__ccgo_up(refs2))
  18509 	**(**VP8LBackwardRefs)(__ccgo_up(refs2)) = tmp
  18510 	if point_to_refs2 != 0 {
  18511 		(*VP8LBackwardRefs)(unsafe.Pointer(refs1)).Ftail = refs1 + 8
  18512 	}
  18513 	if point_to_refs1 != 0 {
  18514 		(*VP8LBackwardRefs)(unsafe.Pointer(refs2)).Ftail = refs2 + 8
  18515 	}
  18516 }
  18517 
  18518 func VP8LBackwardRefsInit(tls *libc.TLS, refs uintptr, block_size int32) {
  18519 	var v1 int32
  18520 	_ = v1
  18521 	libc.Xmemset(tls, refs, 0, uint64(40))
  18522 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = refs + 8
  18523 	if block_size < int32(MIN_BLOCK_SIZE) {
  18524 		v1 = int32(MIN_BLOCK_SIZE)
  18525 	} else {
  18526 		v1 = block_size
  18527 	}
  18528 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size = v1
  18529 }
  18530 
  18531 func VP8LRefsCursorInit(tls *libc.TLS, refs uintptr) (r VP8LRefsCursor) {
  18532 	var c VP8LRefsCursor
  18533 	_ = c
  18534 	c.Fcur_block = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs
  18535 	if (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Frefs != libc.UintptrFromInt32(0) {
  18536 		c.Fcur_pos = (*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fstart
  18537 		c.Flast_pos = c.Fcur_pos + uintptr((*PixOrCopyBlock)(unsafe.Pointer(c.Fcur_block)).Fsize)*8
  18538 	} else {
  18539 		c.Fcur_pos = libc.UintptrFromInt32(0)
  18540 		c.Flast_pos = libc.UintptrFromInt32(0)
  18541 	}
  18542 	return c
  18543 }
  18544 
  18545 func VP8LRefsCursorNextBlock(tls *libc.TLS, c uintptr) {
  18546 	var b, v1 uintptr
  18547 	_, _ = b, v1
  18548 	b = (*PixOrCopyBlock)(unsafe.Pointer((*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block)).Fnext
  18549 	if b == libc.UintptrFromInt32(0) {
  18550 		v1 = libc.UintptrFromInt32(0)
  18551 	} else {
  18552 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart
  18553 	}
  18554 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_pos = v1
  18555 	if b == libc.UintptrFromInt32(0) {
  18556 		v1 = libc.UintptrFromInt32(0)
  18557 	} else {
  18558 		v1 = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr((*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize)*8
  18559 	}
  18560 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Flast_pos = v1
  18561 	(*VP8LRefsCursor)(unsafe.Pointer(c)).Fcur_block = b
  18562 }
  18563 
  18564 // C documentation
  18565 //
  18566 //	// Create a new block, either from the free list or allocated
  18567 func BackwardRefsNewBlock(tls *libc.TLS, refs uintptr) (r uintptr) {
  18568 	var b uintptr
  18569 	var total_size size_t
  18570 	_, _ = b, total_size
  18571 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks
  18572 	if b == libc.UintptrFromInt32(0) { // allocate new memory chunk
  18573 		total_size = uint64(24) + libc.Uint64FromInt32((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size)*uint64(8)
  18574 		b = WebPSafeMalloc(tls, uint64(1), total_size)
  18575 		if b == libc.UintptrFromInt32(0) {
  18576 			**(**int32)(__ccgo_up(refs + 4)) |= int32(1)
  18577 			return libc.UintptrFromInt32(0)
  18578 		}
  18579 		(*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart = b + libc.UintptrFromInt64(24) // not always aligned
  18580 	} else { // recycle from free-list
  18581 		(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ffree_blocks = (*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext
  18582 	}
  18583 	**(**uintptr)(__ccgo_up((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail)) = b
  18584 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ftail = b
  18585 	(*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block = b
  18586 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fnext = libc.UintptrFromInt32(0)
  18587 	(*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize = 0
  18588 	return b
  18589 }
  18590 
  18591 // C documentation
  18592 //
  18593 //	// Return 1 on success, 0 on error.
  18594 func BackwardRefsClone(tls *libc.TLS, from uintptr, to uintptr) (r int32) {
  18595 	var block_from, block_to uintptr
  18596 	_, _ = block_from, block_to
  18597 	block_from = (*VP8LBackwardRefs)(unsafe.Pointer(from)).Frefs
  18598 	VP8LClearBackwardRefs(tls, to)
  18599 	for block_from != libc.UintptrFromInt32(0) {
  18600 		block_to = BackwardRefsNewBlock(tls, to)
  18601 		if block_to == libc.UintptrFromInt32(0) {
  18602 			return 0
  18603 		}
  18604 		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))
  18605 		(*PixOrCopyBlock)(unsafe.Pointer(block_to)).Fsize = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fsize
  18606 		block_from = (*PixOrCopyBlock)(unsafe.Pointer(block_from)).Fnext
  18607 	}
  18608 	return int32(1)
  18609 }
  18610 
  18611 func VP8LBackwardRefsCursorAdd(tls *libc.TLS, refs uintptr, v PixOrCopy) {
  18612 	var b, v2 uintptr
  18613 	var v1 int32
  18614 	_, _, _ = b, v1, v2
  18615 	b = (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Flast_block
  18616 	if b == libc.UintptrFromInt32(0) || (*PixOrCopyBlock)(unsafe.Pointer(b)).Fsize == (*VP8LBackwardRefs)(unsafe.Pointer(refs)).Fblock_size {
  18617 		b = BackwardRefsNewBlock(tls, refs)
  18618 		if b == libc.UintptrFromInt32(0) {
  18619 			return
  18620 		} // refs->error is set
  18621 	}
  18622 	v2 = b + 16
  18623 	v1 = *(*int32)(unsafe.Pointer(v2))
  18624 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  18625 	**(**PixOrCopy)(__ccgo_up((*PixOrCopyBlock)(unsafe.Pointer(b)).Fstart + uintptr(v1)*8)) = v
  18626 }
  18627 
  18628 // -----------------------------------------------------------------------------
  18629 // Hash chains
  18630 
  18631 func VP8LHashChainInit(tls *libc.TLS, p uintptr, size int32) (r int32) {
  18632 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = WebPSafeMalloc(tls, libc.Uint64FromInt32(size), uint64(4))
  18633 	if (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length == libc.UintptrFromInt32(0) {
  18634 		return 0
  18635 	}
  18636 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = size
  18637 	return int32(1)
  18638 }
  18639 
  18640 func VP8LHashChainClear(tls *libc.TLS, p uintptr) {
  18641 	WebPSafeFree(tls, (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)
  18642 	(*VP8LHashChain)(unsafe.Pointer(p)).Fsize = 0
  18643 	(*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length = libc.UintptrFromInt32(0)
  18644 }
  18645 
  18646 // -----------------------------------------------------------------------------
  18647 
  18648 var kHashMultiplierHi = uint32(0xc6a4a793)
  18649 var kHashMultiplierLo = uint32(0x5bd1e996)
  18650 
  18651 func GetPixPairHash64(tls *libc.TLS, argb uintptr) (r uint32_t) {
  18652 	var key uint32_t
  18653 	_ = key
  18654 	key = **(**uint32_t)(__ccgo_up(argb + 1*4)) * kHashMultiplierHi
  18655 	key = key + **(**uint32_t)(__ccgo_up(argb))*kHashMultiplierLo
  18656 	key = key >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(HASH_BITS))
  18657 	return key
  18658 }
  18659 
  18660 // C documentation
  18661 //
  18662 //	// Returns the maximum number of hash chain lookups to do for a
  18663 //	// given compression quality. Return value in range [8, 86].
  18664 func GetMaxItersForQuality(tls *libc.TLS, quality int32) (r int32) {
  18665 	return int32(8) + quality*quality/int32(128)
  18666 }
  18667 
  18668 func GetWindowSizeForHashChain(tls *libc.TLS, quality int32, xsize int32) (r int32) {
  18669 	var max_window_size, v1, v2, v3 int32
  18670 	_, _, _, _ = max_window_size, v1, v2, v3
  18671 	if quality > int32(75) {
  18672 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18673 	} else {
  18674 		if quality > int32(50) {
  18675 			v2 = xsize << int32(8)
  18676 		} else {
  18677 			if quality > int32(25) {
  18678 				v3 = xsize << int32(6)
  18679 			} else {
  18680 				v3 = xsize << int32(4)
  18681 			}
  18682 			v2 = v3
  18683 		}
  18684 		v1 = v2
  18685 	}
  18686 	max_window_size = v1
  18687 	if max_window_size > libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS)-libc.Int32FromInt32(120) {
  18688 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(WINDOW_SIZE_BITS) - libc.Int32FromInt32(120)
  18689 	} else {
  18690 		v1 = max_window_size
  18691 	}
  18692 	return v1
  18693 }
  18694 
  18695 func MaxFindCopyLength(tls *libc.TLS, len1 int32) (r int32) {
  18696 	var v1 int32
  18697 	_ = v1
  18698 	if len1 < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18699 		v1 = len1
  18700 	} else {
  18701 		v1 = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  18702 	}
  18703 	return v1
  18704 }
  18705 
  18706 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) {
  18707 	bp := tls.Alloc(16)
  18708 	defer tls.Free(16)
  18709 	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
  18710 	var argb_start, chain, hash_to_first_index uintptr
  18711 	var base_position, best_argb, best_distance, hash_code, len1, max_base_position, window_size, v1 uint32_t
  18712 	var v12 bool
  18713 	var v8 uint32
  18714 	var _ /* tmp at bp+0 */ [2]uint32_t
  18715 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  18716 	size = xsize * ysize
  18717 	iter_max = GetMaxItersForQuality(tls, quality)
  18718 	window_size = libc.Uint32FromInt32(GetWindowSizeForHashChain(tls, quality, xsize))
  18719 	remaining_percent = percent_range
  18720 	percent_start = **(**int32)(__ccgo_up(percent))
  18721 	// Temporarily use the p->offset_length as a hash chain.
  18722 	chain = (*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length
  18723 	if size <= int32(2) {
  18724 		v1 = libc.Uint32FromInt32(0)
  18725 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18726 		**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18727 		return int32(1)
  18728 	}
  18729 	hash_to_first_index = WebPSafeMalloc(tls, libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS)), uint64(4))
  18730 	if hash_to_first_index == libc.UintptrFromInt32(0) {
  18731 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  18732 	}
  18733 	percent_range = remaining_percent / int32(2)
  18734 	remaining_percent = remaining_percent - percent_range
  18735 	// Set the int32_t array to -1.
  18736 	libc.Xmemset(tls, hash_to_first_index, int32(0xff), libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(HASH_BITS))*libc.Uint64FromInt64(4))
  18737 	// Fill the chain linking pixels with the same hash.
  18738 	argb_comp = libc.BoolInt32(**(**uint32_t)(__ccgo_up(argb)) == **(**uint32_t)(__ccgo_up(argb + 1*4)))
  18739 	pos = 0
  18740 	for {
  18741 		if !(pos < size-int32(2)) {
  18742 			break
  18743 		}
  18744 		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)))
  18745 		if argb_comp != 0 && argb_comp_next != 0 {
  18746 			len1 = uint32(1)
  18747 			(**(**[2]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(argb + uintptr(pos)*4))
  18748 			// Figure out how far the pixels are the same.
  18749 			// The last pixel has a different 64 bit hash, as its next pixel does
  18750 			// not have the same color, so we just need to get to the last pixel equal
  18751 			// to its follower.
  18752 			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)) {
  18753 				len1 = len1 + 1
  18754 			}
  18755 			if len1 > libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1)) {
  18756 				// Skip the pixels that match for distance=1 and length>MAX_LENGTH
  18757 				// because they are linked to their predecessor and we automatically
  18758 				// check that in the main for loop below. Skipping means setting no
  18759 				// predecessor in the chain, hence -1.
  18760 				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))
  18761 				pos = libc.Int32FromUint32(uint32(pos) + (len1 - libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))))
  18762 				len1 = libc.Uint32FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1))
  18763 			}
  18764 			// Process the rest of the hash chain.
  18765 			for len1 != 0 {
  18766 				v1 = len1
  18767 				len1 = len1 - 1
  18768 				(**(**[2]uint32_t)(__ccgo_up(bp)))[int32(1)] = v1
  18769 				hash_code = GetPixPairHash64(tls, bp)
  18770 				**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18771 				v4 = pos
  18772 				pos = pos + 1
  18773 				**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18774 			}
  18775 			argb_comp = 0
  18776 		} else {
  18777 			// Just move one pixel forward.
  18778 			hash_code = GetPixPairHash64(tls, argb+uintptr(pos)*4)
  18779 			**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4))
  18780 			v4 = pos
  18781 			pos = pos + 1
  18782 			**(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(hash_code)*4)) = v4
  18783 			argb_comp = argb_comp_next
  18784 		}
  18785 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*pos/(size-int32(2)), percent) != 0) {
  18786 			WebPSafeFree(tls, hash_to_first_index)
  18787 			return 0
  18788 		}
  18789 		goto _2
  18790 	_2:
  18791 	}
  18792 	// Process the penultimate pixel.
  18793 	**(**int32_t)(__ccgo_up(chain + uintptr(pos)*4)) = **(**int32_t)(__ccgo_up(hash_to_first_index + uintptr(GetPixPairHash64(tls, argb+uintptr(pos)*4))*4))
  18794 	WebPSafeFree(tls, hash_to_first_index)
  18795 	percent_start = percent_start + percent_range
  18796 	if !(WebPReportProgress(tls, pic, percent_start, percent) != 0) {
  18797 		return 0
  18798 	}
  18799 	percent_range = remaining_percent
  18800 	// Find the best match interval at each pixel, defined by an offset to the
  18801 	// pixel and a length. The right-most pixel cannot match anything to the right
  18802 	// (hence a best length of 0) and the left-most pixel nothing to the left
  18803 	// (hence an offset of 0).
  18804 	v1 = libc.Uint32FromInt32(0)
  18805 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length + uintptr(size-int32(1))*4)) = v1
  18806 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(p)).Foffset_length)) = v1
  18807 	base_position = libc.Uint32FromInt32(size - int32(2))
  18808 	for {
  18809 		if !(base_position > uint32(0)) {
  18810 			break
  18811 		}
  18812 		max_len = MaxFindCopyLength(tls, libc.Int32FromUint32(libc.Uint32FromInt32(size-int32(1))-base_position))
  18813 		argb_start = argb + uintptr(base_position)*4
  18814 		iter = iter_max
  18815 		best_length = 0
  18816 		best_distance = uint32(0)
  18817 		if base_position > window_size {
  18818 			v8 = base_position - window_size
  18819 		} else {
  18820 			v8 = uint32(0)
  18821 		}
  18822 		min_pos = libc.Int32FromUint32(v8)
  18823 		if max_len < int32(256) {
  18824 			v4 = max_len
  18825 		} else {
  18826 			v4 = int32(256)
  18827 		}
  18828 		length_max = v4
  18829 		pos = **(**int32_t)(__ccgo_up(chain + uintptr(base_position)*4))
  18830 		if !(low_effort != 0) {
  18831 			// Heuristic: use the comparison with the above line as an initialization.
  18832 			if base_position >= libc.Uint32FromInt32(xsize) {
  18833 				curr_length = FindMatchLength(tls, argb_start-uintptr(xsize)*4, argb_start, best_length, max_len)
  18834 				if curr_length > best_length {
  18835 					best_length = curr_length
  18836 					best_distance = libc.Uint32FromInt32(xsize)
  18837 				}
  18838 				iter = iter - 1
  18839 			}
  18840 			// Heuristic: compare to the previous pixel.
  18841 			curr_length = FindMatchLength(tls, argb_start-uintptr(1)*4, argb_start, best_length, max_len)
  18842 			if curr_length > best_length {
  18843 				best_length = curr_length
  18844 				best_distance = uint32(1)
  18845 			}
  18846 			iter = iter - 1
  18847 			// Skip the for loop if we already have the maximum.
  18848 			if best_length == libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18849 				pos = min_pos - int32(1)
  18850 			}
  18851 		}
  18852 		best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18853 		for {
  18854 			if v12 = pos >= min_pos; v12 {
  18855 				iter = iter - 1
  18856 				v4 = iter
  18857 			}
  18858 			if !(v12 && v4 != 0) {
  18859 				break
  18860 			}
  18861 			if **(**uint32_t)(__ccgo_up(argb + uintptr(pos+best_length)*4)) != best_argb {
  18862 				goto _10
  18863 			}
  18864 			curr_length1 = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{VP8LVectorMismatch})))(tls, argb+uintptr(pos)*4, argb_start, max_len)
  18865 			if best_length < curr_length1 {
  18866 				best_length = curr_length1
  18867 				best_distance = base_position - libc.Uint32FromInt32(pos)
  18868 				best_argb = **(**uint32_t)(__ccgo_up(argb_start + uintptr(best_length)*4))
  18869 				// Stop if we have reached a good enough length.
  18870 				if best_length >= length_max {
  18871 					break
  18872 				}
  18873 			}
  18874 			goto _10
  18875 		_10:
  18876 			;
  18877 			pos = **(**int32_t)(__ccgo_up(chain + uintptr(pos)*4))
  18878 		}
  18879 		// We have the best match but in case the two intervals continue matching
  18880 		// to the left, we have the best matches for the left-extended pixels.
  18881 		max_base_position = base_position
  18882 		for int32(1) != 0 {
  18883 			**(**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)
  18884 			base_position = base_position - 1
  18885 			// Stop if we don't have a match or if we are out of bounds.
  18886 			if best_distance == uint32(0) || base_position == uint32(0) {
  18887 				break
  18888 			}
  18889 			// Stop if we cannot extend the matching intervals to the left.
  18890 			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)) {
  18891 				break
  18892 			}
  18893 			// Stop if we are matching at its limit because there could be a closer
  18894 			// matching interval with the same maximum length. Then again, if the
  18895 			// matching interval is as close as possible (best_distance == 1), we will
  18896 			// never find anything better so let's continue.
  18897 			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 {
  18898 				break
  18899 			}
  18900 			if best_length < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  18901 				best_length = best_length + 1
  18902 				max_base_position = base_position
  18903 			}
  18904 		}
  18905 		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) {
  18906 			return 0
  18907 		}
  18908 		goto _7
  18909 	_7:
  18910 	}
  18911 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  18912 }
  18913 
  18914 func AddSingleLiteral(tls *libc.TLS, pixel uint32_t, use_color_cache int32, hashers uintptr, refs uintptr) {
  18915 	var key2, v5 uint32_t
  18916 	var retval, retval1, v, v7 PixOrCopy
  18917 	var v1, v3 int32
  18918 	_, _, _, _, _, _, _, _ = key2, retval, retval1, v, v1, v3, v5, v7
  18919 	if use_color_cache != 0 {
  18920 		v3 = libc.Int32FromUint32(pixel * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(hashers)).Fhash_shift)
  18921 		goto _4
  18922 	_4:
  18923 		v1 = v3
  18924 		goto _2
  18925 	_2:
  18926 		key2 = libc.Uint32FromInt32(v1)
  18927 		v5 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4))
  18928 		goto _6
  18929 	_6:
  18930 		if v5 == pixel {
  18931 			retval.Fmode = uint8(kCacheIdx)
  18932 			retval.Fargb_or_distance = libc.Uint32FromInt32(libc.Int32FromUint32(key2))
  18933 			retval.Flen1 = uint16(1)
  18934 			v7 = retval
  18935 			goto _8
  18936 		_8:
  18937 			v = v7
  18938 		} else {
  18939 			retval1.Fmode = uint8(kLiteral)
  18940 			retval1.Fargb_or_distance = pixel
  18941 			retval1.Flen1 = uint16(1)
  18942 			v7 = retval1
  18943 			goto _10
  18944 		_10:
  18945 			v = v7
  18946 			**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(hashers)).Fcolors + uintptr(key2)*4)) = pixel
  18947 		}
  18948 	} else {
  18949 		retval1.Fmode = uint8(kLiteral)
  18950 		retval1.Fargb_or_distance = pixel
  18951 		retval1.Flen1 = uint16(1)
  18952 		v7 = retval1
  18953 		goto _12
  18954 	_12:
  18955 		v = v7
  18956 	}
  18957 	VP8LBackwardRefsCursorAdd(tls, refs, v)
  18958 }
  18959 
  18960 func BackwardReferencesRle(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, refs uintptr) (r int32) {
  18961 	bp := tls.Alloc(16)
  18962 	defer tls.Free(16)
  18963 	var i, k, key, max_len, pix_count, prev_row_len, rle_len, use_color_cache, v1 int32
  18964 	var retval, v2 PixOrCopy
  18965 	var v7 uintptr
  18966 	var v8 uint32_t
  18967 	var _ /* hashers at bp+0 */ VP8LColorCache
  18968 	_, _, _, _, _, _, _, _, _, _, _, _, _ = i, k, key, max_len, pix_count, prev_row_len, retval, rle_len, use_color_cache, v1, v2, v7, v8
  18969 	pix_count = xsize * ysize
  18970 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  18971 	if use_color_cache != 0 && !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  18972 		return 0
  18973 	}
  18974 	VP8LClearBackwardRefs(tls, refs)
  18975 	// Add first pixel as literal.
  18976 	AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2)), use_color_cache, bp, refs)
  18977 	i = int32(1)
  18978 	for i < pix_count {
  18979 		max_len = MaxFindCopyLength(tls, pix_count-i)
  18980 		rle_len = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(1)*4, 0, max_len)
  18981 		if i < xsize {
  18982 			v1 = 0
  18983 		} else {
  18984 			v1 = FindMatchLength(tls, argb2+uintptr(i)*4, argb2+uintptr(i)*4-uintptr(xsize)*4, 0, max_len)
  18985 		}
  18986 		prev_row_len = v1
  18987 		if rle_len >= prev_row_len && rle_len >= int32(MIN_LENGTH) {
  18988 			retval.Fmode = uint8(kCopy)
  18989 			retval.Fargb_or_distance = uint32(1)
  18990 			retval.Flen1 = libc.Uint16FromInt32(rle_len)
  18991 			v2 = retval
  18992 			goto _3
  18993 		_3:
  18994 			VP8LBackwardRefsCursorAdd(tls, refs, v2)
  18995 			// We don't need to update the color cache here since it is always the
  18996 			// same pixel being copied, and that does not change the color cache
  18997 			// state.
  18998 			i = i + rle_len
  18999 		} else {
  19000 			if prev_row_len >= int32(MIN_LENGTH) {
  19001 				retval.Fmode = uint8(kCopy)
  19002 				retval.Fargb_or_distance = libc.Uint32FromInt32(xsize)
  19003 				retval.Flen1 = libc.Uint16FromInt32(prev_row_len)
  19004 				v2 = retval
  19005 				goto _5
  19006 			_5:
  19007 				VP8LBackwardRefsCursorAdd(tls, refs, v2)
  19008 				if use_color_cache != 0 {
  19009 					k = 0
  19010 					for {
  19011 						if !(k < prev_row_len) {
  19012 							break
  19013 						}
  19014 						v7 = bp
  19015 						v8 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(i+k)*4))
  19016 						v1 = libc.Int32FromUint32(v8 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v7)).Fhash_shift)
  19017 						goto _10
  19018 					_10:
  19019 						key = v1
  19020 						**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v7)).Fcolors + uintptr(key)*4)) = v8
  19021 						goto _6
  19022 					_6:
  19023 						;
  19024 						k = k + 1
  19025 					}
  19026 				}
  19027 				i = i + prev_row_len
  19028 			} else {
  19029 				AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  19030 				i = i + 1
  19031 			}
  19032 		}
  19033 	}
  19034 	if use_color_cache != 0 {
  19035 		VP8LColorCacheClear(tls, bp)
  19036 	}
  19037 	return libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  19038 }
  19039 
  19040 func BackwardReferencesLz77(tls *libc.TLS, xsize int32, ysize int32, argb2 uintptr, cache_bits int32, hash_chain uintptr, refs uintptr) (r int32) {
  19041 	bp := tls.Alloc(32)
  19042 	defer tls.Free(32)
  19043 	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
  19044 	var retval, v14 PixOrCopy
  19045 	var v2 uintptr
  19046 	var v18 uint32_t
  19047 	var _ /* hashers at bp+0 */ VP8LColorCache
  19048 	var _ /* len at bp+20 */ int32
  19049 	var _ /* offset at bp+16 */ int32
  19050 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19051 	i_last_check = -int32(1)
  19052 	ok = 0
  19053 	cc_init = 0
  19054 	use_color_cache = libc.BoolInt32(cache_bits > libc.Int32FromInt32(0))
  19055 	pix_count = xsize * ysize
  19056 	if use_color_cache != 0 {
  19057 		cc_init = VP8LColorCacheInit(tls, bp, cache_bits)
  19058 		if !(cc_init != 0) {
  19059 			goto Error
  19060 		}
  19061 	}
  19062 	VP8LClearBackwardRefs(tls, refs)
  19063 	i = 0
  19064 	for {
  19065 		if !(i < pix_count) {
  19066 			break
  19067 		}
  19068 		// Alternative#1: Code the pixels starting at 'i' using backward reference.
  19069 		**(**int32)(__ccgo_up(bp + 16)) = 0
  19070 		**(**int32)(__ccgo_up(bp + 20)) = 0
  19071 		v2 = hash_chain
  19072 		v3 = i
  19073 		v4 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(v2)).Foffset_length + uintptr(v3)*4)) >> int32(MAX_LENGTH_BITS))
  19074 		goto _5
  19075 	_5:
  19076 		**(**int32)(__ccgo_up(bp + 16)) = v4
  19077 		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)))
  19078 		goto _7
  19079 	_7:
  19080 		**(**int32)(__ccgo_up(bp + 20)) = v6
  19081 		if **(**int32)(__ccgo_up(bp + 20)) >= int32(MIN_LENGTH) {
  19082 			len_ini = **(**int32)(__ccgo_up(bp + 20))
  19083 			max_reach = 0
  19084 			if i+len_ini >= pix_count {
  19085 				v3 = pix_count - int32(1)
  19086 			} else {
  19087 				v3 = i + len_ini
  19088 			}
  19089 			j_max = v3
  19090 			// Only start from what we have not checked already.
  19091 			if i > i_last_check {
  19092 				v4 = i
  19093 			} else {
  19094 				v4 = i_last_check
  19095 			}
  19096 			i_last_check = v4
  19097 			// We know the best match for the current pixel but we try to find the
  19098 			// best matches for the current pixel AND the next one combined.
  19099 			// The naive method would use the intervals:
  19100 			// [i,i+len) + [i+len, length of best match at i+len)
  19101 			// while we check if we can use:
  19102 			// [i,j) (where j<=i+len) + [j, length of best match at j)
  19103 			j = i_last_check + int32(1)
  19104 			for {
  19105 				if !(j <= j_max) {
  19106 					break
  19107 				}
  19108 				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)))
  19109 				goto _12
  19110 			_12:
  19111 				len_j = v3
  19112 				if len_j >= int32(MIN_LENGTH) {
  19113 					v4 = len_j
  19114 				} else {
  19115 					v4 = int32(1)
  19116 				}
  19117 				reach = j + v4 // 1 for single literal.
  19118 				if reach > max_reach {
  19119 					**(**int32)(__ccgo_up(bp + 20)) = j - i
  19120 					max_reach = reach
  19121 					if max_reach >= pix_count {
  19122 						break
  19123 					}
  19124 				}
  19125 				goto _10
  19126 			_10:
  19127 				;
  19128 				j = j + 1
  19129 			}
  19130 		} else {
  19131 			**(**int32)(__ccgo_up(bp + 20)) = int32(1)
  19132 		}
  19133 		// Go with literal or backward reference.
  19134 		if **(**int32)(__ccgo_up(bp + 20)) == int32(1) {
  19135 			AddSingleLiteral(tls, **(**uint32_t)(__ccgo_up(argb2 + uintptr(i)*4)), use_color_cache, bp, refs)
  19136 		} else {
  19137 			retval.Fmode = uint8(kCopy)
  19138 			retval.Fargb_or_distance = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 16)))
  19139 			retval.Flen1 = libc.Uint16FromInt32(**(**int32)(__ccgo_up(bp + 20)))
  19140 			v14 = retval
  19141 			goto _15
  19142 		_15:
  19143 			VP8LBackwardRefsCursorAdd(tls, refs, v14)
  19144 			if use_color_cache != 0 {
  19145 				j = i
  19146 				for {
  19147 					if !(j < i+**(**int32)(__ccgo_up(bp + 20))) {
  19148 						break
  19149 					}
  19150 					v2 = bp
  19151 					v18 = **(**uint32_t)(__ccgo_up(argb2 + uintptr(j)*4))
  19152 					v3 = libc.Int32FromUint32(v18 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v2)).Fhash_shift)
  19153 					goto _20
  19154 				_20:
  19155 					key = v3
  19156 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v2)).Fcolors + uintptr(key)*4)) = v18
  19157 					goto _16
  19158 				_16:
  19159 					;
  19160 					j = j + 1
  19161 				}
  19162 			}
  19163 		}
  19164 		i = i + **(**int32)(__ccgo_up(bp + 20))
  19165 		goto _1
  19166 	_1:
  19167 	}
  19168 	ok = libc.BoolInt32(!((*VP8LBackwardRefs)(unsafe.Pointer(refs)).Ferror1 != 0))
  19169 	goto Error
  19170 Error:
  19171 	;
  19172 	if cc_init != 0 {
  19173 		VP8LColorCacheClear(tls, bp)
  19174 	}
  19175 	return ok
  19176 }
  19177 
  19178 // C documentation
  19179 //
  19180 //	// Compute an LZ77 by forcing matches to happen within a given distance cost.
  19181 //	// We therefore limit the algorithm to the lowest 32 values in the PlaneCode
  19182 //	// definition.
  19183 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) {
  19184 	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
  19185 	var counts, counts_ini uintptr
  19186 	var window_offsets, window_offsets_new [32]int32
  19187 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19188 	pix_count = xsize * ysize
  19189 	window_offsets = [32]int32{}
  19190 	window_offsets_new = [32]int32{}
  19191 	window_offsets_size = 0
  19192 	window_offsets_new_size = 0
  19193 	counts_ini = WebPSafeMalloc(tls, libc.Uint64FromInt32(xsize*ysize), uint64(2))
  19194 	best_offset_prev = -int32(1)
  19195 	best_length_prev = -int32(1)
  19196 	if counts_ini == libc.UintptrFromInt32(0) {
  19197 		return 0
  19198 	}
  19199 	// counts[i] counts how many times a pixel is repeated starting at position i.
  19200 	i = pix_count - int32(2)
  19201 	counts = counts_ini + uintptr(i)*2
  19202 	**(**uint16_t)(__ccgo_up(counts + 1*2)) = uint16(1)
  19203 	for {
  19204 		if !(i >= 0) {
  19205 			break
  19206 		}
  19207 		if **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) == **(**uint32_t)(__ccgo_up(argb + uintptr(i+int32(1))*4)) {
  19208 			// Max out the counts to MAX_LENGTH.
  19209 			**(**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)))
  19210 		} else {
  19211 			**(**uint16_t)(__ccgo_up(counts)) = uint16(1)
  19212 		}
  19213 		goto _1
  19214 	_1:
  19215 		;
  19216 		i = i - 1
  19217 		counts -= 2
  19218 	}
  19219 	// Figure out the window offsets around a pixel. They are stored in a
  19220 	// spiraling order around the pixel as defined by VP8LDistanceToPlaneCode.
  19221 	y = 0
  19222 	for {
  19223 		if !(y <= int32(6)) {
  19224 			break
  19225 		}
  19226 		x = -int32(6)
  19227 		for {
  19228 			if !(x <= int32(6)) {
  19229 				break
  19230 			}
  19231 			offset = y*xsize + x
  19232 			// Ignore offsets that bring us after the pixel.
  19233 			if offset <= 0 {
  19234 				goto _3
  19235 			}
  19236 			plane_code = VP8LDistanceToPlaneCode(tls, xsize, offset) - int32(1)
  19237 			if plane_code >= int32(WINDOW_OFFSETS_SIZE_MAX) {
  19238 				goto _3
  19239 			}
  19240 			window_offsets[plane_code] = offset
  19241 			goto _3
  19242 		_3:
  19243 			;
  19244 			x = x + 1
  19245 		}
  19246 		goto _2
  19247 	_2:
  19248 		;
  19249 		y = y + 1
  19250 	}
  19251 	// For narrow images, not all plane codes are reached, so remove those.
  19252 	i = 0
  19253 	for {
  19254 		if !(i < int32(WINDOW_OFFSETS_SIZE_MAX)) {
  19255 			break
  19256 		}
  19257 		if window_offsets[i] == 0 {
  19258 			goto _4
  19259 		}
  19260 		v5 = window_offsets_size
  19261 		window_offsets_size = window_offsets_size + 1
  19262 		window_offsets[v5] = window_offsets[i]
  19263 		goto _4
  19264 	_4:
  19265 		;
  19266 		i = i + 1
  19267 	}
  19268 	// Given a pixel P, find the offsets that reach pixels unreachable from P-1
  19269 	// with any of the offsets in window_offsets[].
  19270 	i = 0
  19271 	for {
  19272 		if !(i < window_offsets_size) {
  19273 			break
  19274 		}
  19275 		is_reachable = 0
  19276 		j = 0
  19277 		for {
  19278 			if !(j < window_offsets_size && !(is_reachable != 0)) {
  19279 				break
  19280 			}
  19281 			is_reachable = is_reachable | libc.BoolInt32(window_offsets[i] == window_offsets[j]+int32(1))
  19282 			goto _7
  19283 		_7:
  19284 			;
  19285 			j = j + 1
  19286 		}
  19287 		if !(is_reachable != 0) {
  19288 			window_offsets_new[window_offsets_new_size] = window_offsets[i]
  19289 			window_offsets_new_size = window_offsets_new_size + 1
  19290 		}
  19291 		goto _6
  19292 	_6:
  19293 		;
  19294 		i = i + 1
  19295 	}
  19296 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19297 	i = int32(1)
  19298 	for {
  19299 		if !(i < pix_count) {
  19300 			break
  19301 		}
  19302 		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)))
  19303 		goto _10
  19304 	_10:
  19305 		best_length = v5
  19306 		do_compute = int32(1)
  19307 		if best_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19308 			// Do not recompute the best match if we already have a maximal one in the
  19309 			// window.
  19310 			v9 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain_best)).Foffset_length + uintptr(i)*4)) >> int32(MAX_LENGTH_BITS))
  19311 			goto _12
  19312 		_12:
  19313 			best_offset = v9
  19314 			ind = 0
  19315 			for {
  19316 				if !(ind < window_offsets_size) {
  19317 					break
  19318 				}
  19319 				if best_offset == window_offsets[ind] {
  19320 					do_compute = 0
  19321 					break
  19322 				}
  19323 				goto _13
  19324 			_13:
  19325 				;
  19326 				ind = ind + 1
  19327 			}
  19328 		}
  19329 		if do_compute != 0 {
  19330 			// Figure out if we should use the offset/length from the previous pixel
  19331 			// as an initial guess and therefore only inspect the offsets in
  19332 			// window_offsets_new[].
  19333 			use_prev = libc.BoolInt32(best_length_prev > int32(1) && best_length_prev < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1))
  19334 			if use_prev != 0 {
  19335 				v5 = window_offsets_new_size
  19336 			} else {
  19337 				v5 = window_offsets_size
  19338 			}
  19339 			num_ind = v5
  19340 			if use_prev != 0 {
  19341 				v9 = best_length_prev - int32(1)
  19342 			} else {
  19343 				v9 = 0
  19344 			}
  19345 			best_length = v9
  19346 			if use_prev != 0 {
  19347 				v5 = best_offset_prev
  19348 			} else {
  19349 				v5 = 0
  19350 			}
  19351 			best_offset = v5
  19352 			// Find the longest match in a window around the pixel.
  19353 			ind = 0
  19354 			for {
  19355 				if !(ind < num_ind) {
  19356 					break
  19357 				}
  19358 				curr_length = 0
  19359 				j1 = i
  19360 				if use_prev != 0 {
  19361 					v5 = i - window_offsets_new[ind]
  19362 				} else {
  19363 					v5 = i - window_offsets[ind]
  19364 				}
  19365 				j_offset = v5
  19366 				if j_offset < 0 || **(**uint32_t)(__ccgo_up(argb + uintptr(j_offset)*4)) != **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) {
  19367 					goto _17
  19368 				}
  19369 				// The longest match is the sum of how many times each pixel is
  19370 				// repeated.
  19371 				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)) {
  19372 					counts_j_offset = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j_offset)*2)))
  19373 					counts_j = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(counts_ini + uintptr(j1)*2)))
  19374 					if counts_j_offset != counts_j {
  19375 						if counts_j_offset < counts_j {
  19376 							v5 = counts_j_offset
  19377 						} else {
  19378 							v5 = counts_j
  19379 						}
  19380 						curr_length = curr_length + v5
  19381 						break
  19382 					}
  19383 					// The same color is repeated counts_pos times at j_offset and j.
  19384 					curr_length = curr_length + counts_j_offset
  19385 					j_offset = j_offset + counts_j_offset
  19386 					j1 = j1 + counts_j_offset
  19387 				}
  19388 				if best_length < curr_length {
  19389 					if use_prev != 0 {
  19390 						v5 = window_offsets_new[ind]
  19391 					} else {
  19392 						v5 = window_offsets[ind]
  19393 					}
  19394 					best_offset = v5
  19395 					if curr_length >= libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS)-libc.Int32FromInt32(1) {
  19396 						best_length = libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_LENGTH_BITS) - libc.Int32FromInt32(1)
  19397 						break
  19398 					} else {
  19399 						best_length = curr_length
  19400 					}
  19401 				}
  19402 				goto _17
  19403 			_17:
  19404 				;
  19405 				ind = ind + 1
  19406 			}
  19407 		}
  19408 		if best_length <= int32(MIN_LENGTH) {
  19409 			**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length + uintptr(i)*4)) = uint32(0)
  19410 			best_offset_prev = 0
  19411 			best_length_prev = 0
  19412 		} else {
  19413 			**(**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)
  19414 			best_offset_prev = best_offset
  19415 			best_length_prev = best_length
  19416 		}
  19417 		goto _8
  19418 	_8:
  19419 		;
  19420 		i = i + 1
  19421 	}
  19422 	**(**uint32_t)(__ccgo_up((*VP8LHashChain)(unsafe.Pointer(hash_chain)).Foffset_length)) = uint32(0)
  19423 	WebPSafeFree(tls, counts_ini)
  19424 	return BackwardReferencesLz77(tls, xsize, ysize, argb, cache_bits, hash_chain, refs)
  19425 }
  19426 
  19427 // -----------------------------------------------------------------------------
  19428 
  19429 func BackwardReferences2DLocality(tls *libc.TLS, xsize int32, refs uintptr) {
  19430 	bp := tls.Alloc(32)
  19431 	defer tls.Free(32)
  19432 	var dist, transformed_dist, v1, v3 int32
  19433 	var v5, v6, v7 uintptr
  19434 	var _ /* c at bp+0 */ VP8LRefsCursor
  19435 	_, _, _, _, _, _, _ = dist, transformed_dist, v1, v3, v5, v6, v7
  19436 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  19437 	for {
  19438 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  19439 		goto _2
  19440 	_2:
  19441 		if !(v1 != 0) {
  19442 			break
  19443 		}
  19444 		v3 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fmode) == int32(kCopy))
  19445 		goto _4
  19446 	_4:
  19447 		if v3 != 0 {
  19448 			dist = libc.Int32FromUint32((*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance)
  19449 			transformed_dist = VP8LDistanceToPlaneCode(tls, xsize, dist)
  19450 			(*PixOrCopy)(unsafe.Pointer((**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos)).Fargb_or_distance = libc.Uint32FromInt32(transformed_dist)
  19451 		}
  19452 		v5 = bp
  19453 		v7 = v5
  19454 		*(*uintptr)(unsafe.Pointer(v7)) += 8
  19455 		v6 = *(*uintptr)(unsafe.Pointer(v7))
  19456 		if v6 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19457 			VP8LRefsCursorNextBlock(tls, v5)
  19458 		}
  19459 	}
  19460 }
  19461 
  19462 // C documentation
  19463 //
  19464 //	// Evaluate optimal cache bits for the local color cache.
  19465 //	// The input *best_cache_bits sets the maximum cache bits to use (passing 0
  19466 //	// implies disabling the local color cache). The local color cache is also
  19467 //	// disabled for the lower (<= 25) quality.
  19468 //	// Returns 0 in case of memory error.
  19469 func CalculateBestCacheSize(tls *libc.TLS, argb2 uintptr, quality int32, refs uintptr, best_cache_bits uintptr) (r1 int32) {
  19470 	bp := tls.Alloc(224)
  19471 	defer tls.Free(224)
  19472 	var a, argb_prev, b, g, pix, r, v11 uint32_t
  19473 	var cache_bits_max, highest_bit, i, key2, key3, len1, ok, second_highest_bit, v1, v3, v5, v8 int32
  19474 	var cc_init [11]int32
  19475 	var entropy, entropy_min uint64_t
  19476 	var histos [11]uintptr
  19477 	var prefix_code VP8LPrefixCode
  19478 	var v, v16, v17, v18, v7 uintptr
  19479 	var _ /* c at bp+176 */ VP8LRefsCursor
  19480 	var _ /* code at bp+200 */ int32
  19481 	var _ /* extra_bits at bp+204 */ int32
  19482 	var _ /* extra_bits_value at bp+208 */ int32
  19483 	var _ /* hashers at bp+0 */ [11]VP8LColorCache
  19484 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19485 	if quality <= int32(25) {
  19486 		v1 = 0
  19487 	} else {
  19488 		v1 = **(**int32)(__ccgo_up(best_cache_bits))
  19489 	}
  19490 	cache_bits_max = v1
  19491 	entropy_min = uint64(^libc.Uint64FromUint64(0))
  19492 	cc_init = [11]int32{}
  19493 	**(**VP8LRefsCursor)(__ccgo_up(bp + 176)) = VP8LRefsCursorInit(tls, refs)
  19494 	histos = [11]uintptr{}
  19495 	ok = 0
  19496 	if cache_bits_max == 0 {
  19497 		**(**int32)(__ccgo_up(best_cache_bits)) = 0
  19498 		// Local color cache is disabled.
  19499 		return int32(1)
  19500 	}
  19501 	// Allocate data.
  19502 	i = 0
  19503 	for {
  19504 		if !(i <= cache_bits_max) {
  19505 			break
  19506 		}
  19507 		histos[i] = VP8LAllocateHistogram(tls, i)
  19508 		if histos[i] == libc.UintptrFromInt32(0) {
  19509 			goto Error
  19510 		}
  19511 		VP8LHistogramInit(tls, histos[i], i, int32(1))
  19512 		if i == 0 {
  19513 			goto _2
  19514 		}
  19515 		cc_init[i] = VP8LColorCacheInit(tls, bp+uintptr(i)*16, i)
  19516 		if !(cc_init[i] != 0) {
  19517 			goto Error
  19518 		}
  19519 		goto _2
  19520 	_2:
  19521 		;
  19522 		i = i + 1
  19523 	}
  19524 	// Find the cache_bits giving the lowest entropy. The search is done in a
  19525 	// brute-force way as the function (entropy w.r.t cache_bits) can be
  19526 	// anything in practice.
  19527 	for {
  19528 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+176)).Fcur_pos != libc.UintptrFromInt32(0))
  19529 		goto _4
  19530 	_4:
  19531 		if !(v1 != 0) {
  19532 			break
  19533 		}
  19534 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 176))).Fcur_pos
  19535 		v3 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19536 		goto _6
  19537 	_6:
  19538 		if v3 != 0 {
  19539 			v7 = argb2
  19540 			argb2 += 4
  19541 			pix = **(**uint32_t)(__ccgo_up(v7))
  19542 			a = pix >> libc.Int32FromInt32(24) & uint32(0xff)
  19543 			r = pix >> libc.Int32FromInt32(16) & uint32(0xff)
  19544 			g = pix >> libc.Int32FromInt32(8) & uint32(0xff)
  19545 			b = pix >> libc.Int32FromInt32(0) & uint32(0xff)
  19546 			v5 = libc.Int32FromUint32(pix * kHashMul11 >> (int32(32) - cache_bits_max))
  19547 			goto _9
  19548 		_9:
  19549 			// The keys of the caches can be derived from the longest one.
  19550 			key2 = v5
  19551 			// Do not use the color cache for cache_bits = 0.
  19552 			**(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 1032 + uintptr(b)*4)) + 1
  19553 			**(**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
  19554 			**(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 8 + uintptr(r)*4)) + 1
  19555 			**(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[0] + 2056 + uintptr(a)*4)) + 1
  19556 			// Deal with cache_bits > 0.
  19557 			i = cache_bits_max
  19558 			for {
  19559 				if !(i >= int32(1)) {
  19560 					break
  19561 				}
  19562 				v11 = **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(libc.Uint32FromInt32(key2))*4))
  19563 				goto _12
  19564 			_12:
  19565 				if v11 == pix {
  19566 					**(**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
  19567 				} else {
  19568 					**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(bp+uintptr(i)*16)).Fcolors + uintptr(libc.Uint32FromInt32(key2))*4)) = pix
  19569 					**(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 1032 + uintptr(b)*4)) + 1
  19570 					**(**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
  19571 					**(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 8 + uintptr(r)*4)) + 1
  19572 					**(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) = **(**uint32_t)(__ccgo_up(histos[i] + 2056 + uintptr(a)*4)) + 1
  19573 				}
  19574 				goto _10
  19575 			_10:
  19576 				;
  19577 				i = i - 1
  19578 				key2 = key2 >> int32(1)
  19579 			}
  19580 		} else {
  19581 			v11 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  19582 			goto _14
  19583 		_14:
  19584 			// We should compute the contribution of the (distance,length)
  19585 			// histograms but those are the same independently from the cache size.
  19586 			// As those constant contributions are in the end added to the other
  19587 			// histogram contributions, we can ignore them, except for the length
  19588 			// prefix that is part of the 'literal' histogram.
  19589 			len1 = libc.Int32FromUint32(v11)
  19590 			argb_prev = **(**uint32_t)(__ccgo_up(argb2)) ^ uint32(0xffffffff)
  19591 			v1 = len1
  19592 			v7 = bp + 200
  19593 			v16 = bp + 204
  19594 			v17 = bp + 208
  19595 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  19596 				prefix_code = kPrefixEncodeCode[v1]
  19597 				**(**int32)(__ccgo_up(v7)) = int32(prefix_code.Fcode)
  19598 				**(**int32)(__ccgo_up(v16)) = int32(prefix_code.Fextra_bits)
  19599 				**(**int32)(__ccgo_up(v17)) = libc.Int32FromUint8(kPrefixEncodeExtraBitsValue[v1])
  19600 			} else {
  19601 				v3 = v1
  19602 				v18 = v16
  19603 				v3 = v3 - 1
  19604 				v5 = v3
  19605 				v8 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v5))
  19606 				goto _23
  19607 			_23:
  19608 				highest_bit = v8
  19609 				second_highest_bit = v3 >> (highest_bit - int32(1)) & int32(1)
  19610 				**(**int32)(__ccgo_up(v18)) = highest_bit - int32(1)
  19611 				**(**int32)(__ccgo_up(v17)) = v3 & (int32(1)<<**(**int32)(__ccgo_up(v18)) - int32(1))
  19612 				**(**int32)(__ccgo_up(v7)) = int32(2)*highest_bit + second_highest_bit
  19613 			}
  19614 			i = 0
  19615 			for {
  19616 				if !(i <= cache_bits_max) {
  19617 					break
  19618 				}
  19619 				**(**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
  19620 				goto _24
  19621 			_24:
  19622 				;
  19623 				i = i + 1
  19624 			}
  19625 			// Update the color caches.
  19626 			for {
  19627 				if **(**uint32_t)(__ccgo_up(argb2)) != argb_prev {
  19628 					v3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb2)) * kHashMul11 >> (int32(32) - cache_bits_max))
  19629 					goto _28
  19630 				_28:
  19631 					// Efficiency: insert only if the color changes.
  19632 					key3 = v3
  19633 					i = cache_bits_max
  19634 					for {
  19635 						if !(i >= int32(1)) {
  19636 							break
  19637 						}
  19638 						**(**uint32_t)(__ccgo_up((**(**[11]VP8LColorCache)(__ccgo_up(bp)))[i].Fcolors + uintptr(key3)*4)) = **(**uint32_t)(__ccgo_up(argb2))
  19639 						goto _29
  19640 					_29:
  19641 						;
  19642 						i = i - 1
  19643 						key3 = key3 >> int32(1)
  19644 					}
  19645 					argb_prev = **(**uint32_t)(__ccgo_up(argb2))
  19646 				}
  19647 				argb2 += 4
  19648 				goto _26
  19649 			_26:
  19650 				;
  19651 				len1 = len1 - 1
  19652 				v1 = len1
  19653 				if !(v1 != 0) {
  19654 					break
  19655 				}
  19656 			}
  19657 		}
  19658 		v7 = bp + 176
  19659 		v17 = v7
  19660 		*(*uintptr)(unsafe.Pointer(v17)) += 8
  19661 		v16 = *(*uintptr)(unsafe.Pointer(v17))
  19662 		if v16 == (*VP8LRefsCursor)(unsafe.Pointer(v7)).Flast_pos {
  19663 			VP8LRefsCursorNextBlock(tls, v7)
  19664 		}
  19665 	}
  19666 	i = 0
  19667 	for {
  19668 		if !(i <= cache_bits_max) {
  19669 			break
  19670 		}
  19671 		entropy = VP8LHistogramEstimateBits(tls, histos[i])
  19672 		if i == 0 || entropy < entropy_min {
  19673 			entropy_min = entropy
  19674 			**(**int32)(__ccgo_up(best_cache_bits)) = i
  19675 		}
  19676 		goto _33
  19677 	_33:
  19678 		;
  19679 		i = i + 1
  19680 	}
  19681 	ok = int32(1)
  19682 	goto Error
  19683 Error:
  19684 	;
  19685 	i = 0
  19686 	for {
  19687 		if !(i <= cache_bits_max) {
  19688 			break
  19689 		}
  19690 		if cc_init[i] != 0 {
  19691 			VP8LColorCacheClear(tls, bp+uintptr(i)*16)
  19692 		}
  19693 		VP8LFreeHistogram(tls, histos[i])
  19694 		goto _34
  19695 	_34:
  19696 		;
  19697 		i = i + 1
  19698 	}
  19699 	return ok
  19700 }
  19701 
  19702 // C documentation
  19703 //
  19704 //	// Update (in-place) backward references for specified cache_bits.
  19705 func BackwardRefsWithLocalCache(tls *libc.TLS, argb3 uintptr, cache_bits int32, refs uintptr) (r int32) {
  19706 	bp := tls.Alloc(48)
  19707 	defer tls.Free(48)
  19708 	var argb_literal, v6 uint32_t
  19709 	var ix, k, key, key1, pixel_index, v1, v11, v3, v7, v9 int32
  19710 	var retval, v12 PixOrCopy
  19711 	var v, v14, v20, v5 uintptr
  19712 	var _ /* c at bp+16 */ VP8LRefsCursor
  19713 	var _ /* hashers at bp+0 */ VP8LColorCache
  19714 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_literal, ix, k, key, key1, pixel_index, retval, v, v1, v11, v12, v14, v20, v3, v5, v6, v7, v9
  19715 	pixel_index = 0
  19716 	**(**VP8LRefsCursor)(__ccgo_up(bp + 16)) = VP8LRefsCursorInit(tls, refs)
  19717 	if !(VP8LColorCacheInit(tls, bp, cache_bits) != 0) {
  19718 		return 0
  19719 	}
  19720 	for {
  19721 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp+16)).Fcur_pos != libc.UintptrFromInt32(0))
  19722 		goto _2
  19723 	_2:
  19724 		if !(v1 != 0) {
  19725 			break
  19726 		}
  19727 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp + 16))).Fcur_pos
  19728 		v3 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  19729 		goto _4
  19730 	_4:
  19731 		if v3 != 0 {
  19732 			argb_literal = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  19733 			v5 = bp
  19734 			v6 = argb_literal
  19735 			v7 = libc.Int32FromUint32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19736 			goto _8
  19737 		_8:
  19738 			key1 = v7
  19739 			if **(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key1)*4)) == v6 {
  19740 				v11 = key1
  19741 			} else {
  19742 				v11 = -int32(1)
  19743 			}
  19744 			v9 = v11
  19745 			goto _10
  19746 		_10:
  19747 			ix = v9
  19748 			if ix >= 0 {
  19749 				// hashers contains argb_literal
  19750 				retval.Fmode = uint8(kCacheIdx)
  19751 				retval.Fargb_or_distance = libc.Uint32FromInt32(ix)
  19752 				retval.Flen1 = uint16(1)
  19753 				v12 = retval
  19754 				goto _13
  19755 			_13:
  19756 				**(**PixOrCopy)(__ccgo_up(v)) = v12
  19757 			} else {
  19758 				v5 = bp
  19759 				v6 = argb_literal
  19760 				v1 = libc.Int32FromUint32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19761 				goto _17
  19762 			_17:
  19763 				key = v1
  19764 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19765 			}
  19766 			pixel_index = pixel_index + 1
  19767 		} else {
  19768 			k = 0
  19769 			for {
  19770 				if !(k < libc.Int32FromUint16((*PixOrCopy)(unsafe.Pointer(v)).Flen1)) {
  19771 					break
  19772 				}
  19773 				v1 = pixel_index
  19774 				pixel_index = pixel_index + 1
  19775 				v5 = bp
  19776 				v6 = **(**uint32_t)(__ccgo_up(argb3 + uintptr(v1)*4))
  19777 				v3 = libc.Int32FromUint32(v6 * kHashMul11 >> (*VP8LColorCache)(unsafe.Pointer(v5)).Fhash_shift)
  19778 				goto _23
  19779 			_23:
  19780 				key = v3
  19781 				**(**uint32_t)(__ccgo_up((*VP8LColorCache)(unsafe.Pointer(v5)).Fcolors + uintptr(key)*4)) = v6
  19782 				goto _18
  19783 			_18:
  19784 				;
  19785 				k = k + 1
  19786 			}
  19787 		}
  19788 		v5 = bp + 16
  19789 		v20 = v5
  19790 		*(*uintptr)(unsafe.Pointer(v20)) += 8
  19791 		v14 = *(*uintptr)(unsafe.Pointer(v20))
  19792 		if v14 == (*VP8LRefsCursor)(unsafe.Pointer(v5)).Flast_pos {
  19793 			VP8LRefsCursorNextBlock(tls, v5)
  19794 		}
  19795 	}
  19796 	VP8LColorCacheClear(tls, bp)
  19797 	return int32(1)
  19798 }
  19799 
  19800 func GetBackwardReferencesLowEffort(tls *libc.TLS, width int32, height int32, argb uintptr, cache_bits uintptr, hash_chain uintptr, refs_lz77 uintptr) (r uintptr) {
  19801 	**(**int32)(__ccgo_up(cache_bits)) = 0
  19802 	if !(BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_lz77) != 0) {
  19803 		return libc.UintptrFromInt32(0)
  19804 	}
  19805 	BackwardReferences2DLocality(tls, width, refs_lz77)
  19806 	return refs_lz77
  19807 }
  19808 
  19809 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) {
  19810 	bp := tls.Alloc(32)
  19811 	defer tls.Free(32)
  19812 	var bit_cost, bit_cost_trace uint64_t
  19813 	var bit_costs_best [2]uint64_t
  19814 	var cache_bits1, i, lz77_type, res, status, v1 int32
  19815 	var hash_chain_tmp, histo, refs_tmp, v6 uintptr
  19816 	var lz77_types_best [2]int32
  19817 	var _ /* cache_bits at bp+16 */ int32
  19818 	var _ /* hash_chain_box at bp+0 */ VP8LHashChain
  19819 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  19820 	histo = libc.UintptrFromInt32(0)
  19821 	// Index 0 is for a color cache, index 1 for no cache (if needed).
  19822 	lz77_types_best = [2]int32{}
  19823 	bit_costs_best = [2]uint64_t{
  19824 		0: uint64(^libc.Uint64FromUint64(0)),
  19825 		1: uint64(^libc.Uint64FromUint64(0)),
  19826 	}
  19827 	if do_no_cache != 0 {
  19828 		v1 = int32(2)
  19829 	} else {
  19830 		v1 = int32(1)
  19831 	}
  19832 	refs_tmp = refs + uintptr(v1)*40
  19833 	status = 0
  19834 	libc.Xmemset(tls, bp, 0, uint64(16))
  19835 	histo = VP8LAllocateHistogram(tls, int32(MAX_COLOR_CACHE_BITS))
  19836 	if histo == libc.UintptrFromInt32(0) {
  19837 		goto Error
  19838 	}
  19839 	lz77_type = int32(1)
  19840 	for {
  19841 		if !(lz77_types_to_try != 0) {
  19842 			break
  19843 		}
  19844 		res = 0
  19845 		bit_cost = 0
  19846 		if lz77_types_to_try&lz77_type == 0 {
  19847 			goto _2
  19848 		}
  19849 		switch lz77_type {
  19850 		case int32(kLZ77RLE):
  19851 			res = BackwardReferencesRle(tls, width, height, argb, 0, refs_tmp)
  19852 		case int32(kLZ77Standard):
  19853 			// Compute LZ77 with no cache (0 bits), as the ideal LZ77 with a color
  19854 			// cache is not that different in practice.
  19855 			res = BackwardReferencesLz77(tls, width, height, argb, 0, hash_chain, refs_tmp)
  19856 		case int32(kLZ77Box):
  19857 			if !(VP8LHashChainInit(tls, bp, width*height) != 0) {
  19858 				goto Error
  19859 			}
  19860 			res = BackwardReferencesLz77Box(tls, width, height, argb, 0, hash_chain, bp, refs_tmp)
  19861 		default:
  19862 		}
  19863 		if !(res != 0) {
  19864 			goto Error
  19865 		}
  19866 		// Start with the no color cache case.
  19867 		i = int32(1)
  19868 		for {
  19869 			if !(i >= 0) {
  19870 				break
  19871 			}
  19872 			if i == int32(1) {
  19873 				v1 = 0
  19874 			} else {
  19875 				v1 = cache_bits_max
  19876 			}
  19877 			**(**int32)(__ccgo_up(bp + 16)) = v1
  19878 			if i == int32(1) && !(do_no_cache != 0) {
  19879 				goto _3
  19880 			}
  19881 			if i == 0 {
  19882 				// Try with a color cache.
  19883 				if !(CalculateBestCacheSize(tls, argb, quality, refs_tmp, bp+16) != 0) {
  19884 					goto Error
  19885 				}
  19886 				if **(**int32)(__ccgo_up(bp + 16)) > 0 {
  19887 					if !(BackwardRefsWithLocalCache(tls, argb, **(**int32)(__ccgo_up(bp + 16)), refs_tmp) != 0) {
  19888 						goto Error
  19889 					}
  19890 				}
  19891 			}
  19892 			if i == 0 && do_no_cache != 0 && **(**int32)(__ccgo_up(bp + 16)) == 0 {
  19893 				// No need to re-compute bit_cost as it was computed at i == 1.
  19894 			} else {
  19895 				VP8LHistogramCreate(tls, histo, refs_tmp, **(**int32)(__ccgo_up(bp + 16)))
  19896 				bit_cost = VP8LHistogramEstimateBits(tls, histo)
  19897 			}
  19898 			if bit_cost < bit_costs_best[i] {
  19899 				if i == int32(1) {
  19900 					// Do not swap as the full cache analysis would have the wrong
  19901 					// VP8LBackwardRefs to start with.
  19902 					if !(BackwardRefsClone(tls, refs_tmp, refs+1*40) != 0) {
  19903 						goto Error
  19904 					}
  19905 				} else {
  19906 					BackwardRefsSwap(tls, refs_tmp, refs)
  19907 				}
  19908 				bit_costs_best[i] = bit_cost
  19909 				lz77_types_best[i] = lz77_type
  19910 				if i == 0 {
  19911 					**(**int32)(__ccgo_up(cache_bits_best)) = **(**int32)(__ccgo_up(bp + 16))
  19912 				}
  19913 			}
  19914 			goto _3
  19915 		_3:
  19916 			;
  19917 			i = i - 1
  19918 		}
  19919 		goto _2
  19920 	_2:
  19921 		;
  19922 		lz77_types_to_try = lz77_types_to_try & ^lz77_type
  19923 		lz77_type = lz77_type << int32(1)
  19924 	}
  19925 	// Improve on simple LZ77 but only for high quality (TraceBackwards is
  19926 	// costly).
  19927 	i = int32(1)
  19928 	for {
  19929 		if !(i >= 0) {
  19930 			break
  19931 		}
  19932 		if i == int32(1) && !(do_no_cache != 0) {
  19933 			goto _5
  19934 		}
  19935 		if (lz77_types_best[i] == int32(kLZ77Standard) || lz77_types_best[i] == int32(kLZ77Box)) && quality >= int32(25) {
  19936 			if lz77_types_best[i] == int32(kLZ77Standard) {
  19937 				v6 = hash_chain
  19938 			} else {
  19939 				v6 = bp
  19940 			}
  19941 			hash_chain_tmp = v6
  19942 			if i == int32(1) {
  19943 				v1 = 0
  19944 			} else {
  19945 				v1 = **(**int32)(__ccgo_up(cache_bits_best))
  19946 			}
  19947 			cache_bits1 = v1
  19948 			if !(VP8LBackwardReferencesTraceBackwards(tls, width, height, argb, cache_bits1, hash_chain_tmp, refs+uintptr(i)*40, refs_tmp) != 0) {
  19949 				goto Error
  19950 			}
  19951 			VP8LHistogramCreate(tls, histo, refs_tmp, cache_bits1)
  19952 			bit_cost_trace = VP8LHistogramEstimateBits(tls, histo)
  19953 			if bit_cost_trace < bit_costs_best[i] {
  19954 				BackwardRefsSwap(tls, refs_tmp, refs+uintptr(i)*40)
  19955 			}
  19956 		}
  19957 		BackwardReferences2DLocality(tls, width, refs+uintptr(i)*40)
  19958 		if i == int32(1) && lz77_types_best[0] == lz77_types_best[int32(1)] && **(**int32)(__ccgo_up(cache_bits_best)) == 0 {
  19959 			// If the best cache size is 0 and we have the same best LZ77, just copy
  19960 			// the data over and stop here.
  19961 			if !(BackwardRefsClone(tls, refs+1*40, refs) != 0) {
  19962 				goto Error
  19963 			}
  19964 			break
  19965 		}
  19966 		goto _5
  19967 	_5:
  19968 		;
  19969 		i = i - 1
  19970 	}
  19971 	status = int32(1)
  19972 	goto Error
  19973 Error:
  19974 	;
  19975 	VP8LHashChainClear(tls, bp)
  19976 	VP8LFreeHistogram(tls, histo)
  19977 	return status
  19978 }
  19979 
  19980 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) {
  19981 	var refs_best uintptr
  19982 	_ = refs_best
  19983 	if low_effort != 0 {
  19984 		**(**int32)(__ccgo_up(cache_bits_best)) = cache_bits_max
  19985 		refs_best = GetBackwardReferencesLowEffort(tls, width, height, argb, cache_bits_best, hash_chain, refs)
  19986 		if refs_best == libc.UintptrFromInt32(0) {
  19987 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19988 		}
  19989 		// Set it in first position.
  19990 		BackwardRefsSwap(tls, refs_best, refs)
  19991 	} else {
  19992 		if !(GetBackwardReferences(tls, width, height, argb, quality, lz77_types_to_try, cache_bits_max, do_no_cache, hash_chain, refs, cache_bits_best) != 0) {
  19993 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  19994 		}
  19995 	}
  19996 	return WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent)
  19997 }
  19998 
  19999 const MAX_LEVEL1 = 9
  20000 
  20001 //------------------------------------------------------------------------------
  20002 
  20003 // Copyright 2010 Google Inc. All Rights Reserved.
  20004 //
  20005 // Use of this source code is governed by a BSD-style license
  20006 // that can be found in the COPYING file in the root of the source
  20007 // tree. An additional intellectual property rights grant can be found
  20008 // in the file PATENTS. All contributing project authors may
  20009 // be found in the AUTHORS file in the root of the source tree.
  20010 // -----------------------------------------------------------------------------
  20011 //
  20012 //  Common types + memory wrappers
  20013 //
  20014 // Author: Skal (pascal.massimino@gmail.com)
  20015 
  20016 //------------------------------------------------------------------------------
  20017 // WebPConfig
  20018 //------------------------------------------------------------------------------
  20019 
  20020 func WebPConfigInitInternal(tls *libc.TLS, config uintptr, preset WebPPreset1, quality float32, version int32) (r int32) {
  20021 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  20022 		return 0 // caller/system version mismatch!
  20023 	}
  20024 	if config == libc.UintptrFromInt32(0) {
  20025 		return 0
  20026 	}
  20027 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = quality
  20028 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_size = 0
  20029 	(*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR = float32(0)
  20030 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = int32(4)
  20031 	(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(50)
  20032 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(60) // mid-filtering
  20033 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = 0
  20034 	(*WebPConfig)(unsafe.Pointer(config)).Ffilter_type = int32(1) // default: strong (so U/V is filtered too)
  20035 	(*WebPConfig)(unsafe.Pointer(config)).Fpartitions = 0
  20036 	(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(4)
  20037 	(*WebPConfig)(unsafe.Pointer(config)).Fpass = int32(1)
  20038 	(*WebPConfig)(unsafe.Pointer(config)).Fqmin = 0
  20039 	(*WebPConfig)(unsafe.Pointer(config)).Fqmax = int32(100)
  20040 	(*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed = 0
  20041 	(*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing = 0
  20042 	(*WebPConfig)(unsafe.Pointer(config)).Fautofilter = 0
  20043 	(*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit = 0
  20044 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_compression = int32(1)
  20045 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering = int32(1)
  20046 	(*WebPConfig)(unsafe.Pointer(config)).Falpha_quality = int32(100)
  20047 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = 0
  20048 	(*WebPConfig)(unsafe.Pointer(config)).Fexact = 0
  20049 	(*WebPConfig)(unsafe.Pointer(config)).Fimage_hint = int32(WEBP_HINT_DEFAULT)
  20050 	(*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size = 0
  20051 	(*WebPConfig)(unsafe.Pointer(config)).Fthread_level = 0
  20052 	(*WebPConfig)(unsafe.Pointer(config)).Flow_memory = 0
  20053 	(*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless = int32(100)
  20054 	(*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv = 0
  20055 	// TODO(skal): tune.
  20056 	switch preset {
  20057 	case int32(WEBP_PRESET_PICTURE):
  20058 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  20059 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(4)
  20060 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(35)
  20061 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20062 	case int32(WEBP_PRESET_PHOTO):
  20063 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(80)
  20064 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(3)
  20065 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(30)
  20066 		**(**int32)(__ccgo_up(config + 68)) |= int32(2)
  20067 	case int32(WEBP_PRESET_DRAWING):
  20068 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = int32(25)
  20069 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness = int32(6)
  20070 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = int32(10)
  20071 	case int32(WEBP_PRESET_ICON):
  20072 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  20073 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  20074 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20075 	case int32(WEBP_PRESET_TEXT):
  20076 		(*WebPConfig)(unsafe.Pointer(config)).Fsns_strength = 0
  20077 		(*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength = 0     // disable filtering to retain sharpness
  20078 		**(**int32)(__ccgo_up(config + 68)) &= ^libc.Int32FromInt32(2) // no dithering
  20079 		(*WebPConfig)(unsafe.Pointer(config)).Fsegments = int32(2)
  20080 	case int32(WEBP_PRESET_DEFAULT):
  20081 		fallthrough
  20082 	default:
  20083 		break
  20084 	}
  20085 	return WebPValidateConfig(tls, config)
  20086 }
  20087 
  20088 func WebPValidateConfig(tls *libc.TLS, config uintptr) (r int32) {
  20089 	if config == libc.UintptrFromInt32(0) {
  20090 		return 0
  20091 	}
  20092 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality < libc.Float32FromInt32(0) || (*WebPConfig)(unsafe.Pointer(config)).Fquality > libc.Float32FromInt32(100) {
  20093 		return 0
  20094 	}
  20095 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_size < 0 {
  20096 		return 0
  20097 	}
  20098 	if (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR < libc.Float32FromInt32(0) {
  20099 		return 0
  20100 	}
  20101 	if (*WebPConfig)(unsafe.Pointer(config)).Fmethod < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fmethod > int32(6) {
  20102 		return 0
  20103 	}
  20104 	if (*WebPConfig)(unsafe.Pointer(config)).Fsegments < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fsegments > int32(4) {
  20105 		return 0
  20106 	}
  20107 	if (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fsns_strength > int32(100) {
  20108 		return 0
  20109 	}
  20110 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > int32(100) {
  20111 		return 0
  20112 	}
  20113 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_sharpness > int32(7) {
  20114 		return 0
  20115 	}
  20116 	if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type < 0 || (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type > int32(1) {
  20117 		return 0
  20118 	}
  20119 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > int32(1) {
  20120 		return 0
  20121 	}
  20122 	if (*WebPConfig)(unsafe.Pointer(config)).Fpass < int32(1) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(10) {
  20123 		return 0
  20124 	}
  20125 	if (*WebPConfig)(unsafe.Pointer(config)).Fqmin < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fqmax > int32(100) || (*WebPConfig)(unsafe.Pointer(config)).Fqmin > (*WebPConfig)(unsafe.Pointer(config)).Fqmax {
  20126 		return 0
  20127 	}
  20128 	if (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fshow_compressed > int32(1) {
  20129 		return 0
  20130 	}
  20131 	if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing > int32(7) {
  20132 		return 0
  20133 	}
  20134 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartitions < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartitions > int32(3) {
  20135 		return 0
  20136 	}
  20137 	if (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit > int32(100) {
  20138 		return 0
  20139 	}
  20140 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_compression < 0 {
  20141 		return 0
  20142 	}
  20143 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_filtering < 0 {
  20144 		return 0
  20145 	}
  20146 	if (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality < 0 || (*WebPConfig)(unsafe.Pointer(config)).Falpha_quality > int32(100) {
  20147 		return 0
  20148 	}
  20149 	if (*WebPConfig)(unsafe.Pointer(config)).Flossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flossless > int32(1) {
  20150 		return 0
  20151 	}
  20152 	if (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless > int32(100) {
  20153 		return 0
  20154 	}
  20155 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint >= int32(WEBP_HINT_LAST) {
  20156 		return 0
  20157 	}
  20158 	if (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size < 0 || (*WebPConfig)(unsafe.Pointer(config)).Femulate_jpeg_size > int32(1) {
  20159 		return 0
  20160 	}
  20161 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > int32(1) {
  20162 		return 0
  20163 	}
  20164 	if (*WebPConfig)(unsafe.Pointer(config)).Flow_memory < 0 || (*WebPConfig)(unsafe.Pointer(config)).Flow_memory > int32(1) {
  20165 		return 0
  20166 	}
  20167 	if (*WebPConfig)(unsafe.Pointer(config)).Fexact < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fexact > int32(1) {
  20168 		return 0
  20169 	}
  20170 	if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv < 0 || (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv > int32(1) {
  20171 		return 0
  20172 	}
  20173 	return int32(1)
  20174 }
  20175 
  20176 //------------------------------------------------------------------------------
  20177 
  20178 // C documentation
  20179 //
  20180 //	// Mapping between -z level and -m / -q parameter settings.
  20181 var kLosslessPresets = [10]struct {
  20182 	Fmethod  uint8_t
  20183 	Fquality uint8_t
  20184 }{
  20185 	0: {},
  20186 	1: {
  20187 		Fmethod:  uint8(1),
  20188 		Fquality: uint8(20),
  20189 	},
  20190 	2: {
  20191 		Fmethod:  uint8(2),
  20192 		Fquality: uint8(25),
  20193 	},
  20194 	3: {
  20195 		Fmethod:  uint8(3),
  20196 		Fquality: uint8(30),
  20197 	},
  20198 	4: {
  20199 		Fmethod:  uint8(3),
  20200 		Fquality: uint8(50),
  20201 	},
  20202 	5: {
  20203 		Fmethod:  uint8(4),
  20204 		Fquality: uint8(50),
  20205 	},
  20206 	6: {
  20207 		Fmethod:  uint8(4),
  20208 		Fquality: uint8(75),
  20209 	},
  20210 	7: {
  20211 		Fmethod:  uint8(4),
  20212 		Fquality: uint8(90),
  20213 	},
  20214 	8: {
  20215 		Fmethod:  uint8(5),
  20216 		Fquality: uint8(90),
  20217 	},
  20218 	9: {
  20219 		Fmethod:  uint8(6),
  20220 		Fquality: uint8(100),
  20221 	},
  20222 }
  20223 
  20224 func WebPConfigLosslessPreset(tls *libc.TLS, config uintptr, level int32) (r int32) {
  20225 	if config == libc.UintptrFromInt32(0) || level < 0 || level > int32(MAX_LEVEL1) {
  20226 		return 0
  20227 	}
  20228 	(*WebPConfig)(unsafe.Pointer(config)).Flossless = int32(1)
  20229 	(*WebPConfig)(unsafe.Pointer(config)).Fmethod = libc.Int32FromUint8(kLosslessPresets[level].Fmethod)
  20230 	(*WebPConfig)(unsafe.Pointer(config)).Fquality = float32(kLosslessPresets[level].Fquality)
  20231 	return int32(1)
  20232 }
  20233 
  20234 type VP8Residual = struct {
  20235 	Ffirst      int32
  20236 	Flast       int32
  20237 	Fcoeffs     uintptr
  20238 	Fcoeff_type int32
  20239 	Fprob       uintptr
  20240 	Fstats      uintptr
  20241 	Fcosts      CostArrayPtr
  20242 }
  20243 
  20244 //------------------------------------------------------------------------------
  20245 
  20246 // Copyright 2011 Google Inc. All Rights Reserved.
  20247 //
  20248 // Use of this source code is governed by a BSD-style license
  20249 // that can be found in the COPYING file in the root of the source
  20250 // tree. An additional intellectual property rights grant can be found
  20251 // in the file PATENTS. All contributing project authors may
  20252 // be found in the AUTHORS file in the root of the source tree.
  20253 // -----------------------------------------------------------------------------
  20254 //
  20255 //   WebP encoder: internal header.
  20256 //
  20257 // Author: Skal (pascal.massimino@gmail.com)
  20258 
  20259 //------------------------------------------------------------------------------
  20260 // Level cost tables
  20261 
  20262 // C documentation
  20263 //
  20264 //	// For each given level, the following table gives the pattern of contexts to
  20265 //	// use for coding it (in [][0]) as well as the bit value to use for each
  20266 //	// context (in [][1]).
  20267 var VP8LevelCodes = [67][2]uint16_t{
  20268 	0: {
  20269 		0: uint16(0x001),
  20270 	},
  20271 	1: {
  20272 		0: uint16(0x007),
  20273 		1: uint16(0x001),
  20274 	},
  20275 	2: {
  20276 		0: uint16(0x00f),
  20277 		1: uint16(0x005),
  20278 	},
  20279 	3: {
  20280 		0: uint16(0x00f),
  20281 		1: uint16(0x00d),
  20282 	},
  20283 	4: {
  20284 		0: uint16(0x033),
  20285 		1: uint16(0x003),
  20286 	},
  20287 	5: {
  20288 		0: uint16(0x033),
  20289 		1: uint16(0x003),
  20290 	},
  20291 	6: {
  20292 		0: uint16(0x033),
  20293 		1: uint16(0x023),
  20294 	},
  20295 	7: {
  20296 		0: uint16(0x033),
  20297 		1: uint16(0x023),
  20298 	},
  20299 	8: {
  20300 		0: uint16(0x033),
  20301 		1: uint16(0x023),
  20302 	},
  20303 	9: {
  20304 		0: uint16(0x033),
  20305 		1: uint16(0x023),
  20306 	},
  20307 	10: {
  20308 		0: uint16(0x0d3),
  20309 		1: uint16(0x013),
  20310 	},
  20311 	11: {
  20312 		0: uint16(0x0d3),
  20313 		1: uint16(0x013),
  20314 	},
  20315 	12: {
  20316 		0: uint16(0x0d3),
  20317 		1: uint16(0x013),
  20318 	},
  20319 	13: {
  20320 		0: uint16(0x0d3),
  20321 		1: uint16(0x013),
  20322 	},
  20323 	14: {
  20324 		0: uint16(0x0d3),
  20325 		1: uint16(0x013),
  20326 	},
  20327 	15: {
  20328 		0: uint16(0x0d3),
  20329 		1: uint16(0x013),
  20330 	},
  20331 	16: {
  20332 		0: uint16(0x0d3),
  20333 		1: uint16(0x013),
  20334 	},
  20335 	17: {
  20336 		0: uint16(0x0d3),
  20337 		1: uint16(0x013),
  20338 	},
  20339 	18: {
  20340 		0: uint16(0x0d3),
  20341 		1: uint16(0x093),
  20342 	},
  20343 	19: {
  20344 		0: uint16(0x0d3),
  20345 		1: uint16(0x093),
  20346 	},
  20347 	20: {
  20348 		0: uint16(0x0d3),
  20349 		1: uint16(0x093),
  20350 	},
  20351 	21: {
  20352 		0: uint16(0x0d3),
  20353 		1: uint16(0x093),
  20354 	},
  20355 	22: {
  20356 		0: uint16(0x0d3),
  20357 		1: uint16(0x093),
  20358 	},
  20359 	23: {
  20360 		0: uint16(0x0d3),
  20361 		1: uint16(0x093),
  20362 	},
  20363 	24: {
  20364 		0: uint16(0x0d3),
  20365 		1: uint16(0x093),
  20366 	},
  20367 	25: {
  20368 		0: uint16(0x0d3),
  20369 		1: uint16(0x093),
  20370 	},
  20371 	26: {
  20372 		0: uint16(0x0d3),
  20373 		1: uint16(0x093),
  20374 	},
  20375 	27: {
  20376 		0: uint16(0x0d3),
  20377 		1: uint16(0x093),
  20378 	},
  20379 	28: {
  20380 		0: uint16(0x0d3),
  20381 		1: uint16(0x093),
  20382 	},
  20383 	29: {
  20384 		0: uint16(0x0d3),
  20385 		1: uint16(0x093),
  20386 	},
  20387 	30: {
  20388 		0: uint16(0x0d3),
  20389 		1: uint16(0x093),
  20390 	},
  20391 	31: {
  20392 		0: uint16(0x0d3),
  20393 		1: uint16(0x093),
  20394 	},
  20395 	32: {
  20396 		0: uint16(0x0d3),
  20397 		1: uint16(0x093),
  20398 	},
  20399 	33: {
  20400 		0: uint16(0x0d3),
  20401 		1: uint16(0x093),
  20402 	},
  20403 	34: {
  20404 		0: uint16(0x153),
  20405 		1: uint16(0x053),
  20406 	},
  20407 	35: {
  20408 		0: uint16(0x153),
  20409 		1: uint16(0x053),
  20410 	},
  20411 	36: {
  20412 		0: uint16(0x153),
  20413 		1: uint16(0x053),
  20414 	},
  20415 	37: {
  20416 		0: uint16(0x153),
  20417 		1: uint16(0x053),
  20418 	},
  20419 	38: {
  20420 		0: uint16(0x153),
  20421 		1: uint16(0x053),
  20422 	},
  20423 	39: {
  20424 		0: uint16(0x153),
  20425 		1: uint16(0x053),
  20426 	},
  20427 	40: {
  20428 		0: uint16(0x153),
  20429 		1: uint16(0x053),
  20430 	},
  20431 	41: {
  20432 		0: uint16(0x153),
  20433 		1: uint16(0x053),
  20434 	},
  20435 	42: {
  20436 		0: uint16(0x153),
  20437 		1: uint16(0x053),
  20438 	},
  20439 	43: {
  20440 		0: uint16(0x153),
  20441 		1: uint16(0x053),
  20442 	},
  20443 	44: {
  20444 		0: uint16(0x153),
  20445 		1: uint16(0x053),
  20446 	},
  20447 	45: {
  20448 		0: uint16(0x153),
  20449 		1: uint16(0x053),
  20450 	},
  20451 	46: {
  20452 		0: uint16(0x153),
  20453 		1: uint16(0x053),
  20454 	},
  20455 	47: {
  20456 		0: uint16(0x153),
  20457 		1: uint16(0x053),
  20458 	},
  20459 	48: {
  20460 		0: uint16(0x153),
  20461 		1: uint16(0x053),
  20462 	},
  20463 	49: {
  20464 		0: uint16(0x153),
  20465 		1: uint16(0x053),
  20466 	},
  20467 	50: {
  20468 		0: uint16(0x153),
  20469 		1: uint16(0x053),
  20470 	},
  20471 	51: {
  20472 		0: uint16(0x153),
  20473 		1: uint16(0x053),
  20474 	},
  20475 	52: {
  20476 		0: uint16(0x153),
  20477 		1: uint16(0x053),
  20478 	},
  20479 	53: {
  20480 		0: uint16(0x153),
  20481 		1: uint16(0x053),
  20482 	},
  20483 	54: {
  20484 		0: uint16(0x153),
  20485 		1: uint16(0x053),
  20486 	},
  20487 	55: {
  20488 		0: uint16(0x153),
  20489 		1: uint16(0x053),
  20490 	},
  20491 	56: {
  20492 		0: uint16(0x153),
  20493 		1: uint16(0x053),
  20494 	},
  20495 	57: {
  20496 		0: uint16(0x153),
  20497 		1: uint16(0x053),
  20498 	},
  20499 	58: {
  20500 		0: uint16(0x153),
  20501 		1: uint16(0x053),
  20502 	},
  20503 	59: {
  20504 		0: uint16(0x153),
  20505 		1: uint16(0x053),
  20506 	},
  20507 	60: {
  20508 		0: uint16(0x153),
  20509 		1: uint16(0x053),
  20510 	},
  20511 	61: {
  20512 		0: uint16(0x153),
  20513 		1: uint16(0x053),
  20514 	},
  20515 	62: {
  20516 		0: uint16(0x153),
  20517 		1: uint16(0x053),
  20518 	},
  20519 	63: {
  20520 		0: uint16(0x153),
  20521 		1: uint16(0x053),
  20522 	},
  20523 	64: {
  20524 		0: uint16(0x153),
  20525 		1: uint16(0x053),
  20526 	},
  20527 	65: {
  20528 		0: uint16(0x153),
  20529 		1: uint16(0x053),
  20530 	},
  20531 	66: {
  20532 		0: uint16(0x153),
  20533 		1: uint16(0x153),
  20534 	},
  20535 }
  20536 
  20537 func VariableLevelCost(tls *libc.TLS, level int32, probas uintptr) (r int32) {
  20538 	var bits, cost, i, pattern, v3, v5 int32
  20539 	var v2 uint8_t
  20540 	_, _, _, _, _, _, _ = bits, cost, i, pattern, v2, v3, v5
  20541 	pattern = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4)))
  20542 	bits = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(level-int32(1))*4 + 1*2)))
  20543 	cost = 0
  20544 	i = int32(2)
  20545 	for {
  20546 		if !(pattern != 0) {
  20547 			break
  20548 		}
  20549 		if pattern&int32(1) != 0 {
  20550 			v2 = **(**uint8_t)(__ccgo_up(probas + uintptr(i)))
  20551 			if !(bits&int32(1) != 0) {
  20552 				v5 = libc.Int32FromUint16(VP8EntropyCost[v2])
  20553 			} else {
  20554 				v5 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v2)])
  20555 			}
  20556 			v3 = v5
  20557 			goto _4
  20558 		_4:
  20559 			cost = cost + v3
  20560 		}
  20561 		bits = bits >> int32(1)
  20562 		pattern = pattern >> int32(1)
  20563 		goto _1
  20564 	_1:
  20565 		;
  20566 		i = i + 1
  20567 	}
  20568 	return cost
  20569 }
  20570 
  20571 //------------------------------------------------------------------------------
  20572 // Pre-calc level costs once for all
  20573 
  20574 func VP8CalculateLevelCosts(tls *libc.TLS, proba1 uintptr) {
  20575 	var band, cost0, cost_base, ctx, ctype, n, v, v10, v12, v14, v16, v4, v6, v8 int32
  20576 	var p, table uintptr
  20577 	var v13, v5, v9 uint8_t
  20578 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = band, cost0, cost_base, ctx, ctype, n, p, table, v, v10, v12, v13, v14, v16, v4, v5, v6, v8, v9
  20579 	if !((*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty != 0) {
  20580 		return
  20581 	} // nothing to do.
  20582 	ctype = 0
  20583 	for {
  20584 		if !(ctype < int32(NUM_TYPES)) {
  20585 			break
  20586 		}
  20587 		band = 0
  20588 		for {
  20589 			if !(band < int32(NUM_BANDS)) {
  20590 				break
  20591 			}
  20592 			ctx = 0
  20593 			for {
  20594 				if !(ctx < int32(NUM_CTX)) {
  20595 					break
  20596 				}
  20597 				p = proba1 + 4 + uintptr(ctype)*264 + uintptr(band)*33 + uintptr(ctx)*11
  20598 				table = proba1 + 5284 + uintptr(ctype)*3264 + uintptr(band)*408 + uintptr(ctx)*136
  20599 				if ctx > 0 {
  20600 					v5 = **(**uint8_t)(__ccgo_up(p))
  20601 					if !(int32(1) != 0) {
  20602 						v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  20603 					} else {
  20604 						v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  20605 					}
  20606 					v6 = v8
  20607 					goto _7
  20608 				_7:
  20609 					v4 = v6
  20610 				} else {
  20611 					v4 = 0
  20612 				}
  20613 				cost0 = v4
  20614 				v9 = **(**uint8_t)(__ccgo_up(p + 1))
  20615 				if !(int32(1) != 0) {
  20616 					v12 = libc.Int32FromUint16(VP8EntropyCost[v9])
  20617 				} else {
  20618 					v12 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v9)])
  20619 				}
  20620 				v10 = v12
  20621 				goto _11
  20622 			_11:
  20623 				cost_base = v10 + cost0
  20624 				v13 = **(**uint8_t)(__ccgo_up(p + 1))
  20625 				if !(0 != 0) {
  20626 					v16 = libc.Int32FromUint16(VP8EntropyCost[v13])
  20627 				} else {
  20628 					v16 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v13)])
  20629 				}
  20630 				v14 = v16
  20631 				goto _15
  20632 			_15:
  20633 				**(**uint16_t)(__ccgo_up(table)) = libc.Uint16FromInt32(v14 + cost0)
  20634 				v = int32(1)
  20635 				for {
  20636 					if !(v <= int32(MAX_VARIABLE_LEVEL)) {
  20637 						break
  20638 					}
  20639 					**(**uint16_t)(__ccgo_up(table + uintptr(v)*2)) = libc.Uint16FromInt32(cost_base + VariableLevelCost(tls, v, p))
  20640 					goto _17
  20641 				_17:
  20642 					;
  20643 					v = v + 1
  20644 				}
  20645 				// Starting at level 67 and up, the variable part of the cost is
  20646 				// actually constant.
  20647 				goto _3
  20648 			_3:
  20649 				;
  20650 				ctx = ctx + 1
  20651 			}
  20652 			goto _2
  20653 		_2:
  20654 			;
  20655 			band = band + 1
  20656 		}
  20657 		n = 0
  20658 		for {
  20659 			if !(n < int32(16)) {
  20660 				break
  20661 			} // replicate bands. We don't need to sentinel.
  20662 			ctx = 0
  20663 			for {
  20664 				if !(ctx < int32(NUM_CTX)) {
  20665 					break
  20666 				}
  20667 				**(**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
  20668 				goto _19
  20669 			_19:
  20670 				;
  20671 				ctx = ctx + 1
  20672 			}
  20673 			goto _18
  20674 		_18:
  20675 			;
  20676 			n = n + 1
  20677 		}
  20678 		goto _1
  20679 	_1:
  20680 		;
  20681 		ctype = ctype + 1
  20682 	}
  20683 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = 0
  20684 }
  20685 
  20686 //------------------------------------------------------------------------------
  20687 // helper functions for residuals struct VP8Residual.
  20688 
  20689 func VP8InitResidual(tls *libc.TLS, first int32, coeff_type int32, enc uintptr, res uintptr) {
  20690 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type = coeff_type
  20691 	(*VP8Residual)(unsafe.Pointer(res)).Fprob = enc + 3616 + 4 + uintptr(coeff_type)*264
  20692 	(*VP8Residual)(unsafe.Pointer(res)).Fstats = enc + 3616 + 1060 + uintptr(coeff_type)*1056
  20693 	(*VP8Residual)(unsafe.Pointer(res)).Fcosts = enc + 3616 + 18344 + uintptr(coeff_type)*384
  20694 	(*VP8Residual)(unsafe.Pointer(res)).Ffirst = first
  20695 }
  20696 
  20697 //------------------------------------------------------------------------------
  20698 // Mode costs
  20699 
  20700 func VP8GetCostLuma4(tls *libc.TLS, it uintptr, levels uintptr) (r int32) {
  20701 	bp := tls.Alloc(48)
  20702 	defer tls.Free(48)
  20703 	var R, ctx, x, y int32
  20704 	var enc uintptr
  20705 	var _ /* res at bp+0 */ VP8Residual
  20706 	_, _, _, _, _ = R, ctx, enc, x, y
  20707 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  20708 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> libc.Int32FromInt32(2)
  20709 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20710 	R = 0
  20711 	VP8InitResidual(tls, 0, int32(3), enc, bp)
  20712 	ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20713 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, levels, bp)
  20714 	R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20715 	return R
  20716 }
  20717 
  20718 func VP8GetCostLuma16(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20719 	bp := tls.Alloc(48)
  20720 	defer tls.Free(48)
  20721 	var R, ctx, x, y, v3 int32
  20722 	var enc uintptr
  20723 	var _ /* res at bp+0 */ VP8Residual
  20724 	_, _, _, _, _, _ = R, ctx, enc, x, y, v3
  20725 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20726 	R = 0
  20727 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20728 	// DC
  20729 	VP8InitResidual(tls, 0, int32(1), enc, bp)
  20730 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  20731 	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)
  20732 	// AC
  20733 	VP8InitResidual(tls, int32(1), 0, enc, bp)
  20734 	y = 0
  20735 	for {
  20736 		if !(y < int32(4)) {
  20737 			break
  20738 		}
  20739 		x = 0
  20740 		for {
  20741 			if !(x < int32(4)) {
  20742 				break
  20743 			}
  20744 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  20745 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  20746 			R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20747 			v3 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20748 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v3
  20749 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v3
  20750 			goto _2
  20751 		_2:
  20752 			;
  20753 			x = x + 1
  20754 		}
  20755 		goto _1
  20756 	_1:
  20757 		;
  20758 		y = y + 1
  20759 	}
  20760 	return R
  20761 }
  20762 
  20763 func VP8GetCostUV(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  20764 	bp := tls.Alloc(48)
  20765 	defer tls.Free(48)
  20766 	var R, ch, ctx, x, y, v4 int32
  20767 	var enc uintptr
  20768 	var _ /* res at bp+0 */ VP8Residual
  20769 	_, _, _, _, _, _, _ = R, ch, ctx, enc, x, y, v4
  20770 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  20771 	R = 0
  20772 	VP8IteratorNzToBytes(tls, it) // re-import the non-zero context
  20773 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  20774 	ch = 0
  20775 	for {
  20776 		if !(ch <= int32(2)) {
  20777 			break
  20778 		}
  20779 		y = 0
  20780 		for {
  20781 			if !(y < int32(2)) {
  20782 				break
  20783 			}
  20784 			x = 0
  20785 			for {
  20786 				if !(x < int32(2)) {
  20787 					break
  20788 				}
  20789 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  20790 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  20791 				R = R + (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8GetResidualCost})))(tls, ctx, bp)
  20792 				v4 = libc.BoolInt32((**(**VP8Residual)(__ccgo_up(bp))).Flast >= libc.Int32FromInt32(0))
  20793 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  20794 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  20795 				goto _3
  20796 			_3:
  20797 				;
  20798 				x = x + 1
  20799 			}
  20800 			goto _2
  20801 		_2:
  20802 			;
  20803 			y = y + 1
  20804 		}
  20805 		goto _1
  20806 	_1:
  20807 		;
  20808 		ch = ch + int32(2)
  20809 	}
  20810 	return R
  20811 }
  20812 
  20813 //------------------------------------------------------------------------------
  20814 // Recording of token probabilities.
  20815 
  20816 // We keep the table-free variant around for reference, in case.
  20817 
  20818 // C documentation
  20819 //
  20820 //	// Simulate block coding, but only record statistics.
  20821 //	// Note: no need to record the fixed probas.
  20822 func VP8RecordCoeffs(tls *libc.TLS, ctx int32, res uintptr) (r int32) {
  20823 	var bits, i, mask, n, pattern, v, v1, v4, v7 int32
  20824 	var p proba_t
  20825 	var s, v2 uintptr
  20826 	_, _, _, _, _, _, _, _, _, _, _, _ = bits, i, mask, n, p, pattern, s, v, v1, v2, v4, v7
  20827 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  20828 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  20829 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  20830 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  20831 		v1 = 0
  20832 		v2 = s + uintptr(0)*4
  20833 		p = **(**proba_t)(__ccgo_up(v2))
  20834 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20835 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20836 		}
  20837 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20838 		**(**proba_t)(__ccgo_up(v2)) = p
  20839 		_ = v1
  20840 		goto _3
  20841 	_3:
  20842 		;
  20843 		return 0
  20844 	}
  20845 	for n <= (*VP8Residual)(unsafe.Pointer(res)).Flast {
  20846 		v1 = int32(1)
  20847 		v2 = s + uintptr(0)*4
  20848 		p = **(**proba_t)(__ccgo_up(v2))
  20849 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20850 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20851 		}
  20852 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20853 		**(**proba_t)(__ccgo_up(v2)) = p
  20854 		_ = v1
  20855 		goto _6
  20856 	_6:
  20857 		; // order of record doesn't matter
  20858 		for {
  20859 			v4 = n
  20860 			n = n + 1
  20861 			v1 = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v4)*2)))
  20862 			v = v1
  20863 			if !(v1 == 0) {
  20864 				break
  20865 			}
  20866 			v7 = 0
  20867 			v2 = s + uintptr(1)*4
  20868 			p = **(**proba_t)(__ccgo_up(v2))
  20869 			if p >= libc.Uint32FromUint32(0xfffe0000) {
  20870 				p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20871 			}
  20872 			p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v7))
  20873 			**(**proba_t)(__ccgo_up(v2)) = p
  20874 			_ = v7
  20875 			goto _11
  20876 		_11:
  20877 			;
  20878 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  20879 		}
  20880 		v1 = int32(1)
  20881 		v2 = s + uintptr(1)*4
  20882 		p = **(**proba_t)(__ccgo_up(v2))
  20883 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20884 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20885 		}
  20886 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20887 		**(**proba_t)(__ccgo_up(v2)) = p
  20888 		_ = v1
  20889 		goto _14
  20890 	_14:
  20891 		;
  20892 		v1 = libc.BoolInt32(uint32(2) < libc.Uint32FromInt32(v+libc.Int32FromInt32(1)))
  20893 		v2 = s + uintptr(2)*4
  20894 		p = **(**proba_t)(__ccgo_up(v2))
  20895 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20896 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20897 		}
  20898 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20899 		**(**proba_t)(__ccgo_up(v2)) = p
  20900 		v4 = v1
  20901 		goto _18
  20902 	_18:
  20903 		if !(v4 != 0) { // v = -1 or 1
  20904 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  20905 		} else {
  20906 			v = libc.Xabs(tls, v)
  20907 			if v > int32(MAX_VARIABLE_LEVEL) {
  20908 				v = int32(MAX_VARIABLE_LEVEL)
  20909 			}
  20910 			bits = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4 + 1*2)))
  20911 			pattern = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8LevelCodes)) + uintptr(v-int32(1))*4)))
  20912 			i = 0
  20913 			for {
  20914 				pattern = pattern >> int32(1)
  20915 				if !(pattern != 0) {
  20916 					break
  20917 				}
  20918 				mask = int32(2) << i
  20919 				if pattern&int32(1) != 0 {
  20920 					v1 = libc.BoolInt32(!!(bits&mask != 0))
  20921 					v2 = s + uintptr(3)*4 + uintptr(i)*4
  20922 					p = **(**proba_t)(__ccgo_up(v2))
  20923 					if p >= libc.Uint32FromUint32(0xfffe0000) {
  20924 						p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20925 					}
  20926 					p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20927 					**(**proba_t)(__ccgo_up(v2)) = p
  20928 					_ = v1
  20929 					goto _22
  20930 				_22:
  20931 				}
  20932 				goto _19
  20933 			_19:
  20934 				;
  20935 				i = i + 1
  20936 			}
  20937 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  20938 		}
  20939 	}
  20940 	if n < int32(16) {
  20941 		v1 = 0
  20942 		v2 = s + uintptr(0)*4
  20943 		p = **(**proba_t)(__ccgo_up(v2))
  20944 		if p >= libc.Uint32FromUint32(0xfffe0000) {
  20945 			p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  20946 		}
  20947 		p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  20948 		**(**proba_t)(__ccgo_up(v2)) = p
  20949 		_ = v1
  20950 		goto _25
  20951 	_25:
  20952 	}
  20953 	return int32(1)
  20954 }
  20955 
  20956 const MAX_DELTA_SIZE = 64
  20957 
  20958 //------------------------------------------------------------------------------
  20959 
  20960 // C documentation
  20961 //
  20962 //	// This table gives, for a given sharpness, the filtering strength to be
  20963 //	// used (at least) in order to filter a given edge step delta.
  20964 //	// This is constructed by brute force inspection: for all delta, we iterate
  20965 //	// over all possible filtering strength / thresh until needs_filter() returns
  20966 //	// true.
  20967 var kLevelsFromDelta = [8][64]uint8_t{
  20968 	0: {
  20969 		1:  uint8(1),
  20970 		2:  uint8(2),
  20971 		3:  uint8(3),
  20972 		4:  uint8(4),
  20973 		5:  uint8(5),
  20974 		6:  uint8(6),
  20975 		7:  uint8(7),
  20976 		8:  uint8(8),
  20977 		9:  uint8(9),
  20978 		10: uint8(10),
  20979 		11: uint8(11),
  20980 		12: uint8(12),
  20981 		13: uint8(13),
  20982 		14: uint8(14),
  20983 		15: uint8(15),
  20984 		16: uint8(16),
  20985 		17: uint8(17),
  20986 		18: uint8(18),
  20987 		19: uint8(19),
  20988 		20: uint8(20),
  20989 		21: uint8(21),
  20990 		22: uint8(22),
  20991 		23: uint8(23),
  20992 		24: uint8(24),
  20993 		25: uint8(25),
  20994 		26: uint8(26),
  20995 		27: uint8(27),
  20996 		28: uint8(28),
  20997 		29: uint8(29),
  20998 		30: uint8(30),
  20999 		31: uint8(31),
  21000 		32: uint8(32),
  21001 		33: uint8(33),
  21002 		34: uint8(34),
  21003 		35: uint8(35),
  21004 		36: uint8(36),
  21005 		37: uint8(37),
  21006 		38: uint8(38),
  21007 		39: uint8(39),
  21008 		40: uint8(40),
  21009 		41: uint8(41),
  21010 		42: uint8(42),
  21011 		43: uint8(43),
  21012 		44: uint8(44),
  21013 		45: uint8(45),
  21014 		46: uint8(46),
  21015 		47: uint8(47),
  21016 		48: uint8(48),
  21017 		49: uint8(49),
  21018 		50: uint8(50),
  21019 		51: uint8(51),
  21020 		52: uint8(52),
  21021 		53: uint8(53),
  21022 		54: uint8(54),
  21023 		55: uint8(55),
  21024 		56: uint8(56),
  21025 		57: uint8(57),
  21026 		58: uint8(58),
  21027 		59: uint8(59),
  21028 		60: uint8(60),
  21029 		61: uint8(61),
  21030 		62: uint8(62),
  21031 		63: uint8(63),
  21032 	},
  21033 	1: {
  21034 		1:  uint8(1),
  21035 		2:  uint8(2),
  21036 		3:  uint8(3),
  21037 		4:  uint8(5),
  21038 		5:  uint8(6),
  21039 		6:  uint8(7),
  21040 		7:  uint8(8),
  21041 		8:  uint8(9),
  21042 		9:  uint8(11),
  21043 		10: uint8(12),
  21044 		11: uint8(13),
  21045 		12: uint8(14),
  21046 		13: uint8(15),
  21047 		14: uint8(17),
  21048 		15: uint8(18),
  21049 		16: uint8(20),
  21050 		17: uint8(21),
  21051 		18: uint8(23),
  21052 		19: uint8(24),
  21053 		20: uint8(26),
  21054 		21: uint8(27),
  21055 		22: uint8(29),
  21056 		23: uint8(30),
  21057 		24: uint8(32),
  21058 		25: uint8(33),
  21059 		26: uint8(35),
  21060 		27: uint8(36),
  21061 		28: uint8(38),
  21062 		29: uint8(39),
  21063 		30: uint8(41),
  21064 		31: uint8(42),
  21065 		32: uint8(44),
  21066 		33: uint8(45),
  21067 		34: uint8(47),
  21068 		35: uint8(48),
  21069 		36: uint8(50),
  21070 		37: uint8(51),
  21071 		38: uint8(53),
  21072 		39: uint8(54),
  21073 		40: uint8(56),
  21074 		41: uint8(57),
  21075 		42: uint8(59),
  21076 		43: uint8(60),
  21077 		44: uint8(62),
  21078 		45: uint8(63),
  21079 		46: uint8(63),
  21080 		47: uint8(63),
  21081 		48: uint8(63),
  21082 		49: uint8(63),
  21083 		50: uint8(63),
  21084 		51: uint8(63),
  21085 		52: uint8(63),
  21086 		53: uint8(63),
  21087 		54: uint8(63),
  21088 		55: uint8(63),
  21089 		56: uint8(63),
  21090 		57: uint8(63),
  21091 		58: uint8(63),
  21092 		59: uint8(63),
  21093 		60: uint8(63),
  21094 		61: uint8(63),
  21095 		62: uint8(63),
  21096 		63: uint8(63),
  21097 	},
  21098 	2: {
  21099 		1:  uint8(1),
  21100 		2:  uint8(2),
  21101 		3:  uint8(3),
  21102 		4:  uint8(5),
  21103 		5:  uint8(6),
  21104 		6:  uint8(7),
  21105 		7:  uint8(8),
  21106 		8:  uint8(9),
  21107 		9:  uint8(11),
  21108 		10: uint8(12),
  21109 		11: uint8(13),
  21110 		12: uint8(14),
  21111 		13: uint8(16),
  21112 		14: uint8(17),
  21113 		15: uint8(19),
  21114 		16: uint8(20),
  21115 		17: uint8(22),
  21116 		18: uint8(23),
  21117 		19: uint8(25),
  21118 		20: uint8(26),
  21119 		21: uint8(28),
  21120 		22: uint8(29),
  21121 		23: uint8(31),
  21122 		24: uint8(32),
  21123 		25: uint8(34),
  21124 		26: uint8(35),
  21125 		27: uint8(37),
  21126 		28: uint8(38),
  21127 		29: uint8(40),
  21128 		30: uint8(41),
  21129 		31: uint8(43),
  21130 		32: uint8(44),
  21131 		33: uint8(46),
  21132 		34: uint8(47),
  21133 		35: uint8(49),
  21134 		36: uint8(50),
  21135 		37: uint8(52),
  21136 		38: uint8(53),
  21137 		39: uint8(55),
  21138 		40: uint8(56),
  21139 		41: uint8(58),
  21140 		42: uint8(59),
  21141 		43: uint8(61),
  21142 		44: uint8(62),
  21143 		45: uint8(63),
  21144 		46: uint8(63),
  21145 		47: uint8(63),
  21146 		48: uint8(63),
  21147 		49: uint8(63),
  21148 		50: uint8(63),
  21149 		51: uint8(63),
  21150 		52: uint8(63),
  21151 		53: uint8(63),
  21152 		54: uint8(63),
  21153 		55: uint8(63),
  21154 		56: uint8(63),
  21155 		57: uint8(63),
  21156 		58: uint8(63),
  21157 		59: uint8(63),
  21158 		60: uint8(63),
  21159 		61: uint8(63),
  21160 		62: uint8(63),
  21161 		63: uint8(63),
  21162 	},
  21163 	3: {
  21164 		1:  uint8(1),
  21165 		2:  uint8(2),
  21166 		3:  uint8(3),
  21167 		4:  uint8(5),
  21168 		5:  uint8(6),
  21169 		6:  uint8(7),
  21170 		7:  uint8(8),
  21171 		8:  uint8(9),
  21172 		9:  uint8(11),
  21173 		10: uint8(12),
  21174 		11: uint8(13),
  21175 		12: uint8(15),
  21176 		13: uint8(16),
  21177 		14: uint8(18),
  21178 		15: uint8(19),
  21179 		16: uint8(21),
  21180 		17: uint8(22),
  21181 		18: uint8(24),
  21182 		19: uint8(25),
  21183 		20: uint8(27),
  21184 		21: uint8(28),
  21185 		22: uint8(30),
  21186 		23: uint8(31),
  21187 		24: uint8(33),
  21188 		25: uint8(34),
  21189 		26: uint8(36),
  21190 		27: uint8(37),
  21191 		28: uint8(39),
  21192 		29: uint8(40),
  21193 		30: uint8(42),
  21194 		31: uint8(43),
  21195 		32: uint8(45),
  21196 		33: uint8(46),
  21197 		34: uint8(48),
  21198 		35: uint8(49),
  21199 		36: uint8(51),
  21200 		37: uint8(52),
  21201 		38: uint8(54),
  21202 		39: uint8(55),
  21203 		40: uint8(57),
  21204 		41: uint8(58),
  21205 		42: uint8(60),
  21206 		43: uint8(61),
  21207 		44: uint8(63),
  21208 		45: uint8(63),
  21209 		46: uint8(63),
  21210 		47: uint8(63),
  21211 		48: uint8(63),
  21212 		49: uint8(63),
  21213 		50: uint8(63),
  21214 		51: uint8(63),
  21215 		52: uint8(63),
  21216 		53: uint8(63),
  21217 		54: uint8(63),
  21218 		55: uint8(63),
  21219 		56: uint8(63),
  21220 		57: uint8(63),
  21221 		58: uint8(63),
  21222 		59: uint8(63),
  21223 		60: uint8(63),
  21224 		61: uint8(63),
  21225 		62: uint8(63),
  21226 		63: uint8(63),
  21227 	},
  21228 	4: {
  21229 		1:  uint8(1),
  21230 		2:  uint8(2),
  21231 		3:  uint8(3),
  21232 		4:  uint8(5),
  21233 		5:  uint8(6),
  21234 		6:  uint8(7),
  21235 		7:  uint8(8),
  21236 		8:  uint8(9),
  21237 		9:  uint8(11),
  21238 		10: uint8(12),
  21239 		11: uint8(14),
  21240 		12: uint8(15),
  21241 		13: uint8(17),
  21242 		14: uint8(18),
  21243 		15: uint8(20),
  21244 		16: uint8(21),
  21245 		17: uint8(23),
  21246 		18: uint8(24),
  21247 		19: uint8(26),
  21248 		20: uint8(27),
  21249 		21: uint8(29),
  21250 		22: uint8(30),
  21251 		23: uint8(32),
  21252 		24: uint8(33),
  21253 		25: uint8(35),
  21254 		26: uint8(36),
  21255 		27: uint8(38),
  21256 		28: uint8(39),
  21257 		29: uint8(41),
  21258 		30: uint8(42),
  21259 		31: uint8(44),
  21260 		32: uint8(45),
  21261 		33: uint8(47),
  21262 		34: uint8(48),
  21263 		35: uint8(50),
  21264 		36: uint8(51),
  21265 		37: uint8(53),
  21266 		38: uint8(54),
  21267 		39: uint8(56),
  21268 		40: uint8(57),
  21269 		41: uint8(59),
  21270 		42: uint8(60),
  21271 		43: uint8(62),
  21272 		44: uint8(63),
  21273 		45: uint8(63),
  21274 		46: uint8(63),
  21275 		47: uint8(63),
  21276 		48: uint8(63),
  21277 		49: uint8(63),
  21278 		50: uint8(63),
  21279 		51: uint8(63),
  21280 		52: uint8(63),
  21281 		53: uint8(63),
  21282 		54: uint8(63),
  21283 		55: uint8(63),
  21284 		56: uint8(63),
  21285 		57: uint8(63),
  21286 		58: uint8(63),
  21287 		59: uint8(63),
  21288 		60: uint8(63),
  21289 		61: uint8(63),
  21290 		62: uint8(63),
  21291 		63: uint8(63),
  21292 	},
  21293 	5: {
  21294 		1:  uint8(1),
  21295 		2:  uint8(2),
  21296 		3:  uint8(4),
  21297 		4:  uint8(5),
  21298 		5:  uint8(7),
  21299 		6:  uint8(8),
  21300 		7:  uint8(9),
  21301 		8:  uint8(11),
  21302 		9:  uint8(12),
  21303 		10: uint8(13),
  21304 		11: uint8(15),
  21305 		12: uint8(16),
  21306 		13: uint8(17),
  21307 		14: uint8(19),
  21308 		15: uint8(20),
  21309 		16: uint8(22),
  21310 		17: uint8(23),
  21311 		18: uint8(25),
  21312 		19: uint8(26),
  21313 		20: uint8(28),
  21314 		21: uint8(29),
  21315 		22: uint8(31),
  21316 		23: uint8(32),
  21317 		24: uint8(34),
  21318 		25: uint8(35),
  21319 		26: uint8(37),
  21320 		27: uint8(38),
  21321 		28: uint8(40),
  21322 		29: uint8(41),
  21323 		30: uint8(43),
  21324 		31: uint8(44),
  21325 		32: uint8(46),
  21326 		33: uint8(47),
  21327 		34: uint8(49),
  21328 		35: uint8(50),
  21329 		36: uint8(52),
  21330 		37: uint8(53),
  21331 		38: uint8(55),
  21332 		39: uint8(56),
  21333 		40: uint8(58),
  21334 		41: uint8(59),
  21335 		42: uint8(61),
  21336 		43: uint8(62),
  21337 		44: uint8(63),
  21338 		45: uint8(63),
  21339 		46: uint8(63),
  21340 		47: uint8(63),
  21341 		48: uint8(63),
  21342 		49: uint8(63),
  21343 		50: uint8(63),
  21344 		51: uint8(63),
  21345 		52: uint8(63),
  21346 		53: uint8(63),
  21347 		54: uint8(63),
  21348 		55: uint8(63),
  21349 		56: uint8(63),
  21350 		57: uint8(63),
  21351 		58: uint8(63),
  21352 		59: uint8(63),
  21353 		60: uint8(63),
  21354 		61: uint8(63),
  21355 		62: uint8(63),
  21356 		63: uint8(63),
  21357 	},
  21358 	6: {
  21359 		1:  uint8(1),
  21360 		2:  uint8(2),
  21361 		3:  uint8(4),
  21362 		4:  uint8(5),
  21363 		5:  uint8(7),
  21364 		6:  uint8(8),
  21365 		7:  uint8(9),
  21366 		8:  uint8(11),
  21367 		9:  uint8(12),
  21368 		10: uint8(13),
  21369 		11: uint8(15),
  21370 		12: uint8(16),
  21371 		13: uint8(18),
  21372 		14: uint8(19),
  21373 		15: uint8(21),
  21374 		16: uint8(22),
  21375 		17: uint8(24),
  21376 		18: uint8(25),
  21377 		19: uint8(27),
  21378 		20: uint8(28),
  21379 		21: uint8(30),
  21380 		22: uint8(31),
  21381 		23: uint8(33),
  21382 		24: uint8(34),
  21383 		25: uint8(36),
  21384 		26: uint8(37),
  21385 		27: uint8(39),
  21386 		28: uint8(40),
  21387 		29: uint8(42),
  21388 		30: uint8(43),
  21389 		31: uint8(45),
  21390 		32: uint8(46),
  21391 		33: uint8(48),
  21392 		34: uint8(49),
  21393 		35: uint8(51),
  21394 		36: uint8(52),
  21395 		37: uint8(54),
  21396 		38: uint8(55),
  21397 		39: uint8(57),
  21398 		40: uint8(58),
  21399 		41: uint8(60),
  21400 		42: uint8(61),
  21401 		43: uint8(63),
  21402 		44: uint8(63),
  21403 		45: uint8(63),
  21404 		46: uint8(63),
  21405 		47: uint8(63),
  21406 		48: uint8(63),
  21407 		49: uint8(63),
  21408 		50: uint8(63),
  21409 		51: uint8(63),
  21410 		52: uint8(63),
  21411 		53: uint8(63),
  21412 		54: uint8(63),
  21413 		55: uint8(63),
  21414 		56: uint8(63),
  21415 		57: uint8(63),
  21416 		58: uint8(63),
  21417 		59: uint8(63),
  21418 		60: uint8(63),
  21419 		61: uint8(63),
  21420 		62: uint8(63),
  21421 		63: uint8(63),
  21422 	},
  21423 	7: {
  21424 		1:  uint8(1),
  21425 		2:  uint8(2),
  21426 		3:  uint8(4),
  21427 		4:  uint8(5),
  21428 		5:  uint8(7),
  21429 		6:  uint8(8),
  21430 		7:  uint8(9),
  21431 		8:  uint8(11),
  21432 		9:  uint8(12),
  21433 		10: uint8(14),
  21434 		11: uint8(15),
  21435 		12: uint8(17),
  21436 		13: uint8(18),
  21437 		14: uint8(20),
  21438 		15: uint8(21),
  21439 		16: uint8(23),
  21440 		17: uint8(24),
  21441 		18: uint8(26),
  21442 		19: uint8(27),
  21443 		20: uint8(29),
  21444 		21: uint8(30),
  21445 		22: uint8(32),
  21446 		23: uint8(33),
  21447 		24: uint8(35),
  21448 		25: uint8(36),
  21449 		26: uint8(38),
  21450 		27: uint8(39),
  21451 		28: uint8(41),
  21452 		29: uint8(42),
  21453 		30: uint8(44),
  21454 		31: uint8(45),
  21455 		32: uint8(47),
  21456 		33: uint8(48),
  21457 		34: uint8(50),
  21458 		35: uint8(51),
  21459 		36: uint8(53),
  21460 		37: uint8(54),
  21461 		38: uint8(56),
  21462 		39: uint8(57),
  21463 		40: uint8(59),
  21464 		41: uint8(60),
  21465 		42: uint8(62),
  21466 		43: uint8(63),
  21467 		44: uint8(63),
  21468 		45: uint8(63),
  21469 		46: uint8(63),
  21470 		47: uint8(63),
  21471 		48: uint8(63),
  21472 		49: uint8(63),
  21473 		50: uint8(63),
  21474 		51: uint8(63),
  21475 		52: uint8(63),
  21476 		53: uint8(63),
  21477 		54: uint8(63),
  21478 		55: uint8(63),
  21479 		56: uint8(63),
  21480 		57: uint8(63),
  21481 		58: uint8(63),
  21482 		59: uint8(63),
  21483 		60: uint8(63),
  21484 		61: uint8(63),
  21485 		62: uint8(63),
  21486 		63: uint8(63),
  21487 	},
  21488 }
  21489 
  21490 func VP8FilterStrengthFromDelta(tls *libc.TLS, sharpness int32, delta int32) (r int32) {
  21491 	var pos, v1 int32
  21492 	_, _ = pos, v1
  21493 	if delta < int32(MAX_DELTA_SIZE) {
  21494 		v1 = delta
  21495 	} else {
  21496 		v1 = libc.Int32FromInt32(MAX_DELTA_SIZE) - libc.Int32FromInt32(1)
  21497 	}
  21498 	pos = v1
  21499 	return libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kLevelsFromDelta)) + uintptr(sharpness)*64 + uintptr(pos))))
  21500 }
  21501 
  21502 //------------------------------------------------------------------------------
  21503 // Paragraph 15.4: compute the inner-edge filtering strength
  21504 
  21505 func GetILevel(tls *libc.TLS, sharpness int32, level int32) (r int32) {
  21506 	if sharpness > 0 {
  21507 		if sharpness > int32(4) {
  21508 			level = level >> int32(2)
  21509 		} else {
  21510 			level = level >> int32(1)
  21511 		}
  21512 		if level > int32(9)-sharpness {
  21513 			level = int32(9) - sharpness
  21514 		}
  21515 	}
  21516 	if level < int32(1) {
  21517 		level = int32(1)
  21518 	}
  21519 	return level
  21520 }
  21521 
  21522 func DoFilter1(tls *libc.TLS, it uintptr, level int32) {
  21523 	var enc, u_dst, v_dst, y_dst uintptr
  21524 	var hev_thresh, ilevel, limit, v1, v2 int32
  21525 	_, _, _, _, _, _, _, _, _ = enc, hev_thresh, ilevel, limit, u_dst, v_dst, y_dst, v1, v2
  21526 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21527 	ilevel = GetILevel(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness, level)
  21528 	limit = int32(2)*level + ilevel
  21529 	y_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  21530 	u_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  21531 	v_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  21532 	// copy current block to yuv_out2
  21533 	libc.Xmemcpy(tls, y_dst, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out, libc.Uint64FromInt32(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))*libc.Uint64FromInt64(1))
  21534 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple == int32(1) { // simple
  21535 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleHFilter16i})))(tls, y_dst, int32(BPS), limit)
  21536 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8SimpleVFilter16i})))(tls, y_dst, int32(BPS), limit)
  21537 	} else {
  21538 		if level >= int32(40) {
  21539 			v1 = int32(2)
  21540 		} else {
  21541 			if level >= int32(15) {
  21542 				v2 = int32(1)
  21543 			} else {
  21544 				v2 = 0
  21545 			}
  21546 			v1 = v2
  21547 		} // complex
  21548 		hev_thresh = v1
  21549 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8HFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21550 		(*(*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)
  21551 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8VFilter16i})))(tls, y_dst, int32(BPS), limit, ilevel, hev_thresh)
  21552 		(*(*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)
  21553 	}
  21554 }
  21555 
  21556 //------------------------------------------------------------------------------
  21557 // SSIM metric for one macroblock
  21558 
  21559 func GetMBSSIM(tls *libc.TLS, yuv1 uintptr, yuv2 uintptr) (r float64) {
  21560 	var sum float64
  21561 	var x, y int32
  21562 	_, _, _ = sum, x, y
  21563 	sum = float64(0)
  21564 	// compute SSIM in a 10 x 10 window
  21565 	y = int32(VP8_SSIM_KERNEL)
  21566 	for {
  21567 		if !(y < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21568 			break
  21569 		}
  21570 		x = int32(VP8_SSIM_KERNEL)
  21571 		for {
  21572 			if !(x < libc.Int32FromInt32(16)-libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  21573 				break
  21574 			}
  21575 			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))
  21576 			goto _2
  21577 		_2:
  21578 			;
  21579 			x = x + 1
  21580 		}
  21581 		goto _1
  21582 	_1:
  21583 		;
  21584 		y = y + 1
  21585 	}
  21586 	x = int32(1)
  21587 	for {
  21588 		if !(x < int32(7)) {
  21589 			break
  21590 		}
  21591 		y = int32(1)
  21592 		for {
  21593 			if !(y < int32(7)) {
  21594 				break
  21595 			}
  21596 			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))
  21597 			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))
  21598 			goto _4
  21599 		_4:
  21600 			;
  21601 			y = y + 1
  21602 		}
  21603 		goto _3
  21604 	_3:
  21605 		;
  21606 		x = x + 1
  21607 	}
  21608 	return sum
  21609 }
  21610 
  21611 //------------------------------------------------------------------------------
  21612 // Exposed APIs: Encoder should call the following 3 functions to adjust
  21613 // loop filter strength
  21614 
  21615 func VP8InitFilter(tls *libc.TLS, it uintptr) {
  21616 	var i, s int32
  21617 	_, _ = i, s
  21618 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21619 		s = 0
  21620 		for {
  21621 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21622 				break
  21623 			}
  21624 			i = 0
  21625 			for {
  21626 				if !(i < int32(MAX_LF_LEVELS)) {
  21627 					break
  21628 				}
  21629 				**(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8)) = libc.Float64FromInt32(0)
  21630 				goto _2
  21631 			_2:
  21632 				;
  21633 				i = i + 1
  21634 			}
  21635 			goto _1
  21636 		_1:
  21637 			;
  21638 			s = s + 1
  21639 		}
  21640 		VP8SSIMDspInit(tls)
  21641 	}
  21642 }
  21643 
  21644 func VP8StoreFilterStats(tls *libc.TLS, it uintptr) {
  21645 	var d, delta_max, delta_min, level, level0, s, step_size, v1 int32
  21646 	var enc uintptr
  21647 	_, _, _, _, _, _, _, _, _ = d, delta_max, delta_min, enc, level, level0, s, step_size, v1
  21648 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21649 	s = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  21650 	level0 = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength
  21651 	// explore +/-quant range of values around level0
  21652 	delta_min = -(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21653 	delta_max = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant
  21654 	if delta_max-delta_min >= int32(4) {
  21655 		v1 = int32(4)
  21656 	} else {
  21657 		v1 = int32(1)
  21658 	}
  21659 	step_size = v1
  21660 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats == libc.UintptrFromInt32(0) {
  21661 		return
  21662 	}
  21663 	// NOTE: Currently we are applying filter only across the sublock edges
  21664 	// There are two reasons for that.
  21665 	// 1. Applying filter on macro block edges will change the pixels in
  21666 	// the left and top macro blocks. That will be hard to restore
  21667 	// 2. Macro Blocks on the bottom and right are not yet compressed. So we
  21668 	// cannot apply filter on the right and bottom macro block edges.
  21669 	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 {
  21670 		return
  21671 	}
  21672 	// Always try filter level  zero
  21673 	**(**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)
  21674 	d = delta_min
  21675 	for {
  21676 		if !(d <= delta_max) {
  21677 			break
  21678 		}
  21679 		level = level0 + d
  21680 		if level <= 0 || level >= int32(MAX_LF_LEVELS) {
  21681 			goto _2
  21682 		}
  21683 		DoFilter1(tls, it, level)
  21684 		**(**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)
  21685 		goto _2
  21686 	_2:
  21687 		;
  21688 		d = d + step_size
  21689 	}
  21690 }
  21691 
  21692 func VP8AdjustFilterStrength(tls *libc.TLS, it uintptr) {
  21693 	var best_level, delta, i, level, max_level, s, s1 int32
  21694 	var best_v, v float64
  21695 	var dqm, enc uintptr
  21696 	_, _, _, _, _, _, _, _, _, _, _ = best_level, best_v, delta, dqm, enc, i, level, max_level, s, s1, v
  21697 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  21698 	if (*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats != libc.UintptrFromInt32(0) {
  21699 		s = 0
  21700 		for {
  21701 			if !(s < int32(NUM_MB_SEGMENTS)) {
  21702 				break
  21703 			}
  21704 			best_level = 0
  21705 			// Improvement over filter level 0 should be at least 1e-5 (relatively)
  21706 			best_v = float64(float64(1.00001) * **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512)))
  21707 			i = int32(1)
  21708 			for {
  21709 				if !(i < int32(MAX_LF_LEVELS)) {
  21710 					break
  21711 				}
  21712 				v = **(**float64)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats + uintptr(s)*512 + uintptr(i)*8))
  21713 				if v > best_v {
  21714 					best_v = v
  21715 					best_level = i
  21716 				}
  21717 				goto _2
  21718 			_2:
  21719 				;
  21720 				i = i + 1
  21721 			}
  21722 			(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength = best_level
  21723 			goto _1
  21724 		_1:
  21725 			;
  21726 			s = s + 1
  21727 		}
  21728 		return
  21729 	}
  21730 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength > 0 {
  21731 		max_level = 0
  21732 		s1 = 0
  21733 		for {
  21734 			if !(s1 < int32(NUM_MB_SEGMENTS)) {
  21735 				break
  21736 			}
  21737 			dqm = enc + 608 + uintptr(s1)*744
  21738 			// this '>> 3' accounts for some inverse WHT scaling
  21739 			delta = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(dqm + 224 + 1*2))) >> int32(3)
  21740 			level = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, delta)
  21741 			if level > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21742 				(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength = level
  21743 			}
  21744 			if max_level < (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength {
  21745 				max_level = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ffstrength
  21746 			}
  21747 			goto _3
  21748 		_3:
  21749 			;
  21750 			s1 = s1 + 1
  21751 		}
  21752 		(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = max_level
  21753 	}
  21754 }
  21755 
  21756 const DEBUG_SEARCH = 0
  21757 const DQ_LIMIT = 0.4
  21758 const FP_FAST_FMA = 1
  21759 const FP_FAST_FMAF = 1
  21760 const FP_ILOGB0 = "FP_ILOGBNAN"
  21761 const FP_INFINITE = 1
  21762 const FP_NAN = 0
  21763 const FP_NORMAL = 4
  21764 const FP_SUBNORMAL = 3
  21765 const FP_ZERO = 2
  21766 const HUGE = 3.40282346638528859812e+38
  21767 const HUGE_VALF = "INFINITY"
  21768 const MATH_ERREXCEPT = 2
  21769 const MATH_ERRNO = 1
  21770 const MIN_COUNT = 96
  21771 const M_1_PI = 0.31830988618379067154
  21772 const M_2_PI = 0.63661977236758134308
  21773 const M_2_SQRTPI = 1.12837916709551257390
  21774 const M_E = 2.7182818284590452354
  21775 const M_LN10 = 2.30258509299404568402
  21776 const M_LN2 = 0.69314718055994530942
  21777 const M_LOG10E = 0.43429448190325182765
  21778 const M_LOG2E = 1.4426950408889634074
  21779 const M_PI = 3.14159265358979323846
  21780 const M_PI_2 = 1.57079632679489661923
  21781 const M_PI_4 = 0.78539816339744830962
  21782 const M_SQRT1_2 = 0.70710678118654752440
  21783 const M_SQRT2 = 1.41421356237309504880
  21784 const SEGMENT_VISU = 0
  21785 const SKIP_PROBA_THRESHOLD = 250
  21786 const math_errhandling = 2
  21787 
  21788 type float_t = float32
  21789 
  21790 type double_t = float64
  21791 
  21792 // Alpha related constants.
  21793 
  21794 // Mux related constants.
  21795 
  21796 // Maximum chunk payload is such that adding the header and padding won't
  21797 // overflow a uint32_t.
  21798 
  21799 //------------------------------------------------------------------------------
  21800 // multi-pass convergence
  21801 
  21802 // we allow 2k of extra head-room in PARTITION0 limit.
  21803 
  21804 func Clamp(tls *libc.TLS, v float32, min float32, max float32) (r float32) {
  21805 	var v1, v2 float32
  21806 	_, _ = v1, v2
  21807 	if v < min {
  21808 		v1 = min
  21809 	} else {
  21810 		if v > max {
  21811 			v2 = max
  21812 		} else {
  21813 			v2 = v
  21814 		}
  21815 		v1 = v2
  21816 	}
  21817 	return v1
  21818 }
  21819 
  21820 type PassStats = struct {
  21821 	Fis_first       int32
  21822 	Fdq             float32
  21823 	Fq              float32
  21824 	Flast_q         float32
  21825 	Fqmin           float32
  21826 	Fqmax           float32
  21827 	Fvalue          float64
  21828 	Flast_value     float64
  21829 	Ftarget         float64
  21830 	Fdo_size_search int32
  21831 }
  21832 
  21833 func InitPassStats(tls *libc.TLS, enc uintptr, s uintptr) (r int32) {
  21834 	var do_size_search int32
  21835 	var target_PSNR, v1 float32
  21836 	var target_size uint64_t
  21837 	var v2, v3 float64
  21838 	_, _, _, _, _, _ = do_size_search, target_PSNR, target_size, v1, v2, v3
  21839 	target_size = libc.Uint64FromInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_size)
  21840 	do_size_search = libc.BoolInt32(target_size != libc.Uint64FromInt32(0))
  21841 	target_PSNR = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ftarget_PSNR
  21842 	(*PassStats)(unsafe.Pointer(s)).Fis_first = int32(1)
  21843 	(*PassStats)(unsafe.Pointer(s)).Fdq = libc.Float32FromFloat32(10)
  21844 	(*PassStats)(unsafe.Pointer(s)).Fqmin = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmin))
  21845 	(*PassStats)(unsafe.Pointer(s)).Fqmax = float32(libc.Float32FromFloat32(1) * float32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fqmax))
  21846 	v1 = Clamp(tls, (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fquality, (*PassStats)(unsafe.Pointer(s)).Fqmin, (*PassStats)(unsafe.Pointer(s)).Fqmax)
  21847 	(*PassStats)(unsafe.Pointer(s)).Flast_q = v1
  21848 	(*PassStats)(unsafe.Pointer(s)).Fq = v1
  21849 	if do_size_search != 0 {
  21850 		v2 = float64(target_size)
  21851 	} else {
  21852 		if float64(target_PSNR) > float64(0) {
  21853 			v3 = float64(target_PSNR)
  21854 		} else {
  21855 			v3 = float64(40)
  21856 		}
  21857 		v2 = v3
  21858 	}
  21859 	(*PassStats)(unsafe.Pointer(s)).Ftarget = v2 // default, just in case
  21860 	v2 = libc.Float64FromFloat64(0)
  21861 	(*PassStats)(unsafe.Pointer(s)).Flast_value = v2
  21862 	(*PassStats)(unsafe.Pointer(s)).Fvalue = v2
  21863 	(*PassStats)(unsafe.Pointer(s)).Fdo_size_search = do_size_search
  21864 	return do_size_search
  21865 }
  21866 
  21867 func ComputeNextQ(tls *libc.TLS, s uintptr) (r float32) {
  21868 	var dq, v1 float32
  21869 	var slope float64
  21870 	_, _, _ = dq, slope, v1
  21871 	if (*PassStats)(unsafe.Pointer(s)).Fis_first != 0 {
  21872 		if (*PassStats)(unsafe.Pointer(s)).Fvalue > (*PassStats)(unsafe.Pointer(s)).Ftarget {
  21873 			v1 = -(*PassStats)(unsafe.Pointer(s)).Fdq
  21874 		} else {
  21875 			v1 = (*PassStats)(unsafe.Pointer(s)).Fdq
  21876 		}
  21877 		dq = v1
  21878 		(*PassStats)(unsafe.Pointer(s)).Fis_first = 0
  21879 	} else {
  21880 		if (*PassStats)(unsafe.Pointer(s)).Fvalue != (*PassStats)(unsafe.Pointer(s)).Flast_value {
  21881 			slope = ((*PassStats)(unsafe.Pointer(s)).Ftarget - (*PassStats)(unsafe.Pointer(s)).Fvalue) / ((*PassStats)(unsafe.Pointer(s)).Flast_value - (*PassStats)(unsafe.Pointer(s)).Fvalue)
  21882 			dq = float32(float64(slope * float64((*PassStats)(unsafe.Pointer(s)).Flast_q-(*PassStats)(unsafe.Pointer(s)).Fq)))
  21883 		} else {
  21884 			dq = float32(0) // we're done?!
  21885 		}
  21886 	}
  21887 	// Limit variable to avoid large swings.
  21888 	(*PassStats)(unsafe.Pointer(s)).Fdq = Clamp(tls, dq, -libc.Float32FromFloat32(30), libc.Float32FromFloat32(30))
  21889 	(*PassStats)(unsafe.Pointer(s)).Flast_q = (*PassStats)(unsafe.Pointer(s)).Fq
  21890 	(*PassStats)(unsafe.Pointer(s)).Flast_value = (*PassStats)(unsafe.Pointer(s)).Fvalue
  21891 	(*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)
  21892 	return (*PassStats)(unsafe.Pointer(s)).Fq
  21893 }
  21894 
  21895 //------------------------------------------------------------------------------
  21896 // Reset the statistics about: number of skips, token proba, level cost,...
  21897 
  21898 func ResetStats(tls *libc.TLS, enc uintptr) {
  21899 	var proba uintptr
  21900 	_ = proba
  21901 	proba = enc + 3616
  21902 	VP8CalculateLevelCosts(tls, proba)
  21903 	(*VP8EncProba)(unsafe.Pointer(proba)).Fnb_skip = 0
  21904 }
  21905 
  21906 //------------------------------------------------------------------------------
  21907 // Skip decision probability
  21908 
  21909 func CalcSkipProba(tls *libc.TLS, nb uint64_t, total uint64_t) (r int32) {
  21910 	var v1 uint64
  21911 	_ = v1
  21912 	if total != 0 {
  21913 		v1 = (total - nb) * uint64(255) / total
  21914 	} else {
  21915 		v1 = uint64(255)
  21916 	}
  21917 	return libc.Int32FromUint64(v1)
  21918 }
  21919 
  21920 // C documentation
  21921 //
  21922 //	// Returns the bit-cost for coding the skip probability.
  21923 func FinalizeSkipProba(tls *libc.TLS, enc uintptr) (r int32) {
  21924 	var nb_events, nb_mbs, size, v2, v4, v6, v8 int32
  21925 	var proba1 uintptr
  21926 	var v1, v5 uint8_t
  21927 	_, _, _, _, _, _, _, _, _, _ = nb_events, nb_mbs, proba1, size, v1, v2, v4, v5, v6, v8
  21928 	proba1 = enc + 3616
  21929 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  21930 	nb_events = (*VP8EncProba)(unsafe.Pointer(proba1)).Fnb_skip
  21931 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba = libc.Uint8FromInt32(CalcSkipProba(tls, libc.Uint64FromInt32(nb_events), libc.Uint64FromInt32(nb_mbs)))
  21932 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba = libc.BoolInt32(libc.Int32FromUint8((*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba) < int32(SKIP_PROBA_THRESHOLD))
  21933 	size = int32(256) // 'use_skip_proba' bit
  21934 	if (*VP8EncProba)(unsafe.Pointer(proba1)).Fuse_skip_proba != 0 {
  21935 		v1 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  21936 		if !(int32(1) != 0) {
  21937 			v4 = libc.Int32FromUint16(VP8EntropyCost[v1])
  21938 		} else {
  21939 			v4 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v1)])
  21940 		}
  21941 		v2 = v4
  21942 		goto _3
  21943 	_3:
  21944 		v5 = (*VP8EncProba)(unsafe.Pointer(proba1)).Fskip_proba
  21945 		if !(0 != 0) {
  21946 			v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  21947 		} else {
  21948 			v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  21949 		}
  21950 		v6 = v8
  21951 		goto _7
  21952 	_7:
  21953 		size = size + (nb_events*v2 + (nb_mbs-nb_events)*v6)
  21954 		size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256) // cost of signaling the 'skip_proba' itself.
  21955 	}
  21956 	return size
  21957 }
  21958 
  21959 // C documentation
  21960 //
  21961 //	// Collect statistics and deduce probabilities for next coding pass.
  21962 //	// Return the total bit-cost for coding the probability updates.
  21963 func CalcTokenProba(tls *libc.TLS, nb int32, total int32) (r int32) {
  21964 	var v1 int32
  21965 	_ = v1
  21966 	if nb != 0 {
  21967 		v1 = int32(255) - nb*int32(255)/total
  21968 	} else {
  21969 		v1 = int32(255)
  21970 	}
  21971 	return v1
  21972 }
  21973 
  21974 // C documentation
  21975 //
  21976 //	// Cost of coding 'nb' 1's and 'total-nb' 0's using 'proba' probability.
  21977 func BranchCost(tls *libc.TLS, nb int32, total int32, proba1 int32) (r int32) {
  21978 	var v1, v5 uint8_t
  21979 	var v2, v4, v6, v8 int32
  21980 	_, _, _, _, _, _ = v1, v2, v4, v5, v6, v8
  21981 	v1 = libc.Uint8FromInt32(proba1)
  21982 	if !(int32(1) != 0) {
  21983 		v4 = libc.Int32FromUint16(VP8EntropyCost[v1])
  21984 	} else {
  21985 		v4 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v1)])
  21986 	}
  21987 	v2 = v4
  21988 	goto _3
  21989 _3:
  21990 	v5 = libc.Uint8FromInt32(proba1)
  21991 	if !(0 != 0) {
  21992 		v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  21993 	} else {
  21994 		v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  21995 	}
  21996 	v6 = v8
  21997 	goto _7
  21998 _7:
  21999 	return nb*v2 + (total-nb)*v6
  22000 }
  22001 
  22002 func ResetTokenStats(tls *libc.TLS, enc uintptr) {
  22003 	var proba uintptr
  22004 	_ = proba
  22005 	proba = enc + 3616
  22006 	libc.Xmemset(tls, proba+1060, 0, uint64(4224))
  22007 }
  22008 
  22009 func FinalizeTokenProbas(tls *libc.TLS, proba1 uintptr) (r int32) {
  22010 	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
  22011 	var stats proba_t
  22012 	var v13, v5, v9 uint8_t
  22013 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  22014 	has_changed = 0
  22015 	size = 0
  22016 	t = 0
  22017 	for {
  22018 		if !(t < int32(NUM_TYPES)) {
  22019 			break
  22020 		}
  22021 		b = 0
  22022 		for {
  22023 			if !(b < int32(NUM_BANDS)) {
  22024 				break
  22025 			}
  22026 			c = 0
  22027 			for {
  22028 				if !(c < int32(NUM_CTX)) {
  22029 					break
  22030 				}
  22031 				p = 0
  22032 				for {
  22033 					if !(p < int32(NUM_PROBAS)) {
  22034 						break
  22035 					}
  22036 					stats = **(**proba_t)(__ccgo_up(proba1 + 1060 + uintptr(t)*1056 + uintptr(b)*132 + uintptr(c)*44 + uintptr(p)*4))
  22037 					nb = libc.Int32FromUint32(stats >> libc.Int32FromInt32(0) & uint32(0xffff))
  22038 					total = libc.Int32FromUint32(stats >> libc.Int32FromInt32(16) & uint32(0xffff))
  22039 					update_proba = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsUpdateProba)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  22040 					old_p = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&VP8CoeffsProba0)) + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))))
  22041 					new_p = CalcTokenProba(tls, nb, total)
  22042 					v5 = libc.Uint8FromInt32(update_proba)
  22043 					if !(0 != 0) {
  22044 						v8 = libc.Int32FromUint16(VP8EntropyCost[v5])
  22045 					} else {
  22046 						v8 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v5)])
  22047 					}
  22048 					v6 = v8
  22049 					goto _7
  22050 				_7:
  22051 					old_cost = BranchCost(tls, nb, total, old_p) + v6
  22052 					v9 = libc.Uint8FromInt32(update_proba)
  22053 					if !(int32(1) != 0) {
  22054 						v12 = libc.Int32FromUint16(VP8EntropyCost[v9])
  22055 					} else {
  22056 						v12 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v9)])
  22057 					}
  22058 					v10 = v12
  22059 					goto _11
  22060 				_11:
  22061 					new_cost = BranchCost(tls, nb, total, new_p) + v10 + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  22062 					use_new_p = libc.BoolInt32(old_cost > new_cost)
  22063 					v13 = libc.Uint8FromInt32(update_proba)
  22064 					if !(use_new_p != 0) {
  22065 						v16 = libc.Int32FromUint16(VP8EntropyCost[v13])
  22066 					} else {
  22067 						v16 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v13)])
  22068 					}
  22069 					v14 = v16
  22070 					goto _15
  22071 				_15:
  22072 					size = size + v14
  22073 					if use_new_p != 0 { // only use proba that seem meaningful enough.
  22074 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = libc.Uint8FromInt32(new_p)
  22075 						has_changed = has_changed | libc.BoolInt32(new_p != old_p)
  22076 						size = size + libc.Int32FromInt32(8)*libc.Int32FromInt32(256)
  22077 					} else {
  22078 						**(**uint8_t)(__ccgo_up(proba1 + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p))) = libc.Uint8FromInt32(old_p)
  22079 					}
  22080 					goto _4
  22081 				_4:
  22082 					;
  22083 					p = p + 1
  22084 				}
  22085 				goto _3
  22086 			_3:
  22087 				;
  22088 				c = c + 1
  22089 			}
  22090 			goto _2
  22091 		_2:
  22092 			;
  22093 			b = b + 1
  22094 		}
  22095 		goto _1
  22096 	_1:
  22097 		;
  22098 		t = t + 1
  22099 	}
  22100 	(*VP8EncProba)(unsafe.Pointer(proba1)).Fdirty = has_changed
  22101 	return size
  22102 }
  22103 
  22104 //------------------------------------------------------------------------------
  22105 // Finalize Segment probability based on the coding tree
  22106 
  22107 func GetProba(tls *libc.TLS, a int32, b int32) (r int32) {
  22108 	var total, v1 int32
  22109 	_, _ = total, v1
  22110 	total = a + b
  22111 	if total == 0 {
  22112 		v1 = int32(255)
  22113 	} else {
  22114 		v1 = (int32(255)*a + total/int32(2)) / total
  22115 	}
  22116 	return v1 // rounded proba
  22117 }
  22118 
  22119 func ResetSegments(tls *libc.TLS, enc uintptr) {
  22120 	var n int32
  22121 	_ = n
  22122 	n = 0
  22123 	for {
  22124 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  22125 			break
  22126 		}
  22127 		libc.SetBitFieldPtr8Uint32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info+uintptr(n)*4+0, libc.Uint32FromInt32(0), 5, 0x60)
  22128 		goto _1
  22129 	_1:
  22130 		;
  22131 		n = n + 1
  22132 	}
  22133 }
  22134 
  22135 func SetSegmentProbas(tls *libc.TLS, enc uintptr) {
  22136 	var mb, probas uintptr
  22137 	var n, v10, v12, v14, v16, v18, v20, v22, v24, v26, v28, v30, v32, v34, v4, v6, v8 int32
  22138 	var p [4]int32
  22139 	var v11, v15, v19, v23, v27, v3, v31, v7 uint8_t
  22140 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  22141 	p = [4]int32{}
  22142 	n = 0
  22143 	for {
  22144 		if !(n < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  22145 			break
  22146 		}
  22147 		mb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(n)*4
  22148 		p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] = p[int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5))] + 1
  22149 		goto _1
  22150 	_1:
  22151 		;
  22152 		n = n + 1
  22153 	}
  22154 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  22155 		n = 0
  22156 		for {
  22157 			if !(n < int32(NUM_MB_SEGMENTS)) {
  22158 				break
  22159 			}
  22160 			**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 92 + uintptr(n)*4)) = p[n]
  22161 			goto _2
  22162 		_2:
  22163 			;
  22164 			n = n + 1
  22165 		}
  22166 	}
  22167 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments > int32(1) {
  22168 		probas = enc + 3616
  22169 		**(**uint8_t)(__ccgo_up(probas)) = libc.Uint8FromInt32(GetProba(tls, p[0]+p[int32(1)], p[int32(2)]+p[int32(3)]))
  22170 		**(**uint8_t)(__ccgo_up(probas + 1)) = libc.Uint8FromInt32(GetProba(tls, p[0], p[int32(1)]))
  22171 		**(**uint8_t)(__ccgo_up(probas + 2)) = libc.Uint8FromInt32(GetProba(tls, p[int32(2)], p[int32(3)]))
  22172 		(*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))
  22173 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0) {
  22174 			ResetSegments(tls, enc)
  22175 		}
  22176 		v3 = **(**uint8_t)(__ccgo_up(probas))
  22177 		if !(0 != 0) {
  22178 			v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  22179 		} else {
  22180 			v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  22181 		}
  22182 		v4 = v6
  22183 		goto _5
  22184 	_5:
  22185 		v7 = **(**uint8_t)(__ccgo_up(probas + 1))
  22186 		if !(0 != 0) {
  22187 			v10 = libc.Int32FromUint16(VP8EntropyCost[v7])
  22188 		} else {
  22189 			v10 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v7)])
  22190 		}
  22191 		v8 = v10
  22192 		goto _9
  22193 	_9:
  22194 		v11 = **(**uint8_t)(__ccgo_up(probas))
  22195 		if !(0 != 0) {
  22196 			v14 = libc.Int32FromUint16(VP8EntropyCost[v11])
  22197 		} else {
  22198 			v14 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v11)])
  22199 		}
  22200 		v12 = v14
  22201 		goto _13
  22202 	_13:
  22203 		v15 = **(**uint8_t)(__ccgo_up(probas + 1))
  22204 		if !(int32(1) != 0) {
  22205 			v18 = libc.Int32FromUint16(VP8EntropyCost[v15])
  22206 		} else {
  22207 			v18 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v15)])
  22208 		}
  22209 		v16 = v18
  22210 		goto _17
  22211 	_17:
  22212 		v19 = **(**uint8_t)(__ccgo_up(probas))
  22213 		if !(int32(1) != 0) {
  22214 			v22 = libc.Int32FromUint16(VP8EntropyCost[v19])
  22215 		} else {
  22216 			v22 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v19)])
  22217 		}
  22218 		v20 = v22
  22219 		goto _21
  22220 	_21:
  22221 		v23 = **(**uint8_t)(__ccgo_up(probas + 2))
  22222 		if !(0 != 0) {
  22223 			v26 = libc.Int32FromUint16(VP8EntropyCost[v23])
  22224 		} else {
  22225 			v26 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v23)])
  22226 		}
  22227 		v24 = v26
  22228 		goto _25
  22229 	_25:
  22230 		v27 = **(**uint8_t)(__ccgo_up(probas))
  22231 		if !(int32(1) != 0) {
  22232 			v30 = libc.Int32FromUint16(VP8EntropyCost[v27])
  22233 		} else {
  22234 			v30 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v27)])
  22235 		}
  22236 		v28 = v30
  22237 		goto _29
  22238 	_29:
  22239 		v31 = **(**uint8_t)(__ccgo_up(probas + 2))
  22240 		if !(int32(1) != 0) {
  22241 			v34 = libc.Int32FromUint16(VP8EntropyCost[v31])
  22242 		} else {
  22243 			v34 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v31)])
  22244 		}
  22245 		v32 = v34
  22246 		goto _33
  22247 	_33:
  22248 		(*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)
  22249 	} else {
  22250 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map = 0
  22251 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize = 0
  22252 	}
  22253 }
  22254 
  22255 //------------------------------------------------------------------------------
  22256 // Coefficient coding
  22257 
  22258 func PutCoeffs(tls *libc.TLS, bw uintptr, ctx int32, res uintptr) (r int32) {
  22259 	var c, mask, n, sign, v, v1, v2 int32
  22260 	var p, tab, v3 uintptr
  22261 	_, _, _, _, _, _, _, _, _, _ = c, mask, n, p, sign, tab, v, v1, v2, v3
  22262 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  22263 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  22264 	p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx)*11
  22265 	if !(VP8PutBit(tls, bw, libc.BoolInt32((*VP8Residual)(unsafe.Pointer(res)).Flast >= 0), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22266 		return 0
  22267 	}
  22268 	for n < int32(16) {
  22269 		v1 = n
  22270 		n = n + 1
  22271 		c = int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(v1)*2)))
  22272 		sign = libc.BoolInt32(c < 0)
  22273 		if sign != 0 {
  22274 			v2 = -c
  22275 		} else {
  22276 			v2 = c
  22277 		}
  22278 		v = v2
  22279 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v != 0), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1)))) != 0) {
  22280 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33
  22281 			continue
  22282 		}
  22283 		if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(1)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 2)))) != 0) {
  22284 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 1*11
  22285 		} else {
  22286 			if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(4)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 3)))) != 0) {
  22287 				if VP8PutBit(tls, bw, libc.BoolInt32(v != int32(2)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 4)))) != 0 {
  22288 					VP8PutBit(tls, bw, libc.BoolInt32(v == int32(4)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 5))))
  22289 				}
  22290 			} else {
  22291 				if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(10)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 6)))) != 0) {
  22292 					if !(VP8PutBit(tls, bw, libc.BoolInt32(v > int32(6)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 7)))) != 0) {
  22293 						VP8PutBit(tls, bw, libc.BoolInt32(v == int32(6)), int32(159))
  22294 					} else {
  22295 						VP8PutBit(tls, bw, libc.BoolInt32(v >= int32(9)), int32(165))
  22296 						VP8PutBit(tls, bw, libc.BoolInt32(!(v&libc.Int32FromInt32(1) != 0)), int32(145))
  22297 					}
  22298 				} else {
  22299 					if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(1) { // VP8Cat3  (3b)
  22300 						VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22301 						VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 9))))
  22302 						v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  22303 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  22304 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  22305 					} else {
  22306 						if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(2) { // VP8Cat4  (4b)
  22307 							VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22308 							VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 9))))
  22309 							v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  22310 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  22311 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  22312 						} else {
  22313 							if v < libc.Int32FromInt32(3)+libc.Int32FromInt32(8)<<libc.Int32FromInt32(3) { // VP8Cat5  (5b)
  22314 								VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22315 								VP8PutBit(tls, bw, 0, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 10))))
  22316 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  22317 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  22318 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  22319 							} else { // VP8Cat6 (11b)
  22320 								VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 8))))
  22321 								VP8PutBit(tls, bw, int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 10))))
  22322 								v = v - (libc.Int32FromInt32(3) + libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  22323 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  22324 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  22325 							}
  22326 						}
  22327 					}
  22328 					for mask != 0 {
  22329 						v3 = tab
  22330 						tab = tab + 1
  22331 						VP8PutBit(tls, bw, libc.BoolInt32(!!(v&mask != 0)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v3))))
  22332 						mask = mask >> int32(1)
  22333 					}
  22334 				}
  22335 			}
  22336 			p = (*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(VP8EncBands[n])*33 + 2*11
  22337 		}
  22338 		VP8PutBitUniform(tls, bw, sign)
  22339 		if n == int32(16) || !(VP8PutBit(tls, bw, libc.BoolInt32(n <= (*VP8Residual)(unsafe.Pointer(res)).Flast), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) != 0) {
  22340 			return int32(1) // EOB
  22341 		}
  22342 	}
  22343 	return int32(1)
  22344 }
  22345 
  22346 func CodeResiduals(tls *libc.TLS, bw1 uintptr, it uintptr, rd uintptr) {
  22347 	bp := tls.Alloc(48)
  22348 	defer tls.Free(48)
  22349 	var ch, ctx, ctx1, i16, segment, x, y, v4 int32
  22350 	var enc, v1 uintptr
  22351 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  22352 	var _ /* res at bp+0 */ VP8Residual
  22353 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, ctx1, enc, i16, nb_bits, pos1, pos2, pos3, segment, x, y, v1, v2, v4
  22354 	i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  22355 	segment = int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0)) & 0x60 >> 5))
  22356 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22357 	VP8IteratorNzToBytes(tls, it)
  22358 	v1 = bw1
  22359 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22360 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22361 	goto _3
  22362 _3:
  22363 	pos1 = v2
  22364 	if i16 != 0 {
  22365 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22366 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22367 		v4 = PutCoeffs(tls, bw1, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22368 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v4
  22369 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v4
  22370 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22371 	} else {
  22372 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22373 	}
  22374 	// luma-AC
  22375 	y = 0
  22376 	for {
  22377 		if !(y < int32(4)) {
  22378 			break
  22379 		}
  22380 		x = 0
  22381 		for {
  22382 			if !(x < int32(4)) {
  22383 				break
  22384 			}
  22385 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22386 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22387 			v4 = PutCoeffs(tls, bw1, ctx, bp)
  22388 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  22389 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  22390 			goto _6
  22391 		_6:
  22392 			;
  22393 			x = x + 1
  22394 		}
  22395 		goto _5
  22396 	_5:
  22397 		;
  22398 		y = y + 1
  22399 	}
  22400 	v1 = bw1
  22401 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22402 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22403 	goto _10
  22404 _10:
  22405 	pos2 = v2
  22406 	// U/V
  22407 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22408 	ch = 0
  22409 	for {
  22410 		if !(ch <= int32(2)) {
  22411 			break
  22412 		}
  22413 		y = 0
  22414 		for {
  22415 			if !(y < int32(2)) {
  22416 				break
  22417 			}
  22418 			x = 0
  22419 			for {
  22420 				if !(x < int32(2)) {
  22421 					break
  22422 				}
  22423 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22424 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22425 				v4 = PutCoeffs(tls, bw1, ctx1, bp)
  22426 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v4
  22427 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v4
  22428 				goto _13
  22429 			_13:
  22430 				;
  22431 				x = x + 1
  22432 			}
  22433 			goto _12
  22434 		_12:
  22435 			;
  22436 			y = y + 1
  22437 		}
  22438 		goto _11
  22439 	_11:
  22440 		;
  22441 		ch = ch + int32(2)
  22442 	}
  22443 	v1 = bw1
  22444 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  22445 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  22446 	goto _17
  22447 _17:
  22448 	pos3 = v2
  22449 	(*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits = pos2 - pos1
  22450 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits = pos3 - pos2
  22451 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + uintptr(i16)*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits
  22452 	**(**uint64_t)(__ccgo_up(it + 208 + uintptr(segment)*24 + 2*8)) += (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits
  22453 	VP8IteratorBytesToNz(tls, it)
  22454 }
  22455 
  22456 // C documentation
  22457 //
  22458 //	// Same as CodeResiduals, but doesn't actually write anything.
  22459 //	// Instead, it just records the event distribution.
  22460 func RecordResiduals(tls *libc.TLS, it uintptr, rd uintptr) {
  22461 	bp := tls.Alloc(48)
  22462 	defer tls.Free(48)
  22463 	var ch, ctx, ctx1, x, y, v1 int32
  22464 	var enc uintptr
  22465 	var _ /* res at bp+0 */ VP8Residual
  22466 	_, _, _, _, _, _, _ = ch, ctx, ctx1, enc, x, y, v1
  22467 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22468 	VP8IteratorNzToBytes(tls, it)
  22469 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22470 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22471 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22472 		v1 = VP8RecordCoeffs(tls, **(**int32)(__ccgo_up(it + 132 + 8*4))+**(**int32)(__ccgo_up(it + 168 + 8*4)), bp)
  22473 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22474 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22475 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22476 	} else {
  22477 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22478 	}
  22479 	// luma-AC
  22480 	y = 0
  22481 	for {
  22482 		if !(y < int32(4)) {
  22483 			break
  22484 		}
  22485 		x = 0
  22486 		for {
  22487 			if !(x < int32(4)) {
  22488 				break
  22489 			}
  22490 			ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22491 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22492 			v1 = VP8RecordCoeffs(tls, ctx, bp)
  22493 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22494 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22495 			goto _3
  22496 		_3:
  22497 			;
  22498 			x = x + 1
  22499 		}
  22500 		goto _2
  22501 	_2:
  22502 		;
  22503 		y = y + 1
  22504 	}
  22505 	// U/V
  22506 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22507 	ch = 0
  22508 	for {
  22509 		if !(ch <= int32(2)) {
  22510 			break
  22511 		}
  22512 		y = 0
  22513 		for {
  22514 			if !(y < int32(2)) {
  22515 				break
  22516 			}
  22517 			x = 0
  22518 			for {
  22519 				if !(x < int32(2)) {
  22520 					break
  22521 				}
  22522 				ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22523 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22524 				v1 = VP8RecordCoeffs(tls, ctx1, bp)
  22525 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22526 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22527 				goto _7
  22528 			_7:
  22529 				;
  22530 				x = x + 1
  22531 			}
  22532 			goto _6
  22533 		_6:
  22534 			;
  22535 			y = y + 1
  22536 		}
  22537 		goto _5
  22538 	_5:
  22539 		;
  22540 		ch = ch + int32(2)
  22541 	}
  22542 	VP8IteratorBytesToNz(tls, it)
  22543 }
  22544 
  22545 //------------------------------------------------------------------------------
  22546 // Token buffer
  22547 
  22548 func RecordTokens(tls *libc.TLS, it uintptr, rd uintptr, tokens uintptr) (r int32) {
  22549 	bp := tls.Alloc(48)
  22550 	defer tls.Free(48)
  22551 	var ch, ctx, ctx1, ctx2, x, y, v1 int32
  22552 	var enc uintptr
  22553 	var _ /* res at bp+0 */ VP8Residual
  22554 	_, _, _, _, _, _, _, _ = ch, ctx, ctx1, ctx2, enc, x, y, v1
  22555 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22556 	VP8IteratorNzToBytes(tls, it)
  22557 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) { // i16x16
  22558 		ctx = **(**int32)(__ccgo_up(it + 132 + 8*4)) + **(**int32)(__ccgo_up(it + 168 + 8*4))
  22559 		VP8InitResidual(tls, 0, int32(1), enc, bp)
  22560 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+40, bp)
  22561 		v1 = VP8RecordCoeffTokens(tls, ctx, bp, tokens)
  22562 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = v1
  22563 		**(**int32)(__ccgo_up(it + 132 + 8*4)) = v1
  22564 		VP8InitResidual(tls, int32(1), 0, enc, bp)
  22565 	} else {
  22566 		VP8InitResidual(tls, 0, int32(3), enc, bp)
  22567 	}
  22568 	// luma-AC
  22569 	y = 0
  22570 	for {
  22571 		if !(y < int32(4)) {
  22572 			break
  22573 		}
  22574 		x = 0
  22575 		for {
  22576 			if !(x < int32(4)) {
  22577 				break
  22578 			}
  22579 			ctx1 = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  22580 			(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+72+uintptr(x+y*int32(4))*32, bp)
  22581 			v1 = VP8RecordCoeffTokens(tls, ctx1, bp, tokens)
  22582 			**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v1
  22583 			**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v1
  22584 			goto _3
  22585 		_3:
  22586 			;
  22587 			x = x + 1
  22588 		}
  22589 		goto _2
  22590 	_2:
  22591 		;
  22592 		y = y + 1
  22593 	}
  22594 	// U/V
  22595 	VP8InitResidual(tls, 0, int32(2), enc, bp)
  22596 	ch = 0
  22597 	for {
  22598 		if !(ch <= int32(2)) {
  22599 			break
  22600 		}
  22601 		y = 0
  22602 		for {
  22603 			if !(y < int32(2)) {
  22604 				break
  22605 			}
  22606 			x = 0
  22607 			for {
  22608 				if !(x < int32(2)) {
  22609 					break
  22610 				}
  22611 				ctx2 = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  22612 				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8SetResidualCoeffs})))(tls, rd+584+uintptr(ch*int32(2)+x+y*int32(2))*32, bp)
  22613 				v1 = VP8RecordCoeffTokens(tls, ctx2, bp, tokens)
  22614 				**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v1
  22615 				**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v1
  22616 				goto _7
  22617 			_7:
  22618 				;
  22619 				x = x + 1
  22620 			}
  22621 			goto _6
  22622 		_6:
  22623 			;
  22624 			y = y + 1
  22625 		}
  22626 		goto _5
  22627 	_5:
  22628 		;
  22629 		ch = ch + int32(2)
  22630 	}
  22631 	VP8IteratorBytesToNz(tls, it)
  22632 	return libc.BoolInt32(!((*VP8TBuffer)(unsafe.Pointer(tokens)).Ferror1 != 0))
  22633 }
  22634 
  22635 //------------------------------------------------------------------------------
  22636 // ExtraInfo map / Debug function
  22637 
  22638 func ResetSSE(tls *libc.TLS, enc uintptr) {
  22639 	**(**uint64_t)(__ccgo_up(enc + 23512)) = uint64(0)
  22640 	**(**uint64_t)(__ccgo_up(enc + 23512 + 1*8)) = uint64(0)
  22641 	**(**uint64_t)(__ccgo_up(enc + 23512 + 2*8)) = uint64(0)
  22642 	// Note: enc->sse[3] is managed by alpha.c
  22643 	(*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count = uint64(0)
  22644 }
  22645 
  22646 func StoreSSE(tls *libc.TLS, it uintptr) {
  22647 	var enc, in, out uintptr
  22648 	_, _, _ = enc, in, out
  22649 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22650 	in = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in
  22651 	out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out
  22652 	// Note: not totally accurate at boundary. And doesn't include in-loop filter.
  22653 	**(**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))))
  22654 	**(**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))))
  22655 	**(**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))))
  22656 	**(**uint64_t)(__ccgo_up(enc + 23544)) += libc.Uint64FromInt32(libc.Int32FromInt32(16) * libc.Int32FromInt32(16))
  22657 }
  22658 
  22659 func StoreSideInfo(tls *libc.TLS, it uintptr) {
  22660 	var b, v1 int32
  22661 	var enc, info, mb, pic uintptr
  22662 	_, _, _, _, _, _ = b, enc, info, mb, pic, v1
  22663 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22664 	mb = (*VP8EncIterator)(unsafe.Pointer(it)).Fmb
  22665 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22666 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22667 		StoreSSE(tls, it)
  22668 		**(**int32)(__ccgo_up(enc + 23604)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == 0)
  22669 		**(**int32)(__ccgo_up(enc + 23604 + 1*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1))
  22670 		**(**int32)(__ccgo_up(enc + 23604 + 2*4)) += libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)) != 0)
  22671 	}
  22672 	if (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info != libc.UintptrFromInt32(0) {
  22673 		info = (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx+(*VP8EncIterator)(unsafe.Pointer(it)).Fy*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)
  22674 		switch (*WebPPicture)(unsafe.Pointer(pic)).Fextra_info_type {
  22675 		case int32(1):
  22676 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x3 >> 0)))
  22677 		case int32(2):
  22678 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0x60 >> 5)))
  22679 		case int32(3):
  22680 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)))*744))).Fquant)
  22681 		case int32(4):
  22682 			if int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) == int32(1) {
  22683 				v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds)))
  22684 			} else {
  22685 				v1 = int32(0xff)
  22686 			}
  22687 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(v1)
  22688 		case int32(5):
  22689 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0)) & 0xc >> 2)))
  22690 		case int32(6):
  22691 			b = libc.Int32FromUint64(((*VP8EncIterator)(unsafe.Pointer(it)).Fluma_bits + (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_bits + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  22692 			if b > int32(255) {
  22693 				v1 = int32(255)
  22694 			} else {
  22695 				v1 = b
  22696 			}
  22697 			**(**uint8_t)(__ccgo_up(info)) = libc.Uint8FromInt32(v1)
  22698 		case int32(7):
  22699 			**(**uint8_t)(__ccgo_up(info)) = (*VP8MBInfo)(unsafe.Pointer(mb)).Falpha
  22700 		default:
  22701 			**(**uint8_t)(__ccgo_up(info)) = uint8(0)
  22702 			break
  22703 		}
  22704 	}
  22705 }
  22706 
  22707 func ResetSideInfo(tls *libc.TLS, it uintptr) {
  22708 	var enc, pic uintptr
  22709 	_, _ = enc, pic
  22710 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22711 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  22712 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  22713 		libc.Xmemset(tls, enc+23604, 0, uint64(12))
  22714 	}
  22715 	ResetSSE(tls, enc)
  22716 }
  22717 
  22718 func GetPSNR(tls *libc.TLS, mse uint64_t, size uint64_t) (r float64) {
  22719 	var v1 float64
  22720 	_ = v1
  22721 	if mse > uint64(0) && size > uint64(0) {
  22722 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(mse)))
  22723 	} else {
  22724 		v1 = libc.Float64FromInt32(99)
  22725 	}
  22726 	return v1
  22727 }
  22728 
  22729 //------------------------------------------------------------------------------
  22730 //  StatLoop(): only collect statistics (number of skips, token usage, ...).
  22731 //  This is used for deciding optimal probabilities. It also modifies the
  22732 //  quantizer value if some target (size, PSNR) was specified.
  22733 
  22734 func SetLoopParams(tls *libc.TLS, enc uintptr, q float32) {
  22735 	// Make sure the quality parameter is inside valid bounds
  22736 	q = Clamp(tls, q, libc.Float32FromFloat32(0), libc.Float32FromFloat32(100))
  22737 	VP8SetSegmentParams(tls, enc, q) // setup segment quantizations and filters
  22738 	SetSegmentProbas(tls, enc)       // compute segment probabilities
  22739 	ResetStats(tls, enc)
  22740 	ResetSSE(tls, enc)
  22741 }
  22742 
  22743 func OneStatPass(tls *libc.TLS, enc uintptr, rd_opt VP8RDLevel, nb_mbs int32, percent_delta int32, s uintptr) (r uint64_t) {
  22744 	bp := tls.Alloc(4736)
  22745 	defer tls.Free(4736)
  22746 	var distortion, pixel_count, size, size_p0 uint64_t
  22747 	var v1 int32
  22748 	var v2 bool
  22749 	var _ /* info at bp+3848 */ VP8ModeScore
  22750 	var _ /* it at bp+0 */ VP8EncIterator
  22751 	_, _, _, _, _, _ = distortion, pixel_count, size, size_p0, v1, v2
  22752 	size = uint64(0)
  22753 	size_p0 = uint64(0)
  22754 	distortion = uint64(0)
  22755 	pixel_count = libc.Uint64FromInt32(nb_mbs) * uint64(384)
  22756 	VP8IteratorInit(tls, enc, bp)
  22757 	SetLoopParams(tls, enc, (*PassStats)(unsafe.Pointer(s)).Fq)
  22758 	for {
  22759 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22760 		if VP8Decimate(tls, bp, bp+3848, rd_opt) != 0 {
  22761 			// Just record the number of skips and act like skip_proba is not used.
  22762 			(*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip = (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fnb_skip + 1
  22763 		}
  22764 		RecordResiduals(tls, bp, bp+3848)
  22765 		size = size + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FR+(**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22766 		size_p0 = size_p0 + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FH)
  22767 		distortion = distortion + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3848))).FD)
  22768 		if percent_delta != 0 && !(VP8IteratorProgress(tls, bp, percent_delta) != 0) {
  22769 			return uint64(0)
  22770 		}
  22771 		VP8IteratorSaveBoundary(tls, bp)
  22772 		goto _3
  22773 	_3:
  22774 		;
  22775 		if v2 = VP8IteratorNext(tls, bp) != 0; v2 {
  22776 			nb_mbs = nb_mbs - 1
  22777 			v1 = nb_mbs
  22778 		}
  22779 		if !(v2 && v1 > 0) {
  22780 			break
  22781 		}
  22782 	}
  22783 	size_p0 = size_p0 + libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  22784 	if (*PassStats)(unsafe.Pointer(s)).Fdo_size_search != 0 {
  22785 		size = size + libc.Uint64FromInt32(FinalizeSkipProba(tls, enc))
  22786 		size = size + libc.Uint64FromInt32(FinalizeTokenProbas(tls, enc+3616))
  22787 		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))
  22788 		(*PassStats)(unsafe.Pointer(s)).Fvalue = float64(size)
  22789 	} else {
  22790 		(*PassStats)(unsafe.Pointer(s)).Fvalue = GetPSNR(tls, distortion, pixel_count)
  22791 	}
  22792 	return size_p0
  22793 }
  22794 
  22795 func StatLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22796 	bp := tls.Alloc(64)
  22797 	defer tls.Free(64)
  22798 	var do_search, fast_probe, final_percent, is_last_pass, method, nb_mbs, num_pass_left, percent_per_pass, task_percent, v1 int32
  22799 	var rd_opt VP8RDLevel
  22800 	var size_p0 uint64_t
  22801 	var _ /* stats at bp+0 */ PassStats
  22802 	_, _, _, _, _, _, _, _, _, _, _, _ = 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
  22803 	method = (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod
  22804 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  22805 	fast_probe = libc.BoolInt32((method == 0 || method == int32(3)) && !(do_search != 0))
  22806 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  22807 	task_percent = int32(20)
  22808 	percent_per_pass = (task_percent + num_pass_left/int32(2)) / num_pass_left
  22809 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  22810 	if method >= int32(3) || do_search != 0 {
  22811 		v1 = int32(RD_OPT_BASIC)
  22812 	} else {
  22813 		v1 = int32(RD_OPT_NONE)
  22814 	}
  22815 	rd_opt = v1
  22816 	nb_mbs = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  22817 	InitPassStats(tls, enc, bp)
  22818 	ResetTokenStats(tls, enc)
  22819 	// Fast mode: quick analysis pass over few mbs. Better than nothing.
  22820 	if fast_probe != 0 {
  22821 		if method == int32(3) { // we need more stats for method 3 to be reliable.
  22822 			if nb_mbs > int32(200) {
  22823 				v1 = nb_mbs >> int32(1)
  22824 			} else {
  22825 				v1 = int32(100)
  22826 			}
  22827 			nb_mbs = v1
  22828 		} else {
  22829 			if nb_mbs > int32(200) {
  22830 				v1 = nb_mbs >> int32(2)
  22831 			} else {
  22832 				v1 = int32(50)
  22833 			}
  22834 			nb_mbs = v1
  22835 		}
  22836 	}
  22837 	for {
  22838 		v1 = num_pass_left
  22839 		num_pass_left = num_pass_left - 1
  22840 		if !(v1 > 0) {
  22841 			break
  22842 		}
  22843 		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)
  22844 		size_p0 = OneStatPass(tls, enc, rd_opt, nb_mbs, percent_per_pass, bp)
  22845 		if size_p0 == uint64(0) {
  22846 			return 0
  22847 		}
  22848 		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) {
  22849 			num_pass_left = num_pass_left + 1
  22850 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  22851 			continue                                         // ...and start over
  22852 		}
  22853 		if is_last_pass != 0 {
  22854 			break
  22855 		}
  22856 		// If no target size: just do several pass without changing 'q'
  22857 		if do_search != 0 {
  22858 			ComputeNextQ(tls, bp)
  22859 			if libc.Xfabs(tls, float64((**(**PassStats)(__ccgo_up(bp))).Fdq)) <= float64(DQ_LIMIT) {
  22860 				break
  22861 			}
  22862 		}
  22863 	}
  22864 	if !(do_search != 0) || !((**(**PassStats)(__ccgo_up(bp))).Fdo_size_search != 0) {
  22865 		// Need to finalize probas now, since it wasn't done during the search.
  22866 		FinalizeSkipProba(tls, enc)
  22867 		FinalizeTokenProbas(tls, enc+3616)
  22868 	}
  22869 	VP8CalculateLevelCosts(tls, enc+3616) // finalize costs
  22870 	return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, final_percent, enc+536)
  22871 }
  22872 
  22873 //------------------------------------------------------------------------------
  22874 // Main loops
  22875 //
  22876 
  22877 var kAverageBytesPerMB = [8]uint8_t{
  22878 	0: uint8(50),
  22879 	1: uint8(24),
  22880 	2: uint8(16),
  22881 	3: uint8(9),
  22882 	4: uint8(7),
  22883 	5: uint8(5),
  22884 	6: uint8(3),
  22885 	7: uint8(2),
  22886 }
  22887 
  22888 func PreLoopInitialize(tls *libc.TLS, enc uintptr) (r int32) {
  22889 	var average_bytes_per_MB, bytes_per_parts, ok, p int32
  22890 	_, _, _, _ = average_bytes_per_MB, bytes_per_parts, ok, p
  22891 	ok = int32(1)
  22892 	average_bytes_per_MB = libc.Int32FromUint8(kAverageBytesPerMB[(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant>>int32(4)])
  22893 	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
  22894 	// Initialize the bit-writers
  22895 	p = 0
  22896 	for {
  22897 		if !(ok != 0 && p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22898 			break
  22899 		}
  22900 		ok = VP8BitWriterInit(tls, enc+112+uintptr(p)*48, libc.Uint64FromInt32(bytes_per_parts))
  22901 		goto _1
  22902 	_1:
  22903 		;
  22904 		p = p + 1
  22905 	}
  22906 	if !(ok != 0) {
  22907 		VP8EncFreeBitWriters(tls, enc) // malloc error occurred
  22908 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22909 	}
  22910 	return ok
  22911 }
  22912 
  22913 func PostLoopFinalize(tls *libc.TLS, it uintptr, ok int32) (r int32) {
  22914 	var enc uintptr
  22915 	var i, p, s int32
  22916 	_, _, _, _ = enc, i, p, s
  22917 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  22918 	if ok != 0 {
  22919 		p = 0
  22920 		for {
  22921 			if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  22922 				break
  22923 			}
  22924 			VP8BitWriterFinish(tls, enc+112+uintptr(p)*48)
  22925 			ok = ok & libc.BoolInt32(!((**(**VP8BitWriter)(__ccgo_up(enc + 112 + uintptr(p)*48))).Ferror1 != 0))
  22926 			goto _1
  22927 		_1:
  22928 			;
  22929 			p = p + 1
  22930 		}
  22931 	}
  22932 	if ok != 0 { // All good. Finish up.
  22933 		if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != libc.UintptrFromInt32(0) {
  22934 			i = 0
  22935 			for {
  22936 				if !(i <= int32(2)) {
  22937 					break
  22938 				}
  22939 				s = 0
  22940 				for {
  22941 					if !(s < int32(NUM_MB_SEGMENTS)) {
  22942 						break
  22943 					}
  22944 					**(**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))
  22945 					goto _3
  22946 				_3:
  22947 					;
  22948 					s = s + 1
  22949 				}
  22950 				goto _2
  22951 			_2:
  22952 				;
  22953 				i = i + 1
  22954 			}
  22955 		}
  22956 		VP8AdjustFilterStrength(tls, it) // ...and store filter stats.
  22957 	} else {
  22958 		// Something bad happened -> need to do some memory cleanup.
  22959 		VP8EncFreeBitWriters(tls, enc)
  22960 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  22961 	}
  22962 	return ok
  22963 }
  22964 
  22965 //------------------------------------------------------------------------------
  22966 //  VP8EncLoop(): does the final bitstream coding.
  22967 
  22968 func ResetAfterSkip(tls *libc.TLS, it uintptr) {
  22969 	if int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1) {
  22970 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = uint32(0) // reset all predictors
  22971 		**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  22972 	} else {
  22973 		**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) &= libc.Uint32FromInt32(libc.Int32FromInt32(1) << libc.Int32FromInt32(24)) // preserve the dc_nz bit
  22974 	}
  22975 }
  22976 
  22977 func VP8EncLoop(tls *libc.TLS, enc uintptr) (r int32) {
  22978 	bp := tls.Alloc(4736)
  22979 	defer tls.Free(4736)
  22980 	var dont_use_skip, ok int32
  22981 	var rd_opt VP8RDLevel
  22982 	var _ /* info at bp+3848 */ VP8ModeScore
  22983 	var _ /* it at bp+0 */ VP8EncIterator
  22984 	_, _, _ = dont_use_skip, ok, rd_opt
  22985 	ok = PreLoopInitialize(tls, enc)
  22986 	if !(ok != 0) {
  22987 		return 0
  22988 	}
  22989 	StatLoop(tls, enc) // stats-collection loop
  22990 	VP8IteratorInit(tls, enc, bp)
  22991 	VP8InitFilter(tls, bp)
  22992 	for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  22993 		dont_use_skip = libc.BoolInt32(!((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0))
  22994 		rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  22995 		VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  22996 		// Warning! order is important: first call VP8Decimate() and
  22997 		// *then* decide how to code the skip decision if there's one.
  22998 		if !(VP8Decimate(tls, bp, bp+3848, rd_opt) != 0) || dont_use_skip != 0 {
  22999 			CodeResiduals(tls, (**(**VP8EncIterator)(__ccgo_up(bp))).Fbw, bp, bp+3848)
  23000 			if (*VP8BitWriter)(unsafe.Pointer((**(**VP8EncIterator)(__ccgo_up(bp))).Fbw)).Ferror1 != 0 {
  23001 				// enc->pic->error_code is set in PostLoopFinalize().
  23002 				ok = 0
  23003 				break
  23004 			}
  23005 		} else { // reset predictors after a skip
  23006 			ResetAfterSkip(tls, bp)
  23007 		}
  23008 		StoreSideInfo(tls, bp)
  23009 		VP8StoreFilterStats(tls, bp)
  23010 		VP8IteratorExport(tls, bp)
  23011 		ok = VP8IteratorProgress(tls, bp, int32(20))
  23012 		VP8IteratorSaveBoundary(tls, bp)
  23013 	}
  23014 	return PostLoopFinalize(tls, bp, ok)
  23015 }
  23016 
  23017 //------------------------------------------------------------------------------
  23018 // Single pass using Token Buffer.
  23019 
  23020 func VP8EncTokenLoop(tls *libc.TLS, enc uintptr) (r int32) {
  23021 	bp := tls.Alloc(4784)
  23022 	defer tls.Free(4784)
  23023 	var cnt, do_search, is_last_pass, max_count, num_pass_left, ok, pass_progress, remaining_progress, v1 int32
  23024 	var distortion, pixel_count, size, size_p0 uint64_t
  23025 	var proba uintptr
  23026 	var rd_opt VP8RDLevel
  23027 	var v2 bool
  23028 	var _ /* info at bp+3904 */ VP8ModeScore
  23029 	var _ /* it at bp+0 */ VP8EncIterator
  23030 	var _ /* stats at bp+3848 */ PassStats
  23031 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  23032 	// Roughly refresh the proba eight times per pass
  23033 	max_count = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h >> int32(3)
  23034 	num_pass_left = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fpass
  23035 	remaining_progress = int32(40) // percents
  23036 	do_search = (*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search
  23037 	proba = enc + 3616
  23038 	rd_opt = (*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level
  23039 	pixel_count = libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) * libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) * uint64(384)
  23040 	InitPassStats(tls, enc, bp+3848)
  23041 	ok = PreLoopInitialize(tls, enc)
  23042 	if !(ok != 0) {
  23043 		return 0
  23044 	}
  23045 	if max_count < int32(MIN_COUNT) {
  23046 		max_count = int32(MIN_COUNT)
  23047 	}
  23048 	// otherwise, token-buffer won't be useful
  23049 	for {
  23050 		if v2 = ok != 0; v2 {
  23051 			v1 = num_pass_left
  23052 			num_pass_left = num_pass_left - 1
  23053 		}
  23054 		if !(v2 && v1 > 0) {
  23055 			break
  23056 		}
  23057 		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)
  23058 		size_p0 = uint64(0)
  23059 		distortion = uint64(0)
  23060 		cnt = max_count
  23061 		// The final number of passes is not trivial to know in advance.
  23062 		pass_progress = remaining_progress / (int32(2) + num_pass_left)
  23063 		remaining_progress = remaining_progress - pass_progress
  23064 		VP8IteratorInit(tls, enc, bp)
  23065 		SetLoopParams(tls, enc, (**(**PassStats)(__ccgo_up(bp + 3848))).Fq)
  23066 		if is_last_pass != 0 {
  23067 			ResetTokenStats(tls, enc)
  23068 			VP8InitFilter(tls, bp) // don't collect stats until last pass (too costly)
  23069 		}
  23070 		VP8TBufferClear(tls, enc+496)
  23071 		for cond := true; cond; cond = ok != 0 && VP8IteratorNext(tls, bp) != 0 {
  23072 			VP8IteratorImport(tls, bp, libc.UintptrFromInt32(0))
  23073 			cnt = cnt - 1
  23074 			v1 = cnt
  23075 			if v1 < 0 {
  23076 				FinalizeTokenProbas(tls, proba)
  23077 				VP8CalculateLevelCosts(tls, proba) // refresh cost tables for rd-opt
  23078 				cnt = max_count
  23079 			}
  23080 			VP8Decimate(tls, bp, bp+3904, rd_opt)
  23081 			ok = RecordTokens(tls, bp, bp+3904, enc+496)
  23082 			if !(ok != 0) {
  23083 				WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  23084 				break
  23085 			}
  23086 			size_p0 = size_p0 + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FH)
  23087 			distortion = distortion + libc.Uint64FromInt64((**(**VP8ModeScore)(__ccgo_up(bp + 3904))).FD)
  23088 			if is_last_pass != 0 {
  23089 				StoreSideInfo(tls, bp)
  23090 				VP8StoreFilterStats(tls, bp)
  23091 				VP8IteratorExport(tls, bp)
  23092 				ok = VP8IteratorProgress(tls, bp, pass_progress)
  23093 			}
  23094 			VP8IteratorSaveBoundary(tls, bp)
  23095 		}
  23096 		if !(ok != 0) {
  23097 			break
  23098 		}
  23099 		size_p0 = size_p0 + libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fsize)
  23100 		if (**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0 {
  23101 			size = libc.Uint64FromInt32(FinalizeTokenProbas(tls, enc+3616))
  23102 			size = size + VP8EstimateTokenSize(tls, enc+496, proba+4)
  23103 			size = (size + size_p0 + uint64(1024)) >> int32(11) // -> size in bytes
  23104 			size = size + libc.Uint64FromInt32(libc.Int32FromInt32(RIFF_HEADER_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8_FRAME_HEADER_SIZE))
  23105 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = float64(size)
  23106 		} else { // compute and store PSNR
  23107 			(**(**PassStats)(__ccgo_up(bp + 3848))).Fvalue = GetPSNR(tls, distortion, pixel_count)
  23108 		}
  23109 		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) {
  23110 			num_pass_left = num_pass_left + 1
  23111 			**(**int32)(__ccgo_up(enc + 23624)) >>= int32(1) // strengthen header bit limitation...
  23112 			if is_last_pass != 0 {
  23113 				ResetSideInfo(tls, bp)
  23114 			}
  23115 			continue // ...and start over
  23116 		}
  23117 		if is_last_pass != 0 {
  23118 			break // done
  23119 		}
  23120 		if do_search != 0 {
  23121 			ComputeNextQ(tls, bp+3848) // Adjust q
  23122 		}
  23123 	}
  23124 	if ok != 0 {
  23125 		if !((**(**PassStats)(__ccgo_up(bp + 3848))).Fdo_size_search != 0) {
  23126 			FinalizeTokenProbas(tls, enc+3616)
  23127 		}
  23128 		ok = VP8EmitTokens(tls, enc+496, enc+112+uintptr(0)*48, proba+4, int32(1))
  23129 	}
  23130 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+remaining_progress, enc+536) != 0)
  23131 	return PostLoopFinalize(tls, bp, ok)
  23132 }
  23133 
  23134 const MAX_HISTO_GREEDY = 100
  23135 const NUM_PARTITIONS = 4
  23136 
  23137 //------------------------------------------------------------------------------
  23138 
  23139 // Copyright 2012 Google Inc. All Rights Reserved.
  23140 //
  23141 // Use of this source code is governed by a BSD-style license
  23142 // that can be found in the COPYING file in the root of the source
  23143 // tree. An additional intellectual property rights grant can be found
  23144 // in the file PATENTS. All contributing project authors may
  23145 // be found in the AUTHORS file in the root of the source tree.
  23146 // -----------------------------------------------------------------------------
  23147 //
  23148 // Misc. common utility functions
  23149 //
  23150 // Authors: Skal (pascal.massimino@gmail.com)
  23151 //          Urvang (urvang@google.com)
  23152 
  23153 // Copyright 2011 Google Inc. All Rights Reserved.
  23154 //
  23155 // Use of this source code is governed by a BSD-style license
  23156 // that can be found in the COPYING file in the root of the source
  23157 // tree. An additional intellectual property rights grant can be found
  23158 // in the file PATENTS. All contributing project authors may
  23159 // be found in the AUTHORS file in the root of the source tree.
  23160 // -----------------------------------------------------------------------------
  23161 //
  23162 //   WebP encoder: main interface
  23163 //
  23164 // Author: Skal (pascal.massimino@gmail.com)
  23165 
  23166 // Copyright 2012 Google Inc. All Rights Reserved.
  23167 //
  23168 // Use of this source code is governed by a BSD-style license
  23169 // that can be found in the COPYING file in the root of the source
  23170 // tree. An additional intellectual property rights grant can be found
  23171 // in the file PATENTS. All contributing project authors may
  23172 // be found in the AUTHORS file in the root of the source tree.
  23173 // -----------------------------------------------------------------------------
  23174 //
  23175 //  Internal header for constants related to WebP file format.
  23176 //
  23177 // Author: Urvang (urvang@google.com)
  23178 
  23179 // Copyright 2010 Google Inc. All Rights Reserved.
  23180 //
  23181 // Use of this source code is governed by a BSD-style license
  23182 // that can be found in the COPYING file in the root of the source
  23183 // tree. An additional intellectual property rights grant can be found
  23184 // in the file PATENTS. All contributing project authors may
  23185 // be found in the AUTHORS file in the root of the source tree.
  23186 // -----------------------------------------------------------------------------
  23187 //
  23188 //  Common types + memory wrappers
  23189 //
  23190 // Author: Skal (pascal.massimino@gmail.com)
  23191 
  23192 // Number of partitions for the three dominant (literal, red and blue) symbol
  23193 // costs.
  23194 // The size of the bin-hash corresponding to the three dominant costs.
  23195 // Maximum number of histograms allowed in greedy combining algorithm.
  23196 
  23197 // C documentation
  23198 //
  23199 //	// Enum to meaningfully access the elements of the Histogram arrays.
  23200 type HistogramIndex = int32
  23201 
  23202 const LITERAL = 0
  23203 const DISTANCE = 4
  23204 
  23205 // C documentation
  23206 //
  23207 //	// Return the size of the histogram for a given cache_bits.
  23208 func GetHistogramSize(tls *libc.TLS, cache_bits int32) (r int32) {
  23209 	var literal_size, v1, v2, v4 int32
  23210 	var total_size size_t
  23211 	_, _, _, _, _ = literal_size, total_size, v1, v2, v4
  23212 	v1 = cache_bits
  23213 	if v1 > 0 {
  23214 		v4 = int32(1) << v1
  23215 	} else {
  23216 		v4 = 0
  23217 	}
  23218 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23219 	goto _3
  23220 _3:
  23221 	literal_size = v2
  23222 	total_size = uint64(3312) + uint64(4)*libc.Uint64FromInt32(literal_size)
  23223 	return libc.Int32FromUint64(total_size)
  23224 }
  23225 
  23226 func HistogramStatsClear(tls *libc.TLS, h uintptr) {
  23227 	var i int32
  23228 	_ = i
  23229 	i = 0
  23230 	for {
  23231 		if !(i < int32(5)) {
  23232 			break
  23233 		}
  23234 		**(**uint16_t)(__ccgo_up(h + 3244 + uintptr(i)*2)) = libc.Uint16FromInt32(libc.Int32FromInt32(0xffff))
  23235 		// By default, the histogram is assumed to be used.
  23236 		**(**uint8_t)(__ccgo_up(h + 3304 + uintptr(i))) = uint8(1)
  23237 		goto _1
  23238 	_1:
  23239 		;
  23240 		i = i + 1
  23241 	}
  23242 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = uint64(0)
  23243 	libc.Xmemset(tls, h+3264, 0, uint64(40))
  23244 }
  23245 
  23246 func HistogramClear(tls *libc.TLS, h uintptr) {
  23247 	var cache_bits, histo_size int32
  23248 	var literal uintptr
  23249 	_, _, _ = cache_bits, histo_size, literal
  23250 	literal = (*VP8LHistogram)(unsafe.Pointer(h)).Fliteral
  23251 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits
  23252 	histo_size = GetHistogramSize(tls, cache_bits)
  23253 	libc.Xmemset(tls, h, 0, libc.Uint64FromInt32(histo_size))
  23254 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = cache_bits
  23255 	(*VP8LHistogram)(unsafe.Pointer(h)).Fliteral = literal
  23256 	HistogramStatsClear(tls, h)
  23257 }
  23258 
  23259 // C documentation
  23260 //
  23261 //	// Swap two histogram pointers.
  23262 func HistogramSwap(tls *libc.TLS, h1 uintptr, h2 uintptr) {
  23263 	var tmp uintptr
  23264 	_ = tmp
  23265 	tmp = **(**uintptr)(__ccgo_up(h1))
  23266 	**(**uintptr)(__ccgo_up(h1)) = **(**uintptr)(__ccgo_up(h2))
  23267 	**(**uintptr)(__ccgo_up(h2)) = tmp
  23268 }
  23269 
  23270 func HistogramCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  23271 	var dst_cache_bits, histo_size, literal_size, v1, v2, v4 int32
  23272 	var dst_literal uintptr
  23273 	_, _, _, _, _, _, _ = dst_cache_bits, dst_literal, histo_size, literal_size, v1, v2, v4
  23274 	dst_literal = (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral
  23275 	dst_cache_bits = (*VP8LHistogram)(unsafe.Pointer(dst)).Fpalette_code_bits
  23276 	v1 = dst_cache_bits
  23277 	if v1 > 0 {
  23278 		v4 = int32(1) << v1
  23279 	} else {
  23280 		v4 = 0
  23281 	}
  23282 	v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23283 	goto _3
  23284 _3:
  23285 	literal_size = v2
  23286 	histo_size = GetHistogramSize(tls, dst_cache_bits)
  23287 	libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(histo_size))
  23288 	(*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral = dst_literal
  23289 	libc.Xmemcpy(tls, (*VP8LHistogram)(unsafe.Pointer(dst)).Fliteral, (*VP8LHistogram)(unsafe.Pointer(src)).Fliteral, libc.Uint64FromInt32(literal_size)*uint64(4))
  23290 }
  23291 
  23292 func VP8LFreeHistogram(tls *libc.TLS, h uintptr) {
  23293 	WebPSafeFree(tls, h)
  23294 }
  23295 
  23296 func VP8LFreeHistogramSet(tls *libc.TLS, histograms uintptr) {
  23297 	WebPSafeFree(tls, histograms)
  23298 }
  23299 
  23300 func VP8LHistogramCreate(tls *libc.TLS, h uintptr, refs uintptr, palette_code_bits int32) {
  23301 	if palette_code_bits >= 0 {
  23302 		(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23303 	}
  23304 	HistogramClear(tls, h)
  23305 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, h)
  23306 }
  23307 
  23308 func VP8LHistogramInit(tls *libc.TLS, h uintptr, palette_code_bits int32, init_arrays int32) {
  23309 	(*VP8LHistogram)(unsafe.Pointer(h)).Fpalette_code_bits = palette_code_bits
  23310 	if init_arrays != 0 {
  23311 		HistogramClear(tls, h)
  23312 	} else {
  23313 		HistogramStatsClear(tls, h)
  23314 	}
  23315 }
  23316 
  23317 func VP8LAllocateHistogram(tls *libc.TLS, cache_bits int32) (r uintptr) {
  23318 	var histo, memory uintptr
  23319 	var total_size int32
  23320 	_, _, _ = histo, memory, total_size
  23321 	histo = libc.UintptrFromInt32(0)
  23322 	total_size = GetHistogramSize(tls, cache_bits)
  23323 	memory = WebPSafeMalloc(tls, libc.Uint64FromInt32(total_size), uint64(1))
  23324 	if memory == libc.UintptrFromInt32(0) {
  23325 		return libc.UintptrFromInt32(0)
  23326 	}
  23327 	histo = memory
  23328 	// 'literal' won't necessary be aligned.
  23329 	(*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral = memory + libc.UintptrFromInt64(3312)
  23330 	VP8LHistogramInit(tls, histo, cache_bits, 0)
  23331 	return histo
  23332 }
  23333 
  23334 // C documentation
  23335 //
  23336 //	// Resets the pointers of the histograms to point to the bit buffer in the set.
  23337 func HistogramSetResetPointers(tls *libc.TLS, set uintptr, cache_bits int32) {
  23338 	var histo_size, i int32
  23339 	var memory uintptr
  23340 	_, _, _ = histo_size, i, memory
  23341 	histo_size = GetHistogramSize(tls, cache_bits)
  23342 	memory = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms
  23343 	memory = memory + uintptr(libc.Uint64FromInt32((*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size)*uint64(8))
  23344 	i = 0
  23345 	for {
  23346 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size) {
  23347 			break
  23348 		}
  23349 		memory = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23350 		**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)) = memory
  23351 		// 'literal' won't necessary be aligned.
  23352 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fliteral = memory + libc.UintptrFromInt64(3312)
  23353 		memory = memory + uintptr(histo_size)
  23354 		goto _1
  23355 	_1:
  23356 		;
  23357 		i = i + 1
  23358 	}
  23359 }
  23360 
  23361 // C documentation
  23362 //
  23363 //	// Returns the total size of the VP8LHistogramSet.
  23364 func HistogramSetTotalSize(tls *libc.TLS, size int32, cache_bits int32) (r size_t) {
  23365 	var histo_size int32
  23366 	_ = histo_size
  23367 	histo_size = GetHistogramSize(tls, cache_bits)
  23368 	return libc.Uint64FromInt64(16) + libc.Uint64FromInt32(size)*(libc.Uint64FromInt64(8)+libc.Uint64FromInt32(histo_size)+libc.Uint64FromInt32(WEBP_ALIGN_CST))
  23369 }
  23370 
  23371 func VP8LAllocateHistogramSet(tls *libc.TLS, size int32, cache_bits int32) (r uintptr) {
  23372 	var i int32
  23373 	var memory, set uintptr
  23374 	var total_size size_t
  23375 	_, _, _, _ = i, memory, set, total_size
  23376 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23377 	memory = WebPSafeMalloc(tls, total_size, uint64(1))
  23378 	if memory == libc.UintptrFromInt32(0) {
  23379 		return libc.UintptrFromInt32(0)
  23380 	}
  23381 	set = memory
  23382 	memory = memory + uintptr(16)
  23383 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23384 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23385 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23386 	HistogramSetResetPointers(tls, set, cache_bits)
  23387 	i = 0
  23388 	for {
  23389 		if !(i < size) {
  23390 			break
  23391 		}
  23392 		VP8LHistogramInit(tls, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)), cache_bits, 0)
  23393 		goto _1
  23394 	_1:
  23395 		;
  23396 		i = i + 1
  23397 	}
  23398 	return set
  23399 }
  23400 
  23401 func VP8LHistogramSetClear(tls *libc.TLS, set uintptr) {
  23402 	var cache_bits, i, size int32
  23403 	var memory uintptr
  23404 	var total_size size_t
  23405 	_, _, _, _, _ = cache_bits, i, memory, size, total_size
  23406 	cache_bits = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms)))).Fpalette_code_bits
  23407 	size = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size
  23408 	total_size = HistogramSetTotalSize(tls, size, cache_bits)
  23409 	memory = set
  23410 	libc.Xmemset(tls, memory, 0, total_size)
  23411 	memory = memory + uintptr(16)
  23412 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms = memory
  23413 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fmax_size = size
  23414 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = size
  23415 	HistogramSetResetPointers(tls, set, cache_bits)
  23416 	i = 0
  23417 	for {
  23418 		if !(i < size) {
  23419 			break
  23420 		}
  23421 		(*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(set)).Fhistograms + uintptr(i)*8)))).Fpalette_code_bits = cache_bits
  23422 		goto _1
  23423 	_1:
  23424 		;
  23425 		i = i + 1
  23426 	}
  23427 }
  23428 
  23429 // C documentation
  23430 //
  23431 //	// Removes the histogram 'i' from 'set'.
  23432 func HistogramSetRemoveHistogram(tls *libc.TLS, set uintptr, i int32) {
  23433 	**(**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))
  23434 	(*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(set)).Fsize - 1
  23435 }
  23436 
  23437 // -----------------------------------------------------------------------------
  23438 
  23439 func HistogramAddSinglePixOrCopy(tls *libc.TLS, histo uintptr, v uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32) {
  23440 	bp := tls.Alloc(16)
  23441 	defer tls.Free(16)
  23442 	var highest_bit, literal_ix, second_highest_bit, v1, v11, v17, v20 int32
  23443 	var prefix_code VP8LPrefixCode
  23444 	var v3 uint32_t
  23445 	var v18, v19 uintptr
  23446 	var _ /* code at bp+0 */ int32
  23447 	var _ /* extra_bits at bp+4 */ int32
  23448 	_, _, _, _, _, _, _, _, _, _, _ = highest_bit, literal_ix, prefix_code, second_highest_bit, v1, v11, v17, v18, v19, v20, v3
  23449 	v1 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  23450 	goto _2
  23451 _2:
  23452 	if v1 != 0 {
  23453 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(3) * libc.Int32FromInt32(8)) & uint32(0xff)
  23454 		goto _4
  23455 	_4:
  23456 		**(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 2056 + uintptr(v3)*4)) + 1
  23457 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(2) * libc.Int32FromInt32(8)) & uint32(0xff)
  23458 		goto _6
  23459 	_6:
  23460 		**(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 8 + uintptr(v3)*4)) + 1
  23461 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (int32(1) * libc.Int32FromInt32(8)) & uint32(0xff)
  23462 		goto _8
  23463 	_8:
  23464 		**(**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
  23465 		v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (0 * libc.Int32FromInt32(8)) & uint32(0xff)
  23466 		goto _10
  23467 	_10:
  23468 		**(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) = **(**uint32_t)(__ccgo_up(histo + 1032 + uintptr(v3)*4)) + 1
  23469 	} else {
  23470 		v1 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  23471 		goto _12
  23472 	_12:
  23473 		if v1 != 0 {
  23474 			v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23475 			goto _14
  23476 		_14:
  23477 			literal_ix = libc.Int32FromUint32(libc.Uint32FromInt32(libc.Int32FromInt32(NUM_LITERAL_CODES)+libc.Int32FromInt32(NUM_LENGTH_CODES)) + v3)
  23478 			**(**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
  23479 		} else {
  23480 			v3 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  23481 			goto _16
  23482 		_16:
  23483 			v1 = libc.Int32FromUint32(v3)
  23484 			v18 = bp
  23485 			v19 = bp + 4
  23486 			if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23487 				prefix_code = kPrefixEncodeCode[v1]
  23488 				**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23489 				**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23490 			} else {
  23491 				v11 = v1
  23492 				v11 = v11 - 1
  23493 				v17 = v11
  23494 				v20 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v17))
  23495 				goto _23
  23496 			_23:
  23497 				highest_bit = v20
  23498 				second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23499 				**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23500 				**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23501 			}
  23502 			**(**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
  23503 			if __ccgo_fp_distance_modifier == libc.UintptrFromInt32(0) {
  23504 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23505 				goto _25
  23506 			_25:
  23507 				v1 = libc.Int32FromUint32(v3)
  23508 				v18 = bp
  23509 				v19 = bp + 4
  23510 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23511 					prefix_code = kPrefixEncodeCode[v1]
  23512 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23513 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23514 				} else {
  23515 					v11 = v1
  23516 					v11 = v11 - 1
  23517 					v17 = v11
  23518 					v20 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v17))
  23519 					goto _32
  23520 				_32:
  23521 					highest_bit = v20
  23522 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23523 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23524 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23525 				}
  23526 			} else {
  23527 				v3 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  23528 				goto _34
  23529 			_34:
  23530 				v1 = (*(*func(*libc.TLS, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_distance_modifier})))(tls, distance_modifier_arg0, libc.Int32FromUint32(v3))
  23531 				v18 = bp
  23532 				v19 = bp + 4
  23533 				if v1 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  23534 					prefix_code = kPrefixEncodeCode[v1]
  23535 					**(**int32)(__ccgo_up(v18)) = int32(prefix_code.Fcode)
  23536 					**(**int32)(__ccgo_up(v19)) = int32(prefix_code.Fextra_bits)
  23537 				} else {
  23538 					v11 = v1
  23539 					v11 = v11 - 1
  23540 					v17 = v11
  23541 					v20 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v17))
  23542 					goto _41
  23543 				_41:
  23544 					highest_bit = v20
  23545 					second_highest_bit = v11 >> (highest_bit - int32(1)) & int32(1)
  23546 					**(**int32)(__ccgo_up(v19)) = highest_bit - int32(1)
  23547 					**(**int32)(__ccgo_up(v18)) = int32(2)*highest_bit + second_highest_bit
  23548 				}
  23549 			}
  23550 			**(**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
  23551 		}
  23552 	}
  23553 }
  23554 
  23555 type __ccgo_fp__XVP8LHistogramStoreRefs_1 = func(*libc.TLS, int32, int32) int32
  23556 
  23557 func VP8LHistogramStoreRefs(tls *libc.TLS, refs uintptr, __ccgo_fp_distance_modifier uintptr, distance_modifier_arg0 int32, histo uintptr) {
  23558 	bp := tls.Alloc(32)
  23559 	defer tls.Free(32)
  23560 	var v1 int32
  23561 	var v3, v4, v5 uintptr
  23562 	var _ /* c at bp+0 */ VP8LRefsCursor
  23563 	_, _, _, _ = v1, v3, v4, v5
  23564 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  23565 	for {
  23566 		v1 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  23567 		goto _2
  23568 	_2:
  23569 		if !(v1 != 0) {
  23570 			break
  23571 		}
  23572 		HistogramAddSinglePixOrCopy(tls, histo, (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos, __ccgo_fp_distance_modifier, distance_modifier_arg0)
  23573 		v3 = bp
  23574 		v5 = v3
  23575 		*(*uintptr)(unsafe.Pointer(v5)) += 8
  23576 		v4 = *(*uintptr)(unsafe.Pointer(v5))
  23577 		if v4 == (*VP8LRefsCursor)(unsafe.Pointer(v3)).Flast_pos {
  23578 			VP8LRefsCursorNextBlock(tls, v3)
  23579 		}
  23580 	}
  23581 }
  23582 
  23583 // -----------------------------------------------------------------------------
  23584 // Entropy-related functions.
  23585 
  23586 func BitsEntropyRefine(tls *libc.TLS, entropy uintptr) (r uint64_t) {
  23587 	var min_limit, mix uint64_t
  23588 	var v1, v2, v3 int64_t
  23589 	var v5 int64
  23590 	var v11 uint64
  23591 	_, _, _, _, _, _, _ = min_limit, mix, v1, v11, v2, v3, v5
  23592 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros < int32(5) {
  23593 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros <= int32(1) {
  23594 			return uint64(0)
  23595 		}
  23596 		// Two symbols, they will be 0 and 1 in a Huffman code.
  23597 		// Let's mix in a bit of entropy to favor good clustering when
  23598 		// distributions of these are combined.
  23599 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(2) {
  23600 			v1 = libc.Int64FromUint64(uint64(99)*(uint64((*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23601 			v2 = int64(100)
  23602 			if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23603 				v5 = (v1 + v2/int64(2)) / v2
  23604 			} else {
  23605 				v5 = (v1 - v2/int64(2)) / v2
  23606 			}
  23607 			v3 = v5
  23608 			goto _4
  23609 		_4:
  23610 			return libc.Uint64FromInt64(v3)
  23611 		}
  23612 		// No matter what the entropy says, we cannot be better than min_limit
  23613 		// with Huffman coding. I am mixing a bit of entropy into the
  23614 		// min_limit since it produces much better (~0.5 %) compression results
  23615 		// perhaps because of better entropy clustering.
  23616 		if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros == int32(3) {
  23617 			mix = uint64(950)
  23618 		} else {
  23619 			mix = uint64(700) // nonzeros == 4.
  23620 		}
  23621 	} else {
  23622 		mix = uint64(627)
  23623 	}
  23624 	min_limit = uint64(libc.Uint32FromInt32(2)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum-(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val) << int32(LOG_2_PRECISION_BITS)
  23625 	v1 = libc.Int64FromUint64(mix*min_limit + (uint64(1000)-mix)*(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy)
  23626 	v2 = int64(1000)
  23627 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23628 		v5 = (v1 + v2/int64(2)) / v2
  23629 	} else {
  23630 		v5 = (v1 - v2/int64(2)) / v2
  23631 	}
  23632 	v3 = v5
  23633 	goto _9
  23634 _9:
  23635 	min_limit = libc.Uint64FromInt64(v3)
  23636 	if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy < min_limit {
  23637 		v11 = min_limit
  23638 	} else {
  23639 		v11 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  23640 	}
  23641 	return v11
  23642 	return r
  23643 }
  23644 
  23645 func VP8LBitsEntropy(tls *libc.TLS, array uintptr, n int32) (r uint64_t) {
  23646 	bp := tls.Alloc(32)
  23647 	defer tls.Free(32)
  23648 	var _ /* entropy at bp+0 */ VP8LBitEntropy
  23649 	VP8LBitsEntropyUnrefined(tls, array, n, bp)
  23650 	return BitsEntropyRefine(tls, bp)
  23651 }
  23652 
  23653 func InitialHuffmanCost(tls *libc.TLS) (r uint64_t) {
  23654 	var v1, v2, v3 int64_t
  23655 	var v5 int64
  23656 	_, _, _, _ = v1, v2, v3, v5
  23657 	// Subtract a bias of 9.1.
  23658 	v1 = int64(libc.Int64FromInt64(91) << libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  23659 	v2 = int64(10)
  23660 	if libc.BoolInt32(v1 < 0) == libc.BoolInt32(v2 < 0) {
  23661 		v5 = (v1 + v2/int64(2)) / v2
  23662 	} else {
  23663 		v5 = (v1 - v2/int64(2)) / v2
  23664 	}
  23665 	v3 = v5
  23666 	goto _4
  23667 _4:
  23668 	return kHuffmanCodeOfHuffmanCodeSize<<libc.Int32FromInt32(LOG_2_PRECISION_BITS) - libc.Uint64FromInt64(v3)
  23669 }
  23670 
  23671 // Small bias because Huffman code length is typically not stored in
  23672 // full length.
  23673 var kHuffmanCodeOfHuffmanCodeSize = libc.Uint64FromInt32(libc.Int32FromInt32(CODE_LENGTH_CODES) * libc.Int32FromInt32(3))
  23674 
  23675 // C documentation
  23676 //
  23677 //	// Finalize the Huffman cost based on streak numbers and length type (<3 or >=3)
  23678 func FinalHuffmanCost(tls *libc.TLS, stats uintptr) (r uint64_t) {
  23679 	var retval uint64_t
  23680 	var retval_extra uint32_t
  23681 	_, _ = retval, retval_extra
  23682 	// The constants in this function are empirical and got rounded from
  23683 	// their original values in 1/8 when switched to 1/1024.
  23684 	retval = InitialHuffmanCost(tls)
  23685 	// Second coefficient: Many zeros in the histogram are covered efficiently
  23686 	// by a run-length encode. Originally 2/8.
  23687 	retval_extra = libc.Uint32FromInt32(**(**int32)(__ccgo_up(stats))*int32(1600) + int32(240)***(**int32)(__ccgo_up(stats + 8 + 1*4)))
  23688 	// Second coefficient: Constant values are encoded less efficiently, but still
  23689 	// RLE'ed. Originally 6/8.
  23690 	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)))
  23691 	// 0s are usually encoded more efficiently than non-0s.
  23692 	// Originally 15/8.
  23693 	retval_extra = retval_extra + libc.Uint32FromInt32(int32(1840)***(**int32)(__ccgo_up(stats + 8)))
  23694 	// Originally 26/8.
  23695 	retval_extra = retval_extra + libc.Uint32FromInt32(int32(3360)***(**int32)(__ccgo_up(stats + 8 + 1*8)))
  23696 	return retval + uint64(retval_extra)<<(libc.Int32FromInt32(LOG_2_PRECISION_BITS)-libc.Int32FromInt32(10))
  23697 }
  23698 
  23699 // C documentation
  23700 //
  23701 //	// Get the symbol entropy for the distribution 'population'.
  23702 //	// Set 'trivial_sym', if there's only one symbol present in the distribution.
  23703 func PopulationCost(tls *libc.TLS, population uintptr, length int32, trivial_sym uintptr, is_used uintptr) (r uint64_t) {
  23704 	bp := tls.Alloc(48)
  23705 	defer tls.Free(48)
  23706 	var v1 uint32
  23707 	var _ /* bit_entropy at bp+0 */ VP8LBitEntropy
  23708 	var _ /* stats at bp+24 */ VP8LStreaks
  23709 	_ = v1
  23710 	(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LGetEntropyUnrefined})))(tls, population, length, bp, bp+24)
  23711 	if trivial_sym != libc.UintptrFromInt32(0) {
  23712 		if (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzeros == int32(1) {
  23713 			v1 = (**(**VP8LBitEntropy)(__ccgo_up(bp))).Fnonzero_code
  23714 		} else {
  23715 			v1 = uint32(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff)))
  23716 		}
  23717 		**(**uint16_t)(__ccgo_up(trivial_sym)) = uint16(v1)
  23718 	}
  23719 	if is_used != libc.UintptrFromInt32(0) {
  23720 		// The histogram is used if there is at least one non-zero streak.
  23721 		**(**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)
  23722 	}
  23723 	return BitsEntropyRefine(tls, bp) + FinalHuffmanCost(tls, bp+24)
  23724 }
  23725 
  23726 func GetPopulationInfo(tls *libc.TLS, histo uintptr, index HistogramIndex, population uintptr, length uintptr) {
  23727 	var v1, v2, v4 int32
  23728 	_, _, _ = v1, v2, v4
  23729 	switch index {
  23730 	case int32(LITERAL):
  23731 		**(**uintptr)(__ccgo_up(population)) = (*VP8LHistogram)(unsafe.Pointer(histo)).Fliteral
  23732 		v1 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  23733 		if v1 > 0 {
  23734 			v4 = int32(1) << v1
  23735 		} else {
  23736 			v4 = 0
  23737 		}
  23738 		v2 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v4
  23739 		goto _3
  23740 	_3:
  23741 		**(**int32)(__ccgo_up(length)) = v2
  23742 	case int32(RED):
  23743 		**(**uintptr)(__ccgo_up(population)) = histo + 8
  23744 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23745 	case int32(BLUE):
  23746 		**(**uintptr)(__ccgo_up(population)) = histo + 1032
  23747 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23748 	case int32(ALPHA):
  23749 		**(**uintptr)(__ccgo_up(population)) = histo + 2056
  23750 		**(**int32)(__ccgo_up(length)) = int32(NUM_LITERAL_CODES)
  23751 	case int32(DISTANCE):
  23752 		**(**uintptr)(__ccgo_up(population)) = histo + 3080
  23753 		**(**int32)(__ccgo_up(length)) = int32(NUM_DISTANCE_CODES)
  23754 		break
  23755 	}
  23756 }
  23757 
  23758 // C documentation
  23759 //
  23760 //	// trivial_at_end is 1 if the two histograms only have one element that is
  23761 //	// non-zero: both the zero-th one, or both the last one.
  23762 //	// 'index' is the index of the symbol in the histogram (literal, red, blue,
  23763 //	// alpha, distance).
  23764 func GetCombinedEntropy(tls *libc.TLS, h1 uintptr, h2 uintptr, index HistogramIndex) (r uint64_t) {
  23765 	bp := tls.Alloc(80)
  23766 	defer tls.Free(80)
  23767 	var is_h1_used, is_h2_used, is_trivial int32
  23768 	var _ /* X at bp+0 */ uintptr
  23769 	var _ /* Y at bp+8 */ uintptr
  23770 	var _ /* bit_entropy at bp+48 */ VP8LBitEntropy
  23771 	var _ /* length at bp+16 */ int32
  23772 	var _ /* stats at bp+20 */ VP8LStreaks
  23773 	_, _, _ = is_h1_used, is_h2_used, is_trivial
  23774 	is_h1_used = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(index))))
  23775 	is_h2_used = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(index))))
  23776 	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))))
  23777 	if is_trivial != 0 || !(is_h1_used != 0) || !(is_h2_used != 0) {
  23778 		if is_h1_used != 0 {
  23779 			return **(**uint64_t)(__ccgo_up(h1 + 3264 + uintptr(index)*8))
  23780 		}
  23781 		return **(**uint64_t)(__ccgo_up(h2 + 3264 + uintptr(index)*8))
  23782 	}
  23783 	GetPopulationInfo(tls, h1, index, bp, bp+16)
  23784 	GetPopulationInfo(tls, h2, index, bp+8, bp+16)
  23785 	(*(*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)
  23786 	return BitsEntropyRefine(tls, bp+48) + FinalHuffmanCost(tls, bp+20)
  23787 }
  23788 
  23789 // C documentation
  23790 //
  23791 //	// Estimates the Entropy + Huffman + other block overhead size cost.
  23792 func VP8LHistogramEstimateBits(tls *libc.TLS, h uintptr) (r uint64_t) {
  23793 	bp := tls.Alloc(16)
  23794 	defer tls.Free(16)
  23795 	var cost uint64_t
  23796 	var i int32
  23797 	var _ /* length at bp+0 */ int32
  23798 	var _ /* population at bp+8 */ uintptr
  23799 	_, _ = cost, i
  23800 	cost = uint64(0)
  23801 	i = 0
  23802 	for {
  23803 		if !(i < int32(5)) {
  23804 			break
  23805 		}
  23806 		GetPopulationInfo(tls, h, i, bp+8, bp)
  23807 		cost = cost + PopulationCost(tls, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp)), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
  23808 		goto _1
  23809 	_1:
  23810 		;
  23811 		i = i + 1
  23812 	}
  23813 	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)
  23814 	return cost
  23815 }
  23816 
  23817 // -----------------------------------------------------------------------------
  23818 // Various histogram combine/cost-eval functions
  23819 
  23820 // C documentation
  23821 //
  23822 //	// Set a + b in b, saturating at WEBP_INT64_MAX.
  23823 func SaturateAdd(tls *libc.TLS, a uint64_t, b uintptr) {
  23824 	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)) {
  23825 		**(**int64_t)(__ccgo_up(b)) += libc.Int64FromUint64(a)
  23826 	} else {
  23827 		**(**int64_t)(__ccgo_up(b)) = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  23828 	}
  23829 }
  23830 
  23831 // C documentation
  23832 //
  23833 //	// Returns 1 if the cost of the combined histogram is less than the threshold.
  23834 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23835 func GetCombinedHistogramEntropy(tls *libc.TLS, a uintptr, b uintptr, cost_threshold_in int64_t, cost uintptr, costs uintptr) (r int32) {
  23836 	var cost_threshold uint64_t
  23837 	var i int32
  23838 	_, _ = cost_threshold, i
  23839 	cost_threshold = libc.Uint64FromInt64(cost_threshold_in)
  23840 	if cost_threshold_in <= 0 {
  23841 		return 0
  23842 	}
  23843 	**(**uint64_t)(__ccgo_up(cost)) = uint64(0)
  23844 	// No need to add the extra cost for length and distance as it is a constant
  23845 	// that does not influence the histograms.
  23846 	i = 0
  23847 	for {
  23848 		if !(i < int32(5)) {
  23849 			break
  23850 		}
  23851 		**(**uint64_t)(__ccgo_up(costs + uintptr(i)*8)) = GetCombinedEntropy(tls, a, b, i)
  23852 		**(**uint64_t)(__ccgo_up(cost)) += **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  23853 		if **(**uint64_t)(__ccgo_up(cost)) >= cost_threshold {
  23854 			return 0
  23855 		}
  23856 		goto _1
  23857 	_1:
  23858 		;
  23859 		i = i + 1
  23860 	}
  23861 	return int32(1)
  23862 }
  23863 
  23864 func HistogramAdd(tls *libc.TLS, h1 uintptr, h2 uintptr, hout uintptr) {
  23865 	bp := tls.Alloc(32)
  23866 	defer tls.Free(32)
  23867 	var i, v3 int32
  23868 	var pout uintptr
  23869 	var _ /* length at bp+0 */ int32
  23870 	var _ /* p1 at bp+8 */ uintptr
  23871 	var _ /* p2 at bp+16 */ uintptr
  23872 	var _ /* pout_const at bp+24 */ uintptr
  23873 	_, _, _ = i, pout, v3
  23874 	i = 0
  23875 	for {
  23876 		if !(i < int32(5)) {
  23877 			break
  23878 		}
  23879 		GetPopulationInfo(tls, h1, i, bp+8, bp)
  23880 		GetPopulationInfo(tls, h2, i, bp+16, bp)
  23881 		GetPopulationInfo(tls, hout, i, bp+24, bp)
  23882 		pout = **(**uintptr)(__ccgo_up(bp + 24))
  23883 		if h2 == hout {
  23884 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23885 				if **(**uint8_t)(__ccgo_up(hout + 3304 + uintptr(i))) != 0 {
  23886 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pout, **(**int32)(__ccgo_up(bp)))
  23887 				} else {
  23888 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23889 				}
  23890 			}
  23891 		} else {
  23892 			if **(**uint8_t)(__ccgo_up(h1 + 3304 + uintptr(i))) != 0 {
  23893 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23894 					(*(*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)))
  23895 				} else {
  23896 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 8)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23897 				}
  23898 			} else {
  23899 				if **(**uint8_t)(__ccgo_up(h2 + 3304 + uintptr(i))) != 0 {
  23900 					libc.Xmemcpy(tls, pout, **(**uintptr)(__ccgo_up(bp + 16)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23901 				} else {
  23902 					libc.Xmemset(tls, pout, 0, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4))
  23903 				}
  23904 			}
  23905 		}
  23906 		goto _1
  23907 	_1:
  23908 		;
  23909 		i = i + 1
  23910 	}
  23911 	i = 0
  23912 	for {
  23913 		if !(i < int32(5)) {
  23914 			break
  23915 		}
  23916 		if libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2))) == libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h2 + 3244 + uintptr(i)*2))) {
  23917 			v3 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(h1 + 3244 + uintptr(i)*2)))
  23918 		} else {
  23919 			v3 = libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff)))
  23920 		}
  23921 		**(**uint16_t)(__ccgo_up(hout + 3244 + uintptr(i)*2)) = libc.Uint16FromInt32(v3)
  23922 		**(**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)
  23923 		goto _2
  23924 	_2:
  23925 		;
  23926 		i = i + 1
  23927 	}
  23928 }
  23929 
  23930 func UpdateHistogramCost(tls *libc.TLS, bit_cost uint64_t, costs uintptr, h uintptr) {
  23931 	var i int32
  23932 	_ = i
  23933 	(*VP8LHistogram)(unsafe.Pointer(h)).Fbit_cost = bit_cost
  23934 	i = 0
  23935 	for {
  23936 		if !(i < int32(5)) {
  23937 			break
  23938 		}
  23939 		**(**uint64_t)(__ccgo_up(h + 3264 + uintptr(i)*8)) = **(**uint64_t)(__ccgo_up(costs + uintptr(i)*8))
  23940 		goto _1
  23941 	_1:
  23942 		;
  23943 		i = i + 1
  23944 	}
  23945 }
  23946 
  23947 // C documentation
  23948 //
  23949 //	// Performs out = a + b, computing the cost C(a+b) - C(a) - C(b) while comparing
  23950 //	// to the threshold value 'cost_threshold'. The score returned is
  23951 //	//  Score = C(a+b) - C(a) - C(b), where C(a) + C(b) is known and fixed.
  23952 //	// Since the previous score passed is 'cost_threshold', we only need to compare
  23953 //	// the partial cost against 'cost_threshold + C(a) + C(b)' to possibly bail-out
  23954 //	// early.
  23955 //	// Returns 1 if the cost is less than the threshold.
  23956 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23957 func HistogramAddEval(tls *libc.TLS, a uintptr, b uintptr, out uintptr, _cost_threshold int64_t) (r int32) {
  23958 	bp := tls.Alloc(64)
  23959 	defer tls.Free(64)
  23960 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  23961 	var sum_cost uint64_t
  23962 	var _ /* bit_cost at bp+8 */ uint64_t
  23963 	var _ /* costs at bp+16 */ [5]uint64_t
  23964 	_ = sum_cost
  23965 	sum_cost = (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(b)).Fbit_cost
  23966 	SaturateAdd(tls, sum_cost, bp)
  23967 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  23968 		return 0
  23969 	}
  23970 	HistogramAdd(tls, a, b, out)
  23971 	UpdateHistogramCost(tls, **(**uint64_t)(__ccgo_up(bp + 8)), bp+16, out)
  23972 	return int32(1)
  23973 }
  23974 
  23975 // C documentation
  23976 //
  23977 //	// Same as HistogramAddEval(), except that the resulting histogram
  23978 //	// is not stored. Only the cost C(a+b) - C(a) is evaluated. We omit
  23979 //	// the term C(b) which is constant over all the evaluations.
  23980 //	// Returns 1 if the cost is less than the threshold.
  23981 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  23982 func HistogramAddThresh(tls *libc.TLS, a uintptr, b uintptr, _cost_threshold int64_t, cost_out uintptr) (r int32) {
  23983 	bp := tls.Alloc(64)
  23984 	defer tls.Free(64)
  23985 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  23986 	var _ /* cost at bp+8 */ uint64_t
  23987 	var _ /* costs at bp+16 */ [5]uint64_t
  23988 	SaturateAdd(tls, (*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost, bp)
  23989 	if !(GetCombinedHistogramEntropy(tls, a, b, **(**int64_t)(__ccgo_up(bp)), bp+8, bp+16) != 0) {
  23990 		return 0
  23991 	}
  23992 	**(**int64_t)(__ccgo_up(cost_out)) = libc.Int64FromUint64(**(**uint64_t)(__ccgo_up(bp + 8))) - libc.Int64FromUint64((*VP8LHistogram)(unsafe.Pointer(a)).Fbit_cost)
  23993 	return int32(1)
  23994 }
  23995 
  23996 // -----------------------------------------------------------------------------
  23997 
  23998 // C documentation
  23999 //
  24000 //	// The structure to keep track of cost range for the three dominant entropy
  24001 //	// symbols.
  24002 type DominantCostRange = struct {
  24003 	Fliteral_max uint64_t
  24004 	Fliteral_min uint64_t
  24005 	Fred_max     uint64_t
  24006 	Fred_min     uint64_t
  24007 	Fblue_max    uint64_t
  24008 	Fblue_min    uint64_t
  24009 }
  24010 
  24011 func DominantCostRangeInit(tls *libc.TLS, c uintptr) {
  24012 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = uint64(0)
  24013 	(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = uint64(^libc.Uint64FromUint64(0))
  24014 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = uint64(0)
  24015 	(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = uint64(^libc.Uint64FromUint64(0))
  24016 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = uint64(0)
  24017 	(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = uint64(^libc.Uint64FromUint64(0))
  24018 }
  24019 
  24020 func UpdateDominantCostRange(tls *libc.TLS, h uintptr, c uintptr) {
  24021 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  24022 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  24023 	}
  24024 	if (*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8)) {
  24025 		(*DominantCostRange)(unsafe.Pointer(c)).Fliteral_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(LITERAL)*8))
  24026 	}
  24027 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  24028 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  24029 	}
  24030 	if (*DominantCostRange)(unsafe.Pointer(c)).Fred_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8)) {
  24031 		(*DominantCostRange)(unsafe.Pointer(c)).Fred_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(RED)*8))
  24032 	}
  24033 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_max < **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  24034 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_max = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  24035 	}
  24036 	if (*DominantCostRange)(unsafe.Pointer(c)).Fblue_min > **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8)) {
  24037 		(*DominantCostRange)(unsafe.Pointer(c)).Fblue_min = **(**uint64_t)(__ccgo_up(h + 3264 + uintptr(BLUE)*8))
  24038 	}
  24039 }
  24040 
  24041 func ComputeHistogramCost(tls *libc.TLS, h uintptr) {
  24042 	bp := tls.Alloc(16)
  24043 	defer tls.Free(16)
  24044 	var i int32
  24045 	var _ /* length at bp+8 */ int32
  24046 	var _ /* population at bp+0 */ uintptr
  24047 	_ = i
  24048 	// No need to add the extra cost for length and distance as it is a constant
  24049 	// that does not influence the histograms.
  24050 	i = 0
  24051 	for {
  24052 		if !(i < int32(5)) {
  24053 			break
  24054 		}
  24055 		GetPopulationInfo(tls, h, i, bp, bp+8)
  24056 		**(**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))
  24057 		goto _1
  24058 	_1:
  24059 		;
  24060 		i = i + 1
  24061 	}
  24062 	(*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))
  24063 }
  24064 
  24065 func GetBinIdForEntropy(tls *libc.TLS, min uint64_t, max uint64_t, val uint64_t) (r int32) {
  24066 	var delta, range1 uint64_t
  24067 	_, _ = delta, range1
  24068 	range1 = max - min
  24069 	if range1 > uint64(0) {
  24070 		delta = val - min
  24071 		return int32(float64((libc.Float64FromInt32(NUM_PARTITIONS)-libc.Float64FromFloat64(1e-06))*float64(delta)) / float64(range1))
  24072 	} else {
  24073 		return 0
  24074 	}
  24075 	return r
  24076 }
  24077 
  24078 func GetHistoBinIndex(tls *libc.TLS, h uintptr, c uintptr, low_effort int32) (r int32) {
  24079 	var bin_id int32
  24080 	_ = bin_id
  24081 	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)))
  24082 	if !(low_effort != 0) {
  24083 		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)))
  24084 		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)))
  24085 	}
  24086 	return bin_id
  24087 }
  24088 
  24089 // C documentation
  24090 //
  24091 //	// Construct the histograms from backward references.
  24092 func HistogramBuild(tls *libc.TLS, xsize int32, histo_bits int32, backward_refs uintptr, image_histo uintptr) {
  24093 	bp := tls.Alloc(32)
  24094 	defer tls.Free(32)
  24095 	var histo_xsize, ix, x, y, v4 int32
  24096 	var histograms, v, v10, v8, v9 uintptr
  24097 	var v1, v2 uint32_t
  24098 	var _ /* c at bp+0 */ VP8LRefsCursor
  24099 	_, _, _, _, _, _, _, _, _, _, _, _ = histo_xsize, histograms, ix, v, x, y, v1, v10, v2, v4, v8, v9
  24100 	x = 0
  24101 	y = 0
  24102 	v1 = libc.Uint32FromInt32(histo_bits)
  24103 	v2 = (libc.Uint32FromInt32(xsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  24104 	goto _3
  24105 _3:
  24106 	histo_xsize = libc.Int32FromUint32(v2)
  24107 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24108 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, backward_refs)
  24109 	VP8LHistogramSetClear(tls, image_histo)
  24110 	for {
  24111 		v4 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  24112 		goto _5
  24113 	_5:
  24114 		if !(v4 != 0) {
  24115 			break
  24116 		}
  24117 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  24118 		ix = y>>histo_bits*histo_xsize + x>>histo_bits
  24119 		HistogramAddSinglePixOrCopy(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(ix)*8)), v, libc.UintptrFromInt32(0), 0)
  24120 		v1 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  24121 		goto _7
  24122 	_7:
  24123 		x = libc.Int32FromUint32(uint32(x) + v1)
  24124 		for x >= xsize {
  24125 			x = x - xsize
  24126 			y = y + 1
  24127 		}
  24128 		v8 = bp
  24129 		v10 = v8
  24130 		*(*uintptr)(unsafe.Pointer(v10)) += 8
  24131 		v9 = *(*uintptr)(unsafe.Pointer(v10))
  24132 		if v9 == (*VP8LRefsCursor)(unsafe.Pointer(v8)).Flast_pos {
  24133 			VP8LRefsCursorNextBlock(tls, v8)
  24134 		}
  24135 	}
  24136 }
  24137 
  24138 // C documentation
  24139 //
  24140 //	// Copies the histograms and computes its bit_cost.
  24141 func HistogramCopyAndAnalyze(tls *libc.TLS, orig_histo uintptr, image_histo uintptr) {
  24142 	var histo, histograms, orig_histograms uintptr
  24143 	var i int32
  24144 	_, _, _, _ = histo, histograms, i, orig_histograms
  24145 	orig_histograms = (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fhistograms
  24146 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24147 	(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = 0
  24148 	i = 0
  24149 	for {
  24150 		if !(i < (*VP8LHistogramSet)(unsafe.Pointer(orig_histo)).Fmax_size) {
  24151 			break
  24152 		}
  24153 		histo = **(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8))
  24154 		ComputeHistogramCost(tls, histo)
  24155 		// Skip the histogram if it is completely empty, which can happen for tiles
  24156 		// with no information (when they are skipped because of LZ77).
  24157 		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) {
  24158 			// The first histogram is always used.
  24159 			**(**uintptr)(__ccgo_up(orig_histograms + uintptr(i)*8)) = libc.UintptrFromInt32(0)
  24160 		} else {
  24161 			// Copy histograms from orig_histo[] to image_histo[].
  24162 			HistogramCopy(tls, histo, **(**uintptr)(__ccgo_up(histograms + uintptr((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)*8)))
  24163 			(*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize + 1
  24164 		}
  24165 		goto _1
  24166 	_1:
  24167 		;
  24168 		i = i + 1
  24169 	}
  24170 }
  24171 
  24172 // C documentation
  24173 //
  24174 //	// Partition histograms to different entropy bins for three dominant (literal,
  24175 //	// red and blue) symbol costs and compute the histogram aggregate bit_cost.
  24176 func HistogramAnalyzeEntropyBin(tls *libc.TLS, image_histo uintptr, low_effort int32) {
  24177 	bp := tls.Alloc(48)
  24178 	defer tls.Free(48)
  24179 	var histo_size, i int32
  24180 	var histograms uintptr
  24181 	var _ /* cost_range at bp+0 */ DominantCostRange
  24182 	_, _, _ = histo_size, histograms, i
  24183 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24184 	histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24185 	DominantCostRangeInit(tls, bp)
  24186 	// Analyze the dominant (literal, red and blue) entropy costs.
  24187 	i = 0
  24188 	for {
  24189 		if !(i < histo_size) {
  24190 			break
  24191 		}
  24192 		UpdateDominantCostRange(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(i)*8)), bp)
  24193 		goto _1
  24194 	_1:
  24195 		;
  24196 		i = i + 1
  24197 	}
  24198 	// bin-hash histograms on three of the dominant (literal, red and blue)
  24199 	// symbol costs and store the resulting bin_id for each histogram.
  24200 	i = 0
  24201 	for {
  24202 		if !(i < histo_size) {
  24203 			break
  24204 		}
  24205 		(*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))
  24206 		goto _2
  24207 	_2:
  24208 		;
  24209 		i = i + 1
  24210 	}
  24211 }
  24212 
  24213 // C documentation
  24214 //
  24215 //	// Merges some histograms with same bin_id together if it's advantageous.
  24216 //	// Sets the remaining histograms to NULL.
  24217 //	// 'combine_cost_factor' has to be divided by 100.
  24218 func HistogramCombineEntropyBin(tls *libc.TLS, image_histo uintptr, _cur_combo uintptr, num_bins int32, combine_cost_factor int32_t, low_effort int32) {
  24219 	bp := tls.Alloc(16)
  24220 	defer tls.Free(16)
  24221 	*(*uintptr)(unsafe.Pointer(bp)) = _cur_combo
  24222 	var bin_id, first, idx, max_combine_failures, try_combine int32
  24223 	var bin_info [64]struct {
  24224 		Ffirst                int16_t
  24225 		Fnum_combine_failures uint16_t
  24226 	}
  24227 	var bit_cost uint64_t
  24228 	var bit_cost_thresh, v3, v4, v5 int64_t
  24229 	var histograms uintptr
  24230 	var v7 int64
  24231 	_, _, _, _, _, _, _, _, _, _, _, _, _ = bin_id, bin_info, bit_cost, bit_cost_thresh, first, histograms, idx, max_combine_failures, try_combine, v3, v4, v5, v7
  24232 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24233 	idx = 0
  24234 	for {
  24235 		if !(idx < num_bins) {
  24236 			break
  24237 		}
  24238 		bin_info[idx].Ffirst = int16(-int32(1))
  24239 		bin_info[idx].Fnum_combine_failures = uint16(0)
  24240 		goto _1
  24241 	_1:
  24242 		;
  24243 		idx = idx + 1
  24244 	}
  24245 	idx = 0
  24246 	for {
  24247 		if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24248 			break
  24249 		}
  24250 		bin_id = libc.Int32FromUint16((*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbin_id)
  24251 		first = int32(bin_info[bin_id].Ffirst)
  24252 		if first == -int32(1) {
  24253 			bin_info[bin_id].Ffirst = int16(idx)
  24254 			idx = idx + 1
  24255 		} else {
  24256 			if low_effort != 0 {
  24257 				HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(first)*8)))
  24258 				HistogramSetRemoveHistogram(tls, image_histo, idx)
  24259 			} else {
  24260 				// try to merge #idx into #first (both share the same bin_id)
  24261 				bit_cost = (*VP8LHistogram)(unsafe.Pointer(**(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))).Fbit_cost
  24262 				v3 = libc.Int64FromUint64(bit_cost) * int64(combine_cost_factor)
  24263 				v4 = int64(100)
  24264 				if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  24265 					v7 = (v3 + v4/int64(2)) / v4
  24266 				} else {
  24267 					v7 = (v3 - v4/int64(2)) / v4
  24268 				}
  24269 				v5 = v7
  24270 				goto _6
  24271 			_6:
  24272 				bit_cost_thresh = -v5
  24273 				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 {
  24274 					max_combine_failures = int32(32)
  24275 					// Try to merge two histograms only if the combo is a trivial one or
  24276 					// the two candidate histograms are already non-trivial.
  24277 					// For some images, 'try_combine' turns out to be false for a lot of
  24278 					// histogram pairs. In that case, we fallback to combining
  24279 					// histograms as usual to avoid increasing the header size.
  24280 					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))))
  24281 					if !(try_combine != 0) {
  24282 						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))))
  24283 						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))))
  24284 					}
  24285 					if try_combine != 0 || libc.Int32FromUint16(bin_info[bin_id].Fnum_combine_failures) >= max_combine_failures {
  24286 						// move the (better) merged histogram to its final slot
  24287 						HistogramSwap(tls, bp, histograms+uintptr(first)*8)
  24288 						HistogramSetRemoveHistogram(tls, image_histo, idx)
  24289 					} else {
  24290 						bin_info[bin_id].Fnum_combine_failures = bin_info[bin_id].Fnum_combine_failures + 1
  24291 						idx = idx + 1
  24292 					}
  24293 				} else {
  24294 					idx = idx + 1
  24295 				}
  24296 			}
  24297 		}
  24298 		goto _2
  24299 	_2:
  24300 	}
  24301 	if low_effort != 0 {
  24302 		// for low_effort case, update the final cost when everything is merged
  24303 		idx = 0
  24304 		for {
  24305 			if !(idx < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24306 				break
  24307 			}
  24308 			ComputeHistogramCost(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx)*8)))
  24309 			goto _8
  24310 		_8:
  24311 			;
  24312 			idx = idx + 1
  24313 		}
  24314 	}
  24315 }
  24316 
  24317 // C documentation
  24318 //
  24319 //	// Implement a Lehmer random number generator with a multiplicative constant of
  24320 //	// 48271 and a modulo constant of 2^31 - 1.
  24321 func MyRand(tls *libc.TLS, seed uintptr) (r uint32_t) {
  24322 	**(**uint32_t)(__ccgo_up(seed)) = uint32(uint64(**(**uint32_t)(__ccgo_up(seed))) * libc.Uint64FromUint32(48271) % libc.Uint64FromUint32(2147483647))
  24323 	return **(**uint32_t)(__ccgo_up(seed))
  24324 }
  24325 
  24326 // -----------------------------------------------------------------------------
  24327 // Histogram pairs priority queue
  24328 
  24329 // C documentation
  24330 //
  24331 //	// Pair of histograms. Negative idx1 value means that pair is out-of-date.
  24332 type HistogramPair = struct {
  24333 	Fidx1       int32
  24334 	Fidx2       int32
  24335 	Fcost_diff  int64_t
  24336 	Fcost_combo uint64_t
  24337 	Fcosts      [5]uint64_t
  24338 }
  24339 
  24340 type HistoQueue = struct {
  24341 	Fqueue    uintptr
  24342 	Fsize     int32
  24343 	Fmax_size int32
  24344 }
  24345 
  24346 func HistoQueueInit(tls *libc.TLS, histo_queue uintptr, max_size int32) (r int32) {
  24347 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24348 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = max_size
  24349 	// We allocate max_size + 1 because the last element at index "size" is
  24350 	// used as temporary data (and it could be up to max_size).
  24351 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue = WebPSafeMalloc(tls, libc.Uint64FromInt32((*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size+int32(1)), uint64(64))
  24352 	return libc.BoolInt32((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue != libc.UintptrFromInt32(0))
  24353 }
  24354 
  24355 func HistoQueueClear(tls *libc.TLS, histo_queue uintptr) {
  24356 	WebPSafeFree(tls, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)
  24357 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = 0
  24358 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size = 0
  24359 }
  24360 
  24361 // C documentation
  24362 //
  24363 //	// Pop a specific pair in the queue by replacing it with the last one
  24364 //	// and shrinking the queue.
  24365 func HistoQueuePopPair(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24366 	**(**HistogramPair)(__ccgo_up(pair)) = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64))
  24367 	(*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize = (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize - 1
  24368 }
  24369 
  24370 // C documentation
  24371 //
  24372 //	// Check whether a pair in the queue should be updated as head or not.
  24373 func HistoQueueUpdateHead(tls *libc.TLS, histo_queue uintptr, pair uintptr) {
  24374 	var tmp HistogramPair
  24375 	_ = tmp
  24376 	if (*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff < (**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))).Fcost_diff {
  24377 		// Replace the best pair.
  24378 		tmp = **(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue))
  24379 		**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue)) = **(**HistogramPair)(__ccgo_up(pair))
  24380 		**(**HistogramPair)(__ccgo_up(pair)) = tmp
  24381 	}
  24382 }
  24383 
  24384 // C documentation
  24385 //
  24386 //	// Replaces the bad_id with good_id in the pair.
  24387 func HistoQueueFixPair(tls *libc.TLS, bad_id int32, good_id int32, pair uintptr) {
  24388 	var tmp int32
  24389 	_ = tmp
  24390 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 == bad_id {
  24391 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = good_id
  24392 	}
  24393 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 == bad_id {
  24394 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = good_id
  24395 	}
  24396 	if (*HistogramPair)(unsafe.Pointer(pair)).Fidx1 > (*HistogramPair)(unsafe.Pointer(pair)).Fidx2 {
  24397 		tmp = (*HistogramPair)(unsafe.Pointer(pair)).Fidx1
  24398 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx1 = (*HistogramPair)(unsafe.Pointer(pair)).Fidx2
  24399 		(*HistogramPair)(unsafe.Pointer(pair)).Fidx2 = tmp
  24400 	}
  24401 }
  24402 
  24403 // C documentation
  24404 //
  24405 //	// Update the cost diff and combo of a pair of histograms. This needs to be
  24406 //	// called when the histograms have been merged with a third one.
  24407 //	// Returns 1 if the cost diff is less than the threshold.
  24408 //	// Otherwise returns 0 and the cost is invalid due to early bail-out.
  24409 func HistoQueueUpdatePair(tls *libc.TLS, h1 uintptr, h2 uintptr, _cost_threshold int64_t, pair uintptr) (r int32) {
  24410 	bp := tls.Alloc(16)
  24411 	defer tls.Free(16)
  24412 	*(*int64_t)(unsafe.Pointer(bp)) = _cost_threshold
  24413 	var sum_cost int64_t
  24414 	_ = sum_cost
  24415 	sum_cost = libc.Int64FromUint64((*VP8LHistogram)(unsafe.Pointer(h1)).Fbit_cost + (*VP8LHistogram)(unsafe.Pointer(h2)).Fbit_cost)
  24416 	SaturateAdd(tls, libc.Uint64FromInt64(sum_cost), bp)
  24417 	if !(GetCombinedHistogramEntropy(tls, h1, h2, **(**int64_t)(__ccgo_up(bp)), pair+16, pair+24) != 0) {
  24418 		return 0
  24419 	}
  24420 	(*HistogramPair)(unsafe.Pointer(pair)).Fcost_diff = libc.Int64FromUint64((*HistogramPair)(unsafe.Pointer(pair)).Fcost_combo) - sum_cost
  24421 	return int32(1)
  24422 }
  24423 
  24424 // C documentation
  24425 //
  24426 //	// Create a pair from indices "idx1" and "idx2" provided its cost
  24427 //	// is inferior to "threshold", a negative entropy.
  24428 //	// It returns the cost of the pair, or 0 if it superior to threshold.
  24429 func HistoQueuePush(tls *libc.TLS, histo_queue uintptr, histograms uintptr, idx1 int32, idx2 int32, threshold int64_t) (r int64_t) {
  24430 	bp := tls.Alloc(64)
  24431 	defer tls.Free(64)
  24432 	var h1, h2, v2 uintptr
  24433 	var tmp, v1 int32
  24434 	var _ /* pair at bp+0 */ HistogramPair
  24435 	_, _, _, _, _ = h1, h2, tmp, v1, v2
  24436 	// Stop here if the queue is full.
  24437 	if (*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize == (*HistoQueue)(unsafe.Pointer(histo_queue)).Fmax_size {
  24438 		return 0
  24439 	}
  24440 	if idx1 > idx2 {
  24441 		tmp = idx2
  24442 		idx2 = idx1
  24443 		idx1 = tmp
  24444 	}
  24445 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx1 = idx1
  24446 	(**(**HistogramPair)(__ccgo_up(bp))).Fidx2 = idx2
  24447 	h1 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8))
  24448 	h2 = **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8))
  24449 	// Do not even consider the pair if it does not improve the entropy.
  24450 	if !(HistoQueueUpdatePair(tls, h1, h2, threshold, bp) != 0) {
  24451 		return 0
  24452 	}
  24453 	v2 = histo_queue + 8
  24454 	v1 = *(*int32)(unsafe.Pointer(v2))
  24455 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  24456 	**(**HistogramPair)(__ccgo_up((*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue + uintptr(v1)*64)) = **(**HistogramPair)(__ccgo_up(bp))
  24457 	HistoQueueUpdateHead(tls, histo_queue, (*HistoQueue)(unsafe.Pointer(histo_queue)).Fqueue+uintptr((*HistoQueue)(unsafe.Pointer(histo_queue)).Fsize-int32(1))*64)
  24458 	return (**(**HistogramPair)(__ccgo_up(bp))).Fcost_diff
  24459 }
  24460 
  24461 // -----------------------------------------------------------------------------
  24462 
  24463 // C documentation
  24464 //
  24465 //	// Combines histograms by continuously choosing the one with the highest cost
  24466 //	// reduction.
  24467 func HistogramCombineGreedy(tls *libc.TLS, image_histo uintptr) (r int32) {
  24468 	bp := tls.Alloc(16)
  24469 	defer tls.Free(16)
  24470 	var histograms, p uintptr
  24471 	var i, idx1, idx2, image_histo_size, j, ok int32
  24472 	var _ /* histo_queue at bp+0 */ HistoQueue
  24473 	_, _, _, _, _, _, _, _ = histograms, i, idx1, idx2, image_histo_size, j, ok, p
  24474 	ok = 0
  24475 	image_histo_size = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24476 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24477 	// image_histo_size^2 for the queue size is safe. If you look at
  24478 	// HistogramCombineGreedy, and imagine that UpdateQueueFront always pushes
  24479 	// data to the queue, you insert at most:
  24480 	// - image_histo_size*(image_histo_size-1)/2 (the first two for loops)
  24481 	// - image_histo_size - 1 in the last for loop at the first iteration of
  24482 	//   the while loop, image_histo_size - 2 at the second iteration ...
  24483 	//   therefore image_histo_size*(image_histo_size-1)/2 overall too
  24484 	if !(HistoQueueInit(tls, bp, image_histo_size*image_histo_size) != 0) {
  24485 		goto End
  24486 	}
  24487 	// Initialize the queue.
  24488 	i = 0
  24489 	for {
  24490 		if !(i < image_histo_size) {
  24491 			break
  24492 		}
  24493 		j = i + int32(1)
  24494 		for {
  24495 			if !(j < image_histo_size) {
  24496 				break
  24497 			}
  24498 			HistoQueuePush(tls, bp, histograms, i, j, 0)
  24499 			goto _2
  24500 		_2:
  24501 			;
  24502 			j = j + 1
  24503 		}
  24504 		goto _1
  24505 	_1:
  24506 		;
  24507 		i = i + 1
  24508 	}
  24509 	for (**(**HistoQueue)(__ccgo_up(bp))).Fsize > 0 {
  24510 		idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx1
  24511 		idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp))).Fqueue))).Fidx2
  24512 		HistogramAdd(tls, **(**uintptr)(__ccgo_up(histograms + uintptr(idx2)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)), **(**uintptr)(__ccgo_up(histograms + uintptr(idx1)*8)))
  24513 		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)))
  24514 		// Remove merged histogram.
  24515 		HistogramSetRemoveHistogram(tls, image_histo, idx2)
  24516 		// Remove pairs intersecting the just combined best pair.
  24517 		i = 0
  24518 		for {
  24519 			if !(i < (**(**HistoQueue)(__ccgo_up(bp))).Fsize) {
  24520 				break
  24521 			}
  24522 			p = (**(**HistoQueue)(__ccgo_up(bp))).Fqueue + uintptr(i)*64
  24523 			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 {
  24524 				HistoQueuePopPair(tls, bp, p)
  24525 			} else {
  24526 				HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, idx2, p)
  24527 				HistoQueueUpdateHead(tls, bp, p)
  24528 				i = i + 1
  24529 			}
  24530 			goto _3
  24531 		_3:
  24532 		}
  24533 		// Push new pairs formed with combined histogram to the queue.
  24534 		i = 0
  24535 		for {
  24536 			if !(i < (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize) {
  24537 				break
  24538 			}
  24539 			if i == idx1 {
  24540 				goto _4
  24541 			}
  24542 			HistoQueuePush(tls, bp, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms, idx1, i, 0)
  24543 			goto _4
  24544 		_4:
  24545 			;
  24546 			i = i + 1
  24547 		}
  24548 	}
  24549 	ok = int32(1)
  24550 	goto End
  24551 End:
  24552 	;
  24553 	HistoQueueClear(tls, bp)
  24554 	return ok
  24555 }
  24556 
  24557 // C documentation
  24558 //
  24559 //	// Perform histogram aggregation using a stochastic approach.
  24560 //	// 'do_greedy' is set to 1 if a greedy approach needs to be performed
  24561 //	// afterwards, 0 otherwise.
  24562 func HistogramCombineStochastic(tls *libc.TLS, image_histo uintptr, min_cluster_size int32, do_greedy uintptr) (r int32) {
  24563 	bp := tls.Alloc(32)
  24564 	defer tls.Free(32)
  24565 	var best_cost, curr_cost int64_t
  24566 	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
  24567 	var histograms, p uintptr
  24568 	var idx1, idx2, rand_range, tmp uint32_t
  24569 	var v3 bool
  24570 	var v4 int64
  24571 	var _ /* histo_queue at bp+8 */ HistoQueue
  24572 	var _ /* seed at bp+0 */ uint32_t
  24573 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  24574 	**(**uint32_t)(__ccgo_up(bp)) = uint32(1)
  24575 	tries_with_no_success = 0
  24576 	outer_iters = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize
  24577 	num_tries_no_success = outer_iters / int32(2)
  24578 	histograms = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fhistograms
  24579 	kHistoQueueSize = int32(9)
  24580 	ok = 0
  24581 	if (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize < min_cluster_size {
  24582 		**(**int32)(__ccgo_up(do_greedy)) = int32(1)
  24583 		return int32(1)
  24584 	}
  24585 	if !(HistoQueueInit(tls, bp+8, kHistoQueueSize) != 0) {
  24586 		goto End
  24587 	}
  24588 	// Collapse similar histograms in 'image_histo'.
  24589 	iter = 0
  24590 	for {
  24591 		if v3 = iter < outer_iters && (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= min_cluster_size; v3 {
  24592 			tries_with_no_success = tries_with_no_success + 1
  24593 			v2 = tries_with_no_success
  24594 		}
  24595 		if !(v3 && v2 < num_tries_no_success) {
  24596 			break
  24597 		}
  24598 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24599 			v4 = 0
  24600 		} else {
  24601 			v4 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fcost_diff
  24602 		}
  24603 		best_cost = v4
  24604 		best_idx1 = -int32(1)
  24605 		best_idx2 = int32(1)
  24606 		rand_range = libc.Uint32FromInt32(((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize - int32(1)) * (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize)
  24607 		// (image_histo->size) / 2 was chosen empirically. Less means faster but
  24608 		// worse compression.
  24609 		num_tries = (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize / int32(2)
  24610 		// Pick random samples.
  24611 		j = 0
  24612 		for {
  24613 			if !((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize >= int32(2) && j < num_tries) {
  24614 				break
  24615 			}
  24616 			// Choose two different histograms at random and try to combine them.
  24617 			tmp = MyRand(tls, bp) % rand_range
  24618 			idx1 = tmp / libc.Uint32FromInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24619 			idx2 = tmp % libc.Uint32FromInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize-libc.Int32FromInt32(1))
  24620 			if idx2 >= idx1 {
  24621 				idx2 = idx2 + 1
  24622 			}
  24623 			// Calculate cost reduction on combination.
  24624 			curr_cost = HistoQueuePush(tls, bp+8, histograms, libc.Int32FromUint32(idx1), libc.Int32FromUint32(idx2), best_cost)
  24625 			if curr_cost < 0 { // found a better pair?
  24626 				best_cost = curr_cost
  24627 				// Empty the queue if we reached full capacity.
  24628 				if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == (**(**HistoQueue)(__ccgo_up(bp + 8))).Fmax_size {
  24629 					break
  24630 				}
  24631 			}
  24632 			goto _5
  24633 		_5:
  24634 			;
  24635 			j = j + 1
  24636 		}
  24637 		if (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize == 0 {
  24638 			goto _1
  24639 		}
  24640 		// Get the best histograms.
  24641 		best_idx1 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx1
  24642 		best_idx2 = (**(**HistogramPair)(__ccgo_up((**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue))).Fidx2
  24643 		// Merge the histograms and remove best_idx2 from the queue.
  24644 		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)))
  24645 		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)))
  24646 		HistogramSetRemoveHistogram(tls, image_histo, best_idx2)
  24647 		// Parse the queue and update each pair that deals with best_idx1,
  24648 		// best_idx2 or image_histo_size.
  24649 		j = 0
  24650 		for {
  24651 			if !(j < (**(**HistoQueue)(__ccgo_up(bp + 8))).Fsize) {
  24652 				break
  24653 			}
  24654 			p = (**(**HistoQueue)(__ccgo_up(bp + 8))).Fqueue + uintptr(j)*64
  24655 			is_idx1_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx1 == best_idx2)
  24656 			is_idx2_best = libc.BoolInt32((*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx1 || (*HistogramPair)(unsafe.Pointer(p)).Fidx2 == best_idx2)
  24657 			// The front pair could have been duplicated by a random pick so
  24658 			// check for it all the time nevertheless.
  24659 			if is_idx1_best != 0 && is_idx2_best != 0 {
  24660 				HistoQueuePopPair(tls, bp+8, p)
  24661 				goto _6
  24662 			}
  24663 			// Any pair containing one of the two best indices should only refer to
  24664 			// best_idx1. Its cost should also be updated.
  24665 			if is_idx1_best != 0 || is_idx2_best != 0 {
  24666 				HistoQueueFixPair(tls, best_idx2, best_idx1, p)
  24667 				// Re-evaluate the cost of an updated pair.
  24668 				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) {
  24669 					HistoQueuePopPair(tls, bp+8, p)
  24670 					goto _6
  24671 				}
  24672 			}
  24673 			HistoQueueFixPair(tls, (*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize, best_idx2, p)
  24674 			HistoQueueUpdateHead(tls, bp+8, p)
  24675 			j = j + 1
  24676 			goto _6
  24677 		_6:
  24678 		}
  24679 		tries_with_no_success = 0
  24680 		goto _1
  24681 	_1:
  24682 		;
  24683 		iter = iter + 1
  24684 	}
  24685 	**(**int32)(__ccgo_up(do_greedy)) = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize <= min_cluster_size)
  24686 	ok = int32(1)
  24687 	goto End
  24688 End:
  24689 	;
  24690 	HistoQueueClear(tls, bp+8)
  24691 	return ok
  24692 }
  24693 
  24694 // -----------------------------------------------------------------------------
  24695 // Histogram refinement
  24696 
  24697 // C documentation
  24698 //
  24699 //	// Find the best 'out' histogram for each of the 'in' histograms.
  24700 //	// At call-time, 'out' contains the histograms of the clusters.
  24701 //	// Note: we assume that out[]->bit_cost is already up-to-date.
  24702 func HistogramRemap(tls *libc.TLS, in uintptr, out uintptr, symbols uintptr) {
  24703 	bp := tls.Alloc(16)
  24704 	defer tls.Free(16)
  24705 	var best_bits int64_t
  24706 	var best_out, i, idx, in_size, k, out_size int32
  24707 	var in_histo, out_histo uintptr
  24708 	var _ /* cur_bits at bp+0 */ int64_t
  24709 	_, _, _, _, _, _, _, _, _ = best_bits, best_out, i, idx, in_histo, in_size, k, out_histo, out_size
  24710 	in_histo = (*VP8LHistogramSet)(unsafe.Pointer(in)).Fhistograms
  24711 	out_histo = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fhistograms
  24712 	in_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fmax_size
  24713 	out_size = (*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize
  24714 	if out_size > int32(1) {
  24715 		i = 0
  24716 		for {
  24717 			if !(i < in_size) {
  24718 				break
  24719 			}
  24720 			best_out = 0
  24721 			best_bits = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  24722 			if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24723 				// Arbitrarily set to the previous value if unused to help future LZ77.
  24724 				**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(symbols + uintptr(i-int32(1))*4))
  24725 				goto _1
  24726 			}
  24727 			k = 0
  24728 			for {
  24729 				if !(k < out_size) {
  24730 					break
  24731 				}
  24732 				if HistogramAddThresh(tls, **(**uintptr)(__ccgo_up(out_histo + uintptr(k)*8)), **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)), best_bits, bp) != 0 {
  24733 					best_bits = **(**int64_t)(__ccgo_up(bp))
  24734 					best_out = k
  24735 				}
  24736 				goto _2
  24737 			_2:
  24738 				;
  24739 				k = k + 1
  24740 			}
  24741 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = libc.Uint32FromInt32(best_out)
  24742 			goto _1
  24743 		_1:
  24744 			;
  24745 			i = i + 1
  24746 		}
  24747 	} else {
  24748 		i = 0
  24749 		for {
  24750 			if !(i < in_size) {
  24751 				break
  24752 			}
  24753 			**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)) = uint32(0)
  24754 			goto _3
  24755 		_3:
  24756 			;
  24757 			i = i + 1
  24758 		}
  24759 	}
  24760 	// Recompute each out based on raw and symbols.
  24761 	VP8LHistogramSetClear(tls, out)
  24762 	(*VP8LHistogramSet)(unsafe.Pointer(out)).Fsize = out_size
  24763 	i = 0
  24764 	for {
  24765 		if !(i < in_size) {
  24766 			break
  24767 		}
  24768 		if **(**uintptr)(__ccgo_up(in_histo + uintptr(i)*8)) == libc.UintptrFromInt32(0) {
  24769 			goto _4
  24770 		}
  24771 		idx = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(symbols + uintptr(i)*4)))
  24772 		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)))
  24773 		goto _4
  24774 	_4:
  24775 		;
  24776 		i = i + 1
  24777 	}
  24778 }
  24779 
  24780 func GetCombineCostFactor(tls *libc.TLS, histo_size int32, quality int32) (r int32_t) {
  24781 	var combine_cost_factor int32_t
  24782 	_ = combine_cost_factor
  24783 	combine_cost_factor = int32(16)
  24784 	if quality < int32(90) {
  24785 		if histo_size > int32(256) {
  24786 			combine_cost_factor = combine_cost_factor / int32(2)
  24787 		}
  24788 		if histo_size > int32(512) {
  24789 			combine_cost_factor = combine_cost_factor / int32(2)
  24790 		}
  24791 		if histo_size > int32(1024) {
  24792 			combine_cost_factor = combine_cost_factor / int32(2)
  24793 		}
  24794 		if quality <= int32(50) {
  24795 			combine_cost_factor = combine_cost_factor / int32(2)
  24796 		}
  24797 	}
  24798 	return combine_cost_factor
  24799 }
  24800 
  24801 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) {
  24802 	bp := tls.Alloc(16)
  24803 	defer tls.Free(16)
  24804 	var combine_cost_factor int32_t
  24805 	var entropy_combine, entropy_combine_num_bins, histo_xsize, histo_ysize, image_histo_raw_size, threshold_size, v9 int32
  24806 	var orig_histo uintptr
  24807 	var v1, v5 uint32
  24808 	var v10, v11, v12 int64_t
  24809 	var v14 int64
  24810 	var v2, v3, v6, v7 uint32_t
  24811 	var _ /* do_greedy at bp+0 */ int32
  24812 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  24813 	if histogram_bits != 0 {
  24814 		v2 = libc.Uint32FromInt32(histogram_bits)
  24815 		v3 = (libc.Uint32FromInt32(xsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  24816 		goto _4
  24817 	_4:
  24818 		v1 = v3
  24819 	} else {
  24820 		v1 = uint32(1)
  24821 	}
  24822 	histo_xsize = libc.Int32FromUint32(v1)
  24823 	if histogram_bits != 0 {
  24824 		v6 = libc.Uint32FromInt32(histogram_bits)
  24825 		v7 = (libc.Uint32FromInt32(ysize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  24826 		goto _8
  24827 	_8:
  24828 		v5 = v7
  24829 	} else {
  24830 		v5 = uint32(1)
  24831 	}
  24832 	histo_ysize = libc.Int32FromUint32(v5)
  24833 	image_histo_raw_size = histo_xsize * histo_ysize
  24834 	orig_histo = VP8LAllocateHistogramSet(tls, image_histo_raw_size, cache_bits)
  24835 	if low_effort != 0 {
  24836 		v9 = int32(NUM_PARTITIONS)
  24837 	} else {
  24838 		v9 = libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS) * libc.Int32FromInt32(NUM_PARTITIONS)
  24839 	}
  24840 	// Don't attempt linear bin-partition heuristic for
  24841 	// histograms of small sizes (as bin_map will be very sparse) and
  24842 	// maximum quality q==100 (to preserve the compression gains at that level).
  24843 	entropy_combine_num_bins = v9
  24844 	if orig_histo == libc.UintptrFromInt32(0) {
  24845 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24846 		goto Error
  24847 	}
  24848 	// Construct the histograms from backward references.
  24849 	HistogramBuild(tls, xsize, histogram_bits, refs, orig_histo)
  24850 	HistogramCopyAndAnalyze(tls, orig_histo, image_histo)
  24851 	entropy_combine = libc.BoolInt32((*VP8LHistogramSet)(unsafe.Pointer(image_histo)).Fsize > entropy_combine_num_bins*int32(2) && quality < int32(100))
  24852 	if entropy_combine != 0 {
  24853 		combine_cost_factor = GetCombineCostFactor(tls, image_histo_raw_size, quality)
  24854 		HistogramAnalyzeEntropyBin(tls, image_histo, low_effort)
  24855 		// Collapse histograms with similar entropy.
  24856 		HistogramCombineEntropyBin(tls, image_histo, tmp_histo, entropy_combine_num_bins, combine_cost_factor, low_effort)
  24857 	}
  24858 	// Don't combine the histograms using stochastic and greedy heuristics for
  24859 	// low-effort compression mode.
  24860 	if !(low_effort != 0) || !(entropy_combine != 0) {
  24861 		v10 = int64(quality * quality * quality * (libc.Int32FromInt32(MAX_HISTO_GREEDY) - libc.Int32FromInt32(1)))
  24862 		v11 = int64(libc.Int32FromInt32(100) * libc.Int32FromInt32(100) * libc.Int32FromInt32(100))
  24863 		if libc.BoolInt32(v10 < 0) == libc.BoolInt32(v11 < 0) {
  24864 			v14 = (v10 + v11/int64(2)) / v11
  24865 		} else {
  24866 			v14 = (v10 - v11/int64(2)) / v11
  24867 		}
  24868 		v12 = v14
  24869 		goto _13
  24870 	_13:
  24871 		// cubic ramp between 1 and MAX_HISTO_GREEDY:
  24872 		threshold_size = int32(libc.Int64FromInt32(1) + v12)
  24873 		if !(HistogramCombineStochastic(tls, image_histo, threshold_size, bp) != 0) {
  24874 			WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24875 			goto Error
  24876 		}
  24877 		if **(**int32)(__ccgo_up(bp)) != 0 {
  24878 			if !(HistogramCombineGreedy(tls, image_histo) != 0) {
  24879 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  24880 				goto Error
  24881 			}
  24882 		}
  24883 	}
  24884 	// Find the optimal map from original histograms to the final ones.
  24885 	HistogramRemap(tls, orig_histo, image_histo, histogram_symbols)
  24886 	if !(WebPReportProgress(tls, pic, **(**int32)(__ccgo_up(percent))+percent_range, percent) != 0) {
  24887 		goto Error
  24888 	}
  24889 	goto Error
  24890 Error:
  24891 	;
  24892 	VP8LFreeHistogramSet(tls, orig_histo)
  24893 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  24894 }
  24895 
  24896 //------------------------------------------------------------------------------
  24897 
  24898 // Copyright 2012 Google Inc. All Rights Reserved.
  24899 //
  24900 // Use of this source code is governed by a BSD-style license
  24901 // that can be found in the COPYING file in the root of the source
  24902 // tree. An additional intellectual property rights grant can be found
  24903 // in the file PATENTS. All contributing project authors may
  24904 // be found in the AUTHORS file in the root of the source tree.
  24905 // -----------------------------------------------------------------------------
  24906 //
  24907 // Misc. common utility functions
  24908 //
  24909 // Authors: Skal (pascal.massimino@gmail.com)
  24910 //          Urvang (urvang@google.com)
  24911 
  24912 // Copyright 2010 Google Inc. All Rights Reserved.
  24913 //
  24914 // Use of this source code is governed by a BSD-style license
  24915 // that can be found in the COPYING file in the root of the source
  24916 // tree. An additional intellectual property rights grant can be found
  24917 // in the file PATENTS. All contributing project authors may
  24918 // be found in the AUTHORS file in the root of the source tree.
  24919 // -----------------------------------------------------------------------------
  24920 //
  24921 //  Common types + memory wrappers
  24922 //
  24923 // Author: Skal (pascal.massimino@gmail.com)
  24924 
  24925 //------------------------------------------------------------------------------
  24926 // VP8Iterator
  24927 //------------------------------------------------------------------------------
  24928 
  24929 func InitLeft(tls *libc.TLS, it uintptr) {
  24930 	var v1, v2 uint8_t
  24931 	var v3 int32
  24932 	_, _, _ = v1, v2, v3
  24933 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy > 0 {
  24934 		v3 = int32(129)
  24935 	} else {
  24936 		v3 = int32(127)
  24937 	}
  24938 	v2 = libc.Uint8FromInt32(v3)
  24939 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  24940 	v1 = v2
  24941 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  24942 	**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  24943 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, int32(129), uint64(16))
  24944 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, int32(129), uint64(8))
  24945 	libc.Xmemset(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, int32(129), uint64(8))
  24946 	**(**int32)(__ccgo_up(it + 168 + 8*4)) = 0
  24947 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  24948 		libc.Xmemset(tls, it+344, 0, uint64(4))
  24949 	}
  24950 }
  24951 
  24952 func InitTop(tls *libc.TLS, it uintptr) {
  24953 	var enc uintptr
  24954 	var top_size size_t
  24955 	_, _ = enc, top_size
  24956 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24957 	top_size = libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * int32(16))
  24958 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top, int32(127), uint64(2)*top_size)
  24959 	libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fnz, 0, libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  24960 	if (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr != libc.UintptrFromInt32(0) {
  24961 		libc.Xmemset(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr, 0, libc.Uint64FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*uint64(4))
  24962 	}
  24963 }
  24964 
  24965 func VP8IteratorSetRow(tls *libc.TLS, it uintptr, y int32) {
  24966 	var enc uintptr
  24967 	_ = enc
  24968 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24969 	(*VP8EncIterator)(unsafe.Pointer(it)).Fx = 0
  24970 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy = y
  24971 	(*VP8EncIterator)(unsafe.Pointer(it)).Fbw = enc + 112 + uintptr(y&((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))*48
  24972 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpreds = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds + uintptr(y*int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  24973 	(*VP8EncIterator)(unsafe.Pointer(it)).Fnz = (*VP8Encoder)(unsafe.Pointer(enc)).Fnz
  24974 	(*VP8EncIterator)(unsafe.Pointer(it)).Fmb = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info + uintptr(y*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w)*4
  24975 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top
  24976 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top
  24977 	InitLeft(tls, it)
  24978 }
  24979 
  24980 // C documentation
  24981 //
  24982 //	// restart a scan
  24983 func VP8IteratorReset(tls *libc.TLS, it uintptr) {
  24984 	var enc uintptr
  24985 	_ = enc
  24986 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  24987 	VP8IteratorSetRow(tls, it, 0)
  24988 	VP8IteratorSetCountDown(tls, it, (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) // default
  24989 	InitTop(tls, it)
  24990 	libc.Xmemset(tls, it+208, 0, uint64(96))
  24991 	(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = 0
  24992 }
  24993 
  24994 func VP8IteratorSetCountDown(tls *libc.TLS, it uintptr, count_down int32) {
  24995 	var v1 int32
  24996 	_ = v1
  24997 	v1 = count_down
  24998 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 = v1
  24999 	(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down = v1
  25000 }
  25001 
  25002 func VP8IteratorIsDone(tls *libc.TLS, it uintptr) (r int32) {
  25003 	return libc.BoolInt32((*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down <= 0)
  25004 }
  25005 
  25006 func VP8IteratorInit(tls *libc.TLS, enc uintptr, it uintptr) {
  25007 	(*VP8EncIterator)(unsafe.Pointer(it)).Fenc = enc
  25008 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in = uintptr((uintptr_t(it+488) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  25009 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25010 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25011 	(*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(BPS)*libc.Int32FromInt32(16))
  25012 	(*VP8EncIterator)(unsafe.Pointer(it)).Flf_stats = (*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats
  25013 	(*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent
  25014 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_left = uintptr((uint64(it+400+libc.UintptrFromInt32(1)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  25015 	(*VP8EncIterator)(unsafe.Pointer(it)).Fu_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(16) + uintptr(16)
  25016 	(*VP8EncIterator)(unsafe.Pointer(it)).Fv_left = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(16)
  25017 	(*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr = (*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr
  25018 	VP8IteratorReset(tls, it)
  25019 }
  25020 
  25021 func VP8IteratorProgress(tls *libc.TLS, it uintptr, delta int32) (r int32) {
  25022 	var done, percent, v1 int32
  25023 	var enc uintptr
  25024 	_, _, _, _ = done, enc, percent, v1
  25025 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25026 	if delta != 0 && (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fprogress_hook != libc.UintptrFromInt32(0) {
  25027 		done = (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 - (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down
  25028 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0 <= 0 {
  25029 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0
  25030 		} else {
  25031 			v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fpercent0 + delta*done/(*VP8EncIterator)(unsafe.Pointer(it)).Fcount_down0
  25032 		}
  25033 		percent = v1
  25034 		return WebPReportProgress(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, percent, enc+536)
  25035 	}
  25036 	return int32(1)
  25037 }
  25038 
  25039 //------------------------------------------------------------------------------
  25040 // Import the source samples into the cache. Takes care of replicating
  25041 // boundary pixels if necessary.
  25042 
  25043 func MinSize(tls *libc.TLS, a int32, b int32) (r int32) {
  25044 	var v1 int32
  25045 	_ = v1
  25046 	if a < b {
  25047 		v1 = a
  25048 	} else {
  25049 		v1 = b
  25050 	}
  25051 	return v1
  25052 }
  25053 
  25054 func ImportBlock(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, w int32, h int32, size int32) {
  25055 	var i int32
  25056 	_ = i
  25057 	i = 0
  25058 	for {
  25059 		if !(i < h) {
  25060 			break
  25061 		}
  25062 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(w))
  25063 		if w < size {
  25064 			libc.Xmemset(tls, dst+uintptr(w), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(w-int32(1))))), libc.Uint64FromInt32(size-w))
  25065 		}
  25066 		dst = dst + uintptr(BPS)
  25067 		src = src + uintptr(src_stride)
  25068 		goto _1
  25069 	_1:
  25070 		;
  25071 		i = i + 1
  25072 	}
  25073 	i = h
  25074 	for {
  25075 		if !(i < size) {
  25076 			break
  25077 		}
  25078 		libc.Xmemcpy(tls, dst, dst-uintptr(BPS), libc.Uint64FromInt32(size))
  25079 		dst = dst + uintptr(BPS)
  25080 		goto _2
  25081 	_2:
  25082 		;
  25083 		i = i + 1
  25084 	}
  25085 }
  25086 
  25087 func ImportLine(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, len1 int32, total_len int32) {
  25088 	var i int32
  25089 	_ = i
  25090 	i = 0
  25091 	for {
  25092 		if !(i < len1) {
  25093 			break
  25094 		}
  25095 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(src))
  25096 		goto _1
  25097 	_1:
  25098 		;
  25099 		i = i + 1
  25100 		src = src + uintptr(src_stride)
  25101 	}
  25102 	for {
  25103 		if !(i < total_len) {
  25104 			break
  25105 		}
  25106 		**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = **(**uint8_t)(__ccgo_up(dst + uintptr(len1-int32(1))))
  25107 		goto _2
  25108 	_2:
  25109 		;
  25110 		i = i + 1
  25111 	}
  25112 }
  25113 
  25114 func VP8IteratorImport(tls *libc.TLS, it uintptr, tmp_32 uintptr) {
  25115 	var enc, pic, usrc, vsrc, ysrc uintptr
  25116 	var h, uv_h, uv_w, w, x, y int32
  25117 	var v1, v2 uint8_t
  25118 	_, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, usrc, uv_h, uv_w, vsrc, w, x, y, ysrc, v1, v2
  25119 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25120 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25121 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25122 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  25123 	ysrc = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  25124 	usrc = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25125 	vsrc = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25126 	w = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth-x*int32(16), int32(16))
  25127 	h = MinSize(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fheight-y*int32(16), int32(16))
  25128 	uv_w = (w + int32(1)) >> int32(1)
  25129 	uv_h = (h + int32(1)) >> int32(1)
  25130 	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))
  25131 	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))
  25132 	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))
  25133 	if tmp_32 == libc.UintptrFromInt32(0) {
  25134 		return
  25135 	}
  25136 	// Import source (uncompressed) samples into boundary.
  25137 	if x == 0 {
  25138 		InitLeft(tls, it)
  25139 	} else {
  25140 		if y == 0 {
  25141 			v2 = libc.Uint8FromInt32(127)
  25142 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(-libc.Int32FromInt32(1)))) = v2
  25143 			v1 = v2
  25144 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25145 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(-libc.Int32FromInt32(1)))) = v1
  25146 		} else {
  25147 			**(**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)))
  25148 			**(**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)))
  25149 			**(**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)))
  25150 		}
  25151 		ImportLine(tls, ysrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left, h, int32(16))
  25152 		ImportLine(tls, usrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left, uv_h, int32(8))
  25153 		ImportLine(tls, vsrc-uintptr(1), (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, (*VP8EncIterator)(unsafe.Pointer(it)).Fv_left, uv_h, int32(8))
  25154 	}
  25155 	(*VP8EncIterator)(unsafe.Pointer(it)).Fy_top = tmp_32 + uintptr(0)
  25156 	(*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top = tmp_32 + uintptr(16)
  25157 	if y == 0 {
  25158 		libc.Xmemset(tls, tmp_32, int32(127), libc.Uint64FromInt32(32)*libc.Uint64FromInt64(1))
  25159 	} else {
  25160 		ImportLine(tls, ysrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fy_stride), int32(1), tmp_32, w, int32(16))
  25161 		ImportLine(tls, usrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16), uv_w, int32(8))
  25162 		ImportLine(tls, vsrc-uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride), int32(1), tmp_32+uintptr(16)+uintptr(8), uv_w, int32(8))
  25163 	}
  25164 }
  25165 
  25166 //------------------------------------------------------------------------------
  25167 // Copy back the compressed samples into user space if requested.
  25168 
  25169 func ExportBlock(tls *libc.TLS, src uintptr, dst uintptr, dst_stride int32, w int32, h int32) {
  25170 	var v1 int32
  25171 	_ = v1
  25172 	for {
  25173 		v1 = h
  25174 		h = h - 1
  25175 		if !(v1 > 0) {
  25176 			break
  25177 		}
  25178 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(w))
  25179 		dst = dst + uintptr(dst_stride)
  25180 		src = src + uintptr(BPS)
  25181 	}
  25182 }
  25183 
  25184 func VP8IteratorExport(tls *libc.TLS, it uintptr) {
  25185 	var enc, pic, udst, usrc, vdst, vsrc, ydst, ysrc uintptr
  25186 	var h, uv_h, uv_w, w, x, y int32
  25187 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, h, pic, udst, usrc, uv_h, uv_w, vdst, vsrc, w, x, y, ydst, ysrc
  25188 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25189 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fshow_compressed != 0 {
  25190 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25191 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25192 		ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  25193 		usrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25194 		vsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(16)+libc.Int32FromInt32(8))
  25195 		pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  25196 		ydst = (*WebPPicture)(unsafe.Pointer(pic)).Fy + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride+x)*int32(16))
  25197 		udst = (*WebPPicture)(unsafe.Pointer(pic)).Fu + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25198 		vdst = (*WebPPicture)(unsafe.Pointer(pic)).Fv + uintptr((y*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride+x)*int32(8))
  25199 		w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - x*int32(16)
  25200 		h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - y*int32(16)
  25201 		if w > int32(16) {
  25202 			w = int32(16)
  25203 		}
  25204 		if h > int32(16) {
  25205 			h = int32(16)
  25206 		}
  25207 		// Luma plane
  25208 		ExportBlock(tls, ysrc, ydst, (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride, w, h)
  25209 		// U/V planes
  25210 		uv_w = (w + int32(1)) >> int32(1)
  25211 		uv_h = (h + int32(1)) >> int32(1)
  25212 		ExportBlock(tls, usrc, udst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  25213 		ExportBlock(tls, vsrc, vdst, (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride, uv_w, uv_h)
  25214 	}
  25215 }
  25216 
  25217 //------------------------------------------------------------------------------
  25218 // Non-zero contexts setup/teardown
  25219 
  25220 // Nz bits:
  25221 //  0  1  2  3  Y
  25222 //  4  5  6  7
  25223 //  8  9 10 11
  25224 // 12 13 14 15
  25225 // 16 17        U
  25226 // 18 19
  25227 // 20 21        V
  25228 // 22 23
  25229 // 24           DC-intra16
  25230 
  25231 // Convert packed context to byte array
  25232 
  25233 func VP8IteratorNzToBytes(tls *libc.TLS, it uintptr) {
  25234 	var left_nz, top_nz uintptr
  25235 	var lnz, tnz int32
  25236 	_, _, _, _ = left_nz, lnz, tnz, top_nz
  25237 	tnz = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)))
  25238 	lnz = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)))
  25239 	top_nz = it + 132
  25240 	left_nz = it + 168
  25241 	// Top-Y
  25242 	**(**int32)(__ccgo_up(top_nz)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(12)) != 0))
  25243 	**(**int32)(__ccgo_up(top_nz + 1*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(13)) != 0))
  25244 	**(**int32)(__ccgo_up(top_nz + 2*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(14)) != 0))
  25245 	**(**int32)(__ccgo_up(top_nz + 3*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  25246 	// Top-U
  25247 	**(**int32)(__ccgo_up(top_nz + 4*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(18)) != 0))
  25248 	**(**int32)(__ccgo_up(top_nz + 5*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  25249 	// Top-V
  25250 	**(**int32)(__ccgo_up(top_nz + 6*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(22)) != 0))
  25251 	**(**int32)(__ccgo_up(top_nz + 7*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  25252 	// DC
  25253 	**(**int32)(__ccgo_up(top_nz + 8*4)) = libc.BoolInt32(!!(tnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) != 0))
  25254 	// left-Y
  25255 	**(**int32)(__ccgo_up(left_nz)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(3)) != 0))
  25256 	**(**int32)(__ccgo_up(left_nz + 1*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(7)) != 0))
  25257 	**(**int32)(__ccgo_up(left_nz + 2*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(11)) != 0))
  25258 	**(**int32)(__ccgo_up(left_nz + 3*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(15)) != 0))
  25259 	// left-U
  25260 	**(**int32)(__ccgo_up(left_nz + 4*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(17)) != 0))
  25261 	**(**int32)(__ccgo_up(left_nz + 5*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) != 0))
  25262 	// left-V
  25263 	**(**int32)(__ccgo_up(left_nz + 6*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(21)) != 0))
  25264 	**(**int32)(__ccgo_up(left_nz + 7*4)) = libc.BoolInt32(!!(lnz&(libc.Int32FromInt32(1)<<libc.Int32FromInt32(23)) != 0))
  25265 	// left-DC is special, iterated separately
  25266 }
  25267 
  25268 func VP8IteratorBytesToNz(tls *libc.TLS, it uintptr) {
  25269 	var left_nz, top_nz uintptr
  25270 	var nz uint32_t
  25271 	_, _, _ = left_nz, nz, top_nz
  25272 	nz = uint32(0)
  25273 	top_nz = it + 132
  25274 	left_nz = it + 168
  25275 	// top
  25276 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz))<<libc.Int32FromInt32(12)|**(**int32)(__ccgo_up(top_nz + 1*4))<<libc.Int32FromInt32(13))
  25277 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 2*4))<<libc.Int32FromInt32(14)|**(**int32)(__ccgo_up(top_nz + 3*4))<<libc.Int32FromInt32(15))
  25278 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 4*4))<<libc.Int32FromInt32(18)|**(**int32)(__ccgo_up(top_nz + 5*4))<<libc.Int32FromInt32(19))
  25279 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 6*4))<<libc.Int32FromInt32(22)|**(**int32)(__ccgo_up(top_nz + 7*4))<<libc.Int32FromInt32(23))
  25280 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(top_nz + 8*4))<<libc.Int32FromInt32(24)) // we propagate the _top_ bit, esp. for intra4
  25281 	// left
  25282 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(left_nz))<<libc.Int32FromInt32(3)|**(**int32)(__ccgo_up(left_nz + 1*4))<<libc.Int32FromInt32(7))
  25283 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(left_nz + 2*4))<<libc.Int32FromInt32(11))
  25284 	nz = nz | libc.Uint32FromInt32(**(**int32)(__ccgo_up(left_nz + 4*4))<<libc.Int32FromInt32(17)|**(**int32)(__ccgo_up(left_nz + 6*4))<<libc.Int32FromInt32(21))
  25285 	**(**uint32_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fnz)) = nz
  25286 }
  25287 
  25288 //------------------------------------------------------------------------------
  25289 // Advance to the next position, doing the bookkeeping.
  25290 
  25291 func VP8IteratorSaveBoundary(tls *libc.TLS, it uintptr) {
  25292 	var enc, uvsrc, ysrc uintptr
  25293 	var i, x, y int32
  25294 	_, _, _, _, _, _ = enc, i, uvsrc, x, y, ysrc
  25295 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25296 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fx
  25297 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fy
  25298 	ysrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  25299 	uvsrc = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  25300 	if x < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25301 		i = 0
  25302 		for {
  25303 			if !(i < int32(16)) {
  25304 				break
  25305 			}
  25306 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(ysrc + uintptr(int32(15)+i*int32(BPS))))
  25307 			goto _1
  25308 		_1:
  25309 			;
  25310 			i = i + 1
  25311 		}
  25312 		i = 0
  25313 		for {
  25314 			if !(i < int32(8)) {
  25315 				break
  25316 			}
  25317 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fu_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(7)+i*int32(BPS))))
  25318 			**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fv_left + uintptr(i))) = **(**uint8_t)(__ccgo_up(uvsrc + uintptr(int32(15)+i*int32(BPS))))
  25319 			goto _2
  25320 		_2:
  25321 			;
  25322 			i = i + 1
  25323 		}
  25324 		// top-left (before 'top'!)
  25325 		**(**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))
  25326 		**(**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))))
  25327 		**(**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))))
  25328 	}
  25329 	if y < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h-int32(1) { // top
  25330 		libc.Xmemcpy(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top, ysrc+uintptr(libc.Int32FromInt32(15)*libc.Int32FromInt32(BPS)), uint64(16))
  25331 		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)))
  25332 	}
  25333 }
  25334 
  25335 func VP8IteratorNext(tls *libc.TLS, it uintptr) (r int32) {
  25336 	var v1, v3 int32
  25337 	var v2, v4 uintptr
  25338 	_, _, _, _ = v1, v2, v3, v4
  25339 	v2 = it
  25340 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
  25341 	v1 = *(*int32)(unsafe.Pointer(v2))
  25342 	if v1 == (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_w {
  25343 		v4 = it + 4
  25344 		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
  25345 		v3 = *(*int32)(unsafe.Pointer(v4))
  25346 		VP8IteratorSetRow(tls, it, v3)
  25347 	} else {
  25348 		**(**uintptr)(__ccgo_up(it + 64)) += uintptr(4)
  25349 		**(**uintptr)(__ccgo_up(it + 48)) += uintptr(1) * 4
  25350 		**(**uintptr)(__ccgo_up(it + 72)) += uintptr(1) * 4
  25351 		**(**uintptr)(__ccgo_up(it + 384)) += uintptr(16)
  25352 		**(**uintptr)(__ccgo_up(it + 392)) += uintptr(16)
  25353 	}
  25354 	v2 = it + 332
  25355 	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  25356 	v1 = *(*int32)(unsafe.Pointer(v2))
  25357 	return libc.BoolInt32(0 < v1)
  25358 }
  25359 
  25360 //------------------------------------------------------------------------------
  25361 // Helper function to set mode properties
  25362 
  25363 func VP8SetIntra16Mode(tls *libc.TLS, it uintptr, mode int32) {
  25364 	var preds uintptr
  25365 	var y int32
  25366 	_, _ = preds, y
  25367 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25368 	y = 0
  25369 	for {
  25370 		if !(y < int32(4)) {
  25371 			break
  25372 		}
  25373 		libc.Xmemset(tls, preds, mode, uint64(4))
  25374 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25375 		goto _1
  25376 	_1:
  25377 		;
  25378 		y = y + 1
  25379 	}
  25380 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(1), 0, 0x3)
  25381 }
  25382 
  25383 func VP8SetIntra4Mode(tls *libc.TLS, it uintptr, modes uintptr) {
  25384 	var preds uintptr
  25385 	var y int32
  25386 	_, _ = preds, y
  25387 	preds = (*VP8EncIterator)(unsafe.Pointer(it)).Fpreds
  25388 	y = int32(4)
  25389 	for {
  25390 		if !(y > 0) {
  25391 			break
  25392 		}
  25393 		libc.Xmemcpy(tls, preds, modes, libc.Uint64FromInt32(4)*libc.Uint64FromInt64(1))
  25394 		preds = preds + uintptr((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w)
  25395 		modes = modes + uintptr(4)
  25396 		goto _1
  25397 	_1:
  25398 		;
  25399 		y = y - 1
  25400 	}
  25401 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(0), 0, 0x3)
  25402 }
  25403 
  25404 func VP8SetIntraUVMode(tls *libc.TLS, it uintptr, mode int32) {
  25405 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(mode), 2, 0xc)
  25406 }
  25407 
  25408 func VP8SetSkip(tls *libc.TLS, it uintptr, skip int32) {
  25409 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(skip), 4, 0x10)
  25410 }
  25411 
  25412 func VP8SetSegment(tls *libc.TLS, it uintptr, segment int32) {
  25413 	libc.SetBitFieldPtr8Uint32((*VP8EncIterator)(unsafe.Pointer(it)).Fmb+0, libc.Uint32FromInt32(segment), 5, 0x60)
  25414 }
  25415 
  25416 //------------------------------------------------------------------------------
  25417 // Intra4x4 sub-blocks iteration
  25418 //
  25419 //  We store and update the boundary samples into an array of 37 pixels. They
  25420 //  are updated as we iterate and reconstructs each intra4x4 blocks in turn.
  25421 //  The position of the samples has the following snake pattern:
  25422 //
  25423 // 16|17 18 19 20|21 22 23 24|25 26 27 28|29 30 31 32|33 34 35 36  <- Top-right
  25424 // --+-----------+-----------+-----------+-----------+
  25425 // 15|         19|         23|         27|         31|
  25426 // 14|         18|         22|         26|         30|
  25427 // 13|         17|         21|         25|         29|
  25428 // 12|13 14 15 16|17 18 19 20|21 22 23 24|25 26 27 28|
  25429 // --+-----------+-----------+-----------+-----------+
  25430 // 11|         15|         19|         23|         27|
  25431 // 10|         14|         18|         22|         26|
  25432 //  9|         13|         17|         21|         25|
  25433 //  8| 9 10 11 12|13 14 15 16|17 18 19 20|21 22 23 24|
  25434 // --+-----------+-----------+-----------+-----------+
  25435 //  7|         11|         15|         19|         23|
  25436 //  6|         10|         14|         18|         22|
  25437 //  5|          9|         13|         17|         21|
  25438 //  4| 5  6  7  8| 9 10 11 12|13 14 15 16|17 18 19 20|
  25439 // --+-----------+-----------+-----------+-----------+
  25440 //  3|          7|         11|         15|         19|
  25441 //  2|          6|         10|         14|         18|
  25442 //  1|          5|          9|         13|         17|
  25443 //  0| 1  2  3  4| 5  6  7  8| 9 10 11 12|13 14 15 16|
  25444 // --+-----------+-----------+-----------+-----------+
  25445 
  25446 // C documentation
  25447 //
  25448 //	// Array to record the position of the top sample to pass to the prediction
  25449 //	// functions in dsp.c.
  25450 var VP8TopLeftI4 = [16]uint8_t{
  25451 	0:  uint8(17),
  25452 	1:  uint8(21),
  25453 	2:  uint8(25),
  25454 	3:  uint8(29),
  25455 	4:  uint8(13),
  25456 	5:  uint8(17),
  25457 	6:  uint8(21),
  25458 	7:  uint8(25),
  25459 	8:  uint8(9),
  25460 	9:  uint8(13),
  25461 	10: uint8(17),
  25462 	11: uint8(21),
  25463 	12: uint8(5),
  25464 	13: uint8(9),
  25465 	14: uint8(13),
  25466 	15: uint8(17),
  25467 }
  25468 
  25469 func VP8IteratorStartI4(tls *libc.TLS, it uintptr) {
  25470 	var enc uintptr
  25471 	var i int32
  25472 	_, _ = enc, i
  25473 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  25474 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = 0 // first 4x4 sub-block
  25475 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[0])
  25476 	// Import the boundary samples
  25477 	i = 0
  25478 	for {
  25479 		if !(i < int32(17)) {
  25480 			break
  25481 		} // left
  25482 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_left + uintptr(int32(15)-i)))
  25483 		goto _1
  25484 	_1:
  25485 		;
  25486 		i = i + 1
  25487 	}
  25488 	i = 0
  25489 	for {
  25490 		if !(i < int32(16)) {
  25491 			break
  25492 		} // top
  25493 		**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25494 		goto _2
  25495 	_2:
  25496 		;
  25497 		i = i + 1
  25498 	}
  25499 	// top-right samples have a special case on the far right of the picture
  25500 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx < (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w-int32(1) {
  25501 		i = int32(16)
  25502 		for {
  25503 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25504 				break
  25505 			}
  25506 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fy_top + uintptr(i)))
  25507 			goto _3
  25508 		_3:
  25509 			;
  25510 			i = i + 1
  25511 		}
  25512 	} else { // else, replicate the last valid pixel four times
  25513 		i = int32(16)
  25514 		for {
  25515 			if !(i < libc.Int32FromInt32(16)+libc.Int32FromInt32(4)) {
  25516 				break
  25517 			}
  25518 			**(**uint8_t)(__ccgo_up(it + 80 + uintptr(int32(17)+i))) = **(**uint8_t)(__ccgo_up(it + 80 + uintptr(libc.Int32FromInt32(17)+libc.Int32FromInt32(15))))
  25519 			goto _4
  25520 		_4:
  25521 			;
  25522 			i = i + 1
  25523 		}
  25524 	}
  25525 	VP8IteratorNzToBytes(tls, it) // import the non-zero context
  25526 }
  25527 
  25528 func VP8IteratorRotateI4(tls *libc.TLS, it uintptr, yuv_out uintptr) (r int32) {
  25529 	var blk, top uintptr
  25530 	var i int32
  25531 	_, _, _ = blk, i, top
  25532 	blk = yuv_out + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25533 	top = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top
  25534 	// Update the cache with 7 fresh samples
  25535 	i = 0
  25536 	for {
  25537 		if !(i <= int32(3)) {
  25538 			break
  25539 		}
  25540 		**(**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
  25541 		goto _1
  25542 	_1:
  25543 		;
  25544 		i = i + 1
  25545 	}
  25546 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3) != int32(3) { // if not on the right sub-blocks #3, #7, #11, #15
  25547 		i = 0
  25548 		for {
  25549 			if !(i <= int32(2)) {
  25550 				break
  25551 			} // store future left samples
  25552 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(blk + uintptr(int32(3)+(int32(2)-i)*int32(BPS))))
  25553 			goto _2
  25554 		_2:
  25555 			;
  25556 			i = i + 1
  25557 		}
  25558 	} else { // else replicate top-right samples, as says the specs.
  25559 		i = 0
  25560 		for {
  25561 			if !(i <= int32(3)) {
  25562 				break
  25563 			}
  25564 			**(**uint8_t)(__ccgo_up(top + uintptr(i))) = **(**uint8_t)(__ccgo_up(top + uintptr(i+int32(4))))
  25565 			goto _3
  25566 		_3:
  25567 			;
  25568 			i = i + 1
  25569 		}
  25570 	}
  25571 	// move pointers to next sub-block
  25572 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4 = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 + 1
  25573 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 == int32(16) { // we're done
  25574 		return 0
  25575 	}
  25576 	(*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top = it + 80 + uintptr(VP8TopLeftI4[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  25577 	return int32(1)
  25578 }
  25579 
  25580 const MAX_LIMIT_BITS = 5
  25581 const MIN_DIM_FOR_NEAR_LOSSLESS = 64
  25582 
  25583 //------------------------------------------------------------------------------
  25584 
  25585 // Copyright 2012 Google Inc. All Rights Reserved.
  25586 //
  25587 // Use of this source code is governed by a BSD-style license
  25588 // that can be found in the COPYING file in the root of the source
  25589 // tree. An additional intellectual property rights grant can be found
  25590 // in the file PATENTS. All contributing project authors may
  25591 // be found in the AUTHORS file in the root of the source tree.
  25592 // -----------------------------------------------------------------------------
  25593 //
  25594 // Misc. common utility functions
  25595 //
  25596 // Authors: Skal (pascal.massimino@gmail.com)
  25597 //          Urvang (urvang@google.com)
  25598 
  25599 // Copyright 2011 Google Inc. All Rights Reserved.
  25600 //
  25601 // Use of this source code is governed by a BSD-style license
  25602 // that can be found in the COPYING file in the root of the source
  25603 // tree. An additional intellectual property rights grant can be found
  25604 // in the file PATENTS. All contributing project authors may
  25605 // be found in the AUTHORS file in the root of the source tree.
  25606 // -----------------------------------------------------------------------------
  25607 //
  25608 //   WebP encoder: main interface
  25609 //
  25610 // Author: Skal (pascal.massimino@gmail.com)
  25611 
  25612 // C documentation
  25613 //
  25614 //	// Quantizes the value up or down to a multiple of 1<<bits (or to 255),
  25615 //	// choosing the closer one, resolving ties using bankers' rounding.
  25616 func FindClosestDiscretized(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25617 	var biased, mask uint32_t
  25618 	_, _ = biased, mask
  25619 	mask = uint32(1)<<bits - uint32(1)
  25620 	biased = a + mask>>libc.Int32FromInt32(1) + a>>bits&uint32(1)
  25621 	if biased > uint32(0xff) {
  25622 		return uint32(0xff)
  25623 	}
  25624 	return biased & ^mask
  25625 }
  25626 
  25627 // C documentation
  25628 //
  25629 //	// Applies FindClosestDiscretized to all channels of pixel.
  25630 func ClosestDiscretizedArgb(tls *libc.TLS, a uint32_t, bits int32) (r uint32_t) {
  25631 	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)
  25632 }
  25633 
  25634 // C documentation
  25635 //
  25636 //	// Checks if distance between corresponding channel values of pixels a and b
  25637 //	// is within the given limit.
  25638 func IsNear(tls *libc.TLS, a uint32_t, b uint32_t, limit int32) (r int32) {
  25639 	var delta, k int32
  25640 	_, _ = delta, k
  25641 	k = 0
  25642 	for {
  25643 		if !(k < int32(4)) {
  25644 			break
  25645 		}
  25646 		delta = libc.Int32FromUint32(a>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff)) - libc.Int32FromUint32(b>>(k*libc.Int32FromInt32(8))&libc.Uint32FromInt32(0xff))
  25647 		if delta >= limit || delta <= -limit {
  25648 			return 0
  25649 		}
  25650 		goto _1
  25651 	_1:
  25652 		;
  25653 		k = k + 1
  25654 	}
  25655 	return int32(1)
  25656 }
  25657 
  25658 func IsSmooth(tls *libc.TLS, prev_row uintptr, curr_row uintptr, next_row uintptr, ix int32, limit int32) (r int32) {
  25659 	// Check that all pixels in 4-connected neighborhood are smooth.
  25660 	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)
  25661 }
  25662 
  25663 // C documentation
  25664 //
  25665 //	// Adjusts pixel values of image with given maximum error.
  25666 func NearLossless(tls *libc.TLS, xsize int32, ysize int32, argb_src uintptr, stride int32, limit_bits int32, copy_buffer uintptr, argb_dst uintptr) {
  25667 	var curr_row, next_row, prev_row, temp uintptr
  25668 	var limit, x, y int32
  25669 	_, _, _, _, _, _, _ = curr_row, limit, next_row, prev_row, temp, x, y
  25670 	limit = int32(1) << limit_bits
  25671 	prev_row = copy_buffer
  25672 	curr_row = prev_row + uintptr(xsize)*4
  25673 	next_row = curr_row + uintptr(xsize)*4
  25674 	libc.Xmemcpy(tls, curr_row, argb_src, libc.Uint64FromInt32(xsize)*uint64(4))
  25675 	libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, libc.Uint64FromInt32(xsize)*uint64(4))
  25676 	y = 0
  25677 	for {
  25678 		if !(y < ysize) {
  25679 			break
  25680 		}
  25681 		if y == 0 || y == ysize-int32(1) {
  25682 			libc.Xmemcpy(tls, argb_dst, argb_src, libc.Uint64FromInt32(xsize)*uint64(4))
  25683 		} else {
  25684 			libc.Xmemcpy(tls, next_row, argb_src+uintptr(stride)*4, libc.Uint64FromInt32(xsize)*uint64(4))
  25685 			**(**uint32_t)(__ccgo_up(argb_dst)) = **(**uint32_t)(__ccgo_up(argb_src))
  25686 			**(**uint32_t)(__ccgo_up(argb_dst + uintptr(xsize-int32(1))*4)) = **(**uint32_t)(__ccgo_up(argb_src + uintptr(xsize-int32(1))*4))
  25687 			x = int32(1)
  25688 			for {
  25689 				if !(x < xsize-int32(1)) {
  25690 					break
  25691 				}
  25692 				if IsSmooth(tls, prev_row, curr_row, next_row, x, limit) != 0 {
  25693 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  25694 				} else {
  25695 					**(**uint32_t)(__ccgo_up(argb_dst + uintptr(x)*4)) = ClosestDiscretizedArgb(tls, **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4)), limit_bits)
  25696 				}
  25697 				goto _2
  25698 			_2:
  25699 				;
  25700 				x = x + 1
  25701 			}
  25702 		}
  25703 		// Three-way swap.
  25704 		temp = prev_row
  25705 		prev_row = curr_row
  25706 		curr_row = next_row
  25707 		next_row = temp
  25708 		goto _1
  25709 	_1:
  25710 		;
  25711 		y = y + 1
  25712 		argb_src = argb_src + uintptr(stride)*4
  25713 		argb_dst = argb_dst + uintptr(xsize)*4
  25714 	}
  25715 }
  25716 
  25717 func VP8ApplyNearLossless(tls *libc.TLS, picture uintptr, quality int32, argb_dst uintptr) (r int32) {
  25718 	var copy_buffer uintptr
  25719 	var i, limit_bits, stride, xsize, ysize, v1 int32
  25720 	_, _, _, _, _, _, _ = copy_buffer, i, limit_bits, stride, xsize, ysize, v1
  25721 	xsize = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  25722 	ysize = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  25723 	stride = (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  25724 	copy_buffer = WebPSafeMalloc(tls, libc.Uint64FromInt32(xsize*int32(3)), uint64(4))
  25725 	v1 = int32(5) - quality/int32(20)
  25726 	goto _2
  25727 _2:
  25728 	limit_bits = v1
  25729 	if copy_buffer == libc.UintptrFromInt32(0) {
  25730 		return 0
  25731 	}
  25732 	// For small icon images, don't attempt to apply near-lossless compression.
  25733 	if xsize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) && ysize < int32(MIN_DIM_FOR_NEAR_LOSSLESS) || ysize < int32(3) {
  25734 		i = 0
  25735 		for {
  25736 			if !(i < ysize) {
  25737 				break
  25738 			}
  25739 			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))
  25740 			goto _3
  25741 		_3:
  25742 			;
  25743 			i = i + 1
  25744 		}
  25745 		WebPSafeFree(tls, copy_buffer)
  25746 		return int32(1)
  25747 	}
  25748 	NearLossless(tls, xsize, ysize, (*WebPPicture)(unsafe.Pointer(picture)).Fargb, stride, limit_bits, copy_buffer, argb_dst)
  25749 	i = limit_bits - int32(1)
  25750 	for {
  25751 		if !(i != 0) {
  25752 			break
  25753 		}
  25754 		NearLossless(tls, xsize, ysize, argb_dst, xsize, i, copy_buffer, argb_dst)
  25755 		goto _4
  25756 	_4:
  25757 		;
  25758 		i = i - 1
  25759 	}
  25760 	WebPSafeFree(tls, copy_buffer)
  25761 	return int32(1)
  25762 }
  25763 
  25764 const GAMMA_FIX = 12
  25765 const GAMMA_TAB_FIX = 7
  25766 const SHARPYUV_INLINE = "inline"
  25767 const SHARPYUV_VERSION_MAJOR = 0
  25768 const SHARPYUV_VERSION_MINOR = 4
  25769 const SHARPYUV_VERSION_PATCH = 2
  25770 
  25771 type SharpYuvConversionMatrix = struct {
  25772 	Frgb_to_y [4]int32
  25773 	Frgb_to_u [4]int32
  25774 	Frgb_to_v [4]int32
  25775 }
  25776 
  25777 type SharpYuvOptions = struct {
  25778 	Fyuv_matrix    uintptr
  25779 	Ftransfer_type SharpYuvTransferFunctionType1
  25780 }
  25781 
  25782 type SharpYuvTransferFunctionType = int32
  25783 
  25784 const kSharpYuvTransferFunctionBt709 = 1
  25785 const kSharpYuvTransferFunctionBt470M = 4
  25786 const kSharpYuvTransferFunctionBt470Bg = 5
  25787 const kSharpYuvTransferFunctionBt601 = 6
  25788 const kSharpYuvTransferFunctionSmpte240 = 7
  25789 const kSharpYuvTransferFunctionLinear = 8
  25790 const kSharpYuvTransferFunctionLog100 = 9
  25791 const kSharpYuvTransferFunctionLog100_Sqrt10 = 10
  25792 const kSharpYuvTransferFunctionIec61966 = 11
  25793 const kSharpYuvTransferFunctionBt1361 = 12
  25794 const kSharpYuvTransferFunctionSrgb = 13
  25795 const kSharpYuvTransferFunctionBt2020_10Bit = 14
  25796 const kSharpYuvTransferFunctionBt2020_12Bit = 15
  25797 const kSharpYuvTransferFunctionSmpte2084 = 16
  25798 const kSharpYuvTransferFunctionSmpte428 = 17
  25799 const kSharpYuvTransferFunctionHlg = 18
  25800 const kSharpYuvTransferFunctionNum = 19
  25801 
  25802 type SharpYuvTransferFunctionType1 = int32
  25803 
  25804 type SharpYuvRange = int32
  25805 
  25806 const kSharpYuvRangeFull = 0
  25807 const kSharpYuvRangeLimited = 1
  25808 
  25809 type SharpYuvColorSpace = struct {
  25810 	Fkr        float32
  25811 	Fkb        float32
  25812 	Fbit_depth int32
  25813 	Frange1    SharpYuvRange
  25814 }
  25815 
  25816 type SharpYuvMatrixType = int32
  25817 
  25818 const kSharpYuvMatrixWebp = 0
  25819 const kSharpYuvMatrixRec601Limited = 1
  25820 const kSharpYuvMatrixRec601Full = 2
  25821 const kSharpYuvMatrixRec709Limited = 3
  25822 const kSharpYuvMatrixRec709Full = 4
  25823 const kSharpYuvMatrixNum = 5
  25824 
  25825 // Copyright 2012 Google Inc. All Rights Reserved.
  25826 //
  25827 // Use of this source code is governed by a BSD-style license
  25828 // that can be found in the COPYING file in the root of the source
  25829 // tree. An additional intellectual property rights grant can be found
  25830 // in the file PATENTS. All contributing project authors may
  25831 // be found in the AUTHORS file in the root of the source tree.
  25832 // -----------------------------------------------------------------------------
  25833 //
  25834 // Misc. common utility functions
  25835 //
  25836 // Authors: Skal (pascal.massimino@gmail.com)
  25837 //          Urvang (urvang@google.com)
  25838 
  25839 // Copyright 2011 Google Inc. All Rights Reserved.
  25840 //
  25841 // Use of this source code is governed by a BSD-style license
  25842 // that can be found in the COPYING file in the root of the source
  25843 // tree. An additional intellectual property rights grant can be found
  25844 // in the file PATENTS. All contributing project authors may
  25845 // be found in the AUTHORS file in the root of the source tree.
  25846 // -----------------------------------------------------------------------------
  25847 //
  25848 //   WebP encoder: main interface
  25849 //
  25850 // Author: Skal (pascal.massimino@gmail.com)
  25851 
  25852 // Copyright 2010 Google Inc. All Rights Reserved.
  25853 //
  25854 // Use of this source code is governed by a BSD-style license
  25855 // that can be found in the COPYING file in the root of the source
  25856 // tree. An additional intellectual property rights grant can be found
  25857 // in the file PATENTS. All contributing project authors may
  25858 // be found in the AUTHORS file in the root of the source tree.
  25859 // -----------------------------------------------------------------------------
  25860 //
  25861 //  Common types + memory wrappers
  25862 //
  25863 // Author: Skal (pascal.massimino@gmail.com)
  25864 
  25865 // Uncomment to disable gamma-compression during RGB->U/V averaging
  25866 
  25867 // If defined, use table to compute x / alpha.
  25868 
  25869 // uint32_t 0xff000000 is 0x00,00,00,ff in memory
  25870 
  25871 //------------------------------------------------------------------------------
  25872 // Detection of non-trivial transparency
  25873 
  25874 // C documentation
  25875 //
  25876 //	// Returns true if alpha[] has non-0xff values.
  25877 func CheckNonOpaque(tls *libc.TLS, alpha uintptr, width int32, height int32, x_step int32, y_step int32) (r int32) {
  25878 	var v2 int32
  25879 	_ = v2
  25880 	if alpha == libc.UintptrFromInt32(0) {
  25881 		return 0
  25882 	}
  25883 	WebPInitAlphaProcessing(tls)
  25884 	if x_step == int32(1) {
  25885 		for {
  25886 			v2 = height
  25887 			height = height - 1
  25888 			if !(v2 > 0) {
  25889 				break
  25890 			}
  25891 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha8b})))(tls, alpha, width) != 0 {
  25892 				return int32(1)
  25893 			}
  25894 			goto _1
  25895 		_1:
  25896 			;
  25897 			alpha = alpha + uintptr(y_step)
  25898 		}
  25899 	} else {
  25900 		for {
  25901 			v2 = height
  25902 			height = height - 1
  25903 			if !(v2 > 0) {
  25904 				break
  25905 			}
  25906 			if (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{WebPHasAlpha32b})))(tls, alpha, width) != 0 {
  25907 				return int32(1)
  25908 			}
  25909 			goto _3
  25910 		_3:
  25911 			;
  25912 			alpha = alpha + uintptr(y_step)
  25913 		}
  25914 	}
  25915 	return 0
  25916 }
  25917 
  25918 // C documentation
  25919 //
  25920 //	// Checking for the presence of non-opaque alpha.
  25921 func WebPPictureHasTransparency(tls *libc.TLS, picture uintptr) (r int32) {
  25922 	if picture == libc.UintptrFromInt32(0) {
  25923 		return 0
  25924 	}
  25925 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  25926 		if (*WebPPicture)(unsafe.Pointer(picture)).Fargb != libc.UintptrFromInt32(0) {
  25927 			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)))
  25928 		}
  25929 		return 0
  25930 	}
  25931 	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)
  25932 }
  25933 
  25934 //------------------------------------------------------------------------------
  25935 // Code for gamma correction
  25936 
  25937 // C documentation
  25938 //
  25939 //	// Gamma correction compensates loss of resolution during chroma subsampling.
  25940 var kGamma = float64(0.8)
  25941 var kGammaScale = libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_FIX) - libc.Int32FromInt32(1)
  25942 var kGammaTabScale = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX)
  25943 var kGammaTabRounder = libc.Int32FromInt32(1) << libc.Int32FromInt32(GAMMA_TAB_FIX) >> libc.Int32FromInt32(1)
  25944 
  25945 var kLinearToGammaTab [33]int32
  25946 var kGammaToLinearTab [256]uint16_t
  25947 var kGammaTablesOk = int32(0)
  25948 
  25949 func InitGammaTables(tls *libc.TLS) {
  25950 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  25951 		goto _1
  25952 	}
  25953 	InitGammaTables_body(tls)
  25954 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)), VP8GetCPUInfo)
  25955 	goto _2
  25956 _2:
  25957 	;
  25958 	goto _1
  25959 _1: /**/ //
  25960 }
  25961 
  25962 var InitGammaTables_body_last_cpuinfo_used = uintptr(0)
  25963 
  25964 func init() {
  25965 	p := unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used)
  25966 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&InitGammaTables_body_last_cpuinfo_used))
  25967 }
  25968 
  25969 func InitGammaTables_body(tls *libc.TLS) {
  25970 	var norm, scale float64
  25971 	var v int32
  25972 	_, _, _ = norm, scale, v
  25973 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&kGammaTablesOk))) != 0) {
  25974 		scale = float64(libc.Int32FromInt32(1)<<libc.Int32FromInt32(GAMMA_TAB_FIX)) / float64(kGammaScale)
  25975 		norm = libc.Float64FromFloat64(1) / libc.Float64FromFloat64(255)
  25976 		v = 0
  25977 		for {
  25978 			if !(v <= int32(255)) {
  25979 				break
  25980 			}
  25981 			kGammaToLinearTab[v] = uint16(float64(libc.Xpow(tls, float64(norm*float64(v)), kGamma)*float64(kGammaScale)) + libc.Float64FromFloat64(0.5))
  25982 			goto _1
  25983 		_1:
  25984 			;
  25985 			v = v + 1
  25986 		}
  25987 		v = 0
  25988 		for {
  25989 			if !(v <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(GAMMA_FIX)-libc.Int32FromInt32(GAMMA_TAB_FIX))) {
  25990 				break
  25991 			}
  25992 			kLinearToGammaTab[v] = int32(float64(libc.Float64FromFloat64(255)*libc.Xpow(tls, float64(scale*float64(v)), float64(1)/kGamma)) + libc.Float64FromFloat64(0.5))
  25993 			goto _2
  25994 		_2:
  25995 			;
  25996 			v = v + 1
  25997 		}
  25998 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&kGammaTablesOk)), int32(1))
  25999 	}
  26000 }
  26001 
  26002 func GammaToLinear(tls *libc.TLS, v uint8_t) (r uint32_t) {
  26003 	return uint32(kGammaToLinearTab[v])
  26004 }
  26005 
  26006 func Interpolate(tls *libc.TLS, v int32) (r int32) {
  26007 	var tab_pos, v0, v1, x, y int32
  26008 	_, _, _, _, _ = tab_pos, v0, v1, x, y
  26009 	tab_pos = v >> (libc.Int32FromInt32(GAMMA_TAB_FIX) + libc.Int32FromInt32(2)) // integer part
  26010 	x = v & (kGammaTabScale<<libc.Int32FromInt32(2) - int32(1))                  // fractional part
  26011 	v0 = kLinearToGammaTab[tab_pos]
  26012 	v1 = kLinearToGammaTab[tab_pos+int32(1)]
  26013 	y = v1*x + v0*(kGammaTabScale<<libc.Int32FromInt32(2)-x) // interpolate
  26014 	return y
  26015 }
  26016 
  26017 // C documentation
  26018 //
  26019 //	// Convert a linear value 'v' to YUV_FIX+2 fixed-point precision
  26020 //	// U/V value, suitable for RGBToU/V calls.
  26021 func LinearToGamma(tls *libc.TLS, base_value uint32_t, shift int32) (r int32) {
  26022 	var y int32
  26023 	_ = y
  26024 	y = Interpolate(tls, libc.Int32FromUint32(base_value<<shift)) // final uplifted value
  26025 	return (y + kGammaTabRounder) >> int32(GAMMA_TAB_FIX)         // descale
  26026 }
  26027 
  26028 //------------------------------------------------------------------------------
  26029 // RGB -> YUV conversion
  26030 
  26031 func RGBToY(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26032 	var diff, luma, v1, v11, v13, v15, v2, v5, v8, v9 int32
  26033 	var v10, v12, v4, v7 uintptr
  26034 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, luma, v1, v10, v11, v12, v13, v15, v2, v4, v5, v7, v8, v9
  26035 	if rg2 == libc.UintptrFromInt32(0) {
  26036 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  26037 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  26038 		goto _3
  26039 	_3:
  26040 		v1 = v2
  26041 	} else {
  26042 		v4 = rg2
  26043 		v7 = v4
  26044 		v8 = int32(YUV_FIX)
  26045 		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)))
  26046 		if diff < libc.Int32FromInt32(0) {
  26047 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26048 		}
  26049 		**(**uint32_t)(__ccgo_up(v7 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v7)).Findex1)*4)) = libc.Uint32FromInt32(diff)
  26050 		v10 = v7
  26051 		*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
  26052 		v9 = *(*int32)(unsafe.Pointer(v10))
  26053 		if v9 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26054 			(*VP8Random)(unsafe.Pointer(v7)).Findex1 = 0
  26055 		}
  26056 		v12 = v7 + 4
  26057 		*(*int32)(unsafe.Pointer(v12)) = *(*int32)(unsafe.Pointer(v12)) + 1
  26058 		v11 = *(*int32)(unsafe.Pointer(v12))
  26059 		if v11 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26060 			(*VP8Random)(unsafe.Pointer(v7)).Findex2 = 0
  26061 		}
  26062 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v8)
  26063 		diff = diff * (*VP8Random)(unsafe.Pointer(v4)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26064 		diff = diff + int32(1)<<(v8-int32(1))
  26065 		v13 = diff
  26066 		goto _14
  26067 	_14:
  26068 		v5 = v13
  26069 		goto _6
  26070 	_6:
  26071 		luma = int32(16839)*r1 + int32(33059)*g1 + int32(6420)*b1
  26072 		v15 = (luma + v5 + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  26073 		goto _16
  26074 	_16:
  26075 		v1 = v15
  26076 	}
  26077 	return v1
  26078 }
  26079 
  26080 func RGBToU(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26081 	var diff, u, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  26082 	var v12, v15, v17, v9 uintptr
  26083 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, u, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  26084 	if rg2 == libc.UintptrFromInt32(0) {
  26085 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  26086 		v4 = u
  26087 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26088 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  26089 			v7 = v4
  26090 		} else {
  26091 			if v4 < 0 {
  26092 				v8 = 0
  26093 			} else {
  26094 				v8 = int32(255)
  26095 			}
  26096 			v7 = v8
  26097 		}
  26098 		v5 = v7
  26099 		goto _6
  26100 	_6:
  26101 		v2 = v5
  26102 		goto _3
  26103 	_3:
  26104 		v1 = v2
  26105 	} else {
  26106 		v9 = rg2
  26107 		v12 = v9
  26108 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  26109 		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)))
  26110 		if diff < libc.Int32FromInt32(0) {
  26111 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26112 		}
  26113 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = libc.Uint32FromInt32(diff)
  26114 		v15 = v12
  26115 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  26116 		v14 = *(*int32)(unsafe.Pointer(v15))
  26117 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26118 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  26119 		}
  26120 		v17 = v12 + 4
  26121 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  26122 		v16 = *(*int32)(unsafe.Pointer(v17))
  26123 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26124 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  26125 		}
  26126 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  26127 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26128 		diff = diff + int32(1)<<(v13-int32(1))
  26129 		v18 = diff
  26130 		goto _19
  26131 	_19:
  26132 		v10 = v18
  26133 		goto _11
  26134 	_11:
  26135 		u = -int32(9719)*r1 - int32(19081)*g1 + int32(28800)*b1
  26136 		v22 = u
  26137 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26138 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  26139 			v25 = v22
  26140 		} else {
  26141 			if v22 < 0 {
  26142 				v26 = 0
  26143 			} else {
  26144 				v26 = int32(255)
  26145 			}
  26146 			v25 = v26
  26147 		}
  26148 		v23 = v25
  26149 		goto _24
  26150 	_24:
  26151 		v20 = v23
  26152 		goto _21
  26153 	_21:
  26154 		v1 = v20
  26155 	}
  26156 	return v1
  26157 }
  26158 
  26159 func RGBToV(tls *libc.TLS, r1 int32, g1 int32, b1 int32, rg2 uintptr) (r int32) {
  26160 	var diff, v, v1, v10, v13, v14, v16, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8 int32
  26161 	var v12, v15, v17, v9 uintptr
  26162 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = diff, v, v1, v10, v12, v13, v14, v15, v16, v17, v18, v2, v20, v22, v23, v25, v26, v4, v5, v7, v8, v9
  26163 	if rg2 == libc.UintptrFromInt32(0) {
  26164 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  26165 		v4 = v
  26166 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26167 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  26168 			v7 = v4
  26169 		} else {
  26170 			if v4 < 0 {
  26171 				v8 = 0
  26172 			} else {
  26173 				v8 = int32(255)
  26174 			}
  26175 			v7 = v8
  26176 		}
  26177 		v5 = v7
  26178 		goto _6
  26179 	_6:
  26180 		v2 = v5
  26181 		goto _3
  26182 	_3:
  26183 		v1 = v2
  26184 	} else {
  26185 		v9 = rg2
  26186 		v12 = v9
  26187 		v13 = int32(YUV_FIX) + libc.Int32FromInt32(2)
  26188 		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)))
  26189 		if diff < libc.Int32FromInt32(0) {
  26190 			diff = libc.Int32FromUint32(uint32(diff) + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(31))
  26191 		}
  26192 		**(**uint32_t)(__ccgo_up(v12 + 8 + uintptr((*VP8Random)(unsafe.Pointer(v12)).Findex1)*4)) = libc.Uint32FromInt32(diff)
  26193 		v15 = v12
  26194 		*(*int32)(unsafe.Pointer(v15)) = *(*int32)(unsafe.Pointer(v15)) + 1
  26195 		v14 = *(*int32)(unsafe.Pointer(v15))
  26196 		if v14 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26197 			(*VP8Random)(unsafe.Pointer(v12)).Findex1 = 0
  26198 		}
  26199 		v17 = v12 + 4
  26200 		*(*int32)(unsafe.Pointer(v17)) = *(*int32)(unsafe.Pointer(v17)) + 1
  26201 		v16 = *(*int32)(unsafe.Pointer(v17))
  26202 		if v16 == libc.Int32FromInt32(VP8_RANDOM_TABLE_SIZE) {
  26203 			(*VP8Random)(unsafe.Pointer(v12)).Findex2 = 0
  26204 		}
  26205 		diff = libc.Int32FromUint32(libc.Uint32FromInt32(diff)<<libc.Int32FromInt32(1)) >> (int32(32) - v13)
  26206 		diff = diff * (*VP8Random)(unsafe.Pointer(v9)).Famp >> int32(VP8_RANDOM_DITHER_FIX)
  26207 		diff = diff + int32(1)<<(v13-int32(1))
  26208 		v18 = diff
  26209 		goto _19
  26210 	_19:
  26211 		v10 = v18
  26212 		goto _11
  26213 	_11:
  26214 		v = +libc.Int32FromInt32(28800)*r1 - int32(24116)*g1 - int32(4684)*b1
  26215 		v22 = v
  26216 		v22 = (v22 + v10 + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  26217 		if v22 & ^libc.Int32FromInt32(0xff) == 0 {
  26218 			v25 = v22
  26219 		} else {
  26220 			if v22 < 0 {
  26221 				v26 = 0
  26222 			} else {
  26223 				v26 = int32(255)
  26224 			}
  26225 			v25 = v26
  26226 		}
  26227 		v23 = v25
  26228 		goto _24
  26229 	_24:
  26230 		v20 = v23
  26231 		goto _21
  26232 	_21:
  26233 		v1 = v20
  26234 	}
  26235 	return v1
  26236 }
  26237 
  26238 //------------------------------------------------------------------------------
  26239 // Sharp RGB->YUV conversion
  26240 
  26241 var kMinDimensionIterativeConversion = int32(4)
  26242 
  26243 //------------------------------------------------------------------------------
  26244 // Main function
  26245 
  26246 func PreprocessARGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, picture uintptr) (r int32) {
  26247 	var ok int32
  26248 	_ = ok
  26249 	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)))
  26250 	if !(ok != 0) {
  26251 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  26252 	}
  26253 	return ok
  26254 }
  26255 
  26256 //------------------------------------------------------------------------------
  26257 // "Fast" regular RGB->YUV
  26258 
  26259 var kAlphaFix = int32(19)
  26260 
  26261 // C documentation
  26262 //
  26263 //	// Following table is (1 << kAlphaFix) / a. The (v * kInvAlpha[a]) >> kAlphaFix
  26264 //	// formula is then equal to v / a in most (99.6%) cases. Note that this table
  26265 //	// and constant are adjusted very tightly to fit 32b arithmetic.
  26266 //	// In particular, they use the fact that the operands for 'v / a' are actually
  26267 //	// derived as v = (a0.p0 + a1.p1 + a2.p2 + a3.p3) and a = a0 + a1 + a2 + a3
  26268 //	// with ai in [0..255] and pi in [0..1<<GAMMA_FIX). The constraint to avoid
  26269 //	// overflow is: GAMMA_FIX + kAlphaFix <= 31.
  26270 var kInvAlpha = [1021]uint32_t{
  26271 	1:    uint32(524288),
  26272 	2:    uint32(262144),
  26273 	3:    uint32(174762),
  26274 	4:    uint32(131072),
  26275 	5:    uint32(104857),
  26276 	6:    uint32(87381),
  26277 	7:    uint32(74898),
  26278 	8:    uint32(65536),
  26279 	9:    uint32(58254),
  26280 	10:   uint32(52428),
  26281 	11:   uint32(47662),
  26282 	12:   uint32(43690),
  26283 	13:   uint32(40329),
  26284 	14:   uint32(37449),
  26285 	15:   uint32(34952),
  26286 	16:   uint32(32768),
  26287 	17:   uint32(30840),
  26288 	18:   uint32(29127),
  26289 	19:   uint32(27594),
  26290 	20:   uint32(26214),
  26291 	21:   uint32(24966),
  26292 	22:   uint32(23831),
  26293 	23:   uint32(22795),
  26294 	24:   uint32(21845),
  26295 	25:   uint32(20971),
  26296 	26:   uint32(20164),
  26297 	27:   uint32(19418),
  26298 	28:   uint32(18724),
  26299 	29:   uint32(18078),
  26300 	30:   uint32(17476),
  26301 	31:   uint32(16912),
  26302 	32:   uint32(16384),
  26303 	33:   uint32(15887),
  26304 	34:   uint32(15420),
  26305 	35:   uint32(14979),
  26306 	36:   uint32(14563),
  26307 	37:   uint32(14169),
  26308 	38:   uint32(13797),
  26309 	39:   uint32(13443),
  26310 	40:   uint32(13107),
  26311 	41:   uint32(12787),
  26312 	42:   uint32(12483),
  26313 	43:   uint32(12192),
  26314 	44:   uint32(11915),
  26315 	45:   uint32(11650),
  26316 	46:   uint32(11397),
  26317 	47:   uint32(11155),
  26318 	48:   uint32(10922),
  26319 	49:   uint32(10699),
  26320 	50:   uint32(10485),
  26321 	51:   uint32(10280),
  26322 	52:   uint32(10082),
  26323 	53:   uint32(9892),
  26324 	54:   uint32(9709),
  26325 	55:   uint32(9532),
  26326 	56:   uint32(9362),
  26327 	57:   uint32(9198),
  26328 	58:   uint32(9039),
  26329 	59:   uint32(8886),
  26330 	60:   uint32(8738),
  26331 	61:   uint32(8594),
  26332 	62:   uint32(8456),
  26333 	63:   uint32(8322),
  26334 	64:   uint32(8192),
  26335 	65:   uint32(8065),
  26336 	66:   uint32(7943),
  26337 	67:   uint32(7825),
  26338 	68:   uint32(7710),
  26339 	69:   uint32(7598),
  26340 	70:   uint32(7489),
  26341 	71:   uint32(7384),
  26342 	72:   uint32(7281),
  26343 	73:   uint32(7182),
  26344 	74:   uint32(7084),
  26345 	75:   uint32(6990),
  26346 	76:   uint32(6898),
  26347 	77:   uint32(6808),
  26348 	78:   uint32(6721),
  26349 	79:   uint32(6636),
  26350 	80:   uint32(6553),
  26351 	81:   uint32(6472),
  26352 	82:   uint32(6393),
  26353 	83:   uint32(6316),
  26354 	84:   uint32(6241),
  26355 	85:   uint32(6168),
  26356 	86:   uint32(6096),
  26357 	87:   uint32(6026),
  26358 	88:   uint32(5957),
  26359 	89:   uint32(5890),
  26360 	90:   uint32(5825),
  26361 	91:   uint32(5761),
  26362 	92:   uint32(5698),
  26363 	93:   uint32(5637),
  26364 	94:   uint32(5577),
  26365 	95:   uint32(5518),
  26366 	96:   uint32(5461),
  26367 	97:   uint32(5405),
  26368 	98:   uint32(5349),
  26369 	99:   uint32(5295),
  26370 	100:  uint32(5242),
  26371 	101:  uint32(5190),
  26372 	102:  uint32(5140),
  26373 	103:  uint32(5090),
  26374 	104:  uint32(5041),
  26375 	105:  uint32(4993),
  26376 	106:  uint32(4946),
  26377 	107:  uint32(4899),
  26378 	108:  uint32(4854),
  26379 	109:  uint32(4809),
  26380 	110:  uint32(4766),
  26381 	111:  uint32(4723),
  26382 	112:  uint32(4681),
  26383 	113:  uint32(4639),
  26384 	114:  uint32(4599),
  26385 	115:  uint32(4559),
  26386 	116:  uint32(4519),
  26387 	117:  uint32(4481),
  26388 	118:  uint32(4443),
  26389 	119:  uint32(4405),
  26390 	120:  uint32(4369),
  26391 	121:  uint32(4332),
  26392 	122:  uint32(4297),
  26393 	123:  uint32(4262),
  26394 	124:  uint32(4228),
  26395 	125:  uint32(4194),
  26396 	126:  uint32(4161),
  26397 	127:  uint32(4128),
  26398 	128:  uint32(4096),
  26399 	129:  uint32(4064),
  26400 	130:  uint32(4032),
  26401 	131:  uint32(4002),
  26402 	132:  uint32(3971),
  26403 	133:  uint32(3942),
  26404 	134:  uint32(3912),
  26405 	135:  uint32(3883),
  26406 	136:  uint32(3855),
  26407 	137:  uint32(3826),
  26408 	138:  uint32(3799),
  26409 	139:  uint32(3771),
  26410 	140:  uint32(3744),
  26411 	141:  uint32(3718),
  26412 	142:  uint32(3692),
  26413 	143:  uint32(3666),
  26414 	144:  uint32(3640),
  26415 	145:  uint32(3615),
  26416 	146:  uint32(3591),
  26417 	147:  uint32(3566),
  26418 	148:  uint32(3542),
  26419 	149:  uint32(3518),
  26420 	150:  uint32(3495),
  26421 	151:  uint32(3472),
  26422 	152:  uint32(3449),
  26423 	153:  uint32(3426),
  26424 	154:  uint32(3404),
  26425 	155:  uint32(3382),
  26426 	156:  uint32(3360),
  26427 	157:  uint32(3339),
  26428 	158:  uint32(3318),
  26429 	159:  uint32(3297),
  26430 	160:  uint32(3276),
  26431 	161:  uint32(3256),
  26432 	162:  uint32(3236),
  26433 	163:  uint32(3216),
  26434 	164:  uint32(3196),
  26435 	165:  uint32(3177),
  26436 	166:  uint32(3158),
  26437 	167:  uint32(3139),
  26438 	168:  uint32(3120),
  26439 	169:  uint32(3102),
  26440 	170:  uint32(3084),
  26441 	171:  uint32(3066),
  26442 	172:  uint32(3048),
  26443 	173:  uint32(3030),
  26444 	174:  uint32(3013),
  26445 	175:  uint32(2995),
  26446 	176:  uint32(2978),
  26447 	177:  uint32(2962),
  26448 	178:  uint32(2945),
  26449 	179:  uint32(2928),
  26450 	180:  uint32(2912),
  26451 	181:  uint32(2896),
  26452 	182:  uint32(2880),
  26453 	183:  uint32(2864),
  26454 	184:  uint32(2849),
  26455 	185:  uint32(2833),
  26456 	186:  uint32(2818),
  26457 	187:  uint32(2803),
  26458 	188:  uint32(2788),
  26459 	189:  uint32(2774),
  26460 	190:  uint32(2759),
  26461 	191:  uint32(2744),
  26462 	192:  uint32(2730),
  26463 	193:  uint32(2716),
  26464 	194:  uint32(2702),
  26465 	195:  uint32(2688),
  26466 	196:  uint32(2674),
  26467 	197:  uint32(2661),
  26468 	198:  uint32(2647),
  26469 	199:  uint32(2634),
  26470 	200:  uint32(2621),
  26471 	201:  uint32(2608),
  26472 	202:  uint32(2595),
  26473 	203:  uint32(2582),
  26474 	204:  uint32(2570),
  26475 	205:  uint32(2557),
  26476 	206:  uint32(2545),
  26477 	207:  uint32(2532),
  26478 	208:  uint32(2520),
  26479 	209:  uint32(2508),
  26480 	210:  uint32(2496),
  26481 	211:  uint32(2484),
  26482 	212:  uint32(2473),
  26483 	213:  uint32(2461),
  26484 	214:  uint32(2449),
  26485 	215:  uint32(2438),
  26486 	216:  uint32(2427),
  26487 	217:  uint32(2416),
  26488 	218:  uint32(2404),
  26489 	219:  uint32(2394),
  26490 	220:  uint32(2383),
  26491 	221:  uint32(2372),
  26492 	222:  uint32(2361),
  26493 	223:  uint32(2351),
  26494 	224:  uint32(2340),
  26495 	225:  uint32(2330),
  26496 	226:  uint32(2319),
  26497 	227:  uint32(2309),
  26498 	228:  uint32(2299),
  26499 	229:  uint32(2289),
  26500 	230:  uint32(2279),
  26501 	231:  uint32(2269),
  26502 	232:  uint32(2259),
  26503 	233:  uint32(2250),
  26504 	234:  uint32(2240),
  26505 	235:  uint32(2231),
  26506 	236:  uint32(2221),
  26507 	237:  uint32(2212),
  26508 	238:  uint32(2202),
  26509 	239:  uint32(2193),
  26510 	240:  uint32(2184),
  26511 	241:  uint32(2175),
  26512 	242:  uint32(2166),
  26513 	243:  uint32(2157),
  26514 	244:  uint32(2148),
  26515 	245:  uint32(2139),
  26516 	246:  uint32(2131),
  26517 	247:  uint32(2122),
  26518 	248:  uint32(2114),
  26519 	249:  uint32(2105),
  26520 	250:  uint32(2097),
  26521 	251:  uint32(2088),
  26522 	252:  uint32(2080),
  26523 	253:  uint32(2072),
  26524 	254:  uint32(2064),
  26525 	255:  uint32(2056),
  26526 	256:  uint32(2048),
  26527 	257:  uint32(2040),
  26528 	258:  uint32(2032),
  26529 	259:  uint32(2024),
  26530 	260:  uint32(2016),
  26531 	261:  uint32(2008),
  26532 	262:  uint32(2001),
  26533 	263:  uint32(1993),
  26534 	264:  uint32(1985),
  26535 	265:  uint32(1978),
  26536 	266:  uint32(1971),
  26537 	267:  uint32(1963),
  26538 	268:  uint32(1956),
  26539 	269:  uint32(1949),
  26540 	270:  uint32(1941),
  26541 	271:  uint32(1934),
  26542 	272:  uint32(1927),
  26543 	273:  uint32(1920),
  26544 	274:  uint32(1913),
  26545 	275:  uint32(1906),
  26546 	276:  uint32(1899),
  26547 	277:  uint32(1892),
  26548 	278:  uint32(1885),
  26549 	279:  uint32(1879),
  26550 	280:  uint32(1872),
  26551 	281:  uint32(1865),
  26552 	282:  uint32(1859),
  26553 	283:  uint32(1852),
  26554 	284:  uint32(1846),
  26555 	285:  uint32(1839),
  26556 	286:  uint32(1833),
  26557 	287:  uint32(1826),
  26558 	288:  uint32(1820),
  26559 	289:  uint32(1814),
  26560 	290:  uint32(1807),
  26561 	291:  uint32(1801),
  26562 	292:  uint32(1795),
  26563 	293:  uint32(1789),
  26564 	294:  uint32(1783),
  26565 	295:  uint32(1777),
  26566 	296:  uint32(1771),
  26567 	297:  uint32(1765),
  26568 	298:  uint32(1759),
  26569 	299:  uint32(1753),
  26570 	300:  uint32(1747),
  26571 	301:  uint32(1741),
  26572 	302:  uint32(1736),
  26573 	303:  uint32(1730),
  26574 	304:  uint32(1724),
  26575 	305:  uint32(1718),
  26576 	306:  uint32(1713),
  26577 	307:  uint32(1707),
  26578 	308:  uint32(1702),
  26579 	309:  uint32(1696),
  26580 	310:  uint32(1691),
  26581 	311:  uint32(1685),
  26582 	312:  uint32(1680),
  26583 	313:  uint32(1675),
  26584 	314:  uint32(1669),
  26585 	315:  uint32(1664),
  26586 	316:  uint32(1659),
  26587 	317:  uint32(1653),
  26588 	318:  uint32(1648),
  26589 	319:  uint32(1643),
  26590 	320:  uint32(1638),
  26591 	321:  uint32(1633),
  26592 	322:  uint32(1628),
  26593 	323:  uint32(1623),
  26594 	324:  uint32(1618),
  26595 	325:  uint32(1613),
  26596 	326:  uint32(1608),
  26597 	327:  uint32(1603),
  26598 	328:  uint32(1598),
  26599 	329:  uint32(1593),
  26600 	330:  uint32(1588),
  26601 	331:  uint32(1583),
  26602 	332:  uint32(1579),
  26603 	333:  uint32(1574),
  26604 	334:  uint32(1569),
  26605 	335:  uint32(1565),
  26606 	336:  uint32(1560),
  26607 	337:  uint32(1555),
  26608 	338:  uint32(1551),
  26609 	339:  uint32(1546),
  26610 	340:  uint32(1542),
  26611 	341:  uint32(1537),
  26612 	342:  uint32(1533),
  26613 	343:  uint32(1528),
  26614 	344:  uint32(1524),
  26615 	345:  uint32(1519),
  26616 	346:  uint32(1515),
  26617 	347:  uint32(1510),
  26618 	348:  uint32(1506),
  26619 	349:  uint32(1502),
  26620 	350:  uint32(1497),
  26621 	351:  uint32(1493),
  26622 	352:  uint32(1489),
  26623 	353:  uint32(1485),
  26624 	354:  uint32(1481),
  26625 	355:  uint32(1476),
  26626 	356:  uint32(1472),
  26627 	357:  uint32(1468),
  26628 	358:  uint32(1464),
  26629 	359:  uint32(1460),
  26630 	360:  uint32(1456),
  26631 	361:  uint32(1452),
  26632 	362:  uint32(1448),
  26633 	363:  uint32(1444),
  26634 	364:  uint32(1440),
  26635 	365:  uint32(1436),
  26636 	366:  uint32(1432),
  26637 	367:  uint32(1428),
  26638 	368:  uint32(1424),
  26639 	369:  uint32(1420),
  26640 	370:  uint32(1416),
  26641 	371:  uint32(1413),
  26642 	372:  uint32(1409),
  26643 	373:  uint32(1405),
  26644 	374:  uint32(1401),
  26645 	375:  uint32(1398),
  26646 	376:  uint32(1394),
  26647 	377:  uint32(1390),
  26648 	378:  uint32(1387),
  26649 	379:  uint32(1383),
  26650 	380:  uint32(1379),
  26651 	381:  uint32(1376),
  26652 	382:  uint32(1372),
  26653 	383:  uint32(1368),
  26654 	384:  uint32(1365),
  26655 	385:  uint32(1361),
  26656 	386:  uint32(1358),
  26657 	387:  uint32(1354),
  26658 	388:  uint32(1351),
  26659 	389:  uint32(1347),
  26660 	390:  uint32(1344),
  26661 	391:  uint32(1340),
  26662 	392:  uint32(1337),
  26663 	393:  uint32(1334),
  26664 	394:  uint32(1330),
  26665 	395:  uint32(1327),
  26666 	396:  uint32(1323),
  26667 	397:  uint32(1320),
  26668 	398:  uint32(1317),
  26669 	399:  uint32(1314),
  26670 	400:  uint32(1310),
  26671 	401:  uint32(1307),
  26672 	402:  uint32(1304),
  26673 	403:  uint32(1300),
  26674 	404:  uint32(1297),
  26675 	405:  uint32(1294),
  26676 	406:  uint32(1291),
  26677 	407:  uint32(1288),
  26678 	408:  uint32(1285),
  26679 	409:  uint32(1281),
  26680 	410:  uint32(1278),
  26681 	411:  uint32(1275),
  26682 	412:  uint32(1272),
  26683 	413:  uint32(1269),
  26684 	414:  uint32(1266),
  26685 	415:  uint32(1263),
  26686 	416:  uint32(1260),
  26687 	417:  uint32(1257),
  26688 	418:  uint32(1254),
  26689 	419:  uint32(1251),
  26690 	420:  uint32(1248),
  26691 	421:  uint32(1245),
  26692 	422:  uint32(1242),
  26693 	423:  uint32(1239),
  26694 	424:  uint32(1236),
  26695 	425:  uint32(1233),
  26696 	426:  uint32(1230),
  26697 	427:  uint32(1227),
  26698 	428:  uint32(1224),
  26699 	429:  uint32(1222),
  26700 	430:  uint32(1219),
  26701 	431:  uint32(1216),
  26702 	432:  uint32(1213),
  26703 	433:  uint32(1210),
  26704 	434:  uint32(1208),
  26705 	435:  uint32(1205),
  26706 	436:  uint32(1202),
  26707 	437:  uint32(1199),
  26708 	438:  uint32(1197),
  26709 	439:  uint32(1194),
  26710 	440:  uint32(1191),
  26711 	441:  uint32(1188),
  26712 	442:  uint32(1186),
  26713 	443:  uint32(1183),
  26714 	444:  uint32(1180),
  26715 	445:  uint32(1178),
  26716 	446:  uint32(1175),
  26717 	447:  uint32(1172),
  26718 	448:  uint32(1170),
  26719 	449:  uint32(1167),
  26720 	450:  uint32(1165),
  26721 	451:  uint32(1162),
  26722 	452:  uint32(1159),
  26723 	453:  uint32(1157),
  26724 	454:  uint32(1154),
  26725 	455:  uint32(1152),
  26726 	456:  uint32(1149),
  26727 	457:  uint32(1147),
  26728 	458:  uint32(1144),
  26729 	459:  uint32(1142),
  26730 	460:  uint32(1139),
  26731 	461:  uint32(1137),
  26732 	462:  uint32(1134),
  26733 	463:  uint32(1132),
  26734 	464:  uint32(1129),
  26735 	465:  uint32(1127),
  26736 	466:  uint32(1125),
  26737 	467:  uint32(1122),
  26738 	468:  uint32(1120),
  26739 	469:  uint32(1117),
  26740 	470:  uint32(1115),
  26741 	471:  uint32(1113),
  26742 	472:  uint32(1110),
  26743 	473:  uint32(1108),
  26744 	474:  uint32(1106),
  26745 	475:  uint32(1103),
  26746 	476:  uint32(1101),
  26747 	477:  uint32(1099),
  26748 	478:  uint32(1096),
  26749 	479:  uint32(1094),
  26750 	480:  uint32(1092),
  26751 	481:  uint32(1089),
  26752 	482:  uint32(1087),
  26753 	483:  uint32(1085),
  26754 	484:  uint32(1083),
  26755 	485:  uint32(1081),
  26756 	486:  uint32(1078),
  26757 	487:  uint32(1076),
  26758 	488:  uint32(1074),
  26759 	489:  uint32(1072),
  26760 	490:  uint32(1069),
  26761 	491:  uint32(1067),
  26762 	492:  uint32(1065),
  26763 	493:  uint32(1063),
  26764 	494:  uint32(1061),
  26765 	495:  uint32(1059),
  26766 	496:  uint32(1057),
  26767 	497:  uint32(1054),
  26768 	498:  uint32(1052),
  26769 	499:  uint32(1050),
  26770 	500:  uint32(1048),
  26771 	501:  uint32(1046),
  26772 	502:  uint32(1044),
  26773 	503:  uint32(1042),
  26774 	504:  uint32(1040),
  26775 	505:  uint32(1038),
  26776 	506:  uint32(1036),
  26777 	507:  uint32(1034),
  26778 	508:  uint32(1032),
  26779 	509:  uint32(1030),
  26780 	510:  uint32(1028),
  26781 	511:  uint32(1026),
  26782 	512:  uint32(1024),
  26783 	513:  uint32(1022),
  26784 	514:  uint32(1020),
  26785 	515:  uint32(1018),
  26786 	516:  uint32(1016),
  26787 	517:  uint32(1014),
  26788 	518:  uint32(1012),
  26789 	519:  uint32(1010),
  26790 	520:  uint32(1008),
  26791 	521:  uint32(1006),
  26792 	522:  uint32(1004),
  26793 	523:  uint32(1002),
  26794 	524:  uint32(1000),
  26795 	525:  uint32(998),
  26796 	526:  uint32(996),
  26797 	527:  uint32(994),
  26798 	528:  uint32(992),
  26799 	529:  uint32(991),
  26800 	530:  uint32(989),
  26801 	531:  uint32(987),
  26802 	532:  uint32(985),
  26803 	533:  uint32(983),
  26804 	534:  uint32(981),
  26805 	535:  uint32(979),
  26806 	536:  uint32(978),
  26807 	537:  uint32(976),
  26808 	538:  uint32(974),
  26809 	539:  uint32(972),
  26810 	540:  uint32(970),
  26811 	541:  uint32(969),
  26812 	542:  uint32(967),
  26813 	543:  uint32(965),
  26814 	544:  uint32(963),
  26815 	545:  uint32(961),
  26816 	546:  uint32(960),
  26817 	547:  uint32(958),
  26818 	548:  uint32(956),
  26819 	549:  uint32(954),
  26820 	550:  uint32(953),
  26821 	551:  uint32(951),
  26822 	552:  uint32(949),
  26823 	553:  uint32(948),
  26824 	554:  uint32(946),
  26825 	555:  uint32(944),
  26826 	556:  uint32(942),
  26827 	557:  uint32(941),
  26828 	558:  uint32(939),
  26829 	559:  uint32(937),
  26830 	560:  uint32(936),
  26831 	561:  uint32(934),
  26832 	562:  uint32(932),
  26833 	563:  uint32(931),
  26834 	564:  uint32(929),
  26835 	565:  uint32(927),
  26836 	566:  uint32(926),
  26837 	567:  uint32(924),
  26838 	568:  uint32(923),
  26839 	569:  uint32(921),
  26840 	570:  uint32(919),
  26841 	571:  uint32(918),
  26842 	572:  uint32(916),
  26843 	573:  uint32(914),
  26844 	574:  uint32(913),
  26845 	575:  uint32(911),
  26846 	576:  uint32(910),
  26847 	577:  uint32(908),
  26848 	578:  uint32(907),
  26849 	579:  uint32(905),
  26850 	580:  uint32(903),
  26851 	581:  uint32(902),
  26852 	582:  uint32(900),
  26853 	583:  uint32(899),
  26854 	584:  uint32(897),
  26855 	585:  uint32(896),
  26856 	586:  uint32(894),
  26857 	587:  uint32(893),
  26858 	588:  uint32(891),
  26859 	589:  uint32(890),
  26860 	590:  uint32(888),
  26861 	591:  uint32(887),
  26862 	592:  uint32(885),
  26863 	593:  uint32(884),
  26864 	594:  uint32(882),
  26865 	595:  uint32(881),
  26866 	596:  uint32(879),
  26867 	597:  uint32(878),
  26868 	598:  uint32(876),
  26869 	599:  uint32(875),
  26870 	600:  uint32(873),
  26871 	601:  uint32(872),
  26872 	602:  uint32(870),
  26873 	603:  uint32(869),
  26874 	604:  uint32(868),
  26875 	605:  uint32(866),
  26876 	606:  uint32(865),
  26877 	607:  uint32(863),
  26878 	608:  uint32(862),
  26879 	609:  uint32(860),
  26880 	610:  uint32(859),
  26881 	611:  uint32(858),
  26882 	612:  uint32(856),
  26883 	613:  uint32(855),
  26884 	614:  uint32(853),
  26885 	615:  uint32(852),
  26886 	616:  uint32(851),
  26887 	617:  uint32(849),
  26888 	618:  uint32(848),
  26889 	619:  uint32(846),
  26890 	620:  uint32(845),
  26891 	621:  uint32(844),
  26892 	622:  uint32(842),
  26893 	623:  uint32(841),
  26894 	624:  uint32(840),
  26895 	625:  uint32(838),
  26896 	626:  uint32(837),
  26897 	627:  uint32(836),
  26898 	628:  uint32(834),
  26899 	629:  uint32(833),
  26900 	630:  uint32(832),
  26901 	631:  uint32(830),
  26902 	632:  uint32(829),
  26903 	633:  uint32(828),
  26904 	634:  uint32(826),
  26905 	635:  uint32(825),
  26906 	636:  uint32(824),
  26907 	637:  uint32(823),
  26908 	638:  uint32(821),
  26909 	639:  uint32(820),
  26910 	640:  uint32(819),
  26911 	641:  uint32(817),
  26912 	642:  uint32(816),
  26913 	643:  uint32(815),
  26914 	644:  uint32(814),
  26915 	645:  uint32(812),
  26916 	646:  uint32(811),
  26917 	647:  uint32(810),
  26918 	648:  uint32(809),
  26919 	649:  uint32(807),
  26920 	650:  uint32(806),
  26921 	651:  uint32(805),
  26922 	652:  uint32(804),
  26923 	653:  uint32(802),
  26924 	654:  uint32(801),
  26925 	655:  uint32(800),
  26926 	656:  uint32(799),
  26927 	657:  uint32(798),
  26928 	658:  uint32(796),
  26929 	659:  uint32(795),
  26930 	660:  uint32(794),
  26931 	661:  uint32(793),
  26932 	662:  uint32(791),
  26933 	663:  uint32(790),
  26934 	664:  uint32(789),
  26935 	665:  uint32(788),
  26936 	666:  uint32(787),
  26937 	667:  uint32(786),
  26938 	668:  uint32(784),
  26939 	669:  uint32(783),
  26940 	670:  uint32(782),
  26941 	671:  uint32(781),
  26942 	672:  uint32(780),
  26943 	673:  uint32(779),
  26944 	674:  uint32(777),
  26945 	675:  uint32(776),
  26946 	676:  uint32(775),
  26947 	677:  uint32(774),
  26948 	678:  uint32(773),
  26949 	679:  uint32(772),
  26950 	680:  uint32(771),
  26951 	681:  uint32(769),
  26952 	682:  uint32(768),
  26953 	683:  uint32(767),
  26954 	684:  uint32(766),
  26955 	685:  uint32(765),
  26956 	686:  uint32(764),
  26957 	687:  uint32(763),
  26958 	688:  uint32(762),
  26959 	689:  uint32(760),
  26960 	690:  uint32(759),
  26961 	691:  uint32(758),
  26962 	692:  uint32(757),
  26963 	693:  uint32(756),
  26964 	694:  uint32(755),
  26965 	695:  uint32(754),
  26966 	696:  uint32(753),
  26967 	697:  uint32(752),
  26968 	698:  uint32(751),
  26969 	699:  uint32(750),
  26970 	700:  uint32(748),
  26971 	701:  uint32(747),
  26972 	702:  uint32(746),
  26973 	703:  uint32(745),
  26974 	704:  uint32(744),
  26975 	705:  uint32(743),
  26976 	706:  uint32(742),
  26977 	707:  uint32(741),
  26978 	708:  uint32(740),
  26979 	709:  uint32(739),
  26980 	710:  uint32(738),
  26981 	711:  uint32(737),
  26982 	712:  uint32(736),
  26983 	713:  uint32(735),
  26984 	714:  uint32(734),
  26985 	715:  uint32(733),
  26986 	716:  uint32(732),
  26987 	717:  uint32(731),
  26988 	718:  uint32(730),
  26989 	719:  uint32(729),
  26990 	720:  uint32(728),
  26991 	721:  uint32(727),
  26992 	722:  uint32(726),
  26993 	723:  uint32(725),
  26994 	724:  uint32(724),
  26995 	725:  uint32(723),
  26996 	726:  uint32(722),
  26997 	727:  uint32(721),
  26998 	728:  uint32(720),
  26999 	729:  uint32(719),
  27000 	730:  uint32(718),
  27001 	731:  uint32(717),
  27002 	732:  uint32(716),
  27003 	733:  uint32(715),
  27004 	734:  uint32(714),
  27005 	735:  uint32(713),
  27006 	736:  uint32(712),
  27007 	737:  uint32(711),
  27008 	738:  uint32(710),
  27009 	739:  uint32(709),
  27010 	740:  uint32(708),
  27011 	741:  uint32(707),
  27012 	742:  uint32(706),
  27013 	743:  uint32(705),
  27014 	744:  uint32(704),
  27015 	745:  uint32(703),
  27016 	746:  uint32(702),
  27017 	747:  uint32(701),
  27018 	748:  uint32(700),
  27019 	749:  uint32(699),
  27020 	750:  uint32(699),
  27021 	751:  uint32(698),
  27022 	752:  uint32(697),
  27023 	753:  uint32(696),
  27024 	754:  uint32(695),
  27025 	755:  uint32(694),
  27026 	756:  uint32(693),
  27027 	757:  uint32(692),
  27028 	758:  uint32(691),
  27029 	759:  uint32(690),
  27030 	760:  uint32(689),
  27031 	761:  uint32(688),
  27032 	762:  uint32(688),
  27033 	763:  uint32(687),
  27034 	764:  uint32(686),
  27035 	765:  uint32(685),
  27036 	766:  uint32(684),
  27037 	767:  uint32(683),
  27038 	768:  uint32(682),
  27039 	769:  uint32(681),
  27040 	770:  uint32(680),
  27041 	771:  uint32(680),
  27042 	772:  uint32(679),
  27043 	773:  uint32(678),
  27044 	774:  uint32(677),
  27045 	775:  uint32(676),
  27046 	776:  uint32(675),
  27047 	777:  uint32(674),
  27048 	778:  uint32(673),
  27049 	779:  uint32(673),
  27050 	780:  uint32(672),
  27051 	781:  uint32(671),
  27052 	782:  uint32(670),
  27053 	783:  uint32(669),
  27054 	784:  uint32(668),
  27055 	785:  uint32(667),
  27056 	786:  uint32(667),
  27057 	787:  uint32(666),
  27058 	788:  uint32(665),
  27059 	789:  uint32(664),
  27060 	790:  uint32(663),
  27061 	791:  uint32(662),
  27062 	792:  uint32(661),
  27063 	793:  uint32(661),
  27064 	794:  uint32(660),
  27065 	795:  uint32(659),
  27066 	796:  uint32(658),
  27067 	797:  uint32(657),
  27068 	798:  uint32(657),
  27069 	799:  uint32(656),
  27070 	800:  uint32(655),
  27071 	801:  uint32(654),
  27072 	802:  uint32(653),
  27073 	803:  uint32(652),
  27074 	804:  uint32(652),
  27075 	805:  uint32(651),
  27076 	806:  uint32(650),
  27077 	807:  uint32(649),
  27078 	808:  uint32(648),
  27079 	809:  uint32(648),
  27080 	810:  uint32(647),
  27081 	811:  uint32(646),
  27082 	812:  uint32(645),
  27083 	813:  uint32(644),
  27084 	814:  uint32(644),
  27085 	815:  uint32(643),
  27086 	816:  uint32(642),
  27087 	817:  uint32(641),
  27088 	818:  uint32(640),
  27089 	819:  uint32(640),
  27090 	820:  uint32(639),
  27091 	821:  uint32(638),
  27092 	822:  uint32(637),
  27093 	823:  uint32(637),
  27094 	824:  uint32(636),
  27095 	825:  uint32(635),
  27096 	826:  uint32(634),
  27097 	827:  uint32(633),
  27098 	828:  uint32(633),
  27099 	829:  uint32(632),
  27100 	830:  uint32(631),
  27101 	831:  uint32(630),
  27102 	832:  uint32(630),
  27103 	833:  uint32(629),
  27104 	834:  uint32(628),
  27105 	835:  uint32(627),
  27106 	836:  uint32(627),
  27107 	837:  uint32(626),
  27108 	838:  uint32(625),
  27109 	839:  uint32(624),
  27110 	840:  uint32(624),
  27111 	841:  uint32(623),
  27112 	842:  uint32(622),
  27113 	843:  uint32(621),
  27114 	844:  uint32(621),
  27115 	845:  uint32(620),
  27116 	846:  uint32(619),
  27117 	847:  uint32(618),
  27118 	848:  uint32(618),
  27119 	849:  uint32(617),
  27120 	850:  uint32(616),
  27121 	851:  uint32(616),
  27122 	852:  uint32(615),
  27123 	853:  uint32(614),
  27124 	854:  uint32(613),
  27125 	855:  uint32(613),
  27126 	856:  uint32(612),
  27127 	857:  uint32(611),
  27128 	858:  uint32(611),
  27129 	859:  uint32(610),
  27130 	860:  uint32(609),
  27131 	861:  uint32(608),
  27132 	862:  uint32(608),
  27133 	863:  uint32(607),
  27134 	864:  uint32(606),
  27135 	865:  uint32(606),
  27136 	866:  uint32(605),
  27137 	867:  uint32(604),
  27138 	868:  uint32(604),
  27139 	869:  uint32(603),
  27140 	870:  uint32(602),
  27141 	871:  uint32(601),
  27142 	872:  uint32(601),
  27143 	873:  uint32(600),
  27144 	874:  uint32(599),
  27145 	875:  uint32(599),
  27146 	876:  uint32(598),
  27147 	877:  uint32(597),
  27148 	878:  uint32(597),
  27149 	879:  uint32(596),
  27150 	880:  uint32(595),
  27151 	881:  uint32(595),
  27152 	882:  uint32(594),
  27153 	883:  uint32(593),
  27154 	884:  uint32(593),
  27155 	885:  uint32(592),
  27156 	886:  uint32(591),
  27157 	887:  uint32(591),
  27158 	888:  uint32(590),
  27159 	889:  uint32(589),
  27160 	890:  uint32(589),
  27161 	891:  uint32(588),
  27162 	892:  uint32(587),
  27163 	893:  uint32(587),
  27164 	894:  uint32(586),
  27165 	895:  uint32(585),
  27166 	896:  uint32(585),
  27167 	897:  uint32(584),
  27168 	898:  uint32(583),
  27169 	899:  uint32(583),
  27170 	900:  uint32(582),
  27171 	901:  uint32(581),
  27172 	902:  uint32(581),
  27173 	903:  uint32(580),
  27174 	904:  uint32(579),
  27175 	905:  uint32(579),
  27176 	906:  uint32(578),
  27177 	907:  uint32(578),
  27178 	908:  uint32(577),
  27179 	909:  uint32(576),
  27180 	910:  uint32(576),
  27181 	911:  uint32(575),
  27182 	912:  uint32(574),
  27183 	913:  uint32(574),
  27184 	914:  uint32(573),
  27185 	915:  uint32(572),
  27186 	916:  uint32(572),
  27187 	917:  uint32(571),
  27188 	918:  uint32(571),
  27189 	919:  uint32(570),
  27190 	920:  uint32(569),
  27191 	921:  uint32(569),
  27192 	922:  uint32(568),
  27193 	923:  uint32(568),
  27194 	924:  uint32(567),
  27195 	925:  uint32(566),
  27196 	926:  uint32(566),
  27197 	927:  uint32(565),
  27198 	928:  uint32(564),
  27199 	929:  uint32(564),
  27200 	930:  uint32(563),
  27201 	931:  uint32(563),
  27202 	932:  uint32(562),
  27203 	933:  uint32(561),
  27204 	934:  uint32(561),
  27205 	935:  uint32(560),
  27206 	936:  uint32(560),
  27207 	937:  uint32(559),
  27208 	938:  uint32(558),
  27209 	939:  uint32(558),
  27210 	940:  uint32(557),
  27211 	941:  uint32(557),
  27212 	942:  uint32(556),
  27213 	943:  uint32(555),
  27214 	944:  uint32(555),
  27215 	945:  uint32(554),
  27216 	946:  uint32(554),
  27217 	947:  uint32(553),
  27218 	948:  uint32(553),
  27219 	949:  uint32(552),
  27220 	950:  uint32(551),
  27221 	951:  uint32(551),
  27222 	952:  uint32(550),
  27223 	953:  uint32(550),
  27224 	954:  uint32(549),
  27225 	955:  uint32(548),
  27226 	956:  uint32(548),
  27227 	957:  uint32(547),
  27228 	958:  uint32(547),
  27229 	959:  uint32(546),
  27230 	960:  uint32(546),
  27231 	961:  uint32(545),
  27232 	962:  uint32(544),
  27233 	963:  uint32(544),
  27234 	964:  uint32(543),
  27235 	965:  uint32(543),
  27236 	966:  uint32(542),
  27237 	967:  uint32(542),
  27238 	968:  uint32(541),
  27239 	969:  uint32(541),
  27240 	970:  uint32(540),
  27241 	971:  uint32(539),
  27242 	972:  uint32(539),
  27243 	973:  uint32(538),
  27244 	974:  uint32(538),
  27245 	975:  uint32(537),
  27246 	976:  uint32(537),
  27247 	977:  uint32(536),
  27248 	978:  uint32(536),
  27249 	979:  uint32(535),
  27250 	980:  uint32(534),
  27251 	981:  uint32(534),
  27252 	982:  uint32(533),
  27253 	983:  uint32(533),
  27254 	984:  uint32(532),
  27255 	985:  uint32(532),
  27256 	986:  uint32(531),
  27257 	987:  uint32(531),
  27258 	988:  uint32(530),
  27259 	989:  uint32(530),
  27260 	990:  uint32(529),
  27261 	991:  uint32(529),
  27262 	992:  uint32(528),
  27263 	993:  uint32(527),
  27264 	994:  uint32(527),
  27265 	995:  uint32(526),
  27266 	996:  uint32(526),
  27267 	997:  uint32(525),
  27268 	998:  uint32(525),
  27269 	999:  uint32(524),
  27270 	1000: uint32(524),
  27271 	1001: uint32(523),
  27272 	1002: uint32(523),
  27273 	1003: uint32(522),
  27274 	1004: uint32(522),
  27275 	1005: uint32(521),
  27276 	1006: uint32(521),
  27277 	1007: uint32(520),
  27278 	1008: uint32(520),
  27279 	1009: uint32(519),
  27280 	1010: uint32(519),
  27281 	1011: uint32(518),
  27282 	1012: uint32(518),
  27283 	1013: uint32(517),
  27284 	1014: uint32(517),
  27285 	1015: uint32(516),
  27286 	1016: uint32(516),
  27287 	1017: uint32(515),
  27288 	1018: uint32(515),
  27289 	1019: uint32(514),
  27290 	1020: uint32(514),
  27291 }
  27292 
  27293 // Note that LinearToGamma() expects the values to be premultiplied by 4,
  27294 // so we incorporate this factor 4 inside the DIVIDE_BY_ALPHA macro directly.
  27295 
  27296 func LinearToGammaWeighted(tls *libc.TLS, src uintptr, a_ptr uintptr, total_a uint32_t, step int32, rgb_stride int32) (r int32) {
  27297 	var sum uint32_t
  27298 	_ = sum
  27299 	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))))
  27300 	return LinearToGamma(tls, sum*kInvAlpha[total_a]>>(kAlphaFix-libc.Int32FromInt32(2)), 0)
  27301 }
  27302 
  27303 func ConvertRowToY(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, dst_y uintptr, width int32, rg uintptr) {
  27304 	var i, j int32
  27305 	_, _ = i, j
  27306 	i = 0
  27307 	j = libc.Int32FromInt32(0)
  27308 	for {
  27309 		if !(i < width) {
  27310 			break
  27311 		}
  27312 		**(**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))
  27313 		goto _1
  27314 	_1:
  27315 		;
  27316 		i = i + int32(1)
  27317 		j = j + step
  27318 	}
  27319 }
  27320 
  27321 func AccumulateRGBA(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, a_ptr uintptr, rgb_stride int32, dst uintptr, width int32) {
  27322 	var a, a1 uint32_t
  27323 	var b, b1, g, g1, i, j, r, r1 int32
  27324 	_, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, g, g1, i, j, r, r1
  27325 	// we loop over 2x2 blocks and produce one R/G/B/A value for each.
  27326 	i = 0
  27327 	j = libc.Int32FromInt32(0)
  27328 	for {
  27329 		if !(i < width>>int32(1)) {
  27330 			break
  27331 		}
  27332 		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))))))
  27333 		if a == libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a == uint32(0) {
  27334 			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)
  27335 			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)
  27336 			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)
  27337 		} else {
  27338 			r = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27339 			g = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27340 			b = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a, int32(4), rgb_stride)
  27341 		}
  27342 		**(**uint16_t)(__ccgo_up(dst)) = libc.Uint16FromInt32(r)
  27343 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = libc.Uint16FromInt32(g)
  27344 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = libc.Uint16FromInt32(b)
  27345 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a)
  27346 		goto _1
  27347 	_1:
  27348 		;
  27349 		i = i + int32(1)
  27350 		j = j + libc.Int32FromInt32(2)*libc.Int32FromInt32(4)
  27351 		dst = dst + uintptr(4)*2
  27352 	}
  27353 	if width&int32(1) != 0 {
  27354 		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)))))
  27355 		if a1 == libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(0xff)) || a1 == uint32(0) {
  27356 			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))
  27357 			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))
  27358 			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))
  27359 		} else {
  27360 			r1 = LinearToGammaWeighted(tls, r_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27361 			g1 = LinearToGammaWeighted(tls, g_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27362 			b1 = LinearToGammaWeighted(tls, b_ptr+uintptr(j), a_ptr+uintptr(j), a1, 0, rgb_stride)
  27363 		}
  27364 		**(**uint16_t)(__ccgo_up(dst)) = libc.Uint16FromInt32(r1)
  27365 		**(**uint16_t)(__ccgo_up(dst + 1*2)) = libc.Uint16FromInt32(g1)
  27366 		**(**uint16_t)(__ccgo_up(dst + 2*2)) = libc.Uint16FromInt32(b1)
  27367 		**(**uint16_t)(__ccgo_up(dst + 3*2)) = uint16(a1)
  27368 	}
  27369 }
  27370 
  27371 func AccumulateRGB(tls *libc.TLS, r_ptr uintptr, g_ptr uintptr, b_ptr uintptr, step int32, rgb_stride int32, dst uintptr, width int32) {
  27372 	var i, j int32
  27373 	_, _ = i, j
  27374 	i = 0
  27375 	j = libc.Int32FromInt32(0)
  27376 	for {
  27377 		if !(i < width>>int32(1)) {
  27378 			break
  27379 		}
  27380 		**(**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))
  27381 		**(**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))
  27382 		**(**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))
  27383 		// MemorySanitizer may raise false positives with data that passes through
  27384 		// RGBA32PackedToPlanar_16b_SSE41() due to incorrect modeling of shuffles.
  27385 		// See https://crbug.com/webp/573.
  27386 		goto _1
  27387 	_1:
  27388 		;
  27389 		i = i + int32(1)
  27390 		j = j + int32(2)*step
  27391 		dst = dst + uintptr(4)*2
  27392 	}
  27393 	if width&int32(1) != 0 {
  27394 		**(**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)))
  27395 		**(**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)))
  27396 		**(**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)))
  27397 	}
  27398 }
  27399 
  27400 func ConvertRowsToUV(tls *libc.TLS, rgb uintptr, dst_u uintptr, dst_v uintptr, width int32, rg uintptr) {
  27401 	var b, g, i, r int32
  27402 	_, _, _, _ = b, g, i, r
  27403 	i = 0
  27404 	for {
  27405 		if !(i < width) {
  27406 			break
  27407 		}
  27408 		r = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb)))
  27409 		g = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  27410 		b = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  27411 		**(**uint8_t)(__ccgo_up(dst_u + uintptr(i))) = libc.Uint8FromInt32(RGBToU(tls, r, g, b, rg))
  27412 		**(**uint8_t)(__ccgo_up(dst_v + uintptr(i))) = libc.Uint8FromInt32(RGBToV(tls, r, g, b, rg))
  27413 		goto _1
  27414 	_1:
  27415 		;
  27416 		i = i + int32(1)
  27417 		rgb = rgb + uintptr(4)*2
  27418 	}
  27419 }
  27420 
  27421 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) {
  27422 	bp := tls.Alloc(240)
  27423 	defer tls.Free(240)
  27424 	var dst_a, dst_u, dst_v, dst_y, rg, tmp_rgb uintptr
  27425 	var has_alpha, height, is_rgb, row_has_alpha, rows_have_alpha, use_dsp, uv_width, width, y, v1 int32
  27426 	var _ /* base_rg at bp+0 */ VP8Random
  27427 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  27428 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27429 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27430 	has_alpha = CheckNonOpaque(tls, a_ptr, width, height, step, rgb_stride)
  27431 	is_rgb = libc.BoolInt32(r_ptr < b_ptr) // otherwise it's bgr
  27432 	if has_alpha != 0 {
  27433 		v1 = int32(WEBP_YUV420A)
  27434 	} else {
  27435 		v1 = int32(WEBP_YUV420)
  27436 	}
  27437 	(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = v1
  27438 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = 0
  27439 	// disable smart conversion if source is too small (overkill).
  27440 	if width < kMinDimensionIterativeConversion || height < kMinDimensionIterativeConversion {
  27441 		use_iterative_conversion = 0
  27442 	}
  27443 	if !(WebPPictureAllocYUVA(tls, picture) != 0) {
  27444 		return 0
  27445 	}
  27446 	if has_alpha != 0 {
  27447 	}
  27448 	if use_iterative_conversion != 0 {
  27449 		SharpYuvInit(tls, VP8GetCPUInfo)
  27450 		if !(PreprocessARGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, picture) != 0) {
  27451 			return 0
  27452 		}
  27453 		if has_alpha != 0 {
  27454 			(*(*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)
  27455 		}
  27456 	} else {
  27457 		uv_width = (width + int32(1)) >> int32(1)
  27458 		use_dsp = libc.BoolInt32(step == int32(3)) // use special function in this case
  27459 		// temporary storage for accumulated R/G/B values during conversion to U/V
  27460 		tmp_rgb = WebPSafeMalloc(tls, libc.Uint64FromInt32(int32(4)*uv_width), uint64(2))
  27461 		dst_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27462 		dst_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27463 		dst_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27464 		dst_a = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  27465 		rg = libc.UintptrFromInt32(0)
  27466 		if float64(dithering) > float64(0) {
  27467 			VP8InitRandom(tls, bp, dithering)
  27468 			rg = bp
  27469 			use_dsp = 0 // can't use dsp in this case
  27470 		}
  27471 		WebPInitConvertARGBToYUV(tls)
  27472 		InitGammaTables(tls)
  27473 		if tmp_rgb == libc.UintptrFromInt32(0) {
  27474 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  27475 		}
  27476 		// Downsample Y/U/V planes, two rows at a time
  27477 		y = 0
  27478 		for {
  27479 			if !(y < height>>libc.Int32FromInt32(1)) {
  27480 				break
  27481 			}
  27482 			rows_have_alpha = has_alpha
  27483 			if use_dsp != 0 {
  27484 				if is_rgb != 0 {
  27485 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27486 					(*(*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)
  27487 				} else {
  27488 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27489 					(*(*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)
  27490 				}
  27491 			} else {
  27492 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27493 				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)
  27494 			}
  27495 			dst_y = dst_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27496 			if has_alpha != 0 {
  27497 				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))
  27498 				dst_a = dst_a + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27499 			}
  27500 			// Collect averaged R/G/B(/A)
  27501 			if !(rows_have_alpha != 0) {
  27502 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, rgb_stride, tmp_rgb, width)
  27503 			} else {
  27504 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, rgb_stride, tmp_rgb, width)
  27505 			}
  27506 			// Convert to U/V
  27507 			if rg == libc.UintptrFromInt32(0) {
  27508 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27509 			} else {
  27510 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27511 			}
  27512 			dst_u = dst_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27513 			dst_v = dst_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27514 			r_ptr = r_ptr + uintptr(int32(2)*rgb_stride)
  27515 			b_ptr = b_ptr + uintptr(int32(2)*rgb_stride)
  27516 			g_ptr = g_ptr + uintptr(int32(2)*rgb_stride)
  27517 			if has_alpha != 0 {
  27518 				a_ptr = a_ptr + uintptr(int32(2)*rgb_stride)
  27519 			}
  27520 			goto _2
  27521 		_2:
  27522 			;
  27523 			y = y + 1
  27524 		}
  27525 		if height&int32(1) != 0 { // extra last row
  27526 			row_has_alpha = has_alpha
  27527 			if use_dsp != 0 {
  27528 				if r_ptr < b_ptr {
  27529 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGB24ToY})))(tls, r_ptr, dst_y, width)
  27530 				} else {
  27531 					(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertBGR24ToY})))(tls, b_ptr, dst_y, width)
  27532 				}
  27533 			} else {
  27534 				ConvertRowToY(tls, r_ptr, g_ptr, b_ptr, step, dst_y, width, rg)
  27535 			}
  27536 			if row_has_alpha != 0 {
  27537 				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))
  27538 			}
  27539 			// Collect averaged R/G/B(/A)
  27540 			if !(row_has_alpha != 0) {
  27541 				// Collect averaged R/G/B
  27542 				AccumulateRGB(tls, r_ptr, g_ptr, b_ptr, step, 0, tmp_rgb, width)
  27543 			} else {
  27544 				AccumulateRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, 0, tmp_rgb, width)
  27545 			}
  27546 			if rg == libc.UintptrFromInt32(0) {
  27547 				(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{WebPConvertRGBA32ToUV})))(tls, tmp_rgb, dst_u, dst_v, uv_width)
  27548 			} else {
  27549 				ConvertRowsToUV(tls, tmp_rgb, dst_u, dst_v, uv_width, rg)
  27550 			}
  27551 		}
  27552 		WebPSafeFree(tls, tmp_rgb)
  27553 	}
  27554 	return int32(1)
  27555 }
  27556 
  27557 //------------------------------------------------------------------------------
  27558 // call for ARGB->YUVA conversion
  27559 
  27560 func PictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32, use_iterative_conversion int32) (r1 int32) {
  27561 	var a, argb, b, g, r uintptr
  27562 	_, _, _, _, _ = a, argb, b, g, r
  27563 	if picture == libc.UintptrFromInt32(0) {
  27564 		return 0
  27565 	}
  27566 	if (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  27567 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27568 	} else {
  27569 		if colorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27570 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27571 		} else {
  27572 			argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27573 			a = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(0))
  27574 			r = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(1))
  27575 			g = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(2))
  27576 			b = argb + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(3))
  27577 			(*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace = int32(WEBP_YUV420)
  27578 			return ImportYUVAFromRGBA(tls, r, g, b, a, int32(4), int32(4)*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride, dithering, use_iterative_conversion, picture)
  27579 		}
  27580 	}
  27581 	return r1
  27582 }
  27583 
  27584 func WebPPictureARGBToYUVADithered(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1, dithering float32) (r int32) {
  27585 	return PictureARGBToYUVA(tls, picture, colorspace, dithering, 0)
  27586 }
  27587 
  27588 func WebPPictureARGBToYUVA(tls *libc.TLS, picture uintptr, colorspace WebPEncCSP1) (r int32) {
  27589 	return PictureARGBToYUVA(tls, picture, colorspace, libc.Float32FromFloat32(0), 0)
  27590 }
  27591 
  27592 func WebPPictureSharpARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27593 	return PictureARGBToYUVA(tls, picture, int32(WEBP_YUV420), libc.Float32FromFloat32(0), int32(1))
  27594 }
  27595 
  27596 // C documentation
  27597 //
  27598 //	// for backward compatibility
  27599 func WebPPictureSmartARGBToYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  27600 	return WebPPictureSharpARGBToYUVA(tls, picture)
  27601 }
  27602 
  27603 //------------------------------------------------------------------------------
  27604 // call for YUVA -> ARGB conversion
  27605 
  27606 func WebPPictureYUVAToARGB(tls *libc.TLS, picture uintptr) (r int32) {
  27607 	var argb_dst, cur_u, cur_v, cur_y, dst, src, top_u, top_v uintptr
  27608 	var argb_stride, height, width, x, y int32
  27609 	var upsample WebPUpsampleLinePairFunc
  27610 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = argb_dst, argb_stride, cur_u, cur_v, cur_y, dst, height, src, top_u, top_v, upsample, width, x, y
  27611 	if picture == libc.UintptrFromInt32(0) {
  27612 		return 0
  27613 	}
  27614 	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) {
  27615 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27616 	}
  27617 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 && (*WebPPicture)(unsafe.Pointer(picture)).Fa == libc.UintptrFromInt32(0) {
  27618 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  27619 	}
  27620 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_UV_MASK) != int32(WEBP_YUV420) {
  27621 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  27622 	}
  27623 	// Allocate a new argb buffer (discarding the previous one).
  27624 	if !(WebPPictureAllocARGB(tls, picture) != 0) {
  27625 		return 0
  27626 	}
  27627 	(*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb = int32(1)
  27628 	// Convert
  27629 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27630 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27631 	argb_stride = int32(4) * (*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride
  27632 	dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27633 	cur_u = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  27634 	cur_v = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  27635 	cur_y = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  27636 	upsample = WebPGetLinePairConverter(tls, libc.BoolInt32(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) > 0))
  27637 	// First row, with replicated top samples.
  27638 	(*(*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)
  27639 	cur_y = cur_y + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27640 	dst = dst + uintptr(argb_stride)
  27641 	// Center rows.
  27642 	y = int32(1)
  27643 	for {
  27644 		if !(y+int32(1) < height) {
  27645 			break
  27646 		}
  27647 		top_u = cur_u
  27648 		top_v = cur_v
  27649 		cur_u = cur_u + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27650 		cur_v = cur_v + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  27651 		(*(*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)
  27652 		cur_y = cur_y + uintptr(int32(2)*(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  27653 		dst = dst + uintptr(int32(2)*argb_stride)
  27654 		goto _1
  27655 	_1:
  27656 		;
  27657 		y = y + int32(2)
  27658 	}
  27659 	// Last row (if needed), with replicated bottom samples.
  27660 	if height > int32(1) && !(height&libc.Int32FromInt32(1) != 0) {
  27661 		(*(*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)
  27662 	}
  27663 	// Insert alpha values if needed, in replacement for the default 0xff ones.
  27664 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace&int32(WEBP_CSP_ALPHA_BIT) != 0 {
  27665 		y = 0
  27666 		for {
  27667 			if !(y < height) {
  27668 				break
  27669 			}
  27670 			argb_dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27671 			src = (*WebPPicture)(unsafe.Pointer(picture)).Fa + uintptr(y*(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  27672 			x = 0
  27673 			for {
  27674 				if !(x < width) {
  27675 					break
  27676 				}
  27677 				**(**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)
  27678 				goto _3
  27679 			_3:
  27680 				;
  27681 				x = x + 1
  27682 			}
  27683 			goto _2
  27684 		_2:
  27685 			;
  27686 			y = y + 1
  27687 		}
  27688 	}
  27689 	return int32(1)
  27690 }
  27691 
  27692 //------------------------------------------------------------------------------
  27693 // automatic import / conversion
  27694 
  27695 func Import(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32, step int32, swap_rb int32, import_alpha int32) (r int32) {
  27696 	var a_ptr, b_ptr, dst, dst1, g_ptr, r_ptr, v4 uintptr
  27697 	var do_copy, height, width, y, v1, v2, v3 int32
  27698 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a_ptr, b_ptr, do_copy, dst, dst1, g_ptr, height, r_ptr, width, y, v1, v2, v3, v4
  27699 	if swap_rb != 0 {
  27700 		v1 = int32(2)
  27701 	} else {
  27702 		v1 = 0
  27703 	}
  27704 	// swap_rb -> b,g,r,a , !swap_rb -> r,g,b,a
  27705 	r_ptr = rgb + uintptr(v1)
  27706 	g_ptr = rgb + uintptr(1)
  27707 	if swap_rb != 0 {
  27708 		v2 = 0
  27709 	} else {
  27710 		v2 = int32(2)
  27711 	}
  27712 	b_ptr = rgb + uintptr(v2)
  27713 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  27714 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  27715 	if import_alpha != 0 {
  27716 		v3 = int32(4)
  27717 	} else {
  27718 		v3 = int32(3)
  27719 	}
  27720 	if libc.Xabs(tls, rgb_stride) < v3*width {
  27721 		return 0
  27722 	}
  27723 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  27724 		if import_alpha != 0 {
  27725 			v4 = rgb + uintptr(3)
  27726 		} else {
  27727 			v4 = libc.UintptrFromInt32(0)
  27728 		}
  27729 		a_ptr = v4
  27730 		return ImportYUVAFromRGBA(tls, r_ptr, g_ptr, b_ptr, a_ptr, step, rgb_stride, libc.Float32FromFloat32(0), 0, picture)
  27731 	}
  27732 	if !(WebPPictureAlloc(tls, picture) != 0) {
  27733 		return 0
  27734 	}
  27735 	VP8LDspInit(tls)
  27736 	WebPInitAlphaProcessing(tls)
  27737 	if import_alpha != 0 {
  27738 		// dst[] byte order is {a,r,g,b} for big-endian, {b,g,r,a} for little endian
  27739 		dst = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27740 		do_copy = libc.BoolInt32(libc.Bool(libc.Int32FromInt32(3)-libc.Int32FromInt32(0) == int32(3)) && swap_rb != 0)
  27741 		if do_copy != 0 {
  27742 			y = 0
  27743 			for {
  27744 				if !(y < height) {
  27745 					break
  27746 				}
  27747 				libc.Xmemcpy(tls, dst, rgb, libc.Uint64FromInt32(width*int32(4)))
  27748 				rgb = rgb + uintptr(rgb_stride)
  27749 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27750 				goto _5
  27751 			_5:
  27752 				;
  27753 				y = y + 1
  27754 			}
  27755 		} else {
  27756 			y = 0
  27757 			for {
  27758 				if !(y < height) {
  27759 					break
  27760 				}
  27761 				// RGBA input order. Need to swap R and B.
  27762 				(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, rgb, width, dst)
  27763 				rgb = rgb + uintptr(rgb_stride)
  27764 				dst = dst + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27765 				goto _6
  27766 			_6:
  27767 				;
  27768 				y = y + 1
  27769 			}
  27770 		}
  27771 	} else {
  27772 		dst1 = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  27773 		y = 0
  27774 		for {
  27775 			if !(y < height) {
  27776 				break
  27777 			}
  27778 			(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPPackRGB})))(tls, r_ptr, g_ptr, b_ptr, width, step, dst1)
  27779 			r_ptr = r_ptr + uintptr(rgb_stride)
  27780 			g_ptr = g_ptr + uintptr(rgb_stride)
  27781 			b_ptr = b_ptr + uintptr(rgb_stride)
  27782 			dst1 = dst1 + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  27783 			goto _7
  27784 		_7:
  27785 			;
  27786 			y = y + 1
  27787 		}
  27788 	}
  27789 	return int32(1)
  27790 }
  27791 
  27792 // Public API
  27793 
  27794 func WebPPictureImportBGR(tls *libc.TLS, picture uintptr, bgr uintptr, bgr_stride int32) (r int32) {
  27795 	var v1 int32
  27796 	_ = v1
  27797 	if picture != libc.UintptrFromInt32(0) && bgr != libc.UintptrFromInt32(0) {
  27798 		v1 = Import(tls, picture, bgr, bgr_stride, int32(3), int32(1), 0)
  27799 	} else {
  27800 		v1 = 0
  27801 	}
  27802 	return v1
  27803 }
  27804 
  27805 func WebPPictureImportBGRA(tls *libc.TLS, picture uintptr, bgra uintptr, bgra_stride int32) (r int32) {
  27806 	var v1 int32
  27807 	_ = v1
  27808 	if picture != libc.UintptrFromInt32(0) && bgra != libc.UintptrFromInt32(0) {
  27809 		v1 = Import(tls, picture, bgra, bgra_stride, int32(4), int32(1), int32(1))
  27810 	} else {
  27811 		v1 = 0
  27812 	}
  27813 	return v1
  27814 }
  27815 
  27816 func WebPPictureImportBGRX(tls *libc.TLS, picture uintptr, bgrx uintptr, bgrx_stride int32) (r int32) {
  27817 	var v1 int32
  27818 	_ = v1
  27819 	if picture != libc.UintptrFromInt32(0) && bgrx != libc.UintptrFromInt32(0) {
  27820 		v1 = Import(tls, picture, bgrx, bgrx_stride, int32(4), int32(1), 0)
  27821 	} else {
  27822 		v1 = 0
  27823 	}
  27824 	return v1
  27825 }
  27826 
  27827 func WebPPictureImportRGB(tls *libc.TLS, picture uintptr, rgb uintptr, rgb_stride int32) (r int32) {
  27828 	var v1 int32
  27829 	_ = v1
  27830 	if picture != libc.UintptrFromInt32(0) && rgb != libc.UintptrFromInt32(0) {
  27831 		v1 = Import(tls, picture, rgb, rgb_stride, int32(3), 0, 0)
  27832 	} else {
  27833 		v1 = 0
  27834 	}
  27835 	return v1
  27836 }
  27837 
  27838 func WebPPictureImportRGBA(tls *libc.TLS, picture uintptr, rgba uintptr, rgba_stride int32) (r int32) {
  27839 	var v1 int32
  27840 	_ = v1
  27841 	if picture != libc.UintptrFromInt32(0) && rgba != libc.UintptrFromInt32(0) {
  27842 		v1 = Import(tls, picture, rgba, rgba_stride, int32(4), 0, int32(1))
  27843 	} else {
  27844 		v1 = 0
  27845 	}
  27846 	return v1
  27847 }
  27848 
  27849 func WebPPictureImportRGBX(tls *libc.TLS, picture uintptr, rgbx uintptr, rgbx_stride int32) (r int32) {
  27850 	var v1 int32
  27851 	_ = v1
  27852 	if picture != libc.UintptrFromInt32(0) && rgbx != libc.UintptrFromInt32(0) {
  27853 		v1 = Import(tls, picture, rgbx, rgbx_stride, int32(4), 0, 0)
  27854 	} else {
  27855 		v1 = 0
  27856 	}
  27857 	return v1
  27858 }
  27859 
  27860 const ARG_MAX = 131072
  27861 const BC_BASE_MAX = 99
  27862 const BC_DIM_MAX = 2048
  27863 const BC_SCALE_MAX = 99
  27864 const BC_STRING_MAX = 1000
  27865 const CHARCLASS_NAME_MAX = 14
  27866 const CHAR_BIT = 8
  27867 const CHAR_MAX = 255
  27868 const CHAR_MIN = 0
  27869 const COLL_WEIGHTS_MAX = 2
  27870 const DELAYTIMER_MAX = 0x7fffffff
  27871 const EXPR_NEST_MAX = 32
  27872 const FILESIZEBITS = 64
  27873 const HOST_NAME_MAX = 255
  27874 const INT_MAX = 2147483647
  27875 const IOV_MAX = 1024
  27876 const LINE_MAX = 4096
  27877 const LLONG_MAX = 0x7fffffffffffffff
  27878 const LOGIN_NAME_MAX = 256
  27879 const LONG_BIT = 64
  27880 const LONG_MAX = "__LONG_MAX"
  27881 const LOSSLESS_DEFAULT_QUALITY = 70
  27882 const MB_LEN_MAX = 4
  27883 const MQ_PRIO_MAX = 32768
  27884 const NAME_MAX = 255
  27885 const NGROUPS_MAX = 32
  27886 const NL_ARGMAX = 9
  27887 const NL_LANGMAX = 32
  27888 const NL_MSGMAX = 32767
  27889 const NL_NMAX = 16
  27890 const NL_SETMAX = 255
  27891 const NL_TEXTMAX = 2048
  27892 const NZERO = 20
  27893 const PATH_MAX = 4096
  27894 const PIPE_BUF = 4096
  27895 const PTHREAD_DESTRUCTOR_ITERATIONS = 4
  27896 const PTHREAD_KEYS_MAX = 128
  27897 const PTHREAD_STACK_MIN = 2048
  27898 const RE_DUP_MAX = 255
  27899 const SCHAR_MAX = 127
  27900 const SEM_NSEMS_MAX = 256
  27901 const SEM_VALUE_MAX = 0x7fffffff
  27902 const SHRT_MAX = 0x7fff
  27903 const SSIZE_MAX = "LONG_MAX"
  27904 const SYMLOOP_MAX = 40
  27905 const TTY_NAME_MAX = 32
  27906 const TZNAME_MAX = 6
  27907 const UCHAR_MAX = 255
  27908 const UINT_MAX = 0xffffffff
  27909 const USHRT_MAX = 0xffff
  27910 const WORD_BIT = 32
  27911 const _POSIX2_BC_BASE_MAX = 99
  27912 const _POSIX2_BC_DIM_MAX = 2048
  27913 const _POSIX2_BC_SCALE_MAX = 99
  27914 const _POSIX2_BC_STRING_MAX = 1000
  27915 const _POSIX2_CHARCLASS_NAME_MAX = 14
  27916 const _POSIX2_COLL_WEIGHTS_MAX = 2
  27917 const _POSIX2_EXPR_NEST_MAX = 32
  27918 const _POSIX2_LINE_MAX = 2048
  27919 const _POSIX2_RE_DUP_MAX = 255
  27920 const _POSIX_AIO_LISTIO_MAX = 2
  27921 const _POSIX_AIO_MAX = 1
  27922 const _POSIX_ARG_MAX = 4096
  27923 const _POSIX_CHILD_MAX = 25
  27924 const _POSIX_CLOCKRES_MIN = 20000000
  27925 const _POSIX_DELAYTIMER_MAX = 32
  27926 const _POSIX_HOST_NAME_MAX = 255
  27927 const _POSIX_LINK_MAX = 8
  27928 const _POSIX_LOGIN_NAME_MAX = 9
  27929 const _POSIX_MAX_CANON = 255
  27930 const _POSIX_MAX_INPUT = 255
  27931 const _POSIX_MQ_OPEN_MAX = 8
  27932 const _POSIX_MQ_PRIO_MAX = 32
  27933 const _POSIX_NAME_MAX = 14
  27934 const _POSIX_NGROUPS_MAX = 8
  27935 const _POSIX_OPEN_MAX = 20
  27936 const _POSIX_PATH_MAX = 256
  27937 const _POSIX_PIPE_BUF = 512
  27938 const _POSIX_RE_DUP_MAX = 255
  27939 const _POSIX_RTSIG_MAX = 8
  27940 const _POSIX_SEM_NSEMS_MAX = 256
  27941 const _POSIX_SEM_VALUE_MAX = 32767
  27942 const _POSIX_SIGQUEUE_MAX = 32
  27943 const _POSIX_SSIZE_MAX = 32767
  27944 const _POSIX_SS_REPL_MAX = 4
  27945 const _POSIX_STREAM_MAX = 8
  27946 const _POSIX_SYMLINK_MAX = 255
  27947 const _POSIX_SYMLOOP_MAX = 8
  27948 const _POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4
  27949 const _POSIX_THREAD_KEYS_MAX = 128
  27950 const _POSIX_THREAD_THREADS_MAX = 64
  27951 const _POSIX_TIMER_MAX = 32
  27952 const _POSIX_TRACE_EVENT_NAME_MAX = 30
  27953 const _POSIX_TRACE_NAME_MAX = 8
  27954 const _POSIX_TRACE_SYS_MAX = 8
  27955 const _POSIX_TRACE_USER_EVENT_MAX = 32
  27956 const _POSIX_TTY_NAME_MAX = 9
  27957 const _POSIX_TZNAME_MAX = 6
  27958 const _XOPEN_IOV_MAX = 16
  27959 const _XOPEN_NAME_MAX = 255
  27960 const _XOPEN_PATH_MAX = 1024
  27961 
  27962 //------------------------------------------------------------------------------
  27963 
  27964 // Copyright 2012 Google Inc. All Rights Reserved.
  27965 //
  27966 // Use of this source code is governed by a BSD-style license
  27967 // that can be found in the COPYING file in the root of the source
  27968 // tree. An additional intellectual property rights grant can be found
  27969 // in the file PATENTS. All contributing project authors may
  27970 // be found in the AUTHORS file in the root of the source tree.
  27971 // -----------------------------------------------------------------------------
  27972 //
  27973 // Misc. common utility functions
  27974 //
  27975 // Authors: Skal (pascal.massimino@gmail.com)
  27976 //          Urvang (urvang@google.com)
  27977 
  27978 // Copyright 2011 Google Inc. All Rights Reserved.
  27979 //
  27980 // Use of this source code is governed by a BSD-style license
  27981 // that can be found in the COPYING file in the root of the source
  27982 // tree. An additional intellectual property rights grant can be found
  27983 // in the file PATENTS. All contributing project authors may
  27984 // be found in the AUTHORS file in the root of the source tree.
  27985 // -----------------------------------------------------------------------------
  27986 //
  27987 //   WebP encoder: main interface
  27988 //
  27989 // Author: Skal (pascal.massimino@gmail.com)
  27990 
  27991 // Copyright 2010 Google Inc. All Rights Reserved.
  27992 //
  27993 // Use of this source code is governed by a BSD-style license
  27994 // that can be found in the COPYING file in the root of the source
  27995 // tree. An additional intellectual property rights grant can be found
  27996 // in the file PATENTS. All contributing project authors may
  27997 // be found in the AUTHORS file in the root of the source tree.
  27998 // -----------------------------------------------------------------------------
  27999 //
  28000 //  Common types + memory wrappers
  28001 //
  28002 // Author: Skal (pascal.massimino@gmail.com)
  28003 
  28004 //------------------------------------------------------------------------------
  28005 // WebPPicture
  28006 //------------------------------------------------------------------------------
  28007 
  28008 func DummyWriter(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  28009 	// The following are to prevent 'unused variable' error message.
  28010 	_ = data
  28011 	_ = data_size
  28012 	_ = picture
  28013 	return int32(1)
  28014 }
  28015 
  28016 func WebPPictureInitInternal(tls *libc.TLS, picture uintptr, version int32) (r int32) {
  28017 	if version>>int32(8) != libc.Int32FromInt32(WEBP_ENCODER_ABI_VERSION)>>libc.Int32FromInt32(8) {
  28018 		return 0 // caller/system version mismatch!
  28019 	}
  28020 	if picture != libc.UintptrFromInt32(0) {
  28021 		libc.Xmemset(tls, picture, 0, uint64(256))
  28022 		(*WebPPicture)(unsafe.Pointer(picture)).Fwriter = __ccgo_fp(DummyWriter)
  28023 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_OK))
  28024 	}
  28025 	return int32(1)
  28026 }
  28027 
  28028 //------------------------------------------------------------------------------
  28029 
  28030 func WebPValidatePicture(tls *libc.TLS, picture uintptr) (r int32) {
  28031 	if picture == libc.UintptrFromInt32(0) {
  28032 		return 0
  28033 	}
  28034 	if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth <= 0 || (*WebPPicture)(unsafe.Pointer(picture)).Fheight <= 0 {
  28035 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28036 	}
  28037 	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) {
  28038 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28039 	}
  28040 	if (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420) && (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace != int32(WEBP_YUV420A) {
  28041 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  28042 	}
  28043 	return int32(1)
  28044 }
  28045 
  28046 func WebPPictureResetBufferARGB(tls *libc.TLS, picture uintptr) {
  28047 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = libc.UintptrFromInt32(0)
  28048 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = libc.UintptrFromInt32(0)
  28049 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = 0
  28050 }
  28051 
  28052 func WebPPictureResetBufferYUVA(tls *libc.TLS, picture uintptr) {
  28053 	var v1, v2, v3 uintptr
  28054 	var v4 int32
  28055 	_, _, _, _ = v1, v2, v3, v4
  28056 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = libc.UintptrFromInt32(0)
  28057 	v3 = libc.UintptrFromInt32(0)
  28058 	(*WebPPicture)(unsafe.Pointer(picture)).Fa = v3
  28059 	v2 = v3
  28060 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = v2
  28061 	v1 = v2
  28062 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = v1
  28063 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = v1
  28064 	v4 = libc.Int32FromInt32(0)
  28065 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = v4
  28066 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = v4
  28067 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = 0
  28068 }
  28069 
  28070 func WebPPictureResetBuffers(tls *libc.TLS, picture uintptr) {
  28071 	WebPPictureResetBufferARGB(tls, picture)
  28072 	WebPPictureResetBufferYUVA(tls, picture)
  28073 }
  28074 
  28075 func WebPPictureAllocARGB(tls *libc.TLS, picture uintptr) (r int32) {
  28076 	var argb_size uint64_t
  28077 	var height, width int32
  28078 	var memory uintptr
  28079 	_, _, _, _ = argb_size, height, memory, width
  28080 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28081 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28082 	argb_size = libc.Uint64FromInt32(width) * libc.Uint64FromInt32(height)
  28083 	if !(WebPValidatePicture(tls, picture) != 0) {
  28084 		return 0
  28085 	}
  28086 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  28087 	WebPPictureResetBufferARGB(tls, picture)
  28088 	// allocate a new buffer.
  28089 	memory = WebPSafeMalloc(tls, argb_size+uint64(WEBP_ALIGN_CST), uint64(4))
  28090 	if memory == libc.UintptrFromInt32(0) {
  28091 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28092 	}
  28093 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ = memory
  28094 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb = uintptr((uint64(memory) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  28095 	(*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride = width
  28096 	return int32(1)
  28097 }
  28098 
  28099 func WebPPictureAllocYUVA(tls *libc.TLS, picture uintptr) (r int32) {
  28100 	var a_size, total_size, uv_size, y_size uint64_t
  28101 	var a_stride, a_width, has_alpha, height, uv_height, uv_stride, uv_width, width, y_stride, v1 int32
  28102 	var mem uintptr
  28103 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  28104 	has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  28105 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28106 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28107 	y_stride = width
  28108 	uv_width = int32((int64(width) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  28109 	uv_height = int32((int64(height) + libc.Int64FromInt32(1)) >> libc.Int32FromInt32(1))
  28110 	uv_stride = uv_width
  28111 	if !(WebPValidatePicture(tls, picture) != 0) {
  28112 		return 0
  28113 	}
  28114 	WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  28115 	WebPPictureResetBufferYUVA(tls, picture)
  28116 	// alpha
  28117 	if has_alpha != 0 {
  28118 		v1 = width
  28119 	} else {
  28120 		v1 = 0
  28121 	}
  28122 	a_width = v1
  28123 	a_stride = a_width
  28124 	y_size = libc.Uint64FromInt32(y_stride) * libc.Uint64FromInt32(height)
  28125 	uv_size = libc.Uint64FromInt32(uv_stride) * libc.Uint64FromInt32(uv_height)
  28126 	a_size = libc.Uint64FromInt32(a_stride) * libc.Uint64FromInt32(height)
  28127 	total_size = y_size + a_size + uint64(2)*uv_size
  28128 	// Security and validation checks
  28129 	if width <= 0 || height <= 0 || uv_width <= 0 || uv_height <= 0 { // u/v param error
  28130 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28131 	}
  28132 	// allocate a new buffer.
  28133 	mem = WebPSafeMalloc(tls, total_size, uint64(1))
  28134 	if mem == libc.UintptrFromInt32(0) {
  28135 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28136 	}
  28137 	// From now on, we're in the clear, we can no longer fail...
  28138 	(*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ = mem
  28139 	(*WebPPicture)(unsafe.Pointer(picture)).Fy_stride = y_stride
  28140 	(*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride = uv_stride
  28141 	(*WebPPicture)(unsafe.Pointer(picture)).Fa_stride = a_stride
  28142 	// TODO(skal): we could align the y/u/v planes and adjust stride.
  28143 	(*WebPPicture)(unsafe.Pointer(picture)).Fy = mem
  28144 	mem = mem + uintptr(y_size)
  28145 	(*WebPPicture)(unsafe.Pointer(picture)).Fu = mem
  28146 	mem = mem + uintptr(uv_size)
  28147 	(*WebPPicture)(unsafe.Pointer(picture)).Fv = mem
  28148 	mem = mem + uintptr(uv_size)
  28149 	if a_size > uint64(0) {
  28150 		(*WebPPicture)(unsafe.Pointer(picture)).Fa = mem
  28151 		mem = mem + uintptr(a_size)
  28152 	}
  28153 	_ = mem // makes the static analyzer happy
  28154 	return int32(1)
  28155 }
  28156 
  28157 func WebPPictureAlloc(tls *libc.TLS, picture uintptr) (r int32) {
  28158 	if picture != libc.UintptrFromInt32(0) {
  28159 		WebPPictureFree(tls, picture) // erase previous buffer
  28160 		if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28161 			return WebPPictureAllocYUVA(tls, picture)
  28162 		} else {
  28163 			return WebPPictureAllocARGB(tls, picture)
  28164 		}
  28165 	}
  28166 	return int32(1)
  28167 }
  28168 
  28169 func WebPPictureFree(tls *libc.TLS, picture uintptr) {
  28170 	if picture != libc.UintptrFromInt32(0) {
  28171 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_)
  28172 		WebPSafeFree(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_)
  28173 		WebPPictureResetBuffers(tls, picture)
  28174 	}
  28175 }
  28176 
  28177 //------------------------------------------------------------------------------
  28178 // WebPMemoryWriter: Write-to-memory
  28179 
  28180 func WebPMemoryWriterInit(tls *libc.TLS, writer uintptr) {
  28181 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem = libc.UintptrFromInt32(0)
  28182 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fsize = uint64(0)
  28183 	(*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmax_size = uint64(0)
  28184 }
  28185 
  28186 func WebPMemoryWrite(tls *libc.TLS, data uintptr, data_size size_t, picture uintptr) (r int32) {
  28187 	var new_mem, w uintptr
  28188 	var next_max_size, next_size uint64_t
  28189 	_, _, _, _ = new_mem, next_max_size, next_size, w
  28190 	w = (*WebPPicture)(unsafe.Pointer(picture)).Fcustom_ptr
  28191 	if w == libc.UintptrFromInt32(0) {
  28192 		return int32(1)
  28193 	}
  28194 	next_size = (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize + data_size
  28195 	if next_size > (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size {
  28196 		next_max_size = uint64(2) * (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size
  28197 		if next_max_size < next_size {
  28198 			next_max_size = next_size
  28199 		}
  28200 		if next_max_size < uint64(8192) {
  28201 			next_max_size = uint64(8192)
  28202 		}
  28203 		new_mem = WebPSafeMalloc(tls, next_max_size, uint64(1))
  28204 		if new_mem == libc.UintptrFromInt32(0) {
  28205 			return 0
  28206 		}
  28207 		if (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize > uint64(0) {
  28208 			libc.Xmemcpy(tls, new_mem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize)
  28209 		}
  28210 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem)
  28211 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem = new_mem
  28212 		// down-cast is ok, thanks to WebPSafeMalloc
  28213 		(*WebPMemoryWriter)(unsafe.Pointer(w)).Fmax_size = next_max_size
  28214 	}
  28215 	if data_size > uint64(0) {
  28216 		libc.Xmemcpy(tls, (*WebPMemoryWriter)(unsafe.Pointer(w)).Fmem+uintptr((*WebPMemoryWriter)(unsafe.Pointer(w)).Fsize), data, data_size)
  28217 		**(**size_t)(__ccgo_up(w + 8)) += data_size
  28218 	}
  28219 	return int32(1)
  28220 }
  28221 
  28222 func WebPMemoryWriterClear(tls *libc.TLS, writer uintptr) {
  28223 	if writer != libc.UintptrFromInt32(0) {
  28224 		WebPSafeFree(tls, (*WebPMemoryWriter)(unsafe.Pointer(writer)).Fmem)
  28225 		WebPMemoryWriterInit(tls, writer)
  28226 	}
  28227 }
  28228 
  28229 //------------------------------------------------------------------------------
  28230 // Simplest high-level calls:
  28231 
  28232 type Importer = uintptr
  28233 
  28234 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) {
  28235 	bp := tls.Alloc(416)
  28236 	defer tls.Free(416)
  28237 	var ok, v1, v3 int32
  28238 	var v5 bool
  28239 	var _ /* config at bp+256 */ WebPConfig
  28240 	var _ /* pic at bp+0 */ WebPPicture
  28241 	var _ /* wrt at bp+376 */ WebPMemoryWriter
  28242 	_, _, _, _ = ok, v1, v3, v5
  28243 	if output == libc.UintptrFromInt32(0) {
  28244 		return uint64(0)
  28245 	}
  28246 	v1 = WebPConfigInitInternal(tls, bp+256, int32(WEBP_PRESET_DEFAULT), quality_factor, int32(WEBP_ENCODER_ABI_VERSION))
  28247 	goto _2
  28248 _2:
  28249 	;
  28250 	if v5 = !(v1 != 0); !v5 {
  28251 		v3 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28252 		goto _4
  28253 	_4:
  28254 	}
  28255 	if v5 || !(v3 != 0) {
  28256 		return uint64(0) // shouldn't happen, except if system installation is broken
  28257 	}
  28258 	(**(**WebPConfig)(__ccgo_up(bp + 256))).Flossless = libc.BoolInt32(!!(lossless != 0))
  28259 	(**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb = libc.BoolInt32(!!(lossless != 0))
  28260 	(**(**WebPPicture)(__ccgo_up(bp))).Fwidth = width
  28261 	(**(**WebPPicture)(__ccgo_up(bp))).Fheight = height
  28262 	(**(**WebPPicture)(__ccgo_up(bp))).Fwriter = __ccgo_fp(WebPMemoryWrite)
  28263 	(**(**WebPPicture)(__ccgo_up(bp))).Fcustom_ptr = bp + 376
  28264 	WebPMemoryWriterInit(tls, bp+376)
  28265 	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)
  28266 	WebPPictureFree(tls, bp)
  28267 	if !(ok != 0) {
  28268 		WebPMemoryWriterClear(tls, bp+376)
  28269 		**(**uintptr)(__ccgo_up(output)) = libc.UintptrFromInt32(0)
  28270 		return uint64(0)
  28271 	}
  28272 	**(**uintptr)(__ccgo_up(output)) = (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fmem
  28273 	return (**(**WebPMemoryWriter)(__ccgo_up(bp + 376))).Fsize
  28274 }
  28275 
  28276 func WebPEncodeRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28277 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), q, 0, out)
  28278 }
  28279 
  28280 func WebPEncodeRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28281 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), q, 0, out)
  28282 }
  28283 
  28284 func WebPEncodeBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28285 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), q, 0, out)
  28286 }
  28287 
  28288 func WebPEncodeBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, q float32, out uintptr) (r size_t) {
  28289 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), q, 0, out)
  28290 }
  28291 
  28292 func WebPEncodeLosslessRGB(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28293 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGB), float32(70), int32(1), out)
  28294 }
  28295 
  28296 func WebPEncodeLosslessRGBA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28297 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportRGBA), float32(70), int32(1), out)
  28298 }
  28299 
  28300 func WebPEncodeLosslessBGR(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28301 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGR), float32(70), int32(1), out)
  28302 }
  28303 
  28304 func WebPEncodeLosslessBGRA(tls *libc.TLS, in uintptr, w int32, h int32, bps int32, out uintptr) (r size_t) {
  28305 	return Encode(tls, in, w, h, bps, __ccgo_fp(WebPPictureImportBGRA), float32(70), int32(1), out)
  28306 }
  28307 
  28308 //------------------------------------------------------------------------------
  28309 
  28310 // Copyright 2012 Google Inc. All Rights Reserved.
  28311 //
  28312 // Use of this source code is governed by a BSD-style license
  28313 // that can be found in the COPYING file in the root of the source
  28314 // tree. An additional intellectual property rights grant can be found
  28315 // in the file PATENTS. All contributing project authors may
  28316 // be found in the AUTHORS file in the root of the source tree.
  28317 // -----------------------------------------------------------------------------
  28318 //
  28319 // Misc. common utility functions
  28320 //
  28321 // Authors: Skal (pascal.massimino@gmail.com)
  28322 //          Urvang (urvang@google.com)
  28323 
  28324 type AccumulateFunc = uintptr
  28325 
  28326 //------------------------------------------------------------------------------
  28327 // local-min distortion
  28328 //
  28329 // For every pixel in the *reference* picture, we search for the local best
  28330 // match in the compressed image. This is not a symmetrical measure.
  28331 
  28332 func AccumulateLSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28333 	var best_sse, diff, sse, total_sse, value float64
  28334 	var i, j, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6 int32
  28335 	var s uintptr
  28336 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_sse, diff, i, j, s, sse, total_sse, value, x, x_0, x_1, y, y_0, y_1, v2, v3, v5, v6
  28337 	total_sse = float64(0)
  28338 	y = 0
  28339 	for {
  28340 		if !(y < h) {
  28341 			break
  28342 		}
  28343 		if y-int32(2) < 0 {
  28344 			v2 = 0
  28345 		} else {
  28346 			v2 = y - int32(2)
  28347 		}
  28348 		y_0 = v2
  28349 		if y+int32(2)+int32(1) >= h {
  28350 			v3 = h
  28351 		} else {
  28352 			v3 = y + int32(2) + int32(1)
  28353 		}
  28354 		y_1 = v3
  28355 		x = 0
  28356 		for {
  28357 			if !(x < w) {
  28358 				break
  28359 			}
  28360 			if x-int32(2) < 0 {
  28361 				v5 = 0
  28362 			} else {
  28363 				v5 = x - int32(2)
  28364 			}
  28365 			x_0 = v5
  28366 			if x+int32(2)+int32(1) >= w {
  28367 				v6 = w
  28368 			} else {
  28369 				v6 = x + int32(2) + int32(1)
  28370 			}
  28371 			x_1 = v6
  28372 			best_sse = float64(libc.Float64FromFloat64(255) * libc.Float64FromFloat64(255))
  28373 			value = float64(**(**uint8_t)(__ccgo_up(ref + uintptr(y*ref_stride+x))))
  28374 			j = y_0
  28375 			for {
  28376 				if !(j < y_1) {
  28377 					break
  28378 				}
  28379 				s = src + uintptr(j*src_stride)
  28380 				i = x_0
  28381 				for {
  28382 					if !(i < x_1) {
  28383 						break
  28384 					}
  28385 					diff = float64(**(**uint8_t)(__ccgo_up(s + uintptr(i)))) - value
  28386 					sse = float64(diff * diff)
  28387 					if sse < best_sse {
  28388 						best_sse = sse
  28389 					}
  28390 					goto _8
  28391 				_8:
  28392 					;
  28393 					i = i + 1
  28394 				}
  28395 				goto _7
  28396 			_7:
  28397 				;
  28398 				j = j + 1
  28399 			}
  28400 			total_sse = total_sse + best_sse
  28401 			goto _4
  28402 		_4:
  28403 			;
  28404 			x = x + 1
  28405 		}
  28406 		goto _1
  28407 	_1:
  28408 		;
  28409 		y = y + 1
  28410 	}
  28411 	return total_sse
  28412 }
  28413 
  28414 func AccumulateSSE(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28415 	var total_sse float64
  28416 	var y int32
  28417 	_, _ = total_sse, y
  28418 	total_sse = float64(0)
  28419 	y = 0
  28420 	for {
  28421 		if !(y < h) {
  28422 			break
  28423 		}
  28424 		total_sse = total_sse + float64((*(*func(*libc.TLS, uintptr, uintptr, int32) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8AccumulateSSE})))(tls, src, ref, w))
  28425 		src = src + uintptr(src_stride)
  28426 		ref = ref + uintptr(ref_stride)
  28427 		goto _1
  28428 	_1:
  28429 		;
  28430 		y = y + 1
  28431 	}
  28432 	return total_sse
  28433 }
  28434 
  28435 //------------------------------------------------------------------------------
  28436 
  28437 func AccumulateSSIM(tls *libc.TLS, src uintptr, src_stride int32, ref uintptr, ref_stride int32, w int32, h int32) (r float64) {
  28438 	var h0, h1, off1, off2, w0, w1, x, y, v1, v2 int32
  28439 	var sum float64
  28440 	_, _, _, _, _, _, _, _, _, _, _ = h0, h1, off1, off2, sum, w0, w1, x, y, v1, v2
  28441 	if w < int32(VP8_SSIM_KERNEL) {
  28442 		v1 = w
  28443 	} else {
  28444 		v1 = int32(VP8_SSIM_KERNEL)
  28445 	}
  28446 	w0 = v1
  28447 	w1 = w - int32(VP8_SSIM_KERNEL) - int32(1)
  28448 	if h < int32(VP8_SSIM_KERNEL) {
  28449 		v2 = h
  28450 	} else {
  28451 		v2 = int32(VP8_SSIM_KERNEL)
  28452 	}
  28453 	h0 = v2
  28454 	h1 = h - int32(VP8_SSIM_KERNEL) - int32(1)
  28455 	sum = float64(0)
  28456 	y = 0
  28457 	for {
  28458 		if !(y < h0) {
  28459 			break
  28460 		}
  28461 		x = 0
  28462 		for {
  28463 			if !(x < w) {
  28464 				break
  28465 			}
  28466 			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)
  28467 			goto _4
  28468 		_4:
  28469 			;
  28470 			x = x + 1
  28471 		}
  28472 		goto _3
  28473 	_3:
  28474 		;
  28475 		y = y + 1
  28476 	}
  28477 	for {
  28478 		if !(y < h1) {
  28479 			break
  28480 		}
  28481 		x = 0
  28482 		for {
  28483 			if !(x < w0) {
  28484 				break
  28485 			}
  28486 			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)
  28487 			goto _6
  28488 		_6:
  28489 			;
  28490 			x = x + 1
  28491 		}
  28492 		for {
  28493 			if !(x < w1) {
  28494 				break
  28495 			}
  28496 			off1 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*src_stride
  28497 			off2 = x - int32(VP8_SSIM_KERNEL) + (y-int32(VP8_SSIM_KERNEL))*ref_stride
  28498 			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)
  28499 			goto _7
  28500 		_7:
  28501 			;
  28502 			x = x + 1
  28503 		}
  28504 		for {
  28505 			if !(x < w) {
  28506 				break
  28507 			}
  28508 			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)
  28509 			goto _8
  28510 		_8:
  28511 			;
  28512 			x = x + 1
  28513 		}
  28514 		goto _5
  28515 	_5:
  28516 		;
  28517 		y = y + 1
  28518 	}
  28519 	for {
  28520 		if !(y < h) {
  28521 			break
  28522 		}
  28523 		x = 0
  28524 		for {
  28525 			if !(x < w) {
  28526 				break
  28527 			}
  28528 			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)
  28529 			goto _10
  28530 		_10:
  28531 			;
  28532 			x = x + 1
  28533 		}
  28534 		goto _9
  28535 	_9:
  28536 		;
  28537 		y = y + 1
  28538 	}
  28539 	return sum
  28540 }
  28541 
  28542 //------------------------------------------------------------------------------
  28543 // Distortion
  28544 
  28545 // C documentation
  28546 //
  28547 //	// Max value returned in case of exact similarity.
  28548 var kMinDistortion_dB = float64(99)
  28549 
  28550 func GetPSNR1(tls *libc.TLS, v float64, size float64) (r float64) {
  28551 	var v1 float64
  28552 	_ = v1
  28553 	if v > float64(0) && size > float64(0) {
  28554 		v1 = float64(-libc.Float64FromFloat64(4.3429448) * libc.Xlog(tls, v/float64(float64(size*libc.Float64FromInt32(255))*float64(255))))
  28555 	} else {
  28556 		v1 = kMinDistortion_dB
  28557 	}
  28558 	return v1
  28559 }
  28560 
  28561 func GetLogSSIM(tls *libc.TLS, v float64, size float64) (r float64) {
  28562 	var v1 float64
  28563 	_ = v1
  28564 	if size > float64(0) {
  28565 		v1 = v / size
  28566 	} else {
  28567 		v1 = float64(1)
  28568 	}
  28569 	v = v1
  28570 	if v < float64(1) {
  28571 		v1 = float64(-libc.Float64FromFloat64(10) * libc.Xlog10(tls, float64(1)-v))
  28572 	} else {
  28573 		v1 = kMinDistortion_dB
  28574 	}
  28575 	return v1
  28576 }
  28577 
  28578 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) {
  28579 	var allocated, tmp1, tmp2, v1, v2 uintptr
  28580 	var metric AccumulateFunc
  28581 	var x, y int32
  28582 	var v5 float32
  28583 	_, _, _, _, _, _, _, _, _ = allocated, metric, tmp1, tmp2, x, y, v1, v2, v5
  28584 	allocated = libc.UintptrFromInt32(0)
  28585 	if type1 == 0 {
  28586 		v1 = __ccgo_fp(AccumulateSSE)
  28587 	} else {
  28588 		if type1 == int32(1) {
  28589 			v2 = __ccgo_fp(AccumulateSSIM)
  28590 		} else {
  28591 			v2 = __ccgo_fp(AccumulateLSIM)
  28592 		}
  28593 		v1 = v2
  28594 	}
  28595 	metric = v1
  28596 	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) {
  28597 		return 0
  28598 	}
  28599 	VP8SSIMDspInit(tls)
  28600 	if x_step != uint64(1) {
  28601 		allocated = WebPSafeMalloc(tls, uint64(uint64(2)*libc.Uint64FromInt32(width)*libc.Uint64FromInt32(height)), uint64(1))
  28602 		if allocated == libc.UintptrFromInt32(0) {
  28603 			return 0
  28604 		}
  28605 		tmp1 = allocated
  28606 		tmp2 = tmp1 + uintptr(libc.Uint64FromInt32(width)*libc.Uint64FromInt32(height))
  28607 		y = 0
  28608 		for {
  28609 			if !(y < height) {
  28610 				break
  28611 			}
  28612 			x = 0
  28613 			for {
  28614 				if !(x < width) {
  28615 					break
  28616 				}
  28617 				**(**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)))
  28618 				**(**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)))
  28619 				goto _4
  28620 			_4:
  28621 				;
  28622 				x = x + 1
  28623 			}
  28624 			goto _3
  28625 		_3:
  28626 			;
  28627 			y = y + 1
  28628 		}
  28629 		src = tmp1
  28630 		ref = tmp2
  28631 	}
  28632 	**(**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))
  28633 	WebPSafeFree(tls, allocated)
  28634 	if type1 == int32(1) {
  28635 		v5 = float32(GetLogSSIM(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28636 	} else {
  28637 		v5 = float32(GetPSNR1(tls, float64(**(**float32)(__ccgo_up(distortion))), float64(float64(width)*float64(height))))
  28638 	}
  28639 	**(**float32)(__ccgo_up(result)) = v5
  28640 	return int32(1)
  28641 }
  28642 
  28643 func WebPPictureDistortion(tls *libc.TLS, src uintptr, ref uintptr, type1 int32, results uintptr) (r int32) {
  28644 	bp := tls.Alloc(528)
  28645 	defer tls.Free(528)
  28646 	var c, h, offset, ok, w, v1, v3 int32
  28647 	var stride0, stride1 size_t
  28648 	var total_distortion, total_size float64
  28649 	var v5 bool
  28650 	var v7 float32
  28651 	var _ /* distortion at bp+512 */ float32
  28652 	var _ /* p0 at bp+0 */ WebPPicture
  28653 	var _ /* p1 at bp+256 */ WebPPicture
  28654 	_, _, _, _, _, _, _, _, _, _, _, _, _ = c, h, offset, ok, stride0, stride1, total_distortion, total_size, w, v1, v3, v5, v7
  28655 	ok = 0
  28656 	total_size = float64(0)
  28657 	total_distortion = float64(0)
  28658 	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) {
  28659 		return 0
  28660 	}
  28661 	VP8SSIMDspInit(tls)
  28662 	v1 = WebPPictureInitInternal(tls, bp, int32(WEBP_ENCODER_ABI_VERSION))
  28663 	goto _2
  28664 _2:
  28665 	;
  28666 	if v5 = !(v1 != 0); !v5 {
  28667 		v3 = WebPPictureInitInternal(tls, bp+256, int32(WEBP_ENCODER_ABI_VERSION))
  28668 		goto _4
  28669 	_4:
  28670 	}
  28671 	if v5 || !(v3 != 0) {
  28672 		return 0
  28673 	}
  28674 	w = (*WebPPicture)(unsafe.Pointer(src)).Fwidth
  28675 	h = (*WebPPicture)(unsafe.Pointer(src)).Fheight
  28676 	if !(WebPPictureView(tls, src, 0, 0, w, h, bp) != 0) {
  28677 		goto Error
  28678 	}
  28679 	if !(WebPPictureView(tls, ref, 0, 0, w, h, bp+256) != 0) {
  28680 		goto Error
  28681 	}
  28682 	// We always measure distortion in ARGB space.
  28683 	if (**(**WebPPicture)(__ccgo_up(bp))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp) != 0) {
  28684 		goto Error
  28685 	}
  28686 	if (**(**WebPPicture)(__ccgo_up(bp + 256))).Fuse_argb == 0 && !(WebPPictureYUVAToARGB(tls, bp+256) != 0) {
  28687 		goto Error
  28688 	}
  28689 	c = 0
  28690 	for {
  28691 		if !(c < int32(4)) {
  28692 			break
  28693 		}
  28694 		stride0 = uint64(4) * libc.Uint64FromInt32((**(**WebPPicture)(__ccgo_up(bp))).Fargb_stride)
  28695 		stride1 = uint64(4) * libc.Uint64FromInt32((**(**WebPPicture)(__ccgo_up(bp + 256))).Fargb_stride)
  28696 		// results are reported as BGRA
  28697 		offset = c ^ 0
  28698 		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) {
  28699 			goto Error
  28700 		}
  28701 		total_distortion = total_distortion + float64(**(**float32)(__ccgo_up(bp + 512)))
  28702 		total_size = total_size + float64(w*h)
  28703 		goto _6
  28704 	_6:
  28705 		;
  28706 		c = c + 1
  28707 	}
  28708 	if type1 == int32(1) {
  28709 		v7 = float32(GetLogSSIM(tls, total_distortion, total_size))
  28710 	} else {
  28711 		v7 = float32(GetPSNR1(tls, total_distortion, total_size))
  28712 	}
  28713 	**(**float32)(__ccgo_up(results + 4*4)) = v7
  28714 	ok = int32(1)
  28715 	goto Error
  28716 Error:
  28717 	;
  28718 	WebPPictureFree(tls, bp)
  28719 	WebPPictureFree(tls, bp+256)
  28720 	return ok
  28721 }
  28722 
  28723 //------------------------------------------------------------------------------
  28724 
  28725 // Copyright 2012 Google Inc. All Rights Reserved.
  28726 //
  28727 // Use of this source code is governed by a BSD-style license
  28728 // that can be found in the COPYING file in the root of the source
  28729 // tree. An additional intellectual property rights grant can be found
  28730 // in the file PATENTS. All contributing project authors may
  28731 // be found in the AUTHORS file in the root of the source tree.
  28732 // -----------------------------------------------------------------------------
  28733 //
  28734 // Misc. common utility functions
  28735 //
  28736 // Authors: Skal (pascal.massimino@gmail.com)
  28737 //          Urvang (urvang@google.com)
  28738 
  28739 // C documentation
  28740 //
  28741 //	// Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
  28742 //	// into 'dst'. Mark 'dst' as not owning any memory.
  28743 func PictureGrabSpecs(tls *libc.TLS, src uintptr, dst uintptr) {
  28744 	**(**WebPPicture)(__ccgo_up(dst)) = **(**WebPPicture)(__ccgo_up(src))
  28745 	WebPPictureResetBuffers(tls, dst)
  28746 }
  28747 
  28748 //------------------------------------------------------------------------------
  28749 
  28750 // C documentation
  28751 //
  28752 //	// Adjust top-left corner to chroma sample position.
  28753 func SnapTopLeftPosition(tls *libc.TLS, pic uintptr, left uintptr, top uintptr) {
  28754 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28755 		**(**int32)(__ccgo_up(left)) &= ^libc.Int32FromInt32(1)
  28756 		**(**int32)(__ccgo_up(top)) &= ^libc.Int32FromInt32(1)
  28757 	}
  28758 }
  28759 
  28760 // C documentation
  28761 //
  28762 //	// Adjust top-left corner and verify that the sub-rectangle is valid.
  28763 func AdjustAndCheckRectangle(tls *libc.TLS, pic uintptr, left uintptr, top uintptr, width int32, height int32) (r int32) {
  28764 	SnapTopLeftPosition(tls, pic, left, top)
  28765 	if **(**int32)(__ccgo_up(left)) < 0 || **(**int32)(__ccgo_up(top)) < 0 {
  28766 		return 0
  28767 	}
  28768 	if width <= 0 || height <= 0 {
  28769 		return 0
  28770 	}
  28771 	if **(**int32)(__ccgo_up(left))+width > (*WebPPicture)(unsafe.Pointer(pic)).Fwidth {
  28772 		return 0
  28773 	}
  28774 	if **(**int32)(__ccgo_up(top))+height > (*WebPPicture)(unsafe.Pointer(pic)).Fheight {
  28775 		return 0
  28776 	}
  28777 	return int32(1)
  28778 }
  28779 
  28780 func WebPPictureCopy(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  28781 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28782 		return 0
  28783 	}
  28784 	if src == dst {
  28785 		return int32(1)
  28786 	}
  28787 	PictureGrabSpecs(tls, src, dst)
  28788 	if !(WebPPictureAlloc(tls, dst) != 0) {
  28789 		return 0
  28790 	}
  28791 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28792 		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)
  28793 		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))
  28794 		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))
  28795 		if (*WebPPicture)(unsafe.Pointer(dst)).Fa != libc.UintptrFromInt32(0) {
  28796 			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)
  28797 		}
  28798 	} else {
  28799 		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)
  28800 	}
  28801 	return int32(1)
  28802 }
  28803 
  28804 func WebPPictureIsView(tls *libc.TLS, picture uintptr) (r int32) {
  28805 	if picture == libc.UintptrFromInt32(0) {
  28806 		return 0
  28807 	}
  28808 	if (*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0 {
  28809 		return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_argb_ == libc.UintptrFromInt32(0))
  28810 	}
  28811 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Fmemory_ == libc.UintptrFromInt32(0))
  28812 }
  28813 
  28814 func WebPPictureView(tls *libc.TLS, src uintptr, _left int32, _top int32, width int32, height int32, dst uintptr) (r int32) {
  28815 	bp := tls.Alloc(16)
  28816 	defer tls.Free(16)
  28817 	*(*int32)(unsafe.Pointer(bp)) = _left
  28818 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28819 	if src == libc.UintptrFromInt32(0) || dst == libc.UintptrFromInt32(0) {
  28820 		return 0
  28821 	}
  28822 	// verify rectangle position.
  28823 	if !(AdjustAndCheckRectangle(tls, src, bp, bp+4, width, height) != 0) {
  28824 		return 0
  28825 	}
  28826 	if src != dst { // beware of aliasing! We don't want to leak 'memory_'.
  28827 		PictureGrabSpecs(tls, src, dst)
  28828 	}
  28829 	(*WebPPicture)(unsafe.Pointer(dst)).Fwidth = width
  28830 	(*WebPPicture)(unsafe.Pointer(dst)).Fheight = height
  28831 	if !((*WebPPicture)(unsafe.Pointer(src)).Fuse_argb != 0) {
  28832 		(*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)))
  28833 		(*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))
  28834 		(*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))
  28835 		(*WebPPicture)(unsafe.Pointer(dst)).Fy_stride = (*WebPPicture)(unsafe.Pointer(src)).Fy_stride
  28836 		(*WebPPicture)(unsafe.Pointer(dst)).Fuv_stride = (*WebPPicture)(unsafe.Pointer(src)).Fuv_stride
  28837 		if (*WebPPicture)(unsafe.Pointer(src)).Fa != libc.UintptrFromInt32(0) {
  28838 			(*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)))
  28839 			(*WebPPicture)(unsafe.Pointer(dst)).Fa_stride = (*WebPPicture)(unsafe.Pointer(src)).Fa_stride
  28840 		}
  28841 	} else {
  28842 		(*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
  28843 		(*WebPPicture)(unsafe.Pointer(dst)).Fargb_stride = (*WebPPicture)(unsafe.Pointer(src)).Fargb_stride
  28844 	}
  28845 	return int32(1)
  28846 }
  28847 
  28848 //------------------------------------------------------------------------------
  28849 // Picture cropping
  28850 
  28851 func WebPPictureCrop(tls *libc.TLS, pic uintptr, _left int32, _top int32, width int32, height int32) (r int32) {
  28852 	bp := tls.Alloc(272)
  28853 	defer tls.Free(272)
  28854 	*(*int32)(unsafe.Pointer(bp)) = _left
  28855 	*(*int32)(unsafe.Pointer(bp + 4)) = _top
  28856 	var a_offset, uv_offset, y_offset int32
  28857 	var src uintptr
  28858 	var _ /* tmp at bp+8 */ WebPPicture
  28859 	_, _, _, _ = a_offset, src, uv_offset, y_offset
  28860 	if pic == libc.UintptrFromInt32(0) {
  28861 		return 0
  28862 	}
  28863 	if !(AdjustAndCheckRectangle(tls, pic, bp, bp+4, width, height) != 0) {
  28864 		return 0
  28865 	}
  28866 	PictureGrabSpecs(tls, pic, bp+8)
  28867 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = width
  28868 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = height
  28869 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28870 		return WebPEncodingSetError(tls, pic, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28871 	}
  28872 	if !((*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0) {
  28873 		y_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fy_stride + **(**int32)(__ccgo_up(bp))
  28874 		uv_offset = **(**int32)(__ccgo_up(bp + 4))/int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride + **(**int32)(__ccgo_up(bp))/int32(2)
  28875 		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)
  28876 		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))
  28877 		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))
  28878 		if (**(**WebPPicture)(__ccgo_up(bp + 8))).Fa != libc.UintptrFromInt32(0) {
  28879 			a_offset = **(**int32)(__ccgo_up(bp + 4))*(*WebPPicture)(unsafe.Pointer(pic)).Fa_stride + **(**int32)(__ccgo_up(bp))
  28880 			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)
  28881 		}
  28882 	} else {
  28883 		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
  28884 		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)
  28885 	}
  28886 	WebPPictureFree(tls, pic)
  28887 	**(**WebPPicture)(__ccgo_up(pic)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28888 	return int32(1)
  28889 }
  28890 
  28891 //------------------------------------------------------------------------------
  28892 // Simple picture rescaler
  28893 
  28894 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) {
  28895 	bp := tls.Alloc(112)
  28896 	defer tls.Free(112)
  28897 	var y int32
  28898 	var _ /* rescaler at bp+0 */ WebPRescaler
  28899 	_ = y
  28900 	y = 0
  28901 	if !(WebPRescalerInit(tls, bp, src_width, src_height, dst, dst_width, dst_height, dst_stride, num_channels, work) != 0) {
  28902 		return 0
  28903 	}
  28904 	for y < src_height {
  28905 		y = y + WebPRescalerImport(tls, bp, src_height-y, src+uintptr(y*src_stride), src_stride)
  28906 		WebPRescalerExport(tls, bp)
  28907 	}
  28908 	return int32(1)
  28909 }
  28910 
  28911 func AlphaMultiplyARGB(tls *libc.TLS, pic uintptr, inverse int32) {
  28912 	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)
  28913 }
  28914 
  28915 func AlphaMultiplyY(tls *libc.TLS, pic uintptr, inverse int32) {
  28916 	if (*WebPPicture)(unsafe.Pointer(pic)).Fa != libc.UintptrFromInt32(0) {
  28917 		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)
  28918 	}
  28919 }
  28920 
  28921 func WebPPictureRescale(tls *libc.TLS, picture uintptr, _width int32, _height int32) (r int32) {
  28922 	bp := tls.Alloc(272)
  28923 	defer tls.Free(272)
  28924 	*(*int32)(unsafe.Pointer(bp)) = _width
  28925 	*(*int32)(unsafe.Pointer(bp + 4)) = _height
  28926 	var prev_height, prev_width int32
  28927 	var work uintptr
  28928 	var _ /* tmp at bp+8 */ WebPPicture
  28929 	_, _, _ = prev_height, prev_width, work
  28930 	if picture == libc.UintptrFromInt32(0) {
  28931 		return 0
  28932 	}
  28933 	prev_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  28934 	prev_height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  28935 	if !(WebPRescalerGetScaledDimensions(tls, prev_width, prev_height, bp, bp+4) != 0) {
  28936 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28937 	}
  28938 	PictureGrabSpecs(tls, picture, bp+8)
  28939 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fwidth = **(**int32)(__ccgo_up(bp))
  28940 	(**(**WebPPicture)(__ccgo_up(bp + 8))).Fheight = **(**int32)(__ccgo_up(bp + 4))
  28941 	if !(WebPPictureAlloc(tls, bp+8) != 0) {
  28942 		return WebPEncodingSetError(tls, picture, (**(**WebPPicture)(__ccgo_up(bp + 8))).Ferror_code)
  28943 	}
  28944 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  28945 		work = WebPSafeMalloc(tls, uint64(uint64(2)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))), uint64(4))
  28946 		if work == libc.UintptrFromInt32(0) {
  28947 			WebPPictureFree(tls, bp+8)
  28948 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28949 		}
  28950 		// If present, we need to rescale alpha first (for AlphaMultiplyY).
  28951 		if (*WebPPicture)(unsafe.Pointer(picture)).Fa != libc.UintptrFromInt32(0) {
  28952 			WebPInitAlphaProcessing(tls)
  28953 			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) {
  28954 				return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28955 			}
  28956 		}
  28957 		// We take transparency into account on the luma plane only. That's not
  28958 		// totally exact blending, but still is a good approximation.
  28959 		AlphaMultiplyY(tls, picture, 0)
  28960 		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) {
  28961 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28962 		}
  28963 		AlphaMultiplyY(tls, bp+8, int32(1))
  28964 	} else {
  28965 		work = WebPSafeMalloc(tls, uint64(uint64(2)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(4)), uint64(4))
  28966 		if work == libc.UintptrFromInt32(0) {
  28967 			WebPPictureFree(tls, bp+8)
  28968 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  28969 		}
  28970 		// In order to correctly interpolate colors, we need to apply the alpha
  28971 		// weighting first (black-matting), scale the RGB values, and remove
  28972 		// the premultiplication afterward (while preserving the alpha channel).
  28973 		WebPInitAlphaProcessing(tls)
  28974 		AlphaMultiplyARGB(tls, picture, 0)
  28975 		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) {
  28976 			return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  28977 		}
  28978 		AlphaMultiplyARGB(tls, bp+8, int32(1))
  28979 	}
  28980 	WebPPictureFree(tls, picture)
  28981 	WebPSafeFree(tls, work)
  28982 	**(**WebPPicture)(__ccgo_up(picture)) = **(**WebPPicture)(__ccgo_up(bp + 8))
  28983 	return int32(1)
  28984 }
  28985 
  28986 //------------------------------------------------------------------------------
  28987 
  28988 // Copyright 2011 Google Inc. All Rights Reserved.
  28989 //
  28990 // Use of this source code is governed by a BSD-style license
  28991 // that can be found in the COPYING file in the root of the source
  28992 // tree. An additional intellectual property rights grant can be found
  28993 // in the file PATENTS. All contributing project authors may
  28994 // be found in the AUTHORS file in the root of the source tree.
  28995 // -----------------------------------------------------------------------------
  28996 //
  28997 //   WebP encoder: main interface
  28998 //
  28999 // Author: Skal (pascal.massimino@gmail.com)
  29000 
  29001 // Copyright 2010 Google Inc. All Rights Reserved.
  29002 //
  29003 // Use of this source code is governed by a BSD-style license
  29004 // that can be found in the COPYING file in the root of the source
  29005 // tree. An additional intellectual property rights grant can be found
  29006 // in the file PATENTS. All contributing project authors may
  29007 // be found in the AUTHORS file in the root of the source tree.
  29008 // -----------------------------------------------------------------------------
  29009 //
  29010 //  Common types + memory wrappers
  29011 //
  29012 // Author: Skal (pascal.massimino@gmail.com)
  29013 
  29014 //------------------------------------------------------------------------------
  29015 // Helper: clean up fully transparent area to help compressibility.
  29016 
  29017 func IsTransparentARGBArea(tls *libc.TLS, ptr uintptr, stride int32, size int32) (r int32) {
  29018 	var x, y int32
  29019 	_, _ = x, y
  29020 	y = 0
  29021 	for {
  29022 		if !(y < size) {
  29023 			break
  29024 		}
  29025 		x = 0
  29026 		for {
  29027 			if !(x < size) {
  29028 				break
  29029 			}
  29030 			if **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))&uint32(0xff000000) != 0 {
  29031 				return 0
  29032 			}
  29033 			goto _2
  29034 		_2:
  29035 			;
  29036 			x = x + 1
  29037 		}
  29038 		ptr = ptr + uintptr(stride)*4
  29039 		goto _1
  29040 	_1:
  29041 		;
  29042 		y = y + 1
  29043 	}
  29044 	return int32(1)
  29045 }
  29046 
  29047 func Flatten(tls *libc.TLS, ptr uintptr, v int32, stride int32, size int32) {
  29048 	var y int32
  29049 	_ = y
  29050 	y = 0
  29051 	for {
  29052 		if !(y < size) {
  29053 			break
  29054 		}
  29055 		libc.Xmemset(tls, ptr, v, libc.Uint64FromInt32(size))
  29056 		ptr = ptr + uintptr(stride)
  29057 		goto _1
  29058 	_1:
  29059 		;
  29060 		y = y + 1
  29061 	}
  29062 }
  29063 
  29064 func FlattenARGB(tls *libc.TLS, ptr uintptr, v uint32_t, stride int32, size int32) {
  29065 	var x, y int32
  29066 	_, _ = x, y
  29067 	y = 0
  29068 	for {
  29069 		if !(y < size) {
  29070 			break
  29071 		}
  29072 		x = 0
  29073 		for {
  29074 			if !(x < size) {
  29075 				break
  29076 			}
  29077 			**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = v
  29078 			goto _2
  29079 		_2:
  29080 			;
  29081 			x = x + 1
  29082 		}
  29083 		ptr = ptr + uintptr(stride)*4
  29084 		goto _1
  29085 	_1:
  29086 		;
  29087 		y = y + 1
  29088 	}
  29089 }
  29090 
  29091 // C documentation
  29092 //
  29093 //	// Smoothen the luma components of transparent pixels. Return true if the whole
  29094 //	// block is transparent.
  29095 func SmoothenBlock(tls *libc.TLS, a_ptr uintptr, a_stride int32, y_ptr uintptr, y_stride int32, width int32, height int32) (r int32) {
  29096 	var alpha_ptr, luma_ptr uintptr
  29097 	var avg_u8 uint8_t
  29098 	var count, sum, x, y int32
  29099 	_, _, _, _, _, _, _ = alpha_ptr, avg_u8, count, luma_ptr, sum, x, y
  29100 	sum = 0
  29101 	count = 0
  29102 	alpha_ptr = a_ptr
  29103 	luma_ptr = y_ptr
  29104 	y = 0
  29105 	for {
  29106 		if !(y < height) {
  29107 			break
  29108 		}
  29109 		x = 0
  29110 		for {
  29111 			if !(x < width) {
  29112 				break
  29113 			}
  29114 			if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) != 0 {
  29115 				count = count + 1
  29116 				sum = sum + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))))
  29117 			}
  29118 			goto _2
  29119 		_2:
  29120 			;
  29121 			x = x + 1
  29122 		}
  29123 		alpha_ptr = alpha_ptr + uintptr(a_stride)
  29124 		luma_ptr = luma_ptr + uintptr(y_stride)
  29125 		goto _1
  29126 	_1:
  29127 		;
  29128 		y = y + 1
  29129 	}
  29130 	if count > 0 && count < width*height {
  29131 		avg_u8 = libc.Uint8FromInt32(sum / count)
  29132 		alpha_ptr = a_ptr
  29133 		luma_ptr = y_ptr
  29134 		y = 0
  29135 		for {
  29136 			if !(y < height) {
  29137 				break
  29138 			}
  29139 			x = 0
  29140 			for {
  29141 				if !(x < width) {
  29142 					break
  29143 				}
  29144 				if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(alpha_ptr + uintptr(x)))) == 0 {
  29145 					**(**uint8_t)(__ccgo_up(luma_ptr + uintptr(x))) = avg_u8
  29146 				}
  29147 				goto _4
  29148 			_4:
  29149 				;
  29150 				x = x + 1
  29151 			}
  29152 			alpha_ptr = alpha_ptr + uintptr(a_stride)
  29153 			luma_ptr = luma_ptr + uintptr(y_stride)
  29154 			goto _3
  29155 		_3:
  29156 			;
  29157 			y = y + 1
  29158 		}
  29159 	}
  29160 	return libc.BoolInt32(count == 0)
  29161 }
  29162 
  29163 func WebPReplaceTransparentPixels(tls *libc.TLS, pic uintptr, color uint32_t) {
  29164 	var argb uintptr
  29165 	var y, v1 int32
  29166 	_, _, _ = argb, y, v1
  29167 	if pic != libc.UintptrFromInt32(0) && (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  29168 		y = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  29169 		argb = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  29170 		color = color & uint32(0xffffff) // force alpha=0
  29171 		WebPInitAlphaProcessing(tls)
  29172 		for {
  29173 			v1 = y
  29174 			y = y - 1
  29175 			if !(v1 > 0) {
  29176 				break
  29177 			}
  29178 			(*(*func(*libc.TLS, uintptr, int32, uint32_t))(unsafe.Pointer(&struct{ uintptr }{WebPAlphaReplace})))(tls, argb, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, color)
  29179 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  29180 		}
  29181 	}
  29182 }
  29183 
  29184 func WebPCleanupTransparentArea(tls *libc.TLS, pic uintptr) {
  29185 	var a_ptr, u_ptr, v_ptr, y_ptr uintptr
  29186 	var a_stride, h, height, need_reset, need_reset1, off, sub_height, uv_stride, w, width, x, y, y_stride int32
  29187 	var argb_value uint32_t
  29188 	var values [3]int32
  29189 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  29190 	if pic == libc.UintptrFromInt32(0) {
  29191 		return
  29192 	}
  29193 	w = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth / int32(8)
  29194 	h = (*WebPPicture)(unsafe.Pointer(pic)).Fheight / int32(8)
  29195 	// note: we ignore the left-overs on right/bottom, except for SmoothenBlock().
  29196 	if (*WebPPicture)(unsafe.Pointer(pic)).Fuse_argb != 0 {
  29197 		argb_value = uint32(0)
  29198 		y = 0
  29199 		for {
  29200 			if !(y < h) {
  29201 				break
  29202 			}
  29203 			need_reset = int32(1)
  29204 			x = 0
  29205 			for {
  29206 				if !(x < w) {
  29207 					break
  29208 				}
  29209 				off = (y*(*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride + x) * int32(8)
  29210 				if IsTransparentARGBArea(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8)) != 0 {
  29211 					if need_reset != 0 {
  29212 						argb_value = **(**uint32_t)(__ccgo_up((*WebPPicture)(unsafe.Pointer(pic)).Fargb + uintptr(off)*4))
  29213 						need_reset = 0
  29214 					}
  29215 					FlattenARGB(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fargb+uintptr(off)*4, argb_value, (*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride, int32(8))
  29216 				} else {
  29217 					need_reset = int32(1)
  29218 				}
  29219 				goto _2
  29220 			_2:
  29221 				;
  29222 				x = x + 1
  29223 			}
  29224 			goto _1
  29225 		_1:
  29226 			;
  29227 			y = y + 1
  29228 		}
  29229 	} else {
  29230 		width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  29231 		height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  29232 		y_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fy_stride
  29233 		uv_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fuv_stride
  29234 		a_stride = (*WebPPicture)(unsafe.Pointer(pic)).Fa_stride
  29235 		y_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fy
  29236 		u_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fu
  29237 		v_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fv
  29238 		a_ptr = (*WebPPicture)(unsafe.Pointer(pic)).Fa
  29239 		values = [3]int32{}
  29240 		if a_ptr == libc.UintptrFromInt32(0) || y_ptr == libc.UintptrFromInt32(0) || u_ptr == libc.UintptrFromInt32(0) || v_ptr == libc.UintptrFromInt32(0) {
  29241 			return
  29242 		}
  29243 		y = 0
  29244 		for {
  29245 			if !(y+int32(8) <= height) {
  29246 				break
  29247 			}
  29248 			need_reset1 = int32(1)
  29249 			x = 0
  29250 			for {
  29251 				if !(x+int32(8) <= width) {
  29252 					break
  29253 				}
  29254 				if SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), int32(8)) != 0 {
  29255 					if need_reset1 != 0 {
  29256 						values[0] = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y_ptr + uintptr(x))))
  29257 						values[int32(1)] = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u_ptr + uintptr(x>>int32(1)))))
  29258 						values[int32(2)] = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v_ptr + uintptr(x>>int32(1)))))
  29259 						need_reset1 = 0
  29260 					}
  29261 					Flatten(tls, y_ptr+uintptr(x), values[0], y_stride, int32(8))
  29262 					Flatten(tls, u_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(1)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  29263 					Flatten(tls, v_ptr+uintptr(x>>libc.Int32FromInt32(1)), values[int32(2)], uv_stride, libc.Int32FromInt32(8)/libc.Int32FromInt32(2))
  29264 				} else {
  29265 					need_reset1 = int32(1)
  29266 				}
  29267 				goto _4
  29268 			_4:
  29269 				;
  29270 				x = x + int32(8)
  29271 			}
  29272 			if x < width {
  29273 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, int32(8))
  29274 			}
  29275 			a_ptr = a_ptr + uintptr(int32(8)*a_stride)
  29276 			y_ptr = y_ptr + uintptr(int32(8)*y_stride)
  29277 			u_ptr = u_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  29278 			v_ptr = v_ptr + uintptr(libc.Int32FromInt32(8)/libc.Int32FromInt32(2)*uv_stride)
  29279 			goto _3
  29280 		_3:
  29281 			;
  29282 			y = y + int32(8)
  29283 		}
  29284 		if y < height {
  29285 			sub_height = height - y
  29286 			x = 0
  29287 			for {
  29288 				if !(x+int32(8) <= width) {
  29289 					break
  29290 				}
  29291 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, int32(8), sub_height)
  29292 				goto _5
  29293 			_5:
  29294 				;
  29295 				x = x + int32(8)
  29296 			}
  29297 			if x < width {
  29298 				SmoothenBlock(tls, a_ptr+uintptr(x), a_stride, y_ptr+uintptr(x), y_stride, width-x, sub_height)
  29299 			}
  29300 		}
  29301 	}
  29302 }
  29303 
  29304 //------------------------------------------------------------------------------
  29305 // Blend color and remove transparency info
  29306 
  29307 func MakeARGB32(tls *libc.TLS, r int32, g int32, b int32) (r1 uint32_t) {
  29308 	return libc.Uint32FromUint32(0xff000000) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  29309 }
  29310 
  29311 func WebPBlendAlpha(tls *libc.TLS, picture uintptr, background_rgb uint32_t) {
  29312 	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
  29313 	var a_ptr, a_ptr2, argb, u_ptr, v_ptr, y_ptr, v19 uintptr
  29314 	var alpha uint8_t
  29315 	var alpha1, alpha2, background uint32_t
  29316 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  29317 	red = libc.Int32FromUint32(background_rgb >> libc.Int32FromInt32(16) & uint32(0xff))
  29318 	green = libc.Int32FromUint32(background_rgb >> libc.Int32FromInt32(8) & uint32(0xff))
  29319 	blue = libc.Int32FromUint32(background_rgb >> libc.Int32FromInt32(0) & uint32(0xff))
  29320 	if picture == libc.UintptrFromInt32(0) {
  29321 		return
  29322 	}
  29323 	if !((*WebPPicture)(unsafe.Pointer(picture)).Fuse_argb != 0) {
  29324 		// omit last pixel during u/v loop
  29325 		uv_width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth >> libc.Int32FromInt32(1)
  29326 		luma = int32(16839)*red + int32(33059)*green + int32(6420)*blue
  29327 		v1 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  29328 		goto _2
  29329 	_2:
  29330 		Y0 = v1
  29331 		u = -int32(9719)*(int32(4)*red) - int32(19081)*(int32(4)*green) + int32(28800)*(int32(4)*blue)
  29332 		v5 = u
  29333 		v5 = (v5 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29334 		if v5 & ^libc.Int32FromInt32(0xff) == 0 {
  29335 			v8 = v5
  29336 		} else {
  29337 			if v5 < 0 {
  29338 				v9 = 0
  29339 			} else {
  29340 				v9 = int32(255)
  29341 			}
  29342 			v8 = v9
  29343 		}
  29344 		v6 = v8
  29345 		goto _7
  29346 	_7:
  29347 		v3 = v6
  29348 		goto _4
  29349 	_4:
  29350 		// VP8RGBToU/V expects the u/v values summed over four pixels
  29351 		U0 = v3
  29352 		v = +libc.Int32FromInt32(28800)*(int32(4)*red) - int32(24116)*(int32(4)*green) - int32(4684)*(int32(4)*blue)
  29353 		v12 = v
  29354 		v12 = (v12 + libc.Int32FromInt32(4)*int32(YUV_HALF) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  29355 		if v12 & ^libc.Int32FromInt32(0xff) == 0 {
  29356 			v15 = v12
  29357 		} else {
  29358 			if v12 < 0 {
  29359 				v16 = 0
  29360 			} else {
  29361 				v16 = int32(255)
  29362 			}
  29363 			v15 = v16
  29364 		}
  29365 		v13 = v15
  29366 		goto _14
  29367 	_14:
  29368 		v10 = v13
  29369 		goto _11
  29370 	_11:
  29371 		V0 = v10
  29372 		has_alpha = (*WebPPicture)(unsafe.Pointer(picture)).Fcolorspace & int32(WEBP_CSP_ALPHA_BIT)
  29373 		y_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fy
  29374 		u_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fu
  29375 		v_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fv
  29376 		a_ptr = (*WebPPicture)(unsafe.Pointer(picture)).Fa
  29377 		if !(has_alpha != 0) || a_ptr == libc.UintptrFromInt32(0) {
  29378 			return
  29379 		} // nothing to do
  29380 		y = 0
  29381 		for {
  29382 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29383 				break
  29384 			}
  29385 			// Luma blending
  29386 			x = 0
  29387 			for {
  29388 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29389 					break
  29390 				}
  29391 				alpha = **(**uint8_t)(__ccgo_up(a_ptr + uintptr(x)))
  29392 				if libc.Int32FromUint8(alpha) < int32(0xff) {
  29393 					**(**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))
  29394 				}
  29395 				goto _18
  29396 			_18:
  29397 				;
  29398 				x = x + 1
  29399 			}
  29400 			// Chroma blending every even line
  29401 			if y&int32(1) == 0 {
  29402 				if y+int32(1) == (*WebPPicture)(unsafe.Pointer(picture)).Fheight {
  29403 					v19 = a_ptr
  29404 				} else {
  29405 					v19 = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29406 				}
  29407 				a_ptr2 = v19
  29408 				x = 0
  29409 				for {
  29410 					if !(x < uv_width) {
  29411 						break
  29412 					}
  29413 					// Average four alpha values into a single blending weight.
  29414 					// TODO(skal): might lead to visible contouring. Can we do better?
  29415 					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))))))
  29416 					**(**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))
  29417 					**(**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))
  29418 					goto _20
  29419 				_20:
  29420 					;
  29421 					x = x + 1
  29422 				}
  29423 				if (*WebPPicture)(unsafe.Pointer(picture)).Fwidth&int32(1) != 0 { // rightmost pixel
  29424 					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))))))
  29425 					**(**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))
  29426 					**(**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))
  29427 				}
  29428 			} else {
  29429 				u_ptr = u_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29430 				v_ptr = v_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fuv_stride)
  29431 			}
  29432 			libc.Xmemset(tls, a_ptr, int32(0xff), libc.Uint64FromInt32((*WebPPicture)(unsafe.Pointer(picture)).Fwidth)) // reset alpha value to opaque
  29433 			a_ptr = a_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fa_stride)
  29434 			y_ptr = y_ptr + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fy_stride)
  29435 			goto _17
  29436 		_17:
  29437 			;
  29438 			y = y + 1
  29439 		}
  29440 	} else {
  29441 		argb = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  29442 		background = MakeARGB32(tls, red, green, blue)
  29443 		y = 0
  29444 		for {
  29445 			if !(y < (*WebPPicture)(unsafe.Pointer(picture)).Fheight) {
  29446 				break
  29447 			}
  29448 			x = 0
  29449 			for {
  29450 				if !(x < (*WebPPicture)(unsafe.Pointer(picture)).Fwidth) {
  29451 					break
  29452 				}
  29453 				alpha3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(24) & uint32(0xff))
  29454 				if alpha3 != int32(0xff) {
  29455 					if alpha3 > 0 {
  29456 						r3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(16) & uint32(0xff))
  29457 						g3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  29458 						b3 = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) >> libc.Int32FromInt32(0) & uint32(0xff))
  29459 						r3 = ((red*(int32(255)-alpha3)+r3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29460 						g3 = ((green*(int32(255)-alpha3)+g3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29461 						b3 = ((blue*(int32(255)-alpha3)+b3*alpha3)*int32(0x101) + int32(256)) >> int32(16)
  29462 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = MakeARGB32(tls, r3, g3, b3)
  29463 					} else {
  29464 						**(**uint32_t)(__ccgo_up(argb + uintptr(x)*4)) = background
  29465 					}
  29466 				}
  29467 				goto _22
  29468 			_22:
  29469 				;
  29470 				x = x + 1
  29471 			}
  29472 			argb = argb + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  29473 			goto _21
  29474 		_21:
  29475 			;
  29476 			y = y + 1
  29477 		}
  29478 	}
  29479 }
  29480 
  29481 const ARGB_BLACK1 = 4278190080
  29482 
  29483 //------------------------------------------------------------------------------
  29484 
  29485 // Copyright 2012 Google Inc. All Rights Reserved.
  29486 //
  29487 // Use of this source code is governed by a BSD-style license
  29488 // that can be found in the COPYING file in the root of the source
  29489 // tree. An additional intellectual property rights grant can be found
  29490 // in the file PATENTS. All contributing project authors may
  29491 // be found in the AUTHORS file in the root of the source tree.
  29492 // -----------------------------------------------------------------------------
  29493 //
  29494 // Misc. common utility functions
  29495 //
  29496 // Authors: Skal (pascal.massimino@gmail.com)
  29497 //          Urvang (urvang@google.com)
  29498 
  29499 // Copyright 2011 Google Inc. All Rights Reserved.
  29500 //
  29501 // Use of this source code is governed by a BSD-style license
  29502 // that can be found in the COPYING file in the root of the source
  29503 // tree. An additional intellectual property rights grant can be found
  29504 // in the file PATENTS. All contributing project authors may
  29505 // be found in the AUTHORS file in the root of the source tree.
  29506 // -----------------------------------------------------------------------------
  29507 //
  29508 //   WebP encoder: main interface
  29509 //
  29510 // Author: Skal (pascal.massimino@gmail.com)
  29511 
  29512 // Copyright 2012 Google Inc. All Rights Reserved.
  29513 //
  29514 // Use of this source code is governed by a BSD-style license
  29515 // that can be found in the COPYING file in the root of the source
  29516 // tree. An additional intellectual property rights grant can be found
  29517 // in the file PATENTS. All contributing project authors may
  29518 // be found in the AUTHORS file in the root of the source tree.
  29519 // -----------------------------------------------------------------------------
  29520 //
  29521 //  Internal header for constants related to WebP file format.
  29522 //
  29523 // Author: Urvang (urvang@google.com)
  29524 
  29525 // Copyright 2010 Google Inc. All Rights Reserved.
  29526 //
  29527 // Use of this source code is governed by a BSD-style license
  29528 // that can be found in the COPYING file in the root of the source
  29529 // tree. An additional intellectual property rights grant can be found
  29530 // in the file PATENTS. All contributing project authors may
  29531 // be found in the AUTHORS file in the root of the source tree.
  29532 // -----------------------------------------------------------------------------
  29533 //
  29534 //  Common types + memory wrappers
  29535 //
  29536 // Author: Skal (pascal.massimino@gmail.com)
  29537 
  29538 var kSpatialPredictorBias = int64(libc.Int64FromInt64(15) << libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  29539 var kPredLowEffort = int32(11)
  29540 var kMaskAlpha = uint32(0xff000000)
  29541 var kNumPredModes = int32(14)
  29542 
  29543 // C documentation
  29544 //
  29545 //	// Mostly used to reduce code size + readability
  29546 func GetMin(tls *libc.TLS, a int32, b int32) (r int32) {
  29547 	var v1 int32
  29548 	_ = v1
  29549 	if a > b {
  29550 		v1 = b
  29551 	} else {
  29552 		v1 = a
  29553 	}
  29554 	return v1
  29555 }
  29556 
  29557 func GetMax(tls *libc.TLS, a int32, b int32) (r int32) {
  29558 	var v1 int32
  29559 	_ = v1
  29560 	if a < b {
  29561 		v1 = b
  29562 	} else {
  29563 		v1 = a
  29564 	}
  29565 	return v1
  29566 }
  29567 
  29568 //------------------------------------------------------------------------------
  29569 // Methods to calculate Entropy (Shannon).
  29570 
  29571 // C documentation
  29572 //
  29573 //	// Compute a bias for prediction entropy using a global heuristic to favor
  29574 //	// values closer to 0. Hence the final negative sign.
  29575 //	// 'exp_val' has a scaling factor of 1/100.
  29576 func PredictionCostBias(tls *libc.TLS, counts uintptr, weight_0 uint64_t, exp_val uint64_t) (r int64_t) {
  29577 	var bits, exp_decay_factor uint64_t
  29578 	var i, significant_symbols int32
  29579 	var v6 int64
  29580 	var v2, v3, v4 int64_t
  29581 	_, _, _, _, _, _, _, _ = bits, exp_decay_factor, i, significant_symbols, v2, v3, v4, v6
  29582 	significant_symbols = libc.Int32FromInt32(256) >> libc.Int32FromInt32(4)
  29583 	exp_decay_factor = uint64(6) // has a scaling factor of 1/10
  29584 	bits = weight_0 * uint64(**(**uint32_t)(__ccgo_up(counts))) << int32(LOG_2_PRECISION_BITS)
  29585 	exp_val = exp_val << uint64(LOG_2_PRECISION_BITS)
  29586 	i = int32(1)
  29587 	for {
  29588 		if !(i < significant_symbols) {
  29589 			break
  29590 		}
  29591 		v2 = libc.Int64FromUint64(exp_val * uint64(**(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))+**(**uint32_t)(__ccgo_up(counts + uintptr(int32(256)-i)*4))))
  29592 		v3 = int64(100)
  29593 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29594 			v6 = (v2 + v3/int64(2)) / v3
  29595 		} else {
  29596 			v6 = (v2 - v3/int64(2)) / v3
  29597 		}
  29598 		v4 = v6
  29599 		goto _5
  29600 	_5:
  29601 		bits = bits + libc.Uint64FromInt64(v4)
  29602 		v2 = libc.Int64FromUint64(exp_decay_factor * exp_val)
  29603 		v3 = int64(10)
  29604 		if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29605 			v6 = (v2 + v3/int64(2)) / v3
  29606 		} else {
  29607 			v6 = (v2 - v3/int64(2)) / v3
  29608 		}
  29609 		v4 = v6
  29610 		goto _10
  29611 	_10:
  29612 		exp_val = libc.Uint64FromInt64(v4)
  29613 		goto _1
  29614 	_1:
  29615 		;
  29616 		i = i + 1
  29617 	}
  29618 	v2 = libc.Int64FromUint64(bits)
  29619 	v3 = int64(10)
  29620 	if libc.BoolInt32(v2 < 0) == libc.BoolInt32(v3 < 0) {
  29621 		v6 = (v2 + v3/int64(2)) / v3
  29622 	} else {
  29623 		v6 = (v2 - v3/int64(2)) / v3
  29624 	}
  29625 	v4 = v6
  29626 	goto _15
  29627 _15:
  29628 	return -v4
  29629 }
  29630 
  29631 func PredictionCostSpatialHistogram(tls *libc.TLS, accumulated uintptr, tile uintptr, mode int32, left_mode int32, above_mode int32) (r int64_t) {
  29632 	var i int32
  29633 	var kExpValue uint64_t
  29634 	var retval int64_t
  29635 	_, _, _ = i, kExpValue, retval
  29636 	retval = 0
  29637 	i = 0
  29638 	for {
  29639 		if !(i < int32(4)) {
  29640 			break
  29641 		}
  29642 		kExpValue = uint64(94)
  29643 		retval = retval + PredictionCostBias(tls, tile+uintptr(i*int32(256))*4, uint64(1), kExpValue)
  29644 		// Compute the new cost if 'tile' is added to 'accumulate' but also add the
  29645 		// cost of the current histogram to guide the spatial predictor selection.
  29646 		// Basically, favor low entropy, locally and globally.
  29647 		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))
  29648 		goto _1
  29649 	_1:
  29650 		;
  29651 		i = i + 1
  29652 	}
  29653 	// Favor keeping the areas locally similar.
  29654 	if mode == left_mode {
  29655 		retval = retval - kSpatialPredictorBias
  29656 	}
  29657 	if mode == above_mode {
  29658 		retval = retval - kSpatialPredictorBias
  29659 	}
  29660 	return retval
  29661 }
  29662 
  29663 func UpdateHisto(tls *libc.TLS, histo_argb uintptr, argb uint32_t) {
  29664 	**(**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
  29665 	**(**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
  29666 	**(**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
  29667 	**(**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
  29668 }
  29669 
  29670 //------------------------------------------------------------------------------
  29671 // Spatial transform functions.
  29672 
  29673 func PredictBatch(tls *libc.TLS, mode int32, x_start int32, y int32, num_pixels int32, current uintptr, upper uintptr, out uintptr) {
  29674 	if x_start == 0 {
  29675 		if y == 0 {
  29676 			// ARGB_BLACK.
  29677 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(0)]})))(tls, current, libc.UintptrFromInt32(0), int32(1), out)
  29678 		} else {
  29679 			// Top one.
  29680 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LPredictorsSub[libc.Int32FromInt32(2)]})))(tls, current, upper, int32(1), out)
  29681 		}
  29682 		x_start = x_start + 1
  29683 		out += 4
  29684 		num_pixels = num_pixels - 1
  29685 	}
  29686 	if y == 0 {
  29687 		// Left one.
  29688 		(*(*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)
  29689 	} else {
  29690 		(*(*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)
  29691 	}
  29692 }
  29693 
  29694 func MaxDiffBetweenPixels(tls *libc.TLS, p1 uint32_t, p2 uint32_t) (r int32) {
  29695 	var diff_a, diff_b, diff_g, diff_r int32
  29696 	_, _, _, _ = diff_a, diff_b, diff_g, diff_r
  29697 	diff_a = libc.Xabs(tls, libc.Int32FromUint32(p1>>libc.Int32FromInt32(24))-libc.Int32FromUint32(p2>>libc.Int32FromInt32(24)))
  29698 	diff_r = libc.Xabs(tls, libc.Int32FromUint32(p1>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff))-libc.Int32FromUint32(p2>>libc.Int32FromInt32(16)&libc.Uint32FromInt32(0xff)))
  29699 	diff_g = libc.Xabs(tls, libc.Int32FromUint32(p1>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff))-libc.Int32FromUint32(p2>>libc.Int32FromInt32(8)&libc.Uint32FromInt32(0xff)))
  29700 	diff_b = libc.Xabs(tls, libc.Int32FromUint32(p1&libc.Uint32FromInt32(0xff))-libc.Int32FromUint32(p2&libc.Uint32FromInt32(0xff)))
  29701 	return GetMax(tls, GetMax(tls, diff_a, diff_r), GetMax(tls, diff_g, diff_b))
  29702 }
  29703 
  29704 func MaxDiffAroundPixel(tls *libc.TLS, current uint32_t, up uint32_t, down uint32_t, left uint32_t, right uint32_t) (r int32) {
  29705 	var diff_down, diff_left, diff_right, diff_up int32
  29706 	_, _, _, _ = diff_down, diff_left, diff_right, diff_up
  29707 	diff_up = MaxDiffBetweenPixels(tls, current, up)
  29708 	diff_down = MaxDiffBetweenPixels(tls, current, down)
  29709 	diff_left = MaxDiffBetweenPixels(tls, current, left)
  29710 	diff_right = MaxDiffBetweenPixels(tls, current, right)
  29711 	return GetMax(tls, GetMax(tls, diff_up, diff_down), GetMax(tls, diff_left, diff_right))
  29712 }
  29713 
  29714 func AddGreenToBlueAndRed(tls *libc.TLS, argb uint32_t) (r uint32_t) {
  29715 	var green, red_blue uint32_t
  29716 	_, _ = green, red_blue
  29717 	green = argb >> libc.Int32FromInt32(8) & uint32(0xff)
  29718 	red_blue = argb & uint32(0x00ff00ff)
  29719 	red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  29720 	red_blue = red_blue & uint32(0x00ff00ff)
  29721 	return argb&uint32(0xff00ff00) | red_blue
  29722 }
  29723 
  29724 func MaxDiffsForRow(tls *libc.TLS, width int32, stride int32, argb uintptr, max_diffs uintptr, used_subtract_green int32) {
  29725 	var current, down, left, right, up uint32_t
  29726 	var x int32
  29727 	_, _, _, _, _, _ = current, down, left, right, up, x
  29728 	if width <= int32(2) {
  29729 		return
  29730 	}
  29731 	current = **(**uint32_t)(__ccgo_up(argb))
  29732 	right = **(**uint32_t)(__ccgo_up(argb + 1*4))
  29733 	if used_subtract_green != 0 {
  29734 		current = AddGreenToBlueAndRed(tls, current)
  29735 		right = AddGreenToBlueAndRed(tls, right)
  29736 	}
  29737 	// max_diffs[0] and max_diffs[width - 1] are never used.
  29738 	x = int32(1)
  29739 	for {
  29740 		if !(x < width-int32(1)) {
  29741 			break
  29742 		}
  29743 		up = **(**uint32_t)(__ccgo_up(argb + uintptr(-stride+x)*4))
  29744 		down = **(**uint32_t)(__ccgo_up(argb + uintptr(stride+x)*4))
  29745 		left = current
  29746 		current = right
  29747 		right = **(**uint32_t)(__ccgo_up(argb + uintptr(x+int32(1))*4))
  29748 		if used_subtract_green != 0 {
  29749 			up = AddGreenToBlueAndRed(tls, up)
  29750 			down = AddGreenToBlueAndRed(tls, down)
  29751 			right = AddGreenToBlueAndRed(tls, right)
  29752 		}
  29753 		**(**uint8_t)(__ccgo_up(max_diffs + uintptr(x))) = libc.Uint8FromInt32(MaxDiffAroundPixel(tls, current, up, down, left, right))
  29754 		goto _1
  29755 	_1:
  29756 		;
  29757 		x = x + 1
  29758 	}
  29759 }
  29760 
  29761 // C documentation
  29762 //
  29763 //	// Quantize the difference between the actual component value and its prediction
  29764 //	// to a multiple of quantization, working modulo 256, taking care not to cross
  29765 //	// a boundary (inclusive upper limit).
  29766 func NearLosslessComponent(tls *libc.TLS, value uint8_t, predict uint8_t, boundary uint8_t, quantization int32) (r uint8_t) {
  29767 	var bias, boundary_residual, lower, residual, upper int32
  29768 	_, _, _, _, _ = bias, boundary_residual, lower, residual, upper
  29769 	residual = (libc.Int32FromUint8(value) - libc.Int32FromUint8(predict)) & int32(0xff)
  29770 	boundary_residual = (libc.Int32FromUint8(boundary) - libc.Int32FromUint8(predict)) & int32(0xff)
  29771 	lower = residual & ^(quantization - libc.Int32FromInt32(1))
  29772 	upper = lower + quantization
  29773 	// Resolve ties towards a value closer to the prediction (i.e. towards lower
  29774 	// if value comes after prediction and towards upper otherwise).
  29775 	bias = libc.BoolInt32((libc.Int32FromUint8(boundary)-libc.Int32FromUint8(value))&int32(0xff) < boundary_residual)
  29776 	if residual-lower < upper-residual+bias {
  29777 		// lower is closer to residual than upper.
  29778 		if residual > boundary_residual && lower <= boundary_residual {
  29779 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29780 			// on the same side of boundary as residual because midpoint >= residual
  29781 			// (since lower is closer than upper) and residual is above the boundary.
  29782 			return libc.Uint8FromInt32(lower + quantization>>int32(1))
  29783 		}
  29784 		return libc.Uint8FromInt32(lower)
  29785 	} else {
  29786 		// upper is closer to residual than lower.
  29787 		if residual <= boundary_residual && upper > boundary_residual {
  29788 			// Halve quantization step to avoid crossing boundary. This midpoint is
  29789 			// on the same side of boundary as residual because midpoint <= residual
  29790 			// (since upper is closer than lower) and residual is below the boundary.
  29791 			return libc.Uint8FromInt32(lower + quantization>>int32(1))
  29792 		}
  29793 		return libc.Uint8FromInt32(upper & int32(0xff))
  29794 	}
  29795 	return r
  29796 }
  29797 
  29798 func NearLosslessDiff(tls *libc.TLS, a uint8_t, b uint8_t) (r uint8_t) {
  29799 	return libc.Uint8FromInt32((libc.Int32FromUint8(a) - libc.Int32FromUint8(b)) & libc.Int32FromInt32(0xff))
  29800 }
  29801 
  29802 // C documentation
  29803 //
  29804 //	// Quantize every component of the difference between the actual pixel value and
  29805 //	// its prediction to a multiple of a quantization (a power of 2, not larger than
  29806 //	// max_quantization which is a power of 2, smaller than max_diff). Take care if
  29807 //	// value and predict have undergone subtract green, which means that red and
  29808 //	// blue are represented as offsets from green.
  29809 func NearLossless1(tls *libc.TLS, value uint32_t, predict uint32_t, max_quantization int32, max_diff int32, used_subtract_green int32) (r1 uint32_t) {
  29810 	var a1, b1, g, green_diff, new_green, r uint8_t
  29811 	var alpha_and_green, red_and_blue, v1, v2, v3 uint32_t
  29812 	var quantization int32
  29813 	_, _, _, _, _, _, _, _, _, _, _, _ = a1, alpha_and_green, b1, g, green_diff, new_green, quantization, r, red_and_blue, v1, v2, v3
  29814 	new_green = uint8(0)
  29815 	green_diff = uint8(0)
  29816 	if max_diff <= int32(2) {
  29817 		v1 = value
  29818 		v2 = predict
  29819 		alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  29820 		red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  29821 		v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29822 		goto _4
  29823 	_4:
  29824 		return v3
  29825 	}
  29826 	quantization = max_quantization
  29827 	for quantization >= max_diff {
  29828 		quantization = quantization >> int32(1)
  29829 	}
  29830 	if value>>libc.Int32FromInt32(24) == uint32(0) || value>>libc.Int32FromInt32(24) == uint32(0xff) {
  29831 		// Preserve transparency of fully transparent or fully opaque pixels.
  29832 		a1 = NearLosslessDiff(tls, uint8(value>>libc.Int32FromInt32(24)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(24)&uint32(0xff)))
  29833 	} else {
  29834 		a1 = NearLosslessComponent(tls, uint8(value>>int32(24)), uint8(predict>>int32(24)), uint8(0xff), quantization)
  29835 	}
  29836 	g = NearLosslessComponent(tls, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(predict>>libc.Int32FromInt32(8)&uint32(0xff)), uint8(0xff), quantization)
  29837 	if used_subtract_green != 0 {
  29838 		// The green offset will be added to red and blue components during decoding
  29839 		// to obtain the actual red and blue values.
  29840 		new_green = uint8((predict>>libc.Int32FromInt32(8) + uint32(g)) & uint32(0xff))
  29841 		// The amount by which green has been adjusted during quantization. It is
  29842 		// subtracted from red and blue for compensation, to avoid accumulating two
  29843 		// quantization errors in them.
  29844 		green_diff = NearLosslessDiff(tls, new_green, uint8(value>>libc.Int32FromInt32(8)&uint32(0xff)))
  29845 	}
  29846 	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)
  29847 	b1 = NearLosslessComponent(tls, NearLosslessDiff(tls, uint8(value&uint32(0xff)), green_diff), uint8(predict&uint32(0xff)), libc.Uint8FromInt32(int32(0xff)-libc.Int32FromUint8(new_green)), quantization)
  29848 	return uint32(a1)<<libc.Int32FromInt32(24) | uint32(r)<<libc.Int32FromInt32(16) | uint32(g)<<libc.Int32FromInt32(8) | uint32(b1)
  29849 }
  29850 
  29851 // C documentation
  29852 //
  29853 //	// Stores the difference between the pixel and its prediction in "out".
  29854 //	// In case of a lossy encoding, updates the source image to avoid propagating
  29855 //	// the deviation further to pixels which depend on the current pixel for their
  29856 //	// predictions.
  29857 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) {
  29858 	var alpha_and_green, alpha_and_green1, predict, red_and_blue, red_and_blue1, residual, v3, v4, v5 uint32_t
  29859 	var pred_func VP8LPredictorFunc
  29860 	var x int32
  29861 	var v2 uint32
  29862 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, alpha_and_green1, pred_func, predict, red_and_blue, red_and_blue1, residual, x, v2, v3, v4, v5
  29863 	if exact != 0 {
  29864 		PredictBatch(tls, mode, x_start, y, x_end-x_start, current_row, upper_row, out)
  29865 	} else {
  29866 		pred_func = VP8LPredictors[mode]
  29867 		x = x_start
  29868 		for {
  29869 			if !(x < x_end) {
  29870 				break
  29871 			}
  29872 			if y == 0 {
  29873 				if x == 0 {
  29874 					v2 = uint32(ARGB_BLACK1)
  29875 				} else {
  29876 					v2 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x-int32(1))*4))
  29877 				}
  29878 				predict = v2 // Left.
  29879 			} else {
  29880 				if x == 0 {
  29881 					predict = **(**uint32_t)(__ccgo_up(upper_row + uintptr(x)*4)) // Top.
  29882 				} else {
  29883 					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)
  29884 				}
  29885 			}
  29886 			if max_quantization == int32(1) || mode == 0 || y == 0 || y == height-int32(1) || x == 0 || x == width-int32(1) {
  29887 				v3 = **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))
  29888 				v4 = predict
  29889 				alpha_and_green1 = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  29890 				red_and_blue1 = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  29891 				v5 = alpha_and_green1&uint32(0xff00ff00) | red_and_blue1&uint32(0x00ff00ff)
  29892 				goto _6
  29893 			_6:
  29894 				residual = v5
  29895 			} else {
  29896 				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)
  29897 				// Update the source image.
  29898 				v3 = predict
  29899 				v4 = residual
  29900 				alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  29901 				red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  29902 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  29903 				goto _10
  29904 			_10:
  29905 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = v5
  29906 				// x is never 0 here so we do not need to update upper_row like below.
  29907 			}
  29908 			if **(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4))&kMaskAlpha == uint32(0) {
  29909 				// If alpha is 0, cleanup RGB. We can choose the RGB values of the
  29910 				// residual for best compression. The prediction of alpha itself can be
  29911 				// non-zero and must be kept though. We choose RGB of the residual to be
  29912 				// 0.
  29913 				residual = residual & kMaskAlpha
  29914 				// Update the source image.
  29915 				**(**uint32_t)(__ccgo_up(current_row + uintptr(x)*4)) = predict & ^kMaskAlpha
  29916 				// The prediction for the rightmost pixel in a row uses the leftmost
  29917 				// pixel
  29918 				// in that row as its top-right context pixel. Hence if we change the
  29919 				// leftmost pixel of current_row, the corresponding change must be
  29920 				// applied
  29921 				// to upper_row as well where top-right context is being read from.
  29922 				if x == 0 && y != 0 {
  29923 					**(**uint32_t)(__ccgo_up(upper_row + uintptr(width)*4)) = **(**uint32_t)(__ccgo_up(current_row))
  29924 				}
  29925 			}
  29926 			**(**uint32_t)(__ccgo_up(out + uintptr(x-x_start)*4)) = residual
  29927 			goto _1
  29928 		_1:
  29929 			;
  29930 			x = x + 1
  29931 		}
  29932 	}
  29933 }
  29934 
  29935 // C documentation
  29936 //
  29937 //	// Accessors to residual histograms.
  29938 func GetHistoArgb(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29939 	return all_histos + uintptr((subsampling_index*kNumPredModes+mode)*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29940 }
  29941 
  29942 func GetHistoArgbConst(tls *libc.TLS, all_histos uintptr, subsampling_index int32, mode int32) (r uintptr) {
  29943 	return all_histos + uintptr(subsampling_index*kNumPredModes*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256))+mode*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29944 }
  29945 
  29946 // C documentation
  29947 //
  29948 //	// Accessors to accumulated residual histogram.
  29949 func GetAccumulatedHisto(tls *libc.TLS, all_accumulated uintptr, subsampling_index int32) (r uintptr) {
  29950 	return all_accumulated + uintptr(subsampling_index*(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))*4
  29951 }
  29952 
  29953 // C documentation
  29954 //
  29955 //	// Find and store the best predictor for a tile at subsampling
  29956 //	// 'subsampling_index'.
  29957 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) {
  29958 	var above_mode, left_mode, mode int32
  29959 	var accumulated_argb, best_histo, histo_argb, modes, pred_histos uintptr
  29960 	var best_diff, cur_diff int64_t
  29961 	var best_mode uint32_t
  29962 	var v1, v2 uint32
  29963 	_, _, _, _, _, _, _, _, _, _, _, _, _ = above_mode, accumulated_argb, best_diff, best_histo, best_mode, cur_diff, histo_argb, left_mode, mode, modes, pred_histos, v1, v2
  29964 	accumulated_argb = GetAccumulatedHisto(tls, all_accumulated_argb, subsampling_index)
  29965 	modes = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  29966 	pred_histos = all_pred_histos + uintptr(subsampling_index*kNumPredModes)*4
  29967 	if tile_x > 0 {
  29968 		v1 = **(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x-int32(1))*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29969 	} else {
  29970 		v1 = uint32(0xff)
  29971 	}
  29972 	// Prediction modes of the left and above neighbor tiles.
  29973 	left_mode = libc.Int32FromUint32(v1)
  29974 	if tile_y > 0 {
  29975 		v2 = **(**uint32_t)(__ccgo_up(modes + uintptr((tile_y-int32(1))*tiles_per_row+tile_x)*4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  29976 	} else {
  29977 		v2 = uint32(0xff)
  29978 	}
  29979 	above_mode = libc.Int32FromUint32(v2)
  29980 	best_diff = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  29981 	best_mode = uint32(0)
  29982 	best_histo = GetHistoArgbConst(tls, all_argb, 0, libc.Int32FromUint32(best_mode))
  29983 	mode = 0
  29984 	for {
  29985 		if !(mode < kNumPredModes) {
  29986 			break
  29987 		}
  29988 		histo_argb = GetHistoArgbConst(tls, all_argb, subsampling_index, mode)
  29989 		cur_diff = PredictionCostSpatialHistogram(tls, accumulated_argb, histo_argb, mode, left_mode, above_mode)
  29990 		if cur_diff < best_diff {
  29991 			best_histo = histo_argb
  29992 			best_diff = cur_diff
  29993 			best_mode = libc.Uint32FromInt32(mode)
  29994 		}
  29995 		goto _3
  29996 	_3:
  29997 		;
  29998 		mode = mode + 1
  29999 	}
  30000 	// Update the accumulated histogram.
  30001 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LAddVectorEq})))(tls, best_histo, accumulated_argb, libc.Int32FromInt32(4)*libc.Int32FromInt32(256))
  30002 	**(**uint32_t)(__ccgo_up(modes + uintptr(tile_y*tiles_per_row+tile_x)*4)) = uint32(ARGB_BLACK1) | best_mode<<libc.Int32FromInt32(8)
  30003 	**(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) = **(**uint32_t)(__ccgo_up(pred_histos + uintptr(best_mode)*4)) + 1
  30004 }
  30005 
  30006 // C documentation
  30007 //
  30008 //	// Computes the residuals for the different predictors.
  30009 //	// If max_quantization > 1, assumes that near lossless processing will be
  30010 //	// applied, quantizing residuals to multiples of quantization levels up to
  30011 //	// max_quantization (the actual quantization level depends on smoothness near
  30012 //	// the given pixel).
  30013 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) {
  30014 	bp := tls.Alloc(2048)
  30015 	defer tls.Free(2048)
  30016 	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
  30017 	var current_row, histo_argb, max_diffs, super_histo, tmp, upper_row uintptr
  30018 	var subsampling_index uint32_t
  30019 	var _ /* residuals at bp+0 */ [512]uint32_t
  30020 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30021 	start_x = tile_x << min_bits
  30022 	start_y = tile_y << min_bits
  30023 	tile_size = int32(1) << min_bits
  30024 	max_y = GetMin(tls, tile_size, height-start_y)
  30025 	max_x = GetMin(tls, tile_size, width-start_x)
  30026 	// Whether there exist columns just outside the tile.
  30027 	have_left = libc.BoolInt32(start_x > libc.Int32FromInt32(0))
  30028 	// Position and size of the strip covering the tile and adjacent columns if
  30029 	// they exist.
  30030 	context_start_x = start_x - have_left
  30031 	context_width = max_x + have_left + libc.BoolInt32(max_x < width-start_x)
  30032 	// The width of upper_row and current_row is one pixel larger than image width
  30033 	// to allow the top right pixel to point to the leftmost pixel of the next row
  30034 	// when at the right edge.
  30035 	upper_row = argb_scratch
  30036 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  30037 	max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  30038 	mode = 0
  30039 	for {
  30040 		if !(mode < kNumPredModes) {
  30041 			break
  30042 		}
  30043 		histo_argb = GetHistoArgb(tls, all_argb, 0, mode)
  30044 		if start_y > 0 {
  30045 			// Read the row above the tile which will become the first upper_row.
  30046 			// Include a pixel to the left if it exists; include a pixel to the right
  30047 			// in all cases (wrapping to the leftmost pixel of the next row if it does
  30048 			// not exist).
  30049 			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)))
  30050 		}
  30051 		relative_y = 0
  30052 		for {
  30053 			if !(relative_y < max_y) {
  30054 				break
  30055 			}
  30056 			y = start_y + relative_y
  30057 			tmp = upper_row
  30058 			upper_row = current_row
  30059 			current_row = tmp
  30060 			// Read current_row. Include a pixel to the left if it exists; include a
  30061 			// pixel to the right in all cases except at the bottom right corner of
  30062 			// the image (wrapping to the leftmost pixel of the next row if it does
  30063 			// not exist in the current row).
  30064 			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)))
  30065 			if max_quantization > int32(1) && y >= int32(1) && y+int32(1) < height {
  30066 				MaxDiffsForRow(tls, context_width, width, argb+uintptr(y*width)*4+uintptr(context_start_x)*4, max_diffs+uintptr(context_start_x), used_subtract_green)
  30067 			}
  30068 			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)
  30069 			relative_x = 0
  30070 			for {
  30071 				if !(relative_x < max_x) {
  30072 					break
  30073 				}
  30074 				UpdateHisto(tls, histo_argb, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  30075 				goto _3
  30076 			_3:
  30077 				;
  30078 				relative_x = relative_x + 1
  30079 			}
  30080 			if update_up_to_index > uint32(0) {
  30081 				subsampling_index = uint32(1)
  30082 				for {
  30083 					if !(subsampling_index <= update_up_to_index) {
  30084 						break
  30085 					}
  30086 					super_histo = GetHistoArgb(tls, all_argb, libc.Int32FromUint32(subsampling_index), mode)
  30087 					relative_x = 0
  30088 					for {
  30089 						if !(relative_x < max_x) {
  30090 							break
  30091 						}
  30092 						UpdateHisto(tls, super_histo, (**(**[512]uint32_t)(__ccgo_up(bp)))[relative_x])
  30093 						goto _5
  30094 					_5:
  30095 						;
  30096 						relative_x = relative_x + 1
  30097 					}
  30098 					goto _4
  30099 				_4:
  30100 					;
  30101 					subsampling_index = subsampling_index + 1
  30102 				}
  30103 			}
  30104 			goto _2
  30105 		_2:
  30106 			;
  30107 			relative_y = relative_y + 1
  30108 		}
  30109 		goto _1
  30110 	_1:
  30111 		;
  30112 		mode = mode + 1
  30113 	}
  30114 }
  30115 
  30116 // C documentation
  30117 //
  30118 //	// Converts pixels of the image to residuals with respect to predictions.
  30119 //	// If max_quantization > 1, applies near lossless processing, quantizing
  30120 //	// residuals to multiples of quantization levels up to max_quantization
  30121 //	// (the actual quantization level depends on smoothness near the given pixel).
  30122 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) {
  30123 	var current_max_diffs, current_row, lower_max_diffs, tmp32, tmp8, upper_row uintptr
  30124 	var mode, tiles_per_row, x, x_end, y int32
  30125 	var v1, v2 uint32_t
  30126 	_, _, _, _, _, _, _, _, _, _, _, _, _ = current_max_diffs, current_row, lower_max_diffs, mode, tiles_per_row, tmp32, tmp8, upper_row, x, x_end, y, v1, v2
  30127 	v1 = libc.Uint32FromInt32(bits)
  30128 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30129 	goto _3
  30130 _3:
  30131 	tiles_per_row = libc.Int32FromUint32(v2)
  30132 	// The width of upper_row and current_row is one pixel larger than image width
  30133 	// to allow the top right pixel to point to the leftmost pixel of the next row
  30134 	// when at the right edge.
  30135 	upper_row = argb_scratch
  30136 	current_row = upper_row + uintptr(width)*4 + uintptr(1)*4
  30137 	current_max_diffs = current_row + uintptr(width)*4 + libc.UintptrFromInt32(1)*4
  30138 	lower_max_diffs = current_max_diffs + uintptr(width)
  30139 	y = 0
  30140 	for {
  30141 		if !(y < height) {
  30142 			break
  30143 		}
  30144 		tmp32 = upper_row
  30145 		upper_row = current_row
  30146 		current_row = tmp32
  30147 		libc.Xmemcpy(tls, current_row, argb+uintptr(y*width)*4, uint64(4)*libc.Uint64FromInt32(width+libc.BoolInt32(y+libc.Int32FromInt32(1) < height)))
  30148 		if low_effort != 0 {
  30149 			PredictBatch(tls, kPredLowEffort, 0, y, width, current_row, upper_row, argb+uintptr(y*width)*4)
  30150 		} else {
  30151 			if max_quantization > int32(1) {
  30152 				// Compute max_diffs for the lower row now, because that needs the
  30153 				// contents of argb for the current row, which we will overwrite with
  30154 				// residuals before proceeding with the next row.
  30155 				tmp8 = current_max_diffs
  30156 				current_max_diffs = lower_max_diffs
  30157 				lower_max_diffs = tmp8
  30158 				if y+int32(2) < height {
  30159 					MaxDiffsForRow(tls, width, width, argb+uintptr((y+int32(1))*width)*4, lower_max_diffs, used_subtract_green)
  30160 				}
  30161 			}
  30162 			x = 0
  30163 			for {
  30164 				if !(x < width) {
  30165 					break
  30166 				}
  30167 				mode = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(modes + uintptr(y>>bits*tiles_per_row+x>>bits)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  30168 				x_end = x + int32(1)<<bits
  30169 				if x_end > width {
  30170 					x_end = width
  30171 				}
  30172 				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)
  30173 				x = x_end
  30174 				goto _5
  30175 			_5:
  30176 			}
  30177 		}
  30178 		goto _4
  30179 	_4:
  30180 		;
  30181 		y = y + 1
  30182 	}
  30183 }
  30184 
  30185 // C documentation
  30186 //
  30187 //	// Checks whether 'image' can be subsampled by finding the biggest power of 2
  30188 //	// squares (defined by 'best_bits') of uniform value it is made out of.
  30189 func VP8LOptimizeSampling(tls *libc.TLS, image uintptr, full_width int32, full_height int32, bits int32, max_bits int32, best_bits_out uintptr) {
  30190 	var best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y int32
  30191 	var v1, v2, v4, v5 uint32_t
  30192 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_bits, height, i, is_good, is_good1, new_square_size, old_width, square_size, width, x, y, v1, v2, v4, v5
  30193 	v1 = libc.Uint32FromInt32(bits)
  30194 	v2 = (libc.Uint32FromInt32(full_width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30195 	goto _3
  30196 _3:
  30197 	width = libc.Int32FromUint32(v2)
  30198 	v4 = libc.Uint32FromInt32(bits)
  30199 	v5 = (libc.Uint32FromInt32(full_height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30200 	goto _6
  30201 _6:
  30202 	height = libc.Int32FromUint32(v5)
  30203 	best_bits = bits
  30204 	**(**int32)(__ccgo_up(best_bits_out)) = bits
  30205 	// Check rows first.
  30206 	for best_bits < max_bits {
  30207 		new_square_size = int32(1) << (best_bits + int32(1) - bits)
  30208 		is_good = int32(1)
  30209 		square_size = int32(1) << (best_bits - bits)
  30210 		y = 0
  30211 		for {
  30212 			if !(y+square_size < height) {
  30213 				break
  30214 			}
  30215 			// Check the first lines of consecutive line groups.
  30216 			if libc.Xmemcmp(tls, image+uintptr(y*width)*4, image+uintptr((y+square_size)*width)*4, libc.Uint64FromInt32(width)*uint64(4)) != 0 {
  30217 				is_good = 0
  30218 				break
  30219 			}
  30220 			goto _7
  30221 		_7:
  30222 			;
  30223 			y = y + new_square_size
  30224 		}
  30225 		if is_good != 0 {
  30226 			best_bits = best_bits + 1
  30227 		} else {
  30228 			break
  30229 		}
  30230 	}
  30231 	if best_bits == bits {
  30232 		return
  30233 	}
  30234 	// Check columns.
  30235 	for best_bits > bits {
  30236 		is_good1 = int32(1)
  30237 		square_size = int32(1) << (best_bits - bits)
  30238 		y = 0
  30239 		for {
  30240 			if !(is_good1 != 0 && y < height) {
  30241 				break
  30242 			}
  30243 			x = 0
  30244 			for {
  30245 				if !(is_good1 != 0 && x < width) {
  30246 					break
  30247 				}
  30248 				i = x + int32(1)
  30249 				for {
  30250 					if !(i < GetMin(tls, x+square_size, width)) {
  30251 						break
  30252 					}
  30253 					if **(**uint32_t)(__ccgo_up(image + uintptr(y*width+i)*4)) != **(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) {
  30254 						is_good1 = 0
  30255 						break
  30256 					}
  30257 					goto _10
  30258 				_10:
  30259 					;
  30260 					i = i + 1
  30261 				}
  30262 				goto _9
  30263 			_9:
  30264 				;
  30265 				x = x + square_size
  30266 			}
  30267 			goto _8
  30268 		_8:
  30269 			;
  30270 			y = y + 1
  30271 		}
  30272 		if is_good1 != 0 {
  30273 			break
  30274 		}
  30275 		best_bits = best_bits - 1
  30276 	}
  30277 	if best_bits == bits {
  30278 		return
  30279 	}
  30280 	// Subsample the image.
  30281 	old_width = width
  30282 	square_size = int32(1) << (best_bits - bits)
  30283 	v1 = libc.Uint32FromInt32(best_bits)
  30284 	v2 = (libc.Uint32FromInt32(full_width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30285 	goto _13
  30286 _13:
  30287 	width = libc.Int32FromUint32(v2)
  30288 	v1 = libc.Uint32FromInt32(best_bits)
  30289 	v2 = (libc.Uint32FromInt32(full_height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30290 	goto _16
  30291 _16:
  30292 	height = libc.Int32FromUint32(v2)
  30293 	y = 0
  30294 	for {
  30295 		if !(y < height) {
  30296 			break
  30297 		}
  30298 		x = 0
  30299 		for {
  30300 			if !(x < width) {
  30301 				break
  30302 			}
  30303 			**(**uint32_t)(__ccgo_up(image + uintptr(y*width+x)*4)) = **(**uint32_t)(__ccgo_up(image + uintptr(square_size*(y*old_width+x))*4))
  30304 			goto _18
  30305 		_18:
  30306 			;
  30307 			x = x + 1
  30308 		}
  30309 		goto _17
  30310 	_17:
  30311 		;
  30312 		y = y + 1
  30313 	}
  30314 	**(**int32)(__ccgo_up(best_bits_out)) = best_bits
  30315 }
  30316 
  30317 // C documentation
  30318 //
  30319 //	// Computes the best predictor image.
  30320 //	// Finds the best predictors per tile. Once done, finds the best predictor image
  30321 //	// sampling.
  30322 //	// best_bits is set to 0 in case of error.
  30323 //	// The following requires some glossary:
  30324 //	// - a tile is a square of side 2^min_bits pixels.
  30325 //	// - a super-tile of a tile is a square of side 2^bits pixels with bits in
  30326 //	// [min_bits+1, max_bits].
  30327 //	// - the max-tile of a tile is the square of 2^max_bits pixels containing it.
  30328 //	//   If this max-tile crosses the border of an image, it is cropped.
  30329 //	// - tile, super-tiles and max_tile are aligned on powers of 2 in the original
  30330 //	//   image.
  30331 //	// - coordinates for tile, super-tile, max-tile are respectively named
  30332 //	//   tile_x, super_tile_x, max_tile_x at their bit scale.
  30333 //	// - in the max-tile, a tile has local coordinates (local_tile_x, local_tile_y).
  30334 //	// The tiles are processed in the following zigzag order to complete the
  30335 //	// super-tiles as soon as possible:
  30336 //	//   1  2|  5  6
  30337 //	//   3  4|  7  8
  30338 //	// --------------
  30339 //	//   9 10| 13 14
  30340 //	//  11 12| 15 16
  30341 //	// When computing the residuals for a tile, the histogram of the above
  30342 //	// super-tile is updated. If this super-tile is finished, its histogram is used
  30343 //	// to update the histogram of the next super-tile and so on up to the max-tile.
  30344 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) {
  30345 	var accumulated, all_accumulated_argb, all_argb, all_pred_histos, raw_data uintptr
  30346 	var best_cost, cost int64_t
  30347 	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
  30348 	var max_tile_size, num_accumulated_rgb, num_argb, num_predictors, percent_start, plane int32
  30349 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30350 	v1 = libc.Uint32FromInt32(min_bits)
  30351 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30352 	goto _3
  30353 _3:
  30354 	tiles_per_row = v2
  30355 	v4 = libc.Uint32FromInt32(min_bits)
  30356 	v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30357 	goto _6
  30358 _6:
  30359 	tiles_per_col = v5
  30360 	max_subsampling_index = libc.Uint32FromInt32(max_bits - min_bits)
  30361 	// Compute the needed memory size for residual histograms, accumulated
  30362 	// residual histograms and predictor histograms.
  30363 	num_argb = libc.Int32FromUint32((max_subsampling_index + uint32(1)) * libc.Uint32FromInt32(kNumPredModes) * libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30364 	num_accumulated_rgb = libc.Int32FromUint32((max_subsampling_index + uint32(1)) * libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)))
  30365 	num_predictors = libc.Int32FromUint32((max_subsampling_index + uint32(1)) * libc.Uint32FromInt32(kNumPredModes))
  30366 	raw_data = WebPSafeCalloc(tls, libc.Uint64FromInt32(num_argb+num_accumulated_rgb+num_predictors), uint64(4))
  30367 	all_argb = raw_data
  30368 	all_accumulated_argb = all_argb + uintptr(num_argb)*4
  30369 	all_pred_histos = all_accumulated_argb + uintptr(num_accumulated_rgb)*4
  30370 	max_tile_size = int32(1) << max_subsampling_index // in tile size
  30371 	percent_start = **(**int32)(__ccgo_up(percent))
  30372 	// When using the residuals of a tile for its super-tiles, you can either:
  30373 	// - use each residual to update the histogram of the super-tile, with a cost
  30374 	//   of 4 * (1<<n)^2 increment operations (4 for the number of channels, and
  30375 	//   (1<<n)^2 for the number of pixels in the tile)
  30376 	// - use the histogram of the tile to update the histogram of the super-tile,
  30377 	//   with a cost of HISTO_SIZE (1024)
  30378 	// The first method is therefore faster until n==4. 'update_up_to_index'
  30379 	// defines the maximum subsampling_index for which the residuals should be
  30380 	// individually added to the super-tile histogram.
  30381 	update_up_to_index = libc.Uint32FromInt32(GetMax(tls, GetMin(tls, int32(4), max_bits), min_bits) - min_bits)
  30382 	// Coordinates in the max-tile in tile units.
  30383 	local_tile_x = uint32(0)
  30384 	local_tile_y = uint32(0)
  30385 	max_tile_x = uint32(0)
  30386 	max_tile_y = uint32(0)
  30387 	tile_x = uint32(0)
  30388 	tile_y = uint32(0)
  30389 	**(**int32)(__ccgo_up(best_bits)) = 0
  30390 	**(**uintptr)(__ccgo_up(best_mode)) = libc.UintptrFromInt32(0)
  30391 	if raw_data == libc.UintptrFromInt32(0) {
  30392 		return
  30393 	}
  30394 	for tile_y < tiles_per_col {
  30395 		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)
  30396 		// Update all the super-tiles that are complete.
  30397 		subsampling_index = uint32(0)
  30398 		for int32(1) != 0 {
  30399 			super_tile_x = tile_x >> subsampling_index
  30400 			super_tile_y = tile_y >> subsampling_index
  30401 			v1 = libc.Uint32FromInt32(min_bits) + subsampling_index
  30402 			v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30403 			goto _9
  30404 		_9:
  30405 			super_tiles_per_row = v2
  30406 			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)
  30407 			if subsampling_index == max_subsampling_index {
  30408 				break
  30409 			}
  30410 			// Update the following super-tile histogram if it has not been updated
  30411 			// yet.
  30412 			subsampling_index = subsampling_index + 1
  30413 			if subsampling_index > update_up_to_index && subsampling_index <= max_subsampling_index {
  30414 				(*(*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)
  30415 			}
  30416 			// Check whether the super-tile is not complete (if the smallest tile
  30417 			// is not at the end of a line/column or at the beginning of a super-tile
  30418 			// of size (1 << subsampling_index)).
  30419 			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))) {
  30420 				subsampling_index = subsampling_index - 1
  30421 				// subsampling_index now is the index of the last finished super-tile.
  30422 				break
  30423 			}
  30424 		}
  30425 		// Reset all the histograms belonging to finished tiles.
  30426 		libc.Xmemset(tls, all_argb, 0, uint64(libc.Uint32FromInt32(libc.Int32FromInt32(4)*libc.Int32FromInt32(256)*kNumPredModes)*(subsampling_index+uint32(1)))*uint64(4))
  30427 		if subsampling_index == max_subsampling_index {
  30428 			// If a new max-tile is started.
  30429 			if tile_x == tiles_per_row-uint32(1) {
  30430 				max_tile_x = uint32(0)
  30431 				max_tile_y = max_tile_y + 1
  30432 			} else {
  30433 				max_tile_x = max_tile_x + 1
  30434 			}
  30435 			local_tile_x = uint32(0)
  30436 			local_tile_y = uint32(0)
  30437 		} else {
  30438 			// Proceed with the Z traversal.
  30439 			coord_x = local_tile_x >> subsampling_index
  30440 			coord_y = local_tile_y >> subsampling_index
  30441 			if tile_x == tiles_per_row-uint32(1) && coord_x%uint32(2) == uint32(0) {
  30442 				coord_y = coord_y + 1
  30443 			} else {
  30444 				if coord_x%uint32(2) == uint32(0) {
  30445 					coord_x = coord_x + 1
  30446 				} else {
  30447 					// Z traversal.
  30448 					coord_y = coord_y + 1
  30449 					coord_x = coord_x - 1
  30450 				}
  30451 			}
  30452 			local_tile_x = coord_x << subsampling_index
  30453 			local_tile_y = coord_y << subsampling_index
  30454 		}
  30455 		tile_x = max_tile_x*libc.Uint32FromInt32(max_tile_size) + local_tile_x
  30456 		tile_y = max_tile_y*libc.Uint32FromInt32(max_tile_size) + local_tile_y
  30457 		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) {
  30458 			WebPSafeFree(tls, raw_data)
  30459 			return
  30460 		}
  30461 	}
  30462 	// Figure out the best sampling.
  30463 	best_cost = libc.Int64FromUint64(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(63) - libc.Uint64FromInt32(1))
  30464 	subsampling_index = uint32(0)
  30465 	for {
  30466 		if !(subsampling_index <= max_subsampling_index) {
  30467 			break
  30468 		}
  30469 		accumulated = GetAccumulatedHisto(tls, all_accumulated_argb, libc.Int32FromUint32(subsampling_index))
  30470 		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))
  30471 		plane = 0
  30472 		for {
  30473 			if !(plane < int32(4)) {
  30474 				break
  30475 			}
  30476 			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)))
  30477 			goto _11
  30478 		_11:
  30479 			;
  30480 			plane = plane + 1
  30481 		}
  30482 		if cost < best_cost {
  30483 			best_cost = cost
  30484 			**(**int32)(__ccgo_up(best_bits)) = libc.Int32FromUint32(libc.Uint32FromInt32(min_bits) + subsampling_index)
  30485 			**(**uintptr)(__ccgo_up(best_mode)) = **(**uintptr)(__ccgo_up(all_modes + uintptr(subsampling_index)*8))
  30486 		}
  30487 		goto _10
  30488 	_10:
  30489 		;
  30490 		subsampling_index = subsampling_index + 1
  30491 	}
  30492 	WebPSafeFree(tls, raw_data)
  30493 	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)
  30494 }
  30495 
  30496 // C documentation
  30497 //
  30498 //	// Finds the best predictor for each tile, and converts the image to residuals
  30499 //	// with respect to predictions. If near_lossless_quality < 100, applies
  30500 //	// near lossless processing, shaving off more bits of residuals for lower
  30501 //	// qualities.
  30502 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) {
  30503 	bp := tls.Alloc(96)
  30504 	defer tls.Free(96)
  30505 	var bits, i, max_quantization, percent_start, tiles_per_col, tiles_per_col1, tiles_per_row, tiles_per_row1, v1 int32
  30506 	var modes_raw uintptr
  30507 	var num_pixels [10]uint32_t
  30508 	var sum_num_pixels, v3, v4, v6, v7 uint32_t
  30509 	var _ /* best_mode at bp+0 */ uintptr
  30510 	var _ /* modes at bp+8 */ [10]uintptr
  30511 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30512 	percent_start = **(**int32)(__ccgo_up(percent))
  30513 	v1 = int32(5) - near_lossless_quality1/int32(20)
  30514 	goto _2
  30515 _2:
  30516 	max_quantization = int32(1) << v1
  30517 	if low_effort != 0 {
  30518 		v3 = libc.Uint32FromInt32(max_bits)
  30519 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30520 		goto _5
  30521 	_5:
  30522 		tiles_per_row = libc.Int32FromUint32(v4)
  30523 		v6 = libc.Uint32FromInt32(max_bits)
  30524 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30525 		goto _8
  30526 	_8:
  30527 		tiles_per_col = libc.Int32FromUint32(v7)
  30528 		i = 0
  30529 		for {
  30530 			if !(i < tiles_per_row*tiles_per_col) {
  30531 				break
  30532 			}
  30533 			**(**uint32_t)(__ccgo_up(image + uintptr(i)*4)) = uint32(ARGB_BLACK1) | libc.Uint32FromInt32(kPredLowEffort<<libc.Int32FromInt32(8))
  30534 			goto _9
  30535 		_9:
  30536 			;
  30537 			i = i + 1
  30538 		}
  30539 		**(**int32)(__ccgo_up(best_bits)) = max_bits
  30540 	} else {
  30541 		sum_num_pixels = 0
  30542 		bits = min_bits
  30543 		for {
  30544 			if !(bits <= max_bits) {
  30545 				break
  30546 			}
  30547 			v3 = libc.Uint32FromInt32(bits)
  30548 			v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30549 			goto _13
  30550 		_13:
  30551 			tiles_per_row1 = libc.Int32FromUint32(v4)
  30552 			v6 = libc.Uint32FromInt32(bits)
  30553 			v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30554 			goto _16
  30555 		_16:
  30556 			tiles_per_col1 = libc.Int32FromUint32(v7)
  30557 			num_pixels[bits] = libc.Uint32FromInt32(tiles_per_row1 * tiles_per_col1)
  30558 			sum_num_pixels = sum_num_pixels + num_pixels[bits]
  30559 			goto _10
  30560 		_10:
  30561 			;
  30562 			bits = bits + 1
  30563 		}
  30564 		modes_raw = WebPSafeMalloc(tls, uint64(sum_num_pixels), uint64(4))
  30565 		if modes_raw == libc.UintptrFromInt32(0) {
  30566 			return 0
  30567 		}
  30568 		// Have modes point to the right global memory modes_raw.
  30569 		(**(**[10]uintptr)(__ccgo_up(bp + 8)))[min_bits] = modes_raw
  30570 		bits = min_bits + int32(1)
  30571 		for {
  30572 			if !(bits <= max_bits) {
  30573 				break
  30574 			}
  30575 			(**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits] = (**(**[10]uintptr)(__ccgo_up(bp + 8)))[bits-int32(1)] + uintptr(num_pixels[bits-int32(1)])*4
  30576 			goto _17
  30577 		_17:
  30578 			;
  30579 			bits = bits + 1
  30580 		}
  30581 		// Find the best sampling.
  30582 		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)
  30583 		if **(**int32)(__ccgo_up(best_bits)) == 0 {
  30584 			WebPSafeFree(tls, modes_raw)
  30585 			return 0
  30586 		}
  30587 		// Keep the best predictor image.
  30588 		v3 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  30589 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  30590 		goto _20
  30591 	_20:
  30592 		v6 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  30593 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  30594 		goto _23
  30595 	_23:
  30596 		libc.Xmemcpy(tls, image, **(**uintptr)(__ccgo_up(bp)), uint64(v4*v7)*uint64(4))
  30597 		WebPSafeFree(tls, modes_raw)
  30598 	}
  30599 	CopyImageWithPrediction(tls, width, height, **(**int32)(__ccgo_up(best_bits)), image, argb_scratch, argb, low_effort, max_quantization, exact, used_subtract_green)
  30600 	return WebPReportProgress(tls, pic, percent_start+percent_range, percent)
  30601 }
  30602 
  30603 //------------------------------------------------------------------------------
  30604 // Color transform functions.
  30605 
  30606 func MultipliersClear(tls *libc.TLS, m uintptr) {
  30607 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(0)
  30608 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(0)
  30609 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(0)
  30610 }
  30611 
  30612 func ColorCodeToMultipliers(tls *libc.TLS, color_code uint32_t, m uintptr) {
  30613 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  30614 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  30615 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  30616 }
  30617 
  30618 func MultipliersToColorCode(tls *libc.TLS, m uintptr) (r uint32_t) {
  30619 	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)
  30620 }
  30621 
  30622 func PredictionCostCrossColor(tls *libc.TLS, accumulated uintptr, counts uintptr) (r int64_t) {
  30623 	return libc.Int64FromUint64((*(*func(*libc.TLS, uintptr, uintptr) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LCombinedShannonEntropy})))(tls, counts, accumulated)) + PredictionCostBias(tls, counts, uint64(3), kExpValue)
  30624 }
  30625 
  30626 // Favor low entropy, locally and globally.
  30627 // Favor small absolute values for PredictionCostSpatial
  30628 var kExpValue = uint64(240)
  30629 
  30630 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) {
  30631 	bp := tls.Alloc(1024)
  30632 	defer tls.Free(1024)
  30633 	var cur_diff int64_t
  30634 	var _ /* histo at bp+0 */ [256]uint32_t
  30635 	_ = cur_diff
  30636 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30637 	(*(*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)
  30638 	cur_diff = PredictionCostCrossColor(tls, accumulated_red_histo, bp)
  30639 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_red)) == libc.Int32FromUint8(prev_x.Fgreen_to_red) {
  30640 		// favor keeping the areas locally similar
  30641 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30642 	}
  30643 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_red)) == libc.Int32FromUint8(prev_y.Fgreen_to_red) {
  30644 		// favor keeping the areas locally similar
  30645 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30646 	}
  30647 	if green_to_red == 0 {
  30648 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30649 	}
  30650 	return cur_diff
  30651 }
  30652 
  30653 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) {
  30654 	var best_diff, cur_diff int64_t
  30655 	var delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset int32
  30656 	_, _, _, _, _, _, _, _ = best_diff, cur_diff, delta, green_to_red_best, green_to_red_cur, iter, kMaxIters, offset
  30657 	kMaxIters = int32(4) + int32(7)*quality>>int32(8) // in range [4..6]
  30658 	green_to_red_best = 0
  30659 	best_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_best, accumulated_red_histo)
  30660 	iter = 0
  30661 	for {
  30662 		if !(iter < kMaxIters) {
  30663 			break
  30664 		}
  30665 		// ColorTransformDelta is a 3.5 bit fixed point, so 32 is equal to
  30666 		// one in color computation. Having initial delta here as 1 is sufficient
  30667 		// to explore the range of (-2, 2).
  30668 		delta = int32(32) >> iter
  30669 		// Try a negative and a positive delta from the best known value.
  30670 		offset = -delta
  30671 		for {
  30672 			if !(offset <= delta) {
  30673 				break
  30674 			}
  30675 			green_to_red_cur = offset + green_to_red_best
  30676 			cur_diff = GetPredictionCostCrossColorRed(tls, argb, stride, tile_width, tile_height, prev_x, prev_y, green_to_red_cur, accumulated_red_histo)
  30677 			if cur_diff < best_diff {
  30678 				best_diff = cur_diff
  30679 				green_to_red_best = green_to_red_cur
  30680 			}
  30681 			goto _2
  30682 		_2:
  30683 			;
  30684 			offset = offset + int32(2)*delta
  30685 		}
  30686 		goto _1
  30687 	_1:
  30688 		;
  30689 		iter = iter + 1
  30690 	}
  30691 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_red = libc.Uint8FromInt32(green_to_red_best & libc.Int32FromInt32(0xff))
  30692 }
  30693 
  30694 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) {
  30695 	bp := tls.Alloc(1024)
  30696 	defer tls.Free(1024)
  30697 	var cur_diff int64_t
  30698 	var _ /* histo at bp+0 */ [256]uint32_t
  30699 	_ = cur_diff
  30700 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30701 	(*(*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)
  30702 	cur_diff = PredictionCostCrossColor(tls, accumulated_blue_histo, bp)
  30703 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_blue)) == libc.Int32FromUint8(prev_x.Fgreen_to_blue) {
  30704 		// favor keeping the areas locally similar
  30705 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30706 	}
  30707 	if libc.Int32FromUint8(libc.Uint8FromInt32(green_to_blue)) == libc.Int32FromUint8(prev_y.Fgreen_to_blue) {
  30708 		// favor keeping the areas locally similar
  30709 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30710 	}
  30711 	if libc.Int32FromUint8(libc.Uint8FromInt32(red_to_blue)) == libc.Int32FromUint8(prev_x.Fred_to_blue) {
  30712 		// favor keeping the areas locally similar
  30713 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30714 	}
  30715 	if libc.Int32FromUint8(libc.Uint8FromInt32(red_to_blue)) == libc.Int32FromUint8(prev_y.Fred_to_blue) {
  30716 		// favor keeping the areas locally similar
  30717 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30718 	}
  30719 	if green_to_blue == 0 {
  30720 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30721 	}
  30722 	if red_to_blue == 0 {
  30723 		cur_diff = int64(cur_diff - libc.Int64FromInt64(3)<<libc.Int32FromInt32(LOG_2_PRECISION_BITS))
  30724 	}
  30725 	return cur_diff
  30726 }
  30727 
  30728 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) {
  30729 	bp := tls.Alloc(16)
  30730 	defer tls.Free(16)
  30731 	var axis, delta, green_to_blue_best, green_to_blue_cur, iter, iters, red_to_blue_best, red_to_blue_cur, v1, v2 int32
  30732 	var best_diff, cur_diff int64_t
  30733 	var delta_lut [7]int8_t
  30734 	var _ /* offset at bp+0 */ [8][2]int8_t
  30735 	_, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30736 	**(**[8][2]int8_t)(__ccgo_up(bp)) = [8][2]int8_t{
  30737 		0: {
  30738 			1: int8(-int32(1)),
  30739 		},
  30740 		1: {
  30741 			1: int8(1),
  30742 		},
  30743 		2: {
  30744 			0: int8(-int32(1)),
  30745 		},
  30746 		3: {
  30747 			0: int8(1),
  30748 		},
  30749 		4: {
  30750 			0: int8(-int32(1)),
  30751 			1: int8(-int32(1)),
  30752 		},
  30753 		5: {
  30754 			0: int8(-int32(1)),
  30755 			1: int8(1),
  30756 		},
  30757 		6: {
  30758 			0: int8(1),
  30759 			1: int8(-int32(1)),
  30760 		},
  30761 		7: {
  30762 			0: int8(1),
  30763 			1: int8(1),
  30764 		},
  30765 	}
  30766 	delta_lut = [7]int8_t{
  30767 		0: int8(16),
  30768 		1: int8(16),
  30769 		2: int8(8),
  30770 		3: int8(4),
  30771 		4: int8(2),
  30772 		5: int8(2),
  30773 		6: int8(2),
  30774 	}
  30775 	if quality < int32(25) {
  30776 		v1 = int32(1)
  30777 	} else {
  30778 		if quality > int32(50) {
  30779 			v2 = int32(7)
  30780 		} else {
  30781 			v2 = int32(4)
  30782 		}
  30783 		v1 = v2
  30784 	}
  30785 	iters = v1
  30786 	green_to_blue_best = 0
  30787 	red_to_blue_best = 0
  30788 	// Initial value at origin:
  30789 	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)
  30790 	iter = 0
  30791 	for {
  30792 		if !(iter < iters) {
  30793 			break
  30794 		}
  30795 		delta = int32(delta_lut[iter])
  30796 		axis = 0
  30797 		for {
  30798 			if !(axis < int32(8)) {
  30799 				break
  30800 			}
  30801 			green_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2)))*delta + green_to_blue_best
  30802 			red_to_blue_cur = int32(**(**int8_t)(__ccgo_up(bp + uintptr(axis)*2 + 1)))*delta + red_to_blue_best
  30803 			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)
  30804 			if cur_diff < best_diff {
  30805 				best_diff = cur_diff
  30806 				green_to_blue_best = green_to_blue_cur
  30807 				red_to_blue_best = red_to_blue_cur
  30808 			}
  30809 			if quality < int32(25) && iter == int32(4) {
  30810 				// Only axis aligned diffs for lower quality.
  30811 				break // next iter.
  30812 			}
  30813 			goto _4
  30814 		_4:
  30815 			;
  30816 			axis = axis + 1
  30817 		}
  30818 		if delta == int32(2) && green_to_blue_best == 0 && red_to_blue_best == 0 {
  30819 			// Further iterations would not help.
  30820 			break // out of iter-loop.
  30821 		}
  30822 		goto _3
  30823 	_3:
  30824 		;
  30825 		iter = iter + 1
  30826 	}
  30827 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fgreen_to_blue = libc.Uint8FromInt32(green_to_blue_best & int32(0xff))
  30828 	(*VP8LMultipliers)(unsafe.Pointer(best_tx)).Fred_to_blue = libc.Uint8FromInt32(red_to_blue_best & int32(0xff))
  30829 }
  30830 
  30831 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) {
  30832 	bp := tls.Alloc(16)
  30833 	defer tls.Free(16)
  30834 	var all_x_max, all_y_max, max_tile_size, tile_height, tile_width, tile_x_offset, tile_y_offset int32
  30835 	var tile_argb uintptr
  30836 	var _ /* best_tx at bp+0 */ VP8LMultipliers
  30837 	_, _, _, _, _, _, _, _ = all_x_max, all_y_max, max_tile_size, tile_argb, tile_height, tile_width, tile_x_offset, tile_y_offset
  30838 	max_tile_size = int32(1) << bits
  30839 	tile_y_offset = tile_y * max_tile_size
  30840 	tile_x_offset = tile_x * max_tile_size
  30841 	all_x_max = GetMin(tls, tile_x_offset+max_tile_size, xsize)
  30842 	all_y_max = GetMin(tls, tile_y_offset+max_tile_size, ysize)
  30843 	tile_width = all_x_max - tile_x_offset
  30844 	tile_height = all_y_max - tile_y_offset
  30845 	tile_argb = argb + uintptr(tile_y_offset*xsize)*4 + uintptr(tile_x_offset)*4
  30846 	MultipliersClear(tls, bp)
  30847 	GetBestGreenToRed(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_red_histo, bp)
  30848 	GetBestGreenRedToBlue(tls, tile_argb, xsize, tile_width, tile_height, prev_x, prev_y, quality, accumulated_blue_histo, bp)
  30849 	return **(**VP8LMultipliers)(__ccgo_up(bp))
  30850 }
  30851 
  30852 func CopyTileWithColorTransform(tls *libc.TLS, xsize int32, ysize int32, tile_x int32, tile_y int32, max_tile_size int32, _color_transform VP8LMultipliers, argb uintptr) {
  30853 	bp := tls.Alloc(16)
  30854 	defer tls.Free(16)
  30855 	*(*VP8LMultipliers)(unsafe.Pointer(bp)) = _color_transform
  30856 	var xscan, yscan, v1 int32
  30857 	_, _, _ = xscan, yscan, v1
  30858 	xscan = GetMin(tls, max_tile_size, xsize-tile_x)
  30859 	yscan = GetMin(tls, max_tile_size, ysize-tile_y)
  30860 	argb = argb + uintptr(tile_y*xsize+tile_x)*4
  30861 	for {
  30862 		v1 = yscan
  30863 		yscan = yscan - 1
  30864 		if !(v1 > 0) {
  30865 			break
  30866 		}
  30867 		(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColor})))(tls, bp, argb, xscan)
  30868 		argb = argb + uintptr(xsize)*4
  30869 	}
  30870 }
  30871 
  30872 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) {
  30873 	bp := tls.Alloc(2064)
  30874 	defer tls.Free(2064)
  30875 	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
  30876 	var pix, v1, v2, v4, v5 uint32_t
  30877 	var _ /* accumulated_blue_histo at bp+1024 */ [256]uint32_t
  30878 	var _ /* accumulated_red_histo at bp+0 */ [256]uint32_t
  30879 	var _ /* prev_x at bp+2049 */ VP8LMultipliers
  30880 	var _ /* prev_y at bp+2052 */ VP8LMultipliers
  30881 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  30882 	max_tile_size = int32(1) << bits
  30883 	v1 = libc.Uint32FromInt32(bits)
  30884 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  30885 	goto _3
  30886 _3:
  30887 	tile_xsize = libc.Int32FromUint32(v2)
  30888 	v4 = libc.Uint32FromInt32(bits)
  30889 	v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  30890 	goto _6
  30891 _6:
  30892 	tile_ysize = libc.Int32FromUint32(v5)
  30893 	percent_start = **(**int32)(__ccgo_up(percent))
  30894 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  30895 	**(**[256]uint32_t)(__ccgo_up(bp + 1024)) = [256]uint32_t{}
  30896 	MultipliersClear(tls, bp+2052)
  30897 	MultipliersClear(tls, bp+2049)
  30898 	tile_y = 0
  30899 	for {
  30900 		if !(tile_y < tile_ysize) {
  30901 			break
  30902 		}
  30903 		tile_x = 0
  30904 		for {
  30905 			if !(tile_x < tile_xsize) {
  30906 				break
  30907 			}
  30908 			tile_x_offset = tile_x * max_tile_size
  30909 			tile_y_offset = tile_y * max_tile_size
  30910 			all_x_max = GetMin(tls, tile_x_offset+max_tile_size, width)
  30911 			all_y_max = GetMin(tls, tile_y_offset+max_tile_size, height)
  30912 			offset = tile_y*tile_xsize + tile_x
  30913 			if tile_y != 0 {
  30914 				ColorCodeToMultipliers(tls, **(**uint32_t)(__ccgo_up(image + uintptr(offset-tile_xsize)*4)), bp+2052)
  30915 			}
  30916 			**(**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)
  30917 			**(**uint32_t)(__ccgo_up(image + uintptr(offset)*4)) = MultipliersToColorCode(tls, bp+2049)
  30918 			CopyTileWithColorTransform(tls, width, height, tile_x_offset, tile_y_offset, max_tile_size, **(**VP8LMultipliers)(__ccgo_up(bp + 2049)), argb)
  30919 			// Gather accumulated histogram data.
  30920 			y = tile_y_offset
  30921 			for {
  30922 				if !(y < all_y_max) {
  30923 					break
  30924 				}
  30925 				ix = y*width + tile_x_offset
  30926 				ix_end = ix + all_x_max - tile_x_offset
  30927 				for {
  30928 					if !(ix < ix_end) {
  30929 						break
  30930 					}
  30931 					pix = **(**uint32_t)(__ccgo_up(argb + uintptr(ix)*4))
  30932 					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)) {
  30933 						goto _10 // repeated pixels are handled by backward references
  30934 					}
  30935 					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)) {
  30936 						goto _10 // repeated pixels are handled by backward references
  30937 					}
  30938 					(**(**[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
  30939 					(**(**[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
  30940 					goto _10
  30941 				_10:
  30942 					;
  30943 					ix = ix + 1
  30944 				}
  30945 				goto _9
  30946 			_9:
  30947 				;
  30948 				y = y + 1
  30949 			}
  30950 			goto _8
  30951 		_8:
  30952 			;
  30953 			tile_x = tile_x + 1
  30954 		}
  30955 		if !(WebPReportProgress(tls, pic, percent_start+percent_range*tile_y/tile_ysize, percent) != 0) {
  30956 			return 0
  30957 		}
  30958 		goto _7
  30959 	_7:
  30960 		;
  30961 		tile_y = tile_y + 1
  30962 	}
  30963 	VP8LOptimizeSampling(tls, image, width, height, bits, libc.Int32FromInt32(MIN_TRANSFORM_BITS)+libc.Int32FromInt32(1)<<libc.Int32FromInt32(NUM_TRANSFORM_BITS)-libc.Int32FromInt32(1), best_bits)
  30964 	return int32(1)
  30965 }
  30966 
  30967 const DO_TRELLIS_I16 = 1
  30968 const DO_TRELLIS_I4 = 1
  30969 const DO_TRELLIS_UV = 0
  30970 const FLATNESS_LIMIT_I16 = 0
  30971 const FLATNESS_LIMIT_I4 = 3
  30972 const FLATNESS_LIMIT_UV = 2
  30973 const FLATNESS_PENALTY = 140
  30974 const FSTRENGTH_CUTOFF = 2
  30975 const IsFlat = "IsFlat_C"
  30976 const MAX_ALPHA1 = 100
  30977 const MAX_DELTA = 1
  30978 const MAX_DQ_UV = 6
  30979 const MID_ALPHA = 64
  30980 const MIN_ALPHA = 30
  30981 const MIN_DELTA = 0
  30982 const RD_DISTO_MULT = 256
  30983 const SHARPEN_BITS = 11
  30984 const SNS_TO_DQ = 0.9
  30985 const USE_TDISTO = 1
  30986 
  30987 //------------------------------------------------------------------------------
  30988 
  30989 // Copyright 2011 Google Inc. All Rights Reserved.
  30990 //
  30991 // Use of this source code is governed by a BSD-style license
  30992 // that can be found in the COPYING file in the root of the source
  30993 // tree. An additional intellectual property rights grant can be found
  30994 // in the file PATENTS. All contributing project authors may
  30995 // be found in the AUTHORS file in the root of the source tree.
  30996 // -----------------------------------------------------------------------------
  30997 //
  30998 //   WebP encoder: internal header.
  30999 //
  31000 // Author: Skal (pascal.massimino@gmail.com)
  31001 
  31002 // Copyright 2010 Google Inc. All Rights Reserved.
  31003 //
  31004 // Use of this source code is governed by a BSD-style license
  31005 // that can be found in the COPYING file in the root of the source
  31006 // tree. An additional intellectual property rights grant can be found
  31007 // in the file PATENTS. All contributing project authors may
  31008 // be found in the AUTHORS file in the root of the source tree.
  31009 // -----------------------------------------------------------------------------
  31010 //
  31011 //  Common types + memory wrappers
  31012 //
  31013 // Author: Skal (pascal.massimino@gmail.com)
  31014 
  31015 // power-law modulation. Must be strictly less than 1.
  31016 
  31017 // number of non-zero coeffs below which we consider the block very flat
  31018 // (and apply a penalty to complex predictions)
  31019 
  31020 // #define DEBUG_BLOCK
  31021 
  31022 //------------------------------------------------------------------------------
  31023 
  31024 //------------------------------------------------------------------------------
  31025 
  31026 func clip2(tls *libc.TLS, v int32, m int32, M int32) (r int32) {
  31027 	var v1, v2 int32
  31028 	_, _ = v1, v2
  31029 	if v < m {
  31030 		v1 = m
  31031 	} else {
  31032 		if v > M {
  31033 			v2 = M
  31034 		} else {
  31035 			v2 = v
  31036 		}
  31037 		v1 = v2
  31038 	}
  31039 	return v1
  31040 }
  31041 
  31042 var kZigzag1 = [16]uint8_t{
  31043 	1:  uint8(1),
  31044 	2:  uint8(4),
  31045 	3:  uint8(8),
  31046 	4:  uint8(5),
  31047 	5:  uint8(2),
  31048 	6:  uint8(3),
  31049 	7:  uint8(6),
  31050 	8:  uint8(9),
  31051 	9:  uint8(12),
  31052 	10: uint8(13),
  31053 	11: uint8(10),
  31054 	12: uint8(7),
  31055 	13: uint8(11),
  31056 	14: uint8(14),
  31057 	15: uint8(15),
  31058 }
  31059 
  31060 var kDcTable1 = [128]uint8_t{
  31061 	0:   uint8(4),
  31062 	1:   uint8(5),
  31063 	2:   uint8(6),
  31064 	3:   uint8(7),
  31065 	4:   uint8(8),
  31066 	5:   uint8(9),
  31067 	6:   uint8(10),
  31068 	7:   uint8(10),
  31069 	8:   uint8(11),
  31070 	9:   uint8(12),
  31071 	10:  uint8(13),
  31072 	11:  uint8(14),
  31073 	12:  uint8(15),
  31074 	13:  uint8(16),
  31075 	14:  uint8(17),
  31076 	15:  uint8(17),
  31077 	16:  uint8(18),
  31078 	17:  uint8(19),
  31079 	18:  uint8(20),
  31080 	19:  uint8(20),
  31081 	20:  uint8(21),
  31082 	21:  uint8(21),
  31083 	22:  uint8(22),
  31084 	23:  uint8(22),
  31085 	24:  uint8(23),
  31086 	25:  uint8(23),
  31087 	26:  uint8(24),
  31088 	27:  uint8(25),
  31089 	28:  uint8(25),
  31090 	29:  uint8(26),
  31091 	30:  uint8(27),
  31092 	31:  uint8(28),
  31093 	32:  uint8(29),
  31094 	33:  uint8(30),
  31095 	34:  uint8(31),
  31096 	35:  uint8(32),
  31097 	36:  uint8(33),
  31098 	37:  uint8(34),
  31099 	38:  uint8(35),
  31100 	39:  uint8(36),
  31101 	40:  uint8(37),
  31102 	41:  uint8(37),
  31103 	42:  uint8(38),
  31104 	43:  uint8(39),
  31105 	44:  uint8(40),
  31106 	45:  uint8(41),
  31107 	46:  uint8(42),
  31108 	47:  uint8(43),
  31109 	48:  uint8(44),
  31110 	49:  uint8(45),
  31111 	50:  uint8(46),
  31112 	51:  uint8(46),
  31113 	52:  uint8(47),
  31114 	53:  uint8(48),
  31115 	54:  uint8(49),
  31116 	55:  uint8(50),
  31117 	56:  uint8(51),
  31118 	57:  uint8(52),
  31119 	58:  uint8(53),
  31120 	59:  uint8(54),
  31121 	60:  uint8(55),
  31122 	61:  uint8(56),
  31123 	62:  uint8(57),
  31124 	63:  uint8(58),
  31125 	64:  uint8(59),
  31126 	65:  uint8(60),
  31127 	66:  uint8(61),
  31128 	67:  uint8(62),
  31129 	68:  uint8(63),
  31130 	69:  uint8(64),
  31131 	70:  uint8(65),
  31132 	71:  uint8(66),
  31133 	72:  uint8(67),
  31134 	73:  uint8(68),
  31135 	74:  uint8(69),
  31136 	75:  uint8(70),
  31137 	76:  uint8(71),
  31138 	77:  uint8(72),
  31139 	78:  uint8(73),
  31140 	79:  uint8(74),
  31141 	80:  uint8(75),
  31142 	81:  uint8(76),
  31143 	82:  uint8(76),
  31144 	83:  uint8(77),
  31145 	84:  uint8(78),
  31146 	85:  uint8(79),
  31147 	86:  uint8(80),
  31148 	87:  uint8(81),
  31149 	88:  uint8(82),
  31150 	89:  uint8(83),
  31151 	90:  uint8(84),
  31152 	91:  uint8(85),
  31153 	92:  uint8(86),
  31154 	93:  uint8(87),
  31155 	94:  uint8(88),
  31156 	95:  uint8(89),
  31157 	96:  uint8(91),
  31158 	97:  uint8(93),
  31159 	98:  uint8(95),
  31160 	99:  uint8(96),
  31161 	100: uint8(98),
  31162 	101: uint8(100),
  31163 	102: uint8(101),
  31164 	103: uint8(102),
  31165 	104: uint8(104),
  31166 	105: uint8(106),
  31167 	106: uint8(108),
  31168 	107: uint8(110),
  31169 	108: uint8(112),
  31170 	109: uint8(114),
  31171 	110: uint8(116),
  31172 	111: uint8(118),
  31173 	112: uint8(122),
  31174 	113: uint8(124),
  31175 	114: uint8(126),
  31176 	115: uint8(128),
  31177 	116: uint8(130),
  31178 	117: uint8(132),
  31179 	118: uint8(134),
  31180 	119: uint8(136),
  31181 	120: uint8(138),
  31182 	121: uint8(140),
  31183 	122: uint8(143),
  31184 	123: uint8(145),
  31185 	124: uint8(148),
  31186 	125: uint8(151),
  31187 	126: uint8(154),
  31188 	127: uint8(157),
  31189 }
  31190 
  31191 var kAcTable1 = [128]uint16_t{
  31192 	0:   uint16(4),
  31193 	1:   uint16(5),
  31194 	2:   uint16(6),
  31195 	3:   uint16(7),
  31196 	4:   uint16(8),
  31197 	5:   uint16(9),
  31198 	6:   uint16(10),
  31199 	7:   uint16(11),
  31200 	8:   uint16(12),
  31201 	9:   uint16(13),
  31202 	10:  uint16(14),
  31203 	11:  uint16(15),
  31204 	12:  uint16(16),
  31205 	13:  uint16(17),
  31206 	14:  uint16(18),
  31207 	15:  uint16(19),
  31208 	16:  uint16(20),
  31209 	17:  uint16(21),
  31210 	18:  uint16(22),
  31211 	19:  uint16(23),
  31212 	20:  uint16(24),
  31213 	21:  uint16(25),
  31214 	22:  uint16(26),
  31215 	23:  uint16(27),
  31216 	24:  uint16(28),
  31217 	25:  uint16(29),
  31218 	26:  uint16(30),
  31219 	27:  uint16(31),
  31220 	28:  uint16(32),
  31221 	29:  uint16(33),
  31222 	30:  uint16(34),
  31223 	31:  uint16(35),
  31224 	32:  uint16(36),
  31225 	33:  uint16(37),
  31226 	34:  uint16(38),
  31227 	35:  uint16(39),
  31228 	36:  uint16(40),
  31229 	37:  uint16(41),
  31230 	38:  uint16(42),
  31231 	39:  uint16(43),
  31232 	40:  uint16(44),
  31233 	41:  uint16(45),
  31234 	42:  uint16(46),
  31235 	43:  uint16(47),
  31236 	44:  uint16(48),
  31237 	45:  uint16(49),
  31238 	46:  uint16(50),
  31239 	47:  uint16(51),
  31240 	48:  uint16(52),
  31241 	49:  uint16(53),
  31242 	50:  uint16(54),
  31243 	51:  uint16(55),
  31244 	52:  uint16(56),
  31245 	53:  uint16(57),
  31246 	54:  uint16(58),
  31247 	55:  uint16(60),
  31248 	56:  uint16(62),
  31249 	57:  uint16(64),
  31250 	58:  uint16(66),
  31251 	59:  uint16(68),
  31252 	60:  uint16(70),
  31253 	61:  uint16(72),
  31254 	62:  uint16(74),
  31255 	63:  uint16(76),
  31256 	64:  uint16(78),
  31257 	65:  uint16(80),
  31258 	66:  uint16(82),
  31259 	67:  uint16(84),
  31260 	68:  uint16(86),
  31261 	69:  uint16(88),
  31262 	70:  uint16(90),
  31263 	71:  uint16(92),
  31264 	72:  uint16(94),
  31265 	73:  uint16(96),
  31266 	74:  uint16(98),
  31267 	75:  uint16(100),
  31268 	76:  uint16(102),
  31269 	77:  uint16(104),
  31270 	78:  uint16(106),
  31271 	79:  uint16(108),
  31272 	80:  uint16(110),
  31273 	81:  uint16(112),
  31274 	82:  uint16(114),
  31275 	83:  uint16(116),
  31276 	84:  uint16(119),
  31277 	85:  uint16(122),
  31278 	86:  uint16(125),
  31279 	87:  uint16(128),
  31280 	88:  uint16(131),
  31281 	89:  uint16(134),
  31282 	90:  uint16(137),
  31283 	91:  uint16(140),
  31284 	92:  uint16(143),
  31285 	93:  uint16(146),
  31286 	94:  uint16(149),
  31287 	95:  uint16(152),
  31288 	96:  uint16(155),
  31289 	97:  uint16(158),
  31290 	98:  uint16(161),
  31291 	99:  uint16(164),
  31292 	100: uint16(167),
  31293 	101: uint16(170),
  31294 	102: uint16(173),
  31295 	103: uint16(177),
  31296 	104: uint16(181),
  31297 	105: uint16(185),
  31298 	106: uint16(189),
  31299 	107: uint16(193),
  31300 	108: uint16(197),
  31301 	109: uint16(201),
  31302 	110: uint16(205),
  31303 	111: uint16(209),
  31304 	112: uint16(213),
  31305 	113: uint16(217),
  31306 	114: uint16(221),
  31307 	115: uint16(225),
  31308 	116: uint16(229),
  31309 	117: uint16(234),
  31310 	118: uint16(239),
  31311 	119: uint16(245),
  31312 	120: uint16(249),
  31313 	121: uint16(254),
  31314 	122: uint16(259),
  31315 	123: uint16(264),
  31316 	124: uint16(269),
  31317 	125: uint16(274),
  31318 	126: uint16(279),
  31319 	127: uint16(284),
  31320 }
  31321 
  31322 var kAcTable2 = [128]uint16_t{
  31323 	0:   uint16(8),
  31324 	1:   uint16(8),
  31325 	2:   uint16(9),
  31326 	3:   uint16(10),
  31327 	4:   uint16(12),
  31328 	5:   uint16(13),
  31329 	6:   uint16(15),
  31330 	7:   uint16(17),
  31331 	8:   uint16(18),
  31332 	9:   uint16(20),
  31333 	10:  uint16(21),
  31334 	11:  uint16(23),
  31335 	12:  uint16(24),
  31336 	13:  uint16(26),
  31337 	14:  uint16(27),
  31338 	15:  uint16(29),
  31339 	16:  uint16(31),
  31340 	17:  uint16(32),
  31341 	18:  uint16(34),
  31342 	19:  uint16(35),
  31343 	20:  uint16(37),
  31344 	21:  uint16(38),
  31345 	22:  uint16(40),
  31346 	23:  uint16(41),
  31347 	24:  uint16(43),
  31348 	25:  uint16(44),
  31349 	26:  uint16(46),
  31350 	27:  uint16(48),
  31351 	28:  uint16(49),
  31352 	29:  uint16(51),
  31353 	30:  uint16(52),
  31354 	31:  uint16(54),
  31355 	32:  uint16(55),
  31356 	33:  uint16(57),
  31357 	34:  uint16(58),
  31358 	35:  uint16(60),
  31359 	36:  uint16(62),
  31360 	37:  uint16(63),
  31361 	38:  uint16(65),
  31362 	39:  uint16(66),
  31363 	40:  uint16(68),
  31364 	41:  uint16(69),
  31365 	42:  uint16(71),
  31366 	43:  uint16(72),
  31367 	44:  uint16(74),
  31368 	45:  uint16(75),
  31369 	46:  uint16(77),
  31370 	47:  uint16(79),
  31371 	48:  uint16(80),
  31372 	49:  uint16(82),
  31373 	50:  uint16(83),
  31374 	51:  uint16(85),
  31375 	52:  uint16(86),
  31376 	53:  uint16(88),
  31377 	54:  uint16(89),
  31378 	55:  uint16(93),
  31379 	56:  uint16(96),
  31380 	57:  uint16(99),
  31381 	58:  uint16(102),
  31382 	59:  uint16(105),
  31383 	60:  uint16(108),
  31384 	61:  uint16(111),
  31385 	62:  uint16(114),
  31386 	63:  uint16(117),
  31387 	64:  uint16(120),
  31388 	65:  uint16(124),
  31389 	66:  uint16(127),
  31390 	67:  uint16(130),
  31391 	68:  uint16(133),
  31392 	69:  uint16(136),
  31393 	70:  uint16(139),
  31394 	71:  uint16(142),
  31395 	72:  uint16(145),
  31396 	73:  uint16(148),
  31397 	74:  uint16(151),
  31398 	75:  uint16(155),
  31399 	76:  uint16(158),
  31400 	77:  uint16(161),
  31401 	78:  uint16(164),
  31402 	79:  uint16(167),
  31403 	80:  uint16(170),
  31404 	81:  uint16(173),
  31405 	82:  uint16(176),
  31406 	83:  uint16(179),
  31407 	84:  uint16(184),
  31408 	85:  uint16(189),
  31409 	86:  uint16(193),
  31410 	87:  uint16(198),
  31411 	88:  uint16(203),
  31412 	89:  uint16(207),
  31413 	90:  uint16(212),
  31414 	91:  uint16(217),
  31415 	92:  uint16(221),
  31416 	93:  uint16(226),
  31417 	94:  uint16(230),
  31418 	95:  uint16(235),
  31419 	96:  uint16(240),
  31420 	97:  uint16(244),
  31421 	98:  uint16(249),
  31422 	99:  uint16(254),
  31423 	100: uint16(258),
  31424 	101: uint16(263),
  31425 	102: uint16(268),
  31426 	103: uint16(274),
  31427 	104: uint16(280),
  31428 	105: uint16(286),
  31429 	106: uint16(292),
  31430 	107: uint16(299),
  31431 	108: uint16(305),
  31432 	109: uint16(311),
  31433 	110: uint16(317),
  31434 	111: uint16(323),
  31435 	112: uint16(330),
  31436 	113: uint16(336),
  31437 	114: uint16(342),
  31438 	115: uint16(348),
  31439 	116: uint16(354),
  31440 	117: uint16(362),
  31441 	118: uint16(370),
  31442 	119: uint16(379),
  31443 	120: uint16(385),
  31444 	121: uint16(393),
  31445 	122: uint16(401),
  31446 	123: uint16(409),
  31447 	124: uint16(416),
  31448 	125: uint16(424),
  31449 	126: uint16(432),
  31450 	127: uint16(440),
  31451 }
  31452 
  31453 var kBiasMatrices = [3][2]uint8_t{
  31454 	0: {
  31455 		0: uint8(96),
  31456 		1: uint8(110),
  31457 	},
  31458 	1: {
  31459 		0: uint8(96),
  31460 		1: uint8(108),
  31461 	},
  31462 	2: {
  31463 		0: uint8(110),
  31464 		1: uint8(115),
  31465 	},
  31466 }
  31467 
  31468 // C documentation
  31469 //
  31470 //	// Sharpening by (slightly) raising the hi-frequency coeffs.
  31471 //	// Hack-ish but helpful for mid-bitrate range. Use with care.
  31472 var kFreqSharpening = [16]uint8_t{
  31473 	1:  uint8(30),
  31474 	2:  uint8(60),
  31475 	3:  uint8(90),
  31476 	4:  uint8(30),
  31477 	5:  uint8(60),
  31478 	6:  uint8(90),
  31479 	7:  uint8(90),
  31480 	8:  uint8(60),
  31481 	9:  uint8(90),
  31482 	10: uint8(90),
  31483 	11: uint8(90),
  31484 	12: uint8(90),
  31485 	13: uint8(90),
  31486 	14: uint8(90),
  31487 	15: uint8(90),
  31488 }
  31489 
  31490 //------------------------------------------------------------------------------
  31491 // Initialize quantization parameters in VP8Matrix
  31492 
  31493 // C documentation
  31494 //
  31495 //	// Returns the average quantizer
  31496 func ExpandMatrix(tls *libc.TLS, m uintptr, type1 int32) (r int32) {
  31497 	var bias, i, is_ac_coeff, sum int32
  31498 	_, _, _, _ = bias, i, is_ac_coeff, sum
  31499 	i = 0
  31500 	for {
  31501 		if !(i < int32(2)) {
  31502 			break
  31503 		}
  31504 		is_ac_coeff = libc.BoolInt32(i > libc.Int32FromInt32(0))
  31505 		bias = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kBiasMatrices)) + uintptr(type1)*2 + uintptr(is_ac_coeff))))
  31506 		**(**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))))
  31507 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = libc.Uint32FromInt32(bias << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8)))
  31508 		// zthresh is the exact value such that QUANTDIV(coeff, iQ, B) is:
  31509 		//   * zero if coeff <= zthresh
  31510 		//   * non-zero if coeff > zthresh
  31511 		**(**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)))
  31512 		goto _1
  31513 	_1:
  31514 		;
  31515 		i = i + 1
  31516 	}
  31517 	i = int32(2)
  31518 	for {
  31519 		if !(i < int32(16)) {
  31520 			break
  31521 		}
  31522 		**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 1*2))
  31523 		**(**uint16_t)(__ccgo_up(m + 32 + uintptr(i)*2)) = **(**uint16_t)(__ccgo_up(m + 32 + 1*2))
  31524 		**(**uint32_t)(__ccgo_up(m + 64 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 64 + 1*4))
  31525 		**(**uint32_t)(__ccgo_up(m + 128 + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(m + 128 + 1*4))
  31526 		goto _2
  31527 	_2:
  31528 		;
  31529 		i = i + 1
  31530 	}
  31531 	sum = 0
  31532 	i = libc.Int32FromInt32(0)
  31533 	for {
  31534 		if !(i < int32(16)) {
  31535 			break
  31536 		}
  31537 		if type1 == 0 { // we only use sharpening for AC luma coeffs
  31538 			**(**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))
  31539 		} else {
  31540 			**(**uint16_t)(__ccgo_up(m + 192 + uintptr(i)*2)) = uint16(0)
  31541 		}
  31542 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(m + uintptr(i)*2)))
  31543 		goto _3
  31544 	_3:
  31545 		;
  31546 		i = i + 1
  31547 	}
  31548 	return (sum + int32(8)) >> int32(4)
  31549 }
  31550 
  31551 func CheckLambdaValue(tls *libc.TLS, v uintptr) {
  31552 	if **(**int32)(__ccgo_up(v)) < int32(1) {
  31553 		**(**int32)(__ccgo_up(v)) = int32(1)
  31554 	}
  31555 }
  31556 
  31557 func SetupMatrices(tls *libc.TLS, enc uintptr) {
  31558 	var i, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1 int32
  31559 	var m uintptr
  31560 	_, _, _, _, _, _, _, _, _ = i, m, num_segments, q, q_i16, q_i4, q_uv, tlambda_scale, v1
  31561 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmethod >= int32(4) {
  31562 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength
  31563 	} else {
  31564 		v1 = 0
  31565 	}
  31566 	tlambda_scale = v1
  31567 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31568 	i = 0
  31569 	for {
  31570 		if !(i < num_segments) {
  31571 			break
  31572 		}
  31573 		m = enc + 608 + uintptr(i)*744
  31574 		q = (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant
  31575 		**(**uint16_t)(__ccgo_up(m)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, 0, int32(127))])
  31576 		**(**uint16_t)(__ccgo_up(m + 1*2)) = kAcTable1[clip2(tls, q, 0, int32(127))]
  31577 		**(**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))
  31578 		**(**uint16_t)(__ccgo_up(m + 224 + 1*2)) = kAcTable2[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, 0, int32(127))]
  31579 		**(**uint16_t)(__ccgo_up(m + 448)) = uint16(kDcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, 0, int32(117))])
  31580 		**(**uint16_t)(__ccgo_up(m + 448 + 1*2)) = kAcTable1[clip2(tls, q+(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, 0, int32(127))]
  31581 		q_i4 = ExpandMatrix(tls, m, 0)
  31582 		q_i16 = ExpandMatrix(tls, m+224, int32(1))
  31583 		q_uv = ExpandMatrix(tls, m+448, int32(2))
  31584 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i4 = int32(3) * q_i4 * q_i4 >> int32(7)
  31585 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_i16 = int32(3) * q_i16 * q_i16
  31586 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_uv = int32(3) * q_uv * q_uv >> int32(6)
  31587 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_mode = int32(1) * q_i4 * q_i4 >> int32(7)
  31588 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i4 = int32(7) * q_i4 * q_i4 >> int32(3)
  31589 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_i16 = q_i16 * q_i16 >> int32(2)
  31590 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Flambda_trellis_uv = q_uv * q_uv << int32(1)
  31591 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ftlambda = tlambda_scale * q_i4 >> int32(5)
  31592 		// none of these constants should be < 1
  31593 		CheckLambdaValue(tls, m+700)
  31594 		CheckLambdaValue(tls, m+696)
  31595 		CheckLambdaValue(tls, m+704)
  31596 		CheckLambdaValue(tls, m+708)
  31597 		CheckLambdaValue(tls, m+724)
  31598 		CheckLambdaValue(tls, m+720)
  31599 		CheckLambdaValue(tls, m+728)
  31600 		CheckLambdaValue(tls, m+716)
  31601 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmin_disto = int32(20) * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(m))) // quantization-aware min disto
  31602 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fmax_edge = 0
  31603 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Fi4_penalty = int64(int32(1000) * q_i4 * q_i4)
  31604 		goto _2
  31605 	_2:
  31606 		;
  31607 		i = i + 1
  31608 	}
  31609 }
  31610 
  31611 //------------------------------------------------------------------------------
  31612 // Initialize filtering parameters
  31613 
  31614 // Very small filter-strength values have close to no visual effect. So we can
  31615 // save a little decoding-CPU by turning filtering off for these.
  31616 
  31617 func SetupFilterStrength(tls *libc.TLS, enc uintptr) {
  31618 	var base_strength, f, i, level0, qstep, v2, v3 int32
  31619 	var m uintptr
  31620 	_, _, _, _, _, _, _, _ = base_strength, f, i, level0, m, qstep, v2, v3
  31621 	// level0 is in [0..500]. Using '-f 50' as filter_strength is mid-filtering.
  31622 	level0 = int32(5) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_strength
  31623 	i = 0
  31624 	for {
  31625 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31626 			break
  31627 		}
  31628 		m = enc + 608 + uintptr(i)*744
  31629 		// We focus on the quantization of AC coeffs.
  31630 		qstep = libc.Int32FromUint16(kAcTable1[clip2(tls, (*VP8SegmentInfo)(unsafe.Pointer(m)).Fquant, 0, int32(127))]) >> int32(2)
  31631 		base_strength = VP8FilterStrengthFromDelta(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness, qstep)
  31632 		// Segments with lower complexity ('beta') will be less filtered.
  31633 		f = base_strength * level0 / (int32(256) + (*VP8SegmentInfo)(unsafe.Pointer(m)).Fbeta)
  31634 		if f < int32(FSTRENGTH_CUTOFF) {
  31635 			v2 = 0
  31636 		} else {
  31637 			if f > int32(63) {
  31638 				v3 = int32(63)
  31639 			} else {
  31640 				v3 = f
  31641 			}
  31642 			v2 = v3
  31643 		}
  31644 		(*VP8SegmentInfo)(unsafe.Pointer(m)).Ffstrength = v2
  31645 		goto _1
  31646 	_1:
  31647 		;
  31648 		i = i + 1
  31649 	}
  31650 	// We record the initial strength (mainly for the case of 1-segment only).
  31651 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Flevel = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Ffstrength
  31652 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsimple = libc.BoolInt32((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_type == 0)
  31653 	(*VP8Encoder)(unsafe.Pointer(enc)).Ffilter_hdr.Fsharpness = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Ffilter_sharpness
  31654 }
  31655 
  31656 //------------------------------------------------------------------------------
  31657 
  31658 // Note: if you change the values below, remember that the max range
  31659 // allowed by the syntax for DQ_UV is [-16,16].
  31660 
  31661 // C documentation
  31662 //
  31663 //	// We want to emulate jpeg-like behaviour where the expected "good" quality
  31664 //	// is around q=75. Internally, our "good" middle is around c=50. So we
  31665 //	// map accordingly using linear piece-wise function
  31666 func QualityToCompression(tls *libc.TLS, c float64) (r float64) {
  31667 	var linear_c, v, v1 float64
  31668 	_, _, _ = linear_c, v, v1
  31669 	if c < float64(0.75) {
  31670 		v1 = float64(c * (libc.Float64FromFloat64(2) / libc.Float64FromFloat64(3)))
  31671 	} else {
  31672 		v1 = float64(float64(2)*c) - float64(1)
  31673 	}
  31674 	linear_c = v1
  31675 	// The file size roughly scales as pow(quantizer, 3.). Actually, the
  31676 	// exponent is somewhere between 2.8 and 3.2, but we're mostly interested
  31677 	// in the mid-quant range. So we scale the compressibility inversely to
  31678 	// this power-law: quant ~= compression ^ 1/3. This law holds well for
  31679 	// low quant. Finer modeling for high-quant would make use of kAcTable[]
  31680 	// more explicitly.
  31681 	v = libc.Xpow(tls, linear_c, libc.Float64FromInt32(1)/libc.Float64FromFloat64(3))
  31682 	return v
  31683 }
  31684 
  31685 func QualityToJPEGCompression(tls *libc.TLS, c float64, alpha float64) (r float64) {
  31686 	var amax, amin, exp_max, exp_min, expn, slope, v, v1, v2 float64
  31687 	_, _, _, _, _, _, _, _, _ = amax, amin, exp_max, exp_min, expn, slope, v, v1, v2
  31688 	// We map the complexity 'alpha' and quality setting 'c' to a compression
  31689 	// exponent empirically matched to the compression curve of libjpeg6b.
  31690 	// On average, the WebP output size will be roughly similar to that of a
  31691 	// JPEG file compressed with same quality factor.
  31692 	amin = float64(0.3)
  31693 	amax = float64(0.85)
  31694 	exp_min = float64(0.4)
  31695 	exp_max = float64(0.9)
  31696 	slope = (exp_min - exp_max) / (amax - amin)
  31697 	if alpha > amax {
  31698 		v1 = exp_min
  31699 	} else {
  31700 		if alpha < amin {
  31701 			v2 = exp_max
  31702 		} else {
  31703 			v2 = exp_max + float64(slope*(alpha-amin))
  31704 		}
  31705 		v1 = v2
  31706 	}
  31707 	// Linearly interpolate 'expn' from exp_min to exp_max
  31708 	// in the [amin, amax] range.
  31709 	expn = v1
  31710 	v = libc.Xpow(tls, c, expn)
  31711 	return v
  31712 }
  31713 
  31714 func SegmentsAreEquivalent(tls *libc.TLS, S1 uintptr, S2 uintptr) (r int32) {
  31715 	return libc.BoolInt32((*VP8SegmentInfo)(unsafe.Pointer(S1)).Fquant == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Fquant && (*VP8SegmentInfo)(unsafe.Pointer(S1)).Ffstrength == (*VP8SegmentInfo)(unsafe.Pointer(S2)).Ffstrength)
  31716 }
  31717 
  31718 func SimplifySegments(tls *libc.TLS, enc uintptr) {
  31719 	var S1, S2 uintptr
  31720 	var found, i, num_final_segments, num_segments, s1, s2, v1 int32
  31721 	var map1 [4]int32
  31722 	_, _, _, _, _, _, _, _, _, _ = S1, S2, found, i, map1, num_final_segments, num_segments, s1, s2, v1
  31723 	map1 = [4]int32{
  31724 		1: int32(1),
  31725 		2: int32(2),
  31726 		3: int32(3),
  31727 	}
  31728 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments < int32(NUM_MB_SEGMENTS) {
  31729 		v1 = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31730 	} else {
  31731 		v1 = int32(NUM_MB_SEGMENTS)
  31732 	}
  31733 	// 'num_segments' is previously validated and <= NUM_MB_SEGMENTS, but an
  31734 	// explicit check is needed to avoid a spurious warning about 'i' exceeding
  31735 	// array bounds of 'dqm' with some compilers (noticed with gcc-4.9).
  31736 	num_segments = v1
  31737 	num_final_segments = int32(1)
  31738 	s1 = int32(1)
  31739 	for {
  31740 		if !(s1 < num_segments) {
  31741 			break
  31742 		} // find similar segments
  31743 		S1 = enc + 608 + uintptr(s1)*744
  31744 		found = 0
  31745 		// check if we already have similar segment
  31746 		s2 = 0
  31747 		for {
  31748 			if !(s2 < num_final_segments) {
  31749 				break
  31750 			}
  31751 			S2 = enc + 608 + uintptr(s2)*744
  31752 			if SegmentsAreEquivalent(tls, S1, S2) != 0 {
  31753 				found = int32(1)
  31754 				break
  31755 			}
  31756 			goto _3
  31757 		_3:
  31758 			;
  31759 			s2 = s2 + 1
  31760 		}
  31761 		map1[s1] = s2
  31762 		if !(found != 0) {
  31763 			if num_final_segments != s1 {
  31764 				**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s1)*744))
  31765 			}
  31766 			num_final_segments = num_final_segments + 1
  31767 		}
  31768 		goto _2
  31769 	_2:
  31770 		;
  31771 		s1 = s1 + 1
  31772 	}
  31773 	if num_final_segments < num_segments { // Remap
  31774 		i = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  31775 		for {
  31776 			v1 = i
  31777 			i = i - 1
  31778 			if !(v1 > 0) {
  31779 				break
  31780 			}
  31781 			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)
  31782 		}
  31783 		(*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments = num_final_segments
  31784 		// Replicate the trailing segment infos (it's mostly cosmetics)
  31785 		i = num_final_segments
  31786 		for {
  31787 			if !(i < num_segments) {
  31788 				break
  31789 			}
  31790 			**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744)) = **(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(num_final_segments-int32(1))*744))
  31791 			goto _5
  31792 		_5:
  31793 			;
  31794 			i = i + 1
  31795 		}
  31796 	}
  31797 }
  31798 
  31799 func VP8SetSegmentParams(tls *libc.TLS, enc uintptr, quality float32) {
  31800 	var Q, amp, c, c_base, expn, v1 float64
  31801 	var dq_uv_ac, dq_uv_dc, i, num_segments, q int32
  31802 	_, _, _, _, _, _, _, _, _, _, _ = Q, amp, c, c_base, dq_uv_ac, dq_uv_dc, expn, i, num_segments, q, v1
  31803 	num_segments = (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fnum_segments
  31804 	amp = float64(float64(SNS_TO_DQ)*float64((*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength)) / float64(100) / float64(128)
  31805 	Q = float64(quality) / float64(100)
  31806 	if (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Femulate_jpeg_size != 0 {
  31807 		v1 = QualityToJPEGCompression(tls, Q, float64((*VP8Encoder)(unsafe.Pointer(enc)).Falpha)/float64(255))
  31808 	} else {
  31809 		v1 = QualityToCompression(tls, Q)
  31810 	}
  31811 	c_base = v1
  31812 	i = 0
  31813 	for {
  31814 		if !(i < num_segments) {
  31815 			break
  31816 		}
  31817 		// We modulate the base coefficient to accommodate for the quantization
  31818 		// susceptibility and allow denser segments to be quantized more.
  31819 		expn = float64(1) - float64(amp*float64((**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Falpha))
  31820 		c = libc.Xpow(tls, c_base, expn)
  31821 		q = int32(float64(libc.Float64FromFloat64(127) * (libc.Float64FromFloat64(1) - c)))
  31822 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = clip2(tls, q, 0, int32(127))
  31823 		goto _2
  31824 	_2:
  31825 		;
  31826 		i = i + 1
  31827 	}
  31828 	// purely indicative in the bitstream (except for the 1-segment case)
  31829 	(*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608))).Fquant
  31830 	// fill-in values for the unused segments (required by the syntax)
  31831 	i = num_segments
  31832 	for {
  31833 		if !(i < int32(NUM_MB_SEGMENTS)) {
  31834 			break
  31835 		}
  31836 		(**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant = (*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant
  31837 		goto _3
  31838 	_3:
  31839 		;
  31840 		i = i + 1
  31841 	}
  31842 	// uv_alpha is normally spread around ~60. The useful range is
  31843 	// typically ~30 (quite bad) to ~100 (ok to decimate UV more).
  31844 	// We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv.
  31845 	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))
  31846 	// we rescale by the user-defined strength of adaptation
  31847 	dq_uv_ac = dq_uv_ac * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31848 	// and make it safe.
  31849 	dq_uv_ac = clip2(tls, dq_uv_ac, -int32(4), int32(MAX_DQ_UV))
  31850 	// We also boost the dc-uv-quant a little, based on sns-strength, since
  31851 	// U/V channels are quite more reactive to high quants (flat DC-blocks
  31852 	// tend to appear, and are unpleasant).
  31853 	dq_uv_dc = -int32(4) * (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsns_strength / int32(100)
  31854 	dq_uv_dc = clip2(tls, dq_uv_dc, -int32(15), int32(15)) // 4bit-signed max allowed
  31855 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc = 0       // TODO(skal): dq-lum
  31856 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc = 0
  31857 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac = 0
  31858 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc = dq_uv_dc
  31859 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac = dq_uv_ac
  31860 	SetupFilterStrength(tls, enc) // initialize segments' filtering, eventually
  31861 	if num_segments > int32(1) {
  31862 		SimplifySegments(tls, enc)
  31863 	}
  31864 	SetupMatrices(tls, enc) // finalize quantization matrices
  31865 }
  31866 
  31867 // C documentation
  31868 //
  31869 //	// Must be indexed using {B_DC_PRED -> B_HU_PRED} as index
  31870 var VP8I4ModeOffsets = [10]uint16_t{
  31871 	0: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0)),
  31872 	1: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(4)),
  31873 	2: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(8)),
  31874 	3: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(12)),
  31875 	4: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(16)),
  31876 	5: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(20)),
  31877 	6: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(24)),
  31878 	7: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(0) + libc.Int32FromInt32(28)),
  31879 	8: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31880 	9: libc.Uint16FromInt32(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(4)),
  31881 }
  31882 
  31883 func VP8MakeLuma16Preds(tls *libc.TLS, it uintptr) {
  31884 	var left, top, v1, v2 uintptr
  31885 	_, _, _, _ = left, top, v1, v2
  31886 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31887 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_left
  31888 	} else {
  31889 		v1 = libc.UintptrFromInt32(0)
  31890 	}
  31891 	left = v1
  31892 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31893 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fy_top
  31894 	} else {
  31895 		v2 = libc.UintptrFromInt32(0)
  31896 	}
  31897 	top = v2
  31898 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma16})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31899 }
  31900 
  31901 func VP8MakeChroma8Preds(tls *libc.TLS, it uintptr) {
  31902 	var left, top, v1, v2 uintptr
  31903 	_, _, _, _ = left, top, v1, v2
  31904 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fx != 0 {
  31905 		v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fu_left
  31906 	} else {
  31907 		v1 = libc.UintptrFromInt32(0)
  31908 	}
  31909 	left = v1
  31910 	if (*VP8EncIterator)(unsafe.Pointer(it)).Fy != 0 {
  31911 		v2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fuv_top
  31912 	} else {
  31913 		v2 = libc.UintptrFromInt32(0)
  31914 	}
  31915 	top = v2
  31916 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredChroma8})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, left, top)
  31917 }
  31918 
  31919 // C documentation
  31920 //
  31921 //	// Form all the ten Intra4x4 predictions in the 'yuv_p' cache
  31922 //	// for the 4x4 block it->i4
  31923 func MakeIntra4Preds(tls *libc.TLS, it uintptr) {
  31924 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8EncPredLuma4})))(tls, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p, (*VP8EncIterator)(unsafe.Pointer(it)).Fi4_top)
  31925 }
  31926 
  31927 var VP8ScanUV = [8]uint16_t{
  31928 	1: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31929 	2: libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31930 	3: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31931 	4: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31932 	5: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  31933 	6: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31934 	7: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  31935 }
  31936 
  31937 //------------------------------------------------------------------------------
  31938 // Distortion measurement
  31939 
  31940 var kWeightY = [16]uint16_t{
  31941 	0:  uint16(38),
  31942 	1:  uint16(32),
  31943 	2:  uint16(20),
  31944 	3:  uint16(9),
  31945 	4:  uint16(32),
  31946 	5:  uint16(28),
  31947 	6:  uint16(17),
  31948 	7:  uint16(7),
  31949 	8:  uint16(20),
  31950 	9:  uint16(17),
  31951 	10: uint16(10),
  31952 	11: uint16(4),
  31953 	12: uint16(9),
  31954 	13: uint16(7),
  31955 	14: uint16(4),
  31956 	15: uint16(2),
  31957 }
  31958 
  31959 var kWeightTrellis = [16]uint16_t{
  31960 	0:  uint16(30),
  31961 	1:  uint16(27),
  31962 	2:  uint16(19),
  31963 	3:  uint16(11),
  31964 	4:  uint16(27),
  31965 	5:  uint16(24),
  31966 	6:  uint16(17),
  31967 	7:  uint16(10),
  31968 	8:  uint16(19),
  31969 	9:  uint16(17),
  31970 	10: uint16(12),
  31971 	11: uint16(8),
  31972 	12: uint16(11),
  31973 	13: uint16(10),
  31974 	14: uint16(8),
  31975 	15: uint16(6),
  31976 }
  31977 
  31978 // C documentation
  31979 //
  31980 //	// Init/Copy the common fields in score.
  31981 func InitScore(tls *libc.TLS, rd uintptr) {
  31982 	(*VP8ModeScore)(unsafe.Pointer(rd)).FD = 0
  31983 	(*VP8ModeScore)(unsafe.Pointer(rd)).FSD = 0
  31984 	(*VP8ModeScore)(unsafe.Pointer(rd)).FR = 0
  31985 	(*VP8ModeScore)(unsafe.Pointer(rd)).FH = 0
  31986 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = uint32(0)
  31987 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  31988 }
  31989 
  31990 func CopyScore(tls *libc.TLS, dst uintptr, src uintptr) {
  31991 	(*VP8ModeScore)(unsafe.Pointer(dst)).FD = (*VP8ModeScore)(unsafe.Pointer(src)).FD
  31992 	(*VP8ModeScore)(unsafe.Pointer(dst)).FSD = (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  31993 	(*VP8ModeScore)(unsafe.Pointer(dst)).FR = (*VP8ModeScore)(unsafe.Pointer(src)).FR
  31994 	(*VP8ModeScore)(unsafe.Pointer(dst)).FH = (*VP8ModeScore)(unsafe.Pointer(src)).FH
  31995 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fnz = (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // note that nz is not accumulated, but just copied.
  31996 	(*VP8ModeScore)(unsafe.Pointer(dst)).Fscore = (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  31997 }
  31998 
  31999 func AddScore(tls *libc.TLS, dst uintptr, src uintptr) {
  32000 	**(**score_t)(__ccgo_up(dst)) += (*VP8ModeScore)(unsafe.Pointer(src)).FD
  32001 	**(**score_t)(__ccgo_up(dst + 8)) += (*VP8ModeScore)(unsafe.Pointer(src)).FSD
  32002 	**(**score_t)(__ccgo_up(dst + 24)) += (*VP8ModeScore)(unsafe.Pointer(src)).FR
  32003 	**(**score_t)(__ccgo_up(dst + 16)) += (*VP8ModeScore)(unsafe.Pointer(src)).FH
  32004 	**(**uint32_t)(__ccgo_up(dst + 864)) |= (*VP8ModeScore)(unsafe.Pointer(src)).Fnz // here, new nz bits are accumulated.
  32005 	**(**score_t)(__ccgo_up(dst + 32)) += (*VP8ModeScore)(unsafe.Pointer(src)).Fscore
  32006 }
  32007 
  32008 //------------------------------------------------------------------------------
  32009 // Performs trellis-optimized quantization.
  32010 
  32011 // C documentation
  32012 //
  32013 //	// Trellis node
  32014 type Node = struct {
  32015 	Fprev  int8_t
  32016 	Fsign  int8_t
  32017 	Flevel int16_t
  32018 }
  32019 
  32020 // C documentation
  32021 //
  32022 //	// Score state
  32023 type ScoreState = struct {
  32024 	Fscore score_t
  32025 	Fcosts uintptr
  32026 }
  32027 
  32028 // If a coefficient was quantized to a value Q (using a neutral bias),
  32029 // we test all alternate possibilities between [Q-MIN_DELTA, Q+MAX_DELTA]
  32030 // We don't test negative values though.
  32031 
  32032 func SetRDScore(tls *libc.TLS, lambda int32, rd uintptr) {
  32033 	(*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)
  32034 }
  32035 
  32036 func RDScoreTrellis(tls *libc.TLS, lambda int32, rate score_t, distortion score_t) (r score_t) {
  32037 	return rate*int64(lambda) + int64(RD_DISTO_MULT)*distortion
  32038 }
  32039 
  32040 const TYPE_I16_AC = 0
  32041 const TYPE_I16_DC = 1
  32042 const TYPE_CHROMA_A = 2
  32043 const TYPE_I4_AC = 3
  32044 
  32045 func TrellisQuantizeBlock(tls *libc.TLS, enc uintptr, in uintptr, out uintptr, ctx0 int32, coeff_type int32, mtx uintptr, lambda int32) (r int32) {
  32046 	bp := tls.Alloc(192)
  32047 	defer tls.Free(192)
  32048 	var B1, Q, coeff0, iQ1 uint32_t
  32049 	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
  32050 	var base_score, best_cur_score, best_score, cost, cost1, last_pos_cost, last_pos_score, rate, score score_t
  32051 	var best_path [3]int32
  32052 	var costs CostArrayPtr
  32053 	var cur, node, probas, ss_cur, ss_prev, tmp uintptr
  32054 	var v3 uint8_t
  32055 	var _ /* nodes at bp+0 */ [16][2]Node
  32056 	var _ /* score_states at bp+128 */ [2][2]ScoreState
  32057 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  32058 	probas = enc + 3616 + 4 + uintptr(coeff_type)*264
  32059 	costs = enc + 3616 + 18344 + uintptr(coeff_type)*384
  32060 	if coeff_type == int32(TYPE_I16_AC) {
  32061 		v1 = int32(1)
  32062 	} else {
  32063 		v1 = 0
  32064 	}
  32065 	first = v1
  32066 	ss_cur = bp + 128 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  32067 	ss_prev = bp + 128 + 1*32 + uintptr(libc.Int32FromInt32(MIN_DELTA)+libc.Int32FromInt32(MIN_DELTA))*16
  32068 	best_path = [3]int32{
  32069 		0: -int32(1),
  32070 		1: -int32(1),
  32071 		2: -int32(1),
  32072 	}
  32073 	thresh = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 1*2))) * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 1*2))) / int32(4)
  32074 	last_proba = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas + uintptr(VP8EncBands[first])*33 + uintptr(ctx0)*11)))
  32075 	// compute the position of the last interesting coefficient
  32076 	last = first - int32(1)
  32077 	n1 = int32(15)
  32078 	for {
  32079 		if !(n1 >= first) {
  32080 			break
  32081 		}
  32082 		j = libc.Int32FromUint8(kZigzag1[n1])
  32083 		err = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) * int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  32084 		if err > thresh {
  32085 			last = n1
  32086 			break
  32087 		}
  32088 		goto _2
  32089 	_2:
  32090 		;
  32091 		n1 = n1 - 1
  32092 	}
  32093 	// we don't need to go inspect up to n = 16 coeffs. We can just go up
  32094 	// to last + 1 (inclusive) without losing much.
  32095 	if last < int32(15) {
  32096 		last = last + 1
  32097 	}
  32098 	// compute 'skip' score. This is the max score one can do.
  32099 	v3 = libc.Uint8FromInt32(last_proba)
  32100 	if !(0 != 0) {
  32101 		v4 = libc.Int32FromUint16(VP8EntropyCost[v3])
  32102 	} else {
  32103 		v4 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  32104 	}
  32105 	v1 = v4
  32106 	goto _5
  32107 _5:
  32108 	cost = int64(v1)
  32109 	best_score = RDScoreTrellis(tls, lambda, cost, 0)
  32110 	// initialize source node.
  32111 	m = -MIN_DELTA
  32112 	for {
  32113 		if !(m <= int32(MAX_DELTA)) {
  32114 			break
  32115 		}
  32116 		if ctx0 == 0 {
  32117 			v3 = libc.Uint8FromInt32(last_proba)
  32118 			if !(int32(1) != 0) {
  32119 				v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  32120 			} else {
  32121 				v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  32122 			}
  32123 			v4 = v6
  32124 			goto _11
  32125 		_11:
  32126 			v1 = v4
  32127 		} else {
  32128 			v1 = 0
  32129 		}
  32130 		rate = int64(v1)
  32131 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = RDScoreTrellis(tls, lambda, rate, 0)
  32132 		(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(first)*24 + uintptr(ctx0)*8))
  32133 		goto _7
  32134 	_7:
  32135 		;
  32136 		m = m + 1
  32137 	}
  32138 	// traverse trellis.
  32139 	n1 = first
  32140 	for {
  32141 		if !(n1 <= last) {
  32142 			break
  32143 		}
  32144 		j1 = libc.Int32FromUint8(kZigzag1[n1])
  32145 		Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j1)*2)))
  32146 		iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j1)*2)))
  32147 		B1 = libc.Uint32FromInt32(libc.Int32FromInt32(0x00) << (libc.Int32FromInt32(QFIX) - libc.Int32FromInt32(8))) // neutral bias
  32148 		// note: it's important to take sign of the _original_ coeff,
  32149 		// so we don't have to consider level < 0 afterward.
  32150 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2))) < libc.Int32FromInt32(0))
  32151 		if sign != 0 {
  32152 			v1 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  32153 		} else {
  32154 			v1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j1)*2)))
  32155 		}
  32156 		coeff0 = libc.Uint32FromInt32(v1 + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j1)*2))))
  32157 		v4 = libc.Int32FromUint32((coeff0*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  32158 		goto _16
  32159 	_16:
  32160 		level0 = v4
  32161 		v6 = libc.Int32FromUint32((coeff0*iQ1 + libc.Uint32FromInt32(libc.Int32FromInt32(0x80)<<(libc.Int32FromInt32(QFIX)-libc.Int32FromInt32(8)))) >> libc.Int32FromInt32(QFIX))
  32162 		goto _18
  32163 	_18:
  32164 		thresh_level = v6
  32165 		if thresh_level > int32(MAX_LEVEL) {
  32166 			thresh_level = int32(MAX_LEVEL)
  32167 		}
  32168 		if level0 > int32(MAX_LEVEL) {
  32169 			level0 = int32(MAX_LEVEL)
  32170 		}
  32171 		// Swap current and previous score states
  32172 		tmp = ss_cur
  32173 		ss_cur = ss_prev
  32174 		ss_prev = tmp
  32175 		// test all alternate level values around level0.
  32176 		m = -MIN_DELTA
  32177 		for {
  32178 			if !(m <= int32(MAX_DELTA)) {
  32179 				break
  32180 			}
  32181 			cur = bp + uintptr(n1)*8 + uintptr(m+MIN_DELTA)*4
  32182 			level1 = level0 + m
  32183 			if level1 > int32(2) {
  32184 				v1 = int32(2)
  32185 			} else {
  32186 				v1 = level1
  32187 			}
  32188 			ctx = v1
  32189 			band = libc.Int32FromUint8(VP8EncBands[n1+int32(1)])
  32190 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fcosts = **(**uintptr)(__ccgo_up(costs + uintptr(n1+int32(1))*24 + uintptr(ctx)*8))
  32191 			if level1 < 0 || level1 > thresh_level {
  32192 				(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = libc.Int64FromInt64(0x7fffffffffffff)
  32193 				// Node is dead.
  32194 				goto _19
  32195 			}
  32196 			// Compute delta_error = how much coding this level will
  32197 			// subtract to max_error as distortion.
  32198 			// Here, distortion = sum of (|coeff_i| - level_i * Q_i)^2
  32199 			new_error = libc.Int32FromUint32(coeff0 - libc.Uint32FromInt32(level1)*Q)
  32200 			delta_error = libc.Int32FromUint32(uint32(kWeightTrellis[j1]) * (libc.Uint32FromInt32(new_error*new_error) - coeff0*coeff0))
  32201 			base_score = RDScoreTrellis(tls, lambda, 0, int64(delta_error))
  32202 			// Inspect all possible non-dead predecessors. Retain only the best one.
  32203 			// The base_score is added to all scores so it is only added for the final
  32204 			// value after the loop.
  32205 			v1 = level1
  32206 			if v1 > int32(MAX_VARIABLE_LEVEL) {
  32207 				v6 = int32(MAX_VARIABLE_LEVEL)
  32208 			} else {
  32209 				v6 = v1
  32210 			}
  32211 			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)))
  32212 			goto _23
  32213 		_23:
  32214 			cost1 = int64(v4)
  32215 			best_cur_score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(-libc.Int32FromInt32(MIN_DELTA))*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  32216 			best_prev = -MIN_DELTA
  32217 			p = -libc.Int32FromInt32(MIN_DELTA) + libc.Int32FromInt32(1)
  32218 			for {
  32219 				if !(p <= int32(MAX_DELTA)) {
  32220 					break
  32221 				}
  32222 				// Dead nodes (with ss_prev[p].score >= MAX_COST) are automatically
  32223 				// eliminated since their score can't be better than the current best.
  32224 				v1 = level1
  32225 				if v1 > int32(MAX_VARIABLE_LEVEL) {
  32226 					v6 = int32(MAX_VARIABLE_LEVEL)
  32227 				} else {
  32228 					v6 = v1
  32229 				}
  32230 				v4 = libc.Int32FromUint16(VP8LevelFixedCosts[v1]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fcosts + uintptr(v6)*2)))
  32231 				goto _28
  32232 			_28:
  32233 				cost1 = int64(v4)
  32234 				// Examine node assuming it's a non-terminal one.
  32235 				score = (**(**ScoreState)(__ccgo_up(ss_prev + uintptr(p)*16))).Fscore + RDScoreTrellis(tls, lambda, cost1, 0)
  32236 				if score < best_cur_score {
  32237 					best_cur_score = score
  32238 					best_prev = p
  32239 				}
  32240 				goto _25
  32241 			_25:
  32242 				;
  32243 				p = p + 1
  32244 			}
  32245 			best_cur_score = best_cur_score + base_score
  32246 			// Store best finding in current node.
  32247 			(*Node)(unsafe.Pointer(cur)).Fsign = int8(sign)
  32248 			(*Node)(unsafe.Pointer(cur)).Flevel = int16(level1)
  32249 			(*Node)(unsafe.Pointer(cur)).Fprev = int8(best_prev)
  32250 			(**(**ScoreState)(__ccgo_up(ss_cur + uintptr(m)*16))).Fscore = best_cur_score
  32251 			// Now, record best terminal node (and thus best entry in the graph).
  32252 			if level1 != 0 && best_cur_score < best_score {
  32253 				if n1 < int32(15) {
  32254 					v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(band)*33 + uintptr(ctx)*11))
  32255 					if !(0 != 0) {
  32256 						v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  32257 					} else {
  32258 						v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  32259 					}
  32260 					v4 = v6
  32261 					goto _33
  32262 				_33:
  32263 					v1 = v4
  32264 				} else {
  32265 					v1 = 0
  32266 				}
  32267 				last_pos_cost = int64(v1)
  32268 				last_pos_score = RDScoreTrellis(tls, lambda, last_pos_cost, 0)
  32269 				score = best_cur_score + last_pos_score
  32270 				if score < best_score {
  32271 					best_score = score
  32272 					best_path[0] = n1               // best eob position
  32273 					best_path[int32(1)] = m         // best node index
  32274 					best_path[int32(2)] = best_prev // best predecessor
  32275 				}
  32276 			}
  32277 			goto _19
  32278 		_19:
  32279 			;
  32280 			m = m + 1
  32281 		}
  32282 		goto _13
  32283 	_13:
  32284 		;
  32285 		n1 = n1 + 1
  32286 	}
  32287 	// Fresh start
  32288 	// Beware! We must preserve in[0]/out[0] value for TYPE_I16_AC case.
  32289 	if coeff_type == int32(TYPE_I16_AC) {
  32290 		libc.Xmemset(tls, in+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  32291 		libc.Xmemset(tls, out+uintptr(1)*2, 0, libc.Uint64FromInt32(15)*libc.Uint64FromInt64(2))
  32292 	} else {
  32293 		libc.Xmemset(tls, in, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  32294 		libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(16)*libc.Uint64FromInt64(2))
  32295 	}
  32296 	if best_path[0] == -int32(1) {
  32297 		return 0 // skip!
  32298 	}
  32299 	// Unwind the best path.
  32300 	// Note: best-prev on terminal node is not necessarily equal to the
  32301 	// best_prev for non-terminal. So we patch best_path[2] in.
  32302 	nz = 0
  32303 	best_node = best_path[int32(1)]
  32304 	n1 = best_path[0]
  32305 	(**(**Node)(__ccgo_up(bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4))).Fprev = int8(best_path[int32(2)]) // force best-prev for terminal
  32306 	for {
  32307 		if !(n1 >= first) {
  32308 			break
  32309 		}
  32310 		node = bp + uintptr(n1)*8 + uintptr(best_node+MIN_DELTA)*4
  32311 		j2 = libc.Int32FromUint8(kZigzag1[n1])
  32312 		if (*Node)(unsafe.Pointer(node)).Fsign != 0 {
  32313 			v1 = -int32((*Node)(unsafe.Pointer(node)).Flevel)
  32314 		} else {
  32315 			v1 = int32((*Node)(unsafe.Pointer(node)).Flevel)
  32316 		}
  32317 		**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(v1)
  32318 		nz = nz | int32((*Node)(unsafe.Pointer(node)).Flevel)
  32319 		**(**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))))
  32320 		best_node = int32((*Node)(unsafe.Pointer(node)).Fprev)
  32321 		goto _35
  32322 	_35:
  32323 		;
  32324 		n1 = n1 - 1
  32325 	}
  32326 	return libc.BoolInt32(nz != 0)
  32327 	return r
  32328 }
  32329 
  32330 //------------------------------------------------------------------------------
  32331 // Performs: difference, transform, quantize, back-transform, add
  32332 // all at once. Output is the reconstructed block in *yuv_out, and the
  32333 // quantized levels in *levels.
  32334 
  32335 func ReconstructIntra16(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32336 	bp := tls.Alloc(544)
  32337 	defer tls.Free(544)
  32338 	var ctx, n, non_zero, nz, x, y, v4 int32
  32339 	var dqm, enc, ref, src uintptr
  32340 	var v6 int16_t
  32341 	var _ /* dc_tmp at bp+512 */ [16]int16_t
  32342 	var _ /* tmp at bp+0 */ [16][16]int16_t
  32343 	_, _, _, _, _, _, _, _, _, _, _, _ = ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v4, v6
  32344 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32345 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  32346 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32347 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32348 	nz = 0
  32349 	n = 0
  32350 	for {
  32351 		if !(n < int32(16)) {
  32352 			break
  32353 		}
  32354 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8Scan[n]), ref+uintptr(VP8Scan[n]), bp+uintptr(n)*32)
  32355 		goto _1
  32356 	_1:
  32357 		;
  32358 		n = n + int32(2)
  32359 	}
  32360 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransformWHT})))(tls, bp, bp+512)
  32361 	nz = nz | (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlockWHT})))(tls, bp+512, rd+40, dqm+224)<<int32(24)
  32362 	if libc.Bool(int32(DO_TRELLIS_I16) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32363 		VP8IteratorNzToBytes(tls, it)
  32364 		y = 0
  32365 		n = libc.Int32FromInt32(0)
  32366 		for {
  32367 			if !(y < int32(4)) {
  32368 				break
  32369 			}
  32370 			x = 0
  32371 			for {
  32372 				if !(x < int32(4)) {
  32373 					break
  32374 				}
  32375 				ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32376 				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)
  32377 				v4 = non_zero
  32378 				**(**int32)(__ccgo_up(it + 168 + uintptr(y)*4)) = v4
  32379 				**(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) = v4
  32380 				**(**int16_t)(__ccgo_up(rd + 72 + uintptr(n)*32)) = 0
  32381 				nz = nz | non_zero<<n
  32382 				goto _3
  32383 			_3:
  32384 				;
  32385 				x = x + 1
  32386 				n = n + 1
  32387 			}
  32388 			goto _2
  32389 		_2:
  32390 			;
  32391 			y = y + 1
  32392 		}
  32393 	} else {
  32394 		n = 0
  32395 		for {
  32396 			if !(n < int32(16)) {
  32397 				break
  32398 			}
  32399 			// Zero-out the first coeff, so that: a) nz is correct below, and
  32400 			// b) finding 'last' non-zero coeffs in SetResidualCoeffs() is simplified.
  32401 			v6 = libc.Int16FromInt32(0)
  32402 			**(**int16_t)(__ccgo_up(bp + uintptr(n+int32(1))*32)) = v6
  32403 			**(**int16_t)(__ccgo_up(bp + uintptr(n)*32)) = v6
  32404 			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
  32405 			goto _5
  32406 		_5:
  32407 			;
  32408 			n = n + int32(2)
  32409 		}
  32410 	}
  32411 	// Transform back
  32412 	(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformWHT})))(tls, bp+512, bp)
  32413 	n = 0
  32414 	for {
  32415 		if !(n < int32(16)) {
  32416 			break
  32417 		}
  32418 		(*(*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))
  32419 		goto _7
  32420 	_7:
  32421 		;
  32422 		n = n + int32(2)
  32423 	}
  32424 	return nz
  32425 }
  32426 
  32427 func ReconstructIntra4(tls *libc.TLS, it uintptr, levels uintptr, src uintptr, yuv_out uintptr, mode int32) (r int32) {
  32428 	bp := tls.Alloc(32)
  32429 	defer tls.Free(32)
  32430 	var ctx, nz, x, y int32
  32431 	var dqm, enc, ref uintptr
  32432 	var _ /* tmp at bp+0 */ [16]int16_t
  32433 	_, _, _, _, _, _, _ = ctx, dqm, enc, nz, ref, x, y
  32434 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32435 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  32436 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32437 	nz = 0
  32438 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, bp)
  32439 	if libc.Bool(int32(DO_TRELLIS_I4) != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32440 		x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & int32(3)
  32441 		y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32442 		ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(y)*4))
  32443 		nz = TrellisQuantizeBlock(tls, enc, bp, levels, ctx, int32(TYPE_I4_AC), dqm, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_trellis_i4)
  32444 	} else {
  32445 		nz = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8EncQuantizeBlock})))(tls, bp, levels, dqm)
  32446 	}
  32447 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8ITransform})))(tls, ref, bp, yuv_out, 0)
  32448 	return nz
  32449 }
  32450 
  32451 //------------------------------------------------------------------------------
  32452 // DC-error diffusion
  32453 
  32454 // Diffusion weights. We under-correct a bit (15/16th of the error is actually
  32455 // diffused) to avoid 'rainbow' chessboard pattern of blocks at q~=0.
  32456 
  32457 // C documentation
  32458 //
  32459 //	// Quantize as usual, but also compute and return the quantization error.
  32460 //	// Error is already divided by DSHIFT.
  32461 func QuantizeSingle(tls *libc.TLS, v uintptr, mtx uintptr) (r int32) {
  32462 	var V, err, qV, sign, v1, v3 int32
  32463 	_, _, _, _, _, _ = V, err, qV, sign, v1, v3
  32464 	V = int32(**(**int16_t)(__ccgo_up(v)))
  32465 	sign = libc.BoolInt32(V < libc.Int32FromInt32(0))
  32466 	if sign != 0 {
  32467 		V = -V
  32468 	}
  32469 	if V > libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(mtx + 128))) {
  32470 		v1 = libc.Int32FromUint32((libc.Uint32FromInt32(V)*uint32(**(**uint16_t)(__ccgo_up(mtx + 32))) + **(**uint32_t)(__ccgo_up(mtx + 64))) >> libc.Int32FromInt32(QFIX))
  32471 		goto _2
  32472 	_2:
  32473 		qV = v1 * libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx)))
  32474 		err = V - qV
  32475 		if sign != 0 {
  32476 			v3 = -qV
  32477 		} else {
  32478 			v3 = qV
  32479 		}
  32480 		**(**int16_t)(__ccgo_up(v)) = int16(v3)
  32481 		if sign != 0 {
  32482 			v1 = -err
  32483 		} else {
  32484 			v1 = err
  32485 		}
  32486 		return v1 >> int32(1)
  32487 	}
  32488 	**(**int16_t)(__ccgo_up(v)) = 0
  32489 	if sign != 0 {
  32490 		v1 = -V
  32491 	} else {
  32492 		v1 = V
  32493 	}
  32494 	return v1 >> int32(1)
  32495 }
  32496 
  32497 func CorrectDCValues(tls *libc.TLS, it uintptr, mtx uintptr, tmp uintptr, rd uintptr) {
  32498 	var c, left, top, v2 uintptr
  32499 	var ch, err0, err1, err2, err3 int32
  32500 	_, _, _, _, _, _, _, _, _ = c, ch, err0, err1, err2, err3, left, top, v2
  32501 	ch = 0
  32502 	for {
  32503 		if !(ch <= int32(1)) {
  32504 			break
  32505 		}
  32506 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32507 		left = it + 344 + uintptr(ch)*2
  32508 		c = tmp + uintptr(ch*int32(4))*32
  32509 		v2 = c
  32510 		*(*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)))
  32511 		err0 = QuantizeSingle(tls, c, mtx)
  32512 		v2 = c + 1*32
  32513 		*(*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)))
  32514 		err1 = QuantizeSingle(tls, c+1*32, mtx)
  32515 		v2 = c + 2*32
  32516 		*(*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)))
  32517 		err2 = QuantizeSingle(tls, c+2*32, mtx)
  32518 		v2 = c + 3*32
  32519 		*(*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)))
  32520 		err3 = QuantizeSingle(tls, c+3*32, mtx)
  32521 		// error 'err' is bounded by mtx->q[0] which is 132 at max. Hence
  32522 		// err >> DSCALE will fit in an int8_t type if DSCALE>=1.
  32523 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3)) = int8(err1)
  32524 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1)) = int8(err2)
  32525 		**(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 2)) = int8(err3)
  32526 		goto _1
  32527 	_1:
  32528 		;
  32529 		ch = ch + 1
  32530 	}
  32531 }
  32532 
  32533 func StoreDiffusionErrors(tls *libc.TLS, it uintptr, rd uintptr) {
  32534 	var ch int32
  32535 	var left, top uintptr
  32536 	_, _, _ = ch, left, top
  32537 	ch = 0
  32538 	for {
  32539 		if !(ch <= int32(1)) {
  32540 			break
  32541 		}
  32542 		top = (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fx)*4 + uintptr(ch)*2
  32543 		left = it + 344 + uintptr(ch)*2
  32544 		**(**int8_t)(__ccgo_up(left)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3))                                                                // restore err1
  32545 		**(**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
  32546 		**(**int8_t)(__ccgo_up(top)) = **(**int8_t)(__ccgo_up(rd + 868 + uintptr(ch)*3 + 1))                                                             //     ... err2
  32547 		**(**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.
  32548 		goto _1
  32549 	_1:
  32550 		;
  32551 		ch = ch + 1
  32552 	}
  32553 }
  32554 
  32555 //------------------------------------------------------------------------------
  32556 
  32557 func ReconstructUV(tls *libc.TLS, it uintptr, rd uintptr, yuv_out uintptr, mode int32) (r int32) {
  32558 	bp := tls.Alloc(256)
  32559 	defer tls.Free(256)
  32560 	var ch, ctx, n, non_zero, nz, x, y, v5 int32
  32561 	var dqm, enc, ref, src uintptr
  32562 	var _ /* tmp at bp+0 */ [8][16]int16_t
  32563 	_, _, _, _, _, _, _, _, _, _, _, _ = ch, ctx, dqm, enc, n, non_zero, nz, ref, src, x, y, v5
  32564 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32565 	ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  32566 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  32567 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32568 	nz = 0
  32569 	n = 0
  32570 	for {
  32571 		if !(n < int32(8)) {
  32572 			break
  32573 		}
  32574 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform2})))(tls, src+uintptr(VP8ScanUV[n]), ref+uintptr(VP8ScanUV[n]), bp+uintptr(n)*32)
  32575 		goto _1
  32576 	_1:
  32577 		;
  32578 		n = n + int32(2)
  32579 	}
  32580 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  32581 		CorrectDCValues(tls, it, dqm+448, bp, rd)
  32582 	}
  32583 	if libc.Bool(DO_TRELLIS_UV != 0) && (*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis != 0 {
  32584 		ch = 0
  32585 		n = libc.Int32FromInt32(0)
  32586 		for {
  32587 			if !(ch <= int32(2)) {
  32588 				break
  32589 			}
  32590 			y = 0
  32591 			for {
  32592 				if !(y < int32(2)) {
  32593 					break
  32594 				}
  32595 				x = 0
  32596 				for {
  32597 					if !(x < int32(2)) {
  32598 						break
  32599 					}
  32600 					ctx = **(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) + **(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4))
  32601 					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)
  32602 					v5 = non_zero
  32603 					**(**int32)(__ccgo_up(it + 168 + uintptr(int32(4)+ch+y)*4)) = v5
  32604 					**(**int32)(__ccgo_up(it + 132 + uintptr(int32(4)+ch+x)*4)) = v5
  32605 					nz = nz | non_zero<<n
  32606 					goto _4
  32607 				_4:
  32608 					;
  32609 					x = x + 1
  32610 					n = n + 1
  32611 				}
  32612 				goto _3
  32613 			_3:
  32614 				;
  32615 				y = y + 1
  32616 			}
  32617 			goto _2
  32618 		_2:
  32619 			;
  32620 			ch = ch + int32(2)
  32621 		}
  32622 	} else {
  32623 		n = 0
  32624 		for {
  32625 			if !(n < int32(8)) {
  32626 				break
  32627 			}
  32628 			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
  32629 			goto _6
  32630 		_6:
  32631 			;
  32632 			n = n + int32(2)
  32633 		}
  32634 	}
  32635 	n = 0
  32636 	for {
  32637 		if !(n < int32(8)) {
  32638 			break
  32639 		}
  32640 		(*(*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))
  32641 		goto _7
  32642 	_7:
  32643 		;
  32644 		n = n + int32(2)
  32645 	}
  32646 	return nz << int32(16)
  32647 }
  32648 
  32649 //------------------------------------------------------------------------------
  32650 // RD-opt decision. Reconstruct each modes, evalue distortion and bit-cost.
  32651 // Pick the mode is lower RD-cost = Rate + lambda * Distortion.
  32652 
  32653 func StoreMaxDelta(tls *libc.TLS, dqm uintptr, DCs uintptr) {
  32654 	var max_v, v0, v1, v2, v11, v21 int32
  32655 	_, _, _, _, _, _ = max_v, v0, v1, v2, v11, v21
  32656 	// We look at the first three AC coefficients to determine what is the average
  32657 	// delta between each sub-4x4 block.
  32658 	v0 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 1*2))))
  32659 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 2*2))))
  32660 	v2 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up(DCs + 4*2))))
  32661 	if v1 > v0 {
  32662 		v11 = v1
  32663 	} else {
  32664 		v11 = v0
  32665 	}
  32666 	max_v = v11
  32667 	if v2 > max_v {
  32668 		v21 = v2
  32669 	} else {
  32670 		v21 = max_v
  32671 	}
  32672 	max_v = v21
  32673 	if max_v > (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge {
  32674 		(*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmax_edge = max_v
  32675 	}
  32676 }
  32677 
  32678 func SwapModeScore(tls *libc.TLS, a uintptr, b uintptr) {
  32679 	var tmp uintptr
  32680 	_ = tmp
  32681 	tmp = **(**uintptr)(__ccgo_up(a))
  32682 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32683 	**(**uintptr)(__ccgo_up(b)) = tmp
  32684 }
  32685 
  32686 func SwapPtr(tls *libc.TLS, a uintptr, b uintptr) {
  32687 	var tmp uintptr
  32688 	_ = tmp
  32689 	tmp = **(**uintptr)(__ccgo_up(a))
  32690 	**(**uintptr)(__ccgo_up(a)) = **(**uintptr)(__ccgo_up(b))
  32691 	**(**uintptr)(__ccgo_up(b)) = tmp
  32692 }
  32693 
  32694 func SwapOut(tls *libc.TLS, it uintptr) {
  32695 	SwapPtr(tls, it+16, it+24)
  32696 }
  32697 
  32698 func PickBestIntra16(tls *libc.TLS, it uintptr, rd uintptr) {
  32699 	bp := tls.Alloc(912)
  32700 	defer tls.Free(912)
  32701 	var dqm, src1, tmp_dst, v1 uintptr
  32702 	var i, i1, is_flat, kNumBlocks, lambda, mode, score, tlambda, v3, v6, v8 int32
  32703 	var _ /* rd_best at bp+896 */ uintptr
  32704 	var _ /* rd_cur at bp+888 */ uintptr
  32705 	var _ /* rd_tmp at bp+8 */ VP8ModeScore
  32706 	var _ /* v at bp+0 */ uint32_t
  32707 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, i, i1, is_flat, kNumBlocks, lambda, mode, score, src1, tlambda, tmp_dst, v1, v3, v6, v8
  32708 	kNumBlocks = int32(16)
  32709 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32710 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i16
  32711 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32712 	src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32713 	**(**uintptr)(__ccgo_up(bp + 888)) = bp + 8
  32714 	**(**uintptr)(__ccgo_up(bp + 896)) = rd
  32715 	v1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32716 	**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v1))) * uint32(0x01010101)
  32717 	i1 = libc.Int32FromInt32(0)
  32718 	for {
  32719 		if !(i1 < libc.Int32FromInt32(16)) {
  32720 			break
  32721 		}
  32722 		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 {
  32723 			v3 = 0
  32724 			goto _4
  32725 		}
  32726 		v1 = v1 + uintptr(BPS)
  32727 		goto _2
  32728 	_2:
  32729 		;
  32730 		i1 = i1 + 1
  32731 	}
  32732 	v3 = int32(1)
  32733 	goto _4
  32734 _4:
  32735 	is_flat = v3
  32736 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16 = -int32(1)
  32737 	mode = 0
  32738 	for {
  32739 		if !(mode < int32(NUM_PRED_MODES)) {
  32740 			break
  32741 		}
  32742 		tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) // scratch buffer
  32743 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fmode_i16 = mode
  32744 		// Reconstruct
  32745 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fnz = libc.Uint32FromInt32(ReconstructIntra16(tls, it, **(**uintptr)(__ccgo_up(bp + 888)), tmp_dst, mode))
  32746 		// Measure RD-score
  32747 		(*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))
  32748 		if tlambda != 0 {
  32749 			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)
  32750 		} else {
  32751 			v3 = 0
  32752 		}
  32753 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FSD = int64(v3)
  32754 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FH = libc.Int64FromUint16(VP8FixedCostsI16[mode])
  32755 		(*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).FR = int64(VP8GetCostLuma16(tls, it, **(**uintptr)(__ccgo_up(bp + 888))))
  32756 		if is_flat != 0 {
  32757 			// refine the first impression (which was in pixel space)
  32758 			v1 = **(**uintptr)(__ccgo_up(bp + 888)) + 72
  32759 			v3 = kNumBlocks
  32760 			score = 0
  32761 			for {
  32762 				v6 = v3
  32763 				v3 = v3 - 1
  32764 				if !(v6 > libc.Int32FromInt32(0)) {
  32765 					break
  32766 				}
  32767 				i = libc.Int32FromInt32(1)
  32768 				for {
  32769 					if !(i < libc.Int32FromInt32(16)) {
  32770 						break
  32771 					}
  32772 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v1 + uintptr(i)*2))) != 0)
  32773 					if score > FLATNESS_LIMIT_I16 {
  32774 						v8 = 0
  32775 						goto _12
  32776 					}
  32777 					goto _10
  32778 				_10:
  32779 					;
  32780 					i = i + 1
  32781 				}
  32782 				v1 = v1 + uintptr(16)*2
  32783 			}
  32784 			v8 = int32(1)
  32785 			goto _12
  32786 		_12:
  32787 			is_flat = v8
  32788 			if is_flat != 0 {
  32789 				// Block is very flat. We put emphasis on the distortion being very low!
  32790 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)))) *= int64(2)
  32791 				**(**score_t)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 888)) + 8)) *= int64(2)
  32792 			}
  32793 		}
  32794 		// Since we always examine Intra16 first, we can overwrite *rd directly.
  32795 		SetRDScore(tls, lambda, **(**uintptr)(__ccgo_up(bp + 888)))
  32796 		if mode == 0 || (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 888)))).Fscore < (*VP8ModeScore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 896)))).Fscore {
  32797 			SwapModeScore(tls, bp+888, bp+896)
  32798 			SwapOut(tls, it)
  32799 		}
  32800 		goto _5
  32801 	_5:
  32802 		;
  32803 		mode = mode + 1
  32804 	}
  32805 	if **(**uintptr)(__ccgo_up(bp + 896)) != rd {
  32806 		libc.Xmemcpy(tls, rd, **(**uintptr)(__ccgo_up(bp + 896)), uint64(880))
  32807 	}
  32808 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, rd) // finalize score for mode decision.
  32809 	VP8SetIntra16Mode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_i16)
  32810 	// we have a blocky macroblock (only DCs are non-zero) with fairly high
  32811 	// distortion, record max delta so we can later adjust the minimal filtering
  32812 	// strength needed to smooth these blocks out.
  32813 	if (*VP8ModeScore)(unsafe.Pointer(rd)).Fnz&uint32(0x100ffff) == uint32(0x1000000) && (*VP8ModeScore)(unsafe.Pointer(rd)).FD > int64((*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fmin_disto) {
  32814 		StoreMaxDelta(tls, dqm, rd+40)
  32815 	}
  32816 }
  32817 
  32818 //------------------------------------------------------------------------------
  32819 
  32820 // C documentation
  32821 //
  32822 //	// return the cost array corresponding to the surrounding prediction modes.
  32823 func GetCostModeI4(tls *libc.TLS, it uintptr, modes uintptr) (r uintptr) {
  32824 	var left, preds_w, top, x, y, v1, v2 int32
  32825 	_, _, _, _, _, _, _ = left, preds_w, top, x, y, v1, v2
  32826 	preds_w = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fpreds_w
  32827 	x = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 & libc.Int32FromInt32(3)
  32828 	y = (*VP8EncIterator)(unsafe.Pointer(it)).Fi4 >> int32(2)
  32829 	if x == 0 {
  32830 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(y*preds_w-int32(1)))))
  32831 	} else {
  32832 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(1)))))
  32833 	}
  32834 	left = v1
  32835 	if y == 0 {
  32836 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8EncIterator)(unsafe.Pointer(it)).Fpreds + uintptr(-preds_w+x))))
  32837 	} else {
  32838 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(modes + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4-int32(4)))))
  32839 	}
  32840 	top = v2
  32841 	return uintptr(unsafe.Pointer(&VP8FixedCostsI4)) + uintptr(top)*200 + uintptr(left)*20
  32842 }
  32843 
  32844 func PickBestIntra4(tls *libc.TLS, it uintptr, rd uintptr) (r int32) {
  32845 	bp := tls.Alloc(2688)
  32846 	defer tls.Free(2688)
  32847 	var best_blocks, dqm, enc, mode_costs, src, src0, v3 uintptr
  32848 	var best_mode, i, kNumBlocks, lambda, mode, score, tlambda, total_header_bits, v2, v4, v5 int32
  32849 	var v9 bool
  32850 	var _ /* best_block at bp+1760 */ uintptr
  32851 	var _ /* rd_best at bp+0 */ VP8ModeScore
  32852 	var _ /* rd_i4 at bp+880 */ VP8ModeScore
  32853 	var _ /* rd_tmp at bp+1776 */ VP8ModeScore
  32854 	var _ /* tmp_dst at bp+1768 */ uintptr
  32855 	var _ /* tmp_levels at bp+2656 */ [16]int16_t
  32856 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = best_blocks, best_mode, dqm, enc, i, kNumBlocks, lambda, mode, mode_costs, score, src, src0, tlambda, total_header_bits, v2, v3, v4, v5, v9
  32857 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  32858 	dqm = enc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32859 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_i4
  32860 	tlambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Ftlambda
  32861 	src0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32862 	best_blocks = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  32863 	total_header_bits = 0
  32864 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits == 0 {
  32865 		return 0
  32866 	}
  32867 	InitScore(tls, bp)
  32868 	(**(**VP8ModeScore)(__ccgo_up(bp))).FH = int64(211) // '211' is the value of VP8BitCost(0, 145)
  32869 	SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp)
  32870 	VP8IteratorStartI4(tls, it)
  32871 	for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, best_blocks) != 0 {
  32872 		kNumBlocks = int32(1)
  32873 		best_mode = -int32(1)
  32874 		src = src0 + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32875 		mode_costs = GetCostModeI4(tls, it, rd+844)
  32876 		**(**uintptr)(__ccgo_up(bp + 1760)) = best_blocks + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  32877 		**(**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.
  32878 		InitScore(tls, bp+880)
  32879 		MakeIntra4Preds(tls, it)
  32880 		mode = 0
  32881 		for {
  32882 			if !(mode < int32(NUM_BMODES)) {
  32883 				break
  32884 			}
  32885 			// Reconstruct
  32886 			(**(**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)
  32887 			// Compute RD-score
  32888 			(**(**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))))
  32889 			if tlambda != 0 {
  32890 				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)
  32891 			} else {
  32892 				v2 = 0
  32893 			}
  32894 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FSD = int64(v2)
  32895 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FH = libc.Int64FromUint16(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(mode)*2)))
  32896 			// Add flatness penalty, to avoid flat area to be mispredicted
  32897 			// by a complex mode.
  32898 			if v9 = mode > 0; v9 {
  32899 				v3 = bp + 2656
  32900 				v2 = kNumBlocks
  32901 				score = 0
  32902 				for {
  32903 					v4 = v2
  32904 					v2 = v2 - 1
  32905 					if !(v4 > libc.Int32FromInt32(0)) {
  32906 						break
  32907 					}
  32908 					i = libc.Int32FromInt32(1)
  32909 					for {
  32910 						if !(i < libc.Int32FromInt32(16)) {
  32911 							break
  32912 						}
  32913 						score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v3 + uintptr(i)*2))) != 0)
  32914 						if score > int32(FLATNESS_LIMIT_I4) {
  32915 							v5 = 0
  32916 							goto _8
  32917 						}
  32918 						goto _6
  32919 					_6:
  32920 						;
  32921 						i = i + 1
  32922 					}
  32923 					v3 = v3 + uintptr(16)*2
  32924 				}
  32925 				v5 = int32(1)
  32926 				goto _8
  32927 			_8:
  32928 			}
  32929 			if v9 && v5 != 0 {
  32930 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  32931 			} else {
  32932 				(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR = 0
  32933 			}
  32934 			// early-out check
  32935 			SetRDScore(tls, lambda, bp+1776)
  32936 			if best_mode >= 0 && (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore >= (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32937 				goto _1
  32938 			}
  32939 			// finish computing score
  32940 			(**(**VP8ModeScore)(__ccgo_up(bp + 1776))).FR += int64(VP8GetCostLuma4(tls, it, bp+2656))
  32941 			SetRDScore(tls, lambda, bp+1776)
  32942 			if best_mode < 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 1776))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fscore {
  32943 				CopyScore(tls, bp+880, bp+1776)
  32944 				best_mode = mode
  32945 				SwapPtr(tls, bp+1768, bp+1760)
  32946 				libc.Xmemcpy(tls, bp+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, bp+2656, uint64(32))
  32947 			}
  32948 			goto _1
  32949 		_1:
  32950 			;
  32951 			mode = mode + 1
  32952 		}
  32953 		SetRDScore(tls, (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_mode, bp+880)
  32954 		AddScore(tls, bp, bp+880)
  32955 		if (**(**VP8ModeScore)(__ccgo_up(bp))).Fscore >= (*VP8ModeScore)(unsafe.Pointer(rd)).Fscore {
  32956 			return 0
  32957 		}
  32958 		total_header_bits = total_header_bits + int32((**(**VP8ModeScore)(__ccgo_up(bp + 880))).FH) // <- equal to mode_costs[best_mode];
  32959 		if total_header_bits > (*VP8Encoder)(unsafe.Pointer(enc)).Fmax_i4_header_bits {
  32960 			return 0
  32961 		}
  32962 		// Copy selected samples if not in the right place already.
  32963 		if **(**uintptr)(__ccgo_up(bp + 1760)) != best_blocks+uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4]) {
  32964 			(*(*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]))
  32965 		}
  32966 		**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = libc.Uint8FromInt32(best_mode)
  32967 		if (**(**VP8ModeScore)(__ccgo_up(bp + 880))).Fnz != 0 {
  32968 			v4 = int32(1)
  32969 		} else {
  32970 			v4 = 0
  32971 		}
  32972 		v2 = v4
  32973 		**(**int32)(__ccgo_up(it + 168 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4>>int32(2))*4)) = v2
  32974 		**(**int32)(__ccgo_up(it + 132 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4&int32(3))*4)) = v2
  32975 	}
  32976 	// finalize state
  32977 	CopyScore(tls, rd, bp)
  32978 	VP8SetIntra4Mode(tls, it, rd+844)
  32979 	SwapOut(tls, it)
  32980 	libc.Xmemcpy(tls, rd+72, bp+72, uint64(512))
  32981 	return int32(1) // select intra4x4 over intra16x16
  32982 }
  32983 
  32984 //------------------------------------------------------------------------------
  32985 
  32986 func PickBestUV(tls *libc.TLS, it uintptr, rd uintptr) {
  32987 	bp := tls.Alloc(1776)
  32988 	defer tls.Free(1776)
  32989 	var dqm, dst0, src, v2 uintptr
  32990 	var i, kNumBlocks, lambda, mode, score, v3, v4, v6 int32
  32991 	var v8 bool
  32992 	var _ /* dst at bp+8 */ uintptr
  32993 	var _ /* rd_best at bp+16 */ VP8ModeScore
  32994 	var _ /* rd_uv at bp+896 */ VP8ModeScore
  32995 	var _ /* tmp_dst at bp+0 */ uintptr
  32996 	_, _, _, _, _, _, _, _, _, _, _, _, _ = dqm, dst0, i, kNumBlocks, lambda, mode, score, src, v2, v3, v4, v6, v8
  32997 	kNumBlocks = int32(8)
  32998 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  32999 	lambda = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Flambda_uv
  33000 	src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  33001 	**(**uintptr)(__ccgo_up(bp)) = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(U_OFF_ENC)) // scratch buffer
  33002 	dst0 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  33003 	**(**uintptr)(__ccgo_up(bp + 8)) = dst0
  33004 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = -int32(1)
  33005 	InitScore(tls, bp+16)
  33006 	mode = 0
  33007 	for {
  33008 		if !(mode < int32(NUM_PRED_MODES)) {
  33009 			break
  33010 		}
  33011 		// Reconstruct
  33012 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fnz = libc.Uint32FromInt32(ReconstructUV(tls, it, bp+896, **(**uintptr)(__ccgo_up(bp)), mode))
  33013 		// Compute RD-score
  33014 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FD = int64((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{VP8SSE16x8})))(tls, src, **(**uintptr)(__ccgo_up(bp))))
  33015 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FSD = 0 // not calling TDisto here: it tends to flatten areas.
  33016 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FH = libc.Int64FromUint16(VP8FixedCostsUV[mode])
  33017 		(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR = int64(VP8GetCostUV(tls, it, bp+896))
  33018 		if v8 = mode > 0; v8 {
  33019 			v2 = bp + 896 + 584
  33020 			v3 = kNumBlocks
  33021 			score = 0
  33022 			for {
  33023 				v4 = v3
  33024 				v3 = v3 - 1
  33025 				if !(v4 > libc.Int32FromInt32(0)) {
  33026 					break
  33027 				}
  33028 				i = libc.Int32FromInt32(1)
  33029 				for {
  33030 					if !(i < libc.Int32FromInt32(16)) {
  33031 						break
  33032 					}
  33033 					score = score + libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(v2 + uintptr(i)*2))) != 0)
  33034 					if score > int32(FLATNESS_LIMIT_UV) {
  33035 						v6 = 0
  33036 						goto _7
  33037 					}
  33038 					goto _5
  33039 				_5:
  33040 					;
  33041 					i = i + 1
  33042 				}
  33043 				v2 = v2 + uintptr(16)*2
  33044 			}
  33045 			v6 = int32(1)
  33046 			goto _7
  33047 		_7:
  33048 		}
  33049 		if v8 && v6 != 0 {
  33050 			(**(**VP8ModeScore)(__ccgo_up(bp + 896))).FR += int64(int32(FLATNESS_PENALTY) * kNumBlocks)
  33051 		}
  33052 		SetRDScore(tls, lambda, bp+896)
  33053 		if mode == 0 || (**(**VP8ModeScore)(__ccgo_up(bp + 896))).Fscore < (**(**VP8ModeScore)(__ccgo_up(bp + 16))).Fscore {
  33054 			CopyScore(tls, bp+16, bp+896)
  33055 			(*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv = mode
  33056 			libc.Xmemcpy(tls, rd+584, bp+896+584, uint64(256))
  33057 			if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) {
  33058 				libc.Xmemcpy(tls, rd+868, bp+896+868, uint64(6))
  33059 			}
  33060 			SwapPtr(tls, bp+8, bp)
  33061 		}
  33062 		goto _1
  33063 	_1:
  33064 		;
  33065 		mode = mode + 1
  33066 	}
  33067 	VP8SetIntraUVMode(tls, it, (*VP8ModeScore)(unsafe.Pointer(rd)).Fmode_uv)
  33068 	AddScore(tls, rd, bp+16)
  33069 	if **(**uintptr)(__ccgo_up(bp + 8)) != dst0 { // copy 16x8 block if needed
  33070 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8Copy16x8})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), dst0)
  33071 	}
  33072 	if (*VP8EncIterator)(unsafe.Pointer(it)).Ftop_derr != libc.UintptrFromInt32(0) { // store diffusion errors for next block
  33073 		StoreDiffusionErrors(tls, it, rd)
  33074 	}
  33075 }
  33076 
  33077 //------------------------------------------------------------------------------
  33078 // Final reconstruction and quantization.
  33079 
  33080 func SimpleQuantize(tls *libc.TLS, it uintptr, rd uintptr) {
  33081 	var dst, enc, src uintptr
  33082 	var is_i16, mode, nz int32
  33083 	_, _, _, _, _, _ = dst, enc, is_i16, mode, nz, src
  33084 	enc = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc
  33085 	is_i16 = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == libc.Int32FromInt32(1))
  33086 	nz = 0
  33087 	if is_i16 != 0 {
  33088 		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))))
  33089 	} else {
  33090 		VP8IteratorStartI4(tls, it)
  33091 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  33092 			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))))
  33093 			src = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33094 			dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33095 			MakeIntra4Preds(tls, it)
  33096 			nz = nz | ReconstructIntra4(tls, it, rd+72+uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4)*32, src, dst, mode)<<(*VP8EncIterator)(unsafe.Pointer(it)).Fi4
  33097 		}
  33098 	}
  33099 	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)))
  33100 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = libc.Uint32FromInt32(nz)
  33101 }
  33102 
  33103 // C documentation
  33104 //
  33105 //	// Refine intra16/intra4 sub-modes based on distortion only (not rate).
  33106 func RefineUsingDistortion(tls *libc.TLS, it uintptr, try_both_modes int32, refine_uv_mode int32, rd uintptr) {
  33107 	bp := tls.Alloc(16)
  33108 	defer tls.Free(16)
  33109 	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
  33110 	var best_i4_score, best_score, best_uv_score, bit_limit, i4_bit_sum, score, score1, score2, score_i4 score_t
  33111 	var dqm, mode_costs, ref, ref1, ref2, src1, src2, src3, tmp_dst, v3 uintptr
  33112 	var v1 int64
  33113 	var _ /* v at bp+0 */ uint32_t
  33114 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  33115 	best_score = libc.Int64FromInt64(0x7fffffffffffff)
  33116 	nz = 0
  33117 	is_i16 = libc.BoolInt32(try_both_modes != 0 || int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x3>>0)) == int32(1))
  33118 	dqm = (*VP8EncIterator)(unsafe.Pointer(it)).Fenc + 608 + uintptr(int32(uint32(*(*uint8)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fmb + 0))&0x60>>5)))*744
  33119 	// Some empiric constants, of approximate order of magnitude.
  33120 	lambda_d_i16 = int32(106)
  33121 	lambda_d_i4 = int32(11)
  33122 	lambda_d_uv = int32(120)
  33123 	score_i4 = (*VP8SegmentInfo)(unsafe.Pointer(dqm)).Fi4_penalty
  33124 	i4_bit_sum = 0
  33125 	if try_both_modes != 0 {
  33126 		v1 = int64((*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmb_header_limit)
  33127 	} else {
  33128 		v1 = libc.Int64FromInt64(0x7fffffffffffff)
  33129 	}
  33130 	bit_limit = v1   // no early-out allowed
  33131 	if is_i16 != 0 { // First, evaluate Intra16 distortion
  33132 		best_mode = -int32(1)
  33133 		src1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC))
  33134 		mode = 0
  33135 		for {
  33136 			if !(mode < int32(NUM_PRED_MODES)) {
  33137 				break
  33138 			}
  33139 			ref = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I16ModeOffsets[mode])
  33140 			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)
  33141 			if mode > 0 && libc.Int64FromUint16(VP8FixedCostsI16[mode]) > bit_limit {
  33142 				goto _2
  33143 			}
  33144 			if score < best_score {
  33145 				best_mode = mode
  33146 				best_score = score
  33147 			}
  33148 			goto _2
  33149 		_2:
  33150 			;
  33151 			mode = mode + 1
  33152 		}
  33153 		if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 || (*VP8EncIterator)(unsafe.Pointer(it)).Fy == 0 {
  33154 			// avoid starting a checkerboard resonance from the border. See bug #432.
  33155 			v3 = src1
  33156 			**(**uint32_t)(__ccgo_up(bp)) = uint32(**(**uint8_t)(__ccgo_up(v3))) * uint32(0x01010101)
  33157 			i = libc.Int32FromInt32(0)
  33158 			for {
  33159 				if !(i < libc.Int32FromInt32(16)) {
  33160 					break
  33161 				}
  33162 				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 {
  33163 					v5 = 0
  33164 					goto _6
  33165 				}
  33166 				v3 = v3 + uintptr(BPS)
  33167 				goto _4
  33168 			_4:
  33169 				;
  33170 				i = i + 1
  33171 			}
  33172 			v5 = int32(1)
  33173 			goto _6
  33174 		_6:
  33175 			if v5 != 0 {
  33176 				if (*VP8EncIterator)(unsafe.Pointer(it)).Fx == 0 {
  33177 					v7 = 0
  33178 				} else {
  33179 					v7 = int32(2)
  33180 				}
  33181 				best_mode = v7
  33182 				try_both_modes = 0 // stick to i16
  33183 			}
  33184 		}
  33185 		VP8SetIntra16Mode(tls, it, best_mode)
  33186 		// we'll reconstruct later, if i16 mode actually gets selected
  33187 	}
  33188 	// Next, evaluate Intra4
  33189 	if try_both_modes != 0 || !(is_i16 != 0) {
  33190 		// We don't evaluate the rate here, but just account for it through a
  33191 		// constant penalty (i4 mode usually needs more bits compared to i16).
  33192 		is_i16 = 0
  33193 		VP8IteratorStartI4(tls, it)
  33194 		for cond := true; cond; cond = VP8IteratorRotateI4(tls, it, (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2+uintptr(libc.Int32FromInt32(Y_OFF_ENC))) != 0 {
  33195 			best_i4_mode = -int32(1)
  33196 			best_i4_score = libc.Int64FromInt64(0x7fffffffffffff)
  33197 			src2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33198 			mode_costs = GetCostModeI4(tls, it, rd+844)
  33199 			MakeIntra4Preds(tls, it)
  33200 			mode = 0
  33201 			for {
  33202 				if !(mode < int32(NUM_BMODES)) {
  33203 					break
  33204 				}
  33205 				ref1 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8I4ModeOffsets[mode])
  33206 				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)
  33207 				if score1 < best_i4_score {
  33208 					best_i4_mode = mode
  33209 					best_i4_score = score1
  33210 				}
  33211 				goto _8
  33212 			_8:
  33213 				;
  33214 				mode = mode + 1
  33215 			}
  33216 			i4_bit_sum = i4_bit_sum + libc.Int64FromUint16(**(**uint16_t)(__ccgo_up(mode_costs + uintptr(best_i4_mode)*2)))
  33217 			**(**uint8_t)(__ccgo_up(rd + 844 + uintptr((*VP8EncIterator)(unsafe.Pointer(it)).Fi4))) = libc.Uint8FromInt32(best_i4_mode)
  33218 			score_i4 = score_i4 + best_i4_score
  33219 			if score_i4 >= best_score || i4_bit_sum > bit_limit {
  33220 				// Intra4 won't be better than Intra16. Bail out and pick Intra16.
  33221 				is_i16 = int32(1)
  33222 				break
  33223 			} else { // reconstruct partial block inside yuv_out2 buffer
  33224 				tmp_dst = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_out2 + uintptr(libc.Int32FromInt32(Y_OFF_ENC)) + uintptr(VP8Scan[(*VP8EncIterator)(unsafe.Pointer(it)).Fi4])
  33225 				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
  33226 			}
  33227 		}
  33228 	}
  33229 	// Final reconstruction, depending on which mode is selected.
  33230 	if !(is_i16 != 0) {
  33231 		VP8SetIntra4Mode(tls, it, rd+844)
  33232 		SwapOut(tls, it)
  33233 		best_score = score_i4
  33234 	} else {
  33235 		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))))
  33236 	}
  33237 	// ... and UV!
  33238 	if refine_uv_mode != 0 {
  33239 		best_mode1 = -int32(1)
  33240 		best_uv_score = libc.Int64FromInt64(0x7fffffffffffff)
  33241 		src3 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_in + uintptr(libc.Int32FromInt32(U_OFF_ENC))
  33242 		mode = 0
  33243 		for {
  33244 			if !(mode < int32(NUM_PRED_MODES)) {
  33245 				break
  33246 			}
  33247 			ref2 = (*VP8EncIterator)(unsafe.Pointer(it)).Fyuv_p + uintptr(VP8UVModeOffsets[mode])
  33248 			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)
  33249 			if score2 < best_uv_score {
  33250 				best_mode1 = mode
  33251 				best_uv_score = score2
  33252 			}
  33253 			goto _9
  33254 		_9:
  33255 			;
  33256 			mode = mode + 1
  33257 		}
  33258 		VP8SetIntraUVMode(tls, it, best_mode1)
  33259 	}
  33260 	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)))
  33261 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fnz = libc.Uint32FromInt32(nz)
  33262 	(*VP8ModeScore)(unsafe.Pointer(rd)).Fscore = best_score
  33263 }
  33264 
  33265 //------------------------------------------------------------------------------
  33266 // Entry point
  33267 
  33268 func VP8Decimate(tls *libc.TLS, it uintptr, rd uintptr, rd_opt VP8RDLevel) (r int32) {
  33269 	var is_skipped, method int32
  33270 	_, _ = is_skipped, method
  33271 	method = (*VP8Encoder)(unsafe.Pointer((*VP8EncIterator)(unsafe.Pointer(it)).Fenc)).Fmethod
  33272 	InitScore(tls, rd)
  33273 	// We can perform predictions for Luma16x16 and Chroma8x8 already.
  33274 	// Luma4x4 predictions needs to be done as-we-go.
  33275 	VP8MakeLuma16Preds(tls, it)
  33276 	VP8MakeChroma8Preds(tls, it)
  33277 	if rd_opt > int32(RD_OPT_NONE) {
  33278 		(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = libc.BoolInt32(rd_opt >= int32(RD_OPT_TRELLIS_ALL))
  33279 		PickBestIntra16(tls, it, rd)
  33280 		if method >= int32(2) {
  33281 			PickBestIntra4(tls, it, rd)
  33282 		}
  33283 		PickBestUV(tls, it, rd)
  33284 		if rd_opt == int32(RD_OPT_TRELLIS) { // finish off with trellis-optim now
  33285 			(*VP8EncIterator)(unsafe.Pointer(it)).Fdo_trellis = int32(1)
  33286 			SimpleQuantize(tls, it, rd)
  33287 		}
  33288 	} else {
  33289 		// At this point we have heuristically decided intra16 / intra4.
  33290 		// For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower).
  33291 		// For method <= 1, we don't re-examine the decision but just go ahead with
  33292 		// quantization/reconstruction.
  33293 		RefineUsingDistortion(tls, it, libc.BoolInt32(method >= int32(2)), libc.BoolInt32(method >= int32(1)), rd)
  33294 	}
  33295 	is_skipped = libc.BoolInt32((*VP8ModeScore)(unsafe.Pointer(rd)).Fnz == uint32(0))
  33296 	VP8SetSkip(tls, it, is_skipped)
  33297 	return is_skipped
  33298 }
  33299 
  33300 const ARGB_BLACK2 = 0xff000000
  33301 const VP8_SIGNATURE1 = 10289450
  33302 
  33303 //------------------------------------------------------------------------------
  33304 // Helper functions
  33305 
  33306 func IsVP8XNeeded(tls *libc.TLS, enc uintptr) (r int32) {
  33307 	return libc.BoolInt32(!!((*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0)) // Currently the only case when VP8X is needed.
  33308 	// This could change in the future.
  33309 }
  33310 
  33311 func PutPaddingByte(tls *libc.TLS, pic uintptr) (r int32) {
  33312 	bp := tls.Alloc(16)
  33313 	defer tls.Free(16)
  33314 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  33315 	**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  33316 	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))
  33317 }
  33318 
  33319 //------------------------------------------------------------------------------
  33320 // Writers for header's various pieces (in order of appearance)
  33321 
  33322 func PutRIFFHeader(tls *libc.TLS, enc uintptr, riff_size size_t) (r WebPEncodingError1) {
  33323 	bp := tls.Alloc(16)
  33324 	defer tls.Free(16)
  33325 	var pic, v1, v3, v5 uintptr
  33326 	var v2 uint32_t
  33327 	var v4, v6 int32
  33328 	var _ /* riff at bp+0 */ [12]uint8_t
  33329 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33330 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33331 	**(**[12]uint8_t)(__ccgo_up(bp)) = [12]uint8_t{
  33332 		0:  uint8('R'),
  33333 		1:  uint8('I'),
  33334 		2:  uint8('F'),
  33335 		3:  uint8('F'),
  33336 		8:  uint8('W'),
  33337 		9:  uint8('E'),
  33338 		10: uint8('B'),
  33339 		11: uint8('P'),
  33340 	}
  33341 	v1 = bp + uintptr(TAG_SIZE)
  33342 	v2 = uint32(riff_size)
  33343 	v3 = v1
  33344 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33345 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33346 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33347 	v5 = v1 + uintptr(2)
  33348 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33349 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33350 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33351 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(12), pic) != 0) {
  33352 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33353 	}
  33354 	return int32(VP8_ENC_OK)
  33355 }
  33356 
  33357 func PutVP8XHeader(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33358 	bp := tls.Alloc(32)
  33359 	defer tls.Free(32)
  33360 	var flags, v2 uint32_t
  33361 	var pic, v1, v3, v5 uintptr
  33362 	var v4, v6 int32
  33363 	var _ /* vp8x at bp+0 */ [18]uint8_t
  33364 	_, _, _, _, _, _, _, _ = flags, pic, v1, v2, v3, v4, v5, v6
  33365 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33366 	**(**[18]uint8_t)(__ccgo_up(bp)) = [18]uint8_t{
  33367 		0: uint8('V'),
  33368 		1: uint8('P'),
  33369 		2: uint8('8'),
  33370 		3: uint8('X'),
  33371 	}
  33372 	flags = uint32(0)
  33373 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33374 		flags = flags | uint32(ALPHA_FLAG)
  33375 	}
  33376 	v1 = bp + uintptr(TAG_SIZE)
  33377 	v2 = uint32(VP8X_CHUNK_SIZE)
  33378 	v3 = v1
  33379 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33380 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33381 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33382 	v5 = v1 + uintptr(2)
  33383 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33384 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33385 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33386 	v1 = bp + uintptr(CHUNK_HEADER_SIZE)
  33387 	v2 = flags
  33388 	v3 = v1
  33389 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33390 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33391 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33392 	v5 = v1 + uintptr(2)
  33393 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33394 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33395 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33396 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(4)
  33397 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  33398 	v3 = v1
  33399 	v6 = v4 & int32(0xffff)
  33400 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33401 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33402 	**(**uint8_t)(__ccgo_up(v1 + 2)) = libc.Uint8FromInt32(v4 >> int32(16) & int32(0xff))
  33403 	v1 = bp + uintptr(CHUNK_HEADER_SIZE) + uintptr(7)
  33404 	v4 = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  33405 	v3 = v1
  33406 	v6 = v4 & int32(0xffff)
  33407 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33408 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33409 	**(**uint8_t)(__ccgo_up(v1 + 2)) = libc.Uint8FromInt32(v4 >> int32(16) & int32(0xff))
  33410 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(18), pic) != 0) {
  33411 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33412 	}
  33413 	return int32(VP8_ENC_OK)
  33414 }
  33415 
  33416 func PutAlphaChunk(tls *libc.TLS, enc uintptr) (r WebPEncodingError1) {
  33417 	bp := tls.Alloc(16)
  33418 	defer tls.Free(16)
  33419 	var pic, v1, v3, v5 uintptr
  33420 	var v2 uint32_t
  33421 	var v4, v6 int32
  33422 	var _ /* alpha_chunk_hdr at bp+0 */ [8]uint8_t
  33423 	_, _, _, _, _, _, _ = pic, v1, v2, v3, v4, v5, v6
  33424 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33425 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33426 		0: uint8('A'),
  33427 		1: uint8('L'),
  33428 		2: uint8('P'),
  33429 		3: uint8('H'),
  33430 	}
  33431 	// Alpha chunk header.
  33432 	v1 = bp + uintptr(TAG_SIZE)
  33433 	v2 = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size
  33434 	v3 = v1
  33435 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33436 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33437 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33438 	v5 = v1 + uintptr(2)
  33439 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33440 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33441 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33442 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33443 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33444 	}
  33445 	// Alpha chunk data.
  33446 	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) {
  33447 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33448 	}
  33449 	// Padding.
  33450 	if (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1) != 0 && !(PutPaddingByte(tls, pic) != 0) {
  33451 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33452 	}
  33453 	return int32(VP8_ENC_OK)
  33454 }
  33455 
  33456 func PutVP8Header(tls *libc.TLS, pic uintptr, vp8_size size_t) (r WebPEncodingError1) {
  33457 	bp := tls.Alloc(16)
  33458 	defer tls.Free(16)
  33459 	var v1, v3, v5 uintptr
  33460 	var v2 uint32_t
  33461 	var v4, v6 int32
  33462 	var _ /* vp8_chunk_hdr at bp+0 */ [8]uint8_t
  33463 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  33464 	**(**[8]uint8_t)(__ccgo_up(bp)) = [8]uint8_t{
  33465 		0: uint8('V'),
  33466 		1: uint8('P'),
  33467 		2: uint8('8'),
  33468 		3: uint8(' '),
  33469 	}
  33470 	v1 = bp + uintptr(TAG_SIZE)
  33471 	v2 = uint32(vp8_size)
  33472 	v3 = v1
  33473 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  33474 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  33475 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  33476 	v5 = v1 + uintptr(2)
  33477 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  33478 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  33479 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  33480 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(8), pic) != 0) {
  33481 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33482 	}
  33483 	return int32(VP8_ENC_OK)
  33484 }
  33485 
  33486 func PutVP8FrameHeader(tls *libc.TLS, pic uintptr, profile int32, size0 size_t) (r WebPEncodingError1) {
  33487 	bp := tls.Alloc(16)
  33488 	defer tls.Free(16)
  33489 	var bits uint32_t
  33490 	var _ /* vp8_frm_hdr at bp+0 */ [10]uint8_t
  33491 	_ = bits
  33492 	if size0 >= libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(19)) { // partition #0 is too big to fit
  33493 		return int32(VP8_ENC_ERROR_PARTITION0_OVERFLOW)
  33494 	}
  33495 	// Paragraph 9.1.
  33496 	bits = libc.Uint32FromInt32(0|profile<<int32(1)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(4)) | uint32(size0)<<libc.Int32FromInt32(5) // partition length (19b)
  33497 	(**(**[10]uint8_t)(__ccgo_up(bp)))[0] = uint8(bits >> libc.Int32FromInt32(0) & uint32(0xff))
  33498 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(1)] = uint8(bits >> libc.Int32FromInt32(8) & uint32(0xff))
  33499 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(2)] = uint8(bits >> libc.Int32FromInt32(16) & uint32(0xff))
  33500 	// signature
  33501 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(3)] = libc.Uint8FromInt32(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(16) & libc.Int32FromInt32(0xff))
  33502 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(4)] = libc.Uint8FromInt32(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff))
  33503 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(5)] = libc.Uint8FromInt32(libc.Int32FromInt32(VP8_SIGNATURE1) >> libc.Int32FromInt32(0) & libc.Int32FromInt32(0xff))
  33504 	// dimensions
  33505 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(6)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fwidth & int32(0xff))
  33506 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(7)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fwidth >> int32(8))
  33507 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(8)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fheight & int32(0xff))
  33508 	(**(**[10]uint8_t)(__ccgo_up(bp)))[int32(9)] = libc.Uint8FromInt32((*WebPPicture)(unsafe.Pointer(pic)).Fheight >> int32(8))
  33509 	if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(10), pic) != 0) {
  33510 		return int32(VP8_ENC_ERROR_BAD_WRITE)
  33511 	}
  33512 	return int32(VP8_ENC_OK)
  33513 }
  33514 
  33515 // C documentation
  33516 //
  33517 //	// WebP Headers.
  33518 func PutWebPHeaders(tls *libc.TLS, enc uintptr, size0 size_t, vp8_size size_t, riff_size size_t) (r int32) {
  33519 	var err WebPEncodingError1
  33520 	var pic uintptr
  33521 	_, _ = err, pic
  33522 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33523 	err = int32(VP8_ENC_OK)
  33524 	// RIFF header.
  33525 	err = PutRIFFHeader(tls, enc, riff_size)
  33526 	if err != int32(VP8_ENC_OK) {
  33527 		goto Error
  33528 	}
  33529 	// VP8X.
  33530 	if IsVP8XNeeded(tls, enc) != 0 {
  33531 		err = PutVP8XHeader(tls, enc)
  33532 		if err != int32(VP8_ENC_OK) {
  33533 			goto Error
  33534 		}
  33535 	}
  33536 	// Alpha.
  33537 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 {
  33538 		err = PutAlphaChunk(tls, enc)
  33539 		if err != int32(VP8_ENC_OK) {
  33540 			goto Error
  33541 		}
  33542 	}
  33543 	// VP8 header.
  33544 	err = PutVP8Header(tls, pic, vp8_size)
  33545 	if err != int32(VP8_ENC_OK) {
  33546 		goto Error
  33547 	}
  33548 	// VP8 frame header.
  33549 	err = PutVP8FrameHeader(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fprofile, size0)
  33550 	if err != int32(VP8_ENC_OK) {
  33551 		goto Error
  33552 	}
  33553 	// All OK.
  33554 	return int32(1)
  33555 	// Error.
  33556 	goto Error
  33557 Error:
  33558 	;
  33559 	return WebPEncodingSetError(tls, pic, err)
  33560 	return r
  33561 }
  33562 
  33563 // C documentation
  33564 //
  33565 //	// Segmentation header
  33566 func PutSegmentHeader(tls *libc.TLS, bw uintptr, enc uintptr) {
  33567 	var hdr, proba uintptr
  33568 	var s, update_data int32
  33569 	_, _, _, _ = hdr, proba, s, update_data
  33570 	hdr = enc + 32
  33571 	proba = enc + 3616
  33572 	if VP8PutBitUniform(tls, bw, libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))) != 0 {
  33573 		// We always 'update' the quant and filter strength values
  33574 		update_data = int32(1)
  33575 		VP8PutBitUniform(tls, bw, (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map)
  33576 		if VP8PutBitUniform(tls, bw, update_data) != 0 {
  33577 			// we always use absolute values, not relative ones
  33578 			VP8PutBitUniform(tls, bw, int32(1)) // (segment_feature_mode = 1. Paragraph 9.3.)
  33579 			s = 0
  33580 			for {
  33581 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33582 					break
  33583 				}
  33584 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Fquant, int32(7))
  33585 				goto _1
  33586 			_1:
  33587 				;
  33588 				s = s + 1
  33589 			}
  33590 			s = 0
  33591 			for {
  33592 				if !(s < int32(NUM_MB_SEGMENTS)) {
  33593 					break
  33594 				}
  33595 				VP8PutSignedBits(tls, bw, (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(s)*744))).Ffstrength, int32(6))
  33596 				goto _2
  33597 			_2:
  33598 				;
  33599 				s = s + 1
  33600 			}
  33601 		}
  33602 		if (*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map != 0 {
  33603 			s = 0
  33604 			for {
  33605 				if !(s < int32(3)) {
  33606 					break
  33607 				}
  33608 				if VP8PutBitUniform(tls, bw, libc.BoolInt32(uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))) != uint32(255))) != 0 {
  33609 					VP8PutBits(tls, bw, uint32(**(**uint8_t)(__ccgo_up(proba + uintptr(s)))), int32(8))
  33610 				}
  33611 				goto _3
  33612 			_3:
  33613 				;
  33614 				s = s + 1
  33615 			}
  33616 		}
  33617 	}
  33618 }
  33619 
  33620 // C documentation
  33621 //
  33622 //	// Filtering parameters header
  33623 func PutFilterHeader(tls *libc.TLS, bw uintptr, hdr uintptr) {
  33624 	var need_update, use_lf_delta int32
  33625 	_, _ = need_update, use_lf_delta
  33626 	use_lf_delta = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33627 	VP8PutBitUniform(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple)
  33628 	VP8PutBits(tls, bw, libc.Uint32FromInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel), int32(6))
  33629 	VP8PutBits(tls, bw, libc.Uint32FromInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness), int32(3))
  33630 	if VP8PutBitUniform(tls, bw, use_lf_delta) != 0 {
  33631 		// '0' is the default value for i4x4_lf_delta at frame #0.
  33632 		need_update = libc.BoolInt32((*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta != libc.Int32FromInt32(0))
  33633 		if VP8PutBitUniform(tls, bw, need_update) != 0 {
  33634 			// we don't use ref_lf_delta => emit four 0 bits
  33635 			VP8PutBits(tls, bw, uint32(0), int32(4))
  33636 			// we use mode_lf_delta for i4x4
  33637 			VP8PutSignedBits(tls, bw, (*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta, int32(6))
  33638 			VP8PutBits(tls, bw, uint32(0), int32(3)) // all others unused
  33639 		}
  33640 	}
  33641 }
  33642 
  33643 // C documentation
  33644 //
  33645 //	// Nominal quantization parameters
  33646 func PutQuant(tls *libc.TLS, bw uintptr, enc uintptr) {
  33647 	VP8PutBits(tls, bw, libc.Uint32FromInt32((*VP8Encoder)(unsafe.Pointer(enc)).Fbase_quant), int32(7))
  33648 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y1_dc, int32(4))
  33649 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_dc, int32(4))
  33650 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_y2_ac, int32(4))
  33651 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_dc, int32(4))
  33652 	VP8PutSignedBits(tls, bw, (*VP8Encoder)(unsafe.Pointer(enc)).Fdq_uv_ac, int32(4))
  33653 }
  33654 
  33655 // C documentation
  33656 //
  33657 //	// Partition sizes
  33658 func EmitPartitionsSize(tls *libc.TLS, enc uintptr, pic uintptr) (r int32) {
  33659 	bp := tls.Alloc(32)
  33660 	defer tls.Free(32)
  33661 	var p int32
  33662 	var part_size, v2 size_t
  33663 	var _ /* buf at bp+0 */ [21]uint8_t
  33664 	_, _, _ = p, part_size, v2
  33665 	p = 0
  33666 	for {
  33667 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)) {
  33668 			break
  33669 		}
  33670 		v2 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33671 		goto _3
  33672 	_3:
  33673 		part_size = v2
  33674 		if part_size >= libc.Uint64FromInt32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(24)) {
  33675 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_PARTITION_OVERFLOW))
  33676 		}
  33677 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+0] = uint8(part_size >> libc.Int32FromInt32(0) & uint64(0xff))
  33678 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(1)] = uint8(part_size >> libc.Int32FromInt32(8) & uint64(0xff))
  33679 		(**(**[21]uint8_t)(__ccgo_up(bp)))[int32(3)*p+int32(2)] = uint8(part_size >> libc.Int32FromInt32(16) & uint64(0xff))
  33680 		goto _1
  33681 	_1:
  33682 		;
  33683 		p = p + 1
  33684 	}
  33685 	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) {
  33686 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33687 	}
  33688 	return int32(1)
  33689 }
  33690 
  33691 //------------------------------------------------------------------------------
  33692 
  33693 func GeneratePartition0(tls *libc.TLS, enc uintptr) (r int32) {
  33694 	var bw1, v1 uintptr
  33695 	var mb_size, v4, v5, v6 int32
  33696 	var nb_bits, pos1, pos2, pos3, v2 uint64_t
  33697 	_, _, _, _, _, _, _, _, _, _, _ = bw1, mb_size, nb_bits, pos1, pos2, pos3, v1, v2, v4, v5, v6
  33698 	bw1 = enc + 64
  33699 	mb_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w * (*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h
  33700 	v1 = bw1
  33701 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33702 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33703 	goto _3
  33704 _3:
  33705 	pos1 = v2
  33706 	if !(VP8BitWriterInit(tls, bw1, libc.Uint64FromInt32(mb_size*int32(7)/int32(8))) != 0) { // ~7 bits per macroblock
  33707 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33708 	}
  33709 	VP8PutBitUniform(tls, bw1, 0) // colorspace
  33710 	VP8PutBitUniform(tls, bw1, 0) // clamp type
  33711 	PutSegmentHeader(tls, bw1, enc)
  33712 	PutFilterHeader(tls, bw1, enc+16)
  33713 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(8) {
  33714 		v4 = int32(3)
  33715 	} else {
  33716 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(4) {
  33717 			v5 = int32(2)
  33718 		} else {
  33719 			if (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts == int32(2) {
  33720 				v6 = int32(1)
  33721 			} else {
  33722 				v6 = 0
  33723 			}
  33724 			v5 = v6
  33725 		}
  33726 		v4 = v5
  33727 	}
  33728 	VP8PutBits(tls, bw1, libc.Uint32FromInt32(v4), int32(2))
  33729 	PutQuant(tls, bw1, enc)
  33730 	VP8PutBitUniform(tls, bw1, 0) // no proba update
  33731 	VP8WriteProbas(tls, bw1, enc+3616)
  33732 	v1 = bw1
  33733 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33734 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33735 	goto _9
  33736 _9:
  33737 	pos2 = v2
  33738 	VP8CodeIntraModes(tls, enc)
  33739 	VP8BitWriterFinish(tls, bw1)
  33740 	v1 = bw1
  33741 	nb_bits = libc.Uint64FromInt32(int32(8) + (*VP8BitWriter)(unsafe.Pointer(v1)).Fnb_bits)
  33742 	v2 = ((*VP8BitWriter)(unsafe.Pointer(v1)).Fpos+libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(v1)).Frun))*uint64(8) + nb_bits
  33743 	goto _12
  33744 _12:
  33745 	pos3 = v2
  33746 	if (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats != 0 {
  33747 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats + 36)) = libc.Int32FromUint64((pos2 - pos1 + libc.Uint64FromInt32(7)) >> libc.Int32FromInt32(3))
  33748 		**(**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))
  33749 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats)).Falpha_data_size = libc.Int32FromUint32((*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size)
  33750 	}
  33751 	if (*VP8BitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  33752 		return WebPEncodingSetError(tls, (*VP8Encoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  33753 	}
  33754 	return int32(1)
  33755 }
  33756 
  33757 func VP8EncFreeBitWriters(tls *libc.TLS, enc uintptr) {
  33758 	var p int32
  33759 	_ = p
  33760 	VP8BitWriterWipeOut(tls, enc+64)
  33761 	p = 0
  33762 	for {
  33763 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33764 			break
  33765 		}
  33766 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48)
  33767 		goto _1
  33768 	_1:
  33769 		;
  33770 		p = p + 1
  33771 	}
  33772 }
  33773 
  33774 func VP8EncWrite(tls *libc.TLS, enc uintptr) (r int32) {
  33775 	var buf, bw2, part0, pic, v6 uintptr
  33776 	var final_percent, ok, p, percent_per_part, task_percent int32
  33777 	var pad, riff_size, size, size0, vp8_size, v1 size_t
  33778 	var padded_alpha_size uint32_t
  33779 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  33780 	pic = (*VP8Encoder)(unsafe.Pointer(enc)).Fpic
  33781 	bw2 = enc + 64
  33782 	task_percent = int32(19)
  33783 	percent_per_part = task_percent / (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts
  33784 	final_percent = (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent + task_percent
  33785 	ok = 0
  33786 	// Partition #0 with header and partition sizes
  33787 	ok = GeneratePartition0(tls, enc)
  33788 	if !(ok != 0) {
  33789 		return 0
  33790 	}
  33791 	// Compute VP8 size
  33792 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33793 	goto _2
  33794 _2:
  33795 	vp8_size = uint64(VP8_FRAME_HEADER_SIZE) + v1 + libc.Uint64FromInt32(int32(3)*((*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts-int32(1)))
  33796 	p = 0
  33797 	for {
  33798 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33799 			break
  33800 		}
  33801 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33802 		goto _5
  33803 	_5:
  33804 		vp8_size = vp8_size + v1
  33805 		goto _3
  33806 	_3:
  33807 		;
  33808 		p = p + 1
  33809 	}
  33810 	pad = vp8_size & uint64(1)
  33811 	vp8_size = vp8_size + pad
  33812 	// Compute RIFF size
  33813 	// At the minimum it is: "WEBPVP8 nnnn" + VP8 data size.
  33814 	riff_size = libc.Uint64FromInt32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8_size
  33815 	if IsVP8XNeeded(tls, enc) != 0 { // Add size for: VP8X header + data.
  33816 		riff_size = riff_size + libc.Uint64FromInt32(libc.Int32FromInt32(CHUNK_HEADER_SIZE)+libc.Int32FromInt32(VP8X_CHUNK_SIZE))
  33817 	}
  33818 	if (*VP8Encoder)(unsafe.Pointer(enc)).Fhas_alpha != 0 { // Add size for: ALPH header + data.
  33819 		padded_alpha_size = (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size + (*VP8Encoder)(unsafe.Pointer(enc)).Falpha_data_size&uint32(1)
  33820 		riff_size = riff_size + uint64(uint32(CHUNK_HEADER_SIZE)+padded_alpha_size)
  33821 	}
  33822 	// RIFF size should fit in 32-bits.
  33823 	if riff_size > uint64(0xfffffffe) {
  33824 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_FILE_TOO_BIG))
  33825 	}
  33826 	// Emit headers and partition #0
  33827 	v6 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fbuf
  33828 	goto _7
  33829 _7:
  33830 	part0 = v6
  33831 	v1 = (*VP8BitWriter)(unsafe.Pointer(bw2)).Fpos
  33832 	goto _9
  33833 _9:
  33834 	size0 = v1
  33835 	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)
  33836 	VP8BitWriterWipeOut(tls, bw2) // will free the internal buffer.
  33837 	// Token partitions
  33838 	p = 0
  33839 	for {
  33840 		if !(p < (*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts) {
  33841 			break
  33842 		}
  33843 		v6 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fbuf
  33844 		goto _12
  33845 	_12:
  33846 		buf = v6
  33847 		v1 = (*VP8BitWriter)(unsafe.Pointer(enc + 112 + uintptr(p)*48)).Fpos
  33848 		goto _14
  33849 	_14:
  33850 		size = v1
  33851 		if size != 0 {
  33852 			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)
  33853 		}
  33854 		VP8BitWriterWipeOut(tls, enc+112+uintptr(p)*48) // will free the internal buffer.
  33855 		ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, (*VP8Encoder)(unsafe.Pointer(enc)).Fpercent+percent_per_part, enc+536) != 0)
  33856 		goto _10
  33857 	_10:
  33858 		;
  33859 		p = p + 1
  33860 	}
  33861 	// Padding byte
  33862 	if ok != 0 && pad != 0 {
  33863 		ok = PutPaddingByte(tls, pic)
  33864 	}
  33865 	(*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size = libc.Int32FromUint64(libc.Uint64FromInt32(CHUNK_HEADER_SIZE) + riff_size)
  33866 	ok = libc.BoolInt32(ok != 0 && WebPReportProgress(tls, pic, final_percent, enc+536) != 0)
  33867 	if !(ok != 0) {
  33868 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  33869 	}
  33870 	return ok
  33871 }
  33872 
  33873 const MIN_PAGE_SIZE = 8192
  33874 
  33875 type VP8Tokens = struct {
  33876 	Fnext uintptr
  33877 }
  33878 
  33879 //------------------------------------------------------------------------------
  33880 
  33881 // Copyright 2011 Google Inc. All Rights Reserved.
  33882 //
  33883 // Use of this source code is governed by a BSD-style license
  33884 // that can be found in the COPYING file in the root of the source
  33885 // tree. An additional intellectual property rights grant can be found
  33886 // in the file PATENTS. All contributing project authors may
  33887 // be found in the AUTHORS file in the root of the source tree.
  33888 // -----------------------------------------------------------------------------
  33889 //
  33890 //   WebP encoder: internal header.
  33891 //
  33892 // Author: Skal (pascal.massimino@gmail.com)
  33893 
  33894 // Copyright 2011 Google Inc. All Rights Reserved.
  33895 //
  33896 // Use of this source code is governed by a BSD-style license
  33897 // that can be found in the COPYING file in the root of the source
  33898 // tree. An additional intellectual property rights grant can be found
  33899 // in the file PATENTS. All contributing project authors may
  33900 // be found in the AUTHORS file in the root of the source tree.
  33901 // -----------------------------------------------------------------------------
  33902 //
  33903 // Bit writing and boolean coder
  33904 //
  33905 // Author: Skal (pascal.massimino@gmail.com)
  33906 
  33907 // Copyright 2012 Google Inc. All Rights Reserved.
  33908 //
  33909 // Use of this source code is governed by a BSD-style license
  33910 // that can be found in the COPYING file in the root of the source
  33911 // tree. An additional intellectual property rights grant can be found
  33912 // in the file PATENTS. All contributing project authors may
  33913 // be found in the AUTHORS file in the root of the source tree.
  33914 // -----------------------------------------------------------------------------
  33915 //
  33916 // Misc. common utility functions
  33917 //
  33918 // Authors: Skal (pascal.massimino@gmail.com)
  33919 //          Urvang (urvang@google.com)
  33920 
  33921 // Copyright 2010 Google Inc. All Rights Reserved.
  33922 //
  33923 // Use of this source code is governed by a BSD-style license
  33924 // that can be found in the COPYING file in the root of the source
  33925 // tree. An additional intellectual property rights grant can be found
  33926 // in the file PATENTS. All contributing project authors may
  33927 // be found in the AUTHORS file in the root of the source tree.
  33928 // -----------------------------------------------------------------------------
  33929 //
  33930 //  Common types + memory wrappers
  33931 //
  33932 // Author: Skal (pascal.massimino@gmail.com)
  33933 
  33934 // we use pages to reduce the number of memcpy()
  33935 
  33936 type token_t = uint16
  33937 
  33938 // Token data is located in memory just after the 'next' field.
  33939 // This macro is used to return their address and hide the trick.
  33940 
  33941 //------------------------------------------------------------------------------
  33942 
  33943 func VP8TBufferInit(tls *libc.TLS, b uintptr, page_size int32) {
  33944 	var v1 int32
  33945 	_ = v1
  33946 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = libc.UintptrFromInt32(0)
  33947 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  33948 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = b
  33949 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = 0
  33950 	if page_size < int32(MIN_PAGE_SIZE) {
  33951 		v1 = int32(MIN_PAGE_SIZE)
  33952 	} else {
  33953 		v1 = page_size
  33954 	}
  33955 	(*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size = v1
  33956 	(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = 0
  33957 }
  33958 
  33959 func VP8TBufferClear(tls *libc.TLS, b uintptr) {
  33960 	var next, p uintptr
  33961 	_, _ = next, p
  33962 	if b != libc.UintptrFromInt32(0) {
  33963 		p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  33964 		for p != libc.UintptrFromInt32(0) {
  33965 			next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  33966 			WebPSafeFree(tls, p)
  33967 			p = next
  33968 		}
  33969 		VP8TBufferInit(tls, b, (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)
  33970 	}
  33971 }
  33972 
  33973 func TBufferNewPage(tls *libc.TLS, b uintptr) (r int32) {
  33974 	var page uintptr
  33975 	var size size_t
  33976 	_, _ = page, size
  33977 	page = libc.UintptrFromInt32(0)
  33978 	if !((*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 != 0) {
  33979 		size = uint64(8) + libc.Uint64FromInt32((*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size)*uint64(2)
  33980 		page = WebPSafeMalloc(tls, uint64(1), size)
  33981 	}
  33982 	if page == libc.UintptrFromInt32(0) {
  33983 		(*VP8TBuffer)(unsafe.Pointer(b)).Ferror1 = int32(1)
  33984 		return 0
  33985 	}
  33986 	(*VP8Tokens)(unsafe.Pointer(page)).Fnext = libc.UintptrFromInt32(0)
  33987 	**(**uintptr)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Flast_page)) = page
  33988 	(*VP8TBuffer)(unsafe.Pointer(b)).Flast_page = page
  33989 	(*VP8TBuffer)(unsafe.Pointer(b)).Fleft = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  33990 	(*VP8TBuffer)(unsafe.Pointer(b)).Ftokens = page + 1*8
  33991 	return int32(1)
  33992 }
  33993 
  33994 //------------------------------------------------------------------------------
  33995 
  33996 func AddToken(tls *libc.TLS, b uintptr, bit1 uint32_t, proba_idx uint32_t, stats1 uintptr) (r uint32_t) {
  33997 	var p proba_t
  33998 	var slot, v1 int32
  33999 	var v2 uintptr
  34000 	_, _, _, _ = p, slot, v1, v2
  34001 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  34002 		v2 = b + 24
  34003 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  34004 		v1 = *(*int32)(unsafe.Pointer(v2))
  34005 		slot = v1
  34006 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit1<<libc.Int32FromInt32(15) | proba_idx)
  34007 	}
  34008 	v1 = libc.Int32FromUint32(bit1)
  34009 	v2 = stats1
  34010 	p = **(**proba_t)(__ccgo_up(v2))
  34011 	if p >= libc.Uint32FromUint32(0xfffe0000) {
  34012 		p = (p + uint32(1)) >> int32(1) & uint32(0x7fff7fff)
  34013 	}
  34014 	p = p + (uint32(0x00010000) + libc.Uint32FromInt32(v1))
  34015 	**(**proba_t)(__ccgo_up(v2)) = p
  34016 	_ = v1
  34017 	goto _5
  34018 _5:
  34019 	;
  34020 	return bit1
  34021 }
  34022 
  34023 func AddConstantToken(tls *libc.TLS, b uintptr, bit uint32_t, proba uint32_t) {
  34024 	var slot, v1 int32
  34025 	var v2 uintptr
  34026 	_, _, _ = slot, v1, v2
  34027 	if (*VP8TBuffer)(unsafe.Pointer(b)).Fleft > 0 || TBufferNewPage(tls, b) != 0 {
  34028 		v2 = b + 24
  34029 		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
  34030 		v1 = *(*int32)(unsafe.Pointer(v2))
  34031 		slot = v1
  34032 		**(**uint16_t)(__ccgo_up((*VP8TBuffer)(unsafe.Pointer(b)).Ftokens + uintptr(slot)*2)) = uint16(bit<<libc.Int32FromInt32(15) | libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14) | proba)
  34033 	}
  34034 }
  34035 
  34036 func VP8RecordCoeffTokens(tls *libc.TLS, ctx int32, res uintptr, tokens uintptr) (r int32) {
  34037 	var base_id, residue, v uint32_t
  34038 	var c, coeff_type, last, mask, n, sign, v1, v2 int32
  34039 	var coeffs, s, tab, v3 uintptr
  34040 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = base_id, c, coeff_type, coeffs, last, mask, n, residue, s, sign, tab, v, v1, v2, v3
  34041 	coeffs = (*VP8Residual)(unsafe.Pointer(res)).Fcoeffs
  34042 	coeff_type = (*VP8Residual)(unsafe.Pointer(res)).Fcoeff_type
  34043 	last = (*VP8Residual)(unsafe.Pointer(res)).Flast
  34044 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  34045 	base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (ctx + int32(NUM_CTX)*(n+int32(NUM_BANDS)*coeff_type)))
  34046 	// should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
  34047 	s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(n)*132 + uintptr(ctx)*44
  34048 	if !(AddToken(tls, tokens, libc.BoolUint32(last >= 0), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  34049 		return 0
  34050 	}
  34051 	for n < int32(16) {
  34052 		v1 = n
  34053 		n = n + 1
  34054 		c = int32(**(**int16_t)(__ccgo_up(coeffs + uintptr(v1)*2)))
  34055 		sign = libc.BoolInt32(c < 0)
  34056 		if sign != 0 {
  34057 			v2 = -c
  34058 		} else {
  34059 			v2 = c
  34060 		}
  34061 		v = libc.Uint32FromInt32(v2)
  34062 		if !(AddToken(tls, tokens, libc.BoolUint32(v != uint32(0)), base_id+uint32(1), s+uintptr(1)*4) != 0) {
  34063 			base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (libc.Int32FromInt32(0) + int32(NUM_CTX)*(libc.Int32FromUint8(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=0
  34064 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132
  34065 			continue
  34066 		}
  34067 		if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(1)), base_id+uint32(2), s+uintptr(2)*4) != 0) {
  34068 			base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (libc.Int32FromInt32(1) + int32(NUM_CTX)*(libc.Int32FromUint8(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=1
  34069 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 1*44
  34070 		} else {
  34071 			if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(4)), base_id+uint32(3), s+uintptr(3)*4) != 0) {
  34072 				if AddToken(tls, tokens, libc.BoolUint32(v != uint32(2)), base_id+uint32(4), s+uintptr(4)*4) != 0 {
  34073 					AddToken(tls, tokens, libc.BoolUint32(v == uint32(4)), base_id+uint32(5), s+uintptr(5)*4)
  34074 				}
  34075 			} else {
  34076 				if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(10)), base_id+uint32(6), s+uintptr(6)*4) != 0) {
  34077 					if !(AddToken(tls, tokens, libc.BoolUint32(v > uint32(6)), base_id+uint32(7), s+uintptr(7)*4) != 0) {
  34078 						AddConstantToken(tls, tokens, libc.BoolUint32(v == uint32(6)), uint32(159))
  34079 					} else {
  34080 						AddConstantToken(tls, tokens, libc.BoolUint32(v >= uint32(9)), uint32(165))
  34081 						AddConstantToken(tls, tokens, libc.BoolUint32(!(v&libc.Uint32FromInt32(1) != 0)), uint32(145))
  34082 					}
  34083 				} else {
  34084 					residue = v - uint32(3)
  34085 					if residue < libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1)) { // VP8Cat3  (3b)
  34086 						AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  34087 						AddToken(tls, tokens, uint32(0), base_id+uint32(9), s+uintptr(9)*4)
  34088 						residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(0))
  34089 						mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(2)
  34090 						tab = uintptr(unsafe.Pointer(&VP8Cat3))
  34091 					} else {
  34092 						if residue < libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2)) { // VP8Cat4  (4b)
  34093 							AddToken(tls, tokens, uint32(0), base_id+uint32(8), s+uintptr(8)*4)
  34094 							AddToken(tls, tokens, uint32(1), base_id+uint32(9), s+uintptr(9)*4)
  34095 							residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(1))
  34096 							mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(3)
  34097 							tab = uintptr(unsafe.Pointer(&VP8Cat4))
  34098 						} else {
  34099 							if residue < libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3)) { // VP8Cat5  (5b)
  34100 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  34101 								AddToken(tls, tokens, uint32(0), base_id+uint32(10), s+uintptr(9)*4)
  34102 								residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(2))
  34103 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(4)
  34104 								tab = uintptr(unsafe.Pointer(&VP8Cat5))
  34105 							} else { // VP8Cat6 (11b)
  34106 								AddToken(tls, tokens, uint32(1), base_id+uint32(8), s+uintptr(8)*4)
  34107 								AddToken(tls, tokens, uint32(1), base_id+uint32(10), s+uintptr(9)*4)
  34108 								residue = residue - libc.Uint32FromInt32(libc.Int32FromInt32(8)<<libc.Int32FromInt32(3))
  34109 								mask = libc.Int32FromInt32(1) << libc.Int32FromInt32(10)
  34110 								tab = uintptr(unsafe.Pointer(&VP8Cat6))
  34111 							}
  34112 						}
  34113 					}
  34114 					for mask != 0 {
  34115 						v3 = tab
  34116 						tab = tab + 1
  34117 						AddConstantToken(tls, tokens, libc.BoolUint32(!!(residue&libc.Uint32FromInt32(mask) != 0)), uint32(**(**uint8_t)(__ccgo_up(v3))))
  34118 						mask = mask >> int32(1)
  34119 					}
  34120 				}
  34121 			}
  34122 			base_id = libc.Uint32FromInt32(int32(NUM_PROBAS) * (libc.Int32FromInt32(2) + int32(NUM_CTX)*(libc.Int32FromUint8(VP8EncBands[n])+int32(NUM_BANDS)*coeff_type))) // ctx=2
  34123 			s = (*VP8Residual)(unsafe.Pointer(res)).Fstats + uintptr(VP8EncBands[n])*132 + 2*44
  34124 		}
  34125 		AddConstantToken(tls, tokens, libc.Uint32FromInt32(sign), uint32(128))
  34126 		if n == int32(16) || !(AddToken(tls, tokens, libc.BoolUint32(n <= last), base_id+uint32(0), s+uintptr(0)*4) != 0) {
  34127 			return int32(1) // EOB
  34128 		}
  34129 	}
  34130 	return int32(1)
  34131 }
  34132 
  34133 //------------------------------------------------------------------------------
  34134 // Final coding pass, with known probabilities
  34135 
  34136 func VP8EmitTokens(tls *libc.TLS, b uintptr, bw uintptr, probas uintptr, final_pass int32) (r int32) {
  34137 	var N, bit, n, v1, v2 int32
  34138 	var next, p, tokens uintptr
  34139 	var token token_t
  34140 	_, _, _, _, _, _, _, _, _ = N, bit, n, next, p, token, tokens, v1, v2
  34141 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  34142 	for p != libc.UintptrFromInt32(0) {
  34143 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  34144 		if next == libc.UintptrFromInt32(0) {
  34145 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  34146 		} else {
  34147 			v1 = 0
  34148 		}
  34149 		N = v1
  34150 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  34151 		tokens = p + 1*8
  34152 		for {
  34153 			v2 = n
  34154 			n = n - 1
  34155 			if !(v2 > N) {
  34156 				break
  34157 			}
  34158 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  34159 			bit = libc.Int32FromUint16(token) >> int32(15) & int32(1)
  34160 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  34161 				VP8PutBit(tls, bw, bit, libc.Int32FromUint32(uint32(token)&uint32(0xff))) // constant proba
  34162 			} else {
  34163 				VP8PutBit(tls, bw, bit, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))))
  34164 			}
  34165 		}
  34166 		if final_pass != 0 {
  34167 			WebPSafeFree(tls, p)
  34168 		}
  34169 		p = next
  34170 	}
  34171 	if final_pass != 0 {
  34172 		(*VP8TBuffer)(unsafe.Pointer(b)).Fpages = libc.UintptrFromInt32(0)
  34173 	}
  34174 	return int32(1)
  34175 }
  34176 
  34177 // C documentation
  34178 //
  34179 //	// Size estimation
  34180 func VP8EstimateTokenSize(tls *libc.TLS, b uintptr, probas uintptr) (r size_t) {
  34181 	var N, bit1, n, v1, v2, v4, v6 int32
  34182 	var next, p, tokens uintptr
  34183 	var size size_t
  34184 	var token token_t
  34185 	var v3 uint8_t
  34186 	_, _, _, _, _, _, _, _, _, _, _, _, _ = N, bit1, n, next, p, size, token, tokens, v1, v2, v3, v4, v6
  34187 	size = uint64(0)
  34188 	p = (*VP8TBuffer)(unsafe.Pointer(b)).Fpages
  34189 	for p != libc.UintptrFromInt32(0) {
  34190 		next = (*VP8Tokens)(unsafe.Pointer(p)).Fnext
  34191 		if next == libc.UintptrFromInt32(0) {
  34192 			v1 = (*VP8TBuffer)(unsafe.Pointer(b)).Fleft
  34193 		} else {
  34194 			v1 = 0
  34195 		}
  34196 		N = v1
  34197 		n = (*VP8TBuffer)(unsafe.Pointer(b)).Fpage_size
  34198 		tokens = p + 1*8
  34199 		for {
  34200 			v2 = n
  34201 			n = n - 1
  34202 			if !(v2 > N) {
  34203 				break
  34204 			}
  34205 			token = **(**token_t)(__ccgo_up(tokens + uintptr(n)*2))
  34206 			bit1 = libc.Int32FromUint16(token) & (libc.Int32FromInt32(1) << libc.Int32FromInt32(15))
  34207 			if uint32(token)&(libc.Uint32FromUint32(1)<<libc.Int32FromInt32(14)) != 0 {
  34208 				v3 = uint8(uint32(token) & uint32(0xff))
  34209 				if !(bit1 != 0) {
  34210 					v6 = libc.Int32FromUint16(VP8EntropyCost[v3])
  34211 				} else {
  34212 					v6 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  34213 				}
  34214 				v4 = v6
  34215 				goto _5
  34216 			_5:
  34217 				size = size + libc.Uint64FromInt32(v4)
  34218 			} else {
  34219 				v3 = **(**uint8_t)(__ccgo_up(probas + uintptr(uint32(token)&uint32(0x3fff))))
  34220 				if !(bit1 != 0) {
  34221 					v2 = libc.Int32FromUint16(VP8EntropyCost[v3])
  34222 				} else {
  34223 					v2 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v3)])
  34224 				}
  34225 				v1 = v2
  34226 				goto _9
  34227 			_9:
  34228 				size = size + libc.Uint64FromInt32(v1)
  34229 			}
  34230 		}
  34231 		p = next
  34232 	}
  34233 	return size
  34234 }
  34235 
  34236 func VP8DefaultProbas(tls *libc.TLS, enc uintptr) {
  34237 	var probas uintptr
  34238 	_ = probas
  34239 	probas = enc + 3616
  34240 	(*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba = 0
  34241 	libc.Xmemset(tls, probas, libc.Int32FromUint32(255), uint64(3))
  34242 	libc.Xmemcpy(tls, probas+4, uintptr(unsafe.Pointer(&VP8CoeffsProba0)), uint64(1056))
  34243 	// Note: we could hard-code the level_costs corresponding to VP8CoeffsProba0,
  34244 	// but that's ~11k of static data. Better call VP8CalculateLevelCosts() later.
  34245 	(*VP8EncProba)(unsafe.Pointer(probas)).Fdirty = int32(1)
  34246 }
  34247 
  34248 // C documentation
  34249 //
  34250 //	// Paragraph 11.5.  900bytes.
  34251 var kBModesProba1 = [10][10][9]uint8_t{
  34252 	0: {
  34253 		0: {
  34254 			0: uint8(231),
  34255 			1: uint8(120),
  34256 			2: uint8(48),
  34257 			3: uint8(89),
  34258 			4: uint8(115),
  34259 			5: uint8(113),
  34260 			6: uint8(120),
  34261 			7: uint8(152),
  34262 			8: uint8(112),
  34263 		},
  34264 		1: {
  34265 			0: uint8(152),
  34266 			1: uint8(179),
  34267 			2: uint8(64),
  34268 			3: uint8(126),
  34269 			4: uint8(170),
  34270 			5: uint8(118),
  34271 			6: uint8(46),
  34272 			7: uint8(70),
  34273 			8: uint8(95),
  34274 		},
  34275 		2: {
  34276 			0: uint8(175),
  34277 			1: uint8(69),
  34278 			2: uint8(143),
  34279 			3: uint8(80),
  34280 			4: uint8(85),
  34281 			5: uint8(82),
  34282 			6: uint8(72),
  34283 			7: uint8(155),
  34284 			8: uint8(103),
  34285 		},
  34286 		3: {
  34287 			0: uint8(56),
  34288 			1: uint8(58),
  34289 			2: uint8(10),
  34290 			3: uint8(171),
  34291 			4: uint8(218),
  34292 			5: uint8(189),
  34293 			6: uint8(17),
  34294 			7: uint8(13),
  34295 			8: uint8(152),
  34296 		},
  34297 		4: {
  34298 			0: uint8(114),
  34299 			1: uint8(26),
  34300 			2: uint8(17),
  34301 			3: uint8(163),
  34302 			4: uint8(44),
  34303 			5: uint8(195),
  34304 			6: uint8(21),
  34305 			7: uint8(10),
  34306 			8: uint8(173),
  34307 		},
  34308 		5: {
  34309 			0: uint8(121),
  34310 			1: uint8(24),
  34311 			2: uint8(80),
  34312 			3: uint8(195),
  34313 			4: uint8(26),
  34314 			5: uint8(62),
  34315 			6: uint8(44),
  34316 			7: uint8(64),
  34317 			8: uint8(85),
  34318 		},
  34319 		6: {
  34320 			0: uint8(144),
  34321 			1: uint8(71),
  34322 			2: uint8(10),
  34323 			3: uint8(38),
  34324 			4: uint8(171),
  34325 			5: uint8(213),
  34326 			6: uint8(144),
  34327 			7: uint8(34),
  34328 			8: uint8(26),
  34329 		},
  34330 		7: {
  34331 			0: uint8(170),
  34332 			1: uint8(46),
  34333 			2: uint8(55),
  34334 			3: uint8(19),
  34335 			4: uint8(136),
  34336 			5: uint8(160),
  34337 			6: uint8(33),
  34338 			7: uint8(206),
  34339 			8: uint8(71),
  34340 		},
  34341 		8: {
  34342 			0: uint8(63),
  34343 			1: uint8(20),
  34344 			2: uint8(8),
  34345 			3: uint8(114),
  34346 			4: uint8(114),
  34347 			5: uint8(208),
  34348 			6: uint8(12),
  34349 			7: uint8(9),
  34350 			8: uint8(226),
  34351 		},
  34352 		9: {
  34353 			0: uint8(81),
  34354 			1: uint8(40),
  34355 			2: uint8(11),
  34356 			3: uint8(96),
  34357 			4: uint8(182),
  34358 			5: uint8(84),
  34359 			6: uint8(29),
  34360 			7: uint8(16),
  34361 			8: uint8(36),
  34362 		},
  34363 	},
  34364 	1: {
  34365 		0: {
  34366 			0: uint8(134),
  34367 			1: uint8(183),
  34368 			2: uint8(89),
  34369 			3: uint8(137),
  34370 			4: uint8(98),
  34371 			5: uint8(101),
  34372 			6: uint8(106),
  34373 			7: uint8(165),
  34374 			8: uint8(148),
  34375 		},
  34376 		1: {
  34377 			0: uint8(72),
  34378 			1: uint8(187),
  34379 			2: uint8(100),
  34380 			3: uint8(130),
  34381 			4: uint8(157),
  34382 			5: uint8(111),
  34383 			6: uint8(32),
  34384 			7: uint8(75),
  34385 			8: uint8(80),
  34386 		},
  34387 		2: {
  34388 			0: uint8(66),
  34389 			1: uint8(102),
  34390 			2: uint8(167),
  34391 			3: uint8(99),
  34392 			4: uint8(74),
  34393 			5: uint8(62),
  34394 			6: uint8(40),
  34395 			7: uint8(234),
  34396 			8: uint8(128),
  34397 		},
  34398 		3: {
  34399 			0: uint8(41),
  34400 			1: uint8(53),
  34401 			2: uint8(9),
  34402 			3: uint8(178),
  34403 			4: uint8(241),
  34404 			5: uint8(141),
  34405 			6: uint8(26),
  34406 			7: uint8(8),
  34407 			8: uint8(107),
  34408 		},
  34409 		4: {
  34410 			0: uint8(74),
  34411 			1: uint8(43),
  34412 			2: uint8(26),
  34413 			3: uint8(146),
  34414 			4: uint8(73),
  34415 			5: uint8(166),
  34416 			6: uint8(49),
  34417 			7: uint8(23),
  34418 			8: uint8(157),
  34419 		},
  34420 		5: {
  34421 			0: uint8(65),
  34422 			1: uint8(38),
  34423 			2: uint8(105),
  34424 			3: uint8(160),
  34425 			4: uint8(51),
  34426 			5: uint8(52),
  34427 			6: uint8(31),
  34428 			7: uint8(115),
  34429 			8: uint8(128),
  34430 		},
  34431 		6: {
  34432 			0: uint8(104),
  34433 			1: uint8(79),
  34434 			2: uint8(12),
  34435 			3: uint8(27),
  34436 			4: uint8(217),
  34437 			5: uint8(255),
  34438 			6: uint8(87),
  34439 			7: uint8(17),
  34440 			8: uint8(7),
  34441 		},
  34442 		7: {
  34443 			0: uint8(87),
  34444 			1: uint8(68),
  34445 			2: uint8(71),
  34446 			3: uint8(44),
  34447 			4: uint8(114),
  34448 			5: uint8(51),
  34449 			6: uint8(15),
  34450 			7: uint8(186),
  34451 			8: uint8(23),
  34452 		},
  34453 		8: {
  34454 			0: uint8(47),
  34455 			1: uint8(41),
  34456 			2: uint8(14),
  34457 			3: uint8(110),
  34458 			4: uint8(182),
  34459 			5: uint8(183),
  34460 			6: uint8(21),
  34461 			7: uint8(17),
  34462 			8: uint8(194),
  34463 		},
  34464 		9: {
  34465 			0: uint8(66),
  34466 			1: uint8(45),
  34467 			2: uint8(25),
  34468 			3: uint8(102),
  34469 			4: uint8(197),
  34470 			5: uint8(189),
  34471 			6: uint8(23),
  34472 			7: uint8(18),
  34473 			8: uint8(22),
  34474 		},
  34475 	},
  34476 	2: {
  34477 		0: {
  34478 			0: uint8(88),
  34479 			1: uint8(88),
  34480 			2: uint8(147),
  34481 			3: uint8(150),
  34482 			4: uint8(42),
  34483 			5: uint8(46),
  34484 			6: uint8(45),
  34485 			7: uint8(196),
  34486 			8: uint8(205),
  34487 		},
  34488 		1: {
  34489 			0: uint8(43),
  34490 			1: uint8(97),
  34491 			2: uint8(183),
  34492 			3: uint8(117),
  34493 			4: uint8(85),
  34494 			5: uint8(38),
  34495 			6: uint8(35),
  34496 			7: uint8(179),
  34497 			8: uint8(61),
  34498 		},
  34499 		2: {
  34500 			0: uint8(39),
  34501 			1: uint8(53),
  34502 			2: uint8(200),
  34503 			3: uint8(87),
  34504 			4: uint8(26),
  34505 			5: uint8(21),
  34506 			6: uint8(43),
  34507 			7: uint8(232),
  34508 			8: uint8(171),
  34509 		},
  34510 		3: {
  34511 			0: uint8(56),
  34512 			1: uint8(34),
  34513 			2: uint8(51),
  34514 			3: uint8(104),
  34515 			4: uint8(114),
  34516 			5: uint8(102),
  34517 			6: uint8(29),
  34518 			7: uint8(93),
  34519 			8: uint8(77),
  34520 		},
  34521 		4: {
  34522 			0: uint8(39),
  34523 			1: uint8(28),
  34524 			2: uint8(85),
  34525 			3: uint8(171),
  34526 			4: uint8(58),
  34527 			5: uint8(165),
  34528 			6: uint8(90),
  34529 			7: uint8(98),
  34530 			8: uint8(64),
  34531 		},
  34532 		5: {
  34533 			0: uint8(34),
  34534 			1: uint8(22),
  34535 			2: uint8(116),
  34536 			3: uint8(206),
  34537 			4: uint8(23),
  34538 			5: uint8(34),
  34539 			6: uint8(43),
  34540 			7: uint8(166),
  34541 			8: uint8(73),
  34542 		},
  34543 		6: {
  34544 			0: uint8(107),
  34545 			1: uint8(54),
  34546 			2: uint8(32),
  34547 			3: uint8(26),
  34548 			4: uint8(51),
  34549 			5: uint8(1),
  34550 			6: uint8(81),
  34551 			7: uint8(43),
  34552 			8: uint8(31),
  34553 		},
  34554 		7: {
  34555 			0: uint8(68),
  34556 			1: uint8(25),
  34557 			2: uint8(106),
  34558 			3: uint8(22),
  34559 			4: uint8(64),
  34560 			5: uint8(171),
  34561 			6: uint8(36),
  34562 			7: uint8(225),
  34563 			8: uint8(114),
  34564 		},
  34565 		8: {
  34566 			0: uint8(34),
  34567 			1: uint8(19),
  34568 			2: uint8(21),
  34569 			3: uint8(102),
  34570 			4: uint8(132),
  34571 			5: uint8(188),
  34572 			6: uint8(16),
  34573 			7: uint8(76),
  34574 			8: uint8(124),
  34575 		},
  34576 		9: {
  34577 			0: uint8(62),
  34578 			1: uint8(18),
  34579 			2: uint8(78),
  34580 			3: uint8(95),
  34581 			4: uint8(85),
  34582 			5: uint8(57),
  34583 			6: uint8(50),
  34584 			7: uint8(48),
  34585 			8: uint8(51),
  34586 		},
  34587 	},
  34588 	3: {
  34589 		0: {
  34590 			0: uint8(193),
  34591 			1: uint8(101),
  34592 			2: uint8(35),
  34593 			3: uint8(159),
  34594 			4: uint8(215),
  34595 			5: uint8(111),
  34596 			6: uint8(89),
  34597 			7: uint8(46),
  34598 			8: uint8(111),
  34599 		},
  34600 		1: {
  34601 			0: uint8(60),
  34602 			1: uint8(148),
  34603 			2: uint8(31),
  34604 			3: uint8(172),
  34605 			4: uint8(219),
  34606 			5: uint8(228),
  34607 			6: uint8(21),
  34608 			7: uint8(18),
  34609 			8: uint8(111),
  34610 		},
  34611 		2: {
  34612 			0: uint8(112),
  34613 			1: uint8(113),
  34614 			2: uint8(77),
  34615 			3: uint8(85),
  34616 			4: uint8(179),
  34617 			5: uint8(255),
  34618 			6: uint8(38),
  34619 			7: uint8(120),
  34620 			8: uint8(114),
  34621 		},
  34622 		3: {
  34623 			0: uint8(40),
  34624 			1: uint8(42),
  34625 			2: uint8(1),
  34626 			3: uint8(196),
  34627 			4: uint8(245),
  34628 			5: uint8(209),
  34629 			6: uint8(10),
  34630 			7: uint8(25),
  34631 			8: uint8(109),
  34632 		},
  34633 		4: {
  34634 			0: uint8(88),
  34635 			1: uint8(43),
  34636 			2: uint8(29),
  34637 			3: uint8(140),
  34638 			4: uint8(166),
  34639 			5: uint8(213),
  34640 			6: uint8(37),
  34641 			7: uint8(43),
  34642 			8: uint8(154),
  34643 		},
  34644 		5: {
  34645 			0: uint8(61),
  34646 			1: uint8(63),
  34647 			2: uint8(30),
  34648 			3: uint8(155),
  34649 			4: uint8(67),
  34650 			5: uint8(45),
  34651 			6: uint8(68),
  34652 			7: uint8(1),
  34653 			8: uint8(209),
  34654 		},
  34655 		6: {
  34656 			0: uint8(100),
  34657 			1: uint8(80),
  34658 			2: uint8(8),
  34659 			3: uint8(43),
  34660 			4: uint8(154),
  34661 			5: uint8(1),
  34662 			6: uint8(51),
  34663 			7: uint8(26),
  34664 			8: uint8(71),
  34665 		},
  34666 		7: {
  34667 			0: uint8(142),
  34668 			1: uint8(78),
  34669 			2: uint8(78),
  34670 			3: uint8(16),
  34671 			4: uint8(255),
  34672 			5: uint8(128),
  34673 			6: uint8(34),
  34674 			7: uint8(197),
  34675 			8: uint8(171),
  34676 		},
  34677 		8: {
  34678 			0: uint8(41),
  34679 			1: uint8(40),
  34680 			2: uint8(5),
  34681 			3: uint8(102),
  34682 			4: uint8(211),
  34683 			5: uint8(183),
  34684 			6: uint8(4),
  34685 			7: uint8(1),
  34686 			8: uint8(221),
  34687 		},
  34688 		9: {
  34689 			0: uint8(51),
  34690 			1: uint8(50),
  34691 			2: uint8(17),
  34692 			3: uint8(168),
  34693 			4: uint8(209),
  34694 			5: uint8(192),
  34695 			6: uint8(23),
  34696 			7: uint8(25),
  34697 			8: uint8(82),
  34698 		},
  34699 	},
  34700 	4: {
  34701 		0: {
  34702 			0: uint8(138),
  34703 			1: uint8(31),
  34704 			2: uint8(36),
  34705 			3: uint8(171),
  34706 			4: uint8(27),
  34707 			5: uint8(166),
  34708 			6: uint8(38),
  34709 			7: uint8(44),
  34710 			8: uint8(229),
  34711 		},
  34712 		1: {
  34713 			0: uint8(67),
  34714 			1: uint8(87),
  34715 			2: uint8(58),
  34716 			3: uint8(169),
  34717 			4: uint8(82),
  34718 			5: uint8(115),
  34719 			6: uint8(26),
  34720 			7: uint8(59),
  34721 			8: uint8(179),
  34722 		},
  34723 		2: {
  34724 			0: uint8(63),
  34725 			1: uint8(59),
  34726 			2: uint8(90),
  34727 			3: uint8(180),
  34728 			4: uint8(59),
  34729 			5: uint8(166),
  34730 			6: uint8(93),
  34731 			7: uint8(73),
  34732 			8: uint8(154),
  34733 		},
  34734 		3: {
  34735 			0: uint8(40),
  34736 			1: uint8(40),
  34737 			2: uint8(21),
  34738 			3: uint8(116),
  34739 			4: uint8(143),
  34740 			5: uint8(209),
  34741 			6: uint8(34),
  34742 			7: uint8(39),
  34743 			8: uint8(175),
  34744 		},
  34745 		4: {
  34746 			0: uint8(47),
  34747 			1: uint8(15),
  34748 			2: uint8(16),
  34749 			3: uint8(183),
  34750 			4: uint8(34),
  34751 			5: uint8(223),
  34752 			6: uint8(49),
  34753 			7: uint8(45),
  34754 			8: uint8(183),
  34755 		},
  34756 		5: {
  34757 			0: uint8(46),
  34758 			1: uint8(17),
  34759 			2: uint8(33),
  34760 			3: uint8(183),
  34761 			4: uint8(6),
  34762 			5: uint8(98),
  34763 			6: uint8(15),
  34764 			7: uint8(32),
  34765 			8: uint8(183),
  34766 		},
  34767 		6: {
  34768 			0: uint8(57),
  34769 			1: uint8(46),
  34770 			2: uint8(22),
  34771 			3: uint8(24),
  34772 			4: uint8(128),
  34773 			5: uint8(1),
  34774 			6: uint8(54),
  34775 			7: uint8(17),
  34776 			8: uint8(37),
  34777 		},
  34778 		7: {
  34779 			0: uint8(65),
  34780 			1: uint8(32),
  34781 			2: uint8(73),
  34782 			3: uint8(115),
  34783 			4: uint8(28),
  34784 			5: uint8(128),
  34785 			6: uint8(23),
  34786 			7: uint8(128),
  34787 			8: uint8(205),
  34788 		},
  34789 		8: {
  34790 			0: uint8(40),
  34791 			1: uint8(3),
  34792 			2: uint8(9),
  34793 			3: uint8(115),
  34794 			4: uint8(51),
  34795 			5: uint8(192),
  34796 			6: uint8(18),
  34797 			7: uint8(6),
  34798 			8: uint8(223),
  34799 		},
  34800 		9: {
  34801 			0: uint8(87),
  34802 			1: uint8(37),
  34803 			2: uint8(9),
  34804 			3: uint8(115),
  34805 			4: uint8(59),
  34806 			5: uint8(77),
  34807 			6: uint8(64),
  34808 			7: uint8(21),
  34809 			8: uint8(47),
  34810 		},
  34811 	},
  34812 	5: {
  34813 		0: {
  34814 			0: uint8(104),
  34815 			1: uint8(55),
  34816 			2: uint8(44),
  34817 			3: uint8(218),
  34818 			4: uint8(9),
  34819 			5: uint8(54),
  34820 			6: uint8(53),
  34821 			7: uint8(130),
  34822 			8: uint8(226),
  34823 		},
  34824 		1: {
  34825 			0: uint8(64),
  34826 			1: uint8(90),
  34827 			2: uint8(70),
  34828 			3: uint8(205),
  34829 			4: uint8(40),
  34830 			5: uint8(41),
  34831 			6: uint8(23),
  34832 			7: uint8(26),
  34833 			8: uint8(57),
  34834 		},
  34835 		2: {
  34836 			0: uint8(54),
  34837 			1: uint8(57),
  34838 			2: uint8(112),
  34839 			3: uint8(184),
  34840 			4: uint8(5),
  34841 			5: uint8(41),
  34842 			6: uint8(38),
  34843 			7: uint8(166),
  34844 			8: uint8(213),
  34845 		},
  34846 		3: {
  34847 			0: uint8(30),
  34848 			1: uint8(34),
  34849 			2: uint8(26),
  34850 			3: uint8(133),
  34851 			4: uint8(152),
  34852 			5: uint8(116),
  34853 			6: uint8(10),
  34854 			7: uint8(32),
  34855 			8: uint8(134),
  34856 		},
  34857 		4: {
  34858 			0: uint8(39),
  34859 			1: uint8(19),
  34860 			2: uint8(53),
  34861 			3: uint8(221),
  34862 			4: uint8(26),
  34863 			5: uint8(114),
  34864 			6: uint8(32),
  34865 			7: uint8(73),
  34866 			8: uint8(255),
  34867 		},
  34868 		5: {
  34869 			0: uint8(31),
  34870 			1: uint8(9),
  34871 			2: uint8(65),
  34872 			3: uint8(234),
  34873 			4: uint8(2),
  34874 			5: uint8(15),
  34875 			6: uint8(1),
  34876 			7: uint8(118),
  34877 			8: uint8(73),
  34878 		},
  34879 		6: {
  34880 			0: uint8(75),
  34881 			1: uint8(32),
  34882 			2: uint8(12),
  34883 			3: uint8(51),
  34884 			4: uint8(192),
  34885 			5: uint8(255),
  34886 			6: uint8(160),
  34887 			7: uint8(43),
  34888 			8: uint8(51),
  34889 		},
  34890 		7: {
  34891 			0: uint8(88),
  34892 			1: uint8(31),
  34893 			2: uint8(35),
  34894 			3: uint8(67),
  34895 			4: uint8(102),
  34896 			5: uint8(85),
  34897 			6: uint8(55),
  34898 			7: uint8(186),
  34899 			8: uint8(85),
  34900 		},
  34901 		8: {
  34902 			0: uint8(56),
  34903 			1: uint8(21),
  34904 			2: uint8(23),
  34905 			3: uint8(111),
  34906 			4: uint8(59),
  34907 			5: uint8(205),
  34908 			6: uint8(45),
  34909 			7: uint8(37),
  34910 			8: uint8(192),
  34911 		},
  34912 		9: {
  34913 			0: uint8(55),
  34914 			1: uint8(38),
  34915 			2: uint8(70),
  34916 			3: uint8(124),
  34917 			4: uint8(73),
  34918 			5: uint8(102),
  34919 			6: uint8(1),
  34920 			7: uint8(34),
  34921 			8: uint8(98),
  34922 		},
  34923 	},
  34924 	6: {
  34925 		0: {
  34926 			0: uint8(125),
  34927 			1: uint8(98),
  34928 			2: uint8(42),
  34929 			3: uint8(88),
  34930 			4: uint8(104),
  34931 			5: uint8(85),
  34932 			6: uint8(117),
  34933 			7: uint8(175),
  34934 			8: uint8(82),
  34935 		},
  34936 		1: {
  34937 			0: uint8(95),
  34938 			1: uint8(84),
  34939 			2: uint8(53),
  34940 			3: uint8(89),
  34941 			4: uint8(128),
  34942 			5: uint8(100),
  34943 			6: uint8(113),
  34944 			7: uint8(101),
  34945 			8: uint8(45),
  34946 		},
  34947 		2: {
  34948 			0: uint8(75),
  34949 			1: uint8(79),
  34950 			2: uint8(123),
  34951 			3: uint8(47),
  34952 			4: uint8(51),
  34953 			5: uint8(128),
  34954 			6: uint8(81),
  34955 			7: uint8(171),
  34956 			8: uint8(1),
  34957 		},
  34958 		3: {
  34959 			0: uint8(57),
  34960 			1: uint8(17),
  34961 			2: uint8(5),
  34962 			3: uint8(71),
  34963 			4: uint8(102),
  34964 			5: uint8(57),
  34965 			6: uint8(53),
  34966 			7: uint8(41),
  34967 			8: uint8(49),
  34968 		},
  34969 		4: {
  34970 			0: uint8(38),
  34971 			1: uint8(33),
  34972 			2: uint8(13),
  34973 			3: uint8(121),
  34974 			4: uint8(57),
  34975 			5: uint8(73),
  34976 			6: uint8(26),
  34977 			7: uint8(1),
  34978 			8: uint8(85),
  34979 		},
  34980 		5: {
  34981 			0: uint8(41),
  34982 			1: uint8(10),
  34983 			2: uint8(67),
  34984 			3: uint8(138),
  34985 			4: uint8(77),
  34986 			5: uint8(110),
  34987 			6: uint8(90),
  34988 			7: uint8(47),
  34989 			8: uint8(114),
  34990 		},
  34991 		6: {
  34992 			0: uint8(115),
  34993 			1: uint8(21),
  34994 			2: uint8(2),
  34995 			3: uint8(10),
  34996 			4: uint8(102),
  34997 			5: uint8(255),
  34998 			6: uint8(166),
  34999 			7: uint8(23),
  35000 			8: uint8(6),
  35001 		},
  35002 		7: {
  35003 			0: uint8(101),
  35004 			1: uint8(29),
  35005 			2: uint8(16),
  35006 			3: uint8(10),
  35007 			4: uint8(85),
  35008 			5: uint8(128),
  35009 			6: uint8(101),
  35010 			7: uint8(196),
  35011 			8: uint8(26),
  35012 		},
  35013 		8: {
  35014 			0: uint8(57),
  35015 			1: uint8(18),
  35016 			2: uint8(10),
  35017 			3: uint8(102),
  35018 			4: uint8(102),
  35019 			5: uint8(213),
  35020 			6: uint8(34),
  35021 			7: uint8(20),
  35022 			8: uint8(43),
  35023 		},
  35024 		9: {
  35025 			0: uint8(117),
  35026 			1: uint8(20),
  35027 			2: uint8(15),
  35028 			3: uint8(36),
  35029 			4: uint8(163),
  35030 			5: uint8(128),
  35031 			6: uint8(68),
  35032 			7: uint8(1),
  35033 			8: uint8(26),
  35034 		},
  35035 	},
  35036 	7: {
  35037 		0: {
  35038 			0: uint8(102),
  35039 			1: uint8(61),
  35040 			2: uint8(71),
  35041 			3: uint8(37),
  35042 			4: uint8(34),
  35043 			5: uint8(53),
  35044 			6: uint8(31),
  35045 			7: uint8(243),
  35046 			8: uint8(192),
  35047 		},
  35048 		1: {
  35049 			0: uint8(69),
  35050 			1: uint8(60),
  35051 			2: uint8(71),
  35052 			3: uint8(38),
  35053 			4: uint8(73),
  35054 			5: uint8(119),
  35055 			6: uint8(28),
  35056 			7: uint8(222),
  35057 			8: uint8(37),
  35058 		},
  35059 		2: {
  35060 			0: uint8(68),
  35061 			1: uint8(45),
  35062 			2: uint8(128),
  35063 			3: uint8(34),
  35064 			4: uint8(1),
  35065 			5: uint8(47),
  35066 			6: uint8(11),
  35067 			7: uint8(245),
  35068 			8: uint8(171),
  35069 		},
  35070 		3: {
  35071 			0: uint8(62),
  35072 			1: uint8(17),
  35073 			2: uint8(19),
  35074 			3: uint8(70),
  35075 			4: uint8(146),
  35076 			5: uint8(85),
  35077 			6: uint8(55),
  35078 			7: uint8(62),
  35079 			8: uint8(70),
  35080 		},
  35081 		4: {
  35082 			0: uint8(37),
  35083 			1: uint8(43),
  35084 			2: uint8(37),
  35085 			3: uint8(154),
  35086 			4: uint8(100),
  35087 			5: uint8(163),
  35088 			6: uint8(85),
  35089 			7: uint8(160),
  35090 			8: uint8(1),
  35091 		},
  35092 		5: {
  35093 			0: uint8(63),
  35094 			1: uint8(9),
  35095 			2: uint8(92),
  35096 			3: uint8(136),
  35097 			4: uint8(28),
  35098 			5: uint8(64),
  35099 			6: uint8(32),
  35100 			7: uint8(201),
  35101 			8: uint8(85),
  35102 		},
  35103 		6: {
  35104 			0: uint8(75),
  35105 			1: uint8(15),
  35106 			2: uint8(9),
  35107 			3: uint8(9),
  35108 			4: uint8(64),
  35109 			5: uint8(255),
  35110 			6: uint8(184),
  35111 			7: uint8(119),
  35112 			8: uint8(16),
  35113 		},
  35114 		7: {
  35115 			0: uint8(86),
  35116 			1: uint8(6),
  35117 			2: uint8(28),
  35118 			3: uint8(5),
  35119 			4: uint8(64),
  35120 			5: uint8(255),
  35121 			6: uint8(25),
  35122 			7: uint8(248),
  35123 			8: uint8(1),
  35124 		},
  35125 		8: {
  35126 			0: uint8(56),
  35127 			1: uint8(8),
  35128 			2: uint8(17),
  35129 			3: uint8(132),
  35130 			4: uint8(137),
  35131 			5: uint8(255),
  35132 			6: uint8(55),
  35133 			7: uint8(116),
  35134 			8: uint8(128),
  35135 		},
  35136 		9: {
  35137 			0: uint8(58),
  35138 			1: uint8(15),
  35139 			2: uint8(20),
  35140 			3: uint8(82),
  35141 			4: uint8(135),
  35142 			5: uint8(57),
  35143 			6: uint8(26),
  35144 			7: uint8(121),
  35145 			8: uint8(40),
  35146 		},
  35147 	},
  35148 	8: {
  35149 		0: {
  35150 			0: uint8(164),
  35151 			1: uint8(50),
  35152 			2: uint8(31),
  35153 			3: uint8(137),
  35154 			4: uint8(154),
  35155 			5: uint8(133),
  35156 			6: uint8(25),
  35157 			7: uint8(35),
  35158 			8: uint8(218),
  35159 		},
  35160 		1: {
  35161 			0: uint8(51),
  35162 			1: uint8(103),
  35163 			2: uint8(44),
  35164 			3: uint8(131),
  35165 			4: uint8(131),
  35166 			5: uint8(123),
  35167 			6: uint8(31),
  35168 			7: uint8(6),
  35169 			8: uint8(158),
  35170 		},
  35171 		2: {
  35172 			0: uint8(86),
  35173 			1: uint8(40),
  35174 			2: uint8(64),
  35175 			3: uint8(135),
  35176 			4: uint8(148),
  35177 			5: uint8(224),
  35178 			6: uint8(45),
  35179 			7: uint8(183),
  35180 			8: uint8(128),
  35181 		},
  35182 		3: {
  35183 			0: uint8(22),
  35184 			1: uint8(26),
  35185 			2: uint8(17),
  35186 			3: uint8(131),
  35187 			4: uint8(240),
  35188 			5: uint8(154),
  35189 			6: uint8(14),
  35190 			7: uint8(1),
  35191 			8: uint8(209),
  35192 		},
  35193 		4: {
  35194 			0: uint8(45),
  35195 			1: uint8(16),
  35196 			2: uint8(21),
  35197 			3: uint8(91),
  35198 			4: uint8(64),
  35199 			5: uint8(222),
  35200 			6: uint8(7),
  35201 			7: uint8(1),
  35202 			8: uint8(197),
  35203 		},
  35204 		5: {
  35205 			0: uint8(56),
  35206 			1: uint8(21),
  35207 			2: uint8(39),
  35208 			3: uint8(155),
  35209 			4: uint8(60),
  35210 			5: uint8(138),
  35211 			6: uint8(23),
  35212 			7: uint8(102),
  35213 			8: uint8(213),
  35214 		},
  35215 		6: {
  35216 			0: uint8(83),
  35217 			1: uint8(12),
  35218 			2: uint8(13),
  35219 			3: uint8(54),
  35220 			4: uint8(192),
  35221 			5: uint8(255),
  35222 			6: uint8(68),
  35223 			7: uint8(47),
  35224 			8: uint8(28),
  35225 		},
  35226 		7: {
  35227 			0: uint8(85),
  35228 			1: uint8(26),
  35229 			2: uint8(85),
  35230 			3: uint8(85),
  35231 			4: uint8(128),
  35232 			5: uint8(128),
  35233 			6: uint8(32),
  35234 			7: uint8(146),
  35235 			8: uint8(171),
  35236 		},
  35237 		8: {
  35238 			0: uint8(18),
  35239 			1: uint8(11),
  35240 			2: uint8(7),
  35241 			3: uint8(63),
  35242 			4: uint8(144),
  35243 			5: uint8(171),
  35244 			6: uint8(4),
  35245 			7: uint8(4),
  35246 			8: uint8(246),
  35247 		},
  35248 		9: {
  35249 			0: uint8(35),
  35250 			1: uint8(27),
  35251 			2: uint8(10),
  35252 			3: uint8(146),
  35253 			4: uint8(174),
  35254 			5: uint8(171),
  35255 			6: uint8(12),
  35256 			7: uint8(26),
  35257 			8: uint8(128),
  35258 		},
  35259 	},
  35260 	9: {
  35261 		0: {
  35262 			0: uint8(190),
  35263 			1: uint8(80),
  35264 			2: uint8(35),
  35265 			3: uint8(99),
  35266 			4: uint8(180),
  35267 			5: uint8(80),
  35268 			6: uint8(126),
  35269 			7: uint8(54),
  35270 			8: uint8(45),
  35271 		},
  35272 		1: {
  35273 			0: uint8(85),
  35274 			1: uint8(126),
  35275 			2: uint8(47),
  35276 			3: uint8(87),
  35277 			4: uint8(176),
  35278 			5: uint8(51),
  35279 			6: uint8(41),
  35280 			7: uint8(20),
  35281 			8: uint8(32),
  35282 		},
  35283 		2: {
  35284 			0: uint8(101),
  35285 			1: uint8(75),
  35286 			2: uint8(128),
  35287 			3: uint8(139),
  35288 			4: uint8(118),
  35289 			5: uint8(146),
  35290 			6: uint8(116),
  35291 			7: uint8(128),
  35292 			8: uint8(85),
  35293 		},
  35294 		3: {
  35295 			0: uint8(56),
  35296 			1: uint8(41),
  35297 			2: uint8(15),
  35298 			3: uint8(176),
  35299 			4: uint8(236),
  35300 			5: uint8(85),
  35301 			6: uint8(37),
  35302 			7: uint8(9),
  35303 			8: uint8(62),
  35304 		},
  35305 		4: {
  35306 			0: uint8(71),
  35307 			1: uint8(30),
  35308 			2: uint8(17),
  35309 			3: uint8(119),
  35310 			4: uint8(118),
  35311 			5: uint8(255),
  35312 			6: uint8(17),
  35313 			7: uint8(18),
  35314 			8: uint8(138),
  35315 		},
  35316 		5: {
  35317 			0: uint8(101),
  35318 			1: uint8(38),
  35319 			2: uint8(60),
  35320 			3: uint8(138),
  35321 			4: uint8(55),
  35322 			5: uint8(70),
  35323 			6: uint8(43),
  35324 			7: uint8(26),
  35325 			8: uint8(142),
  35326 		},
  35327 		6: {
  35328 			0: uint8(146),
  35329 			1: uint8(36),
  35330 			2: uint8(19),
  35331 			3: uint8(30),
  35332 			4: uint8(171),
  35333 			5: uint8(255),
  35334 			6: uint8(97),
  35335 			7: uint8(27),
  35336 			8: uint8(20),
  35337 		},
  35338 		7: {
  35339 			0: uint8(138),
  35340 			1: uint8(45),
  35341 			2: uint8(61),
  35342 			3: uint8(62),
  35343 			4: uint8(219),
  35344 			5: uint8(1),
  35345 			6: uint8(81),
  35346 			7: uint8(188),
  35347 			8: uint8(64),
  35348 		},
  35349 		8: {
  35350 			0: uint8(32),
  35351 			1: uint8(41),
  35352 			2: uint8(20),
  35353 			3: uint8(117),
  35354 			4: uint8(151),
  35355 			5: uint8(142),
  35356 			6: uint8(20),
  35357 			7: uint8(21),
  35358 			8: uint8(163),
  35359 		},
  35360 		9: {
  35361 			0: uint8(112),
  35362 			1: uint8(19),
  35363 			2: uint8(12),
  35364 			3: uint8(61),
  35365 			4: uint8(195),
  35366 			5: uint8(128),
  35367 			6: uint8(48),
  35368 			7: uint8(4),
  35369 			8: uint8(24),
  35370 		},
  35371 	},
  35372 }
  35373 
  35374 func PutI4Mode(tls *libc.TLS, bw uintptr, mode int32, prob uintptr) (r int32) {
  35375 	if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_DC_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob)))) != 0 {
  35376 		if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_TM_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 1)))) != 0 {
  35377 			if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VE_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 2)))) != 0 {
  35378 				if !(VP8PutBit(tls, bw, libc.BoolInt32(mode >= int32(B_LD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 3)))) != 0) {
  35379 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HE_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 4)))) != 0 {
  35380 						VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_RD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 5))))
  35381 					}
  35382 				} else {
  35383 					if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_LD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 6)))) != 0 {
  35384 						if VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_VL_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 7)))) != 0 {
  35385 							VP8PutBit(tls, bw, libc.BoolInt32(mode != int32(B_HD_PRED)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prob + 8))))
  35386 						}
  35387 					}
  35388 				}
  35389 			}
  35390 		}
  35391 	}
  35392 	return mode
  35393 }
  35394 
  35395 func PutI16Mode(tls *libc.TLS, bw uintptr, mode int32) {
  35396 	if VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED) || mode == int32(H_PRED)), int32(156)) != 0 {
  35397 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(TM_PRED)), int32(128)) // TM or HE
  35398 	} else {
  35399 		VP8PutBit(tls, bw, libc.BoolInt32(mode == int32(V_PRED)), int32(163)) // VE or DC
  35400 	}
  35401 }
  35402 
  35403 func PutUVMode(tls *libc.TLS, bw uintptr, uv_mode int32) {
  35404 	if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(DC_PRED)), int32(142)) != 0 {
  35405 		if VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(V_PRED)), int32(114)) != 0 {
  35406 			VP8PutBit(tls, bw, libc.BoolInt32(uv_mode != int32(H_PRED)), int32(183)) // else: TM_PRED
  35407 		}
  35408 	}
  35409 }
  35410 
  35411 func PutSegment(tls *libc.TLS, bw uintptr, s int32, p uintptr) {
  35412 	if VP8PutBit(tls, bw, libc.BoolInt32(s >= int32(2)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))) != 0 {
  35413 		p = p + uintptr(1)
  35414 	}
  35415 	VP8PutBit(tls, bw, s&int32(1), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + 1))))
  35416 }
  35417 
  35418 func VP8CodeIntraModes(tls *libc.TLS, enc uintptr) {
  35419 	bp := tls.Alloc(3856)
  35420 	defer tls.Free(3856)
  35421 	var bw, mb, preds, probas, top_pred uintptr
  35422 	var left, preds_w, x, y int32
  35423 	var _ /* it at bp+0 */ VP8EncIterator
  35424 	_, _, _, _, _, _, _, _, _ = bw, left, mb, preds, preds_w, probas, top_pred, x, y
  35425 	bw = enc + 64
  35426 	VP8IteratorInit(tls, enc, bp)
  35427 	for cond := true; cond; cond = VP8IteratorNext(tls, bp) != 0 {
  35428 		mb = (**(**VP8EncIterator)(__ccgo_up(bp))).Fmb
  35429 		preds = (**(**VP8EncIterator)(__ccgo_up(bp))).Fpreds
  35430 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fsegment_hdr.Fupdate_map != 0 {
  35431 			PutSegment(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x60>>5)), enc+3616)
  35432 		}
  35433 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fuse_skip_proba != 0 {
  35434 			VP8PutBit(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x10>>4)), libc.Int32FromUint8((*VP8Encoder)(unsafe.Pointer(enc)).Fproba.Fskip_proba))
  35435 		}
  35436 		if VP8PutBit(tls, bw, libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0x3>>0)) != 0), int32(145)) != 0 { // i16x16
  35437 			PutI16Mode(tls, bw, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(preds))))
  35438 		} else {
  35439 			preds_w = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w
  35440 			top_pred = preds - uintptr(preds_w)
  35441 			y = 0
  35442 			for {
  35443 				if !(y < int32(4)) {
  35444 					break
  35445 				}
  35446 				left = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(preds + uintptr(-libc.Int32FromInt32(1)))))
  35447 				x = 0
  35448 				for {
  35449 					if !(x < int32(4)) {
  35450 						break
  35451 					}
  35452 					probas = uintptr(unsafe.Pointer(&kBModesProba1)) + uintptr(**(**uint8_t)(__ccgo_up(top_pred + uintptr(x))))*90 + uintptr(left)*9
  35453 					left = PutI4Mode(tls, bw, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(preds + uintptr(x)))), probas)
  35454 					goto _2
  35455 				_2:
  35456 					;
  35457 					x = x + 1
  35458 				}
  35459 				top_pred = preds
  35460 				preds = preds + uintptr(preds_w)
  35461 				goto _1
  35462 			_1:
  35463 				;
  35464 				y = y + 1
  35465 			}
  35466 		}
  35467 		PutUVMode(tls, bw, int32(uint32(*(*uint8)(unsafe.Pointer(mb + 0))&0xc>>2)))
  35468 	}
  35469 }
  35470 
  35471 func VP8WriteProbas(tls *libc.TLS, bw uintptr, probas uintptr) {
  35472 	var b, c, p, t, update int32
  35473 	var p0 uint8_t
  35474 	_, _, _, _, _, _ = b, c, p, p0, t, update
  35475 	t = 0
  35476 	for {
  35477 		if !(t < int32(NUM_TYPES)) {
  35478 			break
  35479 		}
  35480 		b = 0
  35481 		for {
  35482 			if !(b < int32(NUM_BANDS)) {
  35483 				break
  35484 			}
  35485 			c = 0
  35486 			for {
  35487 				if !(c < int32(NUM_CTX)) {
  35488 					break
  35489 				}
  35490 				p = 0
  35491 				for {
  35492 					if !(p < int32(NUM_PROBAS)) {
  35493 						break
  35494 					}
  35495 					p0 = **(**uint8_t)(__ccgo_up(probas + 4 + uintptr(t)*264 + uintptr(b)*33 + uintptr(c)*11 + uintptr(p)))
  35496 					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)))))
  35497 					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 {
  35498 						VP8PutBits(tls, bw, uint32(p0), int32(8))
  35499 					}
  35500 					goto _4
  35501 				_4:
  35502 					;
  35503 					p = p + 1
  35504 				}
  35505 				goto _3
  35506 			_3:
  35507 				;
  35508 				c = c + 1
  35509 			}
  35510 			goto _2
  35511 		_2:
  35512 			;
  35513 			b = b + 1
  35514 		}
  35515 		goto _1
  35516 	_1:
  35517 		;
  35518 		t = t + 1
  35519 	}
  35520 	if VP8PutBitUniform(tls, bw, (*VP8EncProba)(unsafe.Pointer(probas)).Fuse_skip_proba) != 0 {
  35521 		VP8PutBits(tls, bw, uint32((*VP8EncProba)(unsafe.Pointer(probas)).Fskip_proba), int32(8))
  35522 	}
  35523 }
  35524 
  35525 const MAX_HUFF_IMAGE_SIZE = 2600
  35526 const NUM_BUCKETS = 256
  35527 const VP8L_MAGIC_BYTE3 = 47
  35528 const VP8_SIGNATURE2 = 0x9d012a
  35529 
  35530 type HuffmanTreeToken = struct {
  35531 	Fcode       uint8_t
  35532 	Fextra_bits uint8_t
  35533 }
  35534 
  35535 type HuffmanTreeCode = struct {
  35536 	Fnum_symbols  int32
  35537 	Fcode_lengths uintptr
  35538 	Fcodes        uintptr
  35539 }
  35540 
  35541 type HuffmanTree = struct {
  35542 	Ftotal_count      uint32_t
  35543 	Fvalue            int32
  35544 	Fpool_index_left  int32
  35545 	Fpool_index_right int32
  35546 }
  35547 
  35548 type PaletteSorting1 = int32
  35549 
  35550 type PaletteSorting = int32
  35551 
  35552 const kSortedDefault = 0
  35553 const kMinimizeDelta = 1
  35554 const kModifiedZeng = 2
  35555 const kUnusedPalette = 3
  35556 const kPaletteSortingNum = 4
  35557 
  35558 // Copyright 2011 Google Inc. All Rights Reserved.
  35559 //
  35560 // Use of this source code is governed by a BSD-style license
  35561 // that can be found in the COPYING file in the root of the source
  35562 // tree. An additional intellectual property rights grant can be found
  35563 // in the file PATENTS. All contributing project authors may
  35564 // be found in the AUTHORS file in the root of the source tree.
  35565 // -----------------------------------------------------------------------------
  35566 //
  35567 // Multi-threaded worker
  35568 //
  35569 // Author: Skal (pascal.massimino@gmail.com)
  35570 
  35571 // Copyright 2012 Google Inc. All Rights Reserved.
  35572 //
  35573 // Use of this source code is governed by a BSD-style license
  35574 // that can be found in the COPYING file in the root of the source
  35575 // tree. An additional intellectual property rights grant can be found
  35576 // in the file PATENTS. All contributing project authors may
  35577 // be found in the AUTHORS file in the root of the source tree.
  35578 // -----------------------------------------------------------------------------
  35579 //
  35580 // Misc. common utility functions
  35581 //
  35582 // Authors: Skal (pascal.massimino@gmail.com)
  35583 //          Urvang (urvang@google.com)
  35584 
  35585 // Copyright 2011 Google Inc. All Rights Reserved.
  35586 //
  35587 // Use of this source code is governed by a BSD-style license
  35588 // that can be found in the COPYING file in the root of the source
  35589 // tree. An additional intellectual property rights grant can be found
  35590 // in the file PATENTS. All contributing project authors may
  35591 // be found in the AUTHORS file in the root of the source tree.
  35592 // -----------------------------------------------------------------------------
  35593 //
  35594 //   WebP encoder: main interface
  35595 //
  35596 // Author: Skal (pascal.massimino@gmail.com)
  35597 
  35598 // Copyright 2012 Google Inc. All Rights Reserved.
  35599 //
  35600 // Use of this source code is governed by a BSD-style license
  35601 // that can be found in the COPYING file in the root of the source
  35602 // tree. An additional intellectual property rights grant can be found
  35603 // in the file PATENTS. All contributing project authors may
  35604 // be found in the AUTHORS file in the root of the source tree.
  35605 // -----------------------------------------------------------------------------
  35606 //
  35607 //  Internal header for constants related to WebP file format.
  35608 //
  35609 // Author: Urvang (urvang@google.com)
  35610 
  35611 // Copyright 2010 Google Inc. All Rights Reserved.
  35612 //
  35613 // Use of this source code is governed by a BSD-style license
  35614 // that can be found in the COPYING file in the root of the source
  35615 // tree. An additional intellectual property rights grant can be found
  35616 // in the file PATENTS. All contributing project authors may
  35617 // be found in the AUTHORS file in the root of the source tree.
  35618 // -----------------------------------------------------------------------------
  35619 //
  35620 //  Common types + memory wrappers
  35621 //
  35622 // Author: Skal (pascal.massimino@gmail.com)
  35623 
  35624 // Maximum number of histogram images (sub-blocks).
  35625 // Empirical value for which it becomes too computationally expensive to
  35626 // compute the best predictor image.
  35627 
  35628 // -----------------------------------------------------------------------------
  35629 // Palette
  35630 
  35631 // C documentation
  35632 //
  35633 //	// These five modes are evaluated and their respective entropy is computed.
  35634 type EntropyIx = int32
  35635 
  35636 const kDirect = 0
  35637 const kSpatial = 1
  35638 const kSubGreen = 2
  35639 const kSpatialSubGreen = 3
  35640 const kPalette = 4
  35641 const kPaletteAndSpatial = 5
  35642 const kNumEntropyIx = 6
  35643 
  35644 type HistoIx = int32
  35645 
  35646 const kHistoAlpha = 0
  35647 const kHistoAlphaPred = 1
  35648 const kHistoGreen = 2
  35649 const kHistoGreenPred = 3
  35650 const kHistoRed = 4
  35651 const kHistoRedPred = 5
  35652 const kHistoBlue = 6
  35653 const kHistoBluePred = 7
  35654 const kHistoRedSubGreen = 8
  35655 const kHistoRedPredSubGreen = 9
  35656 const kHistoBlueSubGreen = 10
  35657 const kHistoBluePredSubGreen = 11
  35658 const kHistoPalette = 12
  35659 const kHistoTotal = 13
  35660 
  35661 type HistogramBuckets = [256]uint32_t
  35662 
  35663 // C documentation
  35664 //
  35665 //	// Keeping track of histograms, indexed by HistoIx.
  35666 //	// Ideally, this would just be a struct with meaningful fields, but the
  35667 //	// calculation of `entropy_comp` uses the index. One refactoring at a time :)
  35668 type Histograms = struct {
  35669 	Fcategory [13]HistogramBuckets
  35670 }
  35671 
  35672 func AddSingleSubGreen(tls *libc.TLS, p uint32_t, r uintptr, b uintptr) {
  35673 	var green int32
  35674 	_ = green
  35675 	green = libc.Int32FromUint32(p) >> int32(8) // The upper bits are masked away later.
  35676 	**(**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
  35677 	**(**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
  35678 }
  35679 
  35680 func AddSingle(tls *libc.TLS, p uint32_t, a uintptr, r uintptr, g uintptr, b uintptr) {
  35681 	**(**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
  35682 	**(**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
  35683 	**(**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
  35684 	**(**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
  35685 }
  35686 
  35687 func HashPix(tls *libc.TLS, pix uint32_t) (r uint8_t) {
  35688 	// Note that masking with 0xffffffffu is for preventing an
  35689 	// 'unsigned int overflow' warning. Doesn't impact the compiled code.
  35690 	return uint8((uint64(pix) + uint64(pix>>libc.Int32FromInt32(19))) * uint64(0x39c5fba7) & uint64(0xffffffff) >> int32(24))
  35691 }
  35692 
  35693 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) {
  35694 	bp := tls.Alloc(48)
  35695 	defer tls.Free(48)
  35696 	var alpha_and_green, pix, pix_diff, pix_prev, red_and_blue, v10, v12, v3, v4, v5, v9 uint32_t
  35697 	var blue_histo, curr_row, histo, prev_row, red_histo, v29 uintptr
  35698 	var entropy_comp [13]uint64_t
  35699 	var hash uint8_t
  35700 	var i, j, k, last_mode_to_analyze, x, y, v7 int32
  35701 	var v18 uint32
  35702 	var _ /* entropy at bp+0 */ [6]uint64_t
  35703 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  35704 	if use_palette != 0 && palette_size <= int32(16) {
  35705 		// In the case of small palettes, we pack 2, 4 or 8 pixels together. In
  35706 		// practice, small palettes are better than any other transform.
  35707 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kPalette)
  35708 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35709 		return int32(1)
  35710 	}
  35711 	histo = WebPSafeCalloc(tls, uint64(1), uint64(13312))
  35712 	if histo != libc.UintptrFromInt32(0) {
  35713 		prev_row = libc.UintptrFromInt32(0)
  35714 		curr_row = argb
  35715 		pix_prev = **(**uint32_t)(__ccgo_up(argb)) // Skip the first pixel.
  35716 		y = 0
  35717 		for {
  35718 			if !(y < height) {
  35719 				break
  35720 			}
  35721 			x = 0
  35722 			for {
  35723 				if !(x < width) {
  35724 					break
  35725 				}
  35726 				pix = **(**uint32_t)(__ccgo_up(curr_row + uintptr(x)*4))
  35727 				v3 = pix
  35728 				v4 = pix_prev
  35729 				alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v4&uint32(0xff00ff00)
  35730 				red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v4&uint32(0x00ff00ff)
  35731 				v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  35732 				goto _6
  35733 			_6:
  35734 				pix_diff = v5
  35735 				pix_prev = pix
  35736 				if pix_diff == uint32(0) || prev_row != libc.UintptrFromInt32(0) && pix == **(**uint32_t)(__ccgo_up(prev_row + uintptr(x)*4)) {
  35737 					goto _2
  35738 				}
  35739 				AddSingle(tls, pix, histo+uintptr(kHistoAlpha)*1024, histo+uintptr(kHistoRed)*1024, histo+uintptr(kHistoGreen)*1024, histo+uintptr(kHistoBlue)*1024)
  35740 				AddSingle(tls, pix_diff, histo+uintptr(kHistoAlphaPred)*1024, histo+uintptr(kHistoRedPred)*1024, histo+uintptr(kHistoGreenPred)*1024, histo+uintptr(kHistoBluePred)*1024)
  35741 				AddSingleSubGreen(tls, pix, histo+uintptr(kHistoRedSubGreen)*1024, histo+uintptr(kHistoBlueSubGreen)*1024)
  35742 				AddSingleSubGreen(tls, pix_diff, histo+uintptr(kHistoRedPredSubGreen)*1024, histo+uintptr(kHistoBluePredSubGreen)*1024)
  35743 				// Approximate the palette by the entropy of the multiplicative hash.
  35744 				hash = HashPix(tls, pix)
  35745 				**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoPalette)*1024 + uintptr(hash)*4)) + 1
  35746 				goto _2
  35747 			_2:
  35748 				;
  35749 				x = x + 1
  35750 			}
  35751 			prev_row = curr_row
  35752 			curr_row = curr_row + uintptr(argb_stride)*4
  35753 			goto _1
  35754 		_1:
  35755 			;
  35756 			y = y + 1
  35757 		}
  35758 		if use_palette != 0 {
  35759 			v7 = int32(kPalette)
  35760 		} else {
  35761 			v7 = int32(kSpatialSubGreen)
  35762 		}
  35763 		last_mode_to_analyze = v7
  35764 		// Let's add one zero to the predicted histograms. The zeros are removed
  35765 		// too efficiently by the pix_diff == 0 comparison, at least one of the
  35766 		// zeros is likely to exist.
  35767 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPredSubGreen)*1024)) + 1
  35768 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePredSubGreen)*1024)) + 1
  35769 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoRedPred)*1024)) + 1
  35770 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoGreenPred)*1024)) + 1
  35771 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoBluePred)*1024)) + 1
  35772 		**(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) = **(**uint32_t)(__ccgo_up(histo + uintptr(kHistoAlphaPred)*1024)) + 1
  35773 		j = 0
  35774 		for {
  35775 			if !(j < int32(kHistoTotal)) {
  35776 				break
  35777 			}
  35778 			entropy_comp[j] = VP8LBitsEntropy(tls, histo+uintptr(j)*1024, int32(NUM_BUCKETS))
  35779 			goto _8
  35780 		_8:
  35781 			;
  35782 			j = j + 1
  35783 		}
  35784 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kDirect)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRed)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlue)]
  35785 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatial)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPred)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePred)]
  35786 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSubGreen)] = entropy_comp[int32(kHistoAlpha)] + entropy_comp[int32(kHistoRedSubGreen)] + entropy_comp[int32(kHistoGreen)] + entropy_comp[int32(kHistoBlueSubGreen)]
  35787 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kSpatialSubGreen)] = entropy_comp[int32(kHistoAlphaPred)] + entropy_comp[int32(kHistoRedPredSubGreen)] + entropy_comp[int32(kHistoGreenPred)] + entropy_comp[int32(kHistoBluePredSubGreen)]
  35788 		(**(**[6]uint64_t)(__ccgo_up(bp)))[int32(kPalette)] = entropy_comp[int32(kHistoPalette)]
  35789 		// When including transforms, there is an overhead in bits from
  35790 		// storing them. This overhead is small but matters for small images.
  35791 		// For spatial, there are 14 transformations.
  35792 		v3 = libc.Uint32FromInt32(transform_bits)
  35793 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35794 		goto _11
  35795 	_11:
  35796 		v5 = libc.Uint32FromInt32(transform_bits)
  35797 		v9 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35798 		goto _14
  35799 	_14:
  35800 		v10 = uint32(14)
  35801 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35802 			v18 = kLog2Table[v10]
  35803 		} else {
  35804 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35805 		}
  35806 		v12 = v18
  35807 		goto _17
  35808 	_17:
  35809 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatial)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35810 		// For color transforms: 24 as only 3 channels are considered in a
  35811 		// ColorTransformElement.
  35812 		v3 = libc.Uint32FromInt32(transform_bits)
  35813 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35814 		goto _21
  35815 	_21:
  35816 		v5 = libc.Uint32FromInt32(transform_bits)
  35817 		v9 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v5) - uint32(1)) >> v5
  35818 		goto _24
  35819 	_24:
  35820 		v10 = uint32(24)
  35821 		if v10 < uint32(LOG_LOOKUP_IDX_MAX) {
  35822 			v18 = kLog2Table[v10]
  35823 		} else {
  35824 			v18 = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastLog2Slow})))(tls, v10)
  35825 		}
  35826 		v12 = v18
  35827 		goto _27
  35828 	_27:
  35829 		**(**uint64_t)(__ccgo_up(bp + uintptr(kSpatialSubGreen)*8)) += uint64(v4) * uint64(v9) * uint64(v12)
  35830 		// For palettes, add the cost of storing the palette.
  35831 		// We empirically estimate the cost of a compressed entry as 8 bits.
  35832 		// The palette is differential-coded when compressed hence a much
  35833 		// lower cost than sizeof(uint32_t)*8.
  35834 		v29 = bp + uintptr(kPalette)*8
  35835 		*(*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))
  35836 		**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = int32(kDirect)
  35837 		k = int32(kDirect) + libc.Int32FromInt32(1)
  35838 		for {
  35839 			if !(k <= last_mode_to_analyze) {
  35840 				break
  35841 			}
  35842 			if (**(**[6]uint64_t)(__ccgo_up(bp)))[**(**EntropyIx)(__ccgo_up(min_entropy_ix))] > (**(**[6]uint64_t)(__ccgo_up(bp)))[k] {
  35843 				**(**EntropyIx)(__ccgo_up(min_entropy_ix)) = k
  35844 			}
  35845 			goto _30
  35846 		_30:
  35847 			;
  35848 			k = k + 1
  35849 		}
  35850 		**(**int32)(__ccgo_up(red_and_blue_always_zero)) = int32(1)
  35851 		red_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2)))*1024
  35852 		blue_histo = histo + uintptr(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&kHistoPairs)) + uintptr(**(**EntropyIx)(__ccgo_up(min_entropy_ix)))*2 + 1)))*1024
  35853 		i = int32(1)
  35854 		for {
  35855 			if !(i < int32(NUM_BUCKETS)) {
  35856 				break
  35857 			}
  35858 			if **(**uint32_t)(__ccgo_up(red_histo + uintptr(i)*4))|**(**uint32_t)(__ccgo_up(blue_histo + uintptr(i)*4)) != uint32(0) {
  35859 				**(**int32)(__ccgo_up(red_and_blue_always_zero)) = 0
  35860 				break
  35861 			}
  35862 			goto _31
  35863 		_31:
  35864 			;
  35865 			i = i + 1
  35866 		}
  35867 		WebPSafeFree(tls, histo)
  35868 		return int32(1)
  35869 	} else {
  35870 		return 0
  35871 	}
  35872 	return r
  35873 }
  35874 
  35875 // Let's check if the histogram of the chosen entropy mode has
  35876 // non-zero red and blue values. If all are zero, we can later skip
  35877 // the cross color optimization.
  35878 
  35879 var kHistoPairs = [5][2]uint8_t{
  35880 	0: {
  35881 		0: uint8(kHistoRed),
  35882 		1: uint8(kHistoBlue),
  35883 	},
  35884 	1: {
  35885 		0: uint8(kHistoRedPred),
  35886 		1: uint8(kHistoBluePred),
  35887 	},
  35888 	2: {
  35889 		0: uint8(kHistoRedSubGreen),
  35890 		1: uint8(kHistoBlueSubGreen),
  35891 	},
  35892 	3: {
  35893 		0: uint8(kHistoRedPredSubGreen),
  35894 		1: uint8(kHistoBluePredSubGreen),
  35895 	},
  35896 	4: {
  35897 		0: uint8(kHistoRed),
  35898 		1: uint8(kHistoBlue),
  35899 	},
  35900 }
  35901 
  35902 // C documentation
  35903 //
  35904 //	// Clamp histogram and transform bits.
  35905 func ClampBits(tls *libc.TLS, width int32, height int32, bits int32, min_bits int32, max_bits int32, image_size_max int32) (r int32) {
  35906 	var image_size, v1, v2 int32
  35907 	var v3, v4, v6, v7 uint32_t
  35908 	_, _, _, _, _, _, _ = image_size, v1, v2, v3, v4, v6, v7
  35909 	if bits < min_bits {
  35910 		v1 = min_bits
  35911 	} else {
  35912 		if bits > max_bits {
  35913 			v2 = max_bits
  35914 		} else {
  35915 			v2 = bits
  35916 		}
  35917 		v1 = v2
  35918 	}
  35919 	bits = v1
  35920 	v3 = libc.Uint32FromInt32(bits)
  35921 	v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35922 	goto _5
  35923 _5:
  35924 	v6 = libc.Uint32FromInt32(bits)
  35925 	v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35926 	goto _8
  35927 _8:
  35928 	image_size = libc.Int32FromUint32(v4 * v7)
  35929 	for bits < max_bits && image_size > image_size_max {
  35930 		bits = bits + 1
  35931 		v3 = libc.Uint32FromInt32(bits)
  35932 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35933 		goto _11
  35934 	_11:
  35935 		v6 = libc.Uint32FromInt32(bits)
  35936 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35937 		goto _14
  35938 	_14:
  35939 		image_size = libc.Int32FromUint32(v4 * v7)
  35940 	}
  35941 	// In case the bits reduce the image too much, choose the smallest value
  35942 	// setting the histogram image size to 1.
  35943 	for bits > min_bits && image_size == int32(1) {
  35944 		v3 = libc.Uint32FromInt32(bits - int32(1))
  35945 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  35946 		goto _17
  35947 	_17:
  35948 		v6 = libc.Uint32FromInt32(bits - int32(1))
  35949 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  35950 		goto _20
  35951 	_20:
  35952 		image_size = libc.Int32FromUint32(v4 * v7)
  35953 		if image_size != int32(1) {
  35954 			break
  35955 		}
  35956 		bits = bits - 1
  35957 	}
  35958 	return bits
  35959 }
  35960 
  35961 func GetHistoBits(tls *libc.TLS, method int32, use_palette int32, width int32, height int32) (r int32) {
  35962 	var histo_bits, v1 int32
  35963 	_, _ = histo_bits, v1
  35964 	if use_palette != 0 {
  35965 		v1 = int32(9)
  35966 	} else {
  35967 		v1 = int32(7)
  35968 	}
  35969 	// Make tile size a function of encoding method (Range: 0 to 6).
  35970 	histo_bits = v1 - method
  35971 	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))
  35972 }
  35973 
  35974 func GetTransformBits(tls *libc.TLS, method int32, histo_bits int32) (r int32) {
  35975 	var max_transform_bits, res, v1, v2, v3 int32
  35976 	_, _, _, _, _ = max_transform_bits, res, v1, v2, v3
  35977 	if method < int32(4) {
  35978 		v1 = int32(6)
  35979 	} else {
  35980 		if method > int32(4) {
  35981 			v2 = int32(4)
  35982 		} else {
  35983 			v2 = int32(5)
  35984 		}
  35985 		v1 = v2
  35986 	}
  35987 	max_transform_bits = v1
  35988 	if histo_bits > max_transform_bits {
  35989 		v3 = max_transform_bits
  35990 	} else {
  35991 		v3 = histo_bits
  35992 	}
  35993 	res = v3
  35994 	return res
  35995 }
  35996 
  35997 // C documentation
  35998 //
  35999 //	// Set of parameters to be used in each iteration of the cruncher.
  36000 type CrunchSubConfig = struct {
  36001 	Flz77        int32
  36002 	Fdo_no_cache int32
  36003 }
  36004 
  36005 type CrunchConfig = struct {
  36006 	Fentropy_idx          int32
  36007 	Fpalette_sorting_type PaletteSorting1
  36008 	Fsub_configs          [2]CrunchSubConfig
  36009 	Fsub_configs_size     int32
  36010 }
  36011 
  36012 // +2 because we add a palette sorting configuration for kPalette and
  36013 // kPaletteAndSpatial.
  36014 
  36015 func EncoderAnalyze(tls *libc.TLS, enc uintptr, crunch_configs uintptr, crunch_configs_size uintptr, red_and_blue_always_zero uintptr) (r int32) {
  36016 	bp := tls.Alloc(16)
  36017 	defer tls.Free(16)
  36018 	var config, pic uintptr
  36019 	var do_no_cache, height, i, j, low_effort, method, n_lz77s, sorting_method, transform_bits, use_palette, width, v1 int32
  36020 	var typed_sorting_method PaletteSorting1
  36021 	var _ /* min_entropy_ix at bp+0 */ EntropyIx
  36022 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = config, do_no_cache, height, i, j, low_effort, method, n_lz77s, pic, sorting_method, transform_bits, typed_sorting_method, use_palette, width, v1
  36023 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  36024 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  36025 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  36026 	config = (*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig
  36027 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  36028 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  36029 	// If set to 0, analyze the cache with the computed cache value. If 1, also
  36030 	// analyze with no-cache.
  36031 	do_no_cache = 0
  36032 	// Check whether a palette is possible.
  36033 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = GetColorPalette(tls, pic, enc+1128)
  36034 	use_palette = libc.BoolInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(MAX_PALETTE_SIZE))
  36035 	if !(use_palette != 0) {
  36036 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size = 0
  36037 	}
  36038 	// Empirical bit sizes.
  36039 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits = GetHistoBits(tls, method, use_palette, (*WebPPicture)(unsafe.Pointer(pic)).Fwidth, (*WebPPicture)(unsafe.Pointer(pic)).Fheight)
  36040 	transform_bits = GetTransformBits(tls, method, (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits)
  36041 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpredictor_transform_bits = transform_bits
  36042 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits = transform_bits
  36043 	if low_effort != 0 {
  36044 		// AnalyzeEntropy is somewhat slow.
  36045 		if use_palette != 0 {
  36046 			v1 = int32(kPalette)
  36047 		} else {
  36048 			v1 = int32(kSpatialSubGreen)
  36049 		}
  36050 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = v1
  36051 		if use_palette != 0 {
  36052 			v1 = int32(kSortedDefault)
  36053 		} else {
  36054 			v1 = int32(kUnusedPalette)
  36055 		}
  36056 		(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  36057 		n_lz77s = int32(1)
  36058 		**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  36059 	} else {
  36060 		// Try out multiple LZ77 on images with few colors.
  36061 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size > 0 && (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size <= int32(16) {
  36062 			v1 = int32(2)
  36063 		} else {
  36064 			v1 = int32(1)
  36065 		}
  36066 		n_lz77s = v1
  36067 		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) {
  36068 			return 0
  36069 		}
  36070 		if method == int32(6) && (*WebPConfig)(unsafe.Pointer(config)).Fquality == libc.Float32FromInt32(100) {
  36071 			do_no_cache = int32(1)
  36072 			// Go brute force on all transforms.
  36073 			**(**int32)(__ccgo_up(crunch_configs_size)) = 0
  36074 			i = 0
  36075 			for {
  36076 				if !(i < int32(kNumEntropyIx)) {
  36077 					break
  36078 				}
  36079 				// We can only apply kPalette or kPaletteAndSpatial if we can indeed use
  36080 				// a palette.
  36081 				if i != int32(kPalette) && i != int32(kPaletteAndSpatial) || use_palette != 0 {
  36082 					if use_palette != 0 && (i == int32(kPalette) || i == int32(kPaletteAndSpatial)) {
  36083 						sorting_method = 0
  36084 						for {
  36085 							if !(sorting_method < int32(kPaletteSortingNum)) {
  36086 								break
  36087 							}
  36088 							typed_sorting_method = sorting_method
  36089 							// TODO(vrabaud) kSortedDefault should be tested. It is omitted
  36090 							// for now for backward compatibility.
  36091 							if typed_sorting_method == int32(kUnusedPalette) || typed_sorting_method == int32(kSortedDefault) {
  36092 								goto _5
  36093 							}
  36094 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  36095 							(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = typed_sorting_method
  36096 							**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  36097 							goto _5
  36098 						_5:
  36099 							;
  36100 							sorting_method = sorting_method + 1
  36101 						}
  36102 					} else {
  36103 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fentropy_idx = i
  36104 						(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(**(**int32)(__ccgo_up(crunch_configs_size)))*28))).Fpalette_sorting_type = int32(kUnusedPalette)
  36105 						**(**int32)(__ccgo_up(crunch_configs_size)) = **(**int32)(__ccgo_up(crunch_configs_size)) + 1
  36106 					}
  36107 				}
  36108 				goto _4
  36109 			_4:
  36110 				;
  36111 				i = i + 1
  36112 			}
  36113 		} else {
  36114 			// Only choose the guessed best transform.
  36115 			**(**int32)(__ccgo_up(crunch_configs_size)) = int32(1)
  36116 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fentropy_idx = **(**EntropyIx)(__ccgo_up(bp))
  36117 			if use_palette != 0 {
  36118 				v1 = int32(kMinimizeDelta)
  36119 			} else {
  36120 				v1 = int32(kUnusedPalette)
  36121 			}
  36122 			(**(**CrunchConfig)(__ccgo_up(crunch_configs))).Fpalette_sorting_type = v1
  36123 			if (*WebPConfig)(unsafe.Pointer(config)).Fquality >= libc.Float32FromInt32(75) && method == int32(5) {
  36124 				// Test with and without color cache.
  36125 				do_no_cache = int32(1)
  36126 				// If we have a palette, also check in combination with spatial.
  36127 				if **(**EntropyIx)(__ccgo_up(bp)) == int32(kPalette) {
  36128 					**(**int32)(__ccgo_up(crunch_configs_size)) = int32(2)
  36129 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fentropy_idx = int32(kPaletteAndSpatial)
  36130 					(**(**CrunchConfig)(__ccgo_up(crunch_configs + 1*28))).Fpalette_sorting_type = int32(kMinimizeDelta)
  36131 				}
  36132 			}
  36133 		}
  36134 	}
  36135 	// Fill in the different LZ77s.
  36136 	i = 0
  36137 	for {
  36138 		if !(i < **(**int32)(__ccgo_up(crunch_configs_size))) {
  36139 			break
  36140 		}
  36141 		j = 0
  36142 		for {
  36143 			if !(j < n_lz77s) {
  36144 				break
  36145 			}
  36146 			if j == 0 {
  36147 				v1 = int32(kLZ77Standard) | int32(kLZ77RLE)
  36148 			} else {
  36149 				v1 = int32(kLZ77Box)
  36150 			}
  36151 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Flz77 = v1
  36152 			(**(**CrunchSubConfig)(__ccgo_up(crunch_configs + uintptr(i)*28 + 8 + uintptr(j)*8))).Fdo_no_cache = do_no_cache
  36153 			goto _8
  36154 		_8:
  36155 			;
  36156 			j = j + 1
  36157 		}
  36158 		(**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(i)*28))).Fsub_configs_size = n_lz77s
  36159 		goto _7
  36160 	_7:
  36161 		;
  36162 		i = i + 1
  36163 	}
  36164 	return int32(1)
  36165 }
  36166 
  36167 func EncoderInit(tls *libc.TLS, enc uintptr) (r int32) {
  36168 	var height, i, pix_cnt, refs_block_size, width int32
  36169 	var pic uintptr
  36170 	_, _, _, _, _, _ = height, i, pic, pix_cnt, refs_block_size, width
  36171 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  36172 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  36173 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  36174 	pix_cnt = width * height
  36175 	// we round the block size up, so we're guaranteed to have
  36176 	// at most MAX_REFS_BLOCK_PER_IMAGE blocks used:
  36177 	refs_block_size = (pix_cnt-int32(1))/int32(MAX_REFS_BLOCK_PER_IMAGE) + int32(1)
  36178 	if !(VP8LHashChainInit(tls, enc+2312, pix_cnt) != 0) {
  36179 		return 0
  36180 	}
  36181 	i = 0
  36182 	for {
  36183 		if !(i < int32(4)) {
  36184 			break
  36185 		}
  36186 		VP8LBackwardRefsInit(tls, enc+2152+uintptr(i)*40, refs_block_size)
  36187 		goto _1
  36188 	_1:
  36189 		;
  36190 		i = i + 1
  36191 	}
  36192 	return int32(1)
  36193 }
  36194 
  36195 // C documentation
  36196 //
  36197 //	// Returns false in case of memory error.
  36198 func GetHuffBitLengthsAndCodes(tls *libc.TLS, histogram_image uintptr, huffman_codes uintptr) (r int32) {
  36199 	var bit_length, histogram_image_size, i, k, max_num_symbols, num_symbols, ok, v3, v4, v5, v7, v8 int32
  36200 	var buf_rle, codes, codes1, codes2, histo, histo1, huff_tree, lengths, mem_buf uintptr
  36201 	var total_length_size uint64_t
  36202 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  36203 	ok = 0
  36204 	total_length_size = uint64(0)
  36205 	mem_buf = libc.UintptrFromInt32(0)
  36206 	histogram_image_size = (*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize
  36207 	max_num_symbols = 0
  36208 	buf_rle = libc.UintptrFromInt32(0)
  36209 	huff_tree = libc.UintptrFromInt32(0)
  36210 	// Iterate over all histograms and get the aggregate number of codes used.
  36211 	i = 0
  36212 	for {
  36213 		if !(i < histogram_image_size) {
  36214 			break
  36215 		}
  36216 		histo = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  36217 		codes = huffman_codes + uintptr(int32(5)*i)*24
  36218 		k = 0
  36219 		for {
  36220 			if !(k < int32(5)) {
  36221 				break
  36222 			}
  36223 			if k == 0 {
  36224 				v4 = (*VP8LHistogram)(unsafe.Pointer(histo)).Fpalette_code_bits
  36225 				if v4 > 0 {
  36226 					v7 = int32(1) << v4
  36227 				} else {
  36228 					v7 = 0
  36229 				}
  36230 				v5 = libc.Int32FromInt32(NUM_LITERAL_CODES) + libc.Int32FromInt32(NUM_LENGTH_CODES) + v7
  36231 				goto _6
  36232 			_6:
  36233 				v3 = v5
  36234 			} else {
  36235 				if k == int32(4) {
  36236 					v8 = int32(NUM_DISTANCE_CODES)
  36237 				} else {
  36238 					v8 = int32(256)
  36239 				}
  36240 				v3 = v8
  36241 			}
  36242 			num_symbols = v3
  36243 			(**(**HuffmanTreeCode)(__ccgo_up(codes + uintptr(k)*24))).Fnum_symbols = num_symbols
  36244 			total_length_size = total_length_size + libc.Uint64FromInt32(num_symbols)
  36245 			goto _2
  36246 		_2:
  36247 			;
  36248 			k = k + 1
  36249 		}
  36250 		goto _1
  36251 	_1:
  36252 		;
  36253 		i = i + 1
  36254 	}
  36255 	// Allocate and Set Huffman codes.
  36256 	mem_buf = WebPSafeCalloc(tls, total_length_size, libc.Uint64FromInt64(1)+libc.Uint64FromInt64(2))
  36257 	if mem_buf == libc.UintptrFromInt32(0) {
  36258 		goto End
  36259 	}
  36260 	codes1 = mem_buf
  36261 	lengths = codes1 + uintptr(total_length_size)*2
  36262 	i = 0
  36263 	for {
  36264 		if !(i < int32(5)*histogram_image_size) {
  36265 			break
  36266 		}
  36267 		bit_length = (**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fnum_symbols
  36268 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcodes = codes1
  36269 		(**(**HuffmanTreeCode)(__ccgo_up(huffman_codes + uintptr(i)*24))).Fcode_lengths = lengths
  36270 		codes1 = codes1 + uintptr(bit_length)*2
  36271 		lengths = lengths + uintptr(bit_length)
  36272 		if max_num_symbols < bit_length {
  36273 			max_num_symbols = bit_length
  36274 		}
  36275 		goto _9
  36276 	_9:
  36277 		;
  36278 		i = i + 1
  36279 	}
  36280 	buf_rle = WebPSafeMalloc(tls, uint64(1), libc.Uint64FromInt32(max_num_symbols))
  36281 	huff_tree = WebPSafeMalloc(tls, uint64(uint64(3)*libc.Uint64FromInt32(max_num_symbols)), uint64(16))
  36282 	if buf_rle == libc.UintptrFromInt32(0) || huff_tree == libc.UintptrFromInt32(0) {
  36283 		goto End
  36284 	}
  36285 	// Create Huffman trees.
  36286 	i = 0
  36287 	for {
  36288 		if !(i < histogram_image_size) {
  36289 			break
  36290 		}
  36291 		codes2 = huffman_codes + uintptr(int32(5)*i)*24
  36292 		histo1 = **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms + uintptr(i)*8))
  36293 		VP8LCreateHuffmanTree(tls, (*VP8LHistogram)(unsafe.Pointer(histo1)).Fliteral, int32(15), buf_rle, huff_tree, codes2+uintptr(0)*24)
  36294 		VP8LCreateHuffmanTree(tls, histo1+8, int32(15), buf_rle, huff_tree, codes2+uintptr(1)*24)
  36295 		VP8LCreateHuffmanTree(tls, histo1+1032, int32(15), buf_rle, huff_tree, codes2+uintptr(2)*24)
  36296 		VP8LCreateHuffmanTree(tls, histo1+2056, int32(15), buf_rle, huff_tree, codes2+uintptr(3)*24)
  36297 		VP8LCreateHuffmanTree(tls, histo1+3080, int32(15), buf_rle, huff_tree, codes2+uintptr(4)*24)
  36298 		goto _10
  36299 	_10:
  36300 		;
  36301 		i = i + 1
  36302 	}
  36303 	ok = int32(1)
  36304 	goto End
  36305 End:
  36306 	;
  36307 	WebPSafeFree(tls, huff_tree)
  36308 	WebPSafeFree(tls, buf_rle)
  36309 	if !(ok != 0) {
  36310 		WebPSafeFree(tls, mem_buf)
  36311 		libc.Xmemset(tls, huffman_codes, 0, libc.Uint64FromInt32(int32(5)*histogram_image_size)*uint64(24))
  36312 	}
  36313 	return ok
  36314 }
  36315 
  36316 func StoreHuffmanTreeOfHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, code_length_bitdepth uintptr) {
  36317 	var codes_to_store, i, v4 int32
  36318 	var v2 uintptr
  36319 	var v3 uint32_t
  36320 	_, _, _, _, _ = codes_to_store, i, v2, v3, v4
  36321 	// Throw away trailing zeros:
  36322 	codes_to_store = int32(CODE_LENGTH_CODES)
  36323 	for {
  36324 		if !(codes_to_store > int32(4)) {
  36325 			break
  36326 		}
  36327 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[codes_to_store-int32(1)])))) != 0 {
  36328 			break
  36329 		}
  36330 		goto _1
  36331 	_1:
  36332 		;
  36333 		codes_to_store = codes_to_store - 1
  36334 	}
  36335 	v2 = bw1
  36336 	v3 = libc.Uint32FromInt32(codes_to_store - int32(4))
  36337 	v4 = int32(4)
  36338 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36339 		if v4 > libc.Int32FromInt32(0) {
  36340 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36341 				VP8LPutBitsFlushBits(tls, v2)
  36342 			}
  36343 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36344 			**(**int32)(__ccgo_up(v2 + 4)) += v4
  36345 		}
  36346 	} else {
  36347 		VP8LPutBitsInternal(tls, v2, v3, v4)
  36348 	}
  36349 	i = 0
  36350 	for {
  36351 		if !(i < codes_to_store) {
  36352 			break
  36353 		}
  36354 		v2 = bw1
  36355 		v3 = uint32(**(**uint8_t)(__ccgo_up(code_length_bitdepth + uintptr(kStorageOrder[i]))))
  36356 		v4 = int32(3)
  36357 		if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36358 			if v4 > libc.Int32FromInt32(0) {
  36359 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36360 					VP8LPutBitsFlushBits(tls, v2)
  36361 				}
  36362 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36363 				**(**int32)(__ccgo_up(v2 + 4)) += v4
  36364 			}
  36365 		} else {
  36366 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36367 		}
  36368 		goto _5
  36369 	_5:
  36370 		;
  36371 		i = i + 1
  36372 	}
  36373 }
  36374 
  36375 // RFC 1951 will calm you down if you are worried about this funny sequence.
  36376 // This sequence is tuned from that, but more weighted for lower symbol count,
  36377 // and more spiking histograms.
  36378 var kStorageOrder = [19]uint8_t{
  36379 	0:  uint8(17),
  36380 	1:  uint8(18),
  36381 	3:  uint8(1),
  36382 	4:  uint8(2),
  36383 	5:  uint8(3),
  36384 	6:  uint8(4),
  36385 	7:  uint8(5),
  36386 	8:  uint8(16),
  36387 	9:  uint8(6),
  36388 	10: uint8(7),
  36389 	11: uint8(8),
  36390 	12: uint8(9),
  36391 	13: uint8(10),
  36392 	14: uint8(11),
  36393 	15: uint8(12),
  36394 	16: uint8(13),
  36395 	17: uint8(14),
  36396 	18: uint8(15),
  36397 }
  36398 
  36399 func ClearHuffmanTreeIfOnlyOneSymbol(tls *libc.TLS, huffman_code uintptr) {
  36400 	var count, k int32
  36401 	_, _ = count, k
  36402 	count = 0
  36403 	k = 0
  36404 	for {
  36405 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36406 			break
  36407 		}
  36408 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k)))) != 0 {
  36409 			count = count + 1
  36410 			if count > int32(1) {
  36411 				return
  36412 			}
  36413 		}
  36414 		goto _1
  36415 	_1:
  36416 		;
  36417 		k = k + 1
  36418 	}
  36419 	k = 0
  36420 	for {
  36421 		if !(k < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols) {
  36422 			break
  36423 		}
  36424 		**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(k))) = uint8(0)
  36425 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(k)*2)) = uint16(0)
  36426 		goto _2
  36427 	_2:
  36428 		;
  36429 		k = k + 1
  36430 	}
  36431 }
  36432 
  36433 func StoreHuffmanTreeToBitMask(tls *libc.TLS, bw1 uintptr, tokens uintptr, num_tokens int32, huffman_code uintptr) {
  36434 	var extra_bits, i, ix, v4 int32
  36435 	var v2 uintptr
  36436 	var v3 uint32_t
  36437 	_, _, _, _, _, _ = extra_bits, i, ix, v2, v3, v4
  36438 	i = 0
  36439 	for {
  36440 		if !(i < num_tokens) {
  36441 			break
  36442 		}
  36443 		ix = libc.Int32FromUint8((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fcode)
  36444 		extra_bits = libc.Int32FromUint8((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i)*2))).Fextra_bits)
  36445 		v2 = bw1
  36446 		v3 = uint32(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcodes + uintptr(ix)*2)))
  36447 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(ix))))
  36448 		if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36449 			if v4 > libc.Int32FromInt32(0) {
  36450 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36451 					VP8LPutBitsFlushBits(tls, v2)
  36452 				}
  36453 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36454 				**(**int32)(__ccgo_up(v2 + 4)) += v4
  36455 			}
  36456 		} else {
  36457 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36458 		}
  36459 		switch ix {
  36460 		case int32(16):
  36461 			v2 = bw1
  36462 			v3 = libc.Uint32FromInt32(extra_bits)
  36463 			v4 = int32(2)
  36464 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36465 				if v4 > libc.Int32FromInt32(0) {
  36466 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36467 						VP8LPutBitsFlushBits(tls, v2)
  36468 					}
  36469 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36470 					**(**int32)(__ccgo_up(v2 + 4)) += v4
  36471 				}
  36472 			} else {
  36473 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36474 			}
  36475 		case int32(17):
  36476 			v2 = bw1
  36477 			v3 = libc.Uint32FromInt32(extra_bits)
  36478 			v4 = int32(3)
  36479 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36480 				if v4 > libc.Int32FromInt32(0) {
  36481 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36482 						VP8LPutBitsFlushBits(tls, v2)
  36483 					}
  36484 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36485 					**(**int32)(__ccgo_up(v2 + 4)) += v4
  36486 				}
  36487 			} else {
  36488 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36489 			}
  36490 		case int32(18):
  36491 			v2 = bw1
  36492 			v3 = libc.Uint32FromInt32(extra_bits)
  36493 			v4 = int32(7)
  36494 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36495 				if v4 > libc.Int32FromInt32(0) {
  36496 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36497 						VP8LPutBitsFlushBits(tls, v2)
  36498 					}
  36499 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36500 					**(**int32)(__ccgo_up(v2 + 4)) += v4
  36501 				}
  36502 			} else {
  36503 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36504 			}
  36505 			break
  36506 		}
  36507 		goto _1
  36508 	_1:
  36509 		;
  36510 		i = i + 1
  36511 	}
  36512 }
  36513 
  36514 // C documentation
  36515 //
  36516 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36517 func StoreFullHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, tree uintptr) {
  36518 	bp := tls.Alloc(192)
  36519 	defer tls.Free(192)
  36520 	var i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v3 int32
  36521 	var v1 uintptr
  36522 	var v2 uint32_t
  36523 	var _ /* buf_rle at bp+164 */ [19]uint8_t
  36524 	var _ /* code_length_bitdepth at bp+0 */ [19]uint8_t
  36525 	var _ /* code_length_bitdepth_symbols at bp+20 */ [19]uint16_t
  36526 	var _ /* histogram at bp+88 */ [19]uint32_t
  36527 	var _ /* huffman_code at bp+64 */ HuffmanTreeCode
  36528 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, i1, ix, length, max_tokens, nbitpairs, nbits, num_tokens, trailing_zero_bits, trimmed_length, write_trimmed_length, v1, v2, v3
  36529 	**(**[19]uint8_t)(__ccgo_up(bp)) = [19]uint8_t{}
  36530 	**(**[19]uint16_t)(__ccgo_up(bp + 20)) = [19]uint16_t{}
  36531 	max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  36532 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fnum_symbols = int32(CODE_LENGTH_CODES)
  36533 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcode_lengths = bp
  36534 	(**(**HuffmanTreeCode)(__ccgo_up(bp + 64))).Fcodes = bp + 20
  36535 	v1 = bw1
  36536 	v2 = uint32(0)
  36537 	v3 = int32(1)
  36538 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36539 		if v3 > libc.Int32FromInt32(0) {
  36540 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36541 				VP8LPutBitsFlushBits(tls, v1)
  36542 			}
  36543 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36544 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  36545 		}
  36546 	} else {
  36547 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36548 	}
  36549 	num_tokens = VP8LCreateCompressedHuffmanTree(tls, tree, tokens, max_tokens)
  36550 	**(**[19]uint32_t)(__ccgo_up(bp + 88)) = [19]uint32_t{}
  36551 	**(**[19]uint8_t)(__ccgo_up(bp + 164)) = [19]uint8_t{}
  36552 	i = 0
  36553 	for {
  36554 		if !(i < num_tokens) {
  36555 			break
  36556 		}
  36557 		(**(**[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
  36558 		goto _4
  36559 	_4:
  36560 		;
  36561 		i = i + 1
  36562 	}
  36563 	VP8LCreateHuffmanTree(tls, bp+88, int32(7), bp+164, huff_tree, bp+64)
  36564 	StoreHuffmanTreeOfHuffmanTreeToBitMask(tls, bw1, bp)
  36565 	ClearHuffmanTreeIfOnlyOneSymbol(tls, bp+64)
  36566 	trailing_zero_bits = 0
  36567 	trimmed_length = num_tokens
  36568 	i1 = num_tokens
  36569 	for {
  36570 		v3 = i1
  36571 		i1 = i1 - 1
  36572 		if !(v3 > 0) {
  36573 			break
  36574 		}
  36575 		ix = libc.Int32FromUint8((**(**HuffmanTreeToken)(__ccgo_up(tokens + uintptr(i1)*2))).Fcode)
  36576 		if ix == 0 || ix == int32(17) || ix == int32(18) {
  36577 			trimmed_length = trimmed_length - 1 // discount trailing zeros
  36578 			trailing_zero_bits = trailing_zero_bits + libc.Int32FromUint8((**(**[19]uint8_t)(__ccgo_up(bp)))[ix])
  36579 			if ix == int32(17) {
  36580 				trailing_zero_bits = trailing_zero_bits + int32(3)
  36581 			} else {
  36582 				if ix == int32(18) {
  36583 					trailing_zero_bits = trailing_zero_bits + int32(7)
  36584 				}
  36585 			}
  36586 		} else {
  36587 			break
  36588 		}
  36589 	}
  36590 	write_trimmed_length = libc.BoolInt32(trimmed_length > int32(1) && trailing_zero_bits > int32(12))
  36591 	if write_trimmed_length != 0 {
  36592 		v3 = trimmed_length
  36593 	} else {
  36594 		v3 = num_tokens
  36595 	}
  36596 	length = v3
  36597 	v1 = bw1
  36598 	v2 = libc.Uint32FromInt32(write_trimmed_length)
  36599 	v3 = int32(1)
  36600 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36601 		if v3 > libc.Int32FromInt32(0) {
  36602 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36603 				VP8LPutBitsFlushBits(tls, v1)
  36604 			}
  36605 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36606 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  36607 		}
  36608 	} else {
  36609 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36610 	}
  36611 	if write_trimmed_length != 0 {
  36612 		if trimmed_length == int32(2) {
  36613 			v1 = bw1
  36614 			v2 = uint32(0)
  36615 			v3 = libc.Int32FromInt32(3) + libc.Int32FromInt32(2)
  36616 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36617 				if v3 > libc.Int32FromInt32(0) {
  36618 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36619 						VP8LPutBitsFlushBits(tls, v1)
  36620 					}
  36621 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36622 					**(**int32)(__ccgo_up(v1 + 4)) += v3
  36623 				}
  36624 			} else {
  36625 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36626 			} // nbitpairs=1, trimmed_length=2
  36627 		} else {
  36628 			v3 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(trimmed_length-int32(2)))
  36629 			goto _14
  36630 		_14:
  36631 			nbits = v3
  36632 			nbitpairs = nbits/int32(2) + int32(1)
  36633 			v1 = bw1
  36634 			v2 = libc.Uint32FromInt32(nbitpairs - int32(1))
  36635 			v3 = int32(3)
  36636 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36637 				if v3 > libc.Int32FromInt32(0) {
  36638 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36639 						VP8LPutBitsFlushBits(tls, v1)
  36640 					}
  36641 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36642 					**(**int32)(__ccgo_up(v1 + 4)) += v3
  36643 				}
  36644 			} else {
  36645 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36646 			}
  36647 			v1 = bw1
  36648 			v2 = libc.Uint32FromInt32(trimmed_length - int32(2))
  36649 			v3 = nbitpairs * int32(2)
  36650 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36651 				if v3 > libc.Int32FromInt32(0) {
  36652 					if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36653 						VP8LPutBitsFlushBits(tls, v1)
  36654 					}
  36655 					**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36656 					**(**int32)(__ccgo_up(v1 + 4)) += v3
  36657 				}
  36658 			} else {
  36659 				VP8LPutBitsInternal(tls, v1, v2, v3)
  36660 			}
  36661 		}
  36662 	}
  36663 	StoreHuffmanTreeToBitMask(tls, bw1, tokens, length, bp+64)
  36664 }
  36665 
  36666 // C documentation
  36667 //
  36668 //	// 'huff_tree' and 'tokens' are pre-alloacted buffers.
  36669 func StoreHuffmanCode(tls *libc.TLS, bw1 uintptr, huff_tree uintptr, tokens uintptr, huffman_code uintptr) {
  36670 	var count, i, kMaxBits, kMaxSymbol, v4 int32
  36671 	var symbols [2]int32
  36672 	var v2 uintptr
  36673 	var v3 uint32_t
  36674 	_, _, _, _, _, _, _, _ = count, i, kMaxBits, kMaxSymbol, symbols, v2, v3, v4
  36675 	count = 0
  36676 	symbols = [2]int32{}
  36677 	kMaxBits = int32(8)
  36678 	kMaxSymbol = int32(1) << kMaxBits
  36679 	// Check whether it's a small tree.
  36680 	i = 0
  36681 	for {
  36682 		if !(i < (*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fnum_symbols && count < int32(3)) {
  36683 			break
  36684 		}
  36685 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(huffman_code)).Fcode_lengths + uintptr(i)))) != 0 {
  36686 			if count < int32(2) {
  36687 				symbols[count] = i
  36688 			}
  36689 			count = count + 1
  36690 		}
  36691 		goto _1
  36692 	_1:
  36693 		;
  36694 		i = i + 1
  36695 	}
  36696 	if count == 0 { // emit minimal tree for empty cases
  36697 		// bits: small tree marker: 1, count-1: 0, large 8-bit code: 0, code: 0
  36698 		v2 = bw1
  36699 		v3 = uint32(0x01)
  36700 		v4 = int32(4)
  36701 		if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36702 			if v4 > libc.Int32FromInt32(0) {
  36703 				if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36704 					VP8LPutBitsFlushBits(tls, v2)
  36705 				}
  36706 				**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36707 				**(**int32)(__ccgo_up(v2 + 4)) += v4
  36708 			}
  36709 		} else {
  36710 			VP8LPutBitsInternal(tls, v2, v3, v4)
  36711 		}
  36712 	} else {
  36713 		if count <= int32(2) && symbols[0] < kMaxSymbol && symbols[int32(1)] < kMaxSymbol {
  36714 			v2 = bw1
  36715 			v3 = uint32(1)
  36716 			v4 = int32(1)
  36717 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36718 				if v4 > libc.Int32FromInt32(0) {
  36719 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36720 						VP8LPutBitsFlushBits(tls, v2)
  36721 					}
  36722 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36723 					**(**int32)(__ccgo_up(v2 + 4)) += v4
  36724 				}
  36725 			} else {
  36726 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36727 			} // Small tree marker to encode 1 or 2 symbols.
  36728 			v2 = bw1
  36729 			v3 = libc.Uint32FromInt32(count - int32(1))
  36730 			v4 = int32(1)
  36731 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36732 				if v4 > libc.Int32FromInt32(0) {
  36733 					if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36734 						VP8LPutBitsFlushBits(tls, v2)
  36735 					}
  36736 					**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36737 					**(**int32)(__ccgo_up(v2 + 4)) += v4
  36738 				}
  36739 			} else {
  36740 				VP8LPutBitsInternal(tls, v2, v3, v4)
  36741 			}
  36742 			if symbols[0] <= int32(1) {
  36743 				v2 = bw1
  36744 				v3 = uint32(0)
  36745 				v4 = int32(1)
  36746 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36747 					if v4 > libc.Int32FromInt32(0) {
  36748 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36749 							VP8LPutBitsFlushBits(tls, v2)
  36750 						}
  36751 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36752 						**(**int32)(__ccgo_up(v2 + 4)) += v4
  36753 					}
  36754 				} else {
  36755 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36756 				} // Code bit for small (1 bit) symbol value.
  36757 				v2 = bw1
  36758 				v3 = libc.Uint32FromInt32(symbols[0])
  36759 				v4 = int32(1)
  36760 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36761 					if v4 > libc.Int32FromInt32(0) {
  36762 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36763 							VP8LPutBitsFlushBits(tls, v2)
  36764 						}
  36765 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36766 						**(**int32)(__ccgo_up(v2 + 4)) += v4
  36767 					}
  36768 				} else {
  36769 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36770 				}
  36771 			} else {
  36772 				v2 = bw1
  36773 				v3 = uint32(1)
  36774 				v4 = int32(1)
  36775 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36776 					if v4 > libc.Int32FromInt32(0) {
  36777 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36778 							VP8LPutBitsFlushBits(tls, v2)
  36779 						}
  36780 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36781 						**(**int32)(__ccgo_up(v2 + 4)) += v4
  36782 					}
  36783 				} else {
  36784 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36785 				}
  36786 				v2 = bw1
  36787 				v3 = libc.Uint32FromInt32(symbols[0])
  36788 				v4 = int32(8)
  36789 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36790 					if v4 > libc.Int32FromInt32(0) {
  36791 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36792 							VP8LPutBitsFlushBits(tls, v2)
  36793 						}
  36794 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36795 						**(**int32)(__ccgo_up(v2 + 4)) += v4
  36796 					}
  36797 				} else {
  36798 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36799 				}
  36800 			}
  36801 			if count == int32(2) {
  36802 				v2 = bw1
  36803 				v3 = libc.Uint32FromInt32(symbols[int32(1)])
  36804 				v4 = int32(8)
  36805 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36806 					if v4 > libc.Int32FromInt32(0) {
  36807 						if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  36808 							VP8LPutBitsFlushBits(tls, v2)
  36809 						}
  36810 						**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  36811 						**(**int32)(__ccgo_up(v2 + 4)) += v4
  36812 					}
  36813 				} else {
  36814 					VP8LPutBitsInternal(tls, v2, v3, v4)
  36815 				}
  36816 			}
  36817 		} else {
  36818 			StoreFullHuffmanCode(tls, bw1, huff_tree, tokens, huffman_code)
  36819 		}
  36820 	}
  36821 }
  36822 
  36823 func WriteHuffmanCode(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32) {
  36824 	var depth, symbol, v3 int32
  36825 	var v1 uintptr
  36826 	var v2 uint32_t
  36827 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36828 	depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36829 	symbol = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36830 	v1 = bw1
  36831 	v2 = libc.Uint32FromInt32(symbol)
  36832 	v3 = depth
  36833 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36834 		if v3 > libc.Int32FromInt32(0) {
  36835 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36836 				VP8LPutBitsFlushBits(tls, v1)
  36837 			}
  36838 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36839 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  36840 		}
  36841 	} else {
  36842 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36843 	}
  36844 }
  36845 
  36846 func WriteHuffmanCodeWithExtraBits(tls *libc.TLS, bw1 uintptr, code uintptr, code_index int32, bits1 int32, n_bits1 int32) {
  36847 	var depth, symbol, v3 int32
  36848 	var v1 uintptr
  36849 	var v2 uint32_t
  36850 	_, _, _, _, _ = depth, symbol, v1, v2, v3
  36851 	depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcode_lengths + uintptr(code_index))))
  36852 	symbol = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(code)).Fcodes + uintptr(code_index)*2)))
  36853 	v1 = bw1
  36854 	v2 = libc.Uint32FromInt32(bits1<<depth | symbol)
  36855 	v3 = depth + n_bits1
  36856 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  36857 		if v3 > libc.Int32FromInt32(0) {
  36858 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  36859 				VP8LPutBitsFlushBits(tls, v1)
  36860 			}
  36861 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  36862 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  36863 		}
  36864 	} else {
  36865 		VP8LPutBitsInternal(tls, v1, v2, v3)
  36866 	}
  36867 }
  36868 
  36869 func StoreImageToBitMask(tls *libc.TLS, bw1 uintptr, width int32, histo_bits int32, refs uintptr, histogram_symbols uintptr, huffman_codes uintptr, pic uintptr) (r int32) {
  36870 	bp := tls.Alloc(48)
  36871 	defer tls.Free(48)
  36872 	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
  36873 	var codes, v, v20, v21, v22, v24 uintptr
  36874 	var prefix_code VP8LPrefixCode
  36875 	var v1 uint32
  36876 	var v2, v3 uint32_t
  36877 	var _ /* bits at bp+24 */ int32
  36878 	var _ /* c at bp+0 */ VP8LRefsCursor
  36879 	var _ /* code at bp+32 */ int32
  36880 	var _ /* n_bits at bp+28 */ int32
  36881 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  36882 	if histo_bits != 0 {
  36883 		v2 = libc.Uint32FromInt32(histo_bits)
  36884 		v3 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  36885 		goto _4
  36886 	_4:
  36887 		v1 = v3
  36888 	} else {
  36889 		v1 = uint32(1)
  36890 	}
  36891 	histo_xsize = libc.Int32FromUint32(v1)
  36892 	if histo_bits == 0 {
  36893 		v5 = 0
  36894 	} else {
  36895 		v5 = -(int32(1) << histo_bits)
  36896 	}
  36897 	tile_mask = v5
  36898 	// x and y trace the position in the image.
  36899 	x = 0
  36900 	y = 0
  36901 	tile_x = x & tile_mask
  36902 	tile_y = y & tile_mask
  36903 	histogram_ix = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(histogram_symbols)) >> libc.Int32FromInt32(8) & uint32(0xffff))
  36904 	codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36905 	**(**VP8LRefsCursor)(__ccgo_up(bp)) = VP8LRefsCursorInit(tls, refs)
  36906 	for {
  36907 		v6 = libc.BoolInt32((*VP8LRefsCursor)(unsafe.Pointer(bp)).Fcur_pos != libc.UintptrFromInt32(0))
  36908 		goto _7
  36909 	_7:
  36910 		if !(v6 != 0) {
  36911 			break
  36912 		}
  36913 		v = (**(**VP8LRefsCursor)(__ccgo_up(bp))).Fcur_pos
  36914 		if tile_x != x&tile_mask || tile_y != y&tile_mask {
  36915 			tile_x = x & tile_mask
  36916 			tile_y = y & tile_mask
  36917 			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))
  36918 			codes = huffman_codes + uintptr(int32(5)*histogram_ix)*24
  36919 		}
  36920 		v5 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kLiteral))
  36921 		goto _9
  36922 	_9:
  36923 		if v5 != 0 {
  36924 			k = 0
  36925 			for {
  36926 				if !(k < int32(4)) {
  36927 					break
  36928 				}
  36929 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance >> (libc.Int32FromUint8(order[k]) * libc.Int32FromInt32(8)) & uint32(0xff)
  36930 				goto _12
  36931 			_12:
  36932 				code2 = libc.Int32FromUint32(v2)
  36933 				WriteHuffmanCode(tls, bw1, codes+uintptr(k)*24, code2)
  36934 				goto _10
  36935 			_10:
  36936 				;
  36937 				k = k + 1
  36938 			}
  36939 		} else {
  36940 			v5 = libc.BoolInt32(libc.Int32FromUint8((*PixOrCopy)(unsafe.Pointer(v)).Fmode) == int32(kCacheIdx))
  36941 			goto _14
  36942 		_14:
  36943 			if v5 != 0 {
  36944 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36945 				goto _16
  36946 			_16:
  36947 				code3 = libc.Int32FromUint32(v2)
  36948 				literal_ix = libc.Int32FromInt32(256) + libc.Int32FromInt32(NUM_LENGTH_CODES) + code3
  36949 				WriteHuffmanCode(tls, bw1, codes, literal_ix)
  36950 			} else {
  36951 				v2 = (*PixOrCopy)(unsafe.Pointer(v)).Fargb_or_distance
  36952 				goto _18
  36953 			_18:
  36954 				distance2 = libc.Int32FromUint32(v2)
  36955 				v5 = libc.Int32FromUint16((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  36956 				v20 = bp + 32
  36957 				v21 = bp + 28
  36958 				v22 = bp + 24
  36959 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36960 					prefix_code = kPrefixEncodeCode[v5]
  36961 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36962 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36963 					**(**int32)(__ccgo_up(v22)) = libc.Int32FromUint8(kPrefixEncodeExtraBitsValue[v5])
  36964 				} else {
  36965 					v6 = v5
  36966 					v24 = v21
  36967 					v6 = v6 - 1
  36968 					v8 = v6
  36969 					v13 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v8))
  36970 					goto _27
  36971 				_27:
  36972 					highest_bit = v13
  36973 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  36974 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  36975 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  36976 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  36977 				}
  36978 				WriteHuffmanCodeWithExtraBits(tls, bw1, codes, int32(256)+**(**int32)(__ccgo_up(bp + 32)), **(**int32)(__ccgo_up(bp + 24)), **(**int32)(__ccgo_up(bp + 28)))
  36979 				// Don't write the distance with the extra bits code since
  36980 				// the distance can be up to 18 bits of extra bits, and the prefix
  36981 				// 15 bits, totaling to 33, and our PutBits only supports up to 32 bits.
  36982 				v5 = distance2
  36983 				v20 = bp + 32
  36984 				v21 = bp + 28
  36985 				v22 = bp + 24
  36986 				if v5 < libc.Int32FromInt32(PREFIX_LOOKUP_IDX_MAX) {
  36987 					prefix_code = kPrefixEncodeCode[v5]
  36988 					**(**int32)(__ccgo_up(v20)) = int32(prefix_code.Fcode)
  36989 					**(**int32)(__ccgo_up(v21)) = int32(prefix_code.Fextra_bits)
  36990 					**(**int32)(__ccgo_up(v22)) = libc.Int32FromUint8(kPrefixEncodeExtraBitsValue[v5])
  36991 				} else {
  36992 					v6 = v5
  36993 					v24 = v21
  36994 					v6 = v6 - 1
  36995 					v8 = v6
  36996 					v13 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32(v8))
  36997 					goto _36
  36998 				_36:
  36999 					highest_bit = v13
  37000 					second_highest_bit = v6 >> (highest_bit - int32(1)) & int32(1)
  37001 					**(**int32)(__ccgo_up(v24)) = highest_bit - int32(1)
  37002 					**(**int32)(__ccgo_up(v22)) = v6 & (int32(1)<<**(**int32)(__ccgo_up(v24)) - int32(1))
  37003 					**(**int32)(__ccgo_up(v20)) = int32(2)*highest_bit + second_highest_bit
  37004 				}
  37005 				WriteHuffmanCode(tls, bw1, codes+uintptr(4)*24, **(**int32)(__ccgo_up(bp + 32)))
  37006 				v20 = bw1
  37007 				v2 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 24)))
  37008 				v5 = **(**int32)(__ccgo_up(bp + 28))
  37009 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37010 					if v5 > libc.Int32FromInt32(0) {
  37011 						if (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused >= libc.Int32FromInt32(32) {
  37012 							VP8LPutBitsFlushBits(tls, v20)
  37013 						}
  37014 						**(**vp8l_atype_t)(__ccgo_up(v20)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v20)).Fused
  37015 						**(**int32)(__ccgo_up(v20 + 4)) += v5
  37016 					}
  37017 				} else {
  37018 					VP8LPutBitsInternal(tls, v20, v2, v5)
  37019 				}
  37020 			}
  37021 		}
  37022 		v2 = uint32((*PixOrCopy)(unsafe.Pointer(v)).Flen1)
  37023 		goto _41
  37024 	_41:
  37025 		x = libc.Int32FromUint32(uint32(x) + v2)
  37026 		for x >= width {
  37027 			x = x - width
  37028 			y = y + 1
  37029 		}
  37030 		v20 = bp
  37031 		v22 = v20
  37032 		*(*uintptr)(unsafe.Pointer(v22)) += 8
  37033 		v21 = *(*uintptr)(unsafe.Pointer(v22))
  37034 		if v21 == (*VP8LRefsCursor)(unsafe.Pointer(v20)).Flast_pos {
  37035 			VP8LRefsCursorNextBlock(tls, v20)
  37036 		}
  37037 	}
  37038 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37039 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37040 	}
  37041 	return int32(1)
  37042 }
  37043 
  37044 var order = [4]uint8_t{
  37045 	0: uint8(1),
  37046 	1: uint8(2),
  37047 	3: uint8(3),
  37048 }
  37049 
  37050 // C documentation
  37051 //
  37052 //	// Special case of EncodeImageInternal() for cache-bits=0, histo_bits=31.
  37053 //	// pic and percent are for progress.
  37054 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) {
  37055 	bp := tls.Alloc(128)
  37056 	defer tls.Free(128)
  37057 	var codes, codes1, histogram_image, huff_tree, refs, tokens, v1 uintptr
  37058 	var i, max_tokens, v3 int32
  37059 	var v2 uint32_t
  37060 	var _ /* cache_bits at bp+124 */ int32
  37061 	var _ /* histogram_symbols at bp+120 */ [1]uint32_t
  37062 	var _ /* huffman_codes at bp+0 */ [5]HuffmanTreeCode
  37063 	_, _, _, _, _, _, _, _, _, _, _ = codes, codes1, histogram_image, huff_tree, i, max_tokens, refs, tokens, v1, v2, v3
  37064 	max_tokens = 0
  37065 	tokens = libc.UintptrFromInt32(0)
  37066 	**(**[5]HuffmanTreeCode)(__ccgo_up(bp)) = [5]HuffmanTreeCode{}
  37067 	**(**[1]uint32_t)(__ccgo_up(bp + 120)) = [1]uint32_t{} // only one tree, one symbol
  37068 	**(**int32)(__ccgo_up(bp + 124)) = 0
  37069 	histogram_image = libc.UintptrFromInt32(0)
  37070 	huff_tree = WebPSafeMalloc(tls, uint64(libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES)), uint64(16))
  37071 	if huff_tree == libc.UintptrFromInt32(0) {
  37072 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37073 		goto Error
  37074 	}
  37075 	// Calculate backward references from ARGB image.
  37076 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range/int32(2), percent) != 0) {
  37077 		goto Error
  37078 	}
  37079 	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) {
  37080 		goto Error
  37081 	}
  37082 	refs = refs_array
  37083 	histogram_image = VP8LAllocateHistogramSet(tls, int32(1), **(**int32)(__ccgo_up(bp + 124)))
  37084 	if histogram_image == libc.UintptrFromInt32(0) {
  37085 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37086 		goto Error
  37087 	}
  37088 	VP8LHistogramSetClear(tls, histogram_image)
  37089 	// Build histogram image and symbols from backward references.
  37090 	VP8LHistogramStoreRefs(tls, refs, libc.UintptrFromInt32(0), 0, **(**uintptr)(__ccgo_up((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fhistograms)))
  37091 	// Create Huffman bit lengths and codes for each histogram image.
  37092 	if !(GetHuffBitLengthsAndCodes(tls, histogram_image, bp) != 0) {
  37093 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37094 		goto Error
  37095 	}
  37096 	// No color cache, no Huffman image.
  37097 	v1 = bw1
  37098 	v2 = uint32(0)
  37099 	v3 = int32(1)
  37100 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37101 		if v3 > libc.Int32FromInt32(0) {
  37102 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37103 				VP8LPutBitsFlushBits(tls, v1)
  37104 			}
  37105 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37106 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37107 		}
  37108 	} else {
  37109 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37110 	}
  37111 	// Find maximum number of symbols for the huffman tree-set.
  37112 	i = 0
  37113 	for {
  37114 		if !(i < int32(5)) {
  37115 			break
  37116 		}
  37117 		codes = bp + uintptr(i)*24
  37118 		if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37119 			max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37120 		}
  37121 		goto _4
  37122 	_4:
  37123 		;
  37124 		i = i + 1
  37125 	}
  37126 	tokens = WebPSafeMalloc(tls, libc.Uint64FromInt32(max_tokens), uint64(2))
  37127 	if tokens == libc.UintptrFromInt32(0) {
  37128 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37129 		goto Error
  37130 	}
  37131 	// Store Huffman codes.
  37132 	i = 0
  37133 	for {
  37134 		if !(i < int32(5)) {
  37135 			break
  37136 		}
  37137 		codes1 = bp + uintptr(i)*24
  37138 		StoreHuffmanCode(tls, bw1, huff_tree, tokens, codes1)
  37139 		ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37140 		goto _5
  37141 	_5:
  37142 		;
  37143 		i = i + 1
  37144 	}
  37145 	// Store actual literals.
  37146 	if !(StoreImageToBitMask(tls, bw1, width, 0, refs, bp+120, bp, pic) != 0) {
  37147 		goto Error
  37148 	}
  37149 	goto Error
  37150 Error:
  37151 	;
  37152 	WebPSafeFree(tls, tokens)
  37153 	WebPSafeFree(tls, huff_tree)
  37154 	VP8LFreeHistogramSet(tls, histogram_image)
  37155 	WebPSafeFree(tls, (**(**[5]HuffmanTreeCode)(__ccgo_up(bp)))[0].Fcodes)
  37156 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37157 }
  37158 
  37159 // C documentation
  37160 //
  37161 //	// pic and percent are for progress.
  37162 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) {
  37163 	bp := tls.Alloc(112)
  37164 	defer tls.Free(112)
  37165 	var bit_array_size, bw_size_best, v37, v40 size_t
  37166 	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
  37167 	var codes, codes1, histogram_argb, histogram_image, huff_tree, huffman_codes, sub_config, tmp_histo, tokens, v12, v15 uintptr
  37168 	var histogram_image_size, histogram_image_xysize, i, v1, v2, v4, v5 uint32_t
  37169 	var _ /* bw_best at bp+40 */ VP8LBitWriter
  37170 	var _ /* bw_init at bp+0 */ VP8LBitWriter
  37171 	var _ /* cache_bits_best at bp+96 */ int32
  37172 	var _ /* hash_chain_histogram at bp+80 */ VP8LHashChain
  37173 	var _ /* histogram_bits at bp+100 */ int32
  37174 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  37175 	v1 = libc.Uint32FromInt32(histogram_bits_in)
  37176 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37177 	goto _3
  37178 _3:
  37179 	v4 = libc.Uint32FromInt32(histogram_bits_in)
  37180 	v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37181 	goto _6
  37182 _6:
  37183 	histogram_image_xysize = v2 * v5
  37184 	remaining_percent = percent_range
  37185 	percent_start = **(**int32)(__ccgo_up(percent))
  37186 	histogram_image = libc.UintptrFromInt32(0)
  37187 	tmp_histo = libc.UintptrFromInt32(0)
  37188 	histogram_image_size = uint32(0)
  37189 	bit_array_size = uint64(0)
  37190 	huff_tree = WebPSafeMalloc(tls, uint64(libc.Uint64FromUint64(3)*libc.Uint64FromInt32(CODE_LENGTH_CODES)), uint64(16))
  37191 	tokens = libc.UintptrFromInt32(0)
  37192 	huffman_codes = libc.UintptrFromInt32(0)
  37193 	histogram_argb = WebPSafeMalloc(tls, uint64(histogram_image_xysize), uint64(4))
  37194 	**(**VP8LBitWriter)(__ccgo_up(bp)) = **(**VP8LBitWriter)(__ccgo_up(bw2)) // histogram image hash chain
  37195 	bw_size_best = ^libc.Uint64FromInt32(0)
  37196 	libc.Xmemset(tls, bp+80, 0, uint64(16))
  37197 	if !(VP8LBitWriterInit(tls, bp+40, uint64(0)) != 0) {
  37198 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37199 		goto Error
  37200 	}
  37201 	// Make sure we can allocate the different objects.
  37202 	if huff_tree == libc.UintptrFromInt32(0) || histogram_argb == libc.UintptrFromInt32(0) || !(VP8LHashChainInit(tls, bp+80, libc.Int32FromUint32(histogram_image_xysize)) != 0) {
  37203 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37204 		goto Error
  37205 	}
  37206 	percent_range = remaining_percent / int32(5)
  37207 	if !(VP8LHashChainFill(tls, hash_chain, quality, argb, width, height, low_effort, pic, percent_range, percent) != 0) {
  37208 		goto Error
  37209 	}
  37210 	percent_start = percent_start + percent_range
  37211 	remaining_percent = remaining_percent - percent_range
  37212 	// If the value is different from zero, it has been set during the palette
  37213 	// analysis.
  37214 	if **(**int32)(__ccgo_up(cache_bits)) == 0 {
  37215 		v7 = int32(MAX_COLOR_CACHE_BITS)
  37216 	} else {
  37217 		v7 = **(**int32)(__ccgo_up(cache_bits))
  37218 	}
  37219 	cache_bits_init = v7
  37220 	// If several iterations will happen, clone into bw_best.
  37221 	if ((*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size > int32(1) || (**(**CrunchSubConfig)(__ccgo_up(config + 8))).Fdo_no_cache != 0) && !(VP8LBitWriterClone(tls, bw2, bp+40) != 0) {
  37222 		WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37223 		goto Error
  37224 	}
  37225 	sub_configs_idx = 0
  37226 	for {
  37227 		if !(sub_configs_idx < (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size) {
  37228 			break
  37229 		}
  37230 		sub_config = config + 8 + uintptr(sub_configs_idx)*8
  37231 		i_remaining_percent = remaining_percent / (*CrunchConfig)(unsafe.Pointer(config)).Fsub_configs_size
  37232 		i_percent_range = i_remaining_percent / int32(4)
  37233 		i_remaining_percent = i_remaining_percent - i_percent_range
  37234 		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+96, pic, i_percent_range, percent) != 0) {
  37235 			goto Error
  37236 		}
  37237 		i_cache = 0
  37238 		for {
  37239 			if (*CrunchSubConfig)(unsafe.Pointer(sub_config)).Fdo_no_cache != 0 {
  37240 				v7 = int32(2)
  37241 			} else {
  37242 				v7 = int32(1)
  37243 			}
  37244 			if !(i_cache < v7) {
  37245 				break
  37246 			}
  37247 			if i_cache == 0 {
  37248 				v10 = **(**int32)(__ccgo_up(bp + 96))
  37249 			} else {
  37250 				v10 = 0
  37251 			}
  37252 			cache_bits_tmp = v10
  37253 			**(**int32)(__ccgo_up(bp + 100)) = histogram_bits_in
  37254 			// Speed-up: no need to study the no-cache case if it was already studied
  37255 			// in i_cache == 0.
  37256 			if i_cache == int32(1) && **(**int32)(__ccgo_up(bp + 96)) == 0 {
  37257 				break
  37258 			}
  37259 			// Reset the bit writer for this iteration.
  37260 			VP8LBitWriterReset(tls, bp, bw2)
  37261 			// Build histogram image and symbols from backward references.
  37262 			histogram_image = VP8LAllocateHistogramSet(tls, libc.Int32FromUint32(histogram_image_xysize), cache_bits_tmp)
  37263 			tmp_histo = VP8LAllocateHistogram(tls, cache_bits_tmp)
  37264 			if histogram_image == libc.UintptrFromInt32(0) || tmp_histo == libc.UintptrFromInt32(0) {
  37265 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37266 				goto Error
  37267 			}
  37268 			i_percent_range = i_remaining_percent / int32(3)
  37269 			i_remaining_percent = i_remaining_percent - i_percent_range
  37270 			if !(VP8LGetHistoImageSymbols(tls, width, height, refs_array+uintptr(i_cache)*40, quality, low_effort, **(**int32)(__ccgo_up(bp + 100)), cache_bits_tmp, histogram_image, tmp_histo, histogram_argb, pic, i_percent_range, percent) != 0) {
  37271 				goto Error
  37272 			}
  37273 			// Create Huffman bit lengths and codes for each histogram image.
  37274 			histogram_image_size = libc.Uint32FromInt32((*VP8LHistogramSet)(unsafe.Pointer(histogram_image)).Fsize)
  37275 			bit_array_size = uint64(uint32(5) * histogram_image_size)
  37276 			huffman_codes = WebPSafeCalloc(tls, bit_array_size, uint64(24))
  37277 			// Note: some histogram_image entries may point to tmp_histos[], so the
  37278 			// latter need to outlive the following call to
  37279 			// GetHuffBitLengthsAndCodes().
  37280 			if huffman_codes == libc.UintptrFromInt32(0) || !(GetHuffBitLengthsAndCodes(tls, histogram_image, huffman_codes) != 0) {
  37281 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37282 				goto Error
  37283 			}
  37284 			// Free combined histograms.
  37285 			VP8LFreeHistogramSet(tls, histogram_image)
  37286 			histogram_image = libc.UintptrFromInt32(0)
  37287 			// Free scratch histograms.
  37288 			VP8LFreeHistogram(tls, tmp_histo)
  37289 			tmp_histo = libc.UintptrFromInt32(0)
  37290 			// Color Cache parameters.
  37291 			if cache_bits_tmp > 0 {
  37292 				v12 = bw2
  37293 				v1 = uint32(1)
  37294 				v7 = int32(1)
  37295 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37296 					if v7 > libc.Int32FromInt32(0) {
  37297 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37298 							VP8LPutBitsFlushBits(tls, v12)
  37299 						}
  37300 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= v1 << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37301 						**(**int32)(__ccgo_up(v12 + 4)) += v7
  37302 					}
  37303 				} else {
  37304 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37305 				}
  37306 				v12 = bw2
  37307 				v1 = libc.Uint32FromInt32(cache_bits_tmp)
  37308 				v7 = int32(4)
  37309 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37310 					if v7 > libc.Int32FromInt32(0) {
  37311 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37312 							VP8LPutBitsFlushBits(tls, v12)
  37313 						}
  37314 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= v1 << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37315 						**(**int32)(__ccgo_up(v12 + 4)) += v7
  37316 					}
  37317 				} else {
  37318 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37319 				}
  37320 			} else {
  37321 				v12 = bw2
  37322 				v1 = uint32(0)
  37323 				v7 = int32(1)
  37324 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37325 					if v7 > libc.Int32FromInt32(0) {
  37326 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37327 							VP8LPutBitsFlushBits(tls, v12)
  37328 						}
  37329 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= v1 << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37330 						**(**int32)(__ccgo_up(v12 + 4)) += v7
  37331 					}
  37332 				} else {
  37333 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37334 				}
  37335 			}
  37336 			// Huffman image + meta huffman.
  37337 			histogram_image_size = uint32(0)
  37338 			i = uint32(0)
  37339 			for {
  37340 				if !(i < histogram_image_xysize) {
  37341 					break
  37342 				}
  37343 				if **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) >= histogram_image_size {
  37344 					histogram_image_size = **(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) + uint32(1)
  37345 				}
  37346 				**(**uint32_t)(__ccgo_up(histogram_argb + uintptr(i)*4)) <<= uint32(8)
  37347 				goto _21
  37348 			_21:
  37349 				;
  37350 				i = i + 1
  37351 			}
  37352 			write_histogram_image = libc.BoolInt32(histogram_image_size > uint32(1))
  37353 			v12 = bw2
  37354 			v1 = libc.Uint32FromInt32(write_histogram_image)
  37355 			v7 = int32(1)
  37356 			if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37357 				if v7 > libc.Int32FromInt32(0) {
  37358 					if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37359 						VP8LPutBitsFlushBits(tls, v12)
  37360 					}
  37361 					**(**vp8l_atype_t)(__ccgo_up(v12)) |= v1 << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37362 					**(**int32)(__ccgo_up(v12 + 4)) += v7
  37363 				}
  37364 			} else {
  37365 				VP8LPutBitsInternal(tls, v12, v1, v7)
  37366 			}
  37367 			if write_histogram_image != 0 {
  37368 				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+100)
  37369 				v12 = bw2
  37370 				v1 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 100)) - int32(2))
  37371 				v7 = int32(3)
  37372 				if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37373 					if v7 > libc.Int32FromInt32(0) {
  37374 						if (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused >= libc.Int32FromInt32(32) {
  37375 							VP8LPutBitsFlushBits(tls, v12)
  37376 						}
  37377 						**(**vp8l_atype_t)(__ccgo_up(v12)) |= v1 << (*VP8LBitWriter)(unsafe.Pointer(v12)).Fused
  37378 						**(**int32)(__ccgo_up(v12 + 4)) += v7
  37379 					}
  37380 				} else {
  37381 					VP8LPutBitsInternal(tls, v12, v1, v7)
  37382 				}
  37383 				i_percent_range = i_remaining_percent / int32(2)
  37384 				i_remaining_percent = i_remaining_percent - i_percent_range
  37385 				v1 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 100)))
  37386 				v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  37387 				goto _30
  37388 			_30:
  37389 				v4 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 100)))
  37390 				v5 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37391 				goto _33
  37392 			_33:
  37393 				if !(EncodeImageNoHuffman(tls, bw2, histogram_argb, bp+80, refs_array+2*40, libc.Int32FromUint32(v2), libc.Int32FromUint32(v5), quality, low_effort, pic, i_percent_range, percent) != 0) {
  37394 					goto Error
  37395 				}
  37396 			}
  37397 			// Store Huffman codes.
  37398 			max_tokens = 0
  37399 			// Find maximum number of symbols for the huffman tree-set.
  37400 			i = uint32(0)
  37401 			for {
  37402 				if !(i < uint32(5)*histogram_image_size) {
  37403 					break
  37404 				}
  37405 				codes = huffman_codes + uintptr(i)*24
  37406 				if max_tokens < (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols {
  37407 					max_tokens = (*HuffmanTreeCode)(unsafe.Pointer(codes)).Fnum_symbols
  37408 				}
  37409 				goto _34
  37410 			_34:
  37411 				;
  37412 				i = i + 1
  37413 			}
  37414 			tokens = WebPSafeMalloc(tls, libc.Uint64FromInt32(max_tokens), uint64(2))
  37415 			if tokens == libc.UintptrFromInt32(0) {
  37416 				WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37417 				goto Error
  37418 			}
  37419 			i = uint32(0)
  37420 			for {
  37421 				if !(i < uint32(5)*histogram_image_size) {
  37422 					break
  37423 				}
  37424 				codes1 = huffman_codes + uintptr(i)*24
  37425 				StoreHuffmanCode(tls, bw2, huff_tree, tokens, codes1)
  37426 				ClearHuffmanTreeIfOnlyOneSymbol(tls, codes1)
  37427 				goto _35
  37428 			_35:
  37429 				;
  37430 				i = i + 1
  37431 			}
  37432 			// Store actual literals.
  37433 			v12 = bw2
  37434 			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)))
  37435 			goto _38
  37436 		_38:
  37437 			hdr_size_tmp = libc.Int32FromUint64(v37 - init_byte_position)
  37438 			if !(StoreImageToBitMask(tls, bw2, width, **(**int32)(__ccgo_up(bp + 100)), refs_array+uintptr(i_cache)*40, histogram_argb, huffman_codes, pic) != 0) {
  37439 				goto Error
  37440 			}
  37441 			// Keep track of the smallest image so far.
  37442 			v12 = bw2
  37443 			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)))
  37444 			goto _41
  37445 		_41:
  37446 			if v37 < bw_size_best {
  37447 				v15 = bw2
  37448 				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)))
  37449 				goto _44
  37450 			_44:
  37451 				bw_size_best = v40
  37452 				**(**int32)(__ccgo_up(cache_bits)) = cache_bits_tmp
  37453 				**(**int32)(__ccgo_up(hdr_size)) = hdr_size_tmp
  37454 				v12 = bw2
  37455 				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)))
  37456 				goto _47
  37457 			_47:
  37458 				**(**int32)(__ccgo_up(data_size)) = libc.Int32FromUint64(v37 - init_byte_position - libc.Uint64FromInt32(**(**int32)(__ccgo_up(hdr_size))))
  37459 				VP8LBitWriterSwap(tls, bw2, bp+40)
  37460 			}
  37461 			WebPSafeFree(tls, tokens)
  37462 			tokens = libc.UintptrFromInt32(0)
  37463 			if huffman_codes != libc.UintptrFromInt32(0) {
  37464 				WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37465 				WebPSafeFree(tls, huffman_codes)
  37466 				huffman_codes = libc.UintptrFromInt32(0)
  37467 			}
  37468 			goto _9
  37469 		_9:
  37470 			;
  37471 			i_cache = i_cache + 1
  37472 		}
  37473 		goto _8
  37474 	_8:
  37475 		;
  37476 		sub_configs_idx = sub_configs_idx + 1
  37477 	}
  37478 	VP8LBitWriterSwap(tls, bw2, bp+40)
  37479 	if !(WebPReportProgress(tls, pic, percent_start+remaining_percent, percent) != 0) {
  37480 		goto Error
  37481 	}
  37482 	goto Error
  37483 Error:
  37484 	;
  37485 	WebPSafeFree(tls, tokens)
  37486 	WebPSafeFree(tls, huff_tree)
  37487 	VP8LFreeHistogramSet(tls, histogram_image)
  37488 	VP8LFreeHistogram(tls, tmp_histo)
  37489 	VP8LHashChainClear(tls, bp+80)
  37490 	if huffman_codes != libc.UintptrFromInt32(0) {
  37491 		WebPSafeFree(tls, (*HuffmanTreeCode)(unsafe.Pointer(huffman_codes)).Fcodes)
  37492 		WebPSafeFree(tls, huffman_codes)
  37493 	}
  37494 	WebPSafeFree(tls, histogram_argb)
  37495 	VP8LBitWriterWipeOut(tls, bp+40)
  37496 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK))
  37497 }
  37498 
  37499 // -----------------------------------------------------------------------------
  37500 // Transforms
  37501 
  37502 func ApplySubtractGreen(tls *libc.TLS, enc uintptr, width int32, height int32, bw1 uintptr) {
  37503 	var v1 uintptr
  37504 	var v2 uint32_t
  37505 	var v3 int32
  37506 	_, _, _ = v1, v2, v3
  37507 	v1 = bw1
  37508 	v2 = uint32(TRANSFORM_PRESENT)
  37509 	v3 = int32(1)
  37510 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37511 		if v3 > libc.Int32FromInt32(0) {
  37512 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37513 				VP8LPutBitsFlushBits(tls, v1)
  37514 			}
  37515 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37516 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37517 		}
  37518 	} else {
  37519 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37520 	}
  37521 	v1 = bw1
  37522 	v2 = uint32(SUBTRACT_GREEN_TRANSFORM)
  37523 	v3 = int32(2)
  37524 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37525 		if v3 > libc.Int32FromInt32(0) {
  37526 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37527 				VP8LPutBitsFlushBits(tls, v1)
  37528 			}
  37529 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37530 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37531 		}
  37532 	} else {
  37533 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37534 	}
  37535 	(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LSubtractGreenFromBlueAndRed})))(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb, width*height)
  37536 }
  37537 
  37538 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) {
  37539 	var max_bits, min_bits, near_lossless_strength, v1, v2 int32
  37540 	var v10, v12, v4, v7 uint32_t
  37541 	var v3 uintptr
  37542 	_, _, _, _, _, _, _, _, _, _ = max_bits, min_bits, near_lossless_strength, v1, v10, v12, v2, v3, v4, v7
  37543 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  37544 		v1 = int32(100)
  37545 	} else {
  37546 		v1 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fnear_lossless
  37547 	}
  37548 	near_lossless_strength = v1
  37549 	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))
  37550 	if (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod > int32(4) {
  37551 		v2 = (*WebPConfig)(unsafe.Pointer((*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig)).Fmethod - int32(4)
  37552 	} else {
  37553 		v2 = 0
  37554 	}
  37555 	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))
  37556 	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) {
  37557 		return 0
  37558 	}
  37559 	v3 = bw1
  37560 	v4 = uint32(TRANSFORM_PRESENT)
  37561 	v1 = int32(1)
  37562 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37563 		if v1 > libc.Int32FromInt32(0) {
  37564 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37565 				VP8LPutBitsFlushBits(tls, v3)
  37566 			}
  37567 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= v4 << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37568 			**(**int32)(__ccgo_up(v3 + 4)) += v1
  37569 		}
  37570 	} else {
  37571 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37572 	}
  37573 	v3 = bw1
  37574 	v4 = uint32(PREDICTOR_TRANSFORM)
  37575 	v1 = int32(2)
  37576 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37577 		if v1 > libc.Int32FromInt32(0) {
  37578 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37579 				VP8LPutBitsFlushBits(tls, v3)
  37580 			}
  37581 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= v4 << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37582 			**(**int32)(__ccgo_up(v3 + 4)) += v1
  37583 		}
  37584 	} else {
  37585 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37586 	}
  37587 	v3 = bw1
  37588 	v4 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37589 	v1 = int32(NUM_TRANSFORM_BITS)
  37590 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37591 		if v1 > libc.Int32FromInt32(0) {
  37592 			if (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused >= libc.Int32FromInt32(32) {
  37593 				VP8LPutBitsFlushBits(tls, v3)
  37594 			}
  37595 			**(**vp8l_atype_t)(__ccgo_up(v3)) |= v4 << (*VP8LBitWriter)(unsafe.Pointer(v3)).Fused
  37596 			**(**int32)(__ccgo_up(v3 + 4)) += v1
  37597 		}
  37598 	} else {
  37599 		VP8LPutBitsInternal(tls, v3, v4, v1)
  37600 	}
  37601 	v4 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37602 	v7 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v4) - uint32(1)) >> v4
  37603 	goto _14
  37604 _14:
  37605 	v10 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37606 	v12 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v10) - uint32(1)) >> v10
  37607 	goto _17
  37608 _17:
  37609 	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)
  37610 }
  37611 
  37612 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) {
  37613 	var min_bits, v3 int32
  37614 	var v1 uintptr
  37615 	var v10, v2, v5, v8 uint32_t
  37616 	_, _, _, _, _, _, _ = min_bits, v1, v10, v2, v3, v5, v8
  37617 	min_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcross_color_transform_bits
  37618 	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) {
  37619 		return 0
  37620 	}
  37621 	v1 = bw1
  37622 	v2 = uint32(TRANSFORM_PRESENT)
  37623 	v3 = int32(1)
  37624 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37625 		if v3 > libc.Int32FromInt32(0) {
  37626 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37627 				VP8LPutBitsFlushBits(tls, v1)
  37628 			}
  37629 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37630 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37631 		}
  37632 	} else {
  37633 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37634 	}
  37635 	v1 = bw1
  37636 	v2 = uint32(CROSS_COLOR_TRANSFORM)
  37637 	v3 = int32(2)
  37638 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37639 		if v3 > libc.Int32FromInt32(0) {
  37640 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37641 				VP8LPutBitsFlushBits(tls, v1)
  37642 			}
  37643 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37644 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37645 		}
  37646 	} else {
  37647 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37648 	}
  37649 	v1 = bw1
  37650 	v2 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)) - int32(MIN_TRANSFORM_BITS))
  37651 	v3 = int32(NUM_TRANSFORM_BITS)
  37652 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37653 		if v3 > libc.Int32FromInt32(0) {
  37654 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37655 				VP8LPutBitsFlushBits(tls, v1)
  37656 			}
  37657 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37658 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37659 		}
  37660 	} else {
  37661 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37662 	}
  37663 	v2 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37664 	v5 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v2) - uint32(1)) >> v2
  37665 	goto _12
  37666 _12:
  37667 	v8 = libc.Uint32FromInt32(**(**int32)(__ccgo_up(best_bits)))
  37668 	v10 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v8) - uint32(1)) >> v8
  37669 	goto _15
  37670 _15:
  37671 	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)
  37672 }
  37673 
  37674 // -----------------------------------------------------------------------------
  37675 
  37676 func WriteRiffHeader(tls *libc.TLS, pic uintptr, riff_size size_t, vp8l_size size_t) (r int32) {
  37677 	bp := tls.Alloc(32)
  37678 	defer tls.Free(32)
  37679 	var v1, v3, v5 uintptr
  37680 	var v4, v6 int32
  37681 	var v2 uint32_t
  37682 	var _ /* riff at bp+0 */ [21]uint8_t
  37683 	_, _, _, _, _, _ = v1, v2, v3, v4, v5, v6
  37684 	**(**[21]uint8_t)(__ccgo_up(bp)) = [21]uint8_t{
  37685 		0:  uint8('R'),
  37686 		1:  uint8('I'),
  37687 		2:  uint8('F'),
  37688 		3:  uint8('F'),
  37689 		8:  uint8('W'),
  37690 		9:  uint8('E'),
  37691 		10: uint8('B'),
  37692 		11: uint8('P'),
  37693 		12: uint8('V'),
  37694 		13: uint8('P'),
  37695 		14: uint8('8'),
  37696 		15: uint8('L'),
  37697 		20: uint8(VP8L_MAGIC_BYTE3),
  37698 	}
  37699 	v1 = bp + uintptr(TAG_SIZE)
  37700 	v2 = uint32(riff_size)
  37701 	v3 = v1
  37702 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  37703 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  37704 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  37705 	v5 = v1 + uintptr(2)
  37706 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  37707 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  37708 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  37709 	v1 = bp + uintptr(RIFF_HEADER_SIZE) + uintptr(TAG_SIZE)
  37710 	v2 = uint32(vp8l_size)
  37711 	v3 = v1
  37712 	v4 = libc.Int32FromUint32(v2 & libc.Uint32FromInt32(0xffff))
  37713 	**(**uint8_t)(__ccgo_up(v3)) = libc.Uint8FromInt32(v4 >> 0 & int32(0xff))
  37714 	**(**uint8_t)(__ccgo_up(v3 + 1)) = libc.Uint8FromInt32(v4 >> int32(8) & int32(0xff))
  37715 	v5 = v1 + uintptr(2)
  37716 	v6 = libc.Int32FromUint32(v2 >> libc.Int32FromInt32(16))
  37717 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6 >> 0 & int32(0xff))
  37718 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v6 >> int32(8) & int32(0xff))
  37719 	return (*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(21), pic)
  37720 }
  37721 
  37722 func WriteImageSize(tls *libc.TLS, pic uintptr, bw1 uintptr) (r int32) {
  37723 	var height, width, v3 int32
  37724 	var v1 uintptr
  37725 	var v2 uint32_t
  37726 	_, _, _, _, _ = height, width, v1, v2, v3
  37727 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth - int32(1)
  37728 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight - int32(1)
  37729 	v1 = bw1
  37730 	v2 = libc.Uint32FromInt32(width)
  37731 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37732 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37733 		if v3 > libc.Int32FromInt32(0) {
  37734 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37735 				VP8LPutBitsFlushBits(tls, v1)
  37736 			}
  37737 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37738 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37739 		}
  37740 	} else {
  37741 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37742 	}
  37743 	v1 = bw1
  37744 	v2 = libc.Uint32FromInt32(height)
  37745 	v3 = int32(VP8L_IMAGE_SIZE_BITS)
  37746 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37747 		if v3 > libc.Int32FromInt32(0) {
  37748 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37749 				VP8LPutBitsFlushBits(tls, v1)
  37750 			}
  37751 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37752 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37753 		}
  37754 	} else {
  37755 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37756 	}
  37757 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37758 }
  37759 
  37760 func WriteRealAlphaAndVersion(tls *libc.TLS, bw1 uintptr, has_alpha int32) (r int32) {
  37761 	var v1 uintptr
  37762 	var v2 uint32_t
  37763 	var v3 int32
  37764 	_, _, _ = v1, v2, v3
  37765 	v1 = bw1
  37766 	v2 = libc.Uint32FromInt32(has_alpha)
  37767 	v3 = int32(1)
  37768 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37769 		if v3 > libc.Int32FromInt32(0) {
  37770 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37771 				VP8LPutBitsFlushBits(tls, v1)
  37772 			}
  37773 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37774 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37775 		}
  37776 	} else {
  37777 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37778 	}
  37779 	v1 = bw1
  37780 	v2 = uint32(VP8L_VERSION)
  37781 	v3 = int32(VP8L_VERSION_BITS)
  37782 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  37783 		if v3 > libc.Int32FromInt32(0) {
  37784 			if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  37785 				VP8LPutBitsFlushBits(tls, v1)
  37786 			}
  37787 			**(**vp8l_atype_t)(__ccgo_up(v1)) |= v2 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  37788 			**(**int32)(__ccgo_up(v1 + 4)) += v3
  37789 		}
  37790 	} else {
  37791 		VP8LPutBitsInternal(tls, v1, v2, v3)
  37792 	}
  37793 	return libc.BoolInt32(!((*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0))
  37794 }
  37795 
  37796 func WriteImage(tls *libc.TLS, pic uintptr, bw1 uintptr, coded_size uintptr) (r int32) {
  37797 	bp := tls.Alloc(16)
  37798 	defer tls.Free(16)
  37799 	var pad, riff_size, vp8l_size, webpll_size, v2 size_t
  37800 	var webpll_data, v1 uintptr
  37801 	var _ /* pad_byte at bp+0 */ [1]uint8_t
  37802 	_, _, _, _, _, _, _ = pad, riff_size, vp8l_size, webpll_data, webpll_size, v1, v2
  37803 	webpll_data = VP8LBitWriterFinish(tls, bw1)
  37804 	v1 = bw1
  37805 	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)))
  37806 	goto _3
  37807 _3:
  37808 	webpll_size = v2
  37809 	vp8l_size = uint64(VP8L_SIGNATURE_SIZE) + webpll_size
  37810 	pad = vp8l_size & uint64(1)
  37811 	riff_size = libc.Uint64FromInt32(libc.Int32FromInt32(TAG_SIZE)+libc.Int32FromInt32(CHUNK_HEADER_SIZE)) + vp8l_size + pad
  37812 	**(**size_t)(__ccgo_up(coded_size)) = uint64(0)
  37813 	if (*VP8LBitWriter)(unsafe.Pointer(bw1)).Ferror1 != 0 {
  37814 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37815 	}
  37816 	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) {
  37817 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37818 	}
  37819 	if pad != 0 {
  37820 		**(**[1]uint8_t)(__ccgo_up(bp)) = [1]uint8_t{}
  37821 		if !((*(*func(*libc.TLS, uintptr, size_t, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPPicture)(unsafe.Pointer(pic)).Fwriter})))(tls, bp, uint64(1), pic) != 0) {
  37822 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_WRITE))
  37823 		}
  37824 	}
  37825 	**(**size_t)(__ccgo_up(coded_size)) = uint64(CHUNK_HEADER_SIZE) + riff_size
  37826 	return int32(1)
  37827 }
  37828 
  37829 // -----------------------------------------------------------------------------
  37830 
  37831 func ClearTransformBuffer(tls *libc.TLS, enc uintptr) {
  37832 	WebPSafeFree(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem)
  37833 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = libc.UintptrFromInt32(0)
  37834 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = uint64(0)
  37835 }
  37836 
  37837 // C documentation
  37838 //
  37839 //	// Allocates the memory for argb (W x H) buffer, 2 rows of context for
  37840 //	// prediction and transform data.
  37841 //	// Flags influencing the memory allocated:
  37842 //	//  enc->transform_bits
  37843 //	//  enc->use_predict, enc->use_cross_color
  37844 func AllocateTransformBuffer(tls *libc.TLS, enc uintptr, width int32, height int32) (r int32) {
  37845 	var argb_scratch_size, image_size, max_alignment_in_words, mem_size, transform_data_size uint64_t
  37846 	var mem uintptr
  37847 	var v1, v2 uint64
  37848 	var v3, v4, v6, v7 uint32_t
  37849 	_, _, _, _, _, _, _, _, _, _, _, _ = argb_scratch_size, image_size, max_alignment_in_words, mem, mem_size, transform_data_size, v1, v2, v3, v4, v6, v7
  37850 	image_size = libc.Uint64FromInt32(width) * libc.Uint64FromInt32(height)
  37851 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  37852 		v1 = libc.Uint64FromInt32((width+int32(1))*int32(2)) + (libc.Uint64FromInt32(width*int32(2))+uint64(4)-uint64(1))/uint64(4)
  37853 	} else {
  37854 		v1 = uint64(0)
  37855 	}
  37856 	// VP8LResidualImage needs room for 2 scanlines of uint32 pixels with an extra
  37857 	// pixel in each, plus 2 regular scanlines of bytes.
  37858 	// TODO(skal): Clean up by using arithmetic in bytes instead of words.
  37859 	argb_scratch_size = v1
  37860 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  37861 		v3 = uint32(MIN_TRANSFORM_BITS)
  37862 		v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  37863 		goto _5
  37864 	_5:
  37865 		v6 = uint32(MIN_TRANSFORM_BITS)
  37866 		v7 = (libc.Uint32FromInt32(height) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v6) - uint32(1)) >> v6
  37867 		goto _8
  37868 	_8:
  37869 		v2 = uint64(v4) * uint64(v7)
  37870 	} else {
  37871 		v2 = uint64(0)
  37872 	}
  37873 	transform_data_size = v2
  37874 	max_alignment_in_words = (libc.Uint64FromInt32(WEBP_ALIGN_CST) + libc.Uint64FromInt64(4) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt64(4)
  37875 	mem_size = image_size + max_alignment_in_words + argb_scratch_size + max_alignment_in_words + transform_data_size
  37876 	mem = (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem
  37877 	if mem == libc.UintptrFromInt32(0) || mem_size > (*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size {
  37878 		ClearTransformBuffer(tls, enc)
  37879 		mem = WebPSafeMalloc(tls, mem_size, uint64(4))
  37880 		if mem == libc.UintptrFromInt32(0) {
  37881 			return WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37882 		}
  37883 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem = mem
  37884 		(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_mem_size = mem_size
  37885 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  37886 	}
  37887 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb = mem
  37888 	mem = uintptr((uint64(mem+uintptr(image_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37889 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_scratch = mem
  37890 	mem = uintptr((uint64(mem+uintptr(argb_scratch_size)*4) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  37891 	(*VP8LEncoder)(unsafe.Pointer(enc)).Ftransform_data = mem
  37892 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width = width
  37893 	return int32(1)
  37894 }
  37895 
  37896 func MakeInputImageCopy(tls *libc.TLS, enc uintptr) (r int32) {
  37897 	var dst, picture, src uintptr
  37898 	var height, width, y int32
  37899 	_, _, _, _, _, _ = dst, height, picture, src, width, y
  37900 	picture = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  37901 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  37902 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  37903 	if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  37904 		return 0
  37905 	}
  37906 	if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content == int32(kEncoderARGB) {
  37907 		return int32(1)
  37908 	}
  37909 	dst = (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb
  37910 	src = (*WebPPicture)(unsafe.Pointer(picture)).Fargb
  37911 	y = 0
  37912 	for {
  37913 		if !(y < height) {
  37914 			break
  37915 		}
  37916 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(width)*uint64(4))
  37917 		dst = dst + uintptr(width)*4
  37918 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(picture)).Fargb_stride)*4
  37919 		goto _1
  37920 	_1:
  37921 		;
  37922 		y = y + 1
  37923 	}
  37924 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderARGB)
  37925 	return int32(1)
  37926 }
  37927 
  37928 // -----------------------------------------------------------------------------
  37929 
  37930 func SearchColorGreedy(tls *libc.TLS, palette uintptr, palette_size int32, color uint32_t) (r uint32_t) {
  37931 	_ = palette_size
  37932 	if color == **(**uint32_t)(__ccgo_up(palette)) {
  37933 		return uint32(0)
  37934 	}
  37935 	if color == **(**uint32_t)(__ccgo_up(palette + 1*4)) {
  37936 		return uint32(1)
  37937 	}
  37938 	if color == **(**uint32_t)(__ccgo_up(palette + 2*4)) {
  37939 		return uint32(2)
  37940 	}
  37941 	return uint32(3)
  37942 }
  37943 
  37944 func ApplyPaletteHash0(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37945 	// Focus on the green color.
  37946 	return color >> libc.Int32FromInt32(8) & uint32(0xff)
  37947 }
  37948 
  37949 func ApplyPaletteHash1(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37950 	// Forget about alpha.
  37951 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*libc.Uint64FromUint64(4222244071)) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37952 }
  37953 
  37954 func ApplyPaletteHash2(tls *libc.TLS, color uint32_t) (r uint32_t) {
  37955 	// Forget about alpha.
  37956 	return uint32(uint64(color&libc.Uint32FromUint32(0x00ffffff))*(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(31)-libc.Uint64FromInt32(1))) >> (libc.Int32FromInt32(32) - libc.Int32FromInt32(11))
  37957 }
  37958 
  37959 // Use 1 pixel cache for ARGB pixels.
  37960 
  37961 // C documentation
  37962 //
  37963 //	// Remap argb values in src[] to packed palettes entries in dst[]
  37964 //	// using 'row' as a temporary buffer of size 'width'.
  37965 //	// We assume that all src[] values have a corresponding entry in the palette.
  37966 //	// Note: src[] can be the same as dst[]
  37967 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) {
  37968 	bp := tls.Alloc(6144)
  37969 	defer tls.Free(6144)
  37970 	var hash_functions [3]uintptr
  37971 	var i, j, use_LUT, x, y int32
  37972 	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
  37973 	var tmp_row uintptr
  37974 	var _ /* buffer at bp+0 */ [2048]uint16_t
  37975 	var _ /* idx_map at bp+4096 */ [256]uint32_t
  37976 	var _ /* palette_sorted at bp+5120 */ [256]uint32_t
  37977 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  37978 	// TODO(skal): this tmp buffer is not needed if VP8LBundleColorMap() can be
  37979 	// made to work in-place.
  37980 	tmp_row = WebPSafeMalloc(tls, libc.Uint64FromInt32(width), uint64(1))
  37981 	if tmp_row == libc.UintptrFromInt32(0) {
  37982 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  37983 	}
  37984 	if palette_size < int32(4) {
  37985 		prev_pix = **(**uint32_t)(__ccgo_up(palette))
  37986 		prev_idx = uint32(0)
  37987 		y = 0
  37988 		for {
  37989 			if !(y < height) {
  37990 				break
  37991 			}
  37992 			x = 0
  37993 			for {
  37994 				if !(x < width) {
  37995 					break
  37996 				}
  37997 				pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  37998 				if pix != prev_pix {
  37999 					prev_idx = SearchColorGreedy(tls, palette, palette_size, pix)
  38000 					prev_pix = pix
  38001 				}
  38002 				**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx)
  38003 				goto _2
  38004 			_2:
  38005 				;
  38006 				x = x + 1
  38007 			}
  38008 			(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38009 			src = src + uintptr(src_stride)*4
  38010 			dst = dst + uintptr(dst_stride)*4
  38011 			goto _1
  38012 		_1:
  38013 			;
  38014 			y = y + 1
  38015 		}
  38016 	} else {
  38017 		hash_functions = [3]uintptr{
  38018 			0: __ccgo_fp(ApplyPaletteHash0),
  38019 			1: __ccgo_fp(ApplyPaletteHash1),
  38020 			2: __ccgo_fp(ApplyPaletteHash2),
  38021 		}
  38022 		// Try to find a perfect hash function able to go from a color to an index
  38023 		// within 1 << PALETTE_INV_SIZE_BITS in order to build a hash map to go
  38024 		// from color to index in palette.
  38025 		i = 0
  38026 		for {
  38027 			if !(i < int32(3)) {
  38028 				break
  38029 			}
  38030 			use_LUT = int32(1)
  38031 			// Set each element in buffer to max uint16_t.
  38032 			libc.Xmemset(tls, bp, int32(0xff), uint64(4096))
  38033 			j = 0
  38034 			for {
  38035 				if !(j < palette_size) {
  38036 					break
  38037 				}
  38038 				ind = (*(*func(*libc.TLS, uint32_t) uint32_t)(unsafe.Pointer(&struct{ uintptr }{hash_functions[i]})))(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(j)*4)))
  38039 				if uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ind]) != uint32(0xffff) {
  38040 					use_LUT = 0
  38041 					break
  38042 				} else {
  38043 					(**(**[2048]uint16_t)(__ccgo_up(bp)))[ind] = libc.Uint16FromInt32(j)
  38044 				}
  38045 				goto _4
  38046 			_4:
  38047 				;
  38048 				j = j + 1
  38049 			}
  38050 			if use_LUT != 0 {
  38051 				break
  38052 			}
  38053 			goto _3
  38054 		_3:
  38055 			;
  38056 			i = i + 1
  38057 		}
  38058 		if i == 0 {
  38059 			prev_pix1 = **(**uint32_t)(__ccgo_up(palette))
  38060 			prev_idx1 = uint32(0)
  38061 			y = 0
  38062 			for {
  38063 				if !(y < height) {
  38064 					break
  38065 				}
  38066 				x = 0
  38067 				for {
  38068 					if !(x < width) {
  38069 						break
  38070 					}
  38071 					pix1 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38072 					if pix1 != prev_pix1 {
  38073 						prev_idx1 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash0(tls, pix1)])
  38074 						prev_pix1 = pix1
  38075 					}
  38076 					**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx1)
  38077 					goto _6
  38078 				_6:
  38079 					;
  38080 					x = x + 1
  38081 				}
  38082 				(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38083 				src = src + uintptr(src_stride)*4
  38084 				dst = dst + uintptr(dst_stride)*4
  38085 				goto _5
  38086 			_5:
  38087 				;
  38088 				y = y + 1
  38089 			}
  38090 		} else {
  38091 			if i == int32(1) {
  38092 				prev_pix2 = **(**uint32_t)(__ccgo_up(palette))
  38093 				prev_idx2 = uint32(0)
  38094 				y = 0
  38095 				for {
  38096 					if !(y < height) {
  38097 						break
  38098 					}
  38099 					x = 0
  38100 					for {
  38101 						if !(x < width) {
  38102 							break
  38103 						}
  38104 						pix2 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38105 						if pix2 != prev_pix2 {
  38106 							prev_idx2 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash1(tls, pix2)])
  38107 							prev_pix2 = pix2
  38108 						}
  38109 						**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx2)
  38110 						goto _8
  38111 					_8:
  38112 						;
  38113 						x = x + 1
  38114 					}
  38115 					(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38116 					src = src + uintptr(src_stride)*4
  38117 					dst = dst + uintptr(dst_stride)*4
  38118 					goto _7
  38119 				_7:
  38120 					;
  38121 					y = y + 1
  38122 				}
  38123 			} else {
  38124 				if i == int32(2) {
  38125 					prev_pix3 = **(**uint32_t)(__ccgo_up(palette))
  38126 					prev_idx3 = uint32(0)
  38127 					y = 0
  38128 					for {
  38129 						if !(y < height) {
  38130 							break
  38131 						}
  38132 						x = 0
  38133 						for {
  38134 							if !(x < width) {
  38135 								break
  38136 							}
  38137 							pix3 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38138 							if pix3 != prev_pix3 {
  38139 								prev_idx3 = uint32((**(**[2048]uint16_t)(__ccgo_up(bp)))[ApplyPaletteHash2(tls, pix3)])
  38140 								prev_pix3 = pix3
  38141 							}
  38142 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx3)
  38143 							goto _10
  38144 						_10:
  38145 							;
  38146 							x = x + 1
  38147 						}
  38148 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38149 						src = src + uintptr(src_stride)*4
  38150 						dst = dst + uintptr(dst_stride)*4
  38151 						goto _9
  38152 					_9:
  38153 						;
  38154 						y = y + 1
  38155 					}
  38156 				} else {
  38157 					PrepareMapToPalette(tls, palette, libc.Uint32FromInt32(palette_size), bp+5120, bp+4096)
  38158 					prev_pix4 = **(**uint32_t)(__ccgo_up(palette))
  38159 					prev_idx4 = uint32(0)
  38160 					y = 0
  38161 					for {
  38162 						if !(y < height) {
  38163 							break
  38164 						}
  38165 						x = 0
  38166 						for {
  38167 							if !(x < width) {
  38168 								break
  38169 							}
  38170 							pix4 = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  38171 							if pix4 != prev_pix4 {
  38172 								prev_idx4 = (**(**[256]uint32_t)(__ccgo_up(bp + 4096)))[SearchColorNoIdx(tls, bp+5120, pix4, palette_size)]
  38173 								prev_pix4 = pix4
  38174 							}
  38175 							**(**uint8_t)(__ccgo_up(tmp_row + uintptr(x))) = uint8(prev_idx4)
  38176 							goto _12
  38177 						_12:
  38178 							;
  38179 							x = x + 1
  38180 						}
  38181 						(*(*func(*libc.TLS, uintptr, int32, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LBundleColorMap})))(tls, tmp_row, width, xbits, dst)
  38182 						src = src + uintptr(src_stride)*4
  38183 						dst = dst + uintptr(dst_stride)*4
  38184 						goto _11
  38185 					_11:
  38186 						;
  38187 						y = y + 1
  38188 					}
  38189 				}
  38190 			}
  38191 		}
  38192 	}
  38193 	WebPSafeFree(tls, tmp_row)
  38194 	return int32(1)
  38195 }
  38196 
  38197 // C documentation
  38198 //
  38199 //	// Note: Expects "enc->palette" to be set properly.
  38200 func MapImageFromPalette(tls *libc.TLS, enc uintptr) (r int32) {
  38201 	var height, palette_size, width, xbits, v1 int32
  38202 	var palette, pic uintptr
  38203 	var v3, v4 uint32_t
  38204 	_, _, _, _, _, _, _, _, _ = height, palette, palette_size, pic, width, xbits, v1, v3, v4
  38205 	pic = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic
  38206 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  38207 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  38208 	palette = enc + 104
  38209 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38210 	// Replace each input pixel by corresponding palette index.
  38211 	// This is done line by line.
  38212 	if palette_size <= int32(4) {
  38213 		if palette_size <= int32(2) {
  38214 			v1 = int32(3)
  38215 		} else {
  38216 			v1 = int32(2)
  38217 		}
  38218 		xbits = v1
  38219 	} else {
  38220 		if palette_size <= int32(16) {
  38221 			v1 = int32(1)
  38222 		} else {
  38223 			v1 = 0
  38224 		}
  38225 		xbits = v1
  38226 	}
  38227 	v3 = libc.Uint32FromInt32(xbits)
  38228 	v4 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v3) - uint32(1)) >> v3
  38229 	goto _5
  38230 _5:
  38231 	if !(AllocateTransformBuffer(tls, enc, libc.Int32FromUint32(v4), height) != 0) {
  38232 		return 0
  38233 	}
  38234 	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) {
  38235 		return 0
  38236 	}
  38237 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderPalette)
  38238 	return int32(1)
  38239 }
  38240 
  38241 // C documentation
  38242 //
  38243 //	// Save palette[] to bitstream.
  38244 func EncodePalette(tls *libc.TLS, bw1 uintptr, low_effort int32, enc uintptr, percent_range int32, percent uintptr) (r int32) {
  38245 	bp := tls.Alloc(1024)
  38246 	defer tls.Free(1024)
  38247 	var alpha_and_green, encoded_palette_size, red_and_blue, v3, v6, v9 uint32_t
  38248 	var i, palette_size, v1, v4 int32
  38249 	var palette, v2 uintptr
  38250 	var _ /* tmp_palette at bp+0 */ [256]uint32_t
  38251 	_, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, encoded_palette_size, i, palette, palette_size, red_and_blue, v1, v2, v3, v4, v6, v9
  38252 	palette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38253 	palette = enc + 104
  38254 	if **(**uint32_t)(__ccgo_up(enc + 104 + uintptr(palette_size-int32(1))*4)) == uint32(0) && palette_size > int32(17) {
  38255 		v1 = palette_size - int32(1)
  38256 	} else {
  38257 		v1 = palette_size
  38258 	}
  38259 	// If the last element is 0, do not store it and count on automatic palette
  38260 	// 0-filling. This can only happen if there is no pixel packing, hence if
  38261 	// there are strictly more than 16 colors (after 0 is removed).
  38262 	encoded_palette_size = libc.Uint32FromInt32(v1)
  38263 	v2 = bw1
  38264 	v3 = uint32(TRANSFORM_PRESENT)
  38265 	v4 = int32(1)
  38266 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  38267 		if v4 > libc.Int32FromInt32(0) {
  38268 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38269 				VP8LPutBitsFlushBits(tls, v2)
  38270 			}
  38271 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38272 			**(**int32)(__ccgo_up(v2 + 4)) += v4
  38273 		}
  38274 	} else {
  38275 		VP8LPutBitsInternal(tls, v2, v3, v4)
  38276 	}
  38277 	v2 = bw1
  38278 	v3 = uint32(COLOR_INDEXING_TRANSFORM)
  38279 	v1 = int32(2)
  38280 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  38281 		if v1 > libc.Int32FromInt32(0) {
  38282 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38283 				VP8LPutBitsFlushBits(tls, v2)
  38284 			}
  38285 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38286 			**(**int32)(__ccgo_up(v2 + 4)) += v1
  38287 		}
  38288 	} else {
  38289 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38290 	}
  38291 	v2 = bw1
  38292 	v3 = encoded_palette_size - uint32(1)
  38293 	v1 = int32(8)
  38294 	if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  38295 		if v1 > libc.Int32FromInt32(0) {
  38296 			if (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused >= libc.Int32FromInt32(32) {
  38297 				VP8LPutBitsFlushBits(tls, v2)
  38298 			}
  38299 			**(**vp8l_atype_t)(__ccgo_up(v2)) |= v3 << (*VP8LBitWriter)(unsafe.Pointer(v2)).Fused
  38300 			**(**int32)(__ccgo_up(v2 + 4)) += v1
  38301 		}
  38302 	} else {
  38303 		VP8LPutBitsInternal(tls, v2, v3, v1)
  38304 	}
  38305 	i = libc.Int32FromUint32(encoded_palette_size - uint32(1))
  38306 	for {
  38307 		if !(i >= int32(1)) {
  38308 			break
  38309 		}
  38310 		v3 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  38311 		v6 = **(**uint32_t)(__ccgo_up(palette + uintptr(i-int32(1))*4))
  38312 		alpha_and_green = uint32(0x00ff00ff) + v3&uint32(0xff00ff00) - v6&uint32(0xff00ff00)
  38313 		red_and_blue = uint32(0xff00ff00) + v3&uint32(0x00ff00ff) - v6&uint32(0x00ff00ff)
  38314 		v9 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  38315 		goto _15
  38316 	_15:
  38317 		(**(**[256]uint32_t)(__ccgo_up(bp)))[i] = v9
  38318 		goto _11
  38319 	_11:
  38320 		;
  38321 		i = i - 1
  38322 	}
  38323 	(**(**[256]uint32_t)(__ccgo_up(bp)))[0] = **(**uint32_t)(__ccgo_up(palette))
  38324 	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)
  38325 }
  38326 
  38327 // -----------------------------------------------------------------------------
  38328 // VP8LEncoder
  38329 
  38330 func VP8LEncoderNew(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  38331 	var enc uintptr
  38332 	_ = enc
  38333 	enc = WebPSafeCalloc(tls, uint64(1), uint64(2328))
  38334 	if enc == libc.UintptrFromInt32(0) {
  38335 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38336 		return libc.UintptrFromInt32(0)
  38337 	}
  38338 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fconfig = config
  38339 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fpic = picture
  38340 	(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38341 	VP8LEncDspInit(tls)
  38342 	return enc
  38343 }
  38344 
  38345 func VP8LEncoderDelete(tls *libc.TLS, enc uintptr) {
  38346 	var i int32
  38347 	_ = i
  38348 	if enc != libc.UintptrFromInt32(0) {
  38349 		VP8LHashChainClear(tls, enc+2312)
  38350 		i = 0
  38351 		for {
  38352 			if !(i < int32(4)) {
  38353 				break
  38354 			}
  38355 			VP8LBackwardRefsClear(tls, enc+2152+uintptr(i)*40)
  38356 			goto _1
  38357 		_1:
  38358 			;
  38359 			i = i + 1
  38360 		}
  38361 		ClearTransformBuffer(tls, enc)
  38362 		WebPSafeFree(tls, enc)
  38363 	}
  38364 }
  38365 
  38366 // -----------------------------------------------------------------------------
  38367 // Main call
  38368 
  38369 type StreamEncodeContext = struct {
  38370 	Fconfig                   uintptr
  38371 	Fpicture                  uintptr
  38372 	Fbw                       uintptr
  38373 	Fenc                      uintptr
  38374 	Fcrunch_configs           [14]CrunchConfig
  38375 	Fnum_crunch_configs       int32
  38376 	Fred_and_blue_always_zero int32
  38377 	Fstats                    uintptr
  38378 }
  38379 
  38380 func EncodeStreamHook(tls *libc.TLS, input uintptr, data2 uintptr) (r int32) {
  38381 	bp := tls.Alloc(112)
  38382 	defer tls.Free(112)
  38383 	var best_size, byte_position, v12, v2 size_t
  38384 	var bw2, config, crunch_configs, enc, params, picture, stats, v1, v8 uintptr
  38385 	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
  38386 	var v9 uint32_t
  38387 	var _ /* bw_best at bp+56 */ VP8LBitWriter
  38388 	var _ /* bw_init at bp+16 */ VP8LBitWriter
  38389 	var _ /* cross_color_transform_bits at bp+100 */ int32
  38390 	var _ /* data_size at bp+8 */ int32
  38391 	var _ /* hdr_size at bp+4 */ int32
  38392 	var _ /* percent at bp+0 */ int32
  38393 	var _ /* predictor_transform_bits at bp+96 */ int32
  38394 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  38395 	params = input
  38396 	config = (*StreamEncodeContext)(unsafe.Pointer(params)).Fconfig
  38397 	picture = (*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture
  38398 	bw2 = (*StreamEncodeContext)(unsafe.Pointer(params)).Fbw
  38399 	enc = (*StreamEncodeContext)(unsafe.Pointer(params)).Fenc
  38400 	crunch_configs = params + 32
  38401 	num_crunch_configs = (*StreamEncodeContext)(unsafe.Pointer(params)).Fnum_crunch_configs
  38402 	red_and_blue_always_zero = (*StreamEncodeContext)(unsafe.Pointer(params)).Fred_and_blue_always_zero
  38403 	stats = (*StreamEncodeContext)(unsafe.Pointer(params)).Fstats
  38404 	quality = int32((*WebPConfig)(unsafe.Pointer(config)).Fquality)
  38405 	low_effort = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Fmethod == libc.Int32FromInt32(0))
  38406 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38407 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38408 	v1 = bw2
  38409 	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)))
  38410 	goto _3
  38411 _3:
  38412 	byte_position = v2
  38413 	**(**int32)(__ccgo_up(bp)) = int32(2) // for WebPProgressHook
  38414 	use_near_lossless = 0
  38415 	**(**int32)(__ccgo_up(bp + 4)) = 0
  38416 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38417 	best_size = ^libc.Uint64FromInt32(0)
  38418 	**(**VP8LBitWriter)(__ccgo_up(bp + 16)) = **(**VP8LBitWriter)(__ccgo_up(bw2))
  38419 	_ = data2
  38420 	if !(VP8LBitWriterInit(tls, bp+56, uint64(0)) != 0) || num_crunch_configs > int32(1) && !(VP8LBitWriterClone(tls, bw2, bp+56) != 0) {
  38421 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38422 		goto Error
  38423 	}
  38424 	idx = 0
  38425 	for {
  38426 		if !(idx < num_crunch_configs) {
  38427 			break
  38428 		}
  38429 		entropy_idx = (**(**CrunchConfig)(__ccgo_up(crunch_configs + uintptr(idx)*28))).Fentropy_idx
  38430 		remaining_percent = int32(97) / num_crunch_configs
  38431 		**(**int32)(__ccgo_up(bp + 96)) = 0
  38432 		**(**int32)(__ccgo_up(bp + 100)) = 0
  38433 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette = libc.BoolInt32(entropy_idx == int32(kPalette) || entropy_idx == int32(kPaletteAndSpatial))
  38434 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green = libc.BoolInt32(entropy_idx == int32(kSubGreen) || entropy_idx == int32(kSpatialSubGreen))
  38435 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict = libc.BoolInt32(entropy_idx == int32(kSpatial) || entropy_idx == int32(kSpatialSubGreen) || entropy_idx == int32(kPaletteAndSpatial))
  38436 		// When using a palette, R/B==0, hence no need to test for cross-color.
  38437 		if low_effort != 0 || (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38438 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = 0
  38439 		} else {
  38440 			if red_and_blue_always_zero != 0 {
  38441 				v5 = 0
  38442 			} else {
  38443 				v5 = (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict
  38444 			}
  38445 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color = v5
  38446 		}
  38447 		// Reset any parameter in the encoder that is set in the previous iteration.
  38448 		(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = 0
  38449 		VP8LBackwardRefsClear(tls, enc+2152)
  38450 		VP8LBackwardRefsClear(tls, enc+2152+1*40)
  38451 		// Apply near-lossless preprocessing.
  38452 		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))
  38453 		if use_near_lossless != 0 {
  38454 			if !(AllocateTransformBuffer(tls, enc, width, height) != 0) {
  38455 				goto Error
  38456 			}
  38457 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && !(VP8ApplyNearLossless(tls, picture, (*WebPConfig)(unsafe.Pointer(config)).Fnear_lossless, (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb) != 0) {
  38458 				WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38459 				goto Error
  38460 			}
  38461 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNearLossless)
  38462 		} else {
  38463 			(*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content = int32(kEncoderNone)
  38464 		}
  38465 		// Encode palette
  38466 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38467 			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) {
  38468 				WebPEncodingSetError(tls, (*VP8LEncoder)(unsafe.Pointer(enc)).Fpic, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38469 				goto Error
  38470 			}
  38471 			percent_range = remaining_percent / int32(4)
  38472 			if !(EncodePalette(tls, bw2, low_effort, enc, percent_range, bp) != 0) {
  38473 				goto Error
  38474 			}
  38475 			remaining_percent = remaining_percent - percent_range
  38476 			if !(MapImageFromPalette(tls, enc) != 0) {
  38477 				goto Error
  38478 			}
  38479 			// If using a color cache, do not have it bigger than the number of
  38480 			// colors.
  38481 			if (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size < libc.Int32FromInt32(1)<<libc.Int32FromInt32(MAX_COLOR_CACHE_BITS) {
  38482 				v5 = int32(31) ^ libc.X__builtin_clz(tls, libc.Uint32FromInt32((*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size))
  38483 				goto _7
  38484 			_7:
  38485 				(*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits = v5 + int32(1)
  38486 			}
  38487 		}
  38488 		// In case image is not packed.
  38489 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderNearLossless) && (*VP8LEncoder)(unsafe.Pointer(enc)).Fargb_content != int32(kEncoderPalette) {
  38490 			if !(MakeInputImageCopy(tls, enc) != 0) {
  38491 				goto Error
  38492 			}
  38493 		}
  38494 		// -------------------------------------------------------------------------
  38495 		// Apply transforms and write transform data.
  38496 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38497 			ApplySubtractGreen(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, bw2)
  38498 		}
  38499 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38500 			percent_range = remaining_percent / int32(3)
  38501 			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+96) != 0) {
  38502 				goto Error
  38503 			}
  38504 			remaining_percent = remaining_percent - percent_range
  38505 		}
  38506 		if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38507 			percent_range = remaining_percent / int32(2)
  38508 			if !(ApplyCrossColorFilter(tls, enc, (*VP8LEncoder)(unsafe.Pointer(enc)).Fcurrent_width, height, quality, low_effort, bw2, percent_range, bp, bp+100) != 0) {
  38509 				goto Error
  38510 			}
  38511 			remaining_percent = remaining_percent - percent_range
  38512 		}
  38513 		v1 = bw2
  38514 		v9 = libc.BoolUint32(!(libc.Int32FromInt32(TRANSFORM_PRESENT) != 0))
  38515 		v5 = int32(1)
  38516 		if libc.Uint64FromInt64(2) == libc.Uint64FromInt32(4) {
  38517 			if v5 > libc.Int32FromInt32(0) {
  38518 				if (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused >= libc.Int32FromInt32(32) {
  38519 					VP8LPutBitsFlushBits(tls, v1)
  38520 				}
  38521 				**(**vp8l_atype_t)(__ccgo_up(v1)) |= v9 << (*VP8LBitWriter)(unsafe.Pointer(v1)).Fused
  38522 				**(**int32)(__ccgo_up(v1 + 4)) += v5
  38523 			}
  38524 		} else {
  38525 			VP8LPutBitsInternal(tls, v1, v9, v5)
  38526 		} // No more transforms.
  38527 		// -------------------------------------------------------------------------
  38528 		// Encode and write the transformed image.
  38529 		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) {
  38530 			goto Error
  38531 		}
  38532 		// If we are better than what we already have.
  38533 		v1 = bw2
  38534 		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)))
  38535 		goto _13
  38536 	_13:
  38537 		if v2 < best_size {
  38538 			v8 = bw2
  38539 			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)))
  38540 			goto _16
  38541 		_16:
  38542 			best_size = v12
  38543 			// Store the BitWriter.
  38544 			VP8LBitWriterSwap(tls, bw2, bp+56)
  38545 			// Update the stats.
  38546 			if stats != libc.UintptrFromInt32(0) {
  38547 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_features = uint32(0)
  38548 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_predict != 0 {
  38549 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(1)
  38550 				}
  38551 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_cross_color != 0 {
  38552 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(2)
  38553 				}
  38554 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_subtract_green != 0 {
  38555 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(4)
  38556 				}
  38557 				if (*VP8LEncoder)(unsafe.Pointer(enc)).Fuse_palette != 0 {
  38558 					**(**uint32_t)(__ccgo_up(stats + 148)) |= uint32(8)
  38559 				}
  38560 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fhistogram_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fhisto_bits
  38561 				(*WebPAuxStats)(unsafe.Pointer(stats)).Ftransform_bits = **(**int32)(__ccgo_up(bp + 96))
  38562 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcross_color_transform_bits = **(**int32)(__ccgo_up(bp + 100))
  38563 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fcache_bits = (*VP8LEncoder)(unsafe.Pointer(enc)).Fcache_bits
  38564 				(*WebPAuxStats)(unsafe.Pointer(stats)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc)).Fpalette_size
  38565 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_size = libc.Int32FromUint64(best_size - byte_position)
  38566 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_hdr_size = **(**int32)(__ccgo_up(bp + 4))
  38567 				(*WebPAuxStats)(unsafe.Pointer(stats)).Flossless_data_size = **(**int32)(__ccgo_up(bp + 8))
  38568 			}
  38569 		}
  38570 		// Reset the bit writer for the following iteration if any.
  38571 		if num_crunch_configs > int32(1) {
  38572 			VP8LBitWriterReset(tls, bp+16, bw2)
  38573 		}
  38574 		goto _4
  38575 	_4:
  38576 		;
  38577 		idx = idx + 1
  38578 	}
  38579 	VP8LBitWriterSwap(tls, bp+56, bw2)
  38580 	goto Error
  38581 Error:
  38582 	;
  38583 	VP8LBitWriterWipeOut(tls, bp+56)
  38584 	// The hook should return false in case of error.
  38585 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer((*StreamEncodeContext)(unsafe.Pointer(params)).Fpicture)).Ferror_code == int32(VP8_ENC_OK))
  38586 }
  38587 
  38588 func VP8LEncodeStream(tls *libc.TLS, config uintptr, picture1 uintptr, bw_main uintptr) (r int32) {
  38589 	bp := tls.Alloc(1872)
  38590 	defer tls.Free(1872)
  38591 	var enc_main, enc_side, param, worker, worker_interface, v7, v8 uintptr
  38592 	var idx, num_crunch_configs_side, ok_main, ok_side, params_size, v1 int32
  38593 	var v11, v14 size_t
  38594 	var _ /* bw_side at bp+1568 */ VP8LBitWriter
  38595 	var _ /* crunch_configs at bp+0 */ [14]CrunchConfig
  38596 	var _ /* num_crunch_configs_main at bp+392 */ int32
  38597 	var _ /* params_main at bp+496 */ StreamEncodeContext
  38598 	var _ /* params_side at bp+936 */ StreamEncodeContext
  38599 	var _ /* picture_side at bp+1608 */ WebPPicture
  38600 	var _ /* red_and_blue_always_zero at bp+396 */ int32
  38601 	var _ /* stats_side at bp+1376 */ WebPAuxStats
  38602 	var _ /* worker_main at bp+400 */ WebPWorker
  38603 	var _ /* worker_side at bp+448 */ WebPWorker
  38604 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc_main, enc_side, idx, num_crunch_configs_side, ok_main, ok_side, param, params_size, worker, worker_interface, v1, v11, v14, v7, v8
  38605 	enc_main = VP8LEncoderNew(tls, config, picture1)
  38606 	enc_side = libc.UintptrFromInt32(0)
  38607 	num_crunch_configs_side = 0
  38608 	**(**int32)(__ccgo_up(bp + 396)) = 0
  38609 	worker_interface = WebPGetWorkerInterface(tls)
  38610 	if enc_main == libc.UintptrFromInt32(0) || !(VP8LBitWriterInit(tls, bp+1568, uint64(0)) != 0) {
  38611 		VP8LEncoderDelete(tls, enc_main)
  38612 		return WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38613 	}
  38614 	// Avoid "garbage value" error from Clang's static analysis tool.
  38615 	v1 = WebPPictureInitInternal(tls, bp+1608, int32(WEBP_ENCODER_ABI_VERSION))
  38616 	goto _2
  38617 _2:
  38618 	if !(v1 != 0) {
  38619 		goto Error
  38620 	}
  38621 	// Analyze image (entropy, num_palettes etc)
  38622 	if !(EncoderAnalyze(tls, enc_main, bp, bp+392, bp+396) != 0) || !(EncoderInit(tls, enc_main) != 0) {
  38623 		WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38624 		goto Error
  38625 	}
  38626 	// Split the configs between the main and side threads (if any).
  38627 	if (*WebPConfig)(unsafe.Pointer(config)).Fthread_level > 0 {
  38628 		num_crunch_configs_side = **(**int32)(__ccgo_up(bp + 392)) / int32(2)
  38629 		idx = 0
  38630 		for {
  38631 			if !(idx < num_crunch_configs_side) {
  38632 				break
  38633 			}
  38634 			**(**CrunchConfig)(__ccgo_up(bp + 936 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[**(**int32)(__ccgo_up(bp + 392))-num_crunch_configs_side+idx]
  38635 			goto _3
  38636 		_3:
  38637 			;
  38638 			idx = idx + 1
  38639 		}
  38640 		(**(**StreamEncodeContext)(__ccgo_up(bp + 936))).Fnum_crunch_configs = num_crunch_configs_side
  38641 	}
  38642 	**(**int32)(__ccgo_up(bp + 392)) = **(**int32)(__ccgo_up(bp + 392)) - num_crunch_configs_side
  38643 	idx = 0
  38644 	for {
  38645 		if !(idx < **(**int32)(__ccgo_up(bp + 392))) {
  38646 			break
  38647 		}
  38648 		**(**CrunchConfig)(__ccgo_up(bp + 496 + 32 + uintptr(idx)*28)) = (**(**[14]CrunchConfig)(__ccgo_up(bp)))[idx]
  38649 		goto _4
  38650 	_4:
  38651 		;
  38652 		idx = idx + 1
  38653 	}
  38654 	(**(**StreamEncodeContext)(__ccgo_up(bp + 496))).Fnum_crunch_configs = **(**int32)(__ccgo_up(bp + 392))
  38655 	// Fill in the parameters for the thread workers.
  38656 	if num_crunch_configs_side > 0 {
  38657 		v1 = int32(2)
  38658 	} else {
  38659 		v1 = int32(1)
  38660 	}
  38661 	params_size = v1
  38662 	idx = 0
  38663 	for {
  38664 		if !(idx < params_size) {
  38665 			break
  38666 		}
  38667 		if idx == 0 {
  38668 			v7 = bp + 400
  38669 		} else {
  38670 			v7 = bp + 448
  38671 		}
  38672 		// Create the parameters for each worker.
  38673 		worker = v7
  38674 		if idx == 0 {
  38675 			v8 = bp + 496
  38676 		} else {
  38677 			v8 = bp + 936
  38678 		}
  38679 		param = v8
  38680 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fconfig = config
  38681 		(*StreamEncodeContext)(unsafe.Pointer(param)).Fred_and_blue_always_zero = **(**int32)(__ccgo_up(bp + 396))
  38682 		if idx == 0 {
  38683 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = picture1
  38684 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = (*WebPPicture)(unsafe.Pointer(picture1)).Fstats
  38685 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bw_main
  38686 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_main
  38687 		} else {
  38688 			// Create a side picture (error_code is not thread-safe).
  38689 			if !(WebPPictureView(tls, picture1, 0, 0, (*WebPPicture)(unsafe.Pointer(picture1)).Fwidth, (*WebPPicture)(unsafe.Pointer(picture1)).Fheight, bp+1608) != 0) {
  38690 			}
  38691 			(**(**WebPPicture)(__ccgo_up(bp + 1608))).Fprogress_hook = libc.UintptrFromInt32(0) // Progress hook is not thread-safe.
  38692 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fpicture = bp + 1608                  // No need to free a view afterwards.
  38693 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats == libc.UintptrFromInt32(0) {
  38694 				v7 = libc.UintptrFromInt32(0)
  38695 			} else {
  38696 				v7 = bp + 1376
  38697 			}
  38698 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fstats = v7
  38699 			// Create a side bit writer.
  38700 			if !(VP8LBitWriterClone(tls, bw_main, bp+1568) != 0) {
  38701 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38702 				goto Error
  38703 			}
  38704 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fbw = bp + 1568
  38705 			// Create a side encoder.
  38706 			enc_side = VP8LEncoderNew(tls, config, bp+1608)
  38707 			if enc_side == libc.UintptrFromInt32(0) || !(EncoderInit(tls, enc_side) != 0) {
  38708 				WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38709 				goto Error
  38710 			}
  38711 			// Copy the values that were computed for the main encoder.
  38712 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fhisto_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fhisto_bits
  38713 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpredictor_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpredictor_transform_bits
  38714 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fcross_color_transform_bits = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fcross_color_transform_bits
  38715 			(*VP8LEncoder)(unsafe.Pointer(enc_side)).Fpalette_size = (*VP8LEncoder)(unsafe.Pointer(enc_main)).Fpalette_size
  38716 			libc.Xmemcpy(tls, enc_side+104, enc_main+104, uint64(1024))
  38717 			libc.Xmemcpy(tls, enc_side+1128, enc_main+1128, uint64(1024))
  38718 			(*StreamEncodeContext)(unsafe.Pointer(param)).Fenc = enc_side
  38719 		}
  38720 		// Create the workers.
  38721 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FInit})))(tls, worker)
  38722 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata1 = param
  38723 		(*WebPWorker)(unsafe.Pointer(worker)).Fdata2 = libc.UintptrFromInt32(0)
  38724 		(*WebPWorker)(unsafe.Pointer(worker)).Fhook = __ccgo_fp(EncodeStreamHook)
  38725 		goto _6
  38726 	_6:
  38727 		;
  38728 		idx = idx + 1
  38729 	}
  38730 	// Start the second thread if needed.
  38731 	if num_crunch_configs_side != 0 {
  38732 		if !((*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FReset})))(tls, bp+448) != 0) {
  38733 			WebPEncodingSetError(tls, picture1, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38734 			goto Error
  38735 		}
  38736 		// This line is here and not in the param initialization above to remove a
  38737 		// Clang static analyzer warning.
  38738 		if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38739 			libc.Xmemcpy(tls, bp+1376, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, uint64(188))
  38740 		}
  38741 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FLaunch})))(tls, bp+448)
  38742 	}
  38743 	// Execute the main thread.
  38744 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FExecute})))(tls, bp+400)
  38745 	ok_main = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+400)
  38746 	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+400)
  38747 	if num_crunch_configs_side != 0 {
  38748 		// Wait for the second thread.
  38749 		ok_side = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FSync})))(tls, bp+448)
  38750 		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*WebPWorkerInterface)(unsafe.Pointer(worker_interface)).FEnd})))(tls, bp+448)
  38751 		if !(ok_main != 0) || !(ok_side != 0) {
  38752 			if (*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK) {
  38753 				WebPEncodingSetError(tls, picture1, (**(**WebPPicture)(__ccgo_up(bp + 1608))).Ferror_code)
  38754 			}
  38755 			goto Error
  38756 		}
  38757 		v7 = bp + 1568
  38758 		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)))
  38759 		goto _12
  38760 	_12:
  38761 		v8 = bw_main
  38762 		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)))
  38763 		goto _15
  38764 	_15:
  38765 		if v11 < v14 {
  38766 			VP8LBitWriterSwap(tls, bw_main, bp+1568)
  38767 			if (*WebPPicture)(unsafe.Pointer(picture1)).Fstats != libc.UintptrFromInt32(0) {
  38768 				libc.Xmemcpy(tls, (*WebPPicture)(unsafe.Pointer(picture1)).Fstats, bp+1376, uint64(188))
  38769 			}
  38770 		}
  38771 	}
  38772 	goto Error
  38773 Error:
  38774 	;
  38775 	VP8LBitWriterWipeOut(tls, bp+1568)
  38776 	VP8LEncoderDelete(tls, enc_main)
  38777 	VP8LEncoderDelete(tls, enc_side)
  38778 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture1)).Ferror_code == int32(VP8_ENC_OK))
  38779 }
  38780 
  38781 func VP8LEncodeImage(tls *libc.TLS, config uintptr, picture uintptr) (r int32) {
  38782 	bp := tls.Alloc(64)
  38783 	defer tls.Free(64)
  38784 	var has_alpha, height, initial_size, mb_h, mb_w, width, v1 int32
  38785 	var stats uintptr
  38786 	var _ /* bw at bp+16 */ VP8LBitWriter
  38787 	var _ /* coded_size at bp+0 */ size_t
  38788 	var _ /* percent at bp+8 */ int32
  38789 	_, _, _, _, _, _, _, _ = has_alpha, height, initial_size, mb_h, mb_w, stats, width, v1
  38790 	**(**int32)(__ccgo_up(bp + 8)) = 0
  38791 	if picture == libc.UintptrFromInt32(0) {
  38792 		return 0
  38793 	}
  38794 	if config == libc.UintptrFromInt32(0) || (*WebPPicture)(unsafe.Pointer(picture)).Fargb == libc.UintptrFromInt32(0) {
  38795 		return WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  38796 	}
  38797 	width = (*WebPPicture)(unsafe.Pointer(picture)).Fwidth
  38798 	height = (*WebPPicture)(unsafe.Pointer(picture)).Fheight
  38799 	// Initialize BitWriter with size corresponding to 16 bpp to photo images and
  38800 	// 8 bpp for graphical images.
  38801 	if (*WebPConfig)(unsafe.Pointer(config)).Fimage_hint == int32(WEBP_HINT_GRAPH) {
  38802 		v1 = width * height
  38803 	} else {
  38804 		v1 = width * height * int32(2)
  38805 	}
  38806 	initial_size = v1
  38807 	if !(VP8LBitWriterInit(tls, bp+16, libc.Uint64FromInt32(initial_size)) != 0) {
  38808 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38809 		goto Error
  38810 	}
  38811 	if !!(WebPReportProgress(tls, picture, int32(1), bp+8) != 0) {
  38812 		goto _2
  38813 	}
  38814 	goto UserAbort
  38815 UserAbort:
  38816 	;
  38817 	WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_USER_ABORT))
  38818 	goto Error
  38819 _2:
  38820 	;
  38821 	// Reset stats (for pure lossless coding)
  38822 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38823 		stats = (*WebPPicture)(unsafe.Pointer(picture)).Fstats
  38824 		libc.Xmemset(tls, stats, 0, uint64(188))
  38825 		**(**float32)(__ccgo_up(stats + 4)) = libc.Float32FromFloat32(99)
  38826 		**(**float32)(__ccgo_up(stats + 4 + 1*4)) = libc.Float32FromFloat32(99)
  38827 		**(**float32)(__ccgo_up(stats + 4 + 2*4)) = libc.Float32FromFloat32(99)
  38828 		**(**float32)(__ccgo_up(stats + 4 + 3*4)) = libc.Float32FromFloat32(99)
  38829 		**(**float32)(__ccgo_up(stats + 4 + 4*4)) = libc.Float32FromFloat32(99)
  38830 	}
  38831 	// Write image size.
  38832 	if !(WriteImageSize(tls, picture, bp+16) != 0) {
  38833 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38834 		goto Error
  38835 	}
  38836 	has_alpha = WebPPictureHasTransparency(tls, picture)
  38837 	// Write the non-trivial Alpha flag and lossless version.
  38838 	if !(WriteRealAlphaAndVersion(tls, bp+16, has_alpha) != 0) {
  38839 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38840 		goto Error
  38841 	}
  38842 	if !(WebPReportProgress(tls, picture, int32(2), bp+8) != 0) {
  38843 		goto UserAbort
  38844 	}
  38845 	// Encode main image stream.
  38846 	if !(VP8LEncodeStream(tls, config, picture, bp+16) != 0) {
  38847 		goto Error
  38848 	}
  38849 	if !(WebPReportProgress(tls, picture, int32(99), bp+8) != 0) {
  38850 		goto UserAbort
  38851 	}
  38852 	// Finish the RIFF chunk.
  38853 	if !(WriteImage(tls, picture, bp+16, bp) != 0) {
  38854 		goto Error
  38855 	}
  38856 	if !(WebPReportProgress(tls, picture, int32(100), bp+8) != 0) {
  38857 		goto UserAbort
  38858 	}
  38859 	// Save size.
  38860 	if (*WebPPicture)(unsafe.Pointer(picture)).Fstats != libc.UintptrFromInt32(0) {
  38861 		**(**int32)(__ccgo_up((*WebPPicture)(unsafe.Pointer(picture)).Fstats)) += libc.Int32FromUint64(**(**size_t)(__ccgo_up(bp)))
  38862 		(*WebPAuxStats)(unsafe.Pointer((*WebPPicture)(unsafe.Pointer(picture)).Fstats)).Flossless_size = libc.Int32FromUint64(**(**size_t)(__ccgo_up(bp)))
  38863 	}
  38864 	if (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info != libc.UintptrFromInt32(0) {
  38865 		mb_w = (width + int32(15)) >> int32(4)
  38866 		mb_h = (height + int32(15)) >> int32(4)
  38867 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(picture)).Fextra_info, 0, libc.Uint64FromInt32(mb_w*mb_h)*uint64(1))
  38868 	}
  38869 	goto Error
  38870 Error:
  38871 	;
  38872 	if (**(**VP8LBitWriter)(__ccgo_up(bp + 16))).Ferror1 != 0 {
  38873 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  38874 	}
  38875 	VP8LBitWriterWipeOut(tls, bp+16)
  38876 	return libc.BoolInt32((*WebPPicture)(unsafe.Pointer(picture)).Ferror_code == int32(VP8_ENC_OK))
  38877 }
  38878 
  38879 const VP8L_MAGIC_BYTE4 = 0x2f
  38880 
  38881 //------------------------------------------------------------------------------
  38882 
  38883 // Copyright 2012 Google Inc. All Rights Reserved.
  38884 //
  38885 // Use of this source code is governed by a BSD-style license
  38886 // that can be found in the COPYING file in the root of the source
  38887 // tree. An additional intellectual property rights grant can be found
  38888 // in the file PATENTS. All contributing project authors may
  38889 // be found in the AUTHORS file in the root of the source tree.
  38890 // -----------------------------------------------------------------------------
  38891 //
  38892 // Misc. common utility functions
  38893 //
  38894 // Authors: Skal (pascal.massimino@gmail.com)
  38895 //          Urvang (urvang@google.com)
  38896 
  38897 // Copyright 2011 Google Inc. All Rights Reserved.
  38898 //
  38899 // Use of this source code is governed by a BSD-style license
  38900 // that can be found in the COPYING file in the root of the source
  38901 // tree. An additional intellectual property rights grant can be found
  38902 // in the file PATENTS. All contributing project authors may
  38903 // be found in the AUTHORS file in the root of the source tree.
  38904 // -----------------------------------------------------------------------------
  38905 //
  38906 //   WebP encoder: main interface
  38907 //
  38908 // Author: Skal (pascal.massimino@gmail.com)
  38909 
  38910 // #define PRINT_MEMORY_INFO
  38911 
  38912 //------------------------------------------------------------------------------
  38913 
  38914 func WebPGetEncoderVersion(tls *libc.TLS) (r int32) {
  38915 	return libc.Int32FromInt32(ENC_MAJ_VERSION)<<libc.Int32FromInt32(16) | libc.Int32FromInt32(ENC_MIN_VERSION)<<libc.Int32FromInt32(8) | libc.Int32FromInt32(ENC_REV_VERSION)
  38916 }
  38917 
  38918 //------------------------------------------------------------------------------
  38919 // VP8Encoder
  38920 //------------------------------------------------------------------------------
  38921 
  38922 func ResetSegmentHeader1(tls *libc.TLS, enc uintptr) {
  38923 	var hdr uintptr
  38924 	_ = hdr
  38925 	hdr = enc + 32
  38926 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments = (*WebPConfig)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fconfig)).Fsegments
  38927 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fupdate_map = libc.BoolInt32((*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fnum_segments > int32(1))
  38928 	(*VP8EncSegmentHeader)(unsafe.Pointer(hdr)).Fsize = 0
  38929 }
  38930 
  38931 func ResetFilterHeader(tls *libc.TLS, enc uintptr) {
  38932 	var hdr uintptr
  38933 	_ = hdr
  38934 	hdr = enc + 16
  38935 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsimple = int32(1)
  38936 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Flevel = 0
  38937 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fsharpness = 0
  38938 	(*VP8EncFilterHeader)(unsafe.Pointer(hdr)).Fi4x4_lf_delta = 0
  38939 }
  38940 
  38941 func ResetBoundaryPredictions(tls *libc.TLS, enc uintptr) {
  38942 	var i int32
  38943 	var left, top uintptr
  38944 	_, _, _ = i, left, top
  38945 	top = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  38946 	left = (*VP8Encoder)(unsafe.Pointer(enc)).Fpreds - uintptr(1)
  38947 	i = -int32(1)
  38948 	for {
  38949 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w) {
  38950 			break
  38951 		}
  38952 		**(**uint8_t)(__ccgo_up(top + uintptr(i))) = uint8(B_DC_PRED)
  38953 		goto _1
  38954 	_1:
  38955 		;
  38956 		i = i + 1
  38957 	}
  38958 	i = 0
  38959 	for {
  38960 		if !(i < int32(4)*(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h) {
  38961 			break
  38962 		}
  38963 		**(**uint8_t)(__ccgo_up(left + uintptr(i*(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w))) = uint8(B_DC_PRED)
  38964 		goto _2
  38965 	_2:
  38966 		;
  38967 		i = i + 1
  38968 	}
  38969 	**(**uint32_t)(__ccgo_up((*VP8Encoder)(unsafe.Pointer(enc)).Fnz + uintptr(-libc.Int32FromInt32(1))*4)) = uint32(0) // constant
  38970 }
  38971 
  38972 // Mapping from config->method to coding tools used.
  38973 //-------------------+---+---+---+---+---+---+---+
  38974 //   Method          | 0 | 1 | 2 | 3 |(4)| 5 | 6 |
  38975 //-------------------+---+---+---+---+---+---+---+
  38976 // fast probe        | x |   |   | x |   |   |   |
  38977 //-------------------+---+---+---+---+---+---+---+
  38978 // dynamic proba     | ~ | x | x | x | x | x | x |
  38979 //-------------------+---+---+---+---+---+---+---+
  38980 // fast mode analysis|[x]|[x]|   |   | x | x | x |
  38981 //-------------------+---+---+---+---+---+---+---+
  38982 // basic rd-opt      |   |   |   | x | x | x | x |
  38983 //-------------------+---+---+---+---+---+---+---+
  38984 // disto-refine i4/16| x | x | x |   |   |   |   |
  38985 //-------------------+---+---+---+---+---+---+---+
  38986 // disto-refine uv   |   | x | x |   |   |   |   |
  38987 //-------------------+---+---+---+---+---+---+---+
  38988 // rd-opt i4/16      |   |   | ~ | x | x | x | x |
  38989 //-------------------+---+---+---+---+---+---+---+
  38990 // token buffer (opt)|   |   |   | x | x | x | x |
  38991 //-------------------+---+---+---+---+---+---+---+
  38992 // Trellis           |   |   |   |   |   | x |Ful|
  38993 //-------------------+---+---+---+---+---+---+---+
  38994 // full-SNS          |   |   |   |   | x | x | x |
  38995 //-------------------+---+---+---+---+---+---+---+
  38996 
  38997 func MapConfigToTools(tls *libc.TLS, enc uintptr) {
  38998 	var config uintptr
  38999 	var limit, method, v1, v2, v3 int32
  39000 	_, _, _, _, _, _ = config, limit, method, v1, v2, v3
  39001 	config = (*VP8Encoder)(unsafe.Pointer(enc)).Fconfig
  39002 	method = (*WebPConfig)(unsafe.Pointer(config)).Fmethod
  39003 	limit = int32(100) - (*WebPConfig)(unsafe.Pointer(config)).Fpartition_limit
  39004 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmethod = method
  39005 	if method >= int32(6) {
  39006 		v1 = int32(RD_OPT_TRELLIS_ALL)
  39007 	} else {
  39008 		if method >= int32(5) {
  39009 			v2 = int32(RD_OPT_TRELLIS)
  39010 		} else {
  39011 			if method >= int32(3) {
  39012 				v3 = int32(RD_OPT_BASIC)
  39013 			} else {
  39014 				v3 = int32(RD_OPT_NONE)
  39015 			}
  39016 			v2 = v3
  39017 		}
  39018 		v1 = v2
  39019 	}
  39020 	(*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level = v1
  39021 	(*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.
  39022 	// partition0 = 512k max.
  39023 	(*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))
  39024 	(*VP8Encoder)(unsafe.Pointer(enc)).Fthread_level = (*WebPConfig)(unsafe.Pointer(config)).Fthread_level
  39025 	(*VP8Encoder)(unsafe.Pointer(enc)).Fdo_search = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ftarget_size > 0 || (*WebPConfig)(unsafe.Pointer(config)).Ftarget_PSNR > libc.Float32FromInt32(0))
  39026 	if !((*WebPConfig)(unsafe.Pointer(config)).Flow_memory != 0) {
  39027 		(*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens = libc.BoolInt32((*VP8Encoder)(unsafe.Pointer(enc)).Frd_opt_level >= int32(RD_OPT_BASIC)) // need rd stats
  39028 		if (*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0 {
  39029 			(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) // doesn't work with multi-partition
  39030 		}
  39031 	}
  39032 }
  39033 
  39034 // Memory scaling with dimensions:
  39035 //  memory (bytes) ~= 2.25 * w + 0.0625 * w * h
  39036 //
  39037 // Typical memory footprint (614x440 picture)
  39038 //              encoder: 22111
  39039 //                 info: 4368
  39040 //                preds: 17741
  39041 //          top samples: 1263
  39042 //             non-zero: 175
  39043 //             lf-stats: 0
  39044 //                total: 45658
  39045 // Transient object sizes:
  39046 //       VP8EncIterator: 3360
  39047 //         VP8ModeScore: 872
  39048 //       VP8SegmentInfo: 732
  39049 //          VP8EncProba: 18352
  39050 //              LFStats: 2048
  39051 // Picture size (yuv): 419328
  39052 
  39053 func InitVP8Encoder(tls *libc.TLS, config uintptr, picture uintptr) (r uintptr) {
  39054 	var enc, mem, v3 uintptr
  39055 	var info_size, lf_stats_size, nz_size, preds_size, samples_size, top_derr_size size_t
  39056 	var mb_h, mb_w, preds_h, preds_w, top_stride, use_filter, v5, v6 int32
  39057 	var scale float32
  39058 	var size uint64_t
  39059 	var v1, v2 uint64
  39060 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  39061 	use_filter = libc.BoolInt32((*WebPConfig)(unsafe.Pointer(config)).Ffilter_strength > 0 || (*WebPConfig)(unsafe.Pointer(config)).Fautofilter > 0)
  39062 	mb_w = ((*WebPPicture)(unsafe.Pointer(picture)).Fwidth + int32(15)) >> int32(4)
  39063 	mb_h = ((*WebPPicture)(unsafe.Pointer(picture)).Fheight + int32(15)) >> int32(4)
  39064 	preds_w = int32(4)*mb_w + int32(1)
  39065 	preds_h = int32(4)*mb_h + int32(1)
  39066 	preds_size = libc.Uint64FromInt32(preds_w*preds_h) * uint64(1)
  39067 	top_stride = mb_w * int32(16)
  39068 	nz_size = libc.Uint64FromInt32(mb_w+libc.Int32FromInt32(1))*uint64(4) + uint64(WEBP_ALIGN_CST)
  39069 	info_size = libc.Uint64FromInt32(mb_w*mb_h) * uint64(4)
  39070 	samples_size = libc.Uint64FromInt32(int32(2)*top_stride)*uint64(1) + uint64(WEBP_ALIGN_CST)
  39071 	if (*WebPConfig)(unsafe.Pointer(config)).Fautofilter != 0 {
  39072 		v1 = libc.Uint64FromInt64(2048) + libc.Uint64FromInt32(WEBP_ALIGN_CST)
  39073 	} else {
  39074 		v1 = uint64(0)
  39075 	} // align all
  39076 	lf_stats_size = v1
  39077 	if (*WebPConfig)(unsafe.Pointer(config)).Fquality <= libc.Float32FromInt32(ERROR_DIFFUSION_QUALITY) || (*WebPConfig)(unsafe.Pointer(config)).Fpass > int32(1) {
  39078 		v2 = libc.Uint64FromInt32(mb_w) * uint64(4)
  39079 	} else {
  39080 		v2 = uint64(0)
  39081 	}
  39082 	top_derr_size = v2
  39083 	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
  39084 	mem = WebPSafeMalloc(tls, size, uint64(1))
  39085 	if mem == libc.UintptrFromInt32(0) {
  39086 		WebPEncodingSetError(tls, picture, int32(VP8_ENC_ERROR_OUT_OF_MEMORY))
  39087 		return libc.UintptrFromInt32(0)
  39088 	}
  39089 	enc = mem
  39090 	mem = uintptr((uint64(mem+libc.UintptrFromInt64(23704)) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39091 	libc.Xmemset(tls, enc, 0, uint64(23704))
  39092 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnum_parts = int32(1) << (*WebPConfig)(unsafe.Pointer(config)).Fpartitions
  39093 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_w = mb_w
  39094 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_h = mb_h
  39095 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w = preds_w
  39096 	(*VP8Encoder)(unsafe.Pointer(enc)).Fmb_info = mem
  39097 	mem = mem + uintptr(info_size)
  39098 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpreds = mem + uintptr(1) + uintptr((*VP8Encoder)(unsafe.Pointer(enc)).Fpreds_w)
  39099 	mem = mem + uintptr(preds_size)
  39100 	(*VP8Encoder)(unsafe.Pointer(enc)).Fnz = uintptr(1)*4 + uintptr((uint64(mem)+libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39101 	mem = mem + uintptr(nz_size)
  39102 	if lf_stats_size != 0 {
  39103 		v3 = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39104 	} else {
  39105 		v3 = libc.UintptrFromInt32(0)
  39106 	}
  39107 	(*VP8Encoder)(unsafe.Pointer(enc)).Flf_stats = v3
  39108 	mem = mem + uintptr(lf_stats_size)
  39109 	// top samples (all 16-aligned)
  39110 	mem = uintptr((uint64(mem) + libc.Uint64FromInt32(WEBP_ALIGN_CST)) & ^libc.Uint64FromInt32(WEBP_ALIGN_CST))
  39111 	(*VP8Encoder)(unsafe.Pointer(enc)).Fy_top = mem
  39112 	(*VP8Encoder)(unsafe.Pointer(enc)).Fuv_top = (*VP8Encoder)(unsafe.Pointer(enc)).Fy_top + uintptr(top_stride)
  39113 	mem = mem + uintptr(int32(2)*top_stride)
  39114 	if top_derr_size != 0 {
  39115 		v3 = mem
  39116 	} else {
  39117 		v3 = libc.UintptrFromInt32(0)
  39118 	}
  39119 	(*VP8Encoder)(unsafe.Pointer(enc)).Ftop_derr = v3
  39120 	mem = mem + uintptr(top_derr_size)
  39121 	(*VP8Encoder)(unsafe.Pointer(enc)).Fconfig = config
  39122 	if use_filter != 0 {
  39123 		if (*WebPConfig)(unsafe.Pointer(config)).Ffilter_type == int32(1) {
  39124 			v6 = 0
  39125 		} else {
  39126 			v6 = int32(1)
  39127 		}
  39128 		v5 = v6
  39129 	} else {
  39130 		v5 = int32(2)
  39131 	}
  39132 	(*VP8Encoder)(unsafe.Pointer(enc)).Fprofile = v5
  39133 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpic = picture
  39134 	(*VP8Encoder)(unsafe.Pointer(enc)).Fpercent = 0
  39135 	MapConfigToTools(tls, enc)
  39136 	VP8EncDspInit(tls)
  39137 	VP8DefaultProbas(tls, enc)
  39138 	ResetSegmentHeader1(tls, enc)
  39139 	ResetFilterHeader(tls, enc)
  39140 	ResetBoundaryPredictions(tls, enc)
  39141 	VP8EncDspCostInit(tls)
  39142 	VP8EncInitAlpha(tls, enc)
  39143 	// lower quality means smaller output -> we modulate a little the page
  39144 	// size based on quality. This is just a crude 1rst-order prediction.
  39145 	scale = libc.Float32FromFloat32(1) + float32((*WebPConfig)(unsafe.Pointer(config)).Fquality*libc.Float32FromFloat32(5))/libc.Float32FromFloat32(100) // in [1,6]
  39146 	VP8TBufferInit(tls, enc+496, int32(float32(float32(mb_w*mb_h*libc.Int32FromInt32(4))*scale)))
  39147 	return enc
  39148 }
  39149 
  39150 func DeleteVP8Encoder(tls *libc.TLS, enc uintptr) (r int32) {
  39151 	var ok int32
  39152 	_ = ok
  39153 	ok = int32(1)
  39154 	if enc != libc.UintptrFromInt32(0) {
  39155 		ok = VP8EncDeleteAlpha(tls, enc)
  39156 		VP8TBufferClear(tls, enc+496)
  39157 		WebPSafeFree(tls, enc)
  39158 	}
  39159 	return ok
  39160 }
  39161 
  39162 //------------------------------------------------------------------------------
  39163 
  39164 func GetPSNR2(tls *libc.TLS, err uint64_t, size uint64_t) (r float64) {
  39165 	var v1 float64
  39166 	_ = v1
  39167 	if err > uint64(0) && size > uint64(0) {
  39168 		v1 = float64(float64(10) * libc.Xlog10(tls, float64(float64(libc.Float64FromFloat64(255)*libc.Float64FromFloat64(255))*float64(size))/float64(err)))
  39169 	} else {
  39170 		v1 = float64(99)
  39171 	}
  39172 	return v1
  39173 }
  39174 
  39175 func FinalizePSNR(tls *libc.TLS, enc uintptr) {
  39176 	var size uint64_t
  39177 	var sse, stats uintptr
  39178 	_, _, _ = size, sse, stats
  39179 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  39180 	size = (*VP8Encoder)(unsafe.Pointer(enc)).Fsse_count
  39181 	sse = enc + 23512
  39182 	**(**float32)(__ccgo_up(stats + 4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse)), size))
  39183 	**(**float32)(__ccgo_up(stats + 4 + 1*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 1*8)), size/uint64(4)))
  39184 	**(**float32)(__ccgo_up(stats + 4 + 2*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 2*8)), size/uint64(4)))
  39185 	**(**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)))
  39186 	**(**float32)(__ccgo_up(stats + 4 + 4*4)) = float32(GetPSNR2(tls, **(**uint64_t)(__ccgo_up(sse + 3*8)), size))
  39187 }
  39188 
  39189 func StoreStats(tls *libc.TLS, enc uintptr) {
  39190 	var i, s int32
  39191 	var stats uintptr
  39192 	_, _, _ = i, s, stats
  39193 	stats = (*WebPPicture)(unsafe.Pointer((*VP8Encoder)(unsafe.Pointer(enc)).Fpic)).Fstats
  39194 	if stats != libc.UintptrFromInt32(0) {
  39195 		i = 0
  39196 		for {
  39197 			if !(i < int32(NUM_MB_SEGMENTS)) {
  39198 				break
  39199 			}
  39200 			**(**int32)(__ccgo_up(stats + 124 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Ffstrength
  39201 			**(**int32)(__ccgo_up(stats + 108 + uintptr(i)*4)) = (**(**VP8SegmentInfo)(__ccgo_up(enc + 608 + uintptr(i)*744))).Fquant
  39202 			s = 0
  39203 			for {
  39204 				if !(s <= int32(2)) {
  39205 					break
  39206 				}
  39207 				**(**int32)(__ccgo_up(stats + 44 + uintptr(s)*16 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23556 + uintptr(s)*16 + uintptr(i)*4))
  39208 				goto _2
  39209 			_2:
  39210 				;
  39211 				s = s + 1
  39212 			}
  39213 			goto _1
  39214 		_1:
  39215 			;
  39216 			i = i + 1
  39217 		}
  39218 		FinalizePSNR(tls, enc)
  39219 		(*WebPAuxStats)(unsafe.Pointer(stats)).Fcoded_size = (*VP8Encoder)(unsafe.Pointer(enc)).Fcoded_size
  39220 		i = 0
  39221 		for {
  39222 			if !(i < int32(3)) {
  39223 				break
  39224 			}
  39225 			**(**int32)(__ccgo_up(stats + 24 + uintptr(i)*4)) = **(**int32)(__ccgo_up(enc + 23604 + uintptr(i)*4))
  39226 			goto _3
  39227 		_3:
  39228 			;
  39229 			i = i + 1
  39230 		}
  39231 	}
  39232 }
  39233 
  39234 func WebPEncodingSetError(tls *libc.TLS, pic uintptr, error1 WebPEncodingError1) (r int32) {
  39235 	// The oldest error reported takes precedence over the new one.
  39236 	if (*WebPPicture)(unsafe.Pointer(pic)).Ferror_code == int32(VP8_ENC_OK) {
  39237 		(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = error1
  39238 	}
  39239 	return 0
  39240 }
  39241 
  39242 func WebPReportProgress(tls *libc.TLS, pic uintptr, percent int32, percent_store uintptr) (r int32) {
  39243 	if percent_store != libc.UintptrFromInt32(0) && percent != **(**int32)(__ccgo_up(percent_store)) {
  39244 		**(**int32)(__ccgo_up(percent_store)) = percent
  39245 		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) {
  39246 			// user abort requested
  39247 			return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_USER_ABORT))
  39248 		}
  39249 	}
  39250 	return int32(1) // ok
  39251 }
  39252 
  39253 //------------------------------------------------------------------------------
  39254 
  39255 func WebPEncode(tls *libc.TLS, config uintptr, pic uintptr) (r int32) {
  39256 	var dithering, x, x2 float32
  39257 	var enc uintptr
  39258 	var ok int32
  39259 	_, _, _, _, _ = dithering, enc, ok, x, x2
  39260 	ok = 0
  39261 	if pic == libc.UintptrFromInt32(0) {
  39262 		return 0
  39263 	}
  39264 	(*WebPPicture)(unsafe.Pointer(pic)).Ferror_code = int32(VP8_ENC_OK) // all ok so far
  39265 	if config == libc.UintptrFromInt32(0) {                             // bad params
  39266 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_NULL_PARAMETER))
  39267 	}
  39268 	if !(WebPValidateConfig(tls, config) != 0) {
  39269 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_INVALID_CONFIGURATION))
  39270 	}
  39271 	if !(WebPValidatePicture(tls, pic) != 0) {
  39272 		return 0
  39273 	}
  39274 	if (*WebPPicture)(unsafe.Pointer(pic)).Fwidth > int32(WEBP_MAX_DIMENSION) || (*WebPPicture)(unsafe.Pointer(pic)).Fheight > int32(WEBP_MAX_DIMENSION) {
  39275 		return WebPEncodingSetError(tls, pic, int32(VP8_ENC_ERROR_BAD_DIMENSION))
  39276 	}
  39277 	if (*WebPPicture)(unsafe.Pointer(pic)).Fstats != libc.UintptrFromInt32(0) {
  39278 		libc.Xmemset(tls, (*WebPPicture)(unsafe.Pointer(pic)).Fstats, 0, uint64(188))
  39279 	}
  39280 	if !((*WebPConfig)(unsafe.Pointer(config)).Flossless != 0) {
  39281 		enc = libc.UintptrFromInt32(0)
  39282 		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) {
  39283 			// Make sure we have YUVA samples.
  39284 			if (*WebPConfig)(unsafe.Pointer(config)).Fuse_sharp_yuv != 0 || (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(4) != 0 {
  39285 				if !(WebPPictureSharpARGBToYUVA(tls, pic) != 0) {
  39286 					return 0
  39287 				}
  39288 			} else {
  39289 				dithering = libc.Float32FromFloat32(0)
  39290 				if (*WebPConfig)(unsafe.Pointer(config)).Fpreprocessing&int32(2) != 0 {
  39291 					x = (*WebPConfig)(unsafe.Pointer(config)).Fquality / libc.Float32FromFloat32(100)
  39292 					x2 = float32(x * x)
  39293 					// slowly decreasing from max dithering at low quality (q->0)
  39294 					// to 0.5 dithering amplitude at high quality (q->100)
  39295 					dithering = libc.Float32FromFloat32(1) + float32(float32((libc.Float32FromFloat32(0.5)-libc.Float32FromFloat32(1))*x2)*x2)
  39296 				}
  39297 				if !(WebPPictureARGBToYUVADithered(tls, pic, int32(WEBP_YUV420), dithering) != 0) {
  39298 					return 0
  39299 				}
  39300 			}
  39301 		}
  39302 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39303 			WebPCleanupTransparentArea(tls, pic)
  39304 		}
  39305 		enc = InitVP8Encoder(tls, config, pic)
  39306 		if enc == libc.UintptrFromInt32(0) {
  39307 			return 0
  39308 		} // pic->error is already set.
  39309 		// Note: each of the tasks below account for 20% in the progress report.
  39310 		ok = VP8EncAnalyze(tls, enc)
  39311 		// Analysis is done, proceed to actual coding.
  39312 		ok = libc.BoolInt32(ok != 0 && VP8EncStartAlpha(tls, enc) != 0) // possibly done in parallel
  39313 		if !((*VP8Encoder)(unsafe.Pointer(enc)).Fuse_tokens != 0) {
  39314 			ok = libc.BoolInt32(ok != 0 && VP8EncLoop(tls, enc) != 0)
  39315 		} else {
  39316 			ok = libc.BoolInt32(ok != 0 && VP8EncTokenLoop(tls, enc) != 0)
  39317 		}
  39318 		ok = libc.BoolInt32(ok != 0 && VP8EncFinishAlpha(tls, enc) != 0)
  39319 		ok = libc.BoolInt32(ok != 0 && VP8EncWrite(tls, enc) != 0)
  39320 		StoreStats(tls, enc)
  39321 		if !(ok != 0) {
  39322 			VP8EncFreeBitWriters(tls, enc)
  39323 		}
  39324 		ok = ok & DeleteVP8Encoder(tls, enc) // must always be called, even if !ok
  39325 	} else {
  39326 		// Make sure we have ARGB samples.
  39327 		if (*WebPPicture)(unsafe.Pointer(pic)).Fargb == libc.UintptrFromInt32(0) && !(WebPPictureYUVAToARGB(tls, pic) != 0) {
  39328 			return 0
  39329 		}
  39330 		if !((*WebPConfig)(unsafe.Pointer(config)).Fexact != 0) {
  39331 			WebPReplaceTransparentPixels(tls, pic, uint32(0x000000))
  39332 		}
  39333 		ok = VP8LEncodeImage(tls, config, pic) // Sets pic->error in case of problem.
  39334 	}
  39335 	return ok
  39336 }
  39337 
  39338 const VP8L_LOG8_WBITS = 4
  39339 
  39340 // Copyright 2010 Google Inc. All Rights Reserved.
  39341 //
  39342 // Use of this source code is governed by a BSD-style license
  39343 // that can be found in the COPYING file in the root of the source
  39344 // tree. An additional intellectual property rights grant can be found
  39345 // in the file PATENTS. All contributing project authors may
  39346 // be found in the AUTHORS file in the root of the source tree.
  39347 // -----------------------------------------------------------------------------
  39348 //
  39349 // Boolean decoder
  39350 //
  39351 // Author: Skal (pascal.massimino@gmail.com)
  39352 //         Vikas Arora (vikaas.arora@gmail.com)
  39353 
  39354 // Copyright 2014 Google Inc. All Rights Reserved.
  39355 //
  39356 // Use of this source code is governed by a BSD-style license
  39357 // that can be found in the COPYING file in the root of the source
  39358 // tree. An additional intellectual property rights grant can be found
  39359 // in the file PATENTS. All contributing project authors may
  39360 // be found in the AUTHORS file in the root of the source tree.
  39361 // -----------------------------------------------------------------------------
  39362 //
  39363 // Endian related functions.
  39364 
  39365 // Copyright 2012 Google Inc. All Rights Reserved.
  39366 //
  39367 // Use of this source code is governed by a BSD-style license
  39368 // that can be found in the COPYING file in the root of the source
  39369 // tree. An additional intellectual property rights grant can be found
  39370 // in the file PATENTS. All contributing project authors may
  39371 // be found in the AUTHORS file in the root of the source tree.
  39372 // -----------------------------------------------------------------------------
  39373 //
  39374 // Misc. common utility functions
  39375 //
  39376 // Authors: Skal (pascal.massimino@gmail.com)
  39377 //          Urvang (urvang@google.com)
  39378 
  39379 //------------------------------------------------------------------------------
  39380 // VP8BitReader
  39381 
  39382 func VP8BitReaderSetBuffer(tls *libc.TLS, br uintptr, start uintptr, size size_t) {
  39383 	var v1 uintptr
  39384 	_ = v1
  39385 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf = start
  39386 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end = start + uintptr(size)
  39387 	if size >= uint64(8) {
  39388 		v1 = start + uintptr(size) - uintptr(8) + uintptr(1)
  39389 	} else {
  39390 		v1 = start
  39391 	}
  39392 	(*VP8BitReader)(unsafe.Pointer(br)).Fbuf_max = v1
  39393 }
  39394 
  39395 func VP8InitBitReader(tls *libc.TLS, br1 uintptr, start uintptr, size size_t) {
  39396 	bp := tls.Alloc(16)
  39397 	defer tls.Free(16)
  39398 	var bits bit_t
  39399 	var v1 uintptr
  39400 	var v2 uint64_t
  39401 	var _ /* in_bits at bp+0 */ lbit_t
  39402 	_, _, _ = bits, v1, v2
  39403 	// limit ensured by format and upstream checks
  39404 	(*VP8BitReader)(unsafe.Pointer(br1)).Frange1 = libc.Uint32FromInt32(libc.Int32FromInt32(255) - libc.Int32FromInt32(1))
  39405 	(*VP8BitReader)(unsafe.Pointer(br1)).Fvalue = uint64(0)
  39406 	(*VP8BitReader)(unsafe.Pointer(br1)).Fbits = -int32(8) // to load the very first 8bits
  39407 	(*VP8BitReader)(unsafe.Pointer(br1)).Feof = 0
  39408 	VP8BitReaderSetBuffer(tls, br1, start, size)
  39409 	v1 = br1
  39410 	if (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf_max {
  39411 		libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v1)).Fbuf, uint64(8))
  39412 		**(**uintptr)(__ccgo_up(v1 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39413 		v2 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39414 		goto _3
  39415 	_3:
  39416 		bits = v2
  39417 		bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39418 		(*VP8BitReader)(unsafe.Pointer(v1)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v1)).Fvalue<<libc.Int32FromInt32(BITS)
  39419 		**(**int32)(__ccgo_up(v1 + 12)) += int32(BITS)
  39420 	} else {
  39421 		VP8LoadFinalBytes(tls, v1)
  39422 	}
  39423 }
  39424 
  39425 func VP8RemapBitReader(tls *libc.TLS, br uintptr, offset ptrdiff_t) {
  39426 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf != libc.UintptrFromInt32(0) {
  39427 		**(**uintptr)(__ccgo_up(br + 16)) += uintptr(offset)
  39428 		**(**uintptr)(__ccgo_up(br + 24)) += uintptr(offset)
  39429 		**(**uintptr)(__ccgo_up(br + 32)) += uintptr(offset)
  39430 	}
  39431 }
  39432 
  39433 func VP8LoadFinalBytes(tls *libc.TLS, br uintptr) {
  39434 	var v1, v2 uintptr
  39435 	_, _ = v1, v2
  39436 	// Only read 8bits at a time
  39437 	if (*VP8BitReader)(unsafe.Pointer(br)).Fbuf < (*VP8BitReader)(unsafe.Pointer(br)).Fbuf_end {
  39438 		**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39439 		v2 = br + 16
  39440 		v1 = *(*uintptr)(unsafe.Pointer(v2))
  39441 		*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  39442 		(*VP8BitReader)(unsafe.Pointer(br)).Fvalue = uint64(**(**uint8_t)(__ccgo_up(v1))) | (*VP8BitReader)(unsafe.Pointer(br)).Fvalue<<libc.Int32FromInt32(8)
  39443 	} else {
  39444 		if !((*VP8BitReader)(unsafe.Pointer(br)).Feof != 0) {
  39445 			**(**bit_t)(__ccgo_up(br)) <<= uint64(8)
  39446 			**(**int32)(__ccgo_up(br + 12)) += int32(8)
  39447 			(*VP8BitReader)(unsafe.Pointer(br)).Feof = int32(1)
  39448 		} else {
  39449 			(*VP8BitReader)(unsafe.Pointer(br)).Fbits = 0 // This is to avoid undefined behaviour with shifts.
  39450 		}
  39451 	}
  39452 }
  39453 
  39454 //------------------------------------------------------------------------------
  39455 // Higher-level calls
  39456 
  39457 func VP8GetValue(tls *libc.TLS, br2 uintptr, bits1 int32) (r uint32_t) {
  39458 	bp := tls.Alloc(16)
  39459 	defer tls.Free(16)
  39460 	var bit, pos, shift, v1, v6, v8 int32
  39461 	var bits bit_t
  39462 	var range1, split, value range_t
  39463 	var v uint32_t
  39464 	var v2, v3 uintptr
  39465 	var v4 uint64_t
  39466 	var _ /* in_bits at bp+0 */ lbit_t
  39467 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bit, bits, pos, range1, shift, split, v, value, v1, v2, v3, v4, v6, v8
  39468 	v = uint32(0)
  39469 	for {
  39470 		v1 = bits1
  39471 		bits1 = bits1 - 1
  39472 		if !(v1 > 0) {
  39473 			break
  39474 		}
  39475 		v2 = br2
  39476 		range1 = (*VP8BitReader)(unsafe.Pointer(v2)).Frange1
  39477 		if (*VP8BitReader)(unsafe.Pointer(v2)).Fbits < libc.Int32FromInt32(0) {
  39478 			v3 = v2
  39479 			if (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf < (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf_max {
  39480 				libc.Xmemcpy(tls, bp, (*VP8BitReader)(unsafe.Pointer(v3)).Fbuf, uint64(8))
  39481 				**(**uintptr)(__ccgo_up(v3 + 16)) += uintptr(libc.Int32FromInt32(BITS) >> libc.Int32FromInt32(3))
  39482 				v4 = libc.X__builtin_bswap64(tls, **(**lbit_t)(__ccgo_up(bp)))
  39483 				goto _5
  39484 			_5:
  39485 				bits = v4
  39486 				bits = bits >> libc.Uint64FromInt32(libc.Int32FromInt32(64)-libc.Int32FromInt32(BITS))
  39487 				(*VP8BitReader)(unsafe.Pointer(v3)).Fvalue = bits | (*VP8BitReader)(unsafe.Pointer(v3)).Fvalue<<libc.Int32FromInt32(BITS)
  39488 				**(**int32)(__ccgo_up(v3 + 12)) += int32(BITS)
  39489 			} else {
  39490 				VP8LoadFinalBytes(tls, v3)
  39491 			}
  39492 		}
  39493 		pos = (*VP8BitReader)(unsafe.Pointer(v2)).Fbits
  39494 		split = range1 * libc.Uint32FromInt32(int32(0x80)) >> int32(8)
  39495 		value = uint32((*VP8BitReader)(unsafe.Pointer(v2)).Fvalue >> pos)
  39496 		bit = libc.BoolInt32(value > split)
  39497 		if bit != 0 {
  39498 			range1 = range1 - split
  39499 			**(**bit_t)(__ccgo_up(v2)) -= uint64(split+libc.Uint32FromInt32(1)) << pos
  39500 		} else {
  39501 			range1 = split + uint32(1)
  39502 		}
  39503 		v6 = int32(31) ^ libc.X__builtin_clz(tls, range1)
  39504 		goto _7
  39505 	_7:
  39506 		shift = int32(7) ^ v6
  39507 		range1 = range1 << libc.Uint32FromInt32(shift)
  39508 		**(**int32)(__ccgo_up(v2 + 12)) -= shift
  39509 		(*VP8BitReader)(unsafe.Pointer(v2)).Frange1 = range1 - uint32(1)
  39510 		v8 = bit
  39511 		goto _9
  39512 	_9:
  39513 		v = v | libc.Uint32FromInt32(v8<<bits1)
  39514 	}
  39515 	return v
  39516 }
  39517 
  39518 func VP8GetSignedValue(tls *libc.TLS, br uintptr, bits int32) (r int32_t) {
  39519 	var value, v1 int32
  39520 	_, _ = value, v1
  39521 	value = libc.Int32FromUint32(VP8GetValue(tls, br, bits))
  39522 	if VP8GetValue(tls, br, int32(1)) != 0 {
  39523 		v1 = -value
  39524 	} else {
  39525 		v1 = value
  39526 	}
  39527 	return v1
  39528 }
  39529 
  39530 //------------------------------------------------------------------------------
  39531 // VP8LBitReader
  39532 
  39533 var kBitMask = [25]uint32_t{
  39534 	1:  uint32(0x000001),
  39535 	2:  uint32(0x000003),
  39536 	3:  uint32(0x000007),
  39537 	4:  uint32(0x00000f),
  39538 	5:  uint32(0x00001f),
  39539 	6:  uint32(0x00003f),
  39540 	7:  uint32(0x00007f),
  39541 	8:  uint32(0x0000ff),
  39542 	9:  uint32(0x0001ff),
  39543 	10: uint32(0x0003ff),
  39544 	11: uint32(0x0007ff),
  39545 	12: uint32(0x000fff),
  39546 	13: uint32(0x001fff),
  39547 	14: uint32(0x003fff),
  39548 	15: uint32(0x007fff),
  39549 	16: uint32(0x00ffff),
  39550 	17: uint32(0x01ffff),
  39551 	18: uint32(0x03ffff),
  39552 	19: uint32(0x07ffff),
  39553 	20: uint32(0x0fffff),
  39554 	21: uint32(0x1fffff),
  39555 	22: uint32(0x3fffff),
  39556 	23: uint32(0x7fffff),
  39557 	24: uint32(0xffffff),
  39558 }
  39559 
  39560 func VP8LInitBitReader(tls *libc.TLS, br uintptr, start uintptr, length size_t) {
  39561 	var i size_t
  39562 	var value vp8l_val_t
  39563 	_, _ = i, value
  39564 	value = uint64(0)
  39565 	// can't happen with a RIFF chunk.
  39566 	(*VP8LBitReader)(unsafe.Pointer(br)).Flen1 = length
  39567 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = uint64(0)
  39568 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0
  39569 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = 0
  39570 	if length > uint64(8) {
  39571 		length = uint64(8)
  39572 	}
  39573 	i = uint64(0)
  39574 	for {
  39575 		if !(i < length) {
  39576 			break
  39577 		}
  39578 		value = value | uint64(**(**uint8_t)(__ccgo_up(start + uintptr(i))))<<(uint64(8)*i)
  39579 		goto _1
  39580 	_1:
  39581 		;
  39582 		i = i + 1
  39583 	}
  39584 	(*VP8LBitReader)(unsafe.Pointer(br)).Fval = value
  39585 	(*VP8LBitReader)(unsafe.Pointer(br)).Fpos = length
  39586 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbuf = start
  39587 }
  39588 
  39589 func VP8LBitReaderSetBuffer(tls *libc.TLS, br1 uintptr, buf uintptr, len1 size_t) {
  39590 	var v1 uintptr
  39591 	var v2 int32
  39592 	var v4 bool
  39593 	_, _, _ = v1, v2, v4
  39594 	// can't happen with a RIFF chunk.
  39595 	(*VP8LBitReader)(unsafe.Pointer(br1)).Fbuf = buf
  39596 	(*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 = len1
  39597 	// 'pos' > 'len' should be considered a param error.
  39598 	if v4 = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos > (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1; !v4 {
  39599 		v1 = br1
  39600 		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))
  39601 		goto _3
  39602 	_3:
  39603 	}
  39604 	(*VP8LBitReader)(unsafe.Pointer(br1)).Feos = libc.BoolInt32(v4 || v2 != 0)
  39605 }
  39606 
  39607 func VP8LSetEndOfStream(tls *libc.TLS, br uintptr) {
  39608 	(*VP8LBitReader)(unsafe.Pointer(br)).Feos = int32(1)
  39609 	(*VP8LBitReader)(unsafe.Pointer(br)).Fbit_pos = 0 // To avoid undefined behaviour with shifts.
  39610 }
  39611 
  39612 // C documentation
  39613 //
  39614 //	// If not at EOS, reload up to VP8L_LBITS byte-by-byte
  39615 func ShiftBytes(tls *libc.TLS, br1 uintptr) {
  39616 	var v1 uintptr
  39617 	var v2 int32
  39618 	_, _ = v1, v2
  39619 	for (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos >= int32(8) && (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos < (*VP8LBitReader)(unsafe.Pointer(br1)).Flen1 {
  39620 		**(**vp8l_val_t)(__ccgo_up(br1)) >>= uint64(8)
  39621 		**(**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))
  39622 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fpos = (*VP8LBitReader)(unsafe.Pointer(br1)).Fpos + 1
  39623 		**(**int32)(__ccgo_up(br1 + 32)) -= int32(8)
  39624 	}
  39625 	v1 = br1
  39626 	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))
  39627 	goto _3
  39628 _3:
  39629 	if v2 != 0 {
  39630 		VP8LSetEndOfStream(tls, br1)
  39631 	}
  39632 }
  39633 
  39634 func VP8LDoFillBitWindow(tls *libc.TLS, br uintptr) {
  39635 	bp := tls.Alloc(16)
  39636 	defer tls.Free(16)
  39637 	var v1 uint32_t
  39638 	var _ /* A at bp+0 */ uint32_t
  39639 	_ = v1
  39640 	if (*VP8LBitReader)(unsafe.Pointer(br)).Fpos+uint64(8) < (*VP8LBitReader)(unsafe.Pointer(br)).Flen1 {
  39641 		**(**vp8l_val_t)(__ccgo_up(br)) >>= uint64(VP8L_WBITS)
  39642 		**(**int32)(__ccgo_up(br + 32)) -= int32(VP8L_WBITS)
  39643 		libc.Xmemcpy(tls, bp, (*VP8LBitReader)(unsafe.Pointer(br)).Fbuf+uintptr((*VP8LBitReader)(unsafe.Pointer(br)).Fpos), uint64(4))
  39644 		v1 = **(**uint32_t)(__ccgo_up(bp))
  39645 		goto _2
  39646 	_2:
  39647 		**(**vp8l_val_t)(__ccgo_up(br)) |= uint64(v1) << (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(VP8L_WBITS))
  39648 		**(**size_t)(__ccgo_up(br + 24)) += uint64(VP8L_LOG8_WBITS)
  39649 		return
  39650 	}
  39651 	ShiftBytes(tls, br) // Slow path.
  39652 }
  39653 
  39654 func VP8LReadBits(tls *libc.TLS, br1 uintptr, n_bits int32) (r uint32_t) {
  39655 	var new_bits int32
  39656 	var val, v2 uint32_t
  39657 	var v1 uintptr
  39658 	_, _, _, _ = new_bits, val, v1, v2
  39659 	// Flag an error if end_of_stream or n_bits is more than allowed limit.
  39660 	if !((*VP8LBitReader)(unsafe.Pointer(br1)).Feos != 0) && n_bits <= int32(VP8L_MAX_NUM_BIT_READ) {
  39661 		v1 = br1
  39662 		v2 = uint32((*VP8LBitReader)(unsafe.Pointer(v1)).Fval >> ((*VP8LBitReader)(unsafe.Pointer(v1)).Fbit_pos & (libc.Int32FromInt32(VP8L_LBITS) - libc.Int32FromInt32(1))))
  39663 		goto _3
  39664 	_3:
  39665 		val = v2 & kBitMask[n_bits]
  39666 		new_bits = (*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos + n_bits
  39667 		(*VP8LBitReader)(unsafe.Pointer(br1)).Fbit_pos = new_bits
  39668 		ShiftBytes(tls, br1)
  39669 		return val
  39670 	} else {
  39671 		VP8LSetEndOfStream(tls, br1)
  39672 		return uint32(0)
  39673 	}
  39674 	return r
  39675 }
  39676 
  39677 const MIN_EXTRA_SIZE = 32768
  39678 
  39679 //------------------------------------------------------------------------------
  39680 
  39681 //------------------------------------------------------------------------------
  39682 // VP8BitWriter
  39683 
  39684 func BitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  39685 	var needed_size, new_size size_t
  39686 	var needed_size_64b uint64_t
  39687 	var new_buf uintptr
  39688 	_, _, _, _ = needed_size, needed_size_64b, new_buf, new_size
  39689 	needed_size_64b = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos + extra_size
  39690 	needed_size = needed_size_64b
  39691 	if needed_size_64b != needed_size {
  39692 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39693 		return 0
  39694 	}
  39695 	if needed_size <= (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos {
  39696 		return int32(1)
  39697 	}
  39698 	// If the following line wraps over 32bit, the test just after will catch it.
  39699 	new_size = uint64(2) * (*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos
  39700 	if new_size < needed_size {
  39701 		new_size = needed_size
  39702 	}
  39703 	if new_size < uint64(1024) {
  39704 		new_size = uint64(1024)
  39705 	}
  39706 	new_buf = WebPSafeMalloc(tls, uint64(1), new_size)
  39707 	if new_buf == libc.UintptrFromInt32(0) {
  39708 		(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  39709 		return 0
  39710 	}
  39711 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos > uint64(0) {
  39712 		libc.Xmemcpy(tls, new_buf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf, (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos)
  39713 	}
  39714 	WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  39715 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = new_buf
  39716 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = new_size
  39717 	return int32(1)
  39718 }
  39719 
  39720 func Flush(tls *libc.TLS, bw uintptr) {
  39721 	var bits int32_t
  39722 	var pos, v3 size_t
  39723 	var s, value, v1 int32
  39724 	_, _, _, _, _, _ = bits, pos, s, value, v1, v3
  39725 	s = int32(8) + (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits
  39726 	bits = (*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue >> s
  39727 	**(**int32_t)(__ccgo_up(bw + 4)) -= bits << s
  39728 	**(**int32)(__ccgo_up(bw + 12)) -= int32(8)
  39729 	if bits&int32(0xff) != int32(0xff) {
  39730 		pos = (*VP8BitWriter)(unsafe.Pointer(bw)).Fpos
  39731 		if !(BitWriterResize(tls, bw, libc.Uint64FromInt32((*VP8BitWriter)(unsafe.Pointer(bw)).Frun+int32(1))) != 0) {
  39732 			return
  39733 		}
  39734 		if bits&int32(0x100) != 0 { // overflow -> propagate carry over pending 0xff's
  39735 			if pos > uint64(0) {
  39736 				**(**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
  39737 			}
  39738 		}
  39739 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0 {
  39740 			if bits&int32(0x100) != 0 {
  39741 				v1 = 0x00
  39742 			} else {
  39743 				v1 = int32(0xff)
  39744 			}
  39745 			value = v1
  39746 			for {
  39747 				if !((*VP8BitWriter)(unsafe.Pointer(bw)).Frun > 0) {
  39748 					break
  39749 				}
  39750 				v3 = pos
  39751 				pos = pos + 1
  39752 				**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = libc.Uint8FromInt32(value)
  39753 				goto _2
  39754 			_2:
  39755 				;
  39756 				(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun - 1
  39757 			}
  39758 		}
  39759 		v3 = pos
  39760 		pos = pos + 1
  39761 		**(**uint8_t)(__ccgo_up((*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(v3))) = libc.Uint8FromInt32(bits & int32(0xff))
  39762 		(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = pos
  39763 	} else {
  39764 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = (*VP8BitWriter)(unsafe.Pointer(bw)).Frun + 1 // delay writing of bytes 0xff, pending eventual carry.
  39765 	}
  39766 }
  39767 
  39768 //------------------------------------------------------------------------------
  39769 // renormalization
  39770 
  39771 var kNorm = [128]uint8_t{
  39772 	0:   uint8(7),
  39773 	1:   uint8(6),
  39774 	2:   uint8(6),
  39775 	3:   uint8(5),
  39776 	4:   uint8(5),
  39777 	5:   uint8(5),
  39778 	6:   uint8(5),
  39779 	7:   uint8(4),
  39780 	8:   uint8(4),
  39781 	9:   uint8(4),
  39782 	10:  uint8(4),
  39783 	11:  uint8(4),
  39784 	12:  uint8(4),
  39785 	13:  uint8(4),
  39786 	14:  uint8(4),
  39787 	15:  uint8(3),
  39788 	16:  uint8(3),
  39789 	17:  uint8(3),
  39790 	18:  uint8(3),
  39791 	19:  uint8(3),
  39792 	20:  uint8(3),
  39793 	21:  uint8(3),
  39794 	22:  uint8(3),
  39795 	23:  uint8(3),
  39796 	24:  uint8(3),
  39797 	25:  uint8(3),
  39798 	26:  uint8(3),
  39799 	27:  uint8(3),
  39800 	28:  uint8(3),
  39801 	29:  uint8(3),
  39802 	30:  uint8(3),
  39803 	31:  uint8(2),
  39804 	32:  uint8(2),
  39805 	33:  uint8(2),
  39806 	34:  uint8(2),
  39807 	35:  uint8(2),
  39808 	36:  uint8(2),
  39809 	37:  uint8(2),
  39810 	38:  uint8(2),
  39811 	39:  uint8(2),
  39812 	40:  uint8(2),
  39813 	41:  uint8(2),
  39814 	42:  uint8(2),
  39815 	43:  uint8(2),
  39816 	44:  uint8(2),
  39817 	45:  uint8(2),
  39818 	46:  uint8(2),
  39819 	47:  uint8(2),
  39820 	48:  uint8(2),
  39821 	49:  uint8(2),
  39822 	50:  uint8(2),
  39823 	51:  uint8(2),
  39824 	52:  uint8(2),
  39825 	53:  uint8(2),
  39826 	54:  uint8(2),
  39827 	55:  uint8(2),
  39828 	56:  uint8(2),
  39829 	57:  uint8(2),
  39830 	58:  uint8(2),
  39831 	59:  uint8(2),
  39832 	60:  uint8(2),
  39833 	61:  uint8(2),
  39834 	62:  uint8(2),
  39835 	63:  uint8(1),
  39836 	64:  uint8(1),
  39837 	65:  uint8(1),
  39838 	66:  uint8(1),
  39839 	67:  uint8(1),
  39840 	68:  uint8(1),
  39841 	69:  uint8(1),
  39842 	70:  uint8(1),
  39843 	71:  uint8(1),
  39844 	72:  uint8(1),
  39845 	73:  uint8(1),
  39846 	74:  uint8(1),
  39847 	75:  uint8(1),
  39848 	76:  uint8(1),
  39849 	77:  uint8(1),
  39850 	78:  uint8(1),
  39851 	79:  uint8(1),
  39852 	80:  uint8(1),
  39853 	81:  uint8(1),
  39854 	82:  uint8(1),
  39855 	83:  uint8(1),
  39856 	84:  uint8(1),
  39857 	85:  uint8(1),
  39858 	86:  uint8(1),
  39859 	87:  uint8(1),
  39860 	88:  uint8(1),
  39861 	89:  uint8(1),
  39862 	90:  uint8(1),
  39863 	91:  uint8(1),
  39864 	92:  uint8(1),
  39865 	93:  uint8(1),
  39866 	94:  uint8(1),
  39867 	95:  uint8(1),
  39868 	96:  uint8(1),
  39869 	97:  uint8(1),
  39870 	98:  uint8(1),
  39871 	99:  uint8(1),
  39872 	100: uint8(1),
  39873 	101: uint8(1),
  39874 	102: uint8(1),
  39875 	103: uint8(1),
  39876 	104: uint8(1),
  39877 	105: uint8(1),
  39878 	106: uint8(1),
  39879 	107: uint8(1),
  39880 	108: uint8(1),
  39881 	109: uint8(1),
  39882 	110: uint8(1),
  39883 	111: uint8(1),
  39884 	112: uint8(1),
  39885 	113: uint8(1),
  39886 	114: uint8(1),
  39887 	115: uint8(1),
  39888 	116: uint8(1),
  39889 	117: uint8(1),
  39890 	118: uint8(1),
  39891 	119: uint8(1),
  39892 	120: uint8(1),
  39893 	121: uint8(1),
  39894 	122: uint8(1),
  39895 	123: uint8(1),
  39896 	124: uint8(1),
  39897 	125: uint8(1),
  39898 	126: uint8(1),
  39899 }
  39900 
  39901 // C documentation
  39902 //
  39903 //	// range = ((range + 1) << kVP8Log2Range[range]) - 1
  39904 var kNewRange = [128]uint8_t{
  39905 	0:   uint8(127),
  39906 	1:   uint8(127),
  39907 	2:   uint8(191),
  39908 	3:   uint8(127),
  39909 	4:   uint8(159),
  39910 	5:   uint8(191),
  39911 	6:   uint8(223),
  39912 	7:   uint8(127),
  39913 	8:   uint8(143),
  39914 	9:   uint8(159),
  39915 	10:  uint8(175),
  39916 	11:  uint8(191),
  39917 	12:  uint8(207),
  39918 	13:  uint8(223),
  39919 	14:  uint8(239),
  39920 	15:  uint8(127),
  39921 	16:  uint8(135),
  39922 	17:  uint8(143),
  39923 	18:  uint8(151),
  39924 	19:  uint8(159),
  39925 	20:  uint8(167),
  39926 	21:  uint8(175),
  39927 	22:  uint8(183),
  39928 	23:  uint8(191),
  39929 	24:  uint8(199),
  39930 	25:  uint8(207),
  39931 	26:  uint8(215),
  39932 	27:  uint8(223),
  39933 	28:  uint8(231),
  39934 	29:  uint8(239),
  39935 	30:  uint8(247),
  39936 	31:  uint8(127),
  39937 	32:  uint8(131),
  39938 	33:  uint8(135),
  39939 	34:  uint8(139),
  39940 	35:  uint8(143),
  39941 	36:  uint8(147),
  39942 	37:  uint8(151),
  39943 	38:  uint8(155),
  39944 	39:  uint8(159),
  39945 	40:  uint8(163),
  39946 	41:  uint8(167),
  39947 	42:  uint8(171),
  39948 	43:  uint8(175),
  39949 	44:  uint8(179),
  39950 	45:  uint8(183),
  39951 	46:  uint8(187),
  39952 	47:  uint8(191),
  39953 	48:  uint8(195),
  39954 	49:  uint8(199),
  39955 	50:  uint8(203),
  39956 	51:  uint8(207),
  39957 	52:  uint8(211),
  39958 	53:  uint8(215),
  39959 	54:  uint8(219),
  39960 	55:  uint8(223),
  39961 	56:  uint8(227),
  39962 	57:  uint8(231),
  39963 	58:  uint8(235),
  39964 	59:  uint8(239),
  39965 	60:  uint8(243),
  39966 	61:  uint8(247),
  39967 	62:  uint8(251),
  39968 	63:  uint8(127),
  39969 	64:  uint8(129),
  39970 	65:  uint8(131),
  39971 	66:  uint8(133),
  39972 	67:  uint8(135),
  39973 	68:  uint8(137),
  39974 	69:  uint8(139),
  39975 	70:  uint8(141),
  39976 	71:  uint8(143),
  39977 	72:  uint8(145),
  39978 	73:  uint8(147),
  39979 	74:  uint8(149),
  39980 	75:  uint8(151),
  39981 	76:  uint8(153),
  39982 	77:  uint8(155),
  39983 	78:  uint8(157),
  39984 	79:  uint8(159),
  39985 	80:  uint8(161),
  39986 	81:  uint8(163),
  39987 	82:  uint8(165),
  39988 	83:  uint8(167),
  39989 	84:  uint8(169),
  39990 	85:  uint8(171),
  39991 	86:  uint8(173),
  39992 	87:  uint8(175),
  39993 	88:  uint8(177),
  39994 	89:  uint8(179),
  39995 	90:  uint8(181),
  39996 	91:  uint8(183),
  39997 	92:  uint8(185),
  39998 	93:  uint8(187),
  39999 	94:  uint8(189),
  40000 	95:  uint8(191),
  40001 	96:  uint8(193),
  40002 	97:  uint8(195),
  40003 	98:  uint8(197),
  40004 	99:  uint8(199),
  40005 	100: uint8(201),
  40006 	101: uint8(203),
  40007 	102: uint8(205),
  40008 	103: uint8(207),
  40009 	104: uint8(209),
  40010 	105: uint8(211),
  40011 	106: uint8(213),
  40012 	107: uint8(215),
  40013 	108: uint8(217),
  40014 	109: uint8(219),
  40015 	110: uint8(221),
  40016 	111: uint8(223),
  40017 	112: uint8(225),
  40018 	113: uint8(227),
  40019 	114: uint8(229),
  40020 	115: uint8(231),
  40021 	116: uint8(233),
  40022 	117: uint8(235),
  40023 	118: uint8(237),
  40024 	119: uint8(239),
  40025 	120: uint8(241),
  40026 	121: uint8(243),
  40027 	122: uint8(245),
  40028 	123: uint8(247),
  40029 	124: uint8(249),
  40030 	125: uint8(251),
  40031 	126: uint8(253),
  40032 	127: uint8(127),
  40033 }
  40034 
  40035 func VP8PutBit(tls *libc.TLS, bw uintptr, bit int32, prob int32) (r int32) {
  40036 	var shift, split int32
  40037 	_, _ = shift, split
  40038 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 * prob >> int32(8)
  40039 	if bit != 0 {
  40040 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  40041 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  40042 	} else {
  40043 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  40044 	}
  40045 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) { // emit 'shift' bits out and renormalize
  40046 		shift = libc.Int32FromUint8(kNorm[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40047 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromUint8(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40048 		**(**int32_t)(__ccgo_up(bw + 4)) <<= shift
  40049 		**(**int32)(__ccgo_up(bw + 12)) += shift
  40050 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  40051 			Flush(tls, bw)
  40052 		}
  40053 	}
  40054 	return bit
  40055 }
  40056 
  40057 func VP8PutBitUniform(tls *libc.TLS, bw uintptr, bit int32) (r int32) {
  40058 	var split int32
  40059 	_ = split
  40060 	split = (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 >> int32(1)
  40061 	if bit != 0 {
  40062 		**(**int32_t)(__ccgo_up(bw + 4)) += split + int32(1)
  40063 		**(**int32_t)(__ccgo_up(bw)) -= split + int32(1)
  40064 	} else {
  40065 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = split
  40066 	}
  40067 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 < int32(127) {
  40068 		(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromUint8(kNewRange[(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1])
  40069 		**(**int32_t)(__ccgo_up(bw + 4)) <<= int32(1)
  40070 		**(**int32)(__ccgo_up(bw + 12)) += int32(1)
  40071 		if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits > 0 {
  40072 			Flush(tls, bw)
  40073 		}
  40074 	}
  40075 	return bit
  40076 }
  40077 
  40078 func VP8PutBits(tls *libc.TLS, bw uintptr, value uint32_t, nb_bits int32) {
  40079 	var mask uint32_t
  40080 	_ = mask
  40081 	mask = uint32(1) << (nb_bits - int32(1))
  40082 	for {
  40083 		if !(mask != 0) {
  40084 			break
  40085 		}
  40086 		VP8PutBitUniform(tls, bw, libc.Int32FromUint32(value&mask))
  40087 		goto _1
  40088 	_1:
  40089 		;
  40090 		mask = mask >> uint32(1)
  40091 	}
  40092 }
  40093 
  40094 func VP8PutSignedBits(tls *libc.TLS, bw uintptr, value int32, nb_bits int32) {
  40095 	if !(VP8PutBitUniform(tls, bw, libc.BoolInt32(value != 0)) != 0) {
  40096 		return
  40097 	}
  40098 	if value < 0 {
  40099 		VP8PutBits(tls, bw, libc.Uint32FromInt32(-value<<int32(1)|int32(1)), nb_bits+int32(1))
  40100 	} else {
  40101 		VP8PutBits(tls, bw, libc.Uint32FromInt32(value<<int32(1)), nb_bits+int32(1))
  40102 	}
  40103 }
  40104 
  40105 //------------------------------------------------------------------------------
  40106 
  40107 func VP8BitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  40108 	var v1 int32
  40109 	_ = v1
  40110 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frange1 = libc.Int32FromInt32(255) - libc.Int32FromInt32(1)
  40111 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fvalue = 0
  40112 	(*VP8BitWriter)(unsafe.Pointer(bw)).Frun = 0
  40113 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = -int32(8)
  40114 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fpos = uint64(0)
  40115 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fmax_pos = uint64(0)
  40116 	(*VP8BitWriter)(unsafe.Pointer(bw)).Ferror1 = 0
  40117 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf = libc.UintptrFromInt32(0)
  40118 	if expected_size > uint64(0) {
  40119 		v1 = BitWriterResize(tls, bw, expected_size)
  40120 	} else {
  40121 		v1 = int32(1)
  40122 	}
  40123 	return v1
  40124 }
  40125 
  40126 func VP8BitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40127 	VP8PutBits(tls, bw, uint32(0), int32(9)-(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits)
  40128 	(*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits = 0 // pad with zeroes
  40129 	Flush(tls, bw)
  40130 	return (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf
  40131 }
  40132 
  40133 func VP8BitWriterAppend(tls *libc.TLS, bw uintptr, data uintptr, size size_t) (r int32) {
  40134 	if (*VP8BitWriter)(unsafe.Pointer(bw)).Fnb_bits != -int32(8) {
  40135 		return 0
  40136 	} // Flush() must have been called
  40137 	if !(BitWriterResize(tls, bw, size) != 0) {
  40138 		return 0
  40139 	}
  40140 	libc.Xmemcpy(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf+uintptr((*VP8BitWriter)(unsafe.Pointer(bw)).Fpos), data, size)
  40141 	**(**size_t)(__ccgo_up(bw + 24)) += size
  40142 	return int32(1)
  40143 }
  40144 
  40145 func VP8BitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  40146 	if bw != libc.UintptrFromInt32(0) {
  40147 		WebPSafeFree(tls, (*VP8BitWriter)(unsafe.Pointer(bw)).Fbuf)
  40148 		libc.Xmemset(tls, bw, 0, uint64(48))
  40149 	}
  40150 }
  40151 
  40152 //------------------------------------------------------------------------------
  40153 // VP8LBitWriter
  40154 
  40155 // This is the minimum amount of size the memory buffer is guaranteed to grow
  40156 // when extra space is needed.
  40157 
  40158 // C documentation
  40159 //
  40160 //	// Returns 1 on success.
  40161 func VP8LBitWriterResize(tls *libc.TLS, bw uintptr, extra_size size_t) (r int32) {
  40162 	var allocated_buf uintptr
  40163 	var allocated_size, current_size, max_bytes, size_required size_t
  40164 	var size_required_64b uint64_t
  40165 	_, _, _, _, _, _ = allocated_buf, allocated_size, current_size, max_bytes, size_required, size_required_64b
  40166 	max_bytes = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  40167 	current_size = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf))
  40168 	size_required_64b = current_size + extra_size
  40169 	size_required = size_required_64b
  40170 	if size_required != size_required_64b {
  40171 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40172 		return 0
  40173 	}
  40174 	if max_bytes > uint64(0) && size_required <= max_bytes {
  40175 		return int32(1)
  40176 	}
  40177 	allocated_size = uint64(3) * max_bytes >> int32(1)
  40178 	if allocated_size < size_required {
  40179 		allocated_size = size_required
  40180 	}
  40181 	// make allocated size multiple of 1k
  40182 	allocated_size = (allocated_size>>libc.Int32FromInt32(10) + libc.Uint64FromInt32(1)) << libc.Int32FromInt32(10)
  40183 	allocated_buf = WebPSafeMalloc(tls, uint64(1), allocated_size)
  40184 	if allocated_buf == libc.UintptrFromInt32(0) {
  40185 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40186 		return 0
  40187 	}
  40188 	if current_size > uint64(0) {
  40189 		libc.Xmemcpy(tls, allocated_buf, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf, current_size)
  40190 	}
  40191 	WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  40192 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf = allocated_buf
  40193 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(current_size)
  40194 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fend = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf + uintptr(allocated_size)
  40195 	return int32(1)
  40196 }
  40197 
  40198 func VP8LBitWriterInit(tls *libc.TLS, bw uintptr, expected_size size_t) (r int32) {
  40199 	libc.Xmemset(tls, bw, 0, uint64(40))
  40200 	return VP8LBitWriterResize(tls, bw, expected_size)
  40201 }
  40202 
  40203 func VP8LBitWriterClone(tls *libc.TLS, src uintptr, dst uintptr) (r int32) {
  40204 	var current_size size_t
  40205 	_ = current_size
  40206 	current_size = libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fcur) - int64((*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf))
  40207 	if !(VP8LBitWriterResize(tls, dst, current_size) != 0) {
  40208 		return 0
  40209 	}
  40210 	libc.Xmemcpy(tls, (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf, (*VP8LBitWriter)(unsafe.Pointer(src)).Fbuf, current_size)
  40211 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(src)).Fbits
  40212 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fused = (*VP8LBitWriter)(unsafe.Pointer(src)).Fused
  40213 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(src)).Ferror1
  40214 	(*VP8LBitWriter)(unsafe.Pointer(dst)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(dst)).Fbuf + uintptr(current_size)
  40215 	return int32(1)
  40216 }
  40217 
  40218 func VP8LBitWriterWipeOut(tls *libc.TLS, bw uintptr) {
  40219 	if bw != libc.UintptrFromInt32(0) {
  40220 		WebPSafeFree(tls, (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)
  40221 		libc.Xmemset(tls, bw, 0, uint64(40))
  40222 	}
  40223 }
  40224 
  40225 func VP8LBitWriterReset(tls *libc.TLS, bw_init uintptr, bw uintptr) {
  40226 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fbits
  40227 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Fused
  40228 	(*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))
  40229 	(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = (*VP8LBitWriter)(unsafe.Pointer(bw_init)).Ferror1
  40230 }
  40231 
  40232 func VP8LBitWriterSwap(tls *libc.TLS, src uintptr, dst uintptr) {
  40233 	var tmp VP8LBitWriter
  40234 	_ = tmp
  40235 	tmp = **(**VP8LBitWriter)(__ccgo_up(src))
  40236 	**(**VP8LBitWriter)(__ccgo_up(src)) = **(**VP8LBitWriter)(__ccgo_up(dst))
  40237 	**(**VP8LBitWriter)(__ccgo_up(dst)) = tmp
  40238 }
  40239 
  40240 func VP8LPutBitsFlushBits(tls *libc.TLS, bw uintptr) {
  40241 	var extra_size, v1 uint64_t
  40242 	var v2 int32
  40243 	_, _, _ = extra_size, v1, v2
  40244 	// If needed, make some room by flushing some bits out.
  40245 	if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  40246 		extra_size = uint64(libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768))
  40247 		v1 = extra_size
  40248 		v2 = libc.BoolInt32(v1 == v1)
  40249 		goto _3
  40250 	_3:
  40251 		;
  40252 		if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  40253 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40254 			(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40255 			return
  40256 		}
  40257 	}
  40258 	**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint16((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40259 	**(**uintptr)(__ccgo_up(bw + 16)) += uintptr(VP8L_WRITER_BYTES)
  40260 	**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint32(VP8L_WRITER_BITS)
  40261 	**(**int32)(__ccgo_up(bw + 4)) -= int32(VP8L_WRITER_BITS)
  40262 }
  40263 
  40264 func VP8LPutBitsInternal(tls *libc.TLS, bw uintptr, bits uint32_t, n_bits int32) {
  40265 	var extra_size, v1 uint64_t
  40266 	var lbits vp8l_atype_t
  40267 	var shift, used, v2 int32
  40268 	_, _, _, _, _, _ = extra_size, lbits, shift, used, v1, v2
  40269 	// That's the max we can handle:
  40270 	if n_bits > 0 {
  40271 		lbits = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits
  40272 		used = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused
  40273 		// Special case of overflow handling for 32bit accumulator (2-steps flush).
  40274 		if used+n_bits >= int32(VP8L_WRITER_MAX_BITS) {
  40275 			// Fill up all the VP8L_WRITER_MAX_BITS so it can be flushed out below.
  40276 			shift = int32(VP8L_WRITER_MAX_BITS) - used
  40277 			lbits = lbits | bits<<used
  40278 			used = int32(VP8L_WRITER_MAX_BITS)
  40279 			n_bits = n_bits - shift
  40280 			bits = bits >> libc.Uint32FromInt32(shift)
  40281 		}
  40282 		// If needed, make some room by flushing some bits out.
  40283 		for used >= int32(VP8L_WRITER_BITS) {
  40284 			if (*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur+uintptr(VP8L_WRITER_BYTES) > (*VP8LBitWriter)(unsafe.Pointer(bw)).Fend {
  40285 				extra_size = uint64(libc.Uint64FromInt64(int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fend)-int64((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf)) + uint64(32768))
  40286 				v1 = extra_size
  40287 				v2 = libc.BoolInt32(v1 == v1)
  40288 				goto _3
  40289 			_3:
  40290 				;
  40291 				if !(v2 != 0) || !(VP8LBitWriterResize(tls, bw, extra_size) != 0) {
  40292 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur = (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40293 					(*VP8LBitWriter)(unsafe.Pointer(bw)).Ferror1 = int32(1)
  40294 					return
  40295 				}
  40296 			}
  40297 			**(**vp8l_wtype_t)(__ccgo_up((*VP8LBitWriter)(unsafe.Pointer(bw)).Fcur)) = uint16(lbits)
  40298 			**(**uintptr)(__ccgo_up(bw + 16)) += uintptr(VP8L_WRITER_BYTES)
  40299 			lbits = lbits >> uint32(VP8L_WRITER_BITS)
  40300 			used = used - int32(VP8L_WRITER_BITS)
  40301 		}
  40302 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits = lbits | bits<<used
  40303 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = used + n_bits
  40304 	}
  40305 }
  40306 
  40307 func VP8LBitWriterFinish(tls *libc.TLS, bw uintptr) (r uintptr) {
  40308 	var v1, v2 uintptr
  40309 	_, _ = v1, v2
  40310 	// flush leftover bits
  40311 	if VP8LBitWriterResize(tls, bw, libc.Uint64FromInt32(((*VP8LBitWriter)(unsafe.Pointer(bw)).Fused+int32(7))>>int32(3))) != 0 {
  40312 		for (*VP8LBitWriter)(unsafe.Pointer(bw)).Fused > 0 {
  40313 			v2 = bw + 16
  40314 			v1 = *(*uintptr)(unsafe.Pointer(v2))
  40315 			*(*uintptr)(unsafe.Pointer(v2)) = *(*uintptr)(unsafe.Pointer(v2)) + 1
  40316 			**(**uint8_t)(__ccgo_up(v1)) = uint8((*VP8LBitWriter)(unsafe.Pointer(bw)).Fbits)
  40317 			**(**vp8l_atype_t)(__ccgo_up(bw)) >>= uint32(8)
  40318 			**(**int32)(__ccgo_up(bw + 4)) -= int32(8)
  40319 		}
  40320 		(*VP8LBitWriter)(unsafe.Pointer(bw)).Fused = 0
  40321 	}
  40322 	return (*VP8LBitWriter)(unsafe.Pointer(bw)).Fbuf
  40323 }
  40324 
  40325 var kHashMul12 = uint32(0x1e35a7bd)
  40326 
  40327 //------------------------------------------------------------------------------
  40328 
  40329 //------------------------------------------------------------------------------
  40330 // VP8LColorCache.
  40331 
  40332 func VP8LColorCacheInit(tls *libc.TLS, color_cache uintptr, hash_bits int32) (r int32) {
  40333 	var hash_size int32
  40334 	_ = hash_size
  40335 	hash_size = int32(1) << hash_bits
  40336 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = WebPSafeCalloc(tls, libc.Uint64FromInt32(hash_size), uint64(4))
  40337 	if (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors == libc.UintptrFromInt32(0) {
  40338 		return 0
  40339 	}
  40340 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_shift = int32(32) - hash_bits
  40341 	(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fhash_bits = hash_bits
  40342 	return int32(1)
  40343 }
  40344 
  40345 func VP8LColorCacheClear(tls *libc.TLS, color_cache uintptr) {
  40346 	if color_cache != libc.UintptrFromInt32(0) {
  40347 		WebPSafeFree(tls, (*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors)
  40348 		(*VP8LColorCache)(unsafe.Pointer(color_cache)).Fcolors = libc.UintptrFromInt32(0)
  40349 	}
  40350 }
  40351 
  40352 func VP8LColorCacheCopy(tls *libc.TLS, src uintptr, dst uintptr) {
  40353 	libc.Xmemcpy(tls, (*VP8LColorCache)(unsafe.Pointer(dst)).Fcolors, (*VP8LColorCache)(unsafe.Pointer(src)).Fcolors, libc.Uint64FromUint32(1)<<(*VP8LColorCache)(unsafe.Pointer(dst)).Fhash_bits*uint64(4))
  40354 }
  40355 
  40356 // -----------------------------------------------------------------------------
  40357 // Quick estimate of a potentially interesting filter mode to try.
  40358 
  40359 func GradientPredictor(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  40360 	var g, v1, v2 int32
  40361 	_, _, _ = g, v1, v2
  40362 	g = libc.Int32FromUint8(a) + libc.Int32FromUint8(b) - libc.Int32FromUint8(c)
  40363 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  40364 		v1 = g
  40365 	} else {
  40366 		if g < 0 {
  40367 			v2 = 0
  40368 		} else {
  40369 			v2 = int32(255)
  40370 		}
  40371 		v1 = v2
  40372 	}
  40373 	return v1 // clip to 8bit
  40374 }
  40375 
  40376 func WebPEstimateBestFilter(tls *libc.TLS, data uintptr, width int32, height int32, stride int32) (r WEBP_FILTER_TYPE) {
  40377 	bp := tls.Alloc(256)
  40378 	defer tls.Free(256)
  40379 	var best_filter WEBP_FILTER_TYPE
  40380 	var best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, score int32
  40381 	var p uintptr
  40382 	var _ /* bins at bp+0 */ [4][16]int32
  40383 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_filter, best_score, diff0, diff1, diff2, diff3, filter, grad_pred, i, j, mean, p, score
  40384 	libc.Xmemset(tls, bp, 0, uint64(256))
  40385 	// We only sample every other pixels. That's enough.
  40386 	j = int32(2)
  40387 	for {
  40388 		if !(j < height-int32(1)) {
  40389 			break
  40390 		}
  40391 		p = data + uintptr(j*stride)
  40392 		mean = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  40393 		i = int32(2)
  40394 		for {
  40395 			if !(i < width-int32(1)) {
  40396 				break
  40397 			}
  40398 			diff0 = libc.Xabs(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-mean) >> libc.Int32FromInt32(4)
  40399 			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)
  40400 			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)
  40401 			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)))))
  40402 			diff3 = libc.Xabs(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i))))-grad_pred) >> libc.Int32FromInt32(4)
  40403 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_NONE)*64 + uintptr(diff0)*4)) = int32(1)
  40404 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_HORIZONTAL)*64 + uintptr(diff1)*4)) = int32(1)
  40405 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_VERTICAL)*64 + uintptr(diff2)*4)) = int32(1)
  40406 			**(**int32)(__ccgo_up(bp + uintptr(WEBP_FILTER_GRADIENT)*64 + uintptr(diff3)*4)) = int32(1)
  40407 			mean = (int32(3)*mean + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(i)))) + int32(2)) >> int32(2)
  40408 			goto _2
  40409 		_2:
  40410 			;
  40411 			i = i + int32(2)
  40412 		}
  40413 		goto _1
  40414 	_1:
  40415 		;
  40416 		j = j + int32(2)
  40417 	}
  40418 	best_filter = int32(WEBP_FILTER_NONE)
  40419 	best_score = int32(0x7fffffff)
  40420 	filter = int32(WEBP_FILTER_NONE)
  40421 	for {
  40422 		if !(filter < int32(WEBP_FILTER_LAST)) {
  40423 			break
  40424 		}
  40425 		score = 0
  40426 		i = 0
  40427 		for {
  40428 			if !(i < int32(16)) {
  40429 				break
  40430 			}
  40431 			if **(**int32)(__ccgo_up(bp + uintptr(filter)*64 + uintptr(i)*4)) > 0 {
  40432 				score = score + i
  40433 			}
  40434 			goto _4
  40435 		_4:
  40436 			;
  40437 			i = i + 1
  40438 		}
  40439 		if score < best_score {
  40440 			best_score = score
  40441 			best_filter = filter
  40442 		}
  40443 		goto _3
  40444 	_3:
  40445 		;
  40446 		filter = filter + 1
  40447 	}
  40448 	return best_filter
  40449 	return r
  40450 }
  40451 
  40452 // Alpha related constants.
  40453 
  40454 // Mux related constants.
  40455 
  40456 // Maximum chunk payload is such that adding the header and padding won't
  40457 // overflow a uint32_t.
  40458 
  40459 // -----------------------------------------------------------------------------
  40460 // Util function to optimize the symbol map for RLE coding
  40461 
  40462 // C documentation
  40463 //
  40464 //	// Heuristics for selecting the stride ranges to collapse.
  40465 func ValuesShouldBeCollapsedToStrideAverage(tls *libc.TLS, a int32, b int32) (r int32) {
  40466 	return libc.BoolInt32(libc.Xabs(tls, a-b) < int32(4))
  40467 }
  40468 
  40469 // C documentation
  40470 //
  40471 //	// Change the population counts in a way that the consequent
  40472 //	// Huffman tree compression, especially its RLE-part, give smaller output.
  40473 func OptimizeHuffmanForRle(tls *libc.TLS, length int32, good_for_rle uintptr, counts uintptr) {
  40474 	var count, k1, limit, stride1, sum, symbol uint32_t
  40475 	var i, k, stride int32
  40476 	_, _, _, _, _, _, _, _, _ = count, i, k, k1, limit, stride, stride1, sum, symbol
  40477 	for {
  40478 		if !(length >= 0) {
  40479 			break
  40480 		}
  40481 		if length == 0 {
  40482 			return // All zeros.
  40483 		}
  40484 		if **(**uint32_t)(__ccgo_up(counts + uintptr(length-int32(1))*4)) != uint32(0) {
  40485 			// Now counts[0..length - 1] does not have trailing zeros.
  40486 			break
  40487 		}
  40488 		goto _1
  40489 	_1:
  40490 		;
  40491 		length = length - 1
  40492 	}
  40493 	// 2) Let's mark all population counts that already can be encoded
  40494 	// with an rle code.
  40495 	// Let's not spoil any of the existing good rle codes.
  40496 	// Mark any seq of 0's that is longer as 5 as a good_for_rle.
  40497 	// Mark any seq of non-0's that is longer as 7 as a good_for_rle.
  40498 	symbol = **(**uint32_t)(__ccgo_up(counts))
  40499 	stride = 0
  40500 	i = 0
  40501 	for {
  40502 		if !(i < length+int32(1)) {
  40503 			break
  40504 		}
  40505 		if i == length || **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4)) != symbol {
  40506 			if symbol == uint32(0) && stride >= int32(5) || symbol != uint32(0) && stride >= int32(7) {
  40507 				k = 0
  40508 				for {
  40509 					if !(k < stride) {
  40510 						break
  40511 					}
  40512 					**(**uint8_t)(__ccgo_up(good_for_rle + uintptr(i-k-int32(1)))) = uint8(1)
  40513 					goto _3
  40514 				_3:
  40515 					;
  40516 					k = k + 1
  40517 				}
  40518 			}
  40519 			stride = int32(1)
  40520 			if i != length {
  40521 				symbol = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40522 			}
  40523 		} else {
  40524 			stride = stride + 1
  40525 		}
  40526 		goto _2
  40527 	_2:
  40528 		;
  40529 		i = i + 1
  40530 	}
  40531 	// 3) Let's replace those population counts that lead to more rle codes.
  40532 	stride1 = uint32(0)
  40533 	limit = **(**uint32_t)(__ccgo_up(counts))
  40534 	sum = uint32(0)
  40535 	i = 0
  40536 	for {
  40537 		if !(i < length+int32(1)) {
  40538 			break
  40539 		}
  40540 		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) {
  40541 			if stride1 >= uint32(4) || stride1 >= uint32(3) && sum == uint32(0) {
  40542 				// The stride must end, collapse what we have, if we have enough (4).
  40543 				count = (sum + stride1/uint32(2)) / stride1
  40544 				if count < uint32(1) {
  40545 					count = uint32(1)
  40546 				}
  40547 				if sum == uint32(0) {
  40548 					// Don't make an all zeros stride to be upgraded to ones.
  40549 					count = uint32(0)
  40550 				}
  40551 				k1 = uint32(0)
  40552 				for {
  40553 					if !(k1 < stride1) {
  40554 						break
  40555 					}
  40556 					// We don't want to change value at counts[i],
  40557 					// that is already belonging to the next stride. Thus - 1.
  40558 					**(**uint32_t)(__ccgo_up(counts + uintptr(libc.Uint32FromInt32(i)-k1-uint32(1))*4)) = count
  40559 					goto _5
  40560 				_5:
  40561 					;
  40562 					k1 = k1 + 1
  40563 				}
  40564 			}
  40565 			stride1 = uint32(0)
  40566 			sum = uint32(0)
  40567 			if i < length-int32(3) {
  40568 				// All interesting strides have a count of at least 4,
  40569 				// at least when non-zeros.
  40570 				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)
  40571 			} else {
  40572 				if i < length {
  40573 					limit = **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40574 				} else {
  40575 					limit = uint32(0)
  40576 				}
  40577 			}
  40578 		}
  40579 		stride1 = stride1 + 1
  40580 		if i != length {
  40581 			sum = sum + **(**uint32_t)(__ccgo_up(counts + uintptr(i)*4))
  40582 			if stride1 >= uint32(4) {
  40583 				limit = (sum + stride1/uint32(2)) / stride1
  40584 			}
  40585 		}
  40586 		goto _4
  40587 	_4:
  40588 		;
  40589 		i = i + 1
  40590 	}
  40591 }
  40592 
  40593 // C documentation
  40594 //
  40595 //	// A comparer function for two Huffman trees: sorts first by 'total count'
  40596 //	// (more comes first), and then by 'value' (more comes first).
  40597 func CompareHuffmanTrees(tls *libc.TLS, ptr1 uintptr, ptr2 uintptr) (r int32) {
  40598 	var t1, t2 uintptr
  40599 	var v1 int32
  40600 	_, _, _ = t1, t2, v1
  40601 	t1 = ptr1
  40602 	t2 = ptr2
  40603 	if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count > (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40604 		return -int32(1)
  40605 	} else {
  40606 		if (*HuffmanTree)(unsafe.Pointer(t1)).Ftotal_count < (*HuffmanTree)(unsafe.Pointer(t2)).Ftotal_count {
  40607 			return int32(1)
  40608 		} else {
  40609 			if (*HuffmanTree)(unsafe.Pointer(t1)).Fvalue < (*HuffmanTree)(unsafe.Pointer(t2)).Fvalue {
  40610 				v1 = -int32(1)
  40611 			} else {
  40612 				v1 = int32(1)
  40613 			}
  40614 			return v1
  40615 		}
  40616 	}
  40617 	return r
  40618 }
  40619 
  40620 func SetBitDepths(tls *libc.TLS, tree uintptr, pool uintptr, bit_depths uintptr, level int32) {
  40621 	if (*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left >= 0 {
  40622 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_left)*16, pool, bit_depths, level+int32(1))
  40623 		SetBitDepths(tls, pool+uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fpool_index_right)*16, pool, bit_depths, level+int32(1))
  40624 	} else {
  40625 		**(**uint8_t)(__ccgo_up(bit_depths + uintptr((*HuffmanTree)(unsafe.Pointer(tree)).Fvalue))) = libc.Uint8FromInt32(level)
  40626 	}
  40627 }
  40628 
  40629 // C documentation
  40630 //
  40631 //	// Create an optimal Huffman tree.
  40632 //	//
  40633 //	// (data,length): population counts.
  40634 //	// tree_limit: maximum bit depth (inclusive) of the codes.
  40635 //	// bit_depths[]: how many bits are used for the symbol.
  40636 //	//
  40637 //	// Returns 0 when an error has occurred.
  40638 //	//
  40639 //	// The catch here is that the tree cannot be arbitrarily deep
  40640 //	//
  40641 //	// count_limit is the value that is to be faked as the minimum value
  40642 //	// and this minimum value is raised until the tree matches the
  40643 //	// maximum length requirement.
  40644 //	//
  40645 //	// This algorithm is not of excellent performance for very long data blocks,
  40646 //	// especially when population counts are longer than 2**tree_limit, but
  40647 //	// we are not planning to use this with extremely long blocks.
  40648 //	//
  40649 //	// See https://en.wikipedia.org/wiki/Huffman_coding
  40650 func GenerateOptimalTree(tls *libc.TLS, histogram uintptr, histogram_size int32, tree uintptr, tree_depth_limit int32, bit_depths uintptr) {
  40651 	var count, count1, count_min uint32_t
  40652 	var i, idx, j, k, max_depth, tree_pool_size, tree_size, tree_size_orig, v5 int32
  40653 	var tree_pool uintptr
  40654 	var v4 uint32
  40655 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = count, count1, count_min, i, idx, j, k, max_depth, tree_pool, tree_pool_size, tree_size, tree_size_orig, v4, v5
  40656 	tree_size_orig = 0
  40657 	i = 0
  40658 	for {
  40659 		if !(i < histogram_size) {
  40660 			break
  40661 		}
  40662 		if **(**uint32_t)(__ccgo_up(histogram + uintptr(i)*4)) != uint32(0) {
  40663 			tree_size_orig = tree_size_orig + 1
  40664 		}
  40665 		goto _1
  40666 	_1:
  40667 		;
  40668 		i = i + 1
  40669 	}
  40670 	if tree_size_orig == 0 { // pretty optimal already!
  40671 		return
  40672 	}
  40673 	tree_pool = tree + uintptr(tree_size_orig)*16
  40674 	// For block sizes with less than 64k symbols we never need to do a
  40675 	// second iteration of this loop.
  40676 	// If we actually start running inside this loop a lot, we would perhaps
  40677 	// be better off with the Katajainen algorithm.
  40678 	count_min = uint32(1)
  40679 	for {
  40680 		tree_size = tree_size_orig
  40681 		// We need to pack the Huffman tree in tree_depth_limit bits.
  40682 		// So, we try by faking histogram entries to be at least 'count_min'.
  40683 		idx = 0
  40684 		j = 0
  40685 		for {
  40686 			if !(j < histogram_size) {
  40687 				break
  40688 			}
  40689 			if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) != uint32(0) {
  40690 				if **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4)) < count_min {
  40691 					v4 = count_min
  40692 				} else {
  40693 					v4 = **(**uint32_t)(__ccgo_up(histogram + uintptr(j)*4))
  40694 				}
  40695 				count = v4
  40696 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Ftotal_count = count
  40697 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fvalue = j
  40698 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_left = -int32(1)
  40699 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(idx)*16))).Fpool_index_right = -int32(1)
  40700 				idx = idx + 1
  40701 			}
  40702 			goto _3
  40703 		_3:
  40704 			;
  40705 			j = j + 1
  40706 		}
  40707 		// Build the Huffman tree.
  40708 		libc.Xqsort(tls, tree, libc.Uint64FromInt32(tree_size), uint64(16), __ccgo_fp(CompareHuffmanTrees))
  40709 		if tree_size > int32(1) { // Normal case.
  40710 			tree_pool_size = 0
  40711 			for tree_size > int32(1) {
  40712 				v5 = tree_pool_size
  40713 				tree_pool_size = tree_pool_size + 1
  40714 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(1))*16))
  40715 				v5 = tree_pool_size
  40716 				tree_pool_size = tree_pool_size + 1
  40717 				**(**HuffmanTree)(__ccgo_up(tree_pool + uintptr(v5)*16)) = **(**HuffmanTree)(__ccgo_up(tree + uintptr(tree_size-int32(2))*16))
  40718 				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
  40719 				tree_size = tree_size - int32(2)
  40720 				k = 0
  40721 				for {
  40722 					if !(k < tree_size) {
  40723 						break
  40724 					}
  40725 					if (**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count <= count1 {
  40726 						break
  40727 					}
  40728 					goto _7
  40729 				_7:
  40730 					;
  40731 					k = k + 1
  40732 				}
  40733 				libc.Xmemmove(tls, tree+uintptr(k+libc.Int32FromInt32(1))*16, tree+uintptr(k)*16, libc.Uint64FromInt32(tree_size-k)*uint64(16))
  40734 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Ftotal_count = count1
  40735 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fvalue = -int32(1)
  40736 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_left = tree_pool_size - int32(1)
  40737 				(**(**HuffmanTree)(__ccgo_up(tree + uintptr(k)*16))).Fpool_index_right = tree_pool_size - int32(2)
  40738 				tree_size = tree_size + int32(1)
  40739 			}
  40740 			SetBitDepths(tls, tree, tree_pool, bit_depths, 0)
  40741 		} else {
  40742 			if tree_size == int32(1) { // Trivial case: only one element.
  40743 				**(**uint8_t)(__ccgo_up(bit_depths + uintptr((**(**HuffmanTree)(__ccgo_up(tree))).Fvalue))) = uint8(1)
  40744 			}
  40745 		}
  40746 		// Test if this Huffman tree satisfies our 'tree_depth_limit' criteria.
  40747 		max_depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bit_depths)))
  40748 		j = int32(1)
  40749 		for {
  40750 			if !(j < histogram_size) {
  40751 				break
  40752 			}
  40753 			if max_depth < libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j)))) {
  40754 				max_depth = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bit_depths + uintptr(j))))
  40755 			}
  40756 			goto _8
  40757 		_8:
  40758 			;
  40759 			j = j + 1
  40760 		}
  40761 		if max_depth <= tree_depth_limit {
  40762 			break
  40763 		}
  40764 		goto _2
  40765 	_2:
  40766 		;
  40767 		count_min = count_min * uint32(2)
  40768 	}
  40769 }
  40770 
  40771 // -----------------------------------------------------------------------------
  40772 // Coding of the Huffman tree values
  40773 
  40774 func CodeRepeatedValues(tls *libc.TLS, repetitions int32, tokens uintptr, value int32, prev_value int32) (r uintptr) {
  40775 	var i int32
  40776 	_ = i
  40777 	if value != prev_value {
  40778 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = libc.Uint8FromInt32(value)
  40779 		(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40780 		tokens += 2
  40781 		repetitions = repetitions - 1
  40782 	}
  40783 	for repetitions >= int32(1) {
  40784 		if repetitions < int32(3) {
  40785 			i = 0
  40786 			for {
  40787 				if !(i < repetitions) {
  40788 					break
  40789 				}
  40790 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = libc.Uint8FromInt32(value)
  40791 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40792 				tokens += 2
  40793 				goto _1
  40794 			_1:
  40795 				;
  40796 				i = i + 1
  40797 			}
  40798 			break
  40799 		} else {
  40800 			if repetitions < int32(7) {
  40801 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40802 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = libc.Uint8FromInt32(repetitions - int32(3))
  40803 				tokens += 2
  40804 				break
  40805 			} else {
  40806 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(16)
  40807 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(3)
  40808 				tokens += 2
  40809 				repetitions = repetitions - int32(6)
  40810 			}
  40811 		}
  40812 	}
  40813 	return tokens
  40814 }
  40815 
  40816 func CodeRepeatedZeros(tls *libc.TLS, repetitions int32, tokens uintptr) (r uintptr) {
  40817 	var i int32
  40818 	_ = i
  40819 	for repetitions >= int32(1) {
  40820 		if repetitions < int32(3) {
  40821 			i = 0
  40822 			for {
  40823 				if !(i < repetitions) {
  40824 					break
  40825 				}
  40826 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(0) // 0-value
  40827 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0)
  40828 				tokens += 2
  40829 				goto _1
  40830 			_1:
  40831 				;
  40832 				i = i + 1
  40833 			}
  40834 			break
  40835 		} else {
  40836 			if repetitions < int32(11) {
  40837 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(17)
  40838 				(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = libc.Uint8FromInt32(repetitions - int32(3))
  40839 				tokens += 2
  40840 				break
  40841 			} else {
  40842 				if repetitions < int32(139) {
  40843 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40844 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = libc.Uint8FromInt32(repetitions - int32(11))
  40845 					tokens += 2
  40846 					break
  40847 				} else {
  40848 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fcode = uint8(18)
  40849 					(*HuffmanTreeToken)(unsafe.Pointer(tokens)).Fextra_bits = uint8(0x7f) // 138 repeated 0s
  40850 					tokens += 2
  40851 					repetitions = repetitions - int32(138)
  40852 				}
  40853 			}
  40854 		}
  40855 	}
  40856 	return tokens
  40857 }
  40858 
  40859 func VP8LCreateCompressedHuffmanTree(tls *libc.TLS, tree uintptr, tokens uintptr, max_tokens int32) (r int32) {
  40860 	var depth_size, i, k, prev_value, runs, value int32
  40861 	var ending_token, starting_token uintptr
  40862 	_, _, _, _, _, _, _, _ = depth_size, ending_token, i, k, prev_value, runs, starting_token, value
  40863 	starting_token = tokens
  40864 	ending_token = tokens + uintptr(max_tokens)*2
  40865 	depth_size = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40866 	prev_value = int32(8) // 8 is the initial value for rle.
  40867 	i = 0
  40868 	for i < depth_size {
  40869 		value = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40870 		k = i + int32(1)
  40871 		for k < depth_size && libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(k)))) == value {
  40872 			k = k + 1
  40873 		}
  40874 		runs = k - i
  40875 		if value == 0 {
  40876 			tokens = CodeRepeatedZeros(tls, runs, tokens)
  40877 		} else {
  40878 			tokens = CodeRepeatedValues(tls, runs, tokens, value, prev_value)
  40879 			prev_value = value
  40880 		}
  40881 		i = i + runs
  40882 	}
  40883 	_ = ending_token // suppress 'unused variable' warning
  40884 	return int32((int64(tokens) - int64(starting_token)) / 2)
  40885 }
  40886 
  40887 // -----------------------------------------------------------------------------
  40888 
  40889 // C documentation
  40890 //
  40891 //	// Pre-reversed 4-bit values.
  40892 var kReversedBits = [16]uint8_t{
  40893 	1:  uint8(0x8),
  40894 	2:  uint8(0x4),
  40895 	3:  uint8(0xc),
  40896 	4:  uint8(0x2),
  40897 	5:  uint8(0xa),
  40898 	6:  uint8(0x6),
  40899 	7:  uint8(0xe),
  40900 	8:  uint8(0x1),
  40901 	9:  uint8(0x9),
  40902 	10: uint8(0x5),
  40903 	11: uint8(0xd),
  40904 	12: uint8(0x3),
  40905 	13: uint8(0xb),
  40906 	14: uint8(0x7),
  40907 	15: uint8(0xf),
  40908 }
  40909 
  40910 func ReverseBits(tls *libc.TLS, num_bits int32, bits uint32_t) (r uint32_t) {
  40911 	var i int32
  40912 	var retval uint32_t
  40913 	_, _ = i, retval
  40914 	retval = uint32(0)
  40915 	i = 0
  40916 	for i < num_bits {
  40917 		i = i + int32(4)
  40918 		retval = retval | libc.Uint32FromInt32(libc.Int32FromUint8(kReversedBits[bits&uint32(0xf)])<<(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-i))
  40919 		bits = bits >> uint32(4)
  40920 	}
  40921 	retval = retval >> libc.Uint32FromInt32(libc.Int32FromInt32(MAX_ALLOWED_CODE_LENGTH)+libc.Int32FromInt32(1)-num_bits)
  40922 	return retval
  40923 }
  40924 
  40925 // C documentation
  40926 //
  40927 //	// Get the actual bit values for a tree of bit depths.
  40928 func ConvertBitDepthsToSymbols(tls *libc.TLS, tree uintptr) {
  40929 	bp := tls.Alloc(64)
  40930 	defer tls.Free(64)
  40931 	var code, v4 uint32_t
  40932 	var code_length, code_length1, i, len1 int32
  40933 	var depth_count [16]int32
  40934 	var v5 uintptr
  40935 	var _ /* next_code at bp+0 */ [16]uint32_t
  40936 	_, _, _, _, _, _, _, _ = code, code_length, code_length1, depth_count, i, len1, v4, v5
  40937 	depth_count = [16]int32{}
  40938 	len1 = (*HuffmanTreeCode)(unsafe.Pointer(tree)).Fnum_symbols
  40939 	i = 0
  40940 	for {
  40941 		if !(i < len1) {
  40942 			break
  40943 		}
  40944 		code_length = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40945 		depth_count[code_length] = depth_count[code_length] + 1
  40946 		goto _1
  40947 	_1:
  40948 		;
  40949 		i = i + 1
  40950 	}
  40951 	depth_count[0] = 0 // ignore unused symbol
  40952 	(**(**[16]uint32_t)(__ccgo_up(bp)))[0] = uint32(0)
  40953 	code = uint32(0)
  40954 	i = int32(1)
  40955 	for {
  40956 		if !(i <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  40957 			break
  40958 		}
  40959 		code = (code + libc.Uint32FromInt32(depth_count[i-int32(1)])) << int32(1)
  40960 		(**(**[16]uint32_t)(__ccgo_up(bp)))[i] = code
  40961 		goto _2
  40962 	_2:
  40963 		;
  40964 		i = i + 1
  40965 	}
  40966 	i = 0
  40967 	for {
  40968 		if !(i < len1) {
  40969 			break
  40970 		}
  40971 		code_length1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcode_lengths + uintptr(i))))
  40972 		v5 = bp + uintptr(code_length1)*4
  40973 		v4 = *(*uint32_t)(unsafe.Pointer(v5))
  40974 		*(*uint32_t)(unsafe.Pointer(v5)) = *(*uint32_t)(unsafe.Pointer(v5)) + 1
  40975 		**(**uint16_t)(__ccgo_up((*HuffmanTreeCode)(unsafe.Pointer(tree)).Fcodes + uintptr(i)*2)) = uint16(ReverseBits(tls, code_length1, v4))
  40976 		goto _3
  40977 	_3:
  40978 		;
  40979 		i = i + 1
  40980 	}
  40981 }
  40982 
  40983 // -----------------------------------------------------------------------------
  40984 // Main entry point
  40985 
  40986 func VP8LCreateHuffmanTree(tls *libc.TLS, histogram uintptr, tree_depth_limit int32, buf_rle uintptr, huff_tree uintptr, huff_code uintptr) {
  40987 	var num_symbols int32
  40988 	_ = num_symbols
  40989 	num_symbols = (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fnum_symbols
  40990 	libc.Xmemset(tls, buf_rle, 0, libc.Uint64FromInt32(num_symbols)*uint64(1))
  40991 	OptimizeHuffmanForRle(tls, num_symbols, buf_rle, histogram)
  40992 	GenerateOptimalTree(tls, histogram, num_symbols, huff_tree, tree_depth_limit, (*HuffmanTreeCode)(unsafe.Pointer(huff_code)).Fcode_lengths)
  40993 	// Create the actual bit codes for the bit lengths.
  40994 	ConvertBitDepthsToSymbols(tls, huff_code)
  40995 }
  40996 
  40997 const MAX_HTREE_GROUPS = 0x10000
  40998 const SORTED_SIZE_CUTOFF = 512
  40999 
  41000 //------------------------------------------------------------------------------
  41001 
  41002 // Copyright 2012 Google Inc. All Rights Reserved.
  41003 //
  41004 // Use of this source code is governed by a BSD-style license
  41005 // that can be found in the COPYING file in the root of the source
  41006 // tree. An additional intellectual property rights grant can be found
  41007 // in the file PATENTS. All contributing project authors may
  41008 // be found in the AUTHORS file in the root of the source tree.
  41009 // -----------------------------------------------------------------------------
  41010 //
  41011 //  Internal header for constants related to WebP file format.
  41012 //
  41013 // Author: Urvang (urvang@google.com)
  41014 
  41015 // Copyright 2010 Google Inc. All Rights Reserved.
  41016 //
  41017 // Use of this source code is governed by a BSD-style license
  41018 // that can be found in the COPYING file in the root of the source
  41019 // tree. An additional intellectual property rights grant can be found
  41020 // in the file PATENTS. All contributing project authors may
  41021 // be found in the AUTHORS file in the root of the source tree.
  41022 // -----------------------------------------------------------------------------
  41023 //
  41024 //  Common types + memory wrappers
  41025 //
  41026 // Author: Skal (pascal.massimino@gmail.com)
  41027 
  41028 // Huffman data read via DecodeImageStream is represented in two (red and green)
  41029 // bytes.
  41030 
  41031 func VP8LHtreeGroupsNew(tls *libc.TLS, num_htree_groups int32) (r uintptr) {
  41032 	var htree_groups uintptr
  41033 	_ = htree_groups
  41034 	htree_groups = WebPSafeMalloc(tls, libc.Uint64FromInt32(num_htree_groups), uint64(568))
  41035 	if htree_groups == libc.UintptrFromInt32(0) {
  41036 		return libc.UintptrFromInt32(0)
  41037 	}
  41038 	return htree_groups
  41039 }
  41040 
  41041 func VP8LHtreeGroupsFree(tls *libc.TLS, htree_groups uintptr) {
  41042 	if htree_groups != libc.UintptrFromInt32(0) {
  41043 		WebPSafeFree(tls, htree_groups)
  41044 	}
  41045 }
  41046 
  41047 // C documentation
  41048 //
  41049 //	// Returns reverse(reverse(key, len) + 1, len), where reverse(key, len) is the
  41050 //	// bit-wise reversal of the len least significant bits of key.
  41051 func GetNextKey(tls *libc.TLS, key uint32_t, len1 int32) (r uint32_t) {
  41052 	var step uint32_t
  41053 	var v1 uint32
  41054 	_, _ = step, v1
  41055 	step = libc.Uint32FromInt32(int32(1) << (len1 - int32(1)))
  41056 	for key&step != 0 {
  41057 		step = step >> uint32(1)
  41058 	}
  41059 	if step != 0 {
  41060 		v1 = key&(step-uint32(1)) + step
  41061 	} else {
  41062 		v1 = key
  41063 	}
  41064 	return v1
  41065 }
  41066 
  41067 // C documentation
  41068 //
  41069 //	// Stores code in table[0], table[step], table[2*step], ..., table[end].
  41070 //	// Assumes that end is an integer multiple of step.
  41071 func ReplicateValue(tls *libc.TLS, table uintptr, step int32, end int32, code HuffmanCode) {
  41072 	for cond := true; cond; cond = end > 0 {
  41073 		end = end - step
  41074 		**(**HuffmanCode)(__ccgo_up(table + uintptr(end)*4)) = code
  41075 	}
  41076 }
  41077 
  41078 // C documentation
  41079 //
  41080 //	// Returns the table width of the next 2nd level table. count is the histogram
  41081 //	// of bit lengths for the remaining symbols, len is the code length of the next
  41082 //	// processed symbol
  41083 func NextTableBitSize(tls *libc.TLS, count uintptr, len1 int32, root_bits int32) (r int32) {
  41084 	var left int32
  41085 	_ = left
  41086 	left = int32(1) << (len1 - root_bits)
  41087 	for len1 < int32(MAX_ALLOWED_CODE_LENGTH) {
  41088 		left = left - **(**int32)(__ccgo_up(count + uintptr(len1)*4))
  41089 		if left <= 0 {
  41090 			break
  41091 		}
  41092 		len1 = len1 + 1
  41093 		left = left << int32(1)
  41094 	}
  41095 	return len1 - root_bits
  41096 }
  41097 
  41098 // C documentation
  41099 //
  41100 //	// sorted[code_lengths_size] is a pre-allocated array for sorting symbols
  41101 //	// by code length.
  41102 func BuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32, sorted uintptr) (r int32) {
  41103 	bp := tls.Alloc(128)
  41104 	defer tls.Free(128)
  41105 	var code, code1, code2 HuffmanCode
  41106 	var key, low, mask uint32_t
  41107 	var len1, num_nodes, num_open, step, symbol, symbol_code_length, table_bits, table_size, total_size, v4 int32
  41108 	var table, v5 uintptr
  41109 	var _ /* count at bp+0 */ [16]int32
  41110 	var _ /* offset at bp+64 */ [16]int32
  41111 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  41112 	table = root_table                 // next available space in table
  41113 	total_size = int32(1) << root_bits // symbol index in original or sorted table
  41114 	// number of codes of each length:
  41115 	**(**[16]int32)(__ccgo_up(bp)) = [16]int32{}
  41116 	// Build histogram of code lengths.
  41117 	symbol = 0
  41118 	for {
  41119 		if !(symbol < code_lengths_size) {
  41120 			break
  41121 		}
  41122 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > int32(MAX_ALLOWED_CODE_LENGTH) {
  41123 			return 0
  41124 		}
  41125 		(**(**[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
  41126 		goto _1
  41127 	_1:
  41128 		;
  41129 		symbol = symbol + 1
  41130 	}
  41131 	// Error, all code lengths are zeros.
  41132 	if (**(**[16]int32)(__ccgo_up(bp)))[0] == code_lengths_size {
  41133 		return 0
  41134 	}
  41135 	// Generate offsets into sorted symbol table by code length.
  41136 	(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(1)] = 0
  41137 	len1 = int32(1)
  41138 	for {
  41139 		if !(len1 < int32(MAX_ALLOWED_CODE_LENGTH)) {
  41140 			break
  41141 		}
  41142 		if (**(**[16]int32)(__ccgo_up(bp)))[len1] > int32(1)<<len1 {
  41143 			return 0
  41144 		}
  41145 		(**(**[16]int32)(__ccgo_up(bp + 64)))[len1+int32(1)] = (**(**[16]int32)(__ccgo_up(bp + 64)))[len1] + (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41146 		goto _2
  41147 	_2:
  41148 		;
  41149 		len1 = len1 + 1
  41150 	}
  41151 	// Sort symbols by length, by symbol order within each length.
  41152 	symbol = 0
  41153 	for {
  41154 		if !(symbol < code_lengths_size) {
  41155 			break
  41156 		}
  41157 		symbol_code_length = **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4))
  41158 		if **(**int32)(__ccgo_up(code_lengths + uintptr(symbol)*4)) > 0 {
  41159 			if sorted != libc.UintptrFromInt32(0) {
  41160 				if (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] >= code_lengths_size {
  41161 					return 0
  41162 				}
  41163 				v5 = bp + 64 + uintptr(symbol_code_length)*4
  41164 				v4 = *(*int32)(unsafe.Pointer(v5))
  41165 				*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
  41166 				**(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2)) = libc.Uint16FromInt32(symbol)
  41167 			} else {
  41168 				(**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] = (**(**[16]int32)(__ccgo_up(bp + 64)))[symbol_code_length] + 1
  41169 			}
  41170 		}
  41171 		goto _3
  41172 	_3:
  41173 		;
  41174 		symbol = symbol + 1
  41175 	}
  41176 	// Special case code with only one value.
  41177 	if (**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)] == int32(1) {
  41178 		if sorted != libc.UintptrFromInt32(0) {
  41179 			code.Fbits = uint8(0)
  41180 			code.Fvalue = **(**uint16_t)(__ccgo_up(sorted))
  41181 			ReplicateValue(tls, table, int32(1), total_size, code)
  41182 		}
  41183 		return total_size
  41184 	}
  41185 	// step size to replicate values in current table
  41186 	low = uint32(0xffffffff)                           // low bits for current root entry
  41187 	mask = libc.Uint32FromInt32(total_size - int32(1)) // mask for low bits
  41188 	key = uint32(0)                                    // reversed prefix code
  41189 	num_nodes = int32(1)                               // number of Huffman tree nodes
  41190 	num_open = int32(1)                                // number of open branches in current tree level
  41191 	table_bits = root_bits                             // key length of current table
  41192 	table_size = int32(1) << table_bits                // size of current table
  41193 	symbol = 0
  41194 	// Fill in root table.
  41195 	len1 = int32(1)
  41196 	step = libc.Int32FromInt32(2)
  41197 	for {
  41198 		if !(len1 <= root_bits) {
  41199 			break
  41200 		}
  41201 		num_open = num_open << int32(1)
  41202 		num_nodes = num_nodes + num_open
  41203 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41204 		if num_open < 0 {
  41205 			return 0
  41206 		}
  41207 		if root_table == libc.UintptrFromInt32(0) {
  41208 			goto _6
  41209 		}
  41210 		for {
  41211 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  41212 				break
  41213 			}
  41214 			code1.Fbits = libc.Uint8FromInt32(len1)
  41215 			v4 = symbol
  41216 			symbol = symbol + 1
  41217 			code1.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  41218 			ReplicateValue(tls, table+uintptr(key)*4, step, table_size, code1)
  41219 			key = GetNextKey(tls, key, len1)
  41220 			goto _7
  41221 		_7:
  41222 			;
  41223 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  41224 		}
  41225 		goto _6
  41226 	_6:
  41227 		;
  41228 		len1 = len1 + 1
  41229 		step = step << int32(1)
  41230 	}
  41231 	// Fill in 2nd level tables and add pointers to root table.
  41232 	len1 = root_bits + int32(1)
  41233 	step = libc.Int32FromInt32(2)
  41234 	for {
  41235 		if !(len1 <= int32(MAX_ALLOWED_CODE_LENGTH)) {
  41236 			break
  41237 		}
  41238 		num_open = num_open << int32(1)
  41239 		num_nodes = num_nodes + num_open
  41240 		num_open = num_open - (**(**[16]int32)(__ccgo_up(bp)))[len1]
  41241 		if num_open < 0 {
  41242 			return 0
  41243 		}
  41244 		for {
  41245 			if !((**(**[16]int32)(__ccgo_up(bp)))[len1] > 0) {
  41246 				break
  41247 			}
  41248 			if key&mask != low {
  41249 				if root_table != libc.UintptrFromInt32(0) {
  41250 					table = table + uintptr(table_size)*4
  41251 				}
  41252 				table_bits = NextTableBitSize(tls, bp, len1, root_bits)
  41253 				table_size = int32(1) << table_bits
  41254 				total_size = total_size + table_size
  41255 				low = key & mask
  41256 				if root_table != libc.UintptrFromInt32(0) {
  41257 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fbits = libc.Uint8FromInt32(table_bits + root_bits)
  41258 					(**(**HuffmanCode)(__ccgo_up(root_table + uintptr(low)*4))).Fvalue = libc.Uint16FromInt64((int64(table)-int64(root_table))/4 - libc.Int64FromUint32(low))
  41259 				}
  41260 			}
  41261 			if root_table != libc.UintptrFromInt32(0) {
  41262 				code2.Fbits = libc.Uint8FromInt32(len1 - root_bits)
  41263 				v4 = symbol
  41264 				symbol = symbol + 1
  41265 				code2.Fvalue = **(**uint16_t)(__ccgo_up(sorted + uintptr(v4)*2))
  41266 				ReplicateValue(tls, table+uintptr(key>>root_bits)*4, step, table_size, code2)
  41267 			}
  41268 			key = GetNextKey(tls, key, len1)
  41269 			goto _10
  41270 		_10:
  41271 			;
  41272 			(**(**[16]int32)(__ccgo_up(bp)))[len1] = (**(**[16]int32)(__ccgo_up(bp)))[len1] - 1
  41273 		}
  41274 		goto _9
  41275 	_9:
  41276 		;
  41277 		len1 = len1 + 1
  41278 		step = step << int32(1)
  41279 	}
  41280 	// Check if tree is full.
  41281 	if num_nodes != int32(2)*(**(**[16]int32)(__ccgo_up(bp + 64)))[int32(MAX_ALLOWED_CODE_LENGTH)]-int32(1) {
  41282 		return 0
  41283 	}
  41284 	return total_size
  41285 }
  41286 
  41287 // C documentation
  41288 //
  41289 //	// Maximum code_lengths_size is 2328 (reached for 11-bit color_cache_bits).
  41290 //	// More commonly, the value is around ~280.
  41291 //	// Cut-off value for switching between heap and stack allocation.
  41292 func VP8LBuildHuffmanTable(tls *libc.TLS, root_table uintptr, root_bits int32, code_lengths uintptr, code_lengths_size int32) (r int32) {
  41293 	bp := tls.Alloc(1024)
  41294 	defer tls.Free(1024)
  41295 	var next, sorted1 uintptr
  41296 	var segment_size, total_size, v1 int32
  41297 	var _ /* sorted at bp+0 */ [512]uint16_t
  41298 	_, _, _, _, _ = next, segment_size, sorted1, total_size, v1
  41299 	total_size = BuildHuffmanTable(tls, libc.UintptrFromInt32(0), root_bits, code_lengths, code_lengths_size, libc.UintptrFromInt32(0))
  41300 	if total_size == 0 || root_table == libc.UintptrFromInt32(0) {
  41301 		return total_size
  41302 	}
  41303 	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 {
  41304 		// If 'root_table' does not have enough memory, allocate a new segment.
  41305 		// The available part of root_table->curr_segment is left unused because we
  41306 		// need a contiguous buffer.
  41307 		segment_size = (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fsize
  41308 		next = WebPSafeMalloc(tls, uint64(1), uint64(32))
  41309 		if next == libc.UintptrFromInt32(0) {
  41310 			return 0
  41311 		}
  41312 		// Fill the new segment.
  41313 		// We need at least 'total_size' but if that value is small, it is better to
  41314 		// allocate a big chunk to prevent more allocations later. 'segment_size' is
  41315 		// therefore chosen (any other arbitrary value could be chosen).
  41316 		if total_size > segment_size {
  41317 			v1 = total_size
  41318 		} else {
  41319 			v1 = segment_size
  41320 		}
  41321 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize = v1
  41322 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart = WebPSafeMalloc(tls, libc.Uint64FromInt32((*HuffmanTablesSegment)(unsafe.Pointer(next)).Fsize), uint64(4))
  41323 		if (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart == libc.UintptrFromInt32(0) {
  41324 			WebPSafeFree(tls, next)
  41325 			return 0
  41326 		}
  41327 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(next)).Fstart
  41328 		(*HuffmanTablesSegment)(unsafe.Pointer(next)).Fnext = libc.UintptrFromInt32(0)
  41329 		// Point to the new segment.
  41330 		(*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fnext = next
  41331 		(*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment = next
  41332 	}
  41333 	if code_lengths_size <= int32(SORTED_SIZE_CUTOFF) {
  41334 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, bp)
  41335 	} else { // rare case. Use heap allocation.
  41336 		sorted1 = WebPSafeMalloc(tls, libc.Uint64FromInt32(code_lengths_size), uint64(2))
  41337 		if sorted1 == libc.UintptrFromInt32(0) {
  41338 			return 0
  41339 		}
  41340 		BuildHuffmanTable(tls, (*HuffmanTablesSegment)(unsafe.Pointer((*HuffmanTables)(unsafe.Pointer(root_table)).Fcurr_segment)).Fcurr_table, root_bits, code_lengths, code_lengths_size, sorted1)
  41341 		WebPSafeFree(tls, sorted1)
  41342 	}
  41343 	return total_size
  41344 }
  41345 
  41346 func VP8LHuffmanTablesAllocate(tls *libc.TLS, size int32, huffman_tables uintptr) (r int32) {
  41347 	var root uintptr
  41348 	_ = root
  41349 	// Have 'segment' point to the first segment for now, 'root'.
  41350 	root = huffman_tables
  41351 	(*HuffmanTables)(unsafe.Pointer(huffman_tables)).Fcurr_segment = root
  41352 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fnext = libc.UintptrFromInt32(0)
  41353 	// Allocate root.
  41354 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart = WebPSafeMalloc(tls, libc.Uint64FromInt32(size), uint64(4))
  41355 	if (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart == libc.UintptrFromInt32(0) {
  41356 		return 0
  41357 	}
  41358 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fcurr_table = (*HuffmanTablesSegment)(unsafe.Pointer(root)).Fstart
  41359 	(*HuffmanTablesSegment)(unsafe.Pointer(root)).Fsize = size
  41360 	return int32(1)
  41361 }
  41362 
  41363 func VP8LHuffmanTablesDeallocate(tls *libc.TLS, huffman_tables uintptr) {
  41364 	var current, next uintptr
  41365 	_, _ = current, next
  41366 	if huffman_tables == libc.UintptrFromInt32(0) {
  41367 		return
  41368 	}
  41369 	// Free the root node.
  41370 	current = huffman_tables
  41371 	next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41372 	WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41373 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart = libc.UintptrFromInt32(0)
  41374 	(*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext = libc.UintptrFromInt32(0)
  41375 	current = next
  41376 	// Free the following nodes.
  41377 	for current != libc.UintptrFromInt32(0) {
  41378 		next = (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fnext
  41379 		WebPSafeFree(tls, (*HuffmanTablesSegment)(unsafe.Pointer(current)).Fstart)
  41380 		WebPSafeFree(tls, current)
  41381 		current = next
  41382 	}
  41383 }
  41384 
  41385 var kHashMul13 = uint32(0x1e35a7bd)
  41386 
  41387 // Alpha related constants.
  41388 
  41389 // Mux related constants.
  41390 
  41391 // Maximum chunk payload is such that adding the header and padding won't
  41392 // overflow a uint32_t.
  41393 
  41394 // Copyright 2010 Google Inc. All Rights Reserved.
  41395 //
  41396 // Use of this source code is governed by a BSD-style license
  41397 // that can be found in the COPYING file in the root of the source
  41398 // tree. An additional intellectual property rights grant can be found
  41399 // in the file PATENTS. All contributing project authors may
  41400 // be found in the AUTHORS file in the root of the source tree.
  41401 // -----------------------------------------------------------------------------
  41402 //
  41403 //  Common types + memory wrappers
  41404 //
  41405 // Author: Skal (pascal.massimino@gmail.com)
  41406 
  41407 // -----------------------------------------------------------------------------
  41408 
  41409 // Palette reordering for smaller sum of deltas (and for smaller storage).
  41410 
  41411 func PaletteCompareColorsForQsort(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
  41412 	bp := tls.Alloc(16)
  41413 	defer tls.Free(16)
  41414 	var a, b, v1, v3 uint32_t
  41415 	var v5 int32
  41416 	var _ /* A at bp+0 */ uint32_t
  41417 	_, _, _, _, _ = a, b, v1, v3, v5
  41418 	libc.Xmemcpy(tls, bp, p1, uint64(4))
  41419 	v1 = **(**uint32_t)(__ccgo_up(bp))
  41420 	goto _2
  41421 _2:
  41422 	a = v1
  41423 	libc.Xmemcpy(tls, bp, p2, uint64(4))
  41424 	v3 = **(**uint32_t)(__ccgo_up(bp))
  41425 	goto _4
  41426 _4:
  41427 	b = v3
  41428 	if a < b {
  41429 		v5 = -int32(1)
  41430 	} else {
  41431 		v5 = int32(1)
  41432 	}
  41433 	return v5
  41434 }
  41435 
  41436 func PaletteComponentDistance(tls *libc.TLS, v uint32_t) (r uint32_t) {
  41437 	var v1 uint32
  41438 	_ = v1
  41439 	if v <= uint32(128) {
  41440 		v1 = v
  41441 	} else {
  41442 		v1 = uint32(256) - v
  41443 	}
  41444 	return v1
  41445 }
  41446 
  41447 // C documentation
  41448 //
  41449 //	// Computes a value that is related to the entropy created by the
  41450 //	// palette entry diff.
  41451 //	//
  41452 //	// Note that the last & 0xff is a no-operation in the next statement, but
  41453 //	// removed by most compilers and is here only for regularity of the code.
  41454 func PaletteColorDistance(tls *libc.TLS, col1 uint32_t, col2 uint32_t) (r uint32_t) {
  41455 	var alpha_and_green, diff, red_and_blue, score, v1, v2, v3 uint32_t
  41456 	var kMoreWeightForRGBThanForAlpha int32
  41457 	_, _, _, _, _, _, _, _ = alpha_and_green, diff, kMoreWeightForRGBThanForAlpha, red_and_blue, score, v1, v2, v3
  41458 	v1 = col1
  41459 	v2 = col2
  41460 	alpha_and_green = uint32(0x00ff00ff) + v1&uint32(0xff00ff00) - v2&uint32(0xff00ff00)
  41461 	red_and_blue = uint32(0xff00ff00) + v1&uint32(0x00ff00ff) - v2&uint32(0x00ff00ff)
  41462 	v3 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41463 	goto _4
  41464 _4:
  41465 	diff = v3
  41466 	kMoreWeightForRGBThanForAlpha = int32(9)
  41467 	score = PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(0)&uint32(0xff))
  41468 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(8)&uint32(0xff))
  41469 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(16)&uint32(0xff))
  41470 	score = score * libc.Uint32FromInt32(kMoreWeightForRGBThanForAlpha)
  41471 	score = score + PaletteComponentDistance(tls, diff>>libc.Int32FromInt32(24)&uint32(0xff))
  41472 	return score
  41473 }
  41474 
  41475 func SwapColor(tls *libc.TLS, col1 uintptr, col2 uintptr) {
  41476 	var tmp uint32_t
  41477 	_ = tmp
  41478 	tmp = **(**uint32_t)(__ccgo_up(col1))
  41479 	**(**uint32_t)(__ccgo_up(col1)) = **(**uint32_t)(__ccgo_up(col2))
  41480 	**(**uint32_t)(__ccgo_up(col2)) = tmp
  41481 }
  41482 
  41483 func SearchColorNoIdx(tls *libc.TLS, sorted uintptr, color uint32_t, num_colors int32) (r int32) {
  41484 	var hi, low, mid int32
  41485 	_, _, _ = hi, low, mid
  41486 	low = 0
  41487 	hi = num_colors
  41488 	if **(**uint32_t)(__ccgo_up(sorted + uintptr(low)*4)) == color {
  41489 		return low
  41490 	} // loop invariant: sorted[low] != color
  41491 	for int32(1) != 0 {
  41492 		mid = (low + hi) >> int32(1)
  41493 		if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) == color {
  41494 			return mid
  41495 		} else {
  41496 			if **(**uint32_t)(__ccgo_up(sorted + uintptr(mid)*4)) < color {
  41497 				low = mid
  41498 			} else {
  41499 				hi = mid
  41500 			}
  41501 		}
  41502 	}
  41503 	return 0
  41504 }
  41505 
  41506 func PrepareMapToPalette(tls *libc.TLS, palette uintptr, num_colors uint32_t, sorted uintptr, idx_map uintptr) {
  41507 	var i uint32_t
  41508 	_ = i
  41509 	libc.Xmemcpy(tls, sorted, palette, uint64(num_colors)*uint64(4))
  41510 	libc.Xqsort(tls, sorted, uint64(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41511 	i = uint32(0)
  41512 	for {
  41513 		if !(i < num_colors) {
  41514 			break
  41515 		}
  41516 		**(**uint32_t)(__ccgo_up(idx_map + uintptr(SearchColorNoIdx(tls, sorted, **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4)), libc.Int32FromUint32(num_colors)))*4)) = i
  41517 		goto _1
  41518 	_1:
  41519 		;
  41520 		i = i + 1
  41521 	}
  41522 }
  41523 
  41524 //------------------------------------------------------------------------------
  41525 
  41526 func GetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  41527 	var argb1 uintptr
  41528 	var colors [1024]uint32_t
  41529 	var height, i, key, num_colors, width, x, y, v3 int32
  41530 	var in_use [1024]uint8_t
  41531 	var last_pix uint32_t
  41532 	_, _, _, _, _, _, _, _, _, _, _, _ = argb1, colors, height, i, in_use, key, last_pix, num_colors, width, x, y, v3
  41533 	num_colors = 0
  41534 	in_use = [1024]uint8_t{}
  41535 	colors = [1024]uint32_t{}
  41536 	argb1 = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41537 	width = (*WebPPicture)(unsafe.Pointer(pic)).Fwidth
  41538 	height = (*WebPPicture)(unsafe.Pointer(pic)).Fheight
  41539 	last_pix = ^**(**uint32_t)(__ccgo_up(argb1)) // so we're sure that last_pix != argb[0]
  41540 	y = 0
  41541 	for {
  41542 		if !(y < height) {
  41543 			break
  41544 		}
  41545 		x = 0
  41546 		for {
  41547 			if !(x < width) {
  41548 				break
  41549 			}
  41550 			if **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4)) == last_pix {
  41551 				goto _2
  41552 			}
  41553 			last_pix = **(**uint32_t)(__ccgo_up(argb1 + uintptr(x)*4))
  41554 			v3 = libc.Int32FromUint32(last_pix * kHashMul13 >> int32(22))
  41555 			goto _4
  41556 		_4:
  41557 			key = v3
  41558 			for int32(1) != 0 {
  41559 				if !(in_use[key] != 0) {
  41560 					colors[key] = last_pix
  41561 					in_use[key] = uint8(1)
  41562 					num_colors = num_colors + 1
  41563 					if num_colors > int32(MAX_PALETTE_SIZE) {
  41564 						return libc.Int32FromInt32(MAX_PALETTE_SIZE) + libc.Int32FromInt32(1) // Exact count not needed.
  41565 					}
  41566 					break
  41567 				} else {
  41568 					if colors[key] == last_pix {
  41569 						break // The color is already there.
  41570 					} else {
  41571 						// Some other color sits here, so do linear conflict resolution.
  41572 						key = key + 1
  41573 						key = key & (libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4) - libc.Int32FromInt32(1)) // Key mask.
  41574 					}
  41575 				}
  41576 			}
  41577 			goto _2
  41578 		_2:
  41579 			;
  41580 			x = x + 1
  41581 		}
  41582 		argb1 = argb1 + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41583 		goto _1
  41584 	_1:
  41585 		;
  41586 		y = y + 1
  41587 	}
  41588 	if palette != libc.UintptrFromInt32(0) { // Fill the colors into palette.
  41589 		num_colors = 0
  41590 		i = 0
  41591 		for {
  41592 			if !(i < libc.Int32FromInt32(MAX_PALETTE_SIZE)*libc.Int32FromInt32(4)) {
  41593 				break
  41594 			}
  41595 			if in_use[i] != 0 {
  41596 				**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors)*4)) = colors[i]
  41597 				num_colors = num_colors + 1
  41598 			}
  41599 			goto _5
  41600 		_5:
  41601 			;
  41602 			i = i + 1
  41603 		}
  41604 		libc.Xqsort(tls, palette, libc.Uint64FromInt32(num_colors), uint64(4), __ccgo_fp(PaletteCompareColorsForQsort))
  41605 	}
  41606 	return num_colors
  41607 }
  41608 
  41609 // -----------------------------------------------------------------------------
  41610 
  41611 // C documentation
  41612 //
  41613 //	// The palette has been sorted by alpha. This function checks if the other
  41614 //	// components of the palette have a monotonic development with regards to
  41615 //	// position in the palette. If all have monotonic development, there is
  41616 //	// no benefit to re-organize them greedily. A monotonic development
  41617 //	// would be spotted in green-only situations (like lossy alpha) or gray-scale
  41618 //	// images.
  41619 func PaletteHasNonMonotonousDeltas(tls *libc.TLS, palette uintptr, num_colors int32) (r int32) {
  41620 	var alpha_and_green, diff, predict, red_and_blue, v2, v3, v4 uint32_t
  41621 	var bd, gd, rd, sign_found uint8_t
  41622 	var i, v6 int32
  41623 	_, _, _, _, _, _, _, _, _, _, _, _, _ = alpha_and_green, bd, diff, gd, i, predict, rd, red_and_blue, sign_found, v2, v3, v4, v6
  41624 	predict = uint32(0x000000)
  41625 	sign_found = uint8(0x00)
  41626 	i = 0
  41627 	for {
  41628 		if !(i < num_colors) {
  41629 			break
  41630 		}
  41631 		v2 = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41632 		v3 = predict
  41633 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  41634 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  41635 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  41636 		goto _5
  41637 	_5:
  41638 		diff = v4
  41639 		rd = uint8(diff >> libc.Int32FromInt32(16) & uint32(0xff))
  41640 		gd = uint8(diff >> libc.Int32FromInt32(8) & uint32(0xff))
  41641 		bd = uint8(diff >> libc.Int32FromInt32(0) & uint32(0xff))
  41642 		if libc.Int32FromUint8(rd) != 0x00 {
  41643 			if libc.Int32FromUint8(rd) < int32(0x80) {
  41644 				v6 = int32(1)
  41645 			} else {
  41646 				v6 = int32(2)
  41647 			}
  41648 			sign_found = libc.Uint8FromInt32(int32(sign_found) | v6)
  41649 		}
  41650 		if libc.Int32FromUint8(gd) != 0x00 {
  41651 			if libc.Int32FromUint8(gd) < int32(0x80) {
  41652 				v6 = int32(8)
  41653 			} else {
  41654 				v6 = int32(16)
  41655 			}
  41656 			sign_found = libc.Uint8FromInt32(int32(sign_found) | v6)
  41657 		}
  41658 		if libc.Int32FromUint8(bd) != 0x00 {
  41659 			if libc.Int32FromUint8(bd) < int32(0x80) {
  41660 				v6 = int32(64)
  41661 			} else {
  41662 				v6 = int32(128)
  41663 			}
  41664 			sign_found = libc.Uint8FromInt32(int32(sign_found) | v6)
  41665 		}
  41666 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41667 		goto _1
  41668 	_1:
  41669 		;
  41670 		i = i + 1
  41671 	}
  41672 	return libc.BoolInt32(libc.Int32FromUint8(sign_found)&(libc.Int32FromUint8(sign_found)<<int32(1)) != 0) // two consequent signs.
  41673 }
  41674 
  41675 func PaletteSortMinimizeDeltas(tls *libc.TLS, palette_sorted uintptr, num_colors int32, palette uintptr) {
  41676 	var best_ix, i, k int32
  41677 	var best_score, cur_score, predict uint32_t
  41678 	_, _, _, _, _, _ = best_ix, best_score, cur_score, i, k, predict
  41679 	predict = uint32(0x00000000)
  41680 	libc.Xmemcpy(tls, palette, palette_sorted, libc.Uint64FromInt32(num_colors)*uint64(4))
  41681 	if !(PaletteHasNonMonotonousDeltas(tls, palette_sorted, num_colors) != 0) {
  41682 		return
  41683 	}
  41684 	// Find greedily always the closest color of the predicted color to minimize
  41685 	// deltas in the palette. This reduces storage needs since the
  41686 	// palette is stored with delta encoding.
  41687 	if num_colors > int32(17) {
  41688 		if **(**uint32_t)(__ccgo_up(palette)) == uint32(0) {
  41689 			num_colors = num_colors - 1
  41690 			SwapColor(tls, palette+uintptr(num_colors)*4, palette)
  41691 		}
  41692 	}
  41693 	i = 0
  41694 	for {
  41695 		if !(i < num_colors) {
  41696 			break
  41697 		}
  41698 		best_ix = i
  41699 		best_score = ^libc.Uint32FromUint32(0)
  41700 		k = i
  41701 		for {
  41702 			if !(k < num_colors) {
  41703 				break
  41704 			}
  41705 			cur_score = PaletteColorDistance(tls, **(**uint32_t)(__ccgo_up(palette + uintptr(k)*4)), predict)
  41706 			if best_score > cur_score {
  41707 				best_score = cur_score
  41708 				best_ix = k
  41709 			}
  41710 			goto _2
  41711 		_2:
  41712 			;
  41713 			k = k + 1
  41714 		}
  41715 		SwapColor(tls, palette+uintptr(best_ix)*4, palette+uintptr(i)*4)
  41716 		predict = **(**uint32_t)(__ccgo_up(palette + uintptr(i)*4))
  41717 		goto _1
  41718 	_1:
  41719 		;
  41720 		i = i + 1
  41721 	}
  41722 }
  41723 
  41724 // -----------------------------------------------------------------------------
  41725 // Modified Zeng method from "A Survey on Palette Reordering
  41726 // Methods for Improving the Compression of Color-Indexed Images" by Armando J.
  41727 // Pinho and Antonio J. R. Neves.
  41728 
  41729 // C documentation
  41730 //
  41731 //	// Finds the biggest cooccurrence in the matrix.
  41732 func CoOccurrenceFindMax(tls *libc.TLS, cooccurrence uintptr, num_colors uint32_t, c1 uintptr, c2 uintptr) {
  41733 	var best_cooccurrence, best_sum, i, j, sum uint32_t
  41734 	_, _, _, _, _ = best_cooccurrence, best_sum, i, j, sum
  41735 	// Find the index that is most frequently located adjacent to other
  41736 	// (different) indexes.
  41737 	best_sum = 0
  41738 	**(**uint8_t)(__ccgo_up(c1)) = 0
  41739 	i = uint32(0)
  41740 	for {
  41741 		if !(i < num_colors) {
  41742 			break
  41743 		}
  41744 		sum = uint32(0)
  41745 		j = uint32(0)
  41746 		for {
  41747 			if !(j < num_colors) {
  41748 				break
  41749 			}
  41750 			sum = sum + **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(i*num_colors+j)*4))
  41751 			goto _2
  41752 		_2:
  41753 			;
  41754 			j = j + 1
  41755 		}
  41756 		if sum > best_sum {
  41757 			best_sum = sum
  41758 			**(**uint8_t)(__ccgo_up(c1)) = uint8(i)
  41759 		}
  41760 		goto _1
  41761 	_1:
  41762 		;
  41763 		i = i + 1
  41764 	}
  41765 	// Find the index that is most frequently found adjacent to *c1.
  41766 	**(**uint8_t)(__ccgo_up(c2)) = 0
  41767 	best_cooccurrence = 0
  41768 	i = uint32(0)
  41769 	for {
  41770 		if !(i < num_colors) {
  41771 			break
  41772 		}
  41773 		if **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4)) > best_cooccurrence {
  41774 			best_cooccurrence = **(**uint32_t)(__ccgo_up(cooccurrence + uintptr(uint32(**(**uint8_t)(__ccgo_up(c1)))*num_colors+i)*4))
  41775 			**(**uint8_t)(__ccgo_up(c2)) = uint8(i)
  41776 		}
  41777 		goto _3
  41778 	_3:
  41779 		;
  41780 		i = i + 1
  41781 	}
  41782 }
  41783 
  41784 // C documentation
  41785 //
  41786 //	// Builds the cooccurrence matrix
  41787 func CoOccurrenceBuild(tls *libc.TLS, pic uintptr, palette uintptr, num_colors uint32_t, cooccurrence uintptr) (r int32) {
  41788 	bp := tls.Alloc(2048)
  41789 	defer tls.Free(2048)
  41790 	var left_idx, pix, prev_idx, prev_pix, top_idx uint32_t
  41791 	var line_current, line_tmp, line_top, lines, src uintptr
  41792 	var x, y int32
  41793 	var _ /* idx_map at bp+0 */ [256]uint32_t
  41794 	var _ /* palette_sorted at bp+1024 */ [256]uint32_t
  41795 	_, _, _, _, _, _, _, _, _, _, _, _ = left_idx, line_current, line_tmp, line_top, lines, pix, prev_idx, prev_pix, src, top_idx, x, y
  41796 	src = (*WebPPicture)(unsafe.Pointer(pic)).Fargb
  41797 	prev_pix = ^**(**uint32_t)(__ccgo_up(src))
  41798 	prev_idx = 0
  41799 	**(**[256]uint32_t)(__ccgo_up(bp)) = [256]uint32_t{}
  41800 	lines = WebPSafeMalloc(tls, libc.Uint64FromInt32(int32(2)*(*WebPPicture)(unsafe.Pointer(pic)).Fwidth), uint64(4))
  41801 	if lines == libc.UintptrFromInt32(0) {
  41802 		return 0
  41803 	}
  41804 	line_top = lines
  41805 	line_current = lines + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fwidth)*4
  41806 	PrepareMapToPalette(tls, palette, num_colors, bp+1024, bp)
  41807 	y = 0
  41808 	for {
  41809 		if !(y < (*WebPPicture)(unsafe.Pointer(pic)).Fheight) {
  41810 			break
  41811 		}
  41812 		x = 0
  41813 		for {
  41814 			if !(x < (*WebPPicture)(unsafe.Pointer(pic)).Fwidth) {
  41815 				break
  41816 			}
  41817 			pix = **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))
  41818 			if pix != prev_pix {
  41819 				prev_idx = (**(**[256]uint32_t)(__ccgo_up(bp)))[SearchColorNoIdx(tls, bp+1024, pix, libc.Int32FromUint32(num_colors))]
  41820 				prev_pix = pix
  41821 			}
  41822 			**(**uint32_t)(__ccgo_up(line_current + uintptr(x)*4)) = prev_idx
  41823 			// 4-connectivity is what works best as mentioned in "On the relation
  41824 			// between Memon's and the modified Zeng's palette reordering methods".
  41825 			if x > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4)) {
  41826 				left_idx = **(**uint32_t)(__ccgo_up(line_current + uintptr(x-int32(1))*4))
  41827 				**(**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
  41828 				**(**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
  41829 			}
  41830 			if y > 0 && prev_idx != **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4)) {
  41831 				top_idx = **(**uint32_t)(__ccgo_up(line_top + uintptr(x)*4))
  41832 				**(**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
  41833 				**(**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
  41834 			}
  41835 			goto _2
  41836 		_2:
  41837 			;
  41838 			x = x + 1
  41839 		}
  41840 		line_tmp = line_top
  41841 		line_top = line_current
  41842 		line_current = line_tmp
  41843 		src = src + uintptr((*WebPPicture)(unsafe.Pointer(pic)).Fargb_stride)*4
  41844 		goto _1
  41845 	_1:
  41846 		;
  41847 		y = y + 1
  41848 	}
  41849 	WebPSafeFree(tls, lines)
  41850 	return int32(1)
  41851 }
  41852 
  41853 type Sum = struct {
  41854 	Findex uint8_t
  41855 	Fsum   uint32_t
  41856 }
  41857 
  41858 func PaletteSortModifiedZeng(tls *libc.TLS, pic uintptr, palette_in uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41859 	bp := tls.Alloc(2304)
  41860 	defer tls.Free(2304)
  41861 	var best_index uint8_t
  41862 	var best_sum, cooccurrence uintptr
  41863 	var delta, n int32_t
  41864 	var first, i, ind, j, last, num_sums uint32_t
  41865 	var l_j uint16_t
  41866 	var v3 uint32
  41867 	var _ /* remapping at bp+0 */ [256]uint8_t
  41868 	var _ /* sums at bp+256 */ [256]Sum
  41869 	_, _, _, _, _, _, _, _, _, _, _, _, _ = best_index, best_sum, cooccurrence, delta, first, i, ind, j, l_j, last, n, num_sums, v3
  41870 	// TODO(vrabaud) check whether one color images should use palette or not.
  41871 	if num_colors <= uint32(1) {
  41872 		return int32(1)
  41873 	}
  41874 	// Build the co-occurrence matrix.
  41875 	cooccurrence = WebPSafeCalloc(tls, uint64(num_colors*num_colors), uint64(4))
  41876 	if cooccurrence == libc.UintptrFromInt32(0) {
  41877 		return 0
  41878 	}
  41879 	if !(CoOccurrenceBuild(tls, pic, palette_in, num_colors, cooccurrence) != 0) {
  41880 		WebPSafeFree(tls, cooccurrence)
  41881 		return 0
  41882 	}
  41883 	// Initialize the mapping list with the two best indices.
  41884 	CoOccurrenceFindMax(tls, cooccurrence, num_colors, bp, bp+1)
  41885 	// We need to append and prepend to the list of remapping. To this end, we
  41886 	// actually define the next start/end of the list as indices in a vector (with
  41887 	// a wrap around when the end is reached).
  41888 	first = uint32(0)
  41889 	last = uint32(1)
  41890 	num_sums = num_colors - uint32(2) // -2 because we know the first two values
  41891 	if num_sums > uint32(0) {
  41892 		// Initialize the sums with the first two remappings and find the best one
  41893 		best_sum = bp + 256
  41894 		(*Sum)(unsafe.Pointer(best_sum)).Findex = 0
  41895 		(*Sum)(unsafe.Pointer(best_sum)).Fsum = 0
  41896 		i = uint32(0)
  41897 		j = libc.Uint32FromInt32(0)
  41898 		for {
  41899 			if !(i < num_colors) {
  41900 				break
  41901 			}
  41902 			if i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[0]) || i == uint32((**(**[256]uint8_t)(__ccgo_up(bp)))[int32(1)]) {
  41903 				goto _1
  41904 			}
  41905 			(**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Findex = uint8(i)
  41906 			(**(**[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))
  41907 			if (**(**[256]Sum)(__ccgo_up(bp + 256)))[j].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41908 				best_sum = bp + 256 + uintptr(j)*8
  41909 			}
  41910 			j = j + 1
  41911 			goto _1
  41912 		_1:
  41913 			;
  41914 			i = i + 1
  41915 		}
  41916 		for num_sums > uint32(0) {
  41917 			best_index = (*Sum)(unsafe.Pointer(best_sum)).Findex
  41918 			// Compute delta to know if we need to prepend or append the best index.
  41919 			delta = 0
  41920 			n = libc.Int32FromUint32(num_colors - num_sums)
  41921 			ind = first
  41922 			j = libc.Uint32FromInt32(0)
  41923 			for {
  41924 				if !((ind+j)%num_colors != last+uint32(1)) {
  41925 					break
  41926 				}
  41927 				l_j = uint16((**(**[256]uint8_t)(__ccgo_up(bp)))[(ind+j)%num_colors])
  41928 				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)))
  41929 				goto _2
  41930 			_2:
  41931 				;
  41932 				j = j + 1
  41933 			}
  41934 			if delta > 0 {
  41935 				if first == uint32(0) {
  41936 					v3 = num_colors - uint32(1)
  41937 				} else {
  41938 					v3 = first - uint32(1)
  41939 				}
  41940 				first = v3
  41941 				(**(**[256]uint8_t)(__ccgo_up(bp)))[first] = best_index
  41942 			} else {
  41943 				last = last + 1
  41944 				(**(**[256]uint8_t)(__ccgo_up(bp)))[last] = best_index
  41945 			}
  41946 			// Remove best_sum from sums.
  41947 			**(**Sum)(__ccgo_up(best_sum)) = (**(**[256]Sum)(__ccgo_up(bp + 256)))[num_sums-uint32(1)]
  41948 			num_sums = num_sums - 1
  41949 			// Update all the sums and find the best one.
  41950 			best_sum = bp + 256
  41951 			i = uint32(0)
  41952 			for {
  41953 				if !(i < num_sums) {
  41954 					break
  41955 				}
  41956 				(**(**[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))
  41957 				if (**(**[256]Sum)(__ccgo_up(bp + 256)))[i].Fsum > (*Sum)(unsafe.Pointer(best_sum)).Fsum {
  41958 					best_sum = bp + 256 + uintptr(i)*8
  41959 				}
  41960 				goto _4
  41961 			_4:
  41962 				;
  41963 				i = i + 1
  41964 			}
  41965 		}
  41966 	}
  41967 	WebPSafeFree(tls, cooccurrence)
  41968 	// Re-map the palette.
  41969 	i = uint32(0)
  41970 	for {
  41971 		if !(i < num_colors) {
  41972 			break
  41973 		}
  41974 		**(**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))
  41975 		goto _5
  41976 	_5:
  41977 		;
  41978 		i = i + 1
  41979 	}
  41980 	return int32(1)
  41981 }
  41982 
  41983 // -----------------------------------------------------------------------------
  41984 
  41985 func PaletteSort(tls *libc.TLS, method PaletteSorting1, pic uintptr, palette_sorted uintptr, num_colors uint32_t, palette uintptr) (r int32) {
  41986 	switch method {
  41987 	case int32(kSortedDefault):
  41988 		if **(**uint32_t)(__ccgo_up(palette_sorted)) == uint32(0) && num_colors > uint32(17) {
  41989 			libc.Xmemcpy(tls, palette, palette_sorted+uintptr(1)*4, uint64(num_colors-libc.Uint32FromInt32(1))*uint64(4))
  41990 			**(**uint32_t)(__ccgo_up(palette + uintptr(num_colors-uint32(1))*4)) = uint32(0)
  41991 		} else {
  41992 			libc.Xmemcpy(tls, palette, palette_sorted, uint64(num_colors)*uint64(4))
  41993 		}
  41994 		return int32(1)
  41995 	case int32(kMinimizeDelta):
  41996 		PaletteSortMinimizeDeltas(tls, palette_sorted, libc.Int32FromUint32(num_colors), palette)
  41997 		return int32(1)
  41998 	case int32(kModifiedZeng):
  41999 		return PaletteSortModifiedZeng(tls, pic, palette_sorted, num_colors, palette)
  42000 	case int32(kUnusedPalette):
  42001 		fallthrough
  42002 	case int32(kPaletteSortingNum):
  42003 		break
  42004 	}
  42005 	return 0
  42006 }
  42007 
  42008 const DFIX = 0
  42009 const FIX = 16
  42010 const LFIX = 2
  42011 
  42012 //------------------------------------------------------------------------------
  42013 
  42014 // Copyright 2010 Google Inc. All Rights Reserved.
  42015 //
  42016 // Use of this source code is governed by a BSD-style license
  42017 // that can be found in the COPYING file in the root of the source
  42018 // tree. An additional intellectual property rights grant can be found
  42019 // in the file PATENTS. All contributing project authors may
  42020 // be found in the AUTHORS file in the root of the source tree.
  42021 // -----------------------------------------------------------------------------
  42022 //
  42023 //  Common types + memory wrappers
  42024 //
  42025 // Author: Skal (pascal.massimino@gmail.com)
  42026 
  42027 // #define USE_DITHERING   // uncomment to enable ordered dithering (not vital)
  42028 
  42029 type SmoothParams = struct {
  42030 	Fwidth          int32
  42031 	Fheight         int32
  42032 	Fstride         int32
  42033 	Frow            int32
  42034 	Fsrc            uintptr
  42035 	Fdst            uintptr
  42036 	Fradius         int32
  42037 	Fscale          int32
  42038 	Fmem            uintptr
  42039 	Fstart          uintptr
  42040 	Fcur            uintptr
  42041 	Fend            uintptr
  42042 	Ftop            uintptr
  42043 	Faverage        uintptr
  42044 	Fnum_levels     int32
  42045 	Fmin            int32
  42046 	Fmax            int32
  42047 	Fmin_level_dist int32
  42048 	Fcorrection     uintptr
  42049 }
  42050 
  42051 //------------------------------------------------------------------------------
  42052 
  42053 func clip_8b(tls *libc.TLS, v int32) (r uint8_t) {
  42054 	var v1, v2 uint32
  42055 	_, _ = v1, v2
  42056 	if !(v&libc.Int32FromUint32(^libc.Uint32FromUint32(0)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(DFIX))) != 0) {
  42057 		v1 = uint32(libc.Uint8FromInt32(v >> libc.Int32FromInt32(DFIX)))
  42058 	} else {
  42059 		if v < 0 {
  42060 			v2 = 0
  42061 		} else {
  42062 			v2 = uint32(255)
  42063 		}
  42064 		v1 = v2
  42065 	}
  42066 	return uint8(v1)
  42067 }
  42068 
  42069 // C documentation
  42070 //
  42071 //	// vertical accumulation
  42072 func VFilter(tls *libc.TLS, p uintptr) {
  42073 	var cur, out, src, top uintptr
  42074 	var new_value, sum uint16_t
  42075 	var w, x int32
  42076 	_, _, _, _, _, _, _, _ = cur, new_value, out, src, sum, top, w, x
  42077 	src = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  42078 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42079 	cur = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  42080 	top = (*SmoothParams)(unsafe.Pointer(p)).Ftop
  42081 	out = (*SmoothParams)(unsafe.Pointer(p)).Fend
  42082 	sum = uint16(0)
  42083 	x = 0
  42084 	for {
  42085 		if !(x < w) {
  42086 			break
  42087 		}
  42088 		sum = libc.Uint16FromInt32(int32(sum) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + uintptr(x)))))
  42089 		new_value = libc.Uint16FromInt32(libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(top + uintptr(x)*2))) + libc.Int32FromUint16(sum))
  42090 		**(**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.
  42091 		**(**uint16_t)(__ccgo_up(cur + uintptr(x)*2)) = new_value
  42092 		goto _1
  42093 	_1:
  42094 		;
  42095 		x = x + 1
  42096 	}
  42097 	// move input pointers one row down
  42098 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fcur
  42099 	**(**uintptr)(__ccgo_up(p + 56)) += uintptr(w) * 2
  42100 	if (*SmoothParams)(unsafe.Pointer(p)).Fcur == (*SmoothParams)(unsafe.Pointer(p)).Fend {
  42101 		(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42102 	} // roll-over
  42103 	// We replicate edges, as it's somewhat easier as a boundary condition.
  42104 	// That's why we don't update the 'src' pointer on top/bottom area:
  42105 	if (*SmoothParams)(unsafe.Pointer(p)).Frow >= 0 && (*SmoothParams)(unsafe.Pointer(p)).Frow < (*SmoothParams)(unsafe.Pointer(p)).Fheight-int32(1) {
  42106 		**(**uintptr)(__ccgo_up(p + 16)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  42107 	}
  42108 }
  42109 
  42110 // C documentation
  42111 //
  42112 //	// horizontal accumulation. We use mirror replication of missing pixels, as it's
  42113 //	// a little easier to implement (surprisingly).
  42114 func HFilter(tls *libc.TLS, p uintptr) {
  42115 	var delta, delta1, delta2 uint16_t
  42116 	var in, out uintptr
  42117 	var r, w, x int32
  42118 	var scale uint32_t
  42119 	_, _, _, _, _, _, _, _, _ = delta, delta1, delta2, in, out, r, scale, w, x
  42120 	in = (*SmoothParams)(unsafe.Pointer(p)).Fend
  42121 	out = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  42122 	scale = libc.Uint32FromInt32((*SmoothParams)(unsafe.Pointer(p)).Fscale)
  42123 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42124 	r = (*SmoothParams)(unsafe.Pointer(p)).Fradius
  42125 	x = 0
  42126 	for {
  42127 		if !(x <= r) {
  42128 			break
  42129 		} // left mirroring
  42130 		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))))
  42131 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta) * scale >> int32(FIX))
  42132 		goto _1
  42133 	_1:
  42134 		;
  42135 		x = x + 1
  42136 	}
  42137 	for {
  42138 		if !(x < w-r) {
  42139 			break
  42140 		} // bulk middle run
  42141 		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))))
  42142 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta1) * scale >> int32(FIX))
  42143 		goto _2
  42144 	_2:
  42145 		;
  42146 		x = x + 1
  42147 	}
  42148 	for {
  42149 		if !(x < w) {
  42150 			break
  42151 		} // right mirroring
  42152 		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))))
  42153 		**(**uint16_t)(__ccgo_up(out + uintptr(x)*2)) = uint16(uint32(delta2) * scale >> int32(FIX))
  42154 		goto _3
  42155 	_3:
  42156 		;
  42157 		x = x + 1
  42158 	}
  42159 }
  42160 
  42161 // C documentation
  42162 //
  42163 //	// emit one filtered output row
  42164 func ApplyFilter(tls *libc.TLS, p uintptr) {
  42165 	var average, correction, dst uintptr
  42166 	var c, v, w, x int32
  42167 	_, _, _, _, _, _, _ = average, c, correction, dst, v, w, x
  42168 	average = (*SmoothParams)(unsafe.Pointer(p)).Faverage
  42169 	w = (*SmoothParams)(unsafe.Pointer(p)).Fwidth
  42170 	correction = (*SmoothParams)(unsafe.Pointer(p)).Fcorrection
  42171 	dst = (*SmoothParams)(unsafe.Pointer(p)).Fdst
  42172 	x = 0
  42173 	for {
  42174 		if !(x < w) {
  42175 			break
  42176 		}
  42177 		v = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(x))))
  42178 		if v < (*SmoothParams)(unsafe.Pointer(p)).Fmax && v > (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  42179 			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)))
  42180 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = clip_8b(tls, c)
  42181 		}
  42182 		goto _1
  42183 	_1:
  42184 		;
  42185 		x = x + 1
  42186 	}
  42187 	**(**uintptr)(__ccgo_up(p + 24)) += uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride) // advance output pointer
  42188 }
  42189 
  42190 //------------------------------------------------------------------------------
  42191 // Initialize correction table
  42192 
  42193 func InitCorrectionLUT(tls *libc.TLS, lut uintptr, min_dist int32) {
  42194 	var c, delta, i, max_threshold, threshold1, threshold2, v2, v3 int32
  42195 	_, _, _, _, _, _, _, _ = c, delta, i, max_threshold, threshold1, threshold2, v2, v3
  42196 	// The correction curve is:
  42197 	//   f(x) = x for x <= threshold2
  42198 	//   f(x) = 0 for x >= threshold1
  42199 	// and a linear interpolation for range x=[threshold2, threshold1]
  42200 	// (along with f(-x) = -f(x) symmetry).
  42201 	// Note that: threshold2 = 3/4 * threshold1
  42202 	threshold1 = min_dist << int32(LFIX)
  42203 	threshold2 = int32(3) * threshold1 >> int32(2)
  42204 	max_threshold = threshold2 << DFIX
  42205 	delta = threshold1 - threshold2
  42206 	i = int32(1)
  42207 	for {
  42208 		if !(i <= libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1)) {
  42209 			break
  42210 		}
  42211 		if i <= threshold2 {
  42212 			v2 = i << DFIX
  42213 		} else {
  42214 			if i < threshold1 {
  42215 				v3 = max_threshold * (threshold1 - i) / delta
  42216 			} else {
  42217 				v3 = 0
  42218 			}
  42219 			v2 = v3
  42220 		}
  42221 		c = v2
  42222 		c = c >> int32(LFIX)
  42223 		**(**int16_t)(__ccgo_up(lut + uintptr(+i)*2)) = int16(+c)
  42224 		**(**int16_t)(__ccgo_up(lut + uintptr(-i)*2)) = int16(-c)
  42225 		goto _1
  42226 	_1:
  42227 		;
  42228 		i = i + 1
  42229 	}
  42230 	**(**int16_t)(__ccgo_up(lut)) = 0
  42231 }
  42232 
  42233 func CountLevels(tls *libc.TLS, p uintptr) {
  42234 	var data uintptr
  42235 	var i, j, last_level, level_dist, v int32
  42236 	var used_levels [256]uint8_t
  42237 	_, _, _, _, _, _, _ = data, i, j, last_level, level_dist, used_levels, v
  42238 	used_levels = [256]uint8_t{}
  42239 	data = (*SmoothParams)(unsafe.Pointer(p)).Fsrc
  42240 	(*SmoothParams)(unsafe.Pointer(p)).Fmin = int32(255)
  42241 	(*SmoothParams)(unsafe.Pointer(p)).Fmax = 0
  42242 	j = 0
  42243 	for {
  42244 		if !(j < (*SmoothParams)(unsafe.Pointer(p)).Fheight) {
  42245 			break
  42246 		}
  42247 		i = 0
  42248 		for {
  42249 			if !(i < (*SmoothParams)(unsafe.Pointer(p)).Fwidth) {
  42250 				break
  42251 			}
  42252 			v = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(i))))
  42253 			if v < (*SmoothParams)(unsafe.Pointer(p)).Fmin {
  42254 				(*SmoothParams)(unsafe.Pointer(p)).Fmin = v
  42255 			}
  42256 			if v > (*SmoothParams)(unsafe.Pointer(p)).Fmax {
  42257 				(*SmoothParams)(unsafe.Pointer(p)).Fmax = v
  42258 			}
  42259 			used_levels[v] = uint8(1)
  42260 			goto _2
  42261 		_2:
  42262 			;
  42263 			i = i + 1
  42264 		}
  42265 		data = data + uintptr((*SmoothParams)(unsafe.Pointer(p)).Fstride)
  42266 		goto _1
  42267 	_1:
  42268 		;
  42269 		j = j + 1
  42270 	}
  42271 	// Compute the mininum distance between two non-zero levels.
  42272 	(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = (*SmoothParams)(unsafe.Pointer(p)).Fmax - (*SmoothParams)(unsafe.Pointer(p)).Fmin
  42273 	last_level = -int32(1)
  42274 	i = 0
  42275 	for {
  42276 		if !(i < int32(256)) {
  42277 			break
  42278 		}
  42279 		if used_levels[i] != 0 {
  42280 			(*SmoothParams)(unsafe.Pointer(p)).Fnum_levels = (*SmoothParams)(unsafe.Pointer(p)).Fnum_levels + 1
  42281 			if last_level >= 0 {
  42282 				level_dist = i - last_level
  42283 				if level_dist < (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist {
  42284 					(*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist = level_dist
  42285 				}
  42286 			}
  42287 			last_level = i
  42288 		}
  42289 		goto _3
  42290 	_3:
  42291 		;
  42292 		i = i + 1
  42293 	}
  42294 }
  42295 
  42296 // C documentation
  42297 //
  42298 //	// Initialize all params.
  42299 func InitParams(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, radius int32, p uintptr) (r int32) {
  42300 	var R int32
  42301 	var mem uintptr
  42302 	var size_lut, size_m, size_scratch_m, total_size size_t
  42303 	_, _, _, _, _, _ = R, mem, size_lut, size_m, size_scratch_m, total_size
  42304 	R = int32(2)*radius + int32(1) // total size of the kernel
  42305 	size_scratch_m = libc.Uint64FromInt32((R+int32(1))*width) * uint64(2)
  42306 	size_m = libc.Uint64FromInt32(width) * uint64(2)
  42307 	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)
  42308 	total_size = size_scratch_m + size_m + size_lut
  42309 	mem = WebPSafeMalloc(tls, uint64(1), total_size)
  42310 	if mem == libc.UintptrFromInt32(0) {
  42311 		return 0
  42312 	}
  42313 	(*SmoothParams)(unsafe.Pointer(p)).Fmem = mem
  42314 	(*SmoothParams)(unsafe.Pointer(p)).Fstart = mem
  42315 	(*SmoothParams)(unsafe.Pointer(p)).Fcur = (*SmoothParams)(unsafe.Pointer(p)).Fstart
  42316 	(*SmoothParams)(unsafe.Pointer(p)).Fend = (*SmoothParams)(unsafe.Pointer(p)).Fstart + uintptr(R*width)*2
  42317 	(*SmoothParams)(unsafe.Pointer(p)).Ftop = (*SmoothParams)(unsafe.Pointer(p)).Fend - uintptr(width)*2
  42318 	libc.Xmemset(tls, (*SmoothParams)(unsafe.Pointer(p)).Ftop, 0, libc.Uint64FromInt32(width)*uint64(2))
  42319 	mem = mem + uintptr(size_scratch_m)
  42320 	(*SmoothParams)(unsafe.Pointer(p)).Faverage = mem
  42321 	mem = mem + uintptr(size_m)
  42322 	(*SmoothParams)(unsafe.Pointer(p)).Fwidth = width
  42323 	(*SmoothParams)(unsafe.Pointer(p)).Fheight = height
  42324 	(*SmoothParams)(unsafe.Pointer(p)).Fstride = stride
  42325 	(*SmoothParams)(unsafe.Pointer(p)).Fsrc = data
  42326 	(*SmoothParams)(unsafe.Pointer(p)).Fdst = data
  42327 	(*SmoothParams)(unsafe.Pointer(p)).Fradius = radius
  42328 	(*SmoothParams)(unsafe.Pointer(p)).Fscale = libc.Int32FromInt32(1) << (libc.Int32FromInt32(FIX) + libc.Int32FromInt32(LFIX)) / (R * R) // normalization constant
  42329 	(*SmoothParams)(unsafe.Pointer(p)).Frow = -radius
  42330 	// analyze the input distribution so we can best-fit the threshold
  42331 	CountLevels(tls, p)
  42332 	// correction table
  42333 	(*SmoothParams)(unsafe.Pointer(p)).Fcorrection = mem + uintptr(libc.Int32FromInt32(1)<<(libc.Int32FromInt32(8)+libc.Int32FromInt32(LFIX))-libc.Int32FromInt32(1))*2
  42334 	InitCorrectionLUT(tls, (*SmoothParams)(unsafe.Pointer(p)).Fcorrection, (*SmoothParams)(unsafe.Pointer(p)).Fmin_level_dist)
  42335 	return int32(1)
  42336 }
  42337 
  42338 func CleanupParams(tls *libc.TLS, p uintptr) {
  42339 	WebPSafeFree(tls, (*SmoothParams)(unsafe.Pointer(p)).Fmem)
  42340 }
  42341 
  42342 func WebPDequantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, strength int32) (r int32) {
  42343 	bp := tls.Alloc(112)
  42344 	defer tls.Free(112)
  42345 	var radius int32
  42346 	var _ /* p at bp+0 */ SmoothParams
  42347 	_ = radius
  42348 	radius = int32(4) * strength / int32(100)
  42349 	if strength < 0 || strength > int32(100) {
  42350 		return 0
  42351 	}
  42352 	if data == libc.UintptrFromInt32(0) || width <= 0 || height <= 0 {
  42353 		return 0
  42354 	} // bad params
  42355 	// limit the filter size to not exceed the image dimensions
  42356 	if int32(2)*radius+int32(1) > width {
  42357 		radius = (width - int32(1)) >> int32(1)
  42358 	}
  42359 	if int32(2)*radius+int32(1) > height {
  42360 		radius = (height - int32(1)) >> int32(1)
  42361 	}
  42362 	if radius > 0 {
  42363 		libc.Xmemset(tls, bp, 0, uint64(112))
  42364 		if !(InitParams(tls, data, width, height, stride, radius, bp) != 0) {
  42365 			return 0
  42366 		}
  42367 		if (**(**SmoothParams)(__ccgo_up(bp))).Fnum_levels > int32(2) {
  42368 			for {
  42369 				if !((**(**SmoothParams)(__ccgo_up(bp))).Frow < (**(**SmoothParams)(__ccgo_up(bp))).Fheight) {
  42370 					break
  42371 				}
  42372 				VFilter(tls, bp) // accumulate average of input
  42373 				// Need to wait few rows in order to prime the filter,
  42374 				// before emitting some output.
  42375 				if (**(**SmoothParams)(__ccgo_up(bp))).Frow >= (**(**SmoothParams)(__ccgo_up(bp))).Fradius {
  42376 					HFilter(tls, bp)
  42377 					ApplyFilter(tls, bp)
  42378 				}
  42379 				goto _1
  42380 			_1:
  42381 				;
  42382 				(**(**SmoothParams)(__ccgo_up(bp))).Frow = (**(**SmoothParams)(__ccgo_up(bp))).Frow + 1
  42383 			}
  42384 		}
  42385 		CleanupParams(tls, bp)
  42386 	}
  42387 	return int32(1)
  42388 }
  42389 
  42390 const ERROR_THRESHOLD = 0.0001
  42391 const MAX_ITER = 6
  42392 const NUM_SYMBOLS = 256
  42393 
  42394 // -----------------------------------------------------------------------------
  42395 // Quantize levels.
  42396 
  42397 func QuantizeLevels(tls *libc.TLS, data uintptr, width int32, height int32, num_levels int32, sse uintptr) (r int32) {
  42398 	bp := tls.Alloc(4096)
  42399 	defer tls.Free(4096)
  42400 	var count, err, err_threshold, error1, last_err float64
  42401 	var data_size, n, n1 size_t
  42402 	var freq, q_level [256]int32
  42403 	var i, iter, max_s, min_s, num_levels_in, s, s1, slot, slot1 int32
  42404 	var inv_q_level [256]float64
  42405 	var map1 [256]uint8_t
  42406 	var _ /* q_count at bp+2048 */ [256]float64
  42407 	var _ /* q_sum at bp+0 */ [256]float64
  42408 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  42409 	freq = [256]int32{}
  42410 	q_level = [256]int32{}
  42411 	inv_q_level = [256]float64{}
  42412 	min_s = int32(255)
  42413 	max_s = 0
  42414 	data_size = libc.Uint64FromInt32(height * width)
  42415 	last_err = float64(1e+38)
  42416 	err = float64(0)
  42417 	err_threshold = float64(float64(0.0001) * float64(data_size))
  42418 	if data == libc.UintptrFromInt32(0) {
  42419 		return 0
  42420 	}
  42421 	if width <= 0 || height <= 0 {
  42422 		return 0
  42423 	}
  42424 	if num_levels < int32(2) || num_levels > int32(256) {
  42425 		return 0
  42426 	}
  42427 	num_levels_in = 0
  42428 	n = uint64(0)
  42429 	for {
  42430 		if !(n < data_size) {
  42431 			break
  42432 		}
  42433 		num_levels_in = num_levels_in + libc.BoolInt32(freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] == 0)
  42434 		if min_s > libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42435 			min_s = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42436 		}
  42437 		if max_s < libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n)))) {
  42438 			max_s = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(data + uintptr(n))))
  42439 		}
  42440 		freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] = freq[**(**uint8_t)(__ccgo_up(data + uintptr(n)))] + 1
  42441 		goto _1
  42442 	_1:
  42443 		;
  42444 		n = n + 1
  42445 	}
  42446 	if num_levels_in <= num_levels {
  42447 		goto End
  42448 	} // nothing to do!
  42449 	// Start with uniformly spread centroids.
  42450 	i = 0
  42451 	for {
  42452 		if !(i < num_levels) {
  42453 			break
  42454 		}
  42455 		inv_q_level[i] = float64(min_s) + float64(float64(max_s-min_s)*float64(i))/float64(num_levels-libc.Int32FromInt32(1))
  42456 		goto _2
  42457 	_2:
  42458 		;
  42459 		i = i + 1
  42460 	}
  42461 	// Fixed values. Won't be changed.
  42462 	q_level[min_s] = 0
  42463 	q_level[max_s] = num_levels - int32(1)
  42464 	// k-Means iterations.
  42465 	iter = 0
  42466 	for {
  42467 		if !(iter < int32(MAX_ITER)) {
  42468 			break
  42469 		}
  42470 		**(**[256]float64)(__ccgo_up(bp)) = [256]float64{}
  42471 		**(**[256]float64)(__ccgo_up(bp + 2048)) = [256]float64{}
  42472 		slot = 0
  42473 		// Assign classes to representatives.
  42474 		s = min_s
  42475 		for {
  42476 			if !(s <= max_s) {
  42477 				break
  42478 			}
  42479 			// Keep track of the nearest neighbour 'slot'
  42480 			for slot < num_levels-int32(1) && float64(int32(2)*s) > inv_q_level[slot]+inv_q_level[slot+int32(1)] {
  42481 				slot = slot + 1
  42482 			}
  42483 			if freq[s] > 0 {
  42484 				**(**float64)(__ccgo_up(bp + uintptr(slot)*8)) += float64(s * freq[s])
  42485 				**(**float64)(__ccgo_up(bp + 2048 + uintptr(slot)*8)) += float64(freq[s])
  42486 			}
  42487 			q_level[s] = slot
  42488 			goto _4
  42489 		_4:
  42490 			;
  42491 			s = s + 1
  42492 		}
  42493 		// Assign new representatives to classes.
  42494 		if num_levels > int32(2) {
  42495 			slot = int32(1)
  42496 			for {
  42497 				if !(slot < num_levels-int32(1)) {
  42498 					break
  42499 				}
  42500 				count = (**(**[256]float64)(__ccgo_up(bp + 2048)))[slot]
  42501 				if count > float64(0) {
  42502 					inv_q_level[slot] = (**(**[256]float64)(__ccgo_up(bp)))[slot] / count
  42503 				}
  42504 				goto _5
  42505 			_5:
  42506 				;
  42507 				slot = slot + 1
  42508 			}
  42509 		}
  42510 		// Compute convergence error.
  42511 		err = float64(0)
  42512 		s = min_s
  42513 		for {
  42514 			if !(s <= max_s) {
  42515 				break
  42516 			}
  42517 			error1 = float64(s) - inv_q_level[q_level[s]]
  42518 			err = err + float64(float64(float64(freq[s])*error1)*error1)
  42519 			goto _6
  42520 		_6:
  42521 			;
  42522 			s = s + 1
  42523 		}
  42524 		// Check for convergence: we stop as soon as the error is no
  42525 		// longer improving.
  42526 		if last_err-err < err_threshold {
  42527 			break
  42528 		}
  42529 		last_err = err
  42530 		goto _3
  42531 	_3:
  42532 		;
  42533 		iter = iter + 1
  42534 	}
  42535 	// Remap the alpha plane to quantized values.
  42536 	s1 = min_s
  42537 	for {
  42538 		if !(s1 <= max_s) {
  42539 			break
  42540 		}
  42541 		slot1 = q_level[s1]
  42542 		map1[s1] = uint8(inv_q_level[slot1] + libc.Float64FromFloat64(0.5))
  42543 		goto _7
  42544 	_7:
  42545 		;
  42546 		s1 = s1 + 1
  42547 	}
  42548 	// Final pass.
  42549 	n1 = uint64(0)
  42550 	for {
  42551 		if !(n1 < data_size) {
  42552 			break
  42553 		}
  42554 		**(**uint8_t)(__ccgo_up(data + uintptr(n1))) = map1[**(**uint8_t)(__ccgo_up(data + uintptr(n1)))]
  42555 		goto _8
  42556 	_8:
  42557 		;
  42558 		n1 = n1 + 1
  42559 	}
  42560 	goto End
  42561 End:
  42562 	;
  42563 	// Store sum of squared error if needed.
  42564 	if sse != libc.UintptrFromInt32(0) {
  42565 		**(**uint64_t)(__ccgo_up(sse)) = uint64(err)
  42566 	}
  42567 	return int32(1)
  42568 }
  42569 
  42570 //------------------------------------------------------------------------------
  42571 
  42572 // C documentation
  42573 //
  42574 //	// 31b-range values
  42575 var kRandomTable = [55]uint32_t{
  42576 	0:  uint32(0x0de15230),
  42577 	1:  uint32(0x03b31886),
  42578 	2:  uint32(0x775faccb),
  42579 	3:  uint32(0x1c88626a),
  42580 	4:  uint32(0x68385c55),
  42581 	5:  uint32(0x14b3b828),
  42582 	6:  uint32(0x4a85fef8),
  42583 	7:  uint32(0x49ddb84b),
  42584 	8:  uint32(0x64fcf397),
  42585 	9:  uint32(0x5c550289),
  42586 	10: uint32(0x4a290000),
  42587 	11: uint32(0x0d7ec1da),
  42588 	12: uint32(0x5940b7ab),
  42589 	13: uint32(0x5492577d),
  42590 	14: uint32(0x4e19ca72),
  42591 	15: uint32(0x38d38c69),
  42592 	16: uint32(0x0c01ee65),
  42593 	17: uint32(0x32a1755f),
  42594 	18: uint32(0x5437f652),
  42595 	19: uint32(0x5abb2c32),
  42596 	20: uint32(0x0faa57b1),
  42597 	21: uint32(0x73f533e7),
  42598 	22: uint32(0x685feeda),
  42599 	23: uint32(0x7563cce2),
  42600 	24: uint32(0x6e990e83),
  42601 	25: uint32(0x4730a7ed),
  42602 	26: uint32(0x4fc0d9c6),
  42603 	27: uint32(0x496b153c),
  42604 	28: uint32(0x4f1403fa),
  42605 	29: uint32(0x541afb0c),
  42606 	30: uint32(0x73990b32),
  42607 	31: uint32(0x26d7cb1c),
  42608 	32: uint32(0x6fcc3706),
  42609 	33: uint32(0x2cbb77d8),
  42610 	34: uint32(0x75762f2a),
  42611 	35: uint32(0x6425ccdd),
  42612 	36: uint32(0x24b35461),
  42613 	37: uint32(0x0a7d8715),
  42614 	38: uint32(0x220414a8),
  42615 	39: uint32(0x141ebf67),
  42616 	40: uint32(0x56b41583),
  42617 	41: uint32(0x73e502e3),
  42618 	42: uint32(0x44cab16f),
  42619 	43: uint32(0x28264d42),
  42620 	44: uint32(0x73baaefb),
  42621 	45: uint32(0x0a50ebed),
  42622 	46: uint32(0x1d6ab6fb),
  42623 	47: uint32(0x0d3ad40b),
  42624 	48: uint32(0x35db3b68),
  42625 	49: uint32(0x2b081e83),
  42626 	50: uint32(0x77ce6b95),
  42627 	51: uint32(0x5181e5f0),
  42628 	52: uint32(0x78853bbc),
  42629 	53: uint32(0x009f9494),
  42630 	54: uint32(0x27e5ed3c),
  42631 }
  42632 
  42633 func VP8InitRandom(tls *libc.TLS, rg uintptr, dithering float32) {
  42634 	var v1, v2 uint32
  42635 	_, _ = v1, v2
  42636 	libc.Xmemcpy(tls, rg+8, uintptr(unsafe.Pointer(&kRandomTable)), uint64(220))
  42637 	(*VP8Random)(unsafe.Pointer(rg)).Findex1 = 0
  42638 	(*VP8Random)(unsafe.Pointer(rg)).Findex2 = int32(31)
  42639 	if float64(dithering) < float64(0) {
  42640 		v1 = uint32(0)
  42641 	} else {
  42642 		if float64(dithering) > float64(1) {
  42643 			v2 = libc.Uint32FromInt32(libc.Int32FromInt32(1) << libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX))
  42644 		} else {
  42645 			v2 = uint32(float32(float32(libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_RANDOM_DITHER_FIX)) * dithering))
  42646 		}
  42647 		v1 = v2
  42648 	}
  42649 	(*VP8Random)(unsafe.Pointer(rg)).Famp = libc.Int32FromUint32(v1)
  42650 }
  42651 
  42652 //------------------------------------------------------------------------------
  42653 
  42654 //------------------------------------------------------------------------------
  42655 
  42656 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) {
  42657 	var den, num, ratio, total_size, v1 uint64_t
  42658 	var x_add, x_sub, y_add, y_sub, v2 int32
  42659 	_, _, _, _, _, _, _, _, _, _ = den, num, ratio, total_size, x_add, x_sub, y_add, y_sub, v1, v2
  42660 	x_add = src_width
  42661 	x_sub = dst_width
  42662 	y_add = src_height
  42663 	y_sub = dst_height
  42664 	total_size = uint64(uint64(2) * libc.Uint64FromInt32(dst_width) * libc.Uint64FromInt32(num_channels) * uint64(4))
  42665 	v1 = total_size
  42666 	v2 = libc.BoolInt32(v1 == v1)
  42667 	goto _3
  42668 _3:
  42669 	if !(v2 != 0) {
  42670 		return 0
  42671 	}
  42672 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand = libc.BoolInt32(src_width < dst_width)
  42673 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand = libc.BoolInt32(src_height < dst_height)
  42674 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_width = src_width
  42675 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_height = src_height
  42676 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_width = dst_width
  42677 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_height = dst_height
  42678 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fsrc_y = 0
  42679 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_y = 0
  42680 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst = dst
  42681 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fdst_stride = dst_stride
  42682 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fnum_channels = num_channels
  42683 	// for 'x_expand', we use bilinear interpolation
  42684 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42685 		v2 = x_sub - int32(1)
  42686 	} else {
  42687 		v2 = x_add
  42688 	}
  42689 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add = v2
  42690 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0 {
  42691 		v2 = x_add - int32(1)
  42692 	} else {
  42693 		v2 = x_sub
  42694 	}
  42695 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_sub = v2
  42696 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_expand != 0) { // fx_scale is not used otherwise
  42697 		(*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))
  42698 	}
  42699 	// vertical scaling parameters
  42700 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42701 		v2 = y_add - int32(1)
  42702 	} else {
  42703 		v2 = y_add
  42704 	}
  42705 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add = v2
  42706 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42707 		v2 = y_sub - int32(1)
  42708 	} else {
  42709 		v2 = y_sub
  42710 	}
  42711 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub = v2
  42712 	if (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0 {
  42713 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42714 	} else {
  42715 		v2 = (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add
  42716 	}
  42717 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum = v2
  42718 	if !((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_expand != 0) {
  42719 		// This is WEBP_RESCALER_FRAC(dst_height, x_add * y_add) without the cast.
  42720 		// Its value is <= WEBP_RESCALER_ONE, because dst_height <= rescaler->y_add
  42721 		// and rescaler->x_add >= 1;
  42722 		num = uint64(uint64(libc.Uint64FromInt32(dst_height)) * (libc.Uint64FromUint64(1) << libc.Int32FromInt32(WEBP_RESCALER_RFIX)))
  42723 		den = libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fx_add) * libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_add)
  42724 		ratio = num / den
  42725 		if ratio != uint64(uint32(ratio)) {
  42726 			// When ratio == WEBP_RESCALER_ONE, we can't represent the ratio with the
  42727 			// current fixed-point precision. This happens when src_height ==
  42728 			// rescaler->y_add (which == src_height), and rescaler->x_add == 1.
  42729 			// => We special-case fxy_scale = 0, in WebPRescalerExportRow().
  42730 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(0)
  42731 		} else {
  42732 			(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffxy_scale = uint32(ratio)
  42733 		}
  42734 		(*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))
  42735 	} else {
  42736 		(*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))
  42737 		// rescaler->fxy_scale is unused here.
  42738 	}
  42739 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Firow = work
  42740 	(*WebPRescaler)(unsafe.Pointer(rescaler)).Ffrow = work + uintptr(num_channels*dst_width)*4
  42741 	libc.Xmemset(tls, work, 0, total_size)
  42742 	WebPRescalerDspInit(tls)
  42743 	return int32(1)
  42744 }
  42745 
  42746 func WebPRescalerGetScaledDimensions(tls *libc.TLS, src_width int32, src_height int32, scaled_width uintptr, scaled_height uintptr) (r int32) {
  42747 	var height, max_size, width int32
  42748 	_, _, _ = height, max_size, width
  42749 	width = **(**int32)(__ccgo_up(scaled_width))
  42750 	height = **(**int32)(__ccgo_up(scaled_height))
  42751 	max_size = libc.Int32FromInt32(INT_MAX) / libc.Int32FromInt32(2)
  42752 	// if width is unspecified, scale original proportionally to height ratio.
  42753 	if width == 0 && src_height > 0 {
  42754 		width = libc.Int32FromUint64((libc.Uint64FromInt32(src_width)*libc.Uint64FromInt32(height) + libc.Uint64FromInt32(src_height) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt32(src_height))
  42755 	}
  42756 	// if height is unspecified, scale original proportionally to width ratio.
  42757 	if height == 0 && src_width > 0 {
  42758 		height = libc.Int32FromUint64((libc.Uint64FromInt32(src_height)*libc.Uint64FromInt32(width) + libc.Uint64FromInt32(src_width) - libc.Uint64FromInt32(1)) / libc.Uint64FromInt32(src_width))
  42759 	}
  42760 	// Check if the overall dimensions still make sense.
  42761 	if width <= 0 || height <= 0 || width > max_size || height > max_size {
  42762 		return 0
  42763 	}
  42764 	**(**int32)(__ccgo_up(scaled_width)) = width
  42765 	**(**int32)(__ccgo_up(scaled_height)) = height
  42766 	return int32(1)
  42767 	return r
  42768 }
  42769 
  42770 //------------------------------------------------------------------------------
  42771 // all-in-one calls
  42772 
  42773 func WebPRescaleNeededLines(tls *libc.TLS, rescaler uintptr, max_num_lines int32) (r int32) {
  42774 	var num_lines, v1 int32
  42775 	_, _ = num_lines, v1
  42776 	num_lines = ((*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_accum + (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub - int32(1)) / (*WebPRescaler)(unsafe.Pointer(rescaler)).Fy_sub
  42777 	if num_lines > max_num_lines {
  42778 		v1 = max_num_lines
  42779 	} else {
  42780 		v1 = num_lines
  42781 	}
  42782 	return v1
  42783 }
  42784 
  42785 func WebPRescalerImport(tls *libc.TLS, rescaler2 uintptr, num_lines int32, src uintptr, src_stride int32) (r int32) {
  42786 	var tmp, v1, v4 uintptr
  42787 	var total_imported, x, v2, v5 int32
  42788 	var v7 bool
  42789 	_, _, _, _, _, _, _, _ = tmp, total_imported, x, v1, v2, v4, v5, v7
  42790 	total_imported = 0
  42791 	for {
  42792 		if v7 = total_imported < num_lines; v7 {
  42793 			v1 = rescaler2
  42794 			v4 = v1
  42795 			v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42796 			goto _6
  42797 		_6:
  42798 			;
  42799 			v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42800 			goto _3
  42801 		_3:
  42802 		}
  42803 		if !(v7 && !(v2 != 0)) {
  42804 			break
  42805 		}
  42806 		if (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0 {
  42807 			tmp = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow
  42808 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow
  42809 			(*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow = tmp
  42810 		}
  42811 		WebPRescalerImportRow(tls, rescaler2, src)
  42812 		if !((*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_expand != 0) {
  42813 			x = 0
  42814 			for {
  42815 				if !(x < (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fdst_width) {
  42816 					break
  42817 				}
  42818 				**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Firow + uintptr(x)*4)) += **(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(rescaler2)).Ffrow + uintptr(x)*4))
  42819 				goto _8
  42820 			_8:
  42821 				;
  42822 				x = x + 1
  42823 			}
  42824 		}
  42825 		(*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y = (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fsrc_y + 1
  42826 		src = src + uintptr(src_stride)
  42827 		total_imported = total_imported + 1
  42828 		**(**int32)(__ccgo_up(rescaler2 + 24)) -= (*WebPRescaler)(unsafe.Pointer(rescaler2)).Fy_sub
  42829 	}
  42830 	return total_imported
  42831 }
  42832 
  42833 func WebPRescalerExport(tls *libc.TLS, rescaler2 uintptr) (r int32) {
  42834 	var total_exported, v2, v5 int32
  42835 	var v1, v4 uintptr
  42836 	_, _, _, _, _ = total_exported, v1, v2, v4, v5
  42837 	total_exported = 0
  42838 	for {
  42839 		v1 = rescaler2
  42840 		v4 = v1
  42841 		v5 = libc.BoolInt32((*WebPRescaler)(unsafe.Pointer(v4)).Fdst_y >= (*WebPRescaler)(unsafe.Pointer(v4)).Fdst_height)
  42842 		goto _6
  42843 	_6:
  42844 		;
  42845 		v2 = libc.BoolInt32(!(v5 != 0) && (*WebPRescaler)(unsafe.Pointer(v1)).Fy_accum <= 0)
  42846 		goto _3
  42847 	_3:
  42848 		if !(v2 != 0) {
  42849 			break
  42850 		}
  42851 		WebPRescalerExportRow(tls, rescaler2)
  42852 		total_exported = total_exported + 1
  42853 	}
  42854 	return total_exported
  42855 }
  42856 
  42857 //------------------------------------------------------------------------------
  42858 
  42859 //------------------------------------------------------------------------------
  42860 
  42861 func Init(tls *libc.TLS, worker uintptr) {
  42862 	libc.Xmemset(tls, worker, 0, uint64(48))
  42863 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42864 }
  42865 
  42866 func Sync(tls *libc.TLS, worker uintptr) (r int32) {
  42867 	return libc.BoolInt32(!((*WebPWorker)(unsafe.Pointer(worker)).Fhad_error != 0))
  42868 }
  42869 
  42870 func Reset(tls *libc.TLS, worker uintptr) (r int32) {
  42871 	var ok int32
  42872 	_ = ok
  42873 	ok = int32(1)
  42874 	(*WebPWorker)(unsafe.Pointer(worker)).Fhad_error = 0
  42875 	if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus < int32(OK) {
  42876 		(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(OK)
  42877 	} else {
  42878 		if (*WebPWorker)(unsafe.Pointer(worker)).Fstatus > int32(OK) {
  42879 			ok = Sync(tls, worker)
  42880 		}
  42881 	}
  42882 	return ok
  42883 }
  42884 
  42885 func Execute(tls *libc.TLS, worker uintptr) {
  42886 	if (*WebPWorker)(unsafe.Pointer(worker)).Fhook != libc.UintptrFromInt32(0) {
  42887 		**(**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))
  42888 	}
  42889 }
  42890 
  42891 func Launch(tls *libc.TLS, worker uintptr) {
  42892 	Execute(tls, worker)
  42893 }
  42894 
  42895 func End(tls *libc.TLS, worker uintptr) {
  42896 	(*WebPWorker)(unsafe.Pointer(worker)).Fstatus = int32(NOT_OK)
  42897 }
  42898 
  42899 //------------------------------------------------------------------------------
  42900 
  42901 var g_worker_interface = WebPWorkerInterface{}
  42902 
  42903 func init() {
  42904 	p := unsafe.Pointer(&g_worker_interface)
  42905 	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(Init)
  42906 	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(Reset)
  42907 	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(Sync)
  42908 	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(Launch)
  42909 	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(Execute)
  42910 	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(End)
  42911 }
  42912 
  42913 func WebPSetWorkerInterface(tls *libc.TLS, winterface uintptr) (r int32) {
  42914 	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) {
  42915 		return 0
  42916 	}
  42917 	g_worker_interface = **(**WebPWorkerInterface)(__ccgo_up(winterface))
  42918 	return int32(1)
  42919 }
  42920 
  42921 func WebPGetWorkerInterface(tls *libc.TLS) (r uintptr) {
  42922 	return uintptr(unsafe.Pointer(&g_worker_interface))
  42923 }
  42924 
  42925 //------------------------------------------------------------------------------
  42926 
  42927 // If PRINT_MEM_INFO is defined, extra info (like total memory used, number of
  42928 // alloc/free etc) is printed. For debugging/tuning purpose only (it's slow,
  42929 // and not multi-thread safe!).
  42930 // An interesting alternative is valgrind's 'massif' tool:
  42931 //    https://valgrind.org/docs/manual/ms-manual.html
  42932 // Here is an example command line:
  42933 /*    valgrind --tool=massif --massif-out-file=massif.out                --stacks=yes --alloc-fn=WebPSafeMalloc --alloc-fn=WebPSafeCalloc
  42934       ms_print massif.out
  42935 */
  42936 // In addition:
  42937 // * if PRINT_MEM_TRAFFIC is defined, all the details of the malloc/free cycles
  42938 //   are printed.
  42939 // * if MALLOC_FAIL_AT is defined, the global environment variable
  42940 //   $MALLOC_FAIL_AT is used to simulate a memory error when calloc or malloc
  42941 //   is called for the nth time. Example usage:
  42942 //   export MALLOC_FAIL_AT=50 && ./examples/cwebp input.png
  42943 // * if MALLOC_LIMIT is defined, the global environment variable $MALLOC_LIMIT
  42944 //   sets the maximum amount of memory (in bytes) made available to libwebp.
  42945 //   This can be used to emulate environment with very limited memory.
  42946 //   Example: export MALLOC_LIMIT=64000000 && ./examples/dwebp picture.webp
  42947 
  42948 // #define PRINT_MEM_INFO
  42949 // #define PRINT_MEM_TRAFFIC
  42950 // #define MALLOC_FAIL_AT
  42951 // #define MALLOC_LIMIT
  42952 
  42953 //------------------------------------------------------------------------------
  42954 // Checked memory allocation
  42955 
  42956 // C documentation
  42957 //
  42958 //	// Returns 0 in case of overflow of nmemb * size.
  42959 func CheckSizeArgumentsOverflow(tls *libc.TLS, nmemb uint64_t, size1 size_t) (r int32) {
  42960 	var total_size, v1 uint64_t
  42961 	var v2 int32
  42962 	_, _, _ = total_size, v1, v2
  42963 	total_size = nmemb * size1
  42964 	if nmemb == uint64(0) {
  42965 		return int32(1)
  42966 	}
  42967 	if size1 > libc.Uint64FromUint64(1)<<libc.Int32FromInt32(34)/nmemb {
  42968 		return 0
  42969 	}
  42970 	v1 = total_size
  42971 	v2 = libc.BoolInt32(v1 == v1)
  42972 	goto _3
  42973 _3:
  42974 	if !(v2 != 0) {
  42975 		return 0
  42976 	}
  42977 	return int32(1)
  42978 }
  42979 
  42980 func WebPSafeMalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42981 	var ptr uintptr
  42982 	_ = ptr
  42983 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42984 		return libc.UintptrFromInt32(0)
  42985 	}
  42986 	ptr = libc.Xmalloc(tls, nmemb*size)
  42987 	return ptr
  42988 }
  42989 
  42990 func WebPSafeCalloc(tls *libc.TLS, nmemb uint64_t, size size_t) (r uintptr) {
  42991 	var ptr uintptr
  42992 	_ = ptr
  42993 	if !(CheckSizeArgumentsOverflow(tls, nmemb, size) != 0) {
  42994 		return libc.UintptrFromInt32(0)
  42995 	}
  42996 	ptr = libc.Xcalloc(tls, nmemb, size)
  42997 	return ptr
  42998 }
  42999 
  43000 func WebPSafeFree(tls *libc.TLS, ptr uintptr) {
  43001 	if ptr != libc.UintptrFromInt32(0) {
  43002 	}
  43003 	libc.Xfree(tls, ptr)
  43004 }
  43005 
  43006 // Public API functions.
  43007 
  43008 func WebPMalloc(tls *libc.TLS, size size_t) (r uintptr) {
  43009 	return WebPSafeMalloc(tls, uint64(1), size)
  43010 }
  43011 
  43012 func WebPFree(tls *libc.TLS, ptr uintptr) {
  43013 	WebPSafeFree(tls, ptr)
  43014 }
  43015 
  43016 //------------------------------------------------------------------------------
  43017 
  43018 func WebPCopyPlane(tls *libc.TLS, src uintptr, src_stride int32, dst uintptr, dst_stride int32, width int32, height int32) {
  43019 	var v1 int32
  43020 	_ = v1
  43021 	for {
  43022 		v1 = height
  43023 		height = height - 1
  43024 		if !(v1 > 0) {
  43025 			break
  43026 		}
  43027 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(width))
  43028 		src = src + uintptr(src_stride)
  43029 		dst = dst + uintptr(dst_stride)
  43030 	}
  43031 }
  43032 
  43033 func WebPCopyPixels(tls *libc.TLS, src uintptr, dst uintptr) {
  43034 	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)
  43035 }
  43036 
  43037 //------------------------------------------------------------------------------
  43038 
  43039 func WebPGetColorPalette(tls *libc.TLS, pic uintptr, palette uintptr) (r int32) {
  43040 	return GetColorPalette(tls, pic, palette)
  43041 }
  43042 
  43043 const USE_TABLES_FOR_ALPHA_MULT = 0
  43044 
  43045 // Copyright 2010 Google Inc. All Rights Reserved.
  43046 //
  43047 // Use of this source code is governed by a BSD-style license
  43048 // that can be found in the COPYING file in the root of the source
  43049 // tree. An additional intellectual property rights grant can be found
  43050 // in the file PATENTS. All contributing project authors may
  43051 // be found in the AUTHORS file in the root of the source tree.
  43052 // -----------------------------------------------------------------------------
  43053 //
  43054 //  Common types + memory wrappers
  43055 //
  43056 // Author: Skal (pascal.massimino@gmail.com)
  43057 
  43058 // Tables can be faster on some platform but incur some extra binary size (~2k).
  43059 
  43060 // -----------------------------------------------------------------------------
  43061 
  43062 func Mult(tls *libc.TLS, x uint8_t, mult uint32_t) (r uint32_t) {
  43063 	var v uint32_t
  43064 	_ = v
  43065 	v = (uint32(x)*mult + libc.Uint32FromUint32(1)<<libc.Int32FromInt32(24)>>libc.Int32FromInt32(1)) >> int32(24)
  43066 	// <- 24bit precision is enough to ensure that.
  43067 	return v
  43068 }
  43069 
  43070 func GetScale(tls *libc.TLS, a uint32_t, inverse int32) (r uint32_t) {
  43071 	var v1 uint32
  43072 	_ = v1
  43073 	if inverse != 0 {
  43074 		v1 = libc.Uint32FromUint32(255) << libc.Int32FromInt32(24) / a
  43075 	} else {
  43076 		v1 = a * (libc.Uint32FromUint32(1) << libc.Int32FromInt32(24) / libc.Uint32FromUint32(255))
  43077 	}
  43078 	return v1
  43079 }
  43080 
  43081 func WebPMultARGBRow_C(tls *libc.TLS, ptr uintptr, width int32, inverse int32) {
  43082 	var alpha, argb, out, scale uint32_t
  43083 	var x int32
  43084 	_, _, _, _, _ = alpha, argb, out, scale, x
  43085 	x = 0
  43086 	for {
  43087 		if !(x < width) {
  43088 			break
  43089 		}
  43090 		argb = **(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4))
  43091 		if argb < uint32(0xff000000) { // alpha < 255
  43092 			if argb <= uint32(0x00ffffff) { // alpha == 0
  43093 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = uint32(0)
  43094 			} else {
  43095 				alpha = argb >> libc.Int32FromInt32(24) & uint32(0xff)
  43096 				scale = GetScale(tls, alpha, inverse)
  43097 				out = argb & uint32(0xff000000)
  43098 				out = out | Mult(tls, uint8(argb>>0), scale)<<0
  43099 				out = out | Mult(tls, uint8(argb>>int32(8)), scale)<<int32(8)
  43100 				out = out | Mult(tls, uint8(argb>>int32(16)), scale)<<int32(16)
  43101 				**(**uint32_t)(__ccgo_up(ptr + uintptr(x)*4)) = out
  43102 			}
  43103 		}
  43104 		goto _1
  43105 	_1:
  43106 		;
  43107 		x = x + 1
  43108 	}
  43109 }
  43110 
  43111 func WebPMultRow_C(tls *libc.TLS, ptr uintptr, alpha uintptr, width int32, inverse int32) {
  43112 	var a, scale uint32_t
  43113 	var x int32
  43114 	_, _, _ = a, scale, x
  43115 	x = 0
  43116 	for {
  43117 		if !(x < width) {
  43118 			break
  43119 		}
  43120 		a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(x))))
  43121 		if a != uint32(255) {
  43122 			if a == uint32(0) {
  43123 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(0)
  43124 			} else {
  43125 				scale = GetScale(tls, a, inverse)
  43126 				**(**uint8_t)(__ccgo_up(ptr + uintptr(x))) = uint8(Mult(tls, **(**uint8_t)(__ccgo_up(ptr + uintptr(x))), scale))
  43127 			}
  43128 		}
  43129 		goto _1
  43130 	_1:
  43131 		;
  43132 		x = x + 1
  43133 	}
  43134 }
  43135 
  43136 //------------------------------------------------------------------------------
  43137 // Generic per-plane calls
  43138 
  43139 func WebPMultARGBRows(tls *libc.TLS, ptr uintptr, stride int32, width int32, num_rows int32, inverse int32) {
  43140 	var n int32
  43141 	_ = n
  43142 	n = 0
  43143 	for {
  43144 		if !(n < num_rows) {
  43145 			break
  43146 		}
  43147 		(*(*func(*libc.TLS, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultARGBRow})))(tls, ptr, width, inverse)
  43148 		ptr = ptr + uintptr(stride)
  43149 		goto _1
  43150 	_1:
  43151 		;
  43152 		n = n + 1
  43153 	}
  43154 }
  43155 
  43156 func WebPMultRows(tls *libc.TLS, ptr uintptr, stride int32, alpha uintptr, alpha_stride int32, width int32, num_rows int32, inverse int32) {
  43157 	var n int32
  43158 	_ = n
  43159 	n = 0
  43160 	for {
  43161 		if !(n < num_rows) {
  43162 			break
  43163 		}
  43164 		(*(*func(*libc.TLS, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPMultRow})))(tls, ptr, alpha, width, inverse)
  43165 		ptr = ptr + uintptr(stride)
  43166 		alpha = alpha + uintptr(alpha_stride)
  43167 		goto _1
  43168 	_1:
  43169 		;
  43170 		n = n + 1
  43171 	}
  43172 }
  43173 
  43174 //------------------------------------------------------------------------------
  43175 // Premultiplied modes
  43176 
  43177 // non dithered-modes
  43178 
  43179 // (x * a * 32897) >> 23 is bit-wise equivalent to (int)(x * a / 255.)
  43180 // for all 8bit x or a. For bit-wise equivalence to (int)(x * a / 255. + .5),
  43181 // one can use instead: (x * a * 65793 + (1 << 23)) >> 24
  43182 
  43183 func ApplyAlphaMultiply_C(tls *libc.TLS, rgba uintptr, alpha_first int32, w int32, h int32, stride int32) {
  43184 	var a, mult uint32_t
  43185 	var alpha, rgb uintptr
  43186 	var i, v1, v2, v3 int32
  43187 	_, _, _, _, _, _, _, _ = a, alpha, i, mult, rgb, v1, v2, v3
  43188 	for {
  43189 		v1 = h
  43190 		h = h - 1
  43191 		if !(v1 > 0) {
  43192 			break
  43193 		}
  43194 		if alpha_first != 0 {
  43195 			v2 = int32(1)
  43196 		} else {
  43197 			v2 = 0
  43198 		}
  43199 		rgb = rgba + uintptr(v2)
  43200 		if alpha_first != 0 {
  43201 			v3 = 0
  43202 		} else {
  43203 			v3 = int32(3)
  43204 		}
  43205 		alpha = rgba + uintptr(v3)
  43206 		i = 0
  43207 		for {
  43208 			if !(i < w) {
  43209 				break
  43210 			}
  43211 			a = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(int32(4)*i))))
  43212 			if a != uint32(0xff) {
  43213 				mult = a * libc.Uint32FromUint32(32897)
  43214 				**(**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))
  43215 				**(**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))
  43216 				**(**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))
  43217 			}
  43218 			goto _4
  43219 		_4:
  43220 			;
  43221 			i = i + 1
  43222 		}
  43223 		rgba = rgba + uintptr(stride)
  43224 	}
  43225 }
  43226 
  43227 // rgbA4444
  43228 
  43229 func dither_hi(tls *libc.TLS, x uint8_t) (r uint8_t) {
  43230 	return libc.Uint8FromInt32(libc.Int32FromUint8(x)&int32(0xf0) | libc.Int32FromUint8(x)>>int32(4))
  43231 }
  43232 
  43233 func dither_lo(tls *libc.TLS, x uint8_t) (r uint8_t) {
  43234 	return libc.Uint8FromInt32(libc.Int32FromUint8(x)&int32(0x0f) | libc.Int32FromUint8(x)<<int32(4))
  43235 }
  43236 
  43237 func multiply(tls *libc.TLS, x uint8_t, m uint32_t) (r uint8_t) {
  43238 	return uint8(uint32(x) * m >> int32(16))
  43239 }
  43240 
  43241 func ApplyAlphaMultiply4444_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32, rg_byte_pos int32) {
  43242 	var a, b, g, r uint8_t
  43243 	var ba, mult, rg uint32_t
  43244 	var i, v1 int32
  43245 	_, _, _, _, _, _, _, _, _ = a, b, ba, g, i, mult, r, rg, v1
  43246 	for {
  43247 		v1 = h
  43248 		h = h - 1
  43249 		if !(v1 > 0) {
  43250 			break
  43251 		}
  43252 		i = 0
  43253 		for {
  43254 			if !(i < w) {
  43255 				break
  43256 			}
  43257 			rg = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+rg_byte_pos))))
  43258 			ba = uint32(**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))))
  43259 			a = uint8(ba & uint32(0x0f))
  43260 			mult = libc.Uint32FromInt32(libc.Int32FromUint8(a) * libc.Int32FromInt32(0x1111))
  43261 			r = multiply(tls, dither_hi(tls, uint8(rg)), mult)
  43262 			g = multiply(tls, dither_lo(tls, uint8(rg)), mult)
  43263 			b = multiply(tls, dither_hi(tls, uint8(ba)), mult)
  43264 			**(**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))
  43265 			**(**uint8_t)(__ccgo_up(rgba4444 + uintptr(int32(2)*i+(rg_byte_pos^int32(1))))) = libc.Uint8FromInt32(libc.Int32FromUint8(b)&int32(0xf0) | libc.Int32FromUint8(a))
  43266 			goto _2
  43267 		_2:
  43268 			;
  43269 			i = i + 1
  43270 		}
  43271 		rgba4444 = rgba4444 + uintptr(stride)
  43272 	}
  43273 }
  43274 
  43275 func ApplyAlphaMultiply_16b_C(tls *libc.TLS, rgba4444 uintptr, w int32, h int32, stride int32) {
  43276 	ApplyAlphaMultiply4444_C(tls, rgba4444, w, h, stride, 0)
  43277 }
  43278 
  43279 func DispatchAlpha_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) (r int32) {
  43280 	var alpha_mask, alpha_value uint32_t
  43281 	var i, j int32
  43282 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43283 	alpha_mask = uint32(0xff)
  43284 	j = 0
  43285 	for {
  43286 		if !(j < height) {
  43287 			break
  43288 		}
  43289 		i = 0
  43290 		for {
  43291 			if !(i < width) {
  43292 				break
  43293 			}
  43294 			alpha_value = uint32(**(**uint8_t)(__ccgo_up(alpha + uintptr(i))))
  43295 			**(**uint8_t)(__ccgo_up(dst + uintptr(int32(4)*i))) = uint8(alpha_value)
  43296 			alpha_mask = alpha_mask & alpha_value
  43297 			goto _2
  43298 		_2:
  43299 			;
  43300 			i = i + 1
  43301 		}
  43302 		alpha = alpha + uintptr(alpha_stride)
  43303 		dst = dst + uintptr(dst_stride)
  43304 		goto _1
  43305 	_1:
  43306 		;
  43307 		j = j + 1
  43308 	}
  43309 	return libc.BoolInt32(alpha_mask != uint32(0xff))
  43310 }
  43311 
  43312 func DispatchAlphaToGreen_C(tls *libc.TLS, alpha uintptr, alpha_stride int32, width int32, height int32, dst uintptr, dst_stride int32) {
  43313 	var i, j int32
  43314 	_, _ = i, j
  43315 	j = 0
  43316 	for {
  43317 		if !(j < height) {
  43318 			break
  43319 		}
  43320 		i = 0
  43321 		for {
  43322 			if !(i < width) {
  43323 				break
  43324 			}
  43325 			**(**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.
  43326 			goto _2
  43327 		_2:
  43328 			;
  43329 			i = i + 1
  43330 		}
  43331 		alpha = alpha + uintptr(alpha_stride)
  43332 		dst = dst + uintptr(dst_stride)*4
  43333 		goto _1
  43334 	_1:
  43335 		;
  43336 		j = j + 1
  43337 	}
  43338 }
  43339 
  43340 func ExtractAlpha_C(tls *libc.TLS, argb uintptr, argb_stride int32, width int32, height int32, alpha uintptr, alpha_stride int32) (r int32) {
  43341 	var alpha_mask, alpha_value uint8_t
  43342 	var i, j int32
  43343 	_, _, _, _ = alpha_mask, alpha_value, i, j
  43344 	alpha_mask = uint8(0xff)
  43345 	j = 0
  43346 	for {
  43347 		if !(j < height) {
  43348 			break
  43349 		}
  43350 		i = 0
  43351 		for {
  43352 			if !(i < width) {
  43353 				break
  43354 			}
  43355 			alpha_value = **(**uint8_t)(__ccgo_up(argb + uintptr(int32(4)*i)))
  43356 			**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = alpha_value
  43357 			alpha_mask = libc.Uint8FromInt32(int32(alpha_mask) & libc.Int32FromUint8(alpha_value))
  43358 			goto _2
  43359 		_2:
  43360 			;
  43361 			i = i + 1
  43362 		}
  43363 		argb = argb + uintptr(argb_stride)
  43364 		alpha = alpha + uintptr(alpha_stride)
  43365 		goto _1
  43366 	_1:
  43367 		;
  43368 		j = j + 1
  43369 	}
  43370 	return libc.BoolInt32(libc.Int32FromUint8(alpha_mask) == int32(0xff))
  43371 }
  43372 
  43373 func ExtractGreen_C(tls *libc.TLS, argb uintptr, alpha uintptr, size int32) {
  43374 	var i int32
  43375 	_ = i
  43376 	i = 0
  43377 	for {
  43378 		if !(i < size) {
  43379 			break
  43380 		}
  43381 		**(**uint8_t)(__ccgo_up(alpha + uintptr(i))) = uint8(**(**uint32_t)(__ccgo_up(argb + uintptr(i)*4)) >> int32(8))
  43382 		goto _1
  43383 	_1:
  43384 		;
  43385 		i = i + 1
  43386 	}
  43387 }
  43388 
  43389 //------------------------------------------------------------------------------
  43390 
  43391 func HasAlpha8b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43392 	var v1 int32
  43393 	var v2 uintptr
  43394 	_, _ = v1, v2
  43395 	for {
  43396 		v1 = length
  43397 		length = length - 1
  43398 		if !(v1 > 0) {
  43399 			break
  43400 		}
  43401 		v2 = src
  43402 		src = src + 1
  43403 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v2))) != int32(0xff) {
  43404 			return int32(1)
  43405 		}
  43406 	}
  43407 	return 0
  43408 }
  43409 
  43410 func HasAlpha32b_C(tls *libc.TLS, src uintptr, length int32) (r int32) {
  43411 	var x, v2 int32
  43412 	_, _ = x, v2
  43413 	x = 0
  43414 	for {
  43415 		v2 = length
  43416 		length = length - 1
  43417 		if !(v2 > 0) {
  43418 			break
  43419 		}
  43420 		if libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + uintptr(x)))) != int32(0xff) {
  43421 			return int32(1)
  43422 		}
  43423 		goto _1
  43424 	_1:
  43425 		;
  43426 		x = x + int32(4)
  43427 	}
  43428 	return 0
  43429 }
  43430 
  43431 func AlphaReplace_C(tls *libc.TLS, src uintptr, length int32, color uint32_t) {
  43432 	var x int32
  43433 	_ = x
  43434 	x = 0
  43435 	for {
  43436 		if !(x < length) {
  43437 			break
  43438 		}
  43439 		if **(**uint32_t)(__ccgo_up(src + uintptr(x)*4))>>libc.Int32FromInt32(24) == uint32(0) {
  43440 			**(**uint32_t)(__ccgo_up(src + uintptr(x)*4)) = color
  43441 		}
  43442 		goto _1
  43443 	_1:
  43444 		;
  43445 		x = x + 1
  43446 	}
  43447 }
  43448 
  43449 //------------------------------------------------------------------------------
  43450 // Simple channel manipulations.
  43451 
  43452 func MakeARGB321(tls *libc.TLS, a int32, r int32, g int32, b int32) (r1 uint32_t) {
  43453 	return libc.Uint32FromInt32(a)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  43454 }
  43455 
  43456 func PackRGB_C(tls *libc.TLS, r uintptr, g uintptr, b uintptr, len1 int32, step int32, out uintptr) {
  43457 	var i, offset int32
  43458 	_, _ = i, offset
  43459 	offset = 0
  43460 	i = 0
  43461 	for {
  43462 		if !(i < len1) {
  43463 			break
  43464 		}
  43465 		**(**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)))))
  43466 		offset = offset + step
  43467 		goto _1
  43468 	_1:
  43469 		;
  43470 		i = i + 1
  43471 	}
  43472 }
  43473 
  43474 func WebPInitAlphaProcessing(tls *libc.TLS) {
  43475 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43476 		goto _1
  43477 	}
  43478 	WebPInitAlphaProcessing_body(tls)
  43479 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43480 	goto _2
  43481 _2:
  43482 	;
  43483 	goto _1
  43484 _1: /**/ //
  43485 }
  43486 
  43487 var WebPInitAlphaProcessing_body_last_cpuinfo_used = uintptr(0)
  43488 
  43489 func init() {
  43490 	p := unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used)
  43491 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitAlphaProcessing_body_last_cpuinfo_used))
  43492 }
  43493 
  43494 func WebPInitAlphaProcessing_body(tls *libc.TLS) {
  43495 	WebPMultARGBRow = __ccgo_fp(WebPMultARGBRow_C)
  43496 	WebPMultRow = __ccgo_fp(WebPMultRow_C)
  43497 	WebPApplyAlphaMultiply4444 = __ccgo_fp(ApplyAlphaMultiply_16b_C)
  43498 	WebPPackRGB = __ccgo_fp(PackRGB_C)
  43499 	WebPApplyAlphaMultiply = __ccgo_fp(ApplyAlphaMultiply_C)
  43500 	WebPDispatchAlpha = __ccgo_fp(DispatchAlpha_C)
  43501 	WebPDispatchAlphaToGreen = __ccgo_fp(DispatchAlphaToGreen_C)
  43502 	WebPExtractAlpha = __ccgo_fp(ExtractAlpha_C)
  43503 	WebPExtractGreen = __ccgo_fp(ExtractGreen_C)
  43504 	WebPHasAlpha8b = __ccgo_fp(HasAlpha8b_C)
  43505 	WebPHasAlpha32b = __ccgo_fp(HasAlpha32b_C)
  43506 	WebPAlphaReplace = __ccgo_fp(AlphaReplace_C)
  43507 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43508 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43509 	}
  43510 }
  43511 
  43512 func WebPInitAlphaProcessingMIPSdspR2(tls *libc.TLS) {
  43513 }
  43514 
  43515 func WebPInitAlphaProcessingNEON(tls *libc.TLS) {
  43516 }
  43517 
  43518 func WebPInitAlphaProcessingSSE2(tls *libc.TLS) {
  43519 }
  43520 
  43521 func WebPInitAlphaProcessingSSE41(tls *libc.TLS) {
  43522 }
  43523 
  43524 //------------------------------------------------------------------------------
  43525 // Mode costs
  43526 
  43527 func GetResidualCost_C(tls *libc.TLS, ctx0 int32, res uintptr) (r int32) {
  43528 	var b, cost, ctx, ctx1, last_p0, n, p0, v, v1, v11, v3, v5, v7, v9 int32
  43529 	var costs CostArrayPtr
  43530 	var t uintptr
  43531 	var v2, v6 uint8_t
  43532 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, cost, costs, ctx, ctx1, last_p0, n, p0, t, v, v1, v11, v2, v3, v5, v6, v7, v9
  43533 	n = (*VP8Residual)(unsafe.Pointer(res)).Ffirst
  43534 	// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
  43535 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(n)*33 + uintptr(ctx0)*11)))
  43536 	costs = (*VP8Residual)(unsafe.Pointer(res)).Fcosts
  43537 	t = **(**uintptr)(__ccgo_up(costs + uintptr(n)*24 + uintptr(ctx0)*8))
  43538 	if ctx0 == 0 {
  43539 		v2 = libc.Uint8FromInt32(p0)
  43540 		if !(int32(1) != 0) {
  43541 			v5 = libc.Int32FromUint16(VP8EntropyCost[v2])
  43542 		} else {
  43543 			v5 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v2)])
  43544 		}
  43545 		v3 = v5
  43546 		goto _4
  43547 	_4:
  43548 		v11 = v3
  43549 	} else {
  43550 		v11 = 0
  43551 	}
  43552 	// bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
  43553 	// (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
  43554 	// be missing during the loop.
  43555 	cost = v11
  43556 	if (*VP8Residual)(unsafe.Pointer(res)).Flast < 0 {
  43557 		v6 = libc.Uint8FromInt32(p0)
  43558 		if !(0 != 0) {
  43559 			v9 = libc.Int32FromUint16(VP8EntropyCost[v6])
  43560 		} else {
  43561 			v9 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v6)])
  43562 		}
  43563 		v7 = v9
  43564 		goto _8
  43565 	_8:
  43566 		return v7
  43567 	}
  43568 	for {
  43569 		if !(n < (*VP8Residual)(unsafe.Pointer(res)).Flast) {
  43570 			break
  43571 		}
  43572 		v = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43573 		if v >= int32(2) {
  43574 			v11 = int32(2)
  43575 		} else {
  43576 			v11 = v
  43577 		}
  43578 		ctx = v11
  43579 		v3 = v
  43580 		if v3 > int32(MAX_VARIABLE_LEVEL) {
  43581 			v7 = int32(MAX_VARIABLE_LEVEL)
  43582 		} else {
  43583 			v7 = v3
  43584 		}
  43585 		v5 = libc.Int32FromUint16(VP8LevelFixedCosts[v3]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(t + uintptr(v7)*2)))
  43586 		goto _14
  43587 	_14:
  43588 		cost = cost + v5
  43589 		t = **(**uintptr)(__ccgo_up(costs + uintptr(n+int32(1))*24 + uintptr(ctx)*8))
  43590 		goto _10
  43591 	_10:
  43592 		;
  43593 		n = n + 1
  43594 	}
  43595 	// Last coefficient is always non-zero
  43596 	v1 = libc.Xabs(tls, int32(**(**int16_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fcoeffs + uintptr(n)*2))))
  43597 	v11 = v1
  43598 	if v11 > int32(MAX_VARIABLE_LEVEL) {
  43599 		v5 = int32(MAX_VARIABLE_LEVEL)
  43600 	} else {
  43601 		v5 = v11
  43602 	}
  43603 	v3 = libc.Int32FromUint16(VP8LevelFixedCosts[v11]) + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(t + uintptr(v5)*2)))
  43604 	goto _18
  43605 _18:
  43606 	cost = cost + v3
  43607 	if n < int32(15) {
  43608 		b = libc.Int32FromUint8(VP8EncBands[n+int32(1)])
  43609 		if v1 == int32(1) {
  43610 			v11 = int32(1)
  43611 		} else {
  43612 			v11 = int32(2)
  43613 		}
  43614 		ctx1 = v11
  43615 		last_p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up((*VP8Residual)(unsafe.Pointer(res)).Fprob + uintptr(b)*33 + uintptr(ctx1)*11)))
  43616 		v2 = libc.Uint8FromInt32(last_p0)
  43617 		if !(0 != 0) {
  43618 			v5 = libc.Int32FromUint16(VP8EntropyCost[v2])
  43619 		} else {
  43620 			v5 = libc.Int32FromUint16(VP8EntropyCost[int32(255)-libc.Int32FromUint8(v2)])
  43621 		}
  43622 		v3 = v5
  43623 		goto _23
  43624 	_23:
  43625 		cost = cost + v3
  43626 	}
  43627 	return cost
  43628 }
  43629 
  43630 func SetResidualCoeffs_C(tls *libc.TLS, coeffs uintptr, res uintptr) {
  43631 	var n int32
  43632 	_ = n
  43633 	(*VP8Residual)(unsafe.Pointer(res)).Flast = -int32(1)
  43634 	n = int32(15)
  43635 	for {
  43636 		if !(n >= 0) {
  43637 			break
  43638 		}
  43639 		if **(**int16_t)(__ccgo_up(coeffs + uintptr(n)*2)) != 0 {
  43640 			(*VP8Residual)(unsafe.Pointer(res)).Flast = n
  43641 			break
  43642 		}
  43643 		goto _1
  43644 	_1:
  43645 		;
  43646 		n = n - 1
  43647 	}
  43648 	(*VP8Residual)(unsafe.Pointer(res)).Fcoeffs = coeffs
  43649 }
  43650 
  43651 func VP8EncDspCostInit(tls *libc.TLS) {
  43652 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  43653 		goto _1
  43654 	}
  43655 	VP8EncDspCostInit_body(tls)
  43656 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  43657 	goto _2
  43658 _2:
  43659 	;
  43660 	goto _1
  43661 _1: /**/ //
  43662 }
  43663 
  43664 var VP8EncDspCostInit_body_last_cpuinfo_used = uintptr(0)
  43665 
  43666 func init() {
  43667 	p := unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used)
  43668 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspCostInit_body_last_cpuinfo_used))
  43669 }
  43670 
  43671 func VP8EncDspCostInit_body(tls *libc.TLS) {
  43672 	VP8GetResidualCost = __ccgo_fp(GetResidualCost_C)
  43673 	VP8SetResidualCoeffs = __ccgo_fp(SetResidualCoeffs_C)
  43674 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  43675 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  43676 	}
  43677 }
  43678 
  43679 func VP8EncDspCostInitMIPS32(tls *libc.TLS) {
  43680 }
  43681 
  43682 func VP8EncDspCostInitMIPSdspR2(tls *libc.TLS) {
  43683 }
  43684 
  43685 func VP8EncDspCostInitNEON(tls *libc.TLS) {
  43686 }
  43687 
  43688 func VP8EncDspCostInitSSE2(tls *libc.TLS) {
  43689 }
  43690 
  43691 var kHashMul14 = uint32(0x1e35a7bd)
  43692 
  43693 //------------------------------------------------------------------------------
  43694 
  43695 // Copyright 2010 Google Inc. All Rights Reserved.
  43696 //
  43697 // Use of this source code is governed by a BSD-style license
  43698 // that can be found in the COPYING file in the root of the source
  43699 // tree. An additional intellectual property rights grant can be found
  43700 // in the file PATENTS. All contributing project authors may
  43701 // be found in the AUTHORS file in the root of the source tree.
  43702 // -----------------------------------------------------------------------------
  43703 //
  43704 //  Common types + memory wrappers
  43705 //
  43706 // Author: Skal (pascal.massimino@gmail.com)
  43707 
  43708 //------------------------------------------------------------------------------
  43709 
  43710 func clip_8b1(tls *libc.TLS, v int32) (r uint8_t) {
  43711 	var v1, v2 int32
  43712 	_, _ = v1, v2
  43713 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  43714 		v1 = v
  43715 	} else {
  43716 		if v < 0 {
  43717 			v2 = 0
  43718 		} else {
  43719 			v2 = int32(255)
  43720 		}
  43721 		v1 = v2
  43722 	}
  43723 	return libc.Uint8FromInt32(v1)
  43724 }
  43725 
  43726 //------------------------------------------------------------------------------
  43727 // Transforms (Paragraph 14.4)
  43728 
  43729 func TransformOne_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43730 	bp := tls.Alloc(64)
  43731 	defer tls.Free(64)
  43732 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  43733 	var tmp uintptr
  43734 	var _ /* C at bp+0 */ [16]int32
  43735 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  43736 	tmp = bp
  43737 	i = 0
  43738 	for {
  43739 		if !(i < int32(4)) {
  43740 			break
  43741 		} // vertical pass
  43742 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4096, 4094]
  43743 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))                                                                                                                                       // [-4095, 4095]
  43744 		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]
  43745 		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]
  43746 		**(**int32)(__ccgo_up(tmp)) = a + d                                                                                                                                                                                       // [-7881, 7875]
  43747 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c                                                                                                                                                                                 // [-7878, 7878]
  43748 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c                                                                                                                                                                                 // [-7878, 7878]
  43749 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d                                                                                                                                                                                 // [-7877, 7879]
  43750 		tmp = tmp + uintptr(4)*4
  43751 		in += 2
  43752 		goto _1
  43753 	_1:
  43754 		;
  43755 		i = i + 1
  43756 	}
  43757 	// Each pass is expanding the dynamic range by ~3.85 (upper bound).
  43758 	// The exact value is (2. + (20091 + 35468) / 65536).
  43759 	// After the second pass, maximum interval is [-3794, 3794], assuming
  43760 	// an input in [-2048, 2047] interval. We then need to add a dst value
  43761 	// in the [0, 255] range.
  43762 	// In the worst case scenario, the input to clip_8b() can be as large as
  43763 	// [-60713, 60968].
  43764 	tmp = bp
  43765 	i = 0
  43766 	for {
  43767 		if !(i < int32(4)) {
  43768 			break
  43769 		} // horizontal pass
  43770 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  43771 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  43772 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  43773 		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)))
  43774 		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)
  43775 		**(**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))
  43776 		**(**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))
  43777 		**(**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))
  43778 		**(**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))
  43779 		tmp += 4
  43780 		dst = dst + uintptr(BPS)
  43781 		goto _2
  43782 	_2:
  43783 		;
  43784 		i = i + 1
  43785 	}
  43786 }
  43787 
  43788 // C documentation
  43789 //
  43790 //	// Simplified transform when only in[0], in[1] and in[4] are non-zero
  43791 func TransformAC3_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43792 	var DC, DC1, DC2, DC3, a, c1, c4, d1, d4 int32
  43793 	_, _, _, _, _, _, _, _, _ = DC, DC1, DC2, DC3, a, c1, c4, d1, d4
  43794 	a = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  43795 	c4 = int32(**(**int16_t)(__ccgo_up(in + 4*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43796 	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)))
  43797 	c1 = int32(**(**int16_t)(__ccgo_up(in + 1*2))) * libc.Int32FromInt32(WEBP_TRANSFORM_AC3_C2) >> libc.Int32FromInt32(16)
  43798 	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)))
  43799 	DC = a + d4
  43800 	**(**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))
  43801 	**(**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))
  43802 	**(**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))
  43803 	**(**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))
  43804 	DC1 = a + c4
  43805 	**(**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))
  43806 	**(**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))
  43807 	**(**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))
  43808 	**(**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))
  43809 	DC2 = a - c4
  43810 	**(**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))
  43811 	**(**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))
  43812 	**(**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))
  43813 	**(**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))
  43814 	DC3 = a - d4
  43815 	**(**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))
  43816 	**(**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))
  43817 	**(**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))
  43818 	**(**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))
  43819 }
  43820 
  43821 func TransformTwo_C(tls *libc.TLS, in uintptr, dst uintptr, do_two int32) {
  43822 	TransformOne_C(tls, in, dst)
  43823 	if do_two != 0 {
  43824 		TransformOne_C(tls, in+uintptr(16)*2, dst+uintptr(4))
  43825 	}
  43826 }
  43827 
  43828 func TransformUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43829 	(*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{VP8Transform})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst, int32(1))
  43830 	(*(*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))
  43831 }
  43832 
  43833 func TransformDC_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43834 	var DC, i, j int32
  43835 	_, _, _ = DC, i, j
  43836 	DC = int32(**(**int16_t)(__ccgo_up(in))) + int32(4)
  43837 	j = 0
  43838 	for {
  43839 		if !(j < int32(4)) {
  43840 			break
  43841 		}
  43842 		i = 0
  43843 		for {
  43844 			if !(i < int32(4)) {
  43845 				break
  43846 			}
  43847 			**(**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))
  43848 			goto _2
  43849 		_2:
  43850 			;
  43851 			i = i + 1
  43852 		}
  43853 		goto _1
  43854 	_1:
  43855 		;
  43856 		j = j + 1
  43857 	}
  43858 }
  43859 
  43860 func TransformDCUV_C(tls *libc.TLS, in uintptr, dst uintptr) {
  43861 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2)) != 0 {
  43862 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16))*2, dst)
  43863 	}
  43864 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2)) != 0 {
  43865 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8TransformDC})))(tls, in+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16))*2, dst+uintptr(4))
  43866 	}
  43867 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16))*2)) != 0 {
  43868 		(*(*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)))
  43869 	}
  43870 	if **(**int16_t)(__ccgo_up(in + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16))*2)) != 0 {
  43871 		(*(*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))
  43872 	}
  43873 }
  43874 
  43875 //------------------------------------------------------------------------------
  43876 // Paragraph 14.3
  43877 
  43878 func TransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  43879 	var a0, a01, a1, a11, a2, a21, a3, a31, dc, i int32
  43880 	var tmp [16]int32
  43881 	_, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, dc, i, tmp
  43882 	i = 0
  43883 	for {
  43884 		if !(i < int32(4)) {
  43885 			break
  43886 		}
  43887 		a0 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  43888 		a1 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) + int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  43889 		a2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(4)+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(8)+i)*2)))
  43890 		a3 = int32(**(**int16_t)(__ccgo_up(in + uintptr(0+i)*2))) - int32(**(**int16_t)(__ccgo_up(in + uintptr(int32(12)+i)*2)))
  43891 		tmp[0+i] = a0 + a1
  43892 		tmp[int32(8)+i] = a0 - a1
  43893 		tmp[int32(4)+i] = a3 + a2
  43894 		tmp[int32(12)+i] = a3 - a2
  43895 		goto _1
  43896 	_1:
  43897 		;
  43898 		i = i + 1
  43899 	}
  43900 	i = 0
  43901 	for {
  43902 		if !(i < int32(4)) {
  43903 			break
  43904 		}
  43905 		dc = tmp[0+i*int32(4)] + int32(3) // w/ rounder
  43906 		a01 = dc + tmp[int32(3)+i*int32(4)]
  43907 		a11 = tmp[int32(1)+i*int32(4)] + tmp[int32(2)+i*int32(4)]
  43908 		a21 = tmp[int32(1)+i*int32(4)] - tmp[int32(2)+i*int32(4)]
  43909 		a31 = dc - tmp[int32(3)+i*int32(4)]
  43910 		**(**int16_t)(__ccgo_up(out)) = int16((a01 + a11) >> int32(3))
  43911 		**(**int16_t)(__ccgo_up(out + 16*2)) = int16((a31 + a21) >> int32(3))
  43912 		**(**int16_t)(__ccgo_up(out + 32*2)) = int16((a01 - a11) >> int32(3))
  43913 		**(**int16_t)(__ccgo_up(out + 48*2)) = int16((a31 - a21) >> int32(3))
  43914 		out = out + uintptr(64)*2
  43915 		goto _2
  43916 	_2:
  43917 		;
  43918 		i = i + 1
  43919 	}
  43920 }
  43921 
  43922 //------------------------------------------------------------------------------
  43923 // Intra predictions
  43924 
  43925 func TrueMotion(tls *libc.TLS, dst uintptr, size int32) {
  43926 	var clip, clip0, top uintptr
  43927 	var x, y int32
  43928 	_, _, _, _, _ = clip, clip0, top, x, y
  43929 	top = dst - uintptr(BPS)
  43930 	clip0 = VP8kclip1 - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  43931 	y = 0
  43932 	for {
  43933 		if !(y < size) {
  43934 			break
  43935 		}
  43936 		clip = clip0 + uintptr(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  43937 		x = 0
  43938 		for {
  43939 			if !(x < size) {
  43940 				break
  43941 			}
  43942 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  43943 			goto _2
  43944 		_2:
  43945 			;
  43946 			x = x + 1
  43947 		}
  43948 		dst = dst + uintptr(BPS)
  43949 		goto _1
  43950 	_1:
  43951 		;
  43952 		y = y + 1
  43953 	}
  43954 }
  43955 
  43956 func TM4_C(tls *libc.TLS, dst uintptr) {
  43957 	TrueMotion(tls, dst, int32(4))
  43958 }
  43959 
  43960 func TM8uv_C(tls *libc.TLS, dst uintptr) {
  43961 	TrueMotion(tls, dst, int32(8))
  43962 }
  43963 
  43964 func TM16_C(tls *libc.TLS, dst uintptr) {
  43965 	TrueMotion(tls, dst, int32(16))
  43966 }
  43967 
  43968 //------------------------------------------------------------------------------
  43969 // 16x16
  43970 
  43971 func VE16_C(tls *libc.TLS, dst uintptr) {
  43972 	var j int32
  43973 	_ = j
  43974 	j = 0
  43975 	for {
  43976 		if !(j < int32(16)) {
  43977 			break
  43978 		}
  43979 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(16))
  43980 		goto _1
  43981 	_1:
  43982 		;
  43983 		j = j + 1
  43984 	}
  43985 }
  43986 
  43987 func HE16_C(tls *libc.TLS, dst uintptr) {
  43988 	var j int32
  43989 	_ = j
  43990 	j = int32(16)
  43991 	for {
  43992 		if !(j > 0) {
  43993 			break
  43994 		}
  43995 		libc.Xmemset(tls, dst, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(16))
  43996 		dst = dst + uintptr(BPS)
  43997 		goto _1
  43998 	_1:
  43999 		;
  44000 		j = j - 1
  44001 	}
  44002 }
  44003 
  44004 func Put16(tls *libc.TLS, v int32, dst uintptr) {
  44005 	var j int32
  44006 	_ = j
  44007 	j = 0
  44008 	for {
  44009 		if !(j < int32(16)) {
  44010 			break
  44011 		}
  44012 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), v, uint64(16))
  44013 		goto _1
  44014 	_1:
  44015 		;
  44016 		j = j + 1
  44017 	}
  44018 }
  44019 
  44020 func DC16_C(tls *libc.TLS, dst uintptr) {
  44021 	var DC, j int32
  44022 	_, _ = DC, j // DC
  44023 	DC = int32(16)
  44024 	j = 0
  44025 	for {
  44026 		if !(j < int32(16)) {
  44027 			break
  44028 		}
  44029 		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))))))
  44030 		goto _1
  44031 	_1:
  44032 		;
  44033 		j = j + 1
  44034 	}
  44035 	Put16(tls, DC>>int32(5), dst)
  44036 }
  44037 
  44038 func DC16NoTop_C(tls *libc.TLS, dst uintptr) {
  44039 	var DC, j int32
  44040 	_, _ = DC, j // DC with top samples not available
  44041 	DC = int32(8)
  44042 	j = 0
  44043 	for {
  44044 		if !(j < int32(16)) {
  44045 			break
  44046 		}
  44047 		DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+j*int32(BPS)))))
  44048 		goto _1
  44049 	_1:
  44050 		;
  44051 		j = j + 1
  44052 	}
  44053 	Put16(tls, DC>>int32(4), dst)
  44054 }
  44055 
  44056 func DC16NoLeft_C(tls *libc.TLS, dst uintptr) {
  44057 	var DC, i int32
  44058 	_, _ = DC, i // DC with left samples not available
  44059 	DC = int32(8)
  44060 	i = 0
  44061 	for {
  44062 		if !(i < int32(16)) {
  44063 			break
  44064 		}
  44065 		DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44066 		goto _1
  44067 	_1:
  44068 		;
  44069 		i = i + 1
  44070 	}
  44071 	Put16(tls, DC>>int32(4), dst)
  44072 }
  44073 
  44074 func DC16NoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44075 	// DC with no top and left samples
  44076 	Put16(tls, int32(0x80), dst)
  44077 }
  44078 
  44079 //------------------------------------------------------------------------------
  44080 // 4x4
  44081 
  44082 func VE4_C(tls *libc.TLS, dst uintptr) {
  44083 	bp := tls.Alloc(16)
  44084 	defer tls.Free(16)
  44085 	var i int32
  44086 	var top uintptr
  44087 	var _ /* vals at bp+0 */ [4]uint8_t
  44088 	_, _ = i, top // vertical
  44089 	top = dst - uintptr(BPS)
  44090 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  44091 		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)),
  44092 		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)),
  44093 		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)),
  44094 		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)),
  44095 	}
  44096 	i = 0
  44097 	for {
  44098 		if !(i < int32(4)) {
  44099 			break
  44100 		}
  44101 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  44102 		goto _1
  44103 	_1:
  44104 		;
  44105 		i = i + 1
  44106 	}
  44107 }
  44108 
  44109 func HE4_C(tls *libc.TLS, dst uintptr) {
  44110 	bp := tls.Alloc(16)
  44111 	defer tls.Free(16)
  44112 	var A, B, C, D, E int32
  44113 	var v1 uint32_t
  44114 	_, _, _, _, _, _ = A, B, C, D, E, v1 // horizontal
  44115 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44116 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)))))
  44117 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(BPS)))))
  44118 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44119 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44120 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((A+libc.Int32FromInt32(2)*B+C+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44121 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44122 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44123 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((B+libc.Int32FromInt32(2)*C+D+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44124 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44125 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44126 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((C+libc.Int32FromInt32(2)*D+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44127 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44128 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44129 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((D+libc.Int32FromInt32(2)*E+E+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  44130 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  44131 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  44132 }
  44133 
  44134 func DC4_C(tls *libc.TLS, dst uintptr) {
  44135 	var dc uint32_t
  44136 	var i int32
  44137 	_, _ = dc, i // DC
  44138 	dc = uint32(4)
  44139 	i = 0
  44140 	for {
  44141 		if !(i < int32(4)) {
  44142 			break
  44143 		}
  44144 		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))))))
  44145 		goto _1
  44146 	_1:
  44147 		;
  44148 		i = i + 1
  44149 	}
  44150 	dc = dc >> uint32(3)
  44151 	i = 0
  44152 	for {
  44153 		if !(i < int32(4)) {
  44154 			break
  44155 		}
  44156 		libc.Xmemset(tls, dst+uintptr(i*int32(BPS)), libc.Int32FromUint32(dc), uint64(4))
  44157 		goto _2
  44158 	_2:
  44159 		;
  44160 		i = i + 1
  44161 	}
  44162 }
  44163 
  44164 func RD4_C(tls *libc.TLS, dst uintptr) {
  44165 	var A, B, C, D, I, J, K, L, X int32
  44166 	var v1, v2, v3 uint8_t
  44167 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3 // Down-right
  44168 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44169 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44170 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44171 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44172 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44173 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44174 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44175 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44176 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44177 	**(**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))
  44178 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44179 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44180 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44181 	v2 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44182 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44183 	v1 = v2
  44184 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44185 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44186 	v3 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44187 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v3
  44188 	v2 = v3
  44189 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v2
  44190 	v1 = v2
  44191 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44192 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44193 	v2 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44194 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v2
  44195 	v1 = v2
  44196 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44197 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44198 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44199 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44200 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44201 	**(**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))
  44202 }
  44203 
  44204 func LD4_C(tls *libc.TLS, dst uintptr) {
  44205 	var A, B, C, D, E, F, G, H int32
  44206 	var v1, v2, v3 uint8_t
  44207 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3 // Down-Left
  44208 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44209 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44210 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44211 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44212 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44213 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44214 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44215 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44216 	**(**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))
  44217 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44218 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44219 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44220 	v2 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44221 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44222 	v1 = v2
  44223 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44224 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44225 	v3 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44226 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44227 	v2 = v3
  44228 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  44229 	v1 = v2
  44230 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44231 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44232 	v2 = libc.Uint8FromInt32((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44233 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44234 	v1 = v2
  44235 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44236 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44237 	v1 = libc.Uint8FromInt32((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44238 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44239 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44240 	**(**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))
  44241 }
  44242 
  44243 func VR4_C(tls *libc.TLS, dst uintptr) {
  44244 	var A, B, C, D, I, J, K, X int32
  44245 	var v1 uint8_t
  44246 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1 // Vertical-Right
  44247 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44248 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44249 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44250 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44251 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44252 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44253 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44254 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44255 	v1 = libc.Uint8FromInt32((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44256 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44257 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44258 	v1 = libc.Uint8FromInt32((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44259 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44260 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44261 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44262 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44263 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44264 	**(**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))
  44265 	**(**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))
  44266 	**(**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))
  44267 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44268 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44269 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44270 	v1 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44271 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44272 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44273 	v1 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44274 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44275 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44276 	**(**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))
  44277 }
  44278 
  44279 func VL4_C(tls *libc.TLS, dst uintptr) {
  44280 	var A, B, C, D, E, F, G, H int32
  44281 	var v1 uint8_t
  44282 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1 // Vertical-Left
  44283 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44284 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44285 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44286 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)-libc.Int32FromInt32(BPS)))))
  44287 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(4)-libc.Int32FromInt32(BPS)))))
  44288 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(5)-libc.Int32FromInt32(BPS)))))
  44289 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(6)-libc.Int32FromInt32(BPS)))))
  44290 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(7)-libc.Int32FromInt32(BPS)))))
  44291 	**(**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))
  44292 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44293 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44294 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44295 	v1 = libc.Uint8FromInt32((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44296 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44297 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44298 	v1 = libc.Uint8FromInt32((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44299 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44300 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44301 	**(**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))
  44302 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44303 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44304 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44305 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44306 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44307 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44308 	v1 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44309 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44310 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44311 	**(**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))
  44312 	**(**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))
  44313 }
  44314 
  44315 func HU4_C(tls *libc.TLS, dst uintptr) {
  44316 	var I, J, K, L int32
  44317 	var v1, v2, v3, v4, v5 uint8_t
  44318 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5 // Horizontal-Up
  44319 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44320 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44321 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44322 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44323 	**(**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))
  44324 	v1 = libc.Uint8FromInt32((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44325 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44326 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44327 	v1 = libc.Uint8FromInt32((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44328 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44329 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44330 	**(**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))
  44331 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44332 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44333 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44334 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44335 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44336 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44337 	v5 = libc.Uint8FromInt32(L)
  44338 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  44339 	v4 = v5
  44340 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  44341 	v3 = v4
  44342 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  44343 	v2 = v3
  44344 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  44345 	v1 = v2
  44346 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44347 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44348 }
  44349 
  44350 func HD4_C(tls *libc.TLS, dst uintptr) {
  44351 	var A, B, C, I, J, K, L, X int32
  44352 	var v1 uint8_t
  44353 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1 // Horizontal-Down
  44354 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))))
  44355 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))))
  44356 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))))
  44357 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))))
  44358 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44359 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)-libc.Int32FromInt32(BPS)))))
  44360 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)-libc.Int32FromInt32(BPS)))))
  44361 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)-libc.Int32FromInt32(BPS)))))
  44362 	v1 = libc.Uint8FromInt32((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44363 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44364 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44365 	v1 = libc.Uint8FromInt32((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44366 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44367 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44368 	v1 = libc.Uint8FromInt32((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  44369 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44370 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44371 	**(**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))
  44372 	**(**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))
  44373 	**(**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))
  44374 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44375 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44376 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  44377 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44378 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44379 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  44380 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  44381 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  44382 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  44383 	**(**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))
  44384 }
  44385 
  44386 //------------------------------------------------------------------------------
  44387 // Chroma
  44388 
  44389 func VE8uv_C(tls *libc.TLS, dst uintptr) {
  44390 	var j int32
  44391 	_ = j
  44392 	j = 0
  44393 	for {
  44394 		if !(j < int32(8)) {
  44395 			break
  44396 		}
  44397 		libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), dst-uintptr(BPS), uint64(8))
  44398 		goto _1
  44399 	_1:
  44400 		;
  44401 		j = j + 1
  44402 	}
  44403 }
  44404 
  44405 func HE8uv_C(tls *libc.TLS, dst uintptr) {
  44406 	var j int32
  44407 	_ = j
  44408 	j = 0
  44409 	for {
  44410 		if !(j < int32(8)) {
  44411 			break
  44412 		}
  44413 		libc.Xmemset(tls, dst, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-libc.Int32FromInt32(1))))), uint64(8))
  44414 		dst = dst + uintptr(BPS)
  44415 		goto _1
  44416 	_1:
  44417 		;
  44418 		j = j + 1
  44419 	}
  44420 }
  44421 
  44422 // C documentation
  44423 //
  44424 //	// helper for chroma-DC predictions
  44425 func Put8x8uv(tls *libc.TLS, value uint8_t, dst uintptr) {
  44426 	var j int32
  44427 	_ = j
  44428 	j = 0
  44429 	for {
  44430 		if !(j < int32(8)) {
  44431 			break
  44432 		}
  44433 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), libc.Int32FromUint8(value), uint64(8))
  44434 		goto _1
  44435 	_1:
  44436 		;
  44437 		j = j + 1
  44438 	}
  44439 }
  44440 
  44441 func DC8uv_C(tls *libc.TLS, dst uintptr) {
  44442 	var dc0, i int32
  44443 	_, _ = dc0, i // DC
  44444 	dc0 = int32(8)
  44445 	i = 0
  44446 	for {
  44447 		if !(i < int32(8)) {
  44448 			break
  44449 		}
  44450 		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))))))
  44451 		goto _1
  44452 	_1:
  44453 		;
  44454 		i = i + 1
  44455 	}
  44456 	Put8x8uv(tls, libc.Uint8FromInt32(dc0>>int32(4)), dst)
  44457 }
  44458 
  44459 func DC8uvNoLeft_C(tls *libc.TLS, dst uintptr) {
  44460 	var dc0, i int32
  44461 	_, _ = dc0, i // DC with no left samples
  44462 	dc0 = int32(4)
  44463 	i = 0
  44464 	for {
  44465 		if !(i < int32(8)) {
  44466 			break
  44467 		}
  44468 		dc0 = dc0 + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i-int32(BPS)))))
  44469 		goto _1
  44470 	_1:
  44471 		;
  44472 		i = i + 1
  44473 	}
  44474 	Put8x8uv(tls, libc.Uint8FromInt32(dc0>>int32(3)), dst)
  44475 }
  44476 
  44477 func DC8uvNoTop_C(tls *libc.TLS, dst uintptr) {
  44478 	var dc0, i int32
  44479 	_, _ = dc0, i // DC with no top samples
  44480 	dc0 = int32(4)
  44481 	i = 0
  44482 	for {
  44483 		if !(i < int32(8)) {
  44484 			break
  44485 		}
  44486 		dc0 = dc0 + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(-int32(1)+i*int32(BPS)))))
  44487 		goto _1
  44488 	_1:
  44489 		;
  44490 		i = i + 1
  44491 	}
  44492 	Put8x8uv(tls, libc.Uint8FromInt32(dc0>>int32(3)), dst)
  44493 }
  44494 
  44495 func DC8uvNoTopLeft_C(tls *libc.TLS, dst uintptr) {
  44496 	// DC with nothing
  44497 	Put8x8uv(tls, uint8(0x80), dst)
  44498 }
  44499 
  44500 //------------------------------------------------------------------------------
  44501 // Edge filtering functions
  44502 
  44503 // C documentation
  44504 //
  44505 //	// 4 pixels in, 2 pixels out
  44506 func DoFilter2_C(tls *libc.TLS, p uintptr, step int32) {
  44507 	var a, a1, a2, p0, p1, q0, q1 int32
  44508 	_, _, _, _, _, _, _ = a, a1, a2, p0, p1, q0, q1
  44509 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44510 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44511 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44512 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44513 	a = int32(3)*(q0-p0) + int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1)))) // in [-893,892]
  44514 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))  // in [-16,15]
  44515 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44516 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44517 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44518 }
  44519 
  44520 // C documentation
  44521 //
  44522 //	// 4 pixels in, 4 pixels out
  44523 func DoFilter4_C(tls *libc.TLS, p uintptr, step int32) {
  44524 	var a, a1, a2, a3, p0, p1, q0, q1 int32
  44525 	_, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, q0, q1
  44526 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44527 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44528 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44529 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44530 	a = int32(3) * (q0 - p0)
  44531 	a1 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(4))>>int32(3)))))
  44532 	a2 = int32(**(**int8_t)(__ccgo_up(VP8ksclip2 + uintptr((a+int32(3))>>int32(3)))))
  44533 	a3 = (a1 + int32(1)) >> int32(1)
  44534 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a3)))
  44535 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a2)))
  44536 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44537 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a3)))
  44538 }
  44539 
  44540 // C documentation
  44541 //
  44542 //	// 6 pixels in, 6 pixels out
  44543 func DoFilter6_C(tls *libc.TLS, p uintptr, step int32) {
  44544 	var a, a1, a2, a3, p0, p1, p2, q0, q1, q2 int32
  44545 	_, _, _, _, _, _, _, _, _, _ = a, a1, a2, a3, p0, p1, p2, q0, q1, q2
  44546 	p2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44547 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44548 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44549 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44550 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44551 	q2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44552 	a = int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(int32(3)*(q0-p0)+int32(**(**int8_t)(__ccgo_up(VP8ksclip1 + uintptr(p1-q1))))))))
  44553 	// a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
  44554 	a1 = (int32(27)*a + int32(63)) >> int32(7) // eq. to ((3 * a + 7) * 9) >> 7
  44555 	a2 = (int32(18)*a + int32(63)) >> int32(7) // eq. to ((2 * a + 7) * 9) >> 7
  44556 	a3 = (int32(9)*a + int32(63)) >> int32(7)  // eq. to ((1 * a + 7) * 9) >> 7
  44557 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p2+a3)))
  44558 	**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p1+a2)))
  44559 	**(**uint8_t)(__ccgo_up(p + uintptr(-step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(p0+a1)))
  44560 	**(**uint8_t)(__ccgo_up(p)) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q0-a1)))
  44561 	**(**uint8_t)(__ccgo_up(p + uintptr(step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q1-a2)))
  44562 	**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))) = **(**uint8_t)(__ccgo_up(VP8kclip1 + uintptr(q2-a3)))
  44563 }
  44564 
  44565 func Hev(tls *libc.TLS, p uintptr, step int32, thresh int32) (r int32) {
  44566 	var p0, p1, q0, q1 int32
  44567 	_, _, _, _ = p0, p1, q0, q1
  44568 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44569 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44570 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44571 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44572 	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)
  44573 }
  44574 
  44575 func NeedsFilter_C(tls *libc.TLS, p uintptr, step int32, t int32) (r int32) {
  44576 	var p0, p1, q0, q1 int32
  44577 	_, _, _, _ = p0, p1, q0, q1
  44578 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44579 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44580 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44581 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44582 	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)
  44583 }
  44584 
  44585 func NeedsFilter2_C(tls *libc.TLS, p uintptr, step int32, t int32, it int32) (r int32) {
  44586 	var p0, p1, p2, p3, q0, q1, q2, q3 int32
  44587 	_, _, _, _, _, _, _, _ = p0, p1, p2, p3, q0, q1, q2, q3
  44588 	p3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(4)*step))))
  44589 	p2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(3)*step))))
  44590 	p1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-int32(2)*step))))
  44591 	p0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(-step))))
  44592 	q0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p)))
  44593 	q1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(step))))
  44594 	q2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(2)*step))))
  44595 	q3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(p + uintptr(int32(3)*step))))
  44596 	if int32(4)*libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p0-q0))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(VP8kabs0 + uintptr(p1-q1)))) > t {
  44597 		return 0
  44598 	}
  44599 	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)
  44600 }
  44601 
  44602 //------------------------------------------------------------------------------
  44603 // Simple In-loop filtering (Paragraph 15.2)
  44604 
  44605 func SimpleVFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44606 	var i, thresh2 int32
  44607 	_, _ = i, thresh2
  44608 	thresh2 = int32(2)*thresh + int32(1)
  44609 	i = 0
  44610 	for {
  44611 		if !(i < int32(16)) {
  44612 			break
  44613 		}
  44614 		if NeedsFilter_C(tls, p+uintptr(i), stride, thresh2) != 0 {
  44615 			DoFilter2_C(tls, p+uintptr(i), stride)
  44616 		}
  44617 		goto _1
  44618 	_1:
  44619 		;
  44620 		i = i + 1
  44621 	}
  44622 }
  44623 
  44624 func SimpleHFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44625 	var i, thresh2 int32
  44626 	_, _ = i, thresh2
  44627 	thresh2 = int32(2)*thresh + int32(1)
  44628 	i = 0
  44629 	for {
  44630 		if !(i < int32(16)) {
  44631 			break
  44632 		}
  44633 		if NeedsFilter_C(tls, p+uintptr(i*stride), int32(1), thresh2) != 0 {
  44634 			DoFilter2_C(tls, p+uintptr(i*stride), int32(1))
  44635 		}
  44636 		goto _1
  44637 	_1:
  44638 		;
  44639 		i = i + 1
  44640 	}
  44641 }
  44642 
  44643 func SimpleVFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44644 	var k int32
  44645 	_ = k
  44646 	k = int32(3)
  44647 	for {
  44648 		if !(k > 0) {
  44649 			break
  44650 		}
  44651 		p = p + uintptr(int32(4)*stride)
  44652 		SimpleVFilter16_C(tls, p, stride, thresh)
  44653 		goto _1
  44654 	_1:
  44655 		;
  44656 		k = k - 1
  44657 	}
  44658 }
  44659 
  44660 func SimpleHFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32) {
  44661 	var k int32
  44662 	_ = k
  44663 	k = int32(3)
  44664 	for {
  44665 		if !(k > 0) {
  44666 			break
  44667 		}
  44668 		p = p + uintptr(4)
  44669 		SimpleHFilter16_C(tls, p, stride, thresh)
  44670 		goto _1
  44671 	_1:
  44672 		;
  44673 		k = k - 1
  44674 	}
  44675 }
  44676 
  44677 //------------------------------------------------------------------------------
  44678 // Complex In-loop filtering (Paragraph 15.3)
  44679 
  44680 func FilterLoop26_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44681 	var thresh2, v1 int32
  44682 	_, _ = thresh2, v1
  44683 	thresh2 = int32(2)*thresh + int32(1)
  44684 	for {
  44685 		v1 = size
  44686 		size = size - 1
  44687 		if !(v1 > 0) {
  44688 			break
  44689 		}
  44690 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44691 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44692 				DoFilter2_C(tls, p, hstride)
  44693 			} else {
  44694 				DoFilter6_C(tls, p, hstride)
  44695 			}
  44696 		}
  44697 		p = p + uintptr(vstride)
  44698 	}
  44699 }
  44700 
  44701 func FilterLoop24_C(tls *libc.TLS, p uintptr, hstride int32, vstride int32, size int32, thresh int32, ithresh int32, hev_thresh int32) {
  44702 	var thresh2, v1 int32
  44703 	_, _ = thresh2, v1
  44704 	thresh2 = int32(2)*thresh + int32(1)
  44705 	for {
  44706 		v1 = size
  44707 		size = size - 1
  44708 		if !(v1 > 0) {
  44709 			break
  44710 		}
  44711 		if NeedsFilter2_C(tls, p, hstride, thresh2, ithresh) != 0 {
  44712 			if Hev(tls, p, hstride, hev_thresh) != 0 {
  44713 				DoFilter2_C(tls, p, hstride)
  44714 			} else {
  44715 				DoFilter4_C(tls, p, hstride)
  44716 			}
  44717 		}
  44718 		p = p + uintptr(vstride)
  44719 	}
  44720 }
  44721 
  44722 // C documentation
  44723 //
  44724 //	// on macroblock edges
  44725 func VFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44726 	FilterLoop26_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44727 }
  44728 
  44729 func HFilter16_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44730 	FilterLoop26_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44731 }
  44732 
  44733 // C documentation
  44734 //
  44735 //	// on three inner edges
  44736 func VFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44737 	var k int32
  44738 	_ = k
  44739 	k = int32(3)
  44740 	for {
  44741 		if !(k > 0) {
  44742 			break
  44743 		}
  44744 		p = p + uintptr(int32(4)*stride)
  44745 		FilterLoop24_C(tls, p, stride, int32(1), int32(16), thresh, ithresh, hev_thresh)
  44746 		goto _1
  44747 	_1:
  44748 		;
  44749 		k = k - 1
  44750 	}
  44751 }
  44752 
  44753 func HFilter16i_C(tls *libc.TLS, p uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44754 	var k int32
  44755 	_ = k
  44756 	k = int32(3)
  44757 	for {
  44758 		if !(k > 0) {
  44759 			break
  44760 		}
  44761 		p = p + uintptr(4)
  44762 		FilterLoop24_C(tls, p, int32(1), stride, int32(16), thresh, ithresh, hev_thresh)
  44763 		goto _1
  44764 	_1:
  44765 		;
  44766 		k = k - 1
  44767 	}
  44768 }
  44769 
  44770 // C documentation
  44771 //
  44772 //	// 8-pixels wide variant, for chroma filtering
  44773 func VFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44774 	FilterLoop26_C(tls, u, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44775 	FilterLoop26_C(tls, v, stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44776 }
  44777 
  44778 func HFilter8_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44779 	FilterLoop26_C(tls, u, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44780 	FilterLoop26_C(tls, v, int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44781 }
  44782 
  44783 func VFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44784 	FilterLoop24_C(tls, u+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44785 	FilterLoop24_C(tls, v+uintptr(int32(4)*stride), stride, int32(1), int32(8), thresh, ithresh, hev_thresh)
  44786 }
  44787 
  44788 func HFilter8i_C(tls *libc.TLS, u uintptr, v uintptr, stride int32, thresh int32, ithresh int32, hev_thresh int32) {
  44789 	FilterLoop24_C(tls, u+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44790 	FilterLoop24_C(tls, v+uintptr(4), int32(1), stride, int32(8), thresh, ithresh, hev_thresh)
  44791 }
  44792 
  44793 //------------------------------------------------------------------------------
  44794 
  44795 func DitherCombine8x8_C(tls *libc.TLS, dither uintptr, dst uintptr, dst_stride int32) {
  44796 	var delta0, delta1, i, j int32
  44797 	_, _, _, _ = delta0, delta1, i, j
  44798 	j = 0
  44799 	for {
  44800 		if !(j < int32(8)) {
  44801 			break
  44802 		}
  44803 		i = 0
  44804 		for {
  44805 			if !(i < int32(8)) {
  44806 				break
  44807 			}
  44808 			delta0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dither + uintptr(i)))) - libc.Int32FromInt32(1)<<libc.Int32FromInt32(VP8_DITHER_AMP_BITS)
  44809 			delta1 = (delta0 + libc.Int32FromInt32(1)<<(libc.Int32FromInt32(VP8_DITHER_DESCALE)-libc.Int32FromInt32(1))) >> int32(VP8_DITHER_DESCALE)
  44810 			**(**uint8_t)(__ccgo_up(dst + uintptr(i))) = clip_8b1(tls, libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(dst + uintptr(i))))+delta1)
  44811 			goto _2
  44812 		_2:
  44813 			;
  44814 			i = i + 1
  44815 		}
  44816 		dst = dst + uintptr(dst_stride)
  44817 		dither = dither + uintptr(8)
  44818 		goto _1
  44819 	_1:
  44820 		;
  44821 		j = j + 1
  44822 	}
  44823 }
  44824 
  44825 func VP8DspInit(tls *libc.TLS) {
  44826 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  44827 		goto _1
  44828 	}
  44829 	VP8DspInit_body(tls)
  44830 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  44831 	goto _2
  44832 _2:
  44833 	;
  44834 	goto _1
  44835 _1: /**/ //
  44836 }
  44837 
  44838 var VP8DspInit_body_last_cpuinfo_used = uintptr(0)
  44839 
  44840 func init() {
  44841 	p := unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used)
  44842 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8DspInit_body_last_cpuinfo_used))
  44843 }
  44844 
  44845 func VP8DspInit_body(tls *libc.TLS) {
  44846 	VP8InitClipTables(tls)
  44847 	VP8TransformWHT = __ccgo_fp(TransformWHT_C)
  44848 	VP8Transform = __ccgo_fp(TransformTwo_C)
  44849 	VP8TransformDC = __ccgo_fp(TransformDC_C)
  44850 	VP8TransformAC3 = __ccgo_fp(TransformAC3_C)
  44851 	VP8TransformUV = __ccgo_fp(TransformUV_C)
  44852 	VP8TransformDCUV = __ccgo_fp(TransformDCUV_C)
  44853 	VP8VFilter16 = __ccgo_fp(VFilter16_C)
  44854 	VP8VFilter16i = __ccgo_fp(VFilter16i_C)
  44855 	VP8HFilter16 = __ccgo_fp(HFilter16_C)
  44856 	VP8VFilter8 = __ccgo_fp(VFilter8_C)
  44857 	VP8VFilter8i = __ccgo_fp(VFilter8i_C)
  44858 	VP8SimpleVFilter16 = __ccgo_fp(SimpleVFilter16_C)
  44859 	VP8SimpleHFilter16 = __ccgo_fp(SimpleHFilter16_C)
  44860 	VP8SimpleVFilter16i = __ccgo_fp(SimpleVFilter16i_C)
  44861 	VP8SimpleHFilter16i = __ccgo_fp(SimpleHFilter16i_C)
  44862 	VP8HFilter16i = __ccgo_fp(HFilter16i_C)
  44863 	VP8HFilter8 = __ccgo_fp(HFilter8_C)
  44864 	VP8HFilter8i = __ccgo_fp(HFilter8i_C)
  44865 	VP8PredLuma4[0] = __ccgo_fp(DC4_C)
  44866 	VP8PredLuma4[int32(1)] = __ccgo_fp(TM4_C)
  44867 	VP8PredLuma4[int32(2)] = __ccgo_fp(VE4_C)
  44868 	VP8PredLuma4[int32(4)] = __ccgo_fp(RD4_C)
  44869 	VP8PredLuma4[int32(6)] = __ccgo_fp(LD4_C)
  44870 	VP8PredLuma4[int32(3)] = __ccgo_fp(HE4_C)
  44871 	VP8PredLuma4[int32(5)] = __ccgo_fp(VR4_C)
  44872 	VP8PredLuma4[int32(7)] = __ccgo_fp(VL4_C)
  44873 	VP8PredLuma4[int32(8)] = __ccgo_fp(HD4_C)
  44874 	VP8PredLuma4[int32(9)] = __ccgo_fp(HU4_C)
  44875 	VP8PredLuma16[0] = __ccgo_fp(DC16_C)
  44876 	VP8PredLuma16[int32(1)] = __ccgo_fp(TM16_C)
  44877 	VP8PredLuma16[int32(2)] = __ccgo_fp(VE16_C)
  44878 	VP8PredLuma16[int32(3)] = __ccgo_fp(HE16_C)
  44879 	VP8PredLuma16[int32(4)] = __ccgo_fp(DC16NoTop_C)
  44880 	VP8PredLuma16[int32(5)] = __ccgo_fp(DC16NoLeft_C)
  44881 	VP8PredLuma16[int32(6)] = __ccgo_fp(DC16NoTopLeft_C)
  44882 	VP8PredChroma8[0] = __ccgo_fp(DC8uv_C)
  44883 	VP8PredChroma8[int32(1)] = __ccgo_fp(TM8uv_C)
  44884 	VP8PredChroma8[int32(2)] = __ccgo_fp(VE8uv_C)
  44885 	VP8PredChroma8[int32(3)] = __ccgo_fp(HE8uv_C)
  44886 	VP8PredChroma8[int32(4)] = __ccgo_fp(DC8uvNoTop_C)
  44887 	VP8PredChroma8[int32(5)] = __ccgo_fp(DC8uvNoLeft_C)
  44888 	VP8PredChroma8[int32(6)] = __ccgo_fp(DC8uvNoTopLeft_C)
  44889 	VP8DitherCombine8x8 = __ccgo_fp(DitherCombine8x8_C)
  44890 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  44891 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  44892 	}
  44893 }
  44894 
  44895 const USE_STATIC_TABLES = 1
  44896 
  44897 // define to 0 to have run-time table initialization
  44898 
  44899 var abs0 = [511]uint8_t{
  44900 	0:   uint8(0xff),
  44901 	1:   uint8(0xfe),
  44902 	2:   uint8(0xfd),
  44903 	3:   uint8(0xfc),
  44904 	4:   uint8(0xfb),
  44905 	5:   uint8(0xfa),
  44906 	6:   uint8(0xf9),
  44907 	7:   uint8(0xf8),
  44908 	8:   uint8(0xf7),
  44909 	9:   uint8(0xf6),
  44910 	10:  uint8(0xf5),
  44911 	11:  uint8(0xf4),
  44912 	12:  uint8(0xf3),
  44913 	13:  uint8(0xf2),
  44914 	14:  uint8(0xf1),
  44915 	15:  uint8(0xf0),
  44916 	16:  uint8(0xef),
  44917 	17:  uint8(0xee),
  44918 	18:  uint8(0xed),
  44919 	19:  uint8(0xec),
  44920 	20:  uint8(0xeb),
  44921 	21:  uint8(0xea),
  44922 	22:  uint8(0xe9),
  44923 	23:  uint8(0xe8),
  44924 	24:  uint8(0xe7),
  44925 	25:  uint8(0xe6),
  44926 	26:  uint8(0xe5),
  44927 	27:  uint8(0xe4),
  44928 	28:  uint8(0xe3),
  44929 	29:  uint8(0xe2),
  44930 	30:  uint8(0xe1),
  44931 	31:  uint8(0xe0),
  44932 	32:  uint8(0xdf),
  44933 	33:  uint8(0xde),
  44934 	34:  uint8(0xdd),
  44935 	35:  uint8(0xdc),
  44936 	36:  uint8(0xdb),
  44937 	37:  uint8(0xda),
  44938 	38:  uint8(0xd9),
  44939 	39:  uint8(0xd8),
  44940 	40:  uint8(0xd7),
  44941 	41:  uint8(0xd6),
  44942 	42:  uint8(0xd5),
  44943 	43:  uint8(0xd4),
  44944 	44:  uint8(0xd3),
  44945 	45:  uint8(0xd2),
  44946 	46:  uint8(0xd1),
  44947 	47:  uint8(0xd0),
  44948 	48:  uint8(0xcf),
  44949 	49:  uint8(0xce),
  44950 	50:  uint8(0xcd),
  44951 	51:  uint8(0xcc),
  44952 	52:  uint8(0xcb),
  44953 	53:  uint8(0xca),
  44954 	54:  uint8(0xc9),
  44955 	55:  uint8(0xc8),
  44956 	56:  uint8(0xc7),
  44957 	57:  uint8(0xc6),
  44958 	58:  uint8(0xc5),
  44959 	59:  uint8(0xc4),
  44960 	60:  uint8(0xc3),
  44961 	61:  uint8(0xc2),
  44962 	62:  uint8(0xc1),
  44963 	63:  uint8(0xc0),
  44964 	64:  uint8(0xbf),
  44965 	65:  uint8(0xbe),
  44966 	66:  uint8(0xbd),
  44967 	67:  uint8(0xbc),
  44968 	68:  uint8(0xbb),
  44969 	69:  uint8(0xba),
  44970 	70:  uint8(0xb9),
  44971 	71:  uint8(0xb8),
  44972 	72:  uint8(0xb7),
  44973 	73:  uint8(0xb6),
  44974 	74:  uint8(0xb5),
  44975 	75:  uint8(0xb4),
  44976 	76:  uint8(0xb3),
  44977 	77:  uint8(0xb2),
  44978 	78:  uint8(0xb1),
  44979 	79:  uint8(0xb0),
  44980 	80:  uint8(0xaf),
  44981 	81:  uint8(0xae),
  44982 	82:  uint8(0xad),
  44983 	83:  uint8(0xac),
  44984 	84:  uint8(0xab),
  44985 	85:  uint8(0xaa),
  44986 	86:  uint8(0xa9),
  44987 	87:  uint8(0xa8),
  44988 	88:  uint8(0xa7),
  44989 	89:  uint8(0xa6),
  44990 	90:  uint8(0xa5),
  44991 	91:  uint8(0xa4),
  44992 	92:  uint8(0xa3),
  44993 	93:  uint8(0xa2),
  44994 	94:  uint8(0xa1),
  44995 	95:  uint8(0xa0),
  44996 	96:  uint8(0x9f),
  44997 	97:  uint8(0x9e),
  44998 	98:  uint8(0x9d),
  44999 	99:  uint8(0x9c),
  45000 	100: uint8(0x9b),
  45001 	101: uint8(0x9a),
  45002 	102: uint8(0x99),
  45003 	103: uint8(0x98),
  45004 	104: uint8(0x97),
  45005 	105: uint8(0x96),
  45006 	106: uint8(0x95),
  45007 	107: uint8(0x94),
  45008 	108: uint8(0x93),
  45009 	109: uint8(0x92),
  45010 	110: uint8(0x91),
  45011 	111: uint8(0x90),
  45012 	112: uint8(0x8f),
  45013 	113: uint8(0x8e),
  45014 	114: uint8(0x8d),
  45015 	115: uint8(0x8c),
  45016 	116: uint8(0x8b),
  45017 	117: uint8(0x8a),
  45018 	118: uint8(0x89),
  45019 	119: uint8(0x88),
  45020 	120: uint8(0x87),
  45021 	121: uint8(0x86),
  45022 	122: uint8(0x85),
  45023 	123: uint8(0x84),
  45024 	124: uint8(0x83),
  45025 	125: uint8(0x82),
  45026 	126: uint8(0x81),
  45027 	127: uint8(0x80),
  45028 	128: uint8(0x7f),
  45029 	129: uint8(0x7e),
  45030 	130: uint8(0x7d),
  45031 	131: uint8(0x7c),
  45032 	132: uint8(0x7b),
  45033 	133: uint8(0x7a),
  45034 	134: uint8(0x79),
  45035 	135: uint8(0x78),
  45036 	136: uint8(0x77),
  45037 	137: uint8(0x76),
  45038 	138: uint8(0x75),
  45039 	139: uint8(0x74),
  45040 	140: uint8(0x73),
  45041 	141: uint8(0x72),
  45042 	142: uint8(0x71),
  45043 	143: uint8(0x70),
  45044 	144: uint8(0x6f),
  45045 	145: uint8(0x6e),
  45046 	146: uint8(0x6d),
  45047 	147: uint8(0x6c),
  45048 	148: uint8(0x6b),
  45049 	149: uint8(0x6a),
  45050 	150: uint8(0x69),
  45051 	151: uint8(0x68),
  45052 	152: uint8(0x67),
  45053 	153: uint8(0x66),
  45054 	154: uint8(0x65),
  45055 	155: uint8(0x64),
  45056 	156: uint8(0x63),
  45057 	157: uint8(0x62),
  45058 	158: uint8(0x61),
  45059 	159: uint8(0x60),
  45060 	160: uint8(0x5f),
  45061 	161: uint8(0x5e),
  45062 	162: uint8(0x5d),
  45063 	163: uint8(0x5c),
  45064 	164: uint8(0x5b),
  45065 	165: uint8(0x5a),
  45066 	166: uint8(0x59),
  45067 	167: uint8(0x58),
  45068 	168: uint8(0x57),
  45069 	169: uint8(0x56),
  45070 	170: uint8(0x55),
  45071 	171: uint8(0x54),
  45072 	172: uint8(0x53),
  45073 	173: uint8(0x52),
  45074 	174: uint8(0x51),
  45075 	175: uint8(0x50),
  45076 	176: uint8(0x4f),
  45077 	177: uint8(0x4e),
  45078 	178: uint8(0x4d),
  45079 	179: uint8(0x4c),
  45080 	180: uint8(0x4b),
  45081 	181: uint8(0x4a),
  45082 	182: uint8(0x49),
  45083 	183: uint8(0x48),
  45084 	184: uint8(0x47),
  45085 	185: uint8(0x46),
  45086 	186: uint8(0x45),
  45087 	187: uint8(0x44),
  45088 	188: uint8(0x43),
  45089 	189: uint8(0x42),
  45090 	190: uint8(0x41),
  45091 	191: uint8(0x40),
  45092 	192: uint8(0x3f),
  45093 	193: uint8(0x3e),
  45094 	194: uint8(0x3d),
  45095 	195: uint8(0x3c),
  45096 	196: uint8(0x3b),
  45097 	197: uint8(0x3a),
  45098 	198: uint8(0x39),
  45099 	199: uint8(0x38),
  45100 	200: uint8(0x37),
  45101 	201: uint8(0x36),
  45102 	202: uint8(0x35),
  45103 	203: uint8(0x34),
  45104 	204: uint8(0x33),
  45105 	205: uint8(0x32),
  45106 	206: uint8(0x31),
  45107 	207: uint8(0x30),
  45108 	208: uint8(0x2f),
  45109 	209: uint8(0x2e),
  45110 	210: uint8(0x2d),
  45111 	211: uint8(0x2c),
  45112 	212: uint8(0x2b),
  45113 	213: uint8(0x2a),
  45114 	214: uint8(0x29),
  45115 	215: uint8(0x28),
  45116 	216: uint8(0x27),
  45117 	217: uint8(0x26),
  45118 	218: uint8(0x25),
  45119 	219: uint8(0x24),
  45120 	220: uint8(0x23),
  45121 	221: uint8(0x22),
  45122 	222: uint8(0x21),
  45123 	223: uint8(0x20),
  45124 	224: uint8(0x1f),
  45125 	225: uint8(0x1e),
  45126 	226: uint8(0x1d),
  45127 	227: uint8(0x1c),
  45128 	228: uint8(0x1b),
  45129 	229: uint8(0x1a),
  45130 	230: uint8(0x19),
  45131 	231: uint8(0x18),
  45132 	232: uint8(0x17),
  45133 	233: uint8(0x16),
  45134 	234: uint8(0x15),
  45135 	235: uint8(0x14),
  45136 	236: uint8(0x13),
  45137 	237: uint8(0x12),
  45138 	238: uint8(0x11),
  45139 	239: uint8(0x10),
  45140 	240: uint8(0x0f),
  45141 	241: uint8(0x0e),
  45142 	242: uint8(0x0d),
  45143 	243: uint8(0x0c),
  45144 	244: uint8(0x0b),
  45145 	245: uint8(0x0a),
  45146 	246: uint8(0x09),
  45147 	247: uint8(0x08),
  45148 	248: uint8(0x07),
  45149 	249: uint8(0x06),
  45150 	250: uint8(0x05),
  45151 	251: uint8(0x04),
  45152 	252: uint8(0x03),
  45153 	253: uint8(0x02),
  45154 	254: uint8(0x01),
  45155 	256: uint8(0x01),
  45156 	257: uint8(0x02),
  45157 	258: uint8(0x03),
  45158 	259: uint8(0x04),
  45159 	260: uint8(0x05),
  45160 	261: uint8(0x06),
  45161 	262: uint8(0x07),
  45162 	263: uint8(0x08),
  45163 	264: uint8(0x09),
  45164 	265: uint8(0x0a),
  45165 	266: uint8(0x0b),
  45166 	267: uint8(0x0c),
  45167 	268: uint8(0x0d),
  45168 	269: uint8(0x0e),
  45169 	270: uint8(0x0f),
  45170 	271: uint8(0x10),
  45171 	272: uint8(0x11),
  45172 	273: uint8(0x12),
  45173 	274: uint8(0x13),
  45174 	275: uint8(0x14),
  45175 	276: uint8(0x15),
  45176 	277: uint8(0x16),
  45177 	278: uint8(0x17),
  45178 	279: uint8(0x18),
  45179 	280: uint8(0x19),
  45180 	281: uint8(0x1a),
  45181 	282: uint8(0x1b),
  45182 	283: uint8(0x1c),
  45183 	284: uint8(0x1d),
  45184 	285: uint8(0x1e),
  45185 	286: uint8(0x1f),
  45186 	287: uint8(0x20),
  45187 	288: uint8(0x21),
  45188 	289: uint8(0x22),
  45189 	290: uint8(0x23),
  45190 	291: uint8(0x24),
  45191 	292: uint8(0x25),
  45192 	293: uint8(0x26),
  45193 	294: uint8(0x27),
  45194 	295: uint8(0x28),
  45195 	296: uint8(0x29),
  45196 	297: uint8(0x2a),
  45197 	298: uint8(0x2b),
  45198 	299: uint8(0x2c),
  45199 	300: uint8(0x2d),
  45200 	301: uint8(0x2e),
  45201 	302: uint8(0x2f),
  45202 	303: uint8(0x30),
  45203 	304: uint8(0x31),
  45204 	305: uint8(0x32),
  45205 	306: uint8(0x33),
  45206 	307: uint8(0x34),
  45207 	308: uint8(0x35),
  45208 	309: uint8(0x36),
  45209 	310: uint8(0x37),
  45210 	311: uint8(0x38),
  45211 	312: uint8(0x39),
  45212 	313: uint8(0x3a),
  45213 	314: uint8(0x3b),
  45214 	315: uint8(0x3c),
  45215 	316: uint8(0x3d),
  45216 	317: uint8(0x3e),
  45217 	318: uint8(0x3f),
  45218 	319: uint8(0x40),
  45219 	320: uint8(0x41),
  45220 	321: uint8(0x42),
  45221 	322: uint8(0x43),
  45222 	323: uint8(0x44),
  45223 	324: uint8(0x45),
  45224 	325: uint8(0x46),
  45225 	326: uint8(0x47),
  45226 	327: uint8(0x48),
  45227 	328: uint8(0x49),
  45228 	329: uint8(0x4a),
  45229 	330: uint8(0x4b),
  45230 	331: uint8(0x4c),
  45231 	332: uint8(0x4d),
  45232 	333: uint8(0x4e),
  45233 	334: uint8(0x4f),
  45234 	335: uint8(0x50),
  45235 	336: uint8(0x51),
  45236 	337: uint8(0x52),
  45237 	338: uint8(0x53),
  45238 	339: uint8(0x54),
  45239 	340: uint8(0x55),
  45240 	341: uint8(0x56),
  45241 	342: uint8(0x57),
  45242 	343: uint8(0x58),
  45243 	344: uint8(0x59),
  45244 	345: uint8(0x5a),
  45245 	346: uint8(0x5b),
  45246 	347: uint8(0x5c),
  45247 	348: uint8(0x5d),
  45248 	349: uint8(0x5e),
  45249 	350: uint8(0x5f),
  45250 	351: uint8(0x60),
  45251 	352: uint8(0x61),
  45252 	353: uint8(0x62),
  45253 	354: uint8(0x63),
  45254 	355: uint8(0x64),
  45255 	356: uint8(0x65),
  45256 	357: uint8(0x66),
  45257 	358: uint8(0x67),
  45258 	359: uint8(0x68),
  45259 	360: uint8(0x69),
  45260 	361: uint8(0x6a),
  45261 	362: uint8(0x6b),
  45262 	363: uint8(0x6c),
  45263 	364: uint8(0x6d),
  45264 	365: uint8(0x6e),
  45265 	366: uint8(0x6f),
  45266 	367: uint8(0x70),
  45267 	368: uint8(0x71),
  45268 	369: uint8(0x72),
  45269 	370: uint8(0x73),
  45270 	371: uint8(0x74),
  45271 	372: uint8(0x75),
  45272 	373: uint8(0x76),
  45273 	374: uint8(0x77),
  45274 	375: uint8(0x78),
  45275 	376: uint8(0x79),
  45276 	377: uint8(0x7a),
  45277 	378: uint8(0x7b),
  45278 	379: uint8(0x7c),
  45279 	380: uint8(0x7d),
  45280 	381: uint8(0x7e),
  45281 	382: uint8(0x7f),
  45282 	383: uint8(0x80),
  45283 	384: uint8(0x81),
  45284 	385: uint8(0x82),
  45285 	386: uint8(0x83),
  45286 	387: uint8(0x84),
  45287 	388: uint8(0x85),
  45288 	389: uint8(0x86),
  45289 	390: uint8(0x87),
  45290 	391: uint8(0x88),
  45291 	392: uint8(0x89),
  45292 	393: uint8(0x8a),
  45293 	394: uint8(0x8b),
  45294 	395: uint8(0x8c),
  45295 	396: uint8(0x8d),
  45296 	397: uint8(0x8e),
  45297 	398: uint8(0x8f),
  45298 	399: uint8(0x90),
  45299 	400: uint8(0x91),
  45300 	401: uint8(0x92),
  45301 	402: uint8(0x93),
  45302 	403: uint8(0x94),
  45303 	404: uint8(0x95),
  45304 	405: uint8(0x96),
  45305 	406: uint8(0x97),
  45306 	407: uint8(0x98),
  45307 	408: uint8(0x99),
  45308 	409: uint8(0x9a),
  45309 	410: uint8(0x9b),
  45310 	411: uint8(0x9c),
  45311 	412: uint8(0x9d),
  45312 	413: uint8(0x9e),
  45313 	414: uint8(0x9f),
  45314 	415: uint8(0xa0),
  45315 	416: uint8(0xa1),
  45316 	417: uint8(0xa2),
  45317 	418: uint8(0xa3),
  45318 	419: uint8(0xa4),
  45319 	420: uint8(0xa5),
  45320 	421: uint8(0xa6),
  45321 	422: uint8(0xa7),
  45322 	423: uint8(0xa8),
  45323 	424: uint8(0xa9),
  45324 	425: uint8(0xaa),
  45325 	426: uint8(0xab),
  45326 	427: uint8(0xac),
  45327 	428: uint8(0xad),
  45328 	429: uint8(0xae),
  45329 	430: uint8(0xaf),
  45330 	431: uint8(0xb0),
  45331 	432: uint8(0xb1),
  45332 	433: uint8(0xb2),
  45333 	434: uint8(0xb3),
  45334 	435: uint8(0xb4),
  45335 	436: uint8(0xb5),
  45336 	437: uint8(0xb6),
  45337 	438: uint8(0xb7),
  45338 	439: uint8(0xb8),
  45339 	440: uint8(0xb9),
  45340 	441: uint8(0xba),
  45341 	442: uint8(0xbb),
  45342 	443: uint8(0xbc),
  45343 	444: uint8(0xbd),
  45344 	445: uint8(0xbe),
  45345 	446: uint8(0xbf),
  45346 	447: uint8(0xc0),
  45347 	448: uint8(0xc1),
  45348 	449: uint8(0xc2),
  45349 	450: uint8(0xc3),
  45350 	451: uint8(0xc4),
  45351 	452: uint8(0xc5),
  45352 	453: uint8(0xc6),
  45353 	454: uint8(0xc7),
  45354 	455: uint8(0xc8),
  45355 	456: uint8(0xc9),
  45356 	457: uint8(0xca),
  45357 	458: uint8(0xcb),
  45358 	459: uint8(0xcc),
  45359 	460: uint8(0xcd),
  45360 	461: uint8(0xce),
  45361 	462: uint8(0xcf),
  45362 	463: uint8(0xd0),
  45363 	464: uint8(0xd1),
  45364 	465: uint8(0xd2),
  45365 	466: uint8(0xd3),
  45366 	467: uint8(0xd4),
  45367 	468: uint8(0xd5),
  45368 	469: uint8(0xd6),
  45369 	470: uint8(0xd7),
  45370 	471: uint8(0xd8),
  45371 	472: uint8(0xd9),
  45372 	473: uint8(0xda),
  45373 	474: uint8(0xdb),
  45374 	475: uint8(0xdc),
  45375 	476: uint8(0xdd),
  45376 	477: uint8(0xde),
  45377 	478: uint8(0xdf),
  45378 	479: uint8(0xe0),
  45379 	480: uint8(0xe1),
  45380 	481: uint8(0xe2),
  45381 	482: uint8(0xe3),
  45382 	483: uint8(0xe4),
  45383 	484: uint8(0xe5),
  45384 	485: uint8(0xe6),
  45385 	486: uint8(0xe7),
  45386 	487: uint8(0xe8),
  45387 	488: uint8(0xe9),
  45388 	489: uint8(0xea),
  45389 	490: uint8(0xeb),
  45390 	491: uint8(0xec),
  45391 	492: uint8(0xed),
  45392 	493: uint8(0xee),
  45393 	494: uint8(0xef),
  45394 	495: uint8(0xf0),
  45395 	496: uint8(0xf1),
  45396 	497: uint8(0xf2),
  45397 	498: uint8(0xf3),
  45398 	499: uint8(0xf4),
  45399 	500: uint8(0xf5),
  45400 	501: uint8(0xf6),
  45401 	502: uint8(0xf7),
  45402 	503: uint8(0xf8),
  45403 	504: uint8(0xf9),
  45404 	505: uint8(0xfa),
  45405 	506: uint8(0xfb),
  45406 	507: uint8(0xfc),
  45407 	508: uint8(0xfd),
  45408 	509: uint8(0xfe),
  45409 	510: uint8(0xff),
  45410 }
  45411 
  45412 var sclip1 = [2041]uint8_t{
  45413 	0:    uint8(0x80),
  45414 	1:    uint8(0x80),
  45415 	2:    uint8(0x80),
  45416 	3:    uint8(0x80),
  45417 	4:    uint8(0x80),
  45418 	5:    uint8(0x80),
  45419 	6:    uint8(0x80),
  45420 	7:    uint8(0x80),
  45421 	8:    uint8(0x80),
  45422 	9:    uint8(0x80),
  45423 	10:   uint8(0x80),
  45424 	11:   uint8(0x80),
  45425 	12:   uint8(0x80),
  45426 	13:   uint8(0x80),
  45427 	14:   uint8(0x80),
  45428 	15:   uint8(0x80),
  45429 	16:   uint8(0x80),
  45430 	17:   uint8(0x80),
  45431 	18:   uint8(0x80),
  45432 	19:   uint8(0x80),
  45433 	20:   uint8(0x80),
  45434 	21:   uint8(0x80),
  45435 	22:   uint8(0x80),
  45436 	23:   uint8(0x80),
  45437 	24:   uint8(0x80),
  45438 	25:   uint8(0x80),
  45439 	26:   uint8(0x80),
  45440 	27:   uint8(0x80),
  45441 	28:   uint8(0x80),
  45442 	29:   uint8(0x80),
  45443 	30:   uint8(0x80),
  45444 	31:   uint8(0x80),
  45445 	32:   uint8(0x80),
  45446 	33:   uint8(0x80),
  45447 	34:   uint8(0x80),
  45448 	35:   uint8(0x80),
  45449 	36:   uint8(0x80),
  45450 	37:   uint8(0x80),
  45451 	38:   uint8(0x80),
  45452 	39:   uint8(0x80),
  45453 	40:   uint8(0x80),
  45454 	41:   uint8(0x80),
  45455 	42:   uint8(0x80),
  45456 	43:   uint8(0x80),
  45457 	44:   uint8(0x80),
  45458 	45:   uint8(0x80),
  45459 	46:   uint8(0x80),
  45460 	47:   uint8(0x80),
  45461 	48:   uint8(0x80),
  45462 	49:   uint8(0x80),
  45463 	50:   uint8(0x80),
  45464 	51:   uint8(0x80),
  45465 	52:   uint8(0x80),
  45466 	53:   uint8(0x80),
  45467 	54:   uint8(0x80),
  45468 	55:   uint8(0x80),
  45469 	56:   uint8(0x80),
  45470 	57:   uint8(0x80),
  45471 	58:   uint8(0x80),
  45472 	59:   uint8(0x80),
  45473 	60:   uint8(0x80),
  45474 	61:   uint8(0x80),
  45475 	62:   uint8(0x80),
  45476 	63:   uint8(0x80),
  45477 	64:   uint8(0x80),
  45478 	65:   uint8(0x80),
  45479 	66:   uint8(0x80),
  45480 	67:   uint8(0x80),
  45481 	68:   uint8(0x80),
  45482 	69:   uint8(0x80),
  45483 	70:   uint8(0x80),
  45484 	71:   uint8(0x80),
  45485 	72:   uint8(0x80),
  45486 	73:   uint8(0x80),
  45487 	74:   uint8(0x80),
  45488 	75:   uint8(0x80),
  45489 	76:   uint8(0x80),
  45490 	77:   uint8(0x80),
  45491 	78:   uint8(0x80),
  45492 	79:   uint8(0x80),
  45493 	80:   uint8(0x80),
  45494 	81:   uint8(0x80),
  45495 	82:   uint8(0x80),
  45496 	83:   uint8(0x80),
  45497 	84:   uint8(0x80),
  45498 	85:   uint8(0x80),
  45499 	86:   uint8(0x80),
  45500 	87:   uint8(0x80),
  45501 	88:   uint8(0x80),
  45502 	89:   uint8(0x80),
  45503 	90:   uint8(0x80),
  45504 	91:   uint8(0x80),
  45505 	92:   uint8(0x80),
  45506 	93:   uint8(0x80),
  45507 	94:   uint8(0x80),
  45508 	95:   uint8(0x80),
  45509 	96:   uint8(0x80),
  45510 	97:   uint8(0x80),
  45511 	98:   uint8(0x80),
  45512 	99:   uint8(0x80),
  45513 	100:  uint8(0x80),
  45514 	101:  uint8(0x80),
  45515 	102:  uint8(0x80),
  45516 	103:  uint8(0x80),
  45517 	104:  uint8(0x80),
  45518 	105:  uint8(0x80),
  45519 	106:  uint8(0x80),
  45520 	107:  uint8(0x80),
  45521 	108:  uint8(0x80),
  45522 	109:  uint8(0x80),
  45523 	110:  uint8(0x80),
  45524 	111:  uint8(0x80),
  45525 	112:  uint8(0x80),
  45526 	113:  uint8(0x80),
  45527 	114:  uint8(0x80),
  45528 	115:  uint8(0x80),
  45529 	116:  uint8(0x80),
  45530 	117:  uint8(0x80),
  45531 	118:  uint8(0x80),
  45532 	119:  uint8(0x80),
  45533 	120:  uint8(0x80),
  45534 	121:  uint8(0x80),
  45535 	122:  uint8(0x80),
  45536 	123:  uint8(0x80),
  45537 	124:  uint8(0x80),
  45538 	125:  uint8(0x80),
  45539 	126:  uint8(0x80),
  45540 	127:  uint8(0x80),
  45541 	128:  uint8(0x80),
  45542 	129:  uint8(0x80),
  45543 	130:  uint8(0x80),
  45544 	131:  uint8(0x80),
  45545 	132:  uint8(0x80),
  45546 	133:  uint8(0x80),
  45547 	134:  uint8(0x80),
  45548 	135:  uint8(0x80),
  45549 	136:  uint8(0x80),
  45550 	137:  uint8(0x80),
  45551 	138:  uint8(0x80),
  45552 	139:  uint8(0x80),
  45553 	140:  uint8(0x80),
  45554 	141:  uint8(0x80),
  45555 	142:  uint8(0x80),
  45556 	143:  uint8(0x80),
  45557 	144:  uint8(0x80),
  45558 	145:  uint8(0x80),
  45559 	146:  uint8(0x80),
  45560 	147:  uint8(0x80),
  45561 	148:  uint8(0x80),
  45562 	149:  uint8(0x80),
  45563 	150:  uint8(0x80),
  45564 	151:  uint8(0x80),
  45565 	152:  uint8(0x80),
  45566 	153:  uint8(0x80),
  45567 	154:  uint8(0x80),
  45568 	155:  uint8(0x80),
  45569 	156:  uint8(0x80),
  45570 	157:  uint8(0x80),
  45571 	158:  uint8(0x80),
  45572 	159:  uint8(0x80),
  45573 	160:  uint8(0x80),
  45574 	161:  uint8(0x80),
  45575 	162:  uint8(0x80),
  45576 	163:  uint8(0x80),
  45577 	164:  uint8(0x80),
  45578 	165:  uint8(0x80),
  45579 	166:  uint8(0x80),
  45580 	167:  uint8(0x80),
  45581 	168:  uint8(0x80),
  45582 	169:  uint8(0x80),
  45583 	170:  uint8(0x80),
  45584 	171:  uint8(0x80),
  45585 	172:  uint8(0x80),
  45586 	173:  uint8(0x80),
  45587 	174:  uint8(0x80),
  45588 	175:  uint8(0x80),
  45589 	176:  uint8(0x80),
  45590 	177:  uint8(0x80),
  45591 	178:  uint8(0x80),
  45592 	179:  uint8(0x80),
  45593 	180:  uint8(0x80),
  45594 	181:  uint8(0x80),
  45595 	182:  uint8(0x80),
  45596 	183:  uint8(0x80),
  45597 	184:  uint8(0x80),
  45598 	185:  uint8(0x80),
  45599 	186:  uint8(0x80),
  45600 	187:  uint8(0x80),
  45601 	188:  uint8(0x80),
  45602 	189:  uint8(0x80),
  45603 	190:  uint8(0x80),
  45604 	191:  uint8(0x80),
  45605 	192:  uint8(0x80),
  45606 	193:  uint8(0x80),
  45607 	194:  uint8(0x80),
  45608 	195:  uint8(0x80),
  45609 	196:  uint8(0x80),
  45610 	197:  uint8(0x80),
  45611 	198:  uint8(0x80),
  45612 	199:  uint8(0x80),
  45613 	200:  uint8(0x80),
  45614 	201:  uint8(0x80),
  45615 	202:  uint8(0x80),
  45616 	203:  uint8(0x80),
  45617 	204:  uint8(0x80),
  45618 	205:  uint8(0x80),
  45619 	206:  uint8(0x80),
  45620 	207:  uint8(0x80),
  45621 	208:  uint8(0x80),
  45622 	209:  uint8(0x80),
  45623 	210:  uint8(0x80),
  45624 	211:  uint8(0x80),
  45625 	212:  uint8(0x80),
  45626 	213:  uint8(0x80),
  45627 	214:  uint8(0x80),
  45628 	215:  uint8(0x80),
  45629 	216:  uint8(0x80),
  45630 	217:  uint8(0x80),
  45631 	218:  uint8(0x80),
  45632 	219:  uint8(0x80),
  45633 	220:  uint8(0x80),
  45634 	221:  uint8(0x80),
  45635 	222:  uint8(0x80),
  45636 	223:  uint8(0x80),
  45637 	224:  uint8(0x80),
  45638 	225:  uint8(0x80),
  45639 	226:  uint8(0x80),
  45640 	227:  uint8(0x80),
  45641 	228:  uint8(0x80),
  45642 	229:  uint8(0x80),
  45643 	230:  uint8(0x80),
  45644 	231:  uint8(0x80),
  45645 	232:  uint8(0x80),
  45646 	233:  uint8(0x80),
  45647 	234:  uint8(0x80),
  45648 	235:  uint8(0x80),
  45649 	236:  uint8(0x80),
  45650 	237:  uint8(0x80),
  45651 	238:  uint8(0x80),
  45652 	239:  uint8(0x80),
  45653 	240:  uint8(0x80),
  45654 	241:  uint8(0x80),
  45655 	242:  uint8(0x80),
  45656 	243:  uint8(0x80),
  45657 	244:  uint8(0x80),
  45658 	245:  uint8(0x80),
  45659 	246:  uint8(0x80),
  45660 	247:  uint8(0x80),
  45661 	248:  uint8(0x80),
  45662 	249:  uint8(0x80),
  45663 	250:  uint8(0x80),
  45664 	251:  uint8(0x80),
  45665 	252:  uint8(0x80),
  45666 	253:  uint8(0x80),
  45667 	254:  uint8(0x80),
  45668 	255:  uint8(0x80),
  45669 	256:  uint8(0x80),
  45670 	257:  uint8(0x80),
  45671 	258:  uint8(0x80),
  45672 	259:  uint8(0x80),
  45673 	260:  uint8(0x80),
  45674 	261:  uint8(0x80),
  45675 	262:  uint8(0x80),
  45676 	263:  uint8(0x80),
  45677 	264:  uint8(0x80),
  45678 	265:  uint8(0x80),
  45679 	266:  uint8(0x80),
  45680 	267:  uint8(0x80),
  45681 	268:  uint8(0x80),
  45682 	269:  uint8(0x80),
  45683 	270:  uint8(0x80),
  45684 	271:  uint8(0x80),
  45685 	272:  uint8(0x80),
  45686 	273:  uint8(0x80),
  45687 	274:  uint8(0x80),
  45688 	275:  uint8(0x80),
  45689 	276:  uint8(0x80),
  45690 	277:  uint8(0x80),
  45691 	278:  uint8(0x80),
  45692 	279:  uint8(0x80),
  45693 	280:  uint8(0x80),
  45694 	281:  uint8(0x80),
  45695 	282:  uint8(0x80),
  45696 	283:  uint8(0x80),
  45697 	284:  uint8(0x80),
  45698 	285:  uint8(0x80),
  45699 	286:  uint8(0x80),
  45700 	287:  uint8(0x80),
  45701 	288:  uint8(0x80),
  45702 	289:  uint8(0x80),
  45703 	290:  uint8(0x80),
  45704 	291:  uint8(0x80),
  45705 	292:  uint8(0x80),
  45706 	293:  uint8(0x80),
  45707 	294:  uint8(0x80),
  45708 	295:  uint8(0x80),
  45709 	296:  uint8(0x80),
  45710 	297:  uint8(0x80),
  45711 	298:  uint8(0x80),
  45712 	299:  uint8(0x80),
  45713 	300:  uint8(0x80),
  45714 	301:  uint8(0x80),
  45715 	302:  uint8(0x80),
  45716 	303:  uint8(0x80),
  45717 	304:  uint8(0x80),
  45718 	305:  uint8(0x80),
  45719 	306:  uint8(0x80),
  45720 	307:  uint8(0x80),
  45721 	308:  uint8(0x80),
  45722 	309:  uint8(0x80),
  45723 	310:  uint8(0x80),
  45724 	311:  uint8(0x80),
  45725 	312:  uint8(0x80),
  45726 	313:  uint8(0x80),
  45727 	314:  uint8(0x80),
  45728 	315:  uint8(0x80),
  45729 	316:  uint8(0x80),
  45730 	317:  uint8(0x80),
  45731 	318:  uint8(0x80),
  45732 	319:  uint8(0x80),
  45733 	320:  uint8(0x80),
  45734 	321:  uint8(0x80),
  45735 	322:  uint8(0x80),
  45736 	323:  uint8(0x80),
  45737 	324:  uint8(0x80),
  45738 	325:  uint8(0x80),
  45739 	326:  uint8(0x80),
  45740 	327:  uint8(0x80),
  45741 	328:  uint8(0x80),
  45742 	329:  uint8(0x80),
  45743 	330:  uint8(0x80),
  45744 	331:  uint8(0x80),
  45745 	332:  uint8(0x80),
  45746 	333:  uint8(0x80),
  45747 	334:  uint8(0x80),
  45748 	335:  uint8(0x80),
  45749 	336:  uint8(0x80),
  45750 	337:  uint8(0x80),
  45751 	338:  uint8(0x80),
  45752 	339:  uint8(0x80),
  45753 	340:  uint8(0x80),
  45754 	341:  uint8(0x80),
  45755 	342:  uint8(0x80),
  45756 	343:  uint8(0x80),
  45757 	344:  uint8(0x80),
  45758 	345:  uint8(0x80),
  45759 	346:  uint8(0x80),
  45760 	347:  uint8(0x80),
  45761 	348:  uint8(0x80),
  45762 	349:  uint8(0x80),
  45763 	350:  uint8(0x80),
  45764 	351:  uint8(0x80),
  45765 	352:  uint8(0x80),
  45766 	353:  uint8(0x80),
  45767 	354:  uint8(0x80),
  45768 	355:  uint8(0x80),
  45769 	356:  uint8(0x80),
  45770 	357:  uint8(0x80),
  45771 	358:  uint8(0x80),
  45772 	359:  uint8(0x80),
  45773 	360:  uint8(0x80),
  45774 	361:  uint8(0x80),
  45775 	362:  uint8(0x80),
  45776 	363:  uint8(0x80),
  45777 	364:  uint8(0x80),
  45778 	365:  uint8(0x80),
  45779 	366:  uint8(0x80),
  45780 	367:  uint8(0x80),
  45781 	368:  uint8(0x80),
  45782 	369:  uint8(0x80),
  45783 	370:  uint8(0x80),
  45784 	371:  uint8(0x80),
  45785 	372:  uint8(0x80),
  45786 	373:  uint8(0x80),
  45787 	374:  uint8(0x80),
  45788 	375:  uint8(0x80),
  45789 	376:  uint8(0x80),
  45790 	377:  uint8(0x80),
  45791 	378:  uint8(0x80),
  45792 	379:  uint8(0x80),
  45793 	380:  uint8(0x80),
  45794 	381:  uint8(0x80),
  45795 	382:  uint8(0x80),
  45796 	383:  uint8(0x80),
  45797 	384:  uint8(0x80),
  45798 	385:  uint8(0x80),
  45799 	386:  uint8(0x80),
  45800 	387:  uint8(0x80),
  45801 	388:  uint8(0x80),
  45802 	389:  uint8(0x80),
  45803 	390:  uint8(0x80),
  45804 	391:  uint8(0x80),
  45805 	392:  uint8(0x80),
  45806 	393:  uint8(0x80),
  45807 	394:  uint8(0x80),
  45808 	395:  uint8(0x80),
  45809 	396:  uint8(0x80),
  45810 	397:  uint8(0x80),
  45811 	398:  uint8(0x80),
  45812 	399:  uint8(0x80),
  45813 	400:  uint8(0x80),
  45814 	401:  uint8(0x80),
  45815 	402:  uint8(0x80),
  45816 	403:  uint8(0x80),
  45817 	404:  uint8(0x80),
  45818 	405:  uint8(0x80),
  45819 	406:  uint8(0x80),
  45820 	407:  uint8(0x80),
  45821 	408:  uint8(0x80),
  45822 	409:  uint8(0x80),
  45823 	410:  uint8(0x80),
  45824 	411:  uint8(0x80),
  45825 	412:  uint8(0x80),
  45826 	413:  uint8(0x80),
  45827 	414:  uint8(0x80),
  45828 	415:  uint8(0x80),
  45829 	416:  uint8(0x80),
  45830 	417:  uint8(0x80),
  45831 	418:  uint8(0x80),
  45832 	419:  uint8(0x80),
  45833 	420:  uint8(0x80),
  45834 	421:  uint8(0x80),
  45835 	422:  uint8(0x80),
  45836 	423:  uint8(0x80),
  45837 	424:  uint8(0x80),
  45838 	425:  uint8(0x80),
  45839 	426:  uint8(0x80),
  45840 	427:  uint8(0x80),
  45841 	428:  uint8(0x80),
  45842 	429:  uint8(0x80),
  45843 	430:  uint8(0x80),
  45844 	431:  uint8(0x80),
  45845 	432:  uint8(0x80),
  45846 	433:  uint8(0x80),
  45847 	434:  uint8(0x80),
  45848 	435:  uint8(0x80),
  45849 	436:  uint8(0x80),
  45850 	437:  uint8(0x80),
  45851 	438:  uint8(0x80),
  45852 	439:  uint8(0x80),
  45853 	440:  uint8(0x80),
  45854 	441:  uint8(0x80),
  45855 	442:  uint8(0x80),
  45856 	443:  uint8(0x80),
  45857 	444:  uint8(0x80),
  45858 	445:  uint8(0x80),
  45859 	446:  uint8(0x80),
  45860 	447:  uint8(0x80),
  45861 	448:  uint8(0x80),
  45862 	449:  uint8(0x80),
  45863 	450:  uint8(0x80),
  45864 	451:  uint8(0x80),
  45865 	452:  uint8(0x80),
  45866 	453:  uint8(0x80),
  45867 	454:  uint8(0x80),
  45868 	455:  uint8(0x80),
  45869 	456:  uint8(0x80),
  45870 	457:  uint8(0x80),
  45871 	458:  uint8(0x80),
  45872 	459:  uint8(0x80),
  45873 	460:  uint8(0x80),
  45874 	461:  uint8(0x80),
  45875 	462:  uint8(0x80),
  45876 	463:  uint8(0x80),
  45877 	464:  uint8(0x80),
  45878 	465:  uint8(0x80),
  45879 	466:  uint8(0x80),
  45880 	467:  uint8(0x80),
  45881 	468:  uint8(0x80),
  45882 	469:  uint8(0x80),
  45883 	470:  uint8(0x80),
  45884 	471:  uint8(0x80),
  45885 	472:  uint8(0x80),
  45886 	473:  uint8(0x80),
  45887 	474:  uint8(0x80),
  45888 	475:  uint8(0x80),
  45889 	476:  uint8(0x80),
  45890 	477:  uint8(0x80),
  45891 	478:  uint8(0x80),
  45892 	479:  uint8(0x80),
  45893 	480:  uint8(0x80),
  45894 	481:  uint8(0x80),
  45895 	482:  uint8(0x80),
  45896 	483:  uint8(0x80),
  45897 	484:  uint8(0x80),
  45898 	485:  uint8(0x80),
  45899 	486:  uint8(0x80),
  45900 	487:  uint8(0x80),
  45901 	488:  uint8(0x80),
  45902 	489:  uint8(0x80),
  45903 	490:  uint8(0x80),
  45904 	491:  uint8(0x80),
  45905 	492:  uint8(0x80),
  45906 	493:  uint8(0x80),
  45907 	494:  uint8(0x80),
  45908 	495:  uint8(0x80),
  45909 	496:  uint8(0x80),
  45910 	497:  uint8(0x80),
  45911 	498:  uint8(0x80),
  45912 	499:  uint8(0x80),
  45913 	500:  uint8(0x80),
  45914 	501:  uint8(0x80),
  45915 	502:  uint8(0x80),
  45916 	503:  uint8(0x80),
  45917 	504:  uint8(0x80),
  45918 	505:  uint8(0x80),
  45919 	506:  uint8(0x80),
  45920 	507:  uint8(0x80),
  45921 	508:  uint8(0x80),
  45922 	509:  uint8(0x80),
  45923 	510:  uint8(0x80),
  45924 	511:  uint8(0x80),
  45925 	512:  uint8(0x80),
  45926 	513:  uint8(0x80),
  45927 	514:  uint8(0x80),
  45928 	515:  uint8(0x80),
  45929 	516:  uint8(0x80),
  45930 	517:  uint8(0x80),
  45931 	518:  uint8(0x80),
  45932 	519:  uint8(0x80),
  45933 	520:  uint8(0x80),
  45934 	521:  uint8(0x80),
  45935 	522:  uint8(0x80),
  45936 	523:  uint8(0x80),
  45937 	524:  uint8(0x80),
  45938 	525:  uint8(0x80),
  45939 	526:  uint8(0x80),
  45940 	527:  uint8(0x80),
  45941 	528:  uint8(0x80),
  45942 	529:  uint8(0x80),
  45943 	530:  uint8(0x80),
  45944 	531:  uint8(0x80),
  45945 	532:  uint8(0x80),
  45946 	533:  uint8(0x80),
  45947 	534:  uint8(0x80),
  45948 	535:  uint8(0x80),
  45949 	536:  uint8(0x80),
  45950 	537:  uint8(0x80),
  45951 	538:  uint8(0x80),
  45952 	539:  uint8(0x80),
  45953 	540:  uint8(0x80),
  45954 	541:  uint8(0x80),
  45955 	542:  uint8(0x80),
  45956 	543:  uint8(0x80),
  45957 	544:  uint8(0x80),
  45958 	545:  uint8(0x80),
  45959 	546:  uint8(0x80),
  45960 	547:  uint8(0x80),
  45961 	548:  uint8(0x80),
  45962 	549:  uint8(0x80),
  45963 	550:  uint8(0x80),
  45964 	551:  uint8(0x80),
  45965 	552:  uint8(0x80),
  45966 	553:  uint8(0x80),
  45967 	554:  uint8(0x80),
  45968 	555:  uint8(0x80),
  45969 	556:  uint8(0x80),
  45970 	557:  uint8(0x80),
  45971 	558:  uint8(0x80),
  45972 	559:  uint8(0x80),
  45973 	560:  uint8(0x80),
  45974 	561:  uint8(0x80),
  45975 	562:  uint8(0x80),
  45976 	563:  uint8(0x80),
  45977 	564:  uint8(0x80),
  45978 	565:  uint8(0x80),
  45979 	566:  uint8(0x80),
  45980 	567:  uint8(0x80),
  45981 	568:  uint8(0x80),
  45982 	569:  uint8(0x80),
  45983 	570:  uint8(0x80),
  45984 	571:  uint8(0x80),
  45985 	572:  uint8(0x80),
  45986 	573:  uint8(0x80),
  45987 	574:  uint8(0x80),
  45988 	575:  uint8(0x80),
  45989 	576:  uint8(0x80),
  45990 	577:  uint8(0x80),
  45991 	578:  uint8(0x80),
  45992 	579:  uint8(0x80),
  45993 	580:  uint8(0x80),
  45994 	581:  uint8(0x80),
  45995 	582:  uint8(0x80),
  45996 	583:  uint8(0x80),
  45997 	584:  uint8(0x80),
  45998 	585:  uint8(0x80),
  45999 	586:  uint8(0x80),
  46000 	587:  uint8(0x80),
  46001 	588:  uint8(0x80),
  46002 	589:  uint8(0x80),
  46003 	590:  uint8(0x80),
  46004 	591:  uint8(0x80),
  46005 	592:  uint8(0x80),
  46006 	593:  uint8(0x80),
  46007 	594:  uint8(0x80),
  46008 	595:  uint8(0x80),
  46009 	596:  uint8(0x80),
  46010 	597:  uint8(0x80),
  46011 	598:  uint8(0x80),
  46012 	599:  uint8(0x80),
  46013 	600:  uint8(0x80),
  46014 	601:  uint8(0x80),
  46015 	602:  uint8(0x80),
  46016 	603:  uint8(0x80),
  46017 	604:  uint8(0x80),
  46018 	605:  uint8(0x80),
  46019 	606:  uint8(0x80),
  46020 	607:  uint8(0x80),
  46021 	608:  uint8(0x80),
  46022 	609:  uint8(0x80),
  46023 	610:  uint8(0x80),
  46024 	611:  uint8(0x80),
  46025 	612:  uint8(0x80),
  46026 	613:  uint8(0x80),
  46027 	614:  uint8(0x80),
  46028 	615:  uint8(0x80),
  46029 	616:  uint8(0x80),
  46030 	617:  uint8(0x80),
  46031 	618:  uint8(0x80),
  46032 	619:  uint8(0x80),
  46033 	620:  uint8(0x80),
  46034 	621:  uint8(0x80),
  46035 	622:  uint8(0x80),
  46036 	623:  uint8(0x80),
  46037 	624:  uint8(0x80),
  46038 	625:  uint8(0x80),
  46039 	626:  uint8(0x80),
  46040 	627:  uint8(0x80),
  46041 	628:  uint8(0x80),
  46042 	629:  uint8(0x80),
  46043 	630:  uint8(0x80),
  46044 	631:  uint8(0x80),
  46045 	632:  uint8(0x80),
  46046 	633:  uint8(0x80),
  46047 	634:  uint8(0x80),
  46048 	635:  uint8(0x80),
  46049 	636:  uint8(0x80),
  46050 	637:  uint8(0x80),
  46051 	638:  uint8(0x80),
  46052 	639:  uint8(0x80),
  46053 	640:  uint8(0x80),
  46054 	641:  uint8(0x80),
  46055 	642:  uint8(0x80),
  46056 	643:  uint8(0x80),
  46057 	644:  uint8(0x80),
  46058 	645:  uint8(0x80),
  46059 	646:  uint8(0x80),
  46060 	647:  uint8(0x80),
  46061 	648:  uint8(0x80),
  46062 	649:  uint8(0x80),
  46063 	650:  uint8(0x80),
  46064 	651:  uint8(0x80),
  46065 	652:  uint8(0x80),
  46066 	653:  uint8(0x80),
  46067 	654:  uint8(0x80),
  46068 	655:  uint8(0x80),
  46069 	656:  uint8(0x80),
  46070 	657:  uint8(0x80),
  46071 	658:  uint8(0x80),
  46072 	659:  uint8(0x80),
  46073 	660:  uint8(0x80),
  46074 	661:  uint8(0x80),
  46075 	662:  uint8(0x80),
  46076 	663:  uint8(0x80),
  46077 	664:  uint8(0x80),
  46078 	665:  uint8(0x80),
  46079 	666:  uint8(0x80),
  46080 	667:  uint8(0x80),
  46081 	668:  uint8(0x80),
  46082 	669:  uint8(0x80),
  46083 	670:  uint8(0x80),
  46084 	671:  uint8(0x80),
  46085 	672:  uint8(0x80),
  46086 	673:  uint8(0x80),
  46087 	674:  uint8(0x80),
  46088 	675:  uint8(0x80),
  46089 	676:  uint8(0x80),
  46090 	677:  uint8(0x80),
  46091 	678:  uint8(0x80),
  46092 	679:  uint8(0x80),
  46093 	680:  uint8(0x80),
  46094 	681:  uint8(0x80),
  46095 	682:  uint8(0x80),
  46096 	683:  uint8(0x80),
  46097 	684:  uint8(0x80),
  46098 	685:  uint8(0x80),
  46099 	686:  uint8(0x80),
  46100 	687:  uint8(0x80),
  46101 	688:  uint8(0x80),
  46102 	689:  uint8(0x80),
  46103 	690:  uint8(0x80),
  46104 	691:  uint8(0x80),
  46105 	692:  uint8(0x80),
  46106 	693:  uint8(0x80),
  46107 	694:  uint8(0x80),
  46108 	695:  uint8(0x80),
  46109 	696:  uint8(0x80),
  46110 	697:  uint8(0x80),
  46111 	698:  uint8(0x80),
  46112 	699:  uint8(0x80),
  46113 	700:  uint8(0x80),
  46114 	701:  uint8(0x80),
  46115 	702:  uint8(0x80),
  46116 	703:  uint8(0x80),
  46117 	704:  uint8(0x80),
  46118 	705:  uint8(0x80),
  46119 	706:  uint8(0x80),
  46120 	707:  uint8(0x80),
  46121 	708:  uint8(0x80),
  46122 	709:  uint8(0x80),
  46123 	710:  uint8(0x80),
  46124 	711:  uint8(0x80),
  46125 	712:  uint8(0x80),
  46126 	713:  uint8(0x80),
  46127 	714:  uint8(0x80),
  46128 	715:  uint8(0x80),
  46129 	716:  uint8(0x80),
  46130 	717:  uint8(0x80),
  46131 	718:  uint8(0x80),
  46132 	719:  uint8(0x80),
  46133 	720:  uint8(0x80),
  46134 	721:  uint8(0x80),
  46135 	722:  uint8(0x80),
  46136 	723:  uint8(0x80),
  46137 	724:  uint8(0x80),
  46138 	725:  uint8(0x80),
  46139 	726:  uint8(0x80),
  46140 	727:  uint8(0x80),
  46141 	728:  uint8(0x80),
  46142 	729:  uint8(0x80),
  46143 	730:  uint8(0x80),
  46144 	731:  uint8(0x80),
  46145 	732:  uint8(0x80),
  46146 	733:  uint8(0x80),
  46147 	734:  uint8(0x80),
  46148 	735:  uint8(0x80),
  46149 	736:  uint8(0x80),
  46150 	737:  uint8(0x80),
  46151 	738:  uint8(0x80),
  46152 	739:  uint8(0x80),
  46153 	740:  uint8(0x80),
  46154 	741:  uint8(0x80),
  46155 	742:  uint8(0x80),
  46156 	743:  uint8(0x80),
  46157 	744:  uint8(0x80),
  46158 	745:  uint8(0x80),
  46159 	746:  uint8(0x80),
  46160 	747:  uint8(0x80),
  46161 	748:  uint8(0x80),
  46162 	749:  uint8(0x80),
  46163 	750:  uint8(0x80),
  46164 	751:  uint8(0x80),
  46165 	752:  uint8(0x80),
  46166 	753:  uint8(0x80),
  46167 	754:  uint8(0x80),
  46168 	755:  uint8(0x80),
  46169 	756:  uint8(0x80),
  46170 	757:  uint8(0x80),
  46171 	758:  uint8(0x80),
  46172 	759:  uint8(0x80),
  46173 	760:  uint8(0x80),
  46174 	761:  uint8(0x80),
  46175 	762:  uint8(0x80),
  46176 	763:  uint8(0x80),
  46177 	764:  uint8(0x80),
  46178 	765:  uint8(0x80),
  46179 	766:  uint8(0x80),
  46180 	767:  uint8(0x80),
  46181 	768:  uint8(0x80),
  46182 	769:  uint8(0x80),
  46183 	770:  uint8(0x80),
  46184 	771:  uint8(0x80),
  46185 	772:  uint8(0x80),
  46186 	773:  uint8(0x80),
  46187 	774:  uint8(0x80),
  46188 	775:  uint8(0x80),
  46189 	776:  uint8(0x80),
  46190 	777:  uint8(0x80),
  46191 	778:  uint8(0x80),
  46192 	779:  uint8(0x80),
  46193 	780:  uint8(0x80),
  46194 	781:  uint8(0x80),
  46195 	782:  uint8(0x80),
  46196 	783:  uint8(0x80),
  46197 	784:  uint8(0x80),
  46198 	785:  uint8(0x80),
  46199 	786:  uint8(0x80),
  46200 	787:  uint8(0x80),
  46201 	788:  uint8(0x80),
  46202 	789:  uint8(0x80),
  46203 	790:  uint8(0x80),
  46204 	791:  uint8(0x80),
  46205 	792:  uint8(0x80),
  46206 	793:  uint8(0x80),
  46207 	794:  uint8(0x80),
  46208 	795:  uint8(0x80),
  46209 	796:  uint8(0x80),
  46210 	797:  uint8(0x80),
  46211 	798:  uint8(0x80),
  46212 	799:  uint8(0x80),
  46213 	800:  uint8(0x80),
  46214 	801:  uint8(0x80),
  46215 	802:  uint8(0x80),
  46216 	803:  uint8(0x80),
  46217 	804:  uint8(0x80),
  46218 	805:  uint8(0x80),
  46219 	806:  uint8(0x80),
  46220 	807:  uint8(0x80),
  46221 	808:  uint8(0x80),
  46222 	809:  uint8(0x80),
  46223 	810:  uint8(0x80),
  46224 	811:  uint8(0x80),
  46225 	812:  uint8(0x80),
  46226 	813:  uint8(0x80),
  46227 	814:  uint8(0x80),
  46228 	815:  uint8(0x80),
  46229 	816:  uint8(0x80),
  46230 	817:  uint8(0x80),
  46231 	818:  uint8(0x80),
  46232 	819:  uint8(0x80),
  46233 	820:  uint8(0x80),
  46234 	821:  uint8(0x80),
  46235 	822:  uint8(0x80),
  46236 	823:  uint8(0x80),
  46237 	824:  uint8(0x80),
  46238 	825:  uint8(0x80),
  46239 	826:  uint8(0x80),
  46240 	827:  uint8(0x80),
  46241 	828:  uint8(0x80),
  46242 	829:  uint8(0x80),
  46243 	830:  uint8(0x80),
  46244 	831:  uint8(0x80),
  46245 	832:  uint8(0x80),
  46246 	833:  uint8(0x80),
  46247 	834:  uint8(0x80),
  46248 	835:  uint8(0x80),
  46249 	836:  uint8(0x80),
  46250 	837:  uint8(0x80),
  46251 	838:  uint8(0x80),
  46252 	839:  uint8(0x80),
  46253 	840:  uint8(0x80),
  46254 	841:  uint8(0x80),
  46255 	842:  uint8(0x80),
  46256 	843:  uint8(0x80),
  46257 	844:  uint8(0x80),
  46258 	845:  uint8(0x80),
  46259 	846:  uint8(0x80),
  46260 	847:  uint8(0x80),
  46261 	848:  uint8(0x80),
  46262 	849:  uint8(0x80),
  46263 	850:  uint8(0x80),
  46264 	851:  uint8(0x80),
  46265 	852:  uint8(0x80),
  46266 	853:  uint8(0x80),
  46267 	854:  uint8(0x80),
  46268 	855:  uint8(0x80),
  46269 	856:  uint8(0x80),
  46270 	857:  uint8(0x80),
  46271 	858:  uint8(0x80),
  46272 	859:  uint8(0x80),
  46273 	860:  uint8(0x80),
  46274 	861:  uint8(0x80),
  46275 	862:  uint8(0x80),
  46276 	863:  uint8(0x80),
  46277 	864:  uint8(0x80),
  46278 	865:  uint8(0x80),
  46279 	866:  uint8(0x80),
  46280 	867:  uint8(0x80),
  46281 	868:  uint8(0x80),
  46282 	869:  uint8(0x80),
  46283 	870:  uint8(0x80),
  46284 	871:  uint8(0x80),
  46285 	872:  uint8(0x80),
  46286 	873:  uint8(0x80),
  46287 	874:  uint8(0x80),
  46288 	875:  uint8(0x80),
  46289 	876:  uint8(0x80),
  46290 	877:  uint8(0x80),
  46291 	878:  uint8(0x80),
  46292 	879:  uint8(0x80),
  46293 	880:  uint8(0x80),
  46294 	881:  uint8(0x80),
  46295 	882:  uint8(0x80),
  46296 	883:  uint8(0x80),
  46297 	884:  uint8(0x80),
  46298 	885:  uint8(0x80),
  46299 	886:  uint8(0x80),
  46300 	887:  uint8(0x80),
  46301 	888:  uint8(0x80),
  46302 	889:  uint8(0x80),
  46303 	890:  uint8(0x80),
  46304 	891:  uint8(0x80),
  46305 	892:  uint8(0x80),
  46306 	893:  uint8(0x81),
  46307 	894:  uint8(0x82),
  46308 	895:  uint8(0x83),
  46309 	896:  uint8(0x84),
  46310 	897:  uint8(0x85),
  46311 	898:  uint8(0x86),
  46312 	899:  uint8(0x87),
  46313 	900:  uint8(0x88),
  46314 	901:  uint8(0x89),
  46315 	902:  uint8(0x8a),
  46316 	903:  uint8(0x8b),
  46317 	904:  uint8(0x8c),
  46318 	905:  uint8(0x8d),
  46319 	906:  uint8(0x8e),
  46320 	907:  uint8(0x8f),
  46321 	908:  uint8(0x90),
  46322 	909:  uint8(0x91),
  46323 	910:  uint8(0x92),
  46324 	911:  uint8(0x93),
  46325 	912:  uint8(0x94),
  46326 	913:  uint8(0x95),
  46327 	914:  uint8(0x96),
  46328 	915:  uint8(0x97),
  46329 	916:  uint8(0x98),
  46330 	917:  uint8(0x99),
  46331 	918:  uint8(0x9a),
  46332 	919:  uint8(0x9b),
  46333 	920:  uint8(0x9c),
  46334 	921:  uint8(0x9d),
  46335 	922:  uint8(0x9e),
  46336 	923:  uint8(0x9f),
  46337 	924:  uint8(0xa0),
  46338 	925:  uint8(0xa1),
  46339 	926:  uint8(0xa2),
  46340 	927:  uint8(0xa3),
  46341 	928:  uint8(0xa4),
  46342 	929:  uint8(0xa5),
  46343 	930:  uint8(0xa6),
  46344 	931:  uint8(0xa7),
  46345 	932:  uint8(0xa8),
  46346 	933:  uint8(0xa9),
  46347 	934:  uint8(0xaa),
  46348 	935:  uint8(0xab),
  46349 	936:  uint8(0xac),
  46350 	937:  uint8(0xad),
  46351 	938:  uint8(0xae),
  46352 	939:  uint8(0xaf),
  46353 	940:  uint8(0xb0),
  46354 	941:  uint8(0xb1),
  46355 	942:  uint8(0xb2),
  46356 	943:  uint8(0xb3),
  46357 	944:  uint8(0xb4),
  46358 	945:  uint8(0xb5),
  46359 	946:  uint8(0xb6),
  46360 	947:  uint8(0xb7),
  46361 	948:  uint8(0xb8),
  46362 	949:  uint8(0xb9),
  46363 	950:  uint8(0xba),
  46364 	951:  uint8(0xbb),
  46365 	952:  uint8(0xbc),
  46366 	953:  uint8(0xbd),
  46367 	954:  uint8(0xbe),
  46368 	955:  uint8(0xbf),
  46369 	956:  uint8(0xc0),
  46370 	957:  uint8(0xc1),
  46371 	958:  uint8(0xc2),
  46372 	959:  uint8(0xc3),
  46373 	960:  uint8(0xc4),
  46374 	961:  uint8(0xc5),
  46375 	962:  uint8(0xc6),
  46376 	963:  uint8(0xc7),
  46377 	964:  uint8(0xc8),
  46378 	965:  uint8(0xc9),
  46379 	966:  uint8(0xca),
  46380 	967:  uint8(0xcb),
  46381 	968:  uint8(0xcc),
  46382 	969:  uint8(0xcd),
  46383 	970:  uint8(0xce),
  46384 	971:  uint8(0xcf),
  46385 	972:  uint8(0xd0),
  46386 	973:  uint8(0xd1),
  46387 	974:  uint8(0xd2),
  46388 	975:  uint8(0xd3),
  46389 	976:  uint8(0xd4),
  46390 	977:  uint8(0xd5),
  46391 	978:  uint8(0xd6),
  46392 	979:  uint8(0xd7),
  46393 	980:  uint8(0xd8),
  46394 	981:  uint8(0xd9),
  46395 	982:  uint8(0xda),
  46396 	983:  uint8(0xdb),
  46397 	984:  uint8(0xdc),
  46398 	985:  uint8(0xdd),
  46399 	986:  uint8(0xde),
  46400 	987:  uint8(0xdf),
  46401 	988:  uint8(0xe0),
  46402 	989:  uint8(0xe1),
  46403 	990:  uint8(0xe2),
  46404 	991:  uint8(0xe3),
  46405 	992:  uint8(0xe4),
  46406 	993:  uint8(0xe5),
  46407 	994:  uint8(0xe6),
  46408 	995:  uint8(0xe7),
  46409 	996:  uint8(0xe8),
  46410 	997:  uint8(0xe9),
  46411 	998:  uint8(0xea),
  46412 	999:  uint8(0xeb),
  46413 	1000: uint8(0xec),
  46414 	1001: uint8(0xed),
  46415 	1002: uint8(0xee),
  46416 	1003: uint8(0xef),
  46417 	1004: uint8(0xf0),
  46418 	1005: uint8(0xf1),
  46419 	1006: uint8(0xf2),
  46420 	1007: uint8(0xf3),
  46421 	1008: uint8(0xf4),
  46422 	1009: uint8(0xf5),
  46423 	1010: uint8(0xf6),
  46424 	1011: uint8(0xf7),
  46425 	1012: uint8(0xf8),
  46426 	1013: uint8(0xf9),
  46427 	1014: uint8(0xfa),
  46428 	1015: uint8(0xfb),
  46429 	1016: uint8(0xfc),
  46430 	1017: uint8(0xfd),
  46431 	1018: uint8(0xfe),
  46432 	1019: uint8(0xff),
  46433 	1021: uint8(0x01),
  46434 	1022: uint8(0x02),
  46435 	1023: uint8(0x03),
  46436 	1024: uint8(0x04),
  46437 	1025: uint8(0x05),
  46438 	1026: uint8(0x06),
  46439 	1027: uint8(0x07),
  46440 	1028: uint8(0x08),
  46441 	1029: uint8(0x09),
  46442 	1030: uint8(0x0a),
  46443 	1031: uint8(0x0b),
  46444 	1032: uint8(0x0c),
  46445 	1033: uint8(0x0d),
  46446 	1034: uint8(0x0e),
  46447 	1035: uint8(0x0f),
  46448 	1036: uint8(0x10),
  46449 	1037: uint8(0x11),
  46450 	1038: uint8(0x12),
  46451 	1039: uint8(0x13),
  46452 	1040: uint8(0x14),
  46453 	1041: uint8(0x15),
  46454 	1042: uint8(0x16),
  46455 	1043: uint8(0x17),
  46456 	1044: uint8(0x18),
  46457 	1045: uint8(0x19),
  46458 	1046: uint8(0x1a),
  46459 	1047: uint8(0x1b),
  46460 	1048: uint8(0x1c),
  46461 	1049: uint8(0x1d),
  46462 	1050: uint8(0x1e),
  46463 	1051: uint8(0x1f),
  46464 	1052: uint8(0x20),
  46465 	1053: uint8(0x21),
  46466 	1054: uint8(0x22),
  46467 	1055: uint8(0x23),
  46468 	1056: uint8(0x24),
  46469 	1057: uint8(0x25),
  46470 	1058: uint8(0x26),
  46471 	1059: uint8(0x27),
  46472 	1060: uint8(0x28),
  46473 	1061: uint8(0x29),
  46474 	1062: uint8(0x2a),
  46475 	1063: uint8(0x2b),
  46476 	1064: uint8(0x2c),
  46477 	1065: uint8(0x2d),
  46478 	1066: uint8(0x2e),
  46479 	1067: uint8(0x2f),
  46480 	1068: uint8(0x30),
  46481 	1069: uint8(0x31),
  46482 	1070: uint8(0x32),
  46483 	1071: uint8(0x33),
  46484 	1072: uint8(0x34),
  46485 	1073: uint8(0x35),
  46486 	1074: uint8(0x36),
  46487 	1075: uint8(0x37),
  46488 	1076: uint8(0x38),
  46489 	1077: uint8(0x39),
  46490 	1078: uint8(0x3a),
  46491 	1079: uint8(0x3b),
  46492 	1080: uint8(0x3c),
  46493 	1081: uint8(0x3d),
  46494 	1082: uint8(0x3e),
  46495 	1083: uint8(0x3f),
  46496 	1084: uint8(0x40),
  46497 	1085: uint8(0x41),
  46498 	1086: uint8(0x42),
  46499 	1087: uint8(0x43),
  46500 	1088: uint8(0x44),
  46501 	1089: uint8(0x45),
  46502 	1090: uint8(0x46),
  46503 	1091: uint8(0x47),
  46504 	1092: uint8(0x48),
  46505 	1093: uint8(0x49),
  46506 	1094: uint8(0x4a),
  46507 	1095: uint8(0x4b),
  46508 	1096: uint8(0x4c),
  46509 	1097: uint8(0x4d),
  46510 	1098: uint8(0x4e),
  46511 	1099: uint8(0x4f),
  46512 	1100: uint8(0x50),
  46513 	1101: uint8(0x51),
  46514 	1102: uint8(0x52),
  46515 	1103: uint8(0x53),
  46516 	1104: uint8(0x54),
  46517 	1105: uint8(0x55),
  46518 	1106: uint8(0x56),
  46519 	1107: uint8(0x57),
  46520 	1108: uint8(0x58),
  46521 	1109: uint8(0x59),
  46522 	1110: uint8(0x5a),
  46523 	1111: uint8(0x5b),
  46524 	1112: uint8(0x5c),
  46525 	1113: uint8(0x5d),
  46526 	1114: uint8(0x5e),
  46527 	1115: uint8(0x5f),
  46528 	1116: uint8(0x60),
  46529 	1117: uint8(0x61),
  46530 	1118: uint8(0x62),
  46531 	1119: uint8(0x63),
  46532 	1120: uint8(0x64),
  46533 	1121: uint8(0x65),
  46534 	1122: uint8(0x66),
  46535 	1123: uint8(0x67),
  46536 	1124: uint8(0x68),
  46537 	1125: uint8(0x69),
  46538 	1126: uint8(0x6a),
  46539 	1127: uint8(0x6b),
  46540 	1128: uint8(0x6c),
  46541 	1129: uint8(0x6d),
  46542 	1130: uint8(0x6e),
  46543 	1131: uint8(0x6f),
  46544 	1132: uint8(0x70),
  46545 	1133: uint8(0x71),
  46546 	1134: uint8(0x72),
  46547 	1135: uint8(0x73),
  46548 	1136: uint8(0x74),
  46549 	1137: uint8(0x75),
  46550 	1138: uint8(0x76),
  46551 	1139: uint8(0x77),
  46552 	1140: uint8(0x78),
  46553 	1141: uint8(0x79),
  46554 	1142: uint8(0x7a),
  46555 	1143: uint8(0x7b),
  46556 	1144: uint8(0x7c),
  46557 	1145: uint8(0x7d),
  46558 	1146: uint8(0x7e),
  46559 	1147: uint8(0x7f),
  46560 	1148: uint8(0x7f),
  46561 	1149: uint8(0x7f),
  46562 	1150: uint8(0x7f),
  46563 	1151: uint8(0x7f),
  46564 	1152: uint8(0x7f),
  46565 	1153: uint8(0x7f),
  46566 	1154: uint8(0x7f),
  46567 	1155: uint8(0x7f),
  46568 	1156: uint8(0x7f),
  46569 	1157: uint8(0x7f),
  46570 	1158: uint8(0x7f),
  46571 	1159: uint8(0x7f),
  46572 	1160: uint8(0x7f),
  46573 	1161: uint8(0x7f),
  46574 	1162: uint8(0x7f),
  46575 	1163: uint8(0x7f),
  46576 	1164: uint8(0x7f),
  46577 	1165: uint8(0x7f),
  46578 	1166: uint8(0x7f),
  46579 	1167: uint8(0x7f),
  46580 	1168: uint8(0x7f),
  46581 	1169: uint8(0x7f),
  46582 	1170: uint8(0x7f),
  46583 	1171: uint8(0x7f),
  46584 	1172: uint8(0x7f),
  46585 	1173: uint8(0x7f),
  46586 	1174: uint8(0x7f),
  46587 	1175: uint8(0x7f),
  46588 	1176: uint8(0x7f),
  46589 	1177: uint8(0x7f),
  46590 	1178: uint8(0x7f),
  46591 	1179: uint8(0x7f),
  46592 	1180: uint8(0x7f),
  46593 	1181: uint8(0x7f),
  46594 	1182: uint8(0x7f),
  46595 	1183: uint8(0x7f),
  46596 	1184: uint8(0x7f),
  46597 	1185: uint8(0x7f),
  46598 	1186: uint8(0x7f),
  46599 	1187: uint8(0x7f),
  46600 	1188: uint8(0x7f),
  46601 	1189: uint8(0x7f),
  46602 	1190: uint8(0x7f),
  46603 	1191: uint8(0x7f),
  46604 	1192: uint8(0x7f),
  46605 	1193: uint8(0x7f),
  46606 	1194: uint8(0x7f),
  46607 	1195: uint8(0x7f),
  46608 	1196: uint8(0x7f),
  46609 	1197: uint8(0x7f),
  46610 	1198: uint8(0x7f),
  46611 	1199: uint8(0x7f),
  46612 	1200: uint8(0x7f),
  46613 	1201: uint8(0x7f),
  46614 	1202: uint8(0x7f),
  46615 	1203: uint8(0x7f),
  46616 	1204: uint8(0x7f),
  46617 	1205: uint8(0x7f),
  46618 	1206: uint8(0x7f),
  46619 	1207: uint8(0x7f),
  46620 	1208: uint8(0x7f),
  46621 	1209: uint8(0x7f),
  46622 	1210: uint8(0x7f),
  46623 	1211: uint8(0x7f),
  46624 	1212: uint8(0x7f),
  46625 	1213: uint8(0x7f),
  46626 	1214: uint8(0x7f),
  46627 	1215: uint8(0x7f),
  46628 	1216: uint8(0x7f),
  46629 	1217: uint8(0x7f),
  46630 	1218: uint8(0x7f),
  46631 	1219: uint8(0x7f),
  46632 	1220: uint8(0x7f),
  46633 	1221: uint8(0x7f),
  46634 	1222: uint8(0x7f),
  46635 	1223: uint8(0x7f),
  46636 	1224: uint8(0x7f),
  46637 	1225: uint8(0x7f),
  46638 	1226: uint8(0x7f),
  46639 	1227: uint8(0x7f),
  46640 	1228: uint8(0x7f),
  46641 	1229: uint8(0x7f),
  46642 	1230: uint8(0x7f),
  46643 	1231: uint8(0x7f),
  46644 	1232: uint8(0x7f),
  46645 	1233: uint8(0x7f),
  46646 	1234: uint8(0x7f),
  46647 	1235: uint8(0x7f),
  46648 	1236: uint8(0x7f),
  46649 	1237: uint8(0x7f),
  46650 	1238: uint8(0x7f),
  46651 	1239: uint8(0x7f),
  46652 	1240: uint8(0x7f),
  46653 	1241: uint8(0x7f),
  46654 	1242: uint8(0x7f),
  46655 	1243: uint8(0x7f),
  46656 	1244: uint8(0x7f),
  46657 	1245: uint8(0x7f),
  46658 	1246: uint8(0x7f),
  46659 	1247: uint8(0x7f),
  46660 	1248: uint8(0x7f),
  46661 	1249: uint8(0x7f),
  46662 	1250: uint8(0x7f),
  46663 	1251: uint8(0x7f),
  46664 	1252: uint8(0x7f),
  46665 	1253: uint8(0x7f),
  46666 	1254: uint8(0x7f),
  46667 	1255: uint8(0x7f),
  46668 	1256: uint8(0x7f),
  46669 	1257: uint8(0x7f),
  46670 	1258: uint8(0x7f),
  46671 	1259: uint8(0x7f),
  46672 	1260: uint8(0x7f),
  46673 	1261: uint8(0x7f),
  46674 	1262: uint8(0x7f),
  46675 	1263: uint8(0x7f),
  46676 	1264: uint8(0x7f),
  46677 	1265: uint8(0x7f),
  46678 	1266: uint8(0x7f),
  46679 	1267: uint8(0x7f),
  46680 	1268: uint8(0x7f),
  46681 	1269: uint8(0x7f),
  46682 	1270: uint8(0x7f),
  46683 	1271: uint8(0x7f),
  46684 	1272: uint8(0x7f),
  46685 	1273: uint8(0x7f),
  46686 	1274: uint8(0x7f),
  46687 	1275: uint8(0x7f),
  46688 	1276: uint8(0x7f),
  46689 	1277: uint8(0x7f),
  46690 	1278: uint8(0x7f),
  46691 	1279: uint8(0x7f),
  46692 	1280: uint8(0x7f),
  46693 	1281: uint8(0x7f),
  46694 	1282: uint8(0x7f),
  46695 	1283: uint8(0x7f),
  46696 	1284: uint8(0x7f),
  46697 	1285: uint8(0x7f),
  46698 	1286: uint8(0x7f),
  46699 	1287: uint8(0x7f),
  46700 	1288: uint8(0x7f),
  46701 	1289: uint8(0x7f),
  46702 	1290: uint8(0x7f),
  46703 	1291: uint8(0x7f),
  46704 	1292: uint8(0x7f),
  46705 	1293: uint8(0x7f),
  46706 	1294: uint8(0x7f),
  46707 	1295: uint8(0x7f),
  46708 	1296: uint8(0x7f),
  46709 	1297: uint8(0x7f),
  46710 	1298: uint8(0x7f),
  46711 	1299: uint8(0x7f),
  46712 	1300: uint8(0x7f),
  46713 	1301: uint8(0x7f),
  46714 	1302: uint8(0x7f),
  46715 	1303: uint8(0x7f),
  46716 	1304: uint8(0x7f),
  46717 	1305: uint8(0x7f),
  46718 	1306: uint8(0x7f),
  46719 	1307: uint8(0x7f),
  46720 	1308: uint8(0x7f),
  46721 	1309: uint8(0x7f),
  46722 	1310: uint8(0x7f),
  46723 	1311: uint8(0x7f),
  46724 	1312: uint8(0x7f),
  46725 	1313: uint8(0x7f),
  46726 	1314: uint8(0x7f),
  46727 	1315: uint8(0x7f),
  46728 	1316: uint8(0x7f),
  46729 	1317: uint8(0x7f),
  46730 	1318: uint8(0x7f),
  46731 	1319: uint8(0x7f),
  46732 	1320: uint8(0x7f),
  46733 	1321: uint8(0x7f),
  46734 	1322: uint8(0x7f),
  46735 	1323: uint8(0x7f),
  46736 	1324: uint8(0x7f),
  46737 	1325: uint8(0x7f),
  46738 	1326: uint8(0x7f),
  46739 	1327: uint8(0x7f),
  46740 	1328: uint8(0x7f),
  46741 	1329: uint8(0x7f),
  46742 	1330: uint8(0x7f),
  46743 	1331: uint8(0x7f),
  46744 	1332: uint8(0x7f),
  46745 	1333: uint8(0x7f),
  46746 	1334: uint8(0x7f),
  46747 	1335: uint8(0x7f),
  46748 	1336: uint8(0x7f),
  46749 	1337: uint8(0x7f),
  46750 	1338: uint8(0x7f),
  46751 	1339: uint8(0x7f),
  46752 	1340: uint8(0x7f),
  46753 	1341: uint8(0x7f),
  46754 	1342: uint8(0x7f),
  46755 	1343: uint8(0x7f),
  46756 	1344: uint8(0x7f),
  46757 	1345: uint8(0x7f),
  46758 	1346: uint8(0x7f),
  46759 	1347: uint8(0x7f),
  46760 	1348: uint8(0x7f),
  46761 	1349: uint8(0x7f),
  46762 	1350: uint8(0x7f),
  46763 	1351: uint8(0x7f),
  46764 	1352: uint8(0x7f),
  46765 	1353: uint8(0x7f),
  46766 	1354: uint8(0x7f),
  46767 	1355: uint8(0x7f),
  46768 	1356: uint8(0x7f),
  46769 	1357: uint8(0x7f),
  46770 	1358: uint8(0x7f),
  46771 	1359: uint8(0x7f),
  46772 	1360: uint8(0x7f),
  46773 	1361: uint8(0x7f),
  46774 	1362: uint8(0x7f),
  46775 	1363: uint8(0x7f),
  46776 	1364: uint8(0x7f),
  46777 	1365: uint8(0x7f),
  46778 	1366: uint8(0x7f),
  46779 	1367: uint8(0x7f),
  46780 	1368: uint8(0x7f),
  46781 	1369: uint8(0x7f),
  46782 	1370: uint8(0x7f),
  46783 	1371: uint8(0x7f),
  46784 	1372: uint8(0x7f),
  46785 	1373: uint8(0x7f),
  46786 	1374: uint8(0x7f),
  46787 	1375: uint8(0x7f),
  46788 	1376: uint8(0x7f),
  46789 	1377: uint8(0x7f),
  46790 	1378: uint8(0x7f),
  46791 	1379: uint8(0x7f),
  46792 	1380: uint8(0x7f),
  46793 	1381: uint8(0x7f),
  46794 	1382: uint8(0x7f),
  46795 	1383: uint8(0x7f),
  46796 	1384: uint8(0x7f),
  46797 	1385: uint8(0x7f),
  46798 	1386: uint8(0x7f),
  46799 	1387: uint8(0x7f),
  46800 	1388: uint8(0x7f),
  46801 	1389: uint8(0x7f),
  46802 	1390: uint8(0x7f),
  46803 	1391: uint8(0x7f),
  46804 	1392: uint8(0x7f),
  46805 	1393: uint8(0x7f),
  46806 	1394: uint8(0x7f),
  46807 	1395: uint8(0x7f),
  46808 	1396: uint8(0x7f),
  46809 	1397: uint8(0x7f),
  46810 	1398: uint8(0x7f),
  46811 	1399: uint8(0x7f),
  46812 	1400: uint8(0x7f),
  46813 	1401: uint8(0x7f),
  46814 	1402: uint8(0x7f),
  46815 	1403: uint8(0x7f),
  46816 	1404: uint8(0x7f),
  46817 	1405: uint8(0x7f),
  46818 	1406: uint8(0x7f),
  46819 	1407: uint8(0x7f),
  46820 	1408: uint8(0x7f),
  46821 	1409: uint8(0x7f),
  46822 	1410: uint8(0x7f),
  46823 	1411: uint8(0x7f),
  46824 	1412: uint8(0x7f),
  46825 	1413: uint8(0x7f),
  46826 	1414: uint8(0x7f),
  46827 	1415: uint8(0x7f),
  46828 	1416: uint8(0x7f),
  46829 	1417: uint8(0x7f),
  46830 	1418: uint8(0x7f),
  46831 	1419: uint8(0x7f),
  46832 	1420: uint8(0x7f),
  46833 	1421: uint8(0x7f),
  46834 	1422: uint8(0x7f),
  46835 	1423: uint8(0x7f),
  46836 	1424: uint8(0x7f),
  46837 	1425: uint8(0x7f),
  46838 	1426: uint8(0x7f),
  46839 	1427: uint8(0x7f),
  46840 	1428: uint8(0x7f),
  46841 	1429: uint8(0x7f),
  46842 	1430: uint8(0x7f),
  46843 	1431: uint8(0x7f),
  46844 	1432: uint8(0x7f),
  46845 	1433: uint8(0x7f),
  46846 	1434: uint8(0x7f),
  46847 	1435: uint8(0x7f),
  46848 	1436: uint8(0x7f),
  46849 	1437: uint8(0x7f),
  46850 	1438: uint8(0x7f),
  46851 	1439: uint8(0x7f),
  46852 	1440: uint8(0x7f),
  46853 	1441: uint8(0x7f),
  46854 	1442: uint8(0x7f),
  46855 	1443: uint8(0x7f),
  46856 	1444: uint8(0x7f),
  46857 	1445: uint8(0x7f),
  46858 	1446: uint8(0x7f),
  46859 	1447: uint8(0x7f),
  46860 	1448: uint8(0x7f),
  46861 	1449: uint8(0x7f),
  46862 	1450: uint8(0x7f),
  46863 	1451: uint8(0x7f),
  46864 	1452: uint8(0x7f),
  46865 	1453: uint8(0x7f),
  46866 	1454: uint8(0x7f),
  46867 	1455: uint8(0x7f),
  46868 	1456: uint8(0x7f),
  46869 	1457: uint8(0x7f),
  46870 	1458: uint8(0x7f),
  46871 	1459: uint8(0x7f),
  46872 	1460: uint8(0x7f),
  46873 	1461: uint8(0x7f),
  46874 	1462: uint8(0x7f),
  46875 	1463: uint8(0x7f),
  46876 	1464: uint8(0x7f),
  46877 	1465: uint8(0x7f),
  46878 	1466: uint8(0x7f),
  46879 	1467: uint8(0x7f),
  46880 	1468: uint8(0x7f),
  46881 	1469: uint8(0x7f),
  46882 	1470: uint8(0x7f),
  46883 	1471: uint8(0x7f),
  46884 	1472: uint8(0x7f),
  46885 	1473: uint8(0x7f),
  46886 	1474: uint8(0x7f),
  46887 	1475: uint8(0x7f),
  46888 	1476: uint8(0x7f),
  46889 	1477: uint8(0x7f),
  46890 	1478: uint8(0x7f),
  46891 	1479: uint8(0x7f),
  46892 	1480: uint8(0x7f),
  46893 	1481: uint8(0x7f),
  46894 	1482: uint8(0x7f),
  46895 	1483: uint8(0x7f),
  46896 	1484: uint8(0x7f),
  46897 	1485: uint8(0x7f),
  46898 	1486: uint8(0x7f),
  46899 	1487: uint8(0x7f),
  46900 	1488: uint8(0x7f),
  46901 	1489: uint8(0x7f),
  46902 	1490: uint8(0x7f),
  46903 	1491: uint8(0x7f),
  46904 	1492: uint8(0x7f),
  46905 	1493: uint8(0x7f),
  46906 	1494: uint8(0x7f),
  46907 	1495: uint8(0x7f),
  46908 	1496: uint8(0x7f),
  46909 	1497: uint8(0x7f),
  46910 	1498: uint8(0x7f),
  46911 	1499: uint8(0x7f),
  46912 	1500: uint8(0x7f),
  46913 	1501: uint8(0x7f),
  46914 	1502: uint8(0x7f),
  46915 	1503: uint8(0x7f),
  46916 	1504: uint8(0x7f),
  46917 	1505: uint8(0x7f),
  46918 	1506: uint8(0x7f),
  46919 	1507: uint8(0x7f),
  46920 	1508: uint8(0x7f),
  46921 	1509: uint8(0x7f),
  46922 	1510: uint8(0x7f),
  46923 	1511: uint8(0x7f),
  46924 	1512: uint8(0x7f),
  46925 	1513: uint8(0x7f),
  46926 	1514: uint8(0x7f),
  46927 	1515: uint8(0x7f),
  46928 	1516: uint8(0x7f),
  46929 	1517: uint8(0x7f),
  46930 	1518: uint8(0x7f),
  46931 	1519: uint8(0x7f),
  46932 	1520: uint8(0x7f),
  46933 	1521: uint8(0x7f),
  46934 	1522: uint8(0x7f),
  46935 	1523: uint8(0x7f),
  46936 	1524: uint8(0x7f),
  46937 	1525: uint8(0x7f),
  46938 	1526: uint8(0x7f),
  46939 	1527: uint8(0x7f),
  46940 	1528: uint8(0x7f),
  46941 	1529: uint8(0x7f),
  46942 	1530: uint8(0x7f),
  46943 	1531: uint8(0x7f),
  46944 	1532: uint8(0x7f),
  46945 	1533: uint8(0x7f),
  46946 	1534: uint8(0x7f),
  46947 	1535: uint8(0x7f),
  46948 	1536: uint8(0x7f),
  46949 	1537: uint8(0x7f),
  46950 	1538: uint8(0x7f),
  46951 	1539: uint8(0x7f),
  46952 	1540: uint8(0x7f),
  46953 	1541: uint8(0x7f),
  46954 	1542: uint8(0x7f),
  46955 	1543: uint8(0x7f),
  46956 	1544: uint8(0x7f),
  46957 	1545: uint8(0x7f),
  46958 	1546: uint8(0x7f),
  46959 	1547: uint8(0x7f),
  46960 	1548: uint8(0x7f),
  46961 	1549: uint8(0x7f),
  46962 	1550: uint8(0x7f),
  46963 	1551: uint8(0x7f),
  46964 	1552: uint8(0x7f),
  46965 	1553: uint8(0x7f),
  46966 	1554: uint8(0x7f),
  46967 	1555: uint8(0x7f),
  46968 	1556: uint8(0x7f),
  46969 	1557: uint8(0x7f),
  46970 	1558: uint8(0x7f),
  46971 	1559: uint8(0x7f),
  46972 	1560: uint8(0x7f),
  46973 	1561: uint8(0x7f),
  46974 	1562: uint8(0x7f),
  46975 	1563: uint8(0x7f),
  46976 	1564: uint8(0x7f),
  46977 	1565: uint8(0x7f),
  46978 	1566: uint8(0x7f),
  46979 	1567: uint8(0x7f),
  46980 	1568: uint8(0x7f),
  46981 	1569: uint8(0x7f),
  46982 	1570: uint8(0x7f),
  46983 	1571: uint8(0x7f),
  46984 	1572: uint8(0x7f),
  46985 	1573: uint8(0x7f),
  46986 	1574: uint8(0x7f),
  46987 	1575: uint8(0x7f),
  46988 	1576: uint8(0x7f),
  46989 	1577: uint8(0x7f),
  46990 	1578: uint8(0x7f),
  46991 	1579: uint8(0x7f),
  46992 	1580: uint8(0x7f),
  46993 	1581: uint8(0x7f),
  46994 	1582: uint8(0x7f),
  46995 	1583: uint8(0x7f),
  46996 	1584: uint8(0x7f),
  46997 	1585: uint8(0x7f),
  46998 	1586: uint8(0x7f),
  46999 	1587: uint8(0x7f),
  47000 	1588: uint8(0x7f),
  47001 	1589: uint8(0x7f),
  47002 	1590: uint8(0x7f),
  47003 	1591: uint8(0x7f),
  47004 	1592: uint8(0x7f),
  47005 	1593: uint8(0x7f),
  47006 	1594: uint8(0x7f),
  47007 	1595: uint8(0x7f),
  47008 	1596: uint8(0x7f),
  47009 	1597: uint8(0x7f),
  47010 	1598: uint8(0x7f),
  47011 	1599: uint8(0x7f),
  47012 	1600: uint8(0x7f),
  47013 	1601: uint8(0x7f),
  47014 	1602: uint8(0x7f),
  47015 	1603: uint8(0x7f),
  47016 	1604: uint8(0x7f),
  47017 	1605: uint8(0x7f),
  47018 	1606: uint8(0x7f),
  47019 	1607: uint8(0x7f),
  47020 	1608: uint8(0x7f),
  47021 	1609: uint8(0x7f),
  47022 	1610: uint8(0x7f),
  47023 	1611: uint8(0x7f),
  47024 	1612: uint8(0x7f),
  47025 	1613: uint8(0x7f),
  47026 	1614: uint8(0x7f),
  47027 	1615: uint8(0x7f),
  47028 	1616: uint8(0x7f),
  47029 	1617: uint8(0x7f),
  47030 	1618: uint8(0x7f),
  47031 	1619: uint8(0x7f),
  47032 	1620: uint8(0x7f),
  47033 	1621: uint8(0x7f),
  47034 	1622: uint8(0x7f),
  47035 	1623: uint8(0x7f),
  47036 	1624: uint8(0x7f),
  47037 	1625: uint8(0x7f),
  47038 	1626: uint8(0x7f),
  47039 	1627: uint8(0x7f),
  47040 	1628: uint8(0x7f),
  47041 	1629: uint8(0x7f),
  47042 	1630: uint8(0x7f),
  47043 	1631: uint8(0x7f),
  47044 	1632: uint8(0x7f),
  47045 	1633: uint8(0x7f),
  47046 	1634: uint8(0x7f),
  47047 	1635: uint8(0x7f),
  47048 	1636: uint8(0x7f),
  47049 	1637: uint8(0x7f),
  47050 	1638: uint8(0x7f),
  47051 	1639: uint8(0x7f),
  47052 	1640: uint8(0x7f),
  47053 	1641: uint8(0x7f),
  47054 	1642: uint8(0x7f),
  47055 	1643: uint8(0x7f),
  47056 	1644: uint8(0x7f),
  47057 	1645: uint8(0x7f),
  47058 	1646: uint8(0x7f),
  47059 	1647: uint8(0x7f),
  47060 	1648: uint8(0x7f),
  47061 	1649: uint8(0x7f),
  47062 	1650: uint8(0x7f),
  47063 	1651: uint8(0x7f),
  47064 	1652: uint8(0x7f),
  47065 	1653: uint8(0x7f),
  47066 	1654: uint8(0x7f),
  47067 	1655: uint8(0x7f),
  47068 	1656: uint8(0x7f),
  47069 	1657: uint8(0x7f),
  47070 	1658: uint8(0x7f),
  47071 	1659: uint8(0x7f),
  47072 	1660: uint8(0x7f),
  47073 	1661: uint8(0x7f),
  47074 	1662: uint8(0x7f),
  47075 	1663: uint8(0x7f),
  47076 	1664: uint8(0x7f),
  47077 	1665: uint8(0x7f),
  47078 	1666: uint8(0x7f),
  47079 	1667: uint8(0x7f),
  47080 	1668: uint8(0x7f),
  47081 	1669: uint8(0x7f),
  47082 	1670: uint8(0x7f),
  47083 	1671: uint8(0x7f),
  47084 	1672: uint8(0x7f),
  47085 	1673: uint8(0x7f),
  47086 	1674: uint8(0x7f),
  47087 	1675: uint8(0x7f),
  47088 	1676: uint8(0x7f),
  47089 	1677: uint8(0x7f),
  47090 	1678: uint8(0x7f),
  47091 	1679: uint8(0x7f),
  47092 	1680: uint8(0x7f),
  47093 	1681: uint8(0x7f),
  47094 	1682: uint8(0x7f),
  47095 	1683: uint8(0x7f),
  47096 	1684: uint8(0x7f),
  47097 	1685: uint8(0x7f),
  47098 	1686: uint8(0x7f),
  47099 	1687: uint8(0x7f),
  47100 	1688: uint8(0x7f),
  47101 	1689: uint8(0x7f),
  47102 	1690: uint8(0x7f),
  47103 	1691: uint8(0x7f),
  47104 	1692: uint8(0x7f),
  47105 	1693: uint8(0x7f),
  47106 	1694: uint8(0x7f),
  47107 	1695: uint8(0x7f),
  47108 	1696: uint8(0x7f),
  47109 	1697: uint8(0x7f),
  47110 	1698: uint8(0x7f),
  47111 	1699: uint8(0x7f),
  47112 	1700: uint8(0x7f),
  47113 	1701: uint8(0x7f),
  47114 	1702: uint8(0x7f),
  47115 	1703: uint8(0x7f),
  47116 	1704: uint8(0x7f),
  47117 	1705: uint8(0x7f),
  47118 	1706: uint8(0x7f),
  47119 	1707: uint8(0x7f),
  47120 	1708: uint8(0x7f),
  47121 	1709: uint8(0x7f),
  47122 	1710: uint8(0x7f),
  47123 	1711: uint8(0x7f),
  47124 	1712: uint8(0x7f),
  47125 	1713: uint8(0x7f),
  47126 	1714: uint8(0x7f),
  47127 	1715: uint8(0x7f),
  47128 	1716: uint8(0x7f),
  47129 	1717: uint8(0x7f),
  47130 	1718: uint8(0x7f),
  47131 	1719: uint8(0x7f),
  47132 	1720: uint8(0x7f),
  47133 	1721: uint8(0x7f),
  47134 	1722: uint8(0x7f),
  47135 	1723: uint8(0x7f),
  47136 	1724: uint8(0x7f),
  47137 	1725: uint8(0x7f),
  47138 	1726: uint8(0x7f),
  47139 	1727: uint8(0x7f),
  47140 	1728: uint8(0x7f),
  47141 	1729: uint8(0x7f),
  47142 	1730: uint8(0x7f),
  47143 	1731: uint8(0x7f),
  47144 	1732: uint8(0x7f),
  47145 	1733: uint8(0x7f),
  47146 	1734: uint8(0x7f),
  47147 	1735: uint8(0x7f),
  47148 	1736: uint8(0x7f),
  47149 	1737: uint8(0x7f),
  47150 	1738: uint8(0x7f),
  47151 	1739: uint8(0x7f),
  47152 	1740: uint8(0x7f),
  47153 	1741: uint8(0x7f),
  47154 	1742: uint8(0x7f),
  47155 	1743: uint8(0x7f),
  47156 	1744: uint8(0x7f),
  47157 	1745: uint8(0x7f),
  47158 	1746: uint8(0x7f),
  47159 	1747: uint8(0x7f),
  47160 	1748: uint8(0x7f),
  47161 	1749: uint8(0x7f),
  47162 	1750: uint8(0x7f),
  47163 	1751: uint8(0x7f),
  47164 	1752: uint8(0x7f),
  47165 	1753: uint8(0x7f),
  47166 	1754: uint8(0x7f),
  47167 	1755: uint8(0x7f),
  47168 	1756: uint8(0x7f),
  47169 	1757: uint8(0x7f),
  47170 	1758: uint8(0x7f),
  47171 	1759: uint8(0x7f),
  47172 	1760: uint8(0x7f),
  47173 	1761: uint8(0x7f),
  47174 	1762: uint8(0x7f),
  47175 	1763: uint8(0x7f),
  47176 	1764: uint8(0x7f),
  47177 	1765: uint8(0x7f),
  47178 	1766: uint8(0x7f),
  47179 	1767: uint8(0x7f),
  47180 	1768: uint8(0x7f),
  47181 	1769: uint8(0x7f),
  47182 	1770: uint8(0x7f),
  47183 	1771: uint8(0x7f),
  47184 	1772: uint8(0x7f),
  47185 	1773: uint8(0x7f),
  47186 	1774: uint8(0x7f),
  47187 	1775: uint8(0x7f),
  47188 	1776: uint8(0x7f),
  47189 	1777: uint8(0x7f),
  47190 	1778: uint8(0x7f),
  47191 	1779: uint8(0x7f),
  47192 	1780: uint8(0x7f),
  47193 	1781: uint8(0x7f),
  47194 	1782: uint8(0x7f),
  47195 	1783: uint8(0x7f),
  47196 	1784: uint8(0x7f),
  47197 	1785: uint8(0x7f),
  47198 	1786: uint8(0x7f),
  47199 	1787: uint8(0x7f),
  47200 	1788: uint8(0x7f),
  47201 	1789: uint8(0x7f),
  47202 	1790: uint8(0x7f),
  47203 	1791: uint8(0x7f),
  47204 	1792: uint8(0x7f),
  47205 	1793: uint8(0x7f),
  47206 	1794: uint8(0x7f),
  47207 	1795: uint8(0x7f),
  47208 	1796: uint8(0x7f),
  47209 	1797: uint8(0x7f),
  47210 	1798: uint8(0x7f),
  47211 	1799: uint8(0x7f),
  47212 	1800: uint8(0x7f),
  47213 	1801: uint8(0x7f),
  47214 	1802: uint8(0x7f),
  47215 	1803: uint8(0x7f),
  47216 	1804: uint8(0x7f),
  47217 	1805: uint8(0x7f),
  47218 	1806: uint8(0x7f),
  47219 	1807: uint8(0x7f),
  47220 	1808: uint8(0x7f),
  47221 	1809: uint8(0x7f),
  47222 	1810: uint8(0x7f),
  47223 	1811: uint8(0x7f),
  47224 	1812: uint8(0x7f),
  47225 	1813: uint8(0x7f),
  47226 	1814: uint8(0x7f),
  47227 	1815: uint8(0x7f),
  47228 	1816: uint8(0x7f),
  47229 	1817: uint8(0x7f),
  47230 	1818: uint8(0x7f),
  47231 	1819: uint8(0x7f),
  47232 	1820: uint8(0x7f),
  47233 	1821: uint8(0x7f),
  47234 	1822: uint8(0x7f),
  47235 	1823: uint8(0x7f),
  47236 	1824: uint8(0x7f),
  47237 	1825: uint8(0x7f),
  47238 	1826: uint8(0x7f),
  47239 	1827: uint8(0x7f),
  47240 	1828: uint8(0x7f),
  47241 	1829: uint8(0x7f),
  47242 	1830: uint8(0x7f),
  47243 	1831: uint8(0x7f),
  47244 	1832: uint8(0x7f),
  47245 	1833: uint8(0x7f),
  47246 	1834: uint8(0x7f),
  47247 	1835: uint8(0x7f),
  47248 	1836: uint8(0x7f),
  47249 	1837: uint8(0x7f),
  47250 	1838: uint8(0x7f),
  47251 	1839: uint8(0x7f),
  47252 	1840: uint8(0x7f),
  47253 	1841: uint8(0x7f),
  47254 	1842: uint8(0x7f),
  47255 	1843: uint8(0x7f),
  47256 	1844: uint8(0x7f),
  47257 	1845: uint8(0x7f),
  47258 	1846: uint8(0x7f),
  47259 	1847: uint8(0x7f),
  47260 	1848: uint8(0x7f),
  47261 	1849: uint8(0x7f),
  47262 	1850: uint8(0x7f),
  47263 	1851: uint8(0x7f),
  47264 	1852: uint8(0x7f),
  47265 	1853: uint8(0x7f),
  47266 	1854: uint8(0x7f),
  47267 	1855: uint8(0x7f),
  47268 	1856: uint8(0x7f),
  47269 	1857: uint8(0x7f),
  47270 	1858: uint8(0x7f),
  47271 	1859: uint8(0x7f),
  47272 	1860: uint8(0x7f),
  47273 	1861: uint8(0x7f),
  47274 	1862: uint8(0x7f),
  47275 	1863: uint8(0x7f),
  47276 	1864: uint8(0x7f),
  47277 	1865: uint8(0x7f),
  47278 	1866: uint8(0x7f),
  47279 	1867: uint8(0x7f),
  47280 	1868: uint8(0x7f),
  47281 	1869: uint8(0x7f),
  47282 	1870: uint8(0x7f),
  47283 	1871: uint8(0x7f),
  47284 	1872: uint8(0x7f),
  47285 	1873: uint8(0x7f),
  47286 	1874: uint8(0x7f),
  47287 	1875: uint8(0x7f),
  47288 	1876: uint8(0x7f),
  47289 	1877: uint8(0x7f),
  47290 	1878: uint8(0x7f),
  47291 	1879: uint8(0x7f),
  47292 	1880: uint8(0x7f),
  47293 	1881: uint8(0x7f),
  47294 	1882: uint8(0x7f),
  47295 	1883: uint8(0x7f),
  47296 	1884: uint8(0x7f),
  47297 	1885: uint8(0x7f),
  47298 	1886: uint8(0x7f),
  47299 	1887: uint8(0x7f),
  47300 	1888: uint8(0x7f),
  47301 	1889: uint8(0x7f),
  47302 	1890: uint8(0x7f),
  47303 	1891: uint8(0x7f),
  47304 	1892: uint8(0x7f),
  47305 	1893: uint8(0x7f),
  47306 	1894: uint8(0x7f),
  47307 	1895: uint8(0x7f),
  47308 	1896: uint8(0x7f),
  47309 	1897: uint8(0x7f),
  47310 	1898: uint8(0x7f),
  47311 	1899: uint8(0x7f),
  47312 	1900: uint8(0x7f),
  47313 	1901: uint8(0x7f),
  47314 	1902: uint8(0x7f),
  47315 	1903: uint8(0x7f),
  47316 	1904: uint8(0x7f),
  47317 	1905: uint8(0x7f),
  47318 	1906: uint8(0x7f),
  47319 	1907: uint8(0x7f),
  47320 	1908: uint8(0x7f),
  47321 	1909: uint8(0x7f),
  47322 	1910: uint8(0x7f),
  47323 	1911: uint8(0x7f),
  47324 	1912: uint8(0x7f),
  47325 	1913: uint8(0x7f),
  47326 	1914: uint8(0x7f),
  47327 	1915: uint8(0x7f),
  47328 	1916: uint8(0x7f),
  47329 	1917: uint8(0x7f),
  47330 	1918: uint8(0x7f),
  47331 	1919: uint8(0x7f),
  47332 	1920: uint8(0x7f),
  47333 	1921: uint8(0x7f),
  47334 	1922: uint8(0x7f),
  47335 	1923: uint8(0x7f),
  47336 	1924: uint8(0x7f),
  47337 	1925: uint8(0x7f),
  47338 	1926: uint8(0x7f),
  47339 	1927: uint8(0x7f),
  47340 	1928: uint8(0x7f),
  47341 	1929: uint8(0x7f),
  47342 	1930: uint8(0x7f),
  47343 	1931: uint8(0x7f),
  47344 	1932: uint8(0x7f),
  47345 	1933: uint8(0x7f),
  47346 	1934: uint8(0x7f),
  47347 	1935: uint8(0x7f),
  47348 	1936: uint8(0x7f),
  47349 	1937: uint8(0x7f),
  47350 	1938: uint8(0x7f),
  47351 	1939: uint8(0x7f),
  47352 	1940: uint8(0x7f),
  47353 	1941: uint8(0x7f),
  47354 	1942: uint8(0x7f),
  47355 	1943: uint8(0x7f),
  47356 	1944: uint8(0x7f),
  47357 	1945: uint8(0x7f),
  47358 	1946: uint8(0x7f),
  47359 	1947: uint8(0x7f),
  47360 	1948: uint8(0x7f),
  47361 	1949: uint8(0x7f),
  47362 	1950: uint8(0x7f),
  47363 	1951: uint8(0x7f),
  47364 	1952: uint8(0x7f),
  47365 	1953: uint8(0x7f),
  47366 	1954: uint8(0x7f),
  47367 	1955: uint8(0x7f),
  47368 	1956: uint8(0x7f),
  47369 	1957: uint8(0x7f),
  47370 	1958: uint8(0x7f),
  47371 	1959: uint8(0x7f),
  47372 	1960: uint8(0x7f),
  47373 	1961: uint8(0x7f),
  47374 	1962: uint8(0x7f),
  47375 	1963: uint8(0x7f),
  47376 	1964: uint8(0x7f),
  47377 	1965: uint8(0x7f),
  47378 	1966: uint8(0x7f),
  47379 	1967: uint8(0x7f),
  47380 	1968: uint8(0x7f),
  47381 	1969: uint8(0x7f),
  47382 	1970: uint8(0x7f),
  47383 	1971: uint8(0x7f),
  47384 	1972: uint8(0x7f),
  47385 	1973: uint8(0x7f),
  47386 	1974: uint8(0x7f),
  47387 	1975: uint8(0x7f),
  47388 	1976: uint8(0x7f),
  47389 	1977: uint8(0x7f),
  47390 	1978: uint8(0x7f),
  47391 	1979: uint8(0x7f),
  47392 	1980: uint8(0x7f),
  47393 	1981: uint8(0x7f),
  47394 	1982: uint8(0x7f),
  47395 	1983: uint8(0x7f),
  47396 	1984: uint8(0x7f),
  47397 	1985: uint8(0x7f),
  47398 	1986: uint8(0x7f),
  47399 	1987: uint8(0x7f),
  47400 	1988: uint8(0x7f),
  47401 	1989: uint8(0x7f),
  47402 	1990: uint8(0x7f),
  47403 	1991: uint8(0x7f),
  47404 	1992: uint8(0x7f),
  47405 	1993: uint8(0x7f),
  47406 	1994: uint8(0x7f),
  47407 	1995: uint8(0x7f),
  47408 	1996: uint8(0x7f),
  47409 	1997: uint8(0x7f),
  47410 	1998: uint8(0x7f),
  47411 	1999: uint8(0x7f),
  47412 	2000: uint8(0x7f),
  47413 	2001: uint8(0x7f),
  47414 	2002: uint8(0x7f),
  47415 	2003: uint8(0x7f),
  47416 	2004: uint8(0x7f),
  47417 	2005: uint8(0x7f),
  47418 	2006: uint8(0x7f),
  47419 	2007: uint8(0x7f),
  47420 	2008: uint8(0x7f),
  47421 	2009: uint8(0x7f),
  47422 	2010: uint8(0x7f),
  47423 	2011: uint8(0x7f),
  47424 	2012: uint8(0x7f),
  47425 	2013: uint8(0x7f),
  47426 	2014: uint8(0x7f),
  47427 	2015: uint8(0x7f),
  47428 	2016: uint8(0x7f),
  47429 	2017: uint8(0x7f),
  47430 	2018: uint8(0x7f),
  47431 	2019: uint8(0x7f),
  47432 	2020: uint8(0x7f),
  47433 	2021: uint8(0x7f),
  47434 	2022: uint8(0x7f),
  47435 	2023: uint8(0x7f),
  47436 	2024: uint8(0x7f),
  47437 	2025: uint8(0x7f),
  47438 	2026: uint8(0x7f),
  47439 	2027: uint8(0x7f),
  47440 	2028: uint8(0x7f),
  47441 	2029: uint8(0x7f),
  47442 	2030: uint8(0x7f),
  47443 	2031: uint8(0x7f),
  47444 	2032: uint8(0x7f),
  47445 	2033: uint8(0x7f),
  47446 	2034: uint8(0x7f),
  47447 	2035: uint8(0x7f),
  47448 	2036: uint8(0x7f),
  47449 	2037: uint8(0x7f),
  47450 	2038: uint8(0x7f),
  47451 	2039: uint8(0x7f),
  47452 }
  47453 
  47454 var sclip2 = [225]uint8_t{
  47455 	0:   uint8(0xf0),
  47456 	1:   uint8(0xf0),
  47457 	2:   uint8(0xf0),
  47458 	3:   uint8(0xf0),
  47459 	4:   uint8(0xf0),
  47460 	5:   uint8(0xf0),
  47461 	6:   uint8(0xf0),
  47462 	7:   uint8(0xf0),
  47463 	8:   uint8(0xf0),
  47464 	9:   uint8(0xf0),
  47465 	10:  uint8(0xf0),
  47466 	11:  uint8(0xf0),
  47467 	12:  uint8(0xf0),
  47468 	13:  uint8(0xf0),
  47469 	14:  uint8(0xf0),
  47470 	15:  uint8(0xf0),
  47471 	16:  uint8(0xf0),
  47472 	17:  uint8(0xf0),
  47473 	18:  uint8(0xf0),
  47474 	19:  uint8(0xf0),
  47475 	20:  uint8(0xf0),
  47476 	21:  uint8(0xf0),
  47477 	22:  uint8(0xf0),
  47478 	23:  uint8(0xf0),
  47479 	24:  uint8(0xf0),
  47480 	25:  uint8(0xf0),
  47481 	26:  uint8(0xf0),
  47482 	27:  uint8(0xf0),
  47483 	28:  uint8(0xf0),
  47484 	29:  uint8(0xf0),
  47485 	30:  uint8(0xf0),
  47486 	31:  uint8(0xf0),
  47487 	32:  uint8(0xf0),
  47488 	33:  uint8(0xf0),
  47489 	34:  uint8(0xf0),
  47490 	35:  uint8(0xf0),
  47491 	36:  uint8(0xf0),
  47492 	37:  uint8(0xf0),
  47493 	38:  uint8(0xf0),
  47494 	39:  uint8(0xf0),
  47495 	40:  uint8(0xf0),
  47496 	41:  uint8(0xf0),
  47497 	42:  uint8(0xf0),
  47498 	43:  uint8(0xf0),
  47499 	44:  uint8(0xf0),
  47500 	45:  uint8(0xf0),
  47501 	46:  uint8(0xf0),
  47502 	47:  uint8(0xf0),
  47503 	48:  uint8(0xf0),
  47504 	49:  uint8(0xf0),
  47505 	50:  uint8(0xf0),
  47506 	51:  uint8(0xf0),
  47507 	52:  uint8(0xf0),
  47508 	53:  uint8(0xf0),
  47509 	54:  uint8(0xf0),
  47510 	55:  uint8(0xf0),
  47511 	56:  uint8(0xf0),
  47512 	57:  uint8(0xf0),
  47513 	58:  uint8(0xf0),
  47514 	59:  uint8(0xf0),
  47515 	60:  uint8(0xf0),
  47516 	61:  uint8(0xf0),
  47517 	62:  uint8(0xf0),
  47518 	63:  uint8(0xf0),
  47519 	64:  uint8(0xf0),
  47520 	65:  uint8(0xf0),
  47521 	66:  uint8(0xf0),
  47522 	67:  uint8(0xf0),
  47523 	68:  uint8(0xf0),
  47524 	69:  uint8(0xf0),
  47525 	70:  uint8(0xf0),
  47526 	71:  uint8(0xf0),
  47527 	72:  uint8(0xf0),
  47528 	73:  uint8(0xf0),
  47529 	74:  uint8(0xf0),
  47530 	75:  uint8(0xf0),
  47531 	76:  uint8(0xf0),
  47532 	77:  uint8(0xf0),
  47533 	78:  uint8(0xf0),
  47534 	79:  uint8(0xf0),
  47535 	80:  uint8(0xf0),
  47536 	81:  uint8(0xf0),
  47537 	82:  uint8(0xf0),
  47538 	83:  uint8(0xf0),
  47539 	84:  uint8(0xf0),
  47540 	85:  uint8(0xf0),
  47541 	86:  uint8(0xf0),
  47542 	87:  uint8(0xf0),
  47543 	88:  uint8(0xf0),
  47544 	89:  uint8(0xf0),
  47545 	90:  uint8(0xf0),
  47546 	91:  uint8(0xf0),
  47547 	92:  uint8(0xf0),
  47548 	93:  uint8(0xf0),
  47549 	94:  uint8(0xf0),
  47550 	95:  uint8(0xf0),
  47551 	96:  uint8(0xf0),
  47552 	97:  uint8(0xf1),
  47553 	98:  uint8(0xf2),
  47554 	99:  uint8(0xf3),
  47555 	100: uint8(0xf4),
  47556 	101: uint8(0xf5),
  47557 	102: uint8(0xf6),
  47558 	103: uint8(0xf7),
  47559 	104: uint8(0xf8),
  47560 	105: uint8(0xf9),
  47561 	106: uint8(0xfa),
  47562 	107: uint8(0xfb),
  47563 	108: uint8(0xfc),
  47564 	109: uint8(0xfd),
  47565 	110: uint8(0xfe),
  47566 	111: uint8(0xff),
  47567 	113: uint8(0x01),
  47568 	114: uint8(0x02),
  47569 	115: uint8(0x03),
  47570 	116: uint8(0x04),
  47571 	117: uint8(0x05),
  47572 	118: uint8(0x06),
  47573 	119: uint8(0x07),
  47574 	120: uint8(0x08),
  47575 	121: uint8(0x09),
  47576 	122: uint8(0x0a),
  47577 	123: uint8(0x0b),
  47578 	124: uint8(0x0c),
  47579 	125: uint8(0x0d),
  47580 	126: uint8(0x0e),
  47581 	127: uint8(0x0f),
  47582 	128: uint8(0x0f),
  47583 	129: uint8(0x0f),
  47584 	130: uint8(0x0f),
  47585 	131: uint8(0x0f),
  47586 	132: uint8(0x0f),
  47587 	133: uint8(0x0f),
  47588 	134: uint8(0x0f),
  47589 	135: uint8(0x0f),
  47590 	136: uint8(0x0f),
  47591 	137: uint8(0x0f),
  47592 	138: uint8(0x0f),
  47593 	139: uint8(0x0f),
  47594 	140: uint8(0x0f),
  47595 	141: uint8(0x0f),
  47596 	142: uint8(0x0f),
  47597 	143: uint8(0x0f),
  47598 	144: uint8(0x0f),
  47599 	145: uint8(0x0f),
  47600 	146: uint8(0x0f),
  47601 	147: uint8(0x0f),
  47602 	148: uint8(0x0f),
  47603 	149: uint8(0x0f),
  47604 	150: uint8(0x0f),
  47605 	151: uint8(0x0f),
  47606 	152: uint8(0x0f),
  47607 	153: uint8(0x0f),
  47608 	154: uint8(0x0f),
  47609 	155: uint8(0x0f),
  47610 	156: uint8(0x0f),
  47611 	157: uint8(0x0f),
  47612 	158: uint8(0x0f),
  47613 	159: uint8(0x0f),
  47614 	160: uint8(0x0f),
  47615 	161: uint8(0x0f),
  47616 	162: uint8(0x0f),
  47617 	163: uint8(0x0f),
  47618 	164: uint8(0x0f),
  47619 	165: uint8(0x0f),
  47620 	166: uint8(0x0f),
  47621 	167: uint8(0x0f),
  47622 	168: uint8(0x0f),
  47623 	169: uint8(0x0f),
  47624 	170: uint8(0x0f),
  47625 	171: uint8(0x0f),
  47626 	172: uint8(0x0f),
  47627 	173: uint8(0x0f),
  47628 	174: uint8(0x0f),
  47629 	175: uint8(0x0f),
  47630 	176: uint8(0x0f),
  47631 	177: uint8(0x0f),
  47632 	178: uint8(0x0f),
  47633 	179: uint8(0x0f),
  47634 	180: uint8(0x0f),
  47635 	181: uint8(0x0f),
  47636 	182: uint8(0x0f),
  47637 	183: uint8(0x0f),
  47638 	184: uint8(0x0f),
  47639 	185: uint8(0x0f),
  47640 	186: uint8(0x0f),
  47641 	187: uint8(0x0f),
  47642 	188: uint8(0x0f),
  47643 	189: uint8(0x0f),
  47644 	190: uint8(0x0f),
  47645 	191: uint8(0x0f),
  47646 	192: uint8(0x0f),
  47647 	193: uint8(0x0f),
  47648 	194: uint8(0x0f),
  47649 	195: uint8(0x0f),
  47650 	196: uint8(0x0f),
  47651 	197: uint8(0x0f),
  47652 	198: uint8(0x0f),
  47653 	199: uint8(0x0f),
  47654 	200: uint8(0x0f),
  47655 	201: uint8(0x0f),
  47656 	202: uint8(0x0f),
  47657 	203: uint8(0x0f),
  47658 	204: uint8(0x0f),
  47659 	205: uint8(0x0f),
  47660 	206: uint8(0x0f),
  47661 	207: uint8(0x0f),
  47662 	208: uint8(0x0f),
  47663 	209: uint8(0x0f),
  47664 	210: uint8(0x0f),
  47665 	211: uint8(0x0f),
  47666 	212: uint8(0x0f),
  47667 	213: uint8(0x0f),
  47668 	214: uint8(0x0f),
  47669 	215: uint8(0x0f),
  47670 	216: uint8(0x0f),
  47671 	217: uint8(0x0f),
  47672 	218: uint8(0x0f),
  47673 	219: uint8(0x0f),
  47674 	220: uint8(0x0f),
  47675 	221: uint8(0x0f),
  47676 	222: uint8(0x0f),
  47677 	223: uint8(0x0f),
  47678 }
  47679 
  47680 var clip11 = [767]uint8_t{
  47681 	256: uint8(0x01),
  47682 	257: uint8(0x02),
  47683 	258: uint8(0x03),
  47684 	259: uint8(0x04),
  47685 	260: uint8(0x05),
  47686 	261: uint8(0x06),
  47687 	262: uint8(0x07),
  47688 	263: uint8(0x08),
  47689 	264: uint8(0x09),
  47690 	265: uint8(0x0a),
  47691 	266: uint8(0x0b),
  47692 	267: uint8(0x0c),
  47693 	268: uint8(0x0d),
  47694 	269: uint8(0x0e),
  47695 	270: uint8(0x0f),
  47696 	271: uint8(0x10),
  47697 	272: uint8(0x11),
  47698 	273: uint8(0x12),
  47699 	274: uint8(0x13),
  47700 	275: uint8(0x14),
  47701 	276: uint8(0x15),
  47702 	277: uint8(0x16),
  47703 	278: uint8(0x17),
  47704 	279: uint8(0x18),
  47705 	280: uint8(0x19),
  47706 	281: uint8(0x1a),
  47707 	282: uint8(0x1b),
  47708 	283: uint8(0x1c),
  47709 	284: uint8(0x1d),
  47710 	285: uint8(0x1e),
  47711 	286: uint8(0x1f),
  47712 	287: uint8(0x20),
  47713 	288: uint8(0x21),
  47714 	289: uint8(0x22),
  47715 	290: uint8(0x23),
  47716 	291: uint8(0x24),
  47717 	292: uint8(0x25),
  47718 	293: uint8(0x26),
  47719 	294: uint8(0x27),
  47720 	295: uint8(0x28),
  47721 	296: uint8(0x29),
  47722 	297: uint8(0x2a),
  47723 	298: uint8(0x2b),
  47724 	299: uint8(0x2c),
  47725 	300: uint8(0x2d),
  47726 	301: uint8(0x2e),
  47727 	302: uint8(0x2f),
  47728 	303: uint8(0x30),
  47729 	304: uint8(0x31),
  47730 	305: uint8(0x32),
  47731 	306: uint8(0x33),
  47732 	307: uint8(0x34),
  47733 	308: uint8(0x35),
  47734 	309: uint8(0x36),
  47735 	310: uint8(0x37),
  47736 	311: uint8(0x38),
  47737 	312: uint8(0x39),
  47738 	313: uint8(0x3a),
  47739 	314: uint8(0x3b),
  47740 	315: uint8(0x3c),
  47741 	316: uint8(0x3d),
  47742 	317: uint8(0x3e),
  47743 	318: uint8(0x3f),
  47744 	319: uint8(0x40),
  47745 	320: uint8(0x41),
  47746 	321: uint8(0x42),
  47747 	322: uint8(0x43),
  47748 	323: uint8(0x44),
  47749 	324: uint8(0x45),
  47750 	325: uint8(0x46),
  47751 	326: uint8(0x47),
  47752 	327: uint8(0x48),
  47753 	328: uint8(0x49),
  47754 	329: uint8(0x4a),
  47755 	330: uint8(0x4b),
  47756 	331: uint8(0x4c),
  47757 	332: uint8(0x4d),
  47758 	333: uint8(0x4e),
  47759 	334: uint8(0x4f),
  47760 	335: uint8(0x50),
  47761 	336: uint8(0x51),
  47762 	337: uint8(0x52),
  47763 	338: uint8(0x53),
  47764 	339: uint8(0x54),
  47765 	340: uint8(0x55),
  47766 	341: uint8(0x56),
  47767 	342: uint8(0x57),
  47768 	343: uint8(0x58),
  47769 	344: uint8(0x59),
  47770 	345: uint8(0x5a),
  47771 	346: uint8(0x5b),
  47772 	347: uint8(0x5c),
  47773 	348: uint8(0x5d),
  47774 	349: uint8(0x5e),
  47775 	350: uint8(0x5f),
  47776 	351: uint8(0x60),
  47777 	352: uint8(0x61),
  47778 	353: uint8(0x62),
  47779 	354: uint8(0x63),
  47780 	355: uint8(0x64),
  47781 	356: uint8(0x65),
  47782 	357: uint8(0x66),
  47783 	358: uint8(0x67),
  47784 	359: uint8(0x68),
  47785 	360: uint8(0x69),
  47786 	361: uint8(0x6a),
  47787 	362: uint8(0x6b),
  47788 	363: uint8(0x6c),
  47789 	364: uint8(0x6d),
  47790 	365: uint8(0x6e),
  47791 	366: uint8(0x6f),
  47792 	367: uint8(0x70),
  47793 	368: uint8(0x71),
  47794 	369: uint8(0x72),
  47795 	370: uint8(0x73),
  47796 	371: uint8(0x74),
  47797 	372: uint8(0x75),
  47798 	373: uint8(0x76),
  47799 	374: uint8(0x77),
  47800 	375: uint8(0x78),
  47801 	376: uint8(0x79),
  47802 	377: uint8(0x7a),
  47803 	378: uint8(0x7b),
  47804 	379: uint8(0x7c),
  47805 	380: uint8(0x7d),
  47806 	381: uint8(0x7e),
  47807 	382: uint8(0x7f),
  47808 	383: uint8(0x80),
  47809 	384: uint8(0x81),
  47810 	385: uint8(0x82),
  47811 	386: uint8(0x83),
  47812 	387: uint8(0x84),
  47813 	388: uint8(0x85),
  47814 	389: uint8(0x86),
  47815 	390: uint8(0x87),
  47816 	391: uint8(0x88),
  47817 	392: uint8(0x89),
  47818 	393: uint8(0x8a),
  47819 	394: uint8(0x8b),
  47820 	395: uint8(0x8c),
  47821 	396: uint8(0x8d),
  47822 	397: uint8(0x8e),
  47823 	398: uint8(0x8f),
  47824 	399: uint8(0x90),
  47825 	400: uint8(0x91),
  47826 	401: uint8(0x92),
  47827 	402: uint8(0x93),
  47828 	403: uint8(0x94),
  47829 	404: uint8(0x95),
  47830 	405: uint8(0x96),
  47831 	406: uint8(0x97),
  47832 	407: uint8(0x98),
  47833 	408: uint8(0x99),
  47834 	409: uint8(0x9a),
  47835 	410: uint8(0x9b),
  47836 	411: uint8(0x9c),
  47837 	412: uint8(0x9d),
  47838 	413: uint8(0x9e),
  47839 	414: uint8(0x9f),
  47840 	415: uint8(0xa0),
  47841 	416: uint8(0xa1),
  47842 	417: uint8(0xa2),
  47843 	418: uint8(0xa3),
  47844 	419: uint8(0xa4),
  47845 	420: uint8(0xa5),
  47846 	421: uint8(0xa6),
  47847 	422: uint8(0xa7),
  47848 	423: uint8(0xa8),
  47849 	424: uint8(0xa9),
  47850 	425: uint8(0xaa),
  47851 	426: uint8(0xab),
  47852 	427: uint8(0xac),
  47853 	428: uint8(0xad),
  47854 	429: uint8(0xae),
  47855 	430: uint8(0xaf),
  47856 	431: uint8(0xb0),
  47857 	432: uint8(0xb1),
  47858 	433: uint8(0xb2),
  47859 	434: uint8(0xb3),
  47860 	435: uint8(0xb4),
  47861 	436: uint8(0xb5),
  47862 	437: uint8(0xb6),
  47863 	438: uint8(0xb7),
  47864 	439: uint8(0xb8),
  47865 	440: uint8(0xb9),
  47866 	441: uint8(0xba),
  47867 	442: uint8(0xbb),
  47868 	443: uint8(0xbc),
  47869 	444: uint8(0xbd),
  47870 	445: uint8(0xbe),
  47871 	446: uint8(0xbf),
  47872 	447: uint8(0xc0),
  47873 	448: uint8(0xc1),
  47874 	449: uint8(0xc2),
  47875 	450: uint8(0xc3),
  47876 	451: uint8(0xc4),
  47877 	452: uint8(0xc5),
  47878 	453: uint8(0xc6),
  47879 	454: uint8(0xc7),
  47880 	455: uint8(0xc8),
  47881 	456: uint8(0xc9),
  47882 	457: uint8(0xca),
  47883 	458: uint8(0xcb),
  47884 	459: uint8(0xcc),
  47885 	460: uint8(0xcd),
  47886 	461: uint8(0xce),
  47887 	462: uint8(0xcf),
  47888 	463: uint8(0xd0),
  47889 	464: uint8(0xd1),
  47890 	465: uint8(0xd2),
  47891 	466: uint8(0xd3),
  47892 	467: uint8(0xd4),
  47893 	468: uint8(0xd5),
  47894 	469: uint8(0xd6),
  47895 	470: uint8(0xd7),
  47896 	471: uint8(0xd8),
  47897 	472: uint8(0xd9),
  47898 	473: uint8(0xda),
  47899 	474: uint8(0xdb),
  47900 	475: uint8(0xdc),
  47901 	476: uint8(0xdd),
  47902 	477: uint8(0xde),
  47903 	478: uint8(0xdf),
  47904 	479: uint8(0xe0),
  47905 	480: uint8(0xe1),
  47906 	481: uint8(0xe2),
  47907 	482: uint8(0xe3),
  47908 	483: uint8(0xe4),
  47909 	484: uint8(0xe5),
  47910 	485: uint8(0xe6),
  47911 	486: uint8(0xe7),
  47912 	487: uint8(0xe8),
  47913 	488: uint8(0xe9),
  47914 	489: uint8(0xea),
  47915 	490: uint8(0xeb),
  47916 	491: uint8(0xec),
  47917 	492: uint8(0xed),
  47918 	493: uint8(0xee),
  47919 	494: uint8(0xef),
  47920 	495: uint8(0xf0),
  47921 	496: uint8(0xf1),
  47922 	497: uint8(0xf2),
  47923 	498: uint8(0xf3),
  47924 	499: uint8(0xf4),
  47925 	500: uint8(0xf5),
  47926 	501: uint8(0xf6),
  47927 	502: uint8(0xf7),
  47928 	503: uint8(0xf8),
  47929 	504: uint8(0xf9),
  47930 	505: uint8(0xfa),
  47931 	506: uint8(0xfb),
  47932 	507: uint8(0xfc),
  47933 	508: uint8(0xfd),
  47934 	509: uint8(0xfe),
  47935 	510: uint8(0xff),
  47936 	511: uint8(0xff),
  47937 	512: uint8(0xff),
  47938 	513: uint8(0xff),
  47939 	514: uint8(0xff),
  47940 	515: uint8(0xff),
  47941 	516: uint8(0xff),
  47942 	517: uint8(0xff),
  47943 	518: uint8(0xff),
  47944 	519: uint8(0xff),
  47945 	520: uint8(0xff),
  47946 	521: uint8(0xff),
  47947 	522: uint8(0xff),
  47948 	523: uint8(0xff),
  47949 	524: uint8(0xff),
  47950 	525: uint8(0xff),
  47951 	526: uint8(0xff),
  47952 	527: uint8(0xff),
  47953 	528: uint8(0xff),
  47954 	529: uint8(0xff),
  47955 	530: uint8(0xff),
  47956 	531: uint8(0xff),
  47957 	532: uint8(0xff),
  47958 	533: uint8(0xff),
  47959 	534: uint8(0xff),
  47960 	535: uint8(0xff),
  47961 	536: uint8(0xff),
  47962 	537: uint8(0xff),
  47963 	538: uint8(0xff),
  47964 	539: uint8(0xff),
  47965 	540: uint8(0xff),
  47966 	541: uint8(0xff),
  47967 	542: uint8(0xff),
  47968 	543: uint8(0xff),
  47969 	544: uint8(0xff),
  47970 	545: uint8(0xff),
  47971 	546: uint8(0xff),
  47972 	547: uint8(0xff),
  47973 	548: uint8(0xff),
  47974 	549: uint8(0xff),
  47975 	550: uint8(0xff),
  47976 	551: uint8(0xff),
  47977 	552: uint8(0xff),
  47978 	553: uint8(0xff),
  47979 	554: uint8(0xff),
  47980 	555: uint8(0xff),
  47981 	556: uint8(0xff),
  47982 	557: uint8(0xff),
  47983 	558: uint8(0xff),
  47984 	559: uint8(0xff),
  47985 	560: uint8(0xff),
  47986 	561: uint8(0xff),
  47987 	562: uint8(0xff),
  47988 	563: uint8(0xff),
  47989 	564: uint8(0xff),
  47990 	565: uint8(0xff),
  47991 	566: uint8(0xff),
  47992 	567: uint8(0xff),
  47993 	568: uint8(0xff),
  47994 	569: uint8(0xff),
  47995 	570: uint8(0xff),
  47996 	571: uint8(0xff),
  47997 	572: uint8(0xff),
  47998 	573: uint8(0xff),
  47999 	574: uint8(0xff),
  48000 	575: uint8(0xff),
  48001 	576: uint8(0xff),
  48002 	577: uint8(0xff),
  48003 	578: uint8(0xff),
  48004 	579: uint8(0xff),
  48005 	580: uint8(0xff),
  48006 	581: uint8(0xff),
  48007 	582: uint8(0xff),
  48008 	583: uint8(0xff),
  48009 	584: uint8(0xff),
  48010 	585: uint8(0xff),
  48011 	586: uint8(0xff),
  48012 	587: uint8(0xff),
  48013 	588: uint8(0xff),
  48014 	589: uint8(0xff),
  48015 	590: uint8(0xff),
  48016 	591: uint8(0xff),
  48017 	592: uint8(0xff),
  48018 	593: uint8(0xff),
  48019 	594: uint8(0xff),
  48020 	595: uint8(0xff),
  48021 	596: uint8(0xff),
  48022 	597: uint8(0xff),
  48023 	598: uint8(0xff),
  48024 	599: uint8(0xff),
  48025 	600: uint8(0xff),
  48026 	601: uint8(0xff),
  48027 	602: uint8(0xff),
  48028 	603: uint8(0xff),
  48029 	604: uint8(0xff),
  48030 	605: uint8(0xff),
  48031 	606: uint8(0xff),
  48032 	607: uint8(0xff),
  48033 	608: uint8(0xff),
  48034 	609: uint8(0xff),
  48035 	610: uint8(0xff),
  48036 	611: uint8(0xff),
  48037 	612: uint8(0xff),
  48038 	613: uint8(0xff),
  48039 	614: uint8(0xff),
  48040 	615: uint8(0xff),
  48041 	616: uint8(0xff),
  48042 	617: uint8(0xff),
  48043 	618: uint8(0xff),
  48044 	619: uint8(0xff),
  48045 	620: uint8(0xff),
  48046 	621: uint8(0xff),
  48047 	622: uint8(0xff),
  48048 	623: uint8(0xff),
  48049 	624: uint8(0xff),
  48050 	625: uint8(0xff),
  48051 	626: uint8(0xff),
  48052 	627: uint8(0xff),
  48053 	628: uint8(0xff),
  48054 	629: uint8(0xff),
  48055 	630: uint8(0xff),
  48056 	631: uint8(0xff),
  48057 	632: uint8(0xff),
  48058 	633: uint8(0xff),
  48059 	634: uint8(0xff),
  48060 	635: uint8(0xff),
  48061 	636: uint8(0xff),
  48062 	637: uint8(0xff),
  48063 	638: uint8(0xff),
  48064 	639: uint8(0xff),
  48065 	640: uint8(0xff),
  48066 	641: uint8(0xff),
  48067 	642: uint8(0xff),
  48068 	643: uint8(0xff),
  48069 	644: uint8(0xff),
  48070 	645: uint8(0xff),
  48071 	646: uint8(0xff),
  48072 	647: uint8(0xff),
  48073 	648: uint8(0xff),
  48074 	649: uint8(0xff),
  48075 	650: uint8(0xff),
  48076 	651: uint8(0xff),
  48077 	652: uint8(0xff),
  48078 	653: uint8(0xff),
  48079 	654: uint8(0xff),
  48080 	655: uint8(0xff),
  48081 	656: uint8(0xff),
  48082 	657: uint8(0xff),
  48083 	658: uint8(0xff),
  48084 	659: uint8(0xff),
  48085 	660: uint8(0xff),
  48086 	661: uint8(0xff),
  48087 	662: uint8(0xff),
  48088 	663: uint8(0xff),
  48089 	664: uint8(0xff),
  48090 	665: uint8(0xff),
  48091 	666: uint8(0xff),
  48092 	667: uint8(0xff),
  48093 	668: uint8(0xff),
  48094 	669: uint8(0xff),
  48095 	670: uint8(0xff),
  48096 	671: uint8(0xff),
  48097 	672: uint8(0xff),
  48098 	673: uint8(0xff),
  48099 	674: uint8(0xff),
  48100 	675: uint8(0xff),
  48101 	676: uint8(0xff),
  48102 	677: uint8(0xff),
  48103 	678: uint8(0xff),
  48104 	679: uint8(0xff),
  48105 	680: uint8(0xff),
  48106 	681: uint8(0xff),
  48107 	682: uint8(0xff),
  48108 	683: uint8(0xff),
  48109 	684: uint8(0xff),
  48110 	685: uint8(0xff),
  48111 	686: uint8(0xff),
  48112 	687: uint8(0xff),
  48113 	688: uint8(0xff),
  48114 	689: uint8(0xff),
  48115 	690: uint8(0xff),
  48116 	691: uint8(0xff),
  48117 	692: uint8(0xff),
  48118 	693: uint8(0xff),
  48119 	694: uint8(0xff),
  48120 	695: uint8(0xff),
  48121 	696: uint8(0xff),
  48122 	697: uint8(0xff),
  48123 	698: uint8(0xff),
  48124 	699: uint8(0xff),
  48125 	700: uint8(0xff),
  48126 	701: uint8(0xff),
  48127 	702: uint8(0xff),
  48128 	703: uint8(0xff),
  48129 	704: uint8(0xff),
  48130 	705: uint8(0xff),
  48131 	706: uint8(0xff),
  48132 	707: uint8(0xff),
  48133 	708: uint8(0xff),
  48134 	709: uint8(0xff),
  48135 	710: uint8(0xff),
  48136 	711: uint8(0xff),
  48137 	712: uint8(0xff),
  48138 	713: uint8(0xff),
  48139 	714: uint8(0xff),
  48140 	715: uint8(0xff),
  48141 	716: uint8(0xff),
  48142 	717: uint8(0xff),
  48143 	718: uint8(0xff),
  48144 	719: uint8(0xff),
  48145 	720: uint8(0xff),
  48146 	721: uint8(0xff),
  48147 	722: uint8(0xff),
  48148 	723: uint8(0xff),
  48149 	724: uint8(0xff),
  48150 	725: uint8(0xff),
  48151 	726: uint8(0xff),
  48152 	727: uint8(0xff),
  48153 	728: uint8(0xff),
  48154 	729: uint8(0xff),
  48155 	730: uint8(0xff),
  48156 	731: uint8(0xff),
  48157 	732: uint8(0xff),
  48158 	733: uint8(0xff),
  48159 	734: uint8(0xff),
  48160 	735: uint8(0xff),
  48161 	736: uint8(0xff),
  48162 	737: uint8(0xff),
  48163 	738: uint8(0xff),
  48164 	739: uint8(0xff),
  48165 	740: uint8(0xff),
  48166 	741: uint8(0xff),
  48167 	742: uint8(0xff),
  48168 	743: uint8(0xff),
  48169 	744: uint8(0xff),
  48170 	745: uint8(0xff),
  48171 	746: uint8(0xff),
  48172 	747: uint8(0xff),
  48173 	748: uint8(0xff),
  48174 	749: uint8(0xff),
  48175 	750: uint8(0xff),
  48176 	751: uint8(0xff),
  48177 	752: uint8(0xff),
  48178 	753: uint8(0xff),
  48179 	754: uint8(0xff),
  48180 	755: uint8(0xff),
  48181 	756: uint8(0xff),
  48182 	757: uint8(0xff),
  48183 	758: uint8(0xff),
  48184 	759: uint8(0xff),
  48185 	760: uint8(0xff),
  48186 	761: uint8(0xff),
  48187 	762: uint8(0xff),
  48188 	763: uint8(0xff),
  48189 	764: uint8(0xff),
  48190 	765: uint8(0xff),
  48191 }
  48192 
  48193 func VP8InitClipTables(tls *libc.TLS) {
  48194 }
  48195 
  48196 func VP8DspInitMIPS32(tls *libc.TLS) {
  48197 }
  48198 
  48199 func VP8DspInitMIPSdspR2(tls *libc.TLS) {
  48200 }
  48201 
  48202 func VP8DspInitMSA(tls *libc.TLS) {
  48203 }
  48204 
  48205 func VP8DspInitNEON(tls *libc.TLS) {
  48206 }
  48207 
  48208 func VP8DspInitSSE2(tls *libc.TLS) {
  48209 }
  48210 
  48211 func VP8DspInitSSE41(tls *libc.TLS) {
  48212 }
  48213 
  48214 //------------------------------------------------------------------------------
  48215 
  48216 // Copyright 2012 Google Inc. All Rights Reserved.
  48217 //
  48218 // Use of this source code is governed by a BSD-style license
  48219 // that can be found in the COPYING file in the root of the source
  48220 // tree. An additional intellectual property rights grant can be found
  48221 // in the file PATENTS. All contributing project authors may
  48222 // be found in the AUTHORS file in the root of the source tree.
  48223 // -----------------------------------------------------------------------------
  48224 //
  48225 // Misc. common utility functions
  48226 //
  48227 // Authors: Skal (pascal.massimino@gmail.com)
  48228 //          Urvang (urvang@google.com)
  48229 
  48230 // Copyright 2010 Google Inc. All Rights Reserved.
  48231 //
  48232 // Use of this source code is governed by a BSD-style license
  48233 // that can be found in the COPYING file in the root of the source
  48234 // tree. An additional intellectual property rights grant can be found
  48235 // in the file PATENTS. All contributing project authors may
  48236 // be found in the AUTHORS file in the root of the source tree.
  48237 // -----------------------------------------------------------------------------
  48238 //
  48239 //  Common types + memory wrappers
  48240 //
  48241 // Author: Skal (pascal.massimino@gmail.com)
  48242 
  48243 func clip_8b2(tls *libc.TLS, v int32) (r uint8_t) {
  48244 	var v1, v2 int32
  48245 	_, _ = v1, v2
  48246 	if !(v & ^libc.Int32FromInt32(0xff) != 0) {
  48247 		v1 = v
  48248 	} else {
  48249 		if v < 0 {
  48250 			v2 = 0
  48251 		} else {
  48252 			v2 = int32(255)
  48253 		}
  48254 		v1 = v2
  48255 	}
  48256 	return libc.Uint8FromInt32(v1)
  48257 }
  48258 
  48259 func clip_max(tls *libc.TLS, v int32, max int32) (r int32) {
  48260 	var v1 int32
  48261 	_ = v1
  48262 	if v > max {
  48263 		v1 = max
  48264 	} else {
  48265 		v1 = v
  48266 	}
  48267 	return v1
  48268 }
  48269 
  48270 // C documentation
  48271 //
  48272 //	// general-purpose util function
  48273 func VP8SetHistogramData(tls *libc.TLS, distribution uintptr, histo uintptr) {
  48274 	var k, last_non_zero, max_value, value int32
  48275 	_, _, _, _ = k, last_non_zero, max_value, value
  48276 	max_value = 0
  48277 	last_non_zero = int32(1)
  48278 	k = 0
  48279 	for {
  48280 		if !(k <= int32(MAX_COEFF_THRESH)) {
  48281 			break
  48282 		}
  48283 		value = **(**int32)(__ccgo_up(distribution + uintptr(k)*4))
  48284 		if value > 0 {
  48285 			if value > max_value {
  48286 				max_value = value
  48287 			}
  48288 			last_non_zero = k
  48289 		}
  48290 		goto _1
  48291 	_1:
  48292 		;
  48293 		k = k + 1
  48294 	}
  48295 	(*VP8Histogram)(unsafe.Pointer(histo)).Fmax_value = max_value
  48296 	(*VP8Histogram)(unsafe.Pointer(histo)).Flast_non_zero = last_non_zero
  48297 }
  48298 
  48299 func CollectHistogram_C(tls *libc.TLS, ref uintptr, pred uintptr, start_block int32, end_block int32, histo uintptr) {
  48300 	bp := tls.Alloc(160)
  48301 	defer tls.Free(160)
  48302 	var clipped_value, j, k, v int32
  48303 	var _ /* distribution at bp+0 */ [32]int32
  48304 	var _ /* out at bp+128 */ [16]int16_t
  48305 	_, _, _, _ = clipped_value, j, k, v
  48306 	**(**[32]int32)(__ccgo_up(bp)) = [32]int32{}
  48307 	j = start_block
  48308 	for {
  48309 		if !(j < end_block) {
  48310 			break
  48311 		}
  48312 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, ref+uintptr(VP8DspScan[j]), pred+uintptr(VP8DspScan[j]), bp+128)
  48313 		// Convert coefficients to bin.
  48314 		k = 0
  48315 		for {
  48316 			if !(k < int32(16)) {
  48317 				break
  48318 			}
  48319 			v = libc.Xabs(tls, int32((**(**[16]int16_t)(__ccgo_up(bp + 128)))[k])) >> int32(3)
  48320 			clipped_value = clip_max(tls, v, int32(MAX_COEFF_THRESH))
  48321 			(**(**[32]int32)(__ccgo_up(bp)))[clipped_value] = (**(**[32]int32)(__ccgo_up(bp)))[clipped_value] + 1
  48322 			goto _2
  48323 		_2:
  48324 			;
  48325 			k = k + 1
  48326 		}
  48327 		goto _1
  48328 	_1:
  48329 		;
  48330 		j = j + 1
  48331 	}
  48332 	VP8SetHistogramData(tls, bp, histo)
  48333 }
  48334 
  48335 //------------------------------------------------------------------------------
  48336 // run-time tables (~4k)
  48337 
  48338 var clip12 [766]uint8_t // clips [-255,510] to [0,255]
  48339 
  48340 // C documentation
  48341 //
  48342 //	// We declare this variable 'volatile' to prevent instruction reordering
  48343 //	// and make sure it's set to true _last_ (so as to be thread-safe)
  48344 var tables_ok = int32(0)
  48345 
  48346 func InitTables(tls *libc.TLS) {
  48347 	var i int32
  48348 	_ = i
  48349 	if !(libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&tables_ok))) != 0) {
  48350 		i = -int32(255)
  48351 		for {
  48352 			if !(i <= libc.Int32FromInt32(255)+libc.Int32FromInt32(255)) {
  48353 				break
  48354 			}
  48355 			clip12[int32(255)+i] = clip_8b2(tls, i)
  48356 			goto _1
  48357 		_1:
  48358 			;
  48359 			i = i + 1
  48360 		}
  48361 		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&tables_ok)), int32(1))
  48362 	}
  48363 }
  48364 
  48365 //------------------------------------------------------------------------------
  48366 // Transforms (Paragraph 14.4)
  48367 
  48368 func ITransformOne(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr) {
  48369 	bp := tls.Alloc(64)
  48370 	defer tls.Free(64)
  48371 	var a, a1, b, b1, c, c1, d, d1, dc, i int32
  48372 	var tmp uintptr
  48373 	var _ /* C at bp+0 */ [16]int32
  48374 	_, _, _, _, _, _, _, _, _, _, _ = a, a1, b, b1, c, c1, d, d1, dc, i, tmp
  48375 	tmp = bp
  48376 	i = 0
  48377 	for {
  48378 		if !(i < int32(4)) {
  48379 			break
  48380 		} // vertical pass
  48381 		a = int32(**(**int16_t)(__ccgo_up(in))) + int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48382 		b = int32(**(**int16_t)(__ccgo_up(in))) - int32(**(**int16_t)(__ccgo_up(in + 8*2)))
  48383 		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))))
  48384 		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)
  48385 		**(**int32)(__ccgo_up(tmp)) = a + d
  48386 		**(**int32)(__ccgo_up(tmp + 1*4)) = b + c
  48387 		**(**int32)(__ccgo_up(tmp + 2*4)) = b - c
  48388 		**(**int32)(__ccgo_up(tmp + 3*4)) = a - d
  48389 		tmp = tmp + uintptr(4)*4
  48390 		in += 2
  48391 		goto _1
  48392 	_1:
  48393 		;
  48394 		i = i + 1
  48395 	}
  48396 	tmp = bp
  48397 	i = 0
  48398 	for {
  48399 		if !(i < int32(4)) {
  48400 			break
  48401 		} // horizontal pass
  48402 		dc = **(**int32)(__ccgo_up(tmp)) + int32(4)
  48403 		a1 = dc + **(**int32)(__ccgo_up(tmp + 8*4))
  48404 		b1 = dc - **(**int32)(__ccgo_up(tmp + 8*4))
  48405 		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)))
  48406 		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)
  48407 		**(**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))
  48408 		**(**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))
  48409 		**(**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))
  48410 		**(**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))
  48411 		tmp += 4
  48412 		goto _2
  48413 	_2:
  48414 		;
  48415 		i = i + 1
  48416 	}
  48417 }
  48418 
  48419 func ITransform_C(tls *libc.TLS, ref uintptr, in uintptr, dst uintptr, do_two int32) {
  48420 	ITransformOne(tls, ref, in, dst)
  48421 	if do_two != 0 {
  48422 		ITransformOne(tls, ref+uintptr(4), in+uintptr(16)*2, dst+uintptr(4))
  48423 	}
  48424 }
  48425 
  48426 func FTransform_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48427 	var a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i int32
  48428 	var tmp [16]int32
  48429 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, d0, d1, d2, d3, i, tmp
  48430 	i = 0
  48431 	for {
  48432 		if !(i < int32(4)) {
  48433 			break
  48434 		}
  48435 		d0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref))) // 9bit dynamic range ([-255,255])
  48436 		d1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + 1))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + 1)))
  48437 		d2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + 2))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + 2)))
  48438 		d3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src + 3))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(ref + 3)))
  48439 		a0 = d0 + d3 // 10b                      [-510,510]
  48440 		a1 = d1 + d2
  48441 		a2 = d1 - d2
  48442 		a3 = d0 - d3
  48443 		tmp[0+i*int32(4)] = (a0 + a1) * int32(8)                                               // 14b                      [-8160,8160]
  48444 		tmp[int32(1)+i*int32(4)] = (a2*int32(2217) + a3*int32(5352) + int32(1812)) >> int32(9) // [-7536,7542]
  48445 		tmp[int32(2)+i*int32(4)] = (a0 - a1) * int32(8)
  48446 		tmp[int32(3)+i*int32(4)] = (a3*int32(2217) - a2*int32(5352) + int32(937)) >> int32(9)
  48447 		goto _1
  48448 	_1:
  48449 		;
  48450 		i = i + 1
  48451 		src = src + uintptr(BPS)
  48452 		ref = ref + uintptr(BPS)
  48453 	}
  48454 	i = 0
  48455 	for {
  48456 		if !(i < int32(4)) {
  48457 			break
  48458 		}
  48459 		a01 = tmp[0+i] + tmp[int32(12)+i] // 15b
  48460 		a11 = tmp[int32(4)+i] + tmp[int32(8)+i]
  48461 		a21 = tmp[int32(4)+i] - tmp[int32(8)+i]
  48462 		a31 = tmp[0+i] - tmp[int32(12)+i]
  48463 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16((a01 + a11 + int32(7)) >> int32(4)) // 12b
  48464 		**(**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))
  48465 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16((a01 - a11 + int32(7)) >> int32(4))
  48466 		**(**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))
  48467 		goto _2
  48468 	_2:
  48469 		;
  48470 		i = i + 1
  48471 	}
  48472 }
  48473 
  48474 func FTransform2_C(tls *libc.TLS, src uintptr, ref uintptr, out uintptr) {
  48475 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src, ref, out)
  48476 	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8FTransform})))(tls, src+uintptr(4), ref+uintptr(4), out+uintptr(16)*2)
  48477 }
  48478 
  48479 func FTransformWHT_C(tls *libc.TLS, in uintptr, out uintptr) {
  48480 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i int32
  48481 	var tmp [16]int32_t
  48482 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, tmp
  48483 	i = 0
  48484 	for {
  48485 		if !(i < int32(4)) {
  48486 			break
  48487 		}
  48488 		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
  48489 		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)))
  48490 		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)))
  48491 		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)))
  48492 		tmp[0+i*int32(4)] = a0 + a1 // 14b
  48493 		tmp[int32(1)+i*int32(4)] = a3 + a2
  48494 		tmp[int32(2)+i*int32(4)] = a3 - a2
  48495 		tmp[int32(3)+i*int32(4)] = a0 - a1
  48496 		goto _1
  48497 	_1:
  48498 		;
  48499 		i = i + 1
  48500 		in = in + uintptr(64)*2
  48501 	}
  48502 	i = 0
  48503 	for {
  48504 		if !(i < int32(4)) {
  48505 			break
  48506 		}
  48507 		a01 = tmp[0+i] + tmp[int32(8)+i] // 15b
  48508 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  48509 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  48510 		a31 = tmp[0+i] - tmp[int32(8)+i]
  48511 		b0 = a01 + a11 // 16b
  48512 		b1 = a31 + a21
  48513 		b2 = a31 - a21
  48514 		b3 = a01 - a11
  48515 		**(**int16_t)(__ccgo_up(out + uintptr(0+i)*2)) = int16(b0 >> int32(1)) // 15b
  48516 		**(**int16_t)(__ccgo_up(out + uintptr(int32(4)+i)*2)) = int16(b1 >> int32(1))
  48517 		**(**int16_t)(__ccgo_up(out + uintptr(int32(8)+i)*2)) = int16(b2 >> int32(1))
  48518 		**(**int16_t)(__ccgo_up(out + uintptr(int32(12)+i)*2)) = int16(b3 >> int32(1))
  48519 		goto _2
  48520 	_2:
  48521 		;
  48522 		i = i + 1
  48523 	}
  48524 }
  48525 
  48526 //------------------------------------------------------------------------------
  48527 // Intra predictions
  48528 
  48529 func Fill(tls *libc.TLS, dst uintptr, value int32, size int32) {
  48530 	var j int32
  48531 	_ = j
  48532 	j = 0
  48533 	for {
  48534 		if !(j < size) {
  48535 			break
  48536 		}
  48537 		libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), value, libc.Uint64FromInt32(size))
  48538 		goto _1
  48539 	_1:
  48540 		;
  48541 		j = j + 1
  48542 	}
  48543 }
  48544 
  48545 func VerticalPred(tls *libc.TLS, dst uintptr, top uintptr, size int32) {
  48546 	var j int32
  48547 	_ = j
  48548 	if top != libc.UintptrFromInt32(0) {
  48549 		j = 0
  48550 		for {
  48551 			if !(j < size) {
  48552 				break
  48553 			}
  48554 			libc.Xmemcpy(tls, dst+uintptr(j*int32(BPS)), top, libc.Uint64FromInt32(size))
  48555 			goto _1
  48556 		_1:
  48557 			;
  48558 			j = j + 1
  48559 		}
  48560 	} else {
  48561 		Fill(tls, dst, int32(127), size)
  48562 	}
  48563 }
  48564 
  48565 func HorizontalPred(tls *libc.TLS, dst uintptr, left uintptr, size int32) {
  48566 	var j int32
  48567 	_ = j
  48568 	if left != libc.UintptrFromInt32(0) {
  48569 		j = 0
  48570 		for {
  48571 			if !(j < size) {
  48572 				break
  48573 			}
  48574 			libc.Xmemset(tls, dst+uintptr(j*int32(BPS)), libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(j)))), libc.Uint64FromInt32(size))
  48575 			goto _1
  48576 		_1:
  48577 			;
  48578 			j = j + 1
  48579 		}
  48580 	} else {
  48581 		Fill(tls, dst, int32(129), size)
  48582 	}
  48583 }
  48584 
  48585 func TrueMotion1(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32) {
  48586 	var clip, clip_table uintptr
  48587 	var x, y int32
  48588 	_, _, _, _ = clip, clip_table, x, y
  48589 	if left != libc.UintptrFromInt32(0) {
  48590 		if top != libc.UintptrFromInt32(0) {
  48591 			clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(-libc.Int32FromInt32(1)))))
  48592 			y = 0
  48593 			for {
  48594 				if !(y < size) {
  48595 					break
  48596 				}
  48597 				clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(left + uintptr(y))))
  48598 				x = 0
  48599 				for {
  48600 					if !(x < size) {
  48601 						break
  48602 					}
  48603 					**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  48604 					goto _2
  48605 				_2:
  48606 					;
  48607 					x = x + 1
  48608 				}
  48609 				dst = dst + uintptr(BPS)
  48610 				goto _1
  48611 			_1:
  48612 				;
  48613 				y = y + 1
  48614 			}
  48615 		} else {
  48616 			HorizontalPred(tls, dst, left, size)
  48617 		}
  48618 	} else {
  48619 		// true motion without left samples (hence: with default 129 value)
  48620 		// is equivalent to VE prediction where you just copy the top samples.
  48621 		// Note that if top samples are not available, the default value is
  48622 		// then 129, and not 127 as in the VerticalPred case.
  48623 		if top != libc.UintptrFromInt32(0) {
  48624 			VerticalPred(tls, dst, top, size)
  48625 		} else {
  48626 			Fill(tls, dst, int32(129), size)
  48627 		}
  48628 	}
  48629 }
  48630 
  48631 func DCMode(tls *libc.TLS, dst uintptr, left uintptr, top uintptr, size int32, round int32, shift int32) {
  48632 	var DC, j int32
  48633 	_, _ = DC, j
  48634 	DC = 0
  48635 	if top != libc.UintptrFromInt32(0) {
  48636 		j = 0
  48637 		for {
  48638 			if !(j < size) {
  48639 				break
  48640 			}
  48641 			DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(j))))
  48642 			goto _1
  48643 		_1:
  48644 			;
  48645 			j = j + 1
  48646 		}
  48647 		if left != libc.UintptrFromInt32(0) { // top and left present
  48648 			j = 0
  48649 			for {
  48650 				if !(j < size) {
  48651 					break
  48652 				}
  48653 				DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48654 				goto _2
  48655 			_2:
  48656 				;
  48657 				j = j + 1
  48658 			}
  48659 		} else { // top, but no left
  48660 			DC = DC + DC
  48661 		}
  48662 		DC = (DC + round) >> shift
  48663 	} else {
  48664 		if left != libc.UintptrFromInt32(0) { // left but no top
  48665 			j = 0
  48666 			for {
  48667 				if !(j < size) {
  48668 					break
  48669 				}
  48670 				DC = DC + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(left + uintptr(j))))
  48671 				goto _3
  48672 			_3:
  48673 				;
  48674 				j = j + 1
  48675 			}
  48676 			DC = DC + DC
  48677 			DC = (DC + round) >> shift
  48678 		} else { // no top, no left, nothing.
  48679 			DC = int32(0x80)
  48680 		}
  48681 	}
  48682 	Fill(tls, dst, DC, size)
  48683 }
  48684 
  48685 //------------------------------------------------------------------------------
  48686 // Chroma 8x8 prediction (paragraph 12.2)
  48687 
  48688 func IntraChromaPreds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48689 	// U block
  48690 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48691 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48692 	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))
  48693 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48694 	// V block
  48695 	dst = dst + uintptr(8)
  48696 	if top != libc.UintptrFromInt32(0) {
  48697 		top = top + uintptr(8)
  48698 	}
  48699 	if left != libc.UintptrFromInt32(0) {
  48700 		left = left + uintptr(16)
  48701 	}
  48702 	DCMode(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(8), int32(8), int32(4))
  48703 	VerticalPred(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS))+dst, top, int32(8))
  48704 	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))
  48705 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(1)*libc.Int32FromInt32(16))+dst, left, top, int32(8))
  48706 }
  48707 
  48708 //------------------------------------------------------------------------------
  48709 // luma 16x16 prediction (paragraph 12.3)
  48710 
  48711 func Intra16Preds_C(tls *libc.TLS, dst uintptr, left uintptr, top uintptr) {
  48712 	DCMode(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, left, top, int32(16), int32(16), int32(5))
  48713 	VerticalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS))+dst, top, int32(16))
  48714 	HorizontalPred(tls, uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, int32(16))
  48715 	TrueMotion1(tls, uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(16))+dst, left, top, int32(16))
  48716 }
  48717 
  48718 //------------------------------------------------------------------------------
  48719 // luma 4x4 prediction
  48720 
  48721 // C documentation
  48722 //
  48723 //	// vertical
  48724 func VE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48725 	bp := tls.Alloc(16)
  48726 	defer tls.Free(16)
  48727 	var i int32
  48728 	var _ /* vals at bp+0 */ [4]uint8_t
  48729 	_ = i
  48730 	**(**[4]uint8_t)(__ccgo_up(bp)) = [4]uint8_t{
  48731 		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)),
  48732 		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)),
  48733 		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)),
  48734 		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)),
  48735 	}
  48736 	i = 0
  48737 	for {
  48738 		if !(i < int32(4)) {
  48739 			break
  48740 		}
  48741 		libc.Xmemcpy(tls, dst+uintptr(i*int32(BPS)), bp, uint64(4))
  48742 		goto _1
  48743 	_1:
  48744 		;
  48745 		i = i + 1
  48746 	}
  48747 }
  48748 
  48749 // C documentation
  48750 //
  48751 //	// horizontal
  48752 func HE4(tls *libc.TLS, dst uintptr, top uintptr) {
  48753 	bp := tls.Alloc(16)
  48754 	defer tls.Free(16)
  48755 	var I, J, K, L, X int32
  48756 	var v1 uint32_t
  48757 	_, _, _, _, _, _ = I, J, K, L, X, v1
  48758 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48759 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48760 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48761 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48762 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48763 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((X+libc.Int32FromInt32(2)*I+J+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48764 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48765 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48766 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((I+libc.Int32FromInt32(2)*J+K+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48767 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48768 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48769 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((J+libc.Int32FromInt32(2)*K+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48770 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48771 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48772 	v1 = uint32(0x01010101) * uint32(libc.Uint8FromInt32((K+libc.Int32FromInt32(2)*L+L+libc.Int32FromInt32(2))>>libc.Int32FromInt32(2)))
  48773 	*(*uint32_t)(unsafe.Pointer(bp)) = v1
  48774 	libc.Xmemcpy(tls, dst+uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)), bp, uint64(4))
  48775 }
  48776 
  48777 func DC4(tls *libc.TLS, dst uintptr, top uintptr) {
  48778 	var dc uint32_t
  48779 	var i int32
  48780 	_, _ = dc, i
  48781 	dc = uint32(4)
  48782 	i = 0
  48783 	for {
  48784 		if !(i < int32(4)) {
  48785 			break
  48786 		}
  48787 		dc = dc + libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(i))))+libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(5)+i)))))
  48788 		goto _1
  48789 	_1:
  48790 		;
  48791 		i = i + 1
  48792 	}
  48793 	Fill(tls, dst, libc.Int32FromUint32(dc>>int32(3)), int32(4))
  48794 }
  48795 
  48796 func RD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48797 	var A, B, C, D, I, J, K, L, X int32
  48798 	var v1, v2, v3 uint8_t
  48799 	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, L, X, v1, v2, v3
  48800 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48801 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48802 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48803 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48804 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48805 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48806 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48807 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48808 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48809 	**(**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))
  48810 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*J + K + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48811 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48812 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48813 	v2 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*I + J + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48814 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48815 	v1 = v2
  48816 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48817 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48818 	v3 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*X + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48819 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48820 	v2 = v3
  48821 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48822 	v1 = v2
  48823 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48824 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48825 	v2 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*A + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48826 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48827 	v1 = v2
  48828 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48829 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48830 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*B + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48831 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48832 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48833 	**(**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))
  48834 }
  48835 
  48836 func LD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48837 	var A, B, C, D, E, F, G, H int32
  48838 	var v1, v2, v3 uint8_t
  48839 	_, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1, v2, v3
  48840 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48841 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48842 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48843 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48844 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 4)))
  48845 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 5)))
  48846 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 6)))
  48847 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 7)))
  48848 	**(**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))
  48849 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48850 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48851 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48852 	v2 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48853 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48854 	v1 = v2
  48855 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48856 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48857 	v3 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48858 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48859 	v2 = v3
  48860 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v2
  48861 	v1 = v2
  48862 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48863 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48864 	v2 = libc.Uint8FromInt32((E + libc.Int32FromInt32(2)*F + G + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48865 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48866 	v1 = v2
  48867 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48868 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48869 	v1 = libc.Uint8FromInt32((F + libc.Int32FromInt32(2)*G + H + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48870 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48871 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48872 	**(**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))
  48873 }
  48874 
  48875 func VR4(tls *libc.TLS, dst uintptr, top uintptr) {
  48876 	var A, B, C, D, I, J, K, X int32
  48877 	var v1 uint8_t
  48878 	_, _, _, _, _, _, _, _, _ = A, B, C, D, I, J, K, X, v1
  48879 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48880 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48881 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48882 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48883 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48884 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48885 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48886 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48887 	v1 = libc.Uint8FromInt32((X + A + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48888 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48889 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48890 	v1 = libc.Uint8FromInt32((A + B + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48891 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48892 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48893 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48894 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48895 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48896 	**(**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))
  48897 	**(**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))
  48898 	**(**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))
  48899 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48900 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48901 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48902 	v1 = libc.Uint8FromInt32((X + libc.Int32FromInt32(2)*A + B + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48903 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48904 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48905 	v1 = libc.Uint8FromInt32((A + libc.Int32FromInt32(2)*B + C + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48906 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48907 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48908 	**(**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))
  48909 }
  48910 
  48911 func VL4(tls *libc.TLS, dst uintptr, top uintptr) {
  48912 	var A, B, C, D, E, F, G, H int32
  48913 	var v1 uint8_t
  48914 	_, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, G, H, v1
  48915 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48916 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48917 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48918 	D = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 3)))
  48919 	E = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 4)))
  48920 	F = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 5)))
  48921 	G = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 6)))
  48922 	H = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 7)))
  48923 	**(**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))
  48924 	v1 = libc.Uint8FromInt32((B + C + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48925 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48926 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48927 	v1 = libc.Uint8FromInt32((C + D + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48928 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48929 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48930 	v1 = libc.Uint8FromInt32((D + E + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48931 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48932 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48933 	**(**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))
  48934 	v1 = libc.Uint8FromInt32((B + libc.Int32FromInt32(2)*C + D + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48935 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48936 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48937 	v1 = libc.Uint8FromInt32((C + libc.Int32FromInt32(2)*D + E + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48938 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48939 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48940 	v1 = libc.Uint8FromInt32((D + libc.Int32FromInt32(2)*E + F + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48941 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  48942 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48943 	**(**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))
  48944 	**(**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))
  48945 }
  48946 
  48947 func HU4(tls *libc.TLS, dst uintptr, top uintptr) {
  48948 	var I, J, K, L int32
  48949 	var v1, v2, v3, v4, v5 uint8_t
  48950 	_, _, _, _, _, _, _, _, _ = I, J, K, L, v1, v2, v3, v4, v5
  48951 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48952 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48953 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48954 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48955 	**(**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))
  48956 	v1 = libc.Uint8FromInt32((J + K + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48957 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48958 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48959 	v1 = libc.Uint8FromInt32((K + L + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48960 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48961 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48962 	**(**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))
  48963 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*K + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48964 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48965 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48966 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*L + L + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  48967 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48968 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48969 	v5 = libc.Uint8FromInt32(L)
  48970 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v5
  48971 	v4 = v5
  48972 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v4
  48973 	v3 = v4
  48974 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v3
  48975 	v2 = v3
  48976 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v2
  48977 	v1 = v2
  48978 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48979 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48980 }
  48981 
  48982 func HD4(tls *libc.TLS, dst uintptr, top uintptr) {
  48983 	var A, B, C, I, J, K, L, X int32
  48984 	var v1 uint8_t
  48985 	_, _, _, _, _, _, _, _, _ = A, B, C, I, J, K, L, X, v1
  48986 	X = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  48987 	I = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(2)))))
  48988 	J = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(3)))))
  48989 	K = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(4)))))
  48990 	L = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(5)))))
  48991 	A = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top)))
  48992 	B = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 1)))
  48993 	C = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top + 2)))
  48994 	v1 = libc.Uint8FromInt32((I + X + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48995 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  48996 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  48997 	v1 = libc.Uint8FromInt32((J + I + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  48998 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  48999 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49000 	v1 = libc.Uint8FromInt32((K + J + libc.Int32FromInt32(1)) >> libc.Int32FromInt32(1))
  49001 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49002 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(0)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49003 	**(**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))
  49004 	**(**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))
  49005 	**(**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))
  49006 	v1 = libc.Uint8FromInt32((I + libc.Int32FromInt32(2)*X + A + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49007 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49008 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)))) = v1
  49009 	v1 = libc.Uint8FromInt32((J + libc.Int32FromInt32(2)*I + X + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49010 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49011 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(1)*libc.Int32FromInt32(BPS)))) = v1
  49012 	v1 = libc.Uint8FromInt32((K + libc.Int32FromInt32(2)*J + I + libc.Int32FromInt32(2)) >> libc.Int32FromInt32(2))
  49013 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(3)+libc.Int32FromInt32(3)*libc.Int32FromInt32(BPS)))) = v1
  49014 	**(**uint8_t)(__ccgo_up(dst + uintptr(libc.Int32FromInt32(1)+libc.Int32FromInt32(2)*libc.Int32FromInt32(BPS)))) = v1
  49015 	**(**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))
  49016 }
  49017 
  49018 func TM4(tls *libc.TLS, dst uintptr, top uintptr) {
  49019 	var clip, clip_table uintptr
  49020 	var x, y int32
  49021 	_, _, _, _ = clip, clip_table, x, y
  49022 	clip = uintptr(unsafe.Pointer(&clip12)) + uintptr(255) - uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1)))))
  49023 	y = 0
  49024 	for {
  49025 		if !(y < int32(4)) {
  49026 			break
  49027 		}
  49028 		clip_table = clip + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(-int32(2)-y))))
  49029 		x = 0
  49030 		for {
  49031 			if !(x < int32(4)) {
  49032 				break
  49033 			}
  49034 			**(**uint8_t)(__ccgo_up(dst + uintptr(x))) = **(**uint8_t)(__ccgo_up(clip_table + uintptr(**(**uint8_t)(__ccgo_up(top + uintptr(x))))))
  49035 			goto _2
  49036 		_2:
  49037 			;
  49038 			x = x + 1
  49039 		}
  49040 		dst = dst + uintptr(BPS)
  49041 		goto _1
  49042 	_1:
  49043 		;
  49044 		y = y + 1
  49045 	}
  49046 }
  49047 
  49048 // C documentation
  49049 //
  49050 //	// Left samples are top[-5 .. -2], top_left is top[-1], top are
  49051 //	// located at top[0..3], and top right is top[4..7]
  49052 func Intra4Preds_C(tls *libc.TLS, dst uintptr, top uintptr) {
  49053 	DC4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0))+dst, top)
  49054 	TM4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(4))+dst, top)
  49055 	VE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(8))+dst, top)
  49056 	HE4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(12))+dst, top)
  49057 	RD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(16))+dst, top)
  49058 	VR4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(20))+dst, top)
  49059 	LD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(24))+dst, top)
  49060 	VL4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(0)+libc.Int32FromInt32(28))+dst, top)
  49061 	HD4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS))+dst, top)
  49062 	HU4(tls, uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)+libc.Int32FromInt32(4))+dst, top)
  49063 }
  49064 
  49065 //------------------------------------------------------------------------------
  49066 // Metric
  49067 
  49068 func GetSSE(tls *libc.TLS, a uintptr, b uintptr, w int32, h int32) (r int32) {
  49069 	var count, diff, x, y int32
  49070 	_, _, _, _ = count, diff, x, y
  49071 	count = 0
  49072 	y = 0
  49073 	for {
  49074 		if !(y < h) {
  49075 			break
  49076 		}
  49077 		x = 0
  49078 		for {
  49079 			if !(x < w) {
  49080 				break
  49081 			}
  49082 			diff = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(a + uintptr(x)))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(b + uintptr(x))))
  49083 			count = count + diff*diff
  49084 			goto _2
  49085 		_2:
  49086 			;
  49087 			x = x + 1
  49088 		}
  49089 		a = a + uintptr(BPS)
  49090 		b = b + uintptr(BPS)
  49091 		goto _1
  49092 	_1:
  49093 		;
  49094 		y = y + 1
  49095 	}
  49096 	return count
  49097 }
  49098 
  49099 func SSE16x16_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49100 	return GetSSE(tls, a, b, int32(16), int32(16))
  49101 }
  49102 
  49103 func SSE16x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49104 	return GetSSE(tls, a, b, int32(16), int32(8))
  49105 }
  49106 
  49107 func SSE8x8_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49108 	return GetSSE(tls, a, b, int32(8), int32(8))
  49109 }
  49110 
  49111 func SSE4x4_C(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
  49112 	return GetSSE(tls, a, b, int32(4), int32(4))
  49113 }
  49114 
  49115 func Mean16x4_C(tls *libc.TLS, ref uintptr, dc uintptr) {
  49116 	var avg uint32_t
  49117 	var k, x, y int32
  49118 	_, _, _, _ = avg, k, x, y
  49119 	k = 0
  49120 	for {
  49121 		if !(k < int32(4)) {
  49122 			break
  49123 		}
  49124 		avg = uint32(0)
  49125 		y = 0
  49126 		for {
  49127 			if !(y < int32(4)) {
  49128 				break
  49129 			}
  49130 			x = 0
  49131 			for {
  49132 				if !(x < int32(4)) {
  49133 					break
  49134 				}
  49135 				avg = avg + uint32(**(**uint8_t)(__ccgo_up(ref + uintptr(x+y*int32(BPS)))))
  49136 				goto _3
  49137 			_3:
  49138 				;
  49139 				x = x + 1
  49140 			}
  49141 			goto _2
  49142 		_2:
  49143 			;
  49144 			y = y + 1
  49145 		}
  49146 		**(**uint32_t)(__ccgo_up(dc + uintptr(k)*4)) = avg
  49147 		ref = ref + uintptr(4) // go to next 4x4 block.
  49148 		goto _1
  49149 	_1:
  49150 		;
  49151 		k = k + 1
  49152 	}
  49153 }
  49154 
  49155 //------------------------------------------------------------------------------
  49156 // Texture distortion
  49157 //
  49158 // We try to match the spectral content (weighted) between source and
  49159 // reconstructed samples.
  49160 
  49161 // C documentation
  49162 //
  49163 //	// Hadamard transform
  49164 //	// Returns the weighted sum of the absolute value of transformed coefficients.
  49165 //	// w[] contains a row-major 4 by 4 symmetric matrix.
  49166 func TTransform(tls *libc.TLS, in uintptr, w uintptr) (r int32) {
  49167 	var a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum int32
  49168 	var tmp [16]int32
  49169 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a0, a01, a1, a11, a2, a21, a3, a31, b0, b1, b2, b3, i, sum, tmp
  49170 	sum = 0
  49171 	// horizontal pass
  49172 	i = 0
  49173 	for {
  49174 		if !(i < int32(4)) {
  49175 			break
  49176 		}
  49177 		a0 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 2)))
  49178 		a1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 1))) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 3)))
  49179 		a2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 1))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 3)))
  49180 		a3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + 2)))
  49181 		tmp[0+i*int32(4)] = a0 + a1
  49182 		tmp[int32(1)+i*int32(4)] = a3 + a2
  49183 		tmp[int32(2)+i*int32(4)] = a3 - a2
  49184 		tmp[int32(3)+i*int32(4)] = a0 - a1
  49185 		goto _1
  49186 	_1:
  49187 		;
  49188 		i = i + 1
  49189 		in = in + uintptr(BPS)
  49190 	}
  49191 	// vertical pass
  49192 	i = 0
  49193 	for {
  49194 		if !(i < int32(4)) {
  49195 			break
  49196 		}
  49197 		a01 = tmp[0+i] + tmp[int32(8)+i]
  49198 		a11 = tmp[int32(4)+i] + tmp[int32(12)+i]
  49199 		a21 = tmp[int32(4)+i] - tmp[int32(12)+i]
  49200 		a31 = tmp[0+i] - tmp[int32(8)+i]
  49201 		b0 = a01 + a11
  49202 		b1 = a31 + a21
  49203 		b2 = a31 - a21
  49204 		b3 = a01 - a11
  49205 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w)))*libc.Xabs(tls, b0)
  49206 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w + 4*2)))*libc.Xabs(tls, b1)
  49207 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w + 8*2)))*libc.Xabs(tls, b2)
  49208 		sum = sum + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(w + 12*2)))*libc.Xabs(tls, b3)
  49209 		goto _2
  49210 	_2:
  49211 		;
  49212 		i = i + 1
  49213 		w += 2
  49214 	}
  49215 	return sum
  49216 }
  49217 
  49218 func Disto4x4_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49219 	var sum1, sum2 int32
  49220 	_, _ = sum1, sum2
  49221 	sum1 = TTransform(tls, a, w)
  49222 	sum2 = TTransform(tls, b, w)
  49223 	return libc.Xabs(tls, sum2-sum1) >> int32(5)
  49224 }
  49225 
  49226 func Disto16x16_C(tls *libc.TLS, a uintptr, b uintptr, w uintptr) (r int32) {
  49227 	var D, x, y int32
  49228 	_, _, _ = D, x, y
  49229 	D = 0
  49230 	y = 0
  49231 	for {
  49232 		if !(y < libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS)) {
  49233 			break
  49234 		}
  49235 		x = 0
  49236 		for {
  49237 			if !(x < int32(16)) {
  49238 				break
  49239 			}
  49240 			D = D + Disto4x4_C(tls, a+uintptr(x)+uintptr(y), b+uintptr(x)+uintptr(y), w)
  49241 			goto _2
  49242 		_2:
  49243 			;
  49244 			x = x + int32(4)
  49245 		}
  49246 		goto _1
  49247 	_1:
  49248 		;
  49249 		y = y + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)
  49250 	}
  49251 	return D
  49252 }
  49253 
  49254 //------------------------------------------------------------------------------
  49255 // Quantization
  49256 //
  49257 
  49258 var kZigzag2 = [16]uint8_t{
  49259 	1:  uint8(1),
  49260 	2:  uint8(4),
  49261 	3:  uint8(8),
  49262 	4:  uint8(5),
  49263 	5:  uint8(2),
  49264 	6:  uint8(3),
  49265 	7:  uint8(6),
  49266 	8:  uint8(9),
  49267 	9:  uint8(12),
  49268 	10: uint8(13),
  49269 	11: uint8(10),
  49270 	12: uint8(7),
  49271 	13: uint8(11),
  49272 	14: uint8(14),
  49273 	15: uint8(15),
  49274 }
  49275 
  49276 // C documentation
  49277 //
  49278 //	// Simple quantization
  49279 func QuantizeBlock_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49280 	var B1, Q, coeff, iQ1 uint32_t
  49281 	var j, last, level, n1, sign, v2, v3 int32
  49282 	_, _, _, _, _, _, _, _, _, _, _ = B1, Q, coeff, iQ1, j, last, level, n1, sign, v2, v3
  49283 	last = -int32(1)
  49284 	n1 = 0
  49285 	for {
  49286 		if !(n1 < int32(16)) {
  49287 			break
  49288 		}
  49289 		j = libc.Int32FromUint8(kZigzag2[n1])
  49290 		sign = libc.BoolInt32(int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2))) < libc.Int32FromInt32(0))
  49291 		if sign != 0 {
  49292 			v2 = -int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49293 		} else {
  49294 			v2 = int32(**(**int16_t)(__ccgo_up(in + uintptr(j)*2)))
  49295 		}
  49296 		coeff = libc.Uint32FromInt32(v2 + libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(mtx + 192 + uintptr(j)*2))))
  49297 		if coeff > **(**uint32_t)(__ccgo_up(mtx + 128 + uintptr(j)*4)) {
  49298 			Q = uint32(**(**uint16_t)(__ccgo_up(mtx + uintptr(j)*2)))
  49299 			iQ1 = uint32(**(**uint16_t)(__ccgo_up(mtx + 32 + uintptr(j)*2)))
  49300 			B1 = **(**uint32_t)(__ccgo_up(mtx + 64 + uintptr(j)*4))
  49301 			v3 = libc.Int32FromUint32((coeff*iQ1 + B1) >> libc.Int32FromInt32(QFIX))
  49302 			goto _4
  49303 		_4:
  49304 			level = v3
  49305 			if level > int32(MAX_LEVEL) {
  49306 				level = int32(MAX_LEVEL)
  49307 			}
  49308 			if sign != 0 {
  49309 				level = -level
  49310 			}
  49311 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = int16(level * libc.Int32FromUint32(Q))
  49312 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = int16(level)
  49313 			if level != 0 {
  49314 				last = n1
  49315 			}
  49316 		} else {
  49317 			**(**int16_t)(__ccgo_up(out + uintptr(n1)*2)) = 0
  49318 			**(**int16_t)(__ccgo_up(in + uintptr(j)*2)) = 0
  49319 		}
  49320 		goto _1
  49321 	_1:
  49322 		;
  49323 		n1 = n1 + 1
  49324 	}
  49325 	return libc.BoolInt32(last >= 0)
  49326 }
  49327 
  49328 func Quantize2Blocks_C(tls *libc.TLS, in uintptr, out uintptr, mtx uintptr) (r int32) {
  49329 	var nz int32
  49330 	_ = nz
  49331 	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
  49332 	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)
  49333 	return nz
  49334 }
  49335 
  49336 //------------------------------------------------------------------------------
  49337 // Block copy
  49338 
  49339 func Copy(tls *libc.TLS, src uintptr, dst uintptr, w int32, h int32) {
  49340 	var y int32
  49341 	_ = y
  49342 	y = 0
  49343 	for {
  49344 		if !(y < h) {
  49345 			break
  49346 		}
  49347 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(w))
  49348 		src = src + uintptr(BPS)
  49349 		dst = dst + uintptr(BPS)
  49350 		goto _1
  49351 	_1:
  49352 		;
  49353 		y = y + 1
  49354 	}
  49355 }
  49356 
  49357 func Copy4x4_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49358 	Copy(tls, src, dst, int32(4), int32(4))
  49359 }
  49360 
  49361 func Copy16x8_C(tls *libc.TLS, src uintptr, dst uintptr) {
  49362 	Copy(tls, src, dst, int32(16), int32(8))
  49363 }
  49364 
  49365 func VP8EncDspInit(tls *libc.TLS) {
  49366 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49367 		goto _1
  49368 	}
  49369 	VP8EncDspInit_body(tls)
  49370 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49371 	goto _2
  49372 _2:
  49373 	;
  49374 	goto _1
  49375 _1: /**/ //
  49376 }
  49377 
  49378 var VP8EncDspInit_body_last_cpuinfo_used = uintptr(0)
  49379 
  49380 func init() {
  49381 	p := unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used)
  49382 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8EncDspInit_body_last_cpuinfo_used))
  49383 }
  49384 
  49385 func VP8EncDspInit_body(tls *libc.TLS) {
  49386 	VP8DspInit(tls) // common inverse transforms
  49387 	InitTables(tls)
  49388 	// default C implementations
  49389 	VP8ITransform = __ccgo_fp(ITransform_C)
  49390 	VP8FTransform = __ccgo_fp(FTransform_C)
  49391 	VP8FTransformWHT = __ccgo_fp(FTransformWHT_C)
  49392 	VP8TDisto4x4 = __ccgo_fp(Disto4x4_C)
  49393 	VP8TDisto16x16 = __ccgo_fp(Disto16x16_C)
  49394 	VP8CollectHistogram = __ccgo_fp(CollectHistogram_C)
  49395 	VP8SSE16x16 = __ccgo_fp(SSE16x16_C)
  49396 	VP8SSE16x8 = __ccgo_fp(SSE16x8_C)
  49397 	VP8SSE8x8 = __ccgo_fp(SSE8x8_C)
  49398 	VP8SSE4x4 = __ccgo_fp(SSE4x4_C)
  49399 	VP8EncQuantizeBlock = __ccgo_fp(QuantizeBlock_C)
  49400 	VP8EncQuantize2Blocks = __ccgo_fp(Quantize2Blocks_C)
  49401 	VP8EncQuantizeBlockWHT = __ccgo_fp(QuantizeBlock_C)
  49402 	VP8EncPredLuma4 = __ccgo_fp(Intra4Preds_C)
  49403 	VP8EncPredLuma16 = __ccgo_fp(Intra16Preds_C)
  49404 	VP8FTransform2 = __ccgo_fp(FTransform2_C)
  49405 	VP8EncPredChroma8 = __ccgo_fp(IntraChromaPreds_C)
  49406 	VP8Mean16x4 = __ccgo_fp(Mean16x4_C)
  49407 	VP8Copy4x4 = __ccgo_fp(Copy4x4_C)
  49408 	VP8Copy16x8 = __ccgo_fp(Copy16x8_C)
  49409 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  49410 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49411 	}
  49412 }
  49413 
  49414 func VP8EncDspInitMIPS32(tls *libc.TLS) {
  49415 }
  49416 
  49417 func VP8EncDspInitMIPSdspR2(tls *libc.TLS) {
  49418 }
  49419 
  49420 func VP8EncDspInitMSA(tls *libc.TLS) {
  49421 }
  49422 
  49423 func VP8EncDspInitNEON(tls *libc.TLS) {
  49424 }
  49425 
  49426 func VP8EncDspInitSSE2(tls *libc.TLS) {
  49427 }
  49428 
  49429 func VP8EncDspInitSSE41(tls *libc.TLS) {
  49430 }
  49431 
  49432 // Copyright 2010 Google Inc. All Rights Reserved.
  49433 //
  49434 // Use of this source code is governed by a BSD-style license
  49435 // that can be found in the COPYING file in the root of the source
  49436 // tree. An additional intellectual property rights grant can be found
  49437 // in the file PATENTS. All contributing project authors may
  49438 // be found in the AUTHORS file in the root of the source tree.
  49439 // -----------------------------------------------------------------------------
  49440 //
  49441 //  Common types + memory wrappers
  49442 //
  49443 // Author: Skal (pascal.massimino@gmail.com)
  49444 
  49445 //------------------------------------------------------------------------------
  49446 // Helpful macro.
  49447 
  49448 func PredictLine_C(tls *libc.TLS, src uintptr, pred uintptr, dst uintptr, length int32) {
  49449 	var i int32
  49450 	_ = i
  49451 	i = 0
  49452 	for {
  49453 		if !(i < length) {
  49454 			break
  49455 		}
  49456 		**(**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)))))
  49457 		goto _1
  49458 	_1:
  49459 		;
  49460 		i = i + 1
  49461 	}
  49462 }
  49463 
  49464 //------------------------------------------------------------------------------
  49465 // Horizontal filter.
  49466 
  49467 func DoHorizontalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49468 	var preds uintptr
  49469 	var row int32
  49470 	_, _ = preds, row
  49471 	preds = in
  49472 	// Leftmost pixel is the same as input for topmost scanline.
  49473 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49474 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49475 	preds = preds + uintptr(stride)
  49476 	in = in + uintptr(stride)
  49477 	out = out + uintptr(stride)
  49478 	// Filter line-by-line.
  49479 	row = int32(1)
  49480 	for {
  49481 		if !(row < height) {
  49482 			break
  49483 		}
  49484 		// Leftmost pixel is predicted from above.
  49485 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49486 		PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49487 		preds = preds + uintptr(stride)
  49488 		in = in + uintptr(stride)
  49489 		out = out + uintptr(stride)
  49490 		goto _1
  49491 	_1:
  49492 		;
  49493 		row = row + 1
  49494 	}
  49495 }
  49496 
  49497 //------------------------------------------------------------------------------
  49498 // Vertical filter.
  49499 
  49500 func DoVerticalFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49501 	var preds uintptr
  49502 	var row int32
  49503 	_, _ = preds, row
  49504 	preds = in
  49505 	// Very first top-left pixel is copied.
  49506 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49507 	// Rest of top scan-line is left-predicted.
  49508 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49509 	in = in + uintptr(stride)
  49510 	out = out + uintptr(stride)
  49511 	// Filter line-by-line.
  49512 	row = int32(1)
  49513 	for {
  49514 		if !(row < height) {
  49515 			break
  49516 		}
  49517 		PredictLine_C(tls, in, preds, out, width)
  49518 		preds = preds + uintptr(stride)
  49519 		in = in + uintptr(stride)
  49520 		out = out + uintptr(stride)
  49521 		goto _1
  49522 	_1:
  49523 		;
  49524 		row = row + 1
  49525 	}
  49526 }
  49527 
  49528 //------------------------------------------------------------------------------
  49529 // Gradient filter.
  49530 
  49531 func GradientPredictor_C(tls *libc.TLS, a uint8_t, b uint8_t, c uint8_t) (r int32) {
  49532 	var g, v1, v2 int32
  49533 	_, _, _ = g, v1, v2
  49534 	g = libc.Int32FromUint8(a) + libc.Int32FromUint8(b) - libc.Int32FromUint8(c)
  49535 	if g & ^libc.Int32FromInt32(0xff) == 0 {
  49536 		v1 = g
  49537 	} else {
  49538 		if g < 0 {
  49539 			v2 = 0
  49540 		} else {
  49541 			v2 = int32(255)
  49542 		}
  49543 		v1 = v2
  49544 	}
  49545 	return v1 // clip to 8bit
  49546 }
  49547 
  49548 func DoGradientFilter_C(tls *libc.TLS, in uintptr, width int32, height int32, stride int32, out uintptr) {
  49549 	var pred, row, w int32
  49550 	var preds uintptr
  49551 	_, _, _, _ = pred, preds, row, w
  49552 	preds = in
  49553 	// left prediction for top scan-line
  49554 	**(**uint8_t)(__ccgo_up(out)) = **(**uint8_t)(__ccgo_up(in))
  49555 	PredictLine_C(tls, in+uintptr(1), preds, out+uintptr(1), width-int32(1))
  49556 	preds = preds + uintptr(stride)
  49557 	in = in + uintptr(stride)
  49558 	out = out + uintptr(stride)
  49559 	// Filter line-by-line.
  49560 	row = int32(1)
  49561 	for {
  49562 		if !(row < height) {
  49563 			break
  49564 		}
  49565 		// leftmost pixel: predict from above.
  49566 		PredictLine_C(tls, in, preds-uintptr(stride), out, int32(1))
  49567 		w = int32(1)
  49568 		for {
  49569 			if !(w < width) {
  49570 				break
  49571 			}
  49572 			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)))))
  49573 			**(**uint8_t)(__ccgo_up(out + uintptr(w))) = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(w)))) - pred)
  49574 			goto _2
  49575 		_2:
  49576 			;
  49577 			w = w + 1
  49578 		}
  49579 		preds = preds + uintptr(stride)
  49580 		in = in + uintptr(stride)
  49581 		out = out + uintptr(stride)
  49582 		goto _1
  49583 	_1:
  49584 		;
  49585 		row = row + 1
  49586 	}
  49587 }
  49588 
  49589 //------------------------------------------------------------------------------
  49590 
  49591 func HorizontalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49592 	DoHorizontalFilter_C(tls, data, width, height, stride, filtered_data)
  49593 }
  49594 
  49595 func VerticalFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49596 	DoVerticalFilter_C(tls, data, width, height, stride, filtered_data)
  49597 }
  49598 
  49599 func GradientFilter_C(tls *libc.TLS, data uintptr, width int32, height int32, stride int32, filtered_data uintptr) {
  49600 	DoGradientFilter_C(tls, data, width, height, stride, filtered_data)
  49601 }
  49602 
  49603 //------------------------------------------------------------------------------
  49604 
  49605 func NoneUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49606 	_ = prev
  49607 	if out != in {
  49608 		libc.Xmemcpy(tls, out, in, libc.Uint64FromInt32(width)*uint64(1))
  49609 	}
  49610 }
  49611 
  49612 func HorizontalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49613 	var i, v1 int32
  49614 	var pred uint8_t
  49615 	_, _, _ = i, pred, v1
  49616 	if prev == libc.UintptrFromInt32(0) {
  49617 		v1 = 0
  49618 	} else {
  49619 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(prev)))
  49620 	}
  49621 	pred = libc.Uint8FromInt32(v1)
  49622 	i = 0
  49623 	for {
  49624 		if !(i < width) {
  49625 			break
  49626 		}
  49627 		**(**uint8_t)(__ccgo_up(out + uintptr(i))) = libc.Uint8FromInt32(libc.Int32FromUint8(pred) + libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(i)))))
  49628 		pred = **(**uint8_t)(__ccgo_up(out + uintptr(i)))
  49629 		goto _2
  49630 	_2:
  49631 		;
  49632 		i = i + 1
  49633 	}
  49634 }
  49635 
  49636 func VerticalUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49637 	var i int32
  49638 	_ = i
  49639 	if prev == libc.UintptrFromInt32(0) {
  49640 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49641 	} else {
  49642 		i = 0
  49643 		for {
  49644 			if !(i < width) {
  49645 				break
  49646 			}
  49647 			**(**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)))))
  49648 			goto _1
  49649 		_1:
  49650 			;
  49651 			i = i + 1
  49652 		}
  49653 	}
  49654 }
  49655 
  49656 func GradientUnfilter_C(tls *libc.TLS, prev uintptr, in uintptr, out uintptr, width int32) {
  49657 	var i int32
  49658 	var left, top, top_left uint8_t
  49659 	_, _, _, _ = i, left, top, top_left
  49660 	if prev == libc.UintptrFromInt32(0) {
  49661 		HorizontalUnfilter_C(tls, libc.UintptrFromInt32(0), in, out, width)
  49662 	} else {
  49663 		top = **(**uint8_t)(__ccgo_up(prev))
  49664 		top_left = top
  49665 		left = top
  49666 		i = 0
  49667 		for {
  49668 			if !(i < width) {
  49669 				break
  49670 			}
  49671 			top = **(**uint8_t)(__ccgo_up(prev + uintptr(i))) // need to read this first, in case prev==out
  49672 			left = libc.Uint8FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(in + uintptr(i)))) + GradientPredictor_C(tls, left, top, top_left))
  49673 			top_left = top
  49674 			**(**uint8_t)(__ccgo_up(out + uintptr(i))) = left
  49675 			goto _1
  49676 		_1:
  49677 			;
  49678 			i = i + 1
  49679 		}
  49680 	}
  49681 }
  49682 
  49683 func VP8FiltersInit(tls *libc.TLS) {
  49684 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  49685 		goto _1
  49686 	}
  49687 	VP8FiltersInit_body(tls)
  49688 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  49689 	goto _2
  49690 _2:
  49691 	;
  49692 	goto _1
  49693 _1: /**/ //
  49694 }
  49695 
  49696 var VP8FiltersInit_body_last_cpuinfo_used = uintptr(0)
  49697 
  49698 func init() {
  49699 	p := unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used)
  49700 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8FiltersInit_body_last_cpuinfo_used))
  49701 }
  49702 
  49703 func VP8FiltersInit_body(tls *libc.TLS) {
  49704 	WebPUnfilters[int32(WEBP_FILTER_NONE)] = __ccgo_fp(NoneUnfilter_C)
  49705 	WebPUnfilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalUnfilter_C)
  49706 	WebPUnfilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalUnfilter_C)
  49707 	WebPUnfilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientUnfilter_C)
  49708 	WebPFilters[int32(WEBP_FILTER_NONE)] = libc.UintptrFromInt32(0)
  49709 	WebPFilters[int32(WEBP_FILTER_HORIZONTAL)] = __ccgo_fp(HorizontalFilter_C)
  49710 	WebPFilters[int32(WEBP_FILTER_VERTICAL)] = __ccgo_fp(VerticalFilter_C)
  49711 	WebPFilters[int32(WEBP_FILTER_GRADIENT)] = __ccgo_fp(GradientFilter_C)
  49712 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  49713 	}
  49714 }
  49715 
  49716 func VP8FiltersInitMIPSdspR2(tls *libc.TLS) {
  49717 }
  49718 
  49719 func VP8FiltersInitMSA(tls *libc.TLS) {
  49720 }
  49721 
  49722 func VP8FiltersInitNEON(tls *libc.TLS) {
  49723 }
  49724 
  49725 func VP8FiltersInitSSE2(tls *libc.TLS) {
  49726 }
  49727 
  49728 func VP8LDspInitAVX2(tls *libc.TLS) {
  49729 }
  49730 
  49731 const ARGB_BLACK3 = 4278190080
  49732 
  49733 var kHashMul15 = uint32(0x1e35a7bd)
  49734 
  49735 // Copyright 2012 Google Inc. All Rights Reserved.
  49736 //
  49737 // Use of this source code is governed by a BSD-style license
  49738 // that can be found in the COPYING file in the root of the source
  49739 // tree. An additional intellectual property rights grant can be found
  49740 // in the file PATENTS. All contributing project authors may
  49741 // be found in the AUTHORS file in the root of the source tree.
  49742 // -----------------------------------------------------------------------------
  49743 //
  49744 // Misc. common utility functions
  49745 //
  49746 // Authors: Skal (pascal.massimino@gmail.com)
  49747 //          Urvang (urvang@google.com)
  49748 
  49749 // Copyright 2010 Google Inc. All Rights Reserved.
  49750 //
  49751 // Use of this source code is governed by a BSD-style license
  49752 // that can be found in the COPYING file in the root of the source
  49753 // tree. An additional intellectual property rights grant can be found
  49754 // in the file PATENTS. All contributing project authors may
  49755 // be found in the AUTHORS file in the root of the source tree.
  49756 // -----------------------------------------------------------------------------
  49757 //
  49758 //  Main decoding functions for WebP images.
  49759 //
  49760 // Author: Skal (pascal.massimino@gmail.com)
  49761 
  49762 // Copyright 2012 Google Inc. All Rights Reserved.
  49763 //
  49764 // Use of this source code is governed by a BSD-style license
  49765 // that can be found in the COPYING file in the root of the source
  49766 // tree. An additional intellectual property rights grant can be found
  49767 // in the file PATENTS. All contributing project authors may
  49768 // be found in the AUTHORS file in the root of the source tree.
  49769 // -----------------------------------------------------------------------------
  49770 //
  49771 //  Internal header for constants related to WebP file format.
  49772 //
  49773 // Author: Urvang (urvang@google.com)
  49774 
  49775 // Copyright 2010 Google Inc. All Rights Reserved.
  49776 //
  49777 // Use of this source code is governed by a BSD-style license
  49778 // that can be found in the COPYING file in the root of the source
  49779 // tree. An additional intellectual property rights grant can be found
  49780 // in the file PATENTS. All contributing project authors may
  49781 // be found in the AUTHORS file in the root of the source tree.
  49782 // -----------------------------------------------------------------------------
  49783 //
  49784 //  Common types + memory wrappers
  49785 //
  49786 // Author: Skal (pascal.massimino@gmail.com)
  49787 
  49788 //------------------------------------------------------------------------------
  49789 // Image transforms.
  49790 
  49791 func Average2(tls *libc.TLS, a0 uint32_t, a1 uint32_t) (r uint32_t) {
  49792 	return (a0^a1)&uint32(0xfefefefe)>>int32(1) + a0&a1
  49793 }
  49794 
  49795 func Average3(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t) (r uint32_t) {
  49796 	return Average2(tls, Average2(tls, a0, a2), a1)
  49797 }
  49798 
  49799 func Average4(tls *libc.TLS, a0 uint32_t, a1 uint32_t, a2 uint32_t, a3 uint32_t) (r uint32_t) {
  49800 	return Average2(tls, Average2(tls, a0, a1), Average2(tls, a2, a3))
  49801 }
  49802 
  49803 func Clip255(tls *libc.TLS, a uint32_t) (r uint32_t) {
  49804 	if a < uint32(256) {
  49805 		return a
  49806 	}
  49807 	// return 0, when a is a negative integer.
  49808 	// return 255, when a is positive.
  49809 	return ^a >> int32(24)
  49810 }
  49811 
  49812 func AddSubtractComponentFull(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  49813 	return libc.Int32FromUint32(Clip255(tls, libc.Uint32FromInt32(a+b-c)))
  49814 }
  49815 
  49816 func ClampedAddSubtractFull(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  49817 	var a, b, g, r int32
  49818 	_, _, _, _ = a, b, g, r
  49819 	a = AddSubtractComponentFull(tls, libc.Int32FromUint32(c0>>int32(24)), libc.Int32FromUint32(c1>>int32(24)), libc.Int32FromUint32(c2>>int32(24)))
  49820 	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)))
  49821 	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)))
  49822 	b = AddSubtractComponentFull(tls, libc.Int32FromUint32(c0&uint32(0xff)), libc.Int32FromUint32(c1&uint32(0xff)), libc.Int32FromUint32(c2&uint32(0xff)))
  49823 	return libc.Uint32FromInt32(a)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  49824 }
  49825 
  49826 func AddSubtractComponentHalf(tls *libc.TLS, a int32, b int32) (r int32) {
  49827 	return libc.Int32FromUint32(Clip255(tls, libc.Uint32FromInt32(a+(a-b)/libc.Int32FromInt32(2))))
  49828 }
  49829 
  49830 func ClampedAddSubtractHalf(tls *libc.TLS, c0 uint32_t, c1 uint32_t, c2 uint32_t) (r1 uint32_t) {
  49831 	var a, b, g, r int32
  49832 	var ave uint32_t
  49833 	_, _, _, _, _ = a, ave, b, g, r
  49834 	ave = Average2(tls, c0, c1)
  49835 	a = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>int32(24)), libc.Int32FromUint32(c2>>int32(24)))
  49836 	r = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>libc.Int32FromInt32(16)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(16)&uint32(0xff)))
  49837 	g = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>libc.Int32FromInt32(8)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(8)&uint32(0xff)))
  49838 	b = AddSubtractComponentHalf(tls, libc.Int32FromUint32(ave>>libc.Int32FromInt32(0)&uint32(0xff)), libc.Int32FromUint32(c2>>libc.Int32FromInt32(0)&uint32(0xff)))
  49839 	return libc.Uint32FromInt32(a)<<libc.Int32FromInt32(24) | libc.Uint32FromInt32(r<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(g<<libc.Int32FromInt32(8)) | libc.Uint32FromInt32(b)
  49840 }
  49841 
  49842 // gcc <= 4.9 on ARM generates incorrect code in Select() when Sub3() is
  49843 // inlined.
  49844 
  49845 func Sub3(tls *libc.TLS, a int32, b int32, c int32) (r int32) {
  49846 	var pa, pb int32
  49847 	_, _ = pa, pb
  49848 	pb = b - c
  49849 	pa = a - c
  49850 	return libc.Xabs(tls, pb) - libc.Xabs(tls, pa)
  49851 }
  49852 
  49853 func Select(tls *libc.TLS, a uint32_t, b uint32_t, c uint32_t) (r uint32_t) {
  49854 	var pa_minus_pb int32
  49855 	var v1 uint32
  49856 	_, _ = pa_minus_pb, v1
  49857 	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)))
  49858 	if pa_minus_pb <= 0 {
  49859 		v1 = a
  49860 	} else {
  49861 		v1 = b
  49862 	}
  49863 	return v1
  49864 }
  49865 
  49866 //------------------------------------------------------------------------------
  49867 // Predictors
  49868 
  49869 func VP8LPredictor0_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49870 	_ = top
  49871 	_ = left
  49872 	return uint32(ARGB_BLACK3)
  49873 }
  49874 
  49875 func VP8LPredictor1_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49876 	_ = top
  49877 	return **(**uint32_t)(__ccgo_up(left))
  49878 }
  49879 
  49880 func VP8LPredictor2_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49881 	_ = left
  49882 	return **(**uint32_t)(__ccgo_up(top))
  49883 }
  49884 
  49885 func VP8LPredictor3_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49886 	_ = left
  49887 	return **(**uint32_t)(__ccgo_up(top + 1*4))
  49888 }
  49889 
  49890 func VP8LPredictor4_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49891 	_ = left
  49892 	return **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4))
  49893 }
  49894 
  49895 func VP8LPredictor5_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49896 	var pred uint32_t
  49897 	_ = pred
  49898 	pred = Average3(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  49899 	return pred
  49900 }
  49901 
  49902 func VP8LPredictor6_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49903 	var pred uint32_t
  49904 	_ = pred
  49905 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49906 	return pred
  49907 }
  49908 
  49909 func VP8LPredictor7_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49910 	var pred uint32_t
  49911 	_ = pred
  49912 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)))
  49913 	return pred
  49914 }
  49915 
  49916 func VP8LPredictor8_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49917 	var pred uint32_t
  49918 	_ = pred
  49919 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)), **(**uint32_t)(__ccgo_up(top)))
  49920 	_ = left
  49921 	return pred
  49922 }
  49923 
  49924 func VP8LPredictor9_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49925 	var pred uint32_t
  49926 	_ = pred
  49927 	pred = Average2(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + 1*4)))
  49928 	_ = left
  49929 	return pred
  49930 }
  49931 
  49932 func VP8LPredictor10_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49933 	var pred uint32_t
  49934 	_ = pred
  49935 	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)))
  49936 	return pred
  49937 }
  49938 
  49939 func VP8LPredictor11_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49940 	var pred uint32_t
  49941 	_ = pred
  49942 	pred = Select(tls, **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49943 	return pred
  49944 }
  49945 
  49946 func VP8LPredictor12_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49947 	var pred uint32_t
  49948 	_ = pred
  49949 	pred = ClampedAddSubtractFull(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49950 	return pred
  49951 }
  49952 
  49953 func VP8LPredictor13_C(tls *libc.TLS, left uintptr, top uintptr) (r uint32_t) {
  49954 	var pred uint32_t
  49955 	_ = pred
  49956 	pred = ClampedAddSubtractHalf(tls, **(**uint32_t)(__ccgo_up(left)), **(**uint32_t)(__ccgo_up(top)), **(**uint32_t)(__ccgo_up(top + uintptr(-libc.Int32FromInt32(1))*4)))
  49957 	return pred
  49958 }
  49959 
  49960 func PredictorAdd0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49961 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  49962 	var x int32
  49963 	_, _, _, _, _, _ = alpha_and_green, red_and_blue, x, v2, v3, v4
  49964 	_ = upper
  49965 	x = 0
  49966 	for {
  49967 		if !(x < num_pixels) {
  49968 			break
  49969 		}
  49970 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  49971 		v3 = uint32(ARGB_BLACK3)
  49972 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  49973 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  49974 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  49975 		goto _5
  49976 	_5:
  49977 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  49978 		goto _1
  49979 	_1:
  49980 		;
  49981 		x = x + 1
  49982 	}
  49983 }
  49984 
  49985 func PredictorAdd1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  49986 	var alpha_and_green, left, red_and_blue, v2, v3, v4, v5 uint32_t
  49987 	var i int32
  49988 	_, _, _, _, _, _, _, _ = alpha_and_green, i, left, red_and_blue, v2, v3, v4, v5
  49989 	left = **(**uint32_t)(__ccgo_up(out + uintptr(-libc.Int32FromInt32(1))*4))
  49990 	_ = upper
  49991 	i = 0
  49992 	for {
  49993 		if !(i < num_pixels) {
  49994 			break
  49995 		}
  49996 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  49997 		v4 = left
  49998 		alpha_and_green = v3&uint32(0xff00ff00) + v4&uint32(0xff00ff00)
  49999 		red_and_blue = v3&uint32(0x00ff00ff) + v4&uint32(0x00ff00ff)
  50000 		v5 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50001 		goto _6
  50002 	_6:
  50003 		v2 = v5
  50004 		left = v2
  50005 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v2
  50006 		goto _1
  50007 	_1:
  50008 		;
  50009 		i = i + 1
  50010 	}
  50011 }
  50012 
  50013 func PredictorAdd2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50014 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50015 	var x int32
  50016 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50017 	x = 0
  50018 	for {
  50019 		if !(x < num_pixels) {
  50020 			break
  50021 		}
  50022 		pred = VP8LPredictor2_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50023 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50024 		v3 = pred
  50025 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50026 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50027 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50028 		goto _5
  50029 	_5:
  50030 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50031 		goto _1
  50032 	_1:
  50033 		;
  50034 		x = x + 1
  50035 	}
  50036 }
  50037 
  50038 func PredictorAdd3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50039 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50040 	var x int32
  50041 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50042 	x = 0
  50043 	for {
  50044 		if !(x < num_pixels) {
  50045 			break
  50046 		}
  50047 		pred = VP8LPredictor3_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50048 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50049 		v3 = pred
  50050 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50051 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50052 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50053 		goto _5
  50054 	_5:
  50055 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50056 		goto _1
  50057 	_1:
  50058 		;
  50059 		x = x + 1
  50060 	}
  50061 }
  50062 
  50063 func PredictorAdd4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50064 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50065 	var x int32
  50066 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50067 	x = 0
  50068 	for {
  50069 		if !(x < num_pixels) {
  50070 			break
  50071 		}
  50072 		pred = VP8LPredictor4_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50073 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50074 		v3 = pred
  50075 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50076 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50077 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50078 		goto _5
  50079 	_5:
  50080 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50081 		goto _1
  50082 	_1:
  50083 		;
  50084 		x = x + 1
  50085 	}
  50086 }
  50087 
  50088 func PredictorAdd5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50089 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50090 	var x int32
  50091 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50092 	x = 0
  50093 	for {
  50094 		if !(x < num_pixels) {
  50095 			break
  50096 		}
  50097 		pred = VP8LPredictor5_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50098 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50099 		v3 = pred
  50100 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50101 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50102 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50103 		goto _5
  50104 	_5:
  50105 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50106 		goto _1
  50107 	_1:
  50108 		;
  50109 		x = x + 1
  50110 	}
  50111 }
  50112 
  50113 func PredictorAdd6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50114 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50115 	var x int32
  50116 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50117 	x = 0
  50118 	for {
  50119 		if !(x < num_pixels) {
  50120 			break
  50121 		}
  50122 		pred = VP8LPredictor6_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50123 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50124 		v3 = pred
  50125 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50126 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50127 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50128 		goto _5
  50129 	_5:
  50130 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50131 		goto _1
  50132 	_1:
  50133 		;
  50134 		x = x + 1
  50135 	}
  50136 }
  50137 
  50138 func PredictorAdd7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50139 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50140 	var x int32
  50141 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50142 	x = 0
  50143 	for {
  50144 		if !(x < num_pixels) {
  50145 			break
  50146 		}
  50147 		pred = VP8LPredictor7_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50148 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50149 		v3 = pred
  50150 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50151 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50152 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50153 		goto _5
  50154 	_5:
  50155 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50156 		goto _1
  50157 	_1:
  50158 		;
  50159 		x = x + 1
  50160 	}
  50161 }
  50162 
  50163 func PredictorAdd8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50164 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50165 	var x int32
  50166 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50167 	x = 0
  50168 	for {
  50169 		if !(x < num_pixels) {
  50170 			break
  50171 		}
  50172 		pred = VP8LPredictor8_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50173 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50174 		v3 = pred
  50175 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50176 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50177 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50178 		goto _5
  50179 	_5:
  50180 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50181 		goto _1
  50182 	_1:
  50183 		;
  50184 		x = x + 1
  50185 	}
  50186 }
  50187 
  50188 func PredictorAdd9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50189 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50190 	var x int32
  50191 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50192 	x = 0
  50193 	for {
  50194 		if !(x < num_pixels) {
  50195 			break
  50196 		}
  50197 		pred = VP8LPredictor9_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50198 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50199 		v3 = pred
  50200 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50201 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50202 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50203 		goto _5
  50204 	_5:
  50205 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50206 		goto _1
  50207 	_1:
  50208 		;
  50209 		x = x + 1
  50210 	}
  50211 }
  50212 
  50213 func PredictorAdd10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50214 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50215 	var x int32
  50216 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50217 	x = 0
  50218 	for {
  50219 		if !(x < num_pixels) {
  50220 			break
  50221 		}
  50222 		pred = VP8LPredictor10_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50223 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50224 		v3 = pred
  50225 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50226 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50227 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50228 		goto _5
  50229 	_5:
  50230 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50231 		goto _1
  50232 	_1:
  50233 		;
  50234 		x = x + 1
  50235 	}
  50236 }
  50237 
  50238 func PredictorAdd11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50239 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50240 	var x int32
  50241 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50242 	x = 0
  50243 	for {
  50244 		if !(x < num_pixels) {
  50245 			break
  50246 		}
  50247 		pred = VP8LPredictor11_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50248 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50249 		v3 = pred
  50250 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50251 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50252 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50253 		goto _5
  50254 	_5:
  50255 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50256 		goto _1
  50257 	_1:
  50258 		;
  50259 		x = x + 1
  50260 	}
  50261 }
  50262 
  50263 func PredictorAdd12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50264 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50265 	var x int32
  50266 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50267 	x = 0
  50268 	for {
  50269 		if !(x < num_pixels) {
  50270 			break
  50271 		}
  50272 		pred = VP8LPredictor12_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50273 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50274 		v3 = pred
  50275 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50276 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50277 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50278 		goto _5
  50279 	_5:
  50280 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50281 		goto _1
  50282 	_1:
  50283 		;
  50284 		x = x + 1
  50285 	}
  50286 }
  50287 
  50288 func PredictorAdd13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  50289 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  50290 	var x int32
  50291 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  50292 	x = 0
  50293 	for {
  50294 		if !(x < num_pixels) {
  50295 			break
  50296 		}
  50297 		pred = VP8LPredictor13_C(tls, out+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  50298 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  50299 		v3 = pred
  50300 		alpha_and_green = v2&uint32(0xff00ff00) + v3&uint32(0xff00ff00)
  50301 		red_and_blue = v2&uint32(0x00ff00ff) + v3&uint32(0x00ff00ff)
  50302 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  50303 		goto _5
  50304 	_5:
  50305 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  50306 		goto _1
  50307 	_1:
  50308 		;
  50309 		x = x + 1
  50310 	}
  50311 }
  50312 
  50313 //------------------------------------------------------------------------------
  50314 
  50315 // C documentation
  50316 //
  50317 //	// Inverse prediction.
  50318 func PredictorInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, in uintptr, out uintptr) {
  50319 	var mask, tile_width, tiles_per_row, width, x, x_end, y int32
  50320 	var pred_func VP8LPredictorAddSubFunc
  50321 	var pred_mode_base, pred_mode_src, v4 uintptr
  50322 	var v1, v2 uint32_t
  50323 	_, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred_func, pred_mode_base, pred_mode_src, tile_width, tiles_per_row, width, x, x_end, y, v1, v2, v4
  50324 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50325 	if y_start == 0 { // First Row follows the L (mode=1) mode.
  50326 		PredictorAdd0_C(tls, in, libc.UintptrFromInt32(0), int32(1), out)
  50327 		PredictorAdd1_C(tls, in+uintptr(1)*4, libc.UintptrFromInt32(0), width-int32(1), out+uintptr(1)*4)
  50328 		in = in + uintptr(width)*4
  50329 		out = out + uintptr(width)*4
  50330 		y_start = y_start + 1
  50331 	}
  50332 	y = y_start
  50333 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50334 	mask = tile_width - int32(1)
  50335 	v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50336 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50337 	goto _3
  50338 _3:
  50339 	tiles_per_row = libc.Int32FromUint32(v2)
  50340 	pred_mode_base = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50341 	for y < y_end {
  50342 		pred_mode_src = pred_mode_base
  50343 		x = int32(1)
  50344 		// First pixel follows the T (mode=2) mode.
  50345 		PredictorAdd2_C(tls, in, out-uintptr(width)*4, int32(1), out)
  50346 		// .. the rest:
  50347 		for x < width {
  50348 			v4 = pred_mode_src
  50349 			pred_mode_src += 4
  50350 			pred_func = VP8LPredictorsAdd[**(**uint32_t)(__ccgo_up(v4))>>libc.Int32FromInt32(8)&uint32(0xf)]
  50351 			x_end = x & ^mask + tile_width
  50352 			if x_end > width {
  50353 				x_end = width
  50354 			}
  50355 			(*(*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)
  50356 			x = x_end
  50357 		}
  50358 		in = in + uintptr(width)*4
  50359 		out = out + uintptr(width)*4
  50360 		y = y + 1
  50361 		if y&mask == 0 { // Use the same mask, since tiles are squares.
  50362 			pred_mode_base = pred_mode_base + uintptr(tiles_per_row)*4
  50363 		}
  50364 	}
  50365 }
  50366 
  50367 // C documentation
  50368 //
  50369 //	// Add green to blue and red channels (i.e. perform the inverse transform of
  50370 //	// 'subtract green').
  50371 func VP8LAddGreenToBlueAndRed_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50372 	var argb, green, red_blue uint32_t
  50373 	var i int32
  50374 	_, _, _, _ = argb, green, i, red_blue
  50375 	i = 0
  50376 	for {
  50377 		if !(i < num_pixels) {
  50378 			break
  50379 		}
  50380 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50381 		green = argb >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xff)
  50382 		red_blue = argb & libc.Uint32FromUint32(0x00ff00ff)
  50383 		red_blue = red_blue + (green<<libc.Int32FromInt32(16) | green)
  50384 		red_blue = red_blue & uint32(0x00ff00ff)
  50385 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | red_blue
  50386 		goto _1
  50387 	_1:
  50388 		;
  50389 		i = i + 1
  50390 	}
  50391 }
  50392 
  50393 func ColorTransformDelta(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  50394 	return int32(color_pred) * int32(color) >> int32(5)
  50395 }
  50396 
  50397 func ColorCodeToMultipliers1(tls *libc.TLS, color_code uint32_t, m uintptr) {
  50398 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red = uint8(color_code >> libc.Int32FromInt32(0) & uint32(0xff))
  50399 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue = uint8(color_code >> libc.Int32FromInt32(8) & uint32(0xff))
  50400 	(*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue = uint8(color_code >> libc.Int32FromInt32(16) & uint32(0xff))
  50401 }
  50402 
  50403 func VP8LTransformColorInverse_C(tls *libc.TLS, m uintptr, src uintptr, num_pixels int32, dst uintptr) {
  50404 	var argb, red uint32_t
  50405 	var green int8_t
  50406 	var i, new_blue, new_red int32
  50407 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  50408 	i = 0
  50409 	for {
  50410 		if !(i < num_pixels) {
  50411 			break
  50412 		}
  50413 		argb = **(**uint32_t)(__ccgo_up(src + uintptr(i)*4))
  50414 		green = libc.Int8FromUint32(argb >> libc.Int32FromInt32(8))
  50415 		red = argb >> int32(16)
  50416 		new_red = libc.Int32FromUint32(red & uint32(0xff))
  50417 		new_blue = libc.Int32FromUint32(argb & uint32(0xff))
  50418 		new_red = new_red + ColorTransformDelta(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  50419 		new_red = new_red & int32(0xff)
  50420 		new_blue = new_blue + ColorTransformDelta(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  50421 		new_blue = new_blue + ColorTransformDelta(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), int8(new_red))
  50422 		new_blue = new_blue & int32(0xff)
  50423 		**(**uint32_t)(__ccgo_up(dst + uintptr(i)*4)) = argb&uint32(0xff00ff00) | libc.Uint32FromInt32(new_red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(new_blue)
  50424 		goto _1
  50425 	_1:
  50426 		;
  50427 		i = i + 1
  50428 	}
  50429 }
  50430 
  50431 // C documentation
  50432 //
  50433 //	// Color space inverse transform.
  50434 func ColorSpaceInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50435 	bp := tls.Alloc(16)
  50436 	defer tls.Free(16)
  50437 	var mask, remaining_width, safe_width, tile_width, tiles_per_row, width, y int32
  50438 	var pred, pred_row, src_end, src_safe_end, v4 uintptr
  50439 	var v1, v2 uint32_t
  50440 	var _ /* m at bp+0 */ VP8LMultipliers
  50441 	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = mask, pred, pred_row, remaining_width, safe_width, src_end, src_safe_end, tile_width, tiles_per_row, width, y, v1, v2, v4
  50442 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50443 	tile_width = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50444 	mask = tile_width - int32(1)
  50445 	safe_width = width & ^mask
  50446 	remaining_width = width - safe_width
  50447 	v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50448 	v2 = (libc.Uint32FromInt32(width) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50449 	goto _3
  50450 _3:
  50451 	tiles_per_row = libc.Int32FromUint32(v2)
  50452 	y = y_start
  50453 	pred_row = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata + uintptr(y>>(*VP8LTransform)(unsafe.Pointer(transform)).Fbits*tiles_per_row)*4
  50454 	for y < y_end {
  50455 		pred = pred_row
  50456 		**(**VP8LMultipliers)(__ccgo_up(bp)) = VP8LMultipliers{}
  50457 		src_safe_end = src + uintptr(safe_width)*4
  50458 		src_end = src + uintptr(width)*4
  50459 		for src < src_safe_end {
  50460 			v4 = pred
  50461 			pred += 4
  50462 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50463 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, tile_width, dst)
  50464 			src = src + uintptr(tile_width)*4
  50465 			dst = dst + uintptr(tile_width)*4
  50466 		}
  50467 		if src < src_end { // Left-overs using C-version.
  50468 			v4 = pred
  50469 			pred += 4
  50470 			ColorCodeToMultipliers1(tls, **(**uint32_t)(__ccgo_up(v4)), bp)
  50471 			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LTransformColorInverse})))(tls, bp, src, remaining_width, dst)
  50472 			src = src + uintptr(remaining_width)*4
  50473 			dst = dst + uintptr(remaining_width)*4
  50474 		}
  50475 		y = y + 1
  50476 		if y&mask == 0 {
  50477 			pred_row = pred_row + uintptr(tiles_per_row)*4
  50478 		}
  50479 	}
  50480 }
  50481 
  50482 // Separate out pixels packed together using pixel-bundling.
  50483 // We define two methods for ARGB data (uint32_t) and alpha-only data (uint8_t).
  50484 func MapARGB_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50485 	var x, y int32
  50486 	var v3, v4 uintptr
  50487 	var v5, v7 uint32_t
  50488 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50489 	y = y_start
  50490 	for {
  50491 		if !(y < y_end) {
  50492 			break
  50493 		}
  50494 		x = 0
  50495 		for {
  50496 			if !(x < width) {
  50497 				break
  50498 			}
  50499 			v3 = dst
  50500 			dst += 4
  50501 			v4 = src
  50502 			src += 4
  50503 			v5 = **(**uint32_t)(__ccgo_up(v4)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50504 			goto _6
  50505 		_6:
  50506 			v7 = **(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4))
  50507 			goto _8
  50508 		_8:
  50509 			**(**uint32_t)(__ccgo_up(v3)) = v7
  50510 			goto _2
  50511 		_2:
  50512 			;
  50513 			x = x + 1
  50514 		}
  50515 		goto _1
  50516 	_1:
  50517 		;
  50518 		y = y + 1
  50519 	}
  50520 }
  50521 
  50522 func ColorIndexInverseTransform_C(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50523 	var bit_mask, packed_pixels, v4 uint32_t
  50524 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50525 	var color_map, v3 uintptr
  50526 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50527 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50528 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50529 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50530 	if bits_per_pixel < int32(8) {
  50531 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50532 		count_mask = pixels_per_byte - int32(1)
  50533 		bit_mask = libc.Uint32FromInt32(int32(1)<<bits_per_pixel - int32(1))
  50534 		y = y_start
  50535 		for {
  50536 			if !(y < y_end) {
  50537 				break
  50538 			}
  50539 			packed_pixels = uint32(0)
  50540 			x = 0
  50541 			for {
  50542 				if !(x < width) {
  50543 					break
  50544 				} /* 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.                                         */
  50545 				if x&count_mask == 0 {
  50546 					v3 = src
  50547 					src += 4
  50548 					v4 = **(**uint32_t)(__ccgo_up(v3)) >> libc.Int32FromInt32(8) & uint32(0xff)
  50549 					goto _5
  50550 				_5:
  50551 					packed_pixels = v4
  50552 				}
  50553 				v3 = dst
  50554 				dst += 4
  50555 				v4 = **(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4))
  50556 				goto _8
  50557 			_8:
  50558 				**(**uint32_t)(__ccgo_up(v3)) = v4
  50559 				packed_pixels = packed_pixels >> libc.Uint32FromInt32(bits_per_pixel)
  50560 				goto _2
  50561 			_2:
  50562 				;
  50563 				x = x + 1
  50564 			}
  50565 			goto _1
  50566 		_1:
  50567 			;
  50568 			y = y + 1
  50569 		}
  50570 	} else {
  50571 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor32b})))(tls, src, color_map, dst, y_start, y_end, width)
  50572 	}
  50573 }
  50574 
  50575 func MapAlpha_C(tls *libc.TLS, src uintptr, color_map uintptr, dst uintptr, y_start int32, y_end int32, width int32) {
  50576 	var x, y int32
  50577 	var v3, v4 uintptr
  50578 	var v5, v7 uint8_t
  50579 	_, _, _, _, _, _ = x, y, v3, v4, v5, v7
  50580 	y = y_start
  50581 	for {
  50582 		if !(y < y_end) {
  50583 			break
  50584 		}
  50585 		x = 0
  50586 		for {
  50587 			if !(x < width) {
  50588 				break
  50589 			}
  50590 			v3 = dst
  50591 			dst = dst + 1
  50592 			v4 = src
  50593 			src = src + 1
  50594 			v5 = **(**uint8_t)(__ccgo_up(v4))
  50595 			goto _6
  50596 		_6:
  50597 			v7 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(v5)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50598 			goto _8
  50599 		_8:
  50600 			**(**uint8_t)(__ccgo_up(v3)) = v7
  50601 			goto _2
  50602 		_2:
  50603 			;
  50604 			x = x + 1
  50605 		}
  50606 		goto _1
  50607 	_1:
  50608 		;
  50609 		y = y + 1
  50610 	}
  50611 }
  50612 
  50613 func VP8LColorIndexInverseTransformAlpha(tls *libc.TLS, transform uintptr, y_start int32, y_end int32, src uintptr, dst uintptr) {
  50614 	var bit_mask, packed_pixels uint32_t
  50615 	var bits_per_pixel, count_mask, pixels_per_byte, width, x, y int32
  50616 	var color_map, v3 uintptr
  50617 	var v4 uint8_t
  50618 	_, _, _, _, _, _, _, _, _, _, _ = bit_mask, bits_per_pixel, color_map, count_mask, packed_pixels, pixels_per_byte, width, x, y, v3, v4
  50619 	bits_per_pixel = int32(8) >> (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50620 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50621 	color_map = (*VP8LTransform)(unsafe.Pointer(transform)).Fdata
  50622 	if bits_per_pixel < int32(8) {
  50623 		pixels_per_byte = int32(1) << (*VP8LTransform)(unsafe.Pointer(transform)).Fbits
  50624 		count_mask = pixels_per_byte - int32(1)
  50625 		bit_mask = libc.Uint32FromInt32(int32(1)<<bits_per_pixel - int32(1))
  50626 		y = y_start
  50627 		for {
  50628 			if !(y < y_end) {
  50629 				break
  50630 			}
  50631 			packed_pixels = uint32(0)
  50632 			x = 0
  50633 			for {
  50634 				if !(x < width) {
  50635 					break
  50636 				} /* 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.                                         */
  50637 				if x&count_mask == 0 {
  50638 					v3 = src
  50639 					src = src + 1
  50640 					v4 = **(**uint8_t)(__ccgo_up(v3))
  50641 					goto _5
  50642 				_5:
  50643 					packed_pixels = uint32(v4)
  50644 				}
  50645 				v3 = dst
  50646 				dst = dst + 1
  50647 				v4 = uint8(**(**uint32_t)(__ccgo_up(color_map + uintptr(packed_pixels&bit_mask)*4)) >> libc.Int32FromInt32(8) & uint32(0xff))
  50648 				goto _8
  50649 			_8:
  50650 				**(**uint8_t)(__ccgo_up(v3)) = v4
  50651 				packed_pixels = packed_pixels >> libc.Uint32FromInt32(bits_per_pixel)
  50652 				goto _2
  50653 			_2:
  50654 				;
  50655 				x = x + 1
  50656 			}
  50657 			goto _1
  50658 		_1:
  50659 			;
  50660 			y = y + 1
  50661 		}
  50662 	} else {
  50663 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{VP8LMapColor8b})))(tls, src, color_map, dst, y_start, y_end, width)
  50664 	}
  50665 }
  50666 
  50667 func VP8LInverseTransform(tls *libc.TLS, transform uintptr, row_start int32, row_end int32, in uintptr, out uintptr) {
  50668 	var in_stride, out_stride, width int32
  50669 	var src uintptr
  50670 	var v1, v2 uint32_t
  50671 	_, _, _, _, _, _ = in_stride, out_stride, src, width, v1, v2
  50672 	width = (*VP8LTransform)(unsafe.Pointer(transform)).Fxsize
  50673 	switch (*VP8LTransform)(unsafe.Pointer(transform)).Ftype1 {
  50674 	case int32(SUBTRACT_GREEN_TRANSFORM):
  50675 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LAddGreenToBlueAndRed})))(tls, in, (row_end-row_start)*width, out)
  50676 	case int32(PREDICTOR_TRANSFORM):
  50677 		PredictorInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50678 		if row_end != (*VP8LTransform)(unsafe.Pointer(transform)).Fysize {
  50679 			// The last predicted row in this iteration will be the top-pred row
  50680 			// for the first row in next iteration.
  50681 			libc.Xmemcpy(tls, out-uintptr(width)*4, out+uintptr((row_end-row_start-int32(1))*width)*4, libc.Uint64FromInt32(width)*uint64(4))
  50682 		}
  50683 	case int32(CROSS_COLOR_TRANSFORM):
  50684 		ColorSpaceInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50685 	case int32(COLOR_INDEXING_TRANSFORM):
  50686 		if in == out && (*VP8LTransform)(unsafe.Pointer(transform)).Fbits > 0 {
  50687 			// Move packed pixels to the end of unpacked region, so that unpacking
  50688 			// can occur seamlessly.
  50689 			// Also, note that this is the only transform that applies on
  50690 			// the effective width of VP8LSubSampleSize(xsize, bits). All other
  50691 			// transforms work on effective width of 'xsize'.
  50692 			out_stride = (row_end - row_start) * width
  50693 			v1 = libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fbits)
  50694 			v2 = (libc.Uint32FromInt32((*VP8LTransform)(unsafe.Pointer(transform)).Fxsize) + libc.Uint32FromInt32(libc.Int32FromInt32(1)<<v1) - uint32(1)) >> v1
  50695 			goto _3
  50696 		_3:
  50697 			in_stride = libc.Int32FromUint32(libc.Uint32FromInt32(row_end-row_start) * v2)
  50698 			src = out + uintptr(out_stride)*4 - uintptr(in_stride)*4
  50699 			libc.Xmemmove(tls, src, out, libc.Uint64FromInt32(in_stride)*uint64(4))
  50700 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, src, out)
  50701 		} else {
  50702 			ColorIndexInverseTransform_C(tls, transform, row_start, row_end, in, out)
  50703 		}
  50704 		break
  50705 	}
  50706 }
  50707 
  50708 //------------------------------------------------------------------------------
  50709 // Color space conversion.
  50710 
  50711 func is_big_endian(tls *libc.TLS) (r int32) {
  50712 	return libc.BoolInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(uintptr(unsafe.Pointer(&tmp))))) != int32(1))
  50713 }
  50714 
  50715 var tmp = *(*struct {
  50716 	Fb [0][2]uint8_t
  50717 	Fw uint16_t
  50718 })(unsafe.Pointer(&[1]uint16{0x1}))
  50719 
  50720 func VP8LConvertBGRAToRGB_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50721 	var argb uint32_t
  50722 	var src_end, v1, v2 uintptr
  50723 	_, _, _, _ = argb, src_end, v1, v2
  50724 	src_end = src + uintptr(num_pixels)*4
  50725 	for src < src_end {
  50726 		v1 = src
  50727 		src += 4
  50728 		argb = **(**uint32_t)(__ccgo_up(v1))
  50729 		v2 = dst
  50730 		dst = dst + 1
  50731 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50732 		v1 = dst
  50733 		dst = dst + 1
  50734 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50735 		v1 = dst
  50736 		dst = dst + 1
  50737 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50738 	}
  50739 }
  50740 
  50741 func VP8LConvertBGRAToRGBA_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50742 	var argb uint32_t
  50743 	var src_end, v1, v2 uintptr
  50744 	_, _, _, _ = argb, src_end, v1, v2
  50745 	src_end = src + uintptr(num_pixels)*4
  50746 	for src < src_end {
  50747 		v1 = src
  50748 		src += 4
  50749 		argb = **(**uint32_t)(__ccgo_up(v1))
  50750 		v2 = dst
  50751 		dst = dst + 1
  50752 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50753 		v1 = dst
  50754 		dst = dst + 1
  50755 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50756 		v1 = dst
  50757 		dst = dst + 1
  50758 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50759 		v1 = dst
  50760 		dst = dst + 1
  50761 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(24) & uint32(0xff))
  50762 	}
  50763 }
  50764 
  50765 func VP8LConvertBGRAToRGBA4444_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50766 	var argb uint32_t
  50767 	var ba, rg uint8_t
  50768 	var src_end, v1, v2 uintptr
  50769 	_, _, _, _, _, _ = argb, ba, rg, src_end, v1, v2
  50770 	src_end = src + uintptr(num_pixels)*4
  50771 	for src < src_end {
  50772 		v1 = src
  50773 		src += 4
  50774 		argb = **(**uint32_t)(__ccgo_up(v1))
  50775 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf0) | argb>>libc.Int32FromInt32(12)&uint32(0xf))
  50776 		ba = uint8(argb>>libc.Int32FromInt32(0)&uint32(0xf0) | argb>>libc.Int32FromInt32(28)&uint32(0xf))
  50777 		v2 = dst
  50778 		dst = dst + 1
  50779 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50780 		v1 = dst
  50781 		dst = dst + 1
  50782 		**(**uint8_t)(__ccgo_up(v1)) = ba
  50783 	}
  50784 }
  50785 
  50786 func VP8LConvertBGRAToRGB565_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50787 	var argb uint32_t
  50788 	var gb, rg uint8_t
  50789 	var src_end, v1, v2 uintptr
  50790 	_, _, _, _, _, _ = argb, gb, rg, src_end, v1, v2
  50791 	src_end = src + uintptr(num_pixels)*4
  50792 	for src < src_end {
  50793 		v1 = src
  50794 		src += 4
  50795 		argb = **(**uint32_t)(__ccgo_up(v1))
  50796 		rg = uint8(argb>>libc.Int32FromInt32(16)&uint32(0xf8) | argb>>libc.Int32FromInt32(13)&uint32(0x7))
  50797 		gb = uint8(argb>>libc.Int32FromInt32(5)&uint32(0xe0) | argb>>libc.Int32FromInt32(3)&uint32(0x1f))
  50798 		v2 = dst
  50799 		dst = dst + 1
  50800 		**(**uint8_t)(__ccgo_up(v2)) = rg
  50801 		v1 = dst
  50802 		dst = dst + 1
  50803 		**(**uint8_t)(__ccgo_up(v1)) = gb
  50804 	}
  50805 }
  50806 
  50807 func VP8LConvertBGRAToBGR_C(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr) {
  50808 	var argb uint32_t
  50809 	var src_end, v1, v2 uintptr
  50810 	_, _, _, _ = argb, src_end, v1, v2
  50811 	src_end = src + uintptr(num_pixels)*4
  50812 	for src < src_end {
  50813 		v1 = src
  50814 		src += 4
  50815 		argb = **(**uint32_t)(__ccgo_up(v1))
  50816 		v2 = dst
  50817 		dst = dst + 1
  50818 		**(**uint8_t)(__ccgo_up(v2)) = uint8(argb >> libc.Int32FromInt32(0) & uint32(0xff))
  50819 		v1 = dst
  50820 		dst = dst + 1
  50821 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(8) & uint32(0xff))
  50822 		v1 = dst
  50823 		dst = dst + 1
  50824 		**(**uint8_t)(__ccgo_up(v1)) = uint8(argb >> libc.Int32FromInt32(16) & uint32(0xff))
  50825 	}
  50826 }
  50827 
  50828 func CopyOrSwap(tls *libc.TLS, src uintptr, num_pixels int32, dst uintptr, swap_on_big_endian int32) {
  50829 	bp := tls.Alloc(16)
  50830 	defer tls.Free(16)
  50831 	var argb, v2, v4 uint32_t
  50832 	var src_end, v1 uintptr
  50833 	_, _, _, _, _ = argb, src_end, v1, v2, v4
  50834 	if is_big_endian(tls) == swap_on_big_endian {
  50835 		src_end = src + uintptr(num_pixels)*4
  50836 		for src < src_end {
  50837 			v1 = src
  50838 			src += 4
  50839 			argb = **(**uint32_t)(__ccgo_up(v1))
  50840 			v2 = libc.X__builtin_bswap32(tls, argb)
  50841 			goto _3
  50842 		_3:
  50843 			v4 = v2
  50844 			*(*uint32_t)(unsafe.Pointer(bp)) = v4
  50845 			libc.Xmemcpy(tls, dst, bp, uint64(4))
  50846 			dst = dst + uintptr(4)
  50847 		}
  50848 	} else {
  50849 		libc.Xmemcpy(tls, dst, src, libc.Uint64FromInt32(num_pixels)*uint64(4))
  50850 	}
  50851 }
  50852 
  50853 func VP8LConvertFromBGRA(tls *libc.TLS, in_data uintptr, num_pixels int32, out_colorspace WEBP_CSP_MODE1, rgba uintptr) {
  50854 	switch out_colorspace {
  50855 	case int32(MODE_RGB):
  50856 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB})))(tls, in_data, num_pixels, rgba)
  50857 	case int32(MODE_RGBA):
  50858 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  50859 	case int32(MODE_rgbA):
  50860 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA})))(tls, in_data, num_pixels, rgba)
  50861 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  50862 	case int32(MODE_BGR):
  50863 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToBGR})))(tls, in_data, num_pixels, rgba)
  50864 	case int32(MODE_BGRA):
  50865 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  50866 	case int32(MODE_bgrA):
  50867 		CopyOrSwap(tls, in_data, num_pixels, rgba, int32(1))
  50868 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, 0, num_pixels, int32(1), 0)
  50869 	case int32(MODE_ARGB):
  50870 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  50871 	case int32(MODE_Argb):
  50872 		CopyOrSwap(tls, in_data, num_pixels, rgba, 0)
  50873 		(*(*func(*libc.TLS, uintptr, int32, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply})))(tls, rgba, int32(1), num_pixels, int32(1), 0)
  50874 	case int32(MODE_RGBA_4444):
  50875 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  50876 	case int32(MODE_rgbA_4444):
  50877 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGBA4444})))(tls, in_data, num_pixels, rgba)
  50878 		(*(*func(*libc.TLS, uintptr, int32, int32, int32))(unsafe.Pointer(&struct{ uintptr }{WebPApplyAlphaMultiply4444})))(tls, rgba, num_pixels, int32(1), 0)
  50879 	case int32(MODE_RGB_565):
  50880 		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{VP8LConvertBGRAToRGB565})))(tls, in_data, num_pixels, rgba)
  50881 	default:
  50882 		// Code flow should not reach here.
  50883 	}
  50884 }
  50885 
  50886 func VP8LDspInit(tls *libc.TLS) {
  50887 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  50888 		goto _1
  50889 	}
  50890 	VP8LDspInit_body(tls)
  50891 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  50892 	goto _2
  50893 _2:
  50894 	;
  50895 	goto _1
  50896 _1: /**/ //
  50897 }
  50898 
  50899 var VP8LDspInit_body_last_cpuinfo_used = uintptr(0)
  50900 
  50901 func init() {
  50902 	p := unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used)
  50903 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LDspInit_body_last_cpuinfo_used))
  50904 }
  50905 
  50906 func VP8LDspInit_body(tls *libc.TLS) {
  50907 	VP8LPredictors[0] = __ccgo_fp(VP8LPredictor0_C)
  50908 	VP8LPredictors[int32(1)] = __ccgo_fp(VP8LPredictor1_C)
  50909 	VP8LPredictors[int32(2)] = __ccgo_fp(VP8LPredictor2_C)
  50910 	VP8LPredictors[int32(3)] = __ccgo_fp(VP8LPredictor3_C)
  50911 	VP8LPredictors[int32(4)] = __ccgo_fp(VP8LPredictor4_C)
  50912 	VP8LPredictors[int32(5)] = __ccgo_fp(VP8LPredictor5_C)
  50913 	VP8LPredictors[int32(6)] = __ccgo_fp(VP8LPredictor6_C)
  50914 	VP8LPredictors[int32(7)] = __ccgo_fp(VP8LPredictor7_C)
  50915 	VP8LPredictors[int32(8)] = __ccgo_fp(VP8LPredictor8_C)
  50916 	VP8LPredictors[int32(9)] = __ccgo_fp(VP8LPredictor9_C)
  50917 	VP8LPredictors[int32(10)] = __ccgo_fp(VP8LPredictor10_C)
  50918 	VP8LPredictors[int32(11)] = __ccgo_fp(VP8LPredictor11_C)
  50919 	VP8LPredictors[int32(12)] = __ccgo_fp(VP8LPredictor12_C)
  50920 	VP8LPredictors[int32(13)] = __ccgo_fp(VP8LPredictor13_C)
  50921 	VP8LPredictors[int32(14)] = __ccgo_fp(VP8LPredictor0_C) /* <- padding security sentinels*/
  50922 	VP8LPredictors[int32(15)] = __ccgo_fp(VP8LPredictor0_C)
  50923 	VP8LPredictorsAdd[0] = __ccgo_fp(PredictorAdd0_C)
  50924 	VP8LPredictorsAdd[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  50925 	VP8LPredictorsAdd[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  50926 	VP8LPredictorsAdd[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  50927 	VP8LPredictorsAdd[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  50928 	VP8LPredictorsAdd[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  50929 	VP8LPredictorsAdd[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  50930 	VP8LPredictorsAdd[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  50931 	VP8LPredictorsAdd[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  50932 	VP8LPredictorsAdd[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  50933 	VP8LPredictorsAdd[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  50934 	VP8LPredictorsAdd[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  50935 	VP8LPredictorsAdd[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  50936 	VP8LPredictorsAdd[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  50937 	VP8LPredictorsAdd[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  50938 	VP8LPredictorsAdd[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  50939 	VP8LPredictorsAdd_C[0] = __ccgo_fp(PredictorAdd0_C)
  50940 	VP8LPredictorsAdd_C[int32(1)] = __ccgo_fp(PredictorAdd1_C)
  50941 	VP8LPredictorsAdd_C[int32(2)] = __ccgo_fp(PredictorAdd2_C)
  50942 	VP8LPredictorsAdd_C[int32(3)] = __ccgo_fp(PredictorAdd3_C)
  50943 	VP8LPredictorsAdd_C[int32(4)] = __ccgo_fp(PredictorAdd4_C)
  50944 	VP8LPredictorsAdd_C[int32(5)] = __ccgo_fp(PredictorAdd5_C)
  50945 	VP8LPredictorsAdd_C[int32(6)] = __ccgo_fp(PredictorAdd6_C)
  50946 	VP8LPredictorsAdd_C[int32(7)] = __ccgo_fp(PredictorAdd7_C)
  50947 	VP8LPredictorsAdd_C[int32(8)] = __ccgo_fp(PredictorAdd8_C)
  50948 	VP8LPredictorsAdd_C[int32(9)] = __ccgo_fp(PredictorAdd9_C)
  50949 	VP8LPredictorsAdd_C[int32(10)] = __ccgo_fp(PredictorAdd10_C)
  50950 	VP8LPredictorsAdd_C[int32(11)] = __ccgo_fp(PredictorAdd11_C)
  50951 	VP8LPredictorsAdd_C[int32(12)] = __ccgo_fp(PredictorAdd12_C)
  50952 	VP8LPredictorsAdd_C[int32(13)] = __ccgo_fp(PredictorAdd13_C)
  50953 	VP8LPredictorsAdd_C[int32(14)] = __ccgo_fp(PredictorAdd0_C) /* <- padding security sentinels*/
  50954 	VP8LPredictorsAdd_C[int32(15)] = __ccgo_fp(PredictorAdd0_C)
  50955 	VP8LAddGreenToBlueAndRed = __ccgo_fp(VP8LAddGreenToBlueAndRed_C)
  50956 	VP8LTransformColorInverse = __ccgo_fp(VP8LTransformColorInverse_C)
  50957 	VP8LConvertBGRAToRGBA = __ccgo_fp(VP8LConvertBGRAToRGBA_C)
  50958 	VP8LConvertBGRAToRGB = __ccgo_fp(VP8LConvertBGRAToRGB_C)
  50959 	VP8LConvertBGRAToBGR = __ccgo_fp(VP8LConvertBGRAToBGR_C)
  50960 	VP8LConvertBGRAToRGBA4444 = __ccgo_fp(VP8LConvertBGRAToRGBA4444_C)
  50961 	VP8LConvertBGRAToRGB565 = __ccgo_fp(VP8LConvertBGRAToRGB565_C)
  50962 	VP8LMapColor32b = __ccgo_fp(MapARGB_C)
  50963 	VP8LMapColor8b = __ccgo_fp(MapAlpha_C)
  50964 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  50965 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  50966 	}
  50967 }
  50968 
  50969 func VP8LEncDspInitAVX2(tls *libc.TLS) {
  50970 }
  50971 
  50972 const LOG_2_RECIPROCAL_FIXED_DOUBLE1 = 1.2102203161561485e+07
  50973 
  50974 func FastSLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint64_t) {
  50975 	var correction, log_cnt, orig_v uint64_t
  50976 	var y uint32_t
  50977 	var v1 int32
  50978 	_, _, _, _, _ = correction, log_cnt, orig_v, y, v1
  50979 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  50980 		orig_v = uint64(v)
  50981 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  50982 		goto _2
  50983 	_2:
  50984 		// use clz if available
  50985 		log_cnt = libc.Uint64FromInt32(v1 - int32(7))
  50986 		y = libc.Uint32FromInt32(int32(1) << log_cnt)
  50987 		v = uint32(uint64(v) >> log_cnt)
  50988 		// vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256
  50989 		// Xf = floor(Xf) * (1 + (v % y) / v)
  50990 		// log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v)
  50991 		// The correction factor: log(1 + d) ~ d; for very small d values, so
  50992 		// log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
  50993 		correction = libc.Uint64FromInt32(12102203) * (orig_v & uint64(y-libc.Uint32FromInt32(1)))
  50994 		return orig_v*(uint64(kLog2Table[v])+log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)) + correction
  50995 	} else {
  50996 		return uint64(float64(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*float64(v))*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  50997 	}
  50998 	return r
  50999 }
  51000 
  51001 func FastLog2Slow_C(tls *libc.TLS, v uint32_t) (r uint32_t) {
  51002 	var correction uint64_t
  51003 	var log_2, log_cnt, orig_v, y uint32_t
  51004 	var v1 int32
  51005 	var v3, v4, v5 int64_t
  51006 	var v7 int64
  51007 	_, _, _, _, _, _, _, _, _, _ = correction, log_2, log_cnt, orig_v, y, v1, v3, v4, v5, v7
  51008 	if v < uint32(APPROX_LOG_WITH_CORRECTION_MAX) {
  51009 		orig_v = v
  51010 		v1 = int32(31) ^ libc.X__builtin_clz(tls, v)
  51011 		goto _2
  51012 	_2:
  51013 		// use clz if available
  51014 		log_cnt = libc.Uint32FromInt32(v1 - int32(7))
  51015 		y = libc.Uint32FromInt32(int32(1) << log_cnt)
  51016 		v = v >> log_cnt
  51017 		log_2 = kLog2Table[v] + log_cnt<<libc.Int32FromInt32(LOG_2_PRECISION_BITS)
  51018 		if orig_v >= uint32(APPROX_LOG_MAX) {
  51019 			// Since the division is still expensive, add this correction factor only
  51020 			// for large values of 'v'.
  51021 			correction = libc.Uint64FromInt32(12102203) * uint64(orig_v&(y-libc.Uint32FromInt32(1)))
  51022 			v3 = libc.Int64FromUint64(correction)
  51023 			v4 = libc.Int64FromUint32(orig_v)
  51024 			if libc.BoolInt32(v3 < 0) == libc.BoolInt32(v4 < 0) {
  51025 				v7 = (v3 + v4/int64(2)) / v4
  51026 			} else {
  51027 				v7 = (v3 - v4/int64(2)) / v4
  51028 			}
  51029 			v5 = v7
  51030 			goto _6
  51031 		_6:
  51032 			log_2 = log_2 + libc.Uint32FromInt64(v5)
  51033 		}
  51034 		return log_2
  51035 	} else {
  51036 		return uint32(float64(libc.Float64FromFloat64(1.2102203161561485e+07)*libc.Xlog(tls, float64(v))) + libc.Float64FromFloat64(0.5))
  51037 	}
  51038 	return r
  51039 }
  51040 
  51041 //------------------------------------------------------------------------------
  51042 // Methods to calculate Entropy (Shannon).
  51043 
  51044 // C documentation
  51045 //
  51046 //	// Compute the combined Shanon's entropy for distribution {X} and {X+Y}
  51047 func CombinedShannonEntropy_C(tls *libc.TLS, X uintptr, Y uintptr) (r uint64_t) {
  51048 	var i int32
  51049 	var retval, v3, v7 uint64_t
  51050 	var sumX, sumXY, x, xy, v2, v6 uint32_t
  51051 	var v5, v9 uint64
  51052 	_, _, _, _, _, _, _, _, _, _, _, _ = i, retval, sumX, sumXY, x, xy, v2, v3, v5, v6, v7, v9
  51053 	retval = uint64(0)
  51054 	sumX = uint32(0)
  51055 	sumXY = uint32(0)
  51056 	i = 0
  51057 	for {
  51058 		if !(i < int32(256)) {
  51059 			break
  51060 		}
  51061 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51062 		if x != uint32(0) {
  51063 			xy = x + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51064 			sumX = sumX + x
  51065 			v2 = x
  51066 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51067 				v5 = kSLog2Table[v2]
  51068 			} else {
  51069 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51070 			}
  51071 			v3 = v5
  51072 			goto _4
  51073 		_4:
  51074 			retval = retval + v3
  51075 			sumXY = sumXY + xy
  51076 			v2 = xy
  51077 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51078 				v5 = kSLog2Table[v2]
  51079 			} else {
  51080 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51081 			}
  51082 			v3 = v5
  51083 			goto _8
  51084 		_8:
  51085 			retval = retval + v3
  51086 		} else {
  51087 			if **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4)) != uint32(0) {
  51088 				sumXY = sumXY + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51089 				v2 = **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51090 				if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51091 					v5 = kSLog2Table[v2]
  51092 				} else {
  51093 					v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51094 				}
  51095 				v3 = v5
  51096 				goto _12
  51097 			_12:
  51098 				retval = retval + v3
  51099 			}
  51100 		}
  51101 		goto _1
  51102 	_1:
  51103 		;
  51104 		i = i + 1
  51105 	}
  51106 	v2 = sumX
  51107 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51108 		v5 = kSLog2Table[v2]
  51109 	} else {
  51110 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51111 	}
  51112 	v3 = v5
  51113 	goto _16
  51114 _16:
  51115 	v6 = sumXY
  51116 	if v6 < uint32(LOG_LOOKUP_IDX_MAX) {
  51117 		v9 = kSLog2Table[v6]
  51118 	} else {
  51119 		v9 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v6)
  51120 	}
  51121 	v7 = v9
  51122 	goto _20
  51123 _20:
  51124 	retval = v3 + v7 - retval
  51125 	return retval
  51126 }
  51127 
  51128 func ShannonEntropy_C(tls *libc.TLS, X uintptr, n int32) (r uint64_t) {
  51129 	var i, x int32
  51130 	var retval, v3 uint64_t
  51131 	var sumX, v2 uint32_t
  51132 	var v5 uint64
  51133 	_, _, _, _, _, _, _ = i, retval, sumX, x, v2, v3, v5
  51134 	retval = uint64(0)
  51135 	sumX = uint32(0)
  51136 	i = 0
  51137 	for {
  51138 		if !(i < n) {
  51139 			break
  51140 		}
  51141 		x = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(X + uintptr(i)*4)))
  51142 		if x != 0 {
  51143 			sumX = sumX + libc.Uint32FromInt32(x)
  51144 			v2 = libc.Uint32FromInt32(x)
  51145 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51146 				v5 = kSLog2Table[v2]
  51147 			} else {
  51148 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51149 			}
  51150 			v3 = v5
  51151 			goto _4
  51152 		_4:
  51153 			retval = retval + v3
  51154 		}
  51155 		goto _1
  51156 	_1:
  51157 		;
  51158 		i = i + 1
  51159 	}
  51160 	v2 = sumX
  51161 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51162 		v5 = kSLog2Table[v2]
  51163 	} else {
  51164 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51165 	}
  51166 	v3 = v5
  51167 	goto _8
  51168 _8:
  51169 	retval = v3 - retval
  51170 	return retval
  51171 }
  51172 
  51173 func VP8LBitEntropyInit(tls *libc.TLS, entropy uintptr) {
  51174 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = uint64(0)
  51175 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum = uint32(0)
  51176 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = 0
  51177 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = uint32(0)
  51178 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = uint32(libc.Uint16FromInt32(libc.Int32FromInt32(0xffff)))
  51179 }
  51180 
  51181 func VP8LBitsEntropyUnrefined(tls *libc.TLS, array uintptr, n int32, entropy uintptr) {
  51182 	var i int32
  51183 	var v2 uint32_t
  51184 	var v3 uint64_t
  51185 	var v5 uint64
  51186 	_, _, _, _ = i, v2, v3, v5
  51187 	VP8LBitEntropyInit(tls, entropy)
  51188 	i = 0
  51189 	for {
  51190 		if !(i < n) {
  51191 			break
  51192 		}
  51193 		if **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) != uint32(0) {
  51194 			**(**uint32_t)(__ccgo_up(entropy + 8)) += **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51195 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzero_code = libc.Uint32FromInt32(i)
  51196 			(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fnonzeros + 1
  51197 			v2 = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51198 			if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51199 				v5 = kSLog2Table[v2]
  51200 			} else {
  51201 				v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51202 			}
  51203 			v3 = v5
  51204 			goto _4
  51205 		_4:
  51206 			**(**uint64_t)(__ccgo_up(entropy)) += v3
  51207 			if (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(array + uintptr(i)*4)) {
  51208 				(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(array + uintptr(i)*4))
  51209 			}
  51210 		}
  51211 		goto _1
  51212 	_1:
  51213 		;
  51214 		i = i + 1
  51215 	}
  51216 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fsum
  51217 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51218 		v5 = kSLog2Table[v2]
  51219 	} else {
  51220 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51221 	}
  51222 	v3 = v5
  51223 	goto _8
  51224 _8:
  51225 	(*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(entropy)).Fentropy
  51226 }
  51227 
  51228 func GetEntropyUnrefinedHelper(tls *libc.TLS, val uint32_t, i int32, val_prev uintptr, i_prev uintptr, bit_entropy uintptr, stats uintptr) {
  51229 	var streak int32
  51230 	var v1 uint32_t
  51231 	var v2 uint64_t
  51232 	var v4 uint64
  51233 	_, _, _, _ = streak, v1, v2, v4
  51234 	streak = i - **(**int32)(__ccgo_up(i_prev))
  51235 	// Gather info for the bit entropy.
  51236 	if **(**uint32_t)(__ccgo_up(val_prev)) != uint32(0) {
  51237 		**(**uint32_t)(__ccgo_up(bit_entropy + 8)) += **(**uint32_t)(__ccgo_up(val_prev)) * libc.Uint32FromInt32(streak)
  51238 		**(**int32)(__ccgo_up(bit_entropy + 12)) += streak
  51239 		(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fnonzero_code = libc.Uint32FromInt32(**(**int32)(__ccgo_up(i_prev)))
  51240 		v1 = **(**uint32_t)(__ccgo_up(val_prev))
  51241 		if v1 < uint32(LOG_LOOKUP_IDX_MAX) {
  51242 			v4 = kSLog2Table[v1]
  51243 		} else {
  51244 			v4 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v1)
  51245 		}
  51246 		v2 = v4
  51247 		goto _3
  51248 	_3:
  51249 		**(**uint64_t)(__ccgo_up(bit_entropy)) += v2 * libc.Uint64FromInt32(streak)
  51250 		if (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val < **(**uint32_t)(__ccgo_up(val_prev)) {
  51251 			(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fmax_val = **(**uint32_t)(__ccgo_up(val_prev))
  51252 		}
  51253 	}
  51254 	// Gather info for the Huffman cost.
  51255 	**(**int32)(__ccgo_up(stats + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*4)) += libc.BoolInt32(streak > int32(3))
  51256 	**(**int32)(__ccgo_up(stats + 8 + libc.BoolUintptr(**(**uint32_t)(__ccgo_up(val_prev)) != uint32(0))*8 + libc.BoolUintptr(streak > libc.Int32FromInt32(3))*4)) += streak
  51257 	**(**uint32_t)(__ccgo_up(val_prev)) = val
  51258 	**(**int32)(__ccgo_up(i_prev)) = i
  51259 }
  51260 
  51261 func GetEntropyUnrefined_C(tls *libc.TLS, X uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51262 	bp := tls.Alloc(16)
  51263 	defer tls.Free(16)
  51264 	var i int32
  51265 	var x, v2 uint32_t
  51266 	var v3 uint64_t
  51267 	var v5 uint64
  51268 	var _ /* i_prev at bp+0 */ int32
  51269 	var _ /* x_prev at bp+4 */ uint32_t
  51270 	_, _, _, _, _ = i, x, v2, v3, v5
  51271 	**(**int32)(__ccgo_up(bp)) = 0
  51272 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X))
  51273 	libc.Xmemset(tls, stats, 0, uint64(24))
  51274 	VP8LBitEntropyInit(tls, bit_entropy)
  51275 	i = int32(1)
  51276 	for {
  51277 		if !(i < length) {
  51278 			break
  51279 		}
  51280 		x = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4))
  51281 		if x != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51282 			GetEntropyUnrefinedHelper(tls, x, i, bp+4, bp, bit_entropy, stats)
  51283 		}
  51284 		goto _1
  51285 	_1:
  51286 		;
  51287 		i = i + 1
  51288 	}
  51289 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51290 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51291 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51292 		v5 = kSLog2Table[v2]
  51293 	} else {
  51294 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51295 	}
  51296 	v3 = v5
  51297 	goto _4
  51298 _4:
  51299 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51300 }
  51301 
  51302 func GetCombinedEntropyUnrefined_C(tls *libc.TLS, X uintptr, Y uintptr, length int32, bit_entropy uintptr, stats uintptr) {
  51303 	bp := tls.Alloc(16)
  51304 	defer tls.Free(16)
  51305 	var i int32
  51306 	var xy, v2 uint32_t
  51307 	var v3 uint64_t
  51308 	var v5 uint64
  51309 	var _ /* i_prev at bp+0 */ int32
  51310 	var _ /* xy_prev at bp+4 */ uint32_t
  51311 	_, _, _, _, _ = i, xy, v2, v3, v5
  51312 	i = int32(1)
  51313 	**(**int32)(__ccgo_up(bp)) = 0
  51314 	**(**uint32_t)(__ccgo_up(bp + 4)) = **(**uint32_t)(__ccgo_up(X)) + **(**uint32_t)(__ccgo_up(Y))
  51315 	libc.Xmemset(tls, stats, 0, uint64(24))
  51316 	VP8LBitEntropyInit(tls, bit_entropy)
  51317 	i = int32(1)
  51318 	for {
  51319 		if !(i < length) {
  51320 			break
  51321 		}
  51322 		xy = **(**uint32_t)(__ccgo_up(X + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(Y + uintptr(i)*4))
  51323 		if xy != **(**uint32_t)(__ccgo_up(bp + 4)) {
  51324 			GetEntropyUnrefinedHelper(tls, xy, i, bp+4, bp, bit_entropy, stats)
  51325 		}
  51326 		goto _1
  51327 	_1:
  51328 		;
  51329 		i = i + 1
  51330 	}
  51331 	GetEntropyUnrefinedHelper(tls, uint32(0), i, bp+4, bp, bit_entropy, stats)
  51332 	v2 = (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fsum
  51333 	if v2 < uint32(LOG_LOOKUP_IDX_MAX) {
  51334 		v5 = kSLog2Table[v2]
  51335 	} else {
  51336 		v5 = (*(*func(*libc.TLS, uint32_t) uint64_t)(unsafe.Pointer(&struct{ uintptr }{VP8LFastSLog2Slow})))(tls, v2)
  51337 	}
  51338 	v3 = v5
  51339 	goto _4
  51340 _4:
  51341 	(*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy = v3 - (*VP8LBitEntropy)(unsafe.Pointer(bit_entropy)).Fentropy
  51342 }
  51343 
  51344 //------------------------------------------------------------------------------
  51345 
  51346 func VP8LSubtractGreenFromBlueAndRed_C(tls *libc.TLS, argb_data uintptr, num_pixels int32) {
  51347 	var argb, green, i int32
  51348 	var new_b, new_r uint32_t
  51349 	_, _, _, _, _ = argb, green, i, new_b, new_r
  51350 	i = 0
  51351 	for {
  51352 		if !(i < num_pixels) {
  51353 			break
  51354 		}
  51355 		argb = libc.Int32FromUint32(**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)))
  51356 		green = argb >> libc.Int32FromInt32(8) & int32(0xff)
  51357 		new_r = libc.Uint32FromInt32((argb>>libc.Int32FromInt32(16)&int32(0xff) - green) & int32(0xff))
  51358 		new_b = libc.Uint32FromInt32((argb>>libc.Int32FromInt32(0)&int32(0xff) - green) & int32(0xff))
  51359 		**(**uint32_t)(__ccgo_up(argb_data + uintptr(i)*4)) = libc.Uint32FromInt32(argb)&uint32(0xff00ff00) | new_r<<libc.Int32FromInt32(16) | new_b
  51360 		goto _1
  51361 	_1:
  51362 		;
  51363 		i = i + 1
  51364 	}
  51365 }
  51366 
  51367 func ColorTransformDelta1(tls *libc.TLS, color_pred int8_t, color int8_t) (r int32) {
  51368 	return int32(color_pred) * int32(color) >> int32(5)
  51369 }
  51370 
  51371 func U32ToS8(tls *libc.TLS, v uint32_t) (r int8_t) {
  51372 	return libc.Int8FromUint32(v & libc.Uint32FromInt32(0xff))
  51373 }
  51374 
  51375 func VP8LTransformColor_C(tls *libc.TLS, m uintptr, data uintptr, num_pixels int32) {
  51376 	var argb uint32_t
  51377 	var green, red int8_t
  51378 	var i, new_blue, new_red int32
  51379 	_, _, _, _, _, _ = argb, green, i, new_blue, new_red, red
  51380 	i = 0
  51381 	for {
  51382 		if !(i < num_pixels) {
  51383 			break
  51384 		}
  51385 		argb = **(**uint32_t)(__ccgo_up(data + uintptr(i)*4))
  51386 		green = U32ToS8(tls, argb>>int32(8))
  51387 		red = U32ToS8(tls, argb>>int32(16))
  51388 		new_red = int32(red) & int32(0xff)
  51389 		new_blue = libc.Int32FromUint32(argb & uint32(0xff))
  51390 		new_red = new_red - ColorTransformDelta1(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_red), green)
  51391 		new_red = new_red & int32(0xff)
  51392 		new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fgreen_to_blue), green)
  51393 		new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8((*VP8LMultipliers)(unsafe.Pointer(m)).Fred_to_blue), red)
  51394 		new_blue = new_blue & int32(0xff)
  51395 		**(**uint32_t)(__ccgo_up(data + uintptr(i)*4)) = argb&uint32(0xff00ff00) | libc.Uint32FromInt32(new_red<<libc.Int32FromInt32(16)) | libc.Uint32FromInt32(new_blue)
  51396 		goto _1
  51397 	_1:
  51398 		;
  51399 		i = i + 1
  51400 	}
  51401 }
  51402 
  51403 func TransformColorRed(tls *libc.TLS, green_to_red uint8_t, argb uint32_t) (r uint8_t) {
  51404 	var green int8_t
  51405 	var new_red int32
  51406 	_, _ = green, new_red
  51407 	green = U32ToS8(tls, argb>>int32(8))
  51408 	new_red = libc.Int32FromUint32(argb >> int32(16))
  51409 	new_red = new_red - ColorTransformDelta1(tls, libc.Int8FromUint8(green_to_red), green)
  51410 	return libc.Uint8FromInt32(new_red & libc.Int32FromInt32(0xff))
  51411 }
  51412 
  51413 func TransformColorBlue(tls *libc.TLS, green_to_blue uint8_t, red_to_blue uint8_t, argb uint32_t) (r uint8_t) {
  51414 	var green, red int8_t
  51415 	var new_blue int32
  51416 	_, _, _ = green, new_blue, red
  51417 	green = U32ToS8(tls, argb>>int32(8))
  51418 	red = U32ToS8(tls, argb>>int32(16))
  51419 	new_blue = libc.Int32FromUint32(argb & uint32(0xff))
  51420 	new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8(green_to_blue), green)
  51421 	new_blue = new_blue - ColorTransformDelta1(tls, libc.Int8FromUint8(red_to_blue), red)
  51422 	return libc.Uint8FromInt32(new_blue & libc.Int32FromInt32(0xff))
  51423 }
  51424 
  51425 func VP8LCollectColorRedTransforms_C(tls *libc.TLS, argb uintptr, stride int32, tile_width int32, tile_height int32, green_to_red int32, histo uintptr) {
  51426 	var x, v1 int32
  51427 	_, _ = x, v1
  51428 	for {
  51429 		v1 = tile_height
  51430 		tile_height = tile_height - 1
  51431 		if !(v1 > 0) {
  51432 			break
  51433 		}
  51434 		x = 0
  51435 		for {
  51436 			if !(x < tile_width) {
  51437 				break
  51438 			}
  51439 			**(**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
  51440 			goto _2
  51441 		_2:
  51442 			;
  51443 			x = x + 1
  51444 		}
  51445 		argb = argb + uintptr(stride)*4
  51446 	}
  51447 }
  51448 
  51449 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) {
  51450 	var x, v1 int32
  51451 	_, _ = x, v1
  51452 	for {
  51453 		v1 = tile_height
  51454 		tile_height = tile_height - 1
  51455 		if !(v1 > 0) {
  51456 			break
  51457 		}
  51458 		x = 0
  51459 		for {
  51460 			if !(x < tile_width) {
  51461 				break
  51462 			}
  51463 			**(**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
  51464 			goto _2
  51465 		_2:
  51466 			;
  51467 			x = x + 1
  51468 		}
  51469 		argb = argb + uintptr(stride)*4
  51470 	}
  51471 }
  51472 
  51473 //------------------------------------------------------------------------------
  51474 
  51475 func VectorMismatch_C(tls *libc.TLS, array1 uintptr, array2 uintptr, length int32) (r int32) {
  51476 	var match_len int32
  51477 	_ = match_len
  51478 	match_len = 0
  51479 	for match_len < length && **(**uint32_t)(__ccgo_up(array1 + uintptr(match_len)*4)) == **(**uint32_t)(__ccgo_up(array2 + uintptr(match_len)*4)) {
  51480 		match_len = match_len + 1
  51481 	}
  51482 	return match_len
  51483 }
  51484 
  51485 // C documentation
  51486 //
  51487 //	// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
  51488 func VP8LBundleColorMap_C(tls *libc.TLS, row uintptr, width int32, xbits int32, dst uintptr) {
  51489 	var bit_depth, mask, x, xsub int32
  51490 	var code uint32_t
  51491 	_, _, _, _, _ = bit_depth, code, mask, x, xsub
  51492 	if xbits > 0 {
  51493 		bit_depth = int32(1) << (int32(3) - xbits)
  51494 		mask = int32(1)<<xbits - int32(1)
  51495 		code = uint32(0xff000000)
  51496 		x = 0
  51497 		for {
  51498 			if !(x < width) {
  51499 				break
  51500 			}
  51501 			xsub = x & mask
  51502 			if xsub == 0 {
  51503 				code = uint32(0xff000000)
  51504 			}
  51505 			code = code | libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<(int32(8)+bit_depth*xsub))
  51506 			**(**uint32_t)(__ccgo_up(dst + uintptr(x>>xbits)*4)) = code
  51507 			goto _1
  51508 		_1:
  51509 			;
  51510 			x = x + 1
  51511 		}
  51512 	} else {
  51513 		x = 0
  51514 		for {
  51515 			if !(x < width) {
  51516 				break
  51517 			}
  51518 			**(**uint32_t)(__ccgo_up(dst + uintptr(x)*4)) = uint32(0xff000000) | libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(row + uintptr(x))))<<libc.Int32FromInt32(8))
  51519 			goto _2
  51520 		_2:
  51521 			;
  51522 			x = x + 1
  51523 		}
  51524 	}
  51525 }
  51526 
  51527 //------------------------------------------------------------------------------
  51528 
  51529 func ExtraCost_C(tls *libc.TLS, population uintptr, length int32) (r uint32_t) {
  51530 	var cost uint32_t
  51531 	var i int32
  51532 	_, _ = cost, i
  51533 	cost = **(**uint32_t)(__ccgo_up(population + 4*4)) + **(**uint32_t)(__ccgo_up(population + 5*4))
  51534 	i = int32(2)
  51535 	for {
  51536 		if !(i < length/int32(2)-int32(1)) {
  51537 			break
  51538 		}
  51539 		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)))
  51540 		goto _1
  51541 	_1:
  51542 		;
  51543 		i = i + 1
  51544 	}
  51545 	return cost
  51546 }
  51547 
  51548 //------------------------------------------------------------------------------
  51549 
  51550 func AddVector_C(tls *libc.TLS, a uintptr, b uintptr, out uintptr, size int32) {
  51551 	var i int32
  51552 	_ = i
  51553 	i = 0
  51554 	for {
  51555 		if !(i < size) {
  51556 			break
  51557 		}
  51558 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = **(**uint32_t)(__ccgo_up(a + uintptr(i)*4)) + **(**uint32_t)(__ccgo_up(b + uintptr(i)*4))
  51559 		goto _1
  51560 	_1:
  51561 		;
  51562 		i = i + 1
  51563 	}
  51564 }
  51565 
  51566 func AddVectorEq_C(tls *libc.TLS, a uintptr, out uintptr, size int32) {
  51567 	var i int32
  51568 	_ = i
  51569 	i = 0
  51570 	for {
  51571 		if !(i < size) {
  51572 			break
  51573 		}
  51574 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) += **(**uint32_t)(__ccgo_up(a + uintptr(i)*4))
  51575 		goto _1
  51576 	_1:
  51577 		;
  51578 		i = i + 1
  51579 	}
  51580 }
  51581 
  51582 //------------------------------------------------------------------------------
  51583 // Image transforms.
  51584 
  51585 func PredictorSub0_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51586 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51587 	var i int32
  51588 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51589 	i = 0
  51590 	for {
  51591 		if !(i < num_pixels) {
  51592 			break
  51593 		}
  51594 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51595 		v3 = uint32(ARGB_BLACK3)
  51596 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51597 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51598 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51599 		goto _5
  51600 	_5:
  51601 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51602 		goto _1
  51603 	_1:
  51604 		;
  51605 		i = i + 1
  51606 	}
  51607 	_ = upper
  51608 }
  51609 
  51610 func PredictorSub1_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51611 	var alpha_and_green, red_and_blue, v2, v3, v4 uint32_t
  51612 	var i int32
  51613 	_, _, _, _, _, _ = alpha_and_green, i, red_and_blue, v2, v3, v4
  51614 	i = 0
  51615 	for {
  51616 		if !(i < num_pixels) {
  51617 			break
  51618 		}
  51619 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(i)*4))
  51620 		v3 = **(**uint32_t)(__ccgo_up(in + uintptr(i-int32(1))*4))
  51621 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51622 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51623 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51624 		goto _5
  51625 	_5:
  51626 		**(**uint32_t)(__ccgo_up(out + uintptr(i)*4)) = v4
  51627 		goto _1
  51628 	_1:
  51629 		;
  51630 		i = i + 1
  51631 	}
  51632 	_ = upper
  51633 }
  51634 
  51635 // It subtracts the prediction from the input pixel and stores the residual
  51636 // in the output pixel.
  51637 func PredictorSub2_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51638 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51639 	var x int32
  51640 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51641 	x = 0
  51642 	for {
  51643 		if !(x < num_pixels) {
  51644 			break
  51645 		}
  51646 		pred = VP8LPredictor2_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51647 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51648 		v3 = pred
  51649 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51650 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51651 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51652 		goto _5
  51653 	_5:
  51654 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51655 		goto _1
  51656 	_1:
  51657 		;
  51658 		x = x + 1
  51659 	}
  51660 }
  51661 
  51662 func PredictorSub3_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51663 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51664 	var x int32
  51665 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51666 	x = 0
  51667 	for {
  51668 		if !(x < num_pixels) {
  51669 			break
  51670 		}
  51671 		pred = VP8LPredictor3_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51672 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51673 		v3 = pred
  51674 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51675 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51676 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51677 		goto _5
  51678 	_5:
  51679 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51680 		goto _1
  51681 	_1:
  51682 		;
  51683 		x = x + 1
  51684 	}
  51685 }
  51686 
  51687 func PredictorSub4_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51688 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51689 	var x int32
  51690 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51691 	x = 0
  51692 	for {
  51693 		if !(x < num_pixels) {
  51694 			break
  51695 		}
  51696 		pred = VP8LPredictor4_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51697 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51698 		v3 = pred
  51699 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51700 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51701 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51702 		goto _5
  51703 	_5:
  51704 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51705 		goto _1
  51706 	_1:
  51707 		;
  51708 		x = x + 1
  51709 	}
  51710 }
  51711 
  51712 func PredictorSub5_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51713 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51714 	var x int32
  51715 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51716 	x = 0
  51717 	for {
  51718 		if !(x < num_pixels) {
  51719 			break
  51720 		}
  51721 		pred = VP8LPredictor5_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51722 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51723 		v3 = pred
  51724 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51725 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51726 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51727 		goto _5
  51728 	_5:
  51729 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51730 		goto _1
  51731 	_1:
  51732 		;
  51733 		x = x + 1
  51734 	}
  51735 }
  51736 
  51737 func PredictorSub6_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51738 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51739 	var x int32
  51740 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51741 	x = 0
  51742 	for {
  51743 		if !(x < num_pixels) {
  51744 			break
  51745 		}
  51746 		pred = VP8LPredictor6_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51747 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51748 		v3 = pred
  51749 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51750 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51751 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51752 		goto _5
  51753 	_5:
  51754 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51755 		goto _1
  51756 	_1:
  51757 		;
  51758 		x = x + 1
  51759 	}
  51760 }
  51761 
  51762 func PredictorSub7_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51763 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51764 	var x int32
  51765 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51766 	x = 0
  51767 	for {
  51768 		if !(x < num_pixels) {
  51769 			break
  51770 		}
  51771 		pred = VP8LPredictor7_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51772 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51773 		v3 = pred
  51774 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51775 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51776 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51777 		goto _5
  51778 	_5:
  51779 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51780 		goto _1
  51781 	_1:
  51782 		;
  51783 		x = x + 1
  51784 	}
  51785 }
  51786 
  51787 func PredictorSub8_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51788 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51789 	var x int32
  51790 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51791 	x = 0
  51792 	for {
  51793 		if !(x < num_pixels) {
  51794 			break
  51795 		}
  51796 		pred = VP8LPredictor8_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51797 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51798 		v3 = pred
  51799 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51800 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51801 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51802 		goto _5
  51803 	_5:
  51804 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51805 		goto _1
  51806 	_1:
  51807 		;
  51808 		x = x + 1
  51809 	}
  51810 }
  51811 
  51812 func PredictorSub9_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51813 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51814 	var x int32
  51815 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51816 	x = 0
  51817 	for {
  51818 		if !(x < num_pixels) {
  51819 			break
  51820 		}
  51821 		pred = VP8LPredictor9_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51822 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51823 		v3 = pred
  51824 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51825 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51826 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51827 		goto _5
  51828 	_5:
  51829 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51830 		goto _1
  51831 	_1:
  51832 		;
  51833 		x = x + 1
  51834 	}
  51835 }
  51836 
  51837 func PredictorSub10_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51838 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51839 	var x int32
  51840 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51841 	x = 0
  51842 	for {
  51843 		if !(x < num_pixels) {
  51844 			break
  51845 		}
  51846 		pred = VP8LPredictor10_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51847 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51848 		v3 = pred
  51849 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51850 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51851 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51852 		goto _5
  51853 	_5:
  51854 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51855 		goto _1
  51856 	_1:
  51857 		;
  51858 		x = x + 1
  51859 	}
  51860 }
  51861 
  51862 func PredictorSub11_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51863 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51864 	var x int32
  51865 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51866 	x = 0
  51867 	for {
  51868 		if !(x < num_pixels) {
  51869 			break
  51870 		}
  51871 		pred = VP8LPredictor11_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51872 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51873 		v3 = pred
  51874 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51875 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51876 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51877 		goto _5
  51878 	_5:
  51879 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51880 		goto _1
  51881 	_1:
  51882 		;
  51883 		x = x + 1
  51884 	}
  51885 }
  51886 
  51887 func PredictorSub12_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51888 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51889 	var x int32
  51890 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51891 	x = 0
  51892 	for {
  51893 		if !(x < num_pixels) {
  51894 			break
  51895 		}
  51896 		pred = VP8LPredictor12_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51897 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51898 		v3 = pred
  51899 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51900 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51901 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51902 		goto _5
  51903 	_5:
  51904 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51905 		goto _1
  51906 	_1:
  51907 		;
  51908 		x = x + 1
  51909 	}
  51910 }
  51911 
  51912 func PredictorSub13_C(tls *libc.TLS, in uintptr, upper uintptr, num_pixels int32, out uintptr) {
  51913 	var alpha_and_green, pred, red_and_blue, v2, v3, v4 uint32_t
  51914 	var x int32
  51915 	_, _, _, _, _, _, _ = alpha_and_green, pred, red_and_blue, x, v2, v3, v4
  51916 	x = 0
  51917 	for {
  51918 		if !(x < num_pixels) {
  51919 			break
  51920 		}
  51921 		pred = VP8LPredictor13_C(tls, in+uintptr(x-int32(1))*4, upper+uintptr(x)*4)
  51922 		v2 = **(**uint32_t)(__ccgo_up(in + uintptr(x)*4))
  51923 		v3 = pred
  51924 		alpha_and_green = uint32(0x00ff00ff) + v2&uint32(0xff00ff00) - v3&uint32(0xff00ff00)
  51925 		red_and_blue = uint32(0xff00ff00) + v2&uint32(0x00ff00ff) - v3&uint32(0x00ff00ff)
  51926 		v4 = alpha_and_green&uint32(0xff00ff00) | red_and_blue&uint32(0x00ff00ff)
  51927 		goto _5
  51928 	_5:
  51929 		**(**uint32_t)(__ccgo_up(out + uintptr(x)*4)) = v4
  51930 		goto _1
  51931 	_1:
  51932 		;
  51933 		x = x + 1
  51934 	}
  51935 }
  51936 
  51937 func VP8LEncDspInit(tls *libc.TLS) {
  51938 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  51939 		goto _1
  51940 	}
  51941 	VP8LEncDspInit_body(tls)
  51942 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  51943 	goto _2
  51944 _2:
  51945 	;
  51946 	goto _1
  51947 _1: /**/ //
  51948 }
  51949 
  51950 var VP8LEncDspInit_body_last_cpuinfo_used = uintptr(0)
  51951 
  51952 func init() {
  51953 	p := unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used)
  51954 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8LEncDspInit_body_last_cpuinfo_used))
  51955 }
  51956 
  51957 func VP8LEncDspInit_body(tls *libc.TLS) {
  51958 	VP8LDspInit(tls)
  51959 	VP8LSubtractGreenFromBlueAndRed = __ccgo_fp(VP8LSubtractGreenFromBlueAndRed_C)
  51960 	VP8LTransformColor = __ccgo_fp(VP8LTransformColor_C)
  51961 	VP8LCollectColorBlueTransforms = __ccgo_fp(VP8LCollectColorBlueTransforms_C)
  51962 	VP8LCollectColorRedTransforms = __ccgo_fp(VP8LCollectColorRedTransforms_C)
  51963 	VP8LFastLog2Slow = __ccgo_fp(FastLog2Slow_C)
  51964 	VP8LFastSLog2Slow = __ccgo_fp(FastSLog2Slow_C)
  51965 	VP8LExtraCost = __ccgo_fp(ExtraCost_C)
  51966 	VP8LCombinedShannonEntropy = __ccgo_fp(CombinedShannonEntropy_C)
  51967 	VP8LShannonEntropy = __ccgo_fp(ShannonEntropy_C)
  51968 	VP8LGetEntropyUnrefined = __ccgo_fp(GetEntropyUnrefined_C)
  51969 	VP8LGetCombinedEntropyUnrefined = __ccgo_fp(GetCombinedEntropyUnrefined_C)
  51970 	VP8LAddVector = __ccgo_fp(AddVector_C)
  51971 	VP8LAddVectorEq = __ccgo_fp(AddVectorEq_C)
  51972 	VP8LVectorMismatch = __ccgo_fp(VectorMismatch_C)
  51973 	VP8LBundleColorMap = __ccgo_fp(VP8LBundleColorMap_C)
  51974 	VP8LPredictorsSub[0] = __ccgo_fp(PredictorSub0_C)
  51975 	VP8LPredictorsSub[int32(1)] = __ccgo_fp(PredictorSub1_C)
  51976 	VP8LPredictorsSub[int32(2)] = __ccgo_fp(PredictorSub2_C)
  51977 	VP8LPredictorsSub[int32(3)] = __ccgo_fp(PredictorSub3_C)
  51978 	VP8LPredictorsSub[int32(4)] = __ccgo_fp(PredictorSub4_C)
  51979 	VP8LPredictorsSub[int32(5)] = __ccgo_fp(PredictorSub5_C)
  51980 	VP8LPredictorsSub[int32(6)] = __ccgo_fp(PredictorSub6_C)
  51981 	VP8LPredictorsSub[int32(7)] = __ccgo_fp(PredictorSub7_C)
  51982 	VP8LPredictorsSub[int32(8)] = __ccgo_fp(PredictorSub8_C)
  51983 	VP8LPredictorsSub[int32(9)] = __ccgo_fp(PredictorSub9_C)
  51984 	VP8LPredictorsSub[int32(10)] = __ccgo_fp(PredictorSub10_C)
  51985 	VP8LPredictorsSub[int32(11)] = __ccgo_fp(PredictorSub11_C)
  51986 	VP8LPredictorsSub[int32(12)] = __ccgo_fp(PredictorSub12_C)
  51987 	VP8LPredictorsSub[int32(13)] = __ccgo_fp(PredictorSub13_C)
  51988 	VP8LPredictorsSub[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  51989 	VP8LPredictorsSub[int32(15)] = __ccgo_fp(PredictorSub0_C)
  51990 	VP8LPredictorsSub_C[0] = __ccgo_fp(PredictorSub0_C)
  51991 	VP8LPredictorsSub_C[int32(1)] = __ccgo_fp(PredictorSub1_C)
  51992 	VP8LPredictorsSub_C[int32(2)] = __ccgo_fp(PredictorSub2_C)
  51993 	VP8LPredictorsSub_C[int32(3)] = __ccgo_fp(PredictorSub3_C)
  51994 	VP8LPredictorsSub_C[int32(4)] = __ccgo_fp(PredictorSub4_C)
  51995 	VP8LPredictorsSub_C[int32(5)] = __ccgo_fp(PredictorSub5_C)
  51996 	VP8LPredictorsSub_C[int32(6)] = __ccgo_fp(PredictorSub6_C)
  51997 	VP8LPredictorsSub_C[int32(7)] = __ccgo_fp(PredictorSub7_C)
  51998 	VP8LPredictorsSub_C[int32(8)] = __ccgo_fp(PredictorSub8_C)
  51999 	VP8LPredictorsSub_C[int32(9)] = __ccgo_fp(PredictorSub9_C)
  52000 	VP8LPredictorsSub_C[int32(10)] = __ccgo_fp(PredictorSub10_C)
  52001 	VP8LPredictorsSub_C[int32(11)] = __ccgo_fp(PredictorSub11_C)
  52002 	VP8LPredictorsSub_C[int32(12)] = __ccgo_fp(PredictorSub12_C)
  52003 	VP8LPredictorsSub_C[int32(13)] = __ccgo_fp(PredictorSub13_C)
  52004 	VP8LPredictorsSub_C[int32(14)] = __ccgo_fp(PredictorSub0_C) // <- padding security sentinels
  52005 	VP8LPredictorsSub_C[int32(15)] = __ccgo_fp(PredictorSub0_C)
  52006 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  52007 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52008 	}
  52009 }
  52010 
  52011 const LOG_2_RECIPROCAL_FIXED_DOUBLE2 = 12102203.161561485379934310913085937500
  52012 
  52013 func VP8LEncDspInitMIPS32(tls *libc.TLS) {
  52014 }
  52015 
  52016 func VP8LEncDspInitMIPSdspR2(tls *libc.TLS) {
  52017 }
  52018 
  52019 func VP8LEncDspInitMSA(tls *libc.TLS) {
  52020 }
  52021 
  52022 func VP8LEncDspInitNEON(tls *libc.TLS) {
  52023 }
  52024 
  52025 func VP8LEncDspInitSSE2(tls *libc.TLS) {
  52026 }
  52027 
  52028 func VP8LEncDspInitSSE41(tls *libc.TLS) {
  52029 }
  52030 
  52031 func VP8LDspInitMIPSdspR2(tls *libc.TLS) {
  52032 }
  52033 
  52034 func VP8LDspInitMSA(tls *libc.TLS) {
  52035 }
  52036 
  52037 func VP8LDspInitNEON(tls *libc.TLS) {
  52038 }
  52039 
  52040 func VP8LDspInitSSE2(tls *libc.TLS) {
  52041 }
  52042 
  52043 func VP8LDspInitSSE41(tls *libc.TLS) {
  52044 }
  52045 
  52046 //------------------------------------------------------------------------------
  52047 
  52048 //------------------------------------------------------------------------------
  52049 // Implementations of critical functions ImportRow / ExportRow
  52050 
  52051 //------------------------------------------------------------------------------
  52052 // Row import
  52053 
  52054 func WebPRescalerImportRowExpand_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  52055 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  52056 	var left, right rescaler_t
  52057 	var v2 uint32
  52058 	_, _, _, _, _, _, _, _, _ = accum, channel, left, right, x_in, x_out, x_out_max, x_stride, v2
  52059 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52060 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52061 	channel = 0
  52062 	for {
  52063 		if !(channel < x_stride) {
  52064 			break
  52065 		}
  52066 		x_in = channel
  52067 		x_out = channel
  52068 		// simple bilinear interpolation
  52069 		accum = (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52070 		left = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52071 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fsrc_width > int32(1) {
  52072 			v2 = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in+x_stride))))
  52073 		} else {
  52074 			v2 = left
  52075 		}
  52076 		right = v2
  52077 		x_in = x_in + x_stride
  52078 		for int32(1) != 0 {
  52079 			**(**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)
  52080 			x_out = x_out + x_stride
  52081 			if x_out >= x_out_max {
  52082 				break
  52083 			}
  52084 			accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  52085 			if accum < 0 {
  52086 				left = right
  52087 				x_in = x_in + x_stride
  52088 				right = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52089 				accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52090 			}
  52091 		}
  52092 		goto _1
  52093 	_1:
  52094 		;
  52095 		channel = channel + 1
  52096 	}
  52097 }
  52098 
  52099 func WebPRescalerImportRowShrink_C(tls *libc.TLS, wrk uintptr, src uintptr) {
  52100 	var accum, channel, x_in, x_out, x_out_max, x_stride int32
  52101 	var base, sum uint32_t
  52102 	var frac rescaler_t
  52103 	_, _, _, _, _, _, _, _, _ = accum, base, channel, frac, sum, x_in, x_out, x_out_max, x_stride
  52104 	x_stride = (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52105 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52106 	channel = 0
  52107 	for {
  52108 		if !(channel < x_stride) {
  52109 			break
  52110 		}
  52111 		x_in = channel
  52112 		x_out = channel
  52113 		sum = uint32(0)
  52114 		accum = 0
  52115 		for x_out < x_out_max {
  52116 			base = uint32(0)
  52117 			accum = accum + (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_add
  52118 			for accum > 0 {
  52119 				accum = accum - (*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub
  52120 				base = uint32(**(**uint8_t)(__ccgo_up(src + uintptr(x_in))))
  52121 				sum = sum + base
  52122 				x_in = x_in + x_stride
  52123 			}
  52124 			// Emit next horizontal pixel.
  52125 			frac = base * libc.Uint32FromInt32(-accum)
  52126 			**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow + uintptr(x_out)*4)) = sum*libc.Uint32FromInt32((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_sub) - frac
  52127 			// fresh fractional start for next pixel
  52128 			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)))
  52129 			x_out = x_out + x_stride
  52130 		}
  52131 		goto _1
  52132 	_1:
  52133 		;
  52134 		channel = channel + 1
  52135 	}
  52136 }
  52137 
  52138 //------------------------------------------------------------------------------
  52139 // Row export
  52140 
  52141 func WebPRescalerExportRowExpand_C(tls *libc.TLS, wrk uintptr) {
  52142 	var A, B, J, J1 uint32_t
  52143 	var I uint64_t
  52144 	var dst, frow, irow uintptr
  52145 	var v, v1, x_out, x_out_max int32
  52146 	var v2 uint32
  52147 	_, _, _, _, _, _, _, _, _, _, _, _, _ = A, B, I, J, J1, dst, frow, irow, v, v1, x_out, x_out_max, v2
  52148 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52149 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52150 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52151 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52152 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum == 0 {
  52153 		x_out = 0
  52154 		for {
  52155 			if !(x_out < x_out_max) {
  52156 				break
  52157 			}
  52158 			J = **(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))
  52159 			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))
  52160 			if v > int32(255) {
  52161 				v2 = uint32(255)
  52162 			} else {
  52163 				v2 = uint32(libc.Uint8FromInt32(v))
  52164 			}
  52165 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52166 			goto _1
  52167 		_1:
  52168 			;
  52169 			x_out = x_out + 1
  52170 		}
  52171 	} else {
  52172 		B = uint32(libc.Uint64FromInt32(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum) << libc.Int32FromInt32(WEBP_RESCALER_RFIX) / libc.Uint64FromInt32((*WebPRescaler)(unsafe.Pointer(wrk)).Fy_sub))
  52173 		A = uint32(libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX) - uint64(B))
  52174 		x_out = 0
  52175 		for {
  52176 			if !(x_out < x_out_max) {
  52177 				break
  52178 			}
  52179 			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)))
  52180 			J1 = uint32((I + libc.Uint64FromUint64(1)<<libc.Int32FromInt32(WEBP_RESCALER_RFIX)>>libc.Int32FromInt32(1)) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52181 			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))
  52182 			if v1 > int32(255) {
  52183 				v2 = uint32(255)
  52184 			} else {
  52185 				v2 = uint32(libc.Uint8FromInt32(v1))
  52186 			}
  52187 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52188 			goto _3
  52189 		_3:
  52190 			;
  52191 			x_out = x_out + 1
  52192 		}
  52193 	}
  52194 }
  52195 
  52196 func WebPRescalerExportRowShrink_C(tls *libc.TLS, wrk uintptr) {
  52197 	var dst, frow, irow uintptr
  52198 	var frac, yscale uint32_t
  52199 	var v, v1, x_out, x_out_max int32
  52200 	var v2 uint32
  52201 	_, _, _, _, _, _, _, _, _, _ = dst, frac, frow, irow, v, v1, x_out, x_out_max, yscale, v2
  52202 	dst = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst
  52203 	irow = (*WebPRescaler)(unsafe.Pointer(wrk)).Firow
  52204 	x_out_max = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width * (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels
  52205 	frow = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffrow
  52206 	yscale = (*WebPRescaler)(unsafe.Pointer(wrk)).Ffy_scale * libc.Uint32FromInt32(-(*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum)
  52207 	if yscale != 0 {
  52208 		x_out = 0
  52209 		for {
  52210 			if !(x_out < x_out_max) {
  52211 				break
  52212 			}
  52213 			frac = uint32(uint64(**(**rescaler_t)(__ccgo_up(frow + uintptr(x_out)*4))) * uint64(yscale) >> libc.Int32FromInt32(WEBP_RESCALER_RFIX))
  52214 			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))
  52215 			if v > int32(255) {
  52216 				v2 = uint32(255)
  52217 			} else {
  52218 				v2 = uint32(libc.Uint8FromInt32(v))
  52219 			}
  52220 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52221 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = frac // new fractional start
  52222 			goto _1
  52223 		_1:
  52224 			;
  52225 			x_out = x_out + 1
  52226 		}
  52227 	} else {
  52228 		x_out = 0
  52229 		for {
  52230 			if !(x_out < x_out_max) {
  52231 				break
  52232 			}
  52233 			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))
  52234 			if v1 > int32(255) {
  52235 				v2 = uint32(255)
  52236 			} else {
  52237 				v2 = uint32(libc.Uint8FromInt32(v1))
  52238 			}
  52239 			**(**uint8_t)(__ccgo_up(dst + uintptr(x_out))) = uint8(v2)
  52240 			**(**rescaler_t)(__ccgo_up(irow + uintptr(x_out)*4)) = uint32(0)
  52241 			goto _3
  52242 		_3:
  52243 			;
  52244 			x_out = x_out + 1
  52245 		}
  52246 	}
  52247 }
  52248 
  52249 //------------------------------------------------------------------------------
  52250 // Main entry calls
  52251 
  52252 func WebPRescalerImportRow(tls *libc.TLS, wrk uintptr, src uintptr) {
  52253 	if !((*WebPRescaler)(unsafe.Pointer(wrk)).Fx_expand != 0) {
  52254 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowShrink})))(tls, wrk, src)
  52255 	} else {
  52256 		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerImportRowExpand})))(tls, wrk, src)
  52257 	}
  52258 }
  52259 
  52260 func WebPRescalerExportRow(tls *libc.TLS, wrk uintptr) {
  52261 	var i int32
  52262 	_ = i
  52263 	if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_accum <= 0 {
  52264 		if (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_expand != 0 {
  52265 			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowExpand})))(tls, wrk)
  52266 		} else {
  52267 			if (*WebPRescaler)(unsafe.Pointer(wrk)).Ffxy_scale != 0 {
  52268 				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{WebPRescalerExportRowShrink})))(tls, wrk)
  52269 			} else {
  52270 				i = 0
  52271 				for {
  52272 					if !(i < (*WebPRescaler)(unsafe.Pointer(wrk)).Fnum_channels*(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_width) {
  52273 						break
  52274 					}
  52275 					**(**uint8_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst + uintptr(i))) = uint8(**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)))
  52276 					**(**rescaler_t)(__ccgo_up((*WebPRescaler)(unsafe.Pointer(wrk)).Firow + uintptr(i)*4)) = uint32(0)
  52277 					goto _1
  52278 				_1:
  52279 					;
  52280 					i = i + 1
  52281 				}
  52282 			}
  52283 		}
  52284 		**(**int32)(__ccgo_up(wrk + 24)) += (*WebPRescaler)(unsafe.Pointer(wrk)).Fy_add
  52285 		**(**uintptr)(__ccgo_up(wrk + 72)) += uintptr((*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_stride)
  52286 		(*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y = (*WebPRescaler)(unsafe.Pointer(wrk)).Fdst_y + 1
  52287 	}
  52288 }
  52289 
  52290 func WebPRescalerDspInit(tls *libc.TLS) {
  52291 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52292 		goto _1
  52293 	}
  52294 	WebPRescalerDspInit_body(tls)
  52295 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52296 	goto _2
  52297 _2:
  52298 	;
  52299 	goto _1
  52300 _1: /**/ //
  52301 }
  52302 
  52303 var WebPRescalerDspInit_body_last_cpuinfo_used = uintptr(0)
  52304 
  52305 func init() {
  52306 	p := unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used)
  52307 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPRescalerDspInit_body_last_cpuinfo_used))
  52308 }
  52309 
  52310 func WebPRescalerDspInit_body(tls *libc.TLS) {
  52311 	WebPRescalerExportRowExpand = __ccgo_fp(WebPRescalerExportRowExpand_C)
  52312 	WebPRescalerExportRowShrink = __ccgo_fp(WebPRescalerExportRowShrink_C)
  52313 	WebPRescalerImportRowExpand = __ccgo_fp(WebPRescalerImportRowExpand_C)
  52314 	WebPRescalerImportRowShrink = __ccgo_fp(WebPRescalerImportRowShrink_C)
  52315 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52316 	}
  52317 }
  52318 
  52319 func WebPRescalerDspInitMIPS32(tls *libc.TLS) {
  52320 }
  52321 
  52322 func WebPRescalerDspInitMIPSdspR2(tls *libc.TLS) {
  52323 }
  52324 
  52325 func WebPRescalerDspInitMSA(tls *libc.TLS) {
  52326 }
  52327 
  52328 func WebPRescalerDspInitNEON(tls *libc.TLS) {
  52329 }
  52330 
  52331 func WebPRescalerDspInitSSE2(tls *libc.TLS) {
  52332 }
  52333 
  52334 // Copyright 2010 Google Inc. All Rights Reserved.
  52335 //
  52336 // Use of this source code is governed by a BSD-style license
  52337 // that can be found in the COPYING file in the root of the source
  52338 // tree. An additional intellectual property rights grant can be found
  52339 // in the file PATENTS. All contributing project authors may
  52340 // be found in the AUTHORS file in the root of the source tree.
  52341 // -----------------------------------------------------------------------------
  52342 //
  52343 //  Common types + memory wrappers
  52344 //
  52345 // Author: Skal (pascal.massimino@gmail.com)
  52346 
  52347 //------------------------------------------------------------------------------
  52348 // SSIM / PSNR
  52349 
  52350 // C documentation
  52351 //
  52352 //	// hat-shaped filter. Sum of coefficients is equal to 16.
  52353 var kWeight = [7]uint32_t{
  52354 	0: uint32(1),
  52355 	1: uint32(2),
  52356 	2: uint32(3),
  52357 	3: uint32(4),
  52358 	4: uint32(3),
  52359 	5: uint32(2),
  52360 	6: uint32(1),
  52361 }
  52362 var kWeightSum = libc.Uint32FromInt32(libc.Int32FromInt32(16) * libc.Int32FromInt32(16)) // sum{kWeight}^2
  52363 
  52364 func SSIMCalculation(tls *libc.TLS, stats uintptr, N uint32_t) (r1 float64) {
  52365 	var C1, C2, C3, w2 uint32_t
  52366 	var den_S, fden, fnum, num_S, sxx, syy, xmxm, ymym uint64_t
  52367 	var r float64
  52368 	var sxy, xmym int64_t
  52369 	var v1 int64
  52370 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = C1, C2, C3, den_S, fden, fnum, num_S, r, sxx, sxy, syy, w2, xmxm, xmym, ymym, v1
  52371 	w2 = N * N
  52372 	C1 = uint32(20) * w2
  52373 	C2 = uint32(60) * w2
  52374 	C3 = libc.Uint32FromInt32(libc.Int32FromInt32(8)*libc.Int32FromInt32(8)) * w2 // 'dark' limit ~= 6
  52375 	xmxm = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm)
  52376 	ymym = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym) * uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52377 	if xmxm+ymym >= uint64(C3) {
  52378 		xmym = libc.Int64FromUint32((*VP8DistoStats)(unsafe.Pointer(stats)).Fxm) * libc.Int64FromUint32((*VP8DistoStats)(unsafe.Pointer(stats)).Fym)
  52379 		sxy = libc.Int64FromUint32((*VP8DistoStats)(unsafe.Pointer(stats)).Fxym)*libc.Int64FromUint32(N) - xmym // can be negative
  52380 		sxx = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fxxm)*uint64(N) - xmxm
  52381 		syy = uint64((*VP8DistoStats)(unsafe.Pointer(stats)).Fyym)*uint64(N) - ymym
  52382 		if sxy < 0 {
  52383 			v1 = 0
  52384 		} else {
  52385 			v1 = sxy
  52386 		}
  52387 		// we descale by 8 to prevent overflow during the fnum/fden multiply.
  52388 		num_S = (uint64(2)*libc.Uint64FromInt64(v1) + uint64(C2)) >> int32(8)
  52389 		den_S = (sxx + syy + uint64(C2)) >> int32(8)
  52390 		fnum = libc.Uint64FromInt64(libc.Int64FromInt32(2)*xmym+libc.Int64FromUint32(C1)) * num_S
  52391 		fden = (xmxm + ymym + uint64(C1)) * den_S
  52392 		r = float64(fnum) / float64(fden)
  52393 		return r
  52394 	}
  52395 	return float64(1) // area is too dark to contribute meaningfully
  52396 }
  52397 
  52398 func VP8SSIMFromStats(tls *libc.TLS, stats uintptr) (r float64) {
  52399 	return SSIMCalculation(tls, stats, kWeightSum)
  52400 }
  52401 
  52402 func VP8SSIMFromStatsClipped(tls *libc.TLS, stats uintptr) (r float64) {
  52403 	return SSIMCalculation(tls, stats, (*VP8DistoStats)(unsafe.Pointer(stats)).Fw)
  52404 }
  52405 
  52406 func SSIMGetClipped_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32, xo int32, yo int32, W int32, H int32) (r float64) {
  52407 	bp := tls.Alloc(32)
  52408 	defer tls.Free(32)
  52409 	var s1, s2, w uint32_t
  52410 	var x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4 int32
  52411 	var _ /* stats at bp+0 */ VP8DistoStats
  52412 	_, _, _, _, _, _, _, _, _, _, _, _, _ = s1, s2, w, x, xmax, xmin, y, ymax, ymin, v1, v2, v3, v4
  52413 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52414 	if yo-int32(VP8_SSIM_KERNEL) < 0 {
  52415 		v1 = 0
  52416 	} else {
  52417 		v1 = yo - int32(VP8_SSIM_KERNEL)
  52418 	}
  52419 	ymin = v1
  52420 	if yo+int32(VP8_SSIM_KERNEL) > H-int32(1) {
  52421 		v2 = H - int32(1)
  52422 	} else {
  52423 		v2 = yo + int32(VP8_SSIM_KERNEL)
  52424 	}
  52425 	ymax = v2
  52426 	if xo-int32(VP8_SSIM_KERNEL) < 0 {
  52427 		v3 = 0
  52428 	} else {
  52429 		v3 = xo - int32(VP8_SSIM_KERNEL)
  52430 	}
  52431 	xmin = v3
  52432 	if xo+int32(VP8_SSIM_KERNEL) > W-int32(1) {
  52433 		v4 = W - int32(1)
  52434 	} else {
  52435 		v4 = xo + int32(VP8_SSIM_KERNEL)
  52436 	}
  52437 	xmax = v4
  52438 	src1 = src1 + uintptr(ymin*stride1)
  52439 	src2 = src2 + uintptr(ymin*stride2)
  52440 	y = ymin
  52441 	for {
  52442 		if !(y <= ymax) {
  52443 			break
  52444 		}
  52445 		x = xmin
  52446 		for {
  52447 			if !(x <= xmax) {
  52448 				break
  52449 			}
  52450 			w = kWeight[int32(VP8_SSIM_KERNEL)+x-xo] * kWeight[int32(VP8_SSIM_KERNEL)+y-yo]
  52451 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52452 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52453 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fw += w
  52454 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52455 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52456 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52457 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52458 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52459 			goto _6
  52460 		_6:
  52461 			;
  52462 			x = x + 1
  52463 		}
  52464 		goto _5
  52465 	_5:
  52466 		;
  52467 		y = y + 1
  52468 		src1 = src1 + uintptr(stride1)
  52469 		src2 = src2 + uintptr(stride2)
  52470 	}
  52471 	return VP8SSIMFromStatsClipped(tls, bp)
  52472 }
  52473 
  52474 func SSIMGet_C(tls *libc.TLS, src1 uintptr, stride1 int32, src2 uintptr, stride2 int32) (r float64) {
  52475 	bp := tls.Alloc(32)
  52476 	defer tls.Free(32)
  52477 	var s1, s2, w uint32_t
  52478 	var x, y int32
  52479 	var _ /* stats at bp+0 */ VP8DistoStats
  52480 	_, _, _, _, _ = s1, s2, w, x, y
  52481 	**(**VP8DistoStats)(__ccgo_up(bp)) = VP8DistoStats{}
  52482 	y = 0
  52483 	for {
  52484 		if !(y <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52485 			break
  52486 		}
  52487 		x = 0
  52488 		for {
  52489 			if !(x <= libc.Int32FromInt32(2)*libc.Int32FromInt32(VP8_SSIM_KERNEL)) {
  52490 				break
  52491 			}
  52492 			w = kWeight[x] * kWeight[y]
  52493 			s1 = uint32(**(**uint8_t)(__ccgo_up(src1 + uintptr(x))))
  52494 			s2 = uint32(**(**uint8_t)(__ccgo_up(src2 + uintptr(x))))
  52495 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxm += w * s1
  52496 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fym += w * s2
  52497 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxxm += w * s1 * s1
  52498 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fxym += w * s1 * s2
  52499 			(**(**VP8DistoStats)(__ccgo_up(bp))).Fyym += w * s2 * s2
  52500 			goto _2
  52501 		_2:
  52502 			;
  52503 			x = x + 1
  52504 		}
  52505 		goto _1
  52506 	_1:
  52507 		;
  52508 		y = y + 1
  52509 		src1 = src1 + uintptr(stride1)
  52510 		src2 = src2 + uintptr(stride2)
  52511 	}
  52512 	return VP8SSIMFromStats(tls, bp)
  52513 }
  52514 
  52515 //------------------------------------------------------------------------------
  52516 
  52517 func AccumulateSSE_C(tls *libc.TLS, src1 uintptr, src2 uintptr, len1 int32) (r uint32_t) {
  52518 	var diff int32_t
  52519 	var i int32
  52520 	var sse2 uint32_t
  52521 	_, _, _ = diff, i, sse2
  52522 	sse2 = uint32(0)
  52523 	// to ensure that accumulation fits within uint32_t
  52524 	i = 0
  52525 	for {
  52526 		if !(i < len1) {
  52527 			break
  52528 		}
  52529 		diff = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src1 + uintptr(i)))) - libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(src2 + uintptr(i))))
  52530 		sse2 = sse2 + libc.Uint32FromInt32(diff*diff)
  52531 		goto _1
  52532 	_1:
  52533 		;
  52534 		i = i + 1
  52535 	}
  52536 	return sse2
  52537 }
  52538 
  52539 func VP8SSIMDspInit(tls *libc.TLS) {
  52540 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  52541 		goto _1
  52542 	}
  52543 	VP8SSIMDspInit_body(tls)
  52544 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)), VP8GetCPUInfo)
  52545 	goto _2
  52546 _2:
  52547 	;
  52548 	goto _1
  52549 _1: /**/ //
  52550 }
  52551 
  52552 var VP8SSIMDspInit_body_last_cpuinfo_used = uintptr(0)
  52553 
  52554 func init() {
  52555 	p := unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used)
  52556 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&VP8SSIMDspInit_body_last_cpuinfo_used))
  52557 }
  52558 
  52559 func VP8SSIMDspInit_body(tls *libc.TLS) {
  52560 	VP8SSIMGetClipped = __ccgo_fp(SSIMGetClipped_C)
  52561 	VP8SSIMGet = __ccgo_fp(SSIMGet_C)
  52562 	VP8AccumulateSSE = __ccgo_fp(AccumulateSSE_C)
  52563 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  52564 	}
  52565 }
  52566 
  52567 func VP8SSIMDspInitSSE2(tls *libc.TLS) {
  52568 }
  52569 
  52570 // Given samples laid out in a square as:
  52571 //  [a b]
  52572 //  [c d]
  52573 // we interpolate u/v as:
  52574 //  ([9*a + 3*b + 3*c +   d    3*a + 9*b + 3*c +   d] + [8 8]) / 16
  52575 //  ([3*a +   b + 9*c + 3*d      a + 3*b + 3*c + 9*d]   [8 8]) / 16
  52576 
  52577 // We process u and v together stashed into 32bit (16bit each).
  52578 
  52579 // C documentation
  52580 //
  52581 //	// All variants implemented.
  52582 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) {
  52583 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  52584 	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
  52585 	var v1, v5 uintptr
  52586 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  52587 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  52588 	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 */
  52589 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  52590 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  52591 	v1 = top_dst
  52592 	v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  52593 	v3 = libc.Int32FromUint8(uint8(uv0 & uint32(0xff)))
  52594 	v4 = libc.Int32FromUint8(uint8(uv0 >> libc.Int32FromInt32(16)))
  52595 	v5 = v1
  52596 	v8 = v2 * int32(19077) >> int32(8)
  52597 	goto _9
  52598 _9:
  52599 	v10 = v4 * int32(26149) >> int32(8)
  52600 	goto _11
  52601 _11:
  52602 	v12 = v8 + v10 - int32(14234)
  52603 	if v12 & ^int32(YUV_MASK2) == 0 {
  52604 		v15 = v12 >> int32(YUV_FIX2)
  52605 	} else {
  52606 		if v12 < 0 {
  52607 			v16 = 0
  52608 		} else {
  52609 			v16 = int32(255)
  52610 		}
  52611 		v15 = v16
  52612 	}
  52613 	v13 = v15
  52614 	goto _14
  52615 _14:
  52616 	v6 = v13
  52617 	goto _7
  52618 _7:
  52619 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52620 	v19 = v2 * int32(19077) >> int32(8)
  52621 	goto _20
  52622 _20:
  52623 	v21 = v3 * int32(6419) >> int32(8)
  52624 	goto _22
  52625 _22:
  52626 	v23 = v4 * int32(13320) >> int32(8)
  52627 	goto _24
  52628 _24:
  52629 	v25 = v19 - v21 - v23 + int32(8708)
  52630 	if v25 & ^int32(YUV_MASK2) == 0 {
  52631 		v28 = v25 >> int32(YUV_FIX2)
  52632 	} else {
  52633 		if v25 < 0 {
  52634 			v29 = 0
  52635 		} else {
  52636 			v29 = int32(255)
  52637 		}
  52638 		v28 = v29
  52639 	}
  52640 	v26 = v28
  52641 	goto _27
  52642 _27:
  52643 	v17 = v26
  52644 	goto _18
  52645 _18:
  52646 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52647 	v32 = v2 * int32(19077) >> int32(8)
  52648 	goto _33
  52649 _33:
  52650 	v34 = v3 * int32(33050) >> int32(8)
  52651 	goto _35
  52652 _35:
  52653 	v36 = v32 + v34 - int32(17685)
  52654 	if v36 & ^int32(YUV_MASK2) == 0 {
  52655 		v39 = v36 >> int32(YUV_FIX2)
  52656 	} else {
  52657 		if v36 < 0 {
  52658 			v40 = 0
  52659 		} else {
  52660 			v40 = int32(255)
  52661 		}
  52662 		v39 = v40
  52663 	}
  52664 	v37 = v39
  52665 	goto _38
  52666 _38:
  52667 	v30 = v37
  52668 	goto _31
  52669 _31:
  52670 	**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52671 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52672 	if bottom_y != libc.UintptrFromInt32(0) {
  52673 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  52674 		v1 = bottom_dst
  52675 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  52676 		v3 = libc.Int32FromUint8(uint8(uv01 & uint32(0xff)))
  52677 		v4 = libc.Int32FromUint8(uint8(uv01 >> libc.Int32FromInt32(16)))
  52678 		v5 = v1
  52679 		v8 = v2 * int32(19077) >> int32(8)
  52680 		goto _49
  52681 	_49:
  52682 		v10 = v4 * int32(26149) >> int32(8)
  52683 		goto _51
  52684 	_51:
  52685 		v12 = v8 + v10 - int32(14234)
  52686 		if v12 & ^int32(YUV_MASK2) == 0 {
  52687 			v15 = v12 >> int32(YUV_FIX2)
  52688 		} else {
  52689 			if v12 < 0 {
  52690 				v16 = 0
  52691 			} else {
  52692 				v16 = int32(255)
  52693 			}
  52694 			v15 = v16
  52695 		}
  52696 		v13 = v15
  52697 		goto _54
  52698 	_54:
  52699 		v6 = v13
  52700 		goto _47
  52701 	_47:
  52702 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52703 		v19 = v2 * int32(19077) >> int32(8)
  52704 		goto _60
  52705 	_60:
  52706 		v21 = v3 * int32(6419) >> int32(8)
  52707 		goto _62
  52708 	_62:
  52709 		v23 = v4 * int32(13320) >> int32(8)
  52710 		goto _64
  52711 	_64:
  52712 		v25 = v19 - v21 - v23 + int32(8708)
  52713 		if v25 & ^int32(YUV_MASK2) == 0 {
  52714 			v28 = v25 >> int32(YUV_FIX2)
  52715 		} else {
  52716 			if v25 < 0 {
  52717 				v29 = 0
  52718 			} else {
  52719 				v29 = int32(255)
  52720 			}
  52721 			v28 = v29
  52722 		}
  52723 		v26 = v28
  52724 		goto _67
  52725 	_67:
  52726 		v17 = v26
  52727 		goto _58
  52728 	_58:
  52729 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52730 		v32 = v2 * int32(19077) >> int32(8)
  52731 		goto _73
  52732 	_73:
  52733 		v34 = v3 * int32(33050) >> int32(8)
  52734 		goto _75
  52735 	_75:
  52736 		v36 = v32 + v34 - int32(17685)
  52737 		if v36 & ^int32(YUV_MASK2) == 0 {
  52738 			v39 = v36 >> int32(YUV_FIX2)
  52739 		} else {
  52740 			if v36 < 0 {
  52741 				v40 = 0
  52742 			} else {
  52743 				v40 = int32(255)
  52744 			}
  52745 			v39 = v40
  52746 		}
  52747 		v37 = v39
  52748 		goto _78
  52749 	_78:
  52750 		v30 = v37
  52751 		goto _71
  52752 	_71:
  52753 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52754 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52755 	}
  52756 	x = int32(1)
  52757 	for {
  52758 		if !(x <= last_pixel_pair) {
  52759 			break
  52760 		}
  52761 		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 */
  52762 		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*/
  52763 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  52764 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  52765 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  52766 		uv02 = (diag_12 + tl_uv) >> int32(1)
  52767 		uv1 = (diag_03 + t_uv) >> int32(1)
  52768 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  52769 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  52770 		v3 = libc.Int32FromUint8(uint8(uv02 & uint32(0xff)))
  52771 		v4 = libc.Int32FromUint8(uint8(uv02 >> libc.Int32FromInt32(16)))
  52772 		v5 = v1
  52773 		v8 = v2 * int32(19077) >> int32(8)
  52774 		goto _90
  52775 	_90:
  52776 		v10 = v4 * int32(26149) >> int32(8)
  52777 		goto _92
  52778 	_92:
  52779 		v12 = v8 + v10 - int32(14234)
  52780 		if v12 & ^int32(YUV_MASK2) == 0 {
  52781 			v15 = v12 >> int32(YUV_FIX2)
  52782 		} else {
  52783 			if v12 < 0 {
  52784 				v16 = 0
  52785 			} else {
  52786 				v16 = int32(255)
  52787 			}
  52788 			v15 = v16
  52789 		}
  52790 		v13 = v15
  52791 		goto _95
  52792 	_95:
  52793 		v6 = v13
  52794 		goto _88
  52795 	_88:
  52796 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52797 		v19 = v2 * int32(19077) >> int32(8)
  52798 		goto _101
  52799 	_101:
  52800 		v21 = v3 * int32(6419) >> int32(8)
  52801 		goto _103
  52802 	_103:
  52803 		v23 = v4 * int32(13320) >> int32(8)
  52804 		goto _105
  52805 	_105:
  52806 		v25 = v19 - v21 - v23 + int32(8708)
  52807 		if v25 & ^int32(YUV_MASK2) == 0 {
  52808 			v28 = v25 >> int32(YUV_FIX2)
  52809 		} else {
  52810 			if v25 < 0 {
  52811 				v29 = 0
  52812 			} else {
  52813 				v29 = int32(255)
  52814 			}
  52815 			v28 = v29
  52816 		}
  52817 		v26 = v28
  52818 		goto _108
  52819 	_108:
  52820 		v17 = v26
  52821 		goto _99
  52822 	_99:
  52823 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52824 		v32 = v2 * int32(19077) >> int32(8)
  52825 		goto _114
  52826 	_114:
  52827 		v34 = v3 * int32(33050) >> int32(8)
  52828 		goto _116
  52829 	_116:
  52830 		v36 = v32 + v34 - int32(17685)
  52831 		if v36 & ^int32(YUV_MASK2) == 0 {
  52832 			v39 = v36 >> int32(YUV_FIX2)
  52833 		} else {
  52834 			if v36 < 0 {
  52835 				v40 = 0
  52836 			} else {
  52837 				v40 = int32(255)
  52838 			}
  52839 			v39 = v40
  52840 		}
  52841 		v37 = v39
  52842 		goto _119
  52843 	_119:
  52844 		v30 = v37
  52845 		goto _112
  52846 	_112:
  52847 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52848 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52849 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  52850 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  52851 		v3 = libc.Int32FromUint8(uint8(uv1 & uint32(0xff)))
  52852 		v4 = libc.Int32FromUint8(uint8(uv1 >> libc.Int32FromInt32(16)))
  52853 		v5 = v1
  52854 		v8 = v2 * int32(19077) >> int32(8)
  52855 		goto _130
  52856 	_130:
  52857 		v10 = v4 * int32(26149) >> int32(8)
  52858 		goto _132
  52859 	_132:
  52860 		v12 = v8 + v10 - int32(14234)
  52861 		if v12 & ^int32(YUV_MASK2) == 0 {
  52862 			v15 = v12 >> int32(YUV_FIX2)
  52863 		} else {
  52864 			if v12 < 0 {
  52865 				v16 = 0
  52866 			} else {
  52867 				v16 = int32(255)
  52868 			}
  52869 			v15 = v16
  52870 		}
  52871 		v13 = v15
  52872 		goto _135
  52873 	_135:
  52874 		v6 = v13
  52875 		goto _128
  52876 	_128:
  52877 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52878 		v19 = v2 * int32(19077) >> int32(8)
  52879 		goto _141
  52880 	_141:
  52881 		v21 = v3 * int32(6419) >> int32(8)
  52882 		goto _143
  52883 	_143:
  52884 		v23 = v4 * int32(13320) >> int32(8)
  52885 		goto _145
  52886 	_145:
  52887 		v25 = v19 - v21 - v23 + int32(8708)
  52888 		if v25 & ^int32(YUV_MASK2) == 0 {
  52889 			v28 = v25 >> int32(YUV_FIX2)
  52890 		} else {
  52891 			if v25 < 0 {
  52892 				v29 = 0
  52893 			} else {
  52894 				v29 = int32(255)
  52895 			}
  52896 			v28 = v29
  52897 		}
  52898 		v26 = v28
  52899 		goto _148
  52900 	_148:
  52901 		v17 = v26
  52902 		goto _139
  52903 	_139:
  52904 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52905 		v32 = v2 * int32(19077) >> int32(8)
  52906 		goto _154
  52907 	_154:
  52908 		v34 = v3 * int32(33050) >> int32(8)
  52909 		goto _156
  52910 	_156:
  52911 		v36 = v32 + v34 - int32(17685)
  52912 		if v36 & ^int32(YUV_MASK2) == 0 {
  52913 			v39 = v36 >> int32(YUV_FIX2)
  52914 		} else {
  52915 			if v36 < 0 {
  52916 				v40 = 0
  52917 			} else {
  52918 				v40 = int32(255)
  52919 			}
  52920 			v39 = v40
  52921 		}
  52922 		v37 = v39
  52923 		goto _159
  52924 	_159:
  52925 		v30 = v37
  52926 		goto _152
  52927 	_152:
  52928 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  52929 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  52930 		if bottom_y != libc.UintptrFromInt32(0) {
  52931 			uv03 = (diag_03 + l_uv) >> int32(1)
  52932 			uv11 = (diag_12 + uv) >> int32(1)
  52933 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  52934 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  52935 			v3 = libc.Int32FromUint8(uint8(uv03 & uint32(0xff)))
  52936 			v4 = libc.Int32FromUint8(uint8(uv03 >> libc.Int32FromInt32(16)))
  52937 			v5 = v1
  52938 			v8 = v2 * int32(19077) >> int32(8)
  52939 			goto _170
  52940 		_170:
  52941 			v10 = v4 * int32(26149) >> int32(8)
  52942 			goto _172
  52943 		_172:
  52944 			v12 = v8 + v10 - int32(14234)
  52945 			if v12 & ^int32(YUV_MASK2) == 0 {
  52946 				v15 = v12 >> int32(YUV_FIX2)
  52947 			} else {
  52948 				if v12 < 0 {
  52949 					v16 = 0
  52950 				} else {
  52951 					v16 = int32(255)
  52952 				}
  52953 				v15 = v16
  52954 			}
  52955 			v13 = v15
  52956 			goto _175
  52957 		_175:
  52958 			v6 = v13
  52959 			goto _168
  52960 		_168:
  52961 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  52962 			v19 = v2 * int32(19077) >> int32(8)
  52963 			goto _181
  52964 		_181:
  52965 			v21 = v3 * int32(6419) >> int32(8)
  52966 			goto _183
  52967 		_183:
  52968 			v23 = v4 * int32(13320) >> int32(8)
  52969 			goto _185
  52970 		_185:
  52971 			v25 = v19 - v21 - v23 + int32(8708)
  52972 			if v25 & ^int32(YUV_MASK2) == 0 {
  52973 				v28 = v25 >> int32(YUV_FIX2)
  52974 			} else {
  52975 				if v25 < 0 {
  52976 					v29 = 0
  52977 				} else {
  52978 					v29 = int32(255)
  52979 				}
  52980 				v28 = v29
  52981 			}
  52982 			v26 = v28
  52983 			goto _188
  52984 		_188:
  52985 			v17 = v26
  52986 			goto _179
  52987 		_179:
  52988 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  52989 			v32 = v2 * int32(19077) >> int32(8)
  52990 			goto _194
  52991 		_194:
  52992 			v34 = v3 * int32(33050) >> int32(8)
  52993 			goto _196
  52994 		_196:
  52995 			v36 = v32 + v34 - int32(17685)
  52996 			if v36 & ^int32(YUV_MASK2) == 0 {
  52997 				v39 = v36 >> int32(YUV_FIX2)
  52998 			} else {
  52999 				if v36 < 0 {
  53000 					v40 = 0
  53001 				} else {
  53002 					v40 = int32(255)
  53003 				}
  53004 				v39 = v40
  53005 			}
  53006 			v37 = v39
  53007 			goto _199
  53008 		_199:
  53009 			v30 = v37
  53010 			goto _192
  53011 		_192:
  53012 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53013 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53014 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53015 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53016 			v3 = libc.Int32FromUint8(uint8(uv11 & uint32(0xff)))
  53017 			v4 = libc.Int32FromUint8(uint8(uv11 >> libc.Int32FromInt32(16)))
  53018 			v5 = v1
  53019 			v8 = v2 * int32(19077) >> int32(8)
  53020 			goto _210
  53021 		_210:
  53022 			v10 = v4 * int32(26149) >> int32(8)
  53023 			goto _212
  53024 		_212:
  53025 			v12 = v8 + v10 - int32(14234)
  53026 			if v12 & ^int32(YUV_MASK2) == 0 {
  53027 				v15 = v12 >> int32(YUV_FIX2)
  53028 			} else {
  53029 				if v12 < 0 {
  53030 					v16 = 0
  53031 				} else {
  53032 					v16 = int32(255)
  53033 				}
  53034 				v15 = v16
  53035 			}
  53036 			v13 = v15
  53037 			goto _215
  53038 		_215:
  53039 			v6 = v13
  53040 			goto _208
  53041 		_208:
  53042 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53043 			v19 = v2 * int32(19077) >> int32(8)
  53044 			goto _221
  53045 		_221:
  53046 			v21 = v3 * int32(6419) >> int32(8)
  53047 			goto _223
  53048 		_223:
  53049 			v23 = v4 * int32(13320) >> int32(8)
  53050 			goto _225
  53051 		_225:
  53052 			v25 = v19 - v21 - v23 + int32(8708)
  53053 			if v25 & ^int32(YUV_MASK2) == 0 {
  53054 				v28 = v25 >> int32(YUV_FIX2)
  53055 			} else {
  53056 				if v25 < 0 {
  53057 					v29 = 0
  53058 				} else {
  53059 					v29 = int32(255)
  53060 				}
  53061 				v28 = v29
  53062 			}
  53063 			v26 = v28
  53064 			goto _228
  53065 		_228:
  53066 			v17 = v26
  53067 			goto _219
  53068 		_219:
  53069 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53070 			v32 = v2 * int32(19077) >> int32(8)
  53071 			goto _234
  53072 		_234:
  53073 			v34 = v3 * int32(33050) >> int32(8)
  53074 			goto _236
  53075 		_236:
  53076 			v36 = v32 + v34 - int32(17685)
  53077 			if v36 & ^int32(YUV_MASK2) == 0 {
  53078 				v39 = v36 >> int32(YUV_FIX2)
  53079 			} else {
  53080 				if v36 < 0 {
  53081 					v40 = 0
  53082 				} else {
  53083 					v40 = int32(255)
  53084 				}
  53085 				v39 = v40
  53086 			}
  53087 			v37 = v39
  53088 			goto _239
  53089 		_239:
  53090 			v30 = v37
  53091 			goto _232
  53092 		_232:
  53093 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53094 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53095 		}
  53096 		tl_uv = t_uv
  53097 		l_uv = uv
  53098 		goto _81
  53099 	_81:
  53100 		;
  53101 		x = x + 1
  53102 	}
  53103 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53104 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53105 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53106 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53107 		v3 = libc.Int32FromUint8(uint8(uv04 & uint32(0xff)))
  53108 		v4 = libc.Int32FromUint8(uint8(uv04 >> libc.Int32FromInt32(16)))
  53109 		v5 = v1
  53110 		v8 = v2 * int32(19077) >> int32(8)
  53111 		goto _250
  53112 	_250:
  53113 		v10 = v4 * int32(26149) >> int32(8)
  53114 		goto _252
  53115 	_252:
  53116 		v12 = v8 + v10 - int32(14234)
  53117 		if v12 & ^int32(YUV_MASK2) == 0 {
  53118 			v15 = v12 >> int32(YUV_FIX2)
  53119 		} else {
  53120 			if v12 < 0 {
  53121 				v16 = 0
  53122 			} else {
  53123 				v16 = int32(255)
  53124 			}
  53125 			v15 = v16
  53126 		}
  53127 		v13 = v15
  53128 		goto _255
  53129 	_255:
  53130 		v6 = v13
  53131 		goto _248
  53132 	_248:
  53133 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53134 		v19 = v2 * int32(19077) >> int32(8)
  53135 		goto _261
  53136 	_261:
  53137 		v21 = v3 * int32(6419) >> int32(8)
  53138 		goto _263
  53139 	_263:
  53140 		v23 = v4 * int32(13320) >> int32(8)
  53141 		goto _265
  53142 	_265:
  53143 		v25 = v19 - v21 - v23 + int32(8708)
  53144 		if v25 & ^int32(YUV_MASK2) == 0 {
  53145 			v28 = v25 >> int32(YUV_FIX2)
  53146 		} else {
  53147 			if v25 < 0 {
  53148 				v29 = 0
  53149 			} else {
  53150 				v29 = int32(255)
  53151 			}
  53152 			v28 = v29
  53153 		}
  53154 		v26 = v28
  53155 		goto _268
  53156 	_268:
  53157 		v17 = v26
  53158 		goto _259
  53159 	_259:
  53160 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53161 		v32 = v2 * int32(19077) >> int32(8)
  53162 		goto _274
  53163 	_274:
  53164 		v34 = v3 * int32(33050) >> int32(8)
  53165 		goto _276
  53166 	_276:
  53167 		v36 = v32 + v34 - int32(17685)
  53168 		if v36 & ^int32(YUV_MASK2) == 0 {
  53169 			v39 = v36 >> int32(YUV_FIX2)
  53170 		} else {
  53171 			if v36 < 0 {
  53172 				v40 = 0
  53173 			} else {
  53174 				v40 = int32(255)
  53175 			}
  53176 			v39 = v40
  53177 		}
  53178 		v37 = v39
  53179 		goto _279
  53180 	_279:
  53181 		v30 = v37
  53182 		goto _272
  53183 	_272:
  53184 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53185 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53186 		if bottom_y != libc.UintptrFromInt32(0) {
  53187 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53188 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  53189 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  53190 			v3 = libc.Int32FromUint8(uint8(uv05 & uint32(0xff)))
  53191 			v4 = libc.Int32FromUint8(uint8(uv05 >> libc.Int32FromInt32(16)))
  53192 			v5 = v1
  53193 			v8 = v2 * int32(19077) >> int32(8)
  53194 			goto _290
  53195 		_290:
  53196 			v10 = v4 * int32(26149) >> int32(8)
  53197 			goto _292
  53198 		_292:
  53199 			v12 = v8 + v10 - int32(14234)
  53200 			if v12 & ^int32(YUV_MASK2) == 0 {
  53201 				v15 = v12 >> int32(YUV_FIX2)
  53202 			} else {
  53203 				if v12 < 0 {
  53204 					v16 = 0
  53205 				} else {
  53206 					v16 = int32(255)
  53207 				}
  53208 				v15 = v16
  53209 			}
  53210 			v13 = v15
  53211 			goto _295
  53212 		_295:
  53213 			v6 = v13
  53214 			goto _288
  53215 		_288:
  53216 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53217 			v19 = v2 * int32(19077) >> int32(8)
  53218 			goto _301
  53219 		_301:
  53220 			v21 = v3 * int32(6419) >> int32(8)
  53221 			goto _303
  53222 		_303:
  53223 			v23 = v4 * int32(13320) >> int32(8)
  53224 			goto _305
  53225 		_305:
  53226 			v25 = v19 - v21 - v23 + int32(8708)
  53227 			if v25 & ^int32(YUV_MASK2) == 0 {
  53228 				v28 = v25 >> int32(YUV_FIX2)
  53229 			} else {
  53230 				if v25 < 0 {
  53231 					v29 = 0
  53232 				} else {
  53233 					v29 = int32(255)
  53234 				}
  53235 				v28 = v29
  53236 			}
  53237 			v26 = v28
  53238 			goto _308
  53239 		_308:
  53240 			v17 = v26
  53241 			goto _299
  53242 		_299:
  53243 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53244 			v32 = v2 * int32(19077) >> int32(8)
  53245 			goto _314
  53246 		_314:
  53247 			v34 = v3 * int32(33050) >> int32(8)
  53248 			goto _316
  53249 		_316:
  53250 			v36 = v32 + v34 - int32(17685)
  53251 			if v36 & ^int32(YUV_MASK2) == 0 {
  53252 				v39 = v36 >> int32(YUV_FIX2)
  53253 			} else {
  53254 				if v36 < 0 {
  53255 					v40 = 0
  53256 				} else {
  53257 					v40 = int32(255)
  53258 				}
  53259 				v39 = v40
  53260 			}
  53261 			v37 = v39
  53262 			goto _319
  53263 		_319:
  53264 			v30 = v37
  53265 			goto _312
  53266 		_312:
  53267 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53268 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53269 		}
  53270 	}
  53271 }
  53272 
  53273 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) {
  53274 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  53275 	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
  53276 	var v1, v5 uintptr
  53277 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  53278 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  53279 	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 */
  53280 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  53281 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53282 	v1 = top_dst
  53283 	v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  53284 	v3 = libc.Int32FromUint8(uint8(uv0 & uint32(0xff)))
  53285 	v4 = libc.Int32FromUint8(uint8(uv0 >> libc.Int32FromInt32(16)))
  53286 	v5 = v1
  53287 	v8 = v2 * int32(19077) >> int32(8)
  53288 	goto _9
  53289 _9:
  53290 	v10 = v3 * int32(33050) >> int32(8)
  53291 	goto _11
  53292 _11:
  53293 	v12 = v8 + v10 - int32(17685)
  53294 	if v12 & ^int32(YUV_MASK2) == 0 {
  53295 		v15 = v12 >> int32(YUV_FIX2)
  53296 	} else {
  53297 		if v12 < 0 {
  53298 			v16 = 0
  53299 		} else {
  53300 			v16 = int32(255)
  53301 		}
  53302 		v15 = v16
  53303 	}
  53304 	v13 = v15
  53305 	goto _14
  53306 _14:
  53307 	v6 = v13
  53308 	goto _7
  53309 _7:
  53310 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53311 	v19 = v2 * int32(19077) >> int32(8)
  53312 	goto _20
  53313 _20:
  53314 	v21 = v3 * int32(6419) >> int32(8)
  53315 	goto _22
  53316 _22:
  53317 	v23 = v4 * int32(13320) >> int32(8)
  53318 	goto _24
  53319 _24:
  53320 	v25 = v19 - v21 - v23 + int32(8708)
  53321 	if v25 & ^int32(YUV_MASK2) == 0 {
  53322 		v28 = v25 >> int32(YUV_FIX2)
  53323 	} else {
  53324 		if v25 < 0 {
  53325 			v29 = 0
  53326 		} else {
  53327 			v29 = int32(255)
  53328 		}
  53329 		v28 = v29
  53330 	}
  53331 	v26 = v28
  53332 	goto _27
  53333 _27:
  53334 	v17 = v26
  53335 	goto _18
  53336 _18:
  53337 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53338 	v32 = v2 * int32(19077) >> int32(8)
  53339 	goto _33
  53340 _33:
  53341 	v34 = v4 * int32(26149) >> int32(8)
  53342 	goto _35
  53343 _35:
  53344 	v36 = v32 + v34 - int32(14234)
  53345 	if v36 & ^int32(YUV_MASK2) == 0 {
  53346 		v39 = v36 >> int32(YUV_FIX2)
  53347 	} else {
  53348 		if v36 < 0 {
  53349 			v40 = 0
  53350 		} else {
  53351 			v40 = int32(255)
  53352 		}
  53353 		v39 = v40
  53354 	}
  53355 	v37 = v39
  53356 	goto _38
  53357 _38:
  53358 	v30 = v37
  53359 	goto _31
  53360 _31:
  53361 	**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53362 	**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53363 	if bottom_y != libc.UintptrFromInt32(0) {
  53364 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53365 		v1 = bottom_dst
  53366 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  53367 		v3 = libc.Int32FromUint8(uint8(uv01 & uint32(0xff)))
  53368 		v4 = libc.Int32FromUint8(uint8(uv01 >> libc.Int32FromInt32(16)))
  53369 		v5 = v1
  53370 		v8 = v2 * int32(19077) >> int32(8)
  53371 		goto _49
  53372 	_49:
  53373 		v10 = v3 * int32(33050) >> int32(8)
  53374 		goto _51
  53375 	_51:
  53376 		v12 = v8 + v10 - int32(17685)
  53377 		if v12 & ^int32(YUV_MASK2) == 0 {
  53378 			v15 = v12 >> int32(YUV_FIX2)
  53379 		} else {
  53380 			if v12 < 0 {
  53381 				v16 = 0
  53382 			} else {
  53383 				v16 = int32(255)
  53384 			}
  53385 			v15 = v16
  53386 		}
  53387 		v13 = v15
  53388 		goto _54
  53389 	_54:
  53390 		v6 = v13
  53391 		goto _47
  53392 	_47:
  53393 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53394 		v19 = v2 * int32(19077) >> int32(8)
  53395 		goto _60
  53396 	_60:
  53397 		v21 = v3 * int32(6419) >> int32(8)
  53398 		goto _62
  53399 	_62:
  53400 		v23 = v4 * int32(13320) >> int32(8)
  53401 		goto _64
  53402 	_64:
  53403 		v25 = v19 - v21 - v23 + int32(8708)
  53404 		if v25 & ^int32(YUV_MASK2) == 0 {
  53405 			v28 = v25 >> int32(YUV_FIX2)
  53406 		} else {
  53407 			if v25 < 0 {
  53408 				v29 = 0
  53409 			} else {
  53410 				v29 = int32(255)
  53411 			}
  53412 			v28 = v29
  53413 		}
  53414 		v26 = v28
  53415 		goto _67
  53416 	_67:
  53417 		v17 = v26
  53418 		goto _58
  53419 	_58:
  53420 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53421 		v32 = v2 * int32(19077) >> int32(8)
  53422 		goto _73
  53423 	_73:
  53424 		v34 = v4 * int32(26149) >> int32(8)
  53425 		goto _75
  53426 	_75:
  53427 		v36 = v32 + v34 - int32(14234)
  53428 		if v36 & ^int32(YUV_MASK2) == 0 {
  53429 			v39 = v36 >> int32(YUV_FIX2)
  53430 		} else {
  53431 			if v36 < 0 {
  53432 				v40 = 0
  53433 			} else {
  53434 				v40 = int32(255)
  53435 			}
  53436 			v39 = v40
  53437 		}
  53438 		v37 = v39
  53439 		goto _78
  53440 	_78:
  53441 		v30 = v37
  53442 		goto _71
  53443 	_71:
  53444 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53445 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53446 	}
  53447 	x = int32(1)
  53448 	for {
  53449 		if !(x <= last_pixel_pair) {
  53450 			break
  53451 		}
  53452 		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 */
  53453 		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*/
  53454 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  53455 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  53456 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  53457 		uv02 = (diag_12 + tl_uv) >> int32(1)
  53458 		uv1 = (diag_03 + t_uv) >> int32(1)
  53459 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53460 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  53461 		v3 = libc.Int32FromUint8(uint8(uv02 & uint32(0xff)))
  53462 		v4 = libc.Int32FromUint8(uint8(uv02 >> libc.Int32FromInt32(16)))
  53463 		v5 = v1
  53464 		v8 = v2 * int32(19077) >> int32(8)
  53465 		goto _90
  53466 	_90:
  53467 		v10 = v3 * int32(33050) >> int32(8)
  53468 		goto _92
  53469 	_92:
  53470 		v12 = v8 + v10 - int32(17685)
  53471 		if v12 & ^int32(YUV_MASK2) == 0 {
  53472 			v15 = v12 >> int32(YUV_FIX2)
  53473 		} else {
  53474 			if v12 < 0 {
  53475 				v16 = 0
  53476 			} else {
  53477 				v16 = int32(255)
  53478 			}
  53479 			v15 = v16
  53480 		}
  53481 		v13 = v15
  53482 		goto _95
  53483 	_95:
  53484 		v6 = v13
  53485 		goto _88
  53486 	_88:
  53487 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53488 		v19 = v2 * int32(19077) >> int32(8)
  53489 		goto _101
  53490 	_101:
  53491 		v21 = v3 * int32(6419) >> int32(8)
  53492 		goto _103
  53493 	_103:
  53494 		v23 = v4 * int32(13320) >> int32(8)
  53495 		goto _105
  53496 	_105:
  53497 		v25 = v19 - v21 - v23 + int32(8708)
  53498 		if v25 & ^int32(YUV_MASK2) == 0 {
  53499 			v28 = v25 >> int32(YUV_FIX2)
  53500 		} else {
  53501 			if v25 < 0 {
  53502 				v29 = 0
  53503 			} else {
  53504 				v29 = int32(255)
  53505 			}
  53506 			v28 = v29
  53507 		}
  53508 		v26 = v28
  53509 		goto _108
  53510 	_108:
  53511 		v17 = v26
  53512 		goto _99
  53513 	_99:
  53514 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53515 		v32 = v2 * int32(19077) >> int32(8)
  53516 		goto _114
  53517 	_114:
  53518 		v34 = v4 * int32(26149) >> int32(8)
  53519 		goto _116
  53520 	_116:
  53521 		v36 = v32 + v34 - int32(14234)
  53522 		if v36 & ^int32(YUV_MASK2) == 0 {
  53523 			v39 = v36 >> int32(YUV_FIX2)
  53524 		} else {
  53525 			if v36 < 0 {
  53526 				v40 = 0
  53527 			} else {
  53528 				v40 = int32(255)
  53529 			}
  53530 			v39 = v40
  53531 		}
  53532 		v37 = v39
  53533 		goto _119
  53534 	_119:
  53535 		v30 = v37
  53536 		goto _112
  53537 	_112:
  53538 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53539 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53540 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  53541 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  53542 		v3 = libc.Int32FromUint8(uint8(uv1 & uint32(0xff)))
  53543 		v4 = libc.Int32FromUint8(uint8(uv1 >> libc.Int32FromInt32(16)))
  53544 		v5 = v1
  53545 		v8 = v2 * int32(19077) >> int32(8)
  53546 		goto _130
  53547 	_130:
  53548 		v10 = v3 * int32(33050) >> int32(8)
  53549 		goto _132
  53550 	_132:
  53551 		v12 = v8 + v10 - int32(17685)
  53552 		if v12 & ^int32(YUV_MASK2) == 0 {
  53553 			v15 = v12 >> int32(YUV_FIX2)
  53554 		} else {
  53555 			if v12 < 0 {
  53556 				v16 = 0
  53557 			} else {
  53558 				v16 = int32(255)
  53559 			}
  53560 			v15 = v16
  53561 		}
  53562 		v13 = v15
  53563 		goto _135
  53564 	_135:
  53565 		v6 = v13
  53566 		goto _128
  53567 	_128:
  53568 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53569 		v19 = v2 * int32(19077) >> int32(8)
  53570 		goto _141
  53571 	_141:
  53572 		v21 = v3 * int32(6419) >> int32(8)
  53573 		goto _143
  53574 	_143:
  53575 		v23 = v4 * int32(13320) >> int32(8)
  53576 		goto _145
  53577 	_145:
  53578 		v25 = v19 - v21 - v23 + int32(8708)
  53579 		if v25 & ^int32(YUV_MASK2) == 0 {
  53580 			v28 = v25 >> int32(YUV_FIX2)
  53581 		} else {
  53582 			if v25 < 0 {
  53583 				v29 = 0
  53584 			} else {
  53585 				v29 = int32(255)
  53586 			}
  53587 			v28 = v29
  53588 		}
  53589 		v26 = v28
  53590 		goto _148
  53591 	_148:
  53592 		v17 = v26
  53593 		goto _139
  53594 	_139:
  53595 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53596 		v32 = v2 * int32(19077) >> int32(8)
  53597 		goto _154
  53598 	_154:
  53599 		v34 = v4 * int32(26149) >> int32(8)
  53600 		goto _156
  53601 	_156:
  53602 		v36 = v32 + v34 - int32(14234)
  53603 		if v36 & ^int32(YUV_MASK2) == 0 {
  53604 			v39 = v36 >> int32(YUV_FIX2)
  53605 		} else {
  53606 			if v36 < 0 {
  53607 				v40 = 0
  53608 			} else {
  53609 				v40 = int32(255)
  53610 			}
  53611 			v39 = v40
  53612 		}
  53613 		v37 = v39
  53614 		goto _159
  53615 	_159:
  53616 		v30 = v37
  53617 		goto _152
  53618 	_152:
  53619 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53620 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53621 		if bottom_y != libc.UintptrFromInt32(0) {
  53622 			uv03 = (diag_03 + l_uv) >> int32(1)
  53623 			uv11 = (diag_12 + uv) >> int32(1)
  53624 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  53625 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  53626 			v3 = libc.Int32FromUint8(uint8(uv03 & uint32(0xff)))
  53627 			v4 = libc.Int32FromUint8(uint8(uv03 >> libc.Int32FromInt32(16)))
  53628 			v5 = v1
  53629 			v8 = v2 * int32(19077) >> int32(8)
  53630 			goto _170
  53631 		_170:
  53632 			v10 = v3 * int32(33050) >> int32(8)
  53633 			goto _172
  53634 		_172:
  53635 			v12 = v8 + v10 - int32(17685)
  53636 			if v12 & ^int32(YUV_MASK2) == 0 {
  53637 				v15 = v12 >> int32(YUV_FIX2)
  53638 			} else {
  53639 				if v12 < 0 {
  53640 					v16 = 0
  53641 				} else {
  53642 					v16 = int32(255)
  53643 				}
  53644 				v15 = v16
  53645 			}
  53646 			v13 = v15
  53647 			goto _175
  53648 		_175:
  53649 			v6 = v13
  53650 			goto _168
  53651 		_168:
  53652 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53653 			v19 = v2 * int32(19077) >> int32(8)
  53654 			goto _181
  53655 		_181:
  53656 			v21 = v3 * int32(6419) >> int32(8)
  53657 			goto _183
  53658 		_183:
  53659 			v23 = v4 * int32(13320) >> int32(8)
  53660 			goto _185
  53661 		_185:
  53662 			v25 = v19 - v21 - v23 + int32(8708)
  53663 			if v25 & ^int32(YUV_MASK2) == 0 {
  53664 				v28 = v25 >> int32(YUV_FIX2)
  53665 			} else {
  53666 				if v25 < 0 {
  53667 					v29 = 0
  53668 				} else {
  53669 					v29 = int32(255)
  53670 				}
  53671 				v28 = v29
  53672 			}
  53673 			v26 = v28
  53674 			goto _188
  53675 		_188:
  53676 			v17 = v26
  53677 			goto _179
  53678 		_179:
  53679 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53680 			v32 = v2 * int32(19077) >> int32(8)
  53681 			goto _194
  53682 		_194:
  53683 			v34 = v4 * int32(26149) >> int32(8)
  53684 			goto _196
  53685 		_196:
  53686 			v36 = v32 + v34 - int32(14234)
  53687 			if v36 & ^int32(YUV_MASK2) == 0 {
  53688 				v39 = v36 >> int32(YUV_FIX2)
  53689 			} else {
  53690 				if v36 < 0 {
  53691 					v40 = 0
  53692 				} else {
  53693 					v40 = int32(255)
  53694 				}
  53695 				v39 = v40
  53696 			}
  53697 			v37 = v39
  53698 			goto _199
  53699 		_199:
  53700 			v30 = v37
  53701 			goto _192
  53702 		_192:
  53703 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53704 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53705 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  53706 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  53707 			v3 = libc.Int32FromUint8(uint8(uv11 & uint32(0xff)))
  53708 			v4 = libc.Int32FromUint8(uint8(uv11 >> libc.Int32FromInt32(16)))
  53709 			v5 = v1
  53710 			v8 = v2 * int32(19077) >> int32(8)
  53711 			goto _210
  53712 		_210:
  53713 			v10 = v3 * int32(33050) >> int32(8)
  53714 			goto _212
  53715 		_212:
  53716 			v12 = v8 + v10 - int32(17685)
  53717 			if v12 & ^int32(YUV_MASK2) == 0 {
  53718 				v15 = v12 >> int32(YUV_FIX2)
  53719 			} else {
  53720 				if v12 < 0 {
  53721 					v16 = 0
  53722 				} else {
  53723 					v16 = int32(255)
  53724 				}
  53725 				v15 = v16
  53726 			}
  53727 			v13 = v15
  53728 			goto _215
  53729 		_215:
  53730 			v6 = v13
  53731 			goto _208
  53732 		_208:
  53733 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53734 			v19 = v2 * int32(19077) >> int32(8)
  53735 			goto _221
  53736 		_221:
  53737 			v21 = v3 * int32(6419) >> int32(8)
  53738 			goto _223
  53739 		_223:
  53740 			v23 = v4 * int32(13320) >> int32(8)
  53741 			goto _225
  53742 		_225:
  53743 			v25 = v19 - v21 - v23 + int32(8708)
  53744 			if v25 & ^int32(YUV_MASK2) == 0 {
  53745 				v28 = v25 >> int32(YUV_FIX2)
  53746 			} else {
  53747 				if v25 < 0 {
  53748 					v29 = 0
  53749 				} else {
  53750 					v29 = int32(255)
  53751 				}
  53752 				v28 = v29
  53753 			}
  53754 			v26 = v28
  53755 			goto _228
  53756 		_228:
  53757 			v17 = v26
  53758 			goto _219
  53759 		_219:
  53760 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53761 			v32 = v2 * int32(19077) >> int32(8)
  53762 			goto _234
  53763 		_234:
  53764 			v34 = v4 * int32(26149) >> int32(8)
  53765 			goto _236
  53766 		_236:
  53767 			v36 = v32 + v34 - int32(14234)
  53768 			if v36 & ^int32(YUV_MASK2) == 0 {
  53769 				v39 = v36 >> int32(YUV_FIX2)
  53770 			} else {
  53771 				if v36 < 0 {
  53772 					v40 = 0
  53773 				} else {
  53774 					v40 = int32(255)
  53775 				}
  53776 				v39 = v40
  53777 			}
  53778 			v37 = v39
  53779 			goto _239
  53780 		_239:
  53781 			v30 = v37
  53782 			goto _232
  53783 		_232:
  53784 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53785 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53786 		}
  53787 		tl_uv = t_uv
  53788 		l_uv = uv
  53789 		goto _81
  53790 	_81:
  53791 		;
  53792 		x = x + 1
  53793 	}
  53794 	if !(len1&libc.Int32FromInt32(1) != 0) {
  53795 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53796 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  53797 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  53798 		v3 = libc.Int32FromUint8(uint8(uv04 & uint32(0xff)))
  53799 		v4 = libc.Int32FromUint8(uint8(uv04 >> libc.Int32FromInt32(16)))
  53800 		v5 = v1
  53801 		v8 = v2 * int32(19077) >> int32(8)
  53802 		goto _250
  53803 	_250:
  53804 		v10 = v3 * int32(33050) >> int32(8)
  53805 		goto _252
  53806 	_252:
  53807 		v12 = v8 + v10 - int32(17685)
  53808 		if v12 & ^int32(YUV_MASK2) == 0 {
  53809 			v15 = v12 >> int32(YUV_FIX2)
  53810 		} else {
  53811 			if v12 < 0 {
  53812 				v16 = 0
  53813 			} else {
  53814 				v16 = int32(255)
  53815 			}
  53816 			v15 = v16
  53817 		}
  53818 		v13 = v15
  53819 		goto _255
  53820 	_255:
  53821 		v6 = v13
  53822 		goto _248
  53823 	_248:
  53824 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53825 		v19 = v2 * int32(19077) >> int32(8)
  53826 		goto _261
  53827 	_261:
  53828 		v21 = v3 * int32(6419) >> int32(8)
  53829 		goto _263
  53830 	_263:
  53831 		v23 = v4 * int32(13320) >> int32(8)
  53832 		goto _265
  53833 	_265:
  53834 		v25 = v19 - v21 - v23 + int32(8708)
  53835 		if v25 & ^int32(YUV_MASK2) == 0 {
  53836 			v28 = v25 >> int32(YUV_FIX2)
  53837 		} else {
  53838 			if v25 < 0 {
  53839 				v29 = 0
  53840 			} else {
  53841 				v29 = int32(255)
  53842 			}
  53843 			v28 = v29
  53844 		}
  53845 		v26 = v28
  53846 		goto _268
  53847 	_268:
  53848 		v17 = v26
  53849 		goto _259
  53850 	_259:
  53851 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53852 		v32 = v2 * int32(19077) >> int32(8)
  53853 		goto _274
  53854 	_274:
  53855 		v34 = v4 * int32(26149) >> int32(8)
  53856 		goto _276
  53857 	_276:
  53858 		v36 = v32 + v34 - int32(14234)
  53859 		if v36 & ^int32(YUV_MASK2) == 0 {
  53860 			v39 = v36 >> int32(YUV_FIX2)
  53861 		} else {
  53862 			if v36 < 0 {
  53863 				v40 = 0
  53864 			} else {
  53865 				v40 = int32(255)
  53866 			}
  53867 			v39 = v40
  53868 		}
  53869 		v37 = v39
  53870 		goto _279
  53871 	_279:
  53872 		v30 = v37
  53873 		goto _272
  53874 	_272:
  53875 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53876 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53877 		if bottom_y != libc.UintptrFromInt32(0) {
  53878 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  53879 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  53880 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  53881 			v3 = libc.Int32FromUint8(uint8(uv05 & uint32(0xff)))
  53882 			v4 = libc.Int32FromUint8(uint8(uv05 >> libc.Int32FromInt32(16)))
  53883 			v5 = v1
  53884 			v8 = v2 * int32(19077) >> int32(8)
  53885 			goto _290
  53886 		_290:
  53887 			v10 = v3 * int32(33050) >> int32(8)
  53888 			goto _292
  53889 		_292:
  53890 			v12 = v8 + v10 - int32(17685)
  53891 			if v12 & ^int32(YUV_MASK2) == 0 {
  53892 				v15 = v12 >> int32(YUV_FIX2)
  53893 			} else {
  53894 				if v12 < 0 {
  53895 					v16 = 0
  53896 				} else {
  53897 					v16 = int32(255)
  53898 				}
  53899 				v15 = v16
  53900 			}
  53901 			v13 = v15
  53902 			goto _295
  53903 		_295:
  53904 			v6 = v13
  53905 			goto _288
  53906 		_288:
  53907 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  53908 			v19 = v2 * int32(19077) >> int32(8)
  53909 			goto _301
  53910 		_301:
  53911 			v21 = v3 * int32(6419) >> int32(8)
  53912 			goto _303
  53913 		_303:
  53914 			v23 = v4 * int32(13320) >> int32(8)
  53915 			goto _305
  53916 		_305:
  53917 			v25 = v19 - v21 - v23 + int32(8708)
  53918 			if v25 & ^int32(YUV_MASK2) == 0 {
  53919 				v28 = v25 >> int32(YUV_FIX2)
  53920 			} else {
  53921 				if v25 < 0 {
  53922 					v29 = 0
  53923 				} else {
  53924 					v29 = int32(255)
  53925 				}
  53926 				v28 = v29
  53927 			}
  53928 			v26 = v28
  53929 			goto _308
  53930 		_308:
  53931 			v17 = v26
  53932 			goto _299
  53933 		_299:
  53934 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  53935 			v32 = v2 * int32(19077) >> int32(8)
  53936 			goto _314
  53937 		_314:
  53938 			v34 = v4 * int32(26149) >> int32(8)
  53939 			goto _316
  53940 		_316:
  53941 			v36 = v32 + v34 - int32(14234)
  53942 			if v36 & ^int32(YUV_MASK2) == 0 {
  53943 				v39 = v36 >> int32(YUV_FIX2)
  53944 			} else {
  53945 				if v36 < 0 {
  53946 					v40 = 0
  53947 				} else {
  53948 					v40 = int32(255)
  53949 				}
  53950 				v39 = v40
  53951 			}
  53952 			v37 = v39
  53953 			goto _319
  53954 		_319:
  53955 			v30 = v37
  53956 			goto _312
  53957 		_312:
  53958 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  53959 			**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  53960 		}
  53961 	}
  53962 }
  53963 
  53964 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) {
  53965 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  53966 	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
  53967 	var v1, v5 uintptr
  53968 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  53969 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  53970 	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 */
  53971 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  53972 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  53973 	v1 = top_dst
  53974 	**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  53975 	v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  53976 	v3 = libc.Int32FromUint8(uint8(uv0 & uint32(0xff)))
  53977 	v4 = libc.Int32FromUint8(uint8(uv0 >> libc.Int32FromInt32(16)))
  53978 	v5 = v1 + uintptr(1)
  53979 	v8 = v2 * int32(19077) >> int32(8)
  53980 	goto _9
  53981 _9:
  53982 	v10 = v4 * int32(26149) >> int32(8)
  53983 	goto _11
  53984 _11:
  53985 	v12 = v8 + v10 - int32(14234)
  53986 	if v12 & ^int32(YUV_MASK2) == 0 {
  53987 		v15 = v12 >> int32(YUV_FIX2)
  53988 	} else {
  53989 		if v12 < 0 {
  53990 			v16 = 0
  53991 		} else {
  53992 			v16 = int32(255)
  53993 		}
  53994 		v15 = v16
  53995 	}
  53996 	v13 = v15
  53997 	goto _14
  53998 _14:
  53999 	v6 = v13
  54000 	goto _7
  54001 _7:
  54002 	**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54003 	v19 = v2 * int32(19077) >> int32(8)
  54004 	goto _20
  54005 _20:
  54006 	v21 = v3 * int32(6419) >> int32(8)
  54007 	goto _22
  54008 _22:
  54009 	v23 = v4 * int32(13320) >> int32(8)
  54010 	goto _24
  54011 _24:
  54012 	v25 = v19 - v21 - v23 + int32(8708)
  54013 	if v25 & ^int32(YUV_MASK2) == 0 {
  54014 		v28 = v25 >> int32(YUV_FIX2)
  54015 	} else {
  54016 		if v25 < 0 {
  54017 			v29 = 0
  54018 		} else {
  54019 			v29 = int32(255)
  54020 		}
  54021 		v28 = v29
  54022 	}
  54023 	v26 = v28
  54024 	goto _27
  54025 _27:
  54026 	v17 = v26
  54027 	goto _18
  54028 _18:
  54029 	**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54030 	v32 = v2 * int32(19077) >> int32(8)
  54031 	goto _33
  54032 _33:
  54033 	v34 = v3 * int32(33050) >> int32(8)
  54034 	goto _35
  54035 _35:
  54036 	v36 = v32 + v34 - int32(17685)
  54037 	if v36 & ^int32(YUV_MASK2) == 0 {
  54038 		v39 = v36 >> int32(YUV_FIX2)
  54039 	} else {
  54040 		if v36 < 0 {
  54041 			v40 = 0
  54042 		} else {
  54043 			v40 = int32(255)
  54044 		}
  54045 		v39 = v40
  54046 	}
  54047 	v37 = v39
  54048 	goto _38
  54049 _38:
  54050 	v30 = v37
  54051 	goto _31
  54052 _31:
  54053 	**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54054 	if bottom_y != libc.UintptrFromInt32(0) {
  54055 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54056 		v1 = bottom_dst
  54057 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54058 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  54059 		v3 = libc.Int32FromUint8(uint8(uv01 & uint32(0xff)))
  54060 		v4 = libc.Int32FromUint8(uint8(uv01 >> libc.Int32FromInt32(16)))
  54061 		v5 = v1 + uintptr(1)
  54062 		v8 = v2 * int32(19077) >> int32(8)
  54063 		goto _49
  54064 	_49:
  54065 		v10 = v4 * int32(26149) >> int32(8)
  54066 		goto _51
  54067 	_51:
  54068 		v12 = v8 + v10 - int32(14234)
  54069 		if v12 & ^int32(YUV_MASK2) == 0 {
  54070 			v15 = v12 >> int32(YUV_FIX2)
  54071 		} else {
  54072 			if v12 < 0 {
  54073 				v16 = 0
  54074 			} else {
  54075 				v16 = int32(255)
  54076 			}
  54077 			v15 = v16
  54078 		}
  54079 		v13 = v15
  54080 		goto _54
  54081 	_54:
  54082 		v6 = v13
  54083 		goto _47
  54084 	_47:
  54085 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54086 		v19 = v2 * int32(19077) >> int32(8)
  54087 		goto _60
  54088 	_60:
  54089 		v21 = v3 * int32(6419) >> int32(8)
  54090 		goto _62
  54091 	_62:
  54092 		v23 = v4 * int32(13320) >> int32(8)
  54093 		goto _64
  54094 	_64:
  54095 		v25 = v19 - v21 - v23 + int32(8708)
  54096 		if v25 & ^int32(YUV_MASK2) == 0 {
  54097 			v28 = v25 >> int32(YUV_FIX2)
  54098 		} else {
  54099 			if v25 < 0 {
  54100 				v29 = 0
  54101 			} else {
  54102 				v29 = int32(255)
  54103 			}
  54104 			v28 = v29
  54105 		}
  54106 		v26 = v28
  54107 		goto _67
  54108 	_67:
  54109 		v17 = v26
  54110 		goto _58
  54111 	_58:
  54112 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54113 		v32 = v2 * int32(19077) >> int32(8)
  54114 		goto _73
  54115 	_73:
  54116 		v34 = v3 * int32(33050) >> int32(8)
  54117 		goto _75
  54118 	_75:
  54119 		v36 = v32 + v34 - int32(17685)
  54120 		if v36 & ^int32(YUV_MASK2) == 0 {
  54121 			v39 = v36 >> int32(YUV_FIX2)
  54122 		} else {
  54123 			if v36 < 0 {
  54124 				v40 = 0
  54125 			} else {
  54126 				v40 = int32(255)
  54127 			}
  54128 			v39 = v40
  54129 		}
  54130 		v37 = v39
  54131 		goto _78
  54132 	_78:
  54133 		v30 = v37
  54134 		goto _71
  54135 	_71:
  54136 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54137 	}
  54138 	x = int32(1)
  54139 	for {
  54140 		if !(x <= last_pixel_pair) {
  54141 			break
  54142 		}
  54143 		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 */
  54144 		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*/
  54145 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  54146 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  54147 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  54148 		uv02 = (diag_12 + tl_uv) >> int32(1)
  54149 		uv1 = (diag_03 + t_uv) >> int32(1)
  54150 		v1 = top_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54151 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54152 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  54153 		v3 = libc.Int32FromUint8(uint8(uv02 & uint32(0xff)))
  54154 		v4 = libc.Int32FromUint8(uint8(uv02 >> libc.Int32FromInt32(16)))
  54155 		v5 = v1 + uintptr(1)
  54156 		v8 = v2 * int32(19077) >> int32(8)
  54157 		goto _90
  54158 	_90:
  54159 		v10 = v4 * int32(26149) >> int32(8)
  54160 		goto _92
  54161 	_92:
  54162 		v12 = v8 + v10 - int32(14234)
  54163 		if v12 & ^int32(YUV_MASK2) == 0 {
  54164 			v15 = v12 >> int32(YUV_FIX2)
  54165 		} else {
  54166 			if v12 < 0 {
  54167 				v16 = 0
  54168 			} else {
  54169 				v16 = int32(255)
  54170 			}
  54171 			v15 = v16
  54172 		}
  54173 		v13 = v15
  54174 		goto _95
  54175 	_95:
  54176 		v6 = v13
  54177 		goto _88
  54178 	_88:
  54179 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54180 		v19 = v2 * int32(19077) >> int32(8)
  54181 		goto _101
  54182 	_101:
  54183 		v21 = v3 * int32(6419) >> int32(8)
  54184 		goto _103
  54185 	_103:
  54186 		v23 = v4 * int32(13320) >> int32(8)
  54187 		goto _105
  54188 	_105:
  54189 		v25 = v19 - v21 - v23 + int32(8708)
  54190 		if v25 & ^int32(YUV_MASK2) == 0 {
  54191 			v28 = v25 >> int32(YUV_FIX2)
  54192 		} else {
  54193 			if v25 < 0 {
  54194 				v29 = 0
  54195 			} else {
  54196 				v29 = int32(255)
  54197 			}
  54198 			v28 = v29
  54199 		}
  54200 		v26 = v28
  54201 		goto _108
  54202 	_108:
  54203 		v17 = v26
  54204 		goto _99
  54205 	_99:
  54206 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54207 		v32 = v2 * int32(19077) >> int32(8)
  54208 		goto _114
  54209 	_114:
  54210 		v34 = v3 * int32(33050) >> int32(8)
  54211 		goto _116
  54212 	_116:
  54213 		v36 = v32 + v34 - int32(17685)
  54214 		if v36 & ^int32(YUV_MASK2) == 0 {
  54215 			v39 = v36 >> int32(YUV_FIX2)
  54216 		} else {
  54217 			if v36 < 0 {
  54218 				v40 = 0
  54219 			} else {
  54220 				v40 = int32(255)
  54221 			}
  54222 			v39 = v40
  54223 		}
  54224 		v37 = v39
  54225 		goto _119
  54226 	_119:
  54227 		v30 = v37
  54228 		goto _112
  54229 	_112:
  54230 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54231 		v1 = top_dst + uintptr((int32(2)*x-0)*int32(4))
  54232 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54233 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  54234 		v3 = libc.Int32FromUint8(uint8(uv1 & uint32(0xff)))
  54235 		v4 = libc.Int32FromUint8(uint8(uv1 >> libc.Int32FromInt32(16)))
  54236 		v5 = v1 + uintptr(1)
  54237 		v8 = v2 * int32(19077) >> int32(8)
  54238 		goto _130
  54239 	_130:
  54240 		v10 = v4 * int32(26149) >> int32(8)
  54241 		goto _132
  54242 	_132:
  54243 		v12 = v8 + v10 - int32(14234)
  54244 		if v12 & ^int32(YUV_MASK2) == 0 {
  54245 			v15 = v12 >> int32(YUV_FIX2)
  54246 		} else {
  54247 			if v12 < 0 {
  54248 				v16 = 0
  54249 			} else {
  54250 				v16 = int32(255)
  54251 			}
  54252 			v15 = v16
  54253 		}
  54254 		v13 = v15
  54255 		goto _135
  54256 	_135:
  54257 		v6 = v13
  54258 		goto _128
  54259 	_128:
  54260 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54261 		v19 = v2 * int32(19077) >> int32(8)
  54262 		goto _141
  54263 	_141:
  54264 		v21 = v3 * int32(6419) >> int32(8)
  54265 		goto _143
  54266 	_143:
  54267 		v23 = v4 * int32(13320) >> int32(8)
  54268 		goto _145
  54269 	_145:
  54270 		v25 = v19 - v21 - v23 + int32(8708)
  54271 		if v25 & ^int32(YUV_MASK2) == 0 {
  54272 			v28 = v25 >> int32(YUV_FIX2)
  54273 		} else {
  54274 			if v25 < 0 {
  54275 				v29 = 0
  54276 			} else {
  54277 				v29 = int32(255)
  54278 			}
  54279 			v28 = v29
  54280 		}
  54281 		v26 = v28
  54282 		goto _148
  54283 	_148:
  54284 		v17 = v26
  54285 		goto _139
  54286 	_139:
  54287 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54288 		v32 = v2 * int32(19077) >> int32(8)
  54289 		goto _154
  54290 	_154:
  54291 		v34 = v3 * int32(33050) >> int32(8)
  54292 		goto _156
  54293 	_156:
  54294 		v36 = v32 + v34 - int32(17685)
  54295 		if v36 & ^int32(YUV_MASK2) == 0 {
  54296 			v39 = v36 >> int32(YUV_FIX2)
  54297 		} else {
  54298 			if v36 < 0 {
  54299 				v40 = 0
  54300 			} else {
  54301 				v40 = int32(255)
  54302 			}
  54303 			v39 = v40
  54304 		}
  54305 		v37 = v39
  54306 		goto _159
  54307 	_159:
  54308 		v30 = v37
  54309 		goto _152
  54310 	_152:
  54311 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54312 		if bottom_y != libc.UintptrFromInt32(0) {
  54313 			uv03 = (diag_03 + l_uv) >> int32(1)
  54314 			uv11 = (diag_12 + uv) >> int32(1)
  54315 			v1 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(4))
  54316 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54317 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  54318 			v3 = libc.Int32FromUint8(uint8(uv03 & uint32(0xff)))
  54319 			v4 = libc.Int32FromUint8(uint8(uv03 >> libc.Int32FromInt32(16)))
  54320 			v5 = v1 + uintptr(1)
  54321 			v8 = v2 * int32(19077) >> int32(8)
  54322 			goto _170
  54323 		_170:
  54324 			v10 = v4 * int32(26149) >> int32(8)
  54325 			goto _172
  54326 		_172:
  54327 			v12 = v8 + v10 - int32(14234)
  54328 			if v12 & ^int32(YUV_MASK2) == 0 {
  54329 				v15 = v12 >> int32(YUV_FIX2)
  54330 			} else {
  54331 				if v12 < 0 {
  54332 					v16 = 0
  54333 				} else {
  54334 					v16 = int32(255)
  54335 				}
  54336 				v15 = v16
  54337 			}
  54338 			v13 = v15
  54339 			goto _175
  54340 		_175:
  54341 			v6 = v13
  54342 			goto _168
  54343 		_168:
  54344 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54345 			v19 = v2 * int32(19077) >> int32(8)
  54346 			goto _181
  54347 		_181:
  54348 			v21 = v3 * int32(6419) >> int32(8)
  54349 			goto _183
  54350 		_183:
  54351 			v23 = v4 * int32(13320) >> int32(8)
  54352 			goto _185
  54353 		_185:
  54354 			v25 = v19 - v21 - v23 + int32(8708)
  54355 			if v25 & ^int32(YUV_MASK2) == 0 {
  54356 				v28 = v25 >> int32(YUV_FIX2)
  54357 			} else {
  54358 				if v25 < 0 {
  54359 					v29 = 0
  54360 				} else {
  54361 					v29 = int32(255)
  54362 				}
  54363 				v28 = v29
  54364 			}
  54365 			v26 = v28
  54366 			goto _188
  54367 		_188:
  54368 			v17 = v26
  54369 			goto _179
  54370 		_179:
  54371 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54372 			v32 = v2 * int32(19077) >> int32(8)
  54373 			goto _194
  54374 		_194:
  54375 			v34 = v3 * int32(33050) >> int32(8)
  54376 			goto _196
  54377 		_196:
  54378 			v36 = v32 + v34 - int32(17685)
  54379 			if v36 & ^int32(YUV_MASK2) == 0 {
  54380 				v39 = v36 >> int32(YUV_FIX2)
  54381 			} else {
  54382 				if v36 < 0 {
  54383 					v40 = 0
  54384 				} else {
  54385 					v40 = int32(255)
  54386 				}
  54387 				v39 = v40
  54388 			}
  54389 			v37 = v39
  54390 			goto _199
  54391 		_199:
  54392 			v30 = v37
  54393 			goto _192
  54394 		_192:
  54395 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54396 			v1 = bottom_dst + uintptr((int32(2)*x+0)*int32(4))
  54397 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54398 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  54399 			v3 = libc.Int32FromUint8(uint8(uv11 & uint32(0xff)))
  54400 			v4 = libc.Int32FromUint8(uint8(uv11 >> libc.Int32FromInt32(16)))
  54401 			v5 = v1 + uintptr(1)
  54402 			v8 = v2 * int32(19077) >> int32(8)
  54403 			goto _210
  54404 		_210:
  54405 			v10 = v4 * int32(26149) >> int32(8)
  54406 			goto _212
  54407 		_212:
  54408 			v12 = v8 + v10 - int32(14234)
  54409 			if v12 & ^int32(YUV_MASK2) == 0 {
  54410 				v15 = v12 >> int32(YUV_FIX2)
  54411 			} else {
  54412 				if v12 < 0 {
  54413 					v16 = 0
  54414 				} else {
  54415 					v16 = int32(255)
  54416 				}
  54417 				v15 = v16
  54418 			}
  54419 			v13 = v15
  54420 			goto _215
  54421 		_215:
  54422 			v6 = v13
  54423 			goto _208
  54424 		_208:
  54425 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54426 			v19 = v2 * int32(19077) >> int32(8)
  54427 			goto _221
  54428 		_221:
  54429 			v21 = v3 * int32(6419) >> int32(8)
  54430 			goto _223
  54431 		_223:
  54432 			v23 = v4 * int32(13320) >> int32(8)
  54433 			goto _225
  54434 		_225:
  54435 			v25 = v19 - v21 - v23 + int32(8708)
  54436 			if v25 & ^int32(YUV_MASK2) == 0 {
  54437 				v28 = v25 >> int32(YUV_FIX2)
  54438 			} else {
  54439 				if v25 < 0 {
  54440 					v29 = 0
  54441 				} else {
  54442 					v29 = int32(255)
  54443 				}
  54444 				v28 = v29
  54445 			}
  54446 			v26 = v28
  54447 			goto _228
  54448 		_228:
  54449 			v17 = v26
  54450 			goto _219
  54451 		_219:
  54452 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54453 			v32 = v2 * int32(19077) >> int32(8)
  54454 			goto _234
  54455 		_234:
  54456 			v34 = v3 * int32(33050) >> int32(8)
  54457 			goto _236
  54458 		_236:
  54459 			v36 = v32 + v34 - int32(17685)
  54460 			if v36 & ^int32(YUV_MASK2) == 0 {
  54461 				v39 = v36 >> int32(YUV_FIX2)
  54462 			} else {
  54463 				if v36 < 0 {
  54464 					v40 = 0
  54465 				} else {
  54466 					v40 = int32(255)
  54467 				}
  54468 				v39 = v40
  54469 			}
  54470 			v37 = v39
  54471 			goto _239
  54472 		_239:
  54473 			v30 = v37
  54474 			goto _232
  54475 		_232:
  54476 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54477 		}
  54478 		tl_uv = t_uv
  54479 		l_uv = uv
  54480 		goto _81
  54481 	_81:
  54482 		;
  54483 		x = x + 1
  54484 	}
  54485 	if !(len1&libc.Int32FromInt32(1) != 0) {
  54486 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54487 		v1 = top_dst + uintptr((len1-int32(1))*int32(4))
  54488 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54489 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  54490 		v3 = libc.Int32FromUint8(uint8(uv04 & uint32(0xff)))
  54491 		v4 = libc.Int32FromUint8(uint8(uv04 >> libc.Int32FromInt32(16)))
  54492 		v5 = v1 + uintptr(1)
  54493 		v8 = v2 * int32(19077) >> int32(8)
  54494 		goto _250
  54495 	_250:
  54496 		v10 = v4 * int32(26149) >> int32(8)
  54497 		goto _252
  54498 	_252:
  54499 		v12 = v8 + v10 - int32(14234)
  54500 		if v12 & ^int32(YUV_MASK2) == 0 {
  54501 			v15 = v12 >> int32(YUV_FIX2)
  54502 		} else {
  54503 			if v12 < 0 {
  54504 				v16 = 0
  54505 			} else {
  54506 				v16 = int32(255)
  54507 			}
  54508 			v15 = v16
  54509 		}
  54510 		v13 = v15
  54511 		goto _255
  54512 	_255:
  54513 		v6 = v13
  54514 		goto _248
  54515 	_248:
  54516 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54517 		v19 = v2 * int32(19077) >> int32(8)
  54518 		goto _261
  54519 	_261:
  54520 		v21 = v3 * int32(6419) >> int32(8)
  54521 		goto _263
  54522 	_263:
  54523 		v23 = v4 * int32(13320) >> int32(8)
  54524 		goto _265
  54525 	_265:
  54526 		v25 = v19 - v21 - v23 + int32(8708)
  54527 		if v25 & ^int32(YUV_MASK2) == 0 {
  54528 			v28 = v25 >> int32(YUV_FIX2)
  54529 		} else {
  54530 			if v25 < 0 {
  54531 				v29 = 0
  54532 			} else {
  54533 				v29 = int32(255)
  54534 			}
  54535 			v28 = v29
  54536 		}
  54537 		v26 = v28
  54538 		goto _268
  54539 	_268:
  54540 		v17 = v26
  54541 		goto _259
  54542 	_259:
  54543 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54544 		v32 = v2 * int32(19077) >> int32(8)
  54545 		goto _274
  54546 	_274:
  54547 		v34 = v3 * int32(33050) >> int32(8)
  54548 		goto _276
  54549 	_276:
  54550 		v36 = v32 + v34 - int32(17685)
  54551 		if v36 & ^int32(YUV_MASK2) == 0 {
  54552 			v39 = v36 >> int32(YUV_FIX2)
  54553 		} else {
  54554 			if v36 < 0 {
  54555 				v40 = 0
  54556 			} else {
  54557 				v40 = int32(255)
  54558 			}
  54559 			v39 = v40
  54560 		}
  54561 		v37 = v39
  54562 		goto _279
  54563 	_279:
  54564 		v30 = v37
  54565 		goto _272
  54566 	_272:
  54567 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54568 		if bottom_y != libc.UintptrFromInt32(0) {
  54569 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54570 			v1 = bottom_dst + uintptr((len1-int32(1))*int32(4))
  54571 			**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  54572 			v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  54573 			v3 = libc.Int32FromUint8(uint8(uv05 & uint32(0xff)))
  54574 			v4 = libc.Int32FromUint8(uint8(uv05 >> libc.Int32FromInt32(16)))
  54575 			v5 = v1 + uintptr(1)
  54576 			v8 = v2 * int32(19077) >> int32(8)
  54577 			goto _290
  54578 		_290:
  54579 			v10 = v4 * int32(26149) >> int32(8)
  54580 			goto _292
  54581 		_292:
  54582 			v12 = v8 + v10 - int32(14234)
  54583 			if v12 & ^int32(YUV_MASK2) == 0 {
  54584 				v15 = v12 >> int32(YUV_FIX2)
  54585 			} else {
  54586 				if v12 < 0 {
  54587 					v16 = 0
  54588 				} else {
  54589 					v16 = int32(255)
  54590 				}
  54591 				v15 = v16
  54592 			}
  54593 			v13 = v15
  54594 			goto _295
  54595 		_295:
  54596 			v6 = v13
  54597 			goto _288
  54598 		_288:
  54599 			**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v6)
  54600 			v19 = v2 * int32(19077) >> int32(8)
  54601 			goto _301
  54602 		_301:
  54603 			v21 = v3 * int32(6419) >> int32(8)
  54604 			goto _303
  54605 		_303:
  54606 			v23 = v4 * int32(13320) >> int32(8)
  54607 			goto _305
  54608 		_305:
  54609 			v25 = v19 - v21 - v23 + int32(8708)
  54610 			if v25 & ^int32(YUV_MASK2) == 0 {
  54611 				v28 = v25 >> int32(YUV_FIX2)
  54612 			} else {
  54613 				if v25 < 0 {
  54614 					v29 = 0
  54615 				} else {
  54616 					v29 = int32(255)
  54617 				}
  54618 				v28 = v29
  54619 			}
  54620 			v26 = v28
  54621 			goto _308
  54622 		_308:
  54623 			v17 = v26
  54624 			goto _299
  54625 		_299:
  54626 			**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  54627 			v32 = v2 * int32(19077) >> int32(8)
  54628 			goto _314
  54629 		_314:
  54630 			v34 = v3 * int32(33050) >> int32(8)
  54631 			goto _316
  54632 		_316:
  54633 			v36 = v32 + v34 - int32(17685)
  54634 			if v36 & ^int32(YUV_MASK2) == 0 {
  54635 				v39 = v36 >> int32(YUV_FIX2)
  54636 			} else {
  54637 				if v36 < 0 {
  54638 					v40 = 0
  54639 				} else {
  54640 					v40 = int32(255)
  54641 				}
  54642 				v39 = v40
  54643 			}
  54644 			v37 = v39
  54645 			goto _319
  54646 		_319:
  54647 			v30 = v37
  54648 			goto _312
  54649 		_312:
  54650 			**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  54651 		}
  54652 	}
  54653 }
  54654 
  54655 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) {
  54656 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  54657 	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
  54658 	var v4 uintptr
  54659 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  54660 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  54661 	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 */
  54662 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  54663 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  54664 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  54665 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  54666 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  54667 	v4 = top_dst
  54668 	v7 = v1 * int32(19077) >> int32(8)
  54669 	goto _8
  54670 _8:
  54671 	v9 = v3 * int32(26149) >> int32(8)
  54672 	goto _10
  54673 _10:
  54674 	v11 = v7 + v9 - int32(14234)
  54675 	if v11 & ^int32(YUV_MASK2) == 0 {
  54676 		v14 = v11 >> int32(YUV_FIX2)
  54677 	} else {
  54678 		if v11 < 0 {
  54679 			v15 = 0
  54680 		} else {
  54681 			v15 = int32(255)
  54682 		}
  54683 		v14 = v15
  54684 	}
  54685 	v12 = v14
  54686 	goto _13
  54687 _13:
  54688 	v5 = v12
  54689 	goto _6
  54690 _6:
  54691 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54692 	v18 = v1 * int32(19077) >> int32(8)
  54693 	goto _19
  54694 _19:
  54695 	v20 = v2 * int32(6419) >> int32(8)
  54696 	goto _21
  54697 _21:
  54698 	v22 = v3 * int32(13320) >> int32(8)
  54699 	goto _23
  54700 _23:
  54701 	v24 = v18 - v20 - v22 + int32(8708)
  54702 	if v24 & ^int32(YUV_MASK2) == 0 {
  54703 		v27 = v24 >> int32(YUV_FIX2)
  54704 	} else {
  54705 		if v24 < 0 {
  54706 			v28 = 0
  54707 		} else {
  54708 			v28 = int32(255)
  54709 		}
  54710 		v27 = v28
  54711 	}
  54712 	v25 = v27
  54713 	goto _26
  54714 _26:
  54715 	v16 = v25
  54716 	goto _17
  54717 _17:
  54718 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54719 	v31 = v1 * int32(19077) >> int32(8)
  54720 	goto _32
  54721 _32:
  54722 	v33 = v2 * int32(33050) >> int32(8)
  54723 	goto _34
  54724 _34:
  54725 	v35 = v31 + v33 - int32(17685)
  54726 	if v35 & ^int32(YUV_MASK2) == 0 {
  54727 		v38 = v35 >> int32(YUV_FIX2)
  54728 	} else {
  54729 		if v35 < 0 {
  54730 			v39 = 0
  54731 		} else {
  54732 			v39 = int32(255)
  54733 		}
  54734 		v38 = v39
  54735 	}
  54736 	v36 = v38
  54737 	goto _37
  54738 _37:
  54739 	v29 = v36
  54740 	goto _30
  54741 _30:
  54742 	**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54743 	if bottom_y != libc.UintptrFromInt32(0) {
  54744 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  54745 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  54746 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  54747 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  54748 		v4 = bottom_dst
  54749 		v7 = v1 * int32(19077) >> int32(8)
  54750 		goto _47
  54751 	_47:
  54752 		v9 = v3 * int32(26149) >> int32(8)
  54753 		goto _49
  54754 	_49:
  54755 		v11 = v7 + v9 - int32(14234)
  54756 		if v11 & ^int32(YUV_MASK2) == 0 {
  54757 			v14 = v11 >> int32(YUV_FIX2)
  54758 		} else {
  54759 			if v11 < 0 {
  54760 				v15 = 0
  54761 			} else {
  54762 				v15 = int32(255)
  54763 			}
  54764 			v14 = v15
  54765 		}
  54766 		v12 = v14
  54767 		goto _52
  54768 	_52:
  54769 		v5 = v12
  54770 		goto _45
  54771 	_45:
  54772 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54773 		v18 = v1 * int32(19077) >> int32(8)
  54774 		goto _58
  54775 	_58:
  54776 		v20 = v2 * int32(6419) >> int32(8)
  54777 		goto _60
  54778 	_60:
  54779 		v22 = v3 * int32(13320) >> int32(8)
  54780 		goto _62
  54781 	_62:
  54782 		v24 = v18 - v20 - v22 + int32(8708)
  54783 		if v24 & ^int32(YUV_MASK2) == 0 {
  54784 			v27 = v24 >> int32(YUV_FIX2)
  54785 		} else {
  54786 			if v24 < 0 {
  54787 				v28 = 0
  54788 			} else {
  54789 				v28 = int32(255)
  54790 			}
  54791 			v27 = v28
  54792 		}
  54793 		v25 = v27
  54794 		goto _65
  54795 	_65:
  54796 		v16 = v25
  54797 		goto _56
  54798 	_56:
  54799 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54800 		v31 = v1 * int32(19077) >> int32(8)
  54801 		goto _71
  54802 	_71:
  54803 		v33 = v2 * int32(33050) >> int32(8)
  54804 		goto _73
  54805 	_73:
  54806 		v35 = v31 + v33 - int32(17685)
  54807 		if v35 & ^int32(YUV_MASK2) == 0 {
  54808 			v38 = v35 >> int32(YUV_FIX2)
  54809 		} else {
  54810 			if v35 < 0 {
  54811 				v39 = 0
  54812 			} else {
  54813 				v39 = int32(255)
  54814 			}
  54815 			v38 = v39
  54816 		}
  54817 		v36 = v38
  54818 		goto _76
  54819 	_76:
  54820 		v29 = v36
  54821 		goto _69
  54822 	_69:
  54823 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54824 	}
  54825 	x = int32(1)
  54826 	for {
  54827 		if !(x <= last_pixel_pair) {
  54828 			break
  54829 		}
  54830 		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 */
  54831 		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*/
  54832 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  54833 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  54834 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  54835 		uv02 = (diag_12 + tl_uv) >> int32(1)
  54836 		uv1 = (diag_03 + t_uv) >> int32(1)
  54837 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  54838 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  54839 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  54840 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  54841 		v7 = v1 * int32(19077) >> int32(8)
  54842 		goto _87
  54843 	_87:
  54844 		v9 = v3 * int32(26149) >> int32(8)
  54845 		goto _89
  54846 	_89:
  54847 		v11 = v7 + v9 - int32(14234)
  54848 		if v11 & ^int32(YUV_MASK2) == 0 {
  54849 			v14 = v11 >> int32(YUV_FIX2)
  54850 		} else {
  54851 			if v11 < 0 {
  54852 				v15 = 0
  54853 			} else {
  54854 				v15 = int32(255)
  54855 			}
  54856 			v14 = v15
  54857 		}
  54858 		v12 = v14
  54859 		goto _92
  54860 	_92:
  54861 		v5 = v12
  54862 		goto _85
  54863 	_85:
  54864 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54865 		v18 = v1 * int32(19077) >> int32(8)
  54866 		goto _98
  54867 	_98:
  54868 		v20 = v2 * int32(6419) >> int32(8)
  54869 		goto _100
  54870 	_100:
  54871 		v22 = v3 * int32(13320) >> int32(8)
  54872 		goto _102
  54873 	_102:
  54874 		v24 = v18 - v20 - v22 + int32(8708)
  54875 		if v24 & ^int32(YUV_MASK2) == 0 {
  54876 			v27 = v24 >> int32(YUV_FIX2)
  54877 		} else {
  54878 			if v24 < 0 {
  54879 				v28 = 0
  54880 			} else {
  54881 				v28 = int32(255)
  54882 			}
  54883 			v27 = v28
  54884 		}
  54885 		v25 = v27
  54886 		goto _105
  54887 	_105:
  54888 		v16 = v25
  54889 		goto _96
  54890 	_96:
  54891 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54892 		v31 = v1 * int32(19077) >> int32(8)
  54893 		goto _111
  54894 	_111:
  54895 		v33 = v2 * int32(33050) >> int32(8)
  54896 		goto _113
  54897 	_113:
  54898 		v35 = v31 + v33 - int32(17685)
  54899 		if v35 & ^int32(YUV_MASK2) == 0 {
  54900 			v38 = v35 >> int32(YUV_FIX2)
  54901 		} else {
  54902 			if v35 < 0 {
  54903 				v39 = 0
  54904 			} else {
  54905 				v39 = int32(255)
  54906 			}
  54907 			v38 = v39
  54908 		}
  54909 		v36 = v38
  54910 		goto _116
  54911 	_116:
  54912 		v29 = v36
  54913 		goto _109
  54914 	_109:
  54915 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54916 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  54917 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  54918 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  54919 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  54920 		v7 = v1 * int32(19077) >> int32(8)
  54921 		goto _126
  54922 	_126:
  54923 		v9 = v3 * int32(26149) >> int32(8)
  54924 		goto _128
  54925 	_128:
  54926 		v11 = v7 + v9 - int32(14234)
  54927 		if v11 & ^int32(YUV_MASK2) == 0 {
  54928 			v14 = v11 >> int32(YUV_FIX2)
  54929 		} else {
  54930 			if v11 < 0 {
  54931 				v15 = 0
  54932 			} else {
  54933 				v15 = int32(255)
  54934 			}
  54935 			v14 = v15
  54936 		}
  54937 		v12 = v14
  54938 		goto _131
  54939 	_131:
  54940 		v5 = v12
  54941 		goto _124
  54942 	_124:
  54943 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  54944 		v18 = v1 * int32(19077) >> int32(8)
  54945 		goto _137
  54946 	_137:
  54947 		v20 = v2 * int32(6419) >> int32(8)
  54948 		goto _139
  54949 	_139:
  54950 		v22 = v3 * int32(13320) >> int32(8)
  54951 		goto _141
  54952 	_141:
  54953 		v24 = v18 - v20 - v22 + int32(8708)
  54954 		if v24 & ^int32(YUV_MASK2) == 0 {
  54955 			v27 = v24 >> int32(YUV_FIX2)
  54956 		} else {
  54957 			if v24 < 0 {
  54958 				v28 = 0
  54959 			} else {
  54960 				v28 = int32(255)
  54961 			}
  54962 			v27 = v28
  54963 		}
  54964 		v25 = v27
  54965 		goto _144
  54966 	_144:
  54967 		v16 = v25
  54968 		goto _135
  54969 	_135:
  54970 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  54971 		v31 = v1 * int32(19077) >> int32(8)
  54972 		goto _150
  54973 	_150:
  54974 		v33 = v2 * int32(33050) >> int32(8)
  54975 		goto _152
  54976 	_152:
  54977 		v35 = v31 + v33 - int32(17685)
  54978 		if v35 & ^int32(YUV_MASK2) == 0 {
  54979 			v38 = v35 >> int32(YUV_FIX2)
  54980 		} else {
  54981 			if v35 < 0 {
  54982 				v39 = 0
  54983 			} else {
  54984 				v39 = int32(255)
  54985 			}
  54986 			v38 = v39
  54987 		}
  54988 		v36 = v38
  54989 		goto _155
  54990 	_155:
  54991 		v29 = v36
  54992 		goto _148
  54993 	_148:
  54994 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  54995 		if bottom_y != libc.UintptrFromInt32(0) {
  54996 			uv03 = (diag_03 + l_uv) >> int32(1)
  54997 			uv11 = (diag_12 + uv) >> int32(1)
  54998 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  54999 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  55000 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  55001 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55002 			v7 = v1 * int32(19077) >> int32(8)
  55003 			goto _165
  55004 		_165:
  55005 			v9 = v3 * int32(26149) >> int32(8)
  55006 			goto _167
  55007 		_167:
  55008 			v11 = v7 + v9 - int32(14234)
  55009 			if v11 & ^int32(YUV_MASK2) == 0 {
  55010 				v14 = v11 >> int32(YUV_FIX2)
  55011 			} else {
  55012 				if v11 < 0 {
  55013 					v15 = 0
  55014 				} else {
  55015 					v15 = int32(255)
  55016 				}
  55017 				v14 = v15
  55018 			}
  55019 			v12 = v14
  55020 			goto _170
  55021 		_170:
  55022 			v5 = v12
  55023 			goto _163
  55024 		_163:
  55025 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55026 			v18 = v1 * int32(19077) >> int32(8)
  55027 			goto _176
  55028 		_176:
  55029 			v20 = v2 * int32(6419) >> int32(8)
  55030 			goto _178
  55031 		_178:
  55032 			v22 = v3 * int32(13320) >> int32(8)
  55033 			goto _180
  55034 		_180:
  55035 			v24 = v18 - v20 - v22 + int32(8708)
  55036 			if v24 & ^int32(YUV_MASK2) == 0 {
  55037 				v27 = v24 >> int32(YUV_FIX2)
  55038 			} else {
  55039 				if v24 < 0 {
  55040 					v28 = 0
  55041 				} else {
  55042 					v28 = int32(255)
  55043 				}
  55044 				v27 = v28
  55045 			}
  55046 			v25 = v27
  55047 			goto _183
  55048 		_183:
  55049 			v16 = v25
  55050 			goto _174
  55051 		_174:
  55052 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55053 			v31 = v1 * int32(19077) >> int32(8)
  55054 			goto _189
  55055 		_189:
  55056 			v33 = v2 * int32(33050) >> int32(8)
  55057 			goto _191
  55058 		_191:
  55059 			v35 = v31 + v33 - int32(17685)
  55060 			if v35 & ^int32(YUV_MASK2) == 0 {
  55061 				v38 = v35 >> int32(YUV_FIX2)
  55062 			} else {
  55063 				if v35 < 0 {
  55064 					v39 = 0
  55065 				} else {
  55066 					v39 = int32(255)
  55067 				}
  55068 				v38 = v39
  55069 			}
  55070 			v36 = v38
  55071 			goto _194
  55072 		_194:
  55073 			v29 = v36
  55074 			goto _187
  55075 		_187:
  55076 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55077 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55078 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  55079 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  55080 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55081 			v7 = v1 * int32(19077) >> int32(8)
  55082 			goto _204
  55083 		_204:
  55084 			v9 = v3 * int32(26149) >> int32(8)
  55085 			goto _206
  55086 		_206:
  55087 			v11 = v7 + v9 - int32(14234)
  55088 			if v11 & ^int32(YUV_MASK2) == 0 {
  55089 				v14 = v11 >> int32(YUV_FIX2)
  55090 			} else {
  55091 				if v11 < 0 {
  55092 					v15 = 0
  55093 				} else {
  55094 					v15 = int32(255)
  55095 				}
  55096 				v14 = v15
  55097 			}
  55098 			v12 = v14
  55099 			goto _209
  55100 		_209:
  55101 			v5 = v12
  55102 			goto _202
  55103 		_202:
  55104 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55105 			v18 = v1 * int32(19077) >> int32(8)
  55106 			goto _215
  55107 		_215:
  55108 			v20 = v2 * int32(6419) >> int32(8)
  55109 			goto _217
  55110 		_217:
  55111 			v22 = v3 * int32(13320) >> int32(8)
  55112 			goto _219
  55113 		_219:
  55114 			v24 = v18 - v20 - v22 + int32(8708)
  55115 			if v24 & ^int32(YUV_MASK2) == 0 {
  55116 				v27 = v24 >> int32(YUV_FIX2)
  55117 			} else {
  55118 				if v24 < 0 {
  55119 					v28 = 0
  55120 				} else {
  55121 					v28 = int32(255)
  55122 				}
  55123 				v27 = v28
  55124 			}
  55125 			v25 = v27
  55126 			goto _222
  55127 		_222:
  55128 			v16 = v25
  55129 			goto _213
  55130 		_213:
  55131 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55132 			v31 = v1 * int32(19077) >> int32(8)
  55133 			goto _228
  55134 		_228:
  55135 			v33 = v2 * int32(33050) >> int32(8)
  55136 			goto _230
  55137 		_230:
  55138 			v35 = v31 + v33 - int32(17685)
  55139 			if v35 & ^int32(YUV_MASK2) == 0 {
  55140 				v38 = v35 >> int32(YUV_FIX2)
  55141 			} else {
  55142 				if v35 < 0 {
  55143 					v39 = 0
  55144 				} else {
  55145 					v39 = int32(255)
  55146 				}
  55147 				v38 = v39
  55148 			}
  55149 			v36 = v38
  55150 			goto _233
  55151 		_233:
  55152 			v29 = v36
  55153 			goto _226
  55154 		_226:
  55155 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55156 		}
  55157 		tl_uv = t_uv
  55158 		l_uv = uv
  55159 		goto _79
  55160 	_79:
  55161 		;
  55162 		x = x + 1
  55163 	}
  55164 	if !(len1&libc.Int32FromInt32(1) != 0) {
  55165 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55166 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  55167 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  55168 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  55169 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  55170 		v7 = v1 * int32(19077) >> int32(8)
  55171 		goto _243
  55172 	_243:
  55173 		v9 = v3 * int32(26149) >> int32(8)
  55174 		goto _245
  55175 	_245:
  55176 		v11 = v7 + v9 - int32(14234)
  55177 		if v11 & ^int32(YUV_MASK2) == 0 {
  55178 			v14 = v11 >> int32(YUV_FIX2)
  55179 		} else {
  55180 			if v11 < 0 {
  55181 				v15 = 0
  55182 			} else {
  55183 				v15 = int32(255)
  55184 			}
  55185 			v14 = v15
  55186 		}
  55187 		v12 = v14
  55188 		goto _248
  55189 	_248:
  55190 		v5 = v12
  55191 		goto _241
  55192 	_241:
  55193 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55194 		v18 = v1 * int32(19077) >> int32(8)
  55195 		goto _254
  55196 	_254:
  55197 		v20 = v2 * int32(6419) >> int32(8)
  55198 		goto _256
  55199 	_256:
  55200 		v22 = v3 * int32(13320) >> int32(8)
  55201 		goto _258
  55202 	_258:
  55203 		v24 = v18 - v20 - v22 + int32(8708)
  55204 		if v24 & ^int32(YUV_MASK2) == 0 {
  55205 			v27 = v24 >> int32(YUV_FIX2)
  55206 		} else {
  55207 			if v24 < 0 {
  55208 				v28 = 0
  55209 			} else {
  55210 				v28 = int32(255)
  55211 			}
  55212 			v27 = v28
  55213 		}
  55214 		v25 = v27
  55215 		goto _261
  55216 	_261:
  55217 		v16 = v25
  55218 		goto _252
  55219 	_252:
  55220 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55221 		v31 = v1 * int32(19077) >> int32(8)
  55222 		goto _267
  55223 	_267:
  55224 		v33 = v2 * int32(33050) >> int32(8)
  55225 		goto _269
  55226 	_269:
  55227 		v35 = v31 + v33 - int32(17685)
  55228 		if v35 & ^int32(YUV_MASK2) == 0 {
  55229 			v38 = v35 >> int32(YUV_FIX2)
  55230 		} else {
  55231 			if v35 < 0 {
  55232 				v39 = 0
  55233 			} else {
  55234 				v39 = int32(255)
  55235 			}
  55236 			v38 = v39
  55237 		}
  55238 		v36 = v38
  55239 		goto _272
  55240 	_272:
  55241 		v29 = v36
  55242 		goto _265
  55243 	_265:
  55244 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55245 		if bottom_y != libc.UintptrFromInt32(0) {
  55246 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55247 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  55248 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  55249 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  55250 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  55251 			v7 = v1 * int32(19077) >> int32(8)
  55252 			goto _282
  55253 		_282:
  55254 			v9 = v3 * int32(26149) >> int32(8)
  55255 			goto _284
  55256 		_284:
  55257 			v11 = v7 + v9 - int32(14234)
  55258 			if v11 & ^int32(YUV_MASK2) == 0 {
  55259 				v14 = v11 >> int32(YUV_FIX2)
  55260 			} else {
  55261 				if v11 < 0 {
  55262 					v15 = 0
  55263 				} else {
  55264 					v15 = int32(255)
  55265 				}
  55266 				v14 = v15
  55267 			}
  55268 			v12 = v14
  55269 			goto _287
  55270 		_287:
  55271 			v5 = v12
  55272 			goto _280
  55273 		_280:
  55274 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55275 			v18 = v1 * int32(19077) >> int32(8)
  55276 			goto _293
  55277 		_293:
  55278 			v20 = v2 * int32(6419) >> int32(8)
  55279 			goto _295
  55280 		_295:
  55281 			v22 = v3 * int32(13320) >> int32(8)
  55282 			goto _297
  55283 		_297:
  55284 			v24 = v18 - v20 - v22 + int32(8708)
  55285 			if v24 & ^int32(YUV_MASK2) == 0 {
  55286 				v27 = v24 >> int32(YUV_FIX2)
  55287 			} else {
  55288 				if v24 < 0 {
  55289 					v28 = 0
  55290 				} else {
  55291 					v28 = int32(255)
  55292 				}
  55293 				v27 = v28
  55294 			}
  55295 			v25 = v27
  55296 			goto _300
  55297 		_300:
  55298 			v16 = v25
  55299 			goto _291
  55300 		_291:
  55301 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55302 			v31 = v1 * int32(19077) >> int32(8)
  55303 			goto _306
  55304 		_306:
  55305 			v33 = v2 * int32(33050) >> int32(8)
  55306 			goto _308
  55307 		_308:
  55308 			v35 = v31 + v33 - int32(17685)
  55309 			if v35 & ^int32(YUV_MASK2) == 0 {
  55310 				v38 = v35 >> int32(YUV_FIX2)
  55311 			} else {
  55312 				if v35 < 0 {
  55313 					v39 = 0
  55314 				} else {
  55315 					v39 = int32(255)
  55316 				}
  55317 				v38 = v39
  55318 			}
  55319 			v36 = v38
  55320 			goto _311
  55321 		_311:
  55322 			v29 = v36
  55323 			goto _304
  55324 		_304:
  55325 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55326 		}
  55327 	}
  55328 }
  55329 
  55330 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) {
  55331 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  55332 	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
  55333 	var v4 uintptr
  55334 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  55335 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  55336 	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 */
  55337 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  55338 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55339 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  55340 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  55341 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  55342 	v4 = top_dst
  55343 	v7 = v1 * int32(19077) >> int32(8)
  55344 	goto _8
  55345 _8:
  55346 	v9 = v2 * int32(33050) >> int32(8)
  55347 	goto _10
  55348 _10:
  55349 	v11 = v7 + v9 - int32(17685)
  55350 	if v11 & ^int32(YUV_MASK2) == 0 {
  55351 		v14 = v11 >> int32(YUV_FIX2)
  55352 	} else {
  55353 		if v11 < 0 {
  55354 			v15 = 0
  55355 		} else {
  55356 			v15 = int32(255)
  55357 		}
  55358 		v14 = v15
  55359 	}
  55360 	v12 = v14
  55361 	goto _13
  55362 _13:
  55363 	v5 = v12
  55364 	goto _6
  55365 _6:
  55366 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55367 	v18 = v1 * int32(19077) >> int32(8)
  55368 	goto _19
  55369 _19:
  55370 	v20 = v2 * int32(6419) >> int32(8)
  55371 	goto _21
  55372 _21:
  55373 	v22 = v3 * int32(13320) >> int32(8)
  55374 	goto _23
  55375 _23:
  55376 	v24 = v18 - v20 - v22 + int32(8708)
  55377 	if v24 & ^int32(YUV_MASK2) == 0 {
  55378 		v27 = v24 >> int32(YUV_FIX2)
  55379 	} else {
  55380 		if v24 < 0 {
  55381 			v28 = 0
  55382 		} else {
  55383 			v28 = int32(255)
  55384 		}
  55385 		v27 = v28
  55386 	}
  55387 	v25 = v27
  55388 	goto _26
  55389 _26:
  55390 	v16 = v25
  55391 	goto _17
  55392 _17:
  55393 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55394 	v31 = v1 * int32(19077) >> int32(8)
  55395 	goto _32
  55396 _32:
  55397 	v33 = v3 * int32(26149) >> int32(8)
  55398 	goto _34
  55399 _34:
  55400 	v35 = v31 + v33 - int32(14234)
  55401 	if v35 & ^int32(YUV_MASK2) == 0 {
  55402 		v38 = v35 >> int32(YUV_FIX2)
  55403 	} else {
  55404 		if v35 < 0 {
  55405 			v39 = 0
  55406 		} else {
  55407 			v39 = int32(255)
  55408 		}
  55409 		v38 = v39
  55410 	}
  55411 	v36 = v38
  55412 	goto _37
  55413 _37:
  55414 	v29 = v36
  55415 	goto _30
  55416 _30:
  55417 	**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55418 	if bottom_y != libc.UintptrFromInt32(0) {
  55419 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55420 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  55421 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  55422 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  55423 		v4 = bottom_dst
  55424 		v7 = v1 * int32(19077) >> int32(8)
  55425 		goto _47
  55426 	_47:
  55427 		v9 = v2 * int32(33050) >> int32(8)
  55428 		goto _49
  55429 	_49:
  55430 		v11 = v7 + v9 - int32(17685)
  55431 		if v11 & ^int32(YUV_MASK2) == 0 {
  55432 			v14 = v11 >> int32(YUV_FIX2)
  55433 		} else {
  55434 			if v11 < 0 {
  55435 				v15 = 0
  55436 			} else {
  55437 				v15 = int32(255)
  55438 			}
  55439 			v14 = v15
  55440 		}
  55441 		v12 = v14
  55442 		goto _52
  55443 	_52:
  55444 		v5 = v12
  55445 		goto _45
  55446 	_45:
  55447 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55448 		v18 = v1 * int32(19077) >> int32(8)
  55449 		goto _58
  55450 	_58:
  55451 		v20 = v2 * int32(6419) >> int32(8)
  55452 		goto _60
  55453 	_60:
  55454 		v22 = v3 * int32(13320) >> int32(8)
  55455 		goto _62
  55456 	_62:
  55457 		v24 = v18 - v20 - v22 + int32(8708)
  55458 		if v24 & ^int32(YUV_MASK2) == 0 {
  55459 			v27 = v24 >> int32(YUV_FIX2)
  55460 		} else {
  55461 			if v24 < 0 {
  55462 				v28 = 0
  55463 			} else {
  55464 				v28 = int32(255)
  55465 			}
  55466 			v27 = v28
  55467 		}
  55468 		v25 = v27
  55469 		goto _65
  55470 	_65:
  55471 		v16 = v25
  55472 		goto _56
  55473 	_56:
  55474 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55475 		v31 = v1 * int32(19077) >> int32(8)
  55476 		goto _71
  55477 	_71:
  55478 		v33 = v3 * int32(26149) >> int32(8)
  55479 		goto _73
  55480 	_73:
  55481 		v35 = v31 + v33 - int32(14234)
  55482 		if v35 & ^int32(YUV_MASK2) == 0 {
  55483 			v38 = v35 >> int32(YUV_FIX2)
  55484 		} else {
  55485 			if v35 < 0 {
  55486 				v39 = 0
  55487 			} else {
  55488 				v39 = int32(255)
  55489 			}
  55490 			v38 = v39
  55491 		}
  55492 		v36 = v38
  55493 		goto _76
  55494 	_76:
  55495 		v29 = v36
  55496 		goto _69
  55497 	_69:
  55498 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55499 	}
  55500 	x = int32(1)
  55501 	for {
  55502 		if !(x <= last_pixel_pair) {
  55503 			break
  55504 		}
  55505 		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 */
  55506 		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*/
  55507 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  55508 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  55509 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  55510 		uv02 = (diag_12 + tl_uv) >> int32(1)
  55511 		uv1 = (diag_03 + t_uv) >> int32(1)
  55512 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  55513 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  55514 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  55515 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55516 		v7 = v1 * int32(19077) >> int32(8)
  55517 		goto _87
  55518 	_87:
  55519 		v9 = v2 * int32(33050) >> int32(8)
  55520 		goto _89
  55521 	_89:
  55522 		v11 = v7 + v9 - int32(17685)
  55523 		if v11 & ^int32(YUV_MASK2) == 0 {
  55524 			v14 = v11 >> int32(YUV_FIX2)
  55525 		} else {
  55526 			if v11 < 0 {
  55527 				v15 = 0
  55528 			} else {
  55529 				v15 = int32(255)
  55530 			}
  55531 			v14 = v15
  55532 		}
  55533 		v12 = v14
  55534 		goto _92
  55535 	_92:
  55536 		v5 = v12
  55537 		goto _85
  55538 	_85:
  55539 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55540 		v18 = v1 * int32(19077) >> int32(8)
  55541 		goto _98
  55542 	_98:
  55543 		v20 = v2 * int32(6419) >> int32(8)
  55544 		goto _100
  55545 	_100:
  55546 		v22 = v3 * int32(13320) >> int32(8)
  55547 		goto _102
  55548 	_102:
  55549 		v24 = v18 - v20 - v22 + int32(8708)
  55550 		if v24 & ^int32(YUV_MASK2) == 0 {
  55551 			v27 = v24 >> int32(YUV_FIX2)
  55552 		} else {
  55553 			if v24 < 0 {
  55554 				v28 = 0
  55555 			} else {
  55556 				v28 = int32(255)
  55557 			}
  55558 			v27 = v28
  55559 		}
  55560 		v25 = v27
  55561 		goto _105
  55562 	_105:
  55563 		v16 = v25
  55564 		goto _96
  55565 	_96:
  55566 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55567 		v31 = v1 * int32(19077) >> int32(8)
  55568 		goto _111
  55569 	_111:
  55570 		v33 = v3 * int32(26149) >> int32(8)
  55571 		goto _113
  55572 	_113:
  55573 		v35 = v31 + v33 - int32(14234)
  55574 		if v35 & ^int32(YUV_MASK2) == 0 {
  55575 			v38 = v35 >> int32(YUV_FIX2)
  55576 		} else {
  55577 			if v35 < 0 {
  55578 				v39 = 0
  55579 			} else {
  55580 				v39 = int32(255)
  55581 			}
  55582 			v38 = v39
  55583 		}
  55584 		v36 = v38
  55585 		goto _116
  55586 	_116:
  55587 		v29 = v36
  55588 		goto _109
  55589 	_109:
  55590 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55591 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-0))))
  55592 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  55593 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  55594 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(3))
  55595 		v7 = v1 * int32(19077) >> int32(8)
  55596 		goto _126
  55597 	_126:
  55598 		v9 = v2 * int32(33050) >> int32(8)
  55599 		goto _128
  55600 	_128:
  55601 		v11 = v7 + v9 - int32(17685)
  55602 		if v11 & ^int32(YUV_MASK2) == 0 {
  55603 			v14 = v11 >> int32(YUV_FIX2)
  55604 		} else {
  55605 			if v11 < 0 {
  55606 				v15 = 0
  55607 			} else {
  55608 				v15 = int32(255)
  55609 			}
  55610 			v14 = v15
  55611 		}
  55612 		v12 = v14
  55613 		goto _131
  55614 	_131:
  55615 		v5 = v12
  55616 		goto _124
  55617 	_124:
  55618 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55619 		v18 = v1 * int32(19077) >> int32(8)
  55620 		goto _137
  55621 	_137:
  55622 		v20 = v2 * int32(6419) >> int32(8)
  55623 		goto _139
  55624 	_139:
  55625 		v22 = v3 * int32(13320) >> int32(8)
  55626 		goto _141
  55627 	_141:
  55628 		v24 = v18 - v20 - v22 + int32(8708)
  55629 		if v24 & ^int32(YUV_MASK2) == 0 {
  55630 			v27 = v24 >> int32(YUV_FIX2)
  55631 		} else {
  55632 			if v24 < 0 {
  55633 				v28 = 0
  55634 			} else {
  55635 				v28 = int32(255)
  55636 			}
  55637 			v27 = v28
  55638 		}
  55639 		v25 = v27
  55640 		goto _144
  55641 	_144:
  55642 		v16 = v25
  55643 		goto _135
  55644 	_135:
  55645 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55646 		v31 = v1 * int32(19077) >> int32(8)
  55647 		goto _150
  55648 	_150:
  55649 		v33 = v3 * int32(26149) >> int32(8)
  55650 		goto _152
  55651 	_152:
  55652 		v35 = v31 + v33 - int32(14234)
  55653 		if v35 & ^int32(YUV_MASK2) == 0 {
  55654 			v38 = v35 >> int32(YUV_FIX2)
  55655 		} else {
  55656 			if v35 < 0 {
  55657 				v39 = 0
  55658 			} else {
  55659 				v39 = int32(255)
  55660 			}
  55661 			v38 = v39
  55662 		}
  55663 		v36 = v38
  55664 		goto _155
  55665 	_155:
  55666 		v29 = v36
  55667 		goto _148
  55668 	_148:
  55669 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55670 		if bottom_y != libc.UintptrFromInt32(0) {
  55671 			uv03 = (diag_03 + l_uv) >> int32(1)
  55672 			uv11 = (diag_12 + uv) >> int32(1)
  55673 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  55674 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  55675 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  55676 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(3))
  55677 			v7 = v1 * int32(19077) >> int32(8)
  55678 			goto _165
  55679 		_165:
  55680 			v9 = v2 * int32(33050) >> int32(8)
  55681 			goto _167
  55682 		_167:
  55683 			v11 = v7 + v9 - int32(17685)
  55684 			if v11 & ^int32(YUV_MASK2) == 0 {
  55685 				v14 = v11 >> int32(YUV_FIX2)
  55686 			} else {
  55687 				if v11 < 0 {
  55688 					v15 = 0
  55689 				} else {
  55690 					v15 = int32(255)
  55691 				}
  55692 				v14 = v15
  55693 			}
  55694 			v12 = v14
  55695 			goto _170
  55696 		_170:
  55697 			v5 = v12
  55698 			goto _163
  55699 		_163:
  55700 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55701 			v18 = v1 * int32(19077) >> int32(8)
  55702 			goto _176
  55703 		_176:
  55704 			v20 = v2 * int32(6419) >> int32(8)
  55705 			goto _178
  55706 		_178:
  55707 			v22 = v3 * int32(13320) >> int32(8)
  55708 			goto _180
  55709 		_180:
  55710 			v24 = v18 - v20 - v22 + int32(8708)
  55711 			if v24 & ^int32(YUV_MASK2) == 0 {
  55712 				v27 = v24 >> int32(YUV_FIX2)
  55713 			} else {
  55714 				if v24 < 0 {
  55715 					v28 = 0
  55716 				} else {
  55717 					v28 = int32(255)
  55718 				}
  55719 				v27 = v28
  55720 			}
  55721 			v25 = v27
  55722 			goto _183
  55723 		_183:
  55724 			v16 = v25
  55725 			goto _174
  55726 		_174:
  55727 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55728 			v31 = v1 * int32(19077) >> int32(8)
  55729 			goto _189
  55730 		_189:
  55731 			v33 = v3 * int32(26149) >> int32(8)
  55732 			goto _191
  55733 		_191:
  55734 			v35 = v31 + v33 - int32(14234)
  55735 			if v35 & ^int32(YUV_MASK2) == 0 {
  55736 				v38 = v35 >> int32(YUV_FIX2)
  55737 			} else {
  55738 				if v35 < 0 {
  55739 					v39 = 0
  55740 				} else {
  55741 					v39 = int32(255)
  55742 				}
  55743 				v38 = v39
  55744 			}
  55745 			v36 = v38
  55746 			goto _194
  55747 		_194:
  55748 			v29 = v36
  55749 			goto _187
  55750 		_187:
  55751 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55752 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  55753 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  55754 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  55755 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(3))
  55756 			v7 = v1 * int32(19077) >> int32(8)
  55757 			goto _204
  55758 		_204:
  55759 			v9 = v2 * int32(33050) >> int32(8)
  55760 			goto _206
  55761 		_206:
  55762 			v11 = v7 + v9 - int32(17685)
  55763 			if v11 & ^int32(YUV_MASK2) == 0 {
  55764 				v14 = v11 >> int32(YUV_FIX2)
  55765 			} else {
  55766 				if v11 < 0 {
  55767 					v15 = 0
  55768 				} else {
  55769 					v15 = int32(255)
  55770 				}
  55771 				v14 = v15
  55772 			}
  55773 			v12 = v14
  55774 			goto _209
  55775 		_209:
  55776 			v5 = v12
  55777 			goto _202
  55778 		_202:
  55779 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55780 			v18 = v1 * int32(19077) >> int32(8)
  55781 			goto _215
  55782 		_215:
  55783 			v20 = v2 * int32(6419) >> int32(8)
  55784 			goto _217
  55785 		_217:
  55786 			v22 = v3 * int32(13320) >> int32(8)
  55787 			goto _219
  55788 		_219:
  55789 			v24 = v18 - v20 - v22 + int32(8708)
  55790 			if v24 & ^int32(YUV_MASK2) == 0 {
  55791 				v27 = v24 >> int32(YUV_FIX2)
  55792 			} else {
  55793 				if v24 < 0 {
  55794 					v28 = 0
  55795 				} else {
  55796 					v28 = int32(255)
  55797 				}
  55798 				v27 = v28
  55799 			}
  55800 			v25 = v27
  55801 			goto _222
  55802 		_222:
  55803 			v16 = v25
  55804 			goto _213
  55805 		_213:
  55806 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55807 			v31 = v1 * int32(19077) >> int32(8)
  55808 			goto _228
  55809 		_228:
  55810 			v33 = v3 * int32(26149) >> int32(8)
  55811 			goto _230
  55812 		_230:
  55813 			v35 = v31 + v33 - int32(14234)
  55814 			if v35 & ^int32(YUV_MASK2) == 0 {
  55815 				v38 = v35 >> int32(YUV_FIX2)
  55816 			} else {
  55817 				if v35 < 0 {
  55818 					v39 = 0
  55819 				} else {
  55820 					v39 = int32(255)
  55821 				}
  55822 				v38 = v39
  55823 			}
  55824 			v36 = v38
  55825 			goto _233
  55826 		_233:
  55827 			v29 = v36
  55828 			goto _226
  55829 		_226:
  55830 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55831 		}
  55832 		tl_uv = t_uv
  55833 		l_uv = uv
  55834 		goto _79
  55835 	_79:
  55836 		;
  55837 		x = x + 1
  55838 	}
  55839 	if !(len1&libc.Int32FromInt32(1) != 0) {
  55840 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  55841 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  55842 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  55843 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  55844 		v4 = top_dst + uintptr((len1-int32(1))*int32(3))
  55845 		v7 = v1 * int32(19077) >> int32(8)
  55846 		goto _243
  55847 	_243:
  55848 		v9 = v2 * int32(33050) >> int32(8)
  55849 		goto _245
  55850 	_245:
  55851 		v11 = v7 + v9 - int32(17685)
  55852 		if v11 & ^int32(YUV_MASK2) == 0 {
  55853 			v14 = v11 >> int32(YUV_FIX2)
  55854 		} else {
  55855 			if v11 < 0 {
  55856 				v15 = 0
  55857 			} else {
  55858 				v15 = int32(255)
  55859 			}
  55860 			v14 = v15
  55861 		}
  55862 		v12 = v14
  55863 		goto _248
  55864 	_248:
  55865 		v5 = v12
  55866 		goto _241
  55867 	_241:
  55868 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55869 		v18 = v1 * int32(19077) >> int32(8)
  55870 		goto _254
  55871 	_254:
  55872 		v20 = v2 * int32(6419) >> int32(8)
  55873 		goto _256
  55874 	_256:
  55875 		v22 = v3 * int32(13320) >> int32(8)
  55876 		goto _258
  55877 	_258:
  55878 		v24 = v18 - v20 - v22 + int32(8708)
  55879 		if v24 & ^int32(YUV_MASK2) == 0 {
  55880 			v27 = v24 >> int32(YUV_FIX2)
  55881 		} else {
  55882 			if v24 < 0 {
  55883 				v28 = 0
  55884 			} else {
  55885 				v28 = int32(255)
  55886 			}
  55887 			v27 = v28
  55888 		}
  55889 		v25 = v27
  55890 		goto _261
  55891 	_261:
  55892 		v16 = v25
  55893 		goto _252
  55894 	_252:
  55895 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55896 		v31 = v1 * int32(19077) >> int32(8)
  55897 		goto _267
  55898 	_267:
  55899 		v33 = v3 * int32(26149) >> int32(8)
  55900 		goto _269
  55901 	_269:
  55902 		v35 = v31 + v33 - int32(14234)
  55903 		if v35 & ^int32(YUV_MASK2) == 0 {
  55904 			v38 = v35 >> int32(YUV_FIX2)
  55905 		} else {
  55906 			if v35 < 0 {
  55907 				v39 = 0
  55908 			} else {
  55909 				v39 = int32(255)
  55910 			}
  55911 			v38 = v39
  55912 		}
  55913 		v36 = v38
  55914 		goto _272
  55915 	_272:
  55916 		v29 = v36
  55917 		goto _265
  55918 	_265:
  55919 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  55920 		if bottom_y != libc.UintptrFromInt32(0) {
  55921 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  55922 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  55923 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  55924 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  55925 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(3))
  55926 			v7 = v1 * int32(19077) >> int32(8)
  55927 			goto _282
  55928 		_282:
  55929 			v9 = v2 * int32(33050) >> int32(8)
  55930 			goto _284
  55931 		_284:
  55932 			v11 = v7 + v9 - int32(17685)
  55933 			if v11 & ^int32(YUV_MASK2) == 0 {
  55934 				v14 = v11 >> int32(YUV_FIX2)
  55935 			} else {
  55936 				if v11 < 0 {
  55937 					v15 = 0
  55938 				} else {
  55939 					v15 = int32(255)
  55940 				}
  55941 				v14 = v15
  55942 			}
  55943 			v12 = v14
  55944 			goto _287
  55945 		_287:
  55946 			v5 = v12
  55947 			goto _280
  55948 		_280:
  55949 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v5)
  55950 			v18 = v1 * int32(19077) >> int32(8)
  55951 			goto _293
  55952 		_293:
  55953 			v20 = v2 * int32(6419) >> int32(8)
  55954 			goto _295
  55955 		_295:
  55956 			v22 = v3 * int32(13320) >> int32(8)
  55957 			goto _297
  55958 		_297:
  55959 			v24 = v18 - v20 - v22 + int32(8708)
  55960 			if v24 & ^int32(YUV_MASK2) == 0 {
  55961 				v27 = v24 >> int32(YUV_FIX2)
  55962 			} else {
  55963 				if v24 < 0 {
  55964 					v28 = 0
  55965 				} else {
  55966 					v28 = int32(255)
  55967 				}
  55968 				v27 = v28
  55969 			}
  55970 			v25 = v27
  55971 			goto _300
  55972 		_300:
  55973 			v16 = v25
  55974 			goto _291
  55975 		_291:
  55976 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  55977 			v31 = v1 * int32(19077) >> int32(8)
  55978 			goto _306
  55979 		_306:
  55980 			v33 = v3 * int32(26149) >> int32(8)
  55981 			goto _308
  55982 		_308:
  55983 			v35 = v31 + v33 - int32(14234)
  55984 			if v35 & ^int32(YUV_MASK2) == 0 {
  55985 				v38 = v35 >> int32(YUV_FIX2)
  55986 			} else {
  55987 				if v35 < 0 {
  55988 					v39 = 0
  55989 				} else {
  55990 					v39 = int32(255)
  55991 				}
  55992 				v38 = v39
  55993 			}
  55994 			v36 = v38
  55995 			goto _311
  55996 		_311:
  55997 			v29 = v36
  55998 			goto _304
  55999 		_304:
  56000 			**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  56001 		}
  56002 	}
  56003 }
  56004 
  56005 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) {
  56006 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56007 	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
  56008 	var v4 uintptr
  56009 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  56010 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56011 	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 */
  56012 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56013 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56014 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  56015 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  56016 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  56017 	v4 = top_dst
  56018 	v7 = v1 * int32(19077) >> int32(8)
  56019 	goto _8
  56020 _8:
  56021 	v9 = v3 * int32(26149) >> int32(8)
  56022 	goto _10
  56023 _10:
  56024 	v11 = v7 + v9 - int32(14234)
  56025 	if v11 & ^int32(YUV_MASK2) == 0 {
  56026 		v14 = v11 >> int32(YUV_FIX2)
  56027 	} else {
  56028 		if v11 < 0 {
  56029 			v15 = 0
  56030 		} else {
  56031 			v15 = int32(255)
  56032 		}
  56033 		v14 = v15
  56034 	}
  56035 	v12 = v14
  56036 	goto _13
  56037 _13:
  56038 	v5 = v12
  56039 	goto _6
  56040 _6:
  56041 	r = v5
  56042 	v18 = v1 * int32(19077) >> int32(8)
  56043 	goto _19
  56044 _19:
  56045 	v20 = v2 * int32(6419) >> int32(8)
  56046 	goto _21
  56047 _21:
  56048 	v22 = v3 * int32(13320) >> int32(8)
  56049 	goto _23
  56050 _23:
  56051 	v24 = v18 - v20 - v22 + int32(8708)
  56052 	if v24 & ^int32(YUV_MASK2) == 0 {
  56053 		v27 = v24 >> int32(YUV_FIX2)
  56054 	} else {
  56055 		if v24 < 0 {
  56056 			v28 = 0
  56057 		} else {
  56058 			v28 = int32(255)
  56059 		}
  56060 		v27 = v28
  56061 	}
  56062 	v25 = v27
  56063 	goto _26
  56064 _26:
  56065 	v16 = v25
  56066 	goto _17
  56067 _17:
  56068 	g = v16
  56069 	v31 = v1 * int32(19077) >> int32(8)
  56070 	goto _32
  56071 _32:
  56072 	v33 = v2 * int32(33050) >> int32(8)
  56073 	goto _34
  56074 _34:
  56075 	v35 = v31 + v33 - int32(17685)
  56076 	if v35 & ^int32(YUV_MASK2) == 0 {
  56077 		v38 = v35 >> int32(YUV_FIX2)
  56078 	} else {
  56079 		if v35 < 0 {
  56080 			v39 = 0
  56081 		} else {
  56082 			v39 = int32(255)
  56083 		}
  56084 		v38 = v39
  56085 	}
  56086 	v36 = v38
  56087 	goto _37
  56088 _37:
  56089 	v29 = v36
  56090 	goto _30
  56091 _30:
  56092 	b = v29
  56093 	rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56094 	ba = b&int32(0xf0) | int32(0x0f)
  56095 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56096 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56097 	if bottom_y != libc.UintptrFromInt32(0) {
  56098 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56099 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  56100 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  56101 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  56102 		v4 = bottom_dst
  56103 		v7 = v1 * int32(19077) >> int32(8)
  56104 		goto _47
  56105 	_47:
  56106 		v9 = v3 * int32(26149) >> int32(8)
  56107 		goto _49
  56108 	_49:
  56109 		v11 = v7 + v9 - int32(14234)
  56110 		if v11 & ^int32(YUV_MASK2) == 0 {
  56111 			v14 = v11 >> int32(YUV_FIX2)
  56112 		} else {
  56113 			if v11 < 0 {
  56114 				v15 = 0
  56115 			} else {
  56116 				v15 = int32(255)
  56117 			}
  56118 			v14 = v15
  56119 		}
  56120 		v12 = v14
  56121 		goto _52
  56122 	_52:
  56123 		v5 = v12
  56124 		goto _45
  56125 	_45:
  56126 		r = v5
  56127 		v18 = v1 * int32(19077) >> int32(8)
  56128 		goto _58
  56129 	_58:
  56130 		v20 = v2 * int32(6419) >> int32(8)
  56131 		goto _60
  56132 	_60:
  56133 		v22 = v3 * int32(13320) >> int32(8)
  56134 		goto _62
  56135 	_62:
  56136 		v24 = v18 - v20 - v22 + int32(8708)
  56137 		if v24 & ^int32(YUV_MASK2) == 0 {
  56138 			v27 = v24 >> int32(YUV_FIX2)
  56139 		} else {
  56140 			if v24 < 0 {
  56141 				v28 = 0
  56142 			} else {
  56143 				v28 = int32(255)
  56144 			}
  56145 			v27 = v28
  56146 		}
  56147 		v25 = v27
  56148 		goto _65
  56149 	_65:
  56150 		v16 = v25
  56151 		goto _56
  56152 	_56:
  56153 		g = v16
  56154 		v31 = v1 * int32(19077) >> int32(8)
  56155 		goto _71
  56156 	_71:
  56157 		v33 = v2 * int32(33050) >> int32(8)
  56158 		goto _73
  56159 	_73:
  56160 		v35 = v31 + v33 - int32(17685)
  56161 		if v35 & ^int32(YUV_MASK2) == 0 {
  56162 			v38 = v35 >> int32(YUV_FIX2)
  56163 		} else {
  56164 			if v35 < 0 {
  56165 				v39 = 0
  56166 			} else {
  56167 				v39 = int32(255)
  56168 			}
  56169 			v38 = v39
  56170 		}
  56171 		v36 = v38
  56172 		goto _76
  56173 	_76:
  56174 		v29 = v36
  56175 		goto _69
  56176 	_69:
  56177 		b = v29
  56178 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56179 		ba = b&int32(0xf0) | int32(0x0f)
  56180 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56181 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56182 	}
  56183 	x = int32(1)
  56184 	for {
  56185 		if !(x <= last_pixel_pair) {
  56186 			break
  56187 		}
  56188 		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 */
  56189 		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*/
  56190 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  56191 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  56192 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  56193 		uv02 = (diag_12 + tl_uv) >> int32(1)
  56194 		uv1 = (diag_03 + t_uv) >> int32(1)
  56195 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  56196 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  56197 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  56198 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56199 		v7 = v1 * int32(19077) >> int32(8)
  56200 		goto _87
  56201 	_87:
  56202 		v9 = v3 * int32(26149) >> int32(8)
  56203 		goto _89
  56204 	_89:
  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 _92
  56218 	_92:
  56219 		v5 = v12
  56220 		goto _85
  56221 	_85:
  56222 		r = v5
  56223 		v18 = v1 * int32(19077) >> int32(8)
  56224 		goto _98
  56225 	_98:
  56226 		v20 = v2 * int32(6419) >> int32(8)
  56227 		goto _100
  56228 	_100:
  56229 		v22 = v3 * int32(13320) >> int32(8)
  56230 		goto _102
  56231 	_102:
  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 _105
  56245 	_105:
  56246 		v16 = v25
  56247 		goto _96
  56248 	_96:
  56249 		g = v16
  56250 		v31 = v1 * int32(19077) >> int32(8)
  56251 		goto _111
  56252 	_111:
  56253 		v33 = v2 * int32(33050) >> int32(8)
  56254 		goto _113
  56255 	_113:
  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 _116
  56269 	_116:
  56270 		v29 = v36
  56271 		goto _109
  56272 	_109:
  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(top_y + uintptr(int32(2)*x-0))))
  56279 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  56280 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  56281 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  56282 		v7 = v1 * int32(19077) >> int32(8)
  56283 		goto _126
  56284 	_126:
  56285 		v9 = v3 * int32(26149) >> int32(8)
  56286 		goto _128
  56287 	_128:
  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 _131
  56301 	_131:
  56302 		v5 = v12
  56303 		goto _124
  56304 	_124:
  56305 		r = v5
  56306 		v18 = v1 * int32(19077) >> int32(8)
  56307 		goto _137
  56308 	_137:
  56309 		v20 = v2 * int32(6419) >> int32(8)
  56310 		goto _139
  56311 	_139:
  56312 		v22 = v3 * int32(13320) >> int32(8)
  56313 		goto _141
  56314 	_141:
  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 _144
  56328 	_144:
  56329 		v16 = v25
  56330 		goto _135
  56331 	_135:
  56332 		g = v16
  56333 		v31 = v1 * int32(19077) >> int32(8)
  56334 		goto _150
  56335 	_150:
  56336 		v33 = v2 * int32(33050) >> int32(8)
  56337 		goto _152
  56338 	_152:
  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 _155
  56352 	_155:
  56353 		v29 = v36
  56354 		goto _148
  56355 	_148:
  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 		if bottom_y != libc.UintptrFromInt32(0) {
  56362 			uv03 = (diag_03 + l_uv) >> int32(1)
  56363 			uv11 = (diag_12 + uv) >> int32(1)
  56364 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  56365 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  56366 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  56367 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56368 			v7 = v1 * int32(19077) >> int32(8)
  56369 			goto _165
  56370 		_165:
  56371 			v9 = v3 * int32(26149) >> int32(8)
  56372 			goto _167
  56373 		_167:
  56374 			v11 = v7 + v9 - int32(14234)
  56375 			if v11 & ^int32(YUV_MASK2) == 0 {
  56376 				v14 = v11 >> int32(YUV_FIX2)
  56377 			} else {
  56378 				if v11 < 0 {
  56379 					v15 = 0
  56380 				} else {
  56381 					v15 = int32(255)
  56382 				}
  56383 				v14 = v15
  56384 			}
  56385 			v12 = v14
  56386 			goto _170
  56387 		_170:
  56388 			v5 = v12
  56389 			goto _163
  56390 		_163:
  56391 			r = v5
  56392 			v18 = v1 * int32(19077) >> int32(8)
  56393 			goto _176
  56394 		_176:
  56395 			v20 = v2 * int32(6419) >> int32(8)
  56396 			goto _178
  56397 		_178:
  56398 			v22 = v3 * int32(13320) >> int32(8)
  56399 			goto _180
  56400 		_180:
  56401 			v24 = v18 - v20 - v22 + int32(8708)
  56402 			if v24 & ^int32(YUV_MASK2) == 0 {
  56403 				v27 = v24 >> int32(YUV_FIX2)
  56404 			} else {
  56405 				if v24 < 0 {
  56406 					v28 = 0
  56407 				} else {
  56408 					v28 = int32(255)
  56409 				}
  56410 				v27 = v28
  56411 			}
  56412 			v25 = v27
  56413 			goto _183
  56414 		_183:
  56415 			v16 = v25
  56416 			goto _174
  56417 		_174:
  56418 			g = v16
  56419 			v31 = v1 * int32(19077) >> int32(8)
  56420 			goto _189
  56421 		_189:
  56422 			v33 = v2 * int32(33050) >> int32(8)
  56423 			goto _191
  56424 		_191:
  56425 			v35 = v31 + v33 - int32(17685)
  56426 			if v35 & ^int32(YUV_MASK2) == 0 {
  56427 				v38 = v35 >> int32(YUV_FIX2)
  56428 			} else {
  56429 				if v35 < 0 {
  56430 					v39 = 0
  56431 				} else {
  56432 					v39 = int32(255)
  56433 				}
  56434 				v38 = v39
  56435 			}
  56436 			v36 = v38
  56437 			goto _194
  56438 		_194:
  56439 			v29 = v36
  56440 			goto _187
  56441 		_187:
  56442 			b = v29
  56443 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56444 			ba = b&int32(0xf0) | int32(0x0f)
  56445 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56446 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56447 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  56448 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  56449 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  56450 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  56451 			v7 = v1 * int32(19077) >> int32(8)
  56452 			goto _204
  56453 		_204:
  56454 			v9 = v3 * int32(26149) >> int32(8)
  56455 			goto _206
  56456 		_206:
  56457 			v11 = v7 + v9 - int32(14234)
  56458 			if v11 & ^int32(YUV_MASK2) == 0 {
  56459 				v14 = v11 >> int32(YUV_FIX2)
  56460 			} else {
  56461 				if v11 < 0 {
  56462 					v15 = 0
  56463 				} else {
  56464 					v15 = int32(255)
  56465 				}
  56466 				v14 = v15
  56467 			}
  56468 			v12 = v14
  56469 			goto _209
  56470 		_209:
  56471 			v5 = v12
  56472 			goto _202
  56473 		_202:
  56474 			r = v5
  56475 			v18 = v1 * int32(19077) >> int32(8)
  56476 			goto _215
  56477 		_215:
  56478 			v20 = v2 * int32(6419) >> int32(8)
  56479 			goto _217
  56480 		_217:
  56481 			v22 = v3 * int32(13320) >> int32(8)
  56482 			goto _219
  56483 		_219:
  56484 			v24 = v18 - v20 - v22 + int32(8708)
  56485 			if v24 & ^int32(YUV_MASK2) == 0 {
  56486 				v27 = v24 >> int32(YUV_FIX2)
  56487 			} else {
  56488 				if v24 < 0 {
  56489 					v28 = 0
  56490 				} else {
  56491 					v28 = int32(255)
  56492 				}
  56493 				v27 = v28
  56494 			}
  56495 			v25 = v27
  56496 			goto _222
  56497 		_222:
  56498 			v16 = v25
  56499 			goto _213
  56500 		_213:
  56501 			g = v16
  56502 			v31 = v1 * int32(19077) >> int32(8)
  56503 			goto _228
  56504 		_228:
  56505 			v33 = v2 * int32(33050) >> int32(8)
  56506 			goto _230
  56507 		_230:
  56508 			v35 = v31 + v33 - int32(17685)
  56509 			if v35 & ^int32(YUV_MASK2) == 0 {
  56510 				v38 = v35 >> int32(YUV_FIX2)
  56511 			} else {
  56512 				if v35 < 0 {
  56513 					v39 = 0
  56514 				} else {
  56515 					v39 = int32(255)
  56516 				}
  56517 				v38 = v39
  56518 			}
  56519 			v36 = v38
  56520 			goto _233
  56521 		_233:
  56522 			v29 = v36
  56523 			goto _226
  56524 		_226:
  56525 			b = v29
  56526 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56527 			ba = b&int32(0xf0) | int32(0x0f)
  56528 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56529 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56530 		}
  56531 		tl_uv = t_uv
  56532 		l_uv = uv
  56533 		goto _79
  56534 	_79:
  56535 		;
  56536 		x = x + 1
  56537 	}
  56538 	if !(len1&libc.Int32FromInt32(1) != 0) {
  56539 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56540 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  56541 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  56542 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  56543 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  56544 		v7 = v1 * int32(19077) >> int32(8)
  56545 		goto _243
  56546 	_243:
  56547 		v9 = v3 * int32(26149) >> int32(8)
  56548 		goto _245
  56549 	_245:
  56550 		v11 = v7 + v9 - int32(14234)
  56551 		if v11 & ^int32(YUV_MASK2) == 0 {
  56552 			v14 = v11 >> int32(YUV_FIX2)
  56553 		} else {
  56554 			if v11 < 0 {
  56555 				v15 = 0
  56556 			} else {
  56557 				v15 = int32(255)
  56558 			}
  56559 			v14 = v15
  56560 		}
  56561 		v12 = v14
  56562 		goto _248
  56563 	_248:
  56564 		v5 = v12
  56565 		goto _241
  56566 	_241:
  56567 		r = v5
  56568 		v18 = v1 * int32(19077) >> int32(8)
  56569 		goto _254
  56570 	_254:
  56571 		v20 = v2 * int32(6419) >> int32(8)
  56572 		goto _256
  56573 	_256:
  56574 		v22 = v3 * int32(13320) >> int32(8)
  56575 		goto _258
  56576 	_258:
  56577 		v24 = v18 - v20 - v22 + int32(8708)
  56578 		if v24 & ^int32(YUV_MASK2) == 0 {
  56579 			v27 = v24 >> int32(YUV_FIX2)
  56580 		} else {
  56581 			if v24 < 0 {
  56582 				v28 = 0
  56583 			} else {
  56584 				v28 = int32(255)
  56585 			}
  56586 			v27 = v28
  56587 		}
  56588 		v25 = v27
  56589 		goto _261
  56590 	_261:
  56591 		v16 = v25
  56592 		goto _252
  56593 	_252:
  56594 		g = v16
  56595 		v31 = v1 * int32(19077) >> int32(8)
  56596 		goto _267
  56597 	_267:
  56598 		v33 = v2 * int32(33050) >> int32(8)
  56599 		goto _269
  56600 	_269:
  56601 		v35 = v31 + v33 - int32(17685)
  56602 		if v35 & ^int32(YUV_MASK2) == 0 {
  56603 			v38 = v35 >> int32(YUV_FIX2)
  56604 		} else {
  56605 			if v35 < 0 {
  56606 				v39 = 0
  56607 			} else {
  56608 				v39 = int32(255)
  56609 			}
  56610 			v38 = v39
  56611 		}
  56612 		v36 = v38
  56613 		goto _272
  56614 	_272:
  56615 		v29 = v36
  56616 		goto _265
  56617 	_265:
  56618 		b = v29
  56619 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56620 		ba = b&int32(0xf0) | int32(0x0f)
  56621 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56622 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56623 		if bottom_y != libc.UintptrFromInt32(0) {
  56624 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56625 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  56626 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  56627 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  56628 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  56629 			v7 = v1 * int32(19077) >> int32(8)
  56630 			goto _282
  56631 		_282:
  56632 			v9 = v3 * int32(26149) >> int32(8)
  56633 			goto _284
  56634 		_284:
  56635 			v11 = v7 + v9 - int32(14234)
  56636 			if v11 & ^int32(YUV_MASK2) == 0 {
  56637 				v14 = v11 >> int32(YUV_FIX2)
  56638 			} else {
  56639 				if v11 < 0 {
  56640 					v15 = 0
  56641 				} else {
  56642 					v15 = int32(255)
  56643 				}
  56644 				v14 = v15
  56645 			}
  56646 			v12 = v14
  56647 			goto _287
  56648 		_287:
  56649 			v5 = v12
  56650 			goto _280
  56651 		_280:
  56652 			r = v5
  56653 			v18 = v1 * int32(19077) >> int32(8)
  56654 			goto _293
  56655 		_293:
  56656 			v20 = v2 * int32(6419) >> int32(8)
  56657 			goto _295
  56658 		_295:
  56659 			v22 = v3 * int32(13320) >> int32(8)
  56660 			goto _297
  56661 		_297:
  56662 			v24 = v18 - v20 - v22 + int32(8708)
  56663 			if v24 & ^int32(YUV_MASK2) == 0 {
  56664 				v27 = v24 >> int32(YUV_FIX2)
  56665 			} else {
  56666 				if v24 < 0 {
  56667 					v28 = 0
  56668 				} else {
  56669 					v28 = int32(255)
  56670 				}
  56671 				v27 = v28
  56672 			}
  56673 			v25 = v27
  56674 			goto _300
  56675 		_300:
  56676 			v16 = v25
  56677 			goto _291
  56678 		_291:
  56679 			g = v16
  56680 			v31 = v1 * int32(19077) >> int32(8)
  56681 			goto _306
  56682 		_306:
  56683 			v33 = v2 * int32(33050) >> int32(8)
  56684 			goto _308
  56685 		_308:
  56686 			v35 = v31 + v33 - int32(17685)
  56687 			if v35 & ^int32(YUV_MASK2) == 0 {
  56688 				v38 = v35 >> int32(YUV_FIX2)
  56689 			} else {
  56690 				if v35 < 0 {
  56691 					v39 = 0
  56692 				} else {
  56693 					v39 = int32(255)
  56694 				}
  56695 				v38 = v39
  56696 			}
  56697 			v36 = v38
  56698 			goto _311
  56699 		_311:
  56700 			v29 = v36
  56701 			goto _304
  56702 		_304:
  56703 			b = v29
  56704 			rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  56705 			ba = b&int32(0xf0) | int32(0x0f)
  56706 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56707 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  56708 		}
  56709 	}
  56710 }
  56711 
  56712 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) {
  56713 	var avg, diag_03, diag_12, l_uv, t_uv, tl_uv, uv, uv0, uv01, uv02, uv03, uv04, uv05, uv1, uv11 uint32_t
  56714 	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
  56715 	var v4 uintptr
  56716 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  56717 	last_pixel_pair = (len1 - int32(1)) >> int32(1)
  56718 	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 */
  56719 	l_uv = libc.Uint32FromInt32(libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_u))) | libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(cur_v)))<<libc.Int32FromInt32(16))
  56720 	uv0 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  56721 	v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y)))
  56722 	v2 = libc.Int32FromUint32(uv0 & uint32(0xff))
  56723 	v3 = libc.Int32FromUint32(uv0 >> libc.Int32FromInt32(16))
  56724 	v4 = top_dst
  56725 	v7 = v1 * int32(19077) >> int32(8)
  56726 	goto _8
  56727 _8:
  56728 	v9 = v3 * int32(26149) >> int32(8)
  56729 	goto _10
  56730 _10:
  56731 	v11 = v7 + v9 - int32(14234)
  56732 	if v11 & ^int32(YUV_MASK2) == 0 {
  56733 		v14 = v11 >> int32(YUV_FIX2)
  56734 	} else {
  56735 		if v11 < 0 {
  56736 			v15 = 0
  56737 		} else {
  56738 			v15 = int32(255)
  56739 		}
  56740 		v14 = v15
  56741 	}
  56742 	v12 = v14
  56743 	goto _13
  56744 _13:
  56745 	v5 = v12
  56746 	goto _6
  56747 _6:
  56748 	r = v5
  56749 	v18 = v1 * int32(19077) >> int32(8)
  56750 	goto _19
  56751 _19:
  56752 	v20 = v2 * int32(6419) >> int32(8)
  56753 	goto _21
  56754 _21:
  56755 	v22 = v3 * int32(13320) >> int32(8)
  56756 	goto _23
  56757 _23:
  56758 	v24 = v18 - v20 - v22 + int32(8708)
  56759 	if v24 & ^int32(YUV_MASK2) == 0 {
  56760 		v27 = v24 >> int32(YUV_FIX2)
  56761 	} else {
  56762 		if v24 < 0 {
  56763 			v28 = 0
  56764 		} else {
  56765 			v28 = int32(255)
  56766 		}
  56767 		v27 = v28
  56768 	}
  56769 	v25 = v27
  56770 	goto _26
  56771 _26:
  56772 	v16 = v25
  56773 	goto _17
  56774 _17:
  56775 	g = v16
  56776 	v31 = v1 * int32(19077) >> int32(8)
  56777 	goto _32
  56778 _32:
  56779 	v33 = v2 * int32(33050) >> int32(8)
  56780 	goto _34
  56781 _34:
  56782 	v35 = v31 + v33 - int32(17685)
  56783 	if v35 & ^int32(YUV_MASK2) == 0 {
  56784 		v38 = v35 >> int32(YUV_FIX2)
  56785 	} else {
  56786 		if v35 < 0 {
  56787 			v39 = 0
  56788 		} else {
  56789 			v39 = int32(255)
  56790 		}
  56791 		v38 = v39
  56792 	}
  56793 	v36 = v38
  56794 	goto _37
  56795 _37:
  56796 	v29 = v36
  56797 	goto _30
  56798 _30:
  56799 	b = v29
  56800 	rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56801 	gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56802 	**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56803 	**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56804 	if bottom_y != libc.UintptrFromInt32(0) {
  56805 		uv01 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  56806 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y)))
  56807 		v2 = libc.Int32FromUint32(uv01 & uint32(0xff))
  56808 		v3 = libc.Int32FromUint32(uv01 >> libc.Int32FromInt32(16))
  56809 		v4 = bottom_dst
  56810 		v7 = v1 * int32(19077) >> int32(8)
  56811 		goto _47
  56812 	_47:
  56813 		v9 = v3 * int32(26149) >> int32(8)
  56814 		goto _49
  56815 	_49:
  56816 		v11 = v7 + v9 - int32(14234)
  56817 		if v11 & ^int32(YUV_MASK2) == 0 {
  56818 			v14 = v11 >> int32(YUV_FIX2)
  56819 		} else {
  56820 			if v11 < 0 {
  56821 				v15 = 0
  56822 			} else {
  56823 				v15 = int32(255)
  56824 			}
  56825 			v14 = v15
  56826 		}
  56827 		v12 = v14
  56828 		goto _52
  56829 	_52:
  56830 		v5 = v12
  56831 		goto _45
  56832 	_45:
  56833 		r = v5
  56834 		v18 = v1 * int32(19077) >> int32(8)
  56835 		goto _58
  56836 	_58:
  56837 		v20 = v2 * int32(6419) >> int32(8)
  56838 		goto _60
  56839 	_60:
  56840 		v22 = v3 * int32(13320) >> int32(8)
  56841 		goto _62
  56842 	_62:
  56843 		v24 = v18 - v20 - v22 + int32(8708)
  56844 		if v24 & ^int32(YUV_MASK2) == 0 {
  56845 			v27 = v24 >> int32(YUV_FIX2)
  56846 		} else {
  56847 			if v24 < 0 {
  56848 				v28 = 0
  56849 			} else {
  56850 				v28 = int32(255)
  56851 			}
  56852 			v27 = v28
  56853 		}
  56854 		v25 = v27
  56855 		goto _65
  56856 	_65:
  56857 		v16 = v25
  56858 		goto _56
  56859 	_56:
  56860 		g = v16
  56861 		v31 = v1 * int32(19077) >> int32(8)
  56862 		goto _71
  56863 	_71:
  56864 		v33 = v2 * int32(33050) >> int32(8)
  56865 		goto _73
  56866 	_73:
  56867 		v35 = v31 + v33 - int32(17685)
  56868 		if v35 & ^int32(YUV_MASK2) == 0 {
  56869 			v38 = v35 >> int32(YUV_FIX2)
  56870 		} else {
  56871 			if v35 < 0 {
  56872 				v39 = 0
  56873 			} else {
  56874 				v39 = int32(255)
  56875 			}
  56876 			v38 = v39
  56877 		}
  56878 		v36 = v38
  56879 		goto _76
  56880 	_76:
  56881 		v29 = v36
  56882 		goto _69
  56883 	_69:
  56884 		b = v29
  56885 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  56886 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  56887 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  56888 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  56889 	}
  56890 	x = int32(1)
  56891 	for {
  56892 		if !(x <= last_pixel_pair) {
  56893 			break
  56894 		}
  56895 		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 */
  56896 		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*/
  56897 		avg = tl_uv + t_uv + l_uv + uv + uint32(0x00080008)
  56898 		diag_12 = (avg + uint32(2)*(t_uv+l_uv)) >> int32(3)
  56899 		diag_03 = (avg + uint32(2)*(tl_uv+uv)) >> int32(3)
  56900 		uv02 = (diag_12 + tl_uv) >> int32(1)
  56901 		uv1 = (diag_03 + t_uv) >> int32(1)
  56902 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(int32(2)*x-int32(1)))))
  56903 		v2 = libc.Int32FromUint32(uv02 & uint32(0xff))
  56904 		v3 = libc.Int32FromUint32(uv02 >> libc.Int32FromInt32(16))
  56905 		v4 = top_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  56906 		v7 = v1 * int32(19077) >> int32(8)
  56907 		goto _87
  56908 	_87:
  56909 		v9 = v3 * int32(26149) >> int32(8)
  56910 		goto _89
  56911 	_89:
  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 _92
  56925 	_92:
  56926 		v5 = v12
  56927 		goto _85
  56928 	_85:
  56929 		r = v5
  56930 		v18 = v1 * int32(19077) >> int32(8)
  56931 		goto _98
  56932 	_98:
  56933 		v20 = v2 * int32(6419) >> int32(8)
  56934 		goto _100
  56935 	_100:
  56936 		v22 = v3 * int32(13320) >> int32(8)
  56937 		goto _102
  56938 	_102:
  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 _105
  56952 	_105:
  56953 		v16 = v25
  56954 		goto _96
  56955 	_96:
  56956 		g = v16
  56957 		v31 = v1 * int32(19077) >> int32(8)
  56958 		goto _111
  56959 	_111:
  56960 		v33 = v2 * int32(33050) >> int32(8)
  56961 		goto _113
  56962 	_113:
  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 _116
  56976 	_116:
  56977 		v29 = v36
  56978 		goto _109
  56979 	_109:
  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(top_y + uintptr(int32(2)*x-0))))
  56986 		v2 = libc.Int32FromUint32(uv1 & uint32(0xff))
  56987 		v3 = libc.Int32FromUint32(uv1 >> libc.Int32FromInt32(16))
  56988 		v4 = top_dst + uintptr((int32(2)*x-0)*int32(2))
  56989 		v7 = v1 * int32(19077) >> int32(8)
  56990 		goto _126
  56991 	_126:
  56992 		v9 = v3 * int32(26149) >> int32(8)
  56993 		goto _128
  56994 	_128:
  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 _131
  57008 	_131:
  57009 		v5 = v12
  57010 		goto _124
  57011 	_124:
  57012 		r = v5
  57013 		v18 = v1 * int32(19077) >> int32(8)
  57014 		goto _137
  57015 	_137:
  57016 		v20 = v2 * int32(6419) >> int32(8)
  57017 		goto _139
  57018 	_139:
  57019 		v22 = v3 * int32(13320) >> int32(8)
  57020 		goto _141
  57021 	_141:
  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 _144
  57035 	_144:
  57036 		v16 = v25
  57037 		goto _135
  57038 	_135:
  57039 		g = v16
  57040 		v31 = v1 * int32(19077) >> int32(8)
  57041 		goto _150
  57042 	_150:
  57043 		v33 = v2 * int32(33050) >> int32(8)
  57044 		goto _152
  57045 	_152:
  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 _155
  57059 	_155:
  57060 		v29 = v36
  57061 		goto _148
  57062 	_148:
  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 		if bottom_y != libc.UintptrFromInt32(0) {
  57069 			uv03 = (diag_03 + l_uv) >> int32(1)
  57070 			uv11 = (diag_12 + uv) >> int32(1)
  57071 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x-int32(1)))))
  57072 			v2 = libc.Int32FromUint32(uv03 & uint32(0xff))
  57073 			v3 = libc.Int32FromUint32(uv03 >> libc.Int32FromInt32(16))
  57074 			v4 = bottom_dst + uintptr((int32(2)*x-int32(1))*int32(2))
  57075 			v7 = v1 * int32(19077) >> int32(8)
  57076 			goto _165
  57077 		_165:
  57078 			v9 = v3 * int32(26149) >> int32(8)
  57079 			goto _167
  57080 		_167:
  57081 			v11 = v7 + v9 - int32(14234)
  57082 			if v11 & ^int32(YUV_MASK2) == 0 {
  57083 				v14 = v11 >> int32(YUV_FIX2)
  57084 			} else {
  57085 				if v11 < 0 {
  57086 					v15 = 0
  57087 				} else {
  57088 					v15 = int32(255)
  57089 				}
  57090 				v14 = v15
  57091 			}
  57092 			v12 = v14
  57093 			goto _170
  57094 		_170:
  57095 			v5 = v12
  57096 			goto _163
  57097 		_163:
  57098 			r = v5
  57099 			v18 = v1 * int32(19077) >> int32(8)
  57100 			goto _176
  57101 		_176:
  57102 			v20 = v2 * int32(6419) >> int32(8)
  57103 			goto _178
  57104 		_178:
  57105 			v22 = v3 * int32(13320) >> int32(8)
  57106 			goto _180
  57107 		_180:
  57108 			v24 = v18 - v20 - v22 + int32(8708)
  57109 			if v24 & ^int32(YUV_MASK2) == 0 {
  57110 				v27 = v24 >> int32(YUV_FIX2)
  57111 			} else {
  57112 				if v24 < 0 {
  57113 					v28 = 0
  57114 				} else {
  57115 					v28 = int32(255)
  57116 				}
  57117 				v27 = v28
  57118 			}
  57119 			v25 = v27
  57120 			goto _183
  57121 		_183:
  57122 			v16 = v25
  57123 			goto _174
  57124 		_174:
  57125 			g = v16
  57126 			v31 = v1 * int32(19077) >> int32(8)
  57127 			goto _189
  57128 		_189:
  57129 			v33 = v2 * int32(33050) >> int32(8)
  57130 			goto _191
  57131 		_191:
  57132 			v35 = v31 + v33 - int32(17685)
  57133 			if v35 & ^int32(YUV_MASK2) == 0 {
  57134 				v38 = v35 >> int32(YUV_FIX2)
  57135 			} else {
  57136 				if v35 < 0 {
  57137 					v39 = 0
  57138 				} else {
  57139 					v39 = int32(255)
  57140 				}
  57141 				v38 = v39
  57142 			}
  57143 			v36 = v38
  57144 			goto _194
  57145 		_194:
  57146 			v29 = v36
  57147 			goto _187
  57148 		_187:
  57149 			b = v29
  57150 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57151 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57152 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57153 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57154 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(int32(2)*x+0))))
  57155 			v2 = libc.Int32FromUint32(uv11 & uint32(0xff))
  57156 			v3 = libc.Int32FromUint32(uv11 >> libc.Int32FromInt32(16))
  57157 			v4 = bottom_dst + uintptr((int32(2)*x+0)*int32(2))
  57158 			v7 = v1 * int32(19077) >> int32(8)
  57159 			goto _204
  57160 		_204:
  57161 			v9 = v3 * int32(26149) >> int32(8)
  57162 			goto _206
  57163 		_206:
  57164 			v11 = v7 + v9 - int32(14234)
  57165 			if v11 & ^int32(YUV_MASK2) == 0 {
  57166 				v14 = v11 >> int32(YUV_FIX2)
  57167 			} else {
  57168 				if v11 < 0 {
  57169 					v15 = 0
  57170 				} else {
  57171 					v15 = int32(255)
  57172 				}
  57173 				v14 = v15
  57174 			}
  57175 			v12 = v14
  57176 			goto _209
  57177 		_209:
  57178 			v5 = v12
  57179 			goto _202
  57180 		_202:
  57181 			r = v5
  57182 			v18 = v1 * int32(19077) >> int32(8)
  57183 			goto _215
  57184 		_215:
  57185 			v20 = v2 * int32(6419) >> int32(8)
  57186 			goto _217
  57187 		_217:
  57188 			v22 = v3 * int32(13320) >> int32(8)
  57189 			goto _219
  57190 		_219:
  57191 			v24 = v18 - v20 - v22 + int32(8708)
  57192 			if v24 & ^int32(YUV_MASK2) == 0 {
  57193 				v27 = v24 >> int32(YUV_FIX2)
  57194 			} else {
  57195 				if v24 < 0 {
  57196 					v28 = 0
  57197 				} else {
  57198 					v28 = int32(255)
  57199 				}
  57200 				v27 = v28
  57201 			}
  57202 			v25 = v27
  57203 			goto _222
  57204 		_222:
  57205 			v16 = v25
  57206 			goto _213
  57207 		_213:
  57208 			g = v16
  57209 			v31 = v1 * int32(19077) >> int32(8)
  57210 			goto _228
  57211 		_228:
  57212 			v33 = v2 * int32(33050) >> int32(8)
  57213 			goto _230
  57214 		_230:
  57215 			v35 = v31 + v33 - int32(17685)
  57216 			if v35 & ^int32(YUV_MASK2) == 0 {
  57217 				v38 = v35 >> int32(YUV_FIX2)
  57218 			} else {
  57219 				if v35 < 0 {
  57220 					v39 = 0
  57221 				} else {
  57222 					v39 = int32(255)
  57223 				}
  57224 				v38 = v39
  57225 			}
  57226 			v36 = v38
  57227 			goto _233
  57228 		_233:
  57229 			v29 = v36
  57230 			goto _226
  57231 		_226:
  57232 			b = v29
  57233 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57234 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57235 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57236 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57237 		}
  57238 		tl_uv = t_uv
  57239 		l_uv = uv
  57240 		goto _79
  57241 	_79:
  57242 		;
  57243 		x = x + 1
  57244 	}
  57245 	if !(len1&libc.Int32FromInt32(1) != 0) {
  57246 		uv04 = (uint32(3)*tl_uv + l_uv + uint32(0x00020002)) >> int32(2)
  57247 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(top_y + uintptr(len1-int32(1)))))
  57248 		v2 = libc.Int32FromUint32(uv04 & uint32(0xff))
  57249 		v3 = libc.Int32FromUint32(uv04 >> libc.Int32FromInt32(16))
  57250 		v4 = top_dst + uintptr((len1-int32(1))*int32(2))
  57251 		v7 = v1 * int32(19077) >> int32(8)
  57252 		goto _243
  57253 	_243:
  57254 		v9 = v3 * int32(26149) >> int32(8)
  57255 		goto _245
  57256 	_245:
  57257 		v11 = v7 + v9 - int32(14234)
  57258 		if v11 & ^int32(YUV_MASK2) == 0 {
  57259 			v14 = v11 >> int32(YUV_FIX2)
  57260 		} else {
  57261 			if v11 < 0 {
  57262 				v15 = 0
  57263 			} else {
  57264 				v15 = int32(255)
  57265 			}
  57266 			v14 = v15
  57267 		}
  57268 		v12 = v14
  57269 		goto _248
  57270 	_248:
  57271 		v5 = v12
  57272 		goto _241
  57273 	_241:
  57274 		r = v5
  57275 		v18 = v1 * int32(19077) >> int32(8)
  57276 		goto _254
  57277 	_254:
  57278 		v20 = v2 * int32(6419) >> int32(8)
  57279 		goto _256
  57280 	_256:
  57281 		v22 = v3 * int32(13320) >> int32(8)
  57282 		goto _258
  57283 	_258:
  57284 		v24 = v18 - v20 - v22 + int32(8708)
  57285 		if v24 & ^int32(YUV_MASK2) == 0 {
  57286 			v27 = v24 >> int32(YUV_FIX2)
  57287 		} else {
  57288 			if v24 < 0 {
  57289 				v28 = 0
  57290 			} else {
  57291 				v28 = int32(255)
  57292 			}
  57293 			v27 = v28
  57294 		}
  57295 		v25 = v27
  57296 		goto _261
  57297 	_261:
  57298 		v16 = v25
  57299 		goto _252
  57300 	_252:
  57301 		g = v16
  57302 		v31 = v1 * int32(19077) >> int32(8)
  57303 		goto _267
  57304 	_267:
  57305 		v33 = v2 * int32(33050) >> int32(8)
  57306 		goto _269
  57307 	_269:
  57308 		v35 = v31 + v33 - int32(17685)
  57309 		if v35 & ^int32(YUV_MASK2) == 0 {
  57310 			v38 = v35 >> int32(YUV_FIX2)
  57311 		} else {
  57312 			if v35 < 0 {
  57313 				v39 = 0
  57314 			} else {
  57315 				v39 = int32(255)
  57316 			}
  57317 			v38 = v39
  57318 		}
  57319 		v36 = v38
  57320 		goto _272
  57321 	_272:
  57322 		v29 = v36
  57323 		goto _265
  57324 	_265:
  57325 		b = v29
  57326 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57327 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57328 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57329 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57330 		if bottom_y != libc.UintptrFromInt32(0) {
  57331 			uv05 = (uint32(3)*l_uv + tl_uv + uint32(0x00020002)) >> int32(2)
  57332 			v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(bottom_y + uintptr(len1-int32(1)))))
  57333 			v2 = libc.Int32FromUint32(uv05 & uint32(0xff))
  57334 			v3 = libc.Int32FromUint32(uv05 >> libc.Int32FromInt32(16))
  57335 			v4 = bottom_dst + uintptr((len1-int32(1))*int32(2))
  57336 			v7 = v1 * int32(19077) >> int32(8)
  57337 			goto _282
  57338 		_282:
  57339 			v9 = v3 * int32(26149) >> int32(8)
  57340 			goto _284
  57341 		_284:
  57342 			v11 = v7 + v9 - int32(14234)
  57343 			if v11 & ^int32(YUV_MASK2) == 0 {
  57344 				v14 = v11 >> int32(YUV_FIX2)
  57345 			} else {
  57346 				if v11 < 0 {
  57347 					v15 = 0
  57348 				} else {
  57349 					v15 = int32(255)
  57350 				}
  57351 				v14 = v15
  57352 			}
  57353 			v12 = v14
  57354 			goto _287
  57355 		_287:
  57356 			v5 = v12
  57357 			goto _280
  57358 		_280:
  57359 			r = v5
  57360 			v18 = v1 * int32(19077) >> int32(8)
  57361 			goto _293
  57362 		_293:
  57363 			v20 = v2 * int32(6419) >> int32(8)
  57364 			goto _295
  57365 		_295:
  57366 			v22 = v3 * int32(13320) >> int32(8)
  57367 			goto _297
  57368 		_297:
  57369 			v24 = v18 - v20 - v22 + int32(8708)
  57370 			if v24 & ^int32(YUV_MASK2) == 0 {
  57371 				v27 = v24 >> int32(YUV_FIX2)
  57372 			} else {
  57373 				if v24 < 0 {
  57374 					v28 = 0
  57375 				} else {
  57376 					v28 = int32(255)
  57377 				}
  57378 				v27 = v28
  57379 			}
  57380 			v25 = v27
  57381 			goto _300
  57382 		_300:
  57383 			v16 = v25
  57384 			goto _291
  57385 		_291:
  57386 			g = v16
  57387 			v31 = v1 * int32(19077) >> int32(8)
  57388 			goto _306
  57389 		_306:
  57390 			v33 = v2 * int32(33050) >> int32(8)
  57391 			goto _308
  57392 		_308:
  57393 			v35 = v31 + v33 - int32(17685)
  57394 			if v35 & ^int32(YUV_MASK2) == 0 {
  57395 				v38 = v35 >> int32(YUV_FIX2)
  57396 			} else {
  57397 				if v35 < 0 {
  57398 					v39 = 0
  57399 				} else {
  57400 					v39 = int32(255)
  57401 				}
  57402 				v38 = v39
  57403 			}
  57404 			v36 = v38
  57405 			goto _311
  57406 		_311:
  57407 			v29 = v36
  57408 			goto _304
  57409 		_304:
  57410 			b = v29
  57411 			rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  57412 			gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  57413 			**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  57414 			**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  57415 		}
  57416 	}
  57417 }
  57418 
  57419 //------------------------------------------------------------------------------
  57420 
  57421 func WebPGetLinePairConverter(tls *libc.TLS, alpha_is_last int32) (r WebPUpsampleLinePairFunc) {
  57422 	var v1 int32
  57423 	_ = v1
  57424 	WebPInitUpsamplers(tls)
  57425 	if alpha_is_last != 0 {
  57426 		v1 = int32(MODE_BGRA)
  57427 	} else {
  57428 		v1 = int32(MODE_ARGB)
  57429 	}
  57430 	return WebPUpsamplers[v1]
  57431 }
  57432 
  57433 func WebPYuv444ToRgba_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57434 	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
  57435 	var v2, v61 uintptr
  57436 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57437 	i = 0
  57438 	for {
  57439 		if !(i < len1) {
  57440 			break
  57441 		}
  57442 		v2 = dst + uintptr(i*int32(4))
  57443 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57444 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57445 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57446 		v61 = v2
  57447 		v9 = v3 * int32(19077) >> int32(8)
  57448 		goto _10
  57449 	_10:
  57450 		v11 = v5 * int32(26149) >> int32(8)
  57451 		goto _12
  57452 	_12:
  57453 		v13 = v9 + v11 - int32(14234)
  57454 		if v13 & ^int32(YUV_MASK2) == 0 {
  57455 			v16 = v13 >> int32(YUV_FIX2)
  57456 		} else {
  57457 			if v13 < 0 {
  57458 				v17 = 0
  57459 			} else {
  57460 				v17 = int32(255)
  57461 			}
  57462 			v16 = v17
  57463 		}
  57464 		v14 = v16
  57465 		goto _15
  57466 	_15:
  57467 		v7 = v14
  57468 		goto _8
  57469 	_8:
  57470 		**(**uint8_t)(__ccgo_up(v61)) = libc.Uint8FromInt32(v7)
  57471 		v20 = v3 * int32(19077) >> int32(8)
  57472 		goto _21
  57473 	_21:
  57474 		v22 = v4 * int32(6419) >> int32(8)
  57475 		goto _23
  57476 	_23:
  57477 		v24 = v5 * int32(13320) >> int32(8)
  57478 		goto _25
  57479 	_25:
  57480 		v26 = v20 - v22 - v24 + int32(8708)
  57481 		if v26 & ^int32(YUV_MASK2) == 0 {
  57482 			v29 = v26 >> int32(YUV_FIX2)
  57483 		} else {
  57484 			if v26 < 0 {
  57485 				v30 = 0
  57486 			} else {
  57487 				v30 = int32(255)
  57488 			}
  57489 			v29 = v30
  57490 		}
  57491 		v27 = v29
  57492 		goto _28
  57493 	_28:
  57494 		v18 = v27
  57495 		goto _19
  57496 	_19:
  57497 		**(**uint8_t)(__ccgo_up(v61 + 1)) = libc.Uint8FromInt32(v18)
  57498 		v33 = v3 * int32(19077) >> int32(8)
  57499 		goto _34
  57500 	_34:
  57501 		v35 = v4 * int32(33050) >> int32(8)
  57502 		goto _36
  57503 	_36:
  57504 		v37 = v33 + v35 - int32(17685)
  57505 		if v37 & ^int32(YUV_MASK2) == 0 {
  57506 			v40 = v37 >> int32(YUV_FIX2)
  57507 		} else {
  57508 			if v37 < 0 {
  57509 				v41 = 0
  57510 			} else {
  57511 				v41 = int32(255)
  57512 			}
  57513 			v40 = v41
  57514 		}
  57515 		v38 = v40
  57516 		goto _39
  57517 	_39:
  57518 		v31 = v38
  57519 		goto _32
  57520 	_32:
  57521 		**(**uint8_t)(__ccgo_up(v61 + 2)) = libc.Uint8FromInt32(v31)
  57522 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57523 		goto _1
  57524 	_1:
  57525 		;
  57526 		i = i + 1
  57527 	}
  57528 }
  57529 
  57530 func WebPYuv444ToBgra_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57531 	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
  57532 	var v2, v61 uintptr
  57533 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57534 	i = 0
  57535 	for {
  57536 		if !(i < len1) {
  57537 			break
  57538 		}
  57539 		v2 = dst + uintptr(i*int32(4))
  57540 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57541 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57542 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57543 		v61 = v2
  57544 		v9 = v3 * int32(19077) >> int32(8)
  57545 		goto _10
  57546 	_10:
  57547 		v11 = v4 * int32(33050) >> int32(8)
  57548 		goto _12
  57549 	_12:
  57550 		v13 = v9 + v11 - int32(17685)
  57551 		if v13 & ^int32(YUV_MASK2) == 0 {
  57552 			v16 = v13 >> int32(YUV_FIX2)
  57553 		} else {
  57554 			if v13 < 0 {
  57555 				v17 = 0
  57556 			} else {
  57557 				v17 = int32(255)
  57558 			}
  57559 			v16 = v17
  57560 		}
  57561 		v14 = v16
  57562 		goto _15
  57563 	_15:
  57564 		v7 = v14
  57565 		goto _8
  57566 	_8:
  57567 		**(**uint8_t)(__ccgo_up(v61)) = libc.Uint8FromInt32(v7)
  57568 		v20 = v3 * int32(19077) >> int32(8)
  57569 		goto _21
  57570 	_21:
  57571 		v22 = v4 * int32(6419) >> int32(8)
  57572 		goto _23
  57573 	_23:
  57574 		v24 = v5 * int32(13320) >> int32(8)
  57575 		goto _25
  57576 	_25:
  57577 		v26 = v20 - v22 - v24 + int32(8708)
  57578 		if v26 & ^int32(YUV_MASK2) == 0 {
  57579 			v29 = v26 >> int32(YUV_FIX2)
  57580 		} else {
  57581 			if v26 < 0 {
  57582 				v30 = 0
  57583 			} else {
  57584 				v30 = int32(255)
  57585 			}
  57586 			v29 = v30
  57587 		}
  57588 		v27 = v29
  57589 		goto _28
  57590 	_28:
  57591 		v18 = v27
  57592 		goto _19
  57593 	_19:
  57594 		**(**uint8_t)(__ccgo_up(v61 + 1)) = libc.Uint8FromInt32(v18)
  57595 		v33 = v3 * int32(19077) >> int32(8)
  57596 		goto _34
  57597 	_34:
  57598 		v35 = v5 * int32(26149) >> int32(8)
  57599 		goto _36
  57600 	_36:
  57601 		v37 = v33 + v35 - int32(14234)
  57602 		if v37 & ^int32(YUV_MASK2) == 0 {
  57603 			v40 = v37 >> int32(YUV_FIX2)
  57604 		} else {
  57605 			if v37 < 0 {
  57606 				v41 = 0
  57607 			} else {
  57608 				v41 = int32(255)
  57609 			}
  57610 			v40 = v41
  57611 		}
  57612 		v38 = v40
  57613 		goto _39
  57614 	_39:
  57615 		v31 = v38
  57616 		goto _32
  57617 	_32:
  57618 		**(**uint8_t)(__ccgo_up(v61 + 2)) = libc.Uint8FromInt32(v31)
  57619 		**(**uint8_t)(__ccgo_up(v2 + 3)) = uint8(0xff)
  57620 		goto _1
  57621 	_1:
  57622 		;
  57623 		i = i + 1
  57624 	}
  57625 }
  57626 
  57627 func WebPYuv444ToRgb_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57628 	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
  57629 	var v51 uintptr
  57630 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57631 	i = 0
  57632 	for {
  57633 		if !(i < len1) {
  57634 			break
  57635 		}
  57636 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57637 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57638 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57639 		v51 = dst + uintptr(i*int32(3))
  57640 		v8 = v2 * int32(19077) >> int32(8)
  57641 		goto _9
  57642 	_9:
  57643 		v10 = v4 * int32(26149) >> int32(8)
  57644 		goto _11
  57645 	_11:
  57646 		v12 = v8 + v10 - int32(14234)
  57647 		if v12 & ^int32(YUV_MASK2) == 0 {
  57648 			v15 = v12 >> int32(YUV_FIX2)
  57649 		} else {
  57650 			if v12 < 0 {
  57651 				v16 = 0
  57652 			} else {
  57653 				v16 = int32(255)
  57654 			}
  57655 			v15 = v16
  57656 		}
  57657 		v13 = v15
  57658 		goto _14
  57659 	_14:
  57660 		v6 = v13
  57661 		goto _7
  57662 	_7:
  57663 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(v6)
  57664 		v19 = v2 * int32(19077) >> int32(8)
  57665 		goto _20
  57666 	_20:
  57667 		v21 = v3 * int32(6419) >> int32(8)
  57668 		goto _22
  57669 	_22:
  57670 		v23 = v4 * int32(13320) >> int32(8)
  57671 		goto _24
  57672 	_24:
  57673 		v25 = v19 - v21 - v23 + int32(8708)
  57674 		if v25 & ^int32(YUV_MASK2) == 0 {
  57675 			v28 = v25 >> int32(YUV_FIX2)
  57676 		} else {
  57677 			if v25 < 0 {
  57678 				v29 = 0
  57679 			} else {
  57680 				v29 = int32(255)
  57681 			}
  57682 			v28 = v29
  57683 		}
  57684 		v26 = v28
  57685 		goto _27
  57686 	_27:
  57687 		v17 = v26
  57688 		goto _18
  57689 	_18:
  57690 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(v17)
  57691 		v32 = v2 * int32(19077) >> int32(8)
  57692 		goto _33
  57693 	_33:
  57694 		v34 = v3 * int32(33050) >> int32(8)
  57695 		goto _35
  57696 	_35:
  57697 		v36 = v32 + v34 - int32(17685)
  57698 		if v36 & ^int32(YUV_MASK2) == 0 {
  57699 			v39 = v36 >> int32(YUV_FIX2)
  57700 		} else {
  57701 			if v36 < 0 {
  57702 				v40 = 0
  57703 			} else {
  57704 				v40 = int32(255)
  57705 			}
  57706 			v39 = v40
  57707 		}
  57708 		v37 = v39
  57709 		goto _38
  57710 	_38:
  57711 		v30 = v37
  57712 		goto _31
  57713 	_31:
  57714 		**(**uint8_t)(__ccgo_up(v51 + 2)) = libc.Uint8FromInt32(v30)
  57715 		goto _1
  57716 	_1:
  57717 		;
  57718 		i = i + 1
  57719 	}
  57720 }
  57721 
  57722 func WebPYuv444ToBgr_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57723 	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
  57724 	var v51 uintptr
  57725 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57726 	i = 0
  57727 	for {
  57728 		if !(i < len1) {
  57729 			break
  57730 		}
  57731 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57732 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57733 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57734 		v51 = dst + uintptr(i*int32(3))
  57735 		v8 = v2 * int32(19077) >> int32(8)
  57736 		goto _9
  57737 	_9:
  57738 		v10 = v3 * int32(33050) >> int32(8)
  57739 		goto _11
  57740 	_11:
  57741 		v12 = v8 + v10 - int32(17685)
  57742 		if v12 & ^int32(YUV_MASK2) == 0 {
  57743 			v15 = v12 >> int32(YUV_FIX2)
  57744 		} else {
  57745 			if v12 < 0 {
  57746 				v16 = 0
  57747 			} else {
  57748 				v16 = int32(255)
  57749 			}
  57750 			v15 = v16
  57751 		}
  57752 		v13 = v15
  57753 		goto _14
  57754 	_14:
  57755 		v6 = v13
  57756 		goto _7
  57757 	_7:
  57758 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(v6)
  57759 		v19 = v2 * int32(19077) >> int32(8)
  57760 		goto _20
  57761 	_20:
  57762 		v21 = v3 * int32(6419) >> int32(8)
  57763 		goto _22
  57764 	_22:
  57765 		v23 = v4 * int32(13320) >> int32(8)
  57766 		goto _24
  57767 	_24:
  57768 		v25 = v19 - v21 - v23 + int32(8708)
  57769 		if v25 & ^int32(YUV_MASK2) == 0 {
  57770 			v28 = v25 >> int32(YUV_FIX2)
  57771 		} else {
  57772 			if v25 < 0 {
  57773 				v29 = 0
  57774 			} else {
  57775 				v29 = int32(255)
  57776 			}
  57777 			v28 = v29
  57778 		}
  57779 		v26 = v28
  57780 		goto _27
  57781 	_27:
  57782 		v17 = v26
  57783 		goto _18
  57784 	_18:
  57785 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(v17)
  57786 		v32 = v2 * int32(19077) >> int32(8)
  57787 		goto _33
  57788 	_33:
  57789 		v34 = v4 * int32(26149) >> int32(8)
  57790 		goto _35
  57791 	_35:
  57792 		v36 = v32 + v34 - int32(14234)
  57793 		if v36 & ^int32(YUV_MASK2) == 0 {
  57794 			v39 = v36 >> int32(YUV_FIX2)
  57795 		} else {
  57796 			if v36 < 0 {
  57797 				v40 = 0
  57798 			} else {
  57799 				v40 = int32(255)
  57800 			}
  57801 			v39 = v40
  57802 		}
  57803 		v37 = v39
  57804 		goto _38
  57805 	_38:
  57806 		v30 = v37
  57807 		goto _31
  57808 	_31:
  57809 		**(**uint8_t)(__ccgo_up(v51 + 2)) = libc.Uint8FromInt32(v30)
  57810 		goto _1
  57811 	_1:
  57812 		;
  57813 		i = i + 1
  57814 	}
  57815 }
  57816 
  57817 func WebPYuv444ToArgb_C(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  57818 	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
  57819 	var v2, v61 uintptr
  57820 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57821 	i = 0
  57822 	for {
  57823 		if !(i < len1) {
  57824 			break
  57825 		}
  57826 		v2 = dst + uintptr(i*int32(4))
  57827 		**(**uint8_t)(__ccgo_up(v2)) = uint8(0xff)
  57828 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + uintptr(i))))
  57829 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4 + uintptr(i))))
  57830 		v5 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6 + uintptr(i))))
  57831 		v61 = v2 + uintptr(1)
  57832 		v9 = v3 * int32(19077) >> int32(8)
  57833 		goto _10
  57834 	_10:
  57835 		v11 = v5 * int32(26149) >> int32(8)
  57836 		goto _12
  57837 	_12:
  57838 		v13 = v9 + v11 - int32(14234)
  57839 		if v13 & ^int32(YUV_MASK2) == 0 {
  57840 			v16 = v13 >> int32(YUV_FIX2)
  57841 		} else {
  57842 			if v13 < 0 {
  57843 				v17 = 0
  57844 			} else {
  57845 				v17 = int32(255)
  57846 			}
  57847 			v16 = v17
  57848 		}
  57849 		v14 = v16
  57850 		goto _15
  57851 	_15:
  57852 		v7 = v14
  57853 		goto _8
  57854 	_8:
  57855 		**(**uint8_t)(__ccgo_up(v61)) = libc.Uint8FromInt32(v7)
  57856 		v20 = v3 * int32(19077) >> int32(8)
  57857 		goto _21
  57858 	_21:
  57859 		v22 = v4 * int32(6419) >> int32(8)
  57860 		goto _23
  57861 	_23:
  57862 		v24 = v5 * int32(13320) >> int32(8)
  57863 		goto _25
  57864 	_25:
  57865 		v26 = v20 - v22 - v24 + int32(8708)
  57866 		if v26 & ^int32(YUV_MASK2) == 0 {
  57867 			v29 = v26 >> int32(YUV_FIX2)
  57868 		} else {
  57869 			if v26 < 0 {
  57870 				v30 = 0
  57871 			} else {
  57872 				v30 = int32(255)
  57873 			}
  57874 			v29 = v30
  57875 		}
  57876 		v27 = v29
  57877 		goto _28
  57878 	_28:
  57879 		v18 = v27
  57880 		goto _19
  57881 	_19:
  57882 		**(**uint8_t)(__ccgo_up(v61 + 1)) = libc.Uint8FromInt32(v18)
  57883 		v33 = v3 * int32(19077) >> int32(8)
  57884 		goto _34
  57885 	_34:
  57886 		v35 = v4 * int32(33050) >> int32(8)
  57887 		goto _36
  57888 	_36:
  57889 		v37 = v33 + v35 - int32(17685)
  57890 		if v37 & ^int32(YUV_MASK2) == 0 {
  57891 			v40 = v37 >> int32(YUV_FIX2)
  57892 		} else {
  57893 			if v37 < 0 {
  57894 				v41 = 0
  57895 			} else {
  57896 				v41 = int32(255)
  57897 			}
  57898 			v40 = v41
  57899 		}
  57900 		v38 = v40
  57901 		goto _39
  57902 	_39:
  57903 		v31 = v38
  57904 		goto _32
  57905 	_32:
  57906 		**(**uint8_t)(__ccgo_up(v61 + 2)) = libc.Uint8FromInt32(v31)
  57907 		goto _1
  57908 	_1:
  57909 		;
  57910 		i = i + 1
  57911 	}
  57912 }
  57913 
  57914 func WebPYuv444ToRgba4444_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  57915 	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
  57916 	var v51 uintptr
  57917 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  57918 	i = 0
  57919 	for {
  57920 		if !(i < len1) {
  57921 			break
  57922 		}
  57923 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  57924 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  57925 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  57926 		v51 = dst + uintptr(i*int32(2))
  57927 		v8 = v2 * int32(19077) >> int32(8)
  57928 		goto _9
  57929 	_9:
  57930 		v10 = v4 * int32(26149) >> int32(8)
  57931 		goto _11
  57932 	_11:
  57933 		v12 = v8 + v10 - int32(14234)
  57934 		if v12 & ^int32(YUV_MASK2) == 0 {
  57935 			v15 = v12 >> int32(YUV_FIX2)
  57936 		} else {
  57937 			if v12 < 0 {
  57938 				v16 = 0
  57939 			} else {
  57940 				v16 = int32(255)
  57941 			}
  57942 			v15 = v16
  57943 		}
  57944 		v13 = v15
  57945 		goto _14
  57946 	_14:
  57947 		v6 = v13
  57948 		goto _7
  57949 	_7:
  57950 		r = v6
  57951 		v19 = v2 * int32(19077) >> int32(8)
  57952 		goto _20
  57953 	_20:
  57954 		v21 = v3 * int32(6419) >> int32(8)
  57955 		goto _22
  57956 	_22:
  57957 		v23 = v4 * int32(13320) >> int32(8)
  57958 		goto _24
  57959 	_24:
  57960 		v25 = v19 - v21 - v23 + int32(8708)
  57961 		if v25 & ^int32(YUV_MASK2) == 0 {
  57962 			v28 = v25 >> int32(YUV_FIX2)
  57963 		} else {
  57964 			if v25 < 0 {
  57965 				v29 = 0
  57966 			} else {
  57967 				v29 = int32(255)
  57968 			}
  57969 			v28 = v29
  57970 		}
  57971 		v26 = v28
  57972 		goto _27
  57973 	_27:
  57974 		v17 = v26
  57975 		goto _18
  57976 	_18:
  57977 		g = v17
  57978 		v32 = v2 * int32(19077) >> int32(8)
  57979 		goto _33
  57980 	_33:
  57981 		v34 = v3 * int32(33050) >> int32(8)
  57982 		goto _35
  57983 	_35:
  57984 		v36 = v32 + v34 - int32(17685)
  57985 		if v36 & ^int32(YUV_MASK2) == 0 {
  57986 			v39 = v36 >> int32(YUV_FIX2)
  57987 		} else {
  57988 			if v36 < 0 {
  57989 				v40 = 0
  57990 			} else {
  57991 				v40 = int32(255)
  57992 			}
  57993 			v39 = v40
  57994 		}
  57995 		v37 = v39
  57996 		goto _38
  57997 	_38:
  57998 		v30 = v37
  57999 		goto _31
  58000 	_31:
  58001 		b = v30
  58002 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  58003 		ba = b&int32(0xf0) | int32(0x0f)
  58004 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(rg)
  58005 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(ba)
  58006 		goto _1
  58007 	_1:
  58008 		;
  58009 		i = i + 1
  58010 	}
  58011 }
  58012 
  58013 func WebPYuv444ToRgb565_C(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58014 	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
  58015 	var v51 uintptr
  58016 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58017 	i = 0
  58018 	for {
  58019 		if !(i < len1) {
  58020 			break
  58021 		}
  58022 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + uintptr(i))))
  58023 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3 + uintptr(i))))
  58024 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5 + uintptr(i))))
  58025 		v51 = dst + uintptr(i*int32(2))
  58026 		v8 = v2 * int32(19077) >> int32(8)
  58027 		goto _9
  58028 	_9:
  58029 		v10 = v4 * int32(26149) >> int32(8)
  58030 		goto _11
  58031 	_11:
  58032 		v12 = v8 + v10 - int32(14234)
  58033 		if v12 & ^int32(YUV_MASK2) == 0 {
  58034 			v15 = v12 >> int32(YUV_FIX2)
  58035 		} else {
  58036 			if v12 < 0 {
  58037 				v16 = 0
  58038 			} else {
  58039 				v16 = int32(255)
  58040 			}
  58041 			v15 = v16
  58042 		}
  58043 		v13 = v15
  58044 		goto _14
  58045 	_14:
  58046 		v6 = v13
  58047 		goto _7
  58048 	_7:
  58049 		r = v6
  58050 		v19 = v2 * int32(19077) >> int32(8)
  58051 		goto _20
  58052 	_20:
  58053 		v21 = v3 * int32(6419) >> int32(8)
  58054 		goto _22
  58055 	_22:
  58056 		v23 = v4 * int32(13320) >> int32(8)
  58057 		goto _24
  58058 	_24:
  58059 		v25 = v19 - v21 - v23 + int32(8708)
  58060 		if v25 & ^int32(YUV_MASK2) == 0 {
  58061 			v28 = v25 >> int32(YUV_FIX2)
  58062 		} else {
  58063 			if v25 < 0 {
  58064 				v29 = 0
  58065 			} else {
  58066 				v29 = int32(255)
  58067 			}
  58068 			v28 = v29
  58069 		}
  58070 		v26 = v28
  58071 		goto _27
  58072 	_27:
  58073 		v17 = v26
  58074 		goto _18
  58075 	_18:
  58076 		g = v17
  58077 		v32 = v2 * int32(19077) >> int32(8)
  58078 		goto _33
  58079 	_33:
  58080 		v34 = v3 * int32(33050) >> int32(8)
  58081 		goto _35
  58082 	_35:
  58083 		v36 = v32 + v34 - int32(17685)
  58084 		if v36 & ^int32(YUV_MASK2) == 0 {
  58085 			v39 = v36 >> int32(YUV_FIX2)
  58086 		} else {
  58087 			if v36 < 0 {
  58088 				v40 = 0
  58089 			} else {
  58090 				v40 = int32(255)
  58091 			}
  58092 			v39 = v40
  58093 		}
  58094 		v37 = v39
  58095 		goto _38
  58096 	_38:
  58097 		v30 = v37
  58098 		goto _31
  58099 	_31:
  58100 		b = v30
  58101 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  58102 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  58103 		**(**uint8_t)(__ccgo_up(v51)) = libc.Uint8FromInt32(rg)
  58104 		**(**uint8_t)(__ccgo_up(v51 + 1)) = libc.Uint8FromInt32(gb)
  58105 		goto _1
  58106 	_1:
  58107 		;
  58108 		i = i + 1
  58109 	}
  58110 }
  58111 
  58112 func WebPInitYUV444Converters(tls *libc.TLS) {
  58113 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  58114 		goto _1
  58115 	}
  58116 	WebPInitYUV444Converters_body(tls)
  58117 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)), VP8GetCPUInfo)
  58118 	goto _2
  58119 _2:
  58120 	;
  58121 	goto _1
  58122 _1: /**/ //
  58123 }
  58124 
  58125 var WebPInitYUV444Converters_body_last_cpuinfo_used = uintptr(0)
  58126 
  58127 func init() {
  58128 	p := unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used)
  58129 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitYUV444Converters_body_last_cpuinfo_used))
  58130 }
  58131 
  58132 func WebPInitYUV444Converters_body(tls *libc.TLS) {
  58133 	WebPYUV444Converters[int32(MODE_RGBA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  58134 	WebPYUV444Converters[int32(MODE_BGRA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  58135 	WebPYUV444Converters[int32(MODE_RGB)] = __ccgo_fp(WebPYuv444ToRgb_C)
  58136 	WebPYUV444Converters[int32(MODE_BGR)] = __ccgo_fp(WebPYuv444ToBgr_C)
  58137 	WebPYUV444Converters[int32(MODE_ARGB)] = __ccgo_fp(WebPYuv444ToArgb_C)
  58138 	WebPYUV444Converters[int32(MODE_RGBA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  58139 	WebPYUV444Converters[int32(MODE_RGB_565)] = __ccgo_fp(WebPYuv444ToRgb565_C)
  58140 	WebPYUV444Converters[int32(MODE_rgbA)] = __ccgo_fp(WebPYuv444ToRgba_C)
  58141 	WebPYUV444Converters[int32(MODE_bgrA)] = __ccgo_fp(WebPYuv444ToBgra_C)
  58142 	WebPYUV444Converters[int32(MODE_Argb)] = __ccgo_fp(WebPYuv444ToArgb_C)
  58143 	WebPYUV444Converters[int32(MODE_rgbA_4444)] = __ccgo_fp(WebPYuv444ToRgba4444_C)
  58144 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58145 	}
  58146 }
  58147 
  58148 func WebPInitUpsamplers(tls *libc.TLS) {
  58149 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  58150 		goto _1
  58151 	}
  58152 	WebPInitUpsamplers_body(tls)
  58153 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  58154 	goto _2
  58155 _2:
  58156 	;
  58157 	goto _1
  58158 _1: /**/ //
  58159 }
  58160 
  58161 var WebPInitUpsamplers_body_last_cpuinfo_used = uintptr(0)
  58162 
  58163 func init() {
  58164 	p := unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used)
  58165 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitUpsamplers_body_last_cpuinfo_used))
  58166 }
  58167 
  58168 func WebPInitUpsamplers_body(tls *libc.TLS) {
  58169 	WebPUpsamplers[int32(MODE_RGBA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58170 	WebPUpsamplers[int32(MODE_BGRA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58171 	WebPUpsamplers[int32(MODE_rgbA)] = __ccgo_fp(UpsampleRgbaLinePair_C)
  58172 	WebPUpsamplers[int32(MODE_bgrA)] = __ccgo_fp(UpsampleBgraLinePair_C)
  58173 	WebPUpsamplers[int32(MODE_RGB)] = __ccgo_fp(UpsampleRgbLinePair_C)
  58174 	WebPUpsamplers[int32(MODE_BGR)] = __ccgo_fp(UpsampleBgrLinePair_C)
  58175 	WebPUpsamplers[int32(MODE_ARGB)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58176 	WebPUpsamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58177 	WebPUpsamplers[int32(MODE_RGB_565)] = __ccgo_fp(UpsampleRgb565LinePair_C)
  58178 	WebPUpsamplers[int32(MODE_Argb)] = __ccgo_fp(UpsampleArgbLinePair_C)
  58179 	WebPUpsamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(UpsampleRgba4444LinePair_C)
  58180 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  58181 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  58182 	}
  58183 }
  58184 
  58185 func WebPInitYUV444ConvertersMIPSdspR2(tls *libc.TLS) {
  58186 }
  58187 
  58188 func WebPInitUpsamplersMIPSdspR2(tls *libc.TLS) {
  58189 }
  58190 
  58191 func WebPInitUpsamplersMSA(tls *libc.TLS) {
  58192 }
  58193 
  58194 func WebPInitUpsamplersNEON(tls *libc.TLS) {
  58195 }
  58196 
  58197 func WebPInitYUV444ConvertersSSE2(tls *libc.TLS) {
  58198 }
  58199 
  58200 func WebPInitUpsamplersSSE2(tls *libc.TLS) {
  58201 }
  58202 
  58203 func WebPInitYUV444ConvertersSSE41(tls *libc.TLS) {
  58204 }
  58205 
  58206 func WebPInitUpsamplersSSE41(tls *libc.TLS) {
  58207 }
  58208 
  58209 // Copyright 2010 Google Inc. All Rights Reserved.
  58210 //
  58211 // Use of this source code is governed by a BSD-style license
  58212 // that can be found in the COPYING file in the root of the source
  58213 // tree. An additional intellectual property rights grant can be found
  58214 // in the file PATENTS. All contributing project authors may
  58215 // be found in the AUTHORS file in the root of the source tree.
  58216 // -----------------------------------------------------------------------------
  58217 //
  58218 //  Main decoding functions for WebP images.
  58219 //
  58220 // Author: Skal (pascal.massimino@gmail.com)
  58221 
  58222 //-----------------------------------------------------------------------------
  58223 // Plain-C version
  58224 
  58225 // C documentation
  58226 //
  58227 //	// All variants implemented.
  58228 func YuvToRgbRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58229 	var end, v4 uintptr
  58230 	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
  58231 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58232 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58233 	for dst != end {
  58234 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58235 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58236 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58237 		v4 = dst
  58238 		v7 = v1 * int32(19077) >> int32(8)
  58239 		goto _8
  58240 	_8:
  58241 		v9 = v3 * int32(26149) >> int32(8)
  58242 		goto _10
  58243 	_10:
  58244 		v11 = v7 + v9 - int32(14234)
  58245 		if v11 & ^int32(YUV_MASK2) == 0 {
  58246 			v14 = v11 >> int32(YUV_FIX2)
  58247 		} else {
  58248 			if v11 < 0 {
  58249 				v15 = 0
  58250 			} else {
  58251 				v15 = int32(255)
  58252 			}
  58253 			v14 = v15
  58254 		}
  58255 		v12 = v14
  58256 		goto _13
  58257 	_13:
  58258 		v51 = v12
  58259 		goto _6
  58260 	_6:
  58261 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58262 		v18 = v1 * int32(19077) >> int32(8)
  58263 		goto _19
  58264 	_19:
  58265 		v20 = v2 * int32(6419) >> int32(8)
  58266 		goto _21
  58267 	_21:
  58268 		v22 = v3 * int32(13320) >> int32(8)
  58269 		goto _23
  58270 	_23:
  58271 		v24 = v18 - v20 - v22 + int32(8708)
  58272 		if v24 & ^int32(YUV_MASK2) == 0 {
  58273 			v27 = v24 >> int32(YUV_FIX2)
  58274 		} else {
  58275 			if v24 < 0 {
  58276 				v28 = 0
  58277 			} else {
  58278 				v28 = int32(255)
  58279 			}
  58280 			v27 = v28
  58281 		}
  58282 		v25 = v27
  58283 		goto _26
  58284 	_26:
  58285 		v16 = v25
  58286 		goto _17
  58287 	_17:
  58288 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58289 		v31 = v1 * int32(19077) >> int32(8)
  58290 		goto _32
  58291 	_32:
  58292 		v33 = v2 * int32(33050) >> int32(8)
  58293 		goto _34
  58294 	_34:
  58295 		v35 = v31 + v33 - int32(17685)
  58296 		if v35 & ^int32(YUV_MASK2) == 0 {
  58297 			v38 = v35 >> int32(YUV_FIX2)
  58298 		} else {
  58299 			if v35 < 0 {
  58300 				v39 = 0
  58301 			} else {
  58302 				v39 = int32(255)
  58303 			}
  58304 			v38 = v39
  58305 		}
  58306 		v36 = v38
  58307 		goto _37
  58308 	_37:
  58309 		v29 = v36
  58310 		goto _30
  58311 	_30:
  58312 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58313 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58314 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58315 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58316 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58317 		v7 = v1 * int32(19077) >> int32(8)
  58318 		goto _47
  58319 	_47:
  58320 		v9 = v3 * int32(26149) >> int32(8)
  58321 		goto _49
  58322 	_49:
  58323 		v11 = v7 + v9 - int32(14234)
  58324 		if v11 & ^int32(YUV_MASK2) == 0 {
  58325 			v14 = v11 >> int32(YUV_FIX2)
  58326 		} else {
  58327 			if v11 < 0 {
  58328 				v15 = 0
  58329 			} else {
  58330 				v15 = int32(255)
  58331 			}
  58332 			v14 = v15
  58333 		}
  58334 		v12 = v14
  58335 		goto _52
  58336 	_52:
  58337 		v51 = v12
  58338 		goto _45
  58339 	_45:
  58340 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58341 		v18 = v1 * int32(19077) >> int32(8)
  58342 		goto _58
  58343 	_58:
  58344 		v20 = v2 * int32(6419) >> int32(8)
  58345 		goto _60
  58346 	_60:
  58347 		v22 = v3 * int32(13320) >> int32(8)
  58348 		goto _62
  58349 	_62:
  58350 		v24 = v18 - v20 - v22 + int32(8708)
  58351 		if v24 & ^int32(YUV_MASK2) == 0 {
  58352 			v27 = v24 >> int32(YUV_FIX2)
  58353 		} else {
  58354 			if v24 < 0 {
  58355 				v28 = 0
  58356 			} else {
  58357 				v28 = int32(255)
  58358 			}
  58359 			v27 = v28
  58360 		}
  58361 		v25 = v27
  58362 		goto _65
  58363 	_65:
  58364 		v16 = v25
  58365 		goto _56
  58366 	_56:
  58367 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58368 		v31 = v1 * int32(19077) >> int32(8)
  58369 		goto _71
  58370 	_71:
  58371 		v33 = v2 * int32(33050) >> int32(8)
  58372 		goto _73
  58373 	_73:
  58374 		v35 = v31 + v33 - int32(17685)
  58375 		if v35 & ^int32(YUV_MASK2) == 0 {
  58376 			v38 = v35 >> int32(YUV_FIX2)
  58377 		} else {
  58378 			if v35 < 0 {
  58379 				v39 = 0
  58380 			} else {
  58381 				v39 = int32(255)
  58382 			}
  58383 			v38 = v39
  58384 		}
  58385 		v36 = v38
  58386 		goto _76
  58387 	_76:
  58388 		v29 = v36
  58389 		goto _69
  58390 	_69:
  58391 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58392 		y4 = y4 + uintptr(2)
  58393 		u3 = u3 + 1
  58394 		v5 = v5 + 1
  58395 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58396 	}
  58397 	if len1&int32(1) != 0 {
  58398 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58399 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58400 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58401 		v4 = dst
  58402 		v7 = v1 * int32(19077) >> int32(8)
  58403 		goto _86
  58404 	_86:
  58405 		v9 = v3 * int32(26149) >> int32(8)
  58406 		goto _88
  58407 	_88:
  58408 		v11 = v7 + v9 - int32(14234)
  58409 		if v11 & ^int32(YUV_MASK2) == 0 {
  58410 			v14 = v11 >> int32(YUV_FIX2)
  58411 		} else {
  58412 			if v11 < 0 {
  58413 				v15 = 0
  58414 			} else {
  58415 				v15 = int32(255)
  58416 			}
  58417 			v14 = v15
  58418 		}
  58419 		v12 = v14
  58420 		goto _91
  58421 	_91:
  58422 		v51 = v12
  58423 		goto _84
  58424 	_84:
  58425 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58426 		v18 = v1 * int32(19077) >> int32(8)
  58427 		goto _97
  58428 	_97:
  58429 		v20 = v2 * int32(6419) >> int32(8)
  58430 		goto _99
  58431 	_99:
  58432 		v22 = v3 * int32(13320) >> int32(8)
  58433 		goto _101
  58434 	_101:
  58435 		v24 = v18 - v20 - v22 + int32(8708)
  58436 		if v24 & ^int32(YUV_MASK2) == 0 {
  58437 			v27 = v24 >> int32(YUV_FIX2)
  58438 		} else {
  58439 			if v24 < 0 {
  58440 				v28 = 0
  58441 			} else {
  58442 				v28 = int32(255)
  58443 			}
  58444 			v27 = v28
  58445 		}
  58446 		v25 = v27
  58447 		goto _104
  58448 	_104:
  58449 		v16 = v25
  58450 		goto _95
  58451 	_95:
  58452 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58453 		v31 = v1 * int32(19077) >> int32(8)
  58454 		goto _110
  58455 	_110:
  58456 		v33 = v2 * int32(33050) >> int32(8)
  58457 		goto _112
  58458 	_112:
  58459 		v35 = v31 + v33 - int32(17685)
  58460 		if v35 & ^int32(YUV_MASK2) == 0 {
  58461 			v38 = v35 >> int32(YUV_FIX2)
  58462 		} else {
  58463 			if v35 < 0 {
  58464 				v39 = 0
  58465 			} else {
  58466 				v39 = int32(255)
  58467 			}
  58468 			v38 = v39
  58469 		}
  58470 		v36 = v38
  58471 		goto _115
  58472 	_115:
  58473 		v29 = v36
  58474 		goto _108
  58475 	_108:
  58476 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58477 	}
  58478 }
  58479 
  58480 func YuvToBgrRow(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  58481 	var end, v4 uintptr
  58482 	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
  58483 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58484 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(3))
  58485 	for dst != end {
  58486 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58487 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58488 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58489 		v4 = dst
  58490 		v7 = v1 * int32(19077) >> int32(8)
  58491 		goto _8
  58492 	_8:
  58493 		v9 = v2 * int32(33050) >> int32(8)
  58494 		goto _10
  58495 	_10:
  58496 		v11 = v7 + v9 - int32(17685)
  58497 		if v11 & ^int32(YUV_MASK2) == 0 {
  58498 			v14 = v11 >> int32(YUV_FIX2)
  58499 		} else {
  58500 			if v11 < 0 {
  58501 				v15 = 0
  58502 			} else {
  58503 				v15 = int32(255)
  58504 			}
  58505 			v14 = v15
  58506 		}
  58507 		v12 = v14
  58508 		goto _13
  58509 	_13:
  58510 		v51 = v12
  58511 		goto _6
  58512 	_6:
  58513 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58514 		v18 = v1 * int32(19077) >> int32(8)
  58515 		goto _19
  58516 	_19:
  58517 		v20 = v2 * int32(6419) >> int32(8)
  58518 		goto _21
  58519 	_21:
  58520 		v22 = v3 * int32(13320) >> int32(8)
  58521 		goto _23
  58522 	_23:
  58523 		v24 = v18 - v20 - v22 + int32(8708)
  58524 		if v24 & ^int32(YUV_MASK2) == 0 {
  58525 			v27 = v24 >> int32(YUV_FIX2)
  58526 		} else {
  58527 			if v24 < 0 {
  58528 				v28 = 0
  58529 			} else {
  58530 				v28 = int32(255)
  58531 			}
  58532 			v27 = v28
  58533 		}
  58534 		v25 = v27
  58535 		goto _26
  58536 	_26:
  58537 		v16 = v25
  58538 		goto _17
  58539 	_17:
  58540 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58541 		v31 = v1 * int32(19077) >> int32(8)
  58542 		goto _32
  58543 	_32:
  58544 		v33 = v3 * int32(26149) >> int32(8)
  58545 		goto _34
  58546 	_34:
  58547 		v35 = v31 + v33 - int32(14234)
  58548 		if v35 & ^int32(YUV_MASK2) == 0 {
  58549 			v38 = v35 >> int32(YUV_FIX2)
  58550 		} else {
  58551 			if v35 < 0 {
  58552 				v39 = 0
  58553 			} else {
  58554 				v39 = int32(255)
  58555 			}
  58556 			v38 = v39
  58557 		}
  58558 		v36 = v38
  58559 		goto _37
  58560 	_37:
  58561 		v29 = v36
  58562 		goto _30
  58563 	_30:
  58564 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58565 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  58566 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58567 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58568 		v4 = dst + uintptr(libc.Int32FromInt32(3))
  58569 		v7 = v1 * int32(19077) >> int32(8)
  58570 		goto _47
  58571 	_47:
  58572 		v9 = v2 * int32(33050) >> int32(8)
  58573 		goto _49
  58574 	_49:
  58575 		v11 = v7 + v9 - int32(17685)
  58576 		if v11 & ^int32(YUV_MASK2) == 0 {
  58577 			v14 = v11 >> int32(YUV_FIX2)
  58578 		} else {
  58579 			if v11 < 0 {
  58580 				v15 = 0
  58581 			} else {
  58582 				v15 = int32(255)
  58583 			}
  58584 			v14 = v15
  58585 		}
  58586 		v12 = v14
  58587 		goto _52
  58588 	_52:
  58589 		v51 = v12
  58590 		goto _45
  58591 	_45:
  58592 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58593 		v18 = v1 * int32(19077) >> int32(8)
  58594 		goto _58
  58595 	_58:
  58596 		v20 = v2 * int32(6419) >> int32(8)
  58597 		goto _60
  58598 	_60:
  58599 		v22 = v3 * int32(13320) >> int32(8)
  58600 		goto _62
  58601 	_62:
  58602 		v24 = v18 - v20 - v22 + int32(8708)
  58603 		if v24 & ^int32(YUV_MASK2) == 0 {
  58604 			v27 = v24 >> int32(YUV_FIX2)
  58605 		} else {
  58606 			if v24 < 0 {
  58607 				v28 = 0
  58608 			} else {
  58609 				v28 = int32(255)
  58610 			}
  58611 			v27 = v28
  58612 		}
  58613 		v25 = v27
  58614 		goto _65
  58615 	_65:
  58616 		v16 = v25
  58617 		goto _56
  58618 	_56:
  58619 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58620 		v31 = v1 * int32(19077) >> int32(8)
  58621 		goto _71
  58622 	_71:
  58623 		v33 = v3 * int32(26149) >> int32(8)
  58624 		goto _73
  58625 	_73:
  58626 		v35 = v31 + v33 - int32(14234)
  58627 		if v35 & ^int32(YUV_MASK2) == 0 {
  58628 			v38 = v35 >> int32(YUV_FIX2)
  58629 		} else {
  58630 			if v35 < 0 {
  58631 				v39 = 0
  58632 			} else {
  58633 				v39 = int32(255)
  58634 			}
  58635 			v38 = v39
  58636 		}
  58637 		v36 = v38
  58638 		goto _76
  58639 	_76:
  58640 		v29 = v36
  58641 		goto _69
  58642 	_69:
  58643 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58644 		y4 = y4 + uintptr(2)
  58645 		u3 = u3 + 1
  58646 		v5 = v5 + 1
  58647 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(3))
  58648 	}
  58649 	if len1&int32(1) != 0 {
  58650 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  58651 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  58652 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  58653 		v4 = dst
  58654 		v7 = v1 * int32(19077) >> int32(8)
  58655 		goto _86
  58656 	_86:
  58657 		v9 = v2 * int32(33050) >> int32(8)
  58658 		goto _88
  58659 	_88:
  58660 		v11 = v7 + v9 - int32(17685)
  58661 		if v11 & ^int32(YUV_MASK2) == 0 {
  58662 			v14 = v11 >> int32(YUV_FIX2)
  58663 		} else {
  58664 			if v11 < 0 {
  58665 				v15 = 0
  58666 			} else {
  58667 				v15 = int32(255)
  58668 			}
  58669 			v14 = v15
  58670 		}
  58671 		v12 = v14
  58672 		goto _91
  58673 	_91:
  58674 		v51 = v12
  58675 		goto _84
  58676 	_84:
  58677 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(v51)
  58678 		v18 = v1 * int32(19077) >> int32(8)
  58679 		goto _97
  58680 	_97:
  58681 		v20 = v2 * int32(6419) >> int32(8)
  58682 		goto _99
  58683 	_99:
  58684 		v22 = v3 * int32(13320) >> int32(8)
  58685 		goto _101
  58686 	_101:
  58687 		v24 = v18 - v20 - v22 + int32(8708)
  58688 		if v24 & ^int32(YUV_MASK2) == 0 {
  58689 			v27 = v24 >> int32(YUV_FIX2)
  58690 		} else {
  58691 			if v24 < 0 {
  58692 				v28 = 0
  58693 			} else {
  58694 				v28 = int32(255)
  58695 			}
  58696 			v27 = v28
  58697 		}
  58698 		v25 = v27
  58699 		goto _104
  58700 	_104:
  58701 		v16 = v25
  58702 		goto _95
  58703 	_95:
  58704 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(v16)
  58705 		v31 = v1 * int32(19077) >> int32(8)
  58706 		goto _110
  58707 	_110:
  58708 		v33 = v3 * int32(26149) >> int32(8)
  58709 		goto _112
  58710 	_112:
  58711 		v35 = v31 + v33 - int32(14234)
  58712 		if v35 & ^int32(YUV_MASK2) == 0 {
  58713 			v38 = v35 >> int32(YUV_FIX2)
  58714 		} else {
  58715 			if v35 < 0 {
  58716 				v39 = 0
  58717 			} else {
  58718 				v39 = int32(255)
  58719 			}
  58720 			v38 = v39
  58721 		}
  58722 		v36 = v38
  58723 		goto _115
  58724 	_115:
  58725 		v29 = v36
  58726 		goto _108
  58727 	_108:
  58728 		**(**uint8_t)(__ccgo_up(v4 + 2)) = libc.Uint8FromInt32(v29)
  58729 	}
  58730 }
  58731 
  58732 func YuvToRgbaRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58733 	var end, v1, v5 uintptr
  58734 	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
  58735 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58736 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  58737 	for dst != end {
  58738 		v1 = dst
  58739 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58740 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58741 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58742 		v5 = v1
  58743 		v8 = v2 * int32(19077) >> int32(8)
  58744 		goto _9
  58745 	_9:
  58746 		v10 = v4 * int32(26149) >> int32(8)
  58747 		goto _11
  58748 	_11:
  58749 		v12 = v8 + v10 - int32(14234)
  58750 		if v12 & ^int32(YUV_MASK2) == 0 {
  58751 			v15 = v12 >> int32(YUV_FIX2)
  58752 		} else {
  58753 			if v12 < 0 {
  58754 				v16 = 0
  58755 			} else {
  58756 				v16 = int32(255)
  58757 			}
  58758 			v15 = v16
  58759 		}
  58760 		v13 = v15
  58761 		goto _14
  58762 	_14:
  58763 		v61 = v13
  58764 		goto _7
  58765 	_7:
  58766 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58767 		v19 = v2 * int32(19077) >> int32(8)
  58768 		goto _20
  58769 	_20:
  58770 		v21 = v3 * int32(6419) >> int32(8)
  58771 		goto _22
  58772 	_22:
  58773 		v23 = v4 * int32(13320) >> int32(8)
  58774 		goto _24
  58775 	_24:
  58776 		v25 = v19 - v21 - v23 + int32(8708)
  58777 		if v25 & ^int32(YUV_MASK2) == 0 {
  58778 			v28 = v25 >> int32(YUV_FIX2)
  58779 		} else {
  58780 			if v25 < 0 {
  58781 				v29 = 0
  58782 			} else {
  58783 				v29 = int32(255)
  58784 			}
  58785 			v28 = v29
  58786 		}
  58787 		v26 = v28
  58788 		goto _27
  58789 	_27:
  58790 		v17 = v26
  58791 		goto _18
  58792 	_18:
  58793 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58794 		v32 = v2 * int32(19077) >> int32(8)
  58795 		goto _33
  58796 	_33:
  58797 		v34 = v3 * int32(33050) >> int32(8)
  58798 		goto _35
  58799 	_35:
  58800 		v36 = v32 + v34 - int32(17685)
  58801 		if v36 & ^int32(YUV_MASK2) == 0 {
  58802 			v39 = v36 >> int32(YUV_FIX2)
  58803 		} else {
  58804 			if v36 < 0 {
  58805 				v40 = 0
  58806 			} else {
  58807 				v40 = int32(255)
  58808 			}
  58809 			v39 = v40
  58810 		}
  58811 		v37 = v39
  58812 		goto _38
  58813 	_38:
  58814 		v30 = v37
  58815 		goto _31
  58816 	_31:
  58817 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58818 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58819 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  58820 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + 1)))
  58821 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58822 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58823 		v5 = v1
  58824 		v8 = v2 * int32(19077) >> int32(8)
  58825 		goto _49
  58826 	_49:
  58827 		v10 = v4 * int32(26149) >> int32(8)
  58828 		goto _51
  58829 	_51:
  58830 		v12 = v8 + v10 - int32(14234)
  58831 		if v12 & ^int32(YUV_MASK2) == 0 {
  58832 			v15 = v12 >> int32(YUV_FIX2)
  58833 		} else {
  58834 			if v12 < 0 {
  58835 				v16 = 0
  58836 			} else {
  58837 				v16 = int32(255)
  58838 			}
  58839 			v15 = v16
  58840 		}
  58841 		v13 = v15
  58842 		goto _54
  58843 	_54:
  58844 		v61 = v13
  58845 		goto _47
  58846 	_47:
  58847 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58848 		v19 = v2 * int32(19077) >> int32(8)
  58849 		goto _60
  58850 	_60:
  58851 		v21 = v3 * int32(6419) >> int32(8)
  58852 		goto _62
  58853 	_62:
  58854 		v23 = v4 * int32(13320) >> int32(8)
  58855 		goto _64
  58856 	_64:
  58857 		v25 = v19 - v21 - v23 + int32(8708)
  58858 		if v25 & ^int32(YUV_MASK2) == 0 {
  58859 			v28 = v25 >> int32(YUV_FIX2)
  58860 		} else {
  58861 			if v25 < 0 {
  58862 				v29 = 0
  58863 			} else {
  58864 				v29 = int32(255)
  58865 			}
  58866 			v28 = v29
  58867 		}
  58868 		v26 = v28
  58869 		goto _67
  58870 	_67:
  58871 		v17 = v26
  58872 		goto _58
  58873 	_58:
  58874 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58875 		v32 = v2 * int32(19077) >> int32(8)
  58876 		goto _73
  58877 	_73:
  58878 		v34 = v3 * int32(33050) >> int32(8)
  58879 		goto _75
  58880 	_75:
  58881 		v36 = v32 + v34 - int32(17685)
  58882 		if v36 & ^int32(YUV_MASK2) == 0 {
  58883 			v39 = v36 >> int32(YUV_FIX2)
  58884 		} else {
  58885 			if v36 < 0 {
  58886 				v40 = 0
  58887 			} else {
  58888 				v40 = int32(255)
  58889 			}
  58890 			v39 = v40
  58891 		}
  58892 		v37 = v39
  58893 		goto _78
  58894 	_78:
  58895 		v30 = v37
  58896 		goto _71
  58897 	_71:
  58898 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58899 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58900 		y5 = y5 + uintptr(2)
  58901 		u4 = u4 + 1
  58902 		v6 = v6 + 1
  58903 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  58904 	}
  58905 	if len1&int32(1) != 0 {
  58906 		v1 = dst
  58907 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58908 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58909 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  58910 		v5 = v1
  58911 		v8 = v2 * int32(19077) >> int32(8)
  58912 		goto _89
  58913 	_89:
  58914 		v10 = v4 * int32(26149) >> int32(8)
  58915 		goto _91
  58916 	_91:
  58917 		v12 = v8 + v10 - int32(14234)
  58918 		if v12 & ^int32(YUV_MASK2) == 0 {
  58919 			v15 = v12 >> int32(YUV_FIX2)
  58920 		} else {
  58921 			if v12 < 0 {
  58922 				v16 = 0
  58923 			} else {
  58924 				v16 = int32(255)
  58925 			}
  58926 			v15 = v16
  58927 		}
  58928 		v13 = v15
  58929 		goto _94
  58930 	_94:
  58931 		v61 = v13
  58932 		goto _87
  58933 	_87:
  58934 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  58935 		v19 = v2 * int32(19077) >> int32(8)
  58936 		goto _100
  58937 	_100:
  58938 		v21 = v3 * int32(6419) >> int32(8)
  58939 		goto _102
  58940 	_102:
  58941 		v23 = v4 * int32(13320) >> int32(8)
  58942 		goto _104
  58943 	_104:
  58944 		v25 = v19 - v21 - v23 + int32(8708)
  58945 		if v25 & ^int32(YUV_MASK2) == 0 {
  58946 			v28 = v25 >> int32(YUV_FIX2)
  58947 		} else {
  58948 			if v25 < 0 {
  58949 				v29 = 0
  58950 			} else {
  58951 				v29 = int32(255)
  58952 			}
  58953 			v28 = v29
  58954 		}
  58955 		v26 = v28
  58956 		goto _107
  58957 	_107:
  58958 		v17 = v26
  58959 		goto _98
  58960 	_98:
  58961 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  58962 		v32 = v2 * int32(19077) >> int32(8)
  58963 		goto _113
  58964 	_113:
  58965 		v34 = v3 * int32(33050) >> int32(8)
  58966 		goto _115
  58967 	_115:
  58968 		v36 = v32 + v34 - int32(17685)
  58969 		if v36 & ^int32(YUV_MASK2) == 0 {
  58970 			v39 = v36 >> int32(YUV_FIX2)
  58971 		} else {
  58972 			if v36 < 0 {
  58973 				v40 = 0
  58974 			} else {
  58975 				v40 = int32(255)
  58976 			}
  58977 			v39 = v40
  58978 		}
  58979 		v37 = v39
  58980 		goto _118
  58981 	_118:
  58982 		v30 = v37
  58983 		goto _111
  58984 	_111:
  58985 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  58986 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  58987 	}
  58988 }
  58989 
  58990 func YuvToBgraRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  58991 	var end, v1, v5 uintptr
  58992 	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
  58993 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  58994 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  58995 	for dst != end {
  58996 		v1 = dst
  58997 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  58998 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  58999 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59000 		v5 = v1
  59001 		v8 = v2 * int32(19077) >> int32(8)
  59002 		goto _9
  59003 	_9:
  59004 		v10 = v3 * int32(33050) >> int32(8)
  59005 		goto _11
  59006 	_11:
  59007 		v12 = v8 + v10 - int32(17685)
  59008 		if v12 & ^int32(YUV_MASK2) == 0 {
  59009 			v15 = v12 >> int32(YUV_FIX2)
  59010 		} else {
  59011 			if v12 < 0 {
  59012 				v16 = 0
  59013 			} else {
  59014 				v16 = int32(255)
  59015 			}
  59016 			v15 = v16
  59017 		}
  59018 		v13 = v15
  59019 		goto _14
  59020 	_14:
  59021 		v61 = v13
  59022 		goto _7
  59023 	_7:
  59024 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59025 		v19 = v2 * int32(19077) >> int32(8)
  59026 		goto _20
  59027 	_20:
  59028 		v21 = v3 * int32(6419) >> int32(8)
  59029 		goto _22
  59030 	_22:
  59031 		v23 = v4 * int32(13320) >> int32(8)
  59032 		goto _24
  59033 	_24:
  59034 		v25 = v19 - v21 - v23 + int32(8708)
  59035 		if v25 & ^int32(YUV_MASK2) == 0 {
  59036 			v28 = v25 >> int32(YUV_FIX2)
  59037 		} else {
  59038 			if v25 < 0 {
  59039 				v29 = 0
  59040 			} else {
  59041 				v29 = int32(255)
  59042 			}
  59043 			v28 = v29
  59044 		}
  59045 		v26 = v28
  59046 		goto _27
  59047 	_27:
  59048 		v17 = v26
  59049 		goto _18
  59050 	_18:
  59051 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59052 		v32 = v2 * int32(19077) >> int32(8)
  59053 		goto _33
  59054 	_33:
  59055 		v34 = v4 * int32(26149) >> int32(8)
  59056 		goto _35
  59057 	_35:
  59058 		v36 = v32 + v34 - int32(14234)
  59059 		if v36 & ^int32(YUV_MASK2) == 0 {
  59060 			v39 = v36 >> int32(YUV_FIX2)
  59061 		} else {
  59062 			if v36 < 0 {
  59063 				v40 = 0
  59064 			} else {
  59065 				v40 = int32(255)
  59066 			}
  59067 			v39 = v40
  59068 		}
  59069 		v37 = v39
  59070 		goto _38
  59071 	_38:
  59072 		v30 = v37
  59073 		goto _31
  59074 	_31:
  59075 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59076 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59077 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59078 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59079 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59080 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59081 		v5 = v1
  59082 		v8 = v2 * int32(19077) >> int32(8)
  59083 		goto _49
  59084 	_49:
  59085 		v10 = v3 * int32(33050) >> int32(8)
  59086 		goto _51
  59087 	_51:
  59088 		v12 = v8 + v10 - int32(17685)
  59089 		if v12 & ^int32(YUV_MASK2) == 0 {
  59090 			v15 = v12 >> int32(YUV_FIX2)
  59091 		} else {
  59092 			if v12 < 0 {
  59093 				v16 = 0
  59094 			} else {
  59095 				v16 = int32(255)
  59096 			}
  59097 			v15 = v16
  59098 		}
  59099 		v13 = v15
  59100 		goto _54
  59101 	_54:
  59102 		v61 = v13
  59103 		goto _47
  59104 	_47:
  59105 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59106 		v19 = v2 * int32(19077) >> int32(8)
  59107 		goto _60
  59108 	_60:
  59109 		v21 = v3 * int32(6419) >> int32(8)
  59110 		goto _62
  59111 	_62:
  59112 		v23 = v4 * int32(13320) >> int32(8)
  59113 		goto _64
  59114 	_64:
  59115 		v25 = v19 - v21 - v23 + int32(8708)
  59116 		if v25 & ^int32(YUV_MASK2) == 0 {
  59117 			v28 = v25 >> int32(YUV_FIX2)
  59118 		} else {
  59119 			if v25 < 0 {
  59120 				v29 = 0
  59121 			} else {
  59122 				v29 = int32(255)
  59123 			}
  59124 			v28 = v29
  59125 		}
  59126 		v26 = v28
  59127 		goto _67
  59128 	_67:
  59129 		v17 = v26
  59130 		goto _58
  59131 	_58:
  59132 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59133 		v32 = v2 * int32(19077) >> int32(8)
  59134 		goto _73
  59135 	_73:
  59136 		v34 = v4 * int32(26149) >> int32(8)
  59137 		goto _75
  59138 	_75:
  59139 		v36 = v32 + v34 - int32(14234)
  59140 		if v36 & ^int32(YUV_MASK2) == 0 {
  59141 			v39 = v36 >> int32(YUV_FIX2)
  59142 		} else {
  59143 			if v36 < 0 {
  59144 				v40 = 0
  59145 			} else {
  59146 				v40 = int32(255)
  59147 			}
  59148 			v39 = v40
  59149 		}
  59150 		v37 = v39
  59151 		goto _78
  59152 	_78:
  59153 		v30 = v37
  59154 		goto _71
  59155 	_71:
  59156 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59157 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59158 		y5 = y5 + uintptr(2)
  59159 		u4 = u4 + 1
  59160 		v6 = v6 + 1
  59161 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59162 	}
  59163 	if len1&int32(1) != 0 {
  59164 		v1 = dst
  59165 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  59166 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59167 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59168 		v5 = v1
  59169 		v8 = v2 * int32(19077) >> int32(8)
  59170 		goto _89
  59171 	_89:
  59172 		v10 = v3 * int32(33050) >> int32(8)
  59173 		goto _91
  59174 	_91:
  59175 		v12 = v8 + v10 - int32(17685)
  59176 		if v12 & ^int32(YUV_MASK2) == 0 {
  59177 			v15 = v12 >> int32(YUV_FIX2)
  59178 		} else {
  59179 			if v12 < 0 {
  59180 				v16 = 0
  59181 			} else {
  59182 				v16 = int32(255)
  59183 			}
  59184 			v15 = v16
  59185 		}
  59186 		v13 = v15
  59187 		goto _94
  59188 	_94:
  59189 		v61 = v13
  59190 		goto _87
  59191 	_87:
  59192 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59193 		v19 = v2 * int32(19077) >> int32(8)
  59194 		goto _100
  59195 	_100:
  59196 		v21 = v3 * int32(6419) >> int32(8)
  59197 		goto _102
  59198 	_102:
  59199 		v23 = v4 * int32(13320) >> int32(8)
  59200 		goto _104
  59201 	_104:
  59202 		v25 = v19 - v21 - v23 + int32(8708)
  59203 		if v25 & ^int32(YUV_MASK2) == 0 {
  59204 			v28 = v25 >> int32(YUV_FIX2)
  59205 		} else {
  59206 			if v25 < 0 {
  59207 				v29 = 0
  59208 			} else {
  59209 				v29 = int32(255)
  59210 			}
  59211 			v28 = v29
  59212 		}
  59213 		v26 = v28
  59214 		goto _107
  59215 	_107:
  59216 		v17 = v26
  59217 		goto _98
  59218 	_98:
  59219 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59220 		v32 = v2 * int32(19077) >> int32(8)
  59221 		goto _113
  59222 	_113:
  59223 		v34 = v4 * int32(26149) >> int32(8)
  59224 		goto _115
  59225 	_115:
  59226 		v36 = v32 + v34 - int32(14234)
  59227 		if v36 & ^int32(YUV_MASK2) == 0 {
  59228 			v39 = v36 >> int32(YUV_FIX2)
  59229 		} else {
  59230 			if v36 < 0 {
  59231 				v40 = 0
  59232 			} else {
  59233 				v40 = int32(255)
  59234 			}
  59235 			v39 = v40
  59236 		}
  59237 		v37 = v39
  59238 		goto _118
  59239 	_118:
  59240 		v30 = v37
  59241 		goto _111
  59242 	_111:
  59243 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59244 		**(**uint8_t)(__ccgo_up(v1 + 3)) = uint8(0xff)
  59245 	}
  59246 }
  59247 
  59248 func YuvToArgbRow(tls *libc.TLS, y5 uintptr, u4 uintptr, v6 uintptr, dst uintptr, len1 int32) {
  59249 	var end, v1, v5 uintptr
  59250 	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
  59251 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59252 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(4))
  59253 	for dst != end {
  59254 		v1 = dst
  59255 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59256 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  59257 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59258 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59259 		v5 = v1 + uintptr(1)
  59260 		v8 = v2 * int32(19077) >> int32(8)
  59261 		goto _9
  59262 	_9:
  59263 		v10 = v4 * int32(26149) >> int32(8)
  59264 		goto _11
  59265 	_11:
  59266 		v12 = v8 + v10 - int32(14234)
  59267 		if v12 & ^int32(YUV_MASK2) == 0 {
  59268 			v15 = v12 >> int32(YUV_FIX2)
  59269 		} else {
  59270 			if v12 < 0 {
  59271 				v16 = 0
  59272 			} else {
  59273 				v16 = int32(255)
  59274 			}
  59275 			v15 = v16
  59276 		}
  59277 		v13 = v15
  59278 		goto _14
  59279 	_14:
  59280 		v61 = v13
  59281 		goto _7
  59282 	_7:
  59283 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59284 		v19 = v2 * int32(19077) >> int32(8)
  59285 		goto _20
  59286 	_20:
  59287 		v21 = v3 * int32(6419) >> int32(8)
  59288 		goto _22
  59289 	_22:
  59290 		v23 = v4 * int32(13320) >> int32(8)
  59291 		goto _24
  59292 	_24:
  59293 		v25 = v19 - v21 - v23 + int32(8708)
  59294 		if v25 & ^int32(YUV_MASK2) == 0 {
  59295 			v28 = v25 >> int32(YUV_FIX2)
  59296 		} else {
  59297 			if v25 < 0 {
  59298 				v29 = 0
  59299 			} else {
  59300 				v29 = int32(255)
  59301 			}
  59302 			v28 = v29
  59303 		}
  59304 		v26 = v28
  59305 		goto _27
  59306 	_27:
  59307 		v17 = v26
  59308 		goto _18
  59309 	_18:
  59310 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59311 		v32 = v2 * int32(19077) >> int32(8)
  59312 		goto _33
  59313 	_33:
  59314 		v34 = v3 * int32(33050) >> int32(8)
  59315 		goto _35
  59316 	_35:
  59317 		v36 = v32 + v34 - int32(17685)
  59318 		if v36 & ^int32(YUV_MASK2) == 0 {
  59319 			v39 = v36 >> int32(YUV_FIX2)
  59320 		} else {
  59321 			if v36 < 0 {
  59322 				v40 = 0
  59323 			} else {
  59324 				v40 = int32(255)
  59325 			}
  59326 			v39 = v40
  59327 		}
  59328 		v37 = v39
  59329 		goto _38
  59330 	_38:
  59331 		v30 = v37
  59332 		goto _31
  59333 	_31:
  59334 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59335 		v1 = dst + uintptr(libc.Int32FromInt32(4))
  59336 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59337 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5 + 1)))
  59338 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59339 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59340 		v5 = v1 + uintptr(1)
  59341 		v8 = v2 * int32(19077) >> int32(8)
  59342 		goto _49
  59343 	_49:
  59344 		v10 = v4 * int32(26149) >> int32(8)
  59345 		goto _51
  59346 	_51:
  59347 		v12 = v8 + v10 - int32(14234)
  59348 		if v12 & ^int32(YUV_MASK2) == 0 {
  59349 			v15 = v12 >> int32(YUV_FIX2)
  59350 		} else {
  59351 			if v12 < 0 {
  59352 				v16 = 0
  59353 			} else {
  59354 				v16 = int32(255)
  59355 			}
  59356 			v15 = v16
  59357 		}
  59358 		v13 = v15
  59359 		goto _54
  59360 	_54:
  59361 		v61 = v13
  59362 		goto _47
  59363 	_47:
  59364 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59365 		v19 = v2 * int32(19077) >> int32(8)
  59366 		goto _60
  59367 	_60:
  59368 		v21 = v3 * int32(6419) >> int32(8)
  59369 		goto _62
  59370 	_62:
  59371 		v23 = v4 * int32(13320) >> int32(8)
  59372 		goto _64
  59373 	_64:
  59374 		v25 = v19 - v21 - v23 + int32(8708)
  59375 		if v25 & ^int32(YUV_MASK2) == 0 {
  59376 			v28 = v25 >> int32(YUV_FIX2)
  59377 		} else {
  59378 			if v25 < 0 {
  59379 				v29 = 0
  59380 			} else {
  59381 				v29 = int32(255)
  59382 			}
  59383 			v28 = v29
  59384 		}
  59385 		v26 = v28
  59386 		goto _67
  59387 	_67:
  59388 		v17 = v26
  59389 		goto _58
  59390 	_58:
  59391 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59392 		v32 = v2 * int32(19077) >> int32(8)
  59393 		goto _73
  59394 	_73:
  59395 		v34 = v3 * int32(33050) >> int32(8)
  59396 		goto _75
  59397 	_75:
  59398 		v36 = v32 + v34 - int32(17685)
  59399 		if v36 & ^int32(YUV_MASK2) == 0 {
  59400 			v39 = v36 >> int32(YUV_FIX2)
  59401 		} else {
  59402 			if v36 < 0 {
  59403 				v40 = 0
  59404 			} else {
  59405 				v40 = int32(255)
  59406 			}
  59407 			v39 = v40
  59408 		}
  59409 		v37 = v39
  59410 		goto _78
  59411 	_78:
  59412 		v30 = v37
  59413 		goto _71
  59414 	_71:
  59415 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59416 		y5 = y5 + uintptr(2)
  59417 		u4 = u4 + 1
  59418 		v6 = v6 + 1
  59419 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(4))
  59420 	}
  59421 	if len1&int32(1) != 0 {
  59422 		v1 = dst
  59423 		**(**uint8_t)(__ccgo_up(v1)) = uint8(0xff)
  59424 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y5)))
  59425 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u4)))
  59426 		v4 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v6)))
  59427 		v5 = v1 + uintptr(1)
  59428 		v8 = v2 * int32(19077) >> int32(8)
  59429 		goto _89
  59430 	_89:
  59431 		v10 = v4 * int32(26149) >> int32(8)
  59432 		goto _91
  59433 	_91:
  59434 		v12 = v8 + v10 - int32(14234)
  59435 		if v12 & ^int32(YUV_MASK2) == 0 {
  59436 			v15 = v12 >> int32(YUV_FIX2)
  59437 		} else {
  59438 			if v12 < 0 {
  59439 				v16 = 0
  59440 			} else {
  59441 				v16 = int32(255)
  59442 			}
  59443 			v15 = v16
  59444 		}
  59445 		v13 = v15
  59446 		goto _94
  59447 	_94:
  59448 		v61 = v13
  59449 		goto _87
  59450 	_87:
  59451 		**(**uint8_t)(__ccgo_up(v5)) = libc.Uint8FromInt32(v61)
  59452 		v19 = v2 * int32(19077) >> int32(8)
  59453 		goto _100
  59454 	_100:
  59455 		v21 = v3 * int32(6419) >> int32(8)
  59456 		goto _102
  59457 	_102:
  59458 		v23 = v4 * int32(13320) >> int32(8)
  59459 		goto _104
  59460 	_104:
  59461 		v25 = v19 - v21 - v23 + int32(8708)
  59462 		if v25 & ^int32(YUV_MASK2) == 0 {
  59463 			v28 = v25 >> int32(YUV_FIX2)
  59464 		} else {
  59465 			if v25 < 0 {
  59466 				v29 = 0
  59467 			} else {
  59468 				v29 = int32(255)
  59469 			}
  59470 			v28 = v29
  59471 		}
  59472 		v26 = v28
  59473 		goto _107
  59474 	_107:
  59475 		v17 = v26
  59476 		goto _98
  59477 	_98:
  59478 		**(**uint8_t)(__ccgo_up(v5 + 1)) = libc.Uint8FromInt32(v17)
  59479 		v32 = v2 * int32(19077) >> int32(8)
  59480 		goto _113
  59481 	_113:
  59482 		v34 = v3 * int32(33050) >> int32(8)
  59483 		goto _115
  59484 	_115:
  59485 		v36 = v32 + v34 - int32(17685)
  59486 		if v36 & ^int32(YUV_MASK2) == 0 {
  59487 			v39 = v36 >> int32(YUV_FIX2)
  59488 		} else {
  59489 			if v36 < 0 {
  59490 				v40 = 0
  59491 			} else {
  59492 				v40 = int32(255)
  59493 			}
  59494 			v39 = v40
  59495 		}
  59496 		v37 = v39
  59497 		goto _118
  59498 	_118:
  59499 		v30 = v37
  59500 		goto _111
  59501 	_111:
  59502 		**(**uint8_t)(__ccgo_up(v5 + 2)) = libc.Uint8FromInt32(v30)
  59503 	}
  59504 }
  59505 
  59506 func YuvToRgba4444Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59507 	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
  59508 	var end, v4 uintptr
  59509 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59510 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59511 	for dst != end {
  59512 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59513 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59514 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59515 		v4 = dst
  59516 		v7 = v1 * int32(19077) >> int32(8)
  59517 		goto _8
  59518 	_8:
  59519 		v9 = v3 * int32(26149) >> int32(8)
  59520 		goto _10
  59521 	_10:
  59522 		v11 = v7 + v9 - int32(14234)
  59523 		if v11 & ^int32(YUV_MASK2) == 0 {
  59524 			v14 = v11 >> int32(YUV_FIX2)
  59525 		} else {
  59526 			if v11 < 0 {
  59527 				v15 = 0
  59528 			} else {
  59529 				v15 = int32(255)
  59530 			}
  59531 			v14 = v15
  59532 		}
  59533 		v12 = v14
  59534 		goto _13
  59535 	_13:
  59536 		v51 = v12
  59537 		goto _6
  59538 	_6:
  59539 		r = v51
  59540 		v18 = v1 * int32(19077) >> int32(8)
  59541 		goto _19
  59542 	_19:
  59543 		v20 = v2 * int32(6419) >> int32(8)
  59544 		goto _21
  59545 	_21:
  59546 		v22 = v3 * int32(13320) >> int32(8)
  59547 		goto _23
  59548 	_23:
  59549 		v24 = v18 - v20 - v22 + int32(8708)
  59550 		if v24 & ^int32(YUV_MASK2) == 0 {
  59551 			v27 = v24 >> int32(YUV_FIX2)
  59552 		} else {
  59553 			if v24 < 0 {
  59554 				v28 = 0
  59555 			} else {
  59556 				v28 = int32(255)
  59557 			}
  59558 			v27 = v28
  59559 		}
  59560 		v25 = v27
  59561 		goto _26
  59562 	_26:
  59563 		v16 = v25
  59564 		goto _17
  59565 	_17:
  59566 		g = v16
  59567 		v31 = v1 * int32(19077) >> int32(8)
  59568 		goto _32
  59569 	_32:
  59570 		v33 = v2 * int32(33050) >> int32(8)
  59571 		goto _34
  59572 	_34:
  59573 		v35 = v31 + v33 - int32(17685)
  59574 		if v35 & ^int32(YUV_MASK2) == 0 {
  59575 			v38 = v35 >> int32(YUV_FIX2)
  59576 		} else {
  59577 			if v35 < 0 {
  59578 				v39 = 0
  59579 			} else {
  59580 				v39 = int32(255)
  59581 			}
  59582 			v38 = v39
  59583 		}
  59584 		v36 = v38
  59585 		goto _37
  59586 	_37:
  59587 		v29 = v36
  59588 		goto _30
  59589 	_30:
  59590 		b = v29
  59591 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59592 		ba = b&int32(0xf0) | int32(0x0f)
  59593 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59594 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  59595 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  59596 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59597 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59598 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  59599 		v7 = v1 * int32(19077) >> int32(8)
  59600 		goto _47
  59601 	_47:
  59602 		v9 = v3 * int32(26149) >> int32(8)
  59603 		goto _49
  59604 	_49:
  59605 		v11 = v7 + v9 - int32(14234)
  59606 		if v11 & ^int32(YUV_MASK2) == 0 {
  59607 			v14 = v11 >> int32(YUV_FIX2)
  59608 		} else {
  59609 			if v11 < 0 {
  59610 				v15 = 0
  59611 			} else {
  59612 				v15 = int32(255)
  59613 			}
  59614 			v14 = v15
  59615 		}
  59616 		v12 = v14
  59617 		goto _52
  59618 	_52:
  59619 		v51 = v12
  59620 		goto _45
  59621 	_45:
  59622 		r = v51
  59623 		v18 = v1 * int32(19077) >> int32(8)
  59624 		goto _58
  59625 	_58:
  59626 		v20 = v2 * int32(6419) >> int32(8)
  59627 		goto _60
  59628 	_60:
  59629 		v22 = v3 * int32(13320) >> int32(8)
  59630 		goto _62
  59631 	_62:
  59632 		v24 = v18 - v20 - v22 + int32(8708)
  59633 		if v24 & ^int32(YUV_MASK2) == 0 {
  59634 			v27 = v24 >> int32(YUV_FIX2)
  59635 		} else {
  59636 			if v24 < 0 {
  59637 				v28 = 0
  59638 			} else {
  59639 				v28 = int32(255)
  59640 			}
  59641 			v27 = v28
  59642 		}
  59643 		v25 = v27
  59644 		goto _65
  59645 	_65:
  59646 		v16 = v25
  59647 		goto _56
  59648 	_56:
  59649 		g = v16
  59650 		v31 = v1 * int32(19077) >> int32(8)
  59651 		goto _71
  59652 	_71:
  59653 		v33 = v2 * int32(33050) >> int32(8)
  59654 		goto _73
  59655 	_73:
  59656 		v35 = v31 + v33 - int32(17685)
  59657 		if v35 & ^int32(YUV_MASK2) == 0 {
  59658 			v38 = v35 >> int32(YUV_FIX2)
  59659 		} else {
  59660 			if v35 < 0 {
  59661 				v39 = 0
  59662 			} else {
  59663 				v39 = int32(255)
  59664 			}
  59665 			v38 = v39
  59666 		}
  59667 		v36 = v38
  59668 		goto _76
  59669 	_76:
  59670 		v29 = v36
  59671 		goto _69
  59672 	_69:
  59673 		b = v29
  59674 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59675 		ba = b&int32(0xf0) | int32(0x0f)
  59676 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59677 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  59678 		y4 = y4 + uintptr(2)
  59679 		u3 = u3 + 1
  59680 		v5 = v5 + 1
  59681 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  59682 	}
  59683 	if len1&int32(1) != 0 {
  59684 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59685 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59686 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59687 		v4 = dst
  59688 		v7 = v1 * int32(19077) >> int32(8)
  59689 		goto _86
  59690 	_86:
  59691 		v9 = v3 * int32(26149) >> int32(8)
  59692 		goto _88
  59693 	_88:
  59694 		v11 = v7 + v9 - int32(14234)
  59695 		if v11 & ^int32(YUV_MASK2) == 0 {
  59696 			v14 = v11 >> int32(YUV_FIX2)
  59697 		} else {
  59698 			if v11 < 0 {
  59699 				v15 = 0
  59700 			} else {
  59701 				v15 = int32(255)
  59702 			}
  59703 			v14 = v15
  59704 		}
  59705 		v12 = v14
  59706 		goto _91
  59707 	_91:
  59708 		v51 = v12
  59709 		goto _84
  59710 	_84:
  59711 		r = v51
  59712 		v18 = v1 * int32(19077) >> int32(8)
  59713 		goto _97
  59714 	_97:
  59715 		v20 = v2 * int32(6419) >> int32(8)
  59716 		goto _99
  59717 	_99:
  59718 		v22 = v3 * int32(13320) >> int32(8)
  59719 		goto _101
  59720 	_101:
  59721 		v24 = v18 - v20 - v22 + int32(8708)
  59722 		if v24 & ^int32(YUV_MASK2) == 0 {
  59723 			v27 = v24 >> int32(YUV_FIX2)
  59724 		} else {
  59725 			if v24 < 0 {
  59726 				v28 = 0
  59727 			} else {
  59728 				v28 = int32(255)
  59729 			}
  59730 			v27 = v28
  59731 		}
  59732 		v25 = v27
  59733 		goto _104
  59734 	_104:
  59735 		v16 = v25
  59736 		goto _95
  59737 	_95:
  59738 		g = v16
  59739 		v31 = v1 * int32(19077) >> int32(8)
  59740 		goto _110
  59741 	_110:
  59742 		v33 = v2 * int32(33050) >> int32(8)
  59743 		goto _112
  59744 	_112:
  59745 		v35 = v31 + v33 - int32(17685)
  59746 		if v35 & ^int32(YUV_MASK2) == 0 {
  59747 			v38 = v35 >> int32(YUV_FIX2)
  59748 		} else {
  59749 			if v35 < 0 {
  59750 				v39 = 0
  59751 			} else {
  59752 				v39 = int32(255)
  59753 			}
  59754 			v38 = v39
  59755 		}
  59756 		v36 = v38
  59757 		goto _115
  59758 	_115:
  59759 		v29 = v36
  59760 		goto _108
  59761 	_108:
  59762 		b = v29
  59763 		rg = r&int32(0xf0) | g>>libc.Int32FromInt32(4)
  59764 		ba = b&int32(0xf0) | int32(0x0f)
  59765 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59766 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(ba)
  59767 	}
  59768 }
  59769 
  59770 func YuvToRgb565Row(tls *libc.TLS, y4 uintptr, u3 uintptr, v5 uintptr, dst uintptr, len1 int32) {
  59771 	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
  59772 	var end, v4 uintptr
  59773 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  59774 	end = dst + uintptr(len1 & ^libc.Int32FromInt32(1) * int32(2))
  59775 	for dst != end {
  59776 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59777 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59778 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59779 		v4 = dst
  59780 		v7 = v1 * int32(19077) >> int32(8)
  59781 		goto _8
  59782 	_8:
  59783 		v9 = v3 * int32(26149) >> int32(8)
  59784 		goto _10
  59785 	_10:
  59786 		v11 = v7 + v9 - int32(14234)
  59787 		if v11 & ^int32(YUV_MASK2) == 0 {
  59788 			v14 = v11 >> int32(YUV_FIX2)
  59789 		} else {
  59790 			if v11 < 0 {
  59791 				v15 = 0
  59792 			} else {
  59793 				v15 = int32(255)
  59794 			}
  59795 			v14 = v15
  59796 		}
  59797 		v12 = v14
  59798 		goto _13
  59799 	_13:
  59800 		v51 = v12
  59801 		goto _6
  59802 	_6:
  59803 		r = v51
  59804 		v18 = v1 * int32(19077) >> int32(8)
  59805 		goto _19
  59806 	_19:
  59807 		v20 = v2 * int32(6419) >> int32(8)
  59808 		goto _21
  59809 	_21:
  59810 		v22 = v3 * int32(13320) >> int32(8)
  59811 		goto _23
  59812 	_23:
  59813 		v24 = v18 - v20 - v22 + int32(8708)
  59814 		if v24 & ^int32(YUV_MASK2) == 0 {
  59815 			v27 = v24 >> int32(YUV_FIX2)
  59816 		} else {
  59817 			if v24 < 0 {
  59818 				v28 = 0
  59819 			} else {
  59820 				v28 = int32(255)
  59821 			}
  59822 			v27 = v28
  59823 		}
  59824 		v25 = v27
  59825 		goto _26
  59826 	_26:
  59827 		v16 = v25
  59828 		goto _17
  59829 	_17:
  59830 		g = v16
  59831 		v31 = v1 * int32(19077) >> int32(8)
  59832 		goto _32
  59833 	_32:
  59834 		v33 = v2 * int32(33050) >> int32(8)
  59835 		goto _34
  59836 	_34:
  59837 		v35 = v31 + v33 - int32(17685)
  59838 		if v35 & ^int32(YUV_MASK2) == 0 {
  59839 			v38 = v35 >> int32(YUV_FIX2)
  59840 		} else {
  59841 			if v35 < 0 {
  59842 				v39 = 0
  59843 			} else {
  59844 				v39 = int32(255)
  59845 			}
  59846 			v38 = v39
  59847 		}
  59848 		v36 = v38
  59849 		goto _37
  59850 	_37:
  59851 		v29 = v36
  59852 		goto _30
  59853 	_30:
  59854 		b = v29
  59855 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  59856 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  59857 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59858 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  59859 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4 + 1)))
  59860 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59861 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59862 		v4 = dst + uintptr(libc.Int32FromInt32(2))
  59863 		v7 = v1 * int32(19077) >> int32(8)
  59864 		goto _47
  59865 	_47:
  59866 		v9 = v3 * int32(26149) >> int32(8)
  59867 		goto _49
  59868 	_49:
  59869 		v11 = v7 + v9 - int32(14234)
  59870 		if v11 & ^int32(YUV_MASK2) == 0 {
  59871 			v14 = v11 >> int32(YUV_FIX2)
  59872 		} else {
  59873 			if v11 < 0 {
  59874 				v15 = 0
  59875 			} else {
  59876 				v15 = int32(255)
  59877 			}
  59878 			v14 = v15
  59879 		}
  59880 		v12 = v14
  59881 		goto _52
  59882 	_52:
  59883 		v51 = v12
  59884 		goto _45
  59885 	_45:
  59886 		r = v51
  59887 		v18 = v1 * int32(19077) >> int32(8)
  59888 		goto _58
  59889 	_58:
  59890 		v20 = v2 * int32(6419) >> int32(8)
  59891 		goto _60
  59892 	_60:
  59893 		v22 = v3 * int32(13320) >> int32(8)
  59894 		goto _62
  59895 	_62:
  59896 		v24 = v18 - v20 - v22 + int32(8708)
  59897 		if v24 & ^int32(YUV_MASK2) == 0 {
  59898 			v27 = v24 >> int32(YUV_FIX2)
  59899 		} else {
  59900 			if v24 < 0 {
  59901 				v28 = 0
  59902 			} else {
  59903 				v28 = int32(255)
  59904 			}
  59905 			v27 = v28
  59906 		}
  59907 		v25 = v27
  59908 		goto _65
  59909 	_65:
  59910 		v16 = v25
  59911 		goto _56
  59912 	_56:
  59913 		g = v16
  59914 		v31 = v1 * int32(19077) >> int32(8)
  59915 		goto _71
  59916 	_71:
  59917 		v33 = v2 * int32(33050) >> int32(8)
  59918 		goto _73
  59919 	_73:
  59920 		v35 = v31 + v33 - int32(17685)
  59921 		if v35 & ^int32(YUV_MASK2) == 0 {
  59922 			v38 = v35 >> int32(YUV_FIX2)
  59923 		} else {
  59924 			if v35 < 0 {
  59925 				v39 = 0
  59926 			} else {
  59927 				v39 = int32(255)
  59928 			}
  59929 			v38 = v39
  59930 		}
  59931 		v36 = v38
  59932 		goto _76
  59933 	_76:
  59934 		v29 = v36
  59935 		goto _69
  59936 	_69:
  59937 		b = v29
  59938 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  59939 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  59940 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  59941 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  59942 		y4 = y4 + uintptr(2)
  59943 		u3 = u3 + 1
  59944 		v5 = v5 + 1
  59945 		dst = dst + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))
  59946 	}
  59947 	if len1&int32(1) != 0 {
  59948 		v1 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(y4)))
  59949 		v2 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u3)))
  59950 		v3 = libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v5)))
  59951 		v4 = dst
  59952 		v7 = v1 * int32(19077) >> int32(8)
  59953 		goto _86
  59954 	_86:
  59955 		v9 = v3 * int32(26149) >> int32(8)
  59956 		goto _88
  59957 	_88:
  59958 		v11 = v7 + v9 - int32(14234)
  59959 		if v11 & ^int32(YUV_MASK2) == 0 {
  59960 			v14 = v11 >> int32(YUV_FIX2)
  59961 		} else {
  59962 			if v11 < 0 {
  59963 				v15 = 0
  59964 			} else {
  59965 				v15 = int32(255)
  59966 			}
  59967 			v14 = v15
  59968 		}
  59969 		v12 = v14
  59970 		goto _91
  59971 	_91:
  59972 		v51 = v12
  59973 		goto _84
  59974 	_84:
  59975 		r = v51
  59976 		v18 = v1 * int32(19077) >> int32(8)
  59977 		goto _97
  59978 	_97:
  59979 		v20 = v2 * int32(6419) >> int32(8)
  59980 		goto _99
  59981 	_99:
  59982 		v22 = v3 * int32(13320) >> int32(8)
  59983 		goto _101
  59984 	_101:
  59985 		v24 = v18 - v20 - v22 + int32(8708)
  59986 		if v24 & ^int32(YUV_MASK2) == 0 {
  59987 			v27 = v24 >> int32(YUV_FIX2)
  59988 		} else {
  59989 			if v24 < 0 {
  59990 				v28 = 0
  59991 			} else {
  59992 				v28 = int32(255)
  59993 			}
  59994 			v27 = v28
  59995 		}
  59996 		v25 = v27
  59997 		goto _104
  59998 	_104:
  59999 		v16 = v25
  60000 		goto _95
  60001 	_95:
  60002 		g = v16
  60003 		v31 = v1 * int32(19077) >> int32(8)
  60004 		goto _110
  60005 	_110:
  60006 		v33 = v2 * int32(33050) >> int32(8)
  60007 		goto _112
  60008 	_112:
  60009 		v35 = v31 + v33 - int32(17685)
  60010 		if v35 & ^int32(YUV_MASK2) == 0 {
  60011 			v38 = v35 >> int32(YUV_FIX2)
  60012 		} else {
  60013 			if v35 < 0 {
  60014 				v39 = 0
  60015 			} else {
  60016 				v39 = int32(255)
  60017 			}
  60018 			v38 = v39
  60019 		}
  60020 		v36 = v38
  60021 		goto _115
  60022 	_115:
  60023 		v29 = v36
  60024 		goto _108
  60025 	_108:
  60026 		b = v29
  60027 		rg = r&int32(0xf8) | g>>libc.Int32FromInt32(5)
  60028 		gb = g<<libc.Int32FromInt32(3)&int32(0xe0) | b>>libc.Int32FromInt32(3)
  60029 		**(**uint8_t)(__ccgo_up(v4)) = libc.Uint8FromInt32(rg)
  60030 		**(**uint8_t)(__ccgo_up(v4 + 1)) = libc.Uint8FromInt32(gb)
  60031 	}
  60032 }
  60033 
  60034 type __ccgo_fp__XWebPSamplerProcessPlane_9 = func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32)
  60035 
  60036 // C documentation
  60037 //
  60038 //	// Main call for processing a plane with a WebPSamplerRowFunc function:
  60039 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) {
  60040 	var j int32
  60041 	_ = j
  60042 	j = 0
  60043 	for {
  60044 		if !(j < height) {
  60045 			break
  60046 		}
  60047 		(*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_func})))(tls, y, u, v, dst, width)
  60048 		y = y + uintptr(y_stride)
  60049 		if j&int32(1) != 0 {
  60050 			u = u + uintptr(uv_stride)
  60051 			v = v + uintptr(uv_stride)
  60052 		}
  60053 		dst = dst + uintptr(dst_stride)
  60054 		goto _1
  60055 	_1:
  60056 		;
  60057 		j = j + 1
  60058 	}
  60059 }
  60060 
  60061 func WebPInitSamplers(tls *libc.TLS) {
  60062 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60063 		goto _1
  60064 	}
  60065 	WebPInitSamplers_body(tls)
  60066 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60067 	goto _2
  60068 _2:
  60069 	;
  60070 	goto _1
  60071 _1: /**/ //
  60072 }
  60073 
  60074 var WebPInitSamplers_body_last_cpuinfo_used = uintptr(0)
  60075 
  60076 func init() {
  60077 	p := unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used)
  60078 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitSamplers_body_last_cpuinfo_used))
  60079 }
  60080 
  60081 func WebPInitSamplers_body(tls *libc.TLS) {
  60082 	WebPSamplers[int32(MODE_RGB)] = __ccgo_fp(YuvToRgbRow)
  60083 	WebPSamplers[int32(MODE_RGBA)] = __ccgo_fp(YuvToRgbaRow)
  60084 	WebPSamplers[int32(MODE_BGR)] = __ccgo_fp(YuvToBgrRow)
  60085 	WebPSamplers[int32(MODE_BGRA)] = __ccgo_fp(YuvToBgraRow)
  60086 	WebPSamplers[int32(MODE_ARGB)] = __ccgo_fp(YuvToArgbRow)
  60087 	WebPSamplers[int32(MODE_RGBA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  60088 	WebPSamplers[int32(MODE_RGB_565)] = __ccgo_fp(YuvToRgb565Row)
  60089 	WebPSamplers[int32(MODE_rgbA)] = __ccgo_fp(YuvToRgbaRow)
  60090 	WebPSamplers[int32(MODE_bgrA)] = __ccgo_fp(YuvToBgraRow)
  60091 	WebPSamplers[int32(MODE_Argb)] = __ccgo_fp(YuvToArgbRow)
  60092 	WebPSamplers[int32(MODE_rgbA_4444)] = __ccgo_fp(YuvToRgba4444Row)
  60093 	// If defined, use CPUInfo() to overwrite some pointers with faster versions.
  60094 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60095 	}
  60096 }
  60097 
  60098 //-----------------------------------------------------------------------------
  60099 // ARGB -> YUV converters
  60100 
  60101 func ConvertARGBToY_C(tls *libc.TLS, argb uintptr, y uintptr, width int32) {
  60102 	var i, luma, v2 int32
  60103 	var p uint32_t
  60104 	_, _, _, _ = i, luma, p, v2
  60105 	i = 0
  60106 	for {
  60107 		if !(i < width) {
  60108 			break
  60109 		}
  60110 		p = **(**uint32_t)(__ccgo_up(argb + uintptr(i)*4))
  60111 		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))
  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 	}
  60121 }
  60122 
  60123 func WebPConvertARGBToUV_C(tls *libc.TLS, argb uintptr, u1 uintptr, v1 uintptr, src_width int32, do_store int32) {
  60124 	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
  60125 	var v0, v01, v11 uint32_t
  60126 	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = 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
  60127 	// No rounding. Last pixel is dealt with separately.
  60128 	uv_width = src_width >> int32(1)
  60129 	i = 0
  60130 	for {
  60131 		if !(i < uv_width) {
  60132 			break
  60133 		}
  60134 		v0 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60135 		v11 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+int32(1))*4))
  60136 		// VP8RGBToU/V expects four accumulated pixels. Hence we need to
  60137 		// scale r/g/b value by a factor 2. We just shift v0/v1 one bit less.
  60138 		r2 = libc.Int32FromUint32(v0>>libc.Int32FromInt32(15)&uint32(0x1fe) + v11>>libc.Int32FromInt32(15)&uint32(0x1fe))
  60139 		g2 = libc.Int32FromUint32(v0>>libc.Int32FromInt32(7)&uint32(0x1fe) + v11>>libc.Int32FromInt32(7)&uint32(0x1fe))
  60140 		b2 = libc.Int32FromUint32(v0<<libc.Int32FromInt32(1)&uint32(0x1fe) + v11<<libc.Int32FromInt32(1)&uint32(0x1fe))
  60141 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60142 		v4 = u
  60143 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60144 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60145 			v7 = v4
  60146 		} else {
  60147 			if v4 < 0 {
  60148 				v8 = 0
  60149 			} else {
  60150 				v8 = int32(255)
  60151 			}
  60152 			v7 = v8
  60153 		}
  60154 		v5 = v7
  60155 		goto _6
  60156 	_6:
  60157 		v2 = v5
  60158 		goto _3
  60159 	_3:
  60160 		tmp_u = v2
  60161 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60162 		v111 = v
  60163 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60164 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60165 			v14 = v111
  60166 		} else {
  60167 			if v111 < 0 {
  60168 				v15 = 0
  60169 			} else {
  60170 				v15 = int32(255)
  60171 			}
  60172 			v14 = v15
  60173 		}
  60174 		v12 = v14
  60175 		goto _13
  60176 	_13:
  60177 		v9 = v12
  60178 		goto _10
  60179 	_10:
  60180 		tmp_v = v9
  60181 		if do_store != 0 {
  60182 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32(tmp_u)
  60183 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32(tmp_v)
  60184 		} else {
  60185 			// Approximated average-of-four. But it's an acceptable diff.
  60186 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u + int32(1)) >> int32(1))
  60187 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v + int32(1)) >> int32(1))
  60188 		}
  60189 		goto _1
  60190 	_1:
  60191 		;
  60192 		i = i + 1
  60193 	}
  60194 	if src_width&int32(1) != 0 { // last pixel
  60195 		v01 = **(**uint32_t)(__ccgo_up(argb + uintptr(int32(2)*i+0)*4))
  60196 		r3 = libc.Int32FromUint32(v01 >> libc.Int32FromInt32(14) & uint32(0x3fc))
  60197 		g3 = libc.Int32FromUint32(v01 >> libc.Int32FromInt32(6) & uint32(0x3fc))
  60198 		b3 = libc.Int32FromUint32(v01 << libc.Int32FromInt32(2) & uint32(0x3fc))
  60199 		u = -int32(9719)*r3 - int32(19081)*g3 + int32(28800)*b3
  60200 		v4 = u
  60201 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60202 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60203 			v7 = v4
  60204 		} else {
  60205 			if v4 < 0 {
  60206 				v8 = 0
  60207 			} else {
  60208 				v8 = int32(255)
  60209 			}
  60210 			v7 = v8
  60211 		}
  60212 		v5 = v7
  60213 		goto _20
  60214 	_20:
  60215 		v2 = v5
  60216 		goto _17
  60217 	_17:
  60218 		tmp_u1 = v2
  60219 		v = +libc.Int32FromInt32(28800)*r3 - int32(24116)*g3 - int32(4684)*b3
  60220 		v111 = v
  60221 		v111 = (v111 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60222 		if v111 & ^libc.Int32FromInt32(0xff) == 0 {
  60223 			v14 = v111
  60224 		} else {
  60225 			if v111 < 0 {
  60226 				v15 = 0
  60227 			} else {
  60228 				v15 = int32(255)
  60229 			}
  60230 			v14 = v15
  60231 		}
  60232 		v12 = v14
  60233 		goto _27
  60234 	_27:
  60235 		v9 = v12
  60236 		goto _24
  60237 	_24:
  60238 		tmp_v1 = v9
  60239 		if do_store != 0 {
  60240 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32(tmp_u1)
  60241 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32(tmp_v1)
  60242 		} else {
  60243 			**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(u1 + uintptr(i)))) + tmp_u1 + int32(1)) >> int32(1))
  60244 			**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32((libc.Int32FromUint8(**(**uint8_t)(__ccgo_up(v1 + uintptr(i)))) + tmp_v1 + int32(1)) >> int32(1))
  60245 		}
  60246 	}
  60247 }
  60248 
  60249 //-----------------------------------------------------------------------------
  60250 
  60251 func ConvertRGB24ToY_C(tls *libc.TLS, rgb uintptr, y uintptr, width int32) {
  60252 	var i, luma, v2 int32
  60253 	_, _, _ = i, luma, v2
  60254 	i = 0
  60255 	for {
  60256 		if !(i < width) {
  60257 			break
  60258 		}
  60259 		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)))
  60260 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60261 		goto _3
  60262 	_3:
  60263 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = libc.Uint8FromInt32(v2)
  60264 		goto _1
  60265 	_1:
  60266 		;
  60267 		i = i + 1
  60268 		rgb = rgb + uintptr(3)
  60269 	}
  60270 }
  60271 
  60272 func ConvertBGR24ToY_C(tls *libc.TLS, bgr uintptr, y uintptr, width int32) {
  60273 	var i, luma, v2 int32
  60274 	_, _, _ = i, luma, v2
  60275 	i = 0
  60276 	for {
  60277 		if !(i < width) {
  60278 			break
  60279 		}
  60280 		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)))
  60281 		v2 = (luma + int32(YUV_HALF) + libc.Int32FromInt32(16)<<int32(YUV_FIX)) >> int32(YUV_FIX)
  60282 		goto _3
  60283 	_3:
  60284 		**(**uint8_t)(__ccgo_up(y + uintptr(i))) = libc.Uint8FromInt32(v2)
  60285 		goto _1
  60286 	_1:
  60287 		;
  60288 		i = i + 1
  60289 		bgr = bgr + uintptr(3)
  60290 	}
  60291 }
  60292 
  60293 func WebPConvertRGBA32ToUV_C(tls *libc.TLS, rgb uintptr, u1 uintptr, v1 uintptr, width int32) {
  60294 	var b2, g2, i, r2, u, v, v2, v4, v5, v7, v8 int32
  60295 	_, _, _, _, _, _, _, _, _, _, _ = b2, g2, i, r2, u, v, v2, v4, v5, v7, v8
  60296 	i = 0
  60297 	for {
  60298 		if !(i < width) {
  60299 			break
  60300 		}
  60301 		r2 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb)))
  60302 		g2 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 1*2)))
  60303 		b2 = libc.Int32FromUint16(**(**uint16_t)(__ccgo_up(rgb + 2*2)))
  60304 		u = -int32(9719)*r2 - int32(19081)*g2 + int32(28800)*b2
  60305 		v4 = u
  60306 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60307 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60308 			v7 = v4
  60309 		} else {
  60310 			if v4 < 0 {
  60311 				v8 = 0
  60312 			} else {
  60313 				v8 = int32(255)
  60314 			}
  60315 			v7 = v8
  60316 		}
  60317 		v5 = v7
  60318 		goto _6
  60319 	_6:
  60320 		v2 = v5
  60321 		goto _3
  60322 	_3:
  60323 		**(**uint8_t)(__ccgo_up(u1 + uintptr(i))) = libc.Uint8FromInt32(v2)
  60324 		v = +libc.Int32FromInt32(28800)*r2 - int32(24116)*g2 - int32(4684)*b2
  60325 		v4 = v
  60326 		v4 = (v4 + int32(YUV_HALF)<<libc.Int32FromInt32(2) + libc.Int32FromInt32(128)<<(int32(YUV_FIX)+libc.Int32FromInt32(2))) >> (int32(YUV_FIX) + libc.Int32FromInt32(2))
  60327 		if v4 & ^libc.Int32FromInt32(0xff) == 0 {
  60328 			v7 = v4
  60329 		} else {
  60330 			if v4 < 0 {
  60331 				v8 = 0
  60332 			} else {
  60333 				v8 = int32(255)
  60334 			}
  60335 			v7 = v8
  60336 		}
  60337 		v5 = v7
  60338 		goto _13
  60339 	_13:
  60340 		v2 = v5
  60341 		goto _10
  60342 	_10:
  60343 		**(**uint8_t)(__ccgo_up(v1 + uintptr(i))) = libc.Uint8FromInt32(v2)
  60344 		goto _1
  60345 	_1:
  60346 		;
  60347 		i = i + int32(1)
  60348 		rgb = rgb + uintptr(4)*2
  60349 	}
  60350 }
  60351 
  60352 func WebPInitConvertARGBToYUV(tls *libc.TLS) {
  60353 	if libc.AtomicLoadPUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))) == VP8GetCPUInfo {
  60354 		goto _1
  60355 	}
  60356 	WebPInitConvertARGBToYUV_body(tls)
  60357 	libc.AtomicStorePUintptr(uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)), VP8GetCPUInfo)
  60358 	goto _2
  60359 _2:
  60360 	;
  60361 	goto _1
  60362 _1: /**/ //
  60363 }
  60364 
  60365 var WebPInitConvertARGBToYUV_body_last_cpuinfo_used = uintptr(0)
  60366 
  60367 func init() {
  60368 	p := unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used)
  60369 	*(*uintptr)(unsafe.Add(p, 0)) = uintptr(unsafe.Pointer(&WebPInitConvertARGBToYUV_body_last_cpuinfo_used))
  60370 }
  60371 
  60372 func WebPInitConvertARGBToYUV_body(tls *libc.TLS) {
  60373 	WebPConvertARGBToY = __ccgo_fp(ConvertARGBToY_C)
  60374 	WebPConvertARGBToUV = __ccgo_fp(WebPConvertARGBToUV_C)
  60375 	WebPConvertRGB24ToY = __ccgo_fp(ConvertRGB24ToY_C)
  60376 	WebPConvertBGR24ToY = __ccgo_fp(ConvertBGR24ToY_C)
  60377 	WebPConvertRGBA32ToUV = __ccgo_fp(WebPConvertRGBA32ToUV_C)
  60378 	if VP8GetCPUInfo != libc.UintptrFromInt32(0) {
  60379 	}
  60380 }
  60381 
  60382 func WebPInitSamplersMIPS32(tls *libc.TLS) {
  60383 }
  60384 
  60385 func WebPInitSamplersMIPSdspR2(tls *libc.TLS) {
  60386 }
  60387 
  60388 func WebPInitConvertARGBToYUVNEON(tls *libc.TLS) {
  60389 }
  60390 
  60391 func WebPInitSamplersSSE2(tls *libc.TLS) {
  60392 }
  60393 
  60394 func WebPInitConvertARGBToYUVSSE2(tls *libc.TLS) {
  60395 }
  60396 
  60397 func WebPInitSamplersSSE41(tls *libc.TLS) {
  60398 }
  60399 
  60400 func WebPInitConvertARGBToYUVSSE41(tls *libc.TLS) {
  60401 }
  60402 
  60403 type __ccgo_fp__XSharpYuvInit_0 = func(*libc.TLS, int32) int32
  60404 
  60405 func SharpYuvInit(tls *libc.TLS, __ccgo_fp_cpu_info_func VP8CPUInfo) {
  60406 	_ = __ccgo_fp_cpu_info_func
  60407 }
  60408 
  60409 func SharpYuvGetConversionMatrix(tls *libc.TLS, matrix_type SharpYuvMatrixType) (r uintptr) {
  60410 	_ = matrix_type
  60411 	return libc.UintptrFromInt32(0)
  60412 }
  60413 
  60414 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) {
  60415 	_ = r_ptr
  60416 	_ = g_ptr
  60417 	_ = b_ptr
  60418 	_ = rgb_step
  60419 	_ = rgb_stride
  60420 	_ = rgb_bit_depth
  60421 	_ = y_ptr
  60422 	_ = y_stride
  60423 	_ = u_ptr
  60424 	_ = u_stride
  60425 	_ = v_ptr
  60426 	_ = v_stride
  60427 	_ = yuv_bit_depth
  60428 	_ = width
  60429 	_ = height
  60430 	_ = yuv_matrix
  60431 	return 0
  60432 }
  60433 
  60434 func __ccgo_fp(f interface{}) uintptr {
  60435 	type iface [2]uintptr
  60436 	return (*iface)(unsafe.Pointer(&f))[1]
  60437 }
  60438 
  60439 func __ccgo_up(n uintptr) unsafe.Pointer {
  60440 	return unsafe.Pointer(&n)
  60441 }
  60442 
  60443 var VP8AccumulateSSE VP8AccumulateSSEFunc
  60444 
  60445 //------------------------------------------------------------------------------
  60446 // Tables for level coding
  60447 
  60448 var VP8Cat3 = [3]uint8_t{
  60449 	0: uint8(173),
  60450 	1: uint8(148),
  60451 	2: uint8(140),
  60452 }
  60453 
  60454 var VP8Cat4 = [4]uint8_t{
  60455 	0: uint8(176),
  60456 	1: uint8(155),
  60457 	2: uint8(140),
  60458 	3: uint8(135),
  60459 }
  60460 
  60461 var VP8Cat5 = [5]uint8_t{
  60462 	0: uint8(180),
  60463 	1: uint8(157),
  60464 	2: uint8(141),
  60465 	3: uint8(134),
  60466 	4: uint8(130),
  60467 }
  60468 
  60469 var VP8Cat6 = [11]uint8_t{
  60470 	0:  uint8(254),
  60471 	1:  uint8(254),
  60472 	2:  uint8(243),
  60473 	3:  uint8(230),
  60474 	4:  uint8(196),
  60475 	5:  uint8(177),
  60476 	6:  uint8(153),
  60477 	7:  uint8(140),
  60478 	8:  uint8(133),
  60479 	9:  uint8(130),
  60480 	10: uint8(129),
  60481 }
  60482 
  60483 //------------------------------------------------------------------------------
  60484 
  60485 // Copyright 2011 Google Inc. All Rights Reserved.
  60486 //
  60487 // Use of this source code is governed by a BSD-style license
  60488 // that can be found in the COPYING file in the root of the source
  60489 // tree. An additional intellectual property rights grant can be found
  60490 // in the file PATENTS. All contributing project authors may
  60491 // be found in the AUTHORS file in the root of the source tree.
  60492 // -----------------------------------------------------------------------------
  60493 //
  60494 // Bit writing and boolean coder
  60495 //
  60496 // Author: Skal (pascal.massimino@gmail.com)
  60497 
  60498 //------------------------------------------------------------------------------
  60499 // Default probabilities
  60500 
  60501 // C documentation
  60502 //
  60503 //	// Paragraph 13.5
  60504 
  60505 var VP8CoeffsProba0 = [4][8][3][11]uint8_t{
  60506 	0: {
  60507 		0: {
  60508 			0: {
  60509 				0:  uint8(128),
  60510 				1:  uint8(128),
  60511 				2:  uint8(128),
  60512 				3:  uint8(128),
  60513 				4:  uint8(128),
  60514 				5:  uint8(128),
  60515 				6:  uint8(128),
  60516 				7:  uint8(128),
  60517 				8:  uint8(128),
  60518 				9:  uint8(128),
  60519 				10: uint8(128),
  60520 			},
  60521 			1: {
  60522 				0:  uint8(128),
  60523 				1:  uint8(128),
  60524 				2:  uint8(128),
  60525 				3:  uint8(128),
  60526 				4:  uint8(128),
  60527 				5:  uint8(128),
  60528 				6:  uint8(128),
  60529 				7:  uint8(128),
  60530 				8:  uint8(128),
  60531 				9:  uint8(128),
  60532 				10: uint8(128),
  60533 			},
  60534 			2: {
  60535 				0:  uint8(128),
  60536 				1:  uint8(128),
  60537 				2:  uint8(128),
  60538 				3:  uint8(128),
  60539 				4:  uint8(128),
  60540 				5:  uint8(128),
  60541 				6:  uint8(128),
  60542 				7:  uint8(128),
  60543 				8:  uint8(128),
  60544 				9:  uint8(128),
  60545 				10: uint8(128),
  60546 			},
  60547 		},
  60548 		1: {
  60549 			0: {
  60550 				0:  uint8(253),
  60551 				1:  uint8(136),
  60552 				2:  uint8(254),
  60553 				3:  uint8(255),
  60554 				4:  uint8(228),
  60555 				5:  uint8(219),
  60556 				6:  uint8(128),
  60557 				7:  uint8(128),
  60558 				8:  uint8(128),
  60559 				9:  uint8(128),
  60560 				10: uint8(128),
  60561 			},
  60562 			1: {
  60563 				0:  uint8(189),
  60564 				1:  uint8(129),
  60565 				2:  uint8(242),
  60566 				3:  uint8(255),
  60567 				4:  uint8(227),
  60568 				5:  uint8(213),
  60569 				6:  uint8(255),
  60570 				7:  uint8(219),
  60571 				8:  uint8(128),
  60572 				9:  uint8(128),
  60573 				10: uint8(128),
  60574 			},
  60575 			2: {
  60576 				0:  uint8(106),
  60577 				1:  uint8(126),
  60578 				2:  uint8(227),
  60579 				3:  uint8(252),
  60580 				4:  uint8(214),
  60581 				5:  uint8(209),
  60582 				6:  uint8(255),
  60583 				7:  uint8(255),
  60584 				8:  uint8(128),
  60585 				9:  uint8(128),
  60586 				10: uint8(128),
  60587 			},
  60588 		},
  60589 		2: {
  60590 			0: {
  60591 				0:  uint8(1),
  60592 				1:  uint8(98),
  60593 				2:  uint8(248),
  60594 				3:  uint8(255),
  60595 				4:  uint8(236),
  60596 				5:  uint8(226),
  60597 				6:  uint8(255),
  60598 				7:  uint8(255),
  60599 				8:  uint8(128),
  60600 				9:  uint8(128),
  60601 				10: uint8(128),
  60602 			},
  60603 			1: {
  60604 				0:  uint8(181),
  60605 				1:  uint8(133),
  60606 				2:  uint8(238),
  60607 				3:  uint8(254),
  60608 				4:  uint8(221),
  60609 				5:  uint8(234),
  60610 				6:  uint8(255),
  60611 				7:  uint8(154),
  60612 				8:  uint8(128),
  60613 				9:  uint8(128),
  60614 				10: uint8(128),
  60615 			},
  60616 			2: {
  60617 				0:  uint8(78),
  60618 				1:  uint8(134),
  60619 				2:  uint8(202),
  60620 				3:  uint8(247),
  60621 				4:  uint8(198),
  60622 				5:  uint8(180),
  60623 				6:  uint8(255),
  60624 				7:  uint8(219),
  60625 				8:  uint8(128),
  60626 				9:  uint8(128),
  60627 				10: uint8(128),
  60628 			},
  60629 		},
  60630 		3: {
  60631 			0: {
  60632 				0:  uint8(1),
  60633 				1:  uint8(185),
  60634 				2:  uint8(249),
  60635 				3:  uint8(255),
  60636 				4:  uint8(243),
  60637 				5:  uint8(255),
  60638 				6:  uint8(128),
  60639 				7:  uint8(128),
  60640 				8:  uint8(128),
  60641 				9:  uint8(128),
  60642 				10: uint8(128),
  60643 			},
  60644 			1: {
  60645 				0:  uint8(184),
  60646 				1:  uint8(150),
  60647 				2:  uint8(247),
  60648 				3:  uint8(255),
  60649 				4:  uint8(236),
  60650 				5:  uint8(224),
  60651 				6:  uint8(128),
  60652 				7:  uint8(128),
  60653 				8:  uint8(128),
  60654 				9:  uint8(128),
  60655 				10: uint8(128),
  60656 			},
  60657 			2: {
  60658 				0:  uint8(77),
  60659 				1:  uint8(110),
  60660 				2:  uint8(216),
  60661 				3:  uint8(255),
  60662 				4:  uint8(236),
  60663 				5:  uint8(230),
  60664 				6:  uint8(128),
  60665 				7:  uint8(128),
  60666 				8:  uint8(128),
  60667 				9:  uint8(128),
  60668 				10: uint8(128),
  60669 			},
  60670 		},
  60671 		4: {
  60672 			0: {
  60673 				0:  uint8(1),
  60674 				1:  uint8(101),
  60675 				2:  uint8(251),
  60676 				3:  uint8(255),
  60677 				4:  uint8(241),
  60678 				5:  uint8(255),
  60679 				6:  uint8(128),
  60680 				7:  uint8(128),
  60681 				8:  uint8(128),
  60682 				9:  uint8(128),
  60683 				10: uint8(128),
  60684 			},
  60685 			1: {
  60686 				0:  uint8(170),
  60687 				1:  uint8(139),
  60688 				2:  uint8(241),
  60689 				3:  uint8(252),
  60690 				4:  uint8(236),
  60691 				5:  uint8(209),
  60692 				6:  uint8(255),
  60693 				7:  uint8(255),
  60694 				8:  uint8(128),
  60695 				9:  uint8(128),
  60696 				10: uint8(128),
  60697 			},
  60698 			2: {
  60699 				0:  uint8(37),
  60700 				1:  uint8(116),
  60701 				2:  uint8(196),
  60702 				3:  uint8(243),
  60703 				4:  uint8(228),
  60704 				5:  uint8(255),
  60705 				6:  uint8(255),
  60706 				7:  uint8(255),
  60707 				8:  uint8(128),
  60708 				9:  uint8(128),
  60709 				10: uint8(128),
  60710 			},
  60711 		},
  60712 		5: {
  60713 			0: {
  60714 				0:  uint8(1),
  60715 				1:  uint8(204),
  60716 				2:  uint8(254),
  60717 				3:  uint8(255),
  60718 				4:  uint8(245),
  60719 				5:  uint8(255),
  60720 				6:  uint8(128),
  60721 				7:  uint8(128),
  60722 				8:  uint8(128),
  60723 				9:  uint8(128),
  60724 				10: uint8(128),
  60725 			},
  60726 			1: {
  60727 				0:  uint8(207),
  60728 				1:  uint8(160),
  60729 				2:  uint8(250),
  60730 				3:  uint8(255),
  60731 				4:  uint8(238),
  60732 				5:  uint8(128),
  60733 				6:  uint8(128),
  60734 				7:  uint8(128),
  60735 				8:  uint8(128),
  60736 				9:  uint8(128),
  60737 				10: uint8(128),
  60738 			},
  60739 			2: {
  60740 				0:  uint8(102),
  60741 				1:  uint8(103),
  60742 				2:  uint8(231),
  60743 				3:  uint8(255),
  60744 				4:  uint8(211),
  60745 				5:  uint8(171),
  60746 				6:  uint8(128),
  60747 				7:  uint8(128),
  60748 				8:  uint8(128),
  60749 				9:  uint8(128),
  60750 				10: uint8(128),
  60751 			},
  60752 		},
  60753 		6: {
  60754 			0: {
  60755 				0:  uint8(1),
  60756 				1:  uint8(152),
  60757 				2:  uint8(252),
  60758 				3:  uint8(255),
  60759 				4:  uint8(240),
  60760 				5:  uint8(255),
  60761 				6:  uint8(128),
  60762 				7:  uint8(128),
  60763 				8:  uint8(128),
  60764 				9:  uint8(128),
  60765 				10: uint8(128),
  60766 			},
  60767 			1: {
  60768 				0:  uint8(177),
  60769 				1:  uint8(135),
  60770 				2:  uint8(243),
  60771 				3:  uint8(255),
  60772 				4:  uint8(234),
  60773 				5:  uint8(225),
  60774 				6:  uint8(128),
  60775 				7:  uint8(128),
  60776 				8:  uint8(128),
  60777 				9:  uint8(128),
  60778 				10: uint8(128),
  60779 			},
  60780 			2: {
  60781 				0:  uint8(80),
  60782 				1:  uint8(129),
  60783 				2:  uint8(211),
  60784 				3:  uint8(255),
  60785 				4:  uint8(194),
  60786 				5:  uint8(224),
  60787 				6:  uint8(128),
  60788 				7:  uint8(128),
  60789 				8:  uint8(128),
  60790 				9:  uint8(128),
  60791 				10: uint8(128),
  60792 			},
  60793 		},
  60794 		7: {
  60795 			0: {
  60796 				0:  uint8(1),
  60797 				1:  uint8(1),
  60798 				2:  uint8(255),
  60799 				3:  uint8(128),
  60800 				4:  uint8(128),
  60801 				5:  uint8(128),
  60802 				6:  uint8(128),
  60803 				7:  uint8(128),
  60804 				8:  uint8(128),
  60805 				9:  uint8(128),
  60806 				10: uint8(128),
  60807 			},
  60808 			1: {
  60809 				0:  uint8(246),
  60810 				1:  uint8(1),
  60811 				2:  uint8(255),
  60812 				3:  uint8(128),
  60813 				4:  uint8(128),
  60814 				5:  uint8(128),
  60815 				6:  uint8(128),
  60816 				7:  uint8(128),
  60817 				8:  uint8(128),
  60818 				9:  uint8(128),
  60819 				10: uint8(128),
  60820 			},
  60821 			2: {
  60822 				0:  uint8(255),
  60823 				1:  uint8(128),
  60824 				2:  uint8(128),
  60825 				3:  uint8(128),
  60826 				4:  uint8(128),
  60827 				5:  uint8(128),
  60828 				6:  uint8(128),
  60829 				7:  uint8(128),
  60830 				8:  uint8(128),
  60831 				9:  uint8(128),
  60832 				10: uint8(128),
  60833 			},
  60834 		},
  60835 	},
  60836 	1: {
  60837 		0: {
  60838 			0: {
  60839 				0:  uint8(198),
  60840 				1:  uint8(35),
  60841 				2:  uint8(237),
  60842 				3:  uint8(223),
  60843 				4:  uint8(193),
  60844 				5:  uint8(187),
  60845 				6:  uint8(162),
  60846 				7:  uint8(160),
  60847 				8:  uint8(145),
  60848 				9:  uint8(155),
  60849 				10: uint8(62),
  60850 			},
  60851 			1: {
  60852 				0:  uint8(131),
  60853 				1:  uint8(45),
  60854 				2:  uint8(198),
  60855 				3:  uint8(221),
  60856 				4:  uint8(172),
  60857 				5:  uint8(176),
  60858 				6:  uint8(220),
  60859 				7:  uint8(157),
  60860 				8:  uint8(252),
  60861 				9:  uint8(221),
  60862 				10: uint8(1),
  60863 			},
  60864 			2: {
  60865 				0:  uint8(68),
  60866 				1:  uint8(47),
  60867 				2:  uint8(146),
  60868 				3:  uint8(208),
  60869 				4:  uint8(149),
  60870 				5:  uint8(167),
  60871 				6:  uint8(221),
  60872 				7:  uint8(162),
  60873 				8:  uint8(255),
  60874 				9:  uint8(223),
  60875 				10: uint8(128),
  60876 			},
  60877 		},
  60878 		1: {
  60879 			0: {
  60880 				0:  uint8(1),
  60881 				1:  uint8(149),
  60882 				2:  uint8(241),
  60883 				3:  uint8(255),
  60884 				4:  uint8(221),
  60885 				5:  uint8(224),
  60886 				6:  uint8(255),
  60887 				7:  uint8(255),
  60888 				8:  uint8(128),
  60889 				9:  uint8(128),
  60890 				10: uint8(128),
  60891 			},
  60892 			1: {
  60893 				0:  uint8(184),
  60894 				1:  uint8(141),
  60895 				2:  uint8(234),
  60896 				3:  uint8(253),
  60897 				4:  uint8(222),
  60898 				5:  uint8(220),
  60899 				6:  uint8(255),
  60900 				7:  uint8(199),
  60901 				8:  uint8(128),
  60902 				9:  uint8(128),
  60903 				10: uint8(128),
  60904 			},
  60905 			2: {
  60906 				0:  uint8(81),
  60907 				1:  uint8(99),
  60908 				2:  uint8(181),
  60909 				3:  uint8(242),
  60910 				4:  uint8(176),
  60911 				5:  uint8(190),
  60912 				6:  uint8(249),
  60913 				7:  uint8(202),
  60914 				8:  uint8(255),
  60915 				9:  uint8(255),
  60916 				10: uint8(128),
  60917 			},
  60918 		},
  60919 		2: {
  60920 			0: {
  60921 				0:  uint8(1),
  60922 				1:  uint8(129),
  60923 				2:  uint8(232),
  60924 				3:  uint8(253),
  60925 				4:  uint8(214),
  60926 				5:  uint8(197),
  60927 				6:  uint8(242),
  60928 				7:  uint8(196),
  60929 				8:  uint8(255),
  60930 				9:  uint8(255),
  60931 				10: uint8(128),
  60932 			},
  60933 			1: {
  60934 				0:  uint8(99),
  60935 				1:  uint8(121),
  60936 				2:  uint8(210),
  60937 				3:  uint8(250),
  60938 				4:  uint8(201),
  60939 				5:  uint8(198),
  60940 				6:  uint8(255),
  60941 				7:  uint8(202),
  60942 				8:  uint8(128),
  60943 				9:  uint8(128),
  60944 				10: uint8(128),
  60945 			},
  60946 			2: {
  60947 				0:  uint8(23),
  60948 				1:  uint8(91),
  60949 				2:  uint8(163),
  60950 				3:  uint8(242),
  60951 				4:  uint8(170),
  60952 				5:  uint8(187),
  60953 				6:  uint8(247),
  60954 				7:  uint8(210),
  60955 				8:  uint8(255),
  60956 				9:  uint8(255),
  60957 				10: uint8(128),
  60958 			},
  60959 		},
  60960 		3: {
  60961 			0: {
  60962 				0:  uint8(1),
  60963 				1:  uint8(200),
  60964 				2:  uint8(246),
  60965 				3:  uint8(255),
  60966 				4:  uint8(234),
  60967 				5:  uint8(255),
  60968 				6:  uint8(128),
  60969 				7:  uint8(128),
  60970 				8:  uint8(128),
  60971 				9:  uint8(128),
  60972 				10: uint8(128),
  60973 			},
  60974 			1: {
  60975 				0:  uint8(109),
  60976 				1:  uint8(178),
  60977 				2:  uint8(241),
  60978 				3:  uint8(255),
  60979 				4:  uint8(231),
  60980 				5:  uint8(245),
  60981 				6:  uint8(255),
  60982 				7:  uint8(255),
  60983 				8:  uint8(128),
  60984 				9:  uint8(128),
  60985 				10: uint8(128),
  60986 			},
  60987 			2: {
  60988 				0:  uint8(44),
  60989 				1:  uint8(130),
  60990 				2:  uint8(201),
  60991 				3:  uint8(253),
  60992 				4:  uint8(205),
  60993 				5:  uint8(192),
  60994 				6:  uint8(255),
  60995 				7:  uint8(255),
  60996 				8:  uint8(128),
  60997 				9:  uint8(128),
  60998 				10: uint8(128),
  60999 			},
  61000 		},
  61001 		4: {
  61002 			0: {
  61003 				0:  uint8(1),
  61004 				1:  uint8(132),
  61005 				2:  uint8(239),
  61006 				3:  uint8(251),
  61007 				4:  uint8(219),
  61008 				5:  uint8(209),
  61009 				6:  uint8(255),
  61010 				7:  uint8(165),
  61011 				8:  uint8(128),
  61012 				9:  uint8(128),
  61013 				10: uint8(128),
  61014 			},
  61015 			1: {
  61016 				0:  uint8(94),
  61017 				1:  uint8(136),
  61018 				2:  uint8(225),
  61019 				3:  uint8(251),
  61020 				4:  uint8(218),
  61021 				5:  uint8(190),
  61022 				6:  uint8(255),
  61023 				7:  uint8(255),
  61024 				8:  uint8(128),
  61025 				9:  uint8(128),
  61026 				10: uint8(128),
  61027 			},
  61028 			2: {
  61029 				0:  uint8(22),
  61030 				1:  uint8(100),
  61031 				2:  uint8(174),
  61032 				3:  uint8(245),
  61033 				4:  uint8(186),
  61034 				5:  uint8(161),
  61035 				6:  uint8(255),
  61036 				7:  uint8(199),
  61037 				8:  uint8(128),
  61038 				9:  uint8(128),
  61039 				10: uint8(128),
  61040 			},
  61041 		},
  61042 		5: {
  61043 			0: {
  61044 				0:  uint8(1),
  61045 				1:  uint8(182),
  61046 				2:  uint8(249),
  61047 				3:  uint8(255),
  61048 				4:  uint8(232),
  61049 				5:  uint8(235),
  61050 				6:  uint8(128),
  61051 				7:  uint8(128),
  61052 				8:  uint8(128),
  61053 				9:  uint8(128),
  61054 				10: uint8(128),
  61055 			},
  61056 			1: {
  61057 				0:  uint8(124),
  61058 				1:  uint8(143),
  61059 				2:  uint8(241),
  61060 				3:  uint8(255),
  61061 				4:  uint8(227),
  61062 				5:  uint8(234),
  61063 				6:  uint8(128),
  61064 				7:  uint8(128),
  61065 				8:  uint8(128),
  61066 				9:  uint8(128),
  61067 				10: uint8(128),
  61068 			},
  61069 			2: {
  61070 				0:  uint8(35),
  61071 				1:  uint8(77),
  61072 				2:  uint8(181),
  61073 				3:  uint8(251),
  61074 				4:  uint8(193),
  61075 				5:  uint8(211),
  61076 				6:  uint8(255),
  61077 				7:  uint8(205),
  61078 				8:  uint8(128),
  61079 				9:  uint8(128),
  61080 				10: uint8(128),
  61081 			},
  61082 		},
  61083 		6: {
  61084 			0: {
  61085 				0:  uint8(1),
  61086 				1:  uint8(157),
  61087 				2:  uint8(247),
  61088 				3:  uint8(255),
  61089 				4:  uint8(236),
  61090 				5:  uint8(231),
  61091 				6:  uint8(255),
  61092 				7:  uint8(255),
  61093 				8:  uint8(128),
  61094 				9:  uint8(128),
  61095 				10: uint8(128),
  61096 			},
  61097 			1: {
  61098 				0:  uint8(121),
  61099 				1:  uint8(141),
  61100 				2:  uint8(235),
  61101 				3:  uint8(255),
  61102 				4:  uint8(225),
  61103 				5:  uint8(227),
  61104 				6:  uint8(255),
  61105 				7:  uint8(255),
  61106 				8:  uint8(128),
  61107 				9:  uint8(128),
  61108 				10: uint8(128),
  61109 			},
  61110 			2: {
  61111 				0:  uint8(45),
  61112 				1:  uint8(99),
  61113 				2:  uint8(188),
  61114 				3:  uint8(251),
  61115 				4:  uint8(195),
  61116 				5:  uint8(217),
  61117 				6:  uint8(255),
  61118 				7:  uint8(224),
  61119 				8:  uint8(128),
  61120 				9:  uint8(128),
  61121 				10: uint8(128),
  61122 			},
  61123 		},
  61124 		7: {
  61125 			0: {
  61126 				0:  uint8(1),
  61127 				1:  uint8(1),
  61128 				2:  uint8(251),
  61129 				3:  uint8(255),
  61130 				4:  uint8(213),
  61131 				5:  uint8(255),
  61132 				6:  uint8(128),
  61133 				7:  uint8(128),
  61134 				8:  uint8(128),
  61135 				9:  uint8(128),
  61136 				10: uint8(128),
  61137 			},
  61138 			1: {
  61139 				0:  uint8(203),
  61140 				1:  uint8(1),
  61141 				2:  uint8(248),
  61142 				3:  uint8(255),
  61143 				4:  uint8(255),
  61144 				5:  uint8(128),
  61145 				6:  uint8(128),
  61146 				7:  uint8(128),
  61147 				8:  uint8(128),
  61148 				9:  uint8(128),
  61149 				10: uint8(128),
  61150 			},
  61151 			2: {
  61152 				0:  uint8(137),
  61153 				1:  uint8(1),
  61154 				2:  uint8(177),
  61155 				3:  uint8(255),
  61156 				4:  uint8(224),
  61157 				5:  uint8(255),
  61158 				6:  uint8(128),
  61159 				7:  uint8(128),
  61160 				8:  uint8(128),
  61161 				9:  uint8(128),
  61162 				10: uint8(128),
  61163 			},
  61164 		},
  61165 	},
  61166 	2: {
  61167 		0: {
  61168 			0: {
  61169 				0:  uint8(253),
  61170 				1:  uint8(9),
  61171 				2:  uint8(248),
  61172 				3:  uint8(251),
  61173 				4:  uint8(207),
  61174 				5:  uint8(208),
  61175 				6:  uint8(255),
  61176 				7:  uint8(192),
  61177 				8:  uint8(128),
  61178 				9:  uint8(128),
  61179 				10: uint8(128),
  61180 			},
  61181 			1: {
  61182 				0:  uint8(175),
  61183 				1:  uint8(13),
  61184 				2:  uint8(224),
  61185 				3:  uint8(243),
  61186 				4:  uint8(193),
  61187 				5:  uint8(185),
  61188 				6:  uint8(249),
  61189 				7:  uint8(198),
  61190 				8:  uint8(255),
  61191 				9:  uint8(255),
  61192 				10: uint8(128),
  61193 			},
  61194 			2: {
  61195 				0:  uint8(73),
  61196 				1:  uint8(17),
  61197 				2:  uint8(171),
  61198 				3:  uint8(221),
  61199 				4:  uint8(161),
  61200 				5:  uint8(179),
  61201 				6:  uint8(236),
  61202 				7:  uint8(167),
  61203 				8:  uint8(255),
  61204 				9:  uint8(234),
  61205 				10: uint8(128),
  61206 			},
  61207 		},
  61208 		1: {
  61209 			0: {
  61210 				0:  uint8(1),
  61211 				1:  uint8(95),
  61212 				2:  uint8(247),
  61213 				3:  uint8(253),
  61214 				4:  uint8(212),
  61215 				5:  uint8(183),
  61216 				6:  uint8(255),
  61217 				7:  uint8(255),
  61218 				8:  uint8(128),
  61219 				9:  uint8(128),
  61220 				10: uint8(128),
  61221 			},
  61222 			1: {
  61223 				0:  uint8(239),
  61224 				1:  uint8(90),
  61225 				2:  uint8(244),
  61226 				3:  uint8(250),
  61227 				4:  uint8(211),
  61228 				5:  uint8(209),
  61229 				6:  uint8(255),
  61230 				7:  uint8(255),
  61231 				8:  uint8(128),
  61232 				9:  uint8(128),
  61233 				10: uint8(128),
  61234 			},
  61235 			2: {
  61236 				0:  uint8(155),
  61237 				1:  uint8(77),
  61238 				2:  uint8(195),
  61239 				3:  uint8(248),
  61240 				4:  uint8(188),
  61241 				5:  uint8(195),
  61242 				6:  uint8(255),
  61243 				7:  uint8(255),
  61244 				8:  uint8(128),
  61245 				9:  uint8(128),
  61246 				10: uint8(128),
  61247 			},
  61248 		},
  61249 		2: {
  61250 			0: {
  61251 				0:  uint8(1),
  61252 				1:  uint8(24),
  61253 				2:  uint8(239),
  61254 				3:  uint8(251),
  61255 				4:  uint8(218),
  61256 				5:  uint8(219),
  61257 				6:  uint8(255),
  61258 				7:  uint8(205),
  61259 				8:  uint8(128),
  61260 				9:  uint8(128),
  61261 				10: uint8(128),
  61262 			},
  61263 			1: {
  61264 				0:  uint8(201),
  61265 				1:  uint8(51),
  61266 				2:  uint8(219),
  61267 				3:  uint8(255),
  61268 				4:  uint8(196),
  61269 				5:  uint8(186),
  61270 				6:  uint8(128),
  61271 				7:  uint8(128),
  61272 				8:  uint8(128),
  61273 				9:  uint8(128),
  61274 				10: uint8(128),
  61275 			},
  61276 			2: {
  61277 				0:  uint8(69),
  61278 				1:  uint8(46),
  61279 				2:  uint8(190),
  61280 				3:  uint8(239),
  61281 				4:  uint8(201),
  61282 				5:  uint8(218),
  61283 				6:  uint8(255),
  61284 				7:  uint8(228),
  61285 				8:  uint8(128),
  61286 				9:  uint8(128),
  61287 				10: uint8(128),
  61288 			},
  61289 		},
  61290 		3: {
  61291 			0: {
  61292 				0:  uint8(1),
  61293 				1:  uint8(191),
  61294 				2:  uint8(251),
  61295 				3:  uint8(255),
  61296 				4:  uint8(255),
  61297 				5:  uint8(128),
  61298 				6:  uint8(128),
  61299 				7:  uint8(128),
  61300 				8:  uint8(128),
  61301 				9:  uint8(128),
  61302 				10: uint8(128),
  61303 			},
  61304 			1: {
  61305 				0:  uint8(223),
  61306 				1:  uint8(165),
  61307 				2:  uint8(249),
  61308 				3:  uint8(255),
  61309 				4:  uint8(213),
  61310 				5:  uint8(255),
  61311 				6:  uint8(128),
  61312 				7:  uint8(128),
  61313 				8:  uint8(128),
  61314 				9:  uint8(128),
  61315 				10: uint8(128),
  61316 			},
  61317 			2: {
  61318 				0:  uint8(141),
  61319 				1:  uint8(124),
  61320 				2:  uint8(248),
  61321 				3:  uint8(255),
  61322 				4:  uint8(255),
  61323 				5:  uint8(128),
  61324 				6:  uint8(128),
  61325 				7:  uint8(128),
  61326 				8:  uint8(128),
  61327 				9:  uint8(128),
  61328 				10: uint8(128),
  61329 			},
  61330 		},
  61331 		4: {
  61332 			0: {
  61333 				0:  uint8(1),
  61334 				1:  uint8(16),
  61335 				2:  uint8(248),
  61336 				3:  uint8(255),
  61337 				4:  uint8(255),
  61338 				5:  uint8(128),
  61339 				6:  uint8(128),
  61340 				7:  uint8(128),
  61341 				8:  uint8(128),
  61342 				9:  uint8(128),
  61343 				10: uint8(128),
  61344 			},
  61345 			1: {
  61346 				0:  uint8(190),
  61347 				1:  uint8(36),
  61348 				2:  uint8(230),
  61349 				3:  uint8(255),
  61350 				4:  uint8(236),
  61351 				5:  uint8(255),
  61352 				6:  uint8(128),
  61353 				7:  uint8(128),
  61354 				8:  uint8(128),
  61355 				9:  uint8(128),
  61356 				10: uint8(128),
  61357 			},
  61358 			2: {
  61359 				0:  uint8(149),
  61360 				1:  uint8(1),
  61361 				2:  uint8(255),
  61362 				3:  uint8(128),
  61363 				4:  uint8(128),
  61364 				5:  uint8(128),
  61365 				6:  uint8(128),
  61366 				7:  uint8(128),
  61367 				8:  uint8(128),
  61368 				9:  uint8(128),
  61369 				10: uint8(128),
  61370 			},
  61371 		},
  61372 		5: {
  61373 			0: {
  61374 				0:  uint8(1),
  61375 				1:  uint8(226),
  61376 				2:  uint8(255),
  61377 				3:  uint8(128),
  61378 				4:  uint8(128),
  61379 				5:  uint8(128),
  61380 				6:  uint8(128),
  61381 				7:  uint8(128),
  61382 				8:  uint8(128),
  61383 				9:  uint8(128),
  61384 				10: uint8(128),
  61385 			},
  61386 			1: {
  61387 				0:  uint8(247),
  61388 				1:  uint8(192),
  61389 				2:  uint8(255),
  61390 				3:  uint8(128),
  61391 				4:  uint8(128),
  61392 				5:  uint8(128),
  61393 				6:  uint8(128),
  61394 				7:  uint8(128),
  61395 				8:  uint8(128),
  61396 				9:  uint8(128),
  61397 				10: uint8(128),
  61398 			},
  61399 			2: {
  61400 				0:  uint8(240),
  61401 				1:  uint8(128),
  61402 				2:  uint8(255),
  61403 				3:  uint8(128),
  61404 				4:  uint8(128),
  61405 				5:  uint8(128),
  61406 				6:  uint8(128),
  61407 				7:  uint8(128),
  61408 				8:  uint8(128),
  61409 				9:  uint8(128),
  61410 				10: uint8(128),
  61411 			},
  61412 		},
  61413 		6: {
  61414 			0: {
  61415 				0:  uint8(1),
  61416 				1:  uint8(134),
  61417 				2:  uint8(252),
  61418 				3:  uint8(255),
  61419 				4:  uint8(255),
  61420 				5:  uint8(128),
  61421 				6:  uint8(128),
  61422 				7:  uint8(128),
  61423 				8:  uint8(128),
  61424 				9:  uint8(128),
  61425 				10: uint8(128),
  61426 			},
  61427 			1: {
  61428 				0:  uint8(213),
  61429 				1:  uint8(62),
  61430 				2:  uint8(250),
  61431 				3:  uint8(255),
  61432 				4:  uint8(255),
  61433 				5:  uint8(128),
  61434 				6:  uint8(128),
  61435 				7:  uint8(128),
  61436 				8:  uint8(128),
  61437 				9:  uint8(128),
  61438 				10: uint8(128),
  61439 			},
  61440 			2: {
  61441 				0:  uint8(55),
  61442 				1:  uint8(93),
  61443 				2:  uint8(255),
  61444 				3:  uint8(128),
  61445 				4:  uint8(128),
  61446 				5:  uint8(128),
  61447 				6:  uint8(128),
  61448 				7:  uint8(128),
  61449 				8:  uint8(128),
  61450 				9:  uint8(128),
  61451 				10: uint8(128),
  61452 			},
  61453 		},
  61454 		7: {
  61455 			0: {
  61456 				0:  uint8(128),
  61457 				1:  uint8(128),
  61458 				2:  uint8(128),
  61459 				3:  uint8(128),
  61460 				4:  uint8(128),
  61461 				5:  uint8(128),
  61462 				6:  uint8(128),
  61463 				7:  uint8(128),
  61464 				8:  uint8(128),
  61465 				9:  uint8(128),
  61466 				10: uint8(128),
  61467 			},
  61468 			1: {
  61469 				0:  uint8(128),
  61470 				1:  uint8(128),
  61471 				2:  uint8(128),
  61472 				3:  uint8(128),
  61473 				4:  uint8(128),
  61474 				5:  uint8(128),
  61475 				6:  uint8(128),
  61476 				7:  uint8(128),
  61477 				8:  uint8(128),
  61478 				9:  uint8(128),
  61479 				10: uint8(128),
  61480 			},
  61481 			2: {
  61482 				0:  uint8(128),
  61483 				1:  uint8(128),
  61484 				2:  uint8(128),
  61485 				3:  uint8(128),
  61486 				4:  uint8(128),
  61487 				5:  uint8(128),
  61488 				6:  uint8(128),
  61489 				7:  uint8(128),
  61490 				8:  uint8(128),
  61491 				9:  uint8(128),
  61492 				10: uint8(128),
  61493 			},
  61494 		},
  61495 	},
  61496 	3: {
  61497 		0: {
  61498 			0: {
  61499 				0:  uint8(202),
  61500 				1:  uint8(24),
  61501 				2:  uint8(213),
  61502 				3:  uint8(235),
  61503 				4:  uint8(186),
  61504 				5:  uint8(191),
  61505 				6:  uint8(220),
  61506 				7:  uint8(160),
  61507 				8:  uint8(240),
  61508 				9:  uint8(175),
  61509 				10: uint8(255),
  61510 			},
  61511 			1: {
  61512 				0:  uint8(126),
  61513 				1:  uint8(38),
  61514 				2:  uint8(182),
  61515 				3:  uint8(232),
  61516 				4:  uint8(169),
  61517 				5:  uint8(184),
  61518 				6:  uint8(228),
  61519 				7:  uint8(174),
  61520 				8:  uint8(255),
  61521 				9:  uint8(187),
  61522 				10: uint8(128),
  61523 			},
  61524 			2: {
  61525 				0:  uint8(61),
  61526 				1:  uint8(46),
  61527 				2:  uint8(138),
  61528 				3:  uint8(219),
  61529 				4:  uint8(151),
  61530 				5:  uint8(178),
  61531 				6:  uint8(240),
  61532 				7:  uint8(170),
  61533 				8:  uint8(255),
  61534 				9:  uint8(216),
  61535 				10: uint8(128),
  61536 			},
  61537 		},
  61538 		1: {
  61539 			0: {
  61540 				0:  uint8(1),
  61541 				1:  uint8(112),
  61542 				2:  uint8(230),
  61543 				3:  uint8(250),
  61544 				4:  uint8(199),
  61545 				5:  uint8(191),
  61546 				6:  uint8(247),
  61547 				7:  uint8(159),
  61548 				8:  uint8(255),
  61549 				9:  uint8(255),
  61550 				10: uint8(128),
  61551 			},
  61552 			1: {
  61553 				0:  uint8(166),
  61554 				1:  uint8(109),
  61555 				2:  uint8(228),
  61556 				3:  uint8(252),
  61557 				4:  uint8(211),
  61558 				5:  uint8(215),
  61559 				6:  uint8(255),
  61560 				7:  uint8(174),
  61561 				8:  uint8(128),
  61562 				9:  uint8(128),
  61563 				10: uint8(128),
  61564 			},
  61565 			2: {
  61566 				0:  uint8(39),
  61567 				1:  uint8(77),
  61568 				2:  uint8(162),
  61569 				3:  uint8(232),
  61570 				4:  uint8(172),
  61571 				5:  uint8(180),
  61572 				6:  uint8(245),
  61573 				7:  uint8(178),
  61574 				8:  uint8(255),
  61575 				9:  uint8(255),
  61576 				10: uint8(128),
  61577 			},
  61578 		},
  61579 		2: {
  61580 			0: {
  61581 				0:  uint8(1),
  61582 				1:  uint8(52),
  61583 				2:  uint8(220),
  61584 				3:  uint8(246),
  61585 				4:  uint8(198),
  61586 				5:  uint8(199),
  61587 				6:  uint8(249),
  61588 				7:  uint8(220),
  61589 				8:  uint8(255),
  61590 				9:  uint8(255),
  61591 				10: uint8(128),
  61592 			},
  61593 			1: {
  61594 				0:  uint8(124),
  61595 				1:  uint8(74),
  61596 				2:  uint8(191),
  61597 				3:  uint8(243),
  61598 				4:  uint8(183),
  61599 				5:  uint8(193),
  61600 				6:  uint8(250),
  61601 				7:  uint8(221),
  61602 				8:  uint8(255),
  61603 				9:  uint8(255),
  61604 				10: uint8(128),
  61605 			},
  61606 			2: {
  61607 				0:  uint8(24),
  61608 				1:  uint8(71),
  61609 				2:  uint8(130),
  61610 				3:  uint8(219),
  61611 				4:  uint8(154),
  61612 				5:  uint8(170),
  61613 				6:  uint8(243),
  61614 				7:  uint8(182),
  61615 				8:  uint8(255),
  61616 				9:  uint8(255),
  61617 				10: uint8(128),
  61618 			},
  61619 		},
  61620 		3: {
  61621 			0: {
  61622 				0:  uint8(1),
  61623 				1:  uint8(182),
  61624 				2:  uint8(225),
  61625 				3:  uint8(249),
  61626 				4:  uint8(219),
  61627 				5:  uint8(240),
  61628 				6:  uint8(255),
  61629 				7:  uint8(224),
  61630 				8:  uint8(128),
  61631 				9:  uint8(128),
  61632 				10: uint8(128),
  61633 			},
  61634 			1: {
  61635 				0:  uint8(149),
  61636 				1:  uint8(150),
  61637 				2:  uint8(226),
  61638 				3:  uint8(252),
  61639 				4:  uint8(216),
  61640 				5:  uint8(205),
  61641 				6:  uint8(255),
  61642 				7:  uint8(171),
  61643 				8:  uint8(128),
  61644 				9:  uint8(128),
  61645 				10: uint8(128),
  61646 			},
  61647 			2: {
  61648 				0:  uint8(28),
  61649 				1:  uint8(108),
  61650 				2:  uint8(170),
  61651 				3:  uint8(242),
  61652 				4:  uint8(183),
  61653 				5:  uint8(194),
  61654 				6:  uint8(254),
  61655 				7:  uint8(223),
  61656 				8:  uint8(255),
  61657 				9:  uint8(255),
  61658 				10: uint8(128),
  61659 			},
  61660 		},
  61661 		4: {
  61662 			0: {
  61663 				0:  uint8(1),
  61664 				1:  uint8(81),
  61665 				2:  uint8(230),
  61666 				3:  uint8(252),
  61667 				4:  uint8(204),
  61668 				5:  uint8(203),
  61669 				6:  uint8(255),
  61670 				7:  uint8(192),
  61671 				8:  uint8(128),
  61672 				9:  uint8(128),
  61673 				10: uint8(128),
  61674 			},
  61675 			1: {
  61676 				0:  uint8(123),
  61677 				1:  uint8(102),
  61678 				2:  uint8(209),
  61679 				3:  uint8(247),
  61680 				4:  uint8(188),
  61681 				5:  uint8(196),
  61682 				6:  uint8(255),
  61683 				7:  uint8(233),
  61684 				8:  uint8(128),
  61685 				9:  uint8(128),
  61686 				10: uint8(128),
  61687 			},
  61688 			2: {
  61689 				0:  uint8(20),
  61690 				1:  uint8(95),
  61691 				2:  uint8(153),
  61692 				3:  uint8(243),
  61693 				4:  uint8(164),
  61694 				5:  uint8(173),
  61695 				6:  uint8(255),
  61696 				7:  uint8(203),
  61697 				8:  uint8(128),
  61698 				9:  uint8(128),
  61699 				10: uint8(128),
  61700 			},
  61701 		},
  61702 		5: {
  61703 			0: {
  61704 				0:  uint8(1),
  61705 				1:  uint8(222),
  61706 				2:  uint8(248),
  61707 				3:  uint8(255),
  61708 				4:  uint8(216),
  61709 				5:  uint8(213),
  61710 				6:  uint8(128),
  61711 				7:  uint8(128),
  61712 				8:  uint8(128),
  61713 				9:  uint8(128),
  61714 				10: uint8(128),
  61715 			},
  61716 			1: {
  61717 				0:  uint8(168),
  61718 				1:  uint8(175),
  61719 				2:  uint8(246),
  61720 				3:  uint8(252),
  61721 				4:  uint8(235),
  61722 				5:  uint8(205),
  61723 				6:  uint8(255),
  61724 				7:  uint8(255),
  61725 				8:  uint8(128),
  61726 				9:  uint8(128),
  61727 				10: uint8(128),
  61728 			},
  61729 			2: {
  61730 				0:  uint8(47),
  61731 				1:  uint8(116),
  61732 				2:  uint8(215),
  61733 				3:  uint8(255),
  61734 				4:  uint8(211),
  61735 				5:  uint8(212),
  61736 				6:  uint8(255),
  61737 				7:  uint8(255),
  61738 				8:  uint8(128),
  61739 				9:  uint8(128),
  61740 				10: uint8(128),
  61741 			},
  61742 		},
  61743 		6: {
  61744 			0: {
  61745 				0:  uint8(1),
  61746 				1:  uint8(121),
  61747 				2:  uint8(236),
  61748 				3:  uint8(253),
  61749 				4:  uint8(212),
  61750 				5:  uint8(214),
  61751 				6:  uint8(255),
  61752 				7:  uint8(255),
  61753 				8:  uint8(128),
  61754 				9:  uint8(128),
  61755 				10: uint8(128),
  61756 			},
  61757 			1: {
  61758 				0:  uint8(141),
  61759 				1:  uint8(84),
  61760 				2:  uint8(213),
  61761 				3:  uint8(252),
  61762 				4:  uint8(201),
  61763 				5:  uint8(202),
  61764 				6:  uint8(255),
  61765 				7:  uint8(219),
  61766 				8:  uint8(128),
  61767 				9:  uint8(128),
  61768 				10: uint8(128),
  61769 			},
  61770 			2: {
  61771 				0:  uint8(42),
  61772 				1:  uint8(80),
  61773 				2:  uint8(160),
  61774 				3:  uint8(240),
  61775 				4:  uint8(162),
  61776 				5:  uint8(185),
  61777 				6:  uint8(255),
  61778 				7:  uint8(205),
  61779 				8:  uint8(128),
  61780 				9:  uint8(128),
  61781 				10: uint8(128),
  61782 			},
  61783 		},
  61784 		7: {
  61785 			0: {
  61786 				0:  uint8(1),
  61787 				1:  uint8(1),
  61788 				2:  uint8(255),
  61789 				3:  uint8(128),
  61790 				4:  uint8(128),
  61791 				5:  uint8(128),
  61792 				6:  uint8(128),
  61793 				7:  uint8(128),
  61794 				8:  uint8(128),
  61795 				9:  uint8(128),
  61796 				10: uint8(128),
  61797 			},
  61798 			1: {
  61799 				0:  uint8(244),
  61800 				1:  uint8(1),
  61801 				2:  uint8(255),
  61802 				3:  uint8(128),
  61803 				4:  uint8(128),
  61804 				5:  uint8(128),
  61805 				6:  uint8(128),
  61806 				7:  uint8(128),
  61807 				8:  uint8(128),
  61808 				9:  uint8(128),
  61809 				10: uint8(128),
  61810 			},
  61811 			2: {
  61812 				0:  uint8(238),
  61813 				1:  uint8(1),
  61814 				2:  uint8(255),
  61815 				3:  uint8(128),
  61816 				4:  uint8(128),
  61817 				5:  uint8(128),
  61818 				6:  uint8(128),
  61819 				7:  uint8(128),
  61820 				8:  uint8(128),
  61821 				9:  uint8(128),
  61822 				10: uint8(128),
  61823 			},
  61824 		},
  61825 	},
  61826 }
  61827 
  61828 //------------------------------------------------------------------------------
  61829 // Paragraph 13
  61830 
  61831 var VP8CoeffsUpdateProba = [4][8][3][11]uint8_t{
  61832 	0: {
  61833 		0: {
  61834 			0: {
  61835 				0:  uint8(255),
  61836 				1:  uint8(255),
  61837 				2:  uint8(255),
  61838 				3:  uint8(255),
  61839 				4:  uint8(255),
  61840 				5:  uint8(255),
  61841 				6:  uint8(255),
  61842 				7:  uint8(255),
  61843 				8:  uint8(255),
  61844 				9:  uint8(255),
  61845 				10: uint8(255),
  61846 			},
  61847 			1: {
  61848 				0:  uint8(255),
  61849 				1:  uint8(255),
  61850 				2:  uint8(255),
  61851 				3:  uint8(255),
  61852 				4:  uint8(255),
  61853 				5:  uint8(255),
  61854 				6:  uint8(255),
  61855 				7:  uint8(255),
  61856 				8:  uint8(255),
  61857 				9:  uint8(255),
  61858 				10: uint8(255),
  61859 			},
  61860 			2: {
  61861 				0:  uint8(255),
  61862 				1:  uint8(255),
  61863 				2:  uint8(255),
  61864 				3:  uint8(255),
  61865 				4:  uint8(255),
  61866 				5:  uint8(255),
  61867 				6:  uint8(255),
  61868 				7:  uint8(255),
  61869 				8:  uint8(255),
  61870 				9:  uint8(255),
  61871 				10: uint8(255),
  61872 			},
  61873 		},
  61874 		1: {
  61875 			0: {
  61876 				0:  uint8(176),
  61877 				1:  uint8(246),
  61878 				2:  uint8(255),
  61879 				3:  uint8(255),
  61880 				4:  uint8(255),
  61881 				5:  uint8(255),
  61882 				6:  uint8(255),
  61883 				7:  uint8(255),
  61884 				8:  uint8(255),
  61885 				9:  uint8(255),
  61886 				10: uint8(255),
  61887 			},
  61888 			1: {
  61889 				0:  uint8(223),
  61890 				1:  uint8(241),
  61891 				2:  uint8(252),
  61892 				3:  uint8(255),
  61893 				4:  uint8(255),
  61894 				5:  uint8(255),
  61895 				6:  uint8(255),
  61896 				7:  uint8(255),
  61897 				8:  uint8(255),
  61898 				9:  uint8(255),
  61899 				10: uint8(255),
  61900 			},
  61901 			2: {
  61902 				0:  uint8(249),
  61903 				1:  uint8(253),
  61904 				2:  uint8(253),
  61905 				3:  uint8(255),
  61906 				4:  uint8(255),
  61907 				5:  uint8(255),
  61908 				6:  uint8(255),
  61909 				7:  uint8(255),
  61910 				8:  uint8(255),
  61911 				9:  uint8(255),
  61912 				10: uint8(255),
  61913 			},
  61914 		},
  61915 		2: {
  61916 			0: {
  61917 				0:  uint8(255),
  61918 				1:  uint8(244),
  61919 				2:  uint8(252),
  61920 				3:  uint8(255),
  61921 				4:  uint8(255),
  61922 				5:  uint8(255),
  61923 				6:  uint8(255),
  61924 				7:  uint8(255),
  61925 				8:  uint8(255),
  61926 				9:  uint8(255),
  61927 				10: uint8(255),
  61928 			},
  61929 			1: {
  61930 				0:  uint8(234),
  61931 				1:  uint8(254),
  61932 				2:  uint8(254),
  61933 				3:  uint8(255),
  61934 				4:  uint8(255),
  61935 				5:  uint8(255),
  61936 				6:  uint8(255),
  61937 				7:  uint8(255),
  61938 				8:  uint8(255),
  61939 				9:  uint8(255),
  61940 				10: uint8(255),
  61941 			},
  61942 			2: {
  61943 				0:  uint8(253),
  61944 				1:  uint8(255),
  61945 				2:  uint8(255),
  61946 				3:  uint8(255),
  61947 				4:  uint8(255),
  61948 				5:  uint8(255),
  61949 				6:  uint8(255),
  61950 				7:  uint8(255),
  61951 				8:  uint8(255),
  61952 				9:  uint8(255),
  61953 				10: uint8(255),
  61954 			},
  61955 		},
  61956 		3: {
  61957 			0: {
  61958 				0:  uint8(255),
  61959 				1:  uint8(246),
  61960 				2:  uint8(254),
  61961 				3:  uint8(255),
  61962 				4:  uint8(255),
  61963 				5:  uint8(255),
  61964 				6:  uint8(255),
  61965 				7:  uint8(255),
  61966 				8:  uint8(255),
  61967 				9:  uint8(255),
  61968 				10: uint8(255),
  61969 			},
  61970 			1: {
  61971 				0:  uint8(239),
  61972 				1:  uint8(253),
  61973 				2:  uint8(254),
  61974 				3:  uint8(255),
  61975 				4:  uint8(255),
  61976 				5:  uint8(255),
  61977 				6:  uint8(255),
  61978 				7:  uint8(255),
  61979 				8:  uint8(255),
  61980 				9:  uint8(255),
  61981 				10: uint8(255),
  61982 			},
  61983 			2: {
  61984 				0:  uint8(254),
  61985 				1:  uint8(255),
  61986 				2:  uint8(254),
  61987 				3:  uint8(255),
  61988 				4:  uint8(255),
  61989 				5:  uint8(255),
  61990 				6:  uint8(255),
  61991 				7:  uint8(255),
  61992 				8:  uint8(255),
  61993 				9:  uint8(255),
  61994 				10: uint8(255),
  61995 			},
  61996 		},
  61997 		4: {
  61998 			0: {
  61999 				0:  uint8(255),
  62000 				1:  uint8(248),
  62001 				2:  uint8(254),
  62002 				3:  uint8(255),
  62003 				4:  uint8(255),
  62004 				5:  uint8(255),
  62005 				6:  uint8(255),
  62006 				7:  uint8(255),
  62007 				8:  uint8(255),
  62008 				9:  uint8(255),
  62009 				10: uint8(255),
  62010 			},
  62011 			1: {
  62012 				0:  uint8(251),
  62013 				1:  uint8(255),
  62014 				2:  uint8(254),
  62015 				3:  uint8(255),
  62016 				4:  uint8(255),
  62017 				5:  uint8(255),
  62018 				6:  uint8(255),
  62019 				7:  uint8(255),
  62020 				8:  uint8(255),
  62021 				9:  uint8(255),
  62022 				10: uint8(255),
  62023 			},
  62024 			2: {
  62025 				0:  uint8(255),
  62026 				1:  uint8(255),
  62027 				2:  uint8(255),
  62028 				3:  uint8(255),
  62029 				4:  uint8(255),
  62030 				5:  uint8(255),
  62031 				6:  uint8(255),
  62032 				7:  uint8(255),
  62033 				8:  uint8(255),
  62034 				9:  uint8(255),
  62035 				10: uint8(255),
  62036 			},
  62037 		},
  62038 		5: {
  62039 			0: {
  62040 				0:  uint8(255),
  62041 				1:  uint8(253),
  62042 				2:  uint8(254),
  62043 				3:  uint8(255),
  62044 				4:  uint8(255),
  62045 				5:  uint8(255),
  62046 				6:  uint8(255),
  62047 				7:  uint8(255),
  62048 				8:  uint8(255),
  62049 				9:  uint8(255),
  62050 				10: uint8(255),
  62051 			},
  62052 			1: {
  62053 				0:  uint8(251),
  62054 				1:  uint8(254),
  62055 				2:  uint8(254),
  62056 				3:  uint8(255),
  62057 				4:  uint8(255),
  62058 				5:  uint8(255),
  62059 				6:  uint8(255),
  62060 				7:  uint8(255),
  62061 				8:  uint8(255),
  62062 				9:  uint8(255),
  62063 				10: uint8(255),
  62064 			},
  62065 			2: {
  62066 				0:  uint8(254),
  62067 				1:  uint8(255),
  62068 				2:  uint8(254),
  62069 				3:  uint8(255),
  62070 				4:  uint8(255),
  62071 				5:  uint8(255),
  62072 				6:  uint8(255),
  62073 				7:  uint8(255),
  62074 				8:  uint8(255),
  62075 				9:  uint8(255),
  62076 				10: uint8(255),
  62077 			},
  62078 		},
  62079 		6: {
  62080 			0: {
  62081 				0:  uint8(255),
  62082 				1:  uint8(254),
  62083 				2:  uint8(253),
  62084 				3:  uint8(255),
  62085 				4:  uint8(254),
  62086 				5:  uint8(255),
  62087 				6:  uint8(255),
  62088 				7:  uint8(255),
  62089 				8:  uint8(255),
  62090 				9:  uint8(255),
  62091 				10: uint8(255),
  62092 			},
  62093 			1: {
  62094 				0:  uint8(250),
  62095 				1:  uint8(255),
  62096 				2:  uint8(254),
  62097 				3:  uint8(255),
  62098 				4:  uint8(254),
  62099 				5:  uint8(255),
  62100 				6:  uint8(255),
  62101 				7:  uint8(255),
  62102 				8:  uint8(255),
  62103 				9:  uint8(255),
  62104 				10: uint8(255),
  62105 			},
  62106 			2: {
  62107 				0:  uint8(254),
  62108 				1:  uint8(255),
  62109 				2:  uint8(255),
  62110 				3:  uint8(255),
  62111 				4:  uint8(255),
  62112 				5:  uint8(255),
  62113 				6:  uint8(255),
  62114 				7:  uint8(255),
  62115 				8:  uint8(255),
  62116 				9:  uint8(255),
  62117 				10: uint8(255),
  62118 			},
  62119 		},
  62120 		7: {
  62121 			0: {
  62122 				0:  uint8(255),
  62123 				1:  uint8(255),
  62124 				2:  uint8(255),
  62125 				3:  uint8(255),
  62126 				4:  uint8(255),
  62127 				5:  uint8(255),
  62128 				6:  uint8(255),
  62129 				7:  uint8(255),
  62130 				8:  uint8(255),
  62131 				9:  uint8(255),
  62132 				10: uint8(255),
  62133 			},
  62134 			1: {
  62135 				0:  uint8(255),
  62136 				1:  uint8(255),
  62137 				2:  uint8(255),
  62138 				3:  uint8(255),
  62139 				4:  uint8(255),
  62140 				5:  uint8(255),
  62141 				6:  uint8(255),
  62142 				7:  uint8(255),
  62143 				8:  uint8(255),
  62144 				9:  uint8(255),
  62145 				10: uint8(255),
  62146 			},
  62147 			2: {
  62148 				0:  uint8(255),
  62149 				1:  uint8(255),
  62150 				2:  uint8(255),
  62151 				3:  uint8(255),
  62152 				4:  uint8(255),
  62153 				5:  uint8(255),
  62154 				6:  uint8(255),
  62155 				7:  uint8(255),
  62156 				8:  uint8(255),
  62157 				9:  uint8(255),
  62158 				10: uint8(255),
  62159 			},
  62160 		},
  62161 	},
  62162 	1: {
  62163 		0: {
  62164 			0: {
  62165 				0:  uint8(217),
  62166 				1:  uint8(255),
  62167 				2:  uint8(255),
  62168 				3:  uint8(255),
  62169 				4:  uint8(255),
  62170 				5:  uint8(255),
  62171 				6:  uint8(255),
  62172 				7:  uint8(255),
  62173 				8:  uint8(255),
  62174 				9:  uint8(255),
  62175 				10: uint8(255),
  62176 			},
  62177 			1: {
  62178 				0:  uint8(225),
  62179 				1:  uint8(252),
  62180 				2:  uint8(241),
  62181 				3:  uint8(253),
  62182 				4:  uint8(255),
  62183 				5:  uint8(255),
  62184 				6:  uint8(254),
  62185 				7:  uint8(255),
  62186 				8:  uint8(255),
  62187 				9:  uint8(255),
  62188 				10: uint8(255),
  62189 			},
  62190 			2: {
  62191 				0:  uint8(234),
  62192 				1:  uint8(250),
  62193 				2:  uint8(241),
  62194 				3:  uint8(250),
  62195 				4:  uint8(253),
  62196 				5:  uint8(255),
  62197 				6:  uint8(253),
  62198 				7:  uint8(254),
  62199 				8:  uint8(255),
  62200 				9:  uint8(255),
  62201 				10: uint8(255),
  62202 			},
  62203 		},
  62204 		1: {
  62205 			0: {
  62206 				0:  uint8(255),
  62207 				1:  uint8(254),
  62208 				2:  uint8(255),
  62209 				3:  uint8(255),
  62210 				4:  uint8(255),
  62211 				5:  uint8(255),
  62212 				6:  uint8(255),
  62213 				7:  uint8(255),
  62214 				8:  uint8(255),
  62215 				9:  uint8(255),
  62216 				10: uint8(255),
  62217 			},
  62218 			1: {
  62219 				0:  uint8(223),
  62220 				1:  uint8(254),
  62221 				2:  uint8(254),
  62222 				3:  uint8(255),
  62223 				4:  uint8(255),
  62224 				5:  uint8(255),
  62225 				6:  uint8(255),
  62226 				7:  uint8(255),
  62227 				8:  uint8(255),
  62228 				9:  uint8(255),
  62229 				10: uint8(255),
  62230 			},
  62231 			2: {
  62232 				0:  uint8(238),
  62233 				1:  uint8(253),
  62234 				2:  uint8(254),
  62235 				3:  uint8(254),
  62236 				4:  uint8(255),
  62237 				5:  uint8(255),
  62238 				6:  uint8(255),
  62239 				7:  uint8(255),
  62240 				8:  uint8(255),
  62241 				9:  uint8(255),
  62242 				10: uint8(255),
  62243 			},
  62244 		},
  62245 		2: {
  62246 			0: {
  62247 				0:  uint8(255),
  62248 				1:  uint8(248),
  62249 				2:  uint8(254),
  62250 				3:  uint8(255),
  62251 				4:  uint8(255),
  62252 				5:  uint8(255),
  62253 				6:  uint8(255),
  62254 				7:  uint8(255),
  62255 				8:  uint8(255),
  62256 				9:  uint8(255),
  62257 				10: uint8(255),
  62258 			},
  62259 			1: {
  62260 				0:  uint8(249),
  62261 				1:  uint8(254),
  62262 				2:  uint8(255),
  62263 				3:  uint8(255),
  62264 				4:  uint8(255),
  62265 				5:  uint8(255),
  62266 				6:  uint8(255),
  62267 				7:  uint8(255),
  62268 				8:  uint8(255),
  62269 				9:  uint8(255),
  62270 				10: uint8(255),
  62271 			},
  62272 			2: {
  62273 				0:  uint8(255),
  62274 				1:  uint8(255),
  62275 				2:  uint8(255),
  62276 				3:  uint8(255),
  62277 				4:  uint8(255),
  62278 				5:  uint8(255),
  62279 				6:  uint8(255),
  62280 				7:  uint8(255),
  62281 				8:  uint8(255),
  62282 				9:  uint8(255),
  62283 				10: uint8(255),
  62284 			},
  62285 		},
  62286 		3: {
  62287 			0: {
  62288 				0:  uint8(255),
  62289 				1:  uint8(253),
  62290 				2:  uint8(255),
  62291 				3:  uint8(255),
  62292 				4:  uint8(255),
  62293 				5:  uint8(255),
  62294 				6:  uint8(255),
  62295 				7:  uint8(255),
  62296 				8:  uint8(255),
  62297 				9:  uint8(255),
  62298 				10: uint8(255),
  62299 			},
  62300 			1: {
  62301 				0:  uint8(247),
  62302 				1:  uint8(254),
  62303 				2:  uint8(255),
  62304 				3:  uint8(255),
  62305 				4:  uint8(255),
  62306 				5:  uint8(255),
  62307 				6:  uint8(255),
  62308 				7:  uint8(255),
  62309 				8:  uint8(255),
  62310 				9:  uint8(255),
  62311 				10: uint8(255),
  62312 			},
  62313 			2: {
  62314 				0:  uint8(255),
  62315 				1:  uint8(255),
  62316 				2:  uint8(255),
  62317 				3:  uint8(255),
  62318 				4:  uint8(255),
  62319 				5:  uint8(255),
  62320 				6:  uint8(255),
  62321 				7:  uint8(255),
  62322 				8:  uint8(255),
  62323 				9:  uint8(255),
  62324 				10: uint8(255),
  62325 			},
  62326 		},
  62327 		4: {
  62328 			0: {
  62329 				0:  uint8(255),
  62330 				1:  uint8(253),
  62331 				2:  uint8(254),
  62332 				3:  uint8(255),
  62333 				4:  uint8(255),
  62334 				5:  uint8(255),
  62335 				6:  uint8(255),
  62336 				7:  uint8(255),
  62337 				8:  uint8(255),
  62338 				9:  uint8(255),
  62339 				10: uint8(255),
  62340 			},
  62341 			1: {
  62342 				0:  uint8(252),
  62343 				1:  uint8(255),
  62344 				2:  uint8(255),
  62345 				3:  uint8(255),
  62346 				4:  uint8(255),
  62347 				5:  uint8(255),
  62348 				6:  uint8(255),
  62349 				7:  uint8(255),
  62350 				8:  uint8(255),
  62351 				9:  uint8(255),
  62352 				10: uint8(255),
  62353 			},
  62354 			2: {
  62355 				0:  uint8(255),
  62356 				1:  uint8(255),
  62357 				2:  uint8(255),
  62358 				3:  uint8(255),
  62359 				4:  uint8(255),
  62360 				5:  uint8(255),
  62361 				6:  uint8(255),
  62362 				7:  uint8(255),
  62363 				8:  uint8(255),
  62364 				9:  uint8(255),
  62365 				10: uint8(255),
  62366 			},
  62367 		},
  62368 		5: {
  62369 			0: {
  62370 				0:  uint8(255),
  62371 				1:  uint8(254),
  62372 				2:  uint8(254),
  62373 				3:  uint8(255),
  62374 				4:  uint8(255),
  62375 				5:  uint8(255),
  62376 				6:  uint8(255),
  62377 				7:  uint8(255),
  62378 				8:  uint8(255),
  62379 				9:  uint8(255),
  62380 				10: uint8(255),
  62381 			},
  62382 			1: {
  62383 				0:  uint8(253),
  62384 				1:  uint8(255),
  62385 				2:  uint8(255),
  62386 				3:  uint8(255),
  62387 				4:  uint8(255),
  62388 				5:  uint8(255),
  62389 				6:  uint8(255),
  62390 				7:  uint8(255),
  62391 				8:  uint8(255),
  62392 				9:  uint8(255),
  62393 				10: uint8(255),
  62394 			},
  62395 			2: {
  62396 				0:  uint8(255),
  62397 				1:  uint8(255),
  62398 				2:  uint8(255),
  62399 				3:  uint8(255),
  62400 				4:  uint8(255),
  62401 				5:  uint8(255),
  62402 				6:  uint8(255),
  62403 				7:  uint8(255),
  62404 				8:  uint8(255),
  62405 				9:  uint8(255),
  62406 				10: uint8(255),
  62407 			},
  62408 		},
  62409 		6: {
  62410 			0: {
  62411 				0:  uint8(255),
  62412 				1:  uint8(254),
  62413 				2:  uint8(253),
  62414 				3:  uint8(255),
  62415 				4:  uint8(255),
  62416 				5:  uint8(255),
  62417 				6:  uint8(255),
  62418 				7:  uint8(255),
  62419 				8:  uint8(255),
  62420 				9:  uint8(255),
  62421 				10: uint8(255),
  62422 			},
  62423 			1: {
  62424 				0:  uint8(250),
  62425 				1:  uint8(255),
  62426 				2:  uint8(255),
  62427 				3:  uint8(255),
  62428 				4:  uint8(255),
  62429 				5:  uint8(255),
  62430 				6:  uint8(255),
  62431 				7:  uint8(255),
  62432 				8:  uint8(255),
  62433 				9:  uint8(255),
  62434 				10: uint8(255),
  62435 			},
  62436 			2: {
  62437 				0:  uint8(254),
  62438 				1:  uint8(255),
  62439 				2:  uint8(255),
  62440 				3:  uint8(255),
  62441 				4:  uint8(255),
  62442 				5:  uint8(255),
  62443 				6:  uint8(255),
  62444 				7:  uint8(255),
  62445 				8:  uint8(255),
  62446 				9:  uint8(255),
  62447 				10: uint8(255),
  62448 			},
  62449 		},
  62450 		7: {
  62451 			0: {
  62452 				0:  uint8(255),
  62453 				1:  uint8(255),
  62454 				2:  uint8(255),
  62455 				3:  uint8(255),
  62456 				4:  uint8(255),
  62457 				5:  uint8(255),
  62458 				6:  uint8(255),
  62459 				7:  uint8(255),
  62460 				8:  uint8(255),
  62461 				9:  uint8(255),
  62462 				10: uint8(255),
  62463 			},
  62464 			1: {
  62465 				0:  uint8(255),
  62466 				1:  uint8(255),
  62467 				2:  uint8(255),
  62468 				3:  uint8(255),
  62469 				4:  uint8(255),
  62470 				5:  uint8(255),
  62471 				6:  uint8(255),
  62472 				7:  uint8(255),
  62473 				8:  uint8(255),
  62474 				9:  uint8(255),
  62475 				10: uint8(255),
  62476 			},
  62477 			2: {
  62478 				0:  uint8(255),
  62479 				1:  uint8(255),
  62480 				2:  uint8(255),
  62481 				3:  uint8(255),
  62482 				4:  uint8(255),
  62483 				5:  uint8(255),
  62484 				6:  uint8(255),
  62485 				7:  uint8(255),
  62486 				8:  uint8(255),
  62487 				9:  uint8(255),
  62488 				10: uint8(255),
  62489 			},
  62490 		},
  62491 	},
  62492 	2: {
  62493 		0: {
  62494 			0: {
  62495 				0:  uint8(186),
  62496 				1:  uint8(251),
  62497 				2:  uint8(250),
  62498 				3:  uint8(255),
  62499 				4:  uint8(255),
  62500 				5:  uint8(255),
  62501 				6:  uint8(255),
  62502 				7:  uint8(255),
  62503 				8:  uint8(255),
  62504 				9:  uint8(255),
  62505 				10: uint8(255),
  62506 			},
  62507 			1: {
  62508 				0:  uint8(234),
  62509 				1:  uint8(251),
  62510 				2:  uint8(244),
  62511 				3:  uint8(254),
  62512 				4:  uint8(255),
  62513 				5:  uint8(255),
  62514 				6:  uint8(255),
  62515 				7:  uint8(255),
  62516 				8:  uint8(255),
  62517 				9:  uint8(255),
  62518 				10: uint8(255),
  62519 			},
  62520 			2: {
  62521 				0:  uint8(251),
  62522 				1:  uint8(251),
  62523 				2:  uint8(243),
  62524 				3:  uint8(253),
  62525 				4:  uint8(254),
  62526 				5:  uint8(255),
  62527 				6:  uint8(254),
  62528 				7:  uint8(255),
  62529 				8:  uint8(255),
  62530 				9:  uint8(255),
  62531 				10: uint8(255),
  62532 			},
  62533 		},
  62534 		1: {
  62535 			0: {
  62536 				0:  uint8(255),
  62537 				1:  uint8(253),
  62538 				2:  uint8(254),
  62539 				3:  uint8(255),
  62540 				4:  uint8(255),
  62541 				5:  uint8(255),
  62542 				6:  uint8(255),
  62543 				7:  uint8(255),
  62544 				8:  uint8(255),
  62545 				9:  uint8(255),
  62546 				10: uint8(255),
  62547 			},
  62548 			1: {
  62549 				0:  uint8(236),
  62550 				1:  uint8(253),
  62551 				2:  uint8(254),
  62552 				3:  uint8(255),
  62553 				4:  uint8(255),
  62554 				5:  uint8(255),
  62555 				6:  uint8(255),
  62556 				7:  uint8(255),
  62557 				8:  uint8(255),
  62558 				9:  uint8(255),
  62559 				10: uint8(255),
  62560 			},
  62561 			2: {
  62562 				0:  uint8(251),
  62563 				1:  uint8(253),
  62564 				2:  uint8(253),
  62565 				3:  uint8(254),
  62566 				4:  uint8(254),
  62567 				5:  uint8(255),
  62568 				6:  uint8(255),
  62569 				7:  uint8(255),
  62570 				8:  uint8(255),
  62571 				9:  uint8(255),
  62572 				10: uint8(255),
  62573 			},
  62574 		},
  62575 		2: {
  62576 			0: {
  62577 				0:  uint8(255),
  62578 				1:  uint8(254),
  62579 				2:  uint8(254),
  62580 				3:  uint8(255),
  62581 				4:  uint8(255),
  62582 				5:  uint8(255),
  62583 				6:  uint8(255),
  62584 				7:  uint8(255),
  62585 				8:  uint8(255),
  62586 				9:  uint8(255),
  62587 				10: uint8(255),
  62588 			},
  62589 			1: {
  62590 				0:  uint8(254),
  62591 				1:  uint8(254),
  62592 				2:  uint8(254),
  62593 				3:  uint8(255),
  62594 				4:  uint8(255),
  62595 				5:  uint8(255),
  62596 				6:  uint8(255),
  62597 				7:  uint8(255),
  62598 				8:  uint8(255),
  62599 				9:  uint8(255),
  62600 				10: uint8(255),
  62601 			},
  62602 			2: {
  62603 				0:  uint8(255),
  62604 				1:  uint8(255),
  62605 				2:  uint8(255),
  62606 				3:  uint8(255),
  62607 				4:  uint8(255),
  62608 				5:  uint8(255),
  62609 				6:  uint8(255),
  62610 				7:  uint8(255),
  62611 				8:  uint8(255),
  62612 				9:  uint8(255),
  62613 				10: uint8(255),
  62614 			},
  62615 		},
  62616 		3: {
  62617 			0: {
  62618 				0:  uint8(255),
  62619 				1:  uint8(254),
  62620 				2:  uint8(255),
  62621 				3:  uint8(255),
  62622 				4:  uint8(255),
  62623 				5:  uint8(255),
  62624 				6:  uint8(255),
  62625 				7:  uint8(255),
  62626 				8:  uint8(255),
  62627 				9:  uint8(255),
  62628 				10: uint8(255),
  62629 			},
  62630 			1: {
  62631 				0:  uint8(254),
  62632 				1:  uint8(254),
  62633 				2:  uint8(255),
  62634 				3:  uint8(255),
  62635 				4:  uint8(255),
  62636 				5:  uint8(255),
  62637 				6:  uint8(255),
  62638 				7:  uint8(255),
  62639 				8:  uint8(255),
  62640 				9:  uint8(255),
  62641 				10: uint8(255),
  62642 			},
  62643 			2: {
  62644 				0:  uint8(254),
  62645 				1:  uint8(255),
  62646 				2:  uint8(255),
  62647 				3:  uint8(255),
  62648 				4:  uint8(255),
  62649 				5:  uint8(255),
  62650 				6:  uint8(255),
  62651 				7:  uint8(255),
  62652 				8:  uint8(255),
  62653 				9:  uint8(255),
  62654 				10: uint8(255),
  62655 			},
  62656 		},
  62657 		4: {
  62658 			0: {
  62659 				0:  uint8(255),
  62660 				1:  uint8(255),
  62661 				2:  uint8(255),
  62662 				3:  uint8(255),
  62663 				4:  uint8(255),
  62664 				5:  uint8(255),
  62665 				6:  uint8(255),
  62666 				7:  uint8(255),
  62667 				8:  uint8(255),
  62668 				9:  uint8(255),
  62669 				10: uint8(255),
  62670 			},
  62671 			1: {
  62672 				0:  uint8(254),
  62673 				1:  uint8(255),
  62674 				2:  uint8(255),
  62675 				3:  uint8(255),
  62676 				4:  uint8(255),
  62677 				5:  uint8(255),
  62678 				6:  uint8(255),
  62679 				7:  uint8(255),
  62680 				8:  uint8(255),
  62681 				9:  uint8(255),
  62682 				10: uint8(255),
  62683 			},
  62684 			2: {
  62685 				0:  uint8(255),
  62686 				1:  uint8(255),
  62687 				2:  uint8(255),
  62688 				3:  uint8(255),
  62689 				4:  uint8(255),
  62690 				5:  uint8(255),
  62691 				6:  uint8(255),
  62692 				7:  uint8(255),
  62693 				8:  uint8(255),
  62694 				9:  uint8(255),
  62695 				10: uint8(255),
  62696 			},
  62697 		},
  62698 		5: {
  62699 			0: {
  62700 				0:  uint8(255),
  62701 				1:  uint8(255),
  62702 				2:  uint8(255),
  62703 				3:  uint8(255),
  62704 				4:  uint8(255),
  62705 				5:  uint8(255),
  62706 				6:  uint8(255),
  62707 				7:  uint8(255),
  62708 				8:  uint8(255),
  62709 				9:  uint8(255),
  62710 				10: uint8(255),
  62711 			},
  62712 			1: {
  62713 				0:  uint8(255),
  62714 				1:  uint8(255),
  62715 				2:  uint8(255),
  62716 				3:  uint8(255),
  62717 				4:  uint8(255),
  62718 				5:  uint8(255),
  62719 				6:  uint8(255),
  62720 				7:  uint8(255),
  62721 				8:  uint8(255),
  62722 				9:  uint8(255),
  62723 				10: uint8(255),
  62724 			},
  62725 			2: {
  62726 				0:  uint8(255),
  62727 				1:  uint8(255),
  62728 				2:  uint8(255),
  62729 				3:  uint8(255),
  62730 				4:  uint8(255),
  62731 				5:  uint8(255),
  62732 				6:  uint8(255),
  62733 				7:  uint8(255),
  62734 				8:  uint8(255),
  62735 				9:  uint8(255),
  62736 				10: uint8(255),
  62737 			},
  62738 		},
  62739 		6: {
  62740 			0: {
  62741 				0:  uint8(255),
  62742 				1:  uint8(255),
  62743 				2:  uint8(255),
  62744 				3:  uint8(255),
  62745 				4:  uint8(255),
  62746 				5:  uint8(255),
  62747 				6:  uint8(255),
  62748 				7:  uint8(255),
  62749 				8:  uint8(255),
  62750 				9:  uint8(255),
  62751 				10: uint8(255),
  62752 			},
  62753 			1: {
  62754 				0:  uint8(255),
  62755 				1:  uint8(255),
  62756 				2:  uint8(255),
  62757 				3:  uint8(255),
  62758 				4:  uint8(255),
  62759 				5:  uint8(255),
  62760 				6:  uint8(255),
  62761 				7:  uint8(255),
  62762 				8:  uint8(255),
  62763 				9:  uint8(255),
  62764 				10: uint8(255),
  62765 			},
  62766 			2: {
  62767 				0:  uint8(255),
  62768 				1:  uint8(255),
  62769 				2:  uint8(255),
  62770 				3:  uint8(255),
  62771 				4:  uint8(255),
  62772 				5:  uint8(255),
  62773 				6:  uint8(255),
  62774 				7:  uint8(255),
  62775 				8:  uint8(255),
  62776 				9:  uint8(255),
  62777 				10: uint8(255),
  62778 			},
  62779 		},
  62780 		7: {
  62781 			0: {
  62782 				0:  uint8(255),
  62783 				1:  uint8(255),
  62784 				2:  uint8(255),
  62785 				3:  uint8(255),
  62786 				4:  uint8(255),
  62787 				5:  uint8(255),
  62788 				6:  uint8(255),
  62789 				7:  uint8(255),
  62790 				8:  uint8(255),
  62791 				9:  uint8(255),
  62792 				10: uint8(255),
  62793 			},
  62794 			1: {
  62795 				0:  uint8(255),
  62796 				1:  uint8(255),
  62797 				2:  uint8(255),
  62798 				3:  uint8(255),
  62799 				4:  uint8(255),
  62800 				5:  uint8(255),
  62801 				6:  uint8(255),
  62802 				7:  uint8(255),
  62803 				8:  uint8(255),
  62804 				9:  uint8(255),
  62805 				10: uint8(255),
  62806 			},
  62807 			2: {
  62808 				0:  uint8(255),
  62809 				1:  uint8(255),
  62810 				2:  uint8(255),
  62811 				3:  uint8(255),
  62812 				4:  uint8(255),
  62813 				5:  uint8(255),
  62814 				6:  uint8(255),
  62815 				7:  uint8(255),
  62816 				8:  uint8(255),
  62817 				9:  uint8(255),
  62818 				10: uint8(255),
  62819 			},
  62820 		},
  62821 	},
  62822 	3: {
  62823 		0: {
  62824 			0: {
  62825 				0:  uint8(248),
  62826 				1:  uint8(255),
  62827 				2:  uint8(255),
  62828 				3:  uint8(255),
  62829 				4:  uint8(255),
  62830 				5:  uint8(255),
  62831 				6:  uint8(255),
  62832 				7:  uint8(255),
  62833 				8:  uint8(255),
  62834 				9:  uint8(255),
  62835 				10: uint8(255),
  62836 			},
  62837 			1: {
  62838 				0:  uint8(250),
  62839 				1:  uint8(254),
  62840 				2:  uint8(252),
  62841 				3:  uint8(254),
  62842 				4:  uint8(255),
  62843 				5:  uint8(255),
  62844 				6:  uint8(255),
  62845 				7:  uint8(255),
  62846 				8:  uint8(255),
  62847 				9:  uint8(255),
  62848 				10: uint8(255),
  62849 			},
  62850 			2: {
  62851 				0:  uint8(248),
  62852 				1:  uint8(254),
  62853 				2:  uint8(249),
  62854 				3:  uint8(253),
  62855 				4:  uint8(255),
  62856 				5:  uint8(255),
  62857 				6:  uint8(255),
  62858 				7:  uint8(255),
  62859 				8:  uint8(255),
  62860 				9:  uint8(255),
  62861 				10: uint8(255),
  62862 			},
  62863 		},
  62864 		1: {
  62865 			0: {
  62866 				0:  uint8(255),
  62867 				1:  uint8(253),
  62868 				2:  uint8(253),
  62869 				3:  uint8(255),
  62870 				4:  uint8(255),
  62871 				5:  uint8(255),
  62872 				6:  uint8(255),
  62873 				7:  uint8(255),
  62874 				8:  uint8(255),
  62875 				9:  uint8(255),
  62876 				10: uint8(255),
  62877 			},
  62878 			1: {
  62879 				0:  uint8(246),
  62880 				1:  uint8(253),
  62881 				2:  uint8(253),
  62882 				3:  uint8(255),
  62883 				4:  uint8(255),
  62884 				5:  uint8(255),
  62885 				6:  uint8(255),
  62886 				7:  uint8(255),
  62887 				8:  uint8(255),
  62888 				9:  uint8(255),
  62889 				10: uint8(255),
  62890 			},
  62891 			2: {
  62892 				0:  uint8(252),
  62893 				1:  uint8(254),
  62894 				2:  uint8(251),
  62895 				3:  uint8(254),
  62896 				4:  uint8(254),
  62897 				5:  uint8(255),
  62898 				6:  uint8(255),
  62899 				7:  uint8(255),
  62900 				8:  uint8(255),
  62901 				9:  uint8(255),
  62902 				10: uint8(255),
  62903 			},
  62904 		},
  62905 		2: {
  62906 			0: {
  62907 				0:  uint8(255),
  62908 				1:  uint8(254),
  62909 				2:  uint8(252),
  62910 				3:  uint8(255),
  62911 				4:  uint8(255),
  62912 				5:  uint8(255),
  62913 				6:  uint8(255),
  62914 				7:  uint8(255),
  62915 				8:  uint8(255),
  62916 				9:  uint8(255),
  62917 				10: uint8(255),
  62918 			},
  62919 			1: {
  62920 				0:  uint8(248),
  62921 				1:  uint8(254),
  62922 				2:  uint8(253),
  62923 				3:  uint8(255),
  62924 				4:  uint8(255),
  62925 				5:  uint8(255),
  62926 				6:  uint8(255),
  62927 				7:  uint8(255),
  62928 				8:  uint8(255),
  62929 				9:  uint8(255),
  62930 				10: uint8(255),
  62931 			},
  62932 			2: {
  62933 				0:  uint8(253),
  62934 				1:  uint8(255),
  62935 				2:  uint8(254),
  62936 				3:  uint8(254),
  62937 				4:  uint8(255),
  62938 				5:  uint8(255),
  62939 				6:  uint8(255),
  62940 				7:  uint8(255),
  62941 				8:  uint8(255),
  62942 				9:  uint8(255),
  62943 				10: uint8(255),
  62944 			},
  62945 		},
  62946 		3: {
  62947 			0: {
  62948 				0:  uint8(255),
  62949 				1:  uint8(251),
  62950 				2:  uint8(254),
  62951 				3:  uint8(255),
  62952 				4:  uint8(255),
  62953 				5:  uint8(255),
  62954 				6:  uint8(255),
  62955 				7:  uint8(255),
  62956 				8:  uint8(255),
  62957 				9:  uint8(255),
  62958 				10: uint8(255),
  62959 			},
  62960 			1: {
  62961 				0:  uint8(245),
  62962 				1:  uint8(251),
  62963 				2:  uint8(254),
  62964 				3:  uint8(255),
  62965 				4:  uint8(255),
  62966 				5:  uint8(255),
  62967 				6:  uint8(255),
  62968 				7:  uint8(255),
  62969 				8:  uint8(255),
  62970 				9:  uint8(255),
  62971 				10: uint8(255),
  62972 			},
  62973 			2: {
  62974 				0:  uint8(253),
  62975 				1:  uint8(253),
  62976 				2:  uint8(254),
  62977 				3:  uint8(255),
  62978 				4:  uint8(255),
  62979 				5:  uint8(255),
  62980 				6:  uint8(255),
  62981 				7:  uint8(255),
  62982 				8:  uint8(255),
  62983 				9:  uint8(255),
  62984 				10: uint8(255),
  62985 			},
  62986 		},
  62987 		4: {
  62988 			0: {
  62989 				0:  uint8(255),
  62990 				1:  uint8(251),
  62991 				2:  uint8(253),
  62992 				3:  uint8(255),
  62993 				4:  uint8(255),
  62994 				5:  uint8(255),
  62995 				6:  uint8(255),
  62996 				7:  uint8(255),
  62997 				8:  uint8(255),
  62998 				9:  uint8(255),
  62999 				10: uint8(255),
  63000 			},
  63001 			1: {
  63002 				0:  uint8(252),
  63003 				1:  uint8(253),
  63004 				2:  uint8(254),
  63005 				3:  uint8(255),
  63006 				4:  uint8(255),
  63007 				5:  uint8(255),
  63008 				6:  uint8(255),
  63009 				7:  uint8(255),
  63010 				8:  uint8(255),
  63011 				9:  uint8(255),
  63012 				10: uint8(255),
  63013 			},
  63014 			2: {
  63015 				0:  uint8(255),
  63016 				1:  uint8(254),
  63017 				2:  uint8(255),
  63018 				3:  uint8(255),
  63019 				4:  uint8(255),
  63020 				5:  uint8(255),
  63021 				6:  uint8(255),
  63022 				7:  uint8(255),
  63023 				8:  uint8(255),
  63024 				9:  uint8(255),
  63025 				10: uint8(255),
  63026 			},
  63027 		},
  63028 		5: {
  63029 			0: {
  63030 				0:  uint8(255),
  63031 				1:  uint8(252),
  63032 				2:  uint8(255),
  63033 				3:  uint8(255),
  63034 				4:  uint8(255),
  63035 				5:  uint8(255),
  63036 				6:  uint8(255),
  63037 				7:  uint8(255),
  63038 				8:  uint8(255),
  63039 				9:  uint8(255),
  63040 				10: uint8(255),
  63041 			},
  63042 			1: {
  63043 				0:  uint8(249),
  63044 				1:  uint8(255),
  63045 				2:  uint8(254),
  63046 				3:  uint8(255),
  63047 				4:  uint8(255),
  63048 				5:  uint8(255),
  63049 				6:  uint8(255),
  63050 				7:  uint8(255),
  63051 				8:  uint8(255),
  63052 				9:  uint8(255),
  63053 				10: uint8(255),
  63054 			},
  63055 			2: {
  63056 				0:  uint8(255),
  63057 				1:  uint8(255),
  63058 				2:  uint8(254),
  63059 				3:  uint8(255),
  63060 				4:  uint8(255),
  63061 				5:  uint8(255),
  63062 				6:  uint8(255),
  63063 				7:  uint8(255),
  63064 				8:  uint8(255),
  63065 				9:  uint8(255),
  63066 				10: uint8(255),
  63067 			},
  63068 		},
  63069 		6: {
  63070 			0: {
  63071 				0:  uint8(255),
  63072 				1:  uint8(255),
  63073 				2:  uint8(253),
  63074 				3:  uint8(255),
  63075 				4:  uint8(255),
  63076 				5:  uint8(255),
  63077 				6:  uint8(255),
  63078 				7:  uint8(255),
  63079 				8:  uint8(255),
  63080 				9:  uint8(255),
  63081 				10: uint8(255),
  63082 			},
  63083 			1: {
  63084 				0:  uint8(250),
  63085 				1:  uint8(255),
  63086 				2:  uint8(255),
  63087 				3:  uint8(255),
  63088 				4:  uint8(255),
  63089 				5:  uint8(255),
  63090 				6:  uint8(255),
  63091 				7:  uint8(255),
  63092 				8:  uint8(255),
  63093 				9:  uint8(255),
  63094 				10: uint8(255),
  63095 			},
  63096 			2: {
  63097 				0:  uint8(255),
  63098 				1:  uint8(255),
  63099 				2:  uint8(255),
  63100 				3:  uint8(255),
  63101 				4:  uint8(255),
  63102 				5:  uint8(255),
  63103 				6:  uint8(255),
  63104 				7:  uint8(255),
  63105 				8:  uint8(255),
  63106 				9:  uint8(255),
  63107 				10: uint8(255),
  63108 			},
  63109 		},
  63110 		7: {
  63111 			0: {
  63112 				0:  uint8(255),
  63113 				1:  uint8(255),
  63114 				2:  uint8(255),
  63115 				3:  uint8(255),
  63116 				4:  uint8(255),
  63117 				5:  uint8(255),
  63118 				6:  uint8(255),
  63119 				7:  uint8(255),
  63120 				8:  uint8(255),
  63121 				9:  uint8(255),
  63122 				10: uint8(255),
  63123 			},
  63124 			1: {
  63125 				0:  uint8(254),
  63126 				1:  uint8(255),
  63127 				2:  uint8(255),
  63128 				3:  uint8(255),
  63129 				4:  uint8(255),
  63130 				5:  uint8(255),
  63131 				6:  uint8(255),
  63132 				7:  uint8(255),
  63133 				8:  uint8(255),
  63134 				9:  uint8(255),
  63135 				10: uint8(255),
  63136 			},
  63137 			2: {
  63138 				0:  uint8(255),
  63139 				1:  uint8(255),
  63140 				2:  uint8(255),
  63141 				3:  uint8(255),
  63142 				4:  uint8(255),
  63143 				5:  uint8(255),
  63144 				6:  uint8(255),
  63145 				7:  uint8(255),
  63146 				8:  uint8(255),
  63147 				9:  uint8(255),
  63148 				10: uint8(255),
  63149 			},
  63150 		},
  63151 	},
  63152 }
  63153 
  63154 //------------------------------------------------------------------------------
  63155 // Initialization
  63156 
  63157 // C documentation
  63158 //
  63159 //	// Speed-critical function pointers. We have to initialize them to the default
  63160 //	// implementations within VP8EncDspInit().
  63161 var VP8CollectHistogram VP8CHisto
  63162 
  63163 var VP8Copy16x8 VP8BlockCopy
  63164 
  63165 var VP8Copy4x4 VP8BlockCopy
  63166 
  63167 var VP8DitherCombine8x8 uintptr
  63168 
  63169 //------------------------------------------------------------------------------
  63170 // Compute susceptibility based on DCT-coeff histograms:
  63171 // the higher, the "easier" the macroblock is to compress.
  63172 
  63173 var VP8DspScan = [24]int32{
  63174 	1:  libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63175 	2:  libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63176 	3:  libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63177 	4:  libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63178 	5:  libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63179 	6:  libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63180 	7:  libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63181 	8:  libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63182 	9:  libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63183 	10: libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63184 	11: libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS),
  63185 	12: libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63186 	13: libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63187 	14: libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63188 	15: libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS),
  63189 	17: libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63190 	18: libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63191 	19: libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63192 	20: libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63193 	21: libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS),
  63194 	22: libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63195 	23: libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS),
  63196 }
  63197 
  63198 //------------------------------------------------------------------------------
  63199 // Tables for level coding
  63200 
  63201 var VP8EncBands = [17]uint8_t{
  63202 	1:  uint8(1),
  63203 	2:  uint8(2),
  63204 	3:  uint8(3),
  63205 	4:  uint8(6),
  63206 	5:  uint8(4),
  63207 	6:  uint8(5),
  63208 	7:  uint8(6),
  63209 	8:  uint8(6),
  63210 	9:  uint8(6),
  63211 	10: uint8(6),
  63212 	11: uint8(6),
  63213 	12: uint8(6),
  63214 	13: uint8(6),
  63215 	14: uint8(6),
  63216 	15: uint8(7),
  63217 }
  63218 
  63219 var VP8EncPredChroma8 VP8IntraPreds
  63220 
  63221 var VP8EncPredLuma16 VP8IntraPreds
  63222 
  63223 var VP8EncPredLuma4 VP8Intra4Preds
  63224 
  63225 var VP8EncQuantize2Blocks VP8Quantize2Blocks
  63226 
  63227 var VP8EncQuantizeBlock VP8QuantizeBlock
  63228 
  63229 var VP8EncQuantizeBlockWHT VP8QuantizeBlockWHT
  63230 
  63231 //------------------------------------------------------------------------------
  63232 
  63233 // Copyright 2011 Google Inc. All Rights Reserved.
  63234 //
  63235 // Use of this source code is governed by a BSD-style license
  63236 // that can be found in the COPYING file in the root of the source
  63237 // tree. An additional intellectual property rights grant can be found
  63238 // in the file PATENTS. All contributing project authors may
  63239 // be found in the AUTHORS file in the root of the source tree.
  63240 // -----------------------------------------------------------------------------
  63241 //
  63242 //   WebP encoder: internal header.
  63243 //
  63244 // Author: Skal (pascal.massimino@gmail.com)
  63245 
  63246 //------------------------------------------------------------------------------
  63247 // Boolean-cost cost table
  63248 
  63249 var VP8EntropyCost = [256]uint16_t{
  63250 	0:   uint16(1792),
  63251 	1:   uint16(1792),
  63252 	2:   uint16(1792),
  63253 	3:   uint16(1536),
  63254 	4:   uint16(1536),
  63255 	5:   uint16(1408),
  63256 	6:   uint16(1366),
  63257 	7:   uint16(1280),
  63258 	8:   uint16(1280),
  63259 	9:   uint16(1216),
  63260 	10:  uint16(1178),
  63261 	11:  uint16(1152),
  63262 	12:  uint16(1110),
  63263 	13:  uint16(1076),
  63264 	14:  uint16(1061),
  63265 	15:  uint16(1024),
  63266 	16:  uint16(1024),
  63267 	17:  uint16(992),
  63268 	18:  uint16(968),
  63269 	19:  uint16(951),
  63270 	20:  uint16(939),
  63271 	21:  uint16(911),
  63272 	22:  uint16(896),
  63273 	23:  uint16(878),
  63274 	24:  uint16(871),
  63275 	25:  uint16(854),
  63276 	26:  uint16(838),
  63277 	27:  uint16(820),
  63278 	28:  uint16(811),
  63279 	29:  uint16(794),
  63280 	30:  uint16(786),
  63281 	31:  uint16(768),
  63282 	32:  uint16(768),
  63283 	33:  uint16(752),
  63284 	34:  uint16(740),
  63285 	35:  uint16(732),
  63286 	36:  uint16(720),
  63287 	37:  uint16(709),
  63288 	38:  uint16(704),
  63289 	39:  uint16(690),
  63290 	40:  uint16(683),
  63291 	41:  uint16(672),
  63292 	42:  uint16(666),
  63293 	43:  uint16(655),
  63294 	44:  uint16(647),
  63295 	45:  uint16(640),
  63296 	46:  uint16(631),
  63297 	47:  uint16(622),
  63298 	48:  uint16(615),
  63299 	49:  uint16(607),
  63300 	50:  uint16(598),
  63301 	51:  uint16(592),
  63302 	52:  uint16(586),
  63303 	53:  uint16(576),
  63304 	54:  uint16(572),
  63305 	55:  uint16(564),
  63306 	56:  uint16(559),
  63307 	57:  uint16(555),
  63308 	58:  uint16(547),
  63309 	59:  uint16(541),
  63310 	60:  uint16(534),
  63311 	61:  uint16(528),
  63312 	62:  uint16(522),
  63313 	63:  uint16(512),
  63314 	64:  uint16(512),
  63315 	65:  uint16(504),
  63316 	66:  uint16(500),
  63317 	67:  uint16(494),
  63318 	68:  uint16(488),
  63319 	69:  uint16(483),
  63320 	70:  uint16(477),
  63321 	71:  uint16(473),
  63322 	72:  uint16(467),
  63323 	73:  uint16(461),
  63324 	74:  uint16(458),
  63325 	75:  uint16(452),
  63326 	76:  uint16(448),
  63327 	77:  uint16(443),
  63328 	78:  uint16(438),
  63329 	79:  uint16(434),
  63330 	80:  uint16(427),
  63331 	81:  uint16(424),
  63332 	82:  uint16(419),
  63333 	83:  uint16(415),
  63334 	84:  uint16(410),
  63335 	85:  uint16(406),
  63336 	86:  uint16(403),
  63337 	87:  uint16(399),
  63338 	88:  uint16(394),
  63339 	89:  uint16(390),
  63340 	90:  uint16(384),
  63341 	91:  uint16(384),
  63342 	92:  uint16(377),
  63343 	93:  uint16(374),
  63344 	94:  uint16(370),
  63345 	95:  uint16(366),
  63346 	96:  uint16(362),
  63347 	97:  uint16(359),
  63348 	98:  uint16(355),
  63349 	99:  uint16(351),
  63350 	100: uint16(347),
  63351 	101: uint16(342),
  63352 	102: uint16(342),
  63353 	103: uint16(336),
  63354 	104: uint16(333),
  63355 	105: uint16(330),
  63356 	106: uint16(326),
  63357 	107: uint16(323),
  63358 	108: uint16(320),
  63359 	109: uint16(316),
  63360 	110: uint16(312),
  63361 	111: uint16(308),
  63362 	112: uint16(305),
  63363 	113: uint16(302),
  63364 	114: uint16(299),
  63365 	115: uint16(296),
  63366 	116: uint16(293),
  63367 	117: uint16(288),
  63368 	118: uint16(287),
  63369 	119: uint16(283),
  63370 	120: uint16(280),
  63371 	121: uint16(277),
  63372 	122: uint16(274),
  63373 	123: uint16(272),
  63374 	124: uint16(268),
  63375 	125: uint16(266),
  63376 	126: uint16(262),
  63377 	127: uint16(256),
  63378 	128: uint16(256),
  63379 	129: uint16(256),
  63380 	130: uint16(251),
  63381 	131: uint16(248),
  63382 	132: uint16(245),
  63383 	133: uint16(242),
  63384 	134: uint16(240),
  63385 	135: uint16(237),
  63386 	136: uint16(234),
  63387 	137: uint16(232),
  63388 	138: uint16(228),
  63389 	139: uint16(226),
  63390 	140: uint16(223),
  63391 	141: uint16(221),
  63392 	142: uint16(218),
  63393 	143: uint16(216),
  63394 	144: uint16(214),
  63395 	145: uint16(211),
  63396 	146: uint16(208),
  63397 	147: uint16(205),
  63398 	148: uint16(203),
  63399 	149: uint16(201),
  63400 	150: uint16(198),
  63401 	151: uint16(196),
  63402 	152: uint16(192),
  63403 	153: uint16(191),
  63404 	154: uint16(188),
  63405 	155: uint16(187),
  63406 	156: uint16(183),
  63407 	157: uint16(181),
  63408 	158: uint16(179),
  63409 	159: uint16(176),
  63410 	160: uint16(175),
  63411 	161: uint16(171),
  63412 	162: uint16(171),
  63413 	163: uint16(168),
  63414 	164: uint16(165),
  63415 	165: uint16(163),
  63416 	166: uint16(160),
  63417 	167: uint16(159),
  63418 	168: uint16(156),
  63419 	169: uint16(154),
  63420 	170: uint16(152),
  63421 	171: uint16(150),
  63422 	172: uint16(148),
  63423 	173: uint16(146),
  63424 	174: uint16(144),
  63425 	175: uint16(142),
  63426 	176: uint16(139),
  63427 	177: uint16(138),
  63428 	178: uint16(135),
  63429 	179: uint16(133),
  63430 	180: uint16(131),
  63431 	181: uint16(128),
  63432 	182: uint16(128),
  63433 	183: uint16(125),
  63434 	184: uint16(123),
  63435 	185: uint16(121),
  63436 	186: uint16(119),
  63437 	187: uint16(117),
  63438 	188: uint16(115),
  63439 	189: uint16(113),
  63440 	190: uint16(111),
  63441 	191: uint16(110),
  63442 	192: uint16(107),
  63443 	193: uint16(105),
  63444 	194: uint16(103),
  63445 	195: uint16(102),
  63446 	196: uint16(100),
  63447 	197: uint16(98),
  63448 	198: uint16(96),
  63449 	199: uint16(94),
  63450 	200: uint16(92),
  63451 	201: uint16(91),
  63452 	202: uint16(89),
  63453 	203: uint16(86),
  63454 	204: uint16(86),
  63455 	205: uint16(83),
  63456 	206: uint16(82),
  63457 	207: uint16(80),
  63458 	208: uint16(77),
  63459 	209: uint16(76),
  63460 	210: uint16(74),
  63461 	211: uint16(73),
  63462 	212: uint16(71),
  63463 	213: uint16(69),
  63464 	214: uint16(67),
  63465 	215: uint16(66),
  63466 	216: uint16(64),
  63467 	217: uint16(63),
  63468 	218: uint16(61),
  63469 	219: uint16(59),
  63470 	220: uint16(57),
  63471 	221: uint16(55),
  63472 	222: uint16(54),
  63473 	223: uint16(52),
  63474 	224: uint16(51),
  63475 	225: uint16(49),
  63476 	226: uint16(47),
  63477 	227: uint16(46),
  63478 	228: uint16(44),
  63479 	229: uint16(43),
  63480 	230: uint16(41),
  63481 	231: uint16(40),
  63482 	232: uint16(38),
  63483 	233: uint16(36),
  63484 	234: uint16(35),
  63485 	235: uint16(33),
  63486 	236: uint16(32),
  63487 	237: uint16(30),
  63488 	238: uint16(29),
  63489 	239: uint16(27),
  63490 	240: uint16(25),
  63491 	241: uint16(24),
  63492 	242: uint16(22),
  63493 	243: uint16(21),
  63494 	244: uint16(19),
  63495 	245: uint16(18),
  63496 	246: uint16(16),
  63497 	247: uint16(15),
  63498 	248: uint16(13),
  63499 	249: uint16(12),
  63500 	250: uint16(10),
  63501 	251: uint16(9),
  63502 	252: uint16(7),
  63503 	253: uint16(6),
  63504 	254: uint16(4),
  63505 	255: uint16(3),
  63506 }
  63507 
  63508 var VP8FTransform VP8Fdct
  63509 
  63510 var VP8FTransform2 VP8Fdct
  63511 
  63512 var VP8FTransformWHT VP8WHT
  63513 
  63514 // C documentation
  63515 //
  63516 //	// note: these values include the fixed VP8BitCost(1, 145) mode selection cost.
  63517 var VP8FixedCostsI16 = [4]uint16_t{
  63518 	0: uint16(663),
  63519 	1: uint16(919),
  63520 	2: uint16(872),
  63521 	3: uint16(919),
  63522 }
  63523 
  63524 var VP8FixedCostsI4 = [10][10][10]uint16_t{
  63525 	0: {
  63526 		0: {
  63527 			0: uint16(40),
  63528 			1: uint16(1151),
  63529 			2: uint16(1723),
  63530 			3: uint16(1874),
  63531 			4: uint16(2103),
  63532 			5: uint16(2019),
  63533 			6: uint16(1628),
  63534 			7: uint16(1777),
  63535 			8: uint16(2226),
  63536 			9: uint16(2137),
  63537 		},
  63538 		1: {
  63539 			0: uint16(192),
  63540 			1: uint16(469),
  63541 			2: uint16(1296),
  63542 			3: uint16(1308),
  63543 			4: uint16(1849),
  63544 			5: uint16(1794),
  63545 			6: uint16(1781),
  63546 			7: uint16(1703),
  63547 			8: uint16(1713),
  63548 			9: uint16(1522),
  63549 		},
  63550 		2: {
  63551 			0: uint16(142),
  63552 			1: uint16(910),
  63553 			2: uint16(762),
  63554 			3: uint16(1684),
  63555 			4: uint16(1849),
  63556 			5: uint16(1576),
  63557 			6: uint16(1460),
  63558 			7: uint16(1305),
  63559 			8: uint16(1801),
  63560 			9: uint16(1657),
  63561 		},
  63562 		3: {
  63563 			0: uint16(559),
  63564 			1: uint16(641),
  63565 			2: uint16(1370),
  63566 			3: uint16(421),
  63567 			4: uint16(1182),
  63568 			5: uint16(1569),
  63569 			6: uint16(1612),
  63570 			7: uint16(1725),
  63571 			8: uint16(863),
  63572 			9: uint16(1007),
  63573 		},
  63574 		4: {
  63575 			0: uint16(299),
  63576 			1: uint16(1059),
  63577 			2: uint16(1256),
  63578 			3: uint16(1108),
  63579 			4: uint16(636),
  63580 			5: uint16(1068),
  63581 			6: uint16(1581),
  63582 			7: uint16(1883),
  63583 			8: uint16(869),
  63584 			9: uint16(1142),
  63585 		},
  63586 		5: {
  63587 			0: uint16(277),
  63588 			1: uint16(1111),
  63589 			2: uint16(707),
  63590 			3: uint16(1362),
  63591 			4: uint16(1089),
  63592 			5: uint16(672),
  63593 			6: uint16(1603),
  63594 			7: uint16(1541),
  63595 			8: uint16(1545),
  63596 			9: uint16(1291),
  63597 		},
  63598 		6: {
  63599 			0: uint16(214),
  63600 			1: uint16(781),
  63601 			2: uint16(1609),
  63602 			3: uint16(1303),
  63603 			4: uint16(1632),
  63604 			5: uint16(2229),
  63605 			6: uint16(726),
  63606 			7: uint16(1560),
  63607 			8: uint16(1713),
  63608 			9: uint16(918),
  63609 		},
  63610 		7: {
  63611 			0: uint16(152),
  63612 			1: uint16(1037),
  63613 			2: uint16(1046),
  63614 			3: uint16(1759),
  63615 			4: uint16(1983),
  63616 			5: uint16(2174),
  63617 			6: uint16(1358),
  63618 			7: uint16(742),
  63619 			8: uint16(1740),
  63620 			9: uint16(1390),
  63621 		},
  63622 		8: {
  63623 			0: uint16(512),
  63624 			1: uint16(1046),
  63625 			2: uint16(1420),
  63626 			3: uint16(753),
  63627 			4: uint16(752),
  63628 			5: uint16(1297),
  63629 			6: uint16(1486),
  63630 			7: uint16(1613),
  63631 			8: uint16(460),
  63632 			9: uint16(1207),
  63633 		},
  63634 		9: {
  63635 			0: uint16(424),
  63636 			1: uint16(827),
  63637 			2: uint16(1362),
  63638 			3: uint16(719),
  63639 			4: uint16(1462),
  63640 			5: uint16(1202),
  63641 			6: uint16(1199),
  63642 			7: uint16(1476),
  63643 			8: uint16(1199),
  63644 			9: uint16(538),
  63645 		},
  63646 	},
  63647 	1: {
  63648 		0: {
  63649 			0: uint16(240),
  63650 			1: uint16(402),
  63651 			2: uint16(1134),
  63652 			3: uint16(1491),
  63653 			4: uint16(1659),
  63654 			5: uint16(1505),
  63655 			6: uint16(1517),
  63656 			7: uint16(1555),
  63657 			8: uint16(1979),
  63658 			9: uint16(2099),
  63659 		},
  63660 		1: {
  63661 			0: uint16(467),
  63662 			1: uint16(242),
  63663 			2: uint16(960),
  63664 			3: uint16(1232),
  63665 			4: uint16(1714),
  63666 			5: uint16(1620),
  63667 			6: uint16(1834),
  63668 			7: uint16(1570),
  63669 			8: uint16(1676),
  63670 			9: uint16(1391),
  63671 		},
  63672 		2: {
  63673 			0: uint16(500),
  63674 			1: uint16(455),
  63675 			2: uint16(463),
  63676 			3: uint16(1507),
  63677 			4: uint16(1699),
  63678 			5: uint16(1282),
  63679 			6: uint16(1564),
  63680 			7: uint16(982),
  63681 			8: uint16(2114),
  63682 			9: uint16(2114),
  63683 		},
  63684 		3: {
  63685 			0: uint16(672),
  63686 			1: uint16(643),
  63687 			2: uint16(1372),
  63688 			3: uint16(331),
  63689 			4: uint16(1589),
  63690 			5: uint16(1667),
  63691 			6: uint16(1453),
  63692 			7: uint16(1938),
  63693 			8: uint16(996),
  63694 			9: uint16(876),
  63695 		},
  63696 		4: {
  63697 			0: uint16(458),
  63698 			1: uint16(783),
  63699 			2: uint16(1037),
  63700 			3: uint16(911),
  63701 			4: uint16(738),
  63702 			5: uint16(968),
  63703 			6: uint16(1165),
  63704 			7: uint16(1518),
  63705 			8: uint16(859),
  63706 			9: uint16(1033),
  63707 		},
  63708 		5: {
  63709 			0: uint16(504),
  63710 			1: uint16(815),
  63711 			2: uint16(504),
  63712 			3: uint16(1139),
  63713 			4: uint16(1219),
  63714 			5: uint16(719),
  63715 			6: uint16(1506),
  63716 			7: uint16(1085),
  63717 			8: uint16(1268),
  63718 			9: uint16(1268),
  63719 		},
  63720 		6: {
  63721 			0: uint16(333),
  63722 			1: uint16(630),
  63723 			2: uint16(1445),
  63724 			3: uint16(1239),
  63725 			4: uint16(1883),
  63726 			5: uint16(3672),
  63727 			6: uint16(799),
  63728 			7: uint16(1548),
  63729 			8: uint16(1865),
  63730 			9: uint16(598),
  63731 		},
  63732 		7: {
  63733 			0: uint16(399),
  63734 			1: uint16(644),
  63735 			2: uint16(746),
  63736 			3: uint16(1342),
  63737 			4: uint16(1856),
  63738 			5: uint16(1350),
  63739 			6: uint16(1493),
  63740 			7: uint16(613),
  63741 			8: uint16(1855),
  63742 			9: uint16(1015),
  63743 		},
  63744 		8: {
  63745 			0: uint16(622),
  63746 			1: uint16(749),
  63747 			2: uint16(1205),
  63748 			3: uint16(608),
  63749 			4: uint16(1066),
  63750 			5: uint16(1408),
  63751 			6: uint16(1290),
  63752 			7: uint16(1406),
  63753 			8: uint16(546),
  63754 			9: uint16(971),
  63755 		},
  63756 		9: {
  63757 			0: uint16(500),
  63758 			1: uint16(753),
  63759 			2: uint16(1041),
  63760 			3: uint16(668),
  63761 			4: uint16(1230),
  63762 			5: uint16(1617),
  63763 			6: uint16(1297),
  63764 			7: uint16(1425),
  63765 			8: uint16(1383),
  63766 			9: uint16(523),
  63767 		},
  63768 	},
  63769 	2: {
  63770 		0: {
  63771 			0: uint16(394),
  63772 			1: uint16(553),
  63773 			2: uint16(523),
  63774 			3: uint16(1502),
  63775 			4: uint16(1536),
  63776 			5: uint16(981),
  63777 			6: uint16(1608),
  63778 			7: uint16(1142),
  63779 			8: uint16(1666),
  63780 			9: uint16(2181),
  63781 		},
  63782 		1: {
  63783 			0: uint16(655),
  63784 			1: uint16(430),
  63785 			2: uint16(375),
  63786 			3: uint16(1411),
  63787 			4: uint16(1861),
  63788 			5: uint16(1220),
  63789 			6: uint16(1677),
  63790 			7: uint16(1135),
  63791 			8: uint16(1978),
  63792 			9: uint16(1553),
  63793 		},
  63794 		2: {
  63795 			0: uint16(690),
  63796 			1: uint16(640),
  63797 			2: uint16(245),
  63798 			3: uint16(1954),
  63799 			4: uint16(2070),
  63800 			5: uint16(1194),
  63801 			6: uint16(1528),
  63802 			7: uint16(982),
  63803 			8: uint16(1972),
  63804 			9: uint16(2232),
  63805 		},
  63806 		3: {
  63807 			0: uint16(559),
  63808 			1: uint16(834),
  63809 			2: uint16(741),
  63810 			3: uint16(867),
  63811 			4: uint16(1131),
  63812 			5: uint16(980),
  63813 			6: uint16(1225),
  63814 			7: uint16(852),
  63815 			8: uint16(1092),
  63816 			9: uint16(784),
  63817 		},
  63818 		4: {
  63819 			0: uint16(690),
  63820 			1: uint16(875),
  63821 			2: uint16(516),
  63822 			3: uint16(959),
  63823 			4: uint16(673),
  63824 			5: uint16(894),
  63825 			6: uint16(1056),
  63826 			7: uint16(1190),
  63827 			8: uint16(1528),
  63828 			9: uint16(1126),
  63829 		},
  63830 		5: {
  63831 			0: uint16(740),
  63832 			1: uint16(951),
  63833 			2: uint16(384),
  63834 			3: uint16(1277),
  63835 			4: uint16(1177),
  63836 			5: uint16(492),
  63837 			6: uint16(1579),
  63838 			7: uint16(1155),
  63839 			8: uint16(1846),
  63840 			9: uint16(1513),
  63841 		},
  63842 		6: {
  63843 			0: uint16(323),
  63844 			1: uint16(775),
  63845 			2: uint16(1062),
  63846 			3: uint16(1776),
  63847 			4: uint16(3062),
  63848 			5: uint16(1274),
  63849 			6: uint16(813),
  63850 			7: uint16(1188),
  63851 			8: uint16(1372),
  63852 			9: uint16(655),
  63853 		},
  63854 		7: {
  63855 			0: uint16(488),
  63856 			1: uint16(971),
  63857 			2: uint16(484),
  63858 			3: uint16(1767),
  63859 			4: uint16(1515),
  63860 			5: uint16(1775),
  63861 			6: uint16(1115),
  63862 			7: uint16(503),
  63863 			8: uint16(1539),
  63864 			9: uint16(1461),
  63865 		},
  63866 		8: {
  63867 			0: uint16(740),
  63868 			1: uint16(1006),
  63869 			2: uint16(998),
  63870 			3: uint16(709),
  63871 			4: uint16(851),
  63872 			5: uint16(1230),
  63873 			6: uint16(1337),
  63874 			7: uint16(788),
  63875 			8: uint16(741),
  63876 			9: uint16(721),
  63877 		},
  63878 		9: {
  63879 			0: uint16(522),
  63880 			1: uint16(1073),
  63881 			2: uint16(573),
  63882 			3: uint16(1045),
  63883 			4: uint16(1346),
  63884 			5: uint16(887),
  63885 			6: uint16(1046),
  63886 			7: uint16(1146),
  63887 			8: uint16(1203),
  63888 			9: uint16(697),
  63889 		},
  63890 	},
  63891 	3: {
  63892 		0: {
  63893 			0: uint16(105),
  63894 			1: uint16(864),
  63895 			2: uint16(1442),
  63896 			3: uint16(1009),
  63897 			4: uint16(1934),
  63898 			5: uint16(1840),
  63899 			6: uint16(1519),
  63900 			7: uint16(1920),
  63901 			8: uint16(1673),
  63902 			9: uint16(1579),
  63903 		},
  63904 		1: {
  63905 			0: uint16(534),
  63906 			1: uint16(305),
  63907 			2: uint16(1193),
  63908 			3: uint16(683),
  63909 			4: uint16(1388),
  63910 			5: uint16(2164),
  63911 			6: uint16(1802),
  63912 			7: uint16(1894),
  63913 			8: uint16(1264),
  63914 			9: uint16(1170),
  63915 		},
  63916 		2: {
  63917 			0: uint16(305),
  63918 			1: uint16(518),
  63919 			2: uint16(877),
  63920 			3: uint16(1108),
  63921 			4: uint16(1426),
  63922 			5: uint16(3215),
  63923 			6: uint16(1425),
  63924 			7: uint16(1064),
  63925 			8: uint16(1320),
  63926 			9: uint16(1242),
  63927 		},
  63928 		3: {
  63929 			0: uint16(683),
  63930 			1: uint16(732),
  63931 			2: uint16(1927),
  63932 			3: uint16(257),
  63933 			4: uint16(1493),
  63934 			5: uint16(2048),
  63935 			6: uint16(1858),
  63936 			7: uint16(1552),
  63937 			8: uint16(1055),
  63938 			9: uint16(947),
  63939 		},
  63940 		4: {
  63941 			0: uint16(394),
  63942 			1: uint16(814),
  63943 			2: uint16(1024),
  63944 			3: uint16(660),
  63945 			4: uint16(959),
  63946 			5: uint16(1556),
  63947 			6: uint16(1282),
  63948 			7: uint16(1289),
  63949 			8: uint16(893),
  63950 			9: uint16(1047),
  63951 		},
  63952 		5: {
  63953 			0: uint16(528),
  63954 			1: uint16(615),
  63955 			2: uint16(996),
  63956 			3: uint16(940),
  63957 			4: uint16(1201),
  63958 			5: uint16(635),
  63959 			6: uint16(1094),
  63960 			7: uint16(2515),
  63961 			8: uint16(803),
  63962 			9: uint16(1358),
  63963 		},
  63964 		6: {
  63965 			0: uint16(347),
  63966 			1: uint16(614),
  63967 			2: uint16(1609),
  63968 			3: uint16(1187),
  63969 			4: uint16(3133),
  63970 			5: uint16(1345),
  63971 			6: uint16(1007),
  63972 			7: uint16(1339),
  63973 			8: uint16(1017),
  63974 			9: uint16(667),
  63975 		},
  63976 		7: {
  63977 			0: uint16(218),
  63978 			1: uint16(740),
  63979 			2: uint16(878),
  63980 			3: uint16(1605),
  63981 			4: uint16(3650),
  63982 			5: uint16(3650),
  63983 			6: uint16(1345),
  63984 			7: uint16(758),
  63985 			8: uint16(1357),
  63986 			9: uint16(1617),
  63987 		},
  63988 		8: {
  63989 			0: uint16(672),
  63990 			1: uint16(750),
  63991 			2: uint16(1541),
  63992 			3: uint16(558),
  63993 			4: uint16(1257),
  63994 			5: uint16(1599),
  63995 			6: uint16(1870),
  63996 			7: uint16(2135),
  63997 			8: uint16(402),
  63998 			9: uint16(1087),
  63999 		},
  64000 		9: {
  64001 			0: uint16(592),
  64002 			1: uint16(684),
  64003 			2: uint16(1161),
  64004 			3: uint16(430),
  64005 			4: uint16(1092),
  64006 			5: uint16(1497),
  64007 			6: uint16(1475),
  64008 			7: uint16(1489),
  64009 			8: uint16(1095),
  64010 			9: uint16(822),
  64011 		},
  64012 	},
  64013 	4: {
  64014 		0: {
  64015 			0: uint16(228),
  64016 			1: uint16(1056),
  64017 			2: uint16(1059),
  64018 			3: uint16(1368),
  64019 			4: uint16(752),
  64020 			5: uint16(982),
  64021 			6: uint16(1512),
  64022 			7: uint16(1518),
  64023 			8: uint16(987),
  64024 			9: uint16(1782),
  64025 		},
  64026 		1: {
  64027 			0: uint16(494),
  64028 			1: uint16(514),
  64029 			2: uint16(818),
  64030 			3: uint16(942),
  64031 			4: uint16(965),
  64032 			5: uint16(892),
  64033 			6: uint16(1610),
  64034 			7: uint16(1356),
  64035 			8: uint16(1048),
  64036 			9: uint16(1363),
  64037 		},
  64038 		2: {
  64039 			0: uint16(512),
  64040 			1: uint16(648),
  64041 			2: uint16(591),
  64042 			3: uint16(1042),
  64043 			4: uint16(761),
  64044 			5: uint16(991),
  64045 			6: uint16(1196),
  64046 			7: uint16(1454),
  64047 			8: uint16(1309),
  64048 			9: uint16(1463),
  64049 		},
  64050 		3: {
  64051 			0: uint16(683),
  64052 			1: uint16(749),
  64053 			2: uint16(1043),
  64054 			3: uint16(676),
  64055 			4: uint16(841),
  64056 			5: uint16(1396),
  64057 			6: uint16(1133),
  64058 			7: uint16(1138),
  64059 			8: uint16(654),
  64060 			9: uint16(939),
  64061 		},
  64062 		4: {
  64063 			0: uint16(622),
  64064 			1: uint16(1101),
  64065 			2: uint16(1126),
  64066 			3: uint16(994),
  64067 			4: uint16(361),
  64068 			5: uint16(1077),
  64069 			6: uint16(1203),
  64070 			7: uint16(1318),
  64071 			8: uint16(877),
  64072 			9: uint16(1219),
  64073 		},
  64074 		5: {
  64075 			0: uint16(631),
  64076 			1: uint16(1068),
  64077 			2: uint16(857),
  64078 			3: uint16(1650),
  64079 			4: uint16(651),
  64080 			5: uint16(477),
  64081 			6: uint16(1650),
  64082 			7: uint16(1419),
  64083 			8: uint16(828),
  64084 			9: uint16(1170),
  64085 		},
  64086 		6: {
  64087 			0: uint16(555),
  64088 			1: uint16(727),
  64089 			2: uint16(1068),
  64090 			3: uint16(1335),
  64091 			4: uint16(3127),
  64092 			5: uint16(1339),
  64093 			6: uint16(820),
  64094 			7: uint16(1331),
  64095 			8: uint16(1077),
  64096 			9: uint16(429),
  64097 		},
  64098 		7: {
  64099 			0: uint16(504),
  64100 			1: uint16(879),
  64101 			2: uint16(624),
  64102 			3: uint16(1398),
  64103 			4: uint16(889),
  64104 			5: uint16(889),
  64105 			6: uint16(1392),
  64106 			7: uint16(808),
  64107 			8: uint16(891),
  64108 			9: uint16(1406),
  64109 		},
  64110 		8: {
  64111 			0: uint16(683),
  64112 			1: uint16(1602),
  64113 			2: uint16(1289),
  64114 			3: uint16(977),
  64115 			4: uint16(578),
  64116 			5: uint16(983),
  64117 			6: uint16(1280),
  64118 			7: uint16(1708),
  64119 			8: uint16(406),
  64120 			9: uint16(1122),
  64121 		},
  64122 		9: {
  64123 			0: uint16(399),
  64124 			1: uint16(865),
  64125 			2: uint16(1433),
  64126 			3: uint16(1070),
  64127 			4: uint16(1072),
  64128 			5: uint16(764),
  64129 			6: uint16(968),
  64130 			7: uint16(1477),
  64131 			8: uint16(1223),
  64132 			9: uint16(678),
  64133 		},
  64134 	},
  64135 	5: {
  64136 		0: {
  64137 			0: uint16(333),
  64138 			1: uint16(760),
  64139 			2: uint16(935),
  64140 			3: uint16(1638),
  64141 			4: uint16(1010),
  64142 			5: uint16(529),
  64143 			6: uint16(1646),
  64144 			7: uint16(1410),
  64145 			8: uint16(1472),
  64146 			9: uint16(2219),
  64147 		},
  64148 		1: {
  64149 			0: uint16(512),
  64150 			1: uint16(494),
  64151 			2: uint16(750),
  64152 			3: uint16(1160),
  64153 			4: uint16(1215),
  64154 			5: uint16(610),
  64155 			6: uint16(1870),
  64156 			7: uint16(1868),
  64157 			8: uint16(1628),
  64158 			9: uint16(1169),
  64159 		},
  64160 		2: {
  64161 			0: uint16(572),
  64162 			1: uint16(646),
  64163 			2: uint16(492),
  64164 			3: uint16(1934),
  64165 			4: uint16(1208),
  64166 			5: uint16(603),
  64167 			6: uint16(1580),
  64168 			7: uint16(1099),
  64169 			8: uint16(1398),
  64170 			9: uint16(1995),
  64171 		},
  64172 		3: {
  64173 			0: uint16(786),
  64174 			1: uint16(789),
  64175 			2: uint16(942),
  64176 			3: uint16(581),
  64177 			4: uint16(1018),
  64178 			5: uint16(951),
  64179 			6: uint16(1599),
  64180 			7: uint16(1207),
  64181 			8: uint16(731),
  64182 			9: uint16(768),
  64183 		},
  64184 		4: {
  64185 			0: uint16(690),
  64186 			1: uint16(1015),
  64187 			2: uint16(672),
  64188 			3: uint16(1078),
  64189 			4: uint16(582),
  64190 			5: uint16(504),
  64191 			6: uint16(1693),
  64192 			7: uint16(1438),
  64193 			8: uint16(1108),
  64194 			9: uint16(2897),
  64195 		},
  64196 		5: {
  64197 			0: uint16(768),
  64198 			1: uint16(1267),
  64199 			2: uint16(571),
  64200 			3: uint16(2005),
  64201 			4: uint16(1243),
  64202 			5: uint16(244),
  64203 			6: uint16(2881),
  64204 			7: uint16(1380),
  64205 			8: uint16(1786),
  64206 			9: uint16(1453),
  64207 		},
  64208 		6: {
  64209 			0: uint16(452),
  64210 			1: uint16(899),
  64211 			2: uint16(1293),
  64212 			3: uint16(903),
  64213 			4: uint16(1311),
  64214 			5: uint16(3100),
  64215 			6: uint16(465),
  64216 			7: uint16(1311),
  64217 			8: uint16(1319),
  64218 			9: uint16(813),
  64219 		},
  64220 		7: {
  64221 			0: uint16(394),
  64222 			1: uint16(927),
  64223 			2: uint16(942),
  64224 			3: uint16(1103),
  64225 			4: uint16(1358),
  64226 			5: uint16(1104),
  64227 			6: uint16(946),
  64228 			7: uint16(593),
  64229 			8: uint16(1363),
  64230 			9: uint16(1109),
  64231 		},
  64232 		8: {
  64233 			0: uint16(559),
  64234 			1: uint16(1005),
  64235 			2: uint16(1007),
  64236 			3: uint16(1016),
  64237 			4: uint16(658),
  64238 			5: uint16(1173),
  64239 			6: uint16(1021),
  64240 			7: uint16(1164),
  64241 			8: uint16(623),
  64242 			9: uint16(1028),
  64243 		},
  64244 		9: {
  64245 			0: uint16(564),
  64246 			1: uint16(796),
  64247 			2: uint16(632),
  64248 			3: uint16(1005),
  64249 			4: uint16(1014),
  64250 			5: uint16(863),
  64251 			6: uint16(2316),
  64252 			7: uint16(1268),
  64253 			8: uint16(938),
  64254 			9: uint16(764),
  64255 		},
  64256 	},
  64257 	6: {
  64258 		0: {
  64259 			0: uint16(266),
  64260 			1: uint16(606),
  64261 			2: uint16(1098),
  64262 			3: uint16(1228),
  64263 			4: uint16(1497),
  64264 			5: uint16(1243),
  64265 			6: uint16(948),
  64266 			7: uint16(1030),
  64267 			8: uint16(1734),
  64268 			9: uint16(1461),
  64269 		},
  64270 		1: {
  64271 			0: uint16(366),
  64272 			1: uint16(585),
  64273 			2: uint16(901),
  64274 			3: uint16(1060),
  64275 			4: uint16(1407),
  64276 			5: uint16(1247),
  64277 			6: uint16(876),
  64278 			7: uint16(1134),
  64279 			8: uint16(1620),
  64280 			9: uint16(1054),
  64281 		},
  64282 		2: {
  64283 			0: uint16(452),
  64284 			1: uint16(565),
  64285 			2: uint16(542),
  64286 			3: uint16(1729),
  64287 			4: uint16(1479),
  64288 			5: uint16(1479),
  64289 			6: uint16(1016),
  64290 			7: uint16(886),
  64291 			8: uint16(2938),
  64292 			9: uint16(1150),
  64293 		},
  64294 		3: {
  64295 			0: uint16(555),
  64296 			1: uint16(1088),
  64297 			2: uint16(1533),
  64298 			3: uint16(950),
  64299 			4: uint16(1354),
  64300 			5: uint16(895),
  64301 			6: uint16(834),
  64302 			7: uint16(1019),
  64303 			8: uint16(1021),
  64304 			9: uint16(496),
  64305 		},
  64306 		4: {
  64307 			0: uint16(704),
  64308 			1: uint16(815),
  64309 			2: uint16(1193),
  64310 			3: uint16(971),
  64311 			4: uint16(973),
  64312 			5: uint16(640),
  64313 			6: uint16(1217),
  64314 			7: uint16(2214),
  64315 			8: uint16(832),
  64316 			9: uint16(578),
  64317 		},
  64318 		5: {
  64319 			0: uint16(672),
  64320 			1: uint16(1245),
  64321 			2: uint16(579),
  64322 			3: uint16(871),
  64323 			4: uint16(875),
  64324 			5: uint16(774),
  64325 			6: uint16(872),
  64326 			7: uint16(1273),
  64327 			8: uint16(1027),
  64328 			9: uint16(949),
  64329 		},
  64330 		6: {
  64331 			0: uint16(296),
  64332 			1: uint16(1134),
  64333 			2: uint16(2050),
  64334 			3: uint16(1784),
  64335 			4: uint16(1636),
  64336 			5: uint16(3425),
  64337 			6: uint16(442),
  64338 			7: uint16(1550),
  64339 			8: uint16(2076),
  64340 			9: uint16(722),
  64341 		},
  64342 		7: {
  64343 			0: uint16(342),
  64344 			1: uint16(982),
  64345 			2: uint16(1259),
  64346 			3: uint16(1846),
  64347 			4: uint16(1848),
  64348 			5: uint16(1848),
  64349 			6: uint16(622),
  64350 			7: uint16(568),
  64351 			8: uint16(1847),
  64352 			9: uint16(1052),
  64353 		},
  64354 		8: {
  64355 			0: uint16(555),
  64356 			1: uint16(1064),
  64357 			2: uint16(1304),
  64358 			3: uint16(828),
  64359 			4: uint16(746),
  64360 			5: uint16(1343),
  64361 			6: uint16(1075),
  64362 			7: uint16(1329),
  64363 			8: uint16(1078),
  64364 			9: uint16(494),
  64365 		},
  64366 		9: {
  64367 			0: uint16(288),
  64368 			1: uint16(1167),
  64369 			2: uint16(1285),
  64370 			3: uint16(1174),
  64371 			4: uint16(1639),
  64372 			5: uint16(1639),
  64373 			6: uint16(833),
  64374 			7: uint16(2254),
  64375 			8: uint16(1304),
  64376 			9: uint16(509),
  64377 		},
  64378 	},
  64379 	7: {
  64380 		0: {
  64381 			0: uint16(342),
  64382 			1: uint16(719),
  64383 			2: uint16(767),
  64384 			3: uint16(1866),
  64385 			4: uint16(1757),
  64386 			5: uint16(1270),
  64387 			6: uint16(1246),
  64388 			7: uint16(550),
  64389 			8: uint16(1746),
  64390 			9: uint16(2151),
  64391 		},
  64392 		1: {
  64393 			0: uint16(483),
  64394 			1: uint16(653),
  64395 			2: uint16(694),
  64396 			3: uint16(1509),
  64397 			4: uint16(1459),
  64398 			5: uint16(1410),
  64399 			6: uint16(1218),
  64400 			7: uint16(507),
  64401 			8: uint16(1914),
  64402 			9: uint16(1266),
  64403 		},
  64404 		2: {
  64405 			0: uint16(488),
  64406 			1: uint16(757),
  64407 			2: uint16(447),
  64408 			3: uint16(2979),
  64409 			4: uint16(1813),
  64410 			5: uint16(1268),
  64411 			6: uint16(1654),
  64412 			7: uint16(539),
  64413 			8: uint16(1849),
  64414 			9: uint16(2109),
  64415 		},
  64416 		3: {
  64417 			0: uint16(522),
  64418 			1: uint16(1097),
  64419 			2: uint16(1085),
  64420 			3: uint16(851),
  64421 			4: uint16(1365),
  64422 			5: uint16(1111),
  64423 			6: uint16(851),
  64424 			7: uint16(901),
  64425 			8: uint16(961),
  64426 			9: uint16(605),
  64427 		},
  64428 		4: {
  64429 			0: uint16(709),
  64430 			1: uint16(716),
  64431 			2: uint16(841),
  64432 			3: uint16(728),
  64433 			4: uint16(736),
  64434 			5: uint16(945),
  64435 			6: uint16(941),
  64436 			7: uint16(862),
  64437 			8: uint16(2845),
  64438 			9: uint16(1057),
  64439 		},
  64440 		5: {
  64441 			0: uint16(512),
  64442 			1: uint16(1323),
  64443 			2: uint16(500),
  64444 			3: uint16(1336),
  64445 			4: uint16(1083),
  64446 			5: uint16(681),
  64447 			6: uint16(1342),
  64448 			7: uint16(717),
  64449 			8: uint16(1604),
  64450 			9: uint16(1350),
  64451 		},
  64452 		6: {
  64453 			0: uint16(452),
  64454 			1: uint16(1155),
  64455 			2: uint16(1372),
  64456 			3: uint16(1900),
  64457 			4: uint16(1501),
  64458 			5: uint16(3290),
  64459 			6: uint16(311),
  64460 			7: uint16(944),
  64461 			8: uint16(1919),
  64462 			9: uint16(922),
  64463 		},
  64464 		7: {
  64465 			0: uint16(403),
  64466 			1: uint16(1520),
  64467 			2: uint16(977),
  64468 			3: uint16(2132),
  64469 			4: uint16(1733),
  64470 			5: uint16(3522),
  64471 			6: uint16(1076),
  64472 			7: uint16(276),
  64473 			8: uint16(3335),
  64474 			9: uint16(1547),
  64475 		},
  64476 		8: {
  64477 			0: uint16(559),
  64478 			1: uint16(1374),
  64479 			2: uint16(1101),
  64480 			3: uint16(615),
  64481 			4: uint16(673),
  64482 			5: uint16(2462),
  64483 			6: uint16(974),
  64484 			7: uint16(795),
  64485 			8: uint16(984),
  64486 			9: uint16(984),
  64487 		},
  64488 		9: {
  64489 			0: uint16(547),
  64490 			1: uint16(1122),
  64491 			2: uint16(1062),
  64492 			3: uint16(812),
  64493 			4: uint16(1410),
  64494 			5: uint16(951),
  64495 			6: uint16(1140),
  64496 			7: uint16(622),
  64497 			8: uint16(1268),
  64498 			9: uint16(651),
  64499 		},
  64500 	},
  64501 	8: {
  64502 		0: {
  64503 			0: uint16(165),
  64504 			1: uint16(982),
  64505 			2: uint16(1235),
  64506 			3: uint16(938),
  64507 			4: uint16(1334),
  64508 			5: uint16(1366),
  64509 			6: uint16(1659),
  64510 			7: uint16(1578),
  64511 			8: uint16(964),
  64512 			9: uint16(1612),
  64513 		},
  64514 		1: {
  64515 			0: uint16(592),
  64516 			1: uint16(422),
  64517 			2: uint16(925),
  64518 			3: uint16(847),
  64519 			4: uint16(1139),
  64520 			5: uint16(1112),
  64521 			6: uint16(1387),
  64522 			7: uint16(2036),
  64523 			8: uint16(861),
  64524 			9: uint16(1041),
  64525 		},
  64526 		2: {
  64527 			0: uint16(403),
  64528 			1: uint16(837),
  64529 			2: uint16(732),
  64530 			3: uint16(770),
  64531 			4: uint16(941),
  64532 			5: uint16(1658),
  64533 			6: uint16(1250),
  64534 			7: uint16(809),
  64535 			8: uint16(1407),
  64536 			9: uint16(1407),
  64537 		},
  64538 		3: {
  64539 			0: uint16(896),
  64540 			1: uint16(874),
  64541 			2: uint16(1071),
  64542 			3: uint16(381),
  64543 			4: uint16(1568),
  64544 			5: uint16(1722),
  64545 			6: uint16(1437),
  64546 			7: uint16(2192),
  64547 			8: uint16(480),
  64548 			9: uint16(1035),
  64549 		},
  64550 		4: {
  64551 			0: uint16(640),
  64552 			1: uint16(1098),
  64553 			2: uint16(1012),
  64554 			3: uint16(1032),
  64555 			4: uint16(684),
  64556 			5: uint16(1382),
  64557 			6: uint16(1581),
  64558 			7: uint16(2106),
  64559 			8: uint16(416),
  64560 			9: uint16(865),
  64561 		},
  64562 		5: {
  64563 			0: uint16(559),
  64564 			1: uint16(1005),
  64565 			2: uint16(819),
  64566 			3: uint16(914),
  64567 			4: uint16(710),
  64568 			5: uint16(770),
  64569 			6: uint16(1418),
  64570 			7: uint16(920),
  64571 			8: uint16(838),
  64572 			9: uint16(1435),
  64573 		},
  64574 		6: {
  64575 			0: uint16(415),
  64576 			1: uint16(1258),
  64577 			2: uint16(1245),
  64578 			3: uint16(870),
  64579 			4: uint16(1278),
  64580 			5: uint16(3067),
  64581 			6: uint16(770),
  64582 			7: uint16(1021),
  64583 			8: uint16(1287),
  64584 			9: uint16(522),
  64585 		},
  64586 		7: {
  64587 			0: uint16(406),
  64588 			1: uint16(990),
  64589 			2: uint16(601),
  64590 			3: uint16(1009),
  64591 			4: uint16(1265),
  64592 			5: uint16(1265),
  64593 			6: uint16(1267),
  64594 			7: uint16(759),
  64595 			8: uint16(1017),
  64596 			9: uint16(1277),
  64597 		},
  64598 		8: {
  64599 			0: uint16(968),
  64600 			1: uint16(1182),
  64601 			2: uint16(1329),
  64602 			3: uint16(788),
  64603 			4: uint16(1032),
  64604 			5: uint16(1292),
  64605 			6: uint16(1705),
  64606 			7: uint16(1714),
  64607 			8: uint16(203),
  64608 			9: uint16(1403),
  64609 		},
  64610 		9: {
  64611 			0: uint16(732),
  64612 			1: uint16(877),
  64613 			2: uint16(1279),
  64614 			3: uint16(471),
  64615 			4: uint16(901),
  64616 			5: uint16(1161),
  64617 			6: uint16(1545),
  64618 			7: uint16(1294),
  64619 			8: uint16(755),
  64620 			9: uint16(755),
  64621 		},
  64622 	},
  64623 	9: {
  64624 		0: {
  64625 			0: uint16(111),
  64626 			1: uint16(931),
  64627 			2: uint16(1378),
  64628 			3: uint16(1185),
  64629 			4: uint16(1933),
  64630 			5: uint16(1648),
  64631 			6: uint16(1148),
  64632 			7: uint16(1714),
  64633 			8: uint16(1873),
  64634 			9: uint16(1307),
  64635 		},
  64636 		1: {
  64637 			0: uint16(406),
  64638 			1: uint16(414),
  64639 			2: uint16(1030),
  64640 			3: uint16(1023),
  64641 			4: uint16(1910),
  64642 			5: uint16(1404),
  64643 			6: uint16(1313),
  64644 			7: uint16(1647),
  64645 			8: uint16(1509),
  64646 			9: uint16(793),
  64647 		},
  64648 		2: {
  64649 			0: uint16(342),
  64650 			1: uint16(640),
  64651 			2: uint16(575),
  64652 			3: uint16(1088),
  64653 			4: uint16(1241),
  64654 			5: uint16(1349),
  64655 			6: uint16(1161),
  64656 			7: uint16(1350),
  64657 			8: uint16(1756),
  64658 			9: uint16(1502),
  64659 		},
  64660 		3: {
  64661 			0: uint16(559),
  64662 			1: uint16(766),
  64663 			2: uint16(1185),
  64664 			3: uint16(357),
  64665 			4: uint16(1682),
  64666 			5: uint16(1428),
  64667 			6: uint16(1329),
  64668 			7: uint16(1897),
  64669 			8: uint16(1219),
  64670 			9: uint16(802),
  64671 		},
  64672 		4: {
  64673 			0: uint16(473),
  64674 			1: uint16(909),
  64675 			2: uint16(1164),
  64676 			3: uint16(771),
  64677 			4: uint16(719),
  64678 			5: uint16(2508),
  64679 			6: uint16(1427),
  64680 			7: uint16(1432),
  64681 			8: uint16(722),
  64682 			9: uint16(782),
  64683 		},
  64684 		5: {
  64685 			0: uint16(342),
  64686 			1: uint16(892),
  64687 			2: uint16(785),
  64688 			3: uint16(1145),
  64689 			4: uint16(1150),
  64690 			5: uint16(794),
  64691 			6: uint16(1296),
  64692 			7: uint16(1550),
  64693 			8: uint16(973),
  64694 			9: uint16(1057),
  64695 		},
  64696 		6: {
  64697 			0: uint16(208),
  64698 			1: uint16(1036),
  64699 			2: uint16(1326),
  64700 			3: uint16(1343),
  64701 			4: uint16(1606),
  64702 			5: uint16(3395),
  64703 			6: uint16(815),
  64704 			7: uint16(1455),
  64705 			8: uint16(1618),
  64706 			9: uint16(712),
  64707 		},
  64708 		7: {
  64709 			0: uint16(228),
  64710 			1: uint16(928),
  64711 			2: uint16(890),
  64712 			3: uint16(1046),
  64713 			4: uint16(3499),
  64714 			5: uint16(1711),
  64715 			6: uint16(994),
  64716 			7: uint16(829),
  64717 			8: uint16(1720),
  64718 			9: uint16(1318),
  64719 		},
  64720 		8: {
  64721 			0: uint16(768),
  64722 			1: uint16(724),
  64723 			2: uint16(1058),
  64724 			3: uint16(636),
  64725 			4: uint16(991),
  64726 			5: uint16(1075),
  64727 			6: uint16(1319),
  64728 			7: uint16(1324),
  64729 			8: uint16(616),
  64730 			9: uint16(825),
  64731 		},
  64732 		9: {
  64733 			0: uint16(305),
  64734 			1: uint16(1167),
  64735 			2: uint16(1358),
  64736 			3: uint16(899),
  64737 			4: uint16(1587),
  64738 			5: uint16(1587),
  64739 			6: uint16(987),
  64740 			7: uint16(1988),
  64741 			8: uint16(1332),
  64742 			9: uint16(501),
  64743 		},
  64744 	},
  64745 }
  64746 
  64747 //------------------------------------------------------------------------------
  64748 // Mode cost tables.
  64749 
  64750 // C documentation
  64751 //
  64752 //	// These are the fixed probabilities (in the coding trees) turned into bit-cost
  64753 //	// by calling VP8BitCost().
  64754 var VP8FixedCostsUV = [4]uint16_t{
  64755 	0: uint16(302),
  64756 	1: uint16(984),
  64757 	2: uint16(439),
  64758 	3: uint16(642),
  64759 }
  64760 
  64761 var VP8GetCPUInfo VP8CPUInfo
  64762 
  64763 //------------------------------------------------------------------------------
  64764 // init function
  64765 
  64766 var VP8GetResidualCost VP8GetResidualCostFunc
  64767 
  64768 var VP8HFilter16 VP8LumaFilterFunc
  64769 
  64770 var VP8HFilter16i VP8LumaFilterFunc
  64771 
  64772 var VP8HFilter8 VP8ChromaFilterFunc
  64773 
  64774 var VP8HFilter8i VP8ChromaFilterFunc
  64775 
  64776 //------------------------------------------------------------------------------
  64777 // Form the predictions in cache
  64778 
  64779 // C documentation
  64780 //
  64781 //	// Must be ordered using {DC_PRED, TM_PRED, V_PRED, H_PRED} as index
  64782 var VP8I16ModeOffsets = [4]uint16_t{
  64783 	1: libc.Uint16FromInt32(libc.Int32FromInt32(0)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64784 	2: libc.Uint16FromInt32(libc.Int32FromInt32(1) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  64785 	3: libc.Uint16FromInt32(libc.Int32FromInt32(1)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(16)),
  64786 }
  64787 
  64788 var VP8ITransform VP8Idct
  64789 
  64790 //------------------------------------------------------------------------------
  64791 
  64792 var VP8LAddGreenToBlueAndRed VP8LProcessDecBlueAndRedFunc
  64793 
  64794 var VP8LAddGreenToBlueAndRed_SSE VP8LProcessDecBlueAndRedFunc
  64795 
  64796 var VP8LAddVector VP8LAddVectorFunc
  64797 
  64798 var VP8LAddVectorEq VP8LAddVectorEqFunc
  64799 
  64800 var VP8LBundleColorMap VP8LBundleColorMapFunc
  64801 
  64802 var VP8LBundleColorMap_SSE VP8LBundleColorMapFunc
  64803 
  64804 var VP8LCollectColorBlueTransforms VP8LCollectColorBlueTransformsFunc
  64805 
  64806 var VP8LCollectColorBlueTransforms_SSE VP8LCollectColorBlueTransformsFunc
  64807 
  64808 var VP8LCollectColorRedTransforms VP8LCollectColorRedTransformsFunc
  64809 
  64810 var VP8LCollectColorRedTransforms_SSE VP8LCollectColorRedTransformsFunc
  64811 
  64812 var VP8LCombinedShannonEntropy VP8LCombinedShannonEntropyFunc
  64813 
  64814 var VP8LConvertBGRAToBGR VP8LConvertFunc
  64815 
  64816 var VP8LConvertBGRAToRGB VP8LConvertFunc
  64817 
  64818 var VP8LConvertBGRAToRGB565 VP8LConvertFunc
  64819 
  64820 var VP8LConvertBGRAToRGBA VP8LConvertFunc
  64821 
  64822 var VP8LConvertBGRAToRGBA4444 VP8LConvertFunc
  64823 
  64824 var VP8LConvertBGRAToRGBA_SSE VP8LConvertFunc
  64825 
  64826 var VP8LConvertBGRAToRGB_SSE VP8LConvertFunc
  64827 
  64828 var VP8LExtraCost VP8LCostFunc
  64829 
  64830 var VP8LFastLog2Slow VP8LFastLog2SlowFunc
  64831 
  64832 var VP8LFastSLog2Slow VP8LFastSLog2SlowFunc
  64833 
  64834 var VP8LGetCombinedEntropyUnrefined VP8LGetCombinedEntropyUnrefinedFunc
  64835 
  64836 var VP8LGetEntropyUnrefined VP8LGetEntropyUnrefinedFunc
  64837 
  64838 var VP8LMapColor32b VP8LMapARGBFunc
  64839 
  64840 var VP8LMapColor8b VP8LMapAlphaFunc
  64841 
  64842 var VP8LPredictors [16]VP8LPredictorFunc
  64843 
  64844 var VP8LPredictorsAdd [16]VP8LPredictorAddSubFunc
  64845 
  64846 // C documentation
  64847 //
  64848 //	// exposed plain-C implementations
  64849 var VP8LPredictorsAdd_C [16]VP8LPredictorAddSubFunc
  64850 
  64851 var VP8LPredictorsAdd_SSE [16]VP8LPredictorAddSubFunc
  64852 
  64853 var VP8LPredictorsSub [16]VP8LPredictorAddSubFunc
  64854 
  64855 var VP8LPredictorsSub_C [16]VP8LPredictorAddSubFunc
  64856 
  64857 var VP8LPredictorsSub_SSE [16]VP8LPredictorAddSubFunc
  64858 
  64859 var VP8LShannonEntropy VP8LShannonEntropyFunc
  64860 
  64861 //------------------------------------------------------------------------------
  64862 
  64863 var VP8LSubtractGreenFromBlueAndRed VP8LProcessEncBlueAndRedFunc
  64864 
  64865 var VP8LSubtractGreenFromBlueAndRed_SSE VP8LProcessEncBlueAndRedFunc
  64866 
  64867 var VP8LTransformColor VP8LTransformColorFunc
  64868 
  64869 var VP8LTransformColorInverse VP8LTransformColorInverseFunc
  64870 
  64871 var VP8LTransformColorInverse_SSE VP8LTransformColorInverseFunc
  64872 
  64873 var VP8LTransformColor_SSE VP8LTransformColorFunc
  64874 
  64875 var VP8LVectorMismatch VP8LVectorMismatchFunc
  64876 
  64877 //------------------------------------------------------------------------------
  64878 // Level cost tables
  64879 
  64880 // C documentation
  64881 //
  64882 //	// fixed costs for coding levels, deduce from the coding tree.
  64883 //	// This is only the part that doesn't depend on the probability state.
  64884 var VP8LevelFixedCosts = [2048]uint16_t{
  64885 	1:    uint16(256),
  64886 	2:    uint16(256),
  64887 	3:    uint16(256),
  64888 	4:    uint16(256),
  64889 	5:    uint16(432),
  64890 	6:    uint16(618),
  64891 	7:    uint16(630),
  64892 	8:    uint16(731),
  64893 	9:    uint16(640),
  64894 	10:   uint16(640),
  64895 	11:   uint16(828),
  64896 	12:   uint16(901),
  64897 	13:   uint16(948),
  64898 	14:   uint16(1021),
  64899 	15:   uint16(1101),
  64900 	16:   uint16(1174),
  64901 	17:   uint16(1221),
  64902 	18:   uint16(1294),
  64903 	19:   uint16(1042),
  64904 	20:   uint16(1085),
  64905 	21:   uint16(1115),
  64906 	22:   uint16(1158),
  64907 	23:   uint16(1202),
  64908 	24:   uint16(1245),
  64909 	25:   uint16(1275),
  64910 	26:   uint16(1318),
  64911 	27:   uint16(1337),
  64912 	28:   uint16(1380),
  64913 	29:   uint16(1410),
  64914 	30:   uint16(1453),
  64915 	31:   uint16(1497),
  64916 	32:   uint16(1540),
  64917 	33:   uint16(1570),
  64918 	34:   uint16(1613),
  64919 	35:   uint16(1280),
  64920 	36:   uint16(1295),
  64921 	37:   uint16(1317),
  64922 	38:   uint16(1332),
  64923 	39:   uint16(1358),
  64924 	40:   uint16(1373),
  64925 	41:   uint16(1395),
  64926 	42:   uint16(1410),
  64927 	43:   uint16(1454),
  64928 	44:   uint16(1469),
  64929 	45:   uint16(1491),
  64930 	46:   uint16(1506),
  64931 	47:   uint16(1532),
  64932 	48:   uint16(1547),
  64933 	49:   uint16(1569),
  64934 	50:   uint16(1584),
  64935 	51:   uint16(1601),
  64936 	52:   uint16(1616),
  64937 	53:   uint16(1638),
  64938 	54:   uint16(1653),
  64939 	55:   uint16(1679),
  64940 	56:   uint16(1694),
  64941 	57:   uint16(1716),
  64942 	58:   uint16(1731),
  64943 	59:   uint16(1775),
  64944 	60:   uint16(1790),
  64945 	61:   uint16(1812),
  64946 	62:   uint16(1827),
  64947 	63:   uint16(1853),
  64948 	64:   uint16(1868),
  64949 	65:   uint16(1890),
  64950 	66:   uint16(1905),
  64951 	67:   uint16(1727),
  64952 	68:   uint16(1733),
  64953 	69:   uint16(1742),
  64954 	70:   uint16(1748),
  64955 	71:   uint16(1759),
  64956 	72:   uint16(1765),
  64957 	73:   uint16(1774),
  64958 	74:   uint16(1780),
  64959 	75:   uint16(1800),
  64960 	76:   uint16(1806),
  64961 	77:   uint16(1815),
  64962 	78:   uint16(1821),
  64963 	79:   uint16(1832),
  64964 	80:   uint16(1838),
  64965 	81:   uint16(1847),
  64966 	82:   uint16(1853),
  64967 	83:   uint16(1878),
  64968 	84:   uint16(1884),
  64969 	85:   uint16(1893),
  64970 	86:   uint16(1899),
  64971 	87:   uint16(1910),
  64972 	88:   uint16(1916),
  64973 	89:   uint16(1925),
  64974 	90:   uint16(1931),
  64975 	91:   uint16(1951),
  64976 	92:   uint16(1957),
  64977 	93:   uint16(1966),
  64978 	94:   uint16(1972),
  64979 	95:   uint16(1983),
  64980 	96:   uint16(1989),
  64981 	97:   uint16(1998),
  64982 	98:   uint16(2004),
  64983 	99:   uint16(2027),
  64984 	100:  uint16(2033),
  64985 	101:  uint16(2042),
  64986 	102:  uint16(2048),
  64987 	103:  uint16(2059),
  64988 	104:  uint16(2065),
  64989 	105:  uint16(2074),
  64990 	106:  uint16(2080),
  64991 	107:  uint16(2100),
  64992 	108:  uint16(2106),
  64993 	109:  uint16(2115),
  64994 	110:  uint16(2121),
  64995 	111:  uint16(2132),
  64996 	112:  uint16(2138),
  64997 	113:  uint16(2147),
  64998 	114:  uint16(2153),
  64999 	115:  uint16(2178),
  65000 	116:  uint16(2184),
  65001 	117:  uint16(2193),
  65002 	118:  uint16(2199),
  65003 	119:  uint16(2210),
  65004 	120:  uint16(2216),
  65005 	121:  uint16(2225),
  65006 	122:  uint16(2231),
  65007 	123:  uint16(2251),
  65008 	124:  uint16(2257),
  65009 	125:  uint16(2266),
  65010 	126:  uint16(2272),
  65011 	127:  uint16(2283),
  65012 	128:  uint16(2289),
  65013 	129:  uint16(2298),
  65014 	130:  uint16(2304),
  65015 	131:  uint16(2168),
  65016 	132:  uint16(2174),
  65017 	133:  uint16(2183),
  65018 	134:  uint16(2189),
  65019 	135:  uint16(2200),
  65020 	136:  uint16(2206),
  65021 	137:  uint16(2215),
  65022 	138:  uint16(2221),
  65023 	139:  uint16(2241),
  65024 	140:  uint16(2247),
  65025 	141:  uint16(2256),
  65026 	142:  uint16(2262),
  65027 	143:  uint16(2273),
  65028 	144:  uint16(2279),
  65029 	145:  uint16(2288),
  65030 	146:  uint16(2294),
  65031 	147:  uint16(2319),
  65032 	148:  uint16(2325),
  65033 	149:  uint16(2334),
  65034 	150:  uint16(2340),
  65035 	151:  uint16(2351),
  65036 	152:  uint16(2357),
  65037 	153:  uint16(2366),
  65038 	154:  uint16(2372),
  65039 	155:  uint16(2392),
  65040 	156:  uint16(2398),
  65041 	157:  uint16(2407),
  65042 	158:  uint16(2413),
  65043 	159:  uint16(2424),
  65044 	160:  uint16(2430),
  65045 	161:  uint16(2439),
  65046 	162:  uint16(2445),
  65047 	163:  uint16(2468),
  65048 	164:  uint16(2474),
  65049 	165:  uint16(2483),
  65050 	166:  uint16(2489),
  65051 	167:  uint16(2500),
  65052 	168:  uint16(2506),
  65053 	169:  uint16(2515),
  65054 	170:  uint16(2521),
  65055 	171:  uint16(2541),
  65056 	172:  uint16(2547),
  65057 	173:  uint16(2556),
  65058 	174:  uint16(2562),
  65059 	175:  uint16(2573),
  65060 	176:  uint16(2579),
  65061 	177:  uint16(2588),
  65062 	178:  uint16(2594),
  65063 	179:  uint16(2619),
  65064 	180:  uint16(2625),
  65065 	181:  uint16(2634),
  65066 	182:  uint16(2640),
  65067 	183:  uint16(2651),
  65068 	184:  uint16(2657),
  65069 	185:  uint16(2666),
  65070 	186:  uint16(2672),
  65071 	187:  uint16(2692),
  65072 	188:  uint16(2698),
  65073 	189:  uint16(2707),
  65074 	190:  uint16(2713),
  65075 	191:  uint16(2724),
  65076 	192:  uint16(2730),
  65077 	193:  uint16(2739),
  65078 	194:  uint16(2745),
  65079 	195:  uint16(2540),
  65080 	196:  uint16(2546),
  65081 	197:  uint16(2555),
  65082 	198:  uint16(2561),
  65083 	199:  uint16(2572),
  65084 	200:  uint16(2578),
  65085 	201:  uint16(2587),
  65086 	202:  uint16(2593),
  65087 	203:  uint16(2613),
  65088 	204:  uint16(2619),
  65089 	205:  uint16(2628),
  65090 	206:  uint16(2634),
  65091 	207:  uint16(2645),
  65092 	208:  uint16(2651),
  65093 	209:  uint16(2660),
  65094 	210:  uint16(2666),
  65095 	211:  uint16(2691),
  65096 	212:  uint16(2697),
  65097 	213:  uint16(2706),
  65098 	214:  uint16(2712),
  65099 	215:  uint16(2723),
  65100 	216:  uint16(2729),
  65101 	217:  uint16(2738),
  65102 	218:  uint16(2744),
  65103 	219:  uint16(2764),
  65104 	220:  uint16(2770),
  65105 	221:  uint16(2779),
  65106 	222:  uint16(2785),
  65107 	223:  uint16(2796),
  65108 	224:  uint16(2802),
  65109 	225:  uint16(2811),
  65110 	226:  uint16(2817),
  65111 	227:  uint16(2840),
  65112 	228:  uint16(2846),
  65113 	229:  uint16(2855),
  65114 	230:  uint16(2861),
  65115 	231:  uint16(2872),
  65116 	232:  uint16(2878),
  65117 	233:  uint16(2887),
  65118 	234:  uint16(2893),
  65119 	235:  uint16(2913),
  65120 	236:  uint16(2919),
  65121 	237:  uint16(2928),
  65122 	238:  uint16(2934),
  65123 	239:  uint16(2945),
  65124 	240:  uint16(2951),
  65125 	241:  uint16(2960),
  65126 	242:  uint16(2966),
  65127 	243:  uint16(2991),
  65128 	244:  uint16(2997),
  65129 	245:  uint16(3006),
  65130 	246:  uint16(3012),
  65131 	247:  uint16(3023),
  65132 	248:  uint16(3029),
  65133 	249:  uint16(3038),
  65134 	250:  uint16(3044),
  65135 	251:  uint16(3064),
  65136 	252:  uint16(3070),
  65137 	253:  uint16(3079),
  65138 	254:  uint16(3085),
  65139 	255:  uint16(3096),
  65140 	256:  uint16(3102),
  65141 	257:  uint16(3111),
  65142 	258:  uint16(3117),
  65143 	259:  uint16(2981),
  65144 	260:  uint16(2987),
  65145 	261:  uint16(2996),
  65146 	262:  uint16(3002),
  65147 	263:  uint16(3013),
  65148 	264:  uint16(3019),
  65149 	265:  uint16(3028),
  65150 	266:  uint16(3034),
  65151 	267:  uint16(3054),
  65152 	268:  uint16(3060),
  65153 	269:  uint16(3069),
  65154 	270:  uint16(3075),
  65155 	271:  uint16(3086),
  65156 	272:  uint16(3092),
  65157 	273:  uint16(3101),
  65158 	274:  uint16(3107),
  65159 	275:  uint16(3132),
  65160 	276:  uint16(3138),
  65161 	277:  uint16(3147),
  65162 	278:  uint16(3153),
  65163 	279:  uint16(3164),
  65164 	280:  uint16(3170),
  65165 	281:  uint16(3179),
  65166 	282:  uint16(3185),
  65167 	283:  uint16(3205),
  65168 	284:  uint16(3211),
  65169 	285:  uint16(3220),
  65170 	286:  uint16(3226),
  65171 	287:  uint16(3237),
  65172 	288:  uint16(3243),
  65173 	289:  uint16(3252),
  65174 	290:  uint16(3258),
  65175 	291:  uint16(3281),
  65176 	292:  uint16(3287),
  65177 	293:  uint16(3296),
  65178 	294:  uint16(3302),
  65179 	295:  uint16(3313),
  65180 	296:  uint16(3319),
  65181 	297:  uint16(3328),
  65182 	298:  uint16(3334),
  65183 	299:  uint16(3354),
  65184 	300:  uint16(3360),
  65185 	301:  uint16(3369),
  65186 	302:  uint16(3375),
  65187 	303:  uint16(3386),
  65188 	304:  uint16(3392),
  65189 	305:  uint16(3401),
  65190 	306:  uint16(3407),
  65191 	307:  uint16(3432),
  65192 	308:  uint16(3438),
  65193 	309:  uint16(3447),
  65194 	310:  uint16(3453),
  65195 	311:  uint16(3464),
  65196 	312:  uint16(3470),
  65197 	313:  uint16(3479),
  65198 	314:  uint16(3485),
  65199 	315:  uint16(3505),
  65200 	316:  uint16(3511),
  65201 	317:  uint16(3520),
  65202 	318:  uint16(3526),
  65203 	319:  uint16(3537),
  65204 	320:  uint16(3543),
  65205 	321:  uint16(3552),
  65206 	322:  uint16(3558),
  65207 	323:  uint16(2816),
  65208 	324:  uint16(2822),
  65209 	325:  uint16(2831),
  65210 	326:  uint16(2837),
  65211 	327:  uint16(2848),
  65212 	328:  uint16(2854),
  65213 	329:  uint16(2863),
  65214 	330:  uint16(2869),
  65215 	331:  uint16(2889),
  65216 	332:  uint16(2895),
  65217 	333:  uint16(2904),
  65218 	334:  uint16(2910),
  65219 	335:  uint16(2921),
  65220 	336:  uint16(2927),
  65221 	337:  uint16(2936),
  65222 	338:  uint16(2942),
  65223 	339:  uint16(2967),
  65224 	340:  uint16(2973),
  65225 	341:  uint16(2982),
  65226 	342:  uint16(2988),
  65227 	343:  uint16(2999),
  65228 	344:  uint16(3005),
  65229 	345:  uint16(3014),
  65230 	346:  uint16(3020),
  65231 	347:  uint16(3040),
  65232 	348:  uint16(3046),
  65233 	349:  uint16(3055),
  65234 	350:  uint16(3061),
  65235 	351:  uint16(3072),
  65236 	352:  uint16(3078),
  65237 	353:  uint16(3087),
  65238 	354:  uint16(3093),
  65239 	355:  uint16(3116),
  65240 	356:  uint16(3122),
  65241 	357:  uint16(3131),
  65242 	358:  uint16(3137),
  65243 	359:  uint16(3148),
  65244 	360:  uint16(3154),
  65245 	361:  uint16(3163),
  65246 	362:  uint16(3169),
  65247 	363:  uint16(3189),
  65248 	364:  uint16(3195),
  65249 	365:  uint16(3204),
  65250 	366:  uint16(3210),
  65251 	367:  uint16(3221),
  65252 	368:  uint16(3227),
  65253 	369:  uint16(3236),
  65254 	370:  uint16(3242),
  65255 	371:  uint16(3267),
  65256 	372:  uint16(3273),
  65257 	373:  uint16(3282),
  65258 	374:  uint16(3288),
  65259 	375:  uint16(3299),
  65260 	376:  uint16(3305),
  65261 	377:  uint16(3314),
  65262 	378:  uint16(3320),
  65263 	379:  uint16(3340),
  65264 	380:  uint16(3346),
  65265 	381:  uint16(3355),
  65266 	382:  uint16(3361),
  65267 	383:  uint16(3372),
  65268 	384:  uint16(3378),
  65269 	385:  uint16(3387),
  65270 	386:  uint16(3393),
  65271 	387:  uint16(3257),
  65272 	388:  uint16(3263),
  65273 	389:  uint16(3272),
  65274 	390:  uint16(3278),
  65275 	391:  uint16(3289),
  65276 	392:  uint16(3295),
  65277 	393:  uint16(3304),
  65278 	394:  uint16(3310),
  65279 	395:  uint16(3330),
  65280 	396:  uint16(3336),
  65281 	397:  uint16(3345),
  65282 	398:  uint16(3351),
  65283 	399:  uint16(3362),
  65284 	400:  uint16(3368),
  65285 	401:  uint16(3377),
  65286 	402:  uint16(3383),
  65287 	403:  uint16(3408),
  65288 	404:  uint16(3414),
  65289 	405:  uint16(3423),
  65290 	406:  uint16(3429),
  65291 	407:  uint16(3440),
  65292 	408:  uint16(3446),
  65293 	409:  uint16(3455),
  65294 	410:  uint16(3461),
  65295 	411:  uint16(3481),
  65296 	412:  uint16(3487),
  65297 	413:  uint16(3496),
  65298 	414:  uint16(3502),
  65299 	415:  uint16(3513),
  65300 	416:  uint16(3519),
  65301 	417:  uint16(3528),
  65302 	418:  uint16(3534),
  65303 	419:  uint16(3557),
  65304 	420:  uint16(3563),
  65305 	421:  uint16(3572),
  65306 	422:  uint16(3578),
  65307 	423:  uint16(3589),
  65308 	424:  uint16(3595),
  65309 	425:  uint16(3604),
  65310 	426:  uint16(3610),
  65311 	427:  uint16(3630),
  65312 	428:  uint16(3636),
  65313 	429:  uint16(3645),
  65314 	430:  uint16(3651),
  65315 	431:  uint16(3662),
  65316 	432:  uint16(3668),
  65317 	433:  uint16(3677),
  65318 	434:  uint16(3683),
  65319 	435:  uint16(3708),
  65320 	436:  uint16(3714),
  65321 	437:  uint16(3723),
  65322 	438:  uint16(3729),
  65323 	439:  uint16(3740),
  65324 	440:  uint16(3746),
  65325 	441:  uint16(3755),
  65326 	442:  uint16(3761),
  65327 	443:  uint16(3781),
  65328 	444:  uint16(3787),
  65329 	445:  uint16(3796),
  65330 	446:  uint16(3802),
  65331 	447:  uint16(3813),
  65332 	448:  uint16(3819),
  65333 	449:  uint16(3828),
  65334 	450:  uint16(3834),
  65335 	451:  uint16(3629),
  65336 	452:  uint16(3635),
  65337 	453:  uint16(3644),
  65338 	454:  uint16(3650),
  65339 	455:  uint16(3661),
  65340 	456:  uint16(3667),
  65341 	457:  uint16(3676),
  65342 	458:  uint16(3682),
  65343 	459:  uint16(3702),
  65344 	460:  uint16(3708),
  65345 	461:  uint16(3717),
  65346 	462:  uint16(3723),
  65347 	463:  uint16(3734),
  65348 	464:  uint16(3740),
  65349 	465:  uint16(3749),
  65350 	466:  uint16(3755),
  65351 	467:  uint16(3780),
  65352 	468:  uint16(3786),
  65353 	469:  uint16(3795),
  65354 	470:  uint16(3801),
  65355 	471:  uint16(3812),
  65356 	472:  uint16(3818),
  65357 	473:  uint16(3827),
  65358 	474:  uint16(3833),
  65359 	475:  uint16(3853),
  65360 	476:  uint16(3859),
  65361 	477:  uint16(3868),
  65362 	478:  uint16(3874),
  65363 	479:  uint16(3885),
  65364 	480:  uint16(3891),
  65365 	481:  uint16(3900),
  65366 	482:  uint16(3906),
  65367 	483:  uint16(3929),
  65368 	484:  uint16(3935),
  65369 	485:  uint16(3944),
  65370 	486:  uint16(3950),
  65371 	487:  uint16(3961),
  65372 	488:  uint16(3967),
  65373 	489:  uint16(3976),
  65374 	490:  uint16(3982),
  65375 	491:  uint16(4002),
  65376 	492:  uint16(4008),
  65377 	493:  uint16(4017),
  65378 	494:  uint16(4023),
  65379 	495:  uint16(4034),
  65380 	496:  uint16(4040),
  65381 	497:  uint16(4049),
  65382 	498:  uint16(4055),
  65383 	499:  uint16(4080),
  65384 	500:  uint16(4086),
  65385 	501:  uint16(4095),
  65386 	502:  uint16(4101),
  65387 	503:  uint16(4112),
  65388 	504:  uint16(4118),
  65389 	505:  uint16(4127),
  65390 	506:  uint16(4133),
  65391 	507:  uint16(4153),
  65392 	508:  uint16(4159),
  65393 	509:  uint16(4168),
  65394 	510:  uint16(4174),
  65395 	511:  uint16(4185),
  65396 	512:  uint16(4191),
  65397 	513:  uint16(4200),
  65398 	514:  uint16(4206),
  65399 	515:  uint16(4070),
  65400 	516:  uint16(4076),
  65401 	517:  uint16(4085),
  65402 	518:  uint16(4091),
  65403 	519:  uint16(4102),
  65404 	520:  uint16(4108),
  65405 	521:  uint16(4117),
  65406 	522:  uint16(4123),
  65407 	523:  uint16(4143),
  65408 	524:  uint16(4149),
  65409 	525:  uint16(4158),
  65410 	526:  uint16(4164),
  65411 	527:  uint16(4175),
  65412 	528:  uint16(4181),
  65413 	529:  uint16(4190),
  65414 	530:  uint16(4196),
  65415 	531:  uint16(4221),
  65416 	532:  uint16(4227),
  65417 	533:  uint16(4236),
  65418 	534:  uint16(4242),
  65419 	535:  uint16(4253),
  65420 	536:  uint16(4259),
  65421 	537:  uint16(4268),
  65422 	538:  uint16(4274),
  65423 	539:  uint16(4294),
  65424 	540:  uint16(4300),
  65425 	541:  uint16(4309),
  65426 	542:  uint16(4315),
  65427 	543:  uint16(4326),
  65428 	544:  uint16(4332),
  65429 	545:  uint16(4341),
  65430 	546:  uint16(4347),
  65431 	547:  uint16(4370),
  65432 	548:  uint16(4376),
  65433 	549:  uint16(4385),
  65434 	550:  uint16(4391),
  65435 	551:  uint16(4402),
  65436 	552:  uint16(4408),
  65437 	553:  uint16(4417),
  65438 	554:  uint16(4423),
  65439 	555:  uint16(4443),
  65440 	556:  uint16(4449),
  65441 	557:  uint16(4458),
  65442 	558:  uint16(4464),
  65443 	559:  uint16(4475),
  65444 	560:  uint16(4481),
  65445 	561:  uint16(4490),
  65446 	562:  uint16(4496),
  65447 	563:  uint16(4521),
  65448 	564:  uint16(4527),
  65449 	565:  uint16(4536),
  65450 	566:  uint16(4542),
  65451 	567:  uint16(4553),
  65452 	568:  uint16(4559),
  65453 	569:  uint16(4568),
  65454 	570:  uint16(4574),
  65455 	571:  uint16(4594),
  65456 	572:  uint16(4600),
  65457 	573:  uint16(4609),
  65458 	574:  uint16(4615),
  65459 	575:  uint16(4626),
  65460 	576:  uint16(4632),
  65461 	577:  uint16(4641),
  65462 	578:  uint16(4647),
  65463 	579:  uint16(3515),
  65464 	580:  uint16(3521),
  65465 	581:  uint16(3530),
  65466 	582:  uint16(3536),
  65467 	583:  uint16(3547),
  65468 	584:  uint16(3553),
  65469 	585:  uint16(3562),
  65470 	586:  uint16(3568),
  65471 	587:  uint16(3588),
  65472 	588:  uint16(3594),
  65473 	589:  uint16(3603),
  65474 	590:  uint16(3609),
  65475 	591:  uint16(3620),
  65476 	592:  uint16(3626),
  65477 	593:  uint16(3635),
  65478 	594:  uint16(3641),
  65479 	595:  uint16(3666),
  65480 	596:  uint16(3672),
  65481 	597:  uint16(3681),
  65482 	598:  uint16(3687),
  65483 	599:  uint16(3698),
  65484 	600:  uint16(3704),
  65485 	601:  uint16(3713),
  65486 	602:  uint16(3719),
  65487 	603:  uint16(3739),
  65488 	604:  uint16(3745),
  65489 	605:  uint16(3754),
  65490 	606:  uint16(3760),
  65491 	607:  uint16(3771),
  65492 	608:  uint16(3777),
  65493 	609:  uint16(3786),
  65494 	610:  uint16(3792),
  65495 	611:  uint16(3815),
  65496 	612:  uint16(3821),
  65497 	613:  uint16(3830),
  65498 	614:  uint16(3836),
  65499 	615:  uint16(3847),
  65500 	616:  uint16(3853),
  65501 	617:  uint16(3862),
  65502 	618:  uint16(3868),
  65503 	619:  uint16(3888),
  65504 	620:  uint16(3894),
  65505 	621:  uint16(3903),
  65506 	622:  uint16(3909),
  65507 	623:  uint16(3920),
  65508 	624:  uint16(3926),
  65509 	625:  uint16(3935),
  65510 	626:  uint16(3941),
  65511 	627:  uint16(3966),
  65512 	628:  uint16(3972),
  65513 	629:  uint16(3981),
  65514 	630:  uint16(3987),
  65515 	631:  uint16(3998),
  65516 	632:  uint16(4004),
  65517 	633:  uint16(4013),
  65518 	634:  uint16(4019),
  65519 	635:  uint16(4039),
  65520 	636:  uint16(4045),
  65521 	637:  uint16(4054),
  65522 	638:  uint16(4060),
  65523 	639:  uint16(4071),
  65524 	640:  uint16(4077),
  65525 	641:  uint16(4086),
  65526 	642:  uint16(4092),
  65527 	643:  uint16(3956),
  65528 	644:  uint16(3962),
  65529 	645:  uint16(3971),
  65530 	646:  uint16(3977),
  65531 	647:  uint16(3988),
  65532 	648:  uint16(3994),
  65533 	649:  uint16(4003),
  65534 	650:  uint16(4009),
  65535 	651:  uint16(4029),
  65536 	652:  uint16(4035),
  65537 	653:  uint16(4044),
  65538 	654:  uint16(4050),
  65539 	655:  uint16(4061),
  65540 	656:  uint16(4067),
  65541 	657:  uint16(4076),
  65542 	658:  uint16(4082),
  65543 	659:  uint16(4107),
  65544 	660:  uint16(4113),
  65545 	661:  uint16(4122),
  65546 	662:  uint16(4128),
  65547 	663:  uint16(4139),
  65548 	664:  uint16(4145),
  65549 	665:  uint16(4154),
  65550 	666:  uint16(4160),
  65551 	667:  uint16(4180),
  65552 	668:  uint16(4186),
  65553 	669:  uint16(4195),
  65554 	670:  uint16(4201),
  65555 	671:  uint16(4212),
  65556 	672:  uint16(4218),
  65557 	673:  uint16(4227),
  65558 	674:  uint16(4233),
  65559 	675:  uint16(4256),
  65560 	676:  uint16(4262),
  65561 	677:  uint16(4271),
  65562 	678:  uint16(4277),
  65563 	679:  uint16(4288),
  65564 	680:  uint16(4294),
  65565 	681:  uint16(4303),
  65566 	682:  uint16(4309),
  65567 	683:  uint16(4329),
  65568 	684:  uint16(4335),
  65569 	685:  uint16(4344),
  65570 	686:  uint16(4350),
  65571 	687:  uint16(4361),
  65572 	688:  uint16(4367),
  65573 	689:  uint16(4376),
  65574 	690:  uint16(4382),
  65575 	691:  uint16(4407),
  65576 	692:  uint16(4413),
  65577 	693:  uint16(4422),
  65578 	694:  uint16(4428),
  65579 	695:  uint16(4439),
  65580 	696:  uint16(4445),
  65581 	697:  uint16(4454),
  65582 	698:  uint16(4460),
  65583 	699:  uint16(4480),
  65584 	700:  uint16(4486),
  65585 	701:  uint16(4495),
  65586 	702:  uint16(4501),
  65587 	703:  uint16(4512),
  65588 	704:  uint16(4518),
  65589 	705:  uint16(4527),
  65590 	706:  uint16(4533),
  65591 	707:  uint16(4328),
  65592 	708:  uint16(4334),
  65593 	709:  uint16(4343),
  65594 	710:  uint16(4349),
  65595 	711:  uint16(4360),
  65596 	712:  uint16(4366),
  65597 	713:  uint16(4375),
  65598 	714:  uint16(4381),
  65599 	715:  uint16(4401),
  65600 	716:  uint16(4407),
  65601 	717:  uint16(4416),
  65602 	718:  uint16(4422),
  65603 	719:  uint16(4433),
  65604 	720:  uint16(4439),
  65605 	721:  uint16(4448),
  65606 	722:  uint16(4454),
  65607 	723:  uint16(4479),
  65608 	724:  uint16(4485),
  65609 	725:  uint16(4494),
  65610 	726:  uint16(4500),
  65611 	727:  uint16(4511),
  65612 	728:  uint16(4517),
  65613 	729:  uint16(4526),
  65614 	730:  uint16(4532),
  65615 	731:  uint16(4552),
  65616 	732:  uint16(4558),
  65617 	733:  uint16(4567),
  65618 	734:  uint16(4573),
  65619 	735:  uint16(4584),
  65620 	736:  uint16(4590),
  65621 	737:  uint16(4599),
  65622 	738:  uint16(4605),
  65623 	739:  uint16(4628),
  65624 	740:  uint16(4634),
  65625 	741:  uint16(4643),
  65626 	742:  uint16(4649),
  65627 	743:  uint16(4660),
  65628 	744:  uint16(4666),
  65629 	745:  uint16(4675),
  65630 	746:  uint16(4681),
  65631 	747:  uint16(4701),
  65632 	748:  uint16(4707),
  65633 	749:  uint16(4716),
  65634 	750:  uint16(4722),
  65635 	751:  uint16(4733),
  65636 	752:  uint16(4739),
  65637 	753:  uint16(4748),
  65638 	754:  uint16(4754),
  65639 	755:  uint16(4779),
  65640 	756:  uint16(4785),
  65641 	757:  uint16(4794),
  65642 	758:  uint16(4800),
  65643 	759:  uint16(4811),
  65644 	760:  uint16(4817),
  65645 	761:  uint16(4826),
  65646 	762:  uint16(4832),
  65647 	763:  uint16(4852),
  65648 	764:  uint16(4858),
  65649 	765:  uint16(4867),
  65650 	766:  uint16(4873),
  65651 	767:  uint16(4884),
  65652 	768:  uint16(4890),
  65653 	769:  uint16(4899),
  65654 	770:  uint16(4905),
  65655 	771:  uint16(4769),
  65656 	772:  uint16(4775),
  65657 	773:  uint16(4784),
  65658 	774:  uint16(4790),
  65659 	775:  uint16(4801),
  65660 	776:  uint16(4807),
  65661 	777:  uint16(4816),
  65662 	778:  uint16(4822),
  65663 	779:  uint16(4842),
  65664 	780:  uint16(4848),
  65665 	781:  uint16(4857),
  65666 	782:  uint16(4863),
  65667 	783:  uint16(4874),
  65668 	784:  uint16(4880),
  65669 	785:  uint16(4889),
  65670 	786:  uint16(4895),
  65671 	787:  uint16(4920),
  65672 	788:  uint16(4926),
  65673 	789:  uint16(4935),
  65674 	790:  uint16(4941),
  65675 	791:  uint16(4952),
  65676 	792:  uint16(4958),
  65677 	793:  uint16(4967),
  65678 	794:  uint16(4973),
  65679 	795:  uint16(4993),
  65680 	796:  uint16(4999),
  65681 	797:  uint16(5008),
  65682 	798:  uint16(5014),
  65683 	799:  uint16(5025),
  65684 	800:  uint16(5031),
  65685 	801:  uint16(5040),
  65686 	802:  uint16(5046),
  65687 	803:  uint16(5069),
  65688 	804:  uint16(5075),
  65689 	805:  uint16(5084),
  65690 	806:  uint16(5090),
  65691 	807:  uint16(5101),
  65692 	808:  uint16(5107),
  65693 	809:  uint16(5116),
  65694 	810:  uint16(5122),
  65695 	811:  uint16(5142),
  65696 	812:  uint16(5148),
  65697 	813:  uint16(5157),
  65698 	814:  uint16(5163),
  65699 	815:  uint16(5174),
  65700 	816:  uint16(5180),
  65701 	817:  uint16(5189),
  65702 	818:  uint16(5195),
  65703 	819:  uint16(5220),
  65704 	820:  uint16(5226),
  65705 	821:  uint16(5235),
  65706 	822:  uint16(5241),
  65707 	823:  uint16(5252),
  65708 	824:  uint16(5258),
  65709 	825:  uint16(5267),
  65710 	826:  uint16(5273),
  65711 	827:  uint16(5293),
  65712 	828:  uint16(5299),
  65713 	829:  uint16(5308),
  65714 	830:  uint16(5314),
  65715 	831:  uint16(5325),
  65716 	832:  uint16(5331),
  65717 	833:  uint16(5340),
  65718 	834:  uint16(5346),
  65719 	835:  uint16(4604),
  65720 	836:  uint16(4610),
  65721 	837:  uint16(4619),
  65722 	838:  uint16(4625),
  65723 	839:  uint16(4636),
  65724 	840:  uint16(4642),
  65725 	841:  uint16(4651),
  65726 	842:  uint16(4657),
  65727 	843:  uint16(4677),
  65728 	844:  uint16(4683),
  65729 	845:  uint16(4692),
  65730 	846:  uint16(4698),
  65731 	847:  uint16(4709),
  65732 	848:  uint16(4715),
  65733 	849:  uint16(4724),
  65734 	850:  uint16(4730),
  65735 	851:  uint16(4755),
  65736 	852:  uint16(4761),
  65737 	853:  uint16(4770),
  65738 	854:  uint16(4776),
  65739 	855:  uint16(4787),
  65740 	856:  uint16(4793),
  65741 	857:  uint16(4802),
  65742 	858:  uint16(4808),
  65743 	859:  uint16(4828),
  65744 	860:  uint16(4834),
  65745 	861:  uint16(4843),
  65746 	862:  uint16(4849),
  65747 	863:  uint16(4860),
  65748 	864:  uint16(4866),
  65749 	865:  uint16(4875),
  65750 	866:  uint16(4881),
  65751 	867:  uint16(4904),
  65752 	868:  uint16(4910),
  65753 	869:  uint16(4919),
  65754 	870:  uint16(4925),
  65755 	871:  uint16(4936),
  65756 	872:  uint16(4942),
  65757 	873:  uint16(4951),
  65758 	874:  uint16(4957),
  65759 	875:  uint16(4977),
  65760 	876:  uint16(4983),
  65761 	877:  uint16(4992),
  65762 	878:  uint16(4998),
  65763 	879:  uint16(5009),
  65764 	880:  uint16(5015),
  65765 	881:  uint16(5024),
  65766 	882:  uint16(5030),
  65767 	883:  uint16(5055),
  65768 	884:  uint16(5061),
  65769 	885:  uint16(5070),
  65770 	886:  uint16(5076),
  65771 	887:  uint16(5087),
  65772 	888:  uint16(5093),
  65773 	889:  uint16(5102),
  65774 	890:  uint16(5108),
  65775 	891:  uint16(5128),
  65776 	892:  uint16(5134),
  65777 	893:  uint16(5143),
  65778 	894:  uint16(5149),
  65779 	895:  uint16(5160),
  65780 	896:  uint16(5166),
  65781 	897:  uint16(5175),
  65782 	898:  uint16(5181),
  65783 	899:  uint16(5045),
  65784 	900:  uint16(5051),
  65785 	901:  uint16(5060),
  65786 	902:  uint16(5066),
  65787 	903:  uint16(5077),
  65788 	904:  uint16(5083),
  65789 	905:  uint16(5092),
  65790 	906:  uint16(5098),
  65791 	907:  uint16(5118),
  65792 	908:  uint16(5124),
  65793 	909:  uint16(5133),
  65794 	910:  uint16(5139),
  65795 	911:  uint16(5150),
  65796 	912:  uint16(5156),
  65797 	913:  uint16(5165),
  65798 	914:  uint16(5171),
  65799 	915:  uint16(5196),
  65800 	916:  uint16(5202),
  65801 	917:  uint16(5211),
  65802 	918:  uint16(5217),
  65803 	919:  uint16(5228),
  65804 	920:  uint16(5234),
  65805 	921:  uint16(5243),
  65806 	922:  uint16(5249),
  65807 	923:  uint16(5269),
  65808 	924:  uint16(5275),
  65809 	925:  uint16(5284),
  65810 	926:  uint16(5290),
  65811 	927:  uint16(5301),
  65812 	928:  uint16(5307),
  65813 	929:  uint16(5316),
  65814 	930:  uint16(5322),
  65815 	931:  uint16(5345),
  65816 	932:  uint16(5351),
  65817 	933:  uint16(5360),
  65818 	934:  uint16(5366),
  65819 	935:  uint16(5377),
  65820 	936:  uint16(5383),
  65821 	937:  uint16(5392),
  65822 	938:  uint16(5398),
  65823 	939:  uint16(5418),
  65824 	940:  uint16(5424),
  65825 	941:  uint16(5433),
  65826 	942:  uint16(5439),
  65827 	943:  uint16(5450),
  65828 	944:  uint16(5456),
  65829 	945:  uint16(5465),
  65830 	946:  uint16(5471),
  65831 	947:  uint16(5496),
  65832 	948:  uint16(5502),
  65833 	949:  uint16(5511),
  65834 	950:  uint16(5517),
  65835 	951:  uint16(5528),
  65836 	952:  uint16(5534),
  65837 	953:  uint16(5543),
  65838 	954:  uint16(5549),
  65839 	955:  uint16(5569),
  65840 	956:  uint16(5575),
  65841 	957:  uint16(5584),
  65842 	958:  uint16(5590),
  65843 	959:  uint16(5601),
  65844 	960:  uint16(5607),
  65845 	961:  uint16(5616),
  65846 	962:  uint16(5622),
  65847 	963:  uint16(5417),
  65848 	964:  uint16(5423),
  65849 	965:  uint16(5432),
  65850 	966:  uint16(5438),
  65851 	967:  uint16(5449),
  65852 	968:  uint16(5455),
  65853 	969:  uint16(5464),
  65854 	970:  uint16(5470),
  65855 	971:  uint16(5490),
  65856 	972:  uint16(5496),
  65857 	973:  uint16(5505),
  65858 	974:  uint16(5511),
  65859 	975:  uint16(5522),
  65860 	976:  uint16(5528),
  65861 	977:  uint16(5537),
  65862 	978:  uint16(5543),
  65863 	979:  uint16(5568),
  65864 	980:  uint16(5574),
  65865 	981:  uint16(5583),
  65866 	982:  uint16(5589),
  65867 	983:  uint16(5600),
  65868 	984:  uint16(5606),
  65869 	985:  uint16(5615),
  65870 	986:  uint16(5621),
  65871 	987:  uint16(5641),
  65872 	988:  uint16(5647),
  65873 	989:  uint16(5656),
  65874 	990:  uint16(5662),
  65875 	991:  uint16(5673),
  65876 	992:  uint16(5679),
  65877 	993:  uint16(5688),
  65878 	994:  uint16(5694),
  65879 	995:  uint16(5717),
  65880 	996:  uint16(5723),
  65881 	997:  uint16(5732),
  65882 	998:  uint16(5738),
  65883 	999:  uint16(5749),
  65884 	1000: uint16(5755),
  65885 	1001: uint16(5764),
  65886 	1002: uint16(5770),
  65887 	1003: uint16(5790),
  65888 	1004: uint16(5796),
  65889 	1005: uint16(5805),
  65890 	1006: uint16(5811),
  65891 	1007: uint16(5822),
  65892 	1008: uint16(5828),
  65893 	1009: uint16(5837),
  65894 	1010: uint16(5843),
  65895 	1011: uint16(5868),
  65896 	1012: uint16(5874),
  65897 	1013: uint16(5883),
  65898 	1014: uint16(5889),
  65899 	1015: uint16(5900),
  65900 	1016: uint16(5906),
  65901 	1017: uint16(5915),
  65902 	1018: uint16(5921),
  65903 	1019: uint16(5941),
  65904 	1020: uint16(5947),
  65905 	1021: uint16(5956),
  65906 	1022: uint16(5962),
  65907 	1023: uint16(5973),
  65908 	1024: uint16(5979),
  65909 	1025: uint16(5988),
  65910 	1026: uint16(5994),
  65911 	1027: uint16(5858),
  65912 	1028: uint16(5864),
  65913 	1029: uint16(5873),
  65914 	1030: uint16(5879),
  65915 	1031: uint16(5890),
  65916 	1032: uint16(5896),
  65917 	1033: uint16(5905),
  65918 	1034: uint16(5911),
  65919 	1035: uint16(5931),
  65920 	1036: uint16(5937),
  65921 	1037: uint16(5946),
  65922 	1038: uint16(5952),
  65923 	1039: uint16(5963),
  65924 	1040: uint16(5969),
  65925 	1041: uint16(5978),
  65926 	1042: uint16(5984),
  65927 	1043: uint16(6009),
  65928 	1044: uint16(6015),
  65929 	1045: uint16(6024),
  65930 	1046: uint16(6030),
  65931 	1047: uint16(6041),
  65932 	1048: uint16(6047),
  65933 	1049: uint16(6056),
  65934 	1050: uint16(6062),
  65935 	1051: uint16(6082),
  65936 	1052: uint16(6088),
  65937 	1053: uint16(6097),
  65938 	1054: uint16(6103),
  65939 	1055: uint16(6114),
  65940 	1056: uint16(6120),
  65941 	1057: uint16(6129),
  65942 	1058: uint16(6135),
  65943 	1059: uint16(6158),
  65944 	1060: uint16(6164),
  65945 	1061: uint16(6173),
  65946 	1062: uint16(6179),
  65947 	1063: uint16(6190),
  65948 	1064: uint16(6196),
  65949 	1065: uint16(6205),
  65950 	1066: uint16(6211),
  65951 	1067: uint16(6231),
  65952 	1068: uint16(6237),
  65953 	1069: uint16(6246),
  65954 	1070: uint16(6252),
  65955 	1071: uint16(6263),
  65956 	1072: uint16(6269),
  65957 	1073: uint16(6278),
  65958 	1074: uint16(6284),
  65959 	1075: uint16(6309),
  65960 	1076: uint16(6315),
  65961 	1077: uint16(6324),
  65962 	1078: uint16(6330),
  65963 	1079: uint16(6341),
  65964 	1080: uint16(6347),
  65965 	1081: uint16(6356),
  65966 	1082: uint16(6362),
  65967 	1083: uint16(6382),
  65968 	1084: uint16(6388),
  65969 	1085: uint16(6397),
  65970 	1086: uint16(6403),
  65971 	1087: uint16(6414),
  65972 	1088: uint16(6420),
  65973 	1089: uint16(6429),
  65974 	1090: uint16(6435),
  65975 	1091: uint16(3515),
  65976 	1092: uint16(3521),
  65977 	1093: uint16(3530),
  65978 	1094: uint16(3536),
  65979 	1095: uint16(3547),
  65980 	1096: uint16(3553),
  65981 	1097: uint16(3562),
  65982 	1098: uint16(3568),
  65983 	1099: uint16(3588),
  65984 	1100: uint16(3594),
  65985 	1101: uint16(3603),
  65986 	1102: uint16(3609),
  65987 	1103: uint16(3620),
  65988 	1104: uint16(3626),
  65989 	1105: uint16(3635),
  65990 	1106: uint16(3641),
  65991 	1107: uint16(3666),
  65992 	1108: uint16(3672),
  65993 	1109: uint16(3681),
  65994 	1110: uint16(3687),
  65995 	1111: uint16(3698),
  65996 	1112: uint16(3704),
  65997 	1113: uint16(3713),
  65998 	1114: uint16(3719),
  65999 	1115: uint16(3739),
  66000 	1116: uint16(3745),
  66001 	1117: uint16(3754),
  66002 	1118: uint16(3760),
  66003 	1119: uint16(3771),
  66004 	1120: uint16(3777),
  66005 	1121: uint16(3786),
  66006 	1122: uint16(3792),
  66007 	1123: uint16(3815),
  66008 	1124: uint16(3821),
  66009 	1125: uint16(3830),
  66010 	1126: uint16(3836),
  66011 	1127: uint16(3847),
  66012 	1128: uint16(3853),
  66013 	1129: uint16(3862),
  66014 	1130: uint16(3868),
  66015 	1131: uint16(3888),
  66016 	1132: uint16(3894),
  66017 	1133: uint16(3903),
  66018 	1134: uint16(3909),
  66019 	1135: uint16(3920),
  66020 	1136: uint16(3926),
  66021 	1137: uint16(3935),
  66022 	1138: uint16(3941),
  66023 	1139: uint16(3966),
  66024 	1140: uint16(3972),
  66025 	1141: uint16(3981),
  66026 	1142: uint16(3987),
  66027 	1143: uint16(3998),
  66028 	1144: uint16(4004),
  66029 	1145: uint16(4013),
  66030 	1146: uint16(4019),
  66031 	1147: uint16(4039),
  66032 	1148: uint16(4045),
  66033 	1149: uint16(4054),
  66034 	1150: uint16(4060),
  66035 	1151: uint16(4071),
  66036 	1152: uint16(4077),
  66037 	1153: uint16(4086),
  66038 	1154: uint16(4092),
  66039 	1155: uint16(3956),
  66040 	1156: uint16(3962),
  66041 	1157: uint16(3971),
  66042 	1158: uint16(3977),
  66043 	1159: uint16(3988),
  66044 	1160: uint16(3994),
  66045 	1161: uint16(4003),
  66046 	1162: uint16(4009),
  66047 	1163: uint16(4029),
  66048 	1164: uint16(4035),
  66049 	1165: uint16(4044),
  66050 	1166: uint16(4050),
  66051 	1167: uint16(4061),
  66052 	1168: uint16(4067),
  66053 	1169: uint16(4076),
  66054 	1170: uint16(4082),
  66055 	1171: uint16(4107),
  66056 	1172: uint16(4113),
  66057 	1173: uint16(4122),
  66058 	1174: uint16(4128),
  66059 	1175: uint16(4139),
  66060 	1176: uint16(4145),
  66061 	1177: uint16(4154),
  66062 	1178: uint16(4160),
  66063 	1179: uint16(4180),
  66064 	1180: uint16(4186),
  66065 	1181: uint16(4195),
  66066 	1182: uint16(4201),
  66067 	1183: uint16(4212),
  66068 	1184: uint16(4218),
  66069 	1185: uint16(4227),
  66070 	1186: uint16(4233),
  66071 	1187: uint16(4256),
  66072 	1188: uint16(4262),
  66073 	1189: uint16(4271),
  66074 	1190: uint16(4277),
  66075 	1191: uint16(4288),
  66076 	1192: uint16(4294),
  66077 	1193: uint16(4303),
  66078 	1194: uint16(4309),
  66079 	1195: uint16(4329),
  66080 	1196: uint16(4335),
  66081 	1197: uint16(4344),
  66082 	1198: uint16(4350),
  66083 	1199: uint16(4361),
  66084 	1200: uint16(4367),
  66085 	1201: uint16(4376),
  66086 	1202: uint16(4382),
  66087 	1203: uint16(4407),
  66088 	1204: uint16(4413),
  66089 	1205: uint16(4422),
  66090 	1206: uint16(4428),
  66091 	1207: uint16(4439),
  66092 	1208: uint16(4445),
  66093 	1209: uint16(4454),
  66094 	1210: uint16(4460),
  66095 	1211: uint16(4480),
  66096 	1212: uint16(4486),
  66097 	1213: uint16(4495),
  66098 	1214: uint16(4501),
  66099 	1215: uint16(4512),
  66100 	1216: uint16(4518),
  66101 	1217: uint16(4527),
  66102 	1218: uint16(4533),
  66103 	1219: uint16(4328),
  66104 	1220: uint16(4334),
  66105 	1221: uint16(4343),
  66106 	1222: uint16(4349),
  66107 	1223: uint16(4360),
  66108 	1224: uint16(4366),
  66109 	1225: uint16(4375),
  66110 	1226: uint16(4381),
  66111 	1227: uint16(4401),
  66112 	1228: uint16(4407),
  66113 	1229: uint16(4416),
  66114 	1230: uint16(4422),
  66115 	1231: uint16(4433),
  66116 	1232: uint16(4439),
  66117 	1233: uint16(4448),
  66118 	1234: uint16(4454),
  66119 	1235: uint16(4479),
  66120 	1236: uint16(4485),
  66121 	1237: uint16(4494),
  66122 	1238: uint16(4500),
  66123 	1239: uint16(4511),
  66124 	1240: uint16(4517),
  66125 	1241: uint16(4526),
  66126 	1242: uint16(4532),
  66127 	1243: uint16(4552),
  66128 	1244: uint16(4558),
  66129 	1245: uint16(4567),
  66130 	1246: uint16(4573),
  66131 	1247: uint16(4584),
  66132 	1248: uint16(4590),
  66133 	1249: uint16(4599),
  66134 	1250: uint16(4605),
  66135 	1251: uint16(4628),
  66136 	1252: uint16(4634),
  66137 	1253: uint16(4643),
  66138 	1254: uint16(4649),
  66139 	1255: uint16(4660),
  66140 	1256: uint16(4666),
  66141 	1257: uint16(4675),
  66142 	1258: uint16(4681),
  66143 	1259: uint16(4701),
  66144 	1260: uint16(4707),
  66145 	1261: uint16(4716),
  66146 	1262: uint16(4722),
  66147 	1263: uint16(4733),
  66148 	1264: uint16(4739),
  66149 	1265: uint16(4748),
  66150 	1266: uint16(4754),
  66151 	1267: uint16(4779),
  66152 	1268: uint16(4785),
  66153 	1269: uint16(4794),
  66154 	1270: uint16(4800),
  66155 	1271: uint16(4811),
  66156 	1272: uint16(4817),
  66157 	1273: uint16(4826),
  66158 	1274: uint16(4832),
  66159 	1275: uint16(4852),
  66160 	1276: uint16(4858),
  66161 	1277: uint16(4867),
  66162 	1278: uint16(4873),
  66163 	1279: uint16(4884),
  66164 	1280: uint16(4890),
  66165 	1281: uint16(4899),
  66166 	1282: uint16(4905),
  66167 	1283: uint16(4769),
  66168 	1284: uint16(4775),
  66169 	1285: uint16(4784),
  66170 	1286: uint16(4790),
  66171 	1287: uint16(4801),
  66172 	1288: uint16(4807),
  66173 	1289: uint16(4816),
  66174 	1290: uint16(4822),
  66175 	1291: uint16(4842),
  66176 	1292: uint16(4848),
  66177 	1293: uint16(4857),
  66178 	1294: uint16(4863),
  66179 	1295: uint16(4874),
  66180 	1296: uint16(4880),
  66181 	1297: uint16(4889),
  66182 	1298: uint16(4895),
  66183 	1299: uint16(4920),
  66184 	1300: uint16(4926),
  66185 	1301: uint16(4935),
  66186 	1302: uint16(4941),
  66187 	1303: uint16(4952),
  66188 	1304: uint16(4958),
  66189 	1305: uint16(4967),
  66190 	1306: uint16(4973),
  66191 	1307: uint16(4993),
  66192 	1308: uint16(4999),
  66193 	1309: uint16(5008),
  66194 	1310: uint16(5014),
  66195 	1311: uint16(5025),
  66196 	1312: uint16(5031),
  66197 	1313: uint16(5040),
  66198 	1314: uint16(5046),
  66199 	1315: uint16(5069),
  66200 	1316: uint16(5075),
  66201 	1317: uint16(5084),
  66202 	1318: uint16(5090),
  66203 	1319: uint16(5101),
  66204 	1320: uint16(5107),
  66205 	1321: uint16(5116),
  66206 	1322: uint16(5122),
  66207 	1323: uint16(5142),
  66208 	1324: uint16(5148),
  66209 	1325: uint16(5157),
  66210 	1326: uint16(5163),
  66211 	1327: uint16(5174),
  66212 	1328: uint16(5180),
  66213 	1329: uint16(5189),
  66214 	1330: uint16(5195),
  66215 	1331: uint16(5220),
  66216 	1332: uint16(5226),
  66217 	1333: uint16(5235),
  66218 	1334: uint16(5241),
  66219 	1335: uint16(5252),
  66220 	1336: uint16(5258),
  66221 	1337: uint16(5267),
  66222 	1338: uint16(5273),
  66223 	1339: uint16(5293),
  66224 	1340: uint16(5299),
  66225 	1341: uint16(5308),
  66226 	1342: uint16(5314),
  66227 	1343: uint16(5325),
  66228 	1344: uint16(5331),
  66229 	1345: uint16(5340),
  66230 	1346: uint16(5346),
  66231 	1347: uint16(4604),
  66232 	1348: uint16(4610),
  66233 	1349: uint16(4619),
  66234 	1350: uint16(4625),
  66235 	1351: uint16(4636),
  66236 	1352: uint16(4642),
  66237 	1353: uint16(4651),
  66238 	1354: uint16(4657),
  66239 	1355: uint16(4677),
  66240 	1356: uint16(4683),
  66241 	1357: uint16(4692),
  66242 	1358: uint16(4698),
  66243 	1359: uint16(4709),
  66244 	1360: uint16(4715),
  66245 	1361: uint16(4724),
  66246 	1362: uint16(4730),
  66247 	1363: uint16(4755),
  66248 	1364: uint16(4761),
  66249 	1365: uint16(4770),
  66250 	1366: uint16(4776),
  66251 	1367: uint16(4787),
  66252 	1368: uint16(4793),
  66253 	1369: uint16(4802),
  66254 	1370: uint16(4808),
  66255 	1371: uint16(4828),
  66256 	1372: uint16(4834),
  66257 	1373: uint16(4843),
  66258 	1374: uint16(4849),
  66259 	1375: uint16(4860),
  66260 	1376: uint16(4866),
  66261 	1377: uint16(4875),
  66262 	1378: uint16(4881),
  66263 	1379: uint16(4904),
  66264 	1380: uint16(4910),
  66265 	1381: uint16(4919),
  66266 	1382: uint16(4925),
  66267 	1383: uint16(4936),
  66268 	1384: uint16(4942),
  66269 	1385: uint16(4951),
  66270 	1386: uint16(4957),
  66271 	1387: uint16(4977),
  66272 	1388: uint16(4983),
  66273 	1389: uint16(4992),
  66274 	1390: uint16(4998),
  66275 	1391: uint16(5009),
  66276 	1392: uint16(5015),
  66277 	1393: uint16(5024),
  66278 	1394: uint16(5030),
  66279 	1395: uint16(5055),
  66280 	1396: uint16(5061),
  66281 	1397: uint16(5070),
  66282 	1398: uint16(5076),
  66283 	1399: uint16(5087),
  66284 	1400: uint16(5093),
  66285 	1401: uint16(5102),
  66286 	1402: uint16(5108),
  66287 	1403: uint16(5128),
  66288 	1404: uint16(5134),
  66289 	1405: uint16(5143),
  66290 	1406: uint16(5149),
  66291 	1407: uint16(5160),
  66292 	1408: uint16(5166),
  66293 	1409: uint16(5175),
  66294 	1410: uint16(5181),
  66295 	1411: uint16(5045),
  66296 	1412: uint16(5051),
  66297 	1413: uint16(5060),
  66298 	1414: uint16(5066),
  66299 	1415: uint16(5077),
  66300 	1416: uint16(5083),
  66301 	1417: uint16(5092),
  66302 	1418: uint16(5098),
  66303 	1419: uint16(5118),
  66304 	1420: uint16(5124),
  66305 	1421: uint16(5133),
  66306 	1422: uint16(5139),
  66307 	1423: uint16(5150),
  66308 	1424: uint16(5156),
  66309 	1425: uint16(5165),
  66310 	1426: uint16(5171),
  66311 	1427: uint16(5196),
  66312 	1428: uint16(5202),
  66313 	1429: uint16(5211),
  66314 	1430: uint16(5217),
  66315 	1431: uint16(5228),
  66316 	1432: uint16(5234),
  66317 	1433: uint16(5243),
  66318 	1434: uint16(5249),
  66319 	1435: uint16(5269),
  66320 	1436: uint16(5275),
  66321 	1437: uint16(5284),
  66322 	1438: uint16(5290),
  66323 	1439: uint16(5301),
  66324 	1440: uint16(5307),
  66325 	1441: uint16(5316),
  66326 	1442: uint16(5322),
  66327 	1443: uint16(5345),
  66328 	1444: uint16(5351),
  66329 	1445: uint16(5360),
  66330 	1446: uint16(5366),
  66331 	1447: uint16(5377),
  66332 	1448: uint16(5383),
  66333 	1449: uint16(5392),
  66334 	1450: uint16(5398),
  66335 	1451: uint16(5418),
  66336 	1452: uint16(5424),
  66337 	1453: uint16(5433),
  66338 	1454: uint16(5439),
  66339 	1455: uint16(5450),
  66340 	1456: uint16(5456),
  66341 	1457: uint16(5465),
  66342 	1458: uint16(5471),
  66343 	1459: uint16(5496),
  66344 	1460: uint16(5502),
  66345 	1461: uint16(5511),
  66346 	1462: uint16(5517),
  66347 	1463: uint16(5528),
  66348 	1464: uint16(5534),
  66349 	1465: uint16(5543),
  66350 	1466: uint16(5549),
  66351 	1467: uint16(5569),
  66352 	1468: uint16(5575),
  66353 	1469: uint16(5584),
  66354 	1470: uint16(5590),
  66355 	1471: uint16(5601),
  66356 	1472: uint16(5607),
  66357 	1473: uint16(5616),
  66358 	1474: uint16(5622),
  66359 	1475: uint16(5417),
  66360 	1476: uint16(5423),
  66361 	1477: uint16(5432),
  66362 	1478: uint16(5438),
  66363 	1479: uint16(5449),
  66364 	1480: uint16(5455),
  66365 	1481: uint16(5464),
  66366 	1482: uint16(5470),
  66367 	1483: uint16(5490),
  66368 	1484: uint16(5496),
  66369 	1485: uint16(5505),
  66370 	1486: uint16(5511),
  66371 	1487: uint16(5522),
  66372 	1488: uint16(5528),
  66373 	1489: uint16(5537),
  66374 	1490: uint16(5543),
  66375 	1491: uint16(5568),
  66376 	1492: uint16(5574),
  66377 	1493: uint16(5583),
  66378 	1494: uint16(5589),
  66379 	1495: uint16(5600),
  66380 	1496: uint16(5606),
  66381 	1497: uint16(5615),
  66382 	1498: uint16(5621),
  66383 	1499: uint16(5641),
  66384 	1500: uint16(5647),
  66385 	1501: uint16(5656),
  66386 	1502: uint16(5662),
  66387 	1503: uint16(5673),
  66388 	1504: uint16(5679),
  66389 	1505: uint16(5688),
  66390 	1506: uint16(5694),
  66391 	1507: uint16(5717),
  66392 	1508: uint16(5723),
  66393 	1509: uint16(5732),
  66394 	1510: uint16(5738),
  66395 	1511: uint16(5749),
  66396 	1512: uint16(5755),
  66397 	1513: uint16(5764),
  66398 	1514: uint16(5770),
  66399 	1515: uint16(5790),
  66400 	1516: uint16(5796),
  66401 	1517: uint16(5805),
  66402 	1518: uint16(5811),
  66403 	1519: uint16(5822),
  66404 	1520: uint16(5828),
  66405 	1521: uint16(5837),
  66406 	1522: uint16(5843),
  66407 	1523: uint16(5868),
  66408 	1524: uint16(5874),
  66409 	1525: uint16(5883),
  66410 	1526: uint16(5889),
  66411 	1527: uint16(5900),
  66412 	1528: uint16(5906),
  66413 	1529: uint16(5915),
  66414 	1530: uint16(5921),
  66415 	1531: uint16(5941),
  66416 	1532: uint16(5947),
  66417 	1533: uint16(5956),
  66418 	1534: uint16(5962),
  66419 	1535: uint16(5973),
  66420 	1536: uint16(5979),
  66421 	1537: uint16(5988),
  66422 	1538: uint16(5994),
  66423 	1539: uint16(5858),
  66424 	1540: uint16(5864),
  66425 	1541: uint16(5873),
  66426 	1542: uint16(5879),
  66427 	1543: uint16(5890),
  66428 	1544: uint16(5896),
  66429 	1545: uint16(5905),
  66430 	1546: uint16(5911),
  66431 	1547: uint16(5931),
  66432 	1548: uint16(5937),
  66433 	1549: uint16(5946),
  66434 	1550: uint16(5952),
  66435 	1551: uint16(5963),
  66436 	1552: uint16(5969),
  66437 	1553: uint16(5978),
  66438 	1554: uint16(5984),
  66439 	1555: uint16(6009),
  66440 	1556: uint16(6015),
  66441 	1557: uint16(6024),
  66442 	1558: uint16(6030),
  66443 	1559: uint16(6041),
  66444 	1560: uint16(6047),
  66445 	1561: uint16(6056),
  66446 	1562: uint16(6062),
  66447 	1563: uint16(6082),
  66448 	1564: uint16(6088),
  66449 	1565: uint16(6097),
  66450 	1566: uint16(6103),
  66451 	1567: uint16(6114),
  66452 	1568: uint16(6120),
  66453 	1569: uint16(6129),
  66454 	1570: uint16(6135),
  66455 	1571: uint16(6158),
  66456 	1572: uint16(6164),
  66457 	1573: uint16(6173),
  66458 	1574: uint16(6179),
  66459 	1575: uint16(6190),
  66460 	1576: uint16(6196),
  66461 	1577: uint16(6205),
  66462 	1578: uint16(6211),
  66463 	1579: uint16(6231),
  66464 	1580: uint16(6237),
  66465 	1581: uint16(6246),
  66466 	1582: uint16(6252),
  66467 	1583: uint16(6263),
  66468 	1584: uint16(6269),
  66469 	1585: uint16(6278),
  66470 	1586: uint16(6284),
  66471 	1587: uint16(6309),
  66472 	1588: uint16(6315),
  66473 	1589: uint16(6324),
  66474 	1590: uint16(6330),
  66475 	1591: uint16(6341),
  66476 	1592: uint16(6347),
  66477 	1593: uint16(6356),
  66478 	1594: uint16(6362),
  66479 	1595: uint16(6382),
  66480 	1596: uint16(6388),
  66481 	1597: uint16(6397),
  66482 	1598: uint16(6403),
  66483 	1599: uint16(6414),
  66484 	1600: uint16(6420),
  66485 	1601: uint16(6429),
  66486 	1602: uint16(6435),
  66487 	1603: uint16(5303),
  66488 	1604: uint16(5309),
  66489 	1605: uint16(5318),
  66490 	1606: uint16(5324),
  66491 	1607: uint16(5335),
  66492 	1608: uint16(5341),
  66493 	1609: uint16(5350),
  66494 	1610: uint16(5356),
  66495 	1611: uint16(5376),
  66496 	1612: uint16(5382),
  66497 	1613: uint16(5391),
  66498 	1614: uint16(5397),
  66499 	1615: uint16(5408),
  66500 	1616: uint16(5414),
  66501 	1617: uint16(5423),
  66502 	1618: uint16(5429),
  66503 	1619: uint16(5454),
  66504 	1620: uint16(5460),
  66505 	1621: uint16(5469),
  66506 	1622: uint16(5475),
  66507 	1623: uint16(5486),
  66508 	1624: uint16(5492),
  66509 	1625: uint16(5501),
  66510 	1626: uint16(5507),
  66511 	1627: uint16(5527),
  66512 	1628: uint16(5533),
  66513 	1629: uint16(5542),
  66514 	1630: uint16(5548),
  66515 	1631: uint16(5559),
  66516 	1632: uint16(5565),
  66517 	1633: uint16(5574),
  66518 	1634: uint16(5580),
  66519 	1635: uint16(5603),
  66520 	1636: uint16(5609),
  66521 	1637: uint16(5618),
  66522 	1638: uint16(5624),
  66523 	1639: uint16(5635),
  66524 	1640: uint16(5641),
  66525 	1641: uint16(5650),
  66526 	1642: uint16(5656),
  66527 	1643: uint16(5676),
  66528 	1644: uint16(5682),
  66529 	1645: uint16(5691),
  66530 	1646: uint16(5697),
  66531 	1647: uint16(5708),
  66532 	1648: uint16(5714),
  66533 	1649: uint16(5723),
  66534 	1650: uint16(5729),
  66535 	1651: uint16(5754),
  66536 	1652: uint16(5760),
  66537 	1653: uint16(5769),
  66538 	1654: uint16(5775),
  66539 	1655: uint16(5786),
  66540 	1656: uint16(5792),
  66541 	1657: uint16(5801),
  66542 	1658: uint16(5807),
  66543 	1659: uint16(5827),
  66544 	1660: uint16(5833),
  66545 	1661: uint16(5842),
  66546 	1662: uint16(5848),
  66547 	1663: uint16(5859),
  66548 	1664: uint16(5865),
  66549 	1665: uint16(5874),
  66550 	1666: uint16(5880),
  66551 	1667: uint16(5744),
  66552 	1668: uint16(5750),
  66553 	1669: uint16(5759),
  66554 	1670: uint16(5765),
  66555 	1671: uint16(5776),
  66556 	1672: uint16(5782),
  66557 	1673: uint16(5791),
  66558 	1674: uint16(5797),
  66559 	1675: uint16(5817),
  66560 	1676: uint16(5823),
  66561 	1677: uint16(5832),
  66562 	1678: uint16(5838),
  66563 	1679: uint16(5849),
  66564 	1680: uint16(5855),
  66565 	1681: uint16(5864),
  66566 	1682: uint16(5870),
  66567 	1683: uint16(5895),
  66568 	1684: uint16(5901),
  66569 	1685: uint16(5910),
  66570 	1686: uint16(5916),
  66571 	1687: uint16(5927),
  66572 	1688: uint16(5933),
  66573 	1689: uint16(5942),
  66574 	1690: uint16(5948),
  66575 	1691: uint16(5968),
  66576 	1692: uint16(5974),
  66577 	1693: uint16(5983),
  66578 	1694: uint16(5989),
  66579 	1695: uint16(6000),
  66580 	1696: uint16(6006),
  66581 	1697: uint16(6015),
  66582 	1698: uint16(6021),
  66583 	1699: uint16(6044),
  66584 	1700: uint16(6050),
  66585 	1701: uint16(6059),
  66586 	1702: uint16(6065),
  66587 	1703: uint16(6076),
  66588 	1704: uint16(6082),
  66589 	1705: uint16(6091),
  66590 	1706: uint16(6097),
  66591 	1707: uint16(6117),
  66592 	1708: uint16(6123),
  66593 	1709: uint16(6132),
  66594 	1710: uint16(6138),
  66595 	1711: uint16(6149),
  66596 	1712: uint16(6155),
  66597 	1713: uint16(6164),
  66598 	1714: uint16(6170),
  66599 	1715: uint16(6195),
  66600 	1716: uint16(6201),
  66601 	1717: uint16(6210),
  66602 	1718: uint16(6216),
  66603 	1719: uint16(6227),
  66604 	1720: uint16(6233),
  66605 	1721: uint16(6242),
  66606 	1722: uint16(6248),
  66607 	1723: uint16(6268),
  66608 	1724: uint16(6274),
  66609 	1725: uint16(6283),
  66610 	1726: uint16(6289),
  66611 	1727: uint16(6300),
  66612 	1728: uint16(6306),
  66613 	1729: uint16(6315),
  66614 	1730: uint16(6321),
  66615 	1731: uint16(6116),
  66616 	1732: uint16(6122),
  66617 	1733: uint16(6131),
  66618 	1734: uint16(6137),
  66619 	1735: uint16(6148),
  66620 	1736: uint16(6154),
  66621 	1737: uint16(6163),
  66622 	1738: uint16(6169),
  66623 	1739: uint16(6189),
  66624 	1740: uint16(6195),
  66625 	1741: uint16(6204),
  66626 	1742: uint16(6210),
  66627 	1743: uint16(6221),
  66628 	1744: uint16(6227),
  66629 	1745: uint16(6236),
  66630 	1746: uint16(6242),
  66631 	1747: uint16(6267),
  66632 	1748: uint16(6273),
  66633 	1749: uint16(6282),
  66634 	1750: uint16(6288),
  66635 	1751: uint16(6299),
  66636 	1752: uint16(6305),
  66637 	1753: uint16(6314),
  66638 	1754: uint16(6320),
  66639 	1755: uint16(6340),
  66640 	1756: uint16(6346),
  66641 	1757: uint16(6355),
  66642 	1758: uint16(6361),
  66643 	1759: uint16(6372),
  66644 	1760: uint16(6378),
  66645 	1761: uint16(6387),
  66646 	1762: uint16(6393),
  66647 	1763: uint16(6416),
  66648 	1764: uint16(6422),
  66649 	1765: uint16(6431),
  66650 	1766: uint16(6437),
  66651 	1767: uint16(6448),
  66652 	1768: uint16(6454),
  66653 	1769: uint16(6463),
  66654 	1770: uint16(6469),
  66655 	1771: uint16(6489),
  66656 	1772: uint16(6495),
  66657 	1773: uint16(6504),
  66658 	1774: uint16(6510),
  66659 	1775: uint16(6521),
  66660 	1776: uint16(6527),
  66661 	1777: uint16(6536),
  66662 	1778: uint16(6542),
  66663 	1779: uint16(6567),
  66664 	1780: uint16(6573),
  66665 	1781: uint16(6582),
  66666 	1782: uint16(6588),
  66667 	1783: uint16(6599),
  66668 	1784: uint16(6605),
  66669 	1785: uint16(6614),
  66670 	1786: uint16(6620),
  66671 	1787: uint16(6640),
  66672 	1788: uint16(6646),
  66673 	1789: uint16(6655),
  66674 	1790: uint16(6661),
  66675 	1791: uint16(6672),
  66676 	1792: uint16(6678),
  66677 	1793: uint16(6687),
  66678 	1794: uint16(6693),
  66679 	1795: uint16(6557),
  66680 	1796: uint16(6563),
  66681 	1797: uint16(6572),
  66682 	1798: uint16(6578),
  66683 	1799: uint16(6589),
  66684 	1800: uint16(6595),
  66685 	1801: uint16(6604),
  66686 	1802: uint16(6610),
  66687 	1803: uint16(6630),
  66688 	1804: uint16(6636),
  66689 	1805: uint16(6645),
  66690 	1806: uint16(6651),
  66691 	1807: uint16(6662),
  66692 	1808: uint16(6668),
  66693 	1809: uint16(6677),
  66694 	1810: uint16(6683),
  66695 	1811: uint16(6708),
  66696 	1812: uint16(6714),
  66697 	1813: uint16(6723),
  66698 	1814: uint16(6729),
  66699 	1815: uint16(6740),
  66700 	1816: uint16(6746),
  66701 	1817: uint16(6755),
  66702 	1818: uint16(6761),
  66703 	1819: uint16(6781),
  66704 	1820: uint16(6787),
  66705 	1821: uint16(6796),
  66706 	1822: uint16(6802),
  66707 	1823: uint16(6813),
  66708 	1824: uint16(6819),
  66709 	1825: uint16(6828),
  66710 	1826: uint16(6834),
  66711 	1827: uint16(6857),
  66712 	1828: uint16(6863),
  66713 	1829: uint16(6872),
  66714 	1830: uint16(6878),
  66715 	1831: uint16(6889),
  66716 	1832: uint16(6895),
  66717 	1833: uint16(6904),
  66718 	1834: uint16(6910),
  66719 	1835: uint16(6930),
  66720 	1836: uint16(6936),
  66721 	1837: uint16(6945),
  66722 	1838: uint16(6951),
  66723 	1839: uint16(6962),
  66724 	1840: uint16(6968),
  66725 	1841: uint16(6977),
  66726 	1842: uint16(6983),
  66727 	1843: uint16(7008),
  66728 	1844: uint16(7014),
  66729 	1845: uint16(7023),
  66730 	1846: uint16(7029),
  66731 	1847: uint16(7040),
  66732 	1848: uint16(7046),
  66733 	1849: uint16(7055),
  66734 	1850: uint16(7061),
  66735 	1851: uint16(7081),
  66736 	1852: uint16(7087),
  66737 	1853: uint16(7096),
  66738 	1854: uint16(7102),
  66739 	1855: uint16(7113),
  66740 	1856: uint16(7119),
  66741 	1857: uint16(7128),
  66742 	1858: uint16(7134),
  66743 	1859: uint16(6392),
  66744 	1860: uint16(6398),
  66745 	1861: uint16(6407),
  66746 	1862: uint16(6413),
  66747 	1863: uint16(6424),
  66748 	1864: uint16(6430),
  66749 	1865: uint16(6439),
  66750 	1866: uint16(6445),
  66751 	1867: uint16(6465),
  66752 	1868: uint16(6471),
  66753 	1869: uint16(6480),
  66754 	1870: uint16(6486),
  66755 	1871: uint16(6497),
  66756 	1872: uint16(6503),
  66757 	1873: uint16(6512),
  66758 	1874: uint16(6518),
  66759 	1875: uint16(6543),
  66760 	1876: uint16(6549),
  66761 	1877: uint16(6558),
  66762 	1878: uint16(6564),
  66763 	1879: uint16(6575),
  66764 	1880: uint16(6581),
  66765 	1881: uint16(6590),
  66766 	1882: uint16(6596),
  66767 	1883: uint16(6616),
  66768 	1884: uint16(6622),
  66769 	1885: uint16(6631),
  66770 	1886: uint16(6637),
  66771 	1887: uint16(6648),
  66772 	1888: uint16(6654),
  66773 	1889: uint16(6663),
  66774 	1890: uint16(6669),
  66775 	1891: uint16(6692),
  66776 	1892: uint16(6698),
  66777 	1893: uint16(6707),
  66778 	1894: uint16(6713),
  66779 	1895: uint16(6724),
  66780 	1896: uint16(6730),
  66781 	1897: uint16(6739),
  66782 	1898: uint16(6745),
  66783 	1899: uint16(6765),
  66784 	1900: uint16(6771),
  66785 	1901: uint16(6780),
  66786 	1902: uint16(6786),
  66787 	1903: uint16(6797),
  66788 	1904: uint16(6803),
  66789 	1905: uint16(6812),
  66790 	1906: uint16(6818),
  66791 	1907: uint16(6843),
  66792 	1908: uint16(6849),
  66793 	1909: uint16(6858),
  66794 	1910: uint16(6864),
  66795 	1911: uint16(6875),
  66796 	1912: uint16(6881),
  66797 	1913: uint16(6890),
  66798 	1914: uint16(6896),
  66799 	1915: uint16(6916),
  66800 	1916: uint16(6922),
  66801 	1917: uint16(6931),
  66802 	1918: uint16(6937),
  66803 	1919: uint16(6948),
  66804 	1920: uint16(6954),
  66805 	1921: uint16(6963),
  66806 	1922: uint16(6969),
  66807 	1923: uint16(6833),
  66808 	1924: uint16(6839),
  66809 	1925: uint16(6848),
  66810 	1926: uint16(6854),
  66811 	1927: uint16(6865),
  66812 	1928: uint16(6871),
  66813 	1929: uint16(6880),
  66814 	1930: uint16(6886),
  66815 	1931: uint16(6906),
  66816 	1932: uint16(6912),
  66817 	1933: uint16(6921),
  66818 	1934: uint16(6927),
  66819 	1935: uint16(6938),
  66820 	1936: uint16(6944),
  66821 	1937: uint16(6953),
  66822 	1938: uint16(6959),
  66823 	1939: uint16(6984),
  66824 	1940: uint16(6990),
  66825 	1941: uint16(6999),
  66826 	1942: uint16(7005),
  66827 	1943: uint16(7016),
  66828 	1944: uint16(7022),
  66829 	1945: uint16(7031),
  66830 	1946: uint16(7037),
  66831 	1947: uint16(7057),
  66832 	1948: uint16(7063),
  66833 	1949: uint16(7072),
  66834 	1950: uint16(7078),
  66835 	1951: uint16(7089),
  66836 	1952: uint16(7095),
  66837 	1953: uint16(7104),
  66838 	1954: uint16(7110),
  66839 	1955: uint16(7133),
  66840 	1956: uint16(7139),
  66841 	1957: uint16(7148),
  66842 	1958: uint16(7154),
  66843 	1959: uint16(7165),
  66844 	1960: uint16(7171),
  66845 	1961: uint16(7180),
  66846 	1962: uint16(7186),
  66847 	1963: uint16(7206),
  66848 	1964: uint16(7212),
  66849 	1965: uint16(7221),
  66850 	1966: uint16(7227),
  66851 	1967: uint16(7238),
  66852 	1968: uint16(7244),
  66853 	1969: uint16(7253),
  66854 	1970: uint16(7259),
  66855 	1971: uint16(7284),
  66856 	1972: uint16(7290),
  66857 	1973: uint16(7299),
  66858 	1974: uint16(7305),
  66859 	1975: uint16(7316),
  66860 	1976: uint16(7322),
  66861 	1977: uint16(7331),
  66862 	1978: uint16(7337),
  66863 	1979: uint16(7357),
  66864 	1980: uint16(7363),
  66865 	1981: uint16(7372),
  66866 	1982: uint16(7378),
  66867 	1983: uint16(7389),
  66868 	1984: uint16(7395),
  66869 	1985: uint16(7404),
  66870 	1986: uint16(7410),
  66871 	1987: uint16(7205),
  66872 	1988: uint16(7211),
  66873 	1989: uint16(7220),
  66874 	1990: uint16(7226),
  66875 	1991: uint16(7237),
  66876 	1992: uint16(7243),
  66877 	1993: uint16(7252),
  66878 	1994: uint16(7258),
  66879 	1995: uint16(7278),
  66880 	1996: uint16(7284),
  66881 	1997: uint16(7293),
  66882 	1998: uint16(7299),
  66883 	1999: uint16(7310),
  66884 	2000: uint16(7316),
  66885 	2001: uint16(7325),
  66886 	2002: uint16(7331),
  66887 	2003: uint16(7356),
  66888 	2004: uint16(7362),
  66889 	2005: uint16(7371),
  66890 	2006: uint16(7377),
  66891 	2007: uint16(7388),
  66892 	2008: uint16(7394),
  66893 	2009: uint16(7403),
  66894 	2010: uint16(7409),
  66895 	2011: uint16(7429),
  66896 	2012: uint16(7435),
  66897 	2013: uint16(7444),
  66898 	2014: uint16(7450),
  66899 	2015: uint16(7461),
  66900 	2016: uint16(7467),
  66901 	2017: uint16(7476),
  66902 	2018: uint16(7482),
  66903 	2019: uint16(7505),
  66904 	2020: uint16(7511),
  66905 	2021: uint16(7520),
  66906 	2022: uint16(7526),
  66907 	2023: uint16(7537),
  66908 	2024: uint16(7543),
  66909 	2025: uint16(7552),
  66910 	2026: uint16(7558),
  66911 	2027: uint16(7578),
  66912 	2028: uint16(7584),
  66913 	2029: uint16(7593),
  66914 	2030: uint16(7599),
  66915 	2031: uint16(7610),
  66916 	2032: uint16(7616),
  66917 	2033: uint16(7625),
  66918 	2034: uint16(7631),
  66919 	2035: uint16(7656),
  66920 	2036: uint16(7662),
  66921 	2037: uint16(7671),
  66922 	2038: uint16(7677),
  66923 	2039: uint16(7688),
  66924 	2040: uint16(7694),
  66925 	2041: uint16(7703),
  66926 	2042: uint16(7709),
  66927 	2043: uint16(7729),
  66928 	2044: uint16(7735),
  66929 	2045: uint16(7744),
  66930 	2046: uint16(7750),
  66931 	2047: uint16(7761),
  66932 }
  66933 
  66934 var VP8Mean16x4 VP8MeanMetric
  66935 
  66936 var VP8PredChroma8 [7]VP8PredFunc
  66937 
  66938 var VP8PredLuma16 [7]VP8PredFunc
  66939 
  66940 var VP8PredLuma4 [10]VP8PredFunc
  66941 
  66942 var VP8SSE16x16 VP8Metric
  66943 
  66944 var VP8SSE16x8 VP8Metric
  66945 
  66946 var VP8SSE4x4 VP8Metric
  66947 
  66948 var VP8SSE8x8 VP8Metric
  66949 
  66950 //------------------------------------------------------------------------------
  66951 
  66952 var VP8SSIMGet VP8SSIMGetFunc
  66953 
  66954 var VP8SSIMGetClipped VP8SSIMGetClippedFunc
  66955 
  66956 //------------------------------------------------------------------------------
  66957 // Quantize
  66958 
  66959 // Layout:
  66960 // +----+----+
  66961 // |YYYY|UUVV| 0
  66962 // |YYYY|UUVV| 4
  66963 // |YYYY|....| 8
  66964 // |YYYY|....| 12
  66965 // +----+----+
  66966 
  66967 var VP8Scan = [16]uint16_t{
  66968 	1:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  66969 	2:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  66970 	3:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(0)*libc.Int32FromInt32(BPS)),
  66971 	4:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66972 	5:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66973 	6:  libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66974 	7:  libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(4)*libc.Int32FromInt32(BPS)),
  66975 	8:  libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66976 	9:  libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66977 	10: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66978 	11: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  66979 	12: libc.Uint16FromInt32(libc.Int32FromInt32(0) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66980 	13: libc.Uint16FromInt32(libc.Int32FromInt32(4) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66981 	14: libc.Uint16FromInt32(libc.Int32FromInt32(8) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66982 	15: libc.Uint16FromInt32(libc.Int32FromInt32(12) + libc.Int32FromInt32(12)*libc.Int32FromInt32(BPS)),
  66983 }
  66984 
  66985 var VP8SetResidualCoeffs VP8SetResidualCoeffsFunc
  66986 
  66987 var VP8SimpleHFilter16 VP8SimpleFilterFunc
  66988 
  66989 var VP8SimpleHFilter16i VP8SimpleFilterFunc
  66990 
  66991 var VP8SimpleVFilter16 VP8SimpleFilterFunc
  66992 
  66993 var VP8SimpleVFilter16i VP8SimpleFilterFunc
  66994 
  66995 var VP8TDisto16x16 VP8WMetric
  66996 
  66997 var VP8TDisto4x4 VP8WMetric
  66998 
  66999 //------------------------------------------------------------------------------
  67000 
  67001 var VP8Transform VP8DecIdct2
  67002 
  67003 var VP8TransformAC3 VP8DecIdct
  67004 
  67005 var VP8TransformDC VP8DecIdct
  67006 
  67007 var VP8TransformDCUV VP8DecIdct
  67008 
  67009 var VP8TransformUV VP8DecIdct
  67010 
  67011 var VP8TransformWHT VP8WHT
  67012 
  67013 var VP8UVModeOffsets = [4]uint16_t{
  67014 	0: libc.Uint16FromInt32(libc.Int32FromInt32(2) * libc.Int32FromInt32(16) * libc.Int32FromInt32(BPS)),
  67015 	1: libc.Uint16FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  67016 	2: libc.Uint16FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS)),
  67017 	3: libc.Uint16FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(16)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(8)*libc.Int32FromInt32(BPS) + libc.Int32FromInt32(1)*libc.Int32FromInt32(16)),
  67018 }
  67019 
  67020 var VP8VFilter16 VP8LumaFilterFunc
  67021 
  67022 var VP8VFilter16i VP8LumaFilterFunc
  67023 
  67024 var VP8VFilter8 VP8ChromaFilterFunc
  67025 
  67026 var VP8VFilter8i VP8ChromaFilterFunc
  67027 
  67028 var VP8kabs0 = uintptr(unsafe.Pointer(&abs0)) + 255
  67029 
  67030 var VP8kclip1 = uintptr(unsafe.Pointer(&clip11)) + 255
  67031 
  67032 var VP8ksclip1 = uintptr(unsafe.Pointer(&sclip1)) + 1020
  67033 
  67034 var VP8ksclip2 = uintptr(unsafe.Pointer(&sclip2)) + 112
  67035 
  67036 var WebPAlphaReplace uintptr
  67037 
  67038 var WebPApplyAlphaMultiply uintptr
  67039 
  67040 var WebPApplyAlphaMultiply4444 uintptr
  67041 
  67042 var WebPConvertARGBToUV uintptr
  67043 
  67044 var WebPConvertARGBToY uintptr
  67045 
  67046 var WebPConvertBGR24ToY uintptr
  67047 
  67048 //-----------------------------------------------------------------------------
  67049 
  67050 var WebPConvertRGB24ToY uintptr
  67051 
  67052 var WebPConvertRGBA32ToUV uintptr
  67053 
  67054 var WebPDispatchAlpha uintptr
  67055 
  67056 var WebPDispatchAlphaToGreen uintptr
  67057 
  67058 var WebPExtractAlpha uintptr
  67059 
  67060 var WebPExtractGreen uintptr
  67061 
  67062 //------------------------------------------------------------------------------
  67063 // Init function
  67064 
  67065 var WebPFilters [4]WebPFilterFunc
  67066 
  67067 var WebPHasAlpha32b uintptr
  67068 
  67069 var WebPHasAlpha8b uintptr
  67070 
  67071 var WebPMultARGBRow uintptr
  67072 
  67073 var WebPMultRow uintptr
  67074 
  67075 var WebPPackRGB uintptr
  67076 
  67077 var WebPRescalerExportRowExpand WebPRescalerExportRowFunc
  67078 
  67079 var WebPRescalerExportRowShrink WebPRescalerExportRowFunc
  67080 
  67081 //------------------------------------------------------------------------------
  67082 
  67083 var WebPRescalerImportRowExpand WebPRescalerImportRowFunc
  67084 
  67085 var WebPRescalerImportRowShrink WebPRescalerImportRowFunc
  67086 
  67087 //-----------------------------------------------------------------------------
  67088 // Main call
  67089 
  67090 var WebPSamplers [13]WebPSamplerRowFunc
  67091 
  67092 var WebPUnfilters [4]WebPUnfilterFunc
  67093 
  67094 // Copyright 2010 Google Inc. All Rights Reserved.
  67095 //
  67096 // Use of this source code is governed by a BSD-style license
  67097 // that can be found in the COPYING file in the root of the source
  67098 // tree. An additional intellectual property rights grant can be found
  67099 // in the file PATENTS. All contributing project authors may
  67100 // be found in the AUTHORS file in the root of the source tree.
  67101 // -----------------------------------------------------------------------------
  67102 //
  67103 //  Main decoding functions for WebP images.
  67104 //
  67105 // Author: Skal (pascal.massimino@gmail.com)
  67106 
  67107 //------------------------------------------------------------------------------
  67108 // Fancy upsampler
  67109 
  67110 // C documentation
  67111 //
  67112 //	// Fancy upsampling functions to convert YUV to RGB
  67113 var WebPUpsamplers [13]WebPUpsampleLinePairFunc
  67114 
  67115 var WebPYUV444Converters [13]WebPYUV444Converter
  67116 
  67117 // Copyright 2012 Google Inc. All Rights Reserved.
  67118 //
  67119 // Use of this source code is governed by a BSD-style license
  67120 // that can be found in the COPYING file in the root of the source
  67121 // tree. An additional intellectual property rights grant can be found
  67122 // in the file PATENTS. All contributing project authors may
  67123 // be found in the AUTHORS file in the root of the source tree.
  67124 // -----------------------------------------------------------------------------
  67125 //
  67126 // Misc. common utility functions
  67127 //
  67128 // Authors: Skal (pascal.massimino@gmail.com)
  67129 //          Urvang (urvang@google.com)
  67130 
  67131 // Copyright 2012 Google Inc. All Rights Reserved.
  67132 //
  67133 // Use of this source code is governed by a BSD-style license
  67134 // that can be found in the COPYING file in the root of the source
  67135 // tree. An additional intellectual property rights grant can be found
  67136 // in the file PATENTS. All contributing project authors may
  67137 // be found in the AUTHORS file in the root of the source tree.
  67138 // -----------------------------------------------------------------------------
  67139 //
  67140 //  Internal header for constants related to WebP file format.
  67141 //
  67142 // Author: Urvang (urvang@google.com)
  67143 
  67144 // Copyright 2010 Google Inc. All Rights Reserved.
  67145 //
  67146 // Use of this source code is governed by a BSD-style license
  67147 // that can be found in the COPYING file in the root of the source
  67148 // tree. An additional intellectual property rights grant can be found
  67149 // in the file PATENTS. All contributing project authors may
  67150 // be found in the AUTHORS file in the root of the source tree.
  67151 // -----------------------------------------------------------------------------
  67152 //
  67153 //  Common types + memory wrappers
  67154 //
  67155 // Author: Skal (pascal.massimino@gmail.com)
  67156 
  67157 // C documentation
  67158 //
  67159 //	// lookup table for small values of log2(int) * (1 << LOG_2_PRECISION_BITS).
  67160 //	// Obtained in Python with:
  67161 //	// a = [ str(round((1<<23)*math.log2(i))) if i else "0" for i in range(256)]
  67162 //	// print(',\n'.join(['  '+','.join(v)
  67163 //	//       for v in batched([i.rjust(9) for i in a],7)]))
  67164 var kLog2Table = [256]uint32_t{
  67165 	2:   uint32(8388608),
  67166 	3:   uint32(13295629),
  67167 	4:   uint32(16777216),
  67168 	5:   uint32(19477745),
  67169 	6:   uint32(21684237),
  67170 	7:   uint32(23549800),
  67171 	8:   uint32(25165824),
  67172 	9:   uint32(26591258),
  67173 	10:  uint32(27866353),
  67174 	11:  uint32(29019816),
  67175 	12:  uint32(30072845),
  67176 	13:  uint32(31041538),
  67177 	14:  uint32(31938408),
  67178 	15:  uint32(32773374),
  67179 	16:  uint32(33554432),
  67180 	17:  uint32(34288123),
  67181 	18:  uint32(34979866),
  67182 	19:  uint32(35634199),
  67183 	20:  uint32(36254961),
  67184 	21:  uint32(36845429),
  67185 	22:  uint32(37408424),
  67186 	23:  uint32(37946388),
  67187 	24:  uint32(38461453),
  67188 	25:  uint32(38955489),
  67189 	26:  uint32(39430146),
  67190 	27:  uint32(39886887),
  67191 	28:  uint32(40327016),
  67192 	29:  uint32(40751698),
  67193 	30:  uint32(41161982),
  67194 	31:  uint32(41558811),
  67195 	32:  uint32(41943040),
  67196 	33:  uint32(42315445),
  67197 	34:  uint32(42676731),
  67198 	35:  uint32(43027545),
  67199 	36:  uint32(43368474),
  67200 	37:  uint32(43700062),
  67201 	38:  uint32(44022807),
  67202 	39:  uint32(44337167),
  67203 	40:  uint32(44643569),
  67204 	41:  uint32(44942404),
  67205 	42:  uint32(45234037),
  67206 	43:  uint32(45518808),
  67207 	44:  uint32(45797032),
  67208 	45:  uint32(46069003),
  67209 	46:  uint32(46334996),
  67210 	47:  uint32(46595268),
  67211 	48:  uint32(46850061),
  67212 	49:  uint32(47099600),
  67213 	50:  uint32(47344097),
  67214 	51:  uint32(47583753),
  67215 	52:  uint32(47818754),
  67216 	53:  uint32(48049279),
  67217 	54:  uint32(48275495),
  67218 	55:  uint32(48497560),
  67219 	56:  uint32(48715624),
  67220 	57:  uint32(48929828),
  67221 	58:  uint32(49140306),
  67222 	59:  uint32(49347187),
  67223 	60:  uint32(49550590),
  67224 	61:  uint32(49750631),
  67225 	62:  uint32(49947419),
  67226 	63:  uint32(50141058),
  67227 	64:  uint32(50331648),
  67228 	65:  uint32(50519283),
  67229 	66:  uint32(50704053),
  67230 	67:  uint32(50886044),
  67231 	68:  uint32(51065339),
  67232 	69:  uint32(51242017),
  67233 	70:  uint32(51416153),
  67234 	71:  uint32(51587818),
  67235 	72:  uint32(51757082),
  67236 	73:  uint32(51924012),
  67237 	74:  uint32(52088670),
  67238 	75:  uint32(52251118),
  67239 	76:  uint32(52411415),
  67240 	77:  uint32(52569616),
  67241 	78:  uint32(52725775),
  67242 	79:  uint32(52879946),
  67243 	80:  uint32(53032177),
  67244 	81:  uint32(53182516),
  67245 	82:  uint32(53331012),
  67246 	83:  uint32(53477707),
  67247 	84:  uint32(53622645),
  67248 	85:  uint32(53765868),
  67249 	86:  uint32(53907416),
  67250 	87:  uint32(54047327),
  67251 	88:  uint32(54185640),
  67252 	89:  uint32(54322389),
  67253 	90:  uint32(54457611),
  67254 	91:  uint32(54591338),
  67255 	92:  uint32(54723604),
  67256 	93:  uint32(54854440),
  67257 	94:  uint32(54983876),
  67258 	95:  uint32(55111943),
  67259 	96:  uint32(55238669),
  67260 	97:  uint32(55364082),
  67261 	98:  uint32(55488208),
  67262 	99:  uint32(55611074),
  67263 	100: uint32(55732705),
  67264 	101: uint32(55853126),
  67265 	102: uint32(55972361),
  67266 	103: uint32(56090432),
  67267 	104: uint32(56207362),
  67268 	105: uint32(56323174),
  67269 	106: uint32(56437887),
  67270 	107: uint32(56551524),
  67271 	108: uint32(56664103),
  67272 	109: uint32(56775645),
  67273 	110: uint32(56886168),
  67274 	111: uint32(56995691),
  67275 	112: uint32(57104232),
  67276 	113: uint32(57211808),
  67277 	114: uint32(57318436),
  67278 	115: uint32(57424133),
  67279 	116: uint32(57528914),
  67280 	117: uint32(57632796),
  67281 	118: uint32(57735795),
  67282 	119: uint32(57837923),
  67283 	120: uint32(57939198),
  67284 	121: uint32(58039632),
  67285 	122: uint32(58139239),
  67286 	123: uint32(58238033),
  67287 	124: uint32(58336027),
  67288 	125: uint32(58433234),
  67289 	126: uint32(58529666),
  67290 	127: uint32(58625336),
  67291 	128: uint32(58720256),
  67292 	129: uint32(58814437),
  67293 	130: uint32(58907891),
  67294 	131: uint32(59000628),
  67295 	132: uint32(59092661),
  67296 	133: uint32(59183999),
  67297 	134: uint32(59274652),
  67298 	135: uint32(59364632),
  67299 	136: uint32(59453947),
  67300 	137: uint32(59542609),
  67301 	138: uint32(59630625),
  67302 	139: uint32(59718006),
  67303 	140: uint32(59804761),
  67304 	141: uint32(59890898),
  67305 	142: uint32(59976426),
  67306 	143: uint32(60061354),
  67307 	144: uint32(60145690),
  67308 	145: uint32(60229443),
  67309 	146: uint32(60312620),
  67310 	147: uint32(60395229),
  67311 	148: uint32(60477278),
  67312 	149: uint32(60558775),
  67313 	150: uint32(60639726),
  67314 	151: uint32(60720140),
  67315 	152: uint32(60800023),
  67316 	153: uint32(60879382),
  67317 	154: uint32(60958224),
  67318 	155: uint32(61036555),
  67319 	156: uint32(61114383),
  67320 	157: uint32(61191714),
  67321 	158: uint32(61268554),
  67322 	159: uint32(61344908),
  67323 	160: uint32(61420785),
  67324 	161: uint32(61496188),
  67325 	162: uint32(61571124),
  67326 	163: uint32(61645600),
  67327 	164: uint32(61719620),
  67328 	165: uint32(61793189),
  67329 	166: uint32(61866315),
  67330 	167: uint32(61939001),
  67331 	168: uint32(62011253),
  67332 	169: uint32(62083076),
  67333 	170: uint32(62154476),
  67334 	171: uint32(62225457),
  67335 	172: uint32(62296024),
  67336 	173: uint32(62366182),
  67337 	174: uint32(62435935),
  67338 	175: uint32(62505289),
  67339 	176: uint32(62574248),
  67340 	177: uint32(62642816),
  67341 	178: uint32(62710997),
  67342 	179: uint32(62778797),
  67343 	180: uint32(62846219),
  67344 	181: uint32(62913267),
  67345 	182: uint32(62979946),
  67346 	183: uint32(63046260),
  67347 	184: uint32(63112212),
  67348 	185: uint32(63177807),
  67349 	186: uint32(63243048),
  67350 	187: uint32(63307939),
  67351 	188: uint32(63372484),
  67352 	189: uint32(63436687),
  67353 	190: uint32(63500551),
  67354 	191: uint32(63564080),
  67355 	192: uint32(63627277),
  67356 	193: uint32(63690146),
  67357 	194: uint32(63752690),
  67358 	195: uint32(63814912),
  67359 	196: uint32(63876816),
  67360 	197: uint32(63938405),
  67361 	198: uint32(63999682),
  67362 	199: uint32(64060650),
  67363 	200: uint32(64121313),
  67364 	201: uint32(64181673),
  67365 	202: uint32(64241734),
  67366 	203: uint32(64301498),
  67367 	204: uint32(64360969),
  67368 	205: uint32(64420148),
  67369 	206: uint32(64479040),
  67370 	207: uint32(64537646),
  67371 	208: uint32(64595970),
  67372 	209: uint32(64654014),
  67373 	210: uint32(64711782),
  67374 	211: uint32(64769274),
  67375 	212: uint32(64826495),
  67376 	213: uint32(64883447),
  67377 	214: uint32(64940132),
  67378 	215: uint32(64996553),
  67379 	216: uint32(65052711),
  67380 	217: uint32(65108611),
  67381 	218: uint32(65164253),
  67382 	219: uint32(65219641),
  67383 	220: uint32(65274776),
  67384 	221: uint32(65329662),
  67385 	222: uint32(65384299),
  67386 	223: uint32(65438691),
  67387 	224: uint32(65492840),
  67388 	225: uint32(65546747),
  67389 	226: uint32(65600416),
  67390 	227: uint32(65653847),
  67391 	228: uint32(65707044),
  67392 	229: uint32(65760008),
  67393 	230: uint32(65812741),
  67394 	231: uint32(65865245),
  67395 	232: uint32(65917522),
  67396 	233: uint32(65969575),
  67397 	234: uint32(66021404),
  67398 	235: uint32(66073013),
  67399 	236: uint32(66124403),
  67400 	237: uint32(66175575),
  67401 	238: uint32(66226531),
  67402 	239: uint32(66277275),
  67403 	240: uint32(66327806),
  67404 	241: uint32(66378127),
  67405 	242: uint32(66428240),
  67406 	243: uint32(66478146),
  67407 	244: uint32(66527847),
  67408 	245: uint32(66577345),
  67409 	246: uint32(66626641),
  67410 	247: uint32(66675737),
  67411 	248: uint32(66724635),
  67412 	249: uint32(66773336),
  67413 	250: uint32(66821842),
  67414 	251: uint32(66870154),
  67415 	252: uint32(66918274),
  67416 	253: uint32(66966204),
  67417 	254: uint32(67013944),
  67418 	255: uint32(67061497),
  67419 }
  67420 
  67421 var kPrefixEncodeCode = [512]VP8LPrefixCode{
  67422 	0: {},
  67423 	1: {},
  67424 	2: {
  67425 		Fcode: int8(1),
  67426 	},
  67427 	3: {
  67428 		Fcode: int8(2),
  67429 	},
  67430 	4: {
  67431 		Fcode: int8(3),
  67432 	},
  67433 	5: {
  67434 		Fcode:       int8(4),
  67435 		Fextra_bits: int8(1),
  67436 	},
  67437 	6: {
  67438 		Fcode:       int8(4),
  67439 		Fextra_bits: int8(1),
  67440 	},
  67441 	7: {
  67442 		Fcode:       int8(5),
  67443 		Fextra_bits: int8(1),
  67444 	},
  67445 	8: {
  67446 		Fcode:       int8(5),
  67447 		Fextra_bits: int8(1),
  67448 	},
  67449 	9: {
  67450 		Fcode:       int8(6),
  67451 		Fextra_bits: int8(2),
  67452 	},
  67453 	10: {
  67454 		Fcode:       int8(6),
  67455 		Fextra_bits: int8(2),
  67456 	},
  67457 	11: {
  67458 		Fcode:       int8(6),
  67459 		Fextra_bits: int8(2),
  67460 	},
  67461 	12: {
  67462 		Fcode:       int8(6),
  67463 		Fextra_bits: int8(2),
  67464 	},
  67465 	13: {
  67466 		Fcode:       int8(7),
  67467 		Fextra_bits: int8(2),
  67468 	},
  67469 	14: {
  67470 		Fcode:       int8(7),
  67471 		Fextra_bits: int8(2),
  67472 	},
  67473 	15: {
  67474 		Fcode:       int8(7),
  67475 		Fextra_bits: int8(2),
  67476 	},
  67477 	16: {
  67478 		Fcode:       int8(7),
  67479 		Fextra_bits: int8(2),
  67480 	},
  67481 	17: {
  67482 		Fcode:       int8(8),
  67483 		Fextra_bits: int8(3),
  67484 	},
  67485 	18: {
  67486 		Fcode:       int8(8),
  67487 		Fextra_bits: int8(3),
  67488 	},
  67489 	19: {
  67490 		Fcode:       int8(8),
  67491 		Fextra_bits: int8(3),
  67492 	},
  67493 	20: {
  67494 		Fcode:       int8(8),
  67495 		Fextra_bits: int8(3),
  67496 	},
  67497 	21: {
  67498 		Fcode:       int8(8),
  67499 		Fextra_bits: int8(3),
  67500 	},
  67501 	22: {
  67502 		Fcode:       int8(8),
  67503 		Fextra_bits: int8(3),
  67504 	},
  67505 	23: {
  67506 		Fcode:       int8(8),
  67507 		Fextra_bits: int8(3),
  67508 	},
  67509 	24: {
  67510 		Fcode:       int8(8),
  67511 		Fextra_bits: int8(3),
  67512 	},
  67513 	25: {
  67514 		Fcode:       int8(9),
  67515 		Fextra_bits: int8(3),
  67516 	},
  67517 	26: {
  67518 		Fcode:       int8(9),
  67519 		Fextra_bits: int8(3),
  67520 	},
  67521 	27: {
  67522 		Fcode:       int8(9),
  67523 		Fextra_bits: int8(3),
  67524 	},
  67525 	28: {
  67526 		Fcode:       int8(9),
  67527 		Fextra_bits: int8(3),
  67528 	},
  67529 	29: {
  67530 		Fcode:       int8(9),
  67531 		Fextra_bits: int8(3),
  67532 	},
  67533 	30: {
  67534 		Fcode:       int8(9),
  67535 		Fextra_bits: int8(3),
  67536 	},
  67537 	31: {
  67538 		Fcode:       int8(9),
  67539 		Fextra_bits: int8(3),
  67540 	},
  67541 	32: {
  67542 		Fcode:       int8(9),
  67543 		Fextra_bits: int8(3),
  67544 	},
  67545 	33: {
  67546 		Fcode:       int8(10),
  67547 		Fextra_bits: int8(4),
  67548 	},
  67549 	34: {
  67550 		Fcode:       int8(10),
  67551 		Fextra_bits: int8(4),
  67552 	},
  67553 	35: {
  67554 		Fcode:       int8(10),
  67555 		Fextra_bits: int8(4),
  67556 	},
  67557 	36: {
  67558 		Fcode:       int8(10),
  67559 		Fextra_bits: int8(4),
  67560 	},
  67561 	37: {
  67562 		Fcode:       int8(10),
  67563 		Fextra_bits: int8(4),
  67564 	},
  67565 	38: {
  67566 		Fcode:       int8(10),
  67567 		Fextra_bits: int8(4),
  67568 	},
  67569 	39: {
  67570 		Fcode:       int8(10),
  67571 		Fextra_bits: int8(4),
  67572 	},
  67573 	40: {
  67574 		Fcode:       int8(10),
  67575 		Fextra_bits: int8(4),
  67576 	},
  67577 	41: {
  67578 		Fcode:       int8(10),
  67579 		Fextra_bits: int8(4),
  67580 	},
  67581 	42: {
  67582 		Fcode:       int8(10),
  67583 		Fextra_bits: int8(4),
  67584 	},
  67585 	43: {
  67586 		Fcode:       int8(10),
  67587 		Fextra_bits: int8(4),
  67588 	},
  67589 	44: {
  67590 		Fcode:       int8(10),
  67591 		Fextra_bits: int8(4),
  67592 	},
  67593 	45: {
  67594 		Fcode:       int8(10),
  67595 		Fextra_bits: int8(4),
  67596 	},
  67597 	46: {
  67598 		Fcode:       int8(10),
  67599 		Fextra_bits: int8(4),
  67600 	},
  67601 	47: {
  67602 		Fcode:       int8(10),
  67603 		Fextra_bits: int8(4),
  67604 	},
  67605 	48: {
  67606 		Fcode:       int8(10),
  67607 		Fextra_bits: int8(4),
  67608 	},
  67609 	49: {
  67610 		Fcode:       int8(11),
  67611 		Fextra_bits: int8(4),
  67612 	},
  67613 	50: {
  67614 		Fcode:       int8(11),
  67615 		Fextra_bits: int8(4),
  67616 	},
  67617 	51: {
  67618 		Fcode:       int8(11),
  67619 		Fextra_bits: int8(4),
  67620 	},
  67621 	52: {
  67622 		Fcode:       int8(11),
  67623 		Fextra_bits: int8(4),
  67624 	},
  67625 	53: {
  67626 		Fcode:       int8(11),
  67627 		Fextra_bits: int8(4),
  67628 	},
  67629 	54: {
  67630 		Fcode:       int8(11),
  67631 		Fextra_bits: int8(4),
  67632 	},
  67633 	55: {
  67634 		Fcode:       int8(11),
  67635 		Fextra_bits: int8(4),
  67636 	},
  67637 	56: {
  67638 		Fcode:       int8(11),
  67639 		Fextra_bits: int8(4),
  67640 	},
  67641 	57: {
  67642 		Fcode:       int8(11),
  67643 		Fextra_bits: int8(4),
  67644 	},
  67645 	58: {
  67646 		Fcode:       int8(11),
  67647 		Fextra_bits: int8(4),
  67648 	},
  67649 	59: {
  67650 		Fcode:       int8(11),
  67651 		Fextra_bits: int8(4),
  67652 	},
  67653 	60: {
  67654 		Fcode:       int8(11),
  67655 		Fextra_bits: int8(4),
  67656 	},
  67657 	61: {
  67658 		Fcode:       int8(11),
  67659 		Fextra_bits: int8(4),
  67660 	},
  67661 	62: {
  67662 		Fcode:       int8(11),
  67663 		Fextra_bits: int8(4),
  67664 	},
  67665 	63: {
  67666 		Fcode:       int8(11),
  67667 		Fextra_bits: int8(4),
  67668 	},
  67669 	64: {
  67670 		Fcode:       int8(11),
  67671 		Fextra_bits: int8(4),
  67672 	},
  67673 	65: {
  67674 		Fcode:       int8(12),
  67675 		Fextra_bits: int8(5),
  67676 	},
  67677 	66: {
  67678 		Fcode:       int8(12),
  67679 		Fextra_bits: int8(5),
  67680 	},
  67681 	67: {
  67682 		Fcode:       int8(12),
  67683 		Fextra_bits: int8(5),
  67684 	},
  67685 	68: {
  67686 		Fcode:       int8(12),
  67687 		Fextra_bits: int8(5),
  67688 	},
  67689 	69: {
  67690 		Fcode:       int8(12),
  67691 		Fextra_bits: int8(5),
  67692 	},
  67693 	70: {
  67694 		Fcode:       int8(12),
  67695 		Fextra_bits: int8(5),
  67696 	},
  67697 	71: {
  67698 		Fcode:       int8(12),
  67699 		Fextra_bits: int8(5),
  67700 	},
  67701 	72: {
  67702 		Fcode:       int8(12),
  67703 		Fextra_bits: int8(5),
  67704 	},
  67705 	73: {
  67706 		Fcode:       int8(12),
  67707 		Fextra_bits: int8(5),
  67708 	},
  67709 	74: {
  67710 		Fcode:       int8(12),
  67711 		Fextra_bits: int8(5),
  67712 	},
  67713 	75: {
  67714 		Fcode:       int8(12),
  67715 		Fextra_bits: int8(5),
  67716 	},
  67717 	76: {
  67718 		Fcode:       int8(12),
  67719 		Fextra_bits: int8(5),
  67720 	},
  67721 	77: {
  67722 		Fcode:       int8(12),
  67723 		Fextra_bits: int8(5),
  67724 	},
  67725 	78: {
  67726 		Fcode:       int8(12),
  67727 		Fextra_bits: int8(5),
  67728 	},
  67729 	79: {
  67730 		Fcode:       int8(12),
  67731 		Fextra_bits: int8(5),
  67732 	},
  67733 	80: {
  67734 		Fcode:       int8(12),
  67735 		Fextra_bits: int8(5),
  67736 	},
  67737 	81: {
  67738 		Fcode:       int8(12),
  67739 		Fextra_bits: int8(5),
  67740 	},
  67741 	82: {
  67742 		Fcode:       int8(12),
  67743 		Fextra_bits: int8(5),
  67744 	},
  67745 	83: {
  67746 		Fcode:       int8(12),
  67747 		Fextra_bits: int8(5),
  67748 	},
  67749 	84: {
  67750 		Fcode:       int8(12),
  67751 		Fextra_bits: int8(5),
  67752 	},
  67753 	85: {
  67754 		Fcode:       int8(12),
  67755 		Fextra_bits: int8(5),
  67756 	},
  67757 	86: {
  67758 		Fcode:       int8(12),
  67759 		Fextra_bits: int8(5),
  67760 	},
  67761 	87: {
  67762 		Fcode:       int8(12),
  67763 		Fextra_bits: int8(5),
  67764 	},
  67765 	88: {
  67766 		Fcode:       int8(12),
  67767 		Fextra_bits: int8(5),
  67768 	},
  67769 	89: {
  67770 		Fcode:       int8(12),
  67771 		Fextra_bits: int8(5),
  67772 	},
  67773 	90: {
  67774 		Fcode:       int8(12),
  67775 		Fextra_bits: int8(5),
  67776 	},
  67777 	91: {
  67778 		Fcode:       int8(12),
  67779 		Fextra_bits: int8(5),
  67780 	},
  67781 	92: {
  67782 		Fcode:       int8(12),
  67783 		Fextra_bits: int8(5),
  67784 	},
  67785 	93: {
  67786 		Fcode:       int8(12),
  67787 		Fextra_bits: int8(5),
  67788 	},
  67789 	94: {
  67790 		Fcode:       int8(12),
  67791 		Fextra_bits: int8(5),
  67792 	},
  67793 	95: {
  67794 		Fcode:       int8(12),
  67795 		Fextra_bits: int8(5),
  67796 	},
  67797 	96: {
  67798 		Fcode:       int8(12),
  67799 		Fextra_bits: int8(5),
  67800 	},
  67801 	97: {
  67802 		Fcode:       int8(13),
  67803 		Fextra_bits: int8(5),
  67804 	},
  67805 	98: {
  67806 		Fcode:       int8(13),
  67807 		Fextra_bits: int8(5),
  67808 	},
  67809 	99: {
  67810 		Fcode:       int8(13),
  67811 		Fextra_bits: int8(5),
  67812 	},
  67813 	100: {
  67814 		Fcode:       int8(13),
  67815 		Fextra_bits: int8(5),
  67816 	},
  67817 	101: {
  67818 		Fcode:       int8(13),
  67819 		Fextra_bits: int8(5),
  67820 	},
  67821 	102: {
  67822 		Fcode:       int8(13),
  67823 		Fextra_bits: int8(5),
  67824 	},
  67825 	103: {
  67826 		Fcode:       int8(13),
  67827 		Fextra_bits: int8(5),
  67828 	},
  67829 	104: {
  67830 		Fcode:       int8(13),
  67831 		Fextra_bits: int8(5),
  67832 	},
  67833 	105: {
  67834 		Fcode:       int8(13),
  67835 		Fextra_bits: int8(5),
  67836 	},
  67837 	106: {
  67838 		Fcode:       int8(13),
  67839 		Fextra_bits: int8(5),
  67840 	},
  67841 	107: {
  67842 		Fcode:       int8(13),
  67843 		Fextra_bits: int8(5),
  67844 	},
  67845 	108: {
  67846 		Fcode:       int8(13),
  67847 		Fextra_bits: int8(5),
  67848 	},
  67849 	109: {
  67850 		Fcode:       int8(13),
  67851 		Fextra_bits: int8(5),
  67852 	},
  67853 	110: {
  67854 		Fcode:       int8(13),
  67855 		Fextra_bits: int8(5),
  67856 	},
  67857 	111: {
  67858 		Fcode:       int8(13),
  67859 		Fextra_bits: int8(5),
  67860 	},
  67861 	112: {
  67862 		Fcode:       int8(13),
  67863 		Fextra_bits: int8(5),
  67864 	},
  67865 	113: {
  67866 		Fcode:       int8(13),
  67867 		Fextra_bits: int8(5),
  67868 	},
  67869 	114: {
  67870 		Fcode:       int8(13),
  67871 		Fextra_bits: int8(5),
  67872 	},
  67873 	115: {
  67874 		Fcode:       int8(13),
  67875 		Fextra_bits: int8(5),
  67876 	},
  67877 	116: {
  67878 		Fcode:       int8(13),
  67879 		Fextra_bits: int8(5),
  67880 	},
  67881 	117: {
  67882 		Fcode:       int8(13),
  67883 		Fextra_bits: int8(5),
  67884 	},
  67885 	118: {
  67886 		Fcode:       int8(13),
  67887 		Fextra_bits: int8(5),
  67888 	},
  67889 	119: {
  67890 		Fcode:       int8(13),
  67891 		Fextra_bits: int8(5),
  67892 	},
  67893 	120: {
  67894 		Fcode:       int8(13),
  67895 		Fextra_bits: int8(5),
  67896 	},
  67897 	121: {
  67898 		Fcode:       int8(13),
  67899 		Fextra_bits: int8(5),
  67900 	},
  67901 	122: {
  67902 		Fcode:       int8(13),
  67903 		Fextra_bits: int8(5),
  67904 	},
  67905 	123: {
  67906 		Fcode:       int8(13),
  67907 		Fextra_bits: int8(5),
  67908 	},
  67909 	124: {
  67910 		Fcode:       int8(13),
  67911 		Fextra_bits: int8(5),
  67912 	},
  67913 	125: {
  67914 		Fcode:       int8(13),
  67915 		Fextra_bits: int8(5),
  67916 	},
  67917 	126: {
  67918 		Fcode:       int8(13),
  67919 		Fextra_bits: int8(5),
  67920 	},
  67921 	127: {
  67922 		Fcode:       int8(13),
  67923 		Fextra_bits: int8(5),
  67924 	},
  67925 	128: {
  67926 		Fcode:       int8(13),
  67927 		Fextra_bits: int8(5),
  67928 	},
  67929 	129: {
  67930 		Fcode:       int8(14),
  67931 		Fextra_bits: int8(6),
  67932 	},
  67933 	130: {
  67934 		Fcode:       int8(14),
  67935 		Fextra_bits: int8(6),
  67936 	},
  67937 	131: {
  67938 		Fcode:       int8(14),
  67939 		Fextra_bits: int8(6),
  67940 	},
  67941 	132: {
  67942 		Fcode:       int8(14),
  67943 		Fextra_bits: int8(6),
  67944 	},
  67945 	133: {
  67946 		Fcode:       int8(14),
  67947 		Fextra_bits: int8(6),
  67948 	},
  67949 	134: {
  67950 		Fcode:       int8(14),
  67951 		Fextra_bits: int8(6),
  67952 	},
  67953 	135: {
  67954 		Fcode:       int8(14),
  67955 		Fextra_bits: int8(6),
  67956 	},
  67957 	136: {
  67958 		Fcode:       int8(14),
  67959 		Fextra_bits: int8(6),
  67960 	},
  67961 	137: {
  67962 		Fcode:       int8(14),
  67963 		Fextra_bits: int8(6),
  67964 	},
  67965 	138: {
  67966 		Fcode:       int8(14),
  67967 		Fextra_bits: int8(6),
  67968 	},
  67969 	139: {
  67970 		Fcode:       int8(14),
  67971 		Fextra_bits: int8(6),
  67972 	},
  67973 	140: {
  67974 		Fcode:       int8(14),
  67975 		Fextra_bits: int8(6),
  67976 	},
  67977 	141: {
  67978 		Fcode:       int8(14),
  67979 		Fextra_bits: int8(6),
  67980 	},
  67981 	142: {
  67982 		Fcode:       int8(14),
  67983 		Fextra_bits: int8(6),
  67984 	},
  67985 	143: {
  67986 		Fcode:       int8(14),
  67987 		Fextra_bits: int8(6),
  67988 	},
  67989 	144: {
  67990 		Fcode:       int8(14),
  67991 		Fextra_bits: int8(6),
  67992 	},
  67993 	145: {
  67994 		Fcode:       int8(14),
  67995 		Fextra_bits: int8(6),
  67996 	},
  67997 	146: {
  67998 		Fcode:       int8(14),
  67999 		Fextra_bits: int8(6),
  68000 	},
  68001 	147: {
  68002 		Fcode:       int8(14),
  68003 		Fextra_bits: int8(6),
  68004 	},
  68005 	148: {
  68006 		Fcode:       int8(14),
  68007 		Fextra_bits: int8(6),
  68008 	},
  68009 	149: {
  68010 		Fcode:       int8(14),
  68011 		Fextra_bits: int8(6),
  68012 	},
  68013 	150: {
  68014 		Fcode:       int8(14),
  68015 		Fextra_bits: int8(6),
  68016 	},
  68017 	151: {
  68018 		Fcode:       int8(14),
  68019 		Fextra_bits: int8(6),
  68020 	},
  68021 	152: {
  68022 		Fcode:       int8(14),
  68023 		Fextra_bits: int8(6),
  68024 	},
  68025 	153: {
  68026 		Fcode:       int8(14),
  68027 		Fextra_bits: int8(6),
  68028 	},
  68029 	154: {
  68030 		Fcode:       int8(14),
  68031 		Fextra_bits: int8(6),
  68032 	},
  68033 	155: {
  68034 		Fcode:       int8(14),
  68035 		Fextra_bits: int8(6),
  68036 	},
  68037 	156: {
  68038 		Fcode:       int8(14),
  68039 		Fextra_bits: int8(6),
  68040 	},
  68041 	157: {
  68042 		Fcode:       int8(14),
  68043 		Fextra_bits: int8(6),
  68044 	},
  68045 	158: {
  68046 		Fcode:       int8(14),
  68047 		Fextra_bits: int8(6),
  68048 	},
  68049 	159: {
  68050 		Fcode:       int8(14),
  68051 		Fextra_bits: int8(6),
  68052 	},
  68053 	160: {
  68054 		Fcode:       int8(14),
  68055 		Fextra_bits: int8(6),
  68056 	},
  68057 	161: {
  68058 		Fcode:       int8(14),
  68059 		Fextra_bits: int8(6),
  68060 	},
  68061 	162: {
  68062 		Fcode:       int8(14),
  68063 		Fextra_bits: int8(6),
  68064 	},
  68065 	163: {
  68066 		Fcode:       int8(14),
  68067 		Fextra_bits: int8(6),
  68068 	},
  68069 	164: {
  68070 		Fcode:       int8(14),
  68071 		Fextra_bits: int8(6),
  68072 	},
  68073 	165: {
  68074 		Fcode:       int8(14),
  68075 		Fextra_bits: int8(6),
  68076 	},
  68077 	166: {
  68078 		Fcode:       int8(14),
  68079 		Fextra_bits: int8(6),
  68080 	},
  68081 	167: {
  68082 		Fcode:       int8(14),
  68083 		Fextra_bits: int8(6),
  68084 	},
  68085 	168: {
  68086 		Fcode:       int8(14),
  68087 		Fextra_bits: int8(6),
  68088 	},
  68089 	169: {
  68090 		Fcode:       int8(14),
  68091 		Fextra_bits: int8(6),
  68092 	},
  68093 	170: {
  68094 		Fcode:       int8(14),
  68095 		Fextra_bits: int8(6),
  68096 	},
  68097 	171: {
  68098 		Fcode:       int8(14),
  68099 		Fextra_bits: int8(6),
  68100 	},
  68101 	172: {
  68102 		Fcode:       int8(14),
  68103 		Fextra_bits: int8(6),
  68104 	},
  68105 	173: {
  68106 		Fcode:       int8(14),
  68107 		Fextra_bits: int8(6),
  68108 	},
  68109 	174: {
  68110 		Fcode:       int8(14),
  68111 		Fextra_bits: int8(6),
  68112 	},
  68113 	175: {
  68114 		Fcode:       int8(14),
  68115 		Fextra_bits: int8(6),
  68116 	},
  68117 	176: {
  68118 		Fcode:       int8(14),
  68119 		Fextra_bits: int8(6),
  68120 	},
  68121 	177: {
  68122 		Fcode:       int8(14),
  68123 		Fextra_bits: int8(6),
  68124 	},
  68125 	178: {
  68126 		Fcode:       int8(14),
  68127 		Fextra_bits: int8(6),
  68128 	},
  68129 	179: {
  68130 		Fcode:       int8(14),
  68131 		Fextra_bits: int8(6),
  68132 	},
  68133 	180: {
  68134 		Fcode:       int8(14),
  68135 		Fextra_bits: int8(6),
  68136 	},
  68137 	181: {
  68138 		Fcode:       int8(14),
  68139 		Fextra_bits: int8(6),
  68140 	},
  68141 	182: {
  68142 		Fcode:       int8(14),
  68143 		Fextra_bits: int8(6),
  68144 	},
  68145 	183: {
  68146 		Fcode:       int8(14),
  68147 		Fextra_bits: int8(6),
  68148 	},
  68149 	184: {
  68150 		Fcode:       int8(14),
  68151 		Fextra_bits: int8(6),
  68152 	},
  68153 	185: {
  68154 		Fcode:       int8(14),
  68155 		Fextra_bits: int8(6),
  68156 	},
  68157 	186: {
  68158 		Fcode:       int8(14),
  68159 		Fextra_bits: int8(6),
  68160 	},
  68161 	187: {
  68162 		Fcode:       int8(14),
  68163 		Fextra_bits: int8(6),
  68164 	},
  68165 	188: {
  68166 		Fcode:       int8(14),
  68167 		Fextra_bits: int8(6),
  68168 	},
  68169 	189: {
  68170 		Fcode:       int8(14),
  68171 		Fextra_bits: int8(6),
  68172 	},
  68173 	190: {
  68174 		Fcode:       int8(14),
  68175 		Fextra_bits: int8(6),
  68176 	},
  68177 	191: {
  68178 		Fcode:       int8(14),
  68179 		Fextra_bits: int8(6),
  68180 	},
  68181 	192: {
  68182 		Fcode:       int8(14),
  68183 		Fextra_bits: int8(6),
  68184 	},
  68185 	193: {
  68186 		Fcode:       int8(15),
  68187 		Fextra_bits: int8(6),
  68188 	},
  68189 	194: {
  68190 		Fcode:       int8(15),
  68191 		Fextra_bits: int8(6),
  68192 	},
  68193 	195: {
  68194 		Fcode:       int8(15),
  68195 		Fextra_bits: int8(6),
  68196 	},
  68197 	196: {
  68198 		Fcode:       int8(15),
  68199 		Fextra_bits: int8(6),
  68200 	},
  68201 	197: {
  68202 		Fcode:       int8(15),
  68203 		Fextra_bits: int8(6),
  68204 	},
  68205 	198: {
  68206 		Fcode:       int8(15),
  68207 		Fextra_bits: int8(6),
  68208 	},
  68209 	199: {
  68210 		Fcode:       int8(15),
  68211 		Fextra_bits: int8(6),
  68212 	},
  68213 	200: {
  68214 		Fcode:       int8(15),
  68215 		Fextra_bits: int8(6),
  68216 	},
  68217 	201: {
  68218 		Fcode:       int8(15),
  68219 		Fextra_bits: int8(6),
  68220 	},
  68221 	202: {
  68222 		Fcode:       int8(15),
  68223 		Fextra_bits: int8(6),
  68224 	},
  68225 	203: {
  68226 		Fcode:       int8(15),
  68227 		Fextra_bits: int8(6),
  68228 	},
  68229 	204: {
  68230 		Fcode:       int8(15),
  68231 		Fextra_bits: int8(6),
  68232 	},
  68233 	205: {
  68234 		Fcode:       int8(15),
  68235 		Fextra_bits: int8(6),
  68236 	},
  68237 	206: {
  68238 		Fcode:       int8(15),
  68239 		Fextra_bits: int8(6),
  68240 	},
  68241 	207: {
  68242 		Fcode:       int8(15),
  68243 		Fextra_bits: int8(6),
  68244 	},
  68245 	208: {
  68246 		Fcode:       int8(15),
  68247 		Fextra_bits: int8(6),
  68248 	},
  68249 	209: {
  68250 		Fcode:       int8(15),
  68251 		Fextra_bits: int8(6),
  68252 	},
  68253 	210: {
  68254 		Fcode:       int8(15),
  68255 		Fextra_bits: int8(6),
  68256 	},
  68257 	211: {
  68258 		Fcode:       int8(15),
  68259 		Fextra_bits: int8(6),
  68260 	},
  68261 	212: {
  68262 		Fcode:       int8(15),
  68263 		Fextra_bits: int8(6),
  68264 	},
  68265 	213: {
  68266 		Fcode:       int8(15),
  68267 		Fextra_bits: int8(6),
  68268 	},
  68269 	214: {
  68270 		Fcode:       int8(15),
  68271 		Fextra_bits: int8(6),
  68272 	},
  68273 	215: {
  68274 		Fcode:       int8(15),
  68275 		Fextra_bits: int8(6),
  68276 	},
  68277 	216: {
  68278 		Fcode:       int8(15),
  68279 		Fextra_bits: int8(6),
  68280 	},
  68281 	217: {
  68282 		Fcode:       int8(15),
  68283 		Fextra_bits: int8(6),
  68284 	},
  68285 	218: {
  68286 		Fcode:       int8(15),
  68287 		Fextra_bits: int8(6),
  68288 	},
  68289 	219: {
  68290 		Fcode:       int8(15),
  68291 		Fextra_bits: int8(6),
  68292 	},
  68293 	220: {
  68294 		Fcode:       int8(15),
  68295 		Fextra_bits: int8(6),
  68296 	},
  68297 	221: {
  68298 		Fcode:       int8(15),
  68299 		Fextra_bits: int8(6),
  68300 	},
  68301 	222: {
  68302 		Fcode:       int8(15),
  68303 		Fextra_bits: int8(6),
  68304 	},
  68305 	223: {
  68306 		Fcode:       int8(15),
  68307 		Fextra_bits: int8(6),
  68308 	},
  68309 	224: {
  68310 		Fcode:       int8(15),
  68311 		Fextra_bits: int8(6),
  68312 	},
  68313 	225: {
  68314 		Fcode:       int8(15),
  68315 		Fextra_bits: int8(6),
  68316 	},
  68317 	226: {
  68318 		Fcode:       int8(15),
  68319 		Fextra_bits: int8(6),
  68320 	},
  68321 	227: {
  68322 		Fcode:       int8(15),
  68323 		Fextra_bits: int8(6),
  68324 	},
  68325 	228: {
  68326 		Fcode:       int8(15),
  68327 		Fextra_bits: int8(6),
  68328 	},
  68329 	229: {
  68330 		Fcode:       int8(15),
  68331 		Fextra_bits: int8(6),
  68332 	},
  68333 	230: {
  68334 		Fcode:       int8(15),
  68335 		Fextra_bits: int8(6),
  68336 	},
  68337 	231: {
  68338 		Fcode:       int8(15),
  68339 		Fextra_bits: int8(6),
  68340 	},
  68341 	232: {
  68342 		Fcode:       int8(15),
  68343 		Fextra_bits: int8(6),
  68344 	},
  68345 	233: {
  68346 		Fcode:       int8(15),
  68347 		Fextra_bits: int8(6),
  68348 	},
  68349 	234: {
  68350 		Fcode:       int8(15),
  68351 		Fextra_bits: int8(6),
  68352 	},
  68353 	235: {
  68354 		Fcode:       int8(15),
  68355 		Fextra_bits: int8(6),
  68356 	},
  68357 	236: {
  68358 		Fcode:       int8(15),
  68359 		Fextra_bits: int8(6),
  68360 	},
  68361 	237: {
  68362 		Fcode:       int8(15),
  68363 		Fextra_bits: int8(6),
  68364 	},
  68365 	238: {
  68366 		Fcode:       int8(15),
  68367 		Fextra_bits: int8(6),
  68368 	},
  68369 	239: {
  68370 		Fcode:       int8(15),
  68371 		Fextra_bits: int8(6),
  68372 	},
  68373 	240: {
  68374 		Fcode:       int8(15),
  68375 		Fextra_bits: int8(6),
  68376 	},
  68377 	241: {
  68378 		Fcode:       int8(15),
  68379 		Fextra_bits: int8(6),
  68380 	},
  68381 	242: {
  68382 		Fcode:       int8(15),
  68383 		Fextra_bits: int8(6),
  68384 	},
  68385 	243: {
  68386 		Fcode:       int8(15),
  68387 		Fextra_bits: int8(6),
  68388 	},
  68389 	244: {
  68390 		Fcode:       int8(15),
  68391 		Fextra_bits: int8(6),
  68392 	},
  68393 	245: {
  68394 		Fcode:       int8(15),
  68395 		Fextra_bits: int8(6),
  68396 	},
  68397 	246: {
  68398 		Fcode:       int8(15),
  68399 		Fextra_bits: int8(6),
  68400 	},
  68401 	247: {
  68402 		Fcode:       int8(15),
  68403 		Fextra_bits: int8(6),
  68404 	},
  68405 	248: {
  68406 		Fcode:       int8(15),
  68407 		Fextra_bits: int8(6),
  68408 	},
  68409 	249: {
  68410 		Fcode:       int8(15),
  68411 		Fextra_bits: int8(6),
  68412 	},
  68413 	250: {
  68414 		Fcode:       int8(15),
  68415 		Fextra_bits: int8(6),
  68416 	},
  68417 	251: {
  68418 		Fcode:       int8(15),
  68419 		Fextra_bits: int8(6),
  68420 	},
  68421 	252: {
  68422 		Fcode:       int8(15),
  68423 		Fextra_bits: int8(6),
  68424 	},
  68425 	253: {
  68426 		Fcode:       int8(15),
  68427 		Fextra_bits: int8(6),
  68428 	},
  68429 	254: {
  68430 		Fcode:       int8(15),
  68431 		Fextra_bits: int8(6),
  68432 	},
  68433 	255: {
  68434 		Fcode:       int8(15),
  68435 		Fextra_bits: int8(6),
  68436 	},
  68437 	256: {
  68438 		Fcode:       int8(15),
  68439 		Fextra_bits: int8(6),
  68440 	},
  68441 	257: {
  68442 		Fcode:       int8(16),
  68443 		Fextra_bits: int8(7),
  68444 	},
  68445 	258: {
  68446 		Fcode:       int8(16),
  68447 		Fextra_bits: int8(7),
  68448 	},
  68449 	259: {
  68450 		Fcode:       int8(16),
  68451 		Fextra_bits: int8(7),
  68452 	},
  68453 	260: {
  68454 		Fcode:       int8(16),
  68455 		Fextra_bits: int8(7),
  68456 	},
  68457 	261: {
  68458 		Fcode:       int8(16),
  68459 		Fextra_bits: int8(7),
  68460 	},
  68461 	262: {
  68462 		Fcode:       int8(16),
  68463 		Fextra_bits: int8(7),
  68464 	},
  68465 	263: {
  68466 		Fcode:       int8(16),
  68467 		Fextra_bits: int8(7),
  68468 	},
  68469 	264: {
  68470 		Fcode:       int8(16),
  68471 		Fextra_bits: int8(7),
  68472 	},
  68473 	265: {
  68474 		Fcode:       int8(16),
  68475 		Fextra_bits: int8(7),
  68476 	},
  68477 	266: {
  68478 		Fcode:       int8(16),
  68479 		Fextra_bits: int8(7),
  68480 	},
  68481 	267: {
  68482 		Fcode:       int8(16),
  68483 		Fextra_bits: int8(7),
  68484 	},
  68485 	268: {
  68486 		Fcode:       int8(16),
  68487 		Fextra_bits: int8(7),
  68488 	},
  68489 	269: {
  68490 		Fcode:       int8(16),
  68491 		Fextra_bits: int8(7),
  68492 	},
  68493 	270: {
  68494 		Fcode:       int8(16),
  68495 		Fextra_bits: int8(7),
  68496 	},
  68497 	271: {
  68498 		Fcode:       int8(16),
  68499 		Fextra_bits: int8(7),
  68500 	},
  68501 	272: {
  68502 		Fcode:       int8(16),
  68503 		Fextra_bits: int8(7),
  68504 	},
  68505 	273: {
  68506 		Fcode:       int8(16),
  68507 		Fextra_bits: int8(7),
  68508 	},
  68509 	274: {
  68510 		Fcode:       int8(16),
  68511 		Fextra_bits: int8(7),
  68512 	},
  68513 	275: {
  68514 		Fcode:       int8(16),
  68515 		Fextra_bits: int8(7),
  68516 	},
  68517 	276: {
  68518 		Fcode:       int8(16),
  68519 		Fextra_bits: int8(7),
  68520 	},
  68521 	277: {
  68522 		Fcode:       int8(16),
  68523 		Fextra_bits: int8(7),
  68524 	},
  68525 	278: {
  68526 		Fcode:       int8(16),
  68527 		Fextra_bits: int8(7),
  68528 	},
  68529 	279: {
  68530 		Fcode:       int8(16),
  68531 		Fextra_bits: int8(7),
  68532 	},
  68533 	280: {
  68534 		Fcode:       int8(16),
  68535 		Fextra_bits: int8(7),
  68536 	},
  68537 	281: {
  68538 		Fcode:       int8(16),
  68539 		Fextra_bits: int8(7),
  68540 	},
  68541 	282: {
  68542 		Fcode:       int8(16),
  68543 		Fextra_bits: int8(7),
  68544 	},
  68545 	283: {
  68546 		Fcode:       int8(16),
  68547 		Fextra_bits: int8(7),
  68548 	},
  68549 	284: {
  68550 		Fcode:       int8(16),
  68551 		Fextra_bits: int8(7),
  68552 	},
  68553 	285: {
  68554 		Fcode:       int8(16),
  68555 		Fextra_bits: int8(7),
  68556 	},
  68557 	286: {
  68558 		Fcode:       int8(16),
  68559 		Fextra_bits: int8(7),
  68560 	},
  68561 	287: {
  68562 		Fcode:       int8(16),
  68563 		Fextra_bits: int8(7),
  68564 	},
  68565 	288: {
  68566 		Fcode:       int8(16),
  68567 		Fextra_bits: int8(7),
  68568 	},
  68569 	289: {
  68570 		Fcode:       int8(16),
  68571 		Fextra_bits: int8(7),
  68572 	},
  68573 	290: {
  68574 		Fcode:       int8(16),
  68575 		Fextra_bits: int8(7),
  68576 	},
  68577 	291: {
  68578 		Fcode:       int8(16),
  68579 		Fextra_bits: int8(7),
  68580 	},
  68581 	292: {
  68582 		Fcode:       int8(16),
  68583 		Fextra_bits: int8(7),
  68584 	},
  68585 	293: {
  68586 		Fcode:       int8(16),
  68587 		Fextra_bits: int8(7),
  68588 	},
  68589 	294: {
  68590 		Fcode:       int8(16),
  68591 		Fextra_bits: int8(7),
  68592 	},
  68593 	295: {
  68594 		Fcode:       int8(16),
  68595 		Fextra_bits: int8(7),
  68596 	},
  68597 	296: {
  68598 		Fcode:       int8(16),
  68599 		Fextra_bits: int8(7),
  68600 	},
  68601 	297: {
  68602 		Fcode:       int8(16),
  68603 		Fextra_bits: int8(7),
  68604 	},
  68605 	298: {
  68606 		Fcode:       int8(16),
  68607 		Fextra_bits: int8(7),
  68608 	},
  68609 	299: {
  68610 		Fcode:       int8(16),
  68611 		Fextra_bits: int8(7),
  68612 	},
  68613 	300: {
  68614 		Fcode:       int8(16),
  68615 		Fextra_bits: int8(7),
  68616 	},
  68617 	301: {
  68618 		Fcode:       int8(16),
  68619 		Fextra_bits: int8(7),
  68620 	},
  68621 	302: {
  68622 		Fcode:       int8(16),
  68623 		Fextra_bits: int8(7),
  68624 	},
  68625 	303: {
  68626 		Fcode:       int8(16),
  68627 		Fextra_bits: int8(7),
  68628 	},
  68629 	304: {
  68630 		Fcode:       int8(16),
  68631 		Fextra_bits: int8(7),
  68632 	},
  68633 	305: {
  68634 		Fcode:       int8(16),
  68635 		Fextra_bits: int8(7),
  68636 	},
  68637 	306: {
  68638 		Fcode:       int8(16),
  68639 		Fextra_bits: int8(7),
  68640 	},
  68641 	307: {
  68642 		Fcode:       int8(16),
  68643 		Fextra_bits: int8(7),
  68644 	},
  68645 	308: {
  68646 		Fcode:       int8(16),
  68647 		Fextra_bits: int8(7),
  68648 	},
  68649 	309: {
  68650 		Fcode:       int8(16),
  68651 		Fextra_bits: int8(7),
  68652 	},
  68653 	310: {
  68654 		Fcode:       int8(16),
  68655 		Fextra_bits: int8(7),
  68656 	},
  68657 	311: {
  68658 		Fcode:       int8(16),
  68659 		Fextra_bits: int8(7),
  68660 	},
  68661 	312: {
  68662 		Fcode:       int8(16),
  68663 		Fextra_bits: int8(7),
  68664 	},
  68665 	313: {
  68666 		Fcode:       int8(16),
  68667 		Fextra_bits: int8(7),
  68668 	},
  68669 	314: {
  68670 		Fcode:       int8(16),
  68671 		Fextra_bits: int8(7),
  68672 	},
  68673 	315: {
  68674 		Fcode:       int8(16),
  68675 		Fextra_bits: int8(7),
  68676 	},
  68677 	316: {
  68678 		Fcode:       int8(16),
  68679 		Fextra_bits: int8(7),
  68680 	},
  68681 	317: {
  68682 		Fcode:       int8(16),
  68683 		Fextra_bits: int8(7),
  68684 	},
  68685 	318: {
  68686 		Fcode:       int8(16),
  68687 		Fextra_bits: int8(7),
  68688 	},
  68689 	319: {
  68690 		Fcode:       int8(16),
  68691 		Fextra_bits: int8(7),
  68692 	},
  68693 	320: {
  68694 		Fcode:       int8(16),
  68695 		Fextra_bits: int8(7),
  68696 	},
  68697 	321: {
  68698 		Fcode:       int8(16),
  68699 		Fextra_bits: int8(7),
  68700 	},
  68701 	322: {
  68702 		Fcode:       int8(16),
  68703 		Fextra_bits: int8(7),
  68704 	},
  68705 	323: {
  68706 		Fcode:       int8(16),
  68707 		Fextra_bits: int8(7),
  68708 	},
  68709 	324: {
  68710 		Fcode:       int8(16),
  68711 		Fextra_bits: int8(7),
  68712 	},
  68713 	325: {
  68714 		Fcode:       int8(16),
  68715 		Fextra_bits: int8(7),
  68716 	},
  68717 	326: {
  68718 		Fcode:       int8(16),
  68719 		Fextra_bits: int8(7),
  68720 	},
  68721 	327: {
  68722 		Fcode:       int8(16),
  68723 		Fextra_bits: int8(7),
  68724 	},
  68725 	328: {
  68726 		Fcode:       int8(16),
  68727 		Fextra_bits: int8(7),
  68728 	},
  68729 	329: {
  68730 		Fcode:       int8(16),
  68731 		Fextra_bits: int8(7),
  68732 	},
  68733 	330: {
  68734 		Fcode:       int8(16),
  68735 		Fextra_bits: int8(7),
  68736 	},
  68737 	331: {
  68738 		Fcode:       int8(16),
  68739 		Fextra_bits: int8(7),
  68740 	},
  68741 	332: {
  68742 		Fcode:       int8(16),
  68743 		Fextra_bits: int8(7),
  68744 	},
  68745 	333: {
  68746 		Fcode:       int8(16),
  68747 		Fextra_bits: int8(7),
  68748 	},
  68749 	334: {
  68750 		Fcode:       int8(16),
  68751 		Fextra_bits: int8(7),
  68752 	},
  68753 	335: {
  68754 		Fcode:       int8(16),
  68755 		Fextra_bits: int8(7),
  68756 	},
  68757 	336: {
  68758 		Fcode:       int8(16),
  68759 		Fextra_bits: int8(7),
  68760 	},
  68761 	337: {
  68762 		Fcode:       int8(16),
  68763 		Fextra_bits: int8(7),
  68764 	},
  68765 	338: {
  68766 		Fcode:       int8(16),
  68767 		Fextra_bits: int8(7),
  68768 	},
  68769 	339: {
  68770 		Fcode:       int8(16),
  68771 		Fextra_bits: int8(7),
  68772 	},
  68773 	340: {
  68774 		Fcode:       int8(16),
  68775 		Fextra_bits: int8(7),
  68776 	},
  68777 	341: {
  68778 		Fcode:       int8(16),
  68779 		Fextra_bits: int8(7),
  68780 	},
  68781 	342: {
  68782 		Fcode:       int8(16),
  68783 		Fextra_bits: int8(7),
  68784 	},
  68785 	343: {
  68786 		Fcode:       int8(16),
  68787 		Fextra_bits: int8(7),
  68788 	},
  68789 	344: {
  68790 		Fcode:       int8(16),
  68791 		Fextra_bits: int8(7),
  68792 	},
  68793 	345: {
  68794 		Fcode:       int8(16),
  68795 		Fextra_bits: int8(7),
  68796 	},
  68797 	346: {
  68798 		Fcode:       int8(16),
  68799 		Fextra_bits: int8(7),
  68800 	},
  68801 	347: {
  68802 		Fcode:       int8(16),
  68803 		Fextra_bits: int8(7),
  68804 	},
  68805 	348: {
  68806 		Fcode:       int8(16),
  68807 		Fextra_bits: int8(7),
  68808 	},
  68809 	349: {
  68810 		Fcode:       int8(16),
  68811 		Fextra_bits: int8(7),
  68812 	},
  68813 	350: {
  68814 		Fcode:       int8(16),
  68815 		Fextra_bits: int8(7),
  68816 	},
  68817 	351: {
  68818 		Fcode:       int8(16),
  68819 		Fextra_bits: int8(7),
  68820 	},
  68821 	352: {
  68822 		Fcode:       int8(16),
  68823 		Fextra_bits: int8(7),
  68824 	},
  68825 	353: {
  68826 		Fcode:       int8(16),
  68827 		Fextra_bits: int8(7),
  68828 	},
  68829 	354: {
  68830 		Fcode:       int8(16),
  68831 		Fextra_bits: int8(7),
  68832 	},
  68833 	355: {
  68834 		Fcode:       int8(16),
  68835 		Fextra_bits: int8(7),
  68836 	},
  68837 	356: {
  68838 		Fcode:       int8(16),
  68839 		Fextra_bits: int8(7),
  68840 	},
  68841 	357: {
  68842 		Fcode:       int8(16),
  68843 		Fextra_bits: int8(7),
  68844 	},
  68845 	358: {
  68846 		Fcode:       int8(16),
  68847 		Fextra_bits: int8(7),
  68848 	},
  68849 	359: {
  68850 		Fcode:       int8(16),
  68851 		Fextra_bits: int8(7),
  68852 	},
  68853 	360: {
  68854 		Fcode:       int8(16),
  68855 		Fextra_bits: int8(7),
  68856 	},
  68857 	361: {
  68858 		Fcode:       int8(16),
  68859 		Fextra_bits: int8(7),
  68860 	},
  68861 	362: {
  68862 		Fcode:       int8(16),
  68863 		Fextra_bits: int8(7),
  68864 	},
  68865 	363: {
  68866 		Fcode:       int8(16),
  68867 		Fextra_bits: int8(7),
  68868 	},
  68869 	364: {
  68870 		Fcode:       int8(16),
  68871 		Fextra_bits: int8(7),
  68872 	},
  68873 	365: {
  68874 		Fcode:       int8(16),
  68875 		Fextra_bits: int8(7),
  68876 	},
  68877 	366: {
  68878 		Fcode:       int8(16),
  68879 		Fextra_bits: int8(7),
  68880 	},
  68881 	367: {
  68882 		Fcode:       int8(16),
  68883 		Fextra_bits: int8(7),
  68884 	},
  68885 	368: {
  68886 		Fcode:       int8(16),
  68887 		Fextra_bits: int8(7),
  68888 	},
  68889 	369: {
  68890 		Fcode:       int8(16),
  68891 		Fextra_bits: int8(7),
  68892 	},
  68893 	370: {
  68894 		Fcode:       int8(16),
  68895 		Fextra_bits: int8(7),
  68896 	},
  68897 	371: {
  68898 		Fcode:       int8(16),
  68899 		Fextra_bits: int8(7),
  68900 	},
  68901 	372: {
  68902 		Fcode:       int8(16),
  68903 		Fextra_bits: int8(7),
  68904 	},
  68905 	373: {
  68906 		Fcode:       int8(16),
  68907 		Fextra_bits: int8(7),
  68908 	},
  68909 	374: {
  68910 		Fcode:       int8(16),
  68911 		Fextra_bits: int8(7),
  68912 	},
  68913 	375: {
  68914 		Fcode:       int8(16),
  68915 		Fextra_bits: int8(7),
  68916 	},
  68917 	376: {
  68918 		Fcode:       int8(16),
  68919 		Fextra_bits: int8(7),
  68920 	},
  68921 	377: {
  68922 		Fcode:       int8(16),
  68923 		Fextra_bits: int8(7),
  68924 	},
  68925 	378: {
  68926 		Fcode:       int8(16),
  68927 		Fextra_bits: int8(7),
  68928 	},
  68929 	379: {
  68930 		Fcode:       int8(16),
  68931 		Fextra_bits: int8(7),
  68932 	},
  68933 	380: {
  68934 		Fcode:       int8(16),
  68935 		Fextra_bits: int8(7),
  68936 	},
  68937 	381: {
  68938 		Fcode:       int8(16),
  68939 		Fextra_bits: int8(7),
  68940 	},
  68941 	382: {
  68942 		Fcode:       int8(16),
  68943 		Fextra_bits: int8(7),
  68944 	},
  68945 	383: {
  68946 		Fcode:       int8(16),
  68947 		Fextra_bits: int8(7),
  68948 	},
  68949 	384: {
  68950 		Fcode:       int8(16),
  68951 		Fextra_bits: int8(7),
  68952 	},
  68953 	385: {
  68954 		Fcode:       int8(17),
  68955 		Fextra_bits: int8(7),
  68956 	},
  68957 	386: {
  68958 		Fcode:       int8(17),
  68959 		Fextra_bits: int8(7),
  68960 	},
  68961 	387: {
  68962 		Fcode:       int8(17),
  68963 		Fextra_bits: int8(7),
  68964 	},
  68965 	388: {
  68966 		Fcode:       int8(17),
  68967 		Fextra_bits: int8(7),
  68968 	},
  68969 	389: {
  68970 		Fcode:       int8(17),
  68971 		Fextra_bits: int8(7),
  68972 	},
  68973 	390: {
  68974 		Fcode:       int8(17),
  68975 		Fextra_bits: int8(7),
  68976 	},
  68977 	391: {
  68978 		Fcode:       int8(17),
  68979 		Fextra_bits: int8(7),
  68980 	},
  68981 	392: {
  68982 		Fcode:       int8(17),
  68983 		Fextra_bits: int8(7),
  68984 	},
  68985 	393: {
  68986 		Fcode:       int8(17),
  68987 		Fextra_bits: int8(7),
  68988 	},
  68989 	394: {
  68990 		Fcode:       int8(17),
  68991 		Fextra_bits: int8(7),
  68992 	},
  68993 	395: {
  68994 		Fcode:       int8(17),
  68995 		Fextra_bits: int8(7),
  68996 	},
  68997 	396: {
  68998 		Fcode:       int8(17),
  68999 		Fextra_bits: int8(7),
  69000 	},
  69001 	397: {
  69002 		Fcode:       int8(17),
  69003 		Fextra_bits: int8(7),
  69004 	},
  69005 	398: {
  69006 		Fcode:       int8(17),
  69007 		Fextra_bits: int8(7),
  69008 	},
  69009 	399: {
  69010 		Fcode:       int8(17),
  69011 		Fextra_bits: int8(7),
  69012 	},
  69013 	400: {
  69014 		Fcode:       int8(17),
  69015 		Fextra_bits: int8(7),
  69016 	},
  69017 	401: {
  69018 		Fcode:       int8(17),
  69019 		Fextra_bits: int8(7),
  69020 	},
  69021 	402: {
  69022 		Fcode:       int8(17),
  69023 		Fextra_bits: int8(7),
  69024 	},
  69025 	403: {
  69026 		Fcode:       int8(17),
  69027 		Fextra_bits: int8(7),
  69028 	},
  69029 	404: {
  69030 		Fcode:       int8(17),
  69031 		Fextra_bits: int8(7),
  69032 	},
  69033 	405: {
  69034 		Fcode:       int8(17),
  69035 		Fextra_bits: int8(7),
  69036 	},
  69037 	406: {
  69038 		Fcode:       int8(17),
  69039 		Fextra_bits: int8(7),
  69040 	},
  69041 	407: {
  69042 		Fcode:       int8(17),
  69043 		Fextra_bits: int8(7),
  69044 	},
  69045 	408: {
  69046 		Fcode:       int8(17),
  69047 		Fextra_bits: int8(7),
  69048 	},
  69049 	409: {
  69050 		Fcode:       int8(17),
  69051 		Fextra_bits: int8(7),
  69052 	},
  69053 	410: {
  69054 		Fcode:       int8(17),
  69055 		Fextra_bits: int8(7),
  69056 	},
  69057 	411: {
  69058 		Fcode:       int8(17),
  69059 		Fextra_bits: int8(7),
  69060 	},
  69061 	412: {
  69062 		Fcode:       int8(17),
  69063 		Fextra_bits: int8(7),
  69064 	},
  69065 	413: {
  69066 		Fcode:       int8(17),
  69067 		Fextra_bits: int8(7),
  69068 	},
  69069 	414: {
  69070 		Fcode:       int8(17),
  69071 		Fextra_bits: int8(7),
  69072 	},
  69073 	415: {
  69074 		Fcode:       int8(17),
  69075 		Fextra_bits: int8(7),
  69076 	},
  69077 	416: {
  69078 		Fcode:       int8(17),
  69079 		Fextra_bits: int8(7),
  69080 	},
  69081 	417: {
  69082 		Fcode:       int8(17),
  69083 		Fextra_bits: int8(7),
  69084 	},
  69085 	418: {
  69086 		Fcode:       int8(17),
  69087 		Fextra_bits: int8(7),
  69088 	},
  69089 	419: {
  69090 		Fcode:       int8(17),
  69091 		Fextra_bits: int8(7),
  69092 	},
  69093 	420: {
  69094 		Fcode:       int8(17),
  69095 		Fextra_bits: int8(7),
  69096 	},
  69097 	421: {
  69098 		Fcode:       int8(17),
  69099 		Fextra_bits: int8(7),
  69100 	},
  69101 	422: {
  69102 		Fcode:       int8(17),
  69103 		Fextra_bits: int8(7),
  69104 	},
  69105 	423: {
  69106 		Fcode:       int8(17),
  69107 		Fextra_bits: int8(7),
  69108 	},
  69109 	424: {
  69110 		Fcode:       int8(17),
  69111 		Fextra_bits: int8(7),
  69112 	},
  69113 	425: {
  69114 		Fcode:       int8(17),
  69115 		Fextra_bits: int8(7),
  69116 	},
  69117 	426: {
  69118 		Fcode:       int8(17),
  69119 		Fextra_bits: int8(7),
  69120 	},
  69121 	427: {
  69122 		Fcode:       int8(17),
  69123 		Fextra_bits: int8(7),
  69124 	},
  69125 	428: {
  69126 		Fcode:       int8(17),
  69127 		Fextra_bits: int8(7),
  69128 	},
  69129 	429: {
  69130 		Fcode:       int8(17),
  69131 		Fextra_bits: int8(7),
  69132 	},
  69133 	430: {
  69134 		Fcode:       int8(17),
  69135 		Fextra_bits: int8(7),
  69136 	},
  69137 	431: {
  69138 		Fcode:       int8(17),
  69139 		Fextra_bits: int8(7),
  69140 	},
  69141 	432: {
  69142 		Fcode:       int8(17),
  69143 		Fextra_bits: int8(7),
  69144 	},
  69145 	433: {
  69146 		Fcode:       int8(17),
  69147 		Fextra_bits: int8(7),
  69148 	},
  69149 	434: {
  69150 		Fcode:       int8(17),
  69151 		Fextra_bits: int8(7),
  69152 	},
  69153 	435: {
  69154 		Fcode:       int8(17),
  69155 		Fextra_bits: int8(7),
  69156 	},
  69157 	436: {
  69158 		Fcode:       int8(17),
  69159 		Fextra_bits: int8(7),
  69160 	},
  69161 	437: {
  69162 		Fcode:       int8(17),
  69163 		Fextra_bits: int8(7),
  69164 	},
  69165 	438: {
  69166 		Fcode:       int8(17),
  69167 		Fextra_bits: int8(7),
  69168 	},
  69169 	439: {
  69170 		Fcode:       int8(17),
  69171 		Fextra_bits: int8(7),
  69172 	},
  69173 	440: {
  69174 		Fcode:       int8(17),
  69175 		Fextra_bits: int8(7),
  69176 	},
  69177 	441: {
  69178 		Fcode:       int8(17),
  69179 		Fextra_bits: int8(7),
  69180 	},
  69181 	442: {
  69182 		Fcode:       int8(17),
  69183 		Fextra_bits: int8(7),
  69184 	},
  69185 	443: {
  69186 		Fcode:       int8(17),
  69187 		Fextra_bits: int8(7),
  69188 	},
  69189 	444: {
  69190 		Fcode:       int8(17),
  69191 		Fextra_bits: int8(7),
  69192 	},
  69193 	445: {
  69194 		Fcode:       int8(17),
  69195 		Fextra_bits: int8(7),
  69196 	},
  69197 	446: {
  69198 		Fcode:       int8(17),
  69199 		Fextra_bits: int8(7),
  69200 	},
  69201 	447: {
  69202 		Fcode:       int8(17),
  69203 		Fextra_bits: int8(7),
  69204 	},
  69205 	448: {
  69206 		Fcode:       int8(17),
  69207 		Fextra_bits: int8(7),
  69208 	},
  69209 	449: {
  69210 		Fcode:       int8(17),
  69211 		Fextra_bits: int8(7),
  69212 	},
  69213 	450: {
  69214 		Fcode:       int8(17),
  69215 		Fextra_bits: int8(7),
  69216 	},
  69217 	451: {
  69218 		Fcode:       int8(17),
  69219 		Fextra_bits: int8(7),
  69220 	},
  69221 	452: {
  69222 		Fcode:       int8(17),
  69223 		Fextra_bits: int8(7),
  69224 	},
  69225 	453: {
  69226 		Fcode:       int8(17),
  69227 		Fextra_bits: int8(7),
  69228 	},
  69229 	454: {
  69230 		Fcode:       int8(17),
  69231 		Fextra_bits: int8(7),
  69232 	},
  69233 	455: {
  69234 		Fcode:       int8(17),
  69235 		Fextra_bits: int8(7),
  69236 	},
  69237 	456: {
  69238 		Fcode:       int8(17),
  69239 		Fextra_bits: int8(7),
  69240 	},
  69241 	457: {
  69242 		Fcode:       int8(17),
  69243 		Fextra_bits: int8(7),
  69244 	},
  69245 	458: {
  69246 		Fcode:       int8(17),
  69247 		Fextra_bits: int8(7),
  69248 	},
  69249 	459: {
  69250 		Fcode:       int8(17),
  69251 		Fextra_bits: int8(7),
  69252 	},
  69253 	460: {
  69254 		Fcode:       int8(17),
  69255 		Fextra_bits: int8(7),
  69256 	},
  69257 	461: {
  69258 		Fcode:       int8(17),
  69259 		Fextra_bits: int8(7),
  69260 	},
  69261 	462: {
  69262 		Fcode:       int8(17),
  69263 		Fextra_bits: int8(7),
  69264 	},
  69265 	463: {
  69266 		Fcode:       int8(17),
  69267 		Fextra_bits: int8(7),
  69268 	},
  69269 	464: {
  69270 		Fcode:       int8(17),
  69271 		Fextra_bits: int8(7),
  69272 	},
  69273 	465: {
  69274 		Fcode:       int8(17),
  69275 		Fextra_bits: int8(7),
  69276 	},
  69277 	466: {
  69278 		Fcode:       int8(17),
  69279 		Fextra_bits: int8(7),
  69280 	},
  69281 	467: {
  69282 		Fcode:       int8(17),
  69283 		Fextra_bits: int8(7),
  69284 	},
  69285 	468: {
  69286 		Fcode:       int8(17),
  69287 		Fextra_bits: int8(7),
  69288 	},
  69289 	469: {
  69290 		Fcode:       int8(17),
  69291 		Fextra_bits: int8(7),
  69292 	},
  69293 	470: {
  69294 		Fcode:       int8(17),
  69295 		Fextra_bits: int8(7),
  69296 	},
  69297 	471: {
  69298 		Fcode:       int8(17),
  69299 		Fextra_bits: int8(7),
  69300 	},
  69301 	472: {
  69302 		Fcode:       int8(17),
  69303 		Fextra_bits: int8(7),
  69304 	},
  69305 	473: {
  69306 		Fcode:       int8(17),
  69307 		Fextra_bits: int8(7),
  69308 	},
  69309 	474: {
  69310 		Fcode:       int8(17),
  69311 		Fextra_bits: int8(7),
  69312 	},
  69313 	475: {
  69314 		Fcode:       int8(17),
  69315 		Fextra_bits: int8(7),
  69316 	},
  69317 	476: {
  69318 		Fcode:       int8(17),
  69319 		Fextra_bits: int8(7),
  69320 	},
  69321 	477: {
  69322 		Fcode:       int8(17),
  69323 		Fextra_bits: int8(7),
  69324 	},
  69325 	478: {
  69326 		Fcode:       int8(17),
  69327 		Fextra_bits: int8(7),
  69328 	},
  69329 	479: {
  69330 		Fcode:       int8(17),
  69331 		Fextra_bits: int8(7),
  69332 	},
  69333 	480: {
  69334 		Fcode:       int8(17),
  69335 		Fextra_bits: int8(7),
  69336 	},
  69337 	481: {
  69338 		Fcode:       int8(17),
  69339 		Fextra_bits: int8(7),
  69340 	},
  69341 	482: {
  69342 		Fcode:       int8(17),
  69343 		Fextra_bits: int8(7),
  69344 	},
  69345 	483: {
  69346 		Fcode:       int8(17),
  69347 		Fextra_bits: int8(7),
  69348 	},
  69349 	484: {
  69350 		Fcode:       int8(17),
  69351 		Fextra_bits: int8(7),
  69352 	},
  69353 	485: {
  69354 		Fcode:       int8(17),
  69355 		Fextra_bits: int8(7),
  69356 	},
  69357 	486: {
  69358 		Fcode:       int8(17),
  69359 		Fextra_bits: int8(7),
  69360 	},
  69361 	487: {
  69362 		Fcode:       int8(17),
  69363 		Fextra_bits: int8(7),
  69364 	},
  69365 	488: {
  69366 		Fcode:       int8(17),
  69367 		Fextra_bits: int8(7),
  69368 	},
  69369 	489: {
  69370 		Fcode:       int8(17),
  69371 		Fextra_bits: int8(7),
  69372 	},
  69373 	490: {
  69374 		Fcode:       int8(17),
  69375 		Fextra_bits: int8(7),
  69376 	},
  69377 	491: {
  69378 		Fcode:       int8(17),
  69379 		Fextra_bits: int8(7),
  69380 	},
  69381 	492: {
  69382 		Fcode:       int8(17),
  69383 		Fextra_bits: int8(7),
  69384 	},
  69385 	493: {
  69386 		Fcode:       int8(17),
  69387 		Fextra_bits: int8(7),
  69388 	},
  69389 	494: {
  69390 		Fcode:       int8(17),
  69391 		Fextra_bits: int8(7),
  69392 	},
  69393 	495: {
  69394 		Fcode:       int8(17),
  69395 		Fextra_bits: int8(7),
  69396 	},
  69397 	496: {
  69398 		Fcode:       int8(17),
  69399 		Fextra_bits: int8(7),
  69400 	},
  69401 	497: {
  69402 		Fcode:       int8(17),
  69403 		Fextra_bits: int8(7),
  69404 	},
  69405 	498: {
  69406 		Fcode:       int8(17),
  69407 		Fextra_bits: int8(7),
  69408 	},
  69409 	499: {
  69410 		Fcode:       int8(17),
  69411 		Fextra_bits: int8(7),
  69412 	},
  69413 	500: {
  69414 		Fcode:       int8(17),
  69415 		Fextra_bits: int8(7),
  69416 	},
  69417 	501: {
  69418 		Fcode:       int8(17),
  69419 		Fextra_bits: int8(7),
  69420 	},
  69421 	502: {
  69422 		Fcode:       int8(17),
  69423 		Fextra_bits: int8(7),
  69424 	},
  69425 	503: {
  69426 		Fcode:       int8(17),
  69427 		Fextra_bits: int8(7),
  69428 	},
  69429 	504: {
  69430 		Fcode:       int8(17),
  69431 		Fextra_bits: int8(7),
  69432 	},
  69433 	505: {
  69434 		Fcode:       int8(17),
  69435 		Fextra_bits: int8(7),
  69436 	},
  69437 	506: {
  69438 		Fcode:       int8(17),
  69439 		Fextra_bits: int8(7),
  69440 	},
  69441 	507: {
  69442 		Fcode:       int8(17),
  69443 		Fextra_bits: int8(7),
  69444 	},
  69445 	508: {
  69446 		Fcode:       int8(17),
  69447 		Fextra_bits: int8(7),
  69448 	},
  69449 	509: {
  69450 		Fcode:       int8(17),
  69451 		Fextra_bits: int8(7),
  69452 	},
  69453 	510: {
  69454 		Fcode:       int8(17),
  69455 		Fextra_bits: int8(7),
  69456 	},
  69457 	511: {
  69458 		Fcode:       int8(17),
  69459 		Fextra_bits: int8(7),
  69460 	},
  69461 }
  69462 
  69463 var kPrefixEncodeExtraBitsValue = [512]uint8_t{
  69464 	6:   uint8(1),
  69465 	8:   uint8(1),
  69466 	10:  uint8(1),
  69467 	11:  uint8(2),
  69468 	12:  uint8(3),
  69469 	14:  uint8(1),
  69470 	15:  uint8(2),
  69471 	16:  uint8(3),
  69472 	18:  uint8(1),
  69473 	19:  uint8(2),
  69474 	20:  uint8(3),
  69475 	21:  uint8(4),
  69476 	22:  uint8(5),
  69477 	23:  uint8(6),
  69478 	24:  uint8(7),
  69479 	26:  uint8(1),
  69480 	27:  uint8(2),
  69481 	28:  uint8(3),
  69482 	29:  uint8(4),
  69483 	30:  uint8(5),
  69484 	31:  uint8(6),
  69485 	32:  uint8(7),
  69486 	34:  uint8(1),
  69487 	35:  uint8(2),
  69488 	36:  uint8(3),
  69489 	37:  uint8(4),
  69490 	38:  uint8(5),
  69491 	39:  uint8(6),
  69492 	40:  uint8(7),
  69493 	41:  uint8(8),
  69494 	42:  uint8(9),
  69495 	43:  uint8(10),
  69496 	44:  uint8(11),
  69497 	45:  uint8(12),
  69498 	46:  uint8(13),
  69499 	47:  uint8(14),
  69500 	48:  uint8(15),
  69501 	50:  uint8(1),
  69502 	51:  uint8(2),
  69503 	52:  uint8(3),
  69504 	53:  uint8(4),
  69505 	54:  uint8(5),
  69506 	55:  uint8(6),
  69507 	56:  uint8(7),
  69508 	57:  uint8(8),
  69509 	58:  uint8(9),
  69510 	59:  uint8(10),
  69511 	60:  uint8(11),
  69512 	61:  uint8(12),
  69513 	62:  uint8(13),
  69514 	63:  uint8(14),
  69515 	64:  uint8(15),
  69516 	66:  uint8(1),
  69517 	67:  uint8(2),
  69518 	68:  uint8(3),
  69519 	69:  uint8(4),
  69520 	70:  uint8(5),
  69521 	71:  uint8(6),
  69522 	72:  uint8(7),
  69523 	73:  uint8(8),
  69524 	74:  uint8(9),
  69525 	75:  uint8(10),
  69526 	76:  uint8(11),
  69527 	77:  uint8(12),
  69528 	78:  uint8(13),
  69529 	79:  uint8(14),
  69530 	80:  uint8(15),
  69531 	81:  uint8(16),
  69532 	82:  uint8(17),
  69533 	83:  uint8(18),
  69534 	84:  uint8(19),
  69535 	85:  uint8(20),
  69536 	86:  uint8(21),
  69537 	87:  uint8(22),
  69538 	88:  uint8(23),
  69539 	89:  uint8(24),
  69540 	90:  uint8(25),
  69541 	91:  uint8(26),
  69542 	92:  uint8(27),
  69543 	93:  uint8(28),
  69544 	94:  uint8(29),
  69545 	95:  uint8(30),
  69546 	96:  uint8(31),
  69547 	98:  uint8(1),
  69548 	99:  uint8(2),
  69549 	100: uint8(3),
  69550 	101: uint8(4),
  69551 	102: uint8(5),
  69552 	103: uint8(6),
  69553 	104: uint8(7),
  69554 	105: uint8(8),
  69555 	106: uint8(9),
  69556 	107: uint8(10),
  69557 	108: uint8(11),
  69558 	109: uint8(12),
  69559 	110: uint8(13),
  69560 	111: uint8(14),
  69561 	112: uint8(15),
  69562 	113: uint8(16),
  69563 	114: uint8(17),
  69564 	115: uint8(18),
  69565 	116: uint8(19),
  69566 	117: uint8(20),
  69567 	118: uint8(21),
  69568 	119: uint8(22),
  69569 	120: uint8(23),
  69570 	121: uint8(24),
  69571 	122: uint8(25),
  69572 	123: uint8(26),
  69573 	124: uint8(27),
  69574 	125: uint8(28),
  69575 	126: uint8(29),
  69576 	127: uint8(30),
  69577 	128: uint8(31),
  69578 	130: uint8(1),
  69579 	131: uint8(2),
  69580 	132: uint8(3),
  69581 	133: uint8(4),
  69582 	134: uint8(5),
  69583 	135: uint8(6),
  69584 	136: uint8(7),
  69585 	137: uint8(8),
  69586 	138: uint8(9),
  69587 	139: uint8(10),
  69588 	140: uint8(11),
  69589 	141: uint8(12),
  69590 	142: uint8(13),
  69591 	143: uint8(14),
  69592 	144: uint8(15),
  69593 	145: uint8(16),
  69594 	146: uint8(17),
  69595 	147: uint8(18),
  69596 	148: uint8(19),
  69597 	149: uint8(20),
  69598 	150: uint8(21),
  69599 	151: uint8(22),
  69600 	152: uint8(23),
  69601 	153: uint8(24),
  69602 	154: uint8(25),
  69603 	155: uint8(26),
  69604 	156: uint8(27),
  69605 	157: uint8(28),
  69606 	158: uint8(29),
  69607 	159: uint8(30),
  69608 	160: uint8(31),
  69609 	161: uint8(32),
  69610 	162: uint8(33),
  69611 	163: uint8(34),
  69612 	164: uint8(35),
  69613 	165: uint8(36),
  69614 	166: uint8(37),
  69615 	167: uint8(38),
  69616 	168: uint8(39),
  69617 	169: uint8(40),
  69618 	170: uint8(41),
  69619 	171: uint8(42),
  69620 	172: uint8(43),
  69621 	173: uint8(44),
  69622 	174: uint8(45),
  69623 	175: uint8(46),
  69624 	176: uint8(47),
  69625 	177: uint8(48),
  69626 	178: uint8(49),
  69627 	179: uint8(50),
  69628 	180: uint8(51),
  69629 	181: uint8(52),
  69630 	182: uint8(53),
  69631 	183: uint8(54),
  69632 	184: uint8(55),
  69633 	185: uint8(56),
  69634 	186: uint8(57),
  69635 	187: uint8(58),
  69636 	188: uint8(59),
  69637 	189: uint8(60),
  69638 	190: uint8(61),
  69639 	191: uint8(62),
  69640 	192: uint8(63),
  69641 	194: uint8(1),
  69642 	195: uint8(2),
  69643 	196: uint8(3),
  69644 	197: uint8(4),
  69645 	198: uint8(5),
  69646 	199: uint8(6),
  69647 	200: uint8(7),
  69648 	201: uint8(8),
  69649 	202: uint8(9),
  69650 	203: uint8(10),
  69651 	204: uint8(11),
  69652 	205: uint8(12),
  69653 	206: uint8(13),
  69654 	207: uint8(14),
  69655 	208: uint8(15),
  69656 	209: uint8(16),
  69657 	210: uint8(17),
  69658 	211: uint8(18),
  69659 	212: uint8(19),
  69660 	213: uint8(20),
  69661 	214: uint8(21),
  69662 	215: uint8(22),
  69663 	216: uint8(23),
  69664 	217: uint8(24),
  69665 	218: uint8(25),
  69666 	219: uint8(26),
  69667 	220: uint8(27),
  69668 	221: uint8(28),
  69669 	222: uint8(29),
  69670 	223: uint8(30),
  69671 	224: uint8(31),
  69672 	225: uint8(32),
  69673 	226: uint8(33),
  69674 	227: uint8(34),
  69675 	228: uint8(35),
  69676 	229: uint8(36),
  69677 	230: uint8(37),
  69678 	231: uint8(38),
  69679 	232: uint8(39),
  69680 	233: uint8(40),
  69681 	234: uint8(41),
  69682 	235: uint8(42),
  69683 	236: uint8(43),
  69684 	237: uint8(44),
  69685 	238: uint8(45),
  69686 	239: uint8(46),
  69687 	240: uint8(47),
  69688 	241: uint8(48),
  69689 	242: uint8(49),
  69690 	243: uint8(50),
  69691 	244: uint8(51),
  69692 	245: uint8(52),
  69693 	246: uint8(53),
  69694 	247: uint8(54),
  69695 	248: uint8(55),
  69696 	249: uint8(56),
  69697 	250: uint8(57),
  69698 	251: uint8(58),
  69699 	252: uint8(59),
  69700 	253: uint8(60),
  69701 	254: uint8(61),
  69702 	255: uint8(62),
  69703 	256: uint8(63),
  69704 	258: uint8(1),
  69705 	259: uint8(2),
  69706 	260: uint8(3),
  69707 	261: uint8(4),
  69708 	262: uint8(5),
  69709 	263: uint8(6),
  69710 	264: uint8(7),
  69711 	265: uint8(8),
  69712 	266: uint8(9),
  69713 	267: uint8(10),
  69714 	268: uint8(11),
  69715 	269: uint8(12),
  69716 	270: uint8(13),
  69717 	271: uint8(14),
  69718 	272: uint8(15),
  69719 	273: uint8(16),
  69720 	274: uint8(17),
  69721 	275: uint8(18),
  69722 	276: uint8(19),
  69723 	277: uint8(20),
  69724 	278: uint8(21),
  69725 	279: uint8(22),
  69726 	280: uint8(23),
  69727 	281: uint8(24),
  69728 	282: uint8(25),
  69729 	283: uint8(26),
  69730 	284: uint8(27),
  69731 	285: uint8(28),
  69732 	286: uint8(29),
  69733 	287: uint8(30),
  69734 	288: uint8(31),
  69735 	289: uint8(32),
  69736 	290: uint8(33),
  69737 	291: uint8(34),
  69738 	292: uint8(35),
  69739 	293: uint8(36),
  69740 	294: uint8(37),
  69741 	295: uint8(38),
  69742 	296: uint8(39),
  69743 	297: uint8(40),
  69744 	298: uint8(41),
  69745 	299: uint8(42),
  69746 	300: uint8(43),
  69747 	301: uint8(44),
  69748 	302: uint8(45),
  69749 	303: uint8(46),
  69750 	304: uint8(47),
  69751 	305: uint8(48),
  69752 	306: uint8(49),
  69753 	307: uint8(50),
  69754 	308: uint8(51),
  69755 	309: uint8(52),
  69756 	310: uint8(53),
  69757 	311: uint8(54),
  69758 	312: uint8(55),
  69759 	313: uint8(56),
  69760 	314: uint8(57),
  69761 	315: uint8(58),
  69762 	316: uint8(59),
  69763 	317: uint8(60),
  69764 	318: uint8(61),
  69765 	319: uint8(62),
  69766 	320: uint8(63),
  69767 	321: uint8(64),
  69768 	322: uint8(65),
  69769 	323: uint8(66),
  69770 	324: uint8(67),
  69771 	325: uint8(68),
  69772 	326: uint8(69),
  69773 	327: uint8(70),
  69774 	328: uint8(71),
  69775 	329: uint8(72),
  69776 	330: uint8(73),
  69777 	331: uint8(74),
  69778 	332: uint8(75),
  69779 	333: uint8(76),
  69780 	334: uint8(77),
  69781 	335: uint8(78),
  69782 	336: uint8(79),
  69783 	337: uint8(80),
  69784 	338: uint8(81),
  69785 	339: uint8(82),
  69786 	340: uint8(83),
  69787 	341: uint8(84),
  69788 	342: uint8(85),
  69789 	343: uint8(86),
  69790 	344: uint8(87),
  69791 	345: uint8(88),
  69792 	346: uint8(89),
  69793 	347: uint8(90),
  69794 	348: uint8(91),
  69795 	349: uint8(92),
  69796 	350: uint8(93),
  69797 	351: uint8(94),
  69798 	352: uint8(95),
  69799 	353: uint8(96),
  69800 	354: uint8(97),
  69801 	355: uint8(98),
  69802 	356: uint8(99),
  69803 	357: uint8(100),
  69804 	358: uint8(101),
  69805 	359: uint8(102),
  69806 	360: uint8(103),
  69807 	361: uint8(104),
  69808 	362: uint8(105),
  69809 	363: uint8(106),
  69810 	364: uint8(107),
  69811 	365: uint8(108),
  69812 	366: uint8(109),
  69813 	367: uint8(110),
  69814 	368: uint8(111),
  69815 	369: uint8(112),
  69816 	370: uint8(113),
  69817 	371: uint8(114),
  69818 	372: uint8(115),
  69819 	373: uint8(116),
  69820 	374: uint8(117),
  69821 	375: uint8(118),
  69822 	376: uint8(119),
  69823 	377: uint8(120),
  69824 	378: uint8(121),
  69825 	379: uint8(122),
  69826 	380: uint8(123),
  69827 	381: uint8(124),
  69828 	382: uint8(125),
  69829 	383: uint8(126),
  69830 	384: uint8(127),
  69831 	386: uint8(1),
  69832 	387: uint8(2),
  69833 	388: uint8(3),
  69834 	389: uint8(4),
  69835 	390: uint8(5),
  69836 	391: uint8(6),
  69837 	392: uint8(7),
  69838 	393: uint8(8),
  69839 	394: uint8(9),
  69840 	395: uint8(10),
  69841 	396: uint8(11),
  69842 	397: uint8(12),
  69843 	398: uint8(13),
  69844 	399: uint8(14),
  69845 	400: uint8(15),
  69846 	401: uint8(16),
  69847 	402: uint8(17),
  69848 	403: uint8(18),
  69849 	404: uint8(19),
  69850 	405: uint8(20),
  69851 	406: uint8(21),
  69852 	407: uint8(22),
  69853 	408: uint8(23),
  69854 	409: uint8(24),
  69855 	410: uint8(25),
  69856 	411: uint8(26),
  69857 	412: uint8(27),
  69858 	413: uint8(28),
  69859 	414: uint8(29),
  69860 	415: uint8(30),
  69861 	416: uint8(31),
  69862 	417: uint8(32),
  69863 	418: uint8(33),
  69864 	419: uint8(34),
  69865 	420: uint8(35),
  69866 	421: uint8(36),
  69867 	422: uint8(37),
  69868 	423: uint8(38),
  69869 	424: uint8(39),
  69870 	425: uint8(40),
  69871 	426: uint8(41),
  69872 	427: uint8(42),
  69873 	428: uint8(43),
  69874 	429: uint8(44),
  69875 	430: uint8(45),
  69876 	431: uint8(46),
  69877 	432: uint8(47),
  69878 	433: uint8(48),
  69879 	434: uint8(49),
  69880 	435: uint8(50),
  69881 	436: uint8(51),
  69882 	437: uint8(52),
  69883 	438: uint8(53),
  69884 	439: uint8(54),
  69885 	440: uint8(55),
  69886 	441: uint8(56),
  69887 	442: uint8(57),
  69888 	443: uint8(58),
  69889 	444: uint8(59),
  69890 	445: uint8(60),
  69891 	446: uint8(61),
  69892 	447: uint8(62),
  69893 	448: uint8(63),
  69894 	449: uint8(64),
  69895 	450: uint8(65),
  69896 	451: uint8(66),
  69897 	452: uint8(67),
  69898 	453: uint8(68),
  69899 	454: uint8(69),
  69900 	455: uint8(70),
  69901 	456: uint8(71),
  69902 	457: uint8(72),
  69903 	458: uint8(73),
  69904 	459: uint8(74),
  69905 	460: uint8(75),
  69906 	461: uint8(76),
  69907 	462: uint8(77),
  69908 	463: uint8(78),
  69909 	464: uint8(79),
  69910 	465: uint8(80),
  69911 	466: uint8(81),
  69912 	467: uint8(82),
  69913 	468: uint8(83),
  69914 	469: uint8(84),
  69915 	470: uint8(85),
  69916 	471: uint8(86),
  69917 	472: uint8(87),
  69918 	473: uint8(88),
  69919 	474: uint8(89),
  69920 	475: uint8(90),
  69921 	476: uint8(91),
  69922 	477: uint8(92),
  69923 	478: uint8(93),
  69924 	479: uint8(94),
  69925 	480: uint8(95),
  69926 	481: uint8(96),
  69927 	482: uint8(97),
  69928 	483: uint8(98),
  69929 	484: uint8(99),
  69930 	485: uint8(100),
  69931 	486: uint8(101),
  69932 	487: uint8(102),
  69933 	488: uint8(103),
  69934 	489: uint8(104),
  69935 	490: uint8(105),
  69936 	491: uint8(106),
  69937 	492: uint8(107),
  69938 	493: uint8(108),
  69939 	494: uint8(109),
  69940 	495: uint8(110),
  69941 	496: uint8(111),
  69942 	497: uint8(112),
  69943 	498: uint8(113),
  69944 	499: uint8(114),
  69945 	500: uint8(115),
  69946 	501: uint8(116),
  69947 	502: uint8(117),
  69948 	503: uint8(118),
  69949 	504: uint8(119),
  69950 	505: uint8(120),
  69951 	506: uint8(121),
  69952 	507: uint8(122),
  69953 	508: uint8(123),
  69954 	509: uint8(124),
  69955 	510: uint8(125),
  69956 	511: uint8(126),
  69957 }
  69958 
  69959 // C documentation
  69960 //
  69961 //	// lookup table for small values of int*log2(int) * (1 << LOG_2_PRECISION_BITS).
  69962 //	// Obtained in Python with:
  69963 //	// a=[ "%d"%i if i<(1<<32) else "%dull"%i
  69964 //	//     for i in [ round((1<<LOG_2_PRECISION_BITS)*math.log2(i)*i) if i
  69965 //	//     else 0 for i in range(256)]]
  69966 //	// print(',\n '.join([','.join(v) for v in batched([i.rjust(15)
  69967 //	//                      for i in a],4)]))
  69968 var kSLog2Table = [256]uint64_t{
  69969 	2:   uint64(16777216),
  69970 	3:   uint64(39886887),
  69971 	4:   uint64(67108864),
  69972 	5:   uint64(97388723),
  69973 	6:   uint64(130105423),
  69974 	7:   uint64(164848600),
  69975 	8:   uint64(201326592),
  69976 	9:   uint64(239321324),
  69977 	10:  uint64(278663526),
  69978 	11:  uint64(319217973),
  69979 	12:  uint64(360874141),
  69980 	13:  uint64(403539997),
  69981 	14:  uint64(447137711),
  69982 	15:  uint64(491600606),
  69983 	16:  uint64(536870912),
  69984 	17:  uint64(582898099),
  69985 	18:  uint64(629637592),
  69986 	19:  uint64(677049776),
  69987 	20:  uint64(725099212),
  69988 	21:  uint64(773754010),
  69989 	22:  uint64(822985323),
  69990 	23:  uint64(872766924),
  69991 	24:  uint64(923074875),
  69992 	25:  uint64(973887230),
  69993 	26:  uint64(1025183802),
  69994 	27:  uint64(1076945958),
  69995 	28:  uint64(1129156447),
  69996 	29:  uint64(1181799249),
  69997 	30:  uint64(1234859451),
  69998 	31:  uint64(1288323135),
  69999 	32:  uint64(1342177280),
  70000 	33:  uint64(1396409681),
  70001 	34:  uint64(1451008871),
  70002 	35:  uint64(1505964059),
  70003 	36:  uint64(1561265072),
  70004 	37:  uint64(1616902301),
  70005 	38:  uint64(1672866655),
  70006 	39:  uint64(1729149526),
  70007 	40:  uint64(1785742744),
  70008 	41:  uint64(1842638548),
  70009 	42:  uint64(1899829557),
  70010 	43:  uint64(1957308741),
  70011 	44:  uint64(2015069397),
  70012 	45:  uint64(2073105127),
  70013 	46:  uint64(2131409817),
  70014 	47:  uint64(2189977618),
  70015 	48:  uint64(2248802933),
  70016 	49:  uint64(2307880396),
  70017 	50:  uint64(2367204859),
  70018 	51:  uint64(2426771383),
  70019 	52:  uint64(2486575220),
  70020 	53:  uint64(2546611805),
  70021 	54:  uint64(2606876748),
  70022 	55:  uint64(2667365819),
  70023 	56:  uint64(2728074942),
  70024 	57:  uint64(2789000187),
  70025 	58:  uint64(2850137762),
  70026 	59:  uint64(2911484006),
  70027 	60:  uint64(2973035382),
  70028 	61:  uint64(3034788471),
  70029 	62:  uint64(3096739966),
  70030 	63:  uint64(3158886666),
  70031 	64:  uint64(3221225472),
  70032 	65:  uint64(3283753383),
  70033 	66:  uint64(3346467489),
  70034 	67:  uint64(3409364969),
  70035 	68:  uint64(3472443085),
  70036 	69:  uint64(3535699182),
  70037 	70:  uint64(3599130679),
  70038 	71:  uint64(3662735070),
  70039 	72:  uint64(3726509920),
  70040 	73:  uint64(3790452862),
  70041 	74:  uint64(3854561593),
  70042 	75:  uint64(3918833872),
  70043 	76:  uint64(3983267519),
  70044 	77:  uint64(4047860410),
  70045 	78:  uint64(4112610476),
  70046 	79:  uint64(4177515704),
  70047 	80:  uint64(4242574127),
  70048 	81:  uint64(4307783833),
  70049 	82:  uint64(4373142952),
  70050 	83:  uint64(4438649662),
  70051 	84:  uint64(4504302186),
  70052 	85:  uint64(4570098787),
  70053 	86:  uint64(4636037770),
  70054 	87:  uint64(4702117480),
  70055 	88:  uint64(4768336298),
  70056 	89:  uint64(4834692645),
  70057 	90:  uint64(4901184974),
  70058 	91:  uint64(4967811774),
  70059 	92:  uint64(5034571569),
  70060 	93:  uint64(5101462912),
  70061 	94:  uint64(5168484389),
  70062 	95:  uint64(5235634615),
  70063 	96:  uint64(5302912235),
  70064 	97:  uint64(5370315922),
  70065 	98:  uint64(5437844376),
  70066 	99:  uint64(5505496324),
  70067 	100: uint64(5573270518),
  70068 	101: uint64(5641165737),
  70069 	102: uint64(5709180782),
  70070 	103: uint64(5777314477),
  70071 	104: uint64(5845565671),
  70072 	105: uint64(5913933235),
  70073 	106: uint64(5982416059),
  70074 	107: uint64(6051013057),
  70075 	108: uint64(6119723161),
  70076 	109: uint64(6188545324),
  70077 	110: uint64(6257478518),
  70078 	111: uint64(6326521733),
  70079 	112: uint64(6395673979),
  70080 	113: uint64(6464934282),
  70081 	114: uint64(6534301685),
  70082 	115: uint64(6603775250),
  70083 	116: uint64(6673354052),
  70084 	117: uint64(6743037185),
  70085 	118: uint64(6812823756),
  70086 	119: uint64(6882712890),
  70087 	120: uint64(6952703725),
  70088 	121: uint64(7022795412),
  70089 	122: uint64(7092987118),
  70090 	123: uint64(7163278025),
  70091 	124: uint64(7233667324),
  70092 	125: uint64(7304154222),
  70093 	126: uint64(7374737939),
  70094 	127: uint64(7445417707),
  70095 	128: uint64(7516192768),
  70096 	129: uint64(7587062379),
  70097 	130: uint64(7658025806),
  70098 	131: uint64(7729082328),
  70099 	132: uint64(7800231234),
  70100 	133: uint64(7871471825),
  70101 	134: uint64(7942803410),
  70102 	135: uint64(8014225311),
  70103 	136: uint64(8085736859),
  70104 	137: uint64(8157337394),
  70105 	138: uint64(8229026267),
  70106 	139: uint64(8300802839),
  70107 	140: uint64(8372666477),
  70108 	141: uint64(8444616560),
  70109 	142: uint64(8516652476),
  70110 	143: uint64(8588773618),
  70111 	144: uint64(8660979393),
  70112 	145: uint64(8733269211),
  70113 	146: uint64(8805642493),
  70114 	147: uint64(8878098667),
  70115 	148: uint64(8950637170),
  70116 	149: uint64(9023257446),
  70117 	150: uint64(9095958945),
  70118 	151: uint64(9168741125),
  70119 	152: uint64(9241603454),
  70120 	153: uint64(9314545403),
  70121 	154: uint64(9387566451),
  70122 	155: uint64(9460666086),
  70123 	156: uint64(9533843800),
  70124 	157: uint64(9607099093),
  70125 	158: uint64(9680431471),
  70126 	159: uint64(9753840445),
  70127 	160: uint64(9827325535),
  70128 	161: uint64(9900886263),
  70129 	162: uint64(9974522161),
  70130 	163: uint64(10048232765),
  70131 	164: uint64(10122017615),
  70132 	165: uint64(10195876260),
  70133 	166: uint64(10269808253),
  70134 	167: uint64(10343813150),
  70135 	168: uint64(10417890516),
  70136 	169: uint64(10492039919),
  70137 	170: uint64(10566260934),
  70138 	171: uint64(10640553138),
  70139 	172: uint64(10714916116),
  70140 	173: uint64(10789349456),
  70141 	174: uint64(10863852751),
  70142 	175: uint64(10938425600),
  70143 	176: uint64(11013067604),
  70144 	177: uint64(11087778372),
  70145 	178: uint64(11162557513),
  70146 	179: uint64(11237404645),
  70147 	180: uint64(11312319387),
  70148 	181: uint64(11387301364),
  70149 	182: uint64(11462350205),
  70150 	183: uint64(11537465541),
  70151 	184: uint64(11612647010),
  70152 	185: uint64(11687894253),
  70153 	186: uint64(11763206912),
  70154 	187: uint64(11838584638),
  70155 	188: uint64(11914027082),
  70156 	189: uint64(11989533899),
  70157 	190: uint64(12065104750),
  70158 	191: uint64(12140739296),
  70159 	192: uint64(12216437206),
  70160 	193: uint64(12292198148),
  70161 	194: uint64(12368021795),
  70162 	195: uint64(12443907826),
  70163 	196: uint64(12519855920),
  70164 	197: uint64(12595865759),
  70165 	198: uint64(12671937032),
  70166 	199: uint64(12748069427),
  70167 	200: uint64(12824262637),
  70168 	201: uint64(12900516358),
  70169 	202: uint64(12976830290),
  70170 	203: uint64(13053204134),
  70171 	204: uint64(13129637595),
  70172 	205: uint64(13206130381),
  70173 	206: uint64(13282682202),
  70174 	207: uint64(13359292772),
  70175 	208: uint64(13435961806),
  70176 	209: uint64(13512689025),
  70177 	210: uint64(13589474149),
  70178 	211: uint64(13666316903),
  70179 	212: uint64(13743217014),
  70180 	213: uint64(13820174211),
  70181 	214: uint64(13897188225),
  70182 	215: uint64(13974258793),
  70183 	216: uint64(14051385649),
  70184 	217: uint64(14128568535),
  70185 	218: uint64(14205807192),
  70186 	219: uint64(14283101363),
  70187 	220: uint64(14360450796),
  70188 	221: uint64(14437855239),
  70189 	222: uint64(14515314443),
  70190 	223: uint64(14592828162),
  70191 	224: uint64(14670396151),
  70192 	225: uint64(14748018167),
  70193 	226: uint64(14825693972),
  70194 	227: uint64(14903423326),
  70195 	228: uint64(14981205995),
  70196 	229: uint64(15059041743),
  70197 	230: uint64(15136930339),
  70198 	231: uint64(15214871554),
  70199 	232: uint64(15292865160),
  70200 	233: uint64(15370910930),
  70201 	234: uint64(15449008641),
  70202 	235: uint64(15527158071),
  70203 	236: uint64(15605359001),
  70204 	237: uint64(15683611210),
  70205 	238: uint64(15761914485),
  70206 	239: uint64(15840268608),
  70207 	240: uint64(15918673369),
  70208 	241: uint64(15997128556),
  70209 	242: uint64(16075633960),
  70210 	243: uint64(16154189373),
  70211 	244: uint64(16232794589),
  70212 	245: uint64(16311449405),
  70213 	246: uint64(16390153617),
  70214 	247: uint64(16468907026),
  70215 	248: uint64(16547709431),
  70216 	249: uint64(16626560636),
  70217 	250: uint64(16705460444),
  70218 	251: uint64(16784408661),
  70219 	252: uint64(16863405094),
  70220 	253: uint64(16942449552),
  70221 	254: uint64(17021541845),
  70222 	255: uint64(17100681785),
  70223 }
  70224 
  70225 var kVP8Log2Range = [128]uint8_t{
  70226 	0:   uint8(7),
  70227 	1:   uint8(6),
  70228 	2:   uint8(6),
  70229 	3:   uint8(5),
  70230 	4:   uint8(5),
  70231 	5:   uint8(5),
  70232 	6:   uint8(5),
  70233 	7:   uint8(4),
  70234 	8:   uint8(4),
  70235 	9:   uint8(4),
  70236 	10:  uint8(4),
  70237 	11:  uint8(4),
  70238 	12:  uint8(4),
  70239 	13:  uint8(4),
  70240 	14:  uint8(4),
  70241 	15:  uint8(3),
  70242 	16:  uint8(3),
  70243 	17:  uint8(3),
  70244 	18:  uint8(3),
  70245 	19:  uint8(3),
  70246 	20:  uint8(3),
  70247 	21:  uint8(3),
  70248 	22:  uint8(3),
  70249 	23:  uint8(3),
  70250 	24:  uint8(3),
  70251 	25:  uint8(3),
  70252 	26:  uint8(3),
  70253 	27:  uint8(3),
  70254 	28:  uint8(3),
  70255 	29:  uint8(3),
  70256 	30:  uint8(3),
  70257 	31:  uint8(2),
  70258 	32:  uint8(2),
  70259 	33:  uint8(2),
  70260 	34:  uint8(2),
  70261 	35:  uint8(2),
  70262 	36:  uint8(2),
  70263 	37:  uint8(2),
  70264 	38:  uint8(2),
  70265 	39:  uint8(2),
  70266 	40:  uint8(2),
  70267 	41:  uint8(2),
  70268 	42:  uint8(2),
  70269 	43:  uint8(2),
  70270 	44:  uint8(2),
  70271 	45:  uint8(2),
  70272 	46:  uint8(2),
  70273 	47:  uint8(2),
  70274 	48:  uint8(2),
  70275 	49:  uint8(2),
  70276 	50:  uint8(2),
  70277 	51:  uint8(2),
  70278 	52:  uint8(2),
  70279 	53:  uint8(2),
  70280 	54:  uint8(2),
  70281 	55:  uint8(2),
  70282 	56:  uint8(2),
  70283 	57:  uint8(2),
  70284 	58:  uint8(2),
  70285 	59:  uint8(2),
  70286 	60:  uint8(2),
  70287 	61:  uint8(2),
  70288 	62:  uint8(2),
  70289 	63:  uint8(1),
  70290 	64:  uint8(1),
  70291 	65:  uint8(1),
  70292 	66:  uint8(1),
  70293 	67:  uint8(1),
  70294 	68:  uint8(1),
  70295 	69:  uint8(1),
  70296 	70:  uint8(1),
  70297 	71:  uint8(1),
  70298 	72:  uint8(1),
  70299 	73:  uint8(1),
  70300 	74:  uint8(1),
  70301 	75:  uint8(1),
  70302 	76:  uint8(1),
  70303 	77:  uint8(1),
  70304 	78:  uint8(1),
  70305 	79:  uint8(1),
  70306 	80:  uint8(1),
  70307 	81:  uint8(1),
  70308 	82:  uint8(1),
  70309 	83:  uint8(1),
  70310 	84:  uint8(1),
  70311 	85:  uint8(1),
  70312 	86:  uint8(1),
  70313 	87:  uint8(1),
  70314 	88:  uint8(1),
  70315 	89:  uint8(1),
  70316 	90:  uint8(1),
  70317 	91:  uint8(1),
  70318 	92:  uint8(1),
  70319 	93:  uint8(1),
  70320 	94:  uint8(1),
  70321 	95:  uint8(1),
  70322 	96:  uint8(1),
  70323 	97:  uint8(1),
  70324 	98:  uint8(1),
  70325 	99:  uint8(1),
  70326 	100: uint8(1),
  70327 	101: uint8(1),
  70328 	102: uint8(1),
  70329 	103: uint8(1),
  70330 	104: uint8(1),
  70331 	105: uint8(1),
  70332 	106: uint8(1),
  70333 	107: uint8(1),
  70334 	108: uint8(1),
  70335 	109: uint8(1),
  70336 	110: uint8(1),
  70337 	111: uint8(1),
  70338 	112: uint8(1),
  70339 	113: uint8(1),
  70340 	114: uint8(1),
  70341 	115: uint8(1),
  70342 	116: uint8(1),
  70343 	117: uint8(1),
  70344 	118: uint8(1),
  70345 	119: uint8(1),
  70346 	120: uint8(1),
  70347 	121: uint8(1),
  70348 	122: uint8(1),
  70349 	123: uint8(1),
  70350 	124: uint8(1),
  70351 	125: uint8(1),
  70352 	126: uint8(1),
  70353 }
  70354 
  70355 // C documentation
  70356 //
  70357 //	// range = ((range - 1) << kVP8Log2Range[range]) + 1
  70358 var kVP8NewRange = [128]uint8_t{
  70359 	0:   uint8(127),
  70360 	1:   uint8(127),
  70361 	2:   uint8(191),
  70362 	3:   uint8(127),
  70363 	4:   uint8(159),
  70364 	5:   uint8(191),
  70365 	6:   uint8(223),
  70366 	7:   uint8(127),
  70367 	8:   uint8(143),
  70368 	9:   uint8(159),
  70369 	10:  uint8(175),
  70370 	11:  uint8(191),
  70371 	12:  uint8(207),
  70372 	13:  uint8(223),
  70373 	14:  uint8(239),
  70374 	15:  uint8(127),
  70375 	16:  uint8(135),
  70376 	17:  uint8(143),
  70377 	18:  uint8(151),
  70378 	19:  uint8(159),
  70379 	20:  uint8(167),
  70380 	21:  uint8(175),
  70381 	22:  uint8(183),
  70382 	23:  uint8(191),
  70383 	24:  uint8(199),
  70384 	25:  uint8(207),
  70385 	26:  uint8(215),
  70386 	27:  uint8(223),
  70387 	28:  uint8(231),
  70388 	29:  uint8(239),
  70389 	30:  uint8(247),
  70390 	31:  uint8(127),
  70391 	32:  uint8(131),
  70392 	33:  uint8(135),
  70393 	34:  uint8(139),
  70394 	35:  uint8(143),
  70395 	36:  uint8(147),
  70396 	37:  uint8(151),
  70397 	38:  uint8(155),
  70398 	39:  uint8(159),
  70399 	40:  uint8(163),
  70400 	41:  uint8(167),
  70401 	42:  uint8(171),
  70402 	43:  uint8(175),
  70403 	44:  uint8(179),
  70404 	45:  uint8(183),
  70405 	46:  uint8(187),
  70406 	47:  uint8(191),
  70407 	48:  uint8(195),
  70408 	49:  uint8(199),
  70409 	50:  uint8(203),
  70410 	51:  uint8(207),
  70411 	52:  uint8(211),
  70412 	53:  uint8(215),
  70413 	54:  uint8(219),
  70414 	55:  uint8(223),
  70415 	56:  uint8(227),
  70416 	57:  uint8(231),
  70417 	58:  uint8(235),
  70418 	59:  uint8(239),
  70419 	60:  uint8(243),
  70420 	61:  uint8(247),
  70421 	62:  uint8(251),
  70422 	63:  uint8(127),
  70423 	64:  uint8(129),
  70424 	65:  uint8(131),
  70425 	66:  uint8(133),
  70426 	67:  uint8(135),
  70427 	68:  uint8(137),
  70428 	69:  uint8(139),
  70429 	70:  uint8(141),
  70430 	71:  uint8(143),
  70431 	72:  uint8(145),
  70432 	73:  uint8(147),
  70433 	74:  uint8(149),
  70434 	75:  uint8(151),
  70435 	76:  uint8(153),
  70436 	77:  uint8(155),
  70437 	78:  uint8(157),
  70438 	79:  uint8(159),
  70439 	80:  uint8(161),
  70440 	81:  uint8(163),
  70441 	82:  uint8(165),
  70442 	83:  uint8(167),
  70443 	84:  uint8(169),
  70444 	85:  uint8(171),
  70445 	86:  uint8(173),
  70446 	87:  uint8(175),
  70447 	88:  uint8(177),
  70448 	89:  uint8(179),
  70449 	90:  uint8(181),
  70450 	91:  uint8(183),
  70451 	92:  uint8(185),
  70452 	93:  uint8(187),
  70453 	94:  uint8(189),
  70454 	95:  uint8(191),
  70455 	96:  uint8(193),
  70456 	97:  uint8(195),
  70457 	98:  uint8(197),
  70458 	99:  uint8(199),
  70459 	100: uint8(201),
  70460 	101: uint8(203),
  70461 	102: uint8(205),
  70462 	103: uint8(207),
  70463 	104: uint8(209),
  70464 	105: uint8(211),
  70465 	106: uint8(213),
  70466 	107: uint8(215),
  70467 	108: uint8(217),
  70468 	109: uint8(219),
  70469 	110: uint8(221),
  70470 	111: uint8(223),
  70471 	112: uint8(225),
  70472 	113: uint8(227),
  70473 	114: uint8(229),
  70474 	115: uint8(231),
  70475 	116: uint8(233),
  70476 	117: uint8(235),
  70477 	118: uint8(237),
  70478 	119: uint8(239),
  70479 	120: uint8(241),
  70480 	121: uint8(243),
  70481 	122: uint8(245),
  70482 	123: uint8(247),
  70483 	124: uint8(249),
  70484 	125: uint8(251),
  70485 	126: uint8(253),
  70486 	127: uint8(127),
  70487 }
  70488 
  70489 var __ccgo_ts = (*reflect.StringHeader)(unsafe.Pointer(&__ccgo_ts1)).Data
  70490 
  70491 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\x00"